OSDN Git Service

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