1 /* Subroutines for insn-output.c for ATMEL AVR micro controllers
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008,
3 2009 Free Software Foundation, Inc.
4 Contributed by Denis Chertykov (chertykov@gmail.com)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
28 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-attr.h"
45 #include "target-def.h"
49 /* Maximal allowed offset for an address in the LD command */
50 #define MAX_LD_OFFSET(MODE) (64 - (signed)GET_MODE_SIZE (MODE))
52 static int avr_naked_function_p (tree
);
53 static int interrupt_function_p (tree
);
54 static int signal_function_p (tree
);
55 static int avr_OS_task_function_p (tree
);
56 static int avr_OS_main_function_p (tree
);
57 static int avr_regs_to_save (HARD_REG_SET
*);
58 static int get_sequence_length (rtx insns
);
59 static int sequent_regs_live (void);
60 static const char *ptrreg_to_str (int);
61 static const char *cond_string (enum rtx_code
);
62 static int avr_num_arg_regs (enum machine_mode
, tree
);
64 static RTX_CODE
compare_condition (rtx insn
);
65 static rtx
avr_legitimize_address (rtx
, rtx
, enum machine_mode
);
66 static int compare_sign_p (rtx insn
);
67 static tree
avr_handle_progmem_attribute (tree
*, tree
, tree
, int, bool *);
68 static tree
avr_handle_fndecl_attribute (tree
*, tree
, tree
, int, bool *);
69 static tree
avr_handle_fntype_attribute (tree
*, tree
, tree
, int, bool *);
70 static bool avr_assemble_integer (rtx
, unsigned int, int);
71 static void avr_file_start (void);
72 static void avr_file_end (void);
73 static bool avr_legitimate_address_p (enum machine_mode
, rtx
, bool);
74 static void avr_asm_function_end_prologue (FILE *);
75 static void avr_asm_function_begin_epilogue (FILE *);
76 static rtx
avr_function_value (const_tree
, const_tree
, bool);
77 static void avr_insert_attributes (tree
, tree
*);
78 static void avr_asm_init_sections (void);
79 static unsigned int avr_section_type_flags (tree
, const char *, int);
81 static void avr_reorg (void);
82 static void avr_asm_out_ctor (rtx
, int);
83 static void avr_asm_out_dtor (rtx
, int);
84 static int avr_operand_rtx_cost (rtx
, enum machine_mode
, enum rtx_code
, bool);
85 static bool avr_rtx_costs (rtx
, int, int, int *, bool);
86 static int avr_address_cost (rtx
, bool);
87 static bool avr_return_in_memory (const_tree
, const_tree
);
88 static struct machine_function
* avr_init_machine_status (void);
89 static rtx
avr_builtin_setjmp_frame_value (void);
90 static bool avr_hard_regno_scratch_ok (unsigned int);
91 static unsigned int avr_case_values_threshold (void);
92 static bool avr_frame_pointer_required_p (void);
94 /* Allocate registers from r25 to r8 for parameters for function calls. */
95 #define FIRST_CUM_REG 26
97 /* Temporary register RTX (gen_rtx_REG (QImode, TMP_REGNO)) */
98 static GTY(()) rtx tmp_reg_rtx
;
100 /* Zeroed register RTX (gen_rtx_REG (QImode, ZERO_REGNO)) */
101 static GTY(()) rtx zero_reg_rtx
;
103 /* AVR register names {"r0", "r1", ..., "r31"} */
104 static const char *const avr_regnames
[] = REGISTER_NAMES
;
106 /* This holds the last insn address. */
107 static int last_insn_address
= 0;
109 /* Preprocessor macros to define depending on MCU type. */
110 const char *avr_extra_arch_macro
;
112 /* Current architecture. */
113 const struct base_arch_s
*avr_current_arch
;
115 /* Current device. */
116 const struct mcu_type_s
*avr_current_device
;
118 section
*progmem_section
;
120 /* AVR attributes. */
121 static const struct attribute_spec avr_attribute_table
[] =
123 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
124 { "progmem", 0, 0, false, false, false, avr_handle_progmem_attribute
},
125 { "signal", 0, 0, true, false, false, avr_handle_fndecl_attribute
},
126 { "interrupt", 0, 0, true, false, false, avr_handle_fndecl_attribute
},
127 { "naked", 0, 0, false, true, true, avr_handle_fntype_attribute
},
128 { "OS_task", 0, 0, false, true, true, avr_handle_fntype_attribute
},
129 { "OS_main", 0, 0, false, true, true, avr_handle_fntype_attribute
},
130 { NULL
, 0, 0, false, false, false, NULL
}
133 /* Initialize the GCC target structure. */
134 #undef TARGET_ASM_ALIGNED_HI_OP
135 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
136 #undef TARGET_ASM_ALIGNED_SI_OP
137 #define TARGET_ASM_ALIGNED_SI_OP "\t.long\t"
138 #undef TARGET_ASM_UNALIGNED_HI_OP
139 #define TARGET_ASM_UNALIGNED_HI_OP "\t.word\t"
140 #undef TARGET_ASM_UNALIGNED_SI_OP
141 #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
142 #undef TARGET_ASM_INTEGER
143 #define TARGET_ASM_INTEGER avr_assemble_integer
144 #undef TARGET_ASM_FILE_START
145 #define TARGET_ASM_FILE_START avr_file_start
146 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
147 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
148 #undef TARGET_ASM_FILE_END
149 #define TARGET_ASM_FILE_END avr_file_end
151 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
152 #define TARGET_ASM_FUNCTION_END_PROLOGUE avr_asm_function_end_prologue
153 #undef TARGET_ASM_FUNCTION_BEGIN_EPILOGUE
154 #define TARGET_ASM_FUNCTION_BEGIN_EPILOGUE avr_asm_function_begin_epilogue
155 #undef TARGET_FUNCTION_VALUE
156 #define TARGET_FUNCTION_VALUE avr_function_value
157 #undef TARGET_ATTRIBUTE_TABLE
158 #define TARGET_ATTRIBUTE_TABLE avr_attribute_table
159 #undef TARGET_ASM_FUNCTION_RODATA_SECTION
160 #define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
161 #undef TARGET_INSERT_ATTRIBUTES
162 #define TARGET_INSERT_ATTRIBUTES avr_insert_attributes
163 #undef TARGET_SECTION_TYPE_FLAGS
164 #define TARGET_SECTION_TYPE_FLAGS avr_section_type_flags
165 #undef TARGET_RTX_COSTS
166 #define TARGET_RTX_COSTS avr_rtx_costs
167 #undef TARGET_ADDRESS_COST
168 #define TARGET_ADDRESS_COST avr_address_cost
169 #undef TARGET_MACHINE_DEPENDENT_REORG
170 #define TARGET_MACHINE_DEPENDENT_REORG avr_reorg
172 #undef TARGET_LEGITIMIZE_ADDRESS
173 #define TARGET_LEGITIMIZE_ADDRESS avr_legitimize_address
175 #undef TARGET_RETURN_IN_MEMORY
176 #define TARGET_RETURN_IN_MEMORY avr_return_in_memory
178 #undef TARGET_STRICT_ARGUMENT_NAMING
179 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
181 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
182 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE avr_builtin_setjmp_frame_value
184 #undef TARGET_HARD_REGNO_SCRATCH_OK
185 #define TARGET_HARD_REGNO_SCRATCH_OK avr_hard_regno_scratch_ok
186 #undef TARGET_CASE_VALUES_THRESHOLD
187 #define TARGET_CASE_VALUES_THRESHOLD avr_case_values_threshold
189 #undef TARGET_LEGITIMATE_ADDRESS_P
190 #define TARGET_LEGITIMATE_ADDRESS_P avr_legitimate_address_p
192 #undef TARGET_FRAME_POINTER_REQUIRED
193 #define TARGET_FRAME_POINTER_REQUIRED avr_frame_pointer_required_p
195 struct gcc_target targetm
= TARGET_INITIALIZER
;
198 avr_override_options (void)
200 const struct mcu_type_s
*t
;
202 flag_delete_null_pointer_checks
= 0;
204 for (t
= avr_mcu_types
; t
->name
; t
++)
205 if (strcmp (t
->name
, avr_mcu_name
) == 0)
210 fprintf (stderr
, "unknown MCU '%s' specified\nKnown MCU names:\n",
212 for (t
= avr_mcu_types
; t
->name
; t
++)
213 fprintf (stderr
," %s\n", t
->name
);
216 avr_current_arch
= &avr_arch_types
[t
->arch
];
217 avr_extra_arch_macro
= t
->macro
;
219 tmp_reg_rtx
= gen_rtx_REG (QImode
, TMP_REGNO
);
220 zero_reg_rtx
= gen_rtx_REG (QImode
, ZERO_REGNO
);
222 init_machine_status
= avr_init_machine_status
;
225 /* return register class from register number. */
227 static const enum reg_class reg_class_tab
[]={
228 GENERAL_REGS
,GENERAL_REGS
,GENERAL_REGS
,GENERAL_REGS
,GENERAL_REGS
,
229 GENERAL_REGS
,GENERAL_REGS
,GENERAL_REGS
,GENERAL_REGS
,GENERAL_REGS
,
230 GENERAL_REGS
,GENERAL_REGS
,GENERAL_REGS
,GENERAL_REGS
,GENERAL_REGS
,
231 GENERAL_REGS
, /* r0 - r15 */
232 LD_REGS
,LD_REGS
,LD_REGS
,LD_REGS
,LD_REGS
,LD_REGS
,LD_REGS
,
233 LD_REGS
, /* r16 - 23 */
234 ADDW_REGS
,ADDW_REGS
, /* r24,r25 */
235 POINTER_X_REGS
,POINTER_X_REGS
, /* r26,27 */
236 POINTER_Y_REGS
,POINTER_Y_REGS
, /* r28,r29 */
237 POINTER_Z_REGS
,POINTER_Z_REGS
, /* r30,r31 */
238 STACK_REG
,STACK_REG
/* SPL,SPH */
241 /* Function to set up the backend function structure. */
243 static struct machine_function
*
244 avr_init_machine_status (void)
246 return ((struct machine_function
*)
247 ggc_alloc_cleared (sizeof (struct machine_function
)));
250 /* Return register class for register R. */
253 avr_regno_reg_class (int r
)
256 return reg_class_tab
[r
];
260 /* Return nonzero if FUNC is a naked function. */
263 avr_naked_function_p (tree func
)
267 gcc_assert (TREE_CODE (func
) == FUNCTION_DECL
);
269 a
= lookup_attribute ("naked", TYPE_ATTRIBUTES (TREE_TYPE (func
)));
270 return a
!= NULL_TREE
;
273 /* Return nonzero if FUNC is an interrupt function as specified
274 by the "interrupt" attribute. */
277 interrupt_function_p (tree func
)
281 if (TREE_CODE (func
) != FUNCTION_DECL
)
284 a
= lookup_attribute ("interrupt", DECL_ATTRIBUTES (func
));
285 return a
!= NULL_TREE
;
288 /* Return nonzero if FUNC is a signal function as specified
289 by the "signal" attribute. */
292 signal_function_p (tree func
)
296 if (TREE_CODE (func
) != FUNCTION_DECL
)
299 a
= lookup_attribute ("signal", DECL_ATTRIBUTES (func
));
300 return a
!= NULL_TREE
;
303 /* Return nonzero if FUNC is a OS_task function. */
306 avr_OS_task_function_p (tree func
)
310 gcc_assert (TREE_CODE (func
) == FUNCTION_DECL
);
312 a
= lookup_attribute ("OS_task", TYPE_ATTRIBUTES (TREE_TYPE (func
)));
313 return a
!= NULL_TREE
;
316 /* Return nonzero if FUNC is a OS_main function. */
319 avr_OS_main_function_p (tree func
)
323 gcc_assert (TREE_CODE (func
) == FUNCTION_DECL
);
325 a
= lookup_attribute ("OS_main", TYPE_ATTRIBUTES (TREE_TYPE (func
)));
326 return a
!= NULL_TREE
;
329 /* Return the number of hard registers to push/pop in the prologue/epilogue
330 of the current function, and optionally store these registers in SET. */
333 avr_regs_to_save (HARD_REG_SET
*set
)
336 int int_or_sig_p
= (interrupt_function_p (current_function_decl
)
337 || signal_function_p (current_function_decl
));
339 if (!reload_completed
)
340 cfun
->machine
->is_leaf
= leaf_function_p ();
343 CLEAR_HARD_REG_SET (*set
);
346 /* No need to save any registers if the function never returns or
347 is have "OS_task" or "OS_main" attribute. */
348 if (TREE_THIS_VOLATILE (current_function_decl
)
349 || cfun
->machine
->is_OS_task
350 || cfun
->machine
->is_OS_main
)
353 for (reg
= 0; reg
< 32; reg
++)
355 /* Do not push/pop __tmp_reg__, __zero_reg__, as well as
356 any global register variables. */
360 if ((int_or_sig_p
&& !cfun
->machine
->is_leaf
&& call_used_regs
[reg
])
361 || (df_regs_ever_live_p (reg
)
362 && (int_or_sig_p
|| !call_used_regs
[reg
])
363 && !(frame_pointer_needed
364 && (reg
== REG_Y
|| reg
== (REG_Y
+1)))))
367 SET_HARD_REG_BIT (*set
, reg
);
374 /* Return true if register FROM can be eliminated via register TO. */
377 avr_can_eliminate (int from
, int to
)
379 return ((from
== ARG_POINTER_REGNUM
&& to
== FRAME_POINTER_REGNUM
)
380 || ((from
== FRAME_POINTER_REGNUM
381 || from
== FRAME_POINTER_REGNUM
+ 1)
382 && !frame_pointer_needed
));
385 /* Compute offset between arg_pointer and frame_pointer. */
388 avr_initial_elimination_offset (int from
, int to
)
390 if (from
== FRAME_POINTER_REGNUM
&& to
== STACK_POINTER_REGNUM
)
394 int offset
= frame_pointer_needed
? 2 : 0;
395 int avr_pc_size
= AVR_HAVE_EIJMP_EICALL
? 3 : 2;
397 offset
+= avr_regs_to_save (NULL
);
398 return get_frame_size () + (avr_pc_size
) + 1 + offset
;
402 /* Actual start of frame is virtual_stack_vars_rtx this is offset from
403 frame pointer by +STARTING_FRAME_OFFSET.
404 Using saved frame = virtual_stack_vars_rtx - STARTING_FRAME_OFFSET
405 avoids creating add/sub of offset in nonlocal goto and setjmp. */
407 rtx
avr_builtin_setjmp_frame_value (void)
409 return gen_rtx_MINUS (Pmode
, virtual_stack_vars_rtx
,
410 gen_int_mode (STARTING_FRAME_OFFSET
, Pmode
));
413 /* Return 1 if the function epilogue is just a single "ret". */
416 avr_simple_epilogue (void)
418 return (! frame_pointer_needed
419 && get_frame_size () == 0
420 && avr_regs_to_save (NULL
) == 0
421 && ! interrupt_function_p (current_function_decl
)
422 && ! signal_function_p (current_function_decl
)
423 && ! avr_naked_function_p (current_function_decl
)
424 && ! TREE_THIS_VOLATILE (current_function_decl
));
427 /* This function checks sequence of live registers. */
430 sequent_regs_live (void)
436 for (reg
= 0; reg
< 18; ++reg
)
438 if (!call_used_regs
[reg
])
440 if (df_regs_ever_live_p (reg
))
450 if (!frame_pointer_needed
)
452 if (df_regs_ever_live_p (REG_Y
))
460 if (df_regs_ever_live_p (REG_Y
+1))
473 return (cur_seq
== live_seq
) ? live_seq
: 0;
476 /* Obtain the length sequence of insns. */
479 get_sequence_length (rtx insns
)
484 for (insn
= insns
, length
= 0; insn
; insn
= NEXT_INSN (insn
))
485 length
+= get_attr_length (insn
);
490 /* Output function prologue. */
493 expand_prologue (void)
498 HOST_WIDE_INT size
= get_frame_size();
499 /* Define templates for push instructions. */
500 rtx pushbyte
= gen_rtx_MEM (QImode
,
501 gen_rtx_POST_DEC (HImode
, stack_pointer_rtx
));
502 rtx pushword
= gen_rtx_MEM (HImode
,
503 gen_rtx_POST_DEC (HImode
, stack_pointer_rtx
));
506 last_insn_address
= 0;
508 /* Init cfun->machine. */
509 cfun
->machine
->is_naked
= avr_naked_function_p (current_function_decl
);
510 cfun
->machine
->is_interrupt
= interrupt_function_p (current_function_decl
);
511 cfun
->machine
->is_signal
= signal_function_p (current_function_decl
);
512 cfun
->machine
->is_OS_task
= avr_OS_task_function_p (current_function_decl
);
513 cfun
->machine
->is_OS_main
= avr_OS_main_function_p (current_function_decl
);
515 /* Prologue: naked. */
516 if (cfun
->machine
->is_naked
)
521 avr_regs_to_save (&set
);
522 live_seq
= sequent_regs_live ();
523 minimize
= (TARGET_CALL_PROLOGUES
524 && !cfun
->machine
->is_interrupt
525 && !cfun
->machine
->is_signal
526 && !cfun
->machine
->is_OS_task
527 && !cfun
->machine
->is_OS_main
530 if (cfun
->machine
->is_interrupt
|| cfun
->machine
->is_signal
)
532 if (cfun
->machine
->is_interrupt
)
534 /* Enable interrupts. */
535 insn
= emit_insn (gen_enable_interrupt ());
536 RTX_FRAME_RELATED_P (insn
) = 1;
540 insn
= emit_move_insn (pushbyte
, zero_reg_rtx
);
541 RTX_FRAME_RELATED_P (insn
) = 1;
544 insn
= emit_move_insn (pushbyte
, tmp_reg_rtx
);
545 RTX_FRAME_RELATED_P (insn
) = 1;
548 insn
= emit_move_insn (tmp_reg_rtx
,
549 gen_rtx_MEM (QImode
, GEN_INT (SREG_ADDR
)));
550 RTX_FRAME_RELATED_P (insn
) = 1;
551 insn
= emit_move_insn (pushbyte
, tmp_reg_rtx
);
552 RTX_FRAME_RELATED_P (insn
) = 1;
556 && (TEST_HARD_REG_BIT (set
, REG_Z
) && TEST_HARD_REG_BIT (set
, REG_Z
+ 1)))
558 insn
= emit_move_insn (tmp_reg_rtx
,
559 gen_rtx_MEM (QImode
, GEN_INT (RAMPZ_ADDR
)));
560 RTX_FRAME_RELATED_P (insn
) = 1;
561 insn
= emit_move_insn (pushbyte
, tmp_reg_rtx
);
562 RTX_FRAME_RELATED_P (insn
) = 1;
565 /* Clear zero reg. */
566 insn
= emit_move_insn (zero_reg_rtx
, const0_rtx
);
567 RTX_FRAME_RELATED_P (insn
) = 1;
569 /* Prevent any attempt to delete the setting of ZERO_REG! */
570 emit_use (zero_reg_rtx
);
572 if (minimize
&& (frame_pointer_needed
573 || (AVR_2_BYTE_PC
&& live_seq
> 6)
576 insn
= emit_move_insn (gen_rtx_REG (HImode
, REG_X
),
577 gen_int_mode (size
, HImode
));
578 RTX_FRAME_RELATED_P (insn
) = 1;
581 emit_insn (gen_call_prologue_saves (gen_int_mode (live_seq
, HImode
),
582 gen_int_mode (size
+ live_seq
, HImode
)));
583 RTX_FRAME_RELATED_P (insn
) = 1;
588 for (reg
= 0; reg
< 32; ++reg
)
590 if (TEST_HARD_REG_BIT (set
, reg
))
592 /* Emit push of register to save. */
593 insn
=emit_move_insn (pushbyte
, gen_rtx_REG (QImode
, reg
));
594 RTX_FRAME_RELATED_P (insn
) = 1;
597 if (frame_pointer_needed
)
599 if (!(cfun
->machine
->is_OS_task
|| cfun
->machine
->is_OS_main
))
601 /* Push frame pointer. */
602 insn
= emit_move_insn (pushword
, frame_pointer_rtx
);
603 RTX_FRAME_RELATED_P (insn
) = 1;
608 insn
= emit_move_insn (frame_pointer_rtx
, stack_pointer_rtx
);
609 RTX_FRAME_RELATED_P (insn
) = 1;
613 /* Creating a frame can be done by direct manipulation of the
614 stack or via the frame pointer. These two methods are:
621 the optimum method depends on function type, stack and frame size.
622 To avoid a complex logic, both methods are tested and shortest
626 rtx sp_plus_insns
= NULL_RTX
;
628 if (TARGET_TINY_STACK
)
630 /* The high byte (r29) doesn't change - prefer 'subi' (1 cycle)
631 over 'sbiw' (2 cycles, same size). */
632 myfp
= gen_rtx_REG (QImode
, REGNO (frame_pointer_rtx
));
636 /* Normal sized addition. */
637 myfp
= frame_pointer_rtx
;
640 /* Method 1-Adjust frame pointer. */
643 insn
= emit_move_insn (frame_pointer_rtx
, stack_pointer_rtx
);
644 RTX_FRAME_RELATED_P (insn
) = 1;
647 emit_move_insn (myfp
,
648 gen_rtx_PLUS (GET_MODE(myfp
), myfp
,
651 RTX_FRAME_RELATED_P (insn
) = 1;
653 /* Copy to stack pointer. */
654 if (TARGET_TINY_STACK
)
656 insn
= emit_move_insn (stack_pointer_rtx
, frame_pointer_rtx
);
657 RTX_FRAME_RELATED_P (insn
) = 1;
659 else if (TARGET_NO_INTERRUPTS
660 || cfun
->machine
->is_signal
661 || cfun
->machine
->is_OS_main
)
664 emit_insn (gen_movhi_sp_r_irq_off (stack_pointer_rtx
,
666 RTX_FRAME_RELATED_P (insn
) = 1;
668 else if (cfun
->machine
->is_interrupt
)
670 insn
= emit_insn (gen_movhi_sp_r_irq_on (stack_pointer_rtx
,
672 RTX_FRAME_RELATED_P (insn
) = 1;
676 insn
= emit_move_insn (stack_pointer_rtx
, frame_pointer_rtx
);
677 RTX_FRAME_RELATED_P (insn
) = 1;
680 fp_plus_insns
= get_insns ();
683 /* Method 2-Adjust Stack pointer. */
689 emit_move_insn (stack_pointer_rtx
,
690 gen_rtx_PLUS (HImode
,
694 RTX_FRAME_RELATED_P (insn
) = 1;
697 emit_move_insn (frame_pointer_rtx
, stack_pointer_rtx
);
698 RTX_FRAME_RELATED_P (insn
) = 1;
700 sp_plus_insns
= get_insns ();
704 /* Use shortest method. */
705 if (size
<= 6 && (get_sequence_length (sp_plus_insns
)
706 < get_sequence_length (fp_plus_insns
)))
707 emit_insn (sp_plus_insns
);
709 emit_insn (fp_plus_insns
);
715 /* Output summary at end of function prologue. */
718 avr_asm_function_end_prologue (FILE *file
)
720 if (cfun
->machine
->is_naked
)
722 fputs ("/* prologue: naked */\n", file
);
726 if (cfun
->machine
->is_interrupt
)
728 fputs ("/* prologue: Interrupt */\n", file
);
730 else if (cfun
->machine
->is_signal
)
732 fputs ("/* prologue: Signal */\n", file
);
735 fputs ("/* prologue: function */\n", file
);
737 fprintf (file
, "/* frame size = " HOST_WIDE_INT_PRINT_DEC
" */\n",
742 /* Implement EPILOGUE_USES. */
745 avr_epilogue_uses (int regno ATTRIBUTE_UNUSED
)
749 && (cfun
->machine
->is_interrupt
|| cfun
->machine
->is_signal
))
754 /* Output RTL epilogue. */
757 expand_epilogue (void)
763 HOST_WIDE_INT size
= get_frame_size();
765 /* epilogue: naked */
766 if (cfun
->machine
->is_naked
)
768 emit_jump_insn (gen_return ());
772 avr_regs_to_save (&set
);
773 live_seq
= sequent_regs_live ();
774 minimize
= (TARGET_CALL_PROLOGUES
775 && !cfun
->machine
->is_interrupt
776 && !cfun
->machine
->is_signal
777 && !cfun
->machine
->is_OS_task
778 && !cfun
->machine
->is_OS_main
781 if (minimize
&& (frame_pointer_needed
|| live_seq
> 4))
783 if (frame_pointer_needed
)
785 /* Get rid of frame. */
786 emit_move_insn(frame_pointer_rtx
,
787 gen_rtx_PLUS (HImode
, frame_pointer_rtx
,
788 gen_int_mode (size
, HImode
)));
792 emit_move_insn (frame_pointer_rtx
, stack_pointer_rtx
);
795 emit_insn (gen_epilogue_restores (gen_int_mode (live_seq
, HImode
)));
799 if (frame_pointer_needed
)
803 /* Try two methods to adjust stack and select shortest. */
806 rtx sp_plus_insns
= NULL_RTX
;
808 if (TARGET_TINY_STACK
)
810 /* The high byte (r29) doesn't change - prefer 'subi'
811 (1 cycle) over 'sbiw' (2 cycles, same size). */
812 myfp
= gen_rtx_REG (QImode
, REGNO (frame_pointer_rtx
));
816 /* Normal sized addition. */
817 myfp
= frame_pointer_rtx
;
820 /* Method 1-Adjust frame pointer. */
823 emit_move_insn (myfp
,
824 gen_rtx_PLUS (HImode
, myfp
,
828 /* Copy to stack pointer. */
829 if (TARGET_TINY_STACK
)
831 emit_move_insn (stack_pointer_rtx
, frame_pointer_rtx
);
833 else if (TARGET_NO_INTERRUPTS
834 || cfun
->machine
->is_signal
)
836 emit_insn (gen_movhi_sp_r_irq_off (stack_pointer_rtx
,
839 else if (cfun
->machine
->is_interrupt
)
841 emit_insn (gen_movhi_sp_r_irq_on (stack_pointer_rtx
,
846 emit_move_insn (stack_pointer_rtx
, frame_pointer_rtx
);
849 fp_plus_insns
= get_insns ();
852 /* Method 2-Adjust Stack pointer. */
857 emit_move_insn (stack_pointer_rtx
,
858 gen_rtx_PLUS (HImode
, stack_pointer_rtx
,
862 sp_plus_insns
= get_insns ();
866 /* Use shortest method. */
867 if (size
<= 5 && (get_sequence_length (sp_plus_insns
)
868 < get_sequence_length (fp_plus_insns
)))
869 emit_insn (sp_plus_insns
);
871 emit_insn (fp_plus_insns
);
873 if (!(cfun
->machine
->is_OS_task
|| cfun
->machine
->is_OS_main
))
875 /* Restore previous frame_pointer. */
876 emit_insn (gen_pophi (frame_pointer_rtx
));
879 /* Restore used registers. */
880 for (reg
= 31; reg
>= 0; --reg
)
882 if (TEST_HARD_REG_BIT (set
, reg
))
883 emit_insn (gen_popqi (gen_rtx_REG (QImode
, reg
)));
885 if (cfun
->machine
->is_interrupt
|| cfun
->machine
->is_signal
)
887 /* Restore RAMPZ using tmp reg as scratch. */
889 && (TEST_HARD_REG_BIT (set
, REG_Z
) && TEST_HARD_REG_BIT (set
, REG_Z
+ 1)))
891 emit_insn (gen_popqi (tmp_reg_rtx
));
892 emit_move_insn (gen_rtx_MEM(QImode
, GEN_INT(RAMPZ_ADDR
)),
896 /* Restore SREG using tmp reg as scratch. */
897 emit_insn (gen_popqi (tmp_reg_rtx
));
899 emit_move_insn (gen_rtx_MEM(QImode
, GEN_INT(SREG_ADDR
)),
902 /* Restore tmp REG. */
903 emit_insn (gen_popqi (tmp_reg_rtx
));
905 /* Restore zero REG. */
906 emit_insn (gen_popqi (zero_reg_rtx
));
909 emit_jump_insn (gen_return ());
913 /* Output summary messages at beginning of function epilogue. */
916 avr_asm_function_begin_epilogue (FILE *file
)
918 fprintf (file
, "/* epilogue start */\n");
921 /* Return nonzero if X (an RTX) is a legitimate memory address on the target
922 machine for a memory operand of mode MODE. */
925 avr_legitimate_address_p (enum machine_mode mode
, rtx x
, bool strict
)
927 enum reg_class r
= NO_REGS
;
929 if (TARGET_ALL_DEBUG
)
931 fprintf (stderr
, "mode: (%s) %s %s %s %s:",
933 strict
? "(strict)": "",
934 reload_completed
? "(reload_completed)": "",
935 reload_in_progress
? "(reload_in_progress)": "",
936 reg_renumber
? "(reg_renumber)" : "");
937 if (GET_CODE (x
) == PLUS
938 && REG_P (XEXP (x
, 0))
939 && GET_CODE (XEXP (x
, 1)) == CONST_INT
940 && INTVAL (XEXP (x
, 1)) >= 0
941 && INTVAL (XEXP (x
, 1)) <= MAX_LD_OFFSET (mode
)
944 fprintf (stderr
, "(r%d ---> r%d)", REGNO (XEXP (x
, 0)),
945 true_regnum (XEXP (x
, 0)));
948 if (!strict
&& GET_CODE (x
) == SUBREG
)
950 if (REG_P (x
) && (strict
? REG_OK_FOR_BASE_STRICT_P (x
)
951 : REG_OK_FOR_BASE_NOSTRICT_P (x
)))
953 else if (CONSTANT_ADDRESS_P (x
))
955 else if (GET_CODE (x
) == PLUS
956 && REG_P (XEXP (x
, 0))
957 && GET_CODE (XEXP (x
, 1)) == CONST_INT
958 && INTVAL (XEXP (x
, 1)) >= 0)
960 int fit
= INTVAL (XEXP (x
, 1)) <= MAX_LD_OFFSET (mode
);
964 || REGNO (XEXP (x
,0)) == REG_X
965 || REGNO (XEXP (x
,0)) == REG_Y
966 || REGNO (XEXP (x
,0)) == REG_Z
)
967 r
= BASE_POINTER_REGS
;
968 if (XEXP (x
,0) == frame_pointer_rtx
969 || XEXP (x
,0) == arg_pointer_rtx
)
970 r
= BASE_POINTER_REGS
;
972 else if (frame_pointer_needed
&& XEXP (x
,0) == frame_pointer_rtx
)
975 else if ((GET_CODE (x
) == PRE_DEC
|| GET_CODE (x
) == POST_INC
)
976 && REG_P (XEXP (x
, 0))
977 && (strict
? REG_OK_FOR_BASE_STRICT_P (XEXP (x
, 0))
978 : REG_OK_FOR_BASE_NOSTRICT_P (XEXP (x
, 0))))
982 if (TARGET_ALL_DEBUG
)
984 fprintf (stderr
, " ret = %c\n", r
+ '0');
986 return r
== NO_REGS
? 0 : (int)r
;
989 /* Attempts to replace X with a valid
990 memory address for an operand of mode MODE */
993 avr_legitimize_address (rtx x
, rtx oldx
, enum machine_mode mode
)
996 if (TARGET_ALL_DEBUG
)
998 fprintf (stderr
, "legitimize_address mode: %s", GET_MODE_NAME(mode
));
1002 if (GET_CODE (oldx
) == PLUS
1003 && REG_P (XEXP (oldx
,0)))
1005 if (REG_P (XEXP (oldx
,1)))
1006 x
= force_reg (GET_MODE (oldx
), oldx
);
1007 else if (GET_CODE (XEXP (oldx
, 1)) == CONST_INT
)
1009 int offs
= INTVAL (XEXP (oldx
,1));
1010 if (frame_pointer_rtx
!= XEXP (oldx
,0))
1011 if (offs
> MAX_LD_OFFSET (mode
))
1013 if (TARGET_ALL_DEBUG
)
1014 fprintf (stderr
, "force_reg (big offset)\n");
1015 x
= force_reg (GET_MODE (oldx
), oldx
);
1023 /* Return a pointer register name as a string. */
1026 ptrreg_to_str (int regno
)
1030 case REG_X
: return "X";
1031 case REG_Y
: return "Y";
1032 case REG_Z
: return "Z";
1034 output_operand_lossage ("address operand requires constraint for X, Y, or Z register");
1039 /* Return the condition name as a string.
1040 Used in conditional jump constructing */
1043 cond_string (enum rtx_code code
)
1052 if (cc_prev_status
.flags
& CC_OVERFLOW_UNUSABLE
)
1057 if (cc_prev_status
.flags
& CC_OVERFLOW_UNUSABLE
)
1070 /* Output ADDR to FILE as address. */
1073 print_operand_address (FILE *file
, rtx addr
)
1075 switch (GET_CODE (addr
))
1078 fprintf (file
, ptrreg_to_str (REGNO (addr
)));
1082 fprintf (file
, "-%s", ptrreg_to_str (REGNO (XEXP (addr
, 0))));
1086 fprintf (file
, "%s+", ptrreg_to_str (REGNO (XEXP (addr
, 0))));
1090 if (CONSTANT_ADDRESS_P (addr
)
1091 && ((GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_FUNCTION_P (addr
))
1092 || GET_CODE (addr
) == LABEL_REF
))
1094 fprintf (file
, "gs(");
1095 output_addr_const (file
,addr
);
1096 fprintf (file
,")");
1099 output_addr_const (file
, addr
);
1104 /* Output X as assembler operand to file FILE. */
1107 print_operand (FILE *file
, rtx x
, int code
)
1111 if (code
>= 'A' && code
<= 'D')
1116 if (!AVR_HAVE_JMP_CALL
)
1119 else if (code
== '!')
1121 if (AVR_HAVE_EIJMP_EICALL
)
1126 if (x
== zero_reg_rtx
)
1127 fprintf (file
, "__zero_reg__");
1129 fprintf (file
, reg_names
[true_regnum (x
) + abcd
]);
1131 else if (GET_CODE (x
) == CONST_INT
)
1132 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) + abcd
);
1133 else if (GET_CODE (x
) == MEM
)
1135 rtx addr
= XEXP (x
,0);
1137 if (CONSTANT_P (addr
) && abcd
)
1140 output_address (addr
);
1141 fprintf (file
, ")+%d", abcd
);
1143 else if (code
== 'o')
1145 if (GET_CODE (addr
) != PLUS
)
1146 fatal_insn ("bad address, not (reg+disp):", addr
);
1148 print_operand (file
, XEXP (addr
, 1), 0);
1150 else if (code
== 'p' || code
== 'r')
1152 if (GET_CODE (addr
) != POST_INC
&& GET_CODE (addr
) != PRE_DEC
)
1153 fatal_insn ("bad address, not post_inc or pre_dec:", addr
);
1156 print_operand_address (file
, XEXP (addr
, 0)); /* X, Y, Z */
1158 print_operand (file
, XEXP (addr
, 0), 0); /* r26, r28, r30 */
1160 else if (GET_CODE (addr
) == PLUS
)
1162 print_operand_address (file
, XEXP (addr
,0));
1163 if (REGNO (XEXP (addr
, 0)) == REG_X
)
1164 fatal_insn ("internal compiler error. Bad address:"
1167 print_operand (file
, XEXP (addr
,1), code
);
1170 print_operand_address (file
, addr
);
1172 else if (GET_CODE (x
) == CONST_DOUBLE
)
1176 if (GET_MODE (x
) != SFmode
)
1177 fatal_insn ("internal compiler error. Unknown mode:", x
);
1178 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1179 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1180 fprintf (file
, "0x%lx", val
);
1182 else if (code
== 'j')
1183 fputs (cond_string (GET_CODE (x
)), file
);
1184 else if (code
== 'k')
1185 fputs (cond_string (reverse_condition (GET_CODE (x
))), file
);
1187 print_operand_address (file
, x
);
1190 /* Update the condition code in the INSN. */
1193 notice_update_cc (rtx body ATTRIBUTE_UNUSED
, rtx insn
)
1197 switch (get_attr_cc (insn
))
1200 /* Insn does not affect CC at all. */
1208 set
= single_set (insn
);
1212 cc_status
.flags
|= CC_NO_OVERFLOW
;
1213 cc_status
.value1
= SET_DEST (set
);
1218 /* Insn sets the Z,N,C flags of CC to recog_operand[0].
1219 The V flag may or may not be known but that's ok because
1220 alter_cond will change tests to use EQ/NE. */
1221 set
= single_set (insn
);
1225 cc_status
.value1
= SET_DEST (set
);
1226 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
;
1231 set
= single_set (insn
);
1234 cc_status
.value1
= SET_SRC (set
);
1238 /* Insn doesn't leave CC in a usable state. */
1241 /* Correct CC for the ashrqi3 with the shift count as CONST_INT != 6 */
1242 set
= single_set (insn
);
1245 rtx src
= SET_SRC (set
);
1247 if (GET_CODE (src
) == ASHIFTRT
1248 && GET_MODE (src
) == QImode
)
1250 rtx x
= XEXP (src
, 1);
1252 if (GET_CODE (x
) == CONST_INT
1256 cc_status
.value1
= SET_DEST (set
);
1257 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
;
1265 /* Return maximum number of consecutive registers of
1266 class CLASS needed to hold a value of mode MODE. */
1269 class_max_nregs (enum reg_class rclass ATTRIBUTE_UNUSED
,enum machine_mode mode
)
1271 return ((GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
);
1274 /* Choose mode for jump insn:
1275 1 - relative jump in range -63 <= x <= 62 ;
1276 2 - relative jump in range -2046 <= x <= 2045 ;
1277 3 - absolute jump (only for ATmega[16]03). */
1280 avr_jump_mode (rtx x
, rtx insn
)
1282 int dest_addr
= INSN_ADDRESSES (INSN_UID (GET_CODE (x
) == LABEL_REF
1283 ? XEXP (x
, 0) : x
));
1284 int cur_addr
= INSN_ADDRESSES (INSN_UID (insn
));
1285 int jump_distance
= cur_addr
- dest_addr
;
1287 if (-63 <= jump_distance
&& jump_distance
<= 62)
1289 else if (-2046 <= jump_distance
&& jump_distance
<= 2045)
1291 else if (AVR_HAVE_JMP_CALL
)
1297 /* return an AVR condition jump commands.
1298 X is a comparison RTX.
1299 LEN is a number returned by avr_jump_mode function.
1300 if REVERSE nonzero then condition code in X must be reversed. */
1303 ret_cond_branch (rtx x
, int len
, int reverse
)
1305 RTX_CODE cond
= reverse
? reverse_condition (GET_CODE (x
)) : GET_CODE (x
);
1310 if (cc_prev_status
.flags
& CC_OVERFLOW_UNUSABLE
)
1311 return (len
== 1 ? (AS1 (breq
,.+2) CR_TAB
1313 len
== 2 ? (AS1 (breq
,.+4) CR_TAB
1314 AS1 (brmi
,.+2) CR_TAB
1316 (AS1 (breq
,.+6) CR_TAB
1317 AS1 (brmi
,.+4) CR_TAB
1321 return (len
== 1 ? (AS1 (breq
,.+2) CR_TAB
1323 len
== 2 ? (AS1 (breq
,.+4) CR_TAB
1324 AS1 (brlt
,.+2) CR_TAB
1326 (AS1 (breq
,.+6) CR_TAB
1327 AS1 (brlt
,.+4) CR_TAB
1330 return (len
== 1 ? (AS1 (breq
,.+2) CR_TAB
1332 len
== 2 ? (AS1 (breq
,.+4) CR_TAB
1333 AS1 (brlo
,.+2) CR_TAB
1335 (AS1 (breq
,.+6) CR_TAB
1336 AS1 (brlo
,.+4) CR_TAB
1339 if (cc_prev_status
.flags
& CC_OVERFLOW_UNUSABLE
)
1340 return (len
== 1 ? (AS1 (breq
,%0) CR_TAB
1342 len
== 2 ? (AS1 (breq
,.+2) CR_TAB
1343 AS1 (brpl
,.+2) CR_TAB
1345 (AS1 (breq
,.+2) CR_TAB
1346 AS1 (brpl
,.+4) CR_TAB
1349 return (len
== 1 ? (AS1 (breq
,%0) CR_TAB
1351 len
== 2 ? (AS1 (breq
,.+2) CR_TAB
1352 AS1 (brge
,.+2) CR_TAB
1354 (AS1 (breq
,.+2) CR_TAB
1355 AS1 (brge
,.+4) CR_TAB
1358 return (len
== 1 ? (AS1 (breq
,%0) CR_TAB
1360 len
== 2 ? (AS1 (breq
,.+2) CR_TAB
1361 AS1 (brsh
,.+2) CR_TAB
1363 (AS1 (breq
,.+2) CR_TAB
1364 AS1 (brsh
,.+4) CR_TAB
1372 return AS1 (br
%k1
,%0);
1374 return (AS1 (br
%j1
,.+2) CR_TAB
1377 return (AS1 (br
%j1
,.+4) CR_TAB
1386 return AS1 (br
%j1
,%0);
1388 return (AS1 (br
%k1
,.+2) CR_TAB
1391 return (AS1 (br
%k1
,.+4) CR_TAB
1399 /* Predicate function for immediate operand which fits to byte (8bit) */
1402 byte_immediate_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1404 return (GET_CODE (op
) == CONST_INT
1405 && INTVAL (op
) <= 0xff && INTVAL (op
) >= 0);
1408 /* Output all insn addresses and their sizes into the assembly language
1409 output file. This is helpful for debugging whether the length attributes
1410 in the md file are correct.
1411 Output insn cost for next insn. */
1414 final_prescan_insn (rtx insn
, rtx
*operand ATTRIBUTE_UNUSED
,
1415 int num_operands ATTRIBUTE_UNUSED
)
1417 int uid
= INSN_UID (insn
);
1419 if (TARGET_INSN_SIZE_DUMP
|| TARGET_ALL_DEBUG
)
1421 fprintf (asm_out_file
, "/*DEBUG: 0x%x\t\t%d\t%d */\n",
1422 INSN_ADDRESSES (uid
),
1423 INSN_ADDRESSES (uid
) - last_insn_address
,
1424 rtx_cost (PATTERN (insn
), INSN
, !optimize_size
));
1426 last_insn_address
= INSN_ADDRESSES (uid
);
1429 /* Return 0 if undefined, 1 if always true or always false. */
1432 avr_simplify_comparison_p (enum machine_mode mode
, RTX_CODE op
, rtx x
)
1434 unsigned int max
= (mode
== QImode
? 0xff :
1435 mode
== HImode
? 0xffff :
1436 mode
== SImode
? 0xffffffff : 0);
1437 if (max
&& op
&& GET_CODE (x
) == CONST_INT
)
1439 if (unsigned_condition (op
) != op
)
1442 if (max
!= (INTVAL (x
) & max
)
1443 && INTVAL (x
) != 0xff)
1450 /* Returns nonzero if REGNO is the number of a hard
1451 register in which function arguments are sometimes passed. */
1454 function_arg_regno_p(int r
)
1456 return (r
>= 8 && r
<= 25);
1459 /* Initializing the variable cum for the state at the beginning
1460 of the argument list. */
1463 init_cumulative_args (CUMULATIVE_ARGS
*cum
, tree fntype
, rtx libname
,
1464 tree fndecl ATTRIBUTE_UNUSED
)
1467 cum
->regno
= FIRST_CUM_REG
;
1468 if (!libname
&& fntype
)
1470 int stdarg
= (TYPE_ARG_TYPES (fntype
) != 0
1471 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype
)))
1472 != void_type_node
));
1478 /* Returns the number of registers to allocate for a function argument. */
1481 avr_num_arg_regs (enum machine_mode mode
, tree type
)
1485 if (mode
== BLKmode
)
1486 size
= int_size_in_bytes (type
);
1488 size
= GET_MODE_SIZE (mode
);
1490 /* Align all function arguments to start in even-numbered registers.
1491 Odd-sized arguments leave holes above them. */
1493 return (size
+ 1) & ~1;
1496 /* Controls whether a function argument is passed
1497 in a register, and which register. */
1500 function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
, tree type
,
1501 int named ATTRIBUTE_UNUSED
)
1503 int bytes
= avr_num_arg_regs (mode
, type
);
1505 if (cum
->nregs
&& bytes
<= cum
->nregs
)
1506 return gen_rtx_REG (mode
, cum
->regno
- bytes
);
1511 /* Update the summarizer variable CUM to advance past an argument
1512 in the argument list. */
1515 function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
, tree type
,
1516 int named ATTRIBUTE_UNUSED
)
1518 int bytes
= avr_num_arg_regs (mode
, type
);
1520 cum
->nregs
-= bytes
;
1521 cum
->regno
-= bytes
;
1523 if (cum
->nregs
<= 0)
1526 cum
->regno
= FIRST_CUM_REG
;
1530 /***********************************************************************
1531 Functions for outputting various mov's for a various modes
1532 ************************************************************************/
1534 output_movqi (rtx insn
, rtx operands
[], int *l
)
1537 rtx dest
= operands
[0];
1538 rtx src
= operands
[1];
1546 if (register_operand (dest
, QImode
))
1548 if (register_operand (src
, QImode
)) /* mov r,r */
1550 if (test_hard_reg_class (STACK_REG
, dest
))
1551 return AS2 (out
,%0,%1);
1552 else if (test_hard_reg_class (STACK_REG
, src
))
1553 return AS2 (in
,%0,%1);
1555 return AS2 (mov
,%0,%1);
1557 else if (CONSTANT_P (src
))
1559 if (test_hard_reg_class (LD_REGS
, dest
)) /* ldi d,i */
1560 return AS2 (ldi
,%0,lo8(%1));
1562 if (GET_CODE (src
) == CONST_INT
)
1564 if (src
== const0_rtx
) /* mov r,L */
1565 return AS1 (clr
,%0);
1566 else if (src
== const1_rtx
)
1569 return (AS1 (clr
,%0) CR_TAB
1572 else if (src
== constm1_rtx
)
1574 /* Immediate constants -1 to any register */
1576 return (AS1 (clr
,%0) CR_TAB
1581 int bit_nr
= exact_log2 (INTVAL (src
));
1587 output_asm_insn ((AS1 (clr
,%0) CR_TAB
1590 avr_output_bld (operands
, bit_nr
);
1597 /* Last resort, larger than loading from memory. */
1599 return (AS2 (mov
,__tmp_reg__
,r31
) CR_TAB
1600 AS2 (ldi
,r31
,lo8(%1)) CR_TAB
1601 AS2 (mov
,%0,r31
) CR_TAB
1602 AS2 (mov
,r31
,__tmp_reg__
));
1604 else if (GET_CODE (src
) == MEM
)
1605 return out_movqi_r_mr (insn
, operands
, real_l
); /* mov r,m */
1607 else if (GET_CODE (dest
) == MEM
)
1611 if (src
== const0_rtx
)
1612 operands
[1] = zero_reg_rtx
;
1614 templ
= out_movqi_mr_r (insn
, operands
, real_l
);
1617 output_asm_insn (templ
, operands
);
1626 output_movhi (rtx insn
, rtx operands
[], int *l
)
1629 rtx dest
= operands
[0];
1630 rtx src
= operands
[1];
1636 if (register_operand (dest
, HImode
))
1638 if (register_operand (src
, HImode
)) /* mov r,r */
1640 if (test_hard_reg_class (STACK_REG
, dest
))
1642 if (TARGET_TINY_STACK
)
1643 return *l
= 1, AS2 (out
,__SP_L__
,%A1
);
1644 /* Use simple load of stack pointer if no interrupts are
1646 else if (TARGET_NO_INTERRUPTS
)
1647 return *l
= 2, (AS2 (out
,__SP_H__
,%B1
) CR_TAB
1648 AS2 (out
,__SP_L__
,%A1
));
1650 return (AS2 (in
,__tmp_reg__
,__SREG__
) CR_TAB
1652 AS2 (out
,__SP_H__
,%B1
) CR_TAB
1653 AS2 (out
,__SREG__
,__tmp_reg__
) CR_TAB
1654 AS2 (out
,__SP_L__
,%A1
));
1656 else if (test_hard_reg_class (STACK_REG
, src
))
1659 return (AS2 (in
,%A0
,__SP_L__
) CR_TAB
1660 AS2 (in
,%B0
,__SP_H__
));
1666 return (AS2 (movw
,%0,%1));
1671 return (AS2 (mov
,%A0
,%A1
) CR_TAB
1675 else if (CONSTANT_P (src
))
1677 if (test_hard_reg_class (LD_REGS
, dest
)) /* ldi d,i */
1680 return (AS2 (ldi
,%A0
,lo8(%1)) CR_TAB
1681 AS2 (ldi
,%B0
,hi8(%1)));
1684 if (GET_CODE (src
) == CONST_INT
)
1686 if (src
== const0_rtx
) /* mov r,L */
1689 return (AS1 (clr
,%A0
) CR_TAB
1692 else if (src
== const1_rtx
)
1695 return (AS1 (clr
,%A0
) CR_TAB
1696 AS1 (clr
,%B0
) CR_TAB
1699 else if (src
== constm1_rtx
)
1701 /* Immediate constants -1 to any register */
1703 return (AS1 (clr
,%0) CR_TAB
1704 AS1 (dec
,%A0
) CR_TAB
1709 int bit_nr
= exact_log2 (INTVAL (src
));
1715 output_asm_insn ((AS1 (clr
,%A0
) CR_TAB
1716 AS1 (clr
,%B0
) CR_TAB
1719 avr_output_bld (operands
, bit_nr
);
1725 if ((INTVAL (src
) & 0xff) == 0)
1728 return (AS2 (mov
,__tmp_reg__
,r31
) CR_TAB
1729 AS1 (clr
,%A0
) CR_TAB
1730 AS2 (ldi
,r31
,hi8(%1)) CR_TAB
1731 AS2 (mov
,%B0
,r31
) CR_TAB
1732 AS2 (mov
,r31
,__tmp_reg__
));
1734 else if ((INTVAL (src
) & 0xff00) == 0)
1737 return (AS2 (mov
,__tmp_reg__
,r31
) CR_TAB
1738 AS2 (ldi
,r31
,lo8(%1)) CR_TAB
1739 AS2 (mov
,%A0
,r31
) CR_TAB
1740 AS1 (clr
,%B0
) CR_TAB
1741 AS2 (mov
,r31
,__tmp_reg__
));
1745 /* Last resort, equal to loading from memory. */
1747 return (AS2 (mov
,__tmp_reg__
,r31
) CR_TAB
1748 AS2 (ldi
,r31
,lo8(%1)) CR_TAB
1749 AS2 (mov
,%A0
,r31
) CR_TAB
1750 AS2 (ldi
,r31
,hi8(%1)) CR_TAB
1751 AS2 (mov
,%B0
,r31
) CR_TAB
1752 AS2 (mov
,r31
,__tmp_reg__
));
1754 else if (GET_CODE (src
) == MEM
)
1755 return out_movhi_r_mr (insn
, operands
, real_l
); /* mov r,m */
1757 else if (GET_CODE (dest
) == MEM
)
1761 if (src
== const0_rtx
)
1762 operands
[1] = zero_reg_rtx
;
1764 templ
= out_movhi_mr_r (insn
, operands
, real_l
);
1767 output_asm_insn (templ
, operands
);
1772 fatal_insn ("invalid insn:", insn
);
1777 out_movqi_r_mr (rtx insn
, rtx op
[], int *l
)
1781 rtx x
= XEXP (src
, 0);
1787 if (CONSTANT_ADDRESS_P (x
))
1789 if (CONST_INT_P (x
) && INTVAL (x
) == SREG_ADDR
)
1792 return AS2 (in
,%0,__SREG__
);
1794 if (optimize
> 0 && io_address_operand (x
, QImode
))
1797 return AS2 (in
,%0,%1-0x20);
1800 return AS2 (lds
,%0,%1);
1802 /* memory access by reg+disp */
1803 else if (GET_CODE (x
) == PLUS
1804 && REG_P (XEXP (x
,0))
1805 && GET_CODE (XEXP (x
,1)) == CONST_INT
)
1807 if ((INTVAL (XEXP (x
,1)) - GET_MODE_SIZE (GET_MODE (src
))) >= 63)
1809 int disp
= INTVAL (XEXP (x
,1));
1810 if (REGNO (XEXP (x
,0)) != REG_Y
)
1811 fatal_insn ("incorrect insn:",insn
);
1813 if (disp
<= 63 + MAX_LD_OFFSET (GET_MODE (src
)))
1814 return *l
= 3, (AS2 (adiw
,r28
,%o1
-63) CR_TAB
1815 AS2 (ldd
,%0,Y
+63) CR_TAB
1816 AS2 (sbiw
,r28
,%o1
-63));
1818 return *l
= 5, (AS2 (subi
,r28
,lo8(-%o1
)) CR_TAB
1819 AS2 (sbci
,r29
,hi8(-%o1
)) CR_TAB
1820 AS2 (ld
,%0,Y
) CR_TAB
1821 AS2 (subi
,r28
,lo8(%o1
)) CR_TAB
1822 AS2 (sbci
,r29
,hi8(%o1
)));
1824 else if (REGNO (XEXP (x
,0)) == REG_X
)
1826 /* This is a paranoid case LEGITIMIZE_RELOAD_ADDRESS must exclude
1827 it but I have this situation with extremal optimizing options. */
1828 if (reg_overlap_mentioned_p (dest
, XEXP (x
,0))
1829 || reg_unused_after (insn
, XEXP (x
,0)))
1830 return *l
= 2, (AS2 (adiw
,r26
,%o1
) CR_TAB
1833 return *l
= 3, (AS2 (adiw
,r26
,%o1
) CR_TAB
1834 AS2 (ld
,%0,X
) CR_TAB
1835 AS2 (sbiw
,r26
,%o1
));
1838 return AS2 (ldd
,%0,%1);
1841 return AS2 (ld
,%0,%1);
1845 out_movhi_r_mr (rtx insn
, rtx op
[], int *l
)
1849 rtx base
= XEXP (src
, 0);
1850 int reg_dest
= true_regnum (dest
);
1851 int reg_base
= true_regnum (base
);
1852 /* "volatile" forces reading low byte first, even if less efficient,
1853 for correct operation with 16-bit I/O registers. */
1854 int mem_volatile_p
= MEM_VOLATILE_P (src
);
1862 if (reg_dest
== reg_base
) /* R = (R) */
1865 return (AS2 (ld
,__tmp_reg__
,%1+) CR_TAB
1866 AS2 (ld
,%B0
,%1) CR_TAB
1867 AS2 (mov
,%A0
,__tmp_reg__
));
1869 else if (reg_base
== REG_X
) /* (R26) */
1871 if (reg_unused_after (insn
, base
))
1874 return (AS2 (ld
,%A0
,X
+) CR_TAB
1878 return (AS2 (ld
,%A0
,X
+) CR_TAB
1879 AS2 (ld
,%B0
,X
) CR_TAB
1885 return (AS2 (ld
,%A0
,%1) CR_TAB
1886 AS2 (ldd
,%B0
,%1+1));
1889 else if (GET_CODE (base
) == PLUS
) /* (R + i) */
1891 int disp
= INTVAL (XEXP (base
, 1));
1892 int reg_base
= true_regnum (XEXP (base
, 0));
1894 if (disp
> MAX_LD_OFFSET (GET_MODE (src
)))
1896 if (REGNO (XEXP (base
, 0)) != REG_Y
)
1897 fatal_insn ("incorrect insn:",insn
);
1899 if (disp
<= 63 + MAX_LD_OFFSET (GET_MODE (src
)))
1900 return *l
= 4, (AS2 (adiw
,r28
,%o1
-62) CR_TAB
1901 AS2 (ldd
,%A0
,Y
+62) CR_TAB
1902 AS2 (ldd
,%B0
,Y
+63) CR_TAB
1903 AS2 (sbiw
,r28
,%o1
-62));
1905 return *l
= 6, (AS2 (subi
,r28
,lo8(-%o1
)) CR_TAB
1906 AS2 (sbci
,r29
,hi8(-%o1
)) CR_TAB
1907 AS2 (ld
,%A0
,Y
) CR_TAB
1908 AS2 (ldd
,%B0
,Y
+1) CR_TAB
1909 AS2 (subi
,r28
,lo8(%o1
)) CR_TAB
1910 AS2 (sbci
,r29
,hi8(%o1
)));
1912 if (reg_base
== REG_X
)
1914 /* This is a paranoid case. LEGITIMIZE_RELOAD_ADDRESS must exclude
1915 it but I have this situation with extremal
1916 optimization options. */
1919 if (reg_base
== reg_dest
)
1920 return (AS2 (adiw
,r26
,%o1
) CR_TAB
1921 AS2 (ld
,__tmp_reg__
,X
+) CR_TAB
1922 AS2 (ld
,%B0
,X
) CR_TAB
1923 AS2 (mov
,%A0
,__tmp_reg__
));
1925 return (AS2 (adiw
,r26
,%o1
) CR_TAB
1926 AS2 (ld
,%A0
,X
+) CR_TAB
1927 AS2 (ld
,%B0
,X
) CR_TAB
1928 AS2 (sbiw
,r26
,%o1
+1));
1931 if (reg_base
== reg_dest
)
1934 return (AS2 (ldd
,__tmp_reg__
,%A1
) CR_TAB
1935 AS2 (ldd
,%B0
,%B1
) CR_TAB
1936 AS2 (mov
,%A0
,__tmp_reg__
));
1940 return (AS2 (ldd
,%A0
,%A1
) CR_TAB
1943 else if (GET_CODE (base
) == PRE_DEC
) /* (--R) */
1945 if (reg_overlap_mentioned_p (dest
, XEXP (base
, 0)))
1946 fatal_insn ("incorrect insn:", insn
);
1950 if (REGNO (XEXP (base
, 0)) == REG_X
)
1953 return (AS2 (sbiw
,r26
,2) CR_TAB
1954 AS2 (ld
,%A0
,X
+) CR_TAB
1955 AS2 (ld
,%B0
,X
) CR_TAB
1961 return (AS2 (sbiw
,%r1
,2) CR_TAB
1962 AS2 (ld
,%A0
,%p1
) CR_TAB
1963 AS2 (ldd
,%B0
,%p1
+1));
1968 return (AS2 (ld
,%B0
,%1) CR_TAB
1971 else if (GET_CODE (base
) == POST_INC
) /* (R++) */
1973 if (reg_overlap_mentioned_p (dest
, XEXP (base
, 0)))
1974 fatal_insn ("incorrect insn:", insn
);
1977 return (AS2 (ld
,%A0
,%1) CR_TAB
1980 else if (CONSTANT_ADDRESS_P (base
))
1982 if (optimize
> 0 && io_address_operand (base
, HImode
))
1985 return (AS2 (in
,%A0
,%A1
-0x20) CR_TAB
1986 AS2 (in
,%B0
,%B1
-0x20));
1989 return (AS2 (lds
,%A0
,%A1
) CR_TAB
1993 fatal_insn ("unknown move insn:",insn
);
1998 out_movsi_r_mr (rtx insn
, rtx op
[], int *l
)
2002 rtx base
= XEXP (src
, 0);
2003 int reg_dest
= true_regnum (dest
);
2004 int reg_base
= true_regnum (base
);
2012 if (reg_base
== REG_X
) /* (R26) */
2014 if (reg_dest
== REG_X
)
2015 /* "ld r26,-X" is undefined */
2016 return *l
=7, (AS2 (adiw
,r26
,3) CR_TAB
2017 AS2 (ld
,r29
,X
) CR_TAB
2018 AS2 (ld
,r28
,-X
) CR_TAB
2019 AS2 (ld
,__tmp_reg__
,-X
) CR_TAB
2020 AS2 (sbiw
,r26
,1) CR_TAB
2021 AS2 (ld
,r26
,X
) CR_TAB
2022 AS2 (mov
,r27
,__tmp_reg__
));
2023 else if (reg_dest
== REG_X
- 2)
2024 return *l
=5, (AS2 (ld
,%A0
,X
+) CR_TAB
2025 AS2 (ld
,%B0
,X
+) CR_TAB
2026 AS2 (ld
,__tmp_reg__
,X
+) CR_TAB
2027 AS2 (ld
,%D0
,X
) CR_TAB
2028 AS2 (mov
,%C0
,__tmp_reg__
));
2029 else if (reg_unused_after (insn
, base
))
2030 return *l
=4, (AS2 (ld
,%A0
,X
+) CR_TAB
2031 AS2 (ld
,%B0
,X
+) CR_TAB
2032 AS2 (ld
,%C0
,X
+) CR_TAB
2035 return *l
=5, (AS2 (ld
,%A0
,X
+) CR_TAB
2036 AS2 (ld
,%B0
,X
+) CR_TAB
2037 AS2 (ld
,%C0
,X
+) CR_TAB
2038 AS2 (ld
,%D0
,X
) CR_TAB
2043 if (reg_dest
== reg_base
)
2044 return *l
=5, (AS2 (ldd
,%D0
,%1+3) CR_TAB
2045 AS2 (ldd
,%C0
,%1+2) CR_TAB
2046 AS2 (ldd
,__tmp_reg__
,%1+1) CR_TAB
2047 AS2 (ld
,%A0
,%1) CR_TAB
2048 AS2 (mov
,%B0
,__tmp_reg__
));
2049 else if (reg_base
== reg_dest
+ 2)
2050 return *l
=5, (AS2 (ld
,%A0
,%1) CR_TAB
2051 AS2 (ldd
,%B0
,%1+1) CR_TAB
2052 AS2 (ldd
,__tmp_reg__
,%1+2) CR_TAB
2053 AS2 (ldd
,%D0
,%1+3) CR_TAB
2054 AS2 (mov
,%C0
,__tmp_reg__
));
2056 return *l
=4, (AS2 (ld
,%A0
,%1) CR_TAB
2057 AS2 (ldd
,%B0
,%1+1) CR_TAB
2058 AS2 (ldd
,%C0
,%1+2) CR_TAB
2059 AS2 (ldd
,%D0
,%1+3));
2062 else if (GET_CODE (base
) == PLUS
) /* (R + i) */
2064 int disp
= INTVAL (XEXP (base
, 1));
2066 if (disp
> MAX_LD_OFFSET (GET_MODE (src
)))
2068 if (REGNO (XEXP (base
, 0)) != REG_Y
)
2069 fatal_insn ("incorrect insn:",insn
);
2071 if (disp
<= 63 + MAX_LD_OFFSET (GET_MODE (src
)))
2072 return *l
= 6, (AS2 (adiw
,r28
,%o1
-60) CR_TAB
2073 AS2 (ldd
,%A0
,Y
+60) CR_TAB
2074 AS2 (ldd
,%B0
,Y
+61) CR_TAB
2075 AS2 (ldd
,%C0
,Y
+62) CR_TAB
2076 AS2 (ldd
,%D0
,Y
+63) CR_TAB
2077 AS2 (sbiw
,r28
,%o1
-60));
2079 return *l
= 8, (AS2 (subi
,r28
,lo8(-%o1
)) CR_TAB
2080 AS2 (sbci
,r29
,hi8(-%o1
)) CR_TAB
2081 AS2 (ld
,%A0
,Y
) CR_TAB
2082 AS2 (ldd
,%B0
,Y
+1) CR_TAB
2083 AS2 (ldd
,%C0
,Y
+2) CR_TAB
2084 AS2 (ldd
,%D0
,Y
+3) CR_TAB
2085 AS2 (subi
,r28
,lo8(%o1
)) CR_TAB
2086 AS2 (sbci
,r29
,hi8(%o1
)));
2089 reg_base
= true_regnum (XEXP (base
, 0));
2090 if (reg_base
== REG_X
)
2093 if (reg_dest
== REG_X
)
2096 /* "ld r26,-X" is undefined */
2097 return (AS2 (adiw
,r26
,%o1
+3) CR_TAB
2098 AS2 (ld
,r29
,X
) CR_TAB
2099 AS2 (ld
,r28
,-X
) CR_TAB
2100 AS2 (ld
,__tmp_reg__
,-X
) CR_TAB
2101 AS2 (sbiw
,r26
,1) CR_TAB
2102 AS2 (ld
,r26
,X
) CR_TAB
2103 AS2 (mov
,r27
,__tmp_reg__
));
2106 if (reg_dest
== REG_X
- 2)
2107 return (AS2 (adiw
,r26
,%o1
) CR_TAB
2108 AS2 (ld
,r24
,X
+) CR_TAB
2109 AS2 (ld
,r25
,X
+) CR_TAB
2110 AS2 (ld
,__tmp_reg__
,X
+) CR_TAB
2111 AS2 (ld
,r27
,X
) CR_TAB
2112 AS2 (mov
,r26
,__tmp_reg__
));
2114 return (AS2 (adiw
,r26
,%o1
) CR_TAB
2115 AS2 (ld
,%A0
,X
+) CR_TAB
2116 AS2 (ld
,%B0
,X
+) CR_TAB
2117 AS2 (ld
,%C0
,X
+) CR_TAB
2118 AS2 (ld
,%D0
,X
) CR_TAB
2119 AS2 (sbiw
,r26
,%o1
+3));
2121 if (reg_dest
== reg_base
)
2122 return *l
=5, (AS2 (ldd
,%D0
,%D1
) CR_TAB
2123 AS2 (ldd
,%C0
,%C1
) CR_TAB
2124 AS2 (ldd
,__tmp_reg__
,%B1
) CR_TAB
2125 AS2 (ldd
,%A0
,%A1
) CR_TAB
2126 AS2 (mov
,%B0
,__tmp_reg__
));
2127 else if (reg_dest
== reg_base
- 2)
2128 return *l
=5, (AS2 (ldd
,%A0
,%A1
) CR_TAB
2129 AS2 (ldd
,%B0
,%B1
) CR_TAB
2130 AS2 (ldd
,__tmp_reg__
,%C1
) CR_TAB
2131 AS2 (ldd
,%D0
,%D1
) CR_TAB
2132 AS2 (mov
,%C0
,__tmp_reg__
));
2133 return *l
=4, (AS2 (ldd
,%A0
,%A1
) CR_TAB
2134 AS2 (ldd
,%B0
,%B1
) CR_TAB
2135 AS2 (ldd
,%C0
,%C1
) CR_TAB
2138 else if (GET_CODE (base
) == PRE_DEC
) /* (--R) */
2139 return *l
=4, (AS2 (ld
,%D0
,%1) CR_TAB
2140 AS2 (ld
,%C0
,%1) CR_TAB
2141 AS2 (ld
,%B0
,%1) CR_TAB
2143 else if (GET_CODE (base
) == POST_INC
) /* (R++) */
2144 return *l
=4, (AS2 (ld
,%A0
,%1) CR_TAB
2145 AS2 (ld
,%B0
,%1) CR_TAB
2146 AS2 (ld
,%C0
,%1) CR_TAB
2148 else if (CONSTANT_ADDRESS_P (base
))
2149 return *l
=8, (AS2 (lds
,%A0
,%A1
) CR_TAB
2150 AS2 (lds
,%B0
,%B1
) CR_TAB
2151 AS2 (lds
,%C0
,%C1
) CR_TAB
2154 fatal_insn ("unknown move insn:",insn
);
2159 out_movsi_mr_r (rtx insn
, rtx op
[], int *l
)
2163 rtx base
= XEXP (dest
, 0);
2164 int reg_base
= true_regnum (base
);
2165 int reg_src
= true_regnum (src
);
2171 if (CONSTANT_ADDRESS_P (base
))
2172 return *l
=8,(AS2 (sts
,%A0
,%A1
) CR_TAB
2173 AS2 (sts
,%B0
,%B1
) CR_TAB
2174 AS2 (sts
,%C0
,%C1
) CR_TAB
2176 if (reg_base
> 0) /* (r) */
2178 if (reg_base
== REG_X
) /* (R26) */
2180 if (reg_src
== REG_X
)
2182 /* "st X+,r26" is undefined */
2183 if (reg_unused_after (insn
, base
))
2184 return *l
=6, (AS2 (mov
,__tmp_reg__
,r27
) CR_TAB
2185 AS2 (st
,X
,r26
) CR_TAB
2186 AS2 (adiw
,r26
,1) CR_TAB
2187 AS2 (st
,X
+,__tmp_reg__
) CR_TAB
2188 AS2 (st
,X
+,r28
) CR_TAB
2191 return *l
=7, (AS2 (mov
,__tmp_reg__
,r27
) CR_TAB
2192 AS2 (st
,X
,r26
) CR_TAB
2193 AS2 (adiw
,r26
,1) CR_TAB
2194 AS2 (st
,X
+,__tmp_reg__
) CR_TAB
2195 AS2 (st
,X
+,r28
) CR_TAB
2196 AS2 (st
,X
,r29
) CR_TAB
2199 else if (reg_base
== reg_src
+ 2)
2201 if (reg_unused_after (insn
, base
))
2202 return *l
=7, (AS2 (mov
,__zero_reg__
,%C1
) CR_TAB
2203 AS2 (mov
,__tmp_reg__
,%D1
) CR_TAB
2204 AS2 (st
,%0+,%A1
) CR_TAB
2205 AS2 (st
,%0+,%B1
) CR_TAB
2206 AS2 (st
,%0+,__zero_reg__
) CR_TAB
2207 AS2 (st
,%0,__tmp_reg__
) CR_TAB
2208 AS1 (clr
,__zero_reg__
));
2210 return *l
=8, (AS2 (mov
,__zero_reg__
,%C1
) CR_TAB
2211 AS2 (mov
,__tmp_reg__
,%D1
) CR_TAB
2212 AS2 (st
,%0+,%A1
) CR_TAB
2213 AS2 (st
,%0+,%B1
) CR_TAB
2214 AS2 (st
,%0+,__zero_reg__
) CR_TAB
2215 AS2 (st
,%0,__tmp_reg__
) CR_TAB
2216 AS1 (clr
,__zero_reg__
) CR_TAB
2219 return *l
=5, (AS2 (st
,%0+,%A1
) CR_TAB
2220 AS2 (st
,%0+,%B1
) CR_TAB
2221 AS2 (st
,%0+,%C1
) CR_TAB
2222 AS2 (st
,%0,%D1
) CR_TAB
2226 return *l
=4, (AS2 (st
,%0,%A1
) CR_TAB
2227 AS2 (std
,%0+1,%B1
) CR_TAB
2228 AS2 (std
,%0+2,%C1
) CR_TAB
2229 AS2 (std
,%0+3,%D1
));
2231 else if (GET_CODE (base
) == PLUS
) /* (R + i) */
2233 int disp
= INTVAL (XEXP (base
, 1));
2234 reg_base
= REGNO (XEXP (base
, 0));
2235 if (disp
> MAX_LD_OFFSET (GET_MODE (dest
)))
2237 if (reg_base
!= REG_Y
)
2238 fatal_insn ("incorrect insn:",insn
);
2240 if (disp
<= 63 + MAX_LD_OFFSET (GET_MODE (dest
)))
2241 return *l
= 6, (AS2 (adiw
,r28
,%o0
-60) CR_TAB
2242 AS2 (std
,Y
+60,%A1
) CR_TAB
2243 AS2 (std
,Y
+61,%B1
) CR_TAB
2244 AS2 (std
,Y
+62,%C1
) CR_TAB
2245 AS2 (std
,Y
+63,%D1
) CR_TAB
2246 AS2 (sbiw
,r28
,%o0
-60));
2248 return *l
= 8, (AS2 (subi
,r28
,lo8(-%o0
)) CR_TAB
2249 AS2 (sbci
,r29
,hi8(-%o0
)) CR_TAB
2250 AS2 (st
,Y
,%A1
) CR_TAB
2251 AS2 (std
,Y
+1,%B1
) CR_TAB
2252 AS2 (std
,Y
+2,%C1
) CR_TAB
2253 AS2 (std
,Y
+3,%D1
) CR_TAB
2254 AS2 (subi
,r28
,lo8(%o0
)) CR_TAB
2255 AS2 (sbci
,r29
,hi8(%o0
)));
2257 if (reg_base
== REG_X
)
2260 if (reg_src
== REG_X
)
2263 return (AS2 (mov
,__tmp_reg__
,r26
) CR_TAB
2264 AS2 (mov
,__zero_reg__
,r27
) CR_TAB
2265 AS2 (adiw
,r26
,%o0
) CR_TAB
2266 AS2 (st
,X
+,__tmp_reg__
) CR_TAB
2267 AS2 (st
,X
+,__zero_reg__
) CR_TAB
2268 AS2 (st
,X
+,r28
) CR_TAB
2269 AS2 (st
,X
,r29
) CR_TAB
2270 AS1 (clr
,__zero_reg__
) CR_TAB
2271 AS2 (sbiw
,r26
,%o0
+3));
2273 else if (reg_src
== REG_X
- 2)
2276 return (AS2 (mov
,__tmp_reg__
,r26
) CR_TAB
2277 AS2 (mov
,__zero_reg__
,r27
) CR_TAB
2278 AS2 (adiw
,r26
,%o0
) CR_TAB
2279 AS2 (st
,X
+,r24
) CR_TAB
2280 AS2 (st
,X
+,r25
) CR_TAB
2281 AS2 (st
,X
+,__tmp_reg__
) CR_TAB
2282 AS2 (st
,X
,__zero_reg__
) CR_TAB
2283 AS1 (clr
,__zero_reg__
) CR_TAB
2284 AS2 (sbiw
,r26
,%o0
+3));
2287 return (AS2 (adiw
,r26
,%o0
) CR_TAB
2288 AS2 (st
,X
+,%A1
) CR_TAB
2289 AS2 (st
,X
+,%B1
) CR_TAB
2290 AS2 (st
,X
+,%C1
) CR_TAB
2291 AS2 (st
,X
,%D1
) CR_TAB
2292 AS2 (sbiw
,r26
,%o0
+3));
2294 return *l
=4, (AS2 (std
,%A0
,%A1
) CR_TAB
2295 AS2 (std
,%B0
,%B1
) CR_TAB
2296 AS2 (std
,%C0
,%C1
) CR_TAB
2299 else if (GET_CODE (base
) == PRE_DEC
) /* (--R) */
2300 return *l
=4, (AS2 (st
,%0,%D1
) CR_TAB
2301 AS2 (st
,%0,%C1
) CR_TAB
2302 AS2 (st
,%0,%B1
) CR_TAB
2304 else if (GET_CODE (base
) == POST_INC
) /* (R++) */
2305 return *l
=4, (AS2 (st
,%0,%A1
) CR_TAB
2306 AS2 (st
,%0,%B1
) CR_TAB
2307 AS2 (st
,%0,%C1
) CR_TAB
2309 fatal_insn ("unknown move insn:",insn
);
2314 output_movsisf(rtx insn
, rtx operands
[], int *l
)
2317 rtx dest
= operands
[0];
2318 rtx src
= operands
[1];
2324 if (register_operand (dest
, VOIDmode
))
2326 if (register_operand (src
, VOIDmode
)) /* mov r,r */
2328 if (true_regnum (dest
) > true_regnum (src
))
2333 return (AS2 (movw
,%C0
,%C1
) CR_TAB
2334 AS2 (movw
,%A0
,%A1
));
2337 return (AS2 (mov
,%D0
,%D1
) CR_TAB
2338 AS2 (mov
,%C0
,%C1
) CR_TAB
2339 AS2 (mov
,%B0
,%B1
) CR_TAB
2347 return (AS2 (movw
,%A0
,%A1
) CR_TAB
2348 AS2 (movw
,%C0
,%C1
));
2351 return (AS2 (mov
,%A0
,%A1
) CR_TAB
2352 AS2 (mov
,%B0
,%B1
) CR_TAB
2353 AS2 (mov
,%C0
,%C1
) CR_TAB
2357 else if (CONSTANT_P (src
))
2359 if (test_hard_reg_class (LD_REGS
, dest
)) /* ldi d,i */
2362 return (AS2 (ldi
,%A0
,lo8(%1)) CR_TAB
2363 AS2 (ldi
,%B0
,hi8(%1)) CR_TAB
2364 AS2 (ldi
,%C0
,hlo8(%1)) CR_TAB
2365 AS2 (ldi
,%D0
,hhi8(%1)));
2368 if (GET_CODE (src
) == CONST_INT
)
2370 const char *const clr_op0
=
2371 AVR_HAVE_MOVW
? (AS1 (clr
,%A0
) CR_TAB
2372 AS1 (clr
,%B0
) CR_TAB
2374 : (AS1 (clr
,%A0
) CR_TAB
2375 AS1 (clr
,%B0
) CR_TAB
2376 AS1 (clr
,%C0
) CR_TAB
2379 if (src
== const0_rtx
) /* mov r,L */
2381 *l
= AVR_HAVE_MOVW
? 3 : 4;
2384 else if (src
== const1_rtx
)
2387 output_asm_insn (clr_op0
, operands
);
2388 *l
= AVR_HAVE_MOVW
? 4 : 5;
2389 return AS1 (inc
,%A0
);
2391 else if (src
== constm1_rtx
)
2393 /* Immediate constants -1 to any register */
2397 return (AS1 (clr
,%A0
) CR_TAB
2398 AS1 (dec
,%A0
) CR_TAB
2399 AS2 (mov
,%B0
,%A0
) CR_TAB
2400 AS2 (movw
,%C0
,%A0
));
2403 return (AS1 (clr
,%A0
) CR_TAB
2404 AS1 (dec
,%A0
) CR_TAB
2405 AS2 (mov
,%B0
,%A0
) CR_TAB
2406 AS2 (mov
,%C0
,%A0
) CR_TAB
2411 int bit_nr
= exact_log2 (INTVAL (src
));
2415 *l
= AVR_HAVE_MOVW
? 5 : 6;
2418 output_asm_insn (clr_op0
, operands
);
2419 output_asm_insn ("set", operands
);
2422 avr_output_bld (operands
, bit_nr
);
2429 /* Last resort, better than loading from memory. */
2431 return (AS2 (mov
,__tmp_reg__
,r31
) CR_TAB
2432 AS2 (ldi
,r31
,lo8(%1)) CR_TAB
2433 AS2 (mov
,%A0
,r31
) CR_TAB
2434 AS2 (ldi
,r31
,hi8(%1)) CR_TAB
2435 AS2 (mov
,%B0
,r31
) CR_TAB
2436 AS2 (ldi
,r31
,hlo8(%1)) CR_TAB
2437 AS2 (mov
,%C0
,r31
) CR_TAB
2438 AS2 (ldi
,r31
,hhi8(%1)) CR_TAB
2439 AS2 (mov
,%D0
,r31
) CR_TAB
2440 AS2 (mov
,r31
,__tmp_reg__
));
2442 else if (GET_CODE (src
) == MEM
)
2443 return out_movsi_r_mr (insn
, operands
, real_l
); /* mov r,m */
2445 else if (GET_CODE (dest
) == MEM
)
2449 if (src
== const0_rtx
)
2450 operands
[1] = zero_reg_rtx
;
2452 templ
= out_movsi_mr_r (insn
, operands
, real_l
);
2455 output_asm_insn (templ
, operands
);
2460 fatal_insn ("invalid insn:", insn
);
2465 out_movqi_mr_r (rtx insn
, rtx op
[], int *l
)
2469 rtx x
= XEXP (dest
, 0);
2475 if (CONSTANT_ADDRESS_P (x
))
2477 if (CONST_INT_P (x
) && INTVAL (x
) == SREG_ADDR
)
2480 return AS2 (out
,__SREG__
,%1);
2482 if (optimize
> 0 && io_address_operand (x
, QImode
))
2485 return AS2 (out
,%0-0x20,%1);
2488 return AS2 (sts
,%0,%1);
2490 /* memory access by reg+disp */
2491 else if (GET_CODE (x
) == PLUS
2492 && REG_P (XEXP (x
,0))
2493 && GET_CODE (XEXP (x
,1)) == CONST_INT
)
2495 if ((INTVAL (XEXP (x
,1)) - GET_MODE_SIZE (GET_MODE (dest
))) >= 63)
2497 int disp
= INTVAL (XEXP (x
,1));
2498 if (REGNO (XEXP (x
,0)) != REG_Y
)
2499 fatal_insn ("incorrect insn:",insn
);
2501 if (disp
<= 63 + MAX_LD_OFFSET (GET_MODE (dest
)))
2502 return *l
= 3, (AS2 (adiw
,r28
,%o0
-63) CR_TAB
2503 AS2 (std
,Y
+63,%1) CR_TAB
2504 AS2 (sbiw
,r28
,%o0
-63));
2506 return *l
= 5, (AS2 (subi
,r28
,lo8(-%o0
)) CR_TAB
2507 AS2 (sbci
,r29
,hi8(-%o0
)) CR_TAB
2508 AS2 (st
,Y
,%1) CR_TAB
2509 AS2 (subi
,r28
,lo8(%o0
)) CR_TAB
2510 AS2 (sbci
,r29
,hi8(%o0
)));
2512 else if (REGNO (XEXP (x
,0)) == REG_X
)
2514 if (reg_overlap_mentioned_p (src
, XEXP (x
, 0)))
2516 if (reg_unused_after (insn
, XEXP (x
,0)))
2517 return *l
= 3, (AS2 (mov
,__tmp_reg__
,%1) CR_TAB
2518 AS2 (adiw
,r26
,%o0
) CR_TAB
2519 AS2 (st
,X
,__tmp_reg__
));
2521 return *l
= 4, (AS2 (mov
,__tmp_reg__
,%1) CR_TAB
2522 AS2 (adiw
,r26
,%o0
) CR_TAB
2523 AS2 (st
,X
,__tmp_reg__
) CR_TAB
2524 AS2 (sbiw
,r26
,%o0
));
2528 if (reg_unused_after (insn
, XEXP (x
,0)))
2529 return *l
= 2, (AS2 (adiw
,r26
,%o0
) CR_TAB
2532 return *l
= 3, (AS2 (adiw
,r26
,%o0
) CR_TAB
2533 AS2 (st
,X
,%1) CR_TAB
2534 AS2 (sbiw
,r26
,%o0
));
2538 return AS2 (std
,%0,%1);
2541 return AS2 (st
,%0,%1);
2545 out_movhi_mr_r (rtx insn
, rtx op
[], int *l
)
2549 rtx base
= XEXP (dest
, 0);
2550 int reg_base
= true_regnum (base
);
2551 int reg_src
= true_regnum (src
);
2552 /* "volatile" forces writing high byte first, even if less efficient,
2553 for correct operation with 16-bit I/O registers. */
2554 int mem_volatile_p
= MEM_VOLATILE_P (dest
);
2559 if (CONSTANT_ADDRESS_P (base
))
2561 if (optimize
> 0 && io_address_operand (base
, HImode
))
2564 return (AS2 (out
,%B0
-0x20,%B1
) CR_TAB
2565 AS2 (out
,%A0
-0x20,%A1
));
2567 return *l
= 4, (AS2 (sts
,%B0
,%B1
) CR_TAB
2572 if (reg_base
== REG_X
)
2574 if (reg_src
== REG_X
)
2576 /* "st X+,r26" and "st -X,r26" are undefined. */
2577 if (!mem_volatile_p
&& reg_unused_after (insn
, src
))
2578 return *l
=4, (AS2 (mov
,__tmp_reg__
,r27
) CR_TAB
2579 AS2 (st
,X
,r26
) CR_TAB
2580 AS2 (adiw
,r26
,1) CR_TAB
2581 AS2 (st
,X
,__tmp_reg__
));
2583 return *l
=5, (AS2 (mov
,__tmp_reg__
,r27
) CR_TAB
2584 AS2 (adiw
,r26
,1) CR_TAB
2585 AS2 (st
,X
,__tmp_reg__
) CR_TAB
2586 AS2 (sbiw
,r26
,1) CR_TAB
2591 if (!mem_volatile_p
&& reg_unused_after (insn
, base
))
2592 return *l
=2, (AS2 (st
,X
+,%A1
) CR_TAB
2595 return *l
=3, (AS2 (adiw
,r26
,1) CR_TAB
2596 AS2 (st
,X
,%B1
) CR_TAB
2601 return *l
=2, (AS2 (std
,%0+1,%B1
) CR_TAB
2604 else if (GET_CODE (base
) == PLUS
)
2606 int disp
= INTVAL (XEXP (base
, 1));
2607 reg_base
= REGNO (XEXP (base
, 0));
2608 if (disp
> MAX_LD_OFFSET (GET_MODE (dest
)))
2610 if (reg_base
!= REG_Y
)
2611 fatal_insn ("incorrect insn:",insn
);
2613 if (disp
<= 63 + MAX_LD_OFFSET (GET_MODE (dest
)))
2614 return *l
= 4, (AS2 (adiw
,r28
,%o0
-62) CR_TAB
2615 AS2 (std
,Y
+63,%B1
) CR_TAB
2616 AS2 (std
,Y
+62,%A1
) CR_TAB
2617 AS2 (sbiw
,r28
,%o0
-62));
2619 return *l
= 6, (AS2 (subi
,r28
,lo8(-%o0
)) CR_TAB
2620 AS2 (sbci
,r29
,hi8(-%o0
)) CR_TAB
2621 AS2 (std
,Y
+1,%B1
) CR_TAB
2622 AS2 (st
,Y
,%A1
) CR_TAB
2623 AS2 (subi
,r28
,lo8(%o0
)) CR_TAB
2624 AS2 (sbci
,r29
,hi8(%o0
)));
2626 if (reg_base
== REG_X
)
2629 if (reg_src
== REG_X
)
2632 return (AS2 (mov
,__tmp_reg__
,r26
) CR_TAB
2633 AS2 (mov
,__zero_reg__
,r27
) CR_TAB
2634 AS2 (adiw
,r26
,%o0
+1) CR_TAB
2635 AS2 (st
,X
,__zero_reg__
) CR_TAB
2636 AS2 (st
,-X
,__tmp_reg__
) CR_TAB
2637 AS1 (clr
,__zero_reg__
) CR_TAB
2638 AS2 (sbiw
,r26
,%o0
));
2641 return (AS2 (adiw
,r26
,%o0
+1) CR_TAB
2642 AS2 (st
,X
,%B1
) CR_TAB
2643 AS2 (st
,-X
,%A1
) CR_TAB
2644 AS2 (sbiw
,r26
,%o0
));
2646 return *l
=2, (AS2 (std
,%B0
,%B1
) CR_TAB
2649 else if (GET_CODE (base
) == PRE_DEC
) /* (--R) */
2650 return *l
=2, (AS2 (st
,%0,%B1
) CR_TAB
2652 else if (GET_CODE (base
) == POST_INC
) /* (R++) */
2656 if (REGNO (XEXP (base
, 0)) == REG_X
)
2659 return (AS2 (adiw
,r26
,1) CR_TAB
2660 AS2 (st
,X
,%B1
) CR_TAB
2661 AS2 (st
,-X
,%A1
) CR_TAB
2667 return (AS2 (std
,%p0
+1,%B1
) CR_TAB
2668 AS2 (st
,%p0
,%A1
) CR_TAB
2674 return (AS2 (st
,%0,%A1
) CR_TAB
2677 fatal_insn ("unknown move insn:",insn
);
2681 /* Return 1 if frame pointer for current function required. */
2684 avr_frame_pointer_required_p (void)
2686 return (cfun
->calls_alloca
2687 || crtl
->args
.info
.nregs
== 0
2688 || get_frame_size () > 0);
2691 /* Returns the condition of compare insn INSN, or UNKNOWN. */
2694 compare_condition (rtx insn
)
2696 rtx next
= next_real_insn (insn
);
2697 RTX_CODE cond
= UNKNOWN
;
2698 if (next
&& GET_CODE (next
) == JUMP_INSN
)
2700 rtx pat
= PATTERN (next
);
2701 rtx src
= SET_SRC (pat
);
2702 rtx t
= XEXP (src
, 0);
2703 cond
= GET_CODE (t
);
2708 /* Returns nonzero if INSN is a tst insn that only tests the sign. */
2711 compare_sign_p (rtx insn
)
2713 RTX_CODE cond
= compare_condition (insn
);
2714 return (cond
== GE
|| cond
== LT
);
2717 /* Returns nonzero if the next insn is a JUMP_INSN with a condition
2718 that needs to be swapped (GT, GTU, LE, LEU). */
2721 compare_diff_p (rtx insn
)
2723 RTX_CODE cond
= compare_condition (insn
);
2724 return (cond
== GT
|| cond
== GTU
|| cond
== LE
|| cond
== LEU
) ? cond
: 0;
2727 /* Returns nonzero if INSN is a compare insn with the EQ or NE condition. */
2730 compare_eq_p (rtx insn
)
2732 RTX_CODE cond
= compare_condition (insn
);
2733 return (cond
== EQ
|| cond
== NE
);
2737 /* Output test instruction for HImode. */
2740 out_tsthi (rtx insn
, rtx op
, int *l
)
2742 if (compare_sign_p (insn
))
2745 return AS1 (tst
,%B0
);
2747 if (reg_unused_after (insn
, op
)
2748 && compare_eq_p (insn
))
2750 /* Faster than sbiw if we can clobber the operand. */
2752 return "or %A0,%B0";
2754 if (test_hard_reg_class (ADDW_REGS
, op
))
2757 return AS2 (sbiw
,%0,0);
2760 return (AS2 (cp
,%A0
,__zero_reg__
) CR_TAB
2761 AS2 (cpc
,%B0
,__zero_reg__
));
2765 /* Output test instruction for SImode. */
2768 out_tstsi (rtx insn
, rtx op
, int *l
)
2770 if (compare_sign_p (insn
))
2773 return AS1 (tst
,%D0
);
2775 if (test_hard_reg_class (ADDW_REGS
, op
))
2778 return (AS2 (sbiw
,%A0
,0) CR_TAB
2779 AS2 (cpc
,%C0
,__zero_reg__
) CR_TAB
2780 AS2 (cpc
,%D0
,__zero_reg__
));
2783 return (AS2 (cp
,%A0
,__zero_reg__
) CR_TAB
2784 AS2 (cpc
,%B0
,__zero_reg__
) CR_TAB
2785 AS2 (cpc
,%C0
,__zero_reg__
) CR_TAB
2786 AS2 (cpc
,%D0
,__zero_reg__
));
2790 /* Generate asm equivalent for various shifts.
2791 Shift count is a CONST_INT, MEM or REG.
2792 This only handles cases that are not already
2793 carefully hand-optimized in ?sh??i3_out. */
2796 out_shift_with_cnt (const char *templ
, rtx insn
, rtx operands
[],
2797 int *len
, int t_len
)
2801 int second_label
= 1;
2802 int saved_in_tmp
= 0;
2803 int use_zero_reg
= 0;
2805 op
[0] = operands
[0];
2806 op
[1] = operands
[1];
2807 op
[2] = operands
[2];
2808 op
[3] = operands
[3];
2814 if (GET_CODE (operands
[2]) == CONST_INT
)
2816 int scratch
= (GET_CODE (PATTERN (insn
)) == PARALLEL
);
2817 int count
= INTVAL (operands
[2]);
2818 int max_len
= 10; /* If larger than this, always use a loop. */
2827 if (count
< 8 && !scratch
)
2831 max_len
= t_len
+ (scratch
? 3 : (use_zero_reg
? 4 : 5));
2833 if (t_len
* count
<= max_len
)
2835 /* Output shifts inline with no loop - faster. */
2837 *len
= t_len
* count
;
2841 output_asm_insn (templ
, op
);
2850 strcat (str
, AS2 (ldi
,%3,%2));
2852 else if (use_zero_reg
)
2854 /* Hack to save one word: use __zero_reg__ as loop counter.
2855 Set one bit, then shift in a loop until it is 0 again. */
2857 op
[3] = zero_reg_rtx
;
2861 strcat (str
, ("set" CR_TAB
2862 AS2 (bld
,%3,%2-1)));
2866 /* No scratch register available, use one from LD_REGS (saved in
2867 __tmp_reg__) that doesn't overlap with registers to shift. */
2869 op
[3] = gen_rtx_REG (QImode
,
2870 ((true_regnum (operands
[0]) - 1) & 15) + 16);
2871 op
[4] = tmp_reg_rtx
;
2875 *len
= 3; /* Includes "mov %3,%4" after the loop. */
2877 strcat (str
, (AS2 (mov
,%4,%3) CR_TAB
2883 else if (GET_CODE (operands
[2]) == MEM
)
2887 op
[3] = op_mov
[0] = tmp_reg_rtx
;
2891 out_movqi_r_mr (insn
, op_mov
, len
);
2893 output_asm_insn (out_movqi_r_mr (insn
, op_mov
, NULL
), op_mov
);
2895 else if (register_operand (operands
[2], QImode
))
2897 if (reg_unused_after (insn
, operands
[2]))
2901 op
[3] = tmp_reg_rtx
;
2903 strcat (str
, (AS2 (mov
,%3,%2) CR_TAB
));
2907 fatal_insn ("bad shift insn:", insn
);
2914 strcat (str
, AS1 (rjmp
,2f
));
2918 *len
+= t_len
+ 2; /* template + dec + brXX */
2921 strcat (str
, "\n1:\t");
2922 strcat (str
, templ
);
2923 strcat (str
, second_label
? "\n2:\t" : "\n\t");
2924 strcat (str
, use_zero_reg
? AS1 (lsr
,%3) : AS1 (dec
,%3));
2925 strcat (str
, CR_TAB
);
2926 strcat (str
, second_label
? AS1 (brpl
,1b
) : AS1 (brne
,1b
));
2928 strcat (str
, (CR_TAB
AS2 (mov
,%3,%4)));
2929 output_asm_insn (str
, op
);
2934 /* 8bit shift left ((char)x << i) */
2937 ashlqi3_out (rtx insn
, rtx operands
[], int *len
)
2939 if (GET_CODE (operands
[2]) == CONST_INT
)
2946 switch (INTVAL (operands
[2]))
2949 if (INTVAL (operands
[2]) < 8)
2953 return AS1 (clr
,%0);
2957 return AS1 (lsl
,%0);
2961 return (AS1 (lsl
,%0) CR_TAB
2966 return (AS1 (lsl
,%0) CR_TAB
2971 if (test_hard_reg_class (LD_REGS
, operands
[0]))
2974 return (AS1 (swap
,%0) CR_TAB
2975 AS2 (andi
,%0,0xf0));
2978 return (AS1 (lsl
,%0) CR_TAB
2984 if (test_hard_reg_class (LD_REGS
, operands
[0]))
2987 return (AS1 (swap
,%0) CR_TAB
2989 AS2 (andi
,%0,0xe0));
2992 return (AS1 (lsl
,%0) CR_TAB
2999 if (test_hard_reg_class (LD_REGS
, operands
[0]))
3002 return (AS1 (swap
,%0) CR_TAB
3005 AS2 (andi
,%0,0xc0));
3008 return (AS1 (lsl
,%0) CR_TAB
3017 return (AS1 (ror
,%0) CR_TAB
3022 else if (CONSTANT_P (operands
[2]))
3023 fatal_insn ("internal compiler error. Incorrect shift:", insn
);
3025 out_shift_with_cnt (AS1 (lsl
,%0),
3026 insn
, operands
, len
, 1);
3031 /* 16bit shift left ((short)x << i) */
3034 ashlhi3_out (rtx insn
, rtx operands
[], int *len
)
3036 if (GET_CODE (operands
[2]) == CONST_INT
)
3038 int scratch
= (GET_CODE (PATTERN (insn
)) == PARALLEL
);
3039 int ldi_ok
= test_hard_reg_class (LD_REGS
, operands
[0]);
3046 switch (INTVAL (operands
[2]))
3049 if (INTVAL (operands
[2]) < 16)
3053 return (AS1 (clr
,%B0
) CR_TAB
3057 if (optimize_size
&& scratch
)
3062 return (AS1 (swap
,%A0
) CR_TAB
3063 AS1 (swap
,%B0
) CR_TAB
3064 AS2 (andi
,%B0
,0xf0) CR_TAB
3065 AS2 (eor
,%B0
,%A0
) CR_TAB
3066 AS2 (andi
,%A0
,0xf0) CR_TAB
3072 return (AS1 (swap
,%A0
) CR_TAB
3073 AS1 (swap
,%B0
) CR_TAB
3074 AS2 (ldi
,%3,0xf0) CR_TAB
3076 AS2 (eor
,%B0
,%A0
) CR_TAB
3080 break; /* optimize_size ? 6 : 8 */
3084 break; /* scratch ? 5 : 6 */
3088 return (AS1 (lsl
,%A0
) CR_TAB
3089 AS1 (rol
,%B0
) CR_TAB
3090 AS1 (swap
,%A0
) CR_TAB
3091 AS1 (swap
,%B0
) CR_TAB
3092 AS2 (andi
,%B0
,0xf0) CR_TAB
3093 AS2 (eor
,%B0
,%A0
) CR_TAB
3094 AS2 (andi
,%A0
,0xf0) CR_TAB
3100 return (AS1 (lsl
,%A0
) CR_TAB
3101 AS1 (rol
,%B0
) CR_TAB
3102 AS1 (swap
,%A0
) CR_TAB
3103 AS1 (swap
,%B0
) CR_TAB
3104 AS2 (ldi
,%3,0xf0) CR_TAB
3106 AS2 (eor
,%B0
,%A0
) CR_TAB
3114 break; /* scratch ? 5 : 6 */
3116 return (AS1 (clr
,__tmp_reg__
) CR_TAB
3117 AS1 (lsr
,%B0
) CR_TAB
3118 AS1 (ror
,%A0
) CR_TAB
3119 AS1 (ror
,__tmp_reg__
) CR_TAB
3120 AS1 (lsr
,%B0
) CR_TAB
3121 AS1 (ror
,%A0
) CR_TAB
3122 AS1 (ror
,__tmp_reg__
) CR_TAB
3123 AS2 (mov
,%B0
,%A0
) CR_TAB
3124 AS2 (mov
,%A0
,__tmp_reg__
));
3128 return (AS1 (lsr
,%B0
) CR_TAB
3129 AS2 (mov
,%B0
,%A0
) CR_TAB
3130 AS1 (clr
,%A0
) CR_TAB
3131 AS1 (ror
,%B0
) CR_TAB
3135 return *len
= 2, (AS2 (mov
,%B0
,%A1
) CR_TAB
3140 return (AS2 (mov
,%B0
,%A0
) CR_TAB
3141 AS1 (clr
,%A0
) CR_TAB
3146 return (AS2 (mov
,%B0
,%A0
) CR_TAB
3147 AS1 (clr
,%A0
) CR_TAB
3148 AS1 (lsl
,%B0
) CR_TAB
3153 return (AS2 (mov
,%B0
,%A0
) CR_TAB
3154 AS1 (clr
,%A0
) CR_TAB
3155 AS1 (lsl
,%B0
) CR_TAB
3156 AS1 (lsl
,%B0
) CR_TAB
3163 return (AS2 (mov
,%B0
,%A0
) CR_TAB
3164 AS1 (clr
,%A0
) CR_TAB
3165 AS1 (swap
,%B0
) CR_TAB
3166 AS2 (andi
,%B0
,0xf0));
3171 return (AS2 (mov
,%B0
,%A0
) CR_TAB
3172 AS1 (clr
,%A0
) CR_TAB
3173 AS1 (swap
,%B0
) CR_TAB
3174 AS2 (ldi
,%3,0xf0) CR_TAB
3178 return (AS2 (mov
,%B0
,%A0
) CR_TAB
3179 AS1 (clr
,%A0
) CR_TAB
3180 AS1 (lsl
,%B0
) CR_TAB
3181 AS1 (lsl
,%B0
) CR_TAB
3182 AS1 (lsl
,%B0
) CR_TAB
3189 return (AS2 (mov
,%B0
,%A0
) CR_TAB
3190 AS1 (clr
,%A0
) CR_TAB
3191 AS1 (swap
,%B0
) CR_TAB
3192 AS1 (lsl
,%B0
) CR_TAB
3193 AS2 (andi
,%B0
,0xe0));
3195 if (AVR_HAVE_MUL
&& scratch
)
3198 return (AS2 (ldi
,%3,0x20) CR_TAB
3199 AS2 (mul
,%A0
,%3) CR_TAB
3200 AS2 (mov
,%B0
,r0
) CR_TAB
3201 AS1 (clr
,%A0
) CR_TAB
3202 AS1 (clr
,__zero_reg__
));
3204 if (optimize_size
&& scratch
)
3209 return (AS2 (mov
,%B0
,%A0
) CR_TAB
3210 AS1 (clr
,%A0
) CR_TAB
3211 AS1 (swap
,%B0
) CR_TAB
3212 AS1 (lsl
,%B0
) CR_TAB
3213 AS2 (ldi
,%3,0xe0) CR_TAB
3219 return ("set" CR_TAB
3220 AS2 (bld
,r1
,5) CR_TAB
3221 AS2 (mul
,%A0
,r1
) CR_TAB
3222 AS2 (mov
,%B0
,r0
) CR_TAB
3223 AS1 (clr
,%A0
) CR_TAB
3224 AS1 (clr
,__zero_reg__
));
3227 return (AS2 (mov
,%B0
,%A0
) CR_TAB
3228 AS1 (clr
,%A0
) CR_TAB
3229 AS1 (lsl
,%B0
) CR_TAB
3230 AS1 (lsl
,%B0
) CR_TAB
3231 AS1 (lsl
,%B0
) CR_TAB
3232 AS1 (lsl
,%B0
) CR_TAB
3236 if (AVR_HAVE_MUL
&& ldi_ok
)
3239 return (AS2 (ldi
,%B0
,0x40) CR_TAB
3240 AS2 (mul
,%A0
,%B0
) CR_TAB
3241 AS2 (mov
,%B0
,r0
) CR_TAB
3242 AS1 (clr
,%A0
) CR_TAB
3243 AS1 (clr
,__zero_reg__
));
3245 if (AVR_HAVE_MUL
&& scratch
)
3248 return (AS2 (ldi
,%3,0x40) CR_TAB
3249 AS2 (mul
,%A0
,%3) CR_TAB
3250 AS2 (mov
,%B0
,r0
) CR_TAB
3251 AS1 (clr
,%A0
) CR_TAB
3252 AS1 (clr
,__zero_reg__
));
3254 if (optimize_size
&& ldi_ok
)
3257 return (AS2 (mov
,%B0
,%A0
) CR_TAB
3258 AS2 (ldi
,%A0
,6) "\n1:\t"
3259 AS1 (lsl
,%B0
) CR_TAB
3260 AS1 (dec
,%A0
) CR_TAB
3263 if (optimize_size
&& scratch
)
3266 return (AS1 (clr
,%B0
) CR_TAB
3267 AS1 (lsr
,%A0
) CR_TAB
3268 AS1 (ror
,%B0
) CR_TAB
3269 AS1 (lsr
,%A0
) CR_TAB
3270 AS1 (ror
,%B0
) CR_TAB
3275 return (AS1 (clr
,%B0
) CR_TAB
3276 AS1 (lsr
,%A0
) CR_TAB
3277 AS1 (ror
,%B0
) CR_TAB
3282 out_shift_with_cnt ((AS1 (lsl
,%A0
) CR_TAB
3284 insn
, operands
, len
, 2);
3289 /* 32bit shift left ((long)x << i) */
3292 ashlsi3_out (rtx insn
, rtx operands
[], int *len
)
3294 if (GET_CODE (operands
[2]) == CONST_INT
)
3302 switch (INTVAL (operands
[2]))
3305 if (INTVAL (operands
[2]) < 32)
3309 return *len
= 3, (AS1 (clr
,%D0
) CR_TAB
3310 AS1 (clr
,%C0
) CR_TAB
3311 AS2 (movw
,%A0
,%C0
));
3313 return (AS1 (clr
,%D0
) CR_TAB
3314 AS1 (clr
,%C0
) CR_TAB
3315 AS1 (clr
,%B0
) CR_TAB
3320 int reg0
= true_regnum (operands
[0]);
3321 int reg1
= true_regnum (operands
[1]);
3324 return (AS2 (mov
,%D0
,%C1
) CR_TAB
3325 AS2 (mov
,%C0
,%B1
) CR_TAB
3326 AS2 (mov
,%B0
,%A1
) CR_TAB
3329 return (AS1 (clr
,%A0
) CR_TAB
3330 AS2 (mov
,%B0
,%A1
) CR_TAB
3331 AS2 (mov
,%C0
,%B1
) CR_TAB
3337 int reg0
= true_regnum (operands
[0]);
3338 int reg1
= true_regnum (operands
[1]);
3339 if (reg0
+ 2 == reg1
)
3340 return *len
= 2, (AS1 (clr
,%B0
) CR_TAB
3343 return *len
= 3, (AS2 (movw
,%C0
,%A1
) CR_TAB
3344 AS1 (clr
,%B0
) CR_TAB
3347 return *len
= 4, (AS2 (mov
,%C0
,%A1
) CR_TAB
3348 AS2 (mov
,%D0
,%B1
) CR_TAB
3349 AS1 (clr
,%B0
) CR_TAB
3355 return (AS2 (mov
,%D0
,%A1
) CR_TAB
3356 AS1 (clr
,%C0
) CR_TAB
3357 AS1 (clr
,%B0
) CR_TAB
3362 return (AS1 (clr
,%D0
) CR_TAB
3363 AS1 (lsr
,%A0
) CR_TAB
3364 AS1 (ror
,%D0
) CR_TAB
3365 AS1 (clr
,%C0
) CR_TAB
3366 AS1 (clr
,%B0
) CR_TAB
3371 out_shift_with_cnt ((AS1 (lsl
,%A0
) CR_TAB
3372 AS1 (rol
,%B0
) CR_TAB
3373 AS1 (rol
,%C0
) CR_TAB
3375 insn
, operands
, len
, 4);
3379 /* 8bit arithmetic shift right ((signed char)x >> i) */
3382 ashrqi3_out (rtx insn
, rtx operands
[], int *len
)
3384 if (GET_CODE (operands
[2]) == CONST_INT
)
3391 switch (INTVAL (operands
[2]))
3395 return AS1 (asr
,%0);
3399 return (AS1 (asr
,%0) CR_TAB
3404 return (AS1 (asr
,%0) CR_TAB
3410 return (AS1 (asr
,%0) CR_TAB
3417 return (AS1 (asr
,%0) CR_TAB
3425 return (AS2 (bst
,%0,6) CR_TAB
3427 AS2 (sbc
,%0,%0) CR_TAB
3431 if (INTVAL (operands
[2]) < 8)
3438 return (AS1 (lsl
,%0) CR_TAB
3442 else if (CONSTANT_P (operands
[2]))
3443 fatal_insn ("internal compiler error. Incorrect shift:", insn
);
3445 out_shift_with_cnt (AS1 (asr
,%0),
3446 insn
, operands
, len
, 1);
3451 /* 16bit arithmetic shift right ((signed short)x >> i) */
3454 ashrhi3_out (rtx insn
, rtx operands
[], int *len
)
3456 if (GET_CODE (operands
[2]) == CONST_INT
)
3458 int scratch
= (GET_CODE (PATTERN (insn
)) == PARALLEL
);
3459 int ldi_ok
= test_hard_reg_class (LD_REGS
, operands
[0]);
3466 switch (INTVAL (operands
[2]))
3470 /* XXX try to optimize this too? */
3475 break; /* scratch ? 5 : 6 */
3477 return (AS2 (mov
,__tmp_reg__
,%A0
) CR_TAB
3478 AS2 (mov
,%A0
,%B0
) CR_TAB
3479 AS1 (lsl
,__tmp_reg__
) CR_TAB
3480 AS1 (rol
,%A0
) CR_TAB
3481 AS2 (sbc
,%B0
,%B0
) CR_TAB
3482 AS1 (lsl
,__tmp_reg__
) CR_TAB
3483 AS1 (rol
,%A0
) CR_TAB
3488 return (AS1 (lsl
,%A0
) CR_TAB
3489 AS2 (mov
,%A0
,%B0
) CR_TAB
3490 AS1 (rol
,%A0
) CR_TAB
3495 int reg0
= true_regnum (operands
[0]);
3496 int reg1
= true_regnum (operands
[1]);
3499 return *len
= 3, (AS2 (mov
,%A0
,%B0
) CR_TAB
3500 AS1 (lsl
,%B0
) CR_TAB
3503 return *len
= 4, (AS2 (mov
,%A0
,%B1
) CR_TAB
3504 AS1 (clr
,%B0
) CR_TAB
3505 AS2 (sbrc
,%A0
,7) CR_TAB
3511 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3512 AS1 (lsl
,%B0
) CR_TAB
3513 AS2 (sbc
,%B0
,%B0
) CR_TAB
3518 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3519 AS1 (lsl
,%B0
) CR_TAB
3520 AS2 (sbc
,%B0
,%B0
) CR_TAB
3521 AS1 (asr
,%A0
) CR_TAB
3525 if (AVR_HAVE_MUL
&& ldi_ok
)
3528 return (AS2 (ldi
,%A0
,0x20) CR_TAB
3529 AS2 (muls
,%B0
,%A0
) CR_TAB
3530 AS2 (mov
,%A0
,r1
) CR_TAB
3531 AS2 (sbc
,%B0
,%B0
) CR_TAB
3532 AS1 (clr
,__zero_reg__
));
3534 if (optimize_size
&& scratch
)
3537 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3538 AS1 (lsl
,%B0
) CR_TAB
3539 AS2 (sbc
,%B0
,%B0
) CR_TAB
3540 AS1 (asr
,%A0
) CR_TAB
3541 AS1 (asr
,%A0
) CR_TAB
3545 if (AVR_HAVE_MUL
&& ldi_ok
)
3548 return (AS2 (ldi
,%A0
,0x10) CR_TAB
3549 AS2 (muls
,%B0
,%A0
) CR_TAB
3550 AS2 (mov
,%A0
,r1
) CR_TAB
3551 AS2 (sbc
,%B0
,%B0
) CR_TAB
3552 AS1 (clr
,__zero_reg__
));
3554 if (optimize_size
&& scratch
)
3557 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3558 AS1 (lsl
,%B0
) CR_TAB
3559 AS2 (sbc
,%B0
,%B0
) CR_TAB
3560 AS1 (asr
,%A0
) CR_TAB
3561 AS1 (asr
,%A0
) CR_TAB
3562 AS1 (asr
,%A0
) CR_TAB
3566 if (AVR_HAVE_MUL
&& ldi_ok
)
3569 return (AS2 (ldi
,%A0
,0x08) CR_TAB
3570 AS2 (muls
,%B0
,%A0
) CR_TAB
3571 AS2 (mov
,%A0
,r1
) CR_TAB
3572 AS2 (sbc
,%B0
,%B0
) CR_TAB
3573 AS1 (clr
,__zero_reg__
));
3576 break; /* scratch ? 5 : 7 */
3578 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3579 AS1 (lsl
,%B0
) CR_TAB
3580 AS2 (sbc
,%B0
,%B0
) CR_TAB
3581 AS1 (asr
,%A0
) CR_TAB
3582 AS1 (asr
,%A0
) CR_TAB
3583 AS1 (asr
,%A0
) CR_TAB
3584 AS1 (asr
,%A0
) CR_TAB
3589 return (AS1 (lsl
,%B0
) CR_TAB
3590 AS2 (sbc
,%A0
,%A0
) CR_TAB
3591 AS1 (lsl
,%B0
) CR_TAB
3592 AS2 (mov
,%B0
,%A0
) CR_TAB
3596 if (INTVAL (operands
[2]) < 16)
3602 return *len
= 3, (AS1 (lsl
,%B0
) CR_TAB
3603 AS2 (sbc
,%A0
,%A0
) CR_TAB
3608 out_shift_with_cnt ((AS1 (asr
,%B0
) CR_TAB
3610 insn
, operands
, len
, 2);
3615 /* 32bit arithmetic shift right ((signed long)x >> i) */
3618 ashrsi3_out (rtx insn
, rtx operands
[], int *len
)
3620 if (GET_CODE (operands
[2]) == CONST_INT
)
3628 switch (INTVAL (operands
[2]))
3632 int reg0
= true_regnum (operands
[0]);
3633 int reg1
= true_regnum (operands
[1]);
3636 return (AS2 (mov
,%A0
,%B1
) CR_TAB
3637 AS2 (mov
,%B0
,%C1
) CR_TAB
3638 AS2 (mov
,%C0
,%D1
) CR_TAB
3639 AS1 (clr
,%D0
) CR_TAB
3640 AS2 (sbrc
,%C0
,7) CR_TAB
3643 return (AS1 (clr
,%D0
) CR_TAB
3644 AS2 (sbrc
,%D1
,7) CR_TAB
3645 AS1 (dec
,%D0
) CR_TAB
3646 AS2 (mov
,%C0
,%D1
) CR_TAB
3647 AS2 (mov
,%B0
,%C1
) CR_TAB
3653 int reg0
= true_regnum (operands
[0]);
3654 int reg1
= true_regnum (operands
[1]);
3656 if (reg0
== reg1
+ 2)
3657 return *len
= 4, (AS1 (clr
,%D0
) CR_TAB
3658 AS2 (sbrc
,%B0
,7) CR_TAB
3659 AS1 (com
,%D0
) CR_TAB
3662 return *len
= 5, (AS2 (movw
,%A0
,%C1
) CR_TAB
3663 AS1 (clr
,%D0
) CR_TAB
3664 AS2 (sbrc
,%B0
,7) CR_TAB
3665 AS1 (com
,%D0
) CR_TAB
3668 return *len
= 6, (AS2 (mov
,%B0
,%D1
) CR_TAB
3669 AS2 (mov
,%A0
,%C1
) CR_TAB
3670 AS1 (clr
,%D0
) CR_TAB
3671 AS2 (sbrc
,%B0
,7) CR_TAB
3672 AS1 (com
,%D0
) CR_TAB
3677 return *len
= 6, (AS2 (mov
,%A0
,%D1
) CR_TAB
3678 AS1 (clr
,%D0
) CR_TAB
3679 AS2 (sbrc
,%A0
,7) CR_TAB
3680 AS1 (com
,%D0
) CR_TAB
3681 AS2 (mov
,%B0
,%D0
) CR_TAB
3685 if (INTVAL (operands
[2]) < 32)
3692 return *len
= 4, (AS1 (lsl
,%D0
) CR_TAB
3693 AS2 (sbc
,%A0
,%A0
) CR_TAB
3694 AS2 (mov
,%B0
,%A0
) CR_TAB
3695 AS2 (movw
,%C0
,%A0
));
3697 return *len
= 5, (AS1 (lsl
,%D0
) CR_TAB
3698 AS2 (sbc
,%A0
,%A0
) CR_TAB
3699 AS2 (mov
,%B0
,%A0
) CR_TAB
3700 AS2 (mov
,%C0
,%A0
) CR_TAB
3705 out_shift_with_cnt ((AS1 (asr
,%D0
) CR_TAB
3706 AS1 (ror
,%C0
) CR_TAB
3707 AS1 (ror
,%B0
) CR_TAB
3709 insn
, operands
, len
, 4);
3713 /* 8bit logic shift right ((unsigned char)x >> i) */
3716 lshrqi3_out (rtx insn
, rtx operands
[], int *len
)
3718 if (GET_CODE (operands
[2]) == CONST_INT
)
3725 switch (INTVAL (operands
[2]))
3728 if (INTVAL (operands
[2]) < 8)
3732 return AS1 (clr
,%0);
3736 return AS1 (lsr
,%0);
3740 return (AS1 (lsr
,%0) CR_TAB
3744 return (AS1 (lsr
,%0) CR_TAB
3749 if (test_hard_reg_class (LD_REGS
, operands
[0]))
3752 return (AS1 (swap
,%0) CR_TAB
3753 AS2 (andi
,%0,0x0f));
3756 return (AS1 (lsr
,%0) CR_TAB
3762 if (test_hard_reg_class (LD_REGS
, operands
[0]))
3765 return (AS1 (swap
,%0) CR_TAB
3770 return (AS1 (lsr
,%0) CR_TAB
3777 if (test_hard_reg_class (LD_REGS
, operands
[0]))
3780 return (AS1 (swap
,%0) CR_TAB
3786 return (AS1 (lsr
,%0) CR_TAB
3795 return (AS1 (rol
,%0) CR_TAB
3800 else if (CONSTANT_P (operands
[2]))
3801 fatal_insn ("internal compiler error. Incorrect shift:", insn
);
3803 out_shift_with_cnt (AS1 (lsr
,%0),
3804 insn
, operands
, len
, 1);
3808 /* 16bit logic shift right ((unsigned short)x >> i) */
3811 lshrhi3_out (rtx insn
, rtx operands
[], int *len
)
3813 if (GET_CODE (operands
[2]) == CONST_INT
)
3815 int scratch
= (GET_CODE (PATTERN (insn
)) == PARALLEL
);
3816 int ldi_ok
= test_hard_reg_class (LD_REGS
, operands
[0]);
3823 switch (INTVAL (operands
[2]))
3826 if (INTVAL (operands
[2]) < 16)
3830 return (AS1 (clr
,%B0
) CR_TAB
3834 if (optimize_size
&& scratch
)
3839 return (AS1 (swap
,%B0
) CR_TAB
3840 AS1 (swap
,%A0
) CR_TAB
3841 AS2 (andi
,%A0
,0x0f) CR_TAB
3842 AS2 (eor
,%A0
,%B0
) CR_TAB
3843 AS2 (andi
,%B0
,0x0f) CR_TAB
3849 return (AS1 (swap
,%B0
) CR_TAB
3850 AS1 (swap
,%A0
) CR_TAB
3851 AS2 (ldi
,%3,0x0f) CR_TAB
3853 AS2 (eor
,%A0
,%B0
) CR_TAB
3857 break; /* optimize_size ? 6 : 8 */
3861 break; /* scratch ? 5 : 6 */
3865 return (AS1 (lsr
,%B0
) CR_TAB
3866 AS1 (ror
,%A0
) CR_TAB
3867 AS1 (swap
,%B0
) CR_TAB
3868 AS1 (swap
,%A0
) CR_TAB
3869 AS2 (andi
,%A0
,0x0f) CR_TAB
3870 AS2 (eor
,%A0
,%B0
) CR_TAB
3871 AS2 (andi
,%B0
,0x0f) CR_TAB
3877 return (AS1 (lsr
,%B0
) CR_TAB
3878 AS1 (ror
,%A0
) CR_TAB
3879 AS1 (swap
,%B0
) CR_TAB
3880 AS1 (swap
,%A0
) CR_TAB
3881 AS2 (ldi
,%3,0x0f) CR_TAB
3883 AS2 (eor
,%A0
,%B0
) CR_TAB
3891 break; /* scratch ? 5 : 6 */
3893 return (AS1 (clr
,__tmp_reg__
) CR_TAB
3894 AS1 (lsl
,%A0
) CR_TAB
3895 AS1 (rol
,%B0
) CR_TAB
3896 AS1 (rol
,__tmp_reg__
) CR_TAB
3897 AS1 (lsl
,%A0
) CR_TAB
3898 AS1 (rol
,%B0
) CR_TAB
3899 AS1 (rol
,__tmp_reg__
) CR_TAB
3900 AS2 (mov
,%A0
,%B0
) CR_TAB
3901 AS2 (mov
,%B0
,__tmp_reg__
));
3905 return (AS1 (lsl
,%A0
) CR_TAB
3906 AS2 (mov
,%A0
,%B0
) CR_TAB
3907 AS1 (rol
,%A0
) CR_TAB
3908 AS2 (sbc
,%B0
,%B0
) CR_TAB
3912 return *len
= 2, (AS2 (mov
,%A0
,%B1
) CR_TAB
3917 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3918 AS1 (clr
,%B0
) CR_TAB
3923 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3924 AS1 (clr
,%B0
) CR_TAB
3925 AS1 (lsr
,%A0
) CR_TAB
3930 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3931 AS1 (clr
,%B0
) CR_TAB
3932 AS1 (lsr
,%A0
) CR_TAB
3933 AS1 (lsr
,%A0
) CR_TAB
3940 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3941 AS1 (clr
,%B0
) CR_TAB
3942 AS1 (swap
,%A0
) CR_TAB
3943 AS2 (andi
,%A0
,0x0f));
3948 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3949 AS1 (clr
,%B0
) CR_TAB
3950 AS1 (swap
,%A0
) CR_TAB
3951 AS2 (ldi
,%3,0x0f) CR_TAB
3955 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3956 AS1 (clr
,%B0
) CR_TAB
3957 AS1 (lsr
,%A0
) CR_TAB
3958 AS1 (lsr
,%A0
) CR_TAB
3959 AS1 (lsr
,%A0
) CR_TAB
3966 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3967 AS1 (clr
,%B0
) CR_TAB
3968 AS1 (swap
,%A0
) CR_TAB
3969 AS1 (lsr
,%A0
) CR_TAB
3970 AS2 (andi
,%A0
,0x07));
3972 if (AVR_HAVE_MUL
&& scratch
)
3975 return (AS2 (ldi
,%3,0x08) CR_TAB
3976 AS2 (mul
,%B0
,%3) CR_TAB
3977 AS2 (mov
,%A0
,r1
) CR_TAB
3978 AS1 (clr
,%B0
) CR_TAB
3979 AS1 (clr
,__zero_reg__
));
3981 if (optimize_size
&& scratch
)
3986 return (AS2 (mov
,%A0
,%B0
) CR_TAB
3987 AS1 (clr
,%B0
) CR_TAB
3988 AS1 (swap
,%A0
) CR_TAB
3989 AS1 (lsr
,%A0
) CR_TAB
3990 AS2 (ldi
,%3,0x07) CR_TAB
3996 return ("set" CR_TAB
3997 AS2 (bld
,r1
,3) CR_TAB
3998 AS2 (mul
,%B0
,r1
) CR_TAB
3999 AS2 (mov
,%A0
,r1
) CR_TAB
4000 AS1 (clr
,%B0
) CR_TAB
4001 AS1 (clr
,__zero_reg__
));
4004 return (AS2 (mov
,%A0
,%B0
) CR_TAB
4005 AS1 (clr
,%B0
) CR_TAB
4006 AS1 (lsr
,%A0
) CR_TAB
4007 AS1 (lsr
,%A0
) CR_TAB
4008 AS1 (lsr
,%A0
) CR_TAB
4009 AS1 (lsr
,%A0
) CR_TAB
4013 if (AVR_HAVE_MUL
&& ldi_ok
)
4016 return (AS2 (ldi
,%A0
,0x04) CR_TAB
4017 AS2 (mul
,%B0
,%A0
) CR_TAB
4018 AS2 (mov
,%A0
,r1
) CR_TAB
4019 AS1 (clr
,%B0
) CR_TAB
4020 AS1 (clr
,__zero_reg__
));
4022 if (AVR_HAVE_MUL
&& scratch
)
4025 return (AS2 (ldi
,%3,0x04) CR_TAB
4026 AS2 (mul
,%B0
,%3) CR_TAB
4027 AS2 (mov
,%A0
,r1
) CR_TAB
4028 AS1 (clr
,%B0
) CR_TAB
4029 AS1 (clr
,__zero_reg__
));
4031 if (optimize_size
&& ldi_ok
)
4034 return (AS2 (mov
,%A0
,%B0
) CR_TAB
4035 AS2 (ldi
,%B0
,6) "\n1:\t"
4036 AS1 (lsr
,%A0
) CR_TAB
4037 AS1 (dec
,%B0
) CR_TAB
4040 if (optimize_size
&& scratch
)
4043 return (AS1 (clr
,%A0
) CR_TAB
4044 AS1 (lsl
,%B0
) CR_TAB
4045 AS1 (rol
,%A0
) CR_TAB
4046 AS1 (lsl
,%B0
) CR_TAB
4047 AS1 (rol
,%A0
) CR_TAB
4052 return (AS1 (clr
,%A0
) CR_TAB
4053 AS1 (lsl
,%B0
) CR_TAB
4054 AS1 (rol
,%A0
) CR_TAB
4059 out_shift_with_cnt ((AS1 (lsr
,%B0
) CR_TAB
4061 insn
, operands
, len
, 2);
4065 /* 32bit logic shift right ((unsigned int)x >> i) */
4068 lshrsi3_out (rtx insn
, rtx operands
[], int *len
)
4070 if (GET_CODE (operands
[2]) == CONST_INT
)
4078 switch (INTVAL (operands
[2]))
4081 if (INTVAL (operands
[2]) < 32)
4085 return *len
= 3, (AS1 (clr
,%D0
) CR_TAB
4086 AS1 (clr
,%C0
) CR_TAB
4087 AS2 (movw
,%A0
,%C0
));
4089 return (AS1 (clr
,%D0
) CR_TAB
4090 AS1 (clr
,%C0
) CR_TAB
4091 AS1 (clr
,%B0
) CR_TAB
4096 int reg0
= true_regnum (operands
[0]);
4097 int reg1
= true_regnum (operands
[1]);
4100 return (AS2 (mov
,%A0
,%B1
) CR_TAB
4101 AS2 (mov
,%B0
,%C1
) CR_TAB
4102 AS2 (mov
,%C0
,%D1
) CR_TAB
4105 return (AS1 (clr
,%D0
) CR_TAB
4106 AS2 (mov
,%C0
,%D1
) CR_TAB
4107 AS2 (mov
,%B0
,%C1
) CR_TAB
4113 int reg0
= true_regnum (operands
[0]);
4114 int reg1
= true_regnum (operands
[1]);
4116 if (reg0
== reg1
+ 2)
4117 return *len
= 2, (AS1 (clr
,%C0
) CR_TAB
4120 return *len
= 3, (AS2 (movw
,%A0
,%C1
) CR_TAB
4121 AS1 (clr
,%C0
) CR_TAB
4124 return *len
= 4, (AS2 (mov
,%B0
,%D1
) CR_TAB
4125 AS2 (mov
,%A0
,%C1
) CR_TAB
4126 AS1 (clr
,%C0
) CR_TAB
4131 return *len
= 4, (AS2 (mov
,%A0
,%D1
) CR_TAB
4132 AS1 (clr
,%B0
) CR_TAB
4133 AS1 (clr
,%C0
) CR_TAB
4138 return (AS1 (clr
,%A0
) CR_TAB
4139 AS2 (sbrc
,%D0
,7) CR_TAB
4140 AS1 (inc
,%A0
) CR_TAB
4141 AS1 (clr
,%B0
) CR_TAB
4142 AS1 (clr
,%C0
) CR_TAB
4147 out_shift_with_cnt ((AS1 (lsr
,%D0
) CR_TAB
4148 AS1 (ror
,%C0
) CR_TAB
4149 AS1 (ror
,%B0
) CR_TAB
4151 insn
, operands
, len
, 4);
4155 /* Modifies the length assigned to instruction INSN
4156 LEN is the initially computed length of the insn. */
4159 adjust_insn_length (rtx insn
, int len
)
4161 rtx patt
= PATTERN (insn
);
4164 if (GET_CODE (patt
) == SET
)
4167 op
[1] = SET_SRC (patt
);
4168 op
[0] = SET_DEST (patt
);
4169 if (general_operand (op
[1], VOIDmode
)
4170 && general_operand (op
[0], VOIDmode
))
4172 switch (GET_MODE (op
[0]))
4175 output_movqi (insn
, op
, &len
);
4178 output_movhi (insn
, op
, &len
);
4182 output_movsisf (insn
, op
, &len
);
4188 else if (op
[0] == cc0_rtx
&& REG_P (op
[1]))
4190 switch (GET_MODE (op
[1]))
4192 case HImode
: out_tsthi (insn
, op
[1], &len
); break;
4193 case SImode
: out_tstsi (insn
, op
[1], &len
); break;
4197 else if (GET_CODE (op
[1]) == AND
)
4199 if (GET_CODE (XEXP (op
[1],1)) == CONST_INT
)
4201 HOST_WIDE_INT mask
= INTVAL (XEXP (op
[1],1));
4202 if (GET_MODE (op
[1]) == SImode
)
4203 len
= (((mask
& 0xff) != 0xff)
4204 + ((mask
& 0xff00) != 0xff00)
4205 + ((mask
& 0xff0000L
) != 0xff0000L
)
4206 + ((mask
& 0xff000000L
) != 0xff000000L
));
4207 else if (GET_MODE (op
[1]) == HImode
)
4208 len
= (((mask
& 0xff) != 0xff)
4209 + ((mask
& 0xff00) != 0xff00));
4212 else if (GET_CODE (op
[1]) == IOR
)
4214 if (GET_CODE (XEXP (op
[1],1)) == CONST_INT
)
4216 HOST_WIDE_INT mask
= INTVAL (XEXP (op
[1],1));
4217 if (GET_MODE (op
[1]) == SImode
)
4218 len
= (((mask
& 0xff) != 0)
4219 + ((mask
& 0xff00) != 0)
4220 + ((mask
& 0xff0000L
) != 0)
4221 + ((mask
& 0xff000000L
) != 0));
4222 else if (GET_MODE (op
[1]) == HImode
)
4223 len
= (((mask
& 0xff) != 0)
4224 + ((mask
& 0xff00) != 0));
4228 set
= single_set (insn
);
4233 op
[1] = SET_SRC (set
);
4234 op
[0] = SET_DEST (set
);
4236 if (GET_CODE (patt
) == PARALLEL
4237 && general_operand (op
[1], VOIDmode
)
4238 && general_operand (op
[0], VOIDmode
))
4240 if (XVECLEN (patt
, 0) == 2)
4241 op
[2] = XVECEXP (patt
, 0, 1);
4243 switch (GET_MODE (op
[0]))
4249 output_reload_inhi (insn
, op
, &len
);
4253 output_reload_insisf (insn
, op
, &len
);
4259 else if (GET_CODE (op
[1]) == ASHIFT
4260 || GET_CODE (op
[1]) == ASHIFTRT
4261 || GET_CODE (op
[1]) == LSHIFTRT
)
4265 ops
[1] = XEXP (op
[1],0);
4266 ops
[2] = XEXP (op
[1],1);
4267 switch (GET_CODE (op
[1]))
4270 switch (GET_MODE (op
[0]))
4272 case QImode
: ashlqi3_out (insn
,ops
,&len
); break;
4273 case HImode
: ashlhi3_out (insn
,ops
,&len
); break;
4274 case SImode
: ashlsi3_out (insn
,ops
,&len
); break;
4279 switch (GET_MODE (op
[0]))
4281 case QImode
: ashrqi3_out (insn
,ops
,&len
); break;
4282 case HImode
: ashrhi3_out (insn
,ops
,&len
); break;
4283 case SImode
: ashrsi3_out (insn
,ops
,&len
); break;
4288 switch (GET_MODE (op
[0]))
4290 case QImode
: lshrqi3_out (insn
,ops
,&len
); break;
4291 case HImode
: lshrhi3_out (insn
,ops
,&len
); break;
4292 case SImode
: lshrsi3_out (insn
,ops
,&len
); break;
4304 /* Return nonzero if register REG dead after INSN. */
4307 reg_unused_after (rtx insn
, rtx reg
)
4309 return (dead_or_set_p (insn
, reg
)
4310 || (REG_P(reg
) && _reg_unused_after (insn
, reg
)));
4313 /* Return nonzero if REG is not used after INSN.
4314 We assume REG is a reload reg, and therefore does
4315 not live past labels. It may live past calls or jumps though. */
4318 _reg_unused_after (rtx insn
, rtx reg
)
4323 /* If the reg is set by this instruction, then it is safe for our
4324 case. Disregard the case where this is a store to memory, since
4325 we are checking a register used in the store address. */
4326 set
= single_set (insn
);
4327 if (set
&& GET_CODE (SET_DEST (set
)) != MEM
4328 && reg_overlap_mentioned_p (reg
, SET_DEST (set
)))
4331 while ((insn
= NEXT_INSN (insn
)))
4334 code
= GET_CODE (insn
);
4337 /* If this is a label that existed before reload, then the register
4338 if dead here. However, if this is a label added by reorg, then
4339 the register may still be live here. We can't tell the difference,
4340 so we just ignore labels completely. */
4341 if (code
== CODE_LABEL
)
4349 if (code
== JUMP_INSN
)
4352 /* If this is a sequence, we must handle them all at once.
4353 We could have for instance a call that sets the target register,
4354 and an insn in a delay slot that uses the register. In this case,
4355 we must return 0. */
4356 else if (code
== INSN
&& GET_CODE (PATTERN (insn
)) == SEQUENCE
)
4361 for (i
= 0; i
< XVECLEN (PATTERN (insn
), 0); i
++)
4363 rtx this_insn
= XVECEXP (PATTERN (insn
), 0, i
);
4364 rtx set
= single_set (this_insn
);
4366 if (GET_CODE (this_insn
) == CALL_INSN
)
4368 else if (GET_CODE (this_insn
) == JUMP_INSN
)
4370 if (INSN_ANNULLED_BRANCH_P (this_insn
))
4375 if (set
&& reg_overlap_mentioned_p (reg
, SET_SRC (set
)))
4377 if (set
&& reg_overlap_mentioned_p (reg
, SET_DEST (set
)))
4379 if (GET_CODE (SET_DEST (set
)) != MEM
)
4385 && reg_overlap_mentioned_p (reg
, PATTERN (this_insn
)))
4390 else if (code
== JUMP_INSN
)
4394 if (code
== CALL_INSN
)
4397 for (tem
= CALL_INSN_FUNCTION_USAGE (insn
); tem
; tem
= XEXP (tem
, 1))
4398 if (GET_CODE (XEXP (tem
, 0)) == USE
4399 && REG_P (XEXP (XEXP (tem
, 0), 0))
4400 && reg_overlap_mentioned_p (reg
, XEXP (XEXP (tem
, 0), 0)))
4402 if (call_used_regs
[REGNO (reg
)])
4406 set
= single_set (insn
);
4408 if (set
&& reg_overlap_mentioned_p (reg
, SET_SRC (set
)))
4410 if (set
&& reg_overlap_mentioned_p (reg
, SET_DEST (set
)))
4411 return GET_CODE (SET_DEST (set
)) != MEM
;
4412 if (set
== 0 && reg_overlap_mentioned_p (reg
, PATTERN (insn
)))
4418 /* Target hook for assembling integer objects. The AVR version needs
4419 special handling for references to certain labels. */
4422 avr_assemble_integer (rtx x
, unsigned int size
, int aligned_p
)
4424 if (size
== POINTER_SIZE
/ BITS_PER_UNIT
&& aligned_p
4425 && ((GET_CODE (x
) == SYMBOL_REF
&& SYMBOL_REF_FUNCTION_P (x
))
4426 || GET_CODE (x
) == LABEL_REF
))
4428 fputs ("\t.word\tgs(", asm_out_file
);
4429 output_addr_const (asm_out_file
, x
);
4430 fputs (")\n", asm_out_file
);
4433 return default_assemble_integer (x
, size
, aligned_p
);
4436 /* Worker function for ASM_DECLARE_FUNCTION_NAME. */
4439 avr_asm_declare_function_name (FILE *file
, const char *name
, tree decl
)
4442 /* If the function has the 'signal' or 'interrupt' attribute, test to
4443 make sure that the name of the function is "__vector_NN" so as to
4444 catch when the user misspells the interrupt vector name. */
4446 if (cfun
->machine
->is_interrupt
)
4448 if (strncmp (name
, "__vector", strlen ("__vector")) != 0)
4450 warning_at (DECL_SOURCE_LOCATION (decl
), 0,
4451 "%qs appears to be a misspelled interrupt handler",
4455 else if (cfun
->machine
->is_signal
)
4457 if (strncmp (name
, "__vector", strlen ("__vector")) != 0)
4459 warning_at (DECL_SOURCE_LOCATION (decl
), 0,
4460 "%qs appears to be a misspelled signal handler",
4465 ASM_OUTPUT_TYPE_DIRECTIVE (file
, name
, "function");
4466 ASM_OUTPUT_LABEL (file
, name
);
4469 /* The routine used to output NUL terminated strings. We use a special
4470 version of this for most svr4 targets because doing so makes the
4471 generated assembly code more compact (and thus faster to assemble)
4472 as well as more readable, especially for targets like the i386
4473 (where the only alternative is to output character sequences as
4474 comma separated lists of numbers). */
4477 gas_output_limited_string(FILE *file
, const char *str
)
4479 const unsigned char *_limited_str
= (const unsigned char *) str
;
4481 fprintf (file
, "%s\"", STRING_ASM_OP
);
4482 for (; (ch
= *_limited_str
); _limited_str
++)
4485 switch (escape
= ESCAPES
[ch
])
4491 fprintf (file
, "\\%03o", ch
);
4495 putc (escape
, file
);
4499 fprintf (file
, "\"\n");
4502 /* The routine used to output sequences of byte values. We use a special
4503 version of this for most svr4 targets because doing so makes the
4504 generated assembly code more compact (and thus faster to assemble)
4505 as well as more readable. Note that if we find subparts of the
4506 character sequence which end with NUL (and which are shorter than
4507 STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING. */
4510 gas_output_ascii(FILE *file
, const char *str
, size_t length
)
4512 const unsigned char *_ascii_bytes
= (const unsigned char *) str
;
4513 const unsigned char *limit
= _ascii_bytes
+ length
;
4514 unsigned bytes_in_chunk
= 0;
4515 for (; _ascii_bytes
< limit
; _ascii_bytes
++)
4517 const unsigned char *p
;
4518 if (bytes_in_chunk
>= 60)
4520 fprintf (file
, "\"\n");
4523 for (p
= _ascii_bytes
; p
< limit
&& *p
!= '\0'; p
++)
4525 if (p
< limit
&& (p
- _ascii_bytes
) <= (signed)STRING_LIMIT
)
4527 if (bytes_in_chunk
> 0)
4529 fprintf (file
, "\"\n");
4532 gas_output_limited_string (file
, (const char*)_ascii_bytes
);
4539 if (bytes_in_chunk
== 0)
4540 fprintf (file
, "\t.ascii\t\"");
4541 switch (escape
= ESCAPES
[ch
= *_ascii_bytes
])
4548 fprintf (file
, "\\%03o", ch
);
4549 bytes_in_chunk
+= 4;
4553 putc (escape
, file
);
4554 bytes_in_chunk
+= 2;
4559 if (bytes_in_chunk
> 0)
4560 fprintf (file
, "\"\n");
4563 /* Return value is nonzero if pseudos that have been
4564 assigned to registers of class CLASS would likely be spilled
4565 because registers of CLASS are needed for spill registers. */
4568 class_likely_spilled_p (int c
)
4570 return (c
!= ALL_REGS
&& c
!= ADDW_REGS
);
4573 /* Valid attributes:
4574 progmem - put data to program memory;
4575 signal - make a function to be hardware interrupt. After function
4576 prologue interrupts are disabled;
4577 interrupt - make a function to be hardware interrupt. After function
4578 prologue interrupts are enabled;
4579 naked - don't generate function prologue/epilogue and `ret' command.
4581 Only `progmem' attribute valid for type. */
4583 /* Handle a "progmem" attribute; arguments as in
4584 struct attribute_spec.handler. */
4586 avr_handle_progmem_attribute (tree
*node
, tree name
,
4587 tree args ATTRIBUTE_UNUSED
,
4588 int flags ATTRIBUTE_UNUSED
,
4593 if (TREE_CODE (*node
) == TYPE_DECL
)
4595 /* This is really a decl attribute, not a type attribute,
4596 but try to handle it for GCC 3.0 backwards compatibility. */
4598 tree type
= TREE_TYPE (*node
);
4599 tree attr
= tree_cons (name
, args
, TYPE_ATTRIBUTES (type
));
4600 tree newtype
= build_type_attribute_variant (type
, attr
);
4602 TYPE_MAIN_VARIANT (newtype
) = TYPE_MAIN_VARIANT (type
);
4603 TREE_TYPE (*node
) = newtype
;
4604 *no_add_attrs
= true;
4606 else if (TREE_STATIC (*node
) || DECL_EXTERNAL (*node
))
4608 if (DECL_INITIAL (*node
) == NULL_TREE
&& !DECL_EXTERNAL (*node
))
4610 warning (0, "only initialized variables can be placed into "
4611 "program memory area");
4612 *no_add_attrs
= true;
4617 warning (OPT_Wattributes
, "%qE attribute ignored",
4619 *no_add_attrs
= true;
4626 /* Handle an attribute requiring a FUNCTION_DECL; arguments as in
4627 struct attribute_spec.handler. */
4630 avr_handle_fndecl_attribute (tree
*node
, tree name
,
4631 tree args ATTRIBUTE_UNUSED
,
4632 int flags ATTRIBUTE_UNUSED
,
4635 if (TREE_CODE (*node
) != FUNCTION_DECL
)
4637 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
4639 *no_add_attrs
= true;
4646 avr_handle_fntype_attribute (tree
*node
, tree name
,
4647 tree args ATTRIBUTE_UNUSED
,
4648 int flags ATTRIBUTE_UNUSED
,
4651 if (TREE_CODE (*node
) != FUNCTION_TYPE
)
4653 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
4655 *no_add_attrs
= true;
4661 /* Look for attribute `progmem' in DECL
4662 if found return 1, otherwise 0. */
4665 avr_progmem_p (tree decl
, tree attributes
)
4669 if (TREE_CODE (decl
) != VAR_DECL
)
4673 != lookup_attribute ("progmem", attributes
))
4679 while (TREE_CODE (a
) == ARRAY_TYPE
);
4681 if (a
== error_mark_node
)
4684 if (NULL_TREE
!= lookup_attribute ("progmem", TYPE_ATTRIBUTES (a
)))
4690 /* Add the section attribute if the variable is in progmem. */
4693 avr_insert_attributes (tree node
, tree
*attributes
)
4695 if (TREE_CODE (node
) == VAR_DECL
4696 && (TREE_STATIC (node
) || DECL_EXTERNAL (node
))
4697 && avr_progmem_p (node
, *attributes
))
4699 static const char dsec
[] = ".progmem.data";
4700 *attributes
= tree_cons (get_identifier ("section"),
4701 build_tree_list (NULL
, build_string (strlen (dsec
), dsec
)),
4704 /* ??? This seems sketchy. Why can't the user declare the
4705 thing const in the first place? */
4706 TREE_READONLY (node
) = 1;
4710 /* A get_unnamed_section callback for switching to progmem_section. */
4713 avr_output_progmem_section_asm_op (const void *arg ATTRIBUTE_UNUSED
)
4715 fprintf (asm_out_file
,
4716 "\t.section .progmem.gcc_sw_table, \"%s\", @progbits\n",
4717 AVR_HAVE_JMP_CALL
? "a" : "ax");
4718 /* Should already be aligned, this is just to be safe if it isn't. */
4719 fprintf (asm_out_file
, "\t.p2align 1\n");
4722 /* Implement TARGET_ASM_INIT_SECTIONS. */
4725 avr_asm_init_sections (void)
4727 progmem_section
= get_unnamed_section (AVR_HAVE_JMP_CALL
? 0 : SECTION_CODE
,
4728 avr_output_progmem_section_asm_op
,
4730 readonly_data_section
= data_section
;
4734 avr_section_type_flags (tree decl
, const char *name
, int reloc
)
4736 unsigned int flags
= default_section_type_flags (decl
, name
, reloc
);
4738 if (strncmp (name
, ".noinit", 7) == 0)
4740 if (decl
&& TREE_CODE (decl
) == VAR_DECL
4741 && DECL_INITIAL (decl
) == NULL_TREE
)
4742 flags
|= SECTION_BSS
; /* @nobits */
4744 warning (0, "only uninitialized variables can be placed in the "
4751 /* Outputs some appropriate text to go at the start of an assembler
4755 avr_file_start (void)
4757 if (avr_current_arch
->asm_only
)
4758 error ("MCU %qs supported for assembler only", avr_mcu_name
);
4760 default_file_start ();
4762 /* fprintf (asm_out_file, "\t.arch %s\n", avr_mcu_name);*/
4763 fputs ("__SREG__ = 0x3f\n"
4765 "__SP_L__ = 0x3d\n", asm_out_file
);
4767 fputs ("__tmp_reg__ = 0\n"
4768 "__zero_reg__ = 1\n", asm_out_file
);
4770 /* FIXME: output these only if there is anything in the .data / .bss
4771 sections - some code size could be saved by not linking in the
4772 initialization code from libgcc if one or both sections are empty. */
4773 fputs ("\t.global __do_copy_data\n", asm_out_file
);
4774 fputs ("\t.global __do_clear_bss\n", asm_out_file
);
4777 /* Outputs to the stdio stream FILE some
4778 appropriate text to go at the end of an assembler file. */
4785 /* Choose the order in which to allocate hard registers for
4786 pseudo-registers local to a basic block.
4788 Store the desired register order in the array `reg_alloc_order'.
4789 Element 0 should be the register to allocate first; element 1, the
4790 next register; and so on. */
4793 order_regs_for_local_alloc (void)
4796 static const int order_0
[] = {
4804 17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,
4808 static const int order_1
[] = {
4816 17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,
4820 static const int order_2
[] = {
4829 15,14,13,12,11,10,9,8,7,6,5,4,3,2,
4834 const int *order
= (TARGET_ORDER_1
? order_1
:
4835 TARGET_ORDER_2
? order_2
:
4837 for (i
=0; i
< ARRAY_SIZE (order_0
); ++i
)
4838 reg_alloc_order
[i
] = order
[i
];
4842 /* Mutually recursive subroutine of avr_rtx_cost for calculating the
4843 cost of an RTX operand given its context. X is the rtx of the
4844 operand, MODE is its mode, and OUTER is the rtx_code of this
4845 operand's parent operator. */
4848 avr_operand_rtx_cost (rtx x
, enum machine_mode mode
, enum rtx_code outer
,
4851 enum rtx_code code
= GET_CODE (x
);
4862 return COSTS_N_INSNS (GET_MODE_SIZE (mode
));
4869 avr_rtx_costs (x
, code
, outer
, &total
, speed
);
4873 /* The AVR backend's rtx_cost function. X is rtx expression whose cost
4874 is to be calculated. Return true if the complete cost has been
4875 computed, and false if subexpressions should be scanned. In either
4876 case, *TOTAL contains the cost result. */
4879 avr_rtx_costs (rtx x
, int codearg
, int outer_code ATTRIBUTE_UNUSED
, int *total
,
4882 enum rtx_code code
= (enum rtx_code
) codearg
;
4883 enum machine_mode mode
= GET_MODE (x
);
4890 /* Immediate constants are as cheap as registers. */
4898 *total
= COSTS_N_INSNS (GET_MODE_SIZE (mode
));
4906 *total
= COSTS_N_INSNS (1);
4910 *total
= COSTS_N_INSNS (3);
4914 *total
= COSTS_N_INSNS (7);
4920 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
4928 *total
= COSTS_N_INSNS (1);
4934 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
4938 *total
= COSTS_N_INSNS (GET_MODE_SIZE (mode
));
4939 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
4943 *total
= COSTS_N_INSNS (GET_MODE_SIZE (mode
)
4944 - GET_MODE_SIZE (GET_MODE (XEXP (x
, 0))));
4945 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
4949 *total
= COSTS_N_INSNS (GET_MODE_SIZE (mode
) + 2
4950 - GET_MODE_SIZE (GET_MODE (XEXP (x
, 0))));
4951 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
4958 *total
= COSTS_N_INSNS (1);
4959 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
4960 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
4964 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
4966 *total
= COSTS_N_INSNS (2);
4967 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
4969 else if (INTVAL (XEXP (x
, 1)) >= -63 && INTVAL (XEXP (x
, 1)) <= 63)
4970 *total
= COSTS_N_INSNS (1);
4972 *total
= COSTS_N_INSNS (2);
4976 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
4978 *total
= COSTS_N_INSNS (4);
4979 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
4981 else if (INTVAL (XEXP (x
, 1)) >= -63 && INTVAL (XEXP (x
, 1)) <= 63)
4982 *total
= COSTS_N_INSNS (1);
4984 *total
= COSTS_N_INSNS (4);
4990 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
4996 *total
= COSTS_N_INSNS (GET_MODE_SIZE (mode
));
4997 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
4998 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
4999 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5003 *total
= COSTS_N_INSNS (GET_MODE_SIZE (mode
));
5004 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
5005 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5013 *total
= COSTS_N_INSNS (!speed
? 3 : 4);
5015 *total
= COSTS_N_INSNS (AVR_HAVE_JMP_CALL
? 2 : 1);
5022 *total
= COSTS_N_INSNS (!speed
? 7 : 10);
5024 *total
= COSTS_N_INSNS (AVR_HAVE_JMP_CALL
? 2 : 1);
5032 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
5033 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5041 *total
= COSTS_N_INSNS (AVR_HAVE_JMP_CALL
? 2 : 1);
5044 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
5045 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5052 if (CONST_INT_P (XEXP (x
, 1)) && INTVAL (XEXP (x
, 1)) == 4)
5053 *total
= COSTS_N_INSNS (1);
5058 if (CONST_INT_P (XEXP (x
, 1)) && INTVAL (XEXP (x
, 1)) == 8)
5059 *total
= COSTS_N_INSNS (3);
5064 if (CONST_INT_P (XEXP (x
, 1)))
5065 switch (INTVAL (XEXP (x
, 1)))
5069 *total
= COSTS_N_INSNS (5);
5072 *total
= COSTS_N_INSNS (AVR_HAVE_MOVW
? 4 : 6);
5080 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
5087 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5089 *total
= COSTS_N_INSNS (!speed
? 4 : 17);
5090 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5094 val
= INTVAL (XEXP (x
, 1));
5096 *total
= COSTS_N_INSNS (3);
5097 else if (val
>= 0 && val
<= 7)
5098 *total
= COSTS_N_INSNS (val
);
5100 *total
= COSTS_N_INSNS (1);
5105 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5107 *total
= COSTS_N_INSNS (!speed
? 5 : 41);
5108 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5111 switch (INTVAL (XEXP (x
, 1)))
5118 *total
= COSTS_N_INSNS (2);
5121 *total
= COSTS_N_INSNS (3);
5127 *total
= COSTS_N_INSNS (4);
5132 *total
= COSTS_N_INSNS (5);
5135 *total
= COSTS_N_INSNS (!speed
? 5 : 8);
5138 *total
= COSTS_N_INSNS (!speed
? 5 : 9);
5141 *total
= COSTS_N_INSNS (!speed
? 5 : 10);
5144 *total
= COSTS_N_INSNS (!speed
? 5 : 41);
5145 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5150 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5152 *total
= COSTS_N_INSNS (!speed
? 7 : 113);
5153 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5156 switch (INTVAL (XEXP (x
, 1)))
5162 *total
= COSTS_N_INSNS (3);
5167 *total
= COSTS_N_INSNS (4);
5170 *total
= COSTS_N_INSNS (6);
5173 *total
= COSTS_N_INSNS (!speed
? 7 : 8);
5176 *total
= COSTS_N_INSNS (!speed
? 7 : 113);
5177 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5184 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
5191 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5193 *total
= COSTS_N_INSNS (!speed
? 4 : 17);
5194 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5198 val
= INTVAL (XEXP (x
, 1));
5200 *total
= COSTS_N_INSNS (4);
5202 *total
= COSTS_N_INSNS (2);
5203 else if (val
>= 0 && val
<= 7)
5204 *total
= COSTS_N_INSNS (val
);
5206 *total
= COSTS_N_INSNS (1);
5211 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5213 *total
= COSTS_N_INSNS (!speed
? 5 : 41);
5214 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5217 switch (INTVAL (XEXP (x
, 1)))
5223 *total
= COSTS_N_INSNS (2);
5226 *total
= COSTS_N_INSNS (3);
5232 *total
= COSTS_N_INSNS (4);
5236 *total
= COSTS_N_INSNS (5);
5239 *total
= COSTS_N_INSNS (!speed
? 5 : 6);
5242 *total
= COSTS_N_INSNS (!speed
? 5 : 7);
5246 *total
= COSTS_N_INSNS (!speed
? 5 : 8);
5249 *total
= COSTS_N_INSNS (!speed
? 5 : 41);
5250 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5255 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5257 *total
= COSTS_N_INSNS (!speed
? 7 : 113);
5258 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5261 switch (INTVAL (XEXP (x
, 1)))
5267 *total
= COSTS_N_INSNS (4);
5272 *total
= COSTS_N_INSNS (6);
5275 *total
= COSTS_N_INSNS (!speed
? 7 : 8);
5278 *total
= COSTS_N_INSNS (AVR_HAVE_MOVW
? 4 : 5);
5281 *total
= COSTS_N_INSNS (!speed
? 7 : 113);
5282 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5289 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
5296 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5298 *total
= COSTS_N_INSNS (!speed
? 4 : 17);
5299 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5303 val
= INTVAL (XEXP (x
, 1));
5305 *total
= COSTS_N_INSNS (3);
5306 else if (val
>= 0 && val
<= 7)
5307 *total
= COSTS_N_INSNS (val
);
5309 *total
= COSTS_N_INSNS (1);
5314 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5316 *total
= COSTS_N_INSNS (!speed
? 5 : 41);
5317 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5320 switch (INTVAL (XEXP (x
, 1)))
5327 *total
= COSTS_N_INSNS (2);
5330 *total
= COSTS_N_INSNS (3);
5335 *total
= COSTS_N_INSNS (4);
5339 *total
= COSTS_N_INSNS (5);
5345 *total
= COSTS_N_INSNS (!speed
? 5 : 6);
5348 *total
= COSTS_N_INSNS (!speed
? 5 : 7);
5352 *total
= COSTS_N_INSNS (!speed
? 5 : 9);
5355 *total
= COSTS_N_INSNS (!speed
? 5 : 41);
5356 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5361 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5363 *total
= COSTS_N_INSNS (!speed
? 7 : 113);
5364 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5367 switch (INTVAL (XEXP (x
, 1)))
5373 *total
= COSTS_N_INSNS (4);
5376 *total
= COSTS_N_INSNS (!speed
? 7 : 8);
5381 *total
= COSTS_N_INSNS (4);
5384 *total
= COSTS_N_INSNS (6);
5387 *total
= COSTS_N_INSNS (!speed
? 7 : 113);
5388 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5395 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
5399 switch (GET_MODE (XEXP (x
, 0)))
5402 *total
= COSTS_N_INSNS (1);
5403 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5404 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5408 *total
= COSTS_N_INSNS (2);
5409 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5410 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5411 else if (INTVAL (XEXP (x
, 1)) != 0)
5412 *total
+= COSTS_N_INSNS (1);
5416 *total
= COSTS_N_INSNS (4);
5417 if (GET_CODE (XEXP (x
, 1)) != CONST_INT
)
5418 *total
+= avr_operand_rtx_cost (XEXP (x
, 1), mode
, code
, speed
);
5419 else if (INTVAL (XEXP (x
, 1)) != 0)
5420 *total
+= COSTS_N_INSNS (3);
5426 *total
+= avr_operand_rtx_cost (XEXP (x
, 0), mode
, code
, speed
);
5435 /* Calculate the cost of a memory address. */
5438 avr_address_cost (rtx x
, bool speed ATTRIBUTE_UNUSED
)
5440 if (GET_CODE (x
) == PLUS
5441 && GET_CODE (XEXP (x
,1)) == CONST_INT
5442 && (REG_P (XEXP (x
,0)) || GET_CODE (XEXP (x
,0)) == SUBREG
)
5443 && INTVAL (XEXP (x
,1)) >= 61)
5445 if (CONSTANT_ADDRESS_P (x
))
5447 if (optimize
> 0 && io_address_operand (x
, QImode
))
5454 /* Test for extra memory constraint 'Q'.
5455 It's a memory address based on Y or Z pointer with valid displacement. */
5458 extra_constraint_Q (rtx x
)
5460 if (GET_CODE (XEXP (x
,0)) == PLUS
5461 && REG_P (XEXP (XEXP (x
,0), 0))
5462 && GET_CODE (XEXP (XEXP (x
,0), 1)) == CONST_INT
5463 && (INTVAL (XEXP (XEXP (x
,0), 1))
5464 <= MAX_LD_OFFSET (GET_MODE (x
))))
5466 rtx xx
= XEXP (XEXP (x
,0), 0);
5467 int regno
= REGNO (xx
);
5468 if (TARGET_ALL_DEBUG
)
5470 fprintf (stderr
, ("extra_constraint:\n"
5471 "reload_completed: %d\n"
5472 "reload_in_progress: %d\n"),
5473 reload_completed
, reload_in_progress
);
5476 if (regno
>= FIRST_PSEUDO_REGISTER
)
5477 return 1; /* allocate pseudos */
5478 else if (regno
== REG_Z
|| regno
== REG_Y
)
5479 return 1; /* strictly check */
5480 else if (xx
== frame_pointer_rtx
5481 || xx
== arg_pointer_rtx
)
5482 return 1; /* XXX frame & arg pointer checks */
5487 /* Convert condition code CONDITION to the valid AVR condition code. */
5490 avr_normalize_condition (RTX_CODE condition
)
5507 /* This function optimizes conditional jumps. */
5514 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5516 if (! (GET_CODE (insn
) == INSN
5517 || GET_CODE (insn
) == CALL_INSN
5518 || GET_CODE (insn
) == JUMP_INSN
)
5519 || !single_set (insn
))
5522 pattern
= PATTERN (insn
);
5524 if (GET_CODE (pattern
) == PARALLEL
)
5525 pattern
= XVECEXP (pattern
, 0, 0);
5526 if (GET_CODE (pattern
) == SET
5527 && SET_DEST (pattern
) == cc0_rtx
5528 && compare_diff_p (insn
))
5530 if (GET_CODE (SET_SRC (pattern
)) == COMPARE
)
5532 /* Now we work under compare insn. */
5534 pattern
= SET_SRC (pattern
);
5535 if (true_regnum (XEXP (pattern
,0)) >= 0
5536 && true_regnum (XEXP (pattern
,1)) >= 0 )
5538 rtx x
= XEXP (pattern
,0);
5539 rtx next
= next_real_insn (insn
);
5540 rtx pat
= PATTERN (next
);
5541 rtx src
= SET_SRC (pat
);
5542 rtx t
= XEXP (src
,0);
5543 PUT_CODE (t
, swap_condition (GET_CODE (t
)));
5544 XEXP (pattern
,0) = XEXP (pattern
,1);
5545 XEXP (pattern
,1) = x
;
5546 INSN_CODE (next
) = -1;
5548 else if (true_regnum (XEXP (pattern
, 0)) >= 0
5549 && XEXP (pattern
, 1) == const0_rtx
)
5551 /* This is a tst insn, we can reverse it. */
5552 rtx next
= next_real_insn (insn
);
5553 rtx pat
= PATTERN (next
);
5554 rtx src
= SET_SRC (pat
);
5555 rtx t
= XEXP (src
,0);
5557 PUT_CODE (t
, swap_condition (GET_CODE (t
)));
5558 XEXP (pattern
, 1) = XEXP (pattern
, 0);
5559 XEXP (pattern
, 0) = const0_rtx
;
5560 INSN_CODE (next
) = -1;
5561 INSN_CODE (insn
) = -1;
5563 else if (true_regnum (XEXP (pattern
,0)) >= 0
5564 && GET_CODE (XEXP (pattern
,1)) == CONST_INT
)
5566 rtx x
= XEXP (pattern
,1);
5567 rtx next
= next_real_insn (insn
);
5568 rtx pat
= PATTERN (next
);
5569 rtx src
= SET_SRC (pat
);
5570 rtx t
= XEXP (src
,0);
5571 enum machine_mode mode
= GET_MODE (XEXP (pattern
, 0));
5573 if (avr_simplify_comparison_p (mode
, GET_CODE (t
), x
))
5575 XEXP (pattern
, 1) = gen_int_mode (INTVAL (x
) + 1, mode
);
5576 PUT_CODE (t
, avr_normalize_condition (GET_CODE (t
)));
5577 INSN_CODE (next
) = -1;
5578 INSN_CODE (insn
) = -1;
5586 /* Returns register number for function return value.*/
5589 avr_ret_register (void)
5594 /* Create an RTX representing the place where a
5595 library function returns a value of mode MODE. */
5598 avr_libcall_value (enum machine_mode mode
)
5600 int offs
= GET_MODE_SIZE (mode
);
5603 return gen_rtx_REG (mode
, RET_REGISTER
+ 2 - offs
);
5606 /* Create an RTX representing the place where a
5607 function returns a value of data type VALTYPE. */
5610 avr_function_value (const_tree type
,
5611 const_tree func ATTRIBUTE_UNUSED
,
5612 bool outgoing ATTRIBUTE_UNUSED
)
5616 if (TYPE_MODE (type
) != BLKmode
)
5617 return avr_libcall_value (TYPE_MODE (type
));
5619 offs
= int_size_in_bytes (type
);
5622 if (offs
> 2 && offs
< GET_MODE_SIZE (SImode
))
5623 offs
= GET_MODE_SIZE (SImode
);
5624 else if (offs
> GET_MODE_SIZE (SImode
) && offs
< GET_MODE_SIZE (DImode
))
5625 offs
= GET_MODE_SIZE (DImode
);
5627 return gen_rtx_REG (BLKmode
, RET_REGISTER
+ 2 - offs
);
5630 /* Places additional restrictions on the register class to
5631 use when it is necessary to copy value X into a register
5635 preferred_reload_class (rtx x ATTRIBUTE_UNUSED
, enum reg_class rclass
)
5641 test_hard_reg_class (enum reg_class rclass
, rtx x
)
5643 int regno
= true_regnum (x
);
5647 if (TEST_HARD_REG_CLASS (rclass
, regno
))
5655 jump_over_one_insn_p (rtx insn
, rtx dest
)
5657 int uid
= INSN_UID (GET_CODE (dest
) == LABEL_REF
5660 int jump_addr
= INSN_ADDRESSES (INSN_UID (insn
));
5661 int dest_addr
= INSN_ADDRESSES (uid
);
5662 return dest_addr
- jump_addr
== get_attr_length (insn
) + 1;
5665 /* Returns 1 if a value of mode MODE can be stored starting with hard
5666 register number REGNO. On the enhanced core, anything larger than
5667 1 byte must start in even numbered register for "movw" to work
5668 (this way we don't have to check for odd registers everywhere). */
5671 avr_hard_regno_mode_ok (int regno
, enum machine_mode mode
)
5673 /* Disallow QImode in stack pointer regs. */
5674 if ((regno
== REG_SP
|| regno
== (REG_SP
+ 1)) && mode
== QImode
)
5677 /* The only thing that can go into registers r28:r29 is a Pmode. */
5678 if (regno
== REG_Y
&& mode
== Pmode
)
5681 /* Otherwise disallow all regno/mode combinations that span r28:r29. */
5682 if (regno
<= (REG_Y
+ 1) && (regno
+ GET_MODE_SIZE (mode
)) >= (REG_Y
+ 1))
5688 /* Modes larger than QImode occupy consecutive registers. */
5689 if (regno
+ GET_MODE_SIZE (mode
) > FIRST_PSEUDO_REGISTER
)
5692 /* All modes larger than QImode should start in an even register. */
5693 return !(regno
& 1);
5697 output_reload_inhi (rtx insn ATTRIBUTE_UNUSED
, rtx
*operands
, int *len
)
5703 if (GET_CODE (operands
[1]) == CONST_INT
)
5705 int val
= INTVAL (operands
[1]);
5706 if ((val
& 0xff) == 0)
5709 return (AS2 (mov
,%A0
,__zero_reg__
) CR_TAB
5710 AS2 (ldi
,%2,hi8(%1)) CR_TAB
5713 else if ((val
& 0xff00) == 0)
5716 return (AS2 (ldi
,%2,lo8(%1)) CR_TAB
5717 AS2 (mov
,%A0
,%2) CR_TAB
5718 AS2 (mov
,%B0
,__zero_reg__
));
5720 else if ((val
& 0xff) == ((val
& 0xff00) >> 8))
5723 return (AS2 (ldi
,%2,lo8(%1)) CR_TAB
5724 AS2 (mov
,%A0
,%2) CR_TAB
5729 return (AS2 (ldi
,%2,lo8(%1)) CR_TAB
5730 AS2 (mov
,%A0
,%2) CR_TAB
5731 AS2 (ldi
,%2,hi8(%1)) CR_TAB
5737 output_reload_insisf (rtx insn ATTRIBUTE_UNUSED
, rtx
*operands
, int *len
)
5739 rtx src
= operands
[1];
5740 int cnst
= (GET_CODE (src
) == CONST_INT
);
5745 *len
= 4 + ((INTVAL (src
) & 0xff) != 0)
5746 + ((INTVAL (src
) & 0xff00) != 0)
5747 + ((INTVAL (src
) & 0xff0000) != 0)
5748 + ((INTVAL (src
) & 0xff000000) != 0);
5755 if (cnst
&& ((INTVAL (src
) & 0xff) == 0))
5756 output_asm_insn (AS2 (mov
, %A0
, __zero_reg__
), operands
);
5759 output_asm_insn (AS2 (ldi
, %2, lo8(%1)), operands
);
5760 output_asm_insn (AS2 (mov
, %A0
, %2), operands
);
5762 if (cnst
&& ((INTVAL (src
) & 0xff00) == 0))
5763 output_asm_insn (AS2 (mov
, %B0
, __zero_reg__
), operands
);
5766 output_asm_insn (AS2 (ldi
, %2, hi8(%1)), operands
);
5767 output_asm_insn (AS2 (mov
, %B0
, %2), operands
);
5769 if (cnst
&& ((INTVAL (src
) & 0xff0000) == 0))
5770 output_asm_insn (AS2 (mov
, %C0
, __zero_reg__
), operands
);
5773 output_asm_insn (AS2 (ldi
, %2, hlo8(%1)), operands
);
5774 output_asm_insn (AS2 (mov
, %C0
, %2), operands
);
5776 if (cnst
&& ((INTVAL (src
) & 0xff000000) == 0))
5777 output_asm_insn (AS2 (mov
, %D0
, __zero_reg__
), operands
);
5780 output_asm_insn (AS2 (ldi
, %2, hhi8(%1)), operands
);
5781 output_asm_insn (AS2 (mov
, %D0
, %2), operands
);
5787 avr_output_bld (rtx operands
[], int bit_nr
)
5789 static char s
[] = "bld %A0,0";
5791 s
[5] = 'A' + (bit_nr
>> 3);
5792 s
[8] = '0' + (bit_nr
& 7);
5793 output_asm_insn (s
, operands
);
5797 avr_output_addr_vec_elt (FILE *stream
, int value
)
5799 switch_to_section (progmem_section
);
5800 if (AVR_HAVE_JMP_CALL
)
5801 fprintf (stream
, "\t.word gs(.L%d)\n", value
);
5803 fprintf (stream
, "\trjmp .L%d\n", value
);
5806 /* Returns true if SCRATCH are safe to be allocated as a scratch
5807 registers (for a define_peephole2) in the current function. */
5810 avr_hard_regno_scratch_ok (unsigned int regno
)
5812 /* Interrupt functions can only use registers that have already been saved
5813 by the prologue, even if they would normally be call-clobbered. */
5815 if ((cfun
->machine
->is_interrupt
|| cfun
->machine
->is_signal
)
5816 && !df_regs_ever_live_p (regno
))
5822 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
5825 avr_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED
,
5826 unsigned int new_reg
)
5828 /* Interrupt functions can only use registers that have already been
5829 saved by the prologue, even if they would normally be
5832 if ((cfun
->machine
->is_interrupt
|| cfun
->machine
->is_signal
)
5833 && !df_regs_ever_live_p (new_reg
))
5839 /* Output a branch that tests a single bit of a register (QI, HI or SImode)
5840 or memory location in the I/O space (QImode only).
5842 Operand 0: comparison operator (must be EQ or NE, compare bit to zero).
5843 Operand 1: register operand to test, or CONST_INT memory address.
5844 Operand 2: bit number (for QImode operand) or mask (HImode, SImode).
5845 Operand 3: label to jump to if the test is true. */
5848 avr_out_sbxx_branch (rtx insn
, rtx operands
[])
5850 enum rtx_code comp
= GET_CODE (operands
[0]);
5851 int long_jump
= (get_attr_length (insn
) >= 4);
5852 int reverse
= long_jump
|| jump_over_one_insn_p (insn
, operands
[3]);
5856 else if (comp
== LT
)
5860 comp
= reverse_condition (comp
);
5862 if (GET_CODE (operands
[1]) == CONST_INT
)
5864 if (INTVAL (operands
[1]) < 0x40)
5867 output_asm_insn (AS2 (sbis
,%1-0x20,%2), operands
);
5869 output_asm_insn (AS2 (sbic
,%1-0x20,%2), operands
);
5873 output_asm_insn (AS2 (in
,__tmp_reg__
,%1-0x20), operands
);
5875 output_asm_insn (AS2 (sbrs
,__tmp_reg__
,%2), operands
);
5877 output_asm_insn (AS2 (sbrc
,__tmp_reg__
,%2), operands
);
5880 else /* GET_CODE (operands[1]) == REG */
5882 if (GET_MODE (operands
[1]) == QImode
)
5885 output_asm_insn (AS2 (sbrs
,%1,%2), operands
);
5887 output_asm_insn (AS2 (sbrc
,%1,%2), operands
);
5889 else /* HImode or SImode */
5891 static char buf
[] = "sbrc %A1,0";
5892 int bit_nr
= exact_log2 (INTVAL (operands
[2])
5893 & GET_MODE_MASK (GET_MODE (operands
[1])));
5895 buf
[3] = (comp
== EQ
) ? 's' : 'c';
5896 buf
[6] = 'A' + (bit_nr
>> 3);
5897 buf
[9] = '0' + (bit_nr
& 7);
5898 output_asm_insn (buf
, operands
);
5903 return (AS1 (rjmp
,.+4) CR_TAB
5906 return AS1 (rjmp
,%3);
5910 /* Worker function for TARGET_ASM_CONSTRUCTOR. */
5913 avr_asm_out_ctor (rtx symbol
, int priority
)
5915 fputs ("\t.global __do_global_ctors\n", asm_out_file
);
5916 default_ctor_section_asm_out_constructor (symbol
, priority
);
5919 /* Worker function for TARGET_ASM_DESTRUCTOR. */
5922 avr_asm_out_dtor (rtx symbol
, int priority
)
5924 fputs ("\t.global __do_global_dtors\n", asm_out_file
);
5925 default_dtor_section_asm_out_destructor (symbol
, priority
);
5928 /* Worker function for TARGET_RETURN_IN_MEMORY. */
5931 avr_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
5933 if (TYPE_MODE (type
) == BLKmode
)
5935 HOST_WIDE_INT size
= int_size_in_bytes (type
);
5936 return (size
== -1 || size
> 8);
5942 /* Worker function for CASE_VALUES_THRESHOLD. */
5944 unsigned int avr_case_values_threshold (void)
5946 return (!AVR_HAVE_JMP_CALL
|| TARGET_CALL_PROLOGUES
) ? 8 : 17;