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"
56 #include "target-def.h"
57 #include "integrate.h"
60 #define STAB_CODE_TYPE enum __stab_debug_code
62 #define STAB_CODE_TYPE int
65 extern tree lookup_name PARAMS ((tree));
67 /* Enumeration for all of the relational tests, so that we can build
68 arrays indexed by the test type, and not worry about the order
85 /* Return true if it is likely that the given mode will be accessed
86 using only a single instruction. */
87 #define SINGLE_WORD_MODE_P(MODE) \
88 ((MODE) != BLKmode && GET_MODE_SIZE (MODE) <= UNITS_PER_WORD)
91 /* Classifies a non-literal integer constant.
94 Not one of the constants below.
97 The global pointer, treated as a constant when TARGET_MIPS16.
103 A signed 16-bit relocation against either a symbol
104 or a symbol plus an offset. The relocation has the form:
106 (unspec [(SYMBOL) ...] RELOC)
108 Any offset is added outside the unspec, such as:
110 (plus (unspec [(SYMBOL) ...] RELOC) (const_int OFFSET))
112 In either case, the whole expression is wrapped in a (const ...).
115 A reference to a symbol, possibly with an offset. */
116 enum mips_constant_type {
124 /* Classifies a SYMBOL_REF or LABEL_REF.
127 Used when none of the below apply.
130 The symbol refers to something in a small data section.
133 The symbol refers to something in the mips16 constant pool.
136 The symbol refers to local data that will be found using
137 the global offset table.
140 Likewise non-local data. */
141 enum mips_symbol_type {
144 SYMBOL_CONSTANT_POOL,
150 /* Classifies an address.
153 The address should be rejected as invalid.
156 A natural register + offset address. The register satisfies
157 mips_valid_base_register_p and the offset is a const_arith_operand.
160 A LO_SUM rtx. The first operand is a valid base register and
161 the second operand is a symbolic address.
164 A signed 16-bit constant address.
167 A constant symbolic address (equivalent to CONSTANT_SYMBOLIC). */
168 enum mips_address_type {
178 struct mips_arg_info;
179 struct mips_constant_info;
180 struct mips_address_info;
181 struct mips_integer_op;
182 static enum mips_constant_type mips_classify_constant
183 PARAMS ((struct mips_constant_info *, rtx));
184 static enum mips_symbol_type mips_classify_symbol
186 static bool mips_valid_base_register_p
187 PARAMS ((rtx, enum machine_mode, int));
188 static bool mips_symbolic_address_p
189 PARAMS ((rtx, HOST_WIDE_INT,
190 enum machine_mode, int));
191 static enum mips_address_type mips_classify_address
192 PARAMS ((struct mips_address_info *,
193 rtx, enum machine_mode, int, int));
194 static enum internal_test map_test_to_internal_test PARAMS ((enum rtx_code));
195 static void get_float_compare_codes PARAMS ((enum rtx_code, enum rtx_code *,
197 static const char *mips_reloc_string PARAMS ((int));
198 static bool mips_splittable_symbol_p PARAMS ((enum mips_symbol_type));
199 static int mips_symbol_insns PARAMS ((enum mips_symbol_type));
200 static bool mips16_unextended_reference_p
201 PARAMS ((enum machine_mode mode,
203 static rtx mips_force_temporary PARAMS ((rtx, rtx));
204 static rtx mips_add_offset PARAMS ((rtx, HOST_WIDE_INT));
205 static rtx mips_load_got PARAMS ((rtx, rtx, int));
206 static rtx mips_load_got16 PARAMS ((rtx, int));
207 static rtx mips_load_got32 PARAMS ((rtx, rtx, int, int));
208 static rtx mips_emit_high PARAMS ((rtx, rtx));
209 static bool mips_legitimize_symbol PARAMS ((rtx, rtx *, int));
210 static rtx mips_reloc PARAMS ((rtx, int));
211 static rtx mips_lui_reloc PARAMS ((rtx, int));
212 static unsigned int mips_build_shift PARAMS ((struct mips_integer_op *,
214 static unsigned int mips_build_lower PARAMS ((struct mips_integer_op *,
215 unsigned HOST_WIDE_INT));
216 static unsigned int mips_build_integer PARAMS ((struct mips_integer_op *,
217 unsigned HOST_WIDE_INT));
218 static void mips_move_integer PARAMS ((rtx, unsigned HOST_WIDE_INT));
219 static void mips_legitimize_const_move PARAMS ((enum machine_mode,
221 static int m16_check_op PARAMS ((rtx, int, int, int));
222 static bool mips_function_ok_for_sibcall PARAMS ((tree, tree));
223 static void block_move_loop PARAMS ((rtx, rtx,
227 static void block_move_call PARAMS ((rtx, rtx, rtx));
228 static void mips_arg_info PARAMS ((const CUMULATIVE_ARGS *,
231 struct mips_arg_info *));
232 static bool mips_get_unaligned_mem PARAMS ((rtx *, unsigned int,
234 static rtx mips_add_large_offset_to_sp PARAMS ((HOST_WIDE_INT));
235 static void mips_set_frame_expr PARAMS ((rtx));
236 static rtx mips_frame_set PARAMS ((rtx, int));
237 static void mips_emit_frame_related_store PARAMS ((rtx, rtx,
239 static void save_restore_insns PARAMS ((int, rtx, long));
240 static void mips16_fp_args PARAMS ((FILE *, int, int));
241 static void build_mips16_function_stub PARAMS ((FILE *));
242 static void mips16_optimize_gp PARAMS ((rtx));
243 static rtx add_constant PARAMS ((struct constant **,
246 static void dump_constants PARAMS ((struct constant *,
248 static rtx mips_find_symbol PARAMS ((rtx));
249 static void mips_reorg PARAMS ((void));
250 static void abort_with_insn PARAMS ((rtx, const char *))
252 static int symbolic_expression_p PARAMS ((rtx));
253 static bool mips_assemble_integer PARAMS ((rtx, unsigned int, int));
254 static void mips_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
255 static void mips_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
256 static void mips_set_architecture PARAMS ((const struct mips_cpu_info *));
257 static void mips_set_tune PARAMS ((const struct mips_cpu_info *));
258 static bool mips_strict_matching_cpu_name_p PARAMS ((const char *,
260 static bool mips_matching_cpu_name_p PARAMS ((const char *,
262 static const struct mips_cpu_info *mips_parse_cpu PARAMS ((const char *,
264 static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
265 static void copy_file_data PARAMS ((FILE *, FILE *));
267 static void iris6_asm_named_section_1 PARAMS ((const char *,
270 static void iris6_asm_named_section PARAMS ((const char *,
272 static int iris_section_align_entry_eq PARAMS ((const PTR, const PTR));
273 static hashval_t iris_section_align_entry_hash PARAMS ((const PTR));
274 static int iris6_section_align_1 PARAMS ((void **, void *));
276 static int mips_adjust_cost PARAMS ((rtx, rtx, rtx, int));
277 static int mips_issue_rate PARAMS ((void));
279 static struct machine_function * mips_init_machine_status PARAMS ((void));
280 static void mips_select_section PARAMS ((tree, int, unsigned HOST_WIDE_INT))
282 static void mips_unique_section PARAMS ((tree, int))
284 static void mips_select_rtx_section PARAMS ((enum machine_mode, rtx,
285 unsigned HOST_WIDE_INT));
286 static int mips_use_dfa_pipeline_interface PARAMS ((void));
287 static bool mips_rtx_costs PARAMS ((rtx, int, int, int *));
288 static int mips_address_cost PARAMS ((rtx));
289 static void mips_encode_section_info PARAMS ((tree, rtx, int));
292 /* Structure to be filled in by compute_frame_size with register
293 save masks, and offsets for the current function. */
295 struct mips_frame_info GTY(())
297 long total_size; /* # bytes that the entire frame takes up */
298 long var_size; /* # bytes that variables take up */
299 long args_size; /* # bytes that outgoing arguments take up */
300 long extra_size; /* # bytes of extra gunk */
301 int gp_reg_size; /* # bytes needed to store gp regs */
302 int fp_reg_size; /* # bytes needed to store fp regs */
303 long mask; /* mask of saved gp registers */
304 long fmask; /* mask of saved fp registers */
305 long gp_save_offset; /* offset from vfp to store gp registers */
306 long fp_save_offset; /* offset from vfp to store fp registers */
307 long gp_sp_offset; /* offset from new sp to store gp registers */
308 long fp_sp_offset; /* offset from new sp to store fp registers */
309 int initialized; /* != 0 if frame size already calculated */
310 int num_gp; /* number of gp registers saved */
311 int num_fp; /* number of fp registers saved */
314 struct machine_function GTY(()) {
315 /* Pseudo-reg holding the address of the current function when
316 generating embedded PIC code. Created by LEGITIMIZE_ADDRESS,
317 used by mips_finalize_pic if it was created. */
318 rtx embedded_pic_fnaddr_rtx;
320 /* Pseudo-reg holding the value of $28 in a mips16 function which
321 refers to GP relative global variables. */
322 rtx mips16_gp_pseudo_rtx;
324 /* Current frame information, calculated by compute_frame_size. */
325 struct mips_frame_info frame;
327 /* Length of instructions in function; mips16 only. */
331 /* Information about a single argument. */
334 /* True if the argument is a record or union type. */
337 /* True if the argument is passed in a floating-point register, or
338 would have been if we hadn't run out of registers. */
341 /* The argument's size, in bytes. */
342 unsigned int num_bytes;
344 /* The number of words passed in registers, rounded up. */
345 unsigned int reg_words;
347 /* The offset of the first register from GP_ARG_FIRST or FP_ARG_FIRST,
348 or MAX_ARGS_IN_REGISTERS if the argument is passed entirely
350 unsigned int reg_offset;
352 /* The number of words that must be passed on the stack, rounded up. */
353 unsigned int stack_words;
355 /* The offset from the start of the stack overflow area of the argument's
356 first stack word. Only meaningful when STACK_WORDS is nonzero. */
357 unsigned int stack_offset;
361 /* Struct for recording constants. The meaning of the fields depends
362 on a mips_constant_type:
369 SYMBOL is the relocation UNSPEC and OFFSET is the offset applied
373 SYMBOL is the referenced symbol and OFFSET is the constant offset. */
374 struct mips_constant_info
377 HOST_WIDE_INT offset;
381 /* Information about an address described by mips_address_type.
388 REG is the base register and OFFSET is the constant offset.
391 REG is the register that contains the high part of the address,
392 OFFSET is the symbolic address being referenced, and C contains
393 the individual components of the symbolic address.
396 C contains the symbol and offset. */
397 struct mips_address_info
401 struct mips_constant_info c;
405 /* One stage in a constant building sequence. These sequences have
409 A = A CODE[1] VALUE[1]
410 A = A CODE[2] VALUE[2]
413 where A is an accumulator, each CODE[i] is a binary rtl operation
414 and each VALUE[i] is a constant integer. */
415 struct mips_integer_op {
417 unsigned HOST_WIDE_INT value;
421 /* The largest number of operations needed to load an integer constant.
422 The worst accepted case for 64-bit constants is LUI,ORI,SLL,ORI,SLL,ORI.
423 When the lowest bit is clear, we can try, but reject a sequence with
424 an extra SLL at the end. */
425 #define MIPS_MAX_INTEGER_OPS 7
428 /* Global variables for machine-dependent things. */
430 /* Threshold for data being put into the small data/bss area, instead
431 of the normal data area (references to the small data/bss area take
432 1 instruction, and use the global pointer, references to the normal
433 data area takes 2 instructions). */
434 int mips_section_threshold = -1;
436 /* Count the number of .file directives, so that .loc is up to date. */
437 int num_source_filenames = 0;
439 /* Count the number of sdb related labels are generated (to find block
440 start and end boundaries). */
441 int sdb_label_count = 0;
443 /* Next label # for each statement for Silicon Graphics IRIS systems. */
446 /* Nonzero if inside of a function, because the stupid MIPS asm can't
447 handle .files inside of functions. */
448 int inside_function = 0;
450 /* Files to separate the text and the data output, so that all of the data
451 can be emitted before the text, which will mean that the assembler will
452 generate smaller code, based on the global pointer. */
453 FILE *asm_out_data_file;
454 FILE *asm_out_text_file;
456 /* Linked list of all externals that are to be emitted when optimizing
457 for the global pointer if they haven't been declared by the end of
458 the program with an appropriate .comm or initialization. */
460 struct extern_list GTY (())
462 struct extern_list *next; /* next external */
463 const char *name; /* name of the external */
464 int size; /* size in bytes */
467 static GTY (()) struct extern_list *extern_head = 0;
469 /* Name of the file containing the current function. */
470 const char *current_function_file = "";
472 /* Warning given that Mips ECOFF can't support changing files
473 within a function. */
474 int file_in_function_warning = FALSE;
476 /* Whether to suppress issuing .loc's because the user attempted
477 to change the filename within a function. */
478 int ignore_line_number = FALSE;
480 /* Number of nested .set noreorder, noat, nomacro, and volatile requests. */
486 /* The next branch instruction is a branch likely, not branch normal. */
487 int mips_branch_likely;
489 /* Cached operands, and operator to compare for use in set/branch/trap
490 on condition codes. */
493 /* what type of branch to use */
494 enum cmp_type branch_type;
496 /* The target cpu for code generation. */
497 enum processor_type mips_arch;
498 const struct mips_cpu_info *mips_arch_info;
500 /* The target cpu for optimization and scheduling. */
501 enum processor_type mips_tune;
502 const struct mips_cpu_info *mips_tune_info;
504 /* which instruction set architecture to use. */
507 /* which abi to use. */
510 /* Strings to hold which cpu and instruction set architecture to use. */
511 const char *mips_arch_string; /* for -march=<xxx> */
512 const char *mips_tune_string; /* for -mtune=<xxx> */
513 const char *mips_isa_string; /* for -mips{1,2,3,4} */
514 const char *mips_abi_string; /* for -mabi={32,n32,64,eabi} */
516 /* Whether we are generating mips16 code. This is a synonym for
517 TARGET_MIPS16, and exists for use as an attribute. */
520 /* This variable is set by -mno-mips16. We only care whether
521 -mno-mips16 appears or not, and using a string in this fashion is
522 just a way to avoid using up another bit in target_flags. */
523 const char *mips_no_mips16_string;
525 /* Whether we are generating mips16 hard float code. In mips16 mode
526 we always set TARGET_SOFT_FLOAT; this variable is nonzero if
527 -msoft-float was not specified by the user, which means that we
528 should arrange to call mips32 hard floating point code. */
529 int mips16_hard_float;
531 /* This variable is set by -mentry. We only care whether -mentry
532 appears or not, and using a string in this fashion is just a way to
533 avoid using up another bit in target_flags. */
534 const char *mips_entry_string;
536 const char *mips_cache_flush_func = CACHE_FLUSH_FUNC;
538 /* Whether we should entry and exit pseudo-ops in mips16 mode. */
541 /* If TRUE, we split addresses into their high and low parts in the RTL. */
542 int mips_split_addresses;
544 /* Generating calls to position independent functions? */
545 enum mips_abicalls_type mips_abicalls;
547 /* Mode used for saving/restoring general purpose registers. */
548 static enum machine_mode gpr_mode;
550 /* Array giving truth value on whether or not a given hard register
551 can support a given mode. */
552 char mips_hard_regno_mode_ok[(int)MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
554 /* The length of all strings seen when compiling for the mips16. This
555 is used to tell how many strings are in the constant pool, so that
556 we can see if we may have an overflow. This is reset each time the
557 constant pool is output. */
558 int mips_string_length;
560 /* When generating mips16 code, a list of all strings that are to be
561 output after the current function. */
563 static GTY(()) rtx mips16_strings;
565 /* In mips16 mode, we build a list of all the string constants we see
566 in a particular function. */
568 struct string_constant
570 struct string_constant *next;
574 static struct string_constant *string_constants;
576 /* List of all MIPS punctuation characters used by print_operand. */
577 char mips_print_operand_punct[256];
579 /* Map GCC register number to debugger register number. */
580 int mips_dbx_regno[FIRST_PSEUDO_REGISTER];
582 /* An alias set for the GOT. */
583 static int mips_got_alias_set;
585 static GTY (()) int mips_output_filename_first_time = 1;
587 /* Hardware names for the registers. If -mrnames is used, this
588 will be overwritten with mips_sw_reg_names. */
590 char mips_reg_names[][8] =
592 "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
593 "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
594 "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
595 "$24", "$25", "$26", "$27", "$28", "$sp", "$fp", "$31",
596 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
597 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
598 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
599 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
600 "hi", "lo", "accum","$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
601 "$fcc5","$fcc6","$fcc7","", "", "", "", "",
602 "$c0r0", "$c0r1", "$c0r2", "$c0r3", "$c0r4", "$c0r5", "$c0r6", "$c0r7",
603 "$c0r8", "$c0r9", "$c0r10","$c0r11","$c0r12","$c0r13","$c0r14","$c0r15",
604 "$c0r16","$c0r17","$c0r18","$c0r19","$c0r20","$c0r21","$c0r22","$c0r23",
605 "$c0r24","$c0r25","$c0r26","$c0r27","$c0r28","$c0r29","$c0r30","$c0r31",
606 "$c2r0", "$c2r1", "$c2r2", "$c2r3", "$c2r4", "$c2r5", "$c2r6", "$c2r7",
607 "$c2r8", "$c2r9", "$c2r10","$c2r11","$c2r12","$c2r13","$c2r14","$c2r15",
608 "$c2r16","$c2r17","$c2r18","$c2r19","$c2r20","$c2r21","$c2r22","$c2r23",
609 "$c2r24","$c2r25","$c2r26","$c2r27","$c2r28","$c2r29","$c2r30","$c2r31",
610 "$c3r0", "$c3r1", "$c3r2", "$c3r3", "$c3r4", "$c3r5", "$c3r6", "$c3r7",
611 "$c3r8", "$c3r9", "$c3r10","$c3r11","$c3r12","$c3r13","$c3r14","$c3r15",
612 "$c3r16","$c3r17","$c3r18","$c3r19","$c3r20","$c3r21","$c3r22","$c3r23",
613 "$c3r24","$c3r25","$c3r26","$c3r27","$c3r28","$c3r29","$c3r30","$c3r31"
616 /* Mips software names for the registers, used to overwrite the
617 mips_reg_names array. */
619 char mips_sw_reg_names[][8] =
621 "$zero","$at", "$v0", "$v1", "$a0", "$a1", "$a2", "$a3",
622 "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7",
623 "$s0", "$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7",
624 "$t8", "$t9", "$k0", "$k1", "$gp", "$sp", "$fp", "$ra",
625 "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
626 "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
627 "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
628 "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
629 "hi", "lo", "accum","$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
630 "$fcc5","$fcc6","$fcc7","$rap", "", "", "", "",
631 "$c0r0", "$c0r1", "$c0r2", "$c0r3", "$c0r4", "$c0r5", "$c0r6", "$c0r7",
632 "$c0r8", "$c0r9", "$c0r10","$c0r11","$c0r12","$c0r13","$c0r14","$c0r15",
633 "$c0r16","$c0r17","$c0r18","$c0r19","$c0r20","$c0r21","$c0r22","$c0r23",
634 "$c0r24","$c0r25","$c0r26","$c0r27","$c0r28","$c0r29","$c0r30","$c0r31",
635 "$c2r0", "$c2r1", "$c2r2", "$c2r3", "$c2r4", "$c2r5", "$c2r6", "$c2r7",
636 "$c2r8", "$c2r9", "$c2r10","$c2r11","$c2r12","$c2r13","$c2r14","$c2r15",
637 "$c2r16","$c2r17","$c2r18","$c2r19","$c2r20","$c2r21","$c2r22","$c2r23",
638 "$c2r24","$c2r25","$c2r26","$c2r27","$c2r28","$c2r29","$c2r30","$c2r31",
639 "$c3r0", "$c3r1", "$c3r2", "$c3r3", "$c3r4", "$c3r5", "$c3r6", "$c3r7",
640 "$c3r8", "$c3r9", "$c3r10","$c3r11","$c3r12","$c3r13","$c3r14","$c3r15",
641 "$c3r16","$c3r17","$c3r18","$c3r19","$c3r20","$c3r21","$c3r22","$c3r23",
642 "$c3r24","$c3r25","$c3r26","$c3r27","$c3r28","$c3r29","$c3r30","$c3r31"
645 /* Map hard register number to register class */
646 const enum reg_class mips_regno_to_class[] =
648 LEA_REGS, LEA_REGS, M16_NA_REGS, M16_NA_REGS,
649 M16_REGS, M16_REGS, M16_REGS, M16_REGS,
650 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
651 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
652 M16_NA_REGS, M16_NA_REGS, LEA_REGS, LEA_REGS,
653 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
654 T_REG, PIC_FN_ADDR_REG, LEA_REGS, LEA_REGS,
655 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
656 FP_REGS, FP_REGS, FP_REGS, FP_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 HI_REG, LO_REG, HILO_REG, ST_REGS,
665 ST_REGS, ST_REGS, ST_REGS, ST_REGS,
666 ST_REGS, ST_REGS, ST_REGS, NO_REGS,
667 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
668 COP0_REGS, COP0_REGS, COP0_REGS, COP0_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 COP2_REGS, COP2_REGS, COP2_REGS, COP2_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 COP3_REGS, COP3_REGS, COP3_REGS, COP3_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
694 /* Map register constraint character to register class. */
695 enum reg_class mips_char_to_class[256] =
697 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
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,
763 /* A table describing all the processors gcc knows about. Names are
764 matched in the order listed. The first mention of an ISA level is
765 taken as the canonical name for that ISA.
767 To ease comparison, please keep this table in the same order as
768 gas's mips_cpu_info_table[]. */
769 const struct mips_cpu_info mips_cpu_info_table[] = {
770 /* Entries for generic ISAs */
771 { "mips1", PROCESSOR_R3000, 1 },
772 { "mips2", PROCESSOR_R6000, 2 },
773 { "mips3", PROCESSOR_R4000, 3 },
774 { "mips4", PROCESSOR_R8000, 4 },
775 { "mips32", PROCESSOR_4KC, 32 },
776 { "mips32r2", PROCESSOR_M4K, 33 },
777 { "mips64", PROCESSOR_5KC, 64 },
780 { "r3000", PROCESSOR_R3000, 1 },
781 { "r2000", PROCESSOR_R3000, 1 }, /* = r3000 */
782 { "r3900", PROCESSOR_R3900, 1 },
785 { "r6000", PROCESSOR_R6000, 2 },
788 { "r4000", PROCESSOR_R4000, 3 },
789 { "vr4100", PROCESSOR_R4100, 3 },
790 { "vr4111", PROCESSOR_R4111, 3 },
791 { "vr4120", PROCESSOR_R4120, 3 },
792 { "vr4300", PROCESSOR_R4300, 3 },
793 { "r4400", PROCESSOR_R4000, 3 }, /* = r4000 */
794 { "r4600", PROCESSOR_R4600, 3 },
795 { "orion", PROCESSOR_R4600, 3 }, /* = r4600 */
796 { "r4650", PROCESSOR_R4650, 3 },
799 { "r8000", PROCESSOR_R8000, 4 },
800 { "vr5000", PROCESSOR_R5000, 4 },
801 { "vr5400", PROCESSOR_R5400, 4 },
802 { "vr5500", PROCESSOR_R5500, 4 },
805 { "4kc", PROCESSOR_4KC, 32 },
806 { "4kp", PROCESSOR_4KC, 32 }, /* = 4kc */
808 /* MIPS32 Release 2 */
809 { "m4k", PROCESSOR_M4K, 33 },
812 { "5kc", PROCESSOR_5KC, 64 },
813 { "20kc", PROCESSOR_20KC, 64 },
814 { "sb1", PROCESSOR_SB1, 64 },
815 { "sr71000", PROCESSOR_SR71000, 64 },
821 /* Nonzero if -march should decide the default value of MASK_SOFT_FLOAT. */
822 #ifndef MIPS_MARCH_CONTROLS_SOFT_FLOAT
823 #define MIPS_MARCH_CONTROLS_SOFT_FLOAT 0
826 /* Initialize the GCC target structure. */
827 #undef TARGET_ASM_ALIGNED_HI_OP
828 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
829 #undef TARGET_ASM_ALIGNED_SI_OP
830 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
831 #undef TARGET_ASM_INTEGER
832 #define TARGET_ASM_INTEGER mips_assemble_integer
834 #if TARGET_IRIX5 && !TARGET_IRIX6
835 #undef TARGET_ASM_UNALIGNED_HI_OP
836 #define TARGET_ASM_UNALIGNED_HI_OP "\t.align 0\n\t.half\t"
837 #undef TARGET_ASM_UNALIGNED_SI_OP
838 #define TARGET_ASM_UNALIGNED_SI_OP "\t.align 0\n\t.word\t"
839 #undef TARGET_ASM_UNALIGNED_DI_OP
840 #define TARGET_ASM_UNALIGNED_DI_OP "\t.align 0\n\t.dword\t"
843 #undef TARGET_ASM_FUNCTION_PROLOGUE
844 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
845 #undef TARGET_ASM_FUNCTION_EPILOGUE
846 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
847 #undef TARGET_ASM_SELECT_RTX_SECTION
848 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
850 #undef TARGET_SCHED_ADJUST_COST
851 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
852 #undef TARGET_SCHED_ISSUE_RATE
853 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
854 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
855 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE mips_use_dfa_pipeline_interface
857 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
858 #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall
860 #undef TARGET_VALID_POINTER_MODE
861 #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
862 #undef TARGET_RTX_COSTS
863 #define TARGET_RTX_COSTS mips_rtx_costs
864 #undef TARGET_ADDRESS_COST
865 #define TARGET_ADDRESS_COST mips_address_cost
866 #undef TARGET_DELEGITIMIZE_ADDRESS
867 #define TARGET_DELEGITIMIZE_ADDRESS mips_delegitimize_address
869 #undef TARGET_ENCODE_SECTION_INFO
870 #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
872 #undef TARGET_MACHINE_DEPENDENT_REORG
873 #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
875 struct gcc_target targetm = TARGET_INITIALIZER;
877 /* If X is one of the constants described by mips_constant_type,
878 store its components in INFO and return its type. */
880 static enum mips_constant_type
881 mips_classify_constant (info, x)
882 struct mips_constant_info *info;
887 if (GET_CODE (x) == CONST)
891 if (GET_CODE (x) == REG && REGNO (x) == GP_REG_FIRST + 28)
894 while (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
896 info->offset += INTVAL (XEXP (x, 1));
900 if (GET_CODE (x) == UNSPEC)
905 /* These relocations can be applied to symbols with offsets. */
906 return CONSTANT_RELOC;
914 /* These relocations should be applied to bare symbols only. */
915 return (info->offset == 0 ? CONSTANT_RELOC : CONSTANT_NONE);
918 if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
919 return CONSTANT_SYMBOLIC;
920 return CONSTANT_NONE;
924 /* Classify symbol X, which must be a SYMBOL_REF or a LABEL_REF. */
926 static enum mips_symbol_type
927 mips_classify_symbol (x)
930 if (GET_CODE (x) == LABEL_REF)
931 return (TARGET_ABICALLS ? SYMBOL_GOT_LOCAL : SYMBOL_GENERAL);
933 if (GET_CODE (x) != SYMBOL_REF)
936 if (CONSTANT_POOL_ADDRESS_P (x))
939 return SYMBOL_CONSTANT_POOL;
942 return SYMBOL_GOT_LOCAL;
944 if (GET_MODE_SIZE (get_pool_mode (x)) <= mips_section_threshold)
945 return SYMBOL_SMALL_DATA;
947 return SYMBOL_GENERAL;
950 if (XSTR (x, 0)[0] == '*'
951 && strncmp (XSTR (x, 0) + 1, LOCAL_LABEL_PREFIX,
952 sizeof LOCAL_LABEL_PREFIX - 1) == 0)
954 /* The symbol is a local label. For TARGET_MIPS16, SYMBOL_REF_FLAG
955 will be set if the symbol refers to a string in the current
956 function's constant pool. */
957 if (TARGET_MIPS16 && SYMBOL_REF_FLAG (x))
958 return SYMBOL_CONSTANT_POOL;
961 return SYMBOL_GOT_LOCAL;
965 return (SYMBOL_REF_FLAG (x) ? SYMBOL_GOT_LOCAL : SYMBOL_GOT_GLOBAL);
967 return (SYMBOL_REF_FLAG (x) ? SYMBOL_SMALL_DATA : SYMBOL_GENERAL);
971 /* This function is used to implement REG_MODE_OK_FOR_BASE_P. */
974 mips_reg_mode_ok_for_base_p (reg, mode, strict)
976 enum machine_mode mode;
980 ? REGNO_MODE_OK_FOR_BASE_P (REGNO (reg), mode)
981 : GP_REG_OR_PSEUDO_NONSTRICT_P (REGNO (reg), mode));
985 /* Return true if X is a valid base register for the given mode.
986 Allow only hard registers if STRICT. */
989 mips_valid_base_register_p (x, mode, strict)
991 enum machine_mode mode;
994 if (!strict && GET_CODE (x) == SUBREG)
997 return (GET_CODE (x) == REG
998 && mips_reg_mode_ok_for_base_p (x, mode, strict));
1002 /* Return true if SYMBOL + OFFSET should be considered a legitimate
1003 address. LEA_P is true and MODE is word_mode if the address
1004 will be used in an LA or DLA macro. Otherwise MODE is the
1005 mode of the value being accessed.
1007 Some guiding principles:
1009 - Allow a nonzero offset when it takes no additional instructions.
1010 Ask for other offsets to be added separately.
1012 - Only allow multi-instruction load or store macros when MODE is
1013 word-sized or smaller. For other modes (including BLKmode)
1014 it is better to move the address into a register first. */
1017 mips_symbolic_address_p (symbol, offset, mode, lea_p)
1019 HOST_WIDE_INT offset;
1020 enum machine_mode mode;
1023 if (TARGET_EXPLICIT_RELOCS)
1026 switch (mips_classify_symbol (symbol))
1028 case SYMBOL_GENERAL:
1029 /* General symbols aren't valid addresses in mips16 code:
1030 they have to go into the constant pool. */
1031 return (!TARGET_MIPS16
1032 && !mips_split_addresses
1033 && SINGLE_WORD_MODE_P (mode));
1035 case SYMBOL_SMALL_DATA:
1036 /* Small data references are normally OK for any address.
1037 But for mips16 code, we need to use a pseudo register
1038 instead of $gp as the base register. */
1039 return !TARGET_MIPS16;
1041 case SYMBOL_CONSTANT_POOL:
1042 /* PC-relative addressing is only available for lw, sw, ld and sd.
1043 There's also a PC-relative add instruction. */
1044 return lea_p || GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1046 case SYMBOL_GOT_GLOBAL:
1047 /* The address of the symbol is stored in the GOT. We can load
1048 it using an LA or DLA instruction, but any offset is added
1050 return lea_p && offset == 0;
1052 case SYMBOL_GOT_LOCAL:
1053 /* The symbol is part of a block of local memory. We fetch the
1054 address of the local memory from the GOT and then add the
1055 offset for this symbol. This addition can take the form of an
1056 offset(base) address, so the symbol is a legitimate address. */
1057 return SINGLE_WORD_MODE_P (mode);
1063 /* If X is a valid address, describe it in INFO and return its type.
1064 STRICT says to only allow hard registers. MODE and LEA_P are
1065 the same as for mips_symbolic_address_p. */
1067 static enum mips_address_type
1068 mips_classify_address (info, x, mode, strict, lea_p)
1069 struct mips_address_info *info;
1071 enum machine_mode mode;
1074 switch (GET_CODE (x))
1078 if (mips_valid_base_register_p (x, mode, strict))
1081 info->offset = const0_rtx;
1084 return ADDRESS_INVALID;
1087 if (mips_valid_base_register_p (XEXP (x, 0), mode, strict)
1088 && const_arith_operand (XEXP (x, 1), VOIDmode))
1090 info->reg = XEXP (x, 0);
1091 info->offset = XEXP (x, 1);
1094 return ADDRESS_INVALID;
1097 if (SINGLE_WORD_MODE_P (mode)
1098 && mips_valid_base_register_p (XEXP (x, 0), mode, strict)
1099 && (mips_classify_constant (&info->c, XEXP (x, 1))
1100 == CONSTANT_SYMBOLIC)
1101 && mips_splittable_symbol_p (mips_classify_symbol (info->c.symbol)))
1103 info->reg = XEXP (x, 0);
1104 info->offset = XEXP (x, 1);
1105 return ADDRESS_LO_SUM;
1107 return ADDRESS_INVALID;
1110 /* Small-integer addressses don't occur very often, but they
1111 are legitimate if $0 is a valid base register. */
1112 if (!TARGET_MIPS16 && SMALL_INT (x))
1113 return ADDRESS_CONST_INT;
1114 return ADDRESS_INVALID;
1119 if (mips_classify_constant (&info->c, x) == CONSTANT_SYMBOLIC
1120 && mips_symbolic_address_p (info->c.symbol, info->c.offset,
1122 return ADDRESS_SYMBOLIC;
1123 return ADDRESS_INVALID;
1126 return ADDRESS_INVALID;
1130 /* Return true if symbols of the given type can be split into a
1131 HIGH/LO_SUM pair. */
1134 mips_splittable_symbol_p (type)
1135 enum mips_symbol_type type;
1137 if (TARGET_EXPLICIT_RELOCS)
1138 return (type == SYMBOL_GENERAL || type == SYMBOL_GOT_LOCAL);
1139 if (mips_split_addresses)
1140 return (type == SYMBOL_GENERAL);
1145 /* Return the number of instructions needed to load a symbol of the
1146 given type into a register. If valid in an address, the same number
1147 of instructions are needed for loads and stores. Treat extended
1148 mips16 instructions as two instructions. */
1151 mips_symbol_insns (type)
1152 enum mips_symbol_type type;
1156 case SYMBOL_GENERAL:
1157 /* When using 64-bit symbols, we need 5 preparatory instructions,
1160 lui $at,%highest(symbol)
1161 daddiu $at,$at,%higher(symbol)
1163 daddiu $at,$at,%hi(symbol)
1166 The final address is then $at + %lo(symbol). With 32-bit
1167 symbols we just need a preparatory lui. */
1168 return (ABI_HAS_64BIT_SYMBOLS ? 6 : 2);
1170 case SYMBOL_SMALL_DATA:
1173 case SYMBOL_CONSTANT_POOL:
1174 /* This case is for mips16 only. Assume we'll need an
1175 extended instruction. */
1178 case SYMBOL_GOT_GLOBAL:
1179 /* When using a small GOT, we just fetch the address using
1180 a gp-relative load. For a big GOT, we need a sequence
1183 lui $at,%got_hi(symbol)
1186 and the final address is $at + %got_lo(symbol). */
1187 return (flag_pic == 1 ? 1 : 3);
1189 case SYMBOL_GOT_LOCAL:
1190 /* For o32 and o64, the sequence is:
1195 and the final address is $at + %lo(symbol). A load/add
1196 sequence is also needed for n32 and n64. Some versions
1197 of GAS insert a nop in the n32/n64 sequences too so, for
1198 simplicity, use the worst case of 3 instructions. */
1205 /* Return true if a value at OFFSET bytes from BASE can be accessed
1206 using an unextended mips16 instruction. MODE is the mode of the
1209 Usually the offset in an unextended instruction is a 5-bit field.
1210 The offset is unsigned and shifted left once for HIs, twice
1211 for SIs, and so on. An exception is SImode accesses off the
1212 stack pointer, which have an 8-bit immediate field. */
1215 mips16_unextended_reference_p (mode, base, offset)
1216 enum machine_mode mode;
1220 && GET_CODE (offset) == CONST_INT
1221 && INTVAL (offset) >= 0
1222 && (INTVAL (offset) & (GET_MODE_SIZE (mode) - 1)) == 0)
1224 if (GET_MODE_SIZE (mode) == 4 && base == stack_pointer_rtx)
1225 return INTVAL (offset) < 256 * GET_MODE_SIZE (mode);
1226 return INTVAL (offset) < 32 * GET_MODE_SIZE (mode);
1232 /* Return the number of instructions needed to load or store a value
1233 of mode MODE at X. Return 0 if X isn't valid for MODE.
1235 For mips16 code, count extended instructions as two instructions. */
1238 mips_address_insns (x, mode)
1240 enum machine_mode mode;
1242 struct mips_address_info addr;
1245 /* Each word of a multi-word value will be accessed individually. */
1246 factor = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1247 switch (mips_classify_address (&addr, x, mode, 0, 0))
1249 case ADDRESS_INVALID:
1254 && !mips16_unextended_reference_p (mode, addr.reg, addr.offset))
1258 case ADDRESS_LO_SUM:
1259 case ADDRESS_CONST_INT:
1262 case ADDRESS_SYMBOLIC:
1263 return factor * mips_symbol_insns (mips_classify_symbol (addr.c.symbol));
1269 /* Likewise for constant X. */
1272 mips_const_insns (x)
1275 struct mips_constant_info c;
1276 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
1278 switch (GET_CODE (x))
1280 case CONSTANT_P_RTX:
1286 /* Unsigned 8-bit constants can be loaded using an unextended
1287 LI instruction. Unsigned 16-bit constants can be loaded
1288 using an extended LI. Negative constants must be loaded
1289 using LI and then negated. */
1290 return (INTVAL (x) >= 0 && INTVAL (x) < 256 ? 1
1291 : SMALL_OPERAND_UNSIGNED (INTVAL (x)) ? 2
1292 : INTVAL (x) > -256 && INTVAL (x) < 0 ? 2
1293 : SMALL_OPERAND_UNSIGNED (-INTVAL (x)) ? 3
1296 return mips_build_integer (codes, INTVAL (x));
1299 return (!TARGET_MIPS16 && x == CONST0_RTX (GET_MODE (x)) ? 1 : 0);
1302 switch (mips_classify_constant (&c, x))
1310 case CONSTANT_RELOC:
1311 /* When generating mips16 code, we need to set the destination to
1312 $0 and then add in the signed offset. See mips_output_move. */
1313 return (TARGET_MIPS16 ? 3 : 1);
1315 case CONSTANT_SYMBOLIC:
1316 return mips_symbol_insns (mips_classify_symbol (c.symbol));
1323 /* Return the number of instructions needed for memory reference X.
1324 Count extended mips16 instructions as two instructions. */
1327 mips_fetch_insns (x)
1330 if (GET_CODE (x) != MEM)
1333 return mips_address_insns (XEXP (x, 0), GET_MODE (x));
1337 /* Return true if OP is a symbolic constant that refers to a
1338 global PIC symbol. */
1341 mips_global_pic_constant_p (op)
1344 struct mips_constant_info c;
1346 return (mips_classify_constant (&c, op) == CONSTANT_SYMBOLIC
1347 && mips_classify_symbol (c.symbol) == SYMBOL_GOT_GLOBAL);
1351 /* Return truth value of whether OP can be used as an operands
1352 where a register or 16 bit unsigned integer is needed. */
1355 uns_arith_operand (op, mode)
1357 enum machine_mode mode;
1359 if (GET_CODE (op) == CONST_INT && SMALL_INT_UNSIGNED (op))
1362 return register_operand (op, mode);
1366 /* True if OP can be treated as a signed 16-bit constant. */
1369 const_arith_operand (op, mode)
1371 enum machine_mode mode ATTRIBUTE_UNUSED;
1373 struct mips_constant_info c;
1375 return ((GET_CODE (op) == CONST_INT && SMALL_INT (op))
1376 || mips_classify_constant (&c, op) == CONSTANT_RELOC);
1380 /* Return truth value of whether OP can be used as an operands
1381 where a 16 bit integer is needed */
1384 arith_operand (op, mode)
1386 enum machine_mode mode;
1388 return const_arith_operand (op, mode) || register_operand (op, mode);
1391 /* Return truth value of whether OP can be used as an operand in a two
1392 address arithmetic insn (such as set 123456,%o4) of mode MODE. */
1395 arith32_operand (op, mode)
1397 enum machine_mode mode;
1399 if (GET_CODE (op) == CONST_INT)
1402 return register_operand (op, mode);
1405 /* Return truth value of whether OP is an integer which fits in 16 bits. */
1408 small_int (op, mode)
1410 enum machine_mode mode ATTRIBUTE_UNUSED;
1412 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
1415 /* Return truth value of whether OP is a 32 bit integer which is too big to
1416 be loaded with one instruction. */
1419 large_int (op, mode)
1421 enum machine_mode mode ATTRIBUTE_UNUSED;
1423 HOST_WIDE_INT value;
1425 if (GET_CODE (op) != CONST_INT)
1428 value = INTVAL (op);
1430 /* ior reg,$r0,value */
1431 if ((value & ~ ((HOST_WIDE_INT) 0x0000ffff)) == 0)
1434 /* subu reg,$r0,value */
1435 if (((unsigned HOST_WIDE_INT) (value + 32768)) <= 32767)
1438 /* lui reg,value>>16 */
1439 if ((value & 0x0000ffff) == 0)
1445 /* Return truth value of whether OP is a register or the constant 0.
1446 In mips16 mode, we only accept a register, since the mips16 does
1450 reg_or_0_operand (op, mode)
1452 enum machine_mode mode;
1454 switch (GET_CODE (op))
1459 return INTVAL (op) == 0;
1464 return op == CONST0_RTX (mode);
1467 return register_operand (op, mode);
1471 /* Return truth value of whether OP is a register or the constant 0,
1472 even in mips16 mode. */
1475 true_reg_or_0_operand (op, mode)
1477 enum machine_mode mode;
1479 switch (GET_CODE (op))
1482 return INTVAL (op) == 0;
1485 return op == CONST0_RTX (mode);
1488 return register_operand (op, mode);
1492 /* Accept the floating point constant 1 in the appropriate mode. */
1495 const_float_1_operand (op, mode)
1497 enum machine_mode mode;
1501 if (GET_CODE (op) != CONST_DOUBLE
1502 || mode != GET_MODE (op)
1503 || (mode != DFmode && mode != SFmode))
1506 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1508 return REAL_VALUES_EQUAL (d, dconst1);
1511 /* Return true if OP is either the HI or LO register. */
1514 hilo_operand (op, mode)
1516 enum machine_mode mode;
1518 return ((mode == VOIDmode || mode == GET_MODE (op))
1520 && (REGNO (op) == HI_REGNUM || REGNO (op) == LO_REGNUM));
1523 /* Return nonzero if the code of this rtx pattern is EQ or NE. */
1526 equality_op (op, mode)
1528 enum machine_mode mode;
1530 if (mode != GET_MODE (op))
1533 return GET_CODE (op) == EQ || GET_CODE (op) == NE;
1536 /* Return nonzero if the code is a relational operations (EQ, LE, etc.) */
1541 enum machine_mode mode;
1543 if (mode != GET_MODE (op))
1546 return GET_RTX_CLASS (GET_CODE (op)) == '<';
1549 /* Return nonzero if the code is a relational operation suitable for a
1550 conditional trap instructuion (only EQ, NE, LT, LTU, GE, GEU).
1551 We need this in the insn that expands `trap_if' in order to prevent
1552 combine from erroneously altering the condition. */
1555 trap_cmp_op (op, mode)
1557 enum machine_mode mode;
1559 if (mode != GET_MODE (op))
1562 switch (GET_CODE (op))
1577 /* Return nonzero if the operand is either the PC or a label_ref. */
1580 pc_or_label_operand (op, mode)
1582 enum machine_mode mode ATTRIBUTE_UNUSED;
1587 if (GET_CODE (op) == LABEL_REF)
1593 /* Test for a valid call address. */
1596 call_insn_operand (op, mode)
1598 enum machine_mode mode;
1600 struct mips_constant_info c;
1602 if (mips_classify_constant (&c, op) == CONSTANT_SYMBOLIC)
1603 switch (mips_classify_symbol (c.symbol))
1605 case SYMBOL_GENERAL:
1606 /* If -mlong-calls, force all calls to use register addressing. */
1607 return !TARGET_LONG_CALLS;
1609 case SYMBOL_GOT_GLOBAL:
1610 /* Without explicit relocs, there is no special syntax for
1611 loading the address of a call destination into a register.
1612 Using "la $25,foo; jal $25" would prevent the lazy binding
1613 of "foo", so keep the address of global symbols with the
1615 return c.offset == 0 && !TARGET_EXPLICIT_RELOCS;
1620 return register_operand (op, mode);
1624 /* Return nonzero if OP is valid as a source operand for a move
1628 move_operand (op, mode)
1630 enum machine_mode mode;
1632 struct mips_constant_info c;
1634 if (GET_CODE (op) == HIGH && TARGET_ABICALLS)
1636 if (GET_CODE (op) == CONST_INT && !TARGET_MIPS16)
1637 return (SMALL_INT (op) || SMALL_INT_UNSIGNED (op) || LUI_INT (op));
1638 if (mips_classify_constant (&c, op) == CONSTANT_SYMBOLIC)
1639 return mips_symbolic_address_p (c.symbol, c.offset, word_mode, 1);
1640 return general_operand (op, mode);
1644 /* Accept any operand that can appear in a mips16 constant table
1645 instruction. We can't use any of the standard operand functions
1646 because for these instructions we accept values that are not
1647 accepted by LEGITIMATE_CONSTANT, such as arbitrary SYMBOL_REFs. */
1650 consttable_operand (op, mode)
1652 enum machine_mode mode ATTRIBUTE_UNUSED;
1654 return CONSTANT_P (op);
1657 /* Coprocessor operand; return true if rtx is a REG and refers to a
1661 coprocessor_operand (op, mode)
1663 enum machine_mode mode ATTRIBUTE_UNUSED;
1665 return (GET_CODE (op) == REG
1666 && COP0_REG_FIRST <= REGNO (op)
1667 && REGNO (op) <= COP3_REG_LAST);
1671 coprocessor2_operand (op, mode)
1673 enum machine_mode mode ATTRIBUTE_UNUSED;
1675 return (GET_CODE (op) == REG
1676 && COP2_REG_FIRST <= REGNO (op)
1677 && REGNO (op) <= COP2_REG_LAST);
1680 /* Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
1681 possibly with an offset. */
1684 symbolic_operand (op, mode)
1686 enum machine_mode mode ATTRIBUTE_UNUSED;
1688 struct mips_constant_info c;
1690 return mips_classify_constant (&c, op) == CONSTANT_SYMBOLIC;
1694 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
1695 returns a nonzero value if X is a legitimate address for a memory
1696 operand of the indicated MODE. STRICT is nonzero if this function
1697 is called during reload. */
1700 mips_legitimate_address_p (mode, x, strict)
1701 enum machine_mode mode;
1705 struct mips_address_info addr;
1707 return mips_classify_address (&addr, x, mode, strict, 0) != ADDRESS_INVALID;
1711 /* Return an rtx that represents the effect of applying relocation
1712 RELOC to symbolic address ADDR. */
1715 mips_reloc (addr, reloc)
1719 struct mips_constant_info c;
1722 if (mips_classify_constant (&c, addr) != CONSTANT_SYMBOLIC)
1725 x = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, c.symbol), reloc);
1726 return plus_constant (gen_rtx_CONST (VOIDmode, x), c.offset);
1730 /* Likewise, but shift the result left 16 bits. The expression can be
1731 used as the right hand side of an LUISI or LUIDI pattern. */
1734 mips_lui_reloc (addr, reloc)
1738 return gen_rtx_UNSPEC (Pmode,
1739 gen_rtvec (1, mips_reloc (addr, reloc)),
1743 /* Copy VALUE to a register and return that register. Use DEST as the
1744 register if non-null, otherwise create a new one.
1746 VALUE must be valid on the right hand side of a simple SET pattern.
1747 The operation happens in Pmode. */
1750 mips_force_temporary (dest, value)
1754 return force_reg (Pmode, value);
1757 if (!rtx_equal_p (dest, value))
1758 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (dest), value));
1764 /* Return a legitimate address for REG + OFFSET. This function will
1765 create a temporary register if OFFSET is not a SMALL_OPERAND. */
1768 mips_add_offset (reg, offset)
1770 HOST_WIDE_INT offset;
1772 if (!SMALL_OPERAND (offset))
1773 reg = expand_simple_binop (GET_MODE (reg), PLUS,
1774 GEN_INT (CONST_HIGH_PART (offset)),
1775 reg, NULL, 0, OPTAB_WIDEN);
1777 return plus_constant (reg, CONST_LOW_PART (offset));
1781 /* Return the GOT entry whose address is given by %RELOC(ADDR)(BASE).
1782 BASE is a base register (such as $gp), ADDR is addresses being
1783 sought and RELOC is the relocation that should be used. */
1786 mips_load_got (base, addr, reloc)
1792 mem = gen_rtx_MEM (ptr_mode,
1793 gen_rtx_PLUS (Pmode, base, mips_reloc (addr, reloc)));
1794 set_mem_alias_set (mem, mips_got_alias_set);
1796 /* If we allow a function's address to be lazily bound, its entry
1797 may change after the first call. Other entries are constant. */
1798 if (reloc != RELOC_CALL16 && reloc != RELOC_CALL_LO)
1799 RTX_UNCHANGING_P (mem) = 1;
1801 if (Pmode != ptr_mode)
1802 mem = gen_rtx_SIGN_EXTEND (Pmode, mem);
1808 /* Obtain the address of ADDR from the GOT using relocation RELOC.
1809 The returned address may be used on the right hand side of a SET. */
1812 mips_load_got16 (addr, reloc)
1816 return mips_load_got (pic_offset_table_rtx, addr, reloc);
1820 /* Like mips_load_got16, but for 32-bit offsets. HIGH_RELOC is the
1821 relocation that gives the high 16 bits of the offset and LOW_RELOC is
1822 the relocation that gives the low 16 bits. TEMP is a Pmode register
1823 to use a temporary, or null if new registers can be created at will. */
1826 mips_load_got32 (temp, addr, high_reloc, low_reloc)
1828 int high_reloc, low_reloc;
1832 x = mips_force_temporary (temp, mips_lui_reloc (addr, high_reloc));
1833 x = mips_force_temporary (temp,
1834 gen_rtx_PLUS (Pmode, pic_offset_table_rtx, x));
1835 return mips_load_got (x, addr, low_reloc);
1839 /* Copy the high part of ADDR into a register and return the register.
1840 Use DEST as the register if non-null. */
1843 mips_emit_high (dest, addr)
1848 high = gen_rtx_HIGH (Pmode, addr);
1849 if (TARGET_ABICALLS)
1851 x = mips_load_got16 (copy_rtx (addr), RELOC_GOT_PAGE);
1852 x = mips_force_temporary (dest, x);
1853 set_unique_reg_note (get_last_insn (), REG_EQUAL, high);
1856 x = mips_force_temporary (dest, high);
1861 /* See if *XLOC is a symbolic constant that can be reduced in some way.
1862 If it is, set *XLOC to the reduced expression and return true.
1863 The new expression will be both a legitimate address and a legitimate
1864 source operand for a mips.md SET pattern. If OFFSETABLE_P, the
1865 address will be offsetable.
1867 DEST is a register to use a temporary, or null if new registers
1868 can be created at will. */
1871 mips_legitimize_symbol (dest, xloc, offsetable_p)
1875 struct mips_constant_info c;
1876 enum mips_symbol_type symbol_type;
1879 if (mips_classify_constant (&c, *xloc) != CONSTANT_SYMBOLIC)
1882 symbol_type = mips_classify_symbol (c.symbol);
1884 /* Convert a mips16 reference to the small data section into
1885 an address of the form:
1887 (plus BASE (const (plus (unspec [SYMBOL] UNSPEC_GPREL) OFFSET)))
1889 BASE is the pseudo created by mips16_gp_pseudo_reg.
1890 The (const ...) may include an offset. */
1892 && symbol_type == SYMBOL_SMALL_DATA
1895 *xloc = gen_rtx_PLUS (Pmode, mips16_gp_pseudo_reg (),
1896 mips_reloc (*xloc, RELOC_GPREL16));
1900 /* Likewise for normal-mode code. In this case we can use $gp
1901 as a base register. */
1903 && TARGET_EXPLICIT_RELOCS
1904 && symbol_type == SYMBOL_SMALL_DATA)
1906 *xloc = gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
1907 mips_reloc (*xloc, RELOC_GPREL16));
1911 /* If a non-offsetable address is OK, convert general symbols into
1912 a HIGH/LO_SUM pair. */
1913 if (!offsetable_p && mips_splittable_symbol_p (symbol_type))
1915 x = mips_emit_high (dest, *xloc);
1916 *xloc = gen_rtx_LO_SUM (Pmode, x, copy_rtx (*xloc));
1920 /* If generating PIC, and ADDR is a global symbol with an offset,
1921 load the symbol into a register and apply the offset separately.
1922 We need a temporary when adding large offsets. */
1923 if (symbol_type == SYMBOL_GOT_GLOBAL
1925 && (SMALL_OPERAND (c.offset) || dest == 0))
1927 x = (dest == 0 ? gen_reg_rtx (Pmode) : dest);
1928 emit_move_insn (copy_rtx (x), c.symbol);
1929 *xloc = mips_add_offset (x, c.offset);
1937 /* This function is used to implement LEGITIMIZE_ADDRESS. If *XLOC can
1938 be legitimized in a way that the generic machinery might not expect,
1939 put the new address in *XLOC and return true. MODE is the mode of
1940 the memory being accessed. */
1943 mips_legitimize_address (xloc, mode)
1945 enum machine_mode mode;
1947 if (mips_legitimize_symbol (0, xloc, !SINGLE_WORD_MODE_P (mode)))
1950 if (GET_CODE (*xloc) == PLUS && GET_CODE (XEXP (*xloc, 1)) == CONST_INT)
1952 /* Handle REG + CONSTANT using mips_add_offset. */
1955 reg = XEXP (*xloc, 0);
1956 if (!mips_valid_base_register_p (reg, mode, 0))
1957 reg = copy_to_mode_reg (Pmode, reg);
1958 *xloc = mips_add_offset (reg, INTVAL (XEXP (*xloc, 1)));
1966 /* Subroutine of mips_build_integer (with the same interface).
1967 Assume that the final action in the sequence should be a left shift. */
1970 mips_build_shift (codes, value)
1971 struct mips_integer_op *codes;
1972 HOST_WIDE_INT value;
1974 unsigned int i, shift;
1976 /* Shift VALUE right until its lowest bit is set. Shift arithmetically
1977 since signed numbers are easier to load than unsigned ones. */
1979 while ((value & 1) == 0)
1980 value /= 2, shift++;
1982 i = mips_build_integer (codes, value);
1983 codes[i].code = ASHIFT;
1984 codes[i].value = shift;
1989 /* As for mips_build_shift, but assume that the final action will be
1990 an IOR or PLUS operation. */
1993 mips_build_lower (codes, value)
1994 struct mips_integer_op *codes;
1995 unsigned HOST_WIDE_INT value;
1997 unsigned HOST_WIDE_INT high;
2000 high = value & ~(unsigned HOST_WIDE_INT) 0xffff;
2001 if (!LUI_OPERAND (high) && (value & 0x18000) == 0x18000)
2003 /* The constant is too complex to load with a simple lui/ori pair
2004 so our goal is to clear as many trailing zeros as possible.
2005 In this case, we know bit 16 is set and that the low 16 bits
2006 form a negative number. If we subtract that number from VALUE,
2007 we will clear at least the lowest 17 bits, maybe more. */
2008 i = mips_build_integer (codes, CONST_HIGH_PART (value));
2009 codes[i].code = PLUS;
2010 codes[i].value = CONST_LOW_PART (value);
2014 i = mips_build_integer (codes, high);
2015 codes[i].code = IOR;
2016 codes[i].value = value & 0xffff;
2022 /* Fill CODES with a sequence of rtl operations to load VALUE.
2023 Return the number of operations needed. */
2026 mips_build_integer (codes, value)
2027 struct mips_integer_op *codes;
2028 unsigned HOST_WIDE_INT value;
2030 if (SMALL_OPERAND (value)
2031 || SMALL_OPERAND_UNSIGNED (value)
2032 || LUI_OPERAND (value))
2034 /* The value can be loaded with a single instruction. */
2035 codes[0].code = NIL;
2036 codes[0].value = value;
2039 else if ((value & 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value)))
2041 /* Either the constant is a simple LUI/ORI combination or its
2042 lowest bit is set. We don't want to shift in this case. */
2043 return mips_build_lower (codes, value);
2045 else if ((value & 0xffff) == 0)
2047 /* The constant will need at least three actions. The lowest
2048 16 bits are clear, so the final action will be a shift. */
2049 return mips_build_shift (codes, value);
2053 /* The final action could be a shift, add or inclusive OR.
2054 Rather than use a complex condition to select the best
2055 approach, try both mips_build_shift and mips_build_lower
2056 and pick the one that gives the shortest sequence.
2057 Note that this case is only used once per constant. */
2058 struct mips_integer_op alt_codes[MIPS_MAX_INTEGER_OPS];
2059 unsigned int cost, alt_cost;
2061 cost = mips_build_shift (codes, value);
2062 alt_cost = mips_build_lower (alt_codes, value);
2063 if (alt_cost < cost)
2065 memcpy (codes, alt_codes, alt_cost * sizeof (codes[0]));
2073 /* Move VALUE into register DEST. */
2076 mips_move_integer (dest, value)
2078 unsigned HOST_WIDE_INT value;
2080 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
2081 enum machine_mode mode;
2082 unsigned int i, cost;
2085 mode = GET_MODE (dest);
2086 cost = mips_build_integer (codes, value);
2088 /* Apply each binary operation to X. Invariant: X is a legitimate
2089 source operand for a SET pattern. */
2090 x = GEN_INT (codes[0].value);
2091 for (i = 1; i < cost; i++)
2094 emit_move_insn (dest, x), x = dest;
2096 x = force_reg (mode, x);
2097 x = gen_rtx_fmt_ee (codes[i].code, mode, x, GEN_INT (codes[i].value));
2100 emit_insn (gen_rtx_SET (VOIDmode, dest, x));
2104 /* Subroutine of mips_legitimize_move. Move constant SRC into register
2105 DEST given that SRC satisfies immediate_operand but doesn't satisfy
2109 mips_legitimize_const_move (mode, dest, src)
2110 enum machine_mode mode;
2115 temp = no_new_pseudos ? dest : 0;
2117 /* If generating PIC, the high part of an address is loaded from the GOT. */
2118 if (GET_CODE (src) == HIGH)
2120 mips_emit_high (dest, XEXP (src, 0));
2124 if (GET_CODE (src) == CONST_INT && !TARGET_MIPS16)
2126 mips_move_integer (dest, INTVAL (src));
2130 /* Fetch global symbols from the GOT. */
2131 if (TARGET_EXPLICIT_RELOCS
2132 && GET_CODE (src) == SYMBOL_REF
2133 && mips_classify_symbol (src) == SYMBOL_GOT_GLOBAL)
2136 src = mips_load_got16 (src, RELOC_GOT_DISP);
2138 src = mips_load_got32 (temp, src, RELOC_GOT_HI, RELOC_GOT_LO);
2139 emit_insn (gen_rtx_SET (VOIDmode, dest, src));
2143 /* Try handling the source operand as a symbolic address. */
2144 if (mips_legitimize_symbol (temp, &src, false))
2146 emit_insn (gen_rtx_SET (VOIDmode, dest, src));
2150 src = force_const_mem (mode, src);
2152 /* When using explicit relocs, constant pool references are sometimes
2153 not legitimate addresses. mips_legitimize_symbol must be able to
2154 deal with all such cases. */
2155 if (GET_CODE (src) == MEM && !memory_operand (src, VOIDmode))
2157 src = copy_rtx (src);
2158 if (!mips_legitimize_symbol (temp, &XEXP (src, 0), false))
2161 emit_move_insn (dest, src);
2165 /* If (set DEST SRC) is not a valid instruction, emit an equivalent
2166 sequence that is valid. */
2169 mips_legitimize_move (mode, dest, src)
2170 enum machine_mode mode;
2173 if (!register_operand (dest, mode) && !reg_or_0_operand (src, mode))
2175 emit_move_insn (dest, force_reg (mode, src));
2179 /* The source of an SImode move must be a move_operand. Likewise
2180 DImode moves on 64-bit targets. We need to deal with constants
2181 that would be legitimate immediate_operands but not legitimate
2183 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
2185 && !move_operand (src, mode))
2187 mips_legitimize_const_move (mode, dest, src);
2188 set_unique_reg_note (get_last_insn (), REG_EQUAL, copy_rtx (src));
2195 /* Convert GOT and GP-relative accesses back into their original form.
2196 Used by bothh TARGET_DELEGITIMIZE_ADDRESS and FIND_BASE_TERM. */
2199 mips_delegitimize_address (x)
2202 struct mips_constant_info c;
2204 if (GET_CODE (x) == MEM
2205 && GET_CODE (XEXP (x, 0)) == PLUS
2206 && mips_classify_constant (&c, XEXP (XEXP (x, 0), 1)) == CONSTANT_RELOC
2207 && mips_classify_symbol (XVECEXP (c.symbol, 0, 0)) == SYMBOL_GOT_GLOBAL)
2208 return XVECEXP (c.symbol, 0, 0);
2210 if (GET_CODE (x) == PLUS
2211 && (XEXP (x, 0) == pic_offset_table_rtx
2212 || XEXP (x, 0) == cfun->machine->mips16_gp_pseudo_rtx)
2213 && mips_classify_constant (&c, XEXP (x, 1)) == CONSTANT_RELOC
2214 && mips_classify_symbol (XVECEXP (c.symbol, 0, 0)) == SYMBOL_SMALL_DATA)
2215 return plus_constant (XVECEXP (c.symbol, 0, 0), c.offset);
2220 /* We need a lot of little routines to check constant values on the
2221 mips16. These are used to figure out how long the instruction will
2222 be. It would be much better to do this using constraints, but
2223 there aren't nearly enough letters available. */
2226 m16_check_op (op, low, high, mask)
2232 return (GET_CODE (op) == CONST_INT
2233 && INTVAL (op) >= low
2234 && INTVAL (op) <= high
2235 && (INTVAL (op) & mask) == 0);
2239 m16_uimm3_b (op, mode)
2241 enum machine_mode mode ATTRIBUTE_UNUSED;
2243 return m16_check_op (op, 0x1, 0x8, 0);
2247 m16_simm4_1 (op, mode)
2249 enum machine_mode mode ATTRIBUTE_UNUSED;
2251 return m16_check_op (op, - 0x8, 0x7, 0);
2255 m16_nsimm4_1 (op, mode)
2257 enum machine_mode mode ATTRIBUTE_UNUSED;
2259 return m16_check_op (op, - 0x7, 0x8, 0);
2263 m16_simm5_1 (op, mode)
2265 enum machine_mode mode ATTRIBUTE_UNUSED;
2267 return m16_check_op (op, - 0x10, 0xf, 0);
2271 m16_nsimm5_1 (op, mode)
2273 enum machine_mode mode ATTRIBUTE_UNUSED;
2275 return m16_check_op (op, - 0xf, 0x10, 0);
2279 m16_uimm5_4 (op, mode)
2281 enum machine_mode mode ATTRIBUTE_UNUSED;
2283 return m16_check_op (op, (- 0x10) << 2, 0xf << 2, 3);
2287 m16_nuimm5_4 (op, mode)
2289 enum machine_mode mode ATTRIBUTE_UNUSED;
2291 return m16_check_op (op, (- 0xf) << 2, 0x10 << 2, 3);
2295 m16_simm8_1 (op, mode)
2297 enum machine_mode mode ATTRIBUTE_UNUSED;
2299 return m16_check_op (op, - 0x80, 0x7f, 0);
2303 m16_nsimm8_1 (op, mode)
2305 enum machine_mode mode ATTRIBUTE_UNUSED;
2307 return m16_check_op (op, - 0x7f, 0x80, 0);
2311 m16_uimm8_1 (op, mode)
2313 enum machine_mode mode ATTRIBUTE_UNUSED;
2315 return m16_check_op (op, 0x0, 0xff, 0);
2319 m16_nuimm8_1 (op, mode)
2321 enum machine_mode mode ATTRIBUTE_UNUSED;
2323 return m16_check_op (op, - 0xff, 0x0, 0);
2327 m16_uimm8_m1_1 (op, mode)
2329 enum machine_mode mode ATTRIBUTE_UNUSED;
2331 return m16_check_op (op, - 0x1, 0xfe, 0);
2335 m16_uimm8_4 (op, mode)
2337 enum machine_mode mode ATTRIBUTE_UNUSED;
2339 return m16_check_op (op, 0x0, 0xff << 2, 3);
2343 m16_nuimm8_4 (op, mode)
2345 enum machine_mode mode ATTRIBUTE_UNUSED;
2347 return m16_check_op (op, (- 0xff) << 2, 0x0, 3);
2351 m16_simm8_8 (op, mode)
2353 enum machine_mode mode ATTRIBUTE_UNUSED;
2355 return m16_check_op (op, (- 0x80) << 3, 0x7f << 3, 7);
2359 m16_nsimm8_8 (op, mode)
2361 enum machine_mode mode ATTRIBUTE_UNUSED;
2363 return m16_check_op (op, (- 0x7f) << 3, 0x80 << 3, 7);
2366 /* References to the string table on the mips16 only use a small
2367 offset if the function is small. We can't check for LABEL_REF here,
2368 because the offset is always large if the label is before the
2369 referencing instruction. */
2372 m16_usym8_4 (op, mode)
2374 enum machine_mode mode ATTRIBUTE_UNUSED;
2376 if (GET_CODE (op) == SYMBOL_REF
2377 && SYMBOL_REF_FLAG (op)
2378 && cfun->machine->insns_len > 0
2379 && XSTR (op, 0)[0] == '*'
2380 && strncmp (XSTR (op, 0) + 1, LOCAL_LABEL_PREFIX,
2381 sizeof LOCAL_LABEL_PREFIX - 1) == 0
2382 && (cfun->machine->insns_len + get_pool_size () + mips_string_length
2385 struct string_constant *l;
2387 /* Make sure this symbol is on thelist of string constants to be
2388 output for this function. It is possible that it has already
2389 been output, in which case this requires a large offset. */
2390 for (l = string_constants; l != NULL; l = l->next)
2391 if (strcmp (l->label, XSTR (op, 0)) == 0)
2399 m16_usym5_4 (op, mode)
2401 enum machine_mode mode ATTRIBUTE_UNUSED;
2403 if (GET_CODE (op) == SYMBOL_REF
2404 && SYMBOL_REF_FLAG (op)
2405 && cfun->machine->insns_len > 0
2406 && XSTR (op, 0)[0] == '*'
2407 && strncmp (XSTR (op, 0) + 1, LOCAL_LABEL_PREFIX,
2408 sizeof LOCAL_LABEL_PREFIX - 1) == 0
2409 && (cfun->machine->insns_len + get_pool_size () + mips_string_length
2412 struct string_constant *l;
2414 /* Make sure this symbol is on thelist of string constants to be
2415 output for this function. It is possible that it has already
2416 been output, in which case this requires a large offset. */
2417 for (l = string_constants; l != NULL; l = l->next)
2418 if (strcmp (l->label, XSTR (op, 0)) == 0)
2426 mips_rtx_costs (x, code, outer_code, total)
2428 int code, outer_code;
2431 enum machine_mode mode = GET_MODE (x);
2438 /* Always return 0, since we don't have different sized
2439 instructions, hence different costs according to Richard
2445 /* A number between 1 and 8 inclusive is efficient for a shift.
2446 Otherwise, we will need an extended instruction. */
2447 if ((outer_code) == ASHIFT || (outer_code) == ASHIFTRT
2448 || (outer_code) == LSHIFTRT)
2450 if (INTVAL (x) >= 1 && INTVAL (x) <= 8)
2453 *total = COSTS_N_INSNS (1);
2456 /* We can use cmpi for an xor with an unsigned 16 bit value. */
2458 if ((outer_code) == XOR
2459 && INTVAL (x) >= 0 && INTVAL (x) < 0x10000)
2465 /* We may be able to use slt or sltu for a comparison with a
2466 signed 16 bit value. (The boundary conditions aren't quite
2467 right, but this is just a heuristic anyhow.) */
2468 if (((outer_code) == LT || (outer_code) == LE
2469 || (outer_code) == GE || (outer_code) == GT
2470 || (outer_code) == LTU || (outer_code) == LEU
2471 || (outer_code) == GEU || (outer_code) == GTU)
2472 && INTVAL (x) >= -0x8000 && INTVAL (x) < 0x8000)
2478 /* Equality comparisons with 0 are cheap. */
2479 if (((outer_code) == EQ || (outer_code) == NE)
2486 /* Otherwise fall through to the handling below. */
2492 if (((outer_code) == PLUS || (outer_code) == MINUS)
2493 && const_arith_operand (x, VOIDmode))
2500 int n = mips_const_insns (x);
2501 return (n == 0 ? CONSTANT_POOL_COST : COSTS_N_INSNS (n));
2506 /* If the address is legitimate, return the number of
2507 instructions it needs, otherwise use the default handling. */
2508 int n = mips_address_insns (XEXP (x, 0), GET_MODE (x));
2511 *total = COSTS_N_INSNS (1 + n);
2518 *total = COSTS_N_INSNS (6);
2522 *total = COSTS_N_INSNS ((mode == DImode && !TARGET_64BIT) ? 2 : 1);
2528 if (mode == DImode && !TARGET_64BIT)
2530 *total = COSTS_N_INSNS (2);
2538 if (mode == DImode && !TARGET_64BIT)
2540 *total = COSTS_N_INSNS ((GET_CODE (XEXP (x, 1)) == CONST_INT)
2547 if (mode == SFmode || mode == DFmode)
2548 *total = COSTS_N_INSNS (1);
2550 *total = COSTS_N_INSNS (4);
2554 *total = COSTS_N_INSNS (1);
2559 if (mode == SFmode || mode == DFmode)
2561 if (TUNE_MIPS3000 || TUNE_MIPS3900)
2562 *total = COSTS_N_INSNS (2);
2563 else if (TUNE_MIPS6000)
2564 *total = COSTS_N_INSNS (3);
2566 *total = COSTS_N_INSNS (6);
2569 if (mode == DImode && !TARGET_64BIT)
2571 *total = COSTS_N_INSNS (4);
2577 if (mode == DImode && !TARGET_64BIT)
2590 *total = COSTS_N_INSNS (4);
2591 else if (TUNE_MIPS6000
2594 *total = COSTS_N_INSNS (5);
2596 *total = COSTS_N_INSNS (7);
2605 *total = COSTS_N_INSNS (5);
2606 else if (TUNE_MIPS6000
2609 *total = COSTS_N_INSNS (6);
2611 *total = COSTS_N_INSNS (8);
2616 *total = COSTS_N_INSNS (12);
2617 else if (TUNE_MIPS3900)
2618 *total = COSTS_N_INSNS (2);
2619 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2620 *total = COSTS_N_INSNS ((mode == DImode) ? 4 : 3);
2621 else if (TUNE_MIPS6000)
2622 *total = COSTS_N_INSNS (17);
2623 else if (TUNE_MIPS5000)
2624 *total = COSTS_N_INSNS (5);
2626 *total = COSTS_N_INSNS (10);
2635 *total = COSTS_N_INSNS (12);
2636 else if (TUNE_MIPS6000)
2637 *total = COSTS_N_INSNS (15);
2638 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2639 *total = COSTS_N_INSNS (30);
2641 *total = COSTS_N_INSNS (23);
2649 *total = COSTS_N_INSNS (19);
2650 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2651 *total = COSTS_N_INSNS (59);
2652 else if (TUNE_MIPS6000)
2653 *total = COSTS_N_INSNS (16);
2655 *total = COSTS_N_INSNS (36);
2664 *total = COSTS_N_INSNS (35);
2665 else if (TUNE_MIPS6000)
2666 *total = COSTS_N_INSNS (38);
2667 else if (TUNE_MIPS5000)
2668 *total = COSTS_N_INSNS (36);
2669 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2670 *total = COSTS_N_INSNS ((mode == SImode) ? 42 : 74);
2672 *total = COSTS_N_INSNS (69);
2676 /* A sign extend from SImode to DImode in 64 bit mode is often
2677 zero instructions, because the result can often be used
2678 directly by another instruction; we'll call it one. */
2679 if (TARGET_64BIT && mode == DImode
2680 && GET_MODE (XEXP (x, 0)) == SImode)
2681 *total = COSTS_N_INSNS (1);
2683 *total = COSTS_N_INSNS (2);
2687 if (TARGET_64BIT && mode == DImode
2688 && GET_MODE (XEXP (x, 0)) == SImode)
2689 *total = COSTS_N_INSNS (2);
2691 *total = COSTS_N_INSNS (1);
2699 /* Provide the costs of an addressing mode that contains ADDR.
2700 If ADDR is not a valid address, its cost is irrelevant. */
2703 mips_address_cost (addr)
2706 return mips_address_insns (addr, SImode);
2709 /* Return a pseudo that points to the address of the current function.
2710 The first time it is called for a function, an initializer for the
2711 pseudo is emitted in the beginning of the function. */
2714 embedded_pic_fnaddr_reg ()
2716 if (cfun->machine->embedded_pic_fnaddr_rtx == NULL)
2720 cfun->machine->embedded_pic_fnaddr_rtx = gen_reg_rtx (Pmode);
2722 /* Output code at function start to initialize the pseudo-reg. */
2723 /* ??? We used to do this in FINALIZE_PIC, but that does not work for
2724 inline functions, because it is called after RTL for the function
2725 has been copied. The pseudo-reg in embedded_pic_fnaddr_rtx however
2726 does not get copied, and ends up not matching the rest of the RTL.
2727 This solution works, but means that we get unnecessary code to
2728 initialize this value every time a function is inlined into another
2731 emit_insn (gen_get_fnaddr (cfun->machine->embedded_pic_fnaddr_rtx,
2732 XEXP (DECL_RTL (current_function_decl), 0)));
2735 push_topmost_sequence ();
2736 emit_insn_after (seq, get_insns ());
2737 pop_topmost_sequence ();
2740 return cfun->machine->embedded_pic_fnaddr_rtx;
2743 /* Return RTL for the offset from the current function to the argument.
2744 X is the symbol whose offset from the current function we want. */
2747 embedded_pic_offset (x)
2750 /* Make sure it is emitted. */
2751 embedded_pic_fnaddr_reg ();
2754 gen_rtx_CONST (Pmode,
2755 gen_rtx_MINUS (Pmode, x,
2756 XEXP (DECL_RTL (current_function_decl), 0)));
2759 /* Return one word of double-word value OP, taking into account the fixed
2760 endianness of certain registers. HIGH_P is true to select the high part,
2761 false to select the low part. */
2764 mips_subword (op, high_p)
2769 enum machine_mode mode;
2771 mode = GET_MODE (op);
2772 if (mode == VOIDmode)
2775 if (TARGET_BIG_ENDIAN ? !high_p : high_p)
2776 byte = UNITS_PER_WORD;
2780 if (GET_CODE (op) == REG)
2782 if (FP_REG_P (REGNO (op)))
2783 return gen_rtx_REG (word_mode, high_p ? REGNO (op) + 1 : REGNO (op));
2784 if (REGNO (op) == HI_REGNUM)
2785 return gen_rtx_REG (word_mode, high_p ? HI_REGNUM : LO_REGNUM);
2788 if (GET_CODE (op) == MEM)
2789 return adjust_address (op, word_mode, byte);
2791 return simplify_gen_subreg (word_mode, op, mode, byte);
2795 /* Return true if a 64-bit move from SRC to DEST should be split into two. */
2798 mips_split_64bit_move_p (dest, src)
2804 /* FP->FP moves can be done in a single instruction. */
2805 if (FP_REG_RTX_P (src) && FP_REG_RTX_P (dest))
2808 /* Check for floating-point loads and stores. They can be done using
2809 ldc1 and sdc1 on MIPS II and above. */
2812 if (FP_REG_RTX_P (dest) && GET_CODE (src) == MEM)
2814 if (FP_REG_RTX_P (src) && GET_CODE (dest) == MEM)
2821 /* Split a 64-bit move from SRC to DEST assuming that
2822 mips_split_64bit_move_p holds.
2824 Moves into and out of FPRs cause some difficulty here. Such moves
2825 will always be DFmode, since paired FPRs are not allowed to store
2826 DImode values. The most natural representation would be two separate
2827 32-bit moves, such as:
2829 (set (reg:SI $f0) (mem:SI ...))
2830 (set (reg:SI $f1) (mem:SI ...))
2832 However, the second insn is invalid because odd-numbered FPRs are
2833 not allowed to store independent values. Use the patterns load_df_low,
2834 load_df_high and store_df_high instead. */
2837 mips_split_64bit_move (dest, src)
2840 if (FP_REG_RTX_P (dest))
2842 /* Loading an FPR from memory or from GPRs. */
2843 emit_insn (gen_load_df_low (copy_rtx (dest), mips_subword (src, 0)));
2844 emit_insn (gen_load_df_high (dest, mips_subword (src, 1),
2847 else if (FP_REG_RTX_P (src))
2849 /* Storing an FPR into memory or GPRs. */
2850 emit_move_insn (mips_subword (dest, 0), mips_subword (src, 0));
2851 emit_insn (gen_store_df_high (mips_subword (dest, 1), src));
2855 /* The operation can be split into two normal moves. Decide in
2856 which order to do them. */
2859 low_dest = mips_subword (dest, 0);
2860 if (GET_CODE (low_dest) == REG
2861 && reg_overlap_mentioned_p (low_dest, src))
2863 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2864 emit_move_insn (low_dest, mips_subword (src, 0));
2868 emit_move_insn (low_dest, mips_subword (src, 0));
2869 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2874 /* Return the appropriate instructions to move SRC into DEST. Assume
2875 that SRC is operand 1 and DEST is operand 0. */
2878 mips_output_move (dest, src)
2881 enum rtx_code dest_code, src_code;
2882 struct mips_constant_info c;
2885 dest_code = GET_CODE (dest);
2886 src_code = GET_CODE (src);
2887 dbl_p = (GET_MODE_SIZE (GET_MODE (dest)) == 8);
2889 if (dbl_p && mips_split_64bit_move_p (dest, src))
2892 if ((src_code == REG && GP_REG_P (REGNO (src)))
2893 || (!TARGET_MIPS16 && src == CONST0_RTX (GET_MODE (dest))))
2895 if (dest_code == REG)
2897 if (GP_REG_P (REGNO (dest)))
2898 return "or\t%0,%z1,$0";
2900 if (MD_REG_P (REGNO (dest)))
2903 if (FP_REG_P (REGNO (dest)))
2904 return (dbl_p ? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0");
2906 if (ALL_COP_REG_P (REGNO (dest)))
2908 static char retval[] = "dmtc_\t%z1,%0";
2910 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2911 return (dbl_p ? retval : retval + 1);
2914 if (dest_code == MEM)
2915 return (dbl_p ? "sd\t%z1,%0" : "sw\t%z1,%0");
2917 if (dest_code == REG && GP_REG_P (REGNO (dest)))
2919 if (src_code == REG)
2921 if (MD_REG_P (REGNO (src)))
2924 if (ST_REG_P (REGNO (src)) && ISA_HAS_8CC)
2925 return "lui\t%0,0x3f80\n\tmovf\t%0,%.,%1";
2927 if (FP_REG_P (REGNO (src)))
2928 return (dbl_p ? "dmfc1\t%0,%1" : "mfc1\t%0,%1");
2930 if (ALL_COP_REG_P (REGNO (src)))
2932 static char retval[] = "dmfc_\t%0,%1";
2934 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
2935 return (dbl_p ? retval : retval + 1);
2939 if (src_code == MEM)
2940 return (dbl_p ? "ld\t%0,%1" : "lw\t%0,%1");
2942 if (src_code == CONST_INT)
2944 /* Don't use the X format, because that will give out of
2945 range numbers for 64 bit hosts and 32 bit targets. */
2947 return "li\t%0,%1\t\t\t# %X1";
2949 if (INTVAL (src) >= 0 && INTVAL (src) <= 0xffff)
2952 if (INTVAL (src) < 0 && INTVAL (src) >= -0xffff)
2953 return "li\t%0,%n1\n\tneg\t%0";
2956 if (src_code == HIGH)
2957 return "lui\t%0,%h1";
2959 switch (mips_classify_constant (&c, src))
2965 return "or\t%0,%1,$0";
2967 case CONSTANT_RELOC:
2968 return (TARGET_MIPS16 ? "li\t%0,0\n\taddiu\t%0,%1" : "li\t%0,%1");
2970 case CONSTANT_SYMBOLIC:
2971 return (dbl_p ? "dla\t%0,%a1" : "la\t%0,%a1");
2974 if (src_code == REG && FP_REG_P (REGNO (src)))
2976 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2977 return (dbl_p ? "mov.d\t%0,%1" : "mov.s\t%0,%1");
2979 if (dest_code == MEM)
2980 return (dbl_p ? "sdc1\t%1,%0" : "swc1\t%1,%0");
2982 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2984 if (src_code == MEM)
2985 return (dbl_p ? "ldc1\t%0,%1" : "lwc1\t%0,%1");
2987 if (dest_code == REG && ALL_COP_REG_P (REGNO (dest)) && src_code == MEM)
2989 static char retval[] = "l_c_\t%0,%1";
2991 retval[1] = (dbl_p ? 'd' : 'w');
2992 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2995 if (dest_code == MEM && src_code == REG && ALL_COP_REG_P (REGNO (src)))
2997 static char retval[] = "s_c_\t%1,%0";
2999 retval[1] = (dbl_p ? 'd' : 'w');
3000 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
3006 /* Return instructions to restore the global pointer from the stack,
3007 assuming TARGET_ABICALLS. Used by exception_receiver to set up
3008 the GP for exception handlers.
3010 OPERANDS is an array of operands whose contents are undefined
3014 mips_restore_gp (operands)
3019 operands[0] = pic_offset_table_rtx;
3020 if (frame_pointer_needed)
3021 loc = hard_frame_pointer_rtx;
3023 loc = stack_pointer_rtx;
3024 loc = plus_constant (loc, cfun->machine->frame.args_size);
3025 operands[1] = gen_rtx_MEM (ptr_mode, loc);
3027 return mips_output_move (operands[0], operands[1]);
3031 /* Make normal rtx_code into something we can index from an array */
3033 static enum internal_test
3034 map_test_to_internal_test (test_code)
3035 enum rtx_code test_code;
3037 enum internal_test test = ITEST_MAX;
3041 case EQ: test = ITEST_EQ; break;
3042 case NE: test = ITEST_NE; break;
3043 case GT: test = ITEST_GT; break;
3044 case GE: test = ITEST_GE; break;
3045 case LT: test = ITEST_LT; break;
3046 case LE: test = ITEST_LE; break;
3047 case GTU: test = ITEST_GTU; break;
3048 case GEU: test = ITEST_GEU; break;
3049 case LTU: test = ITEST_LTU; break;
3050 case LEU: test = ITEST_LEU; break;
3058 /* Generate the code to compare two integer values. The return value is:
3059 (reg:SI xx) The pseudo register the comparison is in
3060 0 No register, generate a simple branch.
3062 ??? This is called with result nonzero by the Scond patterns in
3063 mips.md. These patterns are called with a target in the mode of
3064 the Scond instruction pattern. Since this must be a constant, we
3065 must use SImode. This means that if RESULT is nonzero, it will
3066 always be an SImode register, even if TARGET_64BIT is true. We
3067 cope with this by calling convert_move rather than emit_move_insn.
3068 This will sometimes lead to an unnecessary extension of the result;
3080 gen_int_relational (test_code, result, cmp0, cmp1, p_invert)
3081 enum rtx_code test_code; /* relational test (EQ, etc) */
3082 rtx result; /* result to store comp. or 0 if branch */
3083 rtx cmp0; /* first operand to compare */
3084 rtx cmp1; /* second operand to compare */
3085 int *p_invert; /* NULL or ptr to hold whether branch needs */
3086 /* to reverse its test */
3090 enum rtx_code test_code; /* code to use in instruction (LT vs. LTU) */
3091 int const_low; /* low bound of constant we can accept */
3092 int const_high; /* high bound of constant we can accept */
3093 int const_add; /* constant to add (convert LE -> LT) */
3094 int reverse_regs; /* reverse registers in test */
3095 int invert_const; /* != 0 if invert value if cmp1 is constant */
3096 int invert_reg; /* != 0 if invert value if cmp1 is register */
3097 int unsignedp; /* != 0 for unsigned comparisons. */
3100 static const struct cmp_info info[ (int)ITEST_MAX ] = {
3102 { XOR, 0, 65535, 0, 0, 0, 0, 0 }, /* EQ */
3103 { XOR, 0, 65535, 0, 0, 1, 1, 0 }, /* NE */
3104 { LT, -32769, 32766, 1, 1, 1, 0, 0 }, /* GT */
3105 { LT, -32768, 32767, 0, 0, 1, 1, 0 }, /* GE */
3106 { LT, -32768, 32767, 0, 0, 0, 0, 0 }, /* LT */
3107 { LT, -32769, 32766, 1, 1, 0, 1, 0 }, /* LE */
3108 { LTU, -32769, 32766, 1, 1, 1, 0, 1 }, /* GTU */
3109 { LTU, -32768, 32767, 0, 0, 1, 1, 1 }, /* GEU */
3110 { LTU, -32768, 32767, 0, 0, 0, 0, 1 }, /* LTU */
3111 { LTU, -32769, 32766, 1, 1, 0, 1, 1 }, /* LEU */
3114 enum internal_test test;
3115 enum machine_mode mode;
3116 const struct cmp_info *p_info;
3123 test = map_test_to_internal_test (test_code);
3124 if (test == ITEST_MAX)
3127 p_info = &info[(int) test];
3128 eqne_p = (p_info->test_code == XOR);
3130 mode = GET_MODE (cmp0);
3131 if (mode == VOIDmode)
3132 mode = GET_MODE (cmp1);
3134 /* Eliminate simple branches */
3135 branch_p = (result == 0);
3138 if (GET_CODE (cmp0) == REG || GET_CODE (cmp0) == SUBREG)
3140 /* Comparisons against zero are simple branches */
3141 if (GET_CODE (cmp1) == CONST_INT && INTVAL (cmp1) == 0
3142 && (! TARGET_MIPS16 || eqne_p))
3145 /* Test for beq/bne. */
3146 if (eqne_p && ! TARGET_MIPS16)
3150 /* allocate a pseudo to calculate the value in. */
3151 result = gen_reg_rtx (mode);
3154 /* Make sure we can handle any constants given to us. */
3155 if (GET_CODE (cmp0) == CONST_INT)
3156 cmp0 = force_reg (mode, cmp0);
3158 if (GET_CODE (cmp1) == CONST_INT)
3160 HOST_WIDE_INT value = INTVAL (cmp1);
3162 if (value < p_info->const_low
3163 || value > p_info->const_high
3164 /* ??? Why? And why wasn't the similar code below modified too? */
3166 && HOST_BITS_PER_WIDE_INT < 64
3167 && p_info->const_add != 0
3168 && ((p_info->unsignedp
3169 ? ((unsigned HOST_WIDE_INT) (value + p_info->const_add)
3170 > (unsigned HOST_WIDE_INT) INTVAL (cmp1))
3171 : (value + p_info->const_add) > INTVAL (cmp1))
3172 != (p_info->const_add > 0))))
3173 cmp1 = force_reg (mode, cmp1);
3176 /* See if we need to invert the result. */
3177 invert = (GET_CODE (cmp1) == CONST_INT
3178 ? p_info->invert_const : p_info->invert_reg);
3180 if (p_invert != (int *)0)
3186 /* Comparison to constants, may involve adding 1 to change a LT into LE.
3187 Comparison between two registers, may involve switching operands. */
3188 if (GET_CODE (cmp1) == CONST_INT)
3190 if (p_info->const_add != 0)
3192 HOST_WIDE_INT new = INTVAL (cmp1) + p_info->const_add;
3194 /* If modification of cmp1 caused overflow,
3195 we would get the wrong answer if we follow the usual path;
3196 thus, x > 0xffffffffU would turn into x > 0U. */
3197 if ((p_info->unsignedp
3198 ? (unsigned HOST_WIDE_INT) new >
3199 (unsigned HOST_WIDE_INT) INTVAL (cmp1)
3200 : new > INTVAL (cmp1))
3201 != (p_info->const_add > 0))
3203 /* This test is always true, but if INVERT is true then
3204 the result of the test needs to be inverted so 0 should
3205 be returned instead. */
3206 emit_move_insn (result, invert ? const0_rtx : const_true_rtx);
3210 cmp1 = GEN_INT (new);
3214 else if (p_info->reverse_regs)
3221 if (test == ITEST_NE && GET_CODE (cmp1) == CONST_INT && INTVAL (cmp1) == 0)
3225 reg = (invert || eqne_p) ? gen_reg_rtx (mode) : result;
3226 convert_move (reg, gen_rtx (p_info->test_code, mode, cmp0, cmp1), 0);
3229 if (test == ITEST_NE)
3231 if (! TARGET_MIPS16)
3233 convert_move (result, gen_rtx (GTU, mode, reg, const0_rtx), 0);
3234 if (p_invert != NULL)
3240 reg2 = invert ? gen_reg_rtx (mode) : result;
3241 convert_move (reg2, gen_rtx (LTU, mode, reg, const1_rtx), 0);
3246 else if (test == ITEST_EQ)
3248 reg2 = invert ? gen_reg_rtx (mode) : result;
3249 convert_move (reg2, gen_rtx_LTU (mode, reg, const1_rtx), 0);
3257 if (! TARGET_MIPS16)
3261 /* The value is in $24. Copy it to another register, so
3262 that reload doesn't think it needs to store the $24 and
3263 the input to the XOR in the same location. */
3264 reg2 = gen_reg_rtx (mode);
3265 emit_move_insn (reg2, reg);
3267 one = force_reg (mode, const1_rtx);
3269 convert_move (result, gen_rtx (XOR, mode, reg, one), 0);
3275 /* Work out how to check a floating-point condition. We need a
3276 separate comparison instruction (C.cond.fmt), followed by a
3277 branch or conditional move. Given that IN_CODE is the
3278 required condition, set *CMP_CODE to the C.cond.fmt code
3279 and *action_code to the branch or move code. */
3282 get_float_compare_codes (in_code, cmp_code, action_code)
3283 enum rtx_code in_code, *cmp_code, *action_code;
3292 *cmp_code = reverse_condition_maybe_unordered (in_code);
3297 *cmp_code = in_code;
3303 /* Emit the common code for doing conditional branches.
3304 operand[0] is the label to jump to.
3305 The comparison operands are saved away by cmp{si,di,sf,df}. */
3308 gen_conditional_branch (operands, test_code)
3310 enum rtx_code test_code;
3312 enum cmp_type type = branch_type;
3313 rtx cmp0 = branch_cmp[0];
3314 rtx cmp1 = branch_cmp[1];
3315 enum machine_mode mode;
3316 enum rtx_code cmp_code;
3325 mode = type == CMP_SI ? SImode : DImode;
3327 reg = gen_int_relational (test_code, NULL_RTX, cmp0, cmp1, &invert);
3335 else if (GET_CODE (cmp1) == CONST_INT && INTVAL (cmp1) != 0)
3336 /* We don't want to build a comparison against a nonzero
3338 cmp1 = force_reg (mode, cmp1);
3345 reg = gen_rtx_REG (CCmode, FPSW_REGNUM);
3347 reg = gen_reg_rtx (CCmode);
3349 get_float_compare_codes (test_code, &cmp_code, &test_code);
3350 emit_insn (gen_rtx_SET (VOIDmode, reg,
3351 gen_rtx (cmp_code, CCmode, cmp0, cmp1)));
3360 abort_with_insn (gen_rtx (test_code, VOIDmode, cmp0, cmp1), "bad test");
3363 /* Generate the branch. */
3365 label1 = gen_rtx_LABEL_REF (VOIDmode, operands[0]);
3374 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3375 gen_rtx_IF_THEN_ELSE (VOIDmode,
3376 gen_rtx (test_code, mode,
3381 /* Emit the common code for conditional moves. OPERANDS is the array
3382 of operands passed to the conditional move defined_expand. */
3385 gen_conditional_move (operands)
3388 rtx op0 = branch_cmp[0];
3389 rtx op1 = branch_cmp[1];
3390 enum machine_mode mode = GET_MODE (branch_cmp[0]);
3391 enum rtx_code cmp_code = GET_CODE (operands[1]);
3392 enum rtx_code move_code = NE;
3393 enum machine_mode op_mode = GET_MODE (operands[0]);
3394 enum machine_mode cmp_mode;
3397 if (GET_MODE_CLASS (mode) != MODE_FLOAT)
3416 op0 = force_reg (mode, branch_cmp[1]);
3417 op1 = branch_cmp[0];
3421 op0 = force_reg (mode, branch_cmp[1]);
3422 op1 = branch_cmp[0];
3433 op0 = force_reg (mode, branch_cmp[1]);
3434 op1 = branch_cmp[0];
3438 op0 = force_reg (mode, branch_cmp[1]);
3439 op1 = branch_cmp[0];
3447 get_float_compare_codes (cmp_code, &cmp_code, &move_code);
3449 if (mode == SImode || mode == DImode)
3451 else if (mode == SFmode || mode == DFmode)
3456 cmp_reg = gen_reg_rtx (cmp_mode);
3457 emit_insn (gen_rtx_SET (cmp_mode, cmp_reg,
3458 gen_rtx (cmp_code, cmp_mode, op0, op1)));
3460 emit_insn (gen_rtx_SET (op_mode, operands[0],
3461 gen_rtx_IF_THEN_ELSE (op_mode,
3462 gen_rtx (move_code, VOIDmode,
3464 CONST0_RTX (SImode)),
3465 operands[2], operands[3])));
3468 /* Emit the common code for conditional moves. OPERANDS is the array
3469 of operands passed to the conditional move defined_expand. */
3472 mips_gen_conditional_trap (operands)
3476 enum rtx_code cmp_code = GET_CODE (operands[0]);
3477 enum machine_mode mode = GET_MODE (branch_cmp[0]);
3479 /* MIPS conditional trap machine instructions don't have GT or LE
3480 flavors, so we must invert the comparison and convert to LT and
3481 GE, respectively. */
3484 case GT: cmp_code = LT; break;
3485 case LE: cmp_code = GE; break;
3486 case GTU: cmp_code = LTU; break;
3487 case LEU: cmp_code = GEU; break;
3490 if (cmp_code == GET_CODE (operands[0]))
3492 op0 = force_reg (mode, branch_cmp[0]);
3493 op1 = branch_cmp[1];