OSDN Git Service

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