OSDN Git Service

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