1 /* Subroutines used for code generation on the Mitsubishi M32R cpu.
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 #include "hard-reg-set.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-flags.h"
32 #include "insn-attr.h"
37 /* Save the operands last given to a compare for use when we
38 generate a scc or bcc insn. */
39 rtx m32r_compare_op0, m32r_compare_op1;
41 /* Array of valid operand punctuation characters. */
42 char m32r_punct_chars[256];
44 /* Selected code model. */
45 char *m32r_model_string = M32R_MODEL_DEFAULT;
46 enum m32r_model m32r_model;
48 /* Selected SDA support. */
49 char *m32r_sdata_string = M32R_SDATA_DEFAULT;
50 enum m32r_sdata m32r_sdata;
53 /* Forward declaration. */
54 static void init_reg_tables PROTO((void));
56 /* Called by OVERRIDE_OPTIONS to initialize various things. */
63 /* Initialize array for PRINT_OPERAND_PUNCT_VALID_P. */
64 memset (m32r_punct_chars, 0, sizeof (m32r_punct_chars));
65 m32r_punct_chars['#'] = 1;
66 m32r_punct_chars['@'] = 1; /* ??? no longer used */
68 /* Provide default value if not specified. */
70 g_switch_value = SDATA_DEFAULT_SIZE;
72 if (strcmp (m32r_model_string, "small") == 0)
73 m32r_model = M32R_MODEL_SMALL;
74 else if (strcmp (m32r_model_string, "medium") == 0)
75 m32r_model = M32R_MODEL_MEDIUM;
76 else if (strcmp (m32r_model_string, "large") == 0)
77 m32r_model = M32R_MODEL_LARGE;
79 error ("bad value (%s) for -mmodel switch", m32r_model_string);
81 if (strcmp (m32r_sdata_string, "none") == 0)
82 m32r_sdata = M32R_SDATA_NONE;
83 else if (strcmp (m32r_sdata_string, "sdata") == 0)
84 m32r_sdata = M32R_SDATA_SDATA;
85 else if (strcmp (m32r_sdata_string, "use") == 0)
86 m32r_sdata = M32R_SDATA_USE;
88 error ("bad value (%s) for -msdata switch", m32r_sdata_string);
92 /* Vectors to keep interesting information about registers where it can easily
93 be got. We use to use the actual mode value as the bit number, but there
94 is (or may be) more than 32 modes now. Instead we use two tables: one
95 indexed by hard register number, and one indexed by mode. */
97 /* The purpose of m32r_mode_class is to shrink the range of modes so that
98 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
99 mapped into one m32r_mode_class mode. */
104 S_MODE, D_MODE, T_MODE, O_MODE,
105 SF_MODE, DF_MODE, TF_MODE, OF_MODE
108 /* Modes for condition codes. */
109 #define C_MODES (1 << (int) C_MODE)
111 /* Modes for single-word and smaller quantities. */
112 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
114 /* Modes for double-word and smaller quantities. */
115 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
117 /* Modes for quad-word and smaller quantities. */
118 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
121 /* Value is 1 if register/mode pair is acceptable on arc. */
123 unsigned int m32r_hard_regno_mode_ok[FIRST_PSEUDO_REGISTER] =
125 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES,
126 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, S_MODES, S_MODES, S_MODES,
130 unsigned int m32r_mode_class [NUM_MACHINE_MODES];
132 enum reg_class m32r_regno_reg_class[FIRST_PSEUDO_REGISTER];
139 for (i = 0; i < NUM_MACHINE_MODES; i++)
141 switch (GET_MODE_CLASS (i))
144 case MODE_PARTIAL_INT:
145 case MODE_COMPLEX_INT:
146 if (GET_MODE_SIZE (i) <= 4)
147 m32r_mode_class[i] = 1 << (int) S_MODE;
148 else if (GET_MODE_SIZE (i) == 8)
149 m32r_mode_class[i] = 1 << (int) D_MODE;
150 else if (GET_MODE_SIZE (i) == 16)
151 m32r_mode_class[i] = 1 << (int) T_MODE;
152 else if (GET_MODE_SIZE (i) == 32)
153 m32r_mode_class[i] = 1 << (int) O_MODE;
155 m32r_mode_class[i] = 0;
158 case MODE_COMPLEX_FLOAT:
159 if (GET_MODE_SIZE (i) <= 4)
160 m32r_mode_class[i] = 1 << (int) SF_MODE;
161 else if (GET_MODE_SIZE (i) == 8)
162 m32r_mode_class[i] = 1 << (int) DF_MODE;
163 else if (GET_MODE_SIZE (i) == 16)
164 m32r_mode_class[i] = 1 << (int) TF_MODE;
165 else if (GET_MODE_SIZE (i) == 32)
166 m32r_mode_class[i] = 1 << (int) OF_MODE;
168 m32r_mode_class[i] = 0;
172 /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so
173 we must explicitly check for them here. */
174 if (i == (int) CCmode)
175 m32r_mode_class[i] = 1 << (int) C_MODE;
177 m32r_mode_class[i] = 0;
182 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
185 m32r_regno_reg_class[i] = GENERAL_REGS;
186 else if (i == ARG_POINTER_REGNUM)
187 m32r_regno_reg_class[i] = GENERAL_REGS;
189 m32r_regno_reg_class[i] = NO_REGS;
193 /* M32R specific attribute support.
195 interrupt - for interrupt functions
197 model - select code model used to access object
199 small: addresses use 24 bits, use bl to make calls
200 medium: addresses use 32 bits, use bl to make calls
201 large: addresses use 32 bits, use seth/add3/jl to make calls
203 Grep for MODEL in m32r.h for more info.
206 /* Return nonzero if IDENTIFIER is a valid decl attribute. */
209 m32r_valid_machine_decl_attribute (type, attributes, identifier, args)
215 static tree interrupt_ident, model_ident;
216 static tree small_ident, medium_ident, large_ident;
218 if (interrupt_ident == 0)
220 interrupt_ident = get_identifier ("__interrupt__");
221 model_ident = get_identifier ("__model__");
222 small_ident = get_identifier ("__small__");
223 medium_ident = get_identifier ("__medium__");
224 large_ident = get_identifier ("__large__");
227 if (identifier == interrupt_ident
228 && list_length (args) == 0)
231 if (identifier == model_ident
232 && list_length (args) == 1
233 && (TREE_VALUE (args) == small_ident
234 || TREE_VALUE (args) == medium_ident
235 || TREE_VALUE (args) == large_ident))
241 /* Return zero if TYPE1 and TYPE are incompatible, one if they are compatible,
242 and two if they are nearly compatible (which causes a warning to be
246 m32r_comp_type_attributes (type1, type2)
252 /* Set the default attributes for TYPE. */
255 m32r_set_default_type_attributes (type)
260 /* A C statement or statements to switch to the appropriate
261 section for output of DECL. DECL is either a `VAR_DECL' node
262 or a constant of some sort. RELOC indicates whether forming
263 the initial value of DECL requires link-time relocations. */
266 m32r_select_section (decl, reloc)
270 if (TREE_CODE (decl) == STRING_CST)
272 if (! flag_writable_strings)
277 else if (TREE_CODE (decl) == VAR_DECL)
279 if (SDATA_NAME_P (XSTR (XEXP (DECL_RTL (decl), 0), 0)))
281 else if ((flag_pic && reloc)
282 || !TREE_READONLY (decl)
283 || TREE_SIDE_EFFECTS (decl)
284 || !DECL_INITIAL (decl)
285 || (DECL_INITIAL (decl) != error_mark_node
286 && !TREE_CONSTANT (DECL_INITIAL (decl))))
295 /* Encode section information of DECL, which is either a VAR_DECL,
296 FUNCTION_DECL, STRING_CST, CONSTRUCTOR, or ???.
298 For the M32R we want to record:
300 - whether the object lives in .sdata/.sbss.
301 objects living in .sdata/.sbss are prefixed with SDATA_FLAG_CHAR
303 - what code model should be used to access the object
304 small: recorded with no flag - for space efficiency since they'll
306 medium: prefixed with MEDIUM_FLAG_CHAR
307 large: prefixed with LARGE_FLAG_CHAR
311 m32r_encode_section_info (decl)
317 switch (TREE_CODE (decl))
321 model = lookup_attribute ("model", DECL_MACHINE_ATTRIBUTES (decl));
325 /* ??? document all others that can appear here */
330 /* Only mark the object as being small data area addressable if
331 it hasn't been explicitly marked with a code model.
333 The user can explicitly put an object in the small data area with the
334 section attribute. If the object is in sdata/sbss and marked with a
335 code model do both [put the object in .sdata and mark it as being
336 addressed with a specific code model - don't mark it as being addressed
337 with an SDA reloc though]. This is ok and might be useful at times. If
338 the object doesn't fit the linker will give an error. */
342 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
343 && DECL_SECTION_NAME (decl) != NULL_TREE)
345 char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
346 if (! strcmp (name, ".sdata") || ! strcmp (name, ".sbss"))
348 #if 0 /* ??? There's no reason to disallow this, is there? */
349 if (TREE_READONLY (decl))
350 error_with_decl (decl, "const objects cannot go in .sdata/.sbss");
352 prefix = SDATA_FLAG_CHAR;
357 if (TREE_CODE (decl) == VAR_DECL
358 && ! TREE_READONLY (decl)
359 && ! TARGET_SDATA_NONE)
361 int size = int_size_in_bytes (TREE_TYPE (decl));
363 if (size > 0 && size <= g_switch_value)
364 prefix = SDATA_FLAG_CHAR;
369 /* If data area not decided yet, check for a code model. */
374 if (TREE_VALUE (TREE_VALUE (model)) == get_identifier ("__small__"))
375 ; /* don't mark the symbol specially */
376 else if (TREE_VALUE (TREE_VALUE (model)) == get_identifier ("__medium__"))
377 prefix = MEDIUM_FLAG_CHAR;
378 else if (TREE_VALUE (TREE_VALUE (model)) == get_identifier ("__large__"))
379 prefix = LARGE_FLAG_CHAR;
381 abort (); /* shouldn't happen */
385 if (TARGET_MODEL_SMALL)
386 ; /* don't mark the symbol specially */
387 else if (TARGET_MODEL_MEDIUM)
388 prefix = MEDIUM_FLAG_CHAR;
389 else if (TARGET_MODEL_LARGE)
390 prefix = LARGE_FLAG_CHAR;
392 abort (); /* shouldn't happen */
398 rtx rtl = (TREE_CODE_CLASS (TREE_CODE (decl)) != 'd'
399 ? TREE_CST_RTL (decl) : DECL_RTL (decl));
400 char *str = XSTR (XEXP (rtl, 0), 0);
401 int len = strlen (str);
402 char *newstr = savealloc (len + 2);
403 strcpy (newstr + 1, str);
405 XSTR (XEXP (rtl, 0), 0) = newstr;
409 /* Do anything needed before RTL is emitted for each function. */
412 m32r_init_expanders ()
414 /* ??? At one point there was code here. The function is left in
415 to make it easy to experiment. */
418 /* Acceptable arguments to the call insn. */
421 call_address_operand (op, int_mode)
425 return symbolic_operand (op, int_mode);
427 /* Constants and values in registers are not OK, because
428 the m32r BL instruction can only support PC relative branching. */
432 call_operand (op, int_mode)
436 enum machine_mode mode = (enum machine_mode)int_mode;
438 if (GET_CODE (op) != MEM)
441 return call_address_operand (op, mode);
444 /* Returns 1 if OP is a symbol reference. */
447 symbolic_operand (op, int_mode)
451 switch (GET_CODE (op))
463 /* Return 1 if OP is a reference to an object in .sdata/.sbss. */
466 small_data_operand (op, int_mode)
470 if (! TARGET_SDATA_USE)
473 if (GET_CODE (op) == SYMBOL_REF)
474 return SDATA_NAME_P (XSTR (op, 0));
476 if (GET_CODE (op) == CONST
477 && GET_CODE (XEXP (op, 0)) == PLUS
478 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
479 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
480 && INT16_P (INTVAL (XEXP (XEXP (op, 0), 1))))
481 return SDATA_NAME_P (XSTR (XEXP (XEXP (op, 0), 0), 0));
486 /* Return 1 if OP is a symbol that can use 24 bit addressing. */
489 addr24_operand (op, int_mode)
493 if (GET_CODE (op) == LABEL_REF)
494 return TARGET_ADDR24;
496 if (GET_CODE (op) == SYMBOL_REF)
497 return (SMALL_NAME_P (XSTR (op, 0))
499 && (CONSTANT_POOL_ADDRESS_P (op)
500 || LIT_NAME_P (XSTR (op, 0)))));
502 if (GET_CODE (op) == CONST
503 && GET_CODE (XEXP (op, 0)) == PLUS
504 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
505 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
506 && UINT24_P (INTVAL (XEXP (XEXP (op, 0), 1))))
508 rtx sym = XEXP (XEXP (op, 0), 0);
509 return (SMALL_NAME_P (XSTR (sym, 0))
511 && (CONSTANT_POOL_ADDRESS_P (op)
512 || LIT_NAME_P (XSTR (op, 0)))));
518 /* Return 1 if OP is a symbol that needs 32 bit addressing. */
521 addr32_operand (op, int_mode)
525 if (GET_CODE (op) == LABEL_REF)
526 return TARGET_ADDR32;
528 if (GET_CODE (op) == SYMBOL_REF)
529 return (! addr24_operand (op, int_mode)
530 && ! small_data_operand (op, int_mode));
532 if (GET_CODE (op) == CONST
533 && GET_CODE (XEXP (op, 0)) == PLUS
534 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
535 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
537 return (! addr24_operand (op, int_mode)
538 && ! small_data_operand (op, int_mode));
544 /* Return 1 if OP is a function that can be called with the `bl' insn. */
547 call26_operand (op, int_mode)
551 if (GET_CODE (op) == SYMBOL_REF)
552 return ! LARGE_NAME_P (XSTR (op, 0));
554 return TARGET_CALL26;
557 /* Returns 1 if OP is an acceptable operand for seth/add3. */
560 seth_add3_operand (op, int_mode)
564 if (GET_CODE (op) == SYMBOL_REF
565 || GET_CODE (op) == LABEL_REF)
568 if (GET_CODE (op) == CONST
569 && GET_CODE (XEXP (op, 0)) == PLUS
570 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
571 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
572 && INT16_P (INTVAL (XEXP (XEXP (op, 0), 1))))
578 /* Return true if OP is a signed 16 bit immediate value
579 useful in comparisons. */
582 cmp_int16_operand (op, int_mode)
586 if (GET_CODE (op) != CONST_INT)
588 return CMP_INT16_P (INTVAL (op));
591 /* Return true if OP is an unsigned 16 bit immediate value. */
594 uint16_operand (op, int_mode)
598 if (GET_CODE (op) != CONST_INT)
600 return UINT16_P (INTVAL (op));
603 /* Return true if OP is a register or signed 8 bit value. */
606 reg_or_int16_operand (op, int_mode)
610 enum machine_mode mode = (enum machine_mode)int_mode;
612 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
613 return register_operand (op, mode);
614 if (GET_CODE (op) != CONST_INT)
616 return INT16_P (INTVAL (op));
619 /* Return true if OP is a register or an unsigned 16 bit value. */
622 reg_or_uint16_operand (op, int_mode)
626 enum machine_mode mode = (enum machine_mode)int_mode;
628 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
629 return register_operand (op, mode);
630 if (GET_CODE (op) != CONST_INT)
632 return UINT16_P (INTVAL (op));
635 /* Return true if OP is a register or signed 16 bit value for compares. */
638 reg_or_cmp_int16_operand (op, int_mode)
642 enum machine_mode mode = (enum machine_mode)int_mode;
644 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
645 return register_operand (op, mode);
646 if (GET_CODE (op) != CONST_INT)
648 return CMP_INT16_P (INTVAL (op));
651 /* Return true if OP is a const_int requiring two instructions to load. */
654 two_insn_const_operand (op, int_mode)
658 if (GET_CODE (op) != CONST_INT)
660 if (INT16_P (INTVAL (op))
661 || UINT24_P (INTVAL (op))
662 || UPPER16_P (INTVAL (op)))
667 /* Return true if OP is an acceptable argument for a single word
671 move_src_operand (op, int_mode)
675 enum machine_mode mode = (enum machine_mode)int_mode;
676 switch (GET_CODE (op))
680 return addr24_operand (op, int_mode);
682 /* ??? We allow more cse opportunities if we only allow constants
683 loadable with one insn, and split the rest into two. The instances
684 where this would help should be rare and the current way is
686 return INT32_P (INTVAL (op));
688 return TARGET_ADDR24;
692 else if (mode == SImode)
694 /* Large unsigned constants are represented as const_double's. */
695 unsigned HOST_WIDE_INT low, high;
697 low = CONST_DOUBLE_LOW (op);
698 high = CONST_DOUBLE_HIGH (op);
699 return high == 0 && low <= 0xffffffff;
704 return register_operand (op, mode);
706 /* (subreg (mem ...) ...) can occur here if the inner part was once a
707 pseudo-reg and is now a stack slot. */
708 if (GET_CODE (SUBREG_REG (op)) == MEM)
709 return address_operand (XEXP (SUBREG_REG (op), 0), mode);
711 return register_operand (op, mode);
713 return address_operand (XEXP (op, 0), mode);
719 /* Return true if OP is an acceptable argument for a double word
723 move_double_src_operand (op, int_mode)
727 enum machine_mode mode = (enum machine_mode)int_mode;
728 switch (GET_CODE (op))
734 return register_operand (op, mode);
736 /* (subreg (mem ...) ...) can occur here if the inner part was once a
737 pseudo-reg and is now a stack slot. */
738 if (GET_CODE (SUBREG_REG (op)) == MEM)
739 return move_double_src_operand (SUBREG_REG (op), int_mode);
741 return register_operand (op, mode);
743 /* Disallow auto inc/dec for now. */
744 if (GET_CODE (XEXP (op, 0)) == PRE_DEC
745 || GET_CODE (XEXP (op, 0)) == PRE_INC)
747 return address_operand (XEXP (op, 0), mode);
753 /* Return true if OP is an acceptable argument for a move destination. */
756 move_dest_operand (op, int_mode)
760 enum machine_mode mode = (enum machine_mode)int_mode;
761 switch (GET_CODE (op))
764 return register_operand (op, mode);
766 /* (subreg (mem ...) ...) can occur here if the inner part was once a
767 pseudo-reg and is now a stack slot. */
768 if (GET_CODE (SUBREG_REG (op)) == MEM)
769 return address_operand (XEXP (SUBREG_REG (op), 0), mode);
771 return register_operand (op, mode);
773 return address_operand (XEXP (op, 0), mode);
779 /* Return 1 if OP is a DImode const we want to handle inline.
780 This must match the code in the movdi pattern.
781 It is used by the 'G' CONST_DOUBLE_OK_FOR_LETTER. */
787 rtx high_rtx, low_rtx;
788 HOST_WIDE_INT high, low;
790 split_double (op, &high_rtx, &low_rtx);
791 high = INTVAL (high_rtx);
792 low = INTVAL (low_rtx);
793 /* Pick constants loadable with 2 16 bit `ldi' insns. */
794 if (high >= -128 && high <= 127
795 && low >= -128 && low <= 127)
800 /* Return 1 if OP is a DFmode const we want to handle inline.
801 This must match the code in the movdf pattern.
802 It is used by the 'H' CONST_DOUBLE_OK_FOR_LETTER. */
811 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
812 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
813 if (l[0] == 0 && l[1] == 0)
815 if ((l[0] & 0xffff) == 0 && l[1] == 0)
820 /* Return 1 if OP is an EQ or NE comparison operator. */
823 eqne_comparison_operator (op, int_mode)
827 enum rtx_code code = GET_CODE (op);
829 if (GET_RTX_CLASS (code) != '<')
831 return (code == EQ || code == NE);
834 /* Return 1 if OP is a signed comparison operator. */
837 signed_comparison_operator (op, int_mode)
841 enum rtx_code code = GET_CODE (op);
843 if (GET_RTX_CLASS (code) != '<')
845 return (code == EQ || code == NE
846 || code == LT || code == LE || code == GT || code == GE);
849 /* Return 1 if OP is (mem (reg ...)).
850 This is used in insn length calcs. */
853 memreg_operand (op, int_mode)
857 return GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) == REG;
860 /* Return non-zero if the operand is an insn that is a small insn.
861 Allow const_int 0 as well, which is a placeholder for NOP slots. */
864 small_insn_p (op, int_mode)
868 if (GET_CODE (op) == CONST_INT && INTVAL (op) == 0)
871 if (GET_RTX_CLASS (GET_CODE (op)) != 'i')
874 return get_attr_length (op) == 2;
877 /* Return non-zero if the operand is an insn that is a large insn. */
880 large_insn_p (op, int_mode)
884 if (GET_RTX_CLASS (GET_CODE (op)) != 'i')
887 return get_attr_length (op) != 2;
893 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
894 return the mode to be used for the comparison. */
897 m32r_select_cc_mode (op, x, y)
904 /* X and Y are two things to compare using CODE. Emit the compare insn and
905 return the rtx for compare [arg0 of the if_then_else].
906 If need_compare is true then the comparison insn must be generated, rather
907 than being susummed into the following branch instruction. */
910 gen_compare (int_code, x, y, need_compare)
916 enum rtx_code code = (enum rtx_code)int_code;
917 enum rtx_code compare_code;
918 enum rtx_code branch_code;
919 enum machine_mode mode = SELECT_CC_MODE (code, x, y);
920 rtx cc_reg = gen_rtx (REG, mode, CARRY_REGNUM);
925 case EQ: compare_code = EQ; branch_code = NE; break;
926 case NE: compare_code = EQ; branch_code = EQ; break;
927 case LT: compare_code = LT; branch_code = NE; break;
928 case LE: compare_code = LT; branch_code = EQ; must_swap = 1; break;
929 case GT: compare_code = LT; branch_code = NE; must_swap = 1; break;
930 case GE: compare_code = LT; branch_code = EQ; break;
931 case LTU: compare_code = LTU; branch_code = NE; break;
932 case LEU: compare_code = LTU; branch_code = EQ; must_swap = 1; break;
933 case GTU: compare_code = LTU; branch_code = NE; must_swap = 1; break;
934 case GEU: compare_code = LTU; branch_code = EQ; break;
939 switch (compare_code)
942 if (GET_CODE (y) == CONST_INT
943 && CMP_INT16_P (INTVAL (y)) /* reg equal to small const. */
946 rtx tmp = gen_reg_rtx (SImode);
948 emit_insn (gen_cmp_ne_small_const_insn (tmp, x, y));
952 else if (CONSTANT_P (y)) /* reg equal to const. */
954 rtx tmp = force_reg (GET_MODE (x), y);
958 if (register_operand (y, SImode) /* reg equal to reg. */
959 || y == const0_rtx) /* req equal to zero. */
961 emit_insn (gen_cmp_eqsi_insn (x, y));
963 return gen_rtx (code, mode, cc_reg, const0_rtx);
968 if (register_operand (y, SImode)
969 || (GET_CODE (y) == CONST_INT && CMP_INT16_P (INTVAL (y))))
971 rtx tmp = gen_reg_rtx (SImode); /* reg compared to reg. */
976 emit_insn (gen_cmp_ltsi_insn (x, y));
983 emit_insn (gen_cmp_ne_small_const_insn (tmp, y, const1_rtx));
984 emit_insn (gen_cmp_ltsi_insn (x, tmp));
988 if (GET_CODE (y) == CONST_INT)
989 tmp = gen_rtx (PLUS, SImode, y, const1_rtx);
991 emit_insn (gen_cmp_ne_small_const_insn (tmp, y, const1_rtx));
992 emit_insn (gen_cmp_ltsi_insn (x, tmp));
996 emit_insn (gen_cmp_ltsi_insn (x, y));
1003 return gen_rtx (code, mode, cc_reg, const0_rtx);
1008 if (register_operand (y, SImode)
1009 || (GET_CODE (y) == CONST_INT && CMP_INT16_P (INTVAL (y))))
1011 rtx tmp = gen_reg_rtx (SImode); /* reg (unsigned) compared to reg. */
1016 emit_insn (gen_cmp_ltusi_insn (x, y));
1020 if (y == const0_rtx)
1023 emit_insn (gen_cmp_ne_small_const_insn (tmp, y, const1_rtx));
1024 emit_insn (gen_cmp_ltusi_insn (x, tmp));
1028 if (GET_CODE (y) == CONST_INT)
1029 tmp = gen_rtx (PLUS, SImode, y, const1_rtx);
1031 emit_insn (gen_cmp_ne_small_const_insn (tmp, y, const1_rtx));
1032 emit_insn (gen_cmp_ltusi_insn (x, tmp));
1036 emit_insn (gen_cmp_ltusi_insn (x, y));
1043 return gen_rtx (code, mode, cc_reg, const0_rtx);
1052 if (! TARGET_OLD_COMPARE)
1054 /* reg/reg equal comparison */
1055 if (compare_code == EQ
1056 && register_operand (y, SImode))
1057 return gen_rtx (code, mode, x, y);
1059 /* reg/zero signed comparison */
1060 if ((compare_code == EQ || compare_code == LT)
1062 return gen_rtx (code, mode, x, y);
1064 /* reg/smallconst equal comparison */
1065 if (compare_code == EQ
1066 && GET_CODE (y) == CONST_INT
1067 && CMP_INT16_P (INTVAL (y)))
1069 rtx tmp = gen_reg_rtx (SImode);
1070 emit_insn (gen_cmp_ne_small_const_insn (tmp, x, y));
1071 return gen_rtx (code, mode, tmp, const0_rtx);
1074 /* reg/const equal comparison */
1075 if (compare_code == EQ
1078 rtx tmp = force_reg (GET_MODE (x), y);
1079 return gen_rtx (code, mode, x, tmp);
1086 y = force_reg (GET_MODE (x), y);
1090 (code == LTU || code == LEU || code == GTU || code == GEU)
1091 ? uint16_operand (y, GET_MODE (y))
1092 : reg_or_cmp_int16_operand (y, GET_MODE (y));
1095 y = force_reg (GET_MODE (x), y);
1099 switch (compare_code)
1102 emit_insn (gen_cmp_eqsi_insn (must_swap ? y : x, must_swap ? x : y));
1105 emit_insn (gen_cmp_ltsi_insn (must_swap ? y : x, must_swap ? x : y));
1108 emit_insn (gen_cmp_ltusi_insn (must_swap ? y : x, must_swap ? x : y));
1112 return gen_rtx (branch_code, VOIDmode, cc_reg, CONST0_RTX (mode));
1115 /* Split a 2 word move (DI or DF) into component parts. */
1118 gen_split_move_double (operands)
1121 enum machine_mode mode = GET_MODE (operands[0]);
1122 rtx dest = operands[0];
1123 rtx src = operands[1];
1126 /* We might have (SUBREG (MEM)) here, so just get rid of the
1127 subregs to make this code simpler. It is safe to call
1128 alter_subreg any time after reload. */
1129 if (GET_CODE (dest) == SUBREG)
1130 dest = alter_subreg (dest);
1131 if (GET_CODE (src) == SUBREG)
1132 src = alter_subreg (src);
1135 if (GET_CODE (dest) == REG)
1137 int dregno = REGNO (dest);
1140 if (GET_CODE (src) == REG)
1142 int sregno = REGNO (src);
1144 int reverse = (dregno == sregno + 1);
1146 /* We normally copy the low-numbered register first. However, if
1147 the first register operand 0 is the same as the second register of
1148 operand 1, we must copy in the opposite order. */
1149 emit_insn (gen_rtx_SET (VOIDmode,
1150 operand_subword (dest, reverse, TRUE, mode),
1151 operand_subword (src, reverse, TRUE, mode)));
1153 emit_insn (gen_rtx_SET (VOIDmode,
1154 operand_subword (dest, !reverse, TRUE, mode),
1155 operand_subword (src, !reverse, TRUE, mode)));
1158 /* reg = constant */
1159 else if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
1162 split_double (src, &words[0], &words[1]);
1163 emit_insn (gen_rtx_SET (VOIDmode,
1164 operand_subword (dest, 0, TRUE, mode),
1167 emit_insn (gen_rtx_SET (VOIDmode,
1168 operand_subword (dest, 1, TRUE, mode),
1173 else if (GET_CODE (src) == MEM)
1175 /* If the high-address word is used in the address, we must load it
1176 last. Otherwise, load it first. */
1177 rtx addr = XEXP (src, 0);
1178 int reverse = (refers_to_regno_p (dregno, dregno+1, addr, 0) != 0);
1180 /* We used to optimize loads from single registers as
1184 if r3 were not used subsequently. However, the REG_NOTES aren't
1185 propigated correctly by the reload phase, and it can cause bad
1186 code to be generated. We could still try:
1188 ld r1,r3+; ld r2,r3; addi r3,-4
1190 which saves 2 bytes and doesn't force longword alignment. */
1191 emit_insn (gen_rtx_SET (VOIDmode,
1192 operand_subword (dest, reverse, TRUE, mode),
1193 change_address (src, SImode,
1194 plus_constant (addr,
1195 reverse * UNITS_PER_WORD))));
1197 emit_insn (gen_rtx_SET (VOIDmode,
1198 operand_subword (dest, !reverse, TRUE, mode),
1199 change_address (src, SImode,
1200 plus_constant (addr,
1201 (!reverse) * UNITS_PER_WORD))));
1209 /* We used to optimize loads from single registers as
1213 if r3 were not used subsequently. However, the REG_NOTES aren't
1214 propigated correctly by the reload phase, and it can cause bad
1215 code to be generated. We could still try:
1217 st r1,r3; st r2,+r3; addi r3,-4
1219 which saves 2 bytes and doesn't force longword alignment. */
1220 else if (GET_CODE (dest) == MEM && GET_CODE (src) == REG)
1222 rtx addr = XEXP (dest, 0);
1224 emit_insn (gen_rtx_SET (VOIDmode,
1225 change_address (dest, SImode, addr),
1226 operand_subword (src, 0, TRUE, mode)));
1228 emit_insn (gen_rtx_SET (VOIDmode,
1229 change_address (dest, SImode,
1230 plus_constant (addr, UNITS_PER_WORD)),
1231 operand_subword (src, 1, TRUE, mode)));
1237 val = gen_sequence ();
1243 /* Implements the FUNCTION_ARG_PARTIAL_NREGS macro. */
1246 function_arg_partial_nregs (cum, int_mode, type, named)
1247 CUMULATIVE_ARGS *cum;
1252 enum machine_mode mode = (enum machine_mode)int_mode;
1254 int size = (((mode == BLKmode && type)
1255 ? int_size_in_bytes (type)
1256 : GET_MODE_SIZE (mode)) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1258 if (*cum >= M32R_MAX_PARM_REGS)
1260 else if (*cum + size > M32R_MAX_PARM_REGS)
1261 ret = (*cum + size) - M32R_MAX_PARM_REGS;
1268 /* Do any needed setup for a variadic function. For the M32R, we must
1269 create a register parameter block, and then copy any anonymous arguments
1270 in registers to memory.
1272 CUM has not been updated for the last named argument which has type TYPE
1273 and mode MODE, and we rely on this fact. */
1276 m32r_setup_incoming_varargs (cum, int_mode, type, pretend_size, no_rtl)
1277 CUMULATIVE_ARGS *cum;
1283 enum machine_mode mode = (enum machine_mode)int_mode;
1289 /* All BLKmode values are passed by reference. */
1290 if (mode == BLKmode)
1293 /* We must treat `__builtin_va_alist' as an anonymous arg. */
1294 if (current_function_varargs)
1295 first_anon_arg = *cum;
1297 first_anon_arg = (ROUND_ADVANCE_CUM (*cum, mode, type)
1298 + ROUND_ADVANCE_ARG (mode, type));
1300 if (first_anon_arg < M32R_MAX_PARM_REGS)
1302 /* Note that first_reg_offset < M32R_MAX_PARM_REGS. */
1303 int first_reg_offset = first_anon_arg;
1304 /* Size in words to "pretend" allocate. */
1305 int size = M32R_MAX_PARM_REGS - first_reg_offset;
1308 regblock = gen_rtx (MEM, BLKmode,
1309 plus_constant (arg_pointer_rtx,
1310 FIRST_PARM_OFFSET (0)));
1311 move_block_from_reg (first_reg_offset, regblock,
1312 size, size * UNITS_PER_WORD);
1314 *pretend_size = (size * UNITS_PER_WORD);
1318 /* Cost functions. */
1320 /* Provide the costs of an addressing mode that contains ADDR.
1321 If ADDR is not a valid address, its cost is irrelevant.
1323 This function is trivial at the moment. This code doesn't live
1324 in m32r.h so it's easy to experiment. */
1327 m32r_address_cost (addr)
1333 /* Type of function DECL.
1335 The result is cached. To reset the cache at the end of a function,
1336 call with DECL = NULL_TREE. */
1338 enum m32r_function_type
1339 m32r_compute_function_type (decl)
1343 static enum m32r_function_type fn_type = M32R_FUNCTION_UNKNOWN;
1344 /* Last function we were called for. */
1345 static tree last_fn = NULL_TREE;
1347 /* Resetting the cached value? */
1348 if (decl == NULL_TREE)
1350 fn_type = M32R_FUNCTION_UNKNOWN;
1351 last_fn = NULL_TREE;
1355 if (decl == last_fn && fn_type != M32R_FUNCTION_UNKNOWN)
1358 /* Compute function type. */
1359 fn_type = (lookup_attribute ("interrupt", DECL_MACHINE_ATTRIBUTES (current_function_decl)) != NULL_TREE
1360 ? M32R_FUNCTION_INTERRUPT
1361 : M32R_FUNCTION_NORMAL);
1366 \f/* Function prologue/epilogue handlers. */
1368 /* M32R stack frames look like:
1370 Before call After call
1371 +-----------------------+ +-----------------------+
1373 high | local variables, | | local variables, |
1374 mem | reg save area, etc. | | reg save area, etc. |
1376 +-----------------------+ +-----------------------+
1378 | arguments on stack. | | arguments on stack. |
1380 SP+0->+-----------------------+ +-----------------------+
1381 | reg parm save area, |
1382 | only created for |
1383 | variable argument |
1385 +-----------------------+
1386 | previous frame ptr |
1387 +-----------------------+
1389 | register save area |
1391 +-----------------------+
1393 +-----------------------+
1397 +-----------------------+
1399 | alloca allocations |
1401 +-----------------------+
1403 low | arguments on stack |
1405 SP+0->+-----------------------+
1408 1) The "reg parm save area" does not exist for non variable argument fns.
1409 2) The "reg parm save area" can be eliminated completely if we saved regs
1410 containing anonymous args separately but that complicates things too
1411 much (so it's not done).
1412 3) The return address is saved after the register save area so as to have as
1413 many insns as possible between the restoration of `lr' and the `jmp lr'.
1416 /* Structure to be filled in by m32r_compute_frame_size with register
1417 save masks, and offsets for the current function. */
1418 struct m32r_frame_info
1420 unsigned int total_size; /* # bytes that the entire frame takes up */
1421 unsigned int extra_size; /* # bytes of extra stuff */
1422 unsigned int pretend_size; /* # bytes we push and pretend caller did */
1423 unsigned int args_size; /* # bytes that outgoing arguments take up */
1424 unsigned int reg_size; /* # bytes needed to store regs */
1425 unsigned int var_size; /* # bytes that variables take up */
1426 unsigned int gmask; /* mask of saved gp registers */
1427 unsigned int save_fp; /* nonzero if fp must be saved */
1428 unsigned int save_lr; /* nonzero if lr (return addr) must be saved */
1429 int initialized; /* nonzero if frame size already calculated */
1432 /* Current frame information calculated by m32r_compute_frame_size. */
1433 static struct m32r_frame_info current_frame_info;
1435 /* Zero structure to initialize current_frame_info. */
1436 static struct m32r_frame_info zero_frame_info;
1438 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
1439 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
1441 /* Tell prologue and epilogue if register REGNO should be saved / restored.
1442 The return address and frame pointer are treated separately.
1443 Don't consider them here. */
1444 #define MUST_SAVE_REGISTER(regno, interrupt_p) \
1445 ((regno) != RETURN_ADDR_REGNUM && (regno) != FRAME_POINTER_REGNUM \
1446 && (regs_ever_live[regno] && (!call_used_regs[regno] || interrupt_p)))
1448 #define MUST_SAVE_FRAME_POINTER (regs_ever_live[FRAME_POINTER_REGNUM])
1449 #define MUST_SAVE_RETURN_ADDR (regs_ever_live[RETURN_ADDR_REGNUM] || profile_flag)
1451 #define SHORT_INSN_SIZE 2 /* size of small instructions */
1452 #define LONG_INSN_SIZE 4 /* size of long instructions */
1454 /* Return the bytes needed to compute the frame pointer from the current
1457 SIZE is the size needed for local variables. */
1460 m32r_compute_frame_size (size)
1461 int size; /* # of var. bytes allocated. */
1464 unsigned int total_size, var_size, args_size, pretend_size, extra_size;
1465 unsigned int reg_size, frame_size;
1467 enum m32r_function_type fn_type;
1470 var_size = M32R_STACK_ALIGN (size);
1471 args_size = M32R_STACK_ALIGN (current_function_outgoing_args_size);
1472 pretend_size = current_function_pretend_args_size;
1473 extra_size = FIRST_PARM_OFFSET (0);
1474 total_size = extra_size + pretend_size + args_size + var_size;
1478 /* See if this is an interrupt handler. Call used registers must be saved
1480 fn_type = m32r_compute_function_type (current_function_decl);
1481 interrupt_p = M32R_INTERRUPT_P (fn_type);
1483 /* Calculate space needed for registers. */
1485 for (regno = 0; regno < M32R_MAX_INT_REGS; regno++)
1487 if (MUST_SAVE_REGISTER (regno, interrupt_p))
1489 reg_size += UNITS_PER_WORD;
1490 gmask |= 1 << regno;
1494 current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
1495 current_frame_info.save_lr = MUST_SAVE_RETURN_ADDR;
1497 reg_size += ((current_frame_info.save_fp + current_frame_info.save_lr)
1499 total_size += reg_size;
1501 /* ??? Not sure this is necessary, and I don't think the epilogue
1502 handler will do the right thing if this changes total_size. */
1503 total_size = M32R_STACK_ALIGN (total_size);
1505 frame_size = total_size - (pretend_size + reg_size);
1507 /* Save computed information. */
1508 current_frame_info.total_size = total_size;
1509 current_frame_info.extra_size = extra_size;
1510 current_frame_info.pretend_size = pretend_size;
1511 current_frame_info.var_size = var_size;
1512 current_frame_info.args_size = args_size;
1513 current_frame_info.reg_size = reg_size;
1514 current_frame_info.gmask = gmask;
1515 current_frame_info.initialized = reload_completed;
1517 /* Ok, we're done. */
1521 /* When the `length' insn attribute is used, this macro specifies the
1522 value to be assigned to the address of the first insn in a
1523 function. If not specified, 0 is used. */
1526 m32r_first_insn_address ()
1528 if (! current_frame_info.initialized)
1529 m32r_compute_frame_size (get_frame_size ());
1534 /* Expand the m32r prologue as a series of insns. */
1537 m32r_expand_prologue ()
1541 unsigned int gmask = current_frame_info.gmask;
1543 if (! current_frame_info.initialized)
1544 m32r_compute_frame_size (get_frame_size ());
1546 gmask = current_frame_info.gmask;
1548 /* These cases shouldn't happen. Catch them now. */
1549 if (current_frame_info.total_size == 0 && gmask)
1552 /* Allocate space for register arguments if this is a variadic function. */
1553 if (current_frame_info.pretend_size != 0)
1554 emit_insn (gen_addsi3 (stack_pointer_rtx,
1556 GEN_INT (-current_frame_info.pretend_size)));
1558 /* Save any registers we need to and set up fp. */
1560 if (current_frame_info.save_fp)
1561 emit_insn (gen_movsi_push (stack_pointer_rtx, frame_pointer_rtx));
1563 gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
1565 /* Save any needed call-saved regs (and call-used if this is an
1566 interrupt handler). */
1567 for (regno = 0; regno <= M32R_MAX_INT_REGS; ++regno)
1569 if ((gmask & (1 << regno)) != 0)
1570 emit_insn (gen_movsi_push (stack_pointer_rtx,
1571 gen_rtx_REG (Pmode, regno)));
1574 if (current_frame_info.save_lr)
1575 emit_insn (gen_movsi_push (stack_pointer_rtx,
1576 gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)));
1578 /* Allocate the stack frame. */
1579 frame_size = (current_frame_info.total_size
1580 - (current_frame_info.pretend_size
1581 + current_frame_info.reg_size));
1583 if (frame_size == 0)
1584 ; /* nothing to do */
1585 else if (frame_size <= 32768)
1586 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1587 GEN_INT (-frame_size)));
1590 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1591 emit_insn (gen_movsi (tmp, GEN_INT (frame_size)));
1592 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
1595 if (frame_pointer_needed)
1596 emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
1598 if (profile_flag || profile_block_flag)
1599 emit_insn (gen_blockage ());
1603 /* Set up the stack and frame pointer (if desired) for the function.
1604 Note, if this is changed, you need to mirror the changes in
1605 m32r_compute_frame_size which calculates the prolog size. */
1608 m32r_output_function_prologue (file, size)
1612 enum m32r_function_type fn_type = m32r_compute_function_type (current_function_decl);
1614 /* If this is an interrupt handler, mark it as such. */
1615 if (M32R_INTERRUPT_P (fn_type))
1617 fprintf (file, "\t%s interrupt handler\n",
1621 if (! current_frame_info.initialized)
1622 m32r_compute_frame_size (size);
1624 /* This is only for the human reader. */
1626 "\t%s PROLOGUE, vars= %d, regs= %d, args= %d, extra= %d\n",
1628 current_frame_info.var_size,
1629 current_frame_info.reg_size / 4,
1630 current_frame_info.args_size,
1631 current_frame_info.extra_size);
1634 /* Do any necessary cleanup after a function to restore stack, frame,
1638 m32r_output_function_epilogue (file, size)
1643 int noepilogue = FALSE;
1645 enum m32r_function_type fn_type = m32r_compute_function_type (current_function_decl);
1647 /* This is only for the human reader. */
1648 fprintf (file, "\t%s EPILOGUE\n", ASM_COMMENT_START);
1650 if (!current_frame_info.initialized)
1652 total_size = current_frame_info.total_size;
1654 if (total_size == 0)
1656 rtx insn = get_last_insn ();
1658 /* If the last insn was a BARRIER, we don't have to write any code
1659 because a jump (aka return) was put there. */
1660 if (GET_CODE (insn) == NOTE)
1661 insn = prev_nonnote_insn (insn);
1662 if (insn && GET_CODE (insn) == BARRIER)
1668 unsigned int pretend_size = current_frame_info.pretend_size;
1669 unsigned int frame_size = total_size - pretend_size;
1670 unsigned int var_size = current_frame_info.var_size;
1671 unsigned int args_size = current_frame_info.args_size;
1672 unsigned int gmask = current_frame_info.gmask;
1673 int can_trust_sp_p = !current_function_calls_alloca;
1674 char * sp_str = reg_names[STACK_POINTER_REGNUM];
1675 char * fp_str = reg_names[FRAME_POINTER_REGNUM];
1677 /* The first thing to do is point the sp at the bottom of the register
1681 unsigned int reg_offset = var_size + args_size;
1682 if (reg_offset == 0)
1683 ; /* nothing to do */
1684 else if (reg_offset < 128)
1685 fprintf (file, "\taddi %s,%s%d\n",
1686 sp_str, IMMEDIATE_PREFIX, reg_offset);
1687 else if (reg_offset < 32768)
1688 fprintf (file, "\tadd3 %s,%s,%s%d\n",
1689 sp_str, sp_str, IMMEDIATE_PREFIX, reg_offset);
1691 fprintf (file, "\tld24 %s,%s%d\n\tadd %s,%s\n",
1692 reg_names[PROLOGUE_TMP_REGNUM],
1693 IMMEDIATE_PREFIX, reg_offset,
1694 sp_str, reg_names[PROLOGUE_TMP_REGNUM]);
1696 else if (frame_pointer_needed)
1698 unsigned int reg_offset = var_size + args_size;
1699 if (reg_offset == 0)
1700 fprintf (file, "\tmv %s,%s\n", sp_str, fp_str);
1701 else if (reg_offset < 32768)
1702 fprintf (file, "\tadd3 %s,%s,%s%d\n",
1703 sp_str, fp_str, IMMEDIATE_PREFIX, reg_offset);
1705 fprintf (file, "\tld24 %s,%s%d\n\tadd %s,%s\n",
1706 reg_names[PROLOGUE_TMP_REGNUM],
1707 IMMEDIATE_PREFIX, reg_offset,
1708 sp_str, reg_names[PROLOGUE_TMP_REGNUM]);
1713 if (current_frame_info.save_lr)
1714 fprintf (file, "\tpop %s\n", reg_names[RETURN_ADDR_REGNUM]);
1716 /* Restore any saved registers, in reverse order of course. */
1717 gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
1718 for (regno = M32R_MAX_INT_REGS - 1; regno >= 0; --regno)
1720 if ((gmask & (1L << regno)) != 0)
1721 fprintf (file, "\tpop %s\n", reg_names[regno]);
1724 if (current_frame_info.save_fp)
1725 fprintf (file, "\tpop %s\n", fp_str);
1727 /* Remove varargs area if present. */
1728 if (current_frame_info.pretend_size != 0)
1729 fprintf (file, "\taddi %s,%s%d\n",
1730 sp_str, IMMEDIATE_PREFIX, current_frame_info.pretend_size);
1732 /* Emit the return instruction. */
1733 if (M32R_INTERRUPT_P (fn_type))
1734 fprintf (file, "\trte\n");
1736 fprintf (file, "\tjmp %s\n", reg_names[RETURN_ADDR_REGNUM]);
1739 #if 0 /* no longer needed */
1740 /* Ensure the function cleanly ends on a 32 bit boundary. */
1741 fprintf (file, "\t.fillinsn\n");
1744 /* Reset state info for each function. */
1745 current_frame_info = zero_frame_info;
1746 m32r_compute_function_type (NULL_TREE);
1751 /* Emit special PIC prologues and epilogues. */
1754 m32r_finalize_pic ()
1759 /* Nested function support. */
1761 /* Emit RTL insns to initialize the variable parts of a trampoline.
1762 FNADDR is an RTX for the address of the function's pure code.
1763 CXT is an RTX for the static chain value for the function. */
1766 m32r_initialize_trampoline (tramp, fnaddr, cxt)
1767 rtx tramp, fnaddr, cxt;
1771 /* Set the cpu type and print out other fancy things,
1772 at the top of the file. */
1775 m32r_asm_file_start (file)
1778 if (flag_verbose_asm)
1779 fprintf (file, "%s M32R/D special options: -G %d\n",
1780 ASM_COMMENT_START, g_switch_value);
1783 /* Print operand X (an rtx) in assembler syntax to file FILE.
1784 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
1785 For `%' followed by punctuation, CODE is the punctuation and X is null. */
1788 m32r_print_operand (file, x, code)
1797 /* The 's' and 'p' codes are used by output_block_move() to
1798 indicate post-increment 's'tores and 'p're-increment loads. */
1800 if (GET_CODE (x) == REG)
1801 fprintf (file, "@+%s", reg_names [REGNO (x)]);
1803 output_operand_lossage ("invalid operand to %s code");
1807 if (GET_CODE (x) == REG)
1808 fprintf (file, "@%s+", reg_names [REGNO (x)]);
1810 output_operand_lossage ("invalid operand to %p code");
1814 /* Write second word of DImode or DFmode reference,
1815 register or memory. */
1816 if (GET_CODE (x) == REG)
1817 fputs (reg_names[REGNO (x)+1], file);
1818 else if (GET_CODE (x) == MEM)
1820 fprintf (file, "@(");
1821 /* Handle possible auto-increment. Since it is pre-increment and
1822 we have already done it, we can just use an offset of four. */
1823 /* ??? This is taken from rs6000.c I think. I don't think it is
1824 currently necessary, but keep it around. */
1825 if (GET_CODE (XEXP (x, 0)) == PRE_INC
1826 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1827 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
1829 output_address (plus_constant (XEXP (x, 0), 4));
1833 output_operand_lossage ("invalid operand to %R code");
1836 case 'H' : /* High word */
1837 case 'L' : /* Low word */
1838 if (GET_CODE (x) == REG)
1840 /* L = least significant word, H = most significant word */
1841 if ((WORDS_BIG_ENDIAN != 0) ^ (code == 'L'))
1842 fputs (reg_names[REGNO (x)], file);
1844 fputs (reg_names[REGNO (x)+1], file);
1846 else if (GET_CODE (x) == CONST_INT
1847 || GET_CODE (x) == CONST_DOUBLE)
1851 split_double (x, &first, &second);
1852 fprintf (file, "0x%08x",
1853 code == 'L' ? INTVAL (first) : INTVAL (second));
1856 output_operand_lossage ("invalid operand to %H/%L code");
1864 if (GET_CODE (x) != CONST_DOUBLE
1865 || GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT)
1867 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
1868 REAL_VALUE_TO_DECIMAL (d, "%.20e", str);
1869 fprintf (file, "%s", str);
1873 case 'B' : /* Bottom half */
1874 case 'T' : /* Top half */
1875 /* Output the argument to a `seth' insn (sets the Top half-word).
1876 For constants output arguments to a seth/or3 pair to set Top and
1877 Bottom halves. For symbols output arguments to a seth/add3 pair to
1878 set Top and Bottom halves. The difference exists because for
1879 constants seth/or3 is more readable but for symbols we need to use
1880 the same scheme as `ld' and `st' insns (16 bit addend is signed). */
1881 switch (GET_CODE (x))
1888 split_double (x, &first, &second);
1889 x = WORDS_BIG_ENDIAN ? second : first;
1891 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1897 ? INTVAL (x) & 0xffff
1898 : (INTVAL (x) >> 16) & 0xffff));
1904 && small_data_operand (x, VOIDmode))
1906 fputs ("sda(", file);
1907 output_addr_const (file, x);
1913 fputs (code == 'T' ? "shigh(" : "low(", file);
1914 output_addr_const (file, x);
1918 output_operand_lossage ("invalid operand to %T/%B code");
1925 /* Output a load/store with update indicator if appropriate. */
1926 if (GET_CODE (x) == MEM)
1928 if (GET_CODE (XEXP (x, 0)) == PRE_INC
1929 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1933 output_operand_lossage ("invalid operand to %U code");
1937 /* Print a constant value negated. */
1938 if (GET_CODE (x) == CONST_INT)
1939 output_addr_const (file, GEN_INT (- INTVAL (x)));
1941 output_operand_lossage ("invalid operand to %N code");
1945 /* Print a const_int in hex. Used in comments. */
1946 if (GET_CODE (x) == CONST_INT)
1948 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1957 fputs (IMMEDIATE_PREFIX, file);
1960 #if 0 /* ??? no longer used */
1962 fputs (reg_names[SDA_REGNUM], file);
1967 /* Do nothing special. */
1972 output_operand_lossage ("invalid operand output code");
1975 switch (GET_CODE (x))
1978 fputs (reg_names[REGNO (x)], file);
1983 if (GET_CODE (addr) == PRE_INC)
1985 if (GET_CODE (XEXP (addr, 0)) != REG)
1988 fprintf (file, "@+%s", reg_names[REGNO (XEXP (addr, 0))]);
1990 else if (GET_CODE (addr) == PRE_DEC)
1992 if (GET_CODE (XEXP (addr, 0)) != REG)
1995 fprintf (file, "@-%s", reg_names[REGNO (XEXP (addr, 0))]);
1997 else if (GET_CODE (addr) == POST_INC)
1999 if (GET_CODE (XEXP (addr, 0)) != REG)
2002 fprintf (file, "@%s+", reg_names[REGNO (XEXP (addr, 0))]);
2007 output_address (XEXP (x, 0));
2013 /* We handle SFmode constants here as output_addr_const doesn't. */
2014 if (GET_MODE (x) == SFmode)
2019 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
2020 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2021 fprintf (file, "0x%08lx", l);
2025 /* Fall through. Let output_addr_const deal with it. */
2028 output_addr_const (file, x);
2033 /* Print a memory address as an operand to reference that memory location. */
2036 m32r_print_operand_address (file, addr)
2041 register rtx index = 0;
2044 switch (GET_CODE (addr))
2047 fputs (reg_names[REGNO (addr)], file);
2051 if (GET_CODE (XEXP (addr, 0)) == CONST_INT)
2052 offset = INTVAL (XEXP (addr, 0)), base = XEXP (addr, 1);
2053 else if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
2054 offset = INTVAL (XEXP (addr, 1)), base = XEXP (addr, 0);
2056 base = XEXP (addr, 0), index = XEXP (addr, 1);
2057 if (GET_CODE (base) == REG)
2059 /* Print the offset first (if present) to conform to the manual. */
2063 fprintf (file, "%d,", offset);
2064 fputs (reg_names[REGNO (base)], file);
2066 /* The chip doesn't support this, but left in for generality. */
2067 else if (GET_CODE (index) == REG)
2068 fprintf (file, "%s,%s",
2069 reg_names[REGNO (base)], reg_names[REGNO (index)]);
2070 /* Not sure this can happen, but leave in for now. */
2071 else if (GET_CODE (index) == SYMBOL_REF)
2073 output_addr_const (file, index);
2075 fputs (reg_names[REGNO (base)], file);
2080 else if (GET_CODE (base) == LO_SUM)
2083 || GET_CODE (XEXP (base, 0)) != REG)
2085 if (small_data_operand (XEXP (base, 1), VOIDmode))
2086 fputs ("sda(", file);
2088 fputs ("low(", file);
2089 output_addr_const (file, plus_constant (XEXP (base, 1), offset));
2091 fputs (reg_names[REGNO (XEXP (base, 0))], file);
2098 if (GET_CODE (XEXP (addr, 0)) != REG)
2100 if (small_data_operand (XEXP (addr, 1), VOIDmode))
2101 fputs ("sda(", file);
2103 fputs ("low(", file);
2104 output_addr_const (file, XEXP (addr, 1));
2106 fputs (reg_names[REGNO (XEXP (addr, 0))], file);
2109 case PRE_INC : /* Assume SImode */
2110 fprintf (file, "+%s", reg_names[REGNO (XEXP (addr, 0))]);
2113 case PRE_DEC : /* Assume SImode */
2114 fprintf (file, "-%s", reg_names[REGNO (XEXP (addr, 0))]);
2117 case POST_INC : /* Assume SImode */
2118 fprintf (file, "%s+", reg_names[REGNO (XEXP (addr, 0))]);
2122 output_addr_const (file, addr);
2127 /* Return true if the operands are the constants 0 and 1. */
2129 zero_and_one (operand1, operand2)
2134 GET_CODE (operand1) == CONST_INT
2135 && GET_CODE (operand2) == CONST_INT
2136 && ( ((INTVAL (operand1) == 0) && (INTVAL (operand2) == 1))
2137 ||((INTVAL (operand1) == 1) && (INTVAL (operand2) == 0)));
2140 /* Return non-zero if the operand is suitable for use in a conditional move sequence. */
2142 conditional_move_operand (operand, int_mode)
2146 enum machine_mode mode = (enum machine_mode)int_mode;
2148 /* Only defined for simple integers so far... */
2149 if (mode != SImode && mode != HImode && mode != QImode)
2152 /* At the moment we can hanndle moving registers and loading constants. */
2153 /* To be added: Addition/subtraction/bitops/multiplication of registers. */
2155 switch (GET_CODE (operand))
2161 return INT8_P (INTVAL (operand));
2165 fprintf (stderr, "Test for cond move op of type: %s\n",
2166 GET_RTX_NAME (GET_CODE (operand)));
2172 /* Return true if the code is a test of the carry bit */
2174 carry_compare_operand (op, int_mode)
2180 if (GET_MODE (op) != SImode && GET_MODE (op) != VOIDmode)
2183 if (GET_CODE (op) != NE && GET_CODE (op) != EQ)
2187 if (GET_CODE (x) != REG || REGNO (x) != CARRY_REGNUM)
2191 if (GET_CODE (x) != CONST_INT || INTVAL (x) != 0)
2198 /* Generate the correct assembler code to handle the conditional loading of a
2199 value into a register. It is known that the operands satisfy the
2200 conditional_move_operand() function above. The destination is operand[0].
2201 The condition is operand [1]. The 'true' value is operand [2] and the
2202 'false' value is operand [3]. */
2204 emit_cond_move (operands, insn)
2208 static char buffer [100];
2209 char * dest = reg_names [REGNO (operands [0])];
2213 /* Destination must be a register. */
2214 if (GET_CODE (operands [0]) != REG)
2216 if (! conditional_move_operand (operands [2], SImode))
2218 if (! conditional_move_operand (operands [3], SImode))
2221 /* Check to see if the test is reversed. */
2222 if (GET_CODE (operands [1]) == NE)
2224 rtx tmp = operands [2];
2225 operands [2] = operands [3];
2229 sprintf (buffer, "mvfc %s, cbr", dest);
2231 /* If the true value was '0' then we need to invert the results of the move. */
2232 if (INTVAL (operands [2]) == 0)
2233 sprintf (buffer + strlen (buffer), "\n\txor3 %s, %s, #1",
2241 /* Use a library function to move some bytes. */
2243 block_move_call (dest_reg, src_reg, bytes_rtx)
2248 /* We want to pass the size as Pmode, which will normally be SImode
2249 but will be DImode if we are using 64 bit longs and pointers. */
2250 if (GET_MODE (bytes_rtx) != VOIDmode
2251 && GET_MODE (bytes_rtx) != Pmode)
2252 bytes_rtx = convert_to_mode (Pmode, bytes_rtx, 1);
2254 #ifdef TARGET_MEM_FUNCTIONS
2255 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memcpy"), 0,
2256 VOIDmode, 3, dest_reg, Pmode, src_reg, Pmode,
2257 convert_to_mode (TYPE_MODE (sizetype), bytes_rtx,
2258 TREE_UNSIGNED (sizetype)),
2259 TYPE_MODE (sizetype));
2261 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bcopy"), 0,
2262 VOIDmode, 3, src_reg, Pmode, dest_reg, Pmode,
2263 convert_to_mode (TYPE_MODE (integer_type_node), bytes_rtx,
2264 TREE_UNSIGNED (integer_type_node)),
2265 TYPE_MODE (integer_type_node));
2269 /* The maximum number of bytes to copy using pairs of load/store instructions.
2270 If a block is larger than this then a loop will be generated to copy
2271 MAX_MOVE_BYTES chunks at a time. The value of 32 is a semi-arbitary choice.
2272 A customer uses Dhrystome as their benchmark, and Dhrystone has a 31 byte
2273 string copy in it. */
2274 #define MAX_MOVE_BYTES 32
2276 /* Expand string/block move operations.
2278 operands[0] is the pointer to the destination.
2279 operands[1] is the pointer to the source.
2280 operands[2] is the number of bytes to move.
2281 operands[3] is the alignment. */
2284 m32r_expand_block_move (operands)
2287 rtx orig_dst = operands[0];
2288 rtx orig_src = operands[1];
2289 rtx bytes_rtx = operands[2];
2290 rtx align_rtx = operands[3];
2291 int constp = GET_CODE (bytes_rtx) == CONST_INT;
2292 HOST_WIDE_INT bytes = constp ? INTVAL (bytes_rtx) : 0;
2293 int align = INTVAL (align_rtx);
2298 if (constp && bytes <= 0)
2301 /* Move the address into scratch registers. */
2302 dst_reg = copy_addr_to_reg (XEXP (orig_dst, 0));
2303 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2305 if (align > UNITS_PER_WORD)
2306 align = UNITS_PER_WORD;
2308 /* If we prefer size over speed, always use a function call.
2309 If we do not know the size, use a function call.
2310 If the blocks are not word aligned, use a function call. */
2311 if (optimize_size || ! constp || align != UNITS_PER_WORD)
2313 block_move_call (dst_reg, src_reg, bytes_rtx);
2317 leftover = bytes % MAX_MOVE_BYTES;
2320 /* If necessary, generate a loop to handle the bulk of the copy. */
2326 bytes_rtx = GEN_INT (MAX_MOVE_BYTES);
2328 /* If we are going to have to perform this loop more than
2329 once, then generate a label and compute the address the
2330 source register will contain upon completion of the final
2332 if (bytes > MAX_MOVE_BYTES)
2334 final_src = gen_reg_rtx (Pmode);
2337 emit_insn (gen_addsi3 (final_src, src_reg, bytes_rtx));
2340 emit_insn (gen_movsi (final_src, bytes_rtx));
2341 emit_insn (gen_addsi3 (final_src, final_src, src_reg));
2344 label = gen_label_rtx ();
2348 /* It is known that output_block_move() will update src_reg to point
2349 to the word after the end of the source block, and dst_reg to point
2350 to the last word of the destination block, provided that the block
2351 is MAX_MOVE_BYTES long. */
2352 emit_insn (gen_movstrsi_internal (dst_reg, src_reg, bytes_rtx));
2353 emit_insn (gen_addsi3 (dst_reg, dst_reg, GEN_INT (4)));
2355 if (bytes > MAX_MOVE_BYTES)
2357 emit_insn (gen_cmpsi (src_reg, final_src));
2358 emit_jump_insn (gen_bne (label));
2363 emit_insn (gen_movstrsi_internal (dst_reg, src_reg, GEN_INT (leftover)));
2367 /* Emit load/stores for a small constant word aligned block_move.
2369 operands[0] is the memory address of the destination.
2370 operands[1] is the memory address of the source.
2371 operands[2] is the number of bytes to move.
2372 operands[3] is a temp register.
2373 operands[4] is a temp register. */
2376 m32r_output_block_move (insn, operands)
2380 HOST_WIDE_INT bytes = INTVAL (operands[2]);
2384 if (bytes < 1 || bytes > MAX_MOVE_BYTES)
2387 /* We do not have a post-increment store available, so the first set of
2388 stores are done without any increment, then the remaining ones can use
2389 the pre-increment addressing mode.
2391 Note: expand_block_move() also relies upon this behaviour when building
2392 loops to copy large blocks. */
2401 output_asm_insn ("ld\t%3, %p1", operands);
2402 output_asm_insn ("ld\t%4, %p1", operands);
2403 output_asm_insn ("st\t%3, @%0", operands);
2404 output_asm_insn ("st\t%4, %s0", operands);
2408 output_asm_insn ("ld\t%3, %p1", operands);
2409 output_asm_insn ("ld\t%4, %p1", operands);
2410 output_asm_insn ("st\t%3, %s0", operands);
2411 output_asm_insn ("st\t%4, %s0", operands);
2416 else if (bytes >= 4)
2421 output_asm_insn ("ld\t%3, %p1", operands);
2424 output_asm_insn ("ld\t%4, %p1", operands);
2427 output_asm_insn ("st\t%3, @%0", operands);
2429 output_asm_insn ("st\t%3, %s0", operands);
2435 /* Get the entire next word, even though we do not want all of it.
2436 The saves us from doing several smaller loads, and we assume that
2437 we cannot cause a page fault when at least part of the word is in
2438 valid memory. If got_extra is true then we have already loaded
2439 the next word as part of loading and storing the previous word. */
2441 output_asm_insn ("ld\t%4, @%1", operands);
2447 output_asm_insn ("sth\t%4, @%0", operands);
2449 /* If there is a byte left to store then increment the
2450 destination address and shift the contents of the source
2451 register down by 16 bits. We could not do the address
2452 increment in the store half word instruction, because it does
2453 not have an auto increment mode. */
2454 if (bytes > 0) /* assert (bytes == 1) */
2456 output_asm_insn ("srai\t%4, #16", operands);
2457 output_asm_insn ("addi\t%0, #2", operands);
2461 output_asm_insn ("stb\t%4, @%0", operands);
2472 /* Return true if op is an integer constant, less than or equal to
2475 m32r_block_immediate_operand (op, mode)
2479 if (GET_CODE (op) != CONST_INT
2480 || INTVAL (op) > MAX_MOVE_BYTES
2481 || INTVAL (op) <= 0)