OSDN Git Service

2008-06-04 Joseph Myers <joseph@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / m68k / m68k.md
1 ;;- Machine description for GNU compiler, Motorola 68000 Version
2 ;;  Copyright (C) 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
3 ;;  2002, 2003, 2004, 2005, 2006, 2007
4 ;;  Free Software Foundation, Inc.
5
6 ;; This file is part of GCC.
7
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; any later version.
12
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3.  If not see
20 ;; <http://www.gnu.org/licenses/>.
21
22 ;;- Information about MCF5200 port.
23
24 ;;- The MCF5200 "ColdFire" architecture is a reduced version of the
25 ;;- 68k ISA.  Differences include reduced support for byte and word
26 ;;- operands and the removal of BCD, bitfield, rotate, and integer
27 ;;- divide instructions.  The TARGET_COLDFIRE flag turns the use of the
28 ;;- removed opcodes and addressing modes off.
29 ;;- 
30
31
32 ;;- instruction definitions
33
34 ;;- @@The original PO technology requires these to be ordered by speed,
35 ;;- @@    so that assigner will pick the fastest.
36
37 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
38
39 ;;- When naming insn's (operand 0 of define_insn) be careful about using
40 ;;- names from other targets machine descriptions.
41
42 ;;- cpp macro #define NOTICE_UPDATE_CC in file tm.h handles condition code
43 ;;- updates for most instructions.
44
45 ;;- Operand classes for the register allocator:
46 ;;- 'a' one of the address registers can be used.
47 ;;- 'd' one of the data registers can be used.
48 ;;- 'f' one of the m68881/fpu registers can be used
49 ;;- 'r' either a data or an address register can be used.
50
51 ;;- Immediate Floating point operator constraints
52 ;;- 'G' a floating point constant that is *NOT* one of the standard
53 ;;   68881 constant values (to force calling output_move_const_double
54 ;;   to get it from rom if it is a 68881 constant).
55 ;;
56 ;;   See the functions standard_XXX_constant_p in output-m68k.c for more
57 ;; info.
58
59 ;;- Immediate integer operand constraints:
60 ;;- 'I'  1 .. 8
61 ;;- 'J'  -32768 .. 32767
62 ;;- 'K'  all integers EXCEPT -128 .. 127
63 ;;- 'L'  -8 .. -1
64 ;;- 'M'  all integers EXCEPT -256 .. 255
65 ;;- 'N'  24 .. 31
66 ;;- 'O'  16
67 ;;- 'P'  8 .. 15
68
69 ;;- Assembler specs:
70 ;;- "%."    size separator ("." or "")                  move%.l d0,d1
71 ;;- "%-"    push operand "sp@-"                         move%.l d0,%-
72 ;;- "%+"    pop operand "sp@+"                          move%.l d0,%+
73 ;;- "%@"    top of stack "sp@"                          move%.l d0,%@
74 ;;- "%!"    fpcr register
75 ;;- "%$"    single-precision fp specifier ("s" or "")   f%$add.x fp0,fp1
76 ;;- "%&"    double-precision fp specifier ("d" or "")   f%&add.x fp0,fp1
77
78 ;;- Information about 68040 port.
79
80 ;;- The 68040 executes all 68030 and 68881/2 instructions, but some must
81 ;;- be emulated in software by the OS.  It is faster to avoid these
82 ;;- instructions and issue a library call rather than trapping into
83 ;;- the kernel.  The affected instructions are fintrz and fscale.  The
84 ;;- TUNE_68040 flag turns the use of the opcodes off.
85
86 ;;- The '040 also implements a set of new floating-point instructions
87 ;;- which specify the rounding precision in the opcode.  This finally
88 ;;- permit the 68k series to be truly IEEE compliant, and solves all
89 ;;- issues of excess precision accumulating in the extended registers.
90 ;;- By default, GCC does not use these instructions, since such code will
91 ;;- not run on an '030.  To use these instructions, use the -m68040-only
92 ;;- switch.
93
94 ;;- These new instructions aren't directly in the md.  They are brought
95 ;;- into play by defining "%$" and "%&" to expand to "s" and "d" rather
96 ;;- than "".
97
98 ;;- Information about 68060 port.
99
100 ;;- The 68060 executes all 68030 and 68881/2 instructions, but some must
101 ;;- be emulated in software by the OS.  It is faster to avoid these
102 ;;- instructions and issue a library call rather than trapping into
103 ;;- the kernel.  The affected instructions are: divs.l <ea>,Dr:Dq;
104 ;;- divu.l <ea>,Dr:Dq; muls.l <ea>,Dr:Dq; mulu.l <ea>,Dr:Dq; and
105 ;;- fscale.  The TUNE_68060 flag turns the use of the opcodes off.
106
107 ;;- Some of these insn's are composites of several m68000 op codes.
108 ;;- The assembler (or final @@??) insures that the appropriate one is
109 ;;- selected.
110
111 ;; UNSPEC usage:
112
113 (define_constants
114   [(UNSPEC_SIN 1)
115    (UNSPEC_COS 2)
116    (UNSPEC_GOT 3)
117    (UNSPEC_IB 4)
118    (UNSPEC_TIE 5)
119    (UNSPEC_GOTOFF 6)
120   ])
121
122 ;; UNSPEC_VOLATILE usage:
123
124 (define_constants
125   [(UNSPECV_BLOCKAGE    0)
126   ])
127
128 ;; Registers by name.
129 (define_constants
130   [(D0_REG              0)
131    (A0_REG              8)
132    (A1_REG              9)
133    (PIC_REG             13)
134    (A6_REG              14)
135    (SP_REG              15)
136    (FP0_REG             16)
137   ])
138
139 (include "predicates.md")
140 (include "constraints.md")
141 \f
142 ;; ::::::::::::::::::::
143 ;; ::
144 ;; :: Attributes
145 ;; ::
146 ;; ::::::::::::::::::::
147
148 ;; Processor type.
149 (define_attr "cpu" "cfv1, cfv2, cfv3, cfv4, unknown"
150   (const (symbol_ref "m68k_sched_cpu")))
151
152 ;; MAC type.
153 (define_attr "mac" "no, cf_mac, cf_emac"
154   (const (symbol_ref "m68k_sched_mac")))
155
156 ;; Instruction type for use in scheduling description.
157 ;; _l and _w suffixes indicate size of the operands of instruction.
158 ;; alu - usual arithmetic or logic instruction.
159 ;; aluq - arithmetic or logic instruction which has a quick immediate (the one
160 ;;        that is encoded in the instruction word) for its Y operand.
161 ;; alux - Arithmetic instruction that uses carry bit (e.g., addx and subx).
162 ;; bcc - conditional branch.
163 ;; bitr - bit operation that only updates flags.
164 ;; bitrw - bit operation that updates flags and output operand.
165 ;; bra, bsr, clr, cmp, div, ext - corresponding instruction.
166 ;; falu, fbcc, fcmp, fdiv, fmove, fmul, fneg, fsqrt, ftst - corresponding
167 ;;                                                          instruction.
168 ;; ib - fake instruction to subscribe slots in ColdFire V1,V2,V3 instruction
169 ;;      buffer.
170 ;; ignore - fake instruction.
171 ;; jmp, jsr, lea, link, mov3q, move, moveq, mul - corresponding instruction.
172 ;; mvsz - mvs or mvz instruction.
173 ;; neg, nop, pea, rts, scc - corresponding instruction.
174 ;; shift - arithmetic or logical shift instruction.
175 ;; trap, tst, unlk - corresponding instruction.
176 (define_attr "type"
177   "alu_l,aluq_l,alux_l,bcc,bitr,bitrw,bra,bsr,clr,clr_l,cmp,cmp_l,
178    div_w,div_l,ext,
179    falu,fbcc,fcmp,fdiv,fmove,fmul,fneg,fsqrt,ftst,
180    ib,ignore,
181    jmp,jsr,lea,link,mov3q_l,move,move_l,moveq_l,mul_w,mul_l,mvsz,neg_l,nop,
182    pea,rts,scc,shift,
183    trap,tst,tst_l,unlk,
184    unknown"
185   (const_string "unknown"))
186
187 ;; Index of the X or Y operand in recog_data.operand[].
188 ;; Should be used only within opx_type and opy_type.
189 (define_attr "opx" "" (const_int 0))
190 (define_attr "opy" "" (const_int 1))
191
192 ;; Type of the Y operand.
193 ;; See m68k.c: enum attr_op_type.
194 (define_attr "opy_type"
195   "none,Rn,FPn,mem1,mem234,mem5,mem6,mem7,imm_q,imm_w,imm_l"
196   (cond [(eq_attr "type" "ext,fbcc,ftst,neg_l,bcc,bra,bsr,clr,clr_l,ib,ignore,
197                           jmp,jsr,nop,rts,scc,trap,tst,tst_l,
198                           unlk,unknown") (const_string "none")
199          (eq_attr "type" "lea,pea")
200          (symbol_ref "m68k_sched_attr_opy_type (insn, 1)")]
201         (symbol_ref "m68k_sched_attr_opy_type (insn, 0)")))
202
203 ;; Type of the X operand.
204 ;; See m68k.c: enum attr_op_type.
205 (define_attr "opx_type"
206   "none,Rn,FPn,mem1,mem234,mem5,mem6,mem7,imm_q,imm_w,imm_l"
207   (cond [(eq_attr "type" "ib,ignore,nop,rts,trap,unlk,
208                           unknown") (const_string "none")
209          (eq_attr "type" "pea") (const_string "mem1")
210          (eq_attr "type" "jmp,jsr")
211          (symbol_ref "m68k_sched_attr_opx_type (insn, 1)")]
212         (symbol_ref "m68k_sched_attr_opx_type (insn, 0)")))
213
214 ;; Access to the X operand: none, read, write, read/write, unknown.
215 ;; Access to the Y operand is either none (if opy_type is none)
216 ;; or read otherwise.
217 (define_attr "opx_access" "none, r, w, rw"
218   (cond [(eq_attr "type" "ib,ignore,nop,rts,trap,unlk,
219                           unknown") (const_string "none")
220          (eq_attr "type" "bcc,bra,bsr,bitr,cmp,cmp_l,fbcc,fcmp,ftst,
221                           jmp,jsr,tst,tst_l") (const_string "r")
222          (eq_attr "type" "clr,clr_l,fneg,fmove,lea,
223                           mov3q_l,move,move_l,moveq_l,mvsz,
224                           pea,scc") (const_string "w")
225          (eq_attr "type" "alu_l,aluq_l,alux_l,bitrw,div_w,div_l,ext,
226                           falu,fdiv,fmul,fsqrt,link,mul_w,mul_l,
227                           neg_l,shift") (const_string "rw")]
228         ;; Should never be used.
229         (symbol_ref "(gcc_unreachable (), OPX_ACCESS_NONE)")))
230
231 ;; Memory accesses of the insn.
232 ;; 00 - no memory references
233 ;; 10 - memory is read
234 ;; i0 - indexed memory is read
235 ;; 01 - memory is written
236 ;; 0i - indexed memory is written
237 ;; 11 - memory is read, memory is written
238 ;; i1 - indexed memory is read, memory is written
239 ;; 1i - memory is read, indexed memory is written
240 (define_attr "op_mem" "00, 10, i0, 01, 0i, 11, i1, 1i"
241   (symbol_ref "m68k_sched_attr_op_mem (insn)"))
242
243 ;; Instruction size in words.
244 (define_attr "size" "1,2,3"
245   (symbol_ref "m68k_sched_attr_size (insn)"))
246
247 \f
248 ;; Mode macros for floating point operations.
249 ;; Valid floating point modes
250 (define_mode_iterator FP [SF DF (XF "TARGET_68881")])
251 ;; Mnemonic infix to round result
252 (define_mode_attr round [(SF "%$") (DF "%&") (XF "")])
253 ;; Mnemonic infix to round result for mul or div instruction
254 (define_mode_attr round_mul [(SF "sgl") (DF "%&") (XF "")])
255 ;; Suffix specifying source operand format
256 (define_mode_attr prec [(SF "s") (DF "d") (XF "x")])
257 ;; Allowable D registers
258 (define_mode_attr dreg [(SF "d") (DF "") (XF "")])
259 ;; Allowable 68881 constant constraints
260 (define_mode_attr const [(SF "F") (DF "G") (XF "")])
261 \f
262
263 (define_insn_and_split "*movdf_internal"
264   [(set (match_operand:DF 0 "push_operand"   "=m, m")
265         (match_operand:DF 1 "general_operand" "f, ro<>E"))]
266   ""
267   "@
268    fmove%.d %f1,%0
269    #"
270   "&& reload_completed && (extract_constrain_insn_cached (insn), which_alternative == 1)"
271   [(const_int 0)]
272 {
273   m68k_emit_move_double (operands);
274   DONE;
275 }
276   [(set_attr "type" "fmove,*")])
277
278 (define_insn_and_split "pushdi"
279   [(set (match_operand:DI 0 "push_operand" "=m")
280         (match_operand:DI 1 "general_operand" "ro<>Fi"))]
281   ""
282   "#"
283   "&& reload_completed"
284   [(const_int 0)]
285 {
286   m68k_emit_move_double (operands);
287   DONE;
288 })
289 \f
290 ;; We don't want to allow a constant operand for test insns because
291 ;; (set (cc0) (const_int foo)) has no mode information.  Such insns will
292 ;; be folded while optimizing anyway.
293
294 (define_expand "tstdi"
295   [(parallel [(set (cc0)
296                    (match_operand:DI 0 "nonimmediate_operand" ""))
297               (clobber (match_scratch:SI 1 ""))
298               (clobber (match_scratch:DI 2 ""))])]
299   ""
300   "m68k_last_compare_had_fp_operands = 0;")
301
302 (define_insn ""
303   [(set (cc0)
304         (match_operand:DI 0 "nonimmediate_operand" "am,d"))
305    (clobber (match_scratch:SI 1 "=X,d"))
306    (clobber (match_scratch:DI 2 "=d,X"))]
307   ""
308 {
309   if (which_alternative == 0)
310     {
311       rtx xoperands[2];
312
313       xoperands[0] = operands[2];
314       xoperands[1] = operands[0];
315       output_move_double (xoperands);
316       cc_status.flags |= CC_REVERSED; /*|*/
317       return "neg%.l %R2\;negx%.l %2";
318     }
319   if (find_reg_note (insn, REG_DEAD, operands[0]))
320     {
321       cc_status.flags |= CC_REVERSED; /*|*/
322       return "neg%.l %R0\;negx%.l %0";
323     }
324   else
325     /*
326        'sub' clears %1, and also clears the X cc bit
327        'tst' sets the Z cc bit according to the low part of the DImode operand
328        'subx %1' (i.e. subx #0) acts as a (non-existent) tstx on the high part.
329     */
330     return "sub%.l %1,%1\;tst%.l %R0\;subx%.l %1,%0";
331 })
332
333 (define_expand "tstsi"
334   [(set (cc0)
335         (match_operand:SI 0 "nonimmediate_operand" ""))]
336   ""
337   "m68k_last_compare_had_fp_operands = 0;")
338
339 ;; If you think that the 68020 does not support tstl a0,
340 ;; reread page B-167 of the 68020 manual more carefully.
341 (define_insn "*tstsi_internal_68020_cf"
342   [(set (cc0)
343         (match_operand:SI 0 "nonimmediate_operand" "rm"))]
344   "TARGET_68020 || TARGET_COLDFIRE"
345   "tst%.l %0"
346   [(set_attr "type" "tst_l")])
347
348 ;; On an address reg, cmpw may replace cmpl.
349 (define_insn "*tstsi_internal"
350   [(set (cc0)
351         (match_operand:SI 0 "nonimmediate_operand" "dm,r"))]
352   "!(TARGET_68020 || TARGET_COLDFIRE)"
353   "@
354    tst%.l %0
355    cmp%.w #0,%0"
356   [(set_attr "type" "tst_l,cmp")])
357
358 ;; This can't use an address register, because comparisons
359 ;; with address registers as second operand always test the whole word.
360 (define_expand "tsthi"
361   [(set (cc0)
362         (match_operand:HI 0 "nonimmediate_operand" ""))]
363   ""
364   "m68k_last_compare_had_fp_operands = 0;")
365
366 (define_insn "*tsthi_internal"
367   [(set (cc0)
368         (match_operand:HI 0 "nonimmediate_operand" "dm"))]
369   ""
370   "tst%.w %0"
371   [(set_attr "type" "tst")])
372
373 (define_expand "tstqi"
374   [(set (cc0)
375         (match_operand:QI 0 "nonimmediate_operand" ""))]
376   ""
377   "m68k_last_compare_had_fp_operands = 0;")
378
379 (define_insn "*tstqi_internal"
380   [(set (cc0)
381         (match_operand:QI 0 "nonimmediate_operand" "dm"))]
382   ""
383   "tst%.b %0"
384   [(set_attr "type" "tst")])
385
386 (define_expand "tst<mode>"
387   [(set (cc0)
388         (match_operand:FP 0 "general_operand" ""))]
389   "TARGET_HARD_FLOAT"
390 {
391   m68k_last_compare_had_fp_operands = 1;
392 })
393
394 (define_insn "tst<mode>_68881"
395   [(set (cc0)
396         (match_operand:FP 0 "general_operand" "f<FP:dreg>m"))]
397   "TARGET_68881"
398 {
399   cc_status.flags = CC_IN_68881;
400   if (FP_REG_P (operands[0]))
401     return "ftst%.x %0";
402   return "ftst%.<FP:prec> %0";
403 }
404   [(set_attr "type" "ftst")])
405
406 (define_insn "tst<mode>_cf"
407   [(set (cc0)
408         (match_operand:FP 0 "general_operand" "f<FP:dreg><Q>U"))]
409   "TARGET_COLDFIRE_FPU"
410 {
411   cc_status.flags = CC_IN_68881;
412   if (FP_REG_P (operands[0]))
413     return "ftst%.d %0";
414   return "ftst%.<FP:prec> %0";
415 }
416   [(set_attr "type" "ftst")])
417
418 \f
419 ;; compare instructions.
420
421 (define_expand "cmpdi"
422   [(parallel
423     [(set (cc0)
424           (compare (match_operand:DI 0 "nonimmediate_operand" "")
425                    (match_operand:DI 1 "general_operand" "")))
426      (clobber (match_dup 2))])]
427   ""
428   "m68k_last_compare_had_fp_operands = 0; operands[2] = gen_reg_rtx (DImode);")
429
430 (define_insn ""
431   [(set (cc0)
432         (compare (match_operand:DI 1 "nonimmediate_operand" "0,d")
433                  (match_operand:DI 2 "general_operand" "d,0")))
434    (clobber (match_operand:DI 0 "register_operand" "=d,d"))]
435   ""
436 {
437   if (rtx_equal_p (operands[0], operands[1]))
438     return "sub%.l %R2,%R0\;subx%.l %2,%0";
439   else
440     {
441       cc_status.flags |= CC_REVERSED; /*|*/
442       return "sub%.l %R1,%R0\;subx%.l %1,%0";
443     }
444 })
445
446 (define_expand "cmpsi"
447   [(set (cc0)
448         (compare (match_operand:SI 0 "nonimmediate_operand" "")
449                  (match_operand:SI 1 "general_operand" "")))]
450   ""
451 {
452   m68k_last_compare_had_fp_operands = 0;
453 })
454
455 ;; A composite of the cmp, cmpa, cmpi & cmpm m68000 op codes.
456 (define_insn ""
457   [(set (cc0)
458         (compare (match_operand:SI 0 "nonimmediate_operand" "rKT,rKs,mSr,mSa,>")
459                  (match_operand:SI 1 "general_src_operand" "mSr,mSa,KTr,Ksr,>")))]
460   "!TARGET_COLDFIRE"
461 {
462   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
463     return "cmpm%.l %1,%0";
464   if (REG_P (operands[1])
465       || (!REG_P (operands[0]) && GET_CODE (operands[0]) != MEM))
466     {
467       cc_status.flags |= CC_REVERSED; /*|*/
468       return "cmp%.l %d0,%d1";
469     }
470   if (ADDRESS_REG_P (operands[0])
471       && GET_CODE (operands[1]) == CONST_INT
472       && INTVAL (operands[1]) < 0x8000
473       && INTVAL (operands[1]) >= -0x8000)
474     return "cmp%.w %1,%0";
475   return "cmp%.l %d1,%d0";
476 })
477
478 (define_insn "*cmpsi_cf"
479   [(set (cc0)
480         (compare (match_operand:SI 0 "nonimmediate_operand" "mrKs,r")
481                  (match_operand:SI 1 "general_operand" "r,mrKs")))]
482   "TARGET_COLDFIRE"
483 {
484   if (REG_P (operands[1])
485       || (!REG_P (operands[0]) && GET_CODE (operands[0]) != MEM))
486     {
487       cc_status.flags |= CC_REVERSED; /*|*/
488       return "cmp%.l %d0,%d1";
489     }
490   return "cmp%.l %d1,%d0";
491 }
492   [(set_attr "type" "cmp_l")])
493
494 (define_expand "cmphi"
495   [(set (cc0)
496         (compare (match_operand:HI 0 "nonimmediate_src_operand" "")
497                  (match_operand:HI 1 "general_src_operand" "")))]
498   "!TARGET_COLDFIRE"
499   "m68k_last_compare_had_fp_operands = 0;")
500
501 (define_insn ""
502   [(set (cc0)
503         (compare (match_operand:HI 0 "nonimmediate_src_operand" "rnmS,d,n,mS,>")
504                  (match_operand:HI 1 "general_src_operand" "d,rnmS,mS,n,>")))]
505   "!TARGET_COLDFIRE"
506 {
507   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
508     return "cmpm%.w %1,%0";
509   if ((REG_P (operands[1]) && !ADDRESS_REG_P (operands[1]))
510       || (!REG_P (operands[0]) && GET_CODE (operands[0]) != MEM))
511     {
512       cc_status.flags |= CC_REVERSED; /*|*/
513       return "cmp%.w %d0,%d1";
514     }
515   return "cmp%.w %d1,%d0";
516 })
517
518 (define_expand "cmpqi"
519   [(set (cc0)
520         (compare (match_operand:QI 0 "nonimmediate_src_operand" "")
521                  (match_operand:QI 1 "general_src_operand" "")))]
522   "!TARGET_COLDFIRE"
523   "m68k_last_compare_had_fp_operands = 0;")
524
525 (define_insn ""
526   [(set (cc0)
527         (compare (match_operand:QI 0 "nonimmediate_src_operand" "dn,dmS,>")
528                  (match_operand:QI 1 "general_src_operand" "dmS,nd,>")))]
529   "!TARGET_COLDFIRE"
530 {
531   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
532     return "cmpm%.b %1,%0";
533   if (REG_P (operands[1])
534       || (!REG_P (operands[0]) && GET_CODE (operands[0]) != MEM))
535     {
536       cc_status.flags |= CC_REVERSED; /*|*/
537       return "cmp%.b %d0,%d1";
538     }
539   return "cmp%.b %d1,%d0";
540 })
541
542 (define_expand "cmp<mode>"
543   [(set (cc0)
544         (compare (match_operand:FP 0 "register_operand" "")
545                  (match_operand:FP 1 "fp_src_operand" "")))]
546   "TARGET_HARD_FLOAT"
547   "m68k_last_compare_had_fp_operands = 1;")
548
549 (define_insn "*cmp<mode>_68881"
550   [(set (cc0)
551         (compare (match_operand:FP 0 "fp_src_operand" "f,f,<FP:dreg>mF")
552                  (match_operand:FP 1 "fp_src_operand" "f,<FP:dreg>mF,f")))]
553   "TARGET_68881
554    && (register_operand (operands[0], <MODE>mode)
555        || register_operand (operands[1], <MODE>mode))"
556   "@
557    fcmp%.x %1,%0
558    fcmp%.<FP:prec> %f1,%0
559    fcmp%.<FP:prec> %0,%f1"
560   [(set_attr "type" "fcmp")])
561
562 (define_insn "*cmp<mode>_cf"
563   [(set (cc0)
564         (compare (match_operand:FP 0 "fp_src_operand" "f,f,<FP:dreg><Q>U")
565                  (match_operand:FP 1 "fp_src_operand" "f,<FP:dreg><Q>U,f")))]
566   "TARGET_COLDFIRE_FPU
567    && (register_operand (operands[0], <MODE>mode)
568        || register_operand (operands[1], <MODE>mode))"
569   "@
570    fcmp%.d %1,%0
571    fcmp%.<FP:prec> %f1,%0
572    fcmp%.<FP:prec> %0,%f1"
573   [(set_attr "type" "fcmp")])
574 \f
575 ;; Recognizers for btst instructions.
576
577 ;; ColdFire/5200 only allows "<Q>" type addresses when the bit position is
578 ;; specified as a constant, so we must disable all patterns that may extract
579 ;; from a MEM at a constant bit position if we can't use this as a constraint.
580
581 (define_insn ""
582   [(set (cc0) (zero_extract (match_operand:QI 0 "memory_src_operand" "oS")
583                             (const_int 1)
584                             (minus:SI (const_int 7)
585                                       (match_operand:SI 1 "general_operand" "di"))))]
586   "!TARGET_COLDFIRE"
587 {
588   return output_btst (operands, operands[1], operands[0], insn, 7);
589 })
590
591 ;; This is the same as the above pattern except for the constraints.  The 'i'
592 ;; has been deleted.
593
594 (define_insn ""
595   [(set (cc0) (zero_extract (match_operand:QI 0 "memory_operand" "o")
596                             (const_int 1)
597                             (minus:SI (const_int 7)
598                                       (match_operand:SI 1 "general_operand" "d"))))]
599   "TARGET_COLDFIRE"
600 {
601   return output_btst (operands, operands[1], operands[0], insn, 7);
602 })
603
604 (define_insn ""
605   [(set (cc0) (zero_extract (match_operand:SI 0 "register_operand" "d")
606                             (const_int 1)
607                             (minus:SI (const_int 31)
608                                       (match_operand:SI 1 "general_operand" "di"))))]
609   ""
610 {
611   return output_btst (operands, operands[1], operands[0], insn, 31);
612 })
613
614 ;; The following two patterns are like the previous two
615 ;; except that they use the fact that bit-number operands
616 ;; are automatically masked to 3 or 5 bits.
617
618 (define_insn ""
619   [(set (cc0) (zero_extract (match_operand:QI 0 "memory_operand" "o")
620                             (const_int 1)
621                             (minus:SI (const_int 7)
622                                       (and:SI
623                                        (match_operand:SI 1 "register_operand" "d")
624                                        (const_int 7)))))]
625   ""
626 {
627   return output_btst (operands, operands[1], operands[0], insn, 7);
628 })
629
630 (define_insn ""
631   [(set (cc0) (zero_extract (match_operand:SI 0 "register_operand" "d")
632                             (const_int 1)
633                             (minus:SI (const_int 31)
634                                       (and:SI
635                                        (match_operand:SI 1 "register_operand" "d")
636                                        (const_int 31)))))]
637   ""
638 {
639   return output_btst (operands, operands[1], operands[0], insn, 31);
640 })
641
642 ;; Nonoffsettable mem refs are ok in this one pattern
643 ;; since we don't try to adjust them.
644 (define_insn ""
645   [(set (cc0) (zero_extract (match_operand:QI 0 "memory_operand" "m")
646                             (const_int 1)
647                             (match_operand:SI 1 "const_int_operand" "n")))]
648   "(unsigned) INTVAL (operands[1]) < 8 && !TARGET_COLDFIRE"
649 {
650   operands[1] = GEN_INT (7 - INTVAL (operands[1]));
651   return output_btst (operands, operands[1], operands[0], insn, 7);
652 })
653
654 (define_insn ""
655   [(set (cc0) (zero_extract (match_operand:SI 0 "register_operand" "do")
656                             (const_int 1)
657                             (match_operand:SI 1 "const_int_operand" "n")))]
658   "!TARGET_COLDFIRE"
659 {
660   if (GET_CODE (operands[0]) == MEM)
661     {
662       operands[0] = adjust_address (operands[0], QImode,
663                                     INTVAL (operands[1]) / 8);
664       operands[1] = GEN_INT (7 - INTVAL (operands[1]) % 8);
665       return output_btst (operands, operands[1], operands[0], insn, 7);
666     }
667   operands[1] = GEN_INT (31 - INTVAL (operands[1]));
668   return output_btst (operands, operands[1], operands[0], insn, 31);
669 })
670
671 ;; This is the same as the above pattern except for the constraints.
672 ;; The 'o' has been replaced with 'Q'.
673
674 (define_insn ""
675   [(set (cc0) (zero_extract (match_operand:SI 0 "register_operand" "dQ")
676                             (const_int 1)
677                             (match_operand:SI 1 "const_int_operand" "n")))]
678   "TARGET_COLDFIRE"
679 {
680   if (GET_CODE (operands[0]) == MEM)
681     {
682       operands[0] = adjust_address (operands[0], QImode,
683                                     INTVAL (operands[1]) / 8);
684       operands[1] = GEN_INT (7 - INTVAL (operands[1]) % 8);
685       return output_btst (operands, operands[1], operands[0], insn, 7);
686     }
687   operands[1] = GEN_INT (31 - INTVAL (operands[1]));
688   return output_btst (operands, operands[1], operands[0], insn, 31);
689 })
690
691 \f
692 ;; move instructions
693
694 ;; A special case in which it is not desirable
695 ;; to reload the constant into a data register.
696 (define_insn "pushexthisi_const"
697   [(set (match_operand:SI 0 "push_operand" "=m,m,m")
698         (match_operand:SI 1 "const_int_operand" "C0,R,J"))]
699   "INTVAL (operands[1]) >= -0x8000 && INTVAL (operands[1]) < 0x8000"
700   "@
701    clr%.l %0
702    mov3q%.l %1,%-
703    pea %a1"
704   [(set_attr "type" "clr_l,mov3q_l,pea")])
705
706 ;This is never used.
707 ;(define_insn "swapsi"
708 ;  [(set (match_operand:SI 0 "nonimmediate_operand" "+r")
709 ;       (match_operand:SI 1 "general_operand" "+r"))
710 ;   (set (match_dup 1) (match_dup 0))]
711 ;  ""
712 ;  "exg %1,%0")
713
714 ;; Special case of fullword move when source is zero for 68000_10.
715 ;; moveq is faster on the 68000.
716 (define_insn "*movsi_const0_68000_10"
717   [(set (match_operand:SI 0 "movsi_const0_operand" "=d,a,g")
718         (const_int 0))]
719   "TUNE_68000_10"
720   "@
721    moveq #0,%0
722    sub%.l %0,%0
723    clr%.l %0"
724   [(set_attr "type" "moveq_l,alu_l,clr_l")
725    (set_attr "opy" "*,0,*")])
726
727 ;; Special case of fullword move when source is zero for 68040_60.
728 ;; On the '040, 'subl an,an' takes 2 clocks while lea takes only 1
729 (define_insn "*movsi_const0_68040_60"
730   [(set (match_operand:SI 0 "movsi_const0_operand" "=a,g")
731         (const_int 0))]
732   "TUNE_68040_60"
733 {
734   if (which_alternative == 0)
735     return MOTOROLA ? "lea 0.w,%0" : "lea 0:w,%0";
736   else if (which_alternative == 1)
737     return "clr%.l %0";
738   else
739     {
740       gcc_unreachable ();
741       return "";
742     }
743 }
744   [(set_attr "type" "lea,clr_l")])
745
746 ;; Special case of fullword move when source is zero.
747 (define_insn "*movsi_const0"
748   [(set (match_operand:SI 0 "movsi_const0_operand" "=a,g")
749         (const_int 0))]
750   "!(TUNE_68000_10 || TUNE_68040_60)"
751   "@
752    sub%.l %0,%0
753    clr%.l %0"
754   [(set_attr "type" "alu_l,clr_l")
755    (set_attr "opy" "0,*")])
756
757 ;; General case of fullword move.
758 ;;
759 ;; This is the main "hook" for PIC code.  When generating
760 ;; PIC, movsi is responsible for determining when the source address
761 ;; needs PIC relocation and appropriately calling legitimize_pic_address
762 ;; to perform the actual relocation.
763 ;;
764 ;; In both the PIC and non-PIC cases the patterns generated will
765 ;; matched by the next define_insn.
766 (define_expand "movsi"
767   [(set (match_operand:SI 0 "" "")
768         (match_operand:SI 1 "" ""))]
769   ""
770 {
771   rtx tmp, base, offset;
772
773   if (flag_pic && !TARGET_PCREL && symbolic_operand (operands[1], SImode))
774     {
775       /* The source is an address which requires PIC relocation.
776          Call legitimize_pic_address with the source, mode, and a relocation
777          register (a new pseudo, or the final destination if reload_in_progress
778          is set).   Then fall through normally */
779       rtx temp = reload_in_progress ? operands[0] : gen_reg_rtx (Pmode);
780       operands[1] = legitimize_pic_address (operands[1], SImode, temp);
781     }
782   else if (flag_pic && TARGET_PCREL && ! reload_in_progress)
783     {
784       /* Don't allow writes to memory except via a register;
785          the m68k doesn't consider PC-relative addresses to be writable.  */
786       if (symbolic_operand (operands[0], SImode))
787         operands[0] = force_reg (SImode, XEXP (operands[0], 0));
788       else if (GET_CODE (operands[0]) == MEM
789                && symbolic_operand (XEXP (operands[0], 0), SImode))
790         operands[0] = gen_rtx_MEM (SImode,
791                                force_reg (SImode, XEXP (operands[0], 0)));
792     }
793   if (M68K_OFFSETS_MUST_BE_WITHIN_SECTIONS_P)
794     {
795       split_const (operands[1], &base, &offset);
796       if (GET_CODE (base) == SYMBOL_REF
797           && !offset_within_block_p (base, INTVAL (offset)))
798         {
799           tmp = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (SImode);
800           emit_move_insn (tmp, base);
801           emit_insn (gen_addsi3 (operands[0], tmp, offset));
802           DONE;
803         }
804     }
805 })
806
807 ;; General case of fullword move.
808 (define_insn "*movsi_m68k"
809   ;; Notes: make sure no alternative allows g vs g.
810   ;; We don't allow f-regs since fixed point cannot go in them.
811   [(set (match_operand:SI 0 "nonimmediate_operand" "=g,d,a<")
812         (match_operand:SI 1 "general_src_operand" "damSnT,n,i"))]
813   "!TARGET_COLDFIRE && reload_completed"
814 {
815   return output_move_simode (operands);
816 })
817
818 ;; Before reload is completed the register constraints
819 ;; force integer constants in range for a moveq to be reloaded
820 ;; if they are headed for memory.
821 (define_insn "*movsi_m68k2"
822   [(set (match_operand:SI 0 "nonimmediate_operand" "=g,d,a<")
823         (match_operand:SI 1 "general_src_operand" "damSKT,n,i"))]
824
825   "!TARGET_COLDFIRE"
826 {
827   return output_move_simode (operands);
828 })
829
830 ;; ColdFire move instructions can have at most one operand of mode >= 6.
831 (define_insn "*movsi_cf"
832   [(set (match_operand:SI 0 "nonimmediate_operand" "=g,d, d, d, d, d, a,Ap,  a,  r<Q>,g,    U")
833         (match_operand:SI 1 "general_operand"      " R,CQ,CW,CZ,CS,Ci,J,J Cs,Cs, g,   Rr<Q>,U"))]
834   "TARGET_COLDFIRE"
835 {
836   switch (which_alternative)
837     {
838     case 0:
839       return "mov3q%.l %1,%0";
840
841     case 1:
842       return "moveq %1,%0";
843
844     case 2:
845       {
846         unsigned u = INTVAL (operands[1]);
847
848         operands[1] = GEN_INT ((u << 16) | (u >> 16));  /*|*/
849         return "moveq %1,%0\n\tswap %0";
850       }
851
852     case 3:
853       return "mvz%.w %1,%0";
854
855     case 4:
856       return "mvs%.w %1,%0";
857
858     case 5:
859       return "move%.l %1,%0";
860
861     case 6:
862       return "move%.w %1,%0";
863
864     case 7:
865       return "pea %a1";
866
867     case 8:
868       return "lea %a1,%0";
869
870     case 9:
871     case 10:
872     case 11:
873       return "move%.l %1,%0";
874
875     default:
876       gcc_unreachable ();
877       return "";
878     }
879 }
880   [(set_attr "type" "mov3q_l,moveq_l,*,mvsz,mvsz,move_l,move,pea,lea,move_l,move_l,move_l")])
881
882 ;; Special case of fullword move, where we need to get a non-GOT PIC
883 ;; reference into an address register.
884 (define_insn ""
885   [(set (match_operand:SI 0 "nonimmediate_operand" "=a<")
886         (match_operand:SI 1 "pcrel_address" ""))]
887   "TARGET_PCREL"
888 {
889   if (push_operand (operands[0], SImode))
890     return "pea %a1";
891   return "lea %a1,%0";
892 })
893
894 (define_expand "movhi"
895   [(set (match_operand:HI 0 "nonimmediate_operand" "")
896         (match_operand:HI 1 "general_operand" ""))]
897   ""
898   "")
899
900 (define_insn ""
901   [(set (match_operand:HI 0 "nonimmediate_operand" "=g")
902         (match_operand:HI 1 "general_src_operand" "gS"))]
903   "!TARGET_COLDFIRE"
904   "* return output_move_himode (operands);")
905
906 (define_insn ""
907   [(set (match_operand:HI 0 "nonimmediate_operand" "=r<Q>,g,U")
908         (match_operand:HI 1 "general_operand" "g,r<Q>,U"))]
909   "TARGET_COLDFIRE"
910   "* return output_move_himode (operands);")
911
912 (define_expand "movstricthi"
913   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" ""))
914         (match_operand:HI 1 "general_src_operand" ""))]
915   ""
916   "")
917
918 (define_insn ""
919   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+dm"))
920         (match_operand:HI 1 "general_src_operand" "rmSn"))]
921   "!TARGET_COLDFIRE"
922   "* return output_move_stricthi (operands);")
923
924 (define_insn ""
925   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+d,m"))
926         (match_operand:HI 1 "general_src_operand" "rmn,r"))]
927   "TARGET_COLDFIRE"
928   "* return output_move_stricthi (operands);")
929
930 (define_expand "movqi"
931   [(set (match_operand:QI 0 "nonimmediate_operand" "")
932         (match_operand:QI 1 "general_src_operand" ""))]
933   ""
934   "")
935
936 (define_insn ""
937   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,*a,m")
938         (match_operand:QI 1 "general_src_operand" "dmSi*a,di*a,dmSi"))]
939   "!TARGET_COLDFIRE"
940   "* return output_move_qimode (operands);")
941
942 (define_insn ""
943   [(set (match_operand:QI 0 "nonimmediate_operand" "=d<Q>,dm,U,d*a")
944         (match_operand:QI 1 "general_src_operand" "dmi,d<Q>,U,di*a"))]
945   "TARGET_COLDFIRE"
946   "* return output_move_qimode (operands);")
947
948 (define_expand "movstrictqi"
949   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
950         (match_operand:QI 1 "general_src_operand" ""))]
951   ""
952   "")
953
954 (define_insn ""
955   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+dm"))
956         (match_operand:QI 1 "general_src_operand" "dmSn"))]
957   "!TARGET_COLDFIRE"
958   "* return output_move_strictqi (operands);")
959
960 (define_insn "*movstrictqi_cf"
961   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+d, Ac, d,m"))
962         (match_operand:QI 1 "general_src_operand"                    "C0,C0, dmn,d"))]
963   "TARGET_COLDFIRE"
964   "@
965    clr%.b %0
966    clr%.b %0
967    move%.b %1,%0
968    move%.b %1,%0"
969   [(set_attr "type" "clr,clr,move,move")])
970
971 (define_expand "pushqi1"
972   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int -2)))
973    (set (mem:QI (plus:SI (reg:SI SP_REG) (const_int 1)))
974         (match_operand:QI 0 "general_operand" ""))]
975   "!TARGET_COLDFIRE"
976   "")
977
978 (define_expand "reload_insf"
979   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
980         (match_operand:SF 1 "general_operand" "mf"))
981    (clobber (match_operand:SI 2 "register_operand" "=&a"))]
982   "TARGET_COLDFIRE_FPU"
983 {
984   if (emit_move_sequence (operands, SFmode, operands[2]))
985     DONE;
986
987   /* We don't want the clobber emitted, so handle this ourselves. */
988   emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
989   DONE;
990 })
991
992 (define_expand "reload_outsf"
993   [(set (match_operand:SF 0 "general_operand" "")
994         (match_operand:SF 1 "register_operand" "f"))
995    (clobber (match_operand:SI 2 "register_operand" "=&a"))]
996   "TARGET_COLDFIRE_FPU"
997 {
998   if (emit_move_sequence (operands, SFmode, operands[2]))
999     DONE;
1000
1001   /* We don't want the clobber emitted, so handle this ourselves. */
1002   emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1003   DONE;
1004 })
1005
1006 (define_expand "movsf"
1007   [(set (match_operand:SF 0 "nonimmediate_operand" "")
1008         (match_operand:SF 1 "general_operand" ""))]
1009   ""
1010   "")
1011
1012 (define_insn ""
1013   [(set (match_operand:SF 0 "nonimmediate_operand" "=rmf")
1014         (match_operand:SF 1 "general_operand" "rmfF"))]
1015   "!TARGET_COLDFIRE"
1016 {
1017   if (FP_REG_P (operands[0]))
1018     {
1019       if (FP_REG_P (operands[1]))
1020         return "f%$move%.x %1,%0";
1021       else if (ADDRESS_REG_P (operands[1]))
1022         return "move%.l %1,%-\;f%$move%.s %+,%0";
1023       else if (GET_CODE (operands[1]) == CONST_DOUBLE)
1024         return output_move_const_single (operands);
1025       return "f%$move%.s %f1,%0";
1026     }
1027   if (FP_REG_P (operands[1]))
1028     {
1029       if (ADDRESS_REG_P (operands[0]))
1030         return "fmove%.s %1,%-\;move%.l %+,%0";
1031       return "fmove%.s %f1,%0";
1032     }
1033   if (operands[1] == CONST0_RTX (SFmode)
1034       /* clr insns on 68000 read before writing.  */
1035       && ((TARGET_68010 || TARGET_COLDFIRE)
1036           || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
1037     {
1038       if (ADDRESS_REG_P (operands[0]))
1039         {
1040           /* On the '040, 'subl an,an' takes 2 clocks while lea takes only 1 */
1041           if (TUNE_68040_60)
1042             return MOTOROLA ? "lea 0.w,%0" : "lea 0:w,%0";
1043           else
1044             return "sub%.l %0,%0";
1045         }
1046       /* moveq is faster on the 68000.  */
1047       if (DATA_REG_P (operands[0]) && TUNE_68000_10)
1048         return "moveq #0,%0";
1049       return "clr%.l %0";
1050     }
1051   return "move%.l %1,%0";
1052 })
1053
1054 (define_insn "movsf_cf_soft"
1055   [(set (match_operand:SF 0 "nonimmediate_operand" "=r<Q>,g,U")
1056         (match_operand:SF 1 "general_operand" "g,r<Q>,U"))]
1057   "TARGET_COLDFIRE && !TARGET_COLDFIRE_FPU"
1058   "move%.l %1,%0"
1059   [(set_attr "type" "move_l")])
1060
1061 ;; SFmode MEMs are restricted to modes 2-4 if TARGET_COLDFIRE_FPU.
1062 ;; The move instructions can handle all combinations.
1063 (define_insn "movsf_cf_hard"
1064   [(set (match_operand:SF 0 "nonimmediate_operand" "=r<Q>U, f,    f,mr,f,r<Q>,f
1065 ,m")
1066         (match_operand:SF 1 "general_operand"      " f,     r<Q>U,f,rm,F,F,   m
1067 ,f"))]
1068   "TARGET_COLDFIRE_FPU"
1069 {
1070   if (which_alternative == 4 || which_alternative == 5) {
1071     rtx xoperands[2];
1072     REAL_VALUE_TYPE r;
1073     long l;
1074     REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
1075     REAL_VALUE_TO_TARGET_SINGLE (r, l);
1076     xoperands[0] = operands[0];
1077     xoperands[1] = GEN_INT (l);
1078     if (which_alternative == 5) {
1079       if (l == 0) {
1080         if (ADDRESS_REG_P (xoperands[0]))
1081           output_asm_insn ("sub%.l %0,%0", xoperands);
1082         else
1083           output_asm_insn ("clr%.l %0", xoperands);
1084       } else
1085         if (GET_CODE (operands[0]) == MEM
1086             && symbolic_operand (XEXP (operands[0], 0), SImode))
1087           output_asm_insn ("move%.l %1,%-;move%.l %+,%0", xoperands);
1088         else
1089           output_asm_insn ("move%.l %1,%0", xoperands);
1090       return "";
1091     }
1092     if (l != 0)
1093       output_asm_insn ("move%.l %1,%-;fsmove%.s %+,%0", xoperands);
1094     else
1095       output_asm_insn ("clr%.l %-;fsmove%.s %+,%0", xoperands);
1096     return "";
1097   }
1098   if (FP_REG_P (operands[0]))
1099     {
1100       if (ADDRESS_REG_P (operands[1]))
1101         return "move%.l %1,%-;fsmove%.s %+,%0";
1102       if (FP_REG_P (operands[1]))
1103         return "fsmove%.d %1,%0";
1104       return "fsmove%.s %f1,%0";
1105     }
1106   if (FP_REG_P (operands[1]))
1107     {
1108       if (ADDRESS_REG_P (operands[0]))
1109         return "fmove%.s %1,%-;move%.l %+,%0";
1110       return "fmove%.s %f1,%0";
1111     }
1112   if (operands[1] == CONST0_RTX (SFmode))
1113     {
1114       if (ADDRESS_REG_P (operands[0]))
1115         return "sub%.l %0,%0";
1116       return "clr%.l %0";
1117     }
1118   return "move%.l %1,%0";
1119 })
1120
1121 (define_expand "reload_indf"
1122   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
1123         (match_operand:DF 1 "general_operand" "mf"))
1124    (clobber (match_operand:SI 2 "register_operand" "=&a"))]
1125   "TARGET_COLDFIRE_FPU"
1126 {
1127   if (emit_move_sequence (operands, DFmode, operands[2]))
1128     DONE;
1129
1130   /* We don't want the clobber emitted, so handle this ourselves. */
1131   emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1132   DONE;
1133 })
1134
1135 (define_expand "reload_outdf"
1136   [(set (match_operand:DF 0 "general_operand" "")
1137         (match_operand:DF 1 "register_operand" "f"))
1138    (clobber (match_operand:SI 2 "register_operand" "=&a"))]
1139   "TARGET_COLDFIRE_FPU"
1140 {
1141   if (emit_move_sequence (operands, DFmode, operands[2]))
1142     DONE;
1143
1144   /* We don't want the clobber emitted, so handle this ourselves. */
1145   emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
1146   DONE;
1147 })
1148
1149 (define_expand "movdf"
1150   [(set (match_operand:DF 0 "nonimmediate_operand" "")
1151         (match_operand:DF 1 "general_operand" ""))]
1152   ""
1153 {
1154   if (TARGET_COLDFIRE_FPU)
1155     if (emit_move_sequence (operands, DFmode, 0))
1156       DONE;
1157 })
1158
1159 (define_insn ""
1160   [(set (match_operand:DF 0 "nonimmediate_operand" "=rm,rf,rf,&rof<>")
1161         (match_operand:DF 1 "general_operand" "*rf,m,0,*rofE<>"))]
1162 ;  [(set (match_operand:DF 0 "nonimmediate_operand" "=rm,&rf,&rof<>")
1163 ;       (match_operand:DF 1 "general_operand" "rf,m,rofF<>"))]
1164   "!TARGET_COLDFIRE"
1165 {
1166   if (FP_REG_P (operands[0]))
1167     {
1168       if (FP_REG_P (operands[1]))
1169         return "f%&move%.x %1,%0";
1170       if (REG_P (operands[1]))
1171         {
1172           rtx xoperands[2];
1173           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
1174           output_asm_insn ("move%.l %1,%-", xoperands);
1175           output_asm_insn ("move%.l %1,%-", operands);
1176           return "f%&move%.d %+,%0";
1177         }
1178       if (GET_CODE (operands[1]) == CONST_DOUBLE)
1179         return output_move_const_double (operands);
1180       return "f%&move%.d %f1,%0";
1181     }
1182   else if (FP_REG_P (operands[1]))
1183     {
1184       if (REG_P (operands[0]))
1185         {
1186           output_asm_insn ("fmove%.d %f1,%-\;move%.l %+,%0", operands);
1187           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1188           return "move%.l %+,%0";
1189         }
1190       else
1191         return "fmove%.d %f1,%0";
1192     }
1193   return output_move_double (operands);
1194 })
1195
1196 (define_insn_and_split "movdf_cf_soft"
1197   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,g")
1198         (match_operand:DF 1 "general_operand" "g,r"))]
1199   "TARGET_COLDFIRE && !TARGET_COLDFIRE_FPU"
1200   "#"
1201   "&& reload_completed"
1202   [(const_int 0)]
1203 {
1204   m68k_emit_move_double (operands);
1205   DONE;
1206 })
1207
1208 (define_insn "movdf_cf_hard"
1209   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,    <Q>U,r,f,r,r,m,f")
1210         (match_operand:DF 1 "general_operand"      " f<Q>U,f,   f,r,r,m,r,E"))]
1211   "TARGET_COLDFIRE_FPU"
1212 {
1213   rtx xoperands[3];
1214   REAL_VALUE_TYPE r;
1215   long l[2];
1216
1217   switch (which_alternative)
1218     {
1219     default:
1220       return "fdmove%.d %1,%0";
1221     case 1:
1222       return "fmove%.d %1,%0";
1223     case 2:
1224       return "fmove%.d %1,%-;move%.l %+,%0;move%.l %+,%R0";
1225     case 3:
1226       return "move%.l %R1,%-;move%.l %1,%-;fdmove%.d %+,%0";
1227     case 4: case 5: case 6:
1228       return output_move_double (operands);
1229     case 7:
1230       REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
1231       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
1232       xoperands[0] = operands[0];
1233       xoperands[1] = GEN_INT (l[0]);
1234       xoperands[2] = GEN_INT (l[1]);
1235       if (operands[1] == CONST0_RTX (DFmode))
1236         output_asm_insn ("clr%.l %-;clr%.l %-;fdmove%.d %+,%0",
1237                         xoperands);
1238       else
1239         if (l[1] == 0)
1240           output_asm_insn ("clr%.l %-;move%.l %1,%-;fdmove%.d %+,%0",
1241                           xoperands);
1242         else
1243           output_asm_insn ("move%.l %2,%-;move%.l %1,%-;fdmove%.d %+,%0",
1244                           xoperands);
1245       return "";
1246     }
1247 })
1248
1249 ;; ??? The XFmode patterns are schizophrenic about whether constants are
1250 ;; allowed.  Most but not all have predicates and constraint that disallow
1251 ;; constants.  Most but not all have output templates that handle constants.
1252 ;; See also LEGITIMATE_CONSTANT_P.
1253
1254 (define_expand "movxf"
1255   [(set (match_operand:XF 0 "nonimmediate_operand" "")
1256         (match_operand:XF 1 "general_operand" ""))]
1257   ""
1258 {
1259   /* We can't rewrite operands during reload.  */
1260   if (! reload_in_progress)
1261     {
1262       if (CONSTANT_P (operands[1]))
1263         {
1264           operands[1] = force_const_mem (XFmode, operands[1]);
1265           if (! memory_address_p (XFmode, XEXP (operands[1], 0)))
1266             operands[1] = adjust_address (operands[1], XFmode, 0);
1267         }
1268       if (flag_pic && TARGET_PCREL)
1269         {
1270           /* Don't allow writes to memory except via a register; the
1271              m68k doesn't consider PC-relative addresses to be writable.  */
1272           if (GET_CODE (operands[0]) == MEM
1273               && symbolic_operand (XEXP (operands[0], 0), SImode))
1274             operands[0] = gen_rtx_MEM (XFmode,
1275                                    force_reg (SImode, XEXP (operands[0], 0)));
1276         }
1277     }
1278 })
1279
1280 (define_insn ""
1281   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m,f,!r,!f,!r,m,!r")
1282         (match_operand:XF 1 "nonimmediate_operand" "m,f,f,f,r,!r,!r,m"))]
1283   "TARGET_68881"
1284 {
1285   if (FP_REG_P (operands[0]))
1286     {
1287       if (FP_REG_P (operands[1]))
1288         return "fmove%.x %1,%0";
1289       if (REG_P (operands[1]))
1290         {
1291           rtx xoperands[2];
1292           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2);
1293           output_asm_insn ("move%.l %1,%-", xoperands);
1294           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
1295           output_asm_insn ("move%.l %1,%-", xoperands);
1296           output_asm_insn ("move%.l %1,%-", operands);
1297           return "fmove%.x %+,%0";
1298         }
1299       if (GET_CODE (operands[1]) == CONST_DOUBLE)
1300         return "fmove%.x %1,%0";
1301       return "fmove%.x %f1,%0";
1302     }
1303   if (FP_REG_P (operands[1]))
1304     {
1305       if (REG_P (operands[0]))
1306         {
1307           output_asm_insn ("fmove%.x %f1,%-\;move%.l %+,%0", operands);
1308           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1309           output_asm_insn ("move%.l %+,%0", operands);
1310           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1311           return "move%.l %+,%0";
1312         }
1313       /* Must be memory destination.  */
1314       return "fmove%.x %f1,%0";
1315     }
1316   return output_move_double (operands);
1317 })
1318
1319 (define_insn ""
1320   [(set (match_operand:XF 0 "nonimmediate_operand" "=rm,rf,&rof<>")
1321         (match_operand:XF 1 "nonimmediate_operand" "rf,m,rof<>"))]
1322   "! TARGET_68881 && ! TARGET_COLDFIRE"
1323 {
1324   if (FP_REG_P (operands[0]))
1325     {
1326       if (FP_REG_P (operands[1]))
1327         return "fmove%.x %1,%0";
1328       if (REG_P (operands[1]))
1329         {
1330           rtx xoperands[2];
1331           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2);
1332           output_asm_insn ("move%.l %1,%-", xoperands);
1333           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
1334           output_asm_insn ("move%.l %1,%-", xoperands);
1335           output_asm_insn ("move%.l %1,%-", operands);
1336           return "fmove%.x %+,%0";
1337         }
1338       if (GET_CODE (operands[1]) == CONST_DOUBLE)
1339         return "fmove%.x %1,%0";
1340       return "fmove%.x %f1,%0";
1341     }
1342   if (FP_REG_P (operands[1]))
1343     {
1344       if (REG_P (operands[0]))
1345         {
1346           output_asm_insn ("fmove%.x %f1,%-\;move%.l %+,%0", operands);
1347           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1348           output_asm_insn ("move%.l %+,%0", operands);
1349           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1350           return "move%.l %+,%0";
1351         }
1352       else
1353         return "fmove%.x %f1,%0";
1354     }
1355   return output_move_double (operands);
1356 })
1357
1358 (define_insn ""
1359   [(set (match_operand:XF 0 "nonimmediate_operand" "=r,g")
1360         (match_operand:XF 1 "nonimmediate_operand" "g,r"))]
1361   "! TARGET_68881 && TARGET_COLDFIRE"
1362   "* return output_move_double (operands);")
1363
1364 (define_expand "movdi"
1365   ;; Let's see if it really still needs to handle fp regs, and, if so, why.
1366   [(set (match_operand:DI 0 "nonimmediate_operand" "")
1367         (match_operand:DI 1 "general_operand" ""))]
1368   ""
1369   "")
1370
1371 ;; movdi can apply to fp regs in some cases
1372 (define_insn ""
1373   ;; Let's see if it really still needs to handle fp regs, and, if so, why.
1374   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r,&ro<>")
1375         (match_operand:DI 1 "general_operand" "rF,m,roi<>F"))]
1376 ;  [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,&r,&ro<>,!&rm,!&f")
1377 ;       (match_operand:DI 1 "general_operand" "r,m,roi<>,fF"))]
1378 ;  [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,&rf,&ro<>,!&rm,!&f")
1379 ;       (match_operand:DI 1 "general_operand" "r,m,roi<>,fF,rfF"))]
1380   "!TARGET_COLDFIRE"
1381 {
1382   if (FP_REG_P (operands[0]))
1383     {
1384       if (FP_REG_P (operands[1]))
1385         return "fmove%.x %1,%0";
1386       if (REG_P (operands[1]))
1387         {
1388           rtx xoperands[2];
1389           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
1390           output_asm_insn ("move%.l %1,%-", xoperands);
1391           output_asm_insn ("move%.l %1,%-", operands);
1392           return "fmove%.d %+,%0";
1393         }
1394       if (GET_CODE (operands[1]) == CONST_DOUBLE)
1395         return output_move_const_double (operands);
1396       return "fmove%.d %f1,%0";
1397     }
1398   else if (FP_REG_P (operands[1]))
1399     {
1400       if (REG_P (operands[0]))
1401         {
1402           output_asm_insn ("fmove%.d %f1,%-\;move%.l %+,%0", operands);
1403           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1404           return "move%.l %+,%0";
1405         }
1406       else
1407         return "fmove%.d %f1,%0";
1408     }
1409   return output_move_double (operands);
1410 })
1411
1412 (define_insn ""
1413   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,g")
1414         (match_operand:DI 1 "general_operand" "g,r"))]
1415   "TARGET_COLDFIRE"
1416   "* return output_move_double (operands);")
1417
1418 ;; Thus goes after the move instructions
1419 ;; because the move instructions are better (require no spilling)
1420 ;; when they can apply.  It goes before the add/sub insns
1421 ;; so we will prefer it to them.
1422
1423 (define_insn "pushasi"
1424   [(set (match_operand:SI 0 "push_operand" "=m")
1425         (match_operand:SI 1 "address_operand" "p"))]
1426   ""
1427   "pea %a1"
1428   [(set_attr "type" "pea")])
1429 \f
1430 ;; truncation instructions
1431 (define_insn "truncsiqi2"
1432   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm,d")
1433         (truncate:QI
1434          (match_operand:SI 1 "general_src_operand" "doJS,i")))]
1435   ""
1436 {
1437   if (GET_CODE (operands[0]) == REG)
1438     {
1439       /* Must clear condition codes, since the move.l bases them on
1440          the entire 32 bits, not just the desired 8 bits.  */
1441       CC_STATUS_INIT;
1442       return "move%.l %1,%0";
1443     }
1444   if (GET_CODE (operands[1]) == MEM)
1445     operands[1] = adjust_address (operands[1], QImode, 3);
1446   return "move%.b %1,%0";
1447 })
1448
1449 (define_insn "trunchiqi2"
1450   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm,d")
1451         (truncate:QI
1452          (match_operand:HI 1 "general_src_operand" "doJS,i")))]
1453   ""
1454 {
1455   if (GET_CODE (operands[0]) == REG
1456       && (GET_CODE (operands[1]) == MEM
1457           || GET_CODE (operands[1]) == CONST_INT))
1458     {
1459       /* Must clear condition codes, since the move.w bases them on
1460          the entire 16 bits, not just the desired 8 bits.  */
1461       CC_STATUS_INIT;
1462       return "move%.w %1,%0";
1463     }
1464   if (GET_CODE (operands[0]) == REG)
1465     {
1466       /* Must clear condition codes, since the move.l bases them on
1467          the entire 32 bits, not just the desired 8 bits.  */
1468       CC_STATUS_INIT;
1469       return "move%.l %1,%0";
1470     }
1471   if (GET_CODE (operands[1]) == MEM)
1472     operands[1] = adjust_address (operands[1], QImode, 1);
1473   return "move%.b %1,%0";
1474 })
1475
1476 (define_insn "truncsihi2"
1477   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm,d")
1478         (truncate:HI
1479          (match_operand:SI 1 "general_src_operand" "roJS,i")))]
1480   ""
1481 {
1482   if (GET_CODE (operands[0]) == REG)
1483     {
1484       /* Must clear condition codes, since the move.l bases them on
1485          the entire 32 bits, not just the desired 8 bits.  */
1486       CC_STATUS_INIT;
1487       return "move%.l %1,%0";
1488     }
1489   if (GET_CODE (operands[1]) == MEM)
1490     operands[1] = adjust_address (operands[1], QImode, 2);
1491   return "move%.w %1,%0";
1492 })
1493 \f
1494 ;; zero extension instructions
1495
1496 ;; two special patterns to match various post_inc/pre_dec patterns
1497 (define_insn_and_split "*zero_extend_inc"
1498   [(set (match_operand 0 "post_inc_operand" "")
1499         (zero_extend (match_operand 1 "register_operand" "")))]
1500   "GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT &&
1501    GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT &&
1502    GET_MODE_SIZE (GET_MODE (operands[0])) == GET_MODE_SIZE (GET_MODE (operands[1])) * 2"
1503   "#"
1504   ""
1505   [(set (match_dup 0)
1506         (const_int 0))
1507    (set (match_dup 0)
1508         (match_dup 1))]
1509 {
1510   operands[0] = adjust_address (operands[0], GET_MODE (operands[1]), 0);
1511 })
1512
1513 (define_insn_and_split "*zero_extend_dec"
1514   [(set (match_operand 0 "pre_dec_operand" "")
1515         (zero_extend (match_operand 1 "register_operand" "")))]
1516   "(GET_MODE (operands[0]) != HImode || XEXP (XEXP (operands[0], 0), 0) != stack_pointer_rtx) &&
1517    GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT &&
1518    GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT &&
1519    GET_MODE_SIZE (GET_MODE (operands[0])) == GET_MODE_SIZE (GET_MODE (operands[1])) * 2"
1520   "#"
1521   ""
1522   [(set (match_dup 0)
1523         (match_dup 1))
1524    (set (match_dup 0)
1525         (const_int 0))]
1526 {
1527   operands[0] = adjust_address (operands[0], GET_MODE (operands[1]), 0);
1528 })
1529
1530 (define_insn_and_split "zero_extendqidi2"
1531   [(set (match_operand:DI 0 "register_operand" "")
1532         (zero_extend:DI (match_operand:QI 1 "nonimmediate_src_operand" "")))]
1533   ""
1534   "#"
1535   ""
1536   [(set (match_dup 2)
1537         (zero_extend:SI (match_dup 1)))
1538    (set (match_dup 3)
1539         (const_int 0))]
1540 {
1541   operands[2] = gen_lowpart (SImode, operands[0]);
1542   operands[3] = gen_highpart (SImode, operands[0]);
1543 })
1544
1545 (define_insn_and_split "zero_extendhidi2"
1546   [(set (match_operand:DI 0 "register_operand" "")
1547         (zero_extend:DI (match_operand:HI 1 "nonimmediate_src_operand" "")))]
1548   ""
1549   "#"
1550   ""
1551   [(set (match_dup 2)
1552         (zero_extend:SI (match_dup 1)))
1553    (set (match_dup 3)
1554         (const_int 0))]
1555 {
1556   operands[2] = gen_lowpart (SImode, operands[0]);
1557   operands[3] = gen_highpart (SImode, operands[0]);
1558 })
1559
1560 (define_expand "zero_extendsidi2"
1561   [(set (match_operand:DI 0 "nonimmediate_operand" "")
1562         (zero_extend:DI (match_operand:SI 1 "nonimmediate_src_operand" "")))]
1563   ""
1564 {
1565   if (GET_CODE (operands[0]) == MEM
1566       && GET_CODE (operands[1]) == MEM)
1567     operands[1] = force_reg (SImode, operands[1]);
1568 })
1569
1570 (define_insn_and_split "*zero_extendsidi2"
1571   [(set (match_operand:DI 0 "nonimmediate_operand" "")
1572         (zero_extend:DI (match_operand:SI 1 "nonimmediate_src_operand" "")))]
1573   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM"
1574   "#"
1575   ""
1576   [(set (match_dup 2)
1577         (match_dup 1))
1578    (set (match_dup 3)
1579         (const_int 0))]
1580 {
1581   operands[2] = gen_lowpart (SImode, operands[0]);
1582   operands[3] = gen_highpart (SImode, operands[0]);
1583 })
1584
1585 (define_insn "*zero_extendhisi2_cf"
1586   [(set (match_operand:SI 0 "register_operand" "=d")
1587         (zero_extend:SI (match_operand:HI 1 "nonimmediate_src_operand" "rmS")))]
1588   "ISA_HAS_MVS_MVZ"
1589   "mvz%.w %1,%0"
1590   [(set_attr "type" "mvsz")])
1591
1592 (define_insn "zero_extendhisi2"
1593   [(set (match_operand:SI 0 "register_operand" "=d")
1594         (zero_extend:SI (match_operand:HI 1 "nonimmediate_src_operand" "rmS")))]
1595   ""
1596   "#")
1597
1598 (define_expand "zero_extendqihi2"
1599   [(set (match_operand:HI 0 "register_operand" "")
1600         (zero_extend:HI (match_operand:QI 1 "nonimmediate_src_operand" "")))]
1601   "!TARGET_COLDFIRE"
1602   "")
1603
1604 (define_insn "*zero_extendqihi2"
1605   [(set (match_operand:HI 0 "register_operand" "=d")
1606         (zero_extend:HI (match_operand:QI 1 "nonimmediate_src_operand" "dmS")))]
1607   "!TARGET_COLDFIRE"
1608   "#")
1609
1610 (define_insn "*zero_extendqisi2_cfv4"
1611   [(set (match_operand:SI 0 "register_operand" "=d")
1612         (zero_extend:SI (match_operand:QI 1 "nonimmediate_src_operand" "dmS")))]
1613   "ISA_HAS_MVS_MVZ"
1614   "mvz%.b %1,%0"
1615   [(set_attr "type" "mvsz")])
1616
1617 (define_insn "zero_extendqisi2"
1618   [(set (match_operand:SI 0 "register_operand" "=d")
1619         (zero_extend:SI (match_operand:QI 1 "nonimmediate_src_operand" "dmS")))]
1620   ""
1621   "#")
1622
1623 ;; these two pattern split everything else which isn't matched by
1624 ;; something else above
1625 (define_split
1626   [(set (match_operand 0 "register_operand" "")
1627         (zero_extend (match_operand 1 "nonimmediate_src_operand" "")))]
1628   "!ISA_HAS_MVS_MVZ
1629    && reload_completed
1630    && reg_mentioned_p (operands[0], operands[1])"
1631   [(set (strict_low_part (match_dup 2))
1632         (match_dup 1))
1633    (set (match_dup 0)
1634         (match_op_dup 4 [(match_dup 0) (match_dup 3)]))]
1635 {
1636   operands[2] = gen_lowpart (GET_MODE (operands[1]), operands[0]);
1637   operands[3] = GEN_INT (GET_MODE_MASK (GET_MODE (operands[1])));
1638   operands[4] = gen_rtx_AND (GET_MODE (operands[0]), operands[0], operands[3]);
1639 })
1640
1641 (define_split
1642   [(set (match_operand 0 "register_operand" "")
1643         (zero_extend (match_operand 1 "nonimmediate_src_operand" "")))]
1644   "!ISA_HAS_MVS_MVZ && reload_completed"
1645   [(set (match_dup 0)
1646         (const_int 0))
1647    (set (strict_low_part (match_dup 2))
1648         (match_dup 1))]
1649 {
1650   operands[2] = gen_lowpart (GET_MODE (operands[1]), operands[0]);
1651 })
1652 \f
1653 ;; sign extension instructions
1654
1655 (define_insn "extendqidi2"
1656   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
1657         (sign_extend:DI (match_operand:QI 1 "general_src_operand" "rmS")))]
1658   ""
1659 {
1660   CC_STATUS_INIT;
1661   operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1662   if (ISA_HAS_MVS_MVZ)
1663     return "mvs%.b %1,%2\;smi %0\;extb%.l %0";
1664   if (TARGET_68020 || TARGET_COLDFIRE)
1665     {
1666       if (ADDRESS_REG_P (operands[1]))
1667         return "move%.w %1,%2\;extb%.l %2\;smi %0\;extb%.l %0";
1668       else
1669         return "move%.b %1,%2\;extb%.l %2\;smi %0\;extb%.l %0";
1670     }
1671   else
1672     {
1673       if (ADDRESS_REG_P (operands[1]))
1674         return "move%.w %1,%2\;ext%.w %2\;ext%.l %2\;move%.l %2,%0\;smi %0";
1675       else
1676         return "move%.b %1,%2\;ext%.w %2\;ext%.l %2\;move%.l %2,%0\;smi %0";
1677     }
1678 })
1679
1680 (define_insn "extendhidi2"
1681   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
1682         (sign_extend:DI
1683          (match_operand:HI 1 "general_src_operand" "rmS")))]
1684   ""
1685 {
1686   CC_STATUS_INIT;
1687   operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1688   if (ISA_HAS_MVS_MVZ)
1689     return "mvs%.w %1,%2\;smi %0\;extb%.l %0";
1690   if (TARGET_68020 || TARGET_COLDFIRE)
1691     return "move%.w %1,%2\;ext%.l %2\;smi %0\;extb%.l %0";
1692   else
1693     return "move%.w %1,%2\;ext%.l %2\;smi %0\;ext%.w %0\;ext%.l %0";
1694 })
1695
1696 (define_insn "extendsidi2"
1697   [(set (match_operand:DI 0 "register_operand" "=d")
1698         (sign_extend:DI (match_operand:SI 1 "nonimmediate_src_operand" "rm")))]
1699   ""
1700 {
1701   CC_STATUS_INIT;
1702   if (TARGET_68020 || TARGET_COLDFIRE)
1703     return "move%.l %1,%R0\;smi %0\;extb%.l %0";
1704   else
1705     return "move%.l %1,%R0\;smi %0\;ext%.w %0\;ext%.l %0";
1706 })
1707
1708 (define_insn "*extendsidi2_mem"
1709   [(set (match_operand:DI 0 "memory_operand" "=o,<")
1710         (sign_extend:DI (match_operand:SI 1 "nonimmediate_src_operand" "rm,rm")))
1711    (clobber (match_scratch:SI 2 "=d,d"))]
1712    ""
1713 {
1714   CC_STATUS_INIT;
1715   operands[3] = adjust_address (operands[0], SImode,
1716                                 which_alternative == 0 ? 4 : 0);
1717   operands[0] = adjust_address (operands[0], SImode, 0);
1718   if (TARGET_68020 || TARGET_COLDFIRE)
1719     return "move%.l %1,%3\;smi %2\;extb%.l %2\;move%.l %2,%0";
1720   else
1721     return "move%.l %1,%3\;smi %2\;ext%.w %2\;ext%.l %2\;move%.l %2,%0";
1722 })
1723
1724 ;; Special case when one can avoid register clobbering, copy and test
1725 ;; Maybe there is a way to make that the general case, by forcing the
1726 ;; result of the SI tree to be in the lower register of the DI target
1727
1728 (define_insn "extendplussidi"
1729   [(set (match_operand:DI 0 "register_operand" "=d")
1730     (sign_extend:DI (plus:SI (match_operand:SI 1 "general_operand" "%rmn")
1731             (match_operand:SI 2 "general_operand" "rmn"))))]
1732   ""
1733 {
1734   CC_STATUS_INIT;
1735   operands[3] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1736   if (GET_CODE (operands[1]) == CONST_INT
1737   && (unsigned) INTVAL (operands[1]) > 8)
1738     {
1739       rtx tmp = operands[1];
1740
1741       operands[1] = operands[2];
1742       operands[2] = tmp;
1743     }
1744   if (GET_CODE (operands[1]) == REG
1745       && REGNO (operands[1]) == REGNO (operands[3]))
1746     output_asm_insn ("add%.l %2,%3", operands);
1747   else
1748     output_asm_insn ("move%.l %2,%3\;add%.l %1,%3", operands);
1749   if (TARGET_68020 || TARGET_COLDFIRE)
1750     return "smi %0\;extb%.l %0";
1751   else
1752     return "smi %0\;ext%.w %0\;ext%.l %0";
1753 })
1754
1755 (define_expand "extendhisi2"
1756   [(set (match_operand:SI 0 "nonimmediate_operand" "")
1757         (sign_extend:SI
1758          (match_operand:HI 1 "nonimmediate_src_operand" "")))]
1759   ""
1760   "")
1761
1762 (define_insn "*cfv4_extendhisi2"
1763   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
1764         (sign_extend:SI
1765          (match_operand:HI 1 "nonimmediate_src_operand" "rmS")))]
1766   "ISA_HAS_MVS_MVZ"
1767   "mvs%.w %1,%0"
1768   [(set_attr "type" "mvsz")])
1769
1770 (define_insn "*68k_extendhisi2"
1771   [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,a")
1772         (sign_extend:SI
1773          (match_operand:HI 1 "nonimmediate_src_operand" "0,rmS")))]
1774   "!ISA_HAS_MVS_MVZ"
1775   "@
1776    ext%.l %0
1777    move%.w %1,%0"
1778   [(set_attr "type" "ext,move")])
1779
1780 (define_insn "extendqihi2"
1781   [(set (match_operand:HI 0 "nonimmediate_operand" "=d")
1782         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0")))]
1783   ""
1784   "ext%.w %0"
1785   [(set_attr "type" "ext")])
1786
1787 (define_expand "extendqisi2"
1788   [(set (match_operand:SI 0 "nonimmediate_operand" "")
1789         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))]
1790   "TARGET_68020 || TARGET_COLDFIRE"
1791   "")
1792
1793 (define_insn "*cfv4_extendqisi2"
1794   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
1795         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "rms")))]
1796   "ISA_HAS_MVS_MVZ"
1797   "mvs%.b %1,%0"
1798   [(set_attr "type" "mvsz")])
1799
1800 (define_insn "*68k_extendqisi2"
1801   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
1802         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "0")))]
1803   "TARGET_68020 || (TARGET_COLDFIRE && !ISA_HAS_MVS_MVZ)"
1804   "extb%.l %0"
1805   [(set_attr "type" "ext")])
1806 \f
1807 ;; Conversions between float and double.
1808
1809 (define_expand "extendsfdf2"
1810   [(set (match_operand:DF 0 "nonimmediate_operand" "")
1811         (float_extend:DF
1812          (match_operand:SF 1 "general_operand" "")))]
1813   "TARGET_HARD_FLOAT"
1814   "")
1815
1816 (define_insn ""
1817   [(set (match_operand:DF 0 "nonimmediate_operand" "=*fdm,f")
1818         (float_extend:DF
1819           (match_operand:SF 1 "general_operand" "f,dmF")))]
1820   "TARGET_68881"
1821 {
1822   if (FP_REG_P (operands[0]) && FP_REG_P (operands[1]))
1823     {
1824       if (REGNO (operands[0]) == REGNO (operands[1]))
1825         {
1826           /* Extending float to double in an fp-reg is a no-op.
1827              NOTICE_UPDATE_CC has already assumed that the
1828              cc will be set.  So cancel what it did.  */
1829           cc_status = cc_prev_status;
1830           return "";
1831         }
1832       return "f%&move%.x %1,%0";
1833     }
1834   if (FP_REG_P (operands[0]))
1835     return "f%&move%.s %f1,%0";
1836   if (DATA_REG_P (operands[0]) && FP_REG_P (operands[1]))
1837     {
1838       output_asm_insn ("fmove%.d %f1,%-\;move%.l %+,%0", operands);
1839       operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1840       return "move%.l %+,%0";
1841     }
1842   return "fmove%.d %f1,%0";
1843 })
1844
1845 (define_insn "extendsfdf2_cf"
1846   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f")
1847         (float_extend:DF
1848          (match_operand:SF 1 "general_operand" "f,<Q>U")))]
1849   "TARGET_COLDFIRE_FPU"
1850 {
1851   if (FP_REG_P (operands[0]) && FP_REG_P (operands[1]))
1852     {
1853       if (REGNO (operands[0]) == REGNO (operands[1]))
1854         {
1855           /* Extending float to double in an fp-reg is a no-op.
1856              NOTICE_UPDATE_CC has already assumed that the
1857              cc will be set.  So cancel what it did.  */
1858           cc_status = cc_prev_status;
1859           return "";
1860         }
1861       return "fdmove%.d %1,%0";
1862     }
1863   return "fdmove%.s %f1,%0";
1864 })
1865
1866 ;; This cannot output into an f-reg because there is no way to be
1867 ;; sure of truncating in that case.
1868 (define_expand "truncdfsf2"
1869   [(set (match_operand:SF 0 "nonimmediate_operand" "")
1870         (float_truncate:SF
1871           (match_operand:DF 1 "general_operand" "")))]
1872   "TARGET_HARD_FLOAT"
1873   "")
1874
1875 ;; On the '040 we can truncate in a register accurately and easily.
1876 (define_insn ""
1877   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
1878         (float_truncate:SF
1879           (match_operand:DF 1 "general_operand" "fmG")))]
1880   "TARGET_68881 && TARGET_68040"
1881 {
1882   if (FP_REG_P (operands[1]))
1883     return "f%$move%.x %1,%0";
1884   return "f%$move%.d %f1,%0";
1885 })
1886
1887 (define_insn "truncdfsf2_cf"
1888   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,d<Q>U")
1889         (float_truncate:SF
1890           (match_operand:DF 1 "general_operand" "<Q>U,f")))]
1891   "TARGET_COLDFIRE_FPU"
1892   "@
1893   fsmove%.d %1,%0
1894   fmove%.s %1,%0"
1895   [(set_attr "type" "fmove")])
1896
1897 (define_insn "*truncdfsf2_68881"
1898   [(set (match_operand:SF 0 "nonimmediate_operand" "=dm")
1899         (float_truncate:SF
1900           (match_operand:DF 1 "general_operand" "f")))]
1901   "TARGET_68881"
1902   "fmove%.s %f1,%0"
1903   [(set_attr "type" "fmove")])
1904 \f
1905 ;; Conversion between fixed point and floating point.
1906 ;; Note that among the fix-to-float insns
1907 ;; the ones that start with SImode come first.
1908 ;; That is so that an operand that is a CONST_INT
1909 ;; (and therefore lacks a specific machine mode).
1910 ;; will be recognized as SImode (which is always valid)
1911 ;; rather than as QImode or HImode.
1912
1913 (define_expand "floatsi<mode>2"
1914   [(set (match_operand:FP 0 "nonimmediate_operand" "")
1915         (float:FP (match_operand:SI 1 "general_operand" "")))]
1916   "TARGET_HARD_FLOAT"
1917   "")
1918
1919 (define_insn "floatsi<mode>2_68881"
1920   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
1921         (float:FP (match_operand:SI 1 "general_operand" "dmi")))]
1922   "TARGET_68881"
1923   "f<FP:round>move%.l %1,%0"
1924   [(set_attr "type" "fmove")])
1925
1926 (define_insn "floatsi<mode>2_cf"
1927   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
1928         (float:FP (match_operand:SI 1 "general_operand" "d<Q>U")))]
1929   "TARGET_COLDFIRE_FPU"
1930   "f<FP:prec>move%.l %1,%0"
1931   [(set_attr "type" "fmove")])
1932
1933
1934 (define_expand "floathi<mode>2"
1935   [(set (match_operand:FP 0 "nonimmediate_operand" "")
1936         (float:FP (match_operand:HI 1 "general_operand" "")))]
1937   "TARGET_HARD_FLOAT"
1938   "")
1939
1940 (define_insn "floathi<mode>2_68881"
1941   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
1942         (float:FP (match_operand:HI 1 "general_operand" "dmn")))]
1943   "TARGET_68881"
1944   "fmove%.w %1,%0"
1945   [(set_attr "type" "fmove")])
1946
1947 (define_insn "floathi<mode>2_cf"
1948   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
1949         (float:FP (match_operand:HI 1 "general_operand" "d<Q>U")))]
1950   "TARGET_COLDFIRE_FPU"
1951   "fmove%.w %1,%0"
1952   [(set_attr "type" "fmove")])
1953
1954
1955 (define_expand "floatqi<mode>2"
1956   [(set (match_operand:FP 0 "nonimmediate_operand" "")
1957         (float:FP (match_operand:QI 1 "general_operand" "")))]
1958   "TARGET_HARD_FLOAT"
1959   "")
1960
1961 (define_insn "floatqi<mode>2_68881"
1962   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
1963         (float:FP (match_operand:QI 1 "general_operand" "dmn")))]
1964   "TARGET_68881"
1965   "fmove%.b %1,%0"
1966   [(set_attr "type" "fmove")])
1967
1968 (define_insn "floatqi<mode>2_cf"
1969   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
1970         (float:FP (match_operand:QI 1 "general_operand" "d<Q>U")))]
1971   "TARGET_COLDFIRE_FPU"
1972   "fmove%.b %1,%0"
1973   [(set_attr "type" "fmove")])
1974
1975
1976 ;; New routines to convert floating-point values to integers
1977 ;; to be used on the '040.  These should be faster than trapping
1978 ;; into the kernel to emulate fintrz.  They should also be faster
1979 ;; than calling the subroutines fixsfsi or fixdfsi.
1980
1981 (define_insn "fix_truncdfsi2"
1982   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
1983         (fix:SI (fix:DF (match_operand:DF 1 "register_operand" "f"))))
1984    (clobber (match_scratch:SI 2 "=d"))
1985    (clobber (match_scratch:SI 3 "=d"))]
1986   "TARGET_68881 && TUNE_68040"
1987 {
1988   CC_STATUS_INIT;
1989   return "fmovem%.l %!,%2\;moveq #16,%3\;or%.l %2,%3\;and%.w #-33,%3\;fmovem%.l %3,%!\;fmove%.l %1,%0\;fmovem%.l %2,%!";
1990 })
1991
1992 (define_insn "fix_truncdfhi2"
1993   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm")
1994         (fix:HI (fix:DF (match_operand:DF 1 "register_operand" "f"))))
1995    (clobber (match_scratch:SI 2 "=d"))
1996    (clobber (match_scratch:SI 3 "=d"))]
1997   "TARGET_68881 && TUNE_68040"
1998 {
1999   CC_STATUS_INIT;
2000   return "fmovem%.l %!,%2\;moveq #16,%3\;or%.l %2,%3\;and%.w #-33,%3\;fmovem%.l %3,%!\;fmove%.w %1,%0\;fmovem%.l %2,%!";
2001 })
2002
2003 (define_insn "fix_truncdfqi2"
2004   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
2005         (fix:QI (fix:DF (match_operand:DF 1 "register_operand" "f"))))
2006    (clobber (match_scratch:SI 2 "=d"))
2007    (clobber (match_scratch:SI 3 "=d"))]
2008   "TARGET_68881 && TUNE_68040"
2009 {
2010   CC_STATUS_INIT;
2011   return "fmovem%.l %!,%2\;moveq #16,%3\;or%.l %2,%3\;and%.w #-33,%3\;fmovem%.l %3,%!\;fmove%.b %1,%0\;fmovem%.l %2,%!";
2012 })
2013
2014 ;; Convert a float to a float whose value is an integer.
2015 ;; This is the first stage of converting it to an integer type.
2016
2017 (define_expand "ftrunc<mode>2"
2018   [(set (match_operand:FP 0 "nonimmediate_operand" "")
2019         (fix:FP (match_operand:FP 1 "general_operand" "")))]
2020   "TARGET_HARD_FLOAT && !TUNE_68040"
2021   "")
2022
2023 (define_insn "ftrunc<mode>2_68881"
2024   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2025         (fix:FP (match_operand:FP 1 "general_operand" "f<FP:dreg>m")))]
2026   "TARGET_68881 && !TUNE_68040"
2027 {
2028   if (FP_REG_P (operands[1]))
2029     return "fintrz%.x %f1,%0";
2030   return "fintrz%.<FP:prec> %f1,%0";
2031 }
2032   [(set_attr "type" "falu")])
2033
2034 (define_insn "ftrunc<mode>2_cf"
2035   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2036         (fix:FP (match_operand:FP 1 "general_operand" "f<FP:dreg><Q>U")))]
2037   "TARGET_COLDFIRE_FPU"
2038 {
2039   if (FP_REG_P (operands[1]))
2040     return "fintrz%.d %f1,%0";
2041   return "fintrz%.<FP:prec> %f1,%0";
2042 }
2043   [(set_attr "type" "falu")])
2044
2045 ;; Convert a float whose value is an integer
2046 ;; to an actual integer.  Second stage of converting float to integer type.
2047 (define_expand "fix<mode>qi2"
2048   [(set (match_operand:QI 0 "nonimmediate_operand" "")
2049         (fix:QI (match_operand:FP 1 "general_operand" "")))]
2050   "TARGET_HARD_FLOAT"
2051   "")
2052
2053 (define_insn "fix<mode>qi2_68881"
2054   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
2055         (fix:QI (match_operand:FP 1 "general_operand" "f")))]
2056   "TARGET_68881"
2057   "fmove%.b %1,%0"
2058   [(set_attr "type" "fmove")])
2059
2060 (define_insn "fix<mode>qi2_cf"
2061   [(set (match_operand:QI 0 "nonimmediate_operand" "=d<Q>U")
2062         (fix:QI (match_operand:FP 1 "general_operand" "f")))]
2063   "TARGET_COLDFIRE_FPU"
2064   "fmove%.b %1,%0"
2065   [(set_attr "type" "fmove")])
2066
2067 (define_expand "fix<mode>hi2"
2068   [(set (match_operand:HI 0 "nonimmediate_operand" "")
2069         (fix:HI (match_operand:FP 1 "general_operand" "")))]
2070   "TARGET_HARD_FLOAT"
2071   "")
2072
2073 (define_insn "fix<mode>hi2_68881"
2074   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm")
2075         (fix:HI (match_operand:FP 1 "general_operand" "f")))]
2076   "TARGET_68881"
2077   "fmove%.w %1,%0"
2078   [(set_attr "type" "fmove")])
2079
2080 (define_insn "fix<mode>hi2_cf"
2081   [(set (match_operand:HI 0 "nonimmediate_operand" "=d<Q>U")
2082         (fix:HI (match_operand:FP 1 "general_operand" "f")))]
2083   "TARGET_COLDFIRE_FPU"
2084   "fmove%.w %1,%0"
2085   [(set_attr "type" "fmove")])
2086
2087 (define_expand "fix<mode>si2"
2088   [(set (match_operand:SI 0 "nonimmediate_operand" "")
2089         (fix:SI (match_operand:FP 1 "general_operand" "")))]
2090   "TARGET_HARD_FLOAT"
2091   "")
2092
2093 (define_insn "fix<mode>si2_68881"
2094   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
2095         (fix:SI (match_operand:FP 1 "general_operand" "f")))]
2096   "TARGET_68881"
2097   "fmove%.l %1,%0"
2098   [(set_attr "type" "fmove")])
2099
2100 (define_insn "fix<mode>si2_cf"
2101   [(set (match_operand:SI 0 "nonimmediate_operand" "=d<Q>U")
2102         (fix:SI (match_operand:FP 1 "general_operand" "f")))]
2103   "TARGET_COLDFIRE_FPU"
2104   "fmove%.l %1,%0"
2105   [(set_attr "type" "fmove")])
2106
2107 \f
2108 ;; add instructions
2109
2110 (define_insn "adddi_lshrdi_63"
2111   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
2112     (plus:DI (lshiftrt:DI (match_operand:DI 1 "general_operand" "rm")
2113             (const_int 63))
2114         (match_dup 1)))
2115    (clobber (match_scratch:SI 2 "=d"))]
2116   ""
2117 {
2118   operands[3] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2119   if (REG_P (operands[1]) && REGNO (operands[1]) == REGNO (operands[0]))
2120     return
2121     "move%.l %1,%2\;add%.l %2,%2\;subx%.l %2,%2\;sub%.l %2,%3\;subx%.l %2,%0";
2122   if (GET_CODE (operands[1]) == REG)
2123     operands[4] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2124   else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC
2125         || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
2126     operands[4] = operands[1];
2127   else
2128     operands[4] = adjust_address (operands[1], SImode, 4);
2129   if (GET_CODE (operands[1]) == MEM
2130    && GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
2131     output_asm_insn ("move%.l %4,%3", operands);
2132   output_asm_insn ("move%.l %1,%0\;smi %2", operands);
2133   if (TARGET_68020 || TARGET_COLDFIRE)
2134     output_asm_insn ("extb%.l %2", operands);
2135   else
2136     output_asm_insn ("ext%.w %2\;ext%.l %2", operands);
2137   if (GET_CODE (operands[1]) != MEM
2138    || GET_CODE (XEXP (operands[1], 0)) != PRE_DEC)
2139     output_asm_insn ("move%.l %4,%3", operands);
2140   return "sub%.l %2,%3\;subx%.l %2,%0";
2141 })
2142
2143 (define_insn "adddi_sexthishl32"
2144   [(set (match_operand:DI 0 "nonimmediate_operand" "=o,a,*d,*d")
2145     (plus:DI (ashift:DI (sign_extend:DI
2146           (match_operand:HI 1 "general_operand" "rm,rm,rm,rm"))
2147             (const_int 32))
2148         (match_operand:DI 2 "general_operand" "0,0,0,0")))
2149    (clobber (match_scratch:SI 3 "=&d,X,a,?d"))]
2150   "!TARGET_COLDFIRE"
2151 {
2152   CC_STATUS_INIT;
2153   if (ADDRESS_REG_P (operands[0]))
2154     return "add%.w %1,%0";
2155   else if (ADDRESS_REG_P (operands[3]))
2156     return "move%.w %1,%3\;add%.l %3,%0";
2157   else
2158     return "move%.w %1,%3\;ext%.l %3\;add%.l %3,%0";
2159 })
2160
2161 (define_insn "*adddi_dilshr32"
2162   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,o")
2163         (plus:DI (lshiftrt:DI (match_operand:DI 1 "general_operand" "ro,d")
2164                               (const_int 32))
2165                  (match_operand:DI 2 "general_operand" "0,0")))]
2166   "!TARGET_COLDFIRE"
2167 {
2168   CC_STATUS_INIT;
2169   if (GET_CODE (operands[0]) == REG)
2170     operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
2171   else
2172     operands[2] = adjust_address (operands[0], SImode, 4);
2173   return "add%.l %1,%2\;negx%.l %0\;neg%.l %0";
2174 })
2175
2176 (define_insn "*adddi_dilshr32_cf"
2177   [(set (match_operand:DI 0 "register_operand" "=d")
2178         (plus:DI (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "ro")
2179                               (const_int 32))
2180                  (match_operand:DI 2 "register_operand" "0")))]
2181   "TARGET_COLDFIRE"
2182 {
2183   CC_STATUS_INIT;
2184   return "add%.l %1,%R0\;negx%.l %0\;neg%.l %0";
2185 })
2186
2187 (define_insn "adddi_dishl32"
2188   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o")
2189 ;;    (plus:DI (match_operand:DI 2 "general_operand" "%0")
2190 ;;      (ashift:DI (match_operand:DI 1 "general_operand" "ro")
2191 ;;            (const_int 32))))]
2192     (plus:DI (ashift:DI (match_operand:DI 1 "general_operand" "ro,d")
2193             (const_int 32))
2194         (match_operand:DI 2 "general_operand" "0,0")))]
2195   ""
2196 {
2197   CC_STATUS_INIT;
2198   if (GET_CODE (operands[1]) == REG)
2199     operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2200   else
2201     operands[1] = adjust_address (operands[1], SImode, 4);
2202   return "add%.l %1,%0";
2203 }
2204   [(set_attr "type" "alu_l")])
2205
2206 (define_insn "adddi3"
2207   [(set (match_operand:DI 0 "nonimmediate_operand" "=o<>,d,d,d")
2208         (plus:DI (match_operand:DI 1 "general_operand" "%0,0,0,0")
2209                  (match_operand:DI 2 "general_operand" "d,no>,d,a")))
2210    (clobber (match_scratch:SI 3 "=&d,&d,X,&d"))]
2211   ""
2212 {
2213   if (DATA_REG_P (operands[0]))
2214     {
2215       if (DATA_REG_P (operands[2]))
2216         return "add%.l %R2,%R0\;addx%.l %2,%0";
2217       else if (GET_CODE (operands[2]) == MEM
2218           && GET_CODE (XEXP (operands[2], 0)) == POST_INC)
2219         return "move%.l %2,%3\;add%.l %2,%R0\;addx%.l %3,%0";
2220       else
2221         {
2222           rtx high, low;
2223           rtx xoperands[2];
2224
2225           if (GET_CODE (operands[2]) == REG)
2226             {
2227               low = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
2228               high = operands[2];
2229             }
2230           else if (CONSTANT_P (operands[2]))
2231             split_double (operands[2], &high, &low);
2232           else
2233             {
2234               low = adjust_address (operands[2], SImode, 4);
2235               high = operands[2];
2236             }
2237
2238           operands[1] = low, operands[2] = high;
2239           xoperands[0] = operands[3];
2240           if (GET_CODE (operands[1]) == CONST_INT
2241               && INTVAL (operands[1]) >= -8 && INTVAL (operands[1]) < 0)
2242             xoperands[1] = GEN_INT (-INTVAL (operands[2]) - 1);
2243           else
2244             xoperands[1] = operands[2];
2245
2246           output_asm_insn (output_move_simode (xoperands), xoperands);
2247           if (GET_CODE (operands[1]) == CONST_INT)
2248             {
2249               if (INTVAL (operands[1]) > 0 && INTVAL (operands[1]) <= 8)
2250                 return "addq%.l %1,%R0\;addx%.l %3,%0";
2251               else if (INTVAL (operands[1]) >= -8 && INTVAL (operands[1]) < 0)
2252                 {
2253                   operands[1] = GEN_INT (-INTVAL (operands[1]));
2254                   return "subq%.l %1,%R0\;subx%.l %3,%0";
2255                 }
2256             }
2257           return "add%.l %1,%R0\;addx%.l %3,%0";
2258         }
2259     }
2260   else
2261     {
2262       gcc_assert (GET_CODE (operands[0]) == MEM);
2263       CC_STATUS_INIT;
2264       if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
2265         {
2266           operands[1] = gen_rtx_MEM (SImode,
2267                                      plus_constant (XEXP(operands[0], 0), -8));
2268           return "move%.l %0,%3\;add%.l %R2,%0\;addx%.l %2,%3\;move%.l %3,%1";
2269         }
2270       else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
2271         {
2272           operands[1] = XEXP(operands[0], 0);
2273           return "add%.l %R2,%0\;move%.l %0,%3\;addx%.l %2,%3\;move%.l %3,%1";
2274         }
2275       else
2276         {
2277           operands[1] = adjust_address (operands[0], SImode, 4);
2278           return "add%.l %R2,%1\;move%.l %0,%3\;addx%.l %2,%3\;move%.l %3,%0";
2279         }
2280     }
2281 })
2282
2283 (define_insn "addsi_lshrsi_31"
2284   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
2285     (plus:SI (lshiftrt:SI (match_operand:SI 1 "general_operand" "rm")
2286             (const_int 31))
2287         (match_dup 1)))]
2288   ""
2289 {
2290   operands[2] = operands[0];
2291   operands[3] = gen_label_rtx();
2292   if (GET_CODE (operands[0]) == MEM)
2293     {
2294       if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
2295         operands[0] = gen_rtx_MEM (SImode, XEXP (XEXP (operands[0], 0), 0));
2296       else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
2297         operands[2] = gen_rtx_MEM (SImode, XEXP (XEXP (operands[0], 0), 0));
2298     }
2299   output_asm_insn ("move%.l %1,%0", operands);
2300   output_asm_insn ("jpl %l3", operands);
2301   output_asm_insn ("addq%.l #1,%2", operands);
2302   (*targetm.asm_out.internal_label) (asm_out_file, "L",
2303                                 CODE_LABEL_NUMBER (operands[3]));
2304   return "";
2305 })
2306
2307 (define_expand "addsi3"
2308   [(set (match_operand:SI 0 "nonimmediate_operand" "")
2309         (plus:SI (match_operand:SI 1 "general_operand" "")
2310                  (match_operand:SI 2 "general_src_operand" "")))]
2311   ""
2312   "")
2313
2314 ;; Note that the middle two alternatives are near-duplicates
2315 ;; in order to handle insns generated by reload.
2316 ;; This is needed since they are not themselves reloaded,
2317 ;; so commutativity won't apply to them.
2318 (define_insn "*addsi3_internal"
2319   [(set (match_operand:SI 0 "nonimmediate_operand" "=m,?a,?a,d,a")
2320         (plus:SI (match_operand:SI 1 "general_operand" "%0,a,rJK,0,0")
2321                  (match_operand:SI 2 "general_src_operand" "dIKLT,rJK,a,mSrIKLT,mSrIKLs")))]
2322
2323
2324   "! TARGET_COLDFIRE"
2325   "* return output_addsi3 (operands);")
2326
2327 (define_insn_and_split "*addsi3_5200"
2328   [(set (match_operand:SI 0 "nonimmediate_operand"         "=mr,mr,m,r,  ?a,?a,?a,?a")
2329         (plus:SI (match_operand:SI 1 "general_operand"     "%0, 0, 0,0,   a, a, r, a")
2330                  (match_operand:SI 2 "general_src_operand" " I, L, d,mrKi,Cj,r, a, J")))]
2331   "TARGET_COLDFIRE"
2332 {
2333   switch (which_alternative)
2334     {
2335     case 0:
2336       return "addq%.l %2,%0";
2337
2338     case 1:
2339       operands[2] = GEN_INT (- INTVAL (operands[2]));
2340       return "subq%.l %2,%0";
2341
2342     case 2:
2343     case 3:
2344       return "add%.l %2,%0";
2345
2346     case 4:
2347       /* move%.l %2,%0\n\tadd%.l %1,%0 */
2348       return "#";
2349
2350     case 5:
2351       return MOTOROLA ? "lea (%1,%2.l),%0" : "lea %1@(0,%2:l),%0";
2352
2353     case 6:
2354       return MOTOROLA ? "lea (%2,%1.l),%0" : "lea %2@(0,%1:l),%0";
2355
2356     case 7:
2357       return MOTOROLA ? "lea (%c2,%1),%0" : "lea %1@(%c2),%0";
2358
2359     default:
2360       gcc_unreachable ();
2361       return "";
2362     }
2363 }
2364   "&& reload_completed && (extract_constrain_insn_cached (insn), which_alternative == 4) && !operands_match_p (operands[0], operands[1])"
2365   [(set (match_dup 0)
2366         (match_dup 2))
2367    (set (match_dup 0)
2368         (plus:SI (match_dup 0)
2369                  (match_dup 1)))]
2370   ""
2371   [(set_attr "type" "aluq_l,aluq_l,alu_l,alu_l,*,lea,lea,lea")
2372    (set_attr "opy" "2,2,2,2,*,*,*,*")
2373    (set_attr "opy_type" "*,*,*,*,*,mem6,mem6,mem5")])
2374
2375 (define_insn ""
2376   [(set (match_operand:SI 0 "nonimmediate_operand" "=a")
2377         (plus:SI (match_operand:SI 1 "general_operand" "0")
2378                  (sign_extend:SI
2379                   (match_operand:HI 2 "nonimmediate_src_operand" "rmS"))))]
2380   "!TARGET_COLDFIRE"
2381   "add%.w %2,%0")
2382
2383 (define_insn "addhi3"
2384   [(set (match_operand:HI 0 "nonimmediate_operand" "=m,r")
2385         (plus:HI (match_operand:HI 1 "general_operand" "%0,0")
2386                  (match_operand:HI 2 "general_src_operand" "dn,rmSn")))]
2387   "!TARGET_COLDFIRE"
2388 {
2389   if (GET_CODE (operands[2]) == CONST_INT)
2390     {
2391       /* If the constant would be a negative number when interpreted as
2392          HImode, make it negative.  This is usually, but not always, done
2393          elsewhere in the compiler.  First check for constants out of range,
2394          which could confuse us.  */
2395
2396       if (INTVAL (operands[2]) >= 32768)
2397         operands[2] = GEN_INT (INTVAL (operands[2]) - 65536);
2398
2399       if (INTVAL (operands[2]) > 0
2400           && INTVAL (operands[2]) <= 8)
2401         return "addq%.w %2,%0";
2402       if (INTVAL (operands[2]) < 0
2403           && INTVAL (operands[2]) >= -8)
2404         {
2405           operands[2] = GEN_INT (- INTVAL (operands[2]));
2406           return "subq%.w %2,%0";
2407         }
2408       /* On the CPU32 it is faster to use two addqw instructions to
2409          add a small integer (8 < N <= 16) to a register.  
2410          Likewise for subqw.  */
2411       if (TUNE_CPU32 && REG_P (operands[0]))
2412         {
2413           if (INTVAL (operands[2]) > 8
2414               && INTVAL (operands[2]) <= 16)
2415             {
2416               operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
2417               return "addq%.w #8,%0\;addq%.w %2,%0";
2418             }
2419           if (INTVAL (operands[2]) < -8
2420               && INTVAL (operands[2]) >= -16)
2421             {
2422               operands[2] = GEN_INT (- INTVAL (operands[2]) - 8);
2423               return "subq%.w #8,%0\;subq%.w %2,%0";
2424             }
2425         }
2426       if (ADDRESS_REG_P (operands[0]) && !TUNE_68040)
2427         return MOTOROLA ? "lea (%c2,%0),%0" : "lea %0@(%c2),%0";
2428     }
2429   return "add%.w %2,%0";
2430 })
2431
2432 ;; These insns must use MATCH_DUP instead of the more expected
2433 ;; use of a matching constraint because the "output" here is also
2434 ;; an input, so you can't use the matching constraint.  That also means
2435 ;; that you can't use the "%", so you need patterns with the matched
2436 ;; operand in both positions.
2437
2438 (define_insn ""
2439   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+m,d"))
2440         (plus:HI (match_dup 0)
2441                  (match_operand:HI 1 "general_src_operand" "dn,rmSn")))]
2442   "!TARGET_COLDFIRE"
2443 {
2444   if (GET_CODE (operands[1]) == CONST_INT)
2445     {
2446       /* If the constant would be a negative number when interpreted as
2447          HImode, make it negative.  This is usually, but not always, done
2448          elsewhere in the compiler.  First check for constants out of range,
2449          which could confuse us.  */
2450
2451       if (INTVAL (operands[1]) >= 32768)
2452         operands[1] = GEN_INT (INTVAL (operands[1]) - 65536);
2453
2454       if (INTVAL (operands[1]) > 0
2455           && INTVAL (operands[1]) <= 8)
2456         return "addq%.w %1,%0";
2457       if (INTVAL (operands[1]) < 0
2458           && INTVAL (operands[1]) >= -8)
2459         {
2460           operands[1] = GEN_INT (- INTVAL (operands[1]));
2461           return "subq%.w %1,%0";
2462         }
2463       /* On the CPU32 it is faster to use two addqw instructions to
2464          add a small integer (8 < N <= 16) to a register. 
2465          Likewise for subqw.  */
2466       if (TUNE_CPU32 && REG_P (operands[0]))
2467         {
2468           if (INTVAL (operands[1]) > 8
2469               && INTVAL (operands[1]) <= 16)
2470             {
2471               operands[1] = GEN_INT (INTVAL (operands[1]) - 8);
2472               return "addq%.w #8,%0\;addq%.w %1,%0";
2473             }
2474           if (INTVAL (operands[1]) < -8
2475               && INTVAL (operands[1]) >= -16)
2476             {
2477               operands[1] = GEN_INT (- INTVAL (operands[1]) - 8);
2478               return "subq%.w #8,%0\;subq%.w %1,%0";
2479             }
2480         }
2481       if (ADDRESS_REG_P (operands[0]) && !TUNE_68040)
2482         return MOTOROLA ? "lea (%c1,%0),%0" : "lea %0@(%c1),%0";
2483     }
2484   return "add%.w %1,%0";
2485 })
2486
2487 (define_insn ""
2488   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+m,d"))
2489         (plus:HI (match_operand:HI 1 "general_src_operand" "dn,rmSn")
2490                  (match_dup 0)))]
2491   "!TARGET_COLDFIRE"
2492 {
2493   if (GET_CODE (operands[1]) == CONST_INT)
2494     {
2495       /* If the constant would be a negative number when interpreted as
2496          HImode, make it negative.  This is usually, but not always, done
2497          elsewhere in the compiler.  First check for constants out of range,
2498          which could confuse us.  */
2499
2500       if (INTVAL (operands[1]) >= 32768)
2501         operands[1] = GEN_INT (INTVAL (operands[1]) - 65536);
2502
2503       if (INTVAL (operands[1]) > 0
2504           && INTVAL (operands[1]) <= 8)
2505         return "addq%.w %1,%0";
2506       if (INTVAL (operands[1]) < 0
2507           && INTVAL (operands[1]) >= -8)
2508         {
2509           operands[1] = GEN_INT (- INTVAL (operands[1]));
2510           return "subq%.w %1,%0";
2511         }
2512       /* On the CPU32 it is faster to use two addqw instructions to
2513          add a small integer (8 < N <= 16) to a register.
2514          Likewise for subqw.  */
2515       if (TUNE_CPU32 && REG_P (operands[0]))
2516         {
2517           if (INTVAL (operands[1]) > 8
2518               && INTVAL (operands[1]) <= 16)
2519             {
2520               operands[1] = GEN_INT (INTVAL (operands[1]) - 8);
2521               return "addq%.w #8,%0\;addq%.w %1,%0";
2522             }
2523           if (INTVAL (operands[1]) < -8
2524               && INTVAL (operands[1]) >= -16)
2525             {
2526               operands[1] = GEN_INT (- INTVAL (operands[1]) - 8);
2527               return "subq%.w #8,%0\;subq%.w %1,%0";
2528             }
2529         }
2530       if (ADDRESS_REG_P (operands[0]) && !TUNE_68040)
2531         return MOTOROLA ? "lea (%c1,%0),%0" : "lea %0@(%c1),%0";
2532     }
2533   return "add%.w %1,%0";
2534 })
2535
2536 (define_insn "addqi3"
2537   [(set (match_operand:QI 0 "nonimmediate_operand" "=m,d")
2538         (plus:QI (match_operand:QI 1 "general_operand" "%0,0")
2539                  (match_operand:QI 2 "general_src_operand" "dn,dmSn")))]
2540   "!TARGET_COLDFIRE"
2541 {
2542   if (GET_CODE (operands[2]) == CONST_INT)
2543     {
2544       if (INTVAL (operands[2]) >= 128)
2545         operands[2] = GEN_INT (INTVAL (operands[2]) - 256);
2546
2547       if (INTVAL (operands[2]) > 0
2548           && INTVAL (operands[2]) <= 8)
2549         return "addq%.b %2,%0";
2550       if (INTVAL (operands[2]) < 0 && INTVAL (operands[2]) >= -8)
2551        {
2552          operands[2] = GEN_INT (- INTVAL (operands[2]));
2553          return "subq%.b %2,%0";
2554        }
2555     }
2556   return "add%.b %2,%0";
2557 })
2558
2559 (define_insn ""
2560   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+m,d"))
2561         (plus:QI (match_dup 0)
2562                  (match_operand:QI 1 "general_src_operand" "dn,dmSn")))]
2563   "!TARGET_COLDFIRE"
2564 {
2565   if (GET_CODE (operands[1]) == CONST_INT)
2566     {
2567       if (INTVAL (operands[1]) >= 128)
2568         operands[1] = GEN_INT (INTVAL (operands[1]) - 256);
2569
2570       if (INTVAL (operands[1]) > 0
2571           && INTVAL (operands[1]) <= 8)
2572         return "addq%.b %1,%0";
2573       if (INTVAL (operands[1]) < 0 && INTVAL (operands[1]) >= -8)
2574        {
2575          operands[1] = GEN_INT (- INTVAL (operands[1]));
2576          return "subq%.b %1,%0";
2577        }
2578     }
2579   return "add%.b %1,%0";
2580 })
2581
2582 (define_insn ""
2583   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+m,d"))
2584         (plus:QI (match_operand:QI 1 "general_src_operand" "dn,dmSn")
2585                  (match_dup 0)))]
2586   "!TARGET_COLDFIRE"
2587 {
2588   if (GET_CODE (operands[1]) == CONST_INT)
2589     {
2590       if (INTVAL (operands[1]) >= 128)
2591         operands[1] = GEN_INT (INTVAL (operands[1]) - 256);
2592
2593       if (INTVAL (operands[1]) > 0
2594           && INTVAL (operands[1]) <= 8)
2595         return "addq%.b %1,%0";
2596       if (INTVAL (operands[1]) < 0 && INTVAL (operands[1]) >= -8)
2597        {
2598          operands[1] = GEN_INT (- INTVAL (operands[1]));
2599          return "subq%.b %1,%0";
2600        }
2601     }
2602   return "add%.b %1,%0";
2603 })
2604
2605 (define_expand "add<mode>3"
2606   [(set (match_operand:FP 0 "nonimmediate_operand" "")
2607         (plus:FP (match_operand:FP 1 "general_operand" "")
2608                  (match_operand:FP 2 "general_operand" "")))]
2609   "TARGET_HARD_FLOAT"
2610   "")
2611
2612 (define_insn "add<mode>3_floatsi_68881"
2613   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2614         (plus:FP (float:FP (match_operand:SI 2 "general_operand" "dmi"))
2615                  (match_operand:FP 1 "general_operand" "0")))]
2616   "TARGET_68881"
2617   "f<FP:round>add%.l %2,%0"
2618   [(set_attr "type" "falu")
2619    (set_attr "opy" "2")])
2620
2621 (define_insn "add<mode>3_floathi_68881"
2622   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2623         (plus:FP (float:FP (match_operand:HI 2 "general_operand" "dmn"))
2624                  (match_operand:FP 1 "general_operand" "0")))]
2625   "TARGET_68881"
2626   "f<FP:round>add%.w %2,%0"
2627   [(set_attr "type" "falu")
2628    (set_attr "opy" "2")])
2629
2630 (define_insn "add<mode>3_floatqi_68881"
2631   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2632         (plus:FP (float:FP (match_operand:QI 2 "general_operand" "dmn"))
2633                  (match_operand:FP 1 "general_operand" "0")))]
2634   "TARGET_68881"
2635   "f<FP:round>add%.b %2,%0"
2636   [(set_attr "type" "falu")
2637    (set_attr "opy" "2")])
2638
2639 (define_insn "add<mode>3_68881"
2640   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2641         (plus:FP (match_operand:FP 1 "general_operand" "%0")
2642                  (match_operand:FP 2 "general_operand" "f<FP:dreg>m<FP:const>")))]
2643   "TARGET_68881"
2644 {
2645   if (FP_REG_P (operands[2]))
2646     return "f<FP:round>add%.x %2,%0";
2647   return "f<FP:round>add%.<FP:prec> %f2,%0";
2648 }
2649   [(set_attr "type" "falu")
2650    (set_attr "opy" "2")])
2651
2652 (define_insn "add<mode>3_cf"
2653   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2654         (plus:FP (match_operand:FP 1 "general_operand" "%0")
2655                  (match_operand:FP 2 "general_operand" "f<FP:dreg><Q>U")))]
2656   "TARGET_COLDFIRE_FPU"
2657 {
2658   if (FP_REG_P (operands[2]))
2659     return "f<FP:prec>add%.d %2,%0";
2660   return "f<FP:prec>add%.<FP:prec> %2,%0";
2661 }
2662   [(set_attr "type" "falu")
2663    (set_attr "opy" "2")])
2664 \f
2665 ;; subtract instructions
2666
2667 (define_insn "subdi_sexthishl32"
2668   [(set (match_operand:DI 0 "nonimmediate_operand" "=o,a,*d,*d")
2669     (minus:DI (match_operand:DI 1 "general_operand" "0,0,0,0")
2670         (ashift:DI (sign_extend:DI (match_operand:HI 2 "general_operand" "rm,rm,rm,rm"))
2671             (const_int 32))))
2672    (clobber (match_scratch:SI 3 "=&d,X,a,?d"))]
2673   "!TARGET_COLDFIRE"
2674 {
2675   CC_STATUS_INIT;
2676   if (ADDRESS_REG_P (operands[0]))
2677     return "sub%.w %2,%0";
2678   else if (ADDRESS_REG_P (operands[3]))
2679     return "move%.w %2,%3\;sub%.l %3,%0";
2680   else
2681     return "move%.w %2,%3\;ext%.l %3\;sub%.l %3,%0";
2682 })
2683
2684 (define_insn "subdi_dishl32"
2685   [(set (match_operand:DI 0 "nonimmediate_operand" "+ro")
2686     (minus:DI (match_dup 0)
2687         (ashift:DI (match_operand:DI 1 "general_operand" "ro")
2688             (const_int 32))))]
2689   ""
2690 {
2691   CC_STATUS_INIT;
2692   if (GET_CODE (operands[1]) == REG)
2693     operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2694   else
2695     operands[1] = adjust_address (operands[1], SImode, 4);
2696   return "sub%.l %1,%0";
2697 }
2698   [(set_attr "type" "alu_l")])
2699
2700 (define_insn "subdi3"
2701   [(set (match_operand:DI 0 "nonimmediate_operand" "=o<>,d,d,d")
2702         (minus:DI (match_operand:DI 1 "general_operand" "0,0,0,0")
2703                  (match_operand:DI 2 "general_operand" "d,no>,d,a")))
2704    (clobber (match_scratch:SI 3 "=&d,&d,X,&d"))]
2705   ""
2706 {
2707   if (DATA_REG_P (operands[0]))
2708     {
2709       if (DATA_REG_P (operands[2]))
2710         return "sub%.l %R2,%R0\;subx%.l %2,%0";
2711       else if (GET_CODE (operands[2]) == MEM
2712           && GET_CODE (XEXP (operands[2], 0)) == POST_INC)
2713         {
2714           return "move%.l %2,%3\;sub%.l %2,%R0\;subx%.l %3,%0";
2715         }
2716       else
2717         {
2718           rtx high, low;
2719           rtx xoperands[2];
2720
2721           if (GET_CODE (operands[2]) == REG)
2722             {
2723               low = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
2724               high = operands[2];
2725             }
2726           else if (CONSTANT_P (operands[2]))
2727             split_double (operands[2], &high, &low);
2728           else
2729             {
2730               low = adjust_address (operands[2], SImode, 4);
2731               high = operands[2];
2732             }
2733
2734           operands[1] = low, operands[2] = high;
2735           xoperands[0] = operands[3];
2736           if (GET_CODE (operands[1]) == CONST_INT
2737               && INTVAL (operands[1]) >= -8 && INTVAL (operands[1]) < 0)
2738             xoperands[1] = GEN_INT (-INTVAL (operands[2]) - 1);
2739           else
2740             xoperands[1] = operands[2];
2741
2742           output_asm_insn (output_move_simode (xoperands), xoperands);
2743           if (GET_CODE (operands[1]) == CONST_INT)
2744             {
2745               if (INTVAL (operands[1]) > 0 && INTVAL (operands[1]) <= 8)
2746                 return "subq%.l %1,%R0\;subx%.l %3,%0";
2747               else if (INTVAL (operands[1]) >= -8 && INTVAL (operands[1]) < 0)
2748                 {
2749                   operands[1] = GEN_INT (-INTVAL (operands[1]));
2750                   return "addq%.l %1,%R0\;addx%.l %3,%0";
2751                 }
2752             }
2753           return "sub%.l %1,%R0\;subx%.l %3,%0";
2754         }
2755     }
2756   else
2757     {
2758       gcc_assert (GET_CODE (operands[0]) == MEM);
2759       CC_STATUS_INIT;
2760       if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
2761         {
2762           operands[1]
2763             = gen_rtx_MEM (SImode, plus_constant (XEXP (operands[0], 0), -8));
2764           return "move%.l %0,%3\;sub%.l %R2,%0\;subx%.l %2,%3\;move%.l %3,%1";
2765         }
2766       else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
2767         {
2768           operands[1] = XEXP(operands[0], 0);
2769           return "sub%.l %R2,%0\;move%.l %0,%3\;subx%.l %2,%3\;move%.l %3,%1";
2770         }
2771       else
2772         {
2773           operands[1] = adjust_address (operands[0], SImode, 4);
2774           return "sub%.l %R2,%1\;move%.l %0,%3\;subx%.l %2,%3\;move%.l %3,%0";
2775         }
2776     }
2777 })
2778
2779 (define_insn "subsi3"
2780   [(set (match_operand:SI 0 "nonimmediate_operand" "=mda,m,d,a")
2781         (minus:SI (match_operand:SI 1 "general_operand" "0,0,0,0")
2782                   (match_operand:SI 2 "general_src_operand" "I,dT,mSrT,mSrs")))]
2783   ""
2784   "@
2785    subq%.l %2, %0
2786    sub%.l %2,%0
2787    sub%.l %2,%0
2788    sub%.l %2,%0"
2789   [(set_attr "type" "aluq_l,alu_l,alu_l,alu_l")
2790    (set_attr "opy" "2")])
2791
2792 (define_insn ""
2793   [(set (match_operand:SI 0 "nonimmediate_operand" "=a")
2794         (minus:SI (match_operand:SI 1 "general_operand" "0")
2795                   (sign_extend:SI
2796                    (match_operand:HI 2 "nonimmediate_src_operand" "rmS"))))]
2797   "!TARGET_COLDFIRE"
2798   "sub%.w %2,%0")
2799
2800 (define_insn "subhi3"
2801   [(set (match_operand:HI 0 "nonimmediate_operand" "=m,r")
2802         (minus:HI (match_operand:HI 1 "general_operand" "0,0")
2803                   (match_operand:HI 2 "general_src_operand" "dn,rmSn")))]
2804   "!TARGET_COLDFIRE"
2805   "sub%.w %2,%0")
2806
2807 (define_insn ""
2808   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+m,d"))
2809         (minus:HI (match_dup 0)
2810                   (match_operand:HI 1 "general_src_operand" "dn,rmSn")))]
2811   "!TARGET_COLDFIRE"
2812   "sub%.w %1,%0")
2813
2814 (define_insn "subqi3"
2815   [(set (match_operand:QI 0 "nonimmediate_operand" "=m,d")
2816         (minus:QI (match_operand:QI 1 "general_operand" "0,0")
2817                   (match_operand:QI 2 "general_src_operand" "dn,dmSn")))]
2818   "!TARGET_COLDFIRE"
2819   "sub%.b %2,%0")
2820
2821 (define_insn ""
2822   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+m,d"))
2823         (minus:QI (match_dup 0)
2824                   (match_operand:QI 1 "general_src_operand" "dn,dmSn")))]
2825   "!TARGET_COLDFIRE"
2826   "sub%.b %1,%0")
2827
2828 (define_expand "sub<mode>3"
2829   [(set (match_operand:FP 0 "nonimmediate_operand" "")
2830         (minus:FP (match_operand:FP 1 "general_operand" "")
2831                   (match_operand:FP 2 "general_operand" "")))]
2832   "TARGET_HARD_FLOAT"
2833   "")
2834
2835 (define_insn "sub<mode>3_floatsi_68881"
2836   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2837         (minus:FP (match_operand:FP 1 "general_operand" "0")
2838                   (float:FP (match_operand:SI 2 "general_operand" "dmi"))))]
2839   "TARGET_68881"
2840   "f<FP:round>sub%.l %2,%0"
2841   [(set_attr "type" "falu")
2842    (set_attr "opy" "2")])
2843
2844 (define_insn "sub<mode>3_floathi_68881"
2845   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2846         (minus:FP (match_operand:FP 1 "general_operand" "0")
2847                   (float:FP (match_operand:HI 2 "general_operand" "dmn"))))]
2848   "TARGET_68881"
2849   "f<FP:round>sub%.w %2,%0"
2850   [(set_attr "type" "falu")
2851    (set_attr "opy" "2")])
2852
2853 (define_insn "sub<mode>3_floatqi_68881"
2854   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2855         (minus:FP (match_operand:FP 1 "general_operand" "0")
2856                   (float:FP (match_operand:QI 2 "general_operand" "dmn"))))]
2857   "TARGET_68881"
2858   "f<FP:round>sub%.b %2,%0"
2859   [(set_attr "type" "falu")
2860    (set_attr "opy" "2")])
2861
2862 (define_insn "sub<mode>3_68881"
2863   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2864         (minus:FP (match_operand:FP 1 "general_operand" "0")
2865                   (match_operand:FP 2 "general_operand" "f<FP:dreg>m<FP:const>")))]
2866   "TARGET_68881"
2867 {
2868   if (FP_REG_P (operands[2]))
2869     return "f<FP:round>sub%.x %2,%0";
2870   return "f<FP:round>sub%.<FP:prec> %f2,%0";
2871 }
2872   [(set_attr "type" "falu")
2873    (set_attr "opy" "2")])
2874
2875 (define_insn "sub<mode>3_cf"
2876   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
2877         (minus:FP (match_operand:FP 1 "general_operand" "0")
2878                   (match_operand:FP 2 "general_operand" "f<FP:dreg><Q>U")))]
2879   "TARGET_COLDFIRE_FPU"
2880 {
2881   if (FP_REG_P (operands[2]))
2882     return "f<FP:prec>sub%.d %2,%0";
2883   return "f<FP:prec>sub%.<FP:prec> %2,%0";
2884 }
2885   [(set_attr "type" "falu")
2886    (set_attr "opy" "2")])
2887 \f
2888 ;; multiply instructions
2889
2890 (define_insn "mulhi3"
2891   [(set (match_operand:HI 0 "nonimmediate_operand" "=d")
2892         (mult:HI (match_operand:HI 1 "general_operand" "%0")
2893                  (match_operand:HI 2 "general_src_operand" "dmSn")))]
2894   ""
2895 {
2896   return MOTOROLA ? "muls%.w %2,%0" : "muls %2,%0";
2897 }
2898   [(set_attr "type" "mul_w")
2899    (set_attr "opy" "2")])
2900
2901 (define_insn "mulhisi3"
2902   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
2903         (mult:SI (sign_extend:SI
2904                   (match_operand:HI 1 "nonimmediate_operand" "%0"))
2905                  (sign_extend:SI
2906                   (match_operand:HI 2 "nonimmediate_src_operand" "dmS"))))]
2907   ""
2908 {
2909   return MOTOROLA ? "muls%.w %2,%0" : "muls %2,%0";
2910 }
2911   [(set_attr "type" "mul_w")
2912    (set_attr "opy" "2")])
2913
2914 (define_insn "*mulhisisi3_s"
2915   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
2916         (mult:SI (sign_extend:SI
2917                   (match_operand:HI 1 "nonimmediate_operand" "%0"))
2918                  (match_operand:SI 2 "const_int_operand" "n")))]
2919   "INTVAL (operands[2]) >= -0x8000 && INTVAL (operands[2]) <= 0x7fff"
2920 {
2921   return MOTOROLA ? "muls%.w %2,%0" : "muls %2,%0";
2922 }
2923   [(set_attr "type" "mul_w")
2924    (set_attr "opy" "2")])
2925
2926 (define_expand "mulsi3"
2927   [(set (match_operand:SI 0 "nonimmediate_operand" "")
2928         (mult:SI (match_operand:SI 1 "general_operand" "")
2929                  (match_operand:SI 2 "general_operand" "")))]
2930   "TARGET_68020 || TARGET_COLDFIRE"
2931   "")
2932
2933 (define_insn "*mulsi3_68020"
2934   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
2935         (mult:SI (match_operand:SI 1 "general_operand" "%0")
2936                  (match_operand:SI 2 "general_src_operand" "dmSTK")))]
2937
2938   "TARGET_68020"
2939   "muls%.l %2,%0"
2940   [(set_attr "type" "mul_l")
2941    (set_attr "opy" "2")])
2942
2943 (define_insn "*mulsi3_cf"
2944   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
2945         (mult:SI (match_operand:SI 1 "general_operand" "%0")
2946                  (match_operand:SI 2 "general_operand" "d<Q>")))]
2947   "TARGET_COLDFIRE"
2948   "muls%.l %2,%0"
2949   [(set_attr "type" "mul_l")
2950    (set_attr "opy" "2")])
2951
2952 (define_insn "umulhisi3"
2953   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
2954         (mult:SI (zero_extend:SI
2955                   (match_operand:HI 1 "nonimmediate_operand" "%0"))
2956                  (zero_extend:SI
2957                   (match_operand:HI 2 "nonimmediate_src_operand" "dmS"))))]
2958   ""
2959 {
2960   return MOTOROLA ? "mulu%.w %2,%0" : "mulu %2,%0";
2961 }
2962   [(set_attr "type" "mul_w")
2963    (set_attr "opy" "2")])
2964
2965 (define_insn "*mulhisisi3_z"
2966   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
2967         (mult:SI (zero_extend:SI
2968                   (match_operand:HI 1 "nonimmediate_operand" "%0"))
2969                  (match_operand:SI 2 "const_int_operand" "n")))]
2970   "INTVAL (operands[2]) >= 0 && INTVAL (operands[2]) <= 0xffff"
2971 {
2972   return MOTOROLA ? "mulu%.w %2,%0" : "mulu %2,%0";
2973 }
2974   [(set_attr "type" "mul_w")
2975    (set_attr "opy" "2")])
2976
2977 ;; We need a separate DEFINE_EXPAND for u?mulsidi3 to be able to use the
2978 ;; proper matching constraint.  This is because the matching is between
2979 ;; the high-numbered word of the DImode operand[0] and operand[1].
2980 (define_expand "umulsidi3"
2981   [(parallel
2982     [(set (subreg:SI (match_operand:DI 0 "register_operand" "") 4)
2983           (mult:SI (match_operand:SI 1 "register_operand" "")
2984                    (match_operand:SI 2 "register_operand" "")))
2985      (set (subreg:SI (match_dup 0) 0)
2986           (truncate:SI (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
2987                                              (zero_extend:DI (match_dup 2)))
2988                                     (const_int 32))))])]
2989   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
2990   "")
2991
2992 (define_insn ""
2993   [(set (match_operand:SI 0 "register_operand" "=d")
2994         (mult:SI (match_operand:SI 1 "register_operand" "%0")
2995                   (match_operand:SI 2 "nonimmediate_operand" "dm")))
2996    (set (match_operand:SI 3 "register_operand" "=d")
2997         (truncate:SI (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
2998                                            (zero_extend:DI (match_dup 2)))
2999                                   (const_int 32))))]
3000   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
3001   "mulu%.l %2,%3:%0")
3002
3003 ; Match immediate case.  For 2.4 only match things < 2^31.
3004 ; It's tricky with larger values in these patterns since we need to match
3005 ; values between the two parallel multiplies, between a CONST_DOUBLE and
3006 ; a CONST_INT.
3007 (define_insn ""
3008   [(set (match_operand:SI 0 "register_operand" "=d")
3009         (mult:SI (match_operand:SI 1 "register_operand" "%0")
3010                  (match_operand:SI 2 "const_int_operand" "n")))
3011    (set (match_operand:SI 3 "register_operand" "=d")
3012         (truncate:SI (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
3013                                            (match_dup 2))
3014                                   (const_int 32))))]
3015   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE
3016    && (unsigned) INTVAL (operands[2]) <= 0x7fffffff"
3017   "mulu%.l %2,%3:%0")
3018
3019 (define_expand "mulsidi3"
3020   [(parallel
3021     [(set (subreg:SI (match_operand:DI 0 "register_operand" "") 4)
3022           (mult:SI (match_operand:SI 1 "register_operand" "")
3023                    (match_operand:SI 2 "register_operand" "")))
3024      (set (subreg:SI (match_dup 0) 0)
3025           (truncate:SI (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
3026                                              (sign_extend:DI (match_dup 2)))
3027                                     (const_int 32))))])]
3028   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
3029   "")
3030
3031 (define_insn ""
3032   [(set (match_operand:SI 0 "register_operand" "=d")
3033         (mult:SI (match_operand:SI 1 "register_operand" "%0")
3034                  (match_operand:SI 2 "nonimmediate_operand" "dm")))
3035    (set (match_operand:SI 3 "register_operand" "=d")
3036         (truncate:SI (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
3037                                            (sign_extend:DI (match_dup 2)))
3038                                   (const_int 32))))]
3039   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
3040   "muls%.l %2,%3:%0")
3041
3042 (define_insn ""
3043   [(set (match_operand:SI 0 "register_operand" "=d")
3044         (mult:SI (match_operand:SI 1 "register_operand" "%0")
3045                  (match_operand:SI 2 "const_int_operand" "n")))
3046    (set (match_operand:SI 3 "register_operand" "=d")
3047         (truncate:SI (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
3048                                            (match_dup 2))
3049                                   (const_int 32))))]
3050   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
3051   "muls%.l %2,%3:%0")
3052
3053 (define_expand "umulsi3_highpart"
3054   [(parallel
3055     [(set (match_operand:SI 0 "register_operand" "")
3056           (truncate:SI
3057            (lshiftrt:DI
3058             (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" ""))
3059                      (zero_extend:DI (match_operand:SI 2 "general_operand" "")))
3060             (const_int 32))))
3061      (clobber (match_dup 3))])]
3062   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
3063 {
3064   operands[3] = gen_reg_rtx (SImode);
3065
3066   if (GET_CODE (operands[2]) == CONST_INT)
3067     {
3068       operands[2] = immed_double_const (INTVAL (operands[2]) & 0xffffffff,
3069                                         0, DImode);
3070
3071       /* We have to adjust the operand order for the matching constraints.  */
3072       emit_insn (gen_const_umulsi3_highpart (operands[0], operands[3],
3073                                              operands[1], operands[2]));
3074       DONE;
3075     }
3076 })
3077
3078 (define_insn ""
3079   [(set (match_operand:SI 0 "register_operand" "=d")
3080         (truncate:SI
3081          (lshiftrt:DI
3082           (mult:DI (zero_extend:DI (match_operand:SI 2 "register_operand" "%1"))
3083                    (zero_extend:DI (match_operand:SI 3 "nonimmediate_operand" "dm")))
3084           (const_int 32))))
3085    (clobber (match_operand:SI 1 "register_operand" "=d"))]
3086   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
3087   "mulu%.l %3,%0:%1")
3088
3089 (define_insn "const_umulsi3_highpart"
3090   [(set (match_operand:SI 0 "register_operand" "=d")
3091         (truncate:SI
3092          (lshiftrt:DI
3093           (mult:DI (zero_extend:DI (match_operand:SI 2 "register_operand" "1"))
3094                    (match_operand:DI 3 "const_uint32_operand" "n"))
3095           (const_int 32))))
3096    (clobber (match_operand:SI 1 "register_operand" "=d"))]
3097   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
3098   "mulu%.l %3,%0:%1")
3099
3100 (define_expand "smulsi3_highpart"
3101   [(parallel
3102     [(set (match_operand:SI 0 "register_operand" "")
3103           (truncate:SI
3104            (lshiftrt:DI
3105             (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" ""))
3106                      (sign_extend:DI (match_operand:SI 2 "general_operand" "")))
3107             (const_int 32))))
3108      (clobber (match_dup 3))])]
3109   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
3110 {
3111   operands[3] = gen_reg_rtx (SImode);
3112   if (GET_CODE (operands[2]) == CONST_INT)
3113     {
3114       /* We have to adjust the operand order for the matching constraints.  */
3115       emit_insn (gen_const_smulsi3_highpart (operands[0], operands[3],
3116                                              operands[1], operands[2]));
3117       DONE;
3118     }
3119 })
3120
3121 (define_insn ""
3122   [(set (match_operand:SI 0 "register_operand" "=d")
3123         (truncate:SI
3124          (lshiftrt:DI
3125           (mult:DI (sign_extend:DI (match_operand:SI 2 "register_operand" "%1"))
3126                    (sign_extend:DI (match_operand:SI 3 "nonimmediate_operand" "dm")))
3127           (const_int 32))))
3128    (clobber (match_operand:SI 1 "register_operand" "=d"))]
3129   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
3130   "muls%.l %3,%0:%1")
3131
3132 (define_insn "const_smulsi3_highpart"
3133   [(set (match_operand:SI 0 "register_operand" "=d")
3134         (truncate:SI
3135          (lshiftrt:DI
3136           (mult:DI (sign_extend:DI (match_operand:SI 2 "register_operand" "1"))
3137                    (match_operand:DI 3 "const_sint32_operand" "n"))
3138           (const_int 32))))
3139    (clobber (match_operand:SI 1 "register_operand" "=d"))]
3140   "TARGET_68020 && !TUNE_68060 && !TARGET_COLDFIRE"
3141   "muls%.l %3,%0:%1")
3142
3143 (define_expand "mul<mode>3"
3144   [(set (match_operand:FP 0 "nonimmediate_operand" "")
3145         (mult:FP (match_operand:FP 1 "general_operand" "")
3146                  (match_operand:FP 2 "general_operand" "")))]
3147   "TARGET_HARD_FLOAT"
3148   "")
3149
3150 (define_insn "mul<mode>3_floatsi_68881"
3151   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
3152         (mult:FP (float:FP (match_operand:SI 2 "general_operand" "dmi"))
3153                  (match_operand:FP 1 "general_operand" "0")))]
3154   "TARGET_68881"
3155 {
3156   return TARGET_68040
3157          ? "f<FP:round>mul%.l %2,%0"
3158          : "f<FP:round_mul>mul%.l %2,%0";
3159 }
3160   [(set_attr "type" "fmul")
3161    (set_attr "opy" "2")])
3162
3163 (define_insn "mul<mode>3_floathi_68881"
3164   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
3165         (mult:FP (float:FP (match_operand:HI 2 "general_operand" "dmn"))
3166                  (match_operand:FP 1 "general_operand" "0")))]
3167   "TARGET_68881"
3168 {
3169   return TARGET_68040
3170          ? "f<FP:round>mul%.w %2,%0"
3171          : "f<FP:round_mul>mul%.w %2,%0";
3172 }
3173   [(set_attr "type" "fmul")
3174    (set_attr "opy" "2")])
3175
3176 (define_insn "mul<mode>3_floatqi_68881"
3177   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
3178         (mult:FP (float:FP (match_operand:QI 2 "general_operand" "dmn"))
3179                  (match_operand:FP 1 "general_operand" "0")))]
3180   "TARGET_68881"
3181 {
3182   return TARGET_68040
3183          ? "f<FP:round>mul%.b %2,%0"
3184          : "f<FP:round_mul>mul%.b %2,%0";
3185 }
3186   [(set_attr "type" "fmul")
3187    (set_attr "opy" "2")])
3188
3189 (define_insn "muldf_68881"
3190   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
3191         (mult:DF (match_operand:DF 1 "general_operand" "%0")
3192                  (match_operand:DF 2 "general_operand" "fmG")))]
3193   "TARGET_68881"
3194 {
3195   if (GET_CODE (operands[2]) == CONST_DOUBLE
3196       && floating_exact_log2 (operands[2]) && !TUNE_68040_60)
3197     {
3198       int i = floating_exact_log2 (operands[2]);
3199       operands[2] = GEN_INT (i);
3200       return "fscale%.l %2,%0";
3201     }
3202   if (REG_P (operands[2]))
3203     return "f%&mul%.x %2,%0";
3204   return "f%&mul%.d %f2,%0";
3205 })
3206
3207 (define_insn "mulsf_68881"
3208   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
3209         (mult:SF (match_operand:SF 1 "general_operand" "%0")
3210                  (match_operand:SF 2 "general_operand" "fdmF")))]
3211   "TARGET_68881"
3212 {
3213   if (FP_REG_P (operands[2]))
3214     return (TARGET_68040
3215             ? "fsmul%.x %2,%0"
3216             : "fsglmul%.x %2,%0");
3217   return (TARGET_68040
3218           ? "fsmul%.s %f2,%0"
3219           : "fsglmul%.s %f2,%0");
3220 })
3221
3222 (define_insn "mulxf3_68881"
3223   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
3224         (mult:XF (match_operand:XF 1 "nonimmediate_operand" "%0")
3225                  (match_operand:XF 2 "nonimmediate_operand" "fm")))]
3226   "TARGET_68881"
3227 {
3228   return "fmul%.x %f2,%0";
3229 })
3230
3231 (define_insn "fmul<mode>3_cf"
3232   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
3233         (mult:FP (match_operand:FP 1 "general_operand" "%0")
3234                  (match_operand:FP 2 "general_operand" "f<Q>U<FP:dreg>")))]
3235   "TARGET_COLDFIRE_FPU"
3236 {
3237   if (FP_REG_P (operands[2]))
3238     return "f<FP:prec>mul%.d %2,%0";
3239   return "f<FP:prec>mul%.<FP:prec> %2,%0";
3240 }
3241   [(set_attr "type" "fmul")
3242    (set_attr "opy" "2")])
3243 \f
3244 ;; divide instructions
3245
3246 (define_expand "div<mode>3"
3247   [(set (match_operand:FP 0 "nonimmediate_operand" "")
3248         (div:FP (match_operand:FP 1 "general_operand" "")
3249                 (match_operand:FP 2 "general_operand" "")))]
3250   "TARGET_HARD_FLOAT"
3251   "")
3252
3253 (define_insn "div<mode>3_floatsi_68881"
3254   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
3255         (div:FP (match_operand:FP 1 "general_operand" "0")
3256                 (float:FP (match_operand:SI 2 "general_operand" "dmi"))))]
3257   "TARGET_68881"
3258 {
3259   return TARGET_68040
3260          ? "f<FP:round>div%.l %2,%0"
3261          : "f<FP:round_mul>div%.l %2,%0";
3262 })
3263
3264 (define_insn "div<mode>3_floathi_68881"
3265   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
3266         (div:FP (match_operand:FP 1 "general_operand" "0")
3267                 (float:FP (match_operand:HI 2 "general_operand" "dmn"))))]
3268   "TARGET_68881"
3269 {
3270   return TARGET_68040
3271          ? "f<FP:round>div%.w %2,%0"
3272          : "f<FP:round_mul>div%.w %2,%0";
3273 })
3274
3275 (define_insn "div<mode>3_floatqi_68881"
3276   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
3277         (div:FP (match_operand:FP 1 "general_operand" "0")
3278                 (float:FP (match_operand:QI 2 "general_operand" "dmn"))))]
3279   "TARGET_68881"
3280 {
3281   return TARGET_68040
3282          ? "f<FP:round>div%.b %2,%0"
3283          : "f<FP:round_mul>div%.b %2,%0";
3284 })
3285
3286 (define_insn "div<mode>3_68881"
3287   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
3288         (div:FP (match_operand:FP 1 "general_operand" "0")
3289                 (match_operand:FP 2 "general_operand" "f<FP:dreg>m<FP:const>")))]
3290   "TARGET_68881"
3291 {
3292   if (FP_REG_P (operands[2]))
3293     return (TARGET_68040
3294             ? "f<FP:round>div%.x %2,%0"
3295             : "f<FP:round_mul>div%.x %2,%0");
3296   return (TARGET_68040
3297           ? "f<FP:round>div%.<FP:prec> %f2,%0"
3298           : "f<FP:round_mul>div%.<FP:prec> %f2,%0");
3299 })
3300
3301 (define_insn "div<mode>3_cf"
3302   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
3303         (div:FP (match_operand:FP 1 "general_operand" "0")
3304                 (match_operand:FP 2 "general_operand" "f<Q>U<FP:dreg>")))]
3305   "TARGET_COLDFIRE_FPU"
3306 {
3307   if (FP_REG_P (operands[2]))
3308     return "f<FP:prec>div%.d %2,%0";
3309   return "f<FP:prec>div%.<FP:prec> %2,%0";
3310 }
3311   [(set_attr "type" "fdiv")
3312    (set_attr "opy" "2")])
3313 \f
3314 ;; Remainder instructions.
3315
3316 (define_expand "divmodsi4"
3317   [(parallel
3318     [(set (match_operand:SI 0 "nonimmediate_operand" "")
3319           (div:SI (match_operand:SI 1 "general_operand" "")
3320                   (match_operand:SI 2 "general_src_operand" "")))
3321      (set (match_operand:SI 3 "nonimmediate_operand" "")
3322           (mod:SI (match_dup 1) (match_dup 2)))])]
3323   "TARGET_68020 || TARGET_CF_HWDIV"
3324   "")
3325
3326 (define_insn ""
3327   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
3328         (div:SI (match_operand:SI 1 "general_operand" "0")
3329                 (match_operand:SI 2 "general_src_operand" "d<Q>U")))
3330    (set (match_operand:SI 3 "nonimmediate_operand" "=&d")
3331         (mod:SI (match_dup 1) (match_dup 2)))]
3332   "TARGET_CF_HWDIV"
3333 {
3334   if (find_reg_note (insn, REG_UNUSED, operands[3]))
3335     return "divs%.l %2,%0";
3336   else if (find_reg_note (insn, REG_UNUSED, operands[0]))
3337     return "rems%.l %2,%3:%0";
3338   else
3339     return "rems%.l %2,%3:%0\;divs%.l %2,%0";
3340 }
3341   [(set_attr "type" "div_l")
3342    (set_attr "opy" "2")])
3343
3344 (define_insn ""
3345   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
3346         (div:SI (match_operand:SI 1 "general_operand" "0")
3347                 (match_operand:SI 2 "general_src_operand" "dmSTK")))
3348    (set (match_operand:SI 3 "nonimmediate_operand" "=d")
3349         (mod:SI (match_dup 1) (match_dup 2)))]
3350   "TARGET_68020"
3351 {
3352   if (find_reg_note (insn, REG_UNUSED, operands[3]))
3353     return "divs%.l %2,%0";
3354   else
3355     return "divsl%.l %2,%3:%0";
3356 })
3357
3358 (define_expand "udivmodsi4"
3359   [(parallel
3360     [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
3361           (udiv:SI (match_operand:SI 1 "general_operand" "0")
3362                    (match_operand:SI 2 "general_src_operand" "dmSTK")))
3363      (set (match_operand:SI 3 "nonimmediate_operand" "=d")
3364           (umod:SI (match_dup 1) (match_dup 2)))])]
3365   "TARGET_68020 || TARGET_CF_HWDIV"
3366   "")
3367
3368 (define_insn ""
3369   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
3370         (udiv:SI (match_operand:SI 1 "general_operand" "0")
3371                  (match_operand:SI 2 "general_src_operand" "d<Q>U")))
3372    (set (match_operand:SI 3 "nonimmediate_operand" "=&d")
3373         (umod:SI (match_dup 1) (match_dup 2)))]
3374   "TARGET_CF_HWDIV"
3375 {
3376   if (find_reg_note (insn, REG_UNUSED, operands[3]))
3377     return "divu%.l %2,%0";
3378   else if (find_reg_note (insn, REG_UNUSED, operands[0]))
3379     return "remu%.l %2,%3:%0";
3380   else
3381     return "remu%.l %2,%3:%0\;divu%.l %2,%0";
3382 }
3383   [(set_attr "type" "div_l")
3384    (set_attr "opy" "2")])
3385
3386 (define_insn ""
3387   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
3388         (udiv:SI (match_operand:SI 1 "general_operand" "0")
3389                  (match_operand:SI 2 "general_src_operand" "dmSTK")))
3390    (set (match_operand:SI 3 "nonimmediate_operand" "=d")
3391         (umod:SI (match_dup 1) (match_dup 2)))]
3392   "TARGET_68020 && !TARGET_COLDFIRE"
3393 {
3394   if (find_reg_note (insn, REG_UNUSED, operands[3]))
3395     return "divu%.l %2,%0";
3396   else
3397     return "divul%.l %2,%3:%0";
3398 })
3399
3400 (define_insn "divmodhi4"
3401   [(set (match_operand:HI 0 "nonimmediate_operand" "=d")
3402         (div:HI (match_operand:HI 1 "general_operand" "0")
3403                 (match_operand:HI 2 "general_src_operand" "dmSKT")))
3404    (set (match_operand:HI 3 "nonimmediate_operand" "=d")
3405         (mod:HI (match_dup 1) (match_dup 2)))]
3406   "!TARGET_COLDFIRE || TARGET_CF_HWDIV"
3407 {
3408   output_asm_insn (MOTOROLA ?
3409     "ext%.l %0\;divs%.w %2,%0" :
3410     "extl %0\;divs %2,%0",
3411     operands);
3412   if (!find_reg_note(insn, REG_UNUSED, operands[3]))
3413     {
3414       CC_STATUS_INIT;
3415       return "move%.l %0,%3\;swap %3";
3416     }
3417   else
3418     return "";
3419 })
3420
3421 (define_insn "udivmodhi4"
3422   [(set (match_operand:HI 0 "nonimmediate_operand" "=d")
3423         (udiv:HI (match_operand:HI 1 "general_operand" "0")
3424                  (match_operand:HI 2 "general_src_operand" "dmSKT")))
3425    (set (match_operand:HI 3 "nonimmediate_operand" "=d")
3426         (umod:HI (match_dup 1) (match_dup 2)))]
3427   "!TARGET_COLDFIRE || TARGET_CF_HWDIV"
3428 {
3429   if (ISA_HAS_MVS_MVZ)
3430     output_asm_insn (MOTOROLA ?
3431       "mvz%.w %0,%0\;divu%.w %2,%0" :
3432       "mvz%.w %0,%0\;divu %2,%0",
3433       operands);
3434   else
3435     output_asm_insn (MOTOROLA ?
3436       "and%.l #0xFFFF,%0\;divu%.w %2,%0" :
3437       "and%.l #0xFFFF,%0\;divu %2,%0",
3438       operands);
3439
3440   if (!find_reg_note(insn, REG_UNUSED, operands[3]))
3441     {
3442       CC_STATUS_INIT;
3443       return "move%.l %0,%3\;swap %3";
3444     }
3445   else
3446     return "";
3447 })
3448 \f
3449 ;; logical-and instructions
3450
3451 ;; "anddi3" is mainly here to help combine().
3452 (define_insn "anddi3"
3453   [(set (match_operand:DI 0 "nonimmediate_operand" "=o,d")
3454         (and:DI (match_operand:DI 1 "general_operand" "%0,0")
3455                 (match_operand:DI 2 "general_operand" "dn,don")))]
3456   "!TARGET_COLDFIRE"
3457 {
3458   CC_STATUS_INIT;
3459   /* We can get CONST_DOUBLE, but also const1_rtx etc.  */
3460   if (CONSTANT_P (operands[2]))
3461     {
3462       rtx hi, lo;
3463
3464       split_double (operands[2], &hi, &lo);
3465
3466       switch (INTVAL (hi))
3467         {
3468           case 0 :
3469             output_asm_insn ("clr%.l %0", operands);
3470             break;
3471           case -1 :
3472             break;
3473           default :
3474             {
3475             rtx xoperands[3];
3476
3477             xoperands[0] = operands[0];
3478             xoperands[2] = hi;
3479             output_asm_insn (output_andsi3 (xoperands), xoperands);
3480             }
3481         }
3482       if (GET_CODE (operands[0]) == REG)
3483         operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3484       else
3485         operands[0] = adjust_address (operands[0], SImode, 4);
3486       switch (INTVAL (lo))
3487         {
3488           case 0 :
3489             output_asm_insn ("clr%.l %0", operands);
3490             break;
3491           case -1 :
3492             break;
3493           default :
3494             {
3495             rtx xoperands[3];
3496
3497             xoperands[0] = operands[0];
3498             xoperands[2] = lo;
3499             output_asm_insn (output_andsi3 (xoperands), xoperands);
3500             }
3501         }
3502       return "";
3503     }
3504   if (GET_CODE (operands[0]) != REG)
3505     {
3506       operands[1] = adjust_address (operands[0], SImode, 4);
3507       return "and%.l %2,%0\;and%.l %R2,%1";
3508     }
3509   if (GET_CODE (operands[2]) != REG)
3510     {
3511       operands[1] = adjust_address (operands[2], SImode, 4);
3512       return "and%.l %2,%0\;and%.l %1,%R0";
3513     }
3514   return "and%.l %2,%0\;and%.l %R2,%R0";
3515 })
3516
3517 ;; Prevent AND from being made with sp.  This doesn't exist in the machine
3518 ;; and reload will cause inefficient code.  Since sp is a FIXED_REG, we
3519 ;; can't allocate pseudos into it.
3520
3521 (define_expand "andsi3"
3522   [(set (match_operand:SI 0 "not_sp_operand" "")
3523         (and:SI (match_operand:SI 1 "general_operand" "")
3524                 (match_operand:SI 2 "general_src_operand" "")))]
3525   ""
3526   "")
3527
3528 ;; produced by split operations after reload finished
3529 (define_insn "*andsi3_split"
3530   [(set (match_operand:SI 0 "register_operand" "=d")
3531         (and:SI (match_operand:SI 1 "register_operand" "0")
3532                 (match_operand:SI 2 "const_int_operand" "i")))]
3533   "reload_completed && !TARGET_COLDFIRE"
3534 {
3535   return output_andsi3 (operands);
3536 })
3537
3538 (define_insn "andsi3_internal"
3539   [(set (match_operand:SI 0 "not_sp_operand" "=m,d")
3540         (and:SI (match_operand:SI 1 "general_operand" "%0,0")
3541                 (match_operand:SI 2 "general_src_operand" "dKT,dmSM")))]
3542   "!TARGET_COLDFIRE"
3543 {
3544   return output_andsi3 (operands);
3545 })
3546
3547 (define_insn "andsi3_5200"
3548   [(set (match_operand:SI 0 "not_sp_operand" "=m,d")
3549         (and:SI (match_operand:SI 1 "general_operand" "%0,0")
3550                 (match_operand:SI 2 "general_src_operand" "d,dmsK")))]
3551   "TARGET_COLDFIRE"
3552 {
3553   if (ISA_HAS_MVS_MVZ
3554       && DATA_REG_P (operands[0])
3555       && GET_CODE (operands[2]) == CONST_INT)
3556     {
3557       if (INTVAL (operands[2]) == 0x000000ff)
3558         return "mvz%.b %0,%0";
3559       else if (INTVAL (operands[2]) == 0x0000ffff)
3560         return "mvz%.w %0,%0";
3561     }
3562   return output_andsi3 (operands);
3563 })
3564
3565 (define_insn "andhi3"
3566   [(set (match_operand:HI 0 "nonimmediate_operand" "=m,d")
3567         (and:HI (match_operand:HI 1 "general_operand" "%0,0")
3568                 (match_operand:HI 2 "general_src_operand" "dn,dmSn")))]
3569   "!TARGET_COLDFIRE"
3570   "and%.w %2,%0")
3571
3572 (define_insn ""
3573   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+m,d"))
3574         (and:HI (match_dup 0)
3575                 (match_operand:HI 1 "general_src_operand" "dn,dmSn")))]
3576   "!TARGET_COLDFIRE"
3577   "and%.w %1,%0")
3578
3579 (define_insn ""
3580   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+m,d"))
3581         (and:HI (match_operand:HI 1 "general_src_operand" "dn,dmSn")
3582                 (match_dup 0)))]
3583   "!TARGET_COLDFIRE"
3584   "and%.w %1,%0")
3585
3586 (define_insn "andqi3"
3587   [(set (match_operand:QI 0 "nonimmediate_operand" "=m,d")
3588         (and:QI (match_operand:QI 1 "general_operand" "%0,0")
3589                 (match_operand:QI 2 "general_src_operand" "dn,dmSn")))]
3590   "!TARGET_COLDFIRE"
3591   "and%.b %2,%0")
3592
3593 (define_insn ""
3594   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+m,d"))
3595         (and:QI (match_dup 0)
3596                 (match_operand:QI 1 "general_src_operand" "dn,dmSn")))]
3597   "!TARGET_COLDFIRE"
3598   "and%.b %1,%0")
3599
3600 (define_insn ""
3601   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+m,d"))
3602         (and:QI (match_operand:QI 1 "general_src_operand" "dn,dmSn")
3603                 (match_dup 0)))]
3604   "!TARGET_COLDFIRE"
3605   "and%.b %1,%0")
3606 \f
3607 ;; inclusive-or instructions
3608
3609 (define_insn "iordi_zext"
3610   [(set (match_operand:DI 0 "nonimmediate_operand" "=o,d")
3611     (ior:DI (zero_extend:DI (match_operand 1 "general_operand" "dn,dmn"))
3612         (match_operand:DI 2 "general_operand" "0,0")))]
3613   "!TARGET_COLDFIRE"
3614 {
3615   int byte_mode;
3616
3617   CC_STATUS_INIT;
3618   if (GET_CODE (operands[0]) == REG)
3619     operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3620   else
3621     operands[0] = adjust_address (operands[0], SImode, 4);
3622   if (GET_MODE (operands[1]) == SImode)
3623     return "or%.l %1,%0";
3624   byte_mode = (GET_MODE (operands[1]) == QImode);
3625   if (GET_CODE (operands[0]) == MEM)
3626     operands[0] = adjust_address (operands[0], byte_mode ? QImode : HImode,
3627                                   byte_mode ? 3 : 2);
3628   if (byte_mode)
3629     return "or%.b %1,%0";
3630   else
3631     return "or%.w %1,%0";
3632 })
3633
3634 ;; "iordi3" is mainly here to help combine().
3635 (define_insn "iordi3"
3636   [(set (match_operand:DI 0 "nonimmediate_operand" "=o,d")
3637         (ior:DI (match_operand:DI 1 "general_operand" "%0,0")
3638                 (match_operand:DI 2 "general_operand" "dn,don")))]
3639   "!TARGET_COLDFIRE"
3640 {
3641   CC_STATUS_INIT;
3642   /* We can get CONST_DOUBLE, but also const1_rtx etc.  */
3643   if (CONSTANT_P (operands[2]))
3644     {
3645       rtx hi, lo;
3646
3647       split_double (operands[2], &hi, &lo);
3648
3649       switch (INTVAL (hi))
3650         {
3651           case 0 :
3652             break;
3653           case -1 :
3654             /* FIXME : a scratch register would be welcome here if operand[0]
3655                is not a register */
3656             output_asm_insn ("move%.l #-1,%0", operands);
3657             break;
3658           default :
3659             {
3660             rtx xoperands[3];
3661
3662             xoperands[0] = operands[0];
3663             xoperands[2] = hi;
3664             output_asm_insn (output_iorsi3 (xoperands), xoperands);
3665             }
3666         }
3667       if (GET_CODE (operands[0]) == REG)
3668         operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3669       else
3670         operands[0] = adjust_address (operands[0], SImode, 4);
3671       switch (INTVAL (lo))
3672         {
3673           case 0 :
3674             break;
3675           case -1 :
3676             /* FIXME : a scratch register would be welcome here if operand[0]
3677                is not a register */
3678             output_asm_insn ("move%.l #-1,%0", operands);
3679             break;
3680           default :
3681             {
3682             rtx xoperands[3];
3683
3684             xoperands[0] = operands[0];
3685             xoperands[2] = lo;
3686             output_asm_insn (output_iorsi3 (xoperands), xoperands);
3687             }
3688         }
3689       return "";
3690     }
3691   if (GET_CODE (operands[0]) != REG)
3692     {
3693       operands[1] = adjust_address (operands[0], SImode, 4);
3694       return "or%.l %2,%0\;or%.l %R2,%1";
3695     }
3696   if (GET_CODE (operands[2]) != REG)
3697     {
3698       operands[1] = adjust_address (operands[2], SImode, 4);
3699       return "or%.l %2,%0\;or%.l %1,%R0";
3700     }
3701   return "or%.l %2,%0\;or%.l %R2,%R0";
3702 })
3703
3704 (define_expand "iorsi3"
3705   [(set (match_operand:SI 0 "nonimmediate_operand" "")
3706         (ior:SI (match_operand:SI 1 "general_operand" "")
3707                 (match_operand:SI 2 "general_src_operand" "")))]
3708   ""
3709   "")
3710
3711 (define_insn "iorsi3_internal"
3712   [(set (match_operand:SI 0 "nonimmediate_operand" "=m,d")
3713         (ior:SI (match_operand:SI 1 "general_operand" "%0,0")
3714                 (match_operand:SI 2 "general_src_operand" "dKT,dmSMT")))]
3715   "! TARGET_COLDFIRE"
3716 {
3717   return output_iorsi3 (operands);
3718 })
3719
3720 (define_insn "iorsi3_5200"
3721   [(set (match_operand:SI 0 "nonimmediate_operand" "=m,d")
3722         (ior:SI (match_operand:SI 1 "general_operand" "%0,0")
3723                 (match_operand:SI 2 "general_src_operand" "d,dmsK")))]
3724   "TARGET_COLDFIRE"
3725 {
3726   return output_iorsi3 (operands);
3727 })
3728
3729 (define_insn "iorhi3"
3730   [(set (match_operand:HI 0 "nonimmediate_operand" "=m,d")
3731         (ior:HI (match_operand:HI 1 "general_operand" "%0,0")
3732                 (match_operand:HI 2 "general_src_operand" "dn,dmSn")))]
3733   "!TARGET_COLDFIRE"
3734   "or%.w %2,%0")
3735
3736 (define_insn ""
3737   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+m,d"))
3738         (ior:HI (match_dup 0)
3739                 (match_operand:HI 1 "general_src_operand" "dn,dmSn")))]
3740   "!TARGET_COLDFIRE"
3741   "or%.w %1,%0")
3742
3743 (define_insn ""
3744   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+m,d"))
3745         (ior:HI (match_operand:HI 1 "general_src_operand" "dn,dmSn")
3746                 (match_dup 0)))]
3747   "!TARGET_COLDFIRE"
3748   "or%.w %1,%0")
3749
3750 (define_insn "iorqi3"
3751   [(set (match_operand:QI 0 "nonimmediate_operand" "=m,d")
3752         (ior:QI (match_operand:QI 1 "general_operand" "%0,0")
3753                 (match_operand:QI 2 "general_src_operand" "dn,dmSn")))]
3754   "!TARGET_COLDFIRE"
3755   "or%.b %2,%0")
3756
3757 (define_insn ""
3758   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+m,d"))
3759         (ior:QI (match_dup 0)
3760                 (match_operand:QI 1 "general_src_operand" "dn,dmSn")))]
3761   "!TARGET_COLDFIRE"
3762   "or%.b %1,%0")
3763
3764 (define_insn ""
3765   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+m,d"))
3766         (ior:QI (match_operand:QI 1 "general_src_operand" "dn,dmSn")
3767                 (match_dup 0)))]
3768   "!TARGET_COLDFIRE"
3769   "or%.b %1,%0")
3770
3771 ;; On all 68k models, this makes faster code in a special case.
3772 ;; See also ashlsi_16, ashrsi_16 and lshrsi_16.
3773
3774 (define_insn "iorsi_zexthi_ashl16"
3775   [(set (match_operand:SI 0 "nonimmediate_operand" "=&d")
3776     (ior:SI (zero_extend:SI (match_operand:HI 1 "general_operand" "rmn"))
3777         (ashift:SI (match_operand:SI 2 "general_operand" "or")
3778             (const_int 16))))]
3779   ""
3780 {
3781   CC_STATUS_INIT;
3782   if (GET_CODE (operands[2]) != REG)
3783       operands[2] = adjust_address (operands[2], HImode, 2);
3784   if (GET_CODE (operands[2]) != REG
3785   || REGNO (operands[2]) != REGNO (operands[0]))
3786     output_asm_insn ("move%.w %2,%0", operands);
3787   return "swap %0\;mov%.w %1,%0";
3788 })
3789
3790 (define_insn "iorsi_zext"
3791   [(set (match_operand:SI 0 "nonimmediate_operand" "=o,d")
3792     (ior:SI (zero_extend:SI (match_operand 1 "general_operand" "dn,dmn"))
3793         (match_operand:SI 2 "general_operand" "0,0")))]
3794   "!TARGET_COLDFIRE"
3795 {
3796   int byte_mode;
3797
3798   CC_STATUS_INIT;
3799   byte_mode = (GET_MODE (operands[1]) == QImode);
3800   if (GET_CODE (operands[0]) == MEM)
3801     operands[0] = adjust_address (operands[0], byte_mode ? QImode : HImode,
3802                                   byte_mode ? 3 : 2);
3803   if (byte_mode)
3804     return "or%.b %1,%0";
3805   else
3806     return "or%.w %1,%0";
3807 })
3808 \f
3809 ;; xor instructions
3810
3811 ;; "xordi3" is mainly here to help combine().
3812 (define_insn "xordi3"
3813   [(set (match_operand:DI 0 "nonimmediate_operand" "=od")
3814         (xor:DI (match_operand:DI 1 "general_operand" "%0")
3815                 (match_operand:DI 2 "general_operand" "dn")))]
3816   "!TARGET_COLDFIRE"
3817 {
3818   CC_STATUS_INIT;
3819   /* We can get CONST_DOUBLE, but also const1_rtx etc.  */
3820
3821   if (CONSTANT_P (operands[2]))
3822     {
3823       rtx hi, lo;
3824
3825       split_double (operands[2], &hi, &lo);
3826
3827       switch (INTVAL (hi))
3828         {
3829           case 0 :
3830             break;
3831           case -1 :
3832             output_asm_insn ("not%.l %0", operands);
3833             break;
3834           default :
3835             /* FIXME : a scratch register would be welcome here if
3836                -128 <= INTVAL (hi) < -1 */
3837             {
3838             rtx xoperands[3];
3839
3840             xoperands[0] = operands[0];
3841             xoperands[2] = hi;
3842             output_asm_insn (output_xorsi3 (xoperands), xoperands);
3843             }
3844         }
3845       if (GET_CODE (operands[0]) == REG)
3846         operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3847       else
3848         operands[0] = adjust_address (operands[0], SImode, 4);
3849       switch (INTVAL (lo))
3850         {
3851           case 0 :
3852             break;
3853           case -1 :
3854             output_asm_insn ("not%.l %0", operands);
3855             break;
3856           default :
3857             /* FIXME : a scratch register would be welcome here if
3858                -128 <= INTVAL (lo) < -1 */
3859             operands[2] = lo;
3860             /* FIXME : this should be merged with xorsi3 */
3861             {
3862             rtx xoperands[3];
3863
3864             xoperands[0] = operands[0];
3865             xoperands[2] = lo;
3866             output_asm_insn (output_xorsi3 (xoperands), xoperands);
3867             }
3868         }
3869       return "";
3870     }
3871   if (GET_CODE (operands[0]) != REG)
3872     {
3873       operands[1] = adjust_address (operands[0], SImode, 4);
3874       return "eor%.l %2,%0\;eor%.l %R2,%1";
3875     }
3876   if (GET_CODE (operands[2]) != REG)
3877     {
3878       operands[1] = adjust_address (operands[2], SImode, 4);
3879       return "eor%.l %2,%0\;eor%.l %1,%R0";
3880     }
3881   return "eor%.l %2,%0\;eor%.l %R2,%R0";
3882 })
3883
3884 (define_expand "xorsi3"
3885   [(set (match_operand:SI 0 "nonimmediate_operand" "")
3886         (xor:SI (match_operand:SI 1 "general_operand" "")
3887                 (match_operand:SI 2 "general_operand" "")))]
3888   ""
3889   "")
3890
3891 (define_insn "xorsi3_internal"
3892   [(set (match_operand:SI 0 "nonimmediate_operand" "=do,m")
3893         (xor:SI (match_operand:SI 1 "general_operand" "%0,0")
3894                 (match_operand:SI 2 "general_operand" "di,dKT")))]
3895
3896   "!TARGET_COLDFIRE"
3897 {
3898   return output_xorsi3 (operands);
3899 })
3900
3901 (define_insn "xorsi3_5200"
3902   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm,d")
3903         (xor:SI (match_operand:SI 1 "general_operand" "%0,0")
3904                 (match_operand:SI 2 "general_operand" "d,Ks")))]
3905   "TARGET_COLDFIRE"
3906 {
3907   return output_xorsi3 (operands);
3908 })
3909
3910 (define_insn "xorhi3"
3911   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm")
3912         (xor:HI (match_operand:HI 1 "general_operand" "%0")
3913                 (match_operand:HI 2 "general_operand" "dn")))]
3914   "!TARGET_COLDFIRE"
3915   "eor%.w %2,%0")
3916
3917 (define_insn ""
3918   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+dm"))
3919         (xor:HI (match_dup 0)
3920                 (match_operand:HI 1 "general_operand" "dn")))]
3921   "!TARGET_COLDFIRE"
3922   "eor%.w %1,%0")
3923
3924 (define_insn ""
3925   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+dm"))
3926         (xor:HI (match_operand:HI 1 "general_operand" "dn")
3927                 (match_dup 0)))]
3928   "!TARGET_COLDFIRE"
3929   "eor%.w %1,%0")
3930
3931 (define_insn "xorqi3"
3932   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
3933         (xor:QI (match_operand:QI 1 "general_operand" "%0")
3934                 (match_operand:QI 2 "general_operand" "dn")))]
3935   "!TARGET_COLDFIRE"
3936   "eor%.b %2,%0")
3937
3938 (define_insn ""
3939   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+dm"))
3940         (xor:QI (match_dup 0)
3941                 (match_operand:QI 1 "general_operand" "dn")))]
3942   "!TARGET_COLDFIRE"
3943   "eor%.b %1,%0")
3944
3945 (define_insn ""
3946   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+dm"))
3947         (xor:QI (match_operand:QI 1 "general_operand" "dn")
3948                 (match_dup 0)))]
3949   "!TARGET_COLDFIRE"
3950   "eor%.b %1,%0")
3951 \f
3952 ;; negation instructions
3953
3954 (define_expand "negdi2"
3955   [(set (match_operand:DI 0 "nonimmediate_operand" "")
3956         (neg:DI (match_operand:DI 1 "general_operand" "")))]
3957   ""
3958 {
3959   if (TARGET_COLDFIRE)
3960     emit_insn (gen_negdi2_5200 (operands[0], operands[1]));
3961   else
3962     emit_insn (gen_negdi2_internal (operands[0], operands[1]));
3963   DONE;
3964 })
3965
3966 (define_insn "negdi2_internal"
3967   [(set (match_operand:DI 0 "nonimmediate_operand" "=<,do,!*a")
3968         (neg:DI (match_operand:DI 1 "general_operand" "0,0,0")))]
3969   "!TARGET_COLDFIRE"
3970 {
3971   if (which_alternative == 0)
3972     return "neg%.l %0\;negx%.l %0";
3973   if (GET_CODE (operands[0]) == REG)
3974     operands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3975   else
3976     operands[1] = adjust_address (operands[0], SImode, 4);
3977   if (ADDRESS_REG_P (operands[0]))
3978     return "exg %/d0,%1\;neg%.l %/d0\;exg %/d0,%1\;exg %/d0,%0\;negx%.l %/d0\;exg %/d0,%0";
3979   else
3980     return "neg%.l %1\;negx%.l %0";
3981 })
3982
3983 (define_insn "negdi2_5200"
3984   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
3985         (neg:DI (match_operand:DI 1 "general_operand" "0")))]
3986   "TARGET_COLDFIRE"
3987 {
3988   operands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3989   return "neg%.l %1\;negx%.l %0";
3990 })
3991
3992 (define_expand "negsi2"
3993   [(set (match_operand:SI 0 "nonimmediate_operand" "")
3994         (neg:SI (match_operand:SI 1 "general_operand" "")))]
3995   ""
3996 {
3997   if (TARGET_COLDFIRE)
3998     emit_insn (gen_negsi2_5200 (operands[0], operands[1]));
3999   else
4000     emit_insn (gen_negsi2_internal (operands[0], operands[1]));
4001   DONE;
4002 })
4003
4004 (define_insn "negsi2_internal"
4005   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
4006         (neg:SI (match_operand:SI 1 "general_operand" "0")))]
4007   "!TARGET_COLDFIRE"
4008   "neg%.l %0"
4009   [(set_attr "type" "neg_l")])
4010
4011 (define_insn "negsi2_5200"
4012   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
4013         (neg:SI (match_operand:SI 1 "general_operand" "0")))]
4014   "TARGET_COLDFIRE"
4015   "neg%.l %0"
4016   [(set_attr "type" "neg_l")])
4017
4018 (define_insn "neghi2"
4019   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm")
4020         (neg:HI (match_operand:HI 1 "general_operand" "0")))]
4021   "!TARGET_COLDFIRE"
4022   "neg%.w %0")
4023
4024 (define_insn ""
4025   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+dm"))
4026         (neg:HI (match_dup 0)))]
4027   "!TARGET_COLDFIRE"
4028   "neg%.w %0")
4029
4030 (define_insn "negqi2"
4031   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
4032         (neg:QI (match_operand:QI 1 "general_operand" "0")))]
4033   "!TARGET_COLDFIRE"
4034   "neg%.b %0")
4035
4036 (define_insn ""
4037   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+dm"))
4038         (neg:QI (match_dup 0)))]
4039   "!TARGET_COLDFIRE"
4040   "neg%.b %0")
4041
4042 ;; If using software floating point, just flip the sign bit.
4043
4044 (define_expand "negsf2"
4045   [(set (match_operand:SF 0 "nonimmediate_operand" "")
4046         (neg:SF (match_operand:SF 1 "general_operand" "")))]
4047   ""
4048 {
4049   if (!TARGET_HARD_FLOAT)
4050     {
4051       rtx result;
4052       rtx target;
4053
4054       target = operand_subword_force (operands[0], 0, SFmode);
4055       result = expand_binop (SImode, xor_optab,
4056                              operand_subword_force (operands[1], 0, SFmode),
4057                              GEN_INT (-2147483647 - 1), target, 0, OPTAB_WIDEN);
4058       gcc_assert (result);
4059
4060       if (result != target)
4061         emit_move_insn (result, target);
4062
4063       /* Make a place for REG_EQUAL.  */
4064       emit_move_insn (operands[0], operands[0]);
4065       DONE;
4066     }
4067 })
4068
4069 (define_expand "negdf2"
4070   [(set (match_operand:DF 0 "nonimmediate_operand" "")
4071         (neg:DF (match_operand:DF 1 "general_operand" "")))]
4072   ""
4073 {
4074   if (!TARGET_HARD_FLOAT)
4075     {
4076       rtx result;
4077       rtx target;
4078       rtx insns;
4079
4080       start_sequence ();
4081       target = operand_subword (operands[0], 0, 1, DFmode);
4082       result = expand_binop (SImode, xor_optab,
4083                              operand_subword_force (operands[1], 0, DFmode),
4084                              GEN_INT (-2147483647 - 1), target, 0, OPTAB_WIDEN);
4085       gcc_assert (result);
4086
4087       if (result != target)
4088         emit_move_insn (result, target);
4089
4090       emit_move_insn (operand_subword (operands[0], 1, 1, DFmode),
4091                       operand_subword_force (operands[1], 1, DFmode));
4092
4093       insns = get_insns ();
4094       end_sequence ();
4095
4096       emit_insn (insns);
4097       DONE;
4098     }
4099 })
4100
4101 (define_expand "negxf2"
4102   [(set (match_operand:XF 0 "nonimmediate_operand" "")
4103         (neg:XF (match_operand:XF 1 "nonimmediate_operand" "")))]
4104   ""
4105 {
4106   if (!TARGET_68881)
4107     {
4108       rtx result;
4109       rtx target;
4110       rtx insns;
4111
4112       start_sequence ();
4113       target = operand_subword (operands[0], 0, 1, XFmode);
4114       result = expand_binop (SImode, xor_optab,
4115                              operand_subword_force (operands[1], 0, XFmode),
4116                              GEN_INT (-2147483647 - 1), target, 0, OPTAB_WIDEN);
4117       gcc_assert (result);
4118
4119       if (result != target)
4120         emit_move_insn (result, target);
4121
4122       emit_move_insn (operand_subword (operands[0], 1, 1, XFmode),
4123                       operand_subword_force (operands[1], 1, XFmode));
4124       emit_move_insn (operand_subword (operands[0], 2, 1, XFmode),
4125                       operand_subword_force (operands[1], 2, XFmode));
4126
4127       insns = get_insns ();
4128       end_sequence ();
4129
4130       emit_insn (insns);
4131       DONE;
4132     }
4133 })
4134
4135 (define_insn "neg<mode>2_68881"
4136   [(set (match_operand:FP 0 "nonimmediate_operand" "=f,d")
4137         (neg:FP (match_operand:FP 1 "general_operand" "f<FP:dreg>m<FP:const>,0")))]
4138   "TARGET_68881"
4139 {
4140   if (DATA_REG_P (operands[0]))
4141     {
4142       operands[1] = GEN_INT (31);
4143       return "bchg %1,%0";
4144     }
4145   if (FP_REG_P (operands[1]))
4146     return "f<FP:round>neg%.x %1,%0";
4147   return "f<FP:round>neg%.<FP:prec> %f1,%0";
4148 })
4149
4150 (define_insn "neg<mode>2_cf"
4151   [(set (match_operand:FP 0 "nonimmediate_operand" "=f,d")
4152         (neg:FP (match_operand:FP 1 "general_operand" "f<FP:dreg><Q>U,0")))]
4153   "TARGET_COLDFIRE_FPU"
4154 {
4155   if (DATA_REG_P (operands[0]))
4156     {
4157       operands[1] = GEN_INT (31);
4158       return "bchg %1,%0";
4159     }
4160   if (FP_REG_P (operands[1]))
4161     return "f<FP:prec>neg%.d %1,%0";
4162   return "f<FP:prec>neg%.<FP:prec> %1,%0";
4163 })
4164 \f
4165 ;; Sqrt instruction for the 68881
4166
4167 (define_expand "sqrt<mode>2"
4168   [(set (match_operand:FP 0 "nonimmediate_operand" "")
4169         (sqrt:FP (match_operand:FP 1 "general_operand" "")))]
4170   "TARGET_HARD_FLOAT"
4171   "")
4172
4173 (define_insn "sqrt<mode>2_68881"
4174   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
4175         (sqrt:FP (match_operand:FP 1 "general_operand" "f<FP:dreg>m")))]
4176   "TARGET_68881"
4177 {
4178   if (FP_REG_P (operands[1]))
4179     return "f<FP:round>sqrt%.x %1,%0";
4180   return "f<FP:round>sqrt%.<FP:prec> %1,%0";
4181 }
4182   [(set_attr "type" "fsqrt")])
4183
4184 (define_insn "sqrt<mode>2_cf"
4185   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
4186         (sqrt:FP (match_operand:FP 1 "general_operand" "f<FP:dreg><Q>U")))]
4187   "TARGET_COLDFIRE_FPU"
4188 {
4189   if (FP_REG_P (operands[1]))
4190     return "f<FP:prec>sqrt%.d %1,%0";
4191   return "f<FP:prec>sqrt%.<FP:prec> %1,%0";
4192 }
4193   [(set_attr "type" "fsqrt")])
4194 ;; Absolute value instructions
4195 ;; If using software floating point, just zero the sign bit.
4196
4197 (define_expand "abssf2"
4198   [(set (match_operand:SF 0 "nonimmediate_operand" "")
4199         (abs:SF (match_operand:SF 1 "general_operand" "")))]
4200   ""
4201 {
4202   if (!TARGET_HARD_FLOAT)
4203     {
4204       rtx result;
4205       rtx target;
4206
4207       target = operand_subword_force (operands[0], 0, SFmode);
4208       result = expand_binop (SImode, and_optab,
4209                              operand_subword_force (operands[1], 0, SFmode),
4210                              GEN_INT (0x7fffffff), target, 0, OPTAB_WIDEN);
4211       gcc_assert (result);
4212
4213       if (result != target)
4214         emit_move_insn (result, target);
4215
4216       /* Make a place for REG_EQUAL.  */
4217       emit_move_insn (operands[0], operands[0]);
4218       DONE;
4219     }
4220 })
4221
4222 (define_expand "absdf2"
4223   [(set (match_operand:DF 0 "nonimmediate_operand" "")
4224         (abs:DF (match_operand:DF 1 "general_operand" "")))]
4225   ""
4226 {
4227   if (!TARGET_HARD_FLOAT)
4228     {
4229       rtx result;
4230       rtx target;
4231       rtx insns;
4232
4233       start_sequence ();
4234       target = operand_subword (operands[0], 0, 1, DFmode);
4235       result = expand_binop (SImode, and_optab,
4236                              operand_subword_force (operands[1], 0, DFmode),
4237                              GEN_INT (0x7fffffff), target, 0, OPTAB_WIDEN);
4238       gcc_assert (result);
4239
4240       if (result != target)
4241         emit_move_insn (result, target);
4242
4243       emit_move_insn (operand_subword (operands[0], 1, 1, DFmode),
4244                       operand_subword_force (operands[1], 1, DFmode));
4245
4246       insns = get_insns ();
4247       end_sequence ();
4248
4249       emit_insn (insns);
4250       DONE;
4251     }
4252 })
4253
4254 (define_expand "absxf2"
4255   [(set (match_operand:XF 0 "nonimmediate_operand" "")
4256         (abs:XF (match_operand:XF 1 "nonimmediate_operand" "")))]
4257   ""
4258 {
4259   if (!TARGET_68881)
4260     {
4261       rtx result;
4262       rtx target;
4263       rtx insns;
4264
4265       start_sequence ();
4266       target = operand_subword (operands[0], 0, 1, XFmode);
4267       result = expand_binop (SImode, and_optab,
4268                              operand_subword_force (operands[1], 0, XFmode),
4269                              GEN_INT (0x7fffffff), target, 0, OPTAB_WIDEN);
4270       gcc_assert (result);
4271
4272       if (result != target)
4273         emit_move_insn (result, target);
4274
4275       emit_move_insn (operand_subword (operands[0], 1, 1, XFmode),
4276                       operand_subword_force (operands[1], 1, XFmode));
4277       emit_move_insn (operand_subword (operands[0], 2, 1, XFmode),
4278                       operand_subword_force (operands[1], 2, XFmode));
4279
4280       insns = get_insns ();
4281       end_sequence ();
4282
4283       emit_insn (insns);
4284       DONE;
4285     }
4286 })
4287
4288 (define_insn "abs<mode>2_68881"
4289   [(set (match_operand:FP 0 "nonimmediate_operand" "=f,d")
4290         (abs:FP (match_operand:FP 1 "general_operand" "f<FP:dreg>m<FP:const>,0")))]
4291   "TARGET_68881"
4292 {
4293   if (DATA_REG_P (operands[0]))
4294     {
4295       operands[1] = GEN_INT (31);
4296       return "bclr %1,%0";
4297     }
4298   if (FP_REG_P (operands[1]))
4299     return "f<FP:round>abs%.x %1,%0";
4300   return "f<FP:round>abs%.<FP:prec> %f1,%0";
4301 })
4302
4303 (define_insn "abs<mode>2_cf"
4304   [(set (match_operand:FP 0 "nonimmediate_operand" "=f,d")
4305         (abs:FP (match_operand:FP 1 "general_operand" "f<FP:dreg><Q>U,0")))]
4306   "TARGET_COLDFIRE_FPU"
4307 {
4308   if (DATA_REG_P (operands[0]))
4309     {
4310       operands[1] = GEN_INT (31);
4311       return "bclr %1,%0";
4312     }
4313   if (FP_REG_P (operands[1]))
4314     return "f<FP:prec>abs%.d %1,%0";
4315   return "f<FP:prec>abs%.<FP:prec> %1,%0";
4316 }
4317   [(set_attr "type" "bitrw,fneg")])
4318 \f
4319 ;; bit indexing instructions
4320
4321 ;; ColdFire ff1 instruction implements clz.
4322 (define_insn "clzsi2"
4323   [(set (match_operand:SI 0 "register_operand" "=d")
4324         (clz:SI (match_operand:SI 1 "register_operand" "0")))]
4325   "ISA_HAS_FF1"
4326   "ff1 %0"
4327   [(set_attr "type" "ext")])
4328 \f
4329 ;; one complement instructions
4330
4331 ;; "one_cmpldi2" is mainly here to help combine().
4332 (define_insn "one_cmpldi2"
4333   [(set (match_operand:DI 0 "nonimmediate_operand" "=dm")
4334         (not:DI (match_operand:DI 1 "general_operand" "0")))]
4335   "!TARGET_COLDFIRE"
4336 {
4337   CC_STATUS_INIT;
4338   if (GET_CODE (operands[0]) == REG)
4339     operands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
4340   else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC
4341         || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
4342     operands[1] = operands[0];
4343   else
4344     operands[1] = adjust_address (operands[0], SImode, 4);
4345   return "not%.l %1\;not%.l %0";
4346 })
4347
4348 (define_expand "one_cmplsi2"
4349   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4350         (not:SI (match_operand:SI 1 "general_operand" "")))]
4351   ""
4352 {
4353   if (TARGET_COLDFIRE)
4354     emit_insn (gen_one_cmplsi2_5200 (operands[0], operands[1]));
4355   else
4356     emit_insn (gen_one_cmplsi2_internal (operands[0], operands[1]));
4357   DONE;
4358 })
4359
4360 (define_insn "one_cmplsi2_internal"
4361   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
4362         (not:SI (match_operand:SI 1 "general_operand" "0")))]
4363   "!TARGET_COLDFIRE"
4364   "not%.l %0")
4365
4366 (define_insn "one_cmplsi2_5200"
4367   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
4368         (not:SI (match_operand:SI 1 "general_operand" "0")))]
4369   "TARGET_COLDFIRE"
4370   "not%.l %0"
4371   [(set_attr "type" "neg_l")])
4372
4373 (define_insn "one_cmplhi2"
4374   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm")
4375         (not:HI (match_operand:HI 1 "general_operand" "0")))]
4376   "!TARGET_COLDFIRE"
4377   "not%.w %0")
4378
4379 (define_insn ""
4380   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+dm"))
4381         (not:HI (match_dup 0)))]
4382   "!TARGET_COLDFIRE"
4383   "not%.w %0")
4384
4385 (define_insn "one_cmplqi2"
4386   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
4387         (not:QI (match_operand:QI 1 "general_operand" "0")))]
4388   "!TARGET_COLDFIRE"
4389   "not%.b %0")
4390
4391 (define_insn ""
4392   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+dm"))
4393         (not:QI (match_dup 0)))]
4394   "!TARGET_COLDFIRE"
4395   "not%.b %0")
4396 \f
4397 ;; arithmetic shift instructions
4398 ;; We don't need the shift memory by 1 bit instruction
4399
4400 (define_insn "ashldi_extsi"
4401   [(set (match_operand:DI 0 "nonimmediate_operand" "=ro")
4402     (ashift:DI
4403       (match_operator:DI 2 "extend_operator"
4404         [(match_operand:SI 1 "general_operand" "rm")])
4405       (const_int 32)))]
4406   ""
4407 {
4408   CC_STATUS_INIT;
4409   if (GET_CODE (operands[0]) == REG)
4410     operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
4411   else
4412     operands[2] = adjust_address (operands[0], SImode, 4);
4413   if (ADDRESS_REG_P (operands[0]))
4414     return "move%.l %1,%0\;sub%.l %2,%2";
4415   else
4416     return "move%.l %1,%0\;clr%.l %2";
4417 })
4418
4419 (define_insn "ashldi_sexthi"
4420   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,a*d")
4421     (ashift:DI (sign_extend:DI (match_operand:HI 1 "general_operand" "rm,rm"))
4422         (const_int 32)))
4423     (clobber (match_scratch:SI 2 "=a,X"))]
4424   ""
4425 {
4426   CC_STATUS_INIT;
4427   if (GET_CODE (operands[0]) == MEM)
4428     {
4429     if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
4430       return "clr%.l %0\;move%.w %1,%2\;move%.l %2,%0";
4431     else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
4432       return "move%.w %1,%2\;move%.l %2,%0\;clr%.l %0";
4433     else
4434       {
4435         operands[3] = adjust_address (operands[0], SImode, 4);
4436         return "move%.w %1,%2\;move%.l %2,%0\;clr%.l %3";
4437       }
4438     }
4439   else if (DATA_REG_P (operands[0]))
4440     return "move%.w %1,%0\;ext%.l %0\;clr%.l %R0";
4441   else
4442     return "move%.w %1,%0\;sub%.l %R0,%R0";
4443 })
4444
4445 (define_insn "*ashldi3_const1"
4446   [(set (match_operand:DI 0 "register_operand" "=d")
4447         (ashift:DI (match_operand:DI 1 "register_operand" "0")
4448                    (const_int 1)))]
4449   "!TARGET_COLDFIRE"
4450   "add%.l %R0,%R0\;addx%.l %0,%0")
4451
4452 (define_split
4453   [(set (match_operand:DI 0 "register_operand" "")
4454         (ashift:DI (match_operand:DI 1 "register_operand" "")
4455                    (const_int 2)))]
4456   "reload_completed && !TARGET_COLDFIRE"
4457   [(set (match_dup 0)
4458         (ashift:DI (match_dup 1) (const_int 1)))
4459    (set (match_dup 0)
4460         (ashift:DI (match_dup 0) (const_int 1)))]
4461   "")
4462
4463 (define_split
4464   [(set (match_operand:DI 0 "register_operand" "")
4465         (ashift:DI (match_operand:DI 1 "register_operand" "")
4466                    (const_int 3)))]
4467   "reload_completed && !TARGET_COLDFIRE"
4468   [(set (match_dup 0)
4469         (ashift:DI (match_dup 1) (const_int 2)))
4470    (set (match_dup 0)
4471         (ashift:DI (match_dup 0) (const_int 1)))]
4472   "")
4473
4474 (define_split
4475   [(set (match_operand:DI 0 "register_operand" "")
4476         (ashift:DI (match_operand:DI 1 "register_operand" "")
4477                    (const_int 8)))]
4478   "reload_completed && !TARGET_COLDFIRE"
4479   [(set (match_dup 2)
4480         (rotate:SI (match_dup 2) (const_int 8)))
4481    (set (match_dup 3)
4482         (rotate:SI (match_dup 3) (const_int 8)))
4483    (set (strict_low_part (subreg:QI (match_dup 0) 3))
4484         (subreg:QI (match_dup 0) 7))
4485    (set (strict_low_part (subreg:QI (match_dup 0) 7))
4486         (const_int 0))]
4487 {
4488   operands[2] = gen_highpart (SImode, operands[0]);
4489   operands[3] = gen_lowpart (SImode, operands[0]);
4490 })
4491
4492 (define_split
4493   [(set (match_operand:DI 0 "register_operand" "")
4494         (ashift:DI (match_operand:DI 1 "register_operand" "")
4495                    (const_int 16)))]
4496   "reload_completed && !TARGET_COLDFIRE"
4497   [(set (match_dup 2)
4498         (rotate:SI (match_dup 2) (const_int 16)))
4499    (set (match_dup 3)
4500         (rotate:SI (match_dup 3) (const_int 16)))
4501    (set (strict_low_part (subreg:HI (match_dup 0) 2))
4502         (subreg:HI (match_dup 0) 6))
4503    (set (strict_low_part (subreg:HI (match_dup 0) 6))
4504         (const_int 0))]
4505 {
4506   operands[2] = gen_highpart (SImode, operands[0]);
4507   operands[3] = gen_lowpart (SImode, operands[0]);
4508 })
4509
4510 (define_split
4511   [(set (match_operand:DI 0 "pre_dec_operand" "")
4512         (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "")
4513                    (const_int 32)))]
4514   "reload_completed"
4515   [(set (match_dup 0) (const_int 0))
4516    (set (match_dup 0) (match_dup 1))]
4517 {
4518   operands[0] = adjust_address(operands[0], SImode, 0);
4519   operands[1] = gen_lowpart(SImode, operands[1]);
4520 })
4521
4522 (define_split
4523   [(set (match_operand:DI 0 "post_inc_operand" "")
4524         (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "")
4525                    (const_int 32)))]
4526   "reload_completed"
4527   [(set (match_dup 0) (match_dup 1))
4528    (set (match_dup 0) (const_int 0))]
4529 {
4530   operands[0] = adjust_address(operands[0], SImode, 0);
4531   operands[1] = gen_lowpart(SImode, operands[1]);
4532 })
4533
4534 (define_insn_and_split "*ashldi3_const32"
4535   [(set (match_operand:DI 0 "nonimmediate_operand" "=ro<>")
4536         (ashift:DI (match_operand:DI 1 "nonimmediate_operand" "ro")
4537                    (const_int 32)))]
4538   ""
4539   "#"
4540   "&& reload_completed"
4541   [(set (match_dup 4) (match_dup 3))
4542    (set (match_dup 2) (const_int 0))]
4543   "split_di(operands, 2, operands + 2, operands + 4);")
4544
4545 (define_split
4546   [(set (match_operand:DI 0 "register_operand" "")
4547         (ashift:DI (match_operand:DI 1 "register_operand" "")
4548                    (match_operand 2 "const_int_operand" "")))]
4549   "reload_completed && !TARGET_COLDFIRE
4550    && INTVAL (operands[2]) > 32 && INTVAL (operands[2]) <= 40"
4551   [(set (match_dup 4) (ashift:SI (match_dup 4) (match_dup 2)))
4552    (set (match_dup 3) (match_dup 4))
4553    (set (match_dup 4) (const_int 0))]
4554 {
4555   operands[2] = GEN_INT (INTVAL (operands[2]) - 32);
4556   operands[3] = gen_highpart (SImode, operands[0]);
4557   operands[4] = gen_lowpart (SImode, operands[0]);
4558 })
4559
4560 (define_split
4561   [(set (match_operand:DI 0 "register_operand" "")
4562         (ashift:DI (match_operand:DI 1 "register_operand" "")
4563                    (const_int 48)))]
4564   "reload_completed && !TARGET_COLDFIRE"
4565   [(set (match_dup 2) (match_dup 3))
4566    (set (match_dup 2)
4567         (rotate:SI (match_dup 2) (const_int 16)))
4568    (set (match_dup 3) (const_int 0))
4569    (set (strict_low_part (subreg:HI (match_dup 0) 2))
4570         (const_int 0))]
4571 {
4572   operands[2] = gen_highpart (SImode, operands[0]);
4573   operands[3] = gen_lowpart (SImode, operands[0]);
4574 })
4575
4576 (define_split
4577   [(set (match_operand:DI 0 "register_operand" "")
4578         (ashift:DI (match_operand:DI 1 "register_operand" "")
4579                    (match_operand 2 "const_int_operand" "")))]
4580   "reload_completed && !TARGET_COLDFIRE
4581    && INTVAL (operands[2]) > 40 && INTVAL (operands[2]) <= 63"
4582   [(set (match_dup 3) (match_dup 2))
4583    (set (match_dup 4) (ashift:SI (match_dup 4) (match_dup 3)))
4584    (set (match_dup 3) (match_dup 4))
4585    (set (match_dup 4) (const_int 0))]
4586 {
4587   operands[2] = GEN_INT (INTVAL (operands[2]) - 32);
4588   operands[3] = gen_highpart (SImode, operands[0]);
4589   operands[4] = gen_lowpart (SImode, operands[0]);
4590 })
4591
4592 (define_insn "*ashldi3"
4593   [(set (match_operand:DI 0 "register_operand" "=d")
4594         (ashift:DI (match_operand:DI 1 "register_operand" "0")
4595                    (match_operand 2 "const_int_operand" "n")))]
4596   "!TARGET_COLDFIRE
4597     && ((INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 3)
4598         || INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 16
4599         || (INTVAL (operands[2]) > 32 && INTVAL (operands[2]) <= 63))"
4600   "#")
4601
4602 (define_expand "ashldi3"
4603   [(set (match_operand:DI 0 "register_operand" "")
4604         (ashift:DI (match_operand:DI 1 "register_operand" "")
4605                    (match_operand 2 "const_int_operand" "")))]
4606   "!TARGET_COLDFIRE"
4607 {
4608   /* ???  This is a named pattern like this is not allowed to FAIL based
4609      on its operands.  */
4610   if (GET_CODE (operands[2]) != CONST_INT
4611       || ((INTVAL (operands[2]) < 1 || INTVAL (operands[2]) > 3)
4612           && INTVAL (operands[2]) != 8 && INTVAL (operands[2]) != 16
4613           && (INTVAL (operands[2]) < 32 || INTVAL (operands[2]) > 63)))
4614     FAIL;
4615 })
4616
4617 ;; On most 68k models, this makes faster code in a special case.
4618
4619 (define_insn "ashlsi_16"
4620   [(set (match_operand:SI 0 "register_operand" "=d")
4621         (ashift:SI (match_operand:SI 1 "register_operand" "0")
4622                    (const_int 16)))]
4623   "!TUNE_68060"
4624 {
4625   CC_STATUS_INIT;
4626   return "swap %0\;clr%.w %0";
4627 })
4628
4629 ;; ashift patterns : use lsl instead of asl, because lsl always clears the
4630 ;; overflow bit, so we must not set CC_NO_OVERFLOW.
4631
4632 ;; On the 68000, this makes faster code in a special case.
4633
4634 (define_insn "ashlsi_17_24"
4635   [(set (match_operand:SI 0 "register_operand" "=d")
4636         (ashift:SI (match_operand:SI 1 "register_operand" "0")
4637                    (match_operand:SI 2 "const_int_operand" "n")))]
4638   "TUNE_68000_10
4639    && INTVAL (operands[2]) > 16
4640    && INTVAL (operands[2]) <= 24"
4641 {
4642   CC_STATUS_INIT;
4643
4644   operands[2] = GEN_INT (INTVAL (operands[2]) - 16);
4645   return "lsl%.w %2,%0\;swap %0\;clr%.w %0";
4646 })
4647
4648 (define_insn "ashlsi3"
4649   [(set (match_operand:SI 0 "register_operand" "=d")
4650         (ashift:SI (match_operand:SI 1 "register_operand" "0")
4651                    (match_operand:SI 2 "general_operand" "dI")))]
4652   ""
4653 {
4654   if (operands[2] == const1_rtx)
4655     {
4656       cc_status.flags = CC_NO_OVERFLOW;
4657       return "add%.l %0,%0";
4658     }
4659   return "lsl%.l %2,%0";
4660 })
4661
4662 (define_insn "ashlhi3"
4663   [(set (match_operand:HI 0 "register_operand" "=d")
4664         (ashift:HI (match_operand:HI 1 "register_operand" "0")
4665                    (match_operand:HI 2 "general_operand" "dI")))]
4666   "!TARGET_COLDFIRE"
4667   "lsl%.w %2,%0")
4668
4669 (define_insn ""
4670   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
4671         (ashift:HI (match_dup 0)
4672                    (match_operand:HI 1 "general_operand" "dI")))]
4673   "!TARGET_COLDFIRE"
4674   "lsl%.w %1,%0")
4675
4676 (define_insn "ashlqi3"
4677   [(set (match_operand:QI 0 "register_operand" "=d")
4678         (ashift:QI (match_operand:QI 1 "register_operand" "0")
4679                    (match_operand:QI 2 "general_operand" "dI")))]
4680   "!TARGET_COLDFIRE"
4681   "lsl%.b %2,%0")
4682
4683 (define_insn ""
4684   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d"))
4685         (ashift:QI (match_dup 0)
4686                    (match_operand:QI 1 "general_operand" "dI")))]
4687   "!TARGET_COLDFIRE"
4688   "lsl%.b %1,%0")
4689
4690 ;; On most 68k models, this makes faster code in a special case.
4691
4692 (define_insn "ashrsi_16"
4693   [(set (match_operand:SI 0 "register_operand" "=d")
4694         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
4695                      (const_int 16)))]
4696   "!TUNE_68060"
4697   "swap %0\;ext%.l %0")
4698
4699 ;; On the 68000, this makes faster code in a special case.
4700
4701 (define_insn ""
4702   [(set (match_operand:SI 0 "register_operand" "=d")
4703         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
4704                      (match_operand:SI 2 "const_int_operand" "n")))]
4705   "TUNE_68000_10
4706    && INTVAL (operands[2]) > 16
4707    && INTVAL (operands[2]) <= 24"
4708 {
4709   operands[2] = GEN_INT (INTVAL (operands[2]) - 16);
4710   return "swap %0\;asr%.w %2,%0\;ext%.l %0";
4711 })
4712
4713 (define_insn "subreghi1ashrdi_const32"
4714   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
4715     (subreg:HI (ashiftrt:DI (match_operand:DI 1 "general_operand" "ro")
4716             (const_int 32)) 6))]
4717   ""
4718 {
4719   if (GET_CODE (operands[1]) != REG)
4720     operands[1] = adjust_address (operands[1], HImode, 2);
4721   return "move%.w %1,%0";
4722 }
4723   [(set_attr "type" "move")])
4724
4725 (define_insn "subregsi1ashrdi_const32"
4726   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
4727     (subreg:SI (ashiftrt:DI (match_operand:DI 1 "general_operand" "ro")
4728             (const_int 32)) 4))]
4729   ""
4730 {
4731   return "move%.l %1,%0";
4732 }
4733   [(set_attr "type" "move_l")])
4734
4735 (define_insn "*ashrdi3_const1"
4736   [(set (match_operand:DI 0 "register_operand" "=d")
4737         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
4738                      (const_int 1)))]
4739   "!TARGET_COLDFIRE"
4740 {
4741   operands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
4742   return "asr%.l #1,%0\;roxr%.l #1,%1";
4743 })
4744
4745 (define_split
4746   [(set (match_operand:DI 0 "register_operand" "")
4747         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
4748                      (const_int 2)))]
4749   "reload_completed && !TARGET_COLDFIRE"
4750   [(set (match_dup 0)
4751         (ashiftrt:DI (match_dup 1) (const_int 1)))
4752    (set (match_dup 0)
4753         (ashiftrt:DI (match_dup 0) (const_int 1)))]
4754   "")
4755
4756 (define_split
4757   [(set (match_operand:DI 0 "register_operand" "")
4758         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
4759                      (const_int 3)))]
4760   "reload_completed && !TARGET_COLDFIRE"
4761   [(set (match_dup 0)
4762         (ashiftrt:DI (match_dup 1) (const_int 2)))
4763    (set (match_dup 0)
4764         (ashiftrt:DI (match_dup 0) (const_int 1)))]
4765   "")
4766
4767 (define_split
4768   [(set (match_operand:DI 0 "register_operand" "")
4769         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
4770                      (const_int 8)))]
4771   "reload_completed && !TARGET_COLDFIRE"
4772   [(set (strict_low_part (subreg:QI (match_dup 0) 7))
4773         (subreg:QI (match_dup 0) 3))
4774    (set (match_dup 2)
4775         (ashiftrt:SI (match_dup 2) (const_int 8)))
4776    (set (match_dup 3)
4777         (rotatert:SI (match_dup 3) (const_int 8)))]
4778 {
4779   operands[2] = gen_highpart (SImode, operands[0]);
4780   operands[3] = gen_lowpart (SImode, operands[0]);
4781 })
4782
4783 (define_split
4784   [(set (match_operand:DI 0 "register_operand" "")
4785         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
4786                      (const_int 16)))]
4787   "reload_completed && !TARGET_COLDFIRE"
4788   [(set (strict_low_part (subreg:HI (match_dup 0) 6))
4789         (subreg:HI (match_dup 0) 2))
4790    (set (match_dup 2)
4791         (rotate:SI (match_dup 2) (const_int 16)))
4792    (set (match_dup 3)
4793         (rotate:SI (match_dup 3) (const_int 16)))
4794    (set (match_dup 2)
4795         (sign_extend:SI (subreg:HI (match_dup 2) 2)))]
4796 {
4797   operands[2] = gen_highpart (SImode, operands[0]);
4798   operands[3] = gen_lowpart (SImode, operands[0]);
4799 })
4800
4801 (define_insn "*ashrdi_const32"
4802   [(set (match_operand:DI 0 "register_operand" "=d")
4803         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_src_operand" "ro")
4804                      (const_int 32)))]
4805   ""
4806 {
4807   CC_STATUS_INIT;
4808   if (TARGET_68020)
4809     return "move%.l %1,%R0\;smi %0\;extb%.l %0";
4810   else
4811     return "move%.l %1,%R0\;smi %0\;ext%.w %0\;ext%.l %0";
4812 })
4813
4814 (define_insn "*ashrdi_const32_mem"
4815   [(set (match_operand:DI 0 "memory_operand" "=o,<")
4816         (ashiftrt:DI (match_operand:DI 1 "nonimmediate_src_operand" "ro,ro")
4817                      (const_int 32)))
4818    (clobber (match_scratch:SI 2 "=d,d"))]
4819   ""
4820 {
4821   CC_STATUS_INIT;
4822   operands[3] = adjust_address (operands[0], SImode,
4823                                 which_alternative == 0 ? 4 : 0);
4824   operands[0] = adjust_address (operands[0], SImode, 0);
4825   if (TARGET_68020 || TARGET_COLDFIRE)
4826     return "move%.l %1,%3\;smi %2\;extb%.l %2\;move%.l %2,%0";
4827   else
4828     return "move%.l %1,%3\;smi %2\;ext%.w %2\;ext%.l %2\;move%.l %2,%0";
4829 })
4830
4831 (define_split
4832   [(set (match_operand:DI 0 "register_operand" "")
4833         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
4834                      (const_int 63)))]
4835   "reload_completed && !TARGET_COLDFIRE"
4836   [(set (match_dup 3)
4837         (ashiftrt:SI (match_dup 3) (const_int 31)))
4838    (set (match_dup 2)
4839         (match_dup 3))]
4840   "split_di(operands, 1, operands + 2, operands + 3);")
4841
4842 ;; The predicate below must be general_operand, because ashrdi3 allows that
4843 (define_insn "ashrdi_const"
4844   [(set (match_operand:DI 0 "register_operand" "=d")
4845         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0")
4846                      (match_operand 2 "const_int_operand" "n")))]
4847   "!TARGET_COLDFIRE
4848     && ((INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 3)
4849         || INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 16
4850         || INTVAL (operands[2]) == 31
4851         || (INTVAL (operands[2]) > 32 && INTVAL (operands[2]) <= 63))"
4852 {
4853   operands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
4854   CC_STATUS_INIT;
4855   if (INTVAL (operands[2]) == 48)
4856     return "swap %0\;ext%.l %0\;move%.l %0,%1\;smi %0\;ext%.w %0";
4857   if (INTVAL (operands[2]) == 31)
4858     return "add%.l %1,%1\;addx%.l %0,%0\;move%.l %0,%1\;subx%.l %0,%0";
4859   if (INTVAL (operands[2]) > 32 && INTVAL (operands[2]) <= 63)
4860     {
4861       operands[2] = GEN_INT (INTVAL (operands[2]) - 32);
4862       output_asm_insn (INTVAL (operands[2]) <= 8 ? "asr%.l %2,%0" :
4863                         "moveq %2,%1\;asr%.l %1,%0", operands);
4864       output_asm_insn ("mov%.l %0,%1\;smi %0", operands);
4865       return INTVAL (operands[2]) >= 15 ? "ext%.w %d0" :
4866              TARGET_68020 ? "extb%.l %0" : "ext%.w %0\;ext%.l %0";
4867     }
4868   return "#";
4869 })
4870
4871 (define_expand "ashrdi3"
4872   [(set (match_operand:DI 0 "register_operand" "")
4873         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
4874                      (match_operand 2 "const_int_operand" "")))]
4875   "!TARGET_COLDFIRE"
4876 {
4877   /* ???  This is a named pattern like this is not allowed to FAIL based
4878      on its operands.  */
4879   if (GET_CODE (operands[2]) != CONST_INT
4880       || ((INTVAL (operands[2]) < 1 || INTVAL (operands[2]) > 3)
4881           && INTVAL (operands[2]) != 8 && INTVAL (operands[2]) != 16
4882           && (INTVAL (operands[2]) < 31 || INTVAL (operands[2]) > 63)))
4883     FAIL;
4884 })
4885
4886 ;; On all 68k models, this makes faster code in a special case.
4887
4888 (define_insn "ashrsi_31"
4889   [(set (match_operand:SI 0 "register_operand" "=d")
4890         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
4891                      (const_int 31)))]
4892   ""
4893 {
4894   return "add%.l %0,%0\;subx%.l %0,%0";
4895 })
4896
4897 (define_insn "ashrsi3"
4898   [(set (match_operand:SI 0 "register_operand" "=d")
4899         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
4900                      (match_operand:SI 2 "general_operand" "dI")))]
4901   ""
4902   "asr%.l %2,%0"
4903   [(set_attr "type" "shift")
4904    (set_attr "opy" "2")])
4905
4906 (define_insn "ashrhi3"
4907   [(set (match_operand:HI 0 "register_operand" "=d")
4908         (ashiftrt:HI (match_operand:HI 1 "register_operand" "0")
4909                      (match_operand:HI 2 "general_operand" "dI")))]
4910   "!TARGET_COLDFIRE"
4911   "asr%.w %2,%0")
4912
4913 (define_insn ""
4914   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
4915         (ashiftrt:HI (match_dup 0)
4916                      (match_operand:HI 1 "general_operand" "dI")))]
4917   "!TARGET_COLDFIRE"
4918   "asr%.w %1,%0")
4919
4920 (define_insn "ashrqi3"
4921   [(set (match_operand:QI 0 "register_operand" "=d")
4922         (ashiftrt:QI (match_operand:QI 1 "register_operand" "0")
4923                      (match_operand:QI 2 "general_operand" "dI")))]
4924   "!TARGET_COLDFIRE"
4925   "asr%.b %2,%0")
4926
4927 (define_insn ""
4928   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d"))
4929         (ashiftrt:QI (match_dup 0)
4930                      (match_operand:QI 1 "general_operand" "dI")))]
4931   "!TARGET_COLDFIRE"
4932   "asr%.b %1,%0")
4933 \f
4934 ;; logical shift instructions
4935
4936 ;; commented out because of reload problems in 950612-1.c
4937 ;;(define_insn ""
4938 ;;        [(set (cc0)
4939 ;;            (subreg:SI (lshiftrt:DI (match_operand:DI 0 "general_operand" "ro")
4940 ;;                    (const_int 32)) 4))
4941 ;;        (set (match_operand:SI 1 "nonimmediate_operand" "=dm")
4942 ;;            (subreg:SI (lshiftrt:DI (match_dup 0)
4943 ;;                    (const_int 32)) 4))]
4944 ;;  ""
4945 ;;{
4946 ;;  return "move%.l %0,%1";
4947 ;;})
4948 ;;
4949 ;;(define_insn ""
4950 ;;        [(set (cc0)
4951 ;;            (subreg:SI (lshiftrt:DI (match_operand:DI 0 "general_operand" "ro")
4952 ;;                    (const_int 32)) 0))
4953 ;;        (set (match_operand:DI 1 "nonimmediate_operand" "=do")
4954 ;;            (lshiftrt:DI (match_dup 0)
4955 ;;                (const_int 32)))]
4956 ;;  ""
4957 ;;{
4958 ;;  if (GET_CODE (operands[1]) == REG)
4959 ;;    operands[2] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
4960 ;;  else
4961 ;;    operands[2] = adjust_address (operands[1], SImode, 4);
4962 ;;  return "move%.l %0,%2\;clr%.l %1";
4963 ;;})
4964
4965 (define_insn "subreg1lshrdi_const32"
4966   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
4967     (subreg:SI (lshiftrt:DI (match_operand:DI 1 "general_operand" "ro")
4968             (const_int 32)) 4))]
4969   ""
4970   "move%.l %1,%0"
4971   [(set_attr "type" "move_l")])
4972
4973 (define_insn "*lshrdi3_const1"
4974   [(set (match_operand:DI 0 "register_operand" "=d")
4975         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
4976                      (const_int 1)))]
4977   "!TARGET_COLDFIRE"
4978   "lsr%.l #1,%0\;roxr%.l #1,%R0")
4979
4980 (define_split
4981   [(set (match_operand:DI 0 "register_operand" "")
4982         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
4983                      (const_int 2)))]
4984   "reload_completed && !TARGET_COLDFIRE"
4985   [(set (match_dup 0)
4986         (lshiftrt:DI (match_dup 1) (const_int 1)))
4987    (set (match_dup 0)
4988         (lshiftrt:DI (match_dup 0) (const_int 1)))]
4989   "")
4990
4991 (define_split
4992   [(set (match_operand:DI 0 "register_operand" "")
4993         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
4994                      (const_int 3)))]
4995   "reload_completed && !TARGET_COLDFIRE"
4996   [(set (match_dup 0)
4997         (lshiftrt:DI (match_dup 1) (const_int 2)))
4998    (set (match_dup 0)
4999         (lshiftrt:DI (match_dup 0) (const_int 1)))]
5000   "")
5001
5002 (define_split
5003   [(set (match_operand:DI 0 "register_operand" "")
5004         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
5005                      (const_int 8)))]
5006   "reload_completed && !TARGET_COLDFIRE"
5007   [(set (strict_low_part (subreg:QI (match_dup 0) 7))
5008         (subreg:QI (match_dup 0) 3))
5009    (set (match_dup 2)
5010         (lshiftrt:SI (match_dup 2) (const_int 8)))
5011    (set (match_dup 3)
5012         (rotatert:SI (match_dup 3) (const_int 8)))]
5013 {
5014   operands[2] = gen_highpart (SImode, operands[0]);
5015   operands[3] = gen_lowpart (SImode, operands[0]);
5016 })
5017
5018 (define_split
5019   [(set (match_operand:DI 0 "register_operand" "")
5020         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
5021                      (const_int 16)))]
5022   "reload_completed && !TARGET_COLDFIRE"
5023   [(set (strict_low_part (subreg:HI (match_dup 0) 6))
5024         (subreg:HI (match_dup 0) 2))
5025    (set (strict_low_part (subreg:HI (match_dup 0) 2))
5026         (const_int 0))
5027    (set (match_dup 3)
5028         (rotate:SI (match_dup 3) (const_int 16)))
5029    (set (match_dup 2)
5030         (rotate:SI (match_dup 2) (const_int 16)))]
5031 {
5032   operands[2] = gen_highpart (SImode, operands[0]);
5033   operands[3] = gen_lowpart (SImode, operands[0]);
5034 })
5035
5036 (define_split
5037   [(set (match_operand:DI 0 "pre_dec_operand" "")
5038         (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "")
5039                      (const_int 32)))]
5040   "reload_completed"
5041   [(set (match_dup 0) (match_dup 1))
5042    (set (match_dup 0) (const_int 0))]
5043 {
5044   operands[0] = adjust_address(operands[0], SImode, 0);
5045   operands[1] = gen_highpart(SImode, operands[1]);
5046 })
5047
5048 (define_split
5049   [(set (match_operand:DI 0 "post_inc_operand" "")
5050         (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "")
5051                      (const_int 32)))]
5052   "reload_completed"
5053   [(set (match_dup 0) (const_int 0))
5054    (set (match_dup 0) (match_dup 1))]
5055 {
5056   operands[0] = adjust_address(operands[0], SImode, 0);
5057   operands[1] = gen_highpart(SImode, operands[1]);
5058 })
5059
5060 (define_split
5061   [(set (match_operand:DI 0 "nonimmediate_operand" "")
5062         (lshiftrt:DI (match_operand:DI 1 "nonimmediate_operand" "")
5063                      (const_int 32)))]
5064   "reload_completed"
5065   [(set (match_dup 2) (match_dup 5))
5066    (set (match_dup 4) (const_int 0))]
5067   "split_di(operands, 2, operands + 2, operands + 4);")
5068
5069 (define_insn "*lshrdi_const32"
5070   [(set (match_operand:DI 0 "nonimmediate_operand" "=ro<>")
5071         (lshiftrt:DI (match_operand:DI 1 "general_operand" "ro")
5072                      (const_int 32)))]
5073   ""
5074   "#")
5075
5076 (define_split
5077   [(set (match_operand:DI 0 "register_operand" "")
5078         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
5079                      (match_operand 2 "const_int_operand" "")))]
5080   "reload_completed && !TARGET_COLDFIRE
5081    && INTVAL (operands[2]) > 32 && INTVAL (operands[2]) <= 40"
5082   [(set (match_dup 3) (lshiftrt:SI (match_dup 3) (match_dup 2)))
5083    (set (match_dup 4) (match_dup 3))
5084    (set (match_dup 3) (const_int 0))]
5085 {
5086   operands[2] = GEN_INT (INTVAL (operands[2]) - 32);
5087   operands[3] = gen_highpart (SImode, operands[0]);
5088   operands[4] = gen_lowpart (SImode, operands[0]);
5089 })
5090
5091 (define_split
5092   [(set (match_operand:DI 0 "register_operand" "")
5093         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
5094                      (const_int 48)))]
5095   "reload_completed"
5096   [(set (match_dup 3) (match_dup 2))
5097    (set (strict_low_part (subreg:HI (match_dup 0) 6))
5098         (const_int 0))
5099    (set (match_dup 2) (const_int 0))
5100    (set (match_dup 3)
5101         (rotate:SI (match_dup 3) (const_int 16)))]
5102 {
5103   operands[2] = gen_highpart (SImode, operands[0]);
5104   operands[3] = gen_lowpart (SImode, operands[0]);
5105 })
5106
5107 (define_split
5108   [(set (match_operand:DI 0 "register_operand" "")
5109         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
5110                      (match_operand 2 "const_int_operand" "")))]
5111   "reload_completed && !TARGET_COLDFIRE
5112    && INTVAL (operands[2]) > 40 && INTVAL (operands[2]) <= 62"
5113   [(set (match_dup 4) (match_dup 2))
5114    (set (match_dup 3) (lshiftrt:SI (match_dup 3) (match_dup 4)))
5115    (set (match_dup 4) (match_dup 3))
5116    (set (match_dup 3) (const_int 0))]
5117 {
5118   operands[2] = GEN_INT (INTVAL (operands[2]) - 32);
5119   operands[3] = gen_highpart (SImode, operands[0]);
5120   operands[4] = gen_lowpart (SImode, operands[0]);
5121 })
5122
5123 (define_insn "*lshrdi_const63"
5124   [(set (match_operand:DI 0 "register_operand" "=d")
5125         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
5126                      (const_int 63)))]
5127   ""
5128   "add%.l %0,%0\;clr%.l %0\;clr%.l %R1\;addx%.l %R1,%R1")
5129
5130 (define_insn "*lshrdi3_const"
5131   [(set (match_operand:DI 0 "register_operand" "=d")
5132         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0")
5133                      (match_operand 2 "const_int_operand" "n")))]
5134   "(!TARGET_COLDFIRE
5135     && ((INTVAL (operands[2]) >= 2 && INTVAL (operands[2]) <= 3)
5136          || INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 16
5137          || (INTVAL (operands[2]) > 32 && INTVAL (operands[2]) <= 63)))"
5138   "#")
5139
5140 (define_expand "lshrdi3"
5141   [(set (match_operand:DI 0 "register_operand" "")
5142         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
5143                      (match_operand 2 "const_int_operand" "")))]
5144   "!TARGET_COLDFIRE"
5145 {
5146   /* ???  This is a named pattern like this is not allowed to FAIL based
5147      on its operands.  */
5148   if (GET_CODE (operands[2]) != CONST_INT
5149       || ((INTVAL (operands[2]) < 1 || INTVAL (operands[2]) > 3)
5150           && INTVAL (operands[2]) != 8 && INTVAL (operands[2]) != 16
5151           && (INTVAL (operands[2]) < 32 || INTVAL (operands[2]) > 63)))
5152     FAIL;
5153 })
5154
5155 ;; On all 68k models, this makes faster code in a special case.
5156
5157 (define_insn "lshrsi_31"
5158   [(set (match_operand:SI 0 "register_operand" "=d")
5159         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
5160                      (const_int 31)))]
5161   ""
5162 {
5163   return "add%.l %0,%0\;subx%.l %0,%0\;neg%.l %0";
5164 })
5165
5166 ;; On most 68k models, this makes faster code in a special case.
5167
5168 (define_insn "lshrsi_16"
5169   [(set (match_operand:SI 0 "register_operand" "=d")
5170         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
5171                      (const_int 16)))]
5172   "!TUNE_68060"
5173 {
5174   CC_STATUS_INIT;
5175   return "clr%.w %0\;swap %0";
5176 })
5177
5178 ;; On the 68000, this makes faster code in a special case.
5179
5180 (define_insn "lshrsi_17_24"
5181   [(set (match_operand:SI 0 "register_operand" "=d")
5182         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
5183                      (match_operand:SI 2 "const_int_operand" "n")))]
5184   "TUNE_68000_10
5185    && INTVAL (operands[2]) > 16
5186    && INTVAL (operands[2]) <= 24"
5187 {
5188   /* I think lsr%.w sets the CC properly.  */
5189   operands[2] = GEN_INT (INTVAL (operands[2]) - 16);
5190   return "clr%.w %0\;swap %0\;lsr%.w %2,%0";
5191 })
5192
5193 (define_insn "lshrsi3"
5194   [(set (match_operand:SI 0 "register_operand" "=d")
5195         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
5196                      (match_operand:SI 2 "general_operand" "dI")))]
5197   ""
5198   "lsr%.l %2,%0"
5199   [(set_attr "type" "shift")
5200    (set_attr "opy" "2")])
5201
5202 (define_insn "lshrhi3"
5203   [(set (match_operand:HI 0 "register_operand" "=d")
5204         (lshiftrt:HI (match_operand:HI 1 "register_operand" "0")
5205                      (match_operand:HI 2 "general_operand" "dI")))]
5206   "!TARGET_COLDFIRE"
5207   "lsr%.w %2,%0")
5208
5209 (define_insn ""
5210   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
5211         (lshiftrt:HI (match_dup 0)
5212                      (match_operand:HI 1 "general_operand" "dI")))]
5213   "!TARGET_COLDFIRE"
5214   "lsr%.w %1,%0")
5215
5216 (define_insn "lshrqi3"
5217   [(set (match_operand:QI 0 "register_operand" "=d")
5218         (lshiftrt:QI (match_operand:QI 1 "register_operand" "0")
5219                      (match_operand:QI 2 "general_operand" "dI")))]
5220   "!TARGET_COLDFIRE"
5221   "lsr%.b %2,%0")
5222
5223 (define_insn ""
5224   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d"))
5225         (lshiftrt:QI (match_dup 0)
5226                      (match_operand:QI 1 "general_operand" "dI")))]
5227   "!TARGET_COLDFIRE"
5228   "lsr%.b %1,%0")
5229 \f
5230 ;; rotate instructions
5231
5232 (define_insn "rotlsi3"
5233   [(set (match_operand:SI 0 "register_operand" "=d")
5234         (rotate:SI (match_operand:SI 1 "register_operand" "0")
5235                    (match_operand:SI 2 "general_operand" "dINO")))]
5236   "!TARGET_COLDFIRE"
5237 {
5238   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) == 16)
5239     return "swap %0";
5240   else if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 16)
5241     {
5242       operands[2] = GEN_INT (32 - INTVAL (operands[2]));
5243       return "ror%.l %2,%0";
5244     }
5245   else
5246     return "rol%.l %2,%0";
5247 })
5248
5249 (define_insn "rotlhi3"
5250   [(set (match_operand:HI 0 "register_operand" "=d")
5251         (rotate:HI (match_operand:HI 1 "register_operand" "0")
5252                    (match_operand:HI 2 "general_operand" "dIP")))]
5253   "!TARGET_COLDFIRE"
5254 {
5255   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 8)
5256     {
5257       operands[2] = GEN_INT (16 - INTVAL (operands[2]));
5258       return "ror%.w %2,%0";
5259     }
5260   else
5261     return "rol%.w %2,%0";
5262 })
5263
5264 (define_insn ""
5265   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
5266         (rotate:HI (match_dup 0)
5267                    (match_operand:HI 1 "general_operand" "dIP")))]
5268   "!TARGET_COLDFIRE"
5269 {
5270   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 8)
5271     {
5272       operands[2] = GEN_INT (16 - INTVAL (operands[2]));
5273       return "ror%.w %2,%0";
5274     }
5275   else
5276     return "rol%.w %2,%0";
5277 })
5278
5279 (define_insn "rotlqi3"
5280   [(set (match_operand:QI 0 "register_operand" "=d")
5281         (rotate:QI (match_operand:QI 1 "register_operand" "0")
5282                    (match_operand:QI 2 "general_operand" "dI")))]
5283   "!TARGET_COLDFIRE"
5284 {
5285   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 4)
5286     {
5287       operands[2] = GEN_INT (8 - INTVAL (operands[2]));
5288       return "ror%.b %2,%0";
5289     }
5290   else
5291     return "rol%.b %2,%0";
5292 })
5293
5294 (define_insn ""
5295   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d"))
5296         (rotate:QI (match_dup 0)
5297                    (match_operand:QI 1 "general_operand" "dI")))]
5298   "!TARGET_COLDFIRE"
5299 {
5300   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 4)
5301     {
5302       operands[2] = GEN_INT (8 - INTVAL (operands[2]));
5303       return "ror%.b %2,%0";
5304     }
5305   else
5306     return "rol%.b %2,%0";
5307 })
5308
5309 (define_insn "rotrsi3"
5310   [(set (match_operand:SI 0 "register_operand" "=d")
5311         (rotatert:SI (match_operand:SI 1 "register_operand" "0")
5312                      (match_operand:SI 2 "general_operand" "dI")))]
5313   "!TARGET_COLDFIRE"
5314   "ror%.l %2,%0")
5315
5316 (define_insn "rotrhi3"
5317   [(set (match_operand:HI 0 "register_operand" "=d")
5318         (rotatert:HI (match_operand:HI 1 "register_operand" "0")
5319                      (match_operand:HI 2 "general_operand" "dI")))]
5320   "!TARGET_COLDFIRE"
5321   "ror%.w %2,%0")
5322
5323 (define_insn ""
5324   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
5325         (rotatert:HI (match_dup 0)
5326                      (match_operand:HI 1 "general_operand" "dI")))]
5327   "!TARGET_COLDFIRE"
5328   "ror%.w %1,%0")
5329
5330 (define_insn "rotrqi3"
5331   [(set (match_operand:QI 0 "register_operand" "=d")
5332         (rotatert:QI (match_operand:QI 1 "register_operand" "0")
5333                      (match_operand:QI 2 "general_operand" "dI")))]
5334   "!TARGET_COLDFIRE"
5335   "ror%.b %2,%0")
5336
5337 (define_insn ""
5338   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d"))
5339         (rotatert:QI (match_dup 0)
5340                      (match_operand:QI 1 "general_operand" "dI")))]
5341   "!TARGET_COLDFIRE"
5342   "ror%.b %1,%0")
5343 \f
5344
5345 ;; Bit set/clear in memory byte.
5346
5347 ;; set bit, bit number is int
5348 (define_insn "bsetmemqi"
5349   [(set (match_operand:QI 0 "memory_operand" "+m")
5350         (ior:QI (subreg:QI (ashift:SI (const_int 1)
5351                 (match_operand:SI 1 "general_operand" "d")) 3)
5352         (match_dup 0)))]
5353   ""
5354 {
5355   CC_STATUS_INIT;
5356   return "bset %1,%0";
5357 }
5358   [(set_attr "type" "bitrw")])
5359
5360 ;; set bit, bit number is (sign/zero)_extended from HImode/QImode
5361 (define_insn "*bsetmemqi_ext"
5362   [(set (match_operand:QI 0 "memory_operand" "+m")
5363         (ior:QI (subreg:QI (ashift:SI (const_int 1)
5364             (match_operator:SI 2 "extend_operator"
5365                 [(match_operand 1 "general_operand" "d")])) 3)
5366         (match_dup 0)))]
5367   ""
5368 {
5369   CC_STATUS_INIT;
5370   return "bset %1,%0";
5371 }
5372   [(set_attr "type" "bitrw")])
5373
5374 ;; clear bit, bit number is int
5375 (define_insn "bclrmemqi"
5376   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+m")
5377         (const_int 1)
5378         (minus:SI (const_int 7)
5379             (match_operand:SI 1 "general_operand" "d")))
5380     (const_int 0))]
5381   ""
5382 {
5383   CC_STATUS_INIT;
5384   return "bclr %1,%0";
5385 }
5386   [(set_attr "type" "bitrw")])
5387
5388 ;; clear bit, bit number is (sign/zero)_extended from HImode/QImode
5389 (define_insn "*bclrmemqi_ext"
5390   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+m")
5391         (const_int 1)
5392         (minus:SI (const_int 7)
5393             (match_operator:SI 2 "extend_operator"
5394                 [(match_operand 1 "general_operand" "d")])))
5395     (const_int 0))]
5396   ""
5397 {
5398   CC_STATUS_INIT;
5399   return "bclr %1,%0";
5400 }
5401   [(set_attr "type" "bitrw")])
5402
5403 ;; Special cases of bit-field insns which we should
5404 ;; recognize in preference to the general case.
5405 ;; These handle aligned 8-bit and 16-bit fields,
5406 ;; which can usually be done with move instructions.
5407
5408 ;
5409 ; Special case for 32-bit field in memory.  This only occurs when 32-bit
5410 ; alignment of structure members is specified.
5411 ;
5412 ; The move is allowed to be odd byte aligned, because that's still faster
5413 ; than an odd byte aligned bit-field instruction.
5414 ;
5415 (define_insn ""
5416   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+o")
5417                          (const_int 32)
5418                          (match_operand:SI 1 "const_int_operand" "n"))
5419         (match_operand:SI 2 "general_src_operand" "rmSi"))]
5420   "TARGET_68020 && TARGET_BITFIELD
5421    && (INTVAL (operands[1]) % 8) == 0
5422    && ! mode_dependent_address_p (XEXP (operands[0], 0))"
5423 {
5424   operands[0]
5425     = adjust_address (operands[0], SImode, INTVAL (operands[1]) / 8);
5426
5427   return "move%.l %2,%0";
5428 })
5429
5430 (define_insn ""
5431   [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+do")
5432                          (match_operand:SI 1 "const_int_operand" "n")
5433                          (match_operand:SI 2 "const_int_operand" "n"))
5434         (match_operand:SI 3 "register_operand" "d"))]
5435   "TARGET_68020 && TARGET_BITFIELD
5436    && (INTVAL (operands[1]) == 8 || INTVAL (operands[1]) == 16)
5437    && INTVAL (operands[2]) % INTVAL (operands[1]) == 0
5438    && (GET_CODE (operands[0]) == REG
5439        || ! mode_dependent_address_p (XEXP (operands[0], 0)))"
5440 {
5441   if (REG_P (operands[0]))
5442     {
5443       if (INTVAL (operands[1]) + INTVAL (operands[2]) != 32)
5444         return "bfins %3,%0{%b2:%b1}";
5445     }
5446   else
5447     operands[0] = adjust_address (operands[0],
5448                                   INTVAL (operands[1]) == 8 ? QImode : HImode,
5449                                   INTVAL (operands[2]) / 8);
5450
5451   if (GET_CODE (operands[3]) == MEM)
5452     operands[3] = adjust_address (operands[3],
5453                                   INTVAL (operands[1]) == 8 ? QImode : HImode,
5454                                   (32 - INTVAL (operands[1])) / 8);
5455
5456   if (INTVAL (operands[1]) == 8)
5457     return "move%.b %3,%0";
5458   return "move%.w %3,%0";
5459 })
5460
5461
5462 ;
5463 ; Special case for 32-bit field in memory.  This only occurs when 32-bit
5464 ; alignment of structure members is specified.
5465 ;
5466 ; The move is allowed to be odd byte aligned, because that's still faster
5467 ; than an odd byte aligned bit-field instruction.
5468 ;
5469 (define_insn ""
5470   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
5471         (zero_extract:SI (match_operand:QI 1 "memory_src_operand" "oS")
5472                          (const_int 32)
5473                          (match_operand:SI 2 "const_int_operand" "n")))]
5474   "TARGET_68020 && TARGET_BITFIELD
5475    && (INTVAL (operands[2]) % 8) == 0
5476    && ! mode_dependent_address_p (XEXP (operands[1], 0))"
5477 {
5478   operands[1]
5479     = adjust_address (operands[1], SImode, INTVAL (operands[2]) / 8);
5480
5481   return "move%.l %1,%0";
5482 })
5483
5484 (define_insn ""
5485   [(set (match_operand:SI 0 "nonimmediate_operand" "=&d")
5486         (zero_extract:SI (match_operand:SI 1 "register_operand" "do")
5487                          (match_operand:SI 2 "const_int_operand" "n")
5488                          (match_operand:SI 3 "const_int_operand" "n")))]
5489   "TARGET_68020 && TARGET_BITFIELD
5490    && (INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 16)
5491    && INTVAL (operands[3]) % INTVAL (operands[2]) == 0
5492    && (GET_CODE (operands[1]) == REG
5493        || ! mode_dependent_address_p (XEXP (operands[1], 0)))"
5494 {
5495   cc_status.flags |= CC_NOT_NEGATIVE;
5496   if (REG_P (operands[1]))
5497     {
5498       if (INTVAL (operands[2]) + INTVAL (operands[3]) != 32)
5499         return "bfextu %1{%b3:%b2},%0";
5500     }
5501   else
5502     operands[1]
5503       = adjust_address (operands[1], SImode, INTVAL (operands[3]) / 8);
5504
5505   output_asm_insn ("clr%.l %0", operands);
5506   if (GET_CODE (operands[0]) == MEM)
5507     operands[0] = adjust_address (operands[0],
5508                                   INTVAL (operands[2]) == 8 ? QImode : HImode,
5509                                   (32 - INTVAL (operands[1])) / 8);
5510
5511   if (INTVAL (operands[2]) == 8)
5512     return "move%.b %1,%0";
5513   return "move%.w %1,%0";
5514 })
5515
5516 ;
5517 ; Special case for 32-bit field in memory.  This only occurs when 32-bit
5518 ; alignment of structure members is specified.
5519 ;
5520 ; The move is allowed to be odd byte aligned, because that's still faster
5521 ; than an odd byte aligned bit-field instruction.
5522 ;
5523 (define_insn ""
5524   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
5525         (sign_extract:SI (match_operand:QI 1 "memory_src_operand" "oS")
5526                          (const_int 32)
5527                          (match_operand:SI 2 "const_int_operand" "n")))]
5528   "TARGET_68020 && TARGET_BITFIELD
5529    && (INTVAL (operands[2]) % 8) == 0
5530    && ! mode_dependent_address_p (XEXP (operands[1], 0))"
5531 {
5532   operands[1]
5533     = adjust_address (operands[1], SImode, INTVAL (operands[2]) / 8);
5534
5535   return "move%.l %1,%0";
5536 })
5537
5538 (define_insn ""
5539   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
5540         (sign_extract:SI (match_operand:SI 1 "register_operand" "do")
5541                          (match_operand:SI 2 "const_int_operand" "n")
5542                          (match_operand:SI 3 "const_int_operand" "n")))]
5543   "TARGET_68020 && TARGET_BITFIELD
5544    && (INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 16)
5545    && INTVAL (operands[3]) % INTVAL (operands[2]) == 0
5546    && (GET_CODE (operands[1]) == REG
5547        || ! mode_dependent_address_p (XEXP (operands[1], 0)))"
5548 {
5549   if (REG_P (operands[1]))
5550     {
5551       if (INTVAL (operands[2]) + INTVAL (operands[3]) != 32)
5552         return "bfexts %1{%b3:%b2},%0";
5553     }
5554   else
5555     operands[1]
5556       = adjust_address (operands[1],
5557                         INTVAL (operands[2]) == 8 ? QImode : HImode,
5558                         INTVAL (operands[3]) / 8);
5559
5560   if (INTVAL (operands[2]) == 8)
5561     return "move%.b %1,%0\;extb%.l %0";
5562   return "move%.w %1,%0\;ext%.l %0";
5563 })
5564 \f
5565 ;; Bit-field instructions, general cases.
5566 ;; "o,d" constraint causes a nonoffsettable memref to match the "o"
5567 ;; so that its address is reloaded.
5568
5569 (define_expand "extv"
5570   [(set (match_operand:SI 0 "register_operand" "")
5571         (sign_extract:SI (match_operand:SI 1 "general_operand" "")
5572                          (match_operand:SI 2 "const_int_operand" "")
5573                          (match_operand:SI 3 "const_int_operand" "")))]
5574   "TARGET_68020 && TARGET_BITFIELD"
5575   "")
5576
5577 (define_insn ""
5578   [(set (match_operand:SI 0 "register_operand" "=d")
5579         (sign_extract:SI (match_operand:QI 1 "memory_operand" "o")
5580                          (match_operand:SI 2 "nonmemory_operand" "dn")
5581                          (match_operand:SI 3 "nonmemory_operand" "dn")))]
5582   "TARGET_68020 && TARGET_BITFIELD"
5583   "bfexts %1{%b3:%b2},%0")
5584
5585 (define_expand "extzv"
5586   [(set (match_operand:SI 0 "register_operand" "")
5587         (zero_extract:SI (match_operand:SI 1 "general_operand" "")
5588                          (match_operand:SI 2 "const_int_operand" "")
5589                          (match_operand:SI 3 "const_int_operand" "")))]
5590   "TARGET_68020 && TARGET_BITFIELD"
5591   "")
5592
5593 (define_insn ""
5594   [(set (match_operand:SI 0 "register_operand" "=d")
5595         (zero_extract:SI (match_operand:QI 1 "memory_operand" "o")
5596                          (match_operand:SI 2 "nonmemory_operand" "dn")
5597                          (match_operand:SI 3 "nonmemory_operand" "dn")))]
5598   "TARGET_68020 && TARGET_BITFIELD"
5599 {
5600   if (GET_CODE (operands[2]) == CONST_INT)
5601     {
5602       if (INTVAL (operands[2]) != 32)
5603         cc_status.flags |= CC_NOT_NEGATIVE;
5604     }
5605   else
5606     {
5607       CC_STATUS_INIT;
5608     }
5609   return "bfextu %1{%b3:%b2},%0";
5610 })
5611
5612 (define_insn ""
5613   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+o")
5614                          (match_operand:SI 1 "nonmemory_operand" "dn")
5615                          (match_operand:SI 2 "nonmemory_operand" "dn"))
5616         (xor:SI (zero_extract:SI (match_dup 0) (match_dup 1) (match_dup 2))
5617                 (match_operand 3 "const_int_operand" "n")))]
5618   "TARGET_68020 && TARGET_BITFIELD
5619    && (INTVAL (operands[3]) == -1
5620        || (GET_CODE (operands[1]) == CONST_INT
5621            && (~ INTVAL (operands[3]) & ((1 << INTVAL (operands[1]))- 1)) == 0))"
5622 {
5623   CC_STATUS_INIT;
5624   return "bfchg %0{%b2:%b1}";
5625 })
5626
5627 (define_insn ""
5628   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+o")
5629                          (match_operand:SI 1 "nonmemory_operand" "dn")
5630                          (match_operand:SI 2 "nonmemory_operand" "dn"))
5631         (const_int 0))]
5632   "TARGET_68020 && TARGET_BITFIELD"
5633 {
5634   CC_STATUS_INIT;
5635   return "bfclr %0{%b2:%b1}";
5636 })
5637
5638 (define_insn ""
5639   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+o")
5640                          (match_operand:SI 1 "general_operand" "dn")
5641                          (match_operand:SI 2 "general_operand" "dn"))
5642         (const_int -1))]
5643   "TARGET_68020 && TARGET_BITFIELD"
5644 {
5645   CC_STATUS_INIT;
5646   return "bfset %0{%b2:%b1}";
5647 })
5648
5649 (define_expand "insv"
5650   [(set (zero_extract:SI (match_operand:SI 0 "nonimmediate_operand" "")
5651                          (match_operand:SI 1 "const_int_operand" "")
5652                          (match_operand:SI 2 "const_int_operand" ""))
5653         (match_operand:SI 3 "register_operand" ""))]
5654   "TARGET_68020 && TARGET_BITFIELD"
5655   "")
5656
5657 (define_insn ""
5658   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+o")
5659                          (match_operand:SI 1 "nonmemory_operand" "dn")
5660                          (match_operand:SI 2 "nonmemory_operand" "dn"))
5661         (match_operand:SI 3 "register_operand" "d"))]
5662   "TARGET_68020 && TARGET_BITFIELD"
5663   "bfins %3,%0{%b2:%b1}")
5664
5665 ;; Now recognize bit-field insns that operate on registers
5666 ;; (or at least were intended to do so).
5667
5668 (define_insn ""
5669   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
5670         (sign_extract:SI (match_operand:SI 1 "register_operand" "d")
5671                          (match_operand:SI 2 "const_int_operand" "n")
5672                          (match_operand:SI 3 "const_int_operand" "n")))]
5673   "TARGET_68020 && TARGET_BITFIELD"
5674   "bfexts %1{%b3:%b2},%0")
5675
5676 (define_insn ""
5677   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
5678         (zero_extract:SI (match_operand:SI 1 "register_operand" "d")
5679                          (match_operand:SI 2 "const_int_operand" "n")
5680                          (match_operand:SI 3 "const_int_operand" "n")))]
5681   "TARGET_68020 && TARGET_BITFIELD"
5682 {
5683   if (GET_CODE (operands[2]) == CONST_INT)
5684     {
5685       if (INTVAL (operands[2]) != 32)
5686         cc_status.flags |= CC_NOT_NEGATIVE;
5687     }
5688   else
5689     {
5690       CC_STATUS_INIT;
5691     }
5692   return "bfextu %1{%b3:%b2},%0";
5693 })
5694
5695 (define_insn ""
5696   [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+d")
5697                          (match_operand:SI 1 "const_int_operand" "n")
5698                          (match_operand:SI 2 "const_int_operand" "n"))
5699         (const_int 0))]
5700   "TARGET_68020 && TARGET_BITFIELD"
5701 {
5702   CC_STATUS_INIT;
5703   return "bfclr %0{%b2:%b1}";
5704 })
5705
5706 (define_insn ""
5707   [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+d")
5708                          (match_operand:SI 1 "const_int_operand" "n")
5709                          (match_operand:SI 2 "const_int_operand" "n"))
5710         (const_int -1))]
5711   "TARGET_68020 && TARGET_BITFIELD"
5712 {
5713   CC_STATUS_INIT;
5714   return "bfset %0{%b2:%b1}";
5715 })
5716
5717 (define_insn ""
5718   [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+d")
5719                          (match_operand:SI 1 "const_int_operand" "n")
5720                          (match_operand:SI 2 "const_int_operand" "n"))
5721         (match_operand:SI 3 "register_operand" "d"))]
5722   "TARGET_68020 && TARGET_BITFIELD"
5723 {
5724 #if 0
5725   /* These special cases are now recognized by a specific pattern.  */
5726   if (GET_CODE (operands[1]) == CONST_INT && GET_CODE (operands[2]) == CONST_INT
5727       && INTVAL (operands[1]) == 16 && INTVAL (operands[2]) == 16)
5728     return "move%.w %3,%0";
5729   if (GET_CODE (operands[1]) == CONST_INT && GET_CODE (operands[2]) == CONST_INT
5730       && INTVAL (operands[1]) == 24 && INTVAL (operands[2]) == 8)
5731     return "move%.b %3,%0";
5732 #endif
5733   return "bfins %3,%0{%b2:%b1}";
5734 })
5735 \f
5736 ;; Special patterns for optimizing bit-field instructions.
5737
5738 (define_insn ""
5739   [(set (cc0)
5740         (zero_extract:SI (match_operand:QI 0 "memory_operand" "o")
5741                          (match_operand:SI 1 "const_int_operand" "n")
5742                          (match_operand:SI 2 "general_operand" "dn")))]
5743   "TARGET_68020 && TARGET_BITFIELD"
5744 {
5745   if (operands[1] == const1_rtx
5746       && GET_CODE (operands[2]) == CONST_INT)
5747     {
5748       int width = GET_CODE (operands[0]) == REG ? 31 : 7;
5749       return output_btst (operands,
5750                           GEN_INT (width - INTVAL (operands[2])),
5751                           operands[0], insn, 1000);
5752       /* Pass 1000 as SIGNPOS argument so that btst will
5753          not think we are testing the sign bit for an `and'
5754          and assume that nonzero implies a negative result.  */
5755     }
5756   if (INTVAL (operands[1]) != 32)
5757     cc_status.flags = CC_NOT_NEGATIVE;
5758   return "bftst %0{%b2:%b1}";
5759 })
5760
5761
5762 ;;; now handle the register cases
5763 (define_insn ""
5764   [(set (cc0)
5765         (zero_extract:SI (match_operand:SI 0 "register_operand" "d")
5766                          (match_operand:SI 1 "const_int_operand" "n")
5767                          (match_operand:SI 2 "general_operand" "dn")))]
5768   "TARGET_68020 && TARGET_BITFIELD"
5769 {
5770   if (operands[1] == const1_rtx
5771       && GET_CODE (operands[2]) == CONST_INT)
5772     {
5773       int width = GET_CODE (operands[0]) == REG ? 31 : 7;
5774       return output_btst (operands, GEN_INT (width - INTVAL (operands[2])),
5775                           operands[0], insn, 1000);
5776       /* Pass 1000 as SIGNPOS argument so that btst will
5777          not think we are testing the sign bit for an `and'
5778          and assume that nonzero implies a negative result.  */
5779     }
5780   if (INTVAL (operands[1]) != 32)
5781     cc_status.flags = CC_NOT_NEGATIVE;
5782   return "bftst %0{%b2:%b1}";
5783 })
5784 \f
5785 (define_insn "scc0_di"
5786   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
5787     (match_operator 1 "valid_dbcc_comparison_p"
5788       [(match_operand:DI 2 "general_operand" "ro") (const_int 0)]))]
5789   "! TARGET_COLDFIRE"
5790 {
5791   return output_scc_di (operands[1], operands[2], const0_rtx, operands[0]);
5792 })
5793
5794 (define_insn "scc0_di_5200"
5795   [(set (match_operand:QI 0 "nonimmediate_operand" "=d")
5796     (match_operator 1 "valid_dbcc_comparison_p"
5797       [(match_operand:DI 2 "general_operand" "ro") (const_int 0)]))]
5798   "TARGET_COLDFIRE"
5799 {
5800   return output_scc_di (operands[1], operands[2], const0_rtx, operands[0]);
5801 })
5802
5803 (define_insn "scc_di"
5804   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm,dm")
5805     (match_operator 1 "valid_dbcc_comparison_p"
5806       [(match_operand:DI 2 "general_operand" "ro,r")
5807        (match_operand:DI 3 "general_operand" "r,ro")]))]
5808   "! TARGET_COLDFIRE"
5809 {
5810   return output_scc_di (operands[1], operands[2], operands[3], operands[0]);
5811 })
5812
5813 (define_insn "scc_di_5200"
5814   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d")
5815     (match_operator 1 "valid_dbcc_comparison_p"
5816       [(match_operand:DI 2 "general_operand" "ro,r")
5817        (match_operand:DI 3 "general_operand" "r,ro")]))]
5818   "TARGET_COLDFIRE"
5819 {
5820   return output_scc_di (operands[1], operands[2], operands[3], operands[0]);
5821 })
5822
5823 ;; Note that operand 0 of an SCC insn is supported in the hardware as
5824 ;; memory, but we cannot allow it to be in memory in case the address
5825 ;; needs to be reloaded.
5826
5827 (define_expand "seq"
5828   [(set (match_operand:QI 0 "register_operand" "")
5829         (eq:QI (cc0) (const_int 0)))]
5830   ""
5831 {
5832   if ((TUNE_68060 || TARGET_COLDFIRE_FPU)
5833       && m68k_last_compare_had_fp_operands)
5834     {
5835       m68k_last_compare_had_fp_operands = 0;
5836       FAIL;
5837     }
5838 })
5839
5840 (define_insn ""
5841   [(set (match_operand:QI 0 "register_operand" "=d")
5842         (eq:QI (cc0) (const_int 0)))]
5843   ""
5844 {
5845   cc_status = cc_prev_status;
5846   OUTPUT_JUMP ("seq %0", "fseq %0", "seq %0");
5847 })
5848
5849 (define_expand "sne"
5850   [(set (match_operand:QI 0 "register_operand" "")
5851         (ne:QI (cc0) (const_int 0)))]
5852   ""
5853 {
5854   if ((TUNE_68060 || TARGET_COLDFIRE_FPU)
5855       && m68k_last_compare_had_fp_operands)
5856     {
5857       m68k_last_compare_had_fp_operands = 0;
5858       FAIL;
5859     }
5860 })
5861
5862 (define_insn ""
5863   [(set (match_operand:QI 0 "register_operand" "=d")
5864         (ne:QI (cc0) (const_int 0)))]
5865   ""
5866 {
5867   cc_status = cc_prev_status;
5868   OUTPUT_JUMP ("sne %0", "fsne %0", "sne %0");
5869 })
5870
5871 (define_expand "sgt"
5872   [(set (match_operand:QI 0 "register_operand" "")
5873         (gt:QI (cc0) (const_int 0)))]
5874   ""
5875 {
5876   if ((TUNE_68060 || TARGET_COLDFIRE_FPU)
5877       && m68k_last_compare_had_fp_operands)
5878     {
5879       m68k_last_compare_had_fp_operands = 0;
5880       FAIL;
5881     }
5882 })
5883
5884 (define_insn ""
5885   [(set (match_operand:QI 0 "register_operand" "=d")
5886         (gt:QI (cc0) (const_int 0)))]
5887   ""
5888 {
5889   cc_status = cc_prev_status;
5890   OUTPUT_JUMP ("sgt %0", "fsgt %0", 0);
5891 })
5892
5893 (define_expand "sgtu"
5894   [(set (match_operand:QI 0 "register_operand" "")
5895         (gtu:QI (cc0) (const_int 0)))]
5896   ""
5897   "")
5898
5899 (define_insn ""
5900   [(set (match_operand:QI 0 "register_operand" "=d")
5901         (gtu:QI (cc0) (const_int 0)))]
5902   ""
5903 {
5904   cc_status = cc_prev_status;
5905   return "shi %0";
5906 })
5907
5908 (define_expand "slt"
5909   [(set (match_operand:QI 0 "register_operand" "")
5910         (lt:QI (cc0) (const_int 0)))]
5911   ""
5912 {
5913   if ((TUNE_68060 || TARGET_COLDFIRE_FPU)
5914       && m68k_last_compare_had_fp_operands)
5915     {
5916       m68k_last_compare_had_fp_operands = 0;
5917       FAIL;
5918     }
5919 })
5920
5921 (define_insn ""
5922   [(set (match_operand:QI 0 "register_operand" "=d")
5923         (lt:QI (cc0) (const_int 0)))]
5924   ""
5925 {
5926    cc_status = cc_prev_status;
5927    OUTPUT_JUMP ("slt %0", "fslt %0", "smi %0");
5928 })
5929
5930 (define_expand "sltu"
5931   [(set (match_operand:QI 0 "register_operand" "")
5932         (ltu:QI (cc0) (const_int 0)))]
5933   ""
5934   "")
5935
5936 (define_insn ""
5937   [(set (match_operand:QI 0 "register_operand" "=d")
5938         (ltu:QI (cc0) (const_int 0)))]
5939   ""
5940 {
5941    cc_status = cc_prev_status;
5942    return "scs %0";
5943 })
5944
5945 (define_expand "sge"
5946   [(set (match_operand:QI 0 "register_operand" "")
5947         (ge:QI (cc0) (const_int 0)))]
5948   ""
5949 {
5950   if ((TUNE_68060 || TARGET_COLDFIRE_FPU)
5951       && m68k_last_compare_had_fp_operands)
5952     {
5953       m68k_last_compare_had_fp_operands = 0;
5954       FAIL;
5955     }
5956 })
5957
5958 (define_insn ""
5959   [(set (match_operand:QI 0 "register_operand" "=d")
5960         (ge:QI (cc0) (const_int 0)))]
5961   ""
5962 {
5963    cc_status = cc_prev_status;
5964    OUTPUT_JUMP ("sge %0", "fsge %0", "spl %0");
5965 })
5966
5967 (define_expand "sgeu"
5968   [(set (match_operand:QI 0 "register_operand" "")
5969         (geu:QI (cc0) (const_int 0)))]
5970   ""
5971   "")
5972
5973 (define_insn "*scc"
5974   [(set (match_operand:QI 0 "register_operand" "=d")
5975         (geu:QI (cc0) (const_int 0)))]
5976   ""
5977 {
5978    cc_status = cc_prev_status;
5979    return "scc %0";
5980 }
5981   [(set_attr "type" "scc")])
5982
5983 (define_expand "sle"
5984   [(set (match_operand:QI 0 "register_operand" "")
5985         (le:QI (cc0) (const_int 0)))]
5986   ""
5987 {
5988   if ((TUNE_68060 || TARGET_COLDFIRE_FPU)
5989       && m68k_last_compare_had_fp_operands)
5990     {
5991       m68k_last_compare_had_fp_operands = 0;
5992       FAIL;
5993     }
5994 })
5995
5996 (define_insn ""
5997   [(set (match_operand:QI 0 "register_operand" "=d")
5998         (le:QI (cc0) (const_int 0)))]
5999   ""
6000 {
6001   cc_status = cc_prev_status;
6002   OUTPUT_JUMP ("sle %0", "fsle %0", 0);
6003 })
6004
6005 (define_expand "sleu"
6006   [(set (match_operand:QI 0 "register_operand" "")
6007         (leu:QI (cc0) (const_int 0)))]
6008   ""
6009   "")
6010
6011 (define_insn "*sls"
6012   [(set (match_operand:QI 0 "register_operand" "=d")
6013         (leu:QI (cc0) (const_int 0)))]
6014   ""
6015 {
6016    cc_status = cc_prev_status;
6017    return "sls %0";
6018 }
6019   [(set_attr "type" "scc")])
6020
6021 (define_expand "sordered"
6022   [(set (match_operand:QI 0 "register_operand" "")
6023         (ordered:QI (cc0) (const_int 0)))]
6024   "TARGET_68881 && !TUNE_68060"
6025 {
6026   gcc_assert (m68k_last_compare_had_fp_operands);
6027   m68k_last_compare_had_fp_operands = 0;
6028 })
6029
6030 (define_insn "*sordered_1"
6031   [(set (match_operand:QI 0 "register_operand" "=d")
6032         (ordered:QI (cc0) (const_int 0)))]
6033   "TARGET_68881 && !TUNE_68060"
6034 {
6035   cc_status = cc_prev_status;
6036   return "fsor %0";
6037 })
6038
6039 (define_expand "sunordered"
6040   [(set (match_operand:QI 0 "register_operand" "")
6041         (unordered:QI (cc0) (const_int 0)))]
6042   "TARGET_68881 && !TUNE_68060"
6043 {
6044   gcc_assert (m68k_last_compare_had_fp_operands);
6045   m68k_last_compare_had_fp_operands = 0;
6046 })
6047
6048 (define_insn "*sunordered_1"
6049   [(set (match_operand:QI 0 "register_operand" "=d")
6050         (unordered:QI (cc0) (const_int 0)))]
6051   "TARGET_68881 && !TUNE_68060"
6052 {
6053   cc_status = cc_prev_status;
6054   return "fsun %0";
6055 })
6056
6057 (define_expand "suneq"
6058   [(set (match_operand:QI 0 "register_operand" "")
6059         (uneq:QI (cc0) (const_int 0)))]
6060   "TARGET_68881 && !TUNE_68060"
6061 {
6062   gcc_assert (m68k_last_compare_had_fp_operands);
6063   m68k_last_compare_had_fp_operands = 0;
6064 })
6065
6066 (define_insn "*suneq_1"
6067   [(set (match_operand:QI 0 "register_operand" "=d")
6068         (uneq:QI (cc0) (const_int 0)))]
6069   "TARGET_68881 && !TUNE_68060"
6070 {
6071   cc_status = cc_prev_status;
6072   return "fsueq %0";
6073 })
6074
6075 (define_expand "sunge"
6076   [(set (match_operand:QI 0 "register_operand" "")
6077         (unge:QI (cc0) (const_int 0)))]
6078   "TARGET_68881 && !TUNE_68060"
6079 {
6080   gcc_assert (m68k_last_compare_had_fp_operands);
6081   m68k_last_compare_had_fp_operands = 0;
6082 })
6083
6084 (define_insn "*sunge_1"
6085   [(set (match_operand:QI 0 "register_operand" "=d")
6086         (unge:QI (cc0) (const_int 0)))]
6087   "TARGET_68881 && !TUNE_68060"
6088 {
6089   cc_status = cc_prev_status;
6090   return "fsuge %0";
6091 })
6092
6093 (define_expand "sungt"
6094   [(set (match_operand:QI 0 "register_operand" "")
6095         (ungt:QI (cc0) (const_int 0)))]
6096   "TARGET_68881 && !TUNE_68060"
6097 {
6098   gcc_assert (m68k_last_compare_had_fp_operands);
6099   m68k_last_compare_had_fp_operands = 0;
6100 })
6101
6102 (define_insn "*sungt_1"
6103   [(set (match_operand:QI 0 "register_operand" "=d")
6104         (ungt:QI (cc0) (const_int 0)))]
6105   "TARGET_68881 && !TUNE_68060"
6106 {
6107   cc_status = cc_prev_status;
6108   return "fsugt %0";
6109 })
6110
6111 (define_expand "sunle"
6112   [(set (match_operand:QI 0 "register_operand" "")
6113         (unle:QI (cc0) (const_int 0)))]
6114   "TARGET_68881 && !TUNE_68060"
6115 {
6116   gcc_assert (m68k_last_compare_had_fp_operands);
6117   m68k_last_compare_had_fp_operands = 0;
6118 })
6119
6120 (define_insn "*sunle_1"
6121   [(set (match_operand:QI 0 "register_operand" "=d")
6122         (unle:QI (cc0) (const_int 0)))]
6123   "TARGET_68881 && !TUNE_68060"
6124 {
6125   cc_status = cc_prev_status;
6126   return "fsule %0";
6127 })
6128
6129 (define_expand "sunlt"
6130   [(set (match_operand:QI 0 "register_operand" "")
6131         (unlt:QI (cc0) (const_int 0)))]
6132   "TARGET_68881 && !TUNE_68060"
6133 {
6134   gcc_assert (m68k_last_compare_had_fp_operands);
6135   m68k_last_compare_had_fp_operands = 0;
6136 })
6137
6138 (define_insn "*sunlt_1"
6139   [(set (match_operand:QI 0 "register_operand" "=d")
6140         (unlt:QI (cc0) (const_int 0)))]
6141   "TARGET_68881 && !TUNE_68060"
6142 {
6143   cc_status = cc_prev_status;
6144   return "fsult %0";
6145 })
6146
6147 (define_expand "sltgt"
6148   [(set (match_operand:QI 0 "register_operand" "")
6149         (ltgt:QI (cc0) (const_int 0)))]
6150   "TARGET_68881 && !TUNE_68060"
6151 {
6152   gcc_assert (m68k_last_compare_had_fp_operands);
6153   m68k_last_compare_had_fp_operands = 0;
6154 })
6155
6156 (define_insn "*sltgt_1"
6157   [(set (match_operand:QI 0 "register_operand" "=d")
6158         (ltgt:QI (cc0) (const_int 0)))]
6159   "TARGET_68881 && !TUNE_68060"
6160 {
6161   cc_status = cc_prev_status;
6162   return "fsogl %0";
6163 })
6164
6165 (define_insn "*fsogt_1"
6166   [(set (match_operand:QI 0 "register_operand" "=d")
6167         (not:QI (unle:QI (cc0) (const_int 0))))]
6168   "TARGET_68881 && !TUNE_68060"
6169 {
6170   cc_status = cc_prev_status;
6171   return "fsogt %0";
6172 })
6173
6174 (define_insn "*fsoge_1"
6175   [(set (match_operand:QI 0 "register_operand" "=d")
6176         (not:QI (unlt:QI (cc0) (const_int 0))))]
6177   "TARGET_68881 && !TUNE_68060"
6178 {
6179   cc_status = cc_prev_status;
6180   return "fsoge %0";
6181 })
6182
6183 (define_insn "*fsolt_1"
6184   [(set (match_operand:QI 0 "register_operand" "=d")
6185         (not:QI (unge:QI (cc0) (const_int 0))))]
6186   "TARGET_68881 && !TUNE_68060"
6187 {
6188   cc_status = cc_prev_status;
6189   return "fsolt %0";
6190 })
6191
6192 (define_insn "*fsole_1"
6193   [(set (match_operand:QI 0 "register_operand" "=d")
6194         (not:QI (ungt:QI (cc0) (const_int 0))))]
6195   "TARGET_68881 && !TUNE_68060"
6196 {
6197   cc_status = cc_prev_status;
6198   return "fsole %0";
6199 })
6200 \f
6201 ;; Basic conditional jump instructions.
6202
6203 (define_insn "beq0_di"
6204   [(set (pc)
6205     (if_then_else (eq (match_operand:DI 0 "general_operand" "d*ao,<>")
6206             (const_int 0))
6207         (label_ref (match_operand 1 "" ","))
6208         (pc)))
6209    (clobber (match_scratch:SI 2 "=d,d"))]
6210   ""
6211 {
6212   CC_STATUS_INIT;
6213   if (which_alternative == 1)
6214     return "move%.l %0,%2\;or%.l %0,%2\;jeq %l1";
6215   if ((cc_prev_status.value1
6216       && rtx_equal_p (cc_prev_status.value1, operands[0]))
6217     || (cc_prev_status.value2
6218       && rtx_equal_p (cc_prev_status.value2, operands[0])))
6219     {
6220       cc_status = cc_prev_status;
6221       return "jeq %l1";
6222     }
6223   if (GET_CODE (operands[0]) == REG)
6224     operands[3] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
6225   else
6226     operands[3] = adjust_address (operands[0], SImode, 4);
6227   if (! ADDRESS_REG_P (operands[0]))
6228     {
6229       if (reg_overlap_mentioned_p (operands[2], operands[0]))
6230         {
6231           if (reg_overlap_mentioned_p (operands[2], operands[3]))
6232             return "or%.l %0,%2\;jeq %l1";
6233           else
6234             return "or%.l %3,%2\;jeq %l1";
6235         }
6236       return "move%.l %0,%2\;or%.l %3,%2\;jeq %l1";
6237     }
6238   operands[4] = gen_label_rtx();
6239   if (TARGET_68020 || TARGET_COLDFIRE)
6240     output_asm_insn ("tst%.l %0\;jne %l4\;tst%.l %3\;jeq %l1", operands);
6241   else
6242     output_asm_insn ("cmp%.w #0,%0\;jne %l4\;cmp%.w #0,%3\;jeq %l1", operands);
6243   (*targetm.asm_out.internal_label) (asm_out_file, "L",
6244                                 CODE_LABEL_NUMBER (operands[4]));
6245   return "";
6246 })
6247
6248 (define_insn "bne0_di"
6249   [(set (pc)
6250     (if_then_else (ne (match_operand:DI 0 "general_operand" "do,*a")
6251             (const_int 0))
6252         (label_ref (match_operand 1 "" ","))
6253         (pc)))
6254    (clobber (match_scratch:SI 2 "=d,X"))]
6255   ""
6256 {
6257   if ((cc_prev_status.value1
6258       && rtx_equal_p (cc_prev_status.value1, operands[0]))
6259     || (cc_prev_status.value2
6260       && rtx_equal_p (cc_prev_status.value2, operands[0])))
6261     {
6262       cc_status = cc_prev_status;
6263       return "jne %l1";
6264     }
6265   CC_STATUS_INIT;
6266   if (GET_CODE (operands[0]) == REG)
6267     operands[3] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
6268   else
6269     operands[3] = adjust_address (operands[0], SImode, 4);
6270   if (!ADDRESS_REG_P (operands[0]))
6271     {
6272       if (reg_overlap_mentioned_p (operands[2], operands[0]))
6273         {
6274           if (reg_overlap_mentioned_p (operands[2], operands[3]))
6275             return "or%.l %0,%2\;jne %l1";
6276           else
6277             return "or%.l %3,%2\;jne %l1";
6278         }
6279       return "move%.l %0,%2\;or%.l %3,%2\;jne %l1";
6280     }
6281   if (TARGET_68020 || TARGET_COLDFIRE)
6282     return "tst%.l %0\;jne %l1\;tst%.l %3\;jne %l1";
6283   else
6284     return "cmp%.w #0,%0\;jne %l1\;cmp%.w #0,%3\;jne %l1";
6285 })
6286
6287 (define_insn "bge0_di"
6288   [(set (pc)
6289     (if_then_else (ge (match_operand:DI 0 "general_operand" "ro")
6290             (const_int 0))
6291         (label_ref (match_operand 1 "" ""))
6292         (pc)))]
6293   ""
6294 {
6295   if ((cc_prev_status.value1
6296       && rtx_equal_p (cc_prev_status.value1, operands[0]))
6297     || (cc_prev_status.value2
6298       && rtx_equal_p (cc_prev_status.value2, operands[0])))
6299     {
6300       cc_status = cc_prev_status;
6301       return cc_status.flags & CC_REVERSED ? "jle %l1" : "jpl %l1";
6302     }
6303   CC_STATUS_INIT;
6304   if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (operands[0]))
6305     output_asm_insn("tst%.l %0", operands);
6306   else
6307     {
6308       /* On an address reg, cmpw may replace cmpl.  */
6309       output_asm_insn("cmp%.w #0,%0", operands);
6310     }
6311   return "jpl %l1";
6312 })
6313
6314 (define_insn "blt0_di"
6315   [(set (pc)
6316     (if_then_else (lt (match_operand:DI 0 "general_operand" "ro")
6317             (const_int 0))
6318         (label_ref (match_operand 1 "" ""))
6319         (pc)))]
6320   ""
6321 {
6322   if ((cc_prev_status.value1
6323       && rtx_equal_p (cc_prev_status.value1, operands[0]))
6324     || (cc_prev_status.value2
6325       && rtx_equal_p (cc_prev_status.value2, operands[0])))
6326     {
6327       cc_status = cc_prev_status;
6328       return cc_status.flags & CC_REVERSED ? "jgt %l1" : "jmi %l1";
6329     }
6330   CC_STATUS_INIT;
6331   if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (operands[0]))
6332     output_asm_insn("tst%.l %0", operands);
6333   else
6334     {
6335       /* On an address reg, cmpw may replace cmpl.  */
6336       output_asm_insn("cmp%.w #0,%0", operands);
6337     }
6338   return "jmi %l1";
6339 })
6340
6341 (define_insn "beq"
6342   [(set (pc)
6343         (if_then_else (eq (cc0)
6344                           (const_int 0))
6345                       (label_ref (match_operand 0 "" ""))
6346                       (pc)))]
6347   ""
6348 {
6349   OUTPUT_JUMP ("jeq %l0", "fjeq %l0", "jeq %l0");
6350 }
6351   [(set (attr "type") (symbol_ref "m68k_sched_branch_type (insn)"))])
6352
6353 (define_insn "bne"
6354   [(set (pc)
6355         (if_then_else (ne (cc0)
6356                           (const_int 0))
6357                       (label_ref (match_operand 0 "" ""))
6358                       (pc)))]
6359   ""
6360 {
6361   OUTPUT_JUMP ("jne %l0", "fjne %l0", "jne %l0");
6362 }
6363   [(set (attr "type") (symbol_ref "m68k_sched_branch_type (insn)"))])
6364
6365 (define_insn "bgt"
6366   [(set (pc)
6367         (if_then_else (gt (cc0)
6368                           (const_int 0))
6369                       (label_ref (match_operand 0 "" ""))
6370                       (pc)))]
6371   ""
6372 {
6373   OUTPUT_JUMP ("jgt %l0", "fjgt %l0", 0);
6374 }
6375   [(set (attr "type") (symbol_ref "m68k_sched_branch_type (insn)"))])
6376
6377 (define_insn "bgtu"
6378   [(set (pc)
6379         (if_then_else (gtu (cc0)
6380                            (const_int 0))
6381                       (label_ref (match_operand 0 "" ""))
6382                       (pc)))]
6383   ""
6384   "jhi %l0"
6385   [(set_attr "type" "bcc")])
6386
6387 (define_insn "blt"
6388   [(set (pc)
6389         (if_then_else (lt (cc0)
6390                           (const_int 0))
6391                       (label_ref (match_operand 0 "" ""))
6392                       (pc)))]
6393   ""
6394 {
6395   OUTPUT_JUMP ("jlt %l0", "fjlt %l0", "jmi %l0");
6396 }
6397   [(set (attr "type") (symbol_ref "m68k_sched_branch_type (insn)"))])
6398
6399 (define_insn "bltu"
6400   [(set (pc)
6401         (if_then_else (ltu (cc0)
6402                            (const_int 0))
6403                       (label_ref (match_operand 0 "" ""))
6404                       (pc)))]
6405   ""
6406   "jcs %l0"
6407   [(set_attr "type" "bcc")])
6408
6409 (define_insn "bge"
6410   [(set (pc)
6411         (if_then_else (ge (cc0)
6412                           (const_int 0))
6413                       (label_ref (match_operand 0 "" ""))
6414                       (pc)))]
6415   ""
6416 {
6417   OUTPUT_JUMP ("jge %l0", "fjge %l0", "jpl %l0");
6418 })
6419
6420 (define_insn "bgeu"
6421   [(set (pc)
6422         (if_then_else (geu (cc0)
6423                            (const_int 0))
6424                       (label_ref (match_operand 0 "" ""))
6425                       (pc)))]
6426   ""
6427   "jcc %l0"
6428   [(set_attr "type" "bcc")])
6429
6430 (define_insn "ble"
6431   [(set (pc)
6432         (if_then_else (le (cc0)
6433                           (const_int 0))
6434                       (label_ref (match_operand 0 "" ""))
6435                       (pc)))]
6436   ""
6437 {
6438   OUTPUT_JUMP ("jle %l0", "fjle %l0", 0);
6439 }
6440   [(set_attr "type" "bcc")])
6441
6442 (define_insn "bleu"
6443   [(set (pc)
6444         (if_then_else (leu (cc0)
6445                            (const_int 0))
6446                       (label_ref (match_operand 0 "" ""))
6447                       (pc)))]
6448   ""
6449   "jls %l0"
6450   [(set_attr "type" "bcc")])
6451
6452 (define_insn "bordered"
6453   [(set (pc)
6454         (if_then_else (ordered (cc0) (const_int 0))
6455                       (label_ref (match_operand 0 "" ""))
6456                       (pc)))]
6457   "TARGET_HARD_FLOAT"
6458 {
6459   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6460   return "fjor %l0";
6461 }
6462   [(set_attr "type" "fbcc")])
6463
6464 (define_insn "bunordered"
6465   [(set (pc)
6466         (if_then_else (unordered (cc0) (const_int 0))
6467                       (label_ref (match_operand 0 "" ""))
6468                       (pc)))]
6469   "TARGET_HARD_FLOAT"
6470 {
6471   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6472   return "fjun %l0";
6473 }
6474   [(set_attr "type" "fbcc")])
6475
6476 (define_insn "buneq"
6477   [(set (pc)
6478         (if_then_else (uneq (cc0) (const_int 0))
6479                       (label_ref (match_operand 0 "" ""))
6480                       (pc)))]
6481   "TARGET_HARD_FLOAT"
6482 {
6483   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6484   return "fjueq %l0";
6485 }
6486   [(set_attr "type" "fbcc")])
6487
6488 (define_insn "bunge"
6489   [(set (pc)
6490         (if_then_else (unge (cc0) (const_int 0))
6491                       (label_ref (match_operand 0 "" ""))
6492                       (pc)))]
6493   "TARGET_HARD_FLOAT"
6494 {
6495   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6496   return "fjuge %l0";
6497 }
6498   [(set_attr "type" "fbcc")])
6499
6500 (define_insn "bungt"
6501   [(set (pc)
6502         (if_then_else (ungt (cc0) (const_int 0))
6503                       (label_ref (match_operand 0 "" ""))
6504                       (pc)))]
6505   "TARGET_HARD_FLOAT"
6506 {
6507   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6508   return "fjugt %l0";
6509 }
6510   [(set_attr "type" "fbcc")])
6511
6512 (define_insn "bunle"
6513   [(set (pc)
6514         (if_then_else (unle (cc0) (const_int 0))
6515                       (label_ref (match_operand 0 "" ""))
6516                       (pc)))]
6517   "TARGET_HARD_FLOAT"
6518 {
6519   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6520   return "fjule %l0";
6521 }
6522   [(set_attr "type" "fbcc")])
6523
6524 (define_insn "bunlt"
6525   [(set (pc)
6526         (if_then_else (unlt (cc0) (const_int 0))
6527                       (label_ref (match_operand 0 "" ""))
6528                       (pc)))]
6529   "TARGET_HARD_FLOAT"
6530 {
6531   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6532   return "fjult %l0";
6533 }
6534   [(set_attr "type" "fbcc")])
6535
6536 (define_insn "bltgt"
6537   [(set (pc)
6538         (if_then_else (ltgt (cc0) (const_int 0))
6539                       (label_ref (match_operand 0 "" ""))
6540                       (pc)))]
6541   "TARGET_HARD_FLOAT"
6542 {
6543   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6544   return "fjogl %l0";
6545 }
6546   [(set_attr "type" "fbcc")])
6547 \f
6548 ;; Negated conditional jump instructions.
6549
6550 (define_insn "*beq_rev"
6551   [(set (pc)
6552         (if_then_else (eq (cc0)
6553                           (const_int 0))
6554                       (pc)
6555                       (label_ref (match_operand 0 "" ""))))]
6556   ""
6557 {
6558   OUTPUT_JUMP ("jne %l0", "fjne %l0", "jne %l0");
6559 }
6560   [(set_attr "type" "bcc")])
6561
6562 (define_insn "*bne_rev"
6563   [(set (pc)
6564         (if_then_else (ne (cc0)
6565                           (const_int 0))
6566                       (pc)
6567                       (label_ref (match_operand 0 "" ""))))]
6568   ""
6569 {
6570   OUTPUT_JUMP ("jeq %l0", "fjeq %l0", "jeq %l0");
6571 }
6572   [(set_attr "type" "bcc")])
6573
6574 (define_insn "*bgt_rev"
6575   [(set (pc)
6576         (if_then_else (gt (cc0)
6577                           (const_int 0))
6578                       (pc)
6579                       (label_ref (match_operand 0 "" ""))))]
6580   ""
6581 {
6582   OUTPUT_JUMP ("jle %l0", "fjngt %l0", 0);
6583 }
6584   [(set_attr "type" "bcc")])
6585
6586 (define_insn "*bgtu_rev"
6587   [(set (pc)
6588         (if_then_else (gtu (cc0)
6589                            (const_int 0))
6590                       (pc)
6591                       (label_ref (match_operand 0 "" ""))))]
6592   ""
6593   "jls %l0"
6594   [(set_attr "type" "bcc")])
6595
6596 (define_insn "*blt_rev"
6597   [(set (pc)
6598         (if_then_else (lt (cc0)
6599                           (const_int 0))
6600                       (pc)
6601                       (label_ref (match_operand 0 "" ""))))]
6602   ""
6603 {
6604   OUTPUT_JUMP ("jge %l0", "fjnlt %l0", "jpl %l0");
6605 }
6606   [(set_attr "type" "bcc")])
6607
6608 (define_insn "*bltu_rev"
6609   [(set (pc)
6610         (if_then_else (ltu (cc0)
6611                            (const_int 0))
6612                       (pc)
6613                       (label_ref (match_operand 0 "" ""))))]
6614   ""
6615   "jcc %l0"
6616   [(set_attr "type" "bcc")])
6617
6618 (define_insn "*bge_rev"
6619   [(set (pc)
6620         (if_then_else (ge (cc0)
6621                           (const_int 0))
6622                       (pc)
6623                       (label_ref (match_operand 0 "" ""))))]
6624   ""
6625 {
6626   OUTPUT_JUMP ("jlt %l0", "fjnge %l0", "jmi %l0");
6627 }
6628   [(set_attr "type" "bcc")])
6629
6630 (define_insn "*bgeu_rev"
6631   [(set (pc)
6632         (if_then_else (geu (cc0)
6633                            (const_int 0))
6634                       (pc)
6635                       (label_ref (match_operand 0 "" ""))))]
6636   ""
6637   "jcs %l0"
6638   [(set_attr "type" "bcc")])
6639
6640 (define_insn "*ble_rev"
6641   [(set (pc)
6642         (if_then_else (le (cc0)
6643                           (const_int 0))
6644                       (pc)
6645                       (label_ref (match_operand 0 "" ""))))]
6646   ""
6647 {
6648   OUTPUT_JUMP ("jgt %l0", "fjnle %l0", 0);
6649 }
6650   [(set_attr "type" "bcc")])
6651
6652 (define_insn "*bleu_rev"
6653   [(set (pc)
6654         (if_then_else (leu (cc0)
6655                            (const_int 0))
6656                       (pc)
6657                       (label_ref (match_operand 0 "" ""))))]
6658   ""
6659   "jhi %l0"
6660   [(set_attr "type" "bcc")])
6661
6662 (define_insn "*bordered_rev"
6663   [(set (pc)
6664         (if_then_else (ordered (cc0) (const_int 0))
6665                       (pc)
6666                       (label_ref (match_operand 0 "" ""))))]
6667   "TARGET_HARD_FLOAT"
6668 {
6669   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6670   return "fjun %l0";
6671 }
6672   [(set_attr "type" "fbcc")])
6673
6674 (define_insn "*bunordered_rev"
6675   [(set (pc)
6676         (if_then_else (unordered (cc0) (const_int 0))
6677                       (pc)
6678                       (label_ref (match_operand 0 "" ""))))]
6679   "TARGET_HARD_FLOAT"
6680 {
6681   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6682   return "fjor %l0";
6683 }
6684   [(set_attr "type" "fbcc")])
6685
6686 (define_insn "*buneq_rev"
6687   [(set (pc)
6688         (if_then_else (uneq (cc0) (const_int 0))
6689                       (pc)
6690                       (label_ref (match_operand 0 "" ""))))]
6691   "TARGET_HARD_FLOAT"
6692 {
6693   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6694   return "fjogl %l0";
6695 }
6696   [(set_attr "type" "fbcc")])
6697
6698 (define_insn "*bunge_rev"
6699   [(set (pc)
6700         (if_then_else (unge (cc0) (const_int 0))
6701                       (pc)
6702                       (label_ref (match_operand 0 "" ""))))]
6703   "TARGET_HARD_FLOAT"
6704 {
6705   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6706   return "fjolt %l0";
6707 }
6708   [(set_attr "type" "fbcc")])
6709
6710 (define_insn "*bungt_rev"
6711   [(set (pc)
6712         (if_then_else (ungt (cc0) (const_int 0))
6713                       (pc)
6714                       (label_ref (match_operand 0 "" ""))))]
6715   "TARGET_HARD_FLOAT"
6716 {
6717   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6718   return "fjole %l0";
6719 }
6720   [(set_attr "type" "fbcc")])
6721
6722 (define_insn "*bunle_rev"
6723   [(set (pc)
6724         (if_then_else (unle (cc0) (const_int 0))
6725                       (pc)
6726                       (label_ref (match_operand 0 "" ""))))]
6727   "TARGET_HARD_FLOAT"
6728 {
6729   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6730   return "fjogt %l0";
6731 }
6732   [(set_attr "type" "fbcc")])
6733
6734 (define_insn "*bunlt_rev"
6735   [(set (pc)
6736         (if_then_else (unlt (cc0) (const_int 0))
6737                       (pc)
6738                       (label_ref (match_operand 0 "" ""))))]
6739   "TARGET_HARD_FLOAT"
6740 {
6741   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6742   return "fjoge %l0";
6743 }
6744   [(set_attr "type" "fbcc")])
6745
6746 (define_insn "*bltgt_rev"
6747   [(set (pc)
6748         (if_then_else (ltgt (cc0) (const_int 0))
6749                       (pc)
6750                       (label_ref (match_operand 0 "" ""))))]
6751   "TARGET_HARD_FLOAT"
6752 {
6753   gcc_assert (cc_prev_status.flags & CC_IN_68881);
6754   return "fjueq %l0";
6755 }
6756   [(set_attr "type" "fbcc")])
6757 \f
6758 ;; Unconditional and other jump instructions
6759 (define_insn "jump"
6760   [(set (pc)
6761         (label_ref (match_operand 0 "" "")))]
6762   ""
6763   "jra %l0"
6764   [(set_attr "type" "bra")])
6765
6766 (define_expand "tablejump"
6767   [(parallel [(set (pc) (match_operand 0 "" ""))
6768               (use (label_ref (match_operand 1 "" "")))])]
6769   ""
6770 {
6771 #ifdef CASE_VECTOR_PC_RELATIVE
6772     operands[0] = gen_rtx_PLUS (SImode, pc_rtx,
6773                                 gen_rtx_SIGN_EXTEND (SImode, operands[0]));
6774 #endif
6775 })
6776
6777 ;; Jump to variable address from dispatch table of absolute addresses.
6778 (define_insn "*tablejump_internal"
6779   [(set (pc) (match_operand:SI 0 "register_operand" "a"))
6780    (use (label_ref (match_operand 1 "" "")))]
6781   ""
6782 {
6783   return MOTOROLA ? "jmp (%0)" : "jmp %0@";
6784 }
6785   [(set_attr "type" "jmp")])
6786
6787 ;; Jump to variable address from dispatch table of relative addresses.
6788 (define_insn ""
6789   [(set (pc)
6790         (plus:SI (pc)
6791                  (sign_extend:SI (match_operand:HI 0 "register_operand" "r"))))
6792    (use (label_ref (match_operand 1 "" "")))]
6793   ""
6794 {
6795 #ifdef ASM_RETURN_CASE_JUMP
6796   ASM_RETURN_CASE_JUMP;
6797 #else
6798   if (TARGET_COLDFIRE)
6799     {
6800       if (ADDRESS_REG_P (operands[0]))
6801         return MOTOROLA ? "jmp (2,pc,%0.l)" : "jmp pc@(2,%0:l)";
6802       else if (MOTOROLA)
6803         return "ext%.l %0\;jmp (2,pc,%0.l)";
6804       else
6805         return "extl %0\;jmp pc@(2,%0:l)";
6806     }
6807   else
6808     return MOTOROLA ? "jmp (2,pc,%0.w)" : "jmp pc@(2,%0:w)";
6809 #endif
6810 })
6811
6812 ;; Decrement-and-branch insns.
6813 (define_insn "*dbne_hi"
6814   [(set (pc)
6815         (if_then_else
6816          (ne (match_operand:HI 0 "nonimmediate_operand" "+d*g")
6817              (const_int 0))
6818          (label_ref (match_operand 1 "" ""))
6819          (pc)))
6820    (set (match_dup 0)
6821         (plus:HI (match_dup 0)
6822                  (const_int -1)))]
6823   "!TARGET_COLDFIRE"
6824 {
6825   CC_STATUS_INIT;
6826   if (DATA_REG_P (operands[0]))
6827     return "dbra %0,%l1";
6828   if (GET_CODE (operands[0]) == MEM)
6829     return "subq%.w #1,%0\;jcc %l1";
6830   return "subq%.w #1,%0\;cmp%.w #-1,%0\;jne %l1";
6831 })
6832
6833 (define_insn "*dbne_si"
6834   [(set (pc)
6835         (if_then_else
6836          (ne (match_operand:SI 0 "nonimmediate_operand" "+d*g")
6837              (const_int 0))
6838          (label_ref (match_operand 1 "" ""))
6839          (pc)))
6840    (set (match_dup 0)
6841         (plus:SI (match_dup 0)
6842                  (const_int -1)))]
6843   "!TARGET_COLDFIRE"
6844 {
6845   CC_STATUS_INIT;
6846   if (DATA_REG_P (operands[0]))
6847     return "dbra %0,%l1\;clr%.w %0\;subq%.l #1,%0\;jcc %l1";
6848   if (GET_CODE (operands[0]) == MEM)
6849     return "subq%.l #1,%0\;jcc %l1";
6850   return "subq%.l #1,%0\;cmp%.l #-1,%0\;jne %l1";
6851 })
6852
6853 ;; Two dbra patterns that use REG_NOTES info generated by strength_reduce.
6854
6855 (define_insn "*dbge_hi"
6856   [(set (pc)
6857         (if_then_else
6858           (ge (plus:HI (match_operand:HI 0 "nonimmediate_operand" "+d*am")
6859                        (const_int -1))
6860               (const_int 0))
6861           (label_ref (match_operand 1 "" ""))
6862           (pc)))
6863    (set (match_dup 0)
6864         (plus:HI (match_dup 0)
6865                  (const_int -1)))]
6866   "!TARGET_COLDFIRE && find_reg_note (insn, REG_NONNEG, 0)"
6867 {
6868   CC_STATUS_INIT;
6869   if (DATA_REG_P (operands[0]))
6870     return "dbra %0,%l1";
6871   if (GET_CODE (operands[0]) == MEM)
6872     return "subq%.w #1,%0\;jcc %l1";
6873   return "subq%.w #1,%0\;cmp%.w #-1,%0\;jne %l1";
6874 })
6875
6876 (define_expand "decrement_and_branch_until_zero"
6877   [(parallel [(set (pc)
6878                    (if_then_else
6879                     (ge (plus:SI (match_operand:SI 0 "nonimmediate_operand" "")
6880                                  (const_int -1))
6881                         (const_int 0))
6882                     (label_ref (match_operand 1 "" ""))
6883                     (pc)))
6884               (set (match_dup 0)
6885                    (plus:SI (match_dup 0)
6886                             (const_int -1)))])]
6887   ""
6888   "")
6889
6890 (define_insn "*dbge_si"
6891   [(set (pc)
6892         (if_then_else
6893           (ge (plus:SI (match_operand:SI 0 "nonimmediate_operand" "+d*am")
6894                        (const_int -1))
6895               (const_int 0))
6896           (label_ref (match_operand 1 "" ""))
6897           (pc)))
6898    (set (match_dup 0)
6899         (plus:SI (match_dup 0)
6900                  (const_int -1)))]
6901   "!TARGET_COLDFIRE && find_reg_note (insn, REG_NONNEG, 0)"
6902 {
6903   CC_STATUS_INIT;
6904   if (DATA_REG_P (operands[0]))
6905     return "dbra %0,%l1\;clr%.w %0\;subq%.l #1,%0\;jcc %l1";
6906   if (GET_CODE (operands[0]) == MEM)
6907     return "subq%.l #1,%0\;jcc %l1";
6908   return "subq%.l #1,%0\;cmp%.l #-1,%0\;jne %l1";
6909 })
6910
6911 (define_expand "sibcall"
6912   [(call (match_operand:QI 0 "memory_operand" "")
6913          (match_operand:SI 1 "general_operand" ""))]
6914   ""
6915 {
6916   operands[0] = m68k_legitimize_sibcall_address (operands[0]);
6917 })
6918
6919 (define_insn "*sibcall"
6920   [(call (mem:QI (match_operand:SI 0 "sibcall_operand" ""))
6921          (match_operand:SI 1 "general_operand" ""))]
6922   "SIBLING_CALL_P (insn)"
6923 {
6924   return output_sibcall (operands[0]);
6925 })
6926
6927 (define_expand "sibcall_value"
6928   [(set (match_operand 0 "" "")
6929         (call (match_operand:QI 1 "memory_operand" "")
6930               (match_operand:SI 2 "general_operand" "")))]
6931   ""
6932 {
6933   operands[1] = m68k_legitimize_sibcall_address (operands[1]);
6934 })
6935
6936 (define_insn "*sibcall_value"
6937   [(set (match_operand 0 "" "=rf,rf")
6938         (call (mem:QI (match_operand:SI 1 "sibcall_operand" ""))
6939               (match_operand:SI 2 "general_operand" "")))]
6940   "SIBLING_CALL_P (insn)"
6941 {
6942   operands[0] = operands[1];
6943   return output_sibcall (operands[0]);
6944 })
6945
6946 ;; Call subroutine with no return value.
6947 (define_expand "call"
6948   [(call (match_operand:QI 0 "memory_operand" "")
6949          (match_operand:SI 1 "general_operand" ""))]
6950   ;; Operand 1 not really used on the m68000.
6951   ""
6952 {
6953   operands[0] = m68k_legitimize_call_address (operands[0]);
6954 })
6955
6956 (define_insn "*call"
6957   [(call (mem:QI (match_operand:SI 0 "call_operand" "a,W"))
6958          (match_operand:SI 1 "general_operand" "g,g"))]
6959   ;; Operand 1 not really used on the m68000.
6960   "!SIBLING_CALL_P (insn)"
6961 {
6962   return output_call (operands[0]);
6963 }
6964   [(set_attr "type" "jsr")])
6965
6966 ;; Call subroutine, returning value in operand 0
6967 ;; (which must be a hard register).
6968 (define_expand "call_value"
6969   [(set (match_operand 0 "" "")
6970         (call (match_operand:QI 1 "memory_operand" "")
6971               (match_operand:SI 2 "general_operand" "")))]
6972   ;; Operand 2 not really used on the m68000.
6973   ""
6974 {
6975   operands[1] = m68k_legitimize_call_address (operands[1]);
6976 })
6977
6978 (define_insn "*non_symbolic_call_value"
6979   [(set (match_operand 0 "" "=rf,rf")
6980         (call (mem:QI (match_operand:SI 1 "non_symbolic_call_operand" "a,W"))
6981               (match_operand:SI 2 "general_operand" "g,g")))]
6982   ;; Operand 2 not really used on the m68000.
6983   "!SIBLING_CALL_P (insn)"
6984   "jsr %a1"
6985   [(set_attr "type" "jsr")
6986    (set_attr "opx" "1")])
6987
6988 (define_insn "*symbolic_call_value_jsr"
6989   [(set (match_operand 0 "" "=rf,rf")
6990         (call (mem:QI (match_operand:SI 1 "symbolic_operand" "a,W"))
6991               (match_operand:SI 2 "general_operand" "g,g")))]
6992   ;; Operand 2 not really used on the m68000.
6993   "!SIBLING_CALL_P (insn) && m68k_symbolic_call_var == M68K_SYMBOLIC_CALL_JSR"
6994 {
6995   operands[0] = operands[1];
6996   return m68k_symbolic_call;
6997 }
6998   [(set_attr "type" "jsr")
6999    (set_attr "opx" "1")])
7000
7001 (define_insn "*symbolic_call_value_bsr"
7002   [(set (match_operand 0 "" "=rf,rf")
7003         (call (mem:QI (match_operand:SI 1 "symbolic_operand" "a,W"))
7004               (match_operand:SI 2 "general_operand" "g,g")))]
7005   ;; Operand 2 not really used on the m68000.
7006   "!SIBLING_CALL_P (insn)
7007    && (m68k_symbolic_call_var == M68K_SYMBOLIC_CALL_BSR_C
7008        || m68k_symbolic_call_var == M68K_SYMBOLIC_CALL_BSR_P)"
7009 {
7010   operands[0] = operands[1];
7011   return m68k_symbolic_call;
7012 }
7013   [(set_attr "type" "bsr")
7014    (set_attr "opx" "1")])
7015
7016 ;; Call subroutine returning any type.
7017
7018 (define_expand "untyped_call"
7019   [(parallel [(call (match_operand 0 "" "")
7020                     (const_int 0))
7021               (match_operand 1 "" "")
7022               (match_operand 2 "" "")])]
7023   "NEEDS_UNTYPED_CALL"
7024 {
7025   int i;
7026
7027   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
7028
7029   for (i = 0; i < XVECLEN (operands[2], 0); i++)
7030     {
7031       rtx set = XVECEXP (operands[2], 0, i);
7032       emit_move_insn (SET_DEST (set), SET_SRC (set));
7033     }
7034
7035   /* The optimizer does not know that the call sets the function value
7036      registers we stored in the result block.  We avoid problems by
7037      claiming that all hard registers are used and clobbered at this
7038      point.  */
7039   emit_insn (gen_blockage ());
7040
7041   DONE;
7042 })
7043
7044 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
7045 ;; all of memory.  This blocks insns from being moved across this point.
7046
7047 (define_insn "blockage"
7048   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
7049   ""
7050   "")
7051
7052 (define_insn "nop"
7053   [(const_int 0)]
7054   ""
7055   "nop"
7056   [(set_attr "type" "nop")])
7057
7058 (define_expand "prologue"
7059   [(const_int 0)]
7060   ""
7061 {
7062   m68k_expand_prologue ();
7063   DONE;
7064 })
7065
7066 (define_expand "epilogue"
7067   [(return)]
7068   ""
7069 {
7070   m68k_expand_epilogue (false);
7071   DONE;
7072 })
7073
7074 (define_expand "sibcall_epilogue"
7075   [(return)]
7076   ""
7077 {
7078   m68k_expand_epilogue (true);
7079   DONE;
7080 })
7081
7082 ;; Used for frameless functions which save no regs and allocate no locals.
7083 (define_expand "return"
7084   [(return)]
7085   "m68k_use_return_insn ()"
7086   "")
7087
7088 (define_insn "*return"
7089   [(return)]
7090   ""
7091 {
7092   switch (m68k_get_function_kind (current_function_decl))
7093     {
7094     case m68k_fk_interrupt_handler:
7095       return "rte";
7096
7097     case m68k_fk_interrupt_thread:
7098       return "sleep";
7099
7100     default:
7101       if (crtl->args.pops_args)
7102         {
7103           operands[0] = GEN_INT (crtl->args.pops_args);
7104           return "rtd %0";
7105         }
7106       else
7107         return "rts";
7108     }
7109 }
7110   [(set_attr "type" "rts")])
7111
7112 (define_insn "*m68k_store_multiple"
7113   [(match_parallel 0 "" [(match_operand 1 "")])]
7114   "m68k_movem_pattern_p (operands[0], NULL, 0, true)"
7115 {
7116   return m68k_output_movem (operands, operands[0], 0, true);
7117 })
7118
7119 (define_insn "*m68k_store_multiple_automod"
7120   [(match_parallel 0 ""
7121      [(set (match_operand:SI 1 "register_operand" "=a")
7122            (plus:SI (match_operand:SI 2 "register_operand" "1")
7123                     (match_operand:SI 3 "const_int_operand")))])]
7124   "m68k_movem_pattern_p (operands[0], operands[1], INTVAL (operands[3]), true)"
7125 {
7126   return m68k_output_movem (operands, operands[0], INTVAL (operands[3]), true);
7127 })
7128
7129 (define_insn "*m68k_load_multiple"
7130   [(match_parallel 0 "" [(match_operand 1 "")])]
7131   "m68k_movem_pattern_p (operands[0], NULL, 0, false)"
7132 {
7133   return m68k_output_movem (operands, operands[0], 0, false);
7134 })
7135
7136 (define_insn "*m68k_load_multiple_automod"
7137   [(match_parallel 0 ""
7138      [(set (match_operand:SI 1 "register_operand" "=a")
7139            (plus:SI (match_operand:SI 2 "register_operand" "1")
7140                     (match_operand:SI 3 "const_int_operand")))])]
7141   "m68k_movem_pattern_p (operands[0], operands[1],
7142                          INTVAL (operands[3]), false)"
7143 {
7144   return m68k_output_movem (operands, operands[0],
7145                             INTVAL (operands[3]), false);
7146 })
7147
7148 (define_expand "link"
7149   [(parallel
7150        [(set (match_operand:SI 0 "register_operand")
7151              (plus:SI (reg:SI SP_REG) (const_int -4)))
7152         (set (match_dup 2)
7153              (match_dup 0))
7154         (set (reg:SI SP_REG)
7155              (plus:SI (reg:SI SP_REG)
7156                       (match_operand:SI 1 "const_int_operand")))])]
7157   "TARGET_68020 || INTVAL (operands[1]) >= -0x8004"
7158 {
7159   operands[2] = gen_frame_mem (SImode, plus_constant (stack_pointer_rtx, -4));
7160 })
7161
7162 (define_insn "*link"
7163   [(set (match_operand:SI 0 "register_operand" "+r")
7164         (plus:SI (reg:SI SP_REG) (const_int -4)))
7165    (set (mem:SI (plus:SI (reg:SI SP_REG) (const_int -4)))
7166         (match_dup 0))
7167    (set (reg:SI SP_REG)
7168         (plus:SI (reg:SI SP_REG)
7169                  (match_operand:SI 1 "const_int_operand")))]
7170   "TARGET_68020 || INTVAL (operands[1]) >= -0x8004"
7171 {
7172   operands[1] = GEN_INT (INTVAL (operands[1]) + 4);
7173   if (!MOTOROLA)
7174     return "link %0,%1";
7175   else if (INTVAL (operands[1]) >= -0x8000)
7176     return "link.w %0,%1";
7177   else
7178     return "link.l %0,%1";
7179 }
7180   [(set_attr "type" "link")])
7181
7182 (define_expand "unlink"
7183   [(parallel
7184       [(set (match_operand:SI 0 "register_operand")
7185             (match_dup 1))
7186        (set (reg:SI SP_REG)
7187             (plus:SI (match_dup 0)
7188                      (const_int 4)))])]
7189   ""
7190 {
7191   operands[1] = gen_frame_mem (SImode, copy_rtx (operands[0]));
7192 })
7193
7194 (define_insn "*unlink"
7195   [(set (match_operand:SI 0 "register_operand" "+r")
7196         (mem:SI (match_dup 0)))
7197    (set (reg:SI SP_REG)
7198         (plus:SI (match_dup 0)
7199                  (const_int 4)))]
7200   ""
7201   "unlk %0"
7202   [(set_attr "type" "unlk")])
7203
7204 (define_insn "load_got"
7205   [(set (match_operand:SI 0 "register_operand" "=a")
7206         (unspec:SI [(const_int 0)] UNSPEC_GOT))]
7207   ""
7208 {
7209   if (TARGET_ID_SHARED_LIBRARY)
7210     {
7211       operands[1] = gen_rtx_REG (Pmode, PIC_REG);
7212       return MOTOROLA ? "move.l %?(%1),%0" : "movel %1@(%?), %0";
7213     }
7214   else if (MOTOROLA)
7215     {
7216       if (TARGET_COLDFIRE)
7217         /* Load the full 32-bit PC-relative offset of
7218            _GLOBAL_OFFSET_TABLE_ into the PIC register, then use it to
7219            calculate the absolute value.  The offset and "lea"
7220            operation word together occupy 6 bytes.  */
7221         return ("move.l #_GLOBAL_OFFSET_TABLE_@GOTPC, %0\n\t"
7222                 "lea (-6, %%pc, %0), %0");
7223       else
7224         return "lea (%%pc, _GLOBAL_OFFSET_TABLE_@GOTPC), %0";
7225     }
7226   else
7227     return ("movel #_GLOBAL_OFFSET_TABLE_, %0\n\t"
7228             "lea %%pc@(0,%0:l),%0");
7229 })
7230
7231 (define_insn "indirect_jump"
7232   [(set (pc) (match_operand:SI 0 "address_operand" "p"))]
7233   ""
7234   "jmp %a0"
7235   [(set_attr "type" "jmp")])
7236 \f
7237 ;; This should not be used unless the add/sub insns can't be.
7238
7239 (define_insn "*lea"
7240   [(set (match_operand:SI 0 "nonimmediate_operand" "=a")
7241         (match_operand:QI 1 "address_operand" "p"))]
7242   ""
7243   "lea %a1,%0")
7244 \f
7245 ;; This is the first machine-dependent peephole optimization.
7246 ;; It is useful when a floating value is returned from a function call
7247 ;; and then is moved into an FP register.
7248 ;; But it is mainly intended to test the support for these optimizations.
7249
7250 (define_peephole2
7251   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))
7252    (set (match_operand:DF 0 "register_operand" "")
7253         (match_operand:DF 1 "register_operand" ""))]
7254   "FP_REG_P (operands[0]) && !FP_REG_P (operands[1])"
7255   [(set (mem:SI (reg:SI SP_REG)) (match_dup 1))
7256    (set (mem:SI (pre_dec:SI (reg:SI SP_REG))) (match_dup 2))
7257    (set (match_dup 0) (mem:DF (post_inc:SI (reg:SI SP_REG))))]
7258   "split_di(operands + 1, 1, operands + 1, operands + 2);")
7259
7260 ;; Optimize a stack-adjust followed by a push of an argument.
7261 ;; This is said to happen frequently with -msoft-float
7262 ;; when there are consecutive library calls.
7263
7264 (define_peephole2
7265   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))
7266    (set (match_operand:SF 0 "push_operand" "")
7267         (match_operand:SF 1 "general_operand" ""))]
7268   "!reg_mentioned_p (stack_pointer_rtx, operands[0])"
7269   [(set (match_dup 0) (match_dup 1))]
7270   "operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);")
7271
7272 (define_peephole2
7273   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
7274                                  (match_operand:SI 0 "const_int_operand" "")))
7275    (set (match_operand:SF 1 "push_operand" "")
7276         (match_operand:SF 2 "general_operand" ""))]
7277   "INTVAL (operands[0]) > 4
7278    && !reg_mentioned_p (stack_pointer_rtx, operands[2])"
7279   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (match_dup 0)))
7280    (set (match_dup 1) (match_dup 2))]
7281 {
7282   operands[0] = GEN_INT (INTVAL (operands[0]) - 4);
7283   operands[1] = replace_equiv_address (operands[1], stack_pointer_rtx);
7284 })
7285
7286 ;; Speed up stack adjust followed by a fullword fixedpoint push.
7287 ;; Constant operands need special care, as replacing a "pea X.w" with
7288 ;; "move.l #X,(%sp)" is often not a win.
7289
7290 ;; Already done by the previous csa pass, left as reference.
7291 (define_peephole2
7292   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))
7293    (set (match_operand:SI 0 "push_operand" "")
7294         (match_operand:SI 1 "general_operand" ""))]
7295   "!reg_mentioned_p (stack_pointer_rtx, operands[1])"
7296   [(set (match_dup 0) (match_dup 1))]
7297   "operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);")
7298
7299 ;; Try to use moveq, after stack push has been changed into a simple move.
7300 (define_peephole2
7301   [(match_scratch:SI 2 "d")
7302    (set (match_operand:SI 0 "memory_operand" "")
7303         (match_operand:SI 1 "const_int_operand" ""))]
7304   "GET_CODE (XEXP (operands[0], 0)) != PRE_DEC
7305    && INTVAL (operands[1]) != 0
7306    && IN_RANGE (INTVAL (operands[1]), -0x80, 0x7f)
7307    && !valid_mov3q_const (INTVAL (operands[1]))"
7308   [(set (match_dup 2) (match_dup 1))
7309    (set (match_dup 0) (match_dup 2))])
7310
7311 ;; This sequence adds an instruction, but is two bytes shorter.
7312 (define_peephole2
7313   [(match_scratch:SI 2 "d")
7314    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 12)))
7315    (set (match_operand:SI 0 "push_operand" "")
7316         (match_operand:SI 1 "const_int_operand" ""))]
7317   "INTVAL (operands[1]) != 0
7318    && IN_RANGE (INTVAL (operands[1]), -0x80, 0x7f)
7319    && !valid_mov3q_const (INTVAL (operands[1]))"
7320   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 8)))
7321    (set (match_dup 2) (match_dup 1))
7322    (set (match_dup 0) (match_dup 2))]
7323   "operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);")
7324
7325 ;; Changing pea X.w into a move.l is no real win here.
7326 (define_peephole2
7327   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
7328                                  (match_operand:SI 0 "const_int_operand" "")))
7329    (set (match_operand:SI 1 "push_operand" "")
7330         (match_operand:SI 2 "general_operand" ""))]
7331   "INTVAL (operands[0]) > 4
7332    && !reg_mentioned_p (stack_pointer_rtx, operands[2])
7333    && !(CONST_INT_P (operands[2]) && INTVAL (operands[2]) != 0
7334         && IN_RANGE (INTVAL (operands[2]), -0x8000, 0x7fff)
7335         && !valid_mov3q_const (INTVAL (operands[2])))"
7336   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (match_dup 0)))
7337    (set (match_dup 1) (match_dup 2))]
7338 {
7339   operands[0] = GEN_INT (INTVAL (operands[0]) - 4);
7340   operands[1] = replace_equiv_address (operands[1], stack_pointer_rtx);
7341 })
7342
7343 ;; Speed up pushing a single byte/two bytes but leaving four bytes of space
7344 ;; (which differs slightly between m680x0 and ColdFire).
7345
7346 (define_peephole2
7347   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int -4)))
7348    (set (match_operand:QI 0 "memory_operand" "")
7349         (match_operand:QI 1 "register_operand" ""))]
7350   "!reg_mentioned_p (stack_pointer_rtx, operands[1])
7351    && GET_CODE (XEXP (operands[0], 0)) == PLUS
7352    && rtx_equal_p (XEXP (XEXP (operands[0], 0), 0), stack_pointer_rtx)
7353    && CONST_INT_P (XEXP (XEXP (operands[0], 0), 1))
7354    && INTVAL (XEXP (XEXP (operands[0], 0), 1)) == 3"
7355   [(set (match_dup 0) (match_dup 1))]
7356 {
7357   rtx addr = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx);
7358   operands[0] = adjust_automodify_address (operands[0], SImode, addr, -3);
7359   operands[1] = simplify_gen_subreg (SImode, operands[1], QImode, 0);
7360 })
7361
7362 (define_peephole2
7363   [(set (match_operand:QI 0 "push_operand" "")
7364         (match_operand:QI 1 "register_operand" ""))
7365    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int -3)))]
7366   "!reg_mentioned_p (stack_pointer_rtx, operands[1])"
7367   [(set (match_dup 0) (match_dup 1))]
7368 {
7369   operands[0] = adjust_automodify_address (operands[0], SImode,
7370                                            XEXP (operands[0], 0), -3);
7371   operands[1] = simplify_gen_subreg (SImode, operands[1], QImode, 0);
7372 })
7373
7374 (define_peephole2
7375   [(set (match_operand:HI 0 "push_operand" "")
7376         (match_operand:HI 1 "register_operand" ""))
7377    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int -2)))]
7378   "!reg_mentioned_p (stack_pointer_rtx, operands[1])"
7379   [(set (match_dup 0) (match_dup 1))]
7380 {
7381   operands[0] = adjust_automodify_address (operands[0], SImode,
7382                                            XEXP (operands[0], 0), -2);
7383   operands[1] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
7384 })
7385
7386 ;; Optimize a series of strict_low_part assignments
7387
7388 (define_peephole2
7389   [(set (match_operand:SI 0 "register_operand" "")
7390         (const_int 0))
7391    (set (strict_low_part (match_operand:HI 1 "register_operand" ""))
7392         (match_operand:HI 2 "general_operand" ""))]
7393   "REGNO (operands[0]) == REGNO (operands[1])
7394    && strict_low_part_peephole_ok (HImode, insn, operands[0])"
7395   [(set (strict_low_part (match_dup 1)) (match_dup 2))]
7396   "")
7397
7398 (define_peephole2
7399   [(set (match_operand:SI 0 "register_operand" "")
7400         (const_int 0))
7401    (set (strict_low_part (match_operand:QI 1 "register_operand" ""))
7402         (match_operand:QI 2 "general_operand" ""))]
7403   "REGNO (operands[0]) == REGNO (operands[1])
7404    && strict_low_part_peephole_ok (QImode, insn, operands[0])"
7405   [(set (strict_low_part (match_dup 1)) (match_dup 2))]
7406   "")
7407
7408 ;; dbCC peepholes
7409 ;;
7410 ;; Turns
7411 ;;   loop:
7412 ;;           [ ... ]
7413 ;;           jCC label          ; abnormal loop termination
7414 ;;           dbra dN, loop      ; normal loop termination
7415 ;;
7416 ;; Into
7417 ;;   loop:
7418 ;;           [ ... ]
7419 ;;           dbCC dN, loop
7420 ;;           jCC label
7421 ;;
7422 ;; Which moves the jCC condition outside the inner loop for free.
7423 ;;
7424
7425 (define_peephole
7426   [(set (pc) (if_then_else (match_operator 3 "valid_dbcc_comparison_p"
7427                              [(cc0) (const_int 0)])
7428                            (label_ref (match_operand 2 "" ""))
7429                            (pc)))
7430    (parallel
7431     [(set (pc)
7432           (if_then_else
7433             (ne (match_operand:HI 0 "register_operand" "")
7434                 (const_int 0))
7435             (label_ref (match_operand 1 "" ""))
7436             (pc)))
7437      (set (match_dup 0)
7438           (plus:HI (match_dup 0)
7439                    (const_int -1)))])]
7440   "!TARGET_COLDFIRE && DATA_REG_P (operands[0]) && ! flags_in_68881 ()"
7441 {
7442   CC_STATUS_INIT;
7443   output_dbcc_and_branch (operands);
7444   return "";
7445 })
7446
7447 (define_peephole
7448   [(set (pc) (if_then_else (match_operator 3 "valid_dbcc_comparison_p"
7449                              [(cc0) (const_int 0)])
7450                            (label_ref (match_operand 2 "" ""))
7451                            (pc)))
7452    (parallel
7453     [(set (pc)
7454           (if_then_else
7455             (ne (match_operand:SI 0 "register_operand" "")
7456                 (const_int 0))
7457             (label_ref (match_operand 1 "" ""))
7458             (pc)))
7459      (set (match_dup 0)
7460           (plus:SI (match_dup 0)
7461                    (const_int -1)))])]
7462   "!TARGET_COLDFIRE && DATA_REG_P (operands[0]) && ! flags_in_68881 ()"
7463 {
7464   CC_STATUS_INIT;
7465   output_dbcc_and_branch (operands);
7466   return "";
7467 })
7468
7469 (define_peephole
7470   [(set (pc) (if_then_else (match_operator 3 "valid_dbcc_comparison_p"
7471                              [(cc0) (const_int 0)])
7472                            (label_ref (match_operand 2 "" ""))
7473                            (pc)))
7474    (parallel
7475     [(set (pc)
7476           (if_then_else
7477             (ge (plus:HI (match_operand:HI 0 "register_operand" "")
7478                          (const_int -1))
7479                 (const_int 0))
7480             (label_ref (match_operand 1 "" ""))
7481             (pc)))
7482      (set (match_dup 0)
7483           (plus:HI (match_dup 0)
7484                    (const_int -1)))])]
7485   "!TARGET_COLDFIRE && DATA_REG_P (operands[0]) && ! flags_in_68881 ()"
7486 {
7487   CC_STATUS_INIT;
7488   output_dbcc_and_branch (operands);
7489   return "";
7490 })
7491
7492 (define_peephole
7493   [(set (pc) (if_then_else (match_operator 3 "valid_dbcc_comparison_p"
7494                              [(cc0) (const_int 0)])
7495                            (label_ref (match_operand 2 "" ""))
7496                            (pc)))
7497    (parallel
7498     [(set (pc)
7499           (if_then_else
7500             (ge (plus:SI (match_operand:SI 0 "register_operand" "")
7501                          (const_int -1))
7502                 (const_int 0))
7503             (label_ref (match_operand 1 "" ""))
7504             (pc)))
7505      (set (match_dup 0)
7506           (plus:SI (match_dup 0)
7507                    (const_int -1)))])]
7508   "!TARGET_COLDFIRE && DATA_REG_P (operands[0]) && ! flags_in_68881 ()"
7509 {
7510   CC_STATUS_INIT;
7511   output_dbcc_and_branch (operands);
7512   return "";
7513 })
7514
7515 \f
7516 (define_insn "extendsfxf2"
7517   [(set (match_operand:XF 0 "nonimmediate_operand" "=fm,f")
7518         (float_extend:XF (match_operand:SF 1 "general_operand" "f,rmF")))]
7519   "TARGET_68881"
7520 {
7521   if (FP_REG_P (operands[0]) && FP_REG_P (operands[1]))
7522     {
7523       if (REGNO (operands[0]) == REGNO (operands[1]))
7524         {
7525           /* Extending float to double in an fp-reg is a no-op.
7526              NOTICE_UPDATE_CC has already assumed that the
7527              cc will be set.  So cancel what it did.  */
7528           cc_status = cc_prev_status;
7529           return "";
7530         }
7531       return "f%$move%.x %1,%0";
7532     }
7533   if (FP_REG_P (operands[0]))
7534     {
7535       if (FP_REG_P (operands[1]))
7536         return "f%$move%.x %1,%0";
7537       else if (ADDRESS_REG_P (operands[1]))
7538         return "move%.l %1,%-\;f%$move%.s %+,%0";
7539       else if (GET_CODE (operands[1]) == CONST_DOUBLE)
7540         return output_move_const_single (operands);
7541       return "f%$move%.s %f1,%0";
7542     }
7543   return "fmove%.x %f1,%0";
7544 })
7545
7546
7547 (define_insn "extenddfxf2"
7548   [(set (match_operand:XF 0 "nonimmediate_operand" "=fm,f")
7549         (float_extend:XF
7550           (match_operand:DF 1 "general_operand" "f,rmE")))]
7551   "TARGET_68881"
7552 {
7553   if (FP_REG_P (operands[0]) && FP_REG_P (operands[1]))
7554     {
7555       if (REGNO (operands[0]) == REGNO (operands[1]))
7556         {
7557           /* Extending float to double in an fp-reg is a no-op.
7558              NOTICE_UPDATE_CC has already assumed that the
7559              cc will be set.  So cancel what it did.  */
7560           cc_status = cc_prev_status;
7561           return "";
7562         }
7563       return "fmove%.x %1,%0";
7564     }
7565   if (FP_REG_P (operands[0]))
7566     {
7567       if (REG_P (operands[1]))
7568         {
7569           rtx xoperands[2];
7570           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
7571           output_asm_insn ("move%.l %1,%-", xoperands);
7572           output_asm_insn ("move%.l %1,%-", operands);
7573           return "f%&move%.d %+,%0";
7574         }
7575       if (GET_CODE (operands[1]) == CONST_DOUBLE)
7576         return output_move_const_double (operands);
7577       return "f%&move%.d %f1,%0";
7578     }
7579   return "fmove%.x %f1,%0";
7580 })
7581
7582 (define_insn "truncxfdf2"
7583   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,!r")
7584         (float_truncate:DF
7585           (match_operand:XF 1 "general_operand" "f,f")))]
7586   "TARGET_68881"
7587 {
7588   if (REG_P (operands[0]))
7589     {
7590       output_asm_insn ("fmove%.d %f1,%-\;move%.l %+,%0", operands);
7591       operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
7592       return "move%.l %+,%0";
7593     }
7594   return "fmove%.d %f1,%0";
7595 })
7596
7597 (define_insn "truncxfsf2"
7598   [(set (match_operand:SF 0 "nonimmediate_operand" "=dm")
7599         (float_truncate:SF
7600           (match_operand:XF 1 "general_operand" "f")))]
7601   "TARGET_68881"
7602   "fmove%.s %f1,%0")
7603
7604 (define_insn "sin<mode>2"
7605   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
7606         (unspec:FP
7607           [(match_operand:FP 1 "general_operand" "f<FP:dreg>m")] UNSPEC_SIN))]
7608   "TARGET_68881 && flag_unsafe_math_optimizations"
7609 {
7610   if (FP_REG_P (operands[1]))
7611     return "fsin%.x %1,%0";
7612   else
7613     return "fsin%.<FP:prec> %1,%0";
7614 })
7615
7616 (define_insn "cos<mode>2"
7617   [(set (match_operand:FP 0 "nonimmediate_operand" "=f")
7618         (unspec:FP
7619           [(match_operand:FP 1 "general_operand" "f<FP:dreg>m")] UNSPEC_COS))]
7620   "TARGET_68881 && flag_unsafe_math_optimizations"
7621 {
7622   if (FP_REG_P (operands[1]))
7623     return "fcos%.x %1,%0";
7624   else
7625     return "fcos%.<FP:prec> %1,%0";
7626 })
7627
7628 ;; Unconditional traps are assumed to have (const_int 1) for the condition.
7629 (define_insn "trap"
7630   [(trap_if (const_int 1) (const_int 7))]
7631   ""
7632   "trap #7"
7633   [(set_attr "type" "trap")])
7634
7635 (define_expand "conditional_trap"
7636   [(trap_if (match_operator 0 "valid_dbcc_comparison_p"
7637                             [(cc0) (const_int 0)])
7638             (match_operand:SI 1 "const_int_operand" "I"))]
7639   "TARGET_68020"
7640 {
7641   if (m68k_last_compare_had_fp_operands)
7642     {
7643       m68k_last_compare_had_fp_operands = 0;
7644       FAIL;
7645     }
7646 })
7647
7648 (define_insn "*conditional_trap"
7649   [(trap_if (match_operator 0 "valid_dbcc_comparison_p"
7650                             [(cc0) (const_int 0)])
7651             (match_operand:SI 1 "const_int_operand" "I"))]
7652   "TARGET_68020 && ! flags_in_68881 ()"
7653 {
7654   switch (GET_CODE (operands[0]))
7655   {
7656   case EQ:  return "trapeq";
7657   case NE:  return "trapne";
7658   case GT:  return "trapgt";
7659   case GTU: return "traphi";
7660   case LT:  return "traplt";
7661   case LTU: return "trapcs";
7662   case GE:  return "trapge";
7663   case GEU: return "trapcc";
7664   case LE:  return "traple";
7665   case LEU: return "trapls";
7666   default: gcc_unreachable ();
7667   }
7668 })
7669
7670 ;; These are to prevent the scheduler from moving stores to the frame
7671 ;; before the stack adjustment.
7672 (define_insn "stack_tie"
7673   [(set (mem:BLK (scratch))
7674         (unspec:BLK [(match_operand:SI 0 "register_operand" "r")
7675                      (match_operand:SI 1 "register_operand" "r")]
7676                     UNSPEC_TIE))]
7677   ""
7678   ""
7679   [(set_attr "type" "ignore")])
7680
7681 ;; Instruction that subscribes one word in ColdFire instruction buffer.
7682 ;; This instruction is used within scheduler only and should not appear
7683 ;; in the instruction stream.
7684 (define_insn "ib"
7685   [(unspec [(const_int 0)] UNSPEC_IB)]
7686   ""
7687   "#"
7688   [(set_attr "type" "ib")])
7689
7690 (include "cf.md")