1 /* Subroutines for insn-output.c for Matsushita MN10200 series
2 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
33 #include "insn-attr.h"
43 #include "target-def.h"
45 /* Global registers known to hold the value zero.
47 Normally we'd depend on CSE and combine to put zero into a
48 register and re-use it.
50 However, on the mn10x00 processors we implicitly use the constant
51 zero in tst instructions, so we might be able to do better by
52 loading the value into a register in the prologue, then re-useing
53 that register throughout the function.
55 We could perform similar optimizations for other constants, but with
56 gcse due soon, it doesn't seem worth the effort.
58 These variables hold a rtx for a register known to hold the value
59 zero throughout the entire function, or NULL if no register of
60 the appropriate class has such a value throughout the life of the
65 static void count_tst_insns
PARAMS ((int *));
67 /* Note whether or not we need an out of line epilogue. */
68 static int out_of_line_epilogue
;
70 /* Initialize the GCC target structure. */
71 #undef TARGET_ASM_ALIGNED_HI_OP
72 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
74 struct gcc_target targetm
= TARGET_INITIALIZER
;
76 /* Indicate this file was compiled by gcc and what optimization
82 fprintf (file
, "#\tGCC For the Matsushita MN10200\n");
84 fprintf (file
, "# -O%d\n", optimize
);
86 fprintf (file
, "\n\n");
87 output_file_directive (file
, main_input_filename
);
88 ggc_add_rtx_root (&zero_dreg
, 1);
89 ggc_add_rtx_root (&zero_areg
, 1);
92 /* Print operand X using operand code CODE to assembly language output file
96 print_operand (file
, x
, code
)
105 /* These are normal and reversed branches. */
106 switch (code
== 'b' ? GET_CODE (x
) : reverse_condition (GET_CODE (x
)))
109 fprintf (file
, "ne");
112 fprintf (file
, "eq");
115 fprintf (file
, "ge");
118 fprintf (file
, "gt");
121 fprintf (file
, "le");
124 fprintf (file
, "lt");
127 fprintf (file
, "cc");
130 fprintf (file
, "hi");
133 fprintf (file
, "ls");
136 fprintf (file
, "cs");
143 /* This is used for the operand to a call instruction;
144 if it's a REG, enclose it in parens, else output
145 the operand normally. */
146 if (GET_CODE (x
) == REG
)
149 print_operand (file
, x
, 0);
153 print_operand (file
, x
, 0);
156 /* These are the least significant word in a 32bit value.
157 'o' allows us to sign extend a constant if doing so
158 makes for more compact code. */
161 switch (GET_CODE (x
))
165 output_address (XEXP (x
, 0));
170 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
174 fprintf (file
, "%s", reg_names
[subreg_regno (x
)]);
183 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
184 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
185 print_operand_address (file
, GEN_INT (val
& 0xffff));
192 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
193 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
196 val
= (((val
) & 0xffff) ^ (~0x7fff)) + 0x8000;
197 print_operand_address (file
, GEN_INT (val
));
203 print_operand_address (file
, GEN_INT ((INTVAL (x
) & 0xffff)));
206 unsigned int val
= INTVAL (x
) & 0xffff;
207 val
= (((val
) & 0xffff) ^ (~0x7fff)) + 0x8000;
208 print_operand_address (file
, GEN_INT (val
));
216 /* Similarly, but for the most significant word. */
219 switch (GET_CODE (x
))
223 x
= adjust_address (x
, HImode
, 2);
224 output_address (XEXP (x
, 0));
229 fprintf (file
, "%s", reg_names
[REGNO (x
) + 1]);
233 fprintf (file
, "%s", reg_names
[subreg_regno (x
) + 1]);
242 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
243 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
245 print_operand_address (file
, GEN_INT ((val
>> 16) & 0xffff));
252 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
253 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
255 val
= (val
>> 16) & 0xffff;
256 val
= (((val
) & 0xffff) ^ (~0x7fff)) + 0x8000;
258 print_operand_address (file
, GEN_INT (val
));
264 print_operand_address (file
,
265 GEN_INT ((INTVAL (x
) >> 16) & 0xffff));
268 unsigned int val
= (INTVAL (x
) >> 16) & 0xffff;
269 val
= (((val
) & 0xffff) ^ (~0x7fff)) + 0x8000;
271 print_operand_address (file
, GEN_INT (val
));
279 /* Output ~CONST_INT. */
281 if (GET_CODE (x
) != CONST_INT
)
283 fprintf (file
, "%d", ~INTVAL (x
));
286 /* An address which can not be register indirect, if it is
287 register indirect, then turn it into reg + disp. */
289 if (GET_CODE (x
) != MEM
)
291 if (GET_CODE (XEXP (x
, 0)) == REG
)
292 x
= gen_rtx_PLUS (PSImode
, XEXP (x
, 0), GEN_INT (0));
301 print_operand (file
, XEXP (x
, 1), 0);
304 /* More cases where we can sign-extend a CONST_INT if it
305 results in more compact code. */
308 if (GET_CODE (x
) == CONST_INT
)
310 int val
= INTVAL (x
);
313 x
= GEN_INT (((val
& 0xffff) ^ (~0x7fff)) + 0x8000);
315 x
= GEN_INT (((val
& 0xff) ^ (~0x7f)) + 0x80);
319 switch (GET_CODE (x
))
323 output_address (XEXP (x
, 0));
328 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
332 fprintf (file
, "%s", reg_names
[subreg_regno (x
)]);
341 print_operand_address (file
, x
);
350 /* Output assembly language output for the address ADDR to FILE. */
353 print_operand_address (file
, addr
)
357 switch (GET_CODE (addr
))
360 print_operand (file
, addr
, 0);
365 /* The base and index could be in any order, so we have
366 to figure out which is the base and which is the index.
367 Uses the same code as GO_IF_LEGITIMATE_ADDRESS. */
368 if (REG_P (XEXP (addr
, 0))
369 && REG_OK_FOR_BASE_P (XEXP (addr
, 0)))
370 base
= XEXP (addr
, 0), index
= XEXP (addr
, 1);
371 else if (REG_P (XEXP (addr
, 1))
372 && REG_OK_FOR_BASE_P (XEXP (addr
, 1)))
373 base
= XEXP (addr
, 1), index
= XEXP (addr
, 0);
376 print_operand (file
, index
, 0);
378 print_operand (file
, base
, 0);;
382 output_addr_const (file
, addr
);
385 output_addr_const (file
, addr
);
390 /* Count the number of tst insns which compare an address register
393 count_tst_insns (areg_countp
)
398 /* Assume no tst insns exist. */
401 /* If not optimizing, then quit now. */
405 /* Walk through all the insns. */
406 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
410 /* Ignore anything that is not a normal INSN. */
411 if (GET_CODE (insn
) != INSN
)
414 /* Ignore anything that isn't a SET. */
415 pat
= PATTERN (insn
);
416 if (GET_CODE (pat
) != SET
)
419 /* Check for a tst insn. */
420 if (SET_DEST (pat
) == cc0_rtx
421 && GET_CODE (SET_SRC (pat
)) == REG
422 && REGNO_REG_CLASS (REGNO (SET_SRC (pat
))) == ADDRESS_REGS
)
427 /* Return the total size (in bytes) of the current function's frame.
428 This is the size of the register save area + the size of locals,
433 unsigned int size
= get_frame_size ();
434 unsigned int outgoing_args_size
= current_function_outgoing_args_size
;
437 /* First figure out if we're going to use an out of line
438 prologue, if so we have to make space for all the
439 registers, even if we don't use them. */
440 if (optimize
&& !current_function_needs_context
&& !frame_pointer_needed
)
442 int inline_count
, outline_count
;
444 /* Compute how many bytes an inline prologue would take.
446 Each address register store takes two bytes, each data register
447 store takes three bytes. */
449 if (regs_ever_live
[5])
451 if (regs_ever_live
[6])
453 if (regs_ever_live
[2])
455 if (regs_ever_live
[3])
458 /* If this function has any stack, then the stack adjustment
459 will take two (or more) bytes. */
460 if (size
|| outgoing_args_size
461 || regs_ever_live
[5] || regs_ever_live
[6]
462 || regs_ever_live
[2] || regs_ever_live
[3])
465 /* Multiply the current count by two and add one to account for the
467 inline_count
= inline_count
* 2 + 1;
469 /* Now compute how many bytes an out of line sequence would take. */
470 /* A relaxed jsr will be three bytes. */
473 /* If there are outgoing arguments, then we will need a stack
474 pointer adjustment after the call to the prologue, two
476 outline_count
+= (outgoing_args_size
== 0 ? 0 : 2);
478 /* If there is some local frame to allocate, it will need to be
479 done before the call to the prologue, two more bytes. */
480 if (get_frame_size () != 0)
483 /* Now account for the epilogue, multiply the base count by two,
484 then deal with optimizing away the rts instruction. */
485 outline_count
= outline_count
* 2 + 1;
487 if (get_frame_size () == 0 && outgoing_args_size
== 0)
490 /* If an out of line prologue is smaller, use it. */
491 if (inline_count
> outline_count
)
492 return size
+ outgoing_args_size
+ 16;
496 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
498 if ((regs_ever_live
[i
] && !call_used_regs
[i
] && ! fixed_regs
[i
])
499 || (i
== FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
503 return (size
+ outgoing_args_size
);
506 /* Expand the prologue into RTL. */
510 unsigned int size
= total_frame_size ();
511 unsigned int outgoing_args_size
= current_function_outgoing_args_size
;
514 zero_areg
= NULL_RTX
;
515 zero_dreg
= NULL_RTX
;
517 /* If optimizing, see if we should do an out of line prologue/epilogue
520 We don't support out of line prologues if the current function
521 needs a context or frame pointer. */
522 if (optimize
&& !current_function_needs_context
&& !frame_pointer_needed
)
524 int inline_count
, outline_count
, areg_count
;
526 /* We need to end the current sequence so that count_tst_insns can
527 look at all the insns in this function. Normally this would be
528 unsafe, but it's OK in the prologue/epilogue expanders. */
531 /* Get a count of the number of tst insns which use address
532 registers (it's not profitable to try and improve tst insns
533 which use data registers). */
534 count_tst_insns (&areg_count
);
536 /* Now start a new sequence. */
539 /* Compute how many bytes an inline prologue would take.
541 Each address register store takes two bytes, each data register
542 store takes three bytes. */
544 if (regs_ever_live
[5])
546 if (regs_ever_live
[6])
548 if (regs_ever_live
[2])
550 if (regs_ever_live
[3])
553 /* If this function has any stack, then the stack adjustment
554 will take two (or more) bytes. */
555 if (size
|| outgoing_args_size
556 || regs_ever_live
[5] || regs_ever_live
[6]
557 || regs_ever_live
[2] || regs_ever_live
[3])
560 /* Multiply the current count by two and add one to account for the
562 inline_count
= inline_count
* 2 + 1;
564 /* Now compute how many bytes an out of line sequence would take. */
565 /* A relaxed jsr will be three bytes. */
568 /* If there are outgoing arguments, then we will need a stack
569 pointer adjustment after the call to the prologue, two
571 outline_count
+= (outgoing_args_size
== 0 ? 0 : 2);
573 /* If there is some local frame to allocate, it will need to be
574 done before the call to the prologue, two more bytes. */
575 if (get_frame_size () != 0)
578 /* Now account for the epilogue, multiply the base count by two,
579 then deal with optimizing away the rts instruction. */
580 outline_count
= outline_count
* 2 + 1;
582 if (get_frame_size () == 0 && outgoing_args_size
== 0)
585 /* If an out of line prologue is smaller, use it. */
586 if (inline_count
> outline_count
)
588 if (get_frame_size () != 0)
589 emit_insn (gen_addpsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
590 GEN_INT (-size
+ outgoing_args_size
+ 16)));
591 emit_insn (gen_outline_prologue_call ());
593 if (outgoing_args_size
)
594 emit_insn (gen_addpsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
595 GEN_INT (-outgoing_args_size
)));
597 out_of_line_epilogue
= 1;
599 /* Determine if it is profitable to put the value zero into a register
600 for the entire function. If so, set ZERO_DREG and ZERO_AREG. */
602 /* First see if we could load the value into a data register
603 since that's the most efficient way. */
605 && (!regs_ever_live
[2] || !regs_ever_live
[3]))
607 if (!regs_ever_live
[2])
609 regs_ever_live
[2] = 1;
610 zero_dreg
= gen_rtx_REG (HImode
, 2);
612 if (!regs_ever_live
[3])
614 regs_ever_live
[3] = 1;
615 zero_dreg
= gen_rtx_REG (HImode
, 3);
619 /* Now see if we could load the value into an address register. */
620 if (zero_dreg
== NULL_RTX
622 && (!regs_ever_live
[5] || !regs_ever_live
[6]))
624 if (!regs_ever_live
[5])
626 regs_ever_live
[5] = 1;
627 zero_areg
= gen_rtx_REG (HImode
, 5);
629 if (!regs_ever_live
[6])
631 regs_ever_live
[6] = 1;
632 zero_areg
= gen_rtx_REG (HImode
, 6);
637 emit_move_insn (zero_dreg
, const0_rtx
);
640 emit_move_insn (zero_areg
, const0_rtx
);
646 out_of_line_epilogue
= 0;
648 /* Temporarily stuff the static chain onto the stack so we can
649 use a0 as a scratch register during the prologue. */
650 if (current_function_needs_context
)
652 emit_insn (gen_addpsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
654 emit_move_insn (gen_rtx_MEM (PSImode
, stack_pointer_rtx
),
655 gen_rtx_REG (PSImode
, STATIC_CHAIN_REGNUM
));
658 if (frame_pointer_needed
)
660 /* Store a2 into a0 temporarily. */
661 emit_move_insn (gen_rtx_REG (PSImode
, 4), frame_pointer_rtx
);
663 /* Set up the frame pointer. */
664 emit_move_insn (frame_pointer_rtx
, stack_pointer_rtx
);
667 /* Make any necessary space for the saved registers and local frame. */
669 emit_insn (gen_addpsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
672 /* Save the callee saved registers. They're saved into the top
673 of the frame, using the stack pointer. */
674 for (i
= 0, offset
= outgoing_args_size
;
675 i
< FIRST_PSEUDO_REGISTER
; i
++)
677 if ((regs_ever_live
[i
] && !call_used_regs
[i
] && ! fixed_regs
[i
])
678 || (i
== FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
682 /* If we're saving the frame pointer, then it will be found in
684 regno
= (i
== FRAME_POINTER_REGNUM
&& frame_pointer_needed
) ? 4 : i
;
686 emit_move_insn (gen_rtx_MEM (PSImode
,
687 plus_constant (stack_pointer_rtx
,
689 gen_rtx_REG (PSImode
, regno
));
694 /* Now put the static chain back where the rest of the function
695 expects to find it. */
696 if (current_function_needs_context
)
698 emit_move_insn (gen_rtx_REG (PSImode
, STATIC_CHAIN_REGNUM
),
699 gen_rtx (MEM
, PSImode
,
700 gen_rtx_PLUS (PSImode
, stack_pointer_rtx
,
705 /* Expand the epilogue into RTL. */
710 unsigned int outgoing_args_size
= current_function_outgoing_args_size
;
711 int offset
, i
, temp_regno
;
714 size
= total_frame_size ();
716 if (DECL_RESULT (current_function_decl
)
717 && DECL_RTL (DECL_RESULT (current_function_decl
))
718 && REG_P (DECL_RTL (DECL_RESULT (current_function_decl
))))
719 temp_regno
= (REGNO (DECL_RTL (DECL_RESULT (current_function_decl
))) == 4
724 /* Emit an out of line epilogue sequence if it's profitable to do so. */
725 if (out_of_line_epilogue
)
727 /* If there were no outgoing arguments and no local frame, then
728 we will be able to omit the rts at the end of this function,
729 so just jump to the epilogue_noreturn routine. */
730 if (get_frame_size () == 0 && outgoing_args_size
== 0)
732 emit_jump_insn (gen_outline_epilogue_jump ());
736 if (outgoing_args_size
)
737 emit_insn (gen_addpsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
738 GEN_INT (outgoing_args_size
)));
741 emit_insn (gen_outline_epilogue_call_d0 ());
742 else if (temp_regno
== 4)
743 emit_insn (gen_outline_epilogue_call_a0 ());
745 if (get_frame_size () != 0)
746 emit_insn (gen_addpsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
747 GEN_INT (size
- outgoing_args_size
- 16)));
748 emit_jump_insn (gen_return_internal ());
752 /* Registers are restored from the frame pointer if we have one,
753 else they're restored from the stack pointer. Figure out
754 the appropriate offset to the register save area for both cases. */
755 if (frame_pointer_needed
)
757 basereg
= frame_pointer_rtx
;
758 offset
= -(size
- outgoing_args_size
);
762 basereg
= stack_pointer_rtx
;
763 offset
= outgoing_args_size
;
766 /* Restore each register. */
767 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
769 if ((regs_ever_live
[i
] && !call_used_regs
[i
] && ! fixed_regs
[i
])
770 || (i
== FRAME_POINTER_REGNUM
&& frame_pointer_needed
))
774 /* Restore the frame pointer (if it exists) into a temporary
776 regno
= ((i
== FRAME_POINTER_REGNUM
&& frame_pointer_needed
)
779 emit_move_insn (gen_rtx_REG (PSImode
, regno
),
780 gen_rtx_MEM (PSImode
,
781 plus_constant (basereg
, offset
)));
786 if (frame_pointer_needed
)
788 /* Deallocate this frame's stack. */
789 emit_move_insn (stack_pointer_rtx
, frame_pointer_rtx
);
790 /* Restore the old frame pointer. */
791 emit_move_insn (frame_pointer_rtx
, gen_rtx_REG (PSImode
, temp_regno
));
795 /* Deallocate this function's stack. */
796 emit_insn (gen_addpsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
800 /* If we had to allocate a slot to save the context pointer,
801 then it must be deallocated here. */
802 if (current_function_needs_context
)
803 emit_insn (gen_addpsi3 (stack_pointer_rtx
, stack_pointer_rtx
, GEN_INT (4)));
805 /* Emit the return insn, if this function had no stack, then we
806 can use the standard return (which allows more optimizations),
807 else we have to use the special one which inhibits optimizations. */
808 if (size
== 0 && !current_function_needs_context
)
809 emit_jump_insn (gen_return ());
811 emit_jump_insn (gen_return_internal ());
814 /* Update the condition code from the insn. */
817 notice_update_cc (body
, insn
)
821 switch (get_attr_cc (insn
))
824 /* Insn does not affect CC at all. */
828 /* Insn does not change CC, but the 0'th operand has been changed. */
829 if (cc_status
.value1
!= 0
830 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
831 cc_status
.value1
= 0;
835 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
836 V,C is in an unusable state. */
838 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
839 cc_status
.value1
= recog_data
.operand
[0];
843 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
844 C is in an unusable state. */
846 cc_status
.flags
|= CC_NO_CARRY
;
847 cc_status
.value1
= recog_data
.operand
[0];
851 /* The insn is a compare instruction. */
853 cc_status
.value1
= SET_SRC (body
);
857 /* Insn doesn't leave CC in a usable state. */
867 /* Return true if OP is a valid call operand. Valid call operands
868 are SYMBOL_REFs and REGs. */
870 call_address_operand (op
, mode
)
872 enum machine_mode mode ATTRIBUTE_UNUSED
;
874 return (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == REG
);
877 /* Return true if OP is a memory operand with a constant address.
878 A special PSImode move pattern uses this predicate. */
880 constant_memory_operand (op
, mode
)
882 enum machine_mode mode ATTRIBUTE_UNUSED
;
884 return GET_CODE (op
) == MEM
&& CONSTANT_ADDRESS_P (XEXP (op
, 0));
887 /* Return true if OP is valid for a psi mode truncation operand.
888 It must either be a memory operand which is valid for a PSImode
889 address, or if it is not a memory operand at all. */
891 psimode_truncation_operand (op
, mode
)
893 enum machine_mode mode
;
895 return (general_operand (op
, mode
)
896 && (GET_CODE (op
) != MEM
897 || memory_address_p (PSImode
, XEXP (op
, 0))));
900 /* What (if any) secondary registers are needed to move IN with mode
901 MODE into a register from in register class CLASS.
903 We might be able to simplify this. */
905 secondary_reload_class (class, mode
, in
, input
)
906 enum reg_class
class;
907 enum machine_mode mode
;
911 /* Memory loads less than a full word wide can't have an
912 address or stack pointer destination. They must use
913 a data register as an intermediate register. */
915 && GET_CODE (in
) == MEM
917 && class == ADDRESS_REGS
)
920 /* Address register stores which are not PSImode need a scratch register. */
922 && GET_CODE (in
) == MEM
924 && class == ADDRESS_REGS
)
927 /* Otherwise assume no secondary reloads are needed. */
934 We devote a fair bit of code to getting efficient shifts since we can only
935 shift one bit at a time, and each single bit shift may take multiple
938 The basic shift methods:
940 * loop shifts -- emit a loop using one (or two on H8/S) bit shifts;
941 this is the default. SHIFT_LOOP
943 * inlined shifts -- emit straight line code for the shift; this is
944 used when a straight line shift is about the same size or smaller
945 than a loop. We allow the inline version to be slightly longer in
946 some cases as it saves a register. SHIFT_INLINE
948 * There other oddballs. Not worth explaining. SHIFT_SPECIAL
955 5-7 If ashift, then multiply, else loop.
957 8-14 - If ashift, then multiply, if lshiftrt, then divide, else loop.
958 15 - rotate the bit we want into the carry, clear the destination,
959 (use mov 0,dst, not sub as sub will clobber the carry), then
962 Don't Panic, it's not nearly as bad as the H8 shifting code!!! */
965 nshift_operator (x
, mode
)
967 enum machine_mode mode ATTRIBUTE_UNUSED
;
969 switch (GET_CODE (x
))
981 /* Called from the .md file to emit code to do shifts.
982 Returns a boolean indicating success
983 (currently this is always TRUE). */
986 expand_a_shift (mode
, code
, operands
)
987 enum machine_mode mode
;
991 emit_move_insn (operands
[0], operands
[1]);
993 /* need a loop to get all the bits we want - we generate the
994 code at emit time, but need to allocate a scratch reg now */
996 emit_insn (gen_rtx_PARALLEL
999 gen_rtx_SET (VOIDmode
, operands
[0],
1000 gen_rtx (code
, mode
,
1001 operands
[0], operands
[2])),
1002 gen_rtx_CLOBBER (VOIDmode
,
1003 gen_rtx_SCRATCH (HImode
)))));
1008 /* Shift algorithm determination.
1010 There are various ways of doing a shift:
1011 SHIFT_INLINE: If the amount is small enough, just generate as many one-bit
1013 SHIFT_SPECIAL: Hand crafted assembler.
1014 SHIFT_LOOP: If the above methods fail, just loop. */
1024 /* Symbols of the various shifts which can be used as indices. */
1028 SHIFT_ASHIFT
, SHIFT_LSHIFTRT
, SHIFT_ASHIFTRT
1031 /* Symbols of the various modes which can be used as indices. */
1038 /* For single bit shift insns, record assembler and what bits of the
1039 condition code are valid afterwards (represented as various CC_FOO
1040 bits, 0 means CC isn't left in a usable state). */
1044 const char *assembler
;
1048 /* Assembler instruction shift table.
1050 These tables are used to look up the basic shifts.
1051 They are indexed by cpu, shift_type, and mode.
1054 static const struct shift_insn shift_one
[3][3] =
1058 { "add\t%0,%0", CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
},
1060 /* SHIFT_LSHIFTRT */
1062 { "lsr\t%0", CC_NO_CARRY
},
1064 /* SHIFT_ASHIFTRT */
1066 { "asr\t%0", CC_NO_CARRY
},
1070 static enum shift_alg get_shift_alg
PARAMS ((enum shift_type
,
1071 enum machine_mode
, int,
1072 const char **, int *));
1074 /* Given CPU, MODE, SHIFT_TYPE, and shift count COUNT, determine the best
1075 algorithm for doing the shift. The assembler code is stored in ASSEMBLER.
1076 We don't achieve maximum efficiency in all cases, but the hooks are here
1079 For now we just use lots of switch statements. Since we don't even come
1080 close to supporting all the cases, this is simplest. If this function ever
1081 gets too big, perhaps resort to a more table based lookup. Of course,
1082 at this point you may just wish to do it all in rtl. */
1084 static enum shift_alg
1085 get_shift_alg (shift_type
, mode
, count
, assembler_p
, cc_valid_p
)
1086 enum shift_type shift_type
;
1087 enum machine_mode mode
;
1089 const char **assembler_p
;
1092 /* The default is to loop. */
1093 enum shift_alg alg
= SHIFT_LOOP
;
1094 enum shift_mode shift_mode
;
1096 /* We don't handle negative shifts or shifts greater than the word size,
1097 they should have been handled already. */
1099 if (count
< 0 || count
> GET_MODE_BITSIZE (mode
))
1105 shift_mode
= HIshift
;
1111 /* Assume either SHIFT_LOOP or SHIFT_INLINE.
1112 It is up to the caller to know that looping clobbers cc. */
1113 *assembler_p
= shift_one
[shift_type
][shift_mode
].assembler
;
1114 *cc_valid_p
= shift_one
[shift_type
][shift_mode
].cc_valid
;
1116 /* Now look for cases we want to optimize. */
1122 return SHIFT_INLINE
;
1123 else if (count
< 15 && shift_type
!= SHIFT_ASHIFTRT
)
1128 if (shift_type
== SHIFT_ASHIFT
)
1129 *assembler_p
= "mov 32,%4\n\tmul %4,%0";
1130 else if (shift_type
== SHIFT_LSHIFTRT
)
1132 = "sub %4,%4\n\tmov %4,mdr\n\tmov 32,%4\n\tdivu %4,%0";
1133 *cc_valid_p
= CC_NO_CARRY
;
1134 return SHIFT_SPECIAL
;
1136 if (shift_type
== SHIFT_ASHIFT
)
1137 *assembler_p
= "mov 64,%4\n\tmul %4,%0";
1138 else if (shift_type
== SHIFT_LSHIFTRT
)
1140 = "sub %4,%4\n\tmov %4,mdr\n\tmov 64,%4\n\tdivu %4,%0";
1141 *cc_valid_p
= CC_NO_CARRY
;
1142 return SHIFT_SPECIAL
;
1144 if (shift_type
== SHIFT_ASHIFT
)
1145 *assembler_p
= "mov 128,%4\n\tmul %4,%0";
1146 else if (shift_type
== SHIFT_LSHIFTRT
)
1148 = "sub %4,%4\n\tmov %4,mdr\n\tmov 128,%4\n\tdivu %4,%0";
1149 *cc_valid_p
= CC_NO_CARRY
;
1150 return SHIFT_SPECIAL
;
1152 if (shift_type
== SHIFT_ASHIFT
)
1153 *assembler_p
= "mov 256,%4\n\tmul %4,%0";
1154 else if (shift_type
== SHIFT_LSHIFTRT
)
1156 = "sub %4,%4\n\tmov %4,mdr\n\tmov 256,%4\n\tdivu %4,%0";
1157 *cc_valid_p
= CC_NO_CARRY
;
1158 return SHIFT_SPECIAL
;
1160 if (shift_type
== SHIFT_ASHIFT
)
1161 *assembler_p
= "mov 512,%4\n\tmul %4,%0";
1162 else if (shift_type
== SHIFT_LSHIFTRT
)
1164 = "sub %4,%4\n\tmov %4,mdr\n\tmov 512,%4\n\tdivu %4,%0";
1165 *cc_valid_p
= CC_NO_CARRY
;
1166 return SHIFT_SPECIAL
;
1168 if (shift_type
== SHIFT_ASHIFT
)
1169 *assembler_p
= "mov 1024,%4\n\tmul %4,%0";
1170 else if (shift_type
== SHIFT_LSHIFTRT
)
1172 = "sub %4,%4\n\tmov %4,mdr\n\tmov 1024,%4\n\tdivu %4,%0";
1173 *cc_valid_p
= CC_NO_CARRY
;
1174 return SHIFT_SPECIAL
;
1176 if (shift_type
== SHIFT_ASHIFT
)
1177 *assembler_p
= "mov 2048,%4\n\tmul %4,%0";
1178 else if (shift_type
== SHIFT_LSHIFTRT
)
1180 = "sub %4,%4\n\tmov %4,mdr\n\tmov 2048,%4\n\tdivu %4,%0";
1181 *cc_valid_p
= CC_NO_CARRY
;
1182 return SHIFT_SPECIAL
;
1184 if (shift_type
== SHIFT_ASHIFT
)
1185 *assembler_p
= "mov 4096,%4\n\tmul %4,%0";
1186 else if (shift_type
== SHIFT_LSHIFTRT
)
1188 = "sub %4,%4\n\tmov %4,mdr\n\tmov 4096,%4\n\tdivu %4,%0";
1189 *cc_valid_p
= CC_NO_CARRY
;
1190 return SHIFT_SPECIAL
;
1192 if (shift_type
== SHIFT_ASHIFT
)
1193 *assembler_p
= "mov 8192,%4\n\tmul %4,%0";
1194 else if (shift_type
== SHIFT_LSHIFTRT
)
1196 = "sub %4,%4\n\tmov %4,mdr\n\tmov 8192,%4\n\tdivu %4,%0";
1197 *cc_valid_p
= CC_NO_CARRY
;
1198 return SHIFT_SPECIAL
;
1200 if (shift_type
== SHIFT_ASHIFT
)
1201 *assembler_p
= "mov 16384,%4\n\tmul %4,%0";
1202 else if (shift_type
== SHIFT_LSHIFTRT
)
1204 = "sub %4,%4\n\tmov %4,mdr\n\tmov 16384,%4\n\tdivu %4,%0";
1205 *cc_valid_p
= CC_NO_CARRY
;
1206 return SHIFT_SPECIAL
;
1209 else if (count
== 15)
1211 if (shift_type
== SHIFT_ASHIFTRT
)
1213 *assembler_p
= "add\t%0,%0\n\tsubc\t%0,%0\n";
1214 *cc_valid_p
= CC_NO_CARRY
;
1215 return SHIFT_SPECIAL
;
1217 if (shift_type
== SHIFT_LSHIFTRT
)
1219 *assembler_p
= "add\t%0,%0\n\tmov 0,%0\n\trol %0\n";
1220 *cc_valid_p
= CC_NO_CARRY
;
1221 return SHIFT_SPECIAL
;
1223 if (shift_type
== SHIFT_ASHIFT
)
1225 *assembler_p
= "ror\t%0\n\tmov 0,%0\n\tror %0\n";
1226 *cc_valid_p
= CC_NO_CARRY
;
1227 return SHIFT_SPECIAL
;
1239 /* Emit the assembler code for doing shifts. */
1242 emit_a_shift (insn
, operands
)
1243 rtx insn ATTRIBUTE_UNUSED
;
1246 static int loopend_lab
;
1247 const char *assembler
;
1249 rtx shift
= operands
[3];
1250 enum machine_mode mode
= GET_MODE (shift
);
1251 enum rtx_code code
= GET_CODE (shift
);
1252 enum shift_type shift_type
;
1253 enum shift_mode shift_mode
;
1260 shift_mode
= HIshift
;
1269 shift_type
= SHIFT_ASHIFTRT
;
1272 shift_type
= SHIFT_LSHIFTRT
;
1275 shift_type
= SHIFT_ASHIFT
;
1281 if (GET_CODE (operands
[2]) != CONST_INT
)
1283 /* Indexing by reg, so have to loop and test at top */
1284 output_asm_insn ("mov %2,%4", operands
);
1285 output_asm_insn ("cmp 0,%4", operands
);
1286 fprintf (asm_out_file
, "\tble .Lle%d\n", loopend_lab
);
1288 /* Get the assembler code to do one shift. */
1289 get_shift_alg (shift_type
, mode
, 1, &assembler
, &cc_valid
);
1293 int n
= INTVAL (operands
[2]);
1296 /* If the count is negative, make it 0. */
1299 /* If the count is too big, truncate it.
1300 ANSI says shifts of GET_MODE_BITSIZE are undefined - we choose to
1301 do the intuitive thing. */
1302 else if (n
> GET_MODE_BITSIZE (mode
))
1303 n
= GET_MODE_BITSIZE (mode
);
1305 alg
= get_shift_alg (shift_type
, mode
, n
, &assembler
, &cc_valid
);
1311 /* Emit one bit shifts. */
1314 output_asm_insn (assembler
, operands
);
1318 /* Keep track of CC. */
1321 cc_status
.value1
= operands
[0];
1322 cc_status
.flags
|= cc_valid
;
1327 output_asm_insn (assembler
, operands
);
1329 /* Keep track of CC. */
1332 cc_status
.value1
= operands
[0];
1333 cc_status
.flags
|= cc_valid
;
1339 fprintf (asm_out_file
, "\tmov %d,%s\n", n
,
1340 reg_names
[REGNO (operands
[4])]);
1341 fprintf (asm_out_file
, ".Llt%d:\n", loopend_lab
);
1342 output_asm_insn (assembler
, operands
);
1343 output_asm_insn ("add -1,%4", operands
);
1344 fprintf (asm_out_file
, "\tbne .Llt%d\n", loopend_lab
);
1349 fprintf (asm_out_file
, ".Llt%d:\n", loopend_lab
);
1350 output_asm_insn (assembler
, operands
);
1351 output_asm_insn ("add -1,%4", operands
);
1352 fprintf (asm_out_file
, "\tbne .Llt%d\n", loopend_lab
);
1353 fprintf (asm_out_file
, ".Lle%d:\n", loopend_lab
);
1358 /* Return an RTX to represent where a value with mode MODE will be returned
1359 from a function. If the result is 0, the argument is pushed. */
1362 function_arg (cum
, mode
, type
, named
)
1363 CUMULATIVE_ARGS
*cum
;
1364 enum machine_mode mode
;
1371 /* We only support using 2 data registers as argument registers. */
1374 /* Only pass named arguments in registers. */
1378 /* Figure out the size of the object to be passed. We lie and claim
1379 PSImode values are only two bytes since they fit in a single
1381 if (mode
== BLKmode
)
1382 size
= int_size_in_bytes (type
);
1383 else if (mode
== PSImode
)
1386 size
= GET_MODE_SIZE (mode
);
1388 /* Figure out the alignment of the object to be passed. */
1391 cum
->nbytes
= (cum
->nbytes
+ 1) & ~1;
1393 /* Don't pass this arg via a register if all the argument registers
1395 if (cum
->nbytes
+ size
> nregs
* UNITS_PER_WORD
)
1398 switch (cum
->nbytes
/ UNITS_PER_WORD
)
1401 result
= gen_rtx_REG (mode
, 0);
1404 result
= gen_rtx_REG (mode
, 1);
1413 /* Return the number of registers to use for an argument passed partially
1414 in registers and partially in memory. */
1417 function_arg_partial_nregs (cum
, mode
, type
, named
)
1418 CUMULATIVE_ARGS
*cum
;
1419 enum machine_mode mode
;
1425 /* We only support using 2 data registers as argument registers. */
1429 /* Only pass named arguments in registers. */
1433 /* Figure out the size of the object to be passed. */
1434 if (mode
== BLKmode
)
1435 size
= int_size_in_bytes (type
);
1436 else if (mode
== PSImode
)
1439 size
= GET_MODE_SIZE (mode
);
1441 /* Figure out the alignment of the object to be passed. */
1444 cum
->nbytes
= (cum
->nbytes
+ 1) & ~1;
1446 /* Don't pass this arg via a register if all the argument registers
1448 if (cum
->nbytes
> nregs
* UNITS_PER_WORD
)
1451 if (cum
->nbytes
+ size
<= nregs
* UNITS_PER_WORD
)
1454 /* Don't pass this arg via a register if it would be split between
1455 registers and memory. */
1456 if (type
== NULL_TREE
1457 && cum
->nbytes
+ size
> nregs
* UNITS_PER_WORD
)
1460 return (nregs
* UNITS_PER_WORD
- cum
->nbytes
) / UNITS_PER_WORD
;
1464 mn10200_va_arg (valist
, type
)
1467 HOST_WIDE_INT align
, rsize
;
1470 /* Compute the rounded size of the type. */
1471 align
= PARM_BOUNDARY
/ BITS_PER_UNIT
;
1472 rsize
= (((int_size_in_bytes (type
) + align
- 1) / align
) * align
);
1474 t
= build (POSTINCREMENT_EXPR
, TREE_TYPE (valist
), valist
,
1475 build_int_2 ((rsize
> 8 ? 4 : rsize
), 0));
1476 TREE_SIDE_EFFECTS (t
) = 1;
1478 ptr
= build_pointer_type (type
);
1480 /* "Large" types are passed by reference. */
1483 pptr
= build_pointer_type (ptr
);
1484 t
= build1 (NOP_EXPR
, pptr
, t
);
1485 TREE_SIDE_EFFECTS (t
) = 1;
1487 t
= build1 (INDIRECT_REF
, ptr
, t
);
1488 TREE_SIDE_EFFECTS (t
) = 1;
1492 t
= build1 (NOP_EXPR
, ptr
, t
);
1493 TREE_SIDE_EFFECTS (t
) = 1;
1497 return force_reg (Pmode
, expand_expr (t
, NULL_RTX
, Pmode
, EXPAND_NORMAL
));
1501 output_tst (operand
, insn
)
1508 /* Only tst insns using address registers can be optimized. */
1509 if (REGNO_REG_CLASS (REGNO (operand
)) != ADDRESS_REGS
)
1512 /* If testing an address register against zero, we can do better if
1513 we know there's a register already holding the value zero. First
1514 see if a global register has been set to zero, else we do a search
1515 for a register holding zero, if both of those fail, then we use a
1516 compare against zero. */
1517 if (zero_dreg
|| zero_areg
)
1520 xoperands
[0] = operand
;
1521 xoperands
[1] = zero_dreg
? zero_dreg
: zero_areg
;
1523 output_asm_insn ("cmp %1,%0", xoperands
);
1527 /* We can save a byte if we can find a register which has the value
1529 temp
= PREV_INSN (insn
);
1534 /* We allow the search to go through call insns. We record
1535 the fact that we've past a CALL_INSN and reject matches which
1536 use call clobbered registers. */
1537 if (GET_CODE (temp
) == CODE_LABEL
1538 || GET_CODE (temp
) == JUMP_INSN
1539 || GET_CODE (temp
) == BARRIER
)
1542 if (GET_CODE (temp
) == CALL_INSN
)
1545 if (GET_CODE (temp
) == NOTE
)
1547 temp
= PREV_INSN (temp
);
1551 /* It must be an insn, see if it is a simple set. */
1552 set
= single_set (temp
);
1555 temp
= PREV_INSN (temp
);
1559 /* Are we setting a register to zero?
1561 If it's a call clobbered register, have we past a call? */
1562 if (REG_P (SET_DEST (set
))
1563 && SET_SRC (set
) == CONST0_RTX (GET_MODE (SET_DEST (set
)))
1564 && !reg_set_between_p (SET_DEST (set
), temp
, insn
)
1566 || !call_used_regs
[REGNO (SET_DEST (set
))]))
1569 xoperands
[0] = operand
;
1570 xoperands
[1] = SET_DEST (set
);
1572 output_asm_insn ("cmp %1,%0", xoperands
);
1575 temp
= PREV_INSN (temp
);
1580 /* Return nonzero if OP is a valid operand for a {zero,sign}_extendpsisi
1583 It accepts anything that is a general operand or the sum of the
1584 stack pointer and a general operand. */
1586 extendpsi_operand (op
, mode
)
1588 enum machine_mode mode
;
1590 return (general_operand (op
, mode
)
1591 || (GET_CODE (op
) == PLUS
1592 && XEXP (op
, 0) == stack_pointer_rtx
1593 && general_operand (XEXP (op
, 1), VOIDmode
)));