1 /* Output routines for GCC for ARM/RISCiX.
2 Copyright (C) 1991, 93, 94, 95, 96, 97, 1998 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 (rwe11@cl.cam.ac.uk)
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. */
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-flags.h"
35 #include "insn-attr.h"
42 /* The maximum number of insns skipped which will be conditionalised if
44 #define MAX_INSNS_SKIPPED 5
46 /* Some function declarations. */
47 extern FILE *asm_out_file;
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 ((enum rtx_code, 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));
72 /* Define the information needed to generate branch insns. This is
73 stored from the compare operation. */
75 rtx arm_compare_op0, arm_compare_op1;
78 /* What type of cpu are we compiling for? */
79 enum processor_type arm_cpu;
81 /* What type of floating point are we tuning for? */
82 enum floating_point_type arm_fpu;
84 /* What type of floating point instructions are available? */
85 enum floating_point_type arm_fpu_arch;
87 /* What program mode is the cpu running in? 26-bit mode or 32-bit mode */
88 enum prog_mode_type arm_prgmode;
90 /* Set by the -mfp=... option */
91 char *target_fp_name = NULL;
93 /* Nonzero if this is an "M" variant of the processor. */
94 int arm_fast_multiply = 0;
96 /* Nonzero if this chip supports the ARM Architecture 4 extensions */
99 /* Set to the features we should tune the code for (multiply speed etc). */
102 /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we
103 must report the mode of the memory reference from PRINT_OPERAND to
104 PRINT_OPERAND_ADDRESS. */
105 enum machine_mode output_memory_reference_mode;
107 /* Nonzero if the prologue must setup `fp'. */
108 int current_function_anonymous_args;
110 /* The register number to be used for the PIC offset register. */
111 int arm_pic_register = 9;
113 /* Location counter of .text segment. */
114 int arm_text_location = 0;
116 /* Set to one if we think that lr is only saved because of subroutine calls,
117 but all of these can be `put after' return insns */
118 int lr_save_eliminated;
120 /* Set to 1 when a return insn is output, this means that the epilogue
123 static int return_used_this_function;
125 static int arm_constant_limit = 3;
127 /* For an explanation of these variables, see final_prescan_insn below. */
129 enum arm_cond_code arm_current_cc;
131 int arm_target_label;
133 /* The condition codes of the ARM, and the inverse function. */
134 char *arm_condition_codes[] =
136 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
137 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
140 static enum arm_cond_code get_arm_condition_code ();
143 /* Initialization code */
145 struct arm_cpu_select arm_select[4] =
147 /* switch name, tune arch */
148 { (char *)0, "--with-cpu=", 1, 1 },
149 { (char *)0, "-mcpu=", 1, 1 },
150 { (char *)0, "-march=", 0, 1 },
151 { (char *)0, "-mtune=", 1, 0 },
154 #define FL_CO_PROC 0x01 /* Has external co-processor bus */
155 #define FL_FAST_MULT 0x02 /* Fast multiply */
156 #define FL_MODE26 0x04 /* 26-bit mode support */
157 #define FL_MODE32 0x08 /* 32-bit mode support */
158 #define FL_ARCH4 0x10 /* Architecture rel 4 */
159 #define FL_THUMB 0x20 /* Thumb aware */
164 enum processor_type type;
168 /* Not all of these give usefully different compilation alternatives,
169 but there is no simple way of generalizing them. */
170 static struct processors all_procs[] =
172 {"arm2", PROCESSOR_ARM2, FL_CO_PROC | FL_MODE26},
173 {"arm250", PROCESSOR_ARM2, FL_CO_PROC | FL_MODE26},
174 {"arm3", PROCESSOR_ARM2, FL_CO_PROC | FL_MODE26},
175 {"arm6", PROCESSOR_ARM6, FL_CO_PROC | FL_MODE32 | FL_MODE26},
176 {"arm600", PROCESSOR_ARM6, FL_CO_PROC | FL_MODE32 | FL_MODE26},
177 {"arm610", PROCESSOR_ARM6, FL_MODE32 | FL_MODE26},
178 {"arm7", PROCESSOR_ARM7, FL_CO_PROC | FL_MODE32 | FL_MODE26},
179 /* arm7m doesn't exist on its own, only in conjunction with D, (and I), but
180 those don't alter the code, so it is sometimes known as the arm7m */
181 {"arm7m", PROCESSOR_ARM7, (FL_CO_PROC | FL_FAST_MULT | FL_MODE32
183 {"arm7dm", PROCESSOR_ARM7, (FL_CO_PROC | FL_FAST_MULT | FL_MODE32
185 {"arm7dmi", PROCESSOR_ARM7, (FL_CO_PROC | FL_FAST_MULT | FL_MODE32
187 {"arm700", PROCESSOR_ARM7, FL_CO_PROC | FL_MODE32 | FL_MODE26},
188 {"arm710", PROCESSOR_ARM7, FL_MODE32 | FL_MODE26},
189 {"arm7100", PROCESSOR_ARM7, FL_MODE32 | FL_MODE26},
190 {"arm7500", PROCESSOR_ARM7, FL_MODE32 | FL_MODE26},
191 /* Doesn't really have an external co-proc, but does have embedded fpu */
192 {"arm7500fe", PROCESSOR_ARM7, FL_CO_PROC | FL_MODE32 | FL_MODE26},
193 {"arm7tdmi", PROCESSOR_ARM7, (FL_CO_PROC | FL_FAST_MULT | FL_MODE32
194 | FL_ARCH4 | FL_THUMB)},
195 {"arm8", PROCESSOR_ARM8, (FL_FAST_MULT | FL_MODE32 | FL_MODE26
197 {"arm810", PROCESSOR_ARM8, (FL_FAST_MULT | FL_MODE32 | FL_MODE26
199 {"strongarm", PROCESSOR_STARM, (FL_FAST_MULT | FL_MODE32 | FL_MODE26
201 {"strongarm110", PROCESSOR_STARM, (FL_FAST_MULT | FL_MODE32 | FL_MODE26
203 {"armv2", PROCESSOR_NONE, FL_CO_PROC | FL_MODE26},
204 {"armv2a", PROCESSOR_NONE, FL_CO_PROC | FL_MODE26},
205 {"armv3", PROCESSOR_NONE, FL_CO_PROC | FL_MODE32 | FL_MODE26},
206 {"armv3m", PROCESSOR_NONE, (FL_CO_PROC | FL_FAST_MULT | FL_MODE32
208 {"armv4", PROCESSOR_NONE, (FL_CO_PROC | FL_FAST_MULT | FL_MODE32
209 | FL_MODE26 | FL_ARCH4)},
210 /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no
211 implementations that support it, so we will leave it out for now. */
212 {"armv4t", PROCESSOR_NONE, (FL_CO_PROC | FL_FAST_MULT | FL_MODE32
217 /* Fix up any incompatible options that the user has specified.
218 This has now turned into a maze. */
220 arm_override_options ()
222 int arm_thumb_aware = 0;
225 struct arm_cpu_select *ptr;
226 static struct cpu_default {
230 { TARGET_CPU_arm2, "arm2" },
231 { TARGET_CPU_arm6, "arm6" },
232 { TARGET_CPU_arm610, "arm610" },
233 { TARGET_CPU_arm7dm, "arm7dm" },
234 { TARGET_CPU_arm7500fe, "arm7500fe" },
235 { TARGET_CPU_arm7tdmi, "arm7tdmi" },
236 { TARGET_CPU_arm8, "arm8" },
237 { TARGET_CPU_arm810, "arm810" },
238 { TARGET_CPU_strongarm, "strongarm" },
241 struct cpu_default *def;
243 /* Set the default. */
244 for (def = &cpu_defaults[0]; def->name; ++def)
245 if (def->cpu == TARGET_CPU_DEFAULT)
250 arm_select[0].string = def->name;
252 for (i = 0; i < sizeof (arm_select) / sizeof (arm_select[0]); i++)
254 ptr = &arm_select[i];
255 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
257 struct processors *sel;
259 for (sel = all_procs; sel->name != NULL; sel++)
260 if (! strcmp (ptr->string, sel->name))
262 /* -march= is the only flag that can take an architecture
263 type, so if we match when the tune bit is set, the
264 option was invalid. */
267 if (sel->type == PROCESSOR_NONE)
268 continue; /* Its an architecture, not a cpu */
271 tune_flags = sel->flags;
280 if (sel->name == NULL)
281 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
285 if (write_symbols != NO_DEBUG && flag_omit_frame_pointer)
286 warning ("-g with -fomit-frame-pointer may not give sensible debugging");
288 if (TARGET_POKE_FUNCTION_NAME)
289 target_flags |= ARM_FLAG_APCS_FRAME;
292 warning ("Option '-m6' deprecated. Use: '-mapcs-32' or -mcpu=<proc>");
295 warning ("Option '-m3' deprecated. Use: '-mapcs-26' or -mcpu=<proc>");
297 if (TARGET_APCS_REENT && flag_pic)
298 fatal ("-fpic and -mapcs-reent are incompatible");
300 if (TARGET_APCS_REENT)
301 warning ("APCS reentrant code not supported.");
303 /* If stack checking is disabled, we can use r10 as the PIC register,
304 which keeps r9 available. */
305 if (flag_pic && ! TARGET_APCS_STACK)
306 arm_pic_register = 10;
308 /* Well, I'm about to have a go, but pic is NOT going to be compatible
309 with APCS reentrancy, since that requires too much support in the
310 assembler and linker, and the ARMASM assembler seems to lack some
311 required directives. */
313 warning ("Position independent code not supported");
315 if (TARGET_APCS_FLOAT)
316 warning ("Passing floating point arguments in fp regs not yet supported");
318 if (TARGET_APCS_STACK && ! TARGET_APCS)
320 warning ("-mapcs-stack-check incompatible with -mno-apcs-frame");
321 target_flags |= ARM_FLAG_APCS_FRAME;
324 /* Default is to tune for an FPA */
327 /* Default value for floating point code... if no co-processor
328 bus, then schedule for emulated floating point. Otherwise,
329 assume the user has an FPA.
330 Note: this does not prevent use of floating point instructions,
331 -msoft-float does that. */
332 if ((tune_flags & FL_CO_PROC) == 0)
335 arm_fast_multiply = (flags & FL_FAST_MULT) != 0;
336 arm_arch4 = (flags & FL_ARCH4) != 0;
337 arm_thumb_aware = (flags & FL_THUMB) != 0;
341 if (strcmp (target_fp_name, "2") == 0)
342 arm_fpu_arch = FP_SOFT2;
343 else if (strcmp (target_fp_name, "3") == 0)
344 arm_fpu_arch = FP_HARD;
346 fatal ("Invalid floating point emulation option: -mfpe=%s",
350 arm_fpu_arch = FP_DEFAULT;
352 if (TARGET_THUMB_INTERWORK && ! arm_thumb_aware)
354 warning ("This processor variant does not support Thumb interworking");
355 target_flags &= ~ARM_FLAG_THUMB;
358 if (TARGET_FPE && arm_fpu != FP_HARD)
361 /* For arm2/3 there is no need to do any scheduling if there is only
362 a floating point emulator, or we are doing software floating-point. */
363 if ((TARGET_SOFT_FLOAT || arm_fpu != FP_HARD) && arm_cpu == PROCESSOR_ARM2)
364 flag_schedule_insns = flag_schedule_insns_after_reload = 0;
366 arm_prog_mode = TARGET_APCS_32 ? PROG_MODE_PROG32 : PROG_MODE_PROG26;
370 /* Return 1 if it is possible to return using a single instruction */
377 if (!reload_completed ||current_function_pretend_args_size
378 || current_function_anonymous_args
379 || ((get_frame_size () + current_function_outgoing_args_size != 0)
380 && !(TARGET_APCS || frame_pointer_needed)))
383 /* Can't be done if interworking with Thumb, and any registers have been
385 if (TARGET_THUMB_INTERWORK)
386 for (regno = 0; regno < 16; regno++)
387 if (regs_ever_live[regno] && ! call_used_regs[regno])
390 /* Can't be done if any of the FPU regs are pushed, since this also
392 for (regno = 16; regno < 24; regno++)
393 if (regs_ever_live[regno] && ! call_used_regs[regno])
396 /* If a function is naked, don't use the "return" insn. */
397 if (arm_naked_function_p (current_function_decl))
403 /* Return TRUE if int I is a valid immediate ARM constant. */
409 unsigned HOST_WIDE_INT mask = ~(unsigned HOST_WIDE_INT)0xFF;
411 /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must
412 be all zero, or all one. */
413 if ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0
414 && ((i & ~(unsigned HOST_WIDE_INT) 0xffffffff)
415 != ((~(unsigned HOST_WIDE_INT) 0)
416 & ~(unsigned HOST_WIDE_INT) 0xffffffff)))
419 /* Fast return for 0 and powers of 2 */
420 if ((i & (i - 1)) == 0)
425 if ((i & mask & (unsigned HOST_WIDE_INT) 0xffffffff) == 0)
428 (mask << 2) | ((mask & (unsigned HOST_WIDE_INT) 0xffffffff)
429 >> (32 - 2)) | ~((unsigned HOST_WIDE_INT) 0xffffffff);
430 } while (mask != ~(unsigned HOST_WIDE_INT) 0xFF);
435 /* Return true if I is a valid constant for the operation CODE. */
437 const_ok_for_op (i, code, mode)
440 enum machine_mode mode;
442 if (const_ok_for_arm (i))
448 return const_ok_for_arm (ARM_SIGN_EXTEND (-i));
450 case MINUS: /* Should only occur with (MINUS I reg) => rsb */
456 return const_ok_for_arm (ARM_SIGN_EXTEND (~i));
463 /* Emit a sequence of insns to handle a large constant.
464 CODE is the code of the operation required, it can be any of SET, PLUS,
465 IOR, AND, XOR, MINUS;
466 MODE is the mode in which the operation is being performed;
467 VAL is the integer to operate on;
468 SOURCE is the other operand (a register, or a null-pointer for SET);
469 SUBTARGETS means it is safe to create scratch registers if that will
470 either produce a simpler sequence, or we will want to cse the values.
471 Return value is the number of insns emitted. */
474 arm_split_constant (code, mode, val, target, source, subtargets)
476 enum machine_mode mode;
482 if (subtargets || code == SET
483 || (GET_CODE (target) == REG && GET_CODE (source) == REG
484 && REGNO (target) != REGNO (source)))
486 if (arm_gen_constant (code, mode, val, target, source, 1, 0)
487 > arm_constant_limit + (code != SET))
491 /* Currently SET is the only monadic value for CODE, all
492 the rest are diadic. */
493 emit_insn (gen_rtx (SET, VOIDmode, target, GEN_INT (val)));
498 rtx temp = subtargets ? gen_reg_rtx (mode) : target;
500 emit_insn (gen_rtx (SET, VOIDmode, temp, GEN_INT (val)));
501 /* For MINUS, the value is subtracted from, since we never
502 have subtraction of a constant. */
504 emit_insn (gen_rtx (SET, VOIDmode, target,
505 gen_rtx (code, mode, temp, source)));
507 emit_insn (gen_rtx (SET, VOIDmode, target,
508 gen_rtx (code, mode, source, temp)));
514 return arm_gen_constant (code, mode, val, target, source, subtargets, 1);
517 /* As above, but extra parameter GENERATE which, if clear, suppresses
520 arm_gen_constant (code, mode, val, target, source, subtargets, generate)
522 enum machine_mode mode;
531 int can_negate_initial = 0;
534 int num_bits_set = 0;
535 int set_sign_bit_copies = 0;
536 int clear_sign_bit_copies = 0;
537 int clear_zero_bit_copies = 0;
538 int set_zero_bit_copies = 0;
540 unsigned HOST_WIDE_INT temp1, temp2;
541 unsigned HOST_WIDE_INT remainder = val & 0xffffffff;
543 /* find out which operations are safe for a given CODE. Also do a quick
544 check for degenerate cases; these can occur when DImode operations
556 can_negate_initial = 1;
560 if (remainder == 0xffffffff)
563 emit_insn (gen_rtx (SET, VOIDmode, target,
564 GEN_INT (ARM_SIGN_EXTEND (val))));
569 if (reload_completed && rtx_equal_p (target, source))
572 emit_insn (gen_rtx (SET, VOIDmode, target, source));
581 emit_insn (gen_rtx (SET, VOIDmode, target, const0_rtx));
584 if (remainder == 0xffffffff)
586 if (reload_completed && rtx_equal_p (target, source))
589 emit_insn (gen_rtx (SET, VOIDmode, target, source));
598 if (reload_completed && rtx_equal_p (target, source))
601 emit_insn (gen_rtx (SET, VOIDmode, target, source));
604 if (remainder == 0xffffffff)
607 emit_insn (gen_rtx (SET, VOIDmode, target,
608 gen_rtx (NOT, mode, source)));
612 /* We don't know how to handle this yet below. */
616 /* We treat MINUS as (val - source), since (source - val) is always
617 passed as (source + (-val)). */
621 emit_insn (gen_rtx (SET, VOIDmode, target,
622 gen_rtx (NEG, mode, source)));
625 if (const_ok_for_arm (val))
628 emit_insn (gen_rtx (SET, VOIDmode, target,
629 gen_rtx (MINUS, mode, GEN_INT (val), source)));
640 /* If we can do it in one insn get out quickly */
641 if (const_ok_for_arm (val)
642 || (can_negate_initial && const_ok_for_arm (-val))
643 || (can_invert && const_ok_for_arm (~val)))
646 emit_insn (gen_rtx (SET, VOIDmode, target,
647 (source ? gen_rtx (code, mode, source,
654 /* Calculate a few attributes that may be useful for specific
657 for (i = 31; i >= 0; i--)
659 if ((remainder & (1 << i)) == 0)
660 clear_sign_bit_copies++;
665 for (i = 31; i >= 0; i--)
667 if ((remainder & (1 << i)) != 0)
668 set_sign_bit_copies++;
673 for (i = 0; i <= 31; i++)
675 if ((remainder & (1 << i)) == 0)
676 clear_zero_bit_copies++;
681 for (i = 0; i <= 31; i++)
683 if ((remainder & (1 << i)) != 0)
684 set_zero_bit_copies++;
692 /* See if we can do this by sign_extending a constant that is known
693 to be negative. This is a good, way of doing it, since the shift
694 may well merge into a subsequent insn. */
695 if (set_sign_bit_copies > 1)
698 (temp1 = ARM_SIGN_EXTEND (remainder
699 << (set_sign_bit_copies - 1))))
703 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
704 emit_insn (gen_rtx (SET, VOIDmode, new_src,
706 emit_insn (gen_ashrsi3 (target, new_src,
707 GEN_INT (set_sign_bit_copies - 1)));
711 /* For an inverted constant, we will need to set the low bits,
712 these will be shifted out of harm's way. */
713 temp1 |= (1 << (set_sign_bit_copies - 1)) - 1;
714 if (const_ok_for_arm (~temp1))
718 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
719 emit_insn (gen_rtx (SET, VOIDmode, new_src,
721 emit_insn (gen_ashrsi3 (target, new_src,
722 GEN_INT (set_sign_bit_copies - 1)));
728 /* See if we can generate this by setting the bottom (or the top)
729 16 bits, and then shifting these into the other half of the
730 word. We only look for the simplest cases, to do more would cost
731 too much. Be careful, however, not to generate this when the
732 alternative would take fewer insns. */
733 if (val & 0xffff0000)
735 temp1 = remainder & 0xffff0000;
736 temp2 = remainder & 0x0000ffff;
738 /* Overlaps outside this range are best done using other methods. */
739 for (i = 9; i < 24; i++)
741 if ((((temp2 | (temp2 << i)) & 0xffffffff) == remainder)
742 && ! const_ok_for_arm (temp2))
744 rtx new_src = (subtargets
745 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
747 insns = arm_gen_constant (code, mode, temp2, new_src,
748 source, subtargets, generate);
751 emit_insn (gen_rtx (SET, VOIDmode, target,
753 gen_rtx (ASHIFT, mode, source,
760 /* Don't duplicate cases already considered. */
761 for (i = 17; i < 24; i++)
763 if (((temp1 | (temp1 >> i)) == remainder)
764 && ! const_ok_for_arm (temp1))
766 rtx new_src = (subtargets
767 ? (generate ? gen_reg_rtx (mode) : NULL_RTX)
769 insns = arm_gen_constant (code, mode, temp1, new_src,
770 source, subtargets, generate);
773 emit_insn (gen_rtx (SET, VOIDmode, target,
775 gen_rtx (LSHIFTRT, mode,
776 source, GEN_INT (i)),
786 /* If we have IOR or XOR, and the constant can be loaded in a
787 single instruction, and we can find a temporary to put it in,
788 then this can be done in two instructions instead of 3-4. */
790 /* TARGET can't be NULL if SUBTARGETS is 0 */
791 || (reload_completed && ! reg_mentioned_p (target, source)))
793 if (const_ok_for_arm (ARM_SIGN_EXTEND (~ val)))
797 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
799 emit_insn (gen_rtx (SET, VOIDmode, sub, GEN_INT (val)));
800 emit_insn (gen_rtx (SET, VOIDmode, target,
801 gen_rtx (code, mode, source, sub)));
810 if (set_sign_bit_copies > 8
811 && (val & (-1 << (32 - set_sign_bit_copies))) == val)
815 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
816 rtx shift = GEN_INT (set_sign_bit_copies);
818 emit_insn (gen_rtx (SET, VOIDmode, sub,
820 gen_rtx (ASHIFT, mode, source,
822 emit_insn (gen_rtx (SET, VOIDmode, target,
824 gen_rtx (LSHIFTRT, mode, sub,
830 if (set_zero_bit_copies > 8
831 && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder)
835 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
836 rtx shift = GEN_INT (set_zero_bit_copies);
838 emit_insn (gen_rtx (SET, VOIDmode, sub,
840 gen_rtx (LSHIFTRT, mode, source,
842 emit_insn (gen_rtx (SET, VOIDmode, target,
844 gen_rtx (ASHIFT, mode, sub,
850 if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~ val)))
854 rtx sub = subtargets ? gen_reg_rtx (mode) : target;
855 emit_insn (gen_rtx (SET, VOIDmode, sub,
856 gen_rtx (NOT, mode, source)));
859 sub = gen_reg_rtx (mode);
860 emit_insn (gen_rtx (SET, VOIDmode, sub,
861 gen_rtx (AND, mode, source,
863 emit_insn (gen_rtx (SET, VOIDmode, target,
864 gen_rtx (NOT, mode, sub)));
871 /* See if two shifts will do 2 or more insn's worth of work. */
872 if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24)
874 HOST_WIDE_INT shift_mask = ((0xffffffff
875 << (32 - clear_sign_bit_copies))
878 if ((remainder | shift_mask) != 0xffffffff)
882 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
883 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
884 new_src, source, subtargets, 1);
889 rtx targ = subtargets ? NULL_RTX : target;
890 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
891 targ, source, subtargets, 0);
897 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
898 rtx shift = GEN_INT (clear_sign_bit_copies);
900 emit_insn (gen_ashlsi3 (new_src, source, shift));
901 emit_insn (gen_lshrsi3 (target, new_src, shift));
907 if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24)
909 HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1;
911 if ((remainder | shift_mask) != 0xffffffff)
915 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
917 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
918 new_src, source, subtargets, 1);
923 rtx targ = subtargets ? NULL_RTX : target;
925 insns = arm_gen_constant (AND, mode, remainder | shift_mask,
926 targ, source, subtargets, 0);
932 rtx new_src = subtargets ? gen_reg_rtx (mode) : target;
933 rtx shift = GEN_INT (clear_zero_bit_copies);
935 emit_insn (gen_lshrsi3 (new_src, source, shift));
936 emit_insn (gen_ashlsi3 (target, new_src, shift));
948 for (i = 0; i < 32; i++)
949 if (remainder & (1 << i))
952 if (code == AND || (can_invert && num_bits_set > 16))
953 remainder = (~remainder) & 0xffffffff;
954 else if (code == PLUS && num_bits_set > 16)
955 remainder = (-remainder) & 0xffffffff;
962 /* Now try and find a way of doing the job in either two or three
964 We start by looking for the largest block of zeros that are aligned on
965 a 2-bit boundary, we then fill up the temps, wrapping around to the
966 top of the word when we drop off the bottom.
967 In the worst case this code should produce no more than four insns. */
970 int best_consecutive_zeros = 0;
972 for (i = 0; i < 32; i += 2)
974 int consecutive_zeros = 0;
976 if (! (remainder & (3 << i)))
978 while ((i < 32) && ! (remainder & (3 << i)))
980 consecutive_zeros += 2;
983 if (consecutive_zeros > best_consecutive_zeros)
985 best_consecutive_zeros = consecutive_zeros;
986 best_start = i - consecutive_zeros;
992 /* Now start emitting the insns, starting with the one with the highest
993 bit set: we do this so that the smallest number will be emitted last;
994 this is more likely to be combinable with addressing insns. */
1002 if (remainder & (3 << (i - 2)))
1007 temp1 = remainder & ((0x0ff << end)
1008 | ((i < end) ? (0xff >> (32 - end)) : 0));
1009 remainder &= ~temp1;
1016 emit_insn (gen_rtx (SET, VOIDmode,
1017 new_src = (subtargets
1018 ? gen_reg_rtx (mode)
1020 GEN_INT (can_invert ? ~temp1 : temp1)));
1021 else if (code == MINUS)
1022 emit_insn (gen_rtx (SET, VOIDmode,
1023 new_src = (subtargets
1024 ? gen_reg_rtx (mode)
1026 gen_rtx (code, mode, GEN_INT (temp1),
1029 emit_insn (gen_rtx (SET, VOIDmode,
1030 new_src = (remainder
1032 ? gen_reg_rtx (mode)
1035 gen_rtx (code, mode, source,
1036 GEN_INT (can_invert ? ~temp1
1048 else if (code == MINUS)
1055 } while (remainder);
1060 /* Canonicalize a comparison so that we are more likely to recognize it.
1061 This can be done for a few constant compares, where we can make the
1062 immediate value easier to load. */
1064 arm_canonicalize_comparison (code, op1)
1068 unsigned HOST_WIDE_INT i = INTVAL (*op1);
1078 if (i != ((((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1))
1080 && (const_ok_for_arm (i+1) || const_ok_for_arm (- (i+1))))
1082 *op1 = GEN_INT (i+1);
1083 return code == GT ? GE : LT;
1089 if (i != (((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1))
1090 && (const_ok_for_arm (i-1) || const_ok_for_arm (- (i-1))))
1092 *op1 = GEN_INT (i-1);
1093 return code == GE ? GT : LE;
1099 if (i != ~((unsigned HOST_WIDE_INT) 0)
1100 && (const_ok_for_arm (i+1) || const_ok_for_arm (- (i+1))))
1102 *op1 = GEN_INT (i + 1);
1103 return code == GTU ? GEU : LTU;
1110 && (const_ok_for_arm (i - 1) || const_ok_for_arm (- (i - 1))))
1112 *op1 = GEN_INT (i - 1);
1113 return code == GEU ? GTU : LEU;
1125 /* Handle aggregates that are not laid out in a BLKmode element.
1126 This is a sub-element of RETURN_IN_MEMORY. */
1128 arm_return_in_memory (type)
1131 if (TREE_CODE (type) == RECORD_TYPE)
1135 /* For a struct, we can return in a register if every element was a
1137 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1138 if (TREE_CODE (field) != FIELD_DECL
1139 || ! DECL_BIT_FIELD_TYPE (field))
1144 else if (TREE_CODE (type) == UNION_TYPE)
1148 /* Unions can be returned in registers if every element is
1149 integral, or can be returned in an integer register. */
1150 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
1152 if (TREE_CODE (field) != FIELD_DECL
1153 || (AGGREGATE_TYPE_P (TREE_TYPE (field))
1154 && RETURN_IN_MEMORY (TREE_TYPE (field)))
1155 || FLOAT_TYPE_P (TREE_TYPE (field)))
1160 /* XXX Not sure what should be done for other aggregates, so put them in
1166 legitimate_pic_operand_p (x)
1169 if (CONSTANT_P (x) && flag_pic
1170 && (GET_CODE (x) == SYMBOL_REF
1171 || (GET_CODE (x) == CONST
1172 && GET_CODE (XEXP (x, 0)) == PLUS
1173 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)))
1180 legitimize_pic_address (orig, mode, reg)
1182 enum machine_mode mode;
1185 if (GET_CODE (orig) == SYMBOL_REF)
1187 rtx pic_ref, address;
1193 if (reload_in_progress || reload_completed)
1196 reg = gen_reg_rtx (Pmode);
1201 #ifdef AOF_ASSEMBLER
1202 /* The AOF assembler can generate relocations for these directly, and
1203 understands that the PIC register has to be added into the offset.
1205 insn = emit_insn (gen_pic_load_addr_based (reg, orig));
1208 address = gen_reg_rtx (Pmode);
1212 emit_insn (gen_pic_load_addr (address, orig));
1214 pic_ref = gen_rtx (MEM, Pmode,
1215 gen_rtx (PLUS, Pmode, pic_offset_table_rtx, address));
1216 RTX_UNCHANGING_P (pic_ref) = 1;
1217 insn = emit_move_insn (reg, pic_ref);
1219 current_function_uses_pic_offset_table = 1;
1220 /* Put a REG_EQUAL note on this insn, so that it can be optimized
1222 REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_EQUAL, orig,
1226 else if (GET_CODE (orig) == CONST)
1230 if (GET_CODE (XEXP (orig, 0)) == PLUS
1231 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
1236 if (reload_in_progress || reload_completed)
1239 reg = gen_reg_rtx (Pmode);
1242 if (GET_CODE (XEXP (orig, 0)) == PLUS)
1244 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
1245 offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
1246 base == reg ? 0 : reg);
1251 if (GET_CODE (offset) == CONST_INT)
1253 /* The base register doesn't really matter, we only want to
1254 test the index for the appropriate mode. */
1255 GO_IF_LEGITIMATE_INDEX (mode, 0, offset, win);
1257 if (! reload_in_progress && ! reload_completed)
1258 offset = force_reg (Pmode, offset);
1263 if (GET_CODE (offset) == CONST_INT)
1264 return plus_constant_for_output (base, INTVAL (offset));
1267 if (GET_MODE_SIZE (mode) > 4
1268 && (GET_MODE_CLASS (mode) == MODE_INT
1269 || TARGET_SOFT_FLOAT))
1271 emit_insn (gen_addsi3 (reg, base, offset));
1275 return gen_rtx (PLUS, Pmode, base, offset);
1277 else if (GET_CODE (orig) == LABEL_REF)
1278 current_function_uses_pic_offset_table = 1;
1297 #ifndef AOF_ASSEMBLER
1298 rtx l1, pic_tmp, pic_tmp2, seq;
1299 rtx global_offset_table;
1301 if (current_function_uses_pic_offset_table == 0)
1308 l1 = gen_label_rtx ();
1310 global_offset_table = gen_rtx (SYMBOL_REF, Pmode, "_GLOBAL_OFFSET_TABLE_");
1311 /* The PC contains 'dot'+8, but the label L1 is on the next
1312 instruction, so the offset is only 'dot'+4. */
1313 pic_tmp = gen_rtx (CONST, VOIDmode,
1314 gen_rtx (PLUS, Pmode,
1315 gen_rtx (LABEL_REF, VOIDmode, l1),
1317 pic_tmp2 = gen_rtx (CONST, VOIDmode,
1318 gen_rtx (PLUS, Pmode,
1319 global_offset_table,
1322 pic_rtx = gen_rtx (CONST, Pmode,
1323 gen_rtx (MINUS, Pmode, pic_tmp2, pic_tmp));
1325 emit_insn (gen_pic_load_addr (pic_offset_table_rtx, pic_rtx));
1326 emit_jump_insn (gen_pic_add_dot_plus_eight(l1, pic_offset_table_rtx));
1329 seq = gen_sequence ();
1331 emit_insn_after (seq, get_insns ());
1333 /* Need to emit this whether or not we obey regdecls,
1334 since setjmp/longjmp can cause life info to screw up. */
1335 emit_insn (gen_rtx (USE, VOIDmode, pic_offset_table_rtx));
1336 #endif /* AOF_ASSEMBLER */
1339 #define REG_OR_SUBREG_REG(X) \
1340 (GET_CODE (X) == REG \
1341 || (GET_CODE (X) == SUBREG && GET_CODE (SUBREG_REG (X)) == REG))
1343 #define REG_OR_SUBREG_RTX(X) \
1344 (GET_CODE (X) == REG ? (X) : SUBREG_REG (X))
1346 #define ARM_FRAME_RTX(X) \
1347 ((X) == frame_pointer_rtx || (X) == stack_pointer_rtx \
1348 || (X) == arg_pointer_rtx)
1351 arm_rtx_costs (x, code, outer_code)
1353 enum rtx_code code, outer_code;
1355 enum machine_mode mode = GET_MODE (x);
1356 enum rtx_code subcode;
1362 /* Memory costs quite a lot for the first word, but subsequent words
1363 load at the equivalent of a single insn each. */
1364 return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD)
1365 + (CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0));
1372 if (mode == SImode && GET_CODE (XEXP (x, 1)) == REG)
1379 case ASHIFT: case LSHIFTRT: case ASHIFTRT:
1381 return (8 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : 8)
1382 + ((GET_CODE (XEXP (x, 0)) == REG
1383 || (GET_CODE (XEXP (x, 0)) == SUBREG
1384 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
1386 return (1 + ((GET_CODE (XEXP (x, 0)) == REG
1387 || (GET_CODE (XEXP (x, 0)) == SUBREG
1388 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG))
1390 + ((GET_CODE (XEXP (x, 1)) == REG
1391 || (GET_CODE (XEXP (x, 1)) == SUBREG
1392 && GET_CODE (SUBREG_REG (XEXP (x, 1))) == REG)
1393 || (GET_CODE (XEXP (x, 1)) == CONST_INT))
1398 return (4 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 8)
1399 + ((REG_OR_SUBREG_REG (XEXP (x, 0))
1400 || (GET_CODE (XEXP (x, 0)) == CONST_INT
1401 && const_ok_for_arm (INTVAL (XEXP (x, 0)))))
1404 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1405 return (2 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1406 || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
1407 && const_double_rtx_ok_for_fpu (XEXP (x, 1))))
1409 + ((REG_OR_SUBREG_REG (XEXP (x, 0))
1410 || (GET_CODE (XEXP (x, 0)) == CONST_DOUBLE
1411 && const_double_rtx_ok_for_fpu (XEXP (x, 0))))
1414 if (((GET_CODE (XEXP (x, 0)) == CONST_INT
1415 && const_ok_for_arm (INTVAL (XEXP (x, 0)))
1416 && REG_OR_SUBREG_REG (XEXP (x, 1))))
1417 || (((subcode = GET_CODE (XEXP (x, 1))) == ASHIFT
1418 || subcode == ASHIFTRT || subcode == LSHIFTRT
1419 || subcode == ROTATE || subcode == ROTATERT
1421 && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
1422 && ((INTVAL (XEXP (XEXP (x, 1), 1)) &
1423 (INTVAL (XEXP (XEXP (x, 1), 1)) - 1)) == 0)))
1424 && REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 0))
1425 && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 1))
1426 || GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT)
1427 && REG_OR_SUBREG_REG (XEXP (x, 0))))
1432 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1433 return (2 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8)
1434 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1435 || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE
1436 && const_double_rtx_ok_for_fpu (XEXP (x, 1))))
1440 case AND: case XOR: case IOR:
1443 /* Normally the frame registers will be spilt into reg+const during
1444 reload, so it is a bad idea to combine them with other instructions,
1445 since then they might not be moved outside of loops. As a compromise
1446 we allow integration with ops that have a constant as their second
1448 if ((REG_OR_SUBREG_REG (XEXP (x, 0))
1449 && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0)))
1450 && GET_CODE (XEXP (x, 1)) != CONST_INT)
1451 || (REG_OR_SUBREG_REG (XEXP (x, 0))
1452 && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0)))))
1456 return (4 + extra_cost + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8)
1457 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1458 || (GET_CODE (XEXP (x, 1)) == CONST_INT
1459 && const_ok_for_op (INTVAL (XEXP (x, 1)), code, mode)))
1462 if (REG_OR_SUBREG_REG (XEXP (x, 0)))
1463 return (1 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : extra_cost)
1464 + ((REG_OR_SUBREG_REG (XEXP (x, 1))
1465 || (GET_CODE (XEXP (x, 1)) == CONST_INT
1466 && const_ok_for_op (INTVAL (XEXP (x, 1)), code, mode)))
1469 else if (REG_OR_SUBREG_REG (XEXP (x, 1)))
1470 return (1 + extra_cost
1471 + ((((subcode = GET_CODE (XEXP (x, 0))) == ASHIFT
1472 || subcode == LSHIFTRT || subcode == ASHIFTRT
1473 || subcode == ROTATE || subcode == ROTATERT
1475 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
1476 && ((INTVAL (XEXP (XEXP (x, 0), 1)) &
1477 (INTVAL (XEXP (XEXP (x, 0), 1)) - 1)) == 0)))
1478 && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 0)))
1479 && ((REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 1)))
1480 || GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))
1486 /* There is no point basing this on the tuning, since it is always the
1487 fast variant if it exists at all */
1488 if (arm_fast_multiply && mode == DImode
1489 && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1)))
1490 && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
1491 || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND))
1494 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1498 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
1500 unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1))
1501 & (unsigned HOST_WIDE_INT) 0xffffffff);
1502 int add_cost = const_ok_for_arm (i) ? 4 : 8;
1504 /* Tune as appropriate */
1505 int booth_unit_size = ((tune_flags & FL_FAST_MULT) ? 8 : 2);
1507 for (j = 0; i && j < 32; j += booth_unit_size)
1509 i >>= booth_unit_size;
1516 return (((tune_flags & FL_FAST_MULT) ? 8 : 30)
1517 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4)
1518 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 4));
1521 if (arm_fast_multiply && mode == SImode
1522 && GET_CODE (XEXP (x, 0)) == LSHIFTRT
1523 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
1524 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0))
1525 == GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)))
1526 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND
1527 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND))
1532 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1533 return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 6);
1537 return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4);
1539 return 1 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4);
1542 if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC)
1550 return 4 + (mode == DImode ? 4 : 0);
1553 if (GET_MODE (XEXP (x, 0)) == QImode)
1554 return (4 + (mode == DImode ? 4 : 0)
1555 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1558 switch (GET_MODE (XEXP (x, 0)))
1561 return (1 + (mode == DImode ? 4 : 0)
1562 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1565 return (4 + (mode == DImode ? 4 : 0)
1566 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1569 return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0));
1582 arm_adjust_cost (insn, link, dep, cost)
1590 if ((i_pat = single_set (insn)) != NULL
1591 && GET_CODE (SET_SRC (i_pat)) == MEM
1592 && (d_pat = single_set (dep)) != NULL
1593 && GET_CODE (SET_DEST (d_pat)) == MEM)
1595 /* This is a load after a store, there is no conflict if the load reads
1596 from a cached area. Assume that loads from the stack, and from the
1597 constant pool are cached, and that others will miss. This is a
1600 /* debug_rtx (insn);
1603 fprintf (stderr, "costs %d\n", cost); */
1605 if (CONSTANT_POOL_ADDRESS_P (XEXP (SET_SRC (i_pat), 0))
1606 || reg_mentioned_p (stack_pointer_rtx, XEXP (SET_SRC (i_pat), 0))
1607 || reg_mentioned_p (frame_pointer_rtx, XEXP (SET_SRC (i_pat), 0))
1608 || reg_mentioned_p (hard_frame_pointer_rtx,
1609 XEXP (SET_SRC (i_pat), 0)))
1611 /* fprintf (stderr, "***** Now 1\n"); */
1619 /* This code has been fixed for cross compilation. */
1621 static int fpa_consts_inited = 0;
1623 char *strings_fpa[8] = {
1625 "4", "5", "0.5", "10"
1628 static REAL_VALUE_TYPE values_fpa[8];
1636 for (i = 0; i < 8; i++)
1638 r = REAL_VALUE_ATOF (strings_fpa[i], DFmode);
1642 fpa_consts_inited = 1;
1645 /* Return TRUE if rtx X is a valid immediate FPU constant. */
1648 const_double_rtx_ok_for_fpu (x)
1654 if (!fpa_consts_inited)
1657 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
1658 if (REAL_VALUE_MINUS_ZERO (r))
1661 for (i = 0; i < 8; i++)
1662 if (REAL_VALUES_EQUAL (r, values_fpa[i]))
1668 /* Return TRUE if rtx X is a valid immediate FPU constant. */
1671 neg_const_double_rtx_ok_for_fpu (x)
1677 if (!fpa_consts_inited)
1680 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
1681 r = REAL_VALUE_NEGATE (r);
1682 if (REAL_VALUE_MINUS_ZERO (r))
1685 for (i = 0; i < 8; i++)
1686 if (REAL_VALUES_EQUAL (r, values_fpa[i]))
1692 /* Predicates for `match_operand' and `match_operator'. */
1694 /* s_register_operand is the same as register_operand, but it doesn't accept
1697 This function exists because at the time it was put in it led to better
1698 code. SUBREG(MEM) always needs a reload in the places where
1699 s_register_operand is used, and this seemed to lead to excessive
1703 s_register_operand (op, mode)
1705 enum machine_mode mode;
1707 if (GET_MODE (op) != mode && mode != VOIDmode)
1710 if (GET_CODE (op) == SUBREG)
1711 op = SUBREG_REG (op);
1713 /* We don't consider registers whose class is NO_REGS
1714 to be a register operand. */
1715 return (GET_CODE (op) == REG
1716 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1717 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1720 /* Only accept reg, subreg(reg), const_int. */
1723 reg_or_int_operand (op, mode)
1725 enum machine_mode mode;
1727 if (GET_CODE (op) == CONST_INT)
1730 if (GET_MODE (op) != mode && mode != VOIDmode)
1733 if (GET_CODE (op) == SUBREG)
1734 op = SUBREG_REG (op);
1736 /* We don't consider registers whose class is NO_REGS
1737 to be a register operand. */
1738 return (GET_CODE (op) == REG
1739 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1740 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1743 /* Return 1 if OP is an item in memory, given that we are in reload. */
1746 reload_memory_operand (op, mode)
1748 enum machine_mode mode;
1750 int regno = true_regnum (op);
1752 return (! CONSTANT_P (op)
1754 || (GET_CODE (op) == REG
1755 && REGNO (op) >= FIRST_PSEUDO_REGISTER)));
1758 /* Return 1 if OP is a valid memory address, but not valid for a signed byte
1759 memory access (architecture V4) */
1761 bad_signed_byte_operand (op, mode)
1763 enum machine_mode mode;
1765 if (! memory_operand (op, mode) || GET_CODE (op) != MEM)
1770 /* A sum of anything more complex than reg + reg or reg + const is bad */
1771 if ((GET_CODE (op) == PLUS || GET_CODE (op) == MINUS)
1772 && (! s_register_operand (XEXP (op, 0), VOIDmode)
1773 || (! s_register_operand (XEXP (op, 1), VOIDmode)
1774 && GET_CODE (XEXP (op, 1)) != CONST_INT)))
1777 /* Big constants are also bad */
1778 if (GET_CODE (op) == PLUS && GET_CODE (XEXP (op, 1)) == CONST_INT
1779 && (INTVAL (XEXP (op, 1)) > 0xff
1780 || -INTVAL (XEXP (op, 1)) > 0xff))
1783 /* Everything else is good, or can will automatically be made so. */
1787 /* Return TRUE for valid operands for the rhs of an ARM instruction. */
1790 arm_rhs_operand (op, mode)
1792 enum machine_mode mode;
1794 return (s_register_operand (op, mode)
1795 || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op))));
1798 /* Return TRUE for valid operands for the rhs of an ARM instruction, or a load.
1802 arm_rhsm_operand (op, mode)
1804 enum machine_mode mode;
1806 return (s_register_operand (op, mode)
1807 || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op)))
1808 || memory_operand (op, mode));
1811 /* Return TRUE for valid operands for the rhs of an ARM instruction, or if a
1812 constant that is valid when negated. */
1815 arm_add_operand (op, mode)
1817 enum machine_mode mode;
1819 return (s_register_operand (op, mode)
1820 || (GET_CODE (op) == CONST_INT
1821 && (const_ok_for_arm (INTVAL (op))
1822 || const_ok_for_arm (-INTVAL (op)))));
1826 arm_not_operand (op, mode)
1828 enum machine_mode mode;
1830 return (s_register_operand (op, mode)
1831 || (GET_CODE (op) == CONST_INT
1832 && (const_ok_for_arm (INTVAL (op))
1833 || const_ok_for_arm (~INTVAL (op)))));
1836 /* Return TRUE if the operand is a memory reference which contains an
1837 offsettable address. */
1839 offsettable_memory_operand (op, mode)
1841 enum machine_mode mode;
1843 if (mode == VOIDmode)
1844 mode = GET_MODE (op);
1846 return (mode == GET_MODE (op)
1847 && GET_CODE (op) == MEM
1848 && offsettable_address_p (reload_completed | reload_in_progress,
1849 mode, XEXP (op, 0)));
1852 /* Return TRUE if the operand is a memory reference which is, or can be
1853 made word aligned by adjusting the offset. */
1855 alignable_memory_operand (op, mode)
1857 enum machine_mode mode;
1861 if (mode == VOIDmode)
1862 mode = GET_MODE (op);
1864 if (mode != GET_MODE (op) || GET_CODE (op) != MEM)
1869 return ((GET_CODE (reg = op) == REG
1870 || (GET_CODE (op) == SUBREG
1871 && GET_CODE (reg = SUBREG_REG (op)) == REG)
1872 || (GET_CODE (op) == PLUS
1873 && GET_CODE (XEXP (op, 1)) == CONST_INT
1874 && (GET_CODE (reg = XEXP (op, 0)) == REG
1875 || (GET_CODE (XEXP (op, 0)) == SUBREG
1876 && GET_CODE (reg = SUBREG_REG (XEXP (op, 0))) == REG))))
1877 && REGNO_POINTER_ALIGN (REGNO (reg)) >= 4);
1880 /* Similar to s_register_operand, but does not allow hard integer
1883 f_register_operand (op, mode)
1885 enum machine_mode mode;
1887 if (GET_MODE (op) != mode && mode != VOIDmode)
1890 if (GET_CODE (op) == SUBREG)
1891 op = SUBREG_REG (op);
1893 /* We don't consider registers whose class is NO_REGS
1894 to be a register operand. */
1895 return (GET_CODE (op) == REG
1896 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1897 || REGNO_REG_CLASS (REGNO (op)) == FPU_REGS));
1900 /* Return TRUE for valid operands for the rhs of an FPU instruction. */
1903 fpu_rhs_operand (op, mode)
1905 enum machine_mode mode;
1907 if (s_register_operand (op, mode))
1909 else if (GET_CODE (op) == CONST_DOUBLE)
1910 return (const_double_rtx_ok_for_fpu (op));
1916 fpu_add_operand (op, mode)
1918 enum machine_mode mode;
1920 if (s_register_operand (op, mode))
1922 else if (GET_CODE (op) == CONST_DOUBLE)
1923 return (const_double_rtx_ok_for_fpu (op)
1924 || neg_const_double_rtx_ok_for_fpu (op));
1929 /* Return nonzero if OP is a constant power of two. */
1932 power_of_two_operand (op, mode)
1934 enum machine_mode mode;
1936 if (GET_CODE (op) == CONST_INT)
1938 HOST_WIDE_INT value = INTVAL(op);
1939 return value != 0 && (value & (value - 1)) == 0;
1944 /* Return TRUE for a valid operand of a DImode operation.
1945 Either: REG, CONST_DOUBLE or MEM(DImode_address).
1946 Note that this disallows MEM(REG+REG), but allows
1947 MEM(PRE/POST_INC/DEC(REG)). */
1950 di_operand (op, mode)
1952 enum machine_mode mode;
1954 if (s_register_operand (op, mode))
1957 switch (GET_CODE (op))
1964 return memory_address_p (DImode, XEXP (op, 0));
1971 /* Return TRUE for a valid operand of a DFmode operation when -msoft-float.
1972 Either: REG, CONST_DOUBLE or MEM(DImode_address).
1973 Note that this disallows MEM(REG+REG), but allows
1974 MEM(PRE/POST_INC/DEC(REG)). */
1977 soft_df_operand (op, mode)
1979 enum machine_mode mode;
1981 if (s_register_operand (op, mode))
1984 switch (GET_CODE (op))
1990 return memory_address_p (DFmode, XEXP (op, 0));
1997 /* Return TRUE for valid index operands. */
2000 index_operand (op, mode)
2002 enum machine_mode mode;
2004 return (s_register_operand(op, mode)
2005 || (immediate_operand (op, mode)
2006 && INTVAL (op) < 4096 && INTVAL (op) > -4096));
2009 /* Return TRUE for valid shifts by a constant. This also accepts any
2010 power of two on the (somewhat overly relaxed) assumption that the
2011 shift operator in this case was a mult. */
2014 const_shift_operand (op, mode)
2016 enum machine_mode mode;
2018 return (power_of_two_operand (op, mode)
2019 || (immediate_operand (op, mode)
2020 && (INTVAL (op) < 32 && INTVAL (op) > 0)));
2023 /* Return TRUE for arithmetic operators which can be combined with a multiply
2027 shiftable_operator (x, mode)
2029 enum machine_mode mode;
2031 if (GET_MODE (x) != mode)
2035 enum rtx_code code = GET_CODE (x);
2037 return (code == PLUS || code == MINUS
2038 || code == IOR || code == XOR || code == AND);
2042 /* Return TRUE for shift operators. */
2045 shift_operator (x, mode)
2047 enum machine_mode mode;
2049 if (GET_MODE (x) != mode)
2053 enum rtx_code code = GET_CODE (x);
2056 return power_of_two_operand (XEXP (x, 1));
2058 return (code == ASHIFT || code == ASHIFTRT || code == LSHIFTRT
2059 || code == ROTATERT);
2063 int equality_operator (x, mode)
2065 enum machine_mode mode;
2067 return GET_CODE (x) == EQ || GET_CODE (x) == NE;
2070 /* Return TRUE for SMIN SMAX UMIN UMAX operators. */
2073 minmax_operator (x, mode)
2075 enum machine_mode mode;
2077 enum rtx_code code = GET_CODE (x);
2079 if (GET_MODE (x) != mode)
2082 return code == SMIN || code == SMAX || code == UMIN || code == UMAX;
2085 /* return TRUE if x is EQ or NE */
2087 /* Return TRUE if this is the condition code register, if we aren't given
2088 a mode, accept any class CCmode register */
2091 cc_register (x, mode)
2093 enum machine_mode mode;
2095 if (mode == VOIDmode)
2097 mode = GET_MODE (x);
2098 if (GET_MODE_CLASS (mode) != MODE_CC)
2102 if (mode == GET_MODE (x) && GET_CODE (x) == REG && REGNO (x) == 24)
2108 /* Return TRUE if this is the condition code register, if we aren't given
2109 a mode, accept any class CCmode register which indicates a dominance
2113 dominant_cc_register (x, mode)
2115 enum machine_mode mode;
2117 if (mode == VOIDmode)
2119 mode = GET_MODE (x);
2120 if (GET_MODE_CLASS (mode) != MODE_CC)
2124 if (mode != CC_DNEmode && mode != CC_DEQmode
2125 && mode != CC_DLEmode && mode != CC_DLTmode
2126 && mode != CC_DGEmode && mode != CC_DGTmode
2127 && mode != CC_DLEUmode && mode != CC_DLTUmode
2128 && mode != CC_DGEUmode && mode != CC_DGTUmode)
2131 if (mode == GET_MODE (x) && GET_CODE (x) == REG && REGNO (x) == 24)
2137 /* Return TRUE if X references a SYMBOL_REF. */
2139 symbol_mentioned_p (x)
2145 if (GET_CODE (x) == SYMBOL_REF)
2148 fmt = GET_RTX_FORMAT (GET_CODE (x));
2149 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2155 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2156 if (symbol_mentioned_p (XVECEXP (x, i, j)))
2159 else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i)))
2166 /* Return TRUE if X references a LABEL_REF. */
2168 label_mentioned_p (x)
2174 if (GET_CODE (x) == LABEL_REF)
2177 fmt = GET_RTX_FORMAT (GET_CODE (x));
2178 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2184 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2185 if (label_mentioned_p (XVECEXP (x, i, j)))
2188 else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i)))
2199 enum rtx_code code = GET_CODE (x);
2203 else if (code == SMIN)
2205 else if (code == UMIN)
2207 else if (code == UMAX)
2213 /* Return 1 if memory locations are adjacent */
2216 adjacent_mem_locations (a, b)
2219 int val0 = 0, val1 = 0;
2222 if ((GET_CODE (XEXP (a, 0)) == REG
2223 || (GET_CODE (XEXP (a, 0)) == PLUS
2224 && GET_CODE (XEXP (XEXP (a, 0), 1)) == CONST_INT))
2225 && (GET_CODE (XEXP (b, 0)) == REG
2226 || (GET_CODE (XEXP (b, 0)) == PLUS
2227 && GET_CODE (XEXP (XEXP (b, 0), 1)) == CONST_INT)))
2229 if (GET_CODE (XEXP (a, 0)) == PLUS)
2231 reg0 = REGNO (XEXP (XEXP (a, 0), 0));
2232 val0 = INTVAL (XEXP (XEXP (a, 0), 1));
2235 reg0 = REGNO (XEXP (a, 0));
2236 if (GET_CODE (XEXP (b, 0)) == PLUS)
2238 reg1 = REGNO (XEXP (XEXP (b, 0), 0));
2239 val1 = INTVAL (XEXP (XEXP (b, 0), 1));
2242 reg1 = REGNO (XEXP (b, 0));
2243 return (reg0 == reg1) && ((val1 - val0) == 4 || (val0 - val1) == 4);
2248 /* Return 1 if OP is a load multiple operation. It is known to be
2249 parallel and the first section will be tested. */
2252 load_multiple_operation (op, mode)
2254 enum machine_mode mode;
2256 HOST_WIDE_INT count = XVECLEN (op, 0);
2259 HOST_WIDE_INT i = 1, base = 0;
2263 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
2266 /* Check to see if this might be a write-back */
2267 if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
2272 /* Now check it more carefully */
2273 if (GET_CODE (SET_DEST (elt)) != REG
2274 || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
2275 || REGNO (XEXP (SET_SRC (elt), 0)) != REGNO (SET_DEST (elt))
2276 || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
2277 || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 2) * 4
2278 || GET_CODE (XVECEXP (op, 0, count - 1)) != CLOBBER
2279 || GET_CODE (XEXP (XVECEXP (op, 0, count - 1), 0)) != REG
2280 || REGNO (XEXP (XVECEXP (op, 0, count - 1), 0))
2281 != REGNO (SET_DEST (elt)))
2287 /* Perform a quick check so we don't blow up below. */
2289 || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
2290 || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != REG
2291 || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != MEM)
2294 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, i - 1)));
2295 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, i - 1)), 0);
2297 for (; i < count; i++)
2299 elt = XVECEXP (op, 0, i);
2301 if (GET_CODE (elt) != SET
2302 || GET_CODE (SET_DEST (elt)) != REG
2303 || GET_MODE (SET_DEST (elt)) != SImode
2304 || REGNO (SET_DEST (elt)) != dest_regno + i - base
2305 || GET_CODE (SET_SRC (elt)) != MEM
2306 || GET_MODE (SET_SRC (elt)) != SImode
2307 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
2308 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
2309 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
2310 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != (i - base) * 4)
2317 /* Return 1 if OP is a store multiple operation. It is known to be
2318 parallel and the first section will be tested. */
2321 store_multiple_operation (op, mode)
2323 enum machine_mode mode;
2325 HOST_WIDE_INT count = XVECLEN (op, 0);
2328 HOST_WIDE_INT i = 1, base = 0;
2332 || GET_CODE (XVECEXP (op, 0, 0)) != SET)
2335 /* Check to see if this might be a write-back */
2336 if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS)
2341 /* Now check it more carefully */
2342 if (GET_CODE (SET_DEST (elt)) != REG
2343 || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG
2344 || REGNO (XEXP (SET_SRC (elt), 0)) != REGNO (SET_DEST (elt))
2345 || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT
2346 || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 2) * 4
2347 || GET_CODE (XVECEXP (op, 0, count - 1)) != CLOBBER
2348 || GET_CODE (XEXP (XVECEXP (op, 0, count - 1), 0)) != REG
2349 || REGNO (XEXP (XVECEXP (op, 0, count - 1), 0))
2350 != REGNO (SET_DEST (elt)))
2356 /* Perform a quick check so we don't blow up below. */
2358 || GET_CODE (XVECEXP (op, 0, i - 1)) != SET
2359 || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != MEM
2360 || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != REG)
2363 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, i - 1)));
2364 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, i - 1)), 0);
2366 for (; i < count; i++)
2368 elt = XVECEXP (op, 0, i);
2370 if (GET_CODE (elt) != SET
2371 || GET_CODE (SET_SRC (elt)) != REG
2372 || GET_MODE (SET_SRC (elt)) != SImode
2373 || REGNO (SET_SRC (elt)) != src_regno + i - base
2374 || GET_CODE (SET_DEST (elt)) != MEM
2375 || GET_MODE (SET_DEST (elt)) != SImode
2376 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
2377 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
2378 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
2379 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != (i - base) * 4)
2387 load_multiple_sequence (operands, nops, regs, base, load_offset)
2392 HOST_WIDE_INT *load_offset;
2394 int unsorted_regs[4];
2395 HOST_WIDE_INT unsorted_offsets[4];
2400 /* Can only handle 2, 3, or 4 insns at present, though could be easily
2401 extended if required. */
2402 if (nops < 2 || nops > 4)
2405 /* Loop over the operands and check that the memory references are
2406 suitable (ie immediate offsets from the same base register). At
2407 the same time, extract the target register, and the memory
2409 for (i = 0; i < nops; i++)
2414 /* Convert a subreg of a mem into the mem itself. */
2415 if (GET_CODE (operands[nops + i]) == SUBREG)
2416 operands[nops + i] = alter_subreg(operands[nops + i]);
2418 if (GET_CODE (operands[nops + i]) != MEM)
2421 /* Don't reorder volatile memory references; it doesn't seem worth
2422 looking for the case where the order is ok anyway. */
2423 if (MEM_VOLATILE_P (operands[nops + i]))
2426 offset = const0_rtx;
2428 if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG
2429 || (GET_CODE (reg) == SUBREG
2430 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2431 || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS
2432 && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0))
2434 || (GET_CODE (reg) == SUBREG
2435 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2436 && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1))
2441 base_reg = REGNO(reg);
2442 unsorted_regs[0] = (GET_CODE (operands[i]) == REG
2443 ? REGNO (operands[i])
2444 : REGNO (SUBREG_REG (operands[i])));
2449 if (base_reg != REGNO (reg))
2450 /* Not addressed from the same base register. */
2453 unsorted_regs[i] = (GET_CODE (operands[i]) == REG
2454 ? REGNO (operands[i])
2455 : REGNO (SUBREG_REG (operands[i])));
2456 if (unsorted_regs[i] < unsorted_regs[order[0]])
2460 /* If it isn't an integer register, or if it overwrites the
2461 base register but isn't the last insn in the list, then
2462 we can't do this. */
2463 if (unsorted_regs[i] < 0 || unsorted_regs[i] > 14
2464 || (i != nops - 1 && unsorted_regs[i] == base_reg))
2467 unsorted_offsets[i] = INTVAL (offset);
2470 /* Not a suitable memory address. */
2474 /* All the useful information has now been extracted from the
2475 operands into unsorted_regs and unsorted_offsets; additionally,
2476 order[0] has been set to the lowest numbered register in the
2477 list. Sort the registers into order, and check that the memory
2478 offsets are ascending and adjacent. */
2480 for (i = 1; i < nops; i++)
2484 order[i] = order[i - 1];
2485 for (j = 0; j < nops; j++)
2486 if (unsorted_regs[j] > unsorted_regs[order[i - 1]]
2487 && (order[i] == order[i - 1]
2488 || unsorted_regs[j] < unsorted_regs[order[i]]))
2491 /* Have we found a suitable register? if not, one must be used more
2493 if (order[i] == order[i - 1])
2496 /* Is the memory address adjacent and ascending? */
2497 if (unsorted_offsets[order[i]] != unsorted_offsets[order[i - 1]] + 4)
2505 for (i = 0; i < nops; i++)
2506 regs[i] = unsorted_regs[order[i]];
2508 *load_offset = unsorted_offsets[order[0]];
2511 if (unsorted_offsets[order[0]] == 0)
2512 return 1; /* ldmia */
2514 if (unsorted_offsets[order[0]] == 4)
2515 return 2; /* ldmib */
2517 if (unsorted_offsets[order[nops - 1]] == 0)
2518 return 3; /* ldmda */
2520 if (unsorted_offsets[order[nops - 1]] == -4)
2521 return 4; /* ldmdb */
2523 /* Can't do it without setting up the offset, only do this if it takes
2524 no more than one insn. */
2525 return (const_ok_for_arm (unsorted_offsets[order[0]])
2526 || const_ok_for_arm (-unsorted_offsets[order[0]])) ? 5 : 0;
2530 emit_ldm_seq (operands, nops)
2536 HOST_WIDE_INT offset;
2540 switch (load_multiple_sequence (operands, nops, regs, &base_reg, &offset))
2543 strcpy (buf, "ldm%?ia\t");
2547 strcpy (buf, "ldm%?ib\t");
2551 strcpy (buf, "ldm%?da\t");
2555 strcpy (buf, "ldm%?db\t");
2560 sprintf (buf, "add%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX,
2561 reg_names[regs[0]], REGISTER_PREFIX, reg_names[base_reg],
2564 sprintf (buf, "sub%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX,
2565 reg_names[regs[0]], REGISTER_PREFIX, reg_names[base_reg],
2567 output_asm_insn (buf, operands);
2569 strcpy (buf, "ldm%?ia\t");
2576 sprintf (buf + strlen (buf), "%s%s, {%s%s", REGISTER_PREFIX,
2577 reg_names[base_reg], REGISTER_PREFIX, reg_names[regs[0]]);
2579 for (i = 1; i < nops; i++)
2580 sprintf (buf + strlen (buf), ", %s%s", REGISTER_PREFIX,
2581 reg_names[regs[i]]);
2583 strcat (buf, "}\t%@ phole ldm");
2585 output_asm_insn (buf, operands);
2590 store_multiple_sequence (operands, nops, regs, base, load_offset)
2595 HOST_WIDE_INT *load_offset;
2597 int unsorted_regs[4];
2598 HOST_WIDE_INT unsorted_offsets[4];
2603 /* Can only handle 2, 3, or 4 insns at present, though could be easily
2604 extended if required. */
2605 if (nops < 2 || nops > 4)
2608 /* Loop over the operands and check that the memory references are
2609 suitable (ie immediate offsets from the same base register). At
2610 the same time, extract the target register, and the memory
2612 for (i = 0; i < nops; i++)
2617 /* Convert a subreg of a mem into the mem itself. */
2618 if (GET_CODE (operands[nops + i]) == SUBREG)
2619 operands[nops + i] = alter_subreg(operands[nops + i]);
2621 if (GET_CODE (operands[nops + i]) != MEM)
2624 /* Don't reorder volatile memory references; it doesn't seem worth
2625 looking for the case where the order is ok anyway. */
2626 if (MEM_VOLATILE_P (operands[nops + i]))
2629 offset = const0_rtx;
2631 if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG
2632 || (GET_CODE (reg) == SUBREG
2633 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2634 || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS
2635 && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0))
2637 || (GET_CODE (reg) == SUBREG
2638 && GET_CODE (reg = SUBREG_REG (reg)) == REG))
2639 && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1))
2644 base_reg = REGNO(reg);
2645 unsorted_regs[0] = (GET_CODE (operands[i]) == REG
2646 ? REGNO (operands[i])
2647 : REGNO (SUBREG_REG (operands[i])));
2652 if (base_reg != REGNO (reg))
2653 /* Not addressed from the same base register. */
2656 unsorted_regs[i] = (GET_CODE (operands[i]) == REG
2657 ? REGNO (operands[i])
2658 : REGNO (SUBREG_REG (operands[i])));
2659 if (unsorted_regs[i] < unsorted_regs[order[0]])
2663 /* If it isn't an integer register, then we can't do this. */
2664 if (unsorted_regs[i] < 0 || unsorted_regs[i] > 14)
2667 unsorted_offsets[i] = INTVAL (offset);
2670 /* Not a suitable memory address. */
2674 /* All the useful information has now been extracted from the
2675 operands into unsorted_regs and unsorted_offsets; additionally,
2676 order[0] has been set to the lowest numbered register in the
2677 list. Sort the registers into order, and check that the memory
2678 offsets are ascending and adjacent. */
2680 for (i = 1; i < nops; i++)
2684 order[i] = order[i - 1];
2685 for (j = 0; j < nops; j++)
2686 if (unsorted_regs[j] > unsorted_regs[order[i - 1]]
2687 && (order[i] == order[i - 1]
2688 || unsorted_regs[j] < unsorted_regs[order[i]]))
2691 /* Have we found a suitable register? if not, one must be used more
2693 if (order[i] == order[i - 1])
2696 /* Is the memory address adjacent and ascending? */
2697 if (unsorted_offsets[order[i]] != unsorted_offsets[order[i - 1]] + 4)
2705 for (i = 0; i < nops; i++)
2706 regs[i] = unsorted_regs[order[i]];
2708 *load_offset = unsorted_offsets[order[0]];
2711 if (unsorted_offsets[order[0]] == 0)
2712 return 1; /* stmia */
2714 if (unsorted_offsets[order[0]] == 4)
2715 return 2; /* stmib */
2717 if (unsorted_offsets[order[nops - 1]] == 0)
2718 return 3; /* stmda */
2720 if (unsorted_offsets[order[nops - 1]] == -4)
2721 return 4; /* stmdb */
2727 emit_stm_seq (operands, nops)
2733 HOST_WIDE_INT offset;
2737 switch (store_multiple_sequence (operands, nops, regs, &base_reg, &offset))
2740 strcpy (buf, "stm%?ia\t");
2744 strcpy (buf, "stm%?ib\t");
2748 strcpy (buf, "stm%?da\t");
2752 strcpy (buf, "stm%?db\t");
2759 sprintf (buf + strlen (buf), "%s%s, {%s%s", REGISTER_PREFIX,
2760 reg_names[base_reg], REGISTER_PREFIX, reg_names[regs[0]]);
2762 for (i = 1; i < nops; i++)
2763 sprintf (buf + strlen (buf), ", %s%s", REGISTER_PREFIX,
2764 reg_names[regs[i]]);
2766 strcat (buf, "}\t%@ phole stm");
2768 output_asm_insn (buf, operands);
2773 multi_register_push (op, mode)
2775 enum machine_mode mode;
2777 if (GET_CODE (op) != PARALLEL
2778 || (GET_CODE (XVECEXP (op, 0, 0)) != SET)
2779 || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC)
2780 || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != 2))
2787 /* Routines for use with attributes */
2789 /* Return nonzero if ATTR is a valid attribute for DECL.
2790 ATTRIBUTES are any existing attributes and ARGS are the arguments
2793 Supported attributes:
2795 naked: don't output any prologue or epilogue code, the user is assumed
2796 to do the right thing. */
2799 arm_valid_machine_decl_attribute (decl, attributes, attr, args)
2805 if (args != NULL_TREE)
2808 if (is_attribute_p ("naked", attr))
2809 return TREE_CODE (decl) == FUNCTION_DECL;
2813 /* Return non-zero if FUNC is a naked function. */
2816 arm_naked_function_p (func)
2821 if (TREE_CODE (func) != FUNCTION_DECL)
2824 a = lookup_attribute ("naked", DECL_MACHINE_ATTRIBUTES (func));
2825 return a != NULL_TREE;
2828 /* Routines for use in generating RTL */
2831 arm_gen_load_multiple (base_regno, count, from, up, write_back, unchanging_p,
2843 int sign = up ? 1 : -1;
2846 result = gen_rtx (PARALLEL, VOIDmode,
2847 rtvec_alloc (count + (write_back ? 2 : 0)));
2850 XVECEXP (result, 0, 0)
2851 = gen_rtx (SET, GET_MODE (from), from,
2852 plus_constant (from, count * 4 * sign));
2857 for (j = 0; i < count; i++, j++)
2859 mem = gen_rtx (MEM, SImode, plus_constant (from, j * 4 * sign));
2860 RTX_UNCHANGING_P (mem) = unchanging_p;
2861 MEM_IN_STRUCT_P (mem) = in_struct_p;
2863 XVECEXP (result, 0, i) = gen_rtx (SET, VOIDmode,
2864 gen_rtx (REG, SImode, base_regno + j),
2869 XVECEXP (result, 0, i) = gen_rtx (CLOBBER, SImode, from);
2875 arm_gen_store_multiple (base_regno, count, to, up, write_back, unchanging_p,
2887 int sign = up ? 1 : -1;
2890 result = gen_rtx (PARALLEL, VOIDmode,
2891 rtvec_alloc (count + (write_back ? 2 : 0)));
2894 XVECEXP (result, 0, 0)
2895 = gen_rtx (SET, GET_MODE (to), to,
2896 plus_constant (to, count * 4 * sign));
2901 for (j = 0; i < count; i++, j++)
2903 mem = gen_rtx (MEM, SImode, plus_constant (to, j * 4 * sign));
2904 RTX_UNCHANGING_P (mem) = unchanging_p;
2905 MEM_IN_STRUCT_P (mem) = in_struct_p;
2907 XVECEXP (result, 0, i) = gen_rtx (SET, VOIDmode, mem,
2908 gen_rtx (REG, SImode, base_regno + j));
2912 XVECEXP (result, 0, i) = gen_rtx (CLOBBER, SImode, to);
2918 arm_gen_movstrqi (operands)
2921 HOST_WIDE_INT in_words_to_go, out_words_to_go, last_bytes;
2924 rtx st_src, st_dst, fin_src, fin_dst;
2925 rtx part_bytes_reg = NULL;
2927 int dst_unchanging_p, dst_in_struct_p, src_unchanging_p, src_in_struct_p;
2929 if (GET_CODE (operands[2]) != CONST_INT
2930 || GET_CODE (operands[3]) != CONST_INT
2931 || INTVAL (operands[2]) > 64
2932 || INTVAL (operands[3]) & 3)
2935 st_dst = XEXP (operands[0], 0);
2936 st_src = XEXP (operands[1], 0);
2938 dst_unchanging_p = RTX_UNCHANGING_P (operands[0]);
2939 dst_in_struct_p = MEM_IN_STRUCT_P (operands[0]);
2940 src_unchanging_p = RTX_UNCHANGING_P (operands[1]);
2941 src_in_struct_p = MEM_IN_STRUCT_P (operands[1]);
2943 fin_dst = dst = copy_to_mode_reg (SImode, st_dst);
2944 fin_src = src = copy_to_mode_reg (SImode, st_src);
2946 in_words_to_go = (INTVAL (operands[2]) + 3) / 4;
2947 out_words_to_go = INTVAL (operands[2]) / 4;
2948 last_bytes = INTVAL (operands[2]) & 3;
2950 if (out_words_to_go != in_words_to_go && ((in_words_to_go - 1) & 3) != 0)
2951 part_bytes_reg = gen_rtx (REG, SImode, (in_words_to_go - 1) & 3);
2953 for (i = 0; in_words_to_go >= 2; i+=4)
2955 if (in_words_to_go > 4)
2956 emit_insn (arm_gen_load_multiple (0, 4, src, TRUE, TRUE,
2957 src_unchanging_p, src_in_struct_p));
2959 emit_insn (arm_gen_load_multiple (0, in_words_to_go, src, TRUE,
2960 FALSE, src_unchanging_p,
2963 if (out_words_to_go)
2965 if (out_words_to_go > 4)
2966 emit_insn (arm_gen_store_multiple (0, 4, dst, TRUE, TRUE,
2969 else if (out_words_to_go != 1)
2970 emit_insn (arm_gen_store_multiple (0, out_words_to_go,
2978 mem = gen_rtx (MEM, SImode, dst);
2979 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
2980 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
2981 emit_move_insn (mem, gen_rtx (REG, SImode, 0));
2982 if (last_bytes != 0)
2983 emit_insn (gen_addsi3 (dst, dst, GEN_INT (4)));
2987 in_words_to_go -= in_words_to_go < 4 ? in_words_to_go : 4;
2988 out_words_to_go -= out_words_to_go < 4 ? out_words_to_go : 4;
2991 /* OUT_WORDS_TO_GO will be zero here if there are byte stores to do. */
2992 if (out_words_to_go)
2996 mem = gen_rtx (MEM, SImode, src);
2997 RTX_UNCHANGING_P (mem) = src_unchanging_p;
2998 MEM_IN_STRUCT_P (mem) = src_in_struct_p;
2999 emit_move_insn (sreg = gen_reg_rtx (SImode), mem);
3000 emit_move_insn (fin_src = gen_reg_rtx (SImode), plus_constant (src, 4));
3002 mem = gen_rtx (MEM, SImode, dst);
3003 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3004 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3005 emit_move_insn (mem, sreg);
3006 emit_move_insn (fin_dst = gen_reg_rtx (SImode), plus_constant (dst, 4));
3009 if (in_words_to_go) /* Sanity check */
3015 if (in_words_to_go < 0)
3018 mem = gen_rtx (MEM, SImode, src);
3019 RTX_UNCHANGING_P (mem) = src_unchanging_p;
3020 MEM_IN_STRUCT_P (mem) = src_in_struct_p;
3021 part_bytes_reg = copy_to_mode_reg (SImode, mem);
3024 if (BYTES_BIG_ENDIAN && last_bytes)
3026 rtx tmp = gen_reg_rtx (SImode);
3028 if (part_bytes_reg == NULL)
3031 /* The bytes we want are in the top end of the word */
3032 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg,
3033 GEN_INT (8 * (4 - last_bytes))));
3034 part_bytes_reg = tmp;
3038 mem = gen_rtx (MEM, QImode, plus_constant (dst, last_bytes - 1));
3039 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3040 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3041 emit_move_insn (mem, gen_rtx (SUBREG, QImode, part_bytes_reg, 0));
3044 tmp = gen_reg_rtx (SImode);
3045 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8)));
3046 part_bytes_reg = tmp;
3055 if (part_bytes_reg == NULL)
3058 mem = gen_rtx (MEM, QImode, dst);
3059 RTX_UNCHANGING_P (mem) = dst_unchanging_p;
3060 MEM_IN_STRUCT_P (mem) = dst_in_struct_p;
3061 emit_move_insn (mem, gen_rtx (SUBREG, QImode, part_bytes_reg, 0));
3064 rtx tmp = gen_reg_rtx (SImode);
3066 emit_insn (gen_addsi3 (dst, dst, const1_rtx));
3067 emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8)));
3068 part_bytes_reg = tmp;
3076 /* Generate a memory reference for a half word, such that it will be loaded
3077 into the top 16 bits of the word. We can assume that the address is
3078 known to be alignable and of the form reg, or plus (reg, const). */
3080 gen_rotated_half_load (memref)
3083 HOST_WIDE_INT offset = 0;
3084 rtx base = XEXP (memref, 0);
3086 if (GET_CODE (base) == PLUS)
3088 offset = INTVAL (XEXP (base, 1));
3089 base = XEXP (base, 0);
3092 /* If we aren't allowed to generate unaligned addresses, then fail. */
3093 if (TARGET_SHORT_BY_BYTES
3094 && ((BYTES_BIG_ENDIAN ? 1 : 0) ^ ((offset & 2) == 0)))
3097 base = gen_rtx (MEM, SImode, plus_constant (base, offset & ~2));
3099 if ((BYTES_BIG_ENDIAN ? 1 : 0) ^ ((offset & 2) == 2))
3102 return gen_rtx (ROTATE, SImode, base, GEN_INT (16));
3105 static enum machine_mode
3106 select_dominance_cc_mode (op, x, y, cond_or)
3110 HOST_WIDE_INT cond_or;
3112 enum rtx_code cond1, cond2;
3115 /* Currently we will probably get the wrong result if the individual
3116 comparisons are not simple. This also ensures that it is safe to
3117 reverse a comparison if necessary. */
3118 if ((arm_select_cc_mode (cond1 = GET_CODE (x), XEXP (x, 0), XEXP (x, 1))
3120 || (arm_select_cc_mode (cond2 = GET_CODE (y), XEXP (y, 0), XEXP (y, 1))
3125 cond1 = reverse_condition (cond1);
3127 /* If the comparisons are not equal, and one doesn't dominate the other,
3128 then we can't do this. */
3130 && ! comparison_dominates_p (cond1, cond2)
3131 && (swapped = 1, ! comparison_dominates_p (cond2, cond1)))
3136 enum rtx_code temp = cond1;
3144 if (cond2 == EQ || ! cond_or)
3149 case LE: return CC_DLEmode;
3150 case LEU: return CC_DLEUmode;
3151 case GE: return CC_DGEmode;
3152 case GEU: return CC_DGEUmode;
3159 if (cond2 == LT || ! cond_or)
3168 if (cond2 == GT || ! cond_or)
3177 if (cond2 == LTU || ! cond_or)
3186 if (cond2 == GTU || ! cond_or)
3194 /* The remaining cases only occur when both comparisons are the
3219 arm_select_cc_mode (op, x, y)
3224 /* All floating point compares return CCFP if it is an equality
3225 comparison, and CCFPE otherwise. */
3226 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
3227 return (op == EQ || op == NE) ? CCFPmode : CCFPEmode;
3229 /* A compare with a shifted operand. Because of canonicalization, the
3230 comparison will have to be swapped when we emit the assembler. */
3231 if (GET_MODE (y) == SImode && GET_CODE (y) == REG
3232 && (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
3233 || GET_CODE (x) == LSHIFTRT || GET_CODE (x) == ROTATE
3234 || GET_CODE (x) == ROTATERT))
3237 /* This is a special case that is used by combine to allow a
3238 comparison of a shifted byte load to be split into a zero-extend
3239 followed by a comparison of the shifted integer (only valid for
3240 equalities and unsigned inequalities). */
3241 if (GET_MODE (x) == SImode
3242 && GET_CODE (x) == ASHIFT
3243 && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 24
3244 && GET_CODE (XEXP (x, 0)) == SUBREG
3245 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == MEM
3246 && GET_MODE (SUBREG_REG (XEXP (x, 0))) == QImode
3247 && (op == EQ || op == NE
3248 || op == GEU || op == GTU || op == LTU || op == LEU)
3249 && GET_CODE (y) == CONST_INT)
3252 /* An operation that sets the condition codes as a side-effect, the
3253 V flag is not set correctly, so we can only use comparisons where
3254 this doesn't matter. (For LT and GE we can use "mi" and "pl"
3256 if (GET_MODE (x) == SImode
3258 && (op == EQ || op == NE || op == LT || op == GE)
3259 && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS
3260 || GET_CODE (x) == AND || GET_CODE (x) == IOR
3261 || GET_CODE (x) == XOR || GET_CODE (x) == MULT
3262 || GET_CODE (x) == NOT || GET_CODE (x) == NEG
3263 || GET_CODE (x) == LSHIFTRT
3264 || GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
3265 || GET_CODE (x) == ROTATERT || GET_CODE (x) == ZERO_EXTRACT))
3268 /* A construct for a conditional compare, if the false arm contains
3269 0, then both conditions must be true, otherwise either condition
3270 must be true. Not all conditions are possible, so CCmode is
3271 returned if it can't be done. */
3272 if (GET_CODE (x) == IF_THEN_ELSE
3273 && (XEXP (x, 2) == const0_rtx
3274 || XEXP (x, 2) == const1_rtx)
3275 && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<'
3276 && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<')
3277 return select_dominance_cc_mode (op, XEXP (x, 0), XEXP (x, 1),
3278 INTVAL (XEXP (x, 2)));
3280 if (GET_MODE (x) == QImode && (op == EQ || op == NE))
3283 if (GET_MODE (x) == SImode && (op == LTU || op == GEU)
3284 && GET_CODE (x) == PLUS
3285 && (rtx_equal_p (XEXP (x, 0), y) || rtx_equal_p (XEXP (x, 1), y)))
3291 /* X and Y are two things to compare using CODE. Emit the compare insn and
3292 return the rtx for register 0 in the proper mode. FP means this is a
3293 floating point compare: I don't think that it is needed on the arm. */
3296 gen_compare_reg (code, x, y, fp)
3301 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
3302 rtx cc_reg = gen_rtx (REG, mode, 24);
3304 emit_insn (gen_rtx (SET, VOIDmode, cc_reg,
3305 gen_rtx (COMPARE, mode, x, y)));
3311 arm_reload_in_hi (operands)
3314 rtx base = find_replacement (&XEXP (operands[1], 0));
3316 emit_insn (gen_zero_extendqisi2 (operands[2], gen_rtx (MEM, QImode, base)));
3317 /* Handle the case where the address is too complex to be offset by 1. */
3318 if (GET_CODE (base) == MINUS
3319 || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT))
3321 rtx base_plus = gen_rtx (REG, SImode, REGNO (operands[0]));
3323 emit_insn (gen_rtx (SET, VOIDmode, base_plus, base));
3327 emit_insn (gen_zero_extendqisi2 (gen_rtx (SUBREG, SImode, operands[0], 0),
3328 gen_rtx (MEM, QImode,
3329 plus_constant (base, 1))));
3330 if (BYTES_BIG_ENDIAN)
3331 emit_insn (gen_rtx (SET, VOIDmode, gen_rtx (SUBREG, SImode,
3333 gen_rtx (IOR, SImode,
3334 gen_rtx (ASHIFT, SImode,
3335 gen_rtx (SUBREG, SImode,
3340 emit_insn (gen_rtx (SET, VOIDmode, gen_rtx (SUBREG, SImode,
3342 gen_rtx (IOR, SImode,
3343 gen_rtx (ASHIFT, SImode,
3346 gen_rtx (SUBREG, SImode, operands[0], 0))));
3350 arm_reload_out_hi (operands)
3353 rtx base = find_replacement (&XEXP (operands[0], 0));
3355 if (BYTES_BIG_ENDIAN)
3357 emit_insn (gen_movqi (gen_rtx (MEM, QImode, plus_constant (base, 1)),
3358 gen_rtx (SUBREG, QImode, operands[1], 0)));
3359 emit_insn (gen_lshrsi3 (operands[2],
3360 gen_rtx (SUBREG, SImode, operands[1], 0),
3362 emit_insn (gen_movqi (gen_rtx (MEM, QImode, base),
3363 gen_rtx (SUBREG, QImode, operands[2], 0)));
3367 emit_insn (gen_movqi (gen_rtx (MEM, QImode, base),
3368 gen_rtx (SUBREG, QImode, operands[1], 0)));
3369 emit_insn (gen_lshrsi3 (operands[2],
3370 gen_rtx (SUBREG, SImode, operands[1], 0),
3372 emit_insn (gen_movqi (gen_rtx (MEM, QImode, plus_constant (base, 1)),
3373 gen_rtx (SUBREG, QImode, operands[2], 0)));
3377 /* Routines for manipulation of the constant pool. */
3378 /* This is unashamedly hacked from the version in sh.c, since the problem is
3379 extremely similar. */
3381 /* Arm instructions cannot load a large constant into a register,
3382 constants have to come from a pc relative load. The reference of a pc
3383 relative load instruction must be less than 1k infront of the instruction.
3384 This means that we often have to dump a constant inside a function, and
3385 generate code to branch around it.
3387 It is important to minimize this, since the branches will slow things
3388 down and make things bigger.
3390 Worst case code looks like:
3406 We fix this by performing a scan before scheduling, which notices which
3407 instructions need to have their operands fetched from the constant table
3408 and builds the table.
3413 scan, find an instruction which needs a pcrel move. Look forward, find th
3414 last barrier which is within MAX_COUNT bytes of the requirement.
3415 If there isn't one, make one. Process all the instructions between
3416 the find and the barrier.
3418 In the above example, we can tell that L3 is within 1k of L1, so
3419 the first move can be shrunk from the 2 insn+constant sequence into
3420 just 1 insn, and the constant moved to L3 to make:
3431 Then the second move becomes the target for the shortening process.
3437 rtx value; /* Value in table */
3438 HOST_WIDE_INT next_offset;
3439 enum machine_mode mode; /* Mode of value */
3442 /* The maximum number of constants that can fit into one pool, since
3443 the pc relative range is 0...1020 bytes and constants are at least 4
3446 #define MAX_POOL_SIZE (1020/4)
3447 static pool_node pool_vector[MAX_POOL_SIZE];
3448 static int pool_size;
3449 static rtx pool_vector_label;
3451 /* Add a constant to the pool and return its offset within the current
3454 X is the rtx we want to replace. MODE is its mode. On return,
3455 ADDRESS_ONLY will be non-zero if we really want the address of such
3456 a constant, not the constant itself. */
3457 static HOST_WIDE_INT
3458 add_constant (x, mode, address_only)
3460 enum machine_mode mode;
3464 HOST_WIDE_INT offset;
3467 if (mode == SImode && GET_CODE (x) == MEM && CONSTANT_P (XEXP (x, 0))
3468 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
3469 x = get_pool_constant (XEXP (x, 0));
3470 else if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P(x))
3473 x = get_pool_constant (x);
3475 #ifndef AOF_ASSEMBLER
3476 else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == 3)
3477 x = XVECEXP (x, 0, 0);
3480 #ifdef AOF_ASSEMBLER
3481 /* PIC Symbol references need to be converted into offsets into the
3483 if (flag_pic && GET_CODE (x) == SYMBOL_REF)
3484 x = aof_pic_entry (x);
3485 #endif /* AOF_ASSEMBLER */
3487 /* First see if we've already got it */
3488 for (i = 0; i < pool_size; i++)
3490 if (GET_CODE (x) == pool_vector[i].value->code
3491 && mode == pool_vector[i].mode)
3493 if (GET_CODE (x) == CODE_LABEL)
3495 if (XINT (x, 3) != XINT (pool_vector[i].value, 3))
3498 if (rtx_equal_p (x, pool_vector[i].value))
3499 return pool_vector[i].next_offset - GET_MODE_SIZE (mode);
3503 /* Need a new one */
3504 pool_vector[pool_size].next_offset = GET_MODE_SIZE (mode);
3507 pool_vector_label = gen_label_rtx ();
3509 pool_vector[pool_size].next_offset
3510 += (offset = pool_vector[pool_size - 1].next_offset);
3512 pool_vector[pool_size].value = x;
3513 pool_vector[pool_size].mode = mode;
3518 /* Output the literal table */
3525 scan = emit_label_after (gen_label_rtx (), scan);
3526 scan = emit_insn_after (gen_align_4 (), scan);
3527 scan = emit_label_after (pool_vector_label, scan);
3529 for (i = 0; i < pool_size; i++)
3531 pool_node *p = pool_vector + i;
3533 switch (GET_MODE_SIZE (p->mode))
3536 scan = emit_insn_after (gen_consttable_4 (p->value), scan);
3540 scan = emit_insn_after (gen_consttable_8 (p->value), scan);
3549 scan = emit_insn_after (gen_consttable_end (), scan);
3550 scan = emit_barrier_after (scan);
3554 /* Non zero if the src operand needs to be fixed up */
3556 fixit (src, mode, destreg)
3558 enum machine_mode mode;
3561 if (CONSTANT_P (src))
3563 if (GET_CODE (src) == CONST_INT)
3564 return (! const_ok_for_arm (INTVAL (src))
3565 && ! const_ok_for_arm (~INTVAL (src)));
3566 if (GET_CODE (src) == CONST_DOUBLE)
3567 return (GET_MODE (src) == VOIDmode
3569 || (! const_double_rtx_ok_for_fpu (src)
3570 && ! neg_const_double_rtx_ok_for_fpu (src)));
3571 return symbol_mentioned_p (src);
3573 #ifndef AOF_ASSEMBLER
3574 else if (GET_CODE (src) == UNSPEC && XINT (src, 1) == 3)
3578 return (mode == SImode && GET_CODE (src) == MEM
3579 && GET_CODE (XEXP (src, 0)) == SYMBOL_REF
3580 && CONSTANT_POOL_ADDRESS_P (XEXP (src, 0)));
3583 /* Find the last barrier less than MAX_COUNT bytes from FROM, or create one. */
3585 find_barrier (from, max_count)
3590 rtx found_barrier = 0;
3593 while (from && count < max_count)
3595 if (GET_CODE (from) == BARRIER)
3598 /* Count the length of this insn */
3599 if (GET_CODE (from) == INSN
3600 && GET_CODE (PATTERN (from)) == SET
3601 && CONSTANT_P (SET_SRC (PATTERN (from)))
3602 && CONSTANT_POOL_ADDRESS_P (SET_SRC (PATTERN (from))))
3605 count += get_attr_length (from);
3608 from = NEXT_INSN (from);
3613 /* We didn't find a barrier in time to
3614 dump our stuff, so we'll make one */
3615 rtx label = gen_label_rtx ();
3618 from = PREV_INSN (last);
3620 from = get_last_insn ();
3622 /* Walk back to be just before any jump */
3623 while (GET_CODE (from) == JUMP_INSN
3624 || GET_CODE (from) == NOTE
3625 || GET_CODE (from) == CODE_LABEL)
3626 from = PREV_INSN (from);
3628 from = emit_jump_insn_after (gen_jump (label), from);
3629 JUMP_LABEL (from) = label;
3630 found_barrier = emit_barrier_after (from);
3631 emit_label_after (label, found_barrier);
3632 return found_barrier;
3635 return found_barrier;
3638 /* Non zero if the insn is a move instruction which needs to be fixed. */
3643 if (!INSN_DELETED_P (insn)
3644 && GET_CODE (insn) == INSN
3645 && GET_CODE (PATTERN (insn)) == SET)
3647 rtx pat = PATTERN (insn);
3648 rtx src = SET_SRC (pat);
3649 rtx dst = SET_DEST (pat);
3651 enum machine_mode mode = GET_MODE (dst);
3656 if (GET_CODE (dst) == REG)
3657 destreg = REGNO (dst);
3658 else if (GET_CODE (dst) == SUBREG && GET_CODE (SUBREG_REG (dst)) == REG)
3659 destreg = REGNO (SUBREG_REG (dst));
3663 return fixit (src, mode, destreg);
3676 /* The ldr instruction can work with up to a 4k offset, and most constants
3677 will be loaded with one of these instructions; however, the adr
3678 instruction and the ldf instructions only work with a 1k offset. This
3679 code needs to be rewritten to use the 4k offset when possible, and to
3680 adjust when a 1k offset is needed. For now we just use a 1k offset
3684 /* Floating point operands can't work further than 1024 bytes from the
3685 PC, so to make things simple we restrict all loads for such functions.
3687 if (TARGET_HARD_FLOAT)
3691 for (regno = 16; regno < 24; regno++)
3692 if (regs_ever_live[regno])
3702 for (insn = first; insn; insn = NEXT_INSN (insn))
3704 if (broken_move (insn))
3706 /* This is a broken move instruction, scan ahead looking for
3707 a barrier to stick the constant table behind */
3709 rtx barrier = find_barrier (insn, count_size);
3711 /* Now find all the moves between the points and modify them */
3712 for (scan = insn; scan != barrier; scan = NEXT_INSN (scan))
3714 if (broken_move (scan))
3716 /* This is a broken move instruction, add it to the pool */
3717 rtx pat = PATTERN (scan);
3718 rtx src = SET_SRC (pat);
3719 rtx dst = SET_DEST (pat);
3720 enum machine_mode mode = GET_MODE (dst);
3721 HOST_WIDE_INT offset;
3728 /* If this is an HImode constant load, convert it into
3729 an SImode constant load. Since the register is always
3730 32 bits this is safe. We have to do this, since the
3731 load pc-relative instruction only does a 32-bit load. */
3735 if (GET_CODE (dst) != REG)
3737 PUT_MODE (dst, SImode);
3740 offset = add_constant (src, mode, &address_only);
3741 addr = plus_constant (gen_rtx (LABEL_REF, VOIDmode,
3745 /* If we only want the address of the pool entry, or
3746 for wide moves to integer regs we need to split
3747 the address calculation off into a separate insn.
3748 If necessary, the load can then be done with a
3749 load-multiple. This is safe, since we have
3750 already noted the length of such insns to be 8,
3751 and we are immediately over-writing the scratch
3752 we have grabbed with the final result. */
3753 if ((address_only || GET_MODE_SIZE (mode) > 4)
3754 && (scratch = REGNO (dst)) < 16)
3761 reg = gen_rtx (REG, SImode, scratch);
3763 newinsn = emit_insn_after (gen_movaddr (reg, addr),
3770 newsrc = gen_rtx (MEM, mode, addr);
3772 /* XXX Fixme -- I think the following is bogus. */
3773 /* Build a jump insn wrapper around the move instead
3774 of an ordinary insn, because we want to have room for
3775 the target label rtx in fld[7], which an ordinary
3776 insn doesn't have. */
3777 newinsn = emit_jump_insn_after
3778 (gen_rtx (SET, VOIDmode, dst, newsrc), newinsn);
3779 JUMP_LABEL (newinsn) = pool_vector_label;
3781 /* But it's still an ordinary insn */
3782 PUT_CODE (newinsn, INSN);
3790 dump_table (barrier);
3797 /* Routines to output assembly language. */
3799 /* If the rtx is the correct value then return the string of the number.
3800 In this way we can ensure that valid double constants are generated even
3801 when cross compiling. */
3803 fp_immediate_constant (x)
3809 if (!fpa_consts_inited)
3812 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3813 for (i = 0; i < 8; i++)
3814 if (REAL_VALUES_EQUAL (r, values_fpa[i]))
3815 return strings_fpa[i];
3820 /* As for fp_immediate_constant, but value is passed directly, not in rtx. */
3822 fp_const_from_val (r)
3827 if (! fpa_consts_inited)
3830 for (i = 0; i < 8; i++)
3831 if (REAL_VALUES_EQUAL (*r, values_fpa[i]))
3832 return strings_fpa[i];
3837 /* Output the operands of a LDM/STM instruction to STREAM.
3838 MASK is the ARM register set mask of which only bits 0-15 are important.
3839 INSTR is the possibly suffixed base register. HAT unequals zero if a hat
3840 must follow the register list. */
3843 print_multi_reg (stream, instr, mask, hat)
3849 int not_first = FALSE;
3851 fputc ('\t', stream);
3852 fprintf (stream, instr, REGISTER_PREFIX);
3853 fputs (", {", stream);
3854 for (i = 0; i < 16; i++)
3855 if (mask & (1 << i))
3858 fprintf (stream, ", ");
3859 fprintf (stream, "%s%s", REGISTER_PREFIX, reg_names[i]);
3863 fprintf (stream, "}%s\n", hat ? "^" : "");
3866 /* Output a 'call' insn. */
3869 output_call (operands)
3872 /* Handle calls to lr using ip (which may be clobbered in subr anyway). */
3874 if (REGNO (operands[0]) == 14)
3876 operands[0] = gen_rtx (REG, SImode, 12);
3877 output_asm_insn ("mov%?\t%0, %|lr", operands);
3879 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
3880 output_asm_insn ("mov%?\t%|pc, %0", operands);
3888 int something_changed = 0;
3890 int code = GET_CODE (x0);
3897 if (REGNO (x0) == 14)
3899 *x = gen_rtx (REG, SImode, 12);
3904 /* Scan through the sub-elements and change any references there */
3905 fmt = GET_RTX_FORMAT (code);
3906 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3908 something_changed |= eliminate_lr2ip (&XEXP (x0, i));
3909 else if (fmt[i] == 'E')
3910 for (j = 0; j < XVECLEN (x0, i); j++)
3911 something_changed |= eliminate_lr2ip (&XVECEXP (x0, i, j));
3912 return something_changed;
3916 /* Output a 'call' insn that is a reference in memory. */
3919 output_call_mem (operands)
3922 operands[0] = copy_rtx (operands[0]); /* Be ultra careful */
3923 /* Handle calls using lr by using ip (which may be clobbered in subr anyway).
3925 if (eliminate_lr2ip (&operands[0]))
3926 output_asm_insn ("mov%?\t%|ip, %|lr", operands);
3928 output_asm_insn ("mov%?\t%|lr, %|pc", operands);
3929 output_asm_insn ("ldr%?\t%|pc, %0", operands);
3934 /* Output a move from arm registers to an fpu registers.
3935 OPERANDS[0] is an fpu register.
3936 OPERANDS[1] is the first registers of an arm register pair. */
3939 output_mov_long_double_fpu_from_arm (operands)
3942 int arm_reg0 = REGNO (operands[1]);
3948 ops[0] = gen_rtx (REG, SImode, arm_reg0);
3949 ops[1] = gen_rtx (REG, SImode, 1 + arm_reg0);
3950 ops[2] = gen_rtx (REG, SImode, 2 + arm_reg0);
3952 output_asm_insn ("stm%?fd\t%|sp!, {%0, %1, %2}", ops);
3953 output_asm_insn ("ldf%?e\t%0, [%|sp], #12", operands);
3957 /* Output a move from an fpu register to arm registers.
3958 OPERANDS[0] is the first registers of an arm register pair.
3959 OPERANDS[1] is an fpu register. */
3962 output_mov_long_double_arm_from_fpu (operands)
3965 int arm_reg0 = REGNO (operands[0]);
3971 ops[0] = gen_rtx (REG, SImode, arm_reg0);
3972 ops[1] = gen_rtx (REG, SImode, 1 + arm_reg0);
3973 ops[2] = gen_rtx (REG, SImode, 2 + arm_reg0);
3975 output_asm_insn ("stf%?e\t%1, [%|sp, #-12]!", operands);
3976 output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1, %2}", ops);
3980 /* Output a move from arm registers to arm registers of a long double
3981 OPERANDS[0] is the destination.
3982 OPERANDS[1] is the source. */
3984 output_mov_long_double_arm_from_arm (operands)
3987 /* We have to be careful here because the two might overlap */
3988 int dest_start = REGNO (operands[0]);
3989 int src_start = REGNO (operands[1]);
3993 if (dest_start < src_start)
3995 for (i = 0; i < 3; i++)
3997 ops[0] = gen_rtx (REG, SImode, dest_start + i);
3998 ops[1] = gen_rtx (REG, SImode, src_start + i);
3999 output_asm_insn ("mov%?\t%0, %1", ops);
4004 for (i = 2; i >= 0; i--)
4006 ops[0] = gen_rtx (REG, SImode, dest_start + i);
4007 ops[1] = gen_rtx (REG, SImode, src_start + i);
4008 output_asm_insn ("mov%?\t%0, %1", ops);
4016 /* Output a move from arm registers to an fpu registers.
4017 OPERANDS[0] is an fpu register.
4018 OPERANDS[1] is the first registers of an arm register pair. */
4021 output_mov_double_fpu_from_arm (operands)
4024 int arm_reg0 = REGNO (operands[1]);
4029 ops[0] = gen_rtx (REG, SImode, arm_reg0);
4030 ops[1] = gen_rtx (REG, SImode, 1 + arm_reg0);
4031 output_asm_insn ("stm%?fd\t%|sp!, {%0, %1}", ops);
4032 output_asm_insn ("ldf%?d\t%0, [%|sp], #8", operands);
4036 /* Output a move from an fpu register to arm registers.
4037 OPERANDS[0] is the first registers of an arm register pair.
4038 OPERANDS[1] is an fpu register. */
4041 output_mov_double_arm_from_fpu (operands)
4044 int arm_reg0 = REGNO (operands[0]);
4050 ops[0] = gen_rtx (REG, SImode, arm_reg0);
4051 ops[1] = gen_rtx (REG, SImode, 1 + arm_reg0);
4052 output_asm_insn ("stf%?d\t%1, [%|sp, #-8]!", operands);
4053 output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1}", ops);
4057 /* Output a move between double words.
4058 It must be REG<-REG, REG<-CONST_DOUBLE, REG<-CONST_INT, REG<-MEM
4059 or MEM<-REG and all MEMs must be offsettable addresses. */
4062 output_move_double (operands)
4065 enum rtx_code code0 = GET_CODE (operands[0]);
4066 enum rtx_code code1 = GET_CODE (operands[1]);
4071 int reg0 = REGNO (operands[0]);
4073 otherops[0] = gen_rtx (REG, SImode, 1 + reg0);
4076 int reg1 = REGNO (operands[1]);
4080 /* Ensure the second source is not overwritten */
4081 if (reg1 == reg0 + (WORDS_BIG_ENDIAN ? -1 : 1))
4082 output_asm_insn("mov%?\t%Q0, %Q1\n\tmov%?\t%R0, %R1", operands);
4084 output_asm_insn("mov%?\t%R0, %R1\n\tmov%?\t%Q0, %Q1", operands);
4086 else if (code1 == CONST_DOUBLE)
4088 if (GET_MODE (operands[1]) == DFmode)
4091 union real_extract u;
4093 bcopy ((char *) &CONST_DOUBLE_LOW (operands[1]), (char *) &u,
4095 REAL_VALUE_TO_TARGET_DOUBLE (u.d, l);
4096 otherops[1] = GEN_INT(l[1]);
4097 operands[1] = GEN_INT(l[0]);
4099 else if (GET_MODE (operands[1]) != VOIDmode)
4101 else if (WORDS_BIG_ENDIAN)
4104 otherops[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
4105 operands[1] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
4110 otherops[1] = GEN_INT (CONST_DOUBLE_HIGH (operands[1]));
4111 operands[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
4113 output_mov_immediate (operands);
4114 output_mov_immediate (otherops);
4116 else if (code1 == CONST_INT)
4118 #if HOST_BITS_PER_WIDE_INT > 32
4119 /* If HOST_WIDE_INT is more than 32 bits, the intval tells us
4120 what the upper word is. */
4121 if (WORDS_BIG_ENDIAN)
4123 otherops[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands[1])));
4124 operands[1] = GEN_INT (INTVAL (operands[1]) >> 32);
4128 otherops[1] = GEN_INT (INTVAL (operands[1]) >> 32);
4129 operands[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands[1])));
4132 /* Sign extend the intval into the high-order word */
4133 if (WORDS_BIG_ENDIAN)
4135 otherops[1] = operands[1];
4136 operands[1] = (INTVAL (operands[1]) < 0
4137 ? constm1_rtx : const0_rtx);
4140 otherops[1] = INTVAL (operands[1]) < 0 ? constm1_rtx : const0_rtx;
4142 output_mov_immediate (otherops);
4143 output_mov_immediate (operands);
4145 else if (code1 == MEM)
4147 switch (GET_CODE (XEXP (operands[1], 0)))
4150 output_asm_insn ("ldm%?ia\t%m1, %M0", operands);
4154 abort (); /* Should never happen now */
4158 output_asm_insn ("ldm%?db\t%m1!, %M0", operands);
4162 output_asm_insn ("ldm%?ia\t%m1!, %M0", operands);
4166 abort (); /* Should never happen now */
4171 output_asm_insn ("adr%?\t%0, %1", operands);
4172 output_asm_insn ("ldm%?ia\t%0, %M0", operands);
4176 if (arm_add_operand (XEXP (XEXP (operands[1], 0), 1)))
4178 otherops[0] = operands[0];
4179 otherops[1] = XEXP (XEXP (operands[1], 0), 0);
4180 otherops[2] = XEXP (XEXP (operands[1], 0), 1);
4181 if (GET_CODE (XEXP (operands[1], 0)) == PLUS)
4183 if (GET_CODE (otherops[2]) == CONST_INT)
4185 switch (INTVAL (otherops[2]))
4188 output_asm_insn ("ldm%?db\t%1, %M0", otherops);
4191 output_asm_insn ("ldm%?da\t%1, %M0", otherops);
4194 output_asm_insn ("ldm%?ib\t%1, %M0", otherops);
4197 if (!(const_ok_for_arm (INTVAL (otherops[2]))))
4198 output_asm_insn ("sub%?\t%0, %1, #%n2", otherops);
4200 output_asm_insn ("add%?\t%0, %1, %2", otherops);
4203 output_asm_insn ("add%?\t%0, %1, %2", otherops);
4206 output_asm_insn ("sub%?\t%0, %1, %2", otherops);
4207 return "ldm%?ia\t%0, %M0";
4211 otherops[1] = adj_offsettable_operand (operands[1], 4);
4212 /* Take care of overlapping base/data reg. */
4213 if (reg_mentioned_p (operands[0], operands[1]))
4215 output_asm_insn ("ldr%?\t%0, %1", otherops);
4216 output_asm_insn ("ldr%?\t%0, %1", operands);
4220 output_asm_insn ("ldr%?\t%0, %1", operands);
4221 output_asm_insn ("ldr%?\t%0, %1", otherops);
4227 abort(); /* Constraints should prevent this */
4229 else if (code0 == MEM && code1 == REG)
4231 if (REGNO (operands[1]) == 12)
4234 switch (GET_CODE (XEXP (operands[0], 0)))
4237 output_asm_insn ("stm%?ia\t%m0, %M1", operands);
4241 abort (); /* Should never happen now */
4245 output_asm_insn ("stm%?db\t%m0!, %M1", operands);
4249 output_asm_insn ("stm%?ia\t%m0!, %M1", operands);
4253 abort (); /* Should never happen now */
4257 if (GET_CODE (XEXP (XEXP (operands[0], 0), 1)) == CONST_INT)
4259 switch (INTVAL (XEXP (XEXP (operands[0], 0), 1)))
4262 output_asm_insn ("stm%?db\t%m0, %M1", operands);
4266 output_asm_insn ("stm%?da\t%m0, %M1", operands);
4270 output_asm_insn ("stm%?ib\t%m0, %M1", operands);
4277 otherops[0] = adj_offsettable_operand (operands[0], 4);
4278 otherops[1] = gen_rtx (REG, SImode, 1 + REGNO (operands[1]));
4279 output_asm_insn ("str%?\t%1, %0", operands);
4280 output_asm_insn ("str%?\t%1, %0", otherops);
4284 abort(); /* Constraints should prevent this */
4290 /* Output an arbitrary MOV reg, #n.
4291 OPERANDS[0] is a register. OPERANDS[1] is a const_int. */
4294 output_mov_immediate (operands)
4297 HOST_WIDE_INT n = INTVAL (operands[1]);
4301 /* Try to use one MOV */
4302 if (const_ok_for_arm (n))
4304 output_asm_insn ("mov%?\t%0, %1", operands);
4308 /* Try to use one MVN */
4309 if (const_ok_for_arm (~n))
4311 operands[1] = GEN_INT (~n);
4312 output_asm_insn ("mvn%?\t%0, %1", operands);
4316 /* If all else fails, make it out of ORRs or BICs as appropriate. */
4318 for (i=0; i < 32; i++)
4322 if (n_ones > 16) /* Shorter to use MVN with BIC in this case. */
4323 output_multi_immediate(operands, "mvn%?\t%0, %1", "bic%?\t%0, %0, %1", 1,
4326 output_multi_immediate(operands, "mov%?\t%0, %1", "orr%?\t%0, %0, %1", 1,
4333 /* Output an ADD r, s, #n where n may be too big for one instruction. If
4334 adding zero to one register, output nothing. */
4337 output_add_immediate (operands)
4340 HOST_WIDE_INT n = INTVAL (operands[2]);
4342 if (n != 0 || REGNO (operands[0]) != REGNO (operands[1]))
4345 output_multi_immediate (operands,
4346 "sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2,
4349 output_multi_immediate (operands,
4350 "add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2,
4357 /* Output a multiple immediate operation.
4358 OPERANDS is the vector of operands referred to in the output patterns.
4359 INSTR1 is the output pattern to use for the first constant.
4360 INSTR2 is the output pattern to use for subsequent constants.
4361 IMMED_OP is the index of the constant slot in OPERANDS.
4362 N is the constant value. */
4365 output_multi_immediate (operands, instr1, instr2, immed_op, n)
4367 char *instr1, *instr2;
4371 #if HOST_BITS_PER_WIDE_INT > 32
4377 operands[immed_op] = const0_rtx;
4378 output_asm_insn (instr1, operands); /* Quick and easy output */
4383 char *instr = instr1;
4385 /* Note that n is never zero here (which would give no output) */
4386 for (i = 0; i < 32; i += 2)
4390 operands[immed_op] = GEN_INT (n & (255 << i));
4391 output_asm_insn (instr, operands);
4401 /* Return the appropriate ARM instruction for the operation code.
4402 The returned result should not be overwritten. OP is the rtx of the
4403 operation. SHIFT_FIRST_ARG is TRUE if the first argument of the operator
4407 arithmetic_instr (op, shift_first_arg)
4409 int shift_first_arg;
4411 switch (GET_CODE (op))
4417 return shift_first_arg ? "rsb" : "sub";
4434 /* Ensure valid constant shifts and return the appropriate shift mnemonic
4435 for the operation code. The returned result should not be overwritten.
4436 OP is the rtx code of the shift.
4437 On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant
4441 shift_op (op, amountp)
4443 HOST_WIDE_INT *amountp;
4446 enum rtx_code code = GET_CODE (op);
4448 if (GET_CODE (XEXP (op, 1)) == REG || GET_CODE (XEXP (op, 1)) == SUBREG)
4450 else if (GET_CODE (XEXP (op, 1)) == CONST_INT)
4451 *amountp = INTVAL (XEXP (op, 1));
4474 /* We never have to worry about the amount being other than a
4475 power of 2, since this case can never be reloaded from a reg. */
4477 *amountp = int_log2 (*amountp);
4488 /* This is not 100% correct, but follows from the desire to merge
4489 multiplication by a power of 2 with the recognizer for a
4490 shift. >=32 is not a valid shift for "asl", so we must try and
4491 output a shift that produces the correct arithmetical result.
4492 Using lsr #32 is identical except for the fact that the carry bit
4493 is not set correctly if we set the flags; but we never use the
4494 carry bit from such an operation, so we can ignore that. */
4495 if (code == ROTATERT)
4496 *amountp &= 31; /* Rotate is just modulo 32 */
4497 else if (*amountp != (*amountp & 31))
4504 /* Shifts of 0 are no-ops. */
4513 /* Obtain the shift from the POWER of two. */
4515 static HOST_WIDE_INT
4517 HOST_WIDE_INT power;
4519 HOST_WIDE_INT shift = 0;
4521 while (((((HOST_WIDE_INT) 1) << shift) & power) == 0)
4531 /* Output a .ascii pseudo-op, keeping track of lengths. This is because
4532 /bin/as is horribly restrictive. */
4535 output_ascii_pseudo_op (stream, p, len)
4541 int len_so_far = 1000;
4542 int chars_so_far = 0;
4544 for (i = 0; i < len; i++)
4546 register int c = p[i];
4548 if (len_so_far > 50)
4551 fputs ("\"\n", stream);
4552 fputs ("\t.ascii\t\"", stream);
4557 if (c == '\"' || c == '\\')
4563 if (c >= ' ' && c < 0177)
4570 fprintf (stream, "\\%03o", c);
4577 fputs ("\"\n", stream);
4581 /* Try to determine whether a pattern really clobbers the link register.
4582 This information is useful when peepholing, so that lr need not be pushed
4583 if we combine a call followed by a return.
4584 NOTE: This code does not check for side-effect expressions in a SET_SRC:
4585 such a check should not be needed because these only update an existing
4586 value within a register; the register must still be set elsewhere within
4590 pattern_really_clobbers_lr (x)
4595 switch (GET_CODE (x))
4598 switch (GET_CODE (SET_DEST (x)))
4601 return REGNO (SET_DEST (x)) == 14;
4604 if (GET_CODE (XEXP (SET_DEST (x), 0)) == REG)
4605 return REGNO (XEXP (SET_DEST (x), 0)) == 14;
4607 if (GET_CODE (XEXP (SET_DEST (x), 0)) == MEM)
4616 for (i = 0; i < XVECLEN (x, 0); i++)
4617 if (pattern_really_clobbers_lr (XVECEXP (x, 0, i)))
4622 switch (GET_CODE (XEXP (x, 0)))
4625 return REGNO (XEXP (x, 0)) == 14;
4628 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG)
4629 return REGNO (XEXP (XEXP (x, 0), 0)) == 14;
4645 function_really_clobbers_lr (first)
4650 for (insn = first; insn; insn = next_nonnote_insn (insn))
4652 switch (GET_CODE (insn))
4657 case JUMP_INSN: /* Jump insns only change the PC (and conds) */
4662 if (pattern_really_clobbers_lr (PATTERN (insn)))
4667 /* Don't yet know how to handle those calls that are not to a
4669 if (GET_CODE (PATTERN (insn)) != PARALLEL)
4672 switch (GET_CODE (XVECEXP (PATTERN (insn), 0, 0)))
4675 if (GET_CODE (XEXP (XEXP (XVECEXP (PATTERN (insn), 0, 0), 0), 0))
4681 if (GET_CODE (XEXP (XEXP (SET_SRC (XVECEXP (PATTERN (insn),
4687 default: /* Don't recognize it, be safe */
4691 /* A call can be made (by peepholing) not to clobber lr iff it is
4692 followed by a return. There may, however, be a use insn iff
4693 we are returning the result of the call.
4694 If we run off the end of the insn chain, then that means the
4695 call was at the end of the function. Unfortunately we don't
4696 have a return insn for the peephole to recognize, so we
4697 must reject this. (Can this be fixed by adding our own insn?) */
4698 if ((next = next_nonnote_insn (insn)) == NULL)
4701 /* No need to worry about lr if the call never returns */
4702 if (GET_CODE (next) == BARRIER)
4705 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == USE
4706 && (GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
4707 && (REGNO (SET_DEST (XVECEXP (PATTERN (insn), 0, 0)))
4708 == REGNO (XEXP (PATTERN (next), 0))))
4709 if ((next = next_nonnote_insn (next)) == NULL)
4712 if (GET_CODE (next) == JUMP_INSN
4713 && GET_CODE (PATTERN (next)) == RETURN)
4722 /* We have reached the end of the chain so lr was _not_ clobbered */
4727 output_return_instruction (operand, really_return, reverse)
4733 int reg, live_regs = 0;
4734 int volatile_func = (optimize > 0
4735 && TREE_THIS_VOLATILE (current_function_decl));
4737 return_used_this_function = 1;
4742 /* If this function was declared non-returning, and we have found a tail
4743 call, then we have to trust that the called function won't return. */
4744 if (! really_return)
4747 /* Otherwise, trap an attempted return by aborting. */
4749 ops[1] = gen_rtx (SYMBOL_REF, Pmode, "abort");
4750 assemble_external_libcall (ops[1]);
4751 output_asm_insn (reverse ? "bl%D0\t%a1" : "bl%d0\t%a1", ops);
4755 if (current_function_calls_alloca && ! really_return)
4758 for (reg = 0; reg <= 10; reg++)
4759 if (regs_ever_live[reg] && ! call_used_regs[reg])
4762 if (live_regs || (regs_ever_live[14] && ! lr_save_eliminated))
4765 if (frame_pointer_needed)
4770 if (lr_save_eliminated || ! regs_ever_live[14])
4773 if (frame_pointer_needed)
4775 reverse ? "ldm%?%D0ea\t%|fp, {" : "ldm%?%d0ea\t%|fp, {");
4778 reverse ? "ldm%?%D0fd\t%|sp!, {" : "ldm%?%d0fd\t%|sp!, {");
4780 for (reg = 0; reg <= 10; reg++)
4781 if (regs_ever_live[reg] && ! call_used_regs[reg])
4783 strcat (instr, "%|");
4784 strcat (instr, reg_names[reg]);
4786 strcat (instr, ", ");
4789 if (frame_pointer_needed)
4791 strcat (instr, "%|");
4792 strcat (instr, reg_names[11]);
4793 strcat (instr, ", ");
4794 strcat (instr, "%|");
4795 strcat (instr, reg_names[13]);
4796 strcat (instr, ", ");
4797 strcat (instr, "%|");
4798 strcat (instr, really_return ? reg_names[15] : reg_names[14]);
4802 strcat (instr, "%|");
4803 strcat (instr, really_return ? reg_names[15] : reg_names[14]);
4805 strcat (instr, (TARGET_APCS_32 || !really_return) ? "}" : "}^");
4806 output_asm_insn (instr, &operand);
4808 else if (really_return)
4810 if (TARGET_THUMB_INTERWORK)
4811 sprintf (instr, "bx%%?%%%s\t%%|lr", reverse ? "D" : "d");
4813 sprintf (instr, "mov%%?%%%s0%s\t%%|pc, %%|lr",
4814 reverse ? "D" : "d", TARGET_APCS_32 ? "" : "s");
4815 output_asm_insn (instr, &operand);
4821 /* Return nonzero if optimizing and the current function is volatile.
4822 Such functions never return, and many memory cycles can be saved
4823 by not storing register values that will never be needed again.
4824 This optimization was added to speed up context switching in a
4825 kernel application. */
4828 arm_volatile_func ()
4830 return (optimize > 0 && TREE_THIS_VOLATILE (current_function_decl));
4833 /* The amount of stack adjustment that happens here, in output_return and in
4834 output_epilogue must be exactly the same as was calculated during reload,
4835 or things will point to the wrong place. The only time we can safely
4836 ignore this constraint is when a function has no arguments on the stack,
4837 no stack frame requirement and no live registers execpt for `lr'. If we
4838 can guarantee that by making all function calls into tail calls and that
4839 lr is not clobbered in any other way, then there is no need to push lr
4843 output_func_prologue (f, frame_size)
4847 int reg, live_regs_mask = 0;
4848 int volatile_func = (optimize > 0
4849 && TREE_THIS_VOLATILE (current_function_decl));
4851 /* Nonzero if we must stuff some register arguments onto the stack as if
4852 they were passed there. */
4853 int store_arg_regs = 0;
4855 if (arm_ccfsm_state || arm_target_insn)
4856 abort (); /* Sanity check */
4858 if (arm_naked_function_p (current_function_decl))
4861 return_used_this_function = 0;
4862 lr_save_eliminated = 0;
4864 fprintf (f, "\t%s args = %d, pretend = %d, frame = %d\n",
4865 ASM_COMMENT_START, current_function_args_size,
4866 current_function_pretend_args_size, frame_size);
4867 fprintf (f, "\t%s frame_needed = %d, current_function_anonymous_args = %d\n",
4868 ASM_COMMENT_START, frame_pointer_needed,
4869 current_function_anonymous_args);
4872 fprintf (f, "\t%s Volatile function.\n", ASM_COMMENT_START);
4874 if (current_function_anonymous_args && current_function_pretend_args_size)
4877 for (reg = 0; reg <= 10; reg++)
4878 if (regs_ever_live[reg] && ! call_used_regs[reg])
4879 live_regs_mask |= (1 << reg);
4881 if (frame_pointer_needed)
4882 live_regs_mask |= 0xD800;
4883 else if (regs_ever_live[14])
4885 if (! current_function_args_size
4886 && ! function_really_clobbers_lr (get_insns ()))
4887 lr_save_eliminated = 1;
4889 live_regs_mask |= 0x4000;
4894 /* if a di mode load/store multiple is used, and the base register
4895 is r3, then r4 can become an ever live register without lr
4896 doing so, in this case we need to push lr as well, or we
4897 will fail to get a proper return. */
4899 live_regs_mask |= 0x4000;
4900 lr_save_eliminated = 0;
4904 if (lr_save_eliminated)
4905 fprintf (f,"\t%s I don't think this function clobbers lr\n",
4908 #ifdef AOF_ASSEMBLER
4910 fprintf (f, "\tmov\t%sip, %s%s\n", REGISTER_PREFIX, REGISTER_PREFIX,
4911 reg_names[PIC_OFFSET_TABLE_REGNUM]);
4917 output_func_epilogue (f, frame_size)
4921 int reg, live_regs_mask = 0;
4922 /* If we need this then it will always be at least this much */
4923 int floats_offset = 12;
4925 int volatile_func = (optimize > 0
4926 && TREE_THIS_VOLATILE (current_function_decl));
4928 if (use_return_insn() && return_used_this_function)
4930 if ((frame_size + current_function_outgoing_args_size) != 0
4931 && !(frame_pointer_needed || TARGET_APCS))
4936 /* Naked functions don't have epilogues. */
4937 if (arm_naked_function_p (current_function_decl))
4940 /* A volatile function should never return. Call abort. */
4943 rtx op = gen_rtx (SYMBOL_REF, Pmode, "abort");
4944 assemble_external_libcall (op);
4945 output_asm_insn ("bl\t%a0", &op);
4949 for (reg = 0; reg <= 10; reg++)
4950 if (regs_ever_live[reg] && ! call_used_regs[reg])
4952 live_regs_mask |= (1 << reg);
4956 if (frame_pointer_needed)
4958 if (arm_fpu_arch == FP_SOFT2)
4960 for (reg = 23; reg > 15; reg--)
4961 if (regs_ever_live[reg] && ! call_used_regs[reg])
4963 floats_offset += 12;
4964 fprintf (f, "\tldfe\t%s%s, [%sfp, #-%d]\n", REGISTER_PREFIX,
4965 reg_names[reg], REGISTER_PREFIX, floats_offset);
4972 for (reg = 23; reg > 15; reg--)
4974 if (regs_ever_live[reg] && ! call_used_regs[reg])
4976 floats_offset += 12;
4977 /* We can't unstack more than four registers at once */
4978 if (start_reg - reg == 3)
4980 fprintf (f, "\tlfm\t%s%s, 4, [%sfp, #-%d]\n",
4981 REGISTER_PREFIX, reg_names[reg],
4982 REGISTER_PREFIX, floats_offset);
4983 start_reg = reg - 1;
4988 if (reg != start_reg)
4989 fprintf (f, "\tlfm\t%s%s, %d, [%sfp, #-%d]\n",
4990 REGISTER_PREFIX, reg_names[reg + 1],
4991 start_reg - reg, REGISTER_PREFIX, floats_offset);
4993 start_reg = reg - 1;
4997 /* Just in case the last register checked also needs unstacking. */
4998 if (reg != start_reg)
4999 fprintf (f, "\tlfm\t%s%s, %d, [%sfp, #-%d]\n",
5000 REGISTER_PREFIX, reg_names[reg + 1],
5001 start_reg - reg, REGISTER_PREFIX, floats_offset);
5004 if (TARGET_THUMB_INTERWORK)
5006 live_regs_mask |= 0x6800;
5007 print_multi_reg (f, "ldmea\t%sfp", live_regs_mask, FALSE);
5008 fprintf (f, "\tbx\t%slr\n", REGISTER_PREFIX);
5012 live_regs_mask |= 0xA800;
5013 print_multi_reg (f, "ldmea\t%sfp", live_regs_mask,
5014 TARGET_APCS_32 ? FALSE : TRUE);
5019 /* Restore stack pointer if necessary. */
5020 if (frame_size + current_function_outgoing_args_size != 0)
5022 operands[0] = operands[1] = stack_pointer_rtx;
5023 operands[2] = GEN_INT (frame_size
5024 + current_function_outgoing_args_size);
5025 output_add_immediate (operands);
5028 if (arm_fpu_arch == FP_SOFT2)
5030 for (reg = 16; reg < 24; reg++)
5031 if (regs_ever_live[reg] && ! call_used_regs[reg])
5032 fprintf (f, "\tldfe\t%s%s, [%ssp], #12\n", REGISTER_PREFIX,
5033 reg_names[reg], REGISTER_PREFIX);
5039 for (reg = 16; reg < 24; reg++)
5041 if (regs_ever_live[reg] && ! call_used_regs[reg])
5043 if (reg - start_reg == 3)
5045 fprintf (f, "\tlfmfd\t%s%s, 4, [%ssp]!\n",
5046 REGISTER_PREFIX, reg_names[start_reg],
5048 start_reg = reg + 1;
5053 if (reg != start_reg)
5054 fprintf (f, "\tlfmfd\t%s%s, %d, [%ssp]!\n",
5055 REGISTER_PREFIX, reg_names[start_reg],
5056 reg - start_reg, REGISTER_PREFIX);
5058 start_reg = reg + 1;
5062 /* Just in case the last register checked also needs unstacking. */
5063 if (reg != start_reg)
5064 fprintf (f, "\tlfmfd\t%s%s, %d, [%ssp]!\n",
5065 REGISTER_PREFIX, reg_names[start_reg],
5066 reg - start_reg, REGISTER_PREFIX);
5069 if (current_function_pretend_args_size == 0 && regs_ever_live[14])
5071 if (TARGET_THUMB_INTERWORK)
5073 if (! lr_save_eliminated)
5074 print_multi_reg(f, "ldmfd\t%ssp!", live_regs_mask | 0x4000,
5077 fprintf (f, "\tbx\t%slr\n", REGISTER_PREFIX);
5079 else if (lr_save_eliminated)
5080 fprintf (f, (TARGET_APCS_32 ? "\tmov\t%spc, %slr\n"
5081 : "\tmovs\t%spc, %slr\n"),
5082 REGISTER_PREFIX, REGISTER_PREFIX, f);
5084 print_multi_reg (f, "ldmfd\t%ssp!", live_regs_mask | 0x8000,
5085 TARGET_APCS_32 ? FALSE : TRUE);
5089 if (live_regs_mask || regs_ever_live[14])
5091 /* Restore the integer regs, and the return address into lr */
5092 if (! lr_save_eliminated)
5093 live_regs_mask |= 0x4000;
5095 if (live_regs_mask != 0)
5096 print_multi_reg (f, "ldmfd\t%ssp!", live_regs_mask, FALSE);
5099 if (current_function_pretend_args_size)
5101 /* Unwind the pre-pushed regs */
5102 operands[0] = operands[1] = stack_pointer_rtx;
5103 operands[2] = GEN_INT (current_function_pretend_args_size);
5104 output_add_immediate (operands);
5106 /* And finally, go home */
5107 if (TARGET_THUMB_INTERWORK)
5108 fprintf (f, "\tbx\t%slr\n", REGISTER_PREFIX);
5110 fprintf (f, (TARGET_APCS_32 ? "\tmov\t%spc, %slr\n"
5111 : "\tmovs\t%spc, %slr\n"),
5112 REGISTER_PREFIX, REGISTER_PREFIX, f);
5118 current_function_anonymous_args = 0;
5122 emit_multi_reg_push (mask)
5129 for (i = 0; i < 16; i++)
5130 if (mask & (1 << i))
5133 if (num_regs == 0 || num_regs > 16)
5136 par = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (num_regs));
5138 for (i = 0; i < 16; i++)
5140 if (mask & (1 << i))
5143 = gen_rtx (SET, VOIDmode, gen_rtx (MEM, BLKmode,
5144 gen_rtx (PRE_DEC, BLKmode,
5145 stack_pointer_rtx)),
5146 gen_rtx (UNSPEC, BLKmode,
5147 gen_rtvec (1, gen_rtx (REG, SImode, i)),
5153 for (j = 1, i++; j < num_regs; i++)
5155 if (mask & (1 << i))
5158 = gen_rtx (USE, VOIDmode, gen_rtx (REG, SImode, i));
5167 emit_sfm (base_reg, count)
5174 par = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (count));
5176 XVECEXP (par, 0, 0) = gen_rtx (SET, VOIDmode,
5177 gen_rtx (MEM, BLKmode,
5178 gen_rtx (PRE_DEC, BLKmode,
5179 stack_pointer_rtx)),
5180 gen_rtx (UNSPEC, BLKmode,
5181 gen_rtvec (1, gen_rtx (REG, XFmode,
5184 for (i = 1; i < count; i++)
5185 XVECEXP (par, 0, i) = gen_rtx (USE, VOIDmode,
5186 gen_rtx (REG, XFmode, base_reg++));
5192 arm_expand_prologue ()
5195 rtx amount = GEN_INT (-(get_frame_size ()
5196 + current_function_outgoing_args_size));
5197 int live_regs_mask = 0;
5198 int store_arg_regs = 0;
5199 int volatile_func = (optimize > 0
5200 && TREE_THIS_VOLATILE (current_function_decl));
5202 /* Naked functions don't have prologues. */
5203 if (arm_naked_function_p (current_function_decl))
5206 if (current_function_anonymous_args && current_function_pretend_args_size)
5209 if (! volatile_func)
5210 for (reg = 0; reg <= 10; reg++)
5211 if (regs_ever_live[reg] && ! call_used_regs[reg])
5212 live_regs_mask |= 1 << reg;
5214 if (! volatile_func && regs_ever_live[14])
5215 live_regs_mask |= 0x4000;
5217 if (frame_pointer_needed)
5219 live_regs_mask |= 0xD800;
5220 emit_insn (gen_movsi (gen_rtx (REG, SImode, 12),
5221 stack_pointer_rtx));
5224 if (current_function_pretend_args_size)
5227 emit_multi_reg_push ((0xf0 >> (current_function_pretend_args_size / 4))
5230 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
5231 GEN_INT (-current_function_pretend_args_size)));
5236 /* If we have to push any regs, then we must push lr as well, or
5237 we won't get a proper return. */
5238 live_regs_mask |= 0x4000;
5239 emit_multi_reg_push (live_regs_mask);
5242 /* For now the integer regs are still pushed in output_func_epilogue (). */
5244 if (! volatile_func)
5246 if (arm_fpu_arch == FP_SOFT2)
5248 for (reg = 23; reg > 15; reg--)
5249 if (regs_ever_live[reg] && ! call_used_regs[reg])
5250 emit_insn (gen_rtx (SET, VOIDmode,
5251 gen_rtx (MEM, XFmode,
5252 gen_rtx (PRE_DEC, XFmode,
5253 stack_pointer_rtx)),
5254 gen_rtx (REG, XFmode, reg)));
5260 for (reg = 23; reg > 15; reg--)
5262 if (regs_ever_live[reg] && ! call_used_regs[reg])
5264 if (start_reg - reg == 3)
5267 start_reg = reg - 1;
5272 if (start_reg != reg)
5273 emit_sfm (reg + 1, start_reg - reg);
5274 start_reg = reg - 1;
5278 if (start_reg != reg)
5279 emit_sfm (reg + 1, start_reg - reg);
5283 if (frame_pointer_needed)
5284 emit_insn (gen_addsi3 (hard_frame_pointer_rtx, gen_rtx (REG, SImode, 12),
5286 (-(4 + current_function_pretend_args_size)))));
5288 if (amount != const0_rtx)
5290 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, amount));
5291 emit_insn (gen_rtx (CLOBBER, VOIDmode,
5292 gen_rtx (MEM, BLKmode, stack_pointer_rtx)));
5295 /* If we are profiling, make sure no instructions are scheduled before
5296 the call to mcount. */
5297 if (profile_flag || profile_block_flag)
5298 emit_insn (gen_blockage ());
5302 /* If CODE is 'd', then the X is a condition operand and the instruction
5303 should only be executed if the condition is true.
5304 if CODE is 'D', then the X is a condition operand and the instruction
5305 should only be executed if the condition is false: however, if the mode
5306 of the comparison is CCFPEmode, then always execute the instruction -- we
5307 do this because in these circumstances !GE does not necessarily imply LT;
5308 in these cases the instruction pattern will take care to make sure that
5309 an instruction containing %d will follow, thereby undoing the effects of
5310 doing this instruction unconditionally.
5311 If CODE is 'N' then X is a floating point operand that must be negated
5313 If CODE is 'B' then output a bitwise inverted value of X (a const int).
5314 If X is a REG and CODE is `M', output a ldm/stm style multi-reg. */
5317 arm_print_operand (stream, x, code)
5325 fputs (ASM_COMMENT_START, stream);
5329 fputs (REGISTER_PREFIX, stream);
5333 if (arm_ccfsm_state == 3 || arm_ccfsm_state == 4)
5334 fputs (arm_condition_codes[arm_current_cc], stream);
5340 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
5341 r = REAL_VALUE_NEGATE (r);
5342 fprintf (stream, "%s", fp_const_from_val (&r));
5347 if (GET_CODE (x) == CONST_INT)
5349 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
5354 ARM_SIGN_EXTEND (~ INTVAL (x)));
5358 output_addr_const (stream, x);
5363 fprintf (stream, "%s", arithmetic_instr (x, 1));
5367 fprintf (stream, "%s", arithmetic_instr (x, 0));
5373 char *shift = shift_op (x, &val);
5377 fprintf (stream, ", %s ", shift_op (x, &val));
5379 arm_print_operand (stream, XEXP (x, 1), 0);
5382 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
5395 fputs (REGISTER_PREFIX, stream);
5396 fputs (reg_names[REGNO (x) + (WORDS_BIG_ENDIAN ? 1 : 0)], stream);
5402 fputs (REGISTER_PREFIX, stream);
5403 fputs (reg_names[REGNO (x) + (WORDS_BIG_ENDIAN ? 0 : 1)], stream);
5407 fputs (REGISTER_PREFIX, stream);
5408 if (GET_CODE (XEXP (x, 0)) == REG)
5409 fputs (reg_names[REGNO (XEXP (x, 0))], stream);
5411 fputs (reg_names[REGNO (XEXP (XEXP (x, 0), 0))], stream);
5415 fprintf (stream, "{%s%s-%s%s}", REGISTER_PREFIX, reg_names[REGNO (x)],
5416 REGISTER_PREFIX, reg_names[REGNO (x) - 1
5417 + ((GET_MODE_SIZE (GET_MODE (x))
5418 + GET_MODE_SIZE (SImode) - 1)
5419 / GET_MODE_SIZE (SImode))]);
5424 fputs (arm_condition_codes[get_arm_condition_code (x)],
5430 fputs (arm_condition_codes[ARM_INVERSE_CONDITION_CODE
5431 (get_arm_condition_code (x))],
5439 if (GET_CODE (x) == REG)
5441 fputs (REGISTER_PREFIX, stream);
5442 fputs (reg_names[REGNO (x)], stream);
5444 else if (GET_CODE (x) == MEM)
5446 output_memory_reference_mode = GET_MODE (x);
5447 output_address (XEXP (x, 0));
5449 else if (GET_CODE (x) == CONST_DOUBLE)
5450 fprintf (stream, "#%s", fp_immediate_constant (x));
5451 else if (GET_CODE (x) == NEG)
5452 abort (); /* This should never happen now. */
5455 fputc ('#', stream);
5456 output_addr_const (stream, x);
5462 /* A finite state machine takes care of noticing whether or not instructions
5463 can be conditionally executed, and thus decrease execution time and code
5464 size by deleting branch instructions. The fsm is controlled by
5465 final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE. */
5467 /* The state of the fsm controlling condition codes are:
5468 0: normal, do nothing special
5469 1: make ASM_OUTPUT_OPCODE not output this instruction
5470 2: make ASM_OUTPUT_OPCODE not output this instruction
5471 3: make instructions conditional
5472 4: make instructions conditional
5474 State transitions (state->state by whom under condition):
5475 0 -> 1 final_prescan_insn if the `target' is a label
5476 0 -> 2 final_prescan_insn if the `target' is an unconditional branch
5477 1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch
5478 2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch
5479 3 -> 0 ASM_OUTPUT_INTERNAL_LABEL if the `target' label is reached
5480 (the target label has CODE_LABEL_NUMBER equal to arm_target_label).
5481 4 -> 0 final_prescan_insn if the `target' unconditional branch is reached
5482 (the target insn is arm_target_insn).
5484 If the jump clobbers the conditions then we use states 2 and 4.
5486 A similar thing can be done with conditional return insns.
5488 XXX In case the `target' is an unconditional branch, this conditionalising
5489 of the instructions always reduces code size, but not always execution
5490 time. But then, I want to reduce the code size to somewhere near what
5491 /bin/cc produces. */
5493 /* Returns the index of the ARM condition code string in
5494 `arm_condition_codes'. COMPARISON should be an rtx like
5495 `(eq (...) (...))'. */
5497 static enum arm_cond_code
5498 get_arm_condition_code (comparison)
5501 enum machine_mode mode = GET_MODE (XEXP (comparison, 0));
5503 register enum rtx_code comp_code = GET_CODE (comparison);
5505 if (GET_MODE_CLASS (mode) != MODE_CC)
5506 mode = SELECT_CC_MODE (comp_code, XEXP (comparison, 0),
5507 XEXP (comparison, 1));
5511 case CC_DNEmode: code = ARM_NE; goto dominance;
5512 case CC_DEQmode: code = ARM_EQ; goto dominance;
5513 case CC_DGEmode: code = ARM_GE; goto dominance;
5514 case CC_DGTmode: code = ARM_GT; goto dominance;
5515 case CC_DLEmode: code = ARM_LE; goto dominance;
5516 case CC_DLTmode: code = ARM_LT; goto dominance;
5517 case CC_DGEUmode: code = ARM_CS; goto dominance;
5518 case CC_DGTUmode: code = ARM_HI; goto dominance;
5519 case CC_DLEUmode: code = ARM_LS; goto dominance;
5520 case CC_DLTUmode: code = ARM_CC;
5523 if (comp_code != EQ && comp_code != NE)
5526 if (comp_code == EQ)
5527 return ARM_INVERSE_CONDITION_CODE (code);
5533 case NE: return ARM_NE;
5534 case EQ: return ARM_EQ;
5535 case GE: return ARM_PL;
5536 case LT: return ARM_MI;
5544 case NE: return ARM_NE;
5545 case EQ: return ARM_EQ;
5552 case GE: return ARM_GE;
5553 case GT: return ARM_GT;
5554 case LE: return ARM_LS;
5555 case LT: return ARM_MI;
5562 case NE: return ARM_NE;
5563 case EQ: return ARM_EQ;
5564 case GE: return ARM_LE;
5565 case GT: return ARM_LT;
5566 case LE: return ARM_GE;
5567 case LT: return ARM_GT;
5568 case GEU: return ARM_LS;
5569 case GTU: return ARM_CC;
5570 case LEU: return ARM_CS;
5571 case LTU: return ARM_HI;
5578 case LTU: return ARM_CS;
5579 case GEU: return ARM_CC;
5586 case NE: return ARM_NE;
5587 case EQ: return ARM_EQ;
5588 case GE: return ARM_GE;
5589 case GT: return ARM_GT;
5590 case LE: return ARM_LE;
5591 case LT: return ARM_LT;
5592 case GEU: return ARM_CS;
5593 case GTU: return ARM_HI;
5594 case LEU: return ARM_LS;
5595 case LTU: return ARM_CC;
5607 final_prescan_insn (insn, opvec, noperands)
5612 /* BODY will hold the body of INSN. */
5613 register rtx body = PATTERN (insn);
5615 /* This will be 1 if trying to repeat the trick, and things need to be
5616 reversed if it appears to fail. */
5619 /* JUMP_CLOBBERS will be one implies that the conditions if a branch is
5620 taken are clobbered, even if the rtl suggests otherwise. It also
5621 means that we have to grub around within the jump expression to find
5622 out what the conditions are when the jump isn't taken. */
5623 int jump_clobbers = 0;
5625 /* If we start with a return insn, we only succeed if we find another one. */
5626 int seeking_return = 0;
5628 /* START_INSN will hold the insn from where we start looking. This is the
5629 first insn after the following code_label if REVERSE is true. */
5630 rtx start_insn = insn;
5632 /* If in state 4, check if the target branch is reached, in order to
5633 change back to state 0. */
5634 if (arm_ccfsm_state == 4)
5636 if (insn == arm_target_insn)
5638 arm_target_insn = NULL;
5639 arm_ccfsm_state = 0;
5644 /* If in state 3, it is possible to repeat the trick, if this insn is an
5645 unconditional branch to a label, and immediately following this branch
5646 is the previous target label which is only used once, and the label this
5647 branch jumps to is not too far off. */
5648 if (arm_ccfsm_state == 3)
5650 if (simplejump_p (insn))
5652 start_insn = next_nonnote_insn (start_insn);
5653 if (GET_CODE (start_insn) == BARRIER)
5655 /* XXX Isn't this always a barrier? */
5656 start_insn = next_nonnote_insn (start_insn);
5658 if (GET_CODE (start_insn) == CODE_LABEL
5659 && CODE_LABEL_NUMBER (start_insn) == arm_target_label
5660 && LABEL_NUSES (start_insn) == 1)
5665 else if (GET_CODE (body) == RETURN)
5667 start_insn = next_nonnote_insn (start_insn);
5668 if (GET_CODE (start_insn) == BARRIER)
5669 start_insn = next_nonnote_insn (start_insn);
5670 if (GET_CODE (start_insn) == CODE_LABEL
5671 && CODE_LABEL_NUMBER (start_insn) == arm_target_label
5672 && LABEL_NUSES (start_insn) == 1)
5684 if (arm_ccfsm_state != 0 && !reverse)
5686 if (GET_CODE (insn) != JUMP_INSN)
5689 /* This jump might be paralleled with a clobber of the condition codes
5690 the jump should always come first */
5691 if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0)
5692 body = XVECEXP (body, 0, 0);
5695 /* If this is a conditional return then we don't want to know */
5696 if (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC
5697 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
5698 && (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN
5699 || GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN))
5704 || (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC
5705 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE))
5708 int fail = FALSE, succeed = FALSE;
5709 /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */
5710 int then_not_else = TRUE;
5711 rtx this_insn = start_insn, label = 0;
5713 if (get_attr_conds (insn) == CONDS_JUMP_CLOB)
5715 /* The code below is wrong for these, and I haven't time to
5716 fix it now. So we just do the safe thing and return. This
5717 whole function needs re-writing anyway. */
5722 /* Register the insn jumped to. */
5725 if (!seeking_return)
5726 label = XEXP (SET_SRC (body), 0);
5728 else if (GET_CODE (XEXP (SET_SRC (body), 1)) == LABEL_REF)
5729 label = XEXP (XEXP (SET_SRC (body), 1), 0);
5730 else if (GET_CODE (XEXP (SET_SRC (body), 2)) == LABEL_REF)
5732 label = XEXP (XEXP (SET_SRC (body), 2), 0);
5733 then_not_else = FALSE;
5735 else if (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN)
5737 else if (GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN)
5740 then_not_else = FALSE;
5745 /* See how many insns this branch skips, and what kind of insns. If all
5746 insns are okay, and the label or unconditional branch to the same
5747 label is not too far away, succeed. */
5748 for (insns_skipped = 0;
5749 !fail && !succeed && insns_skipped++ < MAX_INSNS_SKIPPED;)
5753 this_insn = next_nonnote_insn (this_insn);
5757 switch (GET_CODE (this_insn))
5760 /* Succeed if it is the target label, otherwise fail since
5761 control falls in from somewhere else. */
5762 if (this_insn == label)
5766 arm_ccfsm_state = 2;
5767 this_insn = next_nonnote_insn (this_insn);
5770 arm_ccfsm_state = 1;
5778 /* Succeed if the following insn is the target label.
5780 If return insns are used then the last insn in a function
5781 will be a barrier. */
5782 this_insn = next_nonnote_insn (this_insn);
5783 if (this_insn && this_insn == label)
5787 arm_ccfsm_state = 2;
5788 this_insn = next_nonnote_insn (this_insn);
5791 arm_ccfsm_state = 1;
5799 /* If using 32-bit addresses the cc is not preserved over
5803 /* Succeed if the following insn is the target label,
5804 or if the following two insns are a barrier and
5805 the target label. */
5806 this_insn = next_nonnote_insn (this_insn);
5807 if (this_insn && GET_CODE (this_insn) == BARRIER)
5808 this_insn = next_nonnote_insn (this_insn);
5810 if (this_insn && this_insn == label
5811 && insns_skipped < MAX_INSNS_SKIPPED)
5815 arm_ccfsm_state = 2;
5816 this_insn = next_nonnote_insn (this_insn);
5819 arm_ccfsm_state = 1;
5828 /* If this is an unconditional branch to the same label, succeed.
5829 If it is to another label, do nothing. If it is conditional,
5831 /* XXX Probably, the tests for SET and the PC are unnecessary. */
5833 scanbody = PATTERN (this_insn);
5834 if (GET_CODE (scanbody) == SET
5835 && GET_CODE (SET_DEST (scanbody)) == PC)
5837 if (GET_CODE (SET_SRC (scanbody)) == LABEL_REF
5838 && XEXP (SET_SRC (scanbody), 0) == label && !reverse)
5840 arm_ccfsm_state = 2;
5843 else if (GET_CODE (SET_SRC (scanbody)) == IF_THEN_ELSE)
5846 else if (GET_CODE (scanbody) == RETURN
5849 arm_ccfsm_state = 2;
5852 else if (GET_CODE (scanbody) == PARALLEL)
5854 switch (get_attr_conds (this_insn))
5866 /* Instructions using or affecting the condition codes make it
5868 scanbody = PATTERN (this_insn);
5869 if ((GET_CODE (scanbody) == SET
5870 || GET_CODE (scanbody) == PARALLEL)
5871 && get_attr_conds (this_insn) != CONDS_NOCOND)
5881 if ((!seeking_return) && (arm_ccfsm_state == 1 || reverse))
5882 arm_target_label = CODE_LABEL_NUMBER (label);
5883 else if (seeking_return || arm_ccfsm_state == 2)
5885 while (this_insn && GET_CODE (PATTERN (this_insn)) == USE)
5887 this_insn = next_nonnote_insn (this_insn);
5888 if (this_insn && (GET_CODE (this_insn) == BARRIER
5889 || GET_CODE (this_insn) == CODE_LABEL))
5894 /* Oh, dear! we ran off the end.. give up */
5895 recog (PATTERN (insn), insn, NULL_PTR);
5896 arm_ccfsm_state = 0;
5897 arm_target_insn = NULL;
5900 arm_target_insn = this_insn;
5909 get_arm_condition_code (XEXP (XEXP (XEXP (SET_SRC (body),
5911 if (GET_CODE (XEXP (XEXP (SET_SRC (body), 0), 0)) == AND)
5912 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
5913 if (GET_CODE (XEXP (SET_SRC (body), 0)) == NE)
5914 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
5918 /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from
5921 arm_current_cc = get_arm_condition_code (XEXP (SET_SRC (body),
5925 if (reverse || then_not_else)
5926 arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc);
5928 /* restore recog_operand (getting the attributes of other insns can
5929 destroy this array, but final.c assumes that it remains intact
5930 across this call; since the insn has been recognized already we
5931 call recog direct). */
5932 recog (PATTERN (insn), insn, NULL_PTR);
5936 #ifdef AOF_ASSEMBLER
5937 /* Special functions only needed when producing AOF syntax assembler. */
5939 rtx aof_pic_label = NULL_RTX;
5942 struct pic_chain *next;
5946 static struct pic_chain *aof_pic_chain = NULL;
5952 struct pic_chain **chainp;
5955 if (aof_pic_label == NULL_RTX)
5957 /* This needs to persist throughout the compilation. */
5958 end_temporary_allocation ();
5959 aof_pic_label = gen_rtx (SYMBOL_REF, Pmode, "x$adcons");
5960 resume_temporary_allocation ();
5963 for (offset = 0, chainp = &aof_pic_chain; *chainp;
5964 offset += 4, chainp = &(*chainp)->next)
5965 if ((*chainp)->symname == XSTR (x, 0))
5966 return plus_constant (aof_pic_label, offset);
5968 *chainp = (struct pic_chain *) xmalloc (sizeof (struct pic_chain));
5969 (*chainp)->next = NULL;
5970 (*chainp)->symname = XSTR (x, 0);
5971 return plus_constant (aof_pic_label, offset);
5975 aof_dump_pic_table (f)
5978 struct pic_chain *chain;
5980 if (aof_pic_chain == NULL)
5983 fprintf (f, "\tAREA |%s$$adcons|, BASED %s%s\n",
5984 reg_names[PIC_OFFSET_TABLE_REGNUM], REGISTER_PREFIX,
5985 reg_names[PIC_OFFSET_TABLE_REGNUM]);
5986 fputs ("|x$adcons|\n", f);
5988 for (chain = aof_pic_chain; chain; chain = chain->next)
5990 fputs ("\tDCD\t", f);
5991 assemble_name (f, chain->symname);
5996 int arm_text_section_count = 1;
6001 static char buf[100];
6002 sprintf (buf, "\tAREA |C$$code%d|, CODE, READONLY",
6003 arm_text_section_count++);
6005 strcat (buf, ", PIC, REENTRANT");
6009 static int arm_data_section_count = 1;
6014 static char buf[100];
6015 sprintf (buf, "\tAREA |C$$data%d|, DATA", arm_data_section_count++);
6019 /* The AOF assembler is religiously strict about declarations of
6020 imported and exported symbols, so that it is impossible to declare
6021 a function as imported near the beginning of the file, and then to
6022 export it later on. It is, however, possible to delay the decision
6023 until all the functions in the file have been compiled. To get
6024 around this, we maintain a list of the imports and exports, and
6025 delete from it any that are subsequently defined. At the end of
6026 compilation we spit the remainder of the list out before the END
6031 struct import *next;
6035 static struct import *imports_list = NULL;
6038 aof_add_import (name)
6043 for (new = imports_list; new; new = new->next)
6044 if (new->name == name)
6047 new = (struct import *) xmalloc (sizeof (struct import));
6048 new->next = imports_list;
6054 aof_delete_import (name)
6057 struct import **old;
6059 for (old = &imports_list; *old; old = & (*old)->next)
6061 if ((*old)->name == name)
6063 *old = (*old)->next;
6069 int arm_main_function = 0;
6072 aof_dump_imports (f)
6075 /* The AOF assembler needs this to cause the startup code to be extracted
6076 from the library. Brining in __main causes the whole thing to work
6078 if (arm_main_function)
6081 fputs ("\tIMPORT __main\n", f);
6082 fputs ("\tDCD __main\n", f);
6085 /* Now dump the remaining imports. */
6086 while (imports_list)
6088 fprintf (f, "\tIMPORT\t");
6089 assemble_name (f, imports_list->name);
6091 imports_list = imports_list->next;
6094 #endif /* AOF_ASSEMBLER */