OSDN Git Service

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