OSDN Git Service

* config/h8300/h8300.c (fix_bit_operand): Don't generate insns
[pf3gnuchains/gcc-fork.git] / gcc / config / h8300 / h8300.c
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 Free Software Foundation, Inc.
4    Contributed by Steve Chamberlain (sac@cygnus.com),
5    Jim Wilson (wilson@cygnus.com), and Doug Evans (dje@cygnus.com).
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING.  If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.  */
23
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "regs.h"
31 #include "hard-reg-set.h"
32 #include "real.h"
33 #include "insn-config.h"
34 #include "conditions.h"
35 #include "output.h"
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "recog.h"
39 #include "expr.h"
40 #include "function.h"
41 #include "optabs.h"
42 #include "toplev.h"
43 #include "c-pragma.h"
44 #include "tm_p.h"
45 #include "ggc.h"
46 #include "target.h"
47 #include "target-def.h"
48
49 /* Forward declarations.  */
50 static const char *byte_reg (rtx, int);
51 static int h8300_interrupt_function_p (tree);
52 static int h8300_saveall_function_p (tree);
53 static int h8300_monitor_function_p (tree);
54 static int h8300_os_task_function_p (tree);
55 static void h8300_emit_stack_adjustment (int, unsigned int);
56 static int round_frame_size (int);
57 static unsigned int compute_saved_regs (void);
58 static void push (int);
59 static void pop (int);
60 static const char *cond_string (enum rtx_code);
61 static unsigned int h8300_asm_insn_count (const char *);
62 static tree h8300_handle_fndecl_attribute (tree *, tree, tree, int, bool *);
63 static tree h8300_handle_eightbit_data_attribute (tree *, tree, tree, int, bool *);
64 static tree h8300_handle_tiny_data_attribute (tree *, tree, tree, int, bool *);
65 #ifndef OBJECT_FORMAT_ELF
66 static void h8300_asm_named_section (const char *, unsigned int);
67 #endif
68 static int h8300_and_costs (rtx);
69 static int h8300_shift_costs (rtx);
70
71 /* CPU_TYPE, says what cpu we're compiling for.  */
72 int cpu_type;
73
74 /* True if a #pragma interrupt has been seen for the current function.  */
75 static int pragma_interrupt;
76
77 /* True if a #pragma saveall has been seen for the current function.  */
78 static int pragma_saveall;
79
80 static const char *const names_big[] =
81 { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7" };
82
83 static const char *const names_extended[] =
84 { "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7" };
85
86 static const char *const names_upper_extended[] =
87 { "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7" };
88
89 /* Points to one of the above.  */
90 /* ??? The above could be put in an array indexed by CPU_TYPE.  */
91 const char * const *h8_reg_names;
92
93 /* Various operations needed by the following, indexed by CPU_TYPE.  */
94
95 const char *h8_push_op, *h8_pop_op, *h8_mov_op;
96
97 /* Machine-specific symbol_ref flags.  */
98 #define SYMBOL_FLAG_FUNCVEC_FUNCTION    (SYMBOL_FLAG_MACH_DEP << 0)
99 #define SYMBOL_FLAG_EIGHTBIT_DATA       (SYMBOL_FLAG_MACH_DEP << 1)
100 #define SYMBOL_FLAG_TINY_DATA           (SYMBOL_FLAG_MACH_DEP << 2)
101 \f
102 /* See below where shifts are handled for explanation of this enum.  */
103
104 enum shift_alg
105 {
106   SHIFT_INLINE,
107   SHIFT_ROT_AND,
108   SHIFT_SPECIAL,
109   SHIFT_LOOP
110 };
111
112 /* Symbols of the various shifts which can be used as indices.  */
113
114 enum shift_type
115 {
116   SHIFT_ASHIFT, SHIFT_LSHIFTRT, SHIFT_ASHIFTRT
117 };
118
119 /* Macros to keep the shift algorithm tables small.  */
120 #define INL SHIFT_INLINE
121 #define ROT SHIFT_ROT_AND
122 #define LOP SHIFT_LOOP
123 #define SPC SHIFT_SPECIAL
124
125 /* The shift algorithms for each machine, mode, shift type, and shift
126    count are defined below.  The three tables below correspond to
127    QImode, HImode, and SImode, respectively.  Each table is organized
128    by, in the order of indices, machine, shift type, and shift count.  */
129
130 static enum shift_alg shift_alg_qi[3][3][8] = {
131   {
132     /* TARGET_H8300  */
133     /* 0    1    2    3    4    5    6    7  */
134     { INL, INL, INL, INL, INL, ROT, ROT, ROT }, /* SHIFT_ASHIFT   */
135     { INL, INL, INL, INL, INL, ROT, ROT, ROT }, /* SHIFT_LSHIFTRT */
136     { INL, INL, INL, INL, INL, LOP, LOP, SPC }  /* SHIFT_ASHIFTRT */
137   },
138   {
139     /* TARGET_H8300H  */
140     /* 0    1    2    3    4    5    6    7  */
141     { INL, INL, INL, INL, INL, ROT, ROT, ROT }, /* SHIFT_ASHIFT   */
142     { INL, INL, INL, INL, INL, ROT, ROT, ROT }, /* SHIFT_LSHIFTRT */
143     { INL, INL, INL, INL, INL, LOP, LOP, SPC }  /* SHIFT_ASHIFTRT */
144   },
145   {
146     /* TARGET_H8300S  */
147     /*  0    1    2    3    4    5    6    7  */
148     { INL, INL, INL, INL, INL, INL, ROT, ROT }, /* SHIFT_ASHIFT   */
149     { INL, INL, INL, INL, INL, INL, ROT, ROT }, /* SHIFT_LSHIFTRT */
150     { INL, INL, INL, INL, INL, INL, INL, SPC }  /* SHIFT_ASHIFTRT */
151   }
152 };
153
154 static enum shift_alg shift_alg_hi[3][3][16] = {
155   {
156     /* TARGET_H8300  */
157     /*  0    1    2    3    4    5    6    7  */
158     /*  8    9   10   11   12   13   14   15  */
159     { INL, INL, INL, INL, INL, INL, INL, SPC,
160       SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC }, /* SHIFT_ASHIFT   */
161     { INL, INL, INL, INL, INL, LOP, LOP, SPC,
162       SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC }, /* SHIFT_LSHIFTRT */
163     { INL, INL, INL, INL, INL, LOP, LOP, SPC,
164       SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC }, /* SHIFT_ASHIFTRT */
165   },
166   {
167     /* TARGET_H8300H  */
168     /*  0    1    2    3    4    5    6    7  */
169     /*  8    9   10   11   12   13   14   15  */
170     { INL, INL, INL, INL, INL, INL, INL, SPC,
171       SPC, SPC, SPC, SPC, SPC, ROT, ROT, ROT }, /* SHIFT_ASHIFT   */
172     { INL, INL, INL, INL, INL, INL, INL, SPC,
173       SPC, SPC, SPC, SPC, SPC, ROT, ROT, ROT }, /* SHIFT_LSHIFTRT */
174     { INL, INL, INL, INL, INL, INL, INL, SPC,
175       SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC }, /* SHIFT_ASHIFTRT */
176   },
177   {
178     /* TARGET_H8300S  */
179     /*  0    1    2    3    4    5    6    7  */
180     /*  8    9   10   11   12   13   14   15  */
181     { INL, INL, INL, INL, INL, INL, INL, INL,
182       SPC, SPC, SPC, SPC, SPC, ROT, ROT, ROT }, /* SHIFT_ASHIFT   */
183     { INL, INL, INL, INL, INL, INL, INL, INL,
184       SPC, SPC, SPC, SPC, SPC, ROT, ROT, ROT }, /* SHIFT_LSHIFTRT */
185     { INL, INL, INL, INL, INL, INL, INL, INL,
186       SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC }, /* SHIFT_ASHIFTRT */
187   }
188 };
189
190 static enum shift_alg shift_alg_si[3][3][32] = {
191   {
192     /* TARGET_H8300  */
193     /*  0    1    2    3    4    5    6    7  */
194     /*  8    9   10   11   12   13   14   15  */
195     /* 16   17   18   19   20   21   22   23  */
196     /* 24   25   26   27   28   29   30   31  */
197     { INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
198       SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
199       SPC, SPC, SPC, SPC, SPC, LOP, LOP, LOP,
200       SPC, SPC, SPC, SPC, LOP, LOP, LOP, SPC }, /* SHIFT_ASHIFT   */
201     { INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
202       SPC, SPC, LOP, LOP, LOP, LOP, LOP, SPC,
203       SPC, SPC, SPC, LOP, LOP, LOP, LOP, LOP,
204       SPC, SPC, SPC, SPC, SPC, LOP, LOP, SPC }, /* SHIFT_LSHIFTRT */
205     { INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
206       SPC, LOP, LOP, LOP, LOP, LOP, LOP, SPC,
207       SPC, SPC, LOP, LOP, LOP, LOP, LOP, LOP,
208       SPC, SPC, SPC, LOP, LOP, LOP, LOP, SPC }, /* SHIFT_ASHIFTRT */
209   },
210   {
211     /* TARGET_H8300H  */
212     /*  0    1    2    3    4    5    6    7  */
213     /*  8    9   10   11   12   13   14   15  */
214     /* 16   17   18   19   20   21   22   23  */
215     /* 24   25   26   27   28   29   30   31  */
216     { INL, INL, INL, INL, INL, LOP, LOP, LOP,
217       SPC, LOP, LOP, LOP, LOP, LOP, LOP, SPC,
218       SPC, SPC, SPC, SPC, LOP, LOP, LOP, LOP,
219       SPC, LOP, LOP, LOP, SPC, SPC, SPC, SPC }, /* SHIFT_ASHIFT   */
220     { INL, INL, INL, INL, INL, LOP, LOP, LOP,
221       SPC, LOP, LOP, LOP, LOP, LOP, LOP, SPC,
222       SPC, SPC, SPC, SPC, LOP, LOP, LOP, LOP,
223       SPC, LOP, LOP, LOP, SPC, SPC, SPC, SPC }, /* SHIFT_LSHIFTRT */
224     { INL, INL, INL, INL, INL, LOP, LOP, LOP,
225       SPC, LOP, LOP, LOP, LOP, LOP, LOP, LOP,
226       SPC, SPC, SPC, SPC, LOP, LOP, LOP, LOP,
227       SPC, LOP, LOP, LOP, LOP, LOP, LOP, SPC }, /* SHIFT_ASHIFTRT */
228   },
229   {
230     /* TARGET_H8300S  */
231     /*  0    1    2    3    4    5    6    7  */
232     /*  8    9   10   11   12   13   14   15  */
233     /* 16   17   18   19   20   21   22   23  */
234     /* 24   25   26   27   28   29   30   31  */
235     { INL, INL, INL, INL, INL, INL, INL, INL,
236       INL, INL, INL, LOP, LOP, LOP, LOP, SPC,
237       SPC, SPC, SPC, SPC, SPC, SPC, LOP, LOP,
238       SPC, SPC, LOP, LOP, SPC, SPC, SPC, SPC }, /* SHIFT_ASHIFT   */
239     { INL, INL, INL, INL, INL, INL, INL, INL,
240       INL, INL, INL, LOP, LOP, LOP, LOP, SPC,
241       SPC, SPC, SPC, SPC, SPC, SPC, LOP, LOP,
242       SPC, SPC, LOP, LOP, SPC, SPC, SPC, SPC }, /* SHIFT_LSHIFTRT */
243     { INL, INL, INL, INL, INL, INL, INL, INL,
244       INL, INL, INL, LOP, LOP, LOP, LOP, LOP,
245       SPC, SPC, SPC, SPC, SPC, SPC, LOP, LOP,
246       SPC, SPC, LOP, LOP, LOP, LOP, LOP, SPC }, /* SHIFT_ASHIFTRT */
247   }
248 };
249
250 #undef INL
251 #undef ROT
252 #undef LOP
253 #undef SPC
254
255 enum h8_cpu
256 {
257   H8_300,
258   H8_300H,
259   H8_S
260 };
261
262 /* Initialize various cpu specific globals at start up.  */
263
264 void
265 h8300_init_once (void)
266 {
267   static const char *const h8_push_ops[2] = { "push" , "push.l" };
268   static const char *const h8_pop_ops[2]  = { "pop"  , "pop.l"  };
269   static const char *const h8_mov_ops[2]  = { "mov.w", "mov.l"  };
270
271   if (TARGET_H8300)
272     {
273       cpu_type = (int) CPU_H8300;
274       h8_reg_names = names_big;
275     }
276   else
277     {
278       /* For this we treat the H8/300H and H8S the same.  */
279       cpu_type = (int) CPU_H8300H;
280       h8_reg_names = names_extended;
281     }
282   h8_push_op = h8_push_ops[cpu_type];
283   h8_pop_op = h8_pop_ops[cpu_type];
284   h8_mov_op = h8_mov_ops[cpu_type];
285
286   if (!TARGET_H8300S && TARGET_MAC)
287     {
288       error ("-ms2600 is used without -ms");
289       target_flags |= MASK_H8300S;
290     }
291
292   if (TARGET_H8300 && TARGET_NORMAL_MODE)
293     {
294       error ("-mn is used without -mh or -ms");
295       target_flags ^= MASK_NORMAL_MODE;
296     }
297
298   /* Some of the shifts are optimized for speed by default.
299      See http://gcc.gnu.org/ml/gcc-patches/2002-07/msg01858.html
300      If optimizing for size, change shift_alg for those shift to
301      SHIFT_LOOP.  */
302   if (optimize_size)
303     {
304       /* H8/300 */
305       shift_alg_hi[H8_300][SHIFT_ASHIFT][5] = SHIFT_LOOP;
306       shift_alg_hi[H8_300][SHIFT_ASHIFT][6] = SHIFT_LOOP;
307       shift_alg_hi[H8_300][SHIFT_ASHIFT][13] = SHIFT_LOOP;
308       shift_alg_hi[H8_300][SHIFT_ASHIFT][14] = SHIFT_LOOP;
309
310       shift_alg_hi[H8_300][SHIFT_LSHIFTRT][13] = SHIFT_LOOP;
311       shift_alg_hi[H8_300][SHIFT_LSHIFTRT][14] = SHIFT_LOOP;
312
313       shift_alg_hi[H8_300][SHIFT_ASHIFTRT][13] = SHIFT_LOOP;
314       shift_alg_hi[H8_300][SHIFT_ASHIFTRT][14] = SHIFT_LOOP;
315
316       /* H8/300H */
317       shift_alg_hi[H8_300H][SHIFT_ASHIFT][5] = SHIFT_LOOP;
318       shift_alg_hi[H8_300H][SHIFT_ASHIFT][6] = SHIFT_LOOP;
319
320       shift_alg_hi[H8_300H][SHIFT_LSHIFTRT][5] = SHIFT_LOOP;
321       shift_alg_hi[H8_300H][SHIFT_LSHIFTRT][6] = SHIFT_LOOP;
322
323       shift_alg_hi[H8_300H][SHIFT_ASHIFTRT][5] = SHIFT_LOOP;
324       shift_alg_hi[H8_300H][SHIFT_ASHIFTRT][6] = SHIFT_LOOP;
325       shift_alg_hi[H8_300H][SHIFT_ASHIFTRT][13] = SHIFT_LOOP;
326       shift_alg_hi[H8_300H][SHIFT_ASHIFTRT][14] = SHIFT_LOOP;
327
328       /* H8S */
329       shift_alg_hi[H8_S][SHIFT_ASHIFTRT][14] = SHIFT_LOOP;
330     }
331 }
332
333 static const char *
334 byte_reg (rtx x, int b)
335 {
336   static const char *const names_small[] = {
337     "r0l", "r0h", "r1l", "r1h", "r2l", "r2h", "r3l", "r3h",
338     "r4l", "r4h", "r5l", "r5h", "r6l", "r6h", "r7l", "r7h"
339   };
340
341   if (!REG_P (x))
342     abort ();
343
344   return names_small[REGNO (x) * 2 + b];
345 }
346
347 /* REGNO must be saved/restored across calls if this macro is true.  */
348
349 #define WORD_REG_USED(regno)                                            \
350   (regno < SP_REG                                                       \
351    /* No need to save registers if this function will not return.  */   \
352    && ! TREE_THIS_VOLATILE (current_function_decl)                      \
353    && (h8300_saveall_function_p (current_function_decl)                 \
354        /* Save any call saved register that was used.  */               \
355        || (regs_ever_live[regno] && !call_used_regs[regno])             \
356        /* Save the frame pointer if it was used.  */                    \
357        || (regno == HARD_FRAME_POINTER_REGNUM && regs_ever_live[regno]) \
358        /* Save any register used in an interrupt handler.  */           \
359        || (h8300_current_function_interrupt_function_p ()               \
360            && regs_ever_live[regno])                                    \
361        /* Save call clobbered registers in non-leaf interrupt           \
362           handlers.  */                                                 \
363        || (h8300_current_function_interrupt_function_p ()               \
364            && call_used_regs[regno]                                     \
365            && !current_function_is_leaf)))
366
367 /* Output assembly language to FILE for the operation OP with operand size
368    SIZE to adjust the stack pointer.  */
369
370 static void
371 h8300_emit_stack_adjustment (int sign, unsigned int size)
372 {
373   /* If the frame size is 0, we don't have anything to do.  */
374   if (size == 0)
375     return 0;
376
377   /* H8/300 cannot add/subtract a large constant with a single
378      instruction.  If a temporary register is available, load the
379      constant to it and then do the addition.  */
380   if (TARGET_H8300
381       && size > 4
382       && !h8300_current_function_interrupt_function_p ()
383       && !(current_function_needs_context && sign < 0))
384     {
385       rtx r3 = gen_rtx_REG (Pmode, 3);
386       emit_insn (gen_movhi (r3, GEN_INT (sign * size)));
387       emit_insn (gen_addhi3 (stack_pointer_rtx,
388                              stack_pointer_rtx, r3));
389     }
390   else
391     {
392       /* The stack adjustment made here is further optimized by the
393          splitter.  In case of H8/300, the splitter always splits the
394          addition emitted here to make the adjustment
395          interrupt-safe.  */
396       if (Pmode == HImode)
397         emit_insn (gen_addhi3 (stack_pointer_rtx,
398                                stack_pointer_rtx, GEN_INT (sign * size)));
399       else
400         emit_insn (gen_addsi3 (stack_pointer_rtx,
401                                stack_pointer_rtx, GEN_INT (sign * size)));
402     }
403 }
404
405 /* Round up frame size SIZE.  */
406
407 static int
408 round_frame_size (int size)
409 {
410   return ((size + STACK_BOUNDARY / BITS_PER_UNIT - 1)
411           & -STACK_BOUNDARY / BITS_PER_UNIT);
412 }
413
414 /* Compute which registers to push/pop.
415    Return a bit vector of registers.  */
416
417 static unsigned int
418 compute_saved_regs (void)
419 {
420   unsigned int saved_regs = 0;
421   int regno;
422
423   /* Construct a bit vector of registers to be pushed/popped.  */
424   for (regno = 0; regno <= HARD_FRAME_POINTER_REGNUM; regno++)
425     {
426       if (WORD_REG_USED (regno))
427         saved_regs |= 1 << regno;
428     }
429
430   /* Don't push/pop the frame pointer as it is treated separately.  */
431   if (frame_pointer_needed)
432     saved_regs &= ~(1 << HARD_FRAME_POINTER_REGNUM);
433
434   return saved_regs;
435 }
436
437 /* Emit an insn to push register RN.  */
438
439 static void
440 push (int rn)
441 {
442   rtx reg = gen_rtx_REG (word_mode, rn);
443   rtx x;
444
445   if (TARGET_H8300)
446     x = gen_push_h8300 (reg);
447   else if (!TARGET_NORMAL_MODE)
448     x = gen_push_h8300hs_advanced (reg);
449   else
450     x = gen_push_h8300hs_normal (reg);
451   x = emit_insn (x);
452   REG_NOTES (x) = gen_rtx_EXPR_LIST (REG_INC, stack_pointer_rtx, 0);
453 }
454
455 /* Emit an insn to pop register RN.  */
456
457 static void
458 pop (int rn)
459 {
460   rtx reg = gen_rtx_REG (word_mode, rn);
461   rtx x;
462
463   if (TARGET_H8300)
464     x = gen_pop_h8300 (reg);
465   else if (!TARGET_NORMAL_MODE)
466     x = gen_pop_h8300hs_advanced (reg);
467   else
468     x = gen_pop_h8300hs_normal (reg);
469   x = emit_insn (x);
470   REG_NOTES (x) = gen_rtx_EXPR_LIST (REG_INC, stack_pointer_rtx, 0);
471 }
472
473 /* This is what the stack looks like after the prolog of
474    a function with a frame has been set up:
475
476    <args>
477    PC
478    FP                   <- fp
479    <locals>
480    <saved registers>    <- sp
481
482    This is what the stack looks like after the prolog of
483    a function which doesn't have a frame:
484
485    <args>
486    PC
487    <locals>
488    <saved registers>    <- sp
489 */
490
491 /* Generate RTL code for the function prologue.  */
492
493 void
494 h8300_expand_prologue (void)
495 {
496   int regno;
497   int saved_regs;
498   int n_regs;
499
500   /* If the current function has the OS_Task attribute set, then
501      we have a naked prologue.  */
502   if (h8300_os_task_function_p (current_function_decl))
503     return;
504
505   if (h8300_monitor_function_p (current_function_decl))
506     /* My understanding of monitor functions is they act just like
507        interrupt functions, except the prologue must mask
508        interrupts.  */
509     emit_insn (gen_monitor_prologue ());
510
511   if (frame_pointer_needed)
512     {
513       /* Push fp.  */
514       push (HARD_FRAME_POINTER_REGNUM);
515       emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
516     }
517
518   /* Push the rest of the registers in ascending order.  */
519   saved_regs = compute_saved_regs ();
520   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno += n_regs)
521     {
522       n_regs = 1;
523       if (saved_regs & (1 << regno))
524         {
525           if (TARGET_H8300S)
526             {
527               /* See how many registers we can push at the same time.  */
528               if ((regno == 0 || regno == 4)
529                   && ((saved_regs >> regno) & 0x0f) == 0x0f)
530                 n_regs = 4;
531
532               else if ((regno == 0 || regno == 4)
533                        && ((saved_regs >> regno) & 0x07) == 0x07)
534                 n_regs = 3;
535
536               else if ((regno == 0 || regno == 2 || regno == 4 || regno == 6)
537                        && ((saved_regs >> regno) & 0x03) == 0x03)
538                 n_regs = 2;
539             }
540
541           switch (n_regs)
542             {
543             case 1:
544               push (regno);
545               break;
546             case 2:
547               emit_insn (gen_stm_h8300s_2 (gen_rtx_REG (SImode, regno),
548                                            gen_rtx_REG (SImode, regno + 1)));
549               break;
550             case 3:
551               emit_insn (gen_stm_h8300s_3 (gen_rtx_REG (SImode, regno),
552                                            gen_rtx_REG (SImode, regno + 1),
553                                            gen_rtx_REG (SImode, regno + 2)));
554               break;
555             case 4:
556               emit_insn (gen_stm_h8300s_4 (gen_rtx_REG (SImode, regno),
557                                            gen_rtx_REG (SImode, regno + 1),
558                                            gen_rtx_REG (SImode, regno + 2),
559                                            gen_rtx_REG (SImode, regno + 3)));
560               break;
561             default:
562               abort ();
563             }
564         }
565     }
566
567   /* Leave room for locals.  */
568   h8300_emit_stack_adjustment (-1, round_frame_size (get_frame_size ()));
569 }
570
571 int
572 h8300_can_use_return_insn_p (void)
573 {
574   return (reload_completed
575           && !frame_pointer_needed
576           && get_frame_size () == 0
577           && compute_saved_regs () == 0);
578 }
579
580 /* Generate RTL code for the function epilogue.  */
581
582 void
583 h8300_expand_epilogue (void)
584 {
585   int regno;
586   int saved_regs;
587   int n_regs;
588
589   if (h8300_os_task_function_p (current_function_decl))
590     /* OS_Task epilogues are nearly naked -- they just have an
591        rts instruction.  */
592     return;
593
594   /* Deallocate locals.  */
595   h8300_emit_stack_adjustment (1, round_frame_size (get_frame_size ()));
596
597   /* Pop the saved registers in descending order.  */
598   saved_regs = compute_saved_regs ();
599   for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno -= n_regs)
600     {
601       n_regs = 1;
602       if (saved_regs & (1 << regno))
603         {
604           if (TARGET_H8300S)
605             {
606               /* See how many registers we can pop at the same time.  */
607               if ((regno == 7 || regno == 3)
608                   && ((saved_regs >> (regno - 3)) & 0x0f) == 0x0f)
609                 n_regs = 4;
610
611               else if ((regno == 6 || regno == 2)
612                        && ((saved_regs >> (regno - 2)) & 0x07) == 0x07)
613                 n_regs = 3;
614
615               else if ((regno == 7 || regno == 5 || regno == 3 || regno == 1)
616                        && ((saved_regs >> (regno - 1)) & 0x03) == 0x03)
617                 n_regs = 2;
618             }
619
620           switch (n_regs)
621             {
622             case 1:
623               pop (regno);
624               break;
625             case 2:
626               emit_insn (gen_ldm_h8300s_2 (gen_rtx_REG (SImode, regno - 1),
627                                            gen_rtx_REG (SImode, regno)));
628               break;
629             case 3:
630               emit_insn (gen_ldm_h8300s_3 (gen_rtx_REG (SImode, regno - 2),
631                                            gen_rtx_REG (SImode, regno - 1),
632                                            gen_rtx_REG (SImode, regno)));
633               break;
634             case 4:
635               emit_insn (gen_ldm_h8300s_4 (gen_rtx_REG (SImode, regno - 3),
636                                            gen_rtx_REG (SImode, regno - 2),
637                                            gen_rtx_REG (SImode, regno - 1),
638                                            gen_rtx_REG (SImode, regno)));
639               break;
640             default:
641               abort ();
642             }
643         }
644     }
645
646   /* Pop frame pointer if we had one.  */
647   if (frame_pointer_needed)
648     pop (HARD_FRAME_POINTER_REGNUM);
649 }
650
651 /* Return nonzero if the current function is an interrupt
652    function.  */
653
654 int
655 h8300_current_function_interrupt_function_p (void)
656 {
657   return (h8300_interrupt_function_p (current_function_decl)
658           || h8300_monitor_function_p (current_function_decl));
659 }
660
661 /* Output assembly code for the start of the file.  */
662
663 static void
664 h8300_file_start (void)
665 {
666   default_file_start ();
667
668   if (TARGET_H8300H)
669     fputs (TARGET_NORMAL_MODE ? "\t.h8300hn\n" : "\t.h8300h\n", asm_out_file);
670   else if (TARGET_H8300S)
671     fputs (TARGET_NORMAL_MODE ? "\t.h8300sn\n" : "\t.h8300s\n", asm_out_file);
672 }
673
674 /* Output assembly language code for the end of file.  */
675
676 static void
677 h8300_file_end (void)
678 {
679   fputs ("\t.end\n", asm_out_file);
680 }
681 \f
682 /* Return true if OP is a valid source operand for an integer move
683    instruction.  */
684
685 int
686 general_operand_src (rtx op, enum machine_mode mode)
687 {
688   if (GET_MODE (op) == mode
689       && GET_CODE (op) == MEM
690       && GET_CODE (XEXP (op, 0)) == POST_INC)
691     return 1;
692   return general_operand (op, mode);
693 }
694
695 /* Return true if OP is a valid destination operand for an integer move
696    instruction.  */
697
698 int
699 general_operand_dst (rtx op, enum machine_mode mode)
700 {
701   if (GET_MODE (op) == mode
702       && GET_CODE (op) == MEM
703       && GET_CODE (XEXP (op, 0)) == PRE_DEC)
704     return 1;
705   return general_operand (op, mode);
706 }
707
708 /* Return true if OP is a constant that contains only one 1 in its
709    binary representation.  */
710
711 int
712 single_one_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
713 {
714   if (GET_CODE (operand) == CONST_INT)
715     {
716       /* We really need to do this masking because 0x80 in QImode is
717          represented as -128 for example.  */
718       if (exact_log2 (INTVAL (operand) & GET_MODE_MASK (mode)) >= 0)
719         return 1;
720     }
721
722   return 0;
723 }
724
725 /* Return true if OP is a constant that contains only one 0 in its
726    binary representation.  */
727
728 int
729 single_zero_operand (rtx operand, enum machine_mode mode ATTRIBUTE_UNUSED)
730 {
731   if (GET_CODE (operand) == CONST_INT)
732     {
733       /* We really need to do this masking because 0x80 in QImode is
734          represented as -128 for example.  */
735       if (exact_log2 (~INTVAL (operand) & GET_MODE_MASK (mode)) >= 0)
736         return 1;
737     }
738
739   return 0;
740 }
741
742 /* Return true if OP is a valid call operand.  */
743
744 int
745 call_insn_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
746 {
747   if (GET_CODE (op) == MEM)
748     {
749       rtx inside = XEXP (op, 0);
750       if (register_operand (inside, Pmode))
751         return 1;
752       if (CONSTANT_ADDRESS_P (inside))
753         return 1;
754     }
755   return 0;
756 }
757
758 /* Return 1 if an addition/subtraction of a constant integer can be
759    transformed into two consecutive adds/subs that are faster than the
760    straightforward way.  Otherwise, return 0.  */
761
762 int
763 two_insn_adds_subs_operand (rtx op, enum machine_mode mode)
764 {
765   if (GET_CODE (op) == CONST_INT)
766     {
767       HOST_WIDE_INT value = INTVAL (op);
768
769       /* Force VALUE to be positive so that we do not have to consider
770          the negative case.  */
771       if (value < 0)
772         value = -value;
773       if (TARGET_H8300H || TARGET_H8300S)
774         {
775           /* A constant addition/subtraction takes 2 states in QImode,
776              4 states in HImode, and 6 states in SImode.  Thus, the
777              only case we can win is when SImode is used, in which
778              case, two adds/subs are used, taking 4 states.  */
779           if (mode == SImode
780               && (value == 2 + 1
781                   || value == 4 + 1
782                   || value == 4 + 2
783                   || value == 4 + 4))
784             return 1;
785         }
786       else
787         {
788           /* We do not profit directly by splitting addition or
789              subtraction of 3 and 4.  However, since these are
790              implemented as a sequence of adds or subs, they do not
791              clobber (cc0) unlike a sequence of add.b and add.x.  */
792           if (mode == HImode
793               && (value == 2 + 1
794                   || value == 2 + 2))
795             return 1;
796         }
797     }
798
799   return 0;
800 }
801
802 /* Split an add of a small constant into two adds/subs insns.
803
804    If USE_INCDEC_P is nonzero, we generate the last insn using inc/dec
805    instead of adds/subs.  */
806
807 void
808 split_adds_subs (enum machine_mode mode, rtx *operands)
809 {
810   HOST_WIDE_INT val = INTVAL (operands[1]);
811   rtx reg = operands[0];
812   HOST_WIDE_INT sign = 1;
813   HOST_WIDE_INT amount;
814   rtx (*gen_add) (rtx, rtx, rtx);
815
816   /* Force VAL to be positive so that we do not have to consider the
817      sign.  */
818   if (val < 0)
819     {
820       val = -val;
821       sign = -1;
822     }
823
824   switch (mode)
825     {
826     case HImode:
827       gen_add = gen_addhi3;
828       break;
829
830     case SImode:
831       gen_add = gen_addsi3;
832       break;
833
834     default:
835       abort ();
836     }
837
838   /* Try different amounts in descending order.  */
839   for (amount = (TARGET_H8300H || TARGET_H8300S) ? 4 : 2;
840        amount > 0;
841        amount /= 2)
842     {
843       for (; val >= amount; val -= amount)
844         emit_insn (gen_add (reg, reg, GEN_INT (sign * amount)));
845     }
846
847   return;
848 }
849
850 /* Return true if OP is a valid call operand, and OP represents
851    an operand for a small call (4 bytes instead of 6 bytes).  */
852
853 int
854 small_call_insn_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
855 {
856   if (GET_CODE (op) == MEM)
857     {
858       rtx inside = XEXP (op, 0);
859
860       /* Register indirect is a small call.  */
861       if (register_operand (inside, Pmode))
862         return 1;
863
864       /* A call through the function vector is a small call too.  */
865       if (GET_CODE (inside) == SYMBOL_REF
866           && (SYMBOL_REF_FLAGS (inside) & SYMBOL_FLAG_FUNCVEC_FUNCTION))
867         return 1;
868     }
869   /* Otherwise it's a large call.  */
870   return 0;
871 }
872
873 /* Return true if OP is a valid jump operand.  */
874
875 int
876 jump_address_operand (rtx op, enum machine_mode mode)
877 {
878   if (GET_CODE (op) == REG)
879     return mode == Pmode;
880
881   if (GET_CODE (op) == MEM)
882     {
883       rtx inside = XEXP (op, 0);
884       if (register_operand (inside, Pmode))
885         return 1;
886       if (CONSTANT_ADDRESS_P (inside))
887         return 1;
888     }
889   return 0;
890 }
891
892 /* Recognize valid operands for bit-field instructions.  */
893
894 extern int rtx_equal_function_value_matters;
895
896 int
897 bit_operand (rtx op, enum machine_mode mode)
898 {
899   /* We can accept any general operand, except that MEM operands must
900      be limited to those that use addresses valid for the 'U' constraint.  */
901   if (!general_operand (op, mode))
902     return 0;
903
904   /* Accept any mem during RTL generation.  Otherwise, the code that does
905      insv and extzv will think that we can not handle memory.  However,
906      to avoid reload problems, we only accept 'U' MEM operands after RTL
907      generation.  This means that any named pattern which uses this predicate
908      must force its operands to match 'U' before emitting RTL.  */
909
910   if (GET_CODE (op) == REG)
911     return 1;
912   if (GET_CODE (op) == SUBREG)
913     return 1;
914   return (GET_CODE (op) == MEM
915           && EXTRA_CONSTRAINT (op, 'U'));
916 }
917
918 int
919 bit_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
920 {
921   return (GET_CODE (op) == MEM
922           && EXTRA_CONSTRAINT (op, 'U'));
923 }
924
925 /* Handle machine specific pragmas for compatibility with existing
926    compilers for the H8/300.
927
928    pragma saveall generates prologue/epilogue code which saves and
929    restores all the registers on function entry.
930
931    pragma interrupt saves and restores all registers, and exits with
932    an rte instruction rather than an rts.  A pointer to a function
933    with this attribute may be safely used in an interrupt vector.  */
934
935 void
936 h8300_pr_interrupt (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
937 {
938   pragma_interrupt = 1;
939 }
940
941 void
942 h8300_pr_saveall (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
943 {
944   pragma_saveall = 1;
945 }
946
947 /* If the next function argument with MODE and TYPE is to be passed in
948    a register, return a reg RTX for the hard register in which to pass
949    the argument.  CUM represents the state after the last argument.
950    If the argument is to be pushed, NULL_RTX is returned.  */
951
952 rtx
953 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
954               tree type, int named)
955 {
956   static const char *const hand_list[] = {
957     "__main",
958     "__cmpsi2",
959     "__divhi3",
960     "__modhi3",
961     "__udivhi3",
962     "__umodhi3",
963     "__divsi3",
964     "__modsi3",
965     "__udivsi3",
966     "__umodsi3",
967     "__mulhi3",
968     "__mulsi3",
969     "__reg_memcpy",
970     "__reg_memset",
971     "__ucmpsi2",
972     0,
973   };
974
975   rtx result = NULL_RTX;
976   const char *fname;
977   int regpass = 0;
978
979   /* Never pass unnamed arguments in registers.  */
980   if (!named)
981     return NULL_RTX;
982
983   /* Pass 3 regs worth of data in regs when user asked on the command line.  */
984   if (TARGET_QUICKCALL)
985     regpass = 3;
986
987   /* If calling hand written assembler, use 4 regs of args.  */
988   if (cum->libcall)
989     {
990       const char * const *p;
991
992       fname = XSTR (cum->libcall, 0);
993
994       /* See if this libcall is one of the hand coded ones.  */
995       for (p = hand_list; *p && strcmp (*p, fname) != 0; p++)
996         ;
997
998       if (*p)
999         regpass = 4;
1000     }
1001
1002   if (regpass)
1003     {
1004       int size;
1005
1006       if (mode == BLKmode)
1007         size = int_size_in_bytes (type);
1008       else
1009         size = GET_MODE_SIZE (mode);
1010
1011       if (size + cum->nbytes <= regpass * UNITS_PER_WORD
1012           && cum->nbytes / UNITS_PER_WORD <= 3)
1013         result = gen_rtx_REG (mode, cum->nbytes / UNITS_PER_WORD);
1014     }
1015
1016   return result;
1017 }
1018 \f
1019 static int
1020 h8300_and_costs (rtx x)
1021 {
1022   rtx operands[4];
1023
1024   if (GET_MODE (x) == QImode)
1025     return 1;
1026
1027   if (GET_MODE (x) != HImode
1028       && GET_MODE (x) != SImode)
1029     return 100;
1030
1031   operands[0] = NULL;
1032   operands[1] = NULL;
1033   operands[2] = XEXP (x, 1);
1034   operands[3] = x;
1035   return compute_logical_op_length (GET_MODE (x), operands) / 2;
1036 }
1037
1038 static int
1039 h8300_shift_costs (rtx x)
1040 {
1041   rtx operands[4];
1042
1043   if (GET_MODE (x) != QImode
1044       && GET_MODE (x) != HImode
1045       && GET_MODE (x) != SImode)
1046     return 100;
1047
1048   operands[0] = NULL;
1049   operands[1] = NULL;
1050   operands[2] = XEXP (x, 1);
1051   operands[3] = x;
1052   return compute_a_shift_length (NULL, operands) / 2;
1053 }
1054
1055 static bool
1056 h8300_rtx_costs (rtx x, int code, int outer_code, int *total)
1057 {
1058   switch (code)
1059     {
1060     case CONST_INT:
1061       {
1062         HOST_WIDE_INT n = INTVAL (x);
1063
1064         if (-4 <= n || n <= 4)
1065           {
1066             switch ((int) n)
1067               {
1068               case 0:
1069                 *total = 0;
1070                 return true;
1071               case 1:
1072               case 2:
1073               case -1:
1074               case -2:
1075                 *total = 0 + (outer_code == SET);
1076                 return true;
1077               case 4:
1078               case -4:
1079                 if (TARGET_H8300H || TARGET_H8300S)
1080                   *total = 0 + (outer_code == SET);
1081                 else
1082                   *total = 1;
1083                 return true;
1084               }
1085           }
1086         *total = 1;
1087         return true;
1088       }
1089
1090     case CONST:
1091     case LABEL_REF:
1092     case SYMBOL_REF:
1093       *total = 3;
1094       return true;
1095
1096     case CONST_DOUBLE:
1097       *total = 20;
1098       return true;
1099
1100     case AND:
1101       *total = COSTS_N_INSNS (h8300_and_costs (x));
1102       return true;
1103
1104     /* We say that MOD and DIV are so expensive because otherwise we'll
1105        generate some really horrible code for division of a power of two.  */
1106     case MOD:
1107     case DIV:
1108       *total = 60;
1109       return true;
1110
1111     case MULT:
1112       *total = 20;
1113       return true;
1114
1115     case ASHIFT:
1116     case ASHIFTRT:
1117     case LSHIFTRT:
1118       *total = COSTS_N_INSNS (h8300_shift_costs (x));
1119       return true;
1120
1121     case ROTATE:
1122     case ROTATERT:
1123       if (GET_MODE (x) == HImode)
1124         *total = 2;
1125       else
1126         *total = 8;
1127       return true;
1128
1129     default:
1130       *total = 4;
1131       return true;
1132     }
1133 }
1134 \f
1135 /* Documentation for the machine specific operand escapes:
1136
1137    'E' like s but negative.
1138    'F' like t but negative.
1139    'G' constant just the negative
1140    'R' print operand as a byte:8 address if appropriate, else fall back to
1141        'X' handling.
1142    'S' print operand as a long word
1143    'T' print operand as a word
1144    'V' find the set bit, and print its number.
1145    'W' find the clear bit, and print its number.
1146    'X' print operand as a byte
1147    'Y' print either l or h depending on whether last 'Z' operand < 8 or >= 8.
1148        If this operand isn't a register, fall back to 'R' handling.
1149    'Z' print int & 7.
1150    'c' print the opcode corresponding to rtl
1151    'e' first word of 32 bit value - if reg, then least reg. if mem
1152        then least. if const then most sig word
1153    'f' second word of 32 bit value - if reg, then biggest reg. if mem
1154        then +2. if const then least sig word
1155    'j' print operand as condition code.
1156    'k' print operand as reverse condition code.
1157    's' print as low byte of 16 bit value
1158    't' print as high byte of 16 bit value
1159    'w' print as low byte of 32 bit value
1160    'x' print as 2nd byte of 32 bit value
1161    'y' print as 3rd byte of 32 bit value
1162    'z' print as msb of 32 bit value
1163 */
1164
1165 /* Return assembly language string which identifies a comparison type.  */
1166
1167 static const char *
1168 cond_string (enum rtx_code code)
1169 {
1170   switch (code)
1171     {
1172     case NE:
1173       return "ne";
1174     case EQ:
1175       return "eq";
1176     case GE:
1177       return "ge";
1178     case GT:
1179       return "gt";
1180     case LE:
1181       return "le";
1182     case LT:
1183       return "lt";
1184     case GEU:
1185       return "hs";
1186     case GTU:
1187       return "hi";
1188     case LEU:
1189       return "ls";
1190     case LTU:
1191       return "lo";
1192     default:
1193       abort ();
1194     }
1195 }
1196
1197 /* Print operand X using operand code CODE to assembly language output file
1198    FILE.  */
1199
1200 void
1201 print_operand (FILE *file, rtx x, int code)
1202 {
1203   /* This is used for communication between codes V,W,Z and Y.  */
1204   static int bitint;
1205
1206   switch (code)
1207     {
1208     case 'E':
1209       switch (GET_CODE (x))
1210         {
1211         case REG:
1212           fprintf (file, "%sl", names_big[REGNO (x)]);
1213           break;
1214         case CONST_INT:
1215           fprintf (file, "#%ld", (-INTVAL (x)) & 0xff);
1216           break;
1217         default:
1218           abort ();
1219         }
1220       break;
1221     case 'F':
1222       switch (GET_CODE (x))
1223         {
1224         case REG:
1225           fprintf (file, "%sh", names_big[REGNO (x)]);
1226           break;
1227         case CONST_INT:
1228           fprintf (file, "#%ld", ((-INTVAL (x)) & 0xff00) >> 8);
1229           break;
1230         default:
1231           abort ();
1232         }
1233       break;
1234     case 'G':
1235       if (GET_CODE (x) != CONST_INT)
1236         abort ();
1237       fprintf (file, "#%ld", 0xff & (-INTVAL (x)));
1238       break;
1239     case 'S':
1240       if (GET_CODE (x) == REG)
1241         fprintf (file, "%s", names_extended[REGNO (x)]);
1242       else
1243         goto def;
1244       break;
1245     case 'T':
1246       if (GET_CODE (x) == REG)
1247         fprintf (file, "%s", names_big[REGNO (x)]);
1248       else
1249         goto def;
1250       break;
1251     case 'V':
1252       bitint = exact_log2 (INTVAL (x) & 0xff);
1253       if (bitint == -1)
1254         abort ();
1255       fprintf (file, "#%d", bitint);
1256       break;
1257     case 'W':
1258       bitint = exact_log2 ((~INTVAL (x)) & 0xff);
1259       if (bitint == -1)
1260         abort ();
1261       fprintf (file, "#%d", bitint);
1262       break;
1263     case 'R':
1264     case 'X':
1265       if (GET_CODE (x) == REG)
1266         fprintf (file, "%s", byte_reg (x, 0));
1267       else
1268         goto def;
1269       break;
1270     case 'Y':
1271       if (bitint == -1)
1272         abort ();
1273       if (GET_CODE (x) == REG)
1274         fprintf (file, "%s%c", names_big[REGNO (x)], bitint > 7 ? 'h' : 'l');
1275       else
1276         print_operand (file, x, 'R');
1277       bitint = -1;
1278       break;
1279     case 'Z':
1280       bitint = INTVAL (x);
1281       fprintf (file, "#%d", bitint & 7);
1282       break;
1283     case 'c':
1284       switch (GET_CODE (x))
1285         {
1286         case IOR:
1287           fprintf (file, "or");
1288           break;
1289         case XOR:
1290           fprintf (file, "xor");
1291           break;
1292         case AND:
1293           fprintf (file, "and");
1294           break;
1295         default:
1296           break;
1297         }
1298       break;
1299     case 'e':
1300       switch (GET_CODE (x))
1301         {
1302         case REG:
1303           if (TARGET_H8300)
1304             fprintf (file, "%s", names_big[REGNO (x)]);
1305           else
1306             fprintf (file, "%s", names_upper_extended[REGNO (x)]);
1307           break;
1308         case MEM:
1309           print_operand (file, x, 0);
1310           break;
1311         case CONST_INT:
1312           fprintf (file, "#%ld", ((INTVAL (x) >> 16) & 0xffff));
1313           break;
1314         case CONST_DOUBLE:
1315           {
1316             long val;
1317             REAL_VALUE_TYPE rv;
1318             REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
1319             REAL_VALUE_TO_TARGET_SINGLE (rv, val);
1320             fprintf (file, "#%ld", ((val >> 16) & 0xffff));
1321             break;
1322           }
1323         default:
1324           abort ();
1325           break;
1326         }
1327       break;
1328     case 'f':
1329       switch (GET_CODE (x))
1330         {
1331         case REG:
1332           if (TARGET_H8300)
1333             fprintf (file, "%s", names_big[REGNO (x) + 1]);
1334           else
1335             fprintf (file, "%s", names_big[REGNO (x)]);
1336           break;
1337         case MEM:
1338           x = adjust_address (x, HImode, 2);
1339           print_operand (file, x, 0);
1340           break;
1341         case CONST_INT:
1342           fprintf (file, "#%ld", INTVAL (x) & 0xffff);
1343           break;
1344         case CONST_DOUBLE:
1345           {
1346             long val;
1347             REAL_VALUE_TYPE rv;
1348             REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
1349             REAL_VALUE_TO_TARGET_SINGLE (rv, val);
1350             fprintf (file, "#%ld", (val & 0xffff));
1351             break;
1352           }
1353         default:
1354           abort ();
1355         }
1356       break;
1357     case 'j':
1358       fputs (cond_string (GET_CODE (x)), file);
1359       break;
1360     case 'k':
1361       fputs (cond_string (reverse_condition (GET_CODE (x))), file);
1362       break;
1363     case 's':
1364       if (GET_CODE (x) == CONST_INT)
1365         fprintf (file, "#%ld", (INTVAL (x)) & 0xff);
1366       else
1367         fprintf (file, "%s", byte_reg (x, 0));
1368       break;
1369     case 't':
1370       if (GET_CODE (x) == CONST_INT)
1371         fprintf (file, "#%ld", (INTVAL (x) >> 8) & 0xff);
1372       else
1373         fprintf (file, "%s", byte_reg (x, 1));
1374       break;
1375     case 'w':
1376       if (GET_CODE (x) == CONST_INT)
1377         fprintf (file, "#%ld", INTVAL (x) & 0xff);
1378       else
1379         fprintf (file, "%s",
1380                  byte_reg (x, TARGET_H8300 ? 2 : 0));
1381       break;
1382     case 'x':
1383       if (GET_CODE (x) == CONST_INT)
1384         fprintf (file, "#%ld", (INTVAL (x) >> 8) & 0xff);
1385       else
1386         fprintf (file, "%s",
1387                  byte_reg (x, TARGET_H8300 ? 3 : 1));
1388       break;
1389     case 'y':
1390       if (GET_CODE (x) == CONST_INT)
1391         fprintf (file, "#%ld", (INTVAL (x) >> 16) & 0xff);
1392       else
1393         fprintf (file, "%s", byte_reg (x, 0));
1394       break;
1395     case 'z':
1396       if (GET_CODE (x) == CONST_INT)
1397         fprintf (file, "#%ld", (INTVAL (x) >> 24) & 0xff);
1398       else
1399         fprintf (file, "%s", byte_reg (x, 1));
1400       break;
1401
1402     default:
1403     def:
1404       switch (GET_CODE (x))
1405         {
1406         case REG:
1407           switch (GET_MODE (x))
1408             {
1409             case QImode:
1410 #if 0 /* Is it asm ("mov.b %0,r2l", ...) */
1411               fprintf (file, "%s", byte_reg (x, 0));
1412 #else /* ... or is it asm ("mov.b %0l,r2l", ...) */
1413               fprintf (file, "%s", names_big[REGNO (x)]);
1414 #endif
1415               break;
1416             case HImode:
1417               fprintf (file, "%s", names_big[REGNO (x)]);
1418               break;
1419             case SImode:
1420             case SFmode:
1421               fprintf (file, "%s", names_extended[REGNO (x)]);
1422               break;
1423             default:
1424               abort ();
1425             }
1426           break;
1427
1428         case MEM:
1429           {
1430             rtx addr = XEXP (x, 0);
1431
1432             fprintf (file, "@");
1433             output_address (addr);
1434
1435             /* We fall back from smaller addressing to larger
1436                addressing in various ways depending on CODE.  */
1437             switch (code)
1438               {
1439               case 'R':
1440                 /* Used for mov.b and bit operations.  */
1441                 if (h8300_eightbit_constant_address_p (addr))
1442                   {
1443                     fprintf (file, ":8");
1444                     break;
1445                   }
1446
1447                 /* Fall through.  We should not get here if we are
1448                    processing bit operations on H8/300 or H8/300H
1449                    because 'U' constraint does not allow bit
1450                    operations on the tiny area on these machines.  */
1451
1452               case 'T':
1453               case 'S':
1454                 /* Used for mov.w and mov.l.  */
1455                 if (h8300_tiny_constant_address_p (addr))
1456                   fprintf (file, ":16");
1457                 break;
1458               default:
1459                 break;
1460               }
1461           }
1462           break;
1463
1464         case CONST_INT:
1465         case SYMBOL_REF:
1466         case CONST:
1467         case LABEL_REF:
1468           fprintf (file, "#");
1469           print_operand_address (file, x);
1470           break;
1471         case CONST_DOUBLE:
1472           {
1473             long val;
1474             REAL_VALUE_TYPE rv;
1475             REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
1476             REAL_VALUE_TO_TARGET_SINGLE (rv, val);
1477             fprintf (file, "#%ld", val);
1478             break;
1479           }
1480         default:
1481           break;
1482         }
1483     }
1484 }
1485
1486 /* Output assembly language output for the address ADDR to FILE.  */
1487
1488 void
1489 print_operand_address (FILE *file, rtx addr)
1490 {
1491   switch (GET_CODE (addr))
1492     {
1493     case REG:
1494       fprintf (file, "%s", h8_reg_names[REGNO (addr)]);
1495       break;
1496
1497     case PRE_DEC:
1498       fprintf (file, "-%s", h8_reg_names[REGNO (XEXP (addr, 0))]);
1499       break;
1500
1501     case POST_INC:
1502       fprintf (file, "%s+", h8_reg_names[REGNO (XEXP (addr, 0))]);
1503       break;
1504
1505     case PLUS:
1506       fprintf (file, "(");
1507       if (GET_CODE (XEXP (addr, 0)) == REG)
1508         {
1509           /* reg,foo */
1510           print_operand_address (file, XEXP (addr, 1));
1511           fprintf (file, ",");
1512           print_operand_address (file, XEXP (addr, 0));
1513         }
1514       else
1515         {
1516           /* foo+k */
1517           print_operand_address (file, XEXP (addr, 0));
1518           fprintf (file, "+");
1519           print_operand_address (file, XEXP (addr, 1));
1520         }
1521       fprintf (file, ")");
1522       break;
1523
1524     case CONST_INT:
1525       {
1526         /* Since the H8/300 only has 16 bit pointers, negative values are also
1527            those >= 32768.  This happens for example with pointer minus a
1528            constant.  We don't want to turn (char *p - 2) into
1529            (char *p + 65534) because loop unrolling can build upon this
1530            (IE: char *p + 131068).  */
1531         int n = INTVAL (addr);
1532         if (TARGET_H8300)
1533           n = (int) (short) n;
1534         fprintf (file, "%d", n);
1535         break;
1536       }
1537
1538     default:
1539       output_addr_const (file, addr);
1540       break;
1541     }
1542 }
1543 \f
1544 /* Output all insn addresses and their sizes into the assembly language
1545    output file.  This is helpful for debugging whether the length attributes
1546    in the md file are correct.  This is not meant to be a user selectable
1547    option.  */
1548
1549 void
1550 final_prescan_insn (rtx insn, rtx *operand ATTRIBUTE_UNUSED,
1551                     int num_operands ATTRIBUTE_UNUSED)
1552 {
1553   /* This holds the last insn address.  */
1554   static int last_insn_address = 0;
1555
1556   const int uid = INSN_UID (insn);
1557
1558   if (TARGET_ADDRESSES)
1559     {
1560       fprintf (asm_out_file, "; 0x%x %d\n", INSN_ADDRESSES (uid),
1561                INSN_ADDRESSES (uid) - last_insn_address);
1562       last_insn_address = INSN_ADDRESSES (uid);
1563     }
1564 }
1565
1566 /* Prepare for an SI sized move.  */
1567
1568 int
1569 h8300_expand_movsi (rtx operands[])
1570 {
1571   rtx src = operands[1];
1572   rtx dst = operands[0];
1573   if (!reload_in_progress && !reload_completed)
1574     {
1575       if (!register_operand (dst, GET_MODE (dst)))
1576         {
1577           rtx tmp = gen_reg_rtx (GET_MODE (dst));
1578           emit_move_insn (tmp, src);
1579           operands[1] = tmp;
1580         }
1581     }
1582   return 0;
1583 }
1584
1585 /* Function for INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET).
1586    Define the offset between two registers, one to be eliminated, and
1587    the other its replacement, at the start of a routine.  */
1588
1589 int
1590 h8300_initial_elimination_offset (int from, int to)
1591 {
1592   /* The number of bytes that the return address takes on the stack.  */
1593   int pc_size = POINTER_SIZE / BITS_PER_UNIT;
1594
1595   /* The number of bytes that the saved frame pointer takes on the stack.  */
1596   int fp_size = frame_pointer_needed * UNITS_PER_WORD;
1597
1598   /* The number of bytes that the saved registers, excluding the frame
1599      pointer, take on the stack.  */
1600   int saved_regs_size = 0;
1601
1602   /* The number of bytes that the locals takes on the stack.  */
1603   int frame_size = round_frame_size (get_frame_size ());
1604
1605   int regno;
1606
1607   for (regno = 0; regno <= HARD_FRAME_POINTER_REGNUM; regno++)
1608     if (WORD_REG_USED (regno))
1609       saved_regs_size += UNITS_PER_WORD;
1610
1611   /* Adjust saved_regs_size because the above loop took the frame
1612      pointer int account.  */
1613   saved_regs_size -= fp_size;
1614
1615   if (to == HARD_FRAME_POINTER_REGNUM)
1616     {
1617       switch (from)
1618         {
1619         case ARG_POINTER_REGNUM:
1620           return pc_size + fp_size;
1621         case RETURN_ADDRESS_POINTER_REGNUM:
1622           return fp_size;
1623         case FRAME_POINTER_REGNUM:
1624           return -saved_regs_size;
1625         default:
1626           abort ();
1627         }
1628     }
1629   else if (to == STACK_POINTER_REGNUM)
1630     {
1631       switch (from)
1632         {
1633         case ARG_POINTER_REGNUM:
1634           return pc_size + saved_regs_size + frame_size;
1635         case RETURN_ADDRESS_POINTER_REGNUM:
1636           return saved_regs_size + frame_size;
1637         case FRAME_POINTER_REGNUM:
1638           return frame_size;
1639         default:
1640           abort ();
1641         }
1642     }
1643   else
1644     abort ();
1645 }
1646
1647 rtx
1648 h8300_return_addr_rtx (int count, rtx frame)
1649 {
1650   rtx ret;
1651
1652   if (count == 0)
1653     ret = gen_rtx_MEM (Pmode,
1654                        gen_rtx_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM));
1655   else if (flag_omit_frame_pointer)
1656     return (rtx) 0;
1657   else
1658     ret = gen_rtx_MEM (Pmode,
1659                        memory_address (Pmode,
1660                                        plus_constant (frame, UNITS_PER_WORD)));
1661   set_mem_alias_set (ret, get_frame_alias_set ());
1662   return ret;
1663 }
1664
1665 /* Update the condition code from the insn.  */
1666
1667 void
1668 notice_update_cc (rtx body, rtx insn)
1669 {
1670   rtx set;
1671
1672   switch (get_attr_cc (insn))
1673     {
1674     case CC_NONE:
1675       /* Insn does not affect CC at all.  */
1676       break;
1677
1678     case CC_NONE_0HIT:
1679       /* Insn does not change CC, but the 0'th operand has been changed.  */
1680       if (cc_status.value1 != 0
1681           && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
1682         cc_status.value1 = 0;
1683       if (cc_status.value2 != 0
1684           && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value2))
1685         cc_status.value2 = 0;
1686       break;
1687
1688     case CC_SET_ZN:
1689       /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1690          The V flag is unusable.  The C flag may or may not be known but
1691          that's ok because alter_cond will change tests to use EQ/NE.  */
1692       CC_STATUS_INIT;
1693       cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
1694       set = single_set (insn);
1695       cc_status.value1 = SET_SRC (set);
1696       if (SET_DEST (set) != cc0_rtx)
1697         cc_status.value2 = SET_DEST (set);
1698       break;
1699
1700     case CC_SET_ZNV:
1701       /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
1702          The C flag may or may not be known but that's ok because
1703          alter_cond will change tests to use EQ/NE.  */
1704       CC_STATUS_INIT;
1705       cc_status.flags |= CC_NO_CARRY;
1706       set = single_set (insn);
1707       cc_status.value1 = SET_SRC (set);
1708       if (SET_DEST (set) != cc0_rtx)
1709         {
1710           /* If the destination is STRICT_LOW_PART, strip off
1711              STRICT_LOW_PART.  */
1712           if (GET_CODE (SET_DEST (set)) == STRICT_LOW_PART)
1713             cc_status.value2 = XEXP (SET_DEST (set), 0);
1714           else
1715             cc_status.value2 = SET_DEST (set);
1716         }
1717       break;
1718
1719     case CC_COMPARE:
1720       /* The insn is a compare instruction.  */
1721       CC_STATUS_INIT;
1722       cc_status.value1 = SET_SRC (body);
1723       break;
1724
1725     case CC_CLOBBER:
1726       /* Insn doesn't leave CC in a usable state.  */
1727       CC_STATUS_INIT;
1728       break;
1729     }
1730 }
1731
1732 /* Return nonzero if X is a stack pointer.  */
1733
1734 int
1735 stack_pointer_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1736 {
1737   return x == stack_pointer_rtx;
1738 }
1739
1740 /* Return nonzero if X is a constant whose absolute value is greater
1741    than 2.  */
1742
1743 int
1744 const_int_gt_2_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1745 {
1746   return (GET_CODE (x) == CONST_INT
1747           && abs (INTVAL (x)) > 2);
1748 }
1749
1750 /* Return nonzero if X is a constant whose absolute value is no
1751    smaller than 8.  */
1752
1753 int
1754 const_int_ge_8_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1755 {
1756   return (GET_CODE (x) == CONST_INT
1757           && abs (INTVAL (x)) >= 8);
1758 }
1759
1760 /* Return nonzero if X is a constant expressible in QImode.  */
1761
1762 int
1763 const_int_qi_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1764 {
1765   return (GET_CODE (x) == CONST_INT
1766           && (INTVAL (x) & 0xff) == INTVAL (x));
1767 }
1768
1769 /* Return nonzero if X is a constant expressible in HImode.  */
1770
1771 int
1772 const_int_hi_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1773 {
1774   return (GET_CODE (x) == CONST_INT
1775           && (INTVAL (x) & 0xffff) == INTVAL (x));
1776 }
1777
1778 /* Return nonzero if X is a constant suitable for inc/dec.  */
1779
1780 int
1781 incdec_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1782 {
1783   return (GET_CODE (x) == CONST_INT
1784           && (CONST_OK_FOR_M (INTVAL (x))
1785               || CONST_OK_FOR_O (INTVAL (x))));
1786 }
1787
1788 /* Return nonzero if X is either EQ or NE.  */
1789
1790 int
1791 eqne_operator (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1792 {
1793   enum rtx_code code = GET_CODE (x);
1794
1795   return (code == EQ || code == NE);
1796 }
1797
1798 /* Return nonzero if X is GT, LE, GTU, or LEU.  */
1799
1800 int
1801 gtle_operator (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1802 {
1803   enum rtx_code code = GET_CODE (x);
1804
1805   return (code == GT || code == LE || code == GTU || code == LEU);
1806 }
1807
1808 /* Return nonzero if X is either GTU or LEU.  */
1809
1810 int
1811 gtuleu_operator (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1812 {
1813   enum rtx_code code = GET_CODE (x);
1814
1815   return (code == GTU || code == LEU);
1816 }
1817
1818 /* Return nonzero if X is either IOR or XOR.  */
1819
1820 int
1821 iorxor_operator (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1822 {
1823   enum rtx_code code = GET_CODE (x);
1824
1825   return (code == IOR || code == XOR);
1826 }
1827
1828 /* Recognize valid operators for bit instructions.  */
1829
1830 int
1831 bit_operator (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1832 {
1833   enum rtx_code code = GET_CODE (x);
1834
1835   return (code == XOR
1836           || code == AND
1837           || code == IOR);
1838 }
1839 \f
1840 /* Return the length of mov instruction.  */
1841
1842 unsigned int
1843 compute_mov_length (rtx *operands)
1844 {
1845   /* If the mov instruction involves a memory operand, we compute the
1846      length, assuming the largest addressing mode is used, and then
1847      adjust later in the function.  Otherwise, we compute and return
1848      the exact length in one step.  */
1849   enum machine_mode mode = GET_MODE (operands[0]);
1850   rtx dest = operands[0];
1851   rtx src = operands[1];
1852   rtx addr;
1853
1854   if (GET_CODE (src) == MEM)
1855     addr = XEXP (src, 0);
1856   else if (GET_CODE (dest) == MEM)
1857     addr = XEXP (dest, 0);
1858   else
1859     addr = NULL_RTX;
1860
1861   if (TARGET_H8300)
1862     {
1863       unsigned int base_length;
1864
1865       switch (mode)
1866         {
1867         case QImode:
1868           if (addr == NULL_RTX)
1869             return 2;
1870
1871           /* The eightbit addressing is available only in QImode, so
1872              go ahead and take care of it.  */
1873           if (h8300_eightbit_constant_address_p (addr))
1874             return 2;
1875
1876           base_length = 4;
1877           break;
1878
1879         case HImode:
1880           if (addr == NULL_RTX)
1881             {
1882               if (REG_P (src))
1883                 return 2;
1884
1885               if (src == const0_rtx)
1886                 return 2;
1887
1888               return 4;
1889             }
1890
1891           base_length = 4;
1892           break;
1893
1894         case SImode:
1895           if (addr == NULL_RTX)
1896             {
1897               if (REG_P (src))
1898                 return 4;
1899
1900               if (GET_CODE (src) == CONST_INT)
1901                 {
1902                   if (src == const0_rtx)
1903                     return 4;
1904
1905                   if ((INTVAL (src) & 0xffff) == 0)
1906                     return 6;
1907
1908                   if ((INTVAL (src) & 0xffff) == 0)
1909                     return 6;
1910
1911                   if ((INTVAL (src) & 0xffff)
1912                       == ((INTVAL (src) >> 16) & 0xffff))
1913                     return 6;
1914                 }
1915               return 8;
1916             }
1917
1918           base_length = 8;
1919           break;
1920
1921         case SFmode:
1922           if (addr == NULL_RTX)
1923             {
1924               if (REG_P (src))
1925                 return 4;
1926
1927               if (CONST_DOUBLE_OK_FOR_LETTER_P (src, 'G'))
1928                 return 4;
1929
1930               return 8;
1931             }
1932
1933           base_length = 8;
1934           break;
1935
1936         default:
1937           abort ();
1938         }
1939
1940       /* Adjust the length based on the addressing mode used.
1941          Specifically, we subtract the difference between the actual
1942          length and the longest one, which is @(d:16,Rs).  For SImode
1943          and SFmode, we double the adjustment because two mov.w are
1944          used to do the job.  */
1945
1946       /* @Rs+ and @-Rd are 2 bytes shorter than the longest.  */
1947       if (GET_CODE (addr) == PRE_DEC
1948           || GET_CODE (addr) == POST_INC)
1949         {
1950           if (mode == QImode || mode == HImode)
1951             return base_length - 2;
1952           else
1953             /* In SImode and SFmode, we use two mov.w instructions, so
1954                double the adjustment.  */
1955             return base_length - 4;
1956         }
1957
1958       /* @Rs and @Rd are 2 bytes shorter than the longest.  Note that
1959          in SImode and SFmode, the second mov.w involves an address
1960          with displacement, namely @(2,Rs) or @(2,Rd), so we subtract
1961          only 2 bytes.  */
1962       if (GET_CODE (addr) == REG)
1963         return base_length - 2;
1964
1965       return base_length;
1966     }
1967   else
1968     {
1969       unsigned int base_length;
1970
1971       switch (mode)
1972         {
1973         case QImode:
1974           if (addr == NULL_RTX)
1975             return 2;
1976
1977           /* The eightbit addressing is available only in QImode, so
1978              go ahead and take care of it.  */
1979           if (h8300_eightbit_constant_address_p (addr))
1980             return 2;
1981
1982           base_length = 8;
1983           break;
1984
1985         case HImode:
1986           if (addr == NULL_RTX)
1987             {
1988               if (REG_P (src))
1989                 return 2;
1990
1991               if (src == const0_rtx)
1992                 return 2;
1993
1994               return 4;
1995             }
1996
1997           base_length = 8;
1998           break;
1999
2000         case SImode:
2001           if (addr == NULL_RTX)
2002             {
2003               if (REG_P (src))
2004                 {
2005                   if (REGNO (src) == MAC_REG || REGNO (dest) == MAC_REG)
2006                     return 4;
2007                   else
2008                     return 2;
2009                 }
2010
2011               if (GET_CODE (src) == CONST_INT)
2012                 {
2013                   int val = INTVAL (src);
2014
2015                   if (val == 0)
2016                     return 2;
2017
2018                   if (val == (val & 0x00ff) || val == (val & 0xff00))
2019                     return 4;
2020
2021                   switch (val & 0xffffffff)
2022                     {
2023                     case 0xffffffff:
2024                     case 0xfffffffe:
2025                     case 0xfffffffc:
2026                     case 0x0000ffff:
2027                     case 0x0000fffe:
2028                     case 0xffff0000:
2029                     case 0xfffe0000:
2030                     case 0x00010000:
2031                     case 0x00020000:
2032                       return 4;
2033                     }
2034                 }
2035               return 6;
2036             }
2037
2038           base_length = 10;
2039           break;
2040
2041         case SFmode:
2042           if (addr == NULL_RTX)
2043             {
2044               if (REG_P (src))
2045                 return 2;
2046
2047               if (CONST_DOUBLE_OK_FOR_LETTER_P (src, 'G'))
2048                 return 2;
2049
2050               return 6;
2051             }
2052
2053           base_length = 10;
2054           break;
2055
2056         default:
2057           abort ();
2058         }
2059
2060       /* Adjust the length based on the addressing mode used.
2061          Specifically, we subtract the difference between the actual
2062          length and the longest one, which is @(d:24,ERs).  */
2063
2064       /* @ERs+ and @-ERd are 6 bytes shorter than the longest.  */
2065       if (GET_CODE (addr) == PRE_DEC
2066           || GET_CODE (addr) == POST_INC)
2067         return base_length - 6;
2068
2069       /* @ERs and @ERd are 6 bytes shorter than the longest.  */
2070       if (GET_CODE (addr) == REG)
2071         return base_length - 6;
2072
2073       /* @(d:16,ERs) and @(d:16,ERd) are 4 bytes shorter than the
2074          longest.  */
2075       if (GET_CODE (addr) == PLUS
2076           && GET_CODE (XEXP (addr, 0)) == REG
2077           && GET_CODE (XEXP (addr, 1)) == CONST_INT
2078           && INTVAL (XEXP (addr, 1)) > -32768
2079           && INTVAL (XEXP (addr, 1)) < 32767)
2080         return base_length - 4;
2081
2082       /* @aa:16 is 4 bytes shorter than the longest.  */
2083       if (h8300_tiny_constant_address_p (addr))
2084         return base_length - 4;
2085
2086       /* @aa:24 is 2 bytes shorter than the longest.  */
2087       if (CONSTANT_P (addr))
2088         return base_length - 2;
2089
2090       return base_length;
2091     }
2092 }
2093 \f
2094 const char *
2095 output_plussi (rtx *operands)
2096 {
2097   enum machine_mode mode = GET_MODE (operands[0]);
2098
2099   if (mode != SImode)
2100     abort ();
2101
2102   if (TARGET_H8300)
2103     {
2104       if (GET_CODE (operands[2]) == REG)
2105         return "add.w\t%f2,%f0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
2106
2107       if (GET_CODE (operands[2]) == CONST_INT)
2108         {
2109           HOST_WIDE_INT n = INTVAL (operands[2]);
2110
2111           if ((n & 0xffffff) == 0)
2112             return "add\t%z2,%z0";
2113           if ((n & 0xffff) == 0)
2114             return "add\t%y2,%y0\n\taddx\t%z2,%z0";
2115           if ((n & 0xff) == 0)
2116             return "add\t%x2,%x0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
2117         }
2118
2119       return "add\t%w2,%w0\n\taddx\t%x2,%x0\n\taddx\t%y2,%y0\n\taddx\t%z2,%z0";
2120     }
2121   else
2122     {
2123       if (GET_CODE (operands[2]) == REG)
2124         return "add.l\t%S2,%S0";
2125
2126       if (GET_CODE (operands[2]) == CONST_INT)
2127         {
2128           HOST_WIDE_INT intval = INTVAL (operands[2]);
2129
2130           /* See if we can finish with 2 bytes.  */
2131
2132           switch ((unsigned int) intval & 0xffffffff)
2133             {
2134             case 0x00000001:
2135             case 0x00000002:
2136             case 0x00000004:
2137               return "adds\t%2,%S0";
2138
2139             case 0xffffffff:
2140             case 0xfffffffe:
2141             case 0xfffffffc:
2142               return "subs\t%G2,%S0";
2143
2144             case 0x00010000:
2145             case 0x00020000:
2146               operands[2] = GEN_INT (intval >> 16);
2147               return "inc.w\t%2,%e0";
2148
2149             case 0xffff0000:
2150             case 0xfffe0000:
2151               operands[2] = GEN_INT (intval >> 16);
2152               return "dec.w\t%G2,%e0";
2153             }
2154
2155           /* See if we can finish with 4 bytes.  */
2156           if ((intval & 0xffff) == 0)
2157             {
2158               operands[2] = GEN_INT (intval >> 16);
2159               return "add.w\t%2,%e0";
2160             }
2161         }
2162
2163       return "add.l\t%S2,%S0";
2164     }
2165 }
2166
2167 unsigned int
2168 compute_plussi_length (rtx *operands)
2169 {
2170   enum machine_mode mode = GET_MODE (operands[0]);
2171
2172   if (mode != SImode)
2173     abort ();
2174
2175   if (TARGET_H8300)
2176     {
2177       if (GET_CODE (operands[2]) == REG)
2178         return 6;
2179
2180       if (GET_CODE (operands[2]) == CONST_INT)
2181         {
2182           HOST_WIDE_INT n = INTVAL (operands[2]);
2183
2184           if ((n & 0xffffff) == 0)
2185             return 2;
2186           if ((n & 0xffff) == 0)
2187             return 4;
2188           if ((n & 0xff) == 0)
2189             return 6;
2190         }
2191
2192       return 8;
2193     }
2194   else
2195     {
2196       if (GET_CODE (operands[2]) == REG)
2197         return 2;
2198
2199       if (GET_CODE (operands[2]) == CONST_INT)
2200         {
2201           HOST_WIDE_INT intval = INTVAL (operands[2]);
2202
2203           /* See if we can finish with 2 bytes.  */
2204
2205           switch ((unsigned int) intval & 0xffffffff)
2206             {
2207             case 0x00000001:
2208             case 0x00000002:
2209             case 0x00000004:
2210               return 2;
2211
2212             case 0xffffffff:
2213             case 0xfffffffe:
2214             case 0xfffffffc:
2215               return 2;
2216
2217             case 0x00010000:
2218             case 0x00020000:
2219               return 2;
2220
2221             case 0xffff0000:
2222             case 0xfffe0000:
2223               return 2;
2224             }
2225
2226           /* See if we can finish with 4 bytes.  */
2227           if ((intval & 0xffff) == 0)
2228             return 4;
2229         }
2230
2231       return 6;
2232     }
2233 }
2234
2235 int
2236 compute_plussi_cc (rtx *operands)
2237 {
2238   enum machine_mode mode = GET_MODE (operands[0]);
2239
2240   if (mode != SImode)
2241     abort ();
2242
2243   if (TARGET_H8300)
2244     {
2245       return CC_CLOBBER;
2246     }
2247   else
2248     {
2249       if (GET_CODE (operands[2]) == REG)
2250         return CC_SET_ZN;
2251
2252       if (GET_CODE (operands[2]) == CONST_INT)
2253         {
2254           HOST_WIDE_INT intval = INTVAL (operands[2]);
2255
2256           /* See if we can finish with 2 bytes.  */
2257
2258           switch ((unsigned int) intval & 0xffffffff)
2259             {
2260             case 0x00000001:
2261             case 0x00000002:
2262             case 0x00000004:
2263               return CC_NONE_0HIT;
2264
2265             case 0xffffffff:
2266             case 0xfffffffe:
2267             case 0xfffffffc:
2268               return CC_NONE_0HIT;
2269
2270             case 0x00010000:
2271             case 0x00020000:
2272               return CC_CLOBBER;
2273
2274             case 0xffff0000:
2275             case 0xfffe0000:
2276               return CC_CLOBBER;
2277             }
2278
2279           /* See if we can finish with 4 bytes.  */
2280           if ((intval & 0xffff) == 0)
2281             return CC_CLOBBER;
2282         }
2283
2284       return CC_SET_ZN;
2285     }
2286 }
2287 \f
2288 const char *
2289 output_logical_op (enum machine_mode mode, rtx *operands)
2290 {
2291   /* Figure out the logical op that we need to perform.  */
2292   enum rtx_code code = GET_CODE (operands[3]);
2293   /* Pretend that every byte is affected if both operands are registers.  */
2294   const unsigned HOST_WIDE_INT intval =
2295     (unsigned HOST_WIDE_INT) ((GET_CODE (operands[2]) == CONST_INT)
2296                               ? INTVAL (operands[2]) : 0x55555555);
2297   /* The determinant of the algorithm.  If we perform an AND, 0
2298      affects a bit.  Otherwise, 1 affects a bit.  */
2299   const unsigned HOST_WIDE_INT det = (code != AND) ? intval : ~intval;
2300   /* Break up DET into pieces.  */
2301   const unsigned HOST_WIDE_INT b0 = (det >>  0) & 0xff;
2302   const unsigned HOST_WIDE_INT b1 = (det >>  8) & 0xff;
2303   const unsigned HOST_WIDE_INT b2 = (det >> 16) & 0xff;
2304   const unsigned HOST_WIDE_INT b3 = (det >> 24) & 0xff;
2305   const unsigned HOST_WIDE_INT w0 = (det >>  0) & 0xffff;
2306   const unsigned HOST_WIDE_INT w1 = (det >> 16) & 0xffff;
2307   int lower_half_easy_p = 0;
2308   int upper_half_easy_p = 0;
2309   /* The name of an insn.  */
2310   const char *opname;
2311   char insn_buf[100];
2312
2313   switch (code)
2314     {
2315     case AND:
2316       opname = "and";
2317       break;
2318     case IOR:
2319       opname = "or";
2320       break;
2321     case XOR:
2322       opname = "xor";
2323       break;
2324     default:
2325       abort ();
2326     }
2327
2328   switch (mode)
2329     {
2330     case HImode:
2331       /* First, see if we can finish with one insn.  */
2332       if ((TARGET_H8300H || TARGET_H8300S)
2333           && b0 != 0
2334           && b1 != 0)
2335         {
2336           sprintf (insn_buf, "%s.w\t%%T2,%%T0", opname);
2337           output_asm_insn (insn_buf, operands);
2338         }
2339       else
2340         {
2341           /* Take care of the lower byte.  */
2342           if (b0 != 0)
2343             {
2344               sprintf (insn_buf, "%s\t%%s2,%%s0", opname);
2345               output_asm_insn (insn_buf, operands);
2346             }
2347           /* Take care of the upper byte.  */
2348           if (b1 != 0)
2349             {
2350               sprintf (insn_buf, "%s\t%%t2,%%t0", opname);
2351               output_asm_insn (insn_buf, operands);
2352             }
2353         }
2354       break;
2355     case SImode:
2356       if (TARGET_H8300H || TARGET_H8300S)
2357         {
2358           /* Determine if the lower half can be taken care of in no more
2359              than two bytes.  */
2360           lower_half_easy_p = (b0 == 0
2361                                || b1 == 0
2362                                || (code != IOR && w0 == 0xffff));
2363
2364           /* Determine if the upper half can be taken care of in no more
2365              than two bytes.  */
2366           upper_half_easy_p = ((code != IOR && w1 == 0xffff)
2367                                || (code == AND && w1 == 0xff00));
2368         }
2369
2370       /* Check if doing everything with one insn is no worse than
2371          using multiple insns.  */
2372       if ((TARGET_H8300H || TARGET_H8300S)
2373           && w0 != 0 && w1 != 0
2374           && !(lower_half_easy_p && upper_half_easy_p)
2375           && !(code == IOR && w1 == 0xffff
2376                && (w0 & 0x8000) != 0 && lower_half_easy_p))
2377         {
2378           sprintf (insn_buf, "%s.l\t%%S2,%%S0", opname);
2379           output_asm_insn (insn_buf, operands);
2380         }
2381       else
2382         {
2383           /* Take care of the lower and upper words individually.  For
2384              each word, we try different methods in the order of
2385
2386              1) the special insn (in case of AND or XOR),
2387              2) the word-wise insn, and
2388              3) The byte-wise insn.  */
2389           if (w0 == 0xffff
2390               && (TARGET_H8300 ? (code == AND) : (code != IOR)))
2391             output_asm_insn ((code == AND)
2392                              ? "sub.w\t%f0,%f0" : "not.w\t%f0",
2393                              operands);
2394           else if ((TARGET_H8300H || TARGET_H8300S)
2395                    && (b0 != 0)
2396                    && (b1 != 0))
2397             {
2398               sprintf (insn_buf, "%s.w\t%%f2,%%f0", opname);
2399               output_asm_insn (insn_buf, operands);
2400             }
2401           else
2402             {
2403               if (b0 != 0)
2404                 {
2405                   sprintf (insn_buf, "%s\t%%w2,%%w0", opname);
2406                   output_asm_insn (insn_buf, operands);
2407                 }
2408               if (b1 != 0)
2409                 {
2410                   sprintf (insn_buf, "%s\t%%x2,%%x0", opname);
2411                   output_asm_insn (insn_buf, operands);
2412                 }
2413             }
2414
2415           if ((w1 == 0xffff)
2416               && (TARGET_H8300 ? (code == AND) : (code != IOR)))
2417             output_asm_insn ((code == AND)
2418                              ? "sub.w\t%e0,%e0" : "not.w\t%e0",
2419                              operands);
2420           else if ((TARGET_H8300H || TARGET_H8300S)
2421                    && code == IOR
2422                    && w1 == 0xffff
2423                    && (w0 & 0x8000) != 0)
2424             {
2425               output_asm_insn ("exts.l\t%S0", operands);
2426             }
2427           else if ((TARGET_H8300H || TARGET_H8300S)
2428                    && code == AND
2429                    && w1 == 0xff00)
2430             {
2431               output_asm_insn ("extu.w\t%e0", operands);
2432             }
2433           else if (TARGET_H8300H || TARGET_H8300S)
2434             {
2435               if (w1 != 0)
2436                 {
2437                   sprintf (insn_buf, "%s.w\t%%e2,%%e0", opname);
2438                   output_asm_insn (insn_buf, operands);
2439                 }
2440             }
2441           else
2442             {
2443               if (b2 != 0)
2444                 {
2445                   sprintf (insn_buf, "%s\t%%y2,%%y0", opname);
2446                   output_asm_insn (insn_buf, operands);
2447                 }
2448               if (b3 != 0)
2449                 {
2450                   sprintf (insn_buf, "%s\t%%z2,%%z0", opname);
2451                   output_asm_insn (insn_buf, operands);
2452                 }
2453             }
2454         }
2455       break;
2456     default:
2457       abort ();
2458     }
2459   return "";
2460 }
2461
2462 unsigned int
2463 compute_logical_op_length (enum machine_mode mode, rtx *operands)
2464 {
2465   /* Figure out the logical op that we need to perform.  */
2466   enum rtx_code code = GET_CODE (operands[3]);
2467   /* Pretend that every byte is affected if both operands are registers.  */
2468   const unsigned HOST_WIDE_INT intval =
2469     (unsigned HOST_WIDE_INT) ((GET_CODE (operands[2]) == CONST_INT)
2470                               ? INTVAL (operands[2]) : 0x55555555);
2471   /* The determinant of the algorithm.  If we perform an AND, 0
2472      affects a bit.  Otherwise, 1 affects a bit.  */
2473   const unsigned HOST_WIDE_INT det = (code != AND) ? intval : ~intval;
2474   /* Break up DET into pieces.  */
2475   const unsigned HOST_WIDE_INT b0 = (det >>  0) & 0xff;
2476   const unsigned HOST_WIDE_INT b1 = (det >>  8) & 0xff;
2477   const unsigned HOST_WIDE_INT b2 = (det >> 16) & 0xff;
2478   const unsigned HOST_WIDE_INT b3 = (det >> 24) & 0xff;
2479   const unsigned HOST_WIDE_INT w0 = (det >>  0) & 0xffff;
2480   const unsigned HOST_WIDE_INT w1 = (det >> 16) & 0xffff;
2481   int lower_half_easy_p = 0;
2482   int upper_half_easy_p = 0;
2483   /* Insn length.  */
2484   unsigned int length = 0;
2485
2486   switch (mode)
2487     {
2488     case HImode:
2489       /* First, see if we can finish with one insn.  */
2490       if ((TARGET_H8300H || TARGET_H8300S)
2491           && b0 != 0
2492           && b1 != 0)
2493         {
2494           if (REG_P (operands[2]))
2495             length += 2;
2496           else
2497             length += 4;
2498         }
2499       else
2500         {
2501           /* Take care of the lower byte.  */
2502           if (b0 != 0)
2503             length += 2;
2504
2505           /* Take care of the upper byte.  */
2506           if (b1 != 0)
2507             length += 2;
2508         }
2509       break;
2510     case SImode:
2511       if (TARGET_H8300H || TARGET_H8300S)
2512         {
2513           /* Determine if the lower half can be taken care of in no more
2514              than two bytes.  */
2515           lower_half_easy_p = (b0 == 0
2516                                || b1 == 0
2517                                || (code != IOR && w0 == 0xffff));
2518
2519           /* Determine if the upper half can be taken care of in no more
2520              than two bytes.  */
2521           upper_half_easy_p = ((code != IOR && w1 == 0xffff)
2522                                || (code == AND && w1 == 0xff00));
2523         }
2524
2525       /* Check if doing everything with one insn is no worse than
2526          using multiple insns.  */
2527       if ((TARGET_H8300H || TARGET_H8300S)
2528           && w0 != 0 && w1 != 0
2529           && !(lower_half_easy_p && upper_half_easy_p)
2530           && !(code == IOR && w1 == 0xffff
2531                && (w0 & 0x8000) != 0 && lower_half_easy_p))
2532         {
2533           if (REG_P (operands[2]))
2534             length += 4;
2535           else
2536             length += 6;
2537         }
2538       else
2539         {
2540           /* Take care of the lower and upper words individually.  For
2541              each word, we try different methods in the order of
2542
2543              1) the special insn (in case of AND or XOR),
2544              2) the word-wise insn, and
2545              3) The byte-wise insn.  */
2546           if (w0 == 0xffff
2547               && (TARGET_H8300 ? (code == AND) : (code != IOR)))
2548             {
2549               length += 2;
2550             }
2551           else if ((TARGET_H8300H || TARGET_H8300S)
2552                    && (b0 != 0)
2553                    && (b1 != 0))
2554             {
2555               length += 4;
2556             }
2557           else
2558             {
2559               if (b0 != 0)
2560                 length += 2;
2561
2562               if (b1 != 0)
2563                 length += 2;
2564             }
2565
2566           if (w1 == 0xffff
2567               && (TARGET_H8300 ? (code == AND) : (code != IOR)))
2568             {
2569               length += 2;
2570             }
2571           else if ((TARGET_H8300H || TARGET_H8300S)
2572                    && code == IOR
2573                    && w1 == 0xffff
2574                    && (w0 & 0x8000) != 0)
2575             {
2576               length += 2;
2577             }
2578           else if ((TARGET_H8300H || TARGET_H8300S)
2579                    && code == AND
2580                    && w1 == 0xff00)
2581             {
2582               length += 2;
2583             }
2584           else if (TARGET_H8300H || TARGET_H8300S)
2585             {
2586               if (w1 != 0)
2587                 length += 4;
2588             }
2589           else
2590             {
2591               if (b2 != 0)
2592                 length += 2;
2593
2594               if (b3 != 0)
2595                 length += 2;
2596             }
2597         }
2598       break;
2599     default:
2600       abort ();
2601     }
2602   return length;
2603 }
2604
2605 int
2606 compute_logical_op_cc (enum machine_mode mode, rtx *operands)
2607 {
2608   /* Figure out the logical op that we need to perform.  */
2609   enum rtx_code code = GET_CODE (operands[3]);
2610   /* Pretend that every byte is affected if both operands are registers.  */
2611   const unsigned HOST_WIDE_INT intval =
2612     (unsigned HOST_WIDE_INT) ((GET_CODE (operands[2]) == CONST_INT)
2613                               ? INTVAL (operands[2]) : 0x55555555);
2614   /* The determinant of the algorithm.  If we perform an AND, 0
2615      affects a bit.  Otherwise, 1 affects a bit.  */
2616   const unsigned HOST_WIDE_INT det = (code != AND) ? intval : ~intval;
2617   /* Break up DET into pieces.  */
2618   const unsigned HOST_WIDE_INT b0 = (det >>  0) & 0xff;
2619   const unsigned HOST_WIDE_INT b1 = (det >>  8) & 0xff;
2620   const unsigned HOST_WIDE_INT w0 = (det >>  0) & 0xffff;
2621   const unsigned HOST_WIDE_INT w1 = (det >> 16) & 0xffff;
2622   int lower_half_easy_p = 0;
2623   int upper_half_easy_p = 0;
2624   /* Condition code.  */
2625   enum attr_cc cc = CC_CLOBBER;
2626
2627   switch (mode)
2628     {
2629     case HImode:
2630       /* First, see if we can finish with one insn.  */
2631       if ((TARGET_H8300H || TARGET_H8300S)
2632           && b0 != 0
2633           && b1 != 0)
2634         {
2635           cc = CC_SET_ZNV;
2636         }
2637       break;
2638     case SImode:
2639       if (TARGET_H8300H || TARGET_H8300S)
2640         {
2641           /* Determine if the lower half can be taken care of in no more
2642              than two bytes.  */
2643           lower_half_easy_p = (b0 == 0
2644                                || b1 == 0
2645                                || (code != IOR && w0 == 0xffff));
2646
2647           /* Determine if the upper half can be taken care of in no more
2648              than two bytes.  */
2649           upper_half_easy_p = ((code != IOR && w1 == 0xffff)
2650                                || (code == AND && w1 == 0xff00));
2651         }
2652
2653       /* Check if doing everything with one insn is no worse than
2654          using multiple insns.  */
2655       if ((TARGET_H8300H || TARGET_H8300S)
2656           && w0 != 0 && w1 != 0
2657           && !(lower_half_easy_p && upper_half_easy_p)
2658           && !(code == IOR && w1 == 0xffff
2659                && (w0 & 0x8000) != 0 && lower_half_easy_p))
2660         {
2661           cc = CC_SET_ZNV;
2662         }
2663       else
2664         {
2665           if ((TARGET_H8300H || TARGET_H8300S)
2666               && code == IOR
2667               && w1 == 0xffff
2668               && (w0 & 0x8000) != 0)
2669             {
2670               cc = CC_SET_ZNV;
2671             }
2672         }
2673       break;
2674     default:
2675       abort ();
2676     }
2677   return cc;
2678 }
2679 \f
2680 /* Shifts.
2681
2682    We devote a fair bit of code to getting efficient shifts since we
2683    can only shift one bit at a time on the H8/300 and H8/300H and only
2684    one or two bits at a time on the H8S.
2685
2686    All shift code falls into one of the following ways of
2687    implementation:
2688
2689    o SHIFT_INLINE: Emit straight line code for the shift; this is used
2690      when a straight line shift is about the same size or smaller than
2691      a loop.
2692
2693    o SHIFT_ROT_AND: Rotate the value the opposite direction, then mask
2694      off the bits we don't need.  This is used when only a few of the
2695      bits in the original value will survive in the shifted value.
2696
2697    o SHIFT_SPECIAL: Often it's possible to move a byte or a word to
2698      simulate a shift by 8, 16, or 24 bits.  Once moved, a few inline
2699      shifts can be added if the shift count is slightly more than 8 or
2700      16.  This case also includes other oddballs that are not worth
2701      explaining here.
2702
2703    o SHIFT_LOOP: Emit a loop using one (or two on H8S) bit shifts.
2704
2705    For each shift count, we try to use code that has no trade-off
2706    between code size and speed whenever possible.
2707
2708    If the trade-off is unavoidable, we try to be reasonable.
2709    Specifically, the fastest version is one instruction longer than
2710    the shortest version, we take the fastest version.  We also provide
2711    the use a way to switch back to the shortest version with -Os.
2712
2713    For the details of the shift algorithms for various shift counts,
2714    refer to shift_alg_[qhs]i.  */
2715
2716 int
2717 nshift_operator (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
2718 {
2719   switch (GET_CODE (x))
2720     {
2721     case ASHIFTRT:
2722     case LSHIFTRT:
2723     case ASHIFT:
2724       return 1;
2725
2726     default:
2727       return 0;
2728     }
2729 }
2730
2731 /* Emit code to do shifts.  */
2732
2733 void
2734 expand_a_shift (enum machine_mode mode, int code, rtx operands[])
2735 {
2736   emit_move_insn (operands[0], operands[1]);
2737
2738   /* Need a loop to get all the bits we want  - we generate the
2739      code at emit time, but need to allocate a scratch reg now.  */
2740
2741   emit_insn (gen_rtx_PARALLEL
2742              (VOIDmode,
2743               gen_rtvec (2,
2744                          gen_rtx_SET (VOIDmode, operands[0],
2745                                       gen_rtx_fmt_ee (code, mode,
2746                                                       operands[0], operands[2])),
2747                          gen_rtx_CLOBBER (VOIDmode,
2748                                           gen_rtx_SCRATCH (QImode)))));
2749 }
2750
2751 /* Symbols of the various modes which can be used as indices.  */
2752
2753 enum shift_mode
2754 {
2755   QIshift, HIshift, SIshift
2756 };
2757
2758 /* For single bit shift insns, record assembler and what bits of the
2759    condition code are valid afterwards (represented as various CC_FOO
2760    bits, 0 means CC isn't left in a usable state).  */
2761
2762 struct shift_insn
2763 {
2764   const char *const assembler;
2765   const int cc_valid;
2766 };
2767
2768 /* Assembler instruction shift table.
2769
2770    These tables are used to look up the basic shifts.
2771    They are indexed by cpu, shift_type, and mode.  */
2772
2773 static const struct shift_insn shift_one[2][3][3] =
2774 {
2775 /* H8/300 */
2776   {
2777 /* SHIFT_ASHIFT */
2778     {
2779       { "shll\t%X0", CC_SET_ZNV },
2780       { "add.w\t%T0,%T0", CC_SET_ZN },
2781       { "add.w\t%f0,%f0\n\taddx\t%y0,%y0\n\taddx\t%z0,%z0", CC_CLOBBER }
2782     },
2783 /* SHIFT_LSHIFTRT */
2784     {
2785       { "shlr\t%X0", CC_SET_ZNV },
2786       { "shlr\t%t0\n\trotxr\t%s0", CC_CLOBBER },
2787       { "shlr\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", CC_CLOBBER }
2788     },
2789 /* SHIFT_ASHIFTRT */
2790     {
2791       { "shar\t%X0", CC_SET_ZNV },
2792       { "shar\t%t0\n\trotxr\t%s0", CC_CLOBBER },
2793       { "shar\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", CC_CLOBBER }
2794     }
2795   },
2796 /* H8/300H */
2797   {
2798 /* SHIFT_ASHIFT */
2799     {
2800       { "shll.b\t%X0", CC_SET_ZNV },
2801       { "shll.w\t%T0", CC_SET_ZNV },
2802       { "shll.l\t%S0", CC_SET_ZNV }
2803     },
2804 /* SHIFT_LSHIFTRT */
2805     {
2806       { "shlr.b\t%X0", CC_SET_ZNV },
2807       { "shlr.w\t%T0", CC_SET_ZNV },
2808       { "shlr.l\t%S0", CC_SET_ZNV }
2809     },
2810 /* SHIFT_ASHIFTRT */
2811     {
2812       { "shar.b\t%X0", CC_SET_ZNV },
2813       { "shar.w\t%T0", CC_SET_ZNV },
2814       { "shar.l\t%S0", CC_SET_ZNV }
2815     }
2816   }
2817 };
2818
2819 static const struct shift_insn shift_two[3][3] =
2820 {
2821 /* SHIFT_ASHIFT */
2822     {
2823       { "shll.b\t#2,%X0", CC_SET_ZNV },
2824       { "shll.w\t#2,%T0", CC_SET_ZNV },
2825       { "shll.l\t#2,%S0", CC_SET_ZNV }
2826     },
2827 /* SHIFT_LSHIFTRT */
2828     {
2829       { "shlr.b\t#2,%X0", CC_SET_ZNV },
2830       { "shlr.w\t#2,%T0", CC_SET_ZNV },
2831       { "shlr.l\t#2,%S0", CC_SET_ZNV }
2832     },
2833 /* SHIFT_ASHIFTRT */
2834     {
2835       { "shar.b\t#2,%X0", CC_SET_ZNV },
2836       { "shar.w\t#2,%T0", CC_SET_ZNV },
2837       { "shar.l\t#2,%S0", CC_SET_ZNV }
2838     }
2839 };
2840
2841 /* Rotates are organized by which shift they'll be used in implementing.
2842    There's no need to record whether the cc is valid afterwards because
2843    it is the AND insn that will decide this.  */
2844
2845 static const char *const rotate_one[2][3][3] =
2846 {
2847 /* H8/300 */
2848   {
2849 /* SHIFT_ASHIFT */
2850     {
2851       "rotr\t%X0",
2852       "shlr\t%t0\n\trotxr\t%s0\n\tbst\t#7,%t0",
2853       0
2854     },
2855 /* SHIFT_LSHIFTRT */
2856     {
2857       "rotl\t%X0",
2858       "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
2859       0
2860     },
2861 /* SHIFT_ASHIFTRT */
2862     {
2863       "rotl\t%X0",
2864       "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
2865       0
2866     }
2867   },
2868 /* H8/300H */
2869   {
2870 /* SHIFT_ASHIFT */
2871     {
2872       "rotr.b\t%X0",
2873       "rotr.w\t%T0",
2874       "rotr.l\t%S0"
2875     },
2876 /* SHIFT_LSHIFTRT */
2877     {
2878       "rotl.b\t%X0",
2879       "rotl.w\t%T0",
2880       "rotl.l\t%S0"
2881     },
2882 /* SHIFT_ASHIFTRT */
2883     {
2884       "rotl.b\t%X0",
2885       "rotl.w\t%T0",
2886       "rotl.l\t%S0"
2887     }
2888   }
2889 };
2890
2891 static const char *const rotate_two[3][3] =
2892 {
2893 /* SHIFT_ASHIFT */
2894     {
2895       "rotr.b\t#2,%X0",
2896       "rotr.w\t#2,%T0",
2897       "rotr.l\t#2,%S0"
2898     },
2899 /* SHIFT_LSHIFTRT */
2900     {
2901       "rotl.b\t#2,%X0",
2902       "rotl.w\t#2,%T0",
2903       "rotl.l\t#2,%S0"
2904     },
2905 /* SHIFT_ASHIFTRT */
2906     {
2907       "rotl.b\t#2,%X0",
2908       "rotl.w\t#2,%T0",
2909       "rotl.l\t#2,%S0"
2910     }
2911 };
2912
2913 struct shift_info {
2914   /* Shift algorithm.  */
2915   enum shift_alg alg;
2916
2917   /* The number of bits to be shifted by shift1 and shift2.  Valid
2918      when ALG is SHIFT_SPECIAL.  */
2919   unsigned int remainder;
2920
2921   /* Special insn for a shift.  Valid when ALG is SHIFT_SPECIAL.  */
2922   const char *special;
2923
2924   /* Insn for a one-bit shift.  Valid when ALG is either SHIFT_INLINE
2925      or SHIFT_SPECIAL, and REMAINDER is nonzero.  */
2926   const char *shift1;
2927
2928   /* Insn for a two-bit shift.  Valid when ALG is either SHIFT_INLINE
2929      or SHIFT_SPECIAL, and REMAINDER is nonzero.  */
2930   const char *shift2;
2931
2932   /* CC status for SHIFT_INLINE.  */
2933   int cc_inline;
2934
2935   /* CC status  for SHIFT_SPECIAL.  */
2936   int cc_special;
2937 };
2938
2939 static void get_shift_alg (enum shift_type,
2940                            enum shift_mode, unsigned int,
2941                            struct shift_info *);
2942
2943 /* Given SHIFT_TYPE, SHIFT_MODE, and shift count COUNT, determine the
2944    best algorithm for doing the shift.  The assembler code is stored
2945    in the pointers in INFO.  We achieve the maximum efficiency in most
2946    cases when !TARGET_H8300.  In case of TARGET_H8300, shifts in
2947    SImode in particular have a lot of room to optimize.
2948
2949    We first determine the strategy of the shift algorithm by a table
2950    lookup.  If that tells us to use a hand crafted assembly code, we
2951    go into the big switch statement to find what that is.  Otherwise,
2952    we resort to a generic way, such as inlining.  In either case, the
2953    result is returned through INFO.  */
2954
2955 static void
2956 get_shift_alg (enum shift_type shift_type, enum shift_mode shift_mode,
2957                unsigned int count, struct shift_info *info)
2958 {
2959   enum h8_cpu cpu;
2960
2961   /* Find the target CPU.  */
2962   if (TARGET_H8300)
2963     cpu = H8_300;
2964   else if (TARGET_H8300H)
2965     cpu = H8_300H;
2966   else
2967     cpu = H8_S;
2968
2969   /* Find the shift algorithm.  */
2970   info->alg = SHIFT_LOOP;
2971   switch (shift_mode)
2972     {
2973     case QIshift:
2974       if (count < GET_MODE_BITSIZE (QImode))
2975         info->alg = shift_alg_qi[cpu][shift_type][count];
2976       break;
2977
2978     case HIshift:
2979       if (count < GET_MODE_BITSIZE (HImode))
2980         info->alg = shift_alg_hi[cpu][shift_type][count];
2981       break;
2982
2983     case SIshift:
2984       if (count < GET_MODE_BITSIZE (SImode))
2985         info->alg = shift_alg_si[cpu][shift_type][count];
2986       break;
2987
2988     default:
2989       abort ();
2990     }
2991
2992   /* Fill in INFO.  Return unless we have SHIFT_SPECIAL.  */
2993   switch (info->alg)
2994     {
2995     case SHIFT_INLINE:
2996       info->remainder = count;
2997       /* Fall through.  */
2998
2999     case SHIFT_LOOP:
3000       /* It is up to the caller to know that looping clobbers cc.  */
3001       info->shift1 = shift_one[cpu_type][shift_type][shift_mode].assembler;
3002       info->shift2 = shift_two[shift_type][shift_mode].assembler;
3003       info->cc_inline = shift_one[cpu_type][shift_type][shift_mode].cc_valid;
3004       goto end;
3005
3006     case SHIFT_ROT_AND:
3007       info->shift1 = rotate_one[cpu_type][shift_type][shift_mode];
3008       info->shift2 = rotate_two[shift_type][shift_mode];
3009       info->cc_inline = CC_CLOBBER;
3010       goto end;
3011
3012     case SHIFT_SPECIAL:
3013       /* REMAINDER is 0 for most cases, so initialize it to 0.  */
3014       info->remainder = 0;
3015       info->shift1 = shift_one[cpu_type][shift_type][shift_mode].assembler;
3016       info->shift2 = shift_two[shift_type][shift_mode].assembler;
3017       info->cc_inline = shift_one[cpu_type][shift_type][shift_mode].cc_valid;
3018       info->cc_special = CC_CLOBBER;
3019       break;
3020     }
3021
3022   /* Here we only deal with SHIFT_SPECIAL.  */
3023   switch (shift_mode)
3024     {
3025     case QIshift:
3026       /* For ASHIFTRT by 7 bits, the sign bit is simply replicated
3027          through the entire value.  */
3028       if (shift_type == SHIFT_ASHIFTRT && count == 7)
3029         {
3030           info->special = "shll\t%X0\n\tsubx\t%X0,%X0";
3031           goto end;
3032         }
3033       abort ();
3034
3035     case HIshift:
3036       if (count == 7)
3037         {
3038           switch (shift_type)
3039             {
3040             case SHIFT_ASHIFT:
3041               if (TARGET_H8300)
3042                 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";
3043               else
3044                 info->special = "shar.b\t%t0\n\tmov.b\t%s0,%t0\n\trotxr.w\t%T0\n\tand.b\t#0x80,%s0";
3045               goto end;
3046             case SHIFT_LSHIFTRT:
3047               if (TARGET_H8300)
3048                 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";
3049               else
3050                 info->special = "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.w\t%T0\n\tand.b\t#0x01,%t0";
3051               goto end;
3052             case SHIFT_ASHIFTRT:
3053               info->special = "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.b\t%s0\n\tsubx\t%t0,%t0";
3054               goto end;
3055             }
3056         }
3057       else if ((8 <= count && count <= 13)
3058                || (TARGET_H8300S && count == 14))
3059         {
3060           info->remainder = count - 8;
3061
3062           switch (shift_type)
3063             {
3064             case SHIFT_ASHIFT:
3065               info->special = "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0";
3066               goto end;
3067             case SHIFT_LSHIFTRT:
3068               if (TARGET_H8300)
3069                 {
3070                   info->special = "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0";
3071                   info->shift1  = "shlr.b\t%s0";
3072                   info->cc_inline = CC_SET_ZNV;
3073                 }
3074               else
3075                 {
3076                   info->special = "mov.b\t%t0,%s0\n\textu.w\t%T0";
3077                   info->cc_special = CC_SET_ZNV;
3078                 }
3079               goto end;
3080             case SHIFT_ASHIFTRT:
3081               if (TARGET_H8300)
3082                 {
3083                   info->special = "mov.b\t%t0,%s0\n\tbld\t#7,%s0\n\tsubx\t%t0,%t0";
3084                   info->shift1  = "shar.b\t%s0";
3085                 }
3086               else
3087                 {
3088                   info->special = "mov.b\t%t0,%s0\n\texts.w\t%T0";
3089                   info->cc_special = CC_SET_ZNV;
3090                 }
3091               goto end;
3092             }
3093         }
3094       else if (count == 14)
3095         {
3096           switch (shift_type)
3097             {
3098             case SHIFT_ASHIFT:
3099               if (TARGET_H8300)
3100                 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";
3101               goto end;
3102             case SHIFT_LSHIFTRT:
3103               if (TARGET_H8300)
3104                 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";
3105               goto end;
3106             case SHIFT_ASHIFTRT:
3107               if (TARGET_H8300)
3108                 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";
3109               else if (TARGET_H8300H)
3110                 {
3111                   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";
3112                   info->cc_special = CC_SET_ZNV;
3113                 }
3114               else /* TARGET_H8300S */
3115                 abort ();
3116               goto end;
3117             }
3118         }
3119       else if (count == 15)
3120         {
3121           switch (shift_type)
3122             {
3123             case SHIFT_ASHIFT:
3124               info->special = "bld\t#0,%s0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#7,%t0";
3125               goto end;
3126             case SHIFT_LSHIFTRT:
3127               info->special = "bld\t#7,%t0\n\txor\t%s0,%s0\n\txor\t%t0,%t0\n\tbst\t#0,%s0";
3128               goto end;
3129             case SHIFT_ASHIFTRT:
3130               info->special = "shll\t%t0\n\tsubx\t%t0,%t0\n\tmov.b\t%t0,%s0";
3131               goto end;
3132             }
3133         }
3134       abort ();
3135
3136     case SIshift:
3137       if (TARGET_H8300 && 8 <= count && count <= 9)
3138         {
3139           info->remainder = count - 8;
3140
3141           switch (shift_type)
3142             {
3143             case SHIFT_ASHIFT:
3144               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";
3145               goto end;
3146             case SHIFT_LSHIFTRT:
3147               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";
3148               info->shift1  = "shlr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0";
3149               goto end;
3150             case SHIFT_ASHIFTRT:
3151               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";
3152               goto end;
3153             }
3154         }
3155       else if (count == 8 && !TARGET_H8300)
3156         {
3157           switch (shift_type)
3158             {
3159             case SHIFT_ASHIFT:
3160               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";
3161               goto end;
3162             case SHIFT_LSHIFTRT:
3163               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";
3164               goto end;
3165             case SHIFT_ASHIFTRT:
3166               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";
3167               goto end;
3168             }
3169         }
3170       else if (count == 15 && TARGET_H8300)
3171         {
3172           switch (shift_type)
3173             {
3174             case SHIFT_ASHIFT:
3175               abort ();
3176             case SHIFT_LSHIFTRT:
3177               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";
3178               goto end;
3179             case SHIFT_ASHIFTRT:
3180               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";
3181               goto end;
3182             }
3183         }
3184       else if (count == 15 && !TARGET_H8300)
3185         {
3186           switch (shift_type)
3187             {
3188             case SHIFT_ASHIFT:
3189               info->special = "shlr.w\t%e0\n\tmov.w\t%f0,%e0\n\txor.w\t%f0,%f0\n\trotxr.l\t%S0";
3190               info->cc_special = CC_SET_ZNV;
3191               goto end;
3192             case SHIFT_LSHIFTRT:
3193               info->special = "shll.w\t%f0\n\tmov.w\t%e0,%f0\n\txor.w\t%e0,%e0\n\trotxl.l\t%S0";
3194               info->cc_special = CC_SET_ZNV;
3195               goto end;
3196             case SHIFT_ASHIFTRT:
3197               abort ();
3198             }
3199         }
3200       else if ((TARGET_H8300 && 16 <= count && count <= 20)
3201                || (TARGET_H8300H && 16 <= count && count <= 19)
3202                || (TARGET_H8300S && 16 <= count && count <= 21))
3203         {
3204           info->remainder = count - 16;
3205
3206           switch (shift_type)
3207             {
3208             case SHIFT_ASHIFT:
3209               info->special = "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0";
3210               if (TARGET_H8300)
3211                 info->shift1 = "add.w\t%e0,%e0";
3212               goto end;
3213             case SHIFT_LSHIFTRT:
3214               if (TARGET_H8300)
3215                 {
3216                   info->special = "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0";
3217                   info->shift1  = "shlr\t%x0\n\trotxr\t%w0";
3218                 }
3219               else
3220                 {
3221                   info->special = "mov.w\t%e0,%f0\n\textu.l\t%S0";
3222                   info->cc_special = CC_SET_ZNV;
3223                 }
3224               goto end;
3225             case SHIFT_ASHIFTRT:
3226               if (TARGET_H8300)
3227                 {
3228                   info->special = "mov.w\t%e0,%f0\n\tshll\t%z0\n\tsubx\t%z0,%z0\n\tmov.b\t%z0,%y0";
3229                   info->shift1  = "shar\t%x0\n\trotxr\t%w0";
3230                 }
3231               else
3232                 {
3233                   info->special = "mov.w\t%e0,%f0\n\texts.l\t%S0";
3234                   info->cc_special = CC_SET_ZNV;
3235                 }
3236               goto end;
3237             }
3238         }
3239       else if (TARGET_H8300 && 24 <= count && count <= 28)
3240         {
3241           info->remainder = count - 24;
3242
3243           switch (shift_type)
3244             {
3245             case SHIFT_ASHIFT:
3246               info->special = "mov.b\t%w0,%z0\n\tsub.b\t%y0,%y0\n\tsub.w\t%f0,%f0";
3247               info->shift1  = "shll.b\t%z0";
3248               info->cc_inline = CC_SET_ZNV;
3249               goto end;
3250             case SHIFT_LSHIFTRT:
3251               info->special = "mov.b\t%z0,%w0\n\tsub.b\t%x0,%x0\n\tsub.w\t%e0,%e0";
3252               info->shift1  = "shlr.b\t%w0";
3253               info->cc_inline = CC_SET_ZNV;
3254               goto end;
3255             case SHIFT_ASHIFTRT:
3256               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";
3257               info->shift1  = "shar.b\t%w0";
3258               info->cc_inline = CC_SET_ZNV;
3259               goto end;
3260             }
3261         }
3262       else if ((TARGET_H8300H && count == 24)
3263                || (TARGET_H8300S && 24 <= count && count <= 25))
3264         {
3265           info->remainder = count - 24;
3266
3267           switch (shift_type)
3268             {
3269             case SHIFT_ASHIFT:
3270               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";
3271               goto end;
3272             case SHIFT_LSHIFTRT:
3273               info->special = "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\textu.w\t%f0\n\textu.l\t%S0";
3274               info->cc_special = CC_SET_ZNV;
3275               goto end;
3276             case SHIFT_ASHIFTRT:
3277               info->special = "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\texts.w\t%f0\n\texts.l\t%S0";
3278               info->cc_special = CC_SET_ZNV;
3279               goto end;
3280             }
3281         }
3282       else if (!TARGET_H8300 && count == 28)
3283         {
3284           switch (shift_type)
3285             {
3286             case SHIFT_ASHIFT:
3287               if (TARGET_H8300H)
3288                 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";
3289               else
3290                 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";
3291               goto end;
3292             case SHIFT_LSHIFTRT:
3293               if (TARGET_H8300H)
3294                 {
3295                   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";
3296                   info->cc_special = CC_SET_ZNV;
3297                 }
3298               else
3299                 info->special = "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t#2,%S0\n\textu.l\t%S0";
3300               goto end;
3301             case SHIFT_ASHIFTRT:
3302               abort ();
3303             }
3304         }
3305       else if (!TARGET_H8300 && count == 29)
3306         {
3307           switch (shift_type)
3308             {
3309             case SHIFT_ASHIFT:
3310               if (TARGET_H8300H)
3311                 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";
3312               else
3313                 info->special = "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
3314               goto end;
3315             case SHIFT_LSHIFTRT:
3316               if (TARGET_H8300H)
3317                 {
3318                   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";
3319                   info->cc_special = CC_SET_ZNV;
3320                 }
3321               else
3322                 {
3323                   info->special = "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
3324                   info->cc_special = CC_SET_ZNV;
3325                 }
3326               goto end;
3327             case SHIFT_ASHIFTRT:
3328               abort ();
3329             }
3330         }
3331       else if (!TARGET_H8300 && count == 30)
3332         {
3333           switch (shift_type)
3334             {
3335             case SHIFT_ASHIFT:
3336               if (TARGET_H8300H)
3337                 info->special = "sub.w\t%e0,%e0\n\trotr.l\t%S0\n\trotr.l\t%S0\n\tsub.w\t%f0,%f0";
3338               else
3339                 info->special = "sub.w\t%e0,%e0\n\trotr.l\t#2,%S0\n\tsub.w\t%f0,%f0";
3340               goto end;
3341             case SHIFT_LSHIFTRT:
3342               if (TARGET_H8300H)
3343                 info->special = "sub.w\t%f0,%f0\n\trotl.l\t%S0\n\trotl.l\t%S0\n\textu.l\t%S0";
3344               else
3345                 info->special = "sub.w\t%f0,%f0\n\trotl.l\t#2,%S0\n\textu.l\t%S0";
3346               goto end;
3347             case SHIFT_ASHIFTRT:
3348               abort ();
3349             }
3350         }
3351       else if (count == 31)
3352         {
3353           if (TARGET_H8300)
3354             {
3355               switch (shift_type)
3356                 {
3357                 case SHIFT_ASHIFT:
3358                   info->special = "sub.w\t%e0,%e0\n\tshlr\t%w0\n\tmov.w\t%e0,%f0\n\trotxr\t%z0";
3359                   goto end;
3360                 case SHIFT_LSHIFTRT:
3361                   info->special = "sub.w\t%f0,%f0\n\tshll\t%z0\n\tmov.w\t%f0,%e0\n\trotxl\t%w0";
3362                   goto end;
3363                 case SHIFT_ASHIFTRT:
3364                   info->special = "shll\t%z0\n\tsubx\t%w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
3365                   goto end;
3366                 }
3367             }
3368           else
3369             {
3370               switch (shift_type)
3371                 {
3372                 case SHIFT_ASHIFT:
3373                   info->special = "shlr.l\t%S0\n\txor.l\t%S0,%S0\n\trotxr.l\t%S0";
3374                   info->cc_special = CC_SET_ZNV;
3375                   goto end;
3376                 case SHIFT_LSHIFTRT:
3377                   info->special = "shll.l\t%S0\n\txor.l\t%S0,%S0\n\trotxl.l\t%S0";
3378                   info->cc_special = CC_SET_ZNV;
3379                   goto end;
3380                 case SHIFT_ASHIFTRT:
3381                   info->special = "shll\t%e0\n\tsubx\t%w0,%w0\n\texts.w\t%T0\n\texts.l\t%S0";
3382                   info->cc_special = CC_SET_ZNV;
3383                   goto end;
3384                 }
3385             }
3386         }
3387       abort ();
3388
3389     default:
3390       abort ();
3391     }
3392
3393  end:
3394   if (!TARGET_H8300S)
3395     info->shift2 = NULL;
3396 }
3397
3398 /* Given COUNT and MODE of a shift, return 1 if a scratch reg may be
3399    needed for some shift with COUNT and MODE.  Return 0 otherwise.  */
3400
3401 int
3402 h8300_shift_needs_scratch_p (int count, enum machine_mode mode)
3403 {
3404   enum h8_cpu cpu;
3405   int a, lr, ar;
3406
3407   if (GET_MODE_BITSIZE (mode) <= count)
3408     return 1;
3409
3410   /* Find out the target CPU.  */
3411   if (TARGET_H8300)
3412     cpu = H8_300;
3413   else if (TARGET_H8300H)
3414     cpu = H8_300H;
3415   else
3416     cpu = H8_S;
3417
3418   /* Find the shift algorithm.  */
3419   switch (mode)
3420     {
3421     case QImode:
3422       a  = shift_alg_qi[cpu][SHIFT_ASHIFT][count];
3423       lr = shift_alg_qi[cpu][SHIFT_LSHIFTRT][count];
3424       ar = shift_alg_qi[cpu][SHIFT_ASHIFTRT][count];
3425       break;
3426
3427     case HImode:
3428       a  = shift_alg_hi[cpu][SHIFT_ASHIFT][count];
3429       lr = shift_alg_hi[cpu][SHIFT_LSHIFTRT][count];
3430       ar = shift_alg_hi[cpu][SHIFT_ASHIFTRT][count];
3431       break;
3432
3433     case SImode:
3434       a  = shift_alg_si[cpu][SHIFT_ASHIFT][count];
3435       lr = shift_alg_si[cpu][SHIFT_LSHIFTRT][count];
3436       ar = shift_alg_si[cpu][SHIFT_ASHIFTRT][count];
3437       break;
3438
3439     default:
3440       abort ();
3441     }
3442
3443   /* On H8/300H, count == 8 uses a scratch register.  */
3444   return (a == SHIFT_LOOP || lr == SHIFT_LOOP || ar == SHIFT_LOOP
3445           || (TARGET_H8300H && mode == SImode && count == 8));
3446 }
3447
3448 /* Emit the assembler code for doing shifts.  */
3449
3450 const char *
3451 output_a_shift (rtx *operands)
3452 {
3453   static int loopend_lab;
3454   rtx shift = operands[3];
3455   enum machine_mode mode = GET_MODE (shift);
3456   enum rtx_code code = GET_CODE (shift);
3457   enum shift_type shift_type;
3458   enum shift_mode shift_mode;
3459   struct shift_info info;
3460
3461   loopend_lab++;
3462
3463   switch (mode)
3464     {
3465     case QImode:
3466       shift_mode = QIshift;
3467       break;
3468     case HImode:
3469       shift_mode = HIshift;
3470       break;
3471     case SImode:
3472       shift_mode = SIshift;
3473       break;
3474     default:
3475       abort ();
3476     }
3477
3478   switch (code)
3479     {
3480     case ASHIFTRT:
3481       shift_type = SHIFT_ASHIFTRT;
3482       break;
3483     case LSHIFTRT:
3484       shift_type = SHIFT_LSHIFTRT;
3485       break;
3486     case ASHIFT:
3487       shift_type = SHIFT_ASHIFT;
3488       break;
3489     default:
3490       abort ();
3491     }
3492
3493   if (GET_CODE (operands[2]) != CONST_INT)
3494     {
3495       /* This case must be taken care of by one of the two splitters
3496          that convert a variable shift into a loop.  */
3497       abort ();
3498     }
3499   else
3500     {
3501       int n = INTVAL (operands[2]);
3502
3503       /* If the count is negative, make it 0.  */
3504       if (n < 0)
3505         n = 0;
3506       /* If the count is too big, truncate it.
3507          ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
3508          do the intuitive thing.  */
3509       else if ((unsigned int) n > GET_MODE_BITSIZE (mode))
3510         n = GET_MODE_BITSIZE (mode);
3511
3512       get_shift_alg (shift_type, shift_mode, n, &info);
3513
3514       switch (info.alg)
3515         {
3516         case SHIFT_SPECIAL:
3517           output_asm_insn (info.special, operands);
3518           /* Fall through.  */
3519
3520         case SHIFT_INLINE:
3521           n = info.remainder;
3522
3523           /* Emit two bit shifts first.  */
3524           if (info.shift2 != NULL)
3525             {
3526               for (; n > 1; n -= 2)
3527                 output_asm_insn (info.shift2, operands);
3528             }
3529
3530           /* Now emit one bit shifts for any residual.  */
3531           for (; n > 0; n--)
3532             output_asm_insn (info.shift1, operands);
3533           return "";
3534
3535         case SHIFT_ROT_AND:
3536           {
3537             int m = GET_MODE_BITSIZE (mode) - n;
3538             const int mask = (shift_type == SHIFT_ASHIFT
3539                               ? ((1 << m) - 1) << n
3540                               : (1 << m) - 1);
3541             char insn_buf[200];
3542
3543             /* Not all possibilities of rotate are supported.  They shouldn't
3544                be generated, but let's watch for 'em.  */
3545             if (info.shift1 == 0)
3546               abort ();
3547
3548             /* Emit two bit rotates first.  */
3549             if (info.shift2 != NULL)
3550               {
3551                 for (; m > 1; m -= 2)
3552                   output_asm_insn (info.shift2, operands);
3553               }
3554
3555             /* Now single bit rotates for any residual.  */
3556             for (; m > 0; m--)
3557               output_asm_insn (info.shift1, operands);
3558
3559             /* Now mask off the high bits.  */
3560             if (mode == QImode)
3561               sprintf (insn_buf, "and\t#%d,%%X0", mask);
3562             else if (mode == HImode && (TARGET_H8300H || TARGET_H8300S))
3563               sprintf (insn_buf, "and.w\t#%d,%%T0", mask);
3564             else
3565               abort ();
3566
3567             output_asm_insn (insn_buf, operands);
3568             return "";
3569           }
3570
3571         case SHIFT_LOOP:
3572           /* A loop to shift by a "large" constant value.
3573              If we have shift-by-2 insns, use them.  */
3574           if (info.shift2 != NULL)
3575             {
3576               fprintf (asm_out_file, "\tmov.b   #%d,%sl\n", n / 2,
3577                        names_big[REGNO (operands[4])]);
3578               fprintf (asm_out_file, ".Llt%d:\n", loopend_lab);
3579               output_asm_insn (info.shift2, operands);
3580               output_asm_insn ("add     #0xff,%X4", operands);
3581               fprintf (asm_out_file, "\tbne     .Llt%d\n", loopend_lab);
3582               if (n % 2)
3583                 output_asm_insn (info.shift1, operands);
3584             }
3585           else
3586             {
3587               fprintf (asm_out_file, "\tmov.b   #%d,%sl\n", n,
3588                        names_big[REGNO (operands[4])]);
3589               fprintf (asm_out_file, ".Llt%d:\n", loopend_lab);
3590               output_asm_insn (info.shift1, operands);
3591               output_asm_insn ("add     #0xff,%X4", operands);
3592               fprintf (asm_out_file, "\tbne     .Llt%d\n", loopend_lab);
3593             }
3594           return "";
3595
3596         default:
3597           abort ();
3598         }
3599     }
3600 }
3601
3602 static unsigned int
3603 h8300_asm_insn_count (const char *template)
3604 {
3605   unsigned int count = 1;
3606
3607   for (; *template; template++)
3608     if (*template == '\n')
3609       count++;
3610
3611   return count;
3612 }
3613
3614 unsigned int
3615 compute_a_shift_length (rtx insn ATTRIBUTE_UNUSED, rtx *operands)
3616 {
3617   rtx shift = operands[3];
3618   enum machine_mode mode = GET_MODE (shift);
3619   enum rtx_code code = GET_CODE (shift);
3620   enum shift_type shift_type;
3621   enum shift_mode shift_mode;
3622   struct shift_info info;
3623   unsigned int wlength = 0;
3624
3625   switch (mode)
3626     {
3627     case QImode:
3628       shift_mode = QIshift;
3629       break;
3630     case HImode:
3631       shift_mode = HIshift;
3632       break;
3633     case SImode:
3634       shift_mode = SIshift;
3635       break;
3636     default:
3637       abort ();
3638     }
3639
3640   switch (code)
3641     {
3642     case ASHIFTRT:
3643       shift_type = SHIFT_ASHIFTRT;
3644       break;
3645     case LSHIFTRT:
3646       shift_type = SHIFT_LSHIFTRT;
3647       break;
3648     case ASHIFT:
3649       shift_type = SHIFT_ASHIFT;
3650       break;
3651     default:
3652       abort ();
3653     }
3654
3655   if (GET_CODE (operands[2]) != CONST_INT)
3656     {
3657       /* Get the assembler code to do one shift.  */
3658       get_shift_alg (shift_type, shift_mode, 1, &info);
3659
3660       return (4 + h8300_asm_insn_count (info.shift1)) * 2;
3661     }
3662   else
3663     {
3664       int n = INTVAL (operands[2]);
3665
3666       /* If the count is negative, make it 0.  */
3667       if (n < 0)
3668         n = 0;
3669       /* If the count is too big, truncate it.
3670          ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
3671          do the intuitive thing.  */
3672       else if ((unsigned int) n > GET_MODE_BITSIZE (mode))
3673         n = GET_MODE_BITSIZE (mode);
3674
3675       get_shift_alg (shift_type, shift_mode, n, &info);
3676
3677       switch (info.alg)
3678         {
3679         case SHIFT_SPECIAL:
3680           wlength += h8300_asm_insn_count (info.special);
3681
3682           /* Every assembly instruction used in SHIFT_SPECIAL case
3683              takes 2 bytes except xor.l, which takes 4 bytes, so if we
3684              see xor.l, we just pretend that xor.l counts as two insns
3685              so that the insn length will be computed correctly.  */
3686           if (strstr (info.special, "xor.l") != NULL)
3687             wlength++;
3688
3689           /* Fall through.  */
3690
3691         case SHIFT_INLINE:
3692           n = info.remainder;
3693
3694           if (info.shift2 != NULL)
3695             {
3696               wlength += h8300_asm_insn_count (info.shift2) * (n / 2);
3697               n = n % 2;
3698             }
3699
3700           wlength += h8300_asm_insn_count (info.shift1) * n;
3701
3702           return 2 * wlength;
3703
3704         case SHIFT_ROT_AND:
3705           {
3706             int m = GET_MODE_BITSIZE (mode) - n;
3707
3708             /* Not all possibilities of rotate are supported.  They shouldn't
3709                be generated, but let's watch for 'em.  */
3710             if (info.shift1 == 0)
3711               abort ();
3712
3713             if (info.shift2 != NULL)
3714               {
3715                 wlength += h8300_asm_insn_count (info.shift2) * (m / 2);
3716                 m = m % 2;
3717               }
3718
3719             wlength += h8300_asm_insn_count (info.shift1) * m;
3720
3721             /* Now mask off the high bits.  */
3722             switch (mode)
3723               {
3724               case QImode:
3725                 wlength += 1;
3726                 break;
3727               case HImode:
3728                 wlength += 2;
3729                 break;
3730               case SImode:
3731                 if (TARGET_H8300)
3732                   abort ();
3733                 wlength += 3;
3734                 break;
3735               default:
3736                 abort ();
3737               }
3738             return 2 * wlength;
3739           }
3740
3741         case SHIFT_LOOP:
3742           /* A loop to shift by a "large" constant value.
3743              If we have shift-by-2 insns, use them.  */
3744           if (info.shift2 != NULL)
3745             {
3746               wlength += 3 + h8300_asm_insn_count (info.shift2);
3747               if (n % 2)
3748                 wlength += h8300_asm_insn_count (info.shift1);
3749             }
3750           else
3751             {
3752               wlength += 3 + h8300_asm_insn_count (info.shift1);
3753             }
3754           return 2 * wlength;
3755
3756         default:
3757           abort ();
3758         }
3759     }
3760 }
3761
3762 int
3763 compute_a_shift_cc (rtx insn ATTRIBUTE_UNUSED, rtx *operands)
3764 {
3765   rtx shift = operands[3];
3766   enum machine_mode mode = GET_MODE (shift);
3767   enum rtx_code code = GET_CODE (shift);
3768   enum shift_type shift_type;
3769   enum shift_mode shift_mode;
3770   struct shift_info info;
3771
3772   switch (mode)
3773     {
3774     case QImode:
3775       shift_mode = QIshift;
3776       break;
3777     case HImode:
3778       shift_mode = HIshift;
3779       break;
3780     case SImode:
3781       shift_mode = SIshift;
3782       break;
3783     default:
3784       abort ();
3785     }
3786
3787   switch (code)
3788     {
3789     case ASHIFTRT:
3790       shift_type = SHIFT_ASHIFTRT;
3791       break;
3792     case LSHIFTRT:
3793       shift_type = SHIFT_LSHIFTRT;
3794       break;
3795     case ASHIFT:
3796       shift_type = SHIFT_ASHIFT;
3797       break;
3798     default:
3799       abort ();
3800     }
3801
3802   if (GET_CODE (operands[2]) != CONST_INT)
3803     {
3804       /* This case must be taken care of by one of the two splitters
3805          that convert a variable shift into a loop.  */
3806       abort ();
3807     }
3808   else
3809     {
3810       int n = INTVAL (operands[2]);
3811
3812       /* If the count is negative, make it 0.  */
3813       if (n < 0)
3814         n = 0;
3815       /* If the count is too big, truncate it.
3816          ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
3817          do the intuitive thing.  */
3818       else if ((unsigned int) n > GET_MODE_BITSIZE (mode))
3819         n = GET_MODE_BITSIZE (mode);
3820
3821       get_shift_alg (shift_type, shift_mode, n, &info);
3822
3823       switch (info.alg)
3824         {
3825         case SHIFT_SPECIAL:
3826           if (info.remainder == 0)
3827             return info.cc_special;
3828
3829           /* Fall through.  */
3830
3831         case SHIFT_INLINE:
3832           return info.cc_inline;
3833
3834         case SHIFT_ROT_AND:
3835           /* This case always ends with an and instruction.  */
3836           return CC_SET_ZNV;
3837
3838         case SHIFT_LOOP:
3839           /* A loop to shift by a "large" constant value.
3840              If we have shift-by-2 insns, use them.  */
3841           if (info.shift2 != NULL)
3842             {
3843               if (n % 2)
3844                 return info.cc_inline;
3845             }
3846           return CC_CLOBBER;
3847
3848         default:
3849           abort ();
3850         }
3851     }
3852 }
3853 \f
3854 /* A rotation by a non-constant will cause a loop to be generated, in
3855    which a rotation by one bit is used.  A rotation by a constant,
3856    including the one in the loop, will be taken care of by
3857    output_a_rotate () at the insn emit time.  */
3858
3859 int
3860 expand_a_rotate (enum rtx_code code, rtx operands[])
3861 {
3862   rtx dst = operands[0];
3863   rtx src = operands[1];
3864   rtx rotate_amount = operands[2];
3865   enum machine_mode mode = GET_MODE (dst);
3866   rtx tmp;
3867
3868   /* We rotate in place.  */
3869   emit_move_insn (dst, src);
3870
3871   if (GET_CODE (rotate_amount) != CONST_INT)
3872     {
3873       rtx counter = gen_reg_rtx (QImode);
3874       rtx start_label = gen_label_rtx ();
3875       rtx end_label = gen_label_rtx ();
3876
3877       /* If the rotate amount is less than or equal to 0,
3878          we go out of the loop.  */
3879       emit_cmp_and_jump_insns (rotate_amount, const0_rtx, LE, NULL_RTX,
3880                                QImode, 0, end_label);
3881
3882       /* Initialize the loop counter.  */
3883       emit_move_insn (counter, rotate_amount);
3884
3885       emit_label (start_label);
3886
3887       /* Rotate by one bit.  */
3888       tmp = gen_rtx_fmt_ee (code, mode, dst, const1_rtx);
3889       emit_insn (gen_rtx_SET (mode, dst, tmp));
3890
3891       /* Decrement the counter by 1.  */
3892       tmp = gen_rtx_PLUS (QImode, counter, constm1_rtx);
3893       emit_insn (gen_rtx_SET (VOIDmode, counter, tmp));
3894
3895       /* If the loop counter is nonzero, we go back to the beginning
3896          of the loop.  */
3897       emit_cmp_and_jump_insns (counter, const0_rtx, NE, NULL_RTX, QImode, 1,
3898                                start_label);
3899
3900       emit_label (end_label);
3901     }
3902   else
3903     {
3904       /* Rotate by AMOUNT bits.  */
3905       tmp = gen_rtx_fmt_ee (code, mode, dst, rotate_amount);
3906       emit_insn (gen_rtx_SET (mode, dst, tmp));
3907     }
3908
3909   return 1;
3910 }
3911
3912 /* Output rotate insns.  */
3913
3914 const char *
3915 output_a_rotate (enum rtx_code code, rtx *operands)
3916 {
3917   rtx dst = operands[0];
3918   rtx rotate_amount = operands[2];
3919   enum shift_mode rotate_mode;
3920   enum shift_type rotate_type;
3921   const char *insn_buf;
3922   int bits;
3923   int amount;
3924   enum machine_mode mode = GET_MODE (dst);
3925
3926   if (GET_CODE (rotate_amount) != CONST_INT)
3927     abort ();
3928
3929   switch (mode)
3930     {
3931     case QImode:
3932       rotate_mode = QIshift;
3933       break;
3934     case HImode:
3935       rotate_mode = HIshift;
3936       break;
3937     case SImode:
3938       rotate_mode = SIshift;
3939       break;
3940     default:
3941       abort ();
3942     }
3943
3944   switch (code)
3945     {
3946     case ROTATERT:
3947       rotate_type = SHIFT_ASHIFT;
3948       break;
3949     case ROTATE:
3950       rotate_type = SHIFT_LSHIFTRT;
3951       break;
3952     default:
3953       abort ();
3954     }
3955
3956   amount = INTVAL (rotate_amount);
3957
3958   /* Clean up AMOUNT.  */
3959   if (amount < 0)
3960     amount = 0;
3961   if ((unsigned int) amount > GET_MODE_BITSIZE (mode))
3962     amount = GET_MODE_BITSIZE (mode);
3963
3964   /* Determine the faster direction.  After this phase, amount will be
3965      at most a half of GET_MODE_BITSIZE (mode).  */
3966   if ((unsigned int) amount > GET_MODE_BITSIZE (mode) / (unsigned) 2)
3967     {
3968       /* Flip the direction.  */
3969       amount = GET_MODE_BITSIZE (mode) - amount;
3970       rotate_type =
3971         (rotate_type == SHIFT_ASHIFT) ? SHIFT_LSHIFTRT : SHIFT_ASHIFT;
3972     }
3973
3974   /* See if a byte swap (in HImode) or a word swap (in SImode) can
3975      boost up the rotation.  */
3976   if ((mode == HImode && TARGET_H8300 && amount >= 5)
3977       || (mode == HImode && TARGET_H8300H && amount >= 6)
3978       || (mode == HImode && TARGET_H8300S && amount == 8)
3979       || (mode == SImode && TARGET_H8300H && amount >= 10)
3980       || (mode == SImode && TARGET_H8300S && amount >= 13))
3981     {
3982       switch (mode)
3983         {
3984         case HImode:
3985           /* This code works on any family.  */
3986           insn_buf = "xor.b\t%s0,%t0\n\txor.b\t%t0,%s0\n\txor.b\t%s0,%t0";
3987           output_asm_insn (insn_buf, operands);
3988           break;
3989
3990         case SImode:
3991           /* This code works on the H8/300H and H8S.  */
3992           insn_buf = "xor.w\t%e0,%f0\n\txor.w\t%f0,%e0\n\txor.w\t%e0,%f0";
3993           output_asm_insn (insn_buf, operands);
3994           break;
3995
3996         default:
3997           abort ();
3998         }
3999
4000       /* Adjust AMOUNT and flip the direction.  */
4001       amount = GET_MODE_BITSIZE (mode) / 2 - amount;
4002       rotate_type =
4003         (rotate_type == SHIFT_ASHIFT) ? SHIFT_LSHIFTRT : SHIFT_ASHIFT;
4004     }
4005
4006   /* Emit rotate insns.  */
4007   for (bits = TARGET_H8300S ? 2 : 1; bits > 0; bits /= 2)
4008     {
4009       if (bits == 2)
4010         insn_buf = rotate_two[rotate_type][rotate_mode];
4011       else
4012         insn_buf = rotate_one[cpu_type][rotate_type][rotate_mode];
4013
4014       for (; amount >= bits; amount -= bits)
4015         output_asm_insn (insn_buf, operands);
4016     }
4017
4018   return "";
4019 }
4020
4021 unsigned int
4022 compute_a_rotate_length (rtx *operands)
4023 {
4024   rtx src = operands[1];
4025   rtx amount_rtx = operands[2];
4026   enum machine_mode mode = GET_MODE (src);
4027   int amount;
4028   unsigned int length = 0;
4029
4030   if (GET_CODE (amount_rtx) != CONST_INT)
4031     abort ();
4032
4033   amount = INTVAL (amount_rtx);
4034
4035   /* Clean up AMOUNT.  */
4036   if (amount < 0)
4037     amount = 0;
4038   if ((unsigned int) amount > GET_MODE_BITSIZE (mode))
4039     amount = GET_MODE_BITSIZE (mode);
4040
4041   /* Determine the faster direction.  After this phase, amount
4042      will be at most a half of GET_MODE_BITSIZE (mode).  */
4043   if ((unsigned int) amount > GET_MODE_BITSIZE (mode) / (unsigned) 2)
4044     /* Flip the direction.  */
4045     amount = GET_MODE_BITSIZE (mode) - amount;
4046
4047   /* See if a byte swap (in HImode) or a word swap (in SImode) can
4048      boost up the rotation.  */
4049   if ((mode == HImode && TARGET_H8300 && amount >= 5)
4050       || (mode == HImode && TARGET_H8300H && amount >= 6)
4051       || (mode == HImode && TARGET_H8300S && amount == 8)
4052       || (mode == SImode && TARGET_H8300H && amount >= 10)
4053       || (mode == SImode && TARGET_H8300S && amount >= 13))
4054     {
4055       /* Adjust AMOUNT and flip the direction.  */
4056       amount = GET_MODE_BITSIZE (mode) / 2 - amount;
4057       length += 6;
4058     }
4059
4060   /* We use 2-bit rotations on the H8S.  */
4061   if (TARGET_H8300S)
4062     amount = amount / 2 + amount % 2;
4063
4064   /* The H8/300 uses three insns to rotate one bit, taking 6
4065      length.  */
4066   length += amount * ((TARGET_H8300 && mode == HImode) ? 6 : 2);
4067
4068   return length;
4069 }
4070 \f
4071 /* Fix the operands of a gen_xxx so that it could become a bit
4072    operating insn.  */
4073
4074 int
4075 fix_bit_operand (rtx *operands, int what, enum rtx_code type)
4076 {
4077   /* The bit_operand predicate accepts any memory during RTL generation, but
4078      only 'U' memory afterwards, so if this is a MEM operand, we must force
4079      it to be valid for 'U' by reloading the address.  */
4080
4081   if ((what == 0 && single_zero_operand (operands[2], QImode))
4082       || (what == 1 && single_one_operand (operands[2], QImode)))
4083     {
4084       /* OK to have a memory dest.  */
4085       if (GET_CODE (operands[0]) == MEM
4086           && !EXTRA_CONSTRAINT (operands[0], 'U'))
4087         {
4088           rtx mem = gen_rtx_MEM (GET_MODE (operands[0]),
4089                                  copy_to_mode_reg (Pmode,
4090                                                    XEXP (operands[0], 0)));
4091           MEM_COPY_ATTRIBUTES (mem, operands[0]);
4092           operands[0] = mem;
4093         }
4094
4095       if (GET_CODE (operands[1]) == MEM
4096           && !EXTRA_CONSTRAINT (operands[1], 'U'))
4097         {
4098           rtx mem = gen_rtx_MEM (GET_MODE (operands[1]),
4099                                  copy_to_mode_reg (Pmode,
4100                                                    XEXP (operands[1], 0)));
4101           MEM_COPY_ATTRIBUTES (mem, operands[0]);
4102           operands[1] = mem;
4103         }
4104       return 0;
4105     }
4106
4107   /* Dest and src op must be register.  */
4108
4109   operands[1] = force_reg (QImode, operands[1]);
4110   {
4111     rtx res = gen_reg_rtx (QImode);
4112     switch (type)
4113       {
4114       case AND:
4115         emit_insn (gen_andqi3_1 (res, operands[1], operands[2]));
4116         break;
4117       case IOR:
4118         emit_insn (gen_iorqi3_1 (res, operands[1], operands[2]));
4119         break;
4120       case XOR:
4121         emit_insn (gen_xorqi3_1 (res, operands[1], operands[2]));
4122         break;
4123       default:
4124         abort ();
4125       }
4126     emit_insn (gen_movqi (operands[0], res));
4127   }
4128   return 1;
4129 }
4130
4131 /* Return nonzero if FUNC is an interrupt function as specified
4132    by the "interrupt" attribute.  */
4133
4134 static int
4135 h8300_interrupt_function_p (tree func)
4136 {
4137   tree a;
4138
4139   if (TREE_CODE (func) != FUNCTION_DECL)
4140     return 0;
4141
4142   a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
4143   return a != NULL_TREE;
4144 }
4145
4146 /* Return nonzero if FUNC is a saveall function as specified by the
4147    "saveall" attribute.  */
4148
4149 static int
4150 h8300_saveall_function_p (tree func)
4151 {
4152   tree a;
4153
4154   if (TREE_CODE (func) != FUNCTION_DECL)
4155     return 0;
4156
4157   a = lookup_attribute ("saveall", DECL_ATTRIBUTES (func));
4158   return a != NULL_TREE;
4159 }
4160
4161 /* Return nonzero if FUNC is an OS_Task function as specified
4162    by the "OS_Task" attribute.  */
4163
4164 static int
4165 h8300_os_task_function_p (tree func)
4166 {
4167   tree a;
4168
4169   if (TREE_CODE (func) != FUNCTION_DECL)
4170     return 0;
4171
4172   a = lookup_attribute ("OS_Task", DECL_ATTRIBUTES (func));
4173   return a != NULL_TREE;
4174 }
4175
4176 /* Return nonzero if FUNC is a monitor function as specified
4177    by the "monitor" attribute.  */
4178
4179 static int
4180 h8300_monitor_function_p (tree func)
4181 {
4182   tree a;
4183
4184   if (TREE_CODE (func) != FUNCTION_DECL)
4185     return 0;
4186
4187   a = lookup_attribute ("monitor", DECL_ATTRIBUTES (func));
4188   return a != NULL_TREE;
4189 }
4190
4191 /* Return nonzero if FUNC is a function that should be called
4192    through the function vector.  */
4193
4194 int
4195 h8300_funcvec_function_p (tree func)
4196 {
4197   tree a;
4198
4199   if (TREE_CODE (func) != FUNCTION_DECL)
4200     return 0;
4201
4202   a = lookup_attribute ("function_vector", DECL_ATTRIBUTES (func));
4203   return a != NULL_TREE;
4204 }
4205
4206 /* Return nonzero if DECL is a variable that's in the eight bit
4207    data area.  */
4208
4209 int
4210 h8300_eightbit_data_p (tree decl)
4211 {
4212   tree a;
4213
4214   if (TREE_CODE (decl) != VAR_DECL)
4215     return 0;
4216
4217   a = lookup_attribute ("eightbit_data", DECL_ATTRIBUTES (decl));
4218   return a != NULL_TREE;
4219 }
4220
4221 /* Return nonzero if DECL is a variable that's in the tiny
4222    data area.  */
4223
4224 int
4225 h8300_tiny_data_p (tree decl)
4226 {
4227   tree a;
4228
4229   if (TREE_CODE (decl) != VAR_DECL)
4230     return 0;
4231
4232   a = lookup_attribute ("tiny_data", DECL_ATTRIBUTES (decl));
4233   return a != NULL_TREE;
4234 }
4235
4236 /* Generate an 'interrupt_handler' attribute for decls.  We convert
4237    all the pragmas to corresponding attributes.  */
4238
4239 static void
4240 h8300_insert_attributes (tree node, tree *attributes)
4241 {
4242   if (TREE_CODE (node) == FUNCTION_DECL)
4243     {
4244       if (pragma_interrupt)
4245         {
4246           pragma_interrupt = 0;
4247
4248           /* Add an 'interrupt_handler' attribute.  */
4249           *attributes = tree_cons (get_identifier ("interrupt_handler"),
4250                                    NULL, *attributes);
4251         }
4252
4253       if (pragma_saveall)
4254         {
4255           pragma_saveall = 0;
4256
4257           /* Add an 'saveall' attribute.  */
4258           *attributes = tree_cons (get_identifier ("saveall"),
4259                                    NULL, *attributes);
4260         }
4261     }
4262 }
4263
4264 /* Supported attributes:
4265
4266    interrupt_handler: output a prologue and epilogue suitable for an
4267    interrupt handler.
4268
4269    saveall: output a prologue and epilogue that saves and restores
4270    all registers except the stack pointer.
4271
4272    function_vector: This function should be called through the
4273    function vector.
4274
4275    eightbit_data: This variable lives in the 8-bit data area and can
4276    be referenced with 8-bit absolute memory addresses.
4277
4278    tiny_data: This variable lives in the tiny data area and can be
4279    referenced with 16-bit absolute memory references.  */
4280
4281 const struct attribute_spec h8300_attribute_table[] =
4282 {
4283   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
4284   { "interrupt_handler", 0, 0, true,  false, false, h8300_handle_fndecl_attribute },
4285   { "saveall",           0, 0, true,  false, false, h8300_handle_fndecl_attribute },
4286   { "OS_Task",           0, 0, true,  false, false, h8300_handle_fndecl_attribute },
4287   { "monitor",           0, 0, true,  false, false, h8300_handle_fndecl_attribute },
4288   { "function_vector",   0, 0, true,  false, false, h8300_handle_fndecl_attribute },
4289   { "eightbit_data",     0, 0, true,  false, false, h8300_handle_eightbit_data_attribute },
4290   { "tiny_data",         0, 0, true,  false, false, h8300_handle_tiny_data_attribute },
4291   { NULL,                0, 0, false, false, false, NULL }
4292 };
4293
4294
4295 /* Handle an attribute requiring a FUNCTION_DECL; arguments as in
4296    struct attribute_spec.handler.  */
4297 static tree
4298 h8300_handle_fndecl_attribute (tree *node, tree name,
4299                                tree args ATTRIBUTE_UNUSED,
4300                                int flags ATTRIBUTE_UNUSED,
4301                                bool *no_add_attrs)
4302 {
4303   if (TREE_CODE (*node) != FUNCTION_DECL)
4304     {
4305       warning ("`%s' attribute only applies to functions",
4306                IDENTIFIER_POINTER (name));
4307       *no_add_attrs = true;
4308     }
4309
4310   return NULL_TREE;
4311 }
4312
4313 /* Handle an "eightbit_data" attribute; arguments as in
4314    struct attribute_spec.handler.  */
4315 static tree
4316 h8300_handle_eightbit_data_attribute (tree *node, tree name,
4317                                       tree args ATTRIBUTE_UNUSED,
4318                                       int flags ATTRIBUTE_UNUSED,
4319                                       bool *no_add_attrs)
4320 {
4321   tree decl = *node;
4322
4323   if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
4324     {
4325       DECL_SECTION_NAME (decl) = build_string (7, ".eight");
4326     }
4327   else
4328     {
4329       warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
4330       *no_add_attrs = true;
4331     }
4332
4333   return NULL_TREE;
4334 }
4335
4336 /* Handle an "tiny_data" attribute; arguments as in
4337    struct attribute_spec.handler.  */
4338 static tree
4339 h8300_handle_tiny_data_attribute (tree *node, tree name,
4340                                   tree args ATTRIBUTE_UNUSED,
4341                                   int flags ATTRIBUTE_UNUSED,
4342                                   bool *no_add_attrs)
4343 {
4344   tree decl = *node;
4345
4346   if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
4347     {
4348       DECL_SECTION_NAME (decl) = build_string (6, ".tiny");
4349     }
4350   else
4351     {
4352       warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
4353       *no_add_attrs = true;
4354     }
4355
4356   return NULL_TREE;
4357 }
4358
4359 /* Mark function vectors, and various small data objects.  */
4360
4361 static void
4362 h8300_encode_section_info (tree decl, rtx rtl, int first)
4363 {
4364   int extra_flags = 0;
4365
4366   default_encode_section_info (decl, rtl, first);
4367
4368   if (TREE_CODE (decl) == FUNCTION_DECL
4369       && h8300_funcvec_function_p (decl))
4370     extra_flags = SYMBOL_FLAG_FUNCVEC_FUNCTION;
4371   else if (TREE_CODE (decl) == VAR_DECL
4372            && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
4373     {
4374       if (h8300_eightbit_data_p (decl))
4375         extra_flags = SYMBOL_FLAG_EIGHTBIT_DATA;
4376       else if (first && h8300_tiny_data_p (decl))
4377         extra_flags = SYMBOL_FLAG_TINY_DATA;
4378     }
4379
4380   if (extra_flags)
4381     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= extra_flags;
4382 }
4383
4384 const char *
4385 output_simode_bld (int bild, rtx operands[])
4386 {
4387   if (TARGET_H8300)
4388     {
4389       /* Clear the destination register.  */
4390       output_asm_insn ("sub.w\t%e0,%e0\n\tsub.w\t%f0,%f0", operands);
4391
4392       /* Now output the bit load or bit inverse load, and store it in
4393          the destination.  */
4394       if (bild)
4395         output_asm_insn ("bild\t%Z2,%Y1", operands);
4396       else
4397         output_asm_insn ("bld\t%Z2,%Y1", operands);
4398
4399       output_asm_insn ("bst\t#0,%w0", operands);
4400     }
4401   else
4402     {
4403       /* Determine if we can clear the destination first.  */
4404       int clear_first = (REG_P (operands[0]) && REG_P (operands[1])
4405                          && REGNO (operands[0]) != REGNO (operands[1]));
4406
4407       if (clear_first)
4408         output_asm_insn ("sub.l\t%S0,%S0", operands);
4409
4410       /* Output the bit load or bit inverse load.  */
4411       if (bild)
4412         output_asm_insn ("bild\t%Z2,%Y1", operands);
4413       else
4414         output_asm_insn ("bld\t%Z2,%Y1", operands);
4415
4416       if (!clear_first)
4417         output_asm_insn ("xor.l\t%S0,%S0", operands);
4418
4419       /* Perform the bit store.  */
4420       output_asm_insn ("rotxl.l\t%S0", operands);
4421     }
4422
4423   /* All done.  */
4424   return "";
4425 }
4426
4427 #ifndef OBJECT_FORMAT_ELF
4428 static void
4429 h8300_asm_named_section (const char *name, unsigned int flags ATTRIBUTE_UNUSED)
4430 {
4431   /* ??? Perhaps we should be using default_coff_asm_named_section.  */
4432   fprintf (asm_out_file, "\t.section %s\n", name);
4433 }
4434 #endif /* ! OBJECT_FORMAT_ELF */
4435
4436 /* Nonzero if X is a constant address suitable as an 8-bit absolute,
4437    which is a special case of the 'R' operand.  */
4438
4439 int
4440 h8300_eightbit_constant_address_p (rtx x)
4441 {
4442   /* The ranges of the 8-bit area.  */
4443   const unsigned HOST_WIDE_INT n1 = trunc_int_for_mode (0xff00, HImode);
4444   const unsigned HOST_WIDE_INT n2 = trunc_int_for_mode (0xffff, HImode);
4445   const unsigned HOST_WIDE_INT h1 = trunc_int_for_mode (0x00ffff00, SImode);
4446   const unsigned HOST_WIDE_INT h2 = trunc_int_for_mode (0x00ffffff, SImode);
4447   const unsigned HOST_WIDE_INT s1 = trunc_int_for_mode (0xffffff00, SImode);
4448   const unsigned HOST_WIDE_INT s2 = trunc_int_for_mode (0xffffffff, SImode);
4449
4450   unsigned HOST_WIDE_INT addr;
4451
4452   /* We accept symbols declared with eightbit_data.  */
4453   if (GET_CODE (x) == SYMBOL_REF)
4454     return (SYMBOL_REF_FLAGS (x) & SYMBOL_FLAG_EIGHTBIT_DATA) != 0;
4455
4456   if (GET_CODE (x) != CONST_INT)
4457     return 0;
4458
4459   addr = INTVAL (x);
4460
4461   return (0
4462           || ((TARGET_H8300 || TARGET_NORMAL_MODE) && IN_RANGE (addr, n1, n2))
4463           || (TARGET_H8300H && IN_RANGE (addr, h1, h2))
4464           || (TARGET_H8300S && IN_RANGE (addr, s1, s2)));
4465 }
4466
4467 /* Nonzero if X is a constant address suitable as an 16-bit absolute
4468    on H8/300H and H8S.  */
4469
4470 int
4471 h8300_tiny_constant_address_p (rtx x)
4472 {
4473   /* The ranges of the 16-bit area.  */
4474   const unsigned HOST_WIDE_INT h1 = trunc_int_for_mode (0x00000000, SImode);
4475   const unsigned HOST_WIDE_INT h2 = trunc_int_for_mode (0x00007fff, SImode);
4476   const unsigned HOST_WIDE_INT h3 = trunc_int_for_mode (0x00ff8000, SImode);
4477   const unsigned HOST_WIDE_INT h4 = trunc_int_for_mode (0x00ffffff, SImode);
4478   const unsigned HOST_WIDE_INT s1 = trunc_int_for_mode (0x00000000, SImode);
4479   const unsigned HOST_WIDE_INT s2 = trunc_int_for_mode (0x00007fff, SImode);
4480   const unsigned HOST_WIDE_INT s3 = trunc_int_for_mode (0xffff8000, SImode);
4481   const unsigned HOST_WIDE_INT s4 = trunc_int_for_mode (0xffffffff, SImode);
4482
4483   unsigned HOST_WIDE_INT addr;
4484
4485   switch (GET_CODE (x))
4486     {
4487     case SYMBOL_REF:
4488       /* In the normal mode, any symbol fits in the 16-bit absolute
4489          address range.  We also accept symbols declared with
4490          tiny_data.  */
4491       return (TARGET_NORMAL_MODE
4492               || (SYMBOL_REF_FLAGS (x) & SYMBOL_FLAG_TINY_DATA) != 0);
4493
4494     case CONST_INT:
4495       addr = INTVAL (x);
4496       return (TARGET_NORMAL_MODE
4497               || (TARGET_H8300H
4498                   && (IN_RANGE (addr, h1, h2) || IN_RANGE (addr, h3, h4)))
4499               || (TARGET_H8300S
4500                   && (IN_RANGE (addr, s1, s2) || IN_RANGE (addr, s3, s4))));
4501
4502     case CONST:
4503       return TARGET_NORMAL_MODE;
4504
4505     default:
4506       return 0;
4507     }
4508
4509 }
4510
4511 int
4512 byte_accesses_mergeable_p (rtx addr1, rtx addr2)
4513 {
4514   HOST_WIDE_INT offset1, offset2;
4515   rtx reg1, reg2;
4516
4517   if (REG_P (addr1))
4518     {
4519       reg1 = addr1;
4520       offset1 = 0;
4521     }
4522   else if (GET_CODE (addr1) == PLUS
4523            && REG_P (XEXP (addr1, 0))
4524            && GET_CODE (XEXP (addr1, 1)) == CONST_INT)
4525     {
4526       reg1 = XEXP (addr1, 0);
4527       offset1 = INTVAL (XEXP (addr1, 1));
4528     }
4529   else
4530     return 0;
4531
4532   if (REG_P (addr2))
4533     {
4534       reg2 = addr2;
4535       offset2 = 0;
4536     }
4537   else if (GET_CODE (addr2) == PLUS
4538            && REG_P (XEXP (addr2, 0))
4539            && GET_CODE (XEXP (addr2, 1)) == CONST_INT)
4540     {
4541       reg2 = XEXP (addr2, 0);
4542       offset2 = INTVAL (XEXP (addr2, 1));
4543     }
4544   else
4545     return 0;
4546
4547   if (((reg1 == stack_pointer_rtx && reg2 == stack_pointer_rtx)
4548        || (reg1 == frame_pointer_rtx && reg2 == frame_pointer_rtx))
4549       && offset1 % 2 == 0
4550       && offset1 + 1 == offset2)
4551     return 1;
4552
4553   return 0;
4554 }
4555
4556 /* Return nonzero if we have the same comparison insn as I3 two insns
4557    before I3.  I3 is assumed to be a comparison insn.  */
4558
4559 int
4560 same_cmp_preceding_p (rtx i3)
4561 {
4562   rtx i1, i2;
4563
4564   /* Make sure we have a sequence of three insns.  */
4565   i2 = prev_nonnote_insn (i3);
4566   if (i2 == NULL_RTX)
4567     return 0;
4568   i1 = prev_nonnote_insn (i2);
4569   if (i1 == NULL_RTX)
4570     return 0;
4571
4572   return (INSN_P (i1) && rtx_equal_p (PATTERN (i1), PATTERN (i3))
4573           && any_condjump_p (i2) && onlyjump_p (i2));
4574 }
4575
4576 /* Return nonzero if we have the same comparison insn as I1 two insns
4577    after I1.  I1 is assumed to be a comparison insn.  */
4578
4579 int
4580 same_cmp_following_p (rtx i1)
4581 {
4582   rtx i2, i3;
4583
4584   /* Make sure we have a sequence of three insns.  */
4585   i2 = next_nonnote_insn (i1);
4586   if (i2 == NULL_RTX)
4587     return 0;
4588   i3 = next_nonnote_insn (i2);
4589   if (i3 == NULL_RTX)
4590     return 0;
4591
4592   return (INSN_P (i3) && rtx_equal_p (PATTERN (i1), PATTERN (i3))
4593           && any_condjump_p (i2) && onlyjump_p (i2));
4594 }
4595
4596 /* Return nonzero if OPERANDS are valid for stm (or ldm) that pushes
4597    (or pops) N registers.  OPERANDS are asssumed to be an array of
4598    registers.  */
4599
4600 int
4601 h8300_regs_ok_for_stm (int n, rtx operands[])
4602 {
4603   switch (n)
4604     {
4605     case 2:
4606       return ((REGNO (operands[0]) == 0 && REGNO (operands[1]) == 1)
4607               || (REGNO (operands[0]) == 2 && REGNO (operands[1]) == 3)
4608               || (REGNO (operands[0]) == 4 && REGNO (operands[1]) == 5));
4609     case 3:
4610       return ((REGNO (operands[0]) == 0
4611                && REGNO (operands[1]) == 1
4612                && REGNO (operands[2]) == 2)
4613               || (REGNO (operands[0]) == 4
4614                   && REGNO (operands[1]) == 5
4615                   && REGNO (operands[2]) == 6));
4616
4617     case 4:
4618       return (REGNO (operands[0]) == 0
4619               && REGNO (operands[1]) == 1
4620               && REGNO (operands[2]) == 2
4621               && REGNO (operands[3]) == 3);
4622     }
4623
4624   abort ();
4625 }
4626
4627 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG.  */
4628
4629 int
4630 h8300_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED,
4631                             unsigned int new_reg)
4632 {
4633   /* Interrupt functions can only use registers that have already been
4634      saved by the prologue, even if they would normally be
4635      call-clobbered.  */
4636
4637   if (h8300_current_function_interrupt_function_p ()
4638       && !regs_ever_live[new_reg])
4639     return 0;
4640
4641   return 1;
4642 }
4643
4644 /* Return nonzero if X is a legitimate constant.  */
4645
4646 int
4647 h8300_legitimate_constant_p (rtx x ATTRIBUTE_UNUSED)
4648 {
4649   return 1;
4650 }
4651
4652 /* Return nonzero if X is a REG or SUBREG suitable as a base register.  */
4653
4654 static int
4655 h8300_rtx_ok_for_base_p (rtx x, int strict)
4656 {
4657   /* Strip off SUBREG if any.  */
4658   if (GET_CODE (x) == SUBREG)
4659     x = SUBREG_REG (x);
4660
4661   return (REG_P (x)
4662           && (strict
4663               ? REG_OK_FOR_BASE_STRICT_P (x)
4664               : REG_OK_FOR_BASE_NONSTRICT_P (x)));
4665 }
4666
4667 /* Return nozero if X is a legitimate address.  On the H8/300, a
4668    legitimate address has the form REG, REG+CONSTANT_ADDRESS or
4669    CONSTANT_ADDRESS.  */
4670
4671 int
4672 h8300_legitimate_address_p (rtx x, int strict)
4673 {
4674   /* The register indirect addresses like @er0 is always valid.  */
4675   if (h8300_rtx_ok_for_base_p (x, strict))
4676     return 1;
4677
4678   if (CONSTANT_ADDRESS_P (x))
4679     return 1;
4680
4681   if (GET_CODE (x) == PLUS
4682       && CONSTANT_ADDRESS_P (XEXP (x, 1))
4683       && h8300_rtx_ok_for_base_p (XEXP (x, 0), strict))
4684     return 1;
4685
4686   return 0;
4687 }
4688 \f
4689 /* Perform target dependent optabs initialization.  */
4690 static void
4691 h8300_init_libfuncs (void)
4692 {
4693   set_optab_libfunc (smul_optab, HImode, "__mulhi3");
4694   set_optab_libfunc (sdiv_optab, HImode, "__divhi3");
4695   set_optab_libfunc (udiv_optab, HImode, "__udivhi3");
4696   set_optab_libfunc (smod_optab, HImode, "__modhi3");
4697   set_optab_libfunc (umod_optab, HImode, "__umodhi3");
4698 }
4699 \f
4700 static bool
4701 h8300_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
4702 {
4703   return (TYPE_MODE (type) == BLKmode
4704           || GET_MODE_SIZE (TYPE_MODE (type)) > (TARGET_H8300 ? 4 : 8));
4705 }
4706 \f
4707 /* Initialize the GCC target structure.  */
4708 #undef TARGET_ATTRIBUTE_TABLE
4709 #define TARGET_ATTRIBUTE_TABLE h8300_attribute_table
4710
4711 #undef TARGET_ASM_ALIGNED_HI_OP
4712 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
4713
4714 #undef TARGET_ASM_FILE_START
4715 #define TARGET_ASM_FILE_START h8300_file_start
4716 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
4717 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
4718
4719 #undef TARGET_ASM_FILE_END
4720 #define TARGET_ASM_FILE_END h8300_file_end
4721
4722 #undef TARGET_ENCODE_SECTION_INFO
4723 #define TARGET_ENCODE_SECTION_INFO h8300_encode_section_info
4724
4725 #undef TARGET_INSERT_ATTRIBUTES
4726 #define TARGET_INSERT_ATTRIBUTES h8300_insert_attributes
4727
4728 #undef TARGET_RTX_COSTS
4729 #define TARGET_RTX_COSTS h8300_rtx_costs
4730
4731 #undef TARGET_INIT_LIBFUNCS
4732 #define TARGET_INIT_LIBFUNCS h8300_init_libfuncs
4733
4734 #undef TARGET_RETURN_IN_MEMORY
4735 #define TARGET_RETURN_IN_MEMORY h8300_return_in_memory
4736
4737 struct gcc_target targetm = TARGET_INITIALIZER;