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