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