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.
44 (include "predicates.md")
45 (include "constraints.md")
47 ;; Processor type. This attribute must exactly match the processor_type
48 ;; enumeration in mn10300.h.
49 (define_attr "cpu" "mn10300,am33,am33_2,am34"
50 (const (symbol_ref "(enum attr_cpu) mn10300_tune_cpu")))
52 ;; Used to control the "enabled" attribute on a per-instruction basis.
53 (define_attr "isa" "base,am33,am33_2,am34"
54 (const_string "base"))
56 (define_attr "enabled" ""
57 (cond [(eq_attr "isa" "base")
60 (and (eq_attr "isa" "am33")
61 (ne (symbol_ref "TARGET_AM33") (const_int 0)))
64 (and (eq_attr "isa" "am33_2")
65 (ne (symbol_ref "TARGET_AM33_2") (const_int 0)))
68 (and (eq_attr "isa" "am34")
69 (ne (symbol_ref "TARGET_AM34") (const_int 0)))
75 (define_mode_iterator INT [QI HI SI])
78 ;; ----------------------------------------------------------------------
79 ;; Pipeline description.
80 ;; ----------------------------------------------------------------------
82 ;; The AM33 only has a single pipeline. It has five stages (fetch,
83 ;; decode, execute, memory access, writeback) each of which normally
84 ;; takes a single CPU clock cycle.
86 ;; The timings attribute consists of two numbers, the first is the
87 ;; throughput, which is the number of cycles the instruction takes
88 ;; to execute and generate a result. The second is the latency
89 ;; which is the effective number of cycles the instruction takes to
90 ;; execute if its result is used by the following instruction. The
91 ;; latency is always greater than or equal to the throughput.
92 ;; These values were taken from the Appendix of the "MN103E Series
93 ;; Instruction Manual" and the timings for the AM34.
95 ;; Note - it would be nice to use strings rather than integers for
96 ;; the possible values of this attribute, so that we can have the
97 ;; gcc build mechanism check for values that are not supported by
98 ;; the reservations below. But this will not work because the code
99 ;; in mn10300_adjust_sched_cost() needs integers not strings.
101 (define_attr "timings" "" (const_int 11))
103 (define_automaton "pipelining")
104 (define_cpu_unit "throughput" "pipelining")
106 (define_insn_reservation "throughput__1_latency__1" 1
107 (eq_attr "timings" "11") "throughput")
108 (define_insn_reservation "throughput__1_latency__2" 2
109 (eq_attr "timings" "12") "throughput,nothing")
110 (define_insn_reservation "throughput__1_latency__3" 3
111 (eq_attr "timings" "13") "throughput,nothing*2")
112 (define_insn_reservation "throughput__1_latency__4" 4
113 (eq_attr "timings" "14") "throughput,nothing*3")
114 (define_insn_reservation "throughput__2_latency__2" 2
115 (eq_attr "timings" "22") "throughput*2")
116 (define_insn_reservation "throughput__2_latency__3" 3
117 (eq_attr "timings" "23") "throughput*2,nothing")
118 (define_insn_reservation "throughput__2_latency__4" 4
119 (eq_attr "timings" "24") "throughput*2,nothing*2")
120 (define_insn_reservation "throughput__2_latency__5" 5
121 (eq_attr "timings" "25") "throughput*2,nothing*3")
122 (define_insn_reservation "throughput__3_latency__3" 3
123 (eq_attr "timings" "33") "throughput*3")
124 (define_insn_reservation "throughput__3_latency__7" 7
125 (eq_attr "timings" "37") "throughput*3,nothing*4")
126 (define_insn_reservation "throughput__4_latency__4" 4
127 (eq_attr "timings" "44") "throughput*4")
128 (define_insn_reservation "throughput__4_latency__7" 7
129 (eq_attr "timings" "47") "throughput*4,nothing*3")
130 (define_insn_reservation "throughput__4_latency__8" 8
131 (eq_attr "timings" "48") "throughput*4,nothing*4")
132 (define_insn_reservation "throughput__5_latency__5" 5
133 (eq_attr "timings" "55") "throughput*5")
134 (define_insn_reservation "throughput__6_latency__6" 6
135 (eq_attr "timings" "66") "throughput*6")
136 (define_insn_reservation "throughput__7_latency__7" 7
137 (eq_attr "timings" "77") "throughput*7")
138 (define_insn_reservation "throughput__7_latency__8" 8
139 (eq_attr "timings" "78") "throughput*7,nothing")
140 (define_insn_reservation "throughput__8_latency__8" 8
141 (eq_attr "timings" "88") "throughput*8")
142 (define_insn_reservation "throughput__9_latency__9" 9
143 (eq_attr "timings" "99") "throughput*9")
144 (define_insn_reservation "throughput__8_latency_14" 14
145 (eq_attr "timings" "814") "throughput*8,nothing*6")
146 (define_insn_reservation "throughput__9_latency_10" 10
147 (eq_attr "timings" "910") "throughput*9,nothing")
148 (define_insn_reservation "throughput_10_latency_10" 10
149 (eq_attr "timings" "1010") "throughput*10")
150 (define_insn_reservation "throughput_12_latency_16" 16
151 (eq_attr "timings" "1216") "throughput*12,nothing*4")
152 (define_insn_reservation "throughput_13_latency_13" 13
153 (eq_attr "timings" "1313") "throughput*13")
154 (define_insn_reservation "throughput_14_latency_14" 14
155 (eq_attr "timings" "1414") "throughput*14")
156 (define_insn_reservation "throughput_13_latency_17" 17
157 (eq_attr "timings" "1317") "throughput*13,nothing*4")
158 (define_insn_reservation "throughput_23_latency_27" 27
159 (eq_attr "timings" "2327") "throughput*23,nothing*4")
160 (define_insn_reservation "throughput_25_latency_31" 31
161 (eq_attr "timings" "2531") "throughput*25,nothing*6")
162 (define_insn_reservation "throughput_38_latency_39" 39
163 (eq_attr "timings" "3839") "throughput*38,nothing")
164 (define_insn_reservation "throughput_39_latency_40" 40
165 (eq_attr "timings" "3940") "throughput*39,nothing")
166 (define_insn_reservation "throughput_40_latency_40" 40
167 (eq_attr "timings" "4040") "throughput*40")
168 (define_insn_reservation "throughput_41_latency_42" 42
169 (eq_attr "timings" "4142") "throughput*41,nothing")
170 (define_insn_reservation "throughput_42_latency_43" 44
171 (eq_attr "timings" "4243") "throughput*42,nothing")
172 (define_insn_reservation "throughput_43_latency_44" 44
173 (eq_attr "timings" "4344") "throughput*43,nothing")
174 (define_insn_reservation "throughput_45_latency_46" 46
175 (eq_attr "timings" "4546") "throughput*45,nothing")
176 (define_insn_reservation "throughput_47_latency_53" 53
177 (eq_attr "timings" "4753") "throughput*47,nothing*6")
179 ;; Note - the conflict between memory load/store instructions
180 ;; and floating point instructions described in section 1-7-4
181 ;; of Chapter 3 of the MN103E Series Instruction Manual is
182 ;; handled by the mn10300_adjust_sched_cost function.
184 ;; ----------------------------------------------------------------------
186 ;; ----------------------------------------------------------------------
190 (define_expand "movqi"
191 [(set (match_operand:QI 0 "nonimmediate_operand")
192 (match_operand:QI 1 "general_operand"))]
195 /* One of the ops has to be in a register. */
196 if (!register_operand (operand0, QImode)
197 && !register_operand (operand1, QImode))
198 operands[1] = force_reg (QImode, operand1);
201 (define_insn "*movqi_internal"
202 [(set (match_operand:QI 0 "nonimmediate_operand" "=*r,D*r,D*r,D,m")
203 (match_operand:QI 1 "general_operand" " 0,D*r, i,m,D"))]
204 "(register_operand (operands[0], QImode)
205 || register_operand (operands[1], QImode))"
207 switch (which_alternative)
216 return "movbu %1,%0";
221 [(set_attr_alternative "timings"
225 (if_then_else (eq_attr "cpu" "am34")
226 (const_int 13) (const_int 24))
227 (if_then_else (eq_attr "cpu" "am34")
228 (const_int 11) (const_int 22))
234 (define_expand "movhi"
235 [(set (match_operand:HI 0 "nonimmediate_operand")
236 (match_operand:HI 1 "general_operand"))]
239 /* One of the ops has to be in a register. */
240 if (!register_operand (operand1, HImode)
241 && !register_operand (operand0, HImode))
242 operands[1] = force_reg (HImode, operand1);
245 (define_insn "*movhi_internal"
246 [(set (match_operand:HI 0 "nonimmediate_operand" "=*r,D*r,D*r,D,m")
247 (match_operand:HI 1 "general_operand" " 0, i,D*r,m,D"))]
248 "(register_operand (operands[0], HImode)
249 || register_operand (operands[1], HImode))"
251 switch (which_alternative)
256 /* Note that "MOV imm8,An" is already zero-extending, and is 2 bytes.
257 We have "MOV imm16,Dn" at 3 bytes. The only win for the 4 byte
258 movu is for an 8-bit unsigned move into Rn. */
260 && CONST_INT_P (operands[1])
261 && IN_RANGE (INTVAL (operands[1]), 0x80, 0xff)
262 && REGNO_EXTENDED_P (REGNO (operands[0]), 1))
269 return "movhu %1,%0";
274 [(set_attr_alternative "timings"
277 (if_then_else (eq_attr "cpu" "am34")
278 (const_int 11) (const_int 22))
279 (if_then_else (eq_attr "cpu" "am34")
280 (const_int 13) (const_int 24))
281 (if_then_else (eq_attr "cpu" "am34")
282 (const_int 11) (const_int 22))
288 ;; We use this to handle addition of two values when one operand is the
289 ;; stack pointer and the other is a memory reference of some kind. Reload
290 ;; does not handle them correctly without this expander.
291 (define_expand "reload_plus_sp_const"
292 [(set (match_operand:SI 0 "register_operand" "=r")
293 (match_operand:SI 1 "impossible_plus_operand" ""))
294 (clobber (match_operand:SI 2 "register_operand" "=&A"))]
297 rtx dest, scratch, other;
300 scratch = operands[2];
302 other = XEXP (operands[1], 1);
303 if (other == stack_pointer_rtx)
304 other = XEXP (operands[1], 0);
306 if (true_regnum (other) == true_regnum (dest))
308 gcc_assert (true_regnum (scratch) != true_regnum (dest));
309 emit_move_insn (scratch, stack_pointer_rtx);
310 emit_insn (gen_addsi3 (dest, dest, scratch));
312 else if (TARGET_AM33 || REGNO_REG_CLASS (true_regnum (dest)) == ADDRESS_REGS)
314 emit_move_insn (dest, stack_pointer_rtx);
315 if (other == stack_pointer_rtx)
316 emit_insn (gen_addsi3 (dest, dest, dest));
317 else if (other != const0_rtx)
318 emit_insn (gen_addsi3 (dest, dest, other));
322 emit_move_insn (scratch, stack_pointer_rtx);
323 if (other == stack_pointer_rtx)
325 emit_move_insn (dest, scratch);
326 emit_insn (gen_addsi3 (dest, dest, dest));
328 else if (other != const0_rtx)
330 emit_move_insn (dest, other);
331 emit_insn (gen_addsi3 (dest, dest, scratch));
334 emit_move_insn (dest, scratch);
339 (define_expand "movsi"
340 [(set (match_operand:SI 0 "nonimmediate_operand")
341 (match_operand:SI 1 "general_operand"))]
344 /* One of the ops has to be in a register. */
345 if (!register_operand (operand1, SImode)
346 && !register_operand (operand0, SImode))
347 operands[1] = force_reg (SImode, operand1);
351 if (SYMBOLIC_CONST_P (operands[1]))
353 if (MEM_P (operands[0]))
354 operands[1] = force_reg (Pmode, operands[1]);
357 temp = (!can_create_pseudo_p ()
359 : gen_reg_rtx (Pmode));
360 operands[1] = mn10300_legitimize_pic_address (operands[1], temp);
363 else if (GET_CODE (operands[1]) == CONST
364 && GET_CODE (XEXP (operands[1], 0)) == PLUS
365 && SYMBOLIC_CONST_P (XEXP (XEXP (operands[1], 0), 0)))
367 temp = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
368 temp = mn10300_legitimize_pic_address (XEXP (XEXP (operands[1], 0), 0),
370 operands[1] = expand_binop (SImode, add_optab, temp,
371 XEXP (XEXP (operands[1], 0), 1),
372 (!can_create_pseudo_p ()
374 : gen_reg_rtx (Pmode)),
380 (define_insn "*movsi_internal"
381 [(set (match_operand:SI 0 "nonimmediate_operand"
382 "=r,r,r,m,r, A,*y,*y,*z,*d")
383 (match_operand:SI 1 "general_operand"
384 " 0,i,r,r,m,*y, A, i,*d,*z"))]
385 "register_operand (operands[0], SImode)
386 || register_operand (operands[1], SImode)"
388 switch (which_alternative)
393 /* See movhi for a discussion of sizes for 8-bit movu. Note that the
394 24-bit movu is 6 bytes, which is the same size as the full 32-bit
395 mov form for An and Dn. So again movu is only a win for Rn. */
397 && CONST_INT_P (operands[1])
398 && REGNO_EXTENDED_P (REGNO (operands[0]), 1))
400 HOST_WIDE_INT val = INTVAL (operands[1]);
401 if (IN_RANGE (val, 0x80, 0xff)
402 || IN_RANGE (val, 0x800000, 0xffffff))
406 case 2: /* reg-reg */
407 case 3: /* reg-mem */
408 case 4: /* mem-reg */
412 case 8: /* reg-mdr */
413 case 9: /* mdr-reg */
419 [(set_attr "isa" "*,*,*,*,*,*,*,am33,*,*")
420 (set_attr_alternative "timings"
424 (if_then_else (eq_attr "cpu" "am34")
425 (const_int 11) (const_int 22))
426 (if_then_else (eq_attr "cpu" "am34")
427 (const_int 13) (const_int 24))
428 (if_then_else (eq_attr "cpu" "am34")
429 (const_int 11) (const_int 22))
430 (if_then_else (eq_attr "cpu" "am34")
431 (const_int 13) (const_int 24))
438 (define_expand "movsf"
439 [(set (match_operand:SF 0 "nonimmediate_operand")
440 (match_operand:SF 1 "general_operand"))]
443 /* One of the ops has to be in a register. */
444 if (!register_operand (operand1, SFmode)
445 && !register_operand (operand0, SFmode))
446 operands[1] = force_reg (SFmode, operand1);
449 (define_insn "*movsf_internal"
450 [(set (match_operand:SF 0 "nonimmediate_operand" "=rf,r,f,r,f,r,f,r,m,f,Q")
451 (match_operand:SF 1 "general_operand" " 0,F,F,r,f,f,r,m,r,Q,f"))]
453 && (register_operand (operands[0], SFmode)
454 || register_operand (operands[1], SFmode))"
456 switch (which_alternative)
476 [(set_attr_alternative "timings"
479 (if_then_else (eq_attr "cpu" "am34")
480 (const_int 47) (const_int 25))
482 (if_then_else (eq_attr "cpu" "am34")
483 (const_int 13) (const_int 14))
484 (if_then_else (eq_attr "cpu" "am34")
485 (const_int 13) (const_int 12))
486 (if_then_else (eq_attr "cpu" "am34")
487 (const_int 13) (const_int 14))
488 (if_then_else (eq_attr "cpu" "am34")
489 (const_int 13) (const_int 24))
490 (if_then_else (eq_attr "cpu" "am34")
491 (const_int 13) (const_int 24))
492 (if_then_else (eq_attr "cpu" "am34")
493 (const_int 13) (const_int 24))
494 (if_then_else (eq_attr "cpu" "am34")
495 (const_int 13) (const_int 24))
499 ;; If the flags register is not live, generate CLR instead of MOV 0.
500 ;; For MN103, this is only legal for DATA_REGS; for AM33 this is legal
501 ;; but not a win for ADDRESS_REGS.
503 [(set (match_operand:INT 0 "register_operand" "") (const_int 0))]
504 "peep2_regno_dead_p (0, CC_REG)
505 && (REGNO_DATA_P (REGNO (operands[0]), 1)
506 || REGNO_EXTENDED_P (REGNO (operands[0]), 1))"
507 [(parallel [(set (match_dup 0) (const_int 0))
508 (clobber (reg:CC CC_REG))])]
511 (define_insn "*mov<mode>_clr"
512 [(set (match_operand:INT 0 "register_operand" "=D")
514 (clobber (reg:CC CC_REG))]
519 ;; ----------------------------------------------------------------------
521 ;; ----------------------------------------------------------------------
523 (define_insn "addsi3"
524 [(set (match_operand:SI 0 "register_operand" "=r,!*y,!r")
525 (plus:SI (match_operand:SI 1 "register_operand" "%0, 0, r")
526 (match_operand:SI 2 "nonmemory_operand" "ri, i, r")))
527 (clobber (reg:CC CC_REG))]
529 { return mn10300_output_add (operands, false); }
530 [(set_attr "timings" "11,11,22")]
533 ;; Note that ADD IMM,SP does not set the flags, so omit that here.
534 (define_insn "*addsi3_flags"
535 [(set (match_operand:SI 0 "register_operand" "=r,!r")
536 (plus:SI (match_operand:SI 1 "register_operand" "%0, r")
537 (match_operand:SI 2 "nonmemory_operand" "ri, r")))
539 (compare (plus:SI (match_dup 1) (match_dup 2))
541 "reload_completed && mn10300_match_ccmode (insn, CCZNCmode)"
542 { return mn10300_output_add (operands, true); }
543 [(set_attr "timings" "11,22")]
546 ;; A helper to expand the above, with the CC_MODE filled in.
547 (define_expand "addsi3_flags"
548 [(parallel [(set (match_operand:SI 0 "register_operand")
549 (plus:SI (match_operand:SI 1 "register_operand")
550 (match_operand:SI 2 "nonmemory_operand")))
551 (set (reg:CCZNC CC_REG)
552 (compare:CCZNC (plus:SI (match_dup 1) (match_dup 2))
557 (define_insn "addc_internal"
558 [(set (match_operand:SI 0 "register_operand" "=D,r,r")
561 (ltu:SI (reg:CC CC_REG) (const_int 0))
562 (match_operand:SI 1 "register_operand" "%0,0,r"))
563 (match_operand:SI 2 "reg_or_am33_const_operand" " D,i,r")))
564 (clobber (reg:CC CC_REG))]
570 [(set_attr "isa" "*,am33,am33")]
573 (define_expand "adddi3"
574 [(set (match_operand:DI 0 "register_operand" "")
575 (plus:DI (match_operand:DI 1 "register_operand" "")
576 (match_operand:DI 2 "nonmemory_operand" "")))]
579 rtx op0l, op0h, op1l, op1h, op2l, op2h;
581 op0l = gen_lowpart (SImode, operands[0]);
582 op1l = gen_lowpart (SImode, operands[1]);
583 op2l = gen_lowpart (SImode, operands[2]);
584 op0h = gen_highpart (SImode, operands[0]);
585 op1h = gen_highpart (SImode, operands[1]);
586 op2h = gen_highpart_mode (SImode, DImode, operands[2]);
588 if (!reg_or_am33_const_operand (op2h, SImode))
589 op2h = force_reg (SImode, op2h);
591 emit_insn (gen_adddi3_internal (op0l, op0h, op1l, op2l, op1h, op2h));
595 ;; Note that reload only supports one commutative operand. Thus we cannot
596 ;; auto-swap both the high and low outputs with their matching constraints.
597 ;; For MN103, we're strapped for registers but thankfully the alternatives
598 ;; are few. For AM33, it becomes much easier to not represent the early
599 ;; clobber and 6 permutations of immediate and three-operand adds, but
600 ;; instead allocate a scratch register and do the expansion by hand.
602 (define_insn_and_split "adddi3_internal"
603 [(set (match_operand:SI 0 "register_operand" "=r, r, r")
604 (plus:SI (match_operand:SI 2 "register_operand" "%0, 0, r")
605 (match_operand:SI 3 "nonmemory_operand" "ri,ri,ri")))
606 (set (match_operand:SI 1 "register_operand" "=D, D, r")
609 (ltu:SI (plus:SI (match_dup 2) (match_dup 3)) (match_dup 2))
610 (match_operand:SI 4 "register_operand" " 1, D, r"))
611 (match_operand:SI 5 "reg_or_am33_const_operand" " D, 1,ri")))
612 (clobber (match_scratch:SI 6 "=X, X,&r"))
613 (clobber (reg:CC CC_REG))]
619 rtx op0l = operands[0];
620 rtx op0h = operands[1];
621 rtx op1l = operands[2];
622 rtx op2l = operands[3];
623 rtx op1h = operands[4];
624 rtx op2h = operands[5];
625 rtx scratch = operands[6];
628 if (reg_overlap_mentioned_p (op0l, op1h))
630 emit_move_insn (scratch, op0l);
632 if (reg_overlap_mentioned_p (op0l, op2h))
635 else if (reg_overlap_mentioned_p (op0l, op2h))
637 emit_move_insn (scratch, op0l);
641 if (rtx_equal_p (op0l, op1l))
643 else if (rtx_equal_p (op0l, op2l))
644 x = op1l, op1l = op2l, op2l = x;
647 gcc_assert (TARGET_AM33);
650 emit_move_insn (op0l, op2l);
655 emit_insn (gen_addsi3_flags (op0l, op1l, op2l));
657 if (rtx_equal_p (op0h, op1h))
659 else if (rtx_equal_p (op0h, op2h))
660 x = op1h, op1h = op2h, op2h = x;
663 gcc_assert (TARGET_AM33);
666 emit_move_insn (op0h, op2h);
671 emit_insn (gen_addc_internal (op0h, op1h, op2h));
674 [(set_attr "isa" "*,*,am33")]
677 ;; The following pattern is generated by combine when it proves that one
678 ;; of the inputs to the low-part of the double-word add is zero, and thus
679 ;; no carry is generated into the high-part.
681 (define_insn_and_split "*adddi3_degenerate"
682 [(set (match_operand:SI 0 "register_operand" "=&r,&r")
683 (match_operand:SI 2 "nonmemory_operand" " 0, 0"))
684 (set (match_operand:SI 1 "register_operand" "=r , r")
685 (plus:SI (match_operand:SI 3 "register_operand" "%1 , r")
686 (match_operand:SI 4 "nonmemory_operand" "ri, r")))
687 (clobber (reg:CC CC_REG))]
693 rtx scratch = NULL_RTX;
694 if (!rtx_equal_p (operands[0], operands[2]))
696 gcc_assert (!reg_overlap_mentioned_p (operands[0], operands[1]));
697 if (reg_overlap_mentioned_p (operands[0], operands[3])
698 || reg_overlap_mentioned_p (operands[0], operands[4]))
700 scratch = gen_reg_rtx (SImode);
701 emit_move_insn (scratch, operands[2]);
704 emit_move_insn (operands[0], operands[2]);
706 emit_insn (gen_addsi3 (operands[1], operands[3], operands[4]));
708 emit_move_insn (operands[0], scratch);
712 ;; ----------------------------------------------------------------------
713 ;; SUBTRACT INSTRUCTIONS
714 ;; ----------------------------------------------------------------------
716 (define_insn "subsi3"
717 [(set (match_operand:SI 0 "register_operand" "=r,r")
718 (minus:SI (match_operand:SI 1 "register_operand" " 0,r")
719 (match_operand:SI 2 "nonmemory_operand" "ri,r")))
720 (clobber (reg:CC CC_REG))]
725 [(set_attr "isa" "*,am33")
726 (set_attr "timings" "11,22")]
729 (define_insn "*subsi3_flags"
730 [(set (match_operand:SI 0 "register_operand" "=r,r")
731 (minus:SI (match_operand:SI 1 "register_operand" " 0,r")
732 (match_operand:SI 2 "nonmemory_operand" "ri,r")))
734 (compare (minus:SI (match_dup 1) (match_dup 2))
736 "reload_completed && mn10300_match_ccmode (insn, CCZNCmode)"
740 [(set_attr "isa" "*,am33")
741 (set_attr "timings" "11,22")]
744 ;; A helper to expand the above, with the CC_MODE filled in.
745 (define_expand "subsi3_flags"
746 [(parallel [(set (match_operand:SI 0 "register_operand")
747 (minus:SI (match_operand:SI 1 "register_operand")
748 (match_operand:SI 2 "nonmemory_operand")))
749 (set (reg:CCZNC CC_REG)
750 (compare:CCZNC (minus:SI (match_dup 1) (match_dup 2))
755 (define_insn "subc_internal"
756 [(set (match_operand:SI 0 "register_operand" "=D,r,r")
758 (minus:SI (match_operand:SI 1 "register_operand" " 0,0,r")
759 (match_operand:SI 2 "reg_or_am33_const_operand" " D,i,r"))
760 (geu:SI (reg:CC CC_REG) (const_int 0))))
761 (clobber (reg:CC CC_REG))]
767 [(set_attr "isa" "*,am33,am33")]
770 (define_expand "subdi3"
771 [(set (match_operand:DI 0 "register_operand" "")
772 (minus:DI (match_operand:DI 1 "register_operand" "")
773 (match_operand:DI 2 "nonmemory_operand" "")))]
776 rtx op0l, op0h, op1l, op1h, op2l, op2h;
778 op0l = gen_lowpart (SImode, operands[0]);
779 op1l = gen_lowpart (SImode, operands[1]);
780 op2l = gen_lowpart (SImode, operands[2]);
781 op0h = gen_highpart (SImode, operands[0]);
782 op1h = gen_highpart (SImode, operands[1]);
783 op2h = gen_highpart_mode (SImode, DImode, operands[2]);
785 if (!reg_or_am33_const_operand (op2h, SImode))
786 op2h = force_reg (SImode, op2h);
788 emit_insn (gen_subdi3_internal (op0l, op0h, op1l, op1h, op2l, op2h));
792 ;; As with adddi3, the use of the scratch register helps reduce the
793 ;; number of permutations for AM33.
794 ;; ??? The early clobber on op0 avoids a reload bug wherein both output
795 ;; registers are set the same. Consider negate, where both op2 and op3
796 ;; are 0, are csed to the same input register, and reload fails to undo
797 ;; the cse when satisfying the matching constraints.
799 (define_insn_and_split "subdi3_internal"
800 [(set (match_operand:SI 0 "register_operand" "=&r, r")
802 (match_operand:SI 2 "register_operand" " 0, r")
803 (match_operand:SI 4 "nonmemory_operand" " ri,ri")))
804 (set (match_operand:SI 1 "register_operand" "=D , r")
807 (match_operand:SI 3 "register_operand" " 1, r")
808 (match_operand:SI 5 "reg_or_am33_const_operand" " D,ri"))
809 (ltu:SI (match_dup 2) (match_dup 4))))
810 (clobber (match_scratch:SI 6 "=X ,&r"))
811 (clobber (reg:CC CC_REG))]
817 rtx op0l = operands[0];
818 rtx op0h = operands[1];
819 rtx op1l = operands[2];
820 rtx op1h = operands[3];
821 rtx op2l = operands[4];
822 rtx op2h = operands[5];
823 rtx scratch = operands[6];
825 if (reg_overlap_mentioned_p (op0l, op1h))
827 emit_move_insn (scratch, op0l);
829 if (reg_overlap_mentioned_p (op0l, op2h))
832 else if (reg_overlap_mentioned_p (op0l, op2h))
834 emit_move_insn (scratch, op0l);
838 if (!rtx_equal_p (op0l, op1l))
840 gcc_assert (TARGET_AM33);
843 emit_move_insn (op0l, op1l);
847 emit_insn (gen_subsi3_flags (op0l, op1l, op2l));
849 if (!rtx_equal_p (op0h, op1h))
851 gcc_assert (TARGET_AM33);
854 emit_move_insn (op0h, op1h);
858 emit_insn (gen_subc_internal (op0h, op1h, op2h));
861 [(set_attr "isa" "*,am33")]
864 ;; The following pattern is generated by combine when it proves that one
865 ;; of the inputs to the low-part of the double-word sub is zero, and thus
866 ;; no carry is generated into the high-part.
868 (define_insn_and_split "*subdi3_degenerate"
869 [(set (match_operand:SI 0 "register_operand" "=&r,&r")
870 (match_operand:SI 2 "nonmemory_operand" " 0, 0"))
871 (set (match_operand:SI 1 "register_operand" "=r , r")
872 (minus:SI (match_operand:SI 3 "register_operand" " 1, r")
873 (match_operand:SI 4 "nonmemory_operand" " ri, r")))
874 (clobber (reg:CC CC_REG))]
880 rtx scratch = NULL_RTX;
881 if (!rtx_equal_p (operands[0], operands[2]))
883 gcc_assert (!reg_overlap_mentioned_p (operands[0], operands[1]));
884 if (reg_overlap_mentioned_p (operands[0], operands[3])
885 || reg_overlap_mentioned_p (operands[0], operands[4]))
887 scratch = gen_reg_rtx (SImode);
888 emit_move_insn (scratch, operands[2]);
891 emit_move_insn (operands[0], operands[2]);
893 emit_insn (gen_subsi3 (operands[1], operands[3], operands[4]));
895 emit_move_insn (operands[0], scratch);
899 (define_insn_and_split "negsi2"
900 [(set (match_operand:SI 0 "register_operand" "=D,&r")
901 (neg:SI (match_operand:SI 1 "register_operand" " 0, r")))
902 (clobber (reg:CC CC_REG))]
905 "&& reload_completed"
908 /* Recall that twos-compliment is ones-compliment plus one. When
909 allocated in DATA_REGS this is 2+1 bytes; otherwise (for am33)
912 For AM33, it would have been possible to load zero and use the
913 three-address subtract to have a total size of 3+4*N bytes for
914 multiple negations, plus increased throughput. Not attempted here. */
916 if (true_regnum (operands[0]) == true_regnum (operands[1]))
918 emit_insn (gen_one_cmplsi2 (operands[0], operands[0]));
919 emit_insn (gen_addsi3 (operands[0], operands[0], const1_rtx));
923 emit_move_insn (operands[0], const0_rtx);
924 emit_insn (gen_subsi3 (operands[0], operands[0], operands[1]));
929 ;; ----------------------------------------------------------------------
930 ;; MULTIPLY INSTRUCTIONS
931 ;; ----------------------------------------------------------------------
933 ;; ??? Note that AM33 has a third multiply variant that puts the high part
934 ;; into the MDRQ register, however this variant also constrains the inputs
935 ;; to be in DATA_REGS and thus isn't as helpful as it might be considering
936 ;; the existance of the 4-operand multiply. Nor is there a set of divide
937 ;; insns that use MDRQ. Given that there is an IMM->MDRQ insn, this would
938 ;; have been very handy for starting udivmodsi4...
940 (define_expand "mulsidi3"
941 [(set (match_operand:DI 0 "register_operand" "")
942 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" ""))
943 (sign_extend:DI (match_operand:SI 2 "register_operand" ""))))]
946 emit_insn (gen_mulsidi3_internal (gen_lowpart (SImode, operands[0]),
947 gen_highpart (SImode, operands[0]),
948 operands[1], operands[2]));
952 (define_insn "mulsidi3_internal"
953 [(set (match_operand:SI 0 "register_operand" "=D,r")
954 (mult:SI (match_operand:SI 2 "register_operand" "%0,r")
955 (match_operand:SI 3 "register_operand" " D,r")))
956 (set (match_operand:SI 1 "register_operand" "=z,r")
959 (mult:DI (sign_extend:DI (match_dup 2))
960 (sign_extend:DI (match_dup 3)))
962 (clobber (reg:CC CC_REG))]
965 if (which_alternative == 1)
966 return "mul %2,%3,%1,%0";
967 else if (TARGET_MULT_BUG)
968 return "nop\;nop\;mul %3,%0";
972 [(set_attr "isa" "*,am33")
973 (set (attr "timings")
974 (if_then_else (eq_attr "cpu" "am34") (const_int 24) (const_int 23)))]
977 (define_expand "umulsidi3"
978 [(set (match_operand:DI 0 "register_operand" "")
979 (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" ""))
980 (zero_extend:DI (match_operand:SI 2 "register_operand" ""))))
981 (clobber (reg:CC CC_REG))]
984 emit_insn (gen_umulsidi3_internal (gen_lowpart (SImode, operands[0]),
985 gen_highpart (SImode, operands[0]),
986 operands[1], operands[2]));
990 (define_insn "umulsidi3_internal"
991 [(set (match_operand:SI 0 "register_operand" "=D,r")
992 (mult:SI (match_operand:SI 2 "register_operand" "%0,r")
993 (match_operand:SI 3 "register_operand" " D,r")))
994 (set (match_operand:SI 1 "register_operand" "=z,r")
997 (mult:DI (zero_extend:DI (match_dup 2))
998 (zero_extend:DI (match_dup 3)))
1000 (clobber (reg:CC CC_REG))]
1003 if (which_alternative == 1)
1004 return "mulu %2,%3,%1,%0";
1005 else if (TARGET_MULT_BUG)
1006 return "nop\;nop\;mulu %3,%0";
1008 return "mulu %3,%0";
1010 [(set_attr "isa" "*,am33")
1011 (set (attr "timings")
1012 (if_then_else (eq_attr "cpu" "am34") (const_int 24) (const_int 23)))]
1015 (define_expand "mulsi3"
1016 [(parallel [(set (match_operand:SI 0 "register_operand" "")
1017 (mult:SI (match_operand:SI 1 "register_operand" "")
1018 (match_operand:SI 2 "nonmemory_operand" "")))
1019 (clobber (match_scratch:SI 3 ""))
1020 (clobber (reg:CC CC_REG))])]
1024 (define_insn "*mulsi3"
1025 [(set (match_operand:SI 0 "register_operand" "=D, r,r")
1026 (mult:SI (match_operand:SI 2 "register_operand" "%0, 0,r")
1027 (match_operand:SI 3 "nonmemory_operand" " D,ri,r")))
1028 (clobber (match_scratch:SI 1 "=z, z,r"))
1029 (clobber (reg:CC CC_REG))]
1032 if (which_alternative == 2)
1033 return "mul %2,%3,%1,%0";
1034 else if (TARGET_MULT_BUG)
1035 return "nop\;nop\;mul %3,%0";
1039 [(set_attr "isa" "*,am33,am33")
1040 (set (attr "timings")
1041 (if_then_else (eq_attr "cpu" "am34") (const_int 24) (const_int 23)))]
1044 (define_expand "udivmodsi4"
1045 [(parallel [(set (match_operand:SI 0 "register_operand")
1046 (udiv:SI (match_operand:SI 1 "register_operand")
1047 (match_operand:SI 2 "register_operand")))
1048 (set (match_operand:SI 3 "register_operand")
1049 (umod:SI (match_dup 1) (match_dup 2)))
1051 (clobber (reg:CC CC_REG))])]
1055 ;; Note the trick to get reload to put the zero into the MDR register,
1056 ;; rather than exposing the load early and letting CSE or someone try
1057 ;; to share the zeros between division insns. Which tends to result
1058 ;; in sequences like 0->r0->d0->mdr.
1060 (define_insn "*udivmodsi4"
1061 [(set (match_operand:SI 0 "register_operand" "=D")
1062 (udiv:SI (match_operand:SI 2 "register_operand" " 0")
1063 (match_operand:SI 3 "register_operand" " D")))
1064 (set (match_operand:SI 1 "register_operand" "=z")
1065 (umod:SI (match_dup 2) (match_dup 3)))
1066 (use (match_operand:SI 4 "nonmemory_operand" " 1"))
1067 (clobber (reg:CC CC_REG))]
1070 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1071 (const_int 3839) (const_int 4243)))]
1074 (define_expand "divmodsi4"
1075 [(parallel [(set (match_operand:SI 0 "register_operand" "")
1076 (div:SI (match_operand:SI 1 "register_operand" "")
1077 (match_operand:SI 2 "register_operand" "")))
1078 (set (match_operand:SI 3 "register_operand" "")
1079 (mod:SI (match_dup 1) (match_dup 2)))
1081 (clobber (reg:CC CC_REG))])]
1084 operands[4] = gen_reg_rtx (SImode);
1085 emit_insn (gen_ext_internal (operands[4], operands[1]));
1088 ;; ??? Ideally we'd represent this via shift, but it seems like adding a
1089 ;; special-case pattern for (ashiftrt x 31) is just as likely to result
1090 ;; in poor register allocation choices.
1091 (define_insn "ext_internal"
1092 [(set (match_operand:SI 0 "register_operand" "=z")
1093 (unspec:SI [(match_operand:SI 1 "register_operand" "D")] UNSPEC_EXT))]
1098 (define_insn "*divmodsi4"
1099 [(set (match_operand:SI 0 "register_operand" "=D")
1100 (div:SI (match_operand:SI 2 "register_operand" " 0")
1101 (match_operand:SI 3 "register_operand" " D")))
1102 (set (match_operand:SI 1 "register_operand" "=z")
1103 (mod:SI (match_dup 2) (match_dup 3)))
1104 (use (match_operand:SI 4 "register_operand" " 1"))
1105 (clobber (reg:CC CC_REG))]
1108 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1109 (const_int 3839) (const_int 4243)))]
1113 ;; ----------------------------------------------------------------------
1115 ;; ----------------------------------------------------------------------
1117 (define_insn "andsi3"
1118 [(set (match_operand:SI 0 "register_operand" "=D,D,r")
1119 (and:SI (match_operand:SI 1 "register_operand" "%0,0,r")
1120 (match_operand:SI 2 "nonmemory_operand" " i,D,r")))
1121 (clobber (reg:CC CC_REG))]
1127 [(set_attr "isa" "*,*,am33")
1128 (set_attr "timings" "22,11,11")]
1131 (define_insn "*andsi3_flags"
1132 [(set (match_operand:SI 0 "register_operand" "=D,D,r")
1133 (and:SI (match_operand:SI 1 "register_operand" "%0,0,r")
1134 (match_operand:SI 2 "nonmemory_operand" " i,D,r")))
1136 (compare (and:SI (match_dup 1) (match_dup 2))
1138 "reload_completed && mn10300_match_ccmode (insn, CCZNmode)"
1143 [(set_attr "isa" "*,*,am33")
1144 (set_attr "timings" "22,11,11")]
1147 ;; Make sure we generate extensions instead of ANDs.
1150 [(parallel [(set (match_operand:SI 0 "register_operand" "")
1151 (and:SI (match_operand:SI 1 "register_operand" "")
1153 (clobber (reg:CC CC_REG))])]
1155 [(set (match_dup 0) (zero_extend:SI (match_dup 1)))]
1156 { operands[1] = gen_lowpart (QImode, operands[1]); }
1160 [(parallel [(set (match_operand:SI 0 "register_operand" "")
1161 (and:SI (match_operand:SI 1 "register_operand" "")
1163 (clobber (reg:CC CC_REG))])]
1165 [(set (match_dup 0) (zero_extend:SI (match_dup 1)))]
1166 { operands[1] = gen_lowpart (HImode, operands[1]); }
1169 ;; Split AND by an appropriate constant into two shifts. Recall that
1170 ;; operations with a full 32-bit immediate require an extra cycle, so
1171 ;; this is a size optimization with no speed penalty. This only applies
1172 ;; do DATA_REGS; the shift insns that AM33 adds are too large for a win.
1175 [(parallel [(set (match_operand:SI 0 "register_operand" "")
1176 (and:SI (match_dup 0)
1177 (match_operand:SI 1 "const_int_operand" "")))
1178 (clobber (reg:CC CC_REG))])]
1180 && REGNO_DATA_P (true_regnum (operands[0]), 1)
1181 && mn10300_split_and_operand_count (operands[1]) != 0"
1184 int count = mn10300_split_and_operand_count (operands[1]);
1187 emit_insn (gen_lshrsi3 (operands[0], operands[0], GEN_INT (count)));
1188 emit_insn (gen_ashlsi3 (operands[0], operands[0], GEN_INT (count)));
1192 emit_insn (gen_ashlsi3 (operands[0], operands[0], GEN_INT (-count)));
1193 emit_insn (gen_lshrsi3 (operands[0], operands[0], GEN_INT (-count)));
1198 ;; ----------------------------------------------------------------------
1200 ;; ----------------------------------------------------------------------
1202 (define_insn "iorsi3"
1203 [(set (match_operand:SI 0 "register_operand" "=D,D,r")
1204 (ior:SI (match_operand:SI 1 "register_operand" "%0,0,r")
1205 (match_operand:SI 2 "nonmemory_operand" " i,D,r")))
1206 (clobber (reg:CC CC_REG))]
1212 [(set_attr "isa" "*,*,am33")
1213 (set_attr "timings" "22,11,11")]
1216 (define_insn "*iorsi3_flags"
1217 [(set (match_operand:SI 0 "register_operand" "=D,D,r")
1218 (ior:SI (match_operand:SI 1 "register_operand" "%0,0,r")
1219 (match_operand:SI 2 "nonmemory_operand" " i,D,r")))
1221 (compare (ior:SI (match_dup 1) (match_dup 2))
1223 "reload_completed && mn10300_match_ccmode (insn, CCZNmode)"
1228 [(set_attr "isa" "*,*,am33")
1229 (set_attr "timings" "22,11,11")]
1232 ;; ----------------------------------------------------------------------
1234 ;; ----------------------------------------------------------------------
1236 (define_insn "xorsi3"
1237 [(set (match_operand:SI 0 "register_operand" "=D,D,r")
1238 (xor:SI (match_operand:SI 1 "register_operand" "%0,0,r")
1239 (match_operand:SI 2 "nonmemory_operand" " i,D,r")))
1240 (clobber (reg:CC CC_REG))]
1246 [(set_attr "isa" "*,*,am33")
1247 (set_attr "timings" "22,11,11")]
1250 (define_insn "*xorsi3_flags"
1251 [(set (match_operand:SI 0 "register_operand" "=D,D,r")
1252 (xor:SI (match_operand:SI 1 "register_operand" "%0,0,r")
1253 (match_operand:SI 2 "nonmemory_operand" " i,D,r")))
1255 (compare (xor:SI (match_dup 1) (match_dup 2))
1257 "reload_completed && mn10300_match_ccmode (insn, CCZNmode)"
1262 [(set_attr "isa" "*,*,am33")
1263 (set_attr "timings" "22,11,11")]
1266 ;; ----------------------------------------------------------------------
1268 ;; ----------------------------------------------------------------------
1270 (define_insn "one_cmplsi2"
1271 [(set (match_operand:SI 0 "register_operand" "=D")
1272 (not:SI (match_operand:SI 1 "register_operand" " 0")))
1273 (clobber (reg:CC CC_REG))]
1278 (define_insn "*one_cmplsi2_flags"
1279 [(set (match_operand:SI 0 "register_operand" "=D")
1280 (not:SI (match_operand:SI 1 "register_operand" " 0")))
1282 (compare (not:SI (match_dup 1))
1284 "reload_completed && mn10300_match_ccmode (insn, CCZNmode)"
1288 ;; ----------------------------------------------------------------------
1289 ;; COMPARE AND BRANCH INSTRUCTIONS
1290 ;; ----------------------------------------------------------------------
1292 ;; We expand the comparison into a single insn so that it will not be split
1294 (define_expand "cbranchsi4"
1297 (match_operator 0 "ordered_comparison_operator"
1298 [(match_operand:SI 1 "register_operand")
1299 (match_operand:SI 2 "nonmemory_operand")])
1300 (label_ref (match_operand 3 ""))
1306 (define_insn_and_split "*cbranchsi4_cmp"
1308 (if_then_else (match_operator 3 "ordered_comparison_operator"
1309 [(match_operand:SI 0 "register_operand" "r")
1310 (match_operand:SI 1 "nonmemory_operand" "ri")])
1311 (match_operand 2 "label_ref_operand" "")
1318 mn10300_split_cbranch (CCmode, operands[3], operands[2]);
1322 (define_insn "*cmpsi"
1324 (compare (match_operand:SI 0 "register_operand" "r")
1325 (match_operand:SI 1 "nonmemory_operand" "ri")))]
1328 /* The operands of CMP must be distinct registers. In the case where
1329 we've failed to optimize the comparison of a register to itself, we
1330 must use another method to set the Z flag. We can achieve this
1331 effect with a BTST 0,D0. This will not alter the contents of D0;
1332 the use of d0 is arbitrary; any data register would work. */
1333 if (rtx_equal_p (operands[0], operands[1]))
1338 [(set_attr_alternative "timings"
1339 [(if_then_else (eq_attr "cpu" "am34") (const_int 11) (const_int 22))])]
1342 (define_insn "*integer_conditional_branch"
1344 (if_then_else (match_operator 0 "comparison_operator"
1345 [(match_operand 2 "int_mode_flags" "")
1347 (label_ref (match_operand 1 "" ""))
1353 (define_insn_and_split "*cbranchsi4_btst"
1356 (match_operator 3 "CCZN_comparison_operator"
1357 [(and:SI (match_operand:SI 0 "register_operand" "D")
1358 (match_operand:SI 1 "immediate_operand" "i"))
1360 (match_operand 2 "label_ref_operand" "")
1367 mn10300_split_cbranch (CCZNmode, operands[3], operands[2]);
1371 (define_insn "*btstsi"
1372 [(set (reg:CCZN CC_REG)
1374 (and:SI (match_operand:SI 0 "register_operand" "D")
1375 (match_operand:SI 1 "immediate_operand" "i"))
1381 (define_expand "cbranchsf4"
1384 (match_operator 0 "ordered_comparison_operator"
1385 [(match_operand:SF 1 "register_operand")
1386 (match_operand:SF 2 "nonmemory_operand")])
1387 (label_ref (match_operand 3 ""))
1393 (define_insn_and_split "*cbranchsf4_cmp"
1395 (if_then_else (match_operator 3 "ordered_comparison_operator"
1396 [(match_operand:SF 0 "register_operand" "f")
1397 (match_operand:SF 1 "nonmemory_operand" "fF")])
1398 (match_operand 2 "label_ref_operand" "")
1403 "&& reload_completed"
1406 mn10300_split_cbranch (CC_FLOATmode, operands[3], operands[2]);
1410 (define_insn "*am33_cmpsf"
1411 [(set (reg:CC_FLOAT CC_REG)
1412 (compare:CC_FLOAT (match_operand:SF 0 "register_operand" "f")
1413 (match_operand:SF 1 "nonmemory_operand" "fF")))]
1414 "TARGET_AM33_2 && reload_completed"
1416 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1417 (const_int 17) (const_int 25)))]
1420 (define_insn "*float_conditional_branch"
1422 (if_then_else (match_operator 0 "comparison_operator"
1423 [(reg:CC_FLOAT CC_REG) (const_int 0)])
1424 (label_ref (match_operand 1 "" ""))
1426 "TARGET_AM33_2 && reload_completed"
1428 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1429 (const_int 44) (const_int 33)))]
1432 ;; Unconditional and other jump instructions.
1436 (label_ref (match_operand 0 "" "")))]
1439 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1440 (const_int 11) (const_int 44)))]
1443 (define_insn "indirect_jump"
1444 [(set (pc) (match_operand:SI 0 "register_operand" "a"))]
1447 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1448 (const_int 11) (const_int 33)))]
1451 (define_expand "builtin_setjmp_receiver"
1452 [(match_operand 0 "" "")]
1455 emit_insn (gen_load_pic ());
1459 (define_expand "casesi"
1460 [(match_operand:SI 0 "register_operand")
1461 (match_operand:SI 1 "immediate_operand")
1462 (match_operand:SI 2 "immediate_operand")
1463 (match_operand 3 "" "") (match_operand 4 "")]
1466 rtx table = gen_reg_rtx (SImode);
1467 rtx index = gen_reg_rtx (SImode);
1468 rtx addr = gen_reg_rtx (Pmode);
1471 emit_move_insn (table, gen_rtx_LABEL_REF (VOIDmode, operands[3]));
1472 emit_insn (gen_addsi3 (index, operands[0], GEN_INT (- INTVAL (operands[1]))));
1473 test = gen_rtx_fmt_ee (GTU, VOIDmode, index, operands[2]);
1474 emit_jump_insn (gen_cbranchsi4 (test, index, operands[2], operands[4]));
1476 emit_insn (gen_ashlsi3 (index, index, const2_rtx));
1477 emit_move_insn (addr, gen_rtx_MEM (SImode,
1478 gen_rtx_PLUS (SImode, table, index)));
1480 emit_insn (gen_addsi3 (addr, addr, table));
1482 emit_jump_insn (gen_tablejump (addr, operands[3]));
1486 (define_insn "tablejump"
1487 [(set (pc) (match_operand:SI 0 "register_operand" "a"))
1488 (use (label_ref (match_operand 1 "" "")))]
1491 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1492 (const_int 11) (const_int 33)))]
1495 ;; Call subroutine with no return value.
1497 (define_expand "call"
1498 [(call (match_operand:QI 0 "general_operand")
1499 (match_operand:SI 1 "general_operand"))]
1502 rtx fn = XEXP (operands[0], 0);
1504 if (flag_pic && GET_CODE (fn) == SYMBOL_REF)
1506 if (MN10300_GLOBAL_P (fn))
1508 /* The PLT code won't run on AM30, but then, there's no
1509 shared library support for AM30 either, so we just assume
1510 the linker is going to adjust all @PLT relocs to the
1512 emit_use (pic_offset_table_rtx);
1513 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PLT);
1516 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PIC);
1518 if (! call_address_operand (fn, VOIDmode))
1519 fn = force_reg (SImode, fn);
1521 XEXP (operands[0], 0) = fn;
1524 (define_insn "*call_internal"
1525 [(call (mem:QI (match_operand:SI 0 "call_address_operand" "a,S"))
1526 (match_operand:SI 1 "" ""))]
1531 [(set_attr_alternative "timings"
1532 [(if_then_else (eq_attr "cpu" "am34")
1533 (const_int 33) (const_int 44))
1534 (if_then_else (eq_attr "cpu" "am34")
1535 (const_int 55) (const_int 33))
1540 ;; Call subroutine, returning value in operand 0
1541 ;; (which must be a hard register).
1543 (define_expand "call_value"
1544 [(set (match_operand 0 "")
1545 (call (match_operand:QI 1 "general_operand")
1546 (match_operand:SI 2 "general_operand")))]
1549 rtx fn = XEXP (operands[1], 0);
1551 if (flag_pic && GET_CODE (fn) == SYMBOL_REF)
1553 if (MN10300_GLOBAL_P (fn))
1555 /* The PLT code won't run on AM30, but then, there's no
1556 shared library support for AM30 either, so we just assume
1557 the linker is going to adjust all @PLT relocs to the
1559 emit_use (pic_offset_table_rtx);
1560 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PLT);
1563 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PIC);
1565 if (! call_address_operand (fn, VOIDmode))
1566 fn = force_reg (SImode, fn);
1568 XEXP (operands[1], 0) = fn;
1571 (define_insn "call_value_internal"
1572 [(set (match_operand 0 "" "")
1573 (call (mem:QI (match_operand:SI 1 "call_address_operand" "a,S"))
1574 (match_operand:SI 2 "" "")))]
1579 [(set_attr_alternative "timings"
1580 [(if_then_else (eq_attr "cpu" "am34")
1581 (const_int 33) (const_int 44))
1582 (if_then_else (eq_attr "cpu" "am34")
1583 (const_int 55) (const_int 33))
1588 (define_expand "untyped_call"
1589 [(parallel [(call (match_operand 0 "")
1591 (match_operand 1 "")
1592 (match_operand 2 "")])]
1597 emit_call_insn (gen_call (operands[0], const0_rtx));
1599 for (i = 0; i < XVECLEN (operands[2], 0); i++)
1601 rtx set = XVECEXP (operands[2], 0, i);
1602 emit_move_insn (SET_DEST (set), SET_SRC (set));
1613 ;; ----------------------------------------------------------------------
1614 ;; EXTEND INSTRUCTIONS
1615 ;; ----------------------------------------------------------------------
1617 (define_insn "zero_extendqisi2"
1618 [(set (match_operand:SI 0 "register_operand" "=D,D,r")
1620 (match_operand:QI 1 "nonimmediate_operand" " 0,m,r")))]
1626 [(set_attr "isa" "*,*,am33")
1627 (set_attr_alternative "timings"
1629 (if_then_else (eq_attr "cpu" "am34")
1630 (const_int 13) (const_int 24))
1635 (define_insn "zero_extendhisi2"
1636 [(set (match_operand:SI 0 "register_operand" "=D,D,r")
1638 (match_operand:HI 1 "nonimmediate_operand" " 0,m,r")))]
1644 [(set_attr "isa" "*,*,am33")
1645 (set_attr_alternative "timings"
1647 (if_then_else (eq_attr "cpu" "am34")
1648 (const_int 13) (const_int 24))
1652 (define_insn "extendqisi2"
1653 [(set (match_operand:SI 0 "register_operand" "=D,r")
1655 (match_operand:QI 1 "register_operand" "0,r")))]
1660 [(set_attr "isa" "*,am33")]
1663 (define_insn "extendhisi2"
1664 [(set (match_operand:SI 0 "register_operand" "=D,r")
1666 (match_operand:HI 1 "register_operand" "0,r")))]
1671 [(set_attr "isa" "*,am33")]
1674 ;; ----------------------------------------------------------------------
1676 ;; ----------------------------------------------------------------------
1678 (define_insn "ashlsi3"
1679 [(set (match_operand:SI 0 "register_operand" "=r,D,d,d, D,r")
1681 (match_operand:SI 1 "register_operand" " 0,0,0,0, 0,r")
1682 (match_operand:QI 2 "nonmemory_operand" " J,K,M,L,Di,r")))
1683 (clobber (reg:CC CC_REG))]
1692 [(set_attr "isa" "*,*,*,*,*,am33")
1693 (set_attr "timings" "11,11,22,22,11,11")]
1696 (define_insn "lshrsi3"
1697 [(set (match_operand:SI 0 "register_operand" "=D,r")
1699 (match_operand:SI 1 "register_operand" " 0,r")
1700 (match_operand:QI 2 "nonmemory_operand" "Di,r")))
1701 (clobber (reg:CC CC_REG))]
1706 [(set_attr "isa" "*,am33")]
1709 (define_insn "ashrsi3"
1710 [(set (match_operand:SI 0 "register_operand" "=D,r")
1712 (match_operand:SI 1 "register_operand" " 0,r")
1713 (match_operand:QI 2 "nonmemory_operand" "Di,r")))
1714 (clobber (reg:CC CC_REG))]
1719 [(set_attr "isa" "*,am33")]
1722 ;; ----------------------------------------------------------------------
1724 ;; ----------------------------------------------------------------------
1726 (define_expand "clzsi2"
1727 [(parallel [(set (match_operand:SI 0 "register_operand" "")
1728 (unspec:SI [(match_operand:SI 1 "register_operand" "")
1729 (const_int 0)] UNSPEC_BSCH))
1730 (clobber (reg:CC CC_REG))])]
1734 (define_insn "*bsch"
1735 [(set (match_operand:SI 0 "register_operand" "=r")
1736 (unspec:SI [(match_operand:SI 1 "register_operand" "r")
1737 (match_operand:SI 2 "nonmemory_operand" "0")]
1739 (clobber (reg:CC CC_REG))]
1744 ;; ----------------------------------------------------------------------
1746 ;; ----------------------------------------------------------------------
1748 (define_insn "abssf2"
1749 [(set (match_operand:SF 0 "register_operand" "=f,f")
1750 (abs:SF (match_operand:SF 1 "register_operand" "0,?f")))]
1755 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1756 (const_int 17) (const_int 14)))]
1759 (define_insn "negsf2"
1760 [(set (match_operand:SF 0 "register_operand" "=f,f")
1761 (neg:SF (match_operand:SF 1 "register_operand" "0,?f")))]
1766 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1767 (const_int 17) (const_int 14)))]
1770 (define_expand "sqrtsf2"
1771 [(set (match_operand:SF 0 "register_operand" "")
1772 (sqrt:SF (match_operand:SF 1 "register_operand" "")))]
1773 "TARGET_AM33_2 && flag_unsafe_math_optimizations"
1775 rtx scratch = gen_reg_rtx (SFmode);
1776 emit_insn (gen_rsqrtsf2 (scratch, operands[1], CONST1_RTX (SFmode)));
1777 emit_insn (gen_divsf3 (operands[0], force_reg (SFmode, CONST1_RTX (SFmode)),
1782 (define_insn "rsqrtsf2"
1783 [(set (match_operand:SF 0 "register_operand" "=f,f")
1784 (div:SF (match_operand:SF 2 "const_1f_operand" "F,F")
1785 (sqrt:SF (match_operand:SF 1 "register_operand" "0,?f"))))
1786 (clobber (reg:CC_FLOAT CC_REG))]
1791 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1792 (const_int 4753) (const_int 2327)))]
1795 (define_insn "addsf3"
1796 [(set (match_operand:SF 0 "register_operand" "=f,f")
1797 (plus:SF (match_operand:SF 1 "register_operand" "%0,f")
1798 (match_operand:SF 2 "nonmemory_operand" "f,?fF")))
1799 (clobber (reg:CC_FLOAT CC_REG))]
1804 [(set_attr_alternative "timings"
1805 [(if_then_else (eq_attr "cpu" "am34")
1806 (const_int 17) (const_int 14))
1807 (if_then_else (eq_attr "cpu" "am34")
1808 (const_int 17) (const_int 25))
1812 (define_insn "subsf3"
1813 [(set (match_operand:SF 0 "register_operand" "=f,f")
1814 (minus:SF (match_operand:SF 1 "register_operand" "0,f")
1815 (match_operand:SF 2 "nonmemory_operand" "f,?fF")))
1816 (clobber (reg:CC_FLOAT CC_REG))]
1821 [(set_attr_alternative "timings"
1822 [(if_then_else (eq_attr "cpu" "am34")
1823 (const_int 17) (const_int 14))
1824 (if_then_else (eq_attr "cpu" "am34")
1825 (const_int 17) (const_int 25))
1829 (define_insn "mulsf3"
1830 [(set (match_operand:SF 0 "register_operand" "=f,f")
1831 (mult:SF (match_operand:SF 1 "register_operand" "%0,f")
1832 (match_operand:SF 2 "nonmemory_operand" "f,?fF")))
1833 (clobber (reg:CC_FLOAT CC_REG))
1839 [(set_attr_alternative "timings"
1840 [(if_then_else (eq_attr "cpu" "am34")
1841 (const_int 17) (const_int 14))
1842 (if_then_else (eq_attr "cpu" "am34")
1843 (const_int 17) (const_int 25))
1847 (define_insn "divsf3"
1848 [(set (match_operand:SF 0 "register_operand" "=f,f")
1849 (div:SF (match_operand:SF 1 "register_operand" "0,f")
1850 (match_operand:SF 2 "nonmemory_operand" "f,?fF")))
1851 (clobber (reg:CC_FLOAT CC_REG))]
1856 [(set_attr_alternative "timings"
1857 [(if_then_else (eq_attr "cpu" "am34")
1858 (const_int 2531) (const_int 1216))
1859 (if_then_else (eq_attr "cpu" "am34")
1860 (const_int 2531) (const_int 1317))
1864 (define_insn "fmasf4"
1865 [(set (match_operand:SF 0 "register_operand" "=c")
1866 (fma:SF (match_operand:SF 1 "register_operand" "f")
1867 (match_operand:SF 2 "register_operand" "f")
1868 (match_operand:SF 3 "register_operand" "f")))
1869 (clobber (reg:CC_FLOAT CC_REG))
1872 "fmadd %1, %2, %3, %0"
1873 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1874 (const_int 17) (const_int 24)))]
1877 (define_insn "fmssf4"
1878 [(set (match_operand:SF 0 "register_operand" "=c")
1879 (fma:SF (match_operand:SF 1 "register_operand" "f")
1880 (match_operand:SF 2 "register_operand" "f")
1881 (neg:SF (match_operand:SF 3 "register_operand" "f"))))
1882 (clobber (reg:CC_FLOAT CC_REG))
1885 "fmsub %1, %2, %3, %0"
1886 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1887 (const_int 17) (const_int 24)))]
1890 (define_insn "fnmasf4"
1891 [(set (match_operand:SF 0 "register_operand" "=c")
1892 (fma:SF (neg:SF (match_operand:SF 1 "register_operand" "f"))
1893 (match_operand:SF 2 "register_operand" "f")
1894 (match_operand:SF 3 "register_operand" "f")))
1895 (clobber (reg:CC_FLOAT CC_REG))
1898 "fnmadd %1, %2, %3, %0"
1899 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1900 (const_int 17) (const_int 24)))]
1903 (define_insn "fnmssf4"
1904 [(set (match_operand:SF 0 "register_operand" "=c")
1905 (fma:SF (neg:SF (match_operand:SF 1 "register_operand" "f"))
1906 (match_operand:SF 2 "register_operand" "f")
1907 (neg:SF (match_operand:SF 3 "register_operand" "f"))))
1908 (clobber (reg:CC_FLOAT CC_REG))
1911 "fnmsub %1, %2, %3, %0"
1912 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1913 (const_int 17) (const_int 24)))]
1916 ;; ----------------------------------------------------------------------
1917 ;; PROLOGUE/EPILOGUE
1918 ;; ----------------------------------------------------------------------
1919 (define_expand "prologue"
1922 { mn10300_expand_prologue (); DONE; }
1925 (define_expand "epilogue"
1928 { mn10300_expand_epilogue (); DONE; }
1931 (define_insn "return"
1933 "mn10300_can_use_rets_insn ()"
1935 /* The RETF insn is 4 cycles faster than RETS, though 1 byte larger. */
1936 if (optimize_insn_for_speed_p () && mn10300_can_use_retf_insn ())
1942 (define_insn "return_ret"
1944 (use (match_operand:SI 0 "const_int_operand" ""))]
1947 /* The RETF insn is up to 3 cycles faster than RET. */
1948 fputs ((mn10300_can_use_retf_insn () ? "\tretf " : "\tret "), asm_out_file);
1949 mn10300_print_reg_list (asm_out_file, mn10300_get_live_callee_saved_regs ());
1950 fprintf (asm_out_file, ",%d\n", (int) INTVAL (operands[0]));
1954 ;; This instruction matches one generated by mn10300_gen_multiple_store()
1955 (define_insn "store_movm"
1956 [(match_parallel 0 "mn10300_store_multiple_operation"
1957 [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (match_operand 1 "" "")))])]
1960 fputs ("\tmovm ", asm_out_file);
1961 mn10300_print_reg_list (asm_out_file,
1962 mn10300_store_multiple_operation (operands[0],
1964 fprintf (asm_out_file, ",(sp)\n");
1967 ;; Assume that no more than 8 registers will be pushed.
1968 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1969 (const_int 99) (const_int 88)))]
1972 (define_expand "load_pic"
1977 emit_insn (gen_am33_load_pic (pic_offset_table_rtx));
1978 else if (mn10300_frame_size () == 0)
1979 emit_insn (gen_mn10300_load_pic0 (pic_offset_table_rtx));
1981 emit_insn (gen_mn10300_load_pic1 (pic_offset_table_rtx));
1985 (define_insn "am33_load_pic"
1986 [(set (match_operand:SI 0 "register_operand" "=a")
1987 (unspec:SI [(const_int 0)] UNSPEC_GOT))
1988 (clobber (reg:CC CC_REG))]
1991 operands[1] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);
1992 return ".LPIC%=:\;mov pc,%0\;add %1-(.LPIC%=-.),%0";
1994 [(set_attr "timings" "33")]
1997 ;; Load pic register with push/pop of stack.
1998 (define_insn "mn10300_load_pic0"
1999 [(set (match_operand:SI 0 "register_operand" "=a")
2000 (unspec:SI [(const_int 0)] UNSPEC_GOT))
2001 (clobber (reg:SI MDR_REG))
2002 (clobber (reg:CC CC_REG))]
2005 operands[1] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);
2006 return ("add -4,sp\;"
2010 "add %1-(.LPIC%=-.),%0");
2012 [(set_attr "timings" "88")]
2015 ;; Load pic register re-using existing stack space.
2016 (define_insn "mn10300_load_pic1"
2017 [(set (match_operand:SI 0 "register_operand" "=a")
2018 (unspec:SI [(const_int 0)] UNSPEC_GOT))
2019 (clobber (mem:SI (reg:SI SP_REG)))
2020 (clobber (reg:SI MDR_REG))
2021 (clobber (reg:CC CC_REG))]
2024 operands[1] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);
2025 return ("calls .LPIC%=\n"
2028 "add %1-(.LPIC%=-.),%0");
2030 [(set_attr "timings" "66")]