1 /* Subroutines for insn-output.c for Renesas H8/300.
2 Copyright (C) 1992-2014 Free Software Foundation, Inc.
3 Contributed by Steve Chamberlain (sac@cygnus.com),
4 Jim Wilson (wilson@cygnus.com), and Doug Evans (dje@cygnus.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
28 #include "stor-layout.h"
31 #include "stringpool.h"
33 #include "hard-reg-set.h"
34 #include "insn-config.h"
35 #include "conditions.h"
37 #include "insn-attr.h"
43 #include "diagnostic-core.h"
44 #include "c-family/c-pragma.h" /* ??? */
46 #include "tm-constrs.h"
49 #include "target-def.h"
53 /* Classifies a h8300_src_operand or h8300_dst_operand.
56 A constant operand of some sort.
62 A memory reference with a constant address.
65 A memory reference with a register as its address.
68 Some other kind of memory reference. */
69 enum h8300_operand_class
79 /* For a general two-operand instruction, element [X][Y] gives
80 the length of the opcode fields when the first operand has class
81 (X + 1) and the second has class Y. */
82 typedef unsigned char h8300_length_table
[NUM_H8OPS
- 1][NUM_H8OPS
];
84 /* Forward declarations. */
85 static const char *byte_reg (rtx
, int);
86 static int h8300_interrupt_function_p (tree
);
87 static int h8300_saveall_function_p (tree
);
88 static int h8300_monitor_function_p (tree
);
89 static int h8300_os_task_function_p (tree
);
90 static void h8300_emit_stack_adjustment (int, HOST_WIDE_INT
, bool);
91 static HOST_WIDE_INT
round_frame_size (HOST_WIDE_INT
);
92 static unsigned int compute_saved_regs (void);
93 static const char *cond_string (enum rtx_code
);
94 static unsigned int h8300_asm_insn_count (const char *);
95 static tree
h8300_handle_fndecl_attribute (tree
*, tree
, tree
, int, bool *);
96 static tree
h8300_handle_eightbit_data_attribute (tree
*, tree
, tree
, int, bool *);
97 static tree
h8300_handle_tiny_data_attribute (tree
*, tree
, tree
, int, bool *);
98 static void h8300_print_operand_address (FILE *, rtx
);
99 static void h8300_print_operand (FILE *, rtx
, int);
100 static bool h8300_print_operand_punct_valid_p (unsigned char code
);
101 #ifndef OBJECT_FORMAT_ELF
102 static void h8300_asm_named_section (const char *, unsigned int, tree
);
104 static int h8300_register_move_cost (enum machine_mode
, reg_class_t
, reg_class_t
);
105 static int h8300_and_costs (rtx
);
106 static int h8300_shift_costs (rtx
);
107 static void h8300_push_pop (int, int, bool, bool);
108 static int h8300_stack_offset_p (rtx
, int);
109 static int h8300_ldm_stm_regno (rtx
, int, int, int);
110 static void h8300_reorg (void);
111 static unsigned int h8300_constant_length (rtx
);
112 static unsigned int h8300_displacement_length (rtx
, int);
113 static unsigned int h8300_classify_operand (rtx
, int, enum h8300_operand_class
*);
114 static unsigned int h8300_length_from_table (rtx
, rtx
, const h8300_length_table
*);
115 static unsigned int h8300_unary_length (rtx
);
116 static unsigned int h8300_short_immediate_length (rtx
);
117 static unsigned int h8300_bitfield_length (rtx
, rtx
);
118 static unsigned int h8300_binary_length (rtx
, const h8300_length_table
*);
119 static bool h8300_short_move_mem_p (rtx
, enum rtx_code
);
120 static unsigned int h8300_move_length (rtx
*, const h8300_length_table
*);
121 static bool h8300_hard_regno_scratch_ok (unsigned int);
122 static rtx
h8300_get_index (rtx
, enum machine_mode mode
, int *);
124 /* CPU_TYPE, says what cpu we're compiling for. */
127 /* True if a #pragma interrupt has been seen for the current function. */
128 static int pragma_interrupt
;
130 /* True if a #pragma saveall has been seen for the current function. */
131 static int pragma_saveall
;
133 static const char *const names_big
[] =
134 { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7" };
136 static const char *const names_extended
[] =
137 { "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7" };
139 static const char *const names_upper_extended
[] =
140 { "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7" };
142 /* Points to one of the above. */
143 /* ??? The above could be put in an array indexed by CPU_TYPE. */
144 const char * const *h8_reg_names
;
146 /* Various operations needed by the following, indexed by CPU_TYPE. */
148 const char *h8_push_op
, *h8_pop_op
, *h8_mov_op
;
150 /* Value of MOVE_RATIO. */
151 int h8300_move_ratio
;
153 /* See below where shifts are handled for explanation of this enum. */
163 /* Symbols of the various shifts which can be used as indices. */
167 SHIFT_ASHIFT
, SHIFT_LSHIFTRT
, SHIFT_ASHIFTRT
170 /* Macros to keep the shift algorithm tables small. */
171 #define INL SHIFT_INLINE
172 #define ROT SHIFT_ROT_AND
173 #define LOP SHIFT_LOOP
174 #define SPC SHIFT_SPECIAL
176 /* The shift algorithms for each machine, mode, shift type, and shift
177 count are defined below. The three tables below correspond to
178 QImode, HImode, and SImode, respectively. Each table is organized
179 by, in the order of indices, machine, shift type, and shift count. */
181 static enum shift_alg shift_alg_qi
[3][3][8] = {
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
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
193 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
194 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
} /* SHIFT_ASHIFTRT */
198 /* 0 1 2 3 4 5 6 7 */
199 { INL
, INL
, INL
, INL
, INL
, INL
, ROT
, ROT
}, /* SHIFT_ASHIFT */
200 { INL
, INL
, INL
, INL
, INL
, INL
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
201 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
} /* SHIFT_ASHIFTRT */
205 static enum shift_alg shift_alg_hi
[3][3][16] = {
208 /* 0 1 2 3 4 5 6 7 */
209 /* 8 9 10 11 12 13 14 15 */
210 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
211 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
212 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
,
213 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
214 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
,
215 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
219 /* 0 1 2 3 4 5 6 7 */
220 /* 8 9 10 11 12 13 14 15 */
221 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
222 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
223 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
224 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
225 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
226 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
230 /* 0 1 2 3 4 5 6 7 */
231 /* 8 9 10 11 12 13 14 15 */
232 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
233 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
234 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
235 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
236 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
237 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
241 static enum shift_alg shift_alg_si
[3][3][32] = {
244 /* 0 1 2 3 4 5 6 7 */
245 /* 8 9 10 11 12 13 14 15 */
246 /* 16 17 18 19 20 21 22 23 */
247 /* 24 25 26 27 28 29 30 31 */
248 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
249 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
250 SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
,
251 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFT */
252 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
253 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
254 SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
,
255 SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, SPC
}, /* SHIFT_LSHIFTRT */
256 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
257 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
258 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
259 SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
263 /* 0 1 2 3 4 5 6 7 */
264 /* 8 9 10 11 12 13 14 15 */
265 /* 16 17 18 19 20 21 22 23 */
266 /* 24 25 26 27 28 29 30 31 */
267 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
268 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
269 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
270 SPC
, LOP
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
271 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
272 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
273 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
274 SPC
, LOP
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
275 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
276 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
277 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
278 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
282 /* 0 1 2 3 4 5 6 7 */
283 /* 8 9 10 11 12 13 14 15 */
284 /* 16 17 18 19 20 21 22 23 */
285 /* 24 25 26 27 28 29 30 31 */
286 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
287 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, SPC
,
288 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
289 SPC
, SPC
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
290 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
291 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, SPC
,
292 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
293 SPC
, SPC
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
294 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
295 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
296 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
297 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
313 /* Initialize various cpu specific globals at start up. */
316 h8300_option_override (void)
318 static const char *const h8_push_ops
[2] = { "push" , "push.l" };
319 static const char *const h8_pop_ops
[2] = { "pop" , "pop.l" };
320 static const char *const h8_mov_ops
[2] = { "mov.w", "mov.l" };
322 #ifndef OBJECT_FORMAT_ELF
325 error ("-msx is not supported in coff");
326 target_flags
|= MASK_H8300S
;
332 cpu_type
= (int) CPU_H8300
;
333 h8_reg_names
= names_big
;
337 /* For this we treat the H8/300H and H8S the same. */
338 cpu_type
= (int) CPU_H8300H
;
339 h8_reg_names
= names_extended
;
341 h8_push_op
= h8_push_ops
[cpu_type
];
342 h8_pop_op
= h8_pop_ops
[cpu_type
];
343 h8_mov_op
= h8_mov_ops
[cpu_type
];
345 if (!TARGET_H8300S
&& TARGET_MAC
)
347 error ("-ms2600 is used without -ms");
348 target_flags
|= MASK_H8300S_1
;
351 if (TARGET_H8300
&& TARGET_NORMAL_MODE
)
353 error ("-mn is used without -mh or -ms or -msx");
354 target_flags
^= MASK_NORMAL_MODE
;
357 if (! TARGET_H8300S
&& TARGET_EXR
)
359 error ("-mexr is used without -ms");
360 target_flags
|= MASK_H8300S_1
;
363 if (TARGET_H8300
&& TARGET_INT32
)
365 error ("-mint32 is not supported for H8300 and H8300L targets");
366 target_flags
^= MASK_INT32
;
369 if ((!TARGET_H8300S
&& TARGET_EXR
) && (!TARGET_H8300SX
&& TARGET_EXR
))
371 error ("-mexr is used without -ms or -msx");
372 target_flags
|= MASK_H8300S_1
;
375 if ((!TARGET_H8300S
&& TARGET_NEXR
) && (!TARGET_H8300SX
&& TARGET_NEXR
))
377 warning (OPT_mno_exr
, "-mno-exr valid only with -ms or -msx \
381 /* Some of the shifts are optimized for speed by default.
382 See http://gcc.gnu.org/ml/gcc-patches/2002-07/msg01858.html
383 If optimizing for size, change shift_alg for those shift to
388 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][5] = SHIFT_LOOP
;
389 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][6] = SHIFT_LOOP
;
390 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][13] = SHIFT_LOOP
;
391 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][14] = SHIFT_LOOP
;
393 shift_alg_hi
[H8_300
][SHIFT_LSHIFTRT
][13] = SHIFT_LOOP
;
394 shift_alg_hi
[H8_300
][SHIFT_LSHIFTRT
][14] = SHIFT_LOOP
;
396 shift_alg_hi
[H8_300
][SHIFT_ASHIFTRT
][13] = SHIFT_LOOP
;
397 shift_alg_hi
[H8_300
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
400 shift_alg_hi
[H8_300H
][SHIFT_ASHIFT
][5] = SHIFT_LOOP
;
401 shift_alg_hi
[H8_300H
][SHIFT_ASHIFT
][6] = SHIFT_LOOP
;
403 shift_alg_hi
[H8_300H
][SHIFT_LSHIFTRT
][5] = SHIFT_LOOP
;
404 shift_alg_hi
[H8_300H
][SHIFT_LSHIFTRT
][6] = SHIFT_LOOP
;
406 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][5] = SHIFT_LOOP
;
407 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][6] = SHIFT_LOOP
;
408 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][13] = SHIFT_LOOP
;
409 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
412 shift_alg_hi
[H8_S
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
415 /* Work out a value for MOVE_RATIO. */
418 /* Memory-memory moves are quite expensive without the
419 h8sx instructions. */
420 h8300_move_ratio
= 3;
422 else if (flag_omit_frame_pointer
)
424 /* movmd sequences are fairly cheap when er6 isn't fixed. They can
425 sometimes be as short as two individual memory-to-memory moves,
426 but since they use all the call-saved registers, it seems better
427 to allow up to three moves here. */
428 h8300_move_ratio
= 4;
430 else if (optimize_size
)
432 /* In this case we don't use movmd sequences since they tend
433 to be longer than calls to memcpy(). Memory-to-memory
434 moves are cheaper than for !TARGET_H8300SX, so it makes
435 sense to have a slightly higher threshold. */
436 h8300_move_ratio
= 4;
440 /* We use movmd sequences for some moves since it can be quicker
441 than calling memcpy(). The sequences will need to save and
442 restore er6 though, so bump up the cost. */
443 h8300_move_ratio
= 6;
446 /* This target defaults to strict volatile bitfields. */
447 if (flag_strict_volatile_bitfields
< 0 && abi_version_at_least(2))
448 flag_strict_volatile_bitfields
= 1;
451 /* Return the byte register name for a register rtx X. B should be 0
452 if you want a lower byte register. B should be 1 if you want an
453 upper byte register. */
456 byte_reg (rtx x
, int b
)
458 static const char *const names_small
[] = {
459 "r0l", "r0h", "r1l", "r1h", "r2l", "r2h", "r3l", "r3h",
460 "r4l", "r4h", "r5l", "r5h", "r6l", "r6h", "r7l", "r7h"
463 gcc_assert (REG_P (x
));
465 return names_small
[REGNO (x
) * 2 + b
];
468 /* REGNO must be saved/restored across calls if this macro is true. */
470 #define WORD_REG_USED(regno) \
472 /* No need to save registers if this function will not return. */ \
473 && ! TREE_THIS_VOLATILE (current_function_decl) \
474 && (h8300_saveall_function_p (current_function_decl) \
475 /* Save any call saved register that was used. */ \
476 || (df_regs_ever_live_p (regno) && !call_used_regs[regno]) \
477 /* Save the frame pointer if it was used. */ \
478 || (regno == HARD_FRAME_POINTER_REGNUM && df_regs_ever_live_p (regno)) \
479 /* Save any register used in an interrupt handler. */ \
480 || (h8300_current_function_interrupt_function_p () \
481 && df_regs_ever_live_p (regno)) \
482 /* Save call clobbered registers in non-leaf interrupt \
484 || (h8300_current_function_interrupt_function_p () \
485 && call_used_regs[regno] \
488 /* We use this to wrap all emitted insns in the prologue. */
490 F (rtx x
, bool set_it
)
493 RTX_FRAME_RELATED_P (x
) = 1;
497 /* Mark all the subexpressions of the PARALLEL rtx PAR as
498 frame-related. Return PAR.
500 dwarf2out.c:dwarf2out_frame_debug_expr ignores sub-expressions of a
501 PARALLEL rtx other than the first if they do not have the
502 FRAME_RELATED flag set on them. */
506 int len
= XVECLEN (par
, 0);
509 for (i
= 0; i
< len
; i
++)
510 F (XVECEXP (par
, 0, i
), true);
515 /* Output assembly language to FILE for the operation OP with operand size
516 SIZE to adjust the stack pointer. */
519 h8300_emit_stack_adjustment (int sign
, HOST_WIDE_INT size
, bool in_prologue
)
521 /* If the frame size is 0, we don't have anything to do. */
525 /* H8/300 cannot add/subtract a large constant with a single
526 instruction. If a temporary register is available, load the
527 constant to it and then do the addition. */
530 && !h8300_current_function_interrupt_function_p ()
531 && !(cfun
->static_chain_decl
!= NULL
&& sign
< 0))
533 rtx r3
= gen_rtx_REG (Pmode
, 3);
534 F (emit_insn (gen_movhi (r3
, GEN_INT (sign
* size
))), in_prologue
);
535 F (emit_insn (gen_addhi3 (stack_pointer_rtx
,
536 stack_pointer_rtx
, r3
)), in_prologue
);
540 /* The stack adjustment made here is further optimized by the
541 splitter. In case of H8/300, the splitter always splits the
542 addition emitted here to make the adjustment interrupt-safe.
543 FIXME: We don't always tag those, because we don't know what
544 the splitter will do. */
547 rtx x
= emit_insn (gen_addhi3 (stack_pointer_rtx
,
548 stack_pointer_rtx
, GEN_INT (sign
* size
)));
553 F (emit_insn (gen_addsi3 (stack_pointer_rtx
,
554 stack_pointer_rtx
, GEN_INT (sign
* size
))), in_prologue
);
558 /* Round up frame size SIZE. */
561 round_frame_size (HOST_WIDE_INT size
)
563 return ((size
+ STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
564 & -STACK_BOUNDARY
/ BITS_PER_UNIT
);
567 /* Compute which registers to push/pop.
568 Return a bit vector of registers. */
571 compute_saved_regs (void)
573 unsigned int saved_regs
= 0;
576 /* Construct a bit vector of registers to be pushed/popped. */
577 for (regno
= 0; regno
<= HARD_FRAME_POINTER_REGNUM
; regno
++)
579 if (WORD_REG_USED (regno
))
580 saved_regs
|= 1 << regno
;
583 /* Don't push/pop the frame pointer as it is treated separately. */
584 if (frame_pointer_needed
)
585 saved_regs
&= ~(1 << HARD_FRAME_POINTER_REGNUM
);
590 /* Emit an insn to push register RN. */
595 rtx reg
= gen_rtx_REG (word_mode
, rn
);
599 x
= gen_push_h8300 (reg
);
600 else if (!TARGET_NORMAL_MODE
)
601 x
= gen_push_h8300hs_advanced (reg
);
603 x
= gen_push_h8300hs_normal (reg
);
604 x
= F (emit_insn (x
), true);
605 add_reg_note (x
, REG_INC
, stack_pointer_rtx
);
609 /* Emit an insn to pop register RN. */
614 rtx reg
= gen_rtx_REG (word_mode
, rn
);
618 x
= gen_pop_h8300 (reg
);
619 else if (!TARGET_NORMAL_MODE
)
620 x
= gen_pop_h8300hs_advanced (reg
);
622 x
= gen_pop_h8300hs_normal (reg
);
624 add_reg_note (x
, REG_INC
, stack_pointer_rtx
);
628 /* Emit an instruction to push or pop NREGS consecutive registers
629 starting at register REGNO. POP_P selects a pop rather than a
630 push and RETURN_P is true if the instruction should return.
632 It must be possible to do the requested operation in a single
633 instruction. If NREGS == 1 && !RETURN_P, use a normal push
634 or pop insn. Otherwise emit a parallel of the form:
637 [(return) ;; if RETURN_P
638 (save or restore REGNO)
639 (save or restore REGNO + 1)
641 (save or restore REGNO + NREGS - 1)
642 (set sp (plus sp (const_int adjust)))] */
645 h8300_push_pop (int regno
, int nregs
, bool pop_p
, bool return_p
)
651 /* See whether we can use a simple push or pop. */
652 if (!return_p
&& nregs
== 1)
661 /* We need one element for the return insn, if present, one for each
662 register, and one for stack adjustment. */
663 vec
= rtvec_alloc ((return_p
? 1 : 0) + nregs
+ 1);
664 sp
= stack_pointer_rtx
;
667 /* Add the return instruction. */
670 RTVEC_ELT (vec
, i
) = ret_rtx
;
674 /* Add the register moves. */
675 for (j
= 0; j
< nregs
; j
++)
681 /* Register REGNO + NREGS - 1 is popped first. Before the
682 stack adjustment, its slot is at address @sp. */
683 lhs
= gen_rtx_REG (SImode
, regno
+ j
);
684 rhs
= gen_rtx_MEM (SImode
, plus_constant (Pmode
, sp
,
685 (nregs
- j
- 1) * 4));
689 /* Register REGNO is pushed first and will be stored at @(-4,sp). */
690 lhs
= gen_rtx_MEM (SImode
, plus_constant (Pmode
, sp
, (j
+ 1) * -4));
691 rhs
= gen_rtx_REG (SImode
, regno
+ j
);
693 RTVEC_ELT (vec
, i
+ j
) = gen_rtx_SET (VOIDmode
, lhs
, rhs
);
696 /* Add the stack adjustment. */
697 offset
= GEN_INT ((pop_p
? nregs
: -nregs
) * 4);
698 RTVEC_ELT (vec
, i
+ j
) = gen_rtx_SET (VOIDmode
, sp
,
699 gen_rtx_PLUS (Pmode
, sp
, offset
));
701 x
= gen_rtx_PARALLEL (VOIDmode
, vec
);
711 /* Return true if X has the value sp + OFFSET. */
714 h8300_stack_offset_p (rtx x
, int offset
)
717 return x
== stack_pointer_rtx
;
719 return (GET_CODE (x
) == PLUS
720 && XEXP (x
, 0) == stack_pointer_rtx
721 && GET_CODE (XEXP (x
, 1)) == CONST_INT
722 && INTVAL (XEXP (x
, 1)) == offset
);
725 /* A subroutine of h8300_ldm_stm_parallel. X is one pattern in
726 something that may be an ldm or stm instruction. If it fits
727 the required template, return the register it loads or stores,
730 LOAD_P is true if X should be a load, false if it should be a store.
731 NREGS is the number of registers that the whole instruction is expected
732 to load or store. INDEX is the index of the register that X should
733 load or store, relative to the lowest-numbered register. */
736 h8300_ldm_stm_regno (rtx x
, int load_p
, int index
, int nregs
)
738 int regindex
, memindex
, offset
;
741 regindex
= 0, memindex
= 1, offset
= (nregs
- index
- 1) * 4;
743 memindex
= 0, regindex
= 1, offset
= (index
+ 1) * -4;
745 if (GET_CODE (x
) == SET
746 && GET_CODE (XEXP (x
, regindex
)) == REG
747 && GET_CODE (XEXP (x
, memindex
)) == MEM
748 && h8300_stack_offset_p (XEXP (XEXP (x
, memindex
), 0), offset
))
749 return REGNO (XEXP (x
, regindex
));
754 /* Return true if the elements of VEC starting at FIRST describe an
755 ldm or stm instruction (LOAD_P says which). */
758 h8300_ldm_stm_parallel (rtvec vec
, int load_p
, int first
)
761 int nregs
, i
, regno
, adjust
;
763 /* There must be a stack adjustment, a register move, and at least one
764 other operation (a return or another register move). */
765 if (GET_NUM_ELEM (vec
) < 3)
768 /* Get the range of registers to be pushed or popped. */
769 nregs
= GET_NUM_ELEM (vec
) - first
- 1;
770 regno
= h8300_ldm_stm_regno (RTVEC_ELT (vec
, first
), load_p
, 0, nregs
);
772 /* Check that the call to h8300_ldm_stm_regno succeeded and
773 that we're only dealing with GPRs. */
774 if (regno
< 0 || regno
+ nregs
> 8)
777 /* 2-register h8s instructions must start with an even-numbered register.
778 3- and 4-register instructions must start with er0 or er4. */
781 if ((regno
& 1) != 0)
783 if (nregs
> 2 && (regno
& 3) != 0)
787 /* Check the other loads or stores. */
788 for (i
= 1; i
< nregs
; i
++)
789 if (h8300_ldm_stm_regno (RTVEC_ELT (vec
, first
+ i
), load_p
, i
, nregs
)
793 /* Check the stack adjustment. */
794 last
= RTVEC_ELT (vec
, first
+ nregs
);
795 adjust
= (load_p
? nregs
: -nregs
) * 4;
796 return (GET_CODE (last
) == SET
797 && SET_DEST (last
) == stack_pointer_rtx
798 && h8300_stack_offset_p (SET_SRC (last
), adjust
));
801 /* This is what the stack looks like after the prolog of
802 a function with a frame has been set up:
808 <saved registers> <- sp
810 This is what the stack looks like after the prolog of
811 a function which doesn't have a frame:
816 <saved registers> <- sp
819 /* Generate RTL code for the function prologue. */
822 h8300_expand_prologue (void)
828 /* If the current function has the OS_Task attribute set, then
829 we have a naked prologue. */
830 if (h8300_os_task_function_p (current_function_decl
))
833 if (h8300_monitor_function_p (current_function_decl
))
834 /* The monitor function act as normal functions, which means it
835 can accept parameters and return values. In addition to this,
836 interrupts are masked in prologue and return with "rte" in epilogue. */
837 emit_insn (gen_monitor_prologue ());
839 if (frame_pointer_needed
)
842 push (HARD_FRAME_POINTER_REGNUM
);
843 F (emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
), true);
846 /* Push the rest of the registers in ascending order. */
847 saved_regs
= compute_saved_regs ();
848 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
+= n_regs
)
851 if (saved_regs
& (1 << regno
))
855 /* See how many registers we can push at the same time. */
856 if ((!TARGET_H8300SX
|| (regno
& 3) == 0)
857 && ((saved_regs
>> regno
) & 0x0f) == 0x0f)
860 else if ((!TARGET_H8300SX
|| (regno
& 3) == 0)
861 && ((saved_regs
>> regno
) & 0x07) == 0x07)
864 else if ((!TARGET_H8300SX
|| (regno
& 1) == 0)
865 && ((saved_regs
>> regno
) & 0x03) == 0x03)
869 h8300_push_pop (regno
, n_regs
, false, false);
873 /* Leave room for locals. */
874 h8300_emit_stack_adjustment (-1, round_frame_size (get_frame_size ()), true);
877 /* Return nonzero if we can use "rts" for the function currently being
881 h8300_can_use_return_insn_p (void)
883 return (reload_completed
884 && !frame_pointer_needed
885 && get_frame_size () == 0
886 && compute_saved_regs () == 0);
889 /* Generate RTL code for the function epilogue. */
892 h8300_expand_epilogue (void)
897 HOST_WIDE_INT frame_size
;
900 if (h8300_os_task_function_p (current_function_decl
))
901 /* OS_Task epilogues are nearly naked -- they just have an
905 frame_size
= round_frame_size (get_frame_size ());
908 /* Deallocate locals. */
909 h8300_emit_stack_adjustment (1, frame_size
, false);
911 /* Pop the saved registers in descending order. */
912 saved_regs
= compute_saved_regs ();
913 for (regno
= FIRST_PSEUDO_REGISTER
- 1; regno
>= 0; regno
-= n_regs
)
916 if (saved_regs
& (1 << regno
))
920 /* See how many registers we can pop at the same time. */
921 if ((TARGET_H8300SX
|| (regno
& 3) == 3)
922 && ((saved_regs
<< 3 >> regno
) & 0x0f) == 0x0f)
925 else if ((TARGET_H8300SX
|| (regno
& 3) == 2)
926 && ((saved_regs
<< 2 >> regno
) & 0x07) == 0x07)
929 else if ((TARGET_H8300SX
|| (regno
& 1) == 1)
930 && ((saved_regs
<< 1 >> regno
) & 0x03) == 0x03)
934 /* See if this pop would be the last insn before the return.
935 If so, use rte/l or rts/l instead of pop or ldm.l. */
937 && !frame_pointer_needed
939 && (saved_regs
& ((1 << (regno
- n_regs
+ 1)) - 1)) == 0)
942 h8300_push_pop (regno
- n_regs
+ 1, n_regs
, true, returned_p
);
946 /* Pop frame pointer if we had one. */
947 if (frame_pointer_needed
)
951 h8300_push_pop (HARD_FRAME_POINTER_REGNUM
, 1, true, returned_p
);
955 emit_jump_insn (ret_rtx
);
958 /* Return nonzero if the current function is an interrupt
962 h8300_current_function_interrupt_function_p (void)
964 return (h8300_interrupt_function_p (current_function_decl
));
968 h8300_current_function_monitor_function_p ()
970 return (h8300_monitor_function_p (current_function_decl
));
973 /* Output assembly code for the start of the file. */
976 h8300_file_start (void)
978 default_file_start ();
981 fputs (TARGET_NORMAL_MODE
? "\t.h8300hn\n" : "\t.h8300h\n", asm_out_file
);
982 else if (TARGET_H8300SX
)
983 fputs (TARGET_NORMAL_MODE
? "\t.h8300sxn\n" : "\t.h8300sx\n", asm_out_file
);
984 else if (TARGET_H8300S
)
985 fputs (TARGET_NORMAL_MODE
? "\t.h8300sn\n" : "\t.h8300s\n", asm_out_file
);
988 /* Output assembly language code for the end of file. */
991 h8300_file_end (void)
993 fputs ("\t.end\n", asm_out_file
);
996 /* Split an add of a small constant into two adds/subs insns.
998 If USE_INCDEC_P is nonzero, we generate the last insn using inc/dec
999 instead of adds/subs. */
1002 split_adds_subs (enum machine_mode mode
, rtx
*operands
)
1004 HOST_WIDE_INT val
= INTVAL (operands
[1]);
1005 rtx reg
= operands
[0];
1006 HOST_WIDE_INT sign
= 1;
1007 HOST_WIDE_INT amount
;
1008 rtx (*gen_add
) (rtx
, rtx
, rtx
);
1010 /* Force VAL to be positive so that we do not have to consider the
1021 gen_add
= gen_addhi3
;
1025 gen_add
= gen_addsi3
;
1032 /* Try different amounts in descending order. */
1033 for (amount
= (TARGET_H8300H
|| TARGET_H8300S
) ? 4 : 2;
1037 for (; val
>= amount
; val
-= amount
)
1038 emit_insn (gen_add (reg
, reg
, GEN_INT (sign
* amount
)));
1044 /* Handle machine specific pragmas for compatibility with existing
1045 compilers for the H8/300.
1047 pragma saveall generates prologue/epilogue code which saves and
1048 restores all the registers on function entry.
1050 pragma interrupt saves and restores all registers, and exits with
1051 an rte instruction rather than an rts. A pointer to a function
1052 with this attribute may be safely used in an interrupt vector. */
1055 h8300_pr_interrupt (struct cpp_reader
*pfile ATTRIBUTE_UNUSED
)
1057 pragma_interrupt
= 1;
1061 h8300_pr_saveall (struct cpp_reader
*pfile ATTRIBUTE_UNUSED
)
1066 /* If the next function argument with MODE and TYPE is to be passed in
1067 a register, return a reg RTX for the hard register in which to pass
1068 the argument. CUM represents the state after the last argument.
1069 If the argument is to be pushed, NULL_RTX is returned.
1071 On the H8/300 all normal args are pushed, unless -mquickcall in which
1072 case the first 3 arguments are passed in registers. */
1075 h8300_function_arg (cumulative_args_t cum_v
, enum machine_mode mode
,
1076 const_tree type
, bool named
)
1078 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
1080 static const char *const hand_list
[] = {
1099 rtx result
= NULL_RTX
;
1103 /* Never pass unnamed arguments in registers. */
1107 /* Pass 3 regs worth of data in regs when user asked on the command line. */
1108 if (TARGET_QUICKCALL
)
1111 /* If calling hand written assembler, use 4 regs of args. */
1114 const char * const *p
;
1116 fname
= XSTR (cum
->libcall
, 0);
1118 /* See if this libcall is one of the hand coded ones. */
1119 for (p
= hand_list
; *p
&& strcmp (*p
, fname
) != 0; p
++)
1130 if (mode
== BLKmode
)
1131 size
= int_size_in_bytes (type
);
1133 size
= GET_MODE_SIZE (mode
);
1135 if (size
+ cum
->nbytes
<= regpass
* UNITS_PER_WORD
1136 && cum
->nbytes
/ UNITS_PER_WORD
<= 3)
1137 result
= gen_rtx_REG (mode
, cum
->nbytes
/ UNITS_PER_WORD
);
1143 /* Update the data in CUM to advance over an argument
1144 of mode MODE and data type TYPE.
1145 (TYPE is null for libcalls where that information may not be available.) */
1148 h8300_function_arg_advance (cumulative_args_t cum_v
, enum machine_mode mode
,
1149 const_tree type
, bool named ATTRIBUTE_UNUSED
)
1151 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
1153 cum
->nbytes
+= (mode
!= BLKmode
1154 ? (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
1155 : (int_size_in_bytes (type
) + UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
);
1159 /* Implements TARGET_REGISTER_MOVE_COST.
1161 Any SI register-to-register move may need to be reloaded,
1162 so inmplement h8300_register_move_cost to return > 2 so that reload never
1166 h8300_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
1167 reg_class_t from
, reg_class_t to
)
1169 if (from
== MAC_REGS
|| to
== MAC_REG
)
1175 /* Compute the cost of an and insn. */
1178 h8300_and_costs (rtx x
)
1182 if (GET_MODE (x
) == QImode
)
1185 if (GET_MODE (x
) != HImode
1186 && GET_MODE (x
) != SImode
)
1190 operands
[1] = XEXP (x
, 0);
1191 operands
[2] = XEXP (x
, 1);
1193 return compute_logical_op_length (GET_MODE (x
), operands
) / 2;
1196 /* Compute the cost of a shift insn. */
1199 h8300_shift_costs (rtx x
)
1203 if (GET_MODE (x
) != QImode
1204 && GET_MODE (x
) != HImode
1205 && GET_MODE (x
) != SImode
)
1210 operands
[2] = XEXP (x
, 1);
1212 return compute_a_shift_length (NULL
, operands
) / 2;
1215 /* Worker function for TARGET_RTX_COSTS. */
1218 h8300_rtx_costs (rtx x
, int code
, int outer_code
, int opno ATTRIBUTE_UNUSED
,
1219 int *total
, bool speed
)
1221 if (TARGET_H8300SX
&& outer_code
== MEM
)
1223 /* Estimate the number of execution states needed to calculate
1225 if (register_operand (x
, VOIDmode
)
1226 || GET_CODE (x
) == POST_INC
1227 || GET_CODE (x
) == POST_DEC
1231 *total
= COSTS_N_INSNS (1);
1239 HOST_WIDE_INT n
= INTVAL (x
);
1243 /* Constant operands need the same number of processor
1244 states as register operands. Although we could try to
1245 use a size-based cost for !speed, the lack of
1246 of a mode makes the results very unpredictable. */
1250 if (-4 <= n
&& n
<= 4)
1261 *total
= 0 + (outer_code
== SET
);
1265 if (TARGET_H8300H
|| TARGET_H8300S
)
1266 *total
= 0 + (outer_code
== SET
);
1281 /* See comment for CONST_INT. */
1293 if (XEXP (x
, 1) == const0_rtx
)
1298 if (!h8300_dst_operand (XEXP (x
, 0), VOIDmode
)
1299 || !h8300_src_operand (XEXP (x
, 1), VOIDmode
))
1301 *total
= COSTS_N_INSNS (h8300_and_costs (x
));
1304 /* We say that MOD and DIV are so expensive because otherwise we'll
1305 generate some really horrible code for division of a power of two. */
1311 switch (GET_MODE (x
))
1315 *total
= COSTS_N_INSNS (!speed
? 4 : 10);
1319 *total
= COSTS_N_INSNS (!speed
? 4 : 18);
1325 *total
= COSTS_N_INSNS (12);
1330 switch (GET_MODE (x
))
1334 *total
= COSTS_N_INSNS (2);
1338 *total
= COSTS_N_INSNS (5);
1344 *total
= COSTS_N_INSNS (4);
1350 if (h8sx_binary_shift_operator (x
, VOIDmode
))
1352 *total
= COSTS_N_INSNS (2);
1355 else if (h8sx_unary_shift_operator (x
, VOIDmode
))
1357 *total
= COSTS_N_INSNS (1);
1360 *total
= COSTS_N_INSNS (h8300_shift_costs (x
));
1365 if (GET_MODE (x
) == HImode
)
1372 *total
= COSTS_N_INSNS (1);
1377 /* Documentation for the machine specific operand escapes:
1379 'E' like s but negative.
1380 'F' like t but negative.
1381 'G' constant just the negative
1382 'R' print operand as a byte:8 address if appropriate, else fall back to
1384 'S' print operand as a long word
1385 'T' print operand as a word
1386 'V' find the set bit, and print its number.
1387 'W' find the clear bit, and print its number.
1388 'X' print operand as a byte
1389 'Y' print either l or h depending on whether last 'Z' operand < 8 or >= 8.
1390 If this operand isn't a register, fall back to 'R' handling.
1392 'c' print the opcode corresponding to rtl
1393 'e' first word of 32-bit value - if reg, then least reg. if mem
1394 then least. if const then most sig word
1395 'f' second word of 32-bit value - if reg, then biggest reg. if mem
1396 then +2. if const then least sig word
1397 'j' print operand as condition code.
1398 'k' print operand as reverse condition code.
1399 'm' convert an integer operand to a size suffix (.b, .w or .l)
1400 'o' print an integer without a leading '#'
1401 's' print as low byte of 16-bit value
1402 't' print as high byte of 16-bit value
1403 'w' print as low byte of 32-bit value
1404 'x' print as 2nd byte of 32-bit value
1405 'y' print as 3rd byte of 32-bit value
1406 'z' print as msb of 32-bit value
1409 /* Return assembly language string which identifies a comparison type. */
1412 cond_string (enum rtx_code code
)
1441 /* Print operand X using operand code CODE to assembly language output file
1445 h8300_print_operand (FILE *file
, rtx x
, int code
)
1447 /* This is used for communication between codes V,W,Z and Y. */
1453 if (h8300_constant_length (x
) == 2)
1454 fprintf (file
, ":16");
1456 fprintf (file
, ":32");
1459 switch (GET_CODE (x
))
1462 fprintf (file
, "%sl", names_big
[REGNO (x
)]);
1465 fprintf (file
, "#%ld", (-INTVAL (x
)) & 0xff);
1472 switch (GET_CODE (x
))
1475 fprintf (file
, "%sh", names_big
[REGNO (x
)]);
1478 fprintf (file
, "#%ld", ((-INTVAL (x
)) & 0xff00) >> 8);
1485 gcc_assert (GET_CODE (x
) == CONST_INT
);
1486 fprintf (file
, "#%ld", 0xff & (-INTVAL (x
)));
1489 if (GET_CODE (x
) == REG
)
1490 fprintf (file
, "%s", names_extended
[REGNO (x
)]);
1495 if (GET_CODE (x
) == REG
)
1496 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1501 bitint
= (INTVAL (x
) & 0xffff);
1502 if ((exact_log2 ((bitint
>> 8) & 0xff)) == -1)
1503 bitint
= exact_log2 (bitint
& 0xff);
1505 bitint
= exact_log2 ((bitint
>> 8) & 0xff);
1506 gcc_assert (bitint
>= 0);
1507 fprintf (file
, "#%d", bitint
);
1510 bitint
= ((~INTVAL (x
)) & 0xffff);
1511 if ((exact_log2 ((bitint
>> 8) & 0xff)) == -1 )
1512 bitint
= exact_log2 (bitint
& 0xff);
1514 bitint
= (exact_log2 ((bitint
>> 8) & 0xff));
1515 gcc_assert (bitint
>= 0);
1516 fprintf (file
, "#%d", bitint
);
1520 if (GET_CODE (x
) == REG
)
1521 fprintf (file
, "%s", byte_reg (x
, 0));
1526 gcc_assert (bitint
>= 0);
1527 if (GET_CODE (x
) == REG
)
1528 fprintf (file
, "%s%c", names_big
[REGNO (x
)], bitint
> 7 ? 'h' : 'l');
1530 h8300_print_operand (file
, x
, 'R');
1534 bitint
= INTVAL (x
);
1535 fprintf (file
, "#%d", bitint
& 7);
1538 switch (GET_CODE (x
))
1541 fprintf (file
, "or");
1544 fprintf (file
, "xor");
1547 fprintf (file
, "and");
1554 switch (GET_CODE (x
))
1558 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1560 fprintf (file
, "%s", names_upper_extended
[REGNO (x
)]);
1563 h8300_print_operand (file
, x
, 0);
1566 fprintf (file
, "#%ld", ((INTVAL (x
) >> 16) & 0xffff));
1572 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1573 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1574 fprintf (file
, "#%ld", ((val
>> 16) & 0xffff));
1583 switch (GET_CODE (x
))
1587 fprintf (file
, "%s", names_big
[REGNO (x
) + 1]);
1589 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1592 x
= adjust_address (x
, HImode
, 2);
1593 h8300_print_operand (file
, x
, 0);
1596 fprintf (file
, "#%ld", INTVAL (x
) & 0xffff);
1602 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1603 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1604 fprintf (file
, "#%ld", (val
& 0xffff));
1612 fputs (cond_string (GET_CODE (x
)), file
);
1615 fputs (cond_string (reverse_condition (GET_CODE (x
))), file
);
1618 gcc_assert (GET_CODE (x
) == CONST_INT
);
1638 h8300_print_operand_address (file
, x
);
1641 if (GET_CODE (x
) == CONST_INT
)
1642 fprintf (file
, "#%ld", (INTVAL (x
)) & 0xff);
1644 fprintf (file
, "%s", byte_reg (x
, 0));
1647 if (GET_CODE (x
) == CONST_INT
)
1648 fprintf (file
, "#%ld", (INTVAL (x
) >> 8) & 0xff);
1650 fprintf (file
, "%s", byte_reg (x
, 1));
1653 if (GET_CODE (x
) == CONST_INT
)
1654 fprintf (file
, "#%ld", INTVAL (x
) & 0xff);
1656 fprintf (file
, "%s",
1657 byte_reg (x
, TARGET_H8300
? 2 : 0));
1660 if (GET_CODE (x
) == CONST_INT
)
1661 fprintf (file
, "#%ld", (INTVAL (x
) >> 8) & 0xff);
1663 fprintf (file
, "%s",
1664 byte_reg (x
, TARGET_H8300
? 3 : 1));
1667 if (GET_CODE (x
) == CONST_INT
)
1668 fprintf (file
, "#%ld", (INTVAL (x
) >> 16) & 0xff);
1670 fprintf (file
, "%s", byte_reg (x
, 0));
1673 if (GET_CODE (x
) == CONST_INT
)
1674 fprintf (file
, "#%ld", (INTVAL (x
) >> 24) & 0xff);
1676 fprintf (file
, "%s", byte_reg (x
, 1));
1681 switch (GET_CODE (x
))
1684 switch (GET_MODE (x
))
1687 #if 0 /* Is it asm ("mov.b %0,r2l", ...) */
1688 fprintf (file
, "%s", byte_reg (x
, 0));
1689 #else /* ... or is it asm ("mov.b %0l,r2l", ...) */
1690 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1694 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1698 fprintf (file
, "%s", names_extended
[REGNO (x
)]);
1707 rtx addr
= XEXP (x
, 0);
1709 fprintf (file
, "@");
1710 output_address (addr
);
1712 /* Add a length suffix to constant addresses. Although this
1713 is often unnecessary, it helps to avoid ambiguity in the
1714 syntax of mova. If we wrote an insn like:
1716 mova/w.l @(1,@foo.b),er0
1718 then .b would be considered part of the symbol name.
1719 Adding a length after foo will avoid this. */
1720 if (CONSTANT_P (addr
))
1724 /* Used for mov.b and bit operations. */
1725 if (h8300_eightbit_constant_address_p (addr
))
1727 fprintf (file
, ":8");
1731 /* Fall through. We should not get here if we are
1732 processing bit operations on H8/300 or H8/300H
1733 because 'U' constraint does not allow bit
1734 operations on the tiny area on these machines. */
1739 if (h8300_constant_length (addr
) == 2)
1740 fprintf (file
, ":16");
1742 fprintf (file
, ":32");
1754 fprintf (file
, "#");
1755 h8300_print_operand_address (file
, x
);
1761 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1762 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1763 fprintf (file
, "#%ld", val
);
1772 /* Implements TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1775 h8300_print_operand_punct_valid_p (unsigned char code
)
1777 return (code
== '#');
1780 /* Output assembly language output for the address ADDR to FILE. */
1783 h8300_print_operand_address (FILE *file
, rtx addr
)
1788 switch (GET_CODE (addr
))
1791 fprintf (file
, "%s", h8_reg_names
[REGNO (addr
)]);
1795 fprintf (file
, "-%s", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1799 fprintf (file
, "%s+", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1803 fprintf (file
, "+%s", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1807 fprintf (file
, "%s-", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1811 fprintf (file
, "(");
1813 index
= h8300_get_index (XEXP (addr
, 0), VOIDmode
, &size
);
1814 if (GET_CODE (index
) == REG
)
1817 h8300_print_operand_address (file
, XEXP (addr
, 1));
1818 fprintf (file
, ",");
1822 h8300_print_operand_address (file
, index
);
1826 h8300_print_operand (file
, index
, 'X');
1831 h8300_print_operand (file
, index
, 'T');
1836 h8300_print_operand (file
, index
, 'S');
1840 /* h8300_print_operand_address (file, XEXP (addr, 0)); */
1845 h8300_print_operand_address (file
, XEXP (addr
, 0));
1846 fprintf (file
, "+");
1847 h8300_print_operand_address (file
, XEXP (addr
, 1));
1849 fprintf (file
, ")");
1854 /* Since the H8/300 only has 16-bit pointers, negative values are also
1855 those >= 32768. This happens for example with pointer minus a
1856 constant. We don't want to turn (char *p - 2) into
1857 (char *p + 65534) because loop unrolling can build upon this
1858 (IE: char *p + 131068). */
1859 int n
= INTVAL (addr
);
1861 n
= (int) (short) n
;
1862 fprintf (file
, "%d", n
);
1867 output_addr_const (file
, addr
);
1872 /* Output all insn addresses and their sizes into the assembly language
1873 output file. This is helpful for debugging whether the length attributes
1874 in the md file are correct. This is not meant to be a user selectable
1878 final_prescan_insn (rtx insn
, rtx
*operand ATTRIBUTE_UNUSED
,
1879 int num_operands ATTRIBUTE_UNUSED
)
1881 /* This holds the last insn address. */
1882 static int last_insn_address
= 0;
1884 const int uid
= INSN_UID (insn
);
1886 if (TARGET_ADDRESSES
)
1888 fprintf (asm_out_file
, "; 0x%x %d\n", INSN_ADDRESSES (uid
),
1889 INSN_ADDRESSES (uid
) - last_insn_address
);
1890 last_insn_address
= INSN_ADDRESSES (uid
);
1894 /* Prepare for an SI sized move. */
1897 h8300_expand_movsi (rtx operands
[])
1899 rtx src
= operands
[1];
1900 rtx dst
= operands
[0];
1901 if (!reload_in_progress
&& !reload_completed
)
1903 if (!register_operand (dst
, GET_MODE (dst
)))
1905 rtx tmp
= gen_reg_rtx (GET_MODE (dst
));
1906 emit_move_insn (tmp
, src
);
1913 /* Given FROM and TO register numbers, say whether this elimination is allowed.
1914 Frame pointer elimination is automatically handled.
1916 For the h8300, if frame pointer elimination is being done, we would like to
1917 convert ap and rp into sp, not fp.
1919 All other eliminations are valid. */
1922 h8300_can_eliminate (const int from ATTRIBUTE_UNUSED
, const int to
)
1924 return (to
== STACK_POINTER_REGNUM
? ! frame_pointer_needed
: true);
1927 /* Conditionally modify register usage based on target flags. */
1930 h8300_conditional_register_usage (void)
1933 fixed_regs
[MAC_REG
] = call_used_regs
[MAC_REG
] = 1;
1936 /* Function for INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET).
1937 Define the offset between two registers, one to be eliminated, and
1938 the other its replacement, at the start of a routine. */
1941 h8300_initial_elimination_offset (int from
, int to
)
1943 /* The number of bytes that the return address takes on the stack. */
1944 int pc_size
= POINTER_SIZE
/ BITS_PER_UNIT
;
1946 /* The number of bytes that the saved frame pointer takes on the stack. */
1947 int fp_size
= frame_pointer_needed
* UNITS_PER_WORD
;
1949 /* The number of bytes that the saved registers, excluding the frame
1950 pointer, take on the stack. */
1951 int saved_regs_size
= 0;
1953 /* The number of bytes that the locals takes on the stack. */
1954 int frame_size
= round_frame_size (get_frame_size ());
1958 for (regno
= 0; regno
<= HARD_FRAME_POINTER_REGNUM
; regno
++)
1959 if (WORD_REG_USED (regno
))
1960 saved_regs_size
+= UNITS_PER_WORD
;
1962 /* Adjust saved_regs_size because the above loop took the frame
1963 pointer int account. */
1964 saved_regs_size
-= fp_size
;
1968 case HARD_FRAME_POINTER_REGNUM
:
1971 case ARG_POINTER_REGNUM
:
1972 return pc_size
+ fp_size
;
1973 case RETURN_ADDRESS_POINTER_REGNUM
:
1975 case FRAME_POINTER_REGNUM
:
1976 return -saved_regs_size
;
1981 case STACK_POINTER_REGNUM
:
1984 case ARG_POINTER_REGNUM
:
1985 return pc_size
+ saved_regs_size
+ frame_size
;
1986 case RETURN_ADDRESS_POINTER_REGNUM
:
1987 return saved_regs_size
+ frame_size
;
1988 case FRAME_POINTER_REGNUM
:
2000 /* Worker function for RETURN_ADDR_RTX. */
2003 h8300_return_addr_rtx (int count
, rtx frame
)
2008 ret
= gen_rtx_MEM (Pmode
,
2009 gen_rtx_REG (Pmode
, RETURN_ADDRESS_POINTER_REGNUM
));
2010 else if (flag_omit_frame_pointer
)
2013 ret
= gen_rtx_MEM (Pmode
,
2014 memory_address (Pmode
,
2015 plus_constant (Pmode
, frame
,
2017 set_mem_alias_set (ret
, get_frame_alias_set ());
2021 /* Update the condition code from the insn. */
2024 notice_update_cc (rtx body
, rtx insn
)
2028 switch (get_attr_cc (insn
))
2031 /* Insn does not affect CC at all. */
2035 /* Insn does not change CC, but the 0'th operand has been changed. */
2036 if (cc_status
.value1
!= 0
2037 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
2038 cc_status
.value1
= 0;
2039 if (cc_status
.value2
!= 0
2040 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value2
))
2041 cc_status
.value2
= 0;
2045 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2046 The V flag is unusable. The C flag may or may not be known but
2047 that's ok because alter_cond will change tests to use EQ/NE. */
2049 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2050 set
= single_set (insn
);
2051 cc_status
.value1
= SET_SRC (set
);
2052 if (SET_DEST (set
) != cc0_rtx
)
2053 cc_status
.value2
= SET_DEST (set
);
2057 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2058 The C flag may or may not be known but that's ok because
2059 alter_cond will change tests to use EQ/NE. */
2061 cc_status
.flags
|= CC_NO_CARRY
;
2062 set
= single_set (insn
);
2063 cc_status
.value1
= SET_SRC (set
);
2064 if (SET_DEST (set
) != cc0_rtx
)
2066 /* If the destination is STRICT_LOW_PART, strip off
2068 if (GET_CODE (SET_DEST (set
)) == STRICT_LOW_PART
)
2069 cc_status
.value2
= XEXP (SET_DEST (set
), 0);
2071 cc_status
.value2
= SET_DEST (set
);
2076 /* The insn is a compare instruction. */
2078 cc_status
.value1
= SET_SRC (body
);
2082 /* Insn doesn't leave CC in a usable state. */
2088 /* Given that X occurs in an address of the form (plus X constant),
2089 return the part of X that is expected to be a register. There are
2090 four kinds of addressing mode to recognize:
2097 If SIZE is nonnull, and the address is one of the last three forms,
2098 set *SIZE to the index multiplication factor. Set it to 0 for
2099 plain @(dd,Rn) addresses.
2101 MODE is the mode of the value being accessed. It can be VOIDmode
2102 if the address is known to be valid, but its mode is unknown. */
2105 h8300_get_index (rtx x
, enum machine_mode mode
, int *size
)
2112 factor
= (mode
== VOIDmode
? 0 : GET_MODE_SIZE (mode
));
2115 && (mode
== VOIDmode
2116 || GET_MODE_CLASS (mode
) == MODE_INT
2117 || GET_MODE_CLASS (mode
) == MODE_FLOAT
))
2119 if (factor
<= 1 && GET_CODE (x
) == ZERO_EXTEND
)
2121 /* When accessing byte-sized values, the index can be
2122 a zero-extended QImode or HImode register. */
2123 *size
= GET_MODE_SIZE (GET_MODE (XEXP (x
, 0)));
2128 /* We're looking for addresses of the form:
2131 or (mult (zero_extend X) I)
2133 where I is the size of the operand being accessed.
2134 The canonical form of the second expression is:
2136 (and (mult (subreg X) I) J)
2138 where J == GET_MODE_MASK (GET_MODE (X)) * I. */
2141 if (GET_CODE (x
) == AND
2142 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2144 || INTVAL (XEXP (x
, 1)) == 0xff * factor
2145 || INTVAL (XEXP (x
, 1)) == 0xffff * factor
))
2147 index
= XEXP (x
, 0);
2148 *size
= (INTVAL (XEXP (x
, 1)) >= 0xffff ? 2 : 1);
2156 if (GET_CODE (index
) == MULT
2157 && GET_CODE (XEXP (index
, 1)) == CONST_INT
2158 && (factor
== 0 || factor
== INTVAL (XEXP (index
, 1))))
2159 return XEXP (index
, 0);
2166 /* Worker function for TARGET_MODE_DEPENDENT_ADDRESS_P.
2168 On the H8/300, the predecrement and postincrement address depend thus
2169 (the amount of decrement or increment being the length of the operand). */
2172 h8300_mode_dependent_address_p (const_rtx addr
,
2173 addr_space_t as ATTRIBUTE_UNUSED
)
2175 if (GET_CODE (addr
) == PLUS
2176 && h8300_get_index (XEXP (addr
, 0), VOIDmode
, 0) != XEXP (addr
, 0))
2182 static const h8300_length_table addb_length_table
=
2184 /* #xx Rs @aa @Rs @xx */
2185 { 2, 2, 4, 4, 4 }, /* add.b xx,Rd */
2186 { 4, 4, 4, 4, 6 }, /* add.b xx,@aa */
2187 { 4, 4, 4, 4, 6 }, /* add.b xx,@Rd */
2188 { 6, 4, 4, 4, 6 } /* add.b xx,@xx */
2191 static const h8300_length_table addw_length_table
=
2193 /* #xx Rs @aa @Rs @xx */
2194 { 2, 2, 4, 4, 4 }, /* add.w xx,Rd */
2195 { 4, 4, 4, 4, 6 }, /* add.w xx,@aa */
2196 { 4, 4, 4, 4, 6 }, /* add.w xx,@Rd */
2197 { 4, 4, 4, 4, 6 } /* add.w xx,@xx */
2200 static const h8300_length_table addl_length_table
=
2202 /* #xx Rs @aa @Rs @xx */
2203 { 2, 2, 4, 4, 4 }, /* add.l xx,Rd */
2204 { 4, 4, 6, 6, 6 }, /* add.l xx,@aa */
2205 { 4, 4, 6, 6, 6 }, /* add.l xx,@Rd */
2206 { 4, 4, 6, 6, 6 } /* add.l xx,@xx */
2209 #define logicb_length_table addb_length_table
2210 #define logicw_length_table addw_length_table
2212 static const h8300_length_table logicl_length_table
=
2214 /* #xx Rs @aa @Rs @xx */
2215 { 2, 4, 4, 4, 4 }, /* and.l xx,Rd */
2216 { 4, 4, 6, 6, 6 }, /* and.l xx,@aa */
2217 { 4, 4, 6, 6, 6 }, /* and.l xx,@Rd */
2218 { 4, 4, 6, 6, 6 } /* and.l xx,@xx */
2221 static const h8300_length_table movb_length_table
=
2223 /* #xx Rs @aa @Rs @xx */
2224 { 2, 2, 2, 2, 4 }, /* mov.b xx,Rd */
2225 { 4, 2, 4, 4, 4 }, /* mov.b xx,@aa */
2226 { 4, 2, 4, 4, 4 }, /* mov.b xx,@Rd */
2227 { 4, 4, 4, 4, 4 } /* mov.b xx,@xx */
2230 #define movw_length_table movb_length_table
2232 static const h8300_length_table movl_length_table
=
2234 /* #xx Rs @aa @Rs @xx */
2235 { 2, 2, 4, 4, 4 }, /* mov.l xx,Rd */
2236 { 4, 4, 4, 4, 4 }, /* mov.l xx,@aa */
2237 { 4, 4, 4, 4, 4 }, /* mov.l xx,@Rd */
2238 { 4, 4, 4, 4, 4 } /* mov.l xx,@xx */
2241 /* Return the size of the given address or displacement constant. */
2244 h8300_constant_length (rtx constant
)
2246 /* Check for (@d:16,Reg). */
2247 if (GET_CODE (constant
) == CONST_INT
2248 && IN_RANGE (INTVAL (constant
), -0x8000, 0x7fff))
2251 /* Check for (@d:16,Reg) in cases where the displacement is
2252 an absolute address. */
2253 if (Pmode
== HImode
|| h8300_tiny_constant_address_p (constant
))
2259 /* Return the size of a displacement field in address ADDR, which should
2260 have the form (plus X constant). SIZE is the number of bytes being
2264 h8300_displacement_length (rtx addr
, int size
)
2268 offset
= XEXP (addr
, 1);
2270 /* Check for @(d:2,Reg). */
2271 if (register_operand (XEXP (addr
, 0), VOIDmode
)
2272 && GET_CODE (offset
) == CONST_INT
2273 && (INTVAL (offset
) == size
2274 || INTVAL (offset
) == size
* 2
2275 || INTVAL (offset
) == size
* 3))
2278 return h8300_constant_length (offset
);
2281 /* Store the class of operand OP in *OPCLASS and return the length of any
2282 extra operand fields. SIZE is the number of bytes in OP. OPCLASS
2283 can be null if only the length is needed. */
2286 h8300_classify_operand (rtx op
, int size
, enum h8300_operand_class
*opclass
)
2288 enum h8300_operand_class dummy
;
2293 if (CONSTANT_P (op
))
2295 *opclass
= H8OP_IMMEDIATE
;
2297 /* Byte-sized immediates are stored in the opcode fields. */
2301 /* If this is a 32-bit instruction, see whether the constant
2302 will fit into a 16-bit immediate field. */
2305 && GET_CODE (op
) == CONST_INT
2306 && IN_RANGE (INTVAL (op
), 0, 0xffff))
2311 else if (GET_CODE (op
) == MEM
)
2314 if (CONSTANT_P (op
))
2316 *opclass
= H8OP_MEM_ABSOLUTE
;
2317 return h8300_constant_length (op
);
2319 else if (GET_CODE (op
) == PLUS
&& CONSTANT_P (XEXP (op
, 1)))
2321 *opclass
= H8OP_MEM_COMPLEX
;
2322 return h8300_displacement_length (op
, size
);
2324 else if (GET_RTX_CLASS (GET_CODE (op
)) == RTX_AUTOINC
)
2326 *opclass
= H8OP_MEM_COMPLEX
;
2329 else if (register_operand (op
, VOIDmode
))
2331 *opclass
= H8OP_MEM_BASE
;
2335 gcc_assert (register_operand (op
, VOIDmode
));
2336 *opclass
= H8OP_REGISTER
;
2340 /* Return the length of the instruction described by TABLE given that
2341 its operands are OP1 and OP2. OP1 must be an h8300_dst_operand
2342 and OP2 must be an h8300_src_operand. */
2345 h8300_length_from_table (rtx op1
, rtx op2
, const h8300_length_table
*table
)
2347 enum h8300_operand_class op1_class
, op2_class
;
2348 unsigned int size
, immediate_length
;
2350 size
= GET_MODE_SIZE (GET_MODE (op1
));
2351 immediate_length
= (h8300_classify_operand (op1
, size
, &op1_class
)
2352 + h8300_classify_operand (op2
, size
, &op2_class
));
2353 return immediate_length
+ (*table
)[op1_class
- 1][op2_class
];
2356 /* Return the length of a unary instruction such as neg or not given that
2357 its operand is OP. */
2360 h8300_unary_length (rtx op
)
2362 enum h8300_operand_class opclass
;
2363 unsigned int size
, operand_length
;
2365 size
= GET_MODE_SIZE (GET_MODE (op
));
2366 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2373 return (size
== 4 ? 6 : 4);
2375 case H8OP_MEM_ABSOLUTE
:
2376 return operand_length
+ (size
== 4 ? 6 : 4);
2378 case H8OP_MEM_COMPLEX
:
2379 return operand_length
+ 6;
2386 /* Likewise short immediate instructions such as add.w #xx:3,OP. */
2389 h8300_short_immediate_length (rtx op
)
2391 enum h8300_operand_class opclass
;
2392 unsigned int size
, operand_length
;
2394 size
= GET_MODE_SIZE (GET_MODE (op
));
2395 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2403 case H8OP_MEM_ABSOLUTE
:
2404 case H8OP_MEM_COMPLEX
:
2405 return 4 + operand_length
;
2412 /* Likewise bitfield load and store instructions. */
2415 h8300_bitfield_length (rtx op
, rtx op2
)
2417 enum h8300_operand_class opclass
;
2418 unsigned int size
, operand_length
;
2420 if (GET_CODE (op
) == REG
)
2422 gcc_assert (GET_CODE (op
) != REG
);
2424 size
= GET_MODE_SIZE (GET_MODE (op
));
2425 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2430 case H8OP_MEM_ABSOLUTE
:
2431 case H8OP_MEM_COMPLEX
:
2432 return 4 + operand_length
;
2439 /* Calculate the length of general binary instruction INSN using TABLE. */
2442 h8300_binary_length (rtx insn
, const h8300_length_table
*table
)
2446 set
= single_set (insn
);
2449 if (BINARY_P (SET_SRC (set
)))
2450 return h8300_length_from_table (XEXP (SET_SRC (set
), 0),
2451 XEXP (SET_SRC (set
), 1), table
);
2454 gcc_assert (GET_RTX_CLASS (GET_CODE (SET_SRC (set
))) == RTX_TERNARY
);
2455 return h8300_length_from_table (XEXP (XEXP (SET_SRC (set
), 1), 0),
2456 XEXP (XEXP (SET_SRC (set
), 1), 1),
2461 /* Subroutine of h8300_move_length. Return true if OP is 1- or 2-byte
2462 memory reference and either (1) it has the form @(d:16,Rn) or
2463 (2) its address has the code given by INC_CODE. */
2466 h8300_short_move_mem_p (rtx op
, enum rtx_code inc_code
)
2471 if (GET_CODE (op
) != MEM
)
2474 addr
= XEXP (op
, 0);
2475 size
= GET_MODE_SIZE (GET_MODE (op
));
2476 if (size
!= 1 && size
!= 2)
2479 return (GET_CODE (addr
) == inc_code
2480 || (GET_CODE (addr
) == PLUS
2481 && GET_CODE (XEXP (addr
, 0)) == REG
2482 && h8300_displacement_length (addr
, size
) == 2));
2485 /* Calculate the length of move instruction INSN using the given length
2486 table. Although the tables are correct for most cases, there is some
2487 irregularity in the length of mov.b and mov.w. The following forms:
2494 are two bytes shorter than most other "mov Rs, @complex" or
2495 "mov @complex,Rd" combinations. */
2498 h8300_move_length (rtx
*operands
, const h8300_length_table
*table
)
2502 size
= h8300_length_from_table (operands
[0], operands
[1], table
);
2503 if (REG_P (operands
[0]) && h8300_short_move_mem_p (operands
[1], POST_INC
))
2505 if (REG_P (operands
[1]) && h8300_short_move_mem_p (operands
[0], PRE_DEC
))
2510 /* Return the length of a mova instruction with the given operands.
2511 DEST is the register destination, SRC is the source address and
2512 OFFSET is the 16-bit or 32-bit displacement. */
2515 h8300_mova_length (rtx dest
, rtx src
, rtx offset
)
2520 + h8300_constant_length (offset
)
2521 + h8300_classify_operand (src
, GET_MODE_SIZE (GET_MODE (src
)), 0));
2522 if (!REG_P (dest
) || !REG_P (src
) || REGNO (src
) != REGNO (dest
))
2527 /* Compute the length of INSN based on its length_table attribute.
2528 OPERANDS is the array of its operands. */
2531 h8300_insn_length_from_table (rtx insn
, rtx
* operands
)
2533 switch (get_attr_length_table (insn
))
2535 case LENGTH_TABLE_NONE
:
2538 case LENGTH_TABLE_ADDB
:
2539 return h8300_binary_length (insn
, &addb_length_table
);
2541 case LENGTH_TABLE_ADDW
:
2542 return h8300_binary_length (insn
, &addw_length_table
);
2544 case LENGTH_TABLE_ADDL
:
2545 return h8300_binary_length (insn
, &addl_length_table
);
2547 case LENGTH_TABLE_LOGICB
:
2548 return h8300_binary_length (insn
, &logicb_length_table
);
2550 case LENGTH_TABLE_MOVB
:
2551 return h8300_move_length (operands
, &movb_length_table
);
2553 case LENGTH_TABLE_MOVW
:
2554 return h8300_move_length (operands
, &movw_length_table
);
2556 case LENGTH_TABLE_MOVL
:
2557 return h8300_move_length (operands
, &movl_length_table
);
2559 case LENGTH_TABLE_MOVA
:
2560 return h8300_mova_length (operands
[0], operands
[1], operands
[2]);
2562 case LENGTH_TABLE_MOVA_ZERO
:
2563 return h8300_mova_length (operands
[0], operands
[1], const0_rtx
);
2565 case LENGTH_TABLE_UNARY
:
2566 return h8300_unary_length (operands
[0]);
2568 case LENGTH_TABLE_MOV_IMM4
:
2569 return 2 + h8300_classify_operand (operands
[0], 0, 0);
2571 case LENGTH_TABLE_SHORT_IMMEDIATE
:
2572 return h8300_short_immediate_length (operands
[0]);
2574 case LENGTH_TABLE_BITFIELD
:
2575 return h8300_bitfield_length (operands
[0], operands
[1]);
2577 case LENGTH_TABLE_BITBRANCH
:
2578 return h8300_bitfield_length (operands
[1], operands
[2]) - 2;
2585 /* Return true if LHS and RHS are memory references that can be mapped
2586 to the same h8sx assembly operand. LHS appears as the destination of
2587 an instruction and RHS appears as a source.
2589 Three cases are allowed:
2591 - RHS is @+Rn or @-Rn, LHS is @Rn
2592 - RHS is @Rn, LHS is @Rn+ or @Rn-
2593 - RHS and LHS have the same address and neither has side effects. */
2596 h8sx_mergeable_memrefs_p (rtx lhs
, rtx rhs
)
2598 if (GET_CODE (rhs
) == MEM
&& GET_CODE (lhs
) == MEM
)
2600 rhs
= XEXP (rhs
, 0);
2601 lhs
= XEXP (lhs
, 0);
2603 if (GET_CODE (rhs
) == PRE_INC
|| GET_CODE (rhs
) == PRE_DEC
)
2604 return rtx_equal_p (XEXP (rhs
, 0), lhs
);
2606 if (GET_CODE (lhs
) == POST_INC
|| GET_CODE (lhs
) == POST_DEC
)
2607 return rtx_equal_p (rhs
, XEXP (lhs
, 0));
2609 if (rtx_equal_p (rhs
, lhs
))
2615 /* Return true if OPERANDS[1] can be mapped to the same assembly
2616 operand as OPERANDS[0]. */
2619 h8300_operands_match_p (rtx
*operands
)
2621 if (register_operand (operands
[0], VOIDmode
)
2622 && register_operand (operands
[1], VOIDmode
))
2625 if (h8sx_mergeable_memrefs_p (operands
[0], operands
[1]))
2631 /* Try using movmd to move LENGTH bytes from memory region SRC to memory
2632 region DEST. The two regions do not overlap and have the common
2633 alignment given by ALIGNMENT. Return true on success.
2635 Using movmd for variable-length moves seems to involve some
2636 complex trade-offs. For instance:
2638 - Preparing for a movmd instruction is similar to preparing
2639 for a memcpy. The main difference is that the arguments
2640 are moved into er4, er5 and er6 rather than er0, er1 and er2.
2642 - Since movmd clobbers the frame pointer, we need to save
2643 and restore it somehow when frame_pointer_needed. This can
2644 sometimes make movmd sequences longer than calls to memcpy().
2646 - The counter register is 16 bits, so the instruction is only
2647 suitable for variable-length moves when sizeof (size_t) == 2.
2648 That's only true in normal mode.
2650 - We will often lack static alignment information. Falling back
2651 on movmd.b would likely be slower than calling memcpy(), at least
2654 This function therefore only uses movmd when the length is a
2655 known constant, and only then if -fomit-frame-pointer is in
2656 effect or if we're not optimizing for size.
2658 At the moment the function uses movmd for all in-range constants,
2659 but it might be better to fall back on memcpy() for large moves
2660 if ALIGNMENT == 1. */
2663 h8sx_emit_movmd (rtx dest
, rtx src
, rtx length
,
2664 HOST_WIDE_INT alignment
)
2666 if (!flag_omit_frame_pointer
&& optimize_size
)
2669 if (GET_CODE (length
) == CONST_INT
)
2671 rtx dest_reg
, src_reg
, first_dest
, first_src
;
2675 /* Use movmd.l if the alignment allows it, otherwise fall back
2677 factor
= (alignment
>= 2 ? 4 : 1);
2679 /* Make sure the length is within range. We can handle counter
2680 values up to 65536, although HImode truncation will make
2681 the count appear negative in rtl dumps. */
2682 n
= INTVAL (length
);
2683 if (n
<= 0 || n
/ factor
> 65536)
2686 /* Create temporary registers for the source and destination
2687 pointers. Initialize them to the start of each region. */
2688 dest_reg
= copy_addr_to_reg (XEXP (dest
, 0));
2689 src_reg
= copy_addr_to_reg (XEXP (src
, 0));
2691 /* Create references to the movmd source and destination blocks. */
2692 first_dest
= replace_equiv_address (dest
, dest_reg
);
2693 first_src
= replace_equiv_address (src
, src_reg
);
2695 set_mem_size (first_dest
, n
& -factor
);
2696 set_mem_size (first_src
, n
& -factor
);
2698 length
= copy_to_mode_reg (HImode
, gen_int_mode (n
/ factor
, HImode
));
2699 emit_insn (gen_movmd (first_dest
, first_src
, length
, GEN_INT (factor
)));
2701 if ((n
& -factor
) != n
)
2703 /* Move SRC and DEST past the region we just copied.
2704 This is done to update the memory attributes. */
2705 dest
= adjust_address (dest
, BLKmode
, n
& -factor
);
2706 src
= adjust_address (src
, BLKmode
, n
& -factor
);
2708 /* Replace the addresses with the source and destination
2709 registers, which movmd has left with the right values. */
2710 dest
= replace_equiv_address (dest
, dest_reg
);
2711 src
= replace_equiv_address (src
, src_reg
);
2713 /* Mop up the left-over bytes. */
2715 emit_move_insn (adjust_address (dest
, HImode
, 0),
2716 adjust_address (src
, HImode
, 0));
2718 emit_move_insn (adjust_address (dest
, QImode
, n
& 2),
2719 adjust_address (src
, QImode
, n
& 2));
2726 /* Move ADDR into er6 after pushing its old value onto the stack. */
2729 h8300_swap_into_er6 (rtx addr
)
2731 rtx insn
= push (HARD_FRAME_POINTER_REGNUM
);
2732 if (frame_pointer_needed
)
2733 add_reg_note (insn
, REG_CFA_DEF_CFA
,
2734 plus_constant (Pmode
, gen_rtx_MEM (Pmode
, stack_pointer_rtx
),
2735 2 * UNITS_PER_WORD
));
2737 add_reg_note (insn
, REG_CFA_ADJUST_CFA
,
2738 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
2739 plus_constant (Pmode
, stack_pointer_rtx
, 4)));
2741 emit_move_insn (hard_frame_pointer_rtx
, addr
);
2742 if (REGNO (addr
) == SP_REG
)
2743 emit_move_insn (hard_frame_pointer_rtx
,
2744 plus_constant (Pmode
, hard_frame_pointer_rtx
,
2745 GET_MODE_SIZE (word_mode
)));
2748 /* Move the current value of er6 into ADDR and pop its old value
2752 h8300_swap_out_of_er6 (rtx addr
)
2756 if (REGNO (addr
) != SP_REG
)
2757 emit_move_insn (addr
, hard_frame_pointer_rtx
);
2759 insn
= pop (HARD_FRAME_POINTER_REGNUM
);
2760 RTX_FRAME_RELATED_P (insn
) = 1;
2761 if (frame_pointer_needed
)
2762 add_reg_note (insn
, REG_CFA_DEF_CFA
,
2763 plus_constant (Pmode
, hard_frame_pointer_rtx
,
2764 2 * UNITS_PER_WORD
));
2766 add_reg_note (insn
, REG_CFA_ADJUST_CFA
,
2767 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
2768 plus_constant (Pmode
, stack_pointer_rtx
, -4)));
2771 /* Return the length of mov instruction. */
2774 compute_mov_length (rtx
*operands
)
2776 /* If the mov instruction involves a memory operand, we compute the
2777 length, assuming the largest addressing mode is used, and then
2778 adjust later in the function. Otherwise, we compute and return
2779 the exact length in one step. */
2780 enum machine_mode mode
= GET_MODE (operands
[0]);
2781 rtx dest
= operands
[0];
2782 rtx src
= operands
[1];
2785 if (GET_CODE (src
) == MEM
)
2786 addr
= XEXP (src
, 0);
2787 else if (GET_CODE (dest
) == MEM
)
2788 addr
= XEXP (dest
, 0);
2794 unsigned int base_length
;
2799 if (addr
== NULL_RTX
)
2802 /* The eightbit addressing is available only in QImode, so
2803 go ahead and take care of it. */
2804 if (h8300_eightbit_constant_address_p (addr
))
2811 if (addr
== NULL_RTX
)
2816 if (src
== const0_rtx
)
2826 if (addr
== NULL_RTX
)
2831 if (GET_CODE (src
) == CONST_INT
)
2833 if (src
== const0_rtx
)
2836 if ((INTVAL (src
) & 0xffff) == 0)
2839 if ((INTVAL (src
) & 0xffff) == 0)
2842 if ((INTVAL (src
) & 0xffff)
2843 == ((INTVAL (src
) >> 16) & 0xffff))
2853 if (addr
== NULL_RTX
)
2858 if (satisfies_constraint_G (src
))
2871 /* Adjust the length based on the addressing mode used.
2872 Specifically, we subtract the difference between the actual
2873 length and the longest one, which is @(d:16,Rs). For SImode
2874 and SFmode, we double the adjustment because two mov.w are
2875 used to do the job. */
2877 /* @Rs+ and @-Rd are 2 bytes shorter than the longest. */
2878 if (GET_CODE (addr
) == PRE_DEC
2879 || GET_CODE (addr
) == POST_INC
)
2881 if (mode
== QImode
|| mode
== HImode
)
2882 return base_length
- 2;
2884 /* In SImode and SFmode, we use two mov.w instructions, so
2885 double the adjustment. */
2886 return base_length
- 4;
2889 /* @Rs and @Rd are 2 bytes shorter than the longest. Note that
2890 in SImode and SFmode, the second mov.w involves an address
2891 with displacement, namely @(2,Rs) or @(2,Rd), so we subtract
2893 if (GET_CODE (addr
) == REG
)
2894 return base_length
- 2;
2900 unsigned int base_length
;
2905 if (addr
== NULL_RTX
)
2908 /* The eightbit addressing is available only in QImode, so
2909 go ahead and take care of it. */
2910 if (h8300_eightbit_constant_address_p (addr
))
2917 if (addr
== NULL_RTX
)
2922 if (src
== const0_rtx
)
2932 if (addr
== NULL_RTX
)
2936 if (REGNO (src
) == MAC_REG
|| REGNO (dest
) == MAC_REG
)
2942 if (GET_CODE (src
) == CONST_INT
)
2944 int val
= INTVAL (src
);
2949 if (val
== (val
& 0x00ff) || val
== (val
& 0xff00))
2952 switch (val
& 0xffffffff)
2973 if (addr
== NULL_RTX
)
2978 if (satisfies_constraint_G (src
))
2991 /* Adjust the length based on the addressing mode used.
2992 Specifically, we subtract the difference between the actual
2993 length and the longest one, which is @(d:24,ERs). */
2995 /* @ERs+ and @-ERd are 6 bytes shorter than the longest. */
2996 if (GET_CODE (addr
) == PRE_DEC
2997 || GET_CODE (addr
) == POST_INC
)
2998 return base_length
- 6;
3000 /* @ERs and @ERd are 6 bytes shorter than the longest. */
3001 if (GET_CODE (addr
) == REG
)
3002 return base_length
- 6;
3004 /* @(d:16,ERs) and @(d:16,ERd) are 4 bytes shorter than the
3006 if (GET_CODE (addr
) == PLUS
3007 && GET_CODE (XEXP (addr
, 0)) == REG
3008 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
3009 && INTVAL (XEXP (addr
, 1)) > -32768
3010 && INTVAL (XEXP (addr
, 1)) < 32767)
3011 return base_length
- 4;
3013 /* @aa:16 is 4 bytes shorter than the longest. */
3014 if (h8300_tiny_constant_address_p (addr
))
3015 return base_length
- 4;
3017 /* @aa:24 is 2 bytes shorter than the longest. */
3018 if (CONSTANT_P (addr
))
3019 return base_length
- 2;
3025 /* Output an addition insn. */
3028 output_plussi (rtx
*operands
)
3030 enum machine_mode mode
= GET_MODE (operands
[0]);
3032 gcc_assert (mode
== SImode
);
3036 if (GET_CODE (operands
[2]) == REG
)
3037 return "add.w\t%f2,%f0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
3039 if (GET_CODE (operands
[2]) == CONST_INT
)
3041 HOST_WIDE_INT n
= INTVAL (operands
[2]);
3043 if ((n
& 0xffffff) == 0)
3044 return "add\t%z2,%z0";
3045 if ((n
& 0xffff) == 0)
3046 return "add\t%y2,%y0\n\taddx\t%z2,%z0";
3047 if ((n
& 0xff) == 0)
3048 return "add\t%x2,%x0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
3051 return "add\t%w2,%w0\n\taddx\t%x2,%x0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
3055 if (GET_CODE (operands
[2]) == CONST_INT
3056 && register_operand (operands
[1], VOIDmode
))
3058 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3060 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3061 return "add.l\t%S2,%S0";
3062 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3063 return "sub.l\t%G2,%S0";
3065 /* See if we can finish with 2 bytes. */
3067 switch ((unsigned int) intval
& 0xffffffff)
3072 return "adds\t%2,%S0";
3077 return "subs\t%G2,%S0";
3081 operands
[2] = GEN_INT (intval
>> 16);
3082 return "inc.w\t%2,%e0";
3086 operands
[2] = GEN_INT (intval
>> 16);
3087 return "dec.w\t%G2,%e0";
3090 /* See if we can finish with 4 bytes. */
3091 if ((intval
& 0xffff) == 0)
3093 operands
[2] = GEN_INT (intval
>> 16);
3094 return "add.w\t%2,%e0";
3098 if (GET_CODE (operands
[2]) == CONST_INT
&& INTVAL (operands
[2]) < 0)
3100 operands
[2] = GEN_INT (-INTVAL (operands
[2]));
3101 return "sub.l\t%S2,%S0";
3103 return "add.l\t%S2,%S0";
3107 /* ??? It would be much easier to add the h8sx stuff if a single function
3108 classified the addition as either inc/dec, adds/subs, add.w or add.l. */
3109 /* Compute the length of an addition insn. */
3112 compute_plussi_length (rtx
*operands
)
3114 enum machine_mode mode
= GET_MODE (operands
[0]);
3116 gcc_assert (mode
== SImode
);
3120 if (GET_CODE (operands
[2]) == REG
)
3123 if (GET_CODE (operands
[2]) == CONST_INT
)
3125 HOST_WIDE_INT n
= INTVAL (operands
[2]);
3127 if ((n
& 0xffffff) == 0)
3129 if ((n
& 0xffff) == 0)
3131 if ((n
& 0xff) == 0)
3139 if (GET_CODE (operands
[2]) == CONST_INT
3140 && register_operand (operands
[1], VOIDmode
))
3142 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3144 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3146 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3149 /* See if we can finish with 2 bytes. */
3151 switch ((unsigned int) intval
& 0xffffffff)
3172 /* See if we can finish with 4 bytes. */
3173 if ((intval
& 0xffff) == 0)
3177 if (GET_CODE (operands
[2]) == CONST_INT
&& INTVAL (operands
[2]) < 0)
3178 return h8300_length_from_table (operands
[0],
3179 GEN_INT (-INTVAL (operands
[2])),
3180 &addl_length_table
);
3182 return h8300_length_from_table (operands
[0], operands
[2],
3183 &addl_length_table
);
3188 /* Compute which flag bits are valid after an addition insn. */
3191 compute_plussi_cc (rtx
*operands
)
3193 enum machine_mode mode
= GET_MODE (operands
[0]);
3195 gcc_assert (mode
== SImode
);
3203 if (GET_CODE (operands
[2]) == CONST_INT
3204 && register_operand (operands
[1], VOIDmode
))
3206 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3208 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3210 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3213 /* See if we can finish with 2 bytes. */
3215 switch ((unsigned int) intval
& 0xffffffff)
3220 return CC_NONE_0HIT
;
3225 return CC_NONE_0HIT
;
3236 /* See if we can finish with 4 bytes. */
3237 if ((intval
& 0xffff) == 0)
3245 /* Output a logical insn. */
3248 output_logical_op (enum machine_mode mode
, rtx
*operands
)
3250 /* Figure out the logical op that we need to perform. */
3251 enum rtx_code code
= GET_CODE (operands
[3]);
3252 /* Pretend that every byte is affected if both operands are registers. */
3253 const unsigned HOST_WIDE_INT intval
=
3254 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3255 /* Always use the full instruction if the
3256 first operand is in memory. It is better
3257 to use define_splits to generate the shorter
3258 sequence where valid. */
3259 && register_operand (operands
[1], VOIDmode
)
3260 ? INTVAL (operands
[2]) : 0x55555555);
3261 /* The determinant of the algorithm. If we perform an AND, 0
3262 affects a bit. Otherwise, 1 affects a bit. */
3263 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3264 /* Break up DET into pieces. */
3265 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3266 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3267 const unsigned HOST_WIDE_INT b2
= (det
>> 16) & 0xff;
3268 const unsigned HOST_WIDE_INT b3
= (det
>> 24) & 0xff;
3269 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3270 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3271 int lower_half_easy_p
= 0;
3272 int upper_half_easy_p
= 0;
3273 /* The name of an insn. */
3295 /* First, see if we can finish with one insn. */
3296 if ((TARGET_H8300H
|| TARGET_H8300S
)
3300 sprintf (insn_buf
, "%s.w\t%%T2,%%T0", opname
);
3301 output_asm_insn (insn_buf
, operands
);
3305 /* Take care of the lower byte. */
3308 sprintf (insn_buf
, "%s\t%%s2,%%s0", opname
);
3309 output_asm_insn (insn_buf
, operands
);
3311 /* Take care of the upper byte. */
3314 sprintf (insn_buf
, "%s\t%%t2,%%t0", opname
);
3315 output_asm_insn (insn_buf
, operands
);
3320 if (TARGET_H8300H
|| TARGET_H8300S
)
3322 /* Determine if the lower half can be taken care of in no more
3324 lower_half_easy_p
= (b0
== 0
3326 || (code
!= IOR
&& w0
== 0xffff));
3328 /* Determine if the upper half can be taken care of in no more
3330 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3331 || (code
== AND
&& w1
== 0xff00));
3334 /* Check if doing everything with one insn is no worse than
3335 using multiple insns. */
3336 if ((TARGET_H8300H
|| TARGET_H8300S
)
3337 && w0
!= 0 && w1
!= 0
3338 && !(lower_half_easy_p
&& upper_half_easy_p
)
3339 && !(code
== IOR
&& w1
== 0xffff
3340 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3342 sprintf (insn_buf
, "%s.l\t%%S2,%%S0", opname
);
3343 output_asm_insn (insn_buf
, operands
);
3347 /* Take care of the lower and upper words individually. For
3348 each word, we try different methods in the order of
3350 1) the special insn (in case of AND or XOR),
3351 2) the word-wise insn, and
3352 3) The byte-wise insn. */
3354 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3355 output_asm_insn ((code
== AND
)
3356 ? "sub.w\t%f0,%f0" : "not.w\t%f0",
3358 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3362 sprintf (insn_buf
, "%s.w\t%%f2,%%f0", opname
);
3363 output_asm_insn (insn_buf
, operands
);
3369 sprintf (insn_buf
, "%s\t%%w2,%%w0", opname
);
3370 output_asm_insn (insn_buf
, operands
);
3374 sprintf (insn_buf
, "%s\t%%x2,%%x0", opname
);
3375 output_asm_insn (insn_buf
, operands
);
3380 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3381 output_asm_insn ((code
== AND
)
3382 ? "sub.w\t%e0,%e0" : "not.w\t%e0",
3384 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3387 && (w0
& 0x8000) != 0)
3389 output_asm_insn ("exts.l\t%S0", operands
);
3391 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3395 output_asm_insn ("extu.w\t%e0", operands
);
3397 else if (TARGET_H8300H
|| TARGET_H8300S
)
3401 sprintf (insn_buf
, "%s.w\t%%e2,%%e0", opname
);
3402 output_asm_insn (insn_buf
, operands
);
3409 sprintf (insn_buf
, "%s\t%%y2,%%y0", opname
);
3410 output_asm_insn (insn_buf
, operands
);
3414 sprintf (insn_buf
, "%s\t%%z2,%%z0", opname
);
3415 output_asm_insn (insn_buf
, operands
);
3426 /* Compute the length of a logical insn. */
3429 compute_logical_op_length (enum machine_mode mode
, rtx
*operands
)
3431 /* Figure out the logical op that we need to perform. */
3432 enum rtx_code code
= GET_CODE (operands
[3]);
3433 /* Pretend that every byte is affected if both operands are registers. */
3434 const unsigned HOST_WIDE_INT intval
=
3435 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3436 /* Always use the full instruction if the
3437 first operand is in memory. It is better
3438 to use define_splits to generate the shorter
3439 sequence where valid. */
3440 && register_operand (operands
[1], VOIDmode
)
3441 ? INTVAL (operands
[2]) : 0x55555555);
3442 /* The determinant of the algorithm. If we perform an AND, 0
3443 affects a bit. Otherwise, 1 affects a bit. */
3444 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3445 /* Break up DET into pieces. */
3446 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3447 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3448 const unsigned HOST_WIDE_INT b2
= (det
>> 16) & 0xff;
3449 const unsigned HOST_WIDE_INT b3
= (det
>> 24) & 0xff;
3450 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3451 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3452 int lower_half_easy_p
= 0;
3453 int upper_half_easy_p
= 0;
3455 unsigned int length
= 0;
3460 /* First, see if we can finish with one insn. */
3461 if ((TARGET_H8300H
|| TARGET_H8300S
)
3465 length
= h8300_length_from_table (operands
[1], operands
[2],
3466 &logicw_length_table
);
3470 /* Take care of the lower byte. */
3474 /* Take care of the upper byte. */
3480 if (TARGET_H8300H
|| TARGET_H8300S
)
3482 /* Determine if the lower half can be taken care of in no more
3484 lower_half_easy_p
= (b0
== 0
3486 || (code
!= IOR
&& w0
== 0xffff));
3488 /* Determine if the upper half can be taken care of in no more
3490 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3491 || (code
== AND
&& w1
== 0xff00));
3494 /* Check if doing everything with one insn is no worse than
3495 using multiple insns. */
3496 if ((TARGET_H8300H
|| TARGET_H8300S
)
3497 && w0
!= 0 && w1
!= 0
3498 && !(lower_half_easy_p
&& upper_half_easy_p
)
3499 && !(code
== IOR
&& w1
== 0xffff
3500 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3502 length
= h8300_length_from_table (operands
[1], operands
[2],
3503 &logicl_length_table
);
3507 /* Take care of the lower and upper words individually. For
3508 each word, we try different methods in the order of
3510 1) the special insn (in case of AND or XOR),
3511 2) the word-wise insn, and
3512 3) The byte-wise insn. */
3514 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3518 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3534 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3538 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3541 && (w0
& 0x8000) != 0)
3545 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3551 else if (TARGET_H8300H
|| TARGET_H8300S
)
3572 /* Compute which flag bits are valid after a logical insn. */
3575 compute_logical_op_cc (enum machine_mode mode
, rtx
*operands
)
3577 /* Figure out the logical op that we need to perform. */
3578 enum rtx_code code
= GET_CODE (operands
[3]);
3579 /* Pretend that every byte is affected if both operands are registers. */
3580 const unsigned HOST_WIDE_INT intval
=
3581 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3582 /* Always use the full instruction if the
3583 first operand is in memory. It is better
3584 to use define_splits to generate the shorter
3585 sequence where valid. */
3586 && register_operand (operands
[1], VOIDmode
)
3587 ? INTVAL (operands
[2]) : 0x55555555);
3588 /* The determinant of the algorithm. If we perform an AND, 0
3589 affects a bit. Otherwise, 1 affects a bit. */
3590 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3591 /* Break up DET into pieces. */
3592 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3593 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3594 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3595 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3596 int lower_half_easy_p
= 0;
3597 int upper_half_easy_p
= 0;
3598 /* Condition code. */
3599 enum attr_cc cc
= CC_CLOBBER
;
3604 /* First, see if we can finish with one insn. */
3605 if ((TARGET_H8300H
|| TARGET_H8300S
)
3613 if (TARGET_H8300H
|| TARGET_H8300S
)
3615 /* Determine if the lower half can be taken care of in no more
3617 lower_half_easy_p
= (b0
== 0
3619 || (code
!= IOR
&& w0
== 0xffff));
3621 /* Determine if the upper half can be taken care of in no more
3623 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3624 || (code
== AND
&& w1
== 0xff00));
3627 /* Check if doing everything with one insn is no worse than
3628 using multiple insns. */
3629 if ((TARGET_H8300H
|| TARGET_H8300S
)
3630 && w0
!= 0 && w1
!= 0
3631 && !(lower_half_easy_p
&& upper_half_easy_p
)
3632 && !(code
== IOR
&& w1
== 0xffff
3633 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3639 if ((TARGET_H8300H
|| TARGET_H8300S
)
3642 && (w0
& 0x8000) != 0)
3654 /* Expand a conditional branch. */
3657 h8300_expand_branch (rtx operands
[])
3659 enum rtx_code code
= GET_CODE (operands
[0]);
3660 rtx op0
= operands
[1];
3661 rtx op1
= operands
[2];
3662 rtx label
= operands
[3];
3665 tmp
= gen_rtx_COMPARE (VOIDmode
, op0
, op1
);
3666 emit_insn (gen_rtx_SET (VOIDmode
, cc0_rtx
, tmp
));
3668 tmp
= gen_rtx_fmt_ee (code
, VOIDmode
, cc0_rtx
, const0_rtx
);
3669 tmp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, tmp
,
3670 gen_rtx_LABEL_REF (VOIDmode
, label
),
3672 emit_jump_insn (gen_rtx_SET (VOIDmode
, pc_rtx
, tmp
));
3676 /* Expand a conditional store. */
3679 h8300_expand_store (rtx operands
[])
3681 rtx dest
= operands
[0];
3682 enum rtx_code code
= GET_CODE (operands
[1]);
3683 rtx op0
= operands
[2];
3684 rtx op1
= operands
[3];
3687 tmp
= gen_rtx_COMPARE (VOIDmode
, op0
, op1
);
3688 emit_insn (gen_rtx_SET (VOIDmode
, cc0_rtx
, tmp
));
3690 tmp
= gen_rtx_fmt_ee (code
, GET_MODE (dest
), cc0_rtx
, const0_rtx
);
3691 emit_insn (gen_rtx_SET (VOIDmode
, dest
, tmp
));
3696 We devote a fair bit of code to getting efficient shifts since we
3697 can only shift one bit at a time on the H8/300 and H8/300H and only
3698 one or two bits at a time on the H8S.
3700 All shift code falls into one of the following ways of
3703 o SHIFT_INLINE: Emit straight line code for the shift; this is used
3704 when a straight line shift is about the same size or smaller than
3707 o SHIFT_ROT_AND: Rotate the value the opposite direction, then mask
3708 off the bits we don't need. This is used when only a few of the
3709 bits in the original value will survive in the shifted value.
3711 o SHIFT_SPECIAL: Often it's possible to move a byte or a word to
3712 simulate a shift by 8, 16, or 24 bits. Once moved, a few inline
3713 shifts can be added if the shift count is slightly more than 8 or
3714 16. This case also includes other oddballs that are not worth
3717 o SHIFT_LOOP: Emit a loop using one (or two on H8S) bit shifts.
3719 For each shift count, we try to use code that has no trade-off
3720 between code size and speed whenever possible.
3722 If the trade-off is unavoidable, we try to be reasonable.
3723 Specifically, the fastest version is one instruction longer than
3724 the shortest version, we take the fastest version. We also provide
3725 the use a way to switch back to the shortest version with -Os.
3727 For the details of the shift algorithms for various shift counts,
3728 refer to shift_alg_[qhs]i. */
3730 /* Classify a shift with the given mode and code. OP is the shift amount. */
3732 enum h8sx_shift_type
3733 h8sx_classify_shift (enum machine_mode mode
, enum rtx_code code
, rtx op
)
3735 if (!TARGET_H8300SX
)
3736 return H8SX_SHIFT_NONE
;
3742 /* Check for variable shifts (shll Rs,Rd and shlr Rs,Rd). */
3743 if (GET_CODE (op
) != CONST_INT
)
3744 return H8SX_SHIFT_BINARY
;
3746 /* Reject out-of-range shift amounts. */
3747 if (INTVAL (op
) <= 0 || INTVAL (op
) >= GET_MODE_BITSIZE (mode
))
3748 return H8SX_SHIFT_NONE
;
3750 /* Power-of-2 shifts are effectively unary operations. */
3751 if (exact_log2 (INTVAL (op
)) >= 0)
3752 return H8SX_SHIFT_UNARY
;
3754 return H8SX_SHIFT_BINARY
;
3757 if (op
== const1_rtx
|| op
== const2_rtx
)
3758 return H8SX_SHIFT_UNARY
;
3759 return H8SX_SHIFT_NONE
;
3762 if (GET_CODE (op
) == CONST_INT
3763 && (INTVAL (op
) == 1
3765 || INTVAL (op
) == GET_MODE_BITSIZE (mode
) - 2
3766 || INTVAL (op
) == GET_MODE_BITSIZE (mode
) - 1))
3767 return H8SX_SHIFT_UNARY
;
3768 return H8SX_SHIFT_NONE
;
3771 return H8SX_SHIFT_NONE
;
3775 /* Return the asm template for a single h8sx shift instruction.
3776 OPERANDS[0] and OPERANDS[1] are the destination, OPERANDS[2]
3777 is the source and OPERANDS[3] is the shift. SUFFIX is the
3778 size suffix ('b', 'w' or 'l') and OPTYPE is the h8300_print_operand
3779 prefix for the destination operand. */
3782 output_h8sx_shift (rtx
*operands
, int suffix
, int optype
)
3784 static char buffer
[16];
3787 switch (GET_CODE (operands
[3]))
3803 if (INTVAL (operands
[2]) > 2)
3805 /* This is really a right rotate. */
3806 operands
[2] = GEN_INT (GET_MODE_BITSIZE (GET_MODE (operands
[0]))
3807 - INTVAL (operands
[2]));
3815 if (operands
[2] == const1_rtx
)
3816 sprintf (buffer
, "%s.%c\t%%%c0", stem
, suffix
, optype
);
3818 sprintf (buffer
, "%s.%c\t%%X2,%%%c0", stem
, suffix
, optype
);
3822 /* Emit code to do shifts. */
3825 expand_a_shift (enum machine_mode mode
, enum rtx_code code
, rtx operands
[])
3827 switch (h8sx_classify_shift (mode
, code
, operands
[2]))
3829 case H8SX_SHIFT_BINARY
:
3830 operands
[1] = force_reg (mode
, operands
[1]);
3833 case H8SX_SHIFT_UNARY
:
3836 case H8SX_SHIFT_NONE
:
3840 emit_move_insn (copy_rtx (operands
[0]), operands
[1]);
3842 /* Need a loop to get all the bits we want - we generate the
3843 code at emit time, but need to allocate a scratch reg now. */
3845 emit_insn (gen_rtx_PARALLEL
3848 gen_rtx_SET (VOIDmode
, copy_rtx (operands
[0]),
3849 gen_rtx_fmt_ee (code
, mode
,
3850 copy_rtx (operands
[0]), operands
[2])),
3851 gen_rtx_CLOBBER (VOIDmode
,
3852 gen_rtx_SCRATCH (QImode
)))));
3856 /* Symbols of the various modes which can be used as indices. */
3860 QIshift
, HIshift
, SIshift
3863 /* For single bit shift insns, record assembler and what bits of the
3864 condition code are valid afterwards (represented as various CC_FOO
3865 bits, 0 means CC isn't left in a usable state). */
3869 const char *const assembler
;
3870 const enum attr_cc cc_valid
;
3873 /* Assembler instruction shift table.
3875 These tables are used to look up the basic shifts.
3876 They are indexed by cpu, shift_type, and mode. */
3878 static const struct shift_insn shift_one
[2][3][3] =
3884 { "shll\t%X0", CC_SET_ZNV
},
3885 { "add.w\t%T0,%T0", CC_SET_ZN
},
3886 { "add.w\t%f0,%f0\n\taddx\t%y0,%y0\n\taddx\t%z0,%z0", CC_CLOBBER
}
3888 /* SHIFT_LSHIFTRT */
3890 { "shlr\t%X0", CC_SET_ZNV
},
3891 { "shlr\t%t0\n\trotxr\t%s0", CC_CLOBBER
},
3892 { "shlr\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", CC_CLOBBER
}
3894 /* SHIFT_ASHIFTRT */
3896 { "shar\t%X0", CC_SET_ZNV
},
3897 { "shar\t%t0\n\trotxr\t%s0", CC_CLOBBER
},
3898 { "shar\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", CC_CLOBBER
}
3905 { "shll.b\t%X0", CC_SET_ZNV
},
3906 { "shll.w\t%T0", CC_SET_ZNV
},
3907 { "shll.l\t%S0", CC_SET_ZNV
}
3909 /* SHIFT_LSHIFTRT */
3911 { "shlr.b\t%X0", CC_SET_ZNV
},
3912 { "shlr.w\t%T0", CC_SET_ZNV
},
3913 { "shlr.l\t%S0", CC_SET_ZNV
}
3915 /* SHIFT_ASHIFTRT */
3917 { "shar.b\t%X0", CC_SET_ZNV
},
3918 { "shar.w\t%T0", CC_SET_ZNV
},
3919 { "shar.l\t%S0", CC_SET_ZNV
}
3924 static const struct shift_insn shift_two
[3][3] =
3928 { "shll.b\t#2,%X0", CC_SET_ZNV
},
3929 { "shll.w\t#2,%T0", CC_SET_ZNV
},
3930 { "shll.l\t#2,%S0", CC_SET_ZNV
}
3932 /* SHIFT_LSHIFTRT */
3934 { "shlr.b\t#2,%X0", CC_SET_ZNV
},
3935 { "shlr.w\t#2,%T0", CC_SET_ZNV
},
3936 { "shlr.l\t#2,%S0", CC_SET_ZNV
}
3938 /* SHIFT_ASHIFTRT */
3940 { "shar.b\t#2,%X0", CC_SET_ZNV
},
3941 { "shar.w\t#2,%T0", CC_SET_ZNV
},
3942 { "shar.l\t#2,%S0", CC_SET_ZNV
}
3946 /* Rotates are organized by which shift they'll be used in implementing.
3947 There's no need to record whether the cc is valid afterwards because
3948 it is the AND insn that will decide this. */
3950 static const char *const rotate_one
[2][3][3] =
3957 "shlr\t%t0\n\trotxr\t%s0\n\tbst\t#7,%t0",
3960 /* SHIFT_LSHIFTRT */
3963 "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
3966 /* SHIFT_ASHIFTRT */
3969 "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
3981 /* SHIFT_LSHIFTRT */
3987 /* SHIFT_ASHIFTRT */
3996 static const char *const rotate_two
[3][3] =
4004 /* SHIFT_LSHIFTRT */
4010 /* SHIFT_ASHIFTRT */
4019 /* Shift algorithm. */
4022 /* The number of bits to be shifted by shift1 and shift2. Valid
4023 when ALG is SHIFT_SPECIAL. */
4024 unsigned int remainder
;
4026 /* Special insn for a shift. Valid when ALG is SHIFT_SPECIAL. */
4027 const char *special
;
4029 /* Insn for a one-bit shift. Valid when ALG is either SHIFT_INLINE
4030 or SHIFT_SPECIAL, and REMAINDER is nonzero. */
4033 /* Insn for a two-bit shift. Valid when ALG is either SHIFT_INLINE
4034 or SHIFT_SPECIAL, and REMAINDER is nonzero. */
4037 /* CC status for SHIFT_INLINE. */
4038 enum attr_cc cc_inline
;
4040 /* CC status for SHIFT_SPECIAL. */
4041 enum attr_cc cc_special
;
4044 static void get_shift_alg (enum shift_type
,
4045 enum shift_mode
, unsigned int,
4046 struct shift_info
*);
4048 /* Given SHIFT_TYPE, SHIFT_MODE, and shift count COUNT, determine the
4049 best algorithm for doing the shift. The assembler code is stored
4050 in the pointers in INFO. We achieve the maximum efficiency in most
4051 cases when !TARGET_H8300. In case of TARGET_H8300, shifts in
4052 SImode in particular have a lot of room to optimize.
4054 We first determine the strategy of the shift algorithm by a table
4055 lookup. If that tells us to use a hand crafted assembly code, we
4056 go into the big switch statement to find what that is. Otherwise,
4057 we resort to a generic way, such as inlining. In either case, the
4058 result is returned through INFO. */
4061 get_shift_alg (enum shift_type shift_type
, enum shift_mode shift_mode
,
4062 unsigned int count
, struct shift_info
*info
)
4066 /* Find the target CPU. */
4069 else if (TARGET_H8300H
)
4074 /* Find the shift algorithm. */
4075 info
->alg
= SHIFT_LOOP
;
4079 if (count
< GET_MODE_BITSIZE (QImode
))
4080 info
->alg
= shift_alg_qi
[cpu
][shift_type
][count
];
4084 if (count
< GET_MODE_BITSIZE (HImode
))
4085 info
->alg
= shift_alg_hi
[cpu
][shift_type
][count
];
4089 if (count
< GET_MODE_BITSIZE (SImode
))
4090 info
->alg
= shift_alg_si
[cpu
][shift_type
][count
];
4097 /* Fill in INFO. Return unless we have SHIFT_SPECIAL. */
4101 info
->remainder
= count
;
4105 /* It is up to the caller to know that looping clobbers cc. */
4106 info
->shift1
= shift_one
[cpu_type
][shift_type
][shift_mode
].assembler
;
4107 info
->shift2
= shift_two
[shift_type
][shift_mode
].assembler
;
4108 info
->cc_inline
= shift_one
[cpu_type
][shift_type
][shift_mode
].cc_valid
;
4112 info
->shift1
= rotate_one
[cpu_type
][shift_type
][shift_mode
];
4113 info
->shift2
= rotate_two
[shift_type
][shift_mode
];
4114 info
->cc_inline
= CC_CLOBBER
;
4118 /* REMAINDER is 0 for most cases, so initialize it to 0. */
4119 info
->remainder
= 0;
4120 info
->shift1
= shift_one
[cpu_type
][shift_type
][shift_mode
].assembler
;
4121 info
->shift2
= shift_two
[shift_type
][shift_mode
].assembler
;
4122 info
->cc_inline
= shift_one
[cpu_type
][shift_type
][shift_mode
].cc_valid
;
4123 info
->cc_special
= CC_CLOBBER
;
4127 /* Here we only deal with SHIFT_SPECIAL. */
4131 /* For ASHIFTRT by 7 bits, the sign bit is simply replicated
4132 through the entire value. */
4133 gcc_assert (shift_type
== SHIFT_ASHIFTRT
&& count
== 7);
4134 info
->special
= "shll\t%X0\n\tsubx\t%X0,%X0";
4144 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";
4146 info
->special
= "shar.b\t%t0\n\tmov.b\t%s0,%t0\n\trotxr.w\t%T0\n\tand.b\t#0x80,%s0";
4148 case SHIFT_LSHIFTRT
:
4150 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";
4152 info
->special
= "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.w\t%T0\n\tand.b\t#0x01,%t0";
4154 case SHIFT_ASHIFTRT
:
4155 info
->special
= "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.b\t%s0\n\tsubx\t%t0,%t0";
4159 else if ((8 <= count
&& count
<= 13)
4160 || (TARGET_H8300S
&& count
== 14))
4162 info
->remainder
= count
- 8;
4167 info
->special
= "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0";
4169 case SHIFT_LSHIFTRT
:
4172 info
->special
= "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0";
4173 info
->shift1
= "shlr.b\t%s0";
4174 info
->cc_inline
= CC_SET_ZNV
;
4178 info
->special
= "mov.b\t%t0,%s0\n\textu.w\t%T0";
4179 info
->cc_special
= CC_SET_ZNV
;
4182 case SHIFT_ASHIFTRT
:
4185 info
->special
= "mov.b\t%t0,%s0\n\tbld\t#7,%s0\n\tsubx\t%t0,%t0";
4186 info
->shift1
= "shar.b\t%s0";
4190 info
->special
= "mov.b\t%t0,%s0\n\texts.w\t%T0";
4191 info
->cc_special
= CC_SET_ZNV
;
4196 else if (count
== 14)
4202 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";
4204 case SHIFT_LSHIFTRT
:
4206 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";
4208 case SHIFT_ASHIFTRT
:
4210 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";
4211 else if (TARGET_H8300H
)
4213 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";
4214 info
->cc_special
= CC_SET_ZNV
;
4216 else /* TARGET_H8300S */
4221 else if (count
== 15)
4226 info
->special
= "bld\t#0,%s0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#7,%t0";
4228 case SHIFT_LSHIFTRT
:
4229 info
->special
= "bld\t#7,%t0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#0,%s0";
4231 case SHIFT_ASHIFTRT
:
4232 info
->special
= "shll\t%t0\n\tsubx\t%t0,%t0\n\tmov.b\t%t0,%s0";
4239 if (TARGET_H8300
&& 8 <= count
&& count
<= 9)
4241 info
->remainder
= count
- 8;
4246 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";
4248 case SHIFT_LSHIFTRT
:
4249 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";
4250 info
->shift1
= "shlr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0";
4252 case SHIFT_ASHIFTRT
:
4253 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";
4257 else if (count
== 8 && !TARGET_H8300
)
4262 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";
4264 case SHIFT_LSHIFTRT
:
4265 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";
4267 case SHIFT_ASHIFTRT
:
4268 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";
4272 else if (count
== 15 && TARGET_H8300
)
4278 case SHIFT_LSHIFTRT
:
4279 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";
4281 case SHIFT_ASHIFTRT
:
4282 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";
4286 else if (count
== 15 && !TARGET_H8300
)
4291 info
->special
= "shlr.w\t%e0\n\tmov.w\t%f0,%e0\n\txor.w\t%f0,%f0\n\trotxr.l\t%S0";
4292 info
->cc_special
= CC_SET_ZNV
;
4294 case SHIFT_LSHIFTRT
:
4295 info
->special
= "shll.w\t%f0\n\tmov.w\t%e0,%f0\n\txor.w\t%e0,%e0\n\trotxl.l\t%S0";
4296 info
->cc_special
= CC_SET_ZNV
;
4298 case SHIFT_ASHIFTRT
:
4302 else if ((TARGET_H8300
&& 16 <= count
&& count
<= 20)
4303 || (TARGET_H8300H
&& 16 <= count
&& count
<= 19)
4304 || (TARGET_H8300S
&& 16 <= count
&& count
<= 21))
4306 info
->remainder
= count
- 16;
4311 info
->special
= "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0";
4313 info
->shift1
= "add.w\t%e0,%e0";
4315 case SHIFT_LSHIFTRT
:
4318 info
->special
= "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0";
4319 info
->shift1
= "shlr\t%x0\n\trotxr\t%w0";
4323 info
->special
= "mov.w\t%e0,%f0\n\textu.l\t%S0";
4324 info
->cc_special
= CC_SET_ZNV
;
4327 case SHIFT_ASHIFTRT
:
4330 info
->special
= "mov.w\t%e0,%f0\n\tshll\t%z0\n\tsubx\t%z0,%z0\n\tmov.b\t%z0,%y0";
4331 info
->shift1
= "shar\t%x0\n\trotxr\t%w0";
4335 info
->special
= "mov.w\t%e0,%f0\n\texts.l\t%S0";
4336 info
->cc_special
= CC_SET_ZNV
;
4341 else if (TARGET_H8300
&& 24 <= count
&& count
<= 28)
4343 info
->remainder
= count
- 24;
4348 info
->special
= "mov.b\t%w0,%z0\n\tsub.b\t%y0,%y0\n\tsub.w\t%f0,%f0";
4349 info
->shift1
= "shll.b\t%z0";
4350 info
->cc_inline
= CC_SET_ZNV
;
4352 case SHIFT_LSHIFTRT
:
4353 info
->special
= "mov.b\t%z0,%w0\n\tsub.b\t%x0,%x0\n\tsub.w\t%e0,%e0";
4354 info
->shift1
= "shlr.b\t%w0";
4355 info
->cc_inline
= CC_SET_ZNV
;
4357 case SHIFT_ASHIFTRT
:
4358 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";
4359 info
->shift1
= "shar.b\t%w0";
4360 info
->cc_inline
= CC_SET_ZNV
;
4364 else if ((TARGET_H8300H
&& count
== 24)
4365 || (TARGET_H8300S
&& 24 <= count
&& count
<= 25))
4367 info
->remainder
= count
- 24;
4372 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";
4374 case SHIFT_LSHIFTRT
:
4375 info
->special
= "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\textu.w\t%f0\n\textu.l\t%S0";
4376 info
->cc_special
= CC_SET_ZNV
;
4378 case SHIFT_ASHIFTRT
:
4379 info
->special
= "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\texts.w\t%f0\n\texts.l\t%S0";
4380 info
->cc_special
= CC_SET_ZNV
;
4384 else if (!TARGET_H8300
&& count
== 28)
4390 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";
4392 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";
4394 case SHIFT_LSHIFTRT
:
4397 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";
4398 info
->cc_special
= CC_SET_ZNV
;
4401 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t#2,%S0\n\textu.l\t%S0";
4403 case SHIFT_ASHIFTRT
:
4407 else if (!TARGET_H8300
&& count
== 29)
4413 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";
4415 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
4417 case SHIFT_LSHIFTRT
:
4420 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";
4421 info
->cc_special
= CC_SET_ZNV
;
4425 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
4426 info
->cc_special
= CC_SET_ZNV
;
4429 case SHIFT_ASHIFTRT
:
4433 else if (!TARGET_H8300
&& count
== 30)
4439 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
4441 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\tsub.w\t%f0,%f0";
4443 case SHIFT_LSHIFTRT
:
4445 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
4447 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\textu.l\t%S0";
4449 case SHIFT_ASHIFTRT
:
4453 else if (count
== 31)
4460 info
->special
= "sub.w\t%e0,%e0\n\tshlr\t%w0\n\tmov.w\t%e0,%f0\n\trotxr\t%z0";
4462 case SHIFT_LSHIFTRT
:
4463 info
->special
= "sub.w\t%f0,%f0\n\tshll\t%z0\n\tmov.w\t%f0,%e0\n\trotxl\t%w0";
4465 case SHIFT_ASHIFTRT
:
4466 info
->special
= "shll\t%z0\n\tsubx\t%w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
4475 info
->special
= "shlr.l\t%S0\n\txor.l\t%S0,%S0\n\trotxr.l\t%S0";
4476 info
->cc_special
= CC_SET_ZNV
;
4478 case SHIFT_LSHIFTRT
:
4479 info
->special
= "shll.l\t%S0\n\txor.l\t%S0,%S0\n\trotxl.l\t%S0";
4480 info
->cc_special
= CC_SET_ZNV
;
4482 case SHIFT_ASHIFTRT
:
4483 info
->special
= "shll\t%e0\n\tsubx\t%w0,%w0\n\texts.w\t%T0\n\texts.l\t%S0";
4484 info
->cc_special
= CC_SET_ZNV
;
4497 info
->shift2
= NULL
;
4500 /* Given COUNT and MODE of a shift, return 1 if a scratch reg may be
4501 needed for some shift with COUNT and MODE. Return 0 otherwise. */
4504 h8300_shift_needs_scratch_p (int count
, enum machine_mode mode
)
4509 if (GET_MODE_BITSIZE (mode
) <= count
)
4512 /* Find out the target CPU. */
4515 else if (TARGET_H8300H
)
4520 /* Find the shift algorithm. */
4524 a
= shift_alg_qi
[cpu
][SHIFT_ASHIFT
][count
];
4525 lr
= shift_alg_qi
[cpu
][SHIFT_LSHIFTRT
][count
];
4526 ar
= shift_alg_qi
[cpu
][SHIFT_ASHIFTRT
][count
];
4530 a
= shift_alg_hi
[cpu
][SHIFT_ASHIFT
][count
];
4531 lr
= shift_alg_hi
[cpu
][SHIFT_LSHIFTRT
][count
];
4532 ar
= shift_alg_hi
[cpu
][SHIFT_ASHIFTRT
][count
];
4536 a
= shift_alg_si
[cpu
][SHIFT_ASHIFT
][count
];
4537 lr
= shift_alg_si
[cpu
][SHIFT_LSHIFTRT
][count
];
4538 ar
= shift_alg_si
[cpu
][SHIFT_ASHIFTRT
][count
];
4545 /* On H8/300H, count == 8 uses a scratch register. */
4546 return (a
== SHIFT_LOOP
|| lr
== SHIFT_LOOP
|| ar
== SHIFT_LOOP
4547 || (TARGET_H8300H
&& mode
== SImode
&& count
== 8));
4550 /* Output the assembler code for doing shifts. */
4553 output_a_shift (rtx
*operands
)
4555 static int loopend_lab
;
4556 rtx shift
= operands
[3];
4557 enum machine_mode mode
= GET_MODE (shift
);
4558 enum rtx_code code
= GET_CODE (shift
);
4559 enum shift_type shift_type
;
4560 enum shift_mode shift_mode
;
4561 struct shift_info info
;
4569 shift_mode
= QIshift
;
4572 shift_mode
= HIshift
;
4575 shift_mode
= SIshift
;
4584 shift_type
= SHIFT_ASHIFTRT
;
4587 shift_type
= SHIFT_LSHIFTRT
;
4590 shift_type
= SHIFT_ASHIFT
;
4596 /* This case must be taken care of by one of the two splitters
4597 that convert a variable shift into a loop. */
4598 gcc_assert (GET_CODE (operands
[2]) == CONST_INT
);
4600 n
= INTVAL (operands
[2]);
4602 /* If the count is negative, make it 0. */
4605 /* If the count is too big, truncate it.
4606 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4607 do the intuitive thing. */
4608 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4609 n
= GET_MODE_BITSIZE (mode
);
4611 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4616 output_asm_insn (info
.special
, operands
);
4622 /* Emit two bit shifts first. */
4623 if (info
.shift2
!= NULL
)
4625 for (; n
> 1; n
-= 2)
4626 output_asm_insn (info
.shift2
, operands
);
4629 /* Now emit one bit shifts for any residual. */
4631 output_asm_insn (info
.shift1
, operands
);
4636 int m
= GET_MODE_BITSIZE (mode
) - n
;
4637 const int mask
= (shift_type
== SHIFT_ASHIFT
4638 ? ((1 << m
) - 1) << n
4642 /* Not all possibilities of rotate are supported. They shouldn't
4643 be generated, but let's watch for 'em. */
4644 gcc_assert (info
.shift1
);
4646 /* Emit two bit rotates first. */
4647 if (info
.shift2
!= NULL
)
4649 for (; m
> 1; m
-= 2)
4650 output_asm_insn (info
.shift2
, operands
);
4653 /* Now single bit rotates for any residual. */
4655 output_asm_insn (info
.shift1
, operands
);
4657 /* Now mask off the high bits. */
4661 sprintf (insn_buf
, "and\t#%d,%%X0", mask
);
4665 gcc_assert (TARGET_H8300H
|| TARGET_H8300S
);
4666 sprintf (insn_buf
, "and.w\t#%d,%%T0", mask
);
4673 output_asm_insn (insn_buf
, operands
);
4678 /* A loop to shift by a "large" constant value.
4679 If we have shift-by-2 insns, use them. */
4680 if (info
.shift2
!= NULL
)
4682 fprintf (asm_out_file
, "\tmov.b #%d,%sl\n", n
/ 2,
4683 names_big
[REGNO (operands
[4])]);
4684 fprintf (asm_out_file
, ".Llt%d:\n", loopend_lab
);
4685 output_asm_insn (info
.shift2
, operands
);
4686 output_asm_insn ("add #0xff,%X4", operands
);
4687 fprintf (asm_out_file
, "\tbne .Llt%d\n", loopend_lab
);
4689 output_asm_insn (info
.shift1
, operands
);
4693 fprintf (asm_out_file
, "\tmov.b #%d,%sl\n", n
,
4694 names_big
[REGNO (operands
[4])]);
4695 fprintf (asm_out_file
, ".Llt%d:\n", loopend_lab
);
4696 output_asm_insn (info
.shift1
, operands
);
4697 output_asm_insn ("add #0xff,%X4", operands
);
4698 fprintf (asm_out_file
, "\tbne .Llt%d\n", loopend_lab
);
4707 /* Count the number of assembly instructions in a string TEMPL. */
4710 h8300_asm_insn_count (const char *templ
)
4712 unsigned int count
= 1;
4714 for (; *templ
; templ
++)
4721 /* Compute the length of a shift insn. */
4724 compute_a_shift_length (rtx insn ATTRIBUTE_UNUSED
, rtx
*operands
)
4726 rtx shift
= operands
[3];
4727 enum machine_mode mode
= GET_MODE (shift
);
4728 enum rtx_code code
= GET_CODE (shift
);
4729 enum shift_type shift_type
;
4730 enum shift_mode shift_mode
;
4731 struct shift_info info
;
4732 unsigned int wlength
= 0;
4737 shift_mode
= QIshift
;
4740 shift_mode
= HIshift
;
4743 shift_mode
= SIshift
;
4752 shift_type
= SHIFT_ASHIFTRT
;
4755 shift_type
= SHIFT_LSHIFTRT
;
4758 shift_type
= SHIFT_ASHIFT
;
4764 if (GET_CODE (operands
[2]) != CONST_INT
)
4766 /* Get the assembler code to do one shift. */
4767 get_shift_alg (shift_type
, shift_mode
, 1, &info
);
4769 return (4 + h8300_asm_insn_count (info
.shift1
)) * 2;
4773 int n
= INTVAL (operands
[2]);
4775 /* If the count is negative, make it 0. */
4778 /* If the count is too big, truncate it.
4779 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4780 do the intuitive thing. */
4781 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4782 n
= GET_MODE_BITSIZE (mode
);
4784 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4789 wlength
+= h8300_asm_insn_count (info
.special
);
4791 /* Every assembly instruction used in SHIFT_SPECIAL case
4792 takes 2 bytes except xor.l, which takes 4 bytes, so if we
4793 see xor.l, we just pretend that xor.l counts as two insns
4794 so that the insn length will be computed correctly. */
4795 if (strstr (info
.special
, "xor.l") != NULL
)
4803 if (info
.shift2
!= NULL
)
4805 wlength
+= h8300_asm_insn_count (info
.shift2
) * (n
/ 2);
4809 wlength
+= h8300_asm_insn_count (info
.shift1
) * n
;
4815 int m
= GET_MODE_BITSIZE (mode
) - n
;
4817 /* Not all possibilities of rotate are supported. They shouldn't
4818 be generated, but let's watch for 'em. */
4819 gcc_assert (info
.shift1
);
4821 if (info
.shift2
!= NULL
)
4823 wlength
+= h8300_asm_insn_count (info
.shift2
) * (m
/ 2);
4827 wlength
+= h8300_asm_insn_count (info
.shift1
) * m
;
4829 /* Now mask off the high bits. */
4839 gcc_assert (!TARGET_H8300
);
4849 /* A loop to shift by a "large" constant value.
4850 If we have shift-by-2 insns, use them. */
4851 if (info
.shift2
!= NULL
)
4853 wlength
+= 3 + h8300_asm_insn_count (info
.shift2
);
4855 wlength
+= h8300_asm_insn_count (info
.shift1
);
4859 wlength
+= 3 + h8300_asm_insn_count (info
.shift1
);
4869 /* Compute which flag bits are valid after a shift insn. */
4872 compute_a_shift_cc (rtx insn ATTRIBUTE_UNUSED
, rtx
*operands
)
4874 rtx shift
= operands
[3];
4875 enum machine_mode mode
= GET_MODE (shift
);
4876 enum rtx_code code
= GET_CODE (shift
);
4877 enum shift_type shift_type
;
4878 enum shift_mode shift_mode
;
4879 struct shift_info info
;
4885 shift_mode
= QIshift
;
4888 shift_mode
= HIshift
;
4891 shift_mode
= SIshift
;
4900 shift_type
= SHIFT_ASHIFTRT
;
4903 shift_type
= SHIFT_LSHIFTRT
;
4906 shift_type
= SHIFT_ASHIFT
;
4912 /* This case must be taken care of by one of the two splitters
4913 that convert a variable shift into a loop. */
4914 gcc_assert (GET_CODE (operands
[2]) == CONST_INT
);
4916 n
= INTVAL (operands
[2]);
4918 /* If the count is negative, make it 0. */
4921 /* If the count is too big, truncate it.
4922 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4923 do the intuitive thing. */
4924 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4925 n
= GET_MODE_BITSIZE (mode
);
4927 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4932 if (info
.remainder
== 0)
4933 return info
.cc_special
;
4938 return info
.cc_inline
;
4941 /* This case always ends with an and instruction. */
4945 /* A loop to shift by a "large" constant value.
4946 If we have shift-by-2 insns, use them. */
4947 if (info
.shift2
!= NULL
)
4950 return info
.cc_inline
;
4959 /* A rotation by a non-constant will cause a loop to be generated, in
4960 which a rotation by one bit is used. A rotation by a constant,
4961 including the one in the loop, will be taken care of by
4962 output_a_rotate () at the insn emit time. */
4965 expand_a_rotate (rtx operands
[])
4967 rtx dst
= operands
[0];
4968 rtx src
= operands
[1];
4969 rtx rotate_amount
= operands
[2];
4970 enum machine_mode mode
= GET_MODE (dst
);
4972 if (h8sx_classify_shift (mode
, ROTATE
, rotate_amount
) == H8SX_SHIFT_UNARY
)
4975 /* We rotate in place. */
4976 emit_move_insn (dst
, src
);
4978 if (GET_CODE (rotate_amount
) != CONST_INT
)
4980 rtx counter
= gen_reg_rtx (QImode
);
4981 rtx start_label
= gen_label_rtx ();
4982 rtx end_label
= gen_label_rtx ();
4984 /* If the rotate amount is less than or equal to 0,
4985 we go out of the loop. */
4986 emit_cmp_and_jump_insns (rotate_amount
, const0_rtx
, LE
, NULL_RTX
,
4987 QImode
, 0, end_label
);
4989 /* Initialize the loop counter. */
4990 emit_move_insn (counter
, rotate_amount
);
4992 emit_label (start_label
);
4994 /* Rotate by one bit. */
4998 emit_insn (gen_rotlqi3_1 (dst
, dst
, const1_rtx
));
5001 emit_insn (gen_rotlhi3_1 (dst
, dst
, const1_rtx
));
5004 emit_insn (gen_rotlsi3_1 (dst
, dst
, const1_rtx
));
5010 /* Decrement the counter by 1. */
5011 emit_insn (gen_addqi3 (counter
, counter
, constm1_rtx
));
5013 /* If the loop counter is nonzero, we go back to the beginning
5015 emit_cmp_and_jump_insns (counter
, const0_rtx
, NE
, NULL_RTX
, QImode
, 1,
5018 emit_label (end_label
);
5022 /* Rotate by AMOUNT bits. */
5026 emit_insn (gen_rotlqi3_1 (dst
, dst
, rotate_amount
));
5029 emit_insn (gen_rotlhi3_1 (dst
, dst
, rotate_amount
));
5032 emit_insn (gen_rotlsi3_1 (dst
, dst
, rotate_amount
));
5042 /* Output a rotate insn. */
5045 output_a_rotate (enum rtx_code code
, rtx
*operands
)
5047 rtx dst
= operands
[0];
5048 rtx rotate_amount
= operands
[2];
5049 enum shift_mode rotate_mode
;
5050 enum shift_type rotate_type
;
5051 const char *insn_buf
;
5054 enum machine_mode mode
= GET_MODE (dst
);
5056 gcc_assert (GET_CODE (rotate_amount
) == CONST_INT
);
5061 rotate_mode
= QIshift
;
5064 rotate_mode
= HIshift
;
5067 rotate_mode
= SIshift
;
5076 rotate_type
= SHIFT_ASHIFT
;
5079 rotate_type
= SHIFT_LSHIFTRT
;
5085 amount
= INTVAL (rotate_amount
);
5087 /* Clean up AMOUNT. */
5090 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
))
5091 amount
= GET_MODE_BITSIZE (mode
);
5093 /* Determine the faster direction. After this phase, amount will be
5094 at most a half of GET_MODE_BITSIZE (mode). */
5095 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
) / (unsigned) 2)
5097 /* Flip the direction. */
5098 amount
= GET_MODE_BITSIZE (mode
) - amount
;
5100 (rotate_type
== SHIFT_ASHIFT
) ? SHIFT_LSHIFTRT
: SHIFT_ASHIFT
;
5103 /* See if a byte swap (in HImode) or a word swap (in SImode) can
5104 boost up the rotation. */
5105 if ((mode
== HImode
&& TARGET_H8300
&& amount
>= 5)
5106 || (mode
== HImode
&& TARGET_H8300H
&& amount
>= 6)
5107 || (mode
== HImode
&& TARGET_H8300S
&& amount
== 8)
5108 || (mode
== SImode
&& TARGET_H8300H
&& amount
>= 10)
5109 || (mode
== SImode
&& TARGET_H8300S
&& amount
>= 13))
5114 /* This code works on any family. */
5115 insn_buf
= "xor.b\t%s0,%t0\n\txor.b\t%t0,%s0\n\txor.b\t%s0,%t0";
5116 output_asm_insn (insn_buf
, operands
);
5120 /* This code works on the H8/300H and H8S. */
5121 insn_buf
= "xor.w\t%e0,%f0\n\txor.w\t%f0,%e0\n\txor.w\t%e0,%f0";
5122 output_asm_insn (insn_buf
, operands
);
5129 /* Adjust AMOUNT and flip the direction. */
5130 amount
= GET_MODE_BITSIZE (mode
) / 2 - amount
;
5132 (rotate_type
== SHIFT_ASHIFT
) ? SHIFT_LSHIFTRT
: SHIFT_ASHIFT
;
5135 /* Output rotate insns. */
5136 for (bits
= TARGET_H8300S
? 2 : 1; bits
> 0; bits
/= 2)
5139 insn_buf
= rotate_two
[rotate_type
][rotate_mode
];
5141 insn_buf
= rotate_one
[cpu_type
][rotate_type
][rotate_mode
];
5143 for (; amount
>= bits
; amount
-= bits
)
5144 output_asm_insn (insn_buf
, operands
);
5150 /* Compute the length of a rotate insn. */
5153 compute_a_rotate_length (rtx
*operands
)
5155 rtx src
= operands
[1];
5156 rtx amount_rtx
= operands
[2];
5157 enum machine_mode mode
= GET_MODE (src
);
5159 unsigned int length
= 0;
5161 gcc_assert (GET_CODE (amount_rtx
) == CONST_INT
);
5163 amount
= INTVAL (amount_rtx
);
5165 /* Clean up AMOUNT. */
5168 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
))
5169 amount
= GET_MODE_BITSIZE (mode
);
5171 /* Determine the faster direction. After this phase, amount
5172 will be at most a half of GET_MODE_BITSIZE (mode). */
5173 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
) / (unsigned) 2)
5174 /* Flip the direction. */
5175 amount
= GET_MODE_BITSIZE (mode
) - amount
;
5177 /* See if a byte swap (in HImode) or a word swap (in SImode) can
5178 boost up the rotation. */
5179 if ((mode
== HImode
&& TARGET_H8300
&& amount
>= 5)
5180 || (mode
== HImode
&& TARGET_H8300H
&& amount
>= 6)
5181 || (mode
== HImode
&& TARGET_H8300S
&& amount
== 8)
5182 || (mode
== SImode
&& TARGET_H8300H
&& amount
>= 10)
5183 || (mode
== SImode
&& TARGET_H8300S
&& amount
>= 13))
5185 /* Adjust AMOUNT and flip the direction. */
5186 amount
= GET_MODE_BITSIZE (mode
) / 2 - amount
;
5190 /* We use 2-bit rotations on the H8S. */
5192 amount
= amount
/ 2 + amount
% 2;
5194 /* The H8/300 uses three insns to rotate one bit, taking 6
5196 length
+= amount
* ((TARGET_H8300
&& mode
== HImode
) ? 6 : 2);
5201 /* Fix the operands of a gen_xxx so that it could become a bit
5205 fix_bit_operand (rtx
*operands
, enum rtx_code code
)
5207 /* The bit_operand predicate accepts any memory during RTL generation, but
5208 only 'U' memory afterwards, so if this is a MEM operand, we must force
5209 it to be valid for 'U' by reloading the address. */
5212 ? single_zero_operand (operands
[2], QImode
)
5213 : single_one_operand (operands
[2], QImode
))
5215 /* OK to have a memory dest. */
5216 if (GET_CODE (operands
[0]) == MEM
5217 && !satisfies_constraint_U (operands
[0]))
5219 rtx mem
= gen_rtx_MEM (GET_MODE (operands
[0]),
5220 copy_to_mode_reg (Pmode
,
5221 XEXP (operands
[0], 0)));
5222 MEM_COPY_ATTRIBUTES (mem
, operands
[0]);
5226 if (GET_CODE (operands
[1]) == MEM
5227 && !satisfies_constraint_U (operands
[1]))
5229 rtx mem
= gen_rtx_MEM (GET_MODE (operands
[1]),
5230 copy_to_mode_reg (Pmode
,
5231 XEXP (operands
[1], 0)));
5232 MEM_COPY_ATTRIBUTES (mem
, operands
[0]);
5238 /* Dest and src op must be register. */
5240 operands
[1] = force_reg (QImode
, operands
[1]);
5242 rtx res
= gen_reg_rtx (QImode
);
5246 emit_insn (gen_andqi3_1 (res
, operands
[1], operands
[2]));
5249 emit_insn (gen_iorqi3_1 (res
, operands
[1], operands
[2]));
5252 emit_insn (gen_xorqi3_1 (res
, operands
[1], operands
[2]));
5257 emit_insn (gen_movqi (operands
[0], res
));
5262 /* Return nonzero if FUNC is an interrupt function as specified
5263 by the "interrupt" attribute. */
5266 h8300_interrupt_function_p (tree func
)
5270 if (TREE_CODE (func
) != FUNCTION_DECL
)
5273 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
5274 return a
!= NULL_TREE
;
5277 /* Return nonzero if FUNC is a saveall function as specified by the
5278 "saveall" attribute. */
5281 h8300_saveall_function_p (tree func
)
5285 if (TREE_CODE (func
) != FUNCTION_DECL
)
5288 a
= lookup_attribute ("saveall", DECL_ATTRIBUTES (func
));
5289 return a
!= NULL_TREE
;
5292 /* Return nonzero if FUNC is an OS_Task function as specified
5293 by the "OS_Task" attribute. */
5296 h8300_os_task_function_p (tree func
)
5300 if (TREE_CODE (func
) != FUNCTION_DECL
)
5303 a
= lookup_attribute ("OS_Task", DECL_ATTRIBUTES (func
));
5304 return a
!= NULL_TREE
;
5307 /* Return nonzero if FUNC is a monitor function as specified
5308 by the "monitor" attribute. */
5311 h8300_monitor_function_p (tree func
)
5315 if (TREE_CODE (func
) != FUNCTION_DECL
)
5318 a
= lookup_attribute ("monitor", DECL_ATTRIBUTES (func
));
5319 return a
!= NULL_TREE
;
5322 /* Return nonzero if FUNC is a function that should be called
5323 through the function vector. */
5326 h8300_funcvec_function_p (tree func
)
5330 if (TREE_CODE (func
) != FUNCTION_DECL
)
5333 a
= lookup_attribute ("function_vector", DECL_ATTRIBUTES (func
));
5334 return a
!= NULL_TREE
;
5337 /* Return nonzero if DECL is a variable that's in the eight bit
5341 h8300_eightbit_data_p (tree decl
)
5345 if (TREE_CODE (decl
) != VAR_DECL
)
5348 a
= lookup_attribute ("eightbit_data", DECL_ATTRIBUTES (decl
));
5349 return a
!= NULL_TREE
;
5352 /* Return nonzero if DECL is a variable that's in the tiny
5356 h8300_tiny_data_p (tree decl
)
5360 if (TREE_CODE (decl
) != VAR_DECL
)
5363 a
= lookup_attribute ("tiny_data", DECL_ATTRIBUTES (decl
));
5364 return a
!= NULL_TREE
;
5367 /* Generate an 'interrupt_handler' attribute for decls. We convert
5368 all the pragmas to corresponding attributes. */
5371 h8300_insert_attributes (tree node
, tree
*attributes
)
5373 if (TREE_CODE (node
) == FUNCTION_DECL
)
5375 if (pragma_interrupt
)
5377 pragma_interrupt
= 0;
5379 /* Add an 'interrupt_handler' attribute. */
5380 *attributes
= tree_cons (get_identifier ("interrupt_handler"),
5388 /* Add an 'saveall' attribute. */
5389 *attributes
= tree_cons (get_identifier ("saveall"),
5395 /* Supported attributes:
5397 interrupt_handler: output a prologue and epilogue suitable for an
5400 saveall: output a prologue and epilogue that saves and restores
5401 all registers except the stack pointer.
5403 function_vector: This function should be called through the
5406 eightbit_data: This variable lives in the 8-bit data area and can
5407 be referenced with 8-bit absolute memory addresses.
5409 tiny_data: This variable lives in the tiny data area and can be
5410 referenced with 16-bit absolute memory references. */
5412 static const struct attribute_spec h8300_attribute_table
[] =
5414 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
5415 affects_type_identity } */
5416 { "interrupt_handler", 0, 0, true, false, false,
5417 h8300_handle_fndecl_attribute
, false },
5418 { "saveall", 0, 0, true, false, false,
5419 h8300_handle_fndecl_attribute
, false },
5420 { "OS_Task", 0, 0, true, false, false,
5421 h8300_handle_fndecl_attribute
, false },
5422 { "monitor", 0, 0, true, false, false,
5423 h8300_handle_fndecl_attribute
, false },
5424 { "function_vector", 0, 0, true, false, false,
5425 h8300_handle_fndecl_attribute
, false },
5426 { "eightbit_data", 0, 0, true, false, false,
5427 h8300_handle_eightbit_data_attribute
, false },
5428 { "tiny_data", 0, 0, true, false, false,
5429 h8300_handle_tiny_data_attribute
, false },
5430 { NULL
, 0, 0, false, false, false, NULL
, false }
5434 /* Handle an attribute requiring a FUNCTION_DECL; arguments as in
5435 struct attribute_spec.handler. */
5437 h8300_handle_fndecl_attribute (tree
*node
, tree name
,
5438 tree args ATTRIBUTE_UNUSED
,
5439 int flags ATTRIBUTE_UNUSED
,
5442 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5444 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
5446 *no_add_attrs
= true;
5452 /* Handle an "eightbit_data" attribute; arguments as in
5453 struct attribute_spec.handler. */
5455 h8300_handle_eightbit_data_attribute (tree
*node
, tree name
,
5456 tree args ATTRIBUTE_UNUSED
,
5457 int flags ATTRIBUTE_UNUSED
,
5462 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
5464 set_decl_section_name (decl
, ".eight");
5468 warning (OPT_Wattributes
, "%qE attribute ignored",
5470 *no_add_attrs
= true;
5476 /* Handle an "tiny_data" attribute; arguments as in
5477 struct attribute_spec.handler. */
5479 h8300_handle_tiny_data_attribute (tree
*node
, tree name
,
5480 tree args ATTRIBUTE_UNUSED
,
5481 int flags ATTRIBUTE_UNUSED
,
5486 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
5488 set_decl_section_name (decl
, ".tiny");
5492 warning (OPT_Wattributes
, "%qE attribute ignored",
5494 *no_add_attrs
= true;
5500 /* Mark function vectors, and various small data objects. */
5503 h8300_encode_section_info (tree decl
, rtx rtl
, int first
)
5505 int extra_flags
= 0;
5507 default_encode_section_info (decl
, rtl
, first
);
5509 if (TREE_CODE (decl
) == FUNCTION_DECL
5510 && h8300_funcvec_function_p (decl
))
5511 extra_flags
= SYMBOL_FLAG_FUNCVEC_FUNCTION
;
5512 else if (TREE_CODE (decl
) == VAR_DECL
5513 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
5515 if (h8300_eightbit_data_p (decl
))
5516 extra_flags
= SYMBOL_FLAG_EIGHTBIT_DATA
;
5517 else if (first
&& h8300_tiny_data_p (decl
))
5518 extra_flags
= SYMBOL_FLAG_TINY_DATA
;
5522 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= extra_flags
;
5525 /* Output a single-bit extraction. */
5528 output_simode_bld (int bild
, rtx operands
[])
5532 /* Clear the destination register. */
5533 output_asm_insn ("sub.w\t%e0,%e0\n\tsub.w\t%f0,%f0", operands
);
5535 /* Now output the bit load or bit inverse load, and store it in
5538 output_asm_insn ("bild\t%Z2,%Y1", operands
);
5540 output_asm_insn ("bld\t%Z2,%Y1", operands
);
5542 output_asm_insn ("bst\t#0,%w0", operands
);
5546 /* Determine if we can clear the destination first. */
5547 int clear_first
= (REG_P (operands
[0]) && REG_P (operands
[1])
5548 && REGNO (operands
[0]) != REGNO (operands
[1]));
5551 output_asm_insn ("sub.l\t%S0,%S0", operands
);
5553 /* Output the bit load or bit inverse load. */
5555 output_asm_insn ("bild\t%Z2,%Y1", operands
);
5557 output_asm_insn ("bld\t%Z2,%Y1", operands
);
5560 output_asm_insn ("xor.l\t%S0,%S0", operands
);
5562 /* Perform the bit store. */
5563 output_asm_insn ("rotxl.l\t%S0", operands
);
5570 /* Delayed-branch scheduling is more effective if we have some idea
5571 how long each instruction will be. Use a shorten_branches pass
5572 to get an initial estimate. */
5577 if (flag_delayed_branch
)
5578 shorten_branches (get_insns ());
5581 #ifndef OBJECT_FORMAT_ELF
5583 h8300_asm_named_section (const char *name
, unsigned int flags ATTRIBUTE_UNUSED
,
5586 /* ??? Perhaps we should be using default_coff_asm_named_section. */
5587 fprintf (asm_out_file
, "\t.section %s\n", name
);
5589 #endif /* ! OBJECT_FORMAT_ELF */
5591 /* Nonzero if X is a constant address suitable as an 8-bit absolute,
5592 which is a special case of the 'R' operand. */
5595 h8300_eightbit_constant_address_p (rtx x
)
5597 /* The ranges of the 8-bit area. */
5598 const unsigned HOST_WIDE_INT n1
= trunc_int_for_mode (0xff00, HImode
);
5599 const unsigned HOST_WIDE_INT n2
= trunc_int_for_mode (0xffff, HImode
);
5600 const unsigned HOST_WIDE_INT h1
= trunc_int_for_mode (0x00ffff00, SImode
);
5601 const unsigned HOST_WIDE_INT h2
= trunc_int_for_mode (0x00ffffff, SImode
);
5602 const unsigned HOST_WIDE_INT s1
= trunc_int_for_mode (0xffffff00, SImode
);
5603 const unsigned HOST_WIDE_INT s2
= trunc_int_for_mode (0xffffffff, SImode
);
5605 unsigned HOST_WIDE_INT addr
;
5607 /* We accept symbols declared with eightbit_data. */
5608 if (GET_CODE (x
) == SYMBOL_REF
)
5609 return (SYMBOL_REF_FLAGS (x
) & SYMBOL_FLAG_EIGHTBIT_DATA
) != 0;
5611 if (GET_CODE (x
) != CONST_INT
)
5617 || ((TARGET_H8300
|| TARGET_NORMAL_MODE
) && IN_RANGE (addr
, n1
, n2
))
5618 || (TARGET_H8300H
&& IN_RANGE (addr
, h1
, h2
))
5619 || (TARGET_H8300S
&& IN_RANGE (addr
, s1
, s2
)));
5622 /* Nonzero if X is a constant address suitable as an 16-bit absolute
5623 on H8/300H and H8S. */
5626 h8300_tiny_constant_address_p (rtx x
)
5628 /* The ranges of the 16-bit area. */
5629 const unsigned HOST_WIDE_INT h1
= trunc_int_for_mode (0x00000000, SImode
);
5630 const unsigned HOST_WIDE_INT h2
= trunc_int_for_mode (0x00007fff, SImode
);
5631 const unsigned HOST_WIDE_INT h3
= trunc_int_for_mode (0x00ff8000, SImode
);
5632 const unsigned HOST_WIDE_INT h4
= trunc_int_for_mode (0x00ffffff, SImode
);
5633 const unsigned HOST_WIDE_INT s1
= trunc_int_for_mode (0x00000000, SImode
);
5634 const unsigned HOST_WIDE_INT s2
= trunc_int_for_mode (0x00007fff, SImode
);
5635 const unsigned HOST_WIDE_INT s3
= trunc_int_for_mode (0xffff8000, SImode
);
5636 const unsigned HOST_WIDE_INT s4
= trunc_int_for_mode (0xffffffff, SImode
);
5638 unsigned HOST_WIDE_INT addr
;
5640 switch (GET_CODE (x
))
5643 /* In the normal mode, any symbol fits in the 16-bit absolute
5644 address range. We also accept symbols declared with
5646 return (TARGET_NORMAL_MODE
5647 || (SYMBOL_REF_FLAGS (x
) & SYMBOL_FLAG_TINY_DATA
) != 0);
5651 return (TARGET_NORMAL_MODE
5653 && (IN_RANGE (addr
, h1
, h2
) || IN_RANGE (addr
, h3
, h4
)))
5655 && (IN_RANGE (addr
, s1
, s2
) || IN_RANGE (addr
, s3
, s4
))));
5658 return TARGET_NORMAL_MODE
;
5666 /* Return nonzero if ADDR1 and ADDR2 point to consecutive memory
5667 locations that can be accessed as a 16-bit word. */
5670 byte_accesses_mergeable_p (rtx addr1
, rtx addr2
)
5672 HOST_WIDE_INT offset1
, offset2
;
5680 else if (GET_CODE (addr1
) == PLUS
5681 && REG_P (XEXP (addr1
, 0))
5682 && GET_CODE (XEXP (addr1
, 1)) == CONST_INT
)
5684 reg1
= XEXP (addr1
, 0);
5685 offset1
= INTVAL (XEXP (addr1
, 1));
5695 else if (GET_CODE (addr2
) == PLUS
5696 && REG_P (XEXP (addr2
, 0))
5697 && GET_CODE (XEXP (addr2
, 1)) == CONST_INT
)
5699 reg2
= XEXP (addr2
, 0);
5700 offset2
= INTVAL (XEXP (addr2
, 1));
5705 if (((reg1
== stack_pointer_rtx
&& reg2
== stack_pointer_rtx
)
5706 || (reg1
== frame_pointer_rtx
&& reg2
== frame_pointer_rtx
))
5708 && offset1
+ 1 == offset2
)
5714 /* Return nonzero if we have the same comparison insn as I3 two insns
5715 before I3. I3 is assumed to be a comparison insn. */
5718 same_cmp_preceding_p (rtx i3
)
5722 /* Make sure we have a sequence of three insns. */
5723 i2
= prev_nonnote_insn (i3
);
5726 i1
= prev_nonnote_insn (i2
);
5730 return (INSN_P (i1
) && rtx_equal_p (PATTERN (i1
), PATTERN (i3
))
5731 && any_condjump_p (i2
) && onlyjump_p (i2
));
5734 /* Return nonzero if we have the same comparison insn as I1 two insns
5735 after I1. I1 is assumed to be a comparison insn. */
5738 same_cmp_following_p (rtx i1
)
5742 /* Make sure we have a sequence of three insns. */
5743 i2
= next_nonnote_insn (i1
);
5746 i3
= next_nonnote_insn (i2
);
5750 return (INSN_P (i3
) && rtx_equal_p (PATTERN (i1
), PATTERN (i3
))
5751 && any_condjump_p (i2
) && onlyjump_p (i2
));
5754 /* Return nonzero if OPERANDS are valid for stm (or ldm) that pushes
5755 (or pops) N registers. OPERANDS are assumed to be an array of
5759 h8300_regs_ok_for_stm (int n
, rtx operands
[])
5764 return ((REGNO (operands
[0]) == 0 && REGNO (operands
[1]) == 1)
5765 || (REGNO (operands
[0]) == 2 && REGNO (operands
[1]) == 3)
5766 || (REGNO (operands
[0]) == 4 && REGNO (operands
[1]) == 5));
5768 return ((REGNO (operands
[0]) == 0
5769 && REGNO (operands
[1]) == 1
5770 && REGNO (operands
[2]) == 2)
5771 || (REGNO (operands
[0]) == 4
5772 && REGNO (operands
[1]) == 5
5773 && REGNO (operands
[2]) == 6));
5776 return (REGNO (operands
[0]) == 0
5777 && REGNO (operands
[1]) == 1
5778 && REGNO (operands
[2]) == 2
5779 && REGNO (operands
[3]) == 3);
5785 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
5788 h8300_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED
,
5789 unsigned int new_reg
)
5791 /* Interrupt functions can only use registers that have already been
5792 saved by the prologue, even if they would normally be
5795 if (h8300_current_function_interrupt_function_p ()
5796 && !df_regs_ever_live_p (new_reg
))
5802 /* Returns true if register REGNO is safe to be allocated as a scratch
5803 register in the current function. */
5806 h8300_hard_regno_scratch_ok (unsigned int regno
)
5808 if (h8300_current_function_interrupt_function_p ()
5809 && ! WORD_REG_USED (regno
))
5816 /* Return nonzero if X is a REG or SUBREG suitable as a base register. */
5819 h8300_rtx_ok_for_base_p (rtx x
, int strict
)
5821 /* Strip off SUBREG if any. */
5822 if (GET_CODE (x
) == SUBREG
)
5827 ? REG_OK_FOR_BASE_STRICT_P (x
)
5828 : REG_OK_FOR_BASE_NONSTRICT_P (x
)));
5831 /* Return nozero if X is a legitimate address. On the H8/300, a
5832 legitimate address has the form REG, REG+CONSTANT_ADDRESS or
5833 CONSTANT_ADDRESS. */
5836 h8300_legitimate_address_p (enum machine_mode mode
, rtx x
, bool strict
)
5838 /* The register indirect addresses like @er0 is always valid. */
5839 if (h8300_rtx_ok_for_base_p (x
, strict
))
5842 if (CONSTANT_ADDRESS_P (x
))
5846 && ( GET_CODE (x
) == PRE_INC
5847 || GET_CODE (x
) == PRE_DEC
5848 || GET_CODE (x
) == POST_INC
5849 || GET_CODE (x
) == POST_DEC
)
5850 && h8300_rtx_ok_for_base_p (XEXP (x
, 0), strict
))
5853 if (GET_CODE (x
) == PLUS
5854 && CONSTANT_ADDRESS_P (XEXP (x
, 1))
5855 && h8300_rtx_ok_for_base_p (h8300_get_index (XEXP (x
, 0),
5862 /* Worker function for HARD_REGNO_NREGS.
5864 We pretend the MAC register is 32bits -- we don't have any data
5865 types on the H8 series to handle more than 32bits. */
5868 h8300_hard_regno_nregs (int regno ATTRIBUTE_UNUSED
, enum machine_mode mode
)
5870 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
5873 /* Worker function for HARD_REGNO_MODE_OK. */
5876 h8300_hard_regno_mode_ok (int regno
, enum machine_mode mode
)
5879 /* If an even reg, then anything goes. Otherwise the mode must be
5881 return ((regno
& 1) == 0) || (mode
== HImode
) || (mode
== QImode
);
5883 /* MAC register can only be of SImode. Otherwise, anything
5885 return regno
== MAC_REG
? mode
== SImode
: 1;
5888 /* Helper function for the move patterns. Make sure a move is legitimate. */
5891 h8300_move_ok (rtx dest
, rtx src
)
5895 /* Validate that at least one operand is a register. */
5898 if (MEM_P (src
) || CONSTANT_P (src
))
5900 addr
= XEXP (dest
, 0);
5903 else if (MEM_P (src
))
5905 addr
= XEXP (src
, 0);
5911 /* Validate that auto-inc doesn't affect OTHER. */
5912 if (GET_RTX_CLASS (GET_CODE (addr
)) != RTX_AUTOINC
)
5914 addr
= XEXP (addr
, 0);
5916 if (addr
== stack_pointer_rtx
)
5917 return register_no_sp_elim_operand (other
, VOIDmode
);
5919 return !reg_overlap_mentioned_p(other
, addr
);
5922 /* Perform target dependent optabs initialization. */
5924 h8300_init_libfuncs (void)
5926 set_optab_libfunc (smul_optab
, HImode
, "__mulhi3");
5927 set_optab_libfunc (sdiv_optab
, HImode
, "__divhi3");
5928 set_optab_libfunc (udiv_optab
, HImode
, "__udivhi3");
5929 set_optab_libfunc (smod_optab
, HImode
, "__modhi3");
5930 set_optab_libfunc (umod_optab
, HImode
, "__umodhi3");
5933 /* Worker function for TARGET_FUNCTION_VALUE.
5935 On the H8 the return value is in R0/R1. */
5938 h8300_function_value (const_tree ret_type
,
5939 const_tree fn_decl_or_type ATTRIBUTE_UNUSED
,
5940 bool outgoing ATTRIBUTE_UNUSED
)
5942 return gen_rtx_REG (TYPE_MODE (ret_type
), R0_REG
);
5945 /* Worker function for TARGET_LIBCALL_VALUE.
5947 On the H8 the return value is in R0/R1. */
5950 h8300_libcall_value (enum machine_mode mode
, const_rtx fun ATTRIBUTE_UNUSED
)
5952 return gen_rtx_REG (mode
, R0_REG
);
5955 /* Worker function for TARGET_FUNCTION_VALUE_REGNO_P.
5957 On the H8, R0 is the only register thus used. */
5960 h8300_function_value_regno_p (const unsigned int regno
)
5962 return (regno
== R0_REG
);
5965 /* Worker function for TARGET_RETURN_IN_MEMORY. */
5968 h8300_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
5970 return (TYPE_MODE (type
) == BLKmode
5971 || GET_MODE_SIZE (TYPE_MODE (type
)) > (TARGET_H8300
? 4 : 8));
5974 /* We emit the entire trampoline here. Depending on the pointer size,
5975 we use a different trampoline.
5979 1 0000 7903xxxx mov.w #0x1234,r3
5980 2 0004 5A00xxxx jmp @0x1234
5985 2 0000 7A03xxxxxxxx mov.l #0x12345678,er3
5986 3 0006 5Axxxxxx jmp @0x123456
5991 h8300_trampoline_init (rtx m_tramp
, tree fndecl
, rtx cxt
)
5993 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
5996 if (Pmode
== HImode
)
5998 mem
= adjust_address (m_tramp
, HImode
, 0);
5999 emit_move_insn (mem
, GEN_INT (0x7903));
6000 mem
= adjust_address (m_tramp
, Pmode
, 2);
6001 emit_move_insn (mem
, cxt
);
6002 mem
= adjust_address (m_tramp
, HImode
, 4);
6003 emit_move_insn (mem
, GEN_INT (0x5a00));
6004 mem
= adjust_address (m_tramp
, Pmode
, 6);
6005 emit_move_insn (mem
, fnaddr
);
6011 mem
= adjust_address (m_tramp
, HImode
, 0);
6012 emit_move_insn (mem
, GEN_INT (0x7a03));
6013 mem
= adjust_address (m_tramp
, Pmode
, 2);
6014 emit_move_insn (mem
, cxt
);
6016 tem
= copy_to_reg (fnaddr
);
6017 emit_insn (gen_andsi3 (tem
, tem
, GEN_INT (0x00ffffff)));
6018 emit_insn (gen_iorsi3 (tem
, tem
, GEN_INT (0x5a000000)));
6019 mem
= adjust_address (m_tramp
, SImode
, 6);
6020 emit_move_insn (mem
, tem
);
6024 /* Initialize the GCC target structure. */
6025 #undef TARGET_ATTRIBUTE_TABLE
6026 #define TARGET_ATTRIBUTE_TABLE h8300_attribute_table
6028 #undef TARGET_ASM_ALIGNED_HI_OP
6029 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
6031 #undef TARGET_ASM_FILE_START
6032 #define TARGET_ASM_FILE_START h8300_file_start
6033 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
6034 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
6036 #undef TARGET_ASM_FILE_END
6037 #define TARGET_ASM_FILE_END h8300_file_end
6039 #undef TARGET_PRINT_OPERAND
6040 #define TARGET_PRINT_OPERAND h8300_print_operand
6041 #undef TARGET_PRINT_OPERAND_ADDRESS
6042 #define TARGET_PRINT_OPERAND_ADDRESS h8300_print_operand_address
6043 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
6044 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P h8300_print_operand_punct_valid_p
6046 #undef TARGET_ENCODE_SECTION_INFO
6047 #define TARGET_ENCODE_SECTION_INFO h8300_encode_section_info
6049 #undef TARGET_INSERT_ATTRIBUTES
6050 #define TARGET_INSERT_ATTRIBUTES h8300_insert_attributes
6052 #undef TARGET_REGISTER_MOVE_COST
6053 #define TARGET_REGISTER_MOVE_COST h8300_register_move_cost
6055 #undef TARGET_RTX_COSTS
6056 #define TARGET_RTX_COSTS h8300_rtx_costs
6058 #undef TARGET_INIT_LIBFUNCS
6059 #define TARGET_INIT_LIBFUNCS h8300_init_libfuncs
6061 #undef TARGET_FUNCTION_VALUE
6062 #define TARGET_FUNCTION_VALUE h8300_function_value
6064 #undef TARGET_LIBCALL_VALUE
6065 #define TARGET_LIBCALL_VALUE h8300_libcall_value
6067 #undef TARGET_FUNCTION_VALUE_REGNO_P
6068 #define TARGET_FUNCTION_VALUE_REGNO_P h8300_function_value_regno_p
6070 #undef TARGET_RETURN_IN_MEMORY
6071 #define TARGET_RETURN_IN_MEMORY h8300_return_in_memory
6073 #undef TARGET_FUNCTION_ARG
6074 #define TARGET_FUNCTION_ARG h8300_function_arg
6076 #undef TARGET_FUNCTION_ARG_ADVANCE
6077 #define TARGET_FUNCTION_ARG_ADVANCE h8300_function_arg_advance
6079 #undef TARGET_MACHINE_DEPENDENT_REORG
6080 #define TARGET_MACHINE_DEPENDENT_REORG h8300_reorg
6082 #undef TARGET_HARD_REGNO_SCRATCH_OK
6083 #define TARGET_HARD_REGNO_SCRATCH_OK h8300_hard_regno_scratch_ok
6085 #undef TARGET_LEGITIMATE_ADDRESS_P
6086 #define TARGET_LEGITIMATE_ADDRESS_P h8300_legitimate_address_p
6088 #undef TARGET_CAN_ELIMINATE
6089 #define TARGET_CAN_ELIMINATE h8300_can_eliminate
6091 #undef TARGET_CONDITIONAL_REGISTER_USAGE
6092 #define TARGET_CONDITIONAL_REGISTER_USAGE h8300_conditional_register_usage
6094 #undef TARGET_TRAMPOLINE_INIT
6095 #define TARGET_TRAMPOLINE_INIT h8300_trampoline_init
6097 #undef TARGET_OPTION_OVERRIDE
6098 #define TARGET_OPTION_OVERRIDE h8300_option_override
6100 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
6101 #define TARGET_MODE_DEPENDENT_ADDRESS_P h8300_mode_dependent_address_p
6103 struct gcc_target targetm
= TARGET_INITIALIZER
;