1 /* Subroutines for insn-output.c for MIPS
2 Copyright (C) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 Contributed by A. Lichnewsky, lich@inria.inria.fr.
5 Changes by Michael Meissner, meissner@osf.org.
6 64 bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
7 Brendan Eich, brendan@microunity.com.
9 This file is part of GNU CC.
11 GNU CC is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GNU CC is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GNU CC; see the file COPYING. If not, write to
23 the Free Software Foundation, 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
26 /* ??? The TARGET_FP_CALL_32 macros are intended to simulate a 32 bit
27 calling convention in 64 bit mode. It doesn't work though, and should
28 be replaced with something better designed. */
32 #include "coretypes.h"
37 #include "hard-reg-set.h"
39 #include "insn-config.h"
40 #include "conditions.h"
41 #include "insn-attr.h"
57 #include "target-def.h"
58 #include "integrate.h"
61 #define STAB_CODE_TYPE enum __stab_debug_code
63 #define STAB_CODE_TYPE int
66 extern tree lookup_name PARAMS ((tree));
68 /* Enumeration for all of the relational tests, so that we can build
69 arrays indexed by the test type, and not worry about the order
86 /* Return true if it is likely that the given mode will be accessed
87 using only a single instruction. */
88 #define SINGLE_WORD_MODE_P(MODE) \
89 ((MODE) != BLKmode && GET_MODE_SIZE (MODE) <= UNITS_PER_WORD)
92 /* Classifies a non-literal integer constant.
95 Not one of the constants below.
98 The global pointer, treated as a constant when TARGET_MIPS16.
104 A signed 16-bit relocation against either a symbol
105 or a symbol plus an offset. The relocation has the form:
107 (unspec [(SYMBOL) ...] RELOC)
109 Any offset is added outside the unspec, such as:
111 (plus (unspec [(SYMBOL) ...] RELOC) (const_int OFFSET))
113 In either case, the whole expression is wrapped in a (const ...).
116 A reference to a symbol, possibly with an offset. */
117 enum mips_constant_type {
125 /* Classifies a SYMBOL_REF or LABEL_REF.
128 Used when none of the below apply.
131 The symbol refers to something in a small data section.
134 The symbol refers to something in the mips16 constant pool.
137 The symbol refers to local data that will be found using
138 the global offset table.
141 Likewise non-local data. */
142 enum mips_symbol_type {
145 SYMBOL_CONSTANT_POOL,
151 /* Classifies an address.
154 The address should be rejected as invalid.
157 A natural register + offset address. The register satisfies
158 mips_valid_base_register_p and the offset is a const_arith_operand.
161 A LO_SUM rtx. The first operand is a valid base register and
162 the second operand is a symbolic address.
165 A signed 16-bit constant address.
168 A constant symbolic address (equivalent to CONSTANT_SYMBOLIC). */
169 enum mips_address_type {
179 struct mips_arg_info;
180 struct mips_constant_info;
181 struct mips_address_info;
182 struct mips_integer_op;
183 static enum mips_constant_type mips_classify_constant
184 PARAMS ((struct mips_constant_info *, rtx));
185 static enum mips_symbol_type mips_classify_symbol
187 static bool mips_valid_base_register_p
188 PARAMS ((rtx, enum machine_mode, int));
189 static bool mips_symbolic_address_p
190 PARAMS ((rtx, HOST_WIDE_INT,
191 enum machine_mode, int));
192 static enum mips_address_type mips_classify_address
193 PARAMS ((struct mips_address_info *,
194 rtx, enum machine_mode, int, int));
195 static enum internal_test map_test_to_internal_test PARAMS ((enum rtx_code));
196 static void get_float_compare_codes PARAMS ((enum rtx_code, enum rtx_code *,
198 static const char *mips_reloc_string PARAMS ((int));
199 static bool mips_splittable_symbol_p PARAMS ((enum mips_symbol_type));
200 static int mips_symbol_insns PARAMS ((enum mips_symbol_type));
201 static bool mips16_unextended_reference_p
202 PARAMS ((enum machine_mode mode,
204 static rtx mips_force_temporary PARAMS ((rtx, rtx));
205 static rtx mips_add_offset PARAMS ((rtx, HOST_WIDE_INT));
206 static rtx mips_load_got PARAMS ((rtx, rtx, int));
207 static rtx mips_load_got16 PARAMS ((rtx, int));
208 static rtx mips_load_got32 PARAMS ((rtx, rtx, int, int));
209 static rtx mips_emit_high PARAMS ((rtx, rtx));
210 static bool mips_legitimize_symbol PARAMS ((rtx, rtx *, int));
211 static rtx mips_reloc PARAMS ((rtx, int));
212 static rtx mips_lui_reloc PARAMS ((rtx, int));
213 static unsigned int mips_build_shift PARAMS ((struct mips_integer_op *,
215 static unsigned int mips_build_lower PARAMS ((struct mips_integer_op *,
216 unsigned HOST_WIDE_INT));
217 static unsigned int mips_build_integer PARAMS ((struct mips_integer_op *,
218 unsigned HOST_WIDE_INT));
219 static void mips_move_integer PARAMS ((rtx, unsigned HOST_WIDE_INT));
220 static void mips_legitimize_const_move PARAMS ((enum machine_mode,
222 static int m16_check_op PARAMS ((rtx, int, int, int));
223 static bool mips_function_ok_for_sibcall PARAMS ((tree, tree));
224 static void block_move_loop PARAMS ((rtx, rtx,
228 static void block_move_call PARAMS ((rtx, rtx, rtx));
229 static void mips_arg_info PARAMS ((const CUMULATIVE_ARGS *,
232 struct mips_arg_info *));
233 static bool mips_get_unaligned_mem PARAMS ((rtx *, unsigned int,
235 static rtx mips_add_large_offset_to_sp PARAMS ((HOST_WIDE_INT));
236 static void mips_set_frame_expr PARAMS ((rtx));
237 static rtx mips_frame_set PARAMS ((rtx, int));
238 static void mips_emit_frame_related_store PARAMS ((rtx, rtx,
240 static void save_restore_insns PARAMS ((int, rtx, long));
241 static void mips16_fp_args PARAMS ((FILE *, int, int));
242 static void build_mips16_function_stub PARAMS ((FILE *));
243 static void mips16_optimize_gp PARAMS ((rtx));
244 static rtx add_constant PARAMS ((struct constant **,
247 static void dump_constants PARAMS ((struct constant *,
249 static rtx mips_find_symbol PARAMS ((rtx));
250 static void mips_reorg PARAMS ((void));
251 static void abort_with_insn PARAMS ((rtx, const char *))
253 static int symbolic_expression_p PARAMS ((rtx));
254 static bool mips_assemble_integer PARAMS ((rtx, unsigned int, int));
255 static void mips_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
256 static void mips_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
257 static void mips_set_architecture PARAMS ((const struct mips_cpu_info *));
258 static void mips_set_tune PARAMS ((const struct mips_cpu_info *));
259 static bool mips_strict_matching_cpu_name_p PARAMS ((const char *,
261 static bool mips_matching_cpu_name_p PARAMS ((const char *,
263 static const struct mips_cpu_info *mips_parse_cpu PARAMS ((const char *,
265 static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
266 static void copy_file_data PARAMS ((FILE *, FILE *));
268 static void iris6_asm_named_section_1 PARAMS ((const char *,
271 static void iris6_asm_named_section PARAMS ((const char *,
273 static int iris_section_align_entry_eq PARAMS ((const PTR, const PTR));
274 static hashval_t iris_section_align_entry_hash PARAMS ((const PTR));
275 static int iris6_section_align_1 PARAMS ((void **, void *));
277 static int mips_adjust_cost PARAMS ((rtx, rtx, rtx, int));
278 static int mips_issue_rate PARAMS ((void));
280 static struct machine_function * mips_init_machine_status PARAMS ((void));
281 static void mips_select_section PARAMS ((tree, int, unsigned HOST_WIDE_INT))
283 static void mips_unique_section PARAMS ((tree, int))
285 static void mips_select_rtx_section PARAMS ((enum machine_mode, rtx,
286 unsigned HOST_WIDE_INT));
287 static int mips_use_dfa_pipeline_interface PARAMS ((void));
288 static bool mips_rtx_costs PARAMS ((rtx, int, int, int *));
289 static int mips_address_cost PARAMS ((rtx));
290 static void mips_encode_section_info PARAMS ((tree, rtx, int));
293 /* Structure to be filled in by compute_frame_size with register
294 save masks, and offsets for the current function. */
296 struct mips_frame_info GTY(())
298 long total_size; /* # bytes that the entire frame takes up */
299 long var_size; /* # bytes that variables take up */
300 long args_size; /* # bytes that outgoing arguments take up */
301 long extra_size; /* # bytes of extra gunk */
302 int gp_reg_size; /* # bytes needed to store gp regs */
303 int fp_reg_size; /* # bytes needed to store fp regs */
304 long mask; /* mask of saved gp registers */
305 long fmask; /* mask of saved fp registers */
306 long gp_save_offset; /* offset from vfp to store gp registers */
307 long fp_save_offset; /* offset from vfp to store fp registers */
308 long gp_sp_offset; /* offset from new sp to store gp registers */
309 long fp_sp_offset; /* offset from new sp to store fp registers */
310 int initialized; /* != 0 if frame size already calculated */
311 int num_gp; /* number of gp registers saved */
312 int num_fp; /* number of fp registers saved */
315 struct machine_function GTY(()) {
316 /* Pseudo-reg holding the address of the current function when
317 generating embedded PIC code. Created by LEGITIMIZE_ADDRESS,
318 used by mips_finalize_pic if it was created. */
319 rtx embedded_pic_fnaddr_rtx;
321 /* Pseudo-reg holding the value of $28 in a mips16 function which
322 refers to GP relative global variables. */
323 rtx mips16_gp_pseudo_rtx;
325 /* Current frame information, calculated by compute_frame_size. */
326 struct mips_frame_info frame;
328 /* Length of instructions in function; mips16 only. */
332 /* Information about a single argument. */
335 /* True if the argument is a record or union type. */
338 /* True if the argument is passed in a floating-point register, or
339 would have been if we hadn't run out of registers. */
342 /* The argument's size, in bytes. */
343 unsigned int num_bytes;
345 /* The number of words passed in registers, rounded up. */
346 unsigned int reg_words;
348 /* The offset of the first register from GP_ARG_FIRST or FP_ARG_FIRST,
349 or MAX_ARGS_IN_REGISTERS if the argument is passed entirely
351 unsigned int reg_offset;
353 /* The number of words that must be passed on the stack, rounded up. */
354 unsigned int stack_words;
356 /* The offset from the start of the stack overflow area of the argument's
357 first stack word. Only meaningful when STACK_WORDS is nonzero. */
358 unsigned int stack_offset;
362 /* Struct for recording constants. The meaning of the fields depends
363 on a mips_constant_type:
370 SYMBOL is the relocation UNSPEC and OFFSET is the offset applied
374 SYMBOL is the referenced symbol and OFFSET is the constant offset. */
375 struct mips_constant_info
378 HOST_WIDE_INT offset;
382 /* Information about an address described by mips_address_type.
389 REG is the base register and OFFSET is the constant offset.
392 REG is the register that contains the high part of the address,
393 OFFSET is the symbolic address being referenced, and C contains
394 the individual components of the symbolic address.
397 C contains the symbol and offset. */
398 struct mips_address_info
402 struct mips_constant_info c;
406 /* One stage in a constant building sequence. These sequences have
410 A = A CODE[1] VALUE[1]
411 A = A CODE[2] VALUE[2]
414 where A is an accumulator, each CODE[i] is a binary rtl operation
415 and each VALUE[i] is a constant integer. */
416 struct mips_integer_op {
418 unsigned HOST_WIDE_INT value;
422 /* The largest number of operations needed to load an integer constant.
423 The worst accepted case for 64-bit constants is LUI,ORI,SLL,ORI,SLL,ORI.
424 When the lowest bit is clear, we can try, but reject a sequence with
425 an extra SLL at the end. */
426 #define MIPS_MAX_INTEGER_OPS 7
429 /* Global variables for machine-dependent things. */
431 /* Threshold for data being put into the small data/bss area, instead
432 of the normal data area (references to the small data/bss area take
433 1 instruction, and use the global pointer, references to the normal
434 data area takes 2 instructions). */
435 int mips_section_threshold = -1;
437 /* Count the number of .file directives, so that .loc is up to date. */
438 int num_source_filenames = 0;
440 /* Count the number of sdb related labels are generated (to find block
441 start and end boundaries). */
442 int sdb_label_count = 0;
444 /* Next label # for each statement for Silicon Graphics IRIS systems. */
447 /* Nonzero if inside of a function, because the stupid MIPS asm can't
448 handle .files inside of functions. */
449 int inside_function = 0;
451 /* Files to separate the text and the data output, so that all of the data
452 can be emitted before the text, which will mean that the assembler will
453 generate smaller code, based on the global pointer. */
454 FILE *asm_out_data_file;
455 FILE *asm_out_text_file;
457 /* Linked list of all externals that are to be emitted when optimizing
458 for the global pointer if they haven't been declared by the end of
459 the program with an appropriate .comm or initialization. */
461 struct extern_list GTY (())
463 struct extern_list *next; /* next external */
464 const char *name; /* name of the external */
465 int size; /* size in bytes */
468 static GTY (()) struct extern_list *extern_head = 0;
470 /* Name of the file containing the current function. */
471 const char *current_function_file = "";
473 /* Warning given that Mips ECOFF can't support changing files
474 within a function. */
475 int file_in_function_warning = FALSE;
477 /* Whether to suppress issuing .loc's because the user attempted
478 to change the filename within a function. */
479 int ignore_line_number = FALSE;
481 /* Number of nested .set noreorder, noat, nomacro, and volatile requests. */
487 /* The next branch instruction is a branch likely, not branch normal. */
488 int mips_branch_likely;
490 /* Cached operands, and operator to compare for use in set/branch/trap
491 on condition codes. */
494 /* what type of branch to use */
495 enum cmp_type branch_type;
497 /* The target cpu for code generation. */
498 enum processor_type mips_arch;
499 const struct mips_cpu_info *mips_arch_info;
501 /* The target cpu for optimization and scheduling. */
502 enum processor_type mips_tune;
503 const struct mips_cpu_info *mips_tune_info;
505 /* which instruction set architecture to use. */
508 /* which abi to use. */
511 /* Strings to hold which cpu and instruction set architecture to use. */
512 const char *mips_arch_string; /* for -march=<xxx> */
513 const char *mips_tune_string; /* for -mtune=<xxx> */
514 const char *mips_isa_string; /* for -mips{1,2,3,4} */
515 const char *mips_abi_string; /* for -mabi={32,n32,64,eabi} */
517 /* Whether we are generating mips16 code. This is a synonym for
518 TARGET_MIPS16, and exists for use as an attribute. */
521 /* This variable is set by -mno-mips16. We only care whether
522 -mno-mips16 appears or not, and using a string in this fashion is
523 just a way to avoid using up another bit in target_flags. */
524 const char *mips_no_mips16_string;
526 /* Whether we are generating mips16 hard float code. In mips16 mode
527 we always set TARGET_SOFT_FLOAT; this variable is nonzero if
528 -msoft-float was not specified by the user, which means that we
529 should arrange to call mips32 hard floating point code. */
530 int mips16_hard_float;
532 /* This variable is set by -mentry. We only care whether -mentry
533 appears or not, and using a string in this fashion is just a way to
534 avoid using up another bit in target_flags. */
535 const char *mips_entry_string;
537 const char *mips_cache_flush_func = CACHE_FLUSH_FUNC;
539 /* Whether we should entry and exit pseudo-ops in mips16 mode. */
542 /* If TRUE, we split addresses into their high and low parts in the RTL. */
543 int mips_split_addresses;
545 /* Generating calls to position independent functions? */
546 enum mips_abicalls_type mips_abicalls;
548 /* Mode used for saving/restoring general purpose registers. */
549 static enum machine_mode gpr_mode;
551 /* Array giving truth value on whether or not a given hard register
552 can support a given mode. */
553 char mips_hard_regno_mode_ok[(int)MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
555 /* The length of all strings seen when compiling for the mips16. This
556 is used to tell how many strings are in the constant pool, so that
557 we can see if we may have an overflow. This is reset each time the
558 constant pool is output. */
559 int mips_string_length;
561 /* When generating mips16 code, a list of all strings that are to be
562 output after the current function. */
564 static GTY(()) rtx mips16_strings;
566 /* In mips16 mode, we build a list of all the string constants we see
567 in a particular function. */
569 struct string_constant
571 struct string_constant *next;
575 static struct string_constant *string_constants;
577 /* List of all MIPS punctuation characters used by print_operand. */
578 char mips_print_operand_punct[256];
580 /* Map GCC register number to debugger register number. */
581 int mips_dbx_regno[FIRST_PSEUDO_REGISTER];
583 /* An alias set for the GOT. */
584 static int mips_got_alias_set;
586 static GTY (()) int mips_output_filename_first_time = 1;
588 /* Hardware names for the registers. If -mrnames is used, this
589 will be overwritten with mips_sw_reg_names. */
591 char mips_reg_names[][8] =
593 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
594 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
595 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
596 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
597 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
598 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
599 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
600 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
601 "hi", "lo", "accum","$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
602 "$fcc5","$fcc6","$fcc7","", "", "", "", "",
603 "$c0r0", "$c0r1", "$c0r2", "$c0r3", "$c0r4", "$c0r5", "$c0r6", "$c0r7",
604 "$c0r8", "$c0r9", "$c0r10","$c0r11","$c0r12","$c0r13","$c0r14","$c0r15",
605 "$c0r16","$c0r17","$c0r18","$c0r19","$c0r20","$c0r21","$c0r22","$c0r23",
606 "$c0r24","$c0r25","$c0r26","$c0r27","$c0r28","$c0r29","$c0r30","$c0r31",
607 "$c2r0", "$c2r1", "$c2r2", "$c2r3", "$c2r4", "$c2r5", "$c2r6", "$c2r7",
608 "$c2r8", "$c2r9", "$c2r10","$c2r11","$c2r12","$c2r13","$c2r14","$c2r15",
609 "$c2r16","$c2r17","$c2r18","$c2r19","$c2r20","$c2r21","$c2r22","$c2r23",
610 "$c2r24","$c2r25","$c2r26","$c2r27","$c2r28","$c2r29","$c2r30","$c2r31",
611 "$c3r0", "$c3r1", "$c3r2", "$c3r3", "$c3r4", "$c3r5", "$c3r6", "$c3r7",
612 "$c3r8", "$c3r9", "$c3r10","$c3r11","$c3r12","$c3r13","$c3r14","$c3r15",
613 "$c3r16","$c3r17","$c3r18","$c3r19","$c3r20","$c3r21","$c3r22","$c3r23",
614 "$c3r24","$c3r25","$c3r26","$c3r27","$c3r28","$c3r29","$c3r30","$c3r31"
617 /* Mips software names for the registers, used to overwrite the
618 mips_reg_names array. */
620 char mips_sw_reg_names[][8] =
622 "$zero","$at", "$v0", "$v1", "$a0", "$a1", "$a2", "$a3",
623 "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7",
624 "$s0", "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7",
625 "$t8", "$t9", "$k0", "$k1", "$gp", "$sp", "$fp", "$ra",
626 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
627 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
628 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
629 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
630 "hi", "lo", "accum","$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
631 "$fcc5","$fcc6","$fcc7","$rap", "", "", "", "",
632 "$c0r0", "$c0r1", "$c0r2", "$c0r3", "$c0r4", "$c0r5", "$c0r6", "$c0r7",
633 "$c0r8", "$c0r9", "$c0r10","$c0r11","$c0r12","$c0r13","$c0r14","$c0r15",
634 "$c0r16","$c0r17","$c0r18","$c0r19","$c0r20","$c0r21","$c0r22","$c0r23",
635 "$c0r24","$c0r25","$c0r26","$c0r27","$c0r28","$c0r29","$c0r30","$c0r31",
636 "$c2r0", "$c2r1", "$c2r2", "$c2r3", "$c2r4", "$c2r5", "$c2r6", "$c2r7",
637 "$c2r8", "$c2r9", "$c2r10","$c2r11","$c2r12","$c2r13","$c2r14","$c2r15",
638 "$c2r16","$c2r17","$c2r18","$c2r19","$c2r20","$c2r21","$c2r22","$c2r23",
639 "$c2r24","$c2r25","$c2r26","$c2r27","$c2r28","$c2r29","$c2r30","$c2r31",
640 "$c3r0", "$c3r1", "$c3r2", "$c3r3", "$c3r4", "$c3r5", "$c3r6", "$c3r7",
641 "$c3r8", "$c3r9", "$c3r10","$c3r11","$c3r12","$c3r13","$c3r14","$c3r15",
642 "$c3r16","$c3r17","$c3r18","$c3r19","$c3r20","$c3r21","$c3r22","$c3r23",
643 "$c3r24","$c3r25","$c3r26","$c3r27","$c3r28","$c3r29","$c3r30","$c3r31"
646 /* Map hard register number to register class */
647 const enum reg_class mips_regno_to_class[] =
649 LEA_REGS, LEA_REGS, M16_NA_REGS, M16_NA_REGS,
650 M16_REGS, M16_REGS, M16_REGS, M16_REGS,
651 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
652 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
653 M16_NA_REGS, M16_NA_REGS, LEA_REGS, LEA_REGS,
654 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
655 T_REG, PIC_FN_ADDR_REG, LEA_REGS, LEA_REGS,
656 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
657 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
658 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
659 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
660 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
661 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
662 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
663 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
664 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
665 HI_REG, LO_REG, HILO_REG, ST_REGS,
666 ST_REGS, ST_REGS, ST_REGS, ST_REGS,
667 ST_REGS, ST_REGS, ST_REGS, NO_REGS,
668 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
669 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
670 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
671 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
672 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
673 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
674 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
675 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
676 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
677 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
678 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
679 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
680 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
681 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
682 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
683 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
684 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
685 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
686 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
687 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
688 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
689 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
690 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
691 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
692 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS
695 /* Map register constraint character to register class. */
696 enum reg_class mips_char_to_class[256] =
698 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
699 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
700 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
701 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
702 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
703 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
704 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
705 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
706 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
707 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
708 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
709 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
710 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
711 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
712 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
713 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
714 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
715 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
716 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
717 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
718 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
719 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
720 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
721 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
722 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
723 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
724 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
725 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
726 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
727 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
728 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
729 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
730 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
731 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
732 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
733 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
734 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
735 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
736 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
737 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
738 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
739 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
740 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
741 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
742 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
743 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
744 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
745 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
746 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
747 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
748 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
749 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
750 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
751 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
752 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
753 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
754 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
755 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
756 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
757 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
758 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
759 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
760 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
761 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
764 /* A table describing all the processors gcc knows about. Names are
765 matched in the order listed. The first mention of an ISA level is
766 taken as the canonical name for that ISA.
768 To ease comparison, please keep this table in the same order as
769 gas's mips_cpu_info_table[]. */
770 const struct mips_cpu_info mips_cpu_info_table[] = {
771 /* Entries for generic ISAs */
772 { "mips1", PROCESSOR_R3000, 1 },
773 { "mips2", PROCESSOR_R6000, 2 },
774 { "mips3", PROCESSOR_R4000, 3 },
775 { "mips4", PROCESSOR_R8000, 4 },
776 { "mips32", PROCESSOR_4KC, 32 },
777 { "mips32r2", PROCESSOR_M4K, 33 },
778 { "mips64", PROCESSOR_5KC, 64 },
781 { "r3000", PROCESSOR_R3000, 1 },
782 { "r2000", PROCESSOR_R3000, 1 }, /* = r3000 */
783 { "r3900", PROCESSOR_R3900, 1 },
786 { "r6000", PROCESSOR_R6000, 2 },
789 { "r4000", PROCESSOR_R4000, 3 },
790 { "vr4100", PROCESSOR_R4100, 3 },
791 { "vr4111", PROCESSOR_R4111, 3 },
792 { "vr4120", PROCESSOR_R4120, 3 },
793 { "vr4300", PROCESSOR_R4300, 3 },
794 { "r4400", PROCESSOR_R4000, 3 }, /* = r4000 */
795 { "r4600", PROCESSOR_R4600, 3 },
796 { "orion", PROCESSOR_R4600, 3 }, /* = r4600 */
797 { "r4650", PROCESSOR_R4650, 3 },
800 { "r8000", PROCESSOR_R8000, 4 },
801 { "vr5000", PROCESSOR_R5000, 4 },
802 { "vr5400", PROCESSOR_R5400, 4 },
803 { "vr5500", PROCESSOR_R5500, 4 },
806 { "4kc", PROCESSOR_4KC, 32 },
807 { "4kp", PROCESSOR_4KC, 32 }, /* = 4kc */
809 /* MIPS32 Release 2 */
810 { "m4k", PROCESSOR_M4K, 33 },
813 { "5kc", PROCESSOR_5KC, 64 },
814 { "20kc", PROCESSOR_20KC, 64 },
815 { "sb1", PROCESSOR_SB1, 64 },
816 { "sr71000", PROCESSOR_SR71000, 64 },
822 /* Nonzero if -march should decide the default value of MASK_SOFT_FLOAT. */
823 #ifndef MIPS_MARCH_CONTROLS_SOFT_FLOAT
824 #define MIPS_MARCH_CONTROLS_SOFT_FLOAT 0
827 /* Initialize the GCC target structure. */
828 #undef TARGET_ASM_ALIGNED_HI_OP
829 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
830 #undef TARGET_ASM_ALIGNED_SI_OP
831 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
832 #undef TARGET_ASM_INTEGER
833 #define TARGET_ASM_INTEGER mips_assemble_integer
835 #if TARGET_IRIX5 && !TARGET_IRIX6
836 #undef TARGET_ASM_UNALIGNED_HI_OP
837 #define TARGET_ASM_UNALIGNED_HI_OP "\t.align 0\n\t.half\t"
838 #undef TARGET_ASM_UNALIGNED_SI_OP
839 #define TARGET_ASM_UNALIGNED_SI_OP "\t.align 0\n\t.word\t"
840 #undef TARGET_ASM_UNALIGNED_DI_OP
841 #define TARGET_ASM_UNALIGNED_DI_OP "\t.align 0\n\t.dword\t"
844 #undef TARGET_ASM_FUNCTION_PROLOGUE
845 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
846 #undef TARGET_ASM_FUNCTION_EPILOGUE
847 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
848 #undef TARGET_ASM_SELECT_RTX_SECTION
849 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
851 #undef TARGET_SCHED_ADJUST_COST
852 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
853 #undef TARGET_SCHED_ISSUE_RATE
854 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
855 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
856 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE mips_use_dfa_pipeline_interface
858 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
859 #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall
861 #undef TARGET_VALID_POINTER_MODE
862 #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
863 #undef TARGET_RTX_COSTS
864 #define TARGET_RTX_COSTS mips_rtx_costs
865 #undef TARGET_ADDRESS_COST
866 #define TARGET_ADDRESS_COST mips_address_cost
867 #undef TARGET_DELEGITIMIZE_ADDRESS
868 #define TARGET_DELEGITIMIZE_ADDRESS mips_delegitimize_address
870 #undef TARGET_ENCODE_SECTION_INFO
871 #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
873 #undef TARGET_MACHINE_DEPENDENT_REORG
874 #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
876 struct gcc_target targetm = TARGET_INITIALIZER;
878 /* If X is one of the constants described by mips_constant_type,
879 store its components in INFO and return its type. */
881 static enum mips_constant_type
882 mips_classify_constant (info, x)
883 struct mips_constant_info *info;
888 if (GET_CODE (x) == CONST)
892 if (GET_CODE (x) == REG && REGNO (x) == GP_REG_FIRST + 28)
895 while (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
897 info->offset += INTVAL (XEXP (x, 1));
901 if (GET_CODE (x) == UNSPEC)
906 /* These relocations can be applied to symbols with offsets. */
907 return CONSTANT_RELOC;
915 /* These relocations should be applied to bare symbols only. */
916 return (info->offset == 0 ? CONSTANT_RELOC : CONSTANT_NONE);
919 if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
920 return CONSTANT_SYMBOLIC;
921 return CONSTANT_NONE;
925 /* Classify symbol X, which must be a SYMBOL_REF or a LABEL_REF. */
927 static enum mips_symbol_type
928 mips_classify_symbol (x)
931 if (GET_CODE (x) == LABEL_REF)
932 return (TARGET_ABICALLS ? SYMBOL_GOT_LOCAL : SYMBOL_GENERAL);
934 if (GET_CODE (x) != SYMBOL_REF)
937 if (CONSTANT_POOL_ADDRESS_P (x))
940 return SYMBOL_CONSTANT_POOL;
943 return SYMBOL_GOT_LOCAL;
945 if (GET_MODE_SIZE (get_pool_mode (x)) <= mips_section_threshold)
946 return SYMBOL_SMALL_DATA;
948 return SYMBOL_GENERAL;
951 if (XSTR (x, 0)[0] == '*'
952 && strncmp (XSTR (x, 0) + 1, LOCAL_LABEL_PREFIX,
953 sizeof LOCAL_LABEL_PREFIX - 1) == 0)
955 /* The symbol is a local label. For TARGET_MIPS16, SYMBOL_REF_FLAG
956 will be set if the symbol refers to a string in the current
957 function's constant pool. */
958 if (TARGET_MIPS16 && SYMBOL_REF_FLAG (x))
959 return SYMBOL_CONSTANT_POOL;
962 return SYMBOL_GOT_LOCAL;
966 return (SYMBOL_REF_FLAG (x) ? SYMBOL_GOT_LOCAL : SYMBOL_GOT_GLOBAL);
968 return (SYMBOL_REF_FLAG (x) ? SYMBOL_SMALL_DATA : SYMBOL_GENERAL);
972 /* This function is used to implement REG_MODE_OK_FOR_BASE_P. */
975 mips_reg_mode_ok_for_base_p (reg, mode, strict)
977 enum machine_mode mode;
981 ? REGNO_MODE_OK_FOR_BASE_P (REGNO (reg), mode)
982 : GP_REG_OR_PSEUDO_NONSTRICT_P (REGNO (reg), mode));
986 /* Return true if X is a valid base register for the given mode.
987 Allow only hard registers if STRICT. */
990 mips_valid_base_register_p (x, mode, strict)
992 enum machine_mode mode;
995 if (!strict && GET_CODE (x) == SUBREG)
998 return (GET_CODE (x) == REG
999 && mips_reg_mode_ok_for_base_p (x, mode, strict));
1003 /* Return true if SYMBOL + OFFSET should be considered a legitimate
1004 address. LEA_P is true and MODE is word_mode if the address
1005 will be used in an LA or DLA macro. Otherwise MODE is the
1006 mode of the value being accessed.
1008 Some guiding principles:
1010 - Allow a nonzero offset when it takes no additional instructions.
1011 Ask for other offsets to be added separately.
1013 - Only allow multi-instruction load or store macros when MODE is
1014 word-sized or smaller. For other modes (including BLKmode)
1015 it is better to move the address into a register first. */
1018 mips_symbolic_address_p (symbol, offset, mode, lea_p)
1020 HOST_WIDE_INT offset;
1021 enum machine_mode mode;
1024 if (TARGET_EXPLICIT_RELOCS)
1027 switch (mips_classify_symbol (symbol))
1029 case SYMBOL_GENERAL:
1030 /* General symbols aren't valid addresses in mips16 code:
1031 they have to go into the constant pool. */
1032 return (!TARGET_MIPS16
1033 && !mips_split_addresses
1034 && SINGLE_WORD_MODE_P (mode));
1036 case SYMBOL_SMALL_DATA:
1037 /* Small data references are normally OK for any address.
1038 But for mips16 code, we need to use a pseudo register
1039 instead of $gp as the base register. */
1040 return !TARGET_MIPS16;
1042 case SYMBOL_CONSTANT_POOL:
1043 /* PC-relative addressing is only available for lw, sw, ld and sd.
1044 There's also a PC-relative add instruction. */
1045 return lea_p || GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1047 case SYMBOL_GOT_GLOBAL:
1048 /* The address of the symbol is stored in the GOT. We can load
1049 it using an LA or DLA instruction, but any offset is added
1051 return lea_p && offset == 0;
1053 case SYMBOL_GOT_LOCAL:
1054 /* The symbol is part of a block of local memory. We fetch the
1055 address of the local memory from the GOT and then add the
1056 offset for this symbol. This addition can take the form of an
1057 offset(base) address, so the symbol is a legitimate address. */
1058 return SINGLE_WORD_MODE_P (mode);
1064 /* If X is a valid address, describe it in INFO and return its type.
1065 STRICT says to only allow hard registers. MODE and LEA_P are
1066 the same as for mips_symbolic_address_p. */
1068 static enum mips_address_type
1069 mips_classify_address (info, x, mode, strict, lea_p)
1070 struct mips_address_info *info;
1072 enum machine_mode mode;
1075 switch (GET_CODE (x))
1079 if (mips_valid_base_register_p (x, mode, strict))
1082 info->offset = const0_rtx;
1085 return ADDRESS_INVALID;
1088 if (mips_valid_base_register_p (XEXP (x, 0), mode, strict)
1089 && const_arith_operand (XEXP (x, 1), VOIDmode))
1091 info->reg = XEXP (x, 0);
1092 info->offset = XEXP (x, 1);
1095 return ADDRESS_INVALID;
1098 if (SINGLE_WORD_MODE_P (mode)
1099 && mips_valid_base_register_p (XEXP (x, 0), mode, strict)
1100 && (mips_classify_constant (&info->c, XEXP (x, 1))
1101 == CONSTANT_SYMBOLIC)
1102 && mips_splittable_symbol_p (mips_classify_symbol (info->c.symbol)))
1104 info->reg = XEXP (x, 0);
1105 info->offset = XEXP (x, 1);
1106 return ADDRESS_LO_SUM;
1108 return ADDRESS_INVALID;
1111 /* Small-integer addressses don't occur very often, but they
1112 are legitimate if $0 is a valid base register. */
1113 if (!TARGET_MIPS16 && SMALL_INT (x))
1114 return ADDRESS_CONST_INT;
1115 return ADDRESS_INVALID;
1120 if (mips_classify_constant (&info->c, x) == CONSTANT_SYMBOLIC
1121 && mips_symbolic_address_p (info->c.symbol, info->c.offset,
1123 return ADDRESS_SYMBOLIC;
1124 return ADDRESS_INVALID;
1127 return ADDRESS_INVALID;
1131 /* Return true if symbols of the given type can be split into a
1132 HIGH/LO_SUM pair. */
1135 mips_splittable_symbol_p (type)
1136 enum mips_symbol_type type;
1138 if (TARGET_EXPLICIT_RELOCS)
1139 return (type == SYMBOL_GENERAL || type == SYMBOL_GOT_LOCAL);
1140 if (mips_split_addresses)
1141 return (type == SYMBOL_GENERAL);
1146 /* Return the number of instructions needed to load a symbol of the
1147 given type into a register. If valid in an address, the same number
1148 of instructions are needed for loads and stores. Treat extended
1149 mips16 instructions as two instructions. */
1152 mips_symbol_insns (type)
1153 enum mips_symbol_type type;
1157 case SYMBOL_GENERAL:
1158 /* When using 64-bit symbols, we need 5 preparatory instructions,
1161 lui $at,%highest(symbol)
1162 daddiu $at,$at,%higher(symbol)
1164 daddiu $at,$at,%hi(symbol)
1167 The final address is then $at + %lo(symbol). With 32-bit
1168 symbols we just need a preparatory lui. */
1169 return (ABI_HAS_64BIT_SYMBOLS ? 6 : 2);
1171 case SYMBOL_SMALL_DATA:
1174 case SYMBOL_CONSTANT_POOL:
1175 /* This case is for mips16 only. Assume we'll need an
1176 extended instruction. */
1179 case SYMBOL_GOT_GLOBAL:
1180 /* When using a small GOT, we just fetch the address using
1181 a gp-relative load. For a big GOT, we need a sequence
1184 lui $at,%got_hi(symbol)
1187 and the final address is $at + %got_lo(symbol). */
1188 return (flag_pic == 1 ? 1 : 3);
1190 case SYMBOL_GOT_LOCAL:
1191 /* For o32 and o64, the sequence is:
1196 and the final address is $at + %lo(symbol). A load/add
1197 sequence is also needed for n32 and n64. Some versions
1198 of GAS insert a nop in the n32/n64 sequences too so, for
1199 simplicity, use the worst case of 3 instructions. */
1206 /* Return true if a value at OFFSET bytes from BASE can be accessed
1207 using an unextended mips16 instruction. MODE is the mode of the
1210 Usually the offset in an unextended instruction is a 5-bit field.
1211 The offset is unsigned and shifted left once for HIs, twice
1212 for SIs, and so on. An exception is SImode accesses off the
1213 stack pointer, which have an 8-bit immediate field. */
1216 mips16_unextended_reference_p (mode, base, offset)
1217 enum machine_mode mode;
1221 && GET_CODE (offset) == CONST_INT
1222 && INTVAL (offset) >= 0
1223 && (INTVAL (offset) & (GET_MODE_SIZE (mode) - 1)) == 0)
1225 if (GET_MODE_SIZE (mode) == 4 && base == stack_pointer_rtx)
1226 return INTVAL (offset) < 256 * GET_MODE_SIZE (mode);
1227 return INTVAL (offset) < 32 * GET_MODE_SIZE (mode);
1233 /* Return the number of instructions needed to load or store a value
1234 of mode MODE at X. Return 0 if X isn't valid for MODE.
1236 For mips16 code, count extended instructions as two instructions. */
1239 mips_address_insns (x, mode)
1241 enum machine_mode mode;
1243 struct mips_address_info addr;
1246 /* Each word of a multi-word value will be accessed individually. */
1247 factor = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1248 switch (mips_classify_address (&addr, x, mode, 0, 0))
1250 case ADDRESS_INVALID:
1255 && !mips16_unextended_reference_p (mode, addr.reg, addr.offset))
1259 case ADDRESS_LO_SUM:
1260 case ADDRESS_CONST_INT:
1263 case ADDRESS_SYMBOLIC:
1264 return factor * mips_symbol_insns (mips_classify_symbol (addr.c.symbol));
1270 /* Likewise for constant X. */
1273 mips_const_insns (x)
1276 struct mips_constant_info c;
1277 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
1279 switch (GET_CODE (x))
1281 case CONSTANT_P_RTX:
1287 /* Unsigned 8-bit constants can be loaded using an unextended
1288 LI instruction. Unsigned 16-bit constants can be loaded
1289 using an extended LI. Negative constants must be loaded
1290 using LI and then negated. */
1291 return (INTVAL (x) >= 0 && INTVAL (x) < 256 ? 1
1292 : SMALL_OPERAND_UNSIGNED (INTVAL (x)) ? 2
1293 : INTVAL (x) > -256 && INTVAL (x) < 0 ? 2
1294 : SMALL_OPERAND_UNSIGNED (-INTVAL (x)) ? 3
1297 return mips_build_integer (codes, INTVAL (x));
1300 return (!TARGET_MIPS16 && x == CONST0_RTX (GET_MODE (x)) ? 1 : 0);
1303 switch (mips_classify_constant (&c, x))
1311 case CONSTANT_RELOC:
1312 /* When generating mips16 code, we need to set the destination to
1313 $0 and then add in the signed offset. See mips_output_move. */
1314 return (TARGET_MIPS16 ? 3 : 1);
1316 case CONSTANT_SYMBOLIC:
1317 return mips_symbol_insns (mips_classify_symbol (c.symbol));
1324 /* Return the number of instructions needed for memory reference X.
1325 Count extended mips16 instructions as two instructions. */
1328 mips_fetch_insns (x)
1331 if (GET_CODE (x) != MEM)
1334 return mips_address_insns (XEXP (x, 0), GET_MODE (x));
1338 /* Return true if OP is a symbolic constant that refers to a
1339 global PIC symbol. */
1342 mips_global_pic_constant_p (op)
1345 struct mips_constant_info c;
1347 return (mips_classify_constant (&c, op) == CONSTANT_SYMBOLIC
1348 && mips_classify_symbol (c.symbol) == SYMBOL_GOT_GLOBAL);
1352 /* Return truth value of whether OP can be used as an operands
1353 where a register or 16 bit unsigned integer is needed. */
1356 uns_arith_operand (op, mode)
1358 enum machine_mode mode;
1360 if (GET_CODE (op) == CONST_INT && SMALL_INT_UNSIGNED (op))
1363 return register_operand (op, mode);
1367 /* True if OP can be treated as a signed 16-bit constant. */
1370 const_arith_operand (op, mode)
1372 enum machine_mode mode ATTRIBUTE_UNUSED;
1374 struct mips_constant_info c;
1376 return ((GET_CODE (op) == CONST_INT && SMALL_INT (op))
1377 || mips_classify_constant (&c, op) == CONSTANT_RELOC);
1381 /* Return truth value of whether OP can be used as an operands
1382 where a 16 bit integer is needed */
1385 arith_operand (op, mode)
1387 enum machine_mode mode;
1389 return const_arith_operand (op, mode) || register_operand (op, mode);
1392 /* Return truth value of whether OP can be used as an operand in a two
1393 address arithmetic insn (such as set 123456,%o4) of mode MODE. */
1396 arith32_operand (op, mode)
1398 enum machine_mode mode;
1400 if (GET_CODE (op) == CONST_INT)
1403 return register_operand (op, mode);
1406 /* Return truth value of whether OP is an integer which fits in 16 bits. */
1409 small_int (op, mode)
1411 enum machine_mode mode ATTRIBUTE_UNUSED;
1413 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
1416 /* Return truth value of whether OP is a 32 bit integer which is too big to
1417 be loaded with one instruction. */
1420 large_int (op, mode)
1422 enum machine_mode mode ATTRIBUTE_UNUSED;
1424 HOST_WIDE_INT value;
1426 if (GET_CODE (op) != CONST_INT)
1429 value = INTVAL (op);
1431 /* ior reg,$r0,value */
1432 if ((value & ~ ((HOST_WIDE_INT) 0x0000ffff)) == 0)
1435 /* subu reg,$r0,value */
1436 if (((unsigned HOST_WIDE_INT) (value + 32768)) <= 32767)
1439 /* lui reg,value>>16 */
1440 if ((value & 0x0000ffff) == 0)
1446 /* Return truth value of whether OP is a register or the constant 0.
1447 In mips16 mode, we only accept a register, since the mips16 does
1451 reg_or_0_operand (op, mode)
1453 enum machine_mode mode;
1455 switch (GET_CODE (op))
1460 return INTVAL (op) == 0;
1465 return op == CONST0_RTX (mode);
1468 return register_operand (op, mode);
1472 /* Return truth value of whether OP is a register or the constant 0,
1473 even in mips16 mode. */
1476 true_reg_or_0_operand (op, mode)
1478 enum machine_mode mode;
1480 switch (GET_CODE (op))
1483 return INTVAL (op) == 0;
1486 return op == CONST0_RTX (mode);
1489 return register_operand (op, mode);
1493 /* Accept the floating point constant 1 in the appropriate mode. */
1496 const_float_1_operand (op, mode)
1498 enum machine_mode mode;
1502 if (GET_CODE (op) != CONST_DOUBLE
1503 || mode != GET_MODE (op)
1504 || (mode != DFmode && mode != SFmode))
1507 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1509 return REAL_VALUES_EQUAL (d, dconst1);
1512 /* Return true if OP is either the HI or LO register. */
1515 hilo_operand (op, mode)
1517 enum machine_mode mode;
1519 return ((mode == VOIDmode || mode == GET_MODE (op))
1521 && (REGNO (op) == HI_REGNUM || REGNO (op) == LO_REGNUM));
1524 /* Return nonzero if the code of this rtx pattern is EQ or NE. */
1527 equality_op (op, mode)
1529 enum machine_mode mode;
1531 if (mode != GET_MODE (op))
1534 return GET_CODE (op) == EQ || GET_CODE (op) == NE;
1537 /* Return nonzero if the code is a relational operations (EQ, LE, etc.) */
1542 enum machine_mode mode;
1544 if (mode != GET_MODE (op))
1547 return GET_RTX_CLASS (GET_CODE (op)) == '<';
1550 /* Return nonzero if the code is a relational operation suitable for a
1551 conditional trap instructuion (only EQ, NE, LT, LTU, GE, GEU).
1552 We need this in the insn that expands `trap_if' in order to prevent
1553 combine from erroneously altering the condition. */
1556 trap_cmp_op (op, mode)
1558 enum machine_mode mode;
1560 if (mode != GET_MODE (op))
1563 switch (GET_CODE (op))
1578 /* Return nonzero if the operand is either the PC or a label_ref. */
1581 pc_or_label_operand (op, mode)
1583 enum machine_mode mode ATTRIBUTE_UNUSED;
1588 if (GET_CODE (op) == LABEL_REF)
1594 /* Test for a valid call address. */
1597 call_insn_operand (op, mode)
1599 enum machine_mode mode;
1601 struct mips_constant_info c;
1603 if (mips_classify_constant (&c, op) == CONSTANT_SYMBOLIC)
1604 switch (mips_classify_symbol (c.symbol))
1606 case SYMBOL_GENERAL:
1607 /* If -mlong-calls, force all calls to use register addressing. */
1608 return !TARGET_LONG_CALLS;
1610 case SYMBOL_GOT_GLOBAL:
1611 /* Without explicit relocs, there is no special syntax for
1612 loading the address of a call destination into a register.
1613 Using "la $25,foo; jal $25" would prevent the lazy binding
1614 of "foo", so keep the address of global symbols with the
1616 return c.offset == 0 && !TARGET_EXPLICIT_RELOCS;
1621 return register_operand (op, mode);
1625 /* Return nonzero if OP is valid as a source operand for a move
1629 move_operand (op, mode)
1631 enum machine_mode mode;
1633 struct mips_constant_info c;
1635 if (GET_CODE (op) == HIGH && TARGET_ABICALLS)
1637 if (GET_CODE (op) == CONST_INT && !TARGET_MIPS16)
1638 return (SMALL_INT (op) || SMALL_INT_UNSIGNED (op) || LUI_INT (op));
1639 if (mips_classify_constant (&c, op) == CONSTANT_SYMBOLIC)
1640 return mips_symbolic_address_p (c.symbol, c.offset, word_mode, 1);
1641 return general_operand (op, mode);
1645 /* Accept any operand that can appear in a mips16 constant table
1646 instruction. We can't use any of the standard operand functions
1647 because for these instructions we accept values that are not
1648 accepted by LEGITIMATE_CONSTANT, such as arbitrary SYMBOL_REFs. */
1651 consttable_operand (op, mode)
1653 enum machine_mode mode ATTRIBUTE_UNUSED;
1655 return CONSTANT_P (op);
1658 /* Coprocessor operand; return true if rtx is a REG and refers to a
1662 coprocessor_operand (op, mode)
1664 enum machine_mode mode ATTRIBUTE_UNUSED;
1666 return (GET_CODE (op) == REG
1667 && COP0_REG_FIRST <= REGNO (op)
1668 && REGNO (op) <= COP3_REG_LAST);
1672 coprocessor2_operand (op, mode)
1674 enum machine_mode mode ATTRIBUTE_UNUSED;
1676 return (GET_CODE (op) == REG
1677 && COP2_REG_FIRST <= REGNO (op)
1678 && REGNO (op) <= COP2_REG_LAST);
1681 /* Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
1682 possibly with an offset. */
1685 symbolic_operand (op, mode)
1687 enum machine_mode mode ATTRIBUTE_UNUSED;
1689 struct mips_constant_info c;
1691 return mips_classify_constant (&c, op) == CONSTANT_SYMBOLIC;
1695 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
1696 returns a nonzero value if X is a legitimate address for a memory
1697 operand of the indicated MODE. STRICT is nonzero if this function
1698 is called during reload. */
1701 mips_legitimate_address_p (mode, x, strict)
1702 enum machine_mode mode;
1706 struct mips_address_info addr;
1708 return mips_classify_address (&addr, x, mode, strict, 0) != ADDRESS_INVALID;
1712 /* Return an rtx that represents the effect of applying relocation
1713 RELOC to symbolic address ADDR. */
1716 mips_reloc (addr, reloc)
1720 struct mips_constant_info c;
1723 if (mips_classify_constant (&c, addr) != CONSTANT_SYMBOLIC)
1726 x = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, c.symbol), reloc);
1727 return plus_constant (gen_rtx_CONST (VOIDmode, x), c.offset);
1731 /* Likewise, but shift the result left 16 bits. The expression can be
1732 used as the right hand side of an LUISI or LUIDI pattern. */
1735 mips_lui_reloc (addr, reloc)
1739 return gen_rtx_UNSPEC (Pmode,
1740 gen_rtvec (1, mips_reloc (addr, reloc)),
1744 /* Copy VALUE to a register and return that register. Use DEST as the
1745 register if non-null, otherwise create a new one.
1747 VALUE must be valid on the right hand side of a simple SET pattern.
1748 The operation happens in Pmode. */
1751 mips_force_temporary (dest, value)
1755 return force_reg (Pmode, value);
1758 if (!rtx_equal_p (dest, value))
1759 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (dest), value));
1765 /* Return a legitimate address for REG + OFFSET. This function will
1766 create a temporary register if OFFSET is not a SMALL_OPERAND. */
1769 mips_add_offset (reg, offset)
1771 HOST_WIDE_INT offset;
1773 if (!SMALL_OPERAND (offset))
1774 reg = expand_simple_binop (GET_MODE (reg), PLUS,
1775 GEN_INT (CONST_HIGH_PART (offset)),
1776 reg, NULL, 0, OPTAB_WIDEN);
1778 return plus_constant (reg, CONST_LOW_PART (offset));
1782 /* Return the GOT entry whose address is given by %RELOC(ADDR)(BASE).
1783 BASE is a base register (such as $gp), ADDR is addresses being
1784 sought and RELOC is the relocation that should be used. */
1787 mips_load_got (base, addr, reloc)
1793 mem = gen_rtx_MEM (ptr_mode,
1794 gen_rtx_PLUS (Pmode, base, mips_reloc (addr, reloc)));
1795 set_mem_alias_set (mem, mips_got_alias_set);
1797 /* If we allow a function's address to be lazily bound, its entry
1798 may change after the first call. Other entries are constant. */
1799 if (reloc != RELOC_CALL16 && reloc != RELOC_CALL_LO)
1800 RTX_UNCHANGING_P (mem) = 1;
1802 if (Pmode != ptr_mode)
1803 mem = gen_rtx_SIGN_EXTEND (Pmode, mem);
1809 /* Obtain the address of ADDR from the GOT using relocation RELOC.
1810 The returned address may be used on the right hand side of a SET. */
1813 mips_load_got16 (addr, reloc)
1817 return mips_load_got (pic_offset_table_rtx, addr, reloc);
1821 /* Like mips_load_got16, but for 32-bit offsets. HIGH_RELOC is the
1822 relocation that gives the high 16 bits of the offset and LOW_RELOC is
1823 the relocation that gives the low 16 bits. TEMP is a Pmode register
1824 to use a temporary, or null if new registers can be created at will. */
1827 mips_load_got32 (temp, addr, high_reloc, low_reloc)
1829 int high_reloc, low_reloc;
1833 x = mips_force_temporary (temp, mips_lui_reloc (addr, high_reloc));
1834 x = mips_force_temporary (temp,
1835 gen_rtx_PLUS (Pmode, pic_offset_table_rtx, x));
1836 return mips_load_got (x, addr, low_reloc);
1840 /* Copy the high part of ADDR into a register and return the register.
1841 Use DEST as the register if non-null. */
1844 mips_emit_high (dest, addr)
1849 high = gen_rtx_HIGH (Pmode, addr);
1850 if (TARGET_ABICALLS)
1852 x = mips_load_got16 (copy_rtx (addr), RELOC_GOT_PAGE);
1853 x = mips_force_temporary (dest, x);
1854 set_unique_reg_note (get_last_insn (), REG_EQUAL, high);
1857 x = mips_force_temporary (dest, high);
1862 /* See if *XLOC is a symbolic constant that can be reduced in some way.
1863 If it is, set *XLOC to the reduced expression and return true.
1864 The new expression will be both a legitimate address and a legitimate
1865 source operand for a mips.md SET pattern. If OFFSETABLE_P, the
1866 address will be offsetable.
1868 DEST is a register to use a temporary, or null if new registers
1869 can be created at will. */
1872 mips_legitimize_symbol (dest, xloc, offsetable_p)
1876 struct mips_constant_info c;
1877 enum mips_symbol_type symbol_type;
1880 if (mips_classify_constant (&c, *xloc) != CONSTANT_SYMBOLIC)
1883 symbol_type = mips_classify_symbol (c.symbol);
1885 /* Convert a mips16 reference to the small data section into
1886 an address of the form:
1888 (plus BASE (const (plus (unspec [SYMBOL] UNSPEC_GPREL) OFFSET)))
1890 BASE is the pseudo created by mips16_gp_pseudo_reg.
1891 The (const ...) may include an offset. */
1893 && symbol_type == SYMBOL_SMALL_DATA
1896 *xloc = gen_rtx_PLUS (Pmode, mips16_gp_pseudo_reg (),
1897 mips_reloc (*xloc, RELOC_GPREL16));
1901 /* Likewise for normal-mode code. In this case we can use $gp
1902 as a base register. */
1904 && TARGET_EXPLICIT_RELOCS
1905 && symbol_type == SYMBOL_SMALL_DATA)
1907 *xloc = gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
1908 mips_reloc (*xloc, RELOC_GPREL16));
1912 /* If a non-offsetable address is OK, convert general symbols into
1913 a HIGH/LO_SUM pair. */
1914 if (!offsetable_p && mips_splittable_symbol_p (symbol_type))
1916 x = mips_emit_high (dest, *xloc);
1917 *xloc = gen_rtx_LO_SUM (Pmode, x, copy_rtx (*xloc));
1921 /* If generating PIC, and ADDR is a global symbol with an offset,
1922 load the symbol into a register and apply the offset separately.
1923 We need a temporary when adding large offsets. */
1924 if (symbol_type == SYMBOL_GOT_GLOBAL
1926 && (SMALL_OPERAND (c.offset) || dest == 0))
1928 x = (dest == 0 ? gen_reg_rtx (Pmode) : dest);
1929 emit_move_insn (copy_rtx (x), c.symbol);
1930 *xloc = mips_add_offset (x, c.offset);
1938 /* This function is used to implement LEGITIMIZE_ADDRESS. If *XLOC can
1939 be legitimized in a way that the generic machinery might not expect,
1940 put the new address in *XLOC and return true. MODE is the mode of
1941 the memory being accessed. */
1944 mips_legitimize_address (xloc, mode)
1946 enum machine_mode mode;
1948 if (mips_legitimize_symbol (0, xloc, !SINGLE_WORD_MODE_P (mode)))
1951 if (GET_CODE (*xloc) == PLUS && GET_CODE (XEXP (*xloc, 1)) == CONST_INT)
1953 /* Handle REG + CONSTANT using mips_add_offset. */
1956 reg = XEXP (*xloc, 0);
1957 if (!mips_valid_base_register_p (reg, mode, 0))
1958 reg = copy_to_mode_reg (Pmode, reg);
1959 *xloc = mips_add_offset (reg, INTVAL (XEXP (*xloc, 1)));
1967 /* Subroutine of mips_build_integer (with the same interface).
1968 Assume that the final action in the sequence should be a left shift. */
1971 mips_build_shift (codes, value)
1972 struct mips_integer_op *codes;
1973 HOST_WIDE_INT value;
1975 unsigned int i, shift;
1977 /* Shift VALUE right until its lowest bit is set. Shift arithmetically
1978 since signed numbers are easier to load than unsigned ones. */
1980 while ((value & 1) == 0)
1981 value /= 2, shift++;
1983 i = mips_build_integer (codes, value);
1984 codes[i].code = ASHIFT;
1985 codes[i].value = shift;
1990 /* As for mips_build_shift, but assume that the final action will be
1991 an IOR or PLUS operation. */
1994 mips_build_lower (codes, value)
1995 struct mips_integer_op *codes;
1996 unsigned HOST_WIDE_INT value;
1998 unsigned HOST_WIDE_INT high;
2001 high = value & ~(unsigned HOST_WIDE_INT) 0xffff;
2002 if (!LUI_OPERAND (high) && (value & 0x18000) == 0x18000)
2004 /* The constant is too complex to load with a simple lui/ori pair
2005 so our goal is to clear as many trailing zeros as possible.
2006 In this case, we know bit 16 is set and that the low 16 bits
2007 form a negative number. If we subtract that number from VALUE,
2008 we will clear at least the lowest 17 bits, maybe more. */
2009 i = mips_build_integer (codes, CONST_HIGH_PART (value));
2010 codes[i].code = PLUS;
2011 codes[i].value = CONST_LOW_PART (value);
2015 i = mips_build_integer (codes, high);
2016 codes[i].code = IOR;
2017 codes[i].value = value & 0xffff;
2023 /* Fill CODES with a sequence of rtl operations to load VALUE.
2024 Return the number of operations needed. */
2027 mips_build_integer (codes, value)
2028 struct mips_integer_op *codes;
2029 unsigned HOST_WIDE_INT value;
2031 if (SMALL_OPERAND (value)
2032 || SMALL_OPERAND_UNSIGNED (value)
2033 || LUI_OPERAND (value))
2035 /* The value can be loaded with a single instruction. */
2036 codes[0].code = NIL;
2037 codes[0].value = value;
2040 else if ((value & 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value)))
2042 /* Either the constant is a simple LUI/ORI combination or its
2043 lowest bit is set. We don't want to shift in this case. */
2044 return mips_build_lower (codes, value);
2046 else if ((value & 0xffff) == 0)
2048 /* The constant will need at least three actions. The lowest
2049 16 bits are clear, so the final action will be a shift. */
2050 return mips_build_shift (codes, value);
2054 /* The final action could be a shift, add or inclusive OR.
2055 Rather than use a complex condition to select the best
2056 approach, try both mips_build_shift and mips_build_lower
2057 and pick the one that gives the shortest sequence.
2058 Note that this case is only used once per constant. */
2059 struct mips_integer_op alt_codes[MIPS_MAX_INTEGER_OPS];
2060 unsigned int cost, alt_cost;
2062 cost = mips_build_shift (codes, value);
2063 alt_cost = mips_build_lower (alt_codes, value);
2064 if (alt_cost < cost)
2066 memcpy (codes, alt_codes, alt_cost * sizeof (codes[0]));
2074 /* Move VALUE into register DEST. */
2077 mips_move_integer (dest, value)
2079 unsigned HOST_WIDE_INT value;
2081 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
2082 enum machine_mode mode;
2083 unsigned int i, cost;
2086 mode = GET_MODE (dest);
2087 cost = mips_build_integer (codes, value);
2089 /* Apply each binary operation to X. Invariant: X is a legitimate
2090 source operand for a SET pattern. */
2091 x = GEN_INT (codes[0].value);
2092 for (i = 1; i < cost; i++)
2095 emit_move_insn (dest, x), x = dest;
2097 x = force_reg (mode, x);
2098 x = gen_rtx_fmt_ee (codes[i].code, mode, x, GEN_INT (codes[i].value));
2101 emit_insn (gen_rtx_SET (VOIDmode, dest, x));
2105 /* Subroutine of mips_legitimize_move. Move constant SRC into register
2106 DEST given that SRC satisfies immediate_operand but doesn't satisfy
2110 mips_legitimize_const_move (mode, dest, src)
2111 enum machine_mode mode;
2116 temp = no_new_pseudos ? dest : 0;
2118 /* If generating PIC, the high part of an address is loaded from the GOT. */
2119 if (GET_CODE (src) == HIGH)
2121 mips_emit_high (dest, XEXP (src, 0));
2125 if (GET_CODE (src) == CONST_INT && !TARGET_MIPS16)
2127 mips_move_integer (dest, INTVAL (src));
2131 /* Fetch global symbols from the GOT. */
2132 if (TARGET_EXPLICIT_RELOCS
2133 && GET_CODE (src) == SYMBOL_REF
2134 && mips_classify_symbol (src) == SYMBOL_GOT_GLOBAL)
2137 src = mips_load_got16 (src, RELOC_GOT_DISP);
2139 src = mips_load_got32 (temp, src, RELOC_GOT_HI, RELOC_GOT_LO);
2140 emit_insn (gen_rtx_SET (VOIDmode, dest, src));
2144 /* Try handling the source operand as a symbolic address. */
2145 if (mips_legitimize_symbol (temp, &src, false))
2147 emit_insn (gen_rtx_SET (VOIDmode, dest, src));
2151 src = force_const_mem (mode, src);
2153 /* When using explicit relocs, constant pool references are sometimes
2154 not legitimate addresses. mips_legitimize_symbol must be able to
2155 deal with all such cases. */
2156 if (GET_CODE (src) == MEM && !memory_operand (src, VOIDmode))
2158 src = copy_rtx (src);
2159 if (!mips_legitimize_symbol (temp, &XEXP (src, 0), false))
2162 emit_move_insn (dest, src);
2166 /* If (set DEST SRC) is not a valid instruction, emit an equivalent
2167 sequence that is valid. */
2170 mips_legitimize_move (mode, dest, src)
2171 enum machine_mode mode;
2174 if (!register_operand (dest, mode) && !reg_or_0_operand (src, mode))
2176 emit_move_insn (dest, force_reg (mode, src));
2180 /* The source of an SImode move must be a move_operand. Likewise
2181 DImode moves on 64-bit targets. We need to deal with constants
2182 that would be legitimate immediate_operands but not legitimate
2184 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
2186 && !move_operand (src, mode))
2188 mips_legitimize_const_move (mode, dest, src);
2189 set_unique_reg_note (get_last_insn (), REG_EQUAL, copy_rtx (src));
2196 /* Convert GOT and GP-relative accesses back into their original form.
2197 Used by bothh TARGET_DELEGITIMIZE_ADDRESS and FIND_BASE_TERM. */
2200 mips_delegitimize_address (x)
2203 struct mips_constant_info c;
2205 if (GET_CODE (x) == MEM
2206 && GET_CODE (XEXP (x, 0)) == PLUS
2207 && mips_classify_constant (&c, XEXP (XEXP (x, 0), 1)) == CONSTANT_RELOC
2208 && mips_classify_symbol (XVECEXP (c.symbol, 0, 0)) == SYMBOL_GOT_GLOBAL)
2209 return XVECEXP (c.symbol, 0, 0);
2211 if (GET_CODE (x) == PLUS
2212 && (XEXP (x, 0) == pic_offset_table_rtx
2213 || XEXP (x, 0) == cfun->machine->mips16_gp_pseudo_rtx)
2214 && mips_classify_constant (&c, XEXP (x, 1)) == CONSTANT_RELOC
2215 && mips_classify_symbol (XVECEXP (c.symbol, 0, 0)) == SYMBOL_SMALL_DATA)
2216 return plus_constant (XVECEXP (c.symbol, 0, 0), c.offset);
2221 /* We need a lot of little routines to check constant values on the
2222 mips16. These are used to figure out how long the instruction will
2223 be. It would be much better to do this using constraints, but
2224 there aren't nearly enough letters available. */
2227 m16_check_op (op, low, high, mask)
2233 return (GET_CODE (op) == CONST_INT
2234 && INTVAL (op) >= low
2235 && INTVAL (op) <= high
2236 && (INTVAL (op) & mask) == 0);
2240 m16_uimm3_b (op, mode)
2242 enum machine_mode mode ATTRIBUTE_UNUSED;
2244 return m16_check_op (op, 0x1, 0x8, 0);
2248 m16_simm4_1 (op, mode)
2250 enum machine_mode mode ATTRIBUTE_UNUSED;
2252 return m16_check_op (op, - 0x8, 0x7, 0);
2256 m16_nsimm4_1 (op, mode)
2258 enum machine_mode mode ATTRIBUTE_UNUSED;
2260 return m16_check_op (op, - 0x7, 0x8, 0);
2264 m16_simm5_1 (op, mode)
2266 enum machine_mode mode ATTRIBUTE_UNUSED;
2268 return m16_check_op (op, - 0x10, 0xf, 0);
2272 m16_nsimm5_1 (op, mode)
2274 enum machine_mode mode ATTRIBUTE_UNUSED;
2276 return m16_check_op (op, - 0xf, 0x10, 0);
2280 m16_uimm5_4 (op, mode)
2282 enum machine_mode mode ATTRIBUTE_UNUSED;
2284 return m16_check_op (op, (- 0x10) << 2, 0xf << 2, 3);
2288 m16_nuimm5_4 (op, mode)
2290 enum machine_mode mode ATTRIBUTE_UNUSED;
2292 return m16_check_op (op, (- 0xf) << 2, 0x10 << 2, 3);
2296 m16_simm8_1 (op, mode)
2298 enum machine_mode mode ATTRIBUTE_UNUSED;
2300 return m16_check_op (op, - 0x80, 0x7f, 0);
2304 m16_nsimm8_1 (op, mode)
2306 enum machine_mode mode ATTRIBUTE_UNUSED;
2308 return m16_check_op (op, - 0x7f, 0x80, 0);
2312 m16_uimm8_1 (op, mode)
2314 enum machine_mode mode ATTRIBUTE_UNUSED;
2316 return m16_check_op (op, 0x0, 0xff, 0);
2320 m16_nuimm8_1 (op, mode)
2322 enum machine_mode mode ATTRIBUTE_UNUSED;
2324 return m16_check_op (op, - 0xff, 0x0, 0);
2328 m16_uimm8_m1_1 (op, mode)
2330 enum machine_mode mode ATTRIBUTE_UNUSED;
2332 return m16_check_op (op, - 0x1, 0xfe, 0);
2336 m16_uimm8_4 (op, mode)
2338 enum machine_mode mode ATTRIBUTE_UNUSED;
2340 return m16_check_op (op, 0x0, 0xff << 2, 3);
2344 m16_nuimm8_4 (op, mode)
2346 enum machine_mode mode ATTRIBUTE_UNUSED;
2348 return m16_check_op (op, (- 0xff) << 2, 0x0, 3);
2352 m16_simm8_8 (op, mode)
2354 enum machine_mode mode ATTRIBUTE_UNUSED;
2356 return m16_check_op (op, (- 0x80) << 3, 0x7f << 3, 7);
2360 m16_nsimm8_8 (op, mode)
2362 enum machine_mode mode ATTRIBUTE_UNUSED;
2364 return m16_check_op (op, (- 0x7f) << 3, 0x80 << 3, 7);
2367 /* References to the string table on the mips16 only use a small
2368 offset if the function is small. We can't check for LABEL_REF here,
2369 because the offset is always large if the label is before the
2370 referencing instruction. */
2373 m16_usym8_4 (op, mode)
2375 enum machine_mode mode ATTRIBUTE_UNUSED;
2377 if (GET_CODE (op) == SYMBOL_REF
2378 && SYMBOL_REF_FLAG (op)
2379 && cfun->machine->insns_len > 0
2380 && XSTR (op, 0)[0] == '*'
2381 && strncmp (XSTR (op, 0) + 1, LOCAL_LABEL_PREFIX,
2382 sizeof LOCAL_LABEL_PREFIX - 1) == 0
2383 && (cfun->machine->insns_len + get_pool_size () + mips_string_length
2386 struct string_constant *l;
2388 /* Make sure this symbol is on thelist of string constants to be
2389 output for this function. It is possible that it has already
2390 been output, in which case this requires a large offset. */
2391 for (l = string_constants; l != NULL; l = l->next)
2392 if (strcmp (l->label, XSTR (op, 0)) == 0)
2400 m16_usym5_4 (op, mode)
2402 enum machine_mode mode ATTRIBUTE_UNUSED;
2404 if (GET_CODE (op) == SYMBOL_REF
2405 && SYMBOL_REF_FLAG (op)
2406 && cfun->machine->insns_len > 0
2407 && XSTR (op, 0)[0] == '*'
2408 && strncmp (XSTR (op, 0) + 1, LOCAL_LABEL_PREFIX,
2409 sizeof LOCAL_LABEL_PREFIX - 1) == 0
2410 && (cfun->machine->insns_len + get_pool_size () + mips_string_length
2413 struct string_constant *l;
2415 /* Make sure this symbol is on thelist of string constants to be
2416 output for this function. It is possible that it has already
2417 been output, in which case this requires a large offset. */
2418 for (l = string_constants; l != NULL; l = l->next)
2419 if (strcmp (l->label, XSTR (op, 0)) == 0)
2427 mips_rtx_costs (x, code, outer_code, total)
2429 int code, outer_code;
2432 enum machine_mode mode = GET_MODE (x);
2439 /* Always return 0, since we don't have different sized
2440 instructions, hence different costs according to Richard
2446 /* A number between 1 and 8 inclusive is efficient for a shift.
2447 Otherwise, we will need an extended instruction. */
2448 if ((outer_code) == ASHIFT || (outer_code) == ASHIFTRT
2449 || (outer_code) == LSHIFTRT)
2451 if (INTVAL (x) >= 1 && INTVAL (x) <= 8)
2454 *total = COSTS_N_INSNS (1);
2457 /* We can use cmpi for an xor with an unsigned 16 bit value. */
2459 if ((outer_code) == XOR
2460 && INTVAL (x) >= 0 && INTVAL (x) < 0x10000)
2466 /* We may be able to use slt or sltu for a comparison with a
2467 signed 16 bit value. (The boundary conditions aren't quite
2468 right, but this is just a heuristic anyhow.) */
2469 if (((outer_code) == LT || (outer_code) == LE
2470 || (outer_code) == GE || (outer_code) == GT
2471 || (outer_code) == LTU || (outer_code) == LEU
2472 || (outer_code) == GEU || (outer_code) == GTU)
2473 && INTVAL (x) >= -0x8000 && INTVAL (x) < 0x8000)
2479 /* Equality comparisons with 0 are cheap. */
2480 if (((outer_code) == EQ || (outer_code) == NE)
2487 /* Otherwise fall through to the handling below. */
2493 if (((outer_code) == PLUS || (outer_code) == MINUS)
2494 && const_arith_operand (x, VOIDmode))
2501 int n = mips_const_insns (x);
2502 return (n == 0 ? CONSTANT_POOL_COST : COSTS_N_INSNS (n));
2507 /* If the address is legitimate, return the number of
2508 instructions it needs, otherwise use the default handling. */
2509 int n = mips_address_insns (XEXP (x, 0), GET_MODE (x));
2512 *total = COSTS_N_INSNS (1 + n);
2519 *total = COSTS_N_INSNS (6);
2523 *total = COSTS_N_INSNS ((mode == DImode && !TARGET_64BIT) ? 2 : 1);
2529 if (mode == DImode && !TARGET_64BIT)
2531 *total = COSTS_N_INSNS (2);
2539 if (mode == DImode && !TARGET_64BIT)
2541 *total = COSTS_N_INSNS ((GET_CODE (XEXP (x, 1)) == CONST_INT)
2548 if (mode == SFmode || mode == DFmode)
2549 *total = COSTS_N_INSNS (1);
2551 *total = COSTS_N_INSNS (4);
2555 *total = COSTS_N_INSNS (1);
2560 if (mode == SFmode || mode == DFmode)
2562 if (TUNE_MIPS3000 || TUNE_MIPS3900)
2563 *total = COSTS_N_INSNS (2);
2564 else if (TUNE_MIPS6000)
2565 *total = COSTS_N_INSNS (3);
2567 *total = COSTS_N_INSNS (6);
2570 if (mode == DImode && !TARGET_64BIT)
2572 *total = COSTS_N_INSNS (4);
2578 if (mode == DImode && !TARGET_64BIT)
2591 *total = COSTS_N_INSNS (4);
2592 else if (TUNE_MIPS6000
2595 *total = COSTS_N_INSNS (5);
2597 *total = COSTS_N_INSNS (7);
2606 *total = COSTS_N_INSNS (5);
2607 else if (TUNE_MIPS6000
2610 *total = COSTS_N_INSNS (6);
2612 *total = COSTS_N_INSNS (8);
2617 *total = COSTS_N_INSNS (12);
2618 else if (TUNE_MIPS3900)
2619 *total = COSTS_N_INSNS (2);
2620 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2621 *total = COSTS_N_INSNS ((mode == DImode) ? 4 : 3);
2622 else if (TUNE_MIPS6000)
2623 *total = COSTS_N_INSNS (17);
2624 else if (TUNE_MIPS5000)
2625 *total = COSTS_N_INSNS (5);
2627 *total = COSTS_N_INSNS (10);
2636 *total = COSTS_N_INSNS (12);
2637 else if (TUNE_MIPS6000)
2638 *total = COSTS_N_INSNS (15);
2639 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2640 *total = COSTS_N_INSNS (30);
2642 *total = COSTS_N_INSNS (23);
2650 *total = COSTS_N_INSNS (19);
2651 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2652 *total = COSTS_N_INSNS (59);
2653 else if (TUNE_MIPS6000)
2654 *total = COSTS_N_INSNS (16);
2656 *total = COSTS_N_INSNS (36);
2665 *total = COSTS_N_INSNS (35);
2666 else if (TUNE_MIPS6000)
2667 *total = COSTS_N_INSNS (38);
2668 else if (TUNE_MIPS5000)
2669 *total = COSTS_N_INSNS (36);
2670 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2671 *total = COSTS_N_INSNS ((mode == SImode) ? 42 : 74);
2673 *total = COSTS_N_INSNS (69);
2677 /* A sign extend from SImode to DImode in 64 bit mode is often
2678 zero instructions, because the result can often be used
2679 directly by another instruction; we'll call it one. */
2680 if (TARGET_64BIT && mode == DImode
2681 && GET_MODE (XEXP (x, 0)) == SImode)
2682 *total = COSTS_N_INSNS (1);
2684 *total = COSTS_N_INSNS (2);
2688 if (TARGET_64BIT && mode == DImode
2689 && GET_MODE (XEXP (x, 0)) == SImode)
2690 *total = COSTS_N_INSNS (2);
2692 *total = COSTS_N_INSNS (1);
2700 /* Provide the costs of an addressing mode that contains ADDR.
2701 If ADDR is not a valid address, its cost is irrelevant. */
2704 mips_address_cost (addr)
2707 return mips_address_insns (addr, SImode);
2710 /* Return a pseudo that points to the address of the current function.
2711 The first time it is called for a function, an initializer for the
2712 pseudo is emitted in the beginning of the function. */
2715 embedded_pic_fnaddr_reg ()
2717 if (cfun->machine->embedded_pic_fnaddr_rtx == NULL)
2721 cfun->machine->embedded_pic_fnaddr_rtx = gen_reg_rtx (Pmode);
2723 /* Output code at function start to initialize the pseudo-reg. */
2724 /* ??? We used to do this in FINALIZE_PIC, but that does not work for
2725 inline functions, because it is called after RTL for the function
2726 has been copied. The pseudo-reg in embedded_pic_fnaddr_rtx however
2727 does not get copied, and ends up not matching the rest of the RTL.
2728 This solution works, but means that we get unnecessary code to
2729 initialize this value every time a function is inlined into another
2732 emit_insn (gen_get_fnaddr (cfun->machine->embedded_pic_fnaddr_rtx,
2733 XEXP (DECL_RTL (current_function_decl), 0)));
2736 push_topmost_sequence ();
2737 emit_insn_after (seq, get_insns ());
2738 pop_topmost_sequence ();
2741 return cfun->machine->embedded_pic_fnaddr_rtx;
2744 /* Return RTL for the offset from the current function to the argument.
2745 X is the symbol whose offset from the current function we want. */
2748 embedded_pic_offset (x)
2751 /* Make sure it is emitted. */
2752 embedded_pic_fnaddr_reg ();
2755 gen_rtx_CONST (Pmode,
2756 gen_rtx_MINUS (Pmode, x,
2757 XEXP (DECL_RTL (current_function_decl), 0)));
2760 /* Return one word of double-word value OP, taking into account the fixed
2761 endianness of certain registers. HIGH_P is true to select the high part,
2762 false to select the low part. */
2765 mips_subword (op, high_p)
2770 enum machine_mode mode;
2772 mode = GET_MODE (op);
2773 if (mode == VOIDmode)
2776 if (TARGET_BIG_ENDIAN ? !high_p : high_p)
2777 byte = UNITS_PER_WORD;
2781 if (GET_CODE (op) == REG)
2783 if (FP_REG_P (REGNO (op)))
2784 return gen_rtx_REG (word_mode, high_p ? REGNO (op) + 1 : REGNO (op));
2785 if (REGNO (op) == HI_REGNUM)
2786 return gen_rtx_REG (word_mode, high_p ? HI_REGNUM : LO_REGNUM);
2789 if (GET_CODE (op) == MEM)
2790 return adjust_address (op, word_mode, byte);
2792 return simplify_gen_subreg (word_mode, op, mode, byte);
2796 /* Return true if a 64-bit move from SRC to DEST should be split into two. */
2799 mips_split_64bit_move_p (dest, src)
2805 /* FP->FP moves can be done in a single instruction. */
2806 if (FP_REG_RTX_P (src) && FP_REG_RTX_P (dest))
2809 /* Check for floating-point loads and stores. They can be done using
2810 ldc1 and sdc1 on MIPS II and above. */
2813 if (FP_REG_RTX_P (dest) && GET_CODE (src) == MEM)
2815 if (FP_REG_RTX_P (src) && GET_CODE (dest) == MEM)
2822 /* Split a 64-bit move from SRC to DEST assuming that
2823 mips_split_64bit_move_p holds.
2825 Moves into and out of FPRs cause some difficulty here. Such moves
2826 will always be DFmode, since paired FPRs are not allowed to store
2827 DImode values. The most natural representation would be two separate
2828 32-bit moves, such as:
2830 (set (reg:SI $f0) (mem:SI ...))
2831 (set (reg:SI $f1) (mem:SI ...))
2833 However, the second insn is invalid because odd-numbered FPRs are
2834 not allowed to store independent values. Use the patterns load_df_low,
2835 load_df_high and store_df_high instead. */
2838 mips_split_64bit_move (dest, src)
2841 if (FP_REG_RTX_P (dest))
2843 /* Loading an FPR from memory or from GPRs. */
2844 emit_insn (gen_load_df_low (copy_rtx (dest), mips_subword (src, 0)));
2845 emit_insn (gen_load_df_high (dest, mips_subword (src, 1),
2848 else if (FP_REG_RTX_P (src))
2850 /* Storing an FPR into memory or GPRs. */
2851 emit_move_insn (mips_subword (dest, 0), mips_subword (src, 0));
2852 emit_insn (gen_store_df_high (mips_subword (dest, 1), src));
2856 /* The operation can be split into two normal moves. Decide in
2857 which order to do them. */
2860 low_dest = mips_subword (dest, 0);
2861 if (GET_CODE (low_dest) == REG
2862 && reg_overlap_mentioned_p (low_dest, src))
2864 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2865 emit_move_insn (low_dest, mips_subword (src, 0));
2869 emit_move_insn (low_dest, mips_subword (src, 0));
2870 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2875 /* Return the appropriate instructions to move SRC into DEST. Assume
2876 that SRC is operand 1 and DEST is operand 0. */
2879 mips_output_move (dest, src)
2882 enum rtx_code dest_code, src_code;
2883 struct mips_constant_info c;
2886 dest_code = GET_CODE (dest);
2887 src_code = GET_CODE (src);
2888 dbl_p = (GET_MODE_SIZE (GET_MODE (dest)) == 8);
2890 if (dbl_p && mips_split_64bit_move_p (dest, src))
2893 if ((src_code == REG && GP_REG_P (REGNO (src)))
2894 || (!TARGET_MIPS16 && src == CONST0_RTX (GET_MODE (dest))))
2896 if (dest_code == REG)
2898 if (GP_REG_P (REGNO (dest)))
2899 return "or\t%0,%z1,$0";
2901 if (MD_REG_P (REGNO (dest)))
2904 if (FP_REG_P (REGNO (dest)))
2905 return (dbl_p ? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0");
2907 if (ALL_COP_REG_P (REGNO (dest)))
2909 static char retval[] = "dmtc_\t%z1,%0";
2911 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2912 return (dbl_p ? retval : retval + 1);
2915 if (dest_code == MEM)
2916 return (dbl_p ? "sd\t%z1,%0" : "sw\t%z1,%0");
2918 if (dest_code == REG && GP_REG_P (REGNO (dest)))
2920 if (src_code == REG)
2922 if (MD_REG_P (REGNO (src)))
2925 if (ST_REG_P (REGNO (src)) && ISA_HAS_8CC)
2926 return "lui\t%0,0x3f80\n\tmovf\t%0,%.,%1";
2928 if (FP_REG_P (REGNO (src)))
2929 return (dbl_p ? "dmfc1\t%0,%1" : "mfc1\t%0,%1");
2931 if (ALL_COP_REG_P (REGNO (src)))
2933 static char retval[] = "dmfc_\t%0,%1";
2935 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
2936 return (dbl_p ? retval : retval + 1);
2940 if (src_code == MEM)
2941 return (dbl_p ? "ld\t%0,%1" : "lw\t%0,%1");
2943 if (src_code == CONST_INT)
2945 /* Don't use the X format, because that will give out of
2946 range numbers for 64 bit hosts and 32 bit targets. */
2948 return "li\t%0,%1\t\t\t# %X1";
2950 if (INTVAL (src) >= 0 && INTVAL (src) <= 0xffff)
2953 if (INTVAL (src) < 0 && INTVAL (src) >= -0xffff)
2954 return "li\t%0,%n1\n\tneg\t%0";
2957 if (src_code == HIGH)
2958 return "lui\t%0,%h1";
2960 switch (mips_classify_constant (&c, src))
2966 return "or\t%0,%1,$0";
2968 case CONSTANT_RELOC:
2969 return (TARGET_MIPS16 ? "li\t%0,0\n\taddiu\t%0,%1" : "li\t%0,%1");
2971 case CONSTANT_SYMBOLIC:
2972 return (dbl_p ? "dla\t%0,%a1" : "la\t%0,%a1");
2975 if (src_code == REG && FP_REG_P (REGNO (src)))
2977 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2978 return (dbl_p ? "mov.d\t%0,%1" : "mov.s\t%0,%1");
2980 if (dest_code == MEM)
2981 return (dbl_p ? "sdc1\t%1,%0" : "swc1\t%1,%0");
2983 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2985 if (src_code == MEM)
2986 return (dbl_p ? "ldc1\t%0,%1" : "lwc1\t%0,%1");
2988 if (dest_code == REG && ALL_COP_REG_P (REGNO (dest)) && src_code == MEM)
2990 static char retval[] = "l_c_\t%0,%1";
2992 retval[1] = (dbl_p ? 'd' : 'w');
2993 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2996 if (dest_code == MEM && src_code == REG && ALL_COP_REG_P (REGNO (src)))
2998 static char retval[] = "s_c_\t%1,%0";
3000 retval[1] = (dbl_p ? 'd' : 'w');
3001 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
3007 /* Return instructions to restore the global pointer from the stack,
3008 assuming TARGET_ABICALLS. Used by exception_receiver to set up
3009 the GP for exception handlers.
3011 OPERANDS is an array of operands whose contents are undefined
3015 mips_restore_gp (operands)
3020 operands[0] = pic_offset_table_rtx;
3021 if (frame_pointer_needed)
3022 loc = hard_frame_pointer_rtx;
3024 loc = stack_pointer_rtx;
3025 loc = plus_constant (loc, cfun->machine->frame.args_size);
3026 operands[1] = gen_rtx_MEM (ptr_mode, loc);
3028 return mips_output_move (operands[0], operands[1]);
3032 /* Make normal rtx_code into something we can index from an array */
3034 static enum internal_test
3035 map_test_to_internal_test (test_code)
3036 enum rtx_code test_code;
3038 enum internal_test test = ITEST_MAX;
3042 case EQ: test = ITEST_EQ; break;
3043 case NE: test = ITEST_NE; break;
3044 case GT: test = ITEST_GT; break;
3045 case GE: test = ITEST_GE; break;
3046 case LT: test = ITEST_LT; break;
3047 case LE: test = ITEST_LE; break;
3048 case GTU: test = ITEST_GTU; break;
3049 case GEU: test = ITEST_GEU; break;
3050 case LTU: test = ITEST_LTU; break;
3051 case LEU: test = ITEST_LEU; break;
3059 /* Generate the code to compare two integer values. The return value is:
3060 (reg:SI xx) The pseudo register the comparison is in
3061 0 No register, generate a simple branch.
3063 ??? This is called with result nonzero by the Scond patterns in
3064 mips.md. These patterns are called with a target in the mode of
3065 the Scond instruction pattern. Since this must be a constant, we
3066 must use SImode. This means that if RESULT is nonzero, it will
3067 always be an SImode register, even if TARGET_64BIT is true. We
3068 cope with this by calling convert_move rather than emit_move_insn.
3069 This will sometimes lead to an unnecessary extension of the result;
3081 gen_int_relational (test_code, result, cmp0, cmp1, p_invert)
3082 enum rtx_code test_code; /* relational test (EQ, etc) */
3083 rtx result; /* result to store comp. or 0 if branch */
3084 rtx cmp0; /* first operand to compare */
3085 rtx cmp1; /* second operand to compare */
3086 int *p_invert; /* NULL or ptr to hold whether branch needs */
3087 /* to reverse its test */
3091 enum rtx_code test_code; /* code to use in instruction (LT vs. LTU) */
3092 int const_low; /* low bound of constant we can accept */
3093 int const_high; /* high bound of constant we can accept */
3094 int const_add; /* constant to add (convert LE -> LT) */
3095 int reverse_regs; /* reverse registers in test */
3096 int invert_const; /* != 0 if invert value if cmp1 is constant */
3097 int invert_reg; /* != 0 if invert value if cmp1 is register */
3098 int unsignedp; /* != 0 for unsigned comparisons. */
3101 static const struct cmp_info info[ (int)ITEST_MAX ] = {
3103 { XOR, 0, 65535, 0, 0, 0, 0, 0 }, /* EQ */
3104 { XOR, 0, 65535, 0, 0, 1, 1, 0 }, /* NE */
3105 { LT, -32769, 32766, 1, 1, 1, 0, 0 }, /* GT */
3106 { LT, -32768, 32767, 0, 0, 1, 1, 0 }, /* GE */
3107 { LT, -32768, 32767, 0, 0, 0, 0, 0 }, /* LT */
3108 { LT, -32769, 32766, 1, 1, 0, 1, 0 }, /* LE */
3109 { LTU, -32769, 32766, 1, 1, 1, 0, 1 }, /* GTU */
3110 { LTU, -32768, 32767, 0, 0, 1, 1, 1 }, /* GEU */
3111 { LTU, -32768, 32767, 0, 0, 0, 0, 1 }, /* LTU */
3112 { LTU, -32769, 32766, 1, 1, 0, 1, 1 }, /* LEU */
3115 enum internal_test test;
3116 enum machine_mode mode;
3117 const struct cmp_info *p_info;
3124 test = map_test_to_internal_test (test_code);
3125 if (test == ITEST_MAX)
3128 p_info = &info[(int) test];
3129 eqne_p = (p_info->test_code == XOR);
3131 mode = GET_MODE (cmp0);
3132 if (mode == VOIDmode)
3133 mode = GET_MODE (cmp1);
3135 /* Eliminate simple branches */
3136 branch_p = (result == 0);
3139 if (GET_CODE (cmp0) == REG || GET_CODE (cmp0) == SUBREG)
3141 /* Comparisons against zero are simple branches */
3142 if (GET_CODE (cmp1) == CONST_INT && INTVAL (cmp1) == 0
3143 && (! TARGET_MIPS16 || eqne_p))
3146 /* Test for beq/bne. */
3147 if (eqne_p && ! TARGET_MIPS16)
3151 /* allocate a pseudo to calculate the value in. */
3152 result = gen_reg_rtx (mode);
3155 /* Make sure we can handle any constants given to us. */
3156 if (GET_CODE (cmp0) == CONST_INT)
3157 cmp0 = force_reg (mode, cmp0);
3159 if (GET_CODE (cmp1) == CONST_INT)
3161 HOST_WIDE_INT value = INTVAL (cmp1);
3163 if (value < p_info->const_low
3164 || value > p_info->const_high
3165 /* ??? Why? And why wasn't the similar code below modified too? */
3167 && HOST_BITS_PER_WIDE_INT < 64
3168 && p_info->const_add != 0
3169 && ((p_info->unsignedp
3170 ? ((unsigned HOST_WIDE_INT) (value + p_info->const_add)
3171 > (unsigned HOST_WIDE_INT) INTVAL (cmp1))
3172 : (value + p_info->const_add) > INTVAL (cmp1))
3173 != (p_info->const_add > 0))))
3174 cmp1 = force_reg (mode, cmp1);
3177 /* See if we need to invert the result. */
3178 invert = (GET_CODE (cmp1) == CONST_INT
3179 ? p_info->invert_const : p_info->invert_reg);
3181 if (p_invert != (int *)0)
3187 /* Comparison to constants, may involve adding 1 to change a LT into LE.
3188 Comparison between two registers, may involve switching operands. */
3189 if (GET_CODE (cmp1) == CONST_INT)
3191 if (p_info->const_add != 0)
3193 HOST_WIDE_INT new = INTVAL (cmp1) + p_info->const_add;
3195 /* If modification of cmp1 caused overflow,
3196 we would get the wrong answer if we follow the usual path;
3197 thus, x > 0xffffffffU would turn into x > 0U. */
3198 if ((p_info->unsignedp
3199 ? (unsigned HOST_WIDE_INT) new >
3200 (unsigned HOST_WIDE_INT) INTVAL (cmp1)
3201 : new > INTVAL (cmp1))
3202 != (p_info->const_add > 0))
3204 /* This test is always true, but if INVERT is true then
3205 the result of the test needs to be inverted so 0 should
3206 be returned instead. */
3207 emit_move_insn (result, invert ? const0_rtx : const_true_rtx);
3211 cmp1 = GEN_INT (new);
3215 else if (p_info->reverse_regs)
3222 if (test == ITEST_NE && GET_CODE (cmp1) == CONST_INT && INTVAL (cmp1) == 0)
3226 reg = (invert || eqne_p) ? gen_reg_rtx (mode) : result;
3227 convert_move (reg, gen_rtx (p_info->test_code, mode, cmp0, cmp1), 0);
3230 if (test == ITEST_NE)
3232 if (! TARGET_MIPS16)
3234 convert_move (result, gen_rtx (GTU, mode, reg, const0_rtx), 0);
3235 if (p_invert != NULL)
3241 reg2 = invert ? gen_reg_rtx (mode) : result;
3242 convert_move (reg2, gen_rtx (LTU, mode, reg, const1_rtx), 0);
3247 else if (test == ITEST_EQ)
3249 reg2 = invert ? gen_reg_rtx (mode) : result;
3250 convert_move (reg2, gen_rtx_LTU (mode, reg, const1_rtx), 0);
3258 if (! TARGET_MIPS16)
3262 /* The value is in $24. Copy it to another register, so
3263 that reload doesn't think it needs to store the $24 and
3264 the input to the XOR in the same location. */
3265 reg2 = gen_reg_rtx (mode);
3266 emit_move_insn (reg2, reg);
3268 one = force_reg (mode, const1_rtx);
3270 convert_move (result, gen_rtx (XOR, mode, reg, one), 0);
3276 /* Work out how to check a floating-point condition. We need a
3277 separate comparison instruction (C.cond.fmt), followed by a
3278 branch or conditional move. Given that IN_CODE is the
3279 required condition, set *CMP_CODE to the C.cond.fmt code
3280 and *action_code to the branch or move code. */
3283 get_float_compare_codes (in_code, cmp_code, action_code)
3284 enum rtx_code in_code, *cmp_code, *action_code;
3293 *cmp_code = reverse_condition_maybe_unordered (in_code);
3298 *cmp_code = in_code;
3304 /* Emit the common code for doing conditional branches.
3305 operand[0] is the label to jump to.
3306 The comparison operands are saved away by cmp{si,di,sf,df}. */
3309 gen_conditional_branch (operands, test_code)
3311 enum rtx_code test_code;
3313 enum cmp_type type = branch_type;
3314 rtx cmp0 = branch_cmp[0];
3315 rtx cmp1 = branch_cmp[1];
3316 enum machine_mode mode;
3317 enum rtx_code cmp_code;
3326 mode = type == CMP_SI ? SImode : DImode;
3328 reg = gen_int_relational (test_code, NULL_RTX, cmp0, cmp1, &invert);
3336 else if (GET_CODE (cmp1) == CONST_INT && INTVAL (cmp1) != 0)
3337 /* We don't want to build a comparison against a nonzero
3339 cmp1 = force_reg (mode, cmp1);
3346 reg = gen_rtx_REG (CCmode, FPSW_REGNUM);
3348 reg = gen_reg_rtx (CCmode);
3350 get_float_compare_codes (test_code, &cmp_code, &test_code);
3351 emit_insn (gen_rtx_SET (VOIDmode, reg,
3352 gen_rtx (cmp_code, CCmode, cmp0, cmp1)));
3361 abort_with_insn (gen_rtx (test_code, VOIDmode, cmp0, cmp1), "bad test");
3364 /* Generate the branch. */
3366 label1 = gen_rtx_LABEL_REF (VOIDmode, operands[0]);
3375 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3376 gen_rtx_IF_THEN_ELSE (VOIDmode,
3377 gen_rtx (test_code, mode,
3382 /* Emit the common code for conditional moves. OPERANDS is the array
3383 of operands passed to the conditional move defined_expand. */
3386 gen_conditional_move (operands)
3389 rtx op0 = branch_cmp[0];
3390 rtx op1 = branch_cmp[1];
3391 enum machine_mode mode = GET_MODE (branch_cmp[0]);
3392 enum rtx_code cmp_code = GET_CODE (operands[1]);
3393 enum rtx_code move_code = NE;
3394 enum machine_mode op_mode = GET_MODE (operands[0]);
3395 enum machine_mode cmp_mode;
3398 if (GET_MODE_CLASS (mode) != MODE_FLOAT)
3417 op0 = force_reg (mode, branch_cmp[1]);
3418 op1 = branch_cmp[0];
3422 op0 = force_reg (mode, branch_cmp[1]);
3423 op1 = branch_cmp[0];
3434 op0 = force_reg (mode, branch_cmp[1]);
3435 op1 = branch_cmp[0];
3439 op0 = force_reg (mode, branch_cmp[1]);
3440 op1 = branch_cmp[0];
3448 get_float_compare_codes (cmp_code, &cmp_code, &move_code);
3450 if (mode == SImode || mode == DImode)
3452 else if (mode == SFmode || mode == DFmode)
3457 cmp_reg = gen_reg_rtx (cmp_mode);
3458 emit_insn (gen_rtx_SET (cmp_mode, cmp_reg,
3459 gen_rtx (cmp_code, cmp_mode, op0, op1)));
3461 emit_insn (gen_rtx_SET (op_mode, operands[0],
3462 gen_rtx_IF_THEN_ELSE (op_mode,
3463 gen_rtx (move_code, VOIDmode,
3465 CONST0_RTX (SImode)),
3466 operands[2], operands[3])));
3469 /* Emit the common code for conditional moves. OPERANDS is the array
3470 of operands passed to the conditional move defined_expand. */
3473 mips_gen_conditional_trap (operands)
3477 enum rtx_code cmp_code = GET_CODE (operands[0]);
3478 enum machine_mode mode = GET_MODE (branch_cmp[0]);
3480 /* MIPS conditional trap machine instructions don't have GT or LE
3481 flavors, so we must invert the comparison and convert to LT and
3482 GE, respectively. */
3485 case GT: cmp_code = LT; break;
3486 case LE: cmp_code = GE; break;
3487 case GTU: cmp_code = LTU; break;
3488 case LEU: cmp_code = GEU; break;
3491 if (cmp_code == GET_CODE (operands[0]))
3493 op0 = force_reg (mode, branch_cmp[0]);
3494 op1 = branch_cmp[1];
3498 op0 = force_reg (mode, branch_cmp[1]);
3499 op1 = branch_cmp[0];
3501 if (GET_CODE (op1) == CONST_INT && ! SMALL_INT (op1))
3502 op1 = force_reg (mode, op1);
3504 emit_insn (gen_rtx_TRAP_IF (VOIDmode,
3505 gen_rtx (cmp_code, GET_MODE (operands[0]), op0, op1),
3509 /* Expand a call or call_value instruction. RESULT is where the
3510 result will go (null for calls), ADDR is the address of the
3511 function, ARGS_SIZE is the size of the arguments and AUX is
3512 the value passed to us by mips_function_arg. SIBCALL_P is true
3513 if we are expanding a sibling call, false if we're expanding
3517 mips_expand_call (result, addr, args_size, aux, sibcall_p)
3518 rtx result, addr, args_size, aux;
3523 if (!call_insn_operand (addr, VOIDmode))
3525 /* When generating PIC, try to allow global functions to be
3527 if (TARGET_EXPLICIT_RELOCS
3528 && GET_CODE (addr) == SYMBOL_REF
3529 && mips_classify_symbol (addr) == SYMBOL_GOT_GLOBAL)
3532 addr = mips_load_got16 (addr, RELOC_CALL16);
3534 addr = mips_load_got32 (0, addr, RELOC_CALL_HI, RELOC_CALL_LO);
3536 addr = force_reg (Pmode, addr);
3539 /* In order to pass small structures by value in registers
3540 compatibly with the MIPS compiler, we need to shift the value
3541 into the high part of the register. Function_arg has encoded
3542 a PARALLEL rtx, holding a vector of adjustments to be made
3543 as the next_arg_reg variable, so we split up the insns,
3544 and emit them separately. */
3545 if (aux != 0 && GET_CODE (aux) == PARALLEL)
3546 for (i = 0; i < XVECLEN (aux, 0); i++)
3547 emit_insn (XVECEXP (aux, 0, i));
3550 && mips16_hard_float
3551 && build_mips16_call_stub (result, addr, args_size,
3552 aux == 0 ? 0 : (int) GET_MODE (aux)))
3553 /* Nothing more to do */;
3554 else if (result == 0)
3555 emit_call_insn (sibcall_p
3556 ? gen_sibcall_internal (addr, args_size)
3557 : gen_call_internal (addr, args_size));
3558 else if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 2)
3562 reg1 = XEXP (XVECEXP (result, 0, 0), 0);
3563 reg2 = XEXP (XVECEXP (result, 0, 1), 0);
3566 ? gen_sibcall_value_multiple_internal (reg1, addr, args_size, reg2)
3567 : gen_call_value_multiple_internal (reg1, addr, args_size, reg2));
3570 emit_call_insn (sibcall_p
3571 ? gen_sibcall_value_internal (result, addr, args_size)
3572 : gen_call_value_internal (result, addr, args_size));
3576 /* We can handle any sibcall when TARGET_SIBCALLS is true. */
3579 mips_function_ok_for_sibcall (decl, exp)
3580 tree decl ATTRIBUTE_UNUSED;
3581 tree exp ATTRIBUTE_UNUSED;
3583 return TARGET_SIBCALLS;
3586 /* Return true if operand OP is a condition code register.
3587 Only for use during or after reload. */
3590 fcc_register_operand (op, mode)
3592 enum machine_mode mode;
3594 return ((mode == VOIDmode || mode == GET_MODE (op))
3595 && (reload_in_progress || reload_completed)
3596 && (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
3597 && ST_REG_P (true_regnum (op)));
3600 /* Emit code to move general operand SRC into condition-code
3601 register DEST. SCRATCH is a scratch TFmode float register.
3608 where FP1 and FP2 are single-precision float registers
3609 taken from SCRATCH. */
3612 mips_emit_fcc_reload (dest, src, scratch)
3613 rtx dest, src, scratch;
3617 /* Change the source to SFmode. */
3618 if (GET_CODE (src) == MEM)
3619 src = adjust_address (src, SFmode, 0);
3620 else if (GET_CODE (src) == REG || GET_CODE (src) == SUBREG)
3621 src = gen_rtx_REG (SFmode, true_regnum (src));
3623 fp1 = gen_rtx_REG (SFmode, REGNO (scratch));
3624 fp2 = gen_rtx_REG (SFmode, REGNO (scratch) + FP_INC);
3626 emit_move_insn (copy_rtx (fp1), src);
3627 emit_move_insn (copy_rtx (fp2), CONST0_RTX (SFmode));
3628 emit_insn (gen_slt_sf (dest, fp2, fp1));
3631 /* Emit code to change the current function's return address to
3632 ADDRESS. SCRATCH is available as a scratch register, if needed.
3633 ADDRESS and SCRATCH are both word-mode GPRs. */
3636 mips_set_return_address (address, scratch)
3637 rtx address, scratch;
3639 HOST_WIDE_INT gp_offset;
3641 compute_frame_size (get_frame_size ());
3642 if (((cfun->machine->frame.mask >> 31) & 1) == 0)
3644 gp_offset = cfun->machine->frame.gp_sp_offset;
3646 /* Reduce SP + GP_OFSET to a legitimate address and put it in SCRATCH. */
3647 if (gp_offset < 32768)
3648 scratch = plus_constant (stack_pointer_rtx, gp_offset);
3651 emit_move_insn (scratch, GEN_INT (gp_offset));
3652 if (Pmode == DImode)
3653 emit_insn (gen_adddi3 (scratch, scratch, stack_pointer_rtx));
3655 emit_insn (gen_addsi3 (scratch, scratch, stack_pointer_rtx));
3658 emit_move_insn (gen_rtx_MEM (GET_MODE (address), scratch), address);
3661 /* Write a loop to move a constant number of bytes.
3662 Generate load/stores as follows:
3668 temp<last> = src[MAX_MOVE_REGS-1];
3672 dest[MAX_MOVE_REGS-1] = temp<last>;
3673 src += MAX_MOVE_REGS;
3674 dest += MAX_MOVE_REGS;
3675 } while (src != final);
3677 This way, no NOP's are needed, and only MAX_MOVE_REGS+3 temp
3678 registers are needed.
3680 Aligned moves move MAX_MOVE_REGS*4 bytes every (2*MAX_MOVE_REGS)+3
3681 cycles, unaligned moves move MAX_MOVE_REGS*4 bytes every
3682 (4*MAX_MOVE_REGS)+3 cycles, assuming no cache misses. */
3684 #define MAX_MOVE_REGS 4
3685 #define MAX_MOVE_BYTES (MAX_MOVE_REGS * UNITS_PER_WORD)
3688 block_move_loop (dest_reg, src_reg, bytes, align, orig_dest, orig_src)
3689 rtx dest_reg; /* register holding destination address */
3690 rtx src_reg; /* register holding source address */
3691 unsigned int bytes; /* # bytes to move */
3692 int align; /* alignment */
3693 rtx orig_dest; /* original dest */
3694 rtx orig_src; /* original source for making a reg note */
3696 rtx dest_mem = replace_equiv_address (orig_dest, dest_reg);
3697 rtx src_mem = replace_equiv_address (orig_src, src_reg);
3698 rtx align_rtx = GEN_INT (align);
3704 if (bytes < (unsigned)2 * MAX_MOVE_BYTES)
3707 leftover = bytes % MAX_MOVE_BYTES;
3710 label = gen_label_rtx ();
3711 final_src = gen_reg_rtx (Pmode);
3712 bytes_rtx = GEN_INT (bytes);
3716 if (Pmode == DImode)
3718 emit_insn (gen_movdi (final_src, bytes_rtx));
3719 emit_insn (gen_adddi3 (final_src, final_src, src_reg));
3723 emit_insn (gen_movsi (final_src, bytes_rtx));
3724 emit_insn (gen_addsi3 (final_src, final_src, src_reg));
3729 if (Pmode == DImode)
3730 emit_insn (gen_adddi3 (final_src, src_reg, bytes_rtx));
3732 emit_insn (gen_addsi3 (final_src, src_reg, bytes_rtx));
3737 bytes_rtx = GEN_INT (MAX_MOVE_BYTES);
3738 emit_insn (gen_movstrsi_internal (dest_mem, src_mem, bytes_rtx, align_rtx));
3740 if (Pmode == DImode)
3742 emit_insn (gen_adddi3 (src_reg, src_reg, bytes_rtx));
3743 emit_insn (gen_adddi3 (dest_reg, dest_reg, bytes_rtx));
3744 emit_insn (gen_cmpdi (src_reg, final_src));
3748 emit_insn (gen_addsi3 (src_reg, src_reg, bytes_rtx));
3749 emit_insn (gen_addsi3 (dest_reg, dest_reg, bytes_rtx));
3750 emit_insn (gen_cmpsi (src_reg, final_src));
3753 emit_jump_insn (gen_bne (label));
3756 emit_insn (gen_movstrsi_internal (dest_mem, src_mem, GEN_INT (leftover),
3760 /* Use a library function to move some bytes. */
3763 block_move_call (dest_reg, src_reg, bytes_rtx)
3768 /* We want to pass the size as Pmode, which will normally be SImode
3769 but will be DImode if we are using 64 bit longs and pointers. */
3770 if (GET_MODE (bytes_rtx) != VOIDmode
3771 && GET_MODE (bytes_rtx) != (unsigned) Pmode)
3772 bytes_rtx = convert_to_mode (Pmode, bytes_rtx, 1);
3774 #ifdef TARGET_MEM_FUNCTIONS
3775 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "memcpy"), 0,
3776 VOIDmode, 3, dest_reg, Pmode, src_reg, Pmode,
3777 convert_to_mode (TYPE_MODE (sizetype), bytes_rtx,
3778 TREE_UNSIGNED (sizetype)),
3779 TYPE_MODE (sizetype));
3781 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "bcopy"), 0,
3782 VOIDmode, 3, src_reg, Pmode, dest_reg, Pmode,
3783 convert_to_mode (TYPE_MODE (integer_type_node), bytes_rtx,
3784 TREE_UNSIGNED (integer_type_node)),
3785 TYPE_MODE (integer_type_node));
3789 /* Expand string/block move operations.
3791 operands[0] is the pointer to the destination.
3792 operands[1] is the pointer to the source.
3793 operands[2] is the number of bytes to move.
3794 operands[3] is the alignment. */
3797 expand_block_move (operands)
3800 rtx bytes_rtx = operands[2];
3801 rtx align_rtx = operands[3];
3802 int constp = GET_CODE (bytes_rtx) == CONST_INT;
3803 unsigned HOST_WIDE_INT bytes = constp ? INTVAL (bytes_rtx) : 0;
3804 unsigned int align = INTVAL (align_rtx);
3805 rtx orig_src = operands[1];
3806 rtx orig_dest = operands[0];
3810 if (constp && bytes == 0)
3813 if (align > (unsigned) UNITS_PER_WORD)
3814 align = UNITS_PER_WORD;
3816 /* Move the address into scratch registers. */
3817 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
3818 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
3821 block_move_call (dest_reg, src_reg, bytes_rtx);
3823 else if (constp && bytes <= (unsigned)2 * MAX_MOVE_BYTES
3824 && align == (unsigned) UNITS_PER_WORD)
3825 move_by_pieces (orig_dest, orig_src, bytes, align * BITS_PER_WORD);
3827 else if (constp && bytes <= (unsigned)2 * MAX_MOVE_BYTES)
3828 emit_insn (gen_movstrsi_internal (replace_equiv_address (orig_dest,
3830 replace_equiv_address (orig_src,
3832 bytes_rtx, align_rtx));
3834 else if (constp && align >= (unsigned) UNITS_PER_WORD && optimize)
3835 block_move_loop (dest_reg, src_reg, bytes, align, orig_dest, orig_src);
3837 else if (constp && optimize)
3839 /* If the alignment is not word aligned, generate a test at
3840 runtime, to see whether things wound up aligned, and we
3841 can use the faster lw/sw instead ulw/usw. */
3843 rtx temp = gen_reg_rtx (Pmode);
3844 rtx aligned_label = gen_label_rtx ();
3845 rtx join_label = gen_label_rtx ();
3846 int leftover = bytes % MAX_MOVE_BYTES;
3850 if (Pmode == DImode)
3852 emit_insn (gen_iordi3 (temp, src_reg, dest_reg));
3853 emit_insn (gen_anddi3 (temp, temp, GEN_INT (UNITS_PER_WORD - 1)));
3854 emit_insn (gen_cmpdi (temp, const0_rtx));
3858 emit_insn (gen_iorsi3 (temp, src_reg, dest_reg));
3859 emit_insn (gen_andsi3 (temp, temp, GEN_INT (UNITS_PER_WORD - 1)));
3860 emit_insn (gen_cmpsi (temp, const0_rtx));
3863 emit_jump_insn (gen_beq (aligned_label));
3865 /* Unaligned loop. */
3866 block_move_loop (dest_reg, src_reg, bytes, 1, orig_dest, orig_src);
3867 emit_jump_insn (gen_jump (join_label));
3871 emit_label (aligned_label);
3872 block_move_loop (dest_reg, src_reg, bytes, UNITS_PER_WORD, orig_dest,
3874 emit_label (join_label);
3876 /* Bytes at the end of the loop. */
3878 emit_insn (gen_movstrsi_internal (replace_equiv_address (orig_dest,
3880 replace_equiv_address (orig_src,
3887 block_move_call (dest_reg, src_reg, bytes_rtx);
3890 /* Emit load/stores for a small constant block_move.
3892 operands[0] is the memory address of the destination.
3893 operands[1] is the memory address of the source.
3894 operands[2] is the number of bytes to move.
3895 operands[3] is the alignment.
3896 operands[4] is a temp register.
3897 operands[5] is a temp register.
3899 operands[3+num_regs] is the last temp register.
3901 The block move type can be one of the following:
3902 BLOCK_MOVE_NORMAL Do all of the block move.
3903 BLOCK_MOVE_NOT_LAST Do all but the last store.
3904 BLOCK_MOVE_LAST Do just the last store. */
3907 output_block_move (insn, operands, num_regs, move_type)
3911 enum block_move_type move_type;
3913 rtx dest_reg = XEXP (operands[0], 0);
3914 rtx src_reg = XEXP (operands[1], 0);
3915 HOST_WIDE_INT bytes = INTVAL (operands[2]);
3916 int align = INTVAL (operands[3]);
3919 int use_lwl_lwr = 0;
3920 int last_operand = num_regs + 4;
3926 const char *load; /* load insn without nop */
3927 const char *load_nop; /* load insn with trailing nop */
3928 const char *store; /* store insn */
3929 const char *final; /* if last_store used: NULL or swr */
3930 const char *last_store; /* last store instruction */
3931 int offset; /* current offset */
3932 enum machine_mode mode; /* mode to use on (MEM) */
3935 /* ??? Detect a bug in GCC, where it can give us a register
3936 the same as one of the addressing registers and reduce
3937 the number of registers available. */
3938 for (i = 4; i < last_operand && safe_regs < (int) ARRAY_SIZE (xoperands); i++)
3939 if (! reg_mentioned_p (operands[i], operands[0])
3940 && ! reg_mentioned_p (operands[i], operands[1]))
3941 xoperands[safe_regs++] = operands[i];
3943 if (safe_regs < last_operand)
3945 xoperands[0] = operands[0];
3946 xoperands[1] = operands[1];
3947 xoperands[2] = operands[2];
3948 xoperands[3] = operands[3];
3949 return output_block_move (insn, xoperands, safe_regs - 4, move_type);
3952 /* If we are given global or static addresses, and we would be
3953 emitting a few instructions, try to save time by using a
3954 temporary register for the pointer. */
3955 /* ??? The SGI Irix6 assembler fails when a SYMBOL_REF is used in
3956 an ldl/ldr instruction pair. We play it safe, and always move
3957 constant addresses into registers when generating N32/N64 code, just
3958 in case we might emit an unaligned load instruction. */
3959 if (num_regs > 2 && (bytes > 2 * align || move_type != BLOCK_MOVE_NORMAL
3960 || mips_abi == ABI_N32
3961 || mips_abi == ABI_64))
3963 if (CONSTANT_P (src_reg))
3965 src_reg = operands[3 + num_regs--];
3966 if (move_type != BLOCK_MOVE_LAST)
3968 xoperands[1] = operands[1];
3969 xoperands[0] = src_reg;
3970 if (Pmode == DImode)
3971 output_asm_insn ("dla\t%0,%1", xoperands);
3973 output_asm_insn ("la\t%0,%1", xoperands);
3977 if (CONSTANT_P (dest_reg))
3979 dest_reg = operands[3 + num_regs--];
3980 if (move_type != BLOCK_MOVE_LAST)
3982 xoperands[1] = operands[0];
3983 xoperands[0] = dest_reg;
3984 if (Pmode == DImode)
3985 output_asm_insn ("dla\t%0,%1", xoperands);
3987 output_asm_insn ("la\t%0,%1", xoperands);
3992 /* ??? We really shouldn't get any LO_SUM addresses here, because they
3993 are not offsettable, however, offsettable_address_p says they are
3994 offsettable. I think this is a bug in offsettable_address_p.
3995 For expediency, we fix this by just loading the address into a register
3996 if we happen to get one. */
3998 if (GET_CODE (src_reg) == LO_SUM)
4000 src_reg = operands[3 + num_regs--];
4001 if (move_type != BLOCK_MOVE_LAST)
4003 xoperands[2] = XEXP (XEXP (operands[1], 0), 1);
4004 xoperands[1] = XEXP (XEXP (operands[1], 0), 0);
4005 xoperands[0] = src_reg;
4006 if (Pmode == DImode)
4007 output_asm_insn ("daddiu\t%0,%1,%%lo(%2)", xoperands);
4009 output_asm_insn ("addiu\t%0,%1,%%lo(%2)", xoperands);
4013 if (GET_CODE (dest_reg) == LO_SUM)
4015 dest_reg = operands[3 + num_regs--];
4016 if (move_type != BLOCK_MOVE_LAST)
4018 xoperands[2] = XEXP (XEXP (operands[0], 0), 1);
4019 xoperands[1] = XEXP (XEXP (operands[0], 0), 0);
4020 xoperands[0] = dest_reg;
4021 if (Pmode == DImode)
4022 output_asm_insn ("daddiu\t%0,%1,%%lo(%2)", xoperands);
4024 output_asm_insn ("addiu\t%0,%1,%%lo(%2)", xoperands);
4028 if (num_regs > (int) ARRAY_SIZE (load_store))
4029 num_regs = ARRAY_SIZE (load_store);
4031 else if (num_regs < 1)
4032 abort_with_insn (insn,
4033 "cannot do block move, not enough scratch registers");
4037 load_store[num].offset = offset;
4039 if (TARGET_64BIT && bytes >= 8 && align >= 8)
4041 load_store[num].load = "ld\t%0,%1";
4042 load_store[num].load_nop = "ld\t%0,%1%#";
4043 load_store[num].store = "sd\t%0,%1";
4044 load_store[num].last_store = "sd\t%0,%1";
4045 load_store[num].final = 0;
4046 load_store[num].mode = DImode;
4051 /* ??? Fails because of a MIPS assembler bug? */
4052 else if (TARGET_64BIT && bytes >= 8
4056 if (BYTES_BIG_ENDIAN)
4058 load_store[num].load = "ldl\t%0,%1\n\tldr\t%0,%2";
4059 load_store[num].load_nop = "ldl\t%0,%1\n\tldr\t%0,%2%#";
4060 load_store[num].store = "sdl\t%0,%1\n\tsdr\t%0,%2";
4061 load_store[num].last_store = "sdr\t%0,%2";
4062 load_store[num].final = "sdl\t%0,%1";
4066 load_store[num].load = "ldl\t%0,%2\n\tldr\t%0,%1";
4067 load_store[num].load_nop = "ldl\t%0,%2\n\tldr\t%0,%1%#";
4068 load_store[num].store = "sdl\t%0,%2\n\tsdr\t%0,%1";
4069 load_store[num].last_store = "sdr\t%0,%1";
4070 load_store[num].final = "sdl\t%0,%2";
4073 load_store[num].mode = DImode;
4079 else if (bytes >= 4 && align >= 4)
4081 load_store[num].load = "lw\t%0,%1";
4082 load_store[num].load_nop = "lw\t%0,%1%#";
4083 load_store[num].store = "sw\t%0,%1";
4084 load_store[num].last_store = "sw\t%0,%1";
4085 load_store[num].final = 0;
4086 load_store[num].mode = SImode;