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