OSDN Git Service

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