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