OSDN Git Service

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