1 /* Subroutines for insn-output.c for Tensilica's Xtensa architecture.
2 Copyright 2001,2002,2003 Free Software Foundation, Inc.
3 Contributed by Bob Wilson (bwilson@tensilica.com) at Tensilica.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
28 #include "hard-reg-set.h"
29 #include "basic-block.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-flags.h"
34 #include "insn-attr.h"
35 #include "insn-codes.h"
49 #include "target-def.h"
50 #include "langhooks.h"
52 /* Enumeration for all of the relational tests, so that we can build
53 arrays indexed by the test type, and not worry about the order
70 /* Cached operands, and operator to compare for use in set/branch on
74 /* what type of branch to use */
75 enum cmp_type branch_type;
77 /* Array giving truth value on whether or not a given hard register
78 can support a given mode. */
79 char xtensa_hard_regno_mode_ok[(int) MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
81 /* Current frame size calculated by compute_frame_size. */
82 unsigned xtensa_current_frame_size;
84 /* Tables of ld/st opcode names for block moves */
85 const char *xtensa_ld_opcodes[(int) MAX_MACHINE_MODE];
86 const char *xtensa_st_opcodes[(int) MAX_MACHINE_MODE];
87 #define LARGEST_MOVE_RATIO 15
89 /* Define the structure for the machine field in struct function. */
90 struct machine_function GTY(())
92 int accesses_prev_frame;
93 bool incoming_a7_copied;
96 /* Vector, indexed by hard register number, which contains 1 for a
97 register that is allowable in a candidate for leaf function
100 const char xtensa_leaf_regs[FIRST_PSEUDO_REGISTER] =
102 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
104 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
108 /* Map hard register number to register class */
109 const enum reg_class xtensa_regno_to_class[FIRST_PSEUDO_REGISTER] =
111 RL_REGS, SP_REG, RL_REGS, RL_REGS,
112 RL_REGS, RL_REGS, RL_REGS, GR_REGS,
113 RL_REGS, RL_REGS, RL_REGS, RL_REGS,
114 RL_REGS, RL_REGS, RL_REGS, RL_REGS,
115 AR_REGS, AR_REGS, BR_REGS,
116 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
117 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
118 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
119 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
123 /* Map register constraint character to register class. */
124 enum reg_class xtensa_char_to_class[256] =
126 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
127 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
128 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
129 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
130 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
131 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
132 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
133 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
134 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
135 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
136 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
137 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
138 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
139 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
140 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
141 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
142 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
143 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
144 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
145 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
146 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
147 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
148 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
149 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
150 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
151 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
152 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
153 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
154 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
155 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
156 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
157 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
158 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
159 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
160 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
161 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
162 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
163 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
164 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
165 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
166 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
167 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
168 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
169 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
170 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
171 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
172 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
173 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
174 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
175 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
176 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
177 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
178 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
179 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
180 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
181 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
182 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
183 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
184 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
185 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
186 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
187 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
188 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
189 NO_REGS, NO_REGS, NO_REGS, NO_REGS,
192 static int b4const_or_zero PARAMS ((int));
193 static enum internal_test map_test_to_internal_test PARAMS ((enum rtx_code));
194 static rtx gen_int_relational PARAMS ((enum rtx_code, rtx, rtx, int *));
195 static rtx gen_float_relational PARAMS ((enum rtx_code, rtx, rtx));
196 static rtx gen_conditional_move PARAMS ((rtx));
197 static rtx fixup_subreg_mem PARAMS ((rtx x));
198 static enum machine_mode xtensa_find_mode_for_size PARAMS ((unsigned));
199 static struct machine_function * xtensa_init_machine_status PARAMS ((void));
200 static void printx PARAMS ((FILE *, signed int));
201 static void xtensa_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
202 static unsigned int xtensa_multibss_section_type_flags
203 PARAMS ((tree, const char *, int)) ATTRIBUTE_UNUSED;
204 static void xtensa_select_rtx_section
205 PARAMS ((enum machine_mode, rtx, unsigned HOST_WIDE_INT));
206 static bool xtensa_rtx_costs PARAMS ((rtx, int, int, int *));
208 static int current_function_arg_words;
209 static const int reg_nonleaf_alloc_order[FIRST_PSEUDO_REGISTER] =
213 /* This macro generates the assembly code for function exit,
214 on machines that need it. If FUNCTION_EPILOGUE is not defined
215 then individual return instructions are generated for each
216 return statement. Args are same as for FUNCTION_PROLOGUE. */
218 #undef TARGET_ASM_FUNCTION_EPILOGUE
219 #define TARGET_ASM_FUNCTION_EPILOGUE xtensa_function_epilogue
221 /* These hooks specify assembly directives for creating certain kinds
222 of integer object. */
224 #undef TARGET_ASM_ALIGNED_SI_OP
225 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
227 #undef TARGET_ASM_SELECT_RTX_SECTION
228 #define TARGET_ASM_SELECT_RTX_SECTION xtensa_select_rtx_section
230 #undef TARGET_RTX_COSTS
231 #define TARGET_RTX_COSTS xtensa_rtx_costs
232 #undef TARGET_ADDRESS_COST
233 #define TARGET_ADDRESS_COST hook_int_rtx_0
235 struct gcc_target targetm = TARGET_INITIALIZER;
239 * Functions to test Xtensa immediate operand validity.
273 return (v & 255) == 0 && (v >= -32768 && v <= 32512);
280 return (v == -1 || (v >= 1 && v <= 15));
287 return v >= -32 && v <= 95;
321 return v >= -128 && v <= 127;
328 return (v >= 7 && v <= 22);
335 return (v & 3) == 0 && (v >= 0 && v <= 60);
342 return v >= -2048 && v <= 2047;
349 return v >= 0 && v <= 255;
356 return (v & 1) == 0 && (v >= 0 && v <= 510);
363 return (v & 3) == 0 && (v >= 0 && v <= 1020);
367 /* This is just like the standard true_regnum() function except that it
368 works even when reg_renumber is not initialized. */
374 if (GET_CODE (x) == REG)
377 && REGNO (x) >= FIRST_PSEUDO_REGISTER
378 && reg_renumber[REGNO (x)] >= 0)
379 return reg_renumber[REGNO (x)];
382 if (GET_CODE (x) == SUBREG)
384 int base = xt_true_regnum (SUBREG_REG (x));
385 if (base >= 0 && base < FIRST_PSEUDO_REGISTER)
386 return base + subreg_regno_offset (REGNO (SUBREG_REG (x)),
387 GET_MODE (SUBREG_REG (x)),
388 SUBREG_BYTE (x), GET_MODE (x));
395 add_operand (op, mode)
397 enum machine_mode mode;
399 if (GET_CODE (op) == CONST_INT)
400 return (xtensa_simm8 (INTVAL (op)) || xtensa_simm8x256 (INTVAL (op)));
402 return register_operand (op, mode);
407 arith_operand (op, mode)
409 enum machine_mode mode;
411 if (GET_CODE (op) == CONST_INT)
412 return xtensa_simm8 (INTVAL (op));
414 return register_operand (op, mode);
419 nonimmed_operand (op, mode)
421 enum machine_mode mode;
423 /* We cannot use the standard nonimmediate_operand() predicate because
424 it includes constant pool memory operands. */
426 if (memory_operand (op, mode))
427 return !constantpool_address_p (XEXP (op, 0));
429 return register_operand (op, mode);
434 mem_operand (op, mode)
436 enum machine_mode mode;
438 /* We cannot use the standard memory_operand() predicate because
439 it includes constant pool memory operands. */
441 if (memory_operand (op, mode))
442 return !constantpool_address_p (XEXP (op, 0));
449 xtensa_valid_move (mode, operands)
450 enum machine_mode mode;
453 /* Either the destination or source must be a register, and the
454 MAC16 accumulator doesn't count. */
456 if (register_operand (operands[0], mode))
458 int dst_regnum = xt_true_regnum (operands[0]);
460 /* The stack pointer can only be assigned with a MOVSP opcode. */
461 if (dst_regnum == STACK_POINTER_REGNUM)
462 return (mode == SImode
463 && register_operand (operands[1], mode)
464 && !ACC_REG_P (xt_true_regnum (operands[1])));
466 if (!ACC_REG_P (dst_regnum))
469 if (register_operand (operands[1], mode))
471 int src_regnum = xt_true_regnum (operands[1]);
472 if (!ACC_REG_P (src_regnum))
480 mask_operand (op, mode)
482 enum machine_mode mode;
484 if (GET_CODE (op) == CONST_INT)
485 return xtensa_mask_immediate (INTVAL (op));
487 return register_operand (op, mode);
492 extui_fldsz_operand (op, mode)
494 enum machine_mode mode ATTRIBUTE_UNUSED;
496 return ((GET_CODE (op) == CONST_INT)
497 && xtensa_mask_immediate ((1 << INTVAL (op)) - 1));
502 sext_operand (op, mode)
504 enum machine_mode mode;
507 return nonimmed_operand (op, mode);
508 return mem_operand (op, mode);
513 sext_fldsz_operand (op, mode)
515 enum machine_mode mode ATTRIBUTE_UNUSED;
517 return ((GET_CODE (op) == CONST_INT) && xtensa_tp7 (INTVAL (op) - 1));
522 lsbitnum_operand (op, mode)
524 enum machine_mode mode ATTRIBUTE_UNUSED;
526 if (GET_CODE (op) == CONST_INT)
528 return (BITS_BIG_ENDIAN
529 ? (INTVAL (op) == BITS_PER_WORD-1)
530 : (INTVAL (op) == 0));
542 return xtensa_b4const (v);
547 branch_operand (op, mode)
549 enum machine_mode mode;
551 if (GET_CODE (op) == CONST_INT)
552 return b4const_or_zero (INTVAL (op));
554 return register_operand (op, mode);
559 ubranch_operand (op, mode)
561 enum machine_mode mode;
563 if (GET_CODE (op) == CONST_INT)
564 return xtensa_b4constu (INTVAL (op));
566 return register_operand (op, mode);
571 call_insn_operand (op, mode)
573 enum machine_mode mode ATTRIBUTE_UNUSED;
575 if ((GET_CODE (op) == REG)
576 && (op != arg_pointer_rtx)
577 && ((REGNO (op) < FRAME_POINTER_REGNUM)
578 || (REGNO (op) > LAST_VIRTUAL_REGISTER)))
581 if (CONSTANT_ADDRESS_P (op))
583 /* Direct calls only allowed to static functions with PIC. */
586 tree callee, callee_sec, caller_sec;
588 if (GET_CODE (op) != SYMBOL_REF || !SYMBOL_REF_LOCAL_P (op))
591 /* Don't attempt a direct call if the callee is known to be in
592 a different section, since there's a good chance it will be
595 if (flag_function_sections
596 || DECL_ONE_ONLY (current_function_decl))
598 caller_sec = DECL_SECTION_NAME (current_function_decl);
599 callee = SYMBOL_REF_DECL (op);
602 if (DECL_ONE_ONLY (callee))
604 callee_sec = DECL_SECTION_NAME (callee);
605 if (((caller_sec == NULL_TREE) ^ (callee_sec == NULL_TREE))
606 || (caller_sec != NULL_TREE
607 && strcmp (TREE_STRING_POINTER (caller_sec),
608 TREE_STRING_POINTER (callee_sec)) != 0))
611 else if (caller_sec != NULL_TREE)
622 move_operand (op, mode)
624 enum machine_mode mode;
626 if (register_operand (op, mode)
627 || memory_operand (op, mode))
634 return TARGET_CONST16 && CONSTANT_P (op);
639 return CONSTANT_P (op);
644 /* Accept CONSTANT_P_RTX, since it will be gone by CSE1 and
646 if (GET_CODE (op) == CONSTANT_P_RTX)
649 if (GET_CODE (op) == CONST_INT && xtensa_simm12b (INTVAL (op)))
662 smalloffset_mem_p (op)
665 if (GET_CODE (op) == MEM)
667 rtx addr = XEXP (op, 0);
668 if (GET_CODE (addr) == REG)
669 return REG_OK_FOR_BASE_P (addr);
670 if (GET_CODE (addr) == PLUS)
672 rtx offset = XEXP (addr, 0);
673 if (GET_CODE (offset) != CONST_INT)
674 offset = XEXP (addr, 1);
675 if (GET_CODE (offset) != CONST_INT)
677 return xtensa_lsi4x4 (INTVAL (offset));
685 constantpool_address_p (addr)
690 if (GET_CODE (addr) == CONST)
694 /* only handle (PLUS (SYM, OFFSET)) form */
695 addr = XEXP (addr, 0);
696 if (GET_CODE (addr) != PLUS)
699 /* make sure the address is word aligned */
700 offset = XEXP (addr, 1);
701 if ((GET_CODE (offset) != CONST_INT)
702 || ((INTVAL (offset) & 3) != 0))
705 sym = XEXP (addr, 0);
708 if ((GET_CODE (sym) == SYMBOL_REF)
709 && CONSTANT_POOL_ADDRESS_P (sym))
716 constantpool_mem_p (op)
719 if (GET_CODE (op) == MEM)
720 return constantpool_address_p (XEXP (op, 0));
725 /* Accept the floating point constant 1 in the appropriate mode. */
728 const_float_1_operand (op, mode)
730 enum machine_mode mode;
733 static REAL_VALUE_TYPE onedf;
734 static REAL_VALUE_TYPE onesf;
735 static int one_initialized;
737 if ((GET_CODE (op) != CONST_DOUBLE)
738 || (mode != GET_MODE (op))
739 || (mode != DFmode && mode != SFmode))
742 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
744 if (! one_initialized)
746 onedf = REAL_VALUE_ATOF ("1.0", DFmode);
747 onesf = REAL_VALUE_ATOF ("1.0", SFmode);
748 one_initialized = TRUE;
752 return REAL_VALUES_EQUAL (d, onedf);
754 return REAL_VALUES_EQUAL (d, onesf);
759 fpmem_offset_operand (op, mode)
761 enum machine_mode mode ATTRIBUTE_UNUSED;
763 if (GET_CODE (op) == CONST_INT)
764 return xtensa_mem_offset (INTVAL (op), SFmode);
770 xtensa_extend_reg (dst, src)
774 rtx temp = gen_reg_rtx (SImode);
775 rtx shift = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (GET_MODE (src)));
777 /* generate paradoxical subregs as needed so that the modes match */
778 src = simplify_gen_subreg (SImode, src, GET_MODE (src), 0);
779 dst = simplify_gen_subreg (SImode, dst, GET_MODE (dst), 0);
781 emit_insn (gen_ashlsi3 (temp, src, shift));
782 emit_insn (gen_ashrsi3 (dst, temp, shift));
787 branch_operator (x, mode)
789 enum machine_mode mode;
791 if (GET_MODE (x) != mode)
794 switch (GET_CODE (x))
809 ubranch_operator (x, mode)
811 enum machine_mode mode;
813 if (GET_MODE (x) != mode)
816 switch (GET_CODE (x))
829 boolean_operator (x, mode)
831 enum machine_mode mode;
833 if (GET_MODE (x) != mode)
836 switch (GET_CODE (x))
849 xtensa_mask_immediate (v)
852 #define MAX_MASK_SIZE 16
855 for (mask_size = 1; mask_size <= MAX_MASK_SIZE; mask_size++)
869 xtensa_mem_offset (v, mode)
871 enum machine_mode mode;
876 /* Handle the worst case for block moves. See xtensa_expand_block_move
877 where we emit an optimized block move operation if the block can be
878 moved in < "move_ratio" pieces. The worst case is when the block is
879 aligned but has a size of (3 mod 4) (does this happen?) so that the
880 last piece requires a byte load/store. */
881 return (xtensa_uimm8 (v)
882 && xtensa_uimm8 (v + MOVE_MAX * LARGEST_MOVE_RATIO));
885 return xtensa_uimm8 (v);
888 return xtensa_uimm8x2 (v);
891 return (xtensa_uimm8x4 (v) && xtensa_uimm8x4 (v + 4));
897 return xtensa_uimm8x4 (v);
901 /* Make normal rtx_code into something we can index from an array */
903 static enum internal_test
904 map_test_to_internal_test (test_code)
905 enum rtx_code test_code;
907 enum internal_test test = ITEST_MAX;
912 case EQ: test = ITEST_EQ; break;
913 case NE: test = ITEST_NE; break;
914 case GT: test = ITEST_GT; break;
915 case GE: test = ITEST_GE; break;
916 case LT: test = ITEST_LT; break;
917 case LE: test = ITEST_LE; break;
918 case GTU: test = ITEST_GTU; break;
919 case GEU: test = ITEST_GEU; break;
920 case LTU: test = ITEST_LTU; break;
921 case LEU: test = ITEST_LEU; break;
928 /* Generate the code to compare two integer values. The return value is
929 the comparison expression. */
932 gen_int_relational (test_code, cmp0, cmp1, p_invert)
933 enum rtx_code test_code; /* relational test (EQ, etc) */
934 rtx cmp0; /* first operand to compare */
935 rtx cmp1; /* second operand to compare */
936 int *p_invert; /* whether branch needs to reverse its test */
939 enum rtx_code test_code; /* test code to use in insn */
940 int (*const_range_p) PARAMS ((int)); /* predicate function to check range */
941 int const_add; /* constant to add (convert LE -> LT) */
942 int reverse_regs; /* reverse registers in test */
943 int invert_const; /* != 0 if invert value if cmp1 is constant */
944 int invert_reg; /* != 0 if invert value if cmp1 is register */
945 int unsignedp; /* != 0 for unsigned comparisons. */
948 static struct cmp_info info[ (int)ITEST_MAX ] = {
950 { EQ, b4const_or_zero, 0, 0, 0, 0, 0 }, /* EQ */
951 { NE, b4const_or_zero, 0, 0, 0, 0, 0 }, /* NE */
953 { LT, b4const_or_zero, 1, 1, 1, 0, 0 }, /* GT */
954 { GE, b4const_or_zero, 0, 0, 0, 0, 0 }, /* GE */
955 { LT, b4const_or_zero, 0, 0, 0, 0, 0 }, /* LT */
956 { GE, b4const_or_zero, 1, 1, 1, 0, 0 }, /* LE */
958 { LTU, xtensa_b4constu, 1, 1, 1, 0, 1 }, /* GTU */
959 { GEU, xtensa_b4constu, 0, 0, 0, 0, 1 }, /* GEU */
960 { LTU, xtensa_b4constu, 0, 0, 0, 0, 1 }, /* LTU */
961 { GEU, xtensa_b4constu, 1, 1, 1, 0, 1 }, /* LEU */
964 enum internal_test test;
965 enum machine_mode mode;
966 struct cmp_info *p_info;
968 test = map_test_to_internal_test (test_code);
969 if (test == ITEST_MAX)
972 p_info = &info[ (int)test ];
974 mode = GET_MODE (cmp0);
975 if (mode == VOIDmode)
976 mode = GET_MODE (cmp1);
978 /* Make sure we can handle any constants given to us. */
979 if (GET_CODE (cmp1) == CONST_INT)
981 HOST_WIDE_INT value = INTVAL (cmp1);
982 unsigned HOST_WIDE_INT uvalue = (unsigned HOST_WIDE_INT)value;
984 /* if the immediate overflows or does not fit in the immediate field,
985 spill it to a register */
987 if ((p_info->unsignedp ?
988 (uvalue + p_info->const_add > uvalue) :
989 (value + p_info->const_add > value)) != (p_info->const_add > 0))
991 cmp1 = force_reg (mode, cmp1);
993 else if (!(p_info->const_range_p) (value + p_info->const_add))
995 cmp1 = force_reg (mode, cmp1);
998 else if ((GET_CODE (cmp1) != REG) && (GET_CODE (cmp1) != SUBREG))
1000 cmp1 = force_reg (mode, cmp1);
1003 /* See if we need to invert the result. */
1004 *p_invert = ((GET_CODE (cmp1) == CONST_INT)
1005 ? p_info->invert_const
1006 : p_info->invert_reg);
1008 /* Comparison to constants, may involve adding 1 to change a LT into LE.
1009 Comparison between two registers, may involve switching operands. */
1010 if (GET_CODE (cmp1) == CONST_INT)
1012 if (p_info->const_add != 0)
1013 cmp1 = GEN_INT (INTVAL (cmp1) + p_info->const_add);
1016 else if (p_info->reverse_regs)
1023 return gen_rtx (p_info->test_code, VOIDmode, cmp0, cmp1);
1027 /* Generate the code to compare two float values. The return value is
1028 the comparison expression. */
1031 gen_float_relational (test_code, cmp0, cmp1)
1032 enum rtx_code test_code; /* relational test (EQ, etc) */
1033 rtx cmp0; /* first operand to compare */
1034 rtx cmp1; /* second operand to compare */
1036 rtx (*gen_fn) PARAMS ((rtx, rtx, rtx));
1038 int reverse_regs, invert;
1042 case EQ: reverse_regs = 0; invert = 0; gen_fn = gen_seq_sf; break;
1043 case NE: reverse_regs = 0; invert = 1; gen_fn = gen_seq_sf; break;
1044 case LE: reverse_regs = 0; invert = 0; gen_fn = gen_sle_sf; break;
1045 case GT: reverse_regs = 1; invert = 0; gen_fn = gen_slt_sf; break;
1046 case LT: reverse_regs = 0; invert = 0; gen_fn = gen_slt_sf; break;
1047 case GE: reverse_regs = 1; invert = 0; gen_fn = gen_sle_sf; break;
1049 fatal_insn ("bad test", gen_rtx (test_code, VOIDmode, cmp0, cmp1));
1050 reverse_regs = 0; invert = 0; gen_fn = 0; /* avoid compiler warnings */
1060 brtmp = gen_rtx_REG (CCmode, FPCC_REGNUM);
1061 emit_insn (gen_fn (brtmp, cmp0, cmp1));
1063 return gen_rtx (invert ? EQ : NE, VOIDmode, brtmp, const0_rtx);
1068 xtensa_expand_conditional_branch (operands, test_code)
1070 enum rtx_code test_code;
1072 enum cmp_type type = branch_type;
1073 rtx cmp0 = branch_cmp[0];
1074 rtx cmp1 = branch_cmp[1];
1083 fatal_insn ("bad test", gen_rtx (test_code, VOIDmode, cmp0, cmp1));
1087 cmp = gen_int_relational (test_code, cmp0, cmp1, &invert);
1091 if (!TARGET_HARD_FLOAT)
1092 fatal_insn ("bad test", gen_rtx (test_code, VOIDmode, cmp0, cmp1));
1094 cmp = gen_float_relational (test_code, cmp0, cmp1);
1098 /* Generate the branch. */
1100 label1 = gen_rtx_LABEL_REF (VOIDmode, operands[0]);
1109 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
1110 gen_rtx_IF_THEN_ELSE (VOIDmode, cmp,
1117 gen_conditional_move (cmp)
1120 enum rtx_code code = GET_CODE (cmp);
1121 rtx op0 = branch_cmp[0];
1122 rtx op1 = branch_cmp[1];
1124 if (branch_type == CMP_SI)
1126 /* Jump optimization calls get_condition() which canonicalizes
1127 comparisons like (GE x <const>) to (GT x <const-1>).
1128 Transform those comparisons back to GE, since that is the
1129 comparison supported in Xtensa. We shouldn't have to
1130 transform <LE x const> comparisons, because neither
1131 xtensa_expand_conditional_branch() nor get_condition() will
1134 if ((code == GT) && (op1 == constm1_rtx))
1139 cmp = gen_rtx (code, VOIDmode, cc0_rtx, const0_rtx);
1141 if (boolean_operator (cmp, VOIDmode))
1143 /* swap the operands to make const0 second */
1144 if (op0 == const0_rtx)
1150 /* if not comparing against zero, emit a comparison (subtract) */
1151 if (op1 != const0_rtx)
1153 op0 = expand_binop (SImode, sub_optab, op0, op1,
1154 0, 0, OPTAB_LIB_WIDEN);
1158 else if (branch_operator (cmp, VOIDmode))
1160 /* swap the operands to make const0 second */
1161 if (op0 == const0_rtx)
1168 case LT: code = GE; break;
1169 case GE: code = LT; break;
1174 if (op1 != const0_rtx)
1180 return gen_rtx (code, VOIDmode, op0, op1);
1183 if (TARGET_HARD_FLOAT && (branch_type == CMP_SF))
1184 return gen_float_relational (code, op0, op1);
1191 xtensa_expand_conditional_move (operands, isflt)
1196 rtx (*gen_fn) PARAMS ((rtx, rtx, rtx, rtx, rtx));
1198 if (!(cmp = gen_conditional_move (operands[1])))
1202 gen_fn = (branch_type == CMP_SI
1203 ? gen_movsfcc_internal0
1204 : gen_movsfcc_internal1);
1206 gen_fn = (branch_type == CMP_SI
1207 ? gen_movsicc_internal0
1208 : gen_movsicc_internal1);
1210 emit_insn (gen_fn (operands[0], XEXP (cmp, 0),
1211 operands[2], operands[3], cmp));
1217 xtensa_expand_scc (operands)
1220 rtx dest = operands[0];
1221 rtx cmp = operands[1];
1222 rtx one_tmp, zero_tmp;
1223 rtx (*gen_fn) PARAMS ((rtx, rtx, rtx, rtx, rtx));
1225 if (!(cmp = gen_conditional_move (cmp)))
1228 one_tmp = gen_reg_rtx (SImode);
1229 zero_tmp = gen_reg_rtx (SImode);
1230 emit_insn (gen_movsi (one_tmp, const_true_rtx));
1231 emit_insn (gen_movsi (zero_tmp, const0_rtx));
1233 gen_fn = (branch_type == CMP_SI
1234 ? gen_movsicc_internal0
1235 : gen_movsicc_internal1);
1236 emit_insn (gen_fn (dest, XEXP (cmp, 0), one_tmp, zero_tmp, cmp));
1241 /* Split OP[1] into OP[2,3] and likewise for OP[0] into OP[0,1]. MODE is
1242 for the output, i.e., the input operands are twice as big as MODE. */
1245 xtensa_split_operand_pair (operands, mode)
1247 enum machine_mode mode;
1249 switch (GET_CODE (operands[1]))
1252 operands[3] = gen_rtx_REG (mode, REGNO (operands[1]) + 1);
1253 operands[2] = gen_rtx_REG (mode, REGNO (operands[1]));
1257 operands[3] = adjust_address (operands[1], mode, GET_MODE_SIZE (mode));
1258 operands[2] = adjust_address (operands[1], mode, 0);
1263 split_double (operands[1], &operands[2], &operands[3]);
1270 switch (GET_CODE (operands[0]))
1273 operands[1] = gen_rtx_REG (mode, REGNO (operands[0]) + 1);
1274 operands[0] = gen_rtx_REG (mode, REGNO (operands[0]));
1278 operands[1] = adjust_address (operands[0], mode, GET_MODE_SIZE (mode));
1279 operands[0] = adjust_address (operands[0], mode, 0);
1288 /* Emit insns to move operands[1] into operands[0].
1289 Return 1 if we have written out everything that needs to be done to
1290 do the move. Otherwise, return 0 and the caller will emit the move
1294 xtensa_emit_move_sequence (operands, mode)
1296 enum machine_mode mode;
1298 if (CONSTANT_P (operands[1])
1299 && GET_CODE (operands[1]) != CONSTANT_P_RTX
1300 && (GET_CODE (operands[1]) != CONST_INT
1301 || !xtensa_simm12b (INTVAL (operands[1]))))
1303 if (!TARGET_CONST16)
1304 operands[1] = force_const_mem (SImode, operands[1]);
1306 /* PC-relative loads are always SImode, and CONST16 is only
1307 supported in the movsi pattern, so add a SUBREG for any other
1312 if (register_operand (operands[0], mode))
1314 operands[0] = simplify_gen_subreg (SImode, operands[0], mode, 0);
1315 emit_move_insn (operands[0], operands[1]);
1320 operands[1] = force_reg (SImode, operands[1]);
1321 operands[1] = gen_lowpart_SUBREG (mode, operands[1]);
1326 if (!(reload_in_progress | reload_completed))
1328 if (!xtensa_valid_move (mode, operands))
1329 operands[1] = force_reg (mode, operands[1]);
1331 if (xtensa_copy_incoming_a7 (operands, mode))
1335 /* During reload we don't want to emit (subreg:X (mem:Y)) since that
1336 instruction won't be recognized after reload, so we remove the
1337 subreg and adjust mem accordingly. */
1338 if (reload_in_progress)
1340 operands[0] = fixup_subreg_mem (operands[0]);
1341 operands[1] = fixup_subreg_mem (operands[1]);
1348 fixup_subreg_mem (x)
1351 if (GET_CODE (x) == SUBREG
1352 && GET_CODE (SUBREG_REG (x)) == REG
1353 && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER)
1356 gen_rtx_SUBREG (GET_MODE (x),
1357 reg_equiv_mem [REGNO (SUBREG_REG (x))],
1359 x = alter_subreg (&temp);
1365 /* Check if this move is copying an incoming argument in a7. If so,
1366 emit the move, followed by the special "set_frame_ptr"
1367 unspec_volatile insn, at the very beginning of the function. This
1368 is necessary because the register allocator will ignore conflicts
1369 with a7 and may assign some other pseudo to a7. If that pseudo was
1370 assigned prior to this move, it would clobber the incoming argument
1371 in a7. By copying the argument out of a7 as the very first thing,
1372 and then immediately following that with an unspec_volatile to keep
1373 the scheduler away, we should avoid any problems. */
1376 xtensa_copy_incoming_a7 (operands, mode)
1378 enum machine_mode mode;
1380 if (a7_overlap_mentioned_p (operands[1])
1381 && !cfun->machine->incoming_a7_copied)
1387 mov = gen_movdf_internal (operands[0], operands[1]);
1390 mov = gen_movsf_internal (operands[0], operands[1]);
1393 mov = gen_movdi_internal (operands[0], operands[1]);
1396 mov = gen_movsi_internal (operands[0], operands[1]);
1399 mov = gen_movhi_internal (operands[0], operands[1]);
1402 mov = gen_movqi_internal (operands[0], operands[1]);
1408 /* Insert the instructions before any other argument copies.
1409 (The set_frame_ptr insn comes _after_ the move, so push it
1411 push_topmost_sequence ();
1412 emit_insn_after (gen_set_frame_ptr (), get_insns ());
1413 emit_insn_after (mov, get_insns ());
1414 pop_topmost_sequence ();
1416 /* Ideally the incoming argument in a7 would only be copied
1417 once, since propagating a7 into the body of a function
1418 will almost certainly lead to errors. However, there is
1419 at least one harmless case (in GCSE) where the original
1420 copy from a7 is changed to copy into a new pseudo. Thus,
1421 we use a flag to only do this special treatment for the
1422 first copy of a7. */
1424 cfun->machine->incoming_a7_copied = true;
1433 /* Try to expand a block move operation to an RTL block move instruction.
1434 If not optimizing or if the block size is not a constant or if the
1435 block is small, the expansion fails and GCC falls back to calling
1438 operands[0] is the destination
1439 operands[1] is the source
1440 operands[2] is the length
1441 operands[3] is the alignment */
1444 xtensa_expand_block_move (operands)
1447 rtx dest = operands[0];
1448 rtx src = operands[1];
1449 int bytes = INTVAL (operands[2]);
1450 int align = XINT (operands[3], 0);
1451 int num_pieces, move_ratio;
1453 /* If this is not a fixed size move, just call memcpy */
1454 if (!optimize || (GET_CODE (operands[2]) != CONST_INT))
1457 /* Anything to move? */
1461 if (align > MOVE_MAX)
1464 /* decide whether to expand inline based on the optimization level */
1467 move_ratio = LARGEST_MOVE_RATIO;
1468 num_pieces = (bytes / align) + (bytes % align); /* close enough anyway */
1469 if (num_pieces >= move_ratio)
1472 /* make sure the memory addresses are valid */
1473 operands[0] = validize_mem (dest);
1474 operands[1] = validize_mem (src);
1476 emit_insn (gen_movstrsi_internal (operands[0], operands[1],
1477 operands[2], operands[3]));
1482 /* Emit a sequence of instructions to implement a block move, trying
1483 to hide load delay slots as much as possible. Load N values into
1484 temporary registers, store those N values, and repeat until the
1485 complete block has been moved. N=delay_slots+1 */
1493 xtensa_emit_block_move (operands, tmpregs, delay_slots)
1498 rtx dest = operands[0];
1499 rtx src = operands[1];
1500 int bytes = INTVAL (operands[2]);
1501 int align = XINT (operands[3], 0);
1502 rtx from_addr = XEXP (src, 0);
1503 rtx to_addr = XEXP (dest, 0);
1504 int from_struct = MEM_IN_STRUCT_P (src);
1505 int to_struct = MEM_IN_STRUCT_P (dest);
1507 int chunk_size, item_size;
1508 struct meminsnbuf *ldinsns, *stinsns;
1509 const char *ldname, *stname;
1510 enum machine_mode mode;
1512 if (align > MOVE_MAX)
1515 chunk_size = delay_slots + 1;
1517 ldinsns = (struct meminsnbuf *)
1518 alloca (chunk_size * sizeof (struct meminsnbuf));
1519 stinsns = (struct meminsnbuf *)
1520 alloca (chunk_size * sizeof (struct meminsnbuf));
1522 mode = xtensa_find_mode_for_size (item_size);
1523 item_size = GET_MODE_SIZE (mode);
1524 ldname = xtensa_ld_opcodes[(int) mode];
1525 stname = xtensa_st_opcodes[(int) mode];
1531 for (n = 0; n < chunk_size; n++)
1541 if (bytes < item_size)
1543 /* find a smaller item_size which we can load & store */
1545 mode = xtensa_find_mode_for_size (item_size);
1546 item_size = GET_MODE_SIZE (mode);
1547 ldname = xtensa_ld_opcodes[(int) mode];
1548 stname = xtensa_st_opcodes[(int) mode];
1551 /* record the load instruction opcode and operands */
1552 addr = plus_constant (from_addr, offset);
1553 mem = gen_rtx_MEM (mode, addr);
1554 if (! memory_address_p (mode, addr))
1556 MEM_IN_STRUCT_P (mem) = from_struct;
1557 ldinsns[n].operands[0] = tmpregs[n];
1558 ldinsns[n].operands[1] = mem;
1559 sprintf (ldinsns[n].template, "%s\t%%0, %%1", ldname);
1561 /* record the store instruction opcode and operands */
1562 addr = plus_constant (to_addr, offset);
1563 mem = gen_rtx_MEM (mode, addr);
1564 if (! memory_address_p (mode, addr))
1566 MEM_IN_STRUCT_P (mem) = to_struct;
1567 stinsns[n].operands[0] = tmpregs[n];
1568 stinsns[n].operands[1] = mem;
1569 sprintf (stinsns[n].template, "%s\t%%0, %%1", stname);
1571 offset += item_size;
1575 /* now output the loads followed by the stores */
1576 for (n = 0; n < chunk_size; n++)
1577 output_asm_insn (ldinsns[n].template, ldinsns[n].operands);
1578 for (n = 0; n < chunk_size; n++)
1579 output_asm_insn (stinsns[n].template, stinsns[n].operands);
1584 static enum machine_mode
1585 xtensa_find_mode_for_size (item_size)
1588 enum machine_mode mode, tmode;
1594 /* find mode closest to but not bigger than item_size */
1595 for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
1596 tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
1597 if (GET_MODE_SIZE (tmode) <= item_size)
1599 if (mode == VOIDmode)
1602 item_size = GET_MODE_SIZE (mode);
1604 if (xtensa_ld_opcodes[(int) mode]
1605 && xtensa_st_opcodes[(int) mode])
1608 /* cannot load & store this mode; try something smaller */
1617 xtensa_expand_nonlocal_goto (operands)
1620 rtx goto_handler = operands[1];
1621 rtx containing_fp = operands[3];
1623 /* generate a call to "__xtensa_nonlocal_goto" (in libgcc); the code
1624 is too big to generate in-line */
1626 if (GET_CODE (containing_fp) != REG)
1627 containing_fp = force_reg (Pmode, containing_fp);
1629 goto_handler = replace_rtx (copy_rtx (goto_handler),
1630 virtual_stack_vars_rtx,
1633 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__xtensa_nonlocal_goto"),
1635 containing_fp, Pmode,
1636 goto_handler, Pmode);
1640 static struct machine_function *
1641 xtensa_init_machine_status ()
1643 return ggc_alloc_cleared (sizeof (struct machine_function));
1648 xtensa_setup_frame_addresses ()
1650 /* Set flag to cause FRAME_POINTER_REQUIRED to be set. */
1651 cfun->machine->accesses_prev_frame = 1;
1654 (gen_rtx_SYMBOL_REF (Pmode, "__xtensa_libgcc_window_spill"),
1659 /* Emit the assembly for the end of a zero-cost loop. Normally we just emit
1660 a comment showing where the end of the loop is. However, if there is a
1661 label or a branch at the end of the loop then we need to place a nop
1662 there. If the loop ends with a label we need the nop so that branches
1663 targetting that label will target the nop (and thus remain in the loop),
1664 instead of targetting the instruction after the loop (and thus exiting
1665 the loop). If the loop ends with a branch, we need the nop in case the
1666 branch is targetting a location inside the loop. When the branch
1667 executes it will cause the loop count to be decremented even if it is
1668 taken (because it is the last instruction in the loop), so we need to
1669 nop after the branch to prevent the loop count from being decremented
1670 when the branch is taken. */
1673 xtensa_emit_loop_end (insn, operands)
1679 for (insn = PREV_INSN (insn); insn && !done; insn = PREV_INSN (insn))
1681 switch (GET_CODE (insn))
1688 output_asm_insn (TARGET_DENSITY ? "nop.n" : "nop", operands);
1694 rtx body = PATTERN (insn);
1696 if (GET_CODE (body) == JUMP_INSN)
1698 output_asm_insn (TARGET_DENSITY ? "nop.n" : "nop", operands);
1701 else if ((GET_CODE (body) != USE)
1702 && (GET_CODE (body) != CLOBBER))
1709 output_asm_insn ("# loop end for %0", operands);
1714 xtensa_emit_call (callop, operands)
1718 static char result[64];
1719 rtx tgt = operands[callop];
1721 if (GET_CODE (tgt) == CONST_INT)
1722 sprintf (result, "call8\t0x%lx", INTVAL (tgt));
1723 else if (register_operand (tgt, VOIDmode))
1724 sprintf (result, "callx8\t%%%d", callop);
1726 sprintf (result, "call8\t%%%d", callop);
1732 /* Return the stabs register number to use for 'regno'. */
1735 xtensa_dbx_register_number (regno)
1740 if (GP_REG_P (regno))
1742 regno -= GP_REG_FIRST;
1745 else if (BR_REG_P (regno))
1747 regno -= BR_REG_FIRST;
1750 else if (FP_REG_P (regno))
1752 regno -= FP_REG_FIRST;
1753 /* The current numbering convention is that TIE registers are
1754 numbered in libcc order beginning with 256. We can't guarantee
1755 that the FP registers will come first, so the following is just
1756 a guess. It seems like we should make a special case for FP
1757 registers and give them fixed numbers < 256. */
1760 else if (ACC_REG_P (regno))
1766 /* When optimizing, we sometimes get asked about pseudo-registers
1767 that don't represent hard registers. Return 0 for these. */
1771 return first + regno;
1775 /* Argument support functions. */
1777 /* Initialize CUMULATIVE_ARGS for a function. */
1780 init_cumulative_args (cum, fntype, libname)
1781 CUMULATIVE_ARGS *cum; /* argument info to initialize */
1782 tree fntype ATTRIBUTE_UNUSED; /* tree ptr for function decl */
1783 rtx libname ATTRIBUTE_UNUSED; /* SYMBOL_REF of library name or 0 */
1788 /* Advance the argument to the next argument position. */
1791 function_arg_advance (cum, mode, type)
1792 CUMULATIVE_ARGS *cum; /* current arg information */
1793 enum machine_mode mode; /* current arg mode */
1794 tree type; /* type of the argument or 0 if lib support */
1799 arg_words = &cum->arg_words;
1800 max = MAX_ARGS_IN_REGISTERS;
1802 words = (((mode != BLKmode)
1803 ? (int) GET_MODE_SIZE (mode)
1804 : int_size_in_bytes (type)) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1806 if ((*arg_words + words > max) && (*arg_words < max))
1809 *arg_words += words;
1813 /* Return an RTL expression containing the register for the given mode,
1814 or 0 if the argument is to be passed on the stack. */
1817 function_arg (cum, mode, type, incoming_p)
1818 CUMULATIVE_ARGS *cum; /* current arg information */
1819 enum machine_mode mode; /* current arg mode */
1820 tree type; /* type of the argument or 0 if lib support */
1821 int incoming_p; /* computing the incoming registers? */
1823 int regbase, words, max;
1826 enum machine_mode result_mode;
1828 arg_words = &cum->arg_words;
1829 regbase = (incoming_p ? GP_ARG_FIRST : GP_OUTGOING_ARG_FIRST);
1830 max = MAX_ARGS_IN_REGISTERS;
1832 words = (((mode != BLKmode)
1833 ? (int) GET_MODE_SIZE (mode)
1834 : int_size_in_bytes (type)) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1836 if (type && (TYPE_ALIGN (type) > BITS_PER_WORD))
1837 *arg_words += (*arg_words & 1);
1839 if (*arg_words + words > max)
1842 regno = regbase + *arg_words;
1843 result_mode = (mode == BLKmode ? TYPE_MODE (type) : mode);
1845 /* We need to make sure that references to a7 are represented with
1846 rtx that is not equal to hard_frame_pointer_rtx. For BLKmode and
1847 modes bigger than 2 words (because we only have patterns for
1848 modes of 2 words or smaller), we can't control the expansion
1849 unless we explicitly list the individual registers in a PARALLEL. */
1851 if ((mode == BLKmode || words > 2)
1853 && regno + words > A7_REG)
1858 result = gen_rtx_PARALLEL (result_mode, rtvec_alloc (words));
1859 for (n = 0; n < words; n++)
1861 XVECEXP (result, 0, n) =
1862 gen_rtx_EXPR_LIST (VOIDmode,
1863 gen_raw_REG (SImode, regno + n),
1864 GEN_INT (n * UNITS_PER_WORD));
1869 return gen_raw_REG (result_mode, regno);
1877 enum machine_mode mode;
1879 if (!TARGET_BOOLEANS && TARGET_HARD_FLOAT)
1880 error ("boolean registers required for the floating-point option");
1882 /* set up the tables of ld/st opcode names for block moves */
1883 xtensa_ld_opcodes[(int) SImode] = "l32i";
1884 xtensa_ld_opcodes[(int) HImode] = "l16ui";
1885 xtensa_ld_opcodes[(int) QImode] = "l8ui";
1886 xtensa_st_opcodes[(int) SImode] = "s32i";
1887 xtensa_st_opcodes[(int) HImode] = "s16i";
1888 xtensa_st_opcodes[(int) QImode] = "s8i";
1890 xtensa_char_to_class['q'] = SP_REG;
1891 xtensa_char_to_class['a'] = GR_REGS;
1892 xtensa_char_to_class['b'] = ((TARGET_BOOLEANS) ? BR_REGS : NO_REGS);
1893 xtensa_char_to_class['f'] = ((TARGET_HARD_FLOAT) ? FP_REGS : NO_REGS);
1894 xtensa_char_to_class['A'] = ((TARGET_MAC16) ? ACC_REG : NO_REGS);
1895 xtensa_char_to_class['B'] = ((TARGET_SEXT) ? GR_REGS : NO_REGS);
1896 xtensa_char_to_class['C'] = ((TARGET_MUL16) ? GR_REGS: NO_REGS);
1897 xtensa_char_to_class['D'] = ((TARGET_DENSITY) ? GR_REGS: NO_REGS);
1898 xtensa_char_to_class['d'] = ((TARGET_DENSITY) ? AR_REGS: NO_REGS);
1899 xtensa_char_to_class['W'] = ((TARGET_CONST16) ? GR_REGS: NO_REGS);
1901 /* Set up array giving whether a given register can hold a given mode. */
1902 for (mode = VOIDmode;
1903 mode != MAX_MACHINE_MODE;
1904 mode = (enum machine_mode) ((int) mode + 1))
1906 int size = GET_MODE_SIZE (mode);
1907 enum mode_class class = GET_MODE_CLASS (mode);
1909 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1913 if (ACC_REG_P (regno))
1914 temp = (TARGET_MAC16
1915 && (class == MODE_INT) && (size <= UNITS_PER_WORD));
1916 else if (GP_REG_P (regno))
1917 temp = ((regno & 1) == 0 || (size <= UNITS_PER_WORD));
1918 else if (FP_REG_P (regno))
1919 temp = (TARGET_HARD_FLOAT && (mode == SFmode));
1920 else if (BR_REG_P (regno))
1921 temp = (TARGET_BOOLEANS && (mode == CCmode));
1925 xtensa_hard_regno_mode_ok[(int) mode][regno] = temp;
1929 init_machine_status = xtensa_init_machine_status;
1931 /* Check PIC settings. PIC is only supported when using L32R
1932 instructions, and some targets need to always use PIC. */
1933 if (flag_pic && TARGET_CONST16)
1934 error ("-f%s is not supported with CONST16 instructions",
1935 (flag_pic > 1 ? "PIC" : "pic"));
1936 else if (XTENSA_ALWAYS_PIC)
1939 error ("PIC is required but not supported with CONST16 instructions");
1942 /* There's no need for -fPIC (as opposed to -fpic) on Xtensa. */
1948 /* A C compound statement to output to stdio stream STREAM the
1949 assembler syntax for an instruction operand X. X is an RTL
1952 CODE is a value that can be used to specify one of several ways
1953 of printing the operand. It is used when identical operands
1954 must be printed differently depending on the context. CODE
1955 comes from the '%' specification that was used to request
1956 printing of the operand. If the specification was just '%DIGIT'
1957 then CODE is 0; if the specification was '%LTR DIGIT' then CODE
1958 is the ASCII code for LTR.
1960 If X is a register, this macro should print the register's name.
1961 The names can be found in an array 'reg_names' whose type is
1962 'char *[]'. 'reg_names' is initialized from 'REGISTER_NAMES'.
1964 When the machine description has a specification '%PUNCT' (a '%'
1965 followed by a punctuation character), this macro is called with
1966 a null pointer for X and the punctuation character for CODE.
1968 'a', 'c', 'l', and 'n' are reserved.
1970 The Xtensa specific codes are:
1972 'd' CONST_INT, print as signed decimal
1973 'x' CONST_INT, print as signed hexadecimal
1974 'K' CONST_INT, print number of bits in mask for EXTUI
1975 'R' CONST_INT, print (X & 0x1f)
1976 'L' CONST_INT, print ((32 - X) & 0x1f)
1977 'D' REG, print second register of double-word register operand
1978 'N' MEM, print address of next word following a memory operand
1979 'v' MEM, if memory reference is volatile, output a MEMW before it
1980 't' any constant, add "@h" suffix for top 16 bits
1981 'b' any constant, add "@l" suffix for bottom 16 bits
1989 /* print a hexadecimal value in a nice way */
1990 if ((val > -0xa) && (val < 0xa))
1991 fprintf (file, "%d", val);
1993 fprintf (file, "-0x%x", -val);
1995 fprintf (file, "0x%x", val);
2000 print_operand (file, x, letter)
2001 FILE *file; /* file to write to */
2002 rtx x; /* operand to print */
2003 int letter; /* %<letter> or 0 */
2006 error ("PRINT_OPERAND null pointer");
2011 if (GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
2012 fprintf (file, "%s", reg_names[xt_true_regnum (x) + 1]);
2014 output_operand_lossage ("invalid %%D value");
2018 if (GET_CODE (x) == MEM)
2020 /* For a volatile memory reference, emit a MEMW before the
2022 if (MEM_VOLATILE_P (x))
2023 fprintf (file, "memw\n\t");
2026 output_operand_lossage ("invalid %%v value");
2030 if (GET_CODE (x) == MEM
2031 && (GET_MODE (x) == DFmode || GET_MODE (x) == DImode))
2033 x = adjust_address (x, GET_MODE (x) == DFmode ? SFmode : SImode, 4);
2034 output_address (XEXP (x, 0));
2037 output_operand_lossage ("invalid %%N value");
2041 if (GET_CODE (x) == CONST_INT)
2044 unsigned val = INTVAL (x);
2050 if ((val != 0) || (num_bits == 0) || (num_bits > 16))
2051 fatal_insn ("invalid mask", x);
2053 fprintf (file, "%d", num_bits);
2056 output_operand_lossage ("invalid %%K value");
2060 if (GET_CODE (x) == CONST_INT)
2061 fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
2063 output_operand_lossage ("invalid %%L value");
2067 if (GET_CODE (x) == CONST_INT)
2068 fprintf (file, "%ld", INTVAL (x) & 0x1f);
2070 output_operand_lossage ("invalid %%R value");
2074 if (GET_CODE (x) == CONST_INT)
2075 printx (file, INTVAL (x));
2077 output_operand_lossage ("invalid %%x value");
2081 if (GET_CODE (x) == CONST_INT)
2082 fprintf (file, "%ld", INTVAL (x));
2084 output_operand_lossage ("invalid %%d value");
2089 if (GET_CODE (x) == CONST_INT)
2091 printx (file, INTVAL (x));
2092 fputs (letter == 't' ? "@h" : "@l", file);
2094 else if (GET_CODE (x) == CONST_DOUBLE)
2097 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2098 if (GET_MODE (x) == SFmode)
2101 REAL_VALUE_TO_TARGET_SINGLE (r, l);
2102 fprintf (file, "0x%08lx@%c", l, letter == 't' ? 'h' : 'l');
2105 output_operand_lossage ("invalid %%t/%%b value");
2107 else if (GET_CODE (x) == CONST)
2109 /* X must be a symbolic constant on ELF. Write an expression
2110 suitable for 'const16' that sets the high or low 16 bits. */
2111 if (GET_CODE (XEXP (x, 0)) != PLUS
2112 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
2113 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
2114 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
2115 output_operand_lossage ("invalid %%t/%%b value");
2116 print_operand (file, XEXP (XEXP (x, 0), 0), 0);
2117 fputs (letter == 't' ? "@h" : "@l", file);
2118 /* There must be a non-alphanumeric character between 'h' or 'l'
2119 and the number. The '-' is added by print_operand() already. */
2120 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
2122 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
2126 output_addr_const (file, x);
2127 fputs (letter == 't' ? "@h" : "@l", file);
2132 if (GET_CODE (x) == REG || GET_CODE (x) == SUBREG)
2133 fprintf (file, "%s", reg_names[xt_true_regnum (x)]);
2134 else if (GET_CODE (x) == MEM)
2135 output_address (XEXP (x, 0));
2136 else if (GET_CODE (x) == CONST_INT)
2137 fprintf (file, "%ld", INTVAL (x));
2139 output_addr_const (file, x);
2144 /* A C compound statement to output to stdio stream STREAM the
2145 assembler syntax for an instruction operand that is a memory
2146 reference whose address is ADDR. ADDR is an RTL expression. */
2149 print_operand_address (file, addr)
2154 error ("PRINT_OPERAND_ADDRESS, null pointer");
2156 switch (GET_CODE (addr))
2159 fatal_insn ("invalid address", addr);
2163 fprintf (file, "%s, 0", reg_names [REGNO (addr)]);
2169 rtx offset = (rtx)0;
2170 rtx arg0 = XEXP (addr, 0);
2171 rtx arg1 = XEXP (addr, 1);
2173 if (GET_CODE (arg0) == REG)
2178 else if (GET_CODE (arg1) == REG)
2184 fatal_insn ("no register in address", addr);
2186 if (CONSTANT_P (offset))
2188 fprintf (file, "%s, ", reg_names [REGNO (reg)]);
2189 output_addr_const (file, offset);
2192 fatal_insn ("address offset not a constant", addr);
2200 output_addr_const (file, addr);
2207 xtensa_output_literal (file, x, mode, labelno)
2210 enum machine_mode mode;
2217 fprintf (file, "\t.literal .LC%u, ", (unsigned) labelno);
2219 switch (GET_MODE_CLASS (mode))
2222 if (GET_CODE (x) != CONST_DOUBLE)
2225 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2229 REAL_VALUE_TO_TARGET_SINGLE (r, value_long[0]);
2230 fprintf (file, "0x%08lx\n", value_long[0]);
2234 REAL_VALUE_TO_TARGET_DOUBLE (r, value_long);
2235 fprintf (file, "0x%08lx, 0x%08lx\n",
2236 value_long[0], value_long[1]);
2246 case MODE_PARTIAL_INT:
2247 size = GET_MODE_SIZE (mode);
2250 output_addr_const (file, x);
2255 output_addr_const (file, operand_subword (x, 0, 0, DImode));
2257 output_addr_const (file, operand_subword (x, 1, 0, DImode));
2270 /* Return the bytes needed to compute the frame pointer from the current
2273 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
2274 #define XTENSA_STACK_ALIGN(LOC) (((LOC) + STACK_BYTES-1) & ~(STACK_BYTES-1))
2277 compute_frame_size (size)
2278 int size; /* # of var. bytes allocated */
2280 /* add space for the incoming static chain value */
2281 if (current_function_needs_context)
2282 size += (1 * UNITS_PER_WORD);
2284 xtensa_current_frame_size =
2285 XTENSA_STACK_ALIGN (size
2286 + current_function_outgoing_args_size
2287 + (WINDOW_SIZE * UNITS_PER_WORD));
2288 return xtensa_current_frame_size;
2293 xtensa_frame_pointer_required ()
2295 /* The code to expand builtin_frame_addr and builtin_return_addr
2296 currently uses the hard_frame_pointer instead of frame_pointer.
2297 This seems wrong but maybe it's necessary for other architectures.
2298 This function is derived from the i386 code. */
2300 if (cfun->machine->accesses_prev_frame)
2308 xtensa_expand_prologue ()
2310 HOST_WIDE_INT total_size;
2313 total_size = compute_frame_size (get_frame_size ());
2314 size_rtx = GEN_INT (total_size);
2316 if (total_size < (1 << (12+3)))
2317 emit_insn (gen_entry (size_rtx, size_rtx));
2320 /* Use a8 as a temporary since a0-a7 may be live. */
2321 rtx tmp_reg = gen_rtx_REG (Pmode, A8_REG);
2322 emit_insn (gen_entry (size_rtx, GEN_INT (MIN_FRAME_SIZE)));
2323 emit_move_insn (tmp_reg, GEN_INT (total_size - MIN_FRAME_SIZE));
2324 emit_insn (gen_subsi3 (tmp_reg, stack_pointer_rtx, tmp_reg));
2325 emit_move_insn (stack_pointer_rtx, tmp_reg);
2328 if (frame_pointer_needed)
2330 rtx first, insn, set_frame_ptr_insn = 0;
2332 push_topmost_sequence ();
2333 first = get_insns ();
2334 pop_topmost_sequence ();
2336 /* Search all instructions, looking for the insn that sets up the
2337 frame pointer. This search will fail if the function does not
2338 have an incoming argument in $a7, but in that case, we can just
2339 set up the frame pointer at the very beginning of the
2342 for (insn = first; insn; insn = NEXT_INSN (insn))
2349 pat = PATTERN (insn);
2350 if (GET_CODE (pat) == SET
2351 && GET_CODE (SET_SRC (pat)) == UNSPEC_VOLATILE
2352 && (XINT (SET_SRC (pat), 1) == UNSPECV_SET_FP))
2354 set_frame_ptr_insn = insn;
2359 if (set_frame_ptr_insn)
2361 /* For all instructions prior to set_frame_ptr_insn, replace
2362 hard_frame_pointer references with stack_pointer. */
2364 insn != set_frame_ptr_insn;
2365 insn = NEXT_INSN (insn))
2368 PATTERN (insn) = replace_rtx (copy_rtx (PATTERN (insn)),
2369 hard_frame_pointer_rtx,
2374 emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
2379 /* Clear variables at function end. */
2382 xtensa_function_epilogue (file, size)
2383 FILE *file ATTRIBUTE_UNUSED;
2384 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
2386 xtensa_current_frame_size = 0;
2391 xtensa_return_addr (count, frame)
2395 rtx result, retaddr;
2398 retaddr = gen_rtx_REG (Pmode, A0_REG);
2401 rtx addr = plus_constant (frame, -4 * UNITS_PER_WORD);
2402 addr = memory_address (Pmode, addr);
2403 retaddr = gen_reg_rtx (Pmode);
2404 emit_move_insn (retaddr, gen_rtx_MEM (Pmode, addr));
2407 /* The 2 most-significant bits of the return address on Xtensa hold
2408 the register window size. To get the real return address, these
2409 bits must be replaced with the high bits from the current PC. */
2411 result = gen_reg_rtx (Pmode);
2412 emit_insn (gen_fix_return_addr (result, retaddr));
2417 /* Create the va_list data type.
2418 This structure is set up by __builtin_saveregs. The __va_reg
2419 field points to a stack-allocated region holding the contents of the
2420 incoming argument registers. The __va_ndx field is an index initialized
2421 to the position of the first unnamed (variable) argument. This same index
2422 is also used to address the arguments passed in memory. Thus, the
2423 __va_stk field is initialized to point to the position of the first
2424 argument in memory offset to account for the arguments passed in
2425 registers. E.G., if there are 6 argument registers, and each register is
2426 4 bytes, then __va_stk is set to $sp - (6 * 4); then __va_reg[N*4]
2427 references argument word N for 0 <= N < 6, and __va_stk[N*4] references
2428 argument word N for N >= 6. */
2431 xtensa_build_va_list ()
2433 tree f_stk, f_reg, f_ndx, record, type_decl;
2435 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
2436 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
2438 f_stk = build_decl (FIELD_DECL, get_identifier ("__va_stk"),
2440 f_reg = build_decl (FIELD_DECL, get_identifier ("__va_reg"),
2442 f_ndx = build_decl (FIELD_DECL, get_identifier ("__va_ndx"),
2445 DECL_FIELD_CONTEXT (f_stk) = record;
2446 DECL_FIELD_CONTEXT (f_reg) = record;
2447 DECL_FIELD_CONTEXT (f_ndx) = record;
2449 TREE_CHAIN (record) = type_decl;
2450 TYPE_NAME (record) = type_decl;
2451 TYPE_FIELDS (record) = f_stk;
2452 TREE_CHAIN (f_stk) = f_reg;
2453 TREE_CHAIN (f_reg) = f_ndx;
2455 layout_type (record);
2460 /* Save the incoming argument registers on the stack. Returns the
2461 address of the saved registers. */
2464 xtensa_builtin_saveregs ()
2467 int arg_words = current_function_arg_words;
2468 int gp_left = MAX_ARGS_IN_REGISTERS - arg_words;
2474 /* allocate the general-purpose register space */
2475 gp_regs = assign_stack_local
2476 (BLKmode, MAX_ARGS_IN_REGISTERS * UNITS_PER_WORD, -1);
2477 set_mem_alias_set (gp_regs, get_varargs_alias_set ());
2479 /* Now store the incoming registers. */
2480 dest = change_address (gp_regs, SImode,
2481 plus_constant (XEXP (gp_regs, 0),
2482 arg_words * UNITS_PER_WORD));
2484 /* Note: Don't use move_block_from_reg() here because the incoming
2485 argument in a7 cannot be represented by hard_frame_pointer_rtx.
2486 Instead, call gen_raw_REG() directly so that we get a distinct
2487 instance of (REG:SI 7). */
2488 for (i = 0; i < gp_left; i++)
2490 emit_move_insn (operand_subword (dest, i, 1, BLKmode),
2491 gen_raw_REG (SImode, GP_ARG_FIRST + arg_words + i));
2494 return XEXP (gp_regs, 0);
2498 /* Implement `va_start' for varargs and stdarg. We look at the
2499 current function to fill in an initial va_list. */
2502 xtensa_va_start (valist, nextarg)
2504 rtx nextarg ATTRIBUTE_UNUSED;
2512 arg_words = current_function_args_info.arg_words;
2514 f_stk = TYPE_FIELDS (va_list_type_node);
2515 f_reg = TREE_CHAIN (f_stk);
2516 f_ndx = TREE_CHAIN (f_reg);
2518 stk = build (COMPONENT_REF, TREE_TYPE (f_stk), valist, f_stk);
2519 reg = build (COMPONENT_REF, TREE_TYPE (f_reg), valist, f_reg);
2520 ndx = build (COMPONENT_REF, TREE_TYPE (f_ndx), valist, f_ndx);
2522 /* Call __builtin_saveregs; save the result in __va_reg */
2523 current_function_arg_words = arg_words;
2524 u = make_tree (ptr_type_node, expand_builtin_saveregs ());
2525 t = build (MODIFY_EXPR, ptr_type_node, reg, u);
2526 TREE_SIDE_EFFECTS (t) = 1;
2527 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2529 /* Set the __va_stk member to $arg_ptr - (size of __va_reg area) */
2530 u = make_tree (ptr_type_node, virtual_incoming_args_rtx);
2531 u = fold (build (PLUS_EXPR, ptr_type_node, u,
2532 build_int_2 (-MAX_ARGS_IN_REGISTERS * UNITS_PER_WORD, -1)));
2533 t = build (MODIFY_EXPR, ptr_type_node, stk, u);
2534 TREE_SIDE_EFFECTS (t) = 1;
2535 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2537 /* Set the __va_ndx member. */
2538 u = build_int_2 (arg_words * UNITS_PER_WORD, 0);
2539 t = build (MODIFY_EXPR, integer_type_node, ndx, u);
2540 TREE_SIDE_EFFECTS (t) = 1;
2541 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2545 /* Implement `va_arg'. */
2548 xtensa_va_arg (valist, type)
2554 tree tmp, addr_tree, type_size;
2555 rtx array, orig_ndx, r, addr, size, va_size;
2556 rtx lab_false, lab_over, lab_false2;
2558 f_stk = TYPE_FIELDS (va_list_type_node);
2559 f_reg = TREE_CHAIN (f_stk);
2560 f_ndx = TREE_CHAIN (f_reg);
2562 stk = build (COMPONENT_REF, TREE_TYPE (f_stk), valist, f_stk);
2563 reg = build (COMPONENT_REF, TREE_TYPE (f_reg), valist, f_reg);
2564 ndx = build (COMPONENT_REF, TREE_TYPE (f_ndx), valist, f_ndx);
2566 type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type));
2568 va_size = gen_reg_rtx (SImode);
2569 tmp = fold (build (MULT_EXPR, sizetype,
2570 fold (build (TRUNC_DIV_EXPR, sizetype,
2571 fold (build (PLUS_EXPR, sizetype,
2573 size_int (UNITS_PER_WORD - 1))),
2574 size_int (UNITS_PER_WORD))),
2575 size_int (UNITS_PER_WORD)));
2576 r = expand_expr (tmp, va_size, SImode, EXPAND_NORMAL);
2578 emit_move_insn (va_size, r);
2581 /* First align __va_ndx to a double word boundary if necessary for this arg:
2583 if (__alignof__ (TYPE) > 4)
2584 (AP).__va_ndx = (((AP).__va_ndx + 7) & -8)
2587 if (TYPE_ALIGN (type) > BITS_PER_WORD)
2589 tmp = build (PLUS_EXPR, integer_type_node, ndx,
2590 build_int_2 ((2 * UNITS_PER_WORD) - 1, 0));
2591 tmp = build (BIT_AND_EXPR, integer_type_node, tmp,
2592 build_int_2 (-2 * UNITS_PER_WORD, -1));
2593 tmp = build (MODIFY_EXPR, integer_type_node, ndx, tmp);
2594 TREE_SIDE_EFFECTS (tmp) = 1;
2595 expand_expr (tmp, const0_rtx, VOIDmode, EXPAND_NORMAL);
2599 /* Increment __va_ndx to point past the argument:
2601 orig_ndx = (AP).__va_ndx;
2602 (AP).__va_ndx += __va_size (TYPE);
2605 orig_ndx = gen_reg_rtx (SImode);
2606 r = expand_expr (ndx, orig_ndx, SImode, EXPAND_NORMAL);
2608 emit_move_insn (orig_ndx, r);
2610 tmp = build (PLUS_EXPR, integer_type_node, ndx,
2611 make_tree (intSI_type_node, va_size));
2612 tmp = build (MODIFY_EXPR, integer_type_node, ndx, tmp);
2613 TREE_SIDE_EFFECTS (tmp) = 1;
2614 expand_expr (tmp, const0_rtx, VOIDmode, EXPAND_NORMAL);
2617 /* Check if the argument is in registers:
2619 if ((AP).__va_ndx <= __MAX_ARGS_IN_REGISTERS * 4
2620 && !MUST_PASS_IN_STACK (type))
2621 __array = (AP).__va_reg;
2624 array = gen_reg_rtx (Pmode);
2626 lab_over = NULL_RTX;
2627 if (!MUST_PASS_IN_STACK (VOIDmode, type))
2629 lab_false = gen_label_rtx ();
2630 lab_over = gen_label_rtx ();
2632 emit_cmp_and_jump_insns (expand_expr (ndx, NULL_RTX, SImode,
2634 GEN_INT (MAX_ARGS_IN_REGISTERS
2636 GT, const1_rtx, SImode, 0, lab_false);
2638 r = expand_expr (reg, array, Pmode, EXPAND_NORMAL);
2640 emit_move_insn (array, r);
2642 emit_jump_insn (gen_jump (lab_over));
2644 emit_label (lab_false);
2647 /* ...otherwise, the argument is on the stack (never split between
2648 registers and the stack -- change __va_ndx if necessary):
2652 if (orig_ndx < __MAX_ARGS_IN_REGISTERS * 4)
2653 (AP).__va_ndx = __MAX_ARGS_IN_REGISTERS * 4 + __va_size (TYPE);
2654 __array = (AP).__va_stk;
2658 lab_false2 = gen_label_rtx ();
2659 emit_cmp_and_jump_insns (orig_ndx,
2660 GEN_INT (MAX_ARGS_IN_REGISTERS * UNITS_PER_WORD),
2661 GE, const1_rtx, SImode, 0, lab_false2);
2663 tmp = build (PLUS_EXPR, sizetype, make_tree (intSI_type_node, va_size),
2664 build_int_2 (MAX_ARGS_IN_REGISTERS * UNITS_PER_WORD, 0));
2665 tmp = build (MODIFY_EXPR, integer_type_node, ndx, tmp);
2666 TREE_SIDE_EFFECTS (tmp) = 1;
2667 expand_expr (tmp, const0_rtx, VOIDmode, EXPAND_NORMAL);
2669 emit_label (lab_false2);
2671 r = expand_expr (stk, array, Pmode, EXPAND_NORMAL);
2673 emit_move_insn (array, r);
2675 if (lab_over != NULL_RTX)
2676 emit_label (lab_over);
2679 /* Given the base array pointer (__array) and index to the subsequent
2680 argument (__va_ndx), find the address:
2682 __array + (AP).__va_ndx - (BYTES_BIG_ENDIAN && sizeof (TYPE) < 4
2686 The results are endian-dependent because values smaller than one word
2687 are aligned differently.
2690 size = gen_reg_rtx (SImode);
2691 emit_move_insn (size, va_size);
2693 if (BYTES_BIG_ENDIAN)
2695 rtx lab_use_va_size = gen_label_rtx ();
2697 emit_cmp_and_jump_insns (expand_expr (type_size, NULL_RTX, SImode,
2699 GEN_INT (PARM_BOUNDARY / BITS_PER_UNIT),
2700 GE, const1_rtx, SImode, 0, lab_use_va_size);
2702 r = expand_expr (type_size, size, SImode, EXPAND_NORMAL);
2704 emit_move_insn (size, r);
2706 emit_label (lab_use_va_size);
2709 addr_tree = build (PLUS_EXPR, ptr_type_node,
2710 make_tree (ptr_type_node, array),
2712 addr_tree = build (MINUS_EXPR, ptr_type_node, addr_tree,
2713 make_tree (intSI_type_node, size));
2714 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2715 addr = copy_to_reg (addr);
2721 xtensa_preferred_reload_class (x, class, isoutput)
2723 enum reg_class class;
2726 if (!isoutput && CONSTANT_P (x) && GET_CODE (x) == CONST_DOUBLE)
2729 /* Don't use the stack pointer or hard frame pointer for reloads!
2730 The hard frame pointer would normally be OK except that it may
2731 briefly hold an incoming argument in the prologue, and reload
2732 won't know that it is live because the hard frame pointer is
2733 treated specially. */
2735 if (class == AR_REGS || class == GR_REGS)
2743 xtensa_secondary_reload_class (class, mode, x, isoutput)
2744 enum reg_class class;
2745 enum machine_mode mode ATTRIBUTE_UNUSED;
2751 if (GET_CODE (x) == SIGN_EXTEND)
2753 regno = xt_true_regnum (x);
2757 if (class == FP_REGS && constantpool_mem_p (x))
2761 if (ACC_REG_P (regno))
2762 return ((class == GR_REGS || class == RL_REGS) ? NO_REGS : RL_REGS);
2763 if (class == ACC_REG)
2764 return (GP_REG_P (regno) ? NO_REGS : RL_REGS);
2771 order_regs_for_local_alloc ()
2773 if (!leaf_function_p ())
2775 memcpy (reg_alloc_order, reg_nonleaf_alloc_order,
2776 FIRST_PSEUDO_REGISTER * sizeof (int));
2780 int i, num_arg_regs;
2783 /* use the AR registers in increasing order (skipping a0 and a1)
2784 but save the incoming argument registers for a last resort */
2785 num_arg_regs = current_function_args_info.arg_words;
2786 if (num_arg_regs > MAX_ARGS_IN_REGISTERS)
2787 num_arg_regs = MAX_ARGS_IN_REGISTERS;
2788 for (i = GP_ARG_FIRST; i < 16 - num_arg_regs; i++)
2789 reg_alloc_order[nxt++] = i + num_arg_regs;
2790 for (i = 0; i < num_arg_regs; i++)
2791 reg_alloc_order[nxt++] = GP_ARG_FIRST + i;
2793 /* list the coprocessor registers in order */
2794 for (i = 0; i < BR_REG_NUM; i++)
2795 reg_alloc_order[nxt++] = BR_REG_FIRST + i;
2797 /* list the FP registers in order for now */
2798 for (i = 0; i < 16; i++)
2799 reg_alloc_order[nxt++] = FP_REG_FIRST + i;
2801 /* GCC requires that we list *all* the registers.... */
2802 reg_alloc_order[nxt++] = 0; /* a0 = return address */
2803 reg_alloc_order[nxt++] = 1; /* a1 = stack pointer */
2804 reg_alloc_order[nxt++] = 16; /* pseudo frame pointer */
2805 reg_alloc_order[nxt++] = 17; /* pseudo arg pointer */
2807 reg_alloc_order[nxt++] = ACC_REG_FIRST; /* MAC16 accumulator */
2812 /* A customized version of reg_overlap_mentioned_p that only looks for
2813 references to a7 (as opposed to hard_frame_pointer_rtx). */
2816 a7_overlap_mentioned_p (x)
2820 unsigned int x_regno;
2823 if (GET_CODE (x) == REG)
2825 x_regno = REGNO (x);
2826 return (x != hard_frame_pointer_rtx
2827 && x_regno < A7_REG + 1
2828 && x_regno + HARD_REGNO_NREGS (A7_REG, GET_MODE (x)) > A7_REG);
2831 if (GET_CODE (x) == SUBREG
2832 && GET_CODE (SUBREG_REG (x)) == REG
2833 && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
2835 x_regno = subreg_regno (x);
2836 return (SUBREG_REG (x) != hard_frame_pointer_rtx
2837 && x_regno < A7_REG + 1
2838 && x_regno + HARD_REGNO_NREGS (A7_REG, GET_MODE (x)) > A7_REG);
2841 /* X does not match, so try its subexpressions. */
2842 fmt = GET_RTX_FORMAT (GET_CODE (x));
2843 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
2847 if (a7_overlap_mentioned_p (XEXP (x, i)))
2850 else if (fmt[i] == 'E')
2852 for (j = XVECLEN (x, i) - 1; j >=0; j--)
2853 if (a7_overlap_mentioned_p (XVECEXP (x, i, j)))
2862 /* Some Xtensa targets support multiple bss sections. If the section
2863 name ends with ".bss", add SECTION_BSS to the flags. */
2866 xtensa_multibss_section_type_flags (decl, name, reloc)
2871 unsigned int flags = default_section_type_flags (decl, name, reloc);
2874 suffix = strrchr (name, '.');
2875 if (suffix && strcmp (suffix, ".bss") == 0)
2877 if (!decl || (TREE_CODE (decl) == VAR_DECL
2878 && DECL_INITIAL (decl) == NULL_TREE))
2879 flags |= SECTION_BSS; /* @nobits */
2881 warning ("only uninitialized variables can be placed in a "
2889 /* The literal pool stays with the function. */
2892 xtensa_select_rtx_section (mode, x, align)
2893 enum machine_mode mode ATTRIBUTE_UNUSED;
2894 rtx x ATTRIBUTE_UNUSED;
2895 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
2897 function_section (current_function_decl);
2900 /* Compute a (partial) cost for rtx X. Return true if the complete
2901 cost has been computed, and false if subexpressions should be
2902 scanned. In either case, *TOTAL contains the cost result. */
2905 xtensa_rtx_costs (x, code, outer_code, total)
2907 int code, outer_code;
2916 if (xtensa_simm12b (INTVAL (x)))
2923 if (xtensa_simm8 (INTVAL (x))
2924 || xtensa_simm8x256 (INTVAL (x)))
2931 if (xtensa_mask_immediate (INTVAL (x)))
2938 if ((INTVAL (x) == 0) || xtensa_b4const (INTVAL (x)))
2949 /* no way to tell if X is the 2nd operand so be conservative */
2952 if (xtensa_simm12b (INTVAL (x)))
2954 else if (TARGET_CONST16)
2955 *total = COSTS_N_INSNS (2);
2964 *total = COSTS_N_INSNS (2);
2971 *total = COSTS_N_INSNS (4);
2979 (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD) ? 2 : 1;
2981 if (memory_address_p (GET_MODE (x), XEXP ((x), 0)))
2982 *total = COSTS_N_INSNS (num_words);
2984 *total = COSTS_N_INSNS (2*num_words);
2989 *total = COSTS_N_INSNS (TARGET_NSA ? 5 : 50);
2993 *total = COSTS_N_INSNS ((GET_MODE (x) == DImode) ? 3 : 2);
2999 if (GET_MODE (x) == DImode)
3000 *total = COSTS_N_INSNS (2);
3002 *total = COSTS_N_INSNS (1);
3008 if (GET_MODE (x) == DImode)
3009 *total = COSTS_N_INSNS (50);
3011 *total = COSTS_N_INSNS (1);
3016 enum machine_mode xmode = GET_MODE (x);
3017 if (xmode == SFmode)
3018 *total = COSTS_N_INSNS (TARGET_HARD_FLOAT ? 1 : 50);
3019 else if (xmode == DFmode)
3020 *total = COSTS_N_INSNS (50);
3022 *total = COSTS_N_INSNS (4);
3029 enum machine_mode xmode = GET_MODE (x);
3030 if (xmode == SFmode)
3031 *total = COSTS_N_INSNS (TARGET_HARD_FLOAT ? 1 : 50);
3032 else if (xmode == DFmode || xmode == DImode)
3033 *total = COSTS_N_INSNS (50);
3035 *total = COSTS_N_INSNS (1);
3040 *total = COSTS_N_INSNS ((GET_MODE (x) == DImode) ? 4 : 2);
3045 enum machine_mode xmode = GET_MODE (x);
3046 if (xmode == SFmode)
3047 *total = COSTS_N_INSNS (TARGET_HARD_FLOAT ? 4 : 50);
3048 else if (xmode == DFmode || xmode == DImode)
3049 *total = COSTS_N_INSNS (50);
3050 else if (TARGET_MUL32)
3051 *total = COSTS_N_INSNS (4);
3052 else if (TARGET_MAC16)
3053 *total = COSTS_N_INSNS (16);
3054 else if (TARGET_MUL16)
3055 *total = COSTS_N_INSNS (12);
3057 *total = COSTS_N_INSNS (50);
3064 enum machine_mode xmode = GET_MODE (x);
3065 if (xmode == SFmode)
3067 *total = COSTS_N_INSNS (TARGET_HARD_FLOAT_DIV ? 8 : 50);
3070 else if (xmode == DFmode)
3072 *total = COSTS_N_INSNS (50);
3081 enum machine_mode xmode = GET_MODE (x);
3082 if (xmode == DImode)
3083 *total = COSTS_N_INSNS (50);
3084 else if (TARGET_DIV32)
3085 *total = COSTS_N_INSNS (32);
3087 *total = COSTS_N_INSNS (50);
3092 if (GET_MODE (x) == SFmode)
3093 *total = COSTS_N_INSNS (TARGET_HARD_FLOAT_SQRT ? 8 : 50);
3095 *total = COSTS_N_INSNS (50);
3102 *total = COSTS_N_INSNS (TARGET_MINMAX ? 1 : 50);
3107 *total = COSTS_N_INSNS (TARGET_SEXT ? 1 : 2);
3112 *total = COSTS_N_INSNS (1);
3120 #include "gt-xtensa.h"