1 ;; GCC machine description for Matsushita MN10300
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 ;; 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
5 ;; Contributed by Jeff Law (law@cygnus.com).
7 ;; This file is part of GCC.
9 ;; GCC is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; GCC is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GCC; see the file COPYING3. If not see
21 ;; <http://www.gnu.org/licenses/>.
23 ;; The original PO technology requires these to be ordered by speed,
24 ;; so that assigner will pick the fastest.
26 ;; See file "rtl.def" for documentation on define_insn, match_*, et. al.
45 (include "predicates.md")
46 (include "constraints.md")
48 ;; Processor type. This attribute must exactly match the processor_type
49 ;; enumeration in mn10300.h.
50 (define_attr "cpu" "mn10300,am33,am33_2,am34"
51 (const (symbol_ref "(enum attr_cpu) mn10300_tune_cpu")))
53 ;; Used to control the "enabled" attribute on a per-instruction basis.
54 (define_attr "isa" "base,am33,am33_2,am34"
55 (const_string "base"))
57 (define_attr "enabled" ""
58 (cond [(eq_attr "isa" "base")
61 (and (eq_attr "isa" "am33")
62 (ne (symbol_ref "TARGET_AM33") (const_int 0)))
65 (and (eq_attr "isa" "am33_2")
66 (ne (symbol_ref "TARGET_AM33_2") (const_int 0)))
69 (and (eq_attr "isa" "am34")
70 (ne (symbol_ref "TARGET_AM34") (const_int 0)))
76 (define_mode_iterator INT [QI HI SI])
79 ;; ----------------------------------------------------------------------
80 ;; Pipeline description.
81 ;; ----------------------------------------------------------------------
83 ;; The AM33 only has a single pipeline. It has five stages (fetch,
84 ;; decode, execute, memory access, writeback) each of which normally
85 ;; takes a single CPU clock cycle.
87 ;; The timings attribute consists of two numbers, the first is the
88 ;; throughput, which is the number of cycles the instruction takes
89 ;; to execute and generate a result. The second is the latency
90 ;; which is the effective number of cycles the instruction takes to
91 ;; execute if its result is used by the following instruction. The
92 ;; latency is always greater than or equal to the throughput.
93 ;; These values were taken from the Appendix of the "MN103E Series
94 ;; Instruction Manual" and the timings for the AM34.
96 ;; Note - it would be nice to use strings rather than integers for
97 ;; the possible values of this attribute, so that we can have the
98 ;; gcc build mechanism check for values that are not supported by
99 ;; the reservations below. But this will not work because the code
100 ;; in mn10300_adjust_sched_cost() needs integers not strings.
102 (define_attr "timings" "" (const_int 11))
104 (define_automaton "pipelining")
105 (define_cpu_unit "throughput" "pipelining")
107 (define_insn_reservation "throughput__1_latency__1" 1
108 (eq_attr "timings" "11") "throughput")
109 (define_insn_reservation "throughput__1_latency__2" 2
110 (eq_attr "timings" "12") "throughput,nothing")
111 (define_insn_reservation "throughput__1_latency__3" 3
112 (eq_attr "timings" "13") "throughput,nothing*2")
113 (define_insn_reservation "throughput__1_latency__4" 4
114 (eq_attr "timings" "14") "throughput,nothing*3")
115 (define_insn_reservation "throughput__2_latency__2" 2
116 (eq_attr "timings" "22") "throughput*2")
117 (define_insn_reservation "throughput__2_latency__3" 3
118 (eq_attr "timings" "23") "throughput*2,nothing")
119 (define_insn_reservation "throughput__2_latency__4" 4
120 (eq_attr "timings" "24") "throughput*2,nothing*2")
121 (define_insn_reservation "throughput__2_latency__5" 5
122 (eq_attr "timings" "25") "throughput*2,nothing*3")
123 (define_insn_reservation "throughput__3_latency__3" 3
124 (eq_attr "timings" "33") "throughput*3")
125 (define_insn_reservation "throughput__3_latency__7" 7
126 (eq_attr "timings" "37") "throughput*3,nothing*4")
127 (define_insn_reservation "throughput__4_latency__4" 4
128 (eq_attr "timings" "44") "throughput*4")
129 (define_insn_reservation "throughput__4_latency__7" 7
130 (eq_attr "timings" "47") "throughput*4,nothing*3")
131 (define_insn_reservation "throughput__4_latency__8" 8
132 (eq_attr "timings" "48") "throughput*4,nothing*4")
133 (define_insn_reservation "throughput__5_latency__5" 5
134 (eq_attr "timings" "55") "throughput*5")
135 (define_insn_reservation "throughput__6_latency__6" 6
136 (eq_attr "timings" "66") "throughput*6")
137 (define_insn_reservation "throughput__7_latency__7" 7
138 (eq_attr "timings" "77") "throughput*7")
139 (define_insn_reservation "throughput__7_latency__8" 8
140 (eq_attr "timings" "78") "throughput*7,nothing")
141 (define_insn_reservation "throughput__8_latency__8" 8
142 (eq_attr "timings" "88") "throughput*8")
143 (define_insn_reservation "throughput__9_latency__9" 9
144 (eq_attr "timings" "99") "throughput*9")
145 (define_insn_reservation "throughput__8_latency_14" 14
146 (eq_attr "timings" "814") "throughput*8,nothing*6")
147 (define_insn_reservation "throughput__9_latency_10" 10
148 (eq_attr "timings" "910") "throughput*9,nothing")
149 (define_insn_reservation "throughput_10_latency_10" 10
150 (eq_attr "timings" "1010") "throughput*10")
151 (define_insn_reservation "throughput_12_latency_16" 16
152 (eq_attr "timings" "1216") "throughput*12,nothing*4")
153 (define_insn_reservation "throughput_13_latency_13" 13
154 (eq_attr "timings" "1313") "throughput*13")
155 (define_insn_reservation "throughput_14_latency_14" 14
156 (eq_attr "timings" "1414") "throughput*14")
157 (define_insn_reservation "throughput_13_latency_17" 17
158 (eq_attr "timings" "1317") "throughput*13,nothing*4")
159 (define_insn_reservation "throughput_23_latency_27" 27
160 (eq_attr "timings" "2327") "throughput*23,nothing*4")
161 (define_insn_reservation "throughput_25_latency_31" 31
162 (eq_attr "timings" "2531") "throughput*25,nothing*6")
163 (define_insn_reservation "throughput_38_latency_39" 39
164 (eq_attr "timings" "3839") "throughput*38,nothing")
165 (define_insn_reservation "throughput_39_latency_40" 40
166 (eq_attr "timings" "3940") "throughput*39,nothing")
167 (define_insn_reservation "throughput_40_latency_40" 40
168 (eq_attr "timings" "4040") "throughput*40")
169 (define_insn_reservation "throughput_41_latency_42" 42
170 (eq_attr "timings" "4142") "throughput*41,nothing")
171 (define_insn_reservation "throughput_42_latency_43" 44
172 (eq_attr "timings" "4243") "throughput*42,nothing")
173 (define_insn_reservation "throughput_43_latency_44" 44
174 (eq_attr "timings" "4344") "throughput*43,nothing")
175 (define_insn_reservation "throughput_45_latency_46" 46
176 (eq_attr "timings" "4546") "throughput*45,nothing")
177 (define_insn_reservation "throughput_47_latency_53" 53
178 (eq_attr "timings" "4753") "throughput*47,nothing*6")
180 ;; Note - the conflict between memory load/store instructions
181 ;; and floating point instructions described in section 1-7-4
182 ;; of Chapter 3 of the MN103E Series Instruction Manual is
183 ;; handled by the mn10300_adjust_sched_cost function.
185 ;; ----------------------------------------------------------------------
187 ;; ----------------------------------------------------------------------
191 (define_expand "movqi"
192 [(set (match_operand:QI 0 "nonimmediate_operand")
193 (match_operand:QI 1 "general_operand"))]
196 /* One of the ops has to be in a register. */
197 if (!register_operand (operand0, QImode)
198 && !register_operand (operand1, QImode))
199 operands[1] = force_reg (QImode, operand1);
202 (define_insn "*movqi_internal"
203 [(set (match_operand:QI 0 "nonimmediate_operand" "=*r,D*r,D*r,D,m")
204 (match_operand:QI 1 "general_operand" " 0,D*r, i,m,D"))]
205 "(register_operand (operands[0], QImode)
206 || register_operand (operands[1], QImode))"
208 switch (which_alternative)
217 return "movbu %1,%0";
222 [(set_attr_alternative "timings"
226 (if_then_else (eq_attr "cpu" "am34")
227 (const_int 13) (const_int 24))
228 (if_then_else (eq_attr "cpu" "am34")
229 (const_int 11) (const_int 22))
235 (define_expand "movhi"
236 [(set (match_operand:HI 0 "nonimmediate_operand")
237 (match_operand:HI 1 "general_operand"))]
240 /* One of the ops has to be in a register. */
241 if (!register_operand (operand1, HImode)
242 && !register_operand (operand0, HImode))
243 operands[1] = force_reg (HImode, operand1);
246 (define_insn "*movhi_internal"
247 [(set (match_operand:HI 0 "nonimmediate_operand" "=*r,D*r,D*r,D,m")
248 (match_operand:HI 1 "general_operand" " 0, i,D*r,m,D"))]
249 "(register_operand (operands[0], HImode)
250 || register_operand (operands[1], HImode))"
252 switch (which_alternative)
257 /* Note that "MOV imm8,An" is already zero-extending, and is 2 bytes.
258 We have "MOV imm16,Dn" at 3 bytes. The only win for the 4 byte
259 movu is for an 8-bit unsigned move into Rn. */
261 && CONST_INT_P (operands[1])
262 && IN_RANGE (INTVAL (operands[1]), 0x80, 0xff)
263 && REGNO_EXTENDED_P (REGNO (operands[0]), 1))
270 return "movhu %1,%0";
275 [(set_attr_alternative "timings"
278 (if_then_else (eq_attr "cpu" "am34")
279 (const_int 11) (const_int 22))
280 (if_then_else (eq_attr "cpu" "am34")
281 (const_int 13) (const_int 24))
282 (if_then_else (eq_attr "cpu" "am34")
283 (const_int 11) (const_int 22))
289 ;; We use this to handle addition of two values when one operand is the
290 ;; stack pointer and the other is a memory reference of some kind. Reload
291 ;; does not handle them correctly without this expander.
292 (define_expand "reload_plus_sp_const"
293 [(set (match_operand:SI 0 "register_operand" "=r")
294 (match_operand:SI 1 "impossible_plus_operand" ""))
295 (clobber (match_operand:SI 2 "register_operand" "=&A"))]
299 rtx dest, scratch, other;
302 scratch = operands[2];
304 other = XEXP (operands[1], 1);
305 if (other == stack_pointer_rtx)
306 other = XEXP (operands[1], 0);
308 if (true_regnum (other) == true_regnum (dest))
310 gcc_assert (true_regnum (scratch) != true_regnum (dest));
311 emit_move_insn (scratch, stack_pointer_rtx);
312 emit_insn (gen_addsi3 (dest, dest, scratch));
314 else if (TARGET_AM33 || REGNO_REG_CLASS (true_regnum (dest)) == ADDRESS_REGS)
316 emit_move_insn (dest, stack_pointer_rtx);
317 if (other == stack_pointer_rtx)
318 emit_insn (gen_addsi3 (dest, dest, dest));
319 else if (other != const0_rtx)
320 emit_insn (gen_addsi3 (dest, dest, other));
324 emit_move_insn (scratch, stack_pointer_rtx);
325 if (other == stack_pointer_rtx)
327 emit_move_insn (dest, scratch);
328 emit_insn (gen_addsi3 (dest, dest, dest));
330 else if (other != const0_rtx)
332 emit_move_insn (dest, other);
333 emit_insn (gen_addsi3 (dest, dest, scratch));
336 emit_move_insn (dest, scratch);
341 (define_insn "pop_pic_reg"
342 [(set (reg:SI PIC_REG)
343 (mem:SI (post_inc:SI (reg:SI SP_REG))))]
346 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
347 (const_int 44) (const_int 33)))]
350 (define_expand "movsi"
351 [(set (match_operand:SI 0 "nonimmediate_operand")
352 (match_operand:SI 1 "general_operand"))]
355 /* One of the ops has to be in a register. */
356 if (!register_operand (operand1, SImode)
357 && !register_operand (operand0, SImode))
358 operands[1] = force_reg (SImode, operand1);
362 if (SYMBOLIC_CONST_P (operands[1]))
364 if (MEM_P (operands[0]))
365 operands[1] = force_reg (Pmode, operands[1]);
368 temp = (!can_create_pseudo_p ()
370 : gen_reg_rtx (Pmode));
371 operands[1] = mn10300_legitimize_pic_address (operands[1], temp);
374 else if (GET_CODE (operands[1]) == CONST
375 && GET_CODE (XEXP (operands[1], 0)) == PLUS
376 && SYMBOLIC_CONST_P (XEXP (XEXP (operands[1], 0), 0)))
378 temp = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
379 temp = mn10300_legitimize_pic_address (XEXP (XEXP (operands[1], 0), 0),
381 operands[1] = expand_binop (SImode, add_optab, temp,
382 XEXP (XEXP (operands[1], 0), 1),
383 (!can_create_pseudo_p ()
385 : gen_reg_rtx (Pmode)),
391 (define_insn "*movsi_internal"
392 [(set (match_operand:SI 0 "nonimmediate_operand"
393 "=r,r,r,m,r, A,*y,*y,*z,*d")
394 (match_operand:SI 1 "general_operand"
395 " 0,i,r,r,m,*y, A, i,*d,*z"))]
396 "register_operand (operands[0], SImode)
397 || register_operand (operands[1], SImode)"
399 switch (which_alternative)
404 /* See movhi for a discussion of sizes for 8-bit movu. Note that the
405 24-bit movu is 6 bytes, which is the same size as the full 32-bit
406 mov form for An and Dn. So again movu is only a win for Rn. */
408 && CONST_INT_P (operands[1])
409 && REGNO_EXTENDED_P (REGNO (operands[0]), 1))
411 HOST_WIDE_INT val = INTVAL (operands[1]);
412 if (IN_RANGE (val, 0x80, 0xff)
413 || IN_RANGE (val, 0x800000, 0xffffff))
417 case 2: /* reg-reg */
418 case 3: /* reg-mem */
419 case 4: /* mem-reg */
423 case 8: /* reg-mdr */
424 case 9: /* mdr-reg */
430 [(set_attr "isa" "*,*,*,*,*,*,*,am33,*,*")
431 (set_attr_alternative "timings"
435 (if_then_else (eq_attr "cpu" "am34")
436 (const_int 11) (const_int 22))
437 (if_then_else (eq_attr "cpu" "am34")
438 (const_int 13) (const_int 24))
439 (if_then_else (eq_attr "cpu" "am34")
440 (const_int 11) (const_int 22))
441 (if_then_else (eq_attr "cpu" "am34")
442 (const_int 13) (const_int 24))
449 (define_expand "movsf"
450 [(set (match_operand:SF 0 "nonimmediate_operand")
451 (match_operand:SF 1 "general_operand"))]
454 /* One of the ops has to be in a register. */
455 if (!register_operand (operand1, SFmode)
456 && !register_operand (operand0, SFmode))
457 operands[1] = force_reg (SFmode, operand1);
460 (define_insn "*movsf_internal"
461 [(set (match_operand:SF 0 "nonimmediate_operand" "=rf,r,f,r,f,r,f,r,m,f,Q")
462 (match_operand:SF 1 "general_operand" " 0,F,F,r,f,f,r,m,r,Q,f"))]
464 && (register_operand (operands[0], SFmode)
465 || register_operand (operands[1], SFmode))"
467 switch (which_alternative)
487 [(set_attr_alternative "timings"
490 (if_then_else (eq_attr "cpu" "am34")
491 (const_int 47) (const_int 25))
493 (if_then_else (eq_attr "cpu" "am34")
494 (const_int 13) (const_int 14))
495 (if_then_else (eq_attr "cpu" "am34")
496 (const_int 13) (const_int 12))
497 (if_then_else (eq_attr "cpu" "am34")
498 (const_int 13) (const_int 14))
499 (if_then_else (eq_attr "cpu" "am34")
500 (const_int 13) (const_int 24))
501 (if_then_else (eq_attr "cpu" "am34")
502 (const_int 13) (const_int 24))
503 (if_then_else (eq_attr "cpu" "am34")
504 (const_int 13) (const_int 24))
505 (if_then_else (eq_attr "cpu" "am34")
506 (const_int 13) (const_int 24))
511 ;; ----------------------------------------------------------------------
513 ;; ----------------------------------------------------------------------
515 (define_expand "addsi3"
516 [(parallel [(set (match_operand:SI 0 "register_operand")
517 (plus:SI (match_operand:SI 1 "register_operand")
518 (match_operand:SI 2 "nonmemory_operand")))
519 (clobber (reg:CC CC_REG))
525 (define_insn "*am33_addsi3"
526 [(set (match_operand:SI 0 "register_operand" "=dx,a,x,a,dax,!*y,!dax")
527 (plus:SI (match_operand:SI 1 "register_operand" "%0,0,0,0,0,0,dax")
528 (match_operand:SI 2 "nonmemory_operand" "J,J,L,L,daxi,i,dax")))
529 (clobber (reg:CC CC_REG))
534 switch (which_alternative)
544 return \"add %2,%0\";
547 enum reg_class src1_class, src2_class, dst_class;
549 src1_class = REGNO_REG_CLASS (true_regnum (operands[1]));
550 src2_class = REGNO_REG_CLASS (true_regnum (operands[2]));
551 dst_class = REGNO_REG_CLASS (true_regnum (operands[0]));
553 /* I'm not sure if this can happen or not. Might as well be prepared
554 and generate the best possible code if it does happen. */
555 if (true_regnum (operands[0]) == true_regnum (operands[1]))
556 return \"add %2,%0\";
557 if (true_regnum (operands[0]) == true_regnum (operands[2]))
558 return \"add %1,%0\";
560 /* Catch cases where no extended register was used. These should be
561 handled just like the mn10300. */
562 if (src1_class != EXTENDED_REGS
563 && src2_class != EXTENDED_REGS
564 && dst_class != EXTENDED_REGS)
566 /* We have to copy one of the sources into the destination, then
567 add the other source to the destination.
569 Carefully select which source to copy to the destination; a
570 naive implementation will waste a byte when the source classes
571 are different and the destination is an address register.
572 Selecting the lowest cost register copy will optimize this
574 if (REGNO_REG_CLASS (true_regnum (operands[1]))
575 == REGNO_REG_CLASS (true_regnum (operands[0])))
576 return \"mov %1,%0\;add %2,%0\";
577 return \"mov %2,%0\;add %1,%0\";
580 /* At least one register is an extended register. */
582 /* The three operand add instruction on the am33 is a win iff the
583 output register is an extended register, or if both source
584 registers are extended registers. */
585 if (dst_class == EXTENDED_REGS
586 || src1_class == src2_class)
587 return \"add %2,%1,%0\";
589 /* It is better to copy one of the sources to the destination, then
590 perform a 2 address add. The destination in this case must be
591 an address or data register and one of the sources must be an
592 extended register and the remaining source must not be an extended
595 The best code for this case is to copy the extended reg to the
596 destination, then emit a two address add. */
597 if (src1_class == EXTENDED_REGS)
598 return \"mov %1,%0\;add %2,%0\";
599 return \"mov %2,%0\;add %1,%0\";
605 [(set_attr "timings" "11,11,11,11,11,11,22")]
608 ;; If the flags register is not live, generate CLR instead of MOV 0.
609 ;; For MN103, this is only legal for DATA_REGS; for AM33 this is legal
610 ;; but not a win for ADDRESS_REGS.
612 [(set (match_operand:INT 0 "register_operand" "") (const_int 0))]
613 "peep2_regno_dead_p (0, CC_REG)
614 && (REGNO_DATA_P (REGNO (operands[0]), 1)
615 || REGNO_EXTENDED_P (REGNO (operands[0]), 1))"
616 [(parallel [(set (match_dup 0) (const_int 0))
617 (clobber (reg:CC CC_REG))])]
620 (define_insn "*mov<mode>_clr"
621 [(set (match_operand:INT 0 "register_operand" "=D")
623 (clobber (reg:CC CC_REG))]
628 ;; ----------------------------------------------------------------------
630 ;; ----------------------------------------------------------------------
632 (define_insn "*mn10300_addsi3"
633 [(set (match_operand:SI 0 "register_operand" "=dx,a,a,dax,!*y,!dax")
634 (plus:SI (match_operand:SI 1 "register_operand" "%0,0,0,0,0,dax")
635 (match_operand:SI 2 "nonmemory_operand" "J,J,L,daxi,i,dax")))
636 (clobber (reg:CC CC_REG))
641 switch (which_alternative)
650 return \"add %2,%0\";
652 /* I'm not sure if this can happen or not. Might as well be prepared
653 and generate the best possible code if it does happen. */
654 if (true_regnum (operands[0]) == true_regnum (operands[1]))
655 return \"add %2,%0\";
656 if (true_regnum (operands[0]) == true_regnum (operands[2]))
657 return \"add %1,%0\";
659 /* We have to copy one of the sources into the destination, then add
660 the other source to the destination.
662 Carefully select which source to copy to the destination; a naive
663 implementation will waste a byte when the source classes are different
664 and the destination is an address register. Selecting the lowest
665 cost register copy will optimize this sequence. */
666 if (REGNO_REG_CLASS (true_regnum (operands[1]))
667 == REGNO_REG_CLASS (true_regnum (operands[0])))
668 return \"mov %1,%0\;add %2,%0\";
669 return \"mov %2,%0\;add %1,%0\";
674 [(set_attr "timings" "11,11,11,11,11,22")]
677 ;; ----------------------------------------------------------------------
678 ;; SUBTRACT INSTRUCTIONS
679 ;; ----------------------------------------------------------------------
681 (define_expand "subsi3"
682 [(parallel [(set (match_operand:SI 0 "register_operand")
683 (minus:SI (match_operand:SI 1 "register_operand")
684 (match_operand:SI 2 "nonmemory_operand")))
685 (clobber (reg:CC CC_REG))
691 (define_insn "*am33_subsi3"
692 [(set (match_operand:SI 0 "register_operand" "=dax,!dax")
693 (minus:SI (match_operand:SI 1 "register_operand" "0,dax")
694 (match_operand:SI 2 "nonmemory_operand" "daxi,dax")))
695 (clobber (reg:CC CC_REG))
700 if (true_regnum (operands[0]) == true_regnum (operands[1]))
701 return \"sub %2,%0\";
704 enum reg_class src1_class, src2_class, dst_class;
706 src1_class = REGNO_REG_CLASS (true_regnum (operands[1]));
707 src2_class = REGNO_REG_CLASS (true_regnum (operands[2]));
708 dst_class = REGNO_REG_CLASS (true_regnum (operands[0]));
710 /* If no extended registers are used, then the best way to handle
711 this is to copy the first source operand into the destination
712 and emit a two address subtraction. */
713 if (src1_class != EXTENDED_REGS
714 && src2_class != EXTENDED_REGS
715 && dst_class != EXTENDED_REGS
716 && true_regnum (operands[0]) != true_regnum (operands[2]))
717 return \"mov %1,%0\;sub %2,%0\";
718 return \"sub %2,%1,%0\";
721 [(set_attr "timings" "11,22")]
724 (define_insn "*mn10300_subsi3"
725 [(set (match_operand:SI 0 "register_operand" "=dax")
726 (minus:SI (match_operand:SI 1 "register_operand" "0")
727 (match_operand:SI 2 "nonmemory_operand" "daxi")))
728 (clobber (reg:CC CC_REG))
732 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
733 (const_int 11) (const_int 22)))]
736 (define_expand "negsi2"
737 [(set (match_operand:SI 0 "register_operand")
738 (neg:SI (match_operand:SI 1 "register_operand")))]
742 rtx target = gen_reg_rtx (SImode);
744 emit_move_insn (target, const0_rtx);
745 emit_insn (gen_subsi3 (target, target, operands[1]));
746 emit_move_insn (operands[0], target);
750 ;; ----------------------------------------------------------------------
751 ;; MULTIPLY INSTRUCTIONS
752 ;; ----------------------------------------------------------------------
754 ;; ??? Note that AM33 has a third multiply variant that puts the high part
755 ;; into the MDRQ register, however this variant also constrains the inputs
756 ;; to be in DATA_REGS and thus isn't as helpful as it might be considering
757 ;; the existance of the 4-operand multiply. Nor is there a set of divide
758 ;; insns that use MDRQ. Given that there is an IMM->MDRQ insn, this would
759 ;; have been very handy for starting udivmodsi4...
761 (define_expand "mulsidi3"
762 [(set (match_operand:DI 0 "register_operand" "")
763 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" ""))
764 (sign_extend:DI (match_operand:SI 2 "register_operand" ""))))]
767 emit_insn (gen_mulsidi3_internal (gen_lowpart (SImode, operands[0]),
768 gen_highpart (SImode, operands[0]),
769 operands[1], operands[2]));
773 (define_insn "mulsidi3_internal"
774 [(set (match_operand:SI 0 "register_operand" "=D,r")
775 (mult:SI (match_operand:SI 2 "register_operand" "%0,r")
776 (match_operand:SI 3 "register_operand" " D,r")))
777 (set (match_operand:SI 1 "register_operand" "=z,r")
780 (mult:DI (sign_extend:DI (match_dup 2))
781 (sign_extend:DI (match_dup 3)))
783 (clobber (reg:CC CC_REG))]
786 if (which_alternative == 1)
787 return "mul %2,%3,%1,%0";
788 else if (TARGET_MULT_BUG)
789 return "nop\;nop\;mul %3,%0";
793 [(set_attr "isa" "*,am33")
794 (set (attr "timings")
795 (if_then_else (eq_attr "cpu" "am34") (const_int 24) (const_int 23)))]
798 (define_expand "umulsidi3"
799 [(set (match_operand:DI 0 "register_operand" "")
800 (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" ""))
801 (zero_extend:DI (match_operand:SI 2 "register_operand" ""))))
802 (clobber (reg:CC CC_REG))]
805 emit_insn (gen_umulsidi3_internal (gen_lowpart (SImode, operands[0]),
806 gen_highpart (SImode, operands[0]),
807 operands[1], operands[2]));
811 (define_insn "umulsidi3_internal"
812 [(set (match_operand:SI 0 "register_operand" "=D,r")
813 (mult:SI (match_operand:SI 2 "register_operand" "%0,r")
814 (match_operand:SI 3 "register_operand" " D,r")))
815 (set (match_operand:SI 1 "register_operand" "=z,r")
818 (mult:DI (zero_extend:DI (match_dup 2))
819 (zero_extend:DI (match_dup 3)))
821 (clobber (reg:CC CC_REG))]
824 if (which_alternative == 1)
825 return "mulu %2,%3,%1,%0";
826 else if (TARGET_MULT_BUG)
827 return "nop\;nop\;mulu %3,%0";
831 [(set_attr "isa" "*,am33")
832 (set (attr "timings")
833 (if_then_else (eq_attr "cpu" "am34") (const_int 24) (const_int 23)))]
836 (define_expand "mulsi3"
837 [(parallel [(set (match_operand:SI 0 "register_operand" "")
838 (mult:SI (match_operand:SI 1 "register_operand" "")
839 (match_operand:SI 2 "nonmemory_operand" "")))
840 (clobber (match_scratch:SI 3 ""))
841 (clobber (reg:CC CC_REG))])]
845 (define_insn "*mulsi3"
846 [(set (match_operand:SI 0 "register_operand" "=D, r,r")
847 (mult:SI (match_operand:SI 2 "register_operand" "%0, 0,r")
848 (match_operand:SI 3 "nonmemory_operand" " D,ri,r")))
849 (clobber (match_scratch:SI 1 "=z, z,r"))
850 (clobber (reg:CC CC_REG))]
853 if (which_alternative == 2)
854 return "mul %2,%3,%1,%0";
855 else if (TARGET_MULT_BUG)
856 return "nop\;nop\;mul %3,%0";
860 [(set_attr "isa" "*,am33,am33")
861 (set (attr "timings")
862 (if_then_else (eq_attr "cpu" "am34") (const_int 24) (const_int 23)))]
865 (define_expand "udivmodsi4"
866 [(parallel [(set (match_operand:SI 0 "register_operand")
867 (udiv:SI (match_operand:SI 1 "register_operand")
868 (match_operand:SI 2 "register_operand")))
869 (set (match_operand:SI 3 "register_operand")
870 (umod:SI (match_dup 1) (match_dup 2)))
872 (clobber (reg:CC CC_REG))])]
876 ;; Note the trick to get reload to put the zero into the MDR register,
877 ;; rather than exposing the load early and letting CSE or someone try
878 ;; to share the zeros between division insns. Which tends to result
879 ;; in sequences like 0->r0->d0->mdr.
881 (define_insn "*udivmodsi4"
882 [(set (match_operand:SI 0 "register_operand" "=D")
883 (udiv:SI (match_operand:SI 2 "register_operand" " 0")
884 (match_operand:SI 3 "register_operand" " D")))
885 (set (match_operand:SI 1 "register_operand" "=z")
886 (umod:SI (match_dup 2) (match_dup 3)))
887 (use (match_operand:SI 4 "nonmemory_operand" " 1"))
888 (clobber (reg:CC CC_REG))]
891 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
892 (const_int 3839) (const_int 4243)))]
895 (define_expand "divmodsi4"
896 [(parallel [(set (match_operand:SI 0 "register_operand" "")
897 (div:SI (match_operand:SI 1 "register_operand" "")
898 (match_operand:SI 2 "register_operand" "")))
899 (set (match_operand:SI 3 "register_operand" "")
900 (mod:SI (match_dup 1) (match_dup 2)))
902 (clobber (reg:CC CC_REG))])]
905 operands[4] = gen_reg_rtx (SImode);
906 emit_insn (gen_ext_internal (operands[4], operands[1]));
909 ;; ??? Ideally we'd represent this via shift, but it seems like adding a
910 ;; special-case pattern for (ashiftrt x 31) is just as likely to result
911 ;; in poor register allocation choices.
912 (define_insn "ext_internal"
913 [(set (match_operand:SI 0 "register_operand" "=z")
914 (unspec:SI [(match_operand:SI 1 "register_operand" "D")] UNSPEC_EXT))]
919 (define_insn "*divmodsi4"
920 [(set (match_operand:SI 0 "register_operand" "=D")
921 (div:SI (match_operand:SI 2 "register_operand" " 0")
922 (match_operand:SI 3 "register_operand" " D")))
923 (set (match_operand:SI 1 "register_operand" "=z")
924 (mod:SI (match_dup 2) (match_dup 3)))
925 (use (match_operand:SI 4 "register_operand" " 1"))
926 (clobber (reg:CC CC_REG))]
929 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
930 (const_int 3839) (const_int 4243)))]
934 ;; ----------------------------------------------------------------------
936 ;; ----------------------------------------------------------------------
938 (define_expand "andsi3"
939 [(parallel [(set (match_operand:SI 0 "register_operand")
940 (and:SI (match_operand:SI 1 "register_operand")
941 (match_operand:SI 2 "nonmemory_operand")))
942 (clobber (reg:CC CC_REG))
948 (define_insn "*am33_andsi3"
949 [(set (match_operand:SI 0 "register_operand" "=dx,dx,!dax")
950 (and:SI (match_operand:SI 1 "register_operand" "%0,0,dax")
951 (match_operand:SI 2 "nonmemory_operand" "N,dxi,dax")))
952 (clobber (reg:CC CC_REG))
956 if (CONST_INT_P (operands[2]))
957 switch (INTVAL (operands[2]))
959 case 0xff: return "extbu %0";
960 case 0xffff: return "exthu %0";
961 case 0x7fffffff: return "add %0, %0; lsr 1, %0";
962 case 0x3fffffff: return "asl2 %0; lsr 2, %0";
963 case 0x1fffffff: return "add %0, %0; asl2 %0; lsr 3, %0";
964 case 0x0fffffff: return "asl2 %0; asl2 %0; lsr 4, %0";
965 case 0xfffffffe: return "lsr 1, %0; add %0, %0";
966 case 0xfffffffc: return "lsr 2, %0; asl2 %0";
967 case 0xfffffff8: return "lsr 3, %0; add %0, %0; asl2 %0";
968 case 0xfffffff0: return "lsr 4, %0; asl2 %0; asl2 %0";
971 if (REG_P (operands[2]) && REG_P (operands[1])
972 && true_regnum (operands[0]) != true_regnum (operands[1])
973 && true_regnum (operands[0]) != true_regnum (operands[2])
974 && REGNO_REG_CLASS (true_regnum (operands[0])) == DATA_REGS
975 && REGNO_REG_CLASS (true_regnum (operands[1])) == DATA_REGS
976 && REGNO_REG_CLASS (true_regnum (operands[2])) == DATA_REGS)
977 return "mov %1, %0; and %2, %0";
978 if (REG_P (operands[2]) && REG_P (operands[1])
979 && true_regnum (operands[0]) != true_regnum (operands[1])
980 && true_regnum (operands[0]) != true_regnum (operands[2]))
981 return "and %1, %2, %0";
982 if (REG_P (operands[2]) && REG_P (operands[0])
983 && true_regnum (operands[2]) == true_regnum (operands[0]))
988 [(set_attr "timings" "33")]
991 (define_insn "*mn10300_andsi3"
992 [(set (match_operand:SI 0 "register_operand" "=dx,dx")
993 (and:SI (match_operand:SI 1 "register_operand" "%0,0")
994 (match_operand:SI 2 "nonmemory_operand" "N,dxi")))
995 (clobber (reg:CC CC_REG))
999 if (CONST_INT_P (operands[2]))
1000 switch (INTVAL (operands[2]))
1002 case 0xff: return "extbu %0";
1003 case 0xffff: return "exthu %0";
1004 case 0x7fffffff: return "add %0, %0; lsr 1, %0";
1005 case 0x3fffffff: return "asl2 %0; lsr 2, %0";
1006 case 0x1fffffff: return "add %0, %0; asl2 %0; lsr 3, %0";
1007 case 0x0fffffff: return "asl2 %0; asl2 %0; lsr 4, %0";
1008 case 0xfffffffe: return "lsr 1, %0; add %0, %0";
1009 case 0xfffffffc: return "lsr 2, %0; asl2 %0";
1010 case 0xfffffff8: return "lsr 3, %0; add %0, %0; asl2 %0";
1011 case 0xfffffff0: return "lsr 4, %0; asl2 %0; asl2 %0";
1014 return "and %2, %0";
1016 [(set_attr "timings" "33")]
1019 ;; ----------------------------------------------------------------------
1021 ;; ----------------------------------------------------------------------
1023 (define_expand "iorsi3"
1024 [(parallel [(set (match_operand:SI 0 "register_operand")
1025 (ior:SI (match_operand:SI 1 "register_operand")
1026 (match_operand:SI 2 "nonmemory_operand")))
1027 (clobber (reg:CC CC_REG))
1033 (define_insn "*am33_iorsi3"
1034 [(set (match_operand:SI 0 "register_operand" "=dx,!dax")
1035 (ior:SI (match_operand:SI 1 "register_operand" "%0,dax")
1036 (match_operand:SI 2 "nonmemory_operand" "dxi,dax")))
1037 (clobber (reg:CC CC_REG))
1042 if (REG_P (operands[2]) && REG_P (operands[1])
1043 && true_regnum (operands[0]) != true_regnum (operands[1])
1044 && true_regnum (operands[0]) != true_regnum (operands[2])
1045 && REGNO_REG_CLASS (true_regnum (operands[0])) == DATA_REGS
1046 && REGNO_REG_CLASS (true_regnum (operands[1])) == DATA_REGS
1047 && REGNO_REG_CLASS (true_regnum (operands[2])) == DATA_REGS)
1048 return \"mov %1,%0\;or %2,%0\";
1049 if (REG_P (operands[2]) && REG_P (operands[1])
1050 && true_regnum (operands[0]) != true_regnum (operands[1])
1051 && true_regnum (operands[0]) != true_regnum (operands[2]))
1052 return \"or %1,%2,%0\";
1053 if (REG_P (operands[2]) && REG_P (operands[0])
1054 && true_regnum (operands[2]) == true_regnum (operands[0]))
1055 return \"or %1,%0\";
1056 return \"or %2,%0\";
1058 [(set_attr "timings" "22")]
1061 (define_insn "*mn10300_iorsi3"
1062 [(set (match_operand:SI 0 "register_operand" "=dx")
1063 (ior:SI (match_operand:SI 1 "register_operand" "%0")
1064 (match_operand:SI 2 "nonmemory_operand" "dxi")))
1065 (clobber (reg:CC CC_REG))
1069 [(set_attr "timings" "33")]
1072 ;; ----------------------------------------------------------------------
1074 ;; ----------------------------------------------------------------------
1076 (define_expand "xorsi3"
1077 [(parallel [(set (match_operand:SI 0 "register_operand")
1078 (xor:SI (match_operand:SI 1 "register_operand")
1079 (match_operand:SI 2 "nonmemory_operand")))
1080 (clobber (reg:CC CC_REG))
1086 (define_insn "*am33_xorsi3"
1087 [(set (match_operand:SI 0 "register_operand" "=dx,!dax")
1088 (xor:SI (match_operand:SI 1 "register_operand" "%0,dax")
1089 (match_operand:SI 2 "nonmemory_operand" "dxi,dax")))
1090 (clobber (reg:CC CC_REG))
1095 if (REG_P (operands[2]) && REG_P (operands[1])
1096 && true_regnum (operands[0]) != true_regnum (operands[1])
1097 && true_regnum (operands[0]) != true_regnum (operands[2])
1098 && REGNO_REG_CLASS (true_regnum (operands[0])) == DATA_REGS
1099 && REGNO_REG_CLASS (true_regnum (operands[1])) == DATA_REGS
1100 && REGNO_REG_CLASS (true_regnum (operands[2])) == DATA_REGS)
1101 return \"mov %1,%0\;xor %2,%0\";
1102 if (REG_P (operands[2]) && REG_P (operands[1])
1103 && true_regnum (operands[0]) != true_regnum (operands[1])
1104 && true_regnum (operands[0]) != true_regnum (operands[2]))
1105 return \"xor %1,%2,%0\";
1106 if (REG_P (operands[2]) && REG_P (operands[0])
1107 && true_regnum (operands[2]) == true_regnum (operands[0]))
1108 return \"xor %1,%0\";
1109 return \"xor %2,%0\";
1111 [(set_attr "timings" "22")]
1114 (define_insn "*mn10300_xorsi3"
1115 [(set (match_operand:SI 0 "register_operand" "=dx")
1116 (xor:SI (match_operand:SI 1 "register_operand" "%0")
1117 (match_operand:SI 2 "nonmemory_operand" "dxi")))
1118 (clobber (reg:CC CC_REG))
1122 [(set_attr "timings" "11")]
1125 ;; ----------------------------------------------------------------------
1127 ;; ----------------------------------------------------------------------
1129 (define_expand "one_cmplsi2"
1130 [(parallel [(set (match_operand:SI 0 "register_operand")
1131 (not:SI (match_operand:SI 1 "register_operand")))
1132 (clobber (reg:CC CC_REG))
1138 (define_insn "*am33_cmplsi2"
1139 [(set (match_operand:SI 0 "register_operand" "=dx,!dax")
1140 (not:SI (match_operand:SI 1 "register_operand" "0,0")))
1141 (clobber (reg:CC CC_REG))
1147 (define_insn "*mn10300_cmplsi2"
1148 [(set (match_operand:SI 0 "register_operand" "=dx")
1149 (not:SI (match_operand:SI 1 "register_operand" "0")))
1150 (clobber (reg:CC CC_REG))
1156 ;; ----------------------------------------------------------------------
1157 ;; COMPARE AND BRANCH INSTRUCTIONS
1158 ;; ----------------------------------------------------------------------
1160 ;; We expand the comparison into a single insn so that it will not be split
1162 (define_expand "cbranchsi4"
1165 (match_operator 0 "ordered_comparison_operator"
1166 [(match_operand:SI 1 "register_operand")
1167 (match_operand:SI 2 "nonmemory_operand")])
1168 (label_ref (match_operand 3 ""))
1174 (define_insn_and_split "*cbranchsi4_post_reload"
1176 (if_then_else (match_operator 3 "ordered_comparison_operator"
1177 [(match_operand:SI 0 "register_operand" "dax")
1178 (match_operand:SI 1 "nonmemory_operand" "daxi")])
1179 (label_ref (match_operand 2 "" ""))
1187 /* We construct the split by hand as otherwise the JUMP_LABEL
1188 attribute is not set correctly on the jump insn. */
1189 emit_insn (gen_cmpsi (operands[0], operands[1]));
1191 emit_jump_insn (gen_integer_conditional_branch
1192 (gen_rtx_fmt_ee (GET_CODE (operands[3]),
1194 gen_rtx_REG (CCmode, CC_REG),
1200 ;; Ordinarily, the cmp instruction will set the Z bit of cc0 to 1 if
1201 ;; its operands hold equal values, but the operands of a cmp
1202 ;; instruction must be distinct registers. In the case where we'd
1203 ;; like to compare a register to itself, we can achieve this effect
1204 ;; with a btst 0,d0 instead. (This will not alter the contents of d0
1205 ;; but will have the proper effect on cc0. Using d0 is arbitrary; any
1206 ;; data register would work.)
1208 ;; Even though the first alternative would be preferable if it can
1209 ;; possibly match, reload must not be given the opportunity to attempt
1210 ;; to use it. It assumes that such matches can only occur when one of
1211 ;; the operands is used for input and the other for output. Since
1212 ;; this is not the case, it abort()s. Indeed, such a reload cannot be
1213 ;; possibly satisfied, so just mark the alternative with a `!', so
1214 ;; that it is not considered by reload.
1216 (define_insn "cmpsi"
1217 [(set (reg:CC CC_REG)
1218 (compare (match_operand:SI 0 "register_operand" "!*d*a*x,dax,dax")
1219 (match_operand:SI 1 "nonmemory_operand" "*0,I,daxi")))]
1222 if (which_alternative == 0)
1223 return \"btst 0,d0\";
1224 if (which_alternative == 1)
1225 return mn10300_output_cmp (operands[0], insn);
1226 return \"cmp %1,%0\";
1228 [(set_attr_alternative "timings"
1230 (if_then_else (eq_attr "cpu" "am34")
1231 (const_int 11) (const_int 22))
1237 (define_insn "integer_conditional_branch"
1239 (if_then_else (match_operator 0 "comparison_operator"
1240 [(reg:CC CC_REG) (const_int 0)])
1241 (label_ref (match_operand 1 "" ""))
1247 (define_expand "cbranchsf4"
1250 (match_operator 0 "ordered_comparison_operator"
1251 [(match_operand:SF 1 "register_operand")
1252 (match_operand:SF 2 "nonmemory_operand")])
1253 (label_ref (match_operand 3 ""))
1259 (define_insn_and_split "*cbranchsf4_post_reload"
1261 (if_then_else (match_operator 3 "ordered_comparison_operator"
1262 [(match_operand:SF 0 "register_operand" "f")
1263 (match_operand:SF 1 "nonmemory_operand" "fF")])
1264 (label_ref (match_operand 2 "" ""))
1269 "&& reload_completed"
1272 /* We construct the split by hand as otherwise the JUMP_LABEL
1273 attribute is not set correctly on the jump insn. */
1274 emit_insn (gen_am33_cmpsf (operands[0], operands[1]));
1276 emit_jump_insn (gen_float_conditional_branch
1277 (gen_rtx_fmt_ee (GET_CODE (operands[3]),
1279 gen_rtx_REG (CC_FLOATmode, CC_REG),
1285 (define_insn "am33_cmpsf"
1286 [(set (reg:CC_FLOAT CC_REG)
1287 (compare:CC_FLOAT (match_operand:SF 0 "register_operand" "f")
1288 (match_operand:SF 1 "nonmemory_operand" "fF")))]
1291 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1292 (const_int 17) (const_int 25)))]
1295 (define_insn "float_conditional_branch"
1297 (if_then_else (match_operator 0 "comparison_operator"
1298 [(reg:CC_FLOAT CC_REG) (const_int 0)])
1299 (label_ref (match_operand 1 "" ""))
1303 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1304 (const_int 44) (const_int 33)))]
1307 ;; Unconditional and other jump instructions.
1311 (label_ref (match_operand 0 "" "")))]
1314 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1315 (const_int 11) (const_int 44)))]
1318 (define_insn "indirect_jump"
1319 [(set (pc) (match_operand:SI 0 "register_operand" "a"))]
1322 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1323 (const_int 11) (const_int 33)))]
1326 (define_expand "builtin_setjmp_receiver"
1327 [(match_operand 0 "" "")]
1332 emit_insn (gen_GOTaddr2picreg ());
1337 (define_expand "casesi"
1338 [(match_operand:SI 0 "register_operand")
1339 (match_operand:SI 1 "immediate_operand")
1340 (match_operand:SI 2 "immediate_operand")
1341 (match_operand 3 "" "") (match_operand 4 "")]
1345 rtx table = gen_reg_rtx (SImode);
1346 rtx index = gen_reg_rtx (SImode);
1347 rtx addr = gen_reg_rtx (Pmode);
1350 emit_move_insn (table, gen_rtx_LABEL_REF (VOIDmode, operands[3]));
1351 emit_insn (gen_addsi3 (index, operands[0], GEN_INT (- INTVAL (operands[1]))));
1352 test = gen_rtx_fmt_ee (GTU, VOIDmode, index, operands[2]);
1353 emit_jump_insn (gen_cbranchsi4 (test, index, operands[2], operands[4]));
1355 emit_insn (gen_ashlsi3 (index, index, const2_rtx));
1356 emit_move_insn (addr, gen_rtx_MEM (SImode,
1357 gen_rtx_PLUS (SImode, table, index)));
1359 emit_insn (gen_addsi3 (addr, addr, table));
1361 emit_jump_insn (gen_tablejump (addr, operands[3]));
1365 (define_insn "tablejump"
1366 [(set (pc) (match_operand:SI 0 "register_operand" "a"))
1367 (use (label_ref (match_operand 1 "" "")))]
1370 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1371 (const_int 11) (const_int 33)))]
1374 ;; Call subroutine with no return value.
1376 (define_expand "call"
1377 [(call (match_operand:QI 0 "general_operand")
1378 (match_operand:SI 1 "general_operand"))]
1381 rtx fn = XEXP (operands[0], 0);
1383 if (flag_pic && GET_CODE (fn) == SYMBOL_REF)
1385 if (MN10300_GLOBAL_P (fn))
1387 /* The PLT code won't run on AM30, but then, there's no
1388 shared library support for AM30 either, so we just assume
1389 the linker is going to adjust all @PLT relocs to the
1391 emit_use (pic_offset_table_rtx);
1392 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PLT);
1395 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PIC);
1397 if (! call_address_operand (fn, VOIDmode))
1398 fn = force_reg (SImode, fn);
1400 XEXP (operands[0], 0) = fn;
1403 (define_insn "*call_internal"
1404 [(call (mem:QI (match_operand:SI 0 "call_address_operand" "a,S"))
1405 (match_operand:SI 1 "" ""))]
1410 [(set_attr_alternative "timings"
1411 [(if_then_else (eq_attr "cpu" "am34")
1412 (const_int 33) (const_int 44))
1413 (if_then_else (eq_attr "cpu" "am34")
1414 (const_int 55) (const_int 33))
1419 ;; Call subroutine, returning value in operand 0
1420 ;; (which must be a hard register).
1422 (define_expand "call_value"
1423 [(set (match_operand 0 "")
1424 (call (match_operand:QI 1 "general_operand")
1425 (match_operand:SI 2 "general_operand")))]
1428 rtx fn = XEXP (operands[1], 0);
1430 if (flag_pic && GET_CODE (fn) == SYMBOL_REF)
1432 if (MN10300_GLOBAL_P (fn))
1434 /* The PLT code won't run on AM30, but then, there's no
1435 shared library support for AM30 either, so we just assume
1436 the linker is going to adjust all @PLT relocs to the
1438 emit_use (pic_offset_table_rtx);
1439 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PLT);
1442 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PIC);
1444 if (! call_address_operand (fn, VOIDmode))
1445 fn = force_reg (SImode, fn);
1447 XEXP (operands[1], 0) = fn;
1450 (define_insn "call_value_internal"
1451 [(set (match_operand 0 "" "")
1452 (call (mem:QI (match_operand:SI 1 "call_address_operand" "a,S"))
1453 (match_operand:SI 2 "" "")))]
1458 [(set_attr_alternative "timings"
1459 [(if_then_else (eq_attr "cpu" "am34")
1460 (const_int 33) (const_int 44))
1461 (if_then_else (eq_attr "cpu" "am34")
1462 (const_int 55) (const_int 33))
1467 (define_expand "untyped_call"
1468 [(parallel [(call (match_operand 0 "")
1470 (match_operand 1 "")
1471 (match_operand 2 "")])]
1477 emit_call_insn (gen_call (operands[0], const0_rtx));
1479 for (i = 0; i < XVECLEN (operands[2], 0); i++)
1481 rtx set = XVECEXP (operands[2], 0, i);
1482 emit_move_insn (SET_DEST (set), SET_SRC (set));
1493 ;; ----------------------------------------------------------------------
1494 ;; EXTEND INSTRUCTIONS
1495 ;; ----------------------------------------------------------------------
1497 (define_expand "zero_extendqisi2"
1498 [(set (match_operand:SI 0 "register_operand")
1500 (match_operand:QI 1 "nonimmediate_operand")))]
1504 (define_insn "*zero_extendqisi2_am33"
1505 [(set (match_operand:SI 0 "register_operand" "=dx,dx,dx,!dax,!dax,!dax")
1507 (match_operand:QI 1 "nonimmediate_operand" "0,dax,m,0,dax,m")))]
1516 [(set_attr_alternative "timings"
1519 (if_then_else (eq_attr "cpu" "am34")
1520 (const_int 13) (const_int 24))
1523 (if_then_else (eq_attr "cpu" "am34")
1524 (const_int 13) (const_int 24))
1529 (define_insn "*zero_extendqisi2_mn10300"
1530 [(set (match_operand:SI 0 "register_operand" "=dx,dx,dx")
1532 (match_operand:QI 1 "nonimmediate_operand" "0,d,m")))]
1538 [(set_attr_alternative "timings"
1541 (if_then_else (eq_attr "cpu" "am34")
1542 (const_int 13) (const_int 24))
1547 (define_expand "zero_extendhisi2"
1548 [(set (match_operand:SI 0 "register_operand")
1550 (match_operand:HI 1 "nonimmediate_operand")))]
1554 (define_insn "*zero_extendhisi2_am33"
1555 [(set (match_operand:SI 0 "register_operand" "=dx,dx,dx,!dax,!dax,!dax")
1557 (match_operand:HI 1 "nonimmediate_operand" "0,dax,m,0,dax,m")))]
1566 [(set_attr_alternative "timings"
1569 (if_then_else (eq_attr "cpu" "am34")
1570 (const_int 13) (const_int 24))
1573 (if_then_else (eq_attr "cpu" "am34")
1574 (const_int 13) (const_int 24))
1579 (define_insn "*zero_extendhisi2_mn10300"
1580 [(set (match_operand:SI 0 "register_operand" "=dx,dx,dx")
1582 (match_operand:HI 1 "nonimmediate_operand" "0,dx,m")))]
1588 [(set_attr_alternative "timings"
1591 (if_then_else (eq_attr "cpu" "am34")
1592 (const_int 13) (const_int 24))
1597 ;;- sign extension instructions
1599 (define_expand "extendqisi2"
1600 [(set (match_operand:SI 0 "register_operand")
1602 (match_operand:QI 1 "register_operand")))]
1606 (define_insn "*extendqisi2_am33"
1607 [(set (match_operand:SI 0 "register_operand" "=dx,dx,!dax,!dax")
1609 (match_operand:QI 1 "register_operand" "0,dx,0,dax")))]
1616 [(set_attr "timings" "11,22,11,22")]
1619 (define_insn "*extendqisi2_mn10300"
1620 [(set (match_operand:SI 0 "register_operand" "=dx,dx")
1622 (match_operand:QI 1 "register_operand" "0,dx")))]
1627 [(set_attr "timings" "11,22")]
1630 (define_expand "extendhisi2"
1631 [(set (match_operand:SI 0 "register_operand")
1633 (match_operand:HI 1 "register_operand")))]
1637 (define_insn "*extendhisi2_am33"
1638 [(set (match_operand:SI 0 "register_operand" "=dx,dx,!dax,!dax")
1640 (match_operand:HI 1 "register_operand" "0,dax,0,dax")))]
1647 [(set_attr "timings" "11,22,11,22")]
1650 (define_insn "*extendhisi2_mn10300"
1651 [(set (match_operand:SI 0 "register_operand" "=dx,dx")
1653 (match_operand:HI 1 "register_operand" "0,dx")))]
1658 [(set_attr "timings" "11,22")]
1661 ;; ----------------------------------------------------------------------
1663 ;; ----------------------------------------------------------------------
1665 (define_expand "ashlsi3"
1666 [(parallel [(set (match_operand:SI 0 "register_operand")
1668 (match_operand:SI 1 "register_operand")
1669 (match_operand:QI 2 "nonmemory_operand")))
1670 (clobber (reg:CC CC_REG))
1676 (define_insn "*am33_ashlsi3"
1677 [(set (match_operand:SI 0 "register_operand" "=dax,dx,!dax")
1679 (match_operand:SI 1 "register_operand" "0,0,dax")
1680 (match_operand:QI 2 "nonmemory_operand" "J,dxi,dax")))
1681 (clobber (reg:CC CC_REG))
1686 if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 1)
1687 return \"add %0,%0\";
1689 if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 2)
1692 if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 3
1693 && REGNO_REG_CLASS (true_regnum (operands[0])) == DATA_REGS)
1694 return \"asl2 %0\;add %0,%0\";
1696 if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 4
1697 && REGNO_REG_CLASS (true_regnum (operands[0])) == DATA_REGS)
1698 return \"asl2 %0\;asl2 %0\";
1700 if (true_regnum (operands[1]) == true_regnum (operands[0]))
1701 return \"asl %S2,%0\";
1703 if (REGNO_REG_CLASS (true_regnum (operands[0])) == DATA_REGS
1704 && REGNO_REG_CLASS (true_regnum (operands[1])) == DATA_REGS
1705 && true_regnum (operands[0]) != true_regnum (operands[2]))
1706 return \"mov %1,%0\;asl %S2,%0\";
1707 return \"asl %2,%1,%0\";
1709 [(set_attr "timings" "22")]
1712 (define_insn "*mn10300_ashlsi3"
1713 [(set (match_operand:SI 0 "register_operand" "=dax,dx,dx,dx,dx")
1715 (match_operand:SI 1 "register_operand" "0,0,0,0,0")
1716 (match_operand:QI 2 "nonmemory_operand" "J,K,M,L,dxi")))
1717 (clobber (reg:CC CC_REG))
1726 [(set_attr "timings" "11,11,22,22,11")]
1729 (define_expand "lshrsi3"
1730 [(parallel [(set (match_operand:SI 0 "register_operand")
1732 (match_operand:SI 1 "register_operand")
1733 (match_operand:QI 2 "nonmemory_operand")))
1734 (clobber (reg:CC CC_REG))
1740 (define_insn "*am33_lshrsi3"
1741 [(set (match_operand:SI 0 "register_operand" "=dx,!dax")
1743 (match_operand:SI 1 "register_operand" "0,dax")
1744 (match_operand:QI 2 "nonmemory_operand" "dxi,dax")))
1745 (clobber (reg:CC CC_REG))
1750 if (true_regnum (operands[1]) == true_regnum (operands[0]))
1751 return \"lsr %S2,%0\";
1753 if (REGNO_REG_CLASS (true_regnum (operands[0])) == DATA_REGS
1754 && REGNO_REG_CLASS (true_regnum (operands[1])) == DATA_REGS
1755 && true_regnum (operands[0]) != true_regnum (operands[2]))
1756 return \"mov %1,%0\;lsr %S2,%0\";
1757 return \"lsr %2,%1,%0\";
1759 [(set_attr "timings" "22")]
1762 (define_insn "*mn10300_lshrsi3"
1763 [(set (match_operand:SI 0 "register_operand" "=dx")
1765 (match_operand:SI 1 "register_operand" "0")
1766 (match_operand:QI 2 "nonmemory_operand" "dxi")))
1767 (clobber (reg:CC CC_REG))
1771 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1772 (const_int 11) (const_int 22)))]
1775 (define_expand "ashrsi3"
1776 [(parallel [(set (match_operand:SI 0 "register_operand")
1778 (match_operand:SI 1 "register_operand")
1779 (match_operand:QI 2 "nonmemory_operand")))
1780 (clobber (reg:CC CC_REG))
1786 (define_insn "*am33_ashrisi3"
1787 [(set (match_operand:SI 0 "register_operand" "=dx,!dax")
1789 (match_operand:SI 1 "register_operand" "0,dax")
1790 (match_operand:QI 2 "nonmemory_operand" "dxi,dax")))
1791 (clobber (reg:CC CC_REG))
1796 if (true_regnum (operands[1]) == true_regnum (operands[0]))
1797 return \"asr %S2,%0\";
1799 if (REGNO_REG_CLASS (true_regnum (operands[0])) == DATA_REGS
1800 && REGNO_REG_CLASS (true_regnum (operands[1])) == DATA_REGS
1801 && true_regnum (operands[0]) != true_regnum (operands[2]))
1802 return \"mov %1,%0\;asr %S2,%0\";
1803 return \"asr %2,%1,%0\";
1805 [(set_attr "timings" "22")]
1808 (define_insn "*mn10300_ashrsi3"
1809 [(set (match_operand:SI 0 "register_operand" "=dx")
1811 (match_operand:SI 1 "register_operand" "0")
1812 (match_operand:QI 2 "nonmemory_operand" "dxi")))
1813 (clobber (reg:CC CC_REG))
1817 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1818 (const_int 11) (const_int 22)))]
1821 ;; ----------------------------------------------------------------------
1823 ;; ----------------------------------------------------------------------
1825 (define_expand "clzsi2"
1826 [(parallel [(set (match_operand:SI 0 "register_operand" "")
1827 (unspec:SI [(match_operand:SI 1 "register_operand" "")
1828 (const_int 0)] UNSPEC_BSCH))
1829 (clobber (reg:CC CC_REG))])]
1833 (define_insn "*bsch"
1834 [(set (match_operand:SI 0 "register_operand" "=r")
1835 (unspec:SI [(match_operand:SI 1 "register_operand" "r")
1836 (match_operand:SI 2 "nonmemory_operand" "0")]
1838 (clobber (reg:CC CC_REG))]
1843 ;; ----------------------------------------------------------------------
1845 ;; ----------------------------------------------------------------------
1847 (define_insn "abssf2"
1848 [(set (match_operand:SF 0 "register_operand" "=f,f")
1849 (abs:SF (match_operand:SF 1 "register_operand" "0,?f")))]
1854 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1855 (const_int 17) (const_int 14)))]
1858 (define_insn "negsf2"
1859 [(set (match_operand:SF 0 "register_operand" "=f,f")
1860 (neg:SF (match_operand:SF 1 "register_operand" "0,?f")))]
1865 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1866 (const_int 17) (const_int 14)))]
1869 (define_expand "sqrtsf2"
1870 [(set (match_operand:SF 0 "register_operand" "")
1871 (sqrt:SF (match_operand:SF 1 "register_operand" "")))]
1872 "TARGET_AM33_2 && flag_unsafe_math_optimizations"
1874 rtx scratch = gen_reg_rtx (SFmode);
1875 emit_insn (gen_rsqrtsf2 (scratch, operands[1], CONST1_RTX (SFmode)));
1876 emit_insn (gen_divsf3 (operands[0], force_reg (SFmode, CONST1_RTX (SFmode)),
1881 (define_insn "rsqrtsf2"
1882 [(set (match_operand:SF 0 "register_operand" "=f,f")
1883 (div:SF (match_operand:SF 2 "const_1f_operand" "F,F")
1884 (sqrt:SF (match_operand:SF 1 "register_operand" "0,?f"))))
1885 (clobber (reg:CC_FLOAT CC_REG))]
1890 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1891 (const_int 4753) (const_int 2327)))]
1894 (define_insn "addsf3"
1895 [(set (match_operand:SF 0 "register_operand" "=f,f")
1896 (plus:SF (match_operand:SF 1 "register_operand" "%0,f")
1897 (match_operand:SF 2 "nonmemory_operand" "f,?fF")))
1898 (clobber (reg:CC_FLOAT CC_REG))]
1903 [(set_attr_alternative "timings"
1904 [(if_then_else (eq_attr "cpu" "am34")
1905 (const_int 17) (const_int 14))
1906 (if_then_else (eq_attr "cpu" "am34")
1907 (const_int 17) (const_int 25))
1911 (define_insn "subsf3"
1912 [(set (match_operand:SF 0 "register_operand" "=f,f")
1913 (minus:SF (match_operand:SF 1 "register_operand" "0,f")
1914 (match_operand:SF 2 "nonmemory_operand" "f,?fF")))
1915 (clobber (reg:CC_FLOAT CC_REG))]
1920 [(set_attr_alternative "timings"
1921 [(if_then_else (eq_attr "cpu" "am34")
1922 (const_int 17) (const_int 14))
1923 (if_then_else (eq_attr "cpu" "am34")
1924 (const_int 17) (const_int 25))
1928 (define_insn "mulsf3"
1929 [(set (match_operand:SF 0 "register_operand" "=f,f")
1930 (mult:SF (match_operand:SF 1 "register_operand" "%0,f")
1931 (match_operand:SF 2 "nonmemory_operand" "f,?fF")))
1932 (clobber (reg:CC_FLOAT CC_REG))
1938 [(set_attr_alternative "timings"
1939 [(if_then_else (eq_attr "cpu" "am34")
1940 (const_int 17) (const_int 14))
1941 (if_then_else (eq_attr "cpu" "am34")
1942 (const_int 17) (const_int 25))
1946 (define_insn "divsf3"
1947 [(set (match_operand:SF 0 "register_operand" "=f,f")
1948 (div:SF (match_operand:SF 1 "register_operand" "0,f")
1949 (match_operand:SF 2 "nonmemory_operand" "f,?fF")))
1950 (clobber (reg:CC_FLOAT CC_REG))]
1955 [(set_attr_alternative "timings"
1956 [(if_then_else (eq_attr "cpu" "am34")
1957 (const_int 2531) (const_int 1216))
1958 (if_then_else (eq_attr "cpu" "am34")
1959 (const_int 2531) (const_int 1317))
1963 (define_insn "fmasf4"
1964 [(set (match_operand:SF 0 "register_operand" "=c")
1965 (fma:SF (match_operand:SF 1 "register_operand" "f")
1966 (match_operand:SF 2 "register_operand" "f")
1967 (match_operand:SF 3 "register_operand" "f")))
1968 (clobber (reg:CC_FLOAT CC_REG))
1971 "fmadd %1, %2, %3, %0"
1972 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1973 (const_int 17) (const_int 24)))]
1976 (define_insn "fmssf4"
1977 [(set (match_operand:SF 0 "register_operand" "=c")
1978 (fma:SF (match_operand:SF 1 "register_operand" "f")
1979 (match_operand:SF 2 "register_operand" "f")
1980 (neg:SF (match_operand:SF 3 "register_operand" "f"))))
1981 (clobber (reg:CC_FLOAT CC_REG))
1984 "fmsub %1, %2, %3, %0"
1985 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1986 (const_int 17) (const_int 24)))]
1989 (define_insn "fnmasf4"
1990 [(set (match_operand:SF 0 "register_operand" "=c")
1991 (fma:SF (neg:SF (match_operand:SF 1 "register_operand" "f"))
1992 (match_operand:SF 2 "register_operand" "f")
1993 (match_operand:SF 3 "register_operand" "f")))
1994 (clobber (reg:CC_FLOAT CC_REG))
1997 "fnmadd %1, %2, %3, %0"
1998 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1999 (const_int 17) (const_int 24)))]
2002 (define_insn "fnmssf4"
2003 [(set (match_operand:SF 0 "register_operand" "=c")
2004 (fma:SF (neg:SF (match_operand:SF 1 "register_operand" "f"))
2005 (match_operand:SF 2 "register_operand" "f")
2006 (neg:SF (match_operand:SF 3 "register_operand" "f"))))
2007 (clobber (reg:CC_FLOAT CC_REG))
2010 "fnmsub %1, %2, %3, %0"
2011 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
2012 (const_int 17) (const_int 24)))]
2015 ;; ----------------------------------------------------------------------
2016 ;; PROLOGUE/EPILOGUE
2017 ;; ----------------------------------------------------------------------
2018 (define_expand "prologue"
2021 "mn10300_expand_prologue (); DONE;")
2023 (define_expand "epilogue"
2028 mn10300_expand_epilogue ();
2032 (define_insn "return_internal"
2037 [(set_attr "timings" "66")]
2040 ;; This insn restores the callee saved registers and does a return, it
2041 ;; can also deallocate stack space.
2042 (define_insn "return_internal_regs"
2044 (match_operand:SI 0 "const_int_operand" "i")
2049 fputs (\"\\tret \", asm_out_file);
2050 mn10300_print_reg_list (asm_out_file, mn10300_get_live_callee_saved_regs ());
2051 fprintf (asm_out_file, \",%d\\n\", (int) INTVAL (operands[0]));
2054 ;; Assumes that there will be no more than 8 regs to pop
2055 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
2056 (const_int 1414) (const_int 1313)))]
2059 ;; This instruction matches one generated by mn10300_gen_multiple_store()
2060 (define_insn "store_movm"
2061 [(match_parallel 0 "mn10300_store_multiple_operation"
2062 [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (match_operand 1 "" "")))])]
2066 fputs (\"\\tmovm \", asm_out_file);
2067 mn10300_print_reg_list (asm_out_file,
2068 mn10300_store_multiple_operation (operands[0],
2070 fprintf (asm_out_file, \",(sp)\\n\");
2073 ;; Assume that no more than 8 registers will be pushed.
2074 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
2075 (const_int 99) (const_int 88)))]
2078 (define_insn "return"
2080 "mn10300_can_use_return_insn ()"
2083 rtx next = next_active_insn (insn);
2087 && GET_CODE (PATTERN (next)) == RETURN)
2092 [(set_attr "timings" "66")]
2095 ;; Try to combine consecutive updates of the stack pointer (or any
2096 ;; other register for that matter).
2098 [(parallel [(set (match_operand:SI 0 "register_operand" "=dxay")
2099 (plus:SI (match_dup 0)
2100 (match_operand 1 "const_int_operand" "")))
2101 (clobber (reg:CC CC_REG))
2103 (parallel [(set (match_dup 0)
2104 (plus:SI (match_dup 0)
2105 (match_operand 2 "const_int_operand" "")))
2106 (clobber (reg:CC CC_REG))
2112 operands[1] = GEN_INT (INTVAL (operands[2]) + INTVAL (operands[1]));
2113 return \"add %1,%0\";
2117 (define_expand "int_label"
2118 [(unspec [(match_operand:SI 0 "" "")] UNSPEC_INT_LABEL)]
2121 (define_expand "GOTaddr2picreg"
2125 /* It would be nice to be able to have int_label keep track of the
2126 counter and all, but if we add C code to it, we'll get an insn
2127 back, and we just want the pattern. */
2128 operands[0] = gen_int_label (GEN_INT (mn10300_unspec_int_label_counter++));
2130 emit_insn (gen_am33_loadPC (operands[0]));
2132 emit_insn (gen_mn10300_loadPC (operands[0]));
2133 emit_insn (gen_add_GOT_to_pic_reg (copy_rtx (operands[0])));
2138 (define_insn "am33_loadPC"
2140 [(set (reg:SI PIC_REG) (pc))
2141 (use (match_operand 0 "" ""))])]
2146 (define_insn_and_split "mn10300_loadPC"
2148 [(set (reg:SI PIC_REG) (pc))
2149 (use (match_operand 0 "" ""))])]
2152 "&& reload_completed"
2153 [(match_operand 0 "" "")]
2155 rtx sp_reg = gen_rtx_REG (SImode, SP_REG);
2156 int need_stack_space = (get_frame_size () == 0
2157 && crtl->outgoing_args_size == 0);
2159 if (need_stack_space)
2160 emit_insn (gen_addsi3 (sp_reg, sp_reg, GEN_INT (-4)));
2162 emit_insn (gen_call_next_insn (operands[0]));
2164 if (need_stack_space)
2165 emit_insn (gen_pop_pic_reg ());
2167 emit_move_insn (pic_offset_table_rtx, gen_rtx_MEM (SImode, sp_reg));
2172 (define_insn "call_next_insn"
2174 [(set (mem:SI (reg:SI SP_REG)) (pc))
2175 (use (match_operand 0 "" ""))])]
2178 [(set_attr "timings" "44")]
2181 (define_expand "add_GOT_to_pic_reg"
2182 [(parallel [(set (reg:SI PIC_REG)
2186 (unspec:SI [(minus:SI
2189 (const (match_operand:SI 0 "" ""))
2192 (clobber (reg:CC CC_REG))
2196 "operands[1] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);"
2199 (define_expand "add_GOT_to_any_reg"
2200 [(parallel [(set (match_operand:SI 0 "" "")
2202 (match_operand:SI 1 "" "")
2207 (const (match_operand:SI 2 "" ""))
2210 (clobber (reg:CC CC_REG))
2214 "operands[3] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);"