1 /* Subroutines for insn-output.c for Renesas H8/300.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Steve Chamberlain (sac@cygnus.com),
6 Jim Wilson (wilson@cygnus.com), and Doug Evans (dje@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
31 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
35 #include "insn-attr.h"
41 #include "diagnostic-core.h"
43 #include "c-family/c-pragma.h" /* ??? */
47 #include "target-def.h"
49 /* Classifies a h8300_src_operand or h8300_dst_operand.
52 A constant operand of some sort.
58 A memory reference with a constant address.
61 A memory reference with a register as its address.
64 Some other kind of memory reference. */
65 enum h8300_operand_class
75 /* For a general two-operand instruction, element [X][Y] gives
76 the length of the opcode fields when the first operand has class
77 (X + 1) and the second has class Y. */
78 typedef unsigned char h8300_length_table
[NUM_H8OPS
- 1][NUM_H8OPS
];
80 /* Forward declarations. */
81 static const char *byte_reg (rtx
, int);
82 static int h8300_interrupt_function_p (tree
);
83 static int h8300_saveall_function_p (tree
);
84 static int h8300_monitor_function_p (tree
);
85 static int h8300_os_task_function_p (tree
);
86 static void h8300_emit_stack_adjustment (int, HOST_WIDE_INT
, bool);
87 static HOST_WIDE_INT
round_frame_size (HOST_WIDE_INT
);
88 static unsigned int compute_saved_regs (void);
89 static void push (int);
90 static void pop (int);
91 static const char *cond_string (enum rtx_code
);
92 static unsigned int h8300_asm_insn_count (const char *);
93 static tree
h8300_handle_fndecl_attribute (tree
*, tree
, tree
, int, bool *);
94 static tree
h8300_handle_eightbit_data_attribute (tree
*, tree
, tree
, int, bool *);
95 static tree
h8300_handle_tiny_data_attribute (tree
*, tree
, tree
, int, bool *);
96 #ifndef OBJECT_FORMAT_ELF
97 static void h8300_asm_named_section (const char *, unsigned int, tree
);
99 static int h8300_and_costs (rtx
);
100 static int h8300_shift_costs (rtx
);
101 static void h8300_push_pop (int, int, bool, bool);
102 static int h8300_stack_offset_p (rtx
, int);
103 static int h8300_ldm_stm_regno (rtx
, int, int, int);
104 static void h8300_reorg (void);
105 static unsigned int h8300_constant_length (rtx
);
106 static unsigned int h8300_displacement_length (rtx
, int);
107 static unsigned int h8300_classify_operand (rtx
, int, enum h8300_operand_class
*);
108 static unsigned int h8300_length_from_table (rtx
, rtx
, const h8300_length_table
*);
109 static unsigned int h8300_unary_length (rtx
);
110 static unsigned int h8300_short_immediate_length (rtx
);
111 static unsigned int h8300_bitfield_length (rtx
, rtx
);
112 static unsigned int h8300_binary_length (rtx
, const h8300_length_table
*);
113 static bool h8300_short_move_mem_p (rtx
, enum rtx_code
);
114 static unsigned int h8300_move_length (rtx
*, const h8300_length_table
*);
115 static bool h8300_hard_regno_scratch_ok (unsigned int);
117 /* CPU_TYPE, says what cpu we're compiling for. */
120 /* True if a #pragma interrupt has been seen for the current function. */
121 static int pragma_interrupt
;
123 /* True if a #pragma saveall has been seen for the current function. */
124 static int pragma_saveall
;
126 static const char *const names_big
[] =
127 { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7" };
129 static const char *const names_extended
[] =
130 { "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7" };
132 static const char *const names_upper_extended
[] =
133 { "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7" };
135 /* Points to one of the above. */
136 /* ??? The above could be put in an array indexed by CPU_TYPE. */
137 const char * const *h8_reg_names
;
139 /* Various operations needed by the following, indexed by CPU_TYPE. */
141 const char *h8_push_op
, *h8_pop_op
, *h8_mov_op
;
143 /* Value of MOVE_RATIO. */
144 int h8300_move_ratio
;
146 /* See below where shifts are handled for explanation of this enum. */
156 /* Symbols of the various shifts which can be used as indices. */
160 SHIFT_ASHIFT
, SHIFT_LSHIFTRT
, SHIFT_ASHIFTRT
163 /* Macros to keep the shift algorithm tables small. */
164 #define INL SHIFT_INLINE
165 #define ROT SHIFT_ROT_AND
166 #define LOP SHIFT_LOOP
167 #define SPC SHIFT_SPECIAL
169 /* The shift algorithms for each machine, mode, shift type, and shift
170 count are defined below. The three tables below correspond to
171 QImode, HImode, and SImode, respectively. Each table is organized
172 by, in the order of indices, machine, shift type, and shift count. */
174 static enum shift_alg shift_alg_qi
[3][3][8] = {
177 /* 0 1 2 3 4 5 6 7 */
178 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
179 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
180 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
} /* SHIFT_ASHIFTRT */
184 /* 0 1 2 3 4 5 6 7 */
185 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
186 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
187 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
} /* SHIFT_ASHIFTRT */
191 /* 0 1 2 3 4 5 6 7 */
192 { INL
, INL
, INL
, INL
, INL
, INL
, ROT
, ROT
}, /* SHIFT_ASHIFT */
193 { INL
, INL
, INL
, INL
, INL
, INL
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
194 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
} /* SHIFT_ASHIFTRT */
198 static enum shift_alg shift_alg_hi
[3][3][16] = {
201 /* 0 1 2 3 4 5 6 7 */
202 /* 8 9 10 11 12 13 14 15 */
203 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
204 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
205 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
,
206 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
207 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
,
208 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
212 /* 0 1 2 3 4 5 6 7 */
213 /* 8 9 10 11 12 13 14 15 */
214 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
215 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
216 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
217 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
218 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
219 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
223 /* 0 1 2 3 4 5 6 7 */
224 /* 8 9 10 11 12 13 14 15 */
225 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
226 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
227 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
228 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
229 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
230 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
234 static enum shift_alg shift_alg_si
[3][3][32] = {
237 /* 0 1 2 3 4 5 6 7 */
238 /* 8 9 10 11 12 13 14 15 */
239 /* 16 17 18 19 20 21 22 23 */
240 /* 24 25 26 27 28 29 30 31 */
241 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
242 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
243 SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
,
244 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFT */
245 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
246 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
247 SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
,
248 SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, SPC
}, /* SHIFT_LSHIFTRT */
249 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
250 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
251 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
252 SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
256 /* 0 1 2 3 4 5 6 7 */
257 /* 8 9 10 11 12 13 14 15 */
258 /* 16 17 18 19 20 21 22 23 */
259 /* 24 25 26 27 28 29 30 31 */
260 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
261 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
262 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
263 SPC
, LOP
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
264 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
265 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
266 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
267 SPC
, LOP
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
268 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
269 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
270 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
271 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
275 /* 0 1 2 3 4 5 6 7 */
276 /* 8 9 10 11 12 13 14 15 */
277 /* 16 17 18 19 20 21 22 23 */
278 /* 24 25 26 27 28 29 30 31 */
279 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
280 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, SPC
,
281 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
282 SPC
, SPC
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
283 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
284 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, SPC
,
285 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
286 SPC
, SPC
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
287 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
288 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
289 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
290 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
306 /* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */
308 static const struct default_options h8300_option_optimization_table
[] =
310 /* Basic block reordering is only beneficial on targets with cache
311 and/or variable-cycle branches where (cycle count taken !=
312 cycle count not taken). */
313 { OPT_LEVELS_ALL
, OPT_freorder_blocks
, NULL
, 0 },
314 { OPT_LEVELS_NONE
, 0, NULL
, 0 }
317 /* Initialize various cpu specific globals at start up. */
320 h8300_option_override (void)
322 static const char *const h8_push_ops
[2] = { "push" , "push.l" };
323 static const char *const h8_pop_ops
[2] = { "pop" , "pop.l" };
324 static const char *const h8_mov_ops
[2] = { "mov.w", "mov.l" };
328 cpu_type
= (int) CPU_H8300
;
329 h8_reg_names
= names_big
;
333 /* For this we treat the H8/300H and H8S the same. */
334 cpu_type
= (int) CPU_H8300H
;
335 h8_reg_names
= names_extended
;
337 h8_push_op
= h8_push_ops
[cpu_type
];
338 h8_pop_op
= h8_pop_ops
[cpu_type
];
339 h8_mov_op
= h8_mov_ops
[cpu_type
];
341 if (!TARGET_H8300S
&& TARGET_MAC
)
343 error ("-ms2600 is used without -ms");
344 target_flags
|= MASK_H8300S_1
;
347 if (TARGET_H8300
&& TARGET_NORMAL_MODE
)
349 error ("-mn is used without -mh or -ms");
350 target_flags
^= MASK_NORMAL_MODE
;
353 /* Some of the shifts are optimized for speed by default.
354 See http://gcc.gnu.org/ml/gcc-patches/2002-07/msg01858.html
355 If optimizing for size, change shift_alg for those shift to
360 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][5] = SHIFT_LOOP
;
361 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][6] = SHIFT_LOOP
;
362 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][13] = SHIFT_LOOP
;
363 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][14] = SHIFT_LOOP
;
365 shift_alg_hi
[H8_300
][SHIFT_LSHIFTRT
][13] = SHIFT_LOOP
;
366 shift_alg_hi
[H8_300
][SHIFT_LSHIFTRT
][14] = SHIFT_LOOP
;
368 shift_alg_hi
[H8_300
][SHIFT_ASHIFTRT
][13] = SHIFT_LOOP
;
369 shift_alg_hi
[H8_300
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
372 shift_alg_hi
[H8_300H
][SHIFT_ASHIFT
][5] = SHIFT_LOOP
;
373 shift_alg_hi
[H8_300H
][SHIFT_ASHIFT
][6] = SHIFT_LOOP
;
375 shift_alg_hi
[H8_300H
][SHIFT_LSHIFTRT
][5] = SHIFT_LOOP
;
376 shift_alg_hi
[H8_300H
][SHIFT_LSHIFTRT
][6] = SHIFT_LOOP
;
378 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][5] = SHIFT_LOOP
;
379 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][6] = SHIFT_LOOP
;
380 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][13] = SHIFT_LOOP
;
381 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
384 shift_alg_hi
[H8_S
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
387 /* Work out a value for MOVE_RATIO. */
390 /* Memory-memory moves are quite expensive without the
391 h8sx instructions. */
392 h8300_move_ratio
= 3;
394 else if (flag_omit_frame_pointer
)
396 /* movmd sequences are fairly cheap when er6 isn't fixed. They can
397 sometimes be as short as two individual memory-to-memory moves,
398 but since they use all the call-saved registers, it seems better
399 to allow up to three moves here. */
400 h8300_move_ratio
= 4;
402 else if (optimize_size
)
404 /* In this case we don't use movmd sequences since they tend
405 to be longer than calls to memcpy(). Memory-to-memory
406 moves are cheaper than for !TARGET_H8300SX, so it makes
407 sense to have a slightly higher threshold. */
408 h8300_move_ratio
= 4;
412 /* We use movmd sequences for some moves since it can be quicker
413 than calling memcpy(). The sequences will need to save and
414 restore er6 though, so bump up the cost. */
415 h8300_move_ratio
= 6;
418 /* This target defaults to strict volatile bitfields. */
419 if (flag_strict_volatile_bitfields
< 0)
420 flag_strict_volatile_bitfields
= 1;
423 /* Implement REG_CLASS_FROM_LETTER.
425 Some patterns need to use er6 as a scratch register. This is
426 difficult to arrange since er6 is the frame pointer and usually
429 Such patterns should define two alternatives, one which allows only
430 er6 and one which allows any general register. The former alternative
431 should have a 'd' constraint while the latter should be disparaged and
434 Normally, 'd' maps to DESTINATION_REGS and 'D' maps to GENERAL_REGS.
435 However, there are cases where they should be NO_REGS:
437 - 'd' should be NO_REGS when reloading a function that uses the
438 frame pointer. In this case, DESTINATION_REGS won't contain any
439 spillable registers, so the first alternative can't be used.
441 - -fno-omit-frame-pointer means that the frame pointer will
442 always be in use. It's therefore better to map 'd' to NO_REGS
443 before reload so that register allocator will pick the second
446 - we would like 'D' to be be NO_REGS when the frame pointer isn't
447 live, but we the frame pointer may turn out to be needed after
448 we start reload, and then we may have already decided we don't
449 have a choice, so we can't do that. Forcing the register
450 allocator to use er6 if possible might produce better code for
451 small functions: it's more efficient to save and restore er6 in
452 the prologue & epilogue than to do it in a define_split.
453 Hopefully disparaging 'D' will have a similar effect, without
454 forcing a reload failure if the frame pointer is found to be
458 h8300_reg_class_from_letter (int c
)
469 if (!flag_omit_frame_pointer
&& !reload_completed
)
471 if (frame_pointer_needed
&& reload_in_progress
)
473 return DESTINATION_REGS
;
476 /* The meaning of a constraint shouldn't change dynamically, so
477 we can't make this NO_REGS. */
488 /* Return the byte register name for a register rtx X. B should be 0
489 if you want a lower byte register. B should be 1 if you want an
490 upper byte register. */
493 byte_reg (rtx x
, int b
)
495 static const char *const names_small
[] = {
496 "r0l", "r0h", "r1l", "r1h", "r2l", "r2h", "r3l", "r3h",
497 "r4l", "r4h", "r5l", "r5h", "r6l", "r6h", "r7l", "r7h"
500 gcc_assert (REG_P (x
));
502 return names_small
[REGNO (x
) * 2 + b
];
505 /* REGNO must be saved/restored across calls if this macro is true. */
507 #define WORD_REG_USED(regno) \
509 /* No need to save registers if this function will not return. */ \
510 && ! TREE_THIS_VOLATILE (current_function_decl) \
511 && (h8300_saveall_function_p (current_function_decl) \
512 /* Save any call saved register that was used. */ \
513 || (df_regs_ever_live_p (regno) && !call_used_regs[regno]) \
514 /* Save the frame pointer if it was used. */ \
515 || (regno == HARD_FRAME_POINTER_REGNUM && df_regs_ever_live_p (regno)) \
516 /* Save any register used in an interrupt handler. */ \
517 || (h8300_current_function_interrupt_function_p () \
518 && df_regs_ever_live_p (regno)) \
519 /* Save call clobbered registers in non-leaf interrupt \
521 || (h8300_current_function_interrupt_function_p () \
522 && call_used_regs[regno] \
523 && !current_function_is_leaf)))
525 /* We use this to wrap all emitted insns in the prologue. */
527 F (rtx x
, bool set_it
)
530 RTX_FRAME_RELATED_P (x
) = 1;
534 /* Mark all the subexpressions of the PARALLEL rtx PAR as
535 frame-related. Return PAR.
537 dwarf2out.c:dwarf2out_frame_debug_expr ignores sub-expressions of a
538 PARALLEL rtx other than the first if they do not have the
539 FRAME_RELATED flag set on them. */
543 int len
= XVECLEN (par
, 0);
546 for (i
= 0; i
< len
; i
++)
547 F (XVECEXP (par
, 0, i
), true);
552 /* Output assembly language to FILE for the operation OP with operand size
553 SIZE to adjust the stack pointer. */
556 h8300_emit_stack_adjustment (int sign
, HOST_WIDE_INT size
, bool in_prologue
)
558 /* If the frame size is 0, we don't have anything to do. */
562 /* H8/300 cannot add/subtract a large constant with a single
563 instruction. If a temporary register is available, load the
564 constant to it and then do the addition. */
567 && !h8300_current_function_interrupt_function_p ()
568 && !(cfun
->static_chain_decl
!= NULL
&& sign
< 0))
570 rtx r3
= gen_rtx_REG (Pmode
, 3);
571 F (emit_insn (gen_movhi (r3
, GEN_INT (sign
* size
))), in_prologue
);
572 F (emit_insn (gen_addhi3 (stack_pointer_rtx
,
573 stack_pointer_rtx
, r3
)), in_prologue
);
577 /* The stack adjustment made here is further optimized by the
578 splitter. In case of H8/300, the splitter always splits the
579 addition emitted here to make the adjustment interrupt-safe.
580 FIXME: We don't always tag those, because we don't know what
581 the splitter will do. */
584 rtx x
= emit_insn (gen_addhi3 (stack_pointer_rtx
,
585 stack_pointer_rtx
, GEN_INT (sign
* size
)));
590 F (emit_insn (gen_addsi3 (stack_pointer_rtx
,
591 stack_pointer_rtx
, GEN_INT (sign
* size
))), in_prologue
);
595 /* Round up frame size SIZE. */
598 round_frame_size (HOST_WIDE_INT size
)
600 return ((size
+ STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
601 & -STACK_BOUNDARY
/ BITS_PER_UNIT
);
604 /* Compute which registers to push/pop.
605 Return a bit vector of registers. */
608 compute_saved_regs (void)
610 unsigned int saved_regs
= 0;
613 /* Construct a bit vector of registers to be pushed/popped. */
614 for (regno
= 0; regno
<= HARD_FRAME_POINTER_REGNUM
; regno
++)
616 if (WORD_REG_USED (regno
))
617 saved_regs
|= 1 << regno
;
620 /* Don't push/pop the frame pointer as it is treated separately. */
621 if (frame_pointer_needed
)
622 saved_regs
&= ~(1 << HARD_FRAME_POINTER_REGNUM
);
627 /* Emit an insn to push register RN. */
632 rtx reg
= gen_rtx_REG (word_mode
, rn
);
636 x
= gen_push_h8300 (reg
);
637 else if (!TARGET_NORMAL_MODE
)
638 x
= gen_push_h8300hs_advanced (reg
);
640 x
= gen_push_h8300hs_normal (reg
);
641 x
= F (emit_insn (x
), true);
642 REG_NOTES (x
) = gen_rtx_EXPR_LIST (REG_INC
, stack_pointer_rtx
, 0);
645 /* Emit an insn to pop register RN. */
650 rtx reg
= gen_rtx_REG (word_mode
, rn
);
654 x
= gen_pop_h8300 (reg
);
655 else if (!TARGET_NORMAL_MODE
)
656 x
= gen_pop_h8300hs_advanced (reg
);
658 x
= gen_pop_h8300hs_normal (reg
);
660 REG_NOTES (x
) = gen_rtx_EXPR_LIST (REG_INC
, stack_pointer_rtx
, 0);
663 /* Emit an instruction to push or pop NREGS consecutive registers
664 starting at register REGNO. POP_P selects a pop rather than a
665 push and RETURN_P is true if the instruction should return.
667 It must be possible to do the requested operation in a single
668 instruction. If NREGS == 1 && !RETURN_P, use a normal push
669 or pop insn. Otherwise emit a parallel of the form:
672 [(return) ;; if RETURN_P
673 (save or restore REGNO)
674 (save or restore REGNO + 1)
676 (save or restore REGNO + NREGS - 1)
677 (set sp (plus sp (const_int adjust)))] */
680 h8300_push_pop (int regno
, int nregs
, bool pop_p
, bool return_p
)
686 /* See whether we can use a simple push or pop. */
687 if (!return_p
&& nregs
== 1)
696 /* We need one element for the return insn, if present, one for each
697 register, and one for stack adjustment. */
698 vec
= rtvec_alloc ((return_p
? 1 : 0) + nregs
+ 1);
699 sp
= stack_pointer_rtx
;
702 /* Add the return instruction. */
705 RTVEC_ELT (vec
, i
) = gen_rtx_RETURN (VOIDmode
);
709 /* Add the register moves. */
710 for (j
= 0; j
< nregs
; j
++)
716 /* Register REGNO + NREGS - 1 is popped first. Before the
717 stack adjustment, its slot is at address @sp. */
718 lhs
= gen_rtx_REG (SImode
, regno
+ j
);
719 rhs
= gen_rtx_MEM (SImode
, plus_constant (sp
, (nregs
- j
- 1) * 4));
723 /* Register REGNO is pushed first and will be stored at @(-4,sp). */
724 lhs
= gen_rtx_MEM (SImode
, plus_constant (sp
, (j
+ 1) * -4));
725 rhs
= gen_rtx_REG (SImode
, regno
+ j
);
727 RTVEC_ELT (vec
, i
+ j
) = gen_rtx_SET (VOIDmode
, lhs
, rhs
);
730 /* Add the stack adjustment. */
731 offset
= GEN_INT ((pop_p
? nregs
: -nregs
) * 4);
732 RTVEC_ELT (vec
, i
+ j
) = gen_rtx_SET (VOIDmode
, sp
,
733 gen_rtx_PLUS (Pmode
, sp
, offset
));
735 x
= gen_rtx_PARALLEL (VOIDmode
, vec
);
745 /* Return true if X has the value sp + OFFSET. */
748 h8300_stack_offset_p (rtx x
, int offset
)
751 return x
== stack_pointer_rtx
;
753 return (GET_CODE (x
) == PLUS
754 && XEXP (x
, 0) == stack_pointer_rtx
755 && GET_CODE (XEXP (x
, 1)) == CONST_INT
756 && INTVAL (XEXP (x
, 1)) == offset
);
759 /* A subroutine of h8300_ldm_stm_parallel. X is one pattern in
760 something that may be an ldm or stm instruction. If it fits
761 the required template, return the register it loads or stores,
764 LOAD_P is true if X should be a load, false if it should be a store.
765 NREGS is the number of registers that the whole instruction is expected
766 to load or store. INDEX is the index of the register that X should
767 load or store, relative to the lowest-numbered register. */
770 h8300_ldm_stm_regno (rtx x
, int load_p
, int index
, int nregs
)
772 int regindex
, memindex
, offset
;
775 regindex
= 0, memindex
= 1, offset
= (nregs
- index
- 1) * 4;
777 memindex
= 0, regindex
= 1, offset
= (index
+ 1) * -4;
779 if (GET_CODE (x
) == SET
780 && GET_CODE (XEXP (x
, regindex
)) == REG
781 && GET_CODE (XEXP (x
, memindex
)) == MEM
782 && h8300_stack_offset_p (XEXP (XEXP (x
, memindex
), 0), offset
))
783 return REGNO (XEXP (x
, regindex
));
788 /* Return true if the elements of VEC starting at FIRST describe an
789 ldm or stm instruction (LOAD_P says which). */
792 h8300_ldm_stm_parallel (rtvec vec
, int load_p
, int first
)
795 int nregs
, i
, regno
, adjust
;
797 /* There must be a stack adjustment, a register move, and at least one
798 other operation (a return or another register move). */
799 if (GET_NUM_ELEM (vec
) < 3)
802 /* Get the range of registers to be pushed or popped. */
803 nregs
= GET_NUM_ELEM (vec
) - first
- 1;
804 regno
= h8300_ldm_stm_regno (RTVEC_ELT (vec
, first
), load_p
, 0, nregs
);
806 /* Check that the call to h8300_ldm_stm_regno succeeded and
807 that we're only dealing with GPRs. */
808 if (regno
< 0 || regno
+ nregs
> 8)
811 /* 2-register h8s instructions must start with an even-numbered register.
812 3- and 4-register instructions must start with er0 or er4. */
815 if ((regno
& 1) != 0)
817 if (nregs
> 2 && (regno
& 3) != 0)
821 /* Check the other loads or stores. */
822 for (i
= 1; i
< nregs
; i
++)
823 if (h8300_ldm_stm_regno (RTVEC_ELT (vec
, first
+ i
), load_p
, i
, nregs
)
827 /* Check the stack adjustment. */
828 last
= RTVEC_ELT (vec
, first
+ nregs
);
829 adjust
= (load_p
? nregs
: -nregs
) * 4;
830 return (GET_CODE (last
) == SET
831 && SET_DEST (last
) == stack_pointer_rtx
832 && h8300_stack_offset_p (SET_SRC (last
), adjust
));
835 /* This is what the stack looks like after the prolog of
836 a function with a frame has been set up:
842 <saved registers> <- sp
844 This is what the stack looks like after the prolog of
845 a function which doesn't have a frame:
850 <saved registers> <- sp
853 /* Generate RTL code for the function prologue. */
856 h8300_expand_prologue (void)
862 /* If the current function has the OS_Task attribute set, then
863 we have a naked prologue. */
864 if (h8300_os_task_function_p (current_function_decl
))
867 if (h8300_monitor_function_p (current_function_decl
))
868 /* My understanding of monitor functions is they act just like
869 interrupt functions, except the prologue must mask
871 emit_insn (gen_monitor_prologue ());
873 if (frame_pointer_needed
)
876 push (HARD_FRAME_POINTER_REGNUM
);
877 F (emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
), true);
880 /* Push the rest of the registers in ascending order. */
881 saved_regs
= compute_saved_regs ();
882 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
+= n_regs
)
885 if (saved_regs
& (1 << regno
))
889 /* See how many registers we can push at the same time. */
890 if ((!TARGET_H8300SX
|| (regno
& 3) == 0)
891 && ((saved_regs
>> regno
) & 0x0f) == 0x0f)
894 else if ((!TARGET_H8300SX
|| (regno
& 3) == 0)
895 && ((saved_regs
>> regno
) & 0x07) == 0x07)
898 else if ((!TARGET_H8300SX
|| (regno
& 1) == 0)
899 && ((saved_regs
>> regno
) & 0x03) == 0x03)
903 h8300_push_pop (regno
, n_regs
, false, false);
907 /* Leave room for locals. */
908 h8300_emit_stack_adjustment (-1, round_frame_size (get_frame_size ()), true);
911 /* Return nonzero if we can use "rts" for the function currently being
915 h8300_can_use_return_insn_p (void)
917 return (reload_completed
918 && !frame_pointer_needed
919 && get_frame_size () == 0
920 && compute_saved_regs () == 0);
923 /* Generate RTL code for the function epilogue. */
926 h8300_expand_epilogue (void)
931 HOST_WIDE_INT frame_size
;
934 if (h8300_os_task_function_p (current_function_decl
))
935 /* OS_Task epilogues are nearly naked -- they just have an
939 frame_size
= round_frame_size (get_frame_size ());
942 /* Deallocate locals. */
943 h8300_emit_stack_adjustment (1, frame_size
, false);
945 /* Pop the saved registers in descending order. */
946 saved_regs
= compute_saved_regs ();
947 for (regno
= FIRST_PSEUDO_REGISTER
- 1; regno
>= 0; regno
-= n_regs
)
950 if (saved_regs
& (1 << regno
))
954 /* See how many registers we can pop at the same time. */
955 if ((TARGET_H8300SX
|| (regno
& 3) == 3)
956 && ((saved_regs
<< 3 >> regno
) & 0x0f) == 0x0f)
959 else if ((TARGET_H8300SX
|| (regno
& 3) == 2)
960 && ((saved_regs
<< 2 >> regno
) & 0x07) == 0x07)
963 else if ((TARGET_H8300SX
|| (regno
& 1) == 1)
964 && ((saved_regs
<< 1 >> regno
) & 0x03) == 0x03)
968 /* See if this pop would be the last insn before the return.
969 If so, use rte/l or rts/l instead of pop or ldm.l. */
971 && !frame_pointer_needed
973 && (saved_regs
& ((1 << (regno
- n_regs
+ 1)) - 1)) == 0)
976 h8300_push_pop (regno
- n_regs
+ 1, n_regs
, true, returned_p
);
980 /* Pop frame pointer if we had one. */
981 if (frame_pointer_needed
)
985 h8300_push_pop (HARD_FRAME_POINTER_REGNUM
, 1, true, returned_p
);
989 emit_jump_insn (gen_rtx_RETURN (VOIDmode
));
992 /* Return nonzero if the current function is an interrupt
996 h8300_current_function_interrupt_function_p (void)
998 return (h8300_interrupt_function_p (current_function_decl
)
999 || h8300_monitor_function_p (current_function_decl
));
1002 /* Output assembly code for the start of the file. */
1005 h8300_file_start (void)
1007 default_file_start ();
1010 fputs (TARGET_NORMAL_MODE
? "\t.h8300hn\n" : "\t.h8300h\n", asm_out_file
);
1011 else if (TARGET_H8300SX
)
1012 fputs (TARGET_NORMAL_MODE
? "\t.h8300sxn\n" : "\t.h8300sx\n", asm_out_file
);
1013 else if (TARGET_H8300S
)
1014 fputs (TARGET_NORMAL_MODE
? "\t.h8300sn\n" : "\t.h8300s\n", asm_out_file
);
1017 /* Output assembly language code for the end of file. */
1020 h8300_file_end (void)
1022 fputs ("\t.end\n", asm_out_file
);
1025 /* Split an add of a small constant into two adds/subs insns.
1027 If USE_INCDEC_P is nonzero, we generate the last insn using inc/dec
1028 instead of adds/subs. */
1031 split_adds_subs (enum machine_mode mode
, rtx
*operands
)
1033 HOST_WIDE_INT val
= INTVAL (operands
[1]);
1034 rtx reg
= operands
[0];
1035 HOST_WIDE_INT sign
= 1;
1036 HOST_WIDE_INT amount
;
1037 rtx (*gen_add
) (rtx
, rtx
, rtx
);
1039 /* Force VAL to be positive so that we do not have to consider the
1050 gen_add
= gen_addhi3
;
1054 gen_add
= gen_addsi3
;
1061 /* Try different amounts in descending order. */
1062 for (amount
= (TARGET_H8300H
|| TARGET_H8300S
) ? 4 : 2;
1066 for (; val
>= amount
; val
-= amount
)
1067 emit_insn (gen_add (reg
, reg
, GEN_INT (sign
* amount
)));
1073 /* Handle machine specific pragmas for compatibility with existing
1074 compilers for the H8/300.
1076 pragma saveall generates prologue/epilogue code which saves and
1077 restores all the registers on function entry.
1079 pragma interrupt saves and restores all registers, and exits with
1080 an rte instruction rather than an rts. A pointer to a function
1081 with this attribute may be safely used in an interrupt vector. */
1084 h8300_pr_interrupt (struct cpp_reader
*pfile ATTRIBUTE_UNUSED
)
1086 pragma_interrupt
= 1;
1090 h8300_pr_saveall (struct cpp_reader
*pfile ATTRIBUTE_UNUSED
)
1095 /* If the next function argument with MODE and TYPE is to be passed in
1096 a register, return a reg RTX for the hard register in which to pass
1097 the argument. CUM represents the state after the last argument.
1098 If the argument is to be pushed, NULL_RTX is returned.
1100 On the H8/300 all normal args are pushed, unless -mquickcall in which
1101 case the first 3 arguments are passed in registers. */
1104 h8300_function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1105 const_tree type
, bool named
)
1107 static const char *const hand_list
[] = {
1126 rtx result
= NULL_RTX
;
1130 /* Never pass unnamed arguments in registers. */
1134 /* Pass 3 regs worth of data in regs when user asked on the command line. */
1135 if (TARGET_QUICKCALL
)
1138 /* If calling hand written assembler, use 4 regs of args. */
1141 const char * const *p
;
1143 fname
= XSTR (cum
->libcall
, 0);
1145 /* See if this libcall is one of the hand coded ones. */
1146 for (p
= hand_list
; *p
&& strcmp (*p
, fname
) != 0; p
++)
1157 if (mode
== BLKmode
)
1158 size
= int_size_in_bytes (type
);
1160 size
= GET_MODE_SIZE (mode
);
1162 if (size
+ cum
->nbytes
<= regpass
* UNITS_PER_WORD
1163 && cum
->nbytes
/ UNITS_PER_WORD
<= 3)
1164 result
= gen_rtx_REG (mode
, cum
->nbytes
/ UNITS_PER_WORD
);
1170 /* Update the data in CUM to advance over an argument
1171 of mode MODE and data type TYPE.
1172 (TYPE is null for libcalls where that information may not be available.) */
1175 h8300_function_arg_advance (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1176 const_tree type
, bool named ATTRIBUTE_UNUSED
)
1178 cum
->nbytes
+= (mode
!= BLKmode
1179 ? (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
1180 : (int_size_in_bytes (type
) + UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
);
1184 /* Compute the cost of an and insn. */
1187 h8300_and_costs (rtx x
)
1191 if (GET_MODE (x
) == QImode
)
1194 if (GET_MODE (x
) != HImode
1195 && GET_MODE (x
) != SImode
)
1199 operands
[1] = XEXP (x
, 0);
1200 operands
[2] = XEXP (x
, 1);
1202 return compute_logical_op_length (GET_MODE (x
), operands
) / 2;
1205 /* Compute the cost of a shift insn. */
1208 h8300_shift_costs (rtx x
)
1212 if (GET_MODE (x
) != QImode
1213 && GET_MODE (x
) != HImode
1214 && GET_MODE (x
) != SImode
)
1219 operands
[2] = XEXP (x
, 1);
1221 return compute_a_shift_length (NULL
, operands
) / 2;
1224 /* Worker function for TARGET_RTX_COSTS. */
1227 h8300_rtx_costs (rtx x
, int code
, int outer_code
, int *total
, bool speed
)
1229 if (TARGET_H8300SX
&& outer_code
== MEM
)
1231 /* Estimate the number of execution states needed to calculate
1233 if (register_operand (x
, VOIDmode
)
1234 || GET_CODE (x
) == POST_INC
1235 || GET_CODE (x
) == POST_DEC
1239 *total
= COSTS_N_INSNS (1);
1247 HOST_WIDE_INT n
= INTVAL (x
);
1251 /* Constant operands need the same number of processor
1252 states as register operands. Although we could try to
1253 use a size-based cost for !speed, the lack of
1254 of a mode makes the results very unpredictable. */
1258 if (-4 <= n
|| n
<= 4)
1269 *total
= 0 + (outer_code
== SET
);
1273 if (TARGET_H8300H
|| TARGET_H8300S
)
1274 *total
= 0 + (outer_code
== SET
);
1289 /* See comment for CONST_INT. */
1301 if (XEXP (x
, 1) == const0_rtx
)
1306 if (!h8300_dst_operand (XEXP (x
, 0), VOIDmode
)
1307 || !h8300_src_operand (XEXP (x
, 1), VOIDmode
))
1309 *total
= COSTS_N_INSNS (h8300_and_costs (x
));
1312 /* We say that MOD and DIV are so expensive because otherwise we'll
1313 generate some really horrible code for division of a power of two. */
1319 switch (GET_MODE (x
))
1323 *total
= COSTS_N_INSNS (!speed
? 4 : 10);
1327 *total
= COSTS_N_INSNS (!speed
? 4 : 18);
1333 *total
= COSTS_N_INSNS (12);
1338 switch (GET_MODE (x
))
1342 *total
= COSTS_N_INSNS (2);
1346 *total
= COSTS_N_INSNS (5);
1352 *total
= COSTS_N_INSNS (4);
1358 if (h8sx_binary_shift_operator (x
, VOIDmode
))
1360 *total
= COSTS_N_INSNS (2);
1363 else if (h8sx_unary_shift_operator (x
, VOIDmode
))
1365 *total
= COSTS_N_INSNS (1);
1368 *total
= COSTS_N_INSNS (h8300_shift_costs (x
));
1373 if (GET_MODE (x
) == HImode
)
1380 *total
= COSTS_N_INSNS (1);
1385 /* Documentation for the machine specific operand escapes:
1387 'E' like s but negative.
1388 'F' like t but negative.
1389 'G' constant just the negative
1390 'R' print operand as a byte:8 address if appropriate, else fall back to
1392 'S' print operand as a long word
1393 'T' print operand as a word
1394 'V' find the set bit, and print its number.
1395 'W' find the clear bit, and print its number.
1396 'X' print operand as a byte
1397 'Y' print either l or h depending on whether last 'Z' operand < 8 or >= 8.
1398 If this operand isn't a register, fall back to 'R' handling.
1400 'c' print the opcode corresponding to rtl
1401 'e' first word of 32-bit value - if reg, then least reg. if mem
1402 then least. if const then most sig word
1403 'f' second word of 32-bit value - if reg, then biggest reg. if mem
1404 then +2. if const then least sig word
1405 'j' print operand as condition code.
1406 'k' print operand as reverse condition code.
1407 'm' convert an integer operand to a size suffix (.b, .w or .l)
1408 'o' print an integer without a leading '#'
1409 's' print as low byte of 16-bit value
1410 't' print as high byte of 16-bit value
1411 'w' print as low byte of 32-bit value
1412 'x' print as 2nd byte of 32-bit value
1413 'y' print as 3rd byte of 32-bit value
1414 'z' print as msb of 32-bit value
1417 /* Return assembly language string which identifies a comparison type. */
1420 cond_string (enum rtx_code code
)
1449 /* Print operand X using operand code CODE to assembly language output file
1453 print_operand (FILE *file
, rtx x
, int code
)
1455 /* This is used for communication between codes V,W,Z and Y. */
1461 switch (GET_CODE (x
))
1464 fprintf (file
, "%sl", names_big
[REGNO (x
)]);
1467 fprintf (file
, "#%ld", (-INTVAL (x
)) & 0xff);
1474 switch (GET_CODE (x
))
1477 fprintf (file
, "%sh", names_big
[REGNO (x
)]);
1480 fprintf (file
, "#%ld", ((-INTVAL (x
)) & 0xff00) >> 8);
1487 gcc_assert (GET_CODE (x
) == CONST_INT
);
1488 fprintf (file
, "#%ld", 0xff & (-INTVAL (x
)));
1491 if (GET_CODE (x
) == REG
)
1492 fprintf (file
, "%s", names_extended
[REGNO (x
)]);
1497 if (GET_CODE (x
) == REG
)
1498 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1503 bitint
= (INTVAL (x
) & 0xffff);
1504 if ((exact_log2 ((bitint
>> 8) & 0xff)) == -1)
1505 bitint
= exact_log2 (bitint
& 0xff);
1507 bitint
= exact_log2 ((bitint
>> 8) & 0xff);
1508 gcc_assert (bitint
>= 0);
1509 fprintf (file
, "#%d", bitint
);
1512 bitint
= ((~INTVAL (x
)) & 0xffff);
1513 if ((exact_log2 ((bitint
>> 8) & 0xff)) == -1 )
1514 bitint
= exact_log2 (bitint
& 0xff);
1516 bitint
= (exact_log2 ((bitint
>> 8) & 0xff));
1517 gcc_assert (bitint
>= 0);
1518 fprintf (file
, "#%d", bitint
);
1522 if (GET_CODE (x
) == REG
)
1523 fprintf (file
, "%s", byte_reg (x
, 0));
1528 gcc_assert (bitint
>= 0);
1529 if (GET_CODE (x
) == REG
)
1530 fprintf (file
, "%s%c", names_big
[REGNO (x
)], bitint
> 7 ? 'h' : 'l');
1532 print_operand (file
, x
, 'R');
1536 bitint
= INTVAL (x
);
1537 fprintf (file
, "#%d", bitint
& 7);
1540 switch (GET_CODE (x
))
1543 fprintf (file
, "or");
1546 fprintf (file
, "xor");
1549 fprintf (file
, "and");
1556 switch (GET_CODE (x
))
1560 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1562 fprintf (file
, "%s", names_upper_extended
[REGNO (x
)]);
1565 print_operand (file
, x
, 0);
1568 fprintf (file
, "#%ld", ((INTVAL (x
) >> 16) & 0xffff));
1574 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1575 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1576 fprintf (file
, "#%ld", ((val
>> 16) & 0xffff));
1585 switch (GET_CODE (x
))
1589 fprintf (file
, "%s", names_big
[REGNO (x
) + 1]);
1591 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1594 x
= adjust_address (x
, HImode
, 2);
1595 print_operand (file
, x
, 0);
1598 fprintf (file
, "#%ld", INTVAL (x
) & 0xffff);
1604 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1605 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1606 fprintf (file
, "#%ld", (val
& 0xffff));
1614 fputs (cond_string (GET_CODE (x
)), file
);
1617 fputs (cond_string (reverse_condition (GET_CODE (x
))), file
);
1620 gcc_assert (GET_CODE (x
) == CONST_INT
);
1640 print_operand_address (file
, x
);
1643 if (GET_CODE (x
) == CONST_INT
)
1644 fprintf (file
, "#%ld", (INTVAL (x
)) & 0xff);
1646 fprintf (file
, "%s", byte_reg (x
, 0));
1649 if (GET_CODE (x
) == CONST_INT
)
1650 fprintf (file
, "#%ld", (INTVAL (x
) >> 8) & 0xff);
1652 fprintf (file
, "%s", byte_reg (x
, 1));
1655 if (GET_CODE (x
) == CONST_INT
)
1656 fprintf (file
, "#%ld", INTVAL (x
) & 0xff);
1658 fprintf (file
, "%s",
1659 byte_reg (x
, TARGET_H8300
? 2 : 0));
1662 if (GET_CODE (x
) == CONST_INT
)
1663 fprintf (file
, "#%ld", (INTVAL (x
) >> 8) & 0xff);
1665 fprintf (file
, "%s",
1666 byte_reg (x
, TARGET_H8300
? 3 : 1));
1669 if (GET_CODE (x
) == CONST_INT
)
1670 fprintf (file
, "#%ld", (INTVAL (x
) >> 16) & 0xff);
1672 fprintf (file
, "%s", byte_reg (x
, 0));
1675 if (GET_CODE (x
) == CONST_INT
)
1676 fprintf (file
, "#%ld", (INTVAL (x
) >> 24) & 0xff);
1678 fprintf (file
, "%s", byte_reg (x
, 1));
1683 switch (GET_CODE (x
))
1686 switch (GET_MODE (x
))
1689 #if 0 /* Is it asm ("mov.b %0,r2l", ...) */
1690 fprintf (file
, "%s", byte_reg (x
, 0));
1691 #else /* ... or is it asm ("mov.b %0l,r2l", ...) */
1692 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1696 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1700 fprintf (file
, "%s", names_extended
[REGNO (x
)]);
1709 rtx addr
= XEXP (x
, 0);
1711 fprintf (file
, "@");
1712 output_address (addr
);
1714 /* Add a length suffix to constant addresses. Although this
1715 is often unnecessary, it helps to avoid ambiguity in the
1716 syntax of mova. If we wrote an insn like:
1718 mova/w.l @(1,@foo.b),er0
1720 then .b would be considered part of the symbol name.
1721 Adding a length after foo will avoid this. */
1722 if (CONSTANT_P (addr
))
1726 /* Used for mov.b and bit operations. */
1727 if (h8300_eightbit_constant_address_p (addr
))
1729 fprintf (file
, ":8");
1733 /* Fall through. We should not get here if we are
1734 processing bit operations on H8/300 or H8/300H
1735 because 'U' constraint does not allow bit
1736 operations on the tiny area on these machines. */
1741 if (h8300_constant_length (addr
) == 2)
1742 fprintf (file
, ":16");
1744 fprintf (file
, ":32");
1756 fprintf (file
, "#");
1757 print_operand_address (file
, x
);
1763 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1764 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1765 fprintf (file
, "#%ld", val
);
1774 /* Output assembly language output for the address ADDR to FILE. */
1777 print_operand_address (FILE *file
, rtx addr
)
1782 switch (GET_CODE (addr
))
1785 fprintf (file
, "%s", h8_reg_names
[REGNO (addr
)]);
1789 fprintf (file
, "-%s", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1793 fprintf (file
, "%s+", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1797 fprintf (file
, "+%s", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1801 fprintf (file
, "%s-", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1805 fprintf (file
, "(");
1807 index
= h8300_get_index (XEXP (addr
, 0), VOIDmode
, &size
);
1808 if (GET_CODE (index
) == REG
)
1811 print_operand_address (file
, XEXP (addr
, 1));
1812 fprintf (file
, ",");
1816 print_operand_address (file
, index
);
1820 print_operand (file
, index
, 'X');
1825 print_operand (file
, index
, 'T');
1830 print_operand (file
, index
, 'S');
1834 /* print_operand_address (file, XEXP (addr, 0)); */
1839 print_operand_address (file
, XEXP (addr
, 0));
1840 fprintf (file
, "+");
1841 print_operand_address (file
, XEXP (addr
, 1));
1843 fprintf (file
, ")");
1848 /* Since the H8/300 only has 16-bit pointers, negative values are also
1849 those >= 32768. This happens for example with pointer minus a
1850 constant. We don't want to turn (char *p - 2) into
1851 (char *p + 65534) because loop unrolling can build upon this
1852 (IE: char *p + 131068). */
1853 int n
= INTVAL (addr
);
1855 n
= (int) (short) n
;
1856 fprintf (file
, "%d", n
);
1861 output_addr_const (file
, addr
);
1866 /* Output all insn addresses and their sizes into the assembly language
1867 output file. This is helpful for debugging whether the length attributes
1868 in the md file are correct. This is not meant to be a user selectable
1872 final_prescan_insn (rtx insn
, rtx
*operand ATTRIBUTE_UNUSED
,
1873 int num_operands ATTRIBUTE_UNUSED
)
1875 /* This holds the last insn address. */
1876 static int last_insn_address
= 0;
1878 const int uid
= INSN_UID (insn
);
1880 if (TARGET_ADDRESSES
)
1882 fprintf (asm_out_file
, "; 0x%x %d\n", INSN_ADDRESSES (uid
),
1883 INSN_ADDRESSES (uid
) - last_insn_address
);
1884 last_insn_address
= INSN_ADDRESSES (uid
);
1888 /* Prepare for an SI sized move. */
1891 h8300_expand_movsi (rtx operands
[])
1893 rtx src
= operands
[1];
1894 rtx dst
= operands
[0];
1895 if (!reload_in_progress
&& !reload_completed
)
1897 if (!register_operand (dst
, GET_MODE (dst
)))
1899 rtx tmp
= gen_reg_rtx (GET_MODE (dst
));
1900 emit_move_insn (tmp
, src
);
1907 /* Given FROM and TO register numbers, say whether this elimination is allowed.
1908 Frame pointer elimination is automatically handled.
1910 For the h8300, if frame pointer elimination is being done, we would like to
1911 convert ap and rp into sp, not fp.
1913 All other eliminations are valid. */
1916 h8300_can_eliminate (const int from ATTRIBUTE_UNUSED
, const int to
)
1918 return (to
== STACK_POINTER_REGNUM
? ! frame_pointer_needed
: true);
1921 /* Function for INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET).
1922 Define the offset between two registers, one to be eliminated, and
1923 the other its replacement, at the start of a routine. */
1926 h8300_initial_elimination_offset (int from
, int to
)
1928 /* The number of bytes that the return address takes on the stack. */
1929 int pc_size
= POINTER_SIZE
/ BITS_PER_UNIT
;
1931 /* The number of bytes that the saved frame pointer takes on the stack. */
1932 int fp_size
= frame_pointer_needed
* UNITS_PER_WORD
;
1934 /* The number of bytes that the saved registers, excluding the frame
1935 pointer, take on the stack. */
1936 int saved_regs_size
= 0;
1938 /* The number of bytes that the locals takes on the stack. */
1939 int frame_size
= round_frame_size (get_frame_size ());
1943 for (regno
= 0; regno
<= HARD_FRAME_POINTER_REGNUM
; regno
++)
1944 if (WORD_REG_USED (regno
))
1945 saved_regs_size
+= UNITS_PER_WORD
;
1947 /* Adjust saved_regs_size because the above loop took the frame
1948 pointer int account. */
1949 saved_regs_size
-= fp_size
;
1953 case HARD_FRAME_POINTER_REGNUM
:
1956 case ARG_POINTER_REGNUM
:
1957 return pc_size
+ fp_size
;
1958 case RETURN_ADDRESS_POINTER_REGNUM
:
1960 case FRAME_POINTER_REGNUM
:
1961 return -saved_regs_size
;
1966 case STACK_POINTER_REGNUM
:
1969 case ARG_POINTER_REGNUM
:
1970 return pc_size
+ saved_regs_size
+ frame_size
;
1971 case RETURN_ADDRESS_POINTER_REGNUM
:
1972 return saved_regs_size
+ frame_size
;
1973 case FRAME_POINTER_REGNUM
:
1985 /* Worker function for RETURN_ADDR_RTX. */
1988 h8300_return_addr_rtx (int count
, rtx frame
)
1993 ret
= gen_rtx_MEM (Pmode
,
1994 gen_rtx_REG (Pmode
, RETURN_ADDRESS_POINTER_REGNUM
));
1995 else if (flag_omit_frame_pointer
)
1998 ret
= gen_rtx_MEM (Pmode
,
1999 memory_address (Pmode
,
2000 plus_constant (frame
, UNITS_PER_WORD
)));
2001 set_mem_alias_set (ret
, get_frame_alias_set ());
2005 /* Update the condition code from the insn. */
2008 notice_update_cc (rtx body
, rtx insn
)
2012 switch (get_attr_cc (insn
))
2015 /* Insn does not affect CC at all. */
2019 /* Insn does not change CC, but the 0'th operand has been changed. */
2020 if (cc_status
.value1
!= 0
2021 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
2022 cc_status
.value1
= 0;
2023 if (cc_status
.value2
!= 0
2024 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value2
))
2025 cc_status
.value2
= 0;
2029 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2030 The V flag is unusable. The C flag may or may not be known but
2031 that's ok because alter_cond will change tests to use EQ/NE. */
2033 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2034 set
= single_set (insn
);
2035 cc_status
.value1
= SET_SRC (set
);
2036 if (SET_DEST (set
) != cc0_rtx
)
2037 cc_status
.value2
= SET_DEST (set
);
2041 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2042 The C flag may or may not be known but that's ok because
2043 alter_cond will change tests to use EQ/NE. */
2045 cc_status
.flags
|= CC_NO_CARRY
;
2046 set
= single_set (insn
);
2047 cc_status
.value1
= SET_SRC (set
);
2048 if (SET_DEST (set
) != cc0_rtx
)
2050 /* If the destination is STRICT_LOW_PART, strip off
2052 if (GET_CODE (SET_DEST (set
)) == STRICT_LOW_PART
)
2053 cc_status
.value2
= XEXP (SET_DEST (set
), 0);
2055 cc_status
.value2
= SET_DEST (set
);
2060 /* The insn is a compare instruction. */
2062 cc_status
.value1
= SET_SRC (body
);
2066 /* Insn doesn't leave CC in a usable state. */
2072 /* Given that X occurs in an address of the form (plus X constant),
2073 return the part of X that is expected to be a register. There are
2074 four kinds of addressing mode to recognize:
2081 If SIZE is nonnull, and the address is one of the last three forms,
2082 set *SIZE to the index multiplication factor. Set it to 0 for
2083 plain @(dd,Rn) addresses.
2085 MODE is the mode of the value being accessed. It can be VOIDmode
2086 if the address is known to be valid, but its mode is unknown. */
2089 h8300_get_index (rtx x
, enum machine_mode mode
, int *size
)
2096 factor
= (mode
== VOIDmode
? 0 : GET_MODE_SIZE (mode
));
2099 && (mode
== VOIDmode
2100 || GET_MODE_CLASS (mode
) == MODE_INT
2101 || GET_MODE_CLASS (mode
) == MODE_FLOAT
))
2103 if (factor
<= 1 && GET_CODE (x
) == ZERO_EXTEND
)
2105 /* When accessing byte-sized values, the index can be
2106 a zero-extended QImode or HImode register. */
2107 *size
= GET_MODE_SIZE (GET_MODE (XEXP (x
, 0)));
2112 /* We're looking for addresses of the form:
2115 or (mult (zero_extend X) I)
2117 where I is the size of the operand being accessed.
2118 The canonical form of the second expression is:
2120 (and (mult (subreg X) I) J)
2122 where J == GET_MODE_MASK (GET_MODE (X)) * I. */
2125 if (GET_CODE (x
) == AND
2126 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2128 || INTVAL (XEXP (x
, 1)) == 0xff * factor
2129 || INTVAL (XEXP (x
, 1)) == 0xffff * factor
))
2131 index
= XEXP (x
, 0);
2132 *size
= (INTVAL (XEXP (x
, 1)) >= 0xffff ? 2 : 1);
2140 if (GET_CODE (index
) == MULT
2141 && GET_CODE (XEXP (index
, 1)) == CONST_INT
2142 && (factor
== 0 || factor
== INTVAL (XEXP (index
, 1))))
2143 return XEXP (index
, 0);
2150 static const h8300_length_table addb_length_table
=
2152 /* #xx Rs @aa @Rs @xx */
2153 { 2, 2, 4, 4, 4 }, /* add.b xx,Rd */
2154 { 4, 4, 4, 4, 6 }, /* add.b xx,@aa */
2155 { 4, 4, 4, 4, 6 }, /* add.b xx,@Rd */
2156 { 6, 4, 4, 4, 6 } /* add.b xx,@xx */
2159 static const h8300_length_table addw_length_table
=
2161 /* #xx Rs @aa @Rs @xx */
2162 { 2, 2, 4, 4, 4 }, /* add.w xx,Rd */
2163 { 4, 4, 4, 4, 6 }, /* add.w xx,@aa */
2164 { 4, 4, 4, 4, 6 }, /* add.w xx,@Rd */
2165 { 4, 4, 4, 4, 6 } /* add.w xx,@xx */
2168 static const h8300_length_table addl_length_table
=
2170 /* #xx Rs @aa @Rs @xx */
2171 { 2, 2, 4, 4, 4 }, /* add.l xx,Rd */
2172 { 4, 4, 6, 6, 6 }, /* add.l xx,@aa */
2173 { 4, 4, 6, 6, 6 }, /* add.l xx,@Rd */
2174 { 4, 4, 6, 6, 6 } /* add.l xx,@xx */
2177 #define logicb_length_table addb_length_table
2178 #define logicw_length_table addw_length_table
2180 static const h8300_length_table logicl_length_table
=
2182 /* #xx Rs @aa @Rs @xx */
2183 { 2, 4, 4, 4, 4 }, /* and.l xx,Rd */
2184 { 4, 4, 6, 6, 6 }, /* and.l xx,@aa */
2185 { 4, 4, 6, 6, 6 }, /* and.l xx,@Rd */
2186 { 4, 4, 6, 6, 6 } /* and.l xx,@xx */
2189 static const h8300_length_table movb_length_table
=
2191 /* #xx Rs @aa @Rs @xx */
2192 { 2, 2, 2, 2, 4 }, /* mov.b xx,Rd */
2193 { 4, 2, 4, 4, 4 }, /* mov.b xx,@aa */
2194 { 4, 2, 4, 4, 4 }, /* mov.b xx,@Rd */
2195 { 4, 4, 4, 4, 4 } /* mov.b xx,@xx */
2198 #define movw_length_table movb_length_table
2200 static const h8300_length_table movl_length_table
=
2202 /* #xx Rs @aa @Rs @xx */
2203 { 2, 2, 4, 4, 4 }, /* mov.l xx,Rd */
2204 { 4, 4, 4, 4, 4 }, /* mov.l xx,@aa */
2205 { 4, 4, 4, 4, 4 }, /* mov.l xx,@Rd */
2206 { 4, 4, 4, 4, 4 } /* mov.l xx,@xx */
2209 /* Return the size of the given address or displacement constant. */
2212 h8300_constant_length (rtx constant
)
2214 /* Check for (@d:16,Reg). */
2215 if (GET_CODE (constant
) == CONST_INT
2216 && IN_RANGE (INTVAL (constant
), -0x8000, 0x7fff))
2219 /* Check for (@d:16,Reg) in cases where the displacement is
2220 an absolute address. */
2221 if (Pmode
== HImode
|| h8300_tiny_constant_address_p (constant
))
2227 /* Return the size of a displacement field in address ADDR, which should
2228 have the form (plus X constant). SIZE is the number of bytes being
2232 h8300_displacement_length (rtx addr
, int size
)
2236 offset
= XEXP (addr
, 1);
2238 /* Check for @(d:2,Reg). */
2239 if (register_operand (XEXP (addr
, 0), VOIDmode
)
2240 && GET_CODE (offset
) == CONST_INT
2241 && (INTVAL (offset
) == size
2242 || INTVAL (offset
) == size
* 2
2243 || INTVAL (offset
) == size
* 3))
2246 return h8300_constant_length (offset
);
2249 /* Store the class of operand OP in *OPCLASS and return the length of any
2250 extra operand fields. SIZE is the number of bytes in OP. OPCLASS
2251 can be null if only the length is needed. */
2254 h8300_classify_operand (rtx op
, int size
, enum h8300_operand_class
*opclass
)
2256 enum h8300_operand_class dummy
;
2261 if (CONSTANT_P (op
))
2263 *opclass
= H8OP_IMMEDIATE
;
2265 /* Byte-sized immediates are stored in the opcode fields. */
2269 /* If this is a 32-bit instruction, see whether the constant
2270 will fit into a 16-bit immediate field. */
2273 && GET_CODE (op
) == CONST_INT
2274 && IN_RANGE (INTVAL (op
), 0, 0xffff))
2279 else if (GET_CODE (op
) == MEM
)
2282 if (CONSTANT_P (op
))
2284 *opclass
= H8OP_MEM_ABSOLUTE
;
2285 return h8300_constant_length (op
);
2287 else if (GET_CODE (op
) == PLUS
&& CONSTANT_P (XEXP (op
, 1)))
2289 *opclass
= H8OP_MEM_COMPLEX
;
2290 return h8300_displacement_length (op
, size
);
2292 else if (GET_RTX_CLASS (GET_CODE (op
)) == RTX_AUTOINC
)
2294 *opclass
= H8OP_MEM_COMPLEX
;
2297 else if (register_operand (op
, VOIDmode
))
2299 *opclass
= H8OP_MEM_BASE
;
2303 gcc_assert (register_operand (op
, VOIDmode
));
2304 *opclass
= H8OP_REGISTER
;
2308 /* Return the length of the instruction described by TABLE given that
2309 its operands are OP1 and OP2. OP1 must be an h8300_dst_operand
2310 and OP2 must be an h8300_src_operand. */
2313 h8300_length_from_table (rtx op1
, rtx op2
, const h8300_length_table
*table
)
2315 enum h8300_operand_class op1_class
, op2_class
;
2316 unsigned int size
, immediate_length
;
2318 size
= GET_MODE_SIZE (GET_MODE (op1
));
2319 immediate_length
= (h8300_classify_operand (op1
, size
, &op1_class
)
2320 + h8300_classify_operand (op2
, size
, &op2_class
));
2321 return immediate_length
+ (*table
)[op1_class
- 1][op2_class
];
2324 /* Return the length of a unary instruction such as neg or not given that
2325 its operand is OP. */
2328 h8300_unary_length (rtx op
)
2330 enum h8300_operand_class opclass
;
2331 unsigned int size
, operand_length
;
2333 size
= GET_MODE_SIZE (GET_MODE (op
));
2334 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2341 return (size
== 4 ? 6 : 4);
2343 case H8OP_MEM_ABSOLUTE
:
2344 return operand_length
+ (size
== 4 ? 6 : 4);
2346 case H8OP_MEM_COMPLEX
:
2347 return operand_length
+ 6;
2354 /* Likewise short immediate instructions such as add.w #xx:3,OP. */
2357 h8300_short_immediate_length (rtx op
)
2359 enum h8300_operand_class opclass
;
2360 unsigned int size
, operand_length
;
2362 size
= GET_MODE_SIZE (GET_MODE (op
));
2363 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2371 case H8OP_MEM_ABSOLUTE
:
2372 case H8OP_MEM_COMPLEX
:
2373 return 4 + operand_length
;
2380 /* Likewise bitfield load and store instructions. */
2383 h8300_bitfield_length (rtx op
, rtx op2
)
2385 enum h8300_operand_class opclass
;
2386 unsigned int size
, operand_length
;
2388 if (GET_CODE (op
) == REG
)
2390 gcc_assert (GET_CODE (op
) != REG
);
2392 size
= GET_MODE_SIZE (GET_MODE (op
));
2393 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2398 case H8OP_MEM_ABSOLUTE
:
2399 case H8OP_MEM_COMPLEX
:
2400 return 4 + operand_length
;
2407 /* Calculate the length of general binary instruction INSN using TABLE. */
2410 h8300_binary_length (rtx insn
, const h8300_length_table
*table
)
2414 set
= single_set (insn
);
2417 if (BINARY_P (SET_SRC (set
)))
2418 return h8300_length_from_table (XEXP (SET_SRC (set
), 0),
2419 XEXP (SET_SRC (set
), 1), table
);
2422 gcc_assert (GET_RTX_CLASS (GET_CODE (SET_SRC (set
))) == RTX_TERNARY
);
2423 return h8300_length_from_table (XEXP (XEXP (SET_SRC (set
), 1), 0),
2424 XEXP (XEXP (SET_SRC (set
), 1), 1),
2429 /* Subroutine of h8300_move_length. Return true if OP is 1- or 2-byte
2430 memory reference and either (1) it has the form @(d:16,Rn) or
2431 (2) its address has the code given by INC_CODE. */
2434 h8300_short_move_mem_p (rtx op
, enum rtx_code inc_code
)
2439 if (GET_CODE (op
) != MEM
)
2442 addr
= XEXP (op
, 0);
2443 size
= GET_MODE_SIZE (GET_MODE (op
));
2444 if (size
!= 1 && size
!= 2)
2447 return (GET_CODE (addr
) == inc_code
2448 || (GET_CODE (addr
) == PLUS
2449 && GET_CODE (XEXP (addr
, 0)) == REG
2450 && h8300_displacement_length (addr
, size
) == 2));
2453 /* Calculate the length of move instruction INSN using the given length
2454 table. Although the tables are correct for most cases, there is some
2455 irregularity in the length of mov.b and mov.w. The following forms:
2462 are two bytes shorter than most other "mov Rs, @complex" or
2463 "mov @complex,Rd" combinations. */
2466 h8300_move_length (rtx
*operands
, const h8300_length_table
*table
)
2470 size
= h8300_length_from_table (operands
[0], operands
[1], table
);
2471 if (REG_P (operands
[0]) && h8300_short_move_mem_p (operands
[1], POST_INC
))
2473 if (REG_P (operands
[1]) && h8300_short_move_mem_p (operands
[0], PRE_DEC
))
2478 /* Return the length of a mova instruction with the given operands.
2479 DEST is the register destination, SRC is the source address and
2480 OFFSET is the 16-bit or 32-bit displacement. */
2483 h8300_mova_length (rtx dest
, rtx src
, rtx offset
)
2488 + h8300_constant_length (offset
)
2489 + h8300_classify_operand (src
, GET_MODE_SIZE (GET_MODE (src
)), 0));
2490 if (!REG_P (dest
) || !REG_P (src
) || REGNO (src
) != REGNO (dest
))
2495 /* Compute the length of INSN based on its length_table attribute.
2496 OPERANDS is the array of its operands. */
2499 h8300_insn_length_from_table (rtx insn
, rtx
* operands
)
2501 switch (get_attr_length_table (insn
))
2503 case LENGTH_TABLE_NONE
:
2506 case LENGTH_TABLE_ADDB
:
2507 return h8300_binary_length (insn
, &addb_length_table
);
2509 case LENGTH_TABLE_ADDW
:
2510 return h8300_binary_length (insn
, &addw_length_table
);
2512 case LENGTH_TABLE_ADDL
:
2513 return h8300_binary_length (insn
, &addl_length_table
);
2515 case LENGTH_TABLE_LOGICB
:
2516 return h8300_binary_length (insn
, &logicb_length_table
);
2518 case LENGTH_TABLE_MOVB
:
2519 return h8300_move_length (operands
, &movb_length_table
);
2521 case LENGTH_TABLE_MOVW
:
2522 return h8300_move_length (operands
, &movw_length_table
);
2524 case LENGTH_TABLE_MOVL
:
2525 return h8300_move_length (operands
, &movl_length_table
);
2527 case LENGTH_TABLE_MOVA
:
2528 return h8300_mova_length (operands
[0], operands
[1], operands
[2]);
2530 case LENGTH_TABLE_MOVA_ZERO
:
2531 return h8300_mova_length (operands
[0], operands
[1], const0_rtx
);
2533 case LENGTH_TABLE_UNARY
:
2534 return h8300_unary_length (operands
[0]);
2536 case LENGTH_TABLE_MOV_IMM4
:
2537 return 2 + h8300_classify_operand (operands
[0], 0, 0);
2539 case LENGTH_TABLE_SHORT_IMMEDIATE
:
2540 return h8300_short_immediate_length (operands
[0]);
2542 case LENGTH_TABLE_BITFIELD
:
2543 return h8300_bitfield_length (operands
[0], operands
[1]);
2545 case LENGTH_TABLE_BITBRANCH
:
2546 return h8300_bitfield_length (operands
[1], operands
[2]) - 2;
2553 /* Return true if LHS and RHS are memory references that can be mapped
2554 to the same h8sx assembly operand. LHS appears as the destination of
2555 an instruction and RHS appears as a source.
2557 Three cases are allowed:
2559 - RHS is @+Rn or @-Rn, LHS is @Rn
2560 - RHS is @Rn, LHS is @Rn+ or @Rn-
2561 - RHS and LHS have the same address and neither has side effects. */
2564 h8sx_mergeable_memrefs_p (rtx lhs
, rtx rhs
)
2566 if (GET_CODE (rhs
) == MEM
&& GET_CODE (lhs
) == MEM
)
2568 rhs
= XEXP (rhs
, 0);
2569 lhs
= XEXP (lhs
, 0);
2571 if (GET_CODE (rhs
) == PRE_INC
|| GET_CODE (rhs
) == PRE_DEC
)
2572 return rtx_equal_p (XEXP (rhs
, 0), lhs
);
2574 if (GET_CODE (lhs
) == POST_INC
|| GET_CODE (lhs
) == POST_DEC
)
2575 return rtx_equal_p (rhs
, XEXP (lhs
, 0));
2577 if (rtx_equal_p (rhs
, lhs
))
2583 /* Return true if OPERANDS[1] can be mapped to the same assembly
2584 operand as OPERANDS[0]. */
2587 h8300_operands_match_p (rtx
*operands
)
2589 if (register_operand (operands
[0], VOIDmode
)
2590 && register_operand (operands
[1], VOIDmode
))
2593 if (h8sx_mergeable_memrefs_p (operands
[0], operands
[1]))
2599 /* Try using movmd to move LENGTH bytes from memory region SRC to memory
2600 region DEST. The two regions do not overlap and have the common
2601 alignment given by ALIGNMENT. Return true on success.
2603 Using movmd for variable-length moves seems to involve some
2604 complex trade-offs. For instance:
2606 - Preparing for a movmd instruction is similar to preparing
2607 for a memcpy. The main difference is that the arguments
2608 are moved into er4, er5 and er6 rather than er0, er1 and er2.
2610 - Since movmd clobbers the frame pointer, we need to save
2611 and restore it somehow when frame_pointer_needed. This can
2612 sometimes make movmd sequences longer than calls to memcpy().
2614 - The counter register is 16 bits, so the instruction is only
2615 suitable for variable-length moves when sizeof (size_t) == 2.
2616 That's only true in normal mode.
2618 - We will often lack static alignment information. Falling back
2619 on movmd.b would likely be slower than calling memcpy(), at least
2622 This function therefore only uses movmd when the length is a
2623 known constant, and only then if -fomit-frame-pointer is in
2624 effect or if we're not optimizing for size.
2626 At the moment the function uses movmd for all in-range constants,
2627 but it might be better to fall back on memcpy() for large moves
2628 if ALIGNMENT == 1. */
2631 h8sx_emit_movmd (rtx dest
, rtx src
, rtx length
,
2632 HOST_WIDE_INT alignment
)
2634 if (!flag_omit_frame_pointer
&& optimize_size
)
2637 if (GET_CODE (length
) == CONST_INT
)
2639 rtx dest_reg
, src_reg
, first_dest
, first_src
;
2643 /* Use movmd.l if the alignment allows it, otherwise fall back
2645 factor
= (alignment
>= 2 ? 4 : 1);
2647 /* Make sure the length is within range. We can handle counter
2648 values up to 65536, although HImode truncation will make
2649 the count appear negative in rtl dumps. */
2650 n
= INTVAL (length
);
2651 if (n
<= 0 || n
/ factor
> 65536)
2654 /* Create temporary registers for the source and destination
2655 pointers. Initialize them to the start of each region. */
2656 dest_reg
= copy_addr_to_reg (XEXP (dest
, 0));
2657 src_reg
= copy_addr_to_reg (XEXP (src
, 0));
2659 /* Create references to the movmd source and destination blocks. */
2660 first_dest
= replace_equiv_address (dest
, dest_reg
);
2661 first_src
= replace_equiv_address (src
, src_reg
);
2663 set_mem_size (first_dest
, GEN_INT (n
& -factor
));
2664 set_mem_size (first_src
, GEN_INT (n
& -factor
));
2666 length
= copy_to_mode_reg (HImode
, gen_int_mode (n
/ factor
, HImode
));
2667 emit_insn (gen_movmd (first_dest
, first_src
, length
, GEN_INT (factor
)));
2669 if ((n
& -factor
) != n
)
2671 /* Move SRC and DEST past the region we just copied.
2672 This is done to update the memory attributes. */
2673 dest
= adjust_address (dest
, BLKmode
, n
& -factor
);
2674 src
= adjust_address (src
, BLKmode
, n
& -factor
);
2676 /* Replace the addresses with the source and destination
2677 registers, which movmd has left with the right values. */
2678 dest
= replace_equiv_address (dest
, dest_reg
);
2679 src
= replace_equiv_address (src
, src_reg
);
2681 /* Mop up the left-over bytes. */
2683 emit_move_insn (adjust_address (dest
, HImode
, 0),
2684 adjust_address (src
, HImode
, 0));
2686 emit_move_insn (adjust_address (dest
, QImode
, n
& 2),
2687 adjust_address (src
, QImode
, n
& 2));
2694 /* Move ADDR into er6 after pushing its old value onto the stack. */
2697 h8300_swap_into_er6 (rtx addr
)
2699 push (HARD_FRAME_POINTER_REGNUM
);
2700 emit_move_insn (hard_frame_pointer_rtx
, addr
);
2701 if (REGNO (addr
) == SP_REG
)
2702 emit_move_insn (hard_frame_pointer_rtx
,
2703 plus_constant (hard_frame_pointer_rtx
,
2704 GET_MODE_SIZE (word_mode
)));
2707 /* Move the current value of er6 into ADDR and pop its old value
2711 h8300_swap_out_of_er6 (rtx addr
)
2713 if (REGNO (addr
) != SP_REG
)
2714 emit_move_insn (addr
, hard_frame_pointer_rtx
);
2715 pop (HARD_FRAME_POINTER_REGNUM
);
2718 /* Return the length of mov instruction. */
2721 compute_mov_length (rtx
*operands
)
2723 /* If the mov instruction involves a memory operand, we compute the
2724 length, assuming the largest addressing mode is used, and then
2725 adjust later in the function. Otherwise, we compute and return
2726 the exact length in one step. */
2727 enum machine_mode mode
= GET_MODE (operands
[0]);
2728 rtx dest
= operands
[0];
2729 rtx src
= operands
[1];
2732 if (GET_CODE (src
) == MEM
)
2733 addr
= XEXP (src
, 0);
2734 else if (GET_CODE (dest
) == MEM
)
2735 addr
= XEXP (dest
, 0);
2741 unsigned int base_length
;
2746 if (addr
== NULL_RTX
)
2749 /* The eightbit addressing is available only in QImode, so
2750 go ahead and take care of it. */
2751 if (h8300_eightbit_constant_address_p (addr
))
2758 if (addr
== NULL_RTX
)
2763 if (src
== const0_rtx
)
2773 if (addr
== NULL_RTX
)
2778 if (GET_CODE (src
) == CONST_INT
)
2780 if (src
== const0_rtx
)
2783 if ((INTVAL (src
) & 0xffff) == 0)
2786 if ((INTVAL (src
) & 0xffff) == 0)
2789 if ((INTVAL (src
) & 0xffff)
2790 == ((INTVAL (src
) >> 16) & 0xffff))
2800 if (addr
== NULL_RTX
)
2805 if (CONST_DOUBLE_OK_FOR_LETTER_P (src
, 'G'))
2818 /* Adjust the length based on the addressing mode used.
2819 Specifically, we subtract the difference between the actual
2820 length and the longest one, which is @(d:16,Rs). For SImode
2821 and SFmode, we double the adjustment because two mov.w are
2822 used to do the job. */
2824 /* @Rs+ and @-Rd are 2 bytes shorter than the longest. */
2825 if (GET_CODE (addr
) == PRE_DEC
2826 || GET_CODE (addr
) == POST_INC
)
2828 if (mode
== QImode
|| mode
== HImode
)
2829 return base_length
- 2;
2831 /* In SImode and SFmode, we use two mov.w instructions, so
2832 double the adjustment. */
2833 return base_length
- 4;
2836 /* @Rs and @Rd are 2 bytes shorter than the longest. Note that
2837 in SImode and SFmode, the second mov.w involves an address
2838 with displacement, namely @(2,Rs) or @(2,Rd), so we subtract
2840 if (GET_CODE (addr
) == REG
)
2841 return base_length
- 2;
2847 unsigned int base_length
;
2852 if (addr
== NULL_RTX
)
2855 /* The eightbit addressing is available only in QImode, so
2856 go ahead and take care of it. */
2857 if (h8300_eightbit_constant_address_p (addr
))
2864 if (addr
== NULL_RTX
)
2869 if (src
== const0_rtx
)
2879 if (addr
== NULL_RTX
)
2883 if (REGNO (src
) == MAC_REG
|| REGNO (dest
) == MAC_REG
)
2889 if (GET_CODE (src
) == CONST_INT
)
2891 int val
= INTVAL (src
);
2896 if (val
== (val
& 0x00ff) || val
== (val
& 0xff00))
2899 switch (val
& 0xffffffff)
2920 if (addr
== NULL_RTX
)
2925 if (CONST_DOUBLE_OK_FOR_LETTER_P (src
, 'G'))
2938 /* Adjust the length based on the addressing mode used.
2939 Specifically, we subtract the difference between the actual
2940 length and the longest one, which is @(d:24,ERs). */
2942 /* @ERs+ and @-ERd are 6 bytes shorter than the longest. */
2943 if (GET_CODE (addr
) == PRE_DEC
2944 || GET_CODE (addr
) == POST_INC
)
2945 return base_length
- 6;
2947 /* @ERs and @ERd are 6 bytes shorter than the longest. */
2948 if (GET_CODE (addr
) == REG
)
2949 return base_length
- 6;
2951 /* @(d:16,ERs) and @(d:16,ERd) are 4 bytes shorter than the
2953 if (GET_CODE (addr
) == PLUS
2954 && GET_CODE (XEXP (addr
, 0)) == REG
2955 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
2956 && INTVAL (XEXP (addr
, 1)) > -32768
2957 && INTVAL (XEXP (addr
, 1)) < 32767)
2958 return base_length
- 4;
2960 /* @aa:16 is 4 bytes shorter than the longest. */
2961 if (h8300_tiny_constant_address_p (addr
))
2962 return base_length
- 4;
2964 /* @aa:24 is 2 bytes shorter than the longest. */
2965 if (CONSTANT_P (addr
))
2966 return base_length
- 2;
2972 /* Output an addition insn. */
2975 output_plussi (rtx
*operands
)
2977 enum machine_mode mode
= GET_MODE (operands
[0]);
2979 gcc_assert (mode
== SImode
);
2983 if (GET_CODE (operands
[2]) == REG
)
2984 return "add.w\t%f2,%f0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
2986 if (GET_CODE (operands
[2]) == CONST_INT
)
2988 HOST_WIDE_INT n
= INTVAL (operands
[2]);
2990 if ((n
& 0xffffff) == 0)
2991 return "add\t%z2,%z0";
2992 if ((n
& 0xffff) == 0)
2993 return "add\t%y2,%y0\n\taddx\t%z2,%z0";
2994 if ((n
& 0xff) == 0)
2995 return "add\t%x2,%x0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
2998 return "add\t%w2,%w0\n\taddx\t%x2,%x0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
3002 if (GET_CODE (operands
[2]) == CONST_INT
3003 && register_operand (operands
[1], VOIDmode
))
3005 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3007 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3008 return "add.l\t%S2,%S0";
3009 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3010 return "sub.l\t%G2,%S0";
3012 /* See if we can finish with 2 bytes. */
3014 switch ((unsigned int) intval
& 0xffffffff)
3019 return "adds\t%2,%S0";
3024 return "subs\t%G2,%S0";
3028 operands
[2] = GEN_INT (intval
>> 16);
3029 return "inc.w\t%2,%e0";
3033 operands
[2] = GEN_INT (intval
>> 16);
3034 return "dec.w\t%G2,%e0";
3037 /* See if we can finish with 4 bytes. */
3038 if ((intval
& 0xffff) == 0)
3040 operands
[2] = GEN_INT (intval
>> 16);
3041 return "add.w\t%2,%e0";
3045 if (GET_CODE (operands
[2]) == CONST_INT
&& INTVAL (operands
[2]) < 0)
3047 operands
[2] = GEN_INT (-INTVAL (operands
[2]));
3048 return "sub.l\t%S2,%S0";
3050 return "add.l\t%S2,%S0";
3054 /* ??? It would be much easier to add the h8sx stuff if a single function
3055 classified the addition as either inc/dec, adds/subs, add.w or add.l. */
3056 /* Compute the length of an addition insn. */
3059 compute_plussi_length (rtx
*operands
)
3061 enum machine_mode mode
= GET_MODE (operands
[0]);
3063 gcc_assert (mode
== SImode
);
3067 if (GET_CODE (operands
[2]) == REG
)
3070 if (GET_CODE (operands
[2]) == CONST_INT
)
3072 HOST_WIDE_INT n
= INTVAL (operands
[2]);
3074 if ((n
& 0xffffff) == 0)
3076 if ((n
& 0xffff) == 0)
3078 if ((n
& 0xff) == 0)
3086 if (GET_CODE (operands
[2]) == CONST_INT
3087 && register_operand (operands
[1], VOIDmode
))
3089 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3091 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3093 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3096 /* See if we can finish with 2 bytes. */
3098 switch ((unsigned int) intval
& 0xffffffff)
3119 /* See if we can finish with 4 bytes. */
3120 if ((intval
& 0xffff) == 0)
3124 if (GET_CODE (operands
[2]) == CONST_INT
&& INTVAL (operands
[2]) < 0)
3125 return h8300_length_from_table (operands
[0],
3126 GEN_INT (-INTVAL (operands
[2])),
3127 &addl_length_table
);
3129 return h8300_length_from_table (operands
[0], operands
[2],
3130 &addl_length_table
);
3135 /* Compute which flag bits are valid after an addition insn. */
3138 compute_plussi_cc (rtx
*operands
)
3140 enum machine_mode mode
= GET_MODE (operands
[0]);
3142 gcc_assert (mode
== SImode
);
3150 if (GET_CODE (operands
[2]) == CONST_INT
3151 && register_operand (operands
[1], VOIDmode
))
3153 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3155 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3157 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3160 /* See if we can finish with 2 bytes. */
3162 switch ((unsigned int) intval
& 0xffffffff)
3167 return CC_NONE_0HIT
;
3172 return CC_NONE_0HIT
;
3183 /* See if we can finish with 4 bytes. */
3184 if ((intval
& 0xffff) == 0)
3192 /* Output a logical insn. */
3195 output_logical_op (enum machine_mode mode
, rtx
*operands
)
3197 /* Figure out the logical op that we need to perform. */
3198 enum rtx_code code
= GET_CODE (operands
[3]);
3199 /* Pretend that every byte is affected if both operands are registers. */
3200 const unsigned HOST_WIDE_INT intval
=
3201 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3202 /* Always use the full instruction if the
3203 first operand is in memory. It is better
3204 to use define_splits to generate the shorter
3205 sequence where valid. */
3206 && register_operand (operands
[1], VOIDmode
)
3207 ? INTVAL (operands
[2]) : 0x55555555);
3208 /* The determinant of the algorithm. If we perform an AND, 0
3209 affects a bit. Otherwise, 1 affects a bit. */
3210 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3211 /* Break up DET into pieces. */
3212 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3213 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3214 const unsigned HOST_WIDE_INT b2
= (det
>> 16) & 0xff;
3215 const unsigned HOST_WIDE_INT b3
= (det
>> 24) & 0xff;
3216 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3217 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3218 int lower_half_easy_p
= 0;
3219 int upper_half_easy_p
= 0;
3220 /* The name of an insn. */
3242 /* First, see if we can finish with one insn. */
3243 if ((TARGET_H8300H
|| TARGET_H8300S
)
3247 sprintf (insn_buf
, "%s.w\t%%T2,%%T0", opname
);
3248 output_asm_insn (insn_buf
, operands
);
3252 /* Take care of the lower byte. */
3255 sprintf (insn_buf
, "%s\t%%s2,%%s0", opname
);
3256 output_asm_insn (insn_buf
, operands
);
3258 /* Take care of the upper byte. */
3261 sprintf (insn_buf
, "%s\t%%t2,%%t0", opname
);
3262 output_asm_insn (insn_buf
, operands
);
3267 if (TARGET_H8300H
|| TARGET_H8300S
)
3269 /* Determine if the lower half can be taken care of in no more
3271 lower_half_easy_p
= (b0
== 0
3273 || (code
!= IOR
&& w0
== 0xffff));
3275 /* Determine if the upper half can be taken care of in no more
3277 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3278 || (code
== AND
&& w1
== 0xff00));
3281 /* Check if doing everything with one insn is no worse than
3282 using multiple insns. */
3283 if ((TARGET_H8300H
|| TARGET_H8300S
)
3284 && w0
!= 0 && w1
!= 0
3285 && !(lower_half_easy_p
&& upper_half_easy_p
)
3286 && !(code
== IOR
&& w1
== 0xffff
3287 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3289 sprintf (insn_buf
, "%s.l\t%%S2,%%S0", opname
);
3290 output_asm_insn (insn_buf
, operands
);
3294 /* Take care of the lower and upper words individually. For
3295 each word, we try different methods in the order of
3297 1) the special insn (in case of AND or XOR),
3298 2) the word-wise insn, and
3299 3) The byte-wise insn. */
3301 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3302 output_asm_insn ((code
== AND
)
3303 ? "sub.w\t%f0,%f0" : "not.w\t%f0",
3305 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3309 sprintf (insn_buf
, "%s.w\t%%f2,%%f0", opname
);
3310 output_asm_insn (insn_buf
, operands
);
3316 sprintf (insn_buf
, "%s\t%%w2,%%w0", opname
);
3317 output_asm_insn (insn_buf
, operands
);
3321 sprintf (insn_buf
, "%s\t%%x2,%%x0", opname
);
3322 output_asm_insn (insn_buf
, operands
);
3327 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3328 output_asm_insn ((code
== AND
)
3329 ? "sub.w\t%e0,%e0" : "not.w\t%e0",
3331 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3334 && (w0
& 0x8000) != 0)
3336 output_asm_insn ("exts.l\t%S0", operands
);
3338 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3342 output_asm_insn ("extu.w\t%e0", operands
);
3344 else if (TARGET_H8300H
|| TARGET_H8300S
)
3348 sprintf (insn_buf
, "%s.w\t%%e2,%%e0", opname
);
3349 output_asm_insn (insn_buf
, operands
);
3356 sprintf (insn_buf
, "%s\t%%y2,%%y0", opname
);
3357 output_asm_insn (insn_buf
, operands
);
3361 sprintf (insn_buf
, "%s\t%%z2,%%z0", opname
);
3362 output_asm_insn (insn_buf
, operands
);
3373 /* Compute the length of a logical insn. */
3376 compute_logical_op_length (enum machine_mode mode
, rtx
*operands
)
3378 /* Figure out the logical op that we need to perform. */
3379 enum rtx_code code
= GET_CODE (operands
[3]);
3380 /* Pretend that every byte is affected if both operands are registers. */
3381 const unsigned HOST_WIDE_INT intval
=
3382 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3383 /* Always use the full instruction if the
3384 first operand is in memory. It is better
3385 to use define_splits to generate the shorter
3386 sequence where valid. */
3387 && register_operand (operands
[1], VOIDmode
)
3388 ? INTVAL (operands
[2]) : 0x55555555);
3389 /* The determinant of the algorithm. If we perform an AND, 0
3390 affects a bit. Otherwise, 1 affects a bit. */
3391 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3392 /* Break up DET into pieces. */
3393 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3394 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3395 const unsigned HOST_WIDE_INT b2
= (det
>> 16) & 0xff;
3396 const unsigned HOST_WIDE_INT b3
= (det
>> 24) & 0xff;
3397 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3398 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3399 int lower_half_easy_p
= 0;
3400 int upper_half_easy_p
= 0;
3402 unsigned int length
= 0;
3407 /* First, see if we can finish with one insn. */
3408 if ((TARGET_H8300H
|| TARGET_H8300S
)
3412 length
= h8300_length_from_table (operands
[1], operands
[2],
3413 &logicw_length_table
);
3417 /* Take care of the lower byte. */
3421 /* Take care of the upper byte. */
3427 if (TARGET_H8300H
|| TARGET_H8300S
)
3429 /* Determine if the lower half can be taken care of in no more
3431 lower_half_easy_p
= (b0
== 0
3433 || (code
!= IOR
&& w0
== 0xffff));
3435 /* Determine if the upper half can be taken care of in no more
3437 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3438 || (code
== AND
&& w1
== 0xff00));
3441 /* Check if doing everything with one insn is no worse than
3442 using multiple insns. */
3443 if ((TARGET_H8300H
|| TARGET_H8300S
)
3444 && w0
!= 0 && w1
!= 0
3445 && !(lower_half_easy_p
&& upper_half_easy_p
)
3446 && !(code
== IOR
&& w1
== 0xffff
3447 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3449 length
= h8300_length_from_table (operands
[1], operands
[2],
3450 &logicl_length_table
);
3454 /* Take care of the lower and upper words individually. For
3455 each word, we try different methods in the order of
3457 1) the special insn (in case of AND or XOR),
3458 2) the word-wise insn, and
3459 3) The byte-wise insn. */
3461 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3465 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3481 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3485 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3488 && (w0
& 0x8000) != 0)
3492 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3498 else if (TARGET_H8300H
|| TARGET_H8300S
)
3519 /* Compute which flag bits are valid after a logical insn. */
3522 compute_logical_op_cc (enum machine_mode mode
, rtx
*operands
)
3524 /* Figure out the logical op that we need to perform. */
3525 enum rtx_code code
= GET_CODE (operands
[3]);
3526 /* Pretend that every byte is affected if both operands are registers. */
3527 const unsigned HOST_WIDE_INT intval
=
3528 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3529 /* Always use the full instruction if the
3530 first operand is in memory. It is better
3531 to use define_splits to generate the shorter
3532 sequence where valid. */
3533 && register_operand (operands
[1], VOIDmode
)
3534 ? INTVAL (operands
[2]) : 0x55555555);
3535 /* The determinant of the algorithm. If we perform an AND, 0
3536 affects a bit. Otherwise, 1 affects a bit. */
3537 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3538 /* Break up DET into pieces. */
3539 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3540 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3541 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3542 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3543 int lower_half_easy_p
= 0;
3544 int upper_half_easy_p
= 0;
3545 /* Condition code. */
3546 enum attr_cc cc
= CC_CLOBBER
;
3551 /* First, see if we can finish with one insn. */
3552 if ((TARGET_H8300H
|| TARGET_H8300S
)
3560 if (TARGET_H8300H
|| TARGET_H8300S
)
3562 /* Determine if the lower half can be taken care of in no more
3564 lower_half_easy_p
= (b0
== 0
3566 || (code
!= IOR
&& w0
== 0xffff));
3568 /* Determine if the upper half can be taken care of in no more
3570 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3571 || (code
== AND
&& w1
== 0xff00));
3574 /* Check if doing everything with one insn is no worse than
3575 using multiple insns. */
3576 if ((TARGET_H8300H
|| TARGET_H8300S
)
3577 && w0
!= 0 && w1
!= 0
3578 && !(lower_half_easy_p
&& upper_half_easy_p
)
3579 && !(code
== IOR
&& w1
== 0xffff
3580 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3586 if ((TARGET_H8300H
|| TARGET_H8300S
)
3589 && (w0
& 0x8000) != 0)
3601 /* Expand a conditional branch. */
3604 h8300_expand_branch (rtx operands
[])
3606 enum rtx_code code
= GET_CODE (operands
[0]);
3607 rtx op0
= operands
[1];
3608 rtx op1
= operands
[2];
3609 rtx label
= operands
[3];
3612 tmp
= gen_rtx_COMPARE (VOIDmode
, op0
, op1
);
3613 emit_insn (gen_rtx_SET (VOIDmode
, cc0_rtx
, tmp
));
3615 tmp
= gen_rtx_fmt_ee (code
, VOIDmode
, cc0_rtx
, const0_rtx
);
3616 tmp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, tmp
,
3617 gen_rtx_LABEL_REF (VOIDmode
, label
),
3619 emit_jump_insn (gen_rtx_SET (VOIDmode
, pc_rtx
, tmp
));
3623 /* Expand a conditional store. */
3626 h8300_expand_store (rtx operands
[])
3628 rtx dest
= operands
[0];
3629 enum rtx_code code
= GET_CODE (operands
[1]);
3630 rtx op0
= operands
[2];
3631 rtx op1
= operands
[3];
3634 tmp
= gen_rtx_COMPARE (VOIDmode
, op0
, op1
);
3635 emit_insn (gen_rtx_SET (VOIDmode
, cc0_rtx
, tmp
));
3637 tmp
= gen_rtx_fmt_ee (code
, GET_MODE (dest
), cc0_rtx
, const0_rtx
);
3638 emit_insn (gen_rtx_SET (VOIDmode
, dest
, tmp
));
3643 We devote a fair bit of code to getting efficient shifts since we
3644 can only shift one bit at a time on the H8/300 and H8/300H and only
3645 one or two bits at a time on the H8S.
3647 All shift code falls into one of the following ways of
3650 o SHIFT_INLINE: Emit straight line code for the shift; this is used
3651 when a straight line shift is about the same size or smaller than
3654 o SHIFT_ROT_AND: Rotate the value the opposite direction, then mask
3655 off the bits we don't need. This is used when only a few of the
3656 bits in the original value will survive in the shifted value.
3658 o SHIFT_SPECIAL: Often it's possible to move a byte or a word to
3659 simulate a shift by 8, 16, or 24 bits. Once moved, a few inline
3660 shifts can be added if the shift count is slightly more than 8 or
3661 16. This case also includes other oddballs that are not worth
3664 o SHIFT_LOOP: Emit a loop using one (or two on H8S) bit shifts.
3666 For each shift count, we try to use code that has no trade-off
3667 between code size and speed whenever possible.
3669 If the trade-off is unavoidable, we try to be reasonable.
3670 Specifically, the fastest version is one instruction longer than
3671 the shortest version, we take the fastest version. We also provide
3672 the use a way to switch back to the shortest version with -Os.
3674 For the details of the shift algorithms for various shift counts,
3675 refer to shift_alg_[qhs]i. */
3677 /* Classify a shift with the given mode and code. OP is the shift amount. */
3679 enum h8sx_shift_type
3680 h8sx_classify_shift (enum machine_mode mode
, enum rtx_code code
, rtx op
)
3682 if (!TARGET_H8300SX
)
3683 return H8SX_SHIFT_NONE
;
3689 /* Check for variable shifts (shll Rs,Rd and shlr Rs,Rd). */
3690 if (GET_CODE (op
) != CONST_INT
)
3691 return H8SX_SHIFT_BINARY
;
3693 /* Reject out-of-range shift amounts. */
3694 if (INTVAL (op
) <= 0 || INTVAL (op
) >= GET_MODE_BITSIZE (mode
))
3695 return H8SX_SHIFT_NONE
;
3697 /* Power-of-2 shifts are effectively unary operations. */
3698 if (exact_log2 (INTVAL (op
)) >= 0)
3699 return H8SX_SHIFT_UNARY
;
3701 return H8SX_SHIFT_BINARY
;
3704 if (op
== const1_rtx
|| op
== const2_rtx
)
3705 return H8SX_SHIFT_UNARY
;
3706 return H8SX_SHIFT_NONE
;
3709 if (GET_CODE (op
) == CONST_INT
3710 && (INTVAL (op
) == 1
3712 || INTVAL (op
) == GET_MODE_BITSIZE (mode
) - 2
3713 || INTVAL (op
) == GET_MODE_BITSIZE (mode
) - 1))
3714 return H8SX_SHIFT_UNARY
;
3715 return H8SX_SHIFT_NONE
;
3718 return H8SX_SHIFT_NONE
;
3722 /* Return the asm template for a single h8sx shift instruction.
3723 OPERANDS[0] and OPERANDS[1] are the destination, OPERANDS[2]
3724 is the source and OPERANDS[3] is the shift. SUFFIX is the
3725 size suffix ('b', 'w' or 'l') and OPTYPE is the print_operand
3726 prefix for the destination operand. */
3729 output_h8sx_shift (rtx
*operands
, int suffix
, int optype
)
3731 static char buffer
[16];
3734 switch (GET_CODE (operands
[3]))
3750 if (INTVAL (operands
[2]) > 2)
3752 /* This is really a right rotate. */
3753 operands
[2] = GEN_INT (GET_MODE_BITSIZE (GET_MODE (operands
[0]))
3754 - INTVAL (operands
[2]));
3762 if (operands
[2] == const1_rtx
)
3763 sprintf (buffer
, "%s.%c\t%%%c0", stem
, suffix
, optype
);
3765 sprintf (buffer
, "%s.%c\t%%X2,%%%c0", stem
, suffix
, optype
);
3769 /* Emit code to do shifts. */
3772 expand_a_shift (enum machine_mode mode
, int code
, rtx operands
[])
3774 switch (h8sx_classify_shift (mode
, code
, operands
[2]))
3776 case H8SX_SHIFT_BINARY
:
3777 operands
[1] = force_reg (mode
, operands
[1]);
3780 case H8SX_SHIFT_UNARY
:
3783 case H8SX_SHIFT_NONE
:
3787 emit_move_insn (copy_rtx (operands
[0]), operands
[1]);
3789 /* Need a loop to get all the bits we want - we generate the
3790 code at emit time, but need to allocate a scratch reg now. */
3792 emit_insn (gen_rtx_PARALLEL
3795 gen_rtx_SET (VOIDmode
, copy_rtx (operands
[0]),
3796 gen_rtx_fmt_ee (code
, mode
,
3797 copy_rtx (operands
[0]), operands
[2])),
3798 gen_rtx_CLOBBER (VOIDmode
,
3799 gen_rtx_SCRATCH (QImode
)))));
3803 /* Symbols of the various modes which can be used as indices. */
3807 QIshift
, HIshift
, SIshift
3810 /* For single bit shift insns, record assembler and what bits of the
3811 condition code are valid afterwards (represented as various CC_FOO
3812 bits, 0 means CC isn't left in a usable state). */
3816 const char *const assembler
;
3820 /* Assembler instruction shift table.
3822 These tables are used to look up the basic shifts.
3823 They are indexed by cpu, shift_type, and mode. */
3825 static const struct shift_insn shift_one
[2][3][3] =
3831 { "shll\t%X0", CC_SET_ZNV
},
3832 { "add.w\t%T0,%T0", CC_SET_ZN
},
3833 { "add.w\t%f0,%f0\n\taddx\t%y0,%y0\n\taddx\t%z0,%z0", CC_CLOBBER
}
3835 /* SHIFT_LSHIFTRT */
3837 { "shlr\t%X0", CC_SET_ZNV
},
3838 { "shlr\t%t0\n\trotxr\t%s0", CC_CLOBBER
},
3839 { "shlr\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", CC_CLOBBER
}
3841 /* SHIFT_ASHIFTRT */
3843 { "shar\t%X0", CC_SET_ZNV
},
3844 { "shar\t%t0\n\trotxr\t%s0", CC_CLOBBER
},
3845 { "shar\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", CC_CLOBBER
}
3852 { "shll.b\t%X0", CC_SET_ZNV
},
3853 { "shll.w\t%T0", CC_SET_ZNV
},
3854 { "shll.l\t%S0", CC_SET_ZNV
}
3856 /* SHIFT_LSHIFTRT */
3858 { "shlr.b\t%X0", CC_SET_ZNV
},
3859 { "shlr.w\t%T0", CC_SET_ZNV
},
3860 { "shlr.l\t%S0", CC_SET_ZNV
}
3862 /* SHIFT_ASHIFTRT */
3864 { "shar.b\t%X0", CC_SET_ZNV
},
3865 { "shar.w\t%T0", CC_SET_ZNV
},
3866 { "shar.l\t%S0", CC_SET_ZNV
}
3871 static const struct shift_insn shift_two
[3][3] =
3875 { "shll.b\t#2,%X0", CC_SET_ZNV
},
3876 { "shll.w\t#2,%T0", CC_SET_ZNV
},
3877 { "shll.l\t#2,%S0", CC_SET_ZNV
}
3879 /* SHIFT_LSHIFTRT */
3881 { "shlr.b\t#2,%X0", CC_SET_ZNV
},
3882 { "shlr.w\t#2,%T0", CC_SET_ZNV
},
3883 { "shlr.l\t#2,%S0", CC_SET_ZNV
}
3885 /* SHIFT_ASHIFTRT */
3887 { "shar.b\t#2,%X0", CC_SET_ZNV
},
3888 { "shar.w\t#2,%T0", CC_SET_ZNV
},
3889 { "shar.l\t#2,%S0", CC_SET_ZNV
}
3893 /* Rotates are organized by which shift they'll be used in implementing.
3894 There's no need to record whether the cc is valid afterwards because
3895 it is the AND insn that will decide this. */
3897 static const char *const rotate_one
[2][3][3] =
3904 "shlr\t%t0\n\trotxr\t%s0\n\tbst\t#7,%t0",
3907 /* SHIFT_LSHIFTRT */
3910 "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
3913 /* SHIFT_ASHIFTRT */
3916 "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
3928 /* SHIFT_LSHIFTRT */
3934 /* SHIFT_ASHIFTRT */
3943 static const char *const rotate_two
[3][3] =
3951 /* SHIFT_LSHIFTRT */
3957 /* SHIFT_ASHIFTRT */
3966 /* Shift algorithm. */
3969 /* The number of bits to be shifted by shift1 and shift2. Valid
3970 when ALG is SHIFT_SPECIAL. */
3971 unsigned int remainder
;
3973 /* Special insn for a shift. Valid when ALG is SHIFT_SPECIAL. */
3974 const char *special
;
3976 /* Insn for a one-bit shift. Valid when ALG is either SHIFT_INLINE
3977 or SHIFT_SPECIAL, and REMAINDER is nonzero. */
3980 /* Insn for a two-bit shift. Valid when ALG is either SHIFT_INLINE
3981 or SHIFT_SPECIAL, and REMAINDER is nonzero. */
3984 /* CC status for SHIFT_INLINE. */
3987 /* CC status for SHIFT_SPECIAL. */
3991 static void get_shift_alg (enum shift_type
,
3992 enum shift_mode
, unsigned int,
3993 struct shift_info
*);
3995 /* Given SHIFT_TYPE, SHIFT_MODE, and shift count COUNT, determine the
3996 best algorithm for doing the shift. The assembler code is stored
3997 in the pointers in INFO. We achieve the maximum efficiency in most
3998 cases when !TARGET_H8300. In case of TARGET_H8300, shifts in
3999 SImode in particular have a lot of room to optimize.
4001 We first determine the strategy of the shift algorithm by a table
4002 lookup. If that tells us to use a hand crafted assembly code, we
4003 go into the big switch statement to find what that is. Otherwise,
4004 we resort to a generic way, such as inlining. In either case, the
4005 result is returned through INFO. */
4008 get_shift_alg (enum shift_type shift_type
, enum shift_mode shift_mode
,
4009 unsigned int count
, struct shift_info
*info
)
4013 /* Find the target CPU. */
4016 else if (TARGET_H8300H
)
4021 /* Find the shift algorithm. */
4022 info
->alg
= SHIFT_LOOP
;
4026 if (count
< GET_MODE_BITSIZE (QImode
))
4027 info
->alg
= shift_alg_qi
[cpu
][shift_type
][count
];
4031 if (count
< GET_MODE_BITSIZE (HImode
))
4032 info
->alg
= shift_alg_hi
[cpu
][shift_type
][count
];
4036 if (count
< GET_MODE_BITSIZE (SImode
))
4037 info
->alg
= shift_alg_si
[cpu
][shift_type
][count
];
4044 /* Fill in INFO. Return unless we have SHIFT_SPECIAL. */
4048 info
->remainder
= count
;
4052 /* It is up to the caller to know that looping clobbers cc. */
4053 info
->shift1
= shift_one
[cpu_type
][shift_type
][shift_mode
].assembler
;
4054 info
->shift2
= shift_two
[shift_type
][shift_mode
].assembler
;
4055 info
->cc_inline
= shift_one
[cpu_type
][shift_type
][shift_mode
].cc_valid
;
4059 info
->shift1
= rotate_one
[cpu_type
][shift_type
][shift_mode
];
4060 info
->shift2
= rotate_two
[shift_type
][shift_mode
];
4061 info
->cc_inline
= CC_CLOBBER
;
4065 /* REMAINDER is 0 for most cases, so initialize it to 0. */
4066 info
->remainder
= 0;
4067 info
->shift1
= shift_one
[cpu_type
][shift_type
][shift_mode
].assembler
;
4068 info
->shift2
= shift_two
[shift_type
][shift_mode
].assembler
;
4069 info
->cc_inline
= shift_one
[cpu_type
][shift_type
][shift_mode
].cc_valid
;
4070 info
->cc_special
= CC_CLOBBER
;
4074 /* Here we only deal with SHIFT_SPECIAL. */
4078 /* For ASHIFTRT by 7 bits, the sign bit is simply replicated
4079 through the entire value. */
4080 gcc_assert (shift_type
== SHIFT_ASHIFTRT
&& count
== 7);
4081 info
->special
= "shll\t%X0\n\tsubx\t%X0,%X0";
4091 info
->special
= "shar.b\t%t0\n\tmov.b\t%s0,%t0\n\trotxr.b\t%t0\n\trotr.b\t%s0\n\tand.b\t#0x80,%s0";
4093 info
->special
= "shar.b\t%t0\n\tmov.b\t%s0,%t0\n\trotxr.w\t%T0\n\tand.b\t#0x80,%s0";
4095 case SHIFT_LSHIFTRT
:
4097 info
->special
= "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.b\t%s0\n\trotl.b\t%t0\n\tand.b\t#0x01,%t0";
4099 info
->special
= "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.w\t%T0\n\tand.b\t#0x01,%t0";
4101 case SHIFT_ASHIFTRT
:
4102 info
->special
= "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.b\t%s0\n\tsubx\t%t0,%t0";
4106 else if ((8 <= count
&& count
<= 13)
4107 || (TARGET_H8300S
&& count
== 14))
4109 info
->remainder
= count
- 8;
4114 info
->special
= "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0";
4116 case SHIFT_LSHIFTRT
:
4119 info
->special
= "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0";
4120 info
->shift1
= "shlr.b\t%s0";
4121 info
->cc_inline
= CC_SET_ZNV
;
4125 info
->special
= "mov.b\t%t0,%s0\n\textu.w\t%T0";
4126 info
->cc_special
= CC_SET_ZNV
;
4129 case SHIFT_ASHIFTRT
:
4132 info
->special
= "mov.b\t%t0,%s0\n\tbld\t#7,%s0\n\tsubx\t%t0,%t0";
4133 info
->shift1
= "shar.b\t%s0";
4137 info
->special
= "mov.b\t%t0,%s0\n\texts.w\t%T0";
4138 info
->cc_special
= CC_SET_ZNV
;
4143 else if (count
== 14)
4149 info
->special
= "mov.b\t%s0,%t0\n\trotr.b\t%t0\n\trotr.b\t%t0\n\tand.b\t#0xC0,%t0\n\tsub.b\t%s0,%s0";
4151 case SHIFT_LSHIFTRT
:
4153 info
->special
= "mov.b\t%t0,%s0\n\trotl.b\t%s0\n\trotl.b\t%s0\n\tand.b\t#3,%s0\n\tsub.b\t%t0,%t0";
4155 case SHIFT_ASHIFTRT
:
4157 info
->special
= "mov.b\t%t0,%s0\n\tshll.b\t%s0\n\tsubx.b\t%t0,%t0\n\tshll.b\t%s0\n\tmov.b\t%t0,%s0\n\tbst.b\t#0,%s0";
4158 else if (TARGET_H8300H
)
4160 info
->special
= "shll.b\t%t0\n\tsubx.b\t%s0,%s0\n\tshll.b\t%t0\n\trotxl.b\t%s0\n\texts.w\t%T0";
4161 info
->cc_special
= CC_SET_ZNV
;
4163 else /* TARGET_H8300S */
4168 else if (count
== 15)
4173 info
->special
= "bld\t#0,%s0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#7,%t0";
4175 case SHIFT_LSHIFTRT
:
4176 info
->special
= "bld\t#7,%t0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#0,%s0";
4178 case SHIFT_ASHIFTRT
:
4179 info
->special
= "shll\t%t0\n\tsubx\t%t0,%t0\n\tmov.b\t%t0,%s0";
4186 if (TARGET_H8300
&& 8 <= count
&& count
<= 9)
4188 info
->remainder
= count
- 8;
4193 info
->special
= "mov.b\t%y0,%z0\n\tmov.b\t%x0,%y0\n\tmov.b\t%w0,%x0\n\tsub.b\t%w0,%w0";
4195 case SHIFT_LSHIFTRT
:
4196 info
->special
= "mov.b\t%x0,%w0\n\tmov.b\t%y0,%x0\n\tmov.b\t%z0,%y0\n\tsub.b\t%z0,%z0";
4197 info
->shift1
= "shlr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0";
4199 case SHIFT_ASHIFTRT
:
4200 info
->special
= "mov.b\t%x0,%w0\n\tmov.b\t%y0,%x0\n\tmov.b\t%z0,%y0\n\tshll\t%z0\n\tsubx\t%z0,%z0";
4204 else if (count
== 8 && !TARGET_H8300
)
4209 info
->special
= "mov.w\t%e0,%f4\n\tmov.b\t%s4,%t4\n\tmov.b\t%t0,%s4\n\tmov.b\t%s0,%t0\n\tsub.b\t%s0,%s0\n\tmov.w\t%f4,%e0";
4211 case SHIFT_LSHIFTRT
:
4212 info
->special
= "mov.w\t%e0,%f4\n\tmov.b\t%t0,%s0\n\tmov.b\t%s4,%t0\n\tmov.b\t%t4,%s4\n\textu.w\t%f4\n\tmov.w\t%f4,%e0";
4214 case SHIFT_ASHIFTRT
:
4215 info
->special
= "mov.w\t%e0,%f4\n\tmov.b\t%t0,%s0\n\tmov.b\t%s4,%t0\n\tmov.b\t%t4,%s4\n\texts.w\t%f4\n\tmov.w\t%f4,%e0";
4219 else if (count
== 15 && TARGET_H8300
)
4225 case SHIFT_LSHIFTRT
:
4226 info
->special
= "bld\t#7,%z0\n\tmov.w\t%e0,%f0\n\txor\t%y0,%y0\n\txor\t%z0,%z0\n\trotxl\t%w0\n\trotxl\t%x0\n\trotxl\t%y0";
4228 case SHIFT_ASHIFTRT
:
4229 info
->special
= "bld\t#7,%z0\n\tmov.w\t%e0,%f0\n\trotxl\t%w0\n\trotxl\t%x0\n\tsubx\t%y0,%y0\n\tsubx\t%z0,%z0";
4233 else if (count
== 15 && !TARGET_H8300
)
4238 info
->special
= "shlr.w\t%e0\n\tmov.w\t%f0,%e0\n\txor.w\t%f0,%f0\n\trotxr.l\t%S0";
4239 info
->cc_special
= CC_SET_ZNV
;
4241 case SHIFT_LSHIFTRT
:
4242 info
->special
= "shll.w\t%f0\n\tmov.w\t%e0,%f0\n\txor.w\t%e0,%e0\n\trotxl.l\t%S0";
4243 info
->cc_special
= CC_SET_ZNV
;
4245 case SHIFT_ASHIFTRT
:
4249 else if ((TARGET_H8300
&& 16 <= count
&& count
<= 20)
4250 || (TARGET_H8300H
&& 16 <= count
&& count
<= 19)
4251 || (TARGET_H8300S
&& 16 <= count
&& count
<= 21))
4253 info
->remainder
= count
- 16;
4258 info
->special
= "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0";
4260 info
->shift1
= "add.w\t%e0,%e0";
4262 case SHIFT_LSHIFTRT
:
4265 info
->special
= "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0";
4266 info
->shift1
= "shlr\t%x0\n\trotxr\t%w0";
4270 info
->special
= "mov.w\t%e0,%f0\n\textu.l\t%S0";
4271 info
->cc_special
= CC_SET_ZNV
;
4274 case SHIFT_ASHIFTRT
:
4277 info
->special
= "mov.w\t%e0,%f0\n\tshll\t%z0\n\tsubx\t%z0,%z0\n\tmov.b\t%z0,%y0";
4278 info
->shift1
= "shar\t%x0\n\trotxr\t%w0";
4282 info
->special
= "mov.w\t%e0,%f0\n\texts.l\t%S0";
4283 info
->cc_special
= CC_SET_ZNV
;
4288 else if (TARGET_H8300
&& 24 <= count
&& count
<= 28)
4290 info
->remainder
= count
- 24;
4295 info
->special
= "mov.b\t%w0,%z0\n\tsub.b\t%y0,%y0\n\tsub.w\t%f0,%f0";
4296 info
->shift1
= "shll.b\t%z0";
4297 info
->cc_inline
= CC_SET_ZNV
;
4299 case SHIFT_LSHIFTRT
:
4300 info
->special
= "mov.b\t%z0,%w0\n\tsub.b\t%x0,%x0\n\tsub.w\t%e0,%e0";
4301 info
->shift1
= "shlr.b\t%w0";
4302 info
->cc_inline
= CC_SET_ZNV
;
4304 case SHIFT_ASHIFTRT
:
4305 info
->special
= "mov.b\t%z0,%w0\n\tbld\t#7,%w0\n\tsubx\t%x0,%x0\n\tsubx\t%x0,%x0\n\tsubx\t%x0,%x0";
4306 info
->shift1
= "shar.b\t%w0";
4307 info
->cc_inline
= CC_SET_ZNV
;
4311 else if ((TARGET_H8300H
&& count
== 24)
4312 || (TARGET_H8300S
&& 24 <= count
&& count
<= 25))
4314 info
->remainder
= count
- 24;
4319 info
->special
= "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0\n\tmov.w\t%f0,%e0\n\tsub.w\t%f0,%f0";
4321 case SHIFT_LSHIFTRT
:
4322 info
->special
= "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\textu.w\t%f0\n\textu.l\t%S0";
4323 info
->cc_special
= CC_SET_ZNV
;
4325 case SHIFT_ASHIFTRT
:
4326 info
->special
= "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\texts.w\t%f0\n\texts.l\t%S0";
4327 info
->cc_special
= CC_SET_ZNV
;
4331 else if (!TARGET_H8300
&& count
== 28)
4337 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t%S0\n\trotr.l\t%S0\n\trotr.l\t%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
4339 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\trotr.l\t#2,%S0\n\tsub.w\t%f0,%f0";
4341 case SHIFT_LSHIFTRT
:
4344 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t%S0\n\trotl.l\t%S0\n\trotl.l\t%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
4345 info
->cc_special
= CC_SET_ZNV
;
4348 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t#2,%S0\n\textu.l\t%S0";
4350 case SHIFT_ASHIFTRT
:
4354 else if (!TARGET_H8300
&& count
== 29)
4360 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t%S0\n\trotr.l\t%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
4362 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
4364 case SHIFT_LSHIFTRT
:
4367 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t%S0\n\trotl.l\t%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
4368 info
->cc_special
= CC_SET_ZNV
;
4372 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
4373 info
->cc_special
= CC_SET_ZNV
;
4376 case SHIFT_ASHIFTRT
:
4380 else if (!TARGET_H8300
&& count
== 30)
4386 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
4388 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\tsub.w\t%f0,%f0";
4390 case SHIFT_LSHIFTRT
:
4392 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
4394 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\textu.l\t%S0";
4396 case SHIFT_ASHIFTRT
:
4400 else if (count
== 31)
4407 info
->special
= "sub.w\t%e0,%e0\n\tshlr\t%w0\n\tmov.w\t%e0,%f0\n\trotxr\t%z0";
4409 case SHIFT_LSHIFTRT
:
4410 info
->special
= "sub.w\t%f0,%f0\n\tshll\t%z0\n\tmov.w\t%f0,%e0\n\trotxl\t%w0";
4412 case SHIFT_ASHIFTRT
:
4413 info
->special
= "shll\t%z0\n\tsubx\t%w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
4422 info
->special
= "shlr.l\t%S0\n\txor.l\t%S0,%S0\n\trotxr.l\t%S0";
4423 info
->cc_special
= CC_SET_ZNV
;
4425 case SHIFT_LSHIFTRT
:
4426 info
->special
= "shll.l\t%S0\n\txor.l\t%S0,%S0\n\trotxl.l\t%S0";
4427 info
->cc_special
= CC_SET_ZNV
;
4429 case SHIFT_ASHIFTRT
:
4430 info
->special
= "shll\t%e0\n\tsubx\t%w0,%w0\n\texts.w\t%T0\n\texts.l\t%S0";
4431 info
->cc_special
= CC_SET_ZNV
;
4444 info
->shift2
= NULL
;
4447 /* Given COUNT and MODE of a shift, return 1 if a scratch reg may be
4448 needed for some shift with COUNT and MODE. Return 0 otherwise. */
4451 h8300_shift_needs_scratch_p (int count
, enum machine_mode mode
)
4456 if (GET_MODE_BITSIZE (mode
) <= count
)
4459 /* Find out the target CPU. */
4462 else if (TARGET_H8300H
)
4467 /* Find the shift algorithm. */
4471 a
= shift_alg_qi
[cpu
][SHIFT_ASHIFT
][count
];
4472 lr
= shift_alg_qi
[cpu
][SHIFT_LSHIFTRT
][count
];
4473 ar
= shift_alg_qi
[cpu
][SHIFT_ASHIFTRT
][count
];
4477 a
= shift_alg_hi
[cpu
][SHIFT_ASHIFT
][count
];
4478 lr
= shift_alg_hi
[cpu
][SHIFT_LSHIFTRT
][count
];
4479 ar
= shift_alg_hi
[cpu
][SHIFT_ASHIFTRT
][count
];
4483 a
= shift_alg_si
[cpu
][SHIFT_ASHIFT
][count
];
4484 lr
= shift_alg_si
[cpu
][SHIFT_LSHIFTRT
][count
];
4485 ar
= shift_alg_si
[cpu
][SHIFT_ASHIFTRT
][count
];
4492 /* On H8/300H, count == 8 uses a scratch register. */
4493 return (a
== SHIFT_LOOP
|| lr
== SHIFT_LOOP
|| ar
== SHIFT_LOOP
4494 || (TARGET_H8300H
&& mode
== SImode
&& count
== 8));
4497 /* Output the assembler code for doing shifts. */
4500 output_a_shift (rtx
*operands
)
4502 static int loopend_lab
;
4503 rtx shift
= operands
[3];
4504 enum machine_mode mode
= GET_MODE (shift
);
4505 enum rtx_code code
= GET_CODE (shift
);
4506 enum shift_type shift_type
;
4507 enum shift_mode shift_mode
;
4508 struct shift_info info
;
4516 shift_mode
= QIshift
;
4519 shift_mode
= HIshift
;
4522 shift_mode
= SIshift
;
4531 shift_type
= SHIFT_ASHIFTRT
;
4534 shift_type
= SHIFT_LSHIFTRT
;
4537 shift_type
= SHIFT_ASHIFT
;
4543 /* This case must be taken care of by one of the two splitters
4544 that convert a variable shift into a loop. */
4545 gcc_assert (GET_CODE (operands
[2]) == CONST_INT
);
4547 n
= INTVAL (operands
[2]);
4549 /* If the count is negative, make it 0. */
4552 /* If the count is too big, truncate it.
4553 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4554 do the intuitive thing. */
4555 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4556 n
= GET_MODE_BITSIZE (mode
);
4558 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4563 output_asm_insn (info
.special
, operands
);
4569 /* Emit two bit shifts first. */
4570 if (info
.shift2
!= NULL
)
4572 for (; n
> 1; n
-= 2)
4573 output_asm_insn (info
.shift2
, operands
);
4576 /* Now emit one bit shifts for any residual. */
4578 output_asm_insn (info
.shift1
, operands
);
4583 int m
= GET_MODE_BITSIZE (mode
) - n
;
4584 const int mask
= (shift_type
== SHIFT_ASHIFT
4585 ? ((1 << m
) - 1) << n
4589 /* Not all possibilities of rotate are supported. They shouldn't
4590 be generated, but let's watch for 'em. */
4591 gcc_assert (info
.shift1
);
4593 /* Emit two bit rotates first. */
4594 if (info
.shift2
!= NULL
)
4596 for (; m
> 1; m
-= 2)
4597 output_asm_insn (info
.shift2
, operands
);
4600 /* Now single bit rotates for any residual. */
4602 output_asm_insn (info
.shift1
, operands
);
4604 /* Now mask off the high bits. */
4608 sprintf (insn_buf
, "and\t#%d,%%X0", mask
);
4612 gcc_assert (TARGET_H8300H
|| TARGET_H8300S
);
4613 sprintf (insn_buf
, "and.w\t#%d,%%T0", mask
);
4620 output_asm_insn (insn_buf
, operands
);
4625 /* A loop to shift by a "large" constant value.
4626 If we have shift-by-2 insns, use them. */
4627 if (info
.shift2
!= NULL
)
4629 fprintf (asm_out_file
, "\tmov.b #%d,%sl\n", n
/ 2,
4630 names_big
[REGNO (operands
[4])]);
4631 fprintf (asm_out_file
, ".Llt%d:\n", loopend_lab
);
4632 output_asm_insn (info
.shift2
, operands
);
4633 output_asm_insn ("add #0xff,%X4", operands
);
4634 fprintf (asm_out_file
, "\tbne .Llt%d\n", loopend_lab
);
4636 output_asm_insn (info
.shift1
, operands
);
4640 fprintf (asm_out_file
, "\tmov.b #%d,%sl\n", n
,
4641 names_big
[REGNO (operands
[4])]);
4642 fprintf (asm_out_file
, ".Llt%d:\n", loopend_lab
);
4643 output_asm_insn (info
.shift1
, operands
);
4644 output_asm_insn ("add #0xff,%X4", operands
);
4645 fprintf (asm_out_file
, "\tbne .Llt%d\n", loopend_lab
);
4654 /* Count the number of assembly instructions in a string TEMPL. */
4657 h8300_asm_insn_count (const char *templ
)
4659 unsigned int count
= 1;
4661 for (; *templ
; templ
++)
4668 /* Compute the length of a shift insn. */
4671 compute_a_shift_length (rtx insn ATTRIBUTE_UNUSED
, rtx
*operands
)
4673 rtx shift
= operands
[3];
4674 enum machine_mode mode
= GET_MODE (shift
);
4675 enum rtx_code code
= GET_CODE (shift
);
4676 enum shift_type shift_type
;
4677 enum shift_mode shift_mode
;
4678 struct shift_info info
;
4679 unsigned int wlength
= 0;
4684 shift_mode
= QIshift
;
4687 shift_mode
= HIshift
;
4690 shift_mode
= SIshift
;
4699 shift_type
= SHIFT_ASHIFTRT
;
4702 shift_type
= SHIFT_LSHIFTRT
;
4705 shift_type
= SHIFT_ASHIFT
;
4711 if (GET_CODE (operands
[2]) != CONST_INT
)
4713 /* Get the assembler code to do one shift. */
4714 get_shift_alg (shift_type
, shift_mode
, 1, &info
);
4716 return (4 + h8300_asm_insn_count (info
.shift1
)) * 2;
4720 int n
= INTVAL (operands
[2]);
4722 /* If the count is negative, make it 0. */
4725 /* If the count is too big, truncate it.
4726 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4727 do the intuitive thing. */
4728 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4729 n
= GET_MODE_BITSIZE (mode
);
4731 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4736 wlength
+= h8300_asm_insn_count (info
.special
);
4738 /* Every assembly instruction used in SHIFT_SPECIAL case
4739 takes 2 bytes except xor.l, which takes 4 bytes, so if we
4740 see xor.l, we just pretend that xor.l counts as two insns
4741 so that the insn length will be computed correctly. */
4742 if (strstr (info
.special
, "xor.l") != NULL
)
4750 if (info
.shift2
!= NULL
)
4752 wlength
+= h8300_asm_insn_count (info
.shift2
) * (n
/ 2);
4756 wlength
+= h8300_asm_insn_count (info
.shift1
) * n
;
4762 int m
= GET_MODE_BITSIZE (mode
) - n
;
4764 /* Not all possibilities of rotate are supported. They shouldn't
4765 be generated, but let's watch for 'em. */
4766 gcc_assert (info
.shift1
);
4768 if (info
.shift2
!= NULL
)
4770 wlength
+= h8300_asm_insn_count (info
.shift2
) * (m
/ 2);
4774 wlength
+= h8300_asm_insn_count (info
.shift1
) * m
;
4776 /* Now mask off the high bits. */
4786 gcc_assert (!TARGET_H8300
);
4796 /* A loop to shift by a "large" constant value.
4797 If we have shift-by-2 insns, use them. */
4798 if (info
.shift2
!= NULL
)
4800 wlength
+= 3 + h8300_asm_insn_count (info
.shift2
);
4802 wlength
+= h8300_asm_insn_count (info
.shift1
);
4806 wlength
+= 3 + h8300_asm_insn_count (info
.shift1
);
4816 /* Compute which flag bits are valid after a shift insn. */
4819 compute_a_shift_cc (rtx insn ATTRIBUTE_UNUSED
, rtx
*operands
)
4821 rtx shift
= operands
[3];
4822 enum machine_mode mode
= GET_MODE (shift
);
4823 enum rtx_code code
= GET_CODE (shift
);
4824 enum shift_type shift_type
;
4825 enum shift_mode shift_mode
;
4826 struct shift_info info
;
4832 shift_mode
= QIshift
;
4835 shift_mode
= HIshift
;
4838 shift_mode
= SIshift
;
4847 shift_type
= SHIFT_ASHIFTRT
;
4850 shift_type
= SHIFT_LSHIFTRT
;
4853 shift_type
= SHIFT_ASHIFT
;
4859 /* This case must be taken care of by one of the two splitters
4860 that convert a variable shift into a loop. */
4861 gcc_assert (GET_CODE (operands
[2]) == CONST_INT
);
4863 n
= INTVAL (operands
[2]);
4865 /* If the count is negative, make it 0. */
4868 /* If the count is too big, truncate it.
4869 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4870 do the intuitive thing. */
4871 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4872 n
= GET_MODE_BITSIZE (mode
);
4874 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4879 if (info
.remainder
== 0)
4880 return info
.cc_special
;
4885 return info
.cc_inline
;
4888 /* This case always ends with an and instruction. */
4892 /* A loop to shift by a "large" constant value.
4893 If we have shift-by-2 insns, use them. */
4894 if (info
.shift2
!= NULL
)
4897 return info
.cc_inline
;
4906 /* A rotation by a non-constant will cause a loop to be generated, in
4907 which a rotation by one bit is used. A rotation by a constant,
4908 including the one in the loop, will be taken care of by
4909 output_a_rotate () at the insn emit time. */
4912 expand_a_rotate (rtx operands
[])
4914 rtx dst
= operands
[0];
4915 rtx src
= operands
[1];
4916 rtx rotate_amount
= operands
[2];
4917 enum machine_mode mode
= GET_MODE (dst
);
4919 if (h8sx_classify_shift (mode
, ROTATE
, rotate_amount
) == H8SX_SHIFT_UNARY
)
4922 /* We rotate in place. */
4923 emit_move_insn (dst
, src
);
4925 if (GET_CODE (rotate_amount
) != CONST_INT
)
4927 rtx counter
= gen_reg_rtx (QImode
);
4928 rtx start_label
= gen_label_rtx ();
4929 rtx end_label
= gen_label_rtx ();
4931 /* If the rotate amount is less than or equal to 0,
4932 we go out of the loop. */
4933 emit_cmp_and_jump_insns (rotate_amount
, const0_rtx
, LE
, NULL_RTX
,
4934 QImode
, 0, end_label
);
4936 /* Initialize the loop counter. */
4937 emit_move_insn (counter
, rotate_amount
);
4939 emit_label (start_label
);
4941 /* Rotate by one bit. */
4945 emit_insn (gen_rotlqi3_1 (dst
, dst
, const1_rtx
));
4948 emit_insn (gen_rotlhi3_1 (dst
, dst
, const1_rtx
));
4951 emit_insn (gen_rotlsi3_1 (dst
, dst
, const1_rtx
));
4957 /* Decrement the counter by 1. */
4958 emit_insn (gen_addqi3 (counter
, counter
, constm1_rtx
));
4960 /* If the loop counter is nonzero, we go back to the beginning
4962 emit_cmp_and_jump_insns (counter
, const0_rtx
, NE
, NULL_RTX
, QImode
, 1,
4965 emit_label (end_label
);
4969 /* Rotate by AMOUNT bits. */
4973 emit_insn (gen_rotlqi3_1 (dst
, dst
, rotate_amount
));
4976 emit_insn (gen_rotlhi3_1 (dst
, dst
, rotate_amount
));
4979 emit_insn (gen_rotlsi3_1 (dst
, dst
, rotate_amount
));
4989 /* Output a rotate insn. */
4992 output_a_rotate (enum rtx_code code
, rtx
*operands
)
4994 rtx dst
= operands
[0];
4995 rtx rotate_amount
= operands
[2];
4996 enum shift_mode rotate_mode
;
4997 enum shift_type rotate_type
;
4998 const char *insn_buf
;
5001 enum machine_mode mode
= GET_MODE (dst
);
5003 gcc_assert (GET_CODE (rotate_amount
) == CONST_INT
);
5008 rotate_mode
= QIshift
;
5011 rotate_mode
= HIshift
;
5014 rotate_mode
= SIshift
;
5023 rotate_type
= SHIFT_ASHIFT
;
5026 rotate_type
= SHIFT_LSHIFTRT
;
5032 amount
= INTVAL (rotate_amount
);
5034 /* Clean up AMOUNT. */
5037 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
))
5038 amount
= GET_MODE_BITSIZE (mode
);
5040 /* Determine the faster direction. After this phase, amount will be
5041 at most a half of GET_MODE_BITSIZE (mode). */
5042 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
) / (unsigned) 2)
5044 /* Flip the direction. */
5045 amount
= GET_MODE_BITSIZE (mode
) - amount
;
5047 (rotate_type
== SHIFT_ASHIFT
) ? SHIFT_LSHIFTRT
: SHIFT_ASHIFT
;
5050 /* See if a byte swap (in HImode) or a word swap (in SImode) can
5051 boost up the rotation. */
5052 if ((mode
== HImode
&& TARGET_H8300
&& amount
>= 5)
5053 || (mode
== HImode
&& TARGET_H8300H
&& amount
>= 6)
5054 || (mode
== HImode
&& TARGET_H8300S
&& amount
== 8)
5055 || (mode
== SImode
&& TARGET_H8300H
&& amount
>= 10)
5056 || (mode
== SImode
&& TARGET_H8300S
&& amount
>= 13))
5061 /* This code works on any family. */
5062 insn_buf
= "xor.b\t%s0,%t0\n\txor.b\t%t0,%s0\n\txor.b\t%s0,%t0";
5063 output_asm_insn (insn_buf
, operands
);
5067 /* This code works on the H8/300H and H8S. */
5068 insn_buf
= "xor.w\t%e0,%f0\n\txor.w\t%f0,%e0\n\txor.w\t%e0,%f0";
5069 output_asm_insn (insn_buf
, operands
);
5076 /* Adjust AMOUNT and flip the direction. */
5077 amount
= GET_MODE_BITSIZE (mode
) / 2 - amount
;
5079 (rotate_type
== SHIFT_ASHIFT
) ? SHIFT_LSHIFTRT
: SHIFT_ASHIFT
;
5082 /* Output rotate insns. */
5083 for (bits
= TARGET_H8300S
? 2 : 1; bits
> 0; bits
/= 2)
5086 insn_buf
= rotate_two
[rotate_type
][rotate_mode
];
5088 insn_buf
= rotate_one
[cpu_type
][rotate_type
][rotate_mode
];
5090 for (; amount
>= bits
; amount
-= bits
)
5091 output_asm_insn (insn_buf
, operands
);
5097 /* Compute the length of a rotate insn. */
5100 compute_a_rotate_length (rtx
*operands
)
5102 rtx src
= operands
[1];
5103 rtx amount_rtx
= operands
[2];
5104 enum machine_mode mode
= GET_MODE (src
);
5106 unsigned int length
= 0;
5108 gcc_assert (GET_CODE (amount_rtx
) == CONST_INT
);
5110 amount
= INTVAL (amount_rtx
);
5112 /* Clean up AMOUNT. */
5115 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
))
5116 amount
= GET_MODE_BITSIZE (mode
);
5118 /* Determine the faster direction. After this phase, amount
5119 will be at most a half of GET_MODE_BITSIZE (mode). */
5120 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
) / (unsigned) 2)
5121 /* Flip the direction. */
5122 amount
= GET_MODE_BITSIZE (mode
) - amount
;
5124 /* See if a byte swap (in HImode) or a word swap (in SImode) can
5125 boost up the rotation. */
5126 if ((mode
== HImode
&& TARGET_H8300
&& amount
>= 5)
5127 || (mode
== HImode
&& TARGET_H8300H
&& amount
>= 6)
5128 || (mode
== HImode
&& TARGET_H8300S
&& amount
== 8)
5129 || (mode
== SImode
&& TARGET_H8300H
&& amount
>= 10)
5130 || (mode
== SImode
&& TARGET_H8300S
&& amount
>= 13))
5132 /* Adjust AMOUNT and flip the direction. */
5133 amount
= GET_MODE_BITSIZE (mode
) / 2 - amount
;
5137 /* We use 2-bit rotations on the H8S. */
5139 amount
= amount
/ 2 + amount
% 2;
5141 /* The H8/300 uses three insns to rotate one bit, taking 6
5143 length
+= amount
* ((TARGET_H8300
&& mode
== HImode
) ? 6 : 2);
5148 /* Fix the operands of a gen_xxx so that it could become a bit
5152 fix_bit_operand (rtx
*operands
, enum rtx_code code
)
5154 /* The bit_operand predicate accepts any memory during RTL generation, but
5155 only 'U' memory afterwards, so if this is a MEM operand, we must force
5156 it to be valid for 'U' by reloading the address. */
5159 ? single_zero_operand (operands
[2], QImode
)
5160 : single_one_operand (operands
[2], QImode
))
5162 /* OK to have a memory dest. */
5163 if (GET_CODE (operands
[0]) == MEM
5164 && !OK_FOR_U (operands
[0]))
5166 rtx mem
= gen_rtx_MEM (GET_MODE (operands
[0]),
5167 copy_to_mode_reg (Pmode
,
5168 XEXP (operands
[0], 0)));
5169 MEM_COPY_ATTRIBUTES (mem
, operands
[0]);
5173 if (GET_CODE (operands
[1]) == MEM
5174 && !OK_FOR_U (operands
[1]))
5176 rtx mem
= gen_rtx_MEM (GET_MODE (operands
[1]),
5177 copy_to_mode_reg (Pmode
,
5178 XEXP (operands
[1], 0)));
5179 MEM_COPY_ATTRIBUTES (mem
, operands
[0]);
5185 /* Dest and src op must be register. */
5187 operands
[1] = force_reg (QImode
, operands
[1]);
5189 rtx res
= gen_reg_rtx (QImode
);
5193 emit_insn (gen_andqi3_1 (res
, operands
[1], operands
[2]));
5196 emit_insn (gen_iorqi3_1 (res
, operands
[1], operands
[2]));
5199 emit_insn (gen_xorqi3_1 (res
, operands
[1], operands
[2]));
5204 emit_insn (gen_movqi (operands
[0], res
));
5209 /* Return nonzero if FUNC is an interrupt function as specified
5210 by the "interrupt" attribute. */
5213 h8300_interrupt_function_p (tree func
)
5217 if (TREE_CODE (func
) != FUNCTION_DECL
)
5220 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
5221 return a
!= NULL_TREE
;
5224 /* Return nonzero if FUNC is a saveall function as specified by the
5225 "saveall" attribute. */
5228 h8300_saveall_function_p (tree func
)
5232 if (TREE_CODE (func
) != FUNCTION_DECL
)
5235 a
= lookup_attribute ("saveall", DECL_ATTRIBUTES (func
));
5236 return a
!= NULL_TREE
;
5239 /* Return nonzero if FUNC is an OS_Task function as specified
5240 by the "OS_Task" attribute. */
5243 h8300_os_task_function_p (tree func
)
5247 if (TREE_CODE (func
) != FUNCTION_DECL
)
5250 a
= lookup_attribute ("OS_Task", DECL_ATTRIBUTES (func
));
5251 return a
!= NULL_TREE
;
5254 /* Return nonzero if FUNC is a monitor function as specified
5255 by the "monitor" attribute. */
5258 h8300_monitor_function_p (tree func
)
5262 if (TREE_CODE (func
) != FUNCTION_DECL
)
5265 a
= lookup_attribute ("monitor", DECL_ATTRIBUTES (func
));
5266 return a
!= NULL_TREE
;
5269 /* Return nonzero if FUNC is a function that should be called
5270 through the function vector. */
5273 h8300_funcvec_function_p (tree func
)
5277 if (TREE_CODE (func
) != FUNCTION_DECL
)
5280 a
= lookup_attribute ("function_vector", DECL_ATTRIBUTES (func
));
5281 return a
!= NULL_TREE
;
5284 /* Return nonzero if DECL is a variable that's in the eight bit
5288 h8300_eightbit_data_p (tree decl
)
5292 if (TREE_CODE (decl
) != VAR_DECL
)
5295 a
= lookup_attribute ("eightbit_data", DECL_ATTRIBUTES (decl
));
5296 return a
!= NULL_TREE
;
5299 /* Return nonzero if DECL is a variable that's in the tiny
5303 h8300_tiny_data_p (tree decl
)
5307 if (TREE_CODE (decl
) != VAR_DECL
)
5310 a
= lookup_attribute ("tiny_data", DECL_ATTRIBUTES (decl
));
5311 return a
!= NULL_TREE
;
5314 /* Generate an 'interrupt_handler' attribute for decls. We convert
5315 all the pragmas to corresponding attributes. */
5318 h8300_insert_attributes (tree node
, tree
*attributes
)
5320 if (TREE_CODE (node
) == FUNCTION_DECL
)
5322 if (pragma_interrupt
)
5324 pragma_interrupt
= 0;
5326 /* Add an 'interrupt_handler' attribute. */
5327 *attributes
= tree_cons (get_identifier ("interrupt_handler"),
5335 /* Add an 'saveall' attribute. */
5336 *attributes
= tree_cons (get_identifier ("saveall"),
5342 /* Supported attributes:
5344 interrupt_handler: output a prologue and epilogue suitable for an
5347 saveall: output a prologue and epilogue that saves and restores
5348 all registers except the stack pointer.
5350 function_vector: This function should be called through the
5353 eightbit_data: This variable lives in the 8-bit data area and can
5354 be referenced with 8-bit absolute memory addresses.
5356 tiny_data: This variable lives in the tiny data area and can be
5357 referenced with 16-bit absolute memory references. */
5359 static const struct attribute_spec h8300_attribute_table
[] =
5361 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
5362 { "interrupt_handler", 0, 0, true, false, false, h8300_handle_fndecl_attribute
},
5363 { "saveall", 0, 0, true, false, false, h8300_handle_fndecl_attribute
},
5364 { "OS_Task", 0, 0, true, false, false, h8300_handle_fndecl_attribute
},
5365 { "monitor", 0, 0, true, false, false, h8300_handle_fndecl_attribute
},
5366 { "function_vector", 0, 0, true, false, false, h8300_handle_fndecl_attribute
},
5367 { "eightbit_data", 0, 0, true, false, false, h8300_handle_eightbit_data_attribute
},
5368 { "tiny_data", 0, 0, true, false, false, h8300_handle_tiny_data_attribute
},
5369 { NULL
, 0, 0, false, false, false, NULL
}
5373 /* Handle an attribute requiring a FUNCTION_DECL; arguments as in
5374 struct attribute_spec.handler. */
5376 h8300_handle_fndecl_attribute (tree
*node
, tree name
,
5377 tree args ATTRIBUTE_UNUSED
,
5378 int flags ATTRIBUTE_UNUSED
,
5381 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5383 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
5385 *no_add_attrs
= true;
5391 /* Handle an "eightbit_data" attribute; arguments as in
5392 struct attribute_spec.handler. */
5394 h8300_handle_eightbit_data_attribute (tree
*node
, tree name
,
5395 tree args ATTRIBUTE_UNUSED
,
5396 int flags ATTRIBUTE_UNUSED
,
5401 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
5403 DECL_SECTION_NAME (decl
) = build_string (7, ".eight");
5407 warning (OPT_Wattributes
, "%qE attribute ignored",
5409 *no_add_attrs
= true;
5415 /* Handle an "tiny_data" attribute; arguments as in
5416 struct attribute_spec.handler. */
5418 h8300_handle_tiny_data_attribute (tree
*node
, tree name
,
5419 tree args ATTRIBUTE_UNUSED
,
5420 int flags ATTRIBUTE_UNUSED
,
5425 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
5427 DECL_SECTION_NAME (decl
) = build_string (6, ".tiny");
5431 warning (OPT_Wattributes
, "%qE attribute ignored",
5433 *no_add_attrs
= true;
5439 /* Mark function vectors, and various small data objects. */
5442 h8300_encode_section_info (tree decl
, rtx rtl
, int first
)
5444 int extra_flags
= 0;
5446 default_encode_section_info (decl
, rtl
, first
);
5448 if (TREE_CODE (decl
) == FUNCTION_DECL
5449 && h8300_funcvec_function_p (decl
))
5450 extra_flags
= SYMBOL_FLAG_FUNCVEC_FUNCTION
;
5451 else if (TREE_CODE (decl
) == VAR_DECL
5452 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
5454 if (h8300_eightbit_data_p (decl
))
5455 extra_flags
= SYMBOL_FLAG_EIGHTBIT_DATA
;
5456 else if (first
&& h8300_tiny_data_p (decl
))
5457 extra_flags
= SYMBOL_FLAG_TINY_DATA
;
5461 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= extra_flags
;
5464 /* Output a single-bit extraction. */
5467 output_simode_bld (int bild
, rtx operands
[])
5471 /* Clear the destination register. */
5472 output_asm_insn ("sub.w\t%e0,%e0\n\tsub.w\t%f0,%f0", operands
);
5474 /* Now output the bit load or bit inverse load, and store it in
5477 output_asm_insn ("bild\t%Z2,%Y1", operands
);
5479 output_asm_insn ("bld\t%Z2,%Y1", operands
);
5481 output_asm_insn ("bst\t#0,%w0", operands
);
5485 /* Determine if we can clear the destination first. */
5486 int clear_first
= (REG_P (operands
[0]) && REG_P (operands
[1])
5487 && REGNO (operands
[0]) != REGNO (operands
[1]));
5490 output_asm_insn ("sub.l\t%S0,%S0", operands
);
5492 /* Output the bit load or bit inverse load. */
5494 output_asm_insn ("bild\t%Z2,%Y1", operands
);
5496 output_asm_insn ("bld\t%Z2,%Y1", operands
);
5499 output_asm_insn ("xor.l\t%S0,%S0", operands
);
5501 /* Perform the bit store. */
5502 output_asm_insn ("rotxl.l\t%S0", operands
);
5509 /* Delayed-branch scheduling is more effective if we have some idea
5510 how long each instruction will be. Use a shorten_branches pass
5511 to get an initial estimate. */
5516 if (flag_delayed_branch
)
5517 shorten_branches (get_insns ());
5520 #ifndef OBJECT_FORMAT_ELF
5522 h8300_asm_named_section (const char *name
, unsigned int flags ATTRIBUTE_UNUSED
,
5525 /* ??? Perhaps we should be using default_coff_asm_named_section. */
5526 fprintf (asm_out_file
, "\t.section %s\n", name
);
5528 #endif /* ! OBJECT_FORMAT_ELF */
5530 /* Nonzero if X is a constant address suitable as an 8-bit absolute,
5531 which is a special case of the 'R' operand. */
5534 h8300_eightbit_constant_address_p (rtx x
)
5536 /* The ranges of the 8-bit area. */
5537 const unsigned HOST_WIDE_INT n1
= trunc_int_for_mode (0xff00, HImode
);
5538 const unsigned HOST_WIDE_INT n2
= trunc_int_for_mode (0xffff, HImode
);
5539 const unsigned HOST_WIDE_INT h1
= trunc_int_for_mode (0x00ffff00, SImode
);
5540 const unsigned HOST_WIDE_INT h2
= trunc_int_for_mode (0x00ffffff, SImode
);
5541 const unsigned HOST_WIDE_INT s1
= trunc_int_for_mode (0xffffff00, SImode
);
5542 const unsigned HOST_WIDE_INT s2
= trunc_int_for_mode (0xffffffff, SImode
);
5544 unsigned HOST_WIDE_INT addr
;
5546 /* We accept symbols declared with eightbit_data. */
5547 if (GET_CODE (x
) == SYMBOL_REF
)
5548 return (SYMBOL_REF_FLAGS (x
) & SYMBOL_FLAG_EIGHTBIT_DATA
) != 0;
5550 if (GET_CODE (x
) != CONST_INT
)
5556 || ((TARGET_H8300
|| TARGET_NORMAL_MODE
) && IN_RANGE (addr
, n1
, n2
))
5557 || (TARGET_H8300H
&& IN_RANGE (addr
, h1
, h2
))
5558 || (TARGET_H8300S
&& IN_RANGE (addr
, s1
, s2
)));
5561 /* Nonzero if X is a constant address suitable as an 16-bit absolute
5562 on H8/300H and H8S. */
5565 h8300_tiny_constant_address_p (rtx x
)
5567 /* The ranges of the 16-bit area. */
5568 const unsigned HOST_WIDE_INT h1
= trunc_int_for_mode (0x00000000, SImode
);
5569 const unsigned HOST_WIDE_INT h2
= trunc_int_for_mode (0x00007fff, SImode
);
5570 const unsigned HOST_WIDE_INT h3
= trunc_int_for_mode (0x00ff8000, SImode
);
5571 const unsigned HOST_WIDE_INT h4
= trunc_int_for_mode (0x00ffffff, SImode
);
5572 const unsigned HOST_WIDE_INT s1
= trunc_int_for_mode (0x00000000, SImode
);
5573 const unsigned HOST_WIDE_INT s2
= trunc_int_for_mode (0x00007fff, SImode
);
5574 const unsigned HOST_WIDE_INT s3
= trunc_int_for_mode (0xffff8000, SImode
);
5575 const unsigned HOST_WIDE_INT s4
= trunc_int_for_mode (0xffffffff, SImode
);
5577 unsigned HOST_WIDE_INT addr
;
5579 switch (GET_CODE (x
))
5582 /* In the normal mode, any symbol fits in the 16-bit absolute
5583 address range. We also accept symbols declared with
5585 return (TARGET_NORMAL_MODE
5586 || (SYMBOL_REF_FLAGS (x
) & SYMBOL_FLAG_TINY_DATA
) != 0);
5590 return (TARGET_NORMAL_MODE
5592 && (IN_RANGE (addr
, h1
, h2
) || IN_RANGE (addr
, h3
, h4
)))
5594 && (IN_RANGE (addr
, s1
, s2
) || IN_RANGE (addr
, s3
, s4
))));
5597 return TARGET_NORMAL_MODE
;
5605 /* Return nonzero if ADDR1 and ADDR2 point to consecutive memory
5606 locations that can be accessed as a 16-bit word. */
5609 byte_accesses_mergeable_p (rtx addr1
, rtx addr2
)
5611 HOST_WIDE_INT offset1
, offset2
;
5619 else if (GET_CODE (addr1
) == PLUS
5620 && REG_P (XEXP (addr1
, 0))
5621 && GET_CODE (XEXP (addr1
, 1)) == CONST_INT
)
5623 reg1
= XEXP (addr1
, 0);
5624 offset1
= INTVAL (XEXP (addr1
, 1));
5634 else if (GET_CODE (addr2
) == PLUS
5635 && REG_P (XEXP (addr2
, 0))
5636 && GET_CODE (XEXP (addr2
, 1)) == CONST_INT
)
5638 reg2
= XEXP (addr2
, 0);
5639 offset2
= INTVAL (XEXP (addr2
, 1));
5644 if (((reg1
== stack_pointer_rtx
&& reg2
== stack_pointer_rtx
)
5645 || (reg1
== frame_pointer_rtx
&& reg2
== frame_pointer_rtx
))
5647 && offset1
+ 1 == offset2
)
5653 /* Return nonzero if we have the same comparison insn as I3 two insns
5654 before I3. I3 is assumed to be a comparison insn. */
5657 same_cmp_preceding_p (rtx i3
)
5661 /* Make sure we have a sequence of three insns. */
5662 i2
= prev_nonnote_insn (i3
);
5665 i1
= prev_nonnote_insn (i2
);
5669 return (INSN_P (i1
) && rtx_equal_p (PATTERN (i1
), PATTERN (i3
))
5670 && any_condjump_p (i2
) && onlyjump_p (i2
));
5673 /* Return nonzero if we have the same comparison insn as I1 two insns
5674 after I1. I1 is assumed to be a comparison insn. */
5677 same_cmp_following_p (rtx i1
)
5681 /* Make sure we have a sequence of three insns. */
5682 i2
= next_nonnote_insn (i1
);
5685 i3
= next_nonnote_insn (i2
);
5689 return (INSN_P (i3
) && rtx_equal_p (PATTERN (i1
), PATTERN (i3
))
5690 && any_condjump_p (i2
) && onlyjump_p (i2
));
5693 /* Return nonzero if OPERANDS are valid for stm (or ldm) that pushes
5694 (or pops) N registers. OPERANDS are assumed to be an array of
5698 h8300_regs_ok_for_stm (int n
, rtx operands
[])
5703 return ((REGNO (operands
[0]) == 0 && REGNO (operands
[1]) == 1)
5704 || (REGNO (operands
[0]) == 2 && REGNO (operands
[1]) == 3)
5705 || (REGNO (operands
[0]) == 4 && REGNO (operands
[1]) == 5));
5707 return ((REGNO (operands
[0]) == 0
5708 && REGNO (operands
[1]) == 1
5709 && REGNO (operands
[2]) == 2)
5710 || (REGNO (operands
[0]) == 4
5711 && REGNO (operands
[1]) == 5
5712 && REGNO (operands
[2]) == 6));
5715 return (REGNO (operands
[0]) == 0
5716 && REGNO (operands
[1]) == 1
5717 && REGNO (operands
[2]) == 2
5718 && REGNO (operands
[3]) == 3);
5724 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
5727 h8300_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED
,
5728 unsigned int new_reg
)
5730 /* Interrupt functions can only use registers that have already been
5731 saved by the prologue, even if they would normally be
5734 if (h8300_current_function_interrupt_function_p ()
5735 && !df_regs_ever_live_p (new_reg
))
5741 /* Returns true if register REGNO is safe to be allocated as a scratch
5742 register in the current function. */
5745 h8300_hard_regno_scratch_ok (unsigned int regno
)
5747 if (h8300_current_function_interrupt_function_p ()
5748 && ! WORD_REG_USED (regno
))
5755 /* Return nonzero if X is a legitimate constant. */
5758 h8300_legitimate_constant_p (rtx x ATTRIBUTE_UNUSED
)
5763 /* Return nonzero if X is a REG or SUBREG suitable as a base register. */
5766 h8300_rtx_ok_for_base_p (rtx x
, int strict
)
5768 /* Strip off SUBREG if any. */
5769 if (GET_CODE (x
) == SUBREG
)
5774 ? REG_OK_FOR_BASE_STRICT_P (x
)
5775 : REG_OK_FOR_BASE_NONSTRICT_P (x
)));
5778 /* Return nozero if X is a legitimate address. On the H8/300, a
5779 legitimate address has the form REG, REG+CONSTANT_ADDRESS or
5780 CONSTANT_ADDRESS. */
5783 h8300_legitimate_address_p (enum machine_mode mode
, rtx x
, bool strict
)
5785 /* The register indirect addresses like @er0 is always valid. */
5786 if (h8300_rtx_ok_for_base_p (x
, strict
))
5789 if (CONSTANT_ADDRESS_P (x
))
5793 && ( GET_CODE (x
) == PRE_INC
5794 || GET_CODE (x
) == PRE_DEC
5795 || GET_CODE (x
) == POST_INC
5796 || GET_CODE (x
) == POST_DEC
)
5797 && h8300_rtx_ok_for_base_p (XEXP (x
, 0), strict
))
5800 if (GET_CODE (x
) == PLUS
5801 && CONSTANT_ADDRESS_P (XEXP (x
, 1))
5802 && h8300_rtx_ok_for_base_p (h8300_get_index (XEXP (x
, 0),
5809 /* Worker function for HARD_REGNO_NREGS.
5811 We pretend the MAC register is 32bits -- we don't have any data
5812 types on the H8 series to handle more than 32bits. */
5815 h8300_hard_regno_nregs (int regno ATTRIBUTE_UNUSED
, enum machine_mode mode
)
5817 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
5820 /* Worker function for HARD_REGNO_MODE_OK. */
5823 h8300_hard_regno_mode_ok (int regno
, enum machine_mode mode
)
5826 /* If an even reg, then anything goes. Otherwise the mode must be
5828 return ((regno
& 1) == 0) || (mode
== HImode
) || (mode
== QImode
);
5830 /* MAC register can only be of SImode. Otherwise, anything
5832 return regno
== MAC_REG
? mode
== SImode
: 1;
5835 /* Perform target dependent optabs initialization. */
5837 h8300_init_libfuncs (void)
5839 set_optab_libfunc (smul_optab
, HImode
, "__mulhi3");
5840 set_optab_libfunc (sdiv_optab
, HImode
, "__divhi3");
5841 set_optab_libfunc (udiv_optab
, HImode
, "__udivhi3");
5842 set_optab_libfunc (smod_optab
, HImode
, "__modhi3");
5843 set_optab_libfunc (umod_optab
, HImode
, "__umodhi3");
5846 /* Worker function for TARGET_RETURN_IN_MEMORY. */
5849 h8300_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
5851 return (TYPE_MODE (type
) == BLKmode
5852 || GET_MODE_SIZE (TYPE_MODE (type
)) > (TARGET_H8300
? 4 : 8));
5855 /* We emit the entire trampoline here. Depending on the pointer size,
5856 we use a different trampoline.
5860 1 0000 7903xxxx mov.w #0x1234,r3
5861 2 0004 5A00xxxx jmp @0x1234
5866 2 0000 7A03xxxxxxxx mov.l #0x12345678,er3
5867 3 0006 5Axxxxxx jmp @0x123456
5872 h8300_trampoline_init (rtx m_tramp
, tree fndecl
, rtx cxt
)
5874 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
5877 if (Pmode
== HImode
)
5879 mem
= adjust_address (m_tramp
, HImode
, 0);
5880 emit_move_insn (mem
, GEN_INT (0x7903));
5881 mem
= adjust_address (m_tramp
, Pmode
, 2);
5882 emit_move_insn (mem
, cxt
);
5883 mem
= adjust_address (m_tramp
, HImode
, 4);
5884 emit_move_insn (mem
, GEN_INT (0x5a00));
5885 mem
= adjust_address (m_tramp
, Pmode
, 6);
5886 emit_move_insn (mem
, fnaddr
);
5892 mem
= adjust_address (m_tramp
, HImode
, 0);
5893 emit_move_insn (mem
, GEN_INT (0x7a03));
5894 mem
= adjust_address (m_tramp
, Pmode
, 2);
5895 emit_move_insn (mem
, cxt
);
5897 tem
= copy_to_reg (fnaddr
);
5898 emit_insn (gen_andsi3 (tem
, tem
, GEN_INT (0x00ffffff)));
5899 emit_insn (gen_iorsi3 (tem
, tem
, GEN_INT (0x5a000000)));
5900 mem
= adjust_address (m_tramp
, SImode
, 6);
5901 emit_move_insn (mem
, tem
);
5905 /* Initialize the GCC target structure. */
5906 #undef TARGET_ATTRIBUTE_TABLE
5907 #define TARGET_ATTRIBUTE_TABLE h8300_attribute_table
5909 #undef TARGET_ASM_ALIGNED_HI_OP
5910 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
5912 #undef TARGET_ASM_FILE_START
5913 #define TARGET_ASM_FILE_START h8300_file_start
5914 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
5915 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
5917 #undef TARGET_ASM_FILE_END
5918 #define TARGET_ASM_FILE_END h8300_file_end
5920 #undef TARGET_ENCODE_SECTION_INFO
5921 #define TARGET_ENCODE_SECTION_INFO h8300_encode_section_info
5923 #undef TARGET_INSERT_ATTRIBUTES
5924 #define TARGET_INSERT_ATTRIBUTES h8300_insert_attributes
5926 #undef TARGET_RTX_COSTS
5927 #define TARGET_RTX_COSTS h8300_rtx_costs
5929 #undef TARGET_INIT_LIBFUNCS
5930 #define TARGET_INIT_LIBFUNCS h8300_init_libfuncs
5932 #undef TARGET_RETURN_IN_MEMORY
5933 #define TARGET_RETURN_IN_MEMORY h8300_return_in_memory
5935 #undef TARGET_FUNCTION_ARG
5936 #define TARGET_FUNCTION_ARG h8300_function_arg
5938 #undef TARGET_FUNCTION_ARG_ADVANCE
5939 #define TARGET_FUNCTION_ARG_ADVANCE h8300_function_arg_advance
5941 #undef TARGET_MACHINE_DEPENDENT_REORG
5942 #define TARGET_MACHINE_DEPENDENT_REORG h8300_reorg
5944 #undef TARGET_HARD_REGNO_SCRATCH_OK
5945 #define TARGET_HARD_REGNO_SCRATCH_OK h8300_hard_regno_scratch_ok
5947 #undef TARGET_LEGITIMATE_ADDRESS_P
5948 #define TARGET_LEGITIMATE_ADDRESS_P h8300_legitimate_address_p
5950 #undef TARGET_DEFAULT_TARGET_FLAGS
5951 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
5953 #undef TARGET_CAN_ELIMINATE
5954 #define TARGET_CAN_ELIMINATE h8300_can_eliminate
5956 #undef TARGET_TRAMPOLINE_INIT
5957 #define TARGET_TRAMPOLINE_INIT h8300_trampoline_init
5959 #undef TARGET_OPTION_OVERRIDE
5960 #define TARGET_OPTION_OVERRIDE h8300_option_override
5962 #undef TARGET_OPTION_OPTIMIZATION_TABLE
5963 #define TARGET_OPTION_OPTIMIZATION_TABLE h8300_option_optimization_table
5965 struct gcc_target targetm
= TARGET_INITIALIZER
;