OSDN Git Service

New define_splits to recombine output from LEGITIMIZE_ADDRESS.
[pf3gnuchains/gcc-fork.git] / gcc / config / sh / sh.md
1 ;;- Machine description for the Hitachi SH.
2 ;;  Copyright (C) 1993, 1994, 1995 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 ;; ??? Should add support for using BSR for short function calls.
33
34 ;; ??? The MAC.W and MAC.L instructions are not supported.  There is no
35 ;; way to generate them.
36
37 ;; ??? The BSR instruction is not supported.  It might be possible to
38 ;; generate it by keeping track of function sizes (and hence relative
39 ;; addresses), and then using it only if the target is earlier in the same
40 ;; file, and is within range.  Better would be assembler/linker relaxing,
41 ;; but that is much harder.
42
43 ;; ??? The cmp/str instruction is not supported.  Perhaps it can be used
44 ;; for a str* inline function.
45
46 ;; Special constraints for SH machine description:
47 ;;
48 ;;    t -- T
49 ;;    x -- mac
50 ;;    l -- pr
51 ;;    z -- r0
52 ;;
53 ;; Special formats used for outputting SH instructions:
54 ;;
55 ;;   %.  --  print a .s if insn needs delay slot
56 ;;   %@  --  print rte/rts if is/isn't an interrupt function
57 ;;   %#  --  output a nop if there is nothing to put in the delay slot
58 ;;   %O  --  print a constant without the #
59 ;;   %R  --  print the lsw reg of a double
60 ;;   %S  --  print the msw reg of a double
61 ;;   %T  --  print next word of a double REG or MEM
62 ;;
63 ;; Special predicates:
64 ;;
65 ;;  arith_operand          -- operand is valid source for arithmetic op
66 ;;  arith_reg_operand      -- operand is valid register for arithmetic op
67 ;;  general_movdst_operand -- operand is valid move destination
68 ;;  general_movsrc_operand -- operand is valid move source
69 ;;  logical_operand        -- operand is valid source for logical op
70 ;; -------------------------------------------------------------------------
71 ;; Attributes
72 ;; -------------------------------------------------------------------------
73
74 ;; Target CPU.
75
76 (define_attr "cpu" "sh0,sh1,sh2,sh3,sh3e"
77   (const (symbol_ref "sh_cpu_attr")))
78
79 ;; cbranch      conditional branch instructions
80 ;; jump         unconditional jumps
81 ;; arith        ordinary arithmetic
82 ;; load         from memory
83 ;; store        to memory
84 ;; move         register to register
85 ;; smpy         word precision integer multiply
86 ;; dmpy         longword or doublelongword precision integer multiply
87 ;; return       rts
88 ;; pload        load of pr reg, which can't be put into delay slot of rts
89 ;; pstore       store of pr reg, which can't be put into delay slot of jsr
90 ;; pcload       pc relative load of constant value
91 ;; rte          return from exception
92 ;; sfunc        special function call with known used registers
93 ;; call         function call
94 ;; fp           floating point
95 ;; fdiv         floating point divide (or square root)
96
97 (define_attr "type"
98  "cbranch,jump,arith,other,load,store,move,smpy,dmpy,return,pload,pstore,pcload,rte,sfunc,call,fp,fdiv"
99   (const_string "other"))
100
101 ; If a conditional branch destination is within -252..258 bytes away
102 ; from the instruction it can be 2 bytes long.  Something in the
103 ; range -4090..4100 bytes can be 6 bytes long.  All other conditional
104 ; branches are 16 bytes long.
105
106 ; An unconditional jump in the range -4092..4098 can be 2 bytes long.
107 ; Otherwise, it must be 14 bytes long.
108
109 ; All other instructions are two bytes long by default.
110
111 ; All positive offsets have an adjustment added, which is the number of bytes
112 ; difference between this instruction length and the next larger instruction
113 ; length.  This is because shorten_branches starts with the largest
114 ; instruction size and then tries to reduce them.
115
116 (define_attr "length" ""
117   (cond [(eq_attr "type" "cbranch")
118          (if_then_else (and (ge (minus (match_dup 0) (pc))
119                                 (const_int -252))
120                             (le (minus (match_dup 0) (pc))
121                                 (const_int 262)))
122                        (const_int 2)
123                        (if_then_else (and (ge (minus (match_dup 0) (pc))
124                                               (const_int -4090))
125                                           (le (minus (match_dup 0) (pc))
126                                               (const_int 4110)))
127                                      (const_int 6)
128                                      (const_int 16)))
129
130          (eq_attr "type" "jump")
131          (if_then_else (and (ge (minus (match_dup 0) (pc))
132                                 (const_int -4092))
133                             (le (minus (match_dup 0) (pc))
134                                 (const_int 4110)))
135                        (const_int 2)
136                        (const_int 14))
137          ] (const_int 2)))
138
139 ;; (define_function_unit {name} {num-units} {n-users} {test}
140 ;;                       {ready-delay} {issue-delay} [{conflict-list}])
141
142 ;; Load and store instructions save a cycle if they are aligned on a
143 ;; four byte boundary.  Using a function unit for stores encourages
144 ;; gcc to separate load and store instructions by one instruction,
145 ;; which makes it more likely that the linker will be able to word
146 ;; align them when relaxing.
147 (define_function_unit "memory" 1 0
148   (eq_attr "type" "load,pcload,pload,store,pstore") 2 2)
149
150 ;; ??? These are approximations.
151 (define_function_unit "mpy"    1 0 (eq_attr "type" "smpy") 2 2)
152 (define_function_unit "mpy"    1 0 (eq_attr "type" "dmpy") 3 3)
153
154 (define_function_unit "fp"     1 0 (eq_attr "type" "fp") 2 1)
155 (define_function_unit "fp"     1 0 (eq_attr "type" "fdiv") 13 12)
156
157 ; Definitions for filling branch delay slots.
158
159 (define_attr "needs_delay_slot" "yes,no" (const_string "no"))
160
161 (define_attr "hit_stack" "yes,no" (const_string "no"))
162
163 (define_attr "interrupt_function" "no,yes"
164   (const (symbol_ref "pragma_interrupt")))
165
166 (define_attr "in_delay_slot" "yes,no"
167   (cond [(eq_attr "type" "cbranch") (const_string "no")
168          (eq_attr "type" "pcload") (const_string "no")
169          (eq_attr "needs_delay_slot" "yes") (const_string "no")
170          (eq_attr "length" "2") (const_string "yes")
171          ] (const_string "no")))
172
173 (define_delay
174   (eq_attr "needs_delay_slot" "yes")
175   [(eq_attr "in_delay_slot" "yes") (nil) (nil)])
176
177 ;; On the SH and SH2, the rte instruction reads the return pc from the stack,
178 ;; and thus we can't put a pop instruction in its delay slot.
179 ;; ??? On the SH3, the rte instruction does not use the stack, so a pop
180 ;; instruction can go in the delay slot.
181
182 ;; Since a normal return (rts) implicitly uses the PR register,
183 ;; we can't allow PR register loads in an rts delay slot.
184
185 (define_delay
186   (eq_attr "type" "return")
187   [(and (eq_attr "in_delay_slot" "yes")
188         (ior (and (eq_attr "interrupt_function" "no")
189                   (eq_attr "type" "!pload"))
190              (and (eq_attr "interrupt_function" "yes")
191                   (eq_attr "hit_stack" "no")))) (nil) (nil)])
192
193 ;; Since a call implicitly uses the PR register, we can't allow
194 ;; a PR register store in a jsr delay slot.
195
196 (define_delay
197   (ior (eq_attr "type" "call") (eq_attr "type" "sfunc"))
198   [(and (eq_attr "in_delay_slot" "yes")
199         (eq_attr "type" "!pstore")) (nil) (nil)])
200
201 ;; Say that we have annulled true branches, since this gives smaller and
202 ;; faster code when branches are predicted as not taken.
203
204 ;; ??? Branches which are out-of-range actually have two delay slots,
205 ;; the first is either always executed or else annulled false, and the
206 ;; second is always annulled false.  Handling these differently from
207 ;; in range branches would give better code.
208
209 (define_delay
210   (and (eq_attr "type" "cbranch")
211        (eq_attr "cpu" "sh2,sh3"))
212   [(eq_attr "in_delay_slot" "yes") (eq_attr "in_delay_slot" "yes") (nil)])
213 \f
214 ;; -------------------------------------------------------------------------
215 ;; SImode signed integer comparisons
216 ;; -------------------------------------------------------------------------
217
218 (define_insn ""
219   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
220         (eq:SI (reg:SI 18)
221                (const_int 1)))]
222   ""
223   "movt %0")
224
225 ;; ??? This combiner pattern does not work, because combine does not combine
226 ;; instructions that set a hard register when SMALL_REGISTER_CLASSES is
227 ;; defined.  Perhaps use a pseudo-reg for the T bit?
228
229 (define_insn ""
230   [(set (reg:SI 18)
231         (eq:SI (and:SI (match_operand:SI 0 "arith_reg_operand" "z,r")
232                        (match_operand:SI 1 "arith_operand" "L,r"))
233                (const_int 0)))]
234   ""
235   "tst  %1,%0")
236
237 ;; ??? Perhaps should only accept reg/constant if the register is reg 0.
238 ;; That would still allow reload to create cmpi instructions, but would
239 ;; perhaps allow forcing the constant into a register when that is better.
240 ;; Probably should use r0 for mem/imm compares, but force constant into a
241 ;; register for pseudo/imm compares.
242
243 (define_insn "cmpeqsi_t"
244   [(set (reg:SI 18) (eq:SI (match_operand:SI 0 "arith_reg_operand" "r,z,r")
245                            (match_operand:SI 1 "arith_operand" "N,rI,r")))]
246   ""
247   "@
248         tst     %0,%0
249         cmp/eq  %1,%0
250         cmp/eq  %1,%0")
251
252 (define_insn "cmpgtsi_t"
253   [(set (reg:SI 18) (gt:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
254                            (match_operand:SI 1 "arith_reg_or_0_operand" "r,N")))]
255   ""
256   "@
257         cmp/gt  %1,%0
258         cmp/pl  %0")
259
260 (define_insn "cmpgesi_t"
261   [(set (reg:SI 18) (ge:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
262                            (match_operand:SI 1 "arith_reg_or_0_operand" "r,N")))]
263   ""
264   "@
265         cmp/ge  %1,%0
266         cmp/pz  %0")
267 \f
268 ;; -------------------------------------------------------------------------
269 ;; SImode unsigned integer comparisons
270 ;; -------------------------------------------------------------------------
271
272 (define_insn "cmpgeusi_t"
273   [(set (reg:SI 18) (geu:SI (match_operand:SI 0 "arith_reg_operand" "r")
274                             (match_operand:SI 1 "arith_reg_operand" "r")))]
275   ""
276   "cmp/hs       %1,%0")
277
278 (define_insn "cmpgtusi_t"
279   [(set (reg:SI 18) (gtu:SI (match_operand:SI 0 "arith_reg_operand" "r")
280                             (match_operand:SI 1 "arith_reg_operand" "r")))]
281   ""
282   "cmp/hi       %1,%0")
283
284 ;; We save the compare operands in the cmpxx patterns and use them when
285 ;; we generate the branch.
286
287 (define_expand "cmpsi"
288   [(set (reg:SI 18) (compare (match_operand:SI 0 "arith_operand" "")
289                              (match_operand:SI 1 "arith_operand" "")))]
290   ""
291   "
292 {
293   sh_compare_op0 = operands[0];
294   sh_compare_op1 = operands[1];
295   DONE;
296 }")
297 \f
298 ;; -------------------------------------------------------------------------
299 ;; Addition instructions
300 ;; -------------------------------------------------------------------------
301
302 ;; ??? This should be a define expand.
303
304 (define_insn "adddi3"
305   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
306         (plus:DI (match_operand:DI 1 "arith_reg_operand" "%0")
307                  (match_operand:DI 2 "arith_reg_operand" "r")))
308    (clobber (reg:SI 18))]
309   ""
310   "clrt\;addc   %R2,%R0\;addc   %S2,%S0"
311   [(set_attr "length" "6")])
312
313 (define_insn "addsi3"
314   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
315         (plus:SI (match_operand:SI 1 "arith_operand" "%0")
316                  (match_operand:SI 2 "arith_operand" "rI")))]
317   ""
318   "add  %2,%0"
319   [(set_attr "type" "arith")])
320 \f
321 ;; -------------------------------------------------------------------------
322 ;; Subtraction instructions
323 ;; -------------------------------------------------------------------------
324
325 ;; ??? This should be a define expand.
326
327 (define_insn "subdi3"
328   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
329         (minus:DI (match_operand:DI 1 "arith_reg_operand" "0")
330                  (match_operand:DI 2 "arith_reg_operand" "r")))
331    (clobber (reg:SI 18))]
332   ""
333   "clrt\;subc   %R2,%R0\;subc   %S2,%S0"
334   [(set_attr "length" "6")])
335
336 (define_insn "*subsi3_internal"
337   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
338         (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
339                   (match_operand:SI 2 "arith_reg_operand" "r")))]
340   ""
341   "sub  %2,%0"
342   [(set_attr "type" "arith")])
343
344 ;; Convert `constant - reg' to `neg rX; add rX, #const' since this
345 ;; will sometimes save one instruction.  Otherwise we might get
346 ;; `mov #const, rY; sub rY,rX; mov rX, rY' if the source and dest regs
347 ;; are the same.
348
349 (define_expand "subsi3"
350   [(set (match_operand:SI 0 "arith_reg_operand" "")
351         (minus:SI (match_operand:SI 1 "arith_operand" "")
352                   (match_operand:SI 2 "arith_reg_operand" "")))]
353   ""
354   "
355 {
356   if (GET_CODE (operands[1]) == CONST_INT)
357     {
358       emit_insn (gen_negsi2 (operands[0], operands[2]));
359       emit_insn (gen_addsi3 (operands[0], operands[0], operands[1]));
360       DONE;
361     }
362 }")
363 \f
364 ;; -------------------------------------------------------------------------
365 ;; Division instructions
366 ;; -------------------------------------------------------------------------
367
368 ;; We take advantage of the library routines which don't clobber as many
369 ;; registers as a normal function call would.
370
371 ;; We must use a pseudo-reg forced to reg 0 in the SET_DEST rather than
372 ;; hard register 0.  If we used hard register 0, then the next instruction
373 ;; would be a move from hard register 0 to a pseudo-reg.  If the pseudo-reg
374 ;; gets allocated to a stack slot that needs its address reloaded, then
375 ;; there is nothing to prevent reload from using r0 to reload the address.
376 ;; This reload would clobber the value in r0 we are trying to store.
377 ;; If we let reload allocate r0, then this problem can never happen.
378
379 (define_insn ""
380   [(set (match_operand:SI 1 "register_operand" "=z")
381         (udiv:SI (reg:SI 4) (reg:SI 5)))
382    (clobber (reg:SI 18))
383    (clobber (reg:SI 17))
384    (clobber (reg:SI 4))
385    (use (match_operand:SI 0 "arith_reg_operand" "r"))]
386   ""
387   "jsr  @%0%#"
388   [(set_attr "type" "sfunc")
389    (set_attr "needs_delay_slot" "yes")])
390
391 (define_expand "udivsi3"
392   [(set (reg:SI 4) (match_operand:SI 1 "general_operand" ""))
393    (set (reg:SI 5) (match_operand:SI 2 "general_operand" ""))
394    (set (match_dup 3) (symbol_ref:SI "__udivsi3"))
395    (parallel [(set (match_operand:SI 0 "register_operand" "")
396                    (udiv:SI (reg:SI 4)
397                             (reg:SI 5)))
398               (clobber (reg:SI 18))
399               (clobber (reg:SI 17))
400               (clobber (reg:SI 4))
401               (use (match_dup 3))])]
402   ""
403   "operands[3] = gen_reg_rtx(SImode);")
404
405 (define_insn ""
406   [(set (match_operand:SI 1 "register_operand" "=z")
407         (div:SI (reg:SI 4) (reg:SI 5)))
408    (clobber (reg:SI 18))
409    (clobber (reg:SI 17))
410    (clobber (reg:SI 1))
411    (clobber (reg:SI 2))
412    (clobber (reg:SI 3))
413    (use (match_operand:SI 0 "arith_reg_operand" "r"))]
414   ""
415   "jsr  @%0%#"
416   [(set_attr "type" "sfunc")
417    (set_attr "needs_delay_slot" "yes")])
418
419 (define_expand "divsi3"
420   [(set (reg:SI 4) (match_operand:SI 1 "general_operand" ""))
421    (set (reg:SI 5) (match_operand:SI 2 "general_operand" ""))
422    (set (match_dup 3) (symbol_ref:SI "__sdivsi3"))
423    (parallel [(set (match_operand:SI 0 "register_operand" "")
424                    (div:SI (reg:SI 4)
425                            (reg:SI 5)))
426               (clobber (reg:SI 18))
427               (clobber (reg:SI 17))
428               (clobber (reg:SI 1))
429               (clobber (reg:SI 2))
430               (clobber (reg:SI 3))
431               (use (match_dup 3))])]
432   ""
433   "operands[3] = gen_reg_rtx(SImode);")
434 \f
435 ;; -------------------------------------------------------------------------
436 ;; Multiplication instructions
437 ;; -------------------------------------------------------------------------
438
439 (define_insn ""
440   [(set (reg:SI 21)
441         (mult:SI (zero_extend:SI (match_operand:HI 0 "arith_reg_operand" "r"))
442                  (zero_extend:SI (match_operand:HI 1 "arith_reg_operand" "r"))))]
443   ""
444   "mulu %1,%0"
445   [(set_attr "type" "smpy")])
446
447 (define_insn ""
448   [(set (reg:SI 21)
449         (mult:SI (sign_extend:SI
450                   (match_operand:HI 0 "arith_reg_operand" "r"))
451                  (sign_extend:SI
452                   (match_operand:HI 1 "arith_reg_operand" "r"))))]
453   ""
454   "muls %1,%0"
455   [(set_attr "type" "smpy")])
456
457 (define_expand "mulhisi3"
458   [(set (reg:SI 21)
459         (mult:SI (sign_extend:SI
460                   (match_operand:HI 1 "arith_reg_operand" ""))
461                  (sign_extend:SI
462                   (match_operand:HI 2 "arith_reg_operand" ""))))
463    (set (match_operand:SI 0 "arith_reg_operand" "")
464         (reg:SI 21))]
465   ""
466   "")
467
468 (define_expand "umulhisi3"
469   [(set (reg:SI 21)
470         (mult:SI (zero_extend:SI
471                   (match_operand:HI 1 "arith_reg_operand" ""))
472                  (zero_extend:SI
473                   (match_operand:HI 2 "arith_reg_operand" ""))))
474    (set (match_operand:SI 0 "arith_reg_operand" "")
475         (reg:SI 21))]
476   ""
477   "")
478
479 ;; mulsi3 on the SH2 can be done in one instruction, on the SH1 we generate
480 ;; a call to a routine which clobbers known registers.
481
482 (define_insn ""
483   [(set (match_operand:SI 1 "register_operand" "=z")
484         (mult:SI (reg:SI 4) (reg:SI 5)))
485    (clobber (reg:SI 21))
486    (clobber (reg:SI 18))
487    (clobber (reg:SI 17))
488    (clobber (reg:SI 3))
489    (clobber (reg:SI 2))
490    (clobber (reg:SI 1))
491    (use (match_operand:SI 0 "arith_reg_operand" "r"))]
492   ""
493   "jsr  @%0%#"
494   [(set_attr "type" "sfunc")
495    (set_attr "needs_delay_slot" "yes")])
496
497 (define_expand "mulsi3_call"
498   [(set (reg:SI 4) (match_operand:SI 1 "general_operand" ""))
499    (set (reg:SI 5) (match_operand:SI 2 "general_operand" ""))
500    (set (match_dup 3) (symbol_ref:SI "__mulsi3"))
501    (parallel[(set (match_operand:SI 0 "register_operand" "")
502                   (mult:SI (reg:SI 4)
503                            (reg:SI 5)))
504              (clobber (reg:SI 21))
505              (clobber (reg:SI 18))
506              (clobber (reg:SI 17))
507              (clobber (reg:SI 3))
508              (clobber (reg:SI 2))
509              (clobber (reg:SI 1))
510              (use (match_dup 3))])]
511   ""
512   "operands[3] = gen_reg_rtx(SImode);")
513
514 (define_insn "mul_l"
515   [(set (reg:SI 21)
516         (mult:SI (match_operand:SI 0 "arith_reg_operand" "r")
517                  (match_operand:SI 1 "arith_reg_operand" "r")))]
518   "TARGET_SH2"
519   "mul.l        %1,%0"
520   [(set_attr "type" "dmpy")])
521
522 (define_expand "mulsi3"
523   [(set (reg:SI 21)
524         (mult:SI  (match_operand:SI 1 "arith_reg_operand" "")
525                   (match_operand:SI 2 "arith_reg_operand" "")))
526    (set (match_operand:SI 0 "arith_reg_operand" "")
527         (reg:SI 21))]
528   ""
529   "
530 {
531   if (!TARGET_SH2)
532     {
533       FAIL;
534       /* ??? Does this give worse or better code?  */
535       emit_insn (gen_mulsi3_call (operands[0], operands[1], operands[2]));
536       DONE;
537     }
538 }")
539
540 (define_insn "mulsidi3_i"
541   [(set (reg:DI 20)
542         (mult:DI (sign_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
543                  (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r"))))]
544   "TARGET_SH2"
545   "dmuls.l      %1,%0"
546   [(set_attr "type" "dmpy")])
547
548 (define_expand "mulsidi3"
549   [(set (reg:DI 20)
550         (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
551                  (sign_extend:DI (match_operand:SI 2 "arith_reg_operand" ""))))
552    (set (match_operand:DI 0 "arith_reg_operand" "")
553         (reg:DI 20))]
554   "TARGET_SH2"
555   "
556 {
557   /* We must swap the two words when copying them from MACH/MACL to the
558      output register.  */
559   if (TARGET_LITTLE_ENDIAN)
560     {
561       rtx low_dst = operand_subword (operands[0], 0, 1, DImode);
562       rtx high_dst = operand_subword (operands[0], 1, 1, DImode);
563
564       emit_insn (gen_mulsidi3_i (operands[1], operands[2]));
565
566       emit_insn (gen_rtx (CLOBBER, VOIDmode, operands[0]));
567       emit_move_insn (low_dst, gen_rtx (REG, SImode, 21));
568       emit_move_insn (high_dst, gen_rtx (REG, SImode, 20));
569       DONE;
570     }
571 }")
572
573 (define_insn "umulsidi3_i"
574   [(set (reg:DI 20)
575         (mult:DI (zero_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
576                  (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r"))))]
577   "TARGET_SH2"
578   "dmulu.l      %1,%0"
579   [(set_attr "type" "dmpy")])
580
581 (define_expand "umulsidi3"
582   [(set (reg:DI 20)
583         (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
584                  (zero_extend:DI (match_operand:SI 2 "arith_reg_operand" ""))))
585    (set (match_operand:DI 0 "arith_reg_operand" "")
586         (reg:DI 20))]
587   "TARGET_SH2"
588   "
589 {
590   /* We must swap the two words when copying them from MACH/MACL to the
591      output register.  */
592   if (TARGET_LITTLE_ENDIAN)
593     {
594       rtx low_dst = operand_subword (operands[0], 0, 1, DImode);
595       rtx high_dst = operand_subword (operands[0], 1, 1, DImode);
596
597       emit_insn (gen_umulsidi3_i (operands[1], operands[2]));
598
599       emit_insn (gen_rtx (CLOBBER, VOIDmode, operands[0]));
600       emit_move_insn (low_dst, gen_rtx (REG, SImode, 21));
601       emit_move_insn (high_dst, gen_rtx (REG, SImode, 20));
602       DONE;
603     }
604 }")
605
606 (define_insn ""
607   [(set (reg:SI 20)
608         (truncate:SI
609          (lshiftrt:DI (mult:DI (sign_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
610                                (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
611                       (const_int 32))))
612    (clobber (reg:SI 21))]
613   "TARGET_SH2"
614   "dmuls.l      %1,%0"
615   [(set_attr "type" "dmpy")])
616
617 (define_expand "smulsi3_highpart"
618   [(parallel [(set (reg:SI 20)
619                    (truncate:SI
620                     (lshiftrt:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
621                                           (sign_extend:DI (match_operand:SI 2 "arith_reg_operand" "")))
622                                  (const_int 32))))
623               (clobber (reg:SI 21))])
624    (set (match_operand:SI 0 "arith_reg_operand" "")
625         (reg:SI 20))]
626   "TARGET_SH2"
627   "")
628
629 (define_insn ""
630   [(set (reg:SI 20)
631         (truncate:SI
632          (lshiftrt:DI (mult:DI (zero_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
633                                (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
634                       (const_int 32))))
635    (clobber (reg:SI 21))]
636   "TARGET_SH2"
637   "dmulu.l      %1,%0"
638   [(set_attr "type" "dmpy")])
639
640 (define_expand "umulsi3_highpart"
641   [(parallel [(set (reg:SI 20)
642                    (truncate:SI
643                     (lshiftrt:DI (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
644                                           (zero_extend:DI (match_operand:SI 2 "arith_reg_operand" "")))
645                                  (const_int 32))))
646               (clobber (reg:SI 21))])
647    (set (match_operand:SI 0 "arith_reg_operand" "")
648         (reg:SI 20))]
649   "TARGET_SH2"
650   "")
651 \f
652 ;; -------------------------------------------------------------------------
653 ;; Logical operations
654 ;; -------------------------------------------------------------------------
655
656 (define_insn ""
657   [(set (match_operand:SI 0 "arith_reg_operand" "=r,z")
658         (and:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
659                 (match_operand:SI 2 "logical_operand" "r,L")))]
660   ""
661   "and  %2,%0"
662   [(set_attr "type" "arith")])
663
664 ;; If the constant is 255, then emit a extu.b instruction instead of an
665 ;; and, since that will give better code.
666
667 (define_expand "andsi3"
668   [(set (match_operand:SI 0 "arith_reg_operand" "")
669         (and:SI (match_operand:SI 1 "arith_reg_operand" "")
670                 (match_operand:SI 2 "logical_operand" "")))]
671   ""
672   "
673 {
674   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) == 255)
675     {
676       emit_insn (gen_zero_extendqisi2 (operands[0],
677                                        gen_lowpart (QImode, operands[1])));
678       DONE;
679     }
680 }")
681
682 (define_insn "iorsi3"
683   [(set (match_operand:SI 0 "arith_reg_operand" "=r,z")
684         (ior:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
685                 (match_operand:SI 2 "logical_operand" "r,L")))]
686   ""
687   "or   %2,%0")
688
689 (define_insn "xorsi3"
690   [(set (match_operand:SI 0 "arith_reg_operand" "=z,r")
691         (xor:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
692                 (match_operand:SI 2 "logical_operand" "L,r")))]
693   ""
694   "xor  %2,%0"
695   [(set_attr "type" "arith")])
696 \f
697 ;; -------------------------------------------------------------------------
698 ;; Shifts and rotates
699 ;; -------------------------------------------------------------------------
700
701 (define_insn "rotlsi3_1"
702   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
703         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
704                    (const_int 1)))
705    (set (reg:SI 18)
706         (lshiftrt:SI (match_dup 1) (const_int 31)))]
707   ""
708   "rotl %0")
709
710 (define_insn "rotlsi3_31"
711   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
712         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
713                    (const_int 31)))
714    (clobber (reg:SI 18))]
715   ""
716   "rotr %0")
717
718 (define_insn ""
719   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
720         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "r")
721                    (const_int 16)))]
722   ""
723   "swap.w       %1,%0")
724
725 (define_expand "rotlsi3"
726   [(set (match_operand:SI 0 "arith_reg_operand" "")
727         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "")
728                    (match_operand:SI 2 "immediate_operand" "")))]
729   ""
730   "
731 {
732   if (GET_CODE (operands[2]) != CONST_INT)
733     FAIL;
734
735   if (INTVAL (operands[2]) == 1)
736     {
737       emit_insn (gen_rotlsi3_1 (operands[0], operands[1]));
738       DONE;
739     }
740   else if (INTVAL (operands[2]) == 31)
741     {
742       emit_insn (gen_rotlsi3_31 (operands[0], operands[1]));
743       DONE;
744     }
745   else if (INTVAL (operands[2]) != 16)
746     FAIL;
747 }")
748
749 (define_insn ""
750   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
751         (rotate:HI (match_operand:HI 1 "arith_reg_operand" "r")
752                    (const_int 8)))]
753   ""
754   "swap.b       %1,%0")
755
756 (define_expand "rotlhi3"
757   [(set (match_operand:HI 0 "arith_reg_operand" "")
758         (rotate:HI (match_operand:HI 1 "arith_reg_operand" "")
759                    (match_operand:HI 2 "immediate_operand" "")))]
760   ""
761   "
762 {
763   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 8)
764     FAIL;
765 }")
766
767 ;;
768 ;; shift left
769
770 (define_insn "ashlsi3_d"
771   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
772         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
773                    (match_operand:SI 2 "arith_reg_operand" "r")))]
774   "TARGET_SH3"
775   "shld %2,%0")
776
777 (define_insn "ashlsi3_k"
778   [(set (match_operand:SI 0 "arith_reg_operand" "=r,r")
779         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0,0")
780                    (match_operand:SI 2 "const_int_operand" "M,K")))]
781   "CONST_OK_FOR_K (INTVAL (operands[2]))"
782   "@
783         add     %0,%0
784         shll%O2 %0")
785
786 (define_insn "ashlhi3_k"
787   [(set (match_operand:HI 0 "arith_reg_operand" "=r,r")
788         (ashift:HI (match_operand:HI 1 "arith_reg_operand" "0,0")
789                    (match_operand:HI 2 "const_int_operand" "M,K")))]
790   "CONST_OK_FOR_K (INTVAL (operands[2]))"
791   "@
792         add     %0,%0
793         shll%O2 %0")
794
795 (define_insn "ashlsi3_n"
796   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
797         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
798                    (match_operand:SI 2 "const_int_operand" "n")))
799    (clobber (reg:SI 18))]
800   ""
801   "#"
802   [(set (attr "length")
803         (cond [(eq (symbol_ref "shift_insns_rtx (insn)") (const_int 1))
804                (const_string "2")
805                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 2))
806                (const_string "4")
807                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 3))
808                (const_string "6")]
809               (const_string "8")))
810    (set_attr "type" "arith")])
811
812 (define_split
813   [(set (match_operand:SI 0 "arith_reg_operand" "")
814         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "")
815                    (match_operand:SI 2 "const_int_operand" "n")))
816    (clobber (reg:SI 18))]
817   ""
818   [(use (reg:SI 0))]
819   "
820 {
821   gen_shifty_op (ASHIFT, operands);
822   DONE;
823 }")
824
825 (define_expand "ashlsi3"
826   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "")
827                    (ashift:SI (match_operand:SI 1 "arith_reg_operand" "")
828                               (match_operand:SI 2 "nonmemory_operand" "")))
829               (clobber (reg:SI 18))])]
830   ""
831   "
832 {
833   if (TARGET_SH3 && arith_reg_operand (operands[2], GET_MODE (operands[2])))
834     {
835       emit_insn (gen_ashlsi3_d (operands[0], operands[1], operands[2]));
836       DONE;
837     }
838   if (! immediate_operand (operands[2], GET_MODE (operands[2])))
839     FAIL;
840 }")
841
842 (define_insn "ashlhi3"
843   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
844         (ashift:HI (match_operand:HI 1 "arith_reg_operand" "0")
845                    (match_operand:HI 2 "const_int_operand" "n")))
846    (clobber (reg:SI 18))]
847   ""
848   "#"
849   [(set (attr "length")
850         (cond [(eq (symbol_ref "shift_insns_rtx (insn)") (const_int 1))
851                (const_string "2")
852                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 2))
853                (const_string "4")]
854               (const_string "6")))
855    (set_attr "type" "arith")])
856
857 (define_split
858   [(set (match_operand:HI 0 "arith_reg_operand" "")
859         (ashift:HI (match_operand:HI 1 "arith_reg_operand" "")
860                    (match_operand:HI 2 "const_int_operand" "n")))
861    (clobber (reg:SI 18))]
862   ""
863   [(use (reg:SI 0))]
864   "
865 {
866   gen_shifty_hi_op (ASHIFT, operands);
867   DONE;
868 }")
869
870 ;
871 ; arithmetic shift right
872 ;
873
874 (define_insn "ashrsi3_k"
875   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
876         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
877                      (match_operand:SI 2 "const_int_operand" "M")))
878    (clobber (reg:SI 18))]
879   "INTVAL (operands[2]) == 1"
880   "shar %0"
881   [(set_attr "type" "arith")])
882
883 (define_insn "ashrhi3_k"
884   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
885         (ashiftrt:HI (match_operand:HI 1 "arith_reg_operand" "0")
886                      (match_operand:HI 2 "const_int_operand" "M")))
887    (clobber (reg:SI 18))]
888   "INTVAL (operands[2]) == 1"
889   "shar %0"
890   [(set_attr "type" "arith")])
891
892 ;; ??? This should be a define expand.
893
894 (define_insn "ashrsi2_16"
895   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
896         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "r")
897                      (const_int 16)))]
898   ""
899   "swap.w       %1,%0\;exts.w   %0,%0"
900   [(set_attr "length" "4")])
901
902 ;; ??? This should be a define expand.
903
904 (define_insn "ashrsi2_31"
905   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
906         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
907                      (const_int 31)))
908    (clobber (reg:SI 18))]
909   ""
910   "@
911    shll %0\;subc        %0,%0"
912   [(set_attr "length" "4")])
913
914 (define_insn "ashrsi3_d"
915   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
916         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
917                      (neg:SI (match_operand:SI 2 "arith_reg_operand" "r"))))]
918   "TARGET_SH3"
919   "shad %2,%0")
920
921 (define_insn "ashrsi3_n"
922   [(set (reg:SI 4)
923         (ashiftrt:SI (reg:SI 4)
924                      (match_operand:SI 0 "const_int_operand" "i")))
925    (clobber (reg:SI 18))
926    (clobber (reg:SI 17))
927    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
928   ""
929   "jsr  @%1%#"
930   [(set_attr "type" "sfunc")
931    (set_attr "needs_delay_slot" "yes")])
932
933 (define_expand "ashrsi3"
934   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "")
935                    (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
936                                 (match_operand:SI 2 "nonmemory_operand" "")))
937               (clobber (reg:SI 18))])]
938   ""
939   "if (expand_ashiftrt (operands)) DONE; else FAIL;")
940
941 ;; logical shift right
942
943 (define_insn "lshrsi3_d"
944   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
945         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
946                      (neg:SI (match_operand:SI 2 "arith_reg_operand" "r"))))]
947   "TARGET_SH3"
948   "shld %2,%0")
949
950 ;;  Only the single bit shift clobbers the T bit.
951
952 (define_insn "lshrsi3_m"
953   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
954         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
955                      (match_operand:SI 2 "const_int_operand" "M")))
956    (clobber (reg:SI 18))]
957   "CONST_OK_FOR_M (INTVAL (operands[2]))"
958   "shlr %0")
959
960 (define_insn "lshrsi3_k"
961   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
962         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
963                      (match_operand:SI 2 "const_int_operand" "K")))]
964   "CONST_OK_FOR_K (INTVAL (operands[2]))
965    && ! CONST_OK_FOR_M (INTVAL (operands[2]))"
966   "shlr%O2      %0")
967
968 (define_insn "lshrhi3_m"
969   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
970         (lshiftrt:HI (match_operand:HI 1 "arith_reg_operand" "0")
971                      (match_operand:HI 2 "const_int_operand" "M")))
972    (clobber (reg:SI 18))]
973   "CONST_OK_FOR_M (INTVAL (operands[2]))"
974   "shlr %0")
975
976 (define_insn "lshrhi3_k"
977   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
978         (lshiftrt:HI (match_operand:HI 1 "arith_reg_operand" "0")
979                      (match_operand:HI 2 "const_int_operand" "K")))]
980   "CONST_OK_FOR_K (INTVAL (operands[2]))
981    && ! CONST_OK_FOR_M (INTVAL (operands[2]))"
982   "shlr%O2      %0")
983
984 (define_insn "lshrsi3_n"
985   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
986         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
987                      (match_operand:SI 2 "const_int_operand" "n")))
988    (clobber (reg:SI 18))]
989   ""
990   "#"
991   [(set (attr "length")
992         (cond [(eq (symbol_ref "shift_insns_rtx (insn)") (const_int 1))
993                (const_string "2")
994                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 2))
995                (const_string "4")
996                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 3))
997                (const_string "6")]
998               (const_string "8")))
999    (set_attr "type" "arith")])
1000
1001 (define_split
1002   [(set (match_operand:SI 0 "arith_reg_operand" "")
1003         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
1004                      (match_operand:SI 2 "const_int_operand" "n")))
1005    (clobber (reg:SI 18))]
1006   ""
1007   [(use (reg:SI 0))]
1008   "
1009 {
1010   gen_shifty_op (LSHIFTRT, operands);
1011   DONE;
1012 }")
1013
1014 (define_expand "lshrsi3"
1015   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "")
1016                    (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
1017                                 (match_operand:SI 2 "nonmemory_operand" "")))
1018               (clobber (reg:SI 18))])]
1019   ""
1020   "
1021 {
1022   if (TARGET_SH3 && arith_reg_operand (operands[2], GET_MODE (operands[2])))
1023     {
1024       rtx count = copy_to_mode_reg (SImode, operands[2]);
1025       emit_insn (gen_negsi2 (count, count));
1026       emit_insn (gen_lshrsi3_d (operands[0], operands[1], count));
1027       DONE;
1028     }
1029   if (! immediate_operand (operands[2], GET_MODE (operands[2])))
1030     FAIL;
1031 }")
1032
1033 (define_insn "lshrhi3"
1034   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
1035         (lshiftrt:HI (match_operand:HI 1 "arith_reg_operand" "0")
1036                      (match_operand:HI 2 "const_int_operand" "n")))
1037    (clobber (reg:SI 18))]
1038   ""
1039   "#"
1040 ;; ??? length attribute is sometimes six instead of four.
1041   [(set (attr "length")
1042         (cond [(eq (symbol_ref "shift_insns_rtx (insn)") (const_int 1))
1043                (const_string "2")
1044                (eq (symbol_ref "shift_insns_rtx (insn)") (const_int 2))
1045                (const_string "4")]
1046               (const_string "6")))
1047    (set_attr "type" "arith")])
1048
1049 (define_split
1050   [(set (match_operand:HI 0 "arith_reg_operand" "")
1051         (lshiftrt:HI (match_operand:HI 1 "arith_reg_operand" "")
1052                      (match_operand:HI 2 "const_int_operand" "n")))
1053    (clobber (reg:SI 18))]
1054   ""
1055   [(use (reg:SI 0))]
1056   "
1057 {
1058   gen_shifty_hi_op (LSHIFTRT, operands);
1059   DONE;
1060 }")
1061
1062 ;; ??? This should be a define expand.
1063
1064 (define_insn "ashldi3_k"
1065   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
1066         (ashift:DI (match_operand:DI 1 "arith_reg_operand" "0")
1067                    (const_int 1)))
1068    (clobber (reg:SI 18))]
1069   ""
1070   "shll %R0\;rotcl      %S0"
1071   [(set_attr "length" "4")])
1072
1073 (define_expand "ashldi3"
1074   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
1075                    (ashift:DI (match_operand:DI 1 "arith_reg_operand" "")
1076                               (match_operand:DI 2 "immediate_operand" "")))
1077               (clobber (reg:SI 18))])]
1078   ""
1079   "{ if (GET_CODE (operands[2]) != CONST_INT
1080          || INTVAL (operands[2]) != 1) FAIL;} ")
1081
1082 ;; ??? This should be a define expand.
1083
1084 (define_insn "lshrdi3_k"
1085   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
1086         (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
1087                      (const_int 1)))
1088    (clobber (reg:SI 18))]
1089   ""
1090   "shlr %S0\;rotcr      %R0"
1091   [(set_attr "length" "4")])
1092
1093 (define_expand "lshrdi3"
1094   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
1095                    (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
1096                                (match_operand:DI 2 "immediate_operand" "")))
1097              (clobber (reg:SI 18))])]
1098   ""
1099   "{ if (GET_CODE (operands[2]) != CONST_INT
1100          || INTVAL (operands[2]) != 1) FAIL;} ")
1101
1102 ;; ??? This should be a define expand.
1103
1104 (define_insn "ashrdi3_k"
1105   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
1106         (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
1107                      (const_int 1)))
1108    (clobber (reg:SI 18))]
1109   ""
1110   "shar %S0\;rotcr      %R0"
1111   [(set_attr "length" "4")])
1112
1113 (define_expand "ashrdi3"
1114   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
1115                    (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
1116                                 (match_operand:DI 2 "immediate_operand" "")))
1117               (clobber (reg:SI 18))])]
1118   ""
1119   "{ if (GET_CODE (operands[2]) != CONST_INT
1120          || INTVAL (operands[2]) != 1) FAIL; } ")
1121
1122 ;; combined left/right shift
1123
1124 (define_split
1125   [(set (match_operand:SI 0 "register_operand" "")
1126         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
1127                            (match_operand:SI 2 "const_int_operand" "n"))
1128                 (match_operand:SI 3 "const_int_operand" "n")))]
1129   "(unsigned)INTVAL (operands[2]) < 32"
1130   [(use (reg:SI 0))]
1131   "if (gen_shl_and (operands[0], operands[2], operands[3], operands[1])) FAIL;
1132    DONE;")
1133
1134 (define_split
1135   [(set (match_operand:SI 0 "register_operand" "")
1136         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
1137                            (match_operand:SI 2 "const_int_operand" "n"))
1138                 (match_operand:SI 3 "const_int_operand" "n")))
1139    (clobber (reg:SI 18))]
1140   "(unsigned)INTVAL (operands[2]) < 32"
1141   [(use (reg:SI 0))]
1142   "if (gen_shl_and (operands[0], operands[2], operands[3], operands[1])) FAIL;
1143    DONE;")
1144
1145 (define_insn ""
1146   [(set (match_operand:SI 0 "register_operand" "=r")
1147         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
1148                            (match_operand:SI 2 "const_int_operand" "n"))
1149                 (match_operand:SI 3 "const_int_operand" "n")))
1150    (clobber (reg:SI 18))]
1151   "shl_and_kind (operands[2], operands[3], 0) == 1"
1152  "#"
1153   [(set (attr "length")
1154         (cond [(eq (symbol_ref "shl_and_length (insn)") (const_int 2))
1155                (const_string "4")
1156                (eq (symbol_ref "shl_and_length (insn)") (const_int 3))
1157                (const_string "6")
1158                (eq (symbol_ref "shl_and_length (insn)") (const_int 4))
1159                (const_string "8")
1160                (eq (symbol_ref "shl_and_length (insn)") (const_int 5))
1161                (const_string "10")
1162                (eq (symbol_ref "shl_and_length (insn)") (const_int 6))
1163                (const_string "12")
1164                (eq (symbol_ref "shl_and_length (insn)") (const_int 7))
1165                (const_string "14")
1166                (eq (symbol_ref "shl_and_length (insn)") (const_int 8))
1167                (const_string "16")]
1168               (const_string "18")))
1169    (set_attr "type" "arith")])
1170
1171 (define_insn ""
1172   [(set (match_operand:SI 0 "register_operand" "=z")
1173         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
1174                            (match_operand:SI 2 "const_int_operand" "n"))
1175                 (match_operand:SI 3 "const_int_operand" "n")))
1176    (clobber (reg:SI 18))]
1177   "shl_and_kind (operands[2], operands[3], 0) == 2"
1178  "#"
1179   [(set (attr "length")
1180         (cond [(eq (symbol_ref "shl_and_length (insn)") (const_int 2))
1181                (const_string "4")
1182                (eq (symbol_ref "shl_and_length (insn)") (const_int 3))
1183                (const_string "6")
1184                (eq (symbol_ref "shl_and_length (insn)") (const_int 4))
1185                (const_string "8")]
1186               (const_string "10")))
1187    (set_attr "type" "arith")])
1188
1189 ;; shift left / and combination with a scratch register: The combine pass
1190 ;; does not accept the individual instructions, even though they are
1191 ;; cheap.  But it needs a precise description so that it is usable after
1192 ;; reload.
1193 (define_insn "and_shl_scratch"
1194   [(set (match_operand:SI 0 "register_operand" "=r,&r")
1195         (lshiftrt:SI (ashift:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,0")
1196                                                      (match_operand:SI 2 "const_int_operand" "N,n"))
1197                                         (match_operand:SI 3 "" "0,r"))
1198                                 (match_operand:SI 4 "const_int_operand" "n,n"))
1199                      (match_operand:SI 5 "const_int_operand" "n,n")))
1200    (clobber (reg:SI 18))]
1201   ""
1202   "#"
1203   [(set (attr "length")
1204         (cond [(eq (symbol_ref "shl_and_scr_length (insn)") (const_int 2))
1205                (const_string "4")
1206                (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 3))
1207                (const_string "6")
1208                (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 4))
1209                (const_string "6")
1210                (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 5))
1211                (const_string "10")]
1212               (const_string "12")))
1213    (set_attr "type" "arith")])
1214
1215 (define_split
1216   [(set (match_operand:SI 0 "register_operand" "=r,&r")
1217         (lshiftrt:SI (ashift:SI (and:SI (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,0")
1218                                                      (match_operand:SI 2 "const_int_operand" "N,n"))
1219                                         (match_operand:SI 3 "register_operand" "0,r"))
1220                                 (match_operand:SI 4 "const_int_operand" "n,n"))
1221                      (match_operand:SI 5 "const_int_operand" "n,n")))
1222    (clobber (reg:SI 18))]
1223   ""
1224   [(use (reg:SI 0))]
1225   "
1226 {
1227   rtx and_source = operands[1];
1228
1229   if (INTVAL (operands[2]))
1230     {
1231       gen_shifty_op (LSHIFTRT, operands);
1232       and_source = operands[3];
1233     }
1234   emit_insn (gen_andsi3 (operands[0], operands[0], and_source));
1235   operands[2] = operands[4];
1236   gen_shifty_op (ASHIFT, operands);
1237   if (INTVAL (operands[5]))
1238     {
1239       operands[2] = operands[5];
1240       gen_shifty_op (LSHIFTRT, operands);
1241     }
1242   DONE;
1243 }")
1244
1245 ;; signed left/right shift combination.
1246 (define_split
1247   [(set (match_operand:SI 0 "register_operand" "=r")
1248         (sign_extract:SI (ashift:SI (match_operand:SI 1 "register_operand" "r")
1249                                     (match_operand:SI 2 "const_int_operand" "n"))
1250                          (match_operand:SI 3 "const_int_operand" "n")
1251                          (const_int 0)))
1252    (clobber (reg:SI 18))]
1253   ""
1254   [(use (reg:SI 0))]
1255   "if (gen_shl_sext (operands[0], operands[2], operands[3], operands[1])) FAIL;
1256    DONE;")
1257
1258 (define_insn "shl_sext_ext"
1259   [(set (match_operand:SI 0 "register_operand" "=r")
1260         (sign_extract:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
1261                                     (match_operand:SI 2 "const_int_operand" "n"))
1262                          (match_operand:SI 3 "const_int_operand" "n")
1263                          (const_int 0)))
1264    (clobber (reg:SI 18))]
1265   "shl_sext_kind (operands[2], operands[3], 0) <= 5"
1266   "#"
1267   [(set (attr "length")
1268         (cond [(eq (symbol_ref "shl_sext_length (insn)") (const_int 1))
1269                (const_string "2")
1270                (eq (symbol_ref "shl_sext_length (insn)") (const_int 2))
1271                (const_string "4")
1272                (eq (symbol_ref "shl_sext_length (insn)") (const_int 3))
1273                (const_string "6")
1274                (eq (symbol_ref "shl_sext_length (insn)") (const_int 4))
1275                (const_string "8")
1276                (eq (symbol_ref "shl_sext_length (insn)") (const_int 5))
1277                (const_string "10")
1278                (eq (symbol_ref "shl_sext_length (insn)") (const_int 6))
1279                (const_string "12")
1280                (eq (symbol_ref "shl_sext_length (insn)") (const_int 7))
1281                (const_string "14")
1282                (eq (symbol_ref "shl_sext_length (insn)") (const_int 8))
1283                (const_string "16")]
1284               (const_string "18")))
1285     (set_attr "type" "arith")])
1286
1287 (define_insn "shl_sext_sub"
1288   [(set (match_operand:SI 0 "register_operand" "=z")
1289         (sign_extract:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
1290                                     (match_operand:SI 2 "const_int_operand" "n"))
1291                          (match_operand:SI 3 "const_int_operand" "n")
1292                          (const_int 0)))
1293    (clobber (reg:SI 18))]
1294   "(shl_sext_kind (operands[2], operands[3], 0) & ~1) == 6"
1295   "#"
1296   [(set (attr "length")
1297         (cond [(eq (symbol_ref "shl_sext_length (insn)") (const_int 3))
1298                (const_string "6")
1299                (eq (symbol_ref "shl_sext_length (insn)") (const_int 4))
1300                (const_string "8")
1301                (eq (symbol_ref "shl_sext_length (insn)") (const_int 5))
1302                (const_string "10")
1303                (eq (symbol_ref "shl_sext_length (insn)") (const_int 6))
1304                (const_string "12")]
1305               (const_string "14")))
1306     (set_attr "type" "arith")])
1307
1308 \f
1309 ;; -------------------------------------------------------------------------
1310 ;; Unary arithmetic
1311 ;; -------------------------------------------------------------------------
1312
1313 (define_insn "negc"
1314   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1315         (neg:SI (plus:SI (reg:SI 18)
1316                          (match_operand:SI 1 "arith_reg_operand" "r"))))
1317    (set (reg:SI 18)
1318         (ne:SI (ior:SI (reg:SI 18) (match_dup 1))
1319                (const_int 0)))]
1320   ""
1321   "negc %1,%0"
1322   [(set_attr "type" "arith")])
1323
1324 (define_expand "negdi2"
1325   [(set (match_operand:DI 0 "arith_reg_operand" "")
1326         (neg:DI (match_operand:DI 1 "arith_reg_operand" "")))
1327    (clobber (reg:SI 18))]
1328   ""
1329   "
1330 {
1331   int low_word = (TARGET_LITTLE_ENDIAN ? 0 : 1);
1332   int high_word = (TARGET_LITTLE_ENDIAN ? 1 : 0);
1333
1334   rtx low_src = operand_subword (operands[1], low_word, 0, DImode);
1335   rtx high_src = operand_subword (operands[1], high_word, 0, DImode);
1336
1337   rtx low_dst = operand_subword (operands[0], low_word, 1, DImode);
1338   rtx high_dst = operand_subword (operands[0], high_word, 1, DImode);
1339
1340   emit_insn (gen_clrt ());
1341   emit_insn (gen_negc (low_dst, low_src));
1342   emit_insn (gen_negc (high_dst, high_src));
1343   DONE;
1344 }")
1345
1346 (define_insn "negsi2"
1347   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1348         (neg:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
1349   ""
1350   "neg  %1,%0"
1351   [(set_attr "type" "arith")])
1352
1353 (define_insn "one_cmplsi2"
1354   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1355         (not:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
1356   ""
1357   "not  %1,%0"
1358   [(set_attr "type" "arith")])
1359 \f
1360 ;; -------------------------------------------------------------------------
1361 ;; Zero extension instructions
1362 ;; -------------------------------------------------------------------------
1363
1364 (define_insn "zero_extendhisi2"
1365   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1366         (zero_extend:SI (match_operand:HI 1 "arith_reg_operand" "r")))]
1367   ""
1368   "extu.w       %1,%0"
1369   [(set_attr "type" "arith")])
1370
1371 (define_insn "zero_extendqisi2"
1372   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
1373         (zero_extend:SI (match_operand:QI 1 "arith_reg_operand" "r")))]
1374   ""
1375   "extu.b       %1,%0"
1376   [(set_attr "type" "arith")])
1377
1378 (define_insn "zero_extendqihi2"
1379   [(set (match_operand:HI 0 "arith_reg_operand" "=r")
1380         (zero_extend:HI (match_operand:QI 1 "arith_reg_operand" "r")))]
1381   ""
1382   "extu.b       %1,%0"
1383   [(set_attr "type" "arith")])
1384 \f
1385 ;; -------------------------------------------------------------------------
1386 ;; Sign extension instructions
1387 ;; -------------------------------------------------------------------------
1388
1389 ;; ??? This should be a define expand.
1390 ;; ??? Or perhaps it should be dropped?
1391
1392 (define_insn "extendsidi2"
1393   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
1394         (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
1395    (clobber (reg:SI 18))]
1396   ""
1397   "mov  %1,%S0\;mov     %1,%R0\;shll    %S0\;subc       %S0,%S0"
1398   [(set_attr "length" "8")])
1399
1400 (define_insn "extendhisi2"
1401   [(set (match_operand:SI 0 "arith_reg_operand" "=r,r")
1402         (sign_extend:SI (match_operand:HI 1 "general_movsrc_operand" "r,m")))]
1403   ""
1404   "@
1405         exts.w  %1,%0
1406         mov.w   %1,%0"
1407   [(set_attr "type" "arith,load")])
1408
1409 (define_insn "extendqisi2"
1410   [(set (match_operand:SI 0 "arith_reg_operand" "=r,r")
1411         (sign_extend:SI (match_operand:QI 1 "general_movsrc_operand" "r,m")))]
1412   ""
1413   "@
1414         exts.b  %1,%0
1415         mov.b   %1,%0"
1416   [(set_attr "type" "arith,load")])
1417
1418 (define_insn "extendqihi2"
1419   [(set (match_operand:HI 0 "arith_reg_operand" "=r,r")
1420         (sign_extend:HI (match_operand:QI 1 "general_movsrc_operand" "r,m")))]
1421   ""
1422   "@
1423         exts.b  %1,%0
1424         mov.b   %1,%0"
1425   [(set_attr "type" "arith,load")])
1426 \f
1427 ;; -------------------------------------------------------------------------
1428 ;; Move instructions
1429 ;; -------------------------------------------------------------------------
1430
1431 ;; define push and pop so it is easy for sh.c
1432
1433 (define_insn "push"
1434   [(set (mem:SI (pre_dec:SI (reg:SI 15)))
1435         (match_operand:SI 0 "register_operand" "r,l,x"))]
1436   ""
1437   "@
1438         mov.l   %0,@-r15
1439         sts.l   %0,@-r15
1440         sts.l   %0,@-r15"
1441   [(set_attr "type" "store,pstore,store")
1442    (set_attr "hit_stack" "yes")])
1443
1444 (define_insn "pop"
1445   [(set (match_operand:SI 0 "register_operand" "=r,l,x")
1446         (mem:SI (post_inc:SI (reg:SI 15))))]
1447   ""
1448   "@
1449         mov.l   @r15+,%0
1450         lds.l   @r15+,%0
1451         lds.l   @r15+,%0"
1452   [(set_attr "type" "load,pload,load")
1453    (set_attr "hit_stack" "yes")])
1454
1455 (define_insn "push_e"
1456   [(set (mem:SF (pre_dec:SI (reg:SI 15)))
1457         (match_operand:SF 0 "register_operand" "r,f,y"))]
1458   "TARGET_SH3E"
1459   "@
1460         mov.l   %0,@-r15
1461         fmov.s  %0,@-r15
1462         sts.l   %0,@-r15"
1463   [(set_attr "type" "store")
1464    (set_attr "hit_stack" "yes")])
1465
1466 (define_insn "pop_e"
1467   [(set (match_operand:SF 0 "register_operand" "=r,f,y")
1468         (mem:SF (post_inc:SI (reg:SI 15))))]
1469   "TARGET_SH3E"
1470   "@
1471         mov.l   @r15+,%0
1472         fmov.s  @r15+,%0
1473         lds.l   @r15+,%0"
1474   [(set_attr "type" "load")
1475    (set_attr "hit_stack" "yes")])
1476
1477 ;; These two patterns can happen as the result of optimization, when
1478 ;; comparisons get simplified to a move of zero or 1 into the T reg.
1479 ;; They don't disappear completely, because the T reg is a fixed hard reg.
1480
1481 (define_insn "clrt"
1482   [(set (reg:SI 18) (const_int 0))]
1483   ""
1484   "clrt")
1485
1486 (define_insn "sett"
1487   [(set (reg:SI 18) (const_int 1))]
1488   ""
1489   "sett")
1490
1491 ;; t/z is first, so that it will be preferred over r/r when reloading a move
1492 ;; of a pseudo-reg into the T reg
1493 (define_insn "movsi_i"
1494   [(set (match_operand:SI 0 "general_movdst_operand" "=t,r,r,r,r,r,m,<,xl,xl,r")
1495         (match_operand:SI 1 "general_movsrc_operand" "z,Q,rI,m,xl,t,r,xl,r,>,i"))]
1496   "
1497    ! TARGET_SH3E &&
1498    (register_operand (operands[0], SImode)
1499     || register_operand (operands[1], SImode))"
1500   "@
1501         tst     %1,%1\;rotcl    %1\;xor #1,%1\;rotcr    %1
1502         mov.l   %1,%0
1503         mov     %1,%0
1504         mov.l   %1,%0
1505         sts     %1,%0
1506         movt    %0
1507         mov.l   %1,%0
1508         sts.l   %1,%0
1509         lds     %1,%0
1510         lds.l   %1,%0
1511         fake    %1,%0"
1512   [(set_attr "type" "move,pcload,move,load,move,store,store,move,load,move,move")
1513    (set_attr "length" "8,*,*,*,*,*,*,*,*,*,*")])
1514
1515 ;; t/z is first, so that it will be preferred over r/r when reloading a move
1516 ;; of a pseudo-reg into the T reg
1517 ;; ??? This allows moves from macl to fpul to be recognized, but these moves
1518 ;; will require a reload.
1519 (define_insn "movsi_ie"
1520   [(set (match_operand:SI 0 "general_movdst_operand" "=t,r,r,r,r,r,m,<,xl,xl,r,y,r")
1521         (match_operand:SI 1 "general_movsrc_operand" "z,Q,rI,m,xl,t,r,xl,r,>,i,r,y"))]
1522   "TARGET_SH3E
1523    && (register_operand (operands[0], SImode)
1524        || register_operand (operands[1], SImode))"
1525   "@
1526         tst     %1,%1\;rotcl    %1\;xor #1,%1\;rotcr    %1
1527         mov.l   %1,%0
1528         mov     %1,%0
1529         mov.l   %1,%0
1530         sts     %1,%0
1531         movt    %0
1532         mov.l   %1,%0
1533         sts.l   %1,%0
1534         lds     %1,%0
1535         lds.l   %1,%0
1536         fake    %1,%0
1537         lds     %1,%0
1538         sts     %1,%0"
1539   [(set_attr "type" "move,pcload,move,load,move,store,store,move,load,move,move,move,move")
1540    (set_attr "length" "8,*,*,*,*,*,*,*,*,*,*,*,*")])
1541
1542 (define_expand "movsi"
1543   [(set (match_operand:SI 0 "general_movdst_operand" "")
1544         (match_operand:SI 1 "general_movsrc_operand" ""))]
1545   ""
1546   "{ if (prepare_move_operands (operands, SImode)) DONE; }")
1547
1548 (define_insn "movqi_i"
1549   [(set (match_operand:QI 0 "general_movdst_operand" "=r,r,m,r,r,l")
1550         (match_operand:QI 1 "general_movsrc_operand"  "ri,m,r,t,l,r"))]
1551   "arith_reg_operand (operands[0], QImode)
1552    || arith_reg_operand (operands[1], QImode)"
1553   "@
1554         mov     %1,%0
1555         mov.b   %1,%0
1556         mov.b   %1,%0
1557         movt    %0
1558         sts     %1,%0
1559         lds     %1,%0"
1560  [(set_attr "type" "move,load,store,move,move,move")])
1561
1562 (define_expand "movqi"
1563   [(set (match_operand:QI 0 "general_operand" "")
1564         (match_operand:QI 1 "general_operand"  ""))]
1565   ""
1566   "{ if (prepare_move_operands (operands, QImode)) DONE; }")
1567
1568 (define_insn "movhi_i"
1569   [(set (match_operand:HI 0 "general_movdst_operand" "=r,r,r,r,m,r,l,r")
1570         (match_operand:HI 1 "general_movsrc_operand" "Q,rI,m,t,r,l,r,i"))]
1571   "arith_reg_operand (operands[0], HImode)
1572    || arith_reg_operand (operands[1], HImode)"
1573   "@
1574         mov.w   %1,%0
1575         mov     %1,%0
1576         mov.w   %1,%0
1577         movt    %0
1578         mov.w   %1,%0
1579         sts     %1,%0
1580         lds     %1,%0
1581         fake    %1,%0"
1582   [(set_attr "type" "pcload,move,load,move,store,move,move,move")])
1583
1584 (define_expand "movhi"
1585   [(set (match_operand:HI 0 "general_movdst_operand" "")
1586         (match_operand:HI 1 "general_movsrc_operand"  ""))]
1587   ""
1588   "{ if (prepare_move_operands (operands, HImode)) DONE; }")
1589
1590 ;; ??? This should be a define expand.
1591
1592 (define_insn ""
1593   [(set (match_operand:DI 0 "general_movdst_operand" "=r,r,r,m,r,r")
1594         (match_operand:DI 1 "general_movsrc_operand" "Q,r,m,r,i,x"))]
1595   "arith_reg_operand (operands[0], DImode)
1596    || arith_reg_operand (operands[1], DImode)"
1597   "* return output_movedouble (insn, operands, DImode);"
1598   [(set_attr "length" "4")
1599    (set_attr "type" "pcload,move,load,store,move,move")])
1600
1601 ;; If the output is a register and the input is memory or a register, we have
1602 ;; to be careful and see which word needs to be loaded first.  
1603
1604 (define_split
1605   [(set (match_operand:DI 0 "general_movdst_operand" "")
1606         (match_operand:DI 1 "general_movsrc_operand" ""))]
1607   "reload_completed"
1608   [(set (match_dup 2) (match_dup 3))
1609    (set (match_dup 4) (match_dup 5))]
1610   "
1611 {
1612   int regno;
1613
1614   if ((GET_CODE (operands[0]) == MEM
1615        && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
1616       || (GET_CODE (operands[1]) == MEM
1617           && GET_CODE (XEXP (operands[1], 0)) == POST_INC))
1618     FAIL;
1619
1620   if (GET_CODE (operands[0]) == REG)
1621     regno = REGNO (operands[0]);
1622   else if (GET_CODE (operands[0]) == SUBREG)
1623     regno = REGNO (SUBREG_REG (operands[0])) + SUBREG_WORD (operands[0]);
1624   else if (GET_CODE (operands[0]) == MEM)
1625     regno = -1;
1626
1627   if (regno == -1
1628       || ! refers_to_regno_p (regno, regno + 1, operands[1], 0))
1629     {
1630       operands[2] = operand_subword (operands[0], 0, 0, DImode);
1631       operands[3] = operand_subword (operands[1], 0, 0, DImode);
1632       operands[4] = operand_subword (operands[0], 1, 0, DImode);
1633       operands[5] = operand_subword (operands[1], 1, 0, DImode);
1634     }
1635   else
1636     {
1637       operands[2] = operand_subword (operands[0], 1, 0, DImode);
1638       operands[3] = operand_subword (operands[1], 1, 0, DImode);
1639       operands[4] = operand_subword (operands[0], 0, 0, DImode);
1640       operands[5] = operand_subword (operands[1], 0, 0, DImode);
1641     }
1642
1643   if (operands[2] == 0 || operands[3] == 0
1644       || operands[4] == 0 || operands[5] == 0)
1645     FAIL;
1646 }")
1647
1648 (define_expand "movdi"
1649   [(set (match_operand:DI 0 "general_movdst_operand" "")
1650         (match_operand:DI 1 "general_movsrc_operand" ""))]
1651   ""
1652   "{ if ( prepare_move_operands (operands, DImode)) DONE; }")
1653
1654 ;; ??? This should be a define expand.
1655
1656 (define_insn "movdf_k"
1657   [(set (match_operand:DF 0 "general_movdst_operand" "=r,r,m")
1658         (match_operand:DF 1 "general_movsrc_operand" "r,m,r"))]
1659   "arith_reg_operand (operands[0], DFmode)
1660    || arith_reg_operand (operands[1], DFmode)"
1661   "* return output_movedouble (insn, operands, DFmode);"
1662   [(set_attr "length" "4")
1663    (set_attr "type" "move,load,store")])
1664
1665 ;; If the output is a register and the input is memory or a register, we have
1666 ;; to be careful and see which word needs to be loaded first.  
1667
1668 (define_split
1669   [(set (match_operand:DF 0 "general_movdst_operand" "")
1670         (match_operand:DF 1 "general_movsrc_operand" ""))]
1671   "reload_completed"
1672   [(set (match_dup 2) (match_dup 3))
1673    (set (match_dup 4) (match_dup 5))]
1674   "
1675 {
1676   int regno;
1677
1678   if ((GET_CODE (operands[0]) == MEM
1679        && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
1680       || (GET_CODE (operands[1]) == MEM
1681           && GET_CODE (XEXP (operands[1], 0)) == POST_INC))
1682     FAIL;
1683
1684   if (GET_CODE (operands[0]) == REG)
1685     regno = REGNO (operands[0]);
1686   else if (GET_CODE (operands[0]) == SUBREG)
1687     regno = REGNO (SUBREG_REG (operands[0])) + SUBREG_WORD (operands[0]);
1688   else if (GET_CODE (operands[0]) == MEM)
1689     regno = -1;
1690
1691   if (regno == -1
1692       || ! refers_to_regno_p (regno, regno + 1, operands[1], 0))
1693     {
1694       operands[2] = operand_subword (operands[0], 0, 0, DFmode);
1695       operands[3] = operand_subword (operands[1], 0, 0, DFmode);
1696       operands[4] = operand_subword (operands[0], 1, 0, DFmode);
1697       operands[5] = operand_subword (operands[1], 1, 0, DFmode);
1698     }
1699   else
1700     {
1701       operands[2] = operand_subword (operands[0], 1, 0, DFmode);
1702       operands[3] = operand_subword (operands[1], 1, 0, DFmode);
1703       operands[4] = operand_subword (operands[0], 0, 0, DFmode);
1704       operands[5] = operand_subword (operands[1], 0, 0, DFmode);
1705     }
1706
1707   if (operands[2] == 0 || operands[3] == 0
1708       || operands[4] == 0 || operands[5] == 0)
1709     FAIL;
1710 }")
1711
1712 ;; If a base address generated by LEGITIMIZE_ADDRESS for SImode is
1713 ;; used only once, let combine add in the index again.
1714
1715 (define_split
1716   [(set (match_operand:SI 0 "register_operand" "")
1717         (match_operand:SI 1 "" ""))
1718    (clobber (match_operand 2 "register_operand" ""))]
1719   "! reload_in_progress && ! reload_completed"
1720   [(use (reg:SI 0))]
1721   "
1722 {
1723   rtx addr, reg, const_int;
1724
1725   if (GET_CODE (operands[1]) != MEM)
1726     FAIL;
1727   addr = XEXP (operands[1], 0);
1728   if (GET_CODE (addr) != PLUS)
1729     FAIL;
1730   reg = XEXP (addr, 0);
1731   const_int = XEXP (addr, 1);
1732   if (GET_CODE (reg) != REG || GET_CODE (const_int) != CONST_INT)
1733     FAIL;
1734   emit_move_insn (operands[2], const_int);
1735   emit_move_insn (operands[0],
1736                   change_address (operands[1], VOIDmode,
1737                                   gen_rtx (PLUS, SImode, reg, operands[2])));
1738   DONE;
1739 }")
1740
1741 (define_split
1742   [(set (match_operand:SI 1 "" "")
1743         (match_operand:SI 0 "register_operand" ""))
1744    (clobber (match_operand 2 "register_operand" ""))]
1745   "! reload_in_progress && ! reload_completed"
1746   [(use (reg:SI 0))]
1747   "
1748 {
1749   rtx addr, reg, const_int;
1750
1751   if (GET_CODE (operands[1]) != MEM)
1752     FAIL;
1753   addr = XEXP (operands[1], 0);
1754   if (GET_CODE (addr) != PLUS)
1755     FAIL;
1756   reg = XEXP (addr, 0);
1757   const_int = XEXP (addr, 1);
1758   if (GET_CODE (reg) != REG || GET_CODE (const_int) != CONST_INT)
1759     FAIL;
1760   emit_move_insn (operands[2], const_int);
1761   emit_move_insn (change_address (operands[1], VOIDmode,
1762                                   gen_rtx (PLUS, SImode, reg, operands[2])),
1763                   operands[0]);
1764   DONE;
1765 }")
1766
1767 (define_expand "movdf"
1768   [(set (match_operand:DF 0 "general_movdst_operand" "")
1769         (match_operand:DF 1 "general_movsrc_operand" ""))]
1770   ""
1771   "{ if (prepare_move_operands (operands, DFmode)) DONE; }")
1772
1773 (define_insn "movsf_i"
1774   [(set (match_operand:SF 0 "general_movdst_operand" "=r,r,r,m,l,r")
1775         (match_operand:SF 1 "general_movsrc_operand"  "r,I,m,r,r,l"))]
1776   "
1777    ! TARGET_SH3E &&
1778    (arith_reg_operand (operands[0], SFmode)
1779     || arith_reg_operand (operands[1], SFmode))"
1780   "@
1781         mov     %1,%0
1782         mov     %1,%0
1783         mov.l   %1,%0
1784         mov.l   %1,%0
1785         lds     %1,%0
1786         sts     %1,%0"
1787   [(set_attr "type" "move,move,load,store,move,move")])
1788
1789 (define_insn "movsf_ie"
1790   [(set (match_operand:SF 0 "general_movdst_operand" "=f,r,f,f,f,m,r,m,!r,!f")
1791         (match_operand:SF 1 "general_movsrc_operand"  "f,r,G,H,m,f,m,r,f,r"))]
1792   "TARGET_SH3E
1793    && (arith_reg_operand (operands[0], SFmode)
1794        || arith_reg_operand (operands[1], SFmode))"
1795   "@
1796         fmov    %1,%0
1797         mov     %1,%0
1798         fldi0   %0
1799         fldi1   %0
1800         fmov.s  %1,%0
1801         fmov.s  %1,%0
1802         mov.l   %1,%0
1803         mov.l   %1,%0
1804         flds    %1,fpul\;sts    fpul,%0
1805         lds     %1,fpul\;fsts   fpul,%0"
1806   [(set_attr "type" "move,move,fp,fp,load,store,load,store,move,fp")
1807    (set_attr "length" "*,*,*,*,*,*,*,*,4,4")])
1808
1809 (define_expand "movsf"
1810   [(set (match_operand:SF 0 "general_movdst_operand" "")
1811         (match_operand:SF 1 "general_movsrc_operand" ""))]
1812   ""
1813   "{ if (prepare_move_operands (operands, SFmode)) DONE; }")
1814 \f
1815 ;; ------------------------------------------------------------------------
1816 ;; Define the real conditional branch instructions.
1817 ;; ------------------------------------------------------------------------
1818
1819 (define_insn "branch_true"
1820   [(set (pc) (if_then_else (ne (reg:SI 18) (const_int 0))
1821                            (label_ref (match_operand 0 "" ""))
1822                            (pc)))]
1823   ""
1824   "* return output_branch (1, insn, operands);"
1825   [(set_attr "type" "cbranch")])
1826
1827 (define_insn "branch_false"
1828   [(set (pc) (if_then_else (eq (reg:SI 18) (const_int 0))
1829                            (label_ref (match_operand 0 "" ""))
1830                            (pc)))]
1831   ""
1832   "* return output_branch (0, insn, operands);"
1833   [(set_attr "type" "cbranch")])
1834
1835 (define_insn "inverse_branch_true"
1836   [(set (pc) (if_then_else (ne (reg:SI 18) (const_int 0))
1837                            (pc)
1838                            (label_ref (match_operand 0 "" ""))))]
1839   ""
1840   "* return output_branch (0, insn, operands);"
1841   [(set_attr "type" "cbranch")])
1842
1843 (define_insn "inverse_branch_false"
1844   [(set (pc) (if_then_else (eq (reg:SI 18) (const_int 0))
1845                            (pc)
1846                            (label_ref (match_operand 0 "" ""))))]
1847   ""
1848   "* return output_branch (1, insn, operands);"
1849   [(set_attr "type" "cbranch")])
1850 \f
1851 ;; Conditional branch insns
1852
1853 (define_expand "beq"
1854   [(set (reg:SI 18) (eq:SI (match_dup 1) (match_dup 2)))
1855    (set (pc)
1856         (if_then_else (ne (reg:SI 18) (const_int 0))
1857                       (label_ref (match_operand 0 "" ""))
1858                       (pc)))]
1859   ""
1860   "from_compare (operands, EQ);")
1861
1862 ; There is no bne compare, so we reverse the branch arms.
1863
1864 (define_expand "bne"
1865   [(set (reg:SI 18) (eq:SI (match_dup 1) (match_dup 2)))
1866    (set (pc)
1867         (if_then_else (ne (reg:SI 18) (const_int 0))
1868                       (pc)
1869                       (label_ref (match_operand 0 "" ""))))]
1870   ""
1871   "from_compare (operands, NE);")
1872
1873 (define_expand "bgt"
1874   [(set (reg:SI 18) (gt:SI (match_dup 1) (match_dup 2)))
1875    (set (pc)
1876         (if_then_else (ne (reg:SI 18) (const_int 0))
1877                       (label_ref (match_operand 0 "" ""))
1878                       (pc)))]
1879   ""
1880   "from_compare (operands, GT);")
1881
1882 (define_expand "blt"
1883   [(set (reg:SI 18) (ge:SI (match_dup 1) (match_dup 2)))
1884    (set (pc)
1885         (if_then_else (ne (reg:SI 18) (const_int 0))
1886                       (pc)
1887                       (label_ref (match_operand 0 "" ""))))]
1888   ""
1889   "
1890 {
1891   if (GET_MODE (sh_compare_op0) == SFmode)
1892     {
1893       rtx tmp = sh_compare_op0;
1894       sh_compare_op0 = sh_compare_op1;
1895       sh_compare_op1 = tmp;
1896       emit_insn (gen_bgt (operands[0]));
1897       DONE;
1898     }
1899   from_compare (operands, LT);
1900 }")
1901
1902 (define_expand "ble"
1903   [(set (reg:SI 18) (gt:SI (match_dup 1) (match_dup 2)))
1904    (set (pc)
1905         (if_then_else (ne (reg:SI 18) (const_int 0))
1906                       (pc)
1907                       (label_ref (match_operand 0 "" ""))))]
1908   ""
1909   "from_compare (operands, LE);")
1910
1911 (define_expand "bge"
1912   [(set (reg:SI 18) (ge:SI (match_dup 1) (match_dup 2)))
1913    (set (pc)
1914         (if_then_else (ne (reg:SI 18) (const_int 0))
1915                       (label_ref (match_operand 0 "" ""))
1916                       (pc)))]
1917   ""
1918   "
1919 {
1920   if (GET_MODE (sh_compare_op0) == SFmode)
1921     {
1922       rtx tmp = sh_compare_op0;
1923       sh_compare_op0 = sh_compare_op1;
1924       sh_compare_op1 = tmp;
1925       emit_insn (gen_ble (operands[0]));
1926       DONE;
1927     }
1928   from_compare (operands, GE);
1929 }")
1930
1931 (define_expand "bgtu"
1932   [(set (reg:SI 18) (gtu:SI (match_dup 1) (match_dup 2)))
1933    (set (pc)
1934         (if_then_else (ne (reg:SI 18) (const_int 0))
1935                       (label_ref (match_operand 0 "" ""))
1936                       (pc)))]
1937   ""
1938   "from_compare (operands, GTU); ")
1939
1940 (define_expand "bltu"
1941   [(set (reg:SI 18) (geu:SI (match_dup 1) (match_dup 2)))
1942    (set (pc)
1943                   (if_then_else (ne (reg:SI 18) (const_int 0))
1944                                 (pc)
1945                                 (label_ref (match_operand 0 "" ""))))]
1946   ""
1947   "from_compare (operands, LTU);")
1948
1949 (define_expand "bgeu"
1950   [(set (reg:SI 18) (geu:SI (match_dup 1) (match_dup 2)))
1951    (set (pc)
1952         (if_then_else (ne (reg:SI 18) (const_int 0))
1953                       (label_ref (match_operand 0 "" ""))
1954                       (pc)))]
1955   ""
1956   "from_compare (operands, GEU);")
1957
1958 (define_expand "bleu"
1959   [(set (reg:SI 18) (gtu:SI (match_dup 1) (match_dup 2)))
1960    (set (pc)
1961         (if_then_else (ne (reg:SI 18) (const_int 0))
1962                       (pc)
1963                       (label_ref (match_operand 0 "" ""))))]
1964   ""
1965   "from_compare (operands, LEU);")
1966 \f
1967 ;; ------------------------------------------------------------------------
1968 ;; Jump and linkage insns
1969 ;; ------------------------------------------------------------------------
1970
1971 (define_insn "jump"
1972   [(set (pc)
1973         (label_ref (match_operand 0 "" "")))]
1974   ""
1975   "*
1976 {
1977   /* The length is 16 if the delay slot is unfilled.  */
1978   if (get_attr_length(insn) >= 14)
1979     return output_far_jump(insn, operands[0]);
1980   else
1981     return   \"bra      %l0%#\";
1982 }"
1983   [(set_attr "type" "jump")
1984    (set_attr "needs_delay_slot" "yes")])
1985
1986 (define_insn "calli"
1987   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
1988          (match_operand 1 "" ""))
1989    (clobber (reg:SI 17))]
1990   ""
1991   "jsr  @%0%#"
1992   [(set_attr "type" "call")
1993    (set_attr "needs_delay_slot" "yes")])
1994
1995 (define_insn "call_valuei"
1996   [(set (match_operand 0 "" "=rf")
1997         (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
1998               (match_operand 2 "" "")))
1999    (clobber (reg:SI 17))]
2000   ""
2001   "jsr  @%1%#"
2002   [(set_attr "type" "call")
2003    (set_attr "needs_delay_slot" "yes")])
2004
2005 (define_expand "call"
2006   [(parallel [(call (mem:SI (match_operand 0 "arith_reg_operand" ""))
2007                             (match_operand 1 "" ""))
2008               (clobber (reg:SI 17))])]
2009   ""
2010   "operands[0] = force_reg (SImode, XEXP (operands[0], 0));")
2011
2012 (define_expand "call_value"
2013   [(parallel [(set (match_operand 0 "arith_reg_operand" "")
2014                    (call (mem:SI (match_operand 1 "arith_reg_operand" ""))
2015                                  (match_operand 2 "" "")))
2016               (clobber (reg:SI 17))])]
2017   ""
2018   "operands[1] = force_reg (SImode, XEXP (operands[1], 0));")
2019
2020 (define_insn "indirect_jump"
2021   [(set (pc)
2022         (match_operand:SI 0 "arith_reg_operand" "r"))]
2023   ""
2024   "jmp  @%0%#"
2025   [(set_attr "needs_delay_slot" "yes")])
2026
2027 ;; This might seem redundant, but it helps us distinguish case table jumps
2028 ;; which can be present in structured code from indirect jumps which can not
2029 ;; be present in structured code.  This allows -fprofile-arcs to work.
2030
2031 (define_insn "*casesi_jump"
2032   [(set (pc)
2033         (match_operand:SI 0 "arith_reg_operand" "r"))
2034    (use (label_ref (match_operand 1 "" "")))]
2035   ""
2036   "jmp  @%0%#"
2037   [(set_attr "needs_delay_slot" "yes")])
2038
2039 ;; Call subroutine returning any type.
2040 ;; ??? This probably doesn't work.
2041
2042 (define_expand "untyped_call"
2043   [(parallel [(call (match_operand 0 "" "")
2044                     (const_int 0))
2045               (match_operand 1 "" "")
2046               (match_operand 2 "" "")])]
2047   "TARGET_SH3E"
2048   "
2049 {
2050   int i;
2051
2052   emit_call_insn (gen_call (operands[0], const0_rtx, const0_rtx, const0_rtx));
2053
2054   for (i = 0; i < XVECLEN (operands[2], 0); i++)
2055     {
2056       rtx set = XVECEXP (operands[2], 0, i);
2057       emit_move_insn (SET_DEST (set), SET_SRC (set));
2058     }
2059
2060   /* The optimizer does not know that the call sets the function value
2061      registers we stored in the result block.  We avoid problems by
2062      claiming that all hard registers are used and clobbered at this
2063      point.  */
2064   emit_insn (gen_blockage ());
2065
2066   DONE;
2067 }")
2068 \f
2069 ;; ------------------------------------------------------------------------
2070 ;; Misc insns
2071 ;; ------------------------------------------------------------------------
2072
2073 ;; ??? This combiner pattern does not work, because combine does not combine
2074 ;; instructions that set a hard register when SMALL_REGISTER_CLASSES is
2075 ;; defined.  Perhaps use a pseudo-reg for the T bit?
2076
2077 (define_insn "dect"
2078   [(parallel [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2079                    (plus:SI (match_dup 0)
2080                             (const_int -1)))
2081               (set (reg:SI 18)
2082                    (eq:SI (plus:SI (match_dup 0) (const_int -1))
2083                           (const_int 0)))])]
2084   "TARGET_SH2"
2085   "dt   %0")
2086
2087 (define_insn "nop"
2088   [(const_int 0)]
2089   ""
2090   "nop")
2091
2092 ;; Load address of a label. This is only generated by the casesi expand.
2093 ;; This must use unspec, because this only works immediately before a casesi.
2094
2095 (define_insn "mova"
2096   [(set (reg:SI 0)
2097         (unspec [(label_ref (match_operand 0 "" ""))] 1))]
2098   ""
2099   "mova %O0,r0"
2100   [(set_attr "in_delay_slot" "no")])
2101
2102 ;; case instruction for switch statements.
2103
2104 ;; Operand 0 is index
2105 ;; operand 1 is the minimum bound
2106 ;; operand 2 is the maximum bound - minimum bound + 1
2107 ;; operand 3 is CODE_LABEL for the table;
2108 ;; operand 4 is the CODE_LABEL to go to if index out of range.
2109
2110 ;; ??? There should be a barrier after the jump at the end.
2111
2112 (define_expand "casesi"
2113   [(set (match_dup 5) (match_operand:SI 0 "arith_reg_operand" ""))
2114    (set (match_dup 5) (minus:SI (match_dup 5)
2115                                 (match_operand:SI 1 "arith_operand" "")))
2116    (set (reg:SI 18)
2117         (gtu:SI (match_dup 5)
2118                 (match_operand:SI 2 "arith_reg_operand" "")))
2119    (set (pc)
2120         (if_then_else (ne (reg:SI 18)
2121                           (const_int 0))
2122                       (label_ref (match_operand 4 "" ""))
2123                       (pc)))
2124    (set (match_dup 6) (match_dup 5))
2125    (set (match_dup 6) (ashift:SI (match_dup 6) (match_dup 7)))
2126    (set (reg:SI 0) (unspec [(label_ref (match_operand 3 "" ""))] 1))
2127    (parallel [(set (reg:SI 0) (plus:SI (reg:SI 0)
2128                                        (mem:HI (plus:SI (reg:SI 0)
2129                                                         (match_dup 6)))))
2130               (set (match_dup 6) (mem:HI (plus:SI (reg:SI 0) (match_dup 6))))])
2131    (parallel [(set (pc) (reg:SI 0))
2132               (use (label_ref (match_dup 3)))])]
2133   ""
2134   "
2135 {
2136   operands[1] = copy_to_mode_reg (SImode, operands[1]);
2137   operands[2] = copy_to_mode_reg (SImode, operands[2]);
2138   operands[5] = gen_reg_rtx (SImode);
2139   operands[6] = gen_reg_rtx (SImode);
2140   operands[7] = GEN_INT (TARGET_BIGTABLE  ? 2 : 1);
2141 }")
2142
2143 (define_insn "casesi_worker"
2144   [(set (reg:SI 0)
2145         (plus:SI (reg:SI 0)
2146                  (mem:HI (plus:SI (reg:SI 0)
2147                                   (match_operand:SI 0 "arith_reg_operand" "+r")))))
2148    (set (match_dup 0) (mem:HI (plus:SI (reg:SI 0)
2149                                        (match_dup 0))))]
2150   ""
2151   "*
2152 {
2153   if (TARGET_BIGTABLE)
2154     return \"mov.l      @(r0,%0),%0\;add        %0,r0\";
2155   else
2156     return \"mov.w      @(r0,%0),%0\;add        %0,r0\";
2157 }"
2158   [(set_attr "length" "4")])
2159
2160 (define_insn "return"
2161   [(return)]
2162   "reload_completed"
2163   "%@   %#"
2164   [(set_attr "type" "return")
2165    (set_attr "needs_delay_slot" "yes")])
2166
2167 (define_expand "prologue"
2168   [(const_int 0)]
2169   ""
2170   "sh_expand_prologue (); DONE;")
2171
2172 (define_expand "epilogue"
2173   [(return)]
2174   ""
2175   "sh_expand_epilogue ();")
2176
2177 (define_insn "blockage"
2178   [(unspec_volatile [(const_int 0)] 0)]
2179   ""
2180   ""
2181   [(set_attr "length" "0")])
2182 \f
2183 ;; ------------------------------------------------------------------------
2184 ;; Scc instructions
2185 ;; ------------------------------------------------------------------------
2186
2187 (define_insn "movt"
2188   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2189         (eq:SI (reg:SI 18) (const_int 1)))]
2190   ""
2191   "movt %0")
2192
2193 (define_expand "seq"
2194   [(set (match_operand:SI 0 "arith_reg_operand" "")
2195         (match_dup 1))]
2196   ""
2197   "operands[1] = prepare_scc_operands (EQ);")
2198
2199 (define_expand "slt"
2200   [(set (match_operand:SI 0 "arith_reg_operand" "")
2201         (match_dup 1))]
2202   ""
2203   "operands[1] = prepare_scc_operands (LT);")
2204
2205 (define_expand "sle"
2206   [(set (match_operand:SI 0 "arith_reg_operand" "")
2207         (match_dup 1))]
2208   ""
2209   "
2210 {
2211   if (GET_MODE (sh_compare_op0) == SFmode)
2212     {
2213       emit_insn (gen_sgt (operands[0]));
2214       emit_insn (gen_xorsi3 (operands[0], operands[0], const1_rtx));
2215       DONE;
2216     }
2217   operands[1] = prepare_scc_operands (LE);
2218 }")
2219
2220 (define_expand "sgt"
2221   [(set (match_operand:SI 0 "arith_reg_operand" "")
2222         (match_dup 1))]
2223   ""
2224   "operands[1] = prepare_scc_operands (GT);")
2225
2226 (define_expand "sge"
2227   [(set (match_operand:SI 0 "arith_reg_operand" "")
2228         (match_dup 1))]
2229   ""
2230   "
2231 {
2232   if (GET_MODE (sh_compare_op0) == SFmode)
2233     {
2234       emit_insn (gen_slt (operands[0]));
2235       emit_insn (gen_xorsi3 (operands[0], operands[0], const1_rtx));
2236       DONE;
2237     }
2238   operands[1] = prepare_scc_operands (GE);
2239 }")
2240
2241 (define_expand "sgtu"
2242   [(set (match_operand:SI 0 "arith_reg_operand" "")
2243         (match_dup 1))]
2244   ""
2245   "operands[1] = prepare_scc_operands (GTU);")
2246
2247 (define_expand "sltu"
2248   [(set (match_operand:SI 0 "arith_reg_operand" "")
2249         (match_dup 1))]
2250   ""
2251   "operands[1] = prepare_scc_operands (LTU);")
2252
2253 (define_expand "sleu"
2254   [(set (match_operand:SI 0 "arith_reg_operand" "")
2255         (match_dup 1))]
2256   ""
2257   "operands[1] = prepare_scc_operands (LEU);")
2258
2259 (define_expand "sgeu"
2260   [(set (match_operand:SI 0 "arith_reg_operand" "")
2261         (match_dup 1))]
2262   ""
2263   "operands[1] = prepare_scc_operands (GEU);")
2264
2265 (define_expand "sne"
2266   [(set (match_operand:SI 0 "arith_reg_operand" "")
2267         (match_dup 1))
2268    (set (match_dup 0) (xor:SI (match_dup 0) (const_int 1)))]
2269   ""
2270   "operands[1] = prepare_scc_operands (EQ);")
2271
2272 ;; -------------------------------------------------------------------------
2273 ;; Instructions to cope with inline literal tables
2274 ;; -------------------------------------------------------------------------
2275
2276 ; 2 byte integer in line
2277
2278 (define_insn "consttable_2"
2279  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 2)]
2280  ""
2281  "*
2282 {
2283   assemble_integer (operands[0], 2, 1);
2284   return \"\";
2285 }"
2286  [(set_attr "length" "2")
2287  (set_attr "in_delay_slot" "no")])
2288
2289 ; 4 byte integer in line
2290
2291 (define_insn "consttable_4"
2292  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 4)]
2293  ""
2294  "*
2295 {
2296   assemble_integer (operands[0], 4, 1);
2297   return \"\";
2298 }"
2299  [(set_attr "length" "4")
2300   (set_attr "in_delay_slot" "no")])
2301
2302 ; 8 byte integer in line
2303
2304 (define_insn "consttable_8"
2305  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 6)]
2306  ""
2307  "*
2308 {
2309   assemble_integer (operands[0], 8, 1);
2310   return \"\";
2311 }"
2312  [(set_attr "length" "8")
2313   (set_attr "in_delay_slot" "no")])
2314
2315 ; align to a two byte boundary
2316
2317 (define_insn "align_2"
2318  [(unspec_volatile [(const_int 0)] 10)]
2319  ""
2320  ".align 1"
2321  [(set_attr "length" "0")
2322   (set_attr "in_delay_slot" "no")])
2323
2324 ; align to a four byte boundary
2325
2326 (define_insn "align_4"
2327  [(unspec_volatile [(const_int 0)] 5)]
2328  ""
2329  ".align 2"
2330  [(set_attr "in_delay_slot" "no")])
2331
2332 ; emitted at the end of the literal table, used to emit the
2333 ; 32bit branch labels if needed.
2334
2335 (define_insn "consttable_end"
2336   [(unspec_volatile [(const_int 0)] 11)]
2337   ""
2338   "* return output_jump_label_table ();"
2339   [(set_attr "in_delay_slot" "no")])
2340
2341 ;; -------------------------------------------------------------------------
2342 ;; Misc
2343 ;; -------------------------------------------------------------------------
2344
2345 ;; String/block move insn.
2346
2347 (define_expand "movstrsi"
2348   [(parallel [(set (mem:BLK (match_operand:BLK 0 "" ""))
2349                    (mem:BLK (match_operand:BLK 1 "" "")))
2350               (use (match_operand:SI 2 "nonmemory_operand" ""))
2351               (use (match_operand:SI 3 "immediate_operand" ""))
2352               (clobber (reg:SI 17))
2353               (clobber (reg:SI 4))
2354               (clobber (reg:SI 5))
2355               (clobber (reg:SI 0))])]
2356   ""
2357   "
2358 {
2359   if(expand_block_move (operands))
2360      DONE;
2361   else FAIL;
2362 }")
2363
2364 (define_insn "block_move_real"
2365   [(parallel [(set (mem:BLK (reg:SI 4))
2366                    (mem:BLK (reg:SI 5)))
2367               (use (match_operand:SI 0 "arith_reg_operand" "r"))
2368               (clobber (reg:SI 17))
2369               (clobber (reg:SI 0))])]
2370   ""
2371   "jsr  @%0%#"
2372   [(set_attr "type" "sfunc")
2373    (set_attr "needs_delay_slot" "yes")])
2374
2375 (define_insn "block_lump_real"
2376   [(parallel [(set (mem:BLK (reg:SI 4))
2377                    (mem:BLK (reg:SI 5)))
2378               (use (match_operand:SI 0 "arith_reg_operand" "r"))
2379               (use (reg:SI 6))
2380               (clobber (reg:SI 17))
2381               (clobber (reg:SI 4))
2382               (clobber (reg:SI 5))
2383               (clobber (reg:SI 6))
2384               (clobber (reg:SI 0))])]
2385   ""
2386   "jsr  @%0%#"
2387   [(set_attr "type" "sfunc")
2388    (set_attr "needs_delay_slot" "yes")])
2389 \f
2390 ;; -------------------------------------------------------------------------
2391 ;; Floating point instructions.
2392 ;; -------------------------------------------------------------------------
2393
2394 ;; ??? All patterns should have a type attribute.
2395
2396 (define_insn "addsf3"
2397   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
2398         (plus:SF (match_operand:SF 1 "arith_reg_operand" "%0")
2399                  (match_operand:SF 2 "arith_reg_operand" "f")))]
2400   "TARGET_SH3E"
2401   "fadd %2,%0"
2402   [(set_attr "type" "fp")])
2403
2404 (define_insn "subsf3"
2405   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
2406         (minus:SF (match_operand:SF 1 "arith_reg_operand" "0")
2407                   (match_operand:SF 2 "arith_reg_operand" "f")))]
2408   "TARGET_SH3E"
2409   "fsub %2,%0"
2410   [(set_attr "type" "fp")])
2411
2412 (define_insn "mulsf3"
2413   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
2414         (mult:SF (match_operand:SF 1 "arith_reg_operand" "%0")
2415                  (match_operand:SF 2 "arith_reg_operand" "f")))]
2416   "TARGET_SH3E"
2417   "fmul %2,%0"
2418   [(set_attr "type" "fp")])
2419
2420 (define_insn "*macsf3"
2421   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
2422         (plus:SF (mult:SF (match_operand:SF 1 "arith_reg_operand" "%w")
2423                           (match_operand:SF 2 "arith_reg_operand" "f"))
2424                  (match_operand:SF 3 "arith_reg_operand" "0")))]
2425   "TARGET_SH3E"
2426   "fmac fr0,%2,%0"
2427   [(set_attr "type" "fp")])
2428
2429 (define_insn "divsf3"
2430   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
2431         (div:SF (match_operand:SF 1 "arith_reg_operand" "0")
2432                 (match_operand:SF 2 "arith_reg_operand" "f")))]
2433   "TARGET_SH3E"
2434   "fdiv %2,%0"
2435   [(set_attr "type" "fdiv")])
2436
2437 ;; ??? This is the right solution, but it fails because the movs[if] patterns
2438 ;; silently clobber FPUL (r22) for int<->fp moves.  Thus we can not explicitly
2439 ;; use FPUL here.
2440 ;;
2441 ;;(define_expand "floatsisf2"
2442 ;;  [(set (reg:SI 22)
2443 ;;      (match_operand:SI 1 "arith_reg_operand" ""))
2444 ;;   (set (match_operand:SF 0 "arith_reg_operand" "")
2445 ;;        (float:SF (reg:SI 22)))]
2446 ;;  "TARGET_SH3E"
2447 ;;  "")
2448 ;;
2449 ;;(define_insn "*floatsisf"
2450 ;;  [(set (match_operand:SF 0 "arith_reg_operand" "=f")
2451 ;;      (float:SF (reg:SI 22)))]
2452 ;;  "TARGET_SH3E"
2453 ;;  "float      fpul,%0")
2454
2455 (define_insn "floatsisf2"
2456   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
2457         (float:SF (match_operand:SI 1 "arith_reg_operand" "r")))]
2458   "TARGET_SH3E"
2459   "lds  %1,fpul\;float  fpul,%0"
2460   [(set_attr "length" "4")
2461    (set_attr "type" "fp")])
2462
2463 ;; ??? This is the right solution, but it fails because the movs[if] patterns
2464 ;; silently clobber FPUL (r22) for int<->fp moves.  Thus we can not explicitly
2465 ;; use FPUL here.
2466 ;;
2467 ;;(define_expand "fix_truncsfsi2"
2468 ;;  [(set (reg:SI 22)
2469 ;;      (fix:SI (match_operand:SF 1 "arith_reg_operand" "f")))
2470 ;;   (set (match_operand:SI 0 "arith_reg_operand" "=r")
2471 ;;      (reg:SI 22))]
2472 ;;  "TARGET_SH3E"
2473 ;;  "")
2474 ;;
2475 ;;(define_insn "*fixsfsi"
2476 ;;  [(set (reg:SI 22)
2477 ;;      (fix:SI (match_operand:SF 0 "arith_reg_operand" "f")))]
2478 ;;  "TARGET_SH3E"
2479 ;;  "ftrc       %0,fpul")
2480
2481 (define_insn "fix_truncsfsi2"
2482   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2483         (fix:SI (match_operand:SF 1 "arith_reg_operand" "f")))]
2484   "TARGET_SH3E"
2485   "ftrc %1,fpul\;sts    fpul,%0"
2486   [(set_attr "length" "4")
2487    (set_attr "type" "move")])
2488
2489 ;; ??? This should be SFmode not SImode in the compare, but that would
2490 ;; require fixing the branch patterns too.
2491 (define_insn "*cmpgtsf_t"
2492   [(set (reg:SI 18) (gt:SI (match_operand:SF 0 "arith_reg_operand" "f")
2493                            (match_operand:SF 1 "arith_reg_operand" "f")))]
2494   "TARGET_SH3E"
2495   "fcmp/gt      %1,%0"
2496   [(set_attr "type" "fp")])
2497
2498 ;; ??? This should be SFmode not SImode in the compare, but that would
2499 ;; require fixing the branch patterns too.
2500 (define_insn "*cmpeqsf_t"
2501   [(set (reg:SI 18) (eq:SI (match_operand:SF 0 "arith_reg_operand" "f")
2502                            (match_operand:SF 1 "arith_reg_operand" "f")))]
2503   "TARGET_SH3E"
2504   "fcmp/eq      %1,%0"
2505   [(set_attr "type" "fp")])
2506
2507 (define_expand "cmpsf"
2508   [(set (reg:SI 18) (compare (match_operand:SF 0 "arith_operand" "")
2509                              (match_operand:SF 1 "arith_operand" "")))]
2510   "TARGET_SH3E"
2511   "
2512 {
2513   sh_compare_op0 = operands[0];
2514   sh_compare_op1 = operands[1];
2515   DONE;
2516 }")
2517
2518 (define_insn "negsf2"
2519   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
2520         (neg:SF (match_operand:SF 1 "arith_reg_operand" "0")))]
2521   "TARGET_SH3E"
2522   "fneg %0"
2523   [(set_attr "type" "fp")])
2524
2525 (define_insn "sqrtsf2"
2526   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
2527         (sqrt:DF (match_operand:SF 1 "arith_reg_operand" "0")))]
2528   "TARGET_SH3E"
2529   "fsqrt        %0"
2530   [(set_attr "type" "fdiv")])
2531
2532 (define_insn "abssf2"
2533   [(set (match_operand:SF 0 "arith_reg_operand" "=f")
2534         (abs:SF (match_operand:SF 1 "arith_reg_operand" "0")))]
2535   "TARGET_SH3E"
2536   "fabs %0"
2537   [(set_attr "type" "fp")])
2538 \f
2539 ;; -------------------------------------------------------------------------
2540 ;; Peepholes
2541 ;; -------------------------------------------------------------------------
2542
2543 ;; This matches cases where a stack pointer increment at the start of the
2544 ;; epilogue combines with a stack slot read loading the return value.
2545
2546 (define_peephole
2547   [(set (match_operand:SI 0 "arith_reg_operand" "")
2548         (mem:SI (match_operand:SI 1 "arith_reg_operand" "")))
2549    (set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))]
2550   "REGNO (operands[1]) != REGNO (operands[0])"
2551   "mov.l        @%1+,%0")
2552
2553 ;; See the comment on the dt combiner pattern above.
2554
2555 (define_peephole
2556   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
2557         (plus:SI (match_dup 0)
2558                  (const_int -1)))
2559    (set (reg:SI 18)
2560         (eq:SI (match_dup 0)
2561                (const_int 0)))]
2562   "TARGET_SH2"
2563   "dt   %0")
2564
2565 ;; These convert sequences such as `mov #k,r0; add r15,r0; mov.l @r0,rn'
2566 ;; to `mov #k,r0; mov.l @(r0,r15),rn'.  These sequences are generated by
2567 ;; reload when the constant is too large for a reg+offset address.
2568
2569 ;; ??? We would get much better code if this was done in reload.  This would
2570 ;; require modifying find_reloads_address to recognize that if the constant
2571 ;; is out-of-range for an immediate add, then we get better code by reloading
2572 ;; the constant into a register than by reloading the sum into a register,
2573 ;; since the former is one instruction shorter if the address does not need
2574 ;; to be offsettable.  Unfortunately this does not work, because there is
2575 ;; only one register, r0, that can be used as an index register.  This register
2576 ;; is also the function return value register.  So, if we try to force reload
2577 ;; to use double-reg addresses, then we end up with some instructions that
2578 ;; need to use r0 twice.  The only way to fix this is to change the calling
2579 ;; convention so that r0 is not used to return values.
2580
2581 (define_peephole
2582   [(set (match_operand:SI 0 "register_operand" "=r")
2583         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
2584    (set (mem:SI (match_dup 0))
2585         (match_operand:SI 2 "general_movsrc_operand" ""))]
2586   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
2587   "mov.l        %2,@(%0,%1)")
2588
2589 (define_peephole
2590   [(set (match_operand:SI 0 "register_operand" "=r")
2591         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
2592    (set (match_operand:SI 2 "general_movdst_operand" "")
2593         (mem:SI (match_dup 0)))]
2594   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
2595   "mov.l        @(%0,%1),%2")
2596
2597 (define_peephole
2598   [(set (match_operand:SI 0 "register_operand" "=r")
2599         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
2600    (set (mem:HI (match_dup 0))
2601         (match_operand:HI 2 "general_movsrc_operand" ""))]
2602   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
2603   "mov.w        %2,@(%0,%1)")
2604
2605 (define_peephole
2606   [(set (match_operand:SI 0 "register_operand" "=r")
2607         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
2608    (set (match_operand:HI 2 "general_movdst_operand" "")
2609         (mem:HI (match_dup 0)))]
2610   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
2611   "mov.w        @(%0,%1),%2")
2612
2613 (define_peephole
2614   [(set (match_operand:SI 0 "register_operand" "=r")
2615         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
2616    (set (mem:QI (match_dup 0))
2617         (match_operand:QI 2 "general_movsrc_operand" ""))]
2618   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
2619   "mov.b        %2,@(%0,%1)")
2620
2621 (define_peephole
2622   [(set (match_operand:SI 0 "register_operand" "=r")
2623         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
2624    (set (match_operand:QI 2 "general_movdst_operand" "")
2625         (mem:QI (match_dup 0)))]
2626   "REGNO (operands[0]) == 0 && reg_unused_after (operands[0], insn)"
2627   "mov.b        @(%0,%1),%2")
2628
2629 (define_peephole
2630   [(set (match_operand:SI 0 "register_operand" "=r")
2631         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
2632    (set (mem:SF (match_dup 0))
2633         (match_operand:SF 2 "general_movsrc_operand" ""))]
2634   "REGNO (operands[0]) == 0
2635    && ((GET_CODE (operands[2]) == REG && REGNO (operands[2]) < 16)
2636        || (GET_CODE (operands[2]) == SUBREG
2637            && REGNO (SUBREG_REG (operands[2])) < 16))
2638    && reg_unused_after (operands[0], insn)"
2639   "mov.l        %2,@(%0,%1)")
2640
2641 (define_peephole
2642   [(set (match_operand:SI 0 "register_operand" "=r")
2643         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
2644    (set (match_operand:SF 2 "general_movdst_operand" "")
2645
2646         (mem:SF (match_dup 0)))]
2647   "REGNO (operands[0]) == 0
2648    && ((GET_CODE (operands[2]) == REG && REGNO (operands[2]) < 16)
2649        || (GET_CODE (operands[2]) == SUBREG
2650            && REGNO (SUBREG_REG (operands[2])) < 16))
2651    && reg_unused_after (operands[0], insn)"
2652   "mov.l        @(%0,%1),%2")
2653
2654 (define_peephole
2655   [(set (match_operand:SI 0 "register_operand" "=r")
2656         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
2657    (set (mem:SF (match_dup 0))
2658         (match_operand:SF 2 "general_movsrc_operand" ""))]
2659   "REGNO (operands[0]) == 0
2660    && ((GET_CODE (operands[2]) == REG && REGNO (operands[2]) >= FIRST_FP_REG)
2661        || (GET_CODE (operands[2]) == SUBREG
2662            && REGNO (SUBREG_REG (operands[2])) >= FIRST_FP_REG))
2663    && reg_unused_after (operands[0], insn)"
2664   "fmov.s       %2,@(%0,%1)")
2665
2666 (define_peephole
2667   [(set (match_operand:SI 0 "register_operand" "=r")
2668         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
2669    (set (match_operand:SF 2 "general_movdst_operand" "")
2670
2671         (mem:SF (match_dup 0)))]
2672   "REGNO (operands[0]) == 0
2673    && ((GET_CODE (operands[2]) == REG && REGNO (operands[2]) >= FIRST_FP_REG)
2674        || (GET_CODE (operands[2]) == SUBREG
2675            && REGNO (SUBREG_REG (operands[2])) >= FIRST_FP_REG))
2676    && reg_unused_after (operands[0], insn)"
2677   "fmov.s       @(%0,%1),%2")