]> gcc.gnu.org Git - gcc.git/blob - gcc/config/h8300/h8300.c
alpha-protos.h: PROTO -> PARAMS.
[gcc.git] / gcc / config / h8300 / h8300.c
1 /* Subroutines for insn-output.c for Hitachi H8/300.
2 Copyright (C) 1992, 93-99, 2000 Free Software
3 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 GNU CC.
8
9 GNU CC 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 GNU CC 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 GNU CC; 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 "rtl.h"
27 #include "tree.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "real.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-flags.h"
34 #include "output.h"
35 #include "insn-attr.h"
36 #include "flags.h"
37 #include "recog.h"
38 #include "expr.h"
39 #include "function.h"
40 #include "obstack.h"
41 #include "toplev.h"
42 #include "tm_p.h"
43
44 /* Forward declarations. */
45 static int h8300_interrupt_function_p PARAMS ((tree));
46 static int h8300_monitor_function_p PARAMS ((tree));
47 static int h8300_os_task_function_p PARAMS ((tree));
48 static void dosize PARAMS ((FILE *, const char *, unsigned int));
49 static const char *cond_string PARAMS ((enum rtx_code));
50
51 /* CPU_TYPE, says what cpu we're compiling for. */
52 int cpu_type;
53
54 /* True if the current function is an interrupt handler
55 (either via #pragma or an attribute specification). */
56 int interrupt_handler;
57
58 /* True if the current function is an OS Task
59 (via an attribute specification). */
60 int os_task;
61
62 /* True if the current function is a monitor
63 (via an attribute specification). */
64 int monitor;
65
66 /* True if a #pragma saveall has been seen for the current function. */
67 int pragma_saveall;
68
69 static const char *const names_big[] =
70 {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7"};
71
72 static const char *const names_extended[] =
73 {"er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7"};
74
75 static const char *const names_upper_extended[] =
76 {"e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7"};
77
78 /* Points to one of the above. */
79 /* ??? The above could be put in an array indexed by CPU_TYPE. */
80 const char * const *h8_reg_names;
81
82 /* Various operations needed by the following, indexed by CPU_TYPE. */
83
84 static const char *const h8_push_ops[2] = {"push", "push.l"};
85 static const char *const h8_pop_ops[2] = {"pop", "pop.l"};
86 static const char *const h8_mov_ops[2] = {"mov.w", "mov.l"};
87
88 const char *h8_push_op, *h8_pop_op, *h8_mov_op;
89
90 /* Initialize various cpu specific globals at start up. */
91
92 void
93 h8300_init_once ()
94 {
95 if (TARGET_H8300)
96 {
97 cpu_type = (int) CPU_H8300;
98 h8_reg_names = names_big;
99 }
100 else
101 {
102 /* For this we treat the H8/300 and H8/S the same. */
103 cpu_type = (int) CPU_H8300H;
104 h8_reg_names = names_extended;
105 }
106 h8_push_op = h8_push_ops[cpu_type];
107 h8_pop_op = h8_pop_ops[cpu_type];
108 h8_mov_op = h8_mov_ops[cpu_type];
109 }
110
111 const char *
112 byte_reg (x, b)
113 rtx x;
114 int b;
115 {
116 static const char *const names_small[] =
117 {"r0l", "r0h", "r1l", "r1h", "r2l", "r2h", "r3l", "r3h",
118 "r4l", "r4h", "r5l", "r5h", "r6l", "r6h", "r7l", "r7h"};
119
120 return names_small[REGNO (x) * 2 + b];
121 }
122
123 /* REGNO must be saved/restored across calls if this macro is true. */
124
125 #define WORD_REG_USED(regno) \
126 (regno < 7 \
127 /* No need to save registers if this function will not return.*/\
128 && ! TREE_THIS_VOLATILE (current_function_decl) \
129 && (pragma_saveall \
130 /* Save any call saved register that was used. */ \
131 || (regs_ever_live[regno] && !call_used_regs[regno]) \
132 /* Save the frame pointer if it was used. */ \
133 || (regno == FRAME_POINTER_REGNUM && regs_ever_live[regno])\
134 /* Save any register used in an interrupt handler. */ \
135 || (interrupt_handler && regs_ever_live[regno]) \
136 /* Save call clobbered registers in non-leaf interrupt \
137 handlers. */ \
138 || (interrupt_handler \
139 && call_used_regs[regno] \
140 && !current_function_is_leaf)))
141
142 /* Output assembly language to FILE for the operation OP with operand size
143 SIZE to adjust the stack pointer. */
144
145 static void
146 dosize (file, op, size)
147 FILE *file;
148 const char *op;
149 unsigned int size;
150 {
151 /* On the h8300h and h8300s, for sizes <= 8 bytes it is as good or
152 better to use adds/subs insns rather than add.l/sub.l
153 with an immediate value. */
154 if (size > 4 && size <= 8 && (TARGET_H8300H || TARGET_H8300S))
155 {
156 /* Crank the size down to <= 4 */
157 fprintf (file, "\t%ss\t#%d,sp\n", op, 4);
158 size -= 4;
159 }
160
161 switch (size)
162 {
163 case 4:
164 if (TARGET_H8300H || TARGET_H8300S)
165 {
166 fprintf (file, "\t%ss\t#%d,sp\n", op, 4);
167 size = 0;
168 break;
169 }
170 case 3:
171 fprintf (file, "\t%ss\t#%d,sp\n", op, 2);
172 size -= 2;
173 /* Fall through... */
174 case 2:
175 case 1:
176 fprintf (file, "\t%ss\t#%d,sp\n", op, size);
177 size = 0;
178 break;
179 case 0:
180 break;
181 default:
182 if (TARGET_H8300)
183 {
184 if (current_function_needs_context
185 && strcmp (op, "sub") == 0)
186 {
187 /* Egad. We don't have a temporary to hold the
188 size of the frame in the prologue! Just inline
189 the bastard since this shouldn't happen often. */
190 while (size >= 2)
191 {
192 fprintf (file, "\tsubs\t#2,sp\n");
193 size -= 2;
194 }
195
196 if (size)
197 fprintf (file, "\tsubs\t#1,sp\n");
198
199 size = 0;
200 }
201 else
202 fprintf (file, "\tmov.w\t#%d,r3\n\t%s.w\tr3,sp\n", size, op);
203 }
204 else
205 fprintf (file, "\t%s\t#%d,sp\n", op, size);
206 size = 0;
207 break;
208 }
209 }
210
211 /* Output assembly language code for the function prologue. */
212 static int push_order[FIRST_PSEUDO_REGISTER] =
213 {0, 1, 2, 3, 4, 5, 6, -1, -1, -1};
214 static int pop_order[FIRST_PSEUDO_REGISTER] =
215 {6, 5, 4, 3, 2, 1, 0, -1, -1, -1};
216
217 /* This is what the stack looks like after the prolog of
218 a function with a frame has been set up:
219
220 <args>
221 PC
222 FP <- fp
223 <locals>
224 <saved registers> <- sp
225
226 This is what the stack looks like after the prolog of
227 a function which doesn't have a frame:
228
229 <args>
230 PC
231 <locals>
232 <saved registers> <- sp
233 */
234
235 void
236 function_prologue (file, size)
237 FILE *file;
238 int size;
239 {
240 int fsize = (size + STACK_BOUNDARY / 8 - 1) & -STACK_BOUNDARY / 8;
241 int idx;
242
243 /* Note a function with the interrupt attribute and set interrupt_handler
244 accordingly. */
245 if (h8300_interrupt_function_p (current_function_decl))
246 interrupt_handler = 1;
247
248 /* If the current function has the OS_Task attribute set, then
249 we have a naked prologue. */
250 if (h8300_os_task_function_p (current_function_decl))
251 {
252 fprintf (file, ";OS_Task prologue\n");
253 os_task = 1;
254 return;
255 }
256
257 if (h8300_monitor_function_p (current_function_decl))
258 {
259 /* My understanding of monitor functions is they act just
260 like interrupt functions, except the prologue must
261 mask interrupts. */
262 fprintf (file, ";monitor prologue\n");
263 interrupt_handler = 1;
264 monitor = 1;
265 if (TARGET_H8300)
266 {
267 fprintf (file, "\tsubs\t#2,sp\n");
268 fprintf (file, "\tpush\tr0\n");
269 fprintf (file, "\tstc\tccr,r0l\n");
270 fprintf (file, "\torc\t#128,ccr\n");
271 fprintf (file, "\tmov.b\tr0l,@(4,sp)\n");
272 }
273 else
274 {
275 fprintf (file, "\tpush\ter0\n");
276 fprintf (file, "\tstc\tccr,r0l\n");
277 fprintf (file, "\torc\t#128,ccr\n");
278 fprintf (file, "\tmov.b\tr0l,@(4,sp)\n");
279 }
280 }
281
282 if (frame_pointer_needed)
283 {
284 /* Push fp */
285 fprintf (file, "\t%s\t%s\n", h8_push_op,
286 h8_reg_names[FRAME_POINTER_REGNUM]);
287 fprintf (file, "\t%s\t%s,%s\n", h8_mov_op,
288 h8_reg_names[STACK_POINTER_REGNUM],
289 h8_reg_names[FRAME_POINTER_REGNUM]);
290 }
291
292 /* leave room for locals */
293 dosize (file, "sub", fsize);
294
295 /* Push the rest of the registers */
296 for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx++)
297 {
298 int regno = push_order[idx];
299
300 if (regno >= 0
301 && WORD_REG_USED (regno)
302 && (!frame_pointer_needed || regno != FRAME_POINTER_REGNUM))
303 {
304 if (TARGET_H8300S)
305 {
306 /* Try to push multiple registers. */
307 if (regno == 0 || regno == 4)
308 {
309 int second_regno = push_order[idx + 1];
310 int third_regno = push_order[idx + 2];
311 int fourth_regno = push_order[idx + 3];
312
313 if (fourth_regno >= 0
314 && WORD_REG_USED (fourth_regno)
315 && (!frame_pointer_needed
316 || fourth_regno != FRAME_POINTER_REGNUM)
317 && third_regno >= 0
318 && WORD_REG_USED (third_regno)
319 && (!frame_pointer_needed
320 || third_regno != FRAME_POINTER_REGNUM)
321 && second_regno >= 0
322 && WORD_REG_USED (second_regno)
323 && (!frame_pointer_needed
324 || second_regno != FRAME_POINTER_REGNUM))
325 {
326 fprintf (file, "\tstm.l %s-%s,@-sp\n",
327 h8_reg_names[regno],
328 h8_reg_names[fourth_regno]);
329 idx += 3;
330 continue;
331 }
332 }
333 if (regno == 0 || regno == 4)
334 {
335 int second_regno = push_order[idx + 1];
336 int third_regno = push_order[idx + 2];
337
338 if (third_regno >= 0
339 && WORD_REG_USED (third_regno)
340 && (!frame_pointer_needed
341 || third_regno != FRAME_POINTER_REGNUM)
342 && second_regno >= 0
343 && WORD_REG_USED (second_regno)
344 && (!frame_pointer_needed
345 || second_regno != FRAME_POINTER_REGNUM))
346 {
347 fprintf (file, "\tstm.l %s-%s,@-sp\n",
348 h8_reg_names[regno],
349 h8_reg_names[third_regno]);
350 idx += 2;
351 continue;
352 }
353 }
354 if (regno == 0 || regno == 2 || regno == 4 || regno == 6)
355 {
356 int second_regno = push_order[idx + 1];
357
358 if (second_regno >= 0
359 && WORD_REG_USED (second_regno)
360 && (!frame_pointer_needed
361 || second_regno != FRAME_POINTER_REGNUM))
362 {
363 fprintf (file, "\tstm.l %s-%s,@-sp\n",
364 h8_reg_names[regno],
365 h8_reg_names[second_regno]);
366 idx += 1;
367 continue;
368 }
369 }
370 }
371 fprintf (file, "\t%s\t%s\n", h8_push_op, h8_reg_names[regno]);
372 }
373 }
374 }
375
376 /* Output assembly language code for the function epilogue. */
377
378 void
379 function_epilogue (file, size)
380 FILE *file;
381 int size;
382 {
383 int fsize = (size + STACK_BOUNDARY / 8 - 1) & -STACK_BOUNDARY / 8;
384 int idx;
385 rtx insn = get_last_insn ();
386
387 if (os_task)
388 {
389 /* OS_Task epilogues are nearly naked -- they just have an
390 rts instruction. */
391 fprintf (file, ";OS_task epilogue\n");
392 fprintf (file, "\trts\n");
393 goto out;
394 }
395
396 /* monitor epilogues are the same as interrupt function epilogues.
397 Just make a note that we're in an monitor epilogue. */
398 if (monitor)
399 fprintf(file, ";monitor epilogue\n");
400
401 /* If the last insn was a BARRIER, we don't have to write any code. */
402 if (GET_CODE (insn) == NOTE)
403 insn = prev_nonnote_insn (insn);
404 if (insn && GET_CODE (insn) == BARRIER)
405 return;
406
407 /* Pop the saved registers. */
408 for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx++)
409 {
410 int regno = pop_order[idx];
411
412 if (regno >= 0
413 && WORD_REG_USED (regno)
414 && (!frame_pointer_needed || regno != FRAME_POINTER_REGNUM))
415 {
416 if (TARGET_H8300S)
417 {
418 /* Try to pop multiple registers. */
419 if (regno == 7 || regno == 3)
420 {
421 int second_regno = pop_order[idx + 1];
422 int third_regno = pop_order[idx + 2];
423 int fourth_regno = pop_order[idx + 3];
424
425 if (fourth_regno >= 0
426 && WORD_REG_USED (fourth_regno)
427 && (!frame_pointer_needed
428 || fourth_regno != FRAME_POINTER_REGNUM)
429 && third_regno >= 0
430 && WORD_REG_USED (third_regno)
431 && (!frame_pointer_needed
432 || third_regno != FRAME_POINTER_REGNUM)
433 && second_regno >= 0
434 && WORD_REG_USED (second_regno)
435 && (!frame_pointer_needed
436 || second_regno != FRAME_POINTER_REGNUM))
437 {
438 fprintf (file, "\tldm.l @sp+,%s-%s\n",
439 h8_reg_names[fourth_regno],
440 h8_reg_names[regno]);
441 idx += 3;
442 continue;
443 }
444 }
445 if (regno == 6 || regno == 2)
446 {
447 int second_regno = pop_order[idx + 1];
448 int third_regno = pop_order[idx + 2];
449
450 if (third_regno >= 0
451 && WORD_REG_USED (third_regno)
452 && (!frame_pointer_needed
453 || third_regno != FRAME_POINTER_REGNUM)
454 && second_regno >= 0
455 && WORD_REG_USED (second_regno)
456 && (!frame_pointer_needed
457 || second_regno != FRAME_POINTER_REGNUM))
458 {
459 fprintf (file, "\tldm.l @sp+,%s-%s\n",
460 h8_reg_names[third_regno],
461 h8_reg_names[regno]);
462 idx += 2;
463 continue;
464 }
465 }
466 if (regno == 7 || regno == 5 || regno == 3 || regno == 1)
467 {
468 int second_regno = pop_order[idx + 1];
469
470 if (second_regno >= 0
471 && WORD_REG_USED (second_regno)
472 && (!frame_pointer_needed
473 || second_regno != FRAME_POINTER_REGNUM))
474 {
475 fprintf (file, "\tldm.l @sp+,%s-%s\n",
476 h8_reg_names[second_regno],
477 h8_reg_names[regno]);
478 idx += 1;
479 continue;
480 }
481 }
482 }
483 fprintf (file, "\t%s\t%s\n", h8_pop_op, h8_reg_names[regno]);
484 }
485 }
486
487 /* deallocate locals */
488 dosize (file, "add", fsize);
489
490 /* pop frame pointer if we had one. */
491 if (frame_pointer_needed)
492 fprintf (file, "\t%s\t%s\n", h8_pop_op, h8_reg_names[FRAME_POINTER_REGNUM]);
493
494 /* If this is a monitor function, there is one register still left on
495 the stack. */
496 if (monitor)
497 fprintf (file, "\t%s\t%s\n", h8_pop_op, h8_reg_names[0]);
498
499 if (interrupt_handler)
500 fprintf (file, "\trte\n");
501 else
502 fprintf (file, "\trts\n");
503
504 out:
505 interrupt_handler = 0;
506 os_task = 0;
507 monitor = 0;
508 pragma_saveall = 0;
509 }
510
511 /* Output assembly code for the start of the file. */
512
513 void
514 asm_file_start (file)
515 FILE *file;
516 {
517 fprintf (file, ";\tGCC For the Hitachi H8/300\n");
518 fprintf (file, ";\tBy Hitachi America Ltd and Cygnus Support\n");
519 fprintf (file, ";\trelease F-1\n");
520 if (optimize)
521 fprintf (file, "; -O%d\n", optimize);
522 if (TARGET_H8300H)
523 fprintf (file, "\n\t.h8300h\n");
524 else if (TARGET_H8300S)
525 fprintf (file, "\n\t.h8300s\n");
526 else
527 fprintf (file, "\n\n");
528 output_file_directive (file, main_input_filename);
529 }
530
531 /* Output assembly language code for the end of file. */
532
533 void
534 asm_file_end (file)
535 FILE *file;
536 {
537 fprintf (file, "\t.end\n");
538 }
539 \f
540 /* Return true if VALUE is a valid constant for constraint 'P'.
541 IE: VALUE is a power of two <= 2**15. */
542
543 int
544 small_power_of_two (value)
545 int value;
546 {
547 switch (value)
548 {
549 case 1:
550 case 2:
551 case 4:
552 case 8:
553 case 16:
554 case 32:
555 case 64:
556 case 128:
557 case 256:
558 case 512:
559 case 1024:
560 case 2048:
561 case 4096:
562 case 8192:
563 case 16384:
564 case 32768:
565 return 1;
566 }
567 return 0;
568 }
569
570 /* Return true if VALUE is a valid constant for constraint 'O', which
571 means that the constant would be ok to use as a bit for a bclr
572 instruction. */
573
574 int
575 ok_for_bclr (value)
576 int value;
577 {
578 return small_power_of_two ((~value) & 0xff);
579 }
580
581 /* Return true is OP is a valid source operand for an integer move
582 instruction. */
583
584 int
585 general_operand_src (op, mode)
586 rtx op;
587 enum machine_mode mode;
588 {
589 if (GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) == POST_INC)
590 return 1;
591 return general_operand (op, mode);
592 }
593
594 /* Return true if OP is a valid destination operand for an integer move
595 instruction. */
596
597 int
598 general_operand_dst (op, mode)
599 rtx op;
600 enum machine_mode mode;
601 {
602 if (GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) == PRE_DEC)
603 return 1;
604 return general_operand (op, mode);
605 }
606
607 /* Return true if OP is a const valid for a bit clear instruction. */
608
609 int
610 o_operand (operand, mode)
611 rtx operand;
612 enum machine_mode mode ATTRIBUTE_UNUSED;
613 {
614 return (GET_CODE (operand) == CONST_INT
615 && CONST_OK_FOR_O (INTVAL (operand)));
616 }
617
618 /* Return true if OP is a const valid for a bit set or bit xor instruction. */
619
620 int
621 p_operand (operand, mode)
622 rtx operand;
623 enum machine_mode mode ATTRIBUTE_UNUSED;
624 {
625 return (GET_CODE (operand) == CONST_INT
626 && CONST_OK_FOR_P (INTVAL (operand)));
627 }
628
629 /* Return true if OP is a valid call operand. */
630
631 int
632 call_insn_operand (op, mode)
633 rtx op;
634 enum machine_mode mode ATTRIBUTE_UNUSED;
635 {
636 if (GET_CODE (op) == MEM)
637 {
638 rtx inside = XEXP (op, 0);
639 if (register_operand (inside, Pmode))
640 return 1;
641 if (CONSTANT_ADDRESS_P (inside))
642 return 1;
643 }
644 return 0;
645 }
646
647 int
648 adds_subs_operand (op, mode)
649 rtx op;
650 enum machine_mode mode ATTRIBUTE_UNUSED;
651 {
652 if (GET_CODE (op) == CONST_INT)
653 {
654 if (INTVAL (op) <= 4 && INTVAL (op) >= 0)
655 return 1;
656 if (INTVAL (op) >= -4 && INTVAL (op) <= 0)
657 return 1;
658 if ((TARGET_H8300H || TARGET_H8300S)
659 && INTVAL (op) != 7
660 && (INTVAL (op) <= 8 && INTVAL (op) >= 0))
661 return 1;
662 if ((TARGET_H8300H || TARGET_H8300S)
663 && INTVAL (op) != -7
664 && (INTVAL (op) >= -8 && INTVAL (op) <= 0))
665 return 1;
666 }
667 return 0;
668 }
669
670 /* Return nonzero if op is an adds/subs operand which only requires
671 one insn to implement. It is assumed that OP is already an adds/subs
672 operand. */
673 int
674 one_insn_adds_subs_operand (op, mode)
675 rtx op;
676 enum machine_mode mode ATTRIBUTE_UNUSED;
677 {
678 int val = INTVAL (op);
679
680 if (val == 1 || val == -1
681 || val == 2 || val == -2
682 || ((TARGET_H8300H || TARGET_H8300S)
683 && (val == 4 || val == -4)))
684 return 1;
685 return 0;
686 }
687
688 const char *
689 output_adds_subs (operands)
690 rtx *operands;
691 {
692 int val = INTVAL (operands[2]);
693
694 /* First get the value into the range -4..4 inclusive.
695
696 The only way it can be out of this range is when TARGET_H8300H
697 or TARGET_H8300S is true, thus it is safe to use adds #4 and subs #4. */
698 if (val > 4)
699 {
700 output_asm_insn ("adds #4,%A0", operands);
701 val -= 4;
702 }
703
704 if (val < -4)
705 {
706 output_asm_insn ("subs #4,%A0", operands);
707 val += 4;
708 }
709
710 /* Handle case were val == 4 or val == -4 and we're compiling
711 for TARGET_H8300H or TARGET_H8300S. */
712 if ((TARGET_H8300H || TARGET_H8300S)
713 && val == 4)
714 return "adds #4,%A0";
715
716 if ((TARGET_H8300H || TARGET_H8300S)
717 && val == -4)
718 return "subs #4,%A0";
719
720 if (val > 2)
721 {
722 output_asm_insn ("adds #2,%A0", operands);
723 val -= 2;
724 }
725
726 if (val < -2)
727 {
728 output_asm_insn ("subs #2,%A0", operands);
729 val += 2;
730 }
731
732 /* val should be one or two now. */
733 if (val == 2)
734 return "adds #2,%A0";
735
736 if (val == -2)
737 return "subs #2,%A0";
738
739 /* val should be one now. */
740 if (val == 1)
741 return "adds #1,%A0";
742
743 if (val == -1)
744 return "subs #1,%A0";
745
746 /* If not optimizing, we might be asked to add 0. */
747 if (val == 0)
748 return "";
749
750 /* In theory, this can't happen. */
751 abort ();
752 }
753
754 /* Return true if OP is a valid call operand, and OP represents
755 an operand for a small call (4 bytes instead of 6 bytes). */
756
757 int
758 small_call_insn_operand (op, mode)
759 rtx op;
760 enum machine_mode mode ATTRIBUTE_UNUSED;
761 {
762 if (GET_CODE (op) == MEM)
763 {
764 rtx inside = XEXP (op, 0);
765
766 /* Register indirect is a small call. */
767 if (register_operand (inside, Pmode))
768 return 1;
769
770 /* A call through the function vector is a small
771 call too. */
772 if (GET_CODE (inside) == SYMBOL_REF
773 && SYMBOL_REF_FLAG (inside))
774 return 1;
775 }
776 /* Otherwise it's a large call. */
777 return 0;
778 }
779
780 /* Return true if OP is a valid jump operand. */
781
782 int
783 jump_address_operand (op, mode)
784 rtx op;
785 enum machine_mode mode;
786 {
787 if (GET_CODE (op) == REG)
788 return mode == Pmode;
789
790 if (GET_CODE (op) == MEM)
791 {
792 rtx inside = XEXP (op, 0);
793 if (register_operand (inside, Pmode))
794 return 1;
795 if (CONSTANT_ADDRESS_P (inside))
796 return 1;
797 }
798 return 0;
799 }
800
801 /* Recognize valid operands for bitfield instructions. */
802
803 extern int rtx_equal_function_value_matters;
804
805 int
806 bit_operand (op, mode)
807 rtx op;
808 enum machine_mode mode;
809 {
810 /* We can except any general operand, expept that MEM operands must
811 be limited to those that use addresses valid for the 'U' constraint. */
812 if (!general_operand (op, mode))
813 return 0;
814
815 /* Accept any mem during RTL generation. Otherwise, the code that does
816 insv and extzv will think that we can not handle memory. However,
817 to avoid reload problems, we only accept 'U' MEM operands after RTL
818 generation. This means that any named pattern which uses this predicate
819 must force its operands to match 'U' before emitting RTL. */
820
821 if (GET_CODE (op) == REG)
822 return 1;
823 if (GET_CODE (op) == SUBREG)
824 return 1;
825 if (!rtx_equal_function_value_matters)
826 {
827 /* We're building rtl */
828 return GET_CODE (op) == MEM;
829 }
830 else
831 {
832 return (GET_CODE (op) == MEM
833 && EXTRA_CONSTRAINT (op, 'U'));
834 }
835 }
836
837 int
838 bit_memory_operand (op, mode)
839 rtx op;
840 enum machine_mode mode ATTRIBUTE_UNUSED;
841 {
842 return (GET_CODE (op) == MEM
843 && EXTRA_CONSTRAINT (op, 'U'));
844 }
845
846 /* Recognize valid operators for bit test. */
847
848 int
849 eq_operator (x, mode)
850 rtx x;
851 enum machine_mode mode ATTRIBUTE_UNUSED;
852 {
853 return (GET_CODE (x) == EQ || GET_CODE (x) == NE);
854 }
855
856 /* Handle machine specific pragmas for compatibility with existing
857 compilers for the H8/300.
858
859 pragma saveall generates prolog/epilog code which saves and
860 restores all the registers on function entry.
861
862 pragma interrupt saves and restores all registers, and exits with
863 an rte instruction rather than an rts. A pointer to a function
864 with this attribute may be safely used in an interrupt vector. */
865
866 int
867 handle_pragma (p_getc, p_ungetc, pname)
868 int (* ATTRIBUTE_UNUSED p_getc) PARAMS ((void));
869 void (* ATTRIBUTE_UNUSED p_ungetc) PARAMS ((int));
870 const char *pname;
871 {
872 int retval = 0;
873
874 if (strcmp (pname, "interrupt") == 0)
875 interrupt_handler = retval = 1;
876 else if (strcmp (pname, "saveall") == 0)
877 pragma_saveall = retval = 1;
878
879 return retval;
880 }
881 \f
882 /* If the next arg with MODE and TYPE is to be passed in a register, return
883 the rtx to represent where it is passed. CUM represents the state after
884 the last argument. NAMED is not used. */
885
886 static const char *const hand_list[] =
887 {
888 "__main",
889 "__cmpsi2",
890 "__divhi3",
891 "__modhi3",
892 "__udivhi3",
893 "__umodhi3",
894 "__divsi3",
895 "__modsi3",
896 "__udivsi3",
897 "__umodsi3",
898 "__mulhi3",
899 "__mulsi3",
900 "__reg_memcpy",
901 "__reg_memset",
902 "__ucmpsi2",
903 0,
904 };
905
906 /* Return an RTX to represent where a value with mode MODE will be returned
907 from a function. If the result is 0, the argument is pushed. */
908
909 rtx
910 function_arg (cum, mode, type, named)
911 CUMULATIVE_ARGS *cum;
912 enum machine_mode mode;
913 tree type;
914 int named;
915 {
916 rtx result = 0;
917 const char *fname;
918 int regpass = 0;
919
920 /* Never pass unnamed arguments in registers. */
921 if (!named)
922 return 0;
923
924 /* Pass 3 regs worth of data in regs when user asked on the command line. */
925 if (TARGET_QUICKCALL)
926 regpass = 3;
927
928 /* If calling hand written assembler, use 4 regs of args. */
929
930 if (cum->libcall)
931 {
932 const char * const *p;
933
934 fname = XSTR (cum->libcall, 0);
935
936 /* See if this libcall is one of the hand coded ones. */
937
938 for (p = hand_list; *p && strcmp (*p, fname) != 0; p++)
939 ;
940
941 if (*p)
942 regpass = 4;
943 }
944
945 if (regpass)
946 {
947 int size;
948
949 if (mode == BLKmode)
950 size = int_size_in_bytes (type);
951 else
952 size = GET_MODE_SIZE (mode);
953
954 if (size + cum->nbytes > regpass * UNITS_PER_WORD)
955 {
956 result = 0;
957 }
958 else
959 {
960 switch (cum->nbytes / UNITS_PER_WORD)
961 {
962 case 0:
963 result = gen_rtx_REG (mode, 0);
964 break;
965 case 1:
966 result = gen_rtx_REG (mode, 1);
967 break;
968 case 2:
969 result = gen_rtx_REG (mode, 2);
970 break;
971 case 3:
972 result = gen_rtx_REG (mode, 3);
973 break;
974 default:
975 result = 0;
976 }
977 }
978 }
979
980 return result;
981 }
982 \f
983 /* Return the cost of the rtx R with code CODE. */
984
985 int
986 const_costs (r, c)
987 rtx r;
988 enum rtx_code c;
989 {
990 switch (c)
991 {
992 case CONST_INT:
993 switch (INTVAL (r))
994 {
995 case 0:
996 case 1:
997 case 2:
998 case -1:
999 case -2:
1000 return 0;
1001 case 4:
1002 case -4:
1003 if (TARGET_H8300H || TARGET_H8300S)
1004 return 0;
1005 else
1006 return 1;
1007 default:
1008 return 1;
1009 }
1010
1011 case CONST:
1012 case LABEL_REF:
1013 case SYMBOL_REF:
1014 return 3;
1015
1016 case CONST_DOUBLE:
1017 return 20;
1018
1019 default:
1020 return 4;
1021 }
1022 }
1023 \f
1024 /* Documentation for the machine specific operand escapes:
1025
1026 'A' print rn in h8/300 mode, erN in H8/300H mode
1027 'C' print (operand - 2).
1028 'E' like s but negative.
1029 'F' like t but negative.
1030 'G' constant just the negative
1031 'M' turn a 'M' constant into its negative mod 2.
1032 'P' if operand is incing/decing sp, print .w, otherwise .b.
1033 'R' print operand as a byte:8 address if appropriate, else fall back to
1034 'X' handling.
1035 'S' print operand as a long word
1036 'T' print operand as a word
1037 'U' if operand is incing/decing sp, print l, otherwise nothing.
1038 'V' find the set bit, and print its number.
1039 'W' find the clear bit, and print its number.
1040 'X' print operand as a byte
1041 'Y' print either l or h depending on whether last 'Z' operand < 8 or >= 8.
1042 If this operand isn't a register, fall back to 'R' handling.
1043 'Z' print int & 7.
1044 'b' print the bit opcode
1045 'c' print the ibit opcode
1046 'd' bcc if EQ, bcs if NE
1047 'e' first word of 32 bit value - if reg, then least reg. if mem
1048 then least. if const then most sig word
1049 'f' second word of 32 bit value - if reg, then biggest reg. if mem
1050 then +2. if const then least sig word
1051 'g' bcs if EQ, bcc if NE
1052 'j' print operand as condition code.
1053 'k' print operand as reverse condition code.
1054 's' print as low byte of 16 bit value
1055 't' print as high byte of 16 bit value
1056 'w' print as low byte of 32 bit value
1057 'x' print as 2nd byte of 32 bit value
1058 'y' print as 3rd byte of 32 bit value
1059 'z' print as msb of 32 bit value
1060 */
1061
1062 /* Return assembly language string which identifies a comparison type. */
1063
1064 static const char *
1065 cond_string (code)
1066 enum rtx_code code;
1067 {
1068 switch (code)
1069 {
1070 case NE:
1071 return "ne";
1072 case EQ:
1073 return "eq";
1074 case GE:
1075 return "ge";
1076 case GT:
1077 return "gt";
1078 case LE:
1079 return "le";
1080 case LT:
1081 return "lt";
1082 case GEU:
1083 return "hs";
1084 case GTU:
1085 return "hi";
1086 case LEU:
1087 return "ls";
1088 case LTU:
1089 return "lo";
1090 default:
1091 abort ();
1092 }
1093 }
1094
1095 /* Print operand X using operand code CODE to assembly language output file
1096 FILE. */
1097
1098 void
1099 print_operand (file, x, code)
1100 FILE *file;
1101 rtx x;
1102 int code;
1103 {
1104 /* This is used for communication between the 'P' and 'U' codes. */
1105 static const char *last_p;
1106
1107 /* This is used for communication between codes V,W,Z and Y. */
1108 static int bitint;
1109
1110 switch (code)
1111 {
1112 case 'A':
1113 if (GET_CODE (x) == REG)
1114 fprintf (file, "%s", h8_reg_names[REGNO (x)]);
1115 else
1116 goto def;
1117 break;
1118 case 'C':
1119 fprintf (file, "#%d", INTVAL (x) - 2);
1120 break;
1121 case 'E':
1122 switch (GET_CODE (x))
1123 {
1124 case REG:
1125 fprintf (file, "%sl", names_big[REGNO (x)]);
1126 break;
1127 case CONST_INT:
1128 fprintf (file, "#%d", (-INTVAL (x)) & 0xff);
1129 break;
1130 default:
1131 abort ();
1132 }
1133 break;
1134 case 'F':
1135 switch (GET_CODE (x))
1136 {
1137 case REG:
1138 fprintf (file, "%sh", names_big[REGNO (x)]);
1139 break;
1140 case CONST_INT:
1141 fprintf (file, "#%d", ((-INTVAL (x)) & 0xff00) >> 8);
1142 break;
1143 default:
1144 abort ();
1145 }
1146 break;
1147 case 'G':
1148 if (GET_CODE (x) != CONST_INT)
1149 abort ();
1150 fprintf (file, "#%d", 0xff & (-INTVAL (x)));
1151 break;
1152 case 'M':
1153 /* For 3/-3 and 4/-4, the other 2 is handled separately. */
1154 switch (INTVAL (x))
1155 {
1156 case 2:
1157 case 4:
1158 case -2:
1159 case -4:
1160 fprintf (file, "#2");
1161 break;
1162 case 1:
1163 case 3:
1164 case -1:
1165 case -3:
1166 fprintf (file, "#1");
1167 break;
1168 default:
1169 abort ();
1170 }
1171 break;
1172 case 'P':
1173 if (REGNO (XEXP (XEXP (x, 0), 0)) == STACK_POINTER_REGNUM)
1174 {
1175 last_p = "";
1176 fprintf (file, ".w");
1177 }
1178 else
1179 {
1180 last_p = "l";
1181 fprintf (file, ".b");
1182 }
1183 break;
1184 case 'S':
1185 if (GET_CODE (x) == REG)
1186 fprintf (file, "%s", names_extended[REGNO (x)]);
1187 else
1188 goto def;
1189 break;
1190 case 'T':
1191 if (GET_CODE (x) == REG)
1192 fprintf (file, "%s", names_big[REGNO (x)]);
1193 else
1194 goto def;
1195 break;
1196 case 'U':
1197 fprintf (file, "%s%s", names_big[REGNO (x)], last_p);
1198 break;
1199 case 'V':
1200 bitint = exact_log2 (INTVAL (x));
1201 if (bitint == -1)
1202 abort ();
1203 fprintf (file, "#%d", bitint & 7);
1204 break;
1205 case 'W':
1206 bitint = exact_log2 ((~INTVAL (x)) & 0xff);
1207 if (bitint == -1)
1208 abort ();
1209 fprintf (file, "#%d", bitint & 7);
1210 break;
1211 case 'R':
1212 case 'X':
1213 if (GET_CODE (x) == REG)
1214 fprintf (file, "%s", byte_reg (x, 0));
1215 else
1216 goto def;
1217 break;
1218 case 'Y':
1219 if (bitint == -1)
1220 abort ();
1221 if (GET_CODE (x) == REG)
1222 fprintf (file, "%s%c", names_big[REGNO (x)], bitint > 7 ? 'h' : 'l');
1223 else
1224 print_operand (file, x, 'R');
1225 bitint = -1;
1226 break;
1227 case 'Z':
1228 bitint = INTVAL (x);
1229 fprintf (file, "#%d", bitint & 7);
1230 break;
1231 case 'b':
1232 switch (GET_CODE (x))
1233 {
1234 case IOR:
1235 fprintf (file, "bor");
1236 break;
1237 case XOR:
1238 fprintf (file, "bxor");
1239 break;
1240 case AND:
1241 fprintf (file, "band");
1242 break;
1243 default:
1244 break;
1245 }
1246 break;
1247 case 'c':
1248 switch (GET_CODE (x))
1249 {
1250 case IOR:
1251 fprintf (file, "bior");
1252 break;
1253 case XOR:
1254 fprintf (file, "bixor");
1255 break;
1256 case AND:
1257 fprintf (file, "biand");
1258 break;
1259 default:
1260 break;
1261 }
1262 break;
1263 case 'd':
1264 switch (GET_CODE (x))
1265 {
1266 case EQ:
1267 fprintf (file, "bcc");
1268 break;
1269 case NE:
1270 fprintf (file, "bcs");
1271 break;
1272 default:
1273 abort ();
1274 }
1275 break;
1276 case 'e':
1277 switch (GET_CODE (x))
1278 {
1279 case REG:
1280 if (TARGET_H8300)
1281 fprintf (file, "%s", names_big[REGNO (x)]);
1282 else
1283 fprintf (file, "%s", names_upper_extended[REGNO (x)]);
1284 break;
1285 case MEM:
1286 x = adj_offsettable_operand (x, 0);
1287 print_operand (file, x, 0);
1288 break;
1289 case CONST_INT:
1290 fprintf (file, "#%d", ((INTVAL (x) >> 16) & 0xffff));
1291 break;
1292 case CONST_DOUBLE:
1293 {
1294 long val;
1295 REAL_VALUE_TYPE rv;
1296 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
1297 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
1298 fprintf (file, "#%ld", ((val >> 16) & 0xffff));
1299 break;
1300 }
1301 default:
1302 abort ();
1303 break;
1304 }
1305 break;
1306 case 'f':
1307 switch (GET_CODE (x))
1308 {
1309 case REG:
1310 if (TARGET_H8300)
1311 fprintf (file, "%s", names_big[REGNO (x) + 1]);
1312 else
1313 fprintf (file, "%s", names_big[REGNO (x)]);
1314 break;
1315 case MEM:
1316 x = adj_offsettable_operand (x, 2);
1317 print_operand (file, x, 0);
1318 break;
1319 case CONST_INT:
1320 fprintf (file, "#%d", INTVAL (x) & 0xffff);
1321 break;
1322 case CONST_DOUBLE:
1323 {
1324 long val;
1325 REAL_VALUE_TYPE rv;
1326 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
1327 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
1328 fprintf (file, "#%ld", (val & 0xffff));
1329 break;
1330 }
1331 default:
1332 abort ();
1333 }
1334 break;
1335 case 'g':
1336 switch (GET_CODE (x))
1337 {
1338 case NE:
1339 fprintf (file, "bcc");
1340 break;
1341 case EQ:
1342 fprintf (file, "bcs");
1343 break;
1344 default:
1345 abort ();
1346 }
1347 break;
1348 case 'j':
1349 asm_fprintf (file, cond_string (GET_CODE (x)));
1350 break;
1351 case 'k':
1352 asm_fprintf (file, cond_string (reverse_condition (GET_CODE (x))));
1353 break;
1354 case 's':
1355 if (GET_CODE (x) == CONST_INT)
1356 fprintf (file, "#%d", (INTVAL (x)) & 0xff);
1357 else
1358 fprintf (file, "%s", byte_reg (x, 0));
1359 break;
1360 case 't':
1361 if (GET_CODE (x) == CONST_INT)
1362 fprintf (file, "#%d", (INTVAL (x) >> 8) & 0xff);
1363 else
1364 fprintf (file, "%s", byte_reg (x, 1));
1365 break;
1366 case 'u':
1367 if (GET_CODE (x) != CONST_INT)
1368 abort ();
1369 fprintf (file, "%d", INTVAL (x));
1370 break;
1371 case 'w':
1372 if (GET_CODE (x) == CONST_INT)
1373 fprintf (file, "#%d", INTVAL (x) & 0xff);
1374 else
1375 fprintf (file, "%s",
1376 byte_reg (x, TARGET_H8300 ? 2 : 0));
1377 break;
1378 case 'x':
1379 if (GET_CODE (x) == CONST_INT)
1380 fprintf (file, "#%d", (INTVAL (x) >> 8) & 0xff);
1381 else
1382 fprintf (file, "%s",
1383 byte_reg (x, TARGET_H8300 ? 3 : 1));
1384 break;
1385 case 'y':
1386 if (GET_CODE (x) == CONST_INT)
1387 fprintf (file, "#%d", (INTVAL (x) >> 16) & 0xff);
1388 else
1389 fprintf (file, "%s", byte_reg (x, 0));
1390 break;
1391 case 'z':
1392 if (GET_CODE (x) == CONST_INT)
1393 fprintf (file, "#%d", (INTVAL (x) >> 24) & 0xff);
1394 else
1395 fprintf (file, "%s", byte_reg (x, 1));
1396 break;
1397
1398 default:
1399 def:
1400 switch (GET_CODE (x))
1401 {
1402 case REG:
1403 switch (GET_MODE (x))
1404 {
1405 case QImode:
1406 #if 0 /* Is it asm ("mov.b %0,r2l", ...) */
1407 fprintf (file, "%s", byte_reg (x, 0));
1408 #else /* ... or is it asm ("mov.b %0l,r2l", ...) */
1409 fprintf (file, "%s", names_big[REGNO (x)]);
1410 #endif
1411 break;
1412 case HImode:
1413 fprintf (file, "%s", names_big[REGNO (x)]);
1414 break;
1415 case SImode:
1416 case SFmode:
1417 fprintf (file, "%s", names_extended[REGNO (x)]);
1418 break;
1419 default:
1420 abort ();
1421 }
1422 break;
1423
1424 case MEM:
1425 fprintf (file, "@");
1426 output_address (XEXP (x, 0));
1427
1428 /* If this is an 'R' operand (reference into the 8-bit
1429 area), then specify a symbolic address as "foo:8",
1430 otherwise if operand is still in eight bit section, use
1431 "foo:16". */
1432 if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1433 && SYMBOL_REF_FLAG (XEXP (x, 0)))
1434 fprintf (file, (code == 'R' ? ":8" : ":16"));
1435 else if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1436 && TINY_DATA_NAME_P (XSTR (XEXP (x, 0), 0)))
1437 fprintf (file, ":16");
1438 break;
1439
1440 case CONST_INT:
1441 case SYMBOL_REF:
1442 case CONST:
1443 case LABEL_REF:
1444 fprintf (file, "#");
1445 print_operand_address (file, x);
1446 break;
1447 case CONST_DOUBLE:
1448 {
1449 long val;
1450 REAL_VALUE_TYPE rv;
1451 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
1452 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
1453 fprintf (file, "#%ld", val);
1454 break;
1455 }
1456 default:
1457 break;
1458 }
1459 }
1460 }
1461
1462 /* Output assembly language output for the address ADDR to FILE. */
1463
1464 void
1465 print_operand_address (file, addr)
1466 FILE *file;
1467 rtx addr;
1468 {
1469 switch (GET_CODE (addr))
1470 {
1471 case REG:
1472 fprintf (file, "%s", h8_reg_names[REGNO (addr)]);
1473 break;
1474
1475 case PRE_DEC:
1476 fprintf (file, "-%s", h8_reg_names[REGNO (XEXP (addr, 0))]);
1477 break;
1478
1479 case POST_INC:
1480 fprintf (file, "%s+", h8_reg_names[REGNO (XEXP (addr, 0))]);
1481 break;
1482
1483 case PLUS:
1484 fprintf (file, "(");
1485 if (GET_CODE (XEXP (addr, 0)) == REG)
1486 {
1487 /* reg,foo */
1488 print_operand_address (file, XEXP (addr, 1));
1489 fprintf (file, ",");
1490 print_operand_address (file, XEXP (addr, 0));
1491 }
1492 else
1493 {
1494 /* foo+k */
1495 print_operand_address (file, XEXP (addr, 0));
1496 fprintf (file, "+");
1497 print_operand_address (file, XEXP (addr, 1));
1498 }
1499 fprintf (file, ")");
1500 break;
1501
1502 case CONST_INT:
1503 {
1504 /* Since the h8/300 only has 16 bit pointers, negative values are also
1505 those >= 32768. This happens for example with pointer minus a
1506 constant. We don't want to turn (char *p - 2) into
1507 (char *p + 65534) because loop unrolling can build upon this
1508 (IE: char *p + 131068). */
1509 int n = INTVAL (addr);
1510 if (TARGET_H8300)
1511 n = (int) (short) n;
1512 if (n < 0)
1513 /* ??? Why the special case for -ve values? */
1514 fprintf (file, "-%d", -n);
1515 else
1516 fprintf (file, "%d", n);
1517 break;
1518 }
1519
1520 default:
1521 output_addr_const (file, addr);
1522 break;
1523 }
1524 }
1525 \f
1526 /* Output all insn addresses and their sizes into the assembly language
1527 output file. This is helpful for debugging whether the length attributes
1528 in the md file are correct. This is not meant to be a user selectable
1529 option. */
1530
1531 void
1532 final_prescan_insn (insn, operand, num_operands)
1533 rtx insn, *operand ATTRIBUTE_UNUSED;
1534 int num_operands ATTRIBUTE_UNUSED;
1535 {
1536 /* This holds the last insn address. */
1537 static int last_insn_address = 0;
1538
1539 int uid = INSN_UID (insn);
1540
1541 if (TARGET_RTL_DUMP)
1542 {
1543 fprintf (asm_out_file, "\n****************");
1544 print_rtl (asm_out_file, PATTERN (insn));
1545 fprintf (asm_out_file, "\n");
1546 }
1547
1548 if (TARGET_ADDRESSES)
1549 {
1550 fprintf (asm_out_file, "; 0x%x %d\n", insn_addresses[uid],
1551 insn_addresses[uid] - last_insn_address);
1552 last_insn_address = insn_addresses[uid];
1553 }
1554 }
1555
1556 /* Prepare for an SI sized move. */
1557
1558 int
1559 do_movsi (operands)
1560 rtx operands[];
1561 {
1562 rtx src = operands[1];
1563 rtx dst = operands[0];
1564 if (!reload_in_progress && !reload_completed)
1565 {
1566 if (!register_operand (dst, GET_MODE (dst)))
1567 {
1568 rtx tmp = gen_reg_rtx (GET_MODE (dst));
1569 emit_move_insn (tmp, src);
1570 operands[1] = tmp;
1571 }
1572 }
1573 return 0;
1574 }
1575
1576 /* Function for INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET).
1577 Define the offset between two registers, one to be eliminated, and the other
1578 its replacement, at the start of a routine. */
1579
1580 int
1581 initial_offset (from, to)
1582 int from, to;
1583 {
1584 int offset = 0;
1585
1586 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
1587 offset = UNITS_PER_WORD + frame_pointer_needed * UNITS_PER_WORD;
1588 else
1589 {
1590 int regno;
1591
1592 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1593 if (WORD_REG_USED (regno))
1594 offset += UNITS_PER_WORD;
1595
1596 /* See the comments for get_frame_size. We need to round it up to
1597 STACK_BOUNDARY. */
1598
1599 offset += ((get_frame_size () + STACK_BOUNDARY / BITS_PER_UNIT - 1)
1600 & ~(STACK_BOUNDARY / BITS_PER_UNIT - 1));
1601
1602 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
1603 offset += UNITS_PER_WORD; /* Skip saved PC */
1604 }
1605 return offset;
1606 }
1607
1608 /* Update the condition code from the insn. */
1609
1610 void
1611 notice_update_cc (body, insn)
1612 rtx body;
1613 rtx insn;
1614 {
1615 switch (get_attr_cc (insn))
1616 {
1617 case CC_NONE:
1618 /* Insn does not affect CC at all. */
1619 break;
1620
1621 case CC_NONE_0HIT:
1622 /* Insn does not change CC, but the 0'th operand has been changed. */
1623 if (cc_status.value1 != 0
1624 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
1625 cc_status.value1 = 0;
1626 break;
1627
1628 case CC_SET_ZN:
1629 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1630 The V flag is unusable. The C flag may or may not be known but
1631 that's ok because alter_cond will change tests to use EQ/NE. */
1632 CC_STATUS_INIT;
1633 cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
1634 cc_status.value1 = recog_data.operand[0];
1635 break;
1636
1637 case CC_SET_ZNV:
1638 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
1639 The C flag may or may not be known but that's ok because
1640 alter_cond will change tests to use EQ/NE. */
1641 CC_STATUS_INIT;
1642 cc_status.flags |= CC_NO_CARRY;
1643 cc_status.value1 = recog_data.operand[0];
1644 break;
1645
1646 case CC_COMPARE:
1647 /* The insn is a compare instruction. */
1648 CC_STATUS_INIT;
1649 cc_status.value1 = SET_SRC (body);
1650 break;
1651
1652 case CC_CLOBBER:
1653 /* Insn doesn't leave CC in a usable state. */
1654 CC_STATUS_INIT;
1655 break;
1656 }
1657 }
1658
1659 /* Recognize valid operators for bit instructions */
1660
1661 int
1662 bit_operator (x, mode)
1663 rtx x;
1664 enum machine_mode mode ATTRIBUTE_UNUSED;
1665 {
1666 enum rtx_code code = GET_CODE (x);
1667
1668 return (code == XOR
1669 || code == AND
1670 || code == IOR);
1671 }
1672 \f
1673 /* Shifts.
1674
1675 We devote a fair bit of code to getting efficient shifts since we can only
1676 shift one bit at a time on the H8/300 and H8/300H and only one or two
1677 bits at a time on the H8/S.
1678
1679 The basic shift methods:
1680
1681 * loop shifts -- emit a loop using one (or two on H8/S) bit shifts;
1682 this is the default. SHIFT_LOOP
1683
1684 * inlined shifts -- emit straight line code for the shift; this is
1685 used when a straight line shift is about the same size or smaller
1686 than a loop. We allow the inline version to be slightly longer in
1687 some cases as it saves a register. SHIFT_INLINE
1688
1689 * rotate + and -- rotate the value the opposite direction, then
1690 mask off the values we don't need. This is used when only a few
1691 of the bits in the original value will survive in the shifted value.
1692 Again, this is used when it's about the same size or smaller than
1693 a loop. We allow this version to be slightly longer as it is usually
1694 much faster than a loop. SHIFT_ROT_AND
1695
1696 * swap (+ shifts) -- often it's possible to swap bytes/words to
1697 simulate a shift by 8/16. Once swapped a few inline shifts can be
1698 added if the shift count is slightly more than 8 or 16. This is used
1699 when it's about the same size or smaller than a loop. We allow this
1700 version to be slightly longer as it is usually much faster than a loop.
1701 SHIFT_SPECIAL
1702
1703 * There other oddballs. Not worth explaining. SHIFT_SPECIAL
1704
1705
1706 Here are some thoughts on what the absolutely positively best code is.
1707 "Best" here means some rational trade-off between code size and speed,
1708 where speed is more preferred but not at the expense of generating 20 insns.
1709
1710 A trailing '*' after the shift count indicates the "best" mode isn't
1711 implemented.
1712
1713 H8/300 QImode shifts
1714 1-4 - do them inline
1715 5-6 - ASHIFT | LSHIFTRT: rotate, mask off other bits
1716 ASHIFTRT: loop
1717 7 - ASHIFT | LSHIFTRT: rotate, mask off other bits
1718 ASHIFTRT: shll, subx (propagate carry bit to all bits)
1719
1720 H8/300 HImode shifts
1721 1-4 - do them inline
1722 5-6 - loop
1723 7 - shift 2nd half other way into carry.
1724 copy 1st half into 2nd half
1725 rotate 2nd half other way with carry
1726 rotate 1st half other way (no carry)
1727 mask off bits in 1st half (ASHIFT | LSHIFTRT).
1728 sign extend 1st half (ASHIFTRT)
1729 8 - move byte, zero (ASHIFT | LSHIFTRT) or sign extend other (ASHIFTRT)
1730 9-12 - do shift by 8, inline remaining shifts
1731 13-14* - ASHIFT | LSHIFTRT: rotate 3/2, mask, move byte, set other byte to 0
1732 - ASHIFTRT: loop
1733 15 - ASHIFT | LSHIFTRT: rotate 1, mask, move byte, set other byte to 0
1734 - ASHIFTRT: shll, subx, set other byte
1735
1736 H8/300 SImode shifts
1737 1-2 - do them inline
1738 3-6 - loop
1739 7* - shift other way once, move bytes into place,
1740 move carry into place (possibly with sign extension)
1741 8 - move bytes into place, zero or sign extend other
1742 9-14 - loop
1743 15* - shift other way once, move word into place, move carry into place
1744 16 - move word, zero or sign extend other
1745 17-23 - loop
1746 24* - move bytes into place, zero or sign extend other
1747 25-27 - loop
1748 28-30* - ASHIFT | LSHIFTRT: rotate top byte, mask, move byte into place,
1749 zero others
1750 ASHIFTRT: loop
1751 31 - ASHIFT | LSHIFTRT: rotate top byte, mask, move byte into place,
1752 zero others
1753 ASHIFTRT: shll top byte, subx, copy to other bytes
1754
1755 H8/300H QImode shifts (same as H8/300 QImode shifts)
1756 1-4 - do them inline
1757 5-6 - ASHIFT | LSHIFTRT: rotate, mask off other bits
1758 ASHIFTRT: loop
1759 7 - ASHIFT | LSHIFTRT: rotate, mask off other bits
1760 ASHIFTRT: shll, subx (propagate carry bit to all bits)
1761
1762
1763 H8/300H HImode shifts
1764 1-4 - do them inline
1765 5-6 - loop
1766 7 - shift 2nd half other way into carry.
1767 copy 1st half into 2nd half
1768 rotate entire word other way using carry
1769 mask off remaining bits (ASHIFT | LSHIFTRT)
1770 sign extend remaining bits (ASHIFTRT)
1771 8 - move byte, zero (ASHIFT | LSHIFTRT) or sign extend other (ASHIFTRT)
1772 9-12 - do shift by 8, inline remaining shifts
1773 13-14 - ASHIFT | LSHIFTRT: rotate 3/2, mask, move byte, set other byte to 0
1774 - ASHIFTRT: loop
1775 15 - ASHIFT | LSHIFTRT: rotate 1, mask, move byte, set other byte to 0
1776 - ASHIFTRT: shll, subx, set other byte
1777
1778 H8/300H SImode shifts
1779 (These are complicated by the fact that we don't have byte level access to
1780 the top word.)
1781 A word is: bytes 3,2,1,0 (msb -> lsb), word 1,0 (msw -> lsw)
1782 1-4 - do them inline
1783 5-14 - loop
1784 15* - shift other way once, move word into place, move carry into place
1785 (with sign extension for ASHIFTRT)
1786 16 - move word into place, zero or sign extend other
1787 17-20 - do 16bit shift, then inline remaining shifts
1788 20-23 - loop
1789 24* - ASHIFT: move byte 0(msb) to byte 1, zero byte 0,
1790 move word 0 to word 1, zero word 0
1791 LSHIFTRT: move word 1 to word 0, move byte 1 to byte 0,
1792 zero word 1, zero byte 1
1793 ASHIFTRT: move word 1 to word 0, move byte 1 to byte 0,
1794 sign extend byte 0, sign extend word 0
1795 25-27* - either loop, or
1796 do 24 bit shift, inline rest
1797 28-30 - ASHIFT: rotate 4/3/2, mask
1798 LSHIFTRT: rotate 4/3/2, mask
1799 ASHIFTRT: loop
1800 31 - shll, subx byte 0, sign extend byte 0, sign extend word 0
1801
1802 H8/S QImode shifts
1803 1-6 - do them inline
1804 7 - ASHIFT | LSHIFTRT: rotate, mask off other bits
1805 ASHIFTRT: shll, subx (propagate carry bit to all bits)
1806
1807 H8/S HImode shifts
1808 1-7 - do them inline
1809 8 - move byte, zero (ASHIFT | LSHIFTRT) or sign extend other (ASHIFTRT)
1810 9-12 - do shift by 8, inline remaining shifts
1811 13-14 - ASHIFT | LSHIFTRT: rotate 3/2, mask, move byte, set other byte to 0
1812 - ASHIFTRT: loop
1813 15 - ASHIFT | LSHIFTRT: rotate 1, mask, move byte, set other byte to 0
1814 - ASHIFTRT: shll, subx, set other byte
1815
1816 H8/S SImode shifts
1817 (These are complicated by the fact that we don't have byte level access to
1818 the top word.)
1819 A word is: bytes 3,2,1,0 (msb -> lsb), word 1,0 (msw -> lsw)
1820 1-10 - do them inline
1821 11-14 - loop
1822 15* - shift other way once, move word into place, move carry into place
1823 (with sign extension for ASHIFTRT)
1824 16 - move word into place, zero or sign extend other
1825 17-20 - do 16bit shift, then inline remaining shifts
1826 20-23 - loop
1827 24* - ASHIFT: move byte 0(msb) to byte 1, zero byte 0,
1828 move word 0 to word 1, zero word 0
1829 LSHIFTRT: move word 1 to word 0, move byte 1 to byte 0,
1830 zero word 1, zero byte 1
1831 ASHIFTRT: move word 1 to word 0, move byte 1 to byte 0,
1832 sign extend byte 0, sign extend word 0
1833 25-27* - either loop, or
1834 do 24 bit shift, inline rest
1835 28-30 - ASHIFT: rotate 4/3/2, mask
1836 LSHIFTRT: rotate 4/3/2, mask
1837 ASHIFTRT: loop
1838 31 - shll, subx byte 0, sign extend byte 0, sign extend word 0
1839
1840 Panic!!! */
1841
1842 int
1843 nshift_operator (x, mode)
1844 rtx x;
1845 enum machine_mode mode ATTRIBUTE_UNUSED;
1846 {
1847 switch (GET_CODE (x))
1848 {
1849 case ASHIFTRT:
1850 case LSHIFTRT:
1851 case ASHIFT:
1852 return 1;
1853
1854 default:
1855 return 0;
1856 }
1857 }
1858
1859 /* Called from the .md file to emit code to do shifts.
1860 Returns a boolean indicating success
1861 (currently this is always TRUE). */
1862
1863 int
1864 expand_a_shift (mode, code, operands)
1865 enum machine_mode mode;
1866 int code;
1867 rtx operands[];
1868 {
1869 emit_move_insn (operands[0], operands[1]);
1870
1871 /* need a loop to get all the bits we want - we generate the
1872 code at emit time, but need to allocate a scratch reg now */
1873
1874 emit_insn (gen_rtx_PARALLEL
1875 (VOIDmode,
1876 gen_rtvec (2,
1877 gen_rtx_SET (VOIDmode, operands[0],
1878 gen_rtx (code, mode, operands[0],
1879 operands[2])),
1880 gen_rtx_CLOBBER (VOIDmode,
1881 gen_rtx_SCRATCH (QImode)))));
1882
1883 return 1;
1884 }
1885
1886 /* Shift algorithm determination.
1887
1888 There are various ways of doing a shift:
1889 SHIFT_INLINE: If the amount is small enough, just generate as many one-bit
1890 shifts as we need.
1891 SHIFT_ROT_AND: If the amount is large but close to either end, rotate the
1892 necessary bits into position and then set the rest to zero.
1893 SHIFT_SPECIAL: Hand crafted assembler.
1894 SHIFT_LOOP: If the above methods fail, just loop. */
1895
1896 enum shift_alg
1897 {
1898 SHIFT_INLINE,
1899 SHIFT_ROT_AND,
1900 SHIFT_SPECIAL,
1901 SHIFT_LOOP,
1902 SHIFT_MAX
1903 };
1904
1905 /* Symbols of the various shifts which can be used as indices. */
1906
1907 enum shift_type
1908 {
1909 SHIFT_ASHIFT, SHIFT_LSHIFTRT, SHIFT_ASHIFTRT
1910 };
1911
1912 /* Symbols of the various modes which can be used as indices. */
1913
1914 enum shift_mode
1915 {
1916 QIshift, HIshift, SIshift
1917 };
1918
1919 /* For single bit shift insns, record assembler and what bits of the
1920 condition code are valid afterwards (represented as various CC_FOO
1921 bits, 0 means CC isn't left in a usable state). */
1922
1923 struct shift_insn
1924 {
1925 const char *assembler;
1926 int cc_valid;
1927 };
1928
1929 /* Assembler instruction shift table.
1930
1931 These tables are used to look up the basic shifts.
1932 They are indexed by cpu, shift_type, and mode.
1933 */
1934
1935 static const struct shift_insn shift_one[2][3][3] =
1936 {
1937 /* H8/300 */
1938 {
1939 /* SHIFT_ASHIFT */
1940 {
1941 { "shll\t%X0", CC_NO_CARRY },
1942 { "add.w\t%T0,%T0", CC_OVERFLOW_UNUSABLE | CC_NO_CARRY },
1943 { "add.w\t%f0,%f0\n\taddx\t%y0,%y0\n\taddx\t%z0,%z0", 0 }
1944 },
1945 /* SHIFT_LSHIFTRT */
1946 {
1947 { "shlr\t%X0", CC_NO_CARRY },
1948 { "shlr\t%t0\n\trotxr\t%s0", 0 },
1949 { "shlr\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", 0 }
1950 },
1951 /* SHIFT_ASHIFTRT */
1952 {
1953 { "shar\t%X0", CC_OVERFLOW_UNUSABLE | CC_NO_CARRY },
1954 { "shar\t%t0\n\trotxr\t%s0", 0 },
1955 { "shar\t%z0\n\trotxr\t%y0\n\trotxr\t%x0\n\trotxr\t%w0", 0 }
1956 }
1957 },
1958 /* H8/300H */
1959 {
1960 /* SHIFT_ASHIFT */
1961 {
1962 { "shll.b\t%X0", CC_NO_CARRY },
1963 { "shll.w\t%T0", CC_NO_CARRY },
1964 { "shll.l\t%S0", CC_NO_CARRY }
1965 },
1966 /* SHIFT_LSHIFTRT */
1967 {
1968 { "shlr.b\t%X0", CC_NO_CARRY },
1969 { "shlr.w\t%T0", CC_NO_CARRY },
1970 { "shlr.l\t%S0", CC_NO_CARRY }
1971 },
1972 /* SHIFT_ASHIFTRT */
1973 {
1974 { "shar.b\t%X0", CC_OVERFLOW_UNUSABLE | CC_NO_CARRY },
1975 { "shar.w\t%T0", CC_OVERFLOW_UNUSABLE | CC_NO_CARRY },
1976 { "shar.l\t%S0", CC_OVERFLOW_UNUSABLE | CC_NO_CARRY }
1977 }
1978 }
1979 };
1980
1981 static const struct shift_insn shift_two[3][3] =
1982 {
1983 /* SHIFT_ASHIFT */
1984 {
1985 { "shll.b\t#2,%X0", CC_NO_CARRY },
1986 { "shll.w\t#2,%T0", CC_NO_CARRY },
1987 { "shll.l\t#2,%S0", CC_NO_CARRY }
1988 },
1989 /* SHIFT_LSHIFTRT */
1990 {
1991 { "shlr.b\t#2,%X0", CC_NO_CARRY },
1992 { "shlr.w\t#2,%T0", CC_NO_CARRY },
1993 { "shlr.l\t#2,%S0", CC_NO_CARRY }
1994 },
1995 /* SHIFT_ASHIFTRT */
1996 {
1997 { "shar.b\t#2,%X0", CC_OVERFLOW_UNUSABLE | CC_NO_CARRY },
1998 { "shar.w\t#2,%T0", CC_OVERFLOW_UNUSABLE | CC_NO_CARRY },
1999 { "shar.l\t#2,%S0", CC_OVERFLOW_UNUSABLE | CC_NO_CARRY }
2000 }
2001 };
2002
2003 /* Rotates are organized by which shift they'll be used in implementing.
2004 There's no need to record whether the cc is valid afterwards because
2005 it is the AND insn that will decide this. */
2006
2007 static const char *const rotate_one[2][3][3] =
2008 {
2009 /* H8/300 */
2010 {
2011 /* SHIFT_ASHIFT */
2012 {
2013 "rotr\t%X0",
2014 "shlr\t%t0\n\trotxr\t%s0\n\tbst\t#7,%t0",
2015 0
2016 },
2017 /* SHIFT_LSHIFTRT */
2018 {
2019 "rotl\t%X0",
2020 "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
2021 0
2022 },
2023 /* SHIFT_ASHIFTRT */
2024 {
2025 "rotl\t%X0",
2026 "shll\t%s0\n\trotxl\t%t0\n\tbst\t#0,%s0",
2027 0
2028 }
2029 },
2030 /* H8/300H */
2031 {
2032 /* SHIFT_ASHIFT */
2033 {
2034 "rotr.b\t%X0",
2035 "rotr.w\t%T0",
2036 "rotr.l\t%S0"
2037 },
2038 /* SHIFT_LSHIFTRT */
2039 {
2040 "rotl.b\t%X0",
2041 "rotl.w\t%T0",
2042 "rotl.l\t%S0"
2043 },
2044 /* SHIFT_ASHIFTRT */
2045 {
2046 "rotl.b\t%X0",
2047 "rotl.w\t%T0",
2048 "rotl.l\t%S0"
2049 }
2050 }
2051 };
2052
2053 static const char *const rotate_two[3][3] =
2054 {
2055 /* SHIFT_ASHIFT */
2056 {
2057 "rotr.b\t#2,%X0",
2058 "rotr.w\t#2,%T0",
2059 "rotr.l\t#2,%S0"
2060 },
2061 /* SHIFT_LSHIFTRT */
2062 {
2063 "rotl.b\t#2,%X0",
2064 "rotl.w\t#2,%T0",
2065 "rotl.l\t#2,%S0"
2066 },
2067 /* SHIFT_ASHIFTRT */
2068 {
2069 "rotl.b\t#2,%X0",
2070 "rotl.w\t#2,%T0",
2071 "rotl.l\t#2,%S0"
2072 }
2073 };
2074
2075 static enum shift_alg get_shift_alg PARAMS ((enum attr_cpu, enum shift_type,
2076 enum machine_mode, int,
2077 const char **, const char **,
2078 int *));
2079
2080 /* Given CPU, MODE, SHIFT_TYPE, and shift count COUNT, determine the best
2081 algorithm for doing the shift. The assembler code is stored in ASSEMBLER.
2082 We don't achieve maximum efficiency in all cases, but the hooks are here
2083 to do so.
2084
2085 For now we just use lots of switch statements. Since we don't even come
2086 close to supporting all the cases, this is simplest. If this function ever
2087 gets too big, perhaps resort to a more table based lookup. Of course,
2088 at this point you may just wish to do it all in rtl.
2089
2090 WARNING: The constraints on insns shiftbyn_QI/HI/SI assume shifts of
2091 1,2,3,4 will be inlined (1,2 for SI). */
2092
2093 static enum shift_alg
2094 get_shift_alg (cpu, shift_type, mode, count, assembler_p,
2095 assembler2_p, cc_valid_p)
2096 enum attr_cpu cpu;
2097 enum shift_type shift_type;
2098 enum machine_mode mode;
2099 int count;
2100 const char **assembler_p;
2101 const char **assembler2_p;
2102 int *cc_valid_p;
2103 {
2104 /* The default is to loop. */
2105 enum shift_alg alg = SHIFT_LOOP;
2106 enum shift_mode shift_mode;
2107
2108 /* We don't handle negative shifts or shifts greater than the word size,
2109 they should have been handled already. */
2110
2111 if (count < 0 || count > GET_MODE_BITSIZE (mode))
2112 abort ();
2113
2114 switch (mode)
2115 {
2116 case QImode:
2117 shift_mode = QIshift;
2118 break;
2119 case HImode:
2120 shift_mode = HIshift;
2121 break;
2122 case SImode:
2123 shift_mode = SIshift;
2124 break;
2125 default:
2126 abort ();
2127 }
2128
2129 /* Assume either SHIFT_LOOP or SHIFT_INLINE.
2130 It is up to the caller to know that looping clobbers cc. */
2131 *assembler_p = shift_one[cpu][shift_type][shift_mode].assembler;
2132 if (TARGET_H8300S)
2133 *assembler2_p = shift_two[shift_type][shift_mode].assembler;
2134 else
2135 *assembler2_p = NULL;
2136 *cc_valid_p = shift_one[cpu][shift_type][shift_mode].cc_valid;
2137
2138 /* Now look for cases we want to optimize. */
2139
2140 switch (shift_mode)
2141 {
2142 case QIshift:
2143 if (count <= 4)
2144 return SHIFT_INLINE;
2145 else
2146 {
2147 /* Shift by 5/6 are only 3 insns on the H8/S, so it's just as
2148 fast as SHIFT_ROT_AND, plus CC is valid. */
2149 if (TARGET_H8300S && count <= 6)
2150 return SHIFT_INLINE;
2151
2152 /* For ASHIFTRT by 7 bits, the sign bit is simply replicated
2153 through the entire value. */
2154 if (shift_type == SHIFT_ASHIFTRT && count == 7)
2155 {
2156 *assembler_p = "shll\t%X0\n\tsubx\t%X0,%X0";
2157 *cc_valid_p = 0;
2158 return SHIFT_SPECIAL;
2159 }
2160
2161 /* Other ASHIFTRTs are too much of a pain. */
2162 if (shift_type == SHIFT_ASHIFTRT)
2163 return SHIFT_LOOP;
2164
2165 /* Other shifts by 5, 6, or 7 bits use SHIFT_ROT_AND. */
2166 *assembler_p = rotate_one[cpu][shift_type][shift_mode];
2167 if (TARGET_H8300S)
2168 *assembler2_p = rotate_two[shift_type][shift_mode];
2169 *cc_valid_p = 0;
2170 return SHIFT_ROT_AND;
2171 }
2172
2173 case HIshift:
2174 if (count <= 4)
2175 return SHIFT_INLINE;
2176 else if (TARGET_H8300S && count <= 7)
2177 return SHIFT_INLINE;
2178 else if (count == 7)
2179 {
2180 if (shift_type == SHIFT_ASHIFT && TARGET_H8300)
2181 {
2182 *assembler_p = "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";
2183 *cc_valid_p = 0;
2184 return SHIFT_SPECIAL;
2185 }
2186
2187 if (shift_type == SHIFT_ASHIFT && TARGET_H8300H)
2188 {
2189 *assembler_p = "shar.b\t%t0\n\tmov.b\t%s0,%t0\n\trotxr.w\t%T0\n\tand.b\t#0x80,%s0";
2190 *cc_valid_p = 0;
2191 return SHIFT_SPECIAL;
2192 }
2193
2194 if (shift_type == SHIFT_LSHIFTRT && TARGET_H8300)
2195 {
2196 *assembler_p = "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";
2197 *cc_valid_p = 0;
2198 return SHIFT_SPECIAL;
2199 }
2200
2201 if (shift_type == SHIFT_LSHIFTRT && TARGET_H8300H)
2202 {
2203 *assembler_p = "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.w\t%T0\n\tand.b\t#0x01,%t0";
2204 *cc_valid_p = 0;
2205 return SHIFT_SPECIAL;
2206 }
2207
2208 if (shift_type == SHIFT_ASHIFTRT)
2209 {
2210 *assembler_p = "shal.b\t%s0\n\tmov.b\t%t0,%s0\n\trotxl.b\t%s0\n\tsubx\t%t0,%t0";
2211 *cc_valid_p = 0;
2212 return SHIFT_SPECIAL;
2213 }
2214 }
2215 else if (count == 8)
2216 {
2217 switch (shift_type)
2218 {
2219 case SHIFT_ASHIFT:
2220 *assembler_p = "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0";
2221 *cc_valid_p = 0;
2222 return SHIFT_SPECIAL;
2223 case SHIFT_LSHIFTRT:
2224 *assembler_p = "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0";
2225 *cc_valid_p = 0;
2226 return SHIFT_SPECIAL;
2227 case SHIFT_ASHIFTRT:
2228 if (TARGET_H8300)
2229 *assembler_p = "mov.b\t%t0,%s0\n\tshll\t%t0\n\tsubx\t%t0,%t0\t";
2230 else
2231 *assembler_p = "mov.b\t%t0,%s0\n\texts.w\t%T0";
2232 *cc_valid_p = 0;
2233 return SHIFT_SPECIAL;
2234 }
2235 }
2236 else if (count == 9)
2237 {
2238 switch (shift_type)
2239 {
2240 case SHIFT_ASHIFT:
2241 *assembler_p = "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0\n\tshal.b\t%t0";
2242 *cc_valid_p = 0;
2243 return SHIFT_SPECIAL;
2244 case SHIFT_LSHIFTRT:
2245 *assembler_p = "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0\n\tshlr.b\t%s0";
2246 *cc_valid_p = 0;
2247 return SHIFT_SPECIAL;
2248 case SHIFT_ASHIFTRT:
2249 if (TARGET_H8300)
2250 *assembler_p = "mov.b\t%t0,%s0\n\tbld\t#7,%s0\n\tsubx\t%t0,%t0\n\tshar.b\t%s0";
2251 else
2252 *assembler_p = "mov.b\t%t0,%s0\n\texts.w\t%T0\n\tshar.b\t%s0";
2253 *cc_valid_p = 0;
2254 return SHIFT_SPECIAL;
2255 }
2256 }
2257 else if (count == 10)
2258 {
2259 switch (shift_type)
2260 {
2261 case SHIFT_ASHIFT:
2262 if (TARGET_H8300S)
2263 *assembler_p = "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0\n\tshal.b\t#2,%t0\n\t";
2264 else
2265 *assembler_p = "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0\n\tshal.b\t%t0\n\tshal.b\t%t0";
2266 *cc_valid_p = 0;
2267 return SHIFT_SPECIAL;
2268 case SHIFT_LSHIFTRT:
2269 if (TARGET_H8300S)
2270 *assembler_p = "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0\n\tshlr.b\t#2,%s0";
2271 else
2272 *assembler_p = "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0\n\tshlr.b\t%s0\n\tshlr.b\t%s0";
2273 *cc_valid_p = 0;
2274 return SHIFT_SPECIAL;
2275 case SHIFT_ASHIFTRT:
2276 if (TARGET_H8300)
2277 *assembler_p = "mov.b\t%t0,%s0\n\tbld\t#7,%s0\n\tsubx\t%t0,%t0\n\tshar.b\t%s0\n\tshar.b\t%s0";
2278 else if (TARGET_H8300H)
2279 *assembler_p = "mov.b\t%t0,%s0\n\texts.w\t%T0\n\tshar.b\t%s0\n\tshar.b\t%s0";
2280 else if (TARGET_H8300S)
2281 *assembler_p = "mov.b\t%t0,%s0\n\texts.w\t%T0\n\tshar.b\t#2,%s0";
2282 *cc_valid_p = 0;
2283 return SHIFT_SPECIAL;
2284 }
2285 }
2286 else if (count == 11)
2287 {
2288 switch (shift_type)
2289 {
2290 case SHIFT_ASHIFT:
2291 if (TARGET_H8300S)
2292 *assembler_p = "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0\n\tshal.b\t#2,%t0\n\tshal.b\t%t0";
2293 else
2294 *assembler_p = "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0\n\tshal.b\t%t0\n\tshal.b\t%t0\n\tshal.b\t%t0";
2295 *cc_valid_p = 0;
2296 return SHIFT_SPECIAL;
2297 case SHIFT_LSHIFTRT:
2298 if (TARGET_H8300S)
2299 *assembler_p = "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0\n\tshlr.b\t#2,%s0\n\tshlr.b\t%s0";
2300 else
2301 *assembler_p = "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0\n\tshlr.b\t%s0\n\tshlr.b\t%s0\n\tshlr.b\t%s0";
2302 *cc_valid_p = 0;
2303 return SHIFT_SPECIAL;
2304 case SHIFT_ASHIFTRT:
2305 if (TARGET_H8300)
2306 *assembler_p = "mov.b\t%t0,%s0\n\tbld\t#7,%s0\n\tsubx\t%t0,%t0\n\tshar.b\t%s0\n\tshar.b\t%s0\n\tshar.b\t%s0";
2307 else if (TARGET_H8300H)
2308 *assembler_p = "mov.b\t%t0,%s0\n\texts.w\t%T0\n\tshar.b\t%s0\n\tshar.b\t%s0\n\tshar.b\t%s0";
2309 else if (TARGET_H8300S)
2310 *assembler_p = "mov.b\t%t0,%s0\n\texts.w\t%T0\n\tshar.b\t#2,%s0\n\tshar.b\t%s0";
2311 *cc_valid_p = 0;
2312 return SHIFT_SPECIAL;
2313 }
2314 }
2315 else if (count == 12)
2316 {
2317 switch (shift_type)
2318 {
2319 case SHIFT_ASHIFT:
2320 if (TARGET_H8300S)
2321 *assembler_p = "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0\n\tshal.b\t#2,%t0\n\tshal.b\t#2,%t0";
2322 else
2323 *assembler_p = "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0\n\tshal.b\t%t0\n\tshal.b\t%t0\n\tshal.b\t%t0\n\tshal.b\t%t0";
2324 *cc_valid_p = 0;
2325 return SHIFT_SPECIAL;
2326 case SHIFT_LSHIFTRT:
2327 if (TARGET_H8300S)
2328 *assembler_p = "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0\n\tshlr.b\t#2,%s0\n\tshlr.b\t#2,%s0";
2329 else
2330 *assembler_p = "mov.b\t%t0,%s0\n\tsub.b\t%t0,%t0\n\tshlr.b\t%s0\n\tshlr.b\t%s0\n\tshlr.b\t%s0\n\tshlr.b\t%s0";
2331 *cc_valid_p = 0;
2332 return SHIFT_SPECIAL;
2333 case SHIFT_ASHIFTRT:
2334 if (TARGET_H8300)
2335 *assembler_p = "mov.b\t%t0,%s0\n\tbld\t#7,%s0\n\tsubx\t%t0,%t0\n\tshar.b\t%s0\n\tshar.b\t%s0\n\tshar.b\t%s0\n\tshar.b\t%s0";
2336 else if (TARGET_H8300H)
2337 *assembler_p = "mov.b\t%t0,%s0\n\textw.w\t%T0\n\tshar.b\t%s0\n\tshar.b\t%s0\n\tshar.b\t%s0\n\tshar.b\t%s0";
2338 else if (TARGET_H8300S)
2339 *assembler_p = "mov.b\t%t0,%s0\n\textw.w\t%T0\n\tshar.b\t#2,%s0\n\tshar.b\t#2,%s0";
2340 *cc_valid_p = 0;
2341 return SHIFT_SPECIAL;
2342 }
2343 }
2344 else if ((!TARGET_H8300 && (count == 13 || count == 14))
2345 || count == 15)
2346 {
2347 if (count == 15 && shift_type == SHIFT_ASHIFTRT)
2348 {
2349 *assembler_p = "shll\t%t0,%t0\n\tsubx\t%t0,%t0\n\tmov.b\t%t0,%s0";
2350 *cc_valid_p = 0;
2351 return SHIFT_SPECIAL;
2352 }
2353 else if (shift_type != SHIFT_ASHIFTRT)
2354 {
2355 *assembler_p = rotate_one[cpu][shift_type][shift_mode];
2356 if (TARGET_H8300S)
2357 *assembler2_p = rotate_two[shift_type][shift_mode];
2358 else
2359 *assembler2_p = NULL;
2360 *cc_valid_p = 0;
2361 return SHIFT_ROT_AND;
2362 }
2363 }
2364 break;
2365
2366 case SIshift:
2367 if (count <= (TARGET_H8300 ? 2 : 4))
2368 return SHIFT_INLINE;
2369 else if (TARGET_H8300S && count <= 10)
2370 return SHIFT_INLINE;
2371 else if (count == 8 && TARGET_H8300)
2372 {
2373 switch (shift_type)
2374 {
2375 case SHIFT_ASHIFT:
2376 *assembler_p = "mov.b\t%y0,%z0\n\tmov.b\t%x0,%y0\n\tmov.b\t%w0,%x0\n\tsub.b\t%w0,%w0";
2377 *cc_valid_p = 0;
2378 return SHIFT_SPECIAL;
2379 case SHIFT_LSHIFTRT:
2380 *assembler_p = "mov.b\t%x0,%w0\n\tmov.b\t%y0,%x0\n\tmov.b\t%z0,%y0\n\tsub.b\t%z0,%z0";
2381 *cc_valid_p = 0;
2382 return SHIFT_SPECIAL;
2383 case SHIFT_ASHIFTRT:
2384 *assembler_p = "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";
2385 *cc_valid_p = 0;
2386 return SHIFT_SPECIAL;
2387 }
2388 }
2389 else if (count == 8 && !TARGET_H8300)
2390 {
2391 switch (shift_type)
2392 {
2393 case SHIFT_ASHIFT:
2394 *assembler_p = "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";
2395 *cc_valid_p = 0;
2396 return SHIFT_SPECIAL;
2397 case SHIFT_LSHIFTRT:
2398 *assembler_p = "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";
2399 *cc_valid_p = 0;
2400 return SHIFT_SPECIAL;
2401 case SHIFT_ASHIFTRT:
2402 *assembler_p = "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";
2403 *cc_valid_p = 0;
2404 return SHIFT_SPECIAL;
2405 }
2406 }
2407 else if (count == 16)
2408 {
2409 switch (shift_type)
2410 {
2411 case SHIFT_ASHIFT:
2412 *assembler_p = "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0";
2413 *cc_valid_p = 0;
2414 return SHIFT_SPECIAL;
2415 case SHIFT_LSHIFTRT:
2416 *assembler_p = "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0";
2417 *cc_valid_p = 0;
2418 return SHIFT_SPECIAL;
2419 case SHIFT_ASHIFTRT:
2420 if (TARGET_H8300)
2421 *assembler_p = "mov.w\t%e0,%f0\n\tshll\t%z0\n\tsubx\t%z0,%z0\n\tmov.b\t%z0,%y0";
2422 else
2423 *assembler_p = "mov.w\t%e0,%f0\n\texts.l\t%S0";
2424 *cc_valid_p = 0;
2425 return SHIFT_SPECIAL;
2426 }
2427 }
2428 else if (count == 17 && !TARGET_H8300)
2429 {
2430 switch (shift_type)
2431 {
2432 case SHIFT_ASHIFT:
2433 *assembler_p = "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0\n\tshll.l\t%S0";
2434 *cc_valid_p = 0;
2435 return SHIFT_SPECIAL;
2436 case SHIFT_LSHIFTRT:
2437 *assembler_p = "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0\n\tshlr.l\t%S0";
2438 *cc_valid_p = 0;
2439 return SHIFT_SPECIAL;
2440 case SHIFT_ASHIFTRT:
2441 *assembler_p = "mov.w\t%e0,%f0\n\texts.l\t%S0\n\tshar.l\t%S0";
2442 *cc_valid_p = 0;
2443 return SHIFT_SPECIAL;
2444 }
2445 }
2446 else if (count == 18 && !TARGET_H8300)
2447 {
2448 switch (shift_type)
2449 {
2450 case SHIFT_ASHIFT:
2451 if (TARGET_H8300S)
2452 *assembler_p = "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0\n\tshll.l\t#2,%S0";
2453 else
2454 *assembler_p = "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0\n\tshll.l\t%S0\n\tshll.l\t%S0";
2455 *cc_valid_p = 0;
2456 return SHIFT_SPECIAL;
2457 case SHIFT_LSHIFTRT:
2458 if (TARGET_H8300S)
2459 *assembler_p = "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0\n\tshlr.l\t#2,%S0";
2460 else
2461 *assembler_p = "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0\n\tshlr.l\t%S0\n\tshlr.l\t%S0";
2462 *cc_valid_p = 0;
2463 return SHIFT_SPECIAL;
2464 case SHIFT_ASHIFTRT:
2465 if (TARGET_H8300S)
2466 *assembler_p = "mov.w\t%e0,%f0\n\texts.l\t%S0\n\tshar.l\t#2,%S0";
2467 else
2468 *assembler_p = "mov.w\t%e0,%f0\n\texts.l\t%S0\n\tshar.l\t%S0\n\tshar.l\t%S0";
2469 *cc_valid_p = 0;
2470 return SHIFT_SPECIAL;
2471 }
2472 }
2473 else if (count == 19 && !TARGET_H8300)
2474 {
2475 switch (shift_type)
2476 {
2477 case SHIFT_ASHIFT:
2478 if (TARGET_H8300S)
2479 *assembler_p = "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0\n\tshll.l\t#2,%S0\n\tshll.l\t%S0";
2480 else
2481 *assembler_p = "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0\n\tshll.l\t%S0\n\tshll.l\t%S0\n\tshll.l\t%S0";
2482 *cc_valid_p = 0;
2483 return SHIFT_SPECIAL;
2484 case SHIFT_LSHIFTRT:
2485 if (TARGET_H8300S)
2486 *assembler_p = "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0\n\tshlr.l\t#2,%S0\n\tshlr.l\t%S0";
2487 else
2488 *assembler_p = "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0\n\tshlr.l\t%S0\n\tshlr.l\t%S0\n\tshlr.l\t%S0";
2489 *cc_valid_p = 0;
2490 return SHIFT_SPECIAL;
2491 case SHIFT_ASHIFTRT:
2492 if (TARGET_H8300S)
2493 *assembler_p = "mov.w\t%e0,%f0\n\texts.l\t%S0\n\tshar.l\t#2,%S0\n\tshar.l\t%S0";
2494 else
2495 *assembler_p = "mov.w\t%e0,%f0\n\texts.l\t%S0\n\tshar.l\t%S0\n\tshar.l\t%S0\n\tshar.l\t%S0";
2496 *cc_valid_p = 0;
2497 return SHIFT_SPECIAL;
2498 }
2499 }
2500 else if (count == 20 && TARGET_H8300S)
2501 {
2502 switch (shift_type)
2503 {
2504 case SHIFT_ASHIFT:
2505 *assembler_p = "mov.w\t%f0,%e0\n\tsub.w\t%f0,%f0\n\tshll.l\t#2,%S0\n\tshll.l\t#2,%S0";
2506 *cc_valid_p = 0;
2507 return SHIFT_SPECIAL;
2508 case SHIFT_LSHIFTRT:
2509 *assembler_p = "mov.w\t%e0,%f0\n\tsub.w\t%e0,%e0\n\tshlr.l\t#2,%S0\n\tshlr.l\t#2,%S0";
2510 *cc_valid_p = 0;
2511 return SHIFT_SPECIAL;
2512 case SHIFT_ASHIFTRT:
2513 *assembler_p = "mov.w\t%e0,%f0\n\texts.l\t%S0\n\tshar.l\t#2,%S0\n\tshar.l\t#2,%S0";
2514 *cc_valid_p = 0;
2515 return SHIFT_SPECIAL;
2516 }
2517 }
2518 else if (count == 24 && !TARGET_H8300)
2519 {
2520 switch (shift_type)
2521 {
2522 case SHIFT_ASHIFT:
2523 *assembler_p = "mov.b\t%s0,%t0\n\tsub.b\t%s0,%s0\n\tmov.w\t%f0,%e0\n\tsub.w\t%f0,%f0";
2524 *cc_valid_p = 0;
2525 return SHIFT_SPECIAL;
2526 case SHIFT_LSHIFTRT:
2527 *assembler_p = "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\textu.w\t%f0\n\textu.l\t%S0";
2528 *cc_valid_p = 0;
2529 return SHIFT_SPECIAL;
2530 case SHIFT_ASHIFTRT:
2531 *assembler_p = "mov.w\t%e0,%f0\n\tmov.b\t%t0,%s0\n\texts.w\t%f0\n\texts.l\t%S0";
2532 *cc_valid_p = 0;
2533 return SHIFT_SPECIAL;
2534 }
2535 }
2536 else if (count >= 28 && count <= 30 && !TARGET_H8300)
2537 {
2538 if (shift_type == SHIFT_ASHIFTRT)
2539 {
2540 return SHIFT_LOOP;
2541 }
2542 else
2543 {
2544 *assembler_p = rotate_one[cpu][shift_type][shift_mode];
2545 if (TARGET_H8300S)
2546 *assembler2_p = rotate_two[shift_type][shift_mode];
2547 else
2548 *assembler2_p = NULL;
2549 *cc_valid_p = 0;
2550 return SHIFT_ROT_AND;
2551 }
2552 }
2553 else if (count == 31)
2554 {
2555 if (shift_type == SHIFT_ASHIFTRT)
2556 {
2557 if (TARGET_H8300)
2558 *assembler_p = "shll\t%z0\n\tsubx %w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
2559 else
2560 *assembler_p = "shll\t%e0\n\tsubx\t%w0,%w0\n\tmov.b\t%w0,%x0\n\tmov.w\t%f0,%e0";
2561 *cc_valid_p = 0;
2562 return SHIFT_SPECIAL;
2563 }
2564 else
2565 {
2566 if (TARGET_H8300)
2567 {
2568 if (shift_type == SHIFT_ASHIFT)
2569 *assembler_p = "sub.w\t%e0,%e0\n\tshlr\t%w0\n\tmov.w\t%e0,%f0\n\trotxr\t%z0";
2570 else
2571 *assembler_p = "sub.w\t%f0,%f0\n\tshll\t%z0\n\tmov.w\t%f0,%e0\n\trotxl\t%w0";
2572 *cc_valid_p = 0;
2573 return SHIFT_SPECIAL;
2574 }
2575 else
2576 {
2577 *assembler_p = rotate_one[cpu][shift_type][shift_mode];
2578 if (TARGET_H8300S)
2579 *assembler2_p = rotate_two[shift_type][shift_mode];
2580 else
2581 *assembler2_p = NULL;
2582 *cc_valid_p = 0;
2583 return SHIFT_ROT_AND;
2584 }
2585 }
2586 }
2587 break;
2588
2589 default:
2590 abort ();
2591 }
2592
2593 return alg;
2594 }
2595
2596 /* Emit the assembler code for doing shifts. */
2597
2598 const char *
2599 emit_a_shift (insn, operands)
2600 rtx insn ATTRIBUTE_UNUSED;
2601 rtx *operands;
2602 {
2603 static int loopend_lab;
2604 const char *assembler;
2605 const char *assembler2;
2606 int cc_valid;
2607 rtx shift = operands[3];
2608 enum machine_mode mode = GET_MODE (shift);
2609 enum rtx_code code = GET_CODE (shift);
2610 enum shift_type shift_type;
2611 enum shift_mode shift_mode;
2612
2613 loopend_lab++;
2614
2615 switch (mode)
2616 {
2617 case QImode:
2618 shift_mode = QIshift;
2619 break;
2620 case HImode:
2621 shift_mode = HIshift;
2622 break;
2623 case SImode:
2624 shift_mode = SIshift;
2625 break;
2626 default:
2627 abort ();
2628 }
2629
2630 switch (code)
2631 {
2632 case ASHIFTRT:
2633 shift_type = SHIFT_ASHIFTRT;
2634 break;
2635 case LSHIFTRT:
2636 shift_type = SHIFT_LSHIFTRT;
2637 break;
2638 case ASHIFT:
2639 shift_type = SHIFT_ASHIFT;
2640 break;
2641 default:
2642 abort ();
2643 }
2644
2645 if (GET_CODE (operands[2]) != CONST_INT)
2646 {
2647 /* Indexing by reg, so have to loop and test at top */
2648 output_asm_insn ("mov.b %X2,%X4", operands);
2649 fprintf (asm_out_file, "\tble .Lle%d\n", loopend_lab);
2650
2651 /* Get the assembler code to do one shift. */
2652 get_shift_alg (cpu_type, shift_type, mode, 1, &assembler,
2653 &assembler2, &cc_valid);
2654 }
2655 else
2656 {
2657 int n = INTVAL (operands[2]);
2658 enum shift_alg alg;
2659
2660 /* If the count is negative, make it 0. */
2661 if (n < 0)
2662 n = 0;
2663 /* If the count is too big, truncate it.
2664 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
2665 do the intuitive thing. */
2666 else if (n > GET_MODE_BITSIZE (mode))
2667 n = GET_MODE_BITSIZE (mode);
2668
2669 alg = get_shift_alg (cpu_type, shift_type, mode, n, &assembler,
2670 &assembler2, &cc_valid);
2671
2672 switch (alg)
2673 {
2674 case SHIFT_INLINE:
2675 /* Emit two bit shifts first. */
2676 while (n > 1 && assembler2 != NULL)
2677 {
2678 output_asm_insn (assembler2, operands);
2679 n -= 2;
2680 }
2681
2682 /* Now emit one bit shifts for any residual. */
2683 while (n > 0)
2684 {
2685 output_asm_insn (assembler, operands);
2686 n -= 1;
2687 }
2688
2689 /* Keep track of CC. */
2690 if (cc_valid)
2691 {
2692 cc_status.value1 = operands[0];
2693 cc_status.flags |= cc_valid;
2694 }
2695 return "";
2696
2697 case SHIFT_ROT_AND:
2698 {
2699 int m = GET_MODE_BITSIZE (mode) - n;
2700 int mask = (shift_type == SHIFT_ASHIFT
2701 ? ((1 << (GET_MODE_BITSIZE (mode) - n)) - 1) << n
2702 : (1 << (GET_MODE_BITSIZE (mode) - n)) - 1);
2703 char insn_buf[200];
2704 /* Not all possibilities of rotate are supported. They shouldn't
2705 be generated, but let's watch for 'em. */
2706 if (assembler == 0)
2707 abort ();
2708
2709 /* Emit two bit rotates first. */
2710 while (m > 1 && assembler2 != NULL)
2711 {
2712 output_asm_insn (assembler2, operands);
2713 m -= 2;
2714 }
2715
2716 /* Now single bit rotates for any residual. */
2717 while (m > 0)
2718 {
2719 output_asm_insn (assembler, operands);
2720 m -= 1;
2721 }
2722
2723 /* Now mask off the high bits. */
2724 if (TARGET_H8300)
2725 {
2726 switch (mode)
2727 {
2728 case QImode:
2729 sprintf (insn_buf, "and #%d,%%X0", mask);
2730 cc_status.value1 = operands[0];
2731 cc_status.flags |= CC_NO_CARRY;
2732 break;
2733 case HImode:
2734 sprintf (insn_buf, "and #%d,%%s0\n\tand #%d,%%t0",
2735 mask & 255, mask >> 8);
2736 break;
2737 case SImode:
2738 abort ();
2739 default:
2740 break;
2741 }
2742 }
2743 else
2744 {
2745 sprintf (insn_buf, "and.%c #%d,%%%c0",
2746 "bwl"[shift_mode], mask,
2747 mode == QImode ? 'X' : mode == HImode ? 'T' : 'S');
2748 cc_status.value1 = operands[0];
2749 cc_status.flags |= CC_NO_CARRY;
2750 }
2751 output_asm_insn (insn_buf, operands);
2752 return "";
2753 }
2754 case SHIFT_SPECIAL:
2755 output_asm_insn (assembler, operands);
2756 return "";
2757 }
2758
2759 /* A loop to shift by a "large" constant value.
2760 If we have shift-by-2 insns, use them. */
2761 if (assembler2 != NULL)
2762 {
2763 fprintf (asm_out_file, "\tmov.b #%d,%sl\n", n / 2,
2764 names_big[REGNO (operands[4])]);
2765 fprintf (asm_out_file, ".Llt%d:\n", loopend_lab);
2766 output_asm_insn (assembler2, operands);
2767 output_asm_insn ("add #0xff,%X4", operands);
2768 fprintf (asm_out_file, "\tbne .Llt%d\n", loopend_lab);
2769 if (n % 2)
2770 output_asm_insn (assembler, operands);
2771 return "";
2772 }
2773 else
2774 {
2775 fprintf (asm_out_file, "\tmov.b #%d,%sl\n", n,
2776 names_big[REGNO (operands[4])]);
2777 fprintf (asm_out_file, ".Llt%d:\n", loopend_lab);
2778 output_asm_insn (assembler, operands);
2779 output_asm_insn ("add #0xff,%X4", operands);
2780 fprintf (asm_out_file, "\tbne .Llt%d\n", loopend_lab);
2781 return "";
2782 }
2783 }
2784
2785 fprintf (asm_out_file, ".Llt%d:\n", loopend_lab);
2786 output_asm_insn (assembler, operands);
2787 output_asm_insn ("add #0xff,%X4", operands);
2788 fprintf (asm_out_file, "\tbne .Llt%d\n", loopend_lab);
2789 fprintf (asm_out_file, ".Lle%d:\n", loopend_lab);
2790
2791 return "";
2792 }
2793 \f
2794 /* Fix the operands of a gen_xxx so that it could become a bit
2795 operating insn. */
2796
2797 int
2798 fix_bit_operand (operands, what, type)
2799 rtx *operands;
2800 int what;
2801 enum rtx_code type;
2802 {
2803 /* The bit_operand predicate accepts any memory during RTL generation, but
2804 only 'U' memory afterwards, so if this is a MEM operand, we must force
2805 it to be valid for 'U' by reloading the address. */
2806
2807 if (GET_CODE (operands[2]) == CONST_INT)
2808 {
2809 if (CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), what))
2810 {
2811 /* Ok to have a memory dest. */
2812 if (GET_CODE (operands[0]) == MEM && !EXTRA_CONSTRAINT (operands[0], 'U'))
2813 {
2814 rtx mem = gen_rtx_MEM (GET_MODE (operands[0]),
2815 copy_to_mode_reg (Pmode,
2816 XEXP (operands[0], 0)));
2817 RTX_UNCHANGING_P (mem) = RTX_UNCHANGING_P (operands[0]);
2818 MEM_COPY_ATTRIBUTES (mem, operands[0]);
2819 operands[0] = mem;
2820 }
2821
2822 if (GET_CODE (operands[1]) == MEM && !EXTRA_CONSTRAINT (operands[1], 'U'))
2823 {
2824 rtx mem = gen_rtx_MEM (GET_MODE (operands[1]),
2825 copy_to_mode_reg (Pmode,
2826 XEXP (operands[1], 0)));
2827 RTX_UNCHANGING_P (mem) = RTX_UNCHANGING_P (operands[1]);
2828 MEM_COPY_ATTRIBUTES (mem, operands[0]);
2829 operands[1] = mem;
2830 }
2831 return 0;
2832 }
2833 }
2834
2835 /* Dest and src op must be register. */
2836
2837 operands[1] = force_reg (QImode, operands[1]);
2838 {
2839 rtx res = gen_reg_rtx (QImode);
2840 emit_insn (gen_rtx_SET (VOIDmode, res,
2841 gen_rtx (type, QImode, operands[1], operands[2])));
2842 emit_insn (gen_rtx_SET (VOIDmode, operands[0], res));
2843 }
2844 return 1;
2845 }
2846
2847 /* Return nonzero if FUNC is an interrupt function as specified
2848 by the "interrupt" attribute. */
2849
2850 static int
2851 h8300_interrupt_function_p (func)
2852 tree func;
2853 {
2854 tree a;
2855
2856 if (TREE_CODE (func) != FUNCTION_DECL)
2857 return 0;
2858
2859 a = lookup_attribute ("interrupt_handler", DECL_MACHINE_ATTRIBUTES (func));
2860 return a != NULL_TREE;
2861 }
2862
2863 /* Return nonzero if FUNC is an OS_Task function as specified
2864 by the "OS_Task" attribute. */
2865
2866 static int
2867 h8300_os_task_function_p (func)
2868 tree func;
2869 {
2870 tree a;
2871
2872 if (TREE_CODE (func) != FUNCTION_DECL)
2873 return 0;
2874
2875 a = lookup_attribute ("OS_Task", DECL_MACHINE_ATTRIBUTES (func));
2876 return a != NULL_TREE;
2877 }
2878
2879 /* Return nonzero if FUNC is a monitor function as specified
2880 by the "monitor" attribute. */
2881
2882 static int
2883 h8300_monitor_function_p (func)
2884 tree func;
2885 {
2886 tree a;
2887
2888 if (TREE_CODE (func) != FUNCTION_DECL)
2889 return 0;
2890
2891 a = lookup_attribute ("monitor", DECL_MACHINE_ATTRIBUTES (func));
2892 return a != NULL_TREE;
2893 }
2894
2895 /* Return nonzero if FUNC is a function that should be called
2896 through the function vector. */
2897
2898 int
2899 h8300_funcvec_function_p (func)
2900 tree func;
2901 {
2902 tree a;
2903
2904 if (TREE_CODE (func) != FUNCTION_DECL)
2905 return 0;
2906
2907 a = lookup_attribute ("function_vector", DECL_MACHINE_ATTRIBUTES (func));
2908 return a != NULL_TREE;
2909 }
2910
2911 /* Return nonzero if DECL is a variable that's in the eight bit
2912 data area. */
2913
2914 int
2915 h8300_eightbit_data_p (decl)
2916 tree decl;
2917 {
2918 tree a;
2919
2920 if (TREE_CODE (decl) != VAR_DECL)
2921 return 0;
2922
2923 a = lookup_attribute ("eightbit_data", DECL_MACHINE_ATTRIBUTES (decl));
2924 return a != NULL_TREE;
2925 }
2926
2927 /* Return nonzero if DECL is a variable that's in the tiny
2928 data area. */
2929
2930 int
2931 h8300_tiny_data_p (decl)
2932 tree decl;
2933 {
2934 tree a;
2935
2936 if (TREE_CODE (decl) != VAR_DECL)
2937 return 0;
2938
2939 a = lookup_attribute ("tiny_data", DECL_MACHINE_ATTRIBUTES (decl));
2940 return a != NULL_TREE;
2941 }
2942
2943 /* Return nonzero if ATTR is a valid attribute for DECL.
2944 ATTRIBUTES are any existing attributes and ARGS are the arguments
2945 supplied with ATTR.
2946
2947 Supported attributes:
2948
2949 interrupt_handler: output a prologue and epilogue suitable for an
2950 interrupt handler.
2951
2952 function_vector: This function should be called through the
2953 function vector.
2954
2955 eightbit_data: This variable lives in the 8-bit data area and can
2956 be referenced with 8-bit absolute memory addresses.
2957
2958 tiny_data: This variable lives in the tiny data area and can be
2959 referenced with 16-bit absolute memory references. */
2960
2961 int
2962 h8300_valid_machine_decl_attribute (decl, attributes, attr, args)
2963 tree decl;
2964 tree attributes ATTRIBUTE_UNUSED;
2965 tree attr;
2966 tree args;
2967 {
2968 if (args != NULL_TREE)
2969 return 0;
2970
2971 if (is_attribute_p ("interrupt_handler", attr)
2972 || is_attribute_p ("OS_Task", attr)
2973 || is_attribute_p ("monitor", attr)
2974 || is_attribute_p ("function_vector", attr))
2975 return TREE_CODE (decl) == FUNCTION_DECL;
2976
2977 if (is_attribute_p ("eightbit_data", attr)
2978 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2979 {
2980 if (DECL_INITIAL (decl) == NULL_TREE)
2981 {
2982 warning ("Only initialized variables can be placed into the 8-bit area.");
2983 return 0;
2984 }
2985 DECL_SECTION_NAME (decl) = build_string (7, ".eight");
2986 return 1;
2987 }
2988
2989 if (is_attribute_p ("tiny_data", attr)
2990 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2991 {
2992 if (DECL_INITIAL (decl) == NULL_TREE)
2993 {
2994 warning ("Only initialized variables can be placed into the 8-bit area.");
2995 return 0;
2996 }
2997 DECL_SECTION_NAME (decl) = build_string (6, ".tiny");
2998 return 1;
2999 }
3000
3001 return 0;
3002 }
3003
3004 extern struct obstack *saveable_obstack;
3005
3006 void
3007 h8300_encode_label (decl)
3008 tree decl;
3009 {
3010 const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
3011 int len = strlen (str);
3012 char *newstr;
3013
3014 newstr = obstack_alloc (saveable_obstack, len + 2);
3015
3016 strcpy (newstr + 1, str);
3017 *newstr = '&';
3018 XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr;
3019 }
3020
3021 const char *
3022 output_simode_bld (bild, log2, operands)
3023 int bild;
3024 int log2;
3025 rtx operands[];
3026 {
3027 /* Clear the destination register. */
3028 if (TARGET_H8300H || TARGET_H8300S)
3029 output_asm_insn ("sub.l\t%S0,%S0", operands);
3030 else
3031 output_asm_insn ("sub.w\t%e0,%e0\n\tsub.w\t%f0,%f0", operands);
3032
3033 /* Get the bit number we want to load. */
3034 if (log2)
3035 operands[2] = GEN_INT (exact_log2 (INTVAL (operands[2])));
3036
3037 /* Now output the bit load or bit inverse load, and store it in
3038 the destination. */
3039 if (bild)
3040 output_asm_insn ("bild\t%Z2,%Y1\n\tbst\t#0,%w0", operands);
3041 else
3042 output_asm_insn ("bld\t%Z2,%Y1\n\tbst\t#0,%w0", operands);
3043
3044 /* All done. */
3045 return "";
3046 }
3047
3048 /* Given INSN and its current length LENGTH, return the adjustment
3049 (in bytes) to correctly compute INSN's length.
3050
3051 We use this to get the lengths of various memory references correct. */
3052
3053 int
3054 h8300_adjust_insn_length (insn, length)
3055 rtx insn;
3056 int length ATTRIBUTE_UNUSED;
3057 {
3058 rtx pat;
3059
3060 /* We must filter these ou before calling get_attr_adjust_length. */
3061 if (GET_CODE (PATTERN (insn)) == USE
3062 || GET_CODE (PATTERN (insn)) == CLOBBER
3063 || GET_CODE (PATTERN (insn)) == SEQUENCE
3064 || GET_CODE (PATTERN (insn)) == ADDR_VEC
3065 || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
3066 return 0;
3067
3068 if (get_attr_adjust_length (insn) == ADJUST_LENGTH_NO)
3069 return 0;
3070
3071 pat = PATTERN (insn);
3072
3073 /* Adjust length for reg->mem and mem->reg copies. */
3074 if (GET_CODE (pat) == SET
3075 && (GET_CODE (SET_SRC (pat)) == MEM
3076 || GET_CODE (SET_DEST (pat)) == MEM))
3077 {
3078 /* This insn might need a length adjustment. */
3079 rtx addr;
3080
3081 if (GET_CODE (SET_SRC (pat)) == MEM)
3082 addr = XEXP (SET_SRC (pat), 0);
3083 else
3084 addr = XEXP (SET_DEST (pat), 0);
3085
3086 /* On the H8/300, only one adjustment is necessary; if the
3087 address mode is register indirect, then this insn is two
3088 bytes shorter than indicated in the machine description. */
3089 if (TARGET_H8300 && GET_CODE (addr) == REG)
3090 return -2;
3091
3092 /* On the H8/300H and H8/S, register indirect is 6 bytes shorter than
3093 indicated in the machine description. */
3094 if ((TARGET_H8300H || TARGET_H8300S)
3095 && GET_CODE (addr) == REG)
3096 return -6;
3097
3098 /* On the H8/300H and H8/300S, reg + d, for small displacements is 4
3099 bytes shorter than indicated in the machine description. */
3100 if ((TARGET_H8300H || TARGET_H8300S)
3101 && GET_CODE (addr) == PLUS
3102 && GET_CODE (XEXP (addr, 0)) == REG
3103 && GET_CODE (XEXP (addr, 1)) == CONST_INT
3104 && INTVAL (XEXP (addr, 1)) > -32768
3105 && INTVAL (XEXP (addr, 1)) < 32767)
3106 return -4;
3107
3108 /* On the H8/300H and H8/300S, abs:16 is two bytes shorter than the
3109 more general abs:24. */
3110 if ((TARGET_H8300H || TARGET_H8300S)
3111 && GET_CODE (addr) == SYMBOL_REF
3112 && TINY_DATA_NAME_P (XSTR (addr, 0)))
3113 return -2;
3114 }
3115
3116 /* Loading some constants needs adjustment. */
3117 if (GET_CODE (pat) == SET
3118 && GET_CODE (SET_SRC (pat)) == CONST_INT
3119 && GET_MODE (SET_DEST (pat)) == SImode
3120 && INTVAL (SET_SRC (pat)) != 0)
3121 {
3122 if (TARGET_H8300
3123 && ((INTVAL (SET_SRC (pat)) & 0xffff) == 0
3124 || ((INTVAL (SET_SRC (pat)) >> 16) & 0xffff) == 0))
3125 return -2;
3126
3127 if (TARGET_H8300H || TARGET_H8300S)
3128 {
3129 int val = INTVAL (SET_SRC (pat));
3130
3131 if (val == (val & 0xff)
3132 || val == (val & 0xff00))
3133 return -6;
3134
3135 if (val == -4 || val == -2 || val == -1)
3136 return -6;
3137 }
3138 }
3139
3140 /* Shifts need various adjustments. */
3141 if (GET_CODE (pat) == PARALLEL
3142 && GET_CODE (XVECEXP (pat, 0, 0)) == SET
3143 && (GET_CODE (SET_SRC (XVECEXP (pat, 0, 0))) == ASHIFTRT
3144 || GET_CODE (SET_SRC (XVECEXP (pat, 0, 0))) == LSHIFTRT
3145 || GET_CODE (SET_SRC (XVECEXP (pat, 0, 0))) == ASHIFT))
3146 {
3147 rtx src = SET_SRC (XVECEXP (pat, 0, 0));
3148 enum machine_mode mode = GET_MODE (src);
3149 int shift;
3150
3151 if (GET_CODE (XEXP (src, 1)) != CONST_INT)
3152 return 0;
3153
3154 shift = INTVAL (XEXP (src, 1));
3155 /* According to ANSI, negative shift is undefined. It is
3156 considered to be zero in this case (see function
3157 emit_a_shift above). */
3158 if (shift < 0)
3159 shift = 0;
3160
3161 /* QImode shifts by small constants take one insn
3162 per shift. So the adjustment is 20 (md length) -
3163 # shifts * 2. */
3164 if (mode == QImode && shift <= 4)
3165 return -(20 - shift * 2);
3166
3167 /* Similarly for HImode and SImode shifts by
3168 small constants on the H8/300H and H8/300S. */
3169 if ((TARGET_H8300H || TARGET_H8300S)
3170 && (mode == HImode || mode == SImode) && shift <= 4)
3171 return -(20 - shift * 2);
3172
3173 /* HImode shifts by small constants for the H8/300. */
3174 if (mode == HImode && shift <= 4)
3175 return -(20 - (shift * (GET_CODE (src) == ASHIFT ? 2 : 4)));
3176
3177 /* SImode shifts by small constants for the H8/300. */
3178 if (mode == SImode && shift <= 2)
3179 return -(20 - (shift * (GET_CODE (src) == ASHIFT ? 6 : 8)));
3180
3181 /* XXX ??? Could check for more shift/rotate cases here. */
3182 }
3183
3184 return 0;
3185 }
This page took 0.186594 seconds and 5 git commands to generate.