Update FSF address.
[official-gcc.git] / gcc / config / m68k / m68k.md
blob3e3f99c5cdafb8329511fb5762c9805a66d59a6d
1 ;;- Machine description for GNU compiler, Motorola 68000 Version
2 ;;  Copyright (C) 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
3 ;;  2002, 2003, 2004, 2005
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, 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, 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 (include "predicates.md")
134 (define_insn ""
135   [(set (match_operand:DF 0 "push_operand" "=m")
136         (match_operand:DF 1 "general_operand" "ro<>fyE"))]
137   ""
139   if (FP_REG_P (operands[1]))
140     return "fmove%.d %f1,%0";
141   return output_move_double (operands);
144 (define_insn "pushdi"
145   [(set (match_operand:DI 0 "push_operand" "=m")
146         (match_operand:DI 1 "general_operand" "ro<>Fyi"))]
147   ""
149   return output_move_double (operands);
152 ;; We don't want to allow a constant operand for test insns because
153 ;; (set (cc0) (const_int foo)) has no mode information.  Such insns will
154 ;; be folded while optimizing anyway.
156 (define_expand "tstdi"
157   [(parallel [(set (cc0)
158                    (match_operand:DI 0 "nonimmediate_operand" ""))
159               (clobber (match_scratch:SI 1 ""))
160               (clobber (match_scratch:DI 2 ""))])]
161   ""
162   "m68k_last_compare_had_fp_operands = 0;")
164 (define_insn ""
165   [(set (cc0)
166         (match_operand:DI 0 "nonimmediate_operand" "am,d"))
167    (clobber (match_scratch:SI 1 "=X,d"))
168    (clobber (match_scratch:DI 2 "=d,X"))]
169   ""
171   if (which_alternative == 0)
172     {
173       rtx xoperands[2];
175       xoperands[0] = operands[2];
176       xoperands[1] = operands[0];
177       output_move_double (xoperands);
178       cc_status.flags |= CC_REVERSED;
179       return "neg%.l %R2\;negx%.l %2";
180     }
181   if (find_reg_note (insn, REG_DEAD, operands[0]))
182     {
183       cc_status.flags |= CC_REVERSED;
184       return "neg%.l %R0\;negx%.l %0";
185     }
186   else
187     /*
188        'sub' clears %1, and also clears the X cc bit
189        'tst' sets the Z cc bit according to the low part of the DImode operand
190        'subx %1' (i.e. subx #0) acts as a (non-existent) tstx on the high part.
191     */
192     return "sub%.l %1,%1\;tst%.l %R0\;subx%.l %1,%0";
195 (define_expand "tstsi"
196   [(set (cc0)
197         (match_operand:SI 0 "nonimmediate_operand" ""))]
198   ""
199   "m68k_last_compare_had_fp_operands = 0;")
201 (define_insn ""
202   [(set (cc0)
203         (match_operand:SI 0 "nonimmediate_operand" "rm"))]
204   ""
206   if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (operands[0]))
207     return "tst%.l %0";
208   /* If you think that the 68020 does not support tstl a0,
209      reread page B-167 of the 68020 manual more carefully.  */
210   /* On an address reg, cmpw may replace cmpl.  */
211   return "cmp%.w #0,%0";
214 ;; This can't use an address register, because comparisons
215 ;; with address registers as second operand always test the whole word.
216 (define_expand "tsthi"
217   [(set (cc0)
218         (match_operand:HI 0 "nonimmediate_operand" ""))]
219   ""
220   "m68k_last_compare_had_fp_operands = 0;")
222 (define_insn ""
223   [(set (cc0)
224         (match_operand:HI 0 "nonimmediate_operand" "dm"))]
225   ""
226   "tst%.w %0")
228 (define_expand "tstqi"
229   [(set (cc0)
230         (match_operand:QI 0 "nonimmediate_operand" ""))]
231   ""
232   "m68k_last_compare_had_fp_operands = 0;")
234 (define_insn ""
235   [(set (cc0)
236         (match_operand:QI 0 "nonimmediate_operand" "dm"))]
237   ""
238   "tst%.b %0")
240 (define_expand "tstsf"
241   [(set (cc0)
242         (match_operand:SF 0 "general_operand" ""))]
243   "TARGET_68881"
245   m68k_last_compare_had_fp_operands = 1;
248 (define_insn ""
249   [(set (cc0)
250         (match_operand:SF 0 "general_operand" "fdm"))]
251   "TARGET_68881"
253   cc_status.flags = CC_IN_68881;
254   if (FP_REG_P (operands[0]))
255     return "ftst%.x %0";
256   return "ftst%.s %0";
259 (define_expand "tstdf"
260   [(set (cc0)
261         (match_operand:DF 0 "general_operand" ""))]
262   "TARGET_68881"
264   m68k_last_compare_had_fp_operands = 1;
267 (define_insn ""
268   [(set (cc0)
269         (match_operand:DF 0 "general_operand" "fm"))]
270   "TARGET_68881"
272   cc_status.flags = CC_IN_68881;
273   if (FP_REG_P (operands[0]))
274     return "ftst%.x %0";
275   return "ftst%.d %0";
278 ;; compare instructions.
280 (define_expand "cmpdi"
281   [(parallel
282     [(set (cc0)
283           (compare (match_operand:DI 0 "nonimmediate_operand" "")
284                    (match_operand:DI 1 "general_operand" "")))
285      (clobber (match_dup 2))])]
286   ""
287   "m68k_last_compare_had_fp_operands = 0; operands[2] = gen_reg_rtx (DImode);")
289 (define_insn ""
290   [(set (cc0)
291         (compare (match_operand:DI 1 "nonimmediate_operand" "0,d")
292                  (match_operand:DI 2 "general_operand" "d,0")))
293    (clobber (match_operand:DI 0 "register_operand" "=d,d"))]
294   ""
296   if (rtx_equal_p (operands[0], operands[1]))
297     return "sub%.l %R2,%R0\;subx%.l %2,%0";
298   else
299     {
300       cc_status.flags |= CC_REVERSED;
301       return "sub%.l %R1,%R0\;subx%.l %1,%0";
302     }
305 ;; This is the second "hook" for PIC code (in addition to movsi). See
306 ;; comment of movsi for a description of PIC handling.
307 (define_expand "cmpsi"
308   [(set (cc0)
309         (compare (match_operand:SI 0 "nonimmediate_operand" "")
310                  (match_operand:SI 1 "general_operand" "")))]
311   ""
313   m68k_last_compare_had_fp_operands = 0;
314   if (flag_pic && !TARGET_PCREL && symbolic_operand (operands[1], SImode))
315     {
316       /* The source is an address which requires PIC relocation.
317          Call legitimize_pic_address with the source, mode, and a relocation
318          register (a new pseudo, or the final destination if reload_in_progress
319          is set).   Then fall through normally */
320       rtx temp = reload_in_progress ? operands[0] : gen_reg_rtx (Pmode);
321       operands[1] = legitimize_pic_address (operands[1], SImode, temp);
322     }
325 ;; A composite of the cmp, cmpa, cmpi & cmpm m68000 op codes.
326 (define_insn ""
327   [(set (cc0)
328         (compare (match_operand:SI 0 "nonimmediate_operand" "rKT,rKs,mSr,mSa,>")
329                  (match_operand:SI 1 "general_src_operand" "mSr,mSa,KTr,Ksr,>")))]
330   "!TARGET_COLDFIRE"
332   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
333     return "cmpm%.l %1,%0";
334   if (REG_P (operands[1])
335       || (!REG_P (operands[0]) && GET_CODE (operands[0]) != MEM))
336     {
337       cc_status.flags |= CC_REVERSED;
338       return "cmp%.l %d0,%d1";
339     }
340   if (ADDRESS_REG_P (operands[0])
341       && GET_CODE (operands[1]) == CONST_INT
342       && INTVAL (operands[1]) < 0x8000
343       && INTVAL (operands[1]) >= -0x8000)
344     return "cmp%.w %1,%0";
345   return "cmp%.l %d1,%d0";
348 (define_insn ""
349   [(set (cc0)
350         (compare (match_operand:SI 0 "nonimmediate_operand" "mrKs,r")
351                  (match_operand:SI 1 "general_operand" "r,mrKs")))]
352   "TARGET_COLDFIRE"
354   if (REG_P (operands[1])
355       || (!REG_P (operands[0]) && GET_CODE (operands[0]) != MEM))
356     {
357       cc_status.flags |= CC_REVERSED;
358       return "cmp%.l %d0,%d1";
359     }
360   return "cmp%.l %d1,%d0";
363 (define_expand "cmphi"
364   [(set (cc0)
365         (compare (match_operand:HI 0 "nonimmediate_src_operand" "")
366                  (match_operand:HI 1 "general_src_operand" "")))]
367   "!TARGET_COLDFIRE"
368   "m68k_last_compare_had_fp_operands = 0;")
370 (define_insn ""
371   [(set (cc0)
372         (compare (match_operand:HI 0 "nonimmediate_src_operand" "rnmS,d,n,mS,>")
373                  (match_operand:HI 1 "general_src_operand" "d,rnmS,mS,n,>")))]
374   "!TARGET_COLDFIRE"
376   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
377     return "cmpm%.w %1,%0";
378   if ((REG_P (operands[1]) && !ADDRESS_REG_P (operands[1]))
379       || (!REG_P (operands[0]) && GET_CODE (operands[0]) != MEM))
380     {
381       cc_status.flags |= CC_REVERSED;
382       return "cmp%.w %d0,%d1";
383     }
384   return "cmp%.w %d1,%d0";
387 (define_expand "cmpqi"
388   [(set (cc0)
389         (compare (match_operand:QI 0 "nonimmediate_src_operand" "")
390                  (match_operand:QI 1 "general_src_operand" "")))]
391   "!TARGET_COLDFIRE"
392   "m68k_last_compare_had_fp_operands = 0;")
394 (define_insn ""
395   [(set (cc0)
396         (compare (match_operand:QI 0 "nonimmediate_src_operand" "dn,dmS,>")
397                  (match_operand:QI 1 "general_src_operand" "dmS,nd,>")))]
398   "!TARGET_COLDFIRE"
400   if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM)
401     return "cmpm%.b %1,%0";
402   if (REG_P (operands[1])
403       || (!REG_P (operands[0]) && GET_CODE (operands[0]) != MEM))
404     {
405       cc_status.flags |= CC_REVERSED;
406       return "cmp%.b %d0,%d1";
407     }
408   return "cmp%.b %d1,%d0";
411 (define_expand "cmpdf"
412   [(set (cc0)
413         (compare (match_operand:DF 0 "general_operand" "")
414                  (match_operand:DF 1 "general_operand" "")))]
415   "TARGET_68881"
417   m68k_last_compare_had_fp_operands = 1;
420 (define_insn ""
421   [(set (cc0)
422         (compare (match_operand:DF 0 "general_operand" "f,mG")
423                  (match_operand:DF 1 "general_operand" "fmG,f")))]
424   "TARGET_68881"
426   cc_status.flags = CC_IN_68881;
427   if (REG_P (operands[0]))
428     {
429       if (REG_P (operands[1]))
430         return "fcmp%.x %1,%0";
431       else
432         return "fcmp%.d %f1,%0";
433     }
434   cc_status.flags |= CC_REVERSED;
435   return "fcmp%.d %f0,%1";
438 (define_expand "cmpsf"
439  [(set (cc0)
440        (compare (match_operand:SF 0 "general_operand" "")
441                 (match_operand:SF 1 "general_operand" "")))]
442  "TARGET_68881"
444   m68k_last_compare_had_fp_operands = 1;
447 (define_insn ""
448   [(set (cc0)
449         (compare (match_operand:SF 0 "general_operand" "f,mdG")
450                  (match_operand:SF 1 "general_operand" "fmdG,f")))]
451   "TARGET_68881"
453   cc_status.flags = CC_IN_68881;
454   if (FP_REG_P (operands[0]))
455     {
456       if (FP_REG_P (operands[1]))
457         return "fcmp%.x %1,%0";
458       else
459         return "fcmp%.s %f1,%0";
460     }
461   cc_status.flags |= CC_REVERSED;
462   return "fcmp%.s %f0,%1";
465 ;; Recognizers for btst instructions.
467 ;; ColdFire/5200 only allows "<Q>" type addresses when the bit position is
468 ;; specified as a constant, so we must disable all patterns that may extract
469 ;; from a MEM at a constant bit position if we can't use this as a constraint.
471 (define_insn ""
472   [(set (cc0) (zero_extract (match_operand:QI 0 "memory_src_operand" "oS")
473                             (const_int 1)
474                             (minus:SI (const_int 7)
475                                       (match_operand:SI 1 "general_operand" "di"))))]
476   "!TARGET_COLDFIRE"
478   return output_btst (operands, operands[1], operands[0], insn, 7);
481 ;; This is the same as the above pattern except for the constraints.  The 'i'
482 ;; has been deleted.
484 (define_insn ""
485   [(set (cc0) (zero_extract (match_operand:QI 0 "memory_operand" "o")
486                             (const_int 1)
487                             (minus:SI (const_int 7)
488                                       (match_operand:SI 1 "general_operand" "d"))))]
489   "TARGET_COLDFIRE"
491   return output_btst (operands, operands[1], operands[0], insn, 7);
494 (define_insn ""
495   [(set (cc0) (zero_extract (match_operand:SI 0 "register_operand" "d")
496                             (const_int 1)
497                             (minus:SI (const_int 31)
498                                       (match_operand:SI 1 "general_operand" "di"))))]
499   ""
501   return output_btst (operands, operands[1], operands[0], insn, 31);
504 ;; The following two patterns are like the previous two
505 ;; except that they use the fact that bit-number operands
506 ;; are automatically masked to 3 or 5 bits.
508 (define_insn ""
509   [(set (cc0) (zero_extract (match_operand:QI 0 "memory_operand" "o")
510                             (const_int 1)
511                             (minus:SI (const_int 7)
512                                       (and:SI
513                                        (match_operand:SI 1 "register_operand" "d")
514                                        (const_int 7)))))]
515   ""
517   return output_btst (operands, operands[1], operands[0], insn, 7);
520 (define_insn ""
521   [(set (cc0) (zero_extract (match_operand:SI 0 "register_operand" "d")
522                             (const_int 1)
523                             (minus:SI (const_int 31)
524                                       (and:SI
525                                        (match_operand:SI 1 "register_operand" "d")
526                                        (const_int 31)))))]
527   ""
529   return output_btst (operands, operands[1], operands[0], insn, 31);
532 ;; Nonoffsettable mem refs are ok in this one pattern
533 ;; since we don't try to adjust them.
534 (define_insn ""
535   [(set (cc0) (zero_extract (match_operand:QI 0 "memory_operand" "m")
536                             (const_int 1)
537                             (match_operand:SI 1 "const_int_operand" "n")))]
538   "(unsigned) INTVAL (operands[1]) < 8 && !TARGET_COLDFIRE"
540   operands[1] = GEN_INT (7 - INTVAL (operands[1]));
541   return output_btst (operands, operands[1], operands[0], insn, 7);
544 (define_insn ""
545   [(set (cc0) (zero_extract (match_operand:SI 0 "register_operand" "do")
546                             (const_int 1)
547                             (match_operand:SI 1 "const_int_operand" "n")))]
548   "!TARGET_COLDFIRE"
550   if (GET_CODE (operands[0]) == MEM)
551     {
552       operands[0] = adjust_address (operands[0], QImode,
553                                     INTVAL (operands[1]) / 8);
554       operands[1] = GEN_INT (7 - INTVAL (operands[1]) % 8);
555       return output_btst (operands, operands[1], operands[0], insn, 7);
556     }
557   operands[1] = GEN_INT (31 - INTVAL (operands[1]));
558   return output_btst (operands, operands[1], operands[0], insn, 31);
561 ;; This is the same as the above pattern except for the constraints.
562 ;; The 'o' has been replaced with 'Q'.
564 (define_insn ""
565   [(set (cc0) (zero_extract (match_operand:SI 0 "register_operand" "dQ")
566                             (const_int 1)
567                             (match_operand:SI 1 "const_int_operand" "n")))]
568   "TARGET_COLDFIRE"
570   if (GET_CODE (operands[0]) == MEM)
571     {
572       operands[0] = adjust_address (operands[0], QImode,
573                                     INTVAL (operands[1]) / 8);
574       operands[1] = GEN_INT (7 - INTVAL (operands[1]) % 8);
575       return output_btst (operands, operands[1], operands[0], insn, 7);
576     }
577   operands[1] = GEN_INT (31 - INTVAL (operands[1]));
578   return output_btst (operands, operands[1], operands[0], insn, 31);
582 ;; move instructions
584 ;; A special case in which it is not desirable
585 ;; to reload the constant into a data register.
586 (define_insn "pushexthisi_const"
587   [(set (match_operand:SI 0 "push_operand" "=m")
588         (match_operand:SI 1 "const_int_operand" "J"))]
589   "INTVAL (operands[1]) >= -0x8000 && INTVAL (operands[1]) < 0x8000"
591   if (operands[1] == const0_rtx)
592     return "clr%.l %0";
593   if (valid_mov3q_const(operands[1]))
594     return "mov3q%.l %1,%-";
595   return "pea %a1";
598 ;This is never used.
599 ;(define_insn "swapsi"
600 ;  [(set (match_operand:SI 0 "nonimmediate_operand" "+r")
601 ;       (match_operand:SI 1 "general_operand" "+r"))
602 ;   (set (match_dup 1) (match_dup 0))]
603 ;  ""
604 ;  "exg %1,%0")
606 ;; Special case of fullword move when source is zero.
607 ;; The reason this is special is to avoid loading a zero
608 ;; into a data reg with moveq in order to store it elsewhere.
610 (define_insn "movsi_const0"
611   [(set (match_operand:SI 0 "nonimmediate_operand" "=g")
612         (const_int 0))]
613   ;; clr insns on 68000 read before writing.
614   ;; This isn't so on the 68010, but we have no TARGET_68010.
615   "((TARGET_68020 || TARGET_COLDFIRE)
616     || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0])))"
618   if (ADDRESS_REG_P (operands[0]))
619     {
620       /* On the '040, 'subl an,an' takes 2 clocks while lea takes only 1 */
621       if (!TARGET_68040 && !TARGET_68060)
622         return "sub%.l %0,%0";
623       else
624         return MOTOROLA ? "lea 0.w,%0" : "lea 0:w,%0";
625     }
626   /* moveq is faster on the 68000.  */
627   if (DATA_REG_P (operands[0]) && (!TARGET_68020 && !TARGET_COLDFIRE))
628     return "moveq #0,%0";
629   return "clr%.l %0";
632 ;; General case of fullword move.
634 ;; This is the main "hook" for PIC code.  When generating
635 ;; PIC, movsi is responsible for determining when the source address
636 ;; needs PIC relocation and appropriately calling legitimize_pic_address
637 ;; to perform the actual relocation.
639 ;; In both the PIC and non-PIC cases the patterns generated will
640 ;; matched by the next define_insn.
641 (define_expand "movsi"
642   [(set (match_operand:SI 0 "nonimmediate_operand" "")
643         (match_operand:SI 1 "general_operand" ""))]
644   ""
646   if (flag_pic && !TARGET_PCREL && symbolic_operand (operands[1], SImode))
647     {
648       /* The source is an address which requires PIC relocation.
649          Call legitimize_pic_address with the source, mode, and a relocation
650          register (a new pseudo, or the final destination if reload_in_progress
651          is set).   Then fall through normally */
652       rtx temp = reload_in_progress ? operands[0] : gen_reg_rtx (Pmode);
653       operands[1] = legitimize_pic_address (operands[1], SImode, temp);
654     }
655   else if (flag_pic && TARGET_PCREL && ! reload_in_progress)
656     {
657       /* Don't allow writes to memory except via a register;
658          the m68k doesn't consider PC-relative addresses to be writable.  */
659       if (symbolic_operand (operands[0], SImode))
660         operands[0] = force_reg (SImode, XEXP (operands[0], 0));
661       else if (GET_CODE (operands[0]) == MEM
662                && symbolic_operand (XEXP (operands[0], 0), SImode))
663         operands[0] = gen_rtx_MEM (SImode,
664                                force_reg (SImode, XEXP (operands[0], 0)));
665     }
668 ;; General case of fullword move.  The register constraints
669 ;; force integer constants in range for a moveq to be reloaded
670 ;; if they are headed for memory.
671 (define_insn ""
672   ;; Notes: make sure no alternative allows g vs g.
673   ;; We don't allow f-regs since fixed point cannot go in them.
674   [(set (match_operand:SI 0 "nonimmediate_operand" "=g,d,a<")
675         (match_operand:SI 1 "general_src_operand" "daymSKT,n,i"))]
677   "!TARGET_COLDFIRE"
679   return output_move_simode (operands);
682 (define_insn "*movsi_cf"
683   [(set (match_operand:SI 0 "nonimmediate_operand" "=r<Q>,g,U")
684         (match_operand:SI 1 "general_operand" "g,r<Q>,U"))]
685   "TARGET_COLDFIRE && !TARGET_CFV4"
686   "* return output_move_simode (operands);")
688 (define_insn "*movsi_cfv4"
689   [(set (match_operand:SI 0 "nonimmediate_operand" "=r<Q>,g,U")
690         (match_operand:SI 1 "general_operand" "Rg,Rr<Q>,U"))]
691   "TARGET_CFV4"
692   "* return output_move_simode (operands);")
694 ;; Special case of fullword move, where we need to get a non-GOT PIC
695 ;; reference into an address register.
696 (define_insn ""
697   [(set (match_operand:SI 0 "nonimmediate_operand" "=a<")
698         (match_operand:SI 1 "pcrel_address" ""))]
699   "TARGET_PCREL"
701   if (push_operand (operands[0], SImode))
702     return "pea %a1";
703   return "lea %a1,%0";
706 (define_expand "movhi"
707   [(set (match_operand:HI 0 "nonimmediate_operand" "")
708         (match_operand:HI 1 "general_operand" ""))]
709   ""
710   "")
712 (define_insn ""
713   [(set (match_operand:HI 0 "nonimmediate_operand" "=g")
714         (match_operand:HI 1 "general_src_operand" "gS"))]
715   "!TARGET_COLDFIRE"
716   "* return output_move_himode (operands);")
718 (define_insn ""
719   [(set (match_operand:HI 0 "nonimmediate_operand" "=r<Q>,g,U")
720         (match_operand:HI 1 "general_operand" "g,r<Q>,U"))]
721   "TARGET_COLDFIRE"
722   "* return output_move_himode (operands);")
724 (define_expand "movstricthi"
725   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" ""))
726         (match_operand:HI 1 "general_src_operand" ""))]
727   ""
728   "")
730 (define_insn ""
731   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+dm"))
732         (match_operand:HI 1 "general_src_operand" "rmSn"))]
733   "!TARGET_COLDFIRE"
734   "* return output_move_stricthi (operands);")
736 (define_insn ""
737   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+d,m"))
738         (match_operand:HI 1 "general_src_operand" "rmn,r"))]
739   "TARGET_COLDFIRE"
740   "* return output_move_stricthi (operands);")
742 (define_expand "movqi"
743   [(set (match_operand:QI 0 "nonimmediate_operand" "")
744         (match_operand:QI 1 "general_src_operand" ""))]
745   ""
746   "")
748 (define_insn ""
749   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,*a,m")
750         (match_operand:QI 1 "general_src_operand" "dmSi*a,di*a,dmSi"))]
751   "!TARGET_COLDFIRE"
752   "* return output_move_qimode (operands);")
754 (define_insn ""
755   [(set (match_operand:QI 0 "nonimmediate_operand" "=d<Q>,dm,U,d*a")
756         (match_operand:QI 1 "general_src_operand" "dmi,d<Q>,U,di*a"))]
757   "TARGET_COLDFIRE"
758   "* return output_move_qimode (operands);")
760 (define_expand "movstrictqi"
761   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" ""))
762         (match_operand:QI 1 "general_src_operand" ""))]
763   ""
764   "")
766 (define_insn ""
767   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+dm"))
768         (match_operand:QI 1 "general_src_operand" "dmSn"))]
769   "!TARGET_COLDFIRE"
770   "* return output_move_strictqi (operands);")
772 (define_insn ""
773   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+d,m"))
774         (match_operand:QI 1 "general_src_operand" "dmn,d"))]
775   "TARGET_COLDFIRE"
776   "* return output_move_strictqi (operands);")
778 (define_expand "pushqi1"
779   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int -2)))
780    (set (mem:QI (plus:SI (reg:SI SP_REG) (const_int 1)))
781         (match_operand:QI 0 "general_operand" ""))]
782   "!TARGET_COLDFIRE"
783   "")
785 (define_expand "movsf"
786   [(set (match_operand:SF 0 "nonimmediate_operand" "")
787         (match_operand:SF 1 "general_operand" ""))]
788   ""
789   "")
791 (define_insn ""
792   [(set (match_operand:SF 0 "nonimmediate_operand" "=rmf")
793         (match_operand:SF 1 "general_operand" "rmfF"))]
794   "!TARGET_COLDFIRE"
796   if (FP_REG_P (operands[0]))
797     {
798       if (FP_REG_P (operands[1]))
799         return "f%$move%.x %1,%0";
800       else if (ADDRESS_REG_P (operands[1]))
801         return "move%.l %1,%-\;f%$move%.s %+,%0";
802       else if (GET_CODE (operands[1]) == CONST_DOUBLE)
803         return output_move_const_single (operands);
804       return "f%$move%.s %f1,%0";
805     }
806   if (FP_REG_P (operands[1]))
807     {
808       if (ADDRESS_REG_P (operands[0]))
809         return "fmove%.s %1,%-\;move%.l %+,%0";
810       return "fmove%.s %f1,%0";
811     }
812   if (operands[1] == CONST0_RTX (SFmode)
813       /* clr insns on 68000 read before writing.
814          This isn't so on the 68010, but we have no TARGET_68010.  */
815       && ((TARGET_68020 || TARGET_COLDFIRE)
816           || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
817     {
818       if (ADDRESS_REG_P (operands[0]))
819         {
820           /* On the '040, 'subl an,an' takes 2 clocks while lea takes only 1 */
821           if (!TARGET_68040 && !TARGET_68060)
822             return "sub%.l %0,%0";
823           else
824             return MOTOROLA ? "lea 0.w,%0" : "lea 0:w,%0";
825         }
826       /* moveq is faster on the 68000.  */
827       if (DATA_REG_P (operands[0]) && !(TARGET_68020 || TARGET_COLDFIRE))
828         {
829           return "moveq #0,%0";
830         }
831       return "clr%.l %0";
832     }
833   return "move%.l %1,%0";
836 (define_insn ""
837   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,g")
838         (match_operand:SF 1 "general_operand" "g,r"))]
839   "TARGET_COLDFIRE"
841   return "move%.l %1,%0";
844 (define_expand "movdf"
845   [(set (match_operand:DF 0 "nonimmediate_operand" "")
846         (match_operand:DF 1 "general_operand" ""))]
847   ""
848   "")
850 (define_insn ""
851   [(set (match_operand:DF 0 "nonimmediate_operand" "=rm,rf,rf,&rof<>")
852         (match_operand:DF 1 "general_operand" "*rf,m,0,*rofE<>"))]
853 ;  [(set (match_operand:DF 0 "nonimmediate_operand" "=rm,&rf,&rof<>")
854 ;       (match_operand:DF 1 "general_operand" "rf,m,rofF<>"))]
855   "!TARGET_COLDFIRE"
857   if (FP_REG_P (operands[0]))
858     {
859       if (FP_REG_P (operands[1]))
860         return "f%&move%.x %1,%0";
861       if (REG_P (operands[1]))
862         {
863           rtx xoperands[2];
864           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
865           output_asm_insn ("move%.l %1,%-", xoperands);
866           output_asm_insn ("move%.l %1,%-", operands);
867           return "f%&move%.d %+,%0";
868         }
869       if (GET_CODE (operands[1]) == CONST_DOUBLE)
870         return output_move_const_double (operands);
871       return "f%&move%.d %f1,%0";
872     }
873   else if (FP_REG_P (operands[1]))
874     {
875       if (REG_P (operands[0]))
876         {
877           output_asm_insn ("fmove%.d %f1,%-\;move%.l %+,%0", operands);
878           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
879           return "move%.l %+,%0";
880         }
881       else
882         return "fmove%.d %f1,%0";
883     }
884   return output_move_double (operands);
887 (define_insn ""
888   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,g")
889         (match_operand:DF 1 "general_operand" "g,r"))]
890   "TARGET_COLDFIRE"
892   return output_move_double (operands);
895 ;; ??? The XFmode patterns are schizophrenic about whether constants are
896 ;; allowed.  Most but not all have predicates and constraint that disallow
897 ;; constants.  Most but not all have output templates that handle constants.
898 ;; See also LEGITIMATE_CONSTANT_P.
900 (define_expand "movxf"
901   [(set (match_operand:XF 0 "nonimmediate_operand" "")
902         (match_operand:XF 1 "general_operand" ""))]
903   ""
905   /* We can't rewrite operands during reload.  */
906   if (! reload_in_progress)
907     {
908       if (CONSTANT_P (operands[1]))
909         {
910           operands[1] = force_const_mem (XFmode, operands[1]);
911           if (! memory_address_p (XFmode, XEXP (operands[1], 0)))
912             operands[1] = adjust_address (operands[1], XFmode, 0);
913         }
914       if (flag_pic && TARGET_PCREL)
915         {
916           /* Don't allow writes to memory except via a register; the
917              m68k doesn't consider PC-relative addresses to be writable.  */
918           if (GET_CODE (operands[0]) == MEM
919               && symbolic_operand (XEXP (operands[0], 0), SImode))
920             operands[0] = gen_rtx_MEM (XFmode,
921                                    force_reg (SImode, XEXP (operands[0], 0)));
922         }
923     }
926 (define_insn ""
927   [(set (match_operand:XF 0 "nonimmediate_operand" "=f,m,f,!r,!f,!r")
928         (match_operand:XF 1 "nonimmediate_operand" "m,f,f,f,r,!r"))]
929   "TARGET_68881"
931   if (FP_REG_P (operands[0]))
932     {
933       if (FP_REG_P (operands[1]))
934         return "fmove%.x %1,%0";
935       if (REG_P (operands[1]))
936         {
937           rtx xoperands[2];
938           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2);
939           output_asm_insn ("move%.l %1,%-", xoperands);
940           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
941           output_asm_insn ("move%.l %1,%-", xoperands);
942           output_asm_insn ("move%.l %1,%-", operands);
943           return "fmove%.x %+,%0";
944         }
945       if (GET_CODE (operands[1]) == CONST_DOUBLE)
946         return "fmove%.x %1,%0";
947       return "fmove%.x %f1,%0";
948     }
949   if (FP_REG_P (operands[1]))
950     {
951       if (REG_P (operands[0]))
952         {
953           output_asm_insn ("fmove%.x %f1,%-\;move%.l %+,%0", operands);
954           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
955           output_asm_insn ("move%.l %+,%0", operands);
956           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
957           return "move%.l %+,%0";
958         }
959       /* Must be memory destination.  */
960       return "fmove%.x %f1,%0";
961     }
962   return output_move_double (operands);
965 (define_insn ""
966   [(set (match_operand:XF 0 "nonimmediate_operand" "=rm,rf,&rof<>")
967         (match_operand:XF 1 "nonimmediate_operand" "rf,m,rof<>"))]
968   "! TARGET_68881 && ! TARGET_COLDFIRE"
970   if (FP_REG_P (operands[0]))
971     {
972       if (FP_REG_P (operands[1]))
973         return "fmove%.x %1,%0";
974       if (REG_P (operands[1]))
975         {
976           rtx xoperands[2];
977           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2);
978           output_asm_insn ("move%.l %1,%-", xoperands);
979           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
980           output_asm_insn ("move%.l %1,%-", xoperands);
981           output_asm_insn ("move%.l %1,%-", operands);
982           return "fmove%.x %+,%0";
983         }
984       if (GET_CODE (operands[1]) == CONST_DOUBLE)
985         return "fmove%.x %1,%0";
986       return "fmove%.x %f1,%0";
987     }
988   if (FP_REG_P (operands[1]))
989     {
990       if (REG_P (operands[0]))
991         {
992           output_asm_insn ("fmove%.x %f1,%-\;move%.l %+,%0", operands);
993           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
994           output_asm_insn ("move%.l %+,%0", operands);
995           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
996           return "move%.l %+,%0";
997         }
998       else
999         return "fmove%.x %f1,%0";
1000     }
1001   return output_move_double (operands);
1004 (define_insn ""
1005   [(set (match_operand:XF 0 "nonimmediate_operand" "=r,g")
1006         (match_operand:XF 1 "nonimmediate_operand" "g,r"))]
1007   "! TARGET_68881 && TARGET_COLDFIRE"
1008   "* return output_move_double (operands);")
1010 (define_expand "movdi"
1011   ;; Let's see if it really still needs to handle fp regs, and, if so, why.
1012   [(set (match_operand:DI 0 "nonimmediate_operand" "")
1013         (match_operand:DI 1 "general_operand" ""))]
1014   ""
1015   "")
1017 ;; movdi can apply to fp regs in some cases
1018 (define_insn ""
1019   ;; Let's see if it really still needs to handle fp regs, and, if so, why.
1020   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,r,&ro<>")
1021         (match_operand:DI 1 "general_operand" "rF,m,roi<>F"))]
1022 ;  [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,&r,&ro<>,!&rm,!&f")
1023 ;       (match_operand:DI 1 "general_operand" "r,m,roi<>,fF"))]
1024 ;  [(set (match_operand:DI 0 "nonimmediate_operand" "=rm,&rf,&ro<>,!&rm,!&f")
1025 ;       (match_operand:DI 1 "general_operand" "r,m,roi<>,fF,rfF"))]
1026   "!TARGET_COLDFIRE"
1028   if (FP_REG_P (operands[0]))
1029     {
1030       if (FP_REG_P (operands[1]))
1031         return "fmove%.x %1,%0";
1032       if (REG_P (operands[1]))
1033         {
1034           rtx xoperands[2];
1035           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
1036           output_asm_insn ("move%.l %1,%-", xoperands);
1037           output_asm_insn ("move%.l %1,%-", operands);
1038           return "fmove%.d %+,%0";
1039         }
1040       if (GET_CODE (operands[1]) == CONST_DOUBLE)
1041         return output_move_const_double (operands);
1042       return "fmove%.d %f1,%0";
1043     }
1044   else if (FP_REG_P (operands[1]))
1045     {
1046       if (REG_P (operands[0]))
1047         {
1048           output_asm_insn ("fmove%.d %f1,%-\;move%.l %+,%0", operands);
1049           operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1050           return "move%.l %+,%0";
1051         }
1052       else
1053         return "fmove%.d %f1,%0";
1054     }
1055   return output_move_double (operands);
1058 (define_insn ""
1059   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,g")
1060         (match_operand:DI 1 "general_operand" "g,r"))]
1061   "TARGET_COLDFIRE"
1062   "* return output_move_double (operands);")
1064 ;; Thus goes after the move instructions
1065 ;; because the move instructions are better (require no spilling)
1066 ;; when they can apply.  It goes before the add/sub insns
1067 ;; so we will prefer it to them.
1069 (define_insn "pushasi"
1070   [(set (match_operand:SI 0 "push_operand" "=m")
1071         (match_operand:SI 1 "address_operand" "p"))]
1072   ""
1073   "pea %a1")
1075 ;; truncation instructions
1076 (define_insn "truncsiqi2"
1077   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm,d")
1078         (truncate:QI
1079          (match_operand:SI 1 "general_src_operand" "doJS,i")))]
1080   ""
1082   if (GET_CODE (operands[0]) == REG)
1083     {
1084       /* Must clear condition codes, since the move.l bases them on
1085          the entire 32 bits, not just the desired 8 bits.  */
1086       CC_STATUS_INIT;
1087       return "move%.l %1,%0";
1088     }
1089   if (GET_CODE (operands[1]) == MEM)
1090     operands[1] = adjust_address (operands[1], QImode, 3);
1091   return "move%.b %1,%0";
1094 (define_insn "trunchiqi2"
1095   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm,d")
1096         (truncate:QI
1097          (match_operand:HI 1 "general_src_operand" "doJS,i")))]
1098   ""
1100   if (GET_CODE (operands[0]) == REG
1101       && (GET_CODE (operands[1]) == MEM
1102           || GET_CODE (operands[1]) == CONST_INT))
1103     {
1104       /* Must clear condition codes, since the move.w bases them on
1105          the entire 16 bits, not just the desired 8 bits.  */
1106       CC_STATUS_INIT;
1107       return "move%.w %1,%0";
1108     }
1109   if (GET_CODE (operands[0]) == REG)
1110     {
1111       /* Must clear condition codes, since the move.l bases them on
1112          the entire 32 bits, not just the desired 8 bits.  */
1113       CC_STATUS_INIT;
1114       return "move%.l %1,%0";
1115     }
1116   if (GET_CODE (operands[1]) == MEM)
1117     operands[1] = adjust_address (operands[1], QImode, 1);
1118   return "move%.b %1,%0";
1121 (define_insn "truncsihi2"
1122   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm,d")
1123         (truncate:HI
1124          (match_operand:SI 1 "general_src_operand" "roJS,i")))]
1125   ""
1127   if (GET_CODE (operands[0]) == REG)
1128     {
1129       /* Must clear condition codes, since the move.l bases them on
1130          the entire 32 bits, not just the desired 8 bits.  */
1131       CC_STATUS_INIT;
1132       return "move%.l %1,%0";
1133     }
1134   if (GET_CODE (operands[1]) == MEM)
1135     operands[1] = adjust_address (operands[1], QImode, 2);
1136   return "move%.w %1,%0";
1139 ;; zero extension instructions
1141 ;; two special patterns to match various post_inc/pre_dec patterns
1142 (define_insn_and_split "*zero_extend_inc"
1143   [(set (match_operand 0 "post_inc_operand" "")
1144         (zero_extend (match_operand 1 "register_operand" "")))]
1145   "GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT &&
1146    GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT &&
1147    GET_MODE_SIZE (GET_MODE (operands[0])) == GET_MODE_SIZE (GET_MODE (operands[1])) * 2"
1148   "#"
1149   ""
1150   [(set (match_dup 0)
1151         (const_int 0))
1152    (set (match_dup 0)
1153         (match_dup 1))]
1155   operands[0] = adjust_address (operands[0], GET_MODE (operands[1]), 0);
1158 (define_insn_and_split "*zero_extend_dec"
1159   [(set (match_operand 0 "pre_dec_operand" "")
1160         (zero_extend (match_operand 1 "register_operand" "")))]
1161   "(GET_MODE (operands[0]) != HImode || XEXP (XEXP (operands[0], 0), 0) != stack_pointer_rtx) &&
1162    GET_MODE_CLASS (GET_MODE (operands[0])) == MODE_INT &&
1163    GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT &&
1164    GET_MODE_SIZE (GET_MODE (operands[0])) == GET_MODE_SIZE (GET_MODE (operands[1])) * 2"
1165   "#"
1166   ""
1167   [(set (match_dup 0)
1168         (match_dup 1))
1169    (set (match_dup 0)
1170         (const_int 0))]
1172   operands[0] = adjust_address (operands[0], GET_MODE (operands[1]), 0);
1175 (define_insn_and_split "zero_extendqidi2"
1176   [(set (match_operand:DI 0 "register_operand" "")
1177         (zero_extend:DI (match_operand:QI 1 "nonimmediate_src_operand" "")))]
1178   ""
1179   "#"
1180   ""
1181   [(set (match_dup 2)
1182         (zero_extend:SI (match_dup 1)))
1183    (set (match_dup 3)
1184         (const_int 0))]
1186   operands[2] = gen_lowpart (SImode, operands[0]);
1187   operands[3] = gen_highpart (SImode, operands[0]);
1190 (define_insn_and_split "zero_extendhidi2"
1191   [(set (match_operand:DI 0 "register_operand" "")
1192         (zero_extend:DI (match_operand:HI 1 "nonimmediate_src_operand" "")))]
1193   ""
1194   "#"
1195   ""
1196   [(set (match_dup 2)
1197         (zero_extend:SI (match_dup 1)))
1198    (set (match_dup 3)
1199         (const_int 0))]
1201   operands[2] = gen_lowpart (SImode, operands[0]);
1202   operands[3] = gen_highpart (SImode, operands[0]);
1205 (define_expand "zero_extendsidi2"
1206   [(set (match_operand:DI 0 "nonimmediate_operand" "")
1207         (zero_extend:DI (match_operand:SI 1 "nonimmediate_src_operand" "")))]
1208   ""
1209   "")
1211 (define_insn_and_split "*zero_extendsidi2"
1212   [(set (match_operand:DI 0 "nonimmediate_operand" "")
1213         (zero_extend:DI (match_operand:SI 1 "nonimmediate_src_operand" "")))]
1214   "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM"
1215   "#"
1216   ""
1217   [(set (match_dup 2)
1218         (match_dup 1))
1219    (set (match_dup 3)
1220         (const_int 0))]
1222   operands[2] = gen_lowpart (SImode, operands[0]);
1223   operands[3] = gen_highpart (SImode, operands[0]);
1226 (define_insn "*zero_extendhisi2_cf"
1227   [(set (match_operand:SI 0 "register_operand" "=d")
1228         (zero_extend:SI (match_operand:HI 1 "nonimmediate_src_operand" "rmS")))]
1229   "TARGET_CFV4"
1230   "mvz%.w %1,%0")
1232 (define_insn "zero_extendhisi2"
1233   [(set (match_operand:SI 0 "register_operand" "=d")
1234         (zero_extend:SI (match_operand:HI 1 "nonimmediate_src_operand" "rmS")))]
1235   ""
1236   "#")
1238 (define_expand "zero_extendqihi2"
1239   [(set (match_operand:HI 0 "register_operand" "")
1240         (zero_extend:HI (match_operand:QI 1 "nonimmediate_src_operand" "")))]
1241   "!TARGET_COLDFIRE"
1242   "")
1244 (define_insn "*zero_extendqihi2"
1245   [(set (match_operand:HI 0 "register_operand" "=d")
1246         (zero_extend:HI (match_operand:QI 1 "nonimmediate_src_operand" "dmS")))]
1247   "!TARGET_COLDFIRE"
1248   "#")
1250 (define_insn "*zero_extendqisi2_cfv4"
1251   [(set (match_operand:SI 0 "register_operand" "=d")
1252         (zero_extend:SI (match_operand:QI 1 "nonimmediate_src_operand" "dmS")))]
1253   "TARGET_CFV4"
1254   "mvz%.b %1,%0")
1256 (define_insn "zero_extendqisi2"
1257   [(set (match_operand:SI 0 "register_operand" "=d")
1258         (zero_extend:SI (match_operand:QI 1 "nonimmediate_src_operand" "dmS")))]
1259   ""
1260   "#")
1262 ;; these two pattern split everything else which isn't matched by
1263 ;; something else above
1264 (define_split
1265   [(set (match_operand 0 "register_operand" "")
1266         (zero_extend (match_operand 1 "nonimmediate_src_operand" "")))]
1267   "!TARGET_CFV4 && reload_completed && reg_mentioned_p (operands[0], operands[1])"
1268   [(set (strict_low_part (match_dup 2))
1269         (match_dup 1))
1270    (set (match_dup 0)
1271         (match_op_dup 4 [(match_dup 0) (match_dup 3)]))]
1273   operands[2] = gen_lowpart (GET_MODE (operands[1]), operands[0]);
1274   operands[3] = GEN_INT (GET_MODE_MASK (GET_MODE (operands[1])));
1275   operands[4] = gen_rtx_AND (GET_MODE (operands[0]), operands[0], operands[3]);
1278 (define_split
1279   [(set (match_operand 0 "register_operand" "")
1280         (zero_extend (match_operand 1 "nonimmediate_src_operand" "")))]
1281   "!TARGET_CFV4 && reload_completed"
1282   [(set (match_dup 0)
1283         (const_int 0))
1284    (set (strict_low_part (match_dup 2))
1285         (match_dup 1))]
1287   operands[2] = gen_lowpart (GET_MODE (operands[1]), operands[0]);
1290 ;; sign extension instructions
1292 (define_insn "extendqidi2"
1293   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
1294         (sign_extend:DI (match_operand:QI 1 "general_src_operand" "rmS")))]
1295   ""
1297   CC_STATUS_INIT;
1298   operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1299   if (TARGET_CFV4)
1300     return "mvs%.b %1,%2\;smi %0\;extb%.l %0";
1301   if (TARGET_68020 || TARGET_COLDFIRE)
1302     return "move%.b %1,%2\;extb%.l %2\;smi %0\;extb%.l %0";
1303   else
1304     return "move%.b %1,%2\;ext%.w %0\;ext%.l %2\;move%.l %2,%0\;smi %0";
1307 (define_insn "extendhidi2"
1308   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
1309         (sign_extend:DI
1310          (match_operand:HI 1 "general_src_operand" "rmS")))]
1311   ""
1313   CC_STATUS_INIT;
1314   operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1315   if (TARGET_CFV4)
1316     return "mvs%.w %1,%2\;smi %0\;extb%.l %0";
1317   if (TARGET_68020 || TARGET_COLDFIRE)
1318     return "move%.w %1,%2\;ext%.l %2\;smi %0\;extb%.l %0";
1319   else
1320     return "move%.w %1,%2\;ext%.l %2\;smi %0\;ext%.w %0\;ext%.l %0";
1323 (define_insn "extendsidi2"
1324   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
1325         (sign_extend:DI
1326          (match_operand:SI 1 "general_operand" "rm")))]
1327   ""
1329   CC_STATUS_INIT;
1330   operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1331   if (TARGET_68020 || TARGET_COLDFIRE)
1332     return "move%.l %1,%2\;smi %0\;extb%.l %0";
1333   else
1334     return "move%.l %1,%2\;smi %0\;ext%.w %0\;ext%.l %0";
1337 ;; Special case when one can avoid register clobbering, copy and test
1338 ;; Maybe there is a way to make that the general case, by forcing the
1339 ;; result of the SI tree to be in the lower register of the DI target
1341 (define_insn "extendplussidi"
1342   [(set (match_operand:DI 0 "register_operand" "=d")
1343     (sign_extend:DI (plus:SI (match_operand:SI 1 "general_operand" "%rmn")
1344             (match_operand:SI 2 "general_operand" "rmn"))))]
1345   ""
1347   CC_STATUS_INIT;
1348   operands[3] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1349   if (GET_CODE (operands[1]) == CONST_INT
1350   && (unsigned) INTVAL (operands[1]) > 8)
1351     {
1352       rtx tmp = operands[1];
1354       operands[1] = operands[2];
1355       operands[2] = tmp;
1356     }
1357   if (GET_CODE (operands[1]) == REG
1358       && REGNO (operands[1]) == REGNO (operands[3]))
1359     output_asm_insn ("add%.l %2,%3", operands);
1360   else
1361     output_asm_insn ("move%.l %2,%3\;add%.l %1,%3", operands);
1362   if (TARGET_68020 || TARGET_COLDFIRE)
1363     return "smi %0\;extb%.l %0";
1364   else
1365     return "smi %0\;ext%.w %0\;ext%.l %0";
1368 (define_expand "extendhisi2"
1369   [(set (match_operand:SI 0 "nonimmediate_operand" "")
1370         (sign_extend:SI
1371          (match_operand:HI 1 "nonimmediate_src_operand" "")))]
1372   ""
1373   "")
1375 (define_insn "*cfv4_extendhisi2"
1376   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
1377         (sign_extend:SI
1378          (match_operand:HI 1 "nonimmediate_src_operand" "rmS")))]
1379   "TARGET_CFV4"
1380   "mvs%.w %1,%0")
1382 (define_insn "*68k_extendhisi2"
1383   [(set (match_operand:SI 0 "nonimmediate_operand" "=*d,a")
1384         (sign_extend:SI
1385          (match_operand:HI 1 "nonimmediate_src_operand" "0,rmS")))]
1386   "!TARGET_CFV4"
1388   if (ADDRESS_REG_P (operands[0]))
1389     return "move%.w %1,%0";
1390   return "ext%.l %0";
1393 (define_insn "extendqihi2"
1394   [(set (match_operand:HI 0 "nonimmediate_operand" "=d")
1395         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0")))]
1396   ""
1397   "ext%.w %0")
1399 (define_expand "extendqisi2"
1400   [(set (match_operand:SI 0 "nonimmediate_operand" "")
1401         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))]
1402   "TARGET_68020 || TARGET_COLDFIRE"
1403   "")
1405 (define_insn "*cfv4_extendqisi2"
1406   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
1407         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "rms")))]
1408   "TARGET_CFV4"
1409   "mvs%.b %1,%0")
1411 (define_insn "*68k_extendqisi2"
1412   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
1413         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "0")))]
1414   "TARGET_68020 || (TARGET_COLDFIRE && !TARGET_CFV4)"
1415   "extb%.l %0")
1417 ;; Conversions between float and double.
1419 (define_expand "extendsfdf2"
1420   [(set (match_operand:DF 0 "nonimmediate_operand" "")
1421         (float_extend:DF
1422          (match_operand:SF 1 "general_operand" "")))]
1423   "TARGET_68881"
1424   "")
1426 (define_insn ""
1427   [(set (match_operand:DF 0 "nonimmediate_operand" "=*fdm,f")
1428         (float_extend:DF
1429           (match_operand:SF 1 "general_operand" "f,dmF")))]
1430   "TARGET_68881"
1432   if (FP_REG_P (operands[0]) && FP_REG_P (operands[1]))
1433     {
1434       if (REGNO (operands[0]) == REGNO (operands[1]))
1435         {
1436           /* Extending float to double in an fp-reg is a no-op.
1437              NOTICE_UPDATE_CC has already assumed that the
1438              cc will be set.  So cancel what it did.  */
1439           cc_status = cc_prev_status;
1440           return "";
1441         }
1442       return "f%&move%.x %1,%0";
1443     }
1444   if (FP_REG_P (operands[0]))
1445     return "f%&move%.s %f1,%0";
1446   if (DATA_REG_P (operands[0]) && FP_REG_P (operands[1]))
1447     {
1448       output_asm_insn ("fmove%.d %f1,%-\;move%.l %+,%0", operands);
1449       operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1450       return "move%.l %+,%0";
1451     }
1452   return "fmove%.d %f1,%0";
1455 ;; This cannot output into an f-reg because there is no way to be
1456 ;; sure of truncating in that case.
1457 (define_expand "truncdfsf2"
1458   [(set (match_operand:SF 0 "nonimmediate_operand" "")
1459         (float_truncate:SF
1460           (match_operand:DF 1 "general_operand" "")))]
1461   "TARGET_68881"
1462   "")
1464 ;; On the '040 we can truncate in a register accurately and easily.
1465 (define_insn ""
1466   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
1467         (float_truncate:SF
1468           (match_operand:DF 1 "general_operand" "fmG")))]
1469   "TARGET_68881 && TARGET_68040_ONLY"
1471   if (FP_REG_P (operands[1]))
1472     return "f%$move%.x %1,%0";
1473   return "f%$move%.d %f1,%0";
1476 (define_insn ""
1477   [(set (match_operand:SF 0 "nonimmediate_operand" "=dm")
1478         (float_truncate:SF
1479           (match_operand:DF 1 "general_operand" "f")))]
1480   "TARGET_68881"
1481   "fmove%.s %f1,%0")
1483 ;; Conversion between fixed point and floating point.
1484 ;; Note that among the fix-to-float insns
1485 ;; the ones that start with SImode come first.
1486 ;; That is so that an operand that is a CONST_INT
1487 ;; (and therefore lacks a specific machine mode).
1488 ;; will be recognized as SImode (which is always valid)
1489 ;; rather than as QImode or HImode.
1491 (define_expand "floatsisf2"
1492   [(set (match_operand:SF 0 "nonimmediate_operand" "")
1493         (float:SF (match_operand:SI 1 "general_operand" "")))]
1494   "TARGET_68881"
1495   "")
1497 (define_insn ""
1498   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
1499         (float:SF (match_operand:SI 1 "general_operand" "dmi")))]
1500   "TARGET_68881"
1501   "f%$move%.l %1,%0")
1503 (define_expand "floatsidf2"
1504   [(set (match_operand:DF 0 "nonimmediate_operand" "")
1505         (float:DF (match_operand:SI 1 "general_operand" "")))]
1506   "TARGET_68881"
1507   "")
1509 (define_insn ""
1510   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
1511         (float:DF (match_operand:SI 1 "general_operand" "dmi")))]
1512   "TARGET_68881"
1513   "f%&move%.l %1,%0")
1515 (define_insn "floathisf2"
1516   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
1517         (float:SF (match_operand:HI 1 "general_operand" "dmn")))]
1518   "TARGET_68881"
1519   "f%$move%.w %1,%0")
1521 (define_insn "floathidf2"
1522   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
1523         (float:DF (match_operand:HI 1 "general_operand" "dmn")))]
1524   "TARGET_68881"
1525   "fmove%.w %1,%0")
1527 (define_insn "floatqisf2"
1528   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
1529         (float:SF (match_operand:QI 1 "general_operand" "dmn")))]
1530   "TARGET_68881"
1531   "fmove%.b %1,%0")
1533 (define_insn "floatqidf2"
1534   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
1535         (float:DF (match_operand:QI 1 "general_operand" "dmn")))]
1536   "TARGET_68881"
1537   "f%&move%.b %1,%0")
1539 ;; New routines to convert floating-point values to integers
1540 ;; to be used on the '040.  These should be faster than trapping
1541 ;; into the kernel to emulate fintrz.  They should also be faster
1542 ;; than calling the subroutines fixsfsi or fixdfsi.
1544 (define_insn "fix_truncdfsi2"
1545   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
1546         (fix:SI (fix:DF (match_operand:DF 1 "register_operand" "f"))))
1547    (clobber (match_scratch:SI 2 "=d"))
1548    (clobber (match_scratch:SI 3 "=d"))]
1549   "TARGET_68881 && TARGET_68040"
1551   CC_STATUS_INIT;
1552   return "fmovem%.l %!,%2\;moveq #16,%3\;or%.l %2,%3\;and%.w #-33,%3\;fmovem%.l %3,%!\;fmove%.l %1,%0\;fmovem%.l %2,%!";
1555 (define_insn "fix_truncdfhi2"
1556   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm")
1557         (fix:HI (fix:DF (match_operand:DF 1 "register_operand" "f"))))
1558    (clobber (match_scratch:SI 2 "=d"))
1559    (clobber (match_scratch:SI 3 "=d"))]
1560   "TARGET_68881 && TARGET_68040"
1562   CC_STATUS_INIT;
1563   return "fmovem%.l %!,%2\;moveq #16,%3\;or%.l %2,%3\;and%.w #-33,%3\;fmovem%.l %3,%!\;fmove%.w %1,%0\;fmovem%.l %2,%!";
1566 (define_insn "fix_truncdfqi2"
1567   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
1568         (fix:QI (fix:DF (match_operand:DF 1 "register_operand" "f"))))
1569    (clobber (match_scratch:SI 2 "=d"))
1570    (clobber (match_scratch:SI 3 "=d"))]
1571   "TARGET_68881 && TARGET_68040"
1573   CC_STATUS_INIT;
1574   return "fmovem%.l %!,%2\;moveq #16,%3\;or%.l %2,%3\;and%.w #-33,%3\;fmovem%.l %3,%!\;fmove%.b %1,%0\;fmovem%.l %2,%!";
1577 ;; Convert a float to a float whose value is an integer.
1578 ;; This is the first stage of converting it to an integer type.
1580 (define_insn "ftruncdf2"
1581   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
1582         (fix:DF (match_operand:DF 1 "general_operand" "fFm")))]
1583   "TARGET_68881 && !TARGET_68040"
1585   if (FP_REG_P (operands[1]))
1586     return "fintrz%.x %f1,%0";
1587   return "fintrz%.d %f1,%0";
1590 (define_insn "ftruncsf2"
1591   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
1592         (fix:SF (match_operand:SF 1 "general_operand" "dfFm")))]
1593   "TARGET_68881 && !TARGET_68040"
1595   if (FP_REG_P (operands[1]))
1596     return "fintrz%.x %f1,%0";
1597   return "fintrz%.s %f1,%0";
1600 ;; Convert a float whose value is an integer
1601 ;; to an actual integer.  Second stage of converting float to integer type.
1602 (define_insn "fixsfqi2"
1603   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
1604         (fix:QI (match_operand:SF 1 "general_operand" "f")))]
1605   "TARGET_68881"
1606   "fmove%.b %1,%0")
1608 (define_insn "fixsfhi2"
1609   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm")
1610         (fix:HI (match_operand:SF 1 "general_operand" "f")))]
1611   "TARGET_68881"
1612   "fmove%.w %1,%0")
1614 (define_insn "fixsfsi2"
1615   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
1616         (fix:SI (match_operand:SF 1 "general_operand" "f")))]
1617   "TARGET_68881"
1618   "fmove%.l %1,%0")
1620 (define_insn "fixdfqi2"
1621   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
1622         (fix:QI (match_operand:DF 1 "general_operand" "f")))]
1623   "TARGET_68881"
1624   "fmove%.b %1,%0")
1626 (define_insn "fixdfhi2"
1627   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm")
1628         (fix:HI (match_operand:DF 1 "general_operand" "f")))]
1629   "TARGET_68881"
1630   "fmove%.w %1,%0")
1632 (define_insn "fixdfsi2"
1633   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
1634         (fix:SI (match_operand:DF 1 "general_operand" "f")))]
1635   "TARGET_68881"
1636   "fmove%.l %1,%0")
1638 ;; add instructions
1640 (define_insn "adddi_lshrdi_63"
1641   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
1642     (plus:DI (lshiftrt:DI (match_operand:DI 1 "general_operand" "rm")
1643             (const_int 63))
1644         (match_dup 1)))
1645    (clobber (match_scratch:SI 2 "=d"))]
1646   ""
1648   operands[3] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1649   if (REG_P (operands[1]) && REGNO (operands[1]) == REGNO (operands[0]))
1650     return
1651     "move%.l %1,%2\;add%.l %2,%2\;subx%.l %2,%2\;sub%.l %2,%3\;subx%.l %2,%0";
1652   if (GET_CODE (operands[1]) == REG)
1653     operands[4] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
1654   else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC
1655         || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
1656     operands[4] = operands[1];
1657   else
1658     operands[4] = adjust_address (operands[1], SImode, 4);
1659   if (GET_CODE (operands[1]) == MEM
1660    && GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
1661     output_asm_insn ("move%.l %4,%3", operands);
1662   output_asm_insn ("move%.l %1,%0\;smi %2", operands);
1663   if (TARGET_68020 || TARGET_COLDFIRE)
1664     output_asm_insn ("extb%.l %2", operands);
1665   else
1666     output_asm_insn ("ext%.w %2\;ext%.l %2", operands);
1667   if (GET_CODE (operands[1]) != MEM
1668    || GET_CODE (XEXP (operands[1], 0)) != PRE_DEC)
1669     output_asm_insn ("move%.l %4,%3", operands);
1670   return "sub%.l %2,%3\;subx%.l %2,%0";
1673 (define_insn "adddi_sexthishl32"
1674   [(set (match_operand:DI 0 "nonimmediate_operand" "=o,a,*d,*d")
1675     (plus:DI (ashift:DI (sign_extend:DI
1676           (match_operand:HI 1 "general_operand" "rm,rm,rm,rm"))
1677             (const_int 32))
1678         (match_operand:DI 2 "general_operand" "0,0,0,0")))
1679    (clobber (match_scratch:SI 3 "=&d,X,a,?d"))]
1680   "!TARGET_COLDFIRE"
1682   CC_STATUS_INIT;
1683   if (ADDRESS_REG_P (operands[0]))
1684     return "add%.w %1,%0";
1685   else if (ADDRESS_REG_P (operands[3]))
1686     return "move%.w %1,%3\;add%.l %3,%0";
1687   else
1688     return "move%.w %1,%3\;ext%.l %3\;add%.l %3,%0";
1691 (define_insn "adddi_dilshr32"
1692   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,o")
1693 ;;    (plus:DI (match_operand:DI 2 "general_operand" "%0")
1694 ;;      (lshiftrt:DI (match_operand:DI 1 "general_operand" "ro")
1695 ;;            (const_int 32))))]
1696     (plus:DI (lshiftrt:DI (match_operand:DI 1 "general_operand" "ro,d")
1697             (const_int 32))
1698         (match_operand:DI 2 "general_operand" "0,0")))]
1699   ""
1701   CC_STATUS_INIT;
1702   if (GET_CODE (operands[0]) == REG)
1703     operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
1704   else
1705     operands[2] = adjust_address (operands[0], SImode, 4);
1706   return "add%.l %1,%2\;negx%.l %0\;neg%.l %0";
1709 (define_insn "adddi_dishl32"
1710   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,o")
1711 ;;    (plus:DI (match_operand:DI 2 "general_operand" "%0")
1712 ;;      (ashift:DI (match_operand:DI 1 "general_operand" "ro")
1713 ;;            (const_int 32))))]
1714     (plus:DI (ashift:DI (match_operand:DI 1 "general_operand" "ro,d")
1715             (const_int 32))
1716         (match_operand:DI 2 "general_operand" "0,0")))]
1717   ""
1719   CC_STATUS_INIT;
1720   if (GET_CODE (operands[1]) == REG)
1721     operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
1722   else
1723     operands[1] = adjust_address (operands[1], SImode, 4);
1724   return "add%.l %1,%0";
1727 (define_insn "adddi3"
1728   [(set (match_operand:DI 0 "nonimmediate_operand" "=<,o<>,d,d,d")
1729         (plus:DI (match_operand:DI 1 "general_operand" "%0,0,0,0,0")
1730                  (match_operand:DI 2 "general_operand" "<,d,no>,d,a")))
1731    (clobber (match_scratch:SI 3 "=X,&d,&d,X,&d"))]
1732   ""
1734   if (DATA_REG_P (operands[0]))
1735     {
1736       if (DATA_REG_P (operands[2]))
1737         return "add%.l %R2,%R0\;addx%.l %2,%0";
1738       else if (GET_CODE (operands[2]) == MEM
1739           && GET_CODE (XEXP (operands[2], 0)) == POST_INC)
1740         return "move%.l %2,%3\;add%.l %2,%R0\;addx%.l %3,%0";
1741       else
1742         {
1743           rtx high, low;
1744           rtx xoperands[2];
1746           if (GET_CODE (operands[2]) == REG)
1747             {
1748               low = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
1749               high = operands[2];
1750             }
1751           else if (CONSTANT_P (operands[2]))
1752             split_double (operands[2], &high, &low);
1753           else
1754             {
1755               low = adjust_address (operands[2], SImode, 4);
1756               high = operands[2];
1757             }
1759           operands[1] = low, operands[2] = high;
1760           xoperands[0] = operands[3];
1761           if (GET_CODE (operands[1]) == CONST_INT
1762               && INTVAL (operands[1]) >= -8 && INTVAL (operands[1]) < 0)
1763             xoperands[1] = GEN_INT (-INTVAL (operands[2]) - 1);
1764           else
1765             xoperands[1] = operands[2];
1767           output_asm_insn (output_move_simode (xoperands), xoperands);
1768           if (GET_CODE (operands[1]) == CONST_INT)
1769             {
1770               if (INTVAL (operands[1]) > 0 && INTVAL (operands[1]) <= 8)
1771                 return "addq%.l %1,%R0\;addx%.l %3,%0";
1772               else if (INTVAL (operands[1]) >= -8 && INTVAL (operands[1]) < 0)
1773                 {
1774                   operands[1] = GEN_INT (-INTVAL (operands[1]));
1775                   return "subq%.l %1,%R0\;subx%.l %3,%0";
1776                 }
1777             }
1778           return "add%.l %1,%R0\;addx%.l %3,%0";
1779         }
1780     }
1781   else
1782     {
1783       gcc_assert (GET_CODE (operands[0]) == MEM);
1784       if (GET_CODE (operands[2]) == MEM
1785           && GET_CODE (XEXP (operands[2], 0)) == PRE_DEC)
1786         return "add%.l %2,%0\;addx%.l %2,%0";
1787       CC_STATUS_INIT;
1788       if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
1789         {
1790           operands[1] = gen_rtx_MEM (SImode,
1791                                      plus_constant (XEXP(operands[0], 0), -8));
1792           return "move%.l %0,%3\;add%.l %R2,%0\;addx%.l %2,%3\;move%.l %3,%1";
1793         }
1794       else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
1795         {
1796           operands[1] = XEXP(operands[0], 0);
1797           return "add%.l %R2,%0\;move%.l %0,%3\;addx%.l %2,%3\;move%.l %3,%1";
1798         }
1799       else
1800         {
1801           operands[1] = adjust_address (operands[0], SImode, 4);
1802           return "add%.l %R2,%1\;move%.l %0,%3\;addx%.l %2,%3\;move%.l %3,%0";
1803         }
1804     }
1807 (define_insn "addsi_lshrsi_31"
1808   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
1809     (plus:SI (lshiftrt:SI (match_operand:SI 1 "general_operand" "rm")
1810             (const_int 31))
1811         (match_dup 1)))]
1812   ""
1814   operands[2] = operands[0];
1815   operands[3] = gen_label_rtx();
1816   if (GET_CODE (operands[0]) == MEM)
1817     {
1818       if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
1819         operands[0] = gen_rtx_MEM (SImode, XEXP (XEXP (operands[0], 0), 0));
1820       else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
1821         operands[2] = gen_rtx_MEM (SImode, XEXP (XEXP (operands[0], 0), 0));
1822     }
1823   output_asm_insn ("move%.l %1,%0", operands);
1824   output_asm_insn (MOTOROLA ? "jbpl %l3" : "jpl %l3", operands);
1825   output_asm_insn ("addq%.l #1,%2", operands);
1826   (*targetm.asm_out.internal_label) (asm_out_file, "L",
1827                                 CODE_LABEL_NUMBER (operands[3]));
1828   return "";
1831 (define_expand "addsi3"
1832   [(set (match_operand:SI 0 "nonimmediate_operand" "")
1833         (plus:SI (match_operand:SI 1 "general_operand" "")
1834                  (match_operand:SI 2 "general_src_operand" "")))]
1835   ""
1836   "")
1838 ;; Note that the middle two alternatives are near-duplicates
1839 ;; in order to handle insns generated by reload.
1840 ;; This is needed since they are not themselves reloaded,
1841 ;; so commutativity won't apply to them.
1842 (define_insn "*addsi3_internal"
1843   [(set (match_operand:SI 0 "nonimmediate_operand" "=m,?a,?a,d,a")
1844         (plus:SI (match_operand:SI 1 "general_operand" "%0,a,rJK,0,0")
1845                  (match_operand:SI 2 "general_src_operand" "dIKLT,rJK,a,mSrIKLT,mSrIKLs")))]
1848   "! TARGET_COLDFIRE"
1849   "* return output_addsi3 (operands);")
1851 (define_insn "*addsi3_5200"
1852   [(set (match_operand:SI 0 "nonimmediate_operand" "=m,?a,?a,r")
1853         (plus:SI (match_operand:SI 1 "general_operand" "%0,a,rJK,0")
1854                  (match_operand:SI 2 "general_src_operand" "d,rJK,a,mrIKLs")))]
1855   "TARGET_COLDFIRE"
1856   "* return output_addsi3 (operands);")
1858 (define_insn ""
1859   [(set (match_operand:SI 0 "nonimmediate_operand" "=a")
1860         (plus:SI (match_operand:SI 1 "general_operand" "0")
1861                  (sign_extend:SI
1862                   (match_operand:HI 2 "nonimmediate_src_operand" "rmS"))))]
1863   "!TARGET_COLDFIRE"
1864   "add%.w %2,%0")
1866 (define_insn "addhi3"
1867   [(set (match_operand:HI 0 "nonimmediate_operand" "=m,r")
1868         (plus:HI (match_operand:HI 1 "general_operand" "%0,0")
1869                  (match_operand:HI 2 "general_src_operand" "dn,rmSn")))]
1870   "!TARGET_COLDFIRE"
1872   if (GET_CODE (operands[2]) == CONST_INT)
1873     {
1874       /* If the constant would be a negative number when interpreted as
1875          HImode, make it negative.  This is usually, but not always, done
1876          elsewhere in the compiler.  First check for constants out of range,
1877          which could confuse us.  */
1879       if (INTVAL (operands[2]) >= 32768)
1880         operands[2] = GEN_INT (INTVAL (operands[2]) - 65536);
1882       if (INTVAL (operands[2]) > 0
1883           && INTVAL (operands[2]) <= 8)
1884         return "addq%.w %2,%0";
1885       if (INTVAL (operands[2]) < 0
1886           && INTVAL (operands[2]) >= -8)
1887         {
1888           operands[2] = GEN_INT (- INTVAL (operands[2]));
1889           return "subq%.w %2,%0";
1890         }
1891       /* On the CPU32 it is faster to use two addqw instructions to
1892          add a small integer (8 < N <= 16) to a register.  
1893          Likewise for subqw.  */
1894       if (TARGET_CPU32 && REG_P (operands[0]))
1895         {
1896           if (INTVAL (operands[2]) > 8
1897               && INTVAL (operands[2]) <= 16)
1898             {
1899               operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
1900               return "addq%.w #8,%0\;addq%.w %2,%0";
1901             }
1902           if (INTVAL (operands[2]) < -8
1903               && INTVAL (operands[2]) >= -16)
1904             {
1905               operands[2] = GEN_INT (- INTVAL (operands[2]) - 8);
1906               return "subq%.w #8,%0\;subq%.w %2,%0";
1907             }
1908         }
1909       if (ADDRESS_REG_P (operands[0]) && !TARGET_68040)
1910         return MOTOROLA ? "lea (%c2,%0),%0" : "lea %0@(%c2),%0";
1911     }
1912   return "add%.w %2,%0";
1915 ;; These insns must use MATCH_DUP instead of the more expected
1916 ;; use of a matching constraint because the "output" here is also
1917 ;; an input, so you can't use the matching constraint.  That also means
1918 ;; that you can't use the "%", so you need patterns with the matched
1919 ;; operand in both positions.
1921 (define_insn ""
1922   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+m,d"))
1923         (plus:HI (match_dup 0)
1924                  (match_operand:HI 1 "general_src_operand" "dn,rmSn")))]
1925   "!TARGET_COLDFIRE"
1927   if (GET_CODE (operands[1]) == CONST_INT)
1928     {
1929       /* If the constant would be a negative number when interpreted as
1930          HImode, make it negative.  This is usually, but not always, done
1931          elsewhere in the compiler.  First check for constants out of range,
1932          which could confuse us.  */
1934       if (INTVAL (operands[1]) >= 32768)
1935         operands[1] = GEN_INT (INTVAL (operands[1]) - 65536);
1937       if (INTVAL (operands[1]) > 0
1938           && INTVAL (operands[1]) <= 8)
1939         return "addq%.w %1,%0";
1940       if (INTVAL (operands[1]) < 0
1941           && INTVAL (operands[1]) >= -8)
1942         {
1943           operands[1] = GEN_INT (- INTVAL (operands[1]));
1944           return "subq%.w %1,%0";
1945         }
1946       /* On the CPU32 it is faster to use two addqw instructions to
1947          add a small integer (8 < N <= 16) to a register. 
1948          Likewise for subqw.  */
1949       if (TARGET_CPU32 && REG_P (operands[0]))
1950         {
1951           if (INTVAL (operands[1]) > 8
1952               && INTVAL (operands[1]) <= 16)
1953             {
1954               operands[1] = GEN_INT (INTVAL (operands[1]) - 8);
1955               return "addq%.w #8,%0\;addq%.w %1,%0";
1956             }
1957           if (INTVAL (operands[1]) < -8
1958               && INTVAL (operands[1]) >= -16)
1959             {
1960               operands[1] = GEN_INT (- INTVAL (operands[1]) - 8);
1961               return "subq%.w #8,%0\;subq%.w %1,%0";
1962             }
1963         }
1964       if (ADDRESS_REG_P (operands[0]) && !TARGET_68040)
1965         return MOTOROLA ? "lea (%c1,%0),%0" : "lea %0@(%c1),%0";
1966     }
1967   return "add%.w %1,%0";
1970 (define_insn ""
1971   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+m,d"))
1972         (plus:HI (match_operand:HI 1 "general_src_operand" "dn,rmSn")
1973                  (match_dup 0)))]
1974   "!TARGET_COLDFIRE"
1976   if (GET_CODE (operands[1]) == CONST_INT)
1977     {
1978       /* If the constant would be a negative number when interpreted as
1979          HImode, make it negative.  This is usually, but not always, done
1980          elsewhere in the compiler.  First check for constants out of range,
1981          which could confuse us.  */
1983       if (INTVAL (operands[1]) >= 32768)
1984         operands[1] = GEN_INT (INTVAL (operands[1]) - 65536);
1986       if (INTVAL (operands[1]) > 0
1987           && INTVAL (operands[1]) <= 8)
1988         return "addq%.w %1,%0";
1989       if (INTVAL (operands[1]) < 0
1990           && INTVAL (operands[1]) >= -8)
1991         {
1992           operands[1] = GEN_INT (- INTVAL (operands[1]));
1993           return "subq%.w %1,%0";
1994         }
1995       /* On the CPU32 it is faster to use two addqw instructions to
1996          add a small integer (8 < N <= 16) to a register.
1997          Likewise for subqw.  */
1998       if (TARGET_CPU32 && REG_P (operands[0])) 
1999         {
2000           if (INTVAL (operands[1]) > 8
2001               && INTVAL (operands[1]) <= 16)
2002             {
2003               operands[1] = GEN_INT (INTVAL (operands[1]) - 8);
2004               return "addq%.w #8,%0\;addq%.w %1,%0";
2005             }
2006           if (INTVAL (operands[1]) < -8
2007               && INTVAL (operands[1]) >= -16)
2008             {
2009               operands[1] = GEN_INT (- INTVAL (operands[1]) - 8);
2010               return "subq%.w #8,%0\;subq%.w %1,%0";
2011             }
2012         }
2013       if (ADDRESS_REG_P (operands[0]) && !TARGET_68040)
2014         return MOTOROLA ? "lea (%c1,%0),%0" : "lea %0@(%c1),%0";
2015     }
2016   return "add%.w %1,%0";
2019 (define_insn "addqi3"
2020   [(set (match_operand:QI 0 "nonimmediate_operand" "=m,d")
2021         (plus:QI (match_operand:QI 1 "general_operand" "%0,0")
2022                  (match_operand:QI 2 "general_src_operand" "dn,dmSn")))]
2023   "!TARGET_COLDFIRE"
2025   if (GET_CODE (operands[2]) == CONST_INT)
2026     {
2027       if (INTVAL (operands[2]) >= 128)
2028         operands[2] = GEN_INT (INTVAL (operands[2]) - 256);
2030       if (INTVAL (operands[2]) > 0
2031           && INTVAL (operands[2]) <= 8)
2032         return "addq%.b %2,%0";
2033       if (INTVAL (operands[2]) < 0 && INTVAL (operands[2]) >= -8)
2034        {
2035          operands[2] = GEN_INT (- INTVAL (operands[2]));
2036          return "subq%.b %2,%0";
2037        }
2038     }
2039   return "add%.b %2,%0";
2042 (define_insn ""
2043   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+m,d"))
2044         (plus:QI (match_dup 0)
2045                  (match_operand:QI 1 "general_src_operand" "dn,dmSn")))]
2046   "!TARGET_COLDFIRE"
2048   if (GET_CODE (operands[1]) == CONST_INT)
2049     {
2050       if (INTVAL (operands[1]) >= 128)
2051         operands[1] = GEN_INT (INTVAL (operands[1]) - 256);
2053       if (INTVAL (operands[1]) > 0
2054           && INTVAL (operands[1]) <= 8)
2055         return "addq%.b %1,%0";
2056       if (INTVAL (operands[1]) < 0 && INTVAL (operands[1]) >= -8)
2057        {
2058          operands[1] = GEN_INT (- INTVAL (operands[1]));
2059          return "subq%.b %1,%0";
2060        }
2061     }
2062   return "add%.b %1,%0";
2065 (define_insn ""
2066   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+m,d"))
2067         (plus:QI (match_operand:QI 1 "general_src_operand" "dn,dmSn")
2068                  (match_dup 0)))]
2069   "!TARGET_COLDFIRE"
2071   if (GET_CODE (operands[1]) == CONST_INT)
2072     {
2073       if (INTVAL (operands[1]) >= 128)
2074         operands[1] = GEN_INT (INTVAL (operands[1]) - 256);
2076       if (INTVAL (operands[1]) > 0
2077           && INTVAL (operands[1]) <= 8)
2078         return "addq%.b %1,%0";
2079       if (INTVAL (operands[1]) < 0 && INTVAL (operands[1]) >= -8)
2080        {
2081          operands[1] = GEN_INT (- INTVAL (operands[1]));
2082          return "subq%.b %1,%0";
2083        }
2084     }
2085   return "add%.b %1,%0";
2088 (define_expand "adddf3"
2089   [(set (match_operand:DF 0 "nonimmediate_operand" "")
2090         (plus:DF (match_operand:DF 1 "general_operand" "")
2091                  (match_operand:DF 2 "general_operand" "")))]
2092   "TARGET_68881"
2093   "")
2095 (define_insn ""
2096   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
2097         (plus:DF (float:DF (match_operand:SI 2 "general_operand" "dmi"))
2098                  (match_operand:DF 1 "general_operand" "0")))]
2099   "TARGET_68881"
2100   "f%&add%.l %2,%0")
2102 (define_insn ""
2103   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
2104         (plus:DF (float:DF (match_operand:HI 2 "general_operand" "dmn"))
2105                  (match_operand:DF 1 "general_operand" "0")))]
2106   "TARGET_68881"
2107   "f%&add%.w %2,%0")
2109 (define_insn ""
2110   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
2111         (plus:DF (float:DF (match_operand:QI 2 "general_operand" "dmn"))
2112                  (match_operand:DF 1 "general_operand" "0")))]
2113   "TARGET_68881"
2114   "f%&add%.b %2,%0")
2116 (define_insn ""
2117   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
2118         (plus:DF (match_operand:DF 1 "general_operand" "%0")
2119                  (match_operand:DF 2 "general_operand" "fmG")))]
2120   "TARGET_68881"
2122   if (REG_P (operands[2]))
2123     return "f%&add%.x %2,%0";
2124   return "f%&add%.d %f2,%0";
2127 (define_expand "addsf3"
2128   [(set (match_operand:SF 0 "nonimmediate_operand" "")
2129         (plus:SF (match_operand:SF 1 "general_operand" "")
2130                  (match_operand:SF 2 "general_operand" "")))]
2131   "TARGET_68881"
2132   "")
2134 (define_insn ""
2135   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
2136         (plus:SF (float:SF (match_operand:SI 2 "general_operand" "dmi"))
2137                  (match_operand:SF 1 "general_operand" "0")))]
2138   "TARGET_68881"
2139   "f%$add%.l %2,%0")
2141 (define_insn ""
2142   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
2143         (plus:SF (float:SF (match_operand:HI 2 "general_operand" "dmn"))
2144                  (match_operand:SF 1 "general_operand" "0")))]
2145   "TARGET_68881"
2146   "f%$add%.w %2,%0")
2148 (define_insn ""
2149   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
2150         (plus:SF (float:SF (match_operand:QI 2 "general_operand" "dmn"))
2151                  (match_operand:SF 1 "general_operand" "0")))]
2152   "TARGET_68881"
2153   "f%$add%.b %2,%0")
2155 (define_insn ""
2156   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
2157         (plus:SF (match_operand:SF 1 "general_operand" "%0")
2158                  (match_operand:SF 2 "general_operand" "fdmF")))]
2159   "TARGET_68881"
2161   if (REG_P (operands[2]) && ! DATA_REG_P (operands[2]))
2162     return "f%$add%.x %2,%0";
2163   return "f%$add%.s %f2,%0";
2166 ;; subtract instructions
2168 (define_insn "subdi_sexthishl32"
2169   [(set (match_operand:DI 0 "nonimmediate_operand" "=o,a,*d,*d")
2170     (minus:DI (match_operand:DI 1 "general_operand" "0,0,0,0")
2171         (ashift:DI (sign_extend:DI (match_operand:HI 2 "general_operand" "rm,rm,rm,rm"))
2172             (const_int 32))))
2173    (clobber (match_scratch:SI 3 "=&d,X,a,?d"))]
2174   "!TARGET_COLDFIRE"
2176   CC_STATUS_INIT;
2177   if (ADDRESS_REG_P (operands[0]))
2178     return "sub%.w %2,%0";
2179   else if (ADDRESS_REG_P (operands[3]))
2180     return "move%.w %2,%3\;sub%.l %3,%0";
2181   else
2182     return "move%.w %2,%3\;ext%.l %3\;sub%.l %3,%0";
2185 (define_insn "subdi_dishl32"
2186   [(set (match_operand:DI 0 "nonimmediate_operand" "+ro")
2187     (minus:DI (match_dup 0)
2188         (ashift:DI (match_operand:DI 1 "general_operand" "ro")
2189             (const_int 32))))]
2190   ""
2192   CC_STATUS_INIT;
2193   if (GET_CODE (operands[1]) == REG)
2194     operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
2195   else
2196     operands[1] = adjust_address (operands[1], SImode, 4);
2197   return "sub%.l %1,%0";
2200 (define_insn "subdi3"
2201   [(set (match_operand:DI 0 "nonimmediate_operand" "=<,o<>,d,d,d")
2202         (minus:DI (match_operand:DI 1 "general_operand" "0,0,0,0,0")
2203                  (match_operand:DI 2 "general_operand" "<,d,no>,d,a")))
2204    (clobber (match_scratch:SI 3 "=X,&d,&d,X,&d"))]
2205   ""
2207   if (DATA_REG_P (operands[0]))
2208     {
2209       if (DATA_REG_P (operands[2]))
2210         return "sub%.l %R2,%R0\;subx%.l %2,%0";
2211       else if (GET_CODE (operands[2]) == MEM
2212           && GET_CODE (XEXP (operands[2], 0)) == POST_INC)
2213         {
2214           return "move%.l %2,%3\;sub%.l %2,%R0\;subx%.l %3,%0";
2215         }
2216       else
2217         {
2218           rtx high, low;
2219           rtx xoperands[2];
2221           if (GET_CODE (operands[2]) == REG)
2222             {
2223               low = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
2224               high = operands[2];
2225             }
2226           else if (CONSTANT_P (operands[2]))
2227             split_double (operands[2], &high, &low);
2228           else
2229             {
2230               low = adjust_address (operands[2], SImode, 4);
2231               high = operands[2];
2232             }
2234           operands[1] = low, operands[2] = high;
2235           xoperands[0] = operands[3];
2236           if (GET_CODE (operands[1]) == CONST_INT
2237               && INTVAL (operands[1]) >= -8 && INTVAL (operands[1]) < 0)
2238             xoperands[1] = GEN_INT (-INTVAL (operands[2]) - 1);
2239           else
2240             xoperands[1] = operands[2];
2242           output_asm_insn (output_move_simode (xoperands), xoperands);
2243           if (GET_CODE (operands[1]) == CONST_INT)
2244             {
2245               if (INTVAL (operands[1]) > 0 && INTVAL (operands[1]) <= 8)
2246                 return "subq%.l %1,%R0\;subx%.l %3,%0";
2247               else if (INTVAL (operands[1]) >= -8 && INTVAL (operands[1]) < 0)
2248                 {
2249                   operands[1] = GEN_INT (-INTVAL (operands[1]));
2250                   return "addq%.l %1,%R0\;addx%.l %3,%0";
2251                 }
2252             }
2253           return "sub%.l %1,%R0\;subx%.l %3,%0";
2254         }
2255     }
2256   else
2257     {
2258       gcc_assert (GET_CODE (operands[0]) == MEM);
2259       if (GET_CODE (operands[2]) == MEM
2260           && GET_CODE (XEXP (operands[2], 0)) == PRE_DEC)
2261         return "sub%.l %2,%0\;subx%.l %2,%0";
2262       CC_STATUS_INIT;
2263       if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
2264         {
2265           operands[1]
2266             = gen_rtx_MEM (SImode, plus_constant (XEXP (operands[0], 0), -8));
2267           return "move%.l %0,%3\;sub%.l %R2,%0\;subx%.l %2,%3\;move%.l %3,%1";
2268         }
2269       else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
2270         {
2271           operands[1] = XEXP(operands[0], 0);
2272           return "sub%.l %R2,%0\;move%.l %0,%3\;subx%.l %2,%3\;move%.l %3,%1";
2273         }
2274       else
2275         {
2276           operands[1] = adjust_address (operands[0], SImode, 4);
2277           return "sub%.l %R2,%1\;move%.l %0,%3\;subx%.l %2,%3\;move%.l %3,%0";
2278         }
2279     }
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       gcc_assert (result);
3580       if (result != target)
3581         emit_move_insn (result, target);
3583       /* Make a place for REG_EQUAL.  */
3584       emit_move_insn (operands[0], operands[0]);
3585       DONE;
3586     }
3589 (define_insn ""
3590   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,d")
3591         (neg:SF (match_operand:SF 1 "general_operand" "fdmF,0")))]
3592   "TARGET_68881"
3594   if (DATA_REG_P (operands[0]))
3595     {
3596       operands[1] = GEN_INT (31);
3597       return "bchg %1,%0";
3598     }
3599   if (REG_P (operands[1]) && ! DATA_REG_P (operands[1]))
3600     return "f%$neg%.x %1,%0";
3601   return "f%$neg%.s %f1,%0";
3604 (define_expand "negdf2"
3605   [(set (match_operand:DF 0 "nonimmediate_operand" "")
3606         (neg:DF (match_operand:DF 1 "general_operand" "")))]
3607   ""
3609   if (!TARGET_68881)
3610     {
3611       rtx result;
3612       rtx target;
3613       rtx insns;
3615       start_sequence ();
3616       target = operand_subword (operands[0], 0, 1, DFmode);
3617       result = expand_binop (SImode, xor_optab,
3618                              operand_subword_force (operands[1], 0, DFmode),
3619                              GEN_INT (0x80000000), target, 0, OPTAB_WIDEN);
3620       gcc_assert (result);
3622       if (result != target)
3623         emit_move_insn (result, target);
3625       emit_move_insn (operand_subword (operands[0], 1, 1, DFmode),
3626                       operand_subword_force (operands[1], 1, DFmode));
3628       insns = get_insns ();
3629       end_sequence ();
3631       emit_no_conflict_block (insns, operands[0], operands[1], 0, 0);
3632       DONE;
3633     }
3636 (define_insn ""
3637   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,d")
3638         (neg:DF (match_operand:DF 1 "general_operand" "fmF,0")))]
3639   "TARGET_68881"
3641   if (DATA_REG_P (operands[0]))
3642     {
3643       operands[1] = GEN_INT (31);
3644       return "bchg %1,%0";
3645     }
3646   if (REG_P (operands[1]) && ! DATA_REG_P (operands[1]))
3647     return "f%&neg%.x %1,%0";
3648   return "f%&neg%.d %f1,%0";
3651 ;; Sqrt instruction for the 68881
3653 (define_insn "sqrtsf2"
3654   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
3655         (sqrt:SF (match_operand:SF 1 "general_operand" "fm")))]
3656   "TARGET_68881"
3658   if (FP_REG_P (operands[1]))
3659     return "f%$sqrt%.x %1,%0";
3660   else
3661     return "f%$sqrt%.s %1,%0";
3664 (define_insn "sqrtdf2"
3665   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
3666         (sqrt:DF (match_operand:DF 1 "general_operand" "fm")))]
3667   "TARGET_68881"
3669   if (FP_REG_P (operands[1]))
3670     return "f%&sqrt%.x %1,%0";
3671   else
3672     return "f%&sqrt%.d %1,%0";
3675 ;; Absolute value instructions
3676 ;; If using software floating point, just zero the sign bit.
3678 (define_expand "abssf2"
3679   [(set (match_operand:SF 0 "nonimmediate_operand" "")
3680         (abs:SF (match_operand:SF 1 "general_operand" "")))]
3681   ""
3683   if (!TARGET_68881)
3684     {
3685       rtx result;
3686       rtx target;
3688       target = operand_subword_force (operands[0], 0, SFmode);
3689       result = expand_binop (SImode, and_optab,
3690                              operand_subword_force (operands[1], 0, SFmode),
3691                              GEN_INT (0x7fffffff), target, 0, OPTAB_WIDEN);
3692       gcc_assert (result);
3694       if (result != target)
3695         emit_move_insn (result, target);
3697       /* Make a place for REG_EQUAL.  */
3698       emit_move_insn (operands[0], operands[0]);
3699       DONE;
3700     }
3703 (define_insn ""
3704   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
3705         (abs:SF (match_operand:SF 1 "general_operand" "fdmF")))]
3706   "TARGET_68881"
3708   if (REG_P (operands[1]) && ! DATA_REG_P (operands[1]))
3709     return "f%$abs%.x %1,%0";
3710   return "f%$abs%.s %f1,%0";
3713 (define_expand "absdf2"
3714   [(set (match_operand:DF 0 "nonimmediate_operand" "")
3715         (abs:DF (match_operand:DF 1 "general_operand" "")))]
3716   ""
3718   if (!TARGET_68881)
3719     {
3720       rtx result;
3721       rtx target;
3722       rtx insns;
3724       start_sequence ();
3725       target = operand_subword (operands[0], 0, 1, DFmode);
3726       result = expand_binop (SImode, and_optab,
3727                              operand_subword_force (operands[1], 0, DFmode),
3728                              GEN_INT (0x7fffffff), target, 0, OPTAB_WIDEN);
3729       gcc_assert (result);
3731       if (result != target)
3732         emit_move_insn (result, target);
3734       emit_move_insn (operand_subword (operands[0], 1, 1, DFmode),
3735                       operand_subword_force (operands[1], 1, DFmode));
3737       insns = get_insns ();
3738       end_sequence ();
3740       emit_no_conflict_block (insns, operands[0], operands[1], 0, 0);
3741       DONE;
3742     }
3745 (define_insn ""
3746   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
3747         (abs:DF (match_operand:DF 1 "general_operand" "fmF")))]
3748   "TARGET_68881"
3750   if (REG_P (operands[1]) && ! DATA_REG_P (operands[1]))
3751     return "f%&abs%.x %1,%0";
3752   return "f%&abs%.d %f1,%0";
3755 ;; one complement instructions
3757 ;; "one_cmpldi2" is mainly here to help combine().
3758 (define_insn "one_cmpldi2"
3759   [(set (match_operand:DI 0 "nonimmediate_operand" "=dm")
3760         (not:DI (match_operand:DI 1 "general_operand" "0")))]
3761   "!TARGET_COLDFIRE"
3763   CC_STATUS_INIT;
3764   if (GET_CODE (operands[0]) == REG)
3765     operands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3766   else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC
3767         || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
3768     operands[1] = operands[0];
3769   else
3770     operands[1] = adjust_address (operands[0], SImode, 4);
3771   return "not%.l %1\;not%.l %0";
3774 (define_expand "one_cmplsi2"
3775   [(set (match_operand:SI 0 "nonimmediate_operand" "")
3776         (not:SI (match_operand:SI 1 "general_operand" "")))]
3777   ""
3779   if (TARGET_COLDFIRE)
3780     emit_insn (gen_one_cmplsi2_5200 (operands[0], operands[1]));
3781   else
3782     emit_insn (gen_one_cmplsi2_internal (operands[0], operands[1]));
3783   DONE;
3786 (define_insn "one_cmplsi2_internal"
3787   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
3788         (not:SI (match_operand:SI 1 "general_operand" "0")))]
3789   "!TARGET_COLDFIRE"
3790   "not%.l %0")
3792 (define_insn "one_cmplsi2_5200"
3793   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
3794         (not:SI (match_operand:SI 1 "general_operand" "0")))]
3795   "TARGET_COLDFIRE"
3796   "not%.l %0")
3798 (define_insn "one_cmplhi2"
3799   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm")
3800         (not:HI (match_operand:HI 1 "general_operand" "0")))]
3801   "!TARGET_COLDFIRE"
3802   "not%.w %0")
3804 (define_insn ""
3805   [(set (strict_low_part (match_operand:HI 0 "nonimmediate_operand" "+dm"))
3806         (not:HI (match_dup 0)))]
3807   "!TARGET_COLDFIRE"
3808   "not%.w %0")
3810 (define_insn "one_cmplqi2"
3811   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
3812         (not:QI (match_operand:QI 1 "general_operand" "0")))]
3813   "!TARGET_COLDFIRE"
3814   "not%.b %0")
3816 (define_insn ""
3817   [(set (strict_low_part (match_operand:QI 0 "nonimmediate_operand" "+dm"))
3818         (not:QI (match_dup 0)))]
3819   "!TARGET_COLDFIRE"
3820   "not%.b %0")
3822 ;; arithmetic shift instructions
3823 ;; We don't need the shift memory by 1 bit instruction
3825 (define_insn "ashldi_extsi"
3826   [(set (match_operand:DI 0 "nonimmediate_operand" "=ro")
3827     (ashift:DI
3828       (match_operator:DI 2 "extend_operator"
3829         [(match_operand:SI 1 "general_operand" "rm")])
3830       (const_int 32)))]
3831   ""
3833   CC_STATUS_INIT;
3834   if (GET_CODE (operands[0]) == REG)
3835     operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3836   else
3837     operands[2] = adjust_address (operands[0], SImode, 4);
3838   if (ADDRESS_REG_P (operands[0]))
3839     return "move%.l %1,%0\;sub%.l %2,%2";
3840   else
3841     return "move%.l %1,%0\;clr%.l %2";
3844 (define_insn "ashldi_sexthi"
3845   [(set (match_operand:DI 0 "nonimmediate_operand" "=m,a*d")
3846     (ashift:DI (sign_extend:DI (match_operand:HI 1 "general_operand" "rm,rm"))
3847         (const_int 32)))
3848     (clobber (match_scratch:SI 2 "=a,X"))]
3849   ""
3851   CC_STATUS_INIT;
3852   if (GET_CODE (operands[0]) == MEM)
3853     {
3854     if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
3855       return "clr%.l %0\;move%.w %1,%2\;move%.l %2,%0";
3856     else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
3857       return "move%.w %1,%2\;move%.l %2,%0\;clr%.l %0";
3858     else
3859       {
3860         operands[3] = adjust_address (operands[0], SImode, 4);
3861         return "move%.w %1,%2\;move%.l %2,%0\;clr%.l %3";
3862       }
3863     }
3864   else if (DATA_REG_P (operands[0]))
3865     return "move%.w %1,%0\;ext%.l %0\;clr%.l %R0";
3866   else
3867     return "move%.w %1,%0\;sub%.l %R0,%R0";
3870 (define_insn "ashldi_const32"
3871   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
3872         (ashift:DI (match_operand:DI 1 "general_operand" "ro")
3873                      (const_int 32)))]
3874   ""
3876   CC_STATUS_INIT;
3877   if (GET_CODE (operands[1]) == REG)
3878     operands[3] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
3879   else
3880     operands[3] = adjust_address (operands[1], SImode, 4);
3881   if (GET_CODE (operands[0]) == REG)
3882     operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3883   else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
3884     return "clr%.l %0\;move%.l %3,%0";
3885   else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
3886     return "move%.l %3,%0\;clr%.l %0";
3887   else
3888     operands[2] = adjust_address (operands[0], SImode, 4);
3889   if (ADDRESS_REG_P (operands[2]))
3890     return "move%.l %3,%0\;sub%.l %2,%2";
3891   else
3892     return "move%.l %3,%0\;clr%.l %2";
3895 ;; The predicate below must be general_operand, because ashldi3 allows that
3896 (define_insn "ashldi_const"
3897   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
3898         (ashift:DI (match_operand:DI 1 "general_operand" "0")
3899                      (match_operand 2 "const_int_operand" "n")))]
3900   "(!TARGET_COLDFIRE
3901     && ((INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 3)
3902         || INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 16
3903         || (INTVAL (operands[2]) > 32 && INTVAL (operands[2]) <= 63)))"
3905   operands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3906   if (INTVAL (operands[2]) == 1)
3907     return "add%.l %1,%1\;addx%.l %0,%0";
3908   else if (INTVAL (operands[2]) == 8)
3909     return "rol%.l #8,%1\;rol%.l #8,%0\;move%.b %1,%0\;clr%.b %1";
3910   else if (INTVAL (operands[2]) == 16)
3911     return "swap %1\;swap %0\;move%.w %1,%0\;clr%.w %1";
3912   else if (INTVAL (operands[2]) == 48)
3913     return "mov%.l %1,%0\;swap %0\;clr%.l %1\;clr%.w %0";
3914   else if (INTVAL (operands[2]) == 2)
3915     return "add%.l %1,%1\;addx%.l %0,%0\;add%.l %1,%1\;addx%.l %0,%0";
3916   else if (INTVAL (operands[2]) == 3)
3917     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";
3918   else /* 32 < INTVAL (operands[2]) <= 63 */
3919     {
3920       operands[2] = GEN_INT (INTVAL (operands[2]) - 32);
3921       output_asm_insn (INTVAL (operands[2]) <= 8 ? "asl%.l %2,%1" :
3922                         "moveq %2,%0\;asl%.l %0,%1", operands);
3923       return "mov%.l %1,%0\;moveq #0,%1";
3924     }
3927 (define_expand "ashldi3"
3928   [(set (match_operand:DI 0 "nonimmediate_operand" "")
3929         (ashift:DI (match_operand:DI 1 "general_operand" "")
3930                      (match_operand 2 "const_int_operand" "")))]
3931   "!TARGET_COLDFIRE"
3932   "
3934   /* ???  This is a named pattern like this is not allowed to FAIL based
3935      on its operands.  */
3936   if (GET_CODE (operands[2]) != CONST_INT
3937       || ((INTVAL (operands[2]) < 1 || INTVAL (operands[2]) > 3)
3938           && INTVAL (operands[2]) != 8 && INTVAL (operands[2]) != 16
3939           && (INTVAL (operands[2]) < 32 || INTVAL (operands[2]) > 63)))
3940     FAIL;
3941 } ")
3943 ;; On most 68k models, this makes faster code in a special case.
3945 (define_insn "ashlsi_16"
3946   [(set (match_operand:SI 0 "register_operand" "=d")
3947         (ashift:SI (match_operand:SI 1 "register_operand" "0")
3948                    (const_int 16)))]
3949   "!TARGET_68060"
3951   CC_STATUS_INIT;
3952   return "swap %0\;clr%.w %0";
3955 ;; ashift patterns : use lsl instead of asl, because lsl always clears the
3956 ;; overflow bit, so we must not set CC_NO_OVERFLOW.
3958 ;; On the 68000, this makes faster code in a special case.
3960 (define_insn "ashlsi_17_24"
3961   [(set (match_operand:SI 0 "register_operand" "=d")
3962         (ashift:SI (match_operand:SI 1 "register_operand" "0")
3963                    (match_operand:SI 2 "const_int_operand" "n")))]
3964   "(! TARGET_68020 && !TARGET_COLDFIRE
3965     && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24)"
3967   CC_STATUS_INIT;
3969   operands[2] = GEN_INT (INTVAL (operands[2]) - 16);
3970   return "lsl%.w %2,%0\;swap %0\;clr%.w %0";
3973 (define_insn "ashlsi3"
3974   [(set (match_operand:SI 0 "register_operand" "=d")
3975         (ashift:SI (match_operand:SI 1 "register_operand" "0")
3976                    (match_operand:SI 2 "general_operand" "dI")))]
3977   ""
3979   if (operands[2] == const1_rtx)
3980     {
3981       cc_status.flags = CC_NO_OVERFLOW;
3982       return "add%.l %0,%0";
3983     }
3984   return "lsl%.l %2,%0";
3987 (define_insn "ashlhi3"
3988   [(set (match_operand:HI 0 "register_operand" "=d")
3989         (ashift:HI (match_operand:HI 1 "register_operand" "0")
3990                    (match_operand:HI 2 "general_operand" "dI")))]
3991   "!TARGET_COLDFIRE"
3992   "lsl%.w %2,%0")
3994 (define_insn ""
3995   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
3996         (ashift:HI (match_dup 0)
3997                    (match_operand:HI 1 "general_operand" "dI")))]
3998   "!TARGET_COLDFIRE"
3999   "lsl%.w %1,%0")
4001 (define_insn "ashlqi3"
4002   [(set (match_operand:QI 0 "register_operand" "=d")
4003         (ashift:QI (match_operand:QI 1 "register_operand" "0")
4004                    (match_operand:QI 2 "general_operand" "dI")))]
4005   "!TARGET_COLDFIRE"
4006   "lsl%.b %2,%0")
4008 (define_insn ""
4009   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d"))
4010         (ashift:QI (match_dup 0)
4011                    (match_operand:QI 1 "general_operand" "dI")))]
4012   "!TARGET_COLDFIRE"
4013   "lsl%.b %1,%0")
4015 ;; On most 68k models, this makes faster code in a special case.
4017 (define_insn "ashrsi_16"
4018   [(set (match_operand:SI 0 "register_operand" "=d")
4019         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
4020                      (const_int 16)))]
4021   "!TARGET_68060"
4022   "swap %0\;ext%.l %0")
4024 ;; On the 68000, this makes faster code in a special case.
4026 (define_insn ""
4027   [(set (match_operand:SI 0 "register_operand" "=d")
4028         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
4029                      (match_operand:SI 2 "const_int_operand" "n")))]
4030   "(! TARGET_68020 && !TARGET_COLDFIRE
4031     && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24)"
4033   operands[2] = GEN_INT (INTVAL (operands[2]) - 16);
4034   return "swap %0\;asr%.w %2,%0\;ext%.l %0";
4037 (define_insn "subreghi1ashrdi_const32"
4038   [(set (match_operand:HI 0 "nonimmediate_operand" "=rm")
4039     (subreg:HI (ashiftrt:DI (match_operand:DI 1 "general_operand" "ro")
4040             (const_int 32)) 6))]
4041   ""
4043   if (GET_CODE (operands[1]) != REG)
4044     operands[1] = adjust_address (operands[1], HImode, 2);
4045   return "move%.w %1,%0";
4048 (define_insn "subregsi1ashrdi_const32"
4049   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
4050     (subreg:SI (ashiftrt:DI (match_operand:DI 1 "general_operand" "ro")
4051             (const_int 32)) 4))]
4052   ""
4054   return "move%.l %1,%0";
4057 (define_insn "ashrdi_const32"
4058   [(set (match_operand:DI 0 "register_operand" "=d")
4059         (ashiftrt:DI (match_operand:DI 1 "general_operand" "ro")
4060                      (const_int 32)))]
4061   ""
4063   CC_STATUS_INIT;
4064   operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
4065   if (TARGET_68020)
4066     return "move%.l %1,%2\;smi %0\;extb%.l %0";
4067   else
4068     return "move%.l %1,%2\;smi %0\;ext%.w %0\;ext%.l %0";
4071 (define_insn "ashrdi_const32_mem"
4072   [(set (match_operand:DI 0 "nonimmediate_operand" "=o,<")
4073         (ashiftrt:DI (match_operand:DI 1 "general_operand" "ro,ro")
4074                      (const_int 32)))
4075    (clobber (match_scratch:SI 2 "=d,d"))]
4076   ""
4078   CC_STATUS_INIT;
4079   if (which_alternative == 1)
4080     operands[3] = operands[0];
4081   else
4082     operands[3] = adjust_address (operands[0], SImode, 4);
4083   if (TARGET_68020)
4084     return "move%.l %1,%3\;smi %2\;extb%.l %2\;move%.l %2,%0";
4085   else
4086     return "move%.l %1,%3\;smi %2\;ext%.w %2\;ext%.l %2\;move%.l %2,%0";
4089 ;; The predicate below must be general_operand, because ashrdi3 allows that
4090 (define_insn "ashrdi_const"
4091   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
4092         (ashiftrt:DI (match_operand:DI 1 "general_operand" "0")
4093                      (match_operand 2 "const_int_operand" "n")))]
4094   "(!TARGET_COLDFIRE 
4095     && ((INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 3)
4096         || INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 16
4097         || INTVAL (operands[2]) == 31
4098         || (INTVAL (operands[2]) > 32 && INTVAL (operands[2]) <= 63)))"
4100   operands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
4101   if (INTVAL (operands[2]) == 63)
4102     return "add%.l %0,%0\;subx%.l %0,%0\;move%.l %0,%1";
4103   CC_STATUS_INIT;
4104   if (INTVAL (operands[2]) == 1)
4105     return "asr%.l #1,%0\;roxr%.l #1,%1";
4106   else if (INTVAL (operands[2]) == 8)
4107     return "move%.b %0,%1\;asr%.l #8,%0\;ror%.l #8,%1";
4108   else if (INTVAL (operands[2]) == 16)
4109     return "move%.w %0,%1\;swap %0\;ext%.l %0\;swap %1";
4110   else if (INTVAL (operands[2]) == 48)
4111     return "swap %0\;ext%.l %0\;move%.l %0,%1\;smi %0\;ext%.w %0";
4112   else if (INTVAL (operands[2]) == 31)
4113     return "add%.l %1,%1\;addx%.l %0,%0\;move%.l %0,%1\;subx%.l %0,%0";
4114   else if (INTVAL (operands[2]) == 2)
4115     return "asr%.l #1,%0\;roxr%.l #1,%1\;asr%.l #1,%0\;roxr%.l #1,%1";
4116   else if (INTVAL (operands[2]) == 3)
4117     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";
4118   else /* 32 < INTVAL (operands[2]) <= 63 */
4119     {
4120       operands[2] = GEN_INT (INTVAL (operands[2]) - 32);
4121       output_asm_insn (INTVAL (operands[2]) <= 8 ? "asr%.l %2,%0" :
4122                         "moveq %2,%1\;asr%.l %1,%0", operands);
4123       output_asm_insn ("mov%.l %0,%1\;smi %0", operands);
4124       return INTVAL (operands[2]) >= 15 ? "ext%.w %d0" :
4125              TARGET_68020 ? "extb%.l %0" : "ext%.w %0\;ext%.l %0";
4126     }
4129 (define_expand "ashrdi3"
4130   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4131         (ashiftrt:DI (match_operand:DI 1 "general_operand" "")
4132                      (match_operand 2 "const_int_operand" "")))]
4133   "!TARGET_COLDFIRE"
4134   "
4136   /* ???  This is a named pattern like this is not allowed to FAIL based
4137      on its operands.  */
4138   if (GET_CODE (operands[2]) != CONST_INT
4139       || ((INTVAL (operands[2]) < 1 || INTVAL (operands[2]) > 3)
4140           && INTVAL (operands[2]) != 8 && INTVAL (operands[2]) != 16
4141           && (INTVAL (operands[2]) < 31 || INTVAL (operands[2]) > 63)))
4142     FAIL;
4143 } ")
4145 ;; On all 68k models, this makes faster code in a special case.
4147 (define_insn "ashrsi_31"
4148   [(set (match_operand:SI 0 "register_operand" "=d")
4149         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
4150                      (const_int 31)))]
4151   ""
4153   return "add%.l %0,%0\;subx%.l %0,%0";
4156 (define_insn "ashrsi3"
4157   [(set (match_operand:SI 0 "register_operand" "=d")
4158         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
4159                      (match_operand:SI 2 "general_operand" "dI")))]
4160   ""
4161   "asr%.l %2,%0")
4163 (define_insn "ashrhi3"
4164   [(set (match_operand:HI 0 "register_operand" "=d")
4165         (ashiftrt:HI (match_operand:HI 1 "register_operand" "0")
4166                      (match_operand:HI 2 "general_operand" "dI")))]
4167   "!TARGET_COLDFIRE"
4168   "asr%.w %2,%0")
4170 (define_insn ""
4171   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
4172         (ashiftrt:HI (match_dup 0)
4173                      (match_operand:HI 1 "general_operand" "dI")))]
4174   "!TARGET_COLDFIRE"
4175   "asr%.w %1,%0")
4177 (define_insn "ashrqi3"
4178   [(set (match_operand:QI 0 "register_operand" "=d")
4179         (ashiftrt:QI (match_operand:QI 1 "register_operand" "0")
4180                      (match_operand:QI 2 "general_operand" "dI")))]
4181   "!TARGET_COLDFIRE"
4182   "asr%.b %2,%0")
4184 (define_insn ""
4185   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d"))
4186         (ashiftrt:QI (match_dup 0)
4187                      (match_operand:QI 1 "general_operand" "dI")))]
4188   "!TARGET_COLDFIRE"
4189   "asr%.b %1,%0")
4191 ;; logical shift instructions
4193 ;; commented out because of reload problems in 950612-1.c
4194 ;;(define_insn ""
4195 ;;        [(set (cc0)
4196 ;;            (subreg:SI (lshiftrt:DI (match_operand:DI 0 "general_operand" "ro")
4197 ;;                    (const_int 32)) 4))
4198 ;;        (set (match_operand:SI 1 "nonimmediate_operand" "=dm")
4199 ;;            (subreg:SI (lshiftrt:DI (match_dup 0)
4200 ;;                    (const_int 32)) 4))]
4201 ;;  ""
4203 ;;  return "move%.l %0,%1";
4204 ;;})
4206 ;;(define_insn ""
4207 ;;        [(set (cc0)
4208 ;;            (subreg:SI (lshiftrt:DI (match_operand:DI 0 "general_operand" "ro")
4209 ;;                    (const_int 32)) 0))
4210 ;;        (set (match_operand:DI 1 "nonimmediate_operand" "=do")
4211 ;;            (lshiftrt:DI (match_dup 0)
4212 ;;                (const_int 32)))]
4213 ;;  ""
4215 ;;  if (GET_CODE (operands[1]) == REG)
4216 ;;    operands[2] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
4217 ;;  else
4218 ;;    operands[2] = adjust_address (operands[1], SImode, 4);
4219 ;;  return "move%.l %0,%2\;clr%.l %1";
4220 ;;})
4222 (define_insn "subreg1lshrdi_const32"
4223   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
4224     (subreg:SI (lshiftrt:DI (match_operand:DI 1 "general_operand" "ro")
4225             (const_int 32)) 4))]
4226   ""
4228   return "move%.l %1,%0";
4231 (define_insn "lshrdi_const32"
4232   [(set (match_operand:DI 0 "nonimmediate_operand" "=ro,<,>")
4233         (lshiftrt:DI (match_operand:DI 1 "general_operand" "ro,ro,ro")
4234                      (const_int 32)))]
4235   ""
4237   CC_STATUS_INIT;
4238   if (which_alternative == 1)
4239     return "move%.l %1,%0\;clr%.l %0";
4240   if (which_alternative == 2)
4241     return "clr%.l %0\;move%.l %1,%0";
4242   if (GET_CODE (operands[0]) == REG)
4243     operands[2] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
4244   else
4245     operands[2] = adjust_address (operands[0], SImode, 4);
4246   if (GET_CODE (operands[1]) == REG)
4247     operands[3] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
4248   else
4249     operands[3] = adjust_address (operands[1], SImode, 4);
4250   if (ADDRESS_REG_P (operands[0]))
4251     return "move%.l %1,%2\;sub%.l %0,%0";
4252   else
4253     return "move%.l %1,%2\;clr%.l %0";
4256 ;; The predicate below must be general_operand, because lshrdi3 allows that
4257 (define_insn "lshrdi_const"
4258   [(set (match_operand:DI 0 "nonimmediate_operand" "=d")
4259         (lshiftrt:DI (match_operand:DI 1 "general_operand" "0")
4260                      (match_operand 2 "const_int_operand" "n")))]
4261   "(!TARGET_COLDFIRE
4262     && ((INTVAL (operands[2]) >= 1 && INTVAL (operands[2]) <= 3)
4263          || INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 16
4264          || (INTVAL (operands[2]) > 32 && INTVAL (operands[2]) <= 63)))"
4266   operands[1] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
4267   if (INTVAL (operands[2]) == 63)
4268     return "add%.l %0,%0\;clr%.l %0\;clr%.l %1\;addx%.l %1,%1";
4269   CC_STATUS_INIT;
4270   if (INTVAL (operands[2]) == 1)
4271     return "lsr%.l #1,%0\;roxr%.l #1,%1";
4272   else if (INTVAL (operands[2]) == 8)
4273     return "move%.b %0,%1\;lsr%.l #8,%0\;ror%.l #8,%1";
4274   else if (INTVAL (operands[2]) == 16)
4275     return "move%.w %0,%1\;clr%.w %0\;swap %1\;swap %0";
4276   else if (INTVAL (operands[2]) == 48)
4277     return "move%.l %0,%1\;clr%.w %1\;clr%.l %0\;swap %1";
4278   else if (INTVAL (operands[2]) == 2)
4279     return "lsr%.l #1,%0\;roxr%.l #1,%1\;lsr%.l #1,%0\;roxr%.l #1,%1";
4280   else if (INTVAL (operands[2]) == 3)
4281     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";
4282   else /* 32 < INTVAL (operands[2]) <= 63 */
4283     {
4284       operands[2] = GEN_INT (INTVAL (operands[2]) - 32);
4285       output_asm_insn (INTVAL (operands[2]) <= 8 ? "lsr%.l %2,%0" :
4286                         "moveq %2,%1\;lsr%.l %1,%0", operands);
4287       return "mov%.l %0,%1\;moveq #0,%0";
4288     }
4291 (define_expand "lshrdi3"
4292   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4293         (lshiftrt:DI (match_operand:DI 1 "general_operand" "")
4294                      (match_operand 2 "const_int_operand" "")))]
4295   "!TARGET_COLDFIRE"
4297   /* ???  This is a named pattern like this is not allowed to FAIL based
4298      on its operands.  */
4299   if (GET_CODE (operands[2]) != CONST_INT
4300       || ((INTVAL (operands[2]) < 1 || INTVAL (operands[2]) > 3)
4301           && INTVAL (operands[2]) != 8 && INTVAL (operands[2]) != 16
4302           && (INTVAL (operands[2]) < 32 || INTVAL (operands[2]) > 63)))
4303     FAIL;
4306 ;; On all 68k models, this makes faster code in a special case.
4308 (define_insn "lshrsi_31"
4309   [(set (match_operand:SI 0 "register_operand" "=d")
4310         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
4311                      (const_int 31)))]
4312   ""
4314   return "add%.l %0,%0\;subx%.l %0,%0\;neg%.l %0";
4317 ;; On most 68k models, this makes faster code in a special case.
4319 (define_insn "lshrsi_16"
4320   [(set (match_operand:SI 0 "register_operand" "=d")
4321         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
4322                      (const_int 16)))]
4323   "!TARGET_68060"
4325   CC_STATUS_INIT;
4326   return "clr%.w %0\;swap %0";
4329 ;; On the 68000, this makes faster code in a special case.
4331 (define_insn "lshrsi_17_24"
4332   [(set (match_operand:SI 0 "register_operand" "=d")
4333         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
4334                      (match_operand:SI 2 "const_int_operand" "n")))]
4335   "(! TARGET_68020 && !TARGET_COLDFIRE
4336     && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24)"
4338   /* I think lsr%.w sets the CC properly.  */
4339   operands[2] = GEN_INT (INTVAL (operands[2]) - 16);
4340   return "clr%.w %0\;swap %0\;lsr%.w %2,%0";
4343 (define_insn "lshrsi3"
4344   [(set (match_operand:SI 0 "register_operand" "=d")
4345         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
4346                      (match_operand:SI 2 "general_operand" "dI")))]
4347   ""
4348   "lsr%.l %2,%0")
4350 (define_insn "lshrhi3"
4351   [(set (match_operand:HI 0 "register_operand" "=d")
4352         (lshiftrt:HI (match_operand:HI 1 "register_operand" "0")
4353                      (match_operand:HI 2 "general_operand" "dI")))]
4354   "!TARGET_COLDFIRE"
4355   "lsr%.w %2,%0")
4357 (define_insn ""
4358   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
4359         (lshiftrt:HI (match_dup 0)
4360                      (match_operand:HI 1 "general_operand" "dI")))]
4361   "!TARGET_COLDFIRE"
4362   "lsr%.w %1,%0")
4364 (define_insn "lshrqi3"
4365   [(set (match_operand:QI 0 "register_operand" "=d")
4366         (lshiftrt:QI (match_operand:QI 1 "register_operand" "0")
4367                      (match_operand:QI 2 "general_operand" "dI")))]
4368   "!TARGET_COLDFIRE"
4369   "lsr%.b %2,%0")
4371 (define_insn ""
4372   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d"))
4373         (lshiftrt:QI (match_dup 0)
4374                      (match_operand:QI 1 "general_operand" "dI")))]
4375   "!TARGET_COLDFIRE"
4376   "lsr%.b %1,%0")
4378 ;; rotate instructions
4380 (define_insn "rotlsi3"
4381   [(set (match_operand:SI 0 "register_operand" "=d")
4382         (rotate:SI (match_operand:SI 1 "register_operand" "0")
4383                    (match_operand:SI 2 "general_operand" "dINO")))]
4384   "!TARGET_COLDFIRE"
4386   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) == 16)
4387     return "swap %0";
4388   else if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 16)
4389     {
4390       operands[2] = GEN_INT (32 - INTVAL (operands[2]));
4391       return "ror%.l %2,%0";
4392     }
4393   else
4394     return "rol%.l %2,%0";
4397 (define_insn "rotlhi3"
4398   [(set (match_operand:HI 0 "register_operand" "=d")
4399         (rotate:HI (match_operand:HI 1 "register_operand" "0")
4400                    (match_operand:HI 2 "general_operand" "dIP")))]
4401   "!TARGET_COLDFIRE"
4403   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 8)
4404     {
4405       operands[2] = GEN_INT (16 - INTVAL (operands[2]));
4406       return "ror%.w %2,%0";
4407     }
4408   else
4409     return "rol%.w %2,%0";
4412 (define_insn ""
4413   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
4414         (rotate:HI (match_dup 0)
4415                    (match_operand:HI 1 "general_operand" "dIP")))]
4416   "!TARGET_COLDFIRE"
4418   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 8)
4419     {
4420       operands[2] = GEN_INT (16 - INTVAL (operands[2]));
4421       return "ror%.w %2,%0";
4422     }
4423   else
4424     return "rol%.w %2,%0";
4427 (define_insn "rotlqi3"
4428   [(set (match_operand:QI 0 "register_operand" "=d")
4429         (rotate:QI (match_operand:QI 1 "register_operand" "0")
4430                    (match_operand:QI 2 "general_operand" "dI")))]
4431   "!TARGET_COLDFIRE"
4433   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 4)
4434     {
4435       operands[2] = GEN_INT (8 - INTVAL (operands[2]));
4436       return "ror%.b %2,%0";
4437     }
4438   else
4439     return "rol%.b %2,%0";
4442 (define_insn ""
4443   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d"))
4444         (rotate:QI (match_dup 0)
4445                    (match_operand:QI 1 "general_operand" "dI")))]
4446   "!TARGET_COLDFIRE"
4448   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 4)
4449     {
4450       operands[2] = GEN_INT (8 - INTVAL (operands[2]));
4451       return "ror%.b %2,%0";
4452     }
4453   else
4454     return "rol%.b %2,%0";
4457 (define_insn "rotrsi3"
4458   [(set (match_operand:SI 0 "register_operand" "=d")
4459         (rotatert:SI (match_operand:SI 1 "register_operand" "0")
4460                      (match_operand:SI 2 "general_operand" "dI")))]
4461   "!TARGET_COLDFIRE"
4462   "ror%.l %2,%0")
4464 (define_insn "rotrhi3"
4465   [(set (match_operand:HI 0 "register_operand" "=d")
4466         (rotatert:HI (match_operand:HI 1 "register_operand" "0")
4467                      (match_operand:HI 2 "general_operand" "dI")))]
4468   "!TARGET_COLDFIRE"
4469   "ror%.w %2,%0")
4471 (define_insn ""
4472   [(set (strict_low_part (match_operand:HI 0 "register_operand" "+d"))
4473         (rotatert:HI (match_dup 0)
4474                      (match_operand:HI 1 "general_operand" "dI")))]
4475   "!TARGET_COLDFIRE"
4476   "ror%.w %1,%0")
4478 (define_insn "rotrqi3"
4479   [(set (match_operand:QI 0 "register_operand" "=d")
4480         (rotatert:QI (match_operand:QI 1 "register_operand" "0")
4481                      (match_operand:QI 2 "general_operand" "dI")))]
4482   "!TARGET_COLDFIRE"
4483   "ror%.b %2,%0")
4485 (define_insn ""
4486   [(set (strict_low_part (match_operand:QI 0 "register_operand" "+d"))
4487         (rotatert:QI (match_dup 0)
4488                      (match_operand:QI 1 "general_operand" "dI")))]
4489   "!TARGET_COLDFIRE"
4490   "ror%.b %1,%0")
4493 ;; Bit set/clear in memory byte.
4495 ;; set bit, bit number is int
4496 (define_insn "bsetmemqi"
4497   [(set (match_operand:QI 0 "memory_operand" "+m")
4498         (ior:QI (subreg:QI (ashift:SI (const_int 1)
4499                 (match_operand:SI 1 "general_operand" "d")) 3)
4500         (match_dup 0)))]
4501   ""
4503   CC_STATUS_INIT;
4504   return "bset %1,%0";
4507 ;; set bit, bit number is (sign/zero)_extended from HImode/QImode
4508 (define_insn ""
4509   [(set (match_operand:QI 0 "memory_operand" "+m")
4510         (ior:QI (subreg:QI (ashift:SI (const_int 1)
4511             (match_operator:SI 2 "extend_operator"
4512                 [(match_operand 1 "general_operand" "d")])) 3)
4513         (match_dup 0)))]
4514   ""
4516   CC_STATUS_INIT;
4517   return "bset %1,%0";
4520 ;; clear bit, bit number is int
4521 (define_insn "bclrmemqi"
4522   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+m")
4523         (const_int 1)
4524         (minus:SI (const_int 7)
4525             (match_operand:SI 1 "general_operand" "d")))
4526     (const_int 0))]
4527   ""
4529   CC_STATUS_INIT;
4530   return "bclr %1,%0";
4533 ;; clear bit, bit number is (sign/zero)_extended from HImode/QImode
4534 (define_insn ""
4535   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+m")
4536         (const_int 1)
4537         (minus:SI (const_int 7)
4538             (match_operator:SI 2 "extend_operator"
4539                 [(match_operand 1 "general_operand" "d")])))
4540     (const_int 0))]
4541   ""
4543   CC_STATUS_INIT;
4544   return "bclr %1,%0";
4547 ;; Special cases of bit-field insns which we should
4548 ;; recognize in preference to the general case.
4549 ;; These handle aligned 8-bit and 16-bit fields,
4550 ;; which can usually be done with move instructions.
4553 ; Special case for 32-bit field in memory.  This only occurs when 32-bit
4554 ; alignment of structure members is specified.
4556 ; The move is allowed to be odd byte aligned, because that's still faster
4557 ; than an odd byte aligned bit-field instruction.
4559 (define_insn ""
4560   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+o")
4561                          (const_int 32)
4562                          (match_operand:SI 1 "const_int_operand" "n"))
4563         (match_operand:SI 2 "general_src_operand" "rmSi"))]
4564   "TARGET_68020 && TARGET_BITFIELD
4565    && (INTVAL (operands[1]) % 8) == 0
4566    && ! mode_dependent_address_p (XEXP (operands[0], 0))"
4568   operands[0]
4569     = adjust_address (operands[0], SImode, INTVAL (operands[1]) / 8);
4571   return "move%.l %2,%0";
4574 (define_insn ""
4575   [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+do")
4576                          (match_operand:SI 1 "const_int_operand" "n")
4577                          (match_operand:SI 2 "const_int_operand" "n"))
4578         (match_operand:SI 3 "register_operand" "d"))]
4579   "TARGET_68020 && TARGET_BITFIELD
4580    && (INTVAL (operands[1]) == 8 || INTVAL (operands[1]) == 16)
4581    && INTVAL (operands[2]) % INTVAL (operands[1]) == 0
4582    && (GET_CODE (operands[0]) == REG
4583        || ! mode_dependent_address_p (XEXP (operands[0], 0)))"
4585   if (REG_P (operands[0]))
4586     {
4587       if (INTVAL (operands[1]) + INTVAL (operands[2]) != 32)
4588         return "bfins %3,%0{%b2:%b1}";
4589     }
4590   else
4591     operands[0] = adjust_address (operands[0],
4592                                   INTVAL (operands[1]) == 8 ? QImode : HImode,
4593                                   INTVAL (operands[2]) / 8);
4595   if (GET_CODE (operands[3]) == MEM)
4596     operands[3] = adjust_address (operands[3],
4597                                   INTVAL (operands[1]) == 8 ? QImode : HImode,
4598                                   (32 - INTVAL (operands[1])) / 8);
4600   if (INTVAL (operands[1]) == 8)
4601     return "move%.b %3,%0";
4602   return "move%.w %3,%0";
4607 ; Special case for 32-bit field in memory.  This only occurs when 32-bit
4608 ; alignment of structure members is specified.
4610 ; The move is allowed to be odd byte aligned, because that's still faster
4611 ; than an odd byte aligned bit-field instruction.
4613 (define_insn ""
4614   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
4615         (zero_extract:SI (match_operand:QI 1 "memory_src_operand" "oS")
4616                          (const_int 32)
4617                          (match_operand:SI 2 "const_int_operand" "n")))]
4618   "TARGET_68020 && TARGET_BITFIELD
4619    && (INTVAL (operands[2]) % 8) == 0
4620    && ! mode_dependent_address_p (XEXP (operands[1], 0))"
4622   operands[1]
4623     = adjust_address (operands[1], SImode, INTVAL (operands[2]) / 8);
4625   return "move%.l %1,%0";
4628 (define_insn ""
4629   [(set (match_operand:SI 0 "nonimmediate_operand" "=&d")
4630         (zero_extract:SI (match_operand:SI 1 "register_operand" "do")
4631                          (match_operand:SI 2 "const_int_operand" "n")
4632                          (match_operand:SI 3 "const_int_operand" "n")))]
4633   "TARGET_68020 && TARGET_BITFIELD
4634    && (INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 16)
4635    && INTVAL (operands[3]) % INTVAL (operands[2]) == 0
4636    && (GET_CODE (operands[1]) == REG
4637        || ! mode_dependent_address_p (XEXP (operands[1], 0)))"
4639   cc_status.flags |= CC_NOT_NEGATIVE;
4640   if (REG_P (operands[1]))
4641     {
4642       if (INTVAL (operands[2]) + INTVAL (operands[3]) != 32)
4643         return "bfextu %1{%b3:%b2},%0";
4644     }
4645   else
4646     operands[1]
4647       = adjust_address (operands[1], SImode, INTVAL (operands[3]) / 8);
4649   output_asm_insn ("clr%.l %0", operands);
4650   if (GET_CODE (operands[0]) == MEM)
4651     operands[0] = adjust_address (operands[0],
4652                                   INTVAL (operands[2]) == 8 ? QImode : HImode,
4653                                   (32 - INTVAL (operands[1])) / 8);
4655   if (INTVAL (operands[2]) == 8)
4656     return "move%.b %1,%0";
4657   return "move%.w %1,%0";
4661 ; Special case for 32-bit field in memory.  This only occurs when 32-bit
4662 ; alignment of structure members is specified.
4664 ; The move is allowed to be odd byte aligned, because that's still faster
4665 ; than an odd byte aligned bit-field instruction.
4667 (define_insn ""
4668   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
4669         (sign_extract:SI (match_operand:QI 1 "memory_src_operand" "oS")
4670                          (const_int 32)
4671                          (match_operand:SI 2 "const_int_operand" "n")))]
4672   "TARGET_68020 && TARGET_BITFIELD
4673    && (INTVAL (operands[2]) % 8) == 0
4674    && ! mode_dependent_address_p (XEXP (operands[1], 0))"
4676   operands[1]
4677     = adjust_address (operands[1], SImode, INTVAL (operands[2]) / 8);
4679   return "move%.l %1,%0";
4682 (define_insn ""
4683   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
4684         (sign_extract:SI (match_operand:SI 1 "register_operand" "do")
4685                          (match_operand:SI 2 "const_int_operand" "n")
4686                          (match_operand:SI 3 "const_int_operand" "n")))]
4687   "TARGET_68020 && TARGET_BITFIELD
4688    && (INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 16)
4689    && INTVAL (operands[3]) % INTVAL (operands[2]) == 0
4690    && (GET_CODE (operands[1]) == REG
4691        || ! mode_dependent_address_p (XEXP (operands[1], 0)))"
4693   if (REG_P (operands[1]))
4694     {
4695       if (INTVAL (operands[2]) + INTVAL (operands[3]) != 32)
4696         return "bfexts %1{%b3:%b2},%0";
4697     }
4698   else
4699     operands[1]
4700       = adjust_address (operands[1],
4701                         INTVAL (operands[2]) == 8 ? QImode : HImode,
4702                         INTVAL (operands[3]) / 8);
4704   if (INTVAL (operands[2]) == 8)
4705     return "move%.b %1,%0\;extb%.l %0";
4706   return "move%.w %1,%0\;ext%.l %0";
4709 ;; Bit-field instructions, general cases.
4710 ;; "o,d" constraint causes a nonoffsettable memref to match the "o"
4711 ;; so that its address is reloaded.
4713 (define_expand "extv"
4714   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4715         (sign_extract:SI (match_operand:SI 1 "general_operand" "")
4716                          (match_operand:SI 2 "general_operand" "")
4717                          (match_operand:SI 3 "general_operand" "")))]
4718   "TARGET_68020 && TARGET_BITFIELD"
4719   "")
4721 (define_insn ""
4722   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
4723         (sign_extract:SI (match_operand:QI 1 "memory_operand" "o")
4724                          (match_operand:SI 2 "general_operand" "dn")
4725                          (match_operand:SI 3 "general_operand" "dn")))]
4726   "TARGET_68020 && TARGET_BITFIELD"
4727   "bfexts %1{%b3:%b2},%0")
4729 (define_expand "extzv"
4730   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4731         (zero_extract:SI (match_operand:SI 1 "general_operand" "")
4732                          (match_operand:SI 2 "general_operand" "")
4733                          (match_operand:SI 3 "general_operand" "")))]
4734   "TARGET_68020 && TARGET_BITFIELD"
4735   "")
4737 (define_insn ""
4738   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d")
4739         (zero_extract:SI (match_operand:QI 1 "memory_operand" "o,d")
4740                          (match_operand:SI 2 "general_operand" "dn,dn")
4741                          (match_operand:SI 3 "general_operand" "dn,dn")))]
4742   "TARGET_68020 && TARGET_BITFIELD"
4744   if (GET_CODE (operands[2]) == CONST_INT)
4745     {
4746       if (INTVAL (operands[2]) != 32)
4747         cc_status.flags |= CC_NOT_NEGATIVE;
4748     }
4749   else
4750     {
4751       CC_STATUS_INIT;
4752     }
4753   return "bfextu %1{%b3:%b2},%0";
4756 (define_insn ""
4757   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+o")
4758                          (match_operand:SI 1 "general_operand" "dn")
4759                          (match_operand:SI 2 "general_operand" "dn"))
4760         (xor:SI (zero_extract:SI (match_dup 0) (match_dup 1) (match_dup 2))
4761                 (match_operand 3 "const_int_operand" "n")))]
4762   "TARGET_68020 && TARGET_BITFIELD
4763    && (INTVAL (operands[3]) == -1
4764        || (GET_CODE (operands[1]) == CONST_INT
4765            && (~ INTVAL (operands[3]) & ((1 << INTVAL (operands[1]))- 1)) == 0))"
4767   CC_STATUS_INIT;
4768   return "bfchg %0{%b2:%b1}";
4771 (define_insn ""
4772   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+o")
4773                          (match_operand:SI 1 "general_operand" "dn")
4774                          (match_operand:SI 2 "general_operand" "dn"))
4775         (const_int 0))]
4776   "TARGET_68020 && TARGET_BITFIELD"
4778   CC_STATUS_INIT;
4779   return "bfclr %0{%b2:%b1}";
4782 (define_insn ""
4783   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+o")
4784                          (match_operand:SI 1 "general_operand" "dn")
4785                          (match_operand:SI 2 "general_operand" "dn"))
4786         (const_int -1))]
4787   "TARGET_68020 && TARGET_BITFIELD"
4789   CC_STATUS_INIT;
4790   return "bfset %0{%b2:%b1}";
4793 (define_expand "insv"
4794   [(set (zero_extract:SI (match_operand:SI 0 "nonimmediate_operand" "")
4795                          (match_operand:SI 1 "general_operand" "")
4796                          (match_operand:SI 2 "general_operand" ""))
4797         (match_operand:SI 3 "register_operand" ""))]
4798   "TARGET_68020 && TARGET_BITFIELD"
4799   "")
4801 (define_insn ""
4802   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "+o")
4803                          (match_operand:SI 1 "general_operand" "dn")
4804                          (match_operand:SI 2 "general_operand" "dn"))
4805         (match_operand:SI 3 "register_operand" "d"))]
4806   "TARGET_68020 && TARGET_BITFIELD"
4807   "bfins %3,%0{%b2:%b1}")
4809 ;; Now recognize bit-field insns that operate on registers
4810 ;; (or at least were intended to do so).
4812 (define_insn ""
4813   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
4814         (sign_extract:SI (match_operand:SI 1 "register_operand" "d")
4815                          (match_operand:SI 2 "general_operand" "dn")
4816                          (match_operand:SI 3 "general_operand" "dn")))]
4817   "TARGET_68020 && TARGET_BITFIELD"
4818   "bfexts %1{%b3:%b2},%0")
4820 (define_insn ""
4821   [(set (match_operand:SI 0 "nonimmediate_operand" "=d")
4822         (zero_extract:SI (match_operand:SI 1 "register_operand" "d")
4823                          (match_operand:SI 2 "general_operand" "dn")
4824                          (match_operand:SI 3 "general_operand" "dn")))]
4825   "TARGET_68020 && TARGET_BITFIELD"
4827   if (GET_CODE (operands[2]) == CONST_INT)
4828     {
4829       if (INTVAL (operands[2]) != 32)
4830         cc_status.flags |= CC_NOT_NEGATIVE;
4831     }
4832   else
4833     {
4834       CC_STATUS_INIT;
4835     }
4836   return "bfextu %1{%b3:%b2},%0";
4839 (define_insn ""
4840   [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+d")
4841                          (match_operand:SI 1 "general_operand" "dn")
4842                          (match_operand:SI 2 "general_operand" "dn"))
4843         (const_int 0))]
4844   "TARGET_68020 && TARGET_BITFIELD"
4846   CC_STATUS_INIT;
4847   return "bfclr %0{%b2:%b1}";
4850 (define_insn ""
4851   [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+d")
4852                          (match_operand:SI 1 "general_operand" "dn")
4853                          (match_operand:SI 2 "general_operand" "dn"))
4854         (const_int -1))]
4855   "TARGET_68020 && TARGET_BITFIELD"
4857   CC_STATUS_INIT;
4858   return "bfset %0{%b2:%b1}";
4861 (define_insn ""
4862   [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+d")
4863                          (match_operand:SI 1 "general_operand" "dn")
4864                          (match_operand:SI 2 "general_operand" "dn"))
4865         (match_operand:SI 3 "register_operand" "d"))]
4866   "TARGET_68020 && TARGET_BITFIELD"
4868 #if 0
4869   /* These special cases are now recognized by a specific pattern.  */
4870   if (GET_CODE (operands[1]) == CONST_INT && GET_CODE (operands[2]) == CONST_INT
4871       && INTVAL (operands[1]) == 16 && INTVAL (operands[2]) == 16)
4872     return "move%.w %3,%0";
4873   if (GET_CODE (operands[1]) == CONST_INT && GET_CODE (operands[2]) == CONST_INT
4874       && INTVAL (operands[1]) == 24 && INTVAL (operands[2]) == 8)
4875     return "move%.b %3,%0";
4876 #endif
4877   return "bfins %3,%0{%b2:%b1}";
4880 ;; Special patterns for optimizing bit-field instructions.
4882 (define_insn ""
4883   [(set (cc0)
4884         (zero_extract:SI (match_operand:QI 0 "memory_operand" "o")
4885                          (match_operand:SI 1 "const_int_operand" "n")
4886                          (match_operand:SI 2 "general_operand" "dn")))]
4887   "TARGET_68020 && TARGET_BITFIELD"
4889   if (operands[1] == const1_rtx
4890       && GET_CODE (operands[2]) == CONST_INT)
4891     {
4892       int width = GET_CODE (operands[0]) == REG ? 31 : 7;
4893       return output_btst (operands,
4894                           GEN_INT (width - INTVAL (operands[2])),
4895                           operands[0], insn, 1000);
4896       /* Pass 1000 as SIGNPOS argument so that btst will
4897          not think we are testing the sign bit for an `and'
4898          and assume that nonzero implies a negative result.  */
4899     }
4900   if (INTVAL (operands[1]) != 32)
4901     cc_status.flags = CC_NOT_NEGATIVE;
4902   return "bftst %0{%b2:%b1}";
4906 ;;; now handle the register cases
4907 (define_insn ""
4908   [(set (cc0)
4909         (zero_extract:SI (match_operand:SI 0 "register_operand" "d")
4910                          (match_operand:SI 1 "const_int_operand" "n")
4911                          (match_operand:SI 2 "general_operand" "dn")))]
4912   "TARGET_68020 && TARGET_BITFIELD"
4914   if (operands[1] == const1_rtx
4915       && GET_CODE (operands[2]) == CONST_INT)
4916     {
4917       int width = GET_CODE (operands[0]) == REG ? 31 : 7;
4918       return output_btst (operands, GEN_INT (width - INTVAL (operands[2])),
4919                           operands[0], insn, 1000);
4920       /* Pass 1000 as SIGNPOS argument so that btst will
4921          not think we are testing the sign bit for an `and'
4922          and assume that nonzero implies a negative result.  */
4923     }
4924   if (INTVAL (operands[1]) != 32)
4925     cc_status.flags = CC_NOT_NEGATIVE;
4926   return "bftst %0{%b2:%b1}";
4929 (define_insn "scc0_di"
4930   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
4931     (match_operator 1 "valid_dbcc_comparison_p"
4932       [(match_operand:DI 2 "general_operand" "ro") (const_int 0)]))]
4933   "! TARGET_COLDFIRE"
4935   return output_scc_di (operands[1], operands[2], const0_rtx, operands[0]);
4938 (define_insn "scc0_di_5200"
4939   [(set (match_operand:QI 0 "nonimmediate_operand" "=d")
4940     (match_operator 1 "valid_dbcc_comparison_p"
4941       [(match_operand:DI 2 "general_operand" "ro") (const_int 0)]))]
4942   "TARGET_COLDFIRE"
4944   return output_scc_di (operands[1], operands[2], const0_rtx, operands[0]);
4947 (define_insn "scc_di"
4948   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm,dm")
4949     (match_operator 1 "valid_dbcc_comparison_p"
4950       [(match_operand:DI 2 "general_operand" "ro,r")
4951        (match_operand:DI 3 "general_operand" "r,ro")]))]
4952   "! TARGET_COLDFIRE"
4954   return output_scc_di (operands[1], operands[2], operands[3], operands[0]);
4957 (define_insn "scc_di_5200"
4958   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d")
4959     (match_operator 1 "valid_dbcc_comparison_p"
4960       [(match_operand:DI 2 "general_operand" "ro,r")
4961        (match_operand:DI 3 "general_operand" "r,ro")]))]
4962   "TARGET_COLDFIRE"
4964   return output_scc_di (operands[1], operands[2], operands[3], operands[0]);
4967 ;; Note that operand 0 of an SCC insn is supported in the hardware as
4968 ;; memory, but we cannot allow it to be in memory in case the address
4969 ;; needs to be reloaded.
4971 (define_expand "seq"
4972   [(set (match_operand:QI 0 "register_operand" "")
4973         (eq:QI (cc0) (const_int 0)))]
4974   ""
4976   if (TARGET_68060 && m68k_last_compare_had_fp_operands)
4977     {
4978       m68k_last_compare_had_fp_operands = 0;
4979       FAIL;
4980     }
4983 (define_insn ""
4984   [(set (match_operand:QI 0 "register_operand" "=d")
4985         (eq:QI (cc0) (const_int 0)))]
4986   ""
4988   cc_status = cc_prev_status;
4989   OUTPUT_JUMP ("seq %0", "fseq %0", "seq %0");
4992 (define_expand "sne"
4993   [(set (match_operand:QI 0 "register_operand" "")
4994         (ne:QI (cc0) (const_int 0)))]
4995   ""
4997   if (TARGET_68060 && m68k_last_compare_had_fp_operands)
4998     {
4999       m68k_last_compare_had_fp_operands = 0;
5000       FAIL;
5001     }
5004 (define_insn ""
5005   [(set (match_operand:QI 0 "register_operand" "=d")
5006         (ne:QI (cc0) (const_int 0)))]
5007   ""
5009   cc_status = cc_prev_status;
5010   OUTPUT_JUMP ("sne %0", "fsne %0", "sne %0");
5013 (define_expand "sgt"
5014   [(set (match_operand:QI 0 "register_operand" "")
5015         (gt:QI (cc0) (const_int 0)))]
5016   ""
5018   if (TARGET_68060 && m68k_last_compare_had_fp_operands)
5019     {
5020       m68k_last_compare_had_fp_operands = 0;
5021       FAIL;
5022     }
5025 (define_insn ""
5026   [(set (match_operand:QI 0 "register_operand" "=d")
5027         (gt:QI (cc0) (const_int 0)))]
5028   ""
5030   cc_status = cc_prev_status;
5031   OUTPUT_JUMP ("sgt %0", "fsgt %0", 0);
5034 (define_expand "sgtu"
5035   [(set (match_operand:QI 0 "register_operand" "")
5036         (gtu:QI (cc0) (const_int 0)))]
5037   ""
5038   "")
5040 (define_insn ""
5041   [(set (match_operand:QI 0 "register_operand" "=d")
5042         (gtu:QI (cc0) (const_int 0)))]
5043   ""
5045   cc_status = cc_prev_status;
5046   return "shi %0";
5049 (define_expand "slt"
5050   [(set (match_operand:QI 0 "register_operand" "")
5051         (lt:QI (cc0) (const_int 0)))]
5052   ""
5054   if (TARGET_68060 && m68k_last_compare_had_fp_operands)
5055     {
5056       m68k_last_compare_had_fp_operands = 0;
5057       FAIL;
5058     }
5061 (define_insn ""
5062   [(set (match_operand:QI 0 "register_operand" "=d")
5063         (lt:QI (cc0) (const_int 0)))]
5064   ""
5066    cc_status = cc_prev_status;
5067    OUTPUT_JUMP ("slt %0", "fslt %0", "smi %0");
5070 (define_expand "sltu"
5071   [(set (match_operand:QI 0 "register_operand" "")
5072         (ltu:QI (cc0) (const_int 0)))]
5073   ""
5074   "")
5076 (define_insn ""
5077   [(set (match_operand:QI 0 "register_operand" "=d")
5078         (ltu:QI (cc0) (const_int 0)))]
5079   ""
5081    cc_status = cc_prev_status;
5082    return "scs %0";
5085 (define_expand "sge"
5086   [(set (match_operand:QI 0 "register_operand" "")
5087         (ge:QI (cc0) (const_int 0)))]
5088   ""
5090   if (TARGET_68060 && m68k_last_compare_had_fp_operands)
5091     {
5092       m68k_last_compare_had_fp_operands = 0;
5093       FAIL;
5094     }
5097 (define_insn ""
5098   [(set (match_operand:QI 0 "register_operand" "=d")
5099         (ge:QI (cc0) (const_int 0)))]
5100   ""
5102    cc_status = cc_prev_status;
5103    OUTPUT_JUMP ("sge %0", "fsge %0", "spl %0");
5106 (define_expand "sgeu"
5107   [(set (match_operand:QI 0 "register_operand" "")
5108         (geu:QI (cc0) (const_int 0)))]
5109   ""
5110   "")
5112 (define_insn ""
5113   [(set (match_operand:QI 0 "register_operand" "=d")
5114         (geu:QI (cc0) (const_int 0)))]
5115   ""
5117    cc_status = cc_prev_status;
5118    return "scc %0";
5121 (define_expand "sle"
5122   [(set (match_operand:QI 0 "register_operand" "")
5123         (le:QI (cc0) (const_int 0)))]
5124   ""
5126   if (TARGET_68060 && m68k_last_compare_had_fp_operands)
5127     {
5128       m68k_last_compare_had_fp_operands = 0;
5129       FAIL;
5130     }
5133 (define_insn ""
5134   [(set (match_operand:QI 0 "register_operand" "=d")
5135         (le:QI (cc0) (const_int 0)))]
5136   ""
5138   cc_status = cc_prev_status;
5139   OUTPUT_JUMP ("sle %0", "fsle %0", 0);
5142 (define_expand "sleu"
5143   [(set (match_operand:QI 0 "register_operand" "")
5144         (leu:QI (cc0) (const_int 0)))]
5145   ""
5146   "")
5148 (define_insn ""
5149   [(set (match_operand:QI 0 "register_operand" "=d")
5150         (leu:QI (cc0) (const_int 0)))]
5151   ""
5153    cc_status = cc_prev_status;
5154    return "sls %0";
5157 (define_expand "sordered"
5158   [(set (match_operand:QI 0 "register_operand" "")
5159         (ordered:QI (cc0) (const_int 0)))]
5160   "TARGET_68881 && !TARGET_68060"
5162   gcc_assert (m68k_last_compare_had_fp_operands);
5163   m68k_last_compare_had_fp_operands = 0;
5166 (define_insn "*sordered_1"
5167   [(set (match_operand:QI 0 "register_operand" "=d")
5168         (ordered:QI (cc0) (const_int 0)))]
5169   "TARGET_68881 && !TARGET_68060"
5171   cc_status = cc_prev_status;
5172   return "fsor %0";
5175 (define_expand "sunordered"
5176   [(set (match_operand:QI 0 "register_operand" "")
5177         (unordered:QI (cc0) (const_int 0)))]
5178   "TARGET_68881 && !TARGET_68060"
5180   gcc_assert (m68k_last_compare_had_fp_operands);
5181   m68k_last_compare_had_fp_operands = 0;
5184 (define_insn "*sunordered_1"
5185   [(set (match_operand:QI 0 "register_operand" "=d")
5186         (unordered:QI (cc0) (const_int 0)))]
5187   "TARGET_68881 && !TARGET_68060"
5189   cc_status = cc_prev_status;
5190   return "fsun %0";
5193 (define_expand "suneq"
5194   [(set (match_operand:QI 0 "register_operand" "")
5195         (uneq:QI (cc0) (const_int 0)))]
5196   "TARGET_68881 && !TARGET_68060"
5198   gcc_assert (m68k_last_compare_had_fp_operands);
5199   m68k_last_compare_had_fp_operands = 0;
5202 (define_insn "*suneq_1"
5203   [(set (match_operand:QI 0 "register_operand" "=d")
5204         (uneq:QI (cc0) (const_int 0)))]
5205   "TARGET_68881 && !TARGET_68060"
5207   cc_status = cc_prev_status;
5208   return "fsueq %0";
5211 (define_expand "sunge"
5212   [(set (match_operand:QI 0 "register_operand" "")
5213         (unge:QI (cc0) (const_int 0)))]
5214   "TARGET_68881 && !TARGET_68060"
5216   gcc_assert (m68k_last_compare_had_fp_operands);
5217   m68k_last_compare_had_fp_operands = 0;
5220 (define_insn "*sunge_1"
5221   [(set (match_operand:QI 0 "register_operand" "=d")
5222         (unge:QI (cc0) (const_int 0)))]
5223   "TARGET_68881 && !TARGET_68060"
5225   cc_status = cc_prev_status;
5226   return "fsuge %0";
5229 (define_expand "sungt"
5230   [(set (match_operand:QI 0 "register_operand" "")
5231         (ungt:QI (cc0) (const_int 0)))]
5232   "TARGET_68881 && !TARGET_68060"
5234   gcc_assert (m68k_last_compare_had_fp_operands);
5235   m68k_last_compare_had_fp_operands = 0;
5238 (define_insn "*sungt_1"
5239   [(set (match_operand:QI 0 "register_operand" "=d")
5240         (ungt:QI (cc0) (const_int 0)))]
5241   "TARGET_68881 && !TARGET_68060"
5243   cc_status = cc_prev_status;
5244   return "fsugt %0";
5247 (define_expand "sunle"
5248   [(set (match_operand:QI 0 "register_operand" "")
5249         (unle:QI (cc0) (const_int 0)))]
5250   "TARGET_68881 && !TARGET_68060"
5252   gcc_assert (m68k_last_compare_had_fp_operands);
5253   m68k_last_compare_had_fp_operands = 0;
5256 (define_insn "*sunle_1"
5257   [(set (match_operand:QI 0 "register_operand" "=d")
5258         (unle:QI (cc0) (const_int 0)))]
5259   "TARGET_68881 && !TARGET_68060"
5261   cc_status = cc_prev_status;
5262   return "fsule %0";
5265 (define_expand "sunlt"
5266   [(set (match_operand:QI 0 "register_operand" "")
5267         (unlt:QI (cc0) (const_int 0)))]
5268   "TARGET_68881 && !TARGET_68060"
5270   gcc_assert (m68k_last_compare_had_fp_operands);
5271   m68k_last_compare_had_fp_operands = 0;
5274 (define_insn "*sunlt_1"
5275   [(set (match_operand:QI 0 "register_operand" "=d")
5276         (unlt:QI (cc0) (const_int 0)))]
5277   "TARGET_68881 && !TARGET_68060"
5279   cc_status = cc_prev_status;
5280   return "fsult %0";
5283 (define_expand "sltgt"
5284   [(set (match_operand:QI 0 "register_operand" "")
5285         (ltgt:QI (cc0) (const_int 0)))]
5286   "TARGET_68881 && !TARGET_68060"
5288   gcc_assert (m68k_last_compare_had_fp_operands);
5289   m68k_last_compare_had_fp_operands = 0;
5292 (define_insn "*sltgt_1"
5293   [(set (match_operand:QI 0 "register_operand" "=d")
5294         (ltgt:QI (cc0) (const_int 0)))]
5295   "TARGET_68881 && !TARGET_68060"
5297   cc_status = cc_prev_status;
5298   return "fsogl %0";
5301 (define_insn "*fsogt_1"
5302   [(set (match_operand:QI 0 "register_operand" "=d")
5303         (not:QI (unle:QI (cc0) (const_int 0))))]
5304   "TARGET_68881 && !TARGET_68060"
5306   cc_status = cc_prev_status;
5307   return "fsogt %0";
5310 (define_insn "*fsoge_1"
5311   [(set (match_operand:QI 0 "register_operand" "=d")
5312         (not:QI (unlt:QI (cc0) (const_int 0))))]
5313   "TARGET_68881 && !TARGET_68060"
5315   cc_status = cc_prev_status;
5316   return "fsoge %0";
5319 (define_insn "*fsolt_1"
5320   [(set (match_operand:QI 0 "register_operand" "=d")
5321         (not:QI (unge:QI (cc0) (const_int 0))))]
5322   "TARGET_68881 && !TARGET_68060"
5324   cc_status = cc_prev_status;
5325   return "fsolt %0";
5328 (define_insn "*fsole_1"
5329   [(set (match_operand:QI 0 "register_operand" "=d")
5330         (not:QI (ungt:QI (cc0) (const_int 0))))]
5331   "TARGET_68881 && !TARGET_68060"
5333   cc_status = cc_prev_status;
5334   return "fsole %0";
5337 ;; Basic conditional jump instructions.
5339 (define_insn "beq0_di"
5340   [(set (pc)
5341     (if_then_else (eq (match_operand:DI 0 "general_operand" "d*ao,<>")
5342             (const_int 0))
5343         (label_ref (match_operand 1 "" ","))
5344         (pc)))
5345    (clobber (match_scratch:SI 2 "=d,d"))]
5346   ""
5348   CC_STATUS_INIT;
5349   if (which_alternative == 1)
5350     {
5351       if (MOTOROLA)
5352         return "move%.l %0,%2\;or%.l %0,%2\;jbeq %l1";
5353       else
5354         return "move%.l %0,%2\;or%.l %0,%2\;jeq %l1";
5355     }
5356   if ((cc_prev_status.value1
5357       && rtx_equal_p (cc_prev_status.value1, operands[0]))
5358     || (cc_prev_status.value2
5359       && rtx_equal_p (cc_prev_status.value2, operands[0])))
5360     {
5361       cc_status = cc_prev_status;
5362       return MOTOROLA ? "jbeq %l1" : "jeq %l1";
5363     }
5364   if (GET_CODE (operands[0]) == REG)
5365     operands[3] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
5366   else
5367     operands[3] = adjust_address (operands[0], SImode, 4);
5368   if (! ADDRESS_REG_P (operands[0]))
5369     {
5370       if (reg_overlap_mentioned_p (operands[2], operands[0]))
5371         {
5372           if (reg_overlap_mentioned_p (operands[2], operands[3]))
5373             {
5374               if (MOTOROLA)
5375                 return "or%.l %0,%2\;jbeq %l1";
5376               else
5377                 return "or%.l %0,%2\;jeq %l1";
5378             }
5379           else
5380             {
5381               if (MOTOROLA)
5382                 return "or%.l %3,%2\;jbeq %l1";
5383               else
5384                 return "or%.l %3,%2\;jeq %l1";
5385             }
5386         }
5387       if (MOTOROLA)
5388         return "move%.l %0,%2\;or%.l %3,%2\;jbeq %l1";
5389       else
5390         return "move%.l %0,%2\;or%.l %3,%2\;jeq %l1";
5391     }
5392   operands[4] = gen_label_rtx();
5393   if (TARGET_68020 || TARGET_COLDFIRE)
5394     {
5395       if (MOTOROLA)
5396         output_asm_insn ("tst%.l %0\;jbne %l4\;tst%.l %3\;jbeq %l1", operands);
5397       else
5398         output_asm_insn ("tst%.l %0\;jne %l4\;tst%.l %3\;jeq %l1", operands);
5399     }
5400   else
5401     {
5402       if (MOTOROLA)
5403         output_asm_insn ("cmp%.w #0,%0\;jbne %l4\;cmp%.w #0,%3\;jbeq %l1", operands);
5404       else
5405         output_asm_insn ("cmp%.w #0,%0\;jne %l4\;cmp%.w #0,%3\;jeq %l1", operands);
5406     }
5407   (*targetm.asm_out.internal_label) (asm_out_file, "L",
5408                                 CODE_LABEL_NUMBER (operands[4]));
5409   return "";
5412 (define_insn "bne0_di"
5413   [(set (pc)
5414     (if_then_else (ne (match_operand:DI 0 "general_operand" "do,*a")
5415             (const_int 0))
5416         (label_ref (match_operand 1 "" ","))
5417         (pc)))
5418    (clobber (match_scratch:SI 2 "=d,X"))]
5419   ""
5421   if ((cc_prev_status.value1
5422       && rtx_equal_p (cc_prev_status.value1, operands[0]))
5423     || (cc_prev_status.value2
5424       && rtx_equal_p (cc_prev_status.value2, operands[0])))
5425     {
5426       cc_status = cc_prev_status;
5427       return MOTOROLA ? "jbne %l1" : "jne %l1";
5428     }
5429   CC_STATUS_INIT;
5430   if (GET_CODE (operands[0]) == REG)
5431     operands[3] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
5432   else
5433     operands[3] = adjust_address (operands[0], SImode, 4);
5434   if (!ADDRESS_REG_P (operands[0]))
5435     {
5436       if (reg_overlap_mentioned_p (operands[2], operands[0]))
5437         {
5438           if (reg_overlap_mentioned_p (operands[2], operands[3]))
5439             {
5440               if (MOTOROLA)
5441                 return "or%.l %0,%2\;jbne %l1";
5442               else
5443                 return "or%.l %0,%2\;jne %l1";
5444             }
5445           else
5446             {
5447               if (MOTOROLA)
5448                 return "or%.l %3,%2\;jbne %l1";
5449               else
5450                 return "or%.l %3,%2\;jne %l1";
5451             }
5452         }
5453       if (MOTOROLA)
5454         return "move%.l %0,%2\;or%.l %3,%2\;jbne %l1";
5455       else
5456         return "move%.l %0,%2\;or%.l %3,%2\;jne %l1";
5457     }
5458   if (TARGET_68020 || TARGET_COLDFIRE)
5459     {
5460       if (MOTOROLA)
5461         return "tst%.l %0\;jbne %l1\;tst%.l %3\;jbne %l1";
5462       else
5463         return "tst%.l %0\;jne %l1\;tst%.l %3\;jne %l1";
5464     }
5465   else
5466     {
5467       if (MOTOROLA)
5468         return "cmp%.w #0,%0\;jbne %l1\;cmp%.w #0,%3\;jbne %l1";
5469       else
5470         return "cmp%.w #0,%0\;jne %l1\;cmp%.w #0,%3\;jne %l1";
5471     }
5474 (define_insn "bge0_di"
5475   [(set (pc)
5476     (if_then_else (ge (match_operand:DI 0 "general_operand" "ro")
5477             (const_int 0))
5478         (label_ref (match_operand 1 "" ""))
5479         (pc)))]
5480   ""
5482   if ((cc_prev_status.value1
5483       && rtx_equal_p (cc_prev_status.value1, operands[0]))
5484     || (cc_prev_status.value2
5485       && rtx_equal_p (cc_prev_status.value2, operands[0])))
5486     {
5487       cc_status = cc_prev_status;
5488       if (cc_status.flags & CC_REVERSED)
5489         {
5490           return MOTOROLA ? "jble %l1" : "jle %l1";
5491         }
5492       else
5493         {
5494           return MOTOROLA ? "jbpl %l1" : "jpl %l1";
5495         }
5496     }
5497   CC_STATUS_INIT;
5498   if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (operands[0]))
5499     output_asm_insn("tst%.l %0", operands);
5500   else
5501     {
5502       /* On an address reg, cmpw may replace cmpl.  */
5503       output_asm_insn("cmp%.w #0,%0", operands);
5504     }
5505   return MOTOROLA ? "jbpl %l1" : "jpl %l1";
5508 (define_insn "blt0_di"
5509   [(set (pc)
5510     (if_then_else (lt (match_operand:DI 0 "general_operand" "ro")
5511             (const_int 0))
5512         (label_ref (match_operand 1 "" ""))
5513         (pc)))]
5514   ""
5516   if ((cc_prev_status.value1
5517       && rtx_equal_p (cc_prev_status.value1, operands[0]))
5518     || (cc_prev_status.value2
5519       && rtx_equal_p (cc_prev_status.value2, operands[0])))
5520     {
5521       cc_status = cc_prev_status;
5522       if (cc_status.flags & CC_REVERSED)
5523         {
5524           return MOTOROLA ? "jbgt %l1" : "jgt %l1";
5525         }
5526       else
5527         {
5528           return MOTOROLA ? "jbmi %l1" : "jmi %l1";
5529         }
5530     }
5531   CC_STATUS_INIT;
5532   if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (operands[0]))
5533     output_asm_insn("tst%.l %0", operands);
5534   else
5535     {
5536       /* On an address reg, cmpw may replace cmpl.  */
5537       output_asm_insn("cmp%.w #0,%0", operands);
5538     }
5540   return MOTOROLA ? "jbmi %l1" : "jmi %l1";
5543 (define_insn "beq"
5544   [(set (pc)
5545         (if_then_else (eq (cc0)
5546                           (const_int 0))
5547                       (label_ref (match_operand 0 "" ""))
5548                       (pc)))]
5549   ""
5551   if (MOTOROLA)
5552     OUTPUT_JUMP ("jbeq %l0", "fbeq %l0", "jbeq %l0");
5553   else
5554     OUTPUT_JUMP ("jeq %l0", "fjeq %l0", "jeq %l0");
5557 (define_insn "bne"
5558   [(set (pc)
5559         (if_then_else (ne (cc0)
5560                           (const_int 0))
5561                       (label_ref (match_operand 0 "" ""))
5562                       (pc)))]
5563   ""
5565   if (MOTOROLA)
5566     OUTPUT_JUMP ("jbne %l0", "fbne %l0", "jbne %l0");
5567   else
5568     OUTPUT_JUMP ("jne %l0", "fjne %l0", "jne %l0");
5571 (define_insn "bgt"
5572   [(set (pc)
5573         (if_then_else (gt (cc0)
5574                           (const_int 0))
5575                       (label_ref (match_operand 0 "" ""))
5576                       (pc)))]
5577   ""
5579   if (MOTOROLA)
5580     OUTPUT_JUMP ("jbgt %l0", "fbgt %l0", 0);
5581   else
5582     OUTPUT_JUMP ("jgt %l0", "fjgt %l0", 0);
5585 (define_insn "bgtu"
5586   [(set (pc)
5587         (if_then_else (gtu (cc0)
5588                            (const_int 0))
5589                       (label_ref (match_operand 0 "" ""))
5590                       (pc)))]
5591   ""
5593   return MOTOROLA ? "jbhi %l0" : "jhi %l0";
5596 (define_insn "blt"
5597   [(set (pc)
5598         (if_then_else (lt (cc0)
5599                           (const_int 0))
5600                       (label_ref (match_operand 0 "" ""))
5601                       (pc)))]
5602   ""
5604   if (MOTOROLA)
5605     OUTPUT_JUMP ("jblt %l0", "fblt %l0", "jbmi %l0");
5606   else
5607     OUTPUT_JUMP ("jlt %l0", "fjlt %l0", "jmi %l0");
5610 (define_insn "bltu"
5611   [(set (pc)
5612         (if_then_else (ltu (cc0)
5613                            (const_int 0))
5614                       (label_ref (match_operand 0 "" ""))
5615                       (pc)))]
5616   ""
5618   return MOTOROLA ? "jbcs %l0" : "jcs %l0";
5621 (define_insn "bge"
5622   [(set (pc)
5623         (if_then_else (ge (cc0)
5624                           (const_int 0))
5625                       (label_ref (match_operand 0 "" ""))
5626                       (pc)))]
5627   ""
5629   if (MOTOROLA)
5630     OUTPUT_JUMP ("jbge %l0", "fbge %l0", "jbpl %l0");
5631   else
5632     OUTPUT_JUMP ("jge %l0", "fjge %l0", "jpl %l0");
5635 (define_insn "bgeu"
5636   [(set (pc)
5637         (if_then_else (geu (cc0)
5638                            (const_int 0))
5639                       (label_ref (match_operand 0 "" ""))
5640                       (pc)))]
5641   ""
5643   return MOTOROLA ? "jbcc %l0" : "jcc %l0";
5646 (define_insn "ble"
5647   [(set (pc)
5648         (if_then_else (le (cc0)
5649                           (const_int 0))
5650                       (label_ref (match_operand 0 "" ""))
5651                       (pc)))]
5652   ""
5654   if (MOTOROLA)
5655     OUTPUT_JUMP ("jble %l0", "fble %l0", 0);
5656   else
5657     OUTPUT_JUMP ("jle %l0", "fjle %l0", 0);
5660 (define_insn "bleu"
5661   [(set (pc)
5662         (if_then_else (leu (cc0)
5663                            (const_int 0))
5664                       (label_ref (match_operand 0 "" ""))
5665                       (pc)))]
5666   ""
5668   return MOTOROLA ? "jbls %l0" : "jls %l0";
5671 (define_insn "bordered"
5672   [(set (pc)
5673         (if_then_else (ordered (cc0) (const_int 0))
5674                       (label_ref (match_operand 0 "" ""))
5675                       (pc)))]
5676   "TARGET_68881"
5678   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5679   return MOTOROLA ? "fbor %l0" : "fjor %l0";
5682 (define_insn "bunordered"
5683   [(set (pc)
5684         (if_then_else (unordered (cc0) (const_int 0))
5685                       (label_ref (match_operand 0 "" ""))
5686                       (pc)))]
5687   "TARGET_68881"
5689   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5690   return MOTOROLA ? "fbun %l0" : "fjun %l0";
5693 (define_insn "buneq"
5694   [(set (pc)
5695         (if_then_else (uneq (cc0) (const_int 0))
5696                       (label_ref (match_operand 0 "" ""))
5697                       (pc)))]
5698   "TARGET_68881"
5700   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5701   return MOTOROLA ? "fbueq %l0" : "fjueq %l0";
5704 (define_insn "bunge"
5705   [(set (pc)
5706         (if_then_else (unge (cc0) (const_int 0))
5707                       (label_ref (match_operand 0 "" ""))
5708                       (pc)))]
5709   "TARGET_68881"
5711   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5712   return MOTOROLA ? "fbuge %l0" : "fjuge %l0";
5715 (define_insn "bungt"
5716   [(set (pc)
5717         (if_then_else (ungt (cc0) (const_int 0))
5718                       (label_ref (match_operand 0 "" ""))
5719                       (pc)))]
5720   "TARGET_68881"
5722   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5723   return MOTOROLA ? "fbugt %l0" : "fjugt %l0";
5726 (define_insn "bunle"
5727   [(set (pc)
5728         (if_then_else (unle (cc0) (const_int 0))
5729                       (label_ref (match_operand 0 "" ""))
5730                       (pc)))]
5731   "TARGET_68881"
5733   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5734   return MOTOROLA ? "fbule %l0" : "fjule %l0";
5737 (define_insn "bunlt"
5738   [(set (pc)
5739         (if_then_else (unlt (cc0) (const_int 0))
5740                       (label_ref (match_operand 0 "" ""))
5741                       (pc)))]
5742   "TARGET_68881"
5744   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5745   return MOTOROLA ? "fbult %l0" : "fjult %l0";
5748 (define_insn "bltgt"
5749   [(set (pc)
5750         (if_then_else (ltgt (cc0) (const_int 0))
5751                       (label_ref (match_operand 0 "" ""))
5752                       (pc)))]
5753   "TARGET_68881"
5755   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5756   return MOTOROLA ? "fbogl %l0" : "fjogl %l0";
5759 ;; Negated conditional jump instructions.
5761 (define_insn ""
5762   [(set (pc)
5763         (if_then_else (eq (cc0)
5764                           (const_int 0))
5765                       (pc)
5766                       (label_ref (match_operand 0 "" ""))))]
5767   ""
5769   if (MOTOROLA)
5770     OUTPUT_JUMP ("jbne %l0", "fbne %l0", "jbne %l0");
5771   else
5772     OUTPUT_JUMP ("jne %l0", "fjne %l0", "jne %l0");
5775 (define_insn ""
5776   [(set (pc)
5777         (if_then_else (ne (cc0)
5778                           (const_int 0))
5779                       (pc)
5780                       (label_ref (match_operand 0 "" ""))))]
5781   ""
5783   if (MOTOROLA)
5784     OUTPUT_JUMP ("jbeq %l0", "fbeq %l0", "jbeq %l0");
5785   else
5786     OUTPUT_JUMP ("jeq %l0", "fjeq %l0", "jeq %l0");
5789 (define_insn ""
5790   [(set (pc)
5791         (if_then_else (gt (cc0)
5792                           (const_int 0))
5793                       (pc)
5794                       (label_ref (match_operand 0 "" ""))))]
5795   ""
5797   if (MOTOROLA)
5798     OUTPUT_JUMP ("jble %l0", "fbngt %l0", 0);
5799   else
5800     OUTPUT_JUMP ("jle %l0", "fjngt %l0", 0);
5803 (define_insn ""
5804   [(set (pc)
5805         (if_then_else (gtu (cc0)
5806                            (const_int 0))
5807                       (pc)
5808                       (label_ref (match_operand 0 "" ""))))]
5809   ""
5811   return MOTOROLA ? "jbls %l0" : "jls %l0";
5814 (define_insn ""
5815   [(set (pc)
5816         (if_then_else (lt (cc0)
5817                           (const_int 0))
5818                       (pc)
5819                       (label_ref (match_operand 0 "" ""))))]
5820   ""
5822   if (MOTOROLA)
5823     OUTPUT_JUMP ("jbge %l0", "fbnlt %l0", "jbpl %l0");
5824   else
5825     OUTPUT_JUMP ("jge %l0", "fjnlt %l0", "jpl %l0");
5828 (define_insn ""
5829   [(set (pc)
5830         (if_then_else (ltu (cc0)
5831                            (const_int 0))
5832                       (pc)
5833                       (label_ref (match_operand 0 "" ""))))]
5834   ""
5836   return MOTOROLA ? "jbcc %l0" : "jcc %l0";
5839 (define_insn ""
5840   [(set (pc)
5841         (if_then_else (ge (cc0)
5842                           (const_int 0))
5843                       (pc)
5844                       (label_ref (match_operand 0 "" ""))))]
5845   ""
5847   if (MOTOROLA)
5848     OUTPUT_JUMP ("jblt %l0", "fbnge %l0", "jbmi %l0");
5849   else
5850     OUTPUT_JUMP ("jlt %l0", "fjnge %l0", "jmi %l0");
5853 (define_insn ""
5854   [(set (pc)
5855         (if_then_else (geu (cc0)
5856                            (const_int 0))
5857                       (pc)
5858                       (label_ref (match_operand 0 "" ""))))]
5859   ""
5861   return MOTOROLA ? "jbcs %l0" : "jcs %l0";
5864 (define_insn ""
5865   [(set (pc)
5866         (if_then_else (le (cc0)
5867                           (const_int 0))
5868                       (pc)
5869                       (label_ref (match_operand 0 "" ""))))]
5870   ""
5872   if (MOTOROLA)
5873     OUTPUT_JUMP ("jbgt %l0", "fbnle %l0", 0);
5874   else
5875     OUTPUT_JUMP ("jgt %l0", "fjnle %l0", 0);
5878 (define_insn ""
5879   [(set (pc)
5880         (if_then_else (leu (cc0)
5881                            (const_int 0))
5882                       (pc)
5883                       (label_ref (match_operand 0 "" ""))))]
5884   ""
5886   return MOTOROLA ? "jbhi %l0" : "jhi %l0";
5889 (define_insn "*bordered_rev"
5890   [(set (pc)
5891         (if_then_else (ordered (cc0) (const_int 0))
5892                       (pc)
5893                       (label_ref (match_operand 0 "" ""))))]
5894   "TARGET_68881"
5896   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5897   return MOTOROLA ? "fbun %l0" : "fjun %l0";
5900 (define_insn "*bunordered_rev"
5901   [(set (pc)
5902         (if_then_else (unordered (cc0) (const_int 0))
5903                       (pc)
5904                       (label_ref (match_operand 0 "" ""))))]
5905   "TARGET_68881"
5907   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5908   return MOTOROLA ? "fbor %l0" : "fjor %l0";
5911 (define_insn "*buneq_rev"
5912   [(set (pc)
5913         (if_then_else (uneq (cc0) (const_int 0))
5914                       (pc)
5915                       (label_ref (match_operand 0 "" ""))))]
5916   "TARGET_68881"
5918   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5919   return MOTOROLA ? "fbogl %l0" : "fjogl %l0";
5922 (define_insn "*bunge_rev"
5923   [(set (pc)
5924         (if_then_else (unge (cc0) (const_int 0))
5925                       (pc)
5926                       (label_ref (match_operand 0 "" ""))))]
5927   "TARGET_68881"
5929   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5930   return MOTOROLA ? "fbolt %l0" : "fjolt %l0";
5933 (define_insn "*bunle_rev"
5934   [(set (pc)
5935         (if_then_else (unle (cc0) (const_int 0))
5936                       (pc)
5937                       (label_ref (match_operand 0 "" ""))))]
5938   "TARGET_68881"
5940   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5941   return MOTOROLA ? "fbogt %l0" : "fjogt %l0";
5944 (define_insn "*bunlt_rev"
5945   [(set (pc)
5946         (if_then_else (unlt (cc0) (const_int 0))
5947                       (pc)
5948                       (label_ref (match_operand 0 "" ""))))]
5949   "TARGET_68881"
5951   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5952   return MOTOROLA ? "fboge %l0" : "fjoge %l0";
5955 (define_insn "*bltgt_rev"
5956   [(set (pc)
5957         (if_then_else (ltgt (cc0) (const_int 0))
5958                       (pc)
5959                       (label_ref (match_operand 0 "" ""))))]
5960   "TARGET_68881"
5962   gcc_assert (cc_prev_status.flags & CC_IN_68881);
5963   return MOTOROLA ? "fbueq %l0" : "fjueq %l0";
5966 ;; Unconditional and other jump instructions
5967 (define_insn "jump"
5968   [(set (pc)
5969         (label_ref (match_operand 0 "" "")))]
5970   ""
5972   return MOTOROLA ? "jbra %l0" : "jra %l0";
5975 (define_expand "tablejump"
5976   [(parallel [(set (pc) (match_operand 0 "" ""))
5977               (use (label_ref (match_operand 1 "" "")))])]
5978   ""
5980 #ifdef CASE_VECTOR_PC_RELATIVE
5981     operands[0] = gen_rtx_PLUS (SImode, pc_rtx,
5982                                 gen_rtx_SIGN_EXTEND (SImode, operands[0]));
5983 #endif
5986 ;; Jump to variable address from dispatch table of absolute addresses.
5987 (define_insn ""
5988   [(set (pc) (match_operand:SI 0 "register_operand" "a"))
5989    (use (label_ref (match_operand 1 "" "")))]
5990   ""
5992   return MOTOROLA ? "jmp (%0)" : "jmp %0@";
5995 ;; Jump to variable address from dispatch table of relative addresses.
5996 (define_insn ""
5997   [(set (pc)
5998         (plus:SI (pc)
5999                  (sign_extend:SI (match_operand:HI 0 "register_operand" "r"))))
6000    (use (label_ref (match_operand 1 "" "")))]
6001   ""
6003 #ifdef ASM_RETURN_CASE_JUMP
6004   ASM_RETURN_CASE_JUMP;
6005 #else
6006   if (TARGET_COLDFIRE)
6007     {
6008       if (ADDRESS_REG_P (operands[0]))
6009         return MOTOROLA ? "jmp (2,pc,%0.l)" : "jmp pc@(2,%0:l)";
6010       else if (MOTOROLA)
6011         return "ext%.l %0\;jmp (2,pc,%0.l)";
6012       else
6013         return "extl %0\;jmp pc@(2,%0:l)";
6014     }
6015   else
6016     return MOTOROLA ? "jmp (2,pc,%0.w)" : "jmp pc@(2,%0:w)";
6017 #endif
6020 ;; Decrement-and-branch insns.
6021 (define_insn ""
6022   [(set (pc)
6023         (if_then_else
6024          (ne (match_operand:HI 0 "nonimmediate_operand" "+d*g")
6025              (const_int 0))
6026          (label_ref (match_operand 1 "" ""))
6027          (pc)))
6028    (set (match_dup 0)
6029         (plus:HI (match_dup 0)
6030                  (const_int -1)))]
6031   "!TARGET_COLDFIRE"
6033   CC_STATUS_INIT;
6034   if (DATA_REG_P (operands[0]))
6035     return "dbra %0,%l1";
6036   if (GET_CODE (operands[0]) == MEM)
6037     return MOTOROLA ?
6038       "subq%.w #1,%0\;jbcc %l1" :
6039       "subqw #1,%0\;jcc %l1";
6040   return MOTOROLA ?
6041     "subq%.w #1,%0\;cmp%.w #-1,%0\;jbne %l1" :
6042     "subqw #1,%0\;cmpw #-1,%0\;jne %l1";
6045 (define_insn ""
6046   [(set (pc)
6047         (if_then_else
6048          (ne (match_operand:SI 0 "nonimmediate_operand" "+d*g")
6049              (const_int 0))
6050          (label_ref (match_operand 1 "" ""))
6051          (pc)))
6052    (set (match_dup 0)
6053         (plus:SI (match_dup 0)
6054                  (const_int -1)))]
6055   "!TARGET_COLDFIRE"
6057   CC_STATUS_INIT;
6058   if (DATA_REG_P (operands[0]))
6059     return MOTOROLA ?
6060       "dbra %0,%l1\;clr%.w %0\;subq%.l #1,%0\;jbcc %l1" :
6061       "dbra %0,%l1\;clr%.w %0\;subq%.l #1,%0\;jcc %l1";
6062   if (GET_CODE (operands[0]) == MEM)
6063     return MOTOROLA ?
6064       "subq%.l #1,%0\;jbcc %l1" :
6065       "subq%.l #1,%0\;jcc %l1";
6066   return MOTOROLA ?
6067     "subq.l #1,%0\;cmp.l #-1,%0\;jbne %l1" :
6068     "subql #1,%0\;cmpl #-1,%0\;jne %l1";
6071 ;; Two dbra patterns that use REG_NOTES info generated by strength_reduce.
6073 (define_insn ""
6074   [(set (pc)
6075         (if_then_else
6076           (ge (plus:HI (match_operand:HI 0 "nonimmediate_operand" "+d*am")
6077                        (const_int -1))
6078               (const_int 0))
6079           (label_ref (match_operand 1 "" ""))
6080           (pc)))
6081    (set (match_dup 0)
6082         (plus:HI (match_dup 0)
6083                  (const_int -1)))]
6084   "!TARGET_COLDFIRE && find_reg_note (insn, REG_NONNEG, 0)"
6086   CC_STATUS_INIT;
6087   if (DATA_REG_P (operands[0]))
6088     return "dbra %0,%l1";
6089   if (GET_CODE (operands[0]) == MEM)
6090     return MOTOROLA ?
6091       "subq%.w #1,%0\;jbcc %l1" :
6092       "subq%.w #1,%0\;jcc %l1";
6093   return MOTOROLA ?
6094     "subq.w #1,%0\;cmp.w #-1,%0\;jbne %l1" :
6095     "subqw #1,%0\;cmpw #-1,%0\;jne %l1";
6098 (define_expand "decrement_and_branch_until_zero"
6099   [(parallel [(set (pc)
6100                    (if_then_else
6101                     (ge (plus:SI (match_operand:SI 0 "nonimmediate_operand" "")
6102                                  (const_int -1))
6103                         (const_int 0))
6104                     (label_ref (match_operand 1 "" ""))
6105                     (pc)))
6106               (set (match_dup 0)
6107                    (plus:SI (match_dup 0)
6108                             (const_int -1)))])]
6109   ""
6110   "")
6112 (define_insn ""
6113   [(set (pc)
6114         (if_then_else
6115           (ge (plus:SI (match_operand:SI 0 "nonimmediate_operand" "+d*am")
6116                        (const_int -1))
6117               (const_int 0))
6118           (label_ref (match_operand 1 "" ""))
6119           (pc)))
6120    (set (match_dup 0)
6121         (plus:SI (match_dup 0)
6122                  (const_int -1)))]
6123   "!TARGET_COLDFIRE && find_reg_note (insn, REG_NONNEG, 0)"
6125   CC_STATUS_INIT;
6126   if (DATA_REG_P (operands[0]))
6127     return MOTOROLA ?
6128       "dbra %0,%l1\;clr%.w %0\;subq%.l #1,%0\;jbcc %l1" :
6129       "dbra %0,%l1\;clr%.w %0\;subql #1,%0\;jcc %l1";
6130   if (GET_CODE (operands[0]) == MEM)
6131     return MOTOROLA ?
6132       "subq%.l #1,%0\;jbcc %l1" :
6133       "subql #1,%0\;jcc %l1";
6134   return MOTOROLA ?
6135     "subq.l #1,%0\;cmp.l #-1,%0\;jbne %l1" :
6136     "subql #1,%0\;cmpl #-1,%0\;jne %l1";
6140 ;; For PIC calls, in order to be able to support
6141 ;; dynamic linker LAZY BINDING, all the procedure calls need to go
6142 ;; through the PLT (Procedure Linkage Table) section in PIC mode.
6144 ;; PIC calls are handled by loading the address of the function into a
6145 ;; register (via movsi), then emitting a register indirect call using
6146 ;; the "jsr" function call syntax.
6148 ;; When outputting MIT syntax (e.g. on Suns), we add a bogus extra
6149 ;; operand to the jbsr statement to indicate that this call should
6150 ;; go through the PLT (why? because this is the way that Sun does it).
6152 ;; We have different patterns for PIC calls and non-PIC calls.  The
6153 ;; different patterns are only used to choose the right syntax.
6155 ;; The svr4 m68k assembler recognizes this syntax: `bsr FUNC@PLTPC' and it
6156 ;; will create the correct relocation entry (R_68K_PLT32) for `FUNC',
6157 ;; that tells the linker editor to create an entry for `FUNC' in PLT
6158 ;; section at link time. However, all global objects reference are still
6159 ;; done by using `OBJ@GOT'. So, the goal here is to output the function
6160 ;; call operand as `FUNC@PLTPC', but output object operand as `OBJ@GOT'.
6161 ;; We need to have a way to differentiate these two different operands.
6163 ;; The strategy I use here is to use SYMBOL_REF_FLAG to differentiate
6164 ;; these two different operands. The macro LEGITIMATE_PIC_OPERAND_P needs
6165 ;; to be changed to recognize function calls symbol_ref operand as a valid
6166 ;; PIC operand (by checking whether SYMBOL_REF_FLAG is set). This will
6167 ;; avoid the compiler to load this symbol_ref operand into a register.
6168 ;; Remember, the operand "foo@PLTPC" cannot be called via jsr directly
6169 ;; since the value is a PC relative offset, not a real address.
6171 ;; All global objects are treated in the similar way as in SUN3. The only
6172 ;; difference is: on m68k svr4, the reference of such global object needs
6173 ;; to end with a suffix "@GOT" so the assembler and linker know to create
6174 ;; an entry for it in GOT (Global Offset Table) section. This is done in
6175 ;; m68k.c.
6177 ;; Call subroutine with no return value.
6178 (define_expand "call"
6179   [(call (match_operand:QI 0 "memory_operand" "")
6180          (match_operand:SI 1 "general_operand" ""))]
6181   ;; Operand 1 not really used on the m68000.
6183   ""
6185   if (flag_pic && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
6186     SYMBOL_REF_FLAG (XEXP (operands[0], 0)) = 1;
6189 ;; This is a normal call sequence.
6190 (define_insn ""
6191   [(call (match_operand:QI 0 "memory_operand" "o")
6192          (match_operand:SI 1 "general_operand" "g"))]
6193   ;; Operand 1 not really used on the m68000.
6195   "! flag_pic"
6197 #if MOTOROLA && !defined (USE_GAS)
6198   return "jsr %0";
6199 #else
6200   return "jbsr %0";
6201 #endif
6204 ;; This is a PIC call sequence.
6205 (define_insn ""
6206   [(call (match_operand:QI 0 "memory_operand" "o")
6207          (match_operand:SI 1 "general_operand" "g"))]
6208   ;; Operand 1 not really used on the m68000.
6210   "flag_pic"
6212   m68k_output_pic_call(operands[0]);
6213   return "";
6216 ;; Call subroutine, returning value in operand 0
6217 ;; (which must be a hard register).
6218 ;; See comments before "call" regarding PIC calls.
6219 (define_expand "call_value"
6220   [(set (match_operand 0 "" "")
6221         (call (match_operand:QI 1 "memory_operand" "")
6222      (match_operand:SI 2 "general_operand" "")))]
6223   ;; Operand 2 not really used on the m68000.
6224   ""
6226   if (flag_pic && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
6227     SYMBOL_REF_FLAG (XEXP (operands[1], 0)) = 1;
6230 ;; This is a normal call_value
6231 (define_insn ""
6232   [(set (match_operand 0 "" "=rf")
6233         (call (match_operand:QI 1 "memory_operand" "o")
6234               (match_operand:SI 2 "general_operand" "g")))]
6235   ;; Operand 2 not really used on the m68000.
6236   "! flag_pic"
6238 #if MOTOROLA && !defined (USE_GAS)
6239   return "jsr %1";
6240 #else
6241   return "jbsr %1";
6242 #endif
6245 ;; This is a PIC call_value
6246 (define_insn ""
6247   [(set (match_operand 0 "" "=rf")
6248         (call (match_operand:QI 1 "memory_operand" "o")
6249               (match_operand:SI 2 "general_operand" "g")))]
6250   ;; Operand 2 not really used on the m68000.
6251   "flag_pic"
6253   m68k_output_pic_call(operands[1]);
6254   return "";
6257 ;; Call subroutine returning any type.
6259 (define_expand "untyped_call"
6260   [(parallel [(call (match_operand 0 "" "")
6261                     (const_int 0))
6262               (match_operand 1 "" "")
6263               (match_operand 2 "" "")])]
6264   "NEEDS_UNTYPED_CALL"
6266   int i;
6268   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
6270   for (i = 0; i < XVECLEN (operands[2], 0); i++)
6271     {
6272       rtx set = XVECEXP (operands[2], 0, i);
6273       emit_move_insn (SET_DEST (set), SET_SRC (set));
6274     }
6276   /* The optimizer does not know that the call sets the function value
6277      registers we stored in the result block.  We avoid problems by
6278      claiming that all hard registers are used and clobbered at this
6279      point.  */
6280   emit_insn (gen_blockage ());
6282   DONE;
6285 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
6286 ;; all of memory.  This blocks insns from being moved across this point.
6288 (define_insn "blockage"
6289   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
6290   ""
6291   "")
6293 (define_insn "nop"
6294   [(const_int 0)]
6295   ""
6296   "nop")
6298 ;; Used for frameless functions which save no regs and allocate no locals.
6299 (define_insn "return"
6300   [(return)]
6301   "USE_RETURN_INSN"
6303   if (current_function_pops_args == 0)
6304     return "rts";
6305   operands[0] = GEN_INT (current_function_pops_args);
6306   return "rtd %0";
6309 (define_insn "indirect_jump"
6310   [(set (pc) (match_operand:SI 0 "address_operand" "p"))]
6311   ""
6312   "jmp %a0")
6314 ;; This should not be used unless the add/sub insns can't be.
6316 (define_insn ""
6317   [(set (match_operand:SI 0 "nonimmediate_operand" "=a")
6318         (match_operand:QI 1 "address_operand" "p"))]
6319   ""
6321   /* Recognize an insn that refers to a table of offsets.  Such an insn will
6322      need to refer to a label on the insn.  So output one.  Use the
6323      label-number of the table of offsets to generate this label.  This code,
6324      and similar code above, assumes that there will be at most one reference
6325      to each table.  */
6326   if (GET_CODE (operands[1]) == PLUS
6327       && GET_CODE (XEXP (operands[1], 1)) == LABEL_REF
6328       && GET_CODE (XEXP (operands[1], 0)) != PLUS)
6329     {
6330       rtx labelref = XEXP (operands[1], 1);
6331       if (MOTOROLA)
6332         asm_fprintf (asm_out_file, "\\t.set %LLI%d,.+2\\n",
6333                      CODE_LABEL_NUMBER (XEXP (labelref, 0)));
6334       else
6335         (*targetm.asm_out.internal_label) (asm_out_file, "LI",
6336                      CODE_LABEL_NUMBER (XEXP (labelref, 0)));
6337     }
6338   return "lea %a1,%0";
6341 ;; This is the first machine-dependent peephole optimization.
6342 ;; It is useful when a floating value is returned from a function call
6343 ;; and then is moved into an FP register.
6344 ;; But it is mainly intended to test the support for these optimizations.
6346 (define_peephole
6347   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int 4)))
6348    (set (match_operand:DF 0 "register_operand" "=f")
6349         (match_operand:DF 1 "register_operand" "ad"))]
6350   "FP_REG_P (operands[0]) && ! FP_REG_P (operands[1])"
6352   rtx xoperands[2];
6353   xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
6354   output_asm_insn ("move%.l %1,%@", xoperands);
6355   output_asm_insn ("move%.l %1,%-", operands);
6356   return "fmove%.d %+,%0";
6359 ;; Optimize a stack-adjust followed by a push of an argument.
6360 ;; This is said to happen frequently with -msoft-float
6361 ;; when there are consecutive library calls.
6363 (define_peephole
6364   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
6365                                  (match_operand:SI 0 "const_int_operand" "n")))
6366    (set (match_operand:SF 1 "push_operand" "=m")
6367         (match_operand:SF 2 "general_operand" "rmfF"))]
6368   "INTVAL (operands[0]) >= 4
6369    && ! reg_mentioned_p (stack_pointer_rtx, operands[2])"
6371   if (INTVAL (operands[0]) > 4)
6372     {
6373       rtx xoperands[2];
6374       xoperands[0] = stack_pointer_rtx;
6375       xoperands[1] = GEN_INT (INTVAL (operands[0]) - 4);
6376       if (INTVAL (xoperands[1]) <= 8)
6377         {
6378           if (!TARGET_COLDFIRE)
6379             output_asm_insn ("addq%.w %1,%0", xoperands);
6380           else
6381             output_asm_insn ("addq%.l %1,%0", xoperands);
6382         }
6383       else if (TARGET_CPU32 && INTVAL (xoperands[1]) <= 16) 
6384         {
6385           xoperands[1] = GEN_INT (INTVAL (xoperands[1]) - 8);
6386           output_asm_insn ("addq%.w #8,%0\;addq%.w %1,%0", xoperands);
6387         }
6388       else if (INTVAL (xoperands[1]) <= 0x7FFF)
6389         {
6390           if (TARGET_68040)
6391             output_asm_insn ("add%.w %1,%0", xoperands);
6392           else if (MOTOROLA)
6393             output_asm_insn ("lea (%c1,%0),%0", xoperands);
6394           else
6395             output_asm_insn ("lea %0@(%c1),%0", xoperands);
6396         }
6397       else
6398         output_asm_insn ("add%.l %1,%0", xoperands);
6399     }
6400   if (FP_REG_P (operands[2]))
6401     return "fmove%.s %2,%@";
6402   return "move%.l %2,%@";
6405 ;; Speed up stack adjust followed by a fullword fixedpoint push.
6407 (define_peephole
6408   [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
6409                                  (match_operand:SI 0 "const_int_operand" "n")))
6410    (set (match_operand:SI 1 "push_operand" "=m")
6411         (match_operand:SI 2 "general_operand" "g"))]
6412   "INTVAL (operands[0]) >= 4
6413    && ! reg_mentioned_p (stack_pointer_rtx, operands[2])"
6415   if (INTVAL (operands[0]) > 4)
6416     {
6417       rtx xoperands[2];
6418       xoperands[0] = stack_pointer_rtx;
6419       xoperands[1] = GEN_INT (INTVAL (operands[0]) - 4);
6420       if (INTVAL (xoperands[1]) <= 8)
6421         {
6422           if (!TARGET_COLDFIRE)
6423             output_asm_insn ("addq%.w %1,%0", xoperands);
6424           else
6425             output_asm_insn ("addq%.l %1,%0", xoperands);
6426         }
6427       else if (TARGET_CPU32 && INTVAL (xoperands[1]) <= 16)
6428         {
6429           xoperands[1] = GEN_INT (INTVAL (xoperands[1]) - 8);
6430           output_asm_insn ("addq%.w #8,%0\;addq%.w %1,%0", xoperands);
6431         }
6432       else if (INTVAL (xoperands[1]) <= 0x7FFF)
6433         {
6434           if (TARGET_68040)
6435             output_asm_insn ("add%.w %1,%0", xoperands);
6436           else if (MOTOROLA)
6437             output_asm_insn ("lea (%c1,%0),%0", xoperands);
6438           else
6439             output_asm_insn ("lea %0@(%c1),%0", xoperands);
6440         }
6441       else
6442         output_asm_insn ("add%.l %1,%0", xoperands);
6443     }
6444   if (operands[2] == const0_rtx)
6445     return "clr%.l %@";
6446   return "move%.l %2,%@";
6449 ;; Speed up pushing a single byte but leaving four bytes of space.
6451 (define_peephole
6452   [(set (mem:QI (pre_dec:SI (reg:SI SP_REG)))
6453         (match_operand:QI 1 "general_operand" "dami"))
6454    (set (reg:SI SP_REG) (minus:SI (reg:SI SP_REG) (const_int 2)))]
6455   "! reg_mentioned_p (stack_pointer_rtx, operands[1])"
6457   rtx xoperands[4];
6459   if (GET_CODE (operands[1]) == REG)
6460     return "move%.l %1,%-";
6462   xoperands[1] = operands[1];
6463   xoperands[2]
6464     = gen_rtx_MEM (QImode, plus_constant (stack_pointer_rtx, 3));
6465   xoperands[3] = stack_pointer_rtx;
6466   if (!TARGET_COLDFIRE)
6467     output_asm_insn ("subq%.w #4,%3\;move%.b %1,%2", xoperands);
6468   else
6469     output_asm_insn ("subq%.l #4,%3\;move%.b %1,%2", xoperands);
6470   return "";
6473 (define_peephole
6474   [(set (match_operand:SI 0 "register_operand" "=d")
6475         (const_int 0))
6476    (set (strict_low_part (subreg:HI (match_dup 0) 2))
6477         (match_operand:HI 1 "general_operand" "rmn"))]
6478   "strict_low_part_peephole_ok (HImode, prev_nonnote_insn (insn), operands[0])"
6480   if (GET_CODE (operands[1]) == CONST_INT)
6481     {
6482       if (operands[1] == const0_rtx
6483           && (DATA_REG_P (operands[0])
6484               || GET_CODE (operands[0]) == MEM)
6485           /* clr insns on 68000 read before writing.
6486              This isn't so on the 68010, but we have no TARGET_68010.  */
6487           && ((TARGET_68020 || TARGET_COLDFIRE)
6488               || !(GET_CODE (operands[0]) == MEM
6489                    && MEM_VOLATILE_P (operands[0]))))
6490         return "clr%.w %0";
6491     }
6492   return "move%.w %1,%0";
6495 ;; dbCC peepholes
6497 ;; Turns
6498 ;;   loop:
6499 ;;           [ ... ]
6500 ;;           jCC label          ; abnormal loop termination
6501 ;;           dbra dN, loop      ; normal loop termination
6503 ;; Into
6504 ;;   loop:
6505 ;;           [ ... ]
6506 ;;           dbCC dN, loop
6507 ;;           jCC label
6509 ;; Which moves the jCC condition outside the inner loop for free.
6512 (define_peephole
6513   [(set (pc) (if_then_else (match_operator 3 "valid_dbcc_comparison_p"
6514                              [(cc0) (const_int 0)])
6515                            (label_ref (match_operand 2 "" ""))
6516                            (pc)))
6517    (parallel
6518     [(set (pc)
6519           (if_then_else
6520             (ne (match_operand:HI 0 "register_operand" "")
6521                 (const_int 0))
6522             (label_ref (match_operand 1 "" ""))
6523             (pc)))
6524      (set (match_dup 0)
6525           (plus:HI (match_dup 0)
6526                    (const_int -1)))])]
6527   "!TARGET_COLDFIRE && DATA_REG_P (operands[0]) && ! flags_in_68881 ()"
6529   CC_STATUS_INIT;
6530   output_dbcc_and_branch (operands);
6531   return "";
6534 (define_peephole
6535   [(set (pc) (if_then_else (match_operator 3 "valid_dbcc_comparison_p"
6536                              [(cc0) (const_int 0)])
6537                            (label_ref (match_operand 2 "" ""))
6538                            (pc)))
6539    (parallel
6540     [(set (pc)
6541           (if_then_else
6542             (ne (match_operand:SI 0 "register_operand" "")
6543                 (const_int 0))
6544             (label_ref (match_operand 1 "" ""))
6545             (pc)))
6546      (set (match_dup 0)
6547           (plus:SI (match_dup 0)
6548                    (const_int -1)))])]
6549   "!TARGET_COLDFIRE && DATA_REG_P (operands[0]) && ! flags_in_68881 ()"
6551   CC_STATUS_INIT;
6552   output_dbcc_and_branch (operands);
6553   return "";
6556 (define_peephole
6557   [(set (pc) (if_then_else (match_operator 3 "valid_dbcc_comparison_p"
6558                              [(cc0) (const_int 0)])
6559                            (label_ref (match_operand 2 "" ""))
6560                            (pc)))
6561    (parallel
6562     [(set (pc)
6563           (if_then_else
6564             (ge (plus:HI (match_operand:HI 0 "register_operand" "")
6565                          (const_int -1))
6566                 (const_int 0))
6567             (label_ref (match_operand 1 "" ""))
6568             (pc)))
6569      (set (match_dup 0)
6570           (plus:HI (match_dup 0)
6571                    (const_int -1)))])]
6572   "!TARGET_COLDFIRE && DATA_REG_P (operands[0]) && ! flags_in_68881 ()"
6574   CC_STATUS_INIT;
6575   output_dbcc_and_branch (operands);
6576   return "";
6579 (define_peephole
6580   [(set (pc) (if_then_else (match_operator 3 "valid_dbcc_comparison_p"
6581                              [(cc0) (const_int 0)])
6582                            (label_ref (match_operand 2 "" ""))
6583                            (pc)))
6584    (parallel
6585     [(set (pc)
6586           (if_then_else
6587             (ge (plus:SI (match_operand:SI 0 "register_operand" "")
6588                          (const_int -1))
6589                 (const_int 0))
6590             (label_ref (match_operand 1 "" ""))
6591             (pc)))
6592      (set (match_dup 0)
6593           (plus:SI (match_dup 0)
6594                    (const_int -1)))])]
6595   "!TARGET_COLDFIRE && DATA_REG_P (operands[0]) && ! flags_in_68881 ()"
6597   CC_STATUS_INIT;
6598   output_dbcc_and_branch (operands);
6599   return "";
6603 (define_expand "tstxf"
6604   [(set (cc0)
6605         (match_operand:XF 0 "nonimmediate_operand" ""))]
6606   "TARGET_68881"
6607   "m68k_last_compare_had_fp_operands = 1;")
6609 (define_insn ""
6610   [(set (cc0)
6611         (match_operand:XF 0 "nonimmediate_operand" "fm"))]
6612   "TARGET_68881"
6614   cc_status.flags = CC_IN_68881;
6615   return "ftst%.x %0";
6618 (define_expand "cmpxf"
6619   [(set (cc0)
6620         (compare (match_operand:XF 0 "nonimmediate_operand" "")
6621                  (match_operand:XF 1 "nonimmediate_operand" "")))]
6622   "TARGET_68881"
6623   "m68k_last_compare_had_fp_operands = 1;")
6625 (define_insn ""
6626   [(set (cc0)
6627         (compare (match_operand:XF 0 "nonimmediate_operand" "f,m")
6628                  (match_operand:XF 1 "nonimmediate_operand" "fm,f")))]
6629   "TARGET_68881"
6631   cc_status.flags = CC_IN_68881;
6632   if (REG_P (operands[0]))
6633     {
6634       if (REG_P (operands[1]))
6635         return "fcmp%.x %1,%0";
6636       else
6637         return "fcmp%.x %f1,%0";
6638     }
6639   cc_status.flags |= CC_REVERSED;
6640   return "fcmp%.x %f0,%1";
6643 (define_insn "extendsfxf2"
6644   [(set (match_operand:XF 0 "nonimmediate_operand" "=fm,f")
6645         (float_extend:XF (match_operand:SF 1 "general_operand" "f,rmF")))]
6646   "TARGET_68881"
6648   if (FP_REG_P (operands[0]) && FP_REG_P (operands[1]))
6649     {
6650       if (REGNO (operands[0]) == REGNO (operands[1]))
6651         {
6652           /* Extending float to double in an fp-reg is a no-op.
6653              NOTICE_UPDATE_CC has already assumed that the
6654              cc will be set.  So cancel what it did.  */
6655           cc_status = cc_prev_status;
6656           return "";
6657         }
6658       return "f%$move%.x %1,%0";
6659     }
6660   if (FP_REG_P (operands[0]))
6661     {
6662       if (FP_REG_P (operands[1]))
6663         return "f%$move%.x %1,%0";
6664       else if (ADDRESS_REG_P (operands[1]))
6665         return "move%.l %1,%-\;f%$move%.s %+,%0";
6666       else if (GET_CODE (operands[1]) == CONST_DOUBLE)
6667         return output_move_const_single (operands);
6668       return "f%$move%.s %f1,%0";
6669     }
6670   return "fmove%.x %f1,%0";
6674 (define_insn "extenddfxf2"
6675   [(set (match_operand:XF 0 "nonimmediate_operand" "=fm,f")
6676         (float_extend:XF
6677           (match_operand:DF 1 "general_operand" "f,rmE")))]
6678   "TARGET_68881"
6680   if (FP_REG_P (operands[0]) && FP_REG_P (operands[1]))
6681     {
6682       if (REGNO (operands[0]) == REGNO (operands[1]))
6683         {
6684           /* Extending float to double in an fp-reg is a no-op.
6685              NOTICE_UPDATE_CC has already assumed that the
6686              cc will be set.  So cancel what it did.  */
6687           cc_status = cc_prev_status;
6688           return "";
6689         }
6690       return "fmove%.x %1,%0";
6691     }
6692   if (FP_REG_P (operands[0]))
6693     {
6694       if (REG_P (operands[1]))
6695         {
6696           rtx xoperands[2];
6697           xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
6698           output_asm_insn ("move%.l %1,%-", xoperands);
6699           output_asm_insn ("move%.l %1,%-", operands);
6700           return "f%&move%.d %+,%0";
6701         }
6702       if (GET_CODE (operands[1]) == CONST_DOUBLE)
6703         return output_move_const_double (operands);
6704       return "f%&move%.d %f1,%0";
6705     }
6706   return "fmove%.x %f1,%0";
6709 (define_insn "truncxfdf2"
6710   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,!r")
6711         (float_truncate:DF
6712           (match_operand:XF 1 "general_operand" "f,f")))]
6713   "TARGET_68881"
6715   if (REG_P (operands[0]))
6716     {
6717       output_asm_insn ("fmove%.d %f1,%-\;move%.l %+,%0", operands);
6718       operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
6719       return "move%.l %+,%0";
6720     }
6721   return "fmove%.d %f1,%0";
6724 (define_insn "truncxfsf2"
6725   [(set (match_operand:SF 0 "nonimmediate_operand" "=dm")
6726         (float_truncate:SF
6727           (match_operand:XF 1 "general_operand" "f")))]
6728   "TARGET_68881"
6729   "fmove%.s %f1,%0")
6731 (define_insn "floatsixf2"
6732   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6733         (float:XF (match_operand:SI 1 "general_operand" "dmi")))]
6734   "TARGET_68881"
6735   "fmove%.l %1,%0")
6737 (define_insn "floathixf2"
6738   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6739         (float:XF (match_operand:HI 1 "general_operand" "dmn")))]
6740   "TARGET_68881"
6741   "fmove%.w %1,%0")
6743 (define_insn "floatqixf2"
6744   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6745         (float:XF (match_operand:QI 1 "general_operand" "dmn")))]
6746   "TARGET_68881"
6747   "fmove%.b %1,%0")
6749 (define_insn "ftruncxf2"
6750   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6751         (fix:XF (match_operand:XF 1 "general_operand" "fFm")))]
6752   "TARGET_68881"
6754   if (FP_REG_P (operands[1]))
6755     return "fintrz%.x %f1,%0";
6756   return "fintrz%.x %f1,%0";
6759 (define_insn "fixxfqi2"
6760   [(set (match_operand:QI 0 "nonimmediate_operand" "=dm")
6761         (fix:QI (match_operand:XF 1 "general_operand" "f")))]
6762   "TARGET_68881"
6763   "fmove%.b %1,%0")
6765 (define_insn "fixxfhi2"
6766   [(set (match_operand:HI 0 "nonimmediate_operand" "=dm")
6767         (fix:HI (match_operand:XF 1 "general_operand" "f")))]
6768   "TARGET_68881"
6769   "fmove%.w %1,%0")
6771 (define_insn "fixxfsi2"
6772   [(set (match_operand:SI 0 "nonimmediate_operand" "=dm")
6773         (fix:SI (match_operand:XF 1 "general_operand" "f")))]
6774   "TARGET_68881"
6775   "fmove%.l %1,%0")
6777 (define_insn ""
6778   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6779         (plus:XF (float:XF (match_operand:SI 2 "general_operand" "dmi"))
6780                  (match_operand:XF 1 "nonimmediate_operand" "0")))]
6781   "TARGET_68881"
6782   "fadd%.l %2,%0")
6784 (define_insn ""
6785   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6786         (plus:XF (float:XF (match_operand:HI 2 "general_operand" "dmn"))
6787                  (match_operand:XF 1 "nonimmediate_operand" "0")))]
6788   "TARGET_68881"
6789   "fadd%.w %2,%0")
6791 (define_insn ""
6792   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6793         (plus:XF (float:XF (match_operand:QI 2 "general_operand" "dmn"))
6794                  (match_operand:XF 1 "general_operand" "0")))]
6795   "TARGET_68881"
6796   "fadd%.b %2,%0")
6798 (define_insn "addxf3"
6799   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6800         (plus:XF (match_operand:XF 1 "nonimmediate_operand" "%0")
6801                  (match_operand:XF 2 "nonimmediate_operand" "fm")))]
6802   "TARGET_68881"
6804   if (REG_P (operands[2]))
6805     return "fadd%.x %2,%0";
6806   return "fadd%.x %f2,%0";
6809 (define_insn ""
6810   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6811         (minus:XF (match_operand:XF 1 "nonimmediate_operand" "0")
6812                   (float:XF (match_operand:SI 2 "general_operand" "dmi"))))]
6813   "TARGET_68881"
6814   "fsub%.l %2,%0")
6816 (define_insn ""
6817   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6818         (minus:XF (match_operand:XF 1 "nonimmediate_operand" "0")
6819                   (float:XF (match_operand:HI 2 "general_operand" "dmn"))))]
6820   "TARGET_68881"
6821   "fsub%.w %2,%0")
6823 (define_insn ""
6824   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6825         (minus:XF (match_operand:XF 1 "nonimmediate_operand" "0")
6826                   (float:XF (match_operand:QI 2 "general_operand" "dmn"))))]
6827   "TARGET_68881"
6828   "fsub%.b %2,%0")
6830 (define_insn "subxf3"
6831   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6832         (minus:XF (match_operand:XF 1 "nonimmediate_operand" "0")
6833                   (match_operand:XF 2 "nonimmediate_operand" "fm")))]
6834   "TARGET_68881"
6836   if (REG_P (operands[2]))
6837     return "fsub%.x %2,%0";
6838   return "fsub%.x %f2,%0";
6841 (define_insn ""
6842   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6843         (mult:XF (float:XF (match_operand:SI 2 "general_operand" "dmi"))
6844                  (match_operand:XF 1 "nonimmediate_operand" "0")))]
6845   "TARGET_68881"
6846   "fmul%.l %2,%0")
6848 (define_insn ""
6849   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6850         (mult:XF (float:XF (match_operand:HI 2 "general_operand" "dmn"))
6851                  (match_operand:XF 1 "nonimmediate_operand" "0")))]
6852   "TARGET_68881"
6853   "fmul%.w %2,%0")
6855 (define_insn ""
6856   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6857         (mult:XF (float:XF (match_operand:QI 2 "general_operand" "dmn"))
6858                  (match_operand:XF 1 "nonimmediate_operand" "0")))]
6859   "TARGET_68881"
6860   "fmul%.b %2,%0")
6862 (define_insn "mulxf3"
6863   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6864         (mult:XF (match_operand:XF 1 "nonimmediate_operand" "%0")
6865                  (match_operand:XF 2 "nonimmediate_operand" "fm")))]
6866   "TARGET_68881"
6868   if (REG_P (operands[2]))
6869     return "fmul%.x %2,%0";
6870   return "fmul%.x %f2,%0";
6873 (define_insn ""
6874   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6875         (div:XF (match_operand:XF 1 "nonimmediate_operand" "0")
6876                 (float:XF (match_operand:SI 2 "general_operand" "dmi"))))]
6877   "TARGET_68881"
6878   "fdiv%.l %2,%0")
6880 (define_insn ""
6881   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6882         (div:XF (match_operand:XF 1 "nonimmediate_operand" "0")
6883                 (float:XF (match_operand:HI 2 "general_operand" "dmn"))))]
6884   "TARGET_68881"
6885   "fdiv%.w %2,%0")
6887 (define_insn ""
6888   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6889         (div:XF (match_operand:XF 1 "nonimmediate_operand" "0")
6890                 (float:XF (match_operand:QI 2 "general_operand" "dmn"))))]
6891   "TARGET_68881"
6892   "fdiv%.b %2,%0")
6894 (define_insn "divxf3"
6895   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6896         (div:XF (match_operand:XF 1 "nonimmediate_operand" "0")
6897                 (match_operand:XF 2 "nonimmediate_operand" "fm")))]
6898   "TARGET_68881"
6900   if (REG_P (operands[2]))
6901     return "fdiv%.x %2,%0";
6902   return "fdiv%.x %f2,%0";
6905 (define_expand "negxf2"
6906   [(set (match_operand:XF 0 "nonimmediate_operand" "")
6907         (neg:XF (match_operand:XF 1 "nonimmediate_operand" "")))]
6908   ""
6910   if (!TARGET_68881)
6911     {
6912       rtx result;
6913       rtx target;
6914       rtx insns;
6916       start_sequence ();
6917       target = operand_subword (operands[0], 0, 1, XFmode);
6918       result = expand_binop (SImode, xor_optab,
6919                              operand_subword_force (operands[1], 0, XFmode),
6920                              GEN_INT (0x80000000), target, 0, OPTAB_WIDEN);
6921       gcc_assert (result);
6923       if (result != target)
6924         emit_move_insn (result, target);
6926       emit_move_insn (operand_subword (operands[0], 1, 1, XFmode),
6927                       operand_subword_force (operands[1], 1, XFmode));
6928       emit_move_insn (operand_subword (operands[0], 2, 1, XFmode),
6929                       operand_subword_force (operands[1], 2, XFmode));
6931       insns = get_insns ();
6932       end_sequence ();
6934       emit_no_conflict_block (insns, operands[0], operands[1], 0, 0);
6935       DONE;
6936     }
6939 (define_insn "negxf2_68881"
6940   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6941         (neg:XF (match_operand:XF 1 "nonimmediate_operand" "fm")))]
6942   "TARGET_68881"
6944   if (REG_P (operands[1]) && ! DATA_REG_P (operands[1]))
6945     return "fneg%.x %1,%0";
6946   return "fneg%.x %f1,%0";
6949 (define_expand "absxf2"
6950   [(set (match_operand:XF 0 "nonimmediate_operand" "")
6951         (abs:XF (match_operand:XF 1 "nonimmediate_operand" "")))]
6952   ""
6954   if (!TARGET_68881)
6955     {
6956       rtx result;
6957       rtx target;
6958       rtx insns;
6960       start_sequence ();
6961       target = operand_subword (operands[0], 0, 1, XFmode);
6962       result = expand_binop (SImode, and_optab,
6963                              operand_subword_force (operands[1], 0, XFmode),
6964                              GEN_INT (0x7fffffff), target, 0, OPTAB_WIDEN);
6965       gcc_assert (result);
6967       if (result != target)
6968         emit_move_insn (result, target);
6970       emit_move_insn (operand_subword (operands[0], 1, 1, XFmode),
6971                       operand_subword_force (operands[1], 1, XFmode));
6972       emit_move_insn (operand_subword (operands[0], 2, 1, XFmode),
6973                       operand_subword_force (operands[1], 2, XFmode));
6975       insns = get_insns ();
6976       end_sequence ();
6978       emit_no_conflict_block (insns, operands[0], operands[1], 0, 0);
6979       DONE;
6980     }
6983 (define_insn "absxf2_68881"
6984   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6985         (abs:XF (match_operand:XF 1 "nonimmediate_operand" "fm")))]
6986   "TARGET_68881"
6988   if (REG_P (operands[1]) && ! DATA_REG_P (operands[1]))
6989     return "fabs%.x %1,%0";
6990   return "fabs%.x %f1,%0";
6993 (define_insn "sqrtxf2"
6994   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
6995         (sqrt:XF (match_operand:XF 1 "nonimmediate_operand" "fm")))]
6996   "TARGET_68881"
6997   "fsqrt%.x %1,%0")
6999 (define_insn "sinsf2"
7000   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
7001         (unspec:SF [(match_operand:SF 1 "general_operand" "fm")] UNSPEC_SIN))]
7002   "TARGET_68881 && flag_unsafe_math_optimizations"
7004   if (FP_REG_P (operands[1]))
7005     return "fsin%.x %1,%0";
7006   else
7007     return "fsin%.s %1,%0";
7010 (define_insn "sindf2"
7011   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
7012         (unspec:DF [(match_operand:DF 1 "general_operand" "fm")] UNSPEC_SIN))]
7013   "TARGET_68881 && flag_unsafe_math_optimizations"
7015   if (FP_REG_P (operands[1]))
7016     return "fsin%.x %1,%0";
7017   else
7018     return "fsin%.d %1,%0";
7021 (define_insn "sinxf2"
7022   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
7023         (unspec:XF [(match_operand:XF 1 "nonimmediate_operand" "fm")] UNSPEC_SIN))]
7024   "TARGET_68881 && flag_unsafe_math_optimizations"
7025   "fsin%.x %1,%0")
7027 (define_insn "cossf2"
7028   [(set (match_operand:SF 0 "nonimmediate_operand" "=f")
7029         (unspec:SF [(match_operand:SF 1 "general_operand" "fm")] UNSPEC_COS))]
7030   "TARGET_68881 && flag_unsafe_math_optimizations"
7032   if (FP_REG_P (operands[1]))
7033     return "fcos%.x %1,%0";
7034   else
7035     return "fcos%.s %1,%0";
7038 (define_insn "cosdf2"
7039   [(set (match_operand:DF 0 "nonimmediate_operand" "=f")
7040         (unspec:DF [(match_operand:DF 1 "general_operand" "fm")] UNSPEC_COS))]
7041   "TARGET_68881 && flag_unsafe_math_optimizations"
7043   if (FP_REG_P (operands[1]))
7044     return "fcos%.x %1,%0";
7045   else
7046     return "fcos%.d %1,%0";
7049 (define_insn "cosxf2"
7050   [(set (match_operand:XF 0 "nonimmediate_operand" "=f")
7051         (unspec:XF [(match_operand:XF 1 "nonimmediate_operand" "fm")] UNSPEC_COS))]
7052   "TARGET_68881 && flag_unsafe_math_optimizations"
7053   "fcos%.x %1,%0")
7055 (define_insn "trap"
7056   [(trap_if (const_int -1) (const_int 7))]
7057   ""
7058   "trap #7")
7060 (define_insn "conditional_trap"
7061   [(trap_if (match_operator 0 "valid_dbcc_comparison_p"
7062                             [(cc0) (const_int 0)])
7063             (match_operand:SI 1 "const_int_operand" "I"))]
7064   "TARGET_68020 && ! flags_in_68881 ()"
7066   switch (GET_CODE (operands[0]))
7067   {
7068   case EQ:  return "trapeq";
7069   case NE:  return "trapne";
7070   case GT:  return "trapgt";
7071   case GTU: return "traphi";
7072   case LT:  return "traplt";
7073   case LTU: return "trapcs";
7074   case GE:  return "trapge";
7075   case GEU: return "trapcc";
7076   case LE:  return "traple";
7077   case LEU: return "trapls";
7078   default: gcc_unreachable ();
7079   }