OSDN Git Service

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