]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/mn10300/mn10300.md
mn10300: Explicitly represent MDR in multiply and divide.
[thirdparty/gcc.git] / gcc / config / mn10300 / mn10300.md
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).
6
7 ;; This file is part of GCC.
8
9 ;; GCC is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
13
14 ;; GCC is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GCC; see the file COPYING3. If not see
21 ;; <http://www.gnu.org/licenses/>.
22
23 ;; The original PO technology requires these to be ordered by speed,
24 ;; so that assigner will pick the fastest.
25
26 ;; See file "rtl.def" for documentation on define_insn, match_*, et. al.
27
28 (define_constants [
29 (PIC_REG 6)
30 (SP_REG 9)
31 (MDR_REG 50)
32 (CC_REG 51)
33
34 (UNSPEC_INT_LABEL 0)
35 (UNSPEC_PIC 1)
36 (UNSPEC_GOT 2)
37 (UNSPEC_GOTOFF 3)
38 (UNSPEC_PLT 4)
39 (UNSPEC_GOTSYM_OFF 5)
40
41 (UNSPEC_EXT 6)
42 (UNSPEC_BSCH 7)
43 ])
44
45 (include "predicates.md")
46 (include "constraints.md")
47
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")))
52
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"))
56
57 (define_attr "enabled" ""
58 (cond [(eq_attr "isa" "base")
59 (const_int 1)
60
61 (and (eq_attr "isa" "am33")
62 (ne (symbol_ref "TARGET_AM33") (const_int 0)))
63 (const_int 1)
64
65 (and (eq_attr "isa" "am33_2")
66 (ne (symbol_ref "TARGET_AM33_2") (const_int 0)))
67 (const_int 1)
68
69 (and (eq_attr "isa" "am34")
70 (ne (symbol_ref "TARGET_AM34") (const_int 0)))
71 (const_int 1)
72 ]
73 (const_int 0))
74 )
75
76 (define_mode_iterator INT [QI HI SI])
77
78 \f
79 ;; ----------------------------------------------------------------------
80 ;; Pipeline description.
81 ;; ----------------------------------------------------------------------
82
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.
86
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.
95
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.
101
102 (define_attr "timings" "" (const_int 11))
103
104 (define_automaton "pipelining")
105 (define_cpu_unit "throughput" "pipelining")
106
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")
179
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.
184 \f
185 ;; ----------------------------------------------------------------------
186 ;; MOVE INSTRUCTIONS
187 ;; ----------------------------------------------------------------------
188
189 ;; movqi
190
191 (define_expand "movqi"
192 [(set (match_operand:QI 0 "nonimmediate_operand")
193 (match_operand:QI 1 "general_operand"))]
194 ""
195 {
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);
200 })
201
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))"
207 {
208 switch (which_alternative)
209 {
210 case 0:
211 return "";
212 case 1:
213 case 2:
214 return "mov %1,%0";
215 case 3:
216 case 4:
217 return "movbu %1,%0";
218 default:
219 gcc_unreachable ();
220 }
221 }
222 [(set_attr_alternative "timings"
223 [(const_int 11)
224 (const_int 11)
225 (const_int 11)
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))
230 ])]
231 )
232
233 ;; movhi
234
235 (define_expand "movhi"
236 [(set (match_operand:HI 0 "nonimmediate_operand")
237 (match_operand:HI 1 "general_operand"))]
238 ""
239 {
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);
244 })
245
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))"
251 {
252 switch (which_alternative)
253 {
254 case 0:
255 return "";
256 case 1:
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. */
260 if (TARGET_AM33
261 && CONST_INT_P (operands[1])
262 && IN_RANGE (INTVAL (operands[1]), 0x80, 0xff)
263 && REGNO_EXTENDED_P (REGNO (operands[0]), 1))
264 return "movu %1,%0";
265 /* FALLTHRU */
266 case 2:
267 return "mov %1,%0";
268 case 3:
269 case 4:
270 return "movhu %1,%0";
271 default:
272 gcc_unreachable ();
273 }
274 }
275 [(set_attr_alternative "timings"
276 [(const_int 11)
277 (const_int 11)
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))
284 ])]
285 )
286
287 ;; movsi and helpers
288
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"))]
296 ""
297 "
298 {
299 rtx dest, scratch, other;
300
301 dest = operands[0];
302 scratch = operands[2];
303
304 other = XEXP (operands[1], 1);
305 if (other == stack_pointer_rtx)
306 other = XEXP (operands[1], 0);
307
308 if (true_regnum (other) == true_regnum (dest))
309 {
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));
313 }
314 else if (TARGET_AM33 || REGNO_REG_CLASS (true_regnum (dest)) == ADDRESS_REGS)
315 {
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));
321 }
322 else
323 {
324 emit_move_insn (scratch, stack_pointer_rtx);
325 if (other == stack_pointer_rtx)
326 {
327 emit_move_insn (dest, scratch);
328 emit_insn (gen_addsi3 (dest, dest, dest));
329 }
330 else if (other != const0_rtx)
331 {
332 emit_move_insn (dest, other);
333 emit_insn (gen_addsi3 (dest, dest, scratch));
334 }
335 else
336 emit_move_insn (dest, scratch);
337 }
338 DONE;
339 }")
340
341 (define_insn "pop_pic_reg"
342 [(set (reg:SI PIC_REG)
343 (mem:SI (post_inc:SI (reg:SI SP_REG))))]
344 "reload_completed"
345 "movm (sp),[a2]"
346 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
347 (const_int 44) (const_int 33)))]
348 )
349
350 (define_expand "movsi"
351 [(set (match_operand:SI 0 "nonimmediate_operand")
352 (match_operand:SI 1 "general_operand"))]
353 ""
354 {
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);
359 if (flag_pic)
360 {
361 rtx temp;
362 if (SYMBOLIC_CONST_P (operands[1]))
363 {
364 if (MEM_P (operands[0]))
365 operands[1] = force_reg (Pmode, operands[1]);
366 else
367 {
368 temp = (!can_create_pseudo_p ()
369 ? operands[0]
370 : gen_reg_rtx (Pmode));
371 operands[1] = mn10300_legitimize_pic_address (operands[1], temp);
372 }
373 }
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)))
377 {
378 temp = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
379 temp = mn10300_legitimize_pic_address (XEXP (XEXP (operands[1], 0), 0),
380 temp);
381 operands[1] = expand_binop (SImode, add_optab, temp,
382 XEXP (XEXP (operands[1], 0), 1),
383 (!can_create_pseudo_p ()
384 ? temp
385 : gen_reg_rtx (Pmode)),
386 0, OPTAB_LIB_WIDEN);
387 }
388 }
389 })
390
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)"
398 {
399 switch (which_alternative)
400 {
401 case 0:
402 return "";
403 case 1: /* imm-reg*/
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. */
407 if (TARGET_AM33
408 && CONST_INT_P (operands[1])
409 && REGNO_EXTENDED_P (REGNO (operands[0]), 1))
410 {
411 HOST_WIDE_INT val = INTVAL (operands[1]);
412 if (IN_RANGE (val, 0x80, 0xff)
413 || IN_RANGE (val, 0x800000, 0xffffff))
414 return "movu %1,%0";
415 }
416 /* FALLTHRU */
417 case 2: /* reg-reg */
418 case 3: /* reg-mem */
419 case 4: /* mem-reg */
420 case 5: /* sp-reg */
421 case 6: /* reg-sp */
422 case 7: /* imm-sp */
423 case 8: /* reg-mdr */
424 case 9: /* mdr-reg */
425 return "mov %1,%0";
426 default:
427 gcc_unreachable ();
428 }
429 }
430 [(set_attr "isa" "*,*,*,*,*,*,*,am33,*,*")
431 (set_attr_alternative "timings"
432 [(const_int 11)
433 (const_int 22)
434 (const_int 11)
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))
443 (const_int 11)
444 (const_int 11)
445 (const_int 11)
446 ])]
447 )
448
449 (define_expand "movsf"
450 [(set (match_operand:SF 0 "nonimmediate_operand")
451 (match_operand:SF 1 "general_operand"))]
452 "TARGET_AM33_2"
453 {
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);
458 })
459
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"))]
463 "TARGET_AM33_2
464 && (register_operand (operands[0], SFmode)
465 || register_operand (operands[1], SFmode))"
466 {
467 switch (which_alternative)
468 {
469 case 0:
470 return "";
471 case 1:
472 case 3:
473 case 7:
474 case 8:
475 return "mov %1,%0";
476 case 2:
477 case 4:
478 case 5:
479 case 6:
480 case 9:
481 case 10:
482 return "fmov %1,%0";
483 default:
484 gcc_unreachable ();
485 }
486 }
487 [(set_attr_alternative "timings"
488 [(const_int 11)
489 (const_int 22)
490 (if_then_else (eq_attr "cpu" "am34")
491 (const_int 47) (const_int 25))
492 (const_int 11)
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))
507 ])]
508 )
509
510 \f
511 ;; ----------------------------------------------------------------------
512 ;; ADD INSTRUCTIONS
513 ;; ----------------------------------------------------------------------
514
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))
520 ])
521 ]
522 ""
523 "")
524
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))
530 ]
531 "TARGET_AM33"
532 "*
533 {
534 switch (which_alternative)
535 {
536 case 0:
537 case 1:
538 return \"inc %0\";
539 case 2:
540 case 3:
541 return \"inc4 %0\";
542 case 4:
543 case 5:
544 return \"add %2,%0\";
545 case 6:
546 {
547 enum reg_class src1_class, src2_class, dst_class;
548
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]));
552
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\";
559
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)
565 {
566 /* We have to copy one of the sources into the destination, then
567 add the other source to the destination.
568
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
573 sequence. */
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\";
578 }
579
580 /* At least one register is an extended register. */
581
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\";
588
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
593 register.
594
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\";
600 }
601 default:
602 gcc_unreachable ();
603 }
604 }"
605 [(set_attr "timings" "11,11,11,11,11,11,22")]
606 )
607
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.
611 (define_peephole2
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))])]
618 )
619
620 (define_insn "*mov<mode>_clr"
621 [(set (match_operand:INT 0 "register_operand" "=D")
622 (const_int 0))
623 (clobber (reg:CC CC_REG))]
624 ""
625 "clr %0"
626 )
627 \f
628 ;; ----------------------------------------------------------------------
629 ;; ADD INSTRUCTIONS
630 ;; ----------------------------------------------------------------------
631
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))
637 ]
638 ""
639 "*
640 {
641 switch (which_alternative)
642 {
643 case 0:
644 case 1:
645 return \"inc %0\";
646 case 2:
647 return \"inc4 %0\";
648 case 3:
649 case 4:
650 return \"add %2,%0\";
651 case 5:
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\";
658
659 /* We have to copy one of the sources into the destination, then add
660 the other source to the destination.
661
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\";
670 default:
671 gcc_unreachable ();
672 }
673 }"
674 [(set_attr "timings" "11,11,11,11,11,22")]
675 )
676
677 ;; ----------------------------------------------------------------------
678 ;; SUBTRACT INSTRUCTIONS
679 ;; ----------------------------------------------------------------------
680
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))
686 ])
687 ]
688 ""
689 "")
690
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))
696 ]
697 "TARGET_AM33"
698 "*
699 {
700 if (true_regnum (operands[0]) == true_regnum (operands[1]))
701 return \"sub %2,%0\";
702 else
703 {
704 enum reg_class src1_class, src2_class, dst_class;
705
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]));
709
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\";
719 }
720 }"
721 [(set_attr "timings" "11,22")]
722 )
723
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))
729 ]
730 ""
731 "sub %2,%0"
732 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
733 (const_int 11) (const_int 22)))]
734 )
735
736 (define_expand "negsi2"
737 [(set (match_operand:SI 0 "register_operand")
738 (neg:SI (match_operand:SI 1 "register_operand")))]
739 ""
740 "
741 {
742 rtx target = gen_reg_rtx (SImode);
743
744 emit_move_insn (target, const0_rtx);
745 emit_insn (gen_subsi3 (target, target, operands[1]));
746 emit_move_insn (operands[0], target);
747 DONE;
748 }")
749
750 ;; ----------------------------------------------------------------------
751 ;; MULTIPLY INSTRUCTIONS
752 ;; ----------------------------------------------------------------------
753
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...
760
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" ""))))]
765 ""
766 {
767 emit_insn (gen_mulsidi3_internal (gen_lowpart (SImode, operands[0]),
768 gen_highpart (SImode, operands[0]),
769 operands[1], operands[2]));
770 DONE;
771 })
772
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")
778 (truncate:SI
779 (ashiftrt:DI
780 (mult:DI (sign_extend:DI (match_dup 2))
781 (sign_extend:DI (match_dup 3)))
782 (const_int 32))))
783 (clobber (reg:CC CC_REG))]
784 ""
785 {
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";
790 else
791 return "mul %3,%0";
792 }
793 [(set_attr "isa" "*,am33")
794 (set (attr "timings")
795 (if_then_else (eq_attr "cpu" "am34") (const_int 24) (const_int 23)))]
796 )
797
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))]
803 ""
804 {
805 emit_insn (gen_umulsidi3_internal (gen_lowpart (SImode, operands[0]),
806 gen_highpart (SImode, operands[0]),
807 operands[1], operands[2]));
808 DONE;
809 })
810
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")
816 (truncate:SI
817 (lshiftrt:DI
818 (mult:DI (zero_extend:DI (match_dup 2))
819 (zero_extend:DI (match_dup 3)))
820 (const_int 32))))
821 (clobber (reg:CC CC_REG))]
822 ""
823 {
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";
828 else
829 return "mulu %3,%0";
830 }
831 [(set_attr "isa" "*,am33")
832 (set (attr "timings")
833 (if_then_else (eq_attr "cpu" "am34") (const_int 24) (const_int 23)))]
834 )
835
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))])]
842 ""
843 )
844
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))]
851 ""
852 {
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";
857 else
858 return "mul %3,%0";
859 }
860 [(set_attr "isa" "*,am33,am33")
861 (set (attr "timings")
862 (if_then_else (eq_attr "cpu" "am34") (const_int 24) (const_int 23)))]
863 )
864
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)))
871 (use (const_int 0))
872 (clobber (reg:CC CC_REG))])]
873 ""
874 )
875
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.
880
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))]
889 ""
890 "divu %3,%0"
891 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
892 (const_int 3839) (const_int 4243)))]
893 )
894
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)))
901 (use (match_dup 4))
902 (clobber (reg:CC CC_REG))])]
903 ""
904 {
905 operands[4] = gen_reg_rtx (SImode);
906 emit_insn (gen_ext_internal (operands[4], operands[1]));
907 })
908
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))]
915 ""
916 "ext %1"
917 )
918
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))]
927 ""
928 "div %3,%0";
929 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
930 (const_int 3839) (const_int 4243)))]
931 )
932
933 \f
934 ;; ----------------------------------------------------------------------
935 ;; AND INSTRUCTIONS
936 ;; ----------------------------------------------------------------------
937
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))
943 ])
944 ]
945 ""
946 "")
947
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))
953 ]
954 "TARGET_AM33"
955 {
956 if (CONST_INT_P (operands[2]))
957 switch (INTVAL (operands[2]))
958 {
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";
969 }
970
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]))
984 return "and %1, %0";
985
986 return "and %2, %0";
987 }
988 [(set_attr "timings" "33")]
989 )
990
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))
996 ]
997 ""
998 {
999 if (CONST_INT_P (operands[2]))
1000 switch (INTVAL (operands[2]))
1001 {
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";
1012 }
1013
1014 return "and %2, %0";
1015 }
1016 [(set_attr "timings" "33")]
1017 )
1018
1019 ;; ----------------------------------------------------------------------
1020 ;; OR INSTRUCTIONS
1021 ;; ----------------------------------------------------------------------
1022
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))
1028 ])
1029 ]
1030 ""
1031 "")
1032
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))
1038 ]
1039 "TARGET_AM33"
1040 "*
1041 {
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\";
1057 }"
1058 [(set_attr "timings" "22")]
1059 )
1060
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))
1066 ]
1067 ""
1068 "or %2,%0"
1069 [(set_attr "timings" "33")]
1070 )
1071
1072 ;; ----------------------------------------------------------------------
1073 ;; XOR INSTRUCTIONS
1074 ;; ----------------------------------------------------------------------
1075
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))
1081 ])
1082 ]
1083 ""
1084 "")
1085
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))
1091 ]
1092 "TARGET_AM33"
1093 "*
1094 {
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\";
1110 }"
1111 [(set_attr "timings" "22")]
1112 )
1113
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))
1119 ]
1120 ""
1121 "xor %2,%0"
1122 [(set_attr "timings" "11")]
1123 )
1124
1125 ;; ----------------------------------------------------------------------
1126 ;; NOT INSTRUCTIONS
1127 ;; ----------------------------------------------------------------------
1128
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))
1133 ])
1134 ]
1135 ""
1136 "")
1137
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))
1142 ]
1143 "TARGET_AM33"
1144 "not %0"
1145 )
1146
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))
1151 ]
1152 ""
1153 "not %0"
1154 )
1155 \f
1156 ;; ----------------------------------------------------------------------
1157 ;; COMPARE AND BRANCH INSTRUCTIONS
1158 ;; ----------------------------------------------------------------------
1159
1160 ;; We expand the comparison into a single insn so that it will not be split
1161 ;; up by reload.
1162 (define_expand "cbranchsi4"
1163 [(set (pc)
1164 (if_then_else
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 ""))
1169 (pc)))]
1170 ""
1171 ""
1172 )
1173
1174 (define_insn_and_split "*cbranchsi4_post_reload"
1175 [(set (pc)
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 "" ""))
1180 (pc)))
1181 ]
1182 ""
1183 "#"
1184 "reload_completed"
1185 [(const_int 0)]
1186 "
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]));
1190
1191 emit_jump_insn (gen_integer_conditional_branch
1192 (gen_rtx_fmt_ee (GET_CODE (operands[3]),
1193 CCmode,
1194 gen_rtx_REG (CCmode, CC_REG),
1195 const0_rtx),
1196 operands[2]));
1197 "
1198 )
1199
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.)
1207
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.
1215
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")))]
1220 ""
1221 {
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\";
1227 }
1228 [(set_attr_alternative "timings"
1229 [(const_int 11)
1230 (if_then_else (eq_attr "cpu" "am34")
1231 (const_int 11) (const_int 22))
1232 (const_int 22)
1233 ])
1234 ]
1235 )
1236
1237 (define_insn "integer_conditional_branch"
1238 [(set (pc)
1239 (if_then_else (match_operator 0 "comparison_operator"
1240 [(reg:CC CC_REG) (const_int 0)])
1241 (label_ref (match_operand 1 "" ""))
1242 (pc)))]
1243 ""
1244 "b%b0 %1"
1245 )
1246
1247 (define_expand "cbranchsf4"
1248 [(set (pc)
1249 (if_then_else
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 ""))
1254 (pc)))]
1255 "TARGET_AM33_2"
1256 ""
1257 )
1258
1259 (define_insn_and_split "*cbranchsf4_post_reload"
1260 [(set (pc)
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 "" ""))
1265 (pc)))
1266 ]
1267 "TARGET_AM33_2"
1268 "#"
1269 "&& reload_completed"
1270 [(const_int 0)]
1271 "
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]));
1275
1276 emit_jump_insn (gen_float_conditional_branch
1277 (gen_rtx_fmt_ee (GET_CODE (operands[3]),
1278 CC_FLOATmode,
1279 gen_rtx_REG (CC_FLOATmode, CC_REG),
1280 const0_rtx),
1281 operands[2]));
1282 "
1283 )
1284
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")))]
1289 "TARGET_AM33_2"
1290 "fcmp %1, %0"
1291 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1292 (const_int 17) (const_int 25)))]
1293 )
1294
1295 (define_insn "float_conditional_branch"
1296 [(set (pc)
1297 (if_then_else (match_operator 0 "comparison_operator"
1298 [(reg:CC_FLOAT CC_REG) (const_int 0)])
1299 (label_ref (match_operand 1 "" ""))
1300 (pc)))]
1301 "TARGET_AM33_2"
1302 "fb%b0 %1"
1303 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1304 (const_int 44) (const_int 33)))]
1305 )
1306
1307 ;; Unconditional and other jump instructions.
1308
1309 (define_insn "jump"
1310 [(set (pc)
1311 (label_ref (match_operand 0 "" "")))]
1312 ""
1313 "jmp %l0"
1314 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1315 (const_int 11) (const_int 44)))]
1316 )
1317
1318 (define_insn "indirect_jump"
1319 [(set (pc) (match_operand:SI 0 "register_operand" "a"))]
1320 ""
1321 "jmp (%0)"
1322 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1323 (const_int 11) (const_int 33)))]
1324 )
1325
1326 (define_expand "builtin_setjmp_receiver"
1327 [(match_operand 0 "" "")]
1328 "flag_pic"
1329 "
1330 {
1331 if (flag_pic)
1332 emit_insn (gen_GOTaddr2picreg ());
1333
1334 DONE;
1335 }")
1336
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 "")]
1342 ""
1343 "
1344 {
1345 rtx table = gen_reg_rtx (SImode);
1346 rtx index = gen_reg_rtx (SImode);
1347 rtx addr = gen_reg_rtx (Pmode);
1348 rtx test;
1349
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]));
1354
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)));
1358 if (flag_pic)
1359 emit_insn (gen_addsi3 (addr, addr, table));
1360
1361 emit_jump_insn (gen_tablejump (addr, operands[3]));
1362 DONE;
1363 }")
1364
1365 (define_insn "tablejump"
1366 [(set (pc) (match_operand:SI 0 "register_operand" "a"))
1367 (use (label_ref (match_operand 1 "" "")))]
1368 ""
1369 "jmp (%0)"
1370 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1371 (const_int 11) (const_int 33)))]
1372 )
1373
1374 ;; Call subroutine with no return value.
1375
1376 (define_expand "call"
1377 [(call (match_operand:QI 0 "general_operand")
1378 (match_operand:SI 1 "general_operand"))]
1379 ""
1380 {
1381 rtx fn = XEXP (operands[0], 0);
1382
1383 if (flag_pic && GET_CODE (fn) == SYMBOL_REF)
1384 {
1385 if (MN10300_GLOBAL_P (fn))
1386 {
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
1390 actual symbols. */
1391 emit_use (pic_offset_table_rtx);
1392 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PLT);
1393 }
1394 else
1395 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PIC);
1396 }
1397 if (! call_address_operand (fn, VOIDmode))
1398 fn = force_reg (SImode, fn);
1399
1400 XEXP (operands[0], 0) = fn;
1401 })
1402
1403 (define_insn "*call_internal"
1404 [(call (mem:QI (match_operand:SI 0 "call_address_operand" "a,S"))
1405 (match_operand:SI 1 "" ""))]
1406 ""
1407 "@
1408 calls %C0
1409 call %C0,[],0"
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))
1415 ])
1416 ]
1417 )
1418
1419 ;; Call subroutine, returning value in operand 0
1420 ;; (which must be a hard register).
1421
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")))]
1426 ""
1427 {
1428 rtx fn = XEXP (operands[1], 0);
1429
1430 if (flag_pic && GET_CODE (fn) == SYMBOL_REF)
1431 {
1432 if (MN10300_GLOBAL_P (fn))
1433 {
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
1437 actual symbols. */
1438 emit_use (pic_offset_table_rtx);
1439 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PLT);
1440 }
1441 else
1442 fn = gen_rtx_UNSPEC (SImode, gen_rtvec (1, fn), UNSPEC_PIC);
1443 }
1444 if (! call_address_operand (fn, VOIDmode))
1445 fn = force_reg (SImode, fn);
1446
1447 XEXP (operands[1], 0) = fn;
1448 })
1449
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 "" "")))]
1454 ""
1455 "@
1456 calls %C1
1457 call %C1,[],0"
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))
1463 ])
1464 ]
1465 )
1466
1467 (define_expand "untyped_call"
1468 [(parallel [(call (match_operand 0 "")
1469 (const_int 0))
1470 (match_operand 1 "")
1471 (match_operand 2 "")])]
1472 ""
1473 "
1474 {
1475 int i;
1476
1477 emit_call_insn (gen_call (operands[0], const0_rtx));
1478
1479 for (i = 0; i < XVECLEN (operands[2], 0); i++)
1480 {
1481 rtx set = XVECEXP (operands[2], 0, i);
1482 emit_move_insn (SET_DEST (set), SET_SRC (set));
1483 }
1484 DONE;
1485 }")
1486
1487 (define_insn "nop"
1488 [(const_int 0)]
1489 ""
1490 "nop"
1491 )
1492 \f
1493 ;; ----------------------------------------------------------------------
1494 ;; EXTEND INSTRUCTIONS
1495 ;; ----------------------------------------------------------------------
1496
1497 (define_expand "zero_extendqisi2"
1498 [(set (match_operand:SI 0 "register_operand")
1499 (zero_extend:SI
1500 (match_operand:QI 1 "nonimmediate_operand")))]
1501 ""
1502 "")
1503
1504 (define_insn "*zero_extendqisi2_am33"
1505 [(set (match_operand:SI 0 "register_operand" "=dx,dx,dx,!dax,!dax,!dax")
1506 (zero_extend:SI
1507 (match_operand:QI 1 "nonimmediate_operand" "0,dax,m,0,dax,m")))]
1508 "TARGET_AM33"
1509 "@
1510 extbu %0
1511 mov %1,%0\;extbu %0
1512 movbu %1,%0
1513 extbu %0
1514 mov %1,%0\;extbu %0
1515 movbu %1,%0"
1516 [(set_attr_alternative "timings"
1517 [(const_int 11)
1518 (const_int 22)
1519 (if_then_else (eq_attr "cpu" "am34")
1520 (const_int 13) (const_int 24))
1521 (const_int 11)
1522 (const_int 22)
1523 (if_then_else (eq_attr "cpu" "am34")
1524 (const_int 13) (const_int 24))
1525 ])
1526 ]
1527 )
1528
1529 (define_insn "*zero_extendqisi2_mn10300"
1530 [(set (match_operand:SI 0 "register_operand" "=dx,dx,dx")
1531 (zero_extend:SI
1532 (match_operand:QI 1 "nonimmediate_operand" "0,d,m")))]
1533 ""
1534 "@
1535 extbu %0
1536 mov %1,%0\;extbu %0
1537 movbu %1,%0"
1538 [(set_attr_alternative "timings"
1539 [(const_int 11)
1540 (const_int 22)
1541 (if_then_else (eq_attr "cpu" "am34")
1542 (const_int 13) (const_int 24))
1543 ])
1544 ]
1545 )
1546
1547 (define_expand "zero_extendhisi2"
1548 [(set (match_operand:SI 0 "register_operand")
1549 (zero_extend:SI
1550 (match_operand:HI 1 "nonimmediate_operand")))]
1551 ""
1552 "")
1553
1554 (define_insn "*zero_extendhisi2_am33"
1555 [(set (match_operand:SI 0 "register_operand" "=dx,dx,dx,!dax,!dax,!dax")
1556 (zero_extend:SI
1557 (match_operand:HI 1 "nonimmediate_operand" "0,dax,m,0,dax,m")))]
1558 "TARGET_AM33"
1559 "@
1560 exthu %0
1561 mov %1,%0\;exthu %0
1562 movhu %1,%0
1563 exthu %0
1564 mov %1,%0\;exthu %0
1565 movhu %1,%0"
1566 [(set_attr_alternative "timings"
1567 [(const_int 11)
1568 (const_int 22)
1569 (if_then_else (eq_attr "cpu" "am34")
1570 (const_int 13) (const_int 24))
1571 (const_int 11)
1572 (const_int 22)
1573 (if_then_else (eq_attr "cpu" "am34")
1574 (const_int 13) (const_int 24))
1575 ])
1576 ]
1577 )
1578
1579 (define_insn "*zero_extendhisi2_mn10300"
1580 [(set (match_operand:SI 0 "register_operand" "=dx,dx,dx")
1581 (zero_extend:SI
1582 (match_operand:HI 1 "nonimmediate_operand" "0,dx,m")))]
1583 ""
1584 "@
1585 exthu %0
1586 mov %1,%0\;exthu %0
1587 movhu %1,%0"
1588 [(set_attr_alternative "timings"
1589 [(const_int 11)
1590 (const_int 22)
1591 (if_then_else (eq_attr "cpu" "am34")
1592 (const_int 13) (const_int 24))
1593 ])
1594 ]
1595 )
1596
1597 ;;- sign extension instructions
1598
1599 (define_expand "extendqisi2"
1600 [(set (match_operand:SI 0 "register_operand")
1601 (sign_extend:SI
1602 (match_operand:QI 1 "register_operand")))]
1603 ""
1604 "")
1605
1606 (define_insn "*extendqisi2_am33"
1607 [(set (match_operand:SI 0 "register_operand" "=dx,dx,!dax,!dax")
1608 (sign_extend:SI
1609 (match_operand:QI 1 "register_operand" "0,dx,0,dax")))]
1610 "TARGET_AM33"
1611 "@
1612 extb %0
1613 mov %1,%0\;extb %0
1614 extb %0
1615 mov %1,%0\;extb %0"
1616 [(set_attr "timings" "11,22,11,22")]
1617 )
1618
1619 (define_insn "*extendqisi2_mn10300"
1620 [(set (match_operand:SI 0 "register_operand" "=dx,dx")
1621 (sign_extend:SI
1622 (match_operand:QI 1 "register_operand" "0,dx")))]
1623 ""
1624 "@
1625 extb %0
1626 mov %1,%0\;extb %0"
1627 [(set_attr "timings" "11,22")]
1628 )
1629
1630 (define_expand "extendhisi2"
1631 [(set (match_operand:SI 0 "register_operand")
1632 (sign_extend:SI
1633 (match_operand:HI 1 "register_operand")))]
1634 ""
1635 "")
1636
1637 (define_insn "*extendhisi2_am33"
1638 [(set (match_operand:SI 0 "register_operand" "=dx,dx,!dax,!dax")
1639 (sign_extend:SI
1640 (match_operand:HI 1 "register_operand" "0,dax,0,dax")))]
1641 "TARGET_AM33"
1642 "@
1643 exth %0
1644 mov %1,%0\;exth %0
1645 exth %0
1646 mov %1,%0\;exth %0"
1647 [(set_attr "timings" "11,22,11,22")]
1648 )
1649
1650 (define_insn "*extendhisi2_mn10300"
1651 [(set (match_operand:SI 0 "register_operand" "=dx,dx")
1652 (sign_extend:SI
1653 (match_operand:HI 1 "register_operand" "0,dx")))]
1654 ""
1655 "@
1656 exth %0
1657 mov %1,%0\;exth %0"
1658 [(set_attr "timings" "11,22")]
1659 )
1660 \f
1661 ;; ----------------------------------------------------------------------
1662 ;; SHIFTS
1663 ;; ----------------------------------------------------------------------
1664
1665 (define_expand "ashlsi3"
1666 [(parallel [(set (match_operand:SI 0 "register_operand")
1667 (ashift:SI
1668 (match_operand:SI 1 "register_operand")
1669 (match_operand:QI 2 "nonmemory_operand")))
1670 (clobber (reg:CC CC_REG))
1671 ])
1672 ]
1673 ""
1674 "")
1675
1676 (define_insn "*am33_ashlsi3"
1677 [(set (match_operand:SI 0 "register_operand" "=dax,dx,!dax")
1678 (ashift:SI
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))
1682 ]
1683 "TARGET_AM33"
1684 "*
1685 {
1686 if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 1)
1687 return \"add %0,%0\";
1688
1689 if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 2)
1690 return \"asl2 %0\";
1691
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\";
1695
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\";
1699
1700 if (true_regnum (operands[1]) == true_regnum (operands[0]))
1701 return \"asl %S2,%0\";
1702
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\";
1708 }"
1709 [(set_attr "timings" "22")]
1710 )
1711
1712 (define_insn "*mn10300_ashlsi3"
1713 [(set (match_operand:SI 0 "register_operand" "=dax,dx,dx,dx,dx")
1714 (ashift:SI
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))
1718 ]
1719 ""
1720 "@
1721 add %0,%0
1722 asl2 %0
1723 asl2 %0\;add %0,%0
1724 asl2 %0\;asl2 %0
1725 asl %S2,%0"
1726 [(set_attr "timings" "11,11,22,22,11")]
1727 )
1728
1729 (define_expand "lshrsi3"
1730 [(parallel [(set (match_operand:SI 0 "register_operand")
1731 (lshiftrt:SI
1732 (match_operand:SI 1 "register_operand")
1733 (match_operand:QI 2 "nonmemory_operand")))
1734 (clobber (reg:CC CC_REG))
1735 ])
1736 ]
1737 ""
1738 "")
1739
1740 (define_insn "*am33_lshrsi3"
1741 [(set (match_operand:SI 0 "register_operand" "=dx,!dax")
1742 (lshiftrt:SI
1743 (match_operand:SI 1 "register_operand" "0,dax")
1744 (match_operand:QI 2 "nonmemory_operand" "dxi,dax")))
1745 (clobber (reg:CC CC_REG))
1746 ]
1747 "TARGET_AM33"
1748 "*
1749 {
1750 if (true_regnum (operands[1]) == true_regnum (operands[0]))
1751 return \"lsr %S2,%0\";
1752
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\";
1758 }"
1759 [(set_attr "timings" "22")]
1760 )
1761
1762 (define_insn "*mn10300_lshrsi3"
1763 [(set (match_operand:SI 0 "register_operand" "=dx")
1764 (lshiftrt:SI
1765 (match_operand:SI 1 "register_operand" "0")
1766 (match_operand:QI 2 "nonmemory_operand" "dxi")))
1767 (clobber (reg:CC CC_REG))
1768 ]
1769 ""
1770 "lsr %S2,%0"
1771 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1772 (const_int 11) (const_int 22)))]
1773 )
1774
1775 (define_expand "ashrsi3"
1776 [(parallel [(set (match_operand:SI 0 "register_operand")
1777 (ashiftrt:SI
1778 (match_operand:SI 1 "register_operand")
1779 (match_operand:QI 2 "nonmemory_operand")))
1780 (clobber (reg:CC CC_REG))
1781 ])
1782 ]
1783 ""
1784 "")
1785
1786 (define_insn "*am33_ashrisi3"
1787 [(set (match_operand:SI 0 "register_operand" "=dx,!dax")
1788 (ashiftrt:SI
1789 (match_operand:SI 1 "register_operand" "0,dax")
1790 (match_operand:QI 2 "nonmemory_operand" "dxi,dax")))
1791 (clobber (reg:CC CC_REG))
1792 ]
1793 "TARGET_AM33"
1794 "*
1795 {
1796 if (true_regnum (operands[1]) == true_regnum (operands[0]))
1797 return \"asr %S2,%0\";
1798
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\";
1804 }"
1805 [(set_attr "timings" "22")]
1806 )
1807
1808 (define_insn "*mn10300_ashrsi3"
1809 [(set (match_operand:SI 0 "register_operand" "=dx")
1810 (ashiftrt:SI
1811 (match_operand:SI 1 "register_operand" "0")
1812 (match_operand:QI 2 "nonmemory_operand" "dxi")))
1813 (clobber (reg:CC CC_REG))
1814 ]
1815 ""
1816 "asr %S2,%0"
1817 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1818 (const_int 11) (const_int 22)))]
1819 )
1820
1821 ;; ----------------------------------------------------------------------
1822 ;; MISCELANEOUS
1823 ;; ----------------------------------------------------------------------
1824
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))])]
1830 "TARGET_AM33"
1831 )
1832
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")]
1837 UNSPEC_BSCH))
1838 (clobber (reg:CC CC_REG))]
1839 "TARGET_AM33"
1840 "bsch %1,%0"
1841 )
1842
1843 ;; ----------------------------------------------------------------------
1844 ;; FP INSTRUCTIONS
1845 ;; ----------------------------------------------------------------------
1846
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")))]
1850 "TARGET_AM33_2"
1851 "@
1852 fabs %0
1853 fabs %1, %0"
1854 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1855 (const_int 17) (const_int 14)))]
1856 )
1857
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")))]
1861 "TARGET_AM33_2"
1862 "@
1863 fneg %0
1864 fneg %1, %0"
1865 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1866 (const_int 17) (const_int 14)))]
1867 )
1868
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"
1873 {
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)),
1877 scratch));
1878 DONE;
1879 })
1880
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))]
1886 "TARGET_AM33_2"
1887 "@
1888 frsqrt %0
1889 frsqrt %1, %0"
1890 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1891 (const_int 4753) (const_int 2327)))]
1892 )
1893
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))]
1899 "TARGET_AM33_2"
1900 "@
1901 fadd %2, %0
1902 fadd %2, %1, %0"
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))
1908 ])]
1909 )
1910
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))]
1916 "TARGET_AM33_2"
1917 "@
1918 fsub %2, %0
1919 fsub %2, %1, %0"
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))
1925 ])]
1926 )
1927
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))
1933 ]
1934 "TARGET_AM33_2"
1935 "@
1936 fmul %2, %0
1937 fmul %2, %1, %0"
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))
1943 ])]
1944 )
1945
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))]
1951 "TARGET_AM33_2"
1952 "@
1953 fdiv %2, %0
1954 fdiv %2, %1, %0"
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))
1960 ])]
1961 )
1962
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))
1969 ]
1970 "TARGET_AM33_2"
1971 "fmadd %1, %2, %3, %0"
1972 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1973 (const_int 17) (const_int 24)))]
1974 )
1975
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))
1982 ]
1983 "TARGET_AM33_2"
1984 "fmsub %1, %2, %3, %0"
1985 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1986 (const_int 17) (const_int 24)))]
1987 )
1988
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))
1995 ]
1996 "TARGET_AM33_2"
1997 "fnmadd %1, %2, %3, %0"
1998 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
1999 (const_int 17) (const_int 24)))]
2000 )
2001
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))
2008 ]
2009 "TARGET_AM33_2"
2010 "fnmsub %1, %2, %3, %0"
2011 [(set (attr "timings") (if_then_else (eq_attr "cpu" "am34")
2012 (const_int 17) (const_int 24)))]
2013 )
2014
2015 ;; ----------------------------------------------------------------------
2016 ;; PROLOGUE/EPILOGUE
2017 ;; ----------------------------------------------------------------------
2018 (define_expand "prologue"
2019 [(const_int 0)]
2020 ""
2021 "mn10300_expand_prologue (); DONE;")
2022
2023 (define_expand "epilogue"
2024 [(return)]
2025 ""
2026 "
2027 {
2028 mn10300_expand_epilogue ();
2029 DONE;
2030 }")
2031
2032 (define_insn "return_internal"
2033 [(const_int 2)
2034 (return)]
2035 ""
2036 "rets"
2037 [(set_attr "timings" "66")]
2038 )
2039
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"
2043 [(const_int 0)
2044 (match_operand:SI 0 "const_int_operand" "i")
2045 (return)]
2046 ""
2047 "*
2048 {
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]));
2052 return \"\";
2053 }"
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)))]
2057 )
2058
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 "" "")))])]
2063 ""
2064 "*
2065 {
2066 fputs (\"\\tmovm \", asm_out_file);
2067 mn10300_print_reg_list (asm_out_file,
2068 mn10300_store_multiple_operation (operands[0],
2069 VOIDmode));
2070 fprintf (asm_out_file, \",(sp)\\n\");
2071 return \"\";
2072 }"
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)))]
2076 )
2077
2078 (define_insn "return"
2079 [(return)]
2080 "mn10300_can_use_return_insn ()"
2081 "*
2082 {
2083 rtx next = next_active_insn (insn);
2084
2085 if (next
2086 && JUMP_P (next)
2087 && GET_CODE (PATTERN (next)) == RETURN)
2088 return \"\";
2089 else
2090 return \"rets\";
2091 }"
2092 [(set_attr "timings" "66")]
2093 )
2094
2095 ;; Try to combine consecutive updates of the stack pointer (or any
2096 ;; other register for that matter).
2097 (define_peephole
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))
2102 ])
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))
2107 ])
2108 ]
2109 ""
2110 "*
2111 {
2112 operands[1] = GEN_INT (INTVAL (operands[2]) + INTVAL (operands[1]));
2113 return \"add %1,%0\";
2114 }"
2115 )
2116
2117 (define_expand "int_label"
2118 [(unspec [(match_operand:SI 0 "" "")] UNSPEC_INT_LABEL)]
2119 "" "")
2120
2121 (define_expand "GOTaddr2picreg"
2122 [(match_dup 0)]
2123 "" "
2124 {
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++));
2129 if (TARGET_AM33)
2130 emit_insn (gen_am33_loadPC (operands[0]));
2131 else
2132 emit_insn (gen_mn10300_loadPC (operands[0]));
2133 emit_insn (gen_add_GOT_to_pic_reg (copy_rtx (operands[0])));
2134 DONE;
2135 }
2136 ")
2137
2138 (define_insn "am33_loadPC"
2139 [(parallel
2140 [(set (reg:SI PIC_REG) (pc))
2141 (use (match_operand 0 "" ""))])]
2142 "TARGET_AM33"
2143 "%0:\;mov pc,a2"
2144 )
2145
2146 (define_insn_and_split "mn10300_loadPC"
2147 [(parallel
2148 [(set (reg:SI PIC_REG) (pc))
2149 (use (match_operand 0 "" ""))])]
2150 "! TARGET_AM33"
2151 "#"
2152 "&& reload_completed"
2153 [(match_operand 0 "" "")]
2154 {
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);
2158
2159 if (need_stack_space)
2160 emit_insn (gen_addsi3 (sp_reg, sp_reg, GEN_INT (-4)));
2161
2162 emit_insn (gen_call_next_insn (operands[0]));
2163
2164 if (need_stack_space)
2165 emit_insn (gen_pop_pic_reg ());
2166 else
2167 emit_move_insn (pic_offset_table_rtx, gen_rtx_MEM (SImode, sp_reg));
2168 DONE;
2169 }
2170 )
2171
2172 (define_insn "call_next_insn"
2173 [(parallel
2174 [(set (mem:SI (reg:SI SP_REG)) (pc))
2175 (use (match_operand 0 "" ""))])]
2176 "reload_completed"
2177 "calls %0\;%0:"
2178 [(set_attr "timings" "44")]
2179 )
2180
2181 (define_expand "add_GOT_to_pic_reg"
2182 [(parallel [(set (reg:SI PIC_REG)
2183 (plus:SI
2184 (reg:SI PIC_REG)
2185 (const:SI
2186 (unspec:SI [(minus:SI
2187 (match_dup 1)
2188 (const (minus:SI
2189 (const (match_operand:SI 0 "" ""))
2190 (pc))))
2191 ] UNSPEC_PIC))))
2192 (clobber (reg:CC CC_REG))
2193 ])
2194 ]
2195 ""
2196 "operands[1] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);"
2197 )
2198
2199 (define_expand "add_GOT_to_any_reg"
2200 [(parallel [(set (match_operand:SI 0 "" "")
2201 (plus:SI
2202 (match_operand:SI 1 "" "")
2203 (const
2204 (unspec [(minus:SI
2205 (match_dup 3)
2206 (const (minus:SI
2207 (const (match_operand:SI 2 "" ""))
2208 (pc))))
2209 ] UNSPEC_PIC))))
2210 (clobber (reg:CC CC_REG))
2211 ])
2212 ]
2213 ""
2214 "operands[3] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);"
2215 )