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