1 /* Subroutines for insn-output.c for Renesas H8/300.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Steve Chamberlain (sac@cygnus.com),
6 Jim Wilson (wilson@cygnus.com), and Doug Evans (dje@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
26 #include "coretypes.h"
31 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
35 #include "insn-attr.h"
46 #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 void push (int);
89 static void pop (int);
90 static const char *cond_string (enum rtx_code
);
91 static unsigned int h8300_asm_insn_count (const char *);
92 static tree
h8300_handle_fndecl_attribute (tree
*, tree
, tree
, int, bool *);
93 static tree
h8300_handle_eightbit_data_attribute (tree
*, tree
, tree
, int, bool *);
94 static tree
h8300_handle_tiny_data_attribute (tree
*, tree
, tree
, int, bool *);
95 #ifndef OBJECT_FORMAT_ELF
96 static void h8300_asm_named_section (const char *, unsigned int, tree
);
98 static int h8300_and_costs (rtx
);
99 static int h8300_shift_costs (rtx
);
100 static void h8300_push_pop (int, int, bool, bool);
101 static int h8300_stack_offset_p (rtx
, int);
102 static int h8300_ldm_stm_regno (rtx
, int, int, int);
103 static void h8300_reorg (void);
104 static unsigned int h8300_constant_length (rtx
);
105 static unsigned int h8300_displacement_length (rtx
, int);
106 static unsigned int h8300_classify_operand (rtx
, int, enum h8300_operand_class
*);
107 static unsigned int h8300_length_from_table (rtx
, rtx
, const h8300_length_table
*);
108 static unsigned int h8300_unary_length (rtx
);
109 static unsigned int h8300_short_immediate_length (rtx
);
110 static unsigned int h8300_bitfield_length (rtx
, rtx
);
111 static unsigned int h8300_binary_length (rtx
, const h8300_length_table
*);
112 static bool h8300_short_move_mem_p (rtx
, enum rtx_code
);
113 static unsigned int h8300_move_length (rtx
*, const h8300_length_table
*);
114 static bool h8300_hard_regno_scratch_ok (unsigned int);
116 /* CPU_TYPE, says what cpu we're compiling for. */
119 /* True if a #pragma interrupt has been seen for the current function. */
120 static int pragma_interrupt
;
122 /* True if a #pragma saveall has been seen for the current function. */
123 static int pragma_saveall
;
125 static const char *const names_big
[] =
126 { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7" };
128 static const char *const names_extended
[] =
129 { "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7" };
131 static const char *const names_upper_extended
[] =
132 { "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7" };
134 /* Points to one of the above. */
135 /* ??? The above could be put in an array indexed by CPU_TYPE. */
136 const char * const *h8_reg_names
;
138 /* Various operations needed by the following, indexed by CPU_TYPE. */
140 const char *h8_push_op
, *h8_pop_op
, *h8_mov_op
;
142 /* Value of MOVE_RATIO. */
143 int h8300_move_ratio
;
145 /* See below where shifts are handled for explanation of this enum. */
155 /* Symbols of the various shifts which can be used as indices. */
159 SHIFT_ASHIFT
, SHIFT_LSHIFTRT
, SHIFT_ASHIFTRT
162 /* Macros to keep the shift algorithm tables small. */
163 #define INL SHIFT_INLINE
164 #define ROT SHIFT_ROT_AND
165 #define LOP SHIFT_LOOP
166 #define SPC SHIFT_SPECIAL
168 /* The shift algorithms for each machine, mode, shift type, and shift
169 count are defined below. The three tables below correspond to
170 QImode, HImode, and SImode, respectively. Each table is organized
171 by, in the order of indices, machine, shift type, and shift count. */
173 static enum shift_alg shift_alg_qi
[3][3][8] = {
176 /* 0 1 2 3 4 5 6 7 */
177 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
178 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
179 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
} /* SHIFT_ASHIFTRT */
183 /* 0 1 2 3 4 5 6 7 */
184 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
185 { INL
, INL
, INL
, INL
, INL
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
186 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
} /* SHIFT_ASHIFTRT */
190 /* 0 1 2 3 4 5 6 7 */
191 { INL
, INL
, INL
, INL
, INL
, INL
, ROT
, ROT
}, /* SHIFT_ASHIFT */
192 { INL
, INL
, INL
, INL
, INL
, INL
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
193 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
} /* SHIFT_ASHIFTRT */
197 static enum shift_alg shift_alg_hi
[3][3][16] = {
200 /* 0 1 2 3 4 5 6 7 */
201 /* 8 9 10 11 12 13 14 15 */
202 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
203 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
204 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
,
205 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
206 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, SPC
,
207 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
211 /* 0 1 2 3 4 5 6 7 */
212 /* 8 9 10 11 12 13 14 15 */
213 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
214 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
215 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
216 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
217 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, SPC
,
218 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
222 /* 0 1 2 3 4 5 6 7 */
223 /* 8 9 10 11 12 13 14 15 */
224 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
225 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_ASHIFT */
226 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
227 SPC
, SPC
, SPC
, SPC
, SPC
, ROT
, ROT
, ROT
}, /* SHIFT_LSHIFTRT */
228 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
229 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFTRT */
233 static enum shift_alg shift_alg_si
[3][3][32] = {
236 /* 0 1 2 3 4 5 6 7 */
237 /* 8 9 10 11 12 13 14 15 */
238 /* 16 17 18 19 20 21 22 23 */
239 /* 24 25 26 27 28 29 30 31 */
240 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
241 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
242 SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
,
243 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFT */
244 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
245 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
246 SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
,
247 SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, SPC
}, /* SHIFT_LSHIFTRT */
248 { INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
249 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
250 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
251 SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
255 /* 0 1 2 3 4 5 6 7 */
256 /* 8 9 10 11 12 13 14 15 */
257 /* 16 17 18 19 20 21 22 23 */
258 /* 24 25 26 27 28 29 30 31 */
259 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
260 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
261 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
262 SPC
, LOP
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
263 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
264 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
,
265 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
266 SPC
, LOP
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
267 { INL
, INL
, INL
, INL
, INL
, LOP
, LOP
, LOP
,
268 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
,
269 SPC
, SPC
, SPC
, SPC
, LOP
, LOP
, LOP
, LOP
,
270 SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
274 /* 0 1 2 3 4 5 6 7 */
275 /* 8 9 10 11 12 13 14 15 */
276 /* 16 17 18 19 20 21 22 23 */
277 /* 24 25 26 27 28 29 30 31 */
278 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
279 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, SPC
,
280 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
281 SPC
, SPC
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_ASHIFT */
282 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
283 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, SPC
,
284 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
285 SPC
, SPC
, LOP
, LOP
, SPC
, SPC
, SPC
, SPC
}, /* SHIFT_LSHIFTRT */
286 { INL
, INL
, INL
, INL
, INL
, INL
, INL
, INL
,
287 INL
, INL
, INL
, LOP
, LOP
, LOP
, LOP
, LOP
,
288 SPC
, SPC
, SPC
, SPC
, SPC
, SPC
, LOP
, LOP
,
289 SPC
, SPC
, LOP
, LOP
, LOP
, LOP
, LOP
, SPC
}, /* SHIFT_ASHIFTRT */
305 /* Initialize various cpu specific globals at start up. */
308 h8300_init_once (void)
310 static const char *const h8_push_ops
[2] = { "push" , "push.l" };
311 static const char *const h8_pop_ops
[2] = { "pop" , "pop.l" };
312 static const char *const h8_mov_ops
[2] = { "mov.w", "mov.l" };
316 cpu_type
= (int) CPU_H8300
;
317 h8_reg_names
= names_big
;
321 /* For this we treat the H8/300H and H8S the same. */
322 cpu_type
= (int) CPU_H8300H
;
323 h8_reg_names
= names_extended
;
325 h8_push_op
= h8_push_ops
[cpu_type
];
326 h8_pop_op
= h8_pop_ops
[cpu_type
];
327 h8_mov_op
= h8_mov_ops
[cpu_type
];
329 if (!TARGET_H8300S
&& TARGET_MAC
)
331 error ("-ms2600 is used without -ms");
332 target_flags
|= MASK_H8300S_1
;
335 if (TARGET_H8300
&& TARGET_NORMAL_MODE
)
337 error ("-mn is used without -mh or -ms");
338 target_flags
^= MASK_NORMAL_MODE
;
341 /* Some of the shifts are optimized for speed by default.
342 See http://gcc.gnu.org/ml/gcc-patches/2002-07/msg01858.html
343 If optimizing for size, change shift_alg for those shift to
348 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][5] = SHIFT_LOOP
;
349 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][6] = SHIFT_LOOP
;
350 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][13] = SHIFT_LOOP
;
351 shift_alg_hi
[H8_300
][SHIFT_ASHIFT
][14] = SHIFT_LOOP
;
353 shift_alg_hi
[H8_300
][SHIFT_LSHIFTRT
][13] = SHIFT_LOOP
;
354 shift_alg_hi
[H8_300
][SHIFT_LSHIFTRT
][14] = SHIFT_LOOP
;
356 shift_alg_hi
[H8_300
][SHIFT_ASHIFTRT
][13] = SHIFT_LOOP
;
357 shift_alg_hi
[H8_300
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
360 shift_alg_hi
[H8_300H
][SHIFT_ASHIFT
][5] = SHIFT_LOOP
;
361 shift_alg_hi
[H8_300H
][SHIFT_ASHIFT
][6] = SHIFT_LOOP
;
363 shift_alg_hi
[H8_300H
][SHIFT_LSHIFTRT
][5] = SHIFT_LOOP
;
364 shift_alg_hi
[H8_300H
][SHIFT_LSHIFTRT
][6] = SHIFT_LOOP
;
366 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][5] = SHIFT_LOOP
;
367 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][6] = SHIFT_LOOP
;
368 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][13] = SHIFT_LOOP
;
369 shift_alg_hi
[H8_300H
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
372 shift_alg_hi
[H8_S
][SHIFT_ASHIFTRT
][14] = SHIFT_LOOP
;
375 /* Work out a value for MOVE_RATIO. */
378 /* Memory-memory moves are quite expensive without the
379 h8sx instructions. */
380 h8300_move_ratio
= 3;
382 else if (flag_omit_frame_pointer
)
384 /* movmd sequences are fairly cheap when er6 isn't fixed. They can
385 sometimes be as short as two individual memory-to-memory moves,
386 but since they use all the call-saved registers, it seems better
387 to allow up to three moves here. */
388 h8300_move_ratio
= 4;
390 else if (optimize_size
)
392 /* In this case we don't use movmd sequences since they tend
393 to be longer than calls to memcpy(). Memory-to-memory
394 moves are cheaper than for !TARGET_H8300SX, so it makes
395 sense to have a slightly higher threshold. */
396 h8300_move_ratio
= 4;
400 /* We use movmd sequences for some moves since it can be quicker
401 than calling memcpy(). The sequences will need to save and
402 restore er6 though, so bump up the cost. */
403 h8300_move_ratio
= 6;
407 /* Implement REG_CLASS_FROM_LETTER.
409 Some patterns need to use er6 as a scratch register. This is
410 difficult to arrange since er6 is the frame pointer and usually
413 Such patterns should define two alternatives, one which allows only
414 er6 and one which allows any general register. The former alternative
415 should have a 'd' constraint while the latter should be disparaged and
418 Normally, 'd' maps to DESTINATION_REGS and 'D' maps to GENERAL_REGS.
419 However, there are cases where they should be NO_REGS:
421 - 'd' should be NO_REGS when reloading a function that uses the
422 frame pointer. In this case, DESTINATION_REGS won't contain any
423 spillable registers, so the first alternative can't be used.
425 - -fno-omit-frame-pointer means that the frame pointer will
426 always be in use. It's therefore better to map 'd' to NO_REGS
427 before reload so that register allocator will pick the second
430 - we would like 'D' to be be NO_REGS when the frame pointer isn't
431 live, but we the frame pointer may turn out to be needed after
432 we start reload, and then we may have already decided we don't
433 have a choice, so we can't do that. Forcing the register
434 allocator to use er6 if possible might produce better code for
435 small functions: it's more efficient to save and restore er6 in
436 the prologue & epilogue than to do it in a define_split.
437 Hopefully disparaging 'D' will have a similar effect, without
438 forcing a reload failure if the frame pointer is found to be
442 h8300_reg_class_from_letter (int c
)
453 if (!flag_omit_frame_pointer
&& !reload_completed
)
455 if (frame_pointer_needed
&& reload_in_progress
)
457 return DESTINATION_REGS
;
460 /* The meaning of a constraint shouldn't change dynamically, so
461 we can't make this NO_REGS. */
472 /* Return the byte register name for a register rtx X. B should be 0
473 if you want a lower byte register. B should be 1 if you want an
474 upper byte register. */
477 byte_reg (rtx x
, int b
)
479 static const char *const names_small
[] = {
480 "r0l", "r0h", "r1l", "r1h", "r2l", "r2h", "r3l", "r3h",
481 "r4l", "r4h", "r5l", "r5h", "r6l", "r6h", "r7l", "r7h"
484 gcc_assert (REG_P (x
));
486 return names_small
[REGNO (x
) * 2 + b
];
489 /* REGNO must be saved/restored across calls if this macro is true. */
491 #define WORD_REG_USED(regno) \
493 /* No need to save registers if this function will not return. */ \
494 && ! TREE_THIS_VOLATILE (current_function_decl) \
495 && (h8300_saveall_function_p (current_function_decl) \
496 /* Save any call saved register that was used. */ \
497 || (df_regs_ever_live_p (regno) && !call_used_regs[regno]) \
498 /* Save the frame pointer if it was used. */ \
499 || (regno == HARD_FRAME_POINTER_REGNUM && df_regs_ever_live_p (regno)) \
500 /* Save any register used in an interrupt handler. */ \
501 || (h8300_current_function_interrupt_function_p () \
502 && df_regs_ever_live_p (regno)) \
503 /* Save call clobbered registers in non-leaf interrupt \
505 || (h8300_current_function_interrupt_function_p () \
506 && call_used_regs[regno] \
507 && !current_function_is_leaf)))
509 /* We use this to wrap all emitted insns in the prologue. */
511 F (rtx x
, bool set_it
)
514 RTX_FRAME_RELATED_P (x
) = 1;
518 /* Mark all the subexpressions of the PARALLEL rtx PAR as
519 frame-related. Return PAR.
521 dwarf2out.c:dwarf2out_frame_debug_expr ignores sub-expressions of a
522 PARALLEL rtx other than the first if they do not have the
523 FRAME_RELATED flag set on them. */
527 int len
= XVECLEN (par
, 0);
530 for (i
= 0; i
< len
; i
++)
531 F (XVECEXP (par
, 0, i
), true);
536 /* Output assembly language to FILE for the operation OP with operand size
537 SIZE to adjust the stack pointer. */
540 h8300_emit_stack_adjustment (int sign
, HOST_WIDE_INT size
, bool in_prologue
)
542 /* If the frame size is 0, we don't have anything to do. */
546 /* H8/300 cannot add/subtract a large constant with a single
547 instruction. If a temporary register is available, load the
548 constant to it and then do the addition. */
551 && !h8300_current_function_interrupt_function_p ()
552 && !(cfun
->static_chain_decl
!= NULL
&& sign
< 0))
554 rtx r3
= gen_rtx_REG (Pmode
, 3);
555 F (emit_insn (gen_movhi (r3
, GEN_INT (sign
* size
))), in_prologue
);
556 F (emit_insn (gen_addhi3 (stack_pointer_rtx
,
557 stack_pointer_rtx
, r3
)), in_prologue
);
561 /* The stack adjustment made here is further optimized by the
562 splitter. In case of H8/300, the splitter always splits the
563 addition emitted here to make the adjustment interrupt-safe.
564 FIXME: We don't always tag those, because we don't know what
565 the splitter will do. */
568 rtx x
= emit_insn (gen_addhi3 (stack_pointer_rtx
,
569 stack_pointer_rtx
, GEN_INT (sign
* size
)));
574 F (emit_insn (gen_addsi3 (stack_pointer_rtx
,
575 stack_pointer_rtx
, GEN_INT (sign
* size
))), in_prologue
);
579 /* Round up frame size SIZE. */
582 round_frame_size (HOST_WIDE_INT size
)
584 return ((size
+ STACK_BOUNDARY
/ BITS_PER_UNIT
- 1)
585 & -STACK_BOUNDARY
/ BITS_PER_UNIT
);
588 /* Compute which registers to push/pop.
589 Return a bit vector of registers. */
592 compute_saved_regs (void)
594 unsigned int saved_regs
= 0;
597 /* Construct a bit vector of registers to be pushed/popped. */
598 for (regno
= 0; regno
<= HARD_FRAME_POINTER_REGNUM
; regno
++)
600 if (WORD_REG_USED (regno
))
601 saved_regs
|= 1 << regno
;
604 /* Don't push/pop the frame pointer as it is treated separately. */
605 if (frame_pointer_needed
)
606 saved_regs
&= ~(1 << HARD_FRAME_POINTER_REGNUM
);
611 /* Emit an insn to push register RN. */
616 rtx reg
= gen_rtx_REG (word_mode
, rn
);
620 x
= gen_push_h8300 (reg
);
621 else if (!TARGET_NORMAL_MODE
)
622 x
= gen_push_h8300hs_advanced (reg
);
624 x
= gen_push_h8300hs_normal (reg
);
625 x
= F (emit_insn (x
), true);
626 REG_NOTES (x
) = gen_rtx_EXPR_LIST (REG_INC
, stack_pointer_rtx
, 0);
629 /* Emit an insn to pop register RN. */
634 rtx reg
= gen_rtx_REG (word_mode
, rn
);
638 x
= gen_pop_h8300 (reg
);
639 else if (!TARGET_NORMAL_MODE
)
640 x
= gen_pop_h8300hs_advanced (reg
);
642 x
= gen_pop_h8300hs_normal (reg
);
644 REG_NOTES (x
) = gen_rtx_EXPR_LIST (REG_INC
, stack_pointer_rtx
, 0);
647 /* Emit an instruction to push or pop NREGS consecutive registers
648 starting at register REGNO. POP_P selects a pop rather than a
649 push and RETURN_P is true if the instruction should return.
651 It must be possible to do the requested operation in a single
652 instruction. If NREGS == 1 && !RETURN_P, use a normal push
653 or pop insn. Otherwise emit a parallel of the form:
656 [(return) ;; if RETURN_P
657 (save or restore REGNO)
658 (save or restore REGNO + 1)
660 (save or restore REGNO + NREGS - 1)
661 (set sp (plus sp (const_int adjust)))] */
664 h8300_push_pop (int regno
, int nregs
, bool pop_p
, bool return_p
)
670 /* See whether we can use a simple push or pop. */
671 if (!return_p
&& nregs
== 1)
680 /* We need one element for the return insn, if present, one for each
681 register, and one for stack adjustment. */
682 vec
= rtvec_alloc ((return_p
? 1 : 0) + nregs
+ 1);
683 sp
= stack_pointer_rtx
;
686 /* Add the return instruction. */
689 RTVEC_ELT (vec
, i
) = gen_rtx_RETURN (VOIDmode
);
693 /* Add the register moves. */
694 for (j
= 0; j
< nregs
; j
++)
700 /* Register REGNO + NREGS - 1 is popped first. Before the
701 stack adjustment, its slot is at address @sp. */
702 lhs
= gen_rtx_REG (SImode
, regno
+ j
);
703 rhs
= gen_rtx_MEM (SImode
, plus_constant (sp
, (nregs
- j
- 1) * 4));
707 /* Register REGNO is pushed first and will be stored at @(-4,sp). */
708 lhs
= gen_rtx_MEM (SImode
, plus_constant (sp
, (j
+ 1) * -4));
709 rhs
= gen_rtx_REG (SImode
, regno
+ j
);
711 RTVEC_ELT (vec
, i
+ j
) = gen_rtx_SET (VOIDmode
, lhs
, rhs
);
714 /* Add the stack adjustment. */
715 offset
= GEN_INT ((pop_p
? nregs
: -nregs
) * 4);
716 RTVEC_ELT (vec
, i
+ j
) = gen_rtx_SET (VOIDmode
, sp
,
717 gen_rtx_PLUS (Pmode
, sp
, offset
));
719 x
= gen_rtx_PARALLEL (VOIDmode
, vec
);
729 /* Return true if X has the value sp + OFFSET. */
732 h8300_stack_offset_p (rtx x
, int offset
)
735 return x
== stack_pointer_rtx
;
737 return (GET_CODE (x
) == PLUS
738 && XEXP (x
, 0) == stack_pointer_rtx
739 && GET_CODE (XEXP (x
, 1)) == CONST_INT
740 && INTVAL (XEXP (x
, 1)) == offset
);
743 /* A subroutine of h8300_ldm_stm_parallel. X is one pattern in
744 something that may be an ldm or stm instruction. If it fits
745 the required template, return the register it loads or stores,
748 LOAD_P is true if X should be a load, false if it should be a store.
749 NREGS is the number of registers that the whole instruction is expected
750 to load or store. INDEX is the index of the register that X should
751 load or store, relative to the lowest-numbered register. */
754 h8300_ldm_stm_regno (rtx x
, int load_p
, int index
, int nregs
)
756 int regindex
, memindex
, offset
;
759 regindex
= 0, memindex
= 1, offset
= (nregs
- index
- 1) * 4;
761 memindex
= 0, regindex
= 1, offset
= (index
+ 1) * -4;
763 if (GET_CODE (x
) == SET
764 && GET_CODE (XEXP (x
, regindex
)) == REG
765 && GET_CODE (XEXP (x
, memindex
)) == MEM
766 && h8300_stack_offset_p (XEXP (XEXP (x
, memindex
), 0), offset
))
767 return REGNO (XEXP (x
, regindex
));
772 /* Return true if the elements of VEC starting at FIRST describe an
773 ldm or stm instruction (LOAD_P says which). */
776 h8300_ldm_stm_parallel (rtvec vec
, int load_p
, int first
)
779 int nregs
, i
, regno
, adjust
;
781 /* There must be a stack adjustment, a register move, and at least one
782 other operation (a return or another register move). */
783 if (GET_NUM_ELEM (vec
) < 3)
786 /* Get the range of registers to be pushed or popped. */
787 nregs
= GET_NUM_ELEM (vec
) - first
- 1;
788 regno
= h8300_ldm_stm_regno (RTVEC_ELT (vec
, first
), load_p
, 0, nregs
);
790 /* Check that the call to h8300_ldm_stm_regno succeeded and
791 that we're only dealing with GPRs. */
792 if (regno
< 0 || regno
+ nregs
> 8)
795 /* 2-register h8s instructions must start with an even-numbered register.
796 3- and 4-register instructions must start with er0 or er4. */
799 if ((regno
& 1) != 0)
801 if (nregs
> 2 && (regno
& 3) != 0)
805 /* Check the other loads or stores. */
806 for (i
= 1; i
< nregs
; i
++)
807 if (h8300_ldm_stm_regno (RTVEC_ELT (vec
, first
+ i
), load_p
, i
, nregs
)
811 /* Check the stack adjustment. */
812 last
= RTVEC_ELT (vec
, first
+ nregs
);
813 adjust
= (load_p
? nregs
: -nregs
) * 4;
814 return (GET_CODE (last
) == SET
815 && SET_DEST (last
) == stack_pointer_rtx
816 && h8300_stack_offset_p (SET_SRC (last
), adjust
));
819 /* This is what the stack looks like after the prolog of
820 a function with a frame has been set up:
826 <saved registers> <- sp
828 This is what the stack looks like after the prolog of
829 a function which doesn't have a frame:
834 <saved registers> <- sp
837 /* Generate RTL code for the function prologue. */
840 h8300_expand_prologue (void)
846 /* If the current function has the OS_Task attribute set, then
847 we have a naked prologue. */
848 if (h8300_os_task_function_p (current_function_decl
))
851 if (h8300_monitor_function_p (current_function_decl
))
852 /* My understanding of monitor functions is they act just like
853 interrupt functions, except the prologue must mask
855 emit_insn (gen_monitor_prologue ());
857 if (frame_pointer_needed
)
860 push (HARD_FRAME_POINTER_REGNUM
);
861 F (emit_move_insn (hard_frame_pointer_rtx
, stack_pointer_rtx
), true);
864 /* Push the rest of the registers in ascending order. */
865 saved_regs
= compute_saved_regs ();
866 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
+= n_regs
)
869 if (saved_regs
& (1 << regno
))
873 /* See how many registers we can push at the same time. */
874 if ((!TARGET_H8300SX
|| (regno
& 3) == 0)
875 && ((saved_regs
>> regno
) & 0x0f) == 0x0f)
878 else if ((!TARGET_H8300SX
|| (regno
& 3) == 0)
879 && ((saved_regs
>> regno
) & 0x07) == 0x07)
882 else if ((!TARGET_H8300SX
|| (regno
& 1) == 0)
883 && ((saved_regs
>> regno
) & 0x03) == 0x03)
887 h8300_push_pop (regno
, n_regs
, false, false);
891 /* Leave room for locals. */
892 h8300_emit_stack_adjustment (-1, round_frame_size (get_frame_size ()), true);
895 /* Return nonzero if we can use "rts" for the function currently being
899 h8300_can_use_return_insn_p (void)
901 return (reload_completed
902 && !frame_pointer_needed
903 && get_frame_size () == 0
904 && compute_saved_regs () == 0);
907 /* Generate RTL code for the function epilogue. */
910 h8300_expand_epilogue (void)
915 HOST_WIDE_INT frame_size
;
918 if (h8300_os_task_function_p (current_function_decl
))
919 /* OS_Task epilogues are nearly naked -- they just have an
923 frame_size
= round_frame_size (get_frame_size ());
926 /* Deallocate locals. */
927 h8300_emit_stack_adjustment (1, frame_size
, false);
929 /* Pop the saved registers in descending order. */
930 saved_regs
= compute_saved_regs ();
931 for (regno
= FIRST_PSEUDO_REGISTER
- 1; regno
>= 0; regno
-= n_regs
)
934 if (saved_regs
& (1 << regno
))
938 /* See how many registers we can pop at the same time. */
939 if ((TARGET_H8300SX
|| (regno
& 3) == 3)
940 && ((saved_regs
<< 3 >> regno
) & 0x0f) == 0x0f)
943 else if ((TARGET_H8300SX
|| (regno
& 3) == 2)
944 && ((saved_regs
<< 2 >> regno
) & 0x07) == 0x07)
947 else if ((TARGET_H8300SX
|| (regno
& 1) == 1)
948 && ((saved_regs
<< 1 >> regno
) & 0x03) == 0x03)
952 /* See if this pop would be the last insn before the return.
953 If so, use rte/l or rts/l instead of pop or ldm.l. */
955 && !frame_pointer_needed
957 && (saved_regs
& ((1 << (regno
- n_regs
+ 1)) - 1)) == 0)
960 h8300_push_pop (regno
- n_regs
+ 1, n_regs
, true, returned_p
);
964 /* Pop frame pointer if we had one. */
965 if (frame_pointer_needed
)
969 h8300_push_pop (HARD_FRAME_POINTER_REGNUM
, 1, true, returned_p
);
973 emit_jump_insn (gen_rtx_RETURN (VOIDmode
));
976 /* Return nonzero if the current function is an interrupt
980 h8300_current_function_interrupt_function_p (void)
982 return (h8300_interrupt_function_p (current_function_decl
)
983 || h8300_monitor_function_p (current_function_decl
));
986 /* Output assembly code for the start of the file. */
989 h8300_file_start (void)
991 default_file_start ();
994 fputs (TARGET_NORMAL_MODE
? "\t.h8300hn\n" : "\t.h8300h\n", asm_out_file
);
995 else if (TARGET_H8300SX
)
996 fputs (TARGET_NORMAL_MODE
? "\t.h8300sxn\n" : "\t.h8300sx\n", asm_out_file
);
997 else if (TARGET_H8300S
)
998 fputs (TARGET_NORMAL_MODE
? "\t.h8300sn\n" : "\t.h8300s\n", asm_out_file
);
1001 /* Output assembly language code for the end of file. */
1004 h8300_file_end (void)
1006 fputs ("\t.end\n", asm_out_file
);
1009 /* Split an add of a small constant into two adds/subs insns.
1011 If USE_INCDEC_P is nonzero, we generate the last insn using inc/dec
1012 instead of adds/subs. */
1015 split_adds_subs (enum machine_mode mode
, rtx
*operands
)
1017 HOST_WIDE_INT val
= INTVAL (operands
[1]);
1018 rtx reg
= operands
[0];
1019 HOST_WIDE_INT sign
= 1;
1020 HOST_WIDE_INT amount
;
1021 rtx (*gen_add
) (rtx
, rtx
, rtx
);
1023 /* Force VAL to be positive so that we do not have to consider the
1034 gen_add
= gen_addhi3
;
1038 gen_add
= gen_addsi3
;
1045 /* Try different amounts in descending order. */
1046 for (amount
= (TARGET_H8300H
|| TARGET_H8300S
) ? 4 : 2;
1050 for (; val
>= amount
; val
-= amount
)
1051 emit_insn (gen_add (reg
, reg
, GEN_INT (sign
* amount
)));
1057 /* Handle machine specific pragmas for compatibility with existing
1058 compilers for the H8/300.
1060 pragma saveall generates prologue/epilogue code which saves and
1061 restores all the registers on function entry.
1063 pragma interrupt saves and restores all registers, and exits with
1064 an rte instruction rather than an rts. A pointer to a function
1065 with this attribute may be safely used in an interrupt vector. */
1068 h8300_pr_interrupt (struct cpp_reader
*pfile ATTRIBUTE_UNUSED
)
1070 pragma_interrupt
= 1;
1074 h8300_pr_saveall (struct cpp_reader
*pfile ATTRIBUTE_UNUSED
)
1079 /* If the next function argument with MODE and TYPE is to be passed in
1080 a register, return a reg RTX for the hard register in which to pass
1081 the argument. CUM represents the state after the last argument.
1082 If the argument is to be pushed, NULL_RTX is returned. */
1085 function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1086 tree type
, int named
)
1088 static const char *const hand_list
[] = {
1107 rtx result
= NULL_RTX
;
1111 /* Never pass unnamed arguments in registers. */
1115 /* Pass 3 regs worth of data in regs when user asked on the command line. */
1116 if (TARGET_QUICKCALL
)
1119 /* If calling hand written assembler, use 4 regs of args. */
1122 const char * const *p
;
1124 fname
= XSTR (cum
->libcall
, 0);
1126 /* See if this libcall is one of the hand coded ones. */
1127 for (p
= hand_list
; *p
&& strcmp (*p
, fname
) != 0; p
++)
1138 if (mode
== BLKmode
)
1139 size
= int_size_in_bytes (type
);
1141 size
= GET_MODE_SIZE (mode
);
1143 if (size
+ cum
->nbytes
<= regpass
* UNITS_PER_WORD
1144 && cum
->nbytes
/ UNITS_PER_WORD
<= 3)
1145 result
= gen_rtx_REG (mode
, cum
->nbytes
/ UNITS_PER_WORD
);
1151 /* Compute the cost of an and insn. */
1154 h8300_and_costs (rtx x
)
1158 if (GET_MODE (x
) == QImode
)
1161 if (GET_MODE (x
) != HImode
1162 && GET_MODE (x
) != SImode
)
1166 operands
[1] = XEXP (x
, 0);
1167 operands
[2] = XEXP (x
, 1);
1169 return compute_logical_op_length (GET_MODE (x
), operands
) / 2;
1172 /* Compute the cost of a shift insn. */
1175 h8300_shift_costs (rtx x
)
1179 if (GET_MODE (x
) != QImode
1180 && GET_MODE (x
) != HImode
1181 && GET_MODE (x
) != SImode
)
1186 operands
[2] = XEXP (x
, 1);
1188 return compute_a_shift_length (NULL
, operands
) / 2;
1191 /* Worker function for TARGET_RTX_COSTS. */
1194 h8300_rtx_costs (rtx x
, int code
, int outer_code
, int *total
, bool speed
)
1196 if (TARGET_H8300SX
&& outer_code
== MEM
)
1198 /* Estimate the number of execution states needed to calculate
1200 if (register_operand (x
, VOIDmode
)
1201 || GET_CODE (x
) == POST_INC
1202 || GET_CODE (x
) == POST_DEC
1206 *total
= COSTS_N_INSNS (1);
1214 HOST_WIDE_INT n
= INTVAL (x
);
1218 /* Constant operands need the same number of processor
1219 states as register operands. Although we could try to
1220 use a size-based cost for !speed, the lack of
1221 of a mode makes the results very unpredictable. */
1225 if (-4 <= n
|| n
<= 4)
1236 *total
= 0 + (outer_code
== SET
);
1240 if (TARGET_H8300H
|| TARGET_H8300S
)
1241 *total
= 0 + (outer_code
== SET
);
1256 /* See comment for CONST_INT. */
1268 if (XEXP (x
, 1) == const0_rtx
)
1273 if (!h8300_dst_operand (XEXP (x
, 0), VOIDmode
)
1274 || !h8300_src_operand (XEXP (x
, 1), VOIDmode
))
1276 *total
= COSTS_N_INSNS (h8300_and_costs (x
));
1279 /* We say that MOD and DIV are so expensive because otherwise we'll
1280 generate some really horrible code for division of a power of two. */
1286 switch (GET_MODE (x
))
1290 *total
= COSTS_N_INSNS (!speed
? 4 : 10);
1294 *total
= COSTS_N_INSNS (!speed
? 4 : 18);
1300 *total
= COSTS_N_INSNS (12);
1305 switch (GET_MODE (x
))
1309 *total
= COSTS_N_INSNS (2);
1313 *total
= COSTS_N_INSNS (5);
1319 *total
= COSTS_N_INSNS (4);
1325 if (h8sx_binary_shift_operator (x
, VOIDmode
))
1327 *total
= COSTS_N_INSNS (2);
1330 else if (h8sx_unary_shift_operator (x
, VOIDmode
))
1332 *total
= COSTS_N_INSNS (1);
1335 *total
= COSTS_N_INSNS (h8300_shift_costs (x
));
1340 if (GET_MODE (x
) == HImode
)
1347 *total
= COSTS_N_INSNS (1);
1352 /* Documentation for the machine specific operand escapes:
1354 'E' like s but negative.
1355 'F' like t but negative.
1356 'G' constant just the negative
1357 'R' print operand as a byte:8 address if appropriate, else fall back to
1359 'S' print operand as a long word
1360 'T' print operand as a word
1361 'V' find the set bit, and print its number.
1362 'W' find the clear bit, and print its number.
1363 'X' print operand as a byte
1364 'Y' print either l or h depending on whether last 'Z' operand < 8 or >= 8.
1365 If this operand isn't a register, fall back to 'R' handling.
1367 'c' print the opcode corresponding to rtl
1368 'e' first word of 32-bit value - if reg, then least reg. if mem
1369 then least. if const then most sig word
1370 'f' second word of 32-bit value - if reg, then biggest reg. if mem
1371 then +2. if const then least sig word
1372 'j' print operand as condition code.
1373 'k' print operand as reverse condition code.
1374 'm' convert an integer operand to a size suffix (.b, .w or .l)
1375 'o' print an integer without a leading '#'
1376 's' print as low byte of 16-bit value
1377 't' print as high byte of 16-bit value
1378 'w' print as low byte of 32-bit value
1379 'x' print as 2nd byte of 32-bit value
1380 'y' print as 3rd byte of 32-bit value
1381 'z' print as msb of 32-bit value
1384 /* Return assembly language string which identifies a comparison type. */
1387 cond_string (enum rtx_code code
)
1416 /* Print operand X using operand code CODE to assembly language output file
1420 print_operand (FILE *file
, rtx x
, int code
)
1422 /* This is used for communication between codes V,W,Z and Y. */
1428 switch (GET_CODE (x
))
1431 fprintf (file
, "%sl", names_big
[REGNO (x
)]);
1434 fprintf (file
, "#%ld", (-INTVAL (x
)) & 0xff);
1441 switch (GET_CODE (x
))
1444 fprintf (file
, "%sh", names_big
[REGNO (x
)]);
1447 fprintf (file
, "#%ld", ((-INTVAL (x
)) & 0xff00) >> 8);
1454 gcc_assert (GET_CODE (x
) == CONST_INT
);
1455 fprintf (file
, "#%ld", 0xff & (-INTVAL (x
)));
1458 if (GET_CODE (x
) == REG
)
1459 fprintf (file
, "%s", names_extended
[REGNO (x
)]);
1464 if (GET_CODE (x
) == REG
)
1465 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1470 bitint
= (INTVAL (x
) & 0xffff);
1471 if ((exact_log2 ((bitint
>> 8) & 0xff)) == -1)
1472 bitint
= exact_log2 (bitint
& 0xff);
1474 bitint
= exact_log2 ((bitint
>> 8) & 0xff);
1475 gcc_assert (bitint
>= 0);
1476 fprintf (file
, "#%d", bitint
);
1479 bitint
= ((~INTVAL (x
)) & 0xffff);
1480 if ((exact_log2 ((bitint
>> 8) & 0xff)) == -1 )
1481 bitint
= exact_log2 (bitint
& 0xff);
1483 bitint
= (exact_log2 ((bitint
>> 8) & 0xff));
1484 gcc_assert (bitint
>= 0);
1485 fprintf (file
, "#%d", bitint
);
1489 if (GET_CODE (x
) == REG
)
1490 fprintf (file
, "%s", byte_reg (x
, 0));
1495 gcc_assert (bitint
>= 0);
1496 if (GET_CODE (x
) == REG
)
1497 fprintf (file
, "%s%c", names_big
[REGNO (x
)], bitint
> 7 ? 'h' : 'l');
1499 print_operand (file
, x
, 'R');
1503 bitint
= INTVAL (x
);
1504 fprintf (file
, "#%d", bitint
& 7);
1507 switch (GET_CODE (x
))
1510 fprintf (file
, "or");
1513 fprintf (file
, "xor");
1516 fprintf (file
, "and");
1523 switch (GET_CODE (x
))
1527 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1529 fprintf (file
, "%s", names_upper_extended
[REGNO (x
)]);
1532 print_operand (file
, x
, 0);
1535 fprintf (file
, "#%ld", ((INTVAL (x
) >> 16) & 0xffff));
1541 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1542 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1543 fprintf (file
, "#%ld", ((val
>> 16) & 0xffff));
1552 switch (GET_CODE (x
))
1556 fprintf (file
, "%s", names_big
[REGNO (x
) + 1]);
1558 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1561 x
= adjust_address (x
, HImode
, 2);
1562 print_operand (file
, x
, 0);
1565 fprintf (file
, "#%ld", INTVAL (x
) & 0xffff);
1571 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1572 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1573 fprintf (file
, "#%ld", (val
& 0xffff));
1581 fputs (cond_string (GET_CODE (x
)), file
);
1584 fputs (cond_string (reverse_condition (GET_CODE (x
))), file
);
1587 gcc_assert (GET_CODE (x
) == CONST_INT
);
1607 print_operand_address (file
, x
);
1610 if (GET_CODE (x
) == CONST_INT
)
1611 fprintf (file
, "#%ld", (INTVAL (x
)) & 0xff);
1613 fprintf (file
, "%s", byte_reg (x
, 0));
1616 if (GET_CODE (x
) == CONST_INT
)
1617 fprintf (file
, "#%ld", (INTVAL (x
) >> 8) & 0xff);
1619 fprintf (file
, "%s", byte_reg (x
, 1));
1622 if (GET_CODE (x
) == CONST_INT
)
1623 fprintf (file
, "#%ld", INTVAL (x
) & 0xff);
1625 fprintf (file
, "%s",
1626 byte_reg (x
, TARGET_H8300
? 2 : 0));
1629 if (GET_CODE (x
) == CONST_INT
)
1630 fprintf (file
, "#%ld", (INTVAL (x
) >> 8) & 0xff);
1632 fprintf (file
, "%s",
1633 byte_reg (x
, TARGET_H8300
? 3 : 1));
1636 if (GET_CODE (x
) == CONST_INT
)
1637 fprintf (file
, "#%ld", (INTVAL (x
) >> 16) & 0xff);
1639 fprintf (file
, "%s", byte_reg (x
, 0));
1642 if (GET_CODE (x
) == CONST_INT
)
1643 fprintf (file
, "#%ld", (INTVAL (x
) >> 24) & 0xff);
1645 fprintf (file
, "%s", byte_reg (x
, 1));
1650 switch (GET_CODE (x
))
1653 switch (GET_MODE (x
))
1656 #if 0 /* Is it asm ("mov.b %0,r2l", ...) */
1657 fprintf (file
, "%s", byte_reg (x
, 0));
1658 #else /* ... or is it asm ("mov.b %0l,r2l", ...) */
1659 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1663 fprintf (file
, "%s", names_big
[REGNO (x
)]);
1667 fprintf (file
, "%s", names_extended
[REGNO (x
)]);
1676 rtx addr
= XEXP (x
, 0);
1678 fprintf (file
, "@");
1679 output_address (addr
);
1681 /* Add a length suffix to constant addresses. Although this
1682 is often unnecessary, it helps to avoid ambiguity in the
1683 syntax of mova. If we wrote an insn like:
1685 mova/w.l @(1,@foo.b),er0
1687 then .b would be considered part of the symbol name.
1688 Adding a length after foo will avoid this. */
1689 if (CONSTANT_P (addr
))
1693 /* Used for mov.b and bit operations. */
1694 if (h8300_eightbit_constant_address_p (addr
))
1696 fprintf (file
, ":8");
1700 /* Fall through. We should not get here if we are
1701 processing bit operations on H8/300 or H8/300H
1702 because 'U' constraint does not allow bit
1703 operations on the tiny area on these machines. */
1708 if (h8300_constant_length (addr
) == 2)
1709 fprintf (file
, ":16");
1711 fprintf (file
, ":32");
1723 fprintf (file
, "#");
1724 print_operand_address (file
, x
);
1730 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
1731 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
1732 fprintf (file
, "#%ld", val
);
1741 /* Output assembly language output for the address ADDR to FILE. */
1744 print_operand_address (FILE *file
, rtx addr
)
1749 switch (GET_CODE (addr
))
1752 fprintf (file
, "%s", h8_reg_names
[REGNO (addr
)]);
1756 fprintf (file
, "-%s", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1760 fprintf (file
, "%s+", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1764 fprintf (file
, "+%s", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1768 fprintf (file
, "%s-", h8_reg_names
[REGNO (XEXP (addr
, 0))]);
1772 fprintf (file
, "(");
1774 index
= h8300_get_index (XEXP (addr
, 0), VOIDmode
, &size
);
1775 if (GET_CODE (index
) == REG
)
1778 print_operand_address (file
, XEXP (addr
, 1));
1779 fprintf (file
, ",");
1783 print_operand_address (file
, index
);
1787 print_operand (file
, index
, 'X');
1792 print_operand (file
, index
, 'T');
1797 print_operand (file
, index
, 'S');
1801 /* print_operand_address (file, XEXP (addr, 0)); */
1806 print_operand_address (file
, XEXP (addr
, 0));
1807 fprintf (file
, "+");
1808 print_operand_address (file
, XEXP (addr
, 1));
1810 fprintf (file
, ")");
1815 /* Since the H8/300 only has 16-bit pointers, negative values are also
1816 those >= 32768. This happens for example with pointer minus a
1817 constant. We don't want to turn (char *p - 2) into
1818 (char *p + 65534) because loop unrolling can build upon this
1819 (IE: char *p + 131068). */
1820 int n
= INTVAL (addr
);
1822 n
= (int) (short) n
;
1823 fprintf (file
, "%d", n
);
1828 output_addr_const (file
, addr
);
1833 /* Output all insn addresses and their sizes into the assembly language
1834 output file. This is helpful for debugging whether the length attributes
1835 in the md file are correct. This is not meant to be a user selectable
1839 final_prescan_insn (rtx insn
, rtx
*operand ATTRIBUTE_UNUSED
,
1840 int num_operands ATTRIBUTE_UNUSED
)
1842 /* This holds the last insn address. */
1843 static int last_insn_address
= 0;
1845 const int uid
= INSN_UID (insn
);
1847 if (TARGET_ADDRESSES
)
1849 fprintf (asm_out_file
, "; 0x%x %d\n", INSN_ADDRESSES (uid
),
1850 INSN_ADDRESSES (uid
) - last_insn_address
);
1851 last_insn_address
= INSN_ADDRESSES (uid
);
1855 /* Prepare for an SI sized move. */
1858 h8300_expand_movsi (rtx operands
[])
1860 rtx src
= operands
[1];
1861 rtx dst
= operands
[0];
1862 if (!reload_in_progress
&& !reload_completed
)
1864 if (!register_operand (dst
, GET_MODE (dst
)))
1866 rtx tmp
= gen_reg_rtx (GET_MODE (dst
));
1867 emit_move_insn (tmp
, src
);
1874 /* Given FROM and TO register numbers, say whether this elimination is allowed.
1875 Frame pointer elimination is automatically handled.
1877 For the h8300, if frame pointer elimination is being done, we would like to
1878 convert ap and rp into sp, not fp.
1880 All other eliminations are valid. */
1883 h8300_can_eliminate (const int from ATTRIBUTE_UNUSED
, const int to
)
1885 return (to
== STACK_POINTER_REGNUM
? ! frame_pointer_needed
: true);
1888 /* Function for INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET).
1889 Define the offset between two registers, one to be eliminated, and
1890 the other its replacement, at the start of a routine. */
1893 h8300_initial_elimination_offset (int from
, int to
)
1895 /* The number of bytes that the return address takes on the stack. */
1896 int pc_size
= POINTER_SIZE
/ BITS_PER_UNIT
;
1898 /* The number of bytes that the saved frame pointer takes on the stack. */
1899 int fp_size
= frame_pointer_needed
* UNITS_PER_WORD
;
1901 /* The number of bytes that the saved registers, excluding the frame
1902 pointer, take on the stack. */
1903 int saved_regs_size
= 0;
1905 /* The number of bytes that the locals takes on the stack. */
1906 int frame_size
= round_frame_size (get_frame_size ());
1910 for (regno
= 0; regno
<= HARD_FRAME_POINTER_REGNUM
; regno
++)
1911 if (WORD_REG_USED (regno
))
1912 saved_regs_size
+= UNITS_PER_WORD
;
1914 /* Adjust saved_regs_size because the above loop took the frame
1915 pointer int account. */
1916 saved_regs_size
-= fp_size
;
1920 case HARD_FRAME_POINTER_REGNUM
:
1923 case ARG_POINTER_REGNUM
:
1924 return pc_size
+ fp_size
;
1925 case RETURN_ADDRESS_POINTER_REGNUM
:
1927 case FRAME_POINTER_REGNUM
:
1928 return -saved_regs_size
;
1933 case STACK_POINTER_REGNUM
:
1936 case ARG_POINTER_REGNUM
:
1937 return pc_size
+ saved_regs_size
+ frame_size
;
1938 case RETURN_ADDRESS_POINTER_REGNUM
:
1939 return saved_regs_size
+ frame_size
;
1940 case FRAME_POINTER_REGNUM
:
1952 /* Worker function for RETURN_ADDR_RTX. */
1955 h8300_return_addr_rtx (int count
, rtx frame
)
1960 ret
= gen_rtx_MEM (Pmode
,
1961 gen_rtx_REG (Pmode
, RETURN_ADDRESS_POINTER_REGNUM
));
1962 else if (flag_omit_frame_pointer
)
1965 ret
= gen_rtx_MEM (Pmode
,
1966 memory_address (Pmode
,
1967 plus_constant (frame
, UNITS_PER_WORD
)));
1968 set_mem_alias_set (ret
, get_frame_alias_set ());
1972 /* Update the condition code from the insn. */
1975 notice_update_cc (rtx body
, rtx insn
)
1979 switch (get_attr_cc (insn
))
1982 /* Insn does not affect CC at all. */
1986 /* Insn does not change CC, but the 0'th operand has been changed. */
1987 if (cc_status
.value1
!= 0
1988 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
1989 cc_status
.value1
= 0;
1990 if (cc_status
.value2
!= 0
1991 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value2
))
1992 cc_status
.value2
= 0;
1996 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1997 The V flag is unusable. The C flag may or may not be known but
1998 that's ok because alter_cond will change tests to use EQ/NE. */
2000 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
2001 set
= single_set (insn
);
2002 cc_status
.value1
= SET_SRC (set
);
2003 if (SET_DEST (set
) != cc0_rtx
)
2004 cc_status
.value2
= SET_DEST (set
);
2008 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
2009 The C flag may or may not be known but that's ok because
2010 alter_cond will change tests to use EQ/NE. */
2012 cc_status
.flags
|= CC_NO_CARRY
;
2013 set
= single_set (insn
);
2014 cc_status
.value1
= SET_SRC (set
);
2015 if (SET_DEST (set
) != cc0_rtx
)
2017 /* If the destination is STRICT_LOW_PART, strip off
2019 if (GET_CODE (SET_DEST (set
)) == STRICT_LOW_PART
)
2020 cc_status
.value2
= XEXP (SET_DEST (set
), 0);
2022 cc_status
.value2
= SET_DEST (set
);
2027 /* The insn is a compare instruction. */
2029 cc_status
.value1
= SET_SRC (body
);
2033 /* Insn doesn't leave CC in a usable state. */
2039 /* Given that X occurs in an address of the form (plus X constant),
2040 return the part of X that is expected to be a register. There are
2041 four kinds of addressing mode to recognize:
2048 If SIZE is nonnull, and the address is one of the last three forms,
2049 set *SIZE to the index multiplication factor. Set it to 0 for
2050 plain @(dd,Rn) addresses.
2052 MODE is the mode of the value being accessed. It can be VOIDmode
2053 if the address is known to be valid, but its mode is unknown. */
2056 h8300_get_index (rtx x
, enum machine_mode mode
, int *size
)
2063 factor
= (mode
== VOIDmode
? 0 : GET_MODE_SIZE (mode
));
2066 && (mode
== VOIDmode
2067 || GET_MODE_CLASS (mode
) == MODE_INT
2068 || GET_MODE_CLASS (mode
) == MODE_FLOAT
))
2070 if (factor
<= 1 && GET_CODE (x
) == ZERO_EXTEND
)
2072 /* When accessing byte-sized values, the index can be
2073 a zero-extended QImode or HImode register. */
2074 *size
= GET_MODE_SIZE (GET_MODE (XEXP (x
, 0)));
2079 /* We're looking for addresses of the form:
2082 or (mult (zero_extend X) I)
2084 where I is the size of the operand being accessed.
2085 The canonical form of the second expression is:
2087 (and (mult (subreg X) I) J)
2089 where J == GET_MODE_MASK (GET_MODE (X)) * I. */
2092 if (GET_CODE (x
) == AND
2093 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2095 || INTVAL (XEXP (x
, 1)) == 0xff * factor
2096 || INTVAL (XEXP (x
, 1)) == 0xffff * factor
))
2098 index
= XEXP (x
, 0);
2099 *size
= (INTVAL (XEXP (x
, 1)) >= 0xffff ? 2 : 1);
2107 if (GET_CODE (index
) == MULT
2108 && GET_CODE (XEXP (index
, 1)) == CONST_INT
2109 && (factor
== 0 || factor
== INTVAL (XEXP (index
, 1))))
2110 return XEXP (index
, 0);
2117 static const h8300_length_table addb_length_table
=
2119 /* #xx Rs @aa @Rs @xx */
2120 { 2, 2, 4, 4, 4 }, /* add.b xx,Rd */
2121 { 4, 4, 4, 4, 6 }, /* add.b xx,@aa */
2122 { 4, 4, 4, 4, 6 }, /* add.b xx,@Rd */
2123 { 6, 4, 4, 4, 6 } /* add.b xx,@xx */
2126 static const h8300_length_table addw_length_table
=
2128 /* #xx Rs @aa @Rs @xx */
2129 { 2, 2, 4, 4, 4 }, /* add.w xx,Rd */
2130 { 4, 4, 4, 4, 6 }, /* add.w xx,@aa */
2131 { 4, 4, 4, 4, 6 }, /* add.w xx,@Rd */
2132 { 4, 4, 4, 4, 6 } /* add.w xx,@xx */
2135 static const h8300_length_table addl_length_table
=
2137 /* #xx Rs @aa @Rs @xx */
2138 { 2, 2, 4, 4, 4 }, /* add.l xx,Rd */
2139 { 4, 4, 6, 6, 6 }, /* add.l xx,@aa */
2140 { 4, 4, 6, 6, 6 }, /* add.l xx,@Rd */
2141 { 4, 4, 6, 6, 6 } /* add.l xx,@xx */
2144 #define logicb_length_table addb_length_table
2145 #define logicw_length_table addw_length_table
2147 static const h8300_length_table logicl_length_table
=
2149 /* #xx Rs @aa @Rs @xx */
2150 { 2, 4, 4, 4, 4 }, /* and.l xx,Rd */
2151 { 4, 4, 6, 6, 6 }, /* and.l xx,@aa */
2152 { 4, 4, 6, 6, 6 }, /* and.l xx,@Rd */
2153 { 4, 4, 6, 6, 6 } /* and.l xx,@xx */
2156 static const h8300_length_table movb_length_table
=
2158 /* #xx Rs @aa @Rs @xx */
2159 { 2, 2, 2, 2, 4 }, /* mov.b xx,Rd */
2160 { 4, 2, 4, 4, 4 }, /* mov.b xx,@aa */
2161 { 4, 2, 4, 4, 4 }, /* mov.b xx,@Rd */
2162 { 4, 4, 4, 4, 4 } /* mov.b xx,@xx */
2165 #define movw_length_table movb_length_table
2167 static const h8300_length_table movl_length_table
=
2169 /* #xx Rs @aa @Rs @xx */
2170 { 2, 2, 4, 4, 4 }, /* mov.l xx,Rd */
2171 { 4, 4, 4, 4, 4 }, /* mov.l xx,@aa */
2172 { 4, 4, 4, 4, 4 }, /* mov.l xx,@Rd */
2173 { 4, 4, 4, 4, 4 } /* mov.l xx,@xx */
2176 /* Return the size of the given address or displacement constant. */
2179 h8300_constant_length (rtx constant
)
2181 /* Check for (@d:16,Reg). */
2182 if (GET_CODE (constant
) == CONST_INT
2183 && IN_RANGE (INTVAL (constant
), -0x8000, 0x7fff))
2186 /* Check for (@d:16,Reg) in cases where the displacement is
2187 an absolute address. */
2188 if (Pmode
== HImode
|| h8300_tiny_constant_address_p (constant
))
2194 /* Return the size of a displacement field in address ADDR, which should
2195 have the form (plus X constant). SIZE is the number of bytes being
2199 h8300_displacement_length (rtx addr
, int size
)
2203 offset
= XEXP (addr
, 1);
2205 /* Check for @(d:2,Reg). */
2206 if (register_operand (XEXP (addr
, 0), VOIDmode
)
2207 && GET_CODE (offset
) == CONST_INT
2208 && (INTVAL (offset
) == size
2209 || INTVAL (offset
) == size
* 2
2210 || INTVAL (offset
) == size
* 3))
2213 return h8300_constant_length (offset
);
2216 /* Store the class of operand OP in *OPCLASS and return the length of any
2217 extra operand fields. SIZE is the number of bytes in OP. OPCLASS
2218 can be null if only the length is needed. */
2221 h8300_classify_operand (rtx op
, int size
, enum h8300_operand_class
*opclass
)
2223 enum h8300_operand_class dummy
;
2228 if (CONSTANT_P (op
))
2230 *opclass
= H8OP_IMMEDIATE
;
2232 /* Byte-sized immediates are stored in the opcode fields. */
2236 /* If this is a 32-bit instruction, see whether the constant
2237 will fit into a 16-bit immediate field. */
2240 && GET_CODE (op
) == CONST_INT
2241 && IN_RANGE (INTVAL (op
), 0, 0xffff))
2246 else if (GET_CODE (op
) == MEM
)
2249 if (CONSTANT_P (op
))
2251 *opclass
= H8OP_MEM_ABSOLUTE
;
2252 return h8300_constant_length (op
);
2254 else if (GET_CODE (op
) == PLUS
&& CONSTANT_P (XEXP (op
, 1)))
2256 *opclass
= H8OP_MEM_COMPLEX
;
2257 return h8300_displacement_length (op
, size
);
2259 else if (GET_RTX_CLASS (GET_CODE (op
)) == RTX_AUTOINC
)
2261 *opclass
= H8OP_MEM_COMPLEX
;
2264 else if (register_operand (op
, VOIDmode
))
2266 *opclass
= H8OP_MEM_BASE
;
2270 gcc_assert (register_operand (op
, VOIDmode
));
2271 *opclass
= H8OP_REGISTER
;
2275 /* Return the length of the instruction described by TABLE given that
2276 its operands are OP1 and OP2. OP1 must be an h8300_dst_operand
2277 and OP2 must be an h8300_src_operand. */
2280 h8300_length_from_table (rtx op1
, rtx op2
, const h8300_length_table
*table
)
2282 enum h8300_operand_class op1_class
, op2_class
;
2283 unsigned int size
, immediate_length
;
2285 size
= GET_MODE_SIZE (GET_MODE (op1
));
2286 immediate_length
= (h8300_classify_operand (op1
, size
, &op1_class
)
2287 + h8300_classify_operand (op2
, size
, &op2_class
));
2288 return immediate_length
+ (*table
)[op1_class
- 1][op2_class
];
2291 /* Return the length of a unary instruction such as neg or not given that
2292 its operand is OP. */
2295 h8300_unary_length (rtx op
)
2297 enum h8300_operand_class opclass
;
2298 unsigned int size
, operand_length
;
2300 size
= GET_MODE_SIZE (GET_MODE (op
));
2301 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2308 return (size
== 4 ? 6 : 4);
2310 case H8OP_MEM_ABSOLUTE
:
2311 return operand_length
+ (size
== 4 ? 6 : 4);
2313 case H8OP_MEM_COMPLEX
:
2314 return operand_length
+ 6;
2321 /* Likewise short immediate instructions such as add.w #xx:3,OP. */
2324 h8300_short_immediate_length (rtx op
)
2326 enum h8300_operand_class opclass
;
2327 unsigned int size
, operand_length
;
2329 size
= GET_MODE_SIZE (GET_MODE (op
));
2330 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2338 case H8OP_MEM_ABSOLUTE
:
2339 case H8OP_MEM_COMPLEX
:
2340 return 4 + operand_length
;
2347 /* Likewise bitfield load and store instructions. */
2350 h8300_bitfield_length (rtx op
, rtx op2
)
2352 enum h8300_operand_class opclass
;
2353 unsigned int size
, operand_length
;
2355 if (GET_CODE (op
) == REG
)
2357 gcc_assert (GET_CODE (op
) != REG
);
2359 size
= GET_MODE_SIZE (GET_MODE (op
));
2360 operand_length
= h8300_classify_operand (op
, size
, &opclass
);
2365 case H8OP_MEM_ABSOLUTE
:
2366 case H8OP_MEM_COMPLEX
:
2367 return 4 + operand_length
;
2374 /* Calculate the length of general binary instruction INSN using TABLE. */
2377 h8300_binary_length (rtx insn
, const h8300_length_table
*table
)
2381 set
= single_set (insn
);
2384 if (BINARY_P (SET_SRC (set
)))
2385 return h8300_length_from_table (XEXP (SET_SRC (set
), 0),
2386 XEXP (SET_SRC (set
), 1), table
);
2389 gcc_assert (GET_RTX_CLASS (GET_CODE (SET_SRC (set
))) == RTX_TERNARY
);
2390 return h8300_length_from_table (XEXP (XEXP (SET_SRC (set
), 1), 0),
2391 XEXP (XEXP (SET_SRC (set
), 1), 1),
2396 /* Subroutine of h8300_move_length. Return true if OP is 1- or 2-byte
2397 memory reference and either (1) it has the form @(d:16,Rn) or
2398 (2) its address has the code given by INC_CODE. */
2401 h8300_short_move_mem_p (rtx op
, enum rtx_code inc_code
)
2406 if (GET_CODE (op
) != MEM
)
2409 addr
= XEXP (op
, 0);
2410 size
= GET_MODE_SIZE (GET_MODE (op
));
2411 if (size
!= 1 && size
!= 2)
2414 return (GET_CODE (addr
) == inc_code
2415 || (GET_CODE (addr
) == PLUS
2416 && GET_CODE (XEXP (addr
, 0)) == REG
2417 && h8300_displacement_length (addr
, size
) == 2));
2420 /* Calculate the length of move instruction INSN using the given length
2421 table. Although the tables are correct for most cases, there is some
2422 irregularity in the length of mov.b and mov.w. The following forms:
2429 are two bytes shorter than most other "mov Rs, @complex" or
2430 "mov @complex,Rd" combinations. */
2433 h8300_move_length (rtx
*operands
, const h8300_length_table
*table
)
2437 size
= h8300_length_from_table (operands
[0], operands
[1], table
);
2438 if (REG_P (operands
[0]) && h8300_short_move_mem_p (operands
[1], POST_INC
))
2440 if (REG_P (operands
[1]) && h8300_short_move_mem_p (operands
[0], PRE_DEC
))
2445 /* Return the length of a mova instruction with the given operands.
2446 DEST is the register destination, SRC is the source address and
2447 OFFSET is the 16-bit or 32-bit displacement. */
2450 h8300_mova_length (rtx dest
, rtx src
, rtx offset
)
2455 + h8300_constant_length (offset
)
2456 + h8300_classify_operand (src
, GET_MODE_SIZE (GET_MODE (src
)), 0));
2457 if (!REG_P (dest
) || !REG_P (src
) || REGNO (src
) != REGNO (dest
))
2462 /* Compute the length of INSN based on its length_table attribute.
2463 OPERANDS is the array of its operands. */
2466 h8300_insn_length_from_table (rtx insn
, rtx
* operands
)
2468 switch (get_attr_length_table (insn
))
2470 case LENGTH_TABLE_NONE
:
2473 case LENGTH_TABLE_ADDB
:
2474 return h8300_binary_length (insn
, &addb_length_table
);
2476 case LENGTH_TABLE_ADDW
:
2477 return h8300_binary_length (insn
, &addw_length_table
);
2479 case LENGTH_TABLE_ADDL
:
2480 return h8300_binary_length (insn
, &addl_length_table
);
2482 case LENGTH_TABLE_LOGICB
:
2483 return h8300_binary_length (insn
, &logicb_length_table
);
2485 case LENGTH_TABLE_MOVB
:
2486 return h8300_move_length (operands
, &movb_length_table
);
2488 case LENGTH_TABLE_MOVW
:
2489 return h8300_move_length (operands
, &movw_length_table
);
2491 case LENGTH_TABLE_MOVL
:
2492 return h8300_move_length (operands
, &movl_length_table
);
2494 case LENGTH_TABLE_MOVA
:
2495 return h8300_mova_length (operands
[0], operands
[1], operands
[2]);
2497 case LENGTH_TABLE_MOVA_ZERO
:
2498 return h8300_mova_length (operands
[0], operands
[1], const0_rtx
);
2500 case LENGTH_TABLE_UNARY
:
2501 return h8300_unary_length (operands
[0]);
2503 case LENGTH_TABLE_MOV_IMM4
:
2504 return 2 + h8300_classify_operand (operands
[0], 0, 0);
2506 case LENGTH_TABLE_SHORT_IMMEDIATE
:
2507 return h8300_short_immediate_length (operands
[0]);
2509 case LENGTH_TABLE_BITFIELD
:
2510 return h8300_bitfield_length (operands
[0], operands
[1]);
2512 case LENGTH_TABLE_BITBRANCH
:
2513 return h8300_bitfield_length (operands
[1], operands
[2]) - 2;
2520 /* Return true if LHS and RHS are memory references that can be mapped
2521 to the same h8sx assembly operand. LHS appears as the destination of
2522 an instruction and RHS appears as a source.
2524 Three cases are allowed:
2526 - RHS is @+Rn or @-Rn, LHS is @Rn
2527 - RHS is @Rn, LHS is @Rn+ or @Rn-
2528 - RHS and LHS have the same address and neither has side effects. */
2531 h8sx_mergeable_memrefs_p (rtx lhs
, rtx rhs
)
2533 if (GET_CODE (rhs
) == MEM
&& GET_CODE (lhs
) == MEM
)
2535 rhs
= XEXP (rhs
, 0);
2536 lhs
= XEXP (lhs
, 0);
2538 if (GET_CODE (rhs
) == PRE_INC
|| GET_CODE (rhs
) == PRE_DEC
)
2539 return rtx_equal_p (XEXP (rhs
, 0), lhs
);
2541 if (GET_CODE (lhs
) == POST_INC
|| GET_CODE (lhs
) == POST_DEC
)
2542 return rtx_equal_p (rhs
, XEXP (lhs
, 0));
2544 if (rtx_equal_p (rhs
, lhs
))
2550 /* Return true if OPERANDS[1] can be mapped to the same assembly
2551 operand as OPERANDS[0]. */
2554 h8300_operands_match_p (rtx
*operands
)
2556 if (register_operand (operands
[0], VOIDmode
)
2557 && register_operand (operands
[1], VOIDmode
))
2560 if (h8sx_mergeable_memrefs_p (operands
[0], operands
[1]))
2566 /* Try using movmd to move LENGTH bytes from memory region SRC to memory
2567 region DEST. The two regions do not overlap and have the common
2568 alignment given by ALIGNMENT. Return true on success.
2570 Using movmd for variable-length moves seems to involve some
2571 complex trade-offs. For instance:
2573 - Preparing for a movmd instruction is similar to preparing
2574 for a memcpy. The main difference is that the arguments
2575 are moved into er4, er5 and er6 rather than er0, er1 and er2.
2577 - Since movmd clobbers the frame pointer, we need to save
2578 and restore it somehow when frame_pointer_needed. This can
2579 sometimes make movmd sequences longer than calls to memcpy().
2581 - The counter register is 16 bits, so the instruction is only
2582 suitable for variable-length moves when sizeof (size_t) == 2.
2583 That's only true in normal mode.
2585 - We will often lack static alignment information. Falling back
2586 on movmd.b would likely be slower than calling memcpy(), at least
2589 This function therefore only uses movmd when the length is a
2590 known constant, and only then if -fomit-frame-pointer is in
2591 effect or if we're not optimizing for size.
2593 At the moment the function uses movmd for all in-range constants,
2594 but it might be better to fall back on memcpy() for large moves
2595 if ALIGNMENT == 1. */
2598 h8sx_emit_movmd (rtx dest
, rtx src
, rtx length
,
2599 HOST_WIDE_INT alignment
)
2601 if (!flag_omit_frame_pointer
&& optimize_size
)
2604 if (GET_CODE (length
) == CONST_INT
)
2606 rtx dest_reg
, src_reg
, first_dest
, first_src
;
2610 /* Use movmd.l if the alignment allows it, otherwise fall back
2612 factor
= (alignment
>= 2 ? 4 : 1);
2614 /* Make sure the length is within range. We can handle counter
2615 values up to 65536, although HImode truncation will make
2616 the count appear negative in rtl dumps. */
2617 n
= INTVAL (length
);
2618 if (n
<= 0 || n
/ factor
> 65536)
2621 /* Create temporary registers for the source and destination
2622 pointers. Initialize them to the start of each region. */
2623 dest_reg
= copy_addr_to_reg (XEXP (dest
, 0));
2624 src_reg
= copy_addr_to_reg (XEXP (src
, 0));
2626 /* Create references to the movmd source and destination blocks. */
2627 first_dest
= replace_equiv_address (dest
, dest_reg
);
2628 first_src
= replace_equiv_address (src
, src_reg
);
2630 set_mem_size (first_dest
, GEN_INT (n
& -factor
));
2631 set_mem_size (first_src
, GEN_INT (n
& -factor
));
2633 length
= copy_to_mode_reg (HImode
, gen_int_mode (n
/ factor
, HImode
));
2634 emit_insn (gen_movmd (first_dest
, first_src
, length
, GEN_INT (factor
)));
2636 if ((n
& -factor
) != n
)
2638 /* Move SRC and DEST past the region we just copied.
2639 This is done to update the memory attributes. */
2640 dest
= adjust_address (dest
, BLKmode
, n
& -factor
);
2641 src
= adjust_address (src
, BLKmode
, n
& -factor
);
2643 /* Replace the addresses with the source and destination
2644 registers, which movmd has left with the right values. */
2645 dest
= replace_equiv_address (dest
, dest_reg
);
2646 src
= replace_equiv_address (src
, src_reg
);
2648 /* Mop up the left-over bytes. */
2650 emit_move_insn (adjust_address (dest
, HImode
, 0),
2651 adjust_address (src
, HImode
, 0));
2653 emit_move_insn (adjust_address (dest
, QImode
, n
& 2),
2654 adjust_address (src
, QImode
, n
& 2));
2661 /* Move ADDR into er6 after pushing its old value onto the stack. */
2664 h8300_swap_into_er6 (rtx addr
)
2666 push (HARD_FRAME_POINTER_REGNUM
);
2667 emit_move_insn (hard_frame_pointer_rtx
, addr
);
2668 if (REGNO (addr
) == SP_REG
)
2669 emit_move_insn (hard_frame_pointer_rtx
,
2670 plus_constant (hard_frame_pointer_rtx
,
2671 GET_MODE_SIZE (word_mode
)));
2674 /* Move the current value of er6 into ADDR and pop its old value
2678 h8300_swap_out_of_er6 (rtx addr
)
2680 if (REGNO (addr
) != SP_REG
)
2681 emit_move_insn (addr
, hard_frame_pointer_rtx
);
2682 pop (HARD_FRAME_POINTER_REGNUM
);
2685 /* Return the length of mov instruction. */
2688 compute_mov_length (rtx
*operands
)
2690 /* If the mov instruction involves a memory operand, we compute the
2691 length, assuming the largest addressing mode is used, and then
2692 adjust later in the function. Otherwise, we compute and return
2693 the exact length in one step. */
2694 enum machine_mode mode
= GET_MODE (operands
[0]);
2695 rtx dest
= operands
[0];
2696 rtx src
= operands
[1];
2699 if (GET_CODE (src
) == MEM
)
2700 addr
= XEXP (src
, 0);
2701 else if (GET_CODE (dest
) == MEM
)
2702 addr
= XEXP (dest
, 0);
2708 unsigned int base_length
;
2713 if (addr
== NULL_RTX
)
2716 /* The eightbit addressing is available only in QImode, so
2717 go ahead and take care of it. */
2718 if (h8300_eightbit_constant_address_p (addr
))
2725 if (addr
== NULL_RTX
)
2730 if (src
== const0_rtx
)
2740 if (addr
== NULL_RTX
)
2745 if (GET_CODE (src
) == CONST_INT
)
2747 if (src
== const0_rtx
)
2750 if ((INTVAL (src
) & 0xffff) == 0)
2753 if ((INTVAL (src
) & 0xffff) == 0)
2756 if ((INTVAL (src
) & 0xffff)
2757 == ((INTVAL (src
) >> 16) & 0xffff))
2767 if (addr
== NULL_RTX
)
2772 if (CONST_DOUBLE_OK_FOR_LETTER_P (src
, 'G'))
2785 /* Adjust the length based on the addressing mode used.
2786 Specifically, we subtract the difference between the actual
2787 length and the longest one, which is @(d:16,Rs). For SImode
2788 and SFmode, we double the adjustment because two mov.w are
2789 used to do the job. */
2791 /* @Rs+ and @-Rd are 2 bytes shorter than the longest. */
2792 if (GET_CODE (addr
) == PRE_DEC
2793 || GET_CODE (addr
) == POST_INC
)
2795 if (mode
== QImode
|| mode
== HImode
)
2796 return base_length
- 2;
2798 /* In SImode and SFmode, we use two mov.w instructions, so
2799 double the adjustment. */
2800 return base_length
- 4;
2803 /* @Rs and @Rd are 2 bytes shorter than the longest. Note that
2804 in SImode and SFmode, the second mov.w involves an address
2805 with displacement, namely @(2,Rs) or @(2,Rd), so we subtract
2807 if (GET_CODE (addr
) == REG
)
2808 return base_length
- 2;
2814 unsigned int base_length
;
2819 if (addr
== NULL_RTX
)
2822 /* The eightbit addressing is available only in QImode, so
2823 go ahead and take care of it. */
2824 if (h8300_eightbit_constant_address_p (addr
))
2831 if (addr
== NULL_RTX
)
2836 if (src
== const0_rtx
)
2846 if (addr
== NULL_RTX
)
2850 if (REGNO (src
) == MAC_REG
|| REGNO (dest
) == MAC_REG
)
2856 if (GET_CODE (src
) == CONST_INT
)
2858 int val
= INTVAL (src
);
2863 if (val
== (val
& 0x00ff) || val
== (val
& 0xff00))
2866 switch (val
& 0xffffffff)
2887 if (addr
== NULL_RTX
)
2892 if (CONST_DOUBLE_OK_FOR_LETTER_P (src
, 'G'))
2905 /* Adjust the length based on the addressing mode used.
2906 Specifically, we subtract the difference between the actual
2907 length and the longest one, which is @(d:24,ERs). */
2909 /* @ERs+ and @-ERd are 6 bytes shorter than the longest. */
2910 if (GET_CODE (addr
) == PRE_DEC
2911 || GET_CODE (addr
) == POST_INC
)
2912 return base_length
- 6;
2914 /* @ERs and @ERd are 6 bytes shorter than the longest. */
2915 if (GET_CODE (addr
) == REG
)
2916 return base_length
- 6;
2918 /* @(d:16,ERs) and @(d:16,ERd) are 4 bytes shorter than the
2920 if (GET_CODE (addr
) == PLUS
2921 && GET_CODE (XEXP (addr
, 0)) == REG
2922 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
2923 && INTVAL (XEXP (addr
, 1)) > -32768
2924 && INTVAL (XEXP (addr
, 1)) < 32767)
2925 return base_length
- 4;
2927 /* @aa:16 is 4 bytes shorter than the longest. */
2928 if (h8300_tiny_constant_address_p (addr
))
2929 return base_length
- 4;
2931 /* @aa:24 is 2 bytes shorter than the longest. */
2932 if (CONSTANT_P (addr
))
2933 return base_length
- 2;
2939 /* Output an addition insn. */
2942 output_plussi (rtx
*operands
)
2944 enum machine_mode mode
= GET_MODE (operands
[0]);
2946 gcc_assert (mode
== SImode
);
2950 if (GET_CODE (operands
[2]) == REG
)
2951 return "add.w\t%f2,%f0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
2953 if (GET_CODE (operands
[2]) == CONST_INT
)
2955 HOST_WIDE_INT n
= INTVAL (operands
[2]);
2957 if ((n
& 0xffffff) == 0)
2958 return "add\t%z2,%z0";
2959 if ((n
& 0xffff) == 0)
2960 return "add\t%y2,%y0\n\taddx\t%z2,%z0";
2961 if ((n
& 0xff) == 0)
2962 return "add\t%x2,%x0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
2965 return "add\t%w2,%w0\n\taddx\t%x2,%x0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
2969 if (GET_CODE (operands
[2]) == CONST_INT
2970 && register_operand (operands
[1], VOIDmode
))
2972 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
2974 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
2975 return "add.l\t%S2,%S0";
2976 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
2977 return "sub.l\t%G2,%S0";
2979 /* See if we can finish with 2 bytes. */
2981 switch ((unsigned int) intval
& 0xffffffff)
2986 return "adds\t%2,%S0";
2991 return "subs\t%G2,%S0";
2995 operands
[2] = GEN_INT (intval
>> 16);
2996 return "inc.w\t%2,%e0";
3000 operands
[2] = GEN_INT (intval
>> 16);
3001 return "dec.w\t%G2,%e0";
3004 /* See if we can finish with 4 bytes. */
3005 if ((intval
& 0xffff) == 0)
3007 operands
[2] = GEN_INT (intval
>> 16);
3008 return "add.w\t%2,%e0";
3012 if (GET_CODE (operands
[2]) == CONST_INT
&& INTVAL (operands
[2]) < 0)
3014 operands
[2] = GEN_INT (-INTVAL (operands
[2]));
3015 return "sub.l\t%S2,%S0";
3017 return "add.l\t%S2,%S0";
3021 /* ??? It would be much easier to add the h8sx stuff if a single function
3022 classified the addition as either inc/dec, adds/subs, add.w or add.l. */
3023 /* Compute the length of an addition insn. */
3026 compute_plussi_length (rtx
*operands
)
3028 enum machine_mode mode
= GET_MODE (operands
[0]);
3030 gcc_assert (mode
== SImode
);
3034 if (GET_CODE (operands
[2]) == REG
)
3037 if (GET_CODE (operands
[2]) == CONST_INT
)
3039 HOST_WIDE_INT n
= INTVAL (operands
[2]);
3041 if ((n
& 0xffffff) == 0)
3043 if ((n
& 0xffff) == 0)
3045 if ((n
& 0xff) == 0)
3053 if (GET_CODE (operands
[2]) == CONST_INT
3054 && register_operand (operands
[1], VOIDmode
))
3056 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3058 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3060 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3063 /* See if we can finish with 2 bytes. */
3065 switch ((unsigned int) intval
& 0xffffffff)
3086 /* See if we can finish with 4 bytes. */
3087 if ((intval
& 0xffff) == 0)
3091 if (GET_CODE (operands
[2]) == CONST_INT
&& INTVAL (operands
[2]) < 0)
3092 return h8300_length_from_table (operands
[0],
3093 GEN_INT (-INTVAL (operands
[2])),
3094 &addl_length_table
);
3096 return h8300_length_from_table (operands
[0], operands
[2],
3097 &addl_length_table
);
3102 /* Compute which flag bits are valid after an addition insn. */
3105 compute_plussi_cc (rtx
*operands
)
3107 enum machine_mode mode
= GET_MODE (operands
[0]);
3109 gcc_assert (mode
== SImode
);
3117 if (GET_CODE (operands
[2]) == CONST_INT
3118 && register_operand (operands
[1], VOIDmode
))
3120 HOST_WIDE_INT intval
= INTVAL (operands
[2]);
3122 if (TARGET_H8300SX
&& (intval
>= 1 && intval
<= 7))
3124 if (TARGET_H8300SX
&& (intval
>= -7 && intval
<= -1))
3127 /* See if we can finish with 2 bytes. */
3129 switch ((unsigned int) intval
& 0xffffffff)
3134 return CC_NONE_0HIT
;
3139 return CC_NONE_0HIT
;
3150 /* See if we can finish with 4 bytes. */
3151 if ((intval
& 0xffff) == 0)
3159 /* Output a logical insn. */
3162 output_logical_op (enum machine_mode mode
, rtx
*operands
)
3164 /* Figure out the logical op that we need to perform. */
3165 enum rtx_code code
= GET_CODE (operands
[3]);
3166 /* Pretend that every byte is affected if both operands are registers. */
3167 const unsigned HOST_WIDE_INT intval
=
3168 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3169 /* Always use the full instruction if the
3170 first operand is in memory. It is better
3171 to use define_splits to generate the shorter
3172 sequence where valid. */
3173 && register_operand (operands
[1], VOIDmode
)
3174 ? INTVAL (operands
[2]) : 0x55555555);
3175 /* The determinant of the algorithm. If we perform an AND, 0
3176 affects a bit. Otherwise, 1 affects a bit. */
3177 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3178 /* Break up DET into pieces. */
3179 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3180 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3181 const unsigned HOST_WIDE_INT b2
= (det
>> 16) & 0xff;
3182 const unsigned HOST_WIDE_INT b3
= (det
>> 24) & 0xff;
3183 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3184 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3185 int lower_half_easy_p
= 0;
3186 int upper_half_easy_p
= 0;
3187 /* The name of an insn. */
3209 /* First, see if we can finish with one insn. */
3210 if ((TARGET_H8300H
|| TARGET_H8300S
)
3214 sprintf (insn_buf
, "%s.w\t%%T2,%%T0", opname
);
3215 output_asm_insn (insn_buf
, operands
);
3219 /* Take care of the lower byte. */
3222 sprintf (insn_buf
, "%s\t%%s2,%%s0", opname
);
3223 output_asm_insn (insn_buf
, operands
);
3225 /* Take care of the upper byte. */
3228 sprintf (insn_buf
, "%s\t%%t2,%%t0", opname
);
3229 output_asm_insn (insn_buf
, operands
);
3234 if (TARGET_H8300H
|| TARGET_H8300S
)
3236 /* Determine if the lower half can be taken care of in no more
3238 lower_half_easy_p
= (b0
== 0
3240 || (code
!= IOR
&& w0
== 0xffff));
3242 /* Determine if the upper half can be taken care of in no more
3244 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3245 || (code
== AND
&& w1
== 0xff00));
3248 /* Check if doing everything with one insn is no worse than
3249 using multiple insns. */
3250 if ((TARGET_H8300H
|| TARGET_H8300S
)
3251 && w0
!= 0 && w1
!= 0
3252 && !(lower_half_easy_p
&& upper_half_easy_p
)
3253 && !(code
== IOR
&& w1
== 0xffff
3254 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3256 sprintf (insn_buf
, "%s.l\t%%S2,%%S0", opname
);
3257 output_asm_insn (insn_buf
, operands
);
3261 /* Take care of the lower and upper words individually. For
3262 each word, we try different methods in the order of
3264 1) the special insn (in case of AND or XOR),
3265 2) the word-wise insn, and
3266 3) The byte-wise insn. */
3268 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3269 output_asm_insn ((code
== AND
)
3270 ? "sub.w\t%f0,%f0" : "not.w\t%f0",
3272 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3276 sprintf (insn_buf
, "%s.w\t%%f2,%%f0", opname
);
3277 output_asm_insn (insn_buf
, operands
);
3283 sprintf (insn_buf
, "%s\t%%w2,%%w0", opname
);
3284 output_asm_insn (insn_buf
, operands
);
3288 sprintf (insn_buf
, "%s\t%%x2,%%x0", opname
);
3289 output_asm_insn (insn_buf
, operands
);
3294 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3295 output_asm_insn ((code
== AND
)
3296 ? "sub.w\t%e0,%e0" : "not.w\t%e0",
3298 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3301 && (w0
& 0x8000) != 0)
3303 output_asm_insn ("exts.l\t%S0", operands
);
3305 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3309 output_asm_insn ("extu.w\t%e0", operands
);
3311 else if (TARGET_H8300H
|| TARGET_H8300S
)
3315 sprintf (insn_buf
, "%s.w\t%%e2,%%e0", opname
);
3316 output_asm_insn (insn_buf
, operands
);
3323 sprintf (insn_buf
, "%s\t%%y2,%%y0", opname
);
3324 output_asm_insn (insn_buf
, operands
);
3328 sprintf (insn_buf
, "%s\t%%z2,%%z0", opname
);
3329 output_asm_insn (insn_buf
, operands
);
3340 /* Compute the length of a logical insn. */
3343 compute_logical_op_length (enum machine_mode mode
, rtx
*operands
)
3345 /* Figure out the logical op that we need to perform. */
3346 enum rtx_code code
= GET_CODE (operands
[3]);
3347 /* Pretend that every byte is affected if both operands are registers. */
3348 const unsigned HOST_WIDE_INT intval
=
3349 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3350 /* Always use the full instruction if the
3351 first operand is in memory. It is better
3352 to use define_splits to generate the shorter
3353 sequence where valid. */
3354 && register_operand (operands
[1], VOIDmode
)
3355 ? INTVAL (operands
[2]) : 0x55555555);
3356 /* The determinant of the algorithm. If we perform an AND, 0
3357 affects a bit. Otherwise, 1 affects a bit. */
3358 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3359 /* Break up DET into pieces. */
3360 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3361 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3362 const unsigned HOST_WIDE_INT b2
= (det
>> 16) & 0xff;
3363 const unsigned HOST_WIDE_INT b3
= (det
>> 24) & 0xff;
3364 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3365 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3366 int lower_half_easy_p
= 0;
3367 int upper_half_easy_p
= 0;
3369 unsigned int length
= 0;
3374 /* First, see if we can finish with one insn. */
3375 if ((TARGET_H8300H
|| TARGET_H8300S
)
3379 length
= h8300_length_from_table (operands
[1], operands
[2],
3380 &logicw_length_table
);
3384 /* Take care of the lower byte. */
3388 /* Take care of the upper byte. */
3394 if (TARGET_H8300H
|| TARGET_H8300S
)
3396 /* Determine if the lower half can be taken care of in no more
3398 lower_half_easy_p
= (b0
== 0
3400 || (code
!= IOR
&& w0
== 0xffff));
3402 /* Determine if the upper half can be taken care of in no more
3404 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3405 || (code
== AND
&& w1
== 0xff00));
3408 /* Check if doing everything with one insn is no worse than
3409 using multiple insns. */
3410 if ((TARGET_H8300H
|| TARGET_H8300S
)
3411 && w0
!= 0 && w1
!= 0
3412 && !(lower_half_easy_p
&& upper_half_easy_p
)
3413 && !(code
== IOR
&& w1
== 0xffff
3414 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3416 length
= h8300_length_from_table (operands
[1], operands
[2],
3417 &logicl_length_table
);
3421 /* Take care of the lower and upper words individually. For
3422 each word, we try different methods in the order of
3424 1) the special insn (in case of AND or XOR),
3425 2) the word-wise insn, and
3426 3) The byte-wise insn. */
3428 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3432 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3448 && (TARGET_H8300
? (code
== AND
) : (code
!= IOR
)))
3452 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3455 && (w0
& 0x8000) != 0)
3459 else if ((TARGET_H8300H
|| TARGET_H8300S
)
3465 else if (TARGET_H8300H
|| TARGET_H8300S
)
3486 /* Compute which flag bits are valid after a logical insn. */
3489 compute_logical_op_cc (enum machine_mode mode
, rtx
*operands
)
3491 /* Figure out the logical op that we need to perform. */
3492 enum rtx_code code
= GET_CODE (operands
[3]);
3493 /* Pretend that every byte is affected if both operands are registers. */
3494 const unsigned HOST_WIDE_INT intval
=
3495 (unsigned HOST_WIDE_INT
) ((GET_CODE (operands
[2]) == CONST_INT
)
3496 /* Always use the full instruction if the
3497 first operand is in memory. It is better
3498 to use define_splits to generate the shorter
3499 sequence where valid. */
3500 && register_operand (operands
[1], VOIDmode
)
3501 ? INTVAL (operands
[2]) : 0x55555555);
3502 /* The determinant of the algorithm. If we perform an AND, 0
3503 affects a bit. Otherwise, 1 affects a bit. */
3504 const unsigned HOST_WIDE_INT det
= (code
!= AND
) ? intval
: ~intval
;
3505 /* Break up DET into pieces. */
3506 const unsigned HOST_WIDE_INT b0
= (det
>> 0) & 0xff;
3507 const unsigned HOST_WIDE_INT b1
= (det
>> 8) & 0xff;
3508 const unsigned HOST_WIDE_INT w0
= (det
>> 0) & 0xffff;
3509 const unsigned HOST_WIDE_INT w1
= (det
>> 16) & 0xffff;
3510 int lower_half_easy_p
= 0;
3511 int upper_half_easy_p
= 0;
3512 /* Condition code. */
3513 enum attr_cc cc
= CC_CLOBBER
;
3518 /* First, see if we can finish with one insn. */
3519 if ((TARGET_H8300H
|| TARGET_H8300S
)
3527 if (TARGET_H8300H
|| TARGET_H8300S
)
3529 /* Determine if the lower half can be taken care of in no more
3531 lower_half_easy_p
= (b0
== 0
3533 || (code
!= IOR
&& w0
== 0xffff));
3535 /* Determine if the upper half can be taken care of in no more
3537 upper_half_easy_p
= ((code
!= IOR
&& w1
== 0xffff)
3538 || (code
== AND
&& w1
== 0xff00));
3541 /* Check if doing everything with one insn is no worse than
3542 using multiple insns. */
3543 if ((TARGET_H8300H
|| TARGET_H8300S
)
3544 && w0
!= 0 && w1
!= 0
3545 && !(lower_half_easy_p
&& upper_half_easy_p
)
3546 && !(code
== IOR
&& w1
== 0xffff
3547 && (w0
& 0x8000) != 0 && lower_half_easy_p
))
3553 if ((TARGET_H8300H
|| TARGET_H8300S
)
3556 && (w0
& 0x8000) != 0)
3568 /* Expand a conditional branch. */
3571 h8300_expand_branch (rtx operands
[])
3573 enum rtx_code code
= GET_CODE (operands
[0]);
3574 rtx op0
= operands
[1];
3575 rtx op1
= operands
[2];
3576 rtx label
= operands
[3];
3579 tmp
= gen_rtx_COMPARE (VOIDmode
, op0
, op1
);
3580 emit_insn (gen_rtx_SET (VOIDmode
, cc0_rtx
, tmp
));
3582 tmp
= gen_rtx_fmt_ee (code
, VOIDmode
, cc0_rtx
, const0_rtx
);
3583 tmp
= gen_rtx_IF_THEN_ELSE (VOIDmode
, tmp
,
3584 gen_rtx_LABEL_REF (VOIDmode
, label
),
3586 emit_jump_insn (gen_rtx_SET (VOIDmode
, pc_rtx
, tmp
));
3590 /* Expand a conditional store. */
3593 h8300_expand_store (rtx operands
[])
3595 rtx dest
= operands
[0];
3596 enum rtx_code code
= GET_CODE (operands
[1]);
3597 rtx op0
= operands
[2];
3598 rtx op1
= operands
[3];
3601 tmp
= gen_rtx_COMPARE (VOIDmode
, op0
, op1
);
3602 emit_insn (gen_rtx_SET (VOIDmode
, cc0_rtx
, tmp
));
3604 tmp
= gen_rtx_fmt_ee (code
, GET_MODE (dest
), cc0_rtx
, const0_rtx
);
3605 emit_insn (gen_rtx_SET (VOIDmode
, dest
, tmp
));
3610 We devote a fair bit of code to getting efficient shifts since we
3611 can only shift one bit at a time on the H8/300 and H8/300H and only
3612 one or two bits at a time on the H8S.
3614 All shift code falls into one of the following ways of
3617 o SHIFT_INLINE: Emit straight line code for the shift; this is used
3618 when a straight line shift is about the same size or smaller than
3621 o SHIFT_ROT_AND: Rotate the value the opposite direction, then mask
3622 off the bits we don't need. This is used when only a few of the
3623 bits in the original value will survive in the shifted value.
3625 o SHIFT_SPECIAL: Often it's possible to move a byte or a word to
3626 simulate a shift by 8, 16, or 24 bits. Once moved, a few inline
3627 shifts can be added if the shift count is slightly more than 8 or
3628 16. This case also includes other oddballs that are not worth
3631 o SHIFT_LOOP: Emit a loop using one (or two on H8S) bit shifts.
3633 For each shift count, we try to use code that has no trade-off
3634 between code size and speed whenever possible.
3636 If the trade-off is unavoidable, we try to be reasonable.
3637 Specifically, the fastest version is one instruction longer than
3638 the shortest version, we take the fastest version. We also provide
3639 the use a way to switch back to the shortest version with -Os.
3641 For the details of the shift algorithms for various shift counts,
3642 refer to shift_alg_[qhs]i. */
3644 /* Classify a shift with the given mode and code. OP is the shift amount. */
3646 enum h8sx_shift_type
3647 h8sx_classify_shift (enum machine_mode mode
, enum rtx_code code
, rtx op
)
3649 if (!TARGET_H8300SX
)
3650 return H8SX_SHIFT_NONE
;
3656 /* Check for variable shifts (shll Rs,Rd and shlr Rs,Rd). */
3657 if (GET_CODE (op
) != CONST_INT
)
3658 return H8SX_SHIFT_BINARY
;
3660 /* Reject out-of-range shift amounts. */
3661 if (INTVAL (op
) <= 0 || INTVAL (op
) >= GET_MODE_BITSIZE (mode
))
3662 return H8SX_SHIFT_NONE
;
3664 /* Power-of-2 shifts are effectively unary operations. */
3665 if (exact_log2 (INTVAL (op
)) >= 0)
3666 return H8SX_SHIFT_UNARY
;
3668 return H8SX_SHIFT_BINARY
;
3671 if (op
== const1_rtx
|| op
== const2_rtx
)
3672 return H8SX_SHIFT_UNARY
;
3673 return H8SX_SHIFT_NONE
;
3676 if (GET_CODE (op
) == CONST_INT
3677 && (INTVAL (op
) == 1
3679 || INTVAL (op
) == GET_MODE_BITSIZE (mode
) - 2
3680 || INTVAL (op
) == GET_MODE_BITSIZE (mode
) - 1))
3681 return H8SX_SHIFT_UNARY
;
3682 return H8SX_SHIFT_NONE
;
3685 return H8SX_SHIFT_NONE
;
3689 /* Return the asm template for a single h8sx shift instruction.
3690 OPERANDS[0] and OPERANDS[1] are the destination, OPERANDS[2]
3691 is the source and OPERANDS[3] is the shift. SUFFIX is the
3692 size suffix ('b', 'w' or 'l') and OPTYPE is the print_operand
3693 prefix for the destination operand. */
3696 output_h8sx_shift (rtx
*operands
, int suffix
, int optype
)
3698 static char buffer
[16];
3701 switch (GET_CODE (operands
[3]))
3717 if (INTVAL (operands
[2]) > 2)
3719 /* This is really a right rotate. */
3720 operands
[2] = GEN_INT (GET_MODE_BITSIZE (GET_MODE (operands
[0]))
3721 - INTVAL (operands
[2]));
3729 if (operands
[2] == const1_rtx
)
3730 sprintf (buffer
, "%s.%c\t%%%c0", stem
, suffix
, optype
);
3732 sprintf (buffer
, "%s.%c\t%%X2,%%%c0", stem
, suffix
, optype
);
3736 /* Emit code to do shifts. */
3739 expand_a_shift (enum machine_mode mode
, int code
, rtx operands
[])
3741 switch (h8sx_classify_shift (mode
, code
, operands
[2]))
3743 case H8SX_SHIFT_BINARY
:
3744 operands
[1] = force_reg (mode
, operands
[1]);
3747 case H8SX_SHIFT_UNARY
:
3750 case H8SX_SHIFT_NONE
:
3754 emit_move_insn (copy_rtx (operands
[0]), operands
[1]);
3756 /* Need a loop to get all the bits we want - we generate the
3757 code at emit time, but need to allocate a scratch reg now. */
3759 emit_insn (gen_rtx_PARALLEL
3762 gen_rtx_SET (VOIDmode
, copy_rtx (operands
[0]),
3763 gen_rtx_fmt_ee (code
, mode
,
3764 copy_rtx (operands
[0]), operands
[2])),
3765 gen_rtx_CLOBBER (VOIDmode
,
3766 gen_rtx_SCRATCH (QImode
)))));
3770 /* Symbols of the various modes which can be used as indices. */
3774 QIshift
, HIshift
, SIshift
3777 /* For single bit shift insns, record assembler and what bits of the
3778 condition code are valid afterwards (represented as various CC_FOO
3779 bits, 0 means CC isn't left in a usable state). */
3783 const char *const assembler
;
3787 /* Assembler instruction shift table.
3789 These tables are used to look up the basic shifts.
3790 They are indexed by cpu, shift_type, and mode. */
3792 static const struct shift_insn shift_one
[2][3][3] =
3798 { "shll\t%X0", CC_SET_ZNV
},
3799 { "add.w\t%T0,%T0", CC_SET_ZN
},
3800 { "add.w\t%f0,%f0\n\taddx\t%y0,%y0\n\taddx\t%z0,%z0", CC_CLOBBER
}
3802 /* SHIFT_LSHIFTRT */
3804 { "shlr\t%X0", CC_SET_ZNV
},
3805 { "shlr\t%t0\n\trotxr\t%s0", CC_CLOBBER
},
3806 { "shlr\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", CC_CLOBBER
}
3808 /* SHIFT_ASHIFTRT */
3810 { "shar\t%X0", CC_SET_ZNV
},
3811 { "shar\t%t0\n\trotxr\t%s0", CC_CLOBBER
},
3812 { "shar\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", CC_CLOBBER
}
3819 { "shll.b\t%X0", CC_SET_ZNV
},
3820 { "shll.w\t%T0", CC_SET_ZNV
},
3821 { "shll.l\t%S0", CC_SET_ZNV
}
3823 /* SHIFT_LSHIFTRT */
3825 { "shlr.b\t%X0", CC_SET_ZNV
},
3826 { "shlr.w\t%T0", CC_SET_ZNV
},
3827 { "shlr.l\t%S0", CC_SET_ZNV
}
3829 /* SHIFT_ASHIFTRT */
3831 { "shar.b\t%X0", CC_SET_ZNV
},
3832 { "shar.w\t%T0", CC_SET_ZNV
},
3833 { "shar.l\t%S0", CC_SET_ZNV
}
3838 static const struct shift_insn shift_two
[3][3] =
3842 { "shll.b\t#2,%X0", CC_SET_ZNV
},
3843 { "shll.w\t#2,%T0", CC_SET_ZNV
},
3844 { "shll.l\t#2,%S0", CC_SET_ZNV
}
3846 /* SHIFT_LSHIFTRT */
3848 { "shlr.b\t#2,%X0", CC_SET_ZNV
},
3849 { "shlr.w\t#2,%T0", CC_SET_ZNV
},
3850 { "shlr.l\t#2,%S0", CC_SET_ZNV
}
3852 /* SHIFT_ASHIFTRT */
3854 { "shar.b\t#2,%X0", CC_SET_ZNV
},
3855 { "shar.w\t#2,%T0", CC_SET_ZNV
},
3856 { "shar.l\t#2,%S0", CC_SET_ZNV
}
3860 /* Rotates are organized by which shift they'll be used in implementing.
3861 There's no need to record whether the cc is valid afterwards because
3862 it is the AND insn that will decide this. */
3864 static const char *const rotate_one
[2][3][3] =
3871 "shlr\t%t0\n\trotxr\t%s0\n\tbst\t#7,%t0",
3874 /* SHIFT_LSHIFTRT */
3877 "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
3880 /* SHIFT_ASHIFTRT */
3883 "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
3895 /* SHIFT_LSHIFTRT */
3901 /* SHIFT_ASHIFTRT */
3910 static const char *const rotate_two
[3][3] =
3918 /* SHIFT_LSHIFTRT */
3924 /* SHIFT_ASHIFTRT */
3933 /* Shift algorithm. */
3936 /* The number of bits to be shifted by shift1 and shift2. Valid
3937 when ALG is SHIFT_SPECIAL. */
3938 unsigned int remainder
;
3940 /* Special insn for a shift. Valid when ALG is SHIFT_SPECIAL. */
3941 const char *special
;
3943 /* Insn for a one-bit shift. Valid when ALG is either SHIFT_INLINE
3944 or SHIFT_SPECIAL, and REMAINDER is nonzero. */
3947 /* Insn for a two-bit shift. Valid when ALG is either SHIFT_INLINE
3948 or SHIFT_SPECIAL, and REMAINDER is nonzero. */
3951 /* CC status for SHIFT_INLINE. */
3954 /* CC status for SHIFT_SPECIAL. */
3958 static void get_shift_alg (enum shift_type
,
3959 enum shift_mode
, unsigned int,
3960 struct shift_info
*);
3962 /* Given SHIFT_TYPE, SHIFT_MODE, and shift count COUNT, determine the
3963 best algorithm for doing the shift. The assembler code is stored
3964 in the pointers in INFO. We achieve the maximum efficiency in most
3965 cases when !TARGET_H8300. In case of TARGET_H8300, shifts in
3966 SImode in particular have a lot of room to optimize.
3968 We first determine the strategy of the shift algorithm by a table
3969 lookup. If that tells us to use a hand crafted assembly code, we
3970 go into the big switch statement to find what that is. Otherwise,
3971 we resort to a generic way, such as inlining. In either case, the
3972 result is returned through INFO. */
3975 get_shift_alg (enum shift_type shift_type
, enum shift_mode shift_mode
,
3976 unsigned int count
, struct shift_info
*info
)
3980 /* Find the target CPU. */
3983 else if (TARGET_H8300H
)
3988 /* Find the shift algorithm. */
3989 info
->alg
= SHIFT_LOOP
;
3993 if (count
< GET_MODE_BITSIZE (QImode
))
3994 info
->alg
= shift_alg_qi
[cpu
][shift_type
][count
];
3998 if (count
< GET_MODE_BITSIZE (HImode
))
3999 info
->alg
= shift_alg_hi
[cpu
][shift_type
][count
];
4003 if (count
< GET_MODE_BITSIZE (SImode
))
4004 info
->alg
= shift_alg_si
[cpu
][shift_type
][count
];
4011 /* Fill in INFO. Return unless we have SHIFT_SPECIAL. */
4015 info
->remainder
= count
;
4019 /* It is up to the caller to know that looping clobbers cc. */
4020 info
->shift1
= shift_one
[cpu_type
][shift_type
][shift_mode
].assembler
;
4021 info
->shift2
= shift_two
[shift_type
][shift_mode
].assembler
;
4022 info
->cc_inline
= shift_one
[cpu_type
][shift_type
][shift_mode
].cc_valid
;
4026 info
->shift1
= rotate_one
[cpu_type
][shift_type
][shift_mode
];
4027 info
->shift2
= rotate_two
[shift_type
][shift_mode
];
4028 info
->cc_inline
= CC_CLOBBER
;
4032 /* REMAINDER is 0 for most cases, so initialize it to 0. */
4033 info
->remainder
= 0;
4034 info
->shift1
= shift_one
[cpu_type
][shift_type
][shift_mode
].assembler
;
4035 info
->shift2
= shift_two
[shift_type
][shift_mode
].assembler
;
4036 info
->cc_inline
= shift_one
[cpu_type
][shift_type
][shift_mode
].cc_valid
;
4037 info
->cc_special
= CC_CLOBBER
;
4041 /* Here we only deal with SHIFT_SPECIAL. */
4045 /* For ASHIFTRT by 7 bits, the sign bit is simply replicated
4046 through the entire value. */
4047 gcc_assert (shift_type
== SHIFT_ASHIFTRT
&& count
== 7);
4048 info
->special
= "shll\t%X0\n\tsubx\t%X0,%X0";
4058 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";
4060 info
->special
= "shar.b\t%t0\n\tmov.b\t%s0,%t0\n\trotxr.w\t%T0\n\tand.b\t#0x80,%s0";
4062 case SHIFT_LSHIFTRT
:
4064 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";
4066 info
->special
= "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.w\t%T0\n\tand.b\t#0x01,%t0";
4068 case SHIFT_ASHIFTRT
:
4069 info
->special
= "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.b\t%s0\n\tsubx\t%t0,%t0";
4073 else if ((8 <= count
&& count
<= 13)
4074 || (TARGET_H8300S
&& count
== 14))
4076 info
->remainder
= count
- 8;
4081 info
->special
= "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0";
4083 case SHIFT_LSHIFTRT
:
4086 info
->special
= "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0";
4087 info
->shift1
= "shlr.b\t%s0";
4088 info
->cc_inline
= CC_SET_ZNV
;
4092 info
->special
= "mov.b\t%t0,%s0\n\textu.w\t%T0";
4093 info
->cc_special
= CC_SET_ZNV
;
4096 case SHIFT_ASHIFTRT
:
4099 info
->special
= "mov.b\t%t0,%s0\n\tbld\t#7,%s0\n\tsubx\t%t0,%t0";
4100 info
->shift1
= "shar.b\t%s0";
4104 info
->special
= "mov.b\t%t0,%s0\n\texts.w\t%T0";
4105 info
->cc_special
= CC_SET_ZNV
;
4110 else if (count
== 14)
4116 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";
4118 case SHIFT_LSHIFTRT
:
4120 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";
4122 case SHIFT_ASHIFTRT
:
4124 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";
4125 else if (TARGET_H8300H
)
4127 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";
4128 info
->cc_special
= CC_SET_ZNV
;
4130 else /* TARGET_H8300S */
4135 else if (count
== 15)
4140 info
->special
= "bld\t#0,%s0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#7,%t0";
4142 case SHIFT_LSHIFTRT
:
4143 info
->special
= "bld\t#7,%t0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#0,%s0";
4145 case SHIFT_ASHIFTRT
:
4146 info
->special
= "shll\t%t0\n\tsubx\t%t0,%t0\n\tmov.b\t%t0,%s0";
4153 if (TARGET_H8300
&& 8 <= count
&& count
<= 9)
4155 info
->remainder
= count
- 8;
4160 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";
4162 case SHIFT_LSHIFTRT
:
4163 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";
4164 info
->shift1
= "shlr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0";
4166 case SHIFT_ASHIFTRT
:
4167 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";
4171 else if (count
== 8 && !TARGET_H8300
)
4176 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";
4178 case SHIFT_LSHIFTRT
:
4179 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";
4181 case SHIFT_ASHIFTRT
:
4182 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";
4186 else if (count
== 15 && TARGET_H8300
)
4192 case SHIFT_LSHIFTRT
:
4193 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";
4195 case SHIFT_ASHIFTRT
:
4196 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";
4200 else if (count
== 15 && !TARGET_H8300
)
4205 info
->special
= "shlr.w\t%e0\n\tmov.w\t%f0,%e0\n\txor.w\t%f0,%f0\n\trotxr.l\t%S0";
4206 info
->cc_special
= CC_SET_ZNV
;
4208 case SHIFT_LSHIFTRT
:
4209 info
->special
= "shll.w\t%f0\n\tmov.w\t%e0,%f0\n\txor.w\t%e0,%e0\n\trotxl.l\t%S0";
4210 info
->cc_special
= CC_SET_ZNV
;
4212 case SHIFT_ASHIFTRT
:
4216 else if ((TARGET_H8300
&& 16 <= count
&& count
<= 20)
4217 || (TARGET_H8300H
&& 16 <= count
&& count
<= 19)
4218 || (TARGET_H8300S
&& 16 <= count
&& count
<= 21))
4220 info
->remainder
= count
- 16;
4225 info
->special
= "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0";
4227 info
->shift1
= "add.w\t%e0,%e0";
4229 case SHIFT_LSHIFTRT
:
4232 info
->special
= "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0";
4233 info
->shift1
= "shlr\t%x0\n\trotxr\t%w0";
4237 info
->special
= "mov.w\t%e0,%f0\n\textu.l\t%S0";
4238 info
->cc_special
= CC_SET_ZNV
;
4241 case SHIFT_ASHIFTRT
:
4244 info
->special
= "mov.w\t%e0,%f0\n\tshll\t%z0\n\tsubx\t%z0,%z0\n\tmov.b\t%z0,%y0";
4245 info
->shift1
= "shar\t%x0\n\trotxr\t%w0";
4249 info
->special
= "mov.w\t%e0,%f0\n\texts.l\t%S0";
4250 info
->cc_special
= CC_SET_ZNV
;
4255 else if (TARGET_H8300
&& 24 <= count
&& count
<= 28)
4257 info
->remainder
= count
- 24;
4262 info
->special
= "mov.b\t%w0,%z0\n\tsub.b\t%y0,%y0\n\tsub.w\t%f0,%f0";
4263 info
->shift1
= "shll.b\t%z0";
4264 info
->cc_inline
= CC_SET_ZNV
;
4266 case SHIFT_LSHIFTRT
:
4267 info
->special
= "mov.b\t%z0,%w0\n\tsub.b\t%x0,%x0\n\tsub.w\t%e0,%e0";
4268 info
->shift1
= "shlr.b\t%w0";
4269 info
->cc_inline
= CC_SET_ZNV
;
4271 case SHIFT_ASHIFTRT
:
4272 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";
4273 info
->shift1
= "shar.b\t%w0";
4274 info
->cc_inline
= CC_SET_ZNV
;
4278 else if ((TARGET_H8300H
&& count
== 24)
4279 || (TARGET_H8300S
&& 24 <= count
&& count
<= 25))
4281 info
->remainder
= count
- 24;
4286 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";
4288 case SHIFT_LSHIFTRT
:
4289 info
->special
= "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\textu.w\t%f0\n\textu.l\t%S0";
4290 info
->cc_special
= CC_SET_ZNV
;
4292 case SHIFT_ASHIFTRT
:
4293 info
->special
= "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\texts.w\t%f0\n\texts.l\t%S0";
4294 info
->cc_special
= CC_SET_ZNV
;
4298 else if (!TARGET_H8300
&& count
== 28)
4304 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";
4306 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";
4308 case SHIFT_LSHIFTRT
:
4311 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";
4312 info
->cc_special
= CC_SET_ZNV
;
4315 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t#2,%S0\n\textu.l\t%S0";
4317 case SHIFT_ASHIFTRT
:
4321 else if (!TARGET_H8300
&& count
== 29)
4327 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";
4329 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
4331 case SHIFT_LSHIFTRT
:
4334 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";
4335 info
->cc_special
= CC_SET_ZNV
;
4339 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
4340 info
->cc_special
= CC_SET_ZNV
;
4343 case SHIFT_ASHIFTRT
:
4347 else if (!TARGET_H8300
&& count
== 30)
4353 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
4355 info
->special
= "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\tsub.w\t%f0,%f0";
4357 case SHIFT_LSHIFTRT
:
4359 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
4361 info
->special
= "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\textu.l\t%S0";
4363 case SHIFT_ASHIFTRT
:
4367 else if (count
== 31)
4374 info
->special
= "sub.w\t%e0,%e0\n\tshlr\t%w0\n\tmov.w\t%e0,%f0\n\trotxr\t%z0";
4376 case SHIFT_LSHIFTRT
:
4377 info
->special
= "sub.w\t%f0,%f0\n\tshll\t%z0\n\tmov.w\t%f0,%e0\n\trotxl\t%w0";
4379 case SHIFT_ASHIFTRT
:
4380 info
->special
= "shll\t%z0\n\tsubx\t%w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
4389 info
->special
= "shlr.l\t%S0\n\txor.l\t%S0,%S0\n\trotxr.l\t%S0";
4390 info
->cc_special
= CC_SET_ZNV
;
4392 case SHIFT_LSHIFTRT
:
4393 info
->special
= "shll.l\t%S0\n\txor.l\t%S0,%S0\n\trotxl.l\t%S0";
4394 info
->cc_special
= CC_SET_ZNV
;
4396 case SHIFT_ASHIFTRT
:
4397 info
->special
= "shll\t%e0\n\tsubx\t%w0,%w0\n\texts.w\t%T0\n\texts.l\t%S0";
4398 info
->cc_special
= CC_SET_ZNV
;
4411 info
->shift2
= NULL
;
4414 /* Given COUNT and MODE of a shift, return 1 if a scratch reg may be
4415 needed for some shift with COUNT and MODE. Return 0 otherwise. */
4418 h8300_shift_needs_scratch_p (int count
, enum machine_mode mode
)
4423 if (GET_MODE_BITSIZE (mode
) <= count
)
4426 /* Find out the target CPU. */
4429 else if (TARGET_H8300H
)
4434 /* Find the shift algorithm. */
4438 a
= shift_alg_qi
[cpu
][SHIFT_ASHIFT
][count
];
4439 lr
= shift_alg_qi
[cpu
][SHIFT_LSHIFTRT
][count
];
4440 ar
= shift_alg_qi
[cpu
][SHIFT_ASHIFTRT
][count
];
4444 a
= shift_alg_hi
[cpu
][SHIFT_ASHIFT
][count
];
4445 lr
= shift_alg_hi
[cpu
][SHIFT_LSHIFTRT
][count
];
4446 ar
= shift_alg_hi
[cpu
][SHIFT_ASHIFTRT
][count
];
4450 a
= shift_alg_si
[cpu
][SHIFT_ASHIFT
][count
];
4451 lr
= shift_alg_si
[cpu
][SHIFT_LSHIFTRT
][count
];
4452 ar
= shift_alg_si
[cpu
][SHIFT_ASHIFTRT
][count
];
4459 /* On H8/300H, count == 8 uses a scratch register. */
4460 return (a
== SHIFT_LOOP
|| lr
== SHIFT_LOOP
|| ar
== SHIFT_LOOP
4461 || (TARGET_H8300H
&& mode
== SImode
&& count
== 8));
4464 /* Output the assembler code for doing shifts. */
4467 output_a_shift (rtx
*operands
)
4469 static int loopend_lab
;
4470 rtx shift
= operands
[3];
4471 enum machine_mode mode
= GET_MODE (shift
);
4472 enum rtx_code code
= GET_CODE (shift
);
4473 enum shift_type shift_type
;
4474 enum shift_mode shift_mode
;
4475 struct shift_info info
;
4483 shift_mode
= QIshift
;
4486 shift_mode
= HIshift
;
4489 shift_mode
= SIshift
;
4498 shift_type
= SHIFT_ASHIFTRT
;
4501 shift_type
= SHIFT_LSHIFTRT
;
4504 shift_type
= SHIFT_ASHIFT
;
4510 /* This case must be taken care of by one of the two splitters
4511 that convert a variable shift into a loop. */
4512 gcc_assert (GET_CODE (operands
[2]) == CONST_INT
);
4514 n
= INTVAL (operands
[2]);
4516 /* If the count is negative, make it 0. */
4519 /* If the count is too big, truncate it.
4520 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4521 do the intuitive thing. */
4522 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4523 n
= GET_MODE_BITSIZE (mode
);
4525 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4530 output_asm_insn (info
.special
, operands
);
4536 /* Emit two bit shifts first. */
4537 if (info
.shift2
!= NULL
)
4539 for (; n
> 1; n
-= 2)
4540 output_asm_insn (info
.shift2
, operands
);
4543 /* Now emit one bit shifts for any residual. */
4545 output_asm_insn (info
.shift1
, operands
);
4550 int m
= GET_MODE_BITSIZE (mode
) - n
;
4551 const int mask
= (shift_type
== SHIFT_ASHIFT
4552 ? ((1 << m
) - 1) << n
4556 /* Not all possibilities of rotate are supported. They shouldn't
4557 be generated, but let's watch for 'em. */
4558 gcc_assert (info
.shift1
);
4560 /* Emit two bit rotates first. */
4561 if (info
.shift2
!= NULL
)
4563 for (; m
> 1; m
-= 2)
4564 output_asm_insn (info
.shift2
, operands
);
4567 /* Now single bit rotates for any residual. */
4569 output_asm_insn (info
.shift1
, operands
);
4571 /* Now mask off the high bits. */
4575 sprintf (insn_buf
, "and\t#%d,%%X0", mask
);
4579 gcc_assert (TARGET_H8300H
|| TARGET_H8300S
);
4580 sprintf (insn_buf
, "and.w\t#%d,%%T0", mask
);
4587 output_asm_insn (insn_buf
, operands
);
4592 /* A loop to shift by a "large" constant value.
4593 If we have shift-by-2 insns, use them. */
4594 if (info
.shift2
!= NULL
)
4596 fprintf (asm_out_file
, "\tmov.b #%d,%sl\n", n
/ 2,
4597 names_big
[REGNO (operands
[4])]);
4598 fprintf (asm_out_file
, ".Llt%d:\n", loopend_lab
);
4599 output_asm_insn (info
.shift2
, operands
);
4600 output_asm_insn ("add #0xff,%X4", operands
);
4601 fprintf (asm_out_file
, "\tbne .Llt%d\n", loopend_lab
);
4603 output_asm_insn (info
.shift1
, operands
);
4607 fprintf (asm_out_file
, "\tmov.b #%d,%sl\n", n
,
4608 names_big
[REGNO (operands
[4])]);
4609 fprintf (asm_out_file
, ".Llt%d:\n", loopend_lab
);
4610 output_asm_insn (info
.shift1
, operands
);
4611 output_asm_insn ("add #0xff,%X4", operands
);
4612 fprintf (asm_out_file
, "\tbne .Llt%d\n", loopend_lab
);
4621 /* Count the number of assembly instructions in a string TEMPL. */
4624 h8300_asm_insn_count (const char *templ
)
4626 unsigned int count
= 1;
4628 for (; *templ
; templ
++)
4635 /* Compute the length of a shift insn. */
4638 compute_a_shift_length (rtx insn ATTRIBUTE_UNUSED
, rtx
*operands
)
4640 rtx shift
= operands
[3];
4641 enum machine_mode mode
= GET_MODE (shift
);
4642 enum rtx_code code
= GET_CODE (shift
);
4643 enum shift_type shift_type
;
4644 enum shift_mode shift_mode
;
4645 struct shift_info info
;
4646 unsigned int wlength
= 0;
4651 shift_mode
= QIshift
;
4654 shift_mode
= HIshift
;
4657 shift_mode
= SIshift
;
4666 shift_type
= SHIFT_ASHIFTRT
;
4669 shift_type
= SHIFT_LSHIFTRT
;
4672 shift_type
= SHIFT_ASHIFT
;
4678 if (GET_CODE (operands
[2]) != CONST_INT
)
4680 /* Get the assembler code to do one shift. */
4681 get_shift_alg (shift_type
, shift_mode
, 1, &info
);
4683 return (4 + h8300_asm_insn_count (info
.shift1
)) * 2;
4687 int n
= INTVAL (operands
[2]);
4689 /* If the count is negative, make it 0. */
4692 /* If the count is too big, truncate it.
4693 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4694 do the intuitive thing. */
4695 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4696 n
= GET_MODE_BITSIZE (mode
);
4698 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4703 wlength
+= h8300_asm_insn_count (info
.special
);
4705 /* Every assembly instruction used in SHIFT_SPECIAL case
4706 takes 2 bytes except xor.l, which takes 4 bytes, so if we
4707 see xor.l, we just pretend that xor.l counts as two insns
4708 so that the insn length will be computed correctly. */
4709 if (strstr (info
.special
, "xor.l") != NULL
)
4717 if (info
.shift2
!= NULL
)
4719 wlength
+= h8300_asm_insn_count (info
.shift2
) * (n
/ 2);
4723 wlength
+= h8300_asm_insn_count (info
.shift1
) * n
;
4729 int m
= GET_MODE_BITSIZE (mode
) - n
;
4731 /* Not all possibilities of rotate are supported. They shouldn't
4732 be generated, but let's watch for 'em. */
4733 gcc_assert (info
.shift1
);
4735 if (info
.shift2
!= NULL
)
4737 wlength
+= h8300_asm_insn_count (info
.shift2
) * (m
/ 2);
4741 wlength
+= h8300_asm_insn_count (info
.shift1
) * m
;
4743 /* Now mask off the high bits. */
4753 gcc_assert (!TARGET_H8300
);
4763 /* A loop to shift by a "large" constant value.
4764 If we have shift-by-2 insns, use them. */
4765 if (info
.shift2
!= NULL
)
4767 wlength
+= 3 + h8300_asm_insn_count (info
.shift2
);
4769 wlength
+= h8300_asm_insn_count (info
.shift1
);
4773 wlength
+= 3 + h8300_asm_insn_count (info
.shift1
);
4783 /* Compute which flag bits are valid after a shift insn. */
4786 compute_a_shift_cc (rtx insn ATTRIBUTE_UNUSED
, rtx
*operands
)
4788 rtx shift
= operands
[3];
4789 enum machine_mode mode
= GET_MODE (shift
);
4790 enum rtx_code code
= GET_CODE (shift
);
4791 enum shift_type shift_type
;
4792 enum shift_mode shift_mode
;
4793 struct shift_info info
;
4799 shift_mode
= QIshift
;
4802 shift_mode
= HIshift
;
4805 shift_mode
= SIshift
;
4814 shift_type
= SHIFT_ASHIFTRT
;
4817 shift_type
= SHIFT_LSHIFTRT
;
4820 shift_type
= SHIFT_ASHIFT
;
4826 /* This case must be taken care of by one of the two splitters
4827 that convert a variable shift into a loop. */
4828 gcc_assert (GET_CODE (operands
[2]) == CONST_INT
);
4830 n
= INTVAL (operands
[2]);
4832 /* If the count is negative, make it 0. */
4835 /* If the count is too big, truncate it.
4836 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
4837 do the intuitive thing. */
4838 else if ((unsigned int) n
> GET_MODE_BITSIZE (mode
))
4839 n
= GET_MODE_BITSIZE (mode
);
4841 get_shift_alg (shift_type
, shift_mode
, n
, &info
);
4846 if (info
.remainder
== 0)
4847 return info
.cc_special
;
4852 return info
.cc_inline
;
4855 /* This case always ends with an and instruction. */
4859 /* A loop to shift by a "large" constant value.
4860 If we have shift-by-2 insns, use them. */
4861 if (info
.shift2
!= NULL
)
4864 return info
.cc_inline
;
4873 /* A rotation by a non-constant will cause a loop to be generated, in
4874 which a rotation by one bit is used. A rotation by a constant,
4875 including the one in the loop, will be taken care of by
4876 output_a_rotate () at the insn emit time. */
4879 expand_a_rotate (rtx operands
[])
4881 rtx dst
= operands
[0];
4882 rtx src
= operands
[1];
4883 rtx rotate_amount
= operands
[2];
4884 enum machine_mode mode
= GET_MODE (dst
);
4886 if (h8sx_classify_shift (mode
, ROTATE
, rotate_amount
) == H8SX_SHIFT_UNARY
)
4889 /* We rotate in place. */
4890 emit_move_insn (dst
, src
);
4892 if (GET_CODE (rotate_amount
) != CONST_INT
)
4894 rtx counter
= gen_reg_rtx (QImode
);
4895 rtx start_label
= gen_label_rtx ();
4896 rtx end_label
= gen_label_rtx ();
4898 /* If the rotate amount is less than or equal to 0,
4899 we go out of the loop. */
4900 emit_cmp_and_jump_insns (rotate_amount
, const0_rtx
, LE
, NULL_RTX
,
4901 QImode
, 0, end_label
);
4903 /* Initialize the loop counter. */
4904 emit_move_insn (counter
, rotate_amount
);
4906 emit_label (start_label
);
4908 /* Rotate by one bit. */
4912 emit_insn (gen_rotlqi3_1 (dst
, dst
, const1_rtx
));
4915 emit_insn (gen_rotlhi3_1 (dst
, dst
, const1_rtx
));
4918 emit_insn (gen_rotlsi3_1 (dst
, dst
, const1_rtx
));
4924 /* Decrement the counter by 1. */
4925 emit_insn (gen_addqi3 (counter
, counter
, constm1_rtx
));
4927 /* If the loop counter is nonzero, we go back to the beginning
4929 emit_cmp_and_jump_insns (counter
, const0_rtx
, NE
, NULL_RTX
, QImode
, 1,
4932 emit_label (end_label
);
4936 /* Rotate by AMOUNT bits. */
4940 emit_insn (gen_rotlqi3_1 (dst
, dst
, rotate_amount
));
4943 emit_insn (gen_rotlhi3_1 (dst
, dst
, rotate_amount
));
4946 emit_insn (gen_rotlsi3_1 (dst
, dst
, rotate_amount
));
4956 /* Output a rotate insn. */
4959 output_a_rotate (enum rtx_code code
, rtx
*operands
)
4961 rtx dst
= operands
[0];
4962 rtx rotate_amount
= operands
[2];
4963 enum shift_mode rotate_mode
;
4964 enum shift_type rotate_type
;
4965 const char *insn_buf
;
4968 enum machine_mode mode
= GET_MODE (dst
);
4970 gcc_assert (GET_CODE (rotate_amount
) == CONST_INT
);
4975 rotate_mode
= QIshift
;
4978 rotate_mode
= HIshift
;
4981 rotate_mode
= SIshift
;
4990 rotate_type
= SHIFT_ASHIFT
;
4993 rotate_type
= SHIFT_LSHIFTRT
;
4999 amount
= INTVAL (rotate_amount
);
5001 /* Clean up AMOUNT. */
5004 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
))
5005 amount
= GET_MODE_BITSIZE (mode
);
5007 /* Determine the faster direction. After this phase, amount will be
5008 at most a half of GET_MODE_BITSIZE (mode). */
5009 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
) / (unsigned) 2)
5011 /* Flip the direction. */
5012 amount
= GET_MODE_BITSIZE (mode
) - amount
;
5014 (rotate_type
== SHIFT_ASHIFT
) ? SHIFT_LSHIFTRT
: SHIFT_ASHIFT
;
5017 /* See if a byte swap (in HImode) or a word swap (in SImode) can
5018 boost up the rotation. */
5019 if ((mode
== HImode
&& TARGET_H8300
&& amount
>= 5)
5020 || (mode
== HImode
&& TARGET_H8300H
&& amount
>= 6)
5021 || (mode
== HImode
&& TARGET_H8300S
&& amount
== 8)
5022 || (mode
== SImode
&& TARGET_H8300H
&& amount
>= 10)
5023 || (mode
== SImode
&& TARGET_H8300S
&& amount
>= 13))
5028 /* This code works on any family. */
5029 insn_buf
= "xor.b\t%s0,%t0\n\txor.b\t%t0,%s0\n\txor.b\t%s0,%t0";
5030 output_asm_insn (insn_buf
, operands
);
5034 /* This code works on the H8/300H and H8S. */
5035 insn_buf
= "xor.w\t%e0,%f0\n\txor.w\t%f0,%e0\n\txor.w\t%e0,%f0";
5036 output_asm_insn (insn_buf
, operands
);
5043 /* Adjust AMOUNT and flip the direction. */
5044 amount
= GET_MODE_BITSIZE (mode
) / 2 - amount
;
5046 (rotate_type
== SHIFT_ASHIFT
) ? SHIFT_LSHIFTRT
: SHIFT_ASHIFT
;
5049 /* Output rotate insns. */
5050 for (bits
= TARGET_H8300S
? 2 : 1; bits
> 0; bits
/= 2)
5053 insn_buf
= rotate_two
[rotate_type
][rotate_mode
];
5055 insn_buf
= rotate_one
[cpu_type
][rotate_type
][rotate_mode
];
5057 for (; amount
>= bits
; amount
-= bits
)
5058 output_asm_insn (insn_buf
, operands
);
5064 /* Compute the length of a rotate insn. */
5067 compute_a_rotate_length (rtx
*operands
)
5069 rtx src
= operands
[1];
5070 rtx amount_rtx
= operands
[2];
5071 enum machine_mode mode
= GET_MODE (src
);
5073 unsigned int length
= 0;
5075 gcc_assert (GET_CODE (amount_rtx
) == CONST_INT
);
5077 amount
= INTVAL (amount_rtx
);
5079 /* Clean up AMOUNT. */
5082 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
))
5083 amount
= GET_MODE_BITSIZE (mode
);
5085 /* Determine the faster direction. After this phase, amount
5086 will be at most a half of GET_MODE_BITSIZE (mode). */
5087 if ((unsigned int) amount
> GET_MODE_BITSIZE (mode
) / (unsigned) 2)
5088 /* Flip the direction. */
5089 amount
= GET_MODE_BITSIZE (mode
) - amount
;
5091 /* See if a byte swap (in HImode) or a word swap (in SImode) can
5092 boost up the rotation. */
5093 if ((mode
== HImode
&& TARGET_H8300
&& amount
>= 5)
5094 || (mode
== HImode
&& TARGET_H8300H
&& amount
>= 6)
5095 || (mode
== HImode
&& TARGET_H8300S
&& amount
== 8)
5096 || (mode
== SImode
&& TARGET_H8300H
&& amount
>= 10)
5097 || (mode
== SImode
&& TARGET_H8300S
&& amount
>= 13))
5099 /* Adjust AMOUNT and flip the direction. */
5100 amount
= GET_MODE_BITSIZE (mode
) / 2 - amount
;
5104 /* We use 2-bit rotations on the H8S. */
5106 amount
= amount
/ 2 + amount
% 2;
5108 /* The H8/300 uses three insns to rotate one bit, taking 6
5110 length
+= amount
* ((TARGET_H8300
&& mode
== HImode
) ? 6 : 2);
5115 /* Fix the operands of a gen_xxx so that it could become a bit
5119 fix_bit_operand (rtx
*operands
, enum rtx_code code
)
5121 /* The bit_operand predicate accepts any memory during RTL generation, but
5122 only 'U' memory afterwards, so if this is a MEM operand, we must force
5123 it to be valid for 'U' by reloading the address. */
5126 ? single_zero_operand (operands
[2], QImode
)
5127 : single_one_operand (operands
[2], QImode
))
5129 /* OK to have a memory dest. */
5130 if (GET_CODE (operands
[0]) == MEM
5131 && !OK_FOR_U (operands
[0]))
5133 rtx mem
= gen_rtx_MEM (GET_MODE (operands
[0]),
5134 copy_to_mode_reg (Pmode
,
5135 XEXP (operands
[0], 0)));
5136 MEM_COPY_ATTRIBUTES (mem
, operands
[0]);
5140 if (GET_CODE (operands
[1]) == MEM
5141 && !OK_FOR_U (operands
[1]))
5143 rtx mem
= gen_rtx_MEM (GET_MODE (operands
[1]),
5144 copy_to_mode_reg (Pmode
,
5145 XEXP (operands
[1], 0)));
5146 MEM_COPY_ATTRIBUTES (mem
, operands
[0]);
5152 /* Dest and src op must be register. */
5154 operands
[1] = force_reg (QImode
, operands
[1]);
5156 rtx res
= gen_reg_rtx (QImode
);
5160 emit_insn (gen_andqi3_1 (res
, operands
[1], operands
[2]));
5163 emit_insn (gen_iorqi3_1 (res
, operands
[1], operands
[2]));
5166 emit_insn (gen_xorqi3_1 (res
, operands
[1], operands
[2]));
5171 emit_insn (gen_movqi (operands
[0], res
));
5176 /* Return nonzero if FUNC is an interrupt function as specified
5177 by the "interrupt" attribute. */
5180 h8300_interrupt_function_p (tree func
)
5184 if (TREE_CODE (func
) != FUNCTION_DECL
)
5187 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
5188 return a
!= NULL_TREE
;
5191 /* Return nonzero if FUNC is a saveall function as specified by the
5192 "saveall" attribute. */
5195 h8300_saveall_function_p (tree func
)
5199 if (TREE_CODE (func
) != FUNCTION_DECL
)
5202 a
= lookup_attribute ("saveall", DECL_ATTRIBUTES (func
));
5203 return a
!= NULL_TREE
;
5206 /* Return nonzero if FUNC is an OS_Task function as specified
5207 by the "OS_Task" attribute. */
5210 h8300_os_task_function_p (tree func
)
5214 if (TREE_CODE (func
) != FUNCTION_DECL
)
5217 a
= lookup_attribute ("OS_Task", DECL_ATTRIBUTES (func
));
5218 return a
!= NULL_TREE
;
5221 /* Return nonzero if FUNC is a monitor function as specified
5222 by the "monitor" attribute. */
5225 h8300_monitor_function_p (tree func
)
5229 if (TREE_CODE (func
) != FUNCTION_DECL
)
5232 a
= lookup_attribute ("monitor", DECL_ATTRIBUTES (func
));
5233 return a
!= NULL_TREE
;
5236 /* Return nonzero if FUNC is a function that should be called
5237 through the function vector. */
5240 h8300_funcvec_function_p (tree func
)
5244 if (TREE_CODE (func
) != FUNCTION_DECL
)
5247 a
= lookup_attribute ("function_vector", DECL_ATTRIBUTES (func
));
5248 return a
!= NULL_TREE
;
5251 /* Return nonzero if DECL is a variable that's in the eight bit
5255 h8300_eightbit_data_p (tree decl
)
5259 if (TREE_CODE (decl
) != VAR_DECL
)
5262 a
= lookup_attribute ("eightbit_data", DECL_ATTRIBUTES (decl
));
5263 return a
!= NULL_TREE
;
5266 /* Return nonzero if DECL is a variable that's in the tiny
5270 h8300_tiny_data_p (tree decl
)
5274 if (TREE_CODE (decl
) != VAR_DECL
)
5277 a
= lookup_attribute ("tiny_data", DECL_ATTRIBUTES (decl
));
5278 return a
!= NULL_TREE
;
5281 /* Generate an 'interrupt_handler' attribute for decls. We convert
5282 all the pragmas to corresponding attributes. */
5285 h8300_insert_attributes (tree node
, tree
*attributes
)
5287 if (TREE_CODE (node
) == FUNCTION_DECL
)
5289 if (pragma_interrupt
)
5291 pragma_interrupt
= 0;
5293 /* Add an 'interrupt_handler' attribute. */
5294 *attributes
= tree_cons (get_identifier ("interrupt_handler"),
5302 /* Add an 'saveall' attribute. */
5303 *attributes
= tree_cons (get_identifier ("saveall"),
5309 /* Supported attributes:
5311 interrupt_handler: output a prologue and epilogue suitable for an
5314 saveall: output a prologue and epilogue that saves and restores
5315 all registers except the stack pointer.
5317 function_vector: This function should be called through the
5320 eightbit_data: This variable lives in the 8-bit data area and can
5321 be referenced with 8-bit absolute memory addresses.
5323 tiny_data: This variable lives in the tiny data area and can be
5324 referenced with 16-bit absolute memory references. */
5326 static const struct attribute_spec h8300_attribute_table
[] =
5328 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
5329 { "interrupt_handler", 0, 0, true, false, false, h8300_handle_fndecl_attribute
},
5330 { "saveall", 0, 0, true, false, false, h8300_handle_fndecl_attribute
},
5331 { "OS_Task", 0, 0, true, false, false, h8300_handle_fndecl_attribute
},
5332 { "monitor", 0, 0, true, false, false, h8300_handle_fndecl_attribute
},
5333 { "function_vector", 0, 0, true, false, false, h8300_handle_fndecl_attribute
},
5334 { "eightbit_data", 0, 0, true, false, false, h8300_handle_eightbit_data_attribute
},
5335 { "tiny_data", 0, 0, true, false, false, h8300_handle_tiny_data_attribute
},
5336 { NULL
, 0, 0, false, false, false, NULL
}
5340 /* Handle an attribute requiring a FUNCTION_DECL; arguments as in
5341 struct attribute_spec.handler. */
5343 h8300_handle_fndecl_attribute (tree
*node
, tree name
,
5344 tree args ATTRIBUTE_UNUSED
,
5345 int flags ATTRIBUTE_UNUSED
,
5348 if (TREE_CODE (*node
) != FUNCTION_DECL
)
5350 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
5352 *no_add_attrs
= true;
5358 /* Handle an "eightbit_data" attribute; arguments as in
5359 struct attribute_spec.handler. */
5361 h8300_handle_eightbit_data_attribute (tree
*node
, tree name
,
5362 tree args ATTRIBUTE_UNUSED
,
5363 int flags ATTRIBUTE_UNUSED
,
5368 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
5370 DECL_SECTION_NAME (decl
) = build_string (7, ".eight");
5374 warning (OPT_Wattributes
, "%qE attribute ignored",
5376 *no_add_attrs
= true;
5382 /* Handle an "tiny_data" attribute; arguments as in
5383 struct attribute_spec.handler. */
5385 h8300_handle_tiny_data_attribute (tree
*node
, tree name
,
5386 tree args ATTRIBUTE_UNUSED
,
5387 int flags ATTRIBUTE_UNUSED
,
5392 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
5394 DECL_SECTION_NAME (decl
) = build_string (6, ".tiny");
5398 warning (OPT_Wattributes
, "%qE attribute ignored",
5400 *no_add_attrs
= true;
5406 /* Mark function vectors, and various small data objects. */
5409 h8300_encode_section_info (tree decl
, rtx rtl
, int first
)
5411 int extra_flags
= 0;
5413 default_encode_section_info (decl
, rtl
, first
);
5415 if (TREE_CODE (decl
) == FUNCTION_DECL
5416 && h8300_funcvec_function_p (decl
))
5417 extra_flags
= SYMBOL_FLAG_FUNCVEC_FUNCTION
;
5418 else if (TREE_CODE (decl
) == VAR_DECL
5419 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)))
5421 if (h8300_eightbit_data_p (decl
))
5422 extra_flags
= SYMBOL_FLAG_EIGHTBIT_DATA
;
5423 else if (first
&& h8300_tiny_data_p (decl
))
5424 extra_flags
= SYMBOL_FLAG_TINY_DATA
;
5428 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= extra_flags
;
5431 /* Output a single-bit extraction. */
5434 output_simode_bld (int bild
, rtx operands
[])
5438 /* Clear the destination register. */
5439 output_asm_insn ("sub.w\t%e0,%e0\n\tsub.w\t%f0,%f0", operands
);
5441 /* Now output the bit load or bit inverse load, and store it in
5444 output_asm_insn ("bild\t%Z2,%Y1", operands
);
5446 output_asm_insn ("bld\t%Z2,%Y1", operands
);
5448 output_asm_insn ("bst\t#0,%w0", operands
);
5452 /* Determine if we can clear the destination first. */
5453 int clear_first
= (REG_P (operands
[0]) && REG_P (operands
[1])
5454 && REGNO (operands
[0]) != REGNO (operands
[1]));
5457 output_asm_insn ("sub.l\t%S0,%S0", operands
);
5459 /* Output the bit load or bit inverse load. */
5461 output_asm_insn ("bild\t%Z2,%Y1", operands
);
5463 output_asm_insn ("bld\t%Z2,%Y1", operands
);
5466 output_asm_insn ("xor.l\t%S0,%S0", operands
);
5468 /* Perform the bit store. */
5469 output_asm_insn ("rotxl.l\t%S0", operands
);
5476 /* Delayed-branch scheduling is more effective if we have some idea
5477 how long each instruction will be. Use a shorten_branches pass
5478 to get an initial estimate. */
5483 if (flag_delayed_branch
)
5484 shorten_branches (get_insns ());
5487 #ifndef OBJECT_FORMAT_ELF
5489 h8300_asm_named_section (const char *name
, unsigned int flags ATTRIBUTE_UNUSED
,
5492 /* ??? Perhaps we should be using default_coff_asm_named_section. */
5493 fprintf (asm_out_file
, "\t.section %s\n", name
);
5495 #endif /* ! OBJECT_FORMAT_ELF */
5497 /* Nonzero if X is a constant address suitable as an 8-bit absolute,
5498 which is a special case of the 'R' operand. */
5501 h8300_eightbit_constant_address_p (rtx x
)
5503 /* The ranges of the 8-bit area. */
5504 const unsigned HOST_WIDE_INT n1
= trunc_int_for_mode (0xff00, HImode
);
5505 const unsigned HOST_WIDE_INT n2
= trunc_int_for_mode (0xffff, HImode
);
5506 const unsigned HOST_WIDE_INT h1
= trunc_int_for_mode (0x00ffff00, SImode
);
5507 const unsigned HOST_WIDE_INT h2
= trunc_int_for_mode (0x00ffffff, SImode
);
5508 const unsigned HOST_WIDE_INT s1
= trunc_int_for_mode (0xffffff00, SImode
);
5509 const unsigned HOST_WIDE_INT s2
= trunc_int_for_mode (0xffffffff, SImode
);
5511 unsigned HOST_WIDE_INT addr
;
5513 /* We accept symbols declared with eightbit_data. */
5514 if (GET_CODE (x
) == SYMBOL_REF
)
5515 return (SYMBOL_REF_FLAGS (x
) & SYMBOL_FLAG_EIGHTBIT_DATA
) != 0;
5517 if (GET_CODE (x
) != CONST_INT
)
5523 || ((TARGET_H8300
|| TARGET_NORMAL_MODE
) && IN_RANGE (addr
, n1
, n2
))
5524 || (TARGET_H8300H
&& IN_RANGE (addr
, h1
, h2
))
5525 || (TARGET_H8300S
&& IN_RANGE (addr
, s1
, s2
)));
5528 /* Nonzero if X is a constant address suitable as an 16-bit absolute
5529 on H8/300H and H8S. */
5532 h8300_tiny_constant_address_p (rtx x
)
5534 /* The ranges of the 16-bit area. */
5535 const unsigned HOST_WIDE_INT h1
= trunc_int_for_mode (0x00000000, SImode
);
5536 const unsigned HOST_WIDE_INT h2
= trunc_int_for_mode (0x00007fff, SImode
);
5537 const unsigned HOST_WIDE_INT h3
= trunc_int_for_mode (0x00ff8000, SImode
);
5538 const unsigned HOST_WIDE_INT h4
= trunc_int_for_mode (0x00ffffff, SImode
);
5539 const unsigned HOST_WIDE_INT s1
= trunc_int_for_mode (0x00000000, SImode
);
5540 const unsigned HOST_WIDE_INT s2
= trunc_int_for_mode (0x00007fff, SImode
);
5541 const unsigned HOST_WIDE_INT s3
= trunc_int_for_mode (0xffff8000, SImode
);
5542 const unsigned HOST_WIDE_INT s4
= trunc_int_for_mode (0xffffffff, SImode
);
5544 unsigned HOST_WIDE_INT addr
;
5546 switch (GET_CODE (x
))
5549 /* In the normal mode, any symbol fits in the 16-bit absolute
5550 address range. We also accept symbols declared with
5552 return (TARGET_NORMAL_MODE
5553 || (SYMBOL_REF_FLAGS (x
) & SYMBOL_FLAG_TINY_DATA
) != 0);
5557 return (TARGET_NORMAL_MODE
5559 && (IN_RANGE (addr
, h1
, h2
) || IN_RANGE (addr
, h3
, h4
)))
5561 && (IN_RANGE (addr
, s1
, s2
) || IN_RANGE (addr
, s3
, s4
))));
5564 return TARGET_NORMAL_MODE
;
5572 /* Return nonzero if ADDR1 and ADDR2 point to consecutive memory
5573 locations that can be accessed as a 16-bit word. */
5576 byte_accesses_mergeable_p (rtx addr1
, rtx addr2
)
5578 HOST_WIDE_INT offset1
, offset2
;
5586 else if (GET_CODE (addr1
) == PLUS
5587 && REG_P (XEXP (addr1
, 0))
5588 && GET_CODE (XEXP (addr1
, 1)) == CONST_INT
)
5590 reg1
= XEXP (addr1
, 0);
5591 offset1
= INTVAL (XEXP (addr1
, 1));
5601 else if (GET_CODE (addr2
) == PLUS
5602 && REG_P (XEXP (addr2
, 0))
5603 && GET_CODE (XEXP (addr2
, 1)) == CONST_INT
)
5605 reg2
= XEXP (addr2
, 0);
5606 offset2
= INTVAL (XEXP (addr2
, 1));
5611 if (((reg1
== stack_pointer_rtx
&& reg2
== stack_pointer_rtx
)
5612 || (reg1
== frame_pointer_rtx
&& reg2
== frame_pointer_rtx
))
5614 && offset1
+ 1 == offset2
)
5620 /* Return nonzero if we have the same comparison insn as I3 two insns
5621 before I3. I3 is assumed to be a comparison insn. */
5624 same_cmp_preceding_p (rtx i3
)
5628 /* Make sure we have a sequence of three insns. */
5629 i2
= prev_nonnote_insn (i3
);
5632 i1
= prev_nonnote_insn (i2
);
5636 return (INSN_P (i1
) && rtx_equal_p (PATTERN (i1
), PATTERN (i3
))
5637 && any_condjump_p (i2
) && onlyjump_p (i2
));
5640 /* Return nonzero if we have the same comparison insn as I1 two insns
5641 after I1. I1 is assumed to be a comparison insn. */
5644 same_cmp_following_p (rtx i1
)
5648 /* Make sure we have a sequence of three insns. */
5649 i2
= next_nonnote_insn (i1
);
5652 i3
= next_nonnote_insn (i2
);
5656 return (INSN_P (i3
) && rtx_equal_p (PATTERN (i1
), PATTERN (i3
))
5657 && any_condjump_p (i2
) && onlyjump_p (i2
));
5660 /* Return nonzero if OPERANDS are valid for stm (or ldm) that pushes
5661 (or pops) N registers. OPERANDS are assumed to be an array of
5665 h8300_regs_ok_for_stm (int n
, rtx operands
[])
5670 return ((REGNO (operands
[0]) == 0 && REGNO (operands
[1]) == 1)
5671 || (REGNO (operands
[0]) == 2 && REGNO (operands
[1]) == 3)
5672 || (REGNO (operands
[0]) == 4 && REGNO (operands
[1]) == 5));
5674 return ((REGNO (operands
[0]) == 0
5675 && REGNO (operands
[1]) == 1
5676 && REGNO (operands
[2]) == 2)
5677 || (REGNO (operands
[0]) == 4
5678 && REGNO (operands
[1]) == 5
5679 && REGNO (operands
[2]) == 6));
5682 return (REGNO (operands
[0]) == 0
5683 && REGNO (operands
[1]) == 1
5684 && REGNO (operands
[2]) == 2
5685 && REGNO (operands
[3]) == 3);
5691 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */
5694 h8300_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED
,
5695 unsigned int new_reg
)
5697 /* Interrupt functions can only use registers that have already been
5698 saved by the prologue, even if they would normally be
5701 if (h8300_current_function_interrupt_function_p ()
5702 && !df_regs_ever_live_p (new_reg
))
5708 /* Returns true if register REGNO is safe to be allocated as a scratch
5709 register in the current function. */
5712 h8300_hard_regno_scratch_ok (unsigned int regno
)
5714 if (h8300_current_function_interrupt_function_p ()
5715 && ! WORD_REG_USED (regno
))
5722 /* Return nonzero if X is a legitimate constant. */
5725 h8300_legitimate_constant_p (rtx x ATTRIBUTE_UNUSED
)
5730 /* Return nonzero if X is a REG or SUBREG suitable as a base register. */
5733 h8300_rtx_ok_for_base_p (rtx x
, int strict
)
5735 /* Strip off SUBREG if any. */
5736 if (GET_CODE (x
) == SUBREG
)
5741 ? REG_OK_FOR_BASE_STRICT_P (x
)
5742 : REG_OK_FOR_BASE_NONSTRICT_P (x
)));
5745 /* Return nozero if X is a legitimate address. On the H8/300, a
5746 legitimate address has the form REG, REG+CONSTANT_ADDRESS or
5747 CONSTANT_ADDRESS. */
5750 h8300_legitimate_address_p (enum machine_mode mode
, rtx x
, bool strict
)
5752 /* The register indirect addresses like @er0 is always valid. */
5753 if (h8300_rtx_ok_for_base_p (x
, strict
))
5756 if (CONSTANT_ADDRESS_P (x
))
5760 && ( GET_CODE (x
) == PRE_INC
5761 || GET_CODE (x
) == PRE_DEC
5762 || GET_CODE (x
) == POST_INC
5763 || GET_CODE (x
) == POST_DEC
)
5764 && h8300_rtx_ok_for_base_p (XEXP (x
, 0), strict
))
5767 if (GET_CODE (x
) == PLUS
5768 && CONSTANT_ADDRESS_P (XEXP (x
, 1))
5769 && h8300_rtx_ok_for_base_p (h8300_get_index (XEXP (x
, 0),
5776 /* Worker function for HARD_REGNO_NREGS.
5778 We pretend the MAC register is 32bits -- we don't have any data
5779 types on the H8 series to handle more than 32bits. */
5782 h8300_hard_regno_nregs (int regno ATTRIBUTE_UNUSED
, enum machine_mode mode
)
5784 return (GET_MODE_SIZE (mode
) + UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
5787 /* Worker function for HARD_REGNO_MODE_OK. */
5790 h8300_hard_regno_mode_ok (int regno
, enum machine_mode mode
)
5793 /* If an even reg, then anything goes. Otherwise the mode must be
5795 return ((regno
& 1) == 0) || (mode
== HImode
) || (mode
== QImode
);
5797 /* MAC register can only be of SImode. Otherwise, anything
5799 return regno
== MAC_REG
? mode
== SImode
: 1;
5802 /* Perform target dependent optabs initialization. */
5804 h8300_init_libfuncs (void)
5806 set_optab_libfunc (smul_optab
, HImode
, "__mulhi3");
5807 set_optab_libfunc (sdiv_optab
, HImode
, "__divhi3");
5808 set_optab_libfunc (udiv_optab
, HImode
, "__udivhi3");
5809 set_optab_libfunc (smod_optab
, HImode
, "__modhi3");
5810 set_optab_libfunc (umod_optab
, HImode
, "__umodhi3");
5813 /* Worker function for TARGET_RETURN_IN_MEMORY. */
5816 h8300_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
5818 return (TYPE_MODE (type
) == BLKmode
5819 || GET_MODE_SIZE (TYPE_MODE (type
)) > (TARGET_H8300
? 4 : 8));
5822 /* We emit the entire trampoline here. Depending on the pointer size,
5823 we use a different trampoline.
5827 1 0000 7903xxxx mov.w #0x1234,r3
5828 2 0004 5A00xxxx jmp @0x1234
5833 2 0000 7A03xxxxxxxx mov.l #0x12345678,er3
5834 3 0006 5Axxxxxx jmp @0x123456
5839 h8300_trampoline_init (rtx m_tramp
, tree fndecl
, rtx cxt
)
5841 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
5844 if (Pmode
== HImode
)
5846 mem
= adjust_address (m_tramp
, HImode
, 0);
5847 emit_move_insn (mem
, GEN_INT (0x7903));
5848 mem
= adjust_address (m_tramp
, Pmode
, 2);
5849 emit_move_insn (mem
, cxt
);
5850 mem
= adjust_address (m_tramp
, HImode
, 4);
5851 emit_move_insn (mem
, GEN_INT (0x5a00));
5852 mem
= adjust_address (m_tramp
, Pmode
, 6);
5853 emit_move_insn (mem
, fnaddr
);
5859 mem
= adjust_address (m_tramp
, HImode
, 0);
5860 emit_move_insn (mem
, GEN_INT (0x7a03));
5861 mem
= adjust_address (m_tramp
, Pmode
, 2);
5862 emit_move_insn (mem
, cxt
);
5864 tem
= copy_to_reg (fnaddr
);
5865 emit_insn (gen_andsi3 (tem
, tem
, GEN_INT (0x00ffffff)));
5866 emit_insn (gen_iorsi3 (tem
, tem
, GEN_INT (0x5a000000)));
5867 mem
= adjust_address (m_tramp
, SImode
, 6);
5868 emit_move_insn (mem
, tem
);
5872 /* Initialize the GCC target structure. */
5873 #undef TARGET_ATTRIBUTE_TABLE
5874 #define TARGET_ATTRIBUTE_TABLE h8300_attribute_table
5876 #undef TARGET_ASM_ALIGNED_HI_OP
5877 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
5879 #undef TARGET_ASM_FILE_START
5880 #define TARGET_ASM_FILE_START h8300_file_start
5881 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
5882 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
5884 #undef TARGET_ASM_FILE_END
5885 #define TARGET_ASM_FILE_END h8300_file_end
5887 #undef TARGET_ENCODE_SECTION_INFO
5888 #define TARGET_ENCODE_SECTION_INFO h8300_encode_section_info
5890 #undef TARGET_INSERT_ATTRIBUTES
5891 #define TARGET_INSERT_ATTRIBUTES h8300_insert_attributes
5893 #undef TARGET_RTX_COSTS
5894 #define TARGET_RTX_COSTS h8300_rtx_costs
5896 #undef TARGET_INIT_LIBFUNCS
5897 #define TARGET_INIT_LIBFUNCS h8300_init_libfuncs
5899 #undef TARGET_RETURN_IN_MEMORY
5900 #define TARGET_RETURN_IN_MEMORY h8300_return_in_memory
5902 #undef TARGET_MACHINE_DEPENDENT_REORG
5903 #define TARGET_MACHINE_DEPENDENT_REORG h8300_reorg
5905 #undef TARGET_HARD_REGNO_SCRATCH_OK
5906 #define TARGET_HARD_REGNO_SCRATCH_OK h8300_hard_regno_scratch_ok
5908 #undef TARGET_LEGITIMATE_ADDRESS_P
5909 #define TARGET_LEGITIMATE_ADDRESS_P h8300_legitimate_address_p
5911 #undef TARGET_DEFAULT_TARGET_FLAGS
5912 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_DEFAULT
5914 #undef TARGET_CAN_ELIMINATE
5915 #define TARGET_CAN_ELIMINATE h8300_can_eliminate
5917 #undef TARGET_TRAMPOLINE_INIT
5918 #define TARGET_TRAMPOLINE_INIT h8300_trampoline_init
5920 struct gcc_target targetm
= TARGET_INITIALIZER
;