1 /* Subroutines for insn-output.c for Renesas H8/300.
2 Copyright (C) 1992-2013 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"
29 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
33 #include "insn-attr.h"
39 #include "diagnostic-core.h"
40 #include "c-family/c-pragma.h" /* ??? */
42 #include "tm-constrs.h"
45 #include "target-def.h"
48 /* Classifies a h8300_src_operand or h8300_dst_operand.
51 A constant operand of some sort.
57 A memory reference with a constant address.
60 A memory reference with a register as its address.
63 Some other kind of memory reference. */
64 enum h8300_operand_class
74 /* For a general two-operand instruction, element [X][Y] gives
75 the length of the opcode fields when the first operand has class
76 (X + 1) and the second has class Y. */
77 typedef unsigned char h8300_length_table
[NUM_H8OPS
- 1][NUM_H8OPS
];
79 /* Forward declarations. */
80 static const char *byte_reg (rtx
, int);
81 static int h8300_interrupt_function_p (tree
);
82 static int h8300_saveall_function_p (tree
);
83 static int h8300_monitor_function_p (tree
);
84 static int h8300_os_task_function_p (tree
);
85 static void h8300_emit_stack_adjustment (int, HOST_WIDE_INT
, bool);
86 static HOST_WIDE_INT
round_frame_size (HOST_WIDE_INT
);
87 static unsigned int compute_saved_regs (void);
88 static const char *cond_string (enum rtx_code
);
89 static unsigned int h8300_asm_insn_count (const char *);
90 static tree
h8300_handle_fndecl_attribute (tree
*, tree
, tree
, int, bool *);
91 static tree
h8300_handle_eightbit_data_attribute (tree
*, tree
, tree
, int, bool *);
92 static tree
h8300_handle_tiny_data_attribute (tree
*, tree
, tree
, int, bool *);
93 static void h8300_print_operand_address (FILE *, rtx
);
94 static void h8300_print_operand (FILE *, rtx
, int);
95 static bool h8300_print_operand_punct_valid_p (unsigned char code
);
96 #ifndef OBJECT_FORMAT_ELF
97 static void h8300_asm_named_section (const char *, unsigned int, tree
);
99 static int h8300_register_move_cost (enum machine_mode
, reg_class_t
, reg_class_t
);
100 static int h8300_and_costs (rtx
);
101 static int h8300_shift_costs (rtx
);
102 static void h8300_push_pop (int, int, bool, bool);
103 static int h8300_stack_offset_p (rtx
, int);
104 static int h8300_ldm_stm_regno (rtx
, int, int, int);
105 static void h8300_reorg (void);
106 static unsigned int h8300_constant_length (rtx
);
107 static unsigned int h8300_displacement_length (rtx
, int);
108 static unsigned int h8300_classify_operand (rtx
, int, enum h8300_operand_class
*);
109 static unsigned int h8300_length_from_table (rtx
, rtx
, const h8300_length_table
*);
110 static unsigned int h8300_unary_length (rtx
);
111 static unsigned int h8300_short_immediate_length (rtx
);
112 static unsigned int h8300_bitfield_length (rtx
, rtx
);
113 static unsigned int h8300_binary_length (rtx
, const h8300_length_table
*);
114 static bool h8300_short_move_mem_p (rtx
, enum rtx_code
);
115 static unsigned int h8300_move_length (rtx
*, const h8300_length_table
*);
116 static bool h8300_hard_regno_scratch_ok (unsigned int);
117 static rtx
h8300_get_index (rtx
, enum machine_mode mode
, int *);
119 /* CPU_TYPE, says what cpu we're compiling for. */
122 /* True if a #pragma interrupt has been seen for the current function. */
123 static int pragma_interrupt
;
125 /* True if a #pragma saveall has been seen for the current function. */
126 static int pragma_saveall
;
128 static const char *const names_big
[] =
129 { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7" };
131 static const char *const names_extended
[] =
132 { "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7" };
134 static const char *const names_upper_extended
[] =
135 { "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7" };
137 /* Points to one of the above. */
138 /* ??? The above could be put in an array indexed by CPU_TYPE. */
139 const char * const *h8_reg_names
;
141 /* Various operations needed by the following, indexed by CPU_TYPE. */
143 const char *h8_push_op
, *h8_pop_op
, *h8_mov_op
;
145 /* Value of MOVE_RATIO. */
146 int h8300_move_ratio
;
148 /* See below where shifts are handled for explanation of this enum. */
158 /* Symbols of the various shifts which can be used as indices. */
162 SHIFT_ASHIFT
, SHIFT_LSHIFTRT
, SHIFT_ASHIFTRT
165 /* Macros to keep the shift algorithm tables small. */
166 #define INL SHIFT_INLINE
167 #define ROT SHIFT_ROT_AND
168 #define LOP SHIFT_LOOP
169 #define SPC SHIFT_SPECIAL
171 /* The shift algorithms for each machine, mode, shift type, and shift
172 count are defined below. The three tables below correspond to
173 QImode, HImode, and SImode, respectively. Each table is organized
174 by, in the order of indices, machine, shift type, and shift count. */
176 static enum shift_alg shift_alg_qi
[3][3][8] = {
179 /* 0 1 2 3 4 5 6 7 */
180 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
181 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
182 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
} /* SHIFT_ASHIFTRT */
186 /* 0 1 2 3 4 5 6 7 */
187 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
188 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
189 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
} /* SHIFT_ASHIFTRT */
193 /* 0 1 2 3 4 5 6 7 */
194 { INL
, INL
, INL
, INL
, INL
, INL
, ROT
, ROT
}, /* SHIFT_ASHIFT */
195 { INL
, INL
, INL
, INL
, INL
, INL
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
196 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
} /* SHIFT_ASHIFTRT */
200 static enum shift_alg shift_alg_hi
[3][3][16] = {
203 /* 0 1 2 3 4 5 6 7 */
204 /* 8 9 10 11 12 13 14 15 */
205 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
206 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
207 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
,
208 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
209 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
,
210 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
214 /* 0 1 2 3 4 5 6 7 */
215 /* 8 9 10 11 12 13 14 15 */
216 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
217 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
218 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
219 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
220 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
221 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
225 /* 0 1 2 3 4 5 6 7 */
226 /* 8 9 10 11 12 13 14 15 */
227 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
228 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
229 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
230 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
231 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
232 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
236 static enum shift_alg shift_alg_si
[3][3][32] = {
239 /* 0 1 2 3 4 5 6 7 */
240 /* 8 9 10 11 12 13 14 15 */
241 /* 16 17 18 19 20 21 22 23 */
242 /* 24 25 26 27 28 29 30 31 */
243 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
244 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
245 SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
,
246 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFT */
247 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
248 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
249 SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
,
250 SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, SPC
}, /* SHIFT_LSHIFTRT */
251 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
252 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
253 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
254 SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
258 /* 0 1 2 3 4 5 6 7 */
259 /* 8 9 10 11 12 13 14 15 */
260 /* 16 17 18 19 20 21 22 23 */
261 /* 24 25 26 27 28 29 30 31 */
262 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
263 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
264 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
265 SPC
, LOP
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
266 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
267 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
268 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
269 SPC
, LOP
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
270 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
271 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
272 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
273 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
277 /* 0 1 2 3 4 5 6 7 */
278 /* 8 9 10 11 12 13 14 15 */
279 /* 16 17 18 19 20 21 22 23 */
280 /* 24 25 26 27 28 29 30 31 */
281 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
282 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, SPC
,
283 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
284 SPC
, SPC
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
285 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
286 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, SPC
,
287 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
288 SPC
, SPC
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
289 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
290 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
291 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
292 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
308 /* Initialize various cpu specific globals at start up. */
311 h8300_option_override (void)
313 static const char *const h8_push_ops
[2] = { "push" , "push.l" };
314 static const char *const h8_pop_ops
[2] = { "pop" , "pop.l" };
315 static const char *const h8_mov_ops
[2] = { "mov.w", "mov.l" };
317 #ifndef OBJECT_FORMAT_ELF
320 error ("-msx is not supported in coff");
321 target_flags
|= MASK_H8300S
;
327 cpu_type
= (int) CPU_H8300
;
328 h8_reg_names
= names_big
;
332 /* For this we treat the H8/300H and H8S the same. */
333 cpu_type
= (int) CPU_H8300H
;
334 h8_reg_names
= names_extended
;
336 h8_push_op
= h8_push_ops
[cpu_type
];
337 h8_pop_op
= h8_pop_ops
[cpu_type
];
338 h8_mov_op
= h8_mov_ops
[cpu_type
];
340 if (!TARGET_H8300S
&& TARGET_MAC
)
342 error ("-ms2600 is used without -ms");
343 target_flags
|= MASK_H8300S_1
;
346 if (TARGET_H8300
&& TARGET_NORMAL_MODE
)
348 error ("-mn is used without -mh or -ms or -msx");
349 target_flags
^= MASK_NORMAL_MODE
;
352 if (! TARGET_H8300S
&& TARGET_EXR
)
354 error ("-mexr is used without -ms");
355 target_flags
|= MASK_H8300S_1
;
358 if (TARGET_H8300
&& TARGET_INT32
)
360 error ("-mint32 is not supported for H8300 and H8300L targets");
361 target_flags
^= MASK_INT32
;
364 if ((!TARGET_H8300S
&& TARGET_EXR
) && (!TARGET_H8300SX
&& TARGET_EXR
))
366 error ("-mexr is used without -ms or -msx");
367 target_flags
|= MASK_H8300S_1
;
370 if ((!TARGET_H8300S
&& TARGET_NEXR
) && (!TARGET_H8300SX
&& TARGET_NEXR
))
372 warning (OPT_mno_exr
, "-mno-exr valid only with -ms or -msx \
376 /* Some of the shifts are optimized for speed by default.
377 See http://gcc.gnu.org/ml/gcc-patches/2002-07/msg01858.html
378 If optimizing for size, change shift_alg for those shift to
383 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][5] = SHIFT_LOOP
;
384 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][6] = SHIFT_LOOP
;
385 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][13] = SHIFT_LOOP
;
386 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][14] = SHIFT_LOOP
;
388 shift_alg_hi
[H8_300
][SHIFT_LSHIFTRT
][13] = SHIFT_LOOP
;
389 shift_alg_hi
[H8_300
][SHIFT_LSHIFTRT
][14] = SHIFT_LOOP
;
391 shift_alg_hi
[H8_300
][SHIFT_ASHIFTRT
][13] = SHIFT_LOOP
;
392 shift_alg_hi
[H8_300
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
395 shift_alg_hi
[H8_300H
][SHIFT_ASHIFT
][5] = SHIFT_LOOP
;
396 shift_alg_hi
[H8_300H
][SHIFT_ASHIFT
][6] = SHIFT_LOOP
;
398 shift_alg_hi
[H8_300H
][SHIFT_LSHIFTRT
][5] = SHIFT_LOOP
;
399 shift_alg_hi
[H8_300H
][SHIFT_LSHIFTRT
][6] = SHIFT_LOOP
;
401 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][5] = SHIFT_LOOP
;
402 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][6] = SHIFT_LOOP
;
403 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][13] = SHIFT_LOOP
;
404 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
407 shift_alg_hi
[H8_S
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
410 /* Work out a value for MOVE_RATIO. */
413 /* Memory-memory moves are quite expensive without the
414 h8sx instructions. */
415 h8300_move_ratio
= 3;
417 else if (flag_omit_frame_pointer
)
419 /* movmd sequences are fairly cheap when er6 isn't fixed. They can
420 sometimes be as short as two individual memory-to-memory moves,
421 but since they use all the call-saved registers, it seems better
422 to allow up to three moves here. */
423 h8300_move_ratio
= 4;
425 else if (optimize_size
)
427 /* In this case we don't use movmd sequences since they tend
428 to be longer than calls to memcpy(). Memory-to-memory
429 moves are cheaper than for !TARGET_H8300SX, so it makes
430 sense to have a slightly higher threshold. */
431 h8300_move_ratio
= 4;
435 /* We use movmd sequences for some moves since it can be quicker
436 than calling memcpy(). The sequences will need to save and
437 restore er6 though, so bump up the cost. */
438 h8300_move_ratio
= 6;
441 /* This target defaults to strict volatile bitfields. */
442 if (flag_strict_volatile_bitfields
< 0 && abi_version_at_least(2))
443 flag_strict_volatile_bitfields
= 1;
446 /* Return the byte register name for a register rtx X. B should be 0
447 if you want a lower byte register. B should be 1 if you want an
448 upper byte register. */
451 byte_reg (rtx x
, int b
)
453 static const char *const names_small
[] = {
454 "r0l", "r0h", "r1l", "r1h", "r2l", "r2h", "r3l", "r3h",
455 "r4l", "r4h", "r5l", "r5h", "r6l", "r6h", "r7l", "r7h"
458 gcc_assert (REG_P (x
));
460 return names_small
[REGNO (x
) * 2 + b
];
463 /* REGNO must be saved/restored across calls if this macro is true. */
465 #define WORD_REG_USED(regno) \
467 /* No need to save registers if this function will not return. */ \
468 && ! TREE_THIS_VOLATILE (current_function_decl) \
469 && (h8300_saveall_function_p (current_function_decl) \
470 /* Save any call saved register that was used. */ \
471 || (df_regs_ever_live_p (regno) && !call_used_regs[regno]) \
472 /* Save the frame pointer if it was used. */ \
473 || (regno == HARD_FRAME_POINTER_REGNUM && df_regs_ever_live_p (regno)) \
474 /* Save any register used in an interrupt handler. */ \
475 || (h8300_current_function_interrupt_function_p () \
476 && df_regs_ever_live_p (regno)) \
477 /* Save call clobbered registers in non-leaf interrupt \
479 || (h8300_current_function_interrupt_function_p () \
480 && call_used_regs[regno] \
483 /* We use this to wrap all emitted insns in the prologue. */
485 F (rtx x
, bool set_it
)
488 RTX_FRAME_RELATED_P (x
) = 1;
492 /* Mark all the subexpressions of the PARALLEL rtx PAR as
493 frame-related. Return PAR.
495 dwarf2out.c:dwarf2out_frame_debug_expr ignores sub-expressions of a
496 PARALLEL rtx other than the first if they do not have the
497 FRAME_RELATED flag set on them. */
501 int len
= XVECLEN (par
, 0);
504 for (i
= 0; i
< len
; i
++)
505 F (XVECEXP (par
, 0, i
), true);
510 /* Output assembly language to FILE for the operation OP with operand size
511 SIZE to adjust the stack pointer. */
514 h8300_emit_stack_adjustment (int sign
, HOST_WIDE_INT size
, bool in_prologue
)
516 /* If the frame size is 0, we don't have anything to do. */
520 /* H8/300 cannot add/subtract a large constant with a single
521 instruction. If a temporary register is available, load the
522 constant to it and then do the addition. */
525 && !h8300_current_function_interrupt_function_p ()
526 && !(cfun
->static_chain_decl
!= NULL
&& sign
< 0))
528 rtx r3
= gen_rtx_REG (Pmode
, 3);
529 F (emit_insn (gen_movhi (r3
, GEN_INT (sign
* size
))), in_prologue
);
530 F (emit_insn (gen_addhi3 (stack_pointer_rtx
,
531 stack_pointer_rtx
, r3
)), in_prologue
);
535 /* The stack adjustment made here is further optimized by the
536 splitter. In case of H8/300, the splitter always splits the
537 addition emitted here to make the adjustment interrupt-safe.
538 FIXME: We don't always tag those, because we don't know what
539 the splitter will do. */
542 rtx x
= emit_insn (gen_addhi3 (stack_pointer_rtx
,
543 stack_pointer_rtx
, GEN_INT (sign
* size
)));
548 F (emit_insn (gen_addsi3 (stack_pointer_rtx
,
549 stack_pointer_rtx
, GEN_INT (sign
* size
))), in_prologue
);
553 /* Round up frame size SIZE. */
556 round_frame_size (HOST_WIDE_INT size
)
558 return ((size
+ STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
559 & -STACK_BOUNDARY
/ BITS_PER_UNIT
);
562 /* Compute which registers to push/pop.
563 Return a bit vector of registers. */
566 compute_saved_regs (void)
568 unsigned int saved_regs
= 0;
571 /* Construct a bit vector of registers to be pushed/popped. */
572 for (regno
= 0; regno
<= HARD_FRAME_POINTER_REGNUM
; regno
++)
574 if (WORD_REG_USED (regno
))
575 saved_regs
|= 1 << regno
;
578 /* Don't push/pop the frame pointer as it is treated separately. */
579 if (frame_pointer_needed
)
580 saved_regs
&= ~(1 << HARD_FRAME_POINTER_REGNUM
);
585 /* Emit an insn to push register RN. */
590 rtx reg
= gen_rtx_REG (word_mode
, rn
);
594 x
= gen_push_h8300 (reg
);
595 else if (!TARGET_NORMAL_MODE
)
596 x
= gen_push_h8300hs_advanced (reg
);
598 x
= gen_push_h8300hs_normal (reg
);
599 x
= F (emit_insn (x
), true);
600 add_reg_note (x
, REG_INC
, stack_pointer_rtx
);
604 /* Emit an insn to pop register RN. */
609 rtx reg
= gen_rtx_REG (word_mode
, rn
);
613 x
= gen_pop_h8300 (reg
);
614 else if (!TARGET_NORMAL_MODE
)
615 x
= gen_pop_h8300hs_advanced (reg
);
617 x
= gen_pop_h8300hs_normal (reg
);
619 add_reg_note (x
, REG_INC
, stack_pointer_rtx
);
623 /* Emit an instruction to push or pop NREGS consecutive registers
624 starting at register REGNO. POP_P selects a pop rather than a
625 push and RETURN_P is true if the instruction should return.
627 It must be possible to do the requested operation in a single
628 instruction. If NREGS == 1 && !RETURN_P, use a normal push
629 or pop insn. Otherwise emit a parallel of the form:
632 [(return) ;; if RETURN_P
633 (save or restore REGNO)
634 (save or restore REGNO + 1)
636 (save or restore REGNO + NREGS - 1)
637 (set sp (plus sp (const_int adjust)))] */
640 h8300_push_pop (int regno
, int nregs
, bool pop_p
, bool return_p
)
646 /* See whether we can use a simple push or pop. */
647 if (!return_p
&& nregs
== 1)
656 /* We need one element for the return insn, if present, one for each
657 register, and one for stack adjustment. */
658 vec
= rtvec_alloc ((return_p
? 1 : 0) + nregs
+ 1);
659 sp
= stack_pointer_rtx
;
662 /* Add the return instruction. */
665 RTVEC_ELT (vec
, i
) = ret_rtx
;
669 /* Add the register moves. */
670 for (j
= 0; j
< nregs
; j
++)
676 /* Register REGNO + NREGS - 1 is popped first. Before the
677 stack adjustment, its slot is at address @sp. */
678 lhs
= gen_rtx_REG (SImode
, regno
+ j
);
679 rhs
= gen_rtx_MEM (SImode
, plus_constant (Pmode
, sp
,
680 (nregs
- j
- 1) * 4));
684 /* Register REGNO is pushed first and will be stored at @(-4,sp). */
685 lhs
= gen_rtx_MEM (SImode
, plus_constant (Pmode
, sp
, (j
+ 1) * -4));
686 rhs
= gen_rtx_REG (SImode
, regno
+ j
);
688 RTVEC_ELT (vec
, i
+ j
) = gen_rtx_SET (VOIDmode
, lhs
, rhs
);
691 /* Add the stack adjustment. */
692 offset
= GEN_INT ((pop_p
? nregs
: -nregs
) * 4);
693 RTVEC_ELT (vec
, i
+ j
) = gen_rtx_SET (VOIDmode
, sp
,
694 gen_rtx_PLUS (Pmode
, sp
, offset
));
696 x
= gen_rtx_PARALLEL (VOIDmode
, vec
);
706 /* Return true if X has the value sp + OFFSET. */
709 h8300_stack_offset_p (rtx x
, int offset
)
712 return x
== stack_pointer_rtx
;
714 return (GET_CODE (x
) == PLUS
715 && XEXP (x
, 0) == stack_pointer_rtx
716 && GET_CODE (XEXP (x
, 1)) == CONST_INT
717 && INTVAL (XEXP (x
, 1)) == offset
);
720 /* A subroutine of h8300_ldm_stm_parallel. X is one pattern in
721 something that may be an ldm or stm instruction. If it fits
722 the required template, return the register it loads or stores,
725 LOAD_P is true if X should be a load, false if it should be a store.
726 NREGS is the number of registers that the whole instruction is expected
727 to load or store. INDEX is the index of the register that X should
728 load or store, relative to the lowest-numbered register. */
731 h8300_ldm_stm_regno (rtx x
, int load_p
, int index
, int nregs
)
733 int regindex
, memindex
, offset
;
736 regindex
= 0, memindex
= 1, offset
= (nregs
- index
- 1) * 4;
738 memindex
= 0, regindex
= 1, offset
= (index
+ 1) * -4;
740 if (GET_CODE (x
) == SET
741 && GET_CODE (XEXP (x
, regindex
)) == REG
742 && GET_CODE (XEXP (x
, memindex
)) == MEM
743 && h8300_stack_offset_p (XEXP (XEXP (x
, memindex
), 0), offset
))
744 return REGNO (XEXP (x
, regindex
));
749 /* Return true if the elements of VEC starting at FIRST describe an
750 ldm or stm instruction (LOAD_P says which). */
753 h8300_ldm_stm_parallel (rtvec vec
, int load_p
, int first
)
756 int nregs
, i
, regno
, adjust
;
758 /* There must be a stack adjustment, a register move, and at least one
759 other operation (a return or another register move). */
760 if (GET_NUM_ELEM (vec
) < 3)
763 /* Get the range of registers to be pushed or popped. */
764 nregs
= GET_NUM_ELEM (vec
) - first
- 1;
765 regno
= h8300_ldm_stm_regno (RTVEC_ELT (vec
, first
), load_p
, 0, nregs
);
767 /* Check that the call to h8300_ldm_stm_regno succeeded and
768 that we're only dealing with GPRs. */
769 if (regno
< 0 || regno
+ nregs
> 8)
772 /* 2-register h8s instructions must start with an even-numbered register.
773 3- and 4-register instructions must start with er0 or er4. */
776 if ((regno
& 1) != 0)
778 if (nregs
> 2 && (regno
& 3) != 0)
782 /* Check the other loads or stores. */
783 for (i
= 1; i
< nregs
; i
++)
784 if (h8300_ldm_stm_regno (RTVEC_ELT (vec
, first
+ i
), load_p
, i
, nregs
)
788 /* Check the stack adjustment. */
789 last
= RTVEC_ELT (vec
, first
+ nregs
);
790 adjust
= (load_p
? nregs
: -nregs
) * 4;
791 return (GET_CODE (last
) == SET
792 && SET_DEST (last
) == stack_pointer_rtx
793 && h8300_stack_offset_p (SET_SRC (last
), adjust
));
796 /* This is what the stack looks like after the prolog of
797 a function with a frame has been set up:
803 <saved registers> <- sp
805 This is what the stack looks like after the prolog of
806 a function which doesn't have a frame:
811 <saved registers> <- sp
814 /* Generate RTL code for the function prologue. */
817 h8300_expand_prologue (void)
823 /* If the current function has the OS_Task attribute set, then
824 we have a naked prologue. */
825 if (h8300_os_task_function_p (current_function_decl
))
828 if (h8300_monitor_function_p (current_function_decl
))
829 /* The monitor function act as normal functions, which means it
830 can accept parameters and return values. In addition to this,
831 interrupts are masked in prologue and return with "rte" in epilogue. */
832 emit_insn (gen_monitor_prologue ());
834 if (frame_pointer_needed
)
837 push (HARD_FRAME_POINTER_REGNUM
);
838 F (emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
), true);
841 /* Push the rest of the registers in ascending order. */
842 saved_regs
= compute_saved_regs ();
843 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
+= n_regs
)
846 if (saved_regs
& (1 << regno
))
850 /* See how many registers we can push at the same time. */
851 if ((!TARGET_H8300SX
|| (regno
& 3) == 0)
852 && ((saved_regs
>> regno
) & 0x0f) == 0x0f)
855 else if ((!TARGET_H8300SX
|| (regno
& 3) == 0)
856 && ((saved_regs
>> regno
) & 0x07) == 0x07)
859 else if ((!TARGET_H8300SX
|| (regno
& 1) == 0)
860 && ((saved_regs
>> regno
) & 0x03) == 0x03)
864 h8300_push_pop (regno
, n_regs
, false, false);
868 /* Leave room for locals. */
869 h8300_emit_stack_adjustment (-1, round_frame_size (get_frame_size ()), true);
872 /* Return nonzero if we can use "rts" for the function currently being
876 h8300_can_use_return_insn_p (void)
878 return (reload_completed
879 && !frame_pointer_needed
880 && get_frame_size () == 0
881 && compute_saved_regs () == 0);
884 /* Generate RTL code for the function epilogue. */
887 h8300_expand_epilogue (void)
892 HOST_WIDE_INT frame_size
;
895 if (h8300_os_task_function_p (current_function_decl
))
896 /* OS_Task epilogues are nearly naked -- they just have an
900 frame_size
= round_frame_size (get_frame_size ());
903 /* Deallocate locals. */
904 h8300_emit_stack_adjustment (1, frame_size
, false);
906 /* Pop the saved registers in descending order. */
907 saved_regs
= compute_saved_regs ();
908 for (regno
= FIRST_PSEUDO_REGISTER
- 1; regno
>= 0; regno
-= n_regs
)
911 if (saved_regs
& (1 << regno
))
915 /* See how many registers we can pop at the same time. */
916 if ((TARGET_H8300SX
|| (regno
& 3) == 3)
917 && ((saved_regs
<< 3 >> regno
) & 0x0f) == 0x0f)
920 else if ((TARGET_H8300SX
|| (regno
& 3) == 2)
921 && ((saved_regs
<< 2 >> regno
) & 0x07) == 0x07)
924 else if ((TARGET_H8300SX
|| (regno
& 1) == 1)
925 && ((saved_regs
<< 1 >> regno
) & 0x03) == 0x03)
929 /* See if this pop would be the last insn before the return.
930 If so, use rte/l or rts/l instead of pop or ldm.l. */
932 && !frame_pointer_needed
934 && (saved_regs
& ((1 << (regno
- n_regs
+ 1)) - 1)) == 0)
937 h8300_push_pop (regno
- n_regs
+ 1, n_regs
, true, returned_p
);
941 /* Pop frame pointer if we had one. */
942 if (frame_pointer_needed
)
946 h8300_push_pop (HARD_FRAME_POINTER_REGNUM
, 1, true, returned_p
);
950 emit_jump_insn (ret_rtx
);
953 /* Return nonzero if the current function is an interrupt
957 h8300_current_function_interrupt_function_p (void)
959 return (h8300_interrupt_function_p (current_function_decl
));
963 h8300_current_function_monitor_function_p ()
965 return (h8300_monitor_function_p (current_function_decl
));
968 /* Output assembly code for the start of the file. */
971 h8300_file_start (void)
973 default_file_start ();
976 fputs (TARGET_NORMAL_MODE
? "\t.h8300hn\n" : "\t.h8300h\n", asm_out_file
);
977 else if (TARGET_H8300SX
)
978 fputs (TARGET_NORMAL_MODE
? "\t.h8300sxn\n" : "\t.h8300sx\n", asm_out_file
);
979 else if (TARGET_H8300S
)
980 fputs (TARGET_NORMAL_MODE
? "\t.h8300sn\n" : "\t.h8300s\n", asm_out_file
);
983 /* Output assembly language code for the end of file. */
986 h8300_file_end (void)
988 fputs ("\t.end\n", asm_out_file
);
991 /* Split an add of a small constant into two adds/subs insns.
993 If USE_INCDEC_P is nonzero, we generate the last insn using inc/dec
994 instead of adds/subs. */
997 split_adds_subs (enum machine_mode mode
, rtx
*operands
)
999 HOST_WIDE_INT val
= INTVAL (operands
[1]);
1000 rtx reg
= operands
[0];
1001 HOST_WIDE_INT sign
= 1;
1002 HOST_WIDE_INT amount
;
1003 rtx (*gen_add
) (rtx
, rtx
, rtx
);
1005 /* Force VAL to be positive so that we do not have to consider the
1016 gen_add
= gen_addhi3
;
1020 gen_add
= gen_addsi3
;
1027 /* Try different amounts in descending order. */
1028 for (amount
= (TARGET_H8300H
|| TARGET_H8300S
) ? 4 : 2;
1032 for (; val
>= amount
; val
-= amount
)
1033 emit_insn (gen_add (reg
, reg
, GEN_INT (sign
* amount
)));
1039 /* Handle machine specific pragmas for compatibility with existing
1040 compilers for the H8/300.
1042 pragma saveall generates prologue/epilogue code which saves and
1043 restores all the registers on function entry.
1045 pragma interrupt saves and restores all registers, and exits with
1046 an rte instruction rather than an rts. A pointer to a function
1047 with this attribute may be safely used in an interrupt vector. */
1050 h8300_pr_interrupt (struct cpp_reader
*pfile ATTRIBUTE_UNUSED
)
1052 pragma_interrupt
= 1;
1056 h8300_pr_saveall (struct cpp_reader
*pfile ATTRIBUTE_UNUSED
)
1061 /* If the next function argument with MODE and TYPE is to be passed in
1062 a register, return a reg RTX for the hard register in which to pass
1063 the argument. CUM represents the state after the last argument.
1064 If the argument is to be pushed, NULL_RTX is returned.
1066 On the H8/300 all normal args are pushed, unless -mquickcall in which
1067 case the first 3 arguments are passed in registers. */
1070 h8300_function_arg (cumulative_args_t cum_v
, enum machine_mode mode
,
1071 const_tree type
, bool named
)
1073 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
1075 static const char *const hand_list
[] = {
1094 rtx result
= NULL_RTX
;
1098 /* Never pass unnamed arguments in registers. */
1102 /* Pass 3 regs worth of data in regs when user asked on the command line. */
1103 if (TARGET_QUICKCALL
)
1106 /* If calling hand written assembler, use 4 regs of args. */
1109 const char * const *p
;
1111 fname
= XSTR (cum
->libcall
, 0);
1113 /* See if this libcall is one of the hand coded ones. */
1114 for (p
= hand_list
; *p
&& strcmp (*p
, fname
) != 0; p
++)
1125 if (mode
== BLKmode
)
1126 size
= int_size_in_bytes (type
);
1128 size
= GET_MODE_SIZE (mode
);
1130 if (size
+ cum
->nbytes
<= regpass
* UNITS_PER_WORD
1131 && cum
->nbytes
/ UNITS_PER_WORD
<= 3)
1132 result
= gen_rtx_REG (mode
, cum
->nbytes
/ UNITS_PER_WORD
);
1138 /* Update the data in CUM to advance over an argument
1139 of mode MODE and data type TYPE.
1140 (TYPE is null for libcalls where that information may not be available.) */
1143 h8300_function_arg_advance (cumulative_args_t cum_v
, enum machine_mode mode
,
1144 const_tree type
, bool named ATTRIBUTE_UNUSED
)
1146 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
1148 cum
->nbytes
+= (mode
!= BLKmode
1149 ? (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
1150 : (int_size_in_bytes (type
) + UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
);
1154 /* Implements TARGET_REGISTER_MOVE_COST.
1156 Any SI register-to-register move may need to be reloaded,
1157 so inmplement h8300_register_move_cost to return > 2 so that reload never
1161 h8300_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED
,
1162 reg_class_t from
, reg_class_t to
)
1164 if (from
== MAC_REGS
|| to
== MAC_REG
)
1170 /* Compute the cost of an and insn. */
1173 h8300_and_costs (rtx x
)
1177 if (GET_MODE (x
) == QImode
)
1180 if (GET_MODE (x
) != HImode
1181 && GET_MODE (x
) != SImode
)
1185 operands
[1] = XEXP (x
, 0);
1186 operands
[2] = XEXP (x
, 1);
1188 return compute_logical_op_length (GET_MODE (x
), operands
) / 2;
1191 /* Compute the cost of a shift insn. */
1194 h8300_shift_costs (rtx x
)
1198 if (GET_MODE (x
) != QImode
1199 && GET_MODE (x
) != HImode
1200 && GET_MODE (x
) != SImode
)
1205 operands
[2] = XEXP (x
, 1);
1207 return compute_a_shift_length (NULL
, operands
) / 2;
1210 /* Worker function for TARGET_RTX_COSTS. */
1213 h8300_rtx_costs (rtx x
, int code
, int outer_code
, int opno ATTRIBUTE_UNUSED
,
1214 int *total
, bool speed
)
1216 if (TARGET_H8300SX
&& outer_code
== MEM
)
1218 /* Estimate the number of execution states needed to calculate
1220 if (register_operand (x
, VOIDmode
)
1221 || GET_CODE (x
) == POST_INC
1222 || GET_CODE (x
) == POST_DEC
1226 *total
= COSTS_N_INSNS (1);
1234 HOST_WIDE_INT n
= INTVAL (x
);
1238 /* Constant operands need the same number of processor
1239 states as register operands. Although we could try to
1240 use a size-based cost for !speed, the lack of
1241 of a mode makes the results very unpredictable. */
1245 if (-4 <= n
&& n
<= 4)
1256 *total
= 0 + (outer_code
== SET
);
1260 if (TARGET_H8300H
|| TARGET_H8300S
)
1261 *total
= 0 + (outer_code
== SET
);
1276 /* See comment for CONST_INT. */
1288 if (XEXP (x
, 1) == const0_rtx
)
1293 if (!h8300_dst_operand (XEXP (x
, 0), VOIDmode
)
1294 || !h8300_src_operand (XEXP (x
, 1), VOIDmode
))
1296 *total
= COSTS_N_INSNS (h8300_and_costs (x
));
1299 /* We say that MOD and DIV are so expensive because otherwise we'll
1300 generate some really horrible code for division of a power of two. */
1306 switch (GET_MODE (x
))
1310 *total
= COSTS_N_INSNS (!speed
? 4 : 10);
1314 *total
= COSTS_N_INSNS (!speed
? 4 : 18);
1320 *total
= COSTS_N_INSNS (12);
1325 switch (GET_MODE (x
))
1329 *total
= COSTS_N_INSNS (2);
1333 *total
= COSTS_N_INSNS (5);
1339 *total
= COSTS_N_INSNS (4);
1345 if (h8sx_binary_shift_operator (x
, VOIDmode
))
1347 *total
= COSTS_N_INSNS (2);
1350 else if (h8sx_unary_shift_operator (x
, VOIDmode
))
1352 *total
= COSTS_N_INSNS (1);
1355 *total
= COSTS_N_INSNS (h8300_shift_costs (x
));
1360 if (GET_MODE (x
) == HImode
)
1367 *total
= COSTS_N_INSNS (1);
1372 /* Documentation for the machine specific operand escapes:
1374 'E' like s but negative.
1375 'F' like t but negative.
1376 'G' constant just the negative
1377 'R' print operand as a byte:8 address if appropriate, else fall back to
1379 'S' print operand as a long word
1380 'T' print operand as a word
1381 'V' find the set bit, and print its number.
1382 'W' find the clear bit, and print its number.
1383 'X' print operand as a byte
1384 'Y' print either l or h depending on whether last 'Z' operand < 8 or >= 8.
1385 If this operand isn't a register, fall back to 'R' handling.
1387 'c' print the opcode corresponding to rtl
1388 'e' first word of 32-bit value - if reg, then least reg. if mem
1389 then least. if const then most sig word
1390 'f' second word of 32-bit value - if reg, then biggest reg. if mem
1391 then +2. if const then least sig word
1392 'j' print operand as condition code.
1393 'k' print operand as reverse condition code.
1394 'm' convert an integer operand to a size suffix (.b, .w or .l)
1395 'o' print an integer without a leading '#'
1396 's' print as low byte of 16-bit value
1397 't' print as high byte of 16-bit value
1398 'w' print as low byte of 32-bit value
1399 'x' print as 2nd byte of 32-bit value
1400 'y' print as 3rd byte of 32-bit value
1401 'z' print as msb of 32-bit value
1404 /* Return assembly language string which identifies a comparison type. */
1407 cond_string (enum rtx_code code
)
1436 /* Print operand X using operand code CODE to assembly language output file
1440 h8300_print_operand (FILE *file
, rtx x
, int code
)
1442 /* This is used for communication between codes V,W,Z and Y. */
1448 if (h8300_constant_length (x
) == 2)
1449 fprintf (file
, ":16");
1451 fprintf (file
, ":32");
1454 switch (GET_CODE (x
))
1457 fprintf (file
, "%sl", names_big
[REGNO (x
)]);
1460 fprintf (file
, "#%ld", (-INTVAL (x
)) & 0xff);
1467 switch (GET_CODE (x
))
1470 fprintf (file
, "%sh", names_big
[REGNO (x
)]);
1473 fprintf (file
, "#%ld", ((-INTVAL (x
)) & 0xff00) >> 8);
1480 gcc_assert (GET_CODE (x
) == CONST_INT
);
1481 fprintf (file
, "#%ld", 0xff & (-INTVAL (x
)));
1484 if (GET_CODE (x
) == REG
)
1485 fprintf (file
, "%s", names_extended
[REGNO (x
)]);
1490 if (GET_CODE (x
) == REG
)
1491 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1496 bitint
= (INTVAL (x
) & 0xffff);
1497 if ((exact_log2 ((bitint
>> 8) & 0xff)) == -1)
1498 bitint
= exact_log2 (bitint
& 0xff);
1500 bitint
= exact_log2 ((bitint
>> 8) & 0xff);
1501 gcc_assert (bitint
>= 0);
1502 fprintf (file
, "#%d", bitint
);
1505 bitint
= ((~INTVAL (x
)) & 0xffff);
1506 if ((exact_log2 ((bitint
>> 8) & 0xff)) == -1 )
1507 bitint
= exact_log2 (bitint
& 0xff);
1509 bitint
= (exact_log2 ((bitint
>> 8) & 0xff));
1510 gcc_assert (bitint
>= 0);
1511 fprintf (file
, "#%d", bitint
);
1515 if (GET_CODE (x
) == REG
)
1516 fprintf (file
, "%s", byte_reg (x
, 0));
1521 gcc_assert (bitint
>= 0);
1522 if (GET_CODE (x
) == REG
)
1523 fprintf (file
, "%s%c", names_big
[REGNO (x
)], bitint
> 7 ? 'h' : 'l');
1525 h8300_print_operand (file
, x
, 'R');
1529 bitint
= INTVAL (x
);
1530 fprintf (file
, "#%d", bitint
& 7);
1533 switch (GET_CODE (x
))
1536 fprintf (file
, "or");
1539 fprintf (file
, "xor");
1542 fprintf (file
, "and");
1549 switch (GET_CODE (x
))
1553 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1555 fprintf (file
, "%s", names_upper_extended
[REGNO (x
)]);
1558 h8300_print_operand (file
, x
, 0);
1561 fprintf (file
, "#%ld", ((INTVAL (x
) >> 16) & 0xffff));
1567 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1568 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1569 fprintf (file
, "#%ld", ((val
>> 16) & 0xffff));
1578 switch (GET_CODE (x
))
1582 fprintf (file
, "%s", names_big
[REGNO (x
) + 1]);
1584 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1587 x
= adjust_address (x
, HImode
, 2);
1588 h8300_print_operand (file
, x
, 0);
1591 fprintf (file
, "#%ld", INTVAL (x
) & 0xffff);
1597 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1598 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1599 fprintf (file
, "#%ld", (val
& 0xffff));
1607 fputs (cond_string (GET_CODE (x
)), file
);
1610 fputs (cond_string (reverse_condition (GET_CODE (x
))), file
);
1613 gcc_assert (GET_CODE (x
) == CONST_INT
);
1633 h8300_print_operand_address (file
, x
);
1636 if (GET_CODE (x
) == CONST_INT
)
1637 fprintf (file
, "#%ld", (INTVAL (x
)) & 0xff);
1639 fprintf (file
, "%s", byte_reg (x
, 0));
1642 if (GET_CODE (x
) == CONST_INT
)
1643 fprintf (file
, "#%ld", (INTVAL (x
) >> 8) & 0xff);
1645 fprintf (file
, "%s", byte_reg (x
, 1));
1648 if (GET_CODE (x
) == CONST_INT
)
1649 fprintf (file
, "#%ld", INTVAL (x
) & 0xff);
1651 fprintf (file
, "%s",
1652 byte_reg (x
, TARGET_H8300
? 2 : 0));
1655 if (GET_CODE (x
) == CONST_INT
)
1656 fprintf (file
, "#%ld", (INTVAL (x
) >> 8) & 0xff);
1658 fprintf (file
, "%s",
1659 byte_reg (x
, TARGET_H8300
? 3 : 1));
1662 if (GET_CODE (x
) == CONST_INT
)
1663 fprintf (file
, "#%ld", (INTVAL (x
) >> 16) & 0xff);
1665 fprintf (file
, "%s", byte_reg (x
, 0));
1668 if (GET_CODE (x
) == CONST_INT
)
1669 fprintf (file
, "#%ld", (INTVAL (x
) >> 24) & 0xff);
1671 fprintf (file
, "%s", byte_reg (x
, 1));
1676 switch (GET_CODE (x
))
1679 switch (GET_MODE (x
))
1682 #if 0 /* Is it asm ("mov.b %0,r2l", ...) */
1683 fprintf (file
, "%s", byte_reg (x
, 0));
1684 #else /* ... or is it asm ("mov.b %0l,r2l", ...) */
1685 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1689 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1693 fprintf (file
, "%s", names_extended
[REGNO (x
)]);
1702 rtx addr
= XEXP (x
, 0);
1704 fprintf (file
, "@");
1705 output_address (addr
);
1707 /* Add a length suffix to constant addresses. Although this
1708 is often unnecessary, it helps to avoid ambiguity in the
1709 syntax of mova. If we wrote an insn like:
1711 mova/w.l @(1,@foo.b),er0
1713 then .b would be considered part of the symbol name.
1714 Adding a length after foo will avoid this. */
1715 if (CONSTANT_P (addr
))
1719 /* Used for mov.b and bit operations. */
1720 if (h8300_eightbit_constant_address_p (addr
))
1722 fprintf (file
, ":8");
1726 /* Fall through. We should not get here if we are
1727 processing bit operations on H8/300 or H8/300H
1728 because 'U' constraint does not allow bit
1729 operations on the tiny area on these machines. */
1734 if (h8300_constant_length (addr
) == 2)
1735 fprintf (file
, ":16");
1737 fprintf (file
, ":32");
1749 fprintf (file
, "#");
1750 h8300_print_operand_address (file
, x
);
1756 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1757 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1758 fprintf (file
, "#%ld", val
);
1767 /* Implements TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
1770 h8300_print_operand_punct_valid_p (unsigned char code
)
1772 return (code
== '#');
1775 /* Output assembly language output for the address ADDR to FILE. */
1778 h8300_print_operand_address (FILE *file
, rtx addr
)
1783 switch (GET_CODE (addr
))
1786 fprintf (file
, "%s", h8_reg_names
[REGNO (addr
)]);
1790 fprintf (file
, "-%s", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1794 fprintf (file
, "%s+", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1798 fprintf (file
, "+%s", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1802 fprintf (file
, "%s-", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1806 fprintf (file
, "(");
1808 index
= h8300_get_index (XEXP (addr
, 0), VOIDmode
, &size
);
1809 if (GET_CODE (index
) == REG
)
1812 h8300_print_operand_address (file
, XEXP (addr
, 1));
1813 fprintf (file
, ",");
1817 h8300_print_operand_address (file
, index
);
1821 h8300_print_operand (file
, index
, 'X');
1826 h8300_print_operand (file
, index
, 'T');
1831 h8300_print_operand (file
, index
, 'S');
1835 /* h8300_print_operand_address (file, XEXP (addr, 0)); */
1840 h8300_print_operand_address (file
, XEXP (addr
, 0));
1841 fprintf (file
, "+");
1842 h8300_print_operand_address (file
, XEXP (addr
, 1));
1844 fprintf (file
, ")");
1849 /* Since the H8/300 only has 16-bit pointers, negative values are also
1850 those >= 32768. This happens for example with pointer minus a
1851 constant. We don't want to turn (char *p - 2) into
1852 (char *p + 65534) because loop unrolling can build upon this
1853 (IE: char *p + 131068). */
1854 int n
= INTVAL (addr
);
1856 n
= (int) (short) n
;
1857 fprintf (file
, "%d", n
);
1862 output_addr_const (file
, addr
);
1867 /* Output all insn addresses and their sizes into the assembly language
1868 output file. This is helpful for debugging whether the length attributes
1869 in the md file are correct. This is not meant to be a user selectable
1873 final_prescan_insn (rtx insn
, rtx
*operand ATTRIBUTE_UNUSED
,
1874 int num_operands ATTRIBUTE_UNUSED
)
1876 /* This holds the last insn address. */
1877 static int last_insn_address
= 0;
1879 const int uid
= INSN_UID (insn
);
1881 if (TARGET_ADDRESSES
)
1883 fprintf (asm_out_file
, "; 0x%x %d\n", INSN_ADDRESSES (uid
),
1884 INSN_ADDRESSES (uid
) - last_insn_address
);
1885 last_insn_address
= INSN_ADDRESSES (uid
);
1889 /* Prepare for an SI sized move. */
1892 h8300_expand_movsi (rtx operands
[])
1894 rtx src
= operands
[1];
1895 rtx dst
= operands
[0];
1896 if (!reload_in_progress
&& !reload_completed
)
1898 if (!register_operand (dst
, GET_MODE (dst
)))
1900 rtx tmp
= gen_reg_rtx (GET_MODE (dst
));
1901 emit_move_insn (tmp
, src
);
1908 /* Given FROM and TO register numbers, say whether this elimination is allowed.
1909 Frame pointer elimination is automatically handled.
1911 For the h8300, if frame pointer elimination is being done, we would like to
1912 convert ap and rp into sp, not fp.
1914 All other eliminations are valid. */
1917 h8300_can_eliminate (const int from ATTRIBUTE_UNUSED
, const int to
)
1919 return (to
== STACK_POINTER_REGNUM
? ! frame_pointer_needed
: true);
1922 /* Conditionally modify register usage based on target flags. */
1925 h8300_conditional_register_usage (void)
1928 fixed_regs
[MAC_REG
] = call_used_regs
[MAC_REG
] = 1;
1931 /* Function for INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET).
1932 Define the offset between two registers, one to be eliminated, and
1933 the other its replacement, at the start of a routine. */
1936 h8300_initial_elimination_offset (int from
, int to
)
1938 /* The number of bytes that the return address takes on the stack. */
1939 int pc_size
= POINTER_SIZE
/ BITS_PER_UNIT
;
1941 /* The number of bytes that the saved frame pointer takes on the stack. */
1942 int fp_size
= frame_pointer_needed
* UNITS_PER_WORD
;
1944 /* The number of bytes that the saved registers, excluding the frame
1945 pointer, take on the stack. */
1946 int saved_regs_size
= 0;
1948 /* The number of bytes that the locals takes on the stack. */
1949 int frame_size
= round_frame_size (get_frame_size ());
1953 for (regno
= 0; regno
<= HARD_FRAME_POINTER_REGNUM
; regno
++)
1954 if (WORD_REG_USED (regno
))
1955 saved_regs_size
+= UNITS_PER_WORD
;
1957 /* Adjust saved_regs_size because the above loop took the frame
1958 pointer int account. */
1959 saved_regs_size
-= fp_size
;
1963 case HARD_FRAME_POINTER_REGNUM
:
1966 case ARG_POINTER_REGNUM
:
1967 return pc_size
+ fp_size
;
1968 case RETURN_ADDRESS_POINTER_REGNUM
:
1970 case FRAME_POINTER_REGNUM
:
1971 return -saved_regs_size
;
1976 case STACK_POINTER_REGNUM
:
1979 case ARG_POINTER_REGNUM
:
1980 return pc_size
+ saved_regs_size
+ frame_size
;
1981 case RETURN_ADDRESS_POINTER_REGNUM
:
1982 return saved_regs_size
+ frame_size
;
1983 case FRAME_POINTER_REGNUM
:
1995 /* Worker function for RETURN_ADDR_RTX. */
1998 h8300_return_addr_rtx (int count
, rtx frame
)
2003 ret
= gen_rtx_MEM (Pmode
,
2004 gen_rtx_REG (Pmode
, RETURN_ADDRESS_POINTER_REGNUM
));
2005 else if (flag_omit_frame_pointer
)
2008 ret
= gen_rtx_MEM (Pmode
,
2009 memory_address (Pmode
,
2010 plus_constant (Pmode
, frame
,
2012 set_mem_alias_set (ret
, get_frame_alias_set ());
2016 /* Update the condition code from the insn. */
2019 notice_update_cc (rtx body
, rtx insn
)
2023 switch (get_attr_cc (insn
))
2026 /* Insn does not affect CC at all. */
2030 /* Insn does not change CC, but the 0'th operand has been changed. */
2031 if (cc_status
.value1
!= 0
2032 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
2033 cc_status
.value1
= 0;
2034 if (cc_status
.value2
!= 0
2035 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value2
))
2036 cc_status
.value2
= 0;
2040 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
2041 The V flag is unusable. The C flag may or may not be known but
2042 that's ok because alter_cond will change tests to use EQ/NE. */
2044 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2045 set
= single_set (insn
);
2046 cc_status
.value1
= SET_SRC (set
);
2047 if (SET_DEST (set
) != cc0_rtx
)
2048 cc_status
.value2
= SET_DEST (set
);
2052 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2053 The C flag may or may not be known but that's ok because
2054 alter_cond will change tests to use EQ/NE. */
2056 cc_status
.flags
|= CC_NO_CARRY
;
2057 set
= single_set (insn
);
2058 cc_status
.value1
= SET_SRC (set
);
2059 if (SET_DEST (set
) != cc0_rtx
)
2061 /* If the destination is STRICT_LOW_PART, strip off
2063 if (GET_CODE (SET_DEST (set
)) == STRICT_LOW_PART
)
2064 cc_status
.value2
= XEXP (SET_DEST (set
), 0);
2066 cc_status
.value2
= SET_DEST (set
);
2071 /* The insn is a compare instruction. */
2073 cc_status
.value1
= SET_SRC (body
);
2077 /* Insn doesn't leave CC in a usable state. */
2083 /* Given that X occurs in an address of the form (plus X constant),
2084 return the part of X that is expected to be a register. There are
2085 four kinds of addressing mode to recognize:
2092 If SIZE is nonnull, and the address is one of the last three forms,
2093 set *SIZE to the index multiplication factor. Set it to 0 for
2094 plain @(dd,Rn) addresses.
2096 MODE is the mode of the value being accessed. It can be VOIDmode
2097 if the address is known to be valid, but its mode is unknown. */
2100 h8300_get_index (rtx x
, enum machine_mode mode
, int *size
)
2107 factor
= (mode
== VOIDmode
? 0 : GET_MODE_SIZE (mode
));
2110 && (mode
== VOIDmode
2111 || GET_MODE_CLASS (mode
) == MODE_INT
2112 || GET_MODE_CLASS (mode
) == MODE_FLOAT
))
2114 if (factor
<= 1 && GET_CODE (x
) == ZERO_EXTEND
)
2116 /* When accessing byte-sized values, the index can be
2117 a zero-extended QImode or HImode register. */
2118 *size
= GET_MODE_SIZE (GET_MODE (XEXP (x
, 0)));
2123 /* We're looking for addresses of the form:
2126 or (mult (zero_extend X) I)
2128 where I is the size of the operand being accessed.
2129 The canonical form of the second expression is:
2131 (and (mult (subreg X) I) J)
2133 where J == GET_MODE_MASK (GET_MODE (X)) * I. */
2136 if (GET_CODE (x
) == AND
2137 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2139 || INTVAL (XEXP (x
, 1)) == 0xff * factor
2140 || INTVAL (XEXP (x
, 1)) == 0xffff * factor
))
2142 index
= XEXP (x
, 0);
2143 *size
= (INTVAL (XEXP (x
, 1)) >= 0xffff ? 2 : 1);
2151 if (GET_CODE (index
) == MULT
2152 && GET_CODE (XEXP (index
, 1)) == CONST_INT
2153 && (factor
== 0 || factor
== INTVAL (XEXP (index
, 1))))
2154 return XEXP (index
, 0);
2161 /* Worker function for TARGET_MODE_DEPENDENT_ADDRESS_P.
2163 On the H8/300, the predecrement and postincrement address depend thus
2164 (the amount of decrement or increment being the length of the operand). */
2167 h8300_mode_dependent_address_p (const_rtx addr
,
2168 addr_space_t as ATTRIBUTE_UNUSED
)
2170 if (GET_CODE (addr
) == PLUS
2171 && h8300_get_index (XEXP (addr
, 0), VOIDmode
, 0) != XEXP (addr
, 0))
2177 static const h8300_length_table addb_length_table
=
2179 /* #xx Rs @aa @Rs @xx */
2180 { 2, 2, 4, 4, 4 }, /* add.b xx,Rd */
2181 { 4, 4, 4, 4, 6 }, /* add.b xx,@aa */
2182 { 4, 4, 4, 4, 6 }, /* add.b xx,@Rd */
2183 { 6, 4, 4, 4, 6 } /* add.b xx,@xx */
2186 static const h8300_length_table addw_length_table
=
2188 /* #xx Rs @aa @Rs @xx */
2189 { 2, 2, 4, 4, 4 }, /* add.w xx,Rd */
2190 { 4, 4, 4, 4, 6 }, /* add.w xx,@aa */
2191 { 4, 4, 4, 4, 6 }, /* add.w xx,@Rd */
2192 { 4, 4, 4, 4, 6 } /* add.w xx,@xx */
2195 static const h8300_length_table addl_length_table
=
2197 /* #xx Rs @aa @Rs @xx */
2198 { 2, 2, 4, 4, 4 }, /* add.l xx,Rd */
2199 { 4, 4, 6, 6, 6 }, /* add.l xx,@aa */
2200 { 4, 4, 6, 6, 6 }, /* add.l xx,@Rd */
2201 { 4, 4, 6, 6, 6 } /* add.l xx,@xx */
2204 #define logicb_length_table addb_length_table
2205 #define logicw_length_table addw_length_table
2207 static const h8300_length_table logicl_length_table
=
2209 /* #xx Rs @aa @Rs @xx */
2210 { 2, 4, 4, 4, 4 }, /* and.l xx,Rd */
2211 { 4, 4, 6, 6, 6 }, /* and.l xx,@aa */
2212 { 4, 4, 6, 6, 6 }, /* and.l xx,@Rd */
2213 { 4, 4, 6, 6, 6 } /* and.l xx,@xx */
2216 static const h8300_length_table movb_length_table
=
2218 /* #xx Rs @aa @Rs @xx */
2219 { 2, 2, 2, 2, 4 }, /* mov.b xx,Rd */
2220 { 4, 2, 4, 4, 4 }, /* mov.b xx,@aa */
2221 { 4, 2, 4, 4, 4 }, /* mov.b xx,@Rd */
2222 { 4, 4, 4, 4, 4 } /* mov.b xx,@xx */
2225 #define movw_length_table movb_length_table
2227 static const h8300_length_table movl_length_table
=
2229 /* #xx Rs @aa @Rs @xx */
2230 { 2, 2, 4, 4, 4 }, /* mov.l xx,Rd */
2231 { 4, 4, 4, 4, 4 }, /* mov.l xx,@aa */
2232 { 4, 4, 4, 4, 4 }, /* mov.l xx,@Rd */
2233 { 4, 4, 4, 4, 4 } /* mov.l xx,@xx */
2236 /* Return the size of the given address or displacement constant. */
2239 h8300_constant_length (rtx constant
)
2241 /* Check for (@d:16,Reg). */
2242 if (GET_CODE (constant
) == CONST_INT
2243 && IN_RANGE (INTVAL (constant
), -0x8000, 0x7fff))
2246 /* Check for (@d:16,Reg) in cases where the displacement is
2247 an absolute address. */
2248 if (Pmode
== HImode
|| h8300_tiny_constant_address_p (constant
))
2254 /* Return the size of a displacement field in address ADDR, which should
2255 have the form (plus X constant). SIZE is the number of bytes being
2259 h8300_displacement_length (rtx addr
, int size
)
2263 offset
= XEXP (addr
, 1);
2265 /* Check for @(d:2,Reg). */
2266 if (register_operand (XEXP (addr
, 0), VOIDmode
)
2267 && GET_CODE (offset
) == CONST_INT
2268 && (INTVAL (offset
) == size
2269 || INTVAL (offset
) == size
* 2
2270 || INTVAL (offset
) == size
* 3))
2273 return h8300_constant_length (offset
);
2276 /* Store the class of operand OP in *OPCLASS and return the length of any
2277 extra operand fields. SIZE is the number of bytes in OP. OPCLASS
2278 can be null if only the length is needed. */
2281 h8300_classify_operand (rtx op
, int size
, enum h8300_operand_class
*opclass
)
2283 enum h8300_operand_class dummy
;
2288 if (CONSTANT_P (op
))
2290 *opclass
= H8OP_IMMEDIATE
;
2292 /* Byte-sized immediates are stored in the opcode fields. */
2296 /* If this is a 32-bit instruction, see whether the constant
2297 will fit into a 16-bit immediate field. */
2300 && GET_CODE (op
) == CONST_INT
2301 && IN_RANGE (INTVAL (op
), 0, 0xffff))
2306 else if (GET_CODE (op
) == MEM
)
2309 if (CONSTANT_P (op
))
2311 *opclass
= H8OP_MEM_ABSOLUTE
;
2312 return h8300_constant_length (op
);
2314 else if (GET_CODE (op
) == PLUS
&& CONSTANT_P (XEXP (op
, 1)))
2316 *opclass
= H8OP_MEM_COMPLEX
;
2317 return h8300_displacement_length (op
, size
);
2319 else if (GET_RTX_CLASS (GET_CODE (op
)) == RTX_AUTOINC
)
2321 *opclass
= H8OP_MEM_COMPLEX
;
2324 else if (register_operand (op
, VOIDmode
))
2326 *opclass
= H8OP_MEM_BASE
;
2330 gcc_assert (register_operand (op
, VOIDmode
));
2331 *opclass
= H8OP_REGISTER
;
2335 /* Return the length of the instruction described by TABLE given that
2336 its operands are OP1 and OP2. OP1 must be an h8300_dst_operand
2337 and OP2 must be an h8300_src_operand. */
2340 h8300_length_from_table (rtx op1
, rtx op2
, const h8300_length_table
*table
)
2342 enum h8300_operand_class op1_class
, op2_class
;
2343 unsigned int size
, immediate_length
;
2345 size
= GET_MODE_SIZE (GET_MODE (op1
));
2346 immediate_length
= (h8300_classify_operand (op1
, size
, &op1_class
)
2347 + h8300_classify_operand (op2
, size
, &op2_class
));
2348 return immediate_length
+ (*table
)[op1_class
- 1][op2_class
];
2351 /* Return the length of a unary instruction such as neg or not given that
2352 its operand is OP. */
2355 h8300_unary_length (rtx op
)
2357 enum h8300_operand_class opclass
;
2358 unsigned int size
, operand_length
;
2360 size
= GET_MODE_SIZE (GET_MODE (op
));
2361 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2368 return (size
== 4 ? 6 : 4);
2370 case H8OP_MEM_ABSOLUTE
:
2371 return operand_length
+ (size
== 4 ? 6 : 4);
2373 case H8OP_MEM_COMPLEX
:
2374 return operand_length
+ 6;
2381 /* Likewise short immediate instructions such as add.w #xx:3,OP. */
2384 h8300_short_immediate_length (rtx op
)
2386 enum h8300_operand_class opclass
;
2387 unsigned int size
, operand_length
;
2389 size
= GET_MODE_SIZE (GET_MODE (op
));
2390 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2398 case H8OP_MEM_ABSOLUTE
:
2399 case H8OP_MEM_COMPLEX
:
2400 return 4 + operand_length
;
2407 /* Likewise bitfield load and store instructions. */
2410 h8300_bitfield_length (rtx op
, rtx op2
)
2412 enum h8300_operand_class opclass
;
2413 unsigned int size
, operand_length
;
2415 if (GET_CODE (op
) == REG
)
2417 gcc_assert (GET_CODE (op
) != REG
);
2419 size
= GET_MODE_SIZE (GET_MODE (op
));
2420 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2425 case H8OP_MEM_ABSOLUTE
:
2426 case H8OP_MEM_COMPLEX
:
2427 return 4 + operand_length
;
2434 /* Calculate the length of general binary instruction INSN using TABLE. */
2437 h8300_binary_length (rtx insn
, const h8300_length_table
*table
)
2441 set
= single_set (insn
);
2444 if (BINARY_P (SET_SRC (set
)))
2445 return h8300_length_from_table (XEXP (SET_SRC (set
), 0),
2446 XEXP (SET_SRC (set
), 1), table
);
2449 gcc_assert (GET_RTX_CLASS (GET_CODE (SET_SRC (set
))) == RTX_TERNARY
);
2450 return h8300_length_from_table (XEXP (XEXP (SET_SRC (set
), 1), 0),
2451 XEXP (XEXP (SET_SRC (set
), 1), 1),
2456 /* Subroutine of h8300_move_length. Return true if OP is 1- or 2-byte
2457 memory reference and either (1) it has the form @(d:16,Rn) or
2458 (2) its address has the code given by INC_CODE. */
2461 h8300_short_move_mem_p (rtx op
, enum rtx_code inc_code
)
2466 if (GET_CODE (op
) != MEM
)
2469 addr
= XEXP (op
, 0);
2470 size
= GET_MODE_SIZE (GET_MODE (op
));
2471 if (size
!= 1 && size
!= 2)
2474 return (GET_CODE (addr
) == inc_code
2475 || (GET_CODE (addr
) == PLUS
2476 && GET_CODE (XEXP (addr
, 0)) == REG
2477 && h8300_displacement_length (addr
, size
) == 2));
2480 /* Calculate the length of move instruction INSN using the given length
2481 table. Although the tables are correct for most cases, there is some
2482 irregularity in the length of mov.b and mov.w. The following forms:
2489 are two bytes shorter than most other "mov Rs, @complex" or
2490 "mov @complex,Rd" combinations. */
2493 h8300_move_length (rtx
*operands
, const h8300_length_table
*table
)
2497 size
= h8300_length_from_table (operands
[0], operands
[1], table
);
2498 if (REG_P (operands
[0]) && h8300_short_move_mem_p (operands
[1], POST_INC
))
2500 if (REG_P (operands
[1]) && h8300_short_move_mem_p (operands
[0], PRE_DEC
))
2505 /* Return the length of a mova instruction with the given operands.
2506 DEST is the register destination, SRC is the source address and
2507 OFFSET is the 16-bit or 32-bit displacement. */
2510 h8300_mova_length (rtx dest
, rtx src
, rtx offset
)
2515 + h8300_constant_length (offset
)
2516 + h8300_classify_operand (src
, GET_MODE_SIZE (GET_MODE (src
)), 0));
2517 if (!REG_P (dest
) || !REG_P (src
) || REGNO (src
) != REGNO (dest
))
2522 /* Compute the length of INSN based on its length_table attribute.
2523 OPERANDS is the array of its operands. */
2526 h8300_insn_length_from_table (rtx insn
, rtx
* operands
)
2528 switch (get_attr_length_table (insn
))
2530 case LENGTH_TABLE_NONE
:
2533 case LENGTH_TABLE_ADDB
:
2534 return h8300_binary_length (insn
, &addb_length_table
);
2536 case LENGTH_TABLE_ADDW
:
2537 return h8300_binary_length (insn
, &addw_length_table
);
2539 case LENGTH_TABLE_ADDL
:
2540 return h8300_binary_length (insn
, &addl_length_table
);
2542 case LENGTH_TABLE_LOGICB
:
2543 return h8300_binary_length (insn
, &logicb_length_table
);
2545 case LENGTH_TABLE_MOVB
:
2546 return h8300_move_length (operands
, &movb_length_table
);
2548 case LENGTH_TABLE_MOVW
:
2549 return h8300_move_length (operands
, &movw_length_table
);
2551 case LENGTH_TABLE_MOVL
:
2552 return h8300_move_length (operands
, &movl_length_table
);
2554 case LENGTH_TABLE_MOVA
:
2555 return h8300_mova_length (operands
[0], operands
[1], operands
[2]);
2557 case LENGTH_TABLE_MOVA_ZERO
:
2558 return h8300_mova_length (operands
[0], operands
[1], const0_rtx
);
2560 case LENGTH_TABLE_UNARY
:
2561 return h8300_unary_length (operands
[0]);
2563 case LENGTH_TABLE_MOV_IMM4
:
2564 return 2 + h8300_classify_operand (operands
[0], 0, 0);
2566 case LENGTH_TABLE_SHORT_IMMEDIATE
:
2567 return h8300_short_immediate_length (operands
[0]);
2569 case LENGTH_TABLE_BITFIELD
:
2570 return h8300_bitfield_length (operands
[0], operands
[1]);
2572 case LENGTH_TABLE_BITBRANCH
:
2573 return h8300_bitfield_length (operands
[1], operands
[2]) - 2;
2580 /* Return true if LHS and RHS are memory references that can be mapped
2581 to the same h8sx assembly operand. LHS appears as the destination of
2582 an instruction and RHS appears as a source.
2584 Three cases are allowed:
2586 - RHS is @+Rn or @-Rn, LHS is @Rn
2587 - RHS is @Rn, LHS is @Rn+ or @Rn-
2588 - RHS and LHS have the same address and neither has side effects. */
2591 h8sx_mergeable_memrefs_p (rtx lhs
, rtx rhs
)
2593 if (GET_CODE (rhs
) == MEM
&& GET_CODE (lhs
) == MEM
)
2595 rhs
= XEXP (rhs
, 0);
2596 lhs
= XEXP (lhs
, 0);
2598 if (GET_CODE (rhs
) == PRE_INC
|| GET_CODE (rhs
) == PRE_DEC
)
2599 return rtx_equal_p (XEXP (rhs
, 0), lhs
);
2601 if (GET_CODE (lhs
) == POST_INC
|| GET_CODE (lhs
) == POST_DEC
)
2602 return rtx_equal_p (rhs
, XEXP (lhs
, 0));
2604 if (rtx_equal_p (rhs
, lhs
))
2610 /* Return true if OPERANDS[1] can be mapped to the same assembly
2611 operand as OPERANDS[0]. */
2614 h8300_operands_match_p (rtx
*operands
)
2616 if (register_operand (operands
[0], VOIDmode
)
2617 && register_operand (operands
[1], VOIDmode
))
2620 if (h8sx_mergeable_memrefs_p (operands
[0], operands
[1]))
2626 /* Try using movmd to move LENGTH bytes from memory region SRC to memory
2627 region DEST. The two regions do not overlap and have the common
2628 alignment given by ALIGNMENT. Return true on success.
2630 Using movmd for variable-length moves seems to involve some
2631 complex trade-offs. For instance:
2633 - Preparing for a movmd instruction is similar to preparing
2634 for a memcpy. The main difference is that the arguments
2635 are moved into er4, er5 and er6 rather than er0, er1 and er2.
2637 - Since movmd clobbers the frame pointer, we need to save
2638 and restore it somehow when frame_pointer_needed. This can
2639 sometimes make movmd sequences longer than calls to memcpy().
2641 - The counter register is 16 bits, so the instruction is only
2642 suitable for variable-length moves when sizeof (size_t) == 2.
2643 That's only true in normal mode.
2645 - We will often lack static alignment information. Falling back
2646 on movmd.b would likely be slower than calling memcpy(), at least
2649 This function therefore only uses movmd when the length is a
2650 known constant, and only then if -fomit-frame-pointer is in
2651 effect or if we're not optimizing for size.
2653 At the moment the function uses movmd for all in-range constants,
2654 but it might be better to fall back on memcpy() for large moves
2655 if ALIGNMENT == 1. */
2658 h8sx_emit_movmd (rtx dest
, rtx src
, rtx length
,
2659 HOST_WIDE_INT alignment
)
2661 if (!flag_omit_frame_pointer
&& optimize_size
)
2664 if (GET_CODE (length
) == CONST_INT
)
2666 rtx dest_reg
, src_reg
, first_dest
, first_src
;
2670 /* Use movmd.l if the alignment allows it, otherwise fall back
2672 factor
= (alignment
>= 2 ? 4 : 1);
2674 /* Make sure the length is within range. We can handle counter
2675 values up to 65536, although HImode truncation will make
2676 the count appear negative in rtl dumps. */
2677 n
= INTVAL (length
);
2678 if (n
<= 0 || n
/ factor
> 65536)
2681 /* Create temporary registers for the source and destination
2682 pointers. Initialize them to the start of each region. */
2683 dest_reg
= copy_addr_to_reg (XEXP (dest
, 0));
2684 src_reg
= copy_addr_to_reg (XEXP (src
, 0));
2686 /* Create references to the movmd source and destination blocks. */
2687 first_dest
= replace_equiv_address (dest
, dest_reg
);
2688 first_src
= replace_equiv_address (src
, src_reg
);
2690 set_mem_size (first_dest
, n
& -factor
);
2691 set_mem_size (first_src
, n
& -factor
);
2693 length
= copy_to_mode_reg (HImode
, gen_int_mode (n
/ factor
, HImode
));
2694 emit_insn (gen_movmd (first_dest
, first_src
, length
, GEN_INT (factor
)));
2696 if ((n
& -factor
) != n
)
2698 /* Move SRC and DEST past the region we just copied.
2699 This is done to update the memory attributes. */
2700 dest
= adjust_address (dest
, BLKmode
, n
& -factor
);
2701 src
= adjust_address (src
, BLKmode
, n
& -factor
);
2703 /* Replace the addresses with the source and destination
2704 registers, which movmd has left with the right values. */
2705 dest
= replace_equiv_address (dest
, dest_reg
);
2706 src
= replace_equiv_address (src
, src_reg
);
2708 /* Mop up the left-over bytes. */
2710 emit_move_insn (adjust_address (dest
, HImode
, 0),
2711 adjust_address (src
, HImode
, 0));
2713 emit_move_insn (adjust_address (dest
, QImode
, n
& 2),
2714 adjust_address (src
, QImode
, n
& 2));
2721 /* Move ADDR into er6 after pushing its old value onto the stack. */
2724 h8300_swap_into_er6 (rtx addr
)
2726 rtx insn
= push (HARD_FRAME_POINTER_REGNUM
);
2727 if (frame_pointer_needed
)
2728 add_reg_note (insn
, REG_CFA_DEF_CFA
,
2729 plus_constant (Pmode
, gen_rtx_MEM (Pmode
, stack_pointer_rtx
),
2730 2 * UNITS_PER_WORD
));
2732 add_reg_note (insn
, REG_CFA_ADJUST_CFA
,
2733 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
2734 plus_constant (Pmode
, stack_pointer_rtx
, 4)));
2736 emit_move_insn (hard_frame_pointer_rtx
, addr
);
2737 if (REGNO (addr
) == SP_REG
)
2738 emit_move_insn (hard_frame_pointer_rtx
,
2739 plus_constant (Pmode
, hard_frame_pointer_rtx
,
2740 GET_MODE_SIZE (word_mode
)));
2743 /* Move the current value of er6 into ADDR and pop its old value
2747 h8300_swap_out_of_er6 (rtx addr
)
2751 if (REGNO (addr
) != SP_REG
)
2752 emit_move_insn (addr
, hard_frame_pointer_rtx
);
2754 insn
= pop (HARD_FRAME_POINTER_REGNUM
);
2755 RTX_FRAME_RELATED_P (insn
) = 1;
2756 if (frame_pointer_needed
)
2757 add_reg_note (insn
, REG_CFA_DEF_CFA
,
2758 plus_constant (Pmode
, hard_frame_pointer_rtx
,
2759 2 * UNITS_PER_WORD
));
2761 add_reg_note (insn
, REG_CFA_ADJUST_CFA
,
2762 gen_rtx_SET (VOIDmode
, stack_pointer_rtx
,
2763 plus_constant (Pmode
, stack_pointer_rtx
, -4)));
2766 /* Return the length of mov instruction. */
2769 compute_mov_length (rtx
*operands
)
2771 /* If the mov instruction involves a memory operand, we compute the
2772 length, assuming the largest addressing mode is used, and then
2773 adjust later in the function. Otherwise, we compute and return
2774 the exact length in one step. */
2775 enum machine_mode mode
= GET_MODE (operands
[0]);
2776 rtx dest
= operands
[0];
2777 rtx src
= operands
[1];
2780 if (GET_CODE (src
) == MEM
)
2781 addr
= XEXP (src
, 0);
2782 else if (GET_CODE (dest
) == MEM
)
2783 addr
= XEXP (dest
, 0);
2789 unsigned int base_length
;
2794 if (addr
== NULL_RTX
)
2797 /* The eightbit addressing is available only in QImode, so
2798 go ahead and take care of it. */
2799 if (h8300_eightbit_constant_address_p (addr
))
2806 if (addr
== NULL_RTX
)
2811 if (src
== const0_rtx
)
2821 if (addr
== NULL_RTX
)
2826 if (GET_CODE (src
) == CONST_INT
)
2828 if (src
== const0_rtx
)
2831 if ((INTVAL (src
) & 0xffff) == 0)
2834 if ((INTVAL (src
) & 0xffff) == 0)
2837 if ((INTVAL (src
) & 0xffff)
2838 == ((INTVAL (src
) >> 16) & 0xffff))
2848 if (addr
== NULL_RTX
)
2853 if (satisfies_constraint_G (src
))
2866 /* Adjust the length based on the addressing mode used.
2867 Specifically, we subtract the difference between the actual
2868 length and the longest one, which is @(d:16,Rs). For SImode
2869 and SFmode, we double the adjustment because two mov.w are
2870 used to do the job. */
2872 /* @Rs+ and @-Rd are 2 bytes shorter than the longest. */
2873 if (GET_CODE (addr
) == PRE_DEC
2874 || GET_CODE (addr
) == POST_INC
)
2876 if (mode
== QImode
|| mode
== HImode
)
2877 return base_length
- 2;
2879 /* In SImode and SFmode, we use two mov.w instructions, so
2880 double the adjustment. */
2881 return base_length
- 4;
2884 /* @Rs and @Rd are 2 bytes shorter than the longest. Note that
2885 in SImode and SFmode, the second mov.w involves an address
2886 with displacement, namely @(2,Rs) or @(2,Rd), so we subtract
2888 if (GET_CODE (addr
) == REG
)
2889 return base_length
- 2;
2895 unsigned int base_length
;
2900 if (addr
== NULL_RTX
)
2903 /* The eightbit addressing is available only in QImode, so
2904 go ahead and take care of it. */
2905 if (h8300_eightbit_constant_address_p (addr
))
2912 if (addr
== NULL_RTX
)
2917 if (src
== const0_rtx
)
2927 if (addr
== NULL_RTX
)
2931 if (REGNO (src
) == MAC_REG
|| REGNO (dest
) == MAC_REG
)
2937 if (GET_CODE (src
) == CONST_INT
)
2939 int val
= INTVAL (src
);
2944 if (val
== (val
& 0x00ff) || val
== (val
& 0xff00))
2947 switch (val
& 0xffffffff)
2968 if (addr
== NULL_RTX
)
2973 if (satisfies_constraint_G (src
))
2986 /* Adjust the length based on the addressing mode used.
2987 Specifically, we subtract the difference between the actual
2988 length and the longest one, which is @(d:24,ERs). */
2990 /* @ERs+ and @-ERd are 6 bytes shorter than the longest. */
2991 if (GET_CODE (addr
) == PRE_DEC
2992 || GET_CODE (addr
) == POST_INC
)
2993 return base_length
- 6;
2995 /* @ERs and @ERd are 6 bytes shorter than the longest. */
2996 if (GET_CODE (addr
) == REG
)
2997 return base_length
- 6;
2999 /* @(d:16,ERs) and @(d:16,ERd) are 4 bytes shorter than the
3001 if (GET_CODE (addr
) == PLUS
3002 && GET_CODE (XEXP (addr
, 0)) == REG
3003 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
3004 && INTVAL (XEXP (addr
, 1)) > -32768
3005 && INTVAL (XEXP (addr
, 1)) < 32767)
3006 return base_length
- 4;
3008 /* @aa:16 is 4 bytes shorter than the longest. */
3009 if (h8300_tiny_constant_address_p (addr
))
3010 return base_length
- 4;
3012 /* @aa:24 is 2 bytes shorter than the longest. */
3013 if (CONSTANT_P (addr
))
3014 return base_length
- 2;
3020 /* Output an addition insn. */
3023 output_plussi (rtx
*operands
)
3025 enum machine_mode mode
= GET_MODE (operands
[0]);
3027 gcc_assert (mode
== SImode
);
3031 if (GET_CODE (operands
[2]) == REG
)
3032 return "add.w\t%f2,%f0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
3034 if (GET_CODE (operands
[2]) == CONST_INT
)
3036 HOST_WIDE_INT n
= INTVAL (operands
[2]);
3038 if ((n
& 0xffffff) == 0)
3039 return "add\t%z2,%z0";
3040 if ((n
& 0xffff) == 0)
3041 return "add\t%y2,%y0\n\taddx\t%z2,%z0";
3042 if ((n
& 0xff) == 0)
3043 return "add\t%x2,%x0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
3046 return "add\t%w2,%w0\n\taddx\t%x2,%x0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
3050 if (GET_CODE (operands
[2]) == CONST_INT
3051 && register_operand (operands
[1], VOIDmode
))
3053 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3055 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3056 return "add.l\t%S2,%S0";
3057 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3058 return "sub.l\t%G2,%S0";
3060 /* See if we can finish with 2 bytes. */
3062 switch ((unsigned int) intval
& 0xffffffff)
3067 return "adds\t%2,%S0";
3072 return "subs\t%G2,%S0";
3076 operands
[2] = GEN_INT (intval
>> 16);
3077 return "inc.w\t%2,%e0";
3081 operands
[2] = GEN_INT (intval
>> 16);
3082 return "dec.w\t%G2,%e0";
3085 /* See if we can finish with 4 bytes. */
3086 if ((intval
& 0xffff) == 0)
3088 operands
[2] = GEN_INT (intval
>> 16);
3089 return "add.w\t%2,%e0";
3093 if (GET_CODE (operands
[2]) == CONST_INT
&& INTVAL (operands
[2]) < 0)
3095 operands
[2] = GEN_INT (-INTVAL (operands
[2]));
3096 return "sub.l\t%S2,%S0";
3098 return "add.l\t%S2,%S0";
3102 /* ??? It would be much easier to add the h8sx stuff if a single function
3103 classified the addition as either inc/dec, adds/subs, add.w or add.l. */
3104 /* Compute the length of an addition insn. */
3107 compute_plussi_length (rtx
*operands
)
3109 enum machine_mode mode
= GET_MODE (operands
[0]);
3111 gcc_assert (mode
== SImode
);
3115 if (GET_CODE (operands
[2]) == REG
)
3118 if (GET_CODE (operands
[2]) == CONST_INT
)
3120 HOST_WIDE_INT n
= INTVAL (operands
[2]);
3122 if ((n
& 0xffffff) == 0)
3124 if ((n
& 0xffff) == 0)
3126 if ((n
& 0xff) == 0)
3134 if (GET_CODE (operands
[2]) == CONST_INT
3135 && register_operand (operands
[1], VOIDmode
))
3137 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3139 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3141 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3144 /* See if we can finish with 2 bytes. */
3146 switch ((unsigned int) intval
& 0xffffffff)
3167 /* See if we can finish with 4 bytes. */
3168 if ((intval
& 0xffff) == 0)
3172 if (GET_CODE (operands
[2]) == CONST_INT
&& INTVAL (operands
[2]) < 0)
3173 return h8300_length_from_table (operands
[0],
3174 GEN_INT (-INTVAL (operands
[2])),
3175 &addl_length_table
);
3177 return h8300_length_from_table (operands
[0], operands
[2],
3178 &addl_length_table
);
3183 /* Compute which flag bits are valid after an addition insn. */
3186 compute_plussi_cc (rtx
*operands
)
3188 enum machine_mode mode
= GET_MODE (operands
[0]);
3190 gcc_assert (mode
== SImode
);
3198 if (GET_CODE (operands
[2]) == CONST_INT
3199 && register_operand (operands
[1], VOIDmode
))
3201 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3203 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3205 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3208 /* See if we can finish with 2 bytes. */
3210 switch ((unsigned int) intval
& 0xffffffff)
3215 return CC_NONE_0HIT
;
3220 return CC_NONE_0HIT
;
3231 /* See if we can finish with 4 bytes. */
3232 if ((intval
& 0xffff) == 0)
3240 /* Output a logical insn. */
3243 output_logical_op (enum machine_mode mode
, rtx
*operands
)
3245 /* Figure out the logical op that we need to perform. */
3246 enum rtx_code code
= GET_CODE (operands
[3]);
3247 /* Pretend that every byte is affected if both operands are registers. */
3248 const unsigned HOST_WIDE_INT intval
=
3249 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3250 /* Always use the full instruction if the
3251 first operand is in memory. It is better
3252 to use define_splits to generate the shorter
3253 sequence where valid. */
3254 && register_operand (operands
[1], VOIDmode
)
3255 ? INTVAL (operands
[2]) : 0x55555555);
3256 /* The determinant of the algorithm. If we perform an AND, 0
3257 affects a bit. Otherwise, 1 affects a bit. */
3258 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3259 /* Break up DET into pieces. */
3260 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3261 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3262 const unsigned HOST_WIDE_INT b2
= (det
>> 16) & 0xff;
3263 const unsigned HOST_WIDE_INT b3
= (det
>> 24) & 0xff;
3264 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3265 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3266 int lower_half_easy_p
= 0;
3267 int upper_half_easy_p
= 0;
3268 /* The name of an insn. */
3290 /* First, see if we can finish with one insn. */
3291 if ((TARGET_H8300H
|| TARGET_H8300S
)
3295 sprintf (insn_buf
, "%s.w\t%%T2,%%T0", opname
);
3296 output_asm_insn (insn_buf
, operands
);
3300 /* Take care of the lower byte. */
3303 sprintf (insn_buf
, "%s\t%%s2,%%s0", opname
);
3304 output_asm_insn (insn_buf
, operands
);
3306 /* Take care of the upper byte. */
3309 sprintf (insn_buf
, "%s\t%%t2,%%t0", opname
);
3310 output_asm_insn (insn_buf
, operands
);
3315 if (TARGET_H8300H
|| TARGET_H8300S
)
3317 /* Determine if the lower half can be taken care of in no more
3319 lower_half_easy_p
= (b0
== 0
3321 || (code
!= IOR
&& w0
== 0xffff));
3323 /* Determine if the upper half can be taken care of in no more
3325 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3326 || (code
== AND
&& w1
== 0xff00));
3329 /* Check if doing everything with one insn is no worse than
3330 using multiple insns. */
3331 if ((TARGET_H8300H
|| TARGET_H8300S
)
3332 && w0
!= 0 && w1
!= 0
3333 && !(lower_half_easy_p
&& upper_half_easy_p
)
3334 && !(code
== IOR
&& w1
== 0xffff
3335 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3337 sprintf (insn_buf
, "%s.l\t%%S2,%%S0", opname
);
3338 output_asm_insn (insn_buf
, operands
);
3342 /* Take care of the lower and upper words individually. For
3343 each word, we try different methods in the order of
3345 1) the special insn (in case of AND or XOR),
3346 2) the word-wise insn, and
3347 3) The byte-wise insn. */
3349 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3350 output_asm_insn ((code
== AND
)
3351 ? "sub.w\t%f0,%f0" : "not.w\t%f0",
3353 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3357 sprintf (insn_buf
, "%s.w\t%%f2,%%f0", opname
);
3358 output_asm_insn (insn_buf
, operands
);
3364 sprintf (insn_buf
, "%s\t%%w2,%%w0", opname
);
3365 output_asm_insn (insn_buf
, operands
);
3369 sprintf (insn_buf
, "%s\t%%x2,%%x0", opname
);
3370 output_asm_insn (insn_buf
, operands
);
3375 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3376 output_asm_insn ((code
== AND
)
3377 ? "sub.w\t%e0,%e0" : "not.w\t%e0",
3379 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3382 && (w0
& 0x8000) != 0)
3384 output_asm_insn ("exts.l\t%S0", operands
);
3386 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3390 output_asm_insn ("extu.w\t%e0", operands
);
3392 else if (TARGET_H8300H
|| TARGET_H8300S
)
3396 sprintf (insn_buf
, "%s.w\t%%e2,%%e0", opname
);
3397 output_asm_insn (insn_buf
, operands
);
3404 sprintf (insn_buf
, "%s\t%%y2,%%y0", opname
);
3405 output_asm_insn (insn_buf
, operands
);
3409 sprintf (insn_buf
, "%s\t%%z2,%%z0", opname
);
3410 output_asm_insn (insn_buf
, operands
);
3421 /* Compute the length of a logical insn. */
3424 compute_logical_op_length (enum machine_mode mode
, rtx
*operands
)
3426 /* Figure out the logical op that we need to perform. */
3427 enum rtx_code code
= GET_CODE (operands
[3]);
3428 /* Pretend that every byte is affected if both operands are registers. */
3429 const unsigned HOST_WIDE_INT intval
=
3430 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3431 /* Always use the full instruction if the
3432 first operand is in memory. It is better
3433 to use define_splits to generate the shorter
3434 sequence where valid. */
3435 && register_operand (operands
[1], VOIDmode
)
3436 ? INTVAL (operands
[2]) : 0x55555555);
3437 /* The determinant of the algorithm. If we perform an AND, 0
3438 affects a bit. Otherwise, 1 affects a bit. */
3439 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3440 /* Break up DET into pieces. */
3441 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3442 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3443 const unsigned HOST_WIDE_INT b2
= (det
>> 16) & 0xff;
3444 const unsigned HOST_WIDE_INT b3
= (det
>> 24) & 0xff;
3445 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3446 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3447 int lower_half_easy_p
= 0;
3448 int upper_half_easy_p
= 0;
3450 unsigned int length
= 0;
3455 /* First, see if we can finish with one insn. */
3456 if ((TARGET_H8300H
|| TARGET_H8300S
)
3460 length
= h8300_length_from_table (operands
[1], operands
[2],
3461 &logicw_length_table
);
3465 /* Take care of the lower byte. */
3469 /* Take care of the upper byte. */
3475 if (TARGET_H8300H
|| TARGET_H8300S
)
3477 /* Determine if the lower half can be taken care of in no more
3479 lower_half_easy_p
= (b0
== 0
3481 || (code
!= IOR
&& w0
== 0xffff));
3483 /* Determine if the upper half can be taken care of in no more
3485 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3486 || (code
== AND
&& w1
== 0xff00));
3489 /* Check if doing everything with one insn is no worse than
3490 using multiple insns. */
3491 if ((TARGET_H8300H
|| TARGET_H8300S
)
3492 && w0
!= 0 && w1
!= 0
3493 && !(lower_half_easy_p
&& upper_half_easy_p
)
3494 && !(code
== IOR
&& w1
== 0xffff
3495 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3497 length
= h8300_length_from_table (operands
[1], operands
[2],
3498 &logicl_length_table
);
3502 /* Take care of the lower and upper words individually. For
3503 each word, we try different methods in the order of
3505 1) the special insn (in case of AND or XOR),
3506 2) the word-wise insn, and
3507 3) The byte-wise insn. */
3509 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3513 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3529 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3533 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3536 && (w0
& 0x8000) != 0)
3540 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3546 else if (TARGET_H8300H
|| TARGET_H8300S
)
3567 /* Compute which flag bits are valid after a logical insn. */
3570 compute_logical_op_cc (enum machine_mode mode
, rtx
*operands
)
3572 /* Figure out the logical op that we need to perform. */
3573 enum rtx_code code
= GET_CODE (operands
[3]);
3574 /* Pretend that every byte is affected if both operands are registers. */
3575 const unsigned HOST_WIDE_INT intval
=
3576 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3577 /* Always use the full instruction if the
3578 first operand is in memory. It is better
3579 to use define_splits to generate the shorter
3580 sequence where valid. */
3581 && register_operand (operands
[1], VOIDmode
)
3582 ? INTVAL (operands
[2]) : 0x55555555);
3583 /* The determinant of the algorithm. If we perform an AND, 0
3584 affects a bit. Otherwise, 1 affects a bit. */
3585 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3586 /* Break up DET into pieces. */
3587 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3588 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3589 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3590 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3591 int lower_half_easy_p
= 0;
3592 int upper_half_easy_p
= 0;
3593 /* Condition code. */
3594 enum attr_cc cc
= CC_CLOBBER
;
3599 /* First, see if we can finish with one insn. */
3600 if ((TARGET_H8300H
|| TARGET_H8300S
)
3608 if (TARGET_H8300H
|| TARGET_H8300S
)
3610 /* Determine if the lower half can be taken care of in no more
3612 lower_half_easy_p
= (b0
== 0
3614 || (code
!= IOR
&& w0
== 0xffff));
3616 /* Determine if the upper half can be taken care of in no more
3618 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3619 || (code
== AND
&& w1
== 0xff00));
3622 /* Check if doing everything with one insn is no worse than
3623 using multiple insns. */
3624 if ((TARGET_H8300H
|| TARGET_H8300S
)
3625 && w0
!= 0 && w1
!= 0
3626 && !(lower_half_easy_p
&& upper_half_easy_p
)
3627 && !(code
== IOR
&& w1
== 0xffff
3628 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3634 if ((TARGET_H8300H
|| TARGET_H8300S
)
3637 && (w0
& 0x8000) != 0)
3649 /* Expand a conditional branch. */
3652 h8300_expand_branch (rtx operands
[])
3654 enum rtx_code code
= GET_CODE (operands
[0]);
3655 rtx op0
= operands
[1];
3656 rtx op1
= operands
[2];
3657 rtx label
= operands
[3];
3660 tmp
= gen_rtx_COMPARE (VOIDmode
, op0
, op1
);
3661 emit_insn (gen_rtx_SET (VOIDmode
, cc0_rtx
, tmp
));
3663 tmp
= gen_rtx_fmt_ee (code
, VOIDmode
, cc0_rtx
, const0_rtx
);
3664 tmp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, tmp
,
3665 gen_rtx_LABEL_REF (VOIDmode
, label
),
3667 emit_jump_insn (gen_rtx_SET (VOIDmode
, pc_rtx
, tmp
));
3671 /* Expand a conditional store. */
3674 h8300_expand_store (rtx operands
[])
3676 rtx dest
= operands
[0];
3677 enum rtx_code code
= GET_CODE (operands
[1]);
3678 rtx op0
= operands
[2];
3679 rtx op1
= operands
[3];
3682 tmp
= gen_rtx_COMPARE (VOIDmode
, op0
, op1
);
3683 emit_insn (gen_rtx_SET (VOIDmode
, cc0_rtx
, tmp
));
3685 tmp
= gen_rtx_fmt_ee (code
, GET_MODE (dest
), cc0_rtx
, const0_rtx
);
3686 emit_insn (gen_rtx_SET (VOIDmode
, dest
, tmp
));
3691 We devote a fair bit of code to getting efficient shifts since we
3692 can only shift one bit at a time on the H8/300 and H8/300H and only
3693 one or two bits at a time on the H8S.
3695 All shift code falls into one of the following ways of
3698 o SHIFT_INLINE: Emit straight line code for the shift; this is used
3699 when a straight line shift is about the same size or smaller than
3702 o SHIFT_ROT_AND: Rotate the value the opposite direction, then mask
3703 off the bits we don't need. This is used when only a few of the
3704 bits in the original value will survive in the shifted value.
3706 o SHIFT_SPECIAL: Often it's possible to move a byte or a word to
3707 simulate a shift by 8, 16, or 24 bits. Once moved, a few inline
3708 shifts can be added if the shift count is slightly more than 8 or
3709 16. This case also includes other oddballs that are not worth
3712 o SHIFT_LOOP: Emit a loop using one (or two on H8S) bit shifts.
3714 For each shift count, we try to use code that has no trade-off
3715 between code size and speed whenever possible.
3717 If the trade-off is unavoidable, we try to be reasonable.
3718 Specifically, the fastest version is one instruction longer than
3719 the shortest version, we take the fastest version. We also provide
3720 the use a way to switch back to the shortest version with -Os.
3722 For the details of the shift algorithms for various shift counts,
3723 refer to shift_alg_[qhs]i. */
3725 /* Classify a shift with the given mode and code. OP is the shift amount. */
3727 enum h8sx_shift_type
3728 h8sx_classify_shift (enum machine_mode mode
, enum rtx_code code
, rtx op
)
3730 if (!TARGET_H8300SX
)
3731 return H8SX_SHIFT_NONE
;
3737 /* Check for variable shifts (shll Rs,Rd and shlr Rs,Rd). */
3738 if (GET_CODE (op
) != CONST_INT
)
3739 return H8SX_SHIFT_BINARY
;
3741 /* Reject out-of-range shift amounts. */
3742 if (INTVAL (op
) <= 0 || INTVAL (op
) >= GET_MODE_BITSIZE (mode
))
3743 return H8SX_SHIFT_NONE
;
3745 /* Power-of-2 shifts are effectively unary operations. */
3746 if (exact_log2 (INTVAL (op
)) >= 0)
3747 return H8SX_SHIFT_UNARY
;
3749 return H8SX_SHIFT_BINARY
;
3752 if (op
== const1_rtx
|| op
== const2_rtx
)
3753 return H8SX_SHIFT_UNARY
;
3754 return H8SX_SHIFT_NONE
;
3757 if (GET_CODE (op
) == CONST_INT
3758 && (INTVAL (op
) == 1
3760 || INTVAL (op
) == GET_MODE_BITSIZE (mode
) - 2
3761 || INTVAL (op
) == GET_MODE_BITSIZE (mode
) - 1))
3762 return H8SX_SHIFT_UNARY
;
3763 return H8SX_SHIFT_NONE
;
3766 return H8SX_SHIFT_NONE
;
3770 /* Return the asm template for a single h8sx shift instruction.
3771 OPERANDS[0] and OPERANDS[1] are the destination, OPERANDS[2]
3772 is the source and OPERANDS[3] is the shift. SUFFIX is the
3773 size suffix ('b', 'w' or 'l') and OPTYPE is the h8300_print_operand
3774 prefix for the destination operand. */
3777 output_h8sx_shift (rtx
*operands
, int suffix
, int optype
)
3779 static char buffer
[16];
3782 switch (GET_CODE (operands
[3]))
3798 if (INTVAL (operands
[2]) > 2)
3800 /* This is really a right rotate. */
3801 operands
[2] = GEN_INT (GET_MODE_BITSIZE (GET_MODE (operands
[0]))
3802 - INTVAL (operands
[2]));
3810 if (operands
[2] == const1_rtx
)
3811 sprintf (buffer
, "%s.%c\t%%%c0", stem
, suffix
, optype
);
3813 sprintf (buffer
, "%s.%c\t%%X2,%%%c0", stem
, suffix
, optype
);
3817 /* Emit code to do shifts. */
3820 expand_a_shift (enum machine_mode mode
, enum rtx_code code
, rtx operands
[])
3822 switch (h8sx_classify_shift (mode
, code
, operands
[2]))
3824 case H8SX_SHIFT_BINARY
:
3825 operands
[1] = force_reg (mode
, operands
[1]);
3828 case H8SX_SHIFT_UNARY
:
3831 case H8SX_SHIFT_NONE
:
3835 emit_move_insn (copy_rtx (operands
[0]), operands
[1]);
3837 /* Need a loop to get all the bits we want - we generate the
3838 code at emit time, but need to allocate a scratch reg now. */
3840 emit_insn (gen_rtx_PARALLEL
3843 gen_rtx_SET (VOIDmode
, copy_rtx (operands
[0]),
3844 gen_rtx_fmt_ee (code
, mode
,
3845 copy_rtx (operands
[0]), operands
[2])),
3846 gen_rtx_CLOBBER (VOIDmode
,
3847 gen_rtx_SCRATCH (QImode
)))));
3851 /* Symbols of the various modes which can be used as indices. */
3855 QIshift
, HIshift
, SIshift
3858 /* For single bit shift insns, record assembler and what bits of the
3859 condition code are valid afterwards (represented as various CC_FOO
3860 bits, 0 means CC isn't left in a usable state). */
3864 const char *const assembler
;
3865 const enum attr_cc cc_valid
;
3868 /* Assembler instruction shift table.
3870 These tables are used to look up the basic shifts.
3871 They are indexed by cpu, shift_type, and mode. */
3873 static const struct shift_insn shift_one
[2][3][3] =
3879 { "shll\t%X0", CC_SET_ZNV
},
3880 { "add.w\t%T0,%T0", CC_SET_ZN
},
3881 { "add.w\t%f0,%f0\n\taddx\t%y0,%y0\n\taddx\t%z0,%z0", CC_CLOBBER
}
3883 /* SHIFT_LSHIFTRT */
3885 { "shlr\t%X0", CC_SET_ZNV
},
3886 { "shlr\t%t0\n\trotxr\t%s0", CC_CLOBBER
},
3887 { "shlr\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", CC_CLOBBER
}
3889 /* SHIFT_ASHIFTRT */
3891 { "shar\t%X0", CC_SET_ZNV
},
3892 { "shar\t%t0\n\trotxr\t%s0", CC_CLOBBER
},
3893 { "shar\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", CC_CLOBBER
}
3900 { "shll.b\t%X0", CC_SET_ZNV
},
3901 { "shll.w\t%T0", CC_SET_ZNV
},
3902 { "shll.l\t%S0", CC_SET_ZNV
}
3904 /* SHIFT_LSHIFTRT */
3906 { "shlr.b\t%X0", CC_SET_ZNV
},
3907 { "shlr.w\t%T0", CC_SET_ZNV
},
3908 { "shlr.l\t%S0", CC_SET_ZNV
}
3910 /* SHIFT_ASHIFTRT */
3912 { "shar.b\t%X0", CC_SET_ZNV
},
3913 { "shar.w\t%T0", CC_SET_ZNV
},
3914 { "shar.l\t%S0", CC_SET_ZNV
}
3919 static const struct shift_insn shift_two
[3][3] =
3923 { "shll.b\t#2,%X0", CC_SET_ZNV
},
3924 { "shll.w\t#2,%T0", CC_SET_ZNV
},
3925 { "shll.l\t#2,%S0", CC_SET_ZNV
}
3927 /* SHIFT_LSHIFTRT */
3929 { "shlr.b\t#2,%X0", CC_SET_ZNV
},
3930 { "shlr.w\t#2,%T0", CC_SET_ZNV
},
3931 { "shlr.l\t#2,%S0", CC_SET_ZNV
}
3933 /* SHIFT_ASHIFTRT */
3935 { "shar.b\t#2,%X0", CC_SET_ZNV
},
3936 { "shar.w\t#2,%T0", CC_SET_ZNV
},
3937 { "shar.l\t#2,%S0", CC_SET_ZNV
}
3941 /* Rotates are organized by which shift they'll be used in implementing.
3942 There's no need to record whether the cc is valid afterwards because
3943 it is the AND insn that will decide this. */
3945 static const char *const rotate_one
[2][3][3] =
3952 "shlr\t%t0\n\trotxr\t%s0\n\tbst\t#7,%t0",
3955 /* SHIFT_LSHIFTRT */
3958 "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
3961 /* SHIFT_ASHIFTRT */
3964 "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
3976 /* SHIFT_LSHIFTRT */
3982 /* SHIFT_ASHIFTRT */
3991 static const char *const rotate_two
[3][3] =
3999 /* SHIFT_LSHIFTRT */
4005 /* SHIFT_ASHIFTRT */
4014 /* Shift algorithm. */
4017 /* The number of bits to be shifted by shift1 and shift2. Valid
4018 when ALG is SHIFT_SPECIAL. */
4019 unsigned int remainder
;
4021 /* Special insn for a shift. Valid when ALG is SHIFT_SPECIAL. */
4022 const char *special
;
4024 /* Insn for a one-bit shift. Valid when ALG is either SHIFT_INLINE
4025 or SHIFT_SPECIAL, and REMAINDER is nonzero. */
4028 /* Insn for a two-bit shift. Valid when ALG is either SHIFT_INLINE
4029 or SHIFT_SPECIAL, and REMAINDER is nonzero. */
4032 /* CC status for SHIFT_INLINE. */
4033 enum attr_cc cc_inline
;
4035 /* CC status for SHIFT_SPECIAL. */
4036 enum attr_cc cc_special
;
4039 static void get_shift_alg (enum shift_type
,
4040 enum shift_mode
, unsigned int,
4041 struct shift_info
*);
4043 /* Given SHIFT_TYPE, SHIFT_MODE, and shift count COUNT, determine the
4044 best algorithm for doing the shift. The assembler code is stored
4045 in the pointers in INFO. We achieve the maximum efficiency in most
4046 cases when !TARGET_H8300. In case of TARGET_H8300, shifts in
4047 SImode in particular have a lot of room to optimize.
4049 We first determine the strategy of the shift algorithm by a table
4050 lookup. If that tells us to use a hand crafted assembly code, we
4051 go into the big switch statement to find what that is. Otherwise,
4052 we resort to a generic way, such as inlining. In either case, the
4053 result is returned through INFO. */
4056 get_shift_alg (enum shift_type shift_type
, enum shift_mode shift_mode
,
4057 unsigned int count
, struct shift_info
*info
)
4061 /* Find the target CPU. */
4064 else if (TARGET_H8300H
)
4069 /* Find the shift algorithm. */
4070 info
->alg
= SHIFT_LOOP
;
4074 if (count
< GET_MODE_BITSIZE (QImode
))
4075 info
->alg
= shift_alg_qi
[cpu
][shift_type
][count
];
4079 if (count
< GET_MODE_BITSIZE (HImode
))
4080 info
->alg
= shift_alg_hi
[cpu
][shift_type
][count
];
4084 if (count
< GET_MODE_BITSIZE (SImode
))
4085 info
->alg
= shift_alg_si
[cpu
][shift_type
][count
];
4092 /* Fill in INFO. Return unless we have SHIFT_SPECIAL. */
4096 info
->remainder
= count
;
4100 /* It is up to the caller to know that looping clobbers cc. */
4101 info
->shift1
= shift_one
[cpu_type
][shift_type
][shift_mode
].assembler
;
4102 info
->shift2
= shift_two
[shift_type
][shift_mode
].assembler
;
4103 info
->cc_inline
= shift_one
[cpu_type
][shift_type
][shift_mode
].cc_valid
;
4107 info
->shift1
= rotate_one
[cpu_type
][shift_type
][shift_mode
];
4108 info
->shift2
= rotate_two
[shift_type
][shift_mode
];
4109 info
->cc_inline
= CC_CLOBBER
;
4113 /* REMAINDER is 0 for most cases, so initialize it to 0. */
4114 info
->remainder
= 0;
4115 info
->shift1
= shift_one
[cpu_type
][shift_type
][shift_mode
].assembler
;
4116 info
->shift2
= shift_two
[shift_type
][shift_mode
].assembler
;
4117 info
->cc_inline
= shift_one
[cpu_type
][shift_type
][shift_mode
].cc_valid
;
4118 info
->cc_special
= CC_CLOBBER
;
4122 /* Here we only deal with SHIFT_SPECIAL. */
4126 /* For ASHIFTRT by 7 bits, the sign bit is simply replicated
4127 through the entire value. */
4128 gcc_assert (shift_type
== SHIFT_ASHIFTRT
&& count
== 7);
4129 info
->special
= "shll\t%X0\n\tsubx\t%X0,%X0";
4139 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";
4141 info
->special
= "shar.b\t%t0\n\tmov.b\t%s0,%t0\n\trotxr.w\t%T0\n\tand.b\t#0x80,%s0";
4143 case SHIFT_LSHIFTRT
:
4145 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";
4147 info
->special
= "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.w\t%T0\n\tand.b\t#0x01,%t0";
4149 case SHIFT_ASHIFTRT
:
4150 info
->special
= "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.b\t%s0\n\tsubx\t%t0,%t0";
4154 else if ((8 <= count
&& count
<= 13)
4155 || (TARGET_H8300S
&& count
== 14))
4157 info
->remainder
= count
- 8;
4162 info
->special
= "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0";
4164 case SHIFT_LSHIFTRT
:
4167 info
->special
= "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0";
4168 info
->shift1
= "shlr.b\t%s0";
4169 info
->cc_inline
= CC_SET_ZNV
;
4173 info
->special
= "mov.b\t%t0,%s0\n\textu.w\t%T0";
4174 info
->cc_special
= CC_SET_ZNV
;
4177 case SHIFT_ASHIFTRT
:
4180 info
->special
= "mov.b\t%t0,%s0\n\tbld\t#7,%s0\n\tsubx\t%t0,%t0";
4181 info
->shift1
= "shar.b\t%s0";
4185 info
->special
= "mov.b\t%t0,%s0\n\texts.w\t%T0";
4186 info
->cc_special
= CC_SET_ZNV
;
4191 else if (count
== 14)
4197 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";
4199 case SHIFT_LSHIFTRT
:
4201 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";
4203 case SHIFT_ASHIFTRT
:
4205 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";
4206 else if (TARGET_H8300H
)
4208 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";
4209 info
->cc_special
= CC_SET_ZNV
;
4211 else /* TARGET_H8300S */
4216 else if (count
== 15)
4221 info
->special
= "bld\t#0,%s0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#7,%t0";
4223 case SHIFT_LSHIFTRT
:
4224 info
->special
= "bld\t#7,%t0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#0,%s0";
4226 case SHIFT_ASHIFTRT
:
4227 info
->special
= "shll\t%t0\n\tsubx\t%t0,%t0\n\tmov.b\t%t0,%s0";
4234 if (TARGET_H8300
&& 8 <= count
&& count
<= 9)
4236 info
->remainder
= count
- 8;
4241 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";
4243 case SHIFT_LSHIFTRT
:
4244 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";
4245 info
->shift1
= "shlr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0";
4247 case SHIFT_ASHIFTRT
:
4248 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";
4252 else if (count
== 8 && !TARGET_H8300
)
4257 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";
4259 case SHIFT_LSHIFTRT
:
4260 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";
4262 case SHIFT_ASHIFTRT
:
4263 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";
4267 else if (count
== 15 && TARGET_H8300
)
4273 case SHIFT_LSHIFTRT
:
4274 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";
4276 case SHIFT_ASHIFTRT
:
4277 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";
4281 else if (count
== 15 && !TARGET_H8300
)
4286 info
->special
= "shlr.w\t%e0\n\tmov.w\t%f0,%e0\n\txor.w\t%f0,%f0\n\trotxr.l\t%S0";
4287 info
->cc_special
= CC_SET_ZNV
;
4289 case SHIFT_LSHIFTRT
:
4290 info
->special
= "shll.w\t%f0\n\tmov.w\t%e0,%f0\n\txor.w\t%e0,%e0\n\trotxl.l\t%S0";
4291 info
->cc_special
= CC_SET_ZNV
;
4293 case SHIFT_ASHIFTRT
:
4297 else if ((TARGET_H8300
&& 16 <= count
&& count
<= 20)
4298 || (TARGET_H8300H
&& 16 <= count
&& count
<= 19)
4299 || (TARGET_H8300S
&& 16 <= count
&& count
<= 21))
4301 info
->remainder
= count
- 16;
4306 info
->special
= "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0";
4308 info
->shift1
= "add.w\t%e0,%e0";
4310 case SHIFT_LSHIFTRT
:
4313 info
->special
= "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0";
4314 info
->shift1
= "shlr\t%x0\n\trotxr\t%w0";
4318 info
->special
= "mov.w\t%e0,%f0\n\textu.l\t%S0";
4319 info
->cc_special
= CC_SET_ZNV
;
4322 case SHIFT_ASHIFTRT
:
4325 info
->special
= "mov.w\t%e0,%f0\n\tshll\t%z0\n\tsubx\t%z0,%z0\n\tmov.b\t%z0,%y0";
4326 info
->shift1
= "shar\t%x0\n\trotxr\t%w0";
4330 info
->special
= "mov.w\t%e0,%f0\n\texts.l\t%S0";
4331 info
->cc_special
= CC_SET_ZNV
;
4336 else if (TARGET_H8300
&& 24 <= count
&& count
<= 28)
4338 info
->remainder
= count
- 24;
4343 info
->special
= "mov.b\t%w0,%z0\n\tsub.b\t%y0,%y0\n\tsub.w\t%f0,%f0";
4344 info
->shift1
= "shll.b\t%z0";
4345 info
->cc_inline
= CC_SET_ZNV
;
4347 case SHIFT_LSHIFTRT
:
4348 info
->special
= "mov.b\t%z0,%w0\n\tsub.b\t%x0,%x0\n\tsub.w\t%e0,%e0";
4349 info
->shift1
= "shlr.b\t%w0";
4350 info
->cc_inline
= CC_SET_ZNV
;
4352 case SHIFT_ASHIFTRT
:
4353 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";
4354 info
->shift1
= "shar.b\t%w0";
4355 info
->cc_inline
= CC_SET_ZNV
;
4359 else if ((TARGET_H8300H
&& count
== 24)
4360 || (TARGET_H8300S
&& 24 <= count
&& count
<= 25))
4362 info
->remainder
= count
- 24;
4367 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";
4369 case SHIFT_LSHIFTRT
:
4370 info
->special
= "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\textu.w\t%f0\n\textu.l\t%S0";
4371 info
->cc_special
= CC_SET_ZNV
;
4373 case SHIFT_ASHIFTRT
:
4374 info
->special
= "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\texts.w\t%f0\n\texts.l\t%S0";
4375 info
->cc_special
= CC_SET_ZNV
;
4379 else if (!TARGET_H8300
&& count
== 28)
4385 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";
4387 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";
4389 case SHIFT_LSHIFTRT
:
4392 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";
4393 info
->cc_special
= CC_SET_ZNV
;
4396 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t#2,%S0\n\textu.l\t%S0";
4398 case SHIFT_ASHIFTRT
:
4402 else if (!TARGET_H8300
&& count
== 29)
4408 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";
4410 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
4412 case SHIFT_LSHIFTRT
:
4415 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";
4416 info
->cc_special
= CC_SET_ZNV
;
4420 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
4421 info
->cc_special
= CC_SET_ZNV
;
4424 case SHIFT_ASHIFTRT
:
4428 else if (!TARGET_H8300
&& count
== 30)
4434 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
4436 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\tsub.w\t%f0,%f0";
4438 case SHIFT_LSHIFTRT
:
4440 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
4442 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\textu.l\t%S0";
4444 case SHIFT_ASHIFTRT
:
4448 else if (count
== 31)
4455 info
->special
= "sub.w\t%e0,%e0\n\tshlr\t%w0\n\tmov.w\t%e0,%f0\n\trotxr\t%z0";
4457 case SHIFT_LSHIFTRT
:
4458 info
->special
= "sub.w\t%f0,%f0\n\tshll\t%z0\n\tmov.w\t%f0,%e0\n\trotxl\t%w0";
4460 case SHIFT_ASHIFTRT
:
4461 info
->special
= "shll\t%z0\n\tsubx\t%w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
4470 info
->special
= "shlr.l\t%S0\n\txor.l\t%S0,%S0\n\trotxr.l\t%S0";
4471 info
->cc_special
= CC_SET_ZNV
;
4473 case SHIFT_LSHIFTRT
:
4474 info
->special
= "shll.l\t%S0\n\txor.l\t%S0,%S0\n\trotxl.l\t%S0";
4475 info
->cc_special
= CC_SET_ZNV
;
4477 case SHIFT_ASHIFTRT
:
4478 info
->special
= "shll\t%e0\n\tsubx\t%w0,%w0\n\texts.w\t%T0\n\texts.l\t%S0";
4479 info
->cc_special
= CC_SET_ZNV
;
4492 info
->shift2
= NULL
;
4495 /* Given COUNT and MODE of a shift, return 1 if a scratch reg may be
4496 needed for some shift with COUNT and MODE. Return 0 otherwise. */
4499 h8300_shift_needs_scratch_p (int count
, enum machine_mode mode
)
4504 if (GET_MODE_BITSIZE (mode
) <= count
)
4507 /* Find out the target CPU. */
4510 else if (TARGET_H8300H
)
4515 /* Find the shift algorithm. */
4519 a
= shift_alg_qi
[cpu
][SHIFT_ASHIFT
][count
];
4520 lr
= shift_alg_qi
[cpu
][SHIFT_LSHIFTRT
][count
];
4521 ar
= shift_alg_qi
[cpu
][SHIFT_ASHIFTRT
][count
];
4525 a
= shift_alg_hi
[cpu
][SHIFT_ASHIFT
][count
];
4526 lr
= shift_alg_hi
[cpu
][SHIFT_LSHIFTRT
][count
];
4527 ar
= shift_alg_hi
[cpu
][SHIFT_ASHIFTRT
][count
];
4531 a
= shift_alg_si
[cpu
][SHIFT_ASHIFT
][count
];
4532 lr
= shift_alg_si
[cpu
][SHIFT_LSHIFTRT
][count
];
4533 ar
= shift_alg_si
[cpu
][SHIFT_ASHIFTRT
][count
];
4540 /* On H8/300H, count == 8 uses a scratch register. */
4541 return (a
== SHIFT_LOOP
|| lr
== SHIFT_LOOP
|| ar
== SHIFT_LOOP
4542 || (TARGET_H8300H
&& mode
== SImode
&& count
== 8));
4545 /* Output the assembler code for doing shifts. */
4548 output_a_shift (rtx
*operands
)
4550 static int loopend_lab
;
4551 rtx shift
= operands
[3];
4552 enum machine_mode mode
= GET_MODE (shift
);
4553 enum rtx_code code
= GET_CODE (shift
);
4554 enum shift_type shift_type
;
4555 enum shift_mode shift_mode
;
4556 struct shift_info info
;
4564 shift_mode
= QIshift
;
4567 shift_mode
= HIshift
;
4570 shift_mode
= SIshift
;
4579 shift_type
= SHIFT_ASHIFTRT
;
4582 shift_type
= SHIFT_LSHIFTRT
;
4585 shift_type
= SHIFT_ASHIFT
;
4591 /* This case must be taken care of by one of the two splitters
4592 that convert a variable shift into a loop. */
4593 gcc_assert (GET_CODE (operands
[2]) == CONST_INT
);
4595 n
= INTVAL (operands
[2]);
4597 /* If the count is negative, make it 0. */
4600 /* If the count is too big, truncate it.
4601 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4602 do the intuitive thing. */
4603 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4604 n
= GET_MODE_BITSIZE (mode
);
4606 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4611 output_asm_insn (info
.special
, operands
);
4617 /* Emit two bit shifts first. */
4618 if (info
.shift2
!= NULL
)
4620 for (; n
> 1; n
-= 2)
4621 output_asm_insn (info
.shift2
, operands
);
4624 /* Now emit one bit shifts for any residual. */
4626 output_asm_insn (info
.shift1
, operands
);
4631 int m
= GET_MODE_BITSIZE (mode
) - n
;
4632 const int mask
= (shift_type
== SHIFT_ASHIFT
4633 ? ((1 << m
) - 1) << n
4637 /* Not all possibilities of rotate are supported. They shouldn't
4638 be generated, but let's watch for 'em. */
4639 gcc_assert (info
.shift1
);
4641 /* Emit two bit rotates first. */
4642 if (info
.shift2
!= NULL
)
4644 for (; m
> 1; m
-= 2)
4645 output_asm_insn (info
.shift2
, operands
);
4648 /* Now single bit rotates for any residual. */
4650 output_asm_insn (info
.shift1
, operands
);
4652 /* Now mask off the high bits. */
4656 sprintf (insn_buf
, "and\t#%d,%%X0", mask
);
4660 gcc_assert (TARGET_H8300H
|| TARGET_H8300S
);
4661 sprintf (insn_buf
, "and.w\t#%d,%%T0", mask
);
4668 output_asm_insn (insn_buf
, operands
);
4673 /* A loop to shift by a "large" constant value.
4674 If we have shift-by-2 insns, use them. */
4675 if (info
.shift2
!= NULL
)
4677 fprintf (asm_out_file
, "\tmov.b #%d,%sl\n", n
/ 2,
4678 names_big
[REGNO (operands
[4])]);
4679 fprintf (asm_out_file
, ".Llt%d:\n", loopend_lab
);
4680 output_asm_insn (info
.shift2
, operands
);
4681 output_asm_insn ("add #0xff,%X4", operands
);
4682 fprintf (asm_out_file
, "\tbne .Llt%d\n", loopend_lab
);
4684 output_asm_insn (info
.shift1
, operands
);
4688 fprintf (asm_out_file
, "\tmov.b #%d,%sl\n", n
,
4689 names_big
[REGNO (operands
[4])]);
4690 fprintf (asm_out_file
, ".Llt%d:\n", loopend_lab
);
4691 output_asm_insn (info
.shift1
, operands
);
4692 output_asm_insn ("add #0xff,%X4", operands
);
4693 fprintf (asm_out_file
, "\tbne .Llt%d\n", loopend_lab
);
4702 /* Count the number of assembly instructions in a string TEMPL. */
4705 h8300_asm_insn_count (const char *templ
)
4707 unsigned int count
= 1;
4709 for (; *templ
; templ
++)
4716 /* Compute the length of a shift insn. */
4719 compute_a_shift_length (rtx insn ATTRIBUTE_UNUSED
, rtx
*operands
)
4721 rtx shift
= operands
[3];
4722 enum machine_mode mode
= GET_MODE (shift
);
4723 enum rtx_code code
= GET_CODE (shift
);
4724 enum shift_type shift_type
;
4725 enum shift_mode shift_mode
;
4726 struct shift_info info
;
4727 unsigned int wlength
= 0;
4732 shift_mode
= QIshift
;
4735 shift_mode
= HIshift
;
4738 shift_mode
= SIshift
;
4747 shift_type
= SHIFT_ASHIFTRT
;
4750 shift_type
= SHIFT_LSHIFTRT
;
4753 shift_type
= SHIFT_ASHIFT
;
4759 if (GET_CODE (operands
[2]) != CONST_INT
)
4761 /* Get the assembler code to do one shift. */
4762 get_shift_alg (shift_type
, shift_mode
, 1, &info
);
4764 return (4 + h8300_asm_insn_count (info
.shift1
)) * 2;
4768 int n
= INTVAL (operands
[2]);
4770 /* If the count is negative, make it 0. */
4773 /* If the count is too big, truncate it.
4774 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4775 do the intuitive thing. */
4776 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4777 n
= GET_MODE_BITSIZE (mode
);
4779 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4784 wlength
+= h8300_asm_insn_count (info
.special
);
4786 /* Every assembly instruction used in SHIFT_SPECIAL case
4787 takes 2 bytes except xor.l, which takes 4 bytes, so if we
4788 see xor.l, we just pretend that xor.l counts as two insns
4789 so that the insn length will be computed correctly. */
4790 if (strstr (info
.special
, "xor.l") != NULL
)
4798 if (info
.shift2
!= NULL
)
4800 wlength
+= h8300_asm_insn_count (info
.shift2
) * (n
/ 2);
4804 wlength
+= h8300_asm_insn_count (info
.shift1
) * n
;
4810 int m
= GET_MODE_BITSIZE (mode
) - n
;
4812 /* Not all possibilities of rotate are supported. They shouldn't
4813 be generated, but let's watch for 'em. */
4814 gcc_assert (info
.shift1
);
4816 if (info
.shift2
!= NULL
)
4818 wlength
+= h8300_asm_insn_count (info
.shift2
) * (m
/ 2);
4822 wlength
+= h8300_asm_insn_count (info
.shift1
) * m
;
4824 /* Now mask off the high bits. */
4834 gcc_assert (!TARGET_H8300
);
4844 /* A loop to shift by a "large" constant value.
4845 If we have shift-by-2 insns, use them. */
4846 if (info
.shift2
!= NULL
)
4848 wlength
+= 3 + h8300_asm_insn_count (info
.shift2
);
4850 wlength
+= h8300_asm_insn_count (info
.shift1
);
4854 wlength
+= 3 + h8300_asm_insn_count (info
.shift1
);
4864 /* Compute which flag bits are valid after a shift insn. */
4867 compute_a_shift_cc (rtx insn ATTRIBUTE_UNUSED
, rtx
*operands
)
4869 rtx shift
= operands
[3];
4870 enum machine_mode mode
= GET_MODE (shift
);
4871 enum rtx_code code
= GET_CODE (shift
);
4872 enum shift_type shift_type
;
4873 enum shift_mode shift_mode
;
4874 struct shift_info info
;
4880 shift_mode
= QIshift
;
4883 shift_mode
= HIshift
;
4886 shift_mode
= SIshift
;
4895 shift_type
= SHIFT_ASHIFTRT
;
4898 shift_type
= SHIFT_LSHIFTRT
;
4901 shift_type
= SHIFT_ASHIFT
;
4907 /* This case must be taken care of by one of the two splitters
4908 that convert a variable shift into a loop. */
4909 gcc_assert (GET_CODE (operands
[2]) == CONST_INT
);
4911 n
= INTVAL (operands
[2]);
4913 /* If the count is negative, make it 0. */
4916 /* If the count is too big, truncate it.
4917 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4918 do the intuitive thing. */
4919 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4920 n
= GET_MODE_BITSIZE (mode
);
4922 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4927 if (info
.remainder
== 0)
4928 return info
.cc_special
;
4933 return info
.cc_inline
;
4936 /* This case always ends with an and instruction. */
4940 /* A loop to shift by a "large" constant value.
4941 If we have shift-by-2 insns, use them. */
4942 if (info
.shift2
!= NULL
)
4945 return info
.cc_inline
;
4954 /* A rotation by a non-constant will cause a loop to be generated, in
4955 which a rotation by one bit is used. A rotation by a constant,
4956 including the one in the loop, will be taken care of by
4957 output_a_rotate () at the insn emit time. */
4960 expand_a_rotate (rtx operands
[])
4962 rtx dst
= operands
[0];
4963 rtx src
= operands
[1];
4964 rtx rotate_amount
= operands
[2];
4965 enum machine_mode mode
= GET_MODE (dst
);
4967 if (h8sx_classify_shift (mode
, ROTATE
, rotate_amount
) == H8SX_SHIFT_UNARY
)
4970 /* We rotate in place. */
4971 emit_move_insn (dst
, src
);
4973 if (GET_CODE (rotate_amount
) != CONST_INT
)
4975 rtx counter
= gen_reg_rtx (QImode
);
4976 rtx start_label
= gen_label_rtx ();
4977 rtx end_label
= gen_label_rtx ();
4979 /* If the rotate amount is less than or equal to 0,
4980 we go out of the loop. */
4981 emit_cmp_and_jump_insns (rotate_amount
, const0_rtx
, LE
, NULL_RTX
,
4982 QImode
, 0, end_label
);
4984 /* Initialize the loop counter. */
4985 emit_move_insn (counter
, rotate_amount
);
4987 emit_label (start_label
);
4989 /* Rotate by one bit. */
4993 emit_insn (gen_rotlqi3_1 (dst
, dst
, const1_rtx
));
4996 emit_insn (gen_rotlhi3_1 (dst
, dst
, const1_rtx
));
4999 emit_insn (gen_rotlsi3_1 (dst
, dst
, const1_rtx
));
5005 /* Decrement the counter by 1. */
5006 emit_insn (gen_addqi3 (counter
, counter
, constm1_rtx
));
5008 /* If the loop counter is nonzero, we go back to the beginning
5010 emit_cmp_and_jump_insns (counter
, const0_rtx
, NE
, NULL_RTX
, QImode
, 1,
5013 emit_label (end_label
);
5017 /* Rotate by AMOUNT bits. */
5021 emit_insn (gen_rotlqi3_1 (dst
, dst
, rotate_amount
));
5024 emit_insn (gen_rotlhi3_1 (dst
, dst
, rotate_amount
));
5027 emit_insn (gen_rotlsi3_1 (dst
, dst
, rotate_amount
));
5037 /* Output a rotate insn. */
5040 output_a_rotate (enum rtx_code code
, rtx
*operands
)
5042 rtx dst
= operands
[0];
5043 rtx rotate_amount
= operands
[2];
5044 enum shift_mode rotate_mode
;
5045 enum shift_type rotate_type
;
5046 const char *insn_buf
;
5049 enum machine_mode mode
= GET_MODE (dst
);
5051 gcc_assert (GET_CODE (rotate_amount
) == CONST_INT
);
5056 rotate_mode
= QIshift
;
5059 rotate_mode
= HIshift
;
5062 rotate_mode
= SIshift
;
5071 rotate_type
= SHIFT_ASHIFT
;
5074 rotate_type
= SHIFT_LSHIFTRT
;
5080 amount
= INTVAL (rotate_amount
);
5082 /* Clean up AMOUNT. */
5085 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
))
5086 amount
= GET_MODE_BITSIZE (mode
);
5088 /* Determine the faster direction. After this phase, amount will be
5089 at most a half of GET_MODE_BITSIZE (mode). */
5090 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
) / (unsigned) 2)
5092 /* Flip the direction. */
5093 amount
= GET_MODE_BITSIZE (mode
) - amount
;
5095 (rotate_type
== SHIFT_ASHIFT
) ? SHIFT_LSHIFTRT
: SHIFT_ASHIFT
;
5098 /* See if a byte swap (in HImode) or a word swap (in SImode) can
5099 boost up the rotation. */
5100 if ((mode
== HImode
&& TARGET_H8300
&& amount
>= 5)
5101 || (mode
== HImode
&& TARGET_H8300H
&& amount
>= 6)
5102 || (mode
== HImode
&& TARGET_H8300S
&& amount
== 8)
5103 || (mode
== SImode
&& TARGET_H8300H
&& amount
>= 10)
5104 || (mode
== SImode
&& TARGET_H8300S
&& amount
>= 13))
5109 /* This code works on any family. */
5110 insn_buf
= "xor.b\t%s0,%t0\n\txor.b\t%t0,%s0\n\txor.b\t%s0,%t0";
5111 output_asm_insn (insn_buf
, operands
);
5115 /* This code works on the H8/300H and H8S. */
5116 insn_buf
= "xor.w\t%e0,%f0\n\txor.w\t%f0,%e0\n\txor.w\t%e0,%f0";
5117 output_asm_insn (insn_buf
, operands
);
5124 /* Adjust AMOUNT and flip the direction. */
5125 amount
= GET_MODE_BITSIZE (mode
) / 2 - amount
;
5127 (rotate_type
== SHIFT_ASHIFT
) ? SHIFT_LSHIFTRT
: SHIFT_ASHIFT
;
5130 /* Output rotate insns. */
5131 for (bits
= TARGET_H8300S
? 2 : 1; bits
> 0; bits
/= 2)
5134 insn_buf
= rotate_two
[rotate_type
][rotate_mode
];
5136 insn_buf
= rotate_one
[cpu_type
][rotate_type
][rotate_mode
];
5138 for (; amount
>= bits
; amount
-= bits
)
5139 output_asm_insn (insn_buf
, operands
);
5145 /* Compute the length of a rotate insn. */
5148 compute_a_rotate_length (rtx
*operands
)
5150 rtx src
= operands
[1];
5151 rtx amount_rtx
= operands
[2];
5152 enum machine_mode mode
= GET_MODE (src
);
5154 unsigned int length
= 0;
5156 gcc_assert (GET_CODE (amount_rtx
) == CONST_INT
);
5158 amount
= INTVAL (amount_rtx
);
5160 /* Clean up AMOUNT. */
5163 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
))
5164 amount
= GET_MODE_BITSIZE (mode
);
5166 /* Determine the faster direction. After this phase, amount
5167 will be at most a half of GET_MODE_BITSIZE (mode). */
5168 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
) / (unsigned) 2)
5169 /* Flip the direction. */
5170 amount
= GET_MODE_BITSIZE (mode
) - amount
;
5172 /* See if a byte swap (in HImode) or a word swap (in SImode) can
5173 boost up the rotation. */
5174 if ((mode
== HImode
&& TARGET_H8300
&& amount
>= 5)
5175 || (mode
== HImode
&& TARGET_H8300H
&& amount
>= 6)
5176 || (mode
== HImode
&& TARGET_H8300S
&& amount
== 8)
5177 || (mode
== SImode
&& TARGET_H8300H
&& amount
>= 10)
5178 || (mode
== SImode
&& TARGET_H8300S
&& amount
>= 13))
5180 /* Adjust AMOUNT and flip the direction. */
5181 amount
= GET_MODE_BITSIZE (mode
) / 2 - amount
;
5185 /* We use 2-bit rotations on the H8S. */
5187 amount
= amount
/ 2 + amount
% 2;
5189 /* The H8/300 uses three insns to rotate one bit, taking 6
5191 length
+= amount
* ((TARGET_H8300
&& mode
== HImode
) ? 6 : 2);
5196 /* Fix the operands of a gen_xxx so that it could become a bit
5200 fix_bit_operand (rtx
*operands
, enum rtx_code code
)
5202 /* The bit_operand predicate accepts any memory during RTL generation, but
5203 only 'U' memory afterwards, so if this is a MEM operand, we must force
5204 it to be valid for 'U' by reloading the address. */
5207 ? single_zero_operand (operands
[2], QImode
)
5208 : single_one_operand (operands
[2], QImode
))
5210 /* OK to have a memory dest. */
5211 if (GET_CODE (operands
[0]) == MEM
5212 && !satisfies_constraint_U (operands
[0]))
5214 rtx mem
= gen_rtx_MEM (GET_MODE (operands
[0]),
5215 copy_to_mode_reg (Pmode
,
5216 XEXP (operands
[0], 0)));
5217 MEM_COPY_ATTRIBUTES (mem
, operands
[0]);
5221 if (GET_CODE (operands
[1]) == MEM
5222 && !satisfies_constraint_U (operands
[1]))
5224 rtx mem
= gen_rtx_MEM (GET_MODE (operands
[1]),
5225 copy_to_mode_reg (Pmode
,
5226 XEXP (operands
[1], 0)));
5227 MEM_COPY_ATTRIBUTES (mem
, operands
[0]);
5233 /* Dest and src op must be register. */
5235 operands
[1] = force_reg (QImode
, operands
[1]);
5237 rtx res
= gen_reg_rtx (QImode
);
5241 emit_insn (gen_andqi3_1 (res
, operands
[1], operands
[2]));
5244 emit_insn (gen_iorqi3_1 (res
, operands
[1], operands
[2]));
5247 emit_insn (gen_xorqi3_1 (res
, operands
[1], operands
[2]));
5252 emit_insn (gen_movqi (operands
[0], res
));
5257 /* Return nonzero if FUNC is an interrupt function as specified
5258 by the "interrupt" attribute. */
5261 h8300_interrupt_function_p (tree func
)
5265 if (TREE_CODE (func
) != FUNCTION_DECL
)
5268 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
5269 return a
!= NULL_TREE
;
5272 /* Return nonzero if FUNC is a saveall function as specified by the
5273 "saveall" attribute. */
5276 h8300_saveall_function_p (tree func
)
5280 if (TREE_CODE (func
) != FUNCTION_DECL
)
5283 a
= lookup_attribute ("saveall", DECL_ATTRIBUTES (func
));
5284 return a
!= NULL_TREE
;
5287 /* Return nonzero if FUNC is an OS_Task function as specified
5288 by the "OS_Task" attribute. */
5291 h8300_os_task_function_p (tree func
)
5295 if (TREE_CODE (func
) != FUNCTION_DECL
)
5298 a
= lookup_attribute ("OS_Task", DECL_ATTRIBUTES (func
));
5299 return a
!= NULL_TREE
;
5302 /* Return nonzero if FUNC is a monitor function as specified
5303 by the "monitor" attribute. */
5306 h8300_monitor_function_p (tree func
)
5310 if (TREE_CODE (func
) != FUNCTION_DECL
)
5313 a
= lookup_attribute ("monitor", DECL_ATTRIBUTES (func
));
5314 return a
!= NULL_TREE
;
5317 /* Return nonzero if FUNC is a function that should be called
5318 through the function vector. */
5321 h8300_funcvec_function_p (tree func
)
5325 if (TREE_CODE (func
) != FUNCTION_DECL
)
5328 a
= lookup_attribute ("function_vector", DECL_ATTRIBUTES (func
));
5329 return a
!= NULL_TREE
;
5332 /* Return nonzero if DECL is a variable that's in the eight bit
5336 h8300_eightbit_data_p (tree decl
)
5340 if (TREE_CODE (decl
) != VAR_DECL
)
5343 a
= lookup_attribute ("eightbit_data", DECL_ATTRIBUTES (decl
));
5344 return a
!= NULL_TREE
;
5347 /* Return nonzero if DECL is a variable that's in the tiny
5351 h8300_tiny_data_p (tree decl
)
5355 if (TREE_CODE (decl
) != VAR_DECL
)
5358 a
= lookup_attribute ("tiny_data", DECL_ATTRIBUTES (decl
));
5359 return a
!= NULL_TREE
;
5362 /* Generate an 'interrupt_handler' attribute for decls. We convert
5363 all the pragmas to corresponding attributes. */
5366 h8300_insert_attributes (tree node
, tree
*attributes
)
5368 if (TREE_CODE (node
) == FUNCTION_DECL
)
5370 if (pragma_interrupt
)
5372 pragma_interrupt
= 0;
5374 /* Add an 'interrupt_handler' attribute. */
5375 *attributes
= tree_cons (get_identifier ("interrupt_handler"),
5383 /* Add an 'saveall' attribute. */
5384 *attributes
= tree_cons (get_identifier ("saveall"),
5390 /* Supported attributes:
5392 interrupt_handler: output a prologue and epilogue suitable for an
5395 saveall: output a prologue and epilogue that saves and restores
5396 all registers except the stack pointer.
5398 function_vector: This function should be called through the
5401 eightbit_data: This variable lives in the 8-bit data area and can
5402 be referenced with 8-bit absolute memory addresses.
5404 tiny_data: This variable lives in the tiny data area and can be
5405 referenced with 16-bit absolute memory references. */
5407 static const struct attribute_spec h8300_attribute_table
[] =
5409 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
5410 affects_type_identity } */
5411 { "interrupt_handler", 0, 0, true, false, false,
5412 h8300_handle_fndecl_attribute
, false },
5413 { "saveall", 0, 0, true, false, false,
5414 h8300_handle_fndecl_attribute
, false },
5415 { "OS_Task", 0, 0, true, false, false,
5416 h8300_handle_fndecl_attribute
, false },
5417 { "monitor", 0, 0, true, false, false,
5418 h8300_handle_fndecl_attribute
, false },
5419 { "function_vector", 0, 0, true, false, false,
5420 h8300_handle_fndecl_attribute
, false },
5421 { "eightbit_data", 0, 0, true, false, false,
5422 h8300_handle_eightbit_data_attribute
, false },
5423 { "tiny_data", 0, 0, true, false, false,
5424 h8300_handle_tiny_data_attribute
, false },
5425 { NULL
, 0, 0, false, false, false, NULL
, false }
5429 /* Handle an attribute requiring a FUNCTION_DECL; arguments as in
5430 struct attribute_spec.handler. */
5432 h8300_handle_fndecl_attribute (tree
*node
, tree name
,
5433 tree args ATTRIBUTE_UNUSED
,
5434 int flags ATTRIBUTE_UNUSED
,
5437 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5439 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
5441 *no_add_attrs
= true;
5447 /* Handle an "eightbit_data" attribute; arguments as in
5448 struct attribute_spec.handler. */
5450 h8300_handle_eightbit_data_attribute (tree
*node
, tree name
,
5451 tree args ATTRIBUTE_UNUSED
,
5452 int flags ATTRIBUTE_UNUSED
,
5457 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
5459 DECL_SECTION_NAME (decl
) = build_string (7, ".eight");
5463 warning (OPT_Wattributes
, "%qE attribute ignored",
5465 *no_add_attrs
= true;
5471 /* Handle an "tiny_data" attribute; arguments as in
5472 struct attribute_spec.handler. */
5474 h8300_handle_tiny_data_attribute (tree
*node
, tree name
,
5475 tree args ATTRIBUTE_UNUSED
,
5476 int flags ATTRIBUTE_UNUSED
,
5481 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
5483 DECL_SECTION_NAME (decl
) = build_string (6, ".tiny");
5487 warning (OPT_Wattributes
, "%qE attribute ignored",
5489 *no_add_attrs
= true;
5495 /* Mark function vectors, and various small data objects. */
5498 h8300_encode_section_info (tree decl
, rtx rtl
, int first
)
5500 int extra_flags
= 0;
5502 default_encode_section_info (decl
, rtl
, first
);
5504 if (TREE_CODE (decl
) == FUNCTION_DECL
5505 && h8300_funcvec_function_p (decl
))
5506 extra_flags
= SYMBOL_FLAG_FUNCVEC_FUNCTION
;
5507 else if (TREE_CODE (decl
) == VAR_DECL
5508 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
5510 if (h8300_eightbit_data_p (decl
))
5511 extra_flags
= SYMBOL_FLAG_EIGHTBIT_DATA
;
5512 else if (first
&& h8300_tiny_data_p (decl
))
5513 extra_flags
= SYMBOL_FLAG_TINY_DATA
;
5517 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= extra_flags
;
5520 /* Output a single-bit extraction. */
5523 output_simode_bld (int bild
, rtx operands
[])
5527 /* Clear the destination register. */
5528 output_asm_insn ("sub.w\t%e0,%e0\n\tsub.w\t%f0,%f0", operands
);
5530 /* Now output the bit load or bit inverse load, and store it in
5533 output_asm_insn ("bild\t%Z2,%Y1", operands
);
5535 output_asm_insn ("bld\t%Z2,%Y1", operands
);
5537 output_asm_insn ("bst\t#0,%w0", operands
);
5541 /* Determine if we can clear the destination first. */
5542 int clear_first
= (REG_P (operands
[0]) && REG_P (operands
[1])
5543 && REGNO (operands
[0]) != REGNO (operands
[1]));
5546 output_asm_insn ("sub.l\t%S0,%S0", operands
);
5548 /* Output the bit load or bit inverse load. */
5550 output_asm_insn ("bild\t%Z2,%Y1", operands
);
5552 output_asm_insn ("bld\t%Z2,%Y1", operands
);
5555 output_asm_insn ("xor.l\t%S0,%S0", operands
);
5557 /* Perform the bit store. */
5558 output_asm_insn ("rotxl.l\t%S0", operands
);
5565 /* Delayed-branch scheduling is more effective if we have some idea
5566 how long each instruction will be. Use a shorten_branches pass
5567 to get an initial estimate. */
5572 if (flag_delayed_branch
)
5573 shorten_branches (get_insns ());
5576 #ifndef OBJECT_FORMAT_ELF
5578 h8300_asm_named_section (const char *name
, unsigned int flags ATTRIBUTE_UNUSED
,
5581 /* ??? Perhaps we should be using default_coff_asm_named_section. */
5582 fprintf (asm_out_file
, "\t.section %s\n", name
);
5584 #endif /* ! OBJECT_FORMAT_ELF */
5586 /* Nonzero if X is a constant address suitable as an 8-bit absolute,
5587 which is a special case of the 'R' operand. */
5590 h8300_eightbit_constant_address_p (rtx x
)
5592 /* The ranges of the 8-bit area. */
5593 const unsigned HOST_WIDE_INT n1
= trunc_int_for_mode (0xff00, HImode
);
5594 const unsigned HOST_WIDE_INT n2
= trunc_int_for_mode (0xffff, HImode
);
5595 const unsigned HOST_WIDE_INT h1
= trunc_int_for_mode (0x00ffff00, SImode
);
5596 const unsigned HOST_WIDE_INT h2
= trunc_int_for_mode (0x00ffffff, SImode
);
5597 const unsigned HOST_WIDE_INT s1
= trunc_int_for_mode (0xffffff00, SImode
);
5598 const unsigned HOST_WIDE_INT s2
= trunc_int_for_mode (0xffffffff, SImode
);
5600 unsigned HOST_WIDE_INT addr
;
5602 /* We accept symbols declared with eightbit_data. */
5603 if (GET_CODE (x
) == SYMBOL_REF
)
5604 return (SYMBOL_REF_FLAGS (x
) & SYMBOL_FLAG_EIGHTBIT_DATA
) != 0;
5606 if (GET_CODE (x
) != CONST_INT
)
5612 || ((TARGET_H8300
|| TARGET_NORMAL_MODE
) && IN_RANGE (addr
, n1
, n2
))
5613 || (TARGET_H8300H
&& IN_RANGE (addr
, h1
, h2
))
5614 || (TARGET_H8300S
&& IN_RANGE (addr
, s1
, s2
)));
5617 /* Nonzero if X is a constant address suitable as an 16-bit absolute
5618 on H8/300H and H8S. */
5621 h8300_tiny_constant_address_p (rtx x
)
5623 /* The ranges of the 16-bit area. */
5624 const unsigned HOST_WIDE_INT h1
= trunc_int_for_mode (0x00000000, SImode
);
5625 const unsigned HOST_WIDE_INT h2
= trunc_int_for_mode (0x00007fff, SImode
);
5626 const unsigned HOST_WIDE_INT h3
= trunc_int_for_mode (0x00ff8000, SImode
);
5627 const unsigned HOST_WIDE_INT h4
= trunc_int_for_mode (0x00ffffff, SImode
);
5628 const unsigned HOST_WIDE_INT s1
= trunc_int_for_mode (0x00000000, SImode
);
5629 const unsigned HOST_WIDE_INT s2
= trunc_int_for_mode (0x00007fff, SImode
);
5630 const unsigned HOST_WIDE_INT s3
= trunc_int_for_mode (0xffff8000, SImode
);
5631 const unsigned HOST_WIDE_INT s4
= trunc_int_for_mode (0xffffffff, SImode
);
5633 unsigned HOST_WIDE_INT addr
;
5635 switch (GET_CODE (x
))
5638 /* In the normal mode, any symbol fits in the 16-bit absolute
5639 address range. We also accept symbols declared with
5641 return (TARGET_NORMAL_MODE
5642 || (SYMBOL_REF_FLAGS (x
) & SYMBOL_FLAG_TINY_DATA
) != 0);
5646 return (TARGET_NORMAL_MODE
5648 && (IN_RANGE (addr
, h1
, h2
) || IN_RANGE (addr
, h3
, h4
)))
5650 && (IN_RANGE (addr
, s1
, s2
) || IN_RANGE (addr
, s3
, s4
))));
5653 return TARGET_NORMAL_MODE
;
5661 /* Return nonzero if ADDR1 and ADDR2 point to consecutive memory
5662 locations that can be accessed as a 16-bit word. */
5665 byte_accesses_mergeable_p (rtx addr1
, rtx addr2
)
5667 HOST_WIDE_INT offset1
, offset2
;
5675 else if (GET_CODE (addr1
) == PLUS
5676 && REG_P (XEXP (addr1
, 0))
5677 && GET_CODE (XEXP (addr1
, 1)) == CONST_INT
)
5679 reg1
= XEXP (addr1
, 0);
5680 offset1
= INTVAL (XEXP (addr1
, 1));
5690 else if (GET_CODE (addr2
) == PLUS
5691 && REG_P (XEXP (addr2
, 0))
5692 && GET_CODE (XEXP (addr2
, 1)) == CONST_INT
)
5694 reg2
= XEXP (addr2
, 0);
5695 offset2
= INTVAL (XEXP (addr2
, 1));
5700 if (((reg1
== stack_pointer_rtx
&& reg2
== stack_pointer_rtx
)
5701 || (reg1
== frame_pointer_rtx
&& reg2
== frame_pointer_rtx
))
5703 && offset1
+ 1 == offset2
)
5709 /* Return nonzero if we have the same comparison insn as I3 two insns
5710 before I3. I3 is assumed to be a comparison insn. */
5713 same_cmp_preceding_p (rtx i3
)
5717 /* Make sure we have a sequence of three insns. */
5718 i2
= prev_nonnote_insn (i3
);
5721 i1
= prev_nonnote_insn (i2
);
5725 return (INSN_P (i1
) && rtx_equal_p (PATTERN (i1
), PATTERN (i3
))
5726 && any_condjump_p (i2
) && onlyjump_p (i2
));
5729 /* Return nonzero if we have the same comparison insn as I1 two insns
5730 after I1. I1 is assumed to be a comparison insn. */
5733 same_cmp_following_p (rtx i1
)
5737 /* Make sure we have a sequence of three insns. */
5738 i2
= next_nonnote_insn (i1
);
5741 i3
= next_nonnote_insn (i2
);
5745 return (INSN_P (i3
) && rtx_equal_p (PATTERN (i1
), PATTERN (i3
))
5746 && any_condjump_p (i2
) && onlyjump_p (i2
));
5749 /* Return nonzero if OPERANDS are valid for stm (or ldm) that pushes
5750 (or pops) N registers. OPERANDS are assumed to be an array of
5754 h8300_regs_ok_for_stm (int n
, rtx operands
[])
5759 return ((REGNO (operands
[0]) == 0 && REGNO (operands
[1]) == 1)
5760 || (REGNO (operands
[0]) == 2 && REGNO (operands
[1]) == 3)
5761 || (REGNO (operands
[0]) == 4 && REGNO (operands
[1]) == 5));
5763 return ((REGNO (operands
[0]) == 0
5764 && REGNO (operands
[1]) == 1
5765 && REGNO (operands
[2]) == 2)
5766 || (REGNO (operands
[0]) == 4
5767 && REGNO (operands
[1]) == 5
5768 && REGNO (operands
[2]) == 6));
5771 return (REGNO (operands
[0]) == 0
5772 && REGNO (operands
[1]) == 1
5773 && REGNO (operands
[2]) == 2
5774 && REGNO (operands
[3]) == 3);
5780 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
5783 h8300_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED
,
5784 unsigned int new_reg
)
5786 /* Interrupt functions can only use registers that have already been
5787 saved by the prologue, even if they would normally be
5790 if (h8300_current_function_interrupt_function_p ()
5791 && !df_regs_ever_live_p (new_reg
))
5797 /* Returns true if register REGNO is safe to be allocated as a scratch
5798 register in the current function. */
5801 h8300_hard_regno_scratch_ok (unsigned int regno
)
5803 if (h8300_current_function_interrupt_function_p ()
5804 && ! WORD_REG_USED (regno
))
5811 /* Return nonzero if X is a REG or SUBREG suitable as a base register. */
5814 h8300_rtx_ok_for_base_p (rtx x
, int strict
)
5816 /* Strip off SUBREG if any. */
5817 if (GET_CODE (x
) == SUBREG
)
5822 ? REG_OK_FOR_BASE_STRICT_P (x
)
5823 : REG_OK_FOR_BASE_NONSTRICT_P (x
)));
5826 /* Return nozero if X is a legitimate address. On the H8/300, a
5827 legitimate address has the form REG, REG+CONSTANT_ADDRESS or
5828 CONSTANT_ADDRESS. */
5831 h8300_legitimate_address_p (enum machine_mode mode
, rtx x
, bool strict
)
5833 /* The register indirect addresses like @er0 is always valid. */
5834 if (h8300_rtx_ok_for_base_p (x
, strict
))
5837 if (CONSTANT_ADDRESS_P (x
))
5841 && ( GET_CODE (x
) == PRE_INC
5842 || GET_CODE (x
) == PRE_DEC
5843 || GET_CODE (x
) == POST_INC
5844 || GET_CODE (x
) == POST_DEC
)
5845 && h8300_rtx_ok_for_base_p (XEXP (x
, 0), strict
))
5848 if (GET_CODE (x
) == PLUS
5849 && CONSTANT_ADDRESS_P (XEXP (x
, 1))
5850 && h8300_rtx_ok_for_base_p (h8300_get_index (XEXP (x
, 0),
5857 /* Worker function for HARD_REGNO_NREGS.
5859 We pretend the MAC register is 32bits -- we don't have any data
5860 types on the H8 series to handle more than 32bits. */
5863 h8300_hard_regno_nregs (int regno ATTRIBUTE_UNUSED
, enum machine_mode mode
)
5865 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
5868 /* Worker function for HARD_REGNO_MODE_OK. */
5871 h8300_hard_regno_mode_ok (int regno
, enum machine_mode mode
)
5874 /* If an even reg, then anything goes. Otherwise the mode must be
5876 return ((regno
& 1) == 0) || (mode
== HImode
) || (mode
== QImode
);
5878 /* MAC register can only be of SImode. Otherwise, anything
5880 return regno
== MAC_REG
? mode
== SImode
: 1;
5883 /* Helper function for the move patterns. Make sure a move is legitimate. */
5886 h8300_move_ok (rtx dest
, rtx src
)
5890 /* Validate that at least one operand is a register. */
5893 if (MEM_P (src
) || CONSTANT_P (src
))
5895 addr
= XEXP (dest
, 0);
5898 else if (MEM_P (src
))
5900 addr
= XEXP (src
, 0);
5906 /* Validate that auto-inc doesn't affect OTHER. */
5907 if (GET_RTX_CLASS (GET_CODE (addr
)) != RTX_AUTOINC
)
5909 addr
= XEXP (addr
, 0);
5911 if (addr
== stack_pointer_rtx
)
5912 return register_no_sp_elim_operand (other
, VOIDmode
);
5914 return !reg_overlap_mentioned_p(other
, addr
);
5917 /* Perform target dependent optabs initialization. */
5919 h8300_init_libfuncs (void)
5921 set_optab_libfunc (smul_optab
, HImode
, "__mulhi3");
5922 set_optab_libfunc (sdiv_optab
, HImode
, "__divhi3");
5923 set_optab_libfunc (udiv_optab
, HImode
, "__udivhi3");
5924 set_optab_libfunc (smod_optab
, HImode
, "__modhi3");
5925 set_optab_libfunc (umod_optab
, HImode
, "__umodhi3");
5928 /* Worker function for TARGET_FUNCTION_VALUE.
5930 On the H8 the return value is in R0/R1. */
5933 h8300_function_value (const_tree ret_type
,
5934 const_tree fn_decl_or_type ATTRIBUTE_UNUSED
,
5935 bool outgoing ATTRIBUTE_UNUSED
)
5937 return gen_rtx_REG (TYPE_MODE (ret_type
), R0_REG
);
5940 /* Worker function for TARGET_LIBCALL_VALUE.
5942 On the H8 the return value is in R0/R1. */
5945 h8300_libcall_value (enum machine_mode mode
, const_rtx fun ATTRIBUTE_UNUSED
)
5947 return gen_rtx_REG (mode
, R0_REG
);
5950 /* Worker function for TARGET_FUNCTION_VALUE_REGNO_P.
5952 On the H8, R0 is the only register thus used. */
5955 h8300_function_value_regno_p (const unsigned int regno
)
5957 return (regno
== R0_REG
);
5960 /* Worker function for TARGET_RETURN_IN_MEMORY. */
5963 h8300_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
5965 return (TYPE_MODE (type
) == BLKmode
5966 || GET_MODE_SIZE (TYPE_MODE (type
)) > (TARGET_H8300
? 4 : 8));
5969 /* We emit the entire trampoline here. Depending on the pointer size,
5970 we use a different trampoline.
5974 1 0000 7903xxxx mov.w #0x1234,r3
5975 2 0004 5A00xxxx jmp @0x1234
5980 2 0000 7A03xxxxxxxx mov.l #0x12345678,er3
5981 3 0006 5Axxxxxx jmp @0x123456
5986 h8300_trampoline_init (rtx m_tramp
, tree fndecl
, rtx cxt
)
5988 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
5991 if (Pmode
== HImode
)
5993 mem
= adjust_address (m_tramp
, HImode
, 0);
5994 emit_move_insn (mem
, GEN_INT (0x7903));
5995 mem
= adjust_address (m_tramp
, Pmode
, 2);
5996 emit_move_insn (mem
, cxt
);
5997 mem
= adjust_address (m_tramp
, HImode
, 4);
5998 emit_move_insn (mem
, GEN_INT (0x5a00));
5999 mem
= adjust_address (m_tramp
, Pmode
, 6);
6000 emit_move_insn (mem
, fnaddr
);
6006 mem
= adjust_address (m_tramp
, HImode
, 0);
6007 emit_move_insn (mem
, GEN_INT (0x7a03));
6008 mem
= adjust_address (m_tramp
, Pmode
, 2);
6009 emit_move_insn (mem
, cxt
);
6011 tem
= copy_to_reg (fnaddr
);
6012 emit_insn (gen_andsi3 (tem
, tem
, GEN_INT (0x00ffffff)));
6013 emit_insn (gen_iorsi3 (tem
, tem
, GEN_INT (0x5a000000)));
6014 mem
= adjust_address (m_tramp
, SImode
, 6);
6015 emit_move_insn (mem
, tem
);
6019 /* Initialize the GCC target structure. */
6020 #undef TARGET_ATTRIBUTE_TABLE
6021 #define TARGET_ATTRIBUTE_TABLE h8300_attribute_table
6023 #undef TARGET_ASM_ALIGNED_HI_OP
6024 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
6026 #undef TARGET_ASM_FILE_START
6027 #define TARGET_ASM_FILE_START h8300_file_start
6028 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
6029 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
6031 #undef TARGET_ASM_FILE_END
6032 #define TARGET_ASM_FILE_END h8300_file_end
6034 #undef TARGET_PRINT_OPERAND
6035 #define TARGET_PRINT_OPERAND h8300_print_operand
6036 #undef TARGET_PRINT_OPERAND_ADDRESS
6037 #define TARGET_PRINT_OPERAND_ADDRESS h8300_print_operand_address
6038 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
6039 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P h8300_print_operand_punct_valid_p
6041 #undef TARGET_ENCODE_SECTION_INFO
6042 #define TARGET_ENCODE_SECTION_INFO h8300_encode_section_info
6044 #undef TARGET_INSERT_ATTRIBUTES
6045 #define TARGET_INSERT_ATTRIBUTES h8300_insert_attributes
6047 #undef TARGET_REGISTER_MOVE_COST
6048 #define TARGET_REGISTER_MOVE_COST h8300_register_move_cost
6050 #undef TARGET_RTX_COSTS
6051 #define TARGET_RTX_COSTS h8300_rtx_costs
6053 #undef TARGET_INIT_LIBFUNCS
6054 #define TARGET_INIT_LIBFUNCS h8300_init_libfuncs
6056 #undef TARGET_FUNCTION_VALUE
6057 #define TARGET_FUNCTION_VALUE h8300_function_value
6059 #undef TARGET_LIBCALL_VALUE
6060 #define TARGET_LIBCALL_VALUE h8300_libcall_value
6062 #undef TARGET_FUNCTION_VALUE_REGNO_P
6063 #define TARGET_FUNCTION_VALUE_REGNO_P h8300_function_value_regno_p
6065 #undef TARGET_RETURN_IN_MEMORY
6066 #define TARGET_RETURN_IN_MEMORY h8300_return_in_memory
6068 #undef TARGET_FUNCTION_ARG
6069 #define TARGET_FUNCTION_ARG h8300_function_arg
6071 #undef TARGET_FUNCTION_ARG_ADVANCE
6072 #define TARGET_FUNCTION_ARG_ADVANCE h8300_function_arg_advance
6074 #undef TARGET_MACHINE_DEPENDENT_REORG
6075 #define TARGET_MACHINE_DEPENDENT_REORG h8300_reorg
6077 #undef TARGET_HARD_REGNO_SCRATCH_OK
6078 #define TARGET_HARD_REGNO_SCRATCH_OK h8300_hard_regno_scratch_ok
6080 #undef TARGET_LEGITIMATE_ADDRESS_P
6081 #define TARGET_LEGITIMATE_ADDRESS_P h8300_legitimate_address_p
6083 #undef TARGET_CAN_ELIMINATE
6084 #define TARGET_CAN_ELIMINATE h8300_can_eliminate
6086 #undef TARGET_CONDITIONAL_REGISTER_USAGE
6087 #define TARGET_CONDITIONAL_REGISTER_USAGE h8300_conditional_register_usage
6089 #undef TARGET_TRAMPOLINE_INIT
6090 #define TARGET_TRAMPOLINE_INIT h8300_trampoline_init
6092 #undef TARGET_OPTION_OVERRIDE
6093 #define TARGET_OPTION_OVERRIDE h8300_option_override
6095 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
6096 #define TARGET_MODE_DEPENDENT_ADDRESS_P h8300_mode_dependent_address_p
6098 struct gcc_target targetm
= TARGET_INITIALIZER
;