OSDN Git Service

Avoid problems with reloading fpul in HImode
[pf3gnuchains/gcc-fork.git] / gcc / config / sh / sh.md
1 ;;- Machine description for the Hitachi SH.
2 ;;  Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 ;;  Free Software Foundation, Inc.
4 ;;  Contributed by Steve Chamberlain (sac@cygnus.com).
5 ;;  Improved by Jim Wilson (wilson@cygnus.com).
6
7 ;; This file is part of GNU CC.
8
9 ;; GNU CC is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU CC is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU CC; see the file COPYING.  If not, write to
21 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24
25 ;; ??? Should prepend a * to all pattern names which are not used.
26 ;; This will make the compiler smaller, and rebuilds after changes faster.
27
28 ;; ??? Should be enhanced to include support for many more GNU superoptimizer
29 ;; sequences.  Especially the sequences for arithmetic right shifts.
30
31 ;; ??? Should check all DImode patterns for consistency and usefulness.
32
33 ;; ??? The MAC.W and MAC.L instructions are not supported.  There is no
34 ;; way to generate them.
35
36 ;; ??? The cmp/str instruction is not supported.  Perhaps it can be used
37 ;; for a str* inline function.
38
39 ;; BSR is not generated by the compiler proper, but when relaxing, it
40 ;; generates .uses pseudo-ops that allow linker relaxation to create
41 ;; BSR.  This is actually implemented in bfd/{coff,elf32}-sh.c
42
43 ;; Special constraints for SH machine description:
44 ;;
45 ;;    t -- T
46 ;;    x -- mac
47 ;;    l -- pr
48 ;;    z -- r0
49 ;;
50 ;; Special formats used for outputting SH instructions:
51 ;;
52 ;;   %.  --  print a .s if insn needs delay slot
53 ;;   %@  --  print rte/rts if is/isn't an interrupt function
54 ;;   %#  --  output a nop if there is nothing to put in the delay slot
55 ;;   %O  --  print a constant without the #
56 ;;   %R  --  print the lsw reg of a double
57 ;;   %S  --  print the msw reg of a double
58 ;;   %T  --  print next word of a double REG or MEM
59 ;;
60 ;; Special predicates:
61 ;;
62 ;;  arith_operand          -- operand is valid source for arithmetic op
63 ;;  arith_reg_operand      -- operand is valid register for arithmetic op
64 ;;  general_movdst_operand -- operand is valid move destination
65 ;;  general_movsrc_operand -- operand is valid move source
66 ;;  logical_operand        -- operand is valid source for logical op
67 ;; -------------------------------------------------------------------------
68 ;; Attributes
69 ;; -------------------------------------------------------------------------
70
71 ;; Target CPU.
72
73 (define_attr "cpu"
74  "sh1,sh2,sh3,sh3e,sh4"
75   (const (symbol_ref "sh_cpu_attr")))
76
77 (define_attr "endian" "big,little"
78  (const (if_then_else (symbol_ref "TARGET_LITTLE_ENDIAN")
79                       (const_string "little") (const_string "big"))))
80
81 ;; Indicate if the default fpu mode is single precision.
82 (define_attr "fpu_single" "yes,no"
83   (const (if_then_else (symbol_ref "TARGET_FPU_SINGLE")
84                          (const_string "yes") (const_string "no"))))
85
86 (define_attr "fmovd" "yes,no"
87   (const (if_then_else (symbol_ref "TARGET_FMOVD")
88                        (const_string "yes") (const_string "no"))))
89 ;; issues/clock
90 (define_attr "issues" "1,2"
91   (const (if_then_else (symbol_ref "TARGET_SUPERSCALAR") (const_string "2") (const_string "1"))))
92
93 ;; cbranch      conditional branch instructions
94 ;; jump         unconditional jumps
95 ;; arith        ordinary arithmetic
96 ;; arith3       a compound insn that behaves similarly to a sequence of
97 ;;              three insns of type arith
98 ;; arith3b      like above, but might end with a redirected branch
99 ;; load         from memory
100 ;; load_si      Likewise, SImode variant for general register.
101 ;; store        to memory
102 ;; move         register to register
103 ;; fmove        register to register, floating point
104 ;; smpy         word precision integer multiply
105 ;; dmpy         longword or doublelongword precision integer multiply
106 ;; return       rts
107 ;; pload        load of pr reg, which can't be put into delay slot of rts
108 ;; pstore       store of pr reg, which can't be put into delay slot of jsr
109 ;; pcload       pc relative load of constant value
110 ;; pcload_si    Likewise, SImode variant for general register.
111 ;; rte          return from exception
112 ;; sfunc        special function call with known used registers
113 ;; call         function call
114 ;; fp           floating point
115 ;; fdiv         floating point divide (or square root)
116 ;; gp_fpul      move between general purpose register and fpul
117 ;; dfp_arith, dfp_cmp,dfp_conv
118 ;; dfdiv        double precision floating point divide (or square root)
119 ;; nil          no-op move, will be deleted.
120
121 (define_attr "type"
122  "cbranch,jump,jump_ind,arith,arith3,arith3b,dyn_shift,other,load,load_si,store,move,fmove,smpy,dmpy,return,pload,pstore,pcload,pcload_si,rte,sfunc,call,fp,fdiv,dfp_arith,dfp_cmp,dfp_conv,dfdiv,gp_fpul,nil"
123   (const_string "other"))
124
125 ;; Indicate what precision must be selected in fpscr for this insn, if any.
126
127 (define_attr "fp_mode" "single,double,none" (const_string "none"))
128
129 ; If a conditional branch destination is within -252..258 bytes away
130 ; from the instruction it can be 2 bytes long.  Something in the
131 ; range -4090..4100 bytes can be 6 bytes long.  All other conditional
132 ; branches are initially assumed to be 16 bytes long.
133 ; In machine_dependent_reorg, we split all branches that are longer than
134 ; 2 bytes.
135
136 ;; The maximum range used for SImode constant pool entrys is 1018.  A final
137 ;; instruction can add 8 bytes while only being 4 bytes in size, thus we
138 ;; can have a total of 1022 bytes in the pool.  Add 4 bytes for a branch
139 ;; instruction around the pool table, 2 bytes of alignment before the table,
140 ;; and 30 bytes of alignment after the table.  That gives a maximum total
141 ;; pool size of 1058 bytes.
142 ;; Worst case code/pool content size ratio is 1:2 (using asms).
143 ;; Thus, in the worst case, there is one instruction in front of a maximum
144 ;; sized pool, and then there are 1052 bytes of pool for every 508 bytes of
145 ;; code.  For the last n bytes of code, there are 2n + 36 bytes of pool.
146 ;; If we have a forward branch, the initial table will be put after the
147 ;; unconditional branch.
148 ;;
149 ;; ??? We could do much better by keeping track of the actual pcloads within
150 ;; the branch range and in the pcload range in front of the branch range.
151
152 ;; ??? This looks ugly because genattrtab won't allow if_then_else or cond
153 ;; inside an le.
154 (define_attr "short_cbranch_p" "no,yes"
155   (cond [(ne (symbol_ref "mdep_reorg_phase <= SH_FIXUP_PCLOAD") (const_int 0))
156          (const_string "no")
157          (leu (plus (minus (match_dup 0) (pc)) (const_int 252)) (const_int 506))
158          (const_string "yes")
159          (ne (symbol_ref "NEXT_INSN (PREV_INSN (insn)) != insn") (const_int 0))
160          (const_string "no")
161          (leu (plus (minus (match_dup 0) (pc)) (const_int 252)) (const_int 508))
162          (const_string "yes")
163          ] (const_string "no")))
164
165 (define_attr "med_branch_p" "no,yes"
166   (cond [(leu (plus (minus (match_dup 0) (pc)) (const_int 990))
167               (const_int 1988))
168          (const_string "yes")
169          (ne (symbol_ref "mdep_reorg_phase <= SH_FIXUP_PCLOAD") (const_int 0))
170          (const_string "no")
171          (leu (plus (minus (match_dup 0) (pc)) (const_int 4092))
172               (const_int 8186))
173          (const_string "yes")
174          ] (const_string "no")))
175
176 (define_attr "med_cbranch_p" "no,yes"
177   (cond [(leu (plus (minus (match_dup 0) (pc)) (const_int 988))
178               (const_int 1986))
179          (const_string "yes")
180          (ne (symbol_ref "mdep_reorg_phase <= SH_FIXUP_PCLOAD") (const_int 0))
181          (const_string "no")
182          (leu (plus (minus (match_dup 0) (pc)) (const_int 4090))
183                (const_int 8184))
184          (const_string "yes")
185          ] (const_string "no")))
186
187 (define_attr "braf_branch_p" "no,yes"
188   (cond [(ne (symbol_ref "! TARGET_SH2") (const_int 0))
189          (const_string "no")
190          (leu (plus (minus (match_dup 0) (pc)) (const_int 10330))
191               (const_int 20660))
192          (const_string "yes")
193          (ne (symbol_ref "mdep_reorg_phase <= SH_FIXUP_PCLOAD") (const_int 0))
194          (const_string "no")
195          (leu (plus (minus (match_dup 0) (pc)) (const_int 32764))
196               (const_int 65530))
197          (const_string "yes")
198          ] (const_string "no")))
199
200 (define_attr "braf_cbranch_p" "no,yes"
201   (cond [(ne (symbol_ref "! TARGET_SH2") (const_int 0))
202          (const_string "no")
203          (leu (plus (minus (match_dup 0) (pc)) (const_int 10328))
204               (const_int 20658))
205          (const_string "yes")
206          (ne (symbol_ref "mdep_reorg_phase <= SH_FIXUP_PCLOAD") (const_int 0))
207          (const_string "no")
208          (leu (plus (minus (match_dup 0) (pc)) (const_int 32762))
209               (const_int 65528))
210          (const_string "yes")
211          ] (const_string "no")))
212
213 ; An unconditional jump in the range -4092..4098 can be 2 bytes long.
214 ; For wider ranges, we need a combination of a code and a data part.
215 ; If we can get a scratch register for a long range jump, the code
216 ; part can be 4 bytes long; otherwise, it must be 8 bytes long.
217 ; If the jump is in the range -32764..32770, the data part can be 2 bytes
218 ; long; otherwise, it must be 6 bytes long.
219
220 ; All other instructions are two bytes long by default.
221
222 ;; ??? This should use something like *branch_p (minus (match_dup 0) (pc)),
223 ;; but getattrtab doesn't understand this.
224 (define_attr "length" ""
225   (cond [(eq_attr "type" "cbranch")
226          (cond [(eq_attr "short_cbranch_p" "yes")
227                 (const_int 2)
228                 (eq_attr "med_cbranch_p" "yes")
229                 (const_int 6)
230                 (eq_attr "braf_cbranch_p" "yes")
231                 (const_int 12)
232 ;; ??? using pc is not computed transitively.
233                 (ne (match_dup 0) (match_dup 0))
234                 (const_int 14)
235                 ] (const_int 16))
236          (eq_attr "type" "jump")
237          (cond [(eq_attr "med_branch_p" "yes")
238                 (const_int 2)
239                 (and (eq (symbol_ref "GET_CODE (PREV_INSN (insn))")
240                          (symbol_ref "INSN"))
241                      (eq (symbol_ref "INSN_CODE (PREV_INSN (insn))")
242                          (symbol_ref "code_for_indirect_jump_scratch")))
243                 (if_then_else (eq_attr "braf_branch_p" "yes")
244                               (const_int 6)
245                               (const_int 10))
246                 (eq_attr "braf_branch_p" "yes")
247                 (const_int 10)
248 ;; ??? using pc is not computed transitively.
249                 (ne (match_dup 0) (match_dup 0))
250                 (const_int 12)
251                 ] (const_int 14))
252          ] (const_int 2)))
253
254 ;; (define_function_unit {name} {num-units} {n-users} {test}
255 ;;                       {ready-delay} {issue-delay} [{conflict-list}])
256
257 ;; Load and store instructions save a cycle if they are aligned on a
258 ;; four byte boundary.  Using a function unit for stores encourages
259 ;; gcc to separate load and store instructions by one instruction,
260 ;; which makes it more likely that the linker will be able to word
261 ;; align them when relaxing.
262
263 ;; Loads have a latency of two.
264 ;; However, call insns can have a delay slot, so that we want one more
265 ;; insn to be scheduled between the load of the function address and the call.
266 ;; This is equivalent to a latency of three.
267 ;; We cannot use a conflict list for this, because we need to distinguish
268 ;; between the actual call address and the function arguments.
269 ;; ADJUST_COST can only properly handle reductions of the cost, so we
270 ;; use a latency of three here.
271 ;; We only do this for SImode loads of general registers, to make the work
272 ;; for ADJUST_COST easier.
273 (define_function_unit "memory" 1 0
274   (and (eq_attr "issues" "1")
275        (eq_attr "type" "load_si,pcload_si"))
276   3 2)
277 (define_function_unit "memory" 1 0
278   (and (eq_attr "issues" "1")
279        (eq_attr "type" "load,pcload,pload,store,pstore"))
280   2 2)
281
282 (define_function_unit "int"    1 0
283   (and (eq_attr "issues" "1") (eq_attr "type" "arith3,arith3b")) 3 3)
284
285 (define_function_unit "int"    1 0
286   (and (eq_attr "issues" "1") (eq_attr "type" "dyn_shift")) 2 2)
287
288 (define_function_unit "int"    1 0
289   (and (eq_attr "issues" "1") (eq_attr "type" "!arith3,arith3b,dyn_shift")) 1 1)
290
291 ;; ??? These are approximations.
292 (define_function_unit "mpy"    1 0
293   (and (eq_attr "issues" "1") (eq_attr "type" "smpy")) 2 2)
294 (define_function_unit "mpy"    1 0
295   (and (eq_attr "issues" "1") (eq_attr "type" "dmpy")) 3 3)
296
297 (define_function_unit "fp"     1 0
298   (and (eq_attr "issues" "1") (eq_attr "type" "fp,fmove")) 2 1)
299 (define_function_unit "fp"     1 0
300   (and (eq_attr "issues" "1") (eq_attr "type" "fdiv")) 13 12)
301
302
303 ;; SH4 scheduling
304 ;; The SH4 is a dual-issue implementation, thus we have to multiply all
305 ;; costs by at least two.
306 ;; There will be single increments of the modeled that don't correspond
307 ;; to the actual target ;; whenever two insns to be issued depend one a
308 ;; single resource, and the scheduler picks to be the first one.
309 ;; If we multiplied the costs just by two, just two of these single
310 ;; increments would amount to an actual cycle.  By picking a larger
311 ;; factor, we can ameliorate the effect; However, we then have to make sure
312 ;; that only two insns are modeled as issued per actual cycle.
313 ;; Moreover, we need a way to specify the latency of insns that don't
314 ;; use an actual function unit.
315 ;; We use an 'issue' function unit to do that, and a cost factor of 10.
316
317 (define_function_unit "issue" 2 0
318   (and (eq_attr "issues" "2") (eq_attr "type" "!nil,arith3"))
319   10 10)
320
321 (define_function_unit "issue" 2 0
322   (and (eq_attr "issues" "2") (eq_attr "type" "arith3"))
323   30 30)
324
325 ;; There is no point in providing exact scheduling information about branches,
326 ;; because they are at the starts / ends of basic blocks anyways.
327
328 ;; Some insns cannot be issued before/after another insn in the same cycle,
329 ;; irrespective of the type of the other insn.
330
331 ;; default is dual-issue, but can't be paired with an insn that
332 ;; uses multiple function units.
333 (define_function_unit "single_issue"     1 0
334   (and (eq_attr "issues" "2")
335        (eq_attr "type" "!smpy,dmpy,pload,pstore,dfp_cmp,gp_fpul,call,sfunc,arith3,arith3b"))
336   1 10
337   [(eq_attr "type" "smpy,dmpy,pload,pstore,dfp_cmp,gp_fpul")])
338
339 (define_function_unit "single_issue"     1 0
340   (and (eq_attr "issues" "2")
341        (eq_attr "type" "smpy,dmpy,pload,pstore,dfp_cmp,gp_fpul"))
342   10 10
343   [(const_int 1)])
344
345 ;; arith3 insns are always pairable at the start, but not inecessarily at
346 ;; the end; however, there doesn;t seem to be a way to express that.
347 (define_function_unit "single_issue"     1 0
348   (and (eq_attr "issues" "2")
349        (eq_attr "type" "arith3"))
350   30 20
351   [(const_int 1)])
352
353 ;; arith3b insn are pairable at the end and have latency that prevents pairing
354 ;; with the following branch, but we don't want this latency be respected;
355 ;; When the following branch is immediately adjacent, we can redirect the
356 ;; internal branch, which is likly to be a larger win.
357 (define_function_unit "single_issue"     1 0
358   (and (eq_attr "issues" "2")
359        (eq_attr "type" "arith3b"))
360   20 20
361   [(const_int 1)])
362
363 ;; calls introduce a longisch delay that is likely to flush the pipelines.
364 (define_function_unit "single_issue"     1 0
365   (and (eq_attr "issues" "2")
366        (eq_attr "type" "call,sfunc"))
367   160 160
368   [(eq_attr "type" "!call") (eq_attr "type" "call")])
369
370 ;; Load and store instructions have no alignment peculiarities for the SH4,
371 ;; but they use the load-store unit, which they share with the fmove type
372 ;; insns (fldi[01]; fmov frn,frm; flds; fsts; fabs; fneg) .
373 ;; Loads have a latency of two.
374 ;; However, call insns can only paired with a preceding insn, and have
375 ;; a delay slot, so that we want two more insns to be scheduled between the
376 ;; load of the function address and the call.  This is equivalent to a
377 ;; latency of three.
378 ;; We cannot use a conflict list for this, because we need to distinguish
379 ;; between the actual call address and the function arguments.
380 ;; ADJUST_COST can only properly handle reductions of the cost, so we
381 ;; use a latency of three here, which gets multiplied by 10 to yield 30.
382 ;; We only do this for SImode loads of general registers, to make the work
383 ;; for ADJUST_COST easier.
384
385 ;; When specifying different latencies for different insns using the
386 ;; the same function unit, genattrtab.c assumes a 'FIFO constraint'
387 ;; so that the blockage is at least READY-COST (E) + 1 - READY-COST (C)
388 ;; for an executing insn E and a candidate insn C.
389 ;; Therefore, we define three different function units for load_store:
390 ;; load_store, load and load_si.
391
392 (define_function_unit "load_si" 1 0
393   (and (eq_attr "issues" "2")
394        (eq_attr "type" "load_si,pcload_si")) 30 10)
395 (define_function_unit "load" 1 0
396   (and (eq_attr "issues" "2")
397        (eq_attr "type" "load,pcload,pload")) 20 10)
398 (define_function_unit "load_store" 1 0
399   (and (eq_attr "issues" "2")
400        (eq_attr "type" "load_si,pcload_si,load,pcload,pload,store,pstore,fmove"))
401   10 10)
402
403 (define_function_unit "int"    1 0
404   (and (eq_attr "issues" "2") (eq_attr "type" "arith,dyn_shift")) 10 10)
405
406 ;; Again, we have to pretend a lower latency for the "int" unit to avoid a
407 ;; spurious FIFO constraint; the multiply instructions use the "int"
408 ;; unit actually only for two cycles.
409 (define_function_unit "int"    1 0
410   (and (eq_attr "issues" "2") (eq_attr "type" "smpy,dmpy")) 20 20)
411
412 ;; We use a fictous "mpy" unit to express the actual latency.
413 (define_function_unit "mpy"    1 0
414   (and (eq_attr "issues" "2") (eq_attr "type" "smpy,dmpy")) 40 20)
415
416 ;; Again, we have to pretend a lower latency for the "int" unit to avoid a
417 ;; spurious FIFO constraint.
418 (define_function_unit "int"     1 0
419   (and (eq_attr "issues" "2") (eq_attr "type" "gp_fpul")) 10 10)
420
421 ;; We use a fictous "gp_fpul" unit to express the actual latency.
422 (define_function_unit "gp_fpul"     1 0
423   (and (eq_attr "issues" "2") (eq_attr "type" "gp_fpul")) 20 10)
424
425 ;; ??? multiply uses the floating point unit, but with a two cycle delay.
426 ;; Thus, a simple single-precision fp operation could finish if issued in
427 ;; the very next cycle, but stalls when issued two or three cycles later.
428 ;; Similarily, a divide / sqrt can work without stalls if issued in
429 ;; the very next cycle, while it would have to block if issued two or
430 ;; three cycles later.
431 ;; There is no way to model this with gcc's function units.  This problem is
432 ;; actually mentioned in md.texi.  Tackling this problem requires first that
433 ;; it is possible to speak about the target in an open discussion.
434 ;; 
435 ;; However, simple double-precision operations always conflict.
436
437 (define_function_unit "fp"    1 0
438   (and (eq_attr "issues" "2") (eq_attr "type" "smpy,dmpy")) 40 40
439   [(eq_attr "type" "dfp_cmp,dfp_conv,dfp_arith")])
440
441 ;; The "fp" unit is for pipeline stages F1 and F2.
442
443 (define_function_unit "fp"     1 0
444   (and (eq_attr "issues" "2") (eq_attr "type" "fp")) 30 10)
445
446 ;; Again, we have to pretend a lower latency for the "fp" unit to avoid a
447 ;; spurious FIFO constraint; the bulk of the fdiv type insns executes in
448 ;; the F3 stage.
449 (define_function_unit "fp"     1 0
450   (and (eq_attr "issues" "2") (eq_attr "type" "fdiv")) 30 10)
451
452 ;; The "fdiv" function unit models the aggregate effect of the F1, F2 and F3
453 ;; pipeline stages on the pipelining of fdiv/fsqrt insns.
454 ;; We also use it to give the actual latency here.
455 ;; fsqrt is actually one cycle faster than fdiv (and the value used here),
456 ;; but that will hardly matter in practice for scheduling.
457 (define_function_unit "fdiv"     1 0
458   (and (eq_attr "issues" "2") (eq_attr "type" "fdiv")) 120 100)
459
460 ;; There is again a late use of the "fp" unit by [d]fdiv type insns
461 ;; that we can't express.
462
463 (define_function_unit "fp"     1 0
464   (and (eq_attr "issues" "2") (eq_attr "type" "dfp_cmp,dfp_conv")) 40 20)
465
466 (define_function_unit "fp"     1 0
467   (and (eq_attr "issues" "2") (eq_attr "type" "dfp_arith")) 80 60)
468
469 (define_function_unit "fp"     1 0
470   (and (eq_attr "issues" "2") (eq_attr "type" "dfdiv")) 230 10)
471
472 (define_function_unit "fdiv"     1 0
473   (and (eq_attr "issues" "2") (eq_attr "type" "dfdiv")) 230 210)
474
475 ; Definitions for filling branch delay slots.
476
477 (define_attr "needs_delay_slot" "yes,no" (const_string "no"))
478
479 ;; ??? This should be (nil) instead of (const_int 0)
480 (define_attr "hit_stack" "yes,no"
481         (cond [(eq (symbol_ref "find_regno_note (insn, REG_INC, 15)") (const_int 0))
482                (const_string "no")]
483               (const_string "yes")))
484
485 (define_attr "interrupt_function" "no,yes"
486   (const (symbol_ref "pragma_interrupt")))
487
488 (define_attr "in_delay_slot" "yes,no"
489   (cond [(eq_attr "type" "cbranch") (const_string "no")
490          (eq_attr "type" "pcload,pcload_si") (const_string "no")
491          (eq_attr "needs_delay_slot" "yes") (const_string "no")
492          (eq_attr "length" "2") (const_string "yes")
493          ] (const_string "no")))
494
495 (define_attr "is_sfunc" ""
496   (if_then_else (eq_attr "type" "sfunc") (const_int 1) (const_int 0)))
497
498 (define_delay
499   (eq_attr "needs_delay_slot" "yes")
500   [(eq_attr "in_delay_slot" "yes") (nil) (nil)])
501
502 ;; On the SH and SH2, the rte instruction reads the return pc from the stack,
503 ;; and thus we can't put a pop instruction in its delay slot.
504 ;; ??? On the SH3, the rte instruction does not use the stack, so a pop
505 ;; instruction can go in the delay slot.
506
507 ;; Since a normal return (rts) implicitly uses the PR register,
508 ;; we can't allow PR register loads in an rts delay slot.
509
510 (define_delay
511   (eq_attr "type" "return")
512   [(and (eq_attr "in_delay_slot" "yes")
513         (ior (and (eq_attr "interrupt_function" "no")
514                   (eq_attr "type" "!pload"))
515              (and (eq_attr "interrupt_function" "yes")
516                   (eq_attr "hit_stack" "no")))) (nil) (nil)])
517
518 ;; Since a call implicitly uses the PR register, we can't allow
519 ;; a PR register store in a jsr delay slot.
520
521 (define_delay
522   (ior (eq_attr "type" "call") (eq_attr "type" "sfunc"))
523   [(and (eq_attr "in_delay_slot" "yes")
524         (eq_attr "type" "!pstore")) (nil) (nil)])
525
526 ;; Say that we have annulled true branches, since this gives smaller and
527 ;; faster code when branches are predicted as not taken.
528
529 (define_delay
530   (and (eq_attr "type" "cbranch")
531        (ne (symbol_ref "TARGET_SH2") (const_int 0)))
532   [(eq_attr "in_delay_slot" "yes") (eq_attr "in_delay_slot" "yes") (nil)])
533 \f
534 ;; -------------------------------------------------------------------------
535 ;; SImode signed integer comparisons
536 ;; -------------------------------------------------------------------------
537
538 (define_insn ""
539   [(set (reg:SI 18)
540         (eq:SI (and:SI (match_operand:SI 0 "arith_reg_operand" "z,r")
541                        (match_operand:SI 1 "arith_operand" "L,r"))
542                (const_int 0)))]
543   ""
544   "tst  %1,%0")
545
546 ;; ??? Perhaps should only accept reg/constant if the register is reg 0.
547 ;; That would still allow reload to create cmpi instructions, but would
548 ;; perhaps allow forcing the constant into a register when that is better.
549 ;; Probably should use r0 for mem/imm compares, but force constant into a
550 ;; register for pseudo/imm compares.
551
552 (define_insn "cmpeqsi_t"
553   [(set (reg:SI 18) (eq:SI (match_operand:SI 0 "arith_reg_operand" "r,z,r")
554                            (match_operand:SI 1 "arith_operand" "N,rI,r")))]
555   ""
556   "@
557         tst     %0,%0
558         cmp/eq  %1,%0
559         cmp/eq  %1,%0")
560
561 (define_insn "cmpgtsi_t"
562   [(set (reg:SI 18) (gt:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
563                            (match_operand:SI 1 "arith_reg_or_0_operand" "r,N")))]
564   ""
565   "@
566         cmp/gt  %1,%0
567         cmp/pl  %0")
568
569 (define_insn "cmpgesi_t"
570   [(set (reg:SI 18) (ge:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
571                            (match_operand:SI 1 "arith_reg_or_0_operand" "r,N")))]
572   ""
573   "@
574         cmp/ge  %1,%0
575         cmp/pz  %0")
576 \f
577 ;; -------------------------------------------------------------------------
578 ;; SImode unsigned integer comparisons
579 ;; -------------------------------------------------------------------------
580
581 (define_insn "cmpgeusi_t"
582   [(set (reg:SI 18) (geu:SI (match_operand:SI 0 "arith_reg_operand" "r")
583                             (match_operand:SI 1 "arith_reg_operand" "r")))]
584   ""
585   "cmp/hs       %1,%0")
586
587 (define_insn "cmpgtusi_t"
588   [(set (reg:SI 18) (gtu:SI (match_operand:SI 0 "arith_reg_operand" "r")
589                             (match_operand:SI 1 "arith_reg_operand" "r")))]
590   ""
591   "cmp/hi       %1,%0")
592
593 ;; We save the compare operands in the cmpxx patterns and use them when
594 ;; we generate the branch.
595
596 (define_expand "cmpsi"
597   [(set (reg:SI 18) (compare (match_operand:SI 0 "arith_operand" "")
598                              (match_operand:SI 1 "arith_operand" "")))]
599   ""
600   "
601 {
602   sh_compare_op0 = operands[0];
603   sh_compare_op1 = operands[1];
604   DONE;
605 }")
606 \f
607 ;; -------------------------------------------------------------------------
608 ;; DImode signed integer comparisons
609 ;; -------------------------------------------------------------------------
610
611 ;; ??? Could get better scheduling by splitting the initial test from the
612 ;; rest of the insn after reload.  However, the gain would hardly justify
613 ;; the sh.md size increase necessary to do that.
614
615 (define_insn ""
616   [(set (reg:SI 18)
617         (eq:SI (and:DI (match_operand:DI 0 "arith_reg_operand" "r")
618                        (match_operand:DI 1 "arith_operand" "r"))
619                (const_int 0)))]
620   ""
621   "* return output_branchy_insn (EQ, \"tst\\t%S1,%S0\;bf\\t%l9\;tst\\t%R1,%R0\",
622                                  insn, operands);"
623   [(set_attr "length" "6")
624    (set_attr "type" "arith3b")])
625
626 (define_insn "cmpeqdi_t"
627   [(set (reg:SI 18) (eq:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
628                            (match_operand:DI 1 "arith_reg_or_0_operand" "N,r")))]
629   ""
630   "@
631         tst     %S0,%S0\;bf     %,Ldi%=\;tst    %R0,%R0\\n%,Ldi%=:
632         cmp/eq  %S1,%S0\;bf     %,Ldi%=\;cmp/eq %R1,%R0\\n%,Ldi%=:"
633   [(set_attr "length" "6")
634    (set_attr "type" "arith3b")])
635
636 (define_split
637   [(set (reg:SI 18) (eq:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
638                            (match_operand:DI 1 "arith_reg_or_0_operand" "N,r")))]
639 ;; If we applied this split when not optimizing, it would only be
640 ;; applied during the machine-dependent reorg, when no new basic blocks
641 ;; may be created.
642   "reload_completed && optimize"
643   [(set (reg:SI 18) (eq:SI (match_dup 2) (match_dup 3)))
644    (set (pc) (if_then_else (eq (reg:SI 18) (const_int 0))
645                            (label_ref (match_dup 6))
646                            (pc)))
647    (set (reg:SI 18) (eq:SI (match_dup 4) (match_dup 5)))
648    (match_dup 6)]
649   "
650 {
651   operands[2]
652     = gen_rtx_REG (SImode,
653                    true_regnum (operands[0]) + (TARGET_LITTLE_ENDIAN ? 1 : 0));
654   operands[3]
655     = (operands[1] == const0_rtx
656        ? const0_rtx
657        : gen_rtx_REG (SImode,
658                       true_regnum (operands[1])
659                       + (TARGET_LITTLE_ENDIAN ? 1 : 0)));
660   operands[4] = gen_lowpart (SImode, operands[0]);
661   operands[5] = gen_lowpart (SImode, operands[1]);
662   operands[6] = gen_label_rtx ();
663 }")
664
665 (define_insn "cmpgtdi_t"
666   [(set (reg:SI 18) (gt:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
667                            (match_operand:DI 1 "arith_reg_or_0_operand" "r,N")))]
668   "TARGET_SH2"
669   "@
670         cmp/eq\\t%S1,%S0\;bf{.|/}s\\t%,Ldi%=\;cmp/gt\\t%S1,%S0\;cmp/hi\\t%R1,%R0\\n%,Ldi%=:
671         tst\\t%S0,%S0\;bf{.|/}s\\t%,Ldi%=\;cmp/pl\\t%S0\;cmp/hi\\t%S0,%R0\\n%,Ldi%=:"
672   [(set_attr "length" "8")
673    (set_attr "type" "arith3")])
674
675 (define_insn "cmpgedi_t"
676   [(set (reg:SI 18) (ge:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
677                            (match_operand:DI 1 "arith_reg_or_0_operand" "r,N")))]
678   "TARGET_SH2"
679   "@
680         cmp/eq\\t%S1,%S0\;bf{.|/}s\\t%,Ldi%=\;cmp/ge\\t%S1,%S0\;cmp/hs\\t%R1,%R0\\n%,Ldi%=:
681         cmp/pz\\t%S0"
682   [(set_attr "length" "8,2")
683    (set_attr "type" "arith3,arith")])
684 \f
685 ;; -------------------------------------------------------------------------
686 ;; DImode unsigned integer comparisons
687 ;; -------------------------------------------------------------------------
688
689 (define_insn "cmpgeudi_t"
690   [(set (reg:SI 18) (geu:SI (match_operand:DI 0 "arith_reg_operand" "r")
691                             (match_operand:DI 1 "arith_reg_operand" "r")))]
692   "TARGET_SH2"
693   "cmp/eq\\t%S1,%S0\;bf{.|/}s\\t%,Ldi%=\;cmp/hs\\t%S1,%S0\;cmp/hs\\t%R1,%R0\\n%,Ldi%=:"
694   [(set_attr "length" "8")
695    (set_attr "type" "arith3")])
696
697 (define_insn "cmpgtudi_t"
698   [(set (reg:SI 18) (gtu:SI (match_operand:DI 0 "arith_reg_operand" "r")
699                             (match_operand:DI 1 "arith_reg_operand" "r")))]
700   "TARGET_SH2"
701   "cmp/eq\\t%S1,%S0\;bf{.|/}s\\t%,Ldi%=\;cmp/hi\\t%S1,%S0\;cmp/hi\\t%R1,%R0\\n%,Ldi%=:"
702   [(set_attr "length" "8")
703    (set_attr "type" "arith3")])
704
705 ;; We save the compare operands in the cmpxx patterns and use them when
706 ;; we generate the branch.
707
708 (define_expand "cmpdi"
709   [(set (reg:SI 18) (compare (match_operand:DI 0 "arith_operand" "")
710                              (match_operand:DI 1 "arith_operand" "")))]
711   "TARGET_SH2"
712   "
713 {
714   sh_compare_op0 = operands[0];
715   sh_compare_op1 = operands[1];
716   DONE;
717 }")
718 \f
719 ;; -------------------------------------------------------------------------
720 ;; Addition instructions
721 ;; -------------------------------------------------------------------------
722
723 ;; ??? This should be a define expand.
724
725 (define_insn "adddi3"
726   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
727         (plus:DI (match_operand:DI 1 "arith_reg_operand" "%0")
728                  (match_operand:DI 2 "arith_reg_operand" "r")))
729    (clobber (reg:SI 18))]
730   ""
731   "#"
732   [(set_attr "length" "6")])
733
734 (define_split
735   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
736         (plus:DI (match_operand:DI 1 "arith_reg_operand" "%0")
737                  (match_operand:DI 2 "arith_reg_operand" "r")))
738    (clobber (reg:SI 18))]
739   "reload_completed"
740   [(const_int 0)]
741   "
742 {
743   rtx high0, high2, low0 = gen_lowpart (SImode, operands[0]);
744   high0 = gen_rtx_REG (SImode,
745                        true_regnum (operands[0])
746                        + (TARGET_LITTLE_ENDIAN ? 1 : 0));
747   high2 = gen_rtx_REG (SImode,
748                        true_regnum (operands[2])
749                        + (TARGET_LITTLE_ENDIAN ? 1 : 0));
750   emit_insn (gen_clrt ());
751   emit_insn (gen_addc (low0, low0, gen_lowpart (SImode, operands[2])));
752   emit_insn (gen_addc1 (high0, high0, high2));
753   DONE;
754 }")
755
756 (define_insn "addc"
757   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
758         (plus:SI (plus:SI (match_operand:SI 1 "arith_reg_operand" "0")
759                           (match_operand:SI 2 "arith_reg_operand" "r"))
760                  (reg:SI 18)))
761    (set (reg:SI 18)
762         (ltu:SI (plus:SI (match_dup 1) (match_dup 2)) (match_dup 1)))]
763   ""
764   "addc %2,%0"
765   [(set_attr "type" "arith")])
766
767 (define_insn "addc1"
768   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
769         (plus:SI (plus:SI (match_operand:SI 1 "arith_reg_operand" "0")
770                           (match_operand:SI 2 "arith_reg_operand" "r"))
771                  (reg:SI 18)))
772    (clobber (reg:SI 18))]
773   ""
774   "addc %2,%0"
775   [(set_attr "type" "arith")])
776
777 (define_insn "addsi3"
778   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
779         (plus:SI (match_operand:SI 1 "arith_operand" "%0")
780                  (match_operand:SI 2 "arith_operand" "rI")))]
781   ""
782   "add  %2,%0"
783   [(set_attr "type" "arith")])
784 \f
785 ;; -------------------------------------------------------------------------
786 ;; Subtraction instructions
787 ;; -------------------------------------------------------------------------
788
789 ;; ??? This should be a define expand.
790
791 (define_insn "subdi3"
792   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
793         (minus:DI (match_operand:DI 1 "arith_reg_operand" "0")
794                  (match_operand:DI 2 "arith_reg_operand" "r")))
795    (clobber (reg:SI 18))]
796   ""
797   "#"
798   [(set_attr "length" "6")])
799
800 (define_split
801   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
802         (minus:DI (match_operand:DI 1 "arith_reg_operand" "0")
803                   (match_operand:DI 2 "arith_reg_operand" "r")))
804    (clobber (reg:SI 18))]
805   "reload_completed"
806   [(const_int 0)]
807   "
808 {
809   rtx high0, high2, low0 = gen_lowpart (SImode, operands[0]);
810   high0 = gen_rtx_REG (SImode,
811                        true_regnum (operands[0])
812                        + (TARGET_LITTLE_ENDIAN ? 1 : 0));
813   high2 = gen_rtx_REG (SImode,
814                        true_regnum (operands[2])
815                        + (TARGET_LITTLE_ENDIAN ? 1 : 0));
816   emit_insn (gen_clrt ());
817   emit_insn (gen_subc (low0, low0, gen_lowpart (SImode, operands[2])));
818   emit_insn (gen_subc1 (high0, high0, high2));
819   DONE;
820 }")
821
822 (define_insn "subc"
823   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
824         (minus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
825                             (match_operand:SI 2 "arith_reg_operand" "r"))
826                   (reg:SI 18)))
827    (set (reg:SI 18)
828         (gtu:SI (minus:SI (match_dup 1) (match_dup 2)) (match_dup 1)))]
829   ""
830   "subc %2,%0"
831   [(set_attr "type" "arith")])
832
833 (define_insn "subc1"
834   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
835         (minus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
836                             (match_operand:SI 2 "arith_reg_operand" "r"))
837                   (reg:SI 18)))
838    (clobber (reg:SI 18))]
839   ""
840   "subc %2,%0"
841   [(set_attr "type" "arith")])
842
843 (define_insn "*subsi3_internal"
844   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
845         (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
846                   (match_operand:SI 2 "arith_reg_operand" "r")))]
847   ""
848   "sub  %2,%0"
849   [(set_attr "type" "arith")])
850
851 ;; Convert `constant - reg' to `neg rX; add rX, #const' since this
852 ;; will sometimes save one instruction.  Otherwise we might get
853 ;; `mov #const, rY; sub rY,rX; mov rX, rY' if the source and dest regs
854 ;; are the same.
855
856 (define_expand "subsi3"
857   [(set (match_operand:SI 0 "arith_reg_operand" "")
858         (minus:SI (match_operand:SI 1 "arith_operand" "")
859                   (match_operand:SI 2 "arith_reg_operand" "")))]
860   ""
861   "
862 {
863   if (GET_CODE (operands[1]) == CONST_INT)
864     {
865       emit_insn (gen_negsi2 (operands[0], operands[2]));
866       emit_insn (gen_addsi3 (operands[0], operands[0], operands[1]));
867       DONE;
868     }
869 }")
870 \f
871 ;; -------------------------------------------------------------------------
872 ;; Division instructions
873 ;; -------------------------------------------------------------------------
874
875 ;; We take advantage of the library routines which don't clobber as many
876 ;; registers as a normal function call would.
877
878 ;; The INSN_REFERENCES_ARE_DELAYED in sh.h is problematic because it
879 ;; also has an effect on the register that holds the address of the sfunc.
880 ;; To make this work, we have an extra dummy insns that shows the use
881 ;; of this register for reorg.
882
883 (define_insn "use_sfunc_addr"
884   [(set (reg:SI 17) (unspec [(match_operand:SI 0 "register_operand" "r")] 5))]
885   ""
886   ""
887   [(set_attr "length" "0")])
888
889 ;; We must use a pseudo-reg forced to reg 0 in the SET_DEST rather than
890 ;; hard register 0.  If we used hard register 0, then the next instruction
891 ;; would be a move from hard register 0 to a pseudo-reg.  If the pseudo-reg
892 ;; gets allocated to a stack slot that needs its address reloaded, then
893 ;; there is nothing to prevent reload from using r0 to reload the address.
894 ;; This reload would clobber the value in r0 we are trying to store.
895 ;; If we let reload allocate r0, then this problem can never happen.
896
897 (define_insn "udivsi3_i1"
898   [(set (match_operand:SI 0 "register_operand" "=z")
899         (udiv:SI (reg:SI 4) (reg:SI 5)))
900    (clobber (reg:SI 18))
901    (clobber (reg:SI 17))
902    (clobber (reg:SI 4))
903    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
904   "! TARGET_SH4"
905   "jsr  @%1%#"
906   [(set_attr "type" "sfunc")
907    (set_attr "needs_delay_slot" "yes")])
908
909 (define_insn "udivsi3_i4"
910   [(set (match_operand:SI 0 "register_operand" "=y")
911         (udiv:SI (reg:SI 4) (reg:SI 5)))
912    (clobber (reg:SI 17))
913    (clobber (reg:DF 24))
914    (clobber (reg:DF 26))
915    (clobber (reg:DF 28))
916    (clobber (reg:SI 0))
917    (clobber (reg:SI 1))
918    (clobber (reg:SI 4))
919    (clobber (reg:SI 5))
920    (use (reg:PSI 48))
921    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
922   "TARGET_SH4 && ! TARGET_FPU_SINGLE"
923   "jsr  @%1%#"
924   [(set_attr "type" "sfunc")
925    (set_attr "fp_mode" "double")
926    (set_attr "needs_delay_slot" "yes")])
927
928 (define_insn "udivsi3_i4_single"
929   [(set (match_operand:SI 0 "register_operand" "=y")
930         (udiv:SI (reg:SI 4) (reg:SI 5)))
931    (clobber (reg:SI 17))
932    (clobber (reg:DF 24))
933    (clobber (reg:DF 26))
934    (clobber (reg:DF 28))
935    (clobber (reg:SI 0))
936    (clobber (reg:SI 1))
937    (clobber (reg:SI 4))
938    (clobber (reg:SI 5))
939    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
940   "TARGET_HARD_SH4 && TARGET_FPU_SINGLE"
941   "jsr  @%1%#"
942   [(set_attr "type" "sfunc")
943    (set_attr "needs_delay_slot" "yes")])
944
945 (define_expand "udivsi3"
946   [(set (match_dup 3) (symbol_ref:SI "__udivsi3"))
947    (set (reg:SI 4) (match_operand:SI 1 "general_operand" ""))
948    (set (reg:SI 5) (match_operand:SI 2 "general_operand" ""))
949    (parallel [(set (match_operand:SI 0 "register_operand" "")
950                    (udiv:SI (reg:SI 4)
951                             (reg:SI 5)))
952               (clobber (reg:SI 18))
953               (clobber (reg:SI 17))
954               (clobber (reg:SI 4))
955               (use (match_dup 3))])]
956   ""
957   "
958 {
959   rtx first, last;
960
961   operands[3] = gen_reg_rtx(SImode);
962   /* Emit the move of the address to a pseudo outside of the libcall.  */
963   if (TARGET_HARD_SH4 && TARGET_SH3E)
964     {
965       emit_move_insn (operands[3],
966                       gen_rtx_SYMBOL_REF (SImode, \"__udivsi3_i4\"));
967       if (TARGET_FPU_SINGLE)
968         last = gen_udivsi3_i4_single (operands[0], operands[3]);
969       else
970         last = gen_udivsi3_i4 (operands[0], operands[3]);
971     }
972   else
973     {
974       emit_move_insn (operands[3],
975                       gen_rtx_SYMBOL_REF (SImode, \"__udivsi3\"));
976       last = gen_udivsi3_i1 (operands[0], operands[3]);
977     }
978   first = emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
979   emit_move_insn (gen_rtx_REG (SImode, 5), operands[2]);
980   last = emit_insn (last);
981   /* Wrap the sequence in REG_LIBCALL / REG_RETVAL notes so that loop
982      invariant code motion can move it.  */
983   REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, REG_NOTES (first));
984   REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, REG_NOTES (last));
985   DONE;
986 }")
987
988 (define_insn "divsi3_i1"
989   [(set (match_operand:SI 0 "register_operand" "=z")
990         (div:SI (reg:SI 4) (reg:SI 5)))
991    (clobber (reg:SI 18))
992    (clobber (reg:SI 17))
993    (clobber (reg:SI 1))
994    (clobber (reg:SI 2))
995    (clobber (reg:SI 3))
996    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
997   "! TARGET_SH4"
998   "jsr  @%1%#"
999   [(set_attr "type" "sfunc")
1000    (set_attr "needs_delay_slot" "yes")])
1001
1002 (define_insn "divsi3_i4"
1003   [(set (match_operand:SI 0 "register_operand" "=y")
1004         (div:SI (reg:SI 4) (reg:SI 5)))
1005    (clobber (reg:SI 17))
1006    (clobber (reg:DF 24))
1007    (clobber (reg:DF 26))
1008    (use (reg:PSI 48))
1009    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
1010   "TARGET_SH4 && ! TARGET_FPU_SINGLE"
1011   "jsr  @%1%#"
1012   [(set_attr "type" "sfunc")
1013    (set_attr "fp_mode" "double")
1014    (set_attr "needs_delay_slot" "yes")])
1015
1016 (define_insn "divsi3_i4_single"
1017   [(set (match_operand:SI 0 "register_operand" "=y")
1018         (div:SI (reg:SI 4) (reg:SI 5)))
1019    (clobber (reg:SI 17))
1020    (clobber (reg:DF 24))
1021    (clobber (reg:DF 26))
1022    (clobber (reg:SI 2))
1023    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
1024   "TARGET_HARD_SH4 && TARGET_FPU_SINGLE"
1025   "jsr  @%1%#"
1026   [(set_attr "type" "sfunc")
1027    (set_attr "needs_delay_slot" "yes")])
1028
1029 (define_expand "divsi3"
1030   [(set (match_dup 3) (symbol_ref:SI "__sdivsi3"))
1031    (set (reg:SI 4) (match_operand:SI 1 "general_operand" ""))
1032    (set (reg:SI 5) (match_operand:SI 2 "general_operand" ""))
1033    (parallel [(set (match_operand:SI 0 "register_operand" "")
1034                    (div:SI (reg:SI 4)
1035                            (reg:SI 5)))
1036               (clobber (reg:SI 18))
1037               (clobber (reg:SI 17))
1038               (clobber (reg:SI 1))
1039               (clobber (reg:SI 2))
1040               (clobber (reg:SI 3))
1041               (use (match_dup 3))])]
1042   ""
1043   "
1044 {
1045   rtx first, last;
1046
1047   operands[3] = gen_reg_rtx(SImode);
1048   /* Emit the move of the address to a pseudo outside of the libcall.  */
1049   if (TARGET_HARD_SH4 && TARGET_SH3E)
1050     {
1051       emit_move_insn (operands[3],
1052                       gen_rtx_SYMBOL_REF (SImode, \"__sdivsi3_i4\"));
1053       if (TARGET_FPU_SINGLE)
1054         last = gen_divsi3_i4_single (operands[0], operands[3]);
1055       else
1056         last = gen_divsi3_i4 (operands[0], operands[3]);
1057     }
1058   else
1059     {
1060       emit_move_insn (operands[3], gen_rtx_SYMBOL_REF (SImode, \"__sdivsi3\"));
1061       last = gen_divsi3_i1 (operands[0], operands[3]);
1062     }
1063   first = emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
1064   emit_move_insn (gen_rtx_REG (SImode, 5), operands[2]);
1065   last = emit_insn (last);
1066   /* Wrap the sequence in REG_LIBCALL / REG_RETVAL notes so that loop
1067      invariant code motion can move it.  */
1068   REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, REG_NOTES (first));
1069   REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, REG_NOTES (last));
1070   DONE;
1071 }")
1072 \f
1073 ;; -------------------------------------------------------------------------
1074 ;; Multiplication instructions
1075 ;; -------------------------------------------------------------------------
1076
1077 (define_insn "umulhisi3_i"
1078   [(set (reg:SI 21)
1079         (mult:SI (zero_extend:SI (match_operand:HI 0 "arith_reg_operand" "r"))
1080                  (zero_extend:SI (match_operand:HI 1 "arith_reg_operand" "r"))))]
1081   ""
1082   "mulu %1,%0"
1083   [(set_attr "type" "smpy")])
1084
1085 (define_insn "mulhisi3_i"
1086   [(set (reg:SI 21)
1087         (mult:SI (sign_extend:SI
1088                   (match_operand:HI 0 "arith_reg_operand" "r"))
1089                  (sign_extend:SI
1090                   (match_operand:HI 1 "arith_reg_operand" "r"))))]
1091   ""
1092   "muls %1,%0"
1093   [(set_attr "type" "smpy")])
1094
1095 (define_expand "mulhisi3"
1096   [(set (reg:SI 21)
1097         (mult:SI (sign_extend:SI
1098                   (match_operand:HI 1 "arith_reg_operand" ""))
1099                  (sign_extend:SI
1100                   (match_operand:HI 2 "arith_reg_operand" ""))))
1101    (set (match_operand:SI 0 "arith_reg_operand" "")
1102         (reg:SI 21))]
1103   ""
1104   "
1105 {
1106   rtx first, last;
1107
1108   first = emit_insn (gen_mulhisi3_i (operands[1], operands[2]));
1109   last = emit_move_insn (operands[0], gen_rtx_REG (SImode, 21));
1110   /* Wrap the sequence in REG_LIBCALL / REG_RETVAL notes so that loop
1111      invariant code motion can move it.  */
1112   REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, REG_NOTES (first));
1113   REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, REG_NOTES (last));
1114   DONE;
1115 }")
1116
1117 (define_expand "umulhisi3"
1118   [(set (reg:SI 21)
1119         (mult:SI (zero_extend:SI
1120                   (match_operand:HI 1 "arith_reg_operand" ""))
1121                  (zero_extend:SI
1122                   (match_operand:HI 2 "arith_reg_operand" ""))))
1123    (set (match_operand:SI 0 "arith_reg_operand" "")
1124         (reg:SI 21))]
1125   ""
1126   "
1127 {
1128   rtx first, last;
1129
1130   first = emit_insn (gen_umulhisi3_i (operands[1], operands[2]));
1131   last = emit_move_insn (operands[0], gen_rtx_REG (SImode, 21));
1132   /* Wrap the sequence in REG_LIBCALL / REG_RETVAL notes so that loop
1133      invariant code motion can move it.  */
1134   REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, REG_NOTES (first));
1135   REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, REG_NOTES (last));
1136   DONE;
1137 }")
1138
1139 ;; mulsi3 on the SH2 can be done in one instruction, on the SH1 we generate
1140 ;; a call to a routine which clobbers known registers.
1141
1142 (define_insn ""
1143   [(set (match_operand:SI 1 "register_operand" "=z")
1144         (mult:SI (reg:SI 4) (reg:SI 5)))
1145    (clobber (reg:SI 21))
1146    (clobber (reg:SI 18))
1147    (clobber (reg:SI 17))
1148    (clobber (reg:SI 3))
1149    (clobber (reg:SI 2))
1150    (clobber (reg:SI 1))
1151    (use (match_operand:SI 0 "arith_reg_operand" "r"))]
1152   ""
1153   "jsr  @%0%#"
1154   [(set_attr "type" "sfunc")
1155    (set_attr "needs_delay_slot" "yes")])
1156
1157 (define_expand "mulsi3_call"
1158   [(set (reg:SI 4) (match_operand:SI 1 "general_operand" ""))
1159    (set (reg:SI 5) (match_operand:SI 2 "general_operand" ""))
1160    (parallel[(set (match_operand:SI 0 "register_operand" "")
1161                   (mult:SI (reg:SI 4)
1162                            (reg:SI 5)))
1163              (clobber (reg:SI 21))
1164              (clobber (reg:SI 18))
1165              (clobber (reg:SI 17))
1166              (clobber (reg:SI 3))
1167              (clobber (reg:SI 2))
1168              (clobber (reg:SI 1))
1169              (use (match_operand:SI 3 "register_operand" ""))])]
1170   ""
1171   "")
1172
1173 (define_insn "mul_l"
1174   [(set (reg:SI 21)
1175         (mult:SI (match_operand:SI 0 "arith_reg_operand" "r")
1176                  (match_operand:SI 1 "arith_reg_operand" "r")))]
1177   "TARGET_SH2"
1178   "mul.l        %1,%0"
1179   [(set_attr "type" "dmpy")])
1180
1181 (define_expand "mulsi3"
1182   [(set (reg:SI 21)
1183         (mult:SI  (match_operand:SI 1 "arith_reg_operand" "")
1184                   (match_operand:SI 2 "arith_reg_operand" "")))
1185    (set (match_operand:SI 0 "arith_reg_operand" "")
1186         (reg:SI 21))]
1187   ""
1188   "
1189 {
1190   rtx first, last;
1191
1192   if (!TARGET_SH2)
1193     {
1194       /* The address must be set outside the libcall,
1195          since it goes into a pseudo.  */
1196       rtx sym = gen_rtx_SYMBOL_REF (SImode, \"__mulsi3\");
1197       rtx addr = force_reg (SImode, sym);
1198       rtx insns = gen_mulsi3_call (operands[0], operands[1],
1199                                    operands[2], addr);
1200       first = XVECEXP (insns, 0, 0);
1201       last = XVECEXP (insns, 0, XVECLEN (insns, 0) - 1);
1202       emit_insn (insns);
1203     }
1204   else
1205     {
1206       rtx macl = gen_rtx_REG (SImode, MACL_REG);
1207
1208       first = emit_insn (gen_mul_l (operands[1], operands[2]));
1209       /* consec_sets_giv can only recognize the first insn that sets a
1210          giv as the giv insn.  So we must tag this also with a REG_EQUAL
1211          note.  */
1212       last = emit_insn (gen_movsi_i ((operands[0]), macl));
1213     }
1214   /* Wrap the sequence in REG_LIBCALL / REG_RETVAL notes so that loop
1215      invariant code motion can move it.  */
1216   REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, REG_NOTES (first));
1217   REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, REG_NOTES (last));
1218   DONE;
1219 }")
1220
1221 (define_insn "mulsidi3_i"
1222   [(set (reg:SI 20)
1223         (truncate:SI
1224          (lshiftrt:DI (mult:DI (sign_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
1225                                (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
1226                       (const_int 32))))
1227    (set (reg:SI 21)
1228         (mult:SI (match_dup 0)
1229                  (match_dup 1)))]
1230   "TARGET_SH2"
1231   "dmuls.l      %1,%0"
1232   [(set_attr "type" "dmpy")])
1233
1234 (define_insn "mulsidi3"
1235   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
1236         (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r"))
1237                  (sign_extend:DI (match_operand:SI 2 "arith_reg_operand" "r"))))
1238    (clobber (reg:DI 20))]
1239   "TARGET_SH2"
1240   "#")
1241
1242 (define_split
1243   [(set (match_operand:DI 0 "arith_reg_operand" "")
1244         (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
1245                  (sign_extend:DI (match_operand:SI 2 "arith_reg_operand" ""))))
1246    (clobber (reg:DI 20))]
1247   "TARGET_SH2"
1248   [(const_int 0)]
1249   "
1250 {
1251   rtx low_dst = gen_lowpart (SImode, operands[0]);
1252   rtx high_dst = gen_highpart (SImode, operands[0]);
1253
1254   emit_insn (gen_mulsidi3_i (operands[1], operands[2]));
1255
1256   emit_move_insn (low_dst, gen_rtx_REG (SImode, 21));
1257   emit_move_insn (high_dst, gen_rtx_REG (SImode, 20));
1258   /* We need something to tag the possible REG_EQUAL notes on to.  */
1259   emit_move_insn (operands[0], operands[0]);
1260   DONE;
1261 }")
1262
1263 (define_insn "umulsidi3_i"
1264   [(set (reg:SI 20)
1265         (truncate:SI
1266          (lshiftrt:DI (mult:DI (zero_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
1267                                (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
1268                       (const_int 32))))
1269    (set (reg:SI 21)
1270         (mult:SI (match_dup 0)
1271                  (match_dup 1)))]
1272   "TARGET_SH2"
1273   "dmulu.l      %1,%0"
1274   [(set_attr "type" "dmpy")])
1275
1276 (define_insn "umulsidi3"
1277   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
1278         (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r"))
1279                  (zero_extend:DI (match_operand:SI 2 "arith_reg_operand" "r"))))
1280    (clobber (reg:DI 20))]
1281   "TARGET_SH2"
1282   "#")
1283
1284 (define_split
1285   [(set (match_operand:DI 0 "arith_reg_operand" "")
1286         (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
1287                  (zero_extend:DI (match_operand:SI 2 "arith_reg_operand" ""))))
1288    (clobber (reg:DI 20))]
1289   "TARGET_SH2"
1290   [(const_int 0)]
1291   "
1292 {
1293   rtx low_dst = gen_lowpart (SImode, operands[0]);
1294   rtx high_dst = gen_highpart (SImode, operands[0]);
1295
1296   emit_insn (gen_umulsidi3_i (operands[1], operands[2]));
1297
1298   emit_move_insn (low_dst, gen_rtx_REG (SImode, 21));
1299   emit_move_insn (high_dst, gen_rtx_REG (SImode, 20));
1300   /* We need something to tag the possible REG_EQUAL notes on to.  */
1301   emit_move_insn (operands[0], operands[0]);
1302   DONE;
1303 }")
1304
1305 (define_insn "smulsi3_highpart_i"
1306   [(set (reg:SI 20)
1307         (truncate:SI
1308          (lshiftrt:DI (mult:DI (sign_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
1309                                (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
1310                       (const_int 32))))
1311    (clobber (reg:SI 21))]
1312   "TARGET_SH2"
1313   "dmuls.l      %1,%0"
1314   [(set_attr "type" "dmpy")])
1315
1316 (define_expand "smulsi3_highpart"
1317   [(parallel [(set (reg:SI 20)
1318                    (truncate:SI
1319                     (lshiftrt:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
1320                                           (sign_extend:DI (match_operand:SI 2 "arith_reg_operand" "")))
1321                                  (const_int 32))))
1322               (clobber (reg:SI 21))])
1323    (set (match_operand:SI 0 "arith_reg_operand" "")
1324         (reg:SI 20))]
1325   "TARGET_SH2"
1326   "
1327 {
1328   rtx first, last;
1329
1330   first = emit_insn (gen_smulsi3_highpart_i (operands[1], operands[2]));
1331   last = emit_move_insn (operands[0], gen_rtx_REG (SImode, 20));
1332   /* Wrap the sequence in REG_LIBCALL / REG_RETVAL notes so that loop
1333      invariant code motion can move it.  */
1334   REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, REG_NOTES (first));
1335   REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, REG_NOTES (last));
1336   /* expand_binop can't find a suitable code in mul_highpart_optab to
1337      make a REG_EQUAL note from, so make one here.
1338      ??? Alternatively, we could put this at the calling site of expand_binop,
1339      i.e. expand_mult_highpart.  */
1340   REG_NOTES (last)
1341     = gen_rtx_EXPR_LIST (REG_EQUAL, copy_rtx (SET_SRC (single_set (first))),
1342                          REG_NOTES (last));
1343   DONE;
1344 }")
1345
1346 (define_insn "umulsi3_highpart_i"
1347   [(set (reg:SI 20)
1348         (truncate:SI
1349          (lshiftrt:DI (mult:DI (zero_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
1350                                (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
1351                       (const_int 32))))
1352    (clobber (reg:SI 21))]
1353   "TARGET_SH2"
1354   "dmulu.l      %1,%0"
1355   [(set_attr "type" "dmpy")])
1356
1357 (define_expand "umulsi3_highpart"
1358   [(parallel [(set (reg:SI 20)
1359                    (truncate:SI
1360                     (lshiftrt:DI (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
1361                                           (zero_extend:DI (match_operand:SI 2 "arith_reg_operand" "")))
1362                                  (const_int 32))))
1363               (clobber (reg:SI 21))])
1364    (set (match_operand:SI 0 "arith_reg_operand" "")
1365         (reg:SI 20))]
1366   "TARGET_SH2"
1367   "
1368 {
1369   rtx first, last;
1370
1371   first = emit_insn (gen_umulsi3_highpart_i (operands[1], operands[2]));
1372   last = emit_move_insn (operands[0], gen_rtx_REG (SImode, 20));
1373   /* Wrap the sequence in REG_LIBCALL / REG_RETVAL notes so that loop
1374      invariant code motion can move it.  */
1375   REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, REG_NOTES (first));
1376   REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, REG_NOTES (last));
1377   DONE;
1378 }")
1379 \f
1380 ;; -------------------------------------------------------------------------
1381 ;; Logical operations
1382 ;; -------------------------------------------------------------------------
1383
1384 (define_insn ""
1385   [(set (match_operand:SI 0 "arith_reg_operand" "=r,z")
1386         (and:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
1387                 (match_operand:SI 2 "logical_operand" "r,L")))]
1388   ""
1389   "and  %2,%0"
1390   [(set_attr "type" "arith")])
1391
1392 ;; If the constant is 255, then emit a extu.b instruction instead of an
1393 ;; and, since that will give better code.
1394
1395 (define_expand "andsi3"
1396   [(set (match_operand:SI 0 "arith_reg_operand" "")
1397         (and:SI (match_operand:SI 1 "arith_reg_operand" "")
1398                 (match_operand:SI 2 "logical_operand" "")))]
1399   ""
1400   "
1401 {
1402   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) == 255)
1403     {
1404       emit_insn (gen_zero_extendqisi2 (operands[0],
1405                                        gen_lowpart (QImode, operands[1])));
1406       DONE;
1407     }
1408 }")
1409
1410 (define_insn "iorsi3"
1411   [(set (match_operand:SI 0 "arith_reg_operand" "=r,z")
1412         (ior:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
1413                 (match_operand:SI 2 "logical_operand" "r,L")))]
1414   ""
1415   "or   %2,%0"
1416   [(set_attr "type" "arith")])
1417
1418 (define_insn "xorsi3"
1419   [(set (match_operand:SI 0 "arith_reg_operand" "=z,r")
1420         (xor:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
1421                 (match_operand:SI 2 "logical_operand" "L,r")))]
1422   ""
1423   "xor  %2,%0"
1424   [(set_attr "type" "arith")])
1425 \f
1426 ;; -------------------------------------------------------------------------
1427 ;; Shifts and rotates
1428 ;; -------------------------------------------------------------------------
1429
1430 (define_insn "rotlsi3_1"
1431   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1432         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
1433                    (const_int 1)))
1434    (set (reg:SI 18)
1435         (lshiftrt:SI (match_dup 1) (const_int 31)))]
1436   ""
1437   "rotl %0"
1438   [(set_attr "type" "arith")])
1439
1440 (define_insn "rotlsi3_31"
1441   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1442         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
1443                    (const_int 31)))
1444    (clobber (reg:SI 18))]
1445   ""
1446   "rotr %0"
1447   [(set_attr "type" "arith")])
1448
1449 (define_insn "rotlsi3_16"
1450   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1451         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "r")
1452                    (const_int 16)))]
1453   ""
1454   "swap.w       %1,%0"
1455   [(set_attr "type" "arith")])
1456
1457 (define_expand "rotlsi3"
1458   [(set (match_operand:SI 0 "arith_reg_operand" "")
1459         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "")
1460                    (match_operand:SI 2 "immediate_operand" "")))]
1461   ""
1462   "
1463 {
1464   static char rot_tab[] = {
1465     000, 000, 000, 000, 000, 000, 010, 001,
1466     001, 001, 011, 013, 003, 003, 003, 003,
1467     003, 003, 003, 003, 003, 013, 012, 002,
1468     002, 002, 010, 000, 000, 000, 000, 000,
1469   };
1470
1471   int count, choice;
1472
1473   if (GET_CODE (operands[2]) != CONST_INT)
1474     FAIL;
1475   count = INTVAL (operands[2]);
1476   choice = rot_tab[count];
1477   if (choice & 010 && SH_DYNAMIC_SHIFT_COST <= 1)
1478     FAIL;
1479   choice &= 7;
1480   switch (choice)
1481     {
1482     case 0:
1483       emit_move_insn (operands[0], operands[1]);
1484       count -= (count & 16) * 2;
1485       break;
1486     case 3:
1487      emit_insn (gen_rotlsi3_16 (operands[0], operands[1]));
1488      count -= 16;
1489      break;
1490     case 1:
1491     case 2:
1492       {
1493         rtx parts[2];
1494         parts[0] = gen_reg_rtx (SImode);
1495         parts[1] = gen_reg_rtx (SImode);
1496         emit_insn (gen_rotlsi3_16 (parts[2-choice], operands[1]));
1497         parts[choice-1] = operands[1];
1498         emit_insn (gen_ashlsi3 (parts[0], parts[0], GEN_INT (8)));
1499         emit_insn (gen_lshrsi3 (parts[1], parts[1], GEN_INT (8)));
1500         emit_insn (gen_iorsi3 (operands[0], parts[0], parts[1]));
1501         count = (count & ~16) - 8;
1502       }
1503     }
1504
1505   for (; count > 0; count--)
1506     emit_insn (gen_rotlsi3_1 (operands[0], operands[0]));
1507   for (; count < 0; count++)
1508     emit_insn (gen_rotlsi3_31 (operands[0], operands[0]));
1509
1510   DONE;
1511 }")
1512
1513 (define_insn "*rotlhi3_8"
1514   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
1515         (rotate:HI (match_operand:HI 1 "arith_reg_operand" "r")
1516                    (const_int 8)))]
1517   ""
1518   "swap.b       %1,%0"
1519   [(set_attr "type" "arith")])
1520
1521 (define_expand "rotlhi3"
1522   [(set (match_operand:HI 0 "arith_reg_operand" "")
1523         (rotate:HI (match_operand:HI 1 "arith_reg_operand" "")
1524                    (match_operand:HI 2 "immediate_operand" "")))]
1525   ""
1526   "
1527 {
1528   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 8)
1529     FAIL;
1530 }")
1531
1532 ;;
1533 ;; shift left
1534
1535 ;; This pattern is used by init_expmed for computing the costs of shift
1536 ;; insns.
1537
1538 (define_insn_and_split "ashlsi3_std"
1539   [(set (match_operand:SI 0 "arith_reg_operand" "=r,r,r,r")
1540         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0,0,0,0")
1541                    (match_operand:SI 2 "nonmemory_operand" "r,M,K,?ri")))
1542    (clobber (match_scratch:SI 3 "=X,X,X,&r"))]
1543   "TARGET_SH3
1544    || (GET_CODE (operands[2]) == CONST_INT
1545        && CONST_OK_FOR_K (INTVAL (operands[2])))"
1546   "@
1547    shld %2,%0
1548    add  %0,%0
1549    shll%O2      %0
1550    #"
1551   "TARGET_SH3
1552    && GET_CODE (operands[2]) == CONST_INT
1553    && ! CONST_OK_FOR_K (INTVAL (operands[2]))"
1554   [(set (match_dup 3) (match_dup 2))
1555    (parallel
1556     [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 3)))
1557      (clobber (match_dup 4))])]
1558   "operands[4] = gen_rtx_SCRATCH (SImode);"
1559   [(set_attr "length" "*,*,*,4")
1560    (set_attr "type" "dyn_shift,arith,arith,arith")])
1561
1562 (define_insn "ashlhi3_k"
1563   [(set (match_operand:HI 0 "arith_reg_operand" "=r,r")
1564         (ashift:HI (match_operand:HI 1 "arith_reg_operand" "0,0")
1565                    (match_operand:HI 2 "const_int_operand" "M,K")))]
1566   "CONST_OK_FOR_K (INTVAL (operands[2]))"
1567   "@
1568         add     %0,%0
1569         shll%O2 %0"
1570   [(set_attr "type" "arith")])
1571
1572 (define_insn "ashlsi3_n"
1573   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1574         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
1575                    (match_operand:SI 2 "const_int_operand" "n")))
1576    (clobber (reg:SI 18))]
1577   "! sh_dynamicalize_shift_p (operands[2])"
1578   "#"
1579   [(set (attr "length")
1580         (cond [(eq (symbol_ref "shift_insns_rtx (insn)") (const_int 1))
1581                (const_string "2")
1582                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 2))
1583                (const_string "4")
1584                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 3))
1585                (const_string "6")]
1586               (const_string "8")))
1587    (set_attr "type" "arith")])
1588
1589 (define_split
1590   [(set (match_operand:SI 0 "arith_reg_operand" "")
1591         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "")
1592                    (match_operand:SI 2 "const_int_operand" "n")))
1593    (clobber (reg:SI 18))]
1594   ""
1595   [(use (reg:SI 0))]
1596   "
1597 {
1598   gen_shifty_op (ASHIFT, operands);
1599   DONE;
1600 }")
1601
1602 (define_expand "ashlsi3"
1603   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "")
1604                    (ashift:SI (match_operand:SI 1 "arith_reg_operand" "")
1605                               (match_operand:SI 2 "nonmemory_operand" "")))
1606               (clobber (reg:SI 18))])]
1607   ""
1608   "
1609 {
1610   if (GET_CODE (operands[2]) == CONST_INT
1611       && sh_dynamicalize_shift_p (operands[2]))
1612     operands[2] = force_reg (SImode, operands[2]);
1613   if (TARGET_SH3)
1614     {
1615       emit_insn (gen_ashlsi3_std (operands[0], operands[1], operands[2]));
1616       DONE;
1617     }
1618   if (! immediate_operand (operands[2], GET_MODE (operands[2])))
1619     FAIL;
1620 }")
1621
1622 (define_insn "ashlhi3"
1623   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
1624         (ashift:HI (match_operand:HI 1 "arith_reg_operand" "0")
1625                    (match_operand:HI 2 "const_int_operand" "n")))
1626    (clobber (reg:SI 18))]
1627   ""
1628   "#"
1629   [(set (attr "length")
1630         (cond [(eq (symbol_ref "shift_insns_rtx (insn)") (const_int 1))
1631                (const_string "2")
1632                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 2))
1633                (const_string "4")]
1634               (const_string "6")))
1635    (set_attr "type" "arith")])
1636
1637 (define_split
1638   [(set (match_operand:HI 0 "arith_reg_operand" "")
1639         (ashift:HI (match_operand:HI 1 "arith_reg_operand" "")
1640                    (match_operand:HI 2 "const_int_operand" "n")))
1641    (clobber (reg:SI 18))]
1642   ""
1643   [(use (reg:SI 0))]
1644   "
1645 {
1646   gen_shifty_hi_op (ASHIFT, operands);
1647   DONE;
1648 }")
1649
1650 ;
1651 ; arithmetic shift right
1652 ;
1653
1654 (define_insn "ashrsi3_k"
1655   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1656         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
1657                      (match_operand:SI 2 "const_int_operand" "M")))
1658    (clobber (reg:SI 18))]
1659   "INTVAL (operands[2]) == 1"
1660   "shar %0"
1661   [(set_attr "type" "arith")])
1662
1663 ;; We can't do HImode right shifts correctly unless we start out with an
1664 ;; explicit zero / sign extension; doing that would result in worse overall
1665 ;; code, so just let the machine independent code widen the mode.
1666 ;; That's why we don't have ashrhi3_k / lshrhi3_k / lshrhi3_m / lshrhi3 .
1667
1668
1669 ;; ??? This should be a define expand.
1670
1671 (define_insn "ashrsi2_16"
1672   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1673         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "r")
1674                      (const_int 16)))]
1675   ""
1676   "#"
1677   [(set_attr "length" "4")])
1678
1679 (define_split
1680   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1681         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "r")
1682                      (const_int 16)))]
1683   ""
1684   [(set (match_dup 0) (rotate:SI (match_dup 1) (const_int 16)))
1685    (set (match_dup 0) (sign_extend:SI (match_dup 2)))]
1686   "operands[2] = gen_lowpart (HImode, operands[0]);")
1687
1688 ;; ??? This should be a define expand.
1689
1690 (define_insn "ashrsi2_31"
1691   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1692         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
1693                      (const_int 31)))
1694    (clobber (reg:SI 18))]
1695   ""
1696   "#"
1697   [(set_attr "length" "4")])
1698
1699 (define_split
1700   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1701         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
1702                      (const_int 31)))
1703    (clobber (reg:SI 18))]
1704   ""
1705   [(const_int 0)]
1706   "
1707 {
1708   emit_insn (gen_ashlsi_c (operands[0], operands[1]));
1709   emit_insn (gen_subc1 (operands[0], operands[0], operands[0]));
1710   DONE;
1711 }")
1712
1713 (define_insn "ashlsi_c"
1714   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1715         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0") (const_int 1)))
1716    (set (reg:SI 18) (lt:SI (match_dup 1)
1717                            (const_int 0)))]
1718   ""
1719   "shll %0"
1720   [(set_attr "type" "arith")])
1721
1722 (define_insn "ashrsi3_d"
1723   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1724         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
1725                      (neg:SI (match_operand:SI 2 "arith_reg_operand" "r"))))]
1726   "TARGET_SH3"
1727   "shad %2,%0"
1728   [(set_attr "type" "dyn_shift")])
1729
1730 (define_insn "ashrsi3_n"
1731   [(set (reg:SI 4)
1732         (ashiftrt:SI (reg:SI 4)
1733                      (match_operand:SI 0 "const_int_operand" "i")))
1734    (clobber (reg:SI 18))
1735    (clobber (reg:SI 17))
1736    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
1737   ""
1738   "jsr  @%1%#"
1739   [(set_attr "type" "sfunc")
1740    (set_attr "needs_delay_slot" "yes")])
1741
1742 (define_expand "ashrsi3"
1743   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "")
1744                    (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
1745                                 (match_operand:SI 2 "nonmemory_operand" "")))
1746               (clobber (reg:SI 18))])]
1747   ""
1748   "if (expand_ashiftrt (operands)) DONE; else FAIL;")
1749
1750 ;; logical shift right
1751
1752 (define_insn "lshrsi3_d"
1753   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1754         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
1755                      (neg:SI (match_operand:SI 2 "arith_reg_operand" "r"))))]
1756   "TARGET_SH3"
1757   "shld %2,%0"
1758   [(set_attr "type" "dyn_shift")])
1759
1760 ;;  Only the single bit shift clobbers the T bit.
1761
1762 (define_insn "lshrsi3_m"
1763   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1764         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
1765                      (match_operand:SI 2 "const_int_operand" "M")))
1766    (clobber (reg:SI 18))]
1767   "CONST_OK_FOR_M (INTVAL (operands[2]))"
1768   "shlr %0"
1769   [(set_attr "type" "arith")])
1770
1771 (define_insn "lshrsi3_k"
1772   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1773         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
1774                      (match_operand:SI 2 "const_int_operand" "K")))]
1775   "CONST_OK_FOR_K (INTVAL (operands[2]))
1776    && ! CONST_OK_FOR_M (INTVAL (operands[2]))"
1777   "shlr%O2      %0"
1778   [(set_attr "type" "arith")])
1779
1780 (define_insn "lshrsi3_n"
1781   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1782         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
1783                      (match_operand:SI 2 "const_int_operand" "n")))
1784    (clobber (reg:SI 18))]
1785   "! sh_dynamicalize_shift_p (operands[2])"
1786   "#"
1787   [(set (attr "length")
1788         (cond [(eq (symbol_ref "shift_insns_rtx (insn)") (const_int 1))
1789                (const_string "2")
1790                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 2))
1791                (const_string "4")
1792                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 3))
1793                (const_string "6")]
1794               (const_string "8")))
1795    (set_attr "type" "arith")])
1796
1797 (define_split
1798   [(set (match_operand:SI 0 "arith_reg_operand" "")
1799         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
1800                      (match_operand:SI 2 "const_int_operand" "n")))
1801    (clobber (reg:SI 18))]
1802   ""
1803   [(use (reg:SI 0))]
1804   "
1805 {
1806   gen_shifty_op (LSHIFTRT, operands);
1807   DONE;
1808 }")
1809
1810 (define_expand "lshrsi3"
1811   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "")
1812                    (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
1813                                 (match_operand:SI 2 "nonmemory_operand" "")))
1814               (clobber (reg:SI 18))])]
1815   ""
1816   "
1817 {
1818   if (GET_CODE (operands[2]) == CONST_INT
1819       && sh_dynamicalize_shift_p (operands[2]))
1820     operands[2] = force_reg (SImode, operands[2]);
1821   if (TARGET_SH3 && arith_reg_operand (operands[2], GET_MODE (operands[2])))
1822     {
1823       rtx count = copy_to_mode_reg (SImode, operands[2]);
1824       emit_insn (gen_negsi2 (count, count));
1825       emit_insn (gen_lshrsi3_d (operands[0], operands[1], count));
1826       DONE;
1827     }
1828   if (! immediate_operand (operands[2], GET_MODE (operands[2])))
1829     FAIL;
1830 }")
1831
1832 ;; ??? This should be a define expand.
1833
1834 (define_insn "ashldi3_k"
1835   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
1836         (ashift:DI (match_operand:DI 1 "arith_reg_operand" "0")
1837                    (const_int 1)))
1838    (clobber (reg:SI 18))]
1839   ""
1840   "shll %R0\;rotcl      %S0"
1841   [(set_attr "length" "4")
1842    (set_attr "type" "arith")])
1843
1844 (define_expand "ashldi3"
1845   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
1846                    (ashift:DI (match_operand:DI 1 "arith_reg_operand" "")
1847                               (match_operand:DI 2 "immediate_operand" "")))
1848               (clobber (reg:SI 18))])]
1849   ""
1850   "{ if (GET_CODE (operands[2]) != CONST_INT
1851          || INTVAL (operands[2]) != 1) FAIL;} ")
1852
1853 ;; ??? This should be a define expand.
1854
1855 (define_insn "lshrdi3_k"
1856   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
1857         (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
1858                      (const_int 1)))
1859    (clobber (reg:SI 18))]
1860   ""
1861   "shlr %S0\;rotcr      %R0"
1862   [(set_attr "length" "4")
1863    (set_attr "type" "arith")])
1864
1865 (define_expand "lshrdi3"
1866   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
1867                    (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
1868                                (match_operand:DI 2 "immediate_operand" "")))
1869              (clobber (reg:SI 18))])]
1870   ""
1871   "{ if (GET_CODE (operands[2]) != CONST_INT
1872          || INTVAL (operands[2]) != 1) FAIL;} ")
1873
1874 ;; ??? This should be a define expand.
1875
1876 (define_insn "ashrdi3_k"
1877   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
1878         (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
1879                      (const_int 1)))
1880    (clobber (reg:SI 18))]
1881   ""
1882   "shar %S0\;rotcr      %R0"
1883   [(set_attr "length" "4")
1884    (set_attr "type" "arith")])
1885
1886 (define_expand "ashrdi3"
1887   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
1888                    (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
1889                                 (match_operand:DI 2 "immediate_operand" "")))
1890               (clobber (reg:SI 18))])]
1891   ""
1892   "{ if (GET_CODE (operands[2]) != CONST_INT
1893          || INTVAL (operands[2]) != 1) FAIL; } ")
1894
1895 ;; combined left/right shift
1896
1897 (define_split
1898   [(set (match_operand:SI 0 "register_operand" "")
1899         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
1900                            (match_operand:SI 2 "const_int_operand" "n"))
1901                 (match_operand:SI 3 "const_int_operand" "n")))]
1902   "(unsigned)INTVAL (operands[2]) < 32"
1903   [(use (reg:SI 0))]
1904   "if (gen_shl_and (operands[0], operands[2], operands[3], operands[1])) FAIL;
1905    DONE;")
1906
1907 (define_split
1908   [(set (match_operand:SI 0 "register_operand" "")
1909         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
1910                            (match_operand:SI 2 "const_int_operand" "n"))
1911                 (match_operand:SI 3 "const_int_operand" "n")))
1912    (clobber (reg:SI 18))]
1913   "(unsigned)INTVAL (operands[2]) < 32"
1914   [(use (reg:SI 0))]
1915   "if (gen_shl_and (operands[0], operands[2], operands[3], operands[1])) FAIL;
1916    DONE;")
1917
1918 (define_insn ""
1919   [(set (match_operand:SI 0 "register_operand" "=r")
1920         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
1921                            (match_operand:SI 2 "const_int_operand" "n"))
1922                 (match_operand:SI 3 "const_int_operand" "n")))
1923    (clobber (reg:SI 18))]
1924   "shl_and_kind (operands[2], operands[3], 0) == 1"
1925  "#"
1926   [(set (attr "length")
1927         (cond [(eq (symbol_ref "shl_and_length (insn)") (const_int 2))
1928                (const_string "4")
1929                (eq (symbol_ref "shl_and_length (insn)") (const_int 3))
1930                (const_string "6")
1931                (eq (symbol_ref "shl_and_length (insn)") (const_int 4))
1932                (const_string "8")
1933                (eq (symbol_ref "shl_and_length (insn)") (const_int 5))
1934                (const_string "10")
1935                (eq (symbol_ref "shl_and_length (insn)") (const_int 6))
1936                (const_string "12")
1937                (eq (symbol_ref "shl_and_length (insn)") (const_int 7))
1938                (const_string "14")
1939                (eq (symbol_ref "shl_and_length (insn)") (const_int 8))
1940                (const_string "16")]
1941               (const_string "18")))
1942    (set_attr "type" "arith")])
1943
1944 (define_insn ""
1945   [(set (match_operand:SI 0 "register_operand" "=z")
1946         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
1947                            (match_operand:SI 2 "const_int_operand" "n"))
1948                 (match_operand:SI 3 "const_int_operand" "n")))
1949    (clobber (reg:SI 18))]
1950   "shl_and_kind (operands[2], operands[3], 0) == 2"
1951  "#"
1952   [(set (attr "length")
1953         (cond [(eq (symbol_ref "shl_and_length (insn)") (const_int 2))
1954                (const_string "4")
1955                (eq (symbol_ref "shl_and_length (insn)") (const_int 3))
1956                (const_string "6")
1957                (eq (symbol_ref "shl_and_length (insn)") (const_int 4))
1958                (const_string "8")]
1959               (const_string "10")))
1960    (set_attr "type" "arith")])
1961
1962 ;; shift left / and combination with a scratch register: The combine pass
1963 ;; does not accept the individual instructions, even though they are
1964 ;; cheap.  But it needs a precise description so that it is usable after
1965 ;; reload.
1966 (define_insn "and_shl_scratch"
1967   [(set (match_operand:SI 0 "register_operand" "=r,&r")
1968         (lshiftrt:SI (ashift:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,0")
1969                                                      (match_operand:SI 2 "const_int_operand" "N,n"))
1970                                         (match_operand:SI 3 "" "0,r"))
1971                                 (match_operand:SI 4 "const_int_operand" "n,n"))
1972                      (match_operand:SI 5 "const_int_operand" "n,n")))
1973    (clobber (reg:SI 18))]
1974   ""
1975   "#"
1976   [(set (attr "length")
1977         (cond [(eq (symbol_ref "shl_and_scr_length (insn)") (const_int 2))
1978                (const_string "4")
1979                (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 3))
1980                (const_string "6")
1981                (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 4))
1982                (const_string "8")
1983                (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 5))
1984                (const_string "10")]
1985               (const_string "12")))
1986    (set_attr "type" "arith")])
1987
1988 (define_split
1989   [(set (match_operand:SI 0 "register_operand" "=r,&r")
1990         (lshiftrt:SI (ashift:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,0")
1991                                                      (match_operand:SI 2 "const_int_operand" "N,n"))
1992                                         (match_operand:SI 3 "register_operand" "0,r"))
1993                                 (match_operand:SI 4 "const_int_operand" "n,n"))
1994                      (match_operand:SI 5 "const_int_operand" "n,n")))
1995    (clobber (reg:SI 18))]
1996   ""
1997   [(use (reg:SI 0))]
1998   "
1999 {
2000   rtx and_source = operands[rtx_equal_p (operands[0], operands[1]) ? 3 : 1];
2001
2002   if (INTVAL (operands[2]))
2003     {
2004       gen_shifty_op (LSHIFTRT, operands);
2005     }
2006   emit_insn (gen_andsi3 (operands[0], operands[0], and_source));
2007   operands[2] = operands[4];
2008   gen_shifty_op (ASHIFT, operands);
2009   if (INTVAL (operands[5]))
2010     {
2011       operands[2] = operands[5];
2012       gen_shifty_op (LSHIFTRT, operands);
2013     }
2014   DONE;
2015 }")
2016
2017 ;; signed left/right shift combination.
2018 (define_split
2019   [(set (match_operand:SI 0 "register_operand" "=r")
2020         (sign_extract:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
2021                                     (match_operand:SI 2 "const_int_operand" "n"))
2022                          (match_operand:SI 3 "const_int_operand" "n")
2023                          (const_int 0)))
2024    (clobber (reg:SI 18))]
2025   ""
2026   [(use (reg:SI 0))]
2027   "if (gen_shl_sext (operands[0], operands[2], operands[3], operands[1])) FAIL;
2028    DONE;")
2029
2030 (define_insn "shl_sext_ext"
2031   [(set (match_operand:SI 0 "register_operand" "=r")
2032         (sign_extract:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
2033                                     (match_operand:SI 2 "const_int_operand" "n"))
2034                          (match_operand:SI 3 "const_int_operand" "n")
2035                          (const_int 0)))
2036    (clobber (reg:SI 18))]
2037   "(unsigned)shl_sext_kind (operands[2], operands[3], 0) - 1 < 5"
2038   "#"
2039   [(set (attr "length")
2040         (cond [(eq (symbol_ref "shl_sext_length (insn)") (const_int 1))
2041                (const_string "2")
2042                (eq (symbol_ref "shl_sext_length (insn)") (const_int 2))
2043                (const_string "4")
2044                (eq (symbol_ref "shl_sext_length (insn)") (const_int 3))
2045                (const_string "6")
2046                (eq (symbol_ref "shl_sext_length (insn)") (const_int 4))
2047                (const_string "8")
2048                (eq (symbol_ref "shl_sext_length (insn)") (const_int 5))
2049                (const_string "10")
2050                (eq (symbol_ref "shl_sext_length (insn)") (const_int 6))
2051                (const_string "12")
2052                (eq (symbol_ref "shl_sext_length (insn)") (const_int 7))
2053                (const_string "14")
2054                (eq (symbol_ref "shl_sext_length (insn)") (const_int 8))
2055                (const_string "16")]
2056               (const_string "18")))
2057     (set_attr "type" "arith")])
2058
2059 (define_insn "shl_sext_sub"
2060   [(set (match_operand:SI 0 "register_operand" "=z")
2061         (sign_extract:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
2062                                     (match_operand:SI 2 "const_int_operand" "n"))
2063                          (match_operand:SI 3 "const_int_operand" "n")
2064                          (const_int 0)))
2065    (clobber (reg:SI 18))]
2066   "(shl_sext_kind (operands[2], operands[3], 0) & ~1) == 6"
2067   "#"
2068   [(set (attr "length")
2069         (cond [(eq (symbol_ref "shl_sext_length (insn)") (const_int 3))
2070                (const_string "6")
2071                (eq (symbol_ref "shl_sext_length (insn)") (const_int 4))
2072                (const_string "8")
2073                (eq (symbol_ref "shl_sext_length (insn)") (const_int 5))
2074                (const_string "10")
2075                (eq (symbol_ref "shl_sext_length (insn)") (const_int 6))
2076                (const_string "12")]
2077               (const_string "14")))
2078     (set_attr "type" "arith")])
2079
2080 ;; These patterns are found in expansions of DImode shifts by 16, and
2081 ;; allow the xtrct instruction to be generated from C source.
2082
2083 (define_insn "xtrct_left"
2084   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2085         (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "r")
2086                            (const_int 16))
2087                 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand" "0")
2088                              (const_int 16))))]
2089   ""
2090   "xtrct        %1,%0"
2091   [(set_attr "type" "arith")])
2092
2093 (define_insn "xtrct_right"
2094   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2095         (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
2096                              (const_int 16))
2097                 (ashift:SI (match_operand:SI 2 "arith_reg_operand" "r")
2098                            (const_int 16))))]
2099   ""
2100   "xtrct        %2,%0"
2101   [(set_attr "type" "arith")])
2102 \f
2103 ;; -------------------------------------------------------------------------
2104 ;; Unary arithmetic
2105 ;; -------------------------------------------------------------------------
2106
2107 (define_insn "negc"
2108   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2109         (neg:SI (plus:SI (reg:SI 18)
2110                          (match_operand:SI 1 "arith_reg_operand" "r"))))
2111    (set (reg:SI 18)
2112         (ne:SI (ior:SI (reg:SI 18) (match_dup 1))
2113                (const_int 0)))]
2114   ""
2115   "negc %1,%0"
2116   [(set_attr "type" "arith")])
2117
2118 (define_expand "negdi2"
2119   [(set (match_operand:DI 0 "arith_reg_operand" "")
2120         (neg:DI (match_operand:DI 1 "arith_reg_operand" "")))
2121    (clobber (reg:SI 18))]
2122   ""
2123   "
2124 {
2125   int low_word = (TARGET_LITTLE_ENDIAN ? 0 : 1);
2126   int high_word = (TARGET_LITTLE_ENDIAN ? 1 : 0);
2127
2128   rtx low_src = operand_subword (operands[1], low_word, 0, DImode);
2129   rtx high_src = operand_subword (operands[1], high_word, 0, DImode);
2130
2131   rtx low_dst = operand_subword (operands[0], low_word, 1, DImode);
2132   rtx high_dst = operand_subword (operands[0], high_word, 1, DImode);
2133
2134   emit_insn (gen_clrt ());
2135   emit_insn (gen_negc (low_dst, low_src));
2136   emit_insn (gen_negc (high_dst, high_src));
2137   DONE;
2138 }")
2139
2140 (define_insn "negsi2"
2141   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2142         (neg:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
2143   ""
2144   "neg  %1,%0"
2145   [(set_attr "type" "arith")])
2146
2147 (define_insn "one_cmplsi2"
2148   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2149         (not:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
2150   ""
2151   "not  %1,%0"
2152   [(set_attr "type" "arith")])
2153 \f
2154 ;; -------------------------------------------------------------------------
2155 ;; Zero extension instructions
2156 ;; -------------------------------------------------------------------------
2157
2158 (define_insn "zero_extendhisi2"
2159   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2160         (zero_extend:SI (match_operand:HI 1 "arith_reg_operand" "r")))]
2161   ""
2162   "extu.w       %1,%0"
2163   [(set_attr "type" "arith")])
2164
2165 (define_insn "zero_extendqisi2"
2166   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2167         (zero_extend:SI (match_operand:QI 1 "arith_reg_operand" "r")))]
2168   ""
2169   "extu.b       %1,%0"
2170   [(set_attr "type" "arith")])
2171
2172 (define_insn "zero_extendqihi2"
2173   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
2174         (zero_extend:HI (match_operand:QI 1 "arith_reg_operand" "r")))]
2175   ""
2176   "extu.b       %1,%0"
2177   [(set_attr "type" "arith")])
2178 \f
2179 ;; -------------------------------------------------------------------------
2180 ;; Sign extension instructions
2181 ;; -------------------------------------------------------------------------
2182
2183 ;; ??? This should be a define expand.
2184 ;; ??? Or perhaps it should be dropped?
2185
2186 /* There is no point in defining extendsidi2; convert_move generates good
2187    code for that.  */
2188
2189 (define_insn "extendhisi2"
2190   [(set (match_operand:SI 0 "arith_reg_operand" "=r,r")
2191         (sign_extend:SI (match_operand:HI 1 "general_movsrc_operand" "r,m")))]
2192   ""
2193   "@
2194         exts.w  %1,%0
2195         mov.w   %1,%0"
2196   [(set_attr "type" "arith,load")])
2197
2198 (define_insn "extendqisi2"
2199   [(set (match_operand:SI 0 "arith_reg_operand" "=r,r")
2200         (sign_extend:SI (match_operand:QI 1 "general_movsrc_operand" "r,m")))]
2201   ""
2202   "@
2203         exts.b  %1,%0
2204         mov.b   %1,%0"
2205   [(set_attr "type" "arith,load")])
2206
2207 (define_insn "extendqihi2"
2208   [(set (match_operand:HI 0 "arith_reg_operand" "=r,r")
2209         (sign_extend:HI (match_operand:QI 1 "general_movsrc_operand" "r,m")))]
2210   ""
2211   "@
2212         exts.b  %1,%0
2213         mov.b   %1,%0"
2214   [(set_attr "type" "arith,load")])
2215 \f
2216 ;; -------------------------------------------------------------------------
2217 ;; Move instructions
2218 ;; -------------------------------------------------------------------------
2219
2220 ;; define push and pop so it is easy for sh.c
2221
2222 (define_expand "push"
2223   [(set (mem:SI (pre_dec:SI (reg:SI 15)))
2224         (match_operand:SI 0 "register_operand" "r,l,x"))]
2225   ""
2226   "")
2227
2228 (define_expand "pop"
2229   [(set (match_operand:SI 0 "register_operand" "=r,l,x")
2230         (mem:SI (post_inc:SI (reg:SI 15))))]
2231   ""
2232   "")
2233
2234 (define_expand "push_e"
2235   [(parallel [(set (mem:SF (pre_dec:SI (reg:SI 15)))
2236                    (match_operand:SF 0 "" ""))
2237               (use (reg:PSI 48))
2238               (clobber (scratch:SI))])]
2239   ""
2240   "")
2241
2242 (define_insn "push_fpul"
2243   [(set (mem:SF (pre_dec:SI (reg:SI 15))) (reg:SF 22))]
2244   "TARGET_SH3E"
2245   "sts.l        fpul,@-r15"
2246   [(set_attr "type" "store")
2247    (set_attr "hit_stack" "yes")])
2248
2249 ;; DFmode pushes for sh4 require a lot of what is defined for movdf_i4,
2250 ;; so use that.
2251 (define_expand "push_4"
2252   [(parallel [(set (mem:DF (pre_dec:SI (reg:SI 15))) (match_operand:DF 0 "" ""))
2253               (use (reg:PSI 48))
2254               (clobber (scratch:SI))])]
2255   ""
2256   "")
2257
2258 (define_expand "pop_e"
2259   [(parallel [(set (match_operand:SF 0 "" "")
2260               (mem:SF (post_inc:SI (reg:SI 15))))
2261               (use (reg:PSI 48))
2262               (clobber (scratch:SI))])]
2263   ""
2264   "")
2265
2266 (define_insn "pop_fpul"
2267   [(set (reg:SF 22) (mem:SF (post_inc:SI (reg:SI 15))))]
2268   "TARGET_SH3E"
2269   "lds.l        @r15+,fpul"
2270   [(set_attr "type" "load")
2271    (set_attr "hit_stack" "yes")])
2272
2273 (define_expand "pop_4"
2274   [(parallel [(set (match_operand:DF 0 "" "")
2275                    (mem:DF (post_inc:SI (reg:SI 15))))
2276               (use (reg:PSI 48))
2277               (clobber (scratch:SI))])]
2278   ""
2279   "")
2280
2281 ;; These two patterns can happen as the result of optimization, when
2282 ;; comparisons get simplified to a move of zero or 1 into the T reg.
2283 ;; They don't disappear completely, because the T reg is a fixed hard reg.
2284
2285 (define_insn "clrt"
2286   [(set (reg:SI 18) (const_int 0))]
2287   ""
2288   "clrt")
2289
2290 (define_insn "sett"
2291   [(set (reg:SI 18) (const_int 1))]
2292   ""
2293   "sett")
2294
2295 ;; t/r must come after r/r, lest reload will try to reload stuff like
2296 ;; (set (subreg:SI (mem:QI (plus:SI (reg:SI 15 r15) (const_int 12)) 0) 0)
2297 ;; (made from (set (subreg:SI (reg:QI 73) 0) ) into T.
2298 (define_insn "movsi_i"
2299   [(set (match_operand:SI 0 "general_movdst_operand" "=r,r,t,r,r,r,m,<,<,xl,x,l,r")
2300         (match_operand:SI 1 "general_movsrc_operand" "Q,rI,r,mr,xl,t,r,x,l,r,>,>,i"))]
2301   "
2302    ! TARGET_SH3E
2303    && (register_operand (operands[0], SImode)
2304        || register_operand (operands[1], SImode))"
2305   "@
2306         mov.l   %1,%0
2307         mov     %1,%0
2308         cmp/pl  %1
2309         mov.l   %1,%0
2310         sts     %1,%0
2311         movt    %0
2312         mov.l   %1,%0
2313         sts.l   %1,%0
2314         sts.l   %1,%0
2315         lds     %1,%0
2316         lds.l   %1,%0
2317         lds.l   %1,%0
2318         fake    %1,%0"
2319   [(set_attr "type" "pcload_si,move,*,load_si,move,move,store,store,pstore,move,load,pload,pcload_si")
2320    (set_attr "length" "*,*,*,*,*,*,*,*,*,*,*,*,*")])
2321
2322 ;; t/r must come after r/r, lest reload will try to reload stuff like
2323 ;; (subreg:SI (reg:SF 38 fr14) 0) into T (compiling stdlib/strtod.c -m3e -O2)
2324 ;; ??? This allows moves from macl to fpul to be recognized, but these moves
2325 ;; will require a reload.
2326 (define_insn "movsi_ie"
2327   [(set (match_operand:SI 0 "general_movdst_operand" "=r,r,t,r,r,r,m,<,<,xl,x,l,y,r,y,r,y")
2328         (match_operand:SI 1 "general_movsrc_operand" "Q,rI,r,mr,xl,t,r,x,l,r,>,>,>,i,r,y,y"))]
2329   "TARGET_SH3E
2330    && (register_operand (operands[0], SImode)
2331        || register_operand (operands[1], SImode))"
2332   "@
2333         mov.l   %1,%0
2334         mov     %1,%0
2335         cmp/pl  %1
2336         mov.l   %1,%0
2337         sts     %1,%0
2338         movt    %0
2339         mov.l   %1,%0
2340         sts.l   %1,%0
2341         sts.l   %1,%0
2342         lds     %1,%0
2343         lds.l   %1,%0
2344         lds.l   %1,%0
2345         lds.l   %1,%0
2346         fake    %1,%0
2347         lds     %1,%0
2348         sts     %1,%0
2349         ! move optimized away"
2350   [(set_attr "type" "pcload_si,move,*,load_si,move,move,store,store,pstore,move,load,pload,load,pcload_si,gp_fpul,gp_fpul,nil")
2351    (set_attr "length" "*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,0")])
2352
2353 (define_insn "movsi_i_lowpart"
2354   [(set (strict_low_part (match_operand:SI 0 "general_movdst_operand" "+r,r,r,r,r,m,r"))
2355         (match_operand:SI 1 "general_movsrc_operand" "Q,rI,mr,xl,t,r,i"))]
2356    "register_operand (operands[0], SImode)
2357     || register_operand (operands[1], SImode)"
2358   "@
2359         mov.l   %1,%0
2360         mov     %1,%0
2361         mov.l   %1,%0
2362         sts     %1,%0
2363         movt    %0
2364         mov.l   %1,%0
2365         fake    %1,%0"
2366   [(set_attr "type" "pcload,move,load,move,move,store,pcload")])
2367
2368 (define_expand "movsi"
2369   [(set (match_operand:SI 0 "general_movdst_operand" "")
2370         (match_operand:SI 1 "general_movsrc_operand" ""))]
2371   ""
2372   "{ if (prepare_move_operands (operands, SImode)) DONE; }")
2373
2374 (define_expand "ic_invalidate_line"
2375   [(parallel [(unspec_volatile [(match_operand:SI 0 "register_operand" "+r")
2376                                 (match_dup 1)] 12)
2377               (clobber (scratch:SI))])]
2378   "TARGET_HARD_SH4"
2379   "
2380 {
2381   operands[0] = force_reg (Pmode, operands[0]);
2382   operands[1] = force_reg (Pmode, GEN_INT (0xf0000008));
2383 }")
2384
2385 ;; The address %0 is assumed to be 4-aligned at least.  Thus, by ORing
2386 ;; 0xf0000008, we get the low-oder bits *1*00 (binary), which fits
2387 ;; the requirement *1*00 for associative address writes.  The alignment of
2388 ;; %0 implies that its least significant bit is cleared,
2389 ;; thus we clear the V bit of a matching entry if there is one.
2390 (define_insn "ic_invalidate_line_i"
2391   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")
2392                      (match_operand:SI 1 "register_operand" "r")] 12)
2393    (clobber (match_scratch:SI 2 "=&r"))]
2394   "TARGET_HARD_SH4"
2395   "ocbwb\\t@%0\;extu.w\\t%0,%2\;or\\t%1,%2\;mov.l\\t%0,@%2"
2396   [(set_attr "length" "8")])
2397
2398 (define_insn "movqi_i"
2399   [(set (match_operand:QI 0 "general_movdst_operand" "=r,r,m,r,r,l")
2400         (match_operand:QI 1 "general_movsrc_operand"  "ri,m,r,t,l,r"))]
2401   "arith_reg_operand (operands[0], QImode)
2402    || arith_reg_operand (operands[1], QImode)"
2403   "@
2404         mov     %1,%0
2405         mov.b   %1,%0
2406         mov.b   %1,%0
2407         movt    %0
2408         sts     %1,%0
2409         lds     %1,%0"
2410  [(set_attr "type" "move,load,store,move,move,move")])
2411
2412 (define_expand "movqi"
2413   [(set (match_operand:QI 0 "general_operand" "")
2414         (match_operand:QI 1 "general_operand"  ""))]
2415   ""
2416   "{ if (prepare_move_operands (operands, QImode)) DONE; }")
2417
2418 (define_insn "movhi_i"
2419   [(set (match_operand:HI 0 "general_movdst_operand" "=r,r,r,r,m,r,l,r")
2420         (match_operand:HI 1 "general_movsrc_operand" "Q,rI,m,t,r,l,r,i"))]
2421   "arith_reg_operand (operands[0], HImode)
2422    || arith_reg_operand (operands[1], HImode)"
2423   "@
2424         mov.w   %1,%0
2425         mov     %1,%0
2426         mov.w   %1,%0
2427         movt    %0
2428         mov.w   %1,%0
2429         sts     %1,%0
2430         lds     %1,%0
2431         fake    %1,%0"
2432   [(set_attr "type" "pcload,move,load,move,store,move,move,pcload")])
2433
2434 (define_expand "movhi"
2435   [(set (match_operand:HI 0 "general_movdst_operand" "")
2436         (match_operand:HI 1 "general_movsrc_operand"  ""))]
2437   ""
2438   "{ if (prepare_move_operands (operands, HImode)) DONE; }")
2439
2440 ;; ??? This should be a define expand.
2441
2442 ;; x/r can be created by inlining/cse, e.g. for execute/961213-1.c
2443 ;; compiled with -m2 -ml -O3 -funroll-loops
2444 (define_insn ""
2445   [(set (match_operand:DI 0 "general_movdst_operand" "=r,r,r,m,r,r,r,*!x")
2446         (match_operand:DI 1 "general_movsrc_operand" "Q,r,m,r,I,i,x,r"))]
2447   "arith_reg_operand (operands[0], DImode)
2448    || arith_reg_operand (operands[1], DImode)"
2449   "* return output_movedouble (insn, operands, DImode);"
2450   [(set_attr "length" "4")
2451    (set_attr "type" "pcload,move,load,store,move,pcload,move,move")])
2452
2453 ;; If the output is a register and the input is memory or a register, we have
2454 ;; to be careful and see which word needs to be loaded first.  
2455
2456 (define_split
2457   [(set (match_operand:DI 0 "general_movdst_operand" "")
2458         (match_operand:DI 1 "general_movsrc_operand" ""))]
2459   "reload_completed"
2460   [(set (match_dup 2) (match_dup 3))
2461    (set (match_dup 4) (match_dup 5))]
2462   "
2463 {
2464   int regno;
2465
2466   if ((GET_CODE (operands[0]) == MEM
2467        && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
2468       || (GET_CODE (operands[1]) == MEM
2469           && GET_CODE (XEXP (operands[1], 0)) == POST_INC))
2470     FAIL;
2471
2472   if (GET_CODE (operands[0]) == REG)
2473     regno = REGNO (operands[0]);
2474   else if (GET_CODE (operands[0]) == SUBREG)
2475     regno = REGNO (SUBREG_REG (operands[0])) + SUBREG_WORD (operands[0]);
2476   else if (GET_CODE (operands[0]) == MEM)
2477     regno = -1;
2478
2479   if (regno == -1
2480       || ! refers_to_regno_p (regno, regno + 1, operands[1], 0))
2481     {
2482       operands[2] = operand_subword (operands[0], 0, 0, DImode);
2483       operands[3] = operand_subword (operands[1], 0, 0, DImode);
2484       operands[4] = operand_subword (operands[0], 1, 0, DImode);
2485       operands[5] = operand_subword (operands[1], 1, 0, DImode);
2486     }
2487   else
2488     {
2489       operands[2] = operand_subword (operands[0], 1, 0, DImode);
2490       operands[3] = operand_subword (operands[1], 1, 0, DImode);
2491       operands[4] = operand_subword (operands[0], 0, 0, DImode);
2492       operands[5] = operand_subword (operands[1], 0, 0, DImode);
2493     }
2494
2495   if (operands[2] == 0 || operands[3] == 0
2496       || operands[4] == 0 || operands[5] == 0)
2497     FAIL;
2498 }")
2499
2500 (define_expand "movdi"
2501   [(set (match_operand:DI 0 "general_movdst_operand" "")
2502         (match_operand:DI 1 "general_movsrc_operand" ""))]
2503   ""
2504   "{ if (prepare_move_operands (operands, DImode)) DONE; }")
2505
2506 ;; ??? This should be a define expand.
2507
2508 (define_insn "movdf_k"
2509   [(set (match_operand:DF 0 "general_movdst_operand" "=r,r,r,m")
2510         (match_operand:DF 1 "general_movsrc_operand" "r,FQ,m,r"))]
2511   "(! TARGET_SH4 || reload_completed
2512     /* ??? We provide some insn so that direct_{load,store}[DFmode] get set */
2513     || (GET_CODE (operands[0]) == REG && REGNO (operands[0]) == 3)
2514     || (GET_CODE (operands[1]) == REG && REGNO (operands[1]) == 3))
2515    && (arith_reg_operand (operands[0], DFmode)
2516        || arith_reg_operand (operands[1], DFmode))"
2517   "* return output_movedouble (insn, operands, DFmode);"
2518   [(set_attr "length" "4")
2519    (set_attr "type" "move,pcload,load,store")])
2520
2521 ;; All alternatives of movdf_i4 are split for ! TARGET_FMOVD.
2522 ;; However, the d/F/c/z alternative cannot be split directly; it is converted
2523 ;; with special code in machine_dependent_reorg into a load of the R0_REG and
2524 ;; the d/m/c/X alternative, which is split later into single-precision
2525 ;; instructions.  And when not optimizing, no splits are done before fixing
2526 ;; up pcloads, so we need usable length information for that.
2527 (define_insn "movdf_i4"
2528   [(set (match_operand:DF 0 "general_movdst_operand" "=d,r,d,d,m,r,r,m,!??r,!???d")
2529         (match_operand:DF 1 "general_movsrc_operand" "d,r,F,m,d,FQ,m,r,d,r"))
2530    (use (match_operand:PSI 2 "fpscr_operand" "c,c,c,c,c,c,c,c,c,c"))
2531    (clobber (match_scratch:SI 3 "=X,X,&z,X,X,X,X,X,X,X"))]
2532   "TARGET_SH4
2533    && (arith_reg_operand (operands[0], DFmode)
2534        || arith_reg_operand (operands[1], DFmode))"
2535   "@
2536         fmov    %1,%0
2537         #
2538         #
2539         fmov.d  %1,%0
2540         fmov.d  %1,%0
2541         #
2542         #
2543         #
2544         #
2545         #"
2546   [(set_attr_alternative "length"
2547      [(if_then_else (eq_attr "fmovd" "yes") (const_int 2) (const_int 4))
2548       (const_int 4)
2549       (if_then_else (eq_attr "fmovd" "yes") (const_int 4) (const_int 6))
2550       (if_then_else (eq_attr "fmovd" "yes") (const_int 2) (const_int 6))
2551       (if_then_else (eq_attr "fmovd" "yes") (const_int 2) (const_int 6))
2552       (const_int 4)
2553       (const_int 8) (const_int 8) ;; these need only 8 bytes for @(r0,rn)
2554       (const_int 8) (const_int 8)])
2555    (set_attr "type" "fmove,move,pcload,load,store,pcload,load,store,load,load")
2556    (set (attr "fp_mode") (if_then_else (eq_attr "fmovd" "yes")
2557                                            (const_string "double")
2558                                            (const_string "none")))])
2559
2560 ;; Moving DFmode between fp/general registers through memory
2561 ;; (the top of the stack) is faster than moving through fpul even for
2562 ;; little endian.  Because the type of an instruction is important for its
2563 ;; scheduling,  it is beneficial to split these operations, rather than
2564 ;; emitting them in one single chunk, even if this will expose a stack
2565 ;; use that will prevent scheduling of other stack accesses beyond this
2566 ;; instruction.
2567 (define_split
2568   [(set (match_operand:DF 0 "register_operand" "")
2569         (match_operand:DF 1 "register_operand" ""))
2570    (use (match_operand:PSI 2 "fpscr_operand" "c"))
2571    (clobber (match_scratch:SI 3 "=X"))]
2572   "TARGET_SH4 && reload_completed
2573    && (true_regnum (operands[0]) < 16) != (true_regnum (operands[1]) < 16)"
2574   [(const_int 0)]
2575   "
2576 {
2577   rtx insn, tos;
2578
2579   tos = gen_rtx (MEM, DFmode, gen_rtx (PRE_DEC, Pmode, stack_pointer_rtx));
2580   insn = emit_insn (gen_movdf_i4 (tos, operands[1], operands[2]));
2581   REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, stack_pointer_rtx, NULL_RTX);
2582   tos = gen_rtx (MEM, DFmode, gen_rtx (POST_INC, Pmode, stack_pointer_rtx));
2583   insn = emit_insn (gen_movdf_i4 (operands[0], tos, operands[2]));
2584   REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, stack_pointer_rtx, NULL_RTX);
2585   DONE;
2586 }")
2587
2588 ;; local-alloc sometimes allocates scratch registers even when not required,
2589 ;; so we must be prepared to handle these.
2590
2591 ;; Remove the use and clobber from a movdf_i4 so that we can use movdf_k.
2592 (define_split
2593   [(set (match_operand:DF 0 "general_movdst_operand" "")
2594         (match_operand:DF 1 "general_movsrc_operand"  ""))
2595    (use (match_operand:PSI 2 "fpscr_operand" "c"))
2596    (clobber (match_scratch:SI 3 "X"))]
2597   "TARGET_SH4
2598    && reload_completed
2599    && true_regnum (operands[0]) < 16
2600    && true_regnum (operands[1]) < 16"
2601   [(set (match_dup 0) (match_dup 1))]
2602   "
2603 {
2604   /* If this was a reg <-> mem operation with base + index reg addressing,
2605      we have to handle this in a special way.  */
2606   rtx mem = operands[0];
2607   int store_p = 1;
2608   if (! memory_operand (mem, DFmode))
2609     {
2610       mem = operands[1];
2611       store_p = 0;
2612     }
2613   if (GET_CODE (mem) == SUBREG && SUBREG_WORD (mem) == 0)
2614     mem = SUBREG_REG (mem);
2615   if (GET_CODE (mem) == MEM)
2616     {
2617       rtx addr = XEXP (mem, 0);
2618       if (GET_CODE (addr) == PLUS
2619           && GET_CODE (XEXP (addr, 0)) == REG
2620           && GET_CODE (XEXP (addr, 1)) == REG)
2621         {
2622           int offset;
2623           rtx reg0 = gen_rtx (REG, Pmode, 0);
2624           rtx regop = operands[store_p], word0 ,word1;
2625
2626           if (GET_CODE (regop) == SUBREG)
2627             regop = alter_subreg (regop);
2628           if (REGNO (XEXP (addr, 0)) == REGNO (XEXP (addr, 1)))
2629             offset = 2;
2630           else
2631             offset = 4;
2632           mem = copy_rtx (mem);
2633           PUT_MODE (mem, SImode);
2634           word0 = gen_rtx(SUBREG, SImode, regop, 0);
2635           emit_insn (store_p
2636                      ? gen_movsi_ie (mem, word0) : gen_movsi_ie (word0, mem));
2637           emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (offset)));
2638           mem = copy_rtx (mem);
2639           word1 = gen_rtx(SUBREG, SImode, regop, 1);
2640           emit_insn (store_p
2641                      ? gen_movsi_ie (mem, word1) : gen_movsi_ie (word1, mem));
2642           emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (-offset)));
2643           DONE;
2644         }
2645     }
2646 }")
2647
2648 ;; Split away the clobber of r0 after machine_dependent_reorg has fixed pcloads.
2649 (define_split
2650   [(set (match_operand:DF 0 "register_operand" "")
2651         (match_operand:DF 1 "memory_operand"  ""))
2652    (use (match_operand:PSI 2 "fpscr_operand" "c"))
2653    (clobber (reg:SI 0))]
2654   "TARGET_SH4 && reload_completed"
2655   [(parallel [(set (match_dup 0) (match_dup 1))
2656               (use (match_dup 2))
2657               (clobber (scratch:SI))])]
2658   "")
2659
2660 (define_expand "reload_indf"
2661   [(parallel [(set (match_operand:DF 0 "register_operand" "=f")
2662                    (match_operand:DF 1 "immediate_operand" "FQ"))
2663               (use (reg:PSI 48))
2664               (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
2665   ""
2666   "")
2667
2668 (define_expand "reload_outdf"
2669   [(parallel [(set (match_operand:DF 0 "register_operand" "=r,f")
2670                    (match_operand:DF 1 "register_operand" "af,r"))
2671               (clobber (match_operand:SI 2 "register_operand" "=&y,y"))])]
2672   ""
2673   "")
2674
2675 ;; Simplify no-op moves.
2676 (define_split
2677   [(set (match_operand:SF 0 "register_operand" "")
2678         (match_operand:SF 1 "register_operand" ""))
2679    (use (match_operand:PSI 2 "fpscr_operand" ""))
2680    (clobber (match_scratch:SI 3 "X"))]
2681   "TARGET_SH3E && reload_completed
2682    && true_regnum (operands[0]) == true_regnum (operands[1])"
2683   [(set (match_dup 0) (match_dup 0))]
2684   "")
2685
2686 ;; fmovd substitute post-reload splits
2687 (define_split
2688   [(set (match_operand:DF 0 "register_operand" "")
2689         (match_operand:DF 1 "register_operand" ""))
2690    (use (match_operand:PSI 2 "fpscr_operand" "c"))
2691    (clobber (match_scratch:SI 3 "X"))]
2692   "TARGET_SH4 && ! TARGET_FMOVD && reload_completed
2693    && true_regnum (operands[0]) >= FIRST_FP_REG
2694    && true_regnum (operands[1]) >= FIRST_FP_REG"
2695   [(const_int 0)]
2696   "
2697 {
2698   int dst = true_regnum (operands[0]), src = true_regnum (operands[1]);
2699   emit_insn (gen_movsf_ie (gen_rtx (REG, SFmode, dst),
2700                            gen_rtx (REG, SFmode, src), operands[2]));
2701   emit_insn (gen_movsf_ie (gen_rtx (REG, SFmode, dst + 1),
2702                            gen_rtx (REG, SFmode, src + 1), operands[2]));
2703   DONE;
2704 }")
2705
2706 (define_split
2707   [(set (match_operand:DF 0 "register_operand" "")
2708         (mem:DF (match_operand:SI 1 "register_operand" "")))
2709    (use (match_operand:PSI 2 "fpscr_operand" "c"))
2710    (clobber (match_scratch:SI 3 "X"))]
2711   "TARGET_SH4 && ! TARGET_FMOVD && reload_completed
2712    && true_regnum (operands[0]) >= FIRST_FP_REG
2713    && find_regno_note (insn, REG_DEAD, true_regnum (operands[1]))"
2714   [(const_int 0)]
2715   "
2716 {
2717   int regno = true_regnum (operands[0]);
2718   rtx insn;
2719   rtx mem2 = gen_rtx (MEM, SFmode, gen_rtx (POST_INC, Pmode, operands[1]));
2720
2721   insn = emit_insn (gen_movsf_ie (gen_rtx (REG, SFmode,
2722                                            regno + !! TARGET_LITTLE_ENDIAN),
2723                                   mem2, operands[2]));
2724   REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, operands[1], NULL_RTX);
2725   insn = emit_insn (gen_movsf_ie (gen_rtx (REG, SFmode,
2726                                            regno + ! TARGET_LITTLE_ENDIAN),
2727                                   gen_rtx (MEM, SFmode, operands[1]),
2728                                   operands[2]));
2729   DONE;
2730 }")
2731
2732 (define_split
2733   [(set (match_operand:DF 0 "register_operand" "")
2734         (match_operand:DF 1 "memory_operand" ""))
2735    (use (match_operand:PSI 2 "fpscr_operand" "c"))
2736    (clobber (match_scratch:SI 3 "X"))]
2737   "TARGET_SH4 && ! TARGET_FMOVD && reload_completed
2738    && true_regnum (operands[0]) >= FIRST_FP_REG"
2739   [(const_int 0)]
2740   "
2741 {
2742   int regno = true_regnum (operands[0]);
2743   rtx addr, insn, adjust = NULL_RTX;
2744   rtx mem2 = copy_rtx (operands[1]);
2745   rtx reg0 = gen_rtx_REG (SFmode, regno + !! TARGET_LITTLE_ENDIAN);
2746   rtx reg1 = gen_rtx_REG (SFmode, regno + ! TARGET_LITTLE_ENDIAN);
2747
2748   PUT_MODE (mem2, SFmode);
2749   operands[1] = copy_rtx (mem2);
2750   addr = XEXP (mem2, 0);
2751   if (GET_CODE (addr) != POST_INC)
2752     {
2753       /* If we have to modify the stack pointer, the value that we have
2754          read with post-increment might be modified by an interrupt,
2755          so write it back.  */
2756       if (REGNO (addr) == STACK_POINTER_REGNUM)
2757         adjust = gen_push_e (reg0);
2758       else
2759         adjust = gen_addsi3 (addr, addr, GEN_INT (-4));
2760       XEXP (mem2, 0) = addr = gen_rtx_POST_INC (SImode, addr);
2761     }
2762   addr = XEXP (addr, 0);
2763   insn = emit_insn (gen_movsf_ie (reg0, mem2, operands[2]));
2764   REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_INC, addr, NULL_RTX);
2765   insn = emit_insn (gen_movsf_ie (reg1, operands[1], operands[2]));
2766   if (adjust)
2767     emit_insn (adjust);
2768   else
2769     REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_INC, addr, NULL_RTX);
2770   DONE;
2771 }")
2772
2773 (define_split
2774   [(set (match_operand:DF 0 "memory_operand" "")
2775         (match_operand:DF 1 "register_operand" ""))
2776    (use (match_operand:PSI 2 "fpscr_operand" "c"))
2777    (clobber (match_scratch:SI 3 "X"))]
2778   "TARGET_SH4 && ! TARGET_FMOVD && reload_completed
2779    && true_regnum (operands[1]) >= FIRST_FP_REG"
2780   [(const_int 0)]
2781   "
2782 {
2783   int regno = true_regnum (operands[1]);
2784   rtx insn, addr, adjust = NULL_RTX;
2785
2786   operands[0] = copy_rtx (operands[0]);
2787   PUT_MODE (operands[0], SFmode);
2788   insn = emit_insn (gen_movsf_ie (operands[0],
2789                                   gen_rtx (REG, SFmode,
2790                                            regno + ! TARGET_LITTLE_ENDIAN),
2791                                   operands[2]));
2792   operands[0] = copy_rtx (operands[0]);
2793   addr = XEXP (operands[0], 0);
2794   if (GET_CODE (addr) != PRE_DEC)
2795     {
2796       adjust = gen_addsi3 (addr, addr, GEN_INT (4));
2797       emit_insn_before (adjust, insn);
2798       XEXP (operands[0], 0) = addr = gen_rtx (PRE_DEC, SImode, addr);
2799     }
2800   addr = XEXP (addr, 0);
2801   if (! adjust)
2802     REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, addr, NULL_RTX);
2803   insn = emit_insn (gen_movsf_ie (operands[0],
2804                                   gen_rtx (REG, SFmode,
2805                                            regno + !! TARGET_LITTLE_ENDIAN),
2806                                   operands[2]));
2807   REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, addr, NULL_RTX);
2808   DONE;
2809 }")
2810
2811 ;; The '&' for operand 2 is not really true, but push_secondary_reload
2812 ;; insists on it.
2813 ;; Operand 1 must accept FPUL_REGS in case fpul is reloaded to memory,
2814 ;; to avoid a bogus tertiary reload.
2815 ;; We need a tertiary reload when a floating point register is reloaded
2816 ;; to memory, so the predicate for operand 0 must accept this, while the 
2817 ;; constraint of operand 1 must reject the secondary reload register.
2818 ;; Thus, the secondary reload register for this case has to be GENERAL_REGS,
2819 ;; too.
2820 ;; By having the predicate for operand 0 reject any register, we make
2821 ;; sure that the ordinary moves that just need an intermediate register
2822 ;; won't get a bogus tertiary reload.
2823 ;; We use tertiary_reload_operand instead of memory_operand here because
2824 ;; memory_operand rejects operands that are not directly addressible, e.g.:
2825 ;; (mem:SF (plus:SI (reg:SI 14 r14)
2826 ;;         (const_int 132)))
2827
2828 (define_expand "reload_outsf"
2829   [(parallel [(set (match_operand:SF 2 "register_operand" "=&r")
2830                    (match_operand:SF 1 "register_operand" "y"))
2831               (clobber (scratch:SI))])
2832    (parallel [(set (match_operand:SF 0 "tertiary_reload_operand" "=m")
2833                    (match_dup 2))
2834               (clobber (scratch:SI))])]
2835   ""
2836   "")
2837
2838 ;; If the output is a register and the input is memory or a register, we have
2839 ;; to be careful and see which word needs to be loaded first.  
2840
2841 (define_split
2842   [(set (match_operand:DF 0 "general_movdst_operand" "")
2843         (match_operand:DF 1 "general_movsrc_operand" ""))]
2844   "reload_completed"
2845   [(set (match_dup 2) (match_dup 3))
2846    (set (match_dup 4) (match_dup 5))]
2847   "
2848 {
2849   int regno;
2850
2851   if ((GET_CODE (operands[0]) == MEM
2852        && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
2853       || (GET_CODE (operands[1]) == MEM
2854           && GET_CODE (XEXP (operands[1], 0)) == POST_INC))
2855     FAIL;
2856
2857   if (GET_CODE (operands[0]) == REG)
2858     regno = REGNO (operands[0]);
2859   else if (GET_CODE (operands[0]) == SUBREG)
2860     regno = REGNO (SUBREG_REG (operands[0])) + SUBREG_WORD (operands[0]);
2861   else if (GET_CODE (operands[0]) == MEM)
2862     regno = -1;
2863
2864   if (regno == -1
2865       || ! refers_to_regno_p (regno, regno + 1, operands[1], 0))
2866     {
2867       operands[2] = operand_subword (operands[0], 0, 0, DFmode);
2868       operands[3] = operand_subword (operands[1], 0, 0, DFmode);
2869       operands[4] = operand_subword (operands[0], 1, 0, DFmode);
2870       operands[5] = operand_subword (operands[1], 1, 0, DFmode);
2871     }
2872   else
2873     {
2874       operands[2] = operand_subword (operands[0], 1, 0, DFmode);
2875       operands[3] = operand_subword (operands[1], 1, 0, DFmode);
2876       operands[4] = operand_subword (operands[0], 0, 0, DFmode);
2877       operands[5] = operand_subword (operands[1], 0, 0, DFmode);
2878     }
2879
2880   if (operands[2] == 0 || operands[3] == 0
2881       || operands[4] == 0 || operands[5] == 0)
2882     FAIL;
2883 }")
2884
2885 ;; If a base address generated by LEGITIMIZE_ADDRESS for SImode is
2886 ;; used only once, let combine add in the index again.
2887
2888 (define_split
2889   [(set (match_operand:SI 0 "register_operand" "")
2890         (match_operand:SI 1 "" ""))
2891    (clobber (match_operand 2 "register_operand" ""))]
2892   "! reload_in_progress && ! reload_completed"
2893   [(use (reg:SI 0))]
2894   "
2895 {
2896   rtx addr, reg, const_int;
2897
2898   if (GET_CODE (operands[1]) != MEM)
2899     FAIL;
2900   addr = XEXP (operands[1], 0);
2901   if (GET_CODE (addr) != PLUS)
2902     FAIL;
2903   reg = XEXP (addr, 0);
2904   const_int = XEXP (addr, 1);
2905   if (! (BASE_REGISTER_RTX_P (reg) && INDEX_REGISTER_RTX_P (operands[2])
2906          && GET_CODE (const_int) == CONST_INT))
2907     FAIL;
2908   emit_move_insn (operands[2], const_int);
2909   emit_move_insn (operands[0],
2910                   change_address (operands[1], VOIDmode,
2911                                   gen_rtx_PLUS (SImode, reg, operands[2])));
2912   DONE;
2913 }")
2914
2915 (define_split
2916   [(set (match_operand:SI 1 "" "")
2917         (match_operand:SI 0 "register_operand" ""))
2918    (clobber (match_operand 2 "register_operand" ""))]
2919   "! reload_in_progress && ! reload_completed"
2920   [(use (reg:SI 0))]
2921   "
2922 {
2923   rtx addr, reg, const_int;
2924
2925   if (GET_CODE (operands[1]) != MEM)
2926     FAIL;
2927   addr = XEXP (operands[1], 0);
2928   if (GET_CODE (addr) != PLUS)
2929     FAIL;
2930   reg = XEXP (addr, 0);
2931   const_int = XEXP (addr, 1);
2932   if (! (BASE_REGISTER_RTX_P (reg) && INDEX_REGISTER_RTX_P (operands[2])
2933          && GET_CODE (const_int) == CONST_INT))
2934     FAIL;
2935   emit_move_insn (operands[2], const_int);
2936   emit_move_insn (change_address (operands[1], VOIDmode,
2937                                   gen_rtx_PLUS (SImode, reg, operands[2])),
2938                   operands[0]);
2939   DONE;
2940 }")
2941
2942 (define_expand "movdf"
2943   [(set (match_operand:DF 0 "general_movdst_operand" "")
2944         (match_operand:DF 1 "general_movsrc_operand" ""))]
2945   ""
2946   "
2947 {
2948   if (prepare_move_operands (operands, DFmode)) DONE;
2949   if (TARGET_SH4)
2950     {
2951       emit_df_insn (gen_movdf_i4 (operands[0], operands[1], get_fpscr_rtx ()));
2952       DONE;
2953     }
2954 }")
2955
2956
2957 (define_insn "movsf_i"
2958   [(set (match_operand:SF 0 "general_movdst_operand" "=r,r,r,r,m,l,r")
2959         (match_operand:SF 1 "general_movsrc_operand"  "r,I,FQ,mr,r,r,l"))]
2960   "
2961    (! TARGET_SH3E
2962     /* ??? We provide some insn so that direct_{load,store}[SFmode] get set */
2963     || (GET_CODE (operands[0]) == REG && REGNO (operands[0]) == 3)
2964     || (GET_CODE (operands[1]) == REG && REGNO (operands[1]) == 3))
2965    && (arith_reg_operand (operands[0], SFmode)
2966        || arith_reg_operand (operands[1], SFmode))"
2967   "@
2968         mov     %1,%0
2969         mov     %1,%0
2970         mov.l   %1,%0
2971         mov.l   %1,%0
2972         mov.l   %1,%0
2973         lds     %1,%0
2974         sts     %1,%0"
2975   [(set_attr "type" "move,move,pcload,load,store,move,move")])
2976
2977 ;; We may not split the ry/yr/XX alternatives to movsi_ie, since
2978 ;; update_flow_info would not know where to put REG_EQUAL notes
2979 ;; when the destination changes mode.
2980 (define_insn "movsf_ie"
2981   [(set (match_operand:SF 0 "general_movdst_operand"
2982          "=f,r,f,f,fy,f,m,r,r,m,f,y,y,rf,r,y,y")
2983         (match_operand:SF 1 "general_movsrc_operand"
2984           "f,r,G,H,FQ,mf,f,FQ,mr,r,y,f,>,fr,y,r,y"))
2985    (use (match_operand:PSI 2 "fpscr_operand" "c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c"))
2986    (clobber (match_scratch:SI 3 "=X,X,X,X,&z,X,X,X,X,X,X,X,X,y,X,X,X"))]
2987
2988   "TARGET_SH3E
2989    && (arith_reg_operand (operands[0], SFmode)
2990        || arith_reg_operand (operands[1], SFmode))"
2991   "@
2992         fmov    %1,%0
2993         mov     %1,%0
2994         fldi0   %0
2995         fldi1   %0
2996         #
2997         fmov.s  %1,%0
2998         fmov.s  %1,%0
2999         mov.l   %1,%0
3000         mov.l   %1,%0
3001         mov.l   %1,%0
3002         fsts    fpul,%0
3003         flds    %1,fpul
3004         lds.l   %1,%0
3005         #
3006         sts     %1,%0
3007         lds     %1,%0
3008         ! move optimized away"
3009   [(set_attr "type" "fmove,move,fmove,fmove,pcload,load,store,pcload,load,store,fmove,fmove,load,*,gp_fpul,gp_fpul,nil")
3010    (set_attr "length" "*,*,*,*,4,*,*,*,*,*,2,2,2,4,2,2,0")
3011    (set (attr "fp_mode") (if_then_else (eq_attr "fmovd" "yes")
3012                                            (const_string "single")
3013                                            (const_string "none")))])
3014 (define_split
3015   [(set (match_operand:SF 0 "register_operand" "")
3016         (match_operand:SF 1 "register_operand" ""))
3017    (use (match_operand:PSI 2 "fpscr_operand" "c"))
3018    (clobber (reg:SI 22))]
3019   ""
3020   [(parallel [(set (reg:SF 22) (match_dup 1))
3021               (use (match_dup 2))
3022               (clobber (scratch:SI))])
3023    (parallel [(set (match_dup 0) (reg:SF 22))
3024               (use (match_dup 2))
3025               (clobber (scratch:SI))])]
3026   "")
3027
3028 (define_expand "movsf"
3029   [(set (match_operand:SF 0 "general_movdst_operand" "")
3030         (match_operand:SF 1 "general_movsrc_operand" ""))]
3031   ""
3032   "
3033 {
3034   if (prepare_move_operands (operands, SFmode))
3035     DONE;
3036   if (TARGET_SH3E)
3037     {
3038       emit_sf_insn (gen_movsf_ie (operands[0], operands[1], get_fpscr_rtx ()));
3039       DONE;
3040     }
3041 }")
3042
3043 (define_insn "mov_nop"
3044   [(set (match_operand 0 "register_operand" "") (match_dup 0))]
3045   "TARGET_SH3E"
3046   ""
3047   [(set_attr "length" "0")
3048    (set_attr "type" "nil")])
3049
3050 (define_expand "reload_insf"
3051   [(parallel [(set (match_operand:SF 0 "register_operand" "=f")
3052                    (match_operand:SF 1 "immediate_operand" "FQ"))
3053               (use (reg:PSI 48))
3054               (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
3055   ""
3056   "")
3057
3058 (define_expand "reload_insi"
3059   [(parallel [(set (match_operand:SF 0 "register_operand" "=y")
3060                    (match_operand:SF 1 "immediate_operand" "FQ"))
3061               (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
3062   ""
3063   "")
3064
3065 (define_insn "*movsi_y"
3066   [(set (match_operand:SI 0 "register_operand" "=y,y")
3067         (match_operand:SI 1 "immediate_operand" "Qi,I"))
3068    (clobber (match_scratch:SI 3 "=&z,r"))]
3069   "TARGET_SH3E
3070    && (reload_in_progress || reload_completed)"
3071   "#"
3072   [(set_attr "length" "4")
3073    (set_attr "type" "pcload,move")])
3074
3075 (define_split
3076   [(set (match_operand:SI 0 "register_operand" "")
3077         (match_operand:SI 1 "immediate_operand" ""))
3078    (clobber (match_operand:SI 2 "register_operand" ""))]
3079   ""
3080   [(set (match_dup 2) (match_dup 1))
3081    (set (match_dup 0) (match_dup 2))]
3082   "")
3083
3084 (define_split
3085   [(set (match_operand:SI 0 "register_operand" "")
3086         (match_operand:SI 1 "memory_operand" ""))
3087    (clobber (reg:SI 0))]
3088   ""
3089   [(set (match_dup 0) (match_dup 1))]
3090   "")
3091 \f
3092 ;; ------------------------------------------------------------------------
3093 ;; Define the real conditional branch instructions.
3094 ;; ------------------------------------------------------------------------
3095
3096 (define_insn "branch_true"
3097   [(set (pc) (if_then_else (ne (reg:SI 18) (const_int 0))
3098                            (label_ref (match_operand 0 "" ""))
3099                            (pc)))]
3100   ""
3101   "* return output_branch (1, insn, operands);"
3102   [(set_attr "type" "cbranch")])
3103
3104 (define_insn "branch_false"
3105   [(set (pc) (if_then_else (eq (reg:SI 18) (const_int 0))
3106                            (label_ref (match_operand 0 "" ""))
3107                            (pc)))]
3108   ""
3109   "* return output_branch (0, insn, operands);"
3110   [(set_attr "type" "cbranch")])
3111
3112 ;; Patterns to prevent reorg from re-combining a condbranch with a branch
3113 ;; which destination is too far away.
3114 ;; The const_int_operand is distinct for each branch target; it avoids
3115 ;; unwanted matches with redundant_insn.
3116 (define_insn "block_branch_redirect"
3117   [(set (pc) (unspec [(match_operand 0 "const_int_operand" "")] 4))]
3118   ""
3119   ""
3120   [(set_attr "length" "0")])
3121
3122 ;; This one has the additional purpose to record a possible scratch register
3123 ;; for the following branch.
3124 (define_insn "indirect_jump_scratch"
3125   [(set (match_operand 0 "register_operand" "=r")
3126         (unspec [(match_operand 1 "const_int_operand" "")] 4))]
3127   ""
3128   ""
3129   [(set_attr "length" "0")])
3130 \f
3131 ;; Conditional branch insns
3132
3133 (define_expand "beq"
3134   [(set (pc)
3135         (if_then_else (ne (reg:SI 18) (const_int 0))
3136                       (label_ref (match_operand 0 "" ""))
3137                       (pc)))]
3138   ""
3139   "from_compare (operands, EQ);")
3140
3141 (define_expand "bne"
3142   [(set (pc)
3143         (if_then_else (eq (reg:SI 18) (const_int 0))
3144                       (label_ref (match_operand 0 "" ""))
3145                       (pc)))]
3146   ""
3147   "from_compare (operands, EQ);")
3148
3149 (define_expand "bgt"
3150   [(set (pc)
3151         (if_then_else (ne (reg:SI 18) (const_int 0))
3152                       (label_ref (match_operand 0 "" ""))
3153                       (pc)))]
3154   ""
3155   "from_compare (operands, GT);")
3156
3157 (define_expand "blt"
3158   [(set (pc)
3159         (if_then_else (eq (reg:SI 18) (const_int 0))
3160                       (label_ref (match_operand 0 "" ""))
3161                       (pc)))]
3162   ""
3163   "
3164 {
3165   if (GET_MODE_CLASS (GET_MODE (sh_compare_op0)) == MODE_FLOAT)
3166     {
3167       rtx tmp = sh_compare_op0;
3168       sh_compare_op0 = sh_compare_op1;
3169       sh_compare_op1 = tmp;
3170       emit_insn (gen_bgt (operands[0]));
3171       DONE;
3172     }
3173   from_compare (operands, GE);
3174 }")
3175
3176 (define_expand "ble"
3177   [(set (pc)
3178         (if_then_else (eq (reg:SI 18) (const_int 0))
3179                       (label_ref (match_operand 0 "" ""))
3180                       (pc)))]
3181   ""
3182   "
3183 {
3184   if (TARGET_SH3E
3185       && TARGET_IEEE
3186       && GET_MODE_CLASS (GET_MODE (sh_compare_op0)) == MODE_FLOAT)
3187     {
3188       rtx tmp = sh_compare_op0;
3189       sh_compare_op0 = sh_compare_op1;
3190       sh_compare_op1 = tmp;
3191       emit_insn (gen_bge (operands[0]));
3192       DONE;
3193     }
3194   from_compare (operands, GT);
3195 }")
3196
3197 (define_expand "bge"
3198   [(set (pc)
3199         (if_then_else (ne (reg:SI 18) (const_int 0))
3200                       (label_ref (match_operand 0 "" ""))
3201                       (pc)))]
3202   ""
3203   "
3204 {
3205   if (TARGET_SH3E
3206       && ! TARGET_IEEE
3207       && GET_MODE_CLASS (GET_MODE (sh_compare_op0)) == MODE_FLOAT)
3208     {
3209       rtx tmp = sh_compare_op0;
3210       sh_compare_op0 = sh_compare_op1;
3211       sh_compare_op1 = tmp;
3212       emit_insn (gen_ble (operands[0]));
3213       DONE;
3214     }
3215   from_compare (operands, GE);
3216 }")
3217
3218 (define_expand "bgtu"
3219   [(set (pc)
3220         (if_then_else (ne (reg:SI 18) (const_int 0))
3221                       (label_ref (match_operand 0 "" ""))
3222                       (pc)))]
3223   ""
3224   "from_compare (operands, GTU); ")
3225
3226 (define_expand "bltu"
3227   [(set (pc)
3228                   (if_then_else (eq (reg:SI 18) (const_int 0))
3229                                 (label_ref (match_operand 0 "" ""))
3230                                 (pc)))]
3231   ""
3232   "from_compare (operands, GEU);")
3233
3234 (define_expand "bgeu"
3235   [(set (pc)
3236         (if_then_else (ne (reg:SI 18) (const_int 0))
3237                       (label_ref (match_operand 0 "" ""))
3238                       (pc)))]
3239   ""
3240   "from_compare (operands, GEU);")
3241
3242 (define_expand "bleu"
3243   [(set (pc)
3244         (if_then_else (eq (reg:SI 18) (const_int 0))
3245                       (label_ref (match_operand 0 "" ""))
3246                       (pc)))]
3247   ""
3248   "from_compare (operands, GTU);")
3249 \f
3250 ;; ------------------------------------------------------------------------
3251 ;; Jump and linkage insns
3252 ;; ------------------------------------------------------------------------
3253
3254 (define_insn "jump"
3255   [(set (pc)
3256         (label_ref (match_operand 0 "" "")))]
3257   ""
3258   "*
3259 {
3260   /* The length is 16 if the delay slot is unfilled.  */
3261   if (get_attr_length(insn) > 4)
3262     return output_far_jump(insn, operands[0]);
3263   else
3264     return   \"bra      %l0%#\";
3265 }"
3266   [(set_attr "type" "jump")
3267    (set_attr "needs_delay_slot" "yes")])
3268
3269 (define_insn "calli"
3270   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
3271          (match_operand 1 "" ""))
3272    (use (reg:SI 48))
3273    (clobber (reg:SI 17))]
3274   ""
3275   "jsr  @%0%#"
3276   [(set_attr "type" "call")
3277    (set (attr "fp_mode")
3278         (if_then_else (eq_attr "fpu_single" "yes")
3279                       (const_string "single") (const_string "double")))
3280    (set_attr "needs_delay_slot" "yes")])
3281
3282 ;; This is a pc-rel call, using bsrf, for use with PIC.
3283
3284 (define_insn "calli_pcrel"
3285   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
3286          (match_operand 1 "" ""))
3287    (use (reg:SI 48))
3288    (use (match_operand 2 "" ""))
3289    (clobber (reg:SI 17))]
3290   ""
3291   "bsrf %0\\n%O2:%#"
3292   [(set_attr "type" "call")
3293    (set (attr "fp_mode")
3294         (if_then_else (eq_attr "fpu_single" "yes")
3295                       (const_string "single") (const_string "double")))
3296    (set_attr "needs_delay_slot" "yes")])
3297
3298 (define_insn "call_valuei"
3299   [(set (match_operand 0 "" "=rf")
3300         (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
3301               (match_operand 2 "" "")))
3302    (use (reg:SI 48))
3303    (clobber (reg:SI 17))]
3304   ""
3305   "jsr  @%1%#"
3306   [(set_attr "type" "call")
3307    (set (attr "fp_mode")
3308         (if_then_else (eq_attr "fpu_single" "yes")
3309                       (const_string "single") (const_string "double")))
3310    (set_attr "needs_delay_slot" "yes")])
3311
3312 (define_insn "call_valuei_pcrel"
3313   [(set (match_operand 0 "" "=rf")
3314         (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
3315               (match_operand 2 "" "")))
3316    (use (reg:SI 48))
3317    (use (match_operand 3 "" ""))
3318    (clobber (reg:SI 17))]
3319   ""
3320   "bsrf %1\\n%O3:%#"
3321   [(set_attr "type" "call")
3322    (set (attr "fp_mode")
3323         (if_then_else (eq_attr "fpu_single" "yes")
3324                       (const_string "single") (const_string "double")))
3325    (set_attr "needs_delay_slot" "yes")])
3326
3327 (define_expand "call"
3328   [(parallel [(call (mem:SI (match_operand 0 "arith_reg_operand" ""))
3329                             (match_operand 1 "" ""))
3330               (use (reg:SI 48))
3331               (clobber (reg:SI 17))])]
3332   ""
3333   "
3334 if (flag_pic && ! TARGET_SH1 && ! flag_unroll_loops
3335     && GET_CODE (operands[0]) == MEM
3336     && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
3337   {
3338     rtx reg = gen_reg_rtx (SImode), lab = gen_label_rtx ();
3339
3340     if (SYMBOL_REF_FLAG (XEXP (operands[0], 0)))
3341       emit_insn (gen_sym_label2reg (reg, XEXP (operands[0], 0), lab));
3342     else
3343       emit_insn (gen_symPLT_label2reg (reg, XEXP (operands[0], 0), lab));
3344     operands[0] = reg;
3345     emit_call_insn (gen_calli_pcrel (operands[0], operands[1], lab));
3346     DONE;
3347   }
3348 else
3349   operands[0] = force_reg (SImode, XEXP (operands[0], 0));")
3350
3351 (define_expand "call_value"
3352   [(parallel [(set (match_operand 0 "arith_reg_operand" "")
3353                    (call (mem:SI (match_operand 1 "arith_reg_operand" ""))
3354                                  (match_operand 2 "" "")))
3355               (use (reg:SI 48))
3356               (clobber (reg:SI 17))])]
3357   ""
3358   "
3359 if (flag_pic && ! TARGET_SH1 && ! flag_unroll_loops
3360     && GET_CODE (operands[1]) == MEM
3361     && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
3362   {
3363     rtx reg = gen_reg_rtx (SImode), lab = gen_label_rtx ();
3364
3365     if (SYMBOL_REF_FLAG (XEXP (operands[1], 0)))
3366       emit_insn (gen_sym_label2reg (reg, XEXP (operands[1], 0), lab));
3367     else
3368       emit_insn (gen_symPLT_label2reg (reg, XEXP (operands[1], 0), lab));
3369     operands[1] = reg;
3370     emit_call_insn (gen_call_valuei_pcrel (operands[0], operands[1],
3371                                            operands[2], lab));
3372     DONE;
3373   }
3374 else
3375   operands[1] = force_reg (SImode, XEXP (operands[1], 0));")
3376
3377 (define_insn "indirect_jump"
3378   [(set (pc)
3379         (match_operand:SI 0 "arith_reg_operand" "r"))]
3380   ""
3381   "jmp  @%0%#"
3382   [(set_attr "needs_delay_slot" "yes")
3383    (set_attr "type" "jump_ind")])
3384
3385 ;; The use of operand 1 / 2 helps us distinguish case table jumps
3386 ;; which can be present in structured code from indirect jumps which can not
3387 ;; be present in structured code.  This allows -fprofile-arcs to work.
3388
3389 ;; For SH1 processors.
3390 (define_insn "casesi_jump_1"
3391   [(set (pc)
3392         (match_operand:SI 0 "register_operand" "r"))
3393    (use (label_ref (match_operand 1 "" "")))]
3394   ""
3395   "jmp  @%0%#"
3396   [(set_attr "needs_delay_slot" "yes")
3397    (set_attr "type" "jump_ind")])
3398
3399 ;; For all later processors.
3400 (define_insn "casesi_jump_2"
3401   [(set (pc) (plus:SI (match_operand:SI 0 "register_operand" "r")
3402                       (label_ref (match_operand 1 "" ""))))
3403    (use (label_ref (match_operand 2 "" "")))]
3404   "! INSN_UID (operands[1]) || prev_real_insn (operands[1]) == insn"
3405   "braf %0%#"
3406   [(set_attr "needs_delay_slot" "yes")
3407    (set_attr "type" "jump_ind")])
3408
3409 ;; Call subroutine returning any type.
3410 ;; ??? This probably doesn't work.
3411
3412 (define_expand "untyped_call"
3413   [(parallel [(call (match_operand 0 "" "")
3414                     (const_int 0))
3415               (match_operand 1 "" "")
3416               (match_operand 2 "" "")])]
3417   "TARGET_SH3E"
3418   "
3419 {
3420   int i;
3421
3422   emit_call_insn (gen_call (operands[0], const0_rtx));
3423
3424   for (i = 0; i < XVECLEN (operands[2], 0); i++)
3425     {
3426       rtx set = XVECEXP (operands[2], 0, i);
3427       emit_move_insn (SET_DEST (set), SET_SRC (set));
3428     }
3429
3430   /* The optimizer does not know that the call sets the function value
3431      registers we stored in the result block.  We avoid problems by
3432      claiming that all hard registers are used and clobbered at this
3433      point.  */
3434   emit_insn (gen_blockage ());
3435
3436   DONE;
3437 }")
3438 \f
3439 ;; ------------------------------------------------------------------------
3440 ;; Misc insns
3441 ;; ------------------------------------------------------------------------
3442
3443 (define_insn "dect"
3444   [(set (reg:SI 18)
3445         (eq:SI (match_operand:SI 0 "arith_reg_operand" "+r") (const_int 1)))
3446    (set (match_dup 0) (plus:SI (match_dup 0) (const_int -1)))]
3447   "TARGET_SH2"
3448   "dt   %0"
3449   [(set_attr "type" "arith")])
3450
3451 (define_insn "nop"
3452   [(const_int 0)]
3453   ""
3454   "nop")
3455
3456 ;; Load address of a label. This is only generated by the casesi expand,
3457 ;; and by machine_dependent_reorg (fixing up fp moves).
3458 ;; This must use unspec, because this only works for labels that are
3459 ;; within range,
3460
3461 (define_insn "mova"
3462   [(set (reg:SI 0)
3463         (unspec [(label_ref (match_operand 0 "" ""))] 1))]
3464   ""
3465   "mova %O0,r0"
3466   [(set_attr "in_delay_slot" "no")
3467    (set_attr "type" "arith")])
3468
3469 (define_expand "GOTaddr2picreg"
3470   [(set (reg:SI 0) (const (unspec [(const (unspec [(match_dup 1)] 6))] 1)))
3471   (set (match_dup 0) (const (unspec [(match_dup 1)] 6)))
3472   (set (match_dup 0) (plus:SI (match_dup 0) (reg:SI 0)))]
3473   "" "
3474 {
3475   operands[0] = pic_offset_table_rtx;
3476   current_function_uses_pic_offset_table = 1;
3477   operands[1] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);
3478 }
3479 ")
3480
3481 (define_expand "sym_label2reg"
3482   [(set (match_operand:SI 0 "" "")
3483         (const (minus:SI
3484                 (unspec [(match_operand:SI 1 "" "")] 6)
3485                 (const (plus:SI
3486                         (unspec [(label_ref (match_operand:SI 2 "" ""))] 6)
3487                         (const_int 2))))))]
3488   "" "")
3489
3490 (define_expand "symGOT2reg"
3491   [(set (match_operand:SI 0 "" "")
3492         (const (unspec [(match_operand:SI 1 "" "")] 7)))
3493   (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))
3494   (set (match_dup 0) (mem:SI (match_dup 0)))]
3495   ""
3496   "
3497 {
3498   operands[2] = pic_offset_table_rtx;
3499   current_function_uses_pic_offset_table = 1;
3500 }")
3501
3502 (define_expand "symGOTOFF2reg"
3503   [(set (match_operand:SI 0 "" "")
3504         (const (unspec [(match_operand:SI 1 "" "")] 8)))
3505   (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
3506   ""
3507   "
3508 {
3509   operands[2] = pic_offset_table_rtx;
3510   current_function_uses_pic_offset_table = 1;
3511 }")
3512
3513 (define_expand "symPLT_label2reg"
3514   [(set (match_operand:SI 0 "" "")
3515         (const (minus:SI
3516                 (plus:SI (pc)
3517                          (unspec [(match_operand:SI 1 "" "")] 9))
3518                 (const
3519                  (plus:SI
3520                   (unspec [(label_ref (match_operand:SI 2 "" ""))] 6)
3521                   (const_int 2))))))
3522    (use (match_dup 3))]
3523   ;; Even though the PIC register is not really used by the call
3524   ;; sequence in which this is expanded, the PLT code assumes the PIC
3525   ;; register is set, so we must not skip its initialization.  Since
3526   ;; we only use this expand as part of calling sequences, and never
3527   ;; to take the address of a function, this is the best point to
3528   ;; insert the (use).  Using the PLT to take the address of a
3529   ;; function would be wrong, not only because the PLT entry could
3530   ;; then be called from a function that doesn't initialize the PIC
3531   ;; register to the proper GOT, but also because pointers to the same
3532   ;; function might not compare equal, should they be set by different
3533   ;; shared libraries.
3534   "" "
3535 {
3536   operands[3] = pic_offset_table_rtx;
3537   current_function_uses_pic_offset_table = 1;
3538 }")
3539
3540 ;; case instruction for switch statements.
3541
3542 ;; Operand 0 is index
3543 ;; operand 1 is the minimum bound
3544 ;; operand 2 is the maximum bound - minimum bound + 1
3545 ;; operand 3 is CODE_LABEL for the table;
3546 ;; operand 4 is the CODE_LABEL to go to if index out of range.
3547
3548 (define_expand "casesi"
3549   [(match_operand:SI 0 "arith_reg_operand" "")
3550    (match_operand:SI 1 "arith_reg_operand" "")
3551    (match_operand:SI 2 "arith_reg_operand" "")
3552    (match_operand 3 "" "") (match_operand 4 "" "")]
3553   ""
3554   "
3555 {
3556   rtx reg = gen_reg_rtx (SImode);
3557   rtx reg2 = gen_reg_rtx (SImode);
3558   operands[1] = copy_to_mode_reg (SImode, operands[1]);
3559   operands[2] = copy_to_mode_reg (SImode, operands[2]);
3560   /* If optimizing, casesi_worker depends on the mode of the instruction
3561      before label it 'uses' - operands[3].  */
3562   emit_insn (gen_casesi_0 (operands[0], operands[1], operands[2], operands[4],
3563                            reg));
3564   emit_insn (gen_casesi_worker_0 (reg2, reg, operands[3]));
3565   if (TARGET_SH2)
3566     emit_jump_insn (gen_casesi_jump_2 (reg2, gen_label_rtx (), operands[3]));
3567   else
3568     emit_jump_insn (gen_casesi_jump_1 (reg2, operands[3]));
3569   /* For SH2 and newer, the ADDR_DIFF_VEC is not actually relative to
3570      operands[3], but to lab.  We will fix this up in
3571      machine_dependent_reorg.  */
3572   emit_barrier ();
3573   DONE;
3574 }")
3575
3576 (define_expand "casesi_0"
3577   [(set (match_operand:SI 4 "" "") (match_operand:SI 0 "arith_reg_operand" ""))
3578    (set (match_dup 4) (minus:SI (match_dup 4)
3579                                 (match_operand:SI 1 "arith_operand" "")))
3580    (set (reg:SI 18)
3581         (gtu:SI (match_dup 4)
3582                 (match_operand:SI 2 "arith_reg_operand" "")))
3583    (set (pc)
3584         (if_then_else (ne (reg:SI 18)
3585                           (const_int 0))
3586                       (label_ref (match_operand 3 "" ""))
3587                       (pc)))]
3588   ""
3589   "")
3590
3591 ;; ??? reload might clobber r0 if we use it explicitly in the RTL before
3592 ;; reload; using a R0_REGS pseudo reg is likely to give poor code.
3593 ;; So we keep the use of r0 hidden in a R0_REGS clobber until after reload.
3594
3595 (define_insn "casesi_worker_0"
3596   [(set (match_operand:SI 0 "register_operand" "=r,r")
3597         (unspec [(match_operand 1 "register_operand" "0,r")
3598                  (label_ref (match_operand 2 "" ""))] 2))
3599    (clobber (match_scratch:SI 3 "=X,1"))
3600    (clobber (match_scratch:SI 4 "=&z,z"))]
3601   ""
3602   "#")
3603
3604 (define_split
3605   [(set (match_operand:SI 0 "register_operand" "")
3606         (unspec [(match_operand 1 "register_operand" "")
3607                  (label_ref (match_operand 2 "" ""))] 2))
3608    (clobber (match_scratch:SI 3 ""))
3609    (clobber (match_scratch:SI 4 ""))]
3610   "! TARGET_SH2 && reload_completed"
3611   [(set (reg:SI 0) (unspec [(label_ref (match_dup 2))] 1))
3612    (parallel [(set (match_dup 0)
3613               (unspec [(reg:SI 0) (match_dup 1) (label_ref (match_dup 2))] 2))
3614               (clobber (match_dup 3))])
3615    (set (match_dup 0) (plus:SI (match_dup 0) (reg:SI 0)))]
3616   "LABEL_NUSES (operands[2])++;")
3617
3618 (define_split
3619   [(set (match_operand:SI 0 "register_operand" "")
3620         (unspec [(match_operand 1 "register_operand" "")
3621                  (label_ref (match_operand 2 "" ""))] 2))
3622    (clobber (match_scratch:SI 3 ""))
3623    (clobber (match_scratch:SI 4 ""))]
3624   "TARGET_SH2 && reload_completed"
3625   [(set (reg:SI 0) (unspec [(label_ref (match_dup 2))] 1))
3626    (parallel [(set (match_dup 0)
3627               (unspec [(reg:SI 0) (match_dup 1) (label_ref (match_dup 2))] 2))
3628               (clobber (match_dup 3))])]
3629   "LABEL_NUSES (operands[2])++;")
3630
3631 (define_insn "*casesi_worker"
3632   [(set (match_operand:SI 0 "register_operand" "=r,r")
3633         (unspec [(reg:SI 0) (match_operand 1 "register_operand" "0,r")
3634                  (label_ref (match_operand 2 "" ""))] 2))
3635    (clobber (match_scratch:SI 3 "=X,1"))]
3636   ""
3637   "*
3638 {
3639   rtx diff_vec = PATTERN (next_real_insn (operands[2]));
3640
3641   if (GET_CODE (diff_vec) != ADDR_DIFF_VEC)
3642     abort ();
3643
3644   switch (GET_MODE (diff_vec))
3645     {
3646     case SImode:
3647       return \"shll2    %1\;mov.l       @(r0,%1),%0\";
3648     case HImode:
3649       return \"add      %1,%1\;mov.w    @(r0,%1),%0\";
3650     case QImode:
3651       if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned)
3652         return \"mov.b  @(r0,%1),%0\;extu.b     %0,%0\";
3653       return \"mov.b    @(r0,%1),%0\";
3654     default:
3655       abort ();
3656     }
3657 }"
3658   [(set_attr "length" "4")])
3659
3660 (define_expand "return"
3661   [(return)]
3662   "reload_completed && ! sh_need_epilogue ()"
3663   "")
3664
3665 (define_insn "*return_i"
3666   [(return)]
3667   "reload_completed"
3668   "%@   %#"
3669   [(set_attr "type" "return")
3670    (set_attr "needs_delay_slot" "yes")])
3671
3672 (define_expand "prologue"
3673   [(const_int 0)]
3674   ""
3675   "sh_expand_prologue (); DONE;")
3676
3677 (define_expand "epilogue"
3678   [(return)]
3679   ""
3680   "sh_expand_epilogue ();")
3681
3682 (define_insn "blockage"
3683   [(unspec_volatile [(const_int 0)] 0)]
3684   ""
3685   ""
3686   [(set_attr "length" "0")])
3687 \f
3688 ;; ------------------------------------------------------------------------
3689 ;; Scc instructions
3690 ;; ------------------------------------------------------------------------
3691
3692 (define_insn "movt"
3693   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
3694         (eq:SI (reg:SI 18) (const_int 1)))]
3695   ""
3696   "movt %0"
3697   [(set_attr "type" "arith")])
3698
3699 (define_expand "seq"
3700   [(set (match_operand:SI 0 "arith_reg_operand" "")
3701         (match_dup 1))]
3702   ""
3703   "operands[1] = prepare_scc_operands (EQ);")
3704
3705 (define_expand "slt"
3706   [(set (match_operand:SI 0 "arith_reg_operand" "")
3707         (match_dup 1))]
3708   ""
3709   "operands[1] = prepare_scc_operands (LT);")
3710
3711 (define_expand "sle"
3712   [(match_operand:SI 0 "arith_reg_operand" "")]
3713   ""
3714   "
3715 {
3716   rtx tmp = sh_compare_op0;
3717   sh_compare_op0 = sh_compare_op1;
3718   sh_compare_op1 = tmp;
3719   emit_insn (gen_sge (operands[0]));
3720   DONE;
3721 }")
3722
3723 (define_expand "sgt"
3724   [(set (match_operand:SI 0 "arith_reg_operand" "")
3725         (match_dup 1))]
3726   ""
3727   "operands[1] = prepare_scc_operands (GT);")
3728
3729 (define_expand "sge"
3730   [(set (match_operand:SI 0 "arith_reg_operand" "")
3731         (match_dup 1))]
3732   ""
3733   "
3734 {
3735   if (GET_MODE_CLASS (GET_MODE (sh_compare_op0)) == MODE_FLOAT)
3736     {
3737       if (TARGET_IEEE)
3738         {
3739           rtx lab = gen_label_rtx ();
3740           prepare_scc_operands (EQ);
3741           emit_jump_insn (gen_branch_true (lab));
3742           prepare_scc_operands (GT);
3743           emit_label (lab);
3744           emit_insn (gen_movt (operands[0]));
3745         }
3746       else
3747         emit_insn (gen_movnegt (operands[0], prepare_scc_operands (LT)));
3748       DONE;
3749     }
3750   operands[1] = prepare_scc_operands (GE);
3751 }")
3752
3753 (define_expand "sgtu"
3754   [(set (match_operand:SI 0 "arith_reg_operand" "")
3755         (match_dup 1))]
3756   ""
3757   "operands[1] = prepare_scc_operands (GTU);")
3758
3759 (define_expand "sltu"
3760   [(set (match_operand:SI 0 "arith_reg_operand" "")
3761         (match_dup 1))]
3762   ""
3763   "operands[1] = prepare_scc_operands (LTU);")
3764
3765 (define_expand "sleu"
3766   [(set (match_operand:SI 0 "arith_reg_operand" "")
3767         (match_dup 1))]
3768   ""
3769   "operands[1] = prepare_scc_operands (LEU);")
3770
3771 (define_expand "sgeu"
3772   [(set (match_operand:SI 0 "arith_reg_operand" "")
3773         (match_dup 1))]
3774   ""
3775   "operands[1] = prepare_scc_operands (GEU);")
3776
3777 ;; sne moves the complement of the T reg to DEST like this:
3778 ;;      cmp/eq ...
3779 ;;      mov    #-1,temp
3780 ;;      negc   temp,dest
3781 ;;   This is better than xoring compare result with 1 because it does
3782 ;;   not require r0 and further, the -1 may be CSE-ed or lifted out of a
3783 ;;   loop.
3784
3785 (define_expand "sne"
3786   [(set (match_dup 2) (const_int -1))
3787    (parallel [(set (match_operand:SI 0 "arith_reg_operand" "")
3788                    (neg:SI (plus:SI (match_dup 1)
3789                                     (match_dup 2))))
3790               (set (reg:SI 18)
3791                    (ne:SI (ior:SI (match_dup 1) (match_dup 2))
3792                           (const_int 0)))])]  
3793   ""
3794   "
3795 {
3796    operands[1] = prepare_scc_operands (EQ);
3797    operands[2] = gen_reg_rtx (SImode);
3798 }")
3799
3800 ;; Use the same trick for FP sle / sge
3801 (define_expand "movnegt"
3802   [(set (match_dup 2) (const_int -1))
3803    (parallel [(set (match_operand 0 "" "")
3804                    (neg:SI (plus:SI (match_dup 1)
3805                                     (match_dup 2))))
3806               (set (reg:SI 18)
3807                    (ne:SI (ior:SI (match_operand 1 "" "") (match_dup 2))
3808                           (const_int 0)))])]  
3809   ""
3810   "operands[2] = gen_reg_rtx (SImode);")
3811
3812 ;; Recognize mov #-1/negc/neg sequence, and change it to movt/add #-1.
3813 ;; This prevents a regression that occurred when we switched from xor to
3814 ;; mov/neg for sne.
3815
3816 (define_split
3817   [(set (match_operand:SI 0 "arith_reg_operand" "")
3818         (plus:SI (reg:SI 18)
3819                  (const_int -1)))]
3820   ""
3821   [(set (match_dup 0) (eq:SI (reg:SI 18) (const_int 1)))
3822    (set (match_dup 0) (plus:SI (match_dup 0) (const_int -1)))]
3823   "")
3824
3825 ;; -------------------------------------------------------------------------
3826 ;; Instructions to cope with inline literal tables
3827 ;; -------------------------------------------------------------------------
3828
3829 ; 2 byte integer in line
3830
3831 (define_insn "consttable_2"
3832  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 2)]
3833  ""
3834  "*
3835 {
3836   assemble_integer (operands[0], 2, 1);
3837   return \"\";
3838 }"
3839  [(set_attr "length" "2")
3840  (set_attr "in_delay_slot" "no")])
3841
3842 ; 4 byte integer in line
3843
3844 (define_insn "consttable_4"
3845  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 4)]
3846  ""
3847  "*
3848 {
3849   assemble_integer (operands[0], 4, 1);
3850   return \"\";
3851 }"
3852  [(set_attr "length" "4")
3853   (set_attr "in_delay_slot" "no")])
3854
3855 ; 8 byte integer in line
3856
3857 (define_insn "consttable_8"
3858  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 6)]
3859  ""
3860  "*
3861 {
3862   assemble_integer (operands[0], 8, 1);
3863   return \"\";
3864 }"
3865  [(set_attr "length" "8")
3866   (set_attr "in_delay_slot" "no")])
3867
3868 ; 4 byte floating point
3869
3870 (define_insn "consttable_sf"
3871  [(unspec_volatile [(match_operand:SF 0 "general_operand" "=g")] 4)]
3872  ""
3873  "*
3874 {
3875   union real_extract u;
3876   bcopy ((char *) &CONST_DOUBLE_LOW (operands[0]), (char *) &u, sizeof u);
3877   assemble_real (u.d, SFmode);
3878   return \"\";
3879 }"
3880  [(set_attr "length" "4")
3881   (set_attr "in_delay_slot" "no")])
3882
3883 ; 8 byte floating point
3884
3885 (define_insn "consttable_df"
3886  [(unspec_volatile [(match_operand:DF 0 "general_operand" "=g")] 6)]
3887  ""
3888  "*
3889 {
3890   union real_extract u;
3891   bcopy ((char *) &CONST_DOUBLE_LOW (operands[0]), (char *) &u, sizeof u);
3892   assemble_real (u.d, DFmode);
3893   return \"\";
3894 }"
3895  [(set_attr "length" "8")
3896   (set_attr "in_delay_slot" "no")])
3897
3898 ;; Alignment is needed for some constant tables; it may also be added for
3899 ;; Instructions at the start of loops, or after unconditional branches.
3900 ;; ??? We would get more accurate lengths if we did instruction
3901 ;; alignment based on the value of INSN_CURRENT_ADDRESS; the approach used
3902 ;; here is too conservative.
3903
3904 ; align to a two byte boundary
3905
3906 (define_expand "align_2"
3907  [(unspec_volatile [(const_int 1)] 1)]
3908  ""
3909  "")
3910
3911 ; align to a four byte boundary
3912 ;; align_4 and align_log are instructions for the starts of loops, or
3913 ;; after unconditional branches, which may take up extra room.
3914
3915 (define_expand "align_4"
3916  [(unspec_volatile [(const_int 2)] 1)]
3917  ""
3918  "")
3919
3920 ; align to a cache line boundary
3921
3922 (define_insn "align_log"
3923  [(unspec_volatile [(match_operand 0 "const_int_operand" "")] 1)]
3924  ""
3925  ""
3926  [(set_attr "length" "0")
3927   (set_attr "in_delay_slot" "no")])
3928
3929 ; emitted at the end of the literal table, used to emit the
3930 ; 32bit branch labels if needed.
3931
3932 (define_insn "consttable_end"
3933   [(unspec_volatile [(const_int 0)] 11)]
3934   ""
3935   "* return output_jump_label_table ();"
3936   [(set_attr "in_delay_slot" "no")])
3937
3938 ;; -------------------------------------------------------------------------
3939 ;; Misc
3940 ;; -------------------------------------------------------------------------
3941
3942 ;; String/block move insn.
3943
3944 (define_expand "movstrsi"
3945   [(parallel [(set (mem:BLK (match_operand:BLK 0 "" ""))
3946                    (mem:BLK (match_operand:BLK 1 "" "")))
3947               (use (match_operand:SI 2 "nonmemory_operand" ""))
3948               (use (match_operand:SI 3 "immediate_operand" ""))
3949               (clobber (reg:SI 17))
3950               (clobber (reg:SI 4))
3951               (clobber (reg:SI 5))
3952               (clobber (reg:SI 0))])]
3953   ""
3954   "
3955 {
3956   if(expand_block_move (operands))
3957      DONE;
3958   else FAIL;
3959 }")
3960
3961 (define_insn "block_move_real"
3962   [(parallel [(set (mem:BLK (reg:SI 4))
3963                    (mem:BLK (reg:SI 5)))
3964               (use (match_operand:SI 0 "arith_reg_operand" "r"))
3965               (clobber (reg:SI 17))
3966               (clobber (reg:SI 0))])]
3967   "! TARGET_HARD_SH4"
3968   "jsr  @%0%#"
3969   [(set_attr "type" "sfunc")
3970    (set_attr "needs_delay_slot" "yes")])
3971
3972 (define_insn "block_lump_real"
3973   [(parallel [(set (mem:BLK (reg:SI 4))
3974                    (mem:BLK (reg:SI 5)))
3975               (use (match_operand:SI 0 "arith_reg_operand" "r"))
3976               (use (reg:SI 6))
3977               (clobber (reg:SI 17))
3978               (clobber (reg:SI 18))
3979               (clobber (reg:SI 4))
3980               (clobber (reg:SI 5))
3981               (clobber (reg:SI 6))
3982               (clobber (reg:SI 0))])]
3983   "! TARGET_HARD_SH4"
3984   "jsr  @%0%#"
3985   [(set_attr "type" "sfunc")
3986    (set_attr "needs_delay_slot" "yes")])
3987
3988 (define_insn "block_move_real_i4"
3989   [(parallel [(set (mem:BLK (reg:SI 4))
3990                    (mem:BLK (reg:SI 5)))
3991               (use (match_operand:SI 0 "arith_reg_operand" "r"))
3992               (clobber (reg:SI 17))
3993               (clobber (reg:SI 0))
3994               (clobber (reg:SI 1))
3995               (clobber (reg:SI 2))])]
3996   "TARGET_HARD_SH4"
3997   "jsr  @%0%#"
3998   [(set_attr "type" "sfunc")
3999    (set_attr "needs_delay_slot" "yes")])
4000
4001 (define_insn "block_lump_real_i4"
4002   [(parallel [(set (mem:BLK (reg:SI 4))
4003                    (mem:BLK (reg:SI 5)))
4004               (use (match_operand:SI 0 "arith_reg_operand" "r"))
4005               (use (reg:SI 6))
4006               (clobber (reg:SI 17))
4007               (clobber (reg:SI 18))
4008               (clobber (reg:SI 4))
4009               (clobber (reg:SI 5))
4010               (clobber (reg:SI 6))
4011               (clobber (reg:SI 0))
4012               (clobber (reg:SI 1))
4013               (clobber (reg:SI 2))
4014               (clobber (reg:SI 3))])]
4015   "TARGET_HARD_SH4"
4016   "jsr  @%0%#"
4017   [(set_attr "type" "sfunc")
4018    (set_attr "needs_delay_slot" "yes")])
4019 \f
4020 ;; -------------------------------------------------------------------------
4021 ;; Floating point instructions.
4022 ;; -------------------------------------------------------------------------
4023
4024 ;; ??? All patterns should have a type attribute.
4025
4026 (define_expand "fpu_switch0"
4027   [(set (match_operand:SI 0 "" "") (match_dup 2))
4028    (set (match_dup 1) (mem:PSI (match_dup 0)))]
4029   ""
4030   "
4031 {
4032   operands[1] = get_fpscr_rtx ();
4033   operands[2] = gen_rtx_SYMBOL_REF (SImode, \"__fpscr_values\");
4034   if (flag_pic)
4035     operands[2] = legitimize_pic_address (operands[2], SImode,
4036                                           no_new_pseudos ? operands[0] : 0);
4037 }")
4038
4039 (define_expand "fpu_switch1"
4040   [(set (match_operand:SI 0 "" "") (match_dup 2))
4041    (set (match_dup 3) (plus:SI (match_dup 0) (const_int 4)))
4042    (set (match_dup 1) (mem:PSI (match_dup 3)))]
4043   ""
4044   "
4045 {
4046   operands[1] = get_fpscr_rtx ();
4047   operands[2] = gen_rtx_SYMBOL_REF (SImode, \"__fpscr_values\");
4048   if (flag_pic)
4049     operands[2] = legitimize_pic_address (operands[2], SImode,
4050                                           no_new_pseudos ? operands[0] : 0);
4051   operands[3] = no_new_pseudos ? operands[0] : gen_reg_rtx (SImode);
4052 }")
4053
4054 (define_expand "movpsi"
4055   [(set (match_operand:PSI 0 "register_operand" "")
4056         (match_operand:PSI 1 "general_movsrc_operand" ""))]
4057   ""
4058   "")
4059
4060 ;; The c / m alternative is a fake to guide reload to load directly into
4061 ;; fpscr, since reload doesn't know how to use post-increment.
4062 ;; GO_IF_LEGITIMATE_ADDRESS guards about bogus addresses before reload,
4063 ;; SECONDARY_INPUT_RELOAD_CLASS does this during reload, and the insn's
4064 ;; predicate after reload.
4065 ;; The gp_fpul type for r/!c might look a bit odd, but it actually schedules
4066 ;; like a gpr <-> fpul move.
4067 (define_insn "fpu_switch"
4068   [(set (match_operand:PSI 0 "register_operand" "=c,c,r,c,c,r,m,r")
4069         (match_operand:PSI 1 "general_movsrc_operand" "c,>,m,m,r,r,r,!c"))]
4070   "! reload_completed
4071    || true_regnum (operands[0]) != FPSCR_REG || GET_CODE (operands[1]) != MEM
4072    || GET_CODE (XEXP (operands[1], 0)) != PLUS"
4073   "@
4074         ! precision stays the same
4075         lds.l   %1,fpscr
4076         mov.l   %1,%0
4077         #
4078         lds     %1,fpscr
4079         mov     %1,%0
4080         mov.l   %1,%0
4081         sts     fpscr,%0"
4082   [(set_attr "length" "0,2,2,4,2,2,2,2")
4083    (set_attr "type" "dfp_conv,dfp_conv,load,dfp_conv,dfp_conv,move,store,gp_fpul")])
4084
4085 (define_split
4086   [(set (reg:PSI 48) (mem:PSI (match_operand:SI 0 "register_operand" "r")))]
4087   "find_regno_note (insn, REG_DEAD, true_regnum (operands[0]))"
4088   [(set (match_dup 0) (match_dup 0))]
4089   "
4090 {
4091   rtx insn = emit_insn (gen_fpu_switch (get_fpscr_rtx (),
4092                                         gen_rtx (MEM, PSImode,
4093                                                  gen_rtx (POST_INC, Pmode,
4094                                                           operands[0]))));
4095   REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, operands[0], NULL_RTX);
4096 }")
4097
4098 (define_split
4099   [(set (reg:PSI 48) (mem:PSI (match_operand:SI 0 "register_operand" "r")))]
4100   ""
4101   [(set (match_dup 0) (plus:SI (match_dup 0) (const_int -4)))]
4102   "
4103 {
4104   rtx insn = emit_insn (gen_fpu_switch (get_fpscr_rtx (),
4105                                         gen_rtx (MEM, PSImode,
4106                                                  gen_rtx (POST_INC, Pmode,
4107                                                           operands[0]))));
4108   REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, operands[0], NULL_RTX);
4109 }")
4110
4111 ;; ??? This uses the fp unit, but has no type indicating that.
4112 ;; If we did that, this would either give a bogus latency or introduce
4113 ;; a bogus FIFO constraint.
4114 ;; Since this insn is currently only used for prologues/epilogues,
4115 ;; it is probably best to claim no function unit, which matches the
4116 ;; current setting.
4117 (define_insn "toggle_sz"
4118   [(set (reg:PSI 48) (xor:PSI (reg:PSI 48) (const_int 1048576)))]
4119   "TARGET_SH4"
4120   "fschg")
4121
4122 (define_expand "addsf3"
4123   [(match_operand:SF 0 "arith_reg_operand" "")
4124    (match_operand:SF 1 "arith_reg_operand" "")
4125    (match_operand:SF 2 "arith_reg_operand" "")]
4126   "TARGET_SH3E"
4127   "{ expand_sf_binop (&gen_addsf3_i, operands); DONE; }")
4128
4129 (define_insn "addsf3_i"
4130   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
4131         (plus:SF (match_operand:SF 1 "arith_reg_operand" "%0")
4132                  (match_operand:SF 2 "arith_reg_operand" "f")))
4133    (use (match_operand:PSI 3 "fpscr_operand" "c"))]
4134   "TARGET_SH3E"
4135   "fadd %2,%0"
4136   [(set_attr "type" "fp")
4137    (set_attr "fp_mode" "single")])
4138
4139 (define_expand "subsf3"
4140   [(match_operand:SF 0 "fp_arith_reg_operand" "")
4141    (match_operand:SF 1 "fp_arith_reg_operand" "")
4142    (match_operand:SF 2 "fp_arith_reg_operand" "")]
4143   "TARGET_SH3E"
4144   "{ expand_sf_binop (&gen_subsf3_i, operands); DONE; }")
4145
4146 (define_insn "subsf3_i"
4147   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
4148         (minus:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")
4149                  (match_operand:SF 2 "fp_arith_reg_operand" "f")))
4150    (use (match_operand:PSI 3 "fpscr_operand" "c"))]
4151   "TARGET_SH3E"
4152   "fsub %2,%0"
4153   [(set_attr "type" "fp")
4154    (set_attr "fp_mode" "single")])
4155
4156 ;; Unfortunately, the combiner is unable to cope with the USE of the FPSCR
4157 ;; register in feeding fp instructions.  Thus, we cannot generate fmac for
4158 ;; mixed-precision SH4 targets.  To allow it to be still generated for the
4159 ;; SH3E, we use a separate insn for SH3E mulsf3.
4160
4161 (define_expand "mulsf3"
4162   [(match_operand:SF 0 "arith_reg_operand" "")
4163    (match_operand:SF 1 "arith_reg_operand" "")
4164    (match_operand:SF 2 "arith_reg_operand" "")]
4165   "TARGET_SH3E"
4166   "
4167 {
4168   if (TARGET_SH4)
4169     expand_sf_binop (&gen_mulsf3_i4, operands);
4170   else
4171     emit_insn (gen_mulsf3_ie (operands[0], operands[1], operands[2]));
4172   DONE;
4173 }")
4174
4175 (define_insn "mulsf3_i4"
4176   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
4177         (mult:SF (match_operand:SF 1 "arith_reg_operand" "%0")
4178                  (match_operand:SF 2 "arith_reg_operand" "f")))
4179    (use (match_operand:PSI 3 "fpscr_operand" "c"))]
4180   "TARGET_SH3E"
4181   "fmul %2,%0"
4182   [(set_attr "type" "fp")
4183    (set_attr "fp_mode" "single")])
4184
4185 (define_insn "mulsf3_ie"
4186   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
4187         (mult:SF (match_operand:SF 1 "arith_reg_operand" "%0")
4188                  (match_operand:SF 2 "arith_reg_operand" "f")))]
4189   "TARGET_SH3E && ! TARGET_SH4"
4190   "fmul %2,%0"
4191   [(set_attr "type" "fp")])
4192
4193 (define_insn "*macsf3"
4194   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
4195         (plus:SF (mult:SF (match_operand:SF 1 "arith_reg_operand" "%w")
4196                           (match_operand:SF 2 "arith_reg_operand" "f"))
4197                  (match_operand:SF 3 "arith_reg_operand" "0")))
4198    (use (match_operand:PSI 4 "fpscr_operand" "c"))]
4199   "TARGET_SH3E && ! TARGET_SH4"
4200   "fmac fr0,%2,%0"
4201   [(set_attr "type" "fp")
4202    (set_attr "fp_mode" "single")])
4203
4204 (define_expand "divsf3"
4205   [(match_operand:SF 0 "arith_reg_operand" "")
4206    (match_operand:SF 1 "arith_reg_operand" "")
4207    (match_operand:SF 2 "arith_reg_operand" "")]
4208   "TARGET_SH3E"
4209   "{ expand_sf_binop (&gen_divsf3_i, operands); DONE; }")
4210
4211 (define_insn "divsf3_i"
4212   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
4213         (div:SF (match_operand:SF 1 "arith_reg_operand" "0")
4214                  (match_operand:SF 2 "arith_reg_operand" "f")))
4215    (use (match_operand:PSI 3 "fpscr_operand" "c"))]
4216   "TARGET_SH3E"
4217   "fdiv %2,%0"
4218   [(set_attr "type" "fdiv")
4219    (set_attr "fp_mode" "single")])
4220
4221 (define_expand "floatsisf2"
4222   [(parallel [(set (match_operand:SF 0 "arith_reg_operand" "")
4223                    (float:SF (match_operand:SI 1 "arith_reg_operand" "")))
4224               (use (match_dup 2))])]
4225   "TARGET_SH3E"
4226   "
4227 {
4228   if (TARGET_SH4)
4229     {
4230       emit_sf_insn (gen_floatsisf2_i4 (operands[0], operands[1], get_fpscr_rtx ()));
4231       DONE;
4232     }
4233   operands[2] = get_fpscr_rtx ();
4234 }")
4235
4236 (define_insn "floatsisf2_i4"
4237   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
4238         (float:SF (match_operand:SI 1 "reg_no_subreg_operand" "y")))
4239    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4240   "TARGET_SH3E"
4241   "float        %1,%0"
4242   [(set_attr "type" "fp")
4243    (set_attr "fp_mode" "single")])
4244
4245 ;; ??? This pattern is used nowhere.  floatsisf always expands to floatsisf_i4.
4246 ;; (define_insn "*floatsisf2_ie"
4247 ;;  [(set (match_operand:SF 0 "arith_reg_operand" "=f")
4248 ;;      (float:SF (reg:SI 22)))]
4249 ;;  "TARGET_SH3E && ! TARGET_SH4"
4250 ;;  "float      fpul,%0"
4251 ;;  [(set_attr "type" "fp")])
4252
4253 (define_expand "fix_truncsfsi2"
4254   [(set (match_operand:SI 0 "register_operand" "=y")
4255         (fix:SI (match_operand:SF 1 "arith_reg_operand" "f")))]
4256   "TARGET_SH3E"
4257   "
4258 {
4259   if (TARGET_SH4)
4260     {
4261       emit_sf_insn (gen_fix_truncsfsi2_i4 (operands[0], operands[1], get_fpscr_rtx ()));
4262       DONE;
4263     }
4264 }")
4265
4266 (define_insn "fix_truncsfsi2_i4"
4267   [(set (match_operand:SI 0 "register_operand" "=y")
4268         (fix:SI (match_operand:SF 1 "arith_reg_operand" "f")))
4269    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4270   "TARGET_SH4"
4271   "ftrc %1,%0"
4272   [(set_attr "type" "fp")
4273    (set_attr "fp_mode" "single")])
4274
4275 ;; ??? This pattern is used nowhere.  fix_truncsfsi2 always expands to
4276 ;; fix_truncsfsi2_i4.
4277 ;; (define_insn "fix_truncsfsi2_i4_2"
4278 ;;  [(set (match_operand:SI 0 "arith_reg_operand" "=r")
4279 ;;      (fix:SI (match_operand:SF 1 "arith_reg_operand" "f")))
4280 ;;   (use (reg:SI 48))
4281 ;;   (clobber (reg:SI 22))]
4282 ;;  "TARGET_SH4"
4283 ;;  "#"
4284 ;;  [(set_attr "length" "4")
4285 ;;   (set_attr "fp_mode" "single")])
4286
4287 ;;(define_split
4288 ;;  [(set (match_operand:SI 0 "arith_reg_operand" "=r")
4289 ;;      (fix:SI (match_operand:SF 1 "arith_reg_operand" "f")))
4290 ;;   (use (match_operand:PSI 2 "fpscr_operand" "c"))
4291 ;;   (clobber (reg:SI 22))]
4292 ;;  "TARGET_SH4"
4293 ;;  [(parallel [(set (reg:SI 22) (fix:SI (match_dup 1)))
4294 ;;            (use (match_dup 2))])
4295 ;;   (set (match_dup 0) (reg:SI 22))])
4296
4297 (define_insn "*fixsfsi"
4298   [(set (match_operand:SI 0 "register_operand" "=y")
4299         (fix:SI (match_operand:SF 1 "arith_reg_operand" "f")))]
4300   "TARGET_SH3E && ! TARGET_SH4"
4301   "ftrc %1,%0"
4302   [(set_attr "type" "fp")])
4303
4304 (define_insn "cmpgtsf_t"
4305   [(set (reg:SI 18) (gt:SI (match_operand:SF 0 "arith_reg_operand" "f")
4306                            (match_operand:SF 1 "arith_reg_operand" "f")))]
4307   "TARGET_SH3E && ! TARGET_SH4"
4308   "fcmp/gt      %1,%0"
4309   [(set_attr "type" "fp")
4310    (set_attr "fp_mode" "single")])
4311
4312 (define_insn "cmpeqsf_t"
4313   [(set (reg:SI 18) (eq:SI (match_operand:SF 0 "arith_reg_operand" "f")
4314                            (match_operand:SF 1 "arith_reg_operand" "f")))]
4315   "TARGET_SH3E && ! TARGET_SH4"
4316   "fcmp/eq      %1,%0"
4317   [(set_attr "type" "fp")
4318    (set_attr "fp_mode" "single")])
4319
4320 (define_insn "ieee_ccmpeqsf_t"
4321   [(set (reg:SI 18) (ior:SI (reg:SI 18)
4322                             (eq:SI (match_operand:SF 0 "arith_reg_operand" "f")
4323                                    (match_operand:SF 1 "arith_reg_operand" "f"))))]
4324   "TARGET_SH3E && TARGET_IEEE && ! TARGET_SH4"
4325   "* return output_ieee_ccmpeq (insn, operands);"
4326   [(set_attr "length" "4")])
4327
4328
4329 (define_insn "cmpgtsf_t_i4"
4330   [(set (reg:SI 18) (gt:SI (match_operand:SF 0 "arith_reg_operand" "f")
4331                            (match_operand:SF 1 "arith_reg_operand" "f")))
4332    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4333   "TARGET_SH4"
4334   "fcmp/gt      %1,%0"
4335   [(set_attr "type" "fp")
4336    (set_attr "fp_mode" "single")])
4337
4338 (define_insn "cmpeqsf_t_i4"
4339   [(set (reg:SI 18) (eq:SI (match_operand:SF 0 "arith_reg_operand" "f")
4340                            (match_operand:SF 1 "arith_reg_operand" "f")))
4341    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4342   "TARGET_SH4"
4343   "fcmp/eq      %1,%0"
4344   [(set_attr "type" "fp")
4345    (set_attr "fp_mode" "single")])
4346
4347 (define_insn "*ieee_ccmpeqsf_t_4"
4348   [(set (reg:SI 18) (ior:SI (reg:SI 18)
4349                             (eq:SI (match_operand:SF 0 "arith_reg_operand" "f")
4350                                    (match_operand:SF 1 "arith_reg_operand" "f"))))
4351    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4352   "TARGET_IEEE && TARGET_SH4"
4353   "* return output_ieee_ccmpeq (insn, operands);"
4354   [(set_attr "length" "4")
4355    (set_attr "fp_mode" "single")])
4356
4357 (define_expand "cmpsf"
4358   [(set (reg:SI 18) (compare (match_operand:SF 0 "arith_operand" "")
4359                              (match_operand:SF 1 "arith_operand" "")))]
4360   "TARGET_SH3E"
4361   "
4362 {
4363   sh_compare_op0 = operands[0];
4364   sh_compare_op1 = operands[1];
4365   DONE;
4366 }")
4367
4368 (define_expand "negsf2"
4369   [(match_operand:SF 0 "arith_reg_operand" "")
4370    (match_operand:SF 1 "arith_reg_operand" "")]
4371   "TARGET_SH3E"
4372   "{ expand_sf_unop (&gen_negsf2_i, operands); DONE; }")
4373
4374 (define_insn "negsf2_i"
4375   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
4376         (neg:SF (match_operand:SF 1 "arith_reg_operand" "0")))
4377    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4378   "TARGET_SH3E"
4379   "fneg %0"
4380   [(set_attr "type" "fmove")
4381    (set_attr "fp_mode" "single")])
4382
4383 (define_expand "sqrtsf2"
4384   [(match_operand:SF 0 "arith_reg_operand" "")
4385    (match_operand:SF 1 "arith_reg_operand" "")]
4386   "TARGET_SH3E"
4387   "{ expand_sf_unop (&gen_sqrtsf2_i, operands); DONE; }")
4388
4389 (define_insn "sqrtsf2_i"
4390   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
4391         (sqrt:SF (match_operand:SF 1 "arith_reg_operand" "0")))
4392    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4393   "TARGET_SH3E"
4394   "fsqrt        %0"
4395   [(set_attr "type" "fdiv")
4396    (set_attr "fp_mode" "single")])
4397
4398 (define_expand "abssf2"
4399   [(match_operand:SF 0 "arith_reg_operand" "")
4400    (match_operand:SF 1 "arith_reg_operand" "")]
4401   "TARGET_SH3E"
4402   "{ expand_sf_unop (&gen_abssf2_i, operands); DONE; }")
4403
4404 (define_insn "abssf2_i"
4405   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
4406         (abs:SF (match_operand:SF 1 "arith_reg_operand" "0")))
4407    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4408   "TARGET_SH3E"
4409   "fabs %0"
4410   [(set_attr "type" "fmove")
4411    (set_attr "fp_mode" "single")])
4412
4413 (define_expand "adddf3"
4414   [(match_operand:DF 0 "arith_reg_operand" "")
4415    (match_operand:DF 1 "arith_reg_operand" "")
4416    (match_operand:DF 2 "arith_reg_operand" "")]
4417   "TARGET_SH4"
4418   "{ expand_df_binop (&gen_adddf3_i, operands); DONE; }")
4419
4420 (define_insn "adddf3_i"
4421   [(set (match_operand:DF 0 "arith_reg_operand" "=f")
4422         (plus:DF (match_operand:DF 1 "arith_reg_operand" "%0")
4423                  (match_operand:DF 2 "arith_reg_operand" "f")))
4424    (use (match_operand:PSI 3 "fpscr_operand" "c"))]
4425   "TARGET_SH4"
4426   "fadd %2,%0"
4427   [(set_attr "type" "dfp_arith")
4428    (set_attr "fp_mode" "double")])
4429
4430 (define_expand "subdf3"
4431   [(match_operand:DF 0 "arith_reg_operand" "")
4432    (match_operand:DF 1 "arith_reg_operand" "")
4433    (match_operand:DF 2 "arith_reg_operand" "")]
4434   "TARGET_SH4"
4435   "{ expand_df_binop (&gen_subdf3_i, operands); DONE; }")
4436
4437 (define_insn "subdf3_i"
4438   [(set (match_operand:DF 0 "arith_reg_operand" "=f")
4439         (minus:DF (match_operand:DF 1 "arith_reg_operand" "0")
4440                   (match_operand:DF 2 "arith_reg_operand" "f")))
4441    (use (match_operand:PSI 3 "fpscr_operand" "c"))]
4442   "TARGET_SH4"
4443   "fsub %2,%0"
4444   [(set_attr "type" "dfp_arith")
4445    (set_attr "fp_mode" "double")])
4446
4447 (define_expand "muldf3"
4448   [(match_operand:DF 0 "arith_reg_operand" "")
4449    (match_operand:DF 1 "arith_reg_operand" "")
4450    (match_operand:DF 2 "arith_reg_operand" "")]
4451   "TARGET_SH4"
4452   "{ expand_df_binop (&gen_muldf3_i, operands); DONE; }")
4453
4454 (define_insn "muldf3_i"
4455   [(set (match_operand:DF 0 "arith_reg_operand" "=f")
4456         (mult:DF (match_operand:DF 1 "arith_reg_operand" "%0")
4457                  (match_operand:DF 2 "arith_reg_operand" "f")))
4458    (use (match_operand:PSI 3 "fpscr_operand" "c"))]
4459   "TARGET_SH4"
4460   "fmul %2,%0"
4461   [(set_attr "type" "dfp_arith")
4462    (set_attr "fp_mode" "double")])
4463
4464 (define_expand "divdf3"
4465   [(match_operand:DF 0 "arith_reg_operand" "")
4466    (match_operand:DF 1 "arith_reg_operand" "")
4467    (match_operand:DF 2 "arith_reg_operand" "")]
4468   "TARGET_SH4"
4469   "{ expand_df_binop (&gen_divdf3_i, operands); DONE; }")
4470
4471 (define_insn "divdf3_i"
4472   [(set (match_operand:DF 0 "arith_reg_operand" "=f")
4473         (div:DF (match_operand:DF 1 "arith_reg_operand" "0")
4474                 (match_operand:DF 2 "arith_reg_operand" "f")))
4475    (use (match_operand:PSI 3 "fpscr_operand" "c"))]
4476   "TARGET_SH4"
4477   "fdiv %2,%0"
4478   [(set_attr "type" "dfdiv")
4479    (set_attr "fp_mode" "double")])
4480
4481 (define_expand "floatsidf2"
4482   [(match_operand:DF 0 "arith_reg_operand" "")
4483    (match_operand:SI 1 "arith_reg_operand" "")]
4484   "TARGET_SH4"
4485   "
4486 {
4487   emit_df_insn (gen_floatsidf2_i (operands[0], operands[1], get_fpscr_rtx ()));
4488   DONE;
4489 }")
4490
4491 (define_insn "floatsidf2_i"
4492   [(set (match_operand:DF 0 "arith_reg_operand" "=f")
4493         (float:DF (match_operand:SI 1 "reg_no_subreg_operand" "y")))
4494    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4495   "TARGET_SH4"
4496   "float        %1,%0"
4497   [(set_attr "type" "dfp_conv")
4498    (set_attr "fp_mode" "double")])
4499
4500 (define_expand "fix_truncdfsi2"
4501   [(match_operand:SI 0 "arith_reg_operand" "=r")
4502    (match_operand:DF 1 "arith_reg_operand" "f")]
4503   "TARGET_SH4"
4504   "
4505 {
4506   emit_df_insn (gen_fix_truncdfsi2_i (operands[0], operands[1], get_fpscr_rtx ()));
4507   DONE;
4508 }")
4509
4510 (define_insn "fix_truncdfsi2_i"
4511   [(set (match_operand:SI 0 "register_operand" "=y")
4512         (fix:SI (match_operand:DF 1 "arith_reg_operand" "f")))
4513    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4514   "TARGET_SH4"
4515   "ftrc %1,%0"
4516   [(set_attr "type" "dfp_conv")
4517    (set_attr "fp_mode" "double")])
4518
4519 ;; ??? This pattern is used nowhere.  fix_truncdfsi2 always expands to
4520 ;; fix_truncdfsi2_i.
4521 ;; (define_insn "fix_truncdfsi2_i4"
4522 ;;   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
4523 ;;      (fix:SI (match_operand:DF 1 "arith_reg_operand" "f")))
4524 ;;    (use (match_operand:PSI 2 "fpscr_operand" "c"))
4525 ;;    (clobber (reg:SI 22))]
4526 ;;   "TARGET_SH4"
4527 ;;   "#"
4528 ;;   [(set_attr "length" "4")
4529 ;;    (set_attr "fp_mode" "double")])
4530 ;; 
4531 ;; (define_split
4532 ;;   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
4533 ;;      (fix:SI (match_operand:DF 1 "arith_reg_operand" "f")))
4534 ;;    (use (match_operand:PSI 2 "fpscr_operand" "c"))
4535 ;;    (clobber (reg:SI 22))]
4536 ;;   "TARGET_SH4"
4537 ;;   [(parallel [(set (reg:SI 22) (fix:SI (match_dup 1)))
4538 ;;            (use (match_dup 2))])
4539 ;;    (set (match_dup 0) (reg:SI 22))])
4540
4541 (define_insn "cmpgtdf_t"
4542   [(set (reg:SI 18) (gt:SI (match_operand:DF 0 "arith_reg_operand" "f")
4543                            (match_operand:DF 1 "arith_reg_operand" "f")))
4544    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4545   "TARGET_SH4"
4546   "fcmp/gt      %1,%0"
4547   [(set_attr "type" "dfp_cmp")
4548    (set_attr "fp_mode" "double")])
4549
4550 (define_insn "cmpeqdf_t"
4551   [(set (reg:SI 18) (eq:SI (match_operand:DF 0 "arith_reg_operand" "f")
4552                            (match_operand:DF 1 "arith_reg_operand" "f")))
4553    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4554   "TARGET_SH4"
4555   "fcmp/eq      %1,%0"
4556   [(set_attr "type" "dfp_cmp")
4557    (set_attr "fp_mode" "double")])
4558
4559 (define_insn "*ieee_ccmpeqdf_t"
4560   [(set (reg:SI 18) (ior:SI (reg:SI 18)
4561                             (eq:SI (match_operand:DF 0 "arith_reg_operand" "f")
4562                                    (match_operand:DF 1 "arith_reg_operand" "f"))))
4563    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4564   "TARGET_IEEE && TARGET_SH4"
4565   "* return output_ieee_ccmpeq (insn, operands);"
4566   [(set_attr "length" "4")
4567    (set_attr "fp_mode" "double")])
4568    
4569 (define_expand "cmpdf"
4570   [(set (reg:SI 18) (compare (match_operand:DF 0 "arith_operand" "")
4571                              (match_operand:DF 1 "arith_operand" "")))]
4572   "TARGET_SH4"
4573   "
4574 {
4575   sh_compare_op0 = operands[0];
4576   sh_compare_op1 = operands[1];
4577   DONE;
4578 }")
4579
4580 (define_expand "negdf2"
4581   [(match_operand:DF 0 "arith_reg_operand" "")
4582    (match_operand:DF 1 "arith_reg_operand" "")]
4583   "TARGET_SH4"
4584   "{ expand_df_unop (&gen_negdf2_i, operands); DONE; }")
4585
4586 (define_insn "negdf2_i"
4587   [(set (match_operand:DF 0 "arith_reg_operand" "=f")
4588         (neg:DF (match_operand:DF 1 "arith_reg_operand" "0")))
4589    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4590   "TARGET_SH4"
4591   "fneg %0"
4592   [(set_attr "type" "fmove")
4593    (set_attr "fp_mode" "double")])
4594
4595 (define_expand "sqrtdf2"
4596   [(match_operand:DF 0 "arith_reg_operand" "")
4597    (match_operand:DF 1 "arith_reg_operand" "")]
4598   "TARGET_SH4"
4599   "{ expand_df_unop (&gen_sqrtdf2_i, operands); DONE; }")
4600
4601 (define_insn "sqrtdf2_i"
4602   [(set (match_operand:DF 0 "arith_reg_operand" "=f")
4603         (sqrt:DF (match_operand:DF 1 "arith_reg_operand" "0")))
4604    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4605   "TARGET_SH4"
4606   "fsqrt        %0"
4607   [(set_attr "type" "dfdiv")
4608    (set_attr "fp_mode" "double")])
4609
4610 (define_expand "absdf2"
4611   [(match_operand:DF 0 "arith_reg_operand" "")
4612    (match_operand:DF 1 "arith_reg_operand" "")]
4613   "TARGET_SH4"
4614   "{ expand_df_unop (&gen_absdf2_i, operands); DONE; }")
4615
4616 (define_insn "absdf2_i"
4617   [(set (match_operand:DF 0 "arith_reg_operand" "=f")
4618         (abs:DF (match_operand:DF 1 "arith_reg_operand" "0")))
4619    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4620   "TARGET_SH4"
4621   "fabs %0"
4622   [(set_attr "type" "fmove")
4623    (set_attr "fp_mode" "double")])
4624
4625 (define_expand "extendsfdf2"
4626   [(match_operand:DF 0 "arith_reg_operand" "")
4627    (match_operand:SF 1 "arith_reg_operand" "")]
4628   "TARGET_SH4"
4629   "
4630 {
4631   emit_df_insn (gen_extendsfdf2_i4 (operands[0], operands[1], get_fpscr_rtx ()));
4632   DONE;
4633 }")
4634
4635 (define_insn "extendsfdf2_i4"
4636   [(set (match_operand:DF 0 "arith_reg_operand" "=f")
4637         (float_extend:DF (match_operand:SF 1 "reg_no_subreg_operand" "y")))
4638    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4639   "TARGET_SH4"
4640   "fcnvsd  %1,%0"
4641   [(set_attr "type" "fp")
4642    (set_attr "fp_mode" "double")])
4643
4644 (define_expand "truncdfsf2"
4645   [(match_operand:SF 0 "arith_reg_operand" "")
4646    (match_operand:DF 1 "arith_reg_operand" "")]
4647   "TARGET_SH4"
4648   "
4649 {
4650   emit_df_insn (gen_truncdfsf2_i4 (operands[0], operands[1], get_fpscr_rtx ()));
4651   DONE;
4652 }")
4653
4654 (define_insn "truncdfsf2_i4"
4655   [(set (match_operand:SF 0 "register_operand" "=y")
4656         (float_truncate:SF (match_operand:DF 1 "arith_reg_operand" "f")))
4657    (use (match_operand:PSI 2 "fpscr_operand" "c"))]
4658   "TARGET_SH4"
4659   "fcnvds  %1,%0"
4660   [(set_attr "type" "fp")
4661    (set_attr "fp_mode" "double")])
4662 \f
4663 ;; Bit field extract patterns.  These give better code for packed bitfields,
4664 ;; because they allow auto-increment addresses to be generated.
4665
4666 (define_expand "insv"
4667   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "")
4668                          (match_operand:SI 1 "immediate_operand" "")
4669                          (match_operand:SI 2 "immediate_operand" ""))
4670         (match_operand:SI 3 "general_operand" ""))]
4671   "! TARGET_LITTLE_ENDIAN"
4672   "
4673 {
4674   rtx addr_target, orig_address, shift_reg;
4675   HOST_WIDE_INT size;
4676
4677   /* ??? expmed doesn't care for non-register predicates.  */
4678   if (! memory_operand (operands[0], VOIDmode)
4679       || ! immediate_operand (operands[1], VOIDmode)
4680       || ! immediate_operand (operands[2], VOIDmode)
4681       || ! general_operand (operands[3], VOIDmode))
4682     FAIL;
4683   /* If this isn't a 16 / 24 / 32 bit field, or if
4684      it doesn't start on a byte boundary, then fail.  */
4685   size = INTVAL (operands[1]);
4686   if (size < 16 || size > 32 || size % 8 != 0
4687       || (INTVAL (operands[2]) % 8) != 0)
4688     FAIL;
4689
4690   size /= 8;
4691   orig_address = XEXP (operands[0], 0);
4692   shift_reg = gen_reg_rtx (SImode);
4693   emit_insn (gen_movsi (shift_reg, operands[3]));
4694   addr_target = copy_addr_to_reg (plus_constant (orig_address, size - 1));
4695
4696   operands[0] = change_address (operands[0], QImode, addr_target);
4697   emit_insn (gen_movqi (operands[0], gen_rtx_SUBREG (QImode, shift_reg, 0)));
4698
4699   while (size -= 1)
4700     {
4701       emit_insn (gen_lshrsi3_k (shift_reg, shift_reg, GEN_INT (8)));
4702       emit_insn (gen_addsi3 (addr_target, addr_target, GEN_INT (-1)));
4703       emit_insn (gen_movqi (operands[0],
4704                             gen_rtx_SUBREG (QImode, shift_reg, 0)));
4705     }
4706
4707   DONE;
4708 }")
4709 \f
4710 ;; -------------------------------------------------------------------------
4711 ;; Peepholes
4712 ;; -------------------------------------------------------------------------
4713
4714 ;; This matches cases where a stack pointer increment at the start of the
4715 ;; epilogue combines with a stack slot read loading the return value.
4716
4717 (define_peephole
4718   [(set (match_operand:SI 0 "arith_reg_operand" "")
4719         (mem:SI (match_operand:SI 1 "arith_reg_operand" "")))
4720    (set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))]
4721   "REGNO (operands[1]) != REGNO (operands[0])"
4722   "mov.l        @%1+,%0")
4723
4724 ;; See the comment on the dt combiner pattern above.
4725
4726 (define_peephole
4727   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
4728         (plus:SI (match_dup 0)
4729                  (const_int -1)))
4730    (set (reg:SI 18)
4731         (eq:SI (match_dup 0)
4732                (const_int 0)))]
4733   "TARGET_SH2"
4734   "dt   %0")
4735
4736 ;; These convert sequences such as `mov #k,r0; add r15,r0; mov.l @r0,rn'
4737 ;; to `mov #k,r0; mov.l @(r0,r15),rn'.  These sequences are generated by
4738 ;; reload when the constant is too large for a reg+offset address.
4739
4740 ;; ??? We would get much better code if this was done in reload.  This would
4741 ;; require modifying find_reloads_address to recognize that if the constant
4742 ;; is out-of-range for an immediate add, then we get better code by reloading
4743 ;; the constant into a register than by reloading the sum into a register,
4744 ;; since the former is one instruction shorter if the address does not need
4745 ;; to be offsettable.  Unfortunately this does not work, because there is
4746 ;; only one register, r0, that can be used as an index register.  This register
4747 ;; is also the function return value register.  So, if we try to force reload
4748 ;; to use double-reg addresses, then we end up with some instructions that
4749 ;; need to use r0 twice.  The only way to fix this is to change the calling
4750 ;; convention so that r0 is not used to return values.
4751
4752 (define_peephole
4753   [(set (match_operand:SI 0 "register_operand" "=r")
4754         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
4755    (set (mem:SI (match_dup 0))
4756         (match_operand:SI 2 "general_movsrc_operand" ""))]
4757   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
4758   "mov.l        %2,@(%0,%1)")
4759
4760 (define_peephole
4761   [(set (match_operand:SI 0 "register_operand" "=r")
4762         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
4763    (set (match_operand:SI 2 "general_movdst_operand" "")
4764         (mem:SI (match_dup 0)))]
4765   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
4766   "mov.l        @(%0,%1),%2")
4767
4768 (define_peephole
4769   [(set (match_operand:SI 0 "register_operand" "=r")
4770         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
4771    (set (mem:HI (match_dup 0))
4772         (match_operand:HI 2 "general_movsrc_operand" ""))]
4773   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
4774   "mov.w        %2,@(%0,%1)")
4775
4776 (define_peephole
4777   [(set (match_operand:SI 0 "register_operand" "=r")
4778         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
4779    (set (match_operand:HI 2 "general_movdst_operand" "")
4780         (mem:HI (match_dup 0)))]
4781   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
4782   "mov.w        @(%0,%1),%2")
4783
4784 (define_peephole
4785   [(set (match_operand:SI 0 "register_operand" "=r")
4786         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
4787    (set (mem:QI (match_dup 0))
4788         (match_operand:QI 2 "general_movsrc_operand" ""))]
4789   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
4790   "mov.b        %2,@(%0,%1)")
4791
4792 (define_peephole
4793   [(set (match_operand:SI 0 "register_operand" "=r")
4794         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
4795    (set (match_operand:QI 2 "general_movdst_operand" "")
4796         (mem:QI (match_dup 0)))]
4797   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
4798   "mov.b        @(%0,%1),%2")
4799
4800 (define_peephole
4801   [(set (match_operand:SI 0 "register_operand" "=r")
4802         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
4803    (set (mem:SF (match_dup 0))
4804         (match_operand:SF 2 "general_movsrc_operand" ""))]
4805   "REGNO (operands[0]) == 0
4806    && ((GET_CODE (operands[2]) == REG && REGNO (operands[2]) < 16)
4807        || (GET_CODE (operands[2]) == SUBREG
4808            && REGNO (SUBREG_REG (operands[2])) < 16))
4809    && reg_unused_after (operands[0], insn)"
4810   "mov.l        %2,@(%0,%1)")
4811
4812 (define_peephole
4813   [(set (match_operand:SI 0 "register_operand" "=r")
4814         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
4815    (set (match_operand:SF 2 "general_movdst_operand" "")
4816
4817         (mem:SF (match_dup 0)))]
4818   "REGNO (operands[0]) == 0
4819    && ((GET_CODE (operands[2]) == REG && REGNO (operands[2]) < 16)
4820        || (GET_CODE (operands[2]) == SUBREG
4821            && REGNO (SUBREG_REG (operands[2])) < 16))
4822    && reg_unused_after (operands[0], insn)"
4823   "mov.l        @(%0,%1),%2")
4824
4825 (define_peephole
4826   [(set (match_operand:SI 0 "register_operand" "=r")
4827         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
4828    (set (mem:SF (match_dup 0))
4829         (match_operand:SF 2 "general_movsrc_operand" ""))]
4830   "REGNO (operands[0]) == 0
4831    && ((GET_CODE (operands[2]) == REG && REGNO (operands[2]) >= FIRST_FP_REG)
4832        || (GET_CODE (operands[2]) == SUBREG
4833            && REGNO (SUBREG_REG (operands[2])) >= FIRST_FP_REG))
4834    && reg_unused_after (operands[0], insn)"
4835   "fmov{.s|}    %2,@(%0,%1)")
4836
4837 (define_peephole
4838   [(set (match_operand:SI 0 "register_operand" "=r")
4839         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
4840    (set (match_operand:SF 2 "general_movdst_operand" "")
4841
4842         (mem:SF (match_dup 0)))]
4843   "REGNO (operands[0]) == 0
4844    && ((GET_CODE (operands[2]) == REG && REGNO (operands[2]) >= FIRST_FP_REG)
4845        || (GET_CODE (operands[2]) == SUBREG
4846            && REGNO (SUBREG_REG (operands[2])) >= FIRST_FP_REG))
4847    && reg_unused_after (operands[0], insn)"
4848   "fmov{.s|}    @(%0,%1),%2")
4849
4850 ;; Switch to a new stack with its address in sp_switch (a SYMBOL_REF).  */
4851 (define_insn "sp_switch_1"
4852   [(const_int 1)]
4853   ""
4854   "*
4855 {
4856   rtx xoperands[1];
4857
4858   xoperands[0] = sp_switch;
4859   output_asm_insn (\"mov.l r0,@-r15\;mov.l %0,r0\", xoperands);
4860   output_asm_insn (\"mov.l @r0,r0\;mov.l r15,@-r0\", xoperands);
4861   return \"mov r0,r15\";
4862 }"
4863   [(set_attr "length" "10")])
4864
4865 ;; Switch back to the original stack for interrupt functions with the
4866 ;; sp_switch attribute.  */
4867 (define_insn "sp_switch_2"
4868   [(const_int 2)]
4869   ""
4870   "mov.l @r15+,r15\;mov.l @r15+,r0"
4871   [(set_attr "length" "4")])