OSDN Git Service

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