* [SH] Miscellaneous changes for LRA.
[official-gcc.git] / gcc / config / sh / sh.md
blob536a49896657bb3aee9ff931067d86506f03eadf
1 ;;- Machine description for Renesas / SuperH SH.
2 ;;  Copyright (C) 1993-2014 Free Software Foundation, Inc.
3 ;;  Contributed by Steve Chamberlain (sac@cygnus.com).
4 ;;  Improved by Jim Wilson (wilson@cygnus.com).
6 ;; This file is part of GCC.
8 ;; GCC 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 3, or (at your option)
11 ;; any later version.
13 ;; GCC 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.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3.  If not see
20 ;; <http://www.gnu.org/licenses/>.
23 ;; ??? Should prepend a * to all pattern names which are not used.
24 ;; This will make the compiler smaller, and rebuilds after changes faster.
26 ;; ??? Should be enhanced to include support for many more GNU superoptimizer
27 ;; sequences.  Especially the sequences for arithmetic right shifts.
29 ;; ??? Should check all DImode patterns for consistency and usefulness.
31 ;; ??? The MAC.W and MAC.L instructions are not supported.  There is no
32 ;; way to generate them.
34 ;; BSR is not generated by the compiler proper, but when relaxing, it
35 ;; generates .uses pseudo-ops that allow linker relaxation to create
36 ;; BSR.  This is actually implemented in bfd/{coff,elf32}-sh.c
38 ;; Special constraints for SH machine description:
40 ;;    t -- T
41 ;;    x -- mac
42 ;;    l -- pr
43 ;;    z -- r0
45 ;; Special formats used for outputting SH instructions:
47 ;;   %.  --  print a .s if insn needs delay slot
48 ;;   %@  --  print rte/rts if is/isn't an interrupt function
49 ;;   %#  --  output a nop if there is nothing to put in the delay slot
50 ;;   %O  --  print a constant without the #
51 ;;   %R  --  print the lsw reg of a double
52 ;;   %S  --  print the msw reg of a double
53 ;;   %T  --  print next word of a double REG or MEM
55 ;; Special predicates:
57 ;;  arith_operand          -- operand is valid source for arithmetic op
58 ;;  arith_reg_operand      -- operand is valid register for arithmetic op
59 ;;  general_movdst_operand -- operand is valid move destination
60 ;;  general_movsrc_operand -- operand is valid move source
61 ;;  logical_operand        -- operand is valid source for logical op
63 ;; -------------------------------------------------------------------------
64 ;; Constants
65 ;; -------------------------------------------------------------------------
67 (define_constants [
68   (AP_REG       145)
69   (PR_REG       146)
70   (T_REG        147)
71   (GBR_REG      144)
72   (MACH_REG     148)
73   (MACL_REG     149)
74   (FPUL_REG     150)
75   (RAP_REG      152)
77   (FPSCR_REG    151)
79   ;; Virtual FPSCR - bits that are used by FP ops.
80   (FPSCR_MODES_REG 154)
82   ;; Virtual FPSCR - bits that are updated by FP ops.
83   (FPSCR_STAT_REG 155)
85   (PIC_REG      12)
86   (FP_REG       14)
87   (SP_REG       15)
89   (PR_MEDIA_REG 18)
90   (T_MEDIA_REG  19)
92   (R0_REG       0)
93   (R1_REG       1)
94   (R2_REG       2)
95   (R3_REG       3)
96   (R4_REG       4)
97   (R5_REG       5)
98   (R6_REG       6)
99   (R7_REG       7)
100   (R8_REG       8)
101   (R9_REG       9)
102   (R10_REG      10)
103   (R20_REG      20)
104   (R21_REG      21)
105   (R22_REG      22)
106   (R23_REG      23)
108   (DR0_REG      64)
109   (DR2_REG      66)
110   (DR4_REG      68)
111   (FR23_REG     87)
113   (TR0_REG      128)
114   (TR1_REG      129)
115   (TR2_REG      130)
117   (XD0_REG      136)
119   (FPSCR_PR     524288)  ;; 1 << 19
120   (FPSCR_SZ     1048576) ;; 1 << 20
121   (FPSCR_FR     2097152) ;; 1 << 21
124 (define_c_enum "unspec" [
125   ;; These are used with unspec.
126   UNSPEC_COMPACT_ARGS
127   UNSPEC_MOVA
128   UNSPEC_CASESI
129   UNSPEC_DATALABEL
130   UNSPEC_BBR
131   UNSPEC_SFUNC
132   UNSPEC_PIC
133   UNSPEC_GOT
134   UNSPEC_GOTOFF
135   UNSPEC_PLT
136   UNSPEC_CALLER
137   UNSPEC_GOTPLT
138   UNSPEC_ICACHE
139   UNSPEC_INIT_TRAMP
140   UNSPEC_FCOSA
141   UNSPEC_FSRRA
142   UNSPEC_FSINA
143   UNSPEC_NSB
144   UNSPEC_ALLOCO
145   UNSPEC_TLSGD
146   UNSPEC_TLSLDM
147   UNSPEC_TLSIE
148   UNSPEC_DTPOFF
149   UNSPEC_GOTTPOFF
150   UNSPEC_TPOFF
151   UNSPEC_RA
152   UNSPEC_DIV_INV_M0
153   UNSPEC_DIV_INV_M1
154   UNSPEC_DIV_INV_M2
155   UNSPEC_DIV_INV_M3
156   UNSPEC_DIV_INV20
157   UNSPEC_DIV_INV_TABLE
158   UNSPEC_ASHIFTRT
159   UNSPEC_THUNK
160   UNSPEC_CHKADD
161   UNSPEC_SP_SET
162   UNSPEC_SP_TEST
163   UNSPEC_MOVUA
164   ;; (unspec [VAL SHIFT] UNSPEC_EXTRACT_S16) computes (short) (VAL >> SHIFT).
165   ;; UNSPEC_EXTRACT_U16 is the unsigned equivalent.
166   UNSPEC_EXTRACT_S16
167   UNSPEC_EXTRACT_U16
168   ;; (unspec [TARGET ANCHOR] UNSPEC_SYMOFF) == TARGET - ANCHOR.
169   UNSPEC_SYMOFF
170   ;; (unspec [OFFSET ANCHOR] UNSPEC_PCREL_SYMOFF) == OFFSET - (ANCHOR - .).
171   UNSPEC_PCREL_SYMOFF
172   ;; Misc builtins
173   UNSPEC_BUILTIN_STRLEN
176 (define_c_enum "unspecv" [
177   ;; These are used with unspec_volatile.
178   UNSPECV_BLOCKAGE
179   UNSPECV_ALIGN
180   UNSPECV_CONST2
181   UNSPECV_CONST4
182   UNSPECV_CONST8
183   UNSPECV_WINDOW_END
184   UNSPECV_CONST_END
185   UNSPECV_EH_RETURN
186   UNSPECV_GBR
187   UNSPECV_SP_SWITCH_B
188   UNSPECV_SP_SWITCH_E
190   UNSPECV_FPSCR_MODES
191   UNSPECV_FPSCR_STAT
194 ;; -------------------------------------------------------------------------
195 ;; Attributes
196 ;; -------------------------------------------------------------------------
198 ;; Target CPU.
200 (define_attr "cpu"
201  "sh1,sh2,sh2e,sh2a,sh3,sh3e,sh4,sh4a,sh5"
202   (const (symbol_ref "sh_cpu_attr")))
204 (define_attr "endian" "big,little"
205  (const (if_then_else (symbol_ref "TARGET_LITTLE_ENDIAN")
206                       (const_string "little") (const_string "big"))))
208 ;; Indicate if the default fpu mode is single precision.
209 (define_attr "fpu_single" "yes,no"
210   (const (if_then_else (symbol_ref "TARGET_FPU_SINGLE")
211                        (const_string "yes") (const_string "no"))))
213 (define_attr "fmovd" "yes,no"
214   (const (if_then_else (symbol_ref "TARGET_FMOVD")
215                        (const_string "yes") (const_string "no"))))
216 ;; pipeline model
217 (define_attr "pipe_model" "sh1,sh4,sh5media"
218   (const
219    (cond [(symbol_ref "TARGET_SHMEDIA") (const_string "sh5media")
220           (symbol_ref "TARGET_SUPERSCALAR") (const_string "sh4")]
221          (const_string "sh1"))))
223 ;; cbranch      conditional branch instructions
224 ;; jump         unconditional jumps
225 ;; arith        ordinary arithmetic
226 ;; arith3       a compound insn that behaves similarly to a sequence of
227 ;;              three insns of type arith
228 ;; arith3b      like above, but might end with a redirected branch
229 ;; load         from memory
230 ;; load_si      Likewise, SImode variant for general register.
231 ;; fload        Likewise, but load to fp register.
232 ;; store        to memory
233 ;; fstore       floating point register to memory
234 ;; move         general purpose register to register
235 ;; movi8        8-bit immediate to general purpose register
236 ;; mt_group     other sh4 mt instructions
237 ;; fmove        register to register, floating point
238 ;; smpy         word precision integer multiply
239 ;; dmpy         longword or doublelongword precision integer multiply
240 ;; return       rts
241 ;; pload        load of pr reg, which can't be put into delay slot of rts
242 ;; prset        copy register to pr reg, ditto
243 ;; pstore       store of pr reg, which can't be put into delay slot of jsr
244 ;; prget        copy pr to register, ditto
245 ;; pcload       pc relative load of constant value
246 ;; pcfload      Likewise, but load to fp register.
247 ;; pcload_si    Likewise, SImode variant for general register.
248 ;; rte          return from exception
249 ;; sfunc        special function call with known used registers
250 ;; call         function call
251 ;; fp           floating point
252 ;; fpscr_toggle toggle a bit in the fpscr
253 ;; fdiv         floating point divide (or square root)
254 ;; gp_fpul      move from general purpose register to fpul
255 ;; fpul_gp      move from fpul to general purpose register
256 ;; mac_gp       move from mac[lh] to general purpose register
257 ;; gp_mac       move from general purpose register to mac[lh]
258 ;; mac_mem      move from mac[lh] to memory
259 ;; mem_mac      move from memory to mac[lh]
260 ;; dfp_arith,dfp_mul, fp_cmp,dfp_cmp,dfp_conv
261 ;; ftrc_s       fix_truncsfsi2_i4
262 ;; dfdiv        double precision floating point divide (or square root)
263 ;; cwb          ic_invalidate_line_i
264 ;; movua        SH4a unaligned load
265 ;; fsrra        square root reciprocal approximate
266 ;; fsca         sine and cosine approximate
267 ;; tls_load     load TLS related address
268 ;; arith_media  SHmedia arithmetic, logical, and shift instructions
269 ;; cbranch_media SHmedia conditional branch instructions
270 ;; cmp_media    SHmedia compare instructions
271 ;; dfdiv_media  SHmedia double precision divide and square root
272 ;; dfmul_media  SHmedia double precision multiply instruction
273 ;; dfparith_media SHmedia double precision floating point arithmetic
274 ;; dfpconv_media SHmedia double precision floating point conversions
275 ;; dmpy_media   SHmedia longword multiply
276 ;; fcmp_media   SHmedia floating point compare instructions
277 ;; fdiv_media   SHmedia single precision divide and square root
278 ;; fload_media  SHmedia floating point register load instructions
279 ;; fmove_media  SHmedia floating point register moves (inc. fabs and fneg)
280 ;; fparith_media SHmedia single precision floating point arithmetic
281 ;; fpconv_media SHmedia single precision floating point conversions
282 ;; fstore_media SHmedia floating point register store instructions
283 ;; gettr_media  SHmedia gettr instruction
284 ;; invalidate_line_media SHmedia invalidate_line sequence
285 ;; jump_media   SHmedia unconditional branch instructions
286 ;; load_media   SHmedia general register load instructions
287 ;; pt_media     SHmedia pt instruction (expanded by assembler)
288 ;; ptabs_media  SHmedia ptabs instruction
289 ;; store_media  SHmedia general register store instructions
290 ;; mcmp_media   SHmedia multimedia compare, absolute, saturating ops
291 ;; mac_media    SHmedia mac-style fixed point operations
292 ;; d2mpy_media  SHmedia: two 32-bit integer multiplies
293 ;; atrans_media SHmedia approximate transcendental functions
294 ;; ustore_media SHmedia unaligned stores
295 ;; nil          no-op move, will be deleted.
297 (define_attr "type"
298  "mt_group,cbranch,jump,jump_ind,arith,arith3,arith3b,dyn_shift,load,load_si,
299   fload,store,fstore,move,movi8,fmove,smpy,dmpy,return,pload,prset,pstore,
300   prget,pcload,pcload_si,pcfload,rte,sfunc,call,fp,fpscr_toggle,fdiv,ftrc_s,
301   dfp_arith,dfp_mul,fp_cmp,dfp_cmp,dfp_conv,dfdiv,gp_fpul,fpul_gp,mac_gp,
302   gp_mac,mac_mem,mem_mac,mem_fpscr,gp_fpscr,cwb,movua,fsrra,fsca,tls_load,
303   arith_media,cbranch_media,cmp_media,dfdiv_media,dfmul_media,dfparith_media,
304   dfpconv_media,dmpy_media,fcmp_media,fdiv_media,fload_media,fmove_media,
305   fparith_media,fpconv_media,fstore_media,gettr_media,invalidate_line_media,
306   jump_media,load_media,pt_media,ptabs_media,store_media,mcmp_media,mac_media,
307   d2mpy_media,atrans_media,ustore_media,nil,other"
308   (const_string "other"))
310 ;; We define a new attribute namely "insn_class".We use
311 ;; this for the DFA based pipeline description.
313 ;; mt_group      SH4 "mt" group instructions.
315 ;; ex_group      SH4 "ex" group instructions.
317 ;; ls_group      SH4 "ls" group instructions.
319 (define_attr "insn_class"
320   "mt_group,ex_group,ls_group,br_group,fe_group,co_group,none"
321   (cond [(eq_attr "type" "move,mt_group") (const_string "mt_group")
322          (eq_attr "type" "movi8,arith,dyn_shift") (const_string "ex_group")
323          (eq_attr "type" "fmove,load,pcload,load_si,pcload_si,fload,pcfload,
324                           store,fstore,gp_fpul,fpul_gp") (const_string "ls_group")
325          (eq_attr "type" "cbranch,jump") (const_string "br_group")
326          (eq_attr "type" "fp,fp_cmp,fdiv,ftrc_s,dfp_arith,dfp_mul,dfp_conv,dfdiv")
327            (const_string "fe_group")
328          (eq_attr "type" "jump_ind,smpy,dmpy,mac_gp,return,pload,prset,pstore,
329                           prget,rte,sfunc,call,dfp_cmp,mem_fpscr,gp_fpscr,cwb,
330                           gp_mac,mac_mem,mem_mac") (const_string "co_group")]
331         (const_string "none")))
333 ;; nil are zero instructions, and arith3 / arith3b are multiple instructions,
334 ;; so these do not belong in an insn group, although they are modeled
335 ;; with their own define_insn_reservations.
337 ;; Indicate what precision must be selected in fpscr for this insn, if any.
338 (define_attr "fp_mode" "single,double,none" (const_string "none"))
340 ;; Indicate if the fpu mode is set by this instruction
341 ;; "unknown" must have the value as "none" in fp_mode, and means
342 ;; that the instruction/abi has left the processor in an unknown
343 ;; state.
344 ;; "none" means that nothing has changed and no mode is set.
345 ;; This attribute is only used for the Renesas ABI.
346 (define_attr "fp_set" "single,double,unknown,none" (const_string "none"))
348 ; If a conditional branch destination is within -252..258 bytes away
349 ; from the instruction it can be 2 bytes long.  Something in the
350 ; range -4090..4100 bytes can be 6 bytes long.  All other conditional
351 ; branches are initially assumed to be 16 bytes long.
352 ; In machine_dependent_reorg, we split all branches that are longer than
353 ; 2 bytes.
355 ;; The maximum range used for SImode constant pool entries is 1018.  A final
356 ;; instruction can add 8 bytes while only being 4 bytes in size, thus we
357 ;; can have a total of 1022 bytes in the pool.  Add 4 bytes for a branch
358 ;; instruction around the pool table, 2 bytes of alignment before the table,
359 ;; and 30 bytes of alignment after the table.  That gives a maximum total
360 ;; pool size of 1058 bytes.
361 ;; Worst case code/pool content size ratio is 1:2 (using asms).
362 ;; Thus, in the worst case, there is one instruction in front of a maximum
363 ;; sized pool, and then there are 1052 bytes of pool for every 508 bytes of
364 ;; code.  For the last n bytes of code, there are 2n + 36 bytes of pool.
365 ;; If we have a forward branch, the initial table will be put after the
366 ;; unconditional branch.
368 ;; ??? We could do much better by keeping track of the actual pcloads within
369 ;; the branch range and in the pcload range in front of the branch range.
371 ;; ??? This looks ugly because genattrtab won't allow if_then_else or cond
372 ;; inside an le.
373 (define_attr "short_cbranch_p" "no,yes"
374   (cond [(match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
375          (const_string "no")
376          (leu (plus (minus (match_dup 0) (pc)) (const_int 252)) (const_int 506))
377          (const_string "yes")
378          (match_test "NEXT_INSN (PREV_INSN (insn)) != insn")
379          (const_string "no")
380          (leu (plus (minus (match_dup 0) (pc)) (const_int 252)) (const_int 508))
381          (const_string "yes")
382          ] (const_string "no")))
384 (define_attr "med_branch_p" "no,yes"
385   (cond [(leu (plus (minus (match_dup 0) (pc)) (const_int 990))
386               (const_int 1988))
387          (const_string "yes")
388          (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
389          (const_string "no")
390          (leu (plus (minus (match_dup 0) (pc)) (const_int 4092))
391               (const_int 8186))
392          (const_string "yes")
393          ] (const_string "no")))
395 (define_attr "med_cbranch_p" "no,yes"
396   (cond [(leu (plus (minus (match_dup 0) (pc)) (const_int 988))
397               (const_int 1986))
398          (const_string "yes")
399          (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
400          (const_string "no")
401          (leu (plus (minus (match_dup 0) (pc)) (const_int 4090))
402                (const_int 8184))
403          (const_string "yes")
404          ] (const_string "no")))
406 (define_attr "braf_branch_p" "no,yes"
407   (cond [(match_test "! TARGET_SH2")
408          (const_string "no")
409          (leu (plus (minus (match_dup 0) (pc)) (const_int 10330))
410               (const_int 20660))
411          (const_string "yes")
412          (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
413          (const_string "no")
414          (leu (plus (minus (match_dup 0) (pc)) (const_int 32764))
415               (const_int 65530))
416          (const_string "yes")
417          ] (const_string "no")))
419 (define_attr "braf_cbranch_p" "no,yes"
420   (cond [(match_test "! TARGET_SH2")
421          (const_string "no")
422          (leu (plus (minus (match_dup 0) (pc)) (const_int 10328))
423               (const_int 20658))
424          (const_string "yes")
425          (match_test "mdep_reorg_phase <= SH_FIXUP_PCLOAD")
426          (const_string "no")
427          (leu (plus (minus (match_dup 0) (pc)) (const_int 32762))
428               (const_int 65528))
429          (const_string "yes")
430          ] (const_string "no")))
432 ;; An unconditional jump in the range -4092..4098 can be 2 bytes long.
433 ;; For wider ranges, we need a combination of a code and a data part.
434 ;; If we can get a scratch register for a long range jump, the code
435 ;; part can be 4 bytes long; otherwise, it must be 8 bytes long.
436 ;; If the jump is in the range -32764..32770, the data part can be 2 bytes
437 ;; long; otherwise, it must be 6 bytes long.
439 ;; All other instructions are two bytes long by default.
441 ;; ??? This should use something like *branch_p (minus (match_dup 0) (pc)),
442 ;; but getattrtab doesn't understand this.
443 (define_attr "length" ""
444   (cond [(eq_attr "type" "cbranch")
445          (cond [(eq_attr "short_cbranch_p" "yes")
446                 (const_int 2)
447                 (eq_attr "med_cbranch_p" "yes")
448                 (const_int 6)
449                 (eq_attr "braf_cbranch_p" "yes")
450                 (const_int 12)
451 ;; ??? using pc is not computed transitively.
452                 (ne (match_dup 0) (match_dup 0))
453                 (const_int 14)
454                 (match_test "flag_pic")
455                 (const_int 24)
456                 ] (const_int 16))
457          (eq_attr "type" "jump")
458          (cond [(eq_attr "med_branch_p" "yes")
459                 (const_int 2)
460                 (and (match_test "prev_nonnote_insn (insn)")
461                      (and (eq (symbol_ref "GET_CODE (prev_nonnote_insn (insn))")
462                               (symbol_ref "INSN"))
463                           (eq (symbol_ref "INSN_CODE (prev_nonnote_insn (insn))")
464                               (symbol_ref "code_for_indirect_jump_scratch"))))
465                 (cond [(eq_attr "braf_branch_p" "yes")
466                        (const_int 6)
467                        (not (match_test "flag_pic"))
468                        (const_int 10)
469                        (match_test "TARGET_SH2")
470                        (const_int 10)] (const_int 18))
471                 (eq_attr "braf_branch_p" "yes")
472                 (const_int 10)
473 ;; ??? using pc is not computed transitively.
474                 (ne (match_dup 0) (match_dup 0))
475                 (const_int 12)
476                 (match_test "flag_pic")
477                 (const_int 22)
478                 ] (const_int 14))
479          (eq_attr "type" "pt_media")
480          (if_then_else (match_test "TARGET_SHMEDIA64")
481                        (const_int 20) (const_int 12))
482          (and (eq_attr "type" "jump_media")
483               (match_test "TARGET_SH5_CUT2_WORKAROUND"))
484          (const_int 8)
485          ] (if_then_else (match_test "TARGET_SHMEDIA")
486                          (const_int 4)
487                          (const_int 2))))
489 ;; DFA descriptions for the pipelines
491 (include "sh1.md")
492 (include "shmedia.md")
493 (include "sh4.md")
495 (include "iterators.md")
496 (include "predicates.md")
497 (include "constraints.md")
499 ;; Definitions for filling delay slots
501 (define_attr "needs_delay_slot" "yes,no" (const_string "no"))
503 (define_attr "banked" "yes,no" 
504         (cond [(match_test "sh_loads_bankedreg_p (insn)")
505                (const_string "yes")]
506               (const_string "no")))
508 ;; ??? This should be (nil) instead of (const_int 0)
509 (define_attr "hit_stack" "yes,no"
510         (cond [(not (match_test "find_regno_note (insn, REG_INC, SP_REG)"))
511                (const_string "no")]
512               (const_string "yes")))
514 (define_attr "interrupt_function" "no,yes"
515   (const (symbol_ref "current_function_interrupt")))
517 (define_attr "in_delay_slot" "yes,no"
518   (cond [(eq_attr "type" "cbranch") (const_string "no")
519          (eq_attr "type" "pcload,pcload_si") (const_string "no")
520          (eq_attr "type" "fpscr_toggle") (const_string "no")
521          (eq_attr "needs_delay_slot" "yes") (const_string "no")
522          (eq_attr "length" "2") (const_string "yes")
523          ] (const_string "no")))
525 (define_attr "cond_delay_slot" "yes,no"
526   (cond [(eq_attr "in_delay_slot" "yes") (const_string "yes")
527          ] (const_string "no")))
529 (define_attr "is_sfunc" ""
530   (if_then_else (eq_attr "type" "sfunc") (const_int 1) (const_int 0)))
532 (define_attr "is_mac_media" ""
533   (if_then_else (eq_attr "type" "mac_media") (const_int 1) (const_int 0)))
535 (define_attr "branch_zero" "yes,no"
536   (cond [(eq_attr "type" "!cbranch") (const_string "no")
537          (ne (symbol_ref "(next_active_insn (insn)\
538                            == (prev_active_insn\
539                                (XEXP (SET_SRC (PATTERN (insn)), 1))))\
540                           && get_attr_length (next_active_insn (insn)) == 2")
541              (const_int 0))
542          (const_string "yes")]
543         (const_string "no")))
545 ;; SH4 Double-precision computation with double-precision result -
546 ;; the two halves are ready at different times.
547 (define_attr "dfp_comp" "yes,no"
548   (cond [(eq_attr "type" "dfp_arith,dfp_mul,dfp_conv,dfdiv") (const_string "yes")]
549         (const_string "no")))
551 ;; Insns for which the latency of a preceding fp insn is decreased by one.
552 (define_attr "late_fp_use" "yes,no" (const_string "no"))
553 ;; And feeding insns for which this relevant.
554 (define_attr "any_fp_comp" "yes,no"
555   (cond [(eq_attr "type" "fp,fdiv,ftrc_s,dfp_arith,dfp_mul,dfp_conv,dfdiv")
556          (const_string "yes")]
557         (const_string "no")))
559 (define_attr "any_int_load" "yes,no"
560   (cond [(eq_attr "type" "load,load_si,pcload,pcload_si")
561          (const_string "yes")]
562         (const_string "no")))
564 (define_attr "highpart" "user, ignore, extend, depend, must_split"
565   (const_string "user"))
567 (define_delay
568   (eq_attr "needs_delay_slot" "yes")
569   [(eq_attr "in_delay_slot" "yes") (nil) (nil)])
571 ;; Since a normal return (rts) implicitly uses the PR register,
572 ;; we can't allow PR register loads in an rts delay slot.
573 ;; On the SH1* and SH2*, the rte instruction reads the return pc from the
574 ;; stack, and thus we can't put a pop instruction in its delay slot.
575 ;; On the SH3* and SH4*, the rte instruction does not use the stack, so a
576 ;; pop instruction can go in the delay slot, unless it references a banked
577 ;; register (the register bank is switched by rte).
578 (define_delay
579   (eq_attr "type" "return")
580   [(and (eq_attr "in_delay_slot" "yes")
581         (ior (and (eq_attr "interrupt_function" "no")
582                   (eq_attr "type" "!pload,prset"))
583              (and (eq_attr "interrupt_function" "yes")
584                   (ior (match_test "TARGET_SH3") (eq_attr "hit_stack" "no"))
585                   (eq_attr "banked" "no"))))
586    (nil) (nil)])
588 ;; Since a call implicitly uses the PR register, we can't allow
589 ;; a PR register store in a jsr delay slot.
591 (define_delay
592   (ior (eq_attr "type" "call") (eq_attr "type" "sfunc"))
593   [(and (eq_attr "in_delay_slot" "yes")
594         (eq_attr "type" "!pstore,prget")) (nil) (nil)])
596 ;; Say that we have annulled true branches, since this gives smaller and
597 ;; faster code when branches are predicted as not taken.
599 ;; ??? The non-annulled condition should really be "in_delay_slot",
600 ;; but insns that can be filled in non-annulled get priority over insns
601 ;; that can only be filled in anulled.
603 (define_delay
604   (and (eq_attr "type" "cbranch")
605        (match_test "TARGET_SH2"))
606   ;; SH2e has a hardware bug that pretty much prohibits the use of
607   ;; annulled delay slots.
608   [(eq_attr "cond_delay_slot" "yes") (and (eq_attr "cond_delay_slot" "yes")
609                                           (not (eq_attr "cpu" "sh2e"))) (nil)])
611 ;; -------------------------------------------------------------------------
612 ;; SImode signed integer comparisons
613 ;; -------------------------------------------------------------------------
615 ;; Various patterns to generate the TST #imm, R0 instruction.
616 ;; Although this adds some pressure on the R0 register, it can potentially
617 ;; result in faster code, even if the operand has to be moved to R0 first.
618 ;; This is because on SH4 TST #imm, R0 and MOV Rm, Rn are both MT group 
619 ;; instructions and thus will be executed in parallel.  On SH4A TST #imm, R0
620 ;; is an EX group instruction but still can be executed in parallel with the
621 ;; MT group MOV Rm, Rn instruction.
623 ;; Usual TST #imm, R0 patterns for SI, HI and QI
624 ;; This is usually used for bit patterns other than contiguous bits 
625 ;; and single bits.
626 (define_insn "tstsi_t"
627   [(set (reg:SI T_REG)
628         (eq:SI (and:SI (match_operand:SI 0 "logical_operand" "%z,r")
629                        (match_operand:SI 1 "logical_operand" "K08,r"))
630                (const_int 0)))]
631   "TARGET_SH1"
632   "tst  %1,%0"
633   [(set_attr "type" "mt_group")])
635 (define_insn "tsthi_t"
636   [(set (reg:SI T_REG)
637         (eq:SI (subreg:SI (and:HI (match_operand:HI 0 "logical_operand" "%z")
638                                   (match_operand 1 "const_int_operand")) 0)
639                (const_int 0)))]
640   "TARGET_SH1
641    && CONST_OK_FOR_K08 (INTVAL (operands[1]))"
642   "tst  %1,%0"
643   [(set_attr "type" "mt_group")])
645 (define_insn "tstqi_t"
646   [(set (reg:SI T_REG)
647         (eq:SI (subreg:SI (and:QI (match_operand:QI 0 "logical_operand" "%z")
648                                   (match_operand 1 "const_int_operand")) 0)
649                (const_int 0)))]
650   "TARGET_SH1
651    && (CONST_OK_FOR_K08 (INTVAL (operands[1])) 
652        || CONST_OK_FOR_I08 (INTVAL (operands[1])))"
654   operands[1] = GEN_INT (INTVAL (operands[1]) & 255);
655   return "tst   %1,%0";
657   [(set_attr "type" "mt_group")])
659 ;; Test low QI subreg against zero.
660 ;; This avoids unnecessary zero extension before the test.
661 (define_insn "*tstqi_t_zero"
662   [(set (reg:SI T_REG)
663         (eq:SI (match_operand:QI 0 "logical_operand" "z") (const_int 0)))]
664   "TARGET_SH1"
665   "tst  #255,%0"
666   [(set_attr "type" "mt_group")])
668 ;; This pattern might be risky because it also tests the upper bits and not
669 ;; only the subreg.  However, it seems that combine will get to this only
670 ;; when testing sign/zero extended values.  In this case the extended upper
671 ;; bits do not matter.
672 (define_insn "*tst<mode>_t_zero"
673   [(set (reg:SI T_REG)
674         (eq:SI
675           (subreg:QIHI
676             (and:SI (match_operand:SI 0 "arith_reg_operand" "%r")
677                     (match_operand:SI 1 "arith_reg_operand" "r")) <lowpart_le>)
678           (const_int 0)))]
679   "TARGET_SH1 && TARGET_LITTLE_ENDIAN"
680   "tst  %0,%1"
681   [(set_attr "type" "mt_group")])
683 (define_insn "*tst<mode>_t_zero"
684   [(set (reg:SI T_REG)
685         (eq:SI
686           (subreg:QIHI
687             (and:SI (match_operand:SI 0 "arith_reg_operand" "%r")
688                     (match_operand:SI 1 "arith_reg_operand" "r")) <lowpart_be>)
689           (const_int 0)))]
690   "TARGET_SH1 && TARGET_BIG_ENDIAN"
691   "tst  %0,%1"
692   [(set_attr "type" "mt_group")])
694 ;; Extract LSB, negate and store in T bit.
695 (define_insn "tstsi_t_and_not"
696   [(set (reg:SI T_REG)
697          (and:SI (not:SI (match_operand:SI 0 "logical_operand" "z"))
698                  (const_int 1)))]
699   "TARGET_SH1"
700   "tst  #1,%0"
701   [(set_attr "type" "mt_group")])
703 ;; Extract contiguous bits and compare them against zero.
704 (define_insn "tst<mode>_t_zero_extract_eq"
705   [(set (reg:SI T_REG)
706         (eq:SI (zero_extract:SI (match_operand:QIHISIDI 0 "logical_operand" "z")
707                                 (match_operand:SI 1 "const_int_operand")
708                                 (match_operand:SI 2 "const_int_operand"))
709                (const_int 0)))]
710   "TARGET_SH1
711    && CONST_OK_FOR_K08 (ZERO_EXTRACT_ANDMASK (operands[1], operands[2]))"
713   operands[1] = GEN_INT (ZERO_EXTRACT_ANDMASK (operands[1], operands[2]));
714   return "tst   %1,%0";
716   [(set_attr "type" "mt_group")])
718 ;; This split is required when testing bits in a QI subreg.
719 (define_split
720   [(set (reg:SI T_REG)
721         (eq:SI
722           (if_then_else:SI
723             (zero_extract:SI (match_operand 0 "logical_operand")
724                              (match_operand 1 "const_int_operand")
725                              (match_operand 2 "const_int_operand"))
726             (match_operand 3 "const_int_operand")
727             (const_int 0))
728           (const_int 0)))]
729   "TARGET_SH1
730    && ZERO_EXTRACT_ANDMASK (operands[1], operands[2]) == INTVAL (operands[3])
731    && CONST_OK_FOR_K08 (INTVAL (operands[3]))"
732   [(set (reg:SI T_REG) (eq:SI (and:SI (match_dup 0) (match_dup 3))
733                               (const_int 0)))]
735   if (GET_MODE (operands[0]) == QImode)
736     operands[0] = simplify_gen_subreg (SImode, operands[0], QImode, 0);
739 ;; Extract single bit, negate and store it in the T bit.
740 ;; Not used for SH4A.
741 (define_insn "tstsi_t_zero_extract_xor"
742   [(set (reg:SI T_REG)
743         (zero_extract:SI (xor:SI (match_operand:SI 0 "logical_operand" "z")
744                                  (match_operand:SI 3 "const_int_operand"))
745                          (match_operand:SI 1 "const_int_operand")
746                          (match_operand:SI 2 "const_int_operand")))]
747   "TARGET_SH1
748    && ZERO_EXTRACT_ANDMASK (operands[1], operands[2]) == INTVAL (operands[3])
749    && CONST_OK_FOR_K08 (INTVAL (operands[3]))"
750   "tst  %3,%0"
751   [(set_attr "type" "mt_group")])
753 ;; Extract single bit, negate and store it in the T bit.
754 ;; Used for SH4A little endian.
755 (define_insn "tstsi_t_zero_extract_subreg_xor_little"
756   [(set (reg:SI T_REG)
757         (zero_extract:SI
758          (subreg:QI (xor:SI (match_operand:SI 0 "logical_operand" "z")
759                             (match_operand:SI 3 "const_int_operand")) 0)
760          (match_operand:SI 1 "const_int_operand")
761          (match_operand:SI 2 "const_int_operand")))]
762   "TARGET_SH1 && TARGET_LITTLE_ENDIAN
763    && ZERO_EXTRACT_ANDMASK (operands[1], operands[2])
764       == (INTVAL (operands[3]) & 255)
765    && CONST_OK_FOR_K08 (INTVAL (operands[3]) & 255)"
767   operands[3] = GEN_INT (INTVAL (operands[3]) & 255);
768   return "tst   %3,%0";
770   [(set_attr "type" "mt_group")])
772 ;; Extract single bit, negate and store it in the T bit.
773 ;; Used for SH4A big endian.
774 (define_insn "tstsi_t_zero_extract_subreg_xor_big"
775   [(set (reg:SI T_REG)
776         (zero_extract:SI
777          (subreg:QI (xor:SI (match_operand:SI 0 "logical_operand" "z")
778                             (match_operand:SI 3 "const_int_operand")) 3)
779          (match_operand:SI 1 "const_int_operand")
780          (match_operand:SI 2 "const_int_operand")))]
781   "TARGET_SH1 && TARGET_BIG_ENDIAN
782    && ZERO_EXTRACT_ANDMASK (operands[1], operands[2])
783       == (INTVAL (operands[3]) & 255)
784    && CONST_OK_FOR_K08 (INTVAL (operands[3]) & 255)"
786   operands[3] = GEN_INT (INTVAL (operands[3]) & 255);
787   return "tst   %3,%0";
789   [(set_attr "type" "mt_group")])
791 (define_insn "cmpeqsi_t"
792   [(set (reg:SI T_REG)
793         (eq:SI (match_operand:SI 0 "arith_reg_operand" "r,z,r")
794                (match_operand:SI 1 "arith_operand" "N,rI08,r")))]
795   "TARGET_SH1"
796   "@
797         tst     %0,%0
798         cmp/eq  %1,%0
799         cmp/eq  %1,%0"
800   [(set_attr "type" "mt_group")])
802 ;; FIXME: For some reason, on SH4A and SH2A combine fails to simplify this
803 ;; pattern by itself.  What this actually does is:
804 ;;      x == 0: (1 >> 0-0) & 1 = 1
805 ;;      x != 0: (1 >> 0-x) & 1 = 0
806 ;; Without this the test pr51244-8.c fails on SH2A and SH4A.
807 (define_insn_and_split "*cmpeqsi_t"
808   [(set (reg:SI T_REG)
809         (and:SI (lshiftrt:SI
810                   (const_int 1)
811                   (neg:SI (match_operand:SI 0 "arith_reg_operand" "r")))
812                 (const_int 1)))]
813   "TARGET_SH1"
814   "#"
815   "&& 1"
816   [(set (reg:SI T_REG) (eq:SI (match_dup 0) (const_int 0)))])
818 (define_insn "cmpgtsi_t"
819   [(set (reg:SI T_REG)
820         (gt:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
821                (match_operand:SI 1 "arith_reg_or_0_operand" "N,r")))]
822   "TARGET_SH1"
823   "@
824         cmp/pl  %0
825         cmp/gt  %1,%0"
826   [(set_attr "type" "mt_group")])
828 (define_insn "cmpgesi_t"
829   [(set (reg:SI T_REG)
830         (ge:SI (match_operand:SI 0 "arith_reg_operand" "r,r")
831                (match_operand:SI 1 "arith_reg_or_0_operand" "N,r")))]
832   "TARGET_SH1"
833   "@
834         cmp/pz  %0
835         cmp/ge  %1,%0"
836   [(set_attr "type" "mt_group")])
838 ;; FIXME: This is actually wrong.  There is no way to literally move a
839 ;; general reg to t reg.  Luckily, it seems that this pattern will be only
840 ;; used when the general reg is known be either '0' or '1' during combine.
841 ;; What we actually need is reg != 0 -> T, but we have only reg == 0 -> T.
842 ;; Due to interactions with other patterns, combine fails to pick the latter
843 ;; and invert the dependent logic.
844 (define_insn "*negtstsi"
845   [(set (reg:SI T_REG) (match_operand:SI 0 "arith_reg_operand" "r"))]
846   "TARGET_SH1"
847   "cmp/pl       %0"
848   [(set_attr "type" "mt_group")])
850 ;; Some integer sign comparison patterns can be realized with the div0s insn.
851 ;;      div0s   Rm,Rn           T = (Rm >> 31) ^ (Rn >> 31)
852 (define_insn "cmp_div0s_0"
853   [(set (reg:SI T_REG)
854         (lshiftrt:SI (xor:SI (match_operand:SI 0 "arith_reg_operand" "%r")
855                              (match_operand:SI 1 "arith_reg_operand" "r"))
856                      (const_int 31)))]
857   "TARGET_SH1"
858   "div0s        %0,%1"
859   [(set_attr "type" "arith")])
861 (define_insn "cmp_div0s_1"
862   [(set (reg:SI T_REG)
863         (lt:SI (xor:SI (match_operand:SI 0 "arith_reg_operand" "%r")
864                        (match_operand:SI 1 "arith_reg_operand" "r"))
865                (const_int 0)))]
866   "TARGET_SH1"
867   "div0s        %0,%1"
868   [(set_attr "type" "arith")])
870 (define_insn_and_split "*cmp_div0s_0"
871   [(set (match_operand:SI 0 "arith_reg_dest" "")
872         (lshiftrt:SI (xor:SI (match_operand:SI 1 "arith_reg_operand" "")
873                              (match_operand:SI 2 "arith_reg_operand" ""))
874                      (const_int 31)))
875    (clobber (reg:SI T_REG))]
876   "TARGET_SH1"
877   "#"
878   "&& 1"
879   [(set (reg:SI T_REG)
880         (lshiftrt:SI (xor:SI (match_dup 1) (match_dup 2)) (const_int 31)))
881    (set (match_dup 0) (reg:SI T_REG))])
883 (define_insn "*cmp_div0s_0"
884   [(set (reg:SI T_REG)
885         (eq:SI (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand" "%r")
886                             (const_int 31))
887                (ge:SI (match_operand:SI 1 "arith_reg_operand" "r")
888                       (const_int 0))))]
889   "TARGET_SH1"
890   "div0s        %0,%1"
891   [(set_attr "type" "arith")])
893 (define_insn_and_split "*cmp_div0s_1"
894   [(set (match_operand:SI 0 "arith_reg_dest" "")
895         (ge:SI (xor:SI (match_operand:SI 1 "arith_reg_operand" "")
896                        (match_operand:SI 2 "arith_reg_operand" ""))
897                (const_int 0)))
898    (clobber (reg:SI T_REG))]
899   "TARGET_SH1"
900   "#"
901   "&& can_create_pseudo_p ()"
902   [(const_int 0)]
903 ;; We have to go through the movnegt expander here which will handle the
904 ;; SH2A vs non-SH2A cases.
906   emit_insn (gen_cmp_div0s_1 (operands[1], operands[2]));
907   emit_insn (gen_movnegt (operands[0], get_t_reg_rtx ()));
908   DONE;
911 (define_insn_and_split "*cmp_div0s_1"
912   [(set (reg:SI T_REG)
913         (ge:SI (xor:SI (match_operand:SI 0 "arith_reg_operand" "")
914                        (match_operand:SI 1 "arith_reg_operand" ""))
915                (const_int 0)))]
916   "TARGET_SH1"
917   "#"
918   "&& can_create_pseudo_p ()"
919   [(set (reg:SI T_REG) (lt:SI (xor:SI (match_dup 0) (match_dup 1))
920                               (const_int 0)))
921    (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
923 (define_insn_and_split "*cmp_div0s_1"
924   [(set (reg:SI T_REG)
925         (eq:SI (lshiftrt:SI (match_operand:SI 0 "arith_reg_operand")
926                             (const_int 31))
927                (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
928                             (const_int 31))))]
929   "TARGET_SH1"
930   "#"
931   "&& can_create_pseudo_p ()"
932   [(set (reg:SI T_REG) (lt:SI (xor:SI (match_dup 0) (match_dup 1))
933                               (const_int 0)))
934    (set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))])
936 ;; -------------------------------------------------------------------------
937 ;; SImode compare and branch
938 ;; -------------------------------------------------------------------------
940 (define_expand "cbranchsi4"
941   [(set (pc)
942         (if_then_else (match_operator 0 "comparison_operator"
943                         [(match_operand:SI 1 "arith_operand" "")
944                          (match_operand:SI 2 "arith_operand" "")])
945                       (label_ref (match_operand 3 "" ""))
946                       (pc)))
947    (clobber (reg:SI T_REG))]
948   ""
950   if (TARGET_SHMEDIA)
951     emit_jump_insn (gen_cbranchint4_media (operands[0], operands[1],
952                                            operands[2], operands[3]));
953   else
954     expand_cbranchsi4 (operands, LAST_AND_UNUSED_RTX_CODE, -1);
956   DONE;
959 ;; Combine patterns to invert compare and branch operations for which we
960 ;; don't have actual comparison insns.  These patterns are used in cases
961 ;; which appear after the initial cbranchsi expansion, which also does
962 ;; some condition inversion.
963 (define_split
964   [(set (pc)
965         (if_then_else (ne (match_operand:SI 0 "arith_reg_operand" "")
966                           (match_operand:SI 1 "arith_reg_or_0_operand" ""))
967                       (label_ref (match_operand 2))
968                       (pc)))
969    (clobber (reg:SI T_REG))]
970   "TARGET_SH1"
971   [(set (reg:SI T_REG) (eq:SI (match_dup 0) (match_dup 1)))
972    (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
973                            (label_ref (match_dup 2))
974                            (pc)))])
976 ;; FIXME: Similar to the *cmpeqsi_t pattern above, for some reason, on SH4A
977 ;; and SH2A combine fails to simplify this pattern by itself.
978 ;; What this actually does is:
979 ;;      x == 0: (1 >> 0-0) & 1 = 1
980 ;;      x != 0: (1 >> 0-x) & 1 = 0
981 ;; Without this the test pr51244-8.c fails on SH2A and SH4A.
982 (define_split
983   [(set (pc)
984         (if_then_else
985           (eq (and:SI (lshiftrt:SI
986                         (const_int 1)
987                         (neg:SI (match_operand:SI 0 "arith_reg_operand" "")))
988                       (const_int 1))
989               (const_int 0))
990           (label_ref (match_operand 2))
991           (pc)))
992    (clobber (reg:SI T_REG))]
993   "TARGET_SH1"
994   [(set (reg:SI T_REG) (eq:SI (match_dup 0) (const_int 0)))
995    (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
996                            (label_ref (match_dup 2))
997                            (pc)))])
999 ;; FIXME: These could probably use code iterators for the compare op.
1000 (define_split
1001   [(set (pc)
1002         (if_then_else (le (match_operand:SI 0 "arith_reg_operand" "")
1003                           (match_operand:SI 1 "arith_reg_or_0_operand" ""))
1004                       (label_ref (match_operand 2))
1005                       (pc)))
1006    (clobber (reg:SI T_REG))]
1007   "TARGET_SH1"
1008   [(set (reg:SI T_REG) (gt:SI (match_dup 0) (match_dup 1)))
1009    (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1010                            (label_ref (match_dup 2))
1011                            (pc)))])
1013 (define_split
1014   [(set (pc)
1015         (if_then_else (lt (match_operand:SI 0 "arith_reg_operand" "")
1016                           (match_operand:SI 1 "arith_reg_or_0_operand" ""))
1017                       (label_ref (match_operand 2))
1018                       (pc)))
1019    (clobber (reg:SI T_REG))]
1020   "TARGET_SH1"
1021   [(set (reg:SI T_REG) (ge:SI (match_dup 0) (match_dup 1)))
1022    (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1023                            (label_ref (match_dup 2))
1024                            (pc)))])
1026 (define_split
1027   [(set (pc)
1028         (if_then_else (leu (match_operand:SI 0 "arith_reg_operand" "")
1029                            (match_operand:SI 1 "arith_reg_operand" ""))
1030                       (label_ref (match_operand 2))
1031                       (pc)))
1032    (clobber (reg:SI T_REG))]
1033   "TARGET_SH1"
1034   [(set (reg:SI T_REG) (gtu:SI (match_dup 0) (match_dup 1)))
1035    (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1036                            (label_ref (match_dup 2))
1037                            (pc)))])
1039 (define_split
1040   [(set (pc)
1041         (if_then_else (ltu (match_operand:SI 0 "arith_reg_operand" "")
1042                            (match_operand:SI 1 "arith_reg_operand" ""))
1043                       (label_ref (match_operand 2))
1044                       (pc)))
1045    (clobber (reg:SI T_REG))]
1046   "TARGET_SH1"
1047   [(set (reg:SI T_REG) (geu:SI (match_dup 0) (match_dup 1)))
1048    (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1049                            (label_ref (match_dup 2))
1050                            (pc)))])
1052 ;; Compare and branch combine patterns for div0s comparisons.
1053 (define_insn_and_split "*cbranch_div0s"
1054   [(set (pc)
1055         (if_then_else (lt (xor:SI (match_operand:SI 0 "arith_reg_operand" "")
1056                                   (match_operand:SI 1 "arith_reg_operand" ""))
1057                           (const_int 0))
1058                       (label_ref (match_operand 2))
1059                       (pc)))
1060    (clobber (reg:SI T_REG))]
1061   "TARGET_SH1"
1062   "#"
1063   "&& 1"
1064   [(set (reg:SI T_REG)
1065         (lt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 0)))
1066    (set (pc)
1067         (if_then_else (ne (reg:SI T_REG) (const_int 0))
1068                       (label_ref (match_dup 2))
1069                       (pc)))])
1071 (define_insn_and_split "*cbranch_div0s"
1072   [(set (pc)
1073         (if_then_else (ge (xor:SI (match_operand:SI 0 "arith_reg_operand" "")
1074                                   (match_operand:SI 1 "arith_reg_operand" ""))
1075                           (const_int 0))
1076                       (label_ref (match_operand 2))
1077                       (pc)))
1078    (clobber (reg:SI T_REG))]
1079   "TARGET_SH1"
1080   "#"
1081   "&& 1"
1082   [(set (reg:SI T_REG)
1083         (lt:SI (xor:SI (match_dup 0) (match_dup 1)) (const_int 0)))
1084    (set (pc)
1085         (if_then_else (eq (reg:SI T_REG) (const_int 0))
1086                       (label_ref (match_dup 2))
1087                       (pc)))])
1089 ;; -------------------------------------------------------------------------
1090 ;; SImode unsigned integer comparisons
1091 ;; -------------------------------------------------------------------------
1093 ;; Usually comparisons of 'unsigned int >= 0' are optimized away completely.
1094 ;; However, especially when optimizations are off (e.g. -O0) such comparisons
1095 ;; might remain and we have to handle them.  If the '>= 0' case wasn't
1096 ;; handled here, something else would just load a '0' into the second operand
1097 ;; and do the comparison.  We can do slightly better by just setting the
1098 ;; T bit to '1'.
1099 (define_insn_and_split "cmpgeusi_t"
1100   [(set (reg:SI T_REG)
1101         (geu:SI (match_operand:SI 0 "arith_reg_operand" "r")
1102                 (match_operand:SI 1 "arith_reg_or_0_operand" "r")))]
1103   "TARGET_SH1"
1104   "cmp/hs       %1,%0"
1105   "&& satisfies_constraint_Z (operands[1])"
1106   [(set (reg:SI T_REG) (const_int 1))]
1107   ""
1108   [(set_attr "type" "mt_group")])
1110 (define_insn "cmpgtusi_t"
1111   [(set (reg:SI T_REG)
1112         (gtu:SI (match_operand:SI 0 "arith_reg_operand" "r")
1113                 (match_operand:SI 1 "arith_reg_operand" "r")))]
1114   "TARGET_SH1"
1115   "cmp/hi       %1,%0"
1116   [(set_attr "type" "mt_group")])
1118 ;; -------------------------------------------------------------------------
1119 ;; DImode compare and branch
1120 ;; -------------------------------------------------------------------------
1122 ;; arith3 patterns don't work well with the sh4-300 branch prediction mechanism.
1123 ;; Therefore, we aim to have a set of three branches that go straight to the
1124 ;; destination, i.e. only one of them is taken at any one time.
1125 ;; This mechanism should also be slightly better for the sh4-200.
1127 (define_expand "cbranchdi4"
1128   [(set (pc)
1129         (if_then_else (match_operator 0 "comparison_operator"
1130                         [(match_operand:DI 1 "arith_operand" "")
1131                          (match_operand:DI 2 "arith_operand" "")])
1132                       (label_ref (match_operand 3 "" ""))
1133                       (pc)))
1134    (clobber (match_dup 4))
1135    (clobber (reg:SI T_REG))]
1136   "TARGET_CBRANCHDI4 || TARGET_SH2 || TARGET_SHMEDIA"
1138   enum rtx_code comparison;
1140   if (TARGET_SHMEDIA)
1141     {
1142       emit_jump_insn (gen_cbranchint4_media (operands[0], operands[1],
1143                                              operands[2], operands[3]));
1144       DONE;
1145     }
1146   else if (!TARGET_CBRANCHDI4)
1147     {
1148       sh_emit_compare_and_branch (operands, DImode);
1149       DONE;
1150     }
1151   else
1152     {
1153       if (expand_cbranchdi4 (operands, LAST_AND_UNUSED_RTX_CODE))
1154         DONE;
1156       comparison = prepare_cbranch_operands (operands, DImode,
1157                                              LAST_AND_UNUSED_RTX_CODE);
1158       if (comparison != GET_CODE (operands[0]))
1159         operands[0]
1160           = gen_rtx_fmt_ee (comparison, VOIDmode, operands[1], operands[2]);
1161        operands[4] = gen_rtx_SCRATCH (SImode);
1162     }
1165 (define_insn_and_split "cbranchdi4_i"
1166   [(set (pc)
1167         (if_then_else (match_operator 0 "comparison_operator"
1168                         [(match_operand:DI 1 "arith_operand" "r,r")
1169                          (match_operand:DI 2 "arith_operand" "rN,I08")])
1170                       (label_ref (match_operand 3 "" ""))
1171                       (pc)))
1172    (clobber (match_scratch:SI 4 "=X,&r"))
1173    (clobber (reg:SI T_REG))]
1174   "TARGET_CBRANCHDI4"
1175   "#"
1176   "&& reload_completed"
1177   [(pc)]
1179   if (!expand_cbranchdi4 (operands, GET_CODE (operands[0])))
1180     FAIL;
1181   DONE;
1184 ;; -------------------------------------------------------------------------
1185 ;; DImode signed integer comparisons
1186 ;; -------------------------------------------------------------------------
1188 (define_insn ""
1189   [(set (reg:SI T_REG)
1190         (eq:SI (and:DI (match_operand:DI 0 "arith_reg_operand" "r")
1191                        (match_operand:DI 1 "arith_operand" "r"))
1192                (const_int 0)))]
1193   "TARGET_SH1"
1195   return output_branchy_insn (EQ, "tst\t%S1,%S0;bf\t%l9;tst\t%R1,%R0",
1196                               insn, operands);
1198   [(set_attr "length" "6")
1199    (set_attr "type" "arith3b")])
1201 (define_insn "cmpeqdi_t"
1202   [(set (reg:SI T_REG)
1203         (eq:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
1204                (match_operand:DI 1 "arith_reg_or_0_operand" "N,r")))]
1205   "TARGET_SH1"
1207   static const char* alt[] =
1208   {
1209        "tst     %S0,%S0"        "\n"
1210     "   bf      0f"             "\n"
1211     "   tst     %R0,%R0"        "\n"
1212     "0:",
1214        "cmp/eq  %S1,%S0"        "\n"
1215     "   bf      0f"             "\n"
1216     "   cmp/eq  %R1,%R0"        "\n"
1217     "0:"
1218   };
1219   return alt[which_alternative];
1221   [(set_attr "length" "6")
1222    (set_attr "type" "arith3b")])
1224 (define_split
1225   [(set (reg:SI T_REG)
1226         (eq:SI (match_operand:DI 0 "arith_reg_operand" "")
1227                (match_operand:DI 1 "arith_reg_or_0_operand" "")))]
1228 ;; If we applied this split when not optimizing, it would only be
1229 ;; applied during the machine-dependent reorg, when no new basic blocks
1230 ;; may be created.
1231   "TARGET_SH1 && reload_completed && optimize"
1232   [(set (reg:SI T_REG) (eq:SI (match_dup 2) (match_dup 3)))
1233    (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
1234                            (label_ref (match_dup 6))
1235                            (pc)))
1236    (set (reg:SI T_REG) (eq:SI (match_dup 4) (match_dup 5)))
1237    (match_dup 6)]
1239   operands[2] = gen_highpart (SImode, operands[0]);
1240   operands[3] = operands[1] == const0_rtx
1241                 ? const0_rtx
1242                 : gen_highpart (SImode, operands[1]);
1243   operands[4] = gen_lowpart (SImode, operands[0]);
1244   operands[5] = gen_lowpart (SImode, operands[1]);
1245   operands[6] = gen_label_rtx ();
1248 (define_insn "cmpgtdi_t"
1249   [(set (reg:SI T_REG)
1250         (gt:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
1251                (match_operand:DI 1 "arith_reg_or_0_operand" "r,N")))]
1252   "TARGET_SH2"
1254   static const char* alt[] =
1255   {
1256        "cmp/eq  %S1,%S0"        "\n"
1257     "   bf{.|/}s        0f"     "\n"
1258     "   cmp/gt  %S1,%S0"        "\n"
1259     "   cmp/hi  %R1,%R0"        "\n"
1260     "0:",
1262         "tst    %S0,%S0"        "\n"
1263     "   bf{.|/}s        0f"     "\n"
1264     "   cmp/pl  %S0"            "\n"
1265     "   cmp/hi  %S0,%R0"        "\n"
1266     "0:"
1267   };
1268   return alt[which_alternative];
1270   [(set_attr "length" "8")
1271    (set_attr "type" "arith3")])
1273 (define_insn "cmpgedi_t"
1274   [(set (reg:SI T_REG)
1275         (ge:SI (match_operand:DI 0 "arith_reg_operand" "r,r")
1276                (match_operand:DI 1 "arith_reg_or_0_operand" "r,N")))]
1277   "TARGET_SH2"
1279   static const char* alt[] =
1280   {
1281        "cmp/eq  %S1,%S0"        "\n"
1282     "   bf{.|/}s        0f"     "\n"
1283     "   cmp/ge  %S1,%S0"        "\n"
1284     "   cmp/hs  %R1,%R0"        "\n"
1285     "0:",
1287        "cmp/pz  %S0"
1288   };
1289   return alt[which_alternative];
1291   [(set_attr "length" "8,2")
1292    (set_attr "type" "arith3,mt_group")])
1294 ;; -------------------------------------------------------------------------
1295 ;; DImode unsigned integer comparisons
1296 ;; -------------------------------------------------------------------------
1298 (define_insn "cmpgeudi_t"
1299   [(set (reg:SI T_REG)
1300         (geu:SI (match_operand:DI 0 "arith_reg_operand" "r")
1301                 (match_operand:DI 1 "arith_reg_operand" "r")))]
1302   "TARGET_SH2"
1304   return       "cmp/eq  %S1,%S0"        "\n"
1305          "      bf{.|/}s        0f"     "\n"
1306          "      cmp/hs  %S1,%S0"        "\n"
1307          "      cmp/hs  %R1,%R0"        "\n"
1308          "0:";
1310   [(set_attr "length" "8")
1311    (set_attr "type" "arith3")])
1313 (define_insn "cmpgtudi_t"
1314   [(set (reg:SI T_REG)
1315         (gtu:SI (match_operand:DI 0 "arith_reg_operand" "r")
1316                 (match_operand:DI 1 "arith_reg_operand" "r")))]
1317   "TARGET_SH2"
1319   return       "cmp/eq  %S1,%S0"        "\n"
1320          "      bf{.|/}s        0f"     "\n"
1321          "      cmp/hi  %S1,%S0"        "\n"
1322          "      cmp/hi  %R1,%R0"        "\n"
1323          "0:";
1325   [(set_attr "length" "8")
1326    (set_attr "type" "arith3")])
1328 (define_insn "cmpeqsi_media"
1329   [(set (match_operand:SI 0 "register_operand" "=r")
1330         (eq:SI (match_operand:SI 1 "logical_operand" "%r")
1331                (match_operand:SI 2 "cmp_operand" "Nr")))]
1332   "TARGET_SHMEDIA"
1333   "cmpeq        %1, %N2, %0"
1334   [(set_attr "type" "cmp_media")])
1336 (define_insn "cmpeqdi_media"
1337   [(set (match_operand:SI 0 "register_operand" "=r")
1338         (eq:SI (match_operand:DI 1 "register_operand" "%r")
1339                (match_operand:DI 2 "cmp_operand" "Nr")))]
1340   "TARGET_SHMEDIA"
1341   "cmpeq        %1, %N2, %0"
1342   [(set_attr "type" "cmp_media")])
1344 (define_insn "cmpgtsi_media"
1345   [(set (match_operand:SI 0 "register_operand" "=r")
1346         (gt:SI (match_operand:SI 1 "cmp_operand" "Nr")
1347                (match_operand:SI 2 "cmp_operand" "rN")))]
1348   "TARGET_SHMEDIA"
1349   "cmpgt        %N1, %N2, %0"
1350   [(set_attr "type" "cmp_media")])
1352 (define_insn "cmpgtdi_media"
1353   [(set (match_operand:SI 0 "register_operand" "=r")
1354         (gt:SI (match_operand:DI 1 "arith_reg_or_0_operand" "Nr")
1355                (match_operand:DI 2 "arith_reg_or_0_operand" "rN")))]
1356   "TARGET_SHMEDIA"
1357   "cmpgt        %N1, %N2, %0"
1358   [(set_attr "type" "cmp_media")])
1360 (define_insn "cmpgtusi_media"
1361   [(set (match_operand:SI 0 "register_operand" "=r")
1362         (gtu:SI (match_operand:SI 1 "cmp_operand" "Nr")
1363                 (match_operand:SI 2 "cmp_operand" "rN")))]
1364   "TARGET_SHMEDIA"
1365   "cmpgtu       %N1, %N2, %0"
1366   [(set_attr "type" "cmp_media")])
1368 (define_insn "cmpgtudi_media"
1369   [(set (match_operand:SI 0 "register_operand" "=r")
1370         (gtu:SI (match_operand:DI 1 "arith_reg_or_0_operand" "Nr")
1371                 (match_operand:DI 2 "arith_reg_or_0_operand" "rN")))]
1372   "TARGET_SHMEDIA"
1373   "cmpgtu       %N1, %N2, %0"
1374   [(set_attr "type" "cmp_media")])
1376 ; This pattern is for combine.
1377 (define_insn "*cmpne0sisi_media"
1378   [(set (match_operand:SI 0 "register_operand" "=r")
1379         (ne:SI (match_operand:SI 1 "arith_reg_operand" "r") (const_int 0)))]
1380   "TARGET_SHMEDIA"
1381   "cmpgtu       %1,r63,%0"
1382   [(set_attr "type" "cmp_media")])
1384 ;; -------------------------------------------------------------------------
1385 ;; Conditional move instructions
1386 ;; -------------------------------------------------------------------------
1388 ;; The insn names may seem reversed, but note that cmveq performs the move
1389 ;; if op1 == 0, and cmvne does it if op1 != 0.
1391 (define_insn "movdicc_false"
1392   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
1393         (if_then_else:DI (eq (match_operand:DI 1 "arith_reg_operand" "r")
1394                              (const_int 0))
1395          (match_operand:DI 2 "arith_reg_or_0_operand" "rN")
1396          (match_operand:DI 3 "arith_reg_operand" "0")))]
1397   "TARGET_SHMEDIA"
1398   "cmveq        %1, %N2, %0"
1399   [(set_attr "type" "arith_media")])
1401 (define_insn "movdicc_true"
1402   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
1403         (if_then_else:DI (ne (match_operand:DI 1 "arith_reg_operand" "r")
1404                              (const_int 0))
1405          (match_operand:DI 2 "arith_reg_or_0_operand" "rN")
1406          (match_operand:DI 3 "arith_reg_operand" "0")))]
1407   "TARGET_SHMEDIA"
1408   "cmvne        %1, %N2, %0"
1409   [(set_attr "type" "arith_media")])
1411 (define_peephole2
1412   [(set (match_operand:DI 0 "arith_reg_dest" "")
1413         (if_then_else:DI (match_operator 3 "equality_comparison_operator"
1414                            [(match_operand:DI 1 "arith_reg_operand" "")
1415                             (const_int 0)])
1416          (match_operand:DI 2 "arith_reg_dest" "")
1417          (match_dup 0)))
1418    (set (match_dup 2) (match_dup 0))]
1419   "TARGET_SHMEDIA && peep2_reg_dead_p (2, operands[0])"
1420   [(set (match_dup 2)
1421         (if_then_else:DI (match_dup 3) (match_dup 0) (match_dup 2)))]
1423   operands[3] = gen_rtx_fmt_ee (reverse_condition (GET_CODE (operands[3])),
1424                                 VOIDmode, operands[1], CONST0_RTX (DImode));
1427 (define_peephole2
1428   [(set (match_operand:DI 0 "general_movdst_operand" "")
1429         (match_operand:DI 1 "arith_reg_or_0_operand" ""))
1430    (set (match_operand:DI 2 "arith_reg_dest" "")
1431         (if_then_else:DI (match_operator 4 "equality_comparison_operator"
1432                            [(match_operand:DI 3 "arith_reg_operand" "")
1433                             (const_int 0)])
1434          (match_dup 0)
1435          (match_dup 2)))]
1436   "TARGET_SHMEDIA && peep2_reg_dead_p (2, operands[0])"
1437   [(set (match_dup 2)
1438         (if_then_else:DI (match_dup 4) (match_dup 1) (match_dup 2)))]
1439   "")
1441 (define_expand "movdicc"
1442   [(set (match_operand:DI 0 "register_operand" "")
1443         (if_then_else:DI (match_operand 1 "comparison_operator" "")
1444                          (match_operand:DI 2 "register_operand" "")
1445                          (match_operand:DI 3 "register_operand" "")))]
1446   "TARGET_SHMEDIA"
1448   if ((GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)
1449       && GET_MODE (XEXP (operands[1], 0)) == DImode
1450       && XEXP (operands[1], 1) == const0_rtx)
1451     ;
1452   else
1453     {
1454       if (!can_create_pseudo_p ())
1455         FAIL;
1457       operands[1] = sh_emit_cheap_store_flag (GET_MODE (operands[0]),
1458                                               GET_CODE (operands[1]),
1459                                               XEXP (operands[1], 0),
1460                                               XEXP (operands[1], 1));
1461       if (!operands[1])
1462         FAIL;
1463     }
1466 ;; Add SImode variants for cmveq / cmvne to compensate for not promoting
1467 ;; SImode to DImode.
1468 (define_insn "movsicc_false"
1469   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1470         (if_then_else:SI (eq (match_operand:SI 1 "arith_reg_operand" "r")
1471                           (const_int 0))
1472          (match_operand:SI 2 "arith_reg_or_0_operand" "rN")
1473          (match_operand:SI 3 "arith_reg_operand" "0")))]
1474   "TARGET_SHMEDIA"
1475   "cmveq        %1, %N2, %0"
1476   [(set_attr "type" "arith_media")])
1478 (define_insn "movsicc_true"
1479   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1480         (if_then_else:SI (ne (match_operand:SI 1 "arith_reg_operand" "r")
1481                           (const_int 0))
1482          (match_operand:SI 2 "arith_reg_or_0_operand" "rN")
1483          (match_operand:SI 3 "arith_reg_operand" "0")))]
1484   "TARGET_SHMEDIA"
1485   "cmvne        %1, %N2, %0"
1486   [(set_attr "type" "arith_media")])
1488 (define_peephole2
1489   [(set (match_operand:SI 0 "arith_reg_dest" "")
1490         (if_then_else:SI (match_operator 3 "equality_comparison_operator"
1491                            [(match_operand:SI 1 "arith_reg_operand" "")
1492                             (const_int 0)])
1493          (match_operand:SI 2 "arith_reg_dest" "")
1494          (match_dup 0)))
1495    (set (match_dup 2) (match_dup 0))]
1496   "TARGET_SHMEDIA && peep2_reg_dead_p (2, operands[0])"
1497   [(set (match_dup 2)
1498         (if_then_else:SI (match_dup 3) (match_dup 0) (match_dup 2)))]
1500   operands[3] = gen_rtx_fmt_ee (reverse_condition (GET_CODE (operands[3])),
1501                                 VOIDmode, operands[1], CONST0_RTX (SImode));
1504 (define_peephole2
1505   [(set (match_operand:SI 0 "general_movdst_operand" "")
1506         (match_operand:SI 1 "arith_reg_or_0_operand" ""))
1507    (set (match_operand:SI 2 "arith_reg_dest" "")
1508         (if_then_else:SI (match_operator 4 "equality_comparison_operator"
1509                            [(match_operand:SI 3 "arith_reg_operand" "")
1510                             (const_int 0)])
1511          (match_dup 0)
1512          (match_dup 2)))]
1513   "TARGET_SHMEDIA && peep2_reg_dead_p (2, operands[0])
1514    && (!REG_P (operands[1]) || GENERAL_REGISTER_P (REGNO (operands[1])))"
1515   [(set (match_dup 2)
1516         (if_then_else:SI (match_dup 4) (match_dup 1) (match_dup 2)))]
1518   replace_rtx (operands[4], operands[0], operands[1]);
1521 (define_peephole2
1522   [(set (match_operand 0 "any_register_operand" "")
1523         (match_operand 1 "any_register_operand" ""))
1524    (set (match_operand 2 "any_register_operand" "") (match_operand 3 "" ""))
1525    (set (match_operand 4 "" "") (match_operand 5 "" ""))]
1526   "(HARD_REGNO_NREGS (REGNO (operands[0]), GET_MODE (operands[2]))
1527     <= HARD_REGNO_NREGS (REGNO (operands[0]), GET_MODE (operands[0])))
1528    && peep2_reg_dead_p (3, operands[0]) && peep2_reg_dead_p (3, operands[2])
1529    && ! FIND_REG_INC_NOTE (peep2_next_insn (2), operands[0])
1530    && ! FIND_REG_INC_NOTE (peep2_next_insn (2), operands[2])
1531    && ! reg_overlap_mentioned_p (operands[0], operands[3])
1532    && ! reg_overlap_mentioned_p (operands[2], operands[0])
1533    && ! reg_overlap_mentioned_p (operands[0], operands[1])
1534    && (REGNO_REG_CLASS (REGNO (operands[0]))
1535        == REGNO_REG_CLASS (REGNO (operands[2])))
1536    && (REGNO_REG_CLASS (REGNO (operands[1]))
1537        == REGNO_REG_CLASS (REGNO (operands[0])))"
1538   [(set (match_dup 0) (match_dup 3))
1539    (set (match_dup 4) (match_dup 5))]
1541   rtx set1, set2;
1542   rtx_insn *insn1, *insn2;
1543   rtx replacements[4];
1545   /* We want to replace occurrences of operands[0] with operands[1] and
1546      operands[2] with operands[0] in operands[4]/operands[5].
1547      Doing just two replace_rtx calls naively would result in the second
1548      replacement undoing all that the first did if operands[1] and operands[2]
1549      are identical, so we must do this simultaneously.  */
1550   replacements[0] = operands[0];
1551   replacements[1] = operands[1];
1552   replacements[2] = operands[2];
1553   replacements[3] = operands[0];
1554   if (!replace_n_hard_rtx (operands[5], replacements, 2, 0)
1555       || !replace_n_hard_rtx (operands[4], replacements, 2, 0)
1556       || !replace_n_hard_rtx (operands[2], replacements, 2, 0))
1557     FAIL;
1559   operands[5] = replace_n_hard_rtx (operands[5], replacements, 2, 1);
1560   replace_n_hard_rtx (operands[4], replacements, 2, 1);
1561   operands[2] = replace_n_hard_rtx (operands[2], replacements, 2, 1);
1562   /* The operands array is aliased to recog_data.operand, which gets
1563      clobbered by extract_insn, so finish with it now.  */
1564   set1 = gen_rtx_SET (VOIDmode, operands[2], operands[3]);
1565   set2 = gen_rtx_SET (VOIDmode, operands[4], operands[5]);
1566   /* ??? The last insn might be a jump insn, but the generic peephole2 code
1567      always uses emit_insn.  */
1568   /* Check that we don't violate matching constraints or earlyclobbers.  */
1569   basic_block bb = BLOCK_FOR_INSN (peep2_next_insn (2));
1570   insn1 = emit_insn (set1);
1571   extract_insn (insn1);
1572   if (! constrain_operands (1, get_preferred_alternatives (insn1, bb)))
1573     goto failure;
1574   insn2 = emit (set2);
1575   if (GET_CODE (insn2) == BARRIER)
1576     goto failure;
1577   extract_insn (insn2);
1578   if (! constrain_operands (1, get_preferred_alternatives (insn2, bb)))
1579     {
1580     failure:
1581       std::swap (replacements[0], replacements[1]);
1582       std::swap (replacements[2], replacements[3]);
1583       replace_n_hard_rtx (SET_DEST (set1), replacements, 2, 1);
1584       replace_n_hard_rtx (SET_DEST (set2), replacements, 2, 1);
1585       replace_n_hard_rtx (SET_SRC (set2), replacements, 2, 1);
1586       FAIL;
1587     }
1588   DONE;
1591 ;; The register allocator is rather clumsy in handling multi-way conditional
1592 ;; moves, so allow the combiner to make them, and we split them up after
1593 ;; reload.  */
1594 (define_insn_and_split "*movsicc_umin"
1595   [(set (match_operand:SI 0 "arith_reg_dest" "=&r")
1596         (umin:SI (if_then_else:SI
1597                    (eq (match_operand:SI 1 "arith_reg_operand" "r")
1598                        (const_int 0))
1599                    (match_operand:SI 2 "arith_reg_or_0_operand" "rN")
1600                    (match_operand:SI 3 "register_operand" "0"))
1601                  (match_operand:SI 4 "arith_reg_or_0_operand" "r")))
1602    (clobber (match_scratch:SI 5 "=&r"))]
1603   "TARGET_SHMEDIA && !can_create_pseudo_p ()"
1604   "#"
1605   "TARGET_SHMEDIA && reload_completed"
1606   [(pc)]
1608   emit_insn (gen_movsicc_false (operands[0], operands[1], operands[2],
1609                                 operands[3]));
1610   emit_insn (gen_cmpgtusi_media (operands[5], operands[4], operands[0]));
1611   emit_insn (gen_movsicc_false (operands[0], operands[5], operands[4],
1612                                 operands[0]));
1613   DONE;
1616 (define_insn "*movsicc_t_false"
1617   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
1618         (if_then_else (eq (reg:SI T_REG) (const_int 0))
1619                       (match_operand:SI 1 "general_movsrc_operand" "r,I08")
1620                       (match_operand:SI 2 "arith_reg_operand" "0,0")))]
1621   "TARGET_PRETEND_CMOVE
1622    && (arith_reg_operand (operands[1], SImode)
1623        || (immediate_operand (operands[1], SImode)
1624            && satisfies_constraint_I08 (operands[1])))"
1626   return       "bt      0f"     "\n"
1627          "      mov     %1,%0"  "\n"
1628          "0:";
1630   [(set_attr "type" "mt_group,arith") ;; poor approximation
1631    (set_attr "length" "4")])
1633 (define_insn "*movsicc_t_true"
1634   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
1635         (if_then_else (ne (reg:SI T_REG) (const_int 0))
1636                       (match_operand:SI 1 "general_movsrc_operand" "r,I08")
1637                       (match_operand:SI 2 "arith_reg_operand" "0,0")))]
1638   "TARGET_PRETEND_CMOVE
1639    && (arith_reg_operand (operands[1], SImode)
1640        || (immediate_operand (operands[1], SImode)
1641            && satisfies_constraint_I08 (operands[1])))"
1643   return       "bf      0f"     "\n"
1644          "      mov     %1,%0"  "\n"
1645          "0:";
1647   [(set_attr "type" "mt_group,arith") ;; poor approximation
1648    (set_attr "length" "4")])
1650 (define_expand "movsicc"
1651   [(set (match_operand:SI 0 "arith_reg_dest" "")
1652         (if_then_else:SI (match_operand 1 "comparison_operator" "")
1653                          (match_operand:SI 2 "arith_reg_or_0_operand" "")
1654                          (match_operand:SI 3 "arith_reg_operand" "")))]
1655   "TARGET_SHMEDIA || TARGET_PRETEND_CMOVE"
1657   if ((GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)
1658       && GET_MODE (XEXP (operands[1], 0)) == SImode
1659       && (TARGET_SHMEDIA
1660           || (REG_P (XEXP (operands[1], 0))
1661               && REGNO (XEXP (operands[1], 0)) == T_REG))
1662       && XEXP (operands[1], 1) == const0_rtx)
1663     ;
1665   else if (TARGET_PRETEND_CMOVE)
1666     {
1667       enum rtx_code code = GET_CODE (operands[1]);
1668       enum rtx_code new_code = code;
1669       rtx op0 = XEXP (operands[1], 0);
1670       rtx op1 = XEXP (operands[1], 1);
1672       if (! currently_expanding_to_rtl)
1673         FAIL;
1674       switch (code)
1675         {
1676         case LT: case LE: case LEU: case LTU:
1677           if (GET_MODE_CLASS (GET_MODE (op0)) != MODE_INT)
1678             break;
1679         case NE:
1680           new_code = reverse_condition (code);
1681           break;
1682         case EQ: case GT: case GE: case GEU: case GTU:
1683           break;
1684         default:
1685           FAIL;
1686         }
1687       sh_emit_scc_to_t (new_code, op0, op1);
1688       operands[1] = gen_rtx_fmt_ee (new_code == code ? NE : EQ, VOIDmode,
1689                                     gen_rtx_REG (SImode, T_REG), const0_rtx);
1690     }
1691   else
1692     {
1693       if (!can_create_pseudo_p ())
1694         FAIL;
1696       operands[1] = sh_emit_cheap_store_flag (GET_MODE (operands[0]),
1697                                               GET_CODE (operands[1]),
1698                                               XEXP (operands[1], 0),
1699                                               XEXP (operands[1], 1));
1700       if (!operands[1])
1701         FAIL;
1702     }
1705 (define_expand "movqicc"
1706   [(set (match_operand:QI 0 "register_operand" "")
1707         (if_then_else:QI (match_operand 1 "comparison_operator" "")
1708                          (match_operand:QI 2 "register_operand" "")
1709                          (match_operand:QI 3 "register_operand" "")))]
1710   "TARGET_SHMEDIA"
1712   operands[0] = simplify_gen_subreg (SImode, operands[0], QImode, 0);
1713   operands[2] = simplify_gen_subreg (SImode, operands[2], QImode, 0);
1714   operands[3] = simplify_gen_subreg (SImode, operands[3], QImode, 0);
1715   emit (gen_movsicc (operands[0], operands[1], operands[2], operands[3]));
1716   DONE;
1719 ;; -------------------------------------------------------------------------
1720 ;; Addition instructions
1721 ;; -------------------------------------------------------------------------
1723 (define_expand "adddi3"
1724   [(set (match_operand:DI 0 "arith_reg_operand")
1725         (plus:DI (match_operand:DI 1 "arith_reg_operand")
1726                  (match_operand:DI 2 "arith_operand")))]
1727   ""
1729   if (TARGET_SH1)
1730     {
1731       operands[2] = force_reg (DImode, operands[2]);
1732       emit_insn (gen_adddi3_compact (operands[0], operands[1], operands[2]));
1733       DONE;
1734     }
1737 (define_insn "*adddi3_media"
1738   [(set (match_operand:DI 0 "arith_reg_dest" "=r,r")
1739         (plus:DI (match_operand:DI 1 "arith_reg_operand" "%r,r")
1740                  (match_operand:DI 2 "arith_operand" "r,I10")))]
1741   "TARGET_SHMEDIA"
1742   "@
1743         add     %1, %2, %0
1744         addi    %1, %2, %0"
1745   [(set_attr "type" "arith_media")])
1747 (define_insn "*adddisi3_media"
1748   [(set (subreg:DI (match_operand:SI 0 "arith_reg_operand" "=r,r") 0)
1749         (plus:DI (match_operand:DI 1 "arith_reg_operand" "%r,r")
1750                  (match_operand:DI 2 "arith_operand" "r,I10")))]
1751   "TARGET_SHMEDIA"
1752   "@
1753         add.l   %1, %2, %0
1754         addi.l  %1, %2, %0"
1755   [(set_attr "type" "arith_media")
1756    (set_attr "highpart" "ignore")])
1758 (define_insn "adddi3z_media"
1759   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
1760         (zero_extend:DI
1761          (plus:SI (match_operand:SI 1 "extend_reg_operand" "r")
1762                   (match_operand:SI 2 "extend_reg_or_0_operand" "rN"))))]
1763   "TARGET_SHMEDIA"
1764   "addz.l       %1, %N2, %0"
1765   [(set_attr "type" "arith_media")
1766    (set_attr "highpart" "ignore")])
1768 (define_insn_and_split "adddi3_compact"
1769   [(set (match_operand:DI 0 "arith_reg_dest")
1770         (plus:DI (match_operand:DI 1 "arith_reg_operand")
1771                  (match_operand:DI 2 "arith_reg_operand")))
1772    (clobber (reg:SI T_REG))]
1773   "TARGET_SH1"
1774   "#"
1775   "&& can_create_pseudo_p ()"
1776   [(const_int 0)]
1778   emit_insn (gen_clrt ());
1779   emit_insn (gen_addc (gen_lowpart (SImode, operands[0]),
1780                        gen_lowpart (SImode, operands[1]),
1781                        gen_lowpart (SImode, operands[2])));
1782   emit_insn (gen_addc (gen_highpart (SImode, operands[0]),
1783                        gen_highpart (SImode, operands[1]),
1784                        gen_highpart (SImode, operands[2])));
1785   DONE;
1788 (define_insn "addc"
1789   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1790         (plus:SI (plus:SI (match_operand:SI 1 "arith_reg_operand" "%0")
1791                           (match_operand:SI 2 "arith_reg_operand" "r"))
1792                  (reg:SI T_REG)))
1793    (set (reg:SI T_REG)
1794         (ltu:SI (plus:SI (match_dup 1) (match_dup 2)) (match_dup 1)))]
1795   "TARGET_SH1"
1796   "addc %2,%0"
1797   [(set_attr "type" "arith")])
1799 ;; A simplified version of the addc insn, where the exact value of the
1800 ;; T bit doesn't matter.  This is easier for combine to pick up.
1801 ;; We allow a reg or 0 for one of the operands in order to be able to
1802 ;; do 'reg + T' sequences.  Reload will load the constant 0 into the reg
1803 ;; as needed.
1804 ;; FIXME: The load of constant 0 should be split out before reload, or else
1805 ;; it will be difficult to hoist or combine the constant load.
1806 (define_insn "*addc"
1807   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
1808         (plus:SI (plus:SI (match_operand:SI 1 "arith_reg_operand" "%0")
1809                           (match_operand:SI 2 "arith_reg_or_0_operand" "r"))
1810                  (match_operand:SI 3 "t_reg_operand" "")))
1811    (clobber (reg:SI T_REG))]
1812   "TARGET_SH1"
1813   "addc %2,%0"
1814   [(set_attr "type" "arith")])
1816 ;; Split 'reg + reg + 1' into a sett addc sequence, as it can be scheduled
1817 ;; better, if the sett insn can be done early.
1818 (define_insn_and_split "*addc_r_r_1"
1819   [(set (match_operand:SI 0 "arith_reg_dest" "")
1820         (plus:SI (plus:SI (match_operand:SI 1 "arith_reg_operand" "")
1821                           (match_operand:SI 2 "arith_reg_operand" ""))
1822                  (const_int 1)))
1823    (clobber (reg:SI T_REG))]
1824   "TARGET_SH1"
1825   "#"
1826   "&& 1"
1827   [(set (reg:SI T_REG) (const_int 1))
1828    (parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 1) (match_dup 2))
1829                                           (reg:SI T_REG)))
1830               (clobber (reg:SI T_REG))])])
1832 ;; Left shifts by one are usually done with an add insn to avoid T_REG
1833 ;; clobbers.  Thus addc can also be used to do something like '(x << 1) + 1'.
1834 (define_insn_and_split "*addc_2r_1"
1835   [(set (match_operand:SI 0 "arith_reg_dest")
1836         (plus:SI (mult:SI (match_operand:SI 1 "arith_reg_operand")
1837                           (const_int 2))
1838                  (const_int 1)))
1839    (clobber (reg:SI T_REG))]
1840   "TARGET_SH1"
1841   "#"
1842   "&& 1"
1843   [(set (reg:SI T_REG) (const_int 1))
1844    (parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 1) (match_dup 1))
1845                                           (reg:SI T_REG)))
1846               (clobber (reg:SI T_REG))])])
1848 ;; Sometimes combine will try to do 'reg + (0-reg) + 1' if the *addc pattern
1849 ;; matched.  Split this up into a simple sub add sequence, as this will save
1850 ;; us one sett insn.
1851 (define_insn_and_split "*minus_plus_one"
1852   [(set (match_operand:SI 0 "arith_reg_dest" "")
1853         (plus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "")
1854                            (match_operand:SI 2 "arith_reg_operand" ""))
1855                  (const_int 1)))]
1856   "TARGET_SH1"
1857   "#"
1858   "&& 1"
1859   [(set (match_dup 0) (minus:SI (match_dup 1) (match_dup 2)))
1860    (set (match_dup 0) (plus:SI (match_dup 0) (const_int 1)))])
1862 ;; Split 'reg + T' into 'reg + 0 + T' to utilize the addc insn.
1863 ;; If the 0 constant can be CSE-ed, this becomes a one instruction
1864 ;; operation, as opposed to sequences such as
1865 ;;      movt    r2
1866 ;;      add     r2,r3
1868 ;; Even if the constant is not CSE-ed, a sequence such as
1869 ;;      mov     #0,r2
1870 ;;      addc    r2,r3
1871 ;; can be scheduled much better since the load of the constant can be
1872 ;; done earlier, before any comparison insns that store the result in
1873 ;; the T bit.
1874 (define_insn_and_split "*addc_t_r"
1875   [(set (match_operand:SI 0 "arith_reg_dest")
1876         (plus:SI (match_operand:SI 1 "t_reg_operand")
1877                  (match_operand:SI 2 "arith_reg_operand")))
1878    (clobber (reg:SI T_REG))]
1879   "TARGET_SH1"
1880   "#"
1881   "&& 1"
1882   [(parallel [(set (match_dup 0)
1883                    (plus:SI (plus:SI (match_dup 2) (const_int 0))
1884                             (match_dup 1)))
1885               (clobber (reg:SI T_REG))])])
1887 (define_insn_and_split "*addc_r_t"
1888   [(set (match_operand:SI 0 "arith_reg_dest")
1889         (plus:SI (match_operand:SI 1 "arith_reg_operand")
1890                  (match_operand:SI 2 "t_reg_operand")))
1891    (clobber (reg:SI T_REG))]
1892   "TARGET_SH1"
1893   "#"
1894   "&& 1"
1895   [(parallel [(set (match_dup 0)
1896                    (plus:SI (plus:SI (match_dup 1) (const_int 0))
1897                             (match_dup 2)))
1898               (clobber (reg:SI T_REG))])])
1900 ;; Use shlr-addc to do 'reg + (reg & 1)'.
1901 (define_insn_and_split "*addc_r_lsb"
1902   [(set (match_operand:SI 0 "arith_reg_dest")
1903         (plus:SI (and:SI (match_operand:SI 1 "arith_reg_operand")
1904                          (const_int 1))
1905                  (match_operand:SI 2 "arith_reg_operand")))
1906    (clobber (reg:SI T_REG))]
1907   "TARGET_SH1"
1908   "#"
1909   "&& can_create_pseudo_p ()"
1910   [(parallel [(set (match_dup 0) (plus:SI (reg:SI T_REG) (match_dup 2)))
1911               (clobber (reg:SI T_REG))])]
1913   emit_insn (gen_shlr (gen_reg_rtx (SImode), operands[1]));
1916 ;; Use shlr-addc to do 'reg + reg + (reg & 1)'.
1917 (define_insn_and_split "*addc_r_r_lsb"
1918   [(set (match_operand:SI 0 "arith_reg_dest")
1919         (plus:SI (plus:SI (and:SI (match_operand:SI 1 "arith_reg_operand")
1920                                   (const_int 1))
1921                           (match_operand:SI 2 "arith_reg_operand"))
1922                  (match_operand:SI 3 "arith_reg_operand")))
1923    (clobber (reg:SI T_REG))]
1924   "TARGET_SH1"
1925   "#"
1926   "&& can_create_pseudo_p ()"
1927   [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (match_dup 3))
1928                                           (reg:SI T_REG)))
1929               (clobber (reg:SI T_REG))])]
1931   emit_insn (gen_shlr (gen_reg_rtx (SImode), operands[1]));
1934 ;; Canonicalize 'reg + (reg & 1) + reg' into 'reg + reg + (reg & 1)'.
1935 (define_insn_and_split "*addc_r_lsb_r"
1936   [(set (match_operand:SI 0 "arith_reg_dest")
1937         (plus:SI (and:SI (match_operand:SI 1 "arith_reg_operand")
1938                          (const_int 1))
1939                  (plus:SI (match_operand:SI 2 "arith_reg_operand")
1940                           (match_operand:SI 3 "arith_reg_operand"))))
1941    (clobber (reg:SI T_REG))]
1942   "TARGET_SH1"
1943   "#"
1944   "&& can_create_pseudo_p ()"
1945   [(parallel [(set (match_dup 0)
1946                    (plus:SI (plus:SI (and:SI (match_dup 1) (const_int 1))
1947                                      (match_dup 2))
1948                             (match_dup 3)))
1949               (clobber (reg:SI T_REG))])])
1951 ;; Canonicalize '2 * reg + (reg & 1)' into 'reg + reg + (reg & 1)'.
1952 (define_insn_and_split "*addc_2r_lsb"
1953   [(set (match_operand:SI 0 "arith_reg_dest")
1954         (plus:SI (and:SI (match_operand:SI 1 "arith_reg_operand")
1955                          (const_int 1))
1956                  (mult:SI (match_operand:SI 2 "arith_reg_operand")
1957                           (const_int 2))))
1958    (clobber (reg:SI T_REG))]
1959   "TARGET_SH1"
1960   "#"
1961   "&& can_create_pseudo_p ()"
1962   [(parallel [(set (match_dup 0)
1963                    (plus:SI (plus:SI (and:SI (match_dup 1) (const_int 1))
1964                                      (match_dup 2))
1965                             (match_dup 2)))
1966               (clobber (reg:SI T_REG))])])
1968 ;; Use shll-addc to do 'reg + ((unsigned int)reg >> 31)'.
1969 (define_insn_and_split "*addc_r_msb"
1970   [(set (match_operand:SI 0 "arith_reg_dest")
1971         (plus:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
1972                               (const_int 31))
1973                  (match_operand:SI 2 "arith_reg_operand")))
1974    (clobber (reg:SI T_REG))]
1975   "TARGET_SH1"
1976   "#"
1977   "&& can_create_pseudo_p ()"
1978   [(parallel [(set (match_dup 0) (plus:SI (reg:SI T_REG) (match_dup 2)))
1979               (clobber (reg:SI T_REG))])]
1981   emit_insn (gen_shll (gen_reg_rtx (SImode), operands[1]));
1984 ;; Use shll-addc to do 'reg + reg + ((unsigned int)reg >> 31)'.
1985 (define_insn_and_split "*addc_r_r_msb"
1986   [(set (match_operand:SI 0 "arith_reg_dest")
1987         (plus:SI (plus:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
1988                                        (const_int 31))
1989                           (match_operand:SI 2 "arith_reg_operand"))
1990                  (match_operand:SI 3 "arith_reg_operand")))
1991    (clobber (reg:SI T_REG))]
1992   "TARGET_SH1"
1993   "#"
1994   "&& can_create_pseudo_p ()"
1995   [(parallel [(set (match_dup 0) (plus:SI (plus:SI (match_dup 2) (match_dup 3))
1996                                           (reg:SI T_REG)))
1997               (clobber (reg:SI T_REG))])]
1999   emit_insn (gen_shll (gen_reg_rtx (SImode), operands[1]));
2002 ;; Canonicalize '2 * reg + ((unsigned int)reg >> 31)'
2003 ;; into 'reg + reg + (reg & 1)'.
2004 (define_insn_and_split "*addc_2r_msb"
2005   [(set (match_operand:SI 0 "arith_reg_dest")
2006         (plus:SI (mult:SI (match_operand:SI 1 "arith_reg_operand")
2007                           (const_int 2))
2008                  (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand")
2009                               (const_int 31))))
2010    (clobber (reg:SI T_REG))]
2011   "TARGET_SH1"
2012   "#"
2013   "&& can_create_pseudo_p ()"
2014   [(parallel [(set (match_dup 0)
2015                    (plus:SI (plus:SI (lshiftrt:SI (match_dup 2) (const_int 31))
2016                                      (match_dup 1))
2017                             (match_dup 1)))
2018               (clobber (reg:SI T_REG))])])
2020 (define_expand "addsi3"
2021   [(set (match_operand:SI 0 "arith_reg_operand" "")
2022         (plus:SI (match_operand:SI 1 "arith_operand" "")
2023                  (match_operand:SI 2 "arith_operand" "")))]
2024   ""
2026   if (TARGET_SHMEDIA)
2027     operands[1] = force_reg (SImode, operands[1]);
2030 (define_insn "addsi3_media"
2031   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
2032         (plus:SI (match_operand:SI 1 "extend_reg_operand" "%r,r")
2033                  (match_operand:SI 2 "arith_operand" "r,I10")))]
2034   "TARGET_SHMEDIA"
2035   "@
2036         add.l   %1, %2, %0
2037         addi.l  %1, %2, %0"
2038   [(set_attr "type" "arith_media")
2039    (set_attr "highpart" "ignore")])
2041 (define_insn "addsidi3_media"
2042   [(set (match_operand:DI 0 "arith_reg_dest" "=r,r")
2043         (sign_extend:DI (plus:SI (match_operand:SI 1 "extend_reg_operand"
2044                                   "%r,r")
2045                                  (match_operand:SI 2 "arith_operand"
2046                                   "r,I10"))))]
2047   "TARGET_SHMEDIA"
2048   "@
2049         add.l   %1, %2, %0
2050         addi.l  %1, %2, %0"
2051   [(set_attr "type" "arith_media")
2052    (set_attr "highpart" "ignore")])
2054 (define_insn "*addsi3_compact"
2055   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2056         (plus:SI (match_operand:SI 1 "arith_operand" "%0")
2057                  (match_operand:SI 2 "arith_operand" "rI08")))]
2058   "TARGET_SH1"
2059   "add  %2,%0"
2060   [(set_attr "type" "arith")])
2062 ;; -------------------------------------------------------------------------
2063 ;; Subtraction instructions
2064 ;; -------------------------------------------------------------------------
2066 (define_expand "subdi3"
2067   [(set (match_operand:DI 0 "arith_reg_operand" "")
2068         (minus:DI (match_operand:DI 1 "arith_reg_or_0_operand" "")
2069                   (match_operand:DI 2 "arith_reg_operand" "")))]
2070   ""
2072   if (TARGET_SH1)
2073     {
2074       operands[1] = force_reg (DImode, operands[1]);
2075       emit_insn (gen_subdi3_compact (operands[0], operands[1], operands[2]));
2076       DONE;
2077     }
2080 (define_insn "*subdi3_media"
2081   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
2082         (minus:DI (match_operand:DI 1 "arith_reg_or_0_operand" "rN")
2083                   (match_operand:DI 2 "arith_reg_operand" "r")))]
2084   "TARGET_SHMEDIA"
2085   "sub  %N1, %2, %0"
2086   [(set_attr "type" "arith_media")])
2087   
2088 (define_insn "subdisi3_media"
2089   [(set (subreg:DI (match_operand:SI 0 "arith_reg_operand" "=r") 0)
2090         (minus:DI (match_operand:DI 1 "arith_reg_or_0_operand" "rN")
2091                   (match_operand:DI 2 "arith_reg_operand" "r")))]
2092   "TARGET_SHMEDIA"
2093   "sub.l        %N1, %2, %0"
2094   [(set_attr "type" "arith_media")
2095    (set_attr "highpart" "ignore")])
2097 (define_insn_and_split "subdi3_compact"
2098   [(set (match_operand:DI 0 "arith_reg_dest")
2099         (minus:DI (match_operand:DI 1 "arith_reg_operand")
2100                  (match_operand:DI 2 "arith_reg_operand")))
2101    (clobber (reg:SI T_REG))]
2102   "TARGET_SH1"
2103   "#"
2104   "&& can_create_pseudo_p ()"
2105   [(const_int 0)]
2107   emit_insn (gen_clrt ());
2108   emit_insn (gen_subc (gen_lowpart (SImode, operands[0]),
2109                        gen_lowpart (SImode, operands[1]),
2110                        gen_lowpart (SImode, operands[2])));
2111   emit_insn (gen_subc (gen_highpart (SImode, operands[0]),
2112                        gen_highpart (SImode, operands[1]),
2113                        gen_highpart (SImode, operands[2])));
2114   DONE;
2117 (define_insn "subc"
2118   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2119         (minus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
2120                             (match_operand:SI 2 "arith_reg_operand" "r"))
2121                   (reg:SI T_REG)))
2122    (set (reg:SI T_REG)
2123         (gtu:SI (minus:SI (minus:SI (match_dup 1) (match_dup 2))
2124                           (reg:SI T_REG))
2125                 (match_dup 1)))]
2126   "TARGET_SH1"
2127   "subc %2,%0"
2128   [(set_attr "type" "arith")])
2130 ;; A simplified version of the subc insn, where the exact value of the
2131 ;; T bit doesn't matter.  This is easier for combine to pick up.
2132 ;; We allow a reg or 0 for one of the operands in order to be able to
2133 ;; do 'reg - T' sequences.  Reload will load the constant 0 into the reg
2134 ;; as needed.
2135 (define_insn "*subc"
2136   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2137         (minus:SI (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
2138                             (match_operand:SI 2 "arith_reg_or_0_operand" "r"))
2139                   (match_operand:SI 3 "t_reg_operand" "")))
2140    (clobber (reg:SI T_REG))]
2141   "TARGET_SH1"
2142   "subc %2,%0"
2143   [(set_attr "type" "arith")])
2145 ;; Split reg - reg - 1 into a sett subc sequence, as it can be scheduled
2146 ;; better, if the sett insn can be done early.
2147 ;; Notice that combine turns 'a - b - 1' into 'a + (~b)'.
2148 (define_insn_and_split "*subc"
2149   [(set (match_operand:SI 0 "arith_reg_dest" "")
2150         (plus:SI (not:SI (match_operand:SI 1 "arith_reg_operand" ""))
2151                  (match_operand:SI 2 "arith_reg_operand" "")))
2152    (clobber (reg:SI T_REG))]
2153   "TARGET_SH1"
2154   "#"
2155   "&& 1"
2156   [(set (reg:SI T_REG) (const_int 1))
2157    (parallel [(set (match_dup 0)
2158                    (minus:SI (minus:SI (match_dup 2) (match_dup 1))
2159                              (reg:SI T_REG)))
2160               (clobber (reg:SI T_REG))])])
2162 ;; Split 'reg - T' into 'reg - 0 - T' to utilize the subc insn.
2163 ;; If the 0 constant can be CSE-ed, this becomes a one instruction
2164 ;; operation, as opposed to sequences such as
2165 ;;      movt    r2
2166 ;;      sub     r2,r3
2168 ;; Even if the constant is not CSE-ed, a sequence such as
2169 ;;      mov     #0,r2
2170 ;;      subc    r2,r3
2171 ;; can be scheduled much better since the load of the constant can be
2172 ;; done earlier, before any comparison insns that store the result in
2173 ;; the T bit.
2174 (define_insn_and_split "*subc"
2175   [(set (match_operand:SI 0 "arith_reg_dest" "")
2176         (minus:SI (match_operand:SI 1 "arith_reg_operand" "")
2177                   (match_operand:SI 2 "t_reg_operand" "")))
2178    (clobber (reg:SI T_REG))]
2179   "TARGET_SH1"
2180   "#"
2181   "&& 1"
2182   [(parallel [(set (match_dup 0)
2183                    (minus:SI (minus:SI (match_dup 1) (const_int 0))
2184                              (match_dup 2)))
2185               (clobber (reg:SI T_REG))])])
2187 (define_insn "*subsi3_internal"
2188   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2189         (minus:SI (match_operand:SI 1 "arith_reg_operand" "0")
2190                   (match_operand:SI 2 "arith_reg_operand" "r")))]
2191   "TARGET_SH1"
2192   "sub  %2,%0"
2193   [(set_attr "type" "arith")])
2195 (define_insn_and_split "*subsi3_media"
2196   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2197         (minus:SI (match_operand:SI 1 "minuend_operand" "rN")
2198                   (match_operand:SI 2 "extend_reg_operand" "r")))]
2199   "TARGET_SHMEDIA
2200    && (operands[1] != constm1_rtx
2201        || (GET_CODE (operands[2]) != TRUNCATE
2202            && GET_CODE (operands[2]) != SUBREG))"
2203   "sub.l        %N1, %2, %0"
2204   "operands[1] == constm1_rtx"
2205   [(set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))]
2206   ""
2207   [(set_attr "type" "arith_media")
2208    (set_attr "highpart" "ignore")])
2210 (define_split
2211   [(set (match_operand:SI 0 "arith_reg_dest" "")
2212         (zero_extend:SI (subreg:QI (not:SI (subreg:SI (match_operand:QI 1
2213                                                        "general_extend_operand"
2214                                                        "") 0)) 0)))]
2215   "TARGET_SHMEDIA && TARGET_LITTLE_ENDIAN"
2216   [(set (match_dup 0) (zero_extend:SI (match_dup 1)))
2217    (set (match_dup 0) (xor:SI (match_dup 0) (const_int 255)))]
2218   "")
2220 (define_split
2221   [(set (match_operand:SI 0 "arith_reg_dest" "")
2222         (zero_extend:SI (subreg:QI (not:SI (subreg:SI (match_operand:QI 1
2223                                                        "general_extend_operand"
2224                                                        "") 0)) 3)))]
2225   "TARGET_SHMEDIA && TARGET_BIG_ENDIAN"
2226   [(set (match_dup 0) (zero_extend:SI (match_dup 1)))
2227    (set (match_dup 0) (xor:SI (match_dup 0) (const_int 255)))]
2228   "")
2230 ;; Convert
2231 ;;      constant - reg
2232 ;; to
2233 ;;      neg reg
2234 ;;      add reg, #const
2235 ;; since this will sometimes save one instruction.
2236 ;; Otherwise we might get a sequence like
2237 ;;      mov #const, rY
2238 ;;      sub rY, rX
2239 ;;      mov rX, rY
2240 ;; if the source and dest regs are the same.
2241 (define_expand "subsi3"
2242   [(set (match_operand:SI 0 "arith_reg_operand" "")
2243         (minus:SI (match_operand:SI 1 "arith_operand" "")
2244                   (match_operand:SI 2 "arith_reg_operand" "")))]
2245   ""
2247   if (TARGET_SH1 && CONST_INT_P (operands[1]))
2248     {
2249       emit_insn (gen_negsi2 (operands[0], operands[2]));
2250       emit_insn (gen_addsi3 (operands[0], operands[0], operands[1]));
2251       DONE;
2252     }
2253   if (TARGET_SHMEDIA)
2254     {
2255       if (!can_create_pseudo_p ()
2256           && ! arith_reg_or_0_operand (operands[1], SImode))
2257         FAIL;
2258       if (operands[1] != const0_rtx && GET_CODE (operands[1]) != SUBREG)
2259         operands[1] = force_reg (SImode, operands[1]);
2260     }
2263 ;; -------------------------------------------------------------------------
2264 ;; Division instructions
2265 ;; -------------------------------------------------------------------------
2267 ;; We take advantage of the library routines which don't clobber as many
2268 ;; registers as a normal function call would.
2270 ;; The INSN_REFERENCES_ARE_DELAYED in sh.h is problematic because it
2271 ;; also has an effect on the register that holds the address of the sfunc.
2272 ;; To make this work, we have an extra dummy insn that shows the use
2273 ;; of this register for reorg.
2275 (define_insn "use_sfunc_addr"
2276   [(set (reg:SI PR_REG)
2277         (unspec:SI [(match_operand:SI 0 "register_operand" "r")] UNSPEC_SFUNC))]
2278   "TARGET_SH1 && check_use_sfunc_addr (insn, operands[0])"
2279   ""
2280   [(set_attr "length" "0")])
2282 (define_insn "udivsi3_sh2a"
2283   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2284         (udiv:SI (match_operand:SI 1 "arith_reg_operand" "0")
2285                 (match_operand:SI 2 "arith_reg_operand" "z")))]
2286   "TARGET_SH2A"
2287   "divu %2,%1"
2288   [(set_attr "type" "arith")
2289    (set_attr "in_delay_slot" "no")])
2291 ;; We must use a pseudo-reg forced to reg 0 in the SET_DEST rather than
2292 ;; hard register 0.  If we used hard register 0, then the next instruction
2293 ;; would be a move from hard register 0 to a pseudo-reg.  If the pseudo-reg
2294 ;; gets allocated to a stack slot that needs its address reloaded, then
2295 ;; there is nothing to prevent reload from using r0 to reload the address.
2296 ;; This reload would clobber the value in r0 we are trying to store.
2297 ;; If we let reload allocate r0, then this problem can never happen.
2298 (define_insn "udivsi3_i1"
2299   [(set (match_operand:SI 0 "register_operand" "=z")
2300         (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2301    (clobber (reg:SI T_REG))
2302    (clobber (reg:SI PR_REG))
2303    (clobber (reg:SI R1_REG))
2304    (clobber (reg:SI R4_REG))
2305    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2306   "TARGET_SH1 && TARGET_DIVIDE_CALL_DIV1"
2307   "jsr  @%1%#"
2308   [(set_attr "type" "sfunc")
2309    (set_attr "needs_delay_slot" "yes")])
2311 ; Since shmedia-nofpu code could be linked against shcompact code, and
2312 ; the udivsi3 libcall has the same name, we must consider all registers
2313 ; clobbered that are in the union of the registers clobbered by the
2314 ; shmedia and the shcompact implementation.  Note, if the shcompact
2315 ; implementation actually used shcompact code, we'd need to clobber
2316 ; also r23 and fr23.
2317 (define_insn "udivsi3_i1_media"
2318   [(set (match_operand:SI 0 "register_operand" "=z")
2319         (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2320    (clobber (reg:SI T_MEDIA_REG))
2321    (clobber (reg:SI PR_MEDIA_REG))
2322    (clobber (reg:SI R20_REG))
2323    (clobber (reg:SI R21_REG))
2324    (clobber (reg:SI R22_REG))
2325    (clobber (reg:DI TR0_REG))
2326    (clobber (reg:DI TR1_REG))
2327    (clobber (reg:DI TR2_REG))
2328    (use (match_operand 1 "target_reg_operand" "b"))]
2329   "TARGET_SHMEDIA && (! TARGET_SHMEDIA_FPU || ! TARGET_DIVIDE_FP)"
2330   "blink        %1, r18"
2331   [(set_attr "type" "sfunc")
2332    (set_attr "needs_delay_slot" "yes")])
2334 (define_expand "udivsi3_i4_media"
2335   [(set (match_dup 3)
2336         (zero_extend:DI (match_operand:SI 1 "register_operand" "")))
2337    (set (match_dup 4)
2338         (zero_extend:DI (match_operand:SI 2 "register_operand" "")))
2339    (set (match_dup 5) (float:DF (match_dup 3)))
2340    (set (match_dup 6) (float:DF (match_dup 4)))
2341    (set (match_dup 7) (div:DF (match_dup 5) (match_dup 6)))
2342    (set (match_dup 8) (fix:DI (match_dup 7)))
2343    (set (match_operand:SI 0 "register_operand" "")
2344         (truncate:SI (match_dup 8)))]
2345   "TARGET_SHMEDIA_FPU"
2347   operands[3] = gen_reg_rtx (DImode);
2348   operands[4] = gen_reg_rtx (DImode);
2349   operands[5] = gen_reg_rtx (DFmode);
2350   operands[6] = gen_reg_rtx (DFmode);
2351   operands[7] = gen_reg_rtx (DFmode);
2352   operands[8] = gen_reg_rtx (DImode);
2355 (define_insn "udivsi3_i4"
2356   [(set (match_operand:SI 0 "register_operand" "=y")
2357         (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2358    (clobber (reg:SI T_REG))
2359    (clobber (reg:SI PR_REG))
2360    (clobber (reg:DF DR0_REG))
2361    (clobber (reg:DF DR2_REG))
2362    (clobber (reg:DF DR4_REG))
2363    (clobber (reg:SI R0_REG))
2364    (clobber (reg:SI R1_REG))
2365    (clobber (reg:SI R4_REG))
2366    (clobber (reg:SI R5_REG))
2367    (clobber (reg:SI FPSCR_STAT_REG))
2368    (use (reg:SI FPSCR_MODES_REG))
2369    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2370   "TARGET_FPU_DOUBLE && ! TARGET_FPU_SINGLE"
2371   "jsr  @%1%#"
2372   [(set_attr "type" "sfunc")
2373    (set_attr "fp_mode" "double")
2374    (set_attr "needs_delay_slot" "yes")])
2376 (define_insn "udivsi3_i4_single"
2377   [(set (match_operand:SI 0 "register_operand" "=y")
2378         (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2379    (clobber (reg:SI T_REG))
2380    (clobber (reg:SI PR_REG))
2381    (clobber (reg:DF DR0_REG))
2382    (clobber (reg:DF DR2_REG))
2383    (clobber (reg:DF DR4_REG))
2384    (clobber (reg:SI R0_REG))
2385    (clobber (reg:SI R1_REG))
2386    (clobber (reg:SI R4_REG))
2387    (clobber (reg:SI R5_REG))
2388    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2389   "(TARGET_FPU_SINGLE_ONLY || TARGET_FPU_DOUBLE || TARGET_SHCOMPACT)
2390    && TARGET_FPU_SINGLE"
2391   "jsr  @%1%#"
2392   [(set_attr "type" "sfunc")
2393    (set_attr "needs_delay_slot" "yes")])
2395 (define_insn "udivsi3_i4_int"
2396   [(set (match_operand:SI 0 "register_operand" "=z")
2397         (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2398    (clobber (reg:SI T_REG))
2399    (clobber (reg:SI R1_REG))
2400    (clobber (reg:SI PR_REG))
2401    (clobber (reg:SI MACH_REG))
2402    (clobber (reg:SI MACL_REG))
2403    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2404   "TARGET_SH1"
2405   "jsr  @%1%#"
2406   [(set_attr "type" "sfunc")
2407    (set_attr "needs_delay_slot" "yes")])
2410 (define_expand "udivsi3"
2411   [(set (match_dup 3) (symbol_ref:SI "__udivsi3"))
2412    (set (reg:SI R4_REG) (match_operand:SI 1 "general_operand" ""))
2413    (set (reg:SI R5_REG) (match_operand:SI 2 "general_operand" ""))
2414    (parallel [(set (match_operand:SI 0 "register_operand" "")
2415                    (udiv:SI (reg:SI R4_REG)
2416                             (reg:SI R5_REG)))
2417               (clobber (reg:SI T_REG))
2418               (clobber (reg:SI PR_REG))
2419               (clobber (reg:SI R4_REG))
2420               (use (match_dup 3))])]
2421   ""
2423   rtx last;
2425   operands[3] = gen_reg_rtx (Pmode);
2426   /* Emit the move of the address to a pseudo outside of the libcall.  */
2427   if (TARGET_DIVIDE_CALL_TABLE)
2428     {
2429       /* libgcc2:__udivmoddi4 is not supposed to use an actual division, since
2430          that causes problems when the divide code is supposed to come from a
2431          separate library.  Division by zero is undefined, so dividing 1 can be
2432          implemented by comparing with the divisor.  */
2433       if (operands[1] == const1_rtx && currently_expanding_to_rtl)
2434         {
2435           rtx test = gen_rtx_GEU (VOIDmode, operands[1], operands[2]);
2436           emit_insn (gen_cstoresi4 (operands[0], test,
2437                                     operands[1], operands[2]));
2438           DONE;
2439         }
2440       else if (operands[2] == const0_rtx)
2441         {
2442           emit_move_insn (operands[0], operands[2]);
2443           DONE;
2444         }
2445       function_symbol (operands[3], "__udivsi3_i4i", SFUNC_GOT);
2446       last = gen_udivsi3_i4_int (operands[0], operands[3]);
2447     }
2448   else if (TARGET_DIVIDE_CALL_FP)
2449     {
2450       function_symbol (operands[3], "__udivsi3_i4", SFUNC_STATIC);
2451       if (TARGET_FPU_SINGLE)
2452         last = gen_udivsi3_i4_single (operands[0], operands[3]);
2453       else
2454         last = gen_udivsi3_i4 (operands[0], operands[3]);
2455     }
2456   else if (TARGET_SHMEDIA_FPU)
2457     {
2458       operands[1] = force_reg (SImode, operands[1]);
2459       operands[2] = force_reg (SImode, operands[2]);
2460       emit_insn (gen_udivsi3_i4_media (operands[0], operands[1], operands[2]));
2461       DONE;
2462     }
2463   else if (TARGET_SH2A)
2464     {
2465       operands[1] = force_reg (SImode, operands[1]);
2466       operands[2] = force_reg (SImode, operands[2]);
2467       emit_insn (gen_udivsi3_sh2a (operands[0], operands[1], operands[2]));
2468       DONE;
2469     }
2470   else if (TARGET_SH5)
2471     {
2472       function_symbol (operands[3],
2473                        TARGET_FPU_ANY ? "__udivsi3_i4" : "__udivsi3",
2474                        SFUNC_STATIC);
2476       if (TARGET_SHMEDIA)
2477         last = gen_udivsi3_i1_media (operands[0], operands[3]);
2478       else if (TARGET_FPU_ANY)
2479         last = gen_udivsi3_i4_single (operands[0], operands[3]);
2480       else
2481         last = gen_udivsi3_i1 (operands[0], operands[3]);
2482     }
2483   else
2484     {
2485       function_symbol (operands[3], "__udivsi3", SFUNC_STATIC);
2486       last = gen_udivsi3_i1 (operands[0], operands[3]);
2487     }
2488   emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
2489   emit_move_insn (gen_rtx_REG (SImode, 5), operands[2]);
2490   emit_insn (last);
2491   DONE;
2494 (define_insn "divsi3_sh2a"
2495   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
2496         (div:SI (match_operand:SI 1 "arith_reg_operand" "0")
2497                 (match_operand:SI 2 "arith_reg_operand" "z")))]
2498   "TARGET_SH2A"
2499   "divs %2,%1"
2500   [(set_attr "type" "arith")
2501    (set_attr "in_delay_slot" "no")])
2503 (define_insn "divsi3_i1"
2504   [(set (match_operand:SI 0 "register_operand" "=z")
2505         (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2506    (clobber (reg:SI T_REG))
2507    (clobber (reg:SI PR_REG))
2508    (clobber (reg:SI R1_REG))
2509    (clobber (reg:SI R2_REG))
2510    (clobber (reg:SI R3_REG))
2511    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2512   "TARGET_SH1 && TARGET_DIVIDE_CALL_DIV1"
2513   "jsr  @%1%#"
2514   [(set_attr "type" "sfunc")
2515    (set_attr "needs_delay_slot" "yes")])
2517 (define_insn "divsi3_i1_media"
2518   [(set (match_operand:SI 0 "register_operand" "=z")
2519         (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2520    (clobber (reg:SI T_MEDIA_REG))
2521    (clobber (reg:SI PR_MEDIA_REG))
2522    (clobber (reg:SI R1_REG))
2523    (clobber (reg:SI R20_REG))
2524    (clobber (reg:SI R21_REG))
2525    (clobber (reg:SI TR0_REG))
2526    (use (match_operand 1 "target_reg_operand" "b"))]
2527   "TARGET_SHMEDIA && (! TARGET_SHMEDIA_FPU || ! TARGET_DIVIDE_FP)"
2528   "blink        %1, r18"
2529   [(set_attr "type" "sfunc")])
2531 (define_insn "divsi3_media_2"
2532   [(set (match_operand:SI 0 "register_operand" "=z")
2533         (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2534    (clobber (reg:SI T_MEDIA_REG))
2535    (clobber (reg:SI PR_MEDIA_REG))
2536    (clobber (reg:SI R1_REG))
2537    (clobber (reg:SI R21_REG))
2538    (clobber (reg:SI TR0_REG))
2539    (use (reg:SI R20_REG))
2540    (use (match_operand 1 "target_reg_operand" "b"))]
2541   "TARGET_SHMEDIA && (! TARGET_SHMEDIA_FPU || ! TARGET_DIVIDE_FP)"
2542   "blink        %1, r18"
2543   [(set_attr "type" "sfunc")])
2545 ;; This pattern acts as a placeholder for -mdiv=inv:call to carry
2546 ;; hard reg clobbers and data dependencies that we need when we want
2547 ;; to rematerialize the division into a call.
2548 (define_insn_and_split "divsi_inv_call"
2549   [(set (match_operand:SI 0 "register_operand" "=r")
2550         (div:SI (match_operand:SI 1 "register_operand" "r")
2551                 (match_operand:SI 2 "register_operand" "r")))
2552    (clobber (reg:SI R4_REG))
2553    (clobber (reg:SI R5_REG))
2554    (clobber (reg:SI T_MEDIA_REG))
2555    (clobber (reg:SI PR_MEDIA_REG))
2556    (clobber (reg:SI R1_REG))
2557    (clobber (reg:SI R21_REG))
2558    (clobber (reg:SI TR0_REG))
2559    (clobber (reg:SI R20_REG))
2560    (use (match_operand:SI 3 "register_operand" "r"))]
2561   "TARGET_SHMEDIA"
2562   "#"
2563   "&& (reload_in_progress || reload_completed)"
2564   [(set (match_dup 0) (match_dup 3))]
2565   ""
2566   [(set_attr "highpart" "must_split")])
2568 ;; This is the combiner pattern for -mdiv=inv:call .
2569 (define_insn_and_split "*divsi_inv_call_combine"
2570   [(set (match_operand:SI 0 "register_operand" "=z")
2571         (div:SI (match_operand:SI 1 "register_operand" "r")
2572                 (match_operand:SI 2 "register_operand" "r")))
2573    (clobber (reg:SI R4_REG))
2574    (clobber (reg:SI R5_REG))
2575    (clobber (reg:SI T_MEDIA_REG))
2576    (clobber (reg:SI PR_MEDIA_REG))
2577    (clobber (reg:SI R1_REG))
2578    (clobber (reg:SI R21_REG))
2579    (clobber (reg:SI TR0_REG))
2580    (clobber (reg:SI R20_REG))
2581    (use (unspec:SI [(match_dup 1)
2582                     (match_operand:SI 3 "" "")
2583                     (unspec:SI [(match_operand:SI 4 "" "")
2584                                 (match_dup 3)
2585                                 (match_operand:DI 5 "" "")]
2586                      UNSPEC_DIV_INV_M2)
2587                     (match_operand:DI 6 "" "")
2588                     (const_int 0)
2589                     (const_int 0)]
2590          UNSPEC_DIV_INV_M3))]
2591   "TARGET_SHMEDIA"
2592   "#"
2593   "&& (reload_in_progress || reload_completed)"
2594   [(pc)]
2596   const char *name = sh_divsi3_libfunc;
2597   enum sh_function_kind kind = SFUNC_GOT;
2598   rtx sym;
2600   emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
2601   emit_move_insn (gen_rtx_REG (SImode, R5_REG), operands[2]);
2602   while (TARGET_DIVIDE_INV_CALL2)
2603     {
2604       rtx x = operands[3];
2606       if (GET_CODE (x) != UNSPEC || XINT (x, 1) != UNSPEC_DIV_INV_M1)
2607         break;
2608       x = XVECEXP (x, 0, 0);
2609       name = "__sdivsi3_2";
2610       kind = SFUNC_STATIC;
2611       emit_move_insn (gen_rtx_REG (DImode, R20_REG), x);
2612       break;
2613     }
2614   sym = function_symbol (NULL, name, kind);
2615   emit_insn (gen_divsi3_media_2 (operands[0], sym));
2616   DONE;
2618   [(set_attr "highpart" "must_split")])
2620 (define_expand "divsi3_i4_media"
2621   [(set (match_dup 3) (float:DF (match_operand:SI 1 "register_operand" "r")))
2622    (set (match_dup 4) (float:DF (match_operand:SI 2 "register_operand" "r")))
2623    (set (match_dup 5) (div:DF (match_dup 3) (match_dup 4)))
2624    (set (match_operand:SI 0 "register_operand" "=r")
2625         (fix:SI (match_dup 5)))]
2626   "TARGET_SHMEDIA_FPU"
2628   operands[3] = gen_reg_rtx (DFmode);
2629   operands[4] = gen_reg_rtx (DFmode);
2630   operands[5] = gen_reg_rtx (DFmode);
2633 (define_insn "divsi3_i4"
2634   [(set (match_operand:SI 0 "register_operand" "=y")
2635         (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2636    (clobber (reg:SI PR_REG))
2637    (clobber (reg:DF DR0_REG))
2638    (clobber (reg:DF DR2_REG))
2639    (clobber (reg:SI FPSCR_STAT_REG))
2640    (use (reg:SI FPSCR_MODES_REG))
2641    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2642   "TARGET_FPU_DOUBLE && ! TARGET_FPU_SINGLE"
2643   "jsr  @%1%#"
2644   [(set_attr "type" "sfunc")
2645    (set_attr "fp_mode" "double")
2646    (set_attr "needs_delay_slot" "yes")])
2648 (define_insn "divsi3_i4_single"
2649   [(set (match_operand:SI 0 "register_operand" "=y")
2650         (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2651    (clobber (reg:SI PR_REG))
2652    (clobber (reg:DF DR0_REG))
2653    (clobber (reg:DF DR2_REG))
2654    (clobber (reg:SI R2_REG))
2655    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2656   "(TARGET_FPU_SINGLE_ONLY || TARGET_FPU_DOUBLE || TARGET_SHCOMPACT)
2657    && TARGET_FPU_SINGLE"
2658   "jsr  @%1%#"
2659   [(set_attr "type" "sfunc")
2660    (set_attr "needs_delay_slot" "yes")])
2662 (define_insn "divsi3_i4_int"
2663   [(set (match_operand:SI 0 "register_operand" "=z")
2664         (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
2665    (clobber (reg:SI T_REG))
2666    (clobber (reg:SI PR_REG))
2667    (clobber (reg:SI R1_REG))
2668    (clobber (reg:SI MACH_REG))
2669    (clobber (reg:SI MACL_REG))
2670    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
2671   "TARGET_SH1"
2672   "jsr  @%1%#"
2673   [(set_attr "type" "sfunc")
2674    (set_attr "needs_delay_slot" "yes")])
2676 (define_expand "divsi3"
2677   [(set (match_dup 3) (symbol_ref:SI "__sdivsi3"))
2678    (set (reg:SI R4_REG) (match_operand:SI 1 "general_operand" ""))
2679    (set (reg:SI R5_REG) (match_operand:SI 2 "general_operand" ""))
2680    (parallel [(set (match_operand:SI 0 "register_operand" "")
2681                    (div:SI (reg:SI R4_REG)
2682                            (reg:SI R5_REG)))
2683               (clobber (reg:SI T_REG))
2684               (clobber (reg:SI PR_REG))
2685               (clobber (reg:SI R1_REG))
2686               (clobber (reg:SI R2_REG))
2687               (clobber (reg:SI R3_REG))
2688               (use (match_dup 3))])]
2689   ""
2691   rtx last;
2693   operands[3] = gen_reg_rtx (Pmode);
2694   /* Emit the move of the address to a pseudo outside of the libcall.  */
2695   if (TARGET_DIVIDE_CALL_TABLE)
2696     {
2697       function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
2698       last = gen_divsi3_i4_int (operands[0], operands[3]);
2699     }
2700   else if (TARGET_DIVIDE_CALL_FP)
2701     {
2702       function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_STATIC);
2703       if (TARGET_FPU_SINGLE)
2704         last = gen_divsi3_i4_single (operands[0], operands[3]);
2705       else
2706         last = gen_divsi3_i4 (operands[0], operands[3]);
2707     }
2708   else if (TARGET_SH2A)
2709     {
2710       operands[1] = force_reg (SImode, operands[1]);
2711       operands[2] = force_reg (SImode, operands[2]);
2712       emit_insn (gen_divsi3_sh2a (operands[0], operands[1], operands[2]));
2713       DONE;
2714     }
2715   else if (TARGET_DIVIDE_INV)
2716     {
2717       rtx dividend = operands[1];
2718       rtx divisor = operands[2];
2719       rtx tab_base;
2720       rtx nsb_res = gen_reg_rtx (DImode);
2721       rtx norm64 = gen_reg_rtx (DImode);
2722       rtx tab_ix = gen_reg_rtx (DImode);
2723       rtx norm32 = gen_reg_rtx (SImode);
2724       rtx i92 = force_reg (DImode, GEN_INT (92));
2725       rtx scratch0a = gen_reg_rtx (DImode);
2726       rtx scratch0b = gen_reg_rtx (DImode);
2727       rtx inv0 = gen_reg_rtx (SImode);
2728       rtx scratch1a = gen_reg_rtx (DImode);
2729       rtx scratch1b = gen_reg_rtx (DImode);
2730       rtx shift = gen_reg_rtx (DImode);
2731       rtx i2p27, i43;
2732       rtx inv1 = gen_reg_rtx (SImode);
2733       rtx scratch2a = gen_reg_rtx (DImode);
2734       rtx scratch2b = gen_reg_rtx (SImode);
2735       rtx inv2 = gen_reg_rtx (SImode);
2736       rtx scratch3a = gen_reg_rtx (DImode);
2737       rtx scratch3b = gen_reg_rtx (DImode);
2738       rtx scratch3c = gen_reg_rtx (DImode);
2739       rtx scratch3d = gen_reg_rtx (SImode);
2740       rtx scratch3e = gen_reg_rtx (DImode);
2741       rtx result = gen_reg_rtx (SImode);
2743       if (! arith_reg_or_0_operand (dividend, SImode))
2744         dividend = force_reg (SImode, dividend);
2745       if (! arith_reg_operand (divisor, SImode))
2746         divisor = force_reg (SImode, divisor);
2747       if (flag_pic && Pmode != DImode)
2748         {
2749           tab_base = gen_rtx_SYMBOL_REF (Pmode, "__div_table");
2750           tab_base = gen_datalabel_ref (tab_base);
2751           tab_base = force_reg (DImode, gen_rtx_SIGN_EXTEND (DImode, tab_base));
2752         }
2753       else
2754         {
2755           tab_base = gen_rtx_SYMBOL_REF (DImode, "__div_table");
2756           tab_base = gen_datalabel_ref (tab_base);
2757           tab_base = force_reg (DImode, tab_base);
2758         }
2759       if (TARGET_DIVIDE_INV20U)
2760         i2p27 = force_reg (DImode, GEN_INT (-2 << 27));
2761       else
2762         i2p27 = GEN_INT (0);
2763       if (TARGET_DIVIDE_INV20U || TARGET_DIVIDE_INV20L)
2764         i43 = force_reg (DImode, GEN_INT (43));
2765       else
2766         i43 = GEN_INT (0);
2767       emit_insn (gen_nsbdi (nsb_res,
2768                             simplify_gen_subreg (DImode, divisor, SImode, 0)));
2769       emit_insn (gen_ashldi3_media (norm64,
2770                                     gen_rtx_SUBREG (DImode, divisor, 0),
2771                                     nsb_res));
2772       emit_insn (gen_ashrdi3_media (tab_ix, norm64, GEN_INT (58)));
2773       emit_insn (gen_ashrdisi3_media_high (norm32, norm64, GEN_INT (32)));
2774       emit_insn (gen_divsi_inv_m1 (inv1, tab_base, tab_ix, norm32,
2775                                    inv0, scratch0a, scratch0b,
2776                                    scratch1a, scratch1b));
2777       emit_insn (gen_subdi3 (shift, i92, nsb_res));
2778       emit_insn (gen_divsi_inv_m2 (inv2, norm32, inv1, i92,
2779                                    scratch2a));
2780       emit_insn (gen_divsi_inv_m3 (result, dividend, inv1, inv2, shift,
2781                                    i2p27, i43,
2782                                    scratch3a, scratch3b, scratch3c,
2783                                    scratch2a, scratch2b, scratch3d, scratch3e));
2784       if (TARGET_DIVIDE_INV_CALL || TARGET_DIVIDE_INV_CALL2)
2785         emit_insn (gen_divsi_inv_call (operands[0], dividend, divisor, result));
2786       else if (TARGET_DIVIDE_INV_FP)
2787         emit_insn (gen_divsi_inv_fp (operands[0], dividend, divisor, result,
2788                                      gen_reg_rtx (SImode), gen_reg_rtx (SImode),
2789                                      gen_reg_rtx (DFmode), gen_reg_rtx (DFmode),
2790                                      gen_reg_rtx (DFmode)));
2791       else
2792         emit_move_insn (operands[0], result);
2793       DONE;
2794     }
2795   else if (TARGET_SHMEDIA_FPU && TARGET_DIVIDE_FP)
2796     {
2797       operands[1] = force_reg (SImode, operands[1]);
2798       operands[2] = force_reg (SImode, operands[2]);
2799       emit_insn (gen_divsi3_i4_media (operands[0], operands[1], operands[2]));
2800       DONE;
2801     }
2802   else if (TARGET_SH5)
2803     {
2804       if (TARGET_DIVIDE_CALL2)
2805         {
2806           rtx tab_base = gen_rtx_SYMBOL_REF (Pmode, "__div_table");
2807           tab_base = gen_datalabel_ref (tab_base);
2808           emit_move_insn (gen_rtx_REG (Pmode, R20_REG), tab_base);
2809         }
2810       if (TARGET_FPU_ANY && TARGET_SH1)
2811         function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_STATIC);
2812       else if (TARGET_DIVIDE_CALL2)
2813         function_symbol (operands[3], "__sdivsi3_2", SFUNC_STATIC);
2814       else
2815         function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
2817       if (TARGET_SHMEDIA)
2818         last = ((TARGET_DIVIDE_CALL2 ? gen_divsi3_media_2 : gen_divsi3_i1_media)
2819                 (operands[0], operands[3]));
2820       else if (TARGET_FPU_ANY)
2821         last = gen_divsi3_i4_single (operands[0], operands[3]);
2822       else
2823         last = gen_divsi3_i1 (operands[0], operands[3]);
2824     }
2825   else
2826     {
2827       function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
2828       last = gen_divsi3_i1 (operands[0], operands[3]);
2829     }
2830   emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
2831   emit_move_insn (gen_rtx_REG (SImode, 5), operands[2]);
2832   emit_insn (last);
2833   DONE;
2836 ;; operands: scratch, tab_base, tab_ix
2837 ;; These are unspecs because we could generate an indexed addressing mode
2838 ;; even if -m5-32media, where INDEX_REG_CLASS == NO_REGS, and this would
2839 ;; confuse reload.  See PR27117.
2840 (define_insn "divsi_inv_qitable"
2841   [(set (match_operand:DI 0 "register_operand" "=r")
2842         (zero_extend:DI (unspec:QI [(match_operand:DI 1 "register_operand" "r")
2843                                     (match_operand:DI 2 "register_operand" "r")]
2844                          UNSPEC_DIV_INV_TABLE)))]
2845   "TARGET_SHMEDIA"
2846   "ldx.ub       %1, %2, %0"
2847   [(set_attr "type" "load_media")
2848    (set_attr "highpart" "user")])
2850 ;; operands: scratch, tab_base, tab_ix
2851 (define_insn "divsi_inv_hitable"
2852   [(set (match_operand:DI 0 "register_operand" "=r")
2853         (sign_extend:DI (unspec:HI [(match_operand:DI 1 "register_operand" "r")
2854                                     (match_operand:DI 2 "register_operand" "r")]
2855                          UNSPEC_DIV_INV_TABLE)))]
2856   "TARGET_SHMEDIA"
2857   "ldx.w        %1, %2, %0"
2858   [(set_attr "type" "load_media")
2859    (set_attr "highpart" "user")])
2861 ;; operands: inv0, tab_base, tab_ix, norm32
2862 ;; scratch equiv in sdivsi3_2: r19, r21
2863 (define_expand "divsi_inv_m0"
2864   [(set (match_operand:SI 0 "register_operand" "=r")
2865         (unspec:SI [(match_operand:DI 1 "register_operand" "r")
2866                     (match_operand:DI 2 "register_operand" "r")
2867                     (match_operand:SI 3 "register_operand" "r")]
2868          UNSPEC_DIV_INV_M0))
2869    (clobber (match_operand:DI 4 "register_operand" "=r"))
2870    (clobber (match_operand:DI 5 "register_operand" "=r"))]
2871   "TARGET_SHMEDIA"
2874 tab_base: r20
2875 tab_ix: r21
2876 norm32: r25
2877  ldx.ub r20, r21, r19 // u0.8
2878  shlli r21, 1, r21
2879  muls.l r25, r19, r19 // s2.38
2880  ldx.w r20, r21, r21  // s2.14
2881  shari r19, 24, r19   // truncate to s2.14
2882  sub r21, r19, r19    // some 11 bit inverse in s1.14
2885   rtx inv0 = operands[0];
2886   rtx tab_base = operands[1];
2887   rtx tab_ix = operands[2];
2888   rtx norm32 = operands[3];
2889   rtx scratch0 = operands[4];
2890   rtx scratch0_si = gen_lowpart (SImode, scratch0);
2891   rtx scratch1 = operands[5];
2893   emit_insn (gen_divsi_inv_qitable (scratch0, tab_base, tab_ix));
2894   emit_insn (gen_ashldi3_media (scratch1, tab_ix, GEN_INT (1)));
2895   emit_insn (gen_mulsidi3_media (scratch0, norm32, scratch0_si));
2896   emit_insn (gen_divsi_inv_hitable (scratch1, tab_base, scratch1));
2897   emit_insn (gen_ashrdi3_media (scratch0, scratch0, GEN_INT (24)));
2898   emit_insn (gen_subdisi3_media (inv0, scratch1, scratch0));
2899   DONE;
2902 ;; operands: inv1, tab_base, tab_ix, norm32
2903 (define_insn_and_split "divsi_inv_m1"
2904   [(set (match_operand:SI 0 "register_operand" "=r")
2905         (unspec:SI [(match_operand:DI 1 "register_operand" "r")
2906                     (match_operand:DI 2 "register_operand" "r")
2907                     (match_operand:SI 3 "register_operand" "r")]
2908          UNSPEC_DIV_INV_M1))
2909    (clobber (match_operand:SI 4 "register_operand" "=r"))
2910    (clobber (match_operand:DI 5 "register_operand" "=r"))
2911    (clobber (match_operand:DI 6 "register_operand" "=r"))
2912    (clobber (match_operand:DI 7 "register_operand" "=r"))
2913    (clobber (match_operand:DI 8 "register_operand" "=r"))]
2914   "TARGET_SHMEDIA"
2915   "#"
2916   "&& !can_create_pseudo_p ()"
2917   [(pc)]
2919 /* inv0: r19
2920  muls.l r19, r19, r18 // u0.28
2921  muls.l r25, r18, r18 // s2.58
2922  shlli r19, 45, r0    // multiply by two and convert to s2.58
2923  sub r0, r18, r18
2924  shari r18, 28, r18   // some 18 bit inverse in s1.30
2927   rtx inv1 = operands[0];
2928   rtx tab_base = operands[1];
2929   rtx tab_ix = operands[2];
2930   rtx norm32 = operands[3];
2931   rtx inv0 = operands[4];
2932   rtx inv0_di = simplify_gen_subreg (DImode, inv0, SImode, 0);
2933   rtx scratch0a = operands[5];
2934   rtx scratch0b = operands[6];
2935   rtx scratch0 = operands[7];
2936   rtx scratch1 = operands[8];
2937   rtx scratch1_si = gen_lowpart (SImode, scratch1);
2939   emit_insn (gen_divsi_inv_m0 (inv0, tab_base, tab_ix, norm32,
2940                                scratch0a, scratch0b));
2941   emit_insn (gen_mulsidi3_media (scratch1, inv0, inv0));
2942   emit_insn (gen_mulsidi3_media (scratch1, norm32, scratch1_si));
2943   emit_insn (gen_ashldi3_media (scratch0, inv0_di, GEN_INT (45)));
2944   emit_insn (gen_subdi3 (scratch1, scratch0, scratch1));
2945   emit_insn (gen_ashrdisi3_media_opaque (inv1, scratch1, GEN_INT (28)));
2946   DONE;
2949 ;; operands: inv2, norm32, inv1, i92
2950 (define_insn_and_split "divsi_inv_m2"
2951   [(set (match_operand:SI 0 "register_operand" "=r")
2952         (unspec:SI [(match_operand:SI 1 "register_operand" "r")
2953                     (match_operand:SI 2 "register_operand" "r")
2954                     (match_operand:DI 3 "register_operand" "r")]
2955          UNSPEC_DIV_INV_M2))
2956    (clobber (match_operand:DI 4 "register_operand" "=r"))]
2957   "TARGET_SHMEDIA"
2958   "#"
2959   "&& !can_create_pseudo_p ()"
2960   [(pc)]
2963  muls.l r18, r25, r0  // s2.60
2964  shari r0, 16, r0     // s-16.44
2965   sub
2966  muls.l r0, r18, r19  // s-16.74
2967  shari r19, 30, r19   // s-16.44
2969   rtx inv2 = operands[0];
2970   rtx norm32 = operands[1];
2971   rtx inv1 = operands[2];
2972   rtx i92 = operands[3];
2973   rtx scratch0 = operands[4];
2974   rtx scratch0_si = gen_lowpart (SImode, scratch0);
2976   emit_insn (gen_mulsidi3_media (scratch0, inv1, norm32));
2977   emit_insn (gen_ashrdi3_media (scratch0, scratch0, GEN_INT (16)));
2978   emit_insn (gen_subdi3 (scratch0, i92, scratch0));
2979   emit_insn (gen_mulsidi3_media (scratch0, scratch0_si, inv1));
2980   emit_insn (gen_ashrdisi3_media_opaque (inv2, scratch0, GEN_INT (30)));
2981   DONE;
2984 (define_insn_and_split "divsi_inv_m3"
2985   [(set (match_operand:SI 0 "register_operand" "=r")
2986         (unspec:SI [(match_operand:SI 1 "arith_reg_or_0_operand" "rN")
2987                     (match_operand:SI 2 "register_operand" "r")
2988                     (match_operand:SI 3 "register_operand" "r")
2989                     (match_operand:DI 4 "register_operand" "r")
2990                     (match_operand:DI 5 "arith_reg_or_0_operand" "rN")
2991                     (match_operand:DI 6 "arith_reg_or_0_operand" "rN")]
2992          UNSPEC_DIV_INV_M3))
2993    (clobber (match_operand:DI 7 "register_operand" "=r"))
2994    (clobber (match_operand:DI 8 "register_operand" "=r"))
2995    (clobber (match_operand:DI 9 "register_operand" "=r"))
2996    (clobber (match_operand:DI 10 "register_operand" "=r"))
2997    (clobber (match_operand:SI 11 "register_operand" "=r"))
2998    (clobber (match_operand:SI 12 "register_operand" "=r"))
2999    (clobber (match_operand:DI 13 "register_operand" "=r"))]
3000   "TARGET_SHMEDIA"
3001   "#"
3002   "&& !can_create_pseudo_p ()"
3003   [(pc)]
3006   r0: result  r1: shift  r4: dividend  r18: inv1  r19: inv2
3007   r0: scratch0  r19: scratch1 r21: scratch2
3009   muls.l r18, r4, r25 // s32.30
3010  muls.l r19, r4, r19  // s15.30
3011  shari r25, 63, r21
3012   shari r19, 14, r19  // s18.-14
3013  sub r25, r19, r0
3014  shard r0, r1, r0
3015  sub r0, r21, r0
3018   rtx result = operands[0];
3019   rtx dividend = operands[1];
3020   rtx inv1 = operands[2];
3021   rtx inv2 = operands[3];
3022   rtx shift = operands[4];
3023   rtx scratch0 = operands[7];
3024   rtx scratch1 = operands[8];
3025   rtx scratch2 = operands[9];
3027   if (satisfies_constraint_N (dividend))
3028     {
3029       emit_move_insn (result, dividend);
3030       DONE;
3031     }
3033   emit_insn (gen_mulsidi3_media (scratch0, inv1, dividend));
3034   emit_insn (gen_mulsidi3_media (scratch1, inv2, dividend));
3035   emit_insn (gen_ashrdi3_media (scratch2, scratch0, GEN_INT (63)));
3036   emit_insn (gen_ashrdi3_media (scratch1, scratch1, GEN_INT (14)));
3037   emit_insn (gen_adddi3 (scratch0, scratch0, scratch1));
3038   emit_insn (gen_ashrdi3_media (scratch0, scratch0, shift));
3039   emit_insn (gen_subdisi3_media (result, scratch0, scratch2));
3040   DONE;
3043 ;; operands: quotient, dividend, inv1, inv2, shift, i2p27, i43
3044 ;; inv1: tab_base, tab_ix, norm32
3045 ;; inv2: norm32, inv1, i92
3046 (define_insn_and_split "divsi_inv_m1_3"
3047   [(set (match_operand:SI 0 "register_operand" "=r")
3048         (unspec:SI [(match_operand:SI 1 "arith_reg_or_0_operand" "rN")
3049                     (unspec:SI [(match_operand:DI 2 "register_operand" "r")
3050                                 (match_operand:DI 3 "register_operand" "r")
3051                                 (match_operand:SI 4 "register_operand" "r")]
3052                      UNSPEC_DIV_INV_M1)
3053                     (unspec:SI [(match_dup 4)
3054                                 (unspec:SI [(match_dup 2)
3055                                             (match_dup 3)
3056                                             (match_dup 4)] UNSPEC_DIV_INV_M1)
3057                                 (match_operand:SI 5 "" "")]
3058                      UNSPEC_DIV_INV_M2)
3059                     (match_operand:DI 6 "register_operand" "r")
3060                     (match_operand:DI 7 "arith_reg_or_0_operand" "rN")
3061                     (match_operand:DI 8 "arith_reg_or_0_operand" "rN")]
3062          UNSPEC_DIV_INV_M3))
3063    (clobber (match_operand:DI 9 "register_operand" "=r"))
3064    (clobber (match_operand:DI 10 "register_operand" "=r"))
3065    (clobber (match_operand:DI 11 "register_operand" "=r"))
3066    (clobber (match_operand:DI 12 "register_operand" "=r"))
3067    (clobber (match_operand:SI 13 "register_operand" "=r"))
3068    (clobber (match_operand:SI 14 "register_operand" "=r"))
3069    (clobber (match_operand:DI 15 "register_operand" "=r"))]
3070   "TARGET_SHMEDIA
3071    && (TARGET_DIVIDE_INV_MINLAT
3072        || TARGET_DIVIDE_INV20U || TARGET_DIVIDE_INV20L)"
3073   "#"
3074   "&& !can_create_pseudo_p ()"
3075   [(pc)]
3077   rtx result = operands[0];
3078   rtx dividend = operands[1];
3079   rtx tab_base = operands[2];
3080   rtx tab_ix = operands[3];
3081   rtx norm32 = operands[4];
3082   /* rtx i92 = operands[5]; */
3083   rtx shift = operands[6];
3084   rtx i2p27 = operands[7];
3085   rtx i43 = operands[8];
3086   rtx scratch0 = operands[9];
3087   rtx scratch0_si = gen_lowpart (SImode, scratch0);
3088   rtx scratch1 = operands[10];
3089   rtx scratch1_si = gen_lowpart (SImode, scratch1);
3090   rtx scratch2 = operands[11];
3091   rtx scratch3 = operands[12];
3092   rtx scratch4 = operands[13];
3093   rtx scratch4_di = simplify_gen_subreg (DImode, scratch4, SImode, 0);
3094   rtx scratch5 = operands[14];
3095   rtx scratch5_di = simplify_gen_subreg (DImode, scratch5, SImode, 0);
3096   rtx scratch6 = operands[15];
3098   emit_insn (gen_divsi_inv_m0 (scratch4, tab_base, tab_ix, norm32,
3099                                scratch0, scratch1));
3100   /* inv0 == scratch4 */
3101   if (! TARGET_DIVIDE_INV20U)
3102     {
3103       emit_insn (gen_mulsidi3_media (scratch0, scratch4, scratch4));
3104       i2p27 = scratch0;
3105       emit_insn (gen_mulsidi3_media (scratch1, norm32, scratch0_si));
3106     }
3107   else
3108     {
3109       emit_insn (gen_mulsidi3_media (scratch1, scratch4, scratch4));
3110       emit_insn (gen_mulsidi3_media (scratch1, norm32, scratch1_si));
3111     }
3112   emit_insn (gen_ashldi3_media (scratch2, scratch4_di, GEN_INT (45)));
3113   emit_insn (gen_subdi3 (scratch1, scratch2, scratch1));
3114   emit_insn (gen_ashrdisi3_media_opaque (scratch4, scratch1, GEN_INT (28)));
3115   /* inv1 == scratch4 */
3117   if (TARGET_DIVIDE_INV_MINLAT)
3118     {
3119       emit_insn (gen_mulsidi3_media (scratch1, scratch4, norm32));
3120       emit_insn (gen_mulsidi3_media (scratch2, dividend, scratch4));
3121       emit_insn (gen_ashrdi3_media (scratch1, scratch1, GEN_INT (16)));
3122       emit_insn (gen_mulsidi3_media (scratch1, scratch1_si, scratch4));
3123       emit_insn (gen_ashrdi3_media (scratch3, scratch2, GEN_INT (63)));
3124       emit_insn (gen_ashrsi3_media (scratch5, dividend, GEN_INT (14)));
3125       emit_insn (gen_ashrdi3_media (scratch1, scratch1, GEN_INT (30)));
3126       emit_insn (gen_mulsidi3_media (scratch1, scratch1_si, scratch5));
3127       emit_insn (gen_xordi3 (scratch0, scratch3, i2p27));
3128       emit_insn (gen_adddi3 (scratch2, scratch2, scratch0));
3129       emit_insn (gen_subdi3 (scratch2, scratch2, scratch1));
3130     }
3131   else
3132     {
3133       rtx label = gen_rtx_LABEL_REF (Pmode, gen_label_rtx ());
3134       /* Use separate scratch regs for nsb and sign to allow scheduling.  */
3135       emit_insn (gen_nsbdi (scratch6,
3136                             simplify_gen_subreg (DImode, dividend, SImode, 0)));
3137       emit_insn (gen_xorsi3 (scratch5, dividend, norm32));
3138       emit_insn (gen_ashrdi3_media (scratch3, scratch5_di, GEN_INT (63)));
3139       emit_insn (gen_divsi_inv20 (scratch2,
3140                                   norm32, scratch4, dividend,
3141                                   scratch6, scratch3, i43,
3142                                   /* scratch0 may be shared with i2p27.  */
3143                                   scratch0, scratch1, scratch5,
3144                                   label, label, i2p27));
3145     }
3146   emit_insn (gen_ashrdi3_media (scratch2, scratch2, shift));
3147   emit_insn (gen_subdisi3_media (result, scratch2, scratch3));
3148   DONE;
3151 (define_insn "divsi_inv20"
3152   [(set (match_operand:DI 0 "register_operand" "=&r")
3153         (unspec:DI [(match_operand:SI 1 "register_operand" "r")
3154                     (match_operand:SI 2 "register_operand" "r")
3155                     (match_operand:SI 3 "register_operand" "r")
3156                     (match_operand:DI 4 "register_operand" "r")
3157                     (match_operand:DI 5 "register_operand" "r")
3158                     (match_operand:DI 6 "register_operand" "r")
3159                     (match_operand:DI 12 "register_operand" "r")
3160                     (match_operand 10 "target_operand" "b")
3161                     (match_operand 11 "immediate_operand" "i")]
3162          UNSPEC_DIV_INV20))
3163    (clobber (match_operand:DI 7 "register_operand" "=&r"))
3164    (clobber (match_operand:DI 8 "register_operand" "=&r"))
3165    (clobber (match_operand:SI 9 "register_operand" "=r"))]
3166   "TARGET_SHMEDIA
3167    && (TARGET_DIVIDE_INV20U || TARGET_DIVIDE_INV20L)"
3169 /* operands: %0 div_result, %1 norm32, %2 inv1, %3 dividend,
3170              %4 dividend_nsb, %5 result_sign, %6 i43, %12 i2p27,
3171              %7 round_scratch, %8 scratch0 (di), %9 scratch1 (si)
3172              %10 label (tr), %11 label (imm)
3174  muls.l inv1, norm32, scratch0  // s2.60
3175   muls.l inv1, dividend, result // s32.30
3176   xor i2p27, result_sign, round_scratch
3177  bge/u dividend_nsb, i43, tr.. (label)
3178  shari scratch0, 16, scratch0   // s-16.44
3179  muls.l sratch0_si, inv1, scratch0 // s-16.74
3180   sub result, round_scratch, result
3181   shari dividend, 14, scratch1   // s19.-14
3182  shari scratch0, 30, scratch0   // s-16.44
3183  muls.l scratch0, scratch1, round_scratch // s15.30
3184 label:
3185  sub result, round_scratch, result */
3187   const bool likely = TARGET_DIVIDE_INV20L;
3188   if (likely)
3189     return
3190                "muls.l  %2, %3, %0"     "\n"
3191         "       xor     %12, %5, %7"    "\n"
3192         "       bge/l   %4, %6, %10"    "\n"
3193         "       muls.l  %2, %1, %8"     "\n"
3194         "       shari   %8, 16, %8"     "\n"
3195         "       muls.l  %8, %2, %8"     "\n"
3196         "       shari   %3, 14, %9"     "\n"
3197         "       shari   %8, 30, %8"     "\n"
3198         "       muls.l  %8, %9, %8"     "\n"
3199         "       sub     %0, %8, %0"     "\n"
3200         "%11:   add     %0, %7, %0";
3201   else
3202     return
3203                "muls.l  %2, %1, %8"     "\n"
3204         "       muls.l  %2, %3, %0"     "\n"
3205         "       xor     %12, %5, %7"    "\n"
3206         "       bge/u   %4, %6, %10"    "\n"
3207         "       shari   %8, 16, %8"     "\n"
3208         "       muls.l  %8, %2, %8"     "\n"
3209         "       sub     %0, %7, %0"     "\n"
3210         "       shari   %3, 14, %9"     "\n"
3211         "       shari   %8, 30, %8"     "\n"
3212         "       muls.l  %8, %9, %7"     "\n"
3213         "%11:   sub     %0, %7, %0";
3216 (define_insn_and_split "divsi_inv_fp"
3217   [(set (match_operand:SI 0 "general_movdst_operand" "=rf")
3218         (div:SI (match_operand:SI 1 "general_movsrc_operand" "rf")
3219                 (match_operand:SI 2 "register_operand" "rf")))
3220    (use (match_operand:SI 3 "general_movsrc_operand" "r"))
3221    (clobber (match_operand:SI 4 "register_operand" "=r"))
3222    (clobber (match_operand:SI 5 "register_operand" "=r"))
3223    (clobber (match_operand:DF 6 "register_operand" "=r"))
3224    (clobber (match_operand:DF 7 "register_operand" "=r"))
3225    (clobber (match_operand:DF 8 "register_operand" "=r"))]
3226   "TARGET_SHMEDIA_FPU"
3227   "#"
3228   "&& (reload_in_progress || reload_completed)"
3229   [(set (match_dup 0) (match_dup 3))]
3230   ""
3231   [(set_attr "highpart" "must_split")])
3233 ;; If a matching group of divide-by-inverse instructions is in the same
3234 ;; basic block after gcse & loop optimizations, we want to transform them
3235 ;; to a straight division using floating point for TARGET_DIVIDE_INV_FP.
3236 (define_insn_and_split "*divsi_inv_fp_combine"
3237   [(set (match_operand:SI 0 "register_operand" "=f")
3238         (div:SI (match_operand:SI 1 "register_operand" "f")
3239                 (match_operand:SI 2 "register_operand" "f")))
3240    (use (unspec:SI [(match_dup 1)
3241                     (match_operand:SI 3 "" "")
3242                     (unspec:SI [(match_operand:SI 4 "" "")
3243                                 (match_dup 3)
3244                                 (match_operand:DI 5 "" "")] UNSPEC_DIV_INV_M2)
3245                     (match_operand:DI 6 "" "")
3246                     (const_int 0)
3247                     (const_int 0)] UNSPEC_DIV_INV_M3))
3248    (clobber (match_operand:SI 7 "fp_arith_reg_operand" ""))
3249    (clobber (match_operand:SI 8 "fp_arith_reg_operand" ""))
3250    (clobber (match_operand:DF 9 "fp_arith_reg_operand" ""))
3251    (clobber (match_operand:DF 10 "fp_arith_reg_operand" ""))
3252    (clobber (match_operand:DF 11 "fp_arith_reg_operand" ""))]
3253   "TARGET_SHMEDIA_FPU && TARGET_DIVIDE_INV_FP && !can_create_pseudo_p ()"
3254   "#"
3255   "&& 1"
3256   [(set (match_dup 9) (float:DF (match_dup 1)))
3257    (set (match_dup 10) (float:DF (match_dup 2)))
3258    (set (match_dup 11) (div:DF (match_dup 9) (match_dup 10)))
3259    (set (match_dup 8)
3260         (fix:SI (match_dup 11)))
3261    (set (match_dup 0) (match_dup 8))]
3263   if (! fp_arith_reg_operand (operands[1], SImode))
3264     {
3265       emit_move_insn (operands[7], operands[1]);
3266       operands[1] = operands[7];
3267     }
3268   if (! fp_arith_reg_operand (operands[2], SImode))
3269     {
3270       emit_move_insn (operands[8], operands[2]);
3271       operands[2] = operands[8];
3272     }
3274   [(set_attr "highpart" "must_split")])
3276 ;; -------------------------------------------------------------------------
3277 ;; Multiplication instructions
3278 ;; -------------------------------------------------------------------------
3280 (define_insn "umulhisi3_i"
3281   [(set (reg:SI MACL_REG)
3282         (mult:SI (zero_extend:SI
3283                   (match_operand:HI 0 "arith_reg_operand" "r"))
3284                  (zero_extend:SI
3285                   (match_operand:HI 1 "arith_reg_operand" "r"))))]
3286   "TARGET_SH1"
3287   "mulu.w       %1,%0"
3288   [(set_attr "type" "smpy")])
3290 (define_insn "mulhisi3_i"
3291   [(set (reg:SI MACL_REG)
3292         (mult:SI (sign_extend:SI
3293                   (match_operand:HI 0 "arith_reg_operand" "r"))
3294                  (sign_extend:SI
3295                   (match_operand:HI 1 "arith_reg_operand" "r"))))]
3296   "TARGET_SH1"
3297   "muls.w       %1,%0"
3298   [(set_attr "type" "smpy")])
3300 (define_expand "mulhisi3"
3301   [(set (reg:SI MACL_REG)
3302         (mult:SI (sign_extend:SI
3303                   (match_operand:HI 1 "arith_reg_operand" ""))
3304                  (sign_extend:SI
3305                   (match_operand:HI 2 "arith_reg_operand" ""))))
3306    (set (match_operand:SI 0 "arith_reg_operand" "")
3307         (reg:SI MACL_REG))]
3308   "TARGET_SH1"
3310   rtx_insn *insn;
3311   rtx macl;
3313   macl = gen_rtx_REG (SImode, MACL_REG);
3314   start_sequence ();
3315   emit_insn (gen_mulhisi3_i (operands[1], operands[2]));
3316   insn = get_insns ();  
3317   end_sequence ();
3318   /* expand_binop can't find a suitable code in umul_widen_optab to
3319      make a REG_EQUAL note from, so make one here.
3320      See also smulsi3_highpart.
3321      ??? Alternatively, we could put this at the calling site of expand_binop,
3322      i.e. expand_expr.  */
3323   /* Use emit_libcall_block for loop invariant code motion and to make
3324      a REG_EQUAL note.  */
3325   emit_libcall_block (insn, operands[0], macl, SET_SRC (single_set (insn)));
3327   DONE;
3330 (define_expand "umulhisi3"
3331   [(set (reg:SI MACL_REG)
3332         (mult:SI (zero_extend:SI
3333                   (match_operand:HI 1 "arith_reg_operand" ""))
3334                  (zero_extend:SI
3335                   (match_operand:HI 2 "arith_reg_operand" ""))))
3336    (set (match_operand:SI 0 "arith_reg_operand" "")
3337         (reg:SI MACL_REG))]
3338   "TARGET_SH1"
3340   rtx_insn *insn;
3341   rtx macl;
3343   macl = gen_rtx_REG (SImode, MACL_REG);
3344   start_sequence ();
3345   emit_insn (gen_umulhisi3_i (operands[1], operands[2]));
3346   insn = get_insns ();  
3347   end_sequence ();
3348   /* expand_binop can't find a suitable code in umul_widen_optab to
3349      make a REG_EQUAL note from, so make one here.
3350      See also smulsi3_highpart.
3351      ??? Alternatively, we could put this at the calling site of expand_binop,
3352      i.e. expand_expr.  */
3353   /* Use emit_libcall_block for loop invariant code motion and to make
3354      a REG_EQUAL note.  */
3355   emit_libcall_block (insn, operands[0], macl, SET_SRC (single_set (insn)));
3357   DONE;
3360 ;; mulsi3 on the SH2 can be done in one instruction, on the SH1 we generate
3361 ;; a call to a routine which clobbers known registers.
3362 (define_insn ""
3363   [(set (match_operand:SI 1 "register_operand" "=z")
3364         (mult:SI (reg:SI R4_REG) (reg:SI R5_REG)))
3365    (clobber (reg:SI MACL_REG))
3366    (clobber (reg:SI T_REG))
3367    (clobber (reg:SI PR_REG))
3368    (clobber (reg:SI R3_REG))
3369    (clobber (reg:SI R2_REG))
3370    (clobber (reg:SI R1_REG))
3371    (use (match_operand:SI 0 "arith_reg_operand" "r"))]
3372   "TARGET_SH1"
3373   "jsr  @%0%#"
3374   [(set_attr "type" "sfunc")
3375    (set_attr "needs_delay_slot" "yes")])
3377 (define_expand "mulsi3_call"
3378   [(set (reg:SI R4_REG) (match_operand:SI 1 "general_operand" ""))
3379    (set (reg:SI R5_REG) (match_operand:SI 2 "general_operand" ""))
3380    (parallel[(set (match_operand:SI 0 "register_operand" "")
3381                   (mult:SI (reg:SI R4_REG)
3382                            (reg:SI R5_REG)))
3383              (clobber (reg:SI MACL_REG))
3384              (clobber (reg:SI T_REG))
3385              (clobber (reg:SI PR_REG))
3386              (clobber (reg:SI R3_REG))
3387              (clobber (reg:SI R2_REG))
3388              (clobber (reg:SI R1_REG))
3389              (use (match_operand:SI 3 "register_operand" ""))])]
3390   "TARGET_SH1"
3391   "")
3393 (define_insn "mul_r"
3394   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3395         (mult:SI (match_operand:SI 1 "arith_reg_operand" "0")
3396                  (match_operand:SI 2 "arith_reg_operand" "z")))]
3397   "TARGET_SH2A"
3398   "mulr %2,%0"
3399   [(set_attr "type" "dmpy")])
3401 (define_insn "mul_l"
3402   [(set (reg:SI MACL_REG)
3403         (mult:SI (match_operand:SI 0 "arith_reg_operand" "r")
3404                  (match_operand:SI 1 "arith_reg_operand" "r")))]
3405   "TARGET_SH2"
3406   "mul.l        %1,%0"
3407   [(set_attr "type" "dmpy")])
3409 (define_expand "mulsi3"
3410   [(set (reg:SI MACL_REG)
3411         (mult:SI  (match_operand:SI 1 "arith_reg_operand" "")
3412                   (match_operand:SI 2 "arith_reg_operand" "")))
3413    (set (match_operand:SI 0 "arith_reg_operand" "")
3414         (reg:SI MACL_REG))]
3415   "TARGET_SH1"
3417   if (!TARGET_SH2)
3418     {
3419       /* The address must be set outside the libcall,
3420          since it goes into a pseudo.  */
3421       rtx sym = function_symbol (NULL, "__mulsi3", SFUNC_STATIC);
3422       rtx addr = force_reg (SImode, sym);
3423       rtx insns = gen_mulsi3_call (operands[0], operands[1],
3424                                    operands[2], addr);
3425       emit_insn (insns);
3426     }
3427   else
3428     {
3429       rtx macl = gen_rtx_REG (SImode, MACL_REG);
3431       emit_insn (gen_mul_l (operands[1], operands[2]));
3432       /* consec_sets_giv can only recognize the first insn that sets a
3433          giv as the giv insn.  So we must tag this also with a REG_EQUAL
3434          note.  */
3435       emit_insn (gen_movsi_i ((operands[0]), macl));
3436     }
3437   DONE;
3440 (define_insn "mulsidi3_i"
3441   [(set (reg:SI MACH_REG)
3442         (truncate:SI
3443          (lshiftrt:DI
3444           (mult:DI
3445            (sign_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
3446            (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
3447           (const_int 32))))
3448    (set (reg:SI MACL_REG)
3449         (mult:SI (match_dup 0)
3450                  (match_dup 1)))]
3451   "TARGET_SH2"
3452   "dmuls.l      %1,%0"
3453   [(set_attr "type" "dmpy")])
3455 (define_expand "mulsidi3"
3456   [(set (match_operand:DI 0 "arith_reg_dest" "")
3457         (mult:DI (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
3458                  (sign_extend:DI (match_operand:SI 2 "arith_reg_operand" ""))))]
3459   "TARGET_SH2 || TARGET_SHMEDIA"
3461   if (TARGET_SH2)
3462     {
3463       emit_insn (gen_mulsidi3_compact (operands[0], operands[1], operands[2]));
3464       DONE;
3465     }
3468 (define_insn "mulsidi3_media"
3469   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3470         (mult:DI (sign_extend:DI (match_operand:SI 1 "extend_reg_operand" "%r"))
3471                  (sign_extend:DI (match_operand:SI 2 "extend_reg_operand" "r"))))]
3472   "TARGET_SHMEDIA"
3473   "muls.l       %1, %2, %0"
3474   [(set_attr "type" "dmpy_media")
3475    (set_attr "highpart" "ignore")])
3477 (define_insn_and_split "mulsidi3_compact"
3478   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3479         (mult:DI
3480          (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r"))
3481          (sign_extend:DI (match_operand:SI 2 "arith_reg_operand" "r"))))
3482    (clobber (reg:SI MACH_REG))
3483    (clobber (reg:SI MACL_REG))]
3484   "TARGET_SH2"
3485   "#"
3486   "&& 1"
3487   [(const_int 0)]
3489   rtx low_dst = gen_lowpart (SImode, operands[0]);
3490   rtx high_dst = gen_highpart (SImode, operands[0]);
3492   emit_insn (gen_mulsidi3_i (operands[1], operands[2]));
3494   emit_move_insn (low_dst, gen_rtx_REG (SImode, MACL_REG));
3495   emit_move_insn (high_dst, gen_rtx_REG (SImode, MACH_REG));
3496   /* We need something to tag the possible REG_EQUAL notes on to.  */
3497   emit_move_insn (operands[0], operands[0]);
3498   DONE;
3501 (define_insn "umulsidi3_i"
3502   [(set (reg:SI MACH_REG)
3503         (truncate:SI
3504          (lshiftrt:DI
3505           (mult:DI
3506            (zero_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
3507            (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
3508           (const_int 32))))
3509    (set (reg:SI MACL_REG)
3510         (mult:SI (match_dup 0)
3511                  (match_dup 1)))]
3512   "TARGET_SH2"
3513   "dmulu.l      %1,%0"
3514   [(set_attr "type" "dmpy")])
3516 (define_expand "umulsidi3"
3517   [(set (match_operand:DI 0 "arith_reg_dest" "")
3518         (mult:DI (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
3519                  (zero_extend:DI (match_operand:SI 2 "arith_reg_operand" ""))))]
3520   "TARGET_SH2 || TARGET_SHMEDIA"
3522   if (TARGET_SH2)
3523     {
3524       emit_insn (gen_umulsidi3_compact (operands[0], operands[1], operands[2]));
3525       DONE;
3526     }
3529 (define_insn "umulsidi3_media"
3530   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3531         (mult:DI (zero_extend:DI (match_operand:SI 1 "extend_reg_operand" "%r"))
3532                  (zero_extend:DI (match_operand:SI 2 "extend_reg_operand" "r"))))]
3533   "TARGET_SHMEDIA"
3534   "mulu.l       %1, %2, %0"
3535   [(set_attr "type" "dmpy_media")
3536    (set_attr "highpart" "ignore")])
3538 (define_insn_and_split "umulsidi3_compact"
3539   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3540         (mult:DI
3541          (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r"))
3542          (zero_extend:DI (match_operand:SI 2 "arith_reg_operand" "r"))))
3543    (clobber (reg:SI MACH_REG))
3544    (clobber (reg:SI MACL_REG))]
3545   "TARGET_SH2"
3546   "#"
3547   "&& 1"
3548   [(const_int 0)]
3550   rtx low_dst = gen_lowpart (SImode, operands[0]);
3551   rtx high_dst = gen_highpart (SImode, operands[0]);
3553   emit_insn (gen_umulsidi3_i (operands[1], operands[2]));
3555   emit_move_insn (low_dst, gen_rtx_REG (SImode, MACL_REG));
3556   emit_move_insn (high_dst, gen_rtx_REG (SImode, MACH_REG));
3557   /* We need something to tag the possible REG_EQUAL notes on to.  */
3558   emit_move_insn (operands[0], operands[0]);
3559   DONE;
3562 (define_insn "smulsi3_highpart_i"
3563   [(set (reg:SI MACH_REG)
3564         (truncate:SI
3565          (lshiftrt:DI
3566           (mult:DI
3567            (sign_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
3568            (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
3569           (const_int 32))))
3570    (clobber (reg:SI MACL_REG))]
3571   "TARGET_SH2"
3572   "dmuls.l      %1,%0"
3573   [(set_attr "type" "dmpy")])
3575 (define_expand "smulsi3_highpart"
3576   [(parallel
3577     [(set (reg:SI MACH_REG)
3578           (truncate:SI
3579            (lshiftrt:DI
3580             (mult:DI
3581              (sign_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
3582              (sign_extend:DI (match_operand:SI 2 "arith_reg_operand" "")))
3583             (const_int 32))))
3584     (clobber (reg:SI MACL_REG))])
3585    (set (match_operand:SI 0 "arith_reg_operand" "")
3586         (reg:SI MACH_REG))]
3587   "TARGET_SH2"
3589   rtx_insn *insn;
3590   rtx mach;
3592   mach = gen_rtx_REG (SImode, MACH_REG);
3593   start_sequence ();
3594   emit_insn (gen_smulsi3_highpart_i (operands[1], operands[2]));
3595   insn = get_insns ();  
3596   end_sequence ();
3597   /* expand_binop can't find a suitable code in mul_highpart_optab to
3598      make a REG_EQUAL note from, so make one here.
3599      See also {,u}mulhisi.
3600      ??? Alternatively, we could put this at the calling site of expand_binop,
3601      i.e. expand_mult_highpart.  */
3602   /* Use emit_libcall_block for loop invariant code motion and to make
3603      a REG_EQUAL note.  */
3604   emit_libcall_block (insn, operands[0], mach, SET_SRC (single_set (insn)));
3606   DONE;
3609 (define_insn "umulsi3_highpart_i"
3610   [(set (reg:SI MACH_REG)
3611         (truncate:SI
3612          (lshiftrt:DI
3613           (mult:DI
3614            (zero_extend:DI (match_operand:SI 0 "arith_reg_operand" "r"))
3615            (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" "r")))
3616           (const_int 32))))
3617    (clobber (reg:SI MACL_REG))]
3618   "TARGET_SH2"
3619   "dmulu.l      %1,%0"
3620   [(set_attr "type" "dmpy")])
3622 (define_expand "umulsi3_highpart"
3623   [(parallel
3624     [(set (reg:SI MACH_REG)
3625           (truncate:SI
3626            (lshiftrt:DI
3627             (mult:DI
3628              (zero_extend:DI (match_operand:SI 1 "arith_reg_operand" ""))
3629              (zero_extend:DI (match_operand:SI 2 "arith_reg_operand" "")))
3630             (const_int 32))))
3631     (clobber (reg:SI MACL_REG))])
3632    (set (match_operand:SI 0 "arith_reg_operand" "")
3633         (reg:SI MACH_REG))]
3634   "TARGET_SH2"
3636   rtx_insn *insn;
3637   rtx mach;
3639   mach = gen_rtx_REG (SImode, MACH_REG);
3640   start_sequence ();
3641   emit_insn (gen_umulsi3_highpart_i (operands[1], operands[2]));
3642   insn = get_insns ();  
3643   end_sequence ();
3644   /* Use emit_libcall_block for loop invariant code motion and to make
3645      a REG_EQUAL note.  */
3646   emit_libcall_block (insn, operands[0], mach, SET_SRC (single_set (insn)));
3648   DONE;
3651 (define_insn_and_split "muldi3"
3652   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3653         (mult:DI (match_operand:DI 1 "arith_reg_operand" "r")
3654                  (match_operand:DI 2 "arith_reg_operand" "r")))
3655    (clobber (match_scratch:DI 3 "=&r"))
3656    (clobber (match_scratch:DI 4 "=r"))]
3657   "TARGET_SHMEDIA"
3658   "#"
3659   "reload_completed"
3660   [(const_int 0)]
3662   rtx op3_v2si, op2_v2si;
3664   op3_v2si = operands[3];
3665   if (GET_CODE (op3_v2si) == SIGN_EXTEND)
3666     {
3667       op3_v2si = XEXP (op3_v2si, 0);
3668       op3_v2si = simplify_gen_subreg (DImode, op3_v2si, GET_MODE (op3_v2si), 0);
3669     }
3670   op3_v2si = simplify_gen_subreg (V2SImode, op3_v2si, DImode, 0);
3671   op2_v2si = operands[2];
3672   if (GET_CODE (op2_v2si) == SIGN_EXTEND)
3673     {
3674       op2_v2si = XEXP (op2_v2si, 0);
3675       op2_v2si = simplify_gen_subreg (DImode, op2_v2si, GET_MODE (op2_v2si), 0);
3676     }
3677   op2_v2si = simplify_gen_subreg (V2SImode, op2_v2si, DImode, 0);
3678   emit_insn (gen_rotldi3 (operands[3], operands[1], GEN_INT (32)));
3679   emit_insn (gen_mulv2si3 (op3_v2si, op3_v2si, op2_v2si));
3680   emit_insn (gen_umulsidi3_media (operands[4],
3681                                  sh_gen_truncate (SImode, operands[1], 0),
3682                                  sh_gen_truncate (SImode, operands[2], 0)));
3683   emit_insn (gen_anddi3 (operands[0], operands[3], GEN_INT (0xffffffff00000000LL)));
3684   emit_insn (gen_ashldi3_media (operands[3], operands[3], GEN_INT (32)));
3685   emit_insn (gen_adddi3 (operands[0], operands[3], operands[0]));
3686   emit_insn (gen_adddi3 (operands[0], operands[4], operands[0]));
3687   DONE;
3690 ;; -------------------------------------------------------------------------
3691 ;; Logical operations
3692 ;; -------------------------------------------------------------------------
3694 (define_expand "andsi3"
3695   [(set (match_operand:SI 0 "arith_reg_operand" "")
3696         (and:SI (match_operand:SI 1 "logical_reg_operand" "")
3697                 (match_operand:SI 2 "logical_and_operand" "")))]
3698   ""
3700   /* If it is possible to turn the and insn into a zero extension
3701      already, redundant zero extensions will be folded, which results
3702      in better code.  
3703      Ideally the splitter of *andsi_compact would be enough, if redundant
3704      zero extensions were detected after the combine pass, which does not
3705      happen at the moment.  */
3706   if (TARGET_SH1)
3707     {
3708       if (satisfies_constraint_Jmb (operands[2]))
3709         {
3710           emit_insn (gen_zero_extendqisi2 (operands[0],
3711                                            gen_lowpart (QImode, operands[1])));
3712           DONE;
3713         }
3714       else if (satisfies_constraint_Jmw (operands[2]))
3715         {
3716           emit_insn (gen_zero_extendhisi2 (operands[0],
3717                                            gen_lowpart (HImode, operands[1])));
3718           DONE;
3719         }
3720     }
3723 (define_insn_and_split "*andsi_compact"
3724   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r,z,r")
3725         (and:SI (match_operand:SI 1 "arith_reg_operand" "%r,r,0,0")
3726                 (match_operand:SI 2 "logical_and_operand" "Jmb,Jmw,K08,r")))]
3727   "TARGET_SH1"
3728   "@
3729         extu.b  %1,%0
3730         extu.w  %1,%0
3731         and     %2,%0
3732         and     %2,%0"
3733   "&& 1"
3734  [(set (match_dup 0) (zero_extend:SI (match_dup 1)))]
3736   if (satisfies_constraint_Jmb (operands[2]))
3737     operands[1] = gen_lowpart (QImode, operands[1]);
3738   else if (satisfies_constraint_Jmw (operands[2]))
3739     operands[1] = gen_lowpart (HImode, operands[1]);
3740   else
3741     FAIL;
3743   [(set_attr "type" "arith")])
3745 (define_insn "*andsi3_media"
3746   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
3747         (and:SI (match_operand:SI 1 "logical_reg_operand" "%r,r")
3748                 (match_operand:SI 2 "logical_operand" "r,I10")))]
3749   "TARGET_SHMEDIA"
3750   "@
3751         and     %1, %2, %0
3752         andi    %1, %2, %0"
3753   [(set_attr "type" "arith_media")])
3755 (define_insn "*andsi3_bclr"
3756   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3757         (and:SI (match_operand:SI 1 "arith_reg_operand" "%0")
3758                 (match_operand:SI 2 "const_int_operand" "Psz")))]
3759   "TARGET_SH2A && satisfies_constraint_Psz (operands[2])"
3760   "bclr %W2,%0"
3761   [(set_attr "type" "arith")])
3763 (define_insn_and_split "anddi3"
3764   [(set (match_operand:DI 0 "arith_reg_dest" "=r,r,r")
3765         (and:DI (match_operand:DI 1 "arith_reg_operand" "%r,r,r")
3766                 (match_operand:DI 2 "and_operand" "r,I10,J16")))]
3767   "TARGET_SHMEDIA"
3768   "@
3769         and     %1, %2, %0
3770         andi    %1, %2, %0
3771         #"
3772   "reload_completed
3773    && ! logical_operand (operands[2], DImode)"
3774   [(const_int 0)]
3776   if ((unsigned)INTVAL (operands[2]) == (unsigned) 0xffffffff)
3777     emit_insn (gen_mshflo_l_di (operands[0], operands[1], CONST0_RTX (DImode)));
3778   else
3779     emit_insn (gen_mshfhi_l_di (operands[0], CONST0_RTX (DImode), operands[1]));
3780   DONE;
3782   [(set_attr "type" "arith_media")])
3784 (define_insn "andcsi3"
3785   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3786         (and:SI (match_operand:SI 1 "arith_reg_operand" "r")
3787                 (not:SI (match_operand:SI 2 "arith_reg_operand" "r"))))]
3788   "TARGET_SHMEDIA"
3789   "andc %1,%2,%0"
3790   [(set_attr "type" "arith_media")])
3792 (define_insn "andcdi3"
3793   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3794         (and:DI (match_operand:DI 1 "arith_reg_operand" "r")
3795                 (not:DI (match_operand:DI 2 "arith_reg_operand" "r"))))]
3796   "TARGET_SHMEDIA"
3797   "andc %1,%2,%0"
3798   [(set_attr "type" "arith_media")])
3800 (define_expand "iorsi3"
3801   [(set (match_operand:SI 0 "arith_reg_operand" "")
3802         (ior:SI (match_operand:SI 1 "logical_reg_operand" "")
3803                 (match_operand:SI 2 "logical_operand" "")))]
3804   ""
3805   "")
3807 (define_insn "*iorsi3_compact"
3808   [(set (match_operand:SI 0 "arith_reg_dest" "=r,z")
3809         (ior:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
3810                 (match_operand:SI 2 "logical_operand" "r,K08")))]
3811   "TARGET_SH1
3812    && !(TARGET_SH2A && satisfies_constraint_Pso (operands[2]))"
3813   "or   %2,%0"
3814   [(set_attr "type" "arith")])
3816 (define_insn "*iorsi3_media"
3817   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
3818         (ior:SI (match_operand:SI 1 "logical_reg_operand" "%r,r")
3819                 (match_operand:SI 2 "logical_operand" "r,I10")))]
3820   "TARGET_SHMEDIA"
3821   "@
3822         or      %1, %2, %0
3823         ori     %1, %2, %0"
3824   [(set_attr "type" "arith_media")])
3826 (define_insn "*iorsi3_bset"
3827   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
3828         (ior:SI (match_operand:SI 1 "arith_reg_operand" "%0")
3829         (match_operand:SI 2 "const_int_operand" "Pso")))]
3830   "TARGET_SH2A && satisfies_constraint_Pso (operands[2])"
3831   "bset %V2,%0"
3832   [(set_attr "type" "arith")])
3834 (define_insn "iordi3"
3835   [(set (match_operand:DI 0 "arith_reg_dest" "=r,r")
3836         (ior:DI (match_operand:DI 1 "arith_reg_operand" "%r,r")
3837                 (match_operand:DI 2 "logical_operand" "r,I10")))]
3838   "TARGET_SHMEDIA"
3839   "@
3840         or      %1, %2, %0
3841         ori     %1, %2, %0"
3842   [(set_attr "type" "arith_media")])
3844 (define_insn_and_split "*logical_sidi3"
3845   [(set (match_operand:DI 0 "arith_reg_dest" "=r,r")
3846         (sign_extend:DI (match_operator:SI 3 "logical_operator"
3847                           [(match_operand:SI 1 "arith_reg_operand" "%r,r")
3848                            (match_operand:SI 2 "logical_operand" "r,I10")])))]
3849   "TARGET_SHMEDIA"
3850   "#"
3851   "&& reload_completed"
3852   [(set (match_dup 0) (match_dup 3))]
3854   operands[3]
3855     = gen_rtx_fmt_ee (GET_CODE (operands[3]), DImode,
3856                       simplify_gen_subreg (DImode, operands[1], SImode, 0),
3857                       simplify_gen_subreg (DImode, operands[2], SImode, 0));
3860 (define_insn_and_split "*logical_sidisi3"
3861   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
3862         (truncate:SI (sign_extend:DI
3863                         (match_operator:SI 3 "logical_operator"
3864                           [(match_operand:SI 1 "arith_reg_operand" "%r,r")
3865                            (match_operand:SI 2 "logical_operand" "r,I10")]))))]
3866   "TARGET_SHMEDIA"
3867   "#"
3868   "&& 1"
3869   [(set (match_dup 0) (match_dup 3))])
3871 (define_insn_and_split "*logical_sidi3_2"
3872   [(set (match_operand:DI 0 "arith_reg_dest" "=r,r")
3873         (sign_extend:DI (truncate:SI (sign_extend:DI
3874                         (match_operator:SI 3 "logical_operator"
3875                           [(match_operand:SI 1 "arith_reg_operand" "%r,r")
3876                            (match_operand:SI 2 "logical_operand" "r,I10")])))))]
3877   "TARGET_SHMEDIA"
3878   "#"
3879   "&& 1"
3880   [(set (match_dup 0) (sign_extend:DI (match_dup 3)))])
3882 (define_expand "xorsi3"
3883   [(set (match_operand:SI 0 "arith_reg_operand" "")
3884         (xor:SI (match_operand:SI 1 "logical_reg_operand" "")
3885                 (match_operand:SI 2 "xor_operand" "")))]
3886   ""
3887   "")
3889 (define_insn "*xorsi3_compact"
3890   [(set (match_operand:SI 0 "arith_reg_dest" "=z,r")
3891         (xor:SI (match_operand:SI 1 "arith_reg_operand" "%0,0")
3892                 (match_operand:SI 2 "logical_operand" "K08,r")))]
3893   "TARGET_SH1"
3894   "xor  %2,%0"
3895   [(set_attr "type" "arith")])
3897 ;; The *logical_op_t pattern helps combine eliminating sign/zero extensions
3898 ;; of results where one of the inputs is a T bit store.  Notice that this
3899 ;; pattern must not match during reload.  If reload picks this pattern it
3900 ;; will be impossible to split it afterwards.
3901 (define_insn_and_split "*logical_op_t"
3902   [(set (match_operand:SI 0 "arith_reg_dest")
3903         (match_operator:SI 3 "logical_operator"
3904           [(match_operand:SI 1 "arith_reg_operand")
3905            (match_operand:SI 2 "t_reg_operand")]))]
3906   "TARGET_SH1 && can_create_pseudo_p ()"
3907   "#"
3908   "&& 1"
3909   [(set (match_dup 4) (reg:SI T_REG))
3910    (set (match_dup 0) (match_dup 3))]
3912   operands[4] = gen_reg_rtx (SImode);
3913   operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
3914                                 operands[1], operands[4]);
3917 (define_insn "*xorsi3_media"
3918   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
3919         (xor:SI (match_operand:SI 1 "logical_reg_operand" "%r,r")
3920                 (match_operand:SI 2 "xor_operand" "r,I06")))]
3921   "TARGET_SHMEDIA"
3922   "@
3923         xor     %1, %2, %0
3924         xori    %1, %2, %0"
3925   [(set_attr "type" "arith_media")])
3927 (define_insn "xordi3"
3928   [(set (match_operand:DI 0 "arith_reg_dest" "=r,r")
3929         (xor:DI (match_operand:DI 1 "arith_reg_operand" "%r,r")
3930                 (match_operand:DI 2 "xor_operand" "r,I06")))]
3931   "TARGET_SHMEDIA"
3932   "@
3933         xor     %1, %2, %0
3934         xori    %1, %2, %0"
3935   [(set_attr "type" "arith_media")])
3937 ;; Combiner bridge pattern for 2 * sign extend -> logical op -> truncate.
3938 ;; converts 2 * sign extend -> logical op into logical op -> sign extend
3939 (define_split
3940   [(set (match_operand:DI 0 "arith_reg_dest" "")
3941         (sign_extend:DI (match_operator 4 "binary_logical_operator"
3942                           [(match_operand 1 "any_register_operand" "")
3943                            (match_operand 2 "any_register_operand" "")])))]
3944   "TARGET_SHMEDIA"
3945   [(set (match_dup 5) (match_dup 4))
3946    (set (match_dup 0) (sign_extend:DI (match_dup 5)))]
3948   machine_mode inmode = GET_MODE (operands[1]);
3949   int offset = 0;
3951   if (GET_CODE (operands[0]) == SUBREG)
3952     {
3953       offset = SUBREG_BYTE (operands[0]);
3954       operands[0] = SUBREG_REG (operands[0]);
3955     }
3956   gcc_assert (REG_P (operands[0]));
3957   if (TARGET_BIG_ENDIAN)
3958     offset += 8 - GET_MODE_SIZE (inmode);
3959   operands[5] = gen_rtx_SUBREG (inmode, operands[0], offset);
3962 ;; -------------------------------------------------------------------------
3963 ;; Shifts and rotates
3964 ;; -------------------------------------------------------------------------
3966 (define_expand "rotldi3"
3967   [(set (match_operand:DI 0 "arith_reg_dest" "")
3968         (rotate:DI (match_operand:DI 1 "arith_reg_operand" "")
3969                    (match_operand:HI 2 "mextr_bit_offset" "")))]
3970   "TARGET_SHMEDIA"
3972   if (! mextr_bit_offset (operands[2], HImode))
3973     FAIL;
3976 (define_insn "rotldi3_mextr"
3977   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
3978         (rotate:DI (match_operand:DI 1 "arith_reg_operand" "r")
3979                    (match_operand:HI 2 "mextr_bit_offset" "i")))]
3980   "TARGET_SHMEDIA"
3982   static char templ[16];
3983   sprintf (templ, "mextr%d      %%1,%%1,%%0",
3984            8 - (int) (INTVAL (operands[2]) >> 3));
3985   return templ;
3987   [(set_attr "type" "arith_media")])
3989 (define_expand "rotrdi3"
3990   [(set (match_operand:DI 0 "arith_reg_dest" "")
3991         (rotatert:DI (match_operand:DI 1 "arith_reg_operand" "")
3992                      (match_operand:HI 2 "mextr_bit_offset" "")))]
3993   "TARGET_SHMEDIA"
3995   if (! mextr_bit_offset (operands[2], HImode))
3996     FAIL;
3999 (define_insn "rotrdi3_mextr"
4000   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
4001         (rotatert:DI (match_operand:DI 1 "arith_reg_operand" "r")
4002                      (match_operand:HI 2 "mextr_bit_offset" "i")))]
4003   "TARGET_SHMEDIA"
4005   static char templ[16];
4006   sprintf (templ, "mextr%d      %%1,%%1,%%0", (int) INTVAL (operands[2]) >> 3);
4007   return templ;
4009   [(set_attr "type" "arith_media")])
4011 (define_split
4012   [(set (match_operand:DI 0 "arith_reg_dest" "")
4013         (ior:DI (zero_extend:DI (mem:QI (match_operand 1
4014                                          "ua_address_operand" "")))
4015                 (ashift:DI (match_operand:DI 2 "arith_reg_operand" "")
4016                            (const_int 8))))
4017    (clobber (match_operand:DI 3 "register_operand" ""))]
4018   "TARGET_SHMEDIA"
4019   [(match_dup 4) (match_dup 5)]
4021   operands[4] = ((TARGET_LITTLE_ENDIAN ? gen_ldhi_q : gen_ldlo_q)
4022                  (operands[3], operands[1]));
4023   operands[5] = gen_mextr_rl (operands[0], operands[3], operands[2],
4024                               GEN_INT (56), GEN_INT (8));
4027 (define_expand "rotrsi3"
4028   [(set (match_operand:SI 0 "arith_reg_dest")
4029         (rotatert:SI (match_operand:SI 1 "arith_reg_operand")
4030                      (match_operand:SI 2 "const_int_operand")))]
4031   "TARGET_SH1"
4033   HOST_WIDE_INT ival = INTVAL (operands[2]);
4034   if (ival == 1)
4035     {
4036       emit_insn (gen_rotrsi3_1 (operands[0], operands[1]));
4037       DONE;
4038     }
4040   FAIL;
4043 (define_insn "rotrsi3_1"
4044   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4045         (rotatert:SI (match_operand:SI 1 "arith_reg_operand" "0")
4046                      (const_int 1)))
4047    (set (reg:SI T_REG)
4048         (and:SI (match_dup 1) (const_int 1)))]
4049   "TARGET_SH1"
4050   "rotr %0"
4051   [(set_attr "type" "arith")])
4053 ;; A slimplified version of rotr for combine.
4054 (define_insn "*rotrsi3_1"
4055   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4056         (rotatert:SI (match_operand:SI 1 "arith_reg_operand" "0")
4057                      (const_int 1)))
4058    (clobber (reg:SI T_REG))]
4059   "TARGET_SH1"
4060   "rotr %0"
4061   [(set_attr "type" "arith")])
4063 (define_insn "rotlsi3_1"
4064   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4065         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
4066                    (const_int 1)))
4067    (set (reg:SI T_REG)
4068         (lshiftrt:SI (match_dup 1) (const_int 31)))]
4069   "TARGET_SH1"
4070   "rotl %0"
4071   [(set_attr "type" "arith")])
4073 ;; A simplified version of rotl for combine.
4074 (define_insn "*rotlsi3_1"
4075   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4076         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
4077                    (const_int 1)))
4078    (clobber (reg:SI T_REG))]
4079   "TARGET_SH1"
4080   "rotl %0"
4081   [(set_attr "type" "arith")])
4083 (define_insn "rotlsi3_31"
4084   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4085         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "0")
4086                    (const_int 31)))
4087    (clobber (reg:SI T_REG))]
4088   "TARGET_SH1"
4089   "rotr %0"
4090   [(set_attr "type" "arith")])
4092 (define_insn "rotlsi3_16"
4093   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4094         (rotate:SI (match_operand:SI 1 "arith_reg_operand" "r")
4095                    (const_int 16)))]
4096   "TARGET_SH1"
4097   "swap.w       %1,%0"
4098   [(set_attr "type" "arith")])
4100 (define_expand "rotlsi3"
4101   [(set (match_operand:SI 0 "arith_reg_dest")
4102         (rotate:SI (match_operand:SI 1 "arith_reg_operand")
4103                    (match_operand:SI 2 "const_int_operand")))]
4104   "TARGET_SH1"
4106   static const char rot_tab[] = {
4107     000, 000, 000, 000, 000, 000, 010, 001,
4108     001, 001, 011, 013, 003, 003, 003, 003,
4109     003, 003, 003, 003, 003, 013, 012, 002,
4110     002, 002, 010, 000, 000, 000, 000, 000,
4111   };
4113   int count = INTVAL (operands[2]);
4114   int choice = rot_tab[count];
4115   if (choice & 010 && SH_DYNAMIC_SHIFT_COST <= 1)
4116     FAIL;
4117   choice &= 7;
4118   switch (choice)
4119     {
4120     case 0:
4121       emit_move_insn (operands[0], operands[1]);
4122       count -= (count & 16) * 2;
4123       break;
4124     case 3:
4125      emit_insn (gen_rotlsi3_16 (operands[0], operands[1]));
4126      count -= 16;
4127      break;
4128     case 1:
4129     case 2:
4130       {
4131         rtx parts[2];
4132         parts[0] = gen_reg_rtx (SImode);
4133         parts[1] = gen_reg_rtx (SImode);
4134         emit_insn (gen_rotlsi3_16 (parts[2-choice], operands[1]));
4135         emit_move_insn (parts[choice-1], operands[1]);
4136         emit_insn (gen_ashlsi3 (parts[0], parts[0], GEN_INT (8)));
4137         emit_insn (gen_lshrsi3 (parts[1], parts[1], GEN_INT (8)));
4138         emit_insn (gen_iorsi3 (operands[0], parts[0], parts[1]));
4139         count = (count & ~16) - 8;
4140       }
4141     }
4143   for (; count > 0; count--)
4144     emit_insn (gen_rotlsi3_1 (operands[0], operands[0]));
4145   for (; count < 0; count++)
4146     emit_insn (gen_rotlsi3_31 (operands[0], operands[0]));
4148   DONE;
4151 (define_insn "rotlhi3_8"
4152   [(set (match_operand:HI 0 "arith_reg_dest" "=r")
4153         (rotate:HI (match_operand:HI 1 "arith_reg_operand" "r")
4154                    (const_int 8)))]
4155   "TARGET_SH1"
4156   "swap.b       %1,%0"
4157   [(set_attr "type" "arith")])
4159 (define_expand "rotlhi3"
4160   [(set (match_operand:HI 0 "arith_reg_operand")
4161         (rotate:HI (match_operand:HI 1 "arith_reg_operand")
4162                    (match_operand:HI 2 "const_int_operand")))]
4163   "TARGET_SH1"
4165   if (INTVAL (operands[2]) != 8)
4166     FAIL;
4169 ;; The rotcr and rotcl insns are used primarily in DImode shifts by one.
4170 ;; They can also be used to implement things like
4171 ;;      bool t = a == b;
4172 ;;      int x0 = (y >> 1) | (t << 31);  // rotcr
4173 ;;      int x1 = (y << 1) | t;          // rotcl
4174 (define_insn "rotcr"
4175   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4176         (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4177                              (const_int 1))
4178                 (ashift:SI (match_operand:SI 2 "t_reg_operand")
4179                            (const_int 31))))
4180    (set (reg:SI T_REG)
4181         (and:SI (match_dup 1) (const_int 1)))]
4182   "TARGET_SH1"
4183   "rotcr        %0"
4184   [(set_attr "type" "arith")])
4186 (define_insn "rotcl"
4187   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4188         (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
4189                            (const_int 1))
4190                 (match_operand:SI 2 "t_reg_operand")))
4191    (set (reg:SI T_REG)
4192         (lshiftrt:SI (match_dup 1) (const_int 31)))]
4193   "TARGET_SH1"
4194   "rotcl        %0"
4195   [(set_attr "type" "arith")])
4197 ;; Simplified rotcr version for combine, which allows arbitrary shift
4198 ;; amounts for the reg.  If the shift amount is '1' rotcr can be used
4199 ;; directly.  Otherwise we have to insert a shift in between.
4200 (define_insn_and_split "*rotcr"
4201   [(set (match_operand:SI 0 "arith_reg_dest")
4202         (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
4203                              (match_operand:SI 2 "const_int_operand"))
4204                 (ashift:SI (match_operand:SI 3 "arith_reg_or_t_reg_operand")
4205                            (const_int 31))))
4206    (clobber (reg:SI T_REG))]
4207   "TARGET_SH1"
4208   "#"
4209   "&& can_create_pseudo_p ()"
4210   [(const_int 0)]
4212   if (INTVAL (operands[2]) > 1)
4213     {
4214       const rtx shift_count = GEN_INT (INTVAL (operands[2]) - 1);
4215       rtx prev_set_t_insn = NULL_RTX;
4216       rtx tmp_t_reg = NULL_RTX;
4218       /* If we're going to emit a shift sequence that clobbers the T_REG,
4219          try to find the previous insn that sets the T_REG and emit the 
4220          shift insn before that insn, to remove the T_REG dependency.
4221          If the insn that sets the T_REG cannot be found, store the T_REG
4222          in a temporary reg and restore it after the shift.  */
4223       if (sh_lshrsi_clobbers_t_reg_p (shift_count)
4224           && ! sh_dynamicalize_shift_p (shift_count))
4225         {
4226           prev_set_t_insn = prev_nonnote_insn_bb (curr_insn);
4228           /* Skip the nott insn, which was probably inserted by the splitter
4229              of *rotcr_neg_t.  Don't use one of the recog functions
4230              here during insn splitting, since that causes problems in later
4231              passes.  */
4232           if (prev_set_t_insn != NULL_RTX)
4233             {
4234               rtx pat = PATTERN (prev_set_t_insn);
4235               if (GET_CODE (pat) == SET
4236                   && t_reg_operand (XEXP (pat, 0), SImode)
4237                   && negt_reg_operand (XEXP (pat, 1), SImode))
4238               prev_set_t_insn = prev_nonnote_insn_bb (prev_set_t_insn);
4239             }
4241           if (! (prev_set_t_insn != NULL_RTX
4242                  && reg_set_p (get_t_reg_rtx (), prev_set_t_insn)
4243                  && ! reg_referenced_p (get_t_reg_rtx (),
4244                                         PATTERN (prev_set_t_insn))))
4245             {
4246               prev_set_t_insn = NULL_RTX;
4247               tmp_t_reg = gen_reg_rtx (SImode);
4248               emit_insn (gen_move_insn (tmp_t_reg, get_t_reg_rtx ()));
4249             } 
4250         }
4252       rtx shift_result = gen_reg_rtx (SImode);
4253       rtx shift_insn = gen_lshrsi3 (shift_result, operands[1], shift_count);
4254       operands[1] = shift_result;
4256       /* Emit the shift insn before the insn that sets T_REG, if possible.  */
4257       if (prev_set_t_insn != NULL_RTX)
4258         emit_insn_before (shift_insn, prev_set_t_insn);
4259       else
4260         emit_insn (shift_insn);
4262       /* Restore T_REG if it has been saved before.  */
4263       if (tmp_t_reg != NULL_RTX)
4264         emit_insn (gen_cmpgtsi_t (tmp_t_reg, const0_rtx));
4265     }
4267   /* For the rotcr insn to work, operands[3] must be in T_REG.
4268      If it is not we can get it there by shifting it right one bit.
4269      In this case T_REG is not an input for this insn, thus we don't have to
4270      pay attention as of where to insert the shlr insn.  */
4271   if (! t_reg_operand (operands[3], SImode))
4272     {
4273       /* We don't care about the shifted result here, only the T_REG.  */
4274       emit_insn (gen_shlr (gen_reg_rtx (SImode), operands[3]));
4275       operands[3] = get_t_reg_rtx ();
4276     }
4278   emit_insn (gen_rotcr (operands[0], operands[1], operands[3]));
4279   DONE;
4282 ;; If combine tries the same as above but with swapped operands, split
4283 ;; it so that it will try the pattern above.
4284 (define_split
4285   [(set (match_operand:SI 0 "arith_reg_dest")
4286         (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_or_t_reg_operand")
4287                            (const_int 31))
4288                 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand")
4289                              (match_operand:SI 3 "const_int_operand"))))]
4290   "TARGET_SH1 && can_create_pseudo_p ()"
4291   [(parallel [(set (match_dup 0)
4292                    (ior:SI (lshiftrt:SI (match_dup 2) (match_dup 3))
4293                            (ashift:SI (match_dup 1) (const_int 31))))
4294               (clobber (reg:SI T_REG))])])
4296 ;; Basically the same as the rotcr pattern above, but for rotcl.
4297 ;; FIXME: Fold copy pasted split code for rotcr and rotcl.
4298 (define_insn_and_split "*rotcl"
4299   [(set (match_operand:SI 0 "arith_reg_dest")
4300         (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
4301                            (match_operand:SI 2 "const_int_operand"))
4302                 (and:SI (match_operand:SI 3 "arith_reg_or_t_reg_operand")
4303                         (const_int 1))))
4304    (clobber (reg:SI T_REG))]
4305   "TARGET_SH1"
4306   "#"
4307   "&& can_create_pseudo_p ()"
4308   [(const_int 0)]
4310   gcc_assert (INTVAL (operands[2]) > 0);
4312   if (INTVAL (operands[2]) > 1)
4313     {
4314       const rtx shift_count = GEN_INT (INTVAL (operands[2]) - 1);
4315       rtx prev_set_t_insn = NULL_RTX;
4316       rtx tmp_t_reg = NULL_RTX;
4318       /* If we're going to emit a shift sequence that clobbers the T_REG,
4319          try to find the previous insn that sets the T_REG and emit the 
4320          shift insn before that insn, to remove the T_REG dependency.
4321          If the insn that sets the T_REG cannot be found, store the T_REG
4322          in a temporary reg and restore it after the shift.  */
4323       if (sh_ashlsi_clobbers_t_reg_p (shift_count)
4324           && ! sh_dynamicalize_shift_p (shift_count))
4325         {
4326           prev_set_t_insn = prev_nonnote_insn_bb (curr_insn);
4328           /* Skip the nott insn, which was probably inserted by the splitter
4329              of *rotcl_neg_t.  Don't use one of the recog functions
4330              here during insn splitting, since that causes problems in later
4331              passes.  */
4332           if (prev_set_t_insn != NULL_RTX)
4333             {
4334               rtx pat = PATTERN (prev_set_t_insn);
4335               if (GET_CODE (pat) == SET
4336                   && t_reg_operand (XEXP (pat, 0), SImode)
4337                   && negt_reg_operand (XEXP (pat, 1), SImode))
4338               prev_set_t_insn = prev_nonnote_insn_bb (prev_set_t_insn);
4339             }
4341           if (! (prev_set_t_insn != NULL_RTX
4342                  && reg_set_p (get_t_reg_rtx (), prev_set_t_insn)
4343                  && ! reg_referenced_p (get_t_reg_rtx (),
4344                                         PATTERN (prev_set_t_insn))))
4345             {
4346               prev_set_t_insn = NULL_RTX;
4347               tmp_t_reg = gen_reg_rtx (SImode);
4348               emit_insn (gen_move_insn (tmp_t_reg, get_t_reg_rtx ()));
4349             } 
4350         }
4352       rtx shift_result = gen_reg_rtx (SImode);
4353       rtx shift_insn = gen_ashlsi3 (shift_result, operands[1], shift_count);
4354       operands[1] = shift_result;
4356       /* Emit the shift insn before the insn that sets T_REG, if possible.  */
4357       if (prev_set_t_insn != NULL_RTX)
4358         emit_insn_before (shift_insn, prev_set_t_insn);
4359       else
4360         emit_insn (shift_insn);
4362       /* Restore T_REG if it has been saved before.  */
4363       if (tmp_t_reg != NULL_RTX)
4364         emit_insn (gen_cmpgtsi_t (tmp_t_reg, const0_rtx));
4365     }
4367   /* For the rotcl insn to work, operands[3] must be in T_REG.
4368      If it is not we can get it there by shifting it right one bit.
4369      In this case T_REG is not an input for this insn, thus we don't have to
4370      pay attention as of where to insert the shlr insn.  */
4371   if (! t_reg_operand (operands[3], SImode))
4372     {
4373       /* We don't care about the shifted result here, only the T_REG.  */
4374       emit_insn (gen_shlr (gen_reg_rtx (SImode), operands[3]));
4375       operands[3] = get_t_reg_rtx ();
4376     }
4378   emit_insn (gen_rotcl (operands[0], operands[1], operands[3]));
4379   DONE;
4382 ;; rotcl combine pattern variations
4383 (define_insn_and_split "*rotcl"
4384   [(set (match_operand:SI 0 "arith_reg_dest")
4385         (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
4386                            (match_operand:SI 2 "const_int_operand"))
4387                 (match_operand:SI 3 "t_reg_operand")))
4388    (clobber (reg:SI T_REG))]
4389   "TARGET_SH1"
4390   "#"
4391   "&& can_create_pseudo_p ()"
4392   [(parallel [(set (match_dup 0)
4393                    (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
4394                            (and:SI (match_dup 3) (const_int 1))))
4395               (clobber (reg:SI T_REG))])])
4397 (define_insn_and_split "*rotcl"
4398   [(set (match_operand:SI 0 "arith_reg_dest")
4399         (ior:SI (and:SI (match_operand:SI 1 "arith_reg_or_t_reg_operand")
4400                         (const_int 1))
4401                 (ashift:SI (match_operand:SI 2 "arith_reg_operand")
4402                            (match_operand:SI 3 "const_int_operand"))))
4403    (clobber (reg:SI T_REG))]
4404   "TARGET_SH1"
4405   "#"
4406   "&& can_create_pseudo_p ()"
4407   [(parallel [(set (match_dup 0)
4408                    (ior:SI (ashift:SI (match_dup 2) (match_dup 3))
4409                            (and:SI (match_dup 1) (const_int 1))))
4410               (clobber (reg:SI T_REG))])])
4412 (define_insn_and_split "*rotcl"
4413   [(set (match_operand:SI 0 "arith_reg_dest")
4414         (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand")
4415                            (match_operand:SI 2 "const_int_operand"))
4416                 (lshiftrt:SI (match_operand:SI 3 "arith_reg_operand")
4417                              (const_int 31))))
4418    (clobber (reg:SI T_REG))]
4419   "TARGET_SH1"
4420   "#"
4421   "&& can_create_pseudo_p ()"
4422   [(parallel [(set (match_dup 0)
4423                    (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
4424                            (and:SI (reg:SI T_REG) (const_int 1))))
4425               (clobber (reg:SI T_REG))])]
4427   /* We don't care about the result of the left shift, only the T_REG.  */
4428   emit_insn (gen_shll (gen_reg_rtx (SImode), operands[3]));
4431 (define_insn_and_split "*rotcl"
4432   [(set (match_operand:SI 0 "arith_reg_dest")
4433         (ior:SI (lshiftrt:SI (match_operand:SI 3 "arith_reg_operand")
4434                              (const_int 31))
4435                 (ashift:SI (match_operand:SI 1 "arith_reg_operand")
4436                            (match_operand:SI 2 "const_int_operand"))))
4437    (clobber (reg:SI T_REG))]
4438   "TARGET_SH1"
4439   "#"
4440   "&& can_create_pseudo_p ()"
4441   [(parallel [(set (match_dup 0)
4442                    (ior:SI (ashift:SI (match_dup 1) (match_dup 2))
4443                            (and:SI (reg:SI T_REG) (const_int 1))))
4444               (clobber (reg:SI T_REG))])]
4446   /* We don't care about the result of the left shift, only the T_REG.  */
4447   emit_insn (gen_shll (gen_reg_rtx (SImode), operands[3]));
4450 ;; rotcr combine bridge pattern which will make combine try out more
4451 ;; complex patterns.
4452 (define_insn_and_split "*rotcr"
4453   [(set (match_operand:SI 0 "arith_reg_dest")
4454         (ashift:SI (match_operand:SI 1 "t_reg_operand") (const_int 31)))]
4455   "TARGET_SH1"
4456   "#"
4457   "&& 1"
4458   [(set (match_dup 0) (match_dup 1))
4459    (parallel [(set (match_dup 0)
4460                    (ior:SI (lshiftrt:SI (match_dup 0) (const_int 1))
4461                            (ashift:SI (match_dup 1) (const_int 31))))
4462               (set (reg:SI T_REG)
4463                    (and:SI (match_dup 0) (const_int 1)))])])
4465 (define_insn_and_split "*rotcr"
4466   [(set (match_operand:SI 0 "arith_reg_dest")
4467         (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand")
4468                         (const_int -2147483648)) ;; 0xffffffff80000000
4469                 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand")
4470                              (const_int 1))))
4471    (clobber (reg:SI T_REG))]
4472   "TARGET_SH1"
4473   "#"
4474   "&& can_create_pseudo_p ()"
4475   [(const_int 0)]
4477   rtx tmp = gen_reg_rtx (SImode);
4478   emit_insn (gen_shll (tmp, operands[1]));
4479   emit_insn (gen_rotcr (operands[0], operands[2], get_t_reg_rtx ()));
4480   DONE;
4483 ;; rotcr combine patterns for rotating in the negated T_REG value.
4484 (define_insn_and_split "*rotcr_neg_t"
4485   [(set (match_operand:SI 0 "arith_reg_dest")
4486         (ior:SI (match_operand:SI 1 "negt_reg_shl31_operand")
4487                 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand")
4488                              (match_operand:SI 3 "const_int_operand"))))
4489    (clobber (reg:SI T_REG))]
4490   "TARGET_SH1"
4491   "#"
4492   "&& can_create_pseudo_p ()"
4493   [(parallel [(set (match_dup 0)
4494                    (ior:SI (lshiftrt:SI (match_dup 2) (match_dup 3))
4495                            (ashift:SI (reg:SI T_REG) (const_int 31))))
4496               (clobber (reg:SI T_REG))])]
4498   emit_insn (gen_nott (get_t_reg_rtx ()));
4501 (define_insn_and_split "*rotcr_neg_t"
4502   [(set (match_operand:SI 0 "arith_reg_dest")
4503         (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand")
4504                              (match_operand:SI 2 "const_int_operand"))
4505                 (match_operand:SI 3 "negt_reg_shl31_operand")))
4506    (clobber (reg:SI T_REG))]
4507   "TARGET_SH1"
4508   "#"
4509   "&& can_create_pseudo_p ()"
4510   [(parallel [(set (match_dup 0)
4511                    (ior:SI (lshiftrt:SI (match_dup 1) (match_dup 2))
4512                            (ashift:SI (reg:SI T_REG) (const_int 31))))
4513               (clobber (reg:SI T_REG))])]
4515   emit_insn (gen_nott (get_t_reg_rtx ()));
4518 ;; rotcl combine patterns for rotating in the negated T_REG value.
4519 ;; For some strange reason these have to be specified as splits which combine
4520 ;; will pick up.  If they are specified as insn_and_split like the
4521 ;; *rotcr_neg_t patterns above, combine would recognize them successfully
4522 ;; but not emit them on non-SH2A targets.
4523 (define_split
4524   [(set (match_operand:SI 0 "arith_reg_dest")
4525         (ior:SI (match_operand:SI 1 "negt_reg_operand")
4526                 (ashift:SI (match_operand:SI 2 "arith_reg_operand")
4527                            (match_operand:SI 3 "const_int_operand"))))]
4528   "TARGET_SH1"
4529   [(set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))
4530    (parallel [(set (match_dup 0)
4531                    (ior:SI (ashift:SI (match_dup 2) (match_dup 3))
4532                            (and:SI (reg:SI T_REG) (const_int 1))))
4533               (clobber (reg:SI T_REG))])])
4535 (define_split
4536   [(set (match_operand:SI 0 "arith_reg_dest")
4537         (ior:SI (ashift:SI (match_operand:SI 2 "arith_reg_operand")
4538                            (match_operand:SI 3 "const_int_operand"))
4539                 (match_operand:SI 1 "negt_reg_operand")))]
4540   "TARGET_SH1"
4541   [(set (reg:SI T_REG) (xor:SI (reg:SI T_REG) (const_int 1)))
4542    (parallel [(set (match_dup 0)
4543                    (ior:SI (ashift:SI (match_dup 2) (match_dup 3))
4544                            (and:SI (reg:SI T_REG) (const_int 1))))
4545               (clobber (reg:SI T_REG))])])
4547 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4548 ;; SImode shift left
4550 (define_expand "ashlsi3"
4551   [(set (match_operand:SI 0 "arith_reg_operand" "")
4552         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "")
4553                    (match_operand:SI 2 "shift_count_operand" "")))]
4554   ""
4556   if (TARGET_SHMEDIA)
4557     {
4558        if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0)
4559         {
4560           operands[2] = GEN_INT (-INTVAL (operands[2]));
4561           emit_insn (gen_ashrsi3_media (operands[0], operands[1], operands[2]));
4562           DONE;
4563         }
4564       emit_insn (gen_ashlsi3_media (operands[0], operands[1], operands[2]));
4565       DONE;
4566     }
4567   if (TARGET_DYNSHIFT
4568       && CONST_INT_P (operands[2]) && sh_dynamicalize_shift_p (operands[2]))
4569       operands[2] = force_reg (SImode, operands[2]);
4571   /*  If the ashlsi3_* insn is going to clobber the T_REG it must be
4572       expanded here.  */
4573   if (CONST_INT_P (operands[2])
4574       && sh_ashlsi_clobbers_t_reg_p (operands[2])
4575       && ! sh_dynamicalize_shift_p (operands[2]))
4576     {
4577       emit_insn (gen_ashlsi3_n_clobbers_t (operands[0], operands[1],
4578                                            operands[2]));
4579       DONE;
4580     }
4582   /* Expand a library call for the dynamic shift.  */
4583   if (!CONST_INT_P (operands[2]) && !TARGET_DYNSHIFT)
4584     {
4585       emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
4586       rtx funcaddr = gen_reg_rtx (Pmode);
4587       function_symbol (funcaddr, "__ashlsi3_r0", SFUNC_STATIC);
4588       emit_insn (gen_ashlsi3_d_call (operands[0], operands[2], funcaddr));
4590       DONE;
4591     }
4594 (define_insn "ashlsi3_k"
4595   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
4596         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0,0")
4597                    (match_operand:SI 2 "p27_shift_count_operand" "M,P27")))]
4598   "TARGET_SH1"
4599   "@
4600         add     %0,%0
4601         shll%O2 %0"
4602   [(set_attr "type" "arith")])
4604 (define_insn_and_split "ashlsi3_d"
4605   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4606         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
4607                    (match_operand:SI 2 "shift_count_operand" "r")))]
4608   "TARGET_DYNSHIFT"
4609   "shld %2,%0"
4610   "&& CONST_INT_P (operands[2]) && ! sh_dynamicalize_shift_p (operands[2])
4611    && ! sh_ashlsi_clobbers_t_reg_p (operands[2])"
4612   [(const_int 0)]
4614   if (satisfies_constraint_P27 (operands[2]))
4615     {
4616       emit_insn (gen_ashlsi3_k (operands[0], operands[1], operands[2]));
4617       DONE;
4618     }
4619   else if (! satisfies_constraint_P27 (operands[2]))
4620     {
4621       /* This must happen before reload, otherwise the constant will be moved
4622          into a register due to the "r" constraint, after which this split
4623          cannot be done anymore.
4624          Unfortunately the move insn will not always be eliminated.
4625          Also, here we must not create a shift sequence that clobbers the
4626          T_REG.  */
4627       emit_move_insn (operands[0], operands[1]);
4628       gen_shifty_op (ASHIFT, operands);
4629       DONE;
4630     }
4632   FAIL;
4634   [(set_attr "type" "dyn_shift")])
4636 ;; If dynamic shifts are not available use a library function.
4637 ;; By specifying the pattern we reduce the number of call clobbered regs.
4638 ;; In order to make combine understand the truncation of the shift amount
4639 ;; operand we have to allow it to use pseudo regs for the shift operands.
4640 (define_insn "ashlsi3_d_call"
4641   [(set (match_operand:SI 0 "arith_reg_dest" "=z")
4642         (ashift:SI (reg:SI R4_REG)
4643                    (and:SI (match_operand:SI 1 "arith_reg_operand" "z")
4644                            (const_int 31))))
4645    (use (match_operand:SI 2 "arith_reg_operand" "r"))
4646    (clobber (reg:SI T_REG))
4647    (clobber (reg:SI PR_REG))]
4648   "TARGET_SH1 && !TARGET_DYNSHIFT"
4649   "jsr  @%2%#"
4650   [(set_attr "type" "sfunc")
4651    (set_attr "needs_delay_slot" "yes")])
4653 (define_insn_and_split "ashlsi3_n"
4654   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4655         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
4656                    (match_operand:SI 2 "not_p27_shift_count_operand" "")))]
4657   "TARGET_SH1 && ! sh_ashlsi_clobbers_t_reg_p (operands[2])"
4658   "#"
4659   "&& (reload_completed
4660        || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
4661   [(const_int 0)]
4663   if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
4664     {
4665       /* If this pattern was picked and dynamic shifts are supported, switch
4666          to dynamic shift pattern before reload.  */
4667       operands[2] = force_reg (SImode, operands[2]);
4668       emit_insn (gen_ashlsi3_d (operands[0], operands[1], operands[2]));
4669     }
4670   else
4671     gen_shifty_op (ASHIFT, operands);
4673   DONE;
4676 (define_insn_and_split "ashlsi3_n_clobbers_t"
4677   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4678         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
4679                    (match_operand:SI 2 "not_p27_shift_count_operand" "")))
4680    (clobber (reg:SI T_REG))]
4681   "TARGET_SH1 && sh_ashlsi_clobbers_t_reg_p (operands[2])"
4682   "#"
4683   "&& (reload_completed || INTVAL (operands[2]) == 31
4684        || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
4685   [(const_int 0)]
4687   if (INTVAL (operands[2]) == 31)
4688     {
4689       /* If the shift amount is 31 we split into a different sequence before
4690          reload so that it gets a chance to allocate R0 for the sequence.
4691          If it fails to do so (due to pressure on R0), it will take one insn
4692          more for the and.  */
4693       emit_insn (gen_andsi3 (operands[0], operands[1], const1_rtx));
4694       emit_insn (gen_rotlsi3_31 (operands[0], operands[0]));
4695     }
4696   else if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
4697     {
4698       /* If this pattern was picked and dynamic shifts are supported, switch
4699          to dynamic shift pattern before reload.  */
4700       operands[2] = force_reg (SImode, operands[2]);
4701       emit_insn (gen_ashlsi3_d (operands[0], operands[1], operands[2]));
4702     }
4703   else
4704     gen_shifty_op (ASHIFT, operands);
4706   DONE;
4709 (define_insn "shll"
4710   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4711         (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0") (const_int 1)))
4712    (set (reg:SI T_REG)
4713         (lt:SI (match_dup 1) (const_int 0)))]
4714   "TARGET_SH1"
4715   "shll %0"
4716   [(set_attr "type" "arith")])
4718 (define_insn "*ashlsi_c_void"
4719   [(set (reg:SI T_REG)
4720         (lt:SI (match_operand:SI 0 "arith_reg_operand" "r") (const_int 0)))
4721    (clobber (match_scratch:SI 1 "=0"))]
4722   "TARGET_SH1 && cse_not_expected"
4723   "shll %0"
4724   [(set_attr "type" "arith")])
4726 (define_peephole2
4727   [(set (match_operand:SI 0 "arith_reg_dest" "") (const_int 0))
4728    (set (reg:SI T_REG)
4729         (gt:SI (match_dup 0) (match_operand:SI 1 "arith_reg_operand" "")))]
4730   "TARGET_SH1
4731    && peep2_reg_dead_p (2, operands[0])
4732    && peep2_reg_dead_p (2, operands[1])"
4733   [(const_int 0)]
4735   emit_insn (gen_shll (operands[1], operands[1]));
4736   DONE;
4739 (define_insn "ashlsi3_media"
4740   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
4741         (ashift:SI (match_operand:SI 1 "extend_reg_operand" "r,r")
4742                    (match_operand:SI 2 "shift_count_operand" "r,n")))]
4743   "TARGET_SHMEDIA"
4744   "@
4745         shlld.l %1, %2, %0
4746         shlli.l %1, %2, %0"
4747   [(set_attr "type" "arith_media")
4748    (set_attr "highpart" "ignore")])
4750 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4751 ;; HImode shift left
4753 (define_expand "ashlhi3"
4754   [(parallel [(set (match_operand:HI 0 "arith_reg_operand" "")
4755                    (ashift:HI (match_operand:HI 1 "arith_reg_operand" "")
4756                               (match_operand:SI 2 "nonmemory_operand" "")))
4757               (clobber (reg:SI T_REG))])]
4758   "TARGET_SH1"
4760   if (!CONST_INT_P (operands[2]))
4761     FAIL;
4762   /* It may be possible to call gen_ashlhi3 directly with more generic
4763      operands.  Make sure operands[1] is a HImode register here.  */
4764   if (!arith_reg_operand (operands[1], HImode))
4765     operands[1] = copy_to_mode_reg (HImode, operands[1]);
4768 (define_insn "ashlhi3_k"
4769   [(set (match_operand:HI 0 "arith_reg_dest" "=r,r")
4770         (ashift:HI (match_operand:HI 1 "arith_reg_operand" "0,0")
4771                    (match_operand:HI 2 "const_int_operand" "M,P27")))]
4772   "TARGET_SH1 && satisfies_constraint_P27 (operands[2])"
4773   "@
4774         add     %0,%0
4775         shll%O2 %0"
4776   [(set_attr "type" "arith")])
4778 (define_insn_and_split "*ashlhi3_n"
4779   [(set (match_operand:HI 0 "arith_reg_dest" "=r")
4780         (ashift:HI (match_operand:HI 1 "arith_reg_operand" "0")
4781                    (match_operand:HI 2 "const_int_operand" "n")))
4782    (clobber (reg:SI T_REG))]
4783   "TARGET_SH1"
4784   "#"
4785   "&& reload_completed"
4786   [(use (reg:SI R0_REG))]
4788   gen_shifty_hi_op (ASHIFT, operands);
4789   DONE;
4792 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4793 ;; DImode shift left
4795 (define_expand "ashldi3"
4796   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
4797                    (ashift:DI (match_operand:DI 1 "arith_reg_operand" "")
4798                               (match_operand:DI 2 "immediate_operand" "")))
4799               (clobber (reg:SI T_REG))])]
4800   ""
4802   if (TARGET_SHMEDIA)
4803     {
4804        if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0)
4805         {
4806           operands[2] = GEN_INT (-INTVAL (operands[2]));
4807           emit_insn (gen_ashrdi3_media (operands[0], operands[1], operands[2]));
4808           DONE;
4809         }
4810       emit_insn (gen_ashldi3_media (operands[0], operands[1], operands[2]));
4811       DONE;
4812     }
4813   if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) == 1)
4814     {
4815       emit_insn (gen_ashldi3_k (operands[0], operands[1]));
4816       DONE;
4817     }
4818   else if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 32)
4819     {
4820       emit_insn (gen_ashldi3_std (operands[0], operands[1], operands[2]));
4821       DONE;
4822     }
4823   else
4824     FAIL;
4827 ;; Expander for DImode shift left with SImode operations.
4828 (define_expand "ashldi3_std"
4829   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
4830         (ashift:DI (match_operand:DI 1 "arith_reg_operand" "r")
4831                    (match_operand:DI 2 "const_int_operand" "n")))]
4832   "TARGET_SH1 && INTVAL (operands[2]) < 32"
4834   rtx low_src = gen_lowpart (SImode, operands[1]);
4835   rtx high_src = gen_highpart (SImode, operands[1]);
4836   rtx dst = gen_reg_rtx (DImode);
4837   rtx low_dst = gen_lowpart (SImode, dst);
4838   rtx high_dst = gen_highpart (SImode, dst);
4839   rtx tmp0 = gen_reg_rtx (SImode);
4840   rtx tmp1 = gen_reg_rtx (SImode);
4842   emit_insn (gen_lshrsi3 (tmp0, low_src, GEN_INT (32 - INTVAL (operands[2]))));
4843   emit_insn (gen_ashlsi3 (low_dst, low_src, operands[2]));  
4844   emit_insn (gen_ashlsi3 (tmp1, high_src, operands[2]));  
4845   emit_insn (gen_iorsi3 (high_dst, tmp0, tmp1));
4846   emit_move_insn (operands[0], dst);
4847   DONE;
4850 (define_insn_and_split "ashldi3_k"
4851   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
4852         (ashift:DI (match_operand:DI 1 "arith_reg_operand" "0")
4853                    (const_int 1)))
4854    (clobber (reg:SI T_REG))]
4855   "TARGET_SH1"
4856   "#"
4857   "&& reload_completed"
4858   [(const_int 0)]
4860   rtx high = gen_highpart (SImode, operands[0]);
4861   rtx low = gen_lowpart (SImode, operands[0]);
4862   emit_insn (gen_shll (low, low));
4863   emit_insn (gen_rotcl (high, high, get_t_reg_rtx ()));
4864   DONE;
4867 (define_insn "ashldi3_media"
4868   [(set (match_operand:DI 0 "arith_reg_dest" "=r,r")
4869         (ashift:DI (match_operand:DI 1 "arith_reg_operand" "r,r")
4870                    (match_operand:DI 2 "shift_count_operand" "r,n")))]
4871   "TARGET_SHMEDIA"
4872   "@
4873         shlld   %1, %2, %0
4874         shlli   %1, %2, %0"
4875   [(set_attr "type" "arith_media")])
4877 (define_insn "*ashldisi3_media"
4878   [(set (subreg:DI (match_operand:SI 0 "arith_reg_operand" "=r") 0)
4879         (ashift:DI (match_operand:DI 1 "arith_reg_operand" "r")
4880                    (match_operand:DI 2 "const_int_operand" "n")))]
4881   "TARGET_SHMEDIA && INTVAL (operands[2]) < 32"
4882   "shlli.l      %1, %2, %0"
4883   [(set_attr "type" "arith_media")
4884    (set_attr "highpart" "ignore")])
4886 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4887 ;; SImode arithmetic shift right
4889 ;; We can't do HImode right shifts correctly unless we start out with an
4890 ;; explicit zero / sign extension; doing that would result in worse overall
4891 ;; code, so just let the machine independent code widen the mode.
4892 ;; That's why we don't have ashrhi3_k / lshrhi3_k / lshrhi3_m / lshrhi3 .
4894 (define_expand "ashrsi3"
4895   [(parallel [(set (match_operand:SI 0 "arith_reg_dest" "")
4896                    (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
4897                                 (match_operand:SI 2 "nonmemory_operand" "")))
4898               (clobber (reg:SI T_REG))])]
4899   ""
4901   if (TARGET_SHMEDIA)
4902     {
4903       if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0)
4904         {
4905           operands[2] = GEN_INT (-INTVAL (operands[2]));
4906           emit_insn (gen_ashlsi3_media (operands[0], operands[1], operands[2]));
4907           DONE;
4908         }
4909       emit_insn (gen_ashrsi3_media (operands[0], operands[1], operands[2]));
4910       DONE;
4911     }
4912   if (expand_ashiftrt (operands))
4913     DONE;
4914   else
4915     FAIL;
4918 (define_insn "shar"
4919   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4920         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4921                      (const_int 1)))
4922    (set (reg:SI T_REG)
4923         (and:SI (match_dup 1) (const_int 1)))]
4924   "TARGET_SH1"
4925   "shar %0"
4926   [(set_attr "type" "arith")])
4928 (define_insn "ashrsi3_k"
4929   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4930         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4931                      (match_operand:SI 2 "const_int_operand" "M")))
4932    (clobber (reg:SI T_REG))]
4933   "TARGET_SH1 && INTVAL (operands[2]) == 1"
4934   "shar %0"
4935   [(set_attr "type" "arith")])
4937 (define_insn_and_split "ashrsi2_16"
4938   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4939         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "r")
4940                      (const_int 16)))]
4941   "TARGET_SH1"
4942   "#"
4943   "&& 1"
4944   [(set (match_dup 0) (rotate:SI (match_dup 1) (const_int 16)))
4945    (set (match_dup 0) (sign_extend:SI (match_dup 2)))]
4947   operands[2] = gen_lowpart (HImode, operands[0]);
4950 (define_insn_and_split "ashrsi2_31"
4951   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4952         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4953                      (const_int 31)))
4954    (clobber (reg:SI T_REG))]
4955   "TARGET_SH1"
4956   "#"
4957   "&& 1"
4958   [(const_int 0)]
4960   emit_insn (gen_shll (operands[0], operands[1]));
4961   emit_insn (gen_mov_neg_si_t (operands[0], get_t_reg_rtx ()));
4962   DONE;
4965 (define_insn "ashrsi3_d"
4966   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
4967         (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
4968                      (neg:SI (match_operand:SI 2 "arith_reg_operand" "r"))))]
4969   "TARGET_DYNSHIFT"
4970   "shad %2,%0"
4971   [(set_attr "type" "dyn_shift")])
4973 (define_insn "ashrsi3_n"
4974   [(set (reg:SI R4_REG)
4975         (ashiftrt:SI (reg:SI R4_REG)
4976                      (match_operand:SI 0 "const_int_operand" "i")))
4977    (clobber (reg:SI T_REG))
4978    (clobber (reg:SI PR_REG))
4979    (use (match_operand:SI 1 "arith_reg_operand" "r"))]
4980   "TARGET_SH1"
4981   "jsr  @%1%#"
4982   [(set_attr "type" "sfunc")
4983    (set_attr "needs_delay_slot" "yes")])
4985 (define_insn "ashrsi3_media"
4986   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
4987         (ashiftrt:SI (match_operand:SI 1 "extend_reg_operand" "r,r")
4988                      (match_operand:SI 2 "shift_count_operand" "r,n")))]
4989   "TARGET_SHMEDIA"
4990   "@
4991         shard.l %1, %2, %0
4992         shari.l %1, %2, %0"
4993   [(set_attr "type" "arith_media")
4994    (set_attr "highpart" "ignore")])
4996 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4997 ;; DImode arithmetic shift right
4999 (define_expand "ashrdi3"
5000   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
5001                    (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
5002                                 (match_operand:DI 2 "immediate_operand" "")))
5003               (clobber (reg:SI T_REG))])]
5004   ""
5006   if (TARGET_SHMEDIA)
5007     {
5008       if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0)
5009         {
5010           operands[2] = GEN_INT (-INTVAL (operands[2]));
5011           emit_insn (gen_ashldi3_media (operands[0], operands[1], operands[2]));
5012           DONE;
5013         }
5014       emit_insn (gen_ashrdi3_media (operands[0], operands[1], operands[2]));
5015       DONE;
5016     }
5017   if (!CONST_INT_P (operands[2]) || INTVAL (operands[2]) != 1)
5018     FAIL;
5021 (define_insn_and_split "ashrdi3_k"
5022   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
5023         (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
5024                      (const_int 1)))
5025    (clobber (reg:SI T_REG))]
5026   "TARGET_SH1"
5027   "#"
5028   "&& reload_completed"
5029   [(const_int 0)]
5031   rtx high = gen_highpart (SImode, operands[0]);
5032   rtx low = gen_lowpart (SImode, operands[0]);
5033   emit_insn (gen_shar (high, high));
5034   emit_insn (gen_rotcr (low, low, get_t_reg_rtx ()));
5035   DONE;
5038 (define_insn "ashrdi3_media"
5039   [(set (match_operand:DI 0 "ext_dest_operand" "=r,r")
5040         (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "r,r")
5041                      (match_operand:DI 2 "shift_count_operand" "r,n")))]
5042   "TARGET_SHMEDIA
5043    && (arith_reg_dest (operands[0], DImode)
5044        || (CONST_INT_P (operands[2]) && INTVAL (operands[2]) >= 32))"
5045   "@
5046         shard   %1, %2, %0
5047         shari   %1, %2, %0"
5048   [(set_attr "type" "arith_media")])
5050 (define_insn "*ashrdisi3_media"
5051   [(set (subreg:DI (match_operand:SI 0 "arith_reg_operand" "=r") 0)
5052         (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "r")
5053                      (match_operand:DI 2 "const_int_operand" "n")))]
5054   "TARGET_SHMEDIA && INTVAL (operands[2]) < 32"
5055   "shari.l      %1, %2, %0"
5056   [(set_attr "type" "arith_media")
5057    (set_attr "highpart" "ignore")])
5059 (define_insn "ashrdisi3_media_high"
5060   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5061         (truncate:SI
5062            (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "r")
5063                         (match_operand:DI 2 "const_int_operand" "n"))))]
5064   "TARGET_SHMEDIA && INTVAL (operands[2]) >= 32"
5065   "shari        %1, %2, %0"
5066   [(set_attr "type" "arith_media")])
5068 (define_insn "ashrdisi3_media_opaque"
5069   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5070         (unspec:SI [(match_operand:DI 1 "arith_reg_operand" "r")
5071                     (match_operand:DI 2 "const_int_operand" "n")]
5072          UNSPEC_ASHIFTRT))]
5073   "TARGET_SHMEDIA"
5074   "shari        %1, %2, %0"
5075   [(set_attr "type" "arith_media")])
5077 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5078 ;; SImode logical shift right
5080 (define_expand "lshrsi3"
5081   [(set (match_operand:SI 0 "arith_reg_dest" "")
5082         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "")
5083                      (match_operand:SI 2 "shift_count_operand" "")))]
5084   ""
5086   if (TARGET_SHMEDIA)
5087     {
5088       if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0)
5089         {
5090           operands[2] = GEN_INT (-INTVAL (operands[2]));
5091           emit_insn (gen_ashlsi3_media (operands[0], operands[1], operands[2]));
5092           DONE;
5093         }
5094       emit_insn (gen_lshrsi3_media (operands[0], operands[1], operands[2]));
5095       DONE;
5096     }
5098   /* If a dynamic shift is supposed to be used, expand the lshrsi3_d insn
5099      here, otherwise the pattern will never match due to the shift amount reg
5100      negation.  */
5101   if (TARGET_DYNSHIFT
5102       && CONST_INT_P (operands[2]) && sh_dynamicalize_shift_p (operands[2]))
5103     {
5104       rtx neg_count = force_reg (SImode,
5105                                  gen_int_mode (- INTVAL (operands[2]), SImode));
5106       emit_insn (gen_lshrsi3_d (operands[0], operands[1], neg_count));
5107       DONE;
5108     }
5110   if (TARGET_DYNSHIFT && ! CONST_INT_P (operands[2]))
5111     {
5112       rtx neg_count = gen_reg_rtx (SImode);
5113       emit_insn (gen_negsi2 (neg_count, operands[2]));
5114       emit_insn (gen_lshrsi3_d (operands[0], operands[1], neg_count));
5115       DONE;
5116     }
5118   /* If the lshrsi3_* insn is going to clobber the T_REG it must be
5119      expanded here.  */
5120   if (CONST_INT_P (operands[2])
5121       && sh_lshrsi_clobbers_t_reg_p (operands[2])
5122       && ! sh_dynamicalize_shift_p (operands[2]))
5123     {
5124       emit_insn (gen_lshrsi3_n_clobbers_t (operands[0], operands[1],
5125                  operands[2]));
5126       DONE;
5127     }
5129   /* Expand a library call for the dynamic shift.  */
5130   if (!CONST_INT_P (operands[2]) && !TARGET_DYNSHIFT)
5131     {
5132       emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
5133       rtx funcaddr = gen_reg_rtx (Pmode);
5134       function_symbol (funcaddr, "__lshrsi3_r0", SFUNC_STATIC);
5135       emit_insn (gen_lshrsi3_d_call (operands[0], operands[2], funcaddr));
5136       DONE;
5137     }
5140 (define_insn "lshrsi3_k"
5141   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5142         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
5143                      (match_operand:SI 2 "p27_rshift_count_operand" "P27")))]
5144   "TARGET_SH1"
5145   "shlr%O2      %0"
5146   [(set_attr "type" "arith")])
5148 (define_insn_and_split "lshrsi3_d"
5149   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5150         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
5151                      (neg:SI (match_operand:SI 2 "shift_count_operand" "r"))))]
5152   "TARGET_DYNSHIFT"
5153   "shld %2,%0"
5154   "&& CONST_INT_P (operands[2]) && ! sh_dynamicalize_shift_p (operands[2])
5155    && ! sh_lshrsi_clobbers_t_reg_p (operands[2])"
5156   [(const_int 0)]
5158   if (satisfies_constraint_P27 (operands[2]))
5159     {
5160       /* This will not be done for a shift amount of 1, because it would
5161          clobber the T_REG.  */
5162       emit_insn (gen_lshrsi3_k (operands[0], operands[1], operands[2]));
5163       DONE;
5164     }
5165   else if (! satisfies_constraint_P27 (operands[2]))
5166     {
5167       /* This must happen before reload, otherwise the constant will be moved
5168          into a register due to the "r" constraint, after which this split
5169          cannot be done anymore.
5170          Unfortunately the move insn will not always be eliminated.
5171          Also, here we must not create a shift sequence that clobbers the
5172          T_REG.  */
5173       emit_move_insn (operands[0], operands[1]);
5174       gen_shifty_op (LSHIFTRT, operands);
5175       DONE;
5176     }
5178   FAIL;
5180   [(set_attr "type" "dyn_shift")])
5182 ;; If dynamic shifts are not available use a library function.
5183 ;; By specifying the pattern we reduce the number of call clobbered regs.
5184 ;; In order to make combine understand the truncation of the shift amount
5185 ;; operand we have to allow it to use pseudo regs for the shift operands.
5186 (define_insn "lshrsi3_d_call"
5187   [(set (match_operand:SI 0 "arith_reg_dest" "=z")
5188         (lshiftrt:SI (reg:SI R4_REG)
5189                      (and:SI (match_operand:SI 1 "arith_reg_operand" "z")
5190                              (const_int 31))))
5191    (use (match_operand:SI 2 "arith_reg_operand" "r"))
5192    (clobber (reg:SI T_REG))
5193    (clobber (reg:SI PR_REG))]
5194   "TARGET_SH1 && !TARGET_DYNSHIFT"
5195   "jsr  @%2%#"
5196   [(set_attr "type" "sfunc")
5197    (set_attr "needs_delay_slot" "yes")])
5199 (define_insn_and_split "lshrsi3_n"
5200   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5201         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
5202                      (match_operand:SI 2 "not_p27_rshift_count_operand")))]
5203   "TARGET_SH1 && ! sh_lshrsi_clobbers_t_reg_p (operands[2])"
5204   "#"
5205   "&& (reload_completed
5206        || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
5207   [(const_int 0)]
5209   if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
5210     {
5211       /* If this pattern was picked and dynamic shifts are supported, switch
5212          to dynamic shift pattern before reload.  */
5213       operands[2] = force_reg (SImode,
5214                                gen_int_mode (- INTVAL (operands[2]), SImode));
5215       emit_insn (gen_lshrsi3_d (operands[0], operands[1], operands[2]));
5216     }
5217   else
5218     gen_shifty_op (LSHIFTRT, operands);
5220   DONE;
5223 ;; The lshrsi3_n_clobbers_t pattern also works as a simplified version of
5224 ;; the shlr pattern.
5225 (define_insn_and_split "lshrsi3_n_clobbers_t"
5226   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5227         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
5228                      (match_operand:SI 2 "not_p27_rshift_count_operand")))
5229    (clobber (reg:SI T_REG))]
5230   "TARGET_SH1 && sh_lshrsi_clobbers_t_reg_p (operands[2])"
5231   "#"
5232   "&& (reload_completed || INTVAL (operands[2]) == 31
5233        || (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ()))"
5234   [(const_int 0)]
5236   if (INTVAL (operands[2]) == 31)
5237     {
5238       emit_insn (gen_shll (operands[0], operands[1]));
5239       emit_insn (gen_movt (operands[0], get_t_reg_rtx ()));
5240     }
5241   else if (sh_dynamicalize_shift_p (operands[2]) && can_create_pseudo_p ())
5242     {
5243       /* If this pattern was picked and dynamic shifts are supported, switch
5244          to dynamic shift pattern before reload.  */
5245       operands[2] = force_reg (SImode,
5246                                gen_int_mode (- INTVAL (operands[2]), SImode));
5247       emit_insn (gen_lshrsi3_d (operands[0], operands[1], operands[2]));
5248     }
5249   else
5250     gen_shifty_op (LSHIFTRT, operands);
5252   DONE;
5255 (define_insn "shlr"
5256   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5257         (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
5258                      (const_int 1)))
5259    (set (reg:SI T_REG)
5260         (and:SI (match_dup 1) (const_int 1)))]
5261   "TARGET_SH1"
5262   "shlr %0"
5263   [(set_attr "type" "arith")])
5265 (define_insn "lshrsi3_media"
5266   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
5267         (lshiftrt:SI (match_operand:SI 1 "extend_reg_operand" "r,r")
5268                      (match_operand:SI 2 "shift_count_operand" "r,n")))]
5269   "TARGET_SHMEDIA"
5270   "@
5271         shlrd.l %1, %2, %0
5272         shlri.l %1, %2, %0"
5273   [(set_attr "type" "arith_media")
5274    (set_attr "highpart" "ignore")])
5276 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5277 ;; DImode logical shift right
5279 (define_expand "lshrdi3"
5280   [(parallel [(set (match_operand:DI 0 "arith_reg_operand" "")
5281                    (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "")
5282                                (match_operand:DI 2 "immediate_operand" "")))
5283              (clobber (reg:SI T_REG))])]
5284   ""
5286   if (TARGET_SHMEDIA)
5287     {
5288       if (CONST_INT_P (operands[2]) && INTVAL (operands[2]) < 0)
5289         {
5290           operands[2] = GEN_INT (-INTVAL (operands[2]));
5291           emit_insn (gen_ashldi3_media (operands[0], operands[1], operands[2]));
5292           DONE;
5293         }
5294       emit_insn (gen_lshrdi3_media (operands[0], operands[1], operands[2]));
5295       DONE;
5296     }
5297   if (!CONST_INT_P (operands[2]) || INTVAL (operands[2]) != 1)
5298     FAIL;
5301 (define_insn_and_split "lshrdi3_k"
5302   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
5303         (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "0")
5304                      (const_int 1)))
5305    (clobber (reg:SI T_REG))]
5306   "TARGET_SH1"
5307   "#"
5308   "&& reload_completed"
5309   [(const_int 0)]
5311   rtx high = gen_highpart (SImode, operands[0]);
5312   rtx low = gen_lowpart (SImode, operands[0]);
5313   emit_insn (gen_shlr (high, high));
5314   emit_insn (gen_rotcr (low, low, get_t_reg_rtx ()));
5315   DONE;
5318 (define_insn "lshrdi3_media"
5319   [(set (match_operand:DI 0 "ext_dest_operand" "=r,r")
5320         (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "r,r")
5321                      (match_operand:DI 2 "shift_count_operand" "r,n")))]
5322   "TARGET_SHMEDIA
5323    && (arith_reg_dest (operands[0], DImode)
5324        || (CONST_INT_P (operands[2]) && INTVAL (operands[2]) > 32))"
5325   "@
5326         shlrd   %1, %2, %0
5327         shlri   %1, %2, %0"
5328   [(set_attr "type" "arith_media")])
5330 (define_insn "*lshrdisi3_media"
5331   [(set (subreg:DI (match_operand:SI 0 "arith_reg_operand" "=r") 0)
5332         (lshiftrt:DI (match_operand:DI 1 "arith_reg_operand" "r")
5333                      (match_operand:DI 2 "const_int_operand" "n")))]
5334   "TARGET_SHMEDIA && INTVAL (operands[2]) < 32"
5335   "shlri.l      %1, %2, %0"
5336   [(set_attr "type" "arith_media")
5337    (set_attr "highpart" "ignore")])
5339 ;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5340 ;; Combined left/right shifts
5342 (define_split
5343   [(set (match_operand:SI 0 "register_operand" "")
5344         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
5345                            (match_operand:SI 2 "const_int_operand" ""))
5346                 (match_operand:SI 3 "const_int_operand" "")))]
5347   "TARGET_SH1 && reload_completed && (unsigned)INTVAL (operands[2]) < 32"
5348   [(use (reg:SI R0_REG))]
5350   if (gen_shl_and (operands[0], operands[2], operands[3], operands[1]))
5351     FAIL;
5352   DONE;
5355 (define_split
5356   [(set (match_operand:SI 0 "register_operand" "")
5357         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "")
5358                            (match_operand:SI 2 "const_int_operand" ""))
5359                 (match_operand:SI 3 "const_int_operand" "")))
5360    (clobber (reg:SI T_REG))]
5361   "TARGET_SH1 && reload_completed && (unsigned)INTVAL (operands[2]) < 32"
5362   [(use (reg:SI R0_REG))]
5364   if (gen_shl_and (operands[0], operands[2], operands[3], operands[1]))
5365     FAIL;
5366   DONE;
5369 (define_insn ""
5370   [(set (match_operand:SI 0 "register_operand" "=r")
5371         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
5372                            (match_operand:SI 2 "const_int_operand" "n"))
5373                 (match_operand:SI 3 "const_int_operand" "n")))
5374    (clobber (reg:SI T_REG))]
5375   "TARGET_SH1 && shl_and_kind (operands[2], operands[3], 0) == 1"
5376   "#"
5377   [(set (attr "length")
5378         (cond [(eq (symbol_ref "shl_and_length (insn)") (const_int 2))
5379                (const_string "4")
5380                (eq (symbol_ref "shl_and_length (insn)") (const_int 3))
5381                (const_string "6")
5382                (eq (symbol_ref "shl_and_length (insn)") (const_int 4))
5383                (const_string "8")
5384                (eq (symbol_ref "shl_and_length (insn)") (const_int 5))
5385                (const_string "10")
5386                (eq (symbol_ref "shl_and_length (insn)") (const_int 6))
5387                (const_string "12")
5388                (eq (symbol_ref "shl_and_length (insn)") (const_int 7))
5389                (const_string "14")
5390                (eq (symbol_ref "shl_and_length (insn)") (const_int 8))
5391                (const_string "16")]
5392               (const_string "18")))
5393    (set_attr "type" "arith")])
5395 (define_insn ""
5396   [(set (match_operand:SI 0 "register_operand" "=z")
5397         (and:SI (ashift:SI (match_operand:SI 1 "register_operand" "0")
5398                            (match_operand:SI 2 "const_int_operand" "n"))
5399                 (match_operand:SI 3 "const_int_operand" "n")))
5400    (clobber (reg:SI T_REG))]
5401   "TARGET_SH1 && shl_and_kind (operands[2], operands[3], 0) == 2"
5402   "#"
5403   [(set (attr "length")
5404         (cond [(eq (symbol_ref "shl_and_length (insn)") (const_int 2))
5405                (const_string "4")
5406                (eq (symbol_ref "shl_and_length (insn)") (const_int 3))
5407                (const_string "6")
5408                (eq (symbol_ref "shl_and_length (insn)") (const_int 4))
5409                (const_string "8")]
5410               (const_string "10")))
5411    (set_attr "type" "arith")])
5413 ;; shift left / and combination with a scratch register: The combine pass
5414 ;; does not accept the individual instructions, even though they are
5415 ;; cheap.  But it needs a precise description so that it is usable after
5416 ;; reload.
5417 (define_insn "and_shl_scratch"
5418   [(set (match_operand:SI 0 "register_operand" "=r,&r")
5419         (lshiftrt:SI
5420          (ashift:SI
5421           (and:SI
5422            (lshiftrt:SI (match_operand:SI 1 "register_operand" "r,0")
5423                         (match_operand:SI 2 "const_int_operand" "N,n"))
5424            (match_operand:SI 3 "" "0,r"))
5425           (match_operand:SI 4 "const_int_operand" "n,n"))
5426          (match_operand:SI 5 "const_int_operand" "n,n")))
5427    (clobber (reg:SI T_REG))]
5428   "TARGET_SH1"
5429   "#"
5430   [(set (attr "length")
5431         (cond [(eq (symbol_ref "shl_and_scr_length (insn)") (const_int 2))
5432                (const_string "4")
5433                (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 3))
5434                (const_string "6")
5435                (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 4))
5436                (const_string "8")
5437                (eq (symbol_ref "shl_and_scr_length (insn)") (const_int 5))
5438                (const_string "10")]
5439               (const_string "12")))
5440    (set_attr "type" "arith")])
5442 (define_split
5443   [(set (match_operand:SI 0 "register_operand" "")
5444         (lshiftrt:SI
5445          (ashift:SI
5446           (and:SI
5447            (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
5448                         (match_operand:SI 2 "const_int_operand" ""))
5449            (match_operand:SI 3 "register_operand" ""))
5450           (match_operand:SI 4 "const_int_operand" ""))
5451          (match_operand:SI 5 "const_int_operand" "")))
5452    (clobber (reg:SI T_REG))]
5453   "TARGET_SH1"
5454   [(use (reg:SI R0_REG))]
5456   rtx and_source = operands[rtx_equal_p (operands[0], operands[1]) ? 3 : 1];
5458   if (INTVAL (operands[2]))
5459     {
5460       gen_shifty_op (LSHIFTRT, operands);
5461     }
5462   emit_insn (gen_andsi3 (operands[0], operands[0], and_source));
5463   operands[2] = operands[4];
5464   gen_shifty_op (ASHIFT, operands);
5465   if (INTVAL (operands[5]))
5466     {
5467       operands[2] = operands[5];
5468       gen_shifty_op (LSHIFTRT, operands);
5469     }
5470   DONE;
5473 ;; signed left/right shift combination.
5474 (define_split
5475   [(set (match_operand:SI 0 "register_operand" "")
5476         (sign_extract:SI
5477          (ashift:SI (match_operand:SI 1 "register_operand" "")
5478                     (match_operand:SI 2 "const_int_operand" ""))
5479          (match_operand:SI 3 "const_int_operand" "")
5480          (const_int 0)))
5481    (clobber (reg:SI T_REG))]
5482   "TARGET_SH1"
5483   [(use (reg:SI R0_REG))]
5485   if (gen_shl_sext (operands[0], operands[2], operands[3], operands[1]))
5486     FAIL;
5487   DONE;
5490 (define_insn "shl_sext_ext"
5491   [(set (match_operand:SI 0 "register_operand" "=r")
5492         (sign_extract:SI
5493          (ashift:SI (match_operand:SI 1 "register_operand" "0")
5494                     (match_operand:SI 2 "const_int_operand" "n"))
5495          (match_operand:SI 3 "const_int_operand" "n")
5496          (const_int 0)))
5497    (clobber (reg:SI T_REG))]
5498   "TARGET_SH1 && (unsigned)shl_sext_kind (operands[2], operands[3], 0) - 1 < 5"
5499   "#"
5500   [(set (attr "length")
5501         (cond [(match_test "shl_sext_length (insn)")
5502                (const_string "2")
5503                (eq (symbol_ref "shl_sext_length (insn)") (const_int 2))
5504                (const_string "4")
5505                (eq (symbol_ref "shl_sext_length (insn)") (const_int 3))
5506                (const_string "6")
5507                (eq (symbol_ref "shl_sext_length (insn)") (const_int 4))
5508                (const_string "8")
5509                (eq (symbol_ref "shl_sext_length (insn)") (const_int 5))
5510                (const_string "10")
5511                (eq (symbol_ref "shl_sext_length (insn)") (const_int 6))
5512                (const_string "12")
5513                (eq (symbol_ref "shl_sext_length (insn)") (const_int 7))
5514                (const_string "14")
5515                (eq (symbol_ref "shl_sext_length (insn)") (const_int 8))
5516                (const_string "16")]
5517               (const_string "18")))
5518     (set_attr "type" "arith")])
5520 (define_insn "shl_sext_sub"
5521   [(set (match_operand:SI 0 "register_operand" "=z")
5522         (sign_extract:SI
5523          (ashift:SI (match_operand:SI 1 "register_operand" "0")
5524                     (match_operand:SI 2 "const_int_operand" "n"))
5525          (match_operand:SI 3 "const_int_operand" "n")
5526          (const_int 0)))
5527    (clobber (reg:SI T_REG))]
5528   "TARGET_SH1 && (shl_sext_kind (operands[2], operands[3], 0) & ~1) == 6"
5529   "#"
5530   [(set (attr "length")
5531         (cond [(eq (symbol_ref "shl_sext_length (insn)") (const_int 3))
5532                (const_string "6")
5533                (eq (symbol_ref "shl_sext_length (insn)") (const_int 4))
5534                (const_string "8")
5535                (eq (symbol_ref "shl_sext_length (insn)") (const_int 5))
5536                (const_string "10")
5537                (eq (symbol_ref "shl_sext_length (insn)") (const_int 6))
5538                (const_string "12")]
5539               (const_string "14")))
5540     (set_attr "type" "arith")])
5542 ;; The xtrct_left and xtrct_right patterns are used in expansions of DImode
5543 ;; shifts by 16, and allow the xtrct instruction to be generated from C
5544 ;; source.
5545 (define_insn "xtrct_left"
5546   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5547         (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "r")
5548                            (const_int 16))
5549                 (lshiftrt:SI (match_operand:SI 2 "arith_reg_operand" "0")
5550                              (const_int 16))))]
5551   "TARGET_SH1"
5552   "xtrct        %1,%0"
5553   [(set_attr "type" "arith")])
5555 (define_insn "xtrct_right"
5556   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5557         (ior:SI (lshiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0")
5558                              (const_int 16))
5559                 (ashift:SI (match_operand:SI 2 "arith_reg_operand" "r")
5560                            (const_int 16))))]
5561   "TARGET_SH1"
5562   "xtrct        %2,%0"
5563   [(set_attr "type" "arith")])
5565 ;; -------------------------------------------------------------------------
5566 ;; Unary arithmetic
5567 ;; -------------------------------------------------------------------------
5569 (define_insn "negc"
5570   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5571         (neg:SI (plus:SI (reg:SI T_REG)
5572                          (match_operand:SI 1 "arith_reg_operand" "r"))))
5573    (set (reg:SI T_REG)
5574         (ne:SI (ior:SI (reg:SI T_REG) (match_dup 1))
5575                (const_int 0)))]
5576   "TARGET_SH1"
5577   "negc %1,%0"
5578   [(set_attr "type" "arith")])
5580 ;; A simplified version of the negc insn, where the exact value of the
5581 ;; T bit doesn't matter.  This is easier for combine to pick up.
5582 ;; Notice that '0 - x - 1' is the same as '~x', thus we don't specify
5583 ;; extra patterns for this case.
5584 (define_insn "*negc"
5585   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5586         (minus:SI (neg:SI (match_operand:SI 1 "arith_reg_operand" "r"))
5587                   (match_operand:SI 2 "t_reg_operand" "")))
5588    (clobber (reg:SI T_REG))]
5589   "TARGET_SH1"
5590   "negc %1,%0"
5591   [(set_attr "type" "arith")])
5593 (define_insn "*negdi_media"
5594   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
5595         (neg:DI (match_operand:DI 1 "arith_reg_operand" "r")))]
5596   "TARGET_SHMEDIA"
5597   "sub  r63, %1, %0"
5598   [(set_attr "type" "arith_media")])
5600 ;; Don't split into individual negc insns immediately so that neg:DI (abs:DI)
5601 ;; can be combined.
5602 (define_expand "negdi2"
5603   [(parallel [(set (match_operand:DI 0 "arith_reg_dest")
5604                    (neg:DI (match_operand:DI 1 "arith_reg_operand")))
5605               (clobber (reg:SI T_REG))])]
5606   "TARGET_SH1")
5608 (define_insn_and_split "*negdi2"
5609   [(set (match_operand:DI 0 "arith_reg_dest")
5610         (neg:DI (match_operand:DI 1 "arith_reg_operand")))
5611    (clobber (reg:SI T_REG))]
5612   "TARGET_SH1"
5613   "#"
5614   "&& can_create_pseudo_p ()"
5615   [(const_int 0)]
5617   emit_insn (gen_clrt ());
5618   emit_insn (gen_negc (gen_lowpart (SImode, operands[0]),
5619                        gen_lowpart (SImode, operands[1])));
5620   emit_insn (gen_negc (gen_highpart (SImode, operands[0]),
5621                        gen_highpart (SImode, operands[1])));
5622   DONE;
5625 (define_insn "negsi2"
5626   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5627         (neg:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
5628   "TARGET_SH1"
5629   "neg  %1,%0"
5630   [(set_attr "type" "arith")])
5632 (define_insn_and_split "one_cmplsi2"
5633   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5634         (not:SI (match_operand:SI 1 "arith_reg_operand" "r")))]
5635   "TARGET_SH1"
5636   "not  %1,%0"
5637   "&& can_create_pseudo_p ()"
5638   [(set (reg:SI T_REG) (ge:SI (match_dup 1) (const_int 0)))
5639    (set (match_dup 0) (reg:SI T_REG))]
5641 /* PR 54685
5642    If the result of 'unsigned int <= 0x7FFFFFFF' ends up as the following
5643    sequence:
5645      (set (reg0) (not:SI (reg0) (reg1)))
5646      (parallel [(set (reg2) (lshiftrt:SI (reg0) (const_int 31)))
5647                 (clobber (reg:SI T_REG))])
5649    ... match and combine the sequence manually in the split pass after the
5650    combine pass.  Notice that combine does try the target pattern of this
5651    split, but if the pattern is added it interferes with other patterns, in
5652    particular with the div0s comparisons.
5653    This could also be done with a peephole but doing it here before register
5654    allocation can save one temporary.
5655    When we're here, the not:SI pattern obviously has been matched already
5656    and we only have to see whether the following insn is the left shift.  */
5658   rtx i = next_nonnote_insn_bb (curr_insn);
5659   if (i == NULL_RTX || !NONJUMP_INSN_P (i))
5660     FAIL;
5662   rtx p = PATTERN (i);
5663   if (GET_CODE (p) != PARALLEL || XVECLEN (p, 0) != 2)
5664     FAIL;
5666   rtx p0 = XVECEXP (p, 0, 0);
5667   rtx p1 = XVECEXP (p, 0, 1);
5669   if (/* (set (reg2) (lshiftrt:SI (reg0) (const_int 31)))  */
5670       GET_CODE (p0) == SET
5671       && GET_CODE (XEXP (p0, 1)) == LSHIFTRT
5672       && REG_P (XEXP (XEXP (p0, 1), 0))
5673       && REGNO (XEXP (XEXP (p0, 1), 0)) == REGNO (operands[0])
5674       && CONST_INT_P (XEXP (XEXP (p0, 1), 1))
5675       && INTVAL (XEXP (XEXP (p0, 1), 1)) == 31
5677       /* (clobber (reg:SI T_REG))  */
5678       && GET_CODE (p1) == CLOBBER && REG_P (XEXP (p1, 0))
5679       && REGNO (XEXP (p1, 0)) == T_REG)
5680     {
5681       operands[0] = XEXP (p0, 0);
5682       set_insn_deleted (i);
5683     }
5684   else
5685     FAIL;
5687   [(set_attr "type" "arith")])
5689 (define_expand "one_cmpldi2"
5690   [(set (match_operand:DI 0 "arith_reg_dest" "")
5691         (xor:DI (match_operand:DI 1 "arith_reg_operand" "")
5692                 (const_int -1)))]
5693   "TARGET_SHMEDIA" "")
5695 (define_expand "abs<mode>2"
5696   [(parallel [(set (match_operand:SIDI 0 "arith_reg_dest")
5697                    (abs:SIDI (match_operand:SIDI 1 "arith_reg_operand")))
5698               (clobber (reg:SI T_REG))])]
5699   "TARGET_SH1")
5701 (define_insn_and_split "*abs<mode>2"
5702   [(set (match_operand:SIDI 0 "arith_reg_dest")
5703         (abs:SIDI (match_operand:SIDI 1 "arith_reg_operand")))
5704    (clobber (reg:SI T_REG))]
5705   "TARGET_SH1"
5706   "#"
5707   "&& can_create_pseudo_p ()"
5708   [(const_int 0)]
5710   if (<MODE>mode == SImode)
5711     emit_insn (gen_cmpgesi_t (operands[1], const0_rtx));
5712   else
5713     {
5714       rtx high_src = gen_highpart (SImode, operands[1]);
5715       emit_insn (gen_cmpgesi_t (high_src, const0_rtx));
5716     }
5718   emit_insn (gen_neg<mode>_cond (operands[0], operands[1], operands[1],
5719                                  const1_rtx));
5720   DONE;
5723 (define_insn_and_split "*negabs<mode>2"
5724   [(set (match_operand:SIDI 0 "arith_reg_dest")
5725         (neg:SIDI (abs:SIDI (match_operand:SIDI 1 "arith_reg_operand"))))
5726    (clobber (reg:SI T_REG))]
5727   "TARGET_SH1"
5728   "#"
5729   "&& can_create_pseudo_p ()"
5730   [(const_int 0)]
5732   if (<MODE>mode == SImode)
5733     emit_insn (gen_cmpgesi_t (operands[1], const0_rtx));
5734   else
5735     {
5736       rtx high_src = gen_highpart (SImode, operands[1]);
5737       emit_insn (gen_cmpgesi_t (high_src, const0_rtx));
5738     }
5740   emit_insn (gen_neg<mode>_cond (operands[0], operands[1], operands[1],
5741                                  const0_rtx));
5742   DONE;
5745 ;; The SH4 202 can do zero-offset branches without pipeline stalls.
5746 ;; This can be used as some kind of conditional execution, which is useful
5747 ;; for abs.
5748 ;; Actually the instruction scheduling should decide whether to use a
5749 ;; zero-offset branch or not for any generic case involving a single
5750 ;; instruction on SH4 202.
5751 (define_insn_and_split "negsi_cond"
5752   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
5753         (if_then_else
5754           (eq:SI (reg:SI T_REG) (match_operand:SI 3 "const_int_operand" "M,N"))
5755           (match_operand:SI 1 "arith_reg_operand" "0,0")
5756           (neg:SI (match_operand:SI 2 "arith_reg_operand" "r,r"))))]
5757   "TARGET_SH1 && TARGET_ZDCBRANCH"
5759   static const char* alt[] =
5760   {
5761        "bt      0f"     "\n"
5762     "   neg     %2,%0"  "\n"
5763     "0:",
5765        "bf      0f"     "\n"
5766     "   neg     %2,%0"  "\n"
5767     "0:"
5768   };
5769   return alt[which_alternative];
5771   "TARGET_SH1 && ! TARGET_ZDCBRANCH"
5772   [(const_int 0)]
5774   rtx skip_neg_label = gen_label_rtx ();
5776   emit_move_insn (operands[0], operands[1]);
5778   emit_jump_insn (INTVAL (operands[3])
5779                   ? gen_branch_true (skip_neg_label)
5780                   : gen_branch_false (skip_neg_label));
5782   emit_label_after (skip_neg_label,
5783                     emit_insn (gen_negsi2 (operands[0], operands[1])));
5784   DONE;
5786   [(set_attr "type" "arith") ;; poor approximation
5787    (set_attr "length" "4")])
5789 (define_insn_and_split "negdi_cond"
5790   [(set (match_operand:DI 0 "arith_reg_dest")
5791         (if_then_else
5792           (eq:SI (reg:SI T_REG) (match_operand:SI 3 "const_int_operand"))
5793           (match_operand:DI 1 "arith_reg_operand")
5794           (neg:DI (match_operand:DI 2 "arith_reg_operand"))))
5795    (clobber (reg:SI T_REG))]
5796   "TARGET_SH1"
5797   "#"
5798   "&& can_create_pseudo_p ()"
5799   [(const_int 0)]
5801   rtx skip_neg_label = gen_label_rtx ();
5803   emit_move_insn (operands[0], operands[1]);
5805   emit_jump_insn (INTVAL (operands[3]) 
5806                   ? gen_branch_true (skip_neg_label)
5807                   : gen_branch_false (skip_neg_label));
5809   if (!INTVAL (operands[3]))
5810     emit_insn (gen_clrt ());
5812   emit_insn (gen_negc (gen_lowpart (SImode, operands[0]),
5813                        gen_lowpart (SImode, operands[1])));
5814   emit_label_after (skip_neg_label,
5815                     emit_insn (gen_negc (gen_highpart (SImode, operands[0]),
5816                                          gen_highpart (SImode, operands[1]))));
5817   DONE;
5820 (define_expand "bswapsi2"
5821   [(set (match_operand:SI 0 "arith_reg_dest" "")
5822         (bswap:SI (match_operand:SI 1 "arith_reg_operand" "")))]
5823   "TARGET_SH1"
5825   if (! can_create_pseudo_p ())
5826     FAIL;
5827   else
5828     {
5829       rtx tmp0 = gen_reg_rtx (SImode);
5830       rtx tmp1 = gen_reg_rtx (SImode);
5832       emit_insn (gen_swapbsi2 (tmp0, operands[1]));
5833       emit_insn (gen_rotlsi3_16 (tmp1, tmp0));
5834       emit_insn (gen_swapbsi2 (operands[0], tmp1));
5835       DONE;
5836     }
5839 (define_insn "swapbsi2"
5840   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5841         (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "r")
5842                         (const_int 4294901760))
5843                 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8))
5844                                 (const_int 65280))
5845                         (and:SI (ashiftrt:SI (match_dup 1) (const_int 8))
5846                                 (const_int 255)))))]
5847   "TARGET_SH1"
5848   "swap.b       %1,%0"
5849   [(set_attr "type" "arith")])
5851 ;; The *swapbisi2_and_shl8 pattern helps the combine pass simplifying
5852 ;; partial byte swap expressions such as...
5853 ;;   ((x & 0xFF) << 8) | ((x >> 8) & 0xFF).
5854 ;; ...which are currently not handled by the tree optimizers.
5855 ;; The combine pass will not initially try to combine the full expression,
5856 ;; but only some sub-expressions.  In such a case the *swapbisi2_and_shl8
5857 ;; pattern acts as an intermediate pattern that will eventually lead combine
5858 ;; to the swapbsi2 pattern above.
5859 ;; As a side effect this also improves code that does (x & 0xFF) << 8
5860 ;; or (x << 8) & 0xFF00.
5861 (define_insn_and_split "*swapbisi2_and_shl8"
5862   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5863         (ior:SI (and:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "r")
5864                                    (const_int 8))
5865                         (const_int 65280))
5866                 (match_operand:SI 2 "arith_reg_operand" "r")))]
5867   "TARGET_SH1 && ! reload_in_progress && ! reload_completed"
5868   "#"
5869   "&& can_create_pseudo_p ()"
5870   [(const_int 0)]
5872   rtx tmp0 = gen_reg_rtx (SImode);
5873   rtx tmp1 = gen_reg_rtx (SImode);
5875   emit_insn (gen_zero_extendqisi2 (tmp0, gen_lowpart (QImode, operands[1])));
5876   emit_insn (gen_swapbsi2 (tmp1, tmp0));
5877   emit_insn (gen_iorsi3 (operands[0], tmp1, operands[2]));
5878   DONE;
5881 ;; The *swapbhisi2 pattern is, like the *swapbisi2_and_shl8 pattern, another
5882 ;; intermediate pattern that will help the combine pass arriving at swapbsi2.
5883 (define_insn_and_split "*swapbhisi2"
5884   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5885         (ior:SI (and:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "r")
5886                                    (const_int 8))
5887                         (const_int 65280))
5888                 (zero_extract:SI (match_dup 1) (const_int 8) (const_int 8))))]
5889   "TARGET_SH1 && ! reload_in_progress && ! reload_completed"
5890   "#"
5891   "&& can_create_pseudo_p ()"
5892   [(const_int 0)]
5894   rtx tmp = gen_reg_rtx (SImode);
5896   emit_insn (gen_zero_extendhisi2 (tmp, gen_lowpart (HImode, operands[1])));
5897   emit_insn (gen_swapbsi2 (operands[0], tmp));
5898   DONE;
5901 ;; In some cases the swapbsi2 pattern might leave a sequence such as...
5902 ;;   swap.b  r4,r4
5903 ;;   mov     r4,r0
5905 ;; which can be simplified to...
5906 ;;   swap.b  r4,r0
5907 (define_peephole2
5908   [(set (match_operand:SI 0 "arith_reg_dest" "")
5909         (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "")
5910                         (const_int 4294901760))
5911                 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8))
5912                                 (const_int 65280))
5913                         (and:SI (ashiftrt:SI (match_dup 1) (const_int 8))
5914                                 (const_int 255)))))
5915    (set (match_operand:SI 2 "arith_reg_dest" "")
5916         (match_dup 0))]
5917   "TARGET_SH1 && peep2_reg_dead_p (2, operands[0])"
5918   [(set (match_dup 2)
5919         (ior:SI (and:SI (match_operand:SI 1 "arith_reg_operand" "")
5920                         (const_int 4294901760))
5921                 (ior:SI (and:SI (ashift:SI (match_dup 1) (const_int 8))
5922                                 (const_int 65280))
5923                         (and:SI (ashiftrt:SI (match_dup 1) (const_int 8))
5924                                 (const_int 255)))))])
5926 ;; -------------------------------------------------------------------------
5927 ;; Zero extension instructions
5928 ;; -------------------------------------------------------------------------
5930 (define_insn "zero_extendsidi2"
5931   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
5932         (zero_extend:DI (match_operand:SI 1 "extend_reg_operand" "r")))]
5933   "TARGET_SHMEDIA"
5934   "addz.l       %1, r63, %0"
5935   [(set_attr "type" "arith_media")
5936    (set_attr "highpart" "extend")])
5938 (define_insn "zero_extendhidi2"
5939   [(set (match_operand:DI 0 "register_operand" "=r,r")
5940         (zero_extend:DI (match_operand:HI 1 "general_extend_operand" "r,m")))]
5941   "TARGET_SHMEDIA"
5942   "@
5943         #
5944         ld%M1.uw        %m1, %0"
5945   [(set_attr "type" "*,load_media")
5946    (set (attr "highpart")
5947         (cond [(match_test "sh_contains_memref_p (insn)")
5948                (const_string "user")]
5949               (const_string "ignore")))])
5951 (define_split
5952   [(set (match_operand:DI 0 "register_operand" "")
5953         (zero_extend:DI (match_operand:HI 1 "extend_reg_operand" "")))]
5954   "TARGET_SHMEDIA && reload_completed"
5955   [(set (match_dup 0) (ashift:DI (subreg:DI (match_dup 1) 0) (const_int 48)))
5956    (set (match_dup 0) (lshiftrt:DI (match_dup 0) (const_int 48)))]
5958   if (GET_CODE (operands[1]) == TRUNCATE)
5959     operands[1] = XEXP (operands[1], 0);
5962 ;; ??? when a truncated input to a zero_extend is reloaded, reload will
5963 ;; reload the entire truncate expression.
5964 (define_insn_and_split "*loaddi_trunc"
5965   [(set (match_operand 0 "any_register_operand" "=r")
5966         (truncate (match_operand:DI 1 "memory_operand" "m")))]
5967   "TARGET_SHMEDIA && reload_completed"
5968   "#"
5969   "TARGET_SHMEDIA && reload_completed"
5970   [(set (match_dup 0) (match_dup 1))]
5972   operands[0] = gen_rtx_REG (DImode, true_regnum (operands[0]));
5975 (define_insn "zero_extendqidi2"
5976   [(set (match_operand:DI 0 "register_operand" "=r,r")
5977         (zero_extend:DI (match_operand:QI 1 "general_extend_operand" "r,m")))]
5978   "TARGET_SHMEDIA"
5979   "@
5980         andi    %1, 255, %0
5981         ld%M1.ub        %m1, %0"
5982   [(set_attr "type" "arith_media,load_media")
5983    (set (attr "highpart")
5984         (cond [(match_test "sh_contains_memref_p (insn)")
5985                (const_string "user")]
5986               (const_string "ignore")))])
5988 (define_expand "zero_extend<mode>si2"
5989   [(set (match_operand:SI 0 "arith_reg_dest")
5990         (zero_extend:SI (match_operand:QIHI 1 "zero_extend_operand")))])
5992 (define_insn_and_split "*zero_extend<mode>si2_compact"
5993   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
5994         (zero_extend:SI (match_operand:QIHI 1 "arith_reg_operand" "r")))]
5995   "TARGET_SH1"
5996   "extu.<bw>    %1,%0"
5997   "&& can_create_pseudo_p ()"
5998   [(set (match_dup 0) (match_dup 2))]
6000   /* Sometimes combine fails to combine a T bit or negated T bit store to a
6001      reg with a following zero extension.  In the split pass after combine,
6002      try to figure out how the extended reg was set.  If it originated from
6003      the T bit we can replace the zero extension with a reg move, which will
6004      be eliminated.  Notice that this also helps the *cbranch_t splitter when
6005      it tries to post-combine tests and conditional branches, as it does not
6006      check for zero extensions.  */
6007   operands[2] = sh_try_omit_signzero_extend (operands[1], curr_insn);
6008   if (operands[2] == NULL_RTX)
6009     FAIL;
6011   [(set_attr "type" "arith")])
6013 (define_insn "*zero_extendhisi2_media"
6014   [(set (match_operand:SI 0 "register_operand" "=r,r")
6015         (zero_extend:SI (match_operand:HI 1 "general_extend_operand" "r,m")))]
6016   "TARGET_SHMEDIA"
6017   "@
6018         #
6019         ld%M1.uw        %m1, %0"
6020   [(set_attr "type" "arith_media,load_media")
6021    (set (attr "highpart")
6022         (cond [(match_test "sh_contains_memref_p (insn)")
6023                (const_string "user")]
6024               (const_string "ignore")))])
6026 (define_split
6027   [(set (match_operand:SI 0 "register_operand" "")
6028         (zero_extend:SI (match_operand:HI 1 "extend_reg_operand" "")))]
6029   "TARGET_SHMEDIA && reload_completed"
6030   [(set (match_dup 0) (ashift:SI (match_dup 2) (const_int 16)))
6031    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (const_int 16)))]
6033   rtx op1 = operands[1];
6035   if (GET_CODE (op1) == TRUNCATE)
6036     op1 = XEXP (op1, 0);
6037   operands[2]
6038     = simplify_gen_subreg (SImode, op1, GET_MODE (op1),
6039                            subreg_lowpart_offset (SImode, GET_MODE (op1)));
6042 (define_insn "*zero_extendqisi2_media"
6043   [(set (match_operand:SI 0 "register_operand" "=r,r")
6044         (zero_extend:SI (match_operand:QI 1 "general_extend_operand" "r,m")))]
6045   "TARGET_SHMEDIA"
6046   "@
6047         andi    %1, 255, %0
6048         ld%M1.ub        %m1, %0"
6049   [(set_attr "type" "arith_media,load_media")
6050    (set (attr "highpart")
6051         (cond [(match_test "sh_contains_memref_p (insn)")
6052                (const_string "user")]
6053               (const_string "ignore")))])
6055 (define_insn "zero_extendqihi2"
6056   [(set (match_operand:HI 0 "arith_reg_dest" "=r")
6057         (zero_extend:HI (match_operand:QI 1 "arith_reg_operand" "r")))]
6058   "TARGET_SH1"
6059   "extu.b       %1,%0"
6060   [(set_attr "type" "arith")])
6062 ;; SH2A supports two zero extending load instructions: movu.b and movu.w.
6063 ;; They could also be used for simple memory addresses like @Rn by setting
6064 ;; the displacement value to zero.  However, doing so too early results in
6065 ;; missed opportunities for other optimizations such as post-inc or index
6066 ;; addressing loads.
6067 ;; Although the 'zero_extend_movu_operand' predicate does not allow simple
6068 ;; register addresses (an address without a displacement, index, post-inc),
6069 ;; zero-displacement addresses might be generated during reload, wich are
6070 ;; simplified to simple register addresses in turn.  Thus, we have to
6071 ;; provide the Sdd and Sra alternatives in the patterns.
6072 (define_insn "*zero_extend<mode>si2_disp_mem"
6073   [(set (match_operand:SI 0 "arith_reg_dest" "=r,r")
6074         (zero_extend:SI
6075           (match_operand:QIHI 1 "zero_extend_movu_operand" "Sdd,Sra")))]
6076   "TARGET_SH2A"
6077   "@
6078         movu.<bw>       %1,%0
6079         movu.<bw>       @(0,%t1),%0"
6080   [(set_attr "type" "load")
6081    (set_attr "length" "4")])
6083 ;; Convert the zero extending loads in sequences such as:
6084 ;;      movu.b  @(1,r5),r0      movu.w  @(2,r5),r0
6085 ;;      mov.b   r0,@(1,r4)      mov.b   r0,@(1,r4)
6087 ;; back to sign extending loads like:
6088 ;;      mov.b   @(1,r5),r0      mov.w   @(2,r5),r0
6089 ;;      mov.b   r0,@(1,r4)      mov.b   r0,@(1,r4)
6091 ;; if the extension type is irrelevant.  The sign extending mov.{b|w} insn
6092 ;; is only 2 bytes in size if the displacement is {K04|K05}.
6093 ;; If the displacement is greater it doesn't matter, so we convert anyways.
6094 (define_peephole2
6095   [(set (match_operand:SI 0 "arith_reg_dest" "")
6096         (zero_extend:SI (match_operand 1 "displacement_mem_operand" "")))
6097    (set (match_operand 2 "nonimmediate_operand" "")
6098         (match_operand 3 "arith_reg_operand" ""))]
6099   "TARGET_SH2A
6100    && REGNO (operands[0]) == REGNO (operands[3])
6101    && peep2_reg_dead_p (2, operands[0])
6102    && GET_MODE_SIZE (GET_MODE (operands[2]))
6103       <= GET_MODE_SIZE (GET_MODE (operands[1]))"
6104   [(set (match_dup 0) (sign_extend:SI (match_dup 1)))
6105    (set (match_dup 2) (match_dup 3))])
6107 ;; Fold sequences such as
6108 ;;      mov.b   @r3,r7
6109 ;;      extu.b  r7,r7
6110 ;; into
6111 ;;      movu.b  @(0,r3),r7
6112 ;; This does not reduce the code size but the number of instructions is
6113 ;; halved, which results in faster code.
6114 (define_peephole2
6115   [(set (match_operand:SI 0 "arith_reg_dest" "")
6116         (sign_extend:SI (match_operand 1 "simple_mem_operand" "")))
6117    (set (match_operand:SI 2 "arith_reg_dest" "")
6118         (zero_extend:SI (match_operand 3 "arith_reg_operand" "")))]
6119   "TARGET_SH2A
6120    && GET_MODE (operands[1]) == GET_MODE (operands[3])
6121    && (GET_MODE (operands[1]) == QImode || GET_MODE (operands[1]) == HImode)
6122    && REGNO (operands[0]) == REGNO (operands[3])
6123    && (REGNO (operands[2]) == REGNO (operands[0])
6124        || peep2_reg_dead_p (2, operands[0]))"
6125   [(set (match_dup 2) (zero_extend:SI (match_dup 4)))]
6127   operands[4]
6128     = replace_equiv_address (operands[1],
6129                              gen_rtx_PLUS (SImode, XEXP (operands[1], 0),
6130                                            const0_rtx));
6133 ;; -------------------------------------------------------------------------
6134 ;; Sign extension instructions
6135 ;; -------------------------------------------------------------------------
6137 ;; ??? This should be a define expand.
6138 ;; ??? Or perhaps it should be dropped?
6140 ;; convert_move generates good code for SH[1-4].
6141 (define_insn "extendsidi2"
6142   [(set (match_operand:DI 0 "register_operand" "=r,r,r")
6143         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "r,m,?f")))]
6144   "TARGET_SHMEDIA"
6145   "@
6146         add.l   %1, r63, %0
6147         ld%M1.l %m1, %0
6148         fmov.sl %1, %0"
6149   [(set_attr "type" "arith_media,load_media,fpconv_media")
6150    (set (attr "highpart")
6151         (cond [(match_test "sh_contains_memref_p (insn)")
6152                (const_string "user")]
6153               (const_string "extend")))])
6155 (define_insn "extendhidi2"
6156   [(set (match_operand:DI 0 "register_operand" "=r,r")
6157         (sign_extend:DI (match_operand:HI 1 "general_extend_operand" "r,m")))]
6158   "TARGET_SHMEDIA"
6159   "@
6160         #
6161         ld%M1.w %m1, %0"
6162   [(set_attr "type" "*,load_media")
6163    (set (attr "highpart")
6164         (cond [(match_test "sh_contains_memref_p (insn)")
6165                (const_string "user")]
6166               (const_string "ignore")))])
6168 (define_split
6169   [(set (match_operand:DI 0 "register_operand" "")
6170         (sign_extend:DI (match_operand:HI 1 "extend_reg_operand" "")))]
6171   "TARGET_SHMEDIA && reload_completed"
6172   [(set (match_dup 0) (ashift:DI (subreg:DI (match_dup 1) 0) (const_int 48)))
6173    (set (match_dup 0) (ashiftrt:DI (match_dup 0) (const_int 48)))]
6175   if (GET_CODE (operands[1]) == TRUNCATE)
6176     operands[1] = XEXP (operands[1], 0);
6179 (define_insn "extendqidi2"
6180   [(set (match_operand:DI 0 "register_operand" "=r,r")
6181         (sign_extend:DI (match_operand:QI 1 "general_extend_operand" "r,m")))]
6182   "TARGET_SHMEDIA"
6183   "@
6184         #
6185         ld%M1.b %m1, %0"
6186   [(set_attr "type" "*,load_media")
6187    (set (attr "highpart")
6188         (cond [(match_test "sh_contains_memref_p (insn)")
6189                (const_string "user")]
6190               (const_string "ignore")))])
6192 (define_split
6193   [(set (match_operand:DI 0 "register_operand" "")
6194         (sign_extend:DI (match_operand:QI 1 "extend_reg_operand" "")))]
6195   "TARGET_SHMEDIA && reload_completed"
6196   [(set (match_dup 0) (ashift:DI (subreg:DI (match_dup 1) 0) (const_int 56)))
6197    (set (match_dup 0) (ashiftrt:DI (match_dup 0) (const_int 56)))]
6199   if (GET_CODE (operands[1]) == TRUNCATE)
6200     operands[1] = XEXP (operands[1], 0);
6203 (define_expand "extend<mode>si2"
6204   [(set (match_operand:SI 0 "arith_reg_dest")
6205         (sign_extend:SI (match_operand:QIHI 1 "general_extend_operand")))])
6207 (define_insn "*extendhisi2_media"
6208   [(set (match_operand:SI 0 "register_operand" "=r,r")
6209         (sign_extend:SI (match_operand:HI 1 "general_extend_operand" "r,m")))]
6210   "TARGET_SHMEDIA"
6211   "@
6212         #
6213         ld%M1.w %m1, %0"
6214   [(set_attr "type" "arith_media,load_media")
6215    (set (attr "highpart")
6216         (cond [(match_test "sh_contains_memref_p (insn)")
6217                (const_string "user")]
6218               (const_string "ignore")))])
6220 (define_split
6221   [(set (match_operand:SI 0 "register_operand" "")
6222         (sign_extend:SI (match_operand:HI 1 "extend_reg_operand" "")))]
6223   "TARGET_SHMEDIA && reload_completed"
6224   [(set (match_dup 0) (ashift:SI (match_dup 2) (const_int 16)))
6225    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (const_int 16)))]
6227   rtx op1 = operands[1];
6228   if (GET_CODE (op1) == TRUNCATE)
6229     op1 = XEXP (op1, 0);
6230   operands[2]
6231     = simplify_gen_subreg (SImode, op1, GET_MODE (op1),
6232                            subreg_lowpart_offset (SImode, GET_MODE (op1)));
6235 (define_insn_and_split "*extend<mode>si2_compact_reg"
6236   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
6237         (sign_extend:SI (match_operand:QIHI 1 "arith_reg_operand" "r")))]
6238   "TARGET_SH1"
6239   "exts.<bw>    %1,%0"
6240   "&& can_create_pseudo_p ()"
6241   [(set (match_dup 0) (match_dup 2))]
6243   /* Sometimes combine fails to combine a T bit or negated T bit store to a
6244      reg with a following sign extension.  In the split pass after combine,
6245      try to figure the extended reg was set.  If it originated from the T
6246      bit we can replace the sign extension with a reg move, which will be
6247      eliminated.  */
6248   operands[2] = sh_try_omit_signzero_extend (operands[1], curr_insn);
6249   if (operands[2] == NULL_RTX)
6250     FAIL;
6252   [(set_attr "type" "arith")])
6254 ;; FIXME: Fold non-SH2A and SH2A alternatives with "enabled" attribute.
6255 ;; See movqi insns.
6256 (define_insn "*extend<mode>si2_compact_mem_disp"
6257   [(set (match_operand:SI 0 "arith_reg_dest" "=z,r")
6258         (sign_extend:SI
6259           (mem:QIHI
6260             (plus:SI
6261               (match_operand:SI 1 "arith_reg_operand" "%r,r")
6262               (match_operand:SI 2 "const_int_operand" "<disp04>,N")))))]
6263   "TARGET_SH1 && ! TARGET_SH2A
6264    && sh_legitimate_index_p (<MODE>mode, operands[2], false, true)"
6265   "@
6266         mov.<bw>        @(%O2,%1),%0
6267         mov.<bw>        @%1,%0"
6268   [(set_attr "type" "load")])
6270 (define_insn "*extend<mode>si2_compact_mem_disp"
6271   [(set (match_operand:SI 0 "arith_reg_dest" "=z,r,r")
6272         (sign_extend:SI
6273           (mem:QIHI
6274             (plus:SI
6275               (match_operand:SI 1 "arith_reg_operand" "%r,r,r")
6276               (match_operand:SI 2 "const_int_operand" "<disp04>,N,<disp12>")))))]
6277   "TARGET_SH2A && sh_legitimate_index_p (<MODE>mode, operands[2], true, true)"
6278   "@
6279         mov.<bw>        @(%O2,%1),%0
6280         mov.<bw>        @%1,%0
6281         mov.<bw>        @(%O2,%1),%0"
6282   [(set_attr "type" "load")
6283    (set_attr "length" "2,2,4")])
6285 ;; The *_snd patterns will take care of other QImode/HImode addressing
6286 ;; modes than displacement addressing.  They must be defined _after_ the
6287 ;; displacement addressing patterns.  Otherwise the displacement addressing
6288 ;; patterns will not be picked.
6289 (define_insn "*extend<mode>si2_compact_snd"
6290   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
6291         (sign_extend:SI
6292           (match_operand:QIHI 1 "movsrc_no_disp_mem_operand" "Snd")))]
6293   "TARGET_SH1"
6294   "mov.<bw>     %1,%0"
6295   [(set_attr "type" "load")])
6297 (define_insn "*extendqisi2_media"
6298   [(set (match_operand:SI 0 "register_operand" "=r,r")
6299         (sign_extend:SI (match_operand:QI 1 "general_extend_operand" "r,m")))]
6300   "TARGET_SHMEDIA"
6301   "@
6302         #
6303         ld%M1.b %m1, %0"
6304   [(set_attr "type" "arith_media,load_media")
6305    (set (attr "highpart")
6306         (cond [(match_test "sh_contains_memref_p (insn)")
6307                (const_string "user")]
6308               (const_string "ignore")))])
6310 (define_split
6311   [(set (match_operand:SI 0 "register_operand" "")
6312         (sign_extend:SI (match_operand:QI 1 "extend_reg_operand" "")))]
6313   "TARGET_SHMEDIA && reload_completed"
6314   [(set (match_dup 0) (ashift:SI (match_dup 2) (const_int 24)))
6315    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (const_int 24)))]
6317   rtx op1 = operands[1];
6318   if (GET_CODE (op1) == TRUNCATE)
6319     op1 = XEXP (op1, 0);
6320   operands[2]
6321     = simplify_gen_subreg (SImode, op1, GET_MODE (op1),
6322                            subreg_lowpart_offset (SImode, GET_MODE (op1)));
6325 (define_expand "extendqihi2"
6326   [(set (match_operand:HI 0 "arith_reg_dest")
6327         (sign_extend:HI (match_operand:QI 1 "arith_reg_operand")))]
6328   "TARGET_SH1")
6330 (define_insn "*extendqihi2_compact_reg"
6331   [(set (match_operand:HI 0 "arith_reg_dest" "=r")
6332         (sign_extend:HI (match_operand:QI 1 "arith_reg_operand" "r")))]
6333   "TARGET_SH1"
6334   "exts.b       %1,%0"
6335   [(set_attr "type" "arith")])
6337 ;; It would seem useful to combine the truncXi patterns into the movXi
6338 ;; patterns, but unary operators are ignored when matching constraints,
6339 ;; so we need separate patterns.
6340 (define_insn "truncdisi2"
6341   [(set (match_operand:SI 0 "general_movdst_operand" "=r,m,m,f,r,f")
6342         (truncate:SI (match_operand:DI 1 "register_operand" "r,r,f,r,f,f")))]
6343   "TARGET_SHMEDIA"
6344   "@
6345         add.l   %1, r63, %0
6346         st%M0.l %m0, %1
6347         fst%M0.s        %m0, %T1
6348         fmov.ls %1, %0
6349         fmov.sl %T1, %0
6350         fmov.s  %T1, %0"
6351   [(set_attr "type" "arith_media,store_media,fstore_media,fload_media,
6352                      fpconv_media,fmove_media")
6353    (set (attr "highpart")
6354         (cond [(match_test "sh_contains_memref_p (insn)")
6355                (const_string "user")]
6356               (const_string "extend")))])
6358 (define_insn "truncdihi2"
6359   [(set (match_operand:HI 0 "general_movdst_operand" "=?r,m")
6360         (truncate:HI (match_operand:DI 1 "register_operand" "r,r")))]
6361   "TARGET_SHMEDIA"
6363   static const char* alt[] =
6364   {
6365        "shlli   %1,48,%0"       "\n"
6366     "   shlri   %0,48,%0",
6368        "st%M0.w %m0, %1"
6369   };
6370   return alt[which_alternative];
6372   [(set_attr "type"   "arith_media,store_media")
6373    (set_attr "length" "8,4")
6374    (set (attr "highpart")
6375         (cond [(match_test "sh_contains_memref_p (insn)")
6376                (const_string "user")]
6377               (const_string "extend")))])
6379 ; N.B. This should agree with LOAD_EXTEND_OP and movqi.
6380 ; Because we use zero extension, we can't provide signed QImode compares
6381 ; using a simple compare or conditional branch insn.
6382 (define_insn "truncdiqi2"
6383   [(set (match_operand:QI 0 "general_movdst_operand" "=r,m")
6384         (truncate:QI (match_operand:DI 1 "register_operand" "r,r")))]
6385   "TARGET_SHMEDIA"
6386   "@
6387         andi    %1, 255, %0
6388         st%M0.b %m0, %1"
6389   [(set_attr "type"   "arith_media,store")
6390    (set (attr "highpart")
6391         (cond [(match_test "sh_contains_memref_p (insn)")
6392                (const_string "user")]
6393               (const_string "extend")))])
6395 ;; -------------------------------------------------------------------------
6396 ;; Move instructions
6397 ;; -------------------------------------------------------------------------
6399 ;; define push and pop so it is easy for sh.c
6400 ;; We can't use push and pop on SHcompact because the stack must always
6401 ;; be 8-byte aligned.
6402 (define_expand "push"
6403   [(set (mem:SI (pre_dec:SI (reg:SI SP_REG)))
6404         (match_operand:SI 0 "register_operand" "r,l,x"))]
6405   "TARGET_SH1 && ! TARGET_SH5"
6406   "")
6408 (define_expand "pop"
6409   [(set (match_operand:SI 0 "register_operand" "=r,l,x")
6410         (mem:SI (post_inc:SI (reg:SI SP_REG))))]
6411   "TARGET_SH1 && ! TARGET_SH5"
6412   "")
6414 (define_expand "push_e"
6415   [(parallel [(set (mem:SF (pre_dec:SI (reg:SI SP_REG)))
6416                    (match_operand:SF 0 "" ""))
6417               (use (reg:SI FPSCR_MODES_REG))
6418               (clobber (scratch:SI))])]
6419   "TARGET_SH1 && ! TARGET_SH5"
6420   "")
6422 (define_insn "push_fpul"
6423   [(set (mem:SF (pre_dec:SI (reg:SI SP_REG))) (reg:SF FPUL_REG))]
6424   "TARGET_SH2E && ! TARGET_SH5"
6425   "sts.l        fpul,@-r15"
6426   [(set_attr "type" "fstore")
6427    (set_attr "late_fp_use" "yes")
6428    (set_attr "hit_stack" "yes")])
6430 ;; DFmode pushes for sh4 require a lot of what is defined for movdf_i4,
6431 ;; so use that.
6432 (define_expand "push_4"
6433   [(parallel [(set (mem:DF (pre_dec:SI (reg:SI SP_REG)))
6434                    (match_operand:DF 0 "" ""))
6435               (use (reg:SI FPSCR_MODES_REG))
6436               (clobber (scratch:SI))])]
6437   "TARGET_SH1 && ! TARGET_SH5"
6438   "")
6440 (define_expand "pop_e"
6441   [(parallel [(set (match_operand:SF 0 "" "")
6442               (mem:SF (post_inc:SI (reg:SI SP_REG))))
6443               (use (reg:SI FPSCR_MODES_REG))
6444               (clobber (scratch:SI))])]
6445   "TARGET_SH1 && ! TARGET_SH5"
6446   "")
6448 (define_insn "pop_fpul"
6449   [(set (reg:SF FPUL_REG) (mem:SF (post_inc:SI (reg:SI SP_REG))))]
6450   "TARGET_SH2E && ! TARGET_SH5"
6451   "lds.l        @r15+,fpul"
6452   [(set_attr "type" "load")
6453    (set_attr "hit_stack" "yes")])
6455 (define_expand "pop_4"
6456   [(parallel [(set (match_operand:DF 0 "" "")
6457                    (mem:DF (post_inc:SI (reg:SI SP_REG))))
6458               (use (reg:SI FPSCR_MODES_REG))
6459               (clobber (scratch:SI))])]
6460   "TARGET_SH1 && ! TARGET_SH5"
6461   "")
6463 (define_expand "push_fpscr"
6464   [(const_int 0)]
6465   "TARGET_SH2E"
6467   add_reg_note (
6468     emit_insn (
6469       gen_sts_fpscr (
6470         gen_frame_mem (SImode, gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx)))),
6471     REG_INC, stack_pointer_rtx);
6472   DONE;
6475 (define_expand "pop_fpscr"
6476   [(const_int 0)]
6477   "TARGET_SH2E"
6479   add_reg_note (
6480     emit_insn (
6481       gen_lds_fpscr (
6482         gen_frame_mem (SImode, gen_rtx_POST_INC (Pmode, stack_pointer_rtx)))),
6483     REG_INC, stack_pointer_rtx);
6484   DONE;
6487 ;; The clrt and sett patterns can happen as the result of optimization and
6488 ;; insn expansion.
6489 ;; Comparisons might get simplified to a move of zero or 1 into the T reg.
6490 ;; In this case they might not disappear completely, because the T reg is
6491 ;; a fixed hard reg.
6492 ;; When DImode operations that use the T reg as carry/borrow are split into
6493 ;; individual SImode operations, the T reg is usually cleared before the
6494 ;; first SImode insn.
6495 (define_insn "clrt"
6496   [(set (reg:SI T_REG) (const_int 0))]
6497   "TARGET_SH1"
6498   "clrt"
6499   [(set_attr "type" "mt_group")])
6501 (define_insn "sett"
6502   [(set (reg:SI T_REG) (const_int 1))]
6503   "TARGET_SH1"
6504   "sett"
6505   [(set_attr "type" "mt_group")])
6507 ;; Use the combine pass to transform sequences such as
6508 ;;      mov     r5,r0
6509 ;;      add     #1,r0
6510 ;;      shll2   r0
6511 ;;      mov.l   @(r0,r4),r0
6512 ;; into
6513 ;;      shll2   r5
6514 ;;      add     r4,r5
6515 ;;      mov.l   @(4,r5),r0
6517 ;; See also PR 39423.
6518 ;; Notice that these patterns have a T_REG clobber, because the shift
6519 ;; sequence that will be split out might clobber the T_REG.  Ideally, the
6520 ;; clobber would be added conditionally, depending on the result of
6521 ;; sh_ashlsi_clobbers_t_reg_p.  When splitting out the shifts we must go
6522 ;; through the ashlsi3 expander in order to get the right shift insn --
6523 ;; a T_REG clobbering or non-clobbering shift sequence or dynamic shift.
6524 ;; FIXME: Combine never tries this kind of patterns for DImode.
6525 (define_insn_and_split "*movsi_index_disp_load"
6526   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
6527         (match_operand:SI 1 "mem_index_disp_operand" "m"))
6528    (clobber (reg:SI T_REG))]
6529   "TARGET_SH1"
6530   "#"
6531   "&& can_create_pseudo_p ()"
6532   [(set (match_dup 6) (plus:SI (match_dup 5) (match_dup 3)))
6533    (set (match_dup 0) (match_dup 7))]
6535   rtx mem = operands[1];
6536   rtx plus0_rtx = XEXP (mem, 0);
6537   rtx plus1_rtx = XEXP (plus0_rtx, 0);
6538   rtx mult_rtx = XEXP (plus1_rtx, 0);
6540   operands[1] = XEXP (mult_rtx, 0);
6541   operands[2] = GEN_INT (exact_log2 (INTVAL (XEXP (mult_rtx, 1))));
6542   operands[3] = XEXP (plus1_rtx, 1);
6543   operands[4] = XEXP (plus0_rtx, 1);
6544   operands[5] = gen_reg_rtx (SImode);
6545   operands[6] = gen_reg_rtx (SImode);
6546   operands[7] =
6547     replace_equiv_address (mem,
6548                            gen_rtx_PLUS (SImode, operands[6], operands[4]));
6550   emit_insn (gen_ashlsi3 (operands[5], operands[1], operands[2]));
6553 (define_insn_and_split "*movhi_index_disp_load"
6554   [(set (match_operand:SI 0 "arith_reg_dest")
6555         (SZ_EXTEND:SI (match_operand:HI 1 "mem_index_disp_operand")))
6556    (clobber (reg:SI T_REG))]
6557   "TARGET_SH1"
6558   "#"
6559   "&& can_create_pseudo_p ()"
6560   [(const_int 0)]
6562   rtx mem = operands[1];
6563   rtx plus0_rtx = XEXP (mem, 0);
6564   rtx plus1_rtx = XEXP (plus0_rtx, 0);
6565   rtx mult_rtx = XEXP (plus1_rtx, 0);
6567   rtx op_1 = XEXP (mult_rtx, 0);
6568   rtx op_2 = GEN_INT (exact_log2 (INTVAL (XEXP (mult_rtx, 1))));
6569   rtx op_3 = XEXP (plus1_rtx, 1);
6570   rtx op_4 = XEXP (plus0_rtx, 1);
6571   rtx op_5 = gen_reg_rtx (SImode);
6572   rtx op_6 = gen_reg_rtx (SImode);
6573   rtx op_7 = replace_equiv_address (mem, gen_rtx_PLUS (SImode, op_6, op_4));
6575   emit_insn (gen_ashlsi3 (op_5, op_1, op_2));
6576   emit_insn (gen_addsi3 (op_6, op_5, op_3));
6578   if (<CODE> == SIGN_EXTEND)
6579     {
6580       emit_insn (gen_extendhisi2 (operands[0], op_7));
6581       DONE;
6582     }
6583   else if (<CODE> == ZERO_EXTEND)
6584     {
6585       /* On SH2A the movu.w insn can be used for zero extending loads.  */
6586       if (TARGET_SH2A)
6587         emit_insn (gen_zero_extendhisi2 (operands[0], op_7));
6588       else
6589         {
6590           emit_insn (gen_extendhisi2 (operands[0], op_7));
6591           emit_insn (gen_zero_extendhisi2 (operands[0],
6592                                            gen_lowpart (HImode, operands[0])));
6593         }
6594       DONE;
6595     }
6596   else
6597     FAIL;
6600 (define_insn_and_split "*mov<mode>_index_disp_store"
6601   [(set (match_operand:HISI 0 "mem_index_disp_operand" "=m")
6602         (match_operand:HISI 1 "arith_reg_operand" "r"))
6603    (clobber (reg:SI T_REG))]
6604   "TARGET_SH1"
6605   "#"
6606   "&& can_create_pseudo_p ()"
6607   [(set (match_dup 6) (plus:SI (match_dup 5) (match_dup 3)))
6608    (set (match_dup 7) (match_dup 1))]
6610   rtx mem = operands[0];
6611   rtx plus0_rtx = XEXP (mem, 0);
6612   rtx plus1_rtx = XEXP (plus0_rtx, 0);
6613   rtx mult_rtx = XEXP (plus1_rtx, 0);
6615   operands[0] = XEXP (mult_rtx, 0);
6616   operands[2] = GEN_INT (exact_log2 (INTVAL (XEXP (mult_rtx, 1))));
6617   operands[3] = XEXP (plus1_rtx, 1);
6618   operands[4] = XEXP (plus0_rtx, 1);
6619   operands[5] = gen_reg_rtx (SImode);
6620   operands[6] = gen_reg_rtx (SImode);
6621   operands[7] =
6622     replace_equiv_address (mem,
6623                            gen_rtx_PLUS (SImode, operands[6], operands[4]));
6625   emit_insn (gen_ashlsi3 (operands[5], operands[0], operands[2]));
6628 ;; t/r must come after r/r, lest reload will try to reload stuff like
6629 ;; (set (subreg:SI (mem:QI (plus:SI (reg:SI SP_REG) (const_int 12)) 0) 0)
6630 ;; (made from (set (subreg:SI (reg:QI ###) 0) ) into T.
6631 (define_insn "movsi_i"
6632   [(set (match_operand:SI 0 "general_movdst_operand"
6633             "=r,r,r,r,r,r,m,<,<,x,l,x,l,r")
6634         (match_operand:SI 1 "general_movsrc_operand"
6635          "Q,r,I08,mr,x,l,r,x,l,r,r,>,>,i"))]
6636   "TARGET_SH1
6637    && ! TARGET_SH2E
6638    && ! TARGET_SH2A
6639    && (register_operand (operands[0], SImode)
6640        || register_operand (operands[1], SImode))"
6641   "@
6642         mov.l   %1,%0
6643         mov     %1,%0
6644         mov     %1,%0
6645         mov.l   %1,%0
6646         sts     %1,%0
6647         sts     %1,%0
6648         mov.l   %1,%0
6649         sts.l   %1,%0
6650         sts.l   %1,%0
6651         lds     %1,%0
6652         lds     %1,%0
6653         lds.l   %1,%0
6654         lds.l   %1,%0
6655         fake    %1,%0"
6656   [(set_attr "type" "pcload_si,move,movi8,load_si,mac_gp,prget,store,mac_mem,
6657                      pstore,gp_mac,prset,mem_mac,pload,pcload_si")
6658    (set_attr "length" "*,*,*,*,*,*,*,*,*,*,*,*,*,*")])
6660 ;; t/r must come after r/r, lest reload will try to reload stuff like
6661 ;; (subreg:SI (reg:SF FR14_REG) 0) into T (compiling stdlib/strtod.c -m3e -O2)
6662 ;; ??? This allows moves from macl to fpul to be recognized, but these moves
6663 ;; will require a reload.
6664 ;; ??? We can't include f/f because we need the proper FPSCR setting when
6665 ;; TARGET_FMOVD is in effect, and mode switching is done before reload.
6666 (define_insn "movsi_ie"
6667   [(set (match_operand:SI 0 "general_movdst_operand"
6668             "=r,r,r,r,r,r,r,r,m,<,<,x,l,x,l,y,<,r,y,r,*f,y,*f,y")
6669         (match_operand:SI 1 "general_movsrc_operand"
6670          "Q,r,I08,I20,I28,mr,x,l,r,x,l,r,r,>,>,>,y,i,r,y,y,*f,*f,y"))]
6671   "(TARGET_SH2E || TARGET_SH2A)
6672    && ((register_operand (operands[0], SImode)
6673         && !fpscr_operand (operands[0], SImode))
6674        || (register_operand (operands[1], SImode)
6675            && !fpscr_operand (operands[1], SImode)))"
6676   "@
6677         mov.l   %1,%0
6678         mov     %1,%0
6679         mov     %1,%0
6680         movi20  %1,%0
6681         movi20s %1,%0
6682         mov.l   %1,%0
6683         sts     %1,%0
6684         sts     %1,%0
6685         mov.l   %1,%0
6686         sts.l   %1,%0
6687         sts.l   %1,%0
6688         lds     %1,%0
6689         lds     %1,%0
6690         lds.l   %1,%0
6691         lds.l   %1,%0
6692         lds.l   %1,%0
6693         sts.l   %1,%0
6694         fake    %1,%0
6695         lds     %1,%0
6696         sts     %1,%0
6697         fsts    fpul,%0
6698         flds    %1,fpul
6699         fmov    %1,%0
6700         ! move optimized away"
6701   [(set_attr "type" "pcload_si,move,movi8,move,move,load_si,mac_gp,prget,store,
6702                      mac_mem,pstore,gp_mac,prset,mem_mac,pload,load,fstore,
6703                      pcload_si,gp_fpul,fpul_gp,fmove,fmove,fmove,nil")
6704    (set_attr "late_fp_use" "*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,yes,*,*,yes,*,*,*,*")
6705    (set_attr_alternative "length"
6706      [(const_int 2)
6707       (const_int 2)
6708       (const_int 2)
6709       (const_int 4)
6710       (const_int 4)
6711       (if_then_else
6712         (match_test "TARGET_SH2A")
6713         (const_int 4) (const_int 2))
6714       (const_int 2)
6715       (const_int 2)
6716       (if_then_else
6717         (match_test "TARGET_SH2A")
6718         (const_int 4) (const_int 2))
6719       (const_int 2)
6720       (const_int 2)
6721       (const_int 2)
6722       (const_int 2)
6723       (const_int 2)
6724       (const_int 2)
6725       (const_int 2)
6726       (const_int 2)
6727       (const_int 2)
6728       (const_int 2)
6729       (const_int 2)
6730       (const_int 2)
6731       (const_int 2)
6732       (const_int 2)
6733       (const_int 0)])])
6735 (define_insn "movsi_i_lowpart"
6736   [(set (strict_low_part
6737           (match_operand:SI 0 "general_movdst_operand" "+r,r,r,r,r,r,m,r"))
6738         (match_operand:SI 1 "general_movsrc_operand" "Q,r,I08,mr,x,l,r,i"))]
6739    "TARGET_SH1
6740     && (register_operand (operands[0], SImode)
6741         || register_operand (operands[1], SImode))"
6742   "@
6743         mov.l   %1,%0
6744         mov     %1,%0
6745         mov     %1,%0
6746         mov.l   %1,%0
6747         sts     %1,%0
6748         sts     %1,%0
6749         mov.l   %1,%0
6750         fake    %1,%0"
6751   [(set_attr "type" "pcload,move,arith,load,mac_gp,prget,store,pcload")])
6753 (define_insn_and_split "load_ra"
6754   [(set (match_operand:SI 0 "general_movdst_operand" "")
6755         (unspec:SI [(match_operand:SI 1 "register_operand" "")] UNSPEC_RA))]
6756   "TARGET_SH1"
6757   "#"
6758   "&& ! currently_expanding_to_rtl"
6759   [(set (match_dup 0) (match_dup 1))]
6761   if (TARGET_SHCOMPACT && crtl->saves_all_registers)
6762     operands[1] = gen_frame_mem (SImode, return_address_pointer_rtx);
6765 ;; The '?'s in the following constraints may not reflect the time taken
6766 ;; to perform the move. They are there to discourage the use of floating-
6767 ;; point registers for storing integer values.
6768 (define_insn "*movsi_media"
6769   [(set (match_operand:SI 0 "general_movdst_operand"
6770                 "=r,r,r,r,m,f?,m,f?,r,f?,*b,r,b")
6771         (match_operand:SI 1 "general_movsrc_operand"
6772          "r,I16Css,nCpg,m,rZ,m,f?,rZ,f?,f?,r,*b,Csy"))]
6773   "TARGET_SHMEDIA_FPU
6774    && (register_operand (operands[0], SImode)
6775        || sh_register_operand (operands[1], SImode)
6776        || GET_CODE (operands[1]) == TRUNCATE)"
6777   "@
6778         add.l   %1, r63, %0
6779         movi    %1, %0
6780         #
6781         ld%M1.l %m1, %0
6782         st%M0.l %m0, %N1
6783         fld%M1.s        %m1, %0
6784         fst%M0.s        %m0, %1
6785         fmov.ls %N1, %0
6786         fmov.sl %1, %0
6787         fmov.s  %1, %0
6788         ptabs   %1, %0
6789         gettr   %1, %0
6790         pt      %1, %0"
6791   [(set_attr "type"   "arith_media,arith_media,*,load_media,store_media,
6792                        fload_media,fstore_media,fload_media,fpconv_media,
6793                        fmove_media,ptabs_media,gettr_media,pt_media")
6794    (set_attr "length" "4,4,8,4,4,4,4,4,4,4,4,4,12")
6795    (set (attr "highpart")
6796         (cond [(match_test "sh_contains_memref_p (insn)")
6797                (const_string "user")]
6798               (const_string "ignore")))])
6800 (define_insn "*movsi_media_nofpu"
6801   [(set (match_operand:SI 0 "general_movdst_operand"
6802                 "=r,r,r,r,m,*b,r,*b")
6803         (match_operand:SI 1 "general_movsrc_operand"
6804          "r,I16Css,nCpg,m,rZ,r,*b,Csy"))]
6805   "TARGET_SHMEDIA
6806    && (register_operand (operands[0], SImode)
6807        || sh_register_operand (operands[1], SImode)
6808        || GET_CODE (operands[1]) == TRUNCATE)"
6809   "@
6810         add.l   %1, r63, %0
6811         movi    %1, %0
6812         #
6813         ld%M1.l %m1, %0
6814         st%M0.l %m0, %N1
6815         ptabs   %1, %0
6816         gettr   %1, %0
6817         pt      %1, %0"
6818   [(set_attr "type" "arith_media,arith_media,*,load_media,store_media,
6819                      ptabs_media,gettr_media,pt_media")
6820    (set_attr "length" "4,4,8,4,4,4,4,12")
6821    (set (attr "highpart")
6822         (cond [(match_test "sh_contains_memref_p (insn)")
6823                (const_string "user")]
6824               (const_string "ignore")))])
6826 (define_expand "movsi_const"
6827   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
6828         (const:SI (unspec:SI [(match_operand:DI 1 "immediate_operand" "s")
6829                               (const_int 16)] UNSPEC_EXTRACT_S16)))
6830    (set (match_dup 0)
6831         (ior:SI (ashift:SI (match_dup 0) (const_int 16))
6832                 (const:SI (unspec:SI [(match_dup 1)
6833                                       (const_int 0)] UNSPEC_EXTRACT_U16))))]
6834   "TARGET_SHMEDIA && reload_completed
6835    && MOVI_SHORI_BASE_OPERAND_P (operands[1])"
6837   if (GET_CODE (operands[1]) == LABEL_REF
6838       && GET_CODE (XEXP (operands[1], 0)) == CODE_LABEL)
6839     LABEL_NUSES (XEXP (operands[1], 0)) += 2;
6840   else if (GOTOFF_P (operands[1]))
6841     {
6842       rtx unspec = XEXP (operands[1], 0);
6844       if (! UNSPEC_GOTOFF_P (unspec))
6845         {
6846           unspec = XEXP (unspec, 0);
6847           if (! UNSPEC_GOTOFF_P (unspec))
6848             abort ();
6849         }
6850       if (GET_CODE (XVECEXP (unspec , 0, 0)) == LABEL_REF
6851           && (GET_CODE (XEXP (XVECEXP (unspec, 0, 0), 0)) == CODE_LABEL))
6852         LABEL_NUSES (XEXP (XVECEXP (unspec, 0, 0), 0)) += 2;
6853     }
6856 (define_expand "movsi_const_16bit"
6857   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
6858         (const:SI (unspec:SI [(match_operand:DI 1 "immediate_operand" "s")
6859                               (const_int 0)] UNSPEC_EXTRACT_S16)))]
6860   "TARGET_SHMEDIA && flag_pic && reload_completed
6861    && GET_CODE (operands[1]) == SYMBOL_REF"
6862   "")
6864 (define_split
6865   [(set (match_operand:SI 0 "arith_reg_dest" "")
6866         (match_operand:SI 1 "immediate_operand" ""))]
6867   "TARGET_SHMEDIA && reload_completed
6868    && MOVI_SHORI_BASE_OPERAND_P (operands[1])"
6869   [(const_int 0)]
6871   rtx insn = emit_insn (gen_movsi_const (operands[0], operands[1]));
6873   set_unique_reg_note (insn, REG_EQUAL, copy_rtx (operands[1]));
6875   DONE;
6878 (define_split
6879   [(set (match_operand:SI 0 "register_operand" "")
6880         (match_operand:SI 1 "immediate_operand" ""))]
6881   "TARGET_SHMEDIA && reload_completed
6882    && ((CONST_INT_P (operands[1])
6883         && ! satisfies_constraint_I16 (operands[1]))
6884        || GET_CODE (operands[1]) == CONST_DOUBLE)"
6885   [(set (subreg:DI (match_dup 0) 0) (match_dup 1))])
6887 (define_expand "movsi"
6888   [(set (match_operand:SI 0 "general_movdst_operand" "")
6889         (match_operand:SI 1 "general_movsrc_operand" ""))]
6890   ""
6892   prepare_move_operands (operands, SImode);
6895 (define_expand "ic_invalidate_line"
6896   [(parallel [(unspec_volatile [(match_operand:SI 0 "register_operand" "+r")
6897                                 (match_dup 1)] UNSPEC_ICACHE)
6898               (clobber (scratch:SI))])]
6899   "TARGET_HARD_SH4 || TARGET_SH5"
6901   if (TARGET_SHMEDIA)
6902     {
6903       emit_insn (gen_ic_invalidate_line_media (operands[0]));
6904       DONE;
6905     }
6906   else if (TARGET_SHCOMPACT)
6907     {
6908       operands[1] = function_symbol (NULL, "__ic_invalidate", SFUNC_STATIC);
6909       operands[1] = force_reg (Pmode, operands[1]);
6910       emit_insn (gen_ic_invalidate_line_compact (operands[0], operands[1]));
6911       DONE;
6912     }
6913   else if (TARGET_SH4A || TARGET_SH4_300)
6914     {
6915       emit_insn (gen_ic_invalidate_line_sh4a (operands[0]));
6916       DONE;
6917     }
6918   operands[0] = force_reg (Pmode, operands[0]);
6919   operands[1] = force_reg (Pmode, GEN_INT (trunc_int_for_mode (0xf0000008,
6920                                                                Pmode)));
6923 ;; The address %0 is assumed to be 4-aligned at least.  Thus, by ORing
6924 ;; 0xf0000008, we get the low-oder bits *1*00 (binary), which fits
6925 ;; the requirement *1*00 for associative address writes.  The alignment of
6926 ;; %0 implies that its least significant bit is cleared,
6927 ;; thus we clear the V bit of a matching entry if there is one.
6928 (define_insn "ic_invalidate_line_i"
6929   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")
6930                      (match_operand:SI 1 "register_operand" "r")]
6931                      UNSPEC_ICACHE)
6932    (clobber (match_scratch:SI 2 "=&r"))]
6933   "TARGET_HARD_SH4"
6935   return       "ocbwb   @%0"    "\n"
6936          "      extu.w  %0,%2"  "\n"
6937          "      or      %1,%2"  "\n"
6938          "      mov.l   %0,@%2";
6940   [(set_attr "length" "8")
6941    (set_attr "type" "cwb")])
6943 (define_insn "ic_invalidate_line_sh4a"
6944   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
6945                     UNSPEC_ICACHE)]
6946   "TARGET_SH4A || TARGET_SH4_300"
6948   return       "ocbwb   @%0"    "\n"
6949          "      synco"          "\n"
6950          "      icbi    @%0";
6952   [(set_attr "length" "16")     ;; FIXME: Why 16 and not 6?  Looks like typo.
6953    (set_attr "type" "cwb")])
6955 ;; ??? could make arg 0 an offsettable memory operand to allow to save
6956 ;; an add in the code that calculates the address.
6957 (define_insn "ic_invalidate_line_media"
6958   [(unspec_volatile [(match_operand 0 "any_register_operand" "r")]
6959                     UNSPEC_ICACHE)]
6960   "TARGET_SHMEDIA"
6962   return       "ocbwb   %0,0"   "\n"
6963          "      synco"          "\n"
6964          "      icbi    %0,0"   "\n"
6965          "      synci";
6967   [(set_attr "length" "16")
6968    (set_attr "type" "invalidate_line_media")])
6970 (define_insn "ic_invalidate_line_compact"
6971   [(unspec_volatile [(match_operand:SI 0 "register_operand" "z")
6972                      (match_operand:SI 1 "register_operand" "r")]
6973                     UNSPEC_ICACHE)
6974    (clobber (reg:SI PR_REG))]
6975   "TARGET_SHCOMPACT"
6976   "jsr @%1%#"
6977   [(set_attr "type" "sfunc")
6978    (set_attr "needs_delay_slot" "yes")])
6980 (define_expand "initialize_trampoline"
6981   [(match_operand:SI 0 "" "")
6982    (match_operand:SI 1 "" "")
6983    (match_operand:SI 2 "" "")]
6984   "TARGET_SHCOMPACT"
6986   rtx sfun, tramp;
6988   tramp = force_reg (Pmode, operands[0]);
6989   sfun = force_reg (Pmode, function_symbol (NULL, "__init_trampoline",
6990                                             SFUNC_STATIC));
6991   emit_move_insn (gen_rtx_REG (SImode, R2_REG), operands[1]);
6992   emit_move_insn (gen_rtx_REG (SImode, R3_REG), operands[2]);
6994   emit_insn (gen_initialize_trampoline_compact (tramp, sfun));
6995   DONE;
6998 (define_insn "initialize_trampoline_compact"
6999   [(unspec_volatile [(match_operand:SI 0 "register_operand" "z")
7000                      (match_operand:SI 1 "register_operand" "r")
7001                      (reg:SI R2_REG) (reg:SI R3_REG)]
7002                     UNSPEC_INIT_TRAMP)
7004    (clobber (reg:SI PR_REG))]
7005   "TARGET_SHCOMPACT"
7006   "jsr @%1%#"
7007   [(set_attr "type" "sfunc")
7008    (set_attr "needs_delay_slot" "yes")])
7010 (define_expand "mov<mode>"
7011   [(set (match_operand:QIHI 0 "general_movdst_operand")
7012         (match_operand:QIHI 1 "general_movsrc_operand"))]
7013   ""
7015  if (can_create_pseudo_p () && CONST_INT_P (operands[1])
7016     && REG_P (operands[0]) && REGNO (operands[0]) != R0_REG)
7017     {
7018         rtx reg = gen_reg_rtx(SImode);
7019         emit_move_insn (reg, operands[1]);
7020         operands[1] = gen_lowpart (<MODE>mode, reg);
7021     }
7023   prepare_move_operands (operands, <MODE>mode);
7026 ;; Specifying the displacement addressing load / store patterns separately
7027 ;; before the generic movqi / movhi pattern allows controlling the order
7028 ;; in which load / store insns are selected in a more fine grained way.
7029 ;; FIXME: The non-SH2A and SH2A variants should be combined by adding
7030 ;; "enabled" attribute as it is done in other targets.
7031 (define_insn "*mov<mode>_store_mem_disp04"
7032   [(set (mem:QIHI
7033           (plus:SI (match_operand:SI 0 "arith_reg_operand" "%r,r")
7034                    (match_operand:SI 1 "const_int_operand" "<disp04>,N")))
7035         (match_operand:QIHI 2 "arith_reg_operand" "z,r"))]
7036   "TARGET_SH1 && sh_legitimate_index_p (<MODE>mode, operands[1], false, true)"
7037   "@
7038         mov.<bw>        %2,@(%O1,%0)
7039         mov.<bw>        %2,@%0"
7040   [(set_attr "type" "store")])
7042 (define_insn "*mov<mode>_store_mem_disp12"
7043   [(set (mem:QIHI
7044           (plus:SI (match_operand:SI 0 "arith_reg_operand" "%r")
7045                    (match_operand:SI 1 "const_int_operand" "<disp12>")))
7046         (match_operand:QIHI 2 "arith_reg_operand" "r"))]
7047   "TARGET_SH2A && sh_legitimate_index_p (<MODE>mode, operands[1], true, true)"
7048   "mov.<bw>     %2,@(%O1,%0)"
7049   [(set_attr "type" "store")
7050    (set_attr "length" "4")])
7052 (define_insn "*mov<mode>_load_mem_disp04"
7053   [(set (match_operand:QIHI 0 "arith_reg_dest" "=z,r")
7054         (mem:QIHI
7055           (plus:SI (match_operand:SI 1 "arith_reg_operand" "%r,r")
7056                    (match_operand:SI 2 "const_int_operand" "<disp04>,N"))))]
7057   "TARGET_SH1 && ! TARGET_SH2A
7058    && sh_legitimate_index_p (<MODE>mode, operands[2], false, true)"
7059   "@
7060         mov.<bw>        @(%O2,%1),%0
7061         mov.<bw>        @%1,%0"
7062   [(set_attr "type" "load")])
7064 (define_insn "*mov<mode>_load_mem_disp12"
7065   [(set (match_operand:QIHI 0 "arith_reg_dest" "=z,r,r")
7066         (mem:QIHI
7067           (plus:SI
7068             (match_operand:SI 1 "arith_reg_operand" "%r,r,r")
7069             (match_operand:SI 2 "const_int_operand" "<disp04>,N,<disp12>"))))]
7070   "TARGET_SH2A && sh_legitimate_index_p (<MODE>mode, operands[2], true, true)"
7071   "@
7072         mov.<bw>        @(%O2,%1),%0
7073         mov.<bw>        @%1,%0
7074         mov.<bw>        @(%O2,%1),%0"
7075   [(set_attr "type" "load")
7076    (set_attr "length" "2,2,4")])
7078 ;; The order of the constraint alternatives is important here.
7079 ;; Q/r has to come first, otherwise PC relative loads might wrongly get
7080 ;; placed into delay slots.  Since there is no QImode PC relative load, the
7081 ;; Q constraint and general_movsrc_operand will reject it for QImode.
7082 ;; The Snd alternatives should come before Sdd in order to avoid a preference
7083 ;; of using r0 als the register operand for addressing modes other than
7084 ;; displacement addressing.
7085 ;; The Sdd alternatives allow only r0 as register operand, even though on
7086 ;; SH2A any register could be allowed by switching to a 32 bit insn.
7087 ;; Generally sticking to the r0 is preferrable, since it generates smaller
7088 ;; code.  Obvious r0 reloads can then be eliminated with a peephole on SH2A.
7089 (define_insn "*mov<mode>"
7090   [(set (match_operand:QIHI 0 "general_movdst_operand"
7091                               "=r,r,r,Snd,r,  Sdd,z,  r,l")
7092         (match_operand:QIHI 1 "general_movsrc_operand"
7093                                "Q,r,i,r,  Snd,z,  Sdd,l,r"))]
7094   "TARGET_SH1
7095    && (arith_reg_operand (operands[0], <MODE>mode)
7096        || arith_reg_operand (operands[1], <MODE>mode))"
7097   "@
7098         mov.<bw>        %1,%0
7099         mov     %1,%0
7100         mov     %1,%0
7101         mov.<bw>        %1,%0
7102         mov.<bw>        %1,%0
7103         mov.<bw>        %1,%0
7104         mov.<bw>        %1,%0
7105         sts     %1,%0
7106         lds     %1,%0"
7107   [(set_attr "type" "pcload,move,movi8,store,load,store,load,prget,prset")
7108    (set (attr "length")
7109         (cond [(and (match_operand 0 "displacement_mem_operand")
7110                     (not (match_operand 0 "short_displacement_mem_operand")))
7111                (const_int 4)
7112                (and (match_operand 1 "displacement_mem_operand")
7113                     (not (match_operand 1 "short_displacement_mem_operand")))
7114                (const_int 4)]
7115               (const_int 2)))])
7117 (define_insn "*movqi_media"
7118   [(set (match_operand:QI 0 "general_movdst_operand" "=r,r,r,m")
7119         (match_operand:QI 1 "general_movsrc_operand" "r,I16Css,m,rZ"))]
7120   "TARGET_SHMEDIA
7121    && (arith_reg_operand (operands[0], QImode)
7122        || extend_reg_or_0_operand (operands[1], QImode))"
7123   "@
7124         add.l   %1, r63, %0
7125         movi    %1, %0
7126         ld%M1.ub        %m1, %0
7127         st%M0.b %m0, %N1"
7128   [(set_attr "type" "arith_media,arith_media,load_media,store_media")
7129    (set (attr "highpart")
7130         (cond [(match_test "sh_contains_memref_p (insn)")
7131                (const_string "user")]
7132               (const_string "ignore")))])
7134 (define_expand "reload_inqi"
7135   [(set (match_operand:SI 2 "" "=&r")
7136         (match_operand:QI 1 "inqhi_operand" ""))
7137    (set (match_operand:QI 0 "arith_reg_operand" "=r")
7138         (truncate:QI (match_dup 3)))]
7139   "TARGET_SHMEDIA"
7141   rtx inner = XEXP (operands[1], 0);
7142   int regno = REGNO (inner);
7144   regno += HARD_REGNO_NREGS (regno, GET_MODE (inner)) - 1;
7145   operands[1] = gen_rtx_REG (SImode, regno);
7146   operands[3] = gen_rtx_REG (DImode, REGNO (operands[2]));
7149 (define_insn "*movhi_media"
7150   [(set (match_operand:HI 0 "general_movdst_operand"     "=r,r,r,r,m")
7151         (match_operand:HI 1 "general_movsrc_operand" "r,I16Css,n,m,rZ"))]
7152   "TARGET_SHMEDIA
7153    && (arith_reg_operand (operands[0], HImode)
7154        || arith_reg_or_0_operand (operands[1], HImode))"
7155   "@
7156         add.l   %1, r63, %0
7157         movi    %1, %0
7158         #
7159         ld%M1.w %m1, %0
7160         st%M0.w %m0, %N1"
7161   [(set_attr "type" "arith_media,arith_media,*,load_media,store_media")
7162    (set (attr "highpart")
7163         (cond [(match_test "sh_contains_memref_p (insn)")
7164                (const_string "user")]
7165               (const_string "ignore")))])
7167 (define_split
7168   [(set (match_operand:HI 0 "register_operand" "")
7169         (match_operand:HI 1 "immediate_operand" ""))]
7170   "TARGET_SHMEDIA && reload_completed
7171    && ! satisfies_constraint_I16 (operands[1])"
7172   [(set (subreg:DI (match_dup 0) 0) (match_dup 1))])
7174 (define_expand "reload_inhi"
7175   [(set (match_operand:SI 2 "" "=&r")
7176         (match_operand:HI 1 "inqhi_operand" ""))
7177    (set (match_operand:HI 0 "arith_reg_operand" "=r")
7178         (truncate:HI (match_dup 3)))]
7179   "TARGET_SHMEDIA"
7181   rtx inner = XEXP (operands[1], 0);
7182   int regno = REGNO (inner);
7184   regno += HARD_REGNO_NREGS (regno, GET_MODE (inner)) - 1;
7185   operands[1] = gen_rtx_REG (SImode, regno);
7186   operands[3] = gen_rtx_REG (DImode, REGNO (operands[2]));
7189 ;; x/r can be created by inlining/cse, e.g. for execute/961213-1.c
7190 ;; compiled with -m2 -ml -O3 -funroll-loops
7191 (define_insn "*movdi_i"
7192   [(set (match_operand:DI 0 "general_movdst_operand" "=r,r,r,m,r,r,r,*!x")
7193         (match_operand:DI 1 "general_movsrc_operand" "Q,r,m,r,I08,i,x,r"))]
7194   "TARGET_SH1
7195    && (arith_reg_operand (operands[0], DImode)
7196        || arith_reg_operand (operands[1], DImode))"
7198   return output_movedouble (insn, operands, DImode);
7200   [(set_attr "length" "4")
7201    (set_attr "type" "pcload,move,load,store,move,pcload,move,move")])
7203 ;; If the output is a register and the input is memory or a register, we have
7204 ;; to be careful and see which word needs to be loaded first.
7205 (define_split
7206   [(set (match_operand:DI 0 "general_movdst_operand" "")
7207         (match_operand:DI 1 "general_movsrc_operand" ""))]
7208   "TARGET_SH1 && reload_completed"
7209   [(set (match_dup 2) (match_dup 3))
7210    (set (match_dup 4) (match_dup 5))]
7212   int regno;
7214   if ((MEM_P (operands[0])
7215        && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
7216       || (MEM_P (operands[1])
7217           && GET_CODE (XEXP (operands[1], 0)) == POST_INC))
7218     FAIL;
7220   switch (GET_CODE (operands[0]))
7221     {
7222     case REG:
7223       regno = REGNO (operands[0]);
7224       break;
7225     case SUBREG:
7226       regno = subreg_regno (operands[0]);
7227       break;
7228     case MEM:
7229       regno = -1;
7230       break;
7231     default:
7232       gcc_unreachable ();
7233     }
7235   if (regno == -1
7236       || ! refers_to_regno_p (regno, regno + 1, operands[1], 0))
7237     {
7238       operands[2] = operand_subword (operands[0], 0, 0, DImode);
7239       operands[3] = operand_subword (operands[1], 0, 0, DImode);
7240       operands[4] = operand_subword (operands[0], 1, 0, DImode);
7241       operands[5] = operand_subword (operands[1], 1, 0, DImode);
7242     }
7243   else
7244     {
7245       operands[2] = operand_subword (operands[0], 1, 0, DImode);
7246       operands[3] = operand_subword (operands[1], 1, 0, DImode);
7247       operands[4] = operand_subword (operands[0], 0, 0, DImode);
7248       operands[5] = operand_subword (operands[1], 0, 0, DImode);
7249     }
7251   if (operands[2] == 0 || operands[3] == 0
7252       || operands[4] == 0 || operands[5] == 0)
7253     FAIL;
7256 ;; The '?'s in the following constraints may not reflect the time taken
7257 ;; to perform the move. They are there to discourage the use of floating-
7258 ;; point registers for storing integer values.
7259 (define_insn "*movdi_media"
7260   [(set (match_operand:DI 0 "general_movdst_operand"
7261                  "=r,r,r,rl,m,f?,m,f?,r,f?,*b,r,*b")
7262         (match_operand:DI 1 "general_movsrc_operand"
7263          "r,I16Css,nCpgF,m,rlZ,m,f?,rZ,f?,f?,r,*b,Csy"))]
7264   "TARGET_SHMEDIA_FPU
7265    && (register_operand (operands[0], DImode)
7266        || sh_register_operand (operands[1], DImode))"
7267   "@
7268         add     %1, r63, %0
7269         movi    %1, %0
7270         #
7271         ld%M1.q %m1, %0
7272         st%M0.q %m0, %N1
7273         fld%M1.d        %m1, %0
7274         fst%M0.d        %m0, %1
7275         fmov.qd %N1, %0
7276         fmov.dq %1, %0
7277         fmov.d  %1, %0
7278         ptabs   %1, %0
7279         gettr   %1, %0
7280         pt      %1, %0"
7281   [(set_attr "type" "arith_media,arith_media,*,load_media,store_media,
7282                      fload_media,fstore_media,fload_media,dfpconv_media,
7283                      fmove_media,ptabs_media,gettr_media,pt_media")
7284    (set_attr "length" "4,4,16,4,4,4,4,4,4,4,4,4,*")])
7286 (define_insn "*movdi_media_nofpu"
7287   [(set (match_operand:DI 0 "general_movdst_operand" "=r,r,r,rl,m,*b,r,*b");
7288         (match_operand:DI 1 "general_movsrc_operand" "r,I16Css,nCpgF,m,rlZ,r,*b,Csy"))]
7289   "TARGET_SHMEDIA
7290    && (register_operand (operands[0], DImode)
7291        || sh_register_operand (operands[1], DImode))"
7292   "@
7293         add     %1, r63, %0
7294         movi    %1, %0
7295         #
7296         ld%M1.q %m1, %0
7297         st%M0.q %m0, %N1
7298         ptabs   %1, %0
7299         gettr   %1, %0
7300         pt      %1, %0"
7301   [(set_attr "type" "arith_media,arith_media,*,load_media,store_media,
7302                      ptabs_media,gettr_media,pt_media")
7303    (set_attr "length" "4,4,16,4,4,4,4,*")])
7305 (define_insn "*movdi_media_I16"
7306   [(set (match_operand:DI 0 "ext_dest_operand" "=r")
7307         (match_operand:DI 1 "const_int_operand" "I16"))]
7308   "TARGET_SHMEDIA && reload_completed"
7309   "movi %1, %0"
7310   [(set_attr "type" "arith_media")
7311    (set_attr "length" "4")])
7313 (define_split
7314   [(set (match_operand:DI 0 "arith_reg_dest" "")
7315         (match_operand:DI 1 "immediate_operand" ""))]
7316   "TARGET_SHMEDIA && reload_completed
7317    && MOVI_SHORI_BASE_OPERAND_P (operands[1])"
7318   [(set (match_dup 0) (match_dup 1))]
7320   rtx insn;
7322   if (TARGET_SHMEDIA64)
7323     insn = emit_insn (gen_movdi_const (operands[0], operands[1]));
7324   else
7325     insn = emit_insn (gen_movdi_const_32bit (operands[0], operands[1]));
7327   set_unique_reg_note (insn, REG_EQUAL, copy_rtx (operands[1]));
7329   DONE;
7332 (define_expand "movdi_const"
7333   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
7334         (const:DI (unspec:DI [(match_operand:DI 1 "immediate_operand" "s")
7335                               (const_int 48)] UNSPEC_EXTRACT_S16)))
7336    (set (match_dup 0)
7337         (ior:DI (ashift:DI (match_dup 0) (const_int 16))
7338                 (const:DI (unspec:DI [(match_dup 1)
7339                                       (const_int 32)] UNSPEC_EXTRACT_U16))))
7340    (set (match_dup 0)
7341         (ior:DI (ashift:DI (match_dup 0) (const_int 16))
7342                 (const:DI (unspec:DI [(match_dup 1)
7343                                       (const_int 16)] UNSPEC_EXTRACT_U16))))
7344    (set (match_dup 0)
7345         (ior:DI (ashift:DI (match_dup 0) (const_int 16))
7346                 (const:DI (unspec:DI [(match_dup 1)
7347                                       (const_int 0)] UNSPEC_EXTRACT_U16))))]
7348   "TARGET_SHMEDIA64 && reload_completed
7349    && MOVI_SHORI_BASE_OPERAND_P (operands[1])"
7351   sh_mark_label (operands[1], 4);
7354 (define_expand "movdi_const_32bit"
7355   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
7356         (const:DI (unspec:DI [(match_operand:DI 1 "immediate_operand" "s")
7357                               (const_int 16)] UNSPEC_EXTRACT_S16)))
7358    (set (match_dup 0)
7359         (ior:DI (ashift:DI (match_dup 0) (const_int 16))
7360                 (const:DI (unspec:DI [(match_dup 1)
7361                                       (const_int 0)] UNSPEC_EXTRACT_U16))))]
7362   "TARGET_SHMEDIA32 && reload_completed
7363    && MOVI_SHORI_BASE_OPERAND_P (operands[1])"
7365   sh_mark_label (operands[1], 2);
7368 (define_expand "movdi_const_16bit"
7369   [(set (match_operand:DI 0 "arith_reg_operand" "=r")
7370         (const:DI (unspec:DI [(match_operand:DI 1 "immediate_operand" "s")
7371                               (const_int 0)] UNSPEC_EXTRACT_S16)))]
7372   "TARGET_SHMEDIA && flag_pic && reload_completed
7373    && GET_CODE (operands[1]) == SYMBOL_REF"
7374   "")
7376 (define_split
7377   [(set (match_operand:DI 0 "ext_dest_operand" "")
7378         (match_operand:DI 1 "immediate_operand" ""))]
7379   "TARGET_SHMEDIA && reload_completed
7380    && CONST_INT_P (operands[1])
7381    && ! satisfies_constraint_I16 (operands[1])"
7382   [(set (match_dup 0) (match_dup 2))
7383    (match_dup 1)]
7385   unsigned HOST_WIDE_INT val = INTVAL (operands[1]);
7386   unsigned HOST_WIDE_INT low = val;
7387   unsigned HOST_WIDE_INT high = val;
7388   unsigned HOST_WIDE_INT sign;
7389   unsigned HOST_WIDE_INT val2 = val ^ (val-1);
7391   /* Zero-extend the 16 least-significant bits.  */
7392   low &= 0xffff;
7394   /* Arithmetic shift right the word by 16 bits.  */
7395   high >>= 16;
7396   if (GET_CODE (operands[0]) == SUBREG
7397       && GET_MODE (SUBREG_REG (operands[0])) == SImode)
7398     {
7399       high &= 0xffff;
7400       high ^= 0x8000;
7401       high -= 0x8000;
7402     }
7403   else
7404     {
7405       sign = 1;
7406       sign <<= (HOST_BITS_PER_WIDE_INT - 16 - 1);
7407       high ^= sign;
7408       high -= sign;
7409     }
7410   do
7411     {
7412       /* If we can't generate the constant with a two-insn movi / shori
7413          sequence, try some other strategies.  */
7414       if (! CONST_OK_FOR_I16 (high))
7415         {
7416           /* Try constant load / left shift.  We know VAL != 0.  */
7417           val2 = val ^ (val-1);
7418           if (val2 > 0x1ffff)
7419             {
7420               int trailing_zeroes = exact_log2 ((val2 >> 16) + 1) + 15;
7422               if (CONST_OK_FOR_I16 (val >> trailing_zeroes)
7423                   || (! CONST_OK_FOR_I16 (high >> 16)
7424                       && CONST_OK_FOR_I16 (val >> (trailing_zeroes + 16))))
7425                 {
7426                   val2 = (HOST_WIDE_INT) val >> trailing_zeroes;
7427                   operands[1] = gen_ashldi3_media (operands[0], operands[0],
7428                                                    GEN_INT (trailing_zeroes));
7429                   break;
7430                 }
7431             }
7432           /* Try constant load / right shift.  */
7433           val2 = (val >> 15) + 1;
7434           if (val2 == (val2 & -val2))
7435             {
7436               int shift = 49 - exact_log2 (val2);
7438               val2 = trunc_int_for_mode (val << shift, DImode);
7439               if (CONST_OK_FOR_I16 (val2))
7440                 {
7441                   operands[1] = gen_lshrdi3_media (operands[0], operands[0],
7442                                                    GEN_INT (shift));
7443                   break;
7444                 }
7445             }
7446           /* Try mperm.w .  */
7447           val2 = val & 0xffff;
7448           if ((val >> 16 & 0xffff) == val2
7449               && (val >> 32 & 0xffff) == val2
7450               && (val >> 48 & 0xffff) == val2)
7451             {
7452               val2 = (HOST_WIDE_INT) val >> 48;
7453               operands[1] = gen_rtx_REG (V4HImode, true_regnum (operands[0]));
7454               operands[1] = gen_mperm_w0 (operands[1], operands[1]);
7455               break;
7456             }
7457           /* Try movi / mshflo.l  */
7458           val2 = (HOST_WIDE_INT) val >> 32;
7459           if (val2 == ((unsigned HOST_WIDE_INT)
7460                         trunc_int_for_mode (val, SImode)))
7461             {
7462               operands[1] = gen_mshflo_l_di (operands[0], operands[0],
7463                                              operands[0]);
7464               break;
7465             }
7466           /* Try movi / mshflo.l w/ r63.  */
7467           val2 = val + ((HOST_WIDE_INT) -1 << 32);
7468           if ((HOST_WIDE_INT) val2 < 0 && CONST_OK_FOR_I16 (val2))
7469             {
7470               operands[1] = gen_mshflo_l_di (operands[0], operands[0],
7471                                              const0_rtx);
7472               break;
7473             }
7474         }
7475       val2 = high;
7476       operands[1] = gen_shori_media (operands[0], operands[0], GEN_INT (low));
7477     }
7478   while (0);
7479   operands[2] = GEN_INT (val2);
7482 (define_split
7483   [(set (match_operand:DI 0 "ext_dest_operand" "")
7484         (match_operand:DI 1 "immediate_operand" ""))]
7485   "TARGET_SHMEDIA && reload_completed
7486    && GET_CODE (operands[1]) == CONST_DOUBLE"
7487   [(set (match_dup 0) (match_dup 2))
7488   (set (match_dup 0)
7489        (ior:DI (ashift:DI (match_dup 0) (const_int 16)) (match_dup 1)))]
7491   unsigned HOST_WIDE_INT low = CONST_DOUBLE_LOW (operands[1]);
7492   unsigned HOST_WIDE_INT high = CONST_DOUBLE_HIGH (operands[1]);
7493   unsigned HOST_WIDE_INT val = low;
7494   unsigned HOST_WIDE_INT sign;
7496   /* Zero-extend the 16 least-significant bits.  */
7497   val &= 0xffff;
7498   operands[1] = GEN_INT (val);
7500   /* Arithmetic shift right the double-word by 16 bits.  */
7501   low >>= 16;
7502   low |= (high & 0xffff) << (HOST_BITS_PER_WIDE_INT - 16);
7503   high >>= 16;
7504   sign = 1;
7505   sign <<= (HOST_BITS_PER_WIDE_INT - 16 - 1);
7506   high ^= sign;
7507   high -= sign;
7509   /* This will only be true if high is a sign-extension of low, i.e.,
7510      it must be either 0 or (unsigned)-1, and be zero iff the
7511      most-significant bit of low is set.  */
7512   if (high + (low >> (HOST_BITS_PER_WIDE_INT - 1)) == 0)
7513     operands[2] = GEN_INT (low);
7514   else
7515     operands[2] = immed_double_const (low, high, DImode);
7518 (define_insn "shori_media"
7519   [(set (match_operand:DI 0 "ext_dest_operand" "=r,r")
7520         (ior:DI (ashift:DI (match_operand:DI 1 "arith_reg_operand" "0,0")
7521                            (const_int 16))
7522                 (match_operand:DI 2 "immediate_operand" "K16Csu,nF")))]
7523   "TARGET_SHMEDIA && (reload_completed || arith_reg_dest (operands[0], DImode))"
7524   "@
7525         shori   %u2, %0
7526         #"
7527   [(set_attr "type" "arith_media,*")])
7529 (define_insn "*shori_media_si"
7530   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
7531         (ior:SI (ashift:SI (match_operand:SI 1 "arith_reg_operand" "0")
7532                            (const_int 16))
7533                 (match_operand:SI 2 "immediate_operand" "K16Csu")))]
7534   "TARGET_SHMEDIA"
7535   "shori        %u2, %0")
7537 (define_expand "movdi"
7538   [(set (match_operand:DI 0 "general_movdst_operand" "")
7539         (match_operand:DI 1 "general_movsrc_operand" ""))]
7540   ""
7542   prepare_move_operands (operands, DImode);
7545 (define_insn "movdf_media"
7546   [(set (match_operand:DF 0 "general_movdst_operand" "=f,f,r,r,r,f,m,r,m")
7547         (match_operand:DF 1 "general_movsrc_operand" "f,rZ,f,r,F,m,f,m,rZ"))]
7548   "TARGET_SHMEDIA_FPU
7549    && (register_operand (operands[0], DFmode)
7550        || sh_register_operand (operands[1], DFmode))"
7551   "@
7552         fmov.d  %1, %0
7553         fmov.qd %N1, %0
7554         fmov.dq %1, %0
7555         add     %1, r63, %0
7556         #
7557         fld%M1.d        %m1, %0
7558         fst%M0.d        %m0, %1
7559         ld%M1.q %m1, %0
7560         st%M0.q %m0, %N1"
7561   [(set_attr "type" "fmove_media,fload_media,dfpconv_media,arith_media,*,
7562                      fload_media,fstore_media,load_media,store_media")])
7564 (define_insn "movdf_media_nofpu"
7565   [(set (match_operand:DF 0 "general_movdst_operand" "=r,r,r,m")
7566         (match_operand:DF 1 "general_movsrc_operand" "r,F,m,rZ"))]
7567   "TARGET_SHMEDIA
7568    && (register_operand (operands[0], DFmode)
7569        || sh_register_operand (operands[1], DFmode))"
7570   "@
7571         add     %1, r63, %0
7572         #
7573         ld%M1.q %m1, %0
7574         st%M0.q %m0, %N1"
7575   [(set_attr "type" "arith_media,*,load_media,store_media")])
7577 (define_split
7578   [(set (match_operand:DF 0 "arith_reg_dest" "")
7579         (match_operand:DF 1 "immediate_operand" ""))]
7580   "TARGET_SHMEDIA && reload_completed"
7581   [(set (match_dup 3) (match_dup 2))]
7583   int endian = WORDS_BIG_ENDIAN ? 1 : 0;
7584   long values[2];
7585   REAL_VALUE_TYPE value;
7587   REAL_VALUE_FROM_CONST_DOUBLE (value, operands[1]);
7588   REAL_VALUE_TO_TARGET_DOUBLE (value, values);
7590   if (HOST_BITS_PER_WIDE_INT >= 64)
7591     operands[2] = immed_double_const ((unsigned long) values[endian]
7592                                       | ((HOST_WIDE_INT) values[1 - endian]
7593                                          << 32), 0, DImode);
7594   else
7595     {
7596       gcc_assert (HOST_BITS_PER_WIDE_INT == 32);
7597       operands[2] = immed_double_const (values[endian], values[1 - endian],
7598                                         DImode);
7599     }
7601   operands[3] = gen_rtx_REG (DImode, true_regnum (operands[0]));
7604 ;; FIXME: This should be a define_insn_and_split.
7605 (define_insn "movdf_k"
7606   [(set (match_operand:DF 0 "general_movdst_operand" "=r,r,r,m")
7607         (match_operand:DF 1 "general_movsrc_operand" "r,FQ,m,r"))]
7608   "TARGET_SH1
7609    && (! (TARGET_SH4 || TARGET_SH2A_DOUBLE) || reload_completed
7610        /* ??? We provide some insn so that direct_{load,store}[DFmode] get set */
7611        || (REG_P (operands[0]) && REGNO (operands[0]) == 3)
7612        || (REG_P (operands[1]) && REGNO (operands[1]) == 3))
7613    && (arith_reg_operand (operands[0], DFmode)
7614        || arith_reg_operand (operands[1], DFmode))"
7616   return output_movedouble (insn, operands, DFmode);
7618   [(set_attr "length" "4")
7619    (set_attr "type" "move,pcload,load,store")])
7621 ;; All alternatives of movdf_i4 are split for ! TARGET_FMOVD.
7622 ;; However, the d/F/c/z alternative cannot be split directly; it is converted
7623 ;; with special code in machine_dependent_reorg into a load of the R0_REG and
7624 ;; the d/m/c/X alternative, which is split later into single-precision
7625 ;; instructions.  And when not optimizing, no splits are done before fixing
7626 ;; up pcloads, so we need usable length information for that.
7627 (define_insn "movdf_i4"
7628   [(set (match_operand:DF 0 "general_movdst_operand" "=d,r,d,d,m,r,r,m,!??r,!???d")
7629         (match_operand:DF 1 "general_movsrc_operand"  "d,r,F,m,d,FQ,m,r,d,r"))
7630    (use (reg:SI FPSCR_MODES_REG))
7631    (clobber (match_scratch:SI 2                      "=X,X,&z,X,X,X,X,X,X,X"))]
7632   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)
7633    && (arith_reg_operand (operands[0], DFmode)
7634        || arith_reg_operand (operands[1], DFmode))"
7635   {
7636     switch (which_alternative)
7637     {
7638     case 0:
7639       if (TARGET_FMOVD)
7640         return "fmov    %1,%0";
7641       else if (REGNO (operands[0]) != REGNO (operands[1]) + 1)
7642         return         "fmov    %R1,%R0"        "\n"
7643                "        fmov    %S1,%S0";
7644       else
7645         return         "fmov    %S1,%S0"        "\n"
7646                "        fmov    %R1,%R0";
7647     case 3:
7648     case 4:
7649       return "fmov.d    %1,%0";
7650     default:
7651       return "#";
7652     }
7653   }
7654   [(set_attr_alternative "length"
7655      [(if_then_else (eq_attr "fmovd" "yes") (const_int 4) (const_int 8))
7656       (const_int 4)
7657       (if_then_else (eq_attr "fmovd" "yes") (const_int 4) (const_int 6))
7658       (if_then_else (eq_attr "fmovd" "yes") (const_int 4) (const_int 6))
7659       (if_then_else (eq_attr "fmovd" "yes") (const_int 4) (const_int 6))
7660       (const_int 4)
7661       (const_int 8) (const_int 8) ;; these need only 8 bytes for @(r0,rn)
7662       ;; We can't use 4-byte push/pop on SHcompact, so we have to
7663       ;; increment or decrement r15 explicitly.
7664       (if_then_else
7665        (match_test "TARGET_SHCOMPACT")
7666        (const_int 10) (const_int 8))
7667       (if_then_else
7668        (match_test "TARGET_SHCOMPACT")
7669        (const_int 10) (const_int 8))])
7670    (set_attr "type" "fmove,move,pcfload,fload,fstore,pcload,load,store,load,fload")
7671    (set_attr "late_fp_use" "*,*,*,*,yes,*,*,*,*,*")
7672    (set (attr "fp_mode") (if_then_else (eq_attr "fmovd" "yes")
7673                                            (const_string "double")
7674                                            (const_string "none")))])
7676 ;; Moving DFmode between fp/general registers through memory
7677 ;; (the top of the stack) is faster than moving through fpul even for
7678 ;; little endian.  Because the type of an instruction is important for its
7679 ;; scheduling,  it is beneficial to split these operations, rather than
7680 ;; emitting them in one single chunk, even if this will expose a stack
7681 ;; use that will prevent scheduling of other stack accesses beyond this
7682 ;; instruction.
7683 (define_split
7684   [(set (match_operand:DF 0 "register_operand")
7685         (match_operand:DF 1 "register_operand"))
7686    (use (reg:SI FPSCR_MODES_REG))
7687    (clobber (match_scratch:SI 2))]
7688   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) && reload_completed
7689    && (true_regnum (operands[0]) < 16) != (true_regnum (operands[1]) < 16)"
7690   [(const_int 0)]
7692   rtx insn, tos;
7694   if (TARGET_SH5 && true_regnum (operands[1]) < 16)
7695     {
7696       emit_move_insn (stack_pointer_rtx,
7697                       plus_constant (Pmode, stack_pointer_rtx, -8));
7698       tos = gen_tmp_stack_mem (DFmode, stack_pointer_rtx);
7699     }
7700   else
7701     tos = gen_tmp_stack_mem (DFmode,
7702                              gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx));
7703   insn = emit_insn (gen_movdf_i4 (tos, operands[1]));
7704   if (! (TARGET_SH5 && true_regnum (operands[1]) < 16))
7705     add_reg_note (insn, REG_INC, stack_pointer_rtx);
7706   if (TARGET_SH5 && true_regnum (operands[0]) < 16)
7707     tos = gen_tmp_stack_mem (DFmode, stack_pointer_rtx);
7708   else
7709     tos = gen_tmp_stack_mem (DFmode,
7710                              gen_rtx_POST_INC (Pmode, stack_pointer_rtx));
7711   insn = emit_insn (gen_movdf_i4 (operands[0], tos));
7712   if (TARGET_SH5 && true_regnum (operands[0]) < 16)
7713     emit_move_insn (stack_pointer_rtx,
7714                     plus_constant (Pmode, stack_pointer_rtx, 8));
7715   else
7716     add_reg_note (insn, REG_INC, stack_pointer_rtx);
7717   DONE;
7720 ;; local-alloc sometimes allocates scratch registers even when not required,
7721 ;; so we must be prepared to handle these.
7723 ;; Remove the use and clobber from a movdf_i4 so that we can use movdf_k.
7724 (define_split
7725   [(set (match_operand:DF 0 "general_movdst_operand" "")
7726         (match_operand:DF 1 "general_movsrc_operand"  ""))
7727    (use (reg:SI FPSCR_MODES_REG))
7728    (clobber (match_scratch:SI 2))]
7729   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)
7730    && reload_completed
7731    && true_regnum (operands[0]) < 16
7732    && true_regnum (operands[1]) < 16"
7733   [(set (match_dup 0) (match_dup 1))]
7735   /* If this was a reg <-> mem operation with base + index reg addressing,
7736      we have to handle this in a special way.  */
7737   rtx mem = operands[0];
7738   int store_p = 1;
7739   if (! memory_operand (mem, DFmode))
7740     {
7741       mem = operands[1];
7742       store_p = 0;
7743     }
7744   if (GET_CODE (mem) == SUBREG && SUBREG_BYTE (mem) == 0)
7745     mem = SUBREG_REG (mem);
7746   if (MEM_P (mem))
7747     {
7748       rtx addr = XEXP (mem, 0);
7749       if (GET_CODE (addr) == PLUS
7750           && REG_P (XEXP (addr, 0))
7751           && REG_P (XEXP (addr, 1)))
7752         {
7753           int offset;
7754           rtx reg0 = gen_rtx_REG (Pmode, 0);
7755           rtx regop = operands[store_p], word0 ,word1;
7757           if (GET_CODE (regop) == SUBREG)
7758             alter_subreg (&regop, true);
7759           if (REGNO (XEXP (addr, 0)) == REGNO (XEXP (addr, 1)))
7760             offset = 2;
7761           else
7762             offset = 4;
7763           mem = copy_rtx (mem);
7764           PUT_MODE (mem, SImode);
7765           word0 = gen_rtx_SUBREG (SImode, regop, 0);
7766           alter_subreg (&word0, true);
7767           word1 = gen_rtx_SUBREG (SImode, regop, 4);
7768           alter_subreg (&word1, true);
7769           if (store_p || ! refers_to_regno_p (REGNO (word0),
7770                                               REGNO (word0) + 1, addr, 0))
7771             {
7772               emit_insn (store_p
7773                          ? gen_movsi_ie (mem, word0)
7774                          : gen_movsi_ie (word0, mem));
7775               emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (offset)));
7776               mem = copy_rtx (mem);
7777               emit_insn (store_p
7778                          ? gen_movsi_ie (mem, word1)
7779                          : gen_movsi_ie (word1, mem));
7780               emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (-offset)));
7781             }
7782           else
7783             {
7784               emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (offset)));
7785               emit_insn (gen_movsi_ie (word1, mem));
7786               emit_insn (gen_addsi3 (reg0, reg0, GEN_INT (-offset)));
7787               mem = copy_rtx (mem);
7788               emit_insn (gen_movsi_ie (word0, mem));
7789             }
7790           DONE;
7791         }
7792     }
7795 ;; Split away the clobber of r0 after machine_dependent_reorg has fixed pcloads.
7796 (define_split
7797   [(set (match_operand:DF 0 "register_operand" "")
7798         (match_operand:DF 1 "memory_operand"  ""))
7799    (use (reg:SI FPSCR_MODES_REG))
7800    (clobber (reg:SI R0_REG))]
7801   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) && reload_completed"
7802   [(parallel [(set (match_dup 0) (match_dup 1))
7803               (use (reg:SI FPSCR_MODES_REG))
7804               (clobber (scratch:SI))])]
7805   "")
7807 (define_expand "reload_indf__frn"
7808   [(parallel [(set (match_operand:DF 0 "register_operand" "=a")
7809                    (match_operand:DF 1 "immediate_operand" "FQ"))
7810               (use (reg:SI FPSCR_MODES_REG))
7811               (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
7812   "TARGET_SH1"
7813   "")
7815 (define_expand "reload_outdf__RnFRm"
7816   [(parallel [(set (match_operand:DF 0 "register_operand" "=r,f")
7817                    (match_operand:DF 1 "register_operand" "af,r"))
7818               (clobber (match_operand:SI 2 "register_operand" "=&y,y"))])]
7819   "TARGET_SH1"
7820   "")
7822 ;; Simplify no-op moves.
7823 (define_split
7824   [(set (match_operand:SF 0 "register_operand" "")
7825         (match_operand:SF 1 "register_operand" ""))
7826    (use (reg:SI FPSCR_MODES_REG))
7827    (clobber (match_scratch:SI 2))]
7828   "TARGET_SH2E && reload_completed
7829    && true_regnum (operands[0]) == true_regnum (operands[1])"
7830   [(set (match_dup 0) (match_dup 0))]
7831   "")
7833 ;; fmovd substitute post-reload splits
7834 (define_split
7835   [(set (match_operand:DF 0 "register_operand" "")
7836         (match_operand:DF 1 "register_operand" ""))
7837    (use (reg:SI FPSCR_MODES_REG))
7838    (clobber (match_scratch:SI 2))]
7839   "TARGET_SH4 && ! TARGET_FMOVD && reload_completed
7840    && FP_OR_XD_REGISTER_P (true_regnum (operands[0]))
7841    && FP_OR_XD_REGISTER_P (true_regnum (operands[1]))"
7842   [(const_int 0)]
7844   int dst = true_regnum (operands[0]), src = true_regnum (operands[1]);
7845   emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode, dst),
7846                            gen_rtx_REG (SFmode, src)));
7847   emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode, dst + 1),
7848                            gen_rtx_REG (SFmode, src + 1)));
7849   DONE;
7852 (define_split
7853   [(set (match_operand:DF 0 "register_operand" "")
7854         (mem:DF (match_operand:SI 1 "register_operand" "")))
7855    (use (reg:SI FPSCR_MODES_REG))
7856    (clobber (match_scratch:SI 2))]
7857   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) && ! TARGET_FMOVD && reload_completed
7858    && FP_OR_XD_REGISTER_P (true_regnum (operands[0]))
7859    && find_regno_note (insn, REG_DEAD, true_regnum (operands[1]))"
7860   [(const_int 0)]
7862   int regno = true_regnum (operands[0]);
7863   rtx insn;
7864   rtx mem = SET_SRC (XVECEXP (PATTERN (curr_insn), 0, 0));
7865   rtx mem2
7866     = change_address (mem, SFmode, gen_rtx_POST_INC (Pmode, operands[1]));
7867   insn = emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode,
7868                                                regno + SH_REG_MSW_OFFSET),
7869                                   mem2));
7870   add_reg_note (insn, REG_INC, operands[1]);
7871   insn = emit_insn (gen_movsf_ie (gen_rtx_REG (SFmode,
7872                                                regno + SH_REG_LSW_OFFSET),
7873                                   change_address (mem, SFmode, NULL_RTX)));
7874   DONE;
7877 (define_split
7878   [(set (match_operand:DF 0 "register_operand" "")
7879         (match_operand:DF 1 "memory_operand" ""))
7880    (use (reg:SI FPSCR_MODES_REG))
7881    (clobber (match_scratch:SI 2))]
7882   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) && ! TARGET_FMOVD && reload_completed
7883    && FP_OR_XD_REGISTER_P (true_regnum (operands[0]))"
7884   [(const_int 0)]
7886   int regno = true_regnum (operands[0]);
7887   rtx addr, insn;
7888   rtx mem2 = change_address (operands[1], SFmode, NULL_RTX);
7889   rtx reg0 = gen_rtx_REG (SFmode, regno + SH_REG_MSW_OFFSET);
7890   rtx reg1 = gen_rtx_REG (SFmode, regno + SH_REG_LSW_OFFSET);
7892   operands[1] = copy_rtx (mem2);
7893   addr = XEXP (mem2, 0);
7895   switch (GET_CODE (addr))
7896     {
7897     case REG:
7898       /* This is complicated.  If the register is an arithmetic register
7899          we can just fall through to the REG+DISP case below.  Otherwise
7900          we have to use a combination of POST_INC and REG addressing...  */
7901       if (! arith_reg_operand (operands[1], SFmode))
7902         {
7903           XEXP (mem2, 0) = addr = gen_rtx_POST_INC (SImode, addr);
7904           insn = emit_insn (gen_movsf_ie (reg0, mem2));
7905           add_reg_note (insn, REG_INC, XEXP (addr, 0));
7906           
7907           emit_insn (gen_movsf_ie (reg1, operands[1]));
7909           /* If we have modified the stack pointer, the value that we have
7910              read with post-increment might be modified by an interrupt,
7911              so write it back.  */
7912           if (REGNO (XEXP (addr, 0)) == STACK_POINTER_REGNUM)
7913             emit_insn (gen_push_e (reg0));
7914           else
7915             emit_insn (gen_addsi3 (XEXP (operands[1], 0), XEXP (operands[1], 0),
7916                                    GEN_INT (-4)));
7917           break;
7918         }
7919       /* Fall through.  */
7921     case PLUS:
7922       emit_insn (gen_movsf_ie (reg0, operands[1]));
7923       operands[1] = copy_rtx (operands[1]);
7924       XEXP (operands[1], 0) = plus_constant (Pmode, addr, 4);
7925       emit_insn (gen_movsf_ie (reg1, operands[1]));
7926       break;
7928     case POST_INC:
7929       insn = emit_insn (gen_movsf_ie (reg0, operands[1]));
7930       add_reg_note (insn, REG_INC, XEXP (addr, 0));
7932       insn = emit_insn (gen_movsf_ie (reg1, operands[1]));
7933       add_reg_note (insn, REG_INC, XEXP (addr, 0));
7934       break;
7936     default:
7937       debug_rtx (addr);
7938       gcc_unreachable ();
7939     }
7941   DONE;
7944 (define_split
7945   [(set (match_operand:DF 0 "memory_operand" "")
7946         (match_operand:DF 1 "register_operand" ""))
7947    (use (reg:SI FPSCR_MODES_REG))
7948    (clobber (match_scratch:SI 2))]
7949   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) && ! TARGET_FMOVD && reload_completed
7950    && FP_OR_XD_REGISTER_P (true_regnum (operands[1]))"
7951   [(const_int 0)]
7953   int regno = true_regnum (operands[1]);
7954   rtx insn, addr;
7955   rtx reg0 = gen_rtx_REG (SFmode, regno + SH_REG_MSW_OFFSET);
7956   rtx reg1 = gen_rtx_REG (SFmode, regno + SH_REG_LSW_OFFSET);
7958   operands[0] = copy_rtx (operands[0]);
7959   PUT_MODE (operands[0], SFmode);
7960   addr = XEXP (operands[0], 0);
7962   switch (GET_CODE (addr))
7963     {
7964     case REG:
7965       /* This is complicated.  If the register is an arithmetic register
7966          we can just fall through to the REG+DISP case below.  Otherwise
7967          we have to use a combination of REG and PRE_DEC addressing...  */
7968       if (! arith_reg_operand (operands[0], SFmode))
7969         {
7970           emit_insn (gen_addsi3 (addr, addr, GEN_INT (4)));
7971           emit_insn (gen_movsf_ie (operands[0], reg1));
7973           operands[0] = copy_rtx (operands[0]);
7974           XEXP (operands[0], 0) = addr = gen_rtx_PRE_DEC (SImode, addr);
7975           
7976           insn = emit_insn (gen_movsf_ie (operands[0], reg0));
7977           add_reg_note (insn, REG_INC, XEXP (addr, 0));
7978           break;
7979         }
7980       /* Fall through.  */
7982     case PLUS:
7983       /* Since REG+DISP addressing has already been decided upon by gcc
7984          we can rely upon it having chosen an arithmetic register as the
7985          register component of the address.  Just emit the lower numbered
7986          register first, to the lower address, then the higher numbered
7987          register to the higher address.  */
7988       emit_insn (gen_movsf_ie (operands[0], reg0));
7990       operands[0] = copy_rtx (operands[0]);
7991       XEXP (operands[0], 0) = plus_constant (Pmode, addr, 4);
7993       emit_insn (gen_movsf_ie (operands[0], reg1));
7994       break;
7996     case PRE_DEC:
7997       /* This is easy.  Output the word to go to the higher address
7998          first (ie the word in the higher numbered register) then the
7999          word to go to the lower address.  */
8001       insn = emit_insn (gen_movsf_ie (operands[0], reg1));
8002       add_reg_note (insn, REG_INC, XEXP (addr, 0));
8004       insn = emit_insn (gen_movsf_ie (operands[0], reg0));
8005       add_reg_note (insn, REG_INC, XEXP (addr, 0));
8006       break;
8008     default:
8009       /* FAIL; */
8010       debug_rtx (addr);
8011       gcc_unreachable ();
8012     }
8014   DONE;
8017 ;; If the output is a register and the input is memory or a register, we have
8018 ;; to be careful and see which word needs to be loaded first.
8019 (define_split
8020   [(set (match_operand:DF 0 "general_movdst_operand" "")
8021         (match_operand:DF 1 "general_movsrc_operand" ""))]
8022   "TARGET_SH1 && reload_completed"
8023   [(set (match_dup 2) (match_dup 3))
8024    (set (match_dup 4) (match_dup 5))]
8026   int regno;
8028   if ((MEM_P (operands[0])
8029        && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
8030       || (MEM_P (operands[1])
8031           && GET_CODE (XEXP (operands[1], 0)) == POST_INC))
8032     FAIL;
8034   switch (GET_CODE (operands[0]))
8035     {
8036     case REG:
8037       regno = REGNO (operands[0]);
8038       break;
8039     case SUBREG:
8040       regno = subreg_regno (operands[0]);
8041       break;
8042     case MEM:
8043       regno = -1;
8044       break;
8045     default:
8046       gcc_unreachable ();
8047     }
8049   if (regno == -1
8050       || ! refers_to_regno_p (regno, regno + 1, operands[1], 0))
8051     {
8052       operands[2] = operand_subword (operands[0], 0, 0, DFmode);
8053       operands[3] = operand_subword (operands[1], 0, 0, DFmode);
8054       operands[4] = operand_subword (operands[0], 1, 0, DFmode);
8055       operands[5] = operand_subword (operands[1], 1, 0, DFmode);
8056     }
8057   else
8058     {
8059       operands[2] = operand_subword (operands[0], 1, 0, DFmode);
8060       operands[3] = operand_subword (operands[1], 1, 0, DFmode);
8061       operands[4] = operand_subword (operands[0], 0, 0, DFmode);
8062       operands[5] = operand_subword (operands[1], 0, 0, DFmode);
8063     }
8065   if (operands[2] == 0 || operands[3] == 0
8066       || operands[4] == 0 || operands[5] == 0)
8067     FAIL;
8070 (define_expand "movdf"
8071   [(set (match_operand:DF 0 "general_movdst_operand" "")
8072         (match_operand:DF 1 "general_movsrc_operand" ""))]
8073   ""
8075   prepare_move_operands (operands, DFmode);
8076   if (TARGET_SHMEDIA)
8077     {
8078       if (TARGET_SHMEDIA_FPU)
8079         emit_insn (gen_movdf_media (operands[0], operands[1]));
8080       else
8081         emit_insn (gen_movdf_media_nofpu (operands[0], operands[1]));
8082       DONE;
8083     }
8084   if (TARGET_SH4 || TARGET_SH2A_DOUBLE)
8085     {
8086       emit_insn (gen_movdf_i4 (operands[0], operands[1]));
8087       DONE;
8088     }
8091 ;;This is incompatible with the way gcc uses subregs.
8092 ;;(define_insn "movv2sf_i"
8093 ;;  [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,m")
8094 ;;      (match_operand:V2SF 1 "nonimmediate_operand" "f,m,f"))]
8095 ;;  "TARGET_SHMEDIA_FPU
8096 ;;   && (fp_arith_reg_operand (operands[0], V2SFmode)
8097 ;;       || fp_arith_reg_operand (operands[1], V2SFmode))"
8098 ;;  "@
8099 ;;      #
8100 ;;      fld%M1.p        %m1, %0
8101 ;;      fst%M0.p        %m0, %1"
8102 ;;  [(set_attr "type" "*,fload_media,fstore_media")])
8103 (define_insn_and_split "movv2sf_i"
8104   [(set (match_operand:V2SF 0 "general_movdst_operand" "=f,rf,r,m,mf")
8105         (match_operand:V2SF 1 "general_operand" "fm,rfm?,F?,f,rfZ?"))]
8106   "TARGET_SHMEDIA_FPU"
8107   "#"
8108   "TARGET_SHMEDIA_FPU && reload_completed"
8109   [(set (match_dup 0) (match_dup 1))]
8111   operands[0] = simplify_gen_subreg (DFmode, operands[0], V2SFmode, 0);
8112   operands[1] = simplify_gen_subreg (DFmode, operands[1], V2SFmode, 0);
8115 (define_expand "movv2sf"
8116   [(set (match_operand:V2SF 0 "general_movdst_operand" "")
8117         (match_operand:V2SF 1 "nonimmediate_operand" ""))]
8118   "TARGET_SHMEDIA_FPU"
8120   prepare_move_operands (operands, V2SFmode);
8123 (define_expand "addv2sf3"
8124   [(match_operand:V2SF 0 "fp_arith_reg_operand" "")
8125    (match_operand:V2SF 1 "fp_arith_reg_operand" "")
8126    (match_operand:V2SF 2 "fp_arith_reg_operand" "")]
8127   "TARGET_SHMEDIA_FPU"
8129   sh_expand_binop_v2sf (PLUS, operands[0], operands[1], operands[2]);
8130   DONE;
8133 (define_expand "subv2sf3"
8134   [(match_operand:V2SF 0 "fp_arith_reg_operand" "")
8135    (match_operand:V2SF 1 "fp_arith_reg_operand" "")
8136    (match_operand:V2SF 2 "fp_arith_reg_operand" "")]
8137   "TARGET_SHMEDIA_FPU"
8139   sh_expand_binop_v2sf (MINUS, operands[0], operands[1], operands[2]);
8140   DONE;
8143 (define_expand "mulv2sf3"
8144   [(match_operand:V2SF 0 "fp_arith_reg_operand" "")
8145    (match_operand:V2SF 1 "fp_arith_reg_operand" "")
8146    (match_operand:V2SF 2 "fp_arith_reg_operand" "")]
8147   "TARGET_SHMEDIA_FPU"
8149   sh_expand_binop_v2sf (MULT, operands[0], operands[1], operands[2]);
8150   DONE;
8153 (define_expand "divv2sf3"
8154   [(match_operand:V2SF 0 "fp_arith_reg_operand" "")
8155    (match_operand:V2SF 1 "fp_arith_reg_operand" "")
8156    (match_operand:V2SF 2 "fp_arith_reg_operand" "")]
8157   "TARGET_SHMEDIA_FPU"
8159   sh_expand_binop_v2sf (DIV, operands[0], operands[1], operands[2]);
8160   DONE;
8163 (define_insn_and_split "*movv4sf_i"
8164   [(set (match_operand:V4SF 0 "general_movdst_operand" "=f,rf,r,m,mf")
8165         (match_operand:V4SF 1 "general_operand" "fm,rfm?,F?,f,rfZ?"))]
8166   "TARGET_SHMEDIA_FPU"
8167   "#"
8168   "&& reload_completed"
8169   [(const_int 0)]
8171   for (int i = 0; i < 4/2; i++)
8172     {
8173       rtx x, y;
8175       if (MEM_P (operands[0]))
8176         x = adjust_address (operands[0], V2SFmode,
8177                             i * GET_MODE_SIZE (V2SFmode));
8178       else
8179         x = simplify_gen_subreg (V2SFmode, operands[0], V4SFmode, i * 8);
8181       if (MEM_P (operands[1]))
8182         y = adjust_address (operands[1], V2SFmode,
8183                             i * GET_MODE_SIZE (V2SFmode));
8184       else
8185         y = simplify_gen_subreg (V2SFmode, operands[1], V4SFmode, i * 8);
8187       emit_insn (gen_movv2sf_i (x, y));
8188     }
8190   DONE;
8192   [(set_attr "length" "8")])
8194 (define_expand "movv4sf"
8195   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
8196         (match_operand:V4SF 1 "general_operand" ""))]
8197   "TARGET_SHMEDIA_FPU"
8199   prepare_move_operands (operands, V4SFmode);
8202 (define_insn_and_split "*movv16sf_i"
8203   [(set (match_operand:V16SF 0 "nonimmediate_operand" "=f,f,m")
8204         (match_operand:V16SF 1 "nonimmediate_operand" "f,m,f"))]
8205   "TARGET_SHMEDIA_FPU"
8206   "#"
8207   "&& reload_completed"
8208   [(const_int 0)]
8210   for (int i = 0; i < 16/2; i++)
8211     {
8212       rtx x, y;
8214       if (MEM_P (operands[0]))
8215         x = adjust_address (operands[0], V2SFmode,
8216                             i * GET_MODE_SIZE (V2SFmode));
8217       else
8218         {
8219           x = gen_rtx_SUBREG (V2SFmode, operands[0], i * 8);
8220           alter_subreg (&x, true);
8221         }
8223       if (MEM_P (operands[1]))
8224         y = adjust_address (operands[1], V2SFmode,
8225                             i * GET_MODE_SIZE (V2SFmode));
8226       else
8227         {
8228           y = gen_rtx_SUBREG (V2SFmode, operands[1], i * 8);
8229           alter_subreg (&y, true);
8230         }
8232       emit_insn (gen_movv2sf_i (x, y));
8233     }
8235   DONE;
8237   [(set_attr "length" "32")])
8239 (define_expand "movv16sf"
8240   [(set (match_operand:V16SF 0 "nonimmediate_operand" "=f,f,m")
8241         (match_operand:V16SF 1 "nonimmediate_operand" "f,m,f"))]
8242   "TARGET_SHMEDIA_FPU"
8244   prepare_move_operands (operands, V16SFmode);
8247 (define_insn "movsf_media"
8248   [(set (match_operand:SF 0 "general_movdst_operand" "=f,f,r,r,r,f,m,r,m")
8249         (match_operand:SF 1 "general_movsrc_operand" "f,rZ,f,r,F,m,f,m,rZ"))]
8250   "TARGET_SHMEDIA_FPU
8251    && (register_operand (operands[0], SFmode)
8252        || sh_register_operand (operands[1], SFmode))"
8253   "@
8254         fmov.s  %1, %0
8255         fmov.ls %N1, %0
8256         fmov.sl %1, %0
8257         add.l   %1, r63, %0
8258         #
8259         fld%M1.s        %m1, %0
8260         fst%M0.s        %m0, %1
8261         ld%M1.l %m1, %0
8262         st%M0.l %m0, %N1"
8263   [(set_attr "type" "fmove_media,fload_media,fpconv_media,arith_media,*,fload_media,fstore_media,load_media,store_media")
8264    (set (attr "highpart")
8265         (cond [(match_test "sh_contains_memref_p (insn)")
8266                (const_string "user")]
8267               (const_string "ignore")))])
8269 (define_insn "movsf_media_nofpu"
8270   [(set (match_operand:SF 0 "general_movdst_operand" "=r,r,r,m")
8271         (match_operand:SF 1 "general_movsrc_operand" "r,F,m,rZ"))]
8272   "TARGET_SHMEDIA
8273    && (register_operand (operands[0], SFmode)
8274        || sh_register_operand (operands[1], SFmode))"
8275   "@
8276         add.l   %1, r63, %0
8277         #
8278         ld%M1.l %m1, %0
8279         st%M0.l %m0, %N1"
8280   [(set_attr "type" "arith_media,*,load_media,store_media")
8281    (set (attr "highpart")
8282         (cond [(match_test "sh_contains_memref_p (insn)")
8283                (const_string "user")]
8284               (const_string "ignore")))])
8286 (define_split
8287   [(set (match_operand:SF 0 "arith_reg_dest" "")
8288         (match_operand:SF 1 "immediate_operand" ""))]
8289   "TARGET_SHMEDIA && reload_completed
8290    && ! FP_REGISTER_P (true_regnum (operands[0]))"
8291   [(set (match_dup 3) (match_dup 2))]
8293   long values;
8294   REAL_VALUE_TYPE value;
8296   REAL_VALUE_FROM_CONST_DOUBLE (value, operands[1]);
8297   REAL_VALUE_TO_TARGET_SINGLE (value, values);
8298   operands[2] = GEN_INT (values);
8300   operands[3] = gen_rtx_REG (DImode, true_regnum (operands[0]));
8303 (define_insn "movsf_i"
8304   [(set (match_operand:SF 0 "general_movdst_operand" "=r,r,r,r,m,l,r")
8305         (match_operand:SF 1 "general_movsrc_operand"  "r,G,FQ,mr,r,r,l"))]
8306   "TARGET_SH1
8307    && (! TARGET_SH2E
8308        /* ??? We provide some insn so that direct_{load,store}[SFmode] get set */
8309        || (REG_P (operands[0]) && REGNO (operands[0]) == 3)
8310        || (REG_P (operands[1]) && REGNO (operands[1]) == 3))
8311    && (arith_reg_operand (operands[0], SFmode)
8312        || arith_reg_operand (operands[1], SFmode))"
8313   "@
8314         mov     %1,%0
8315         mov     #0,%0
8316         mov.l   %1,%0
8317         mov.l   %1,%0
8318         mov.l   %1,%0
8319         lds     %1,%0
8320         sts     %1,%0"
8321   [(set_attr "type" "move,move,pcload,load,store,move,move")])
8323 ;; We may not split the ry/yr/XX alternatives to movsi_ie, since
8324 ;; update_flow_info would not know where to put REG_EQUAL notes
8325 ;; when the destination changes mode.
8326 (define_insn "movsf_ie"
8327   [(set (match_operand:SF 0 "general_movdst_operand"
8328          "=f,r,f,f,fy,f,m,r,r,m,f,y,y,rf,r,y,<,y,y")
8329         (match_operand:SF 1 "general_movsrc_operand"
8330           "f,r,G,H,FQ,mf,f,FQ,mr,r,y,f,>,fr,y,r,y,>,y"))
8331    (use (reg:SI FPSCR_MODES_REG))
8332    (clobber (match_scratch:SI 2 "=X,X,Bsc,Bsc,&z,X,X,X,X,X,X,X,X,y,X,X,X,X,X"))]
8333   "TARGET_SH2E
8334    && (arith_reg_operand (operands[0], SFmode) || fpul_operand (operands[0], SFmode)
8335        || arith_reg_operand (operands[1], SFmode) || fpul_operand (operands[1], SFmode)
8336        || arith_reg_operand (operands[2], SImode))"
8337   "@
8338         fmov    %1,%0
8339         mov     %1,%0
8340         fldi0   %0
8341         fldi1   %0
8342         #
8343         fmov.s  %1,%0
8344         fmov.s  %1,%0
8345         mov.l   %1,%0
8346         mov.l   %1,%0
8347         mov.l   %1,%0
8348         fsts    fpul,%0
8349         flds    %1,fpul
8350         lds.l   %1,%0
8351         #
8352         sts     %1,%0
8353         lds     %1,%0
8354         sts.l   %1,%0
8355         lds.l   %1,%0
8356         ! move optimized away"
8357   [(set_attr "type" "fmove,move,fmove,fmove,pcfload,fload,fstore,pcload,load,
8358                      store,fmove,fmove,load,*,fpul_gp,gp_fpul,fstore,load,nil")
8359    (set_attr "late_fp_use" "*,*,*,*,*,*,yes,*,*,*,*,*,*,*,yes,*,yes,*,*")
8360    (set_attr_alternative "length"
8361      [(const_int 2)
8362       (const_int 2)
8363       (const_int 2)
8364       (const_int 2)
8365       (const_int 4)
8366       (if_then_else
8367         (match_test "TARGET_SH2A")
8368         (const_int 4) (const_int 2))
8369       (if_then_else
8370         (match_test "TARGET_SH2A")
8371         (const_int 4) (const_int 2))
8372       (const_int 2)
8373       (if_then_else
8374         (match_test "TARGET_SH2A")
8375         (const_int 4) (const_int 2))
8376       (if_then_else
8377         (match_test "TARGET_SH2A")
8378         (const_int 4) (const_int 2))
8379       (const_int 2)
8380       (const_int 2)
8381       (const_int 2)
8382       (const_int 4)
8383       (const_int 2)
8384       (const_int 2)
8385       (const_int 2)
8386       (const_int 2)
8387       (const_int 0)])
8388   (set_attr_alternative "fp_mode"
8389      [(if_then_else (eq_attr "fmovd" "yes")
8390                     (const_string "single") (const_string "none"))
8391       (const_string "none")
8392       (const_string "single")
8393       (const_string "single")
8394       (const_string "none")
8395       (if_then_else (eq_attr "fmovd" "yes")
8396                     (const_string "single") (const_string "none"))
8397       (if_then_else (eq_attr "fmovd" "yes")
8398                     (const_string "single") (const_string "none"))
8399       (const_string "none")
8400       (const_string "none")
8401       (const_string "none")
8402       (const_string "none")
8403       (const_string "none")
8404       (const_string "none")
8405       (const_string "none")
8406       (const_string "none")
8407       (const_string "none")
8408       (const_string "none")
8409       (const_string "none")
8410       (const_string "none")])])
8412 (define_split
8413   [(set (match_operand:SF 0 "register_operand" "")
8414         (match_operand:SF 1 "register_operand" ""))
8415    (use (reg:SI FPSCR_MODES_REG))
8416    (clobber (reg:SI FPUL_REG))]
8417   "TARGET_SH1"
8418   [(parallel [(set (reg:SF FPUL_REG) (match_dup 1))
8419               (use (reg:SI FPSCR_MODES_REG))
8420               (clobber (scratch:SI))])
8421    (parallel [(set (match_dup 0) (reg:SF FPUL_REG))
8422               (use (reg:SI FPSCR_MODES_REG))
8423               (clobber (scratch:SI))])]
8424   "")
8426 (define_expand "movsf"
8427   [(set (match_operand:SF 0 "general_movdst_operand" "")
8428         (match_operand:SF 1 "general_movsrc_operand" ""))]
8429   ""
8431   prepare_move_operands (operands, SFmode);
8432   if (TARGET_SHMEDIA)
8433     {
8434       if (TARGET_SHMEDIA_FPU)
8435         emit_insn (gen_movsf_media (operands[0], operands[1]));
8436       else
8437         emit_insn (gen_movsf_media_nofpu (operands[0], operands[1]));
8438       DONE;
8439     }
8440   if (TARGET_SH2E)
8441     {
8442       emit_insn (gen_movsf_ie (operands[0], operands[1]));
8443       DONE;
8444     }
8447 (define_insn "mov_nop"
8448   [(set (match_operand 0 "any_register_operand" "") (match_dup 0))]
8449   "TARGET_SH2E"
8450   ""
8451   [(set_attr "length" "0")
8452    (set_attr "type" "nil")])
8454 (define_expand "reload_insf__frn"
8455   [(parallel [(set (match_operand:SF 0 "register_operand" "=a")
8456                    (match_operand:SF 1 "immediate_operand" "FQ"))
8457               (use (reg:SI FPSCR_MODES_REG))
8458               (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
8459   "TARGET_SH1"
8460   "")
8462 (define_expand "reload_insi__i_fpul"
8463   [(parallel [(set (match_operand:SI 0 "fpul_operand" "=y")
8464                    (match_operand:SI 1 "immediate_operand" "i"))
8465               (clobber (match_operand:SI 2 "register_operand" "=&z"))])]
8466   "TARGET_SH1"
8467   "")
8469 (define_expand "ptabs"
8470   [(set (match_operand 0 "" "=b") (match_operand 1 "" "r"))]
8471   "TARGET_SHMEDIA"
8473   if (!TARGET_PT_FIXED)
8474     {
8475       rtx eq = operands[1];
8477       /* ??? For canonical RTL we really should remove any CONST from EQ
8478          before wrapping it in the AND, and finally wrap the EQ into a
8479          const if is constant.  However, for reload we must expose the
8480          input register or symbolic constant, and we can't have
8481          different insn structures outside of the operands for different
8482          alternatives of the same pattern.  */
8483       eq = gen_rtx_EQ (SImode, gen_rtx_AND (Pmode, eq, GEN_INT (3)),
8484                        GEN_INT (3));
8485       operands[1]
8486         = (gen_rtx_IF_THEN_ELSE
8487             (PDImode,
8488              eq,
8489              gen_rtx_MEM (PDImode, operands[1]),
8490              gen_rtx_fmt_e (TARGET_SHMEDIA32 ? SIGN_EXTEND : TRUNCATE,
8491                             PDImode, operands[1])));
8492     }
8495 ;; expanded by ptabs expander.
8496 (define_insn "*extendsipdi_media"
8497   [(set (match_operand:PDI 0 "target_reg_operand" "=b,b");
8498         (if_then_else:PDI (eq (and:SI (match_operand:SI 1 "target_operand"
8499                                                           "r,Csy")
8500                                       (const_int 3))
8501                               (const_int 3))
8502                           (mem:PDI (match_dup 1))
8503                           (sign_extend:PDI (match_dup 1))))]
8504   "TARGET_SHMEDIA && !TARGET_PT_FIXED"
8505   "@
8506         ptabs   %1, %0
8507         pt      %1, %0"
8508   [(set_attr "type"   "ptabs_media,pt_media")
8509    (set_attr "length" "4,*")])
8511 (define_insn "*truncdipdi_media"
8512   [(set (match_operand:PDI 0 "target_reg_operand" "=b,b");
8513         (if_then_else:PDI (eq (and:DI (match_operand:DI 1 "target_operand"
8514                                                           "r,Csy")
8515                                       (const_int 3))
8516                               (const_int 3))
8517                           (mem:PDI (match_dup 1))
8518                           (truncate:PDI (match_dup 1))))]
8519   "TARGET_SHMEDIA && !TARGET_PT_FIXED"
8520   "@
8521         ptabs   %1, %0
8522         pt      %1, %0"
8523   [(set_attr "type"   "ptabs_media,pt_media")
8524    (set_attr "length" "4,*")])
8526 (define_insn "*movsi_y"
8527   [(set (match_operand:SI 0 "register_operand" "=y,y")
8528         (match_operand:SI 1 "immediate_operand" "Qi,I08"))
8529    (clobber (match_scratch:SI 2 "=&z,r"))]
8530   "TARGET_SH2E
8531    && (reload_in_progress || reload_completed)"
8532   "#"
8533   [(set_attr "length" "4")
8534    (set_attr "type" "pcload,move")])
8536 (define_split
8537   [(set (match_operand:SI 0 "register_operand" "")
8538         (match_operand:SI 1 "immediate_operand" ""))
8539    (clobber (match_operand:SI 2 "register_operand" ""))]
8540   "TARGET_SH1"
8541   [(set (match_dup 2) (match_dup 1))
8542    (set (match_dup 0) (match_dup 2))]
8543   "")
8545 ;; ------------------------------------------------------------------------
8546 ;; Define the real conditional branch instructions.
8547 ;; ------------------------------------------------------------------------
8549 (define_expand "branch_true"
8550   [(set (pc) (if_then_else (ne (reg:SI T_REG) (const_int 0))
8551                            (label_ref (match_operand 0))
8552                            (pc)))]
8553   "TARGET_SH1")
8555 (define_expand "branch_false"
8556   [(set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
8557                            (label_ref (match_operand 0))
8558                            (pc)))]
8559   "TARGET_SH1")
8561 (define_insn_and_split "*cbranch_t"
8562   [(set (pc) (if_then_else (match_operand 1 "cbranch_treg_value")
8563                            (label_ref (match_operand 0))
8564                            (pc)))]
8565   "TARGET_SH1"
8567   return output_branch (sh_eval_treg_value (operands[1]), insn, operands);
8569   "&& 1"
8570   [(const_int 0)]
8572   /* Try to canonicalize the branch condition if it is not one of:
8573         (ne (reg:SI T_REG) (const_int 0))
8574         (eq (reg:SI T_REG) (const_int 0))
8576      Instead of splitting out a new insn, we modify the current insn's
8577      operands as needed.  This preserves things such as REG_DEAD notes.  */
8579   if ((GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)
8580       && REG_P (XEXP (operands[1], 0)) && REGNO (XEXP (operands[1], 0)) == T_REG
8581       && XEXP (operands[1], 1) == const0_rtx)
8582     DONE;
8584   int branch_cond = sh_eval_treg_value (operands[1]);
8585   rtx new_cond_rtx = NULL_RTX;
8587   if (branch_cond == 0)
8588     new_cond_rtx = gen_rtx_EQ (VOIDmode, get_t_reg_rtx (), const0_rtx);
8589   else if (branch_cond == 1)
8590     new_cond_rtx = gen_rtx_NE (VOIDmode, get_t_reg_rtx (), const0_rtx);
8592   if (new_cond_rtx != NULL_RTX)
8593     validate_change (curr_insn, &XEXP (XEXP (PATTERN (curr_insn), 1), 0),
8594                      new_cond_rtx, false);
8595   DONE;
8597   [(set_attr "type" "cbranch")])
8599 ;; Patterns to prevent reorg from re-combining a condbranch with a branch
8600 ;; which destination is too far away.
8601 ;; The const_int_operand is distinct for each branch target; it avoids
8602 ;; unwanted matches with redundant_insn.
8603 (define_insn "block_branch_redirect"
8604   [(set (pc) (unspec [(match_operand 0 "const_int_operand" "")] UNSPEC_BBR))]
8605   "TARGET_SH1"
8606   ""
8607   [(set_attr "length" "0")])
8609 ;; This one has the additional purpose to record a possible scratch register
8610 ;; for the following branch.
8611 ;; ??? Unfortunately, just setting the scratch register is not good enough,
8612 ;; because the insn then might be deemed dead and deleted.  And we can't
8613 ;; make the use in the jump insn explicit because that would disable
8614 ;; delay slot scheduling from the target.
8615 (define_insn "indirect_jump_scratch"
8616   [(set (match_operand:SI 0 "register_operand" "=r")
8617         (unspec:SI [(match_operand 1 "const_int_operand" "")] UNSPEC_BBR))
8618    (set (pc) (unspec [(const_int 0)] UNSPEC_BBR))]
8619   "TARGET_SH1"
8620   ""
8621   [(set_attr "length" "0")])
8623 ;; This one is used to preemt an insn from beyond the bra / braf / jmp
8624 ;; being pulled into the delay slot of a condbranch that has been made to
8625 ;; jump around the unconditional jump because it was out of range.
8626 (define_insn "stuff_delay_slot"
8627   [(set (pc)
8628         (unspec [(match_operand:SI 0 "const_int_operand" "") (pc)
8629                  (match_operand:SI 1 "const_int_operand" "")] UNSPEC_BBR))]
8630   "TARGET_SH1"
8631   ""
8632   [(set_attr "length" "0")
8633    (set_attr "cond_delay_slot" "yes")])
8635 ;; Conditional branch insns
8637 (define_expand "cbranchint4_media"
8638   [(set (pc)
8639         (if_then_else (match_operator 0 "shmedia_cbranch_comparison_operator"
8640                        [(match_operand 1 "" "")
8641                         (match_operand 2 "" "")])
8642                       (match_operand 3 "" "")
8643                       (pc)))]
8644   "TARGET_SHMEDIA"
8646   machine_mode mode = GET_MODE (operands[1]);
8647   if (mode == VOIDmode)
8648     mode = GET_MODE (operands[2]);
8649   if (GET_CODE (operands[0]) == EQ || GET_CODE (operands[0]) == NE)
8650     {
8651       operands[1] = force_reg (mode, operands[1]);
8652       if (CONSTANT_P (operands[2])
8653           && (! satisfies_constraint_I06 (operands[2])))
8654         operands[2] = force_reg (mode, operands[2]);
8655     }
8656   else
8657     {
8658       if (operands[1] != const0_rtx)
8659         operands[1] = force_reg (mode, operands[1]);
8660       if (operands[2] != const0_rtx)
8661         operands[2] = force_reg (mode, operands[2]);
8662     }
8663   switch (GET_CODE (operands[0]))
8664     {
8665     case LEU:
8666     case LE:
8667     case LTU:
8668     case LT:
8669       operands[0] = gen_rtx_fmt_ee (swap_condition (GET_CODE (operands[0])),
8670                                     VOIDmode, operands[2], operands[1]);
8671       operands[1] = XEXP (operands[0], 0);
8672       operands[2] = XEXP (operands[0], 1);
8673       break;
8674     default:
8675       operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
8676                                     VOIDmode, operands[1], operands[2]);
8677       break;
8678     }
8679   operands[3] = gen_rtx_LABEL_REF (Pmode, operands[3]);
8682 (define_expand "cbranchfp4_media"
8683   [(set (pc)
8684         (if_then_else (match_operator 0 "sh_float_comparison_operator"
8685                        [(match_operand 1 "" "")
8686                         (match_operand 2 "" "")])
8687                       (match_operand 3 "" "")
8688                       (pc)))]
8689   "TARGET_SHMEDIA"
8691   rtx tmp = gen_reg_rtx (SImode);
8692   rtx cmp;
8693   if (GET_CODE (operands[0]) == NE)
8694     cmp = gen_rtx_EQ (SImode, operands[1], operands[2]);
8695   else
8696     cmp = gen_rtx_fmt_ee (GET_CODE (operands[0]), SImode,
8697                           operands[1], operands[2]);
8699   emit_insn (gen_cstore4_media (tmp, cmp, operands[1], operands[2]));
8701   if (GET_CODE (cmp) == GET_CODE (operands[0]))
8702     operands[0] = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
8703   else
8704     operands[0] = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
8705   operands[1] = tmp;
8706   operands[2] = const0_rtx;
8707   operands[3] = gen_rtx_LABEL_REF (Pmode, operands[3]);
8710 (define_insn "*beq_media_i"
8711   [(set (pc)
8712         (if_then_else (match_operator 3 "equality_comparison_operator"
8713                         [(match_operand:DI 1 "arith_reg_operand" "r,r")
8714                          (match_operand:DI 2 "arith_operand" "r,I06")])
8715                       (match_operand 0 "target_operand" "b,b")
8716                       (pc)))]
8717   "TARGET_SHMEDIA"
8718   "@
8719         b%o3%'  %1, %2, %0%>
8720         b%o3i%' %1, %2, %0%>"
8721   [(set_attr "type" "cbranch_media")])
8723 (define_insn "*beq_media_i32"
8724   [(set (pc)
8725         (if_then_else (match_operator 3 "equality_comparison_operator"
8726                         [(match_operand:SI 1 "arith_reg_operand" "r,r")
8727                          (match_operand:SI 2 "arith_operand" "r,I06")])
8728                       (match_operand 0 "target_operand" "b,b")
8729                       (pc)))]
8730   "TARGET_SHMEDIA"
8731   "@
8732         b%o3%'  %1, %2, %0%>
8733         b%o3i%' %1, %2, %0%>"
8734   [(set_attr "type" "cbranch_media")])
8736 (define_insn "*bgt_media_i"
8737   [(set (pc)
8738         (if_then_else (match_operator 3 "greater_comparison_operator"
8739                         [(match_operand:DI 1 "arith_reg_or_0_operand" "rN")
8740                          (match_operand:DI 2 "arith_reg_or_0_operand" "rN")])
8741                       (match_operand 0 "target_operand" "b")
8742                       (pc)))]
8743   "TARGET_SHMEDIA"
8744   "b%o3%'       %N1, %N2, %0%>"
8745   [(set_attr "type" "cbranch_media")])
8747 (define_insn "*bgt_media_i32"
8748   [(set (pc)
8749         (if_then_else (match_operator 3 "greater_comparison_operator"
8750                         [(match_operand:SI 1 "arith_reg_or_0_operand" "rN")
8751                          (match_operand:SI 2 "arith_reg_or_0_operand" "rN")])
8752                       (match_operand 0 "target_operand" "b")
8753                       (pc)))]
8754   "TARGET_SHMEDIA"
8755   "b%o3%'       %N1, %N2, %0%>"
8756   [(set_attr "type" "cbranch_media")])
8758 ;; These are only needed to make invert_jump() happy - otherwise, jump
8759 ;; optimization will be silently disabled.
8760 (define_insn "*blt_media_i"
8761   [(set (pc)
8762         (if_then_else (match_operator 3 "less_comparison_operator"
8763                         [(match_operand:DI 1 "arith_reg_or_0_operand" "rN")
8764                          (match_operand:DI 2 "arith_reg_or_0_operand" "rN")])
8765                       (match_operand 0 "target_operand" "b")
8766                       (pc)))]
8767   "TARGET_SHMEDIA"
8768   "b%o3%'       %N2, %N1, %0%>"
8769   [(set_attr "type" "cbranch_media")])
8771 (define_insn "*blt_media_i32"
8772   [(set (pc)
8773         (if_then_else (match_operator 3 "less_comparison_operator"
8774                         [(match_operand:SI 1 "arith_reg_or_0_operand" "rN")
8775                          (match_operand:SI 2 "arith_reg_or_0_operand" "rN")])
8776                       (match_operand 0 "target_operand" "b")
8777                       (pc)))]
8778   "TARGET_SHMEDIA"
8779   "b%o3%'       %N2, %N1, %0%>"
8780   [(set_attr "type" "cbranch_media")])
8782 ;; combiner splitter for test-and-branch on single bit in register.  This
8783 ;; is endian dependent because the non-paradoxical subreg looks different
8784 ;; on big endian.
8785 (define_split
8786   [(set (pc)
8787         (if_then_else
8788           (match_operator 3 "equality_comparison_operator"
8789             [(subreg:SI
8790                (zero_extract:DI
8791                  (subreg:DI (match_operand:SI 1 "extend_reg_operand" "") 0)
8792                  (const_int 1)
8793                  (match_operand 2 "const_int_operand" "")) 0)
8794              (const_int 0)])
8795           (match_operand 0 "target_operand" "")
8796           (pc)))
8797    (clobber (match_operand:SI 4 "arith_reg_dest" ""))]
8798   "TARGET_SHMEDIA && TARGET_LITTLE_ENDIAN"
8799   [(set (match_dup 4) (ashift:SI (match_dup 1) (match_dup 5)))
8800    (set (pc) (if_then_else (match_dup 6) (match_dup 0) (pc)))]
8802   operands[5] = GEN_INT (31 - INTVAL (operands[2]));
8803   operands[6] = (GET_CODE (operands[3]) == EQ
8804                  ? gen_rtx_GE (VOIDmode, operands[4], const0_rtx)
8805                  : gen_rtx_GT (VOIDmode, const0_rtx, operands[4]));
8808 ; operand 0 is the loop count pseudo register
8809 ; operand 1 is the label to jump to at the top of the loop
8810 (define_expand "doloop_end"
8811   [(parallel [(set (pc)
8812                    (if_then_else (ne:SI (match_operand:SI 0 "" "")
8813                                         (const_int 1))
8814                                  (label_ref (match_operand 1 "" ""))
8815                                  (pc)))
8816               (set (match_dup 0)
8817                    (plus:SI (match_dup 0) (const_int -1)))
8818               (clobber (reg:SI T_REG))])]
8819   "TARGET_SH2"
8821   if (GET_MODE (operands[0]) != SImode)
8822     FAIL;
8823   emit_jump_insn (gen_doloop_end_split (operands[0], operands[1], operands[0]));
8824   DONE;
8827 (define_insn_and_split "doloop_end_split"
8828   [(set (pc)
8829         (if_then_else (ne:SI (match_operand:SI 2 "arith_reg_dest" "0")
8830                              (const_int 1))
8831                       (label_ref (match_operand 1 "" ""))
8832                       (pc)))
8833    (set (match_operand:SI 0 "arith_reg_dest" "=r")
8834         (plus:SI (match_dup 2) (const_int -1)))
8835    (clobber (reg:SI T_REG))]
8836   "TARGET_SH2"
8837   "#"
8838   ""
8839   [(parallel [(set (reg:SI T_REG)
8840                    (eq:SI (match_dup 2) (const_int 1)))
8841               (set (match_dup 0) (plus:SI (match_dup 2) (const_int -1)))])
8842    (set (pc) (if_then_else (eq (reg:SI T_REG) (const_int 0))
8843                            (label_ref (match_dup 1))
8844                            (pc)))]
8845   ""
8846   [(set_attr "type" "cbranch")])
8848 ;; ------------------------------------------------------------------------
8849 ;; Jump and linkage insns
8850 ;; ------------------------------------------------------------------------
8852 (define_insn "jump_compact"
8853   [(set (pc)
8854         (label_ref (match_operand 0 "" "")))]
8855   "TARGET_SH1 && !CROSSING_JUMP_P (insn)"
8857   /* The length is 16 if the delay slot is unfilled.  */
8858   if (get_attr_length(insn) > 4)
8859     return output_far_jump(insn, operands[0]);
8860   else
8861     return "bra %l0%#";
8863   [(set_attr "type" "jump")
8864    (set_attr "needs_delay_slot" "yes")])
8866 ;; ??? It would be much saner to explicitly use the scratch register
8867 ;; in the jump insn, and have indirect_jump_scratch only set it,
8868 ;; but fill_simple_delay_slots would refuse to do delay slot filling
8869 ;; from the target then, as it uses simplejump_p.
8870 ;;(define_insn "jump_compact_far"
8871 ;;  [(set (pc)
8872 ;;      (label_ref (match_operand 0 "" "")))
8873 ;;   (use (match_operand 1 "register_operand" "r")]
8874 ;;  "TARGET_SH1"
8875 ;;  "* return output_far_jump(insn, operands[0], operands[1]);"
8876 ;;  [(set_attr "type" "jump")
8877 ;;   (set_attr "needs_delay_slot" "yes")])
8879 (define_insn "jump_media"
8880   [(set (pc)
8881         (match_operand 0 "target_operand" "b"))]
8882   "TARGET_SHMEDIA"
8883   "blink        %0, r63%>"
8884   [(set_attr "type" "jump_media")])
8886 (define_expand "jump"
8887   [(set (pc)
8888         (label_ref (match_operand 0 "" "")))]
8889   ""
8891   if (TARGET_SH1)
8892     emit_jump_insn (gen_jump_compact (operands[0]));
8893   else if (TARGET_SHMEDIA)
8894     {
8895       if (reload_in_progress || reload_completed)
8896         FAIL;
8897       emit_jump_insn (gen_jump_media (gen_rtx_LABEL_REF (Pmode, operands[0])));
8898     }
8899   DONE;
8902 (define_insn "force_mode_for_call"
8903   [(use (reg:SI FPSCR_MODES_REG))]
8904   "TARGET_SHCOMPACT"
8905   ""
8906   [(set_attr "length" "0")
8907    (set (attr "fp_mode")
8908         (if_then_else (eq_attr "fpu_single" "yes")
8909                       (const_string "single") (const_string "double")))])
8911 (define_insn "calli"
8912   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
8913          (match_operand 1 "" ""))
8914    (use (reg:SI FPSCR_MODES_REG))
8915    (clobber (reg:SI PR_REG))]
8916   "TARGET_SH1"
8918   if (TARGET_SH2A && (dbr_sequence_length () == 0))
8919     return "jsr/n       @%0";
8920   else
8921     return "jsr @%0%#";
8923   [(set_attr "type" "call")
8924    (set (attr "fp_mode")
8925         (if_then_else (eq_attr "fpu_single" "yes")
8926                       (const_string "single") (const_string "double")))
8927    (set_attr "needs_delay_slot" "yes")
8928    (set_attr "fp_set" "unknown")])
8930 ;; This is TBR relative jump instruction for SH2A architecture.
8931 ;; Its use is enabled by assigning an attribute "function_vector"
8932 ;; and the vector number to a function during its declaration.
8933 (define_insn "calli_tbr_rel"
8934   [(call (mem (match_operand:SI 0 "symbol_ref_operand" ""))
8935          (match_operand 1 "" ""))
8936    (use (reg:SI FPSCR_MODES_REG))
8937    (clobber (reg:SI PR_REG))]
8938   "TARGET_SH2A && sh2a_is_function_vector_call (operands[0])"
8940   unsigned HOST_WIDE_INT vect_num;
8941   vect_num = sh2a_get_function_vector_number (operands[0]);
8942   operands[2] = GEN_INT (vect_num * 4);
8944   return "jsr/n @@(%O2,tbr)";
8946   [(set_attr "type" "call")
8947    (set (attr "fp_mode")
8948         (if_then_else (eq_attr "fpu_single" "yes")
8949                       (const_string "single") (const_string "double")))
8950    (set_attr "needs_delay_slot" "no")
8951    (set_attr "fp_set" "unknown")])
8953 ;; This is a pc-rel call, using bsrf, for use with PIC.
8954 (define_insn "calli_pcrel"
8955   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
8956          (match_operand 1 "" ""))
8957    (use (reg:SI FPSCR_MODES_REG))
8958    (use (reg:SI PIC_REG))
8959    (use (match_operand 2 "" ""))
8960    (clobber (reg:SI PR_REG))]
8961   "TARGET_SH2"
8963   return       "bsrf    %0"     "\n"
8964          "%O2:%#";
8966   [(set_attr "type" "call")
8967    (set (attr "fp_mode")
8968         (if_then_else (eq_attr "fpu_single" "yes")
8969                       (const_string "single") (const_string "double")))
8970    (set_attr "needs_delay_slot" "yes")
8971    (set_attr "fp_set" "unknown")])
8973 (define_insn_and_split "call_pcrel"
8974   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" ""))
8975          (match_operand 1 "" ""))
8976    (use (reg:SI FPSCR_MODES_REG))
8977    (use (reg:SI PIC_REG))
8978    (clobber (reg:SI PR_REG))
8979    (clobber (match_scratch:SI 2 "=r"))]
8980   "TARGET_SH2"
8981   "#"
8982   "reload_completed"
8983   [(const_int 0)]
8985   rtx lab = PATTERN (gen_call_site ());
8987   if (SYMBOL_REF_LOCAL_P (operands[0]))
8988     emit_insn (gen_sym_label2reg (operands[2], operands[0], lab));
8989   else
8990     emit_insn (gen_symPLT_label2reg (operands[2], operands[0], lab));
8991   emit_call_insn (gen_calli_pcrel (operands[2], operands[1], copy_rtx (lab)));
8992   DONE;
8994   [(set_attr "type" "call")
8995    (set (attr "fp_mode")
8996         (if_then_else (eq_attr "fpu_single" "yes")
8997                       (const_string "single") (const_string "double")))
8998    (set_attr "needs_delay_slot" "yes")
8999    (set_attr "fp_set" "unknown")])
9001 (define_insn "call_compact"
9002   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
9003          (match_operand 1 "" ""))
9004    (match_operand 2 "immediate_operand" "n")
9005    (use (reg:SI R0_REG))
9006    (use (reg:SI R1_REG))
9007    (use (reg:SI FPSCR_MODES_REG))
9008    (clobber (reg:SI PR_REG))]
9009   "TARGET_SHCOMPACT && ! (INTVAL (operands[2]) & CALL_COOKIE_RET_TRAMP (1))"
9010   "jsr  @%0%#"
9011   [(set_attr "type" "call")
9012    (set (attr "fp_mode")
9013         (if_then_else (eq_attr "fpu_single" "yes")
9014                       (const_string "single") (const_string "double")))
9015    (set_attr "needs_delay_slot" "yes")])
9017 (define_insn "call_compact_rettramp"
9018   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
9019          (match_operand 1 "" ""))
9020    (match_operand 2 "immediate_operand" "n")
9021    (use (reg:SI R0_REG))
9022    (use (reg:SI R1_REG))
9023    (use (reg:SI FPSCR_MODES_REG))
9024    (clobber (reg:SI R10_REG))
9025    (clobber (reg:SI PR_REG))]
9026   "TARGET_SHCOMPACT && (INTVAL (operands[2]) & CALL_COOKIE_RET_TRAMP (1))"
9027   "jsr  @%0%#"
9028   [(set_attr "type" "call")
9029    (set (attr "fp_mode")
9030         (if_then_else (eq_attr "fpu_single" "yes")
9031                       (const_string "single") (const_string "double")))
9032    (set_attr "needs_delay_slot" "yes")])
9034 (define_insn "call_media"
9035   [(call (mem:DI (match_operand 0 "target_reg_operand" "b"))
9036          (match_operand 1 "" ""))
9037    (clobber (reg:DI PR_MEDIA_REG))]
9038   "TARGET_SHMEDIA"
9039   "blink        %0, r18"
9040   [(set_attr "type" "jump_media")])
9042 (define_insn "call_valuei"
9043   [(set (match_operand 0 "" "=rf")
9044         (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
9045               (match_operand 2 "" "")))
9046    (use (reg:SI FPSCR_MODES_REG))
9047    (clobber (reg:SI PR_REG))]
9048   "TARGET_SH1"
9050   if (TARGET_SH2A && (dbr_sequence_length () == 0))
9051     return "jsr/n       @%1";
9052   else
9053     return "jsr @%1%#";
9055   [(set_attr "type" "call")
9056    (set (attr "fp_mode")
9057         (if_then_else (eq_attr "fpu_single" "yes")
9058                       (const_string "single") (const_string "double")))
9059    (set_attr "needs_delay_slot" "yes")
9060    (set_attr "fp_set" "unknown")])
9062 ;; This is TBR relative jump instruction for SH2A architecture.
9063 ;; Its use is enabled by assigning an attribute "function_vector"
9064 ;; and the vector number to a function during its declaration.
9065 (define_insn "call_valuei_tbr_rel"
9066   [(set (match_operand 0 "" "=rf")
9067         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
9068               (match_operand 2 "" "")))
9069    (use (reg:SI FPSCR_MODES_REG))
9070    (clobber (reg:SI PR_REG))]
9071   "TARGET_SH2A && sh2a_is_function_vector_call (operands[1])"
9073   unsigned HOST_WIDE_INT vect_num;
9074   vect_num = sh2a_get_function_vector_number (operands[1]);
9075   operands[3] = GEN_INT (vect_num * 4);
9077   return "jsr/n @@(%O3,tbr)";
9079   [(set_attr "type" "call")
9080    (set (attr "fp_mode")
9081         (if_then_else (eq_attr "fpu_single" "yes")
9082                       (const_string "single") (const_string "double")))
9083    (set_attr "needs_delay_slot" "no")
9084    (set_attr "fp_set" "unknown")])
9086 (define_insn "call_valuei_pcrel"
9087   [(set (match_operand 0 "" "=rf")
9088         (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
9089               (match_operand 2 "" "")))
9090    (use (reg:SI FPSCR_MODES_REG))
9091    (use (reg:SI PIC_REG))
9092    (use (match_operand 3 "" ""))
9093    (clobber (reg:SI PR_REG))]
9094   "TARGET_SH2"
9096   return       "bsrf    %1"     "\n"
9097          "%O3:%#";
9099   [(set_attr "type" "call")
9100    (set (attr "fp_mode")
9101         (if_then_else (eq_attr "fpu_single" "yes")
9102                       (const_string "single") (const_string "double")))
9103    (set_attr "needs_delay_slot" "yes")
9104    (set_attr "fp_set" "unknown")])
9106 (define_insn_and_split "call_value_pcrel"
9107   [(set (match_operand 0 "" "=rf")
9108         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
9109               (match_operand 2 "" "")))
9110    (use (reg:SI FPSCR_MODES_REG))
9111    (use (reg:SI PIC_REG))
9112    (clobber (reg:SI PR_REG))
9113    (clobber (match_scratch:SI 3 "=r"))]
9114   "TARGET_SH2"
9115   "#"
9116   "reload_completed"
9117   [(const_int 0)]
9119   rtx lab = PATTERN (gen_call_site ());
9121   if (SYMBOL_REF_LOCAL_P (operands[1]))
9122     emit_insn (gen_sym_label2reg (operands[3], operands[1], lab));
9123   else
9124     emit_insn (gen_symPLT_label2reg (operands[3], operands[1], lab));
9125   emit_call_insn (gen_call_valuei_pcrel (operands[0], operands[3],
9126                                          operands[2], copy_rtx (lab)));
9127   DONE;
9129   [(set_attr "type" "call")
9130    (set (attr "fp_mode")
9131         (if_then_else (eq_attr "fpu_single" "yes")
9132                       (const_string "single") (const_string "double")))
9133    (set_attr "needs_delay_slot" "yes")
9134    (set_attr "fp_set" "unknown")])
9136 (define_insn "call_value_compact"
9137   [(set (match_operand 0 "" "=rf")
9138         (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
9139               (match_operand 2 "" "")))
9140    (match_operand 3 "immediate_operand" "n")
9141    (use (reg:SI R0_REG))
9142    (use (reg:SI R1_REG))
9143    (use (reg:SI FPSCR_MODES_REG))
9144    (clobber (reg:SI PR_REG))]
9145   "TARGET_SHCOMPACT && ! (INTVAL (operands[3]) & CALL_COOKIE_RET_TRAMP (1))"
9146   "jsr  @%1%#"
9147   [(set_attr "type" "call")
9148    (set (attr "fp_mode")
9149         (if_then_else (eq_attr "fpu_single" "yes")
9150                       (const_string "single") (const_string "double")))
9151    (set_attr "needs_delay_slot" "yes")])
9153 (define_insn "call_value_compact_rettramp"
9154   [(set (match_operand 0 "" "=rf")
9155         (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
9156               (match_operand 2 "" "")))
9157    (match_operand 3 "immediate_operand" "n")
9158    (use (reg:SI R0_REG))
9159    (use (reg:SI R1_REG))
9160    (use (reg:SI FPSCR_MODES_REG))
9161    (clobber (reg:SI R10_REG))
9162    (clobber (reg:SI PR_REG))]
9163   "TARGET_SHCOMPACT && (INTVAL (operands[3]) & CALL_COOKIE_RET_TRAMP (1))"
9164   "jsr  @%1%#"
9165   [(set_attr "type" "call")
9166    (set (attr "fp_mode")
9167         (if_then_else (eq_attr "fpu_single" "yes")
9168                       (const_string "single") (const_string "double")))
9169    (set_attr "needs_delay_slot" "yes")])
9171 (define_insn "call_value_media"
9172   [(set (match_operand 0 "" "=rf")
9173         (call (mem:DI (match_operand 1 "target_reg_operand" "b"))
9174               (match_operand 2 "" "")))
9175    (clobber (reg:DI PR_MEDIA_REG))]
9176   "TARGET_SHMEDIA"
9177   "blink        %1, r18"
9178   [(set_attr "type" "jump_media")])
9180 (define_expand "call"
9181   [(parallel [(call (mem:SI (match_operand 0 "arith_reg_operand" ""))
9182                             (match_operand 1 "" ""))
9183               (match_operand 2 "" "")
9184               (use (reg:SI FPSCR_MODES_REG))
9185               (clobber (reg:SI PR_REG))])]
9186   ""
9188   if (TARGET_SHMEDIA)
9189     {
9190       operands[0] = shmedia_prepare_call_address (operands[0], 0);
9191       emit_call_insn (gen_call_media (operands[0], operands[1]));
9192       DONE;
9193     }
9194   else if (TARGET_SHCOMPACT && operands[2] && INTVAL (operands[2]))
9195     {
9196       rtx cookie_rtx = operands[2];
9197       long cookie = INTVAL (cookie_rtx);
9198       rtx func = XEXP (operands[0], 0);
9199       rtx r0, r1;
9201       if (flag_pic)
9202         {
9203           if (GET_CODE (func) == SYMBOL_REF && ! SYMBOL_REF_LOCAL_P (func))
9204             {
9205               rtx reg = gen_reg_rtx (Pmode);
9207               emit_insn (gen_symGOTPLT2reg (reg, func));
9208               func = reg;
9209             }
9210           else
9211             func = legitimize_pic_address (func, Pmode, 0);
9212         }
9214       r0 = gen_rtx_REG (SImode, R0_REG);
9215       r1 = gen_rtx_REG (SImode, R1_REG);
9217       /* Since such a call function may use all call-clobbered
9218          registers, we force a mode switch earlier, so that we don't
9219          run out of registers when adjusting fpscr for the call.  */
9220       emit_insn (gen_force_mode_for_call ());
9222       operands[0]
9223         = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
9224       operands[0] = force_reg (SImode, operands[0]);
9226       emit_move_insn (r0, func);
9227       emit_move_insn (r1, cookie_rtx);
9229       if (cookie & CALL_COOKIE_RET_TRAMP (1))
9230         emit_call_insn (gen_call_compact_rettramp (operands[0], operands[1],
9231                                                    operands[2]));
9232       else
9233         emit_call_insn (gen_call_compact (operands[0], operands[1],
9234                                           operands[2]));
9236       DONE;
9237     }
9238   else if (TARGET_SHCOMPACT && flag_pic
9239            && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
9240            && ! SYMBOL_REF_LOCAL_P (XEXP (operands[0], 0)))
9241     {
9242       rtx reg = gen_reg_rtx (Pmode);
9244       emit_insn (gen_symGOTPLT2reg (reg, XEXP (operands[0], 0)));
9245       XEXP (operands[0], 0) = reg;
9246     }
9247   if (!flag_pic && TARGET_SH2A
9248       && MEM_P (operands[0])
9249       && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
9250     {
9251       if (sh2a_is_function_vector_call (XEXP (operands[0], 0)))
9252         {
9253           emit_call_insn (gen_calli_tbr_rel (XEXP (operands[0], 0),
9254                                              operands[1]));
9255           DONE;
9256         }
9257     }
9258   if (flag_pic && TARGET_SH2
9259       && MEM_P (operands[0])
9260       && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
9261     {
9262       emit_call_insn (gen_call_pcrel (XEXP (operands[0], 0), operands[1]));
9263       DONE;
9264     }
9265   else
9266   {
9267     operands[0] = force_reg (SImode, XEXP (operands[0], 0));
9268     operands[1] = operands[2];
9269   }
9271   emit_call_insn (gen_calli (operands[0], operands[1]));
9272   DONE;
9275 (define_insn "call_pop_compact"
9276   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
9277          (match_operand 1 "" ""))
9278    (match_operand 2 "immediate_operand" "n")
9279    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
9280                                  (match_operand 3 "immediate_operand" "n")))
9281    (use (reg:SI R0_REG))
9282    (use (reg:SI R1_REG))
9283    (use (reg:SI FPSCR_MODES_REG))
9284    (clobber (reg:SI PR_REG))]
9285   "TARGET_SHCOMPACT && ! (INTVAL (operands[2]) & CALL_COOKIE_RET_TRAMP (1))"
9286   "jsr  @%0%#"
9287   [(set_attr "type" "call")
9288    (set (attr "fp_mode")
9289         (if_then_else (eq_attr "fpu_single" "yes")
9290                       (const_string "single") (const_string "double")))
9291    (set_attr "needs_delay_slot" "yes")])
9293 (define_insn "call_pop_compact_rettramp"
9294   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
9295          (match_operand 1 "" ""))
9296    (match_operand 2 "immediate_operand" "n")
9297    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
9298                                  (match_operand 3 "immediate_operand" "n")))
9299    (use (reg:SI R0_REG))
9300    (use (reg:SI R1_REG))
9301    (use (reg:SI FPSCR_MODES_REG))
9302    (clobber (reg:SI R10_REG))
9303    (clobber (reg:SI PR_REG))]
9304   "TARGET_SHCOMPACT && (INTVAL (operands[2]) & CALL_COOKIE_RET_TRAMP (1))"
9305   "jsr  @%0%#"
9306   [(set_attr "type" "call")
9307    (set (attr "fp_mode")
9308         (if_then_else (eq_attr "fpu_single" "yes")
9309                       (const_string "single") (const_string "double")))
9310    (set_attr "needs_delay_slot" "yes")])
9312 (define_expand "call_pop"
9313   [(parallel [(call (mem:SI (match_operand 0 "arith_reg_operand" ""))
9314                     (match_operand 1 "" ""))
9315              (match_operand 2 "" "")
9316              (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
9317                                            (match_operand 3 "" "")))])]
9318   "TARGET_SHCOMPACT"
9320   rtx cookie_rtx;
9321   long cookie;
9322   rtx func;
9323   rtx r0, r1;
9325   gcc_assert (operands[2] && INTVAL (operands[2]));
9326   cookie_rtx = operands[2];
9327   cookie = INTVAL (cookie_rtx);
9328   func = XEXP (operands[0], 0);
9330   if (flag_pic)
9331     {
9332       if (GET_CODE (func) == SYMBOL_REF && ! SYMBOL_REF_LOCAL_P (func))
9333         {
9334           rtx reg = gen_reg_rtx (Pmode);
9335           emit_insn (gen_symGOTPLT2reg (reg, func));
9336           func = reg;
9337         }
9338       else
9339         func = legitimize_pic_address (func, Pmode, 0);
9340     }
9342   r0 = gen_rtx_REG (SImode, R0_REG);
9343   r1 = gen_rtx_REG (SImode, R1_REG);
9345   /* Since such a call function may use all call-clobbered
9346      registers, we force a mode switch earlier, so that we don't
9347      run out of registers when adjusting fpscr for the call.  */
9348   emit_insn (gen_force_mode_for_call ());
9350   operands[0] = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
9351                                  SFUNC_GOT);
9352   operands[0] = force_reg (SImode, operands[0]);
9354   emit_move_insn (r0, func);
9355   emit_move_insn (r1, cookie_rtx);
9357   if (cookie & CALL_COOKIE_RET_TRAMP (1))
9358     emit_call_insn (gen_call_pop_compact_rettramp
9359                      (operands[0], operands[1], operands[2], operands[3]));
9360   else
9361     emit_call_insn (gen_call_pop_compact
9362                      (operands[0], operands[1], operands[2], operands[3]));
9364   DONE;
9367 (define_expand "call_value"
9368   [(parallel [(set (match_operand 0 "arith_reg_operand" "")
9369                    (call (mem:SI (match_operand 1 "arith_reg_operand" ""))
9370                                  (match_operand 2 "" "")))
9371               (match_operand 3 "" "")
9372               (use (reg:SI FPSCR_MODES_REG))
9373               (clobber (reg:SI PR_REG))])]
9374   ""
9376   if (TARGET_SHMEDIA)
9377     {
9378       operands[1] = shmedia_prepare_call_address (operands[1], 0);
9379       emit_call_insn (gen_call_value_media (operands[0], operands[1],
9380                                             operands[2]));
9381       DONE;
9382     }
9383   else if (TARGET_SHCOMPACT && operands[3] && INTVAL (operands[3]))
9384     {
9385       rtx cookie_rtx = operands[3];
9386       long cookie = INTVAL (cookie_rtx);
9387       rtx func = XEXP (operands[1], 0);
9388       rtx r0, r1;
9390       if (flag_pic)
9391         {
9392           if (GET_CODE (func) == SYMBOL_REF && ! SYMBOL_REF_LOCAL_P (func))
9393             {
9394               rtx reg = gen_reg_rtx (Pmode);
9396               emit_insn (gen_symGOTPLT2reg (reg, func));
9397               func = reg;
9398             }
9399           else
9400             func = legitimize_pic_address (func, Pmode, 0);
9401         }
9403       r0 = gen_rtx_REG (SImode, R0_REG);
9404       r1 = gen_rtx_REG (SImode, R1_REG);
9406       /* Since such a call function may use all call-clobbered
9407          registers, we force a mode switch earlier, so that we don't
9408          run out of registers when adjusting fpscr for the call.  */
9409       emit_insn (gen_force_mode_for_call ());
9411       operands[1]
9412         = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
9413       operands[1] = force_reg (SImode, operands[1]);
9415       emit_move_insn (r0, func);
9416       emit_move_insn (r1, cookie_rtx);
9418       if (cookie & CALL_COOKIE_RET_TRAMP (1))
9419         emit_call_insn (gen_call_value_compact_rettramp (operands[0],
9420                                                          operands[1],
9421                                                          operands[2],
9422                                                          operands[3]));
9423       else
9424         emit_call_insn (gen_call_value_compact (operands[0], operands[1],
9425                                                 operands[2], operands[3]));
9427       DONE;
9428     }
9429   else if (TARGET_SHCOMPACT && flag_pic
9430            && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
9431            && ! SYMBOL_REF_LOCAL_P (XEXP (operands[1], 0)))
9432     {
9433       rtx reg = gen_reg_rtx (Pmode);
9435       emit_insn (gen_symGOTPLT2reg (reg, XEXP (operands[1], 0)));
9436       XEXP (operands[1], 0) = reg;
9437     }
9438   if (!flag_pic && TARGET_SH2A
9439       && MEM_P (operands[1])
9440       && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
9441     {
9442       if (sh2a_is_function_vector_call (XEXP (operands[1], 0)))
9443         {
9444           emit_call_insn (gen_call_valuei_tbr_rel (operands[0],
9445                                  XEXP (operands[1], 0), operands[2]));
9446           DONE;
9447         }
9448     }
9449   if (flag_pic && TARGET_SH2
9450       && MEM_P (operands[1])
9451       && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
9452     {
9453       emit_call_insn (gen_call_value_pcrel (operands[0], XEXP (operands[1], 0),
9454                                             operands[2]));
9455       DONE;
9456     }
9457   else
9458     operands[1] = force_reg (SImode, XEXP (operands[1], 0));
9460   emit_call_insn (gen_call_valuei (operands[0], operands[1], operands[2]));
9461   DONE;
9464 (define_insn "sibcalli"
9465   [(call (mem:SI (match_operand:SI 0 "register_operand" "k"))
9466          (match_operand 1 "" ""))
9467    (use (reg:SI FPSCR_MODES_REG))
9468    (return)]
9469   "TARGET_SH1"
9470   "jmp  @%0%#"
9471   [(set_attr "needs_delay_slot" "yes")
9472    (set (attr "fp_mode")
9473         (if_then_else (eq_attr "fpu_single" "yes")
9474                       (const_string "single") (const_string "double")))
9475    (set_attr "type" "jump_ind")])
9477 (define_insn "sibcalli_pcrel"
9478   [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "k"))
9479          (match_operand 1 "" ""))
9480    (use (match_operand 2 "" ""))
9481    (use (reg:SI FPSCR_MODES_REG))
9482    (return)]
9483   "TARGET_SH2"
9485   return       "braf    %0"     "\n"
9486          "%O2:%#";
9488   [(set_attr "needs_delay_slot" "yes")
9489    (set (attr "fp_mode")
9490         (if_then_else (eq_attr "fpu_single" "yes")
9491                       (const_string "single") (const_string "double")))
9492    (set_attr "type" "jump_ind")])
9494 ;; This uses an unspec to describe that the symbol_ref is very close.
9495 (define_insn "sibcalli_thunk"
9496   [(call (mem:SI (unspec:SI [(match_operand:SI 0 "symbol_ref_operand" "")]
9497                              UNSPEC_THUNK))
9498          (match_operand 1 "" ""))
9499    (use (reg:SI FPSCR_MODES_REG))
9500    (return)]
9501   "TARGET_SH1"
9502   "bra  %O0"
9503   [(set_attr "needs_delay_slot" "yes")
9504    (set (attr "fp_mode")
9505         (if_then_else (eq_attr "fpu_single" "yes")
9506                       (const_string "single") (const_string "double")))
9507    (set_attr "type" "jump")
9508    (set_attr "length" "2")])
9510 (define_insn_and_split "sibcall_pcrel"
9511   [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" ""))
9512          (match_operand 1 "" ""))
9513    (use (reg:SI FPSCR_MODES_REG))
9514    (clobber (match_scratch:SI 2 "=k"))
9515    (return)]
9516   "TARGET_SH2"
9517   "#"
9518   "reload_completed"
9519   [(const_int 0)]
9521   rtx lab = PATTERN (gen_call_site ());
9522   rtx call_insn;
9524   emit_insn (gen_sym_label2reg (operands[2], operands[0], lab));
9525   call_insn = emit_call_insn (gen_sibcalli_pcrel (operands[2], operands[1],
9526                                                   copy_rtx (lab)));
9527   SIBLING_CALL_P (call_insn) = 1;
9528   DONE;
9530   [(set_attr "needs_delay_slot" "yes")
9531    (set (attr "fp_mode")
9532         (if_then_else (eq_attr "fpu_single" "yes")
9533                       (const_string "single") (const_string "double")))
9534    (set_attr "type" "jump_ind")])
9536 (define_insn "sibcall_compact"
9537   [(call (mem:SI (match_operand:SI 0 "register_operand" "k,k"))
9538          (match_operand 1 "" ""))
9539    (return)
9540    (use (match_operand:SI 2 "register_operand" "z,x"))
9541    (use (reg:SI R1_REG))
9542    (use (reg:SI FPSCR_MODES_REG))
9543    ;; We want to make sure the `x' above will only match MACH_REG
9544    ;; because sibcall_epilogue may clobber MACL_REG.
9545    (clobber (reg:SI MACL_REG))]
9546   "TARGET_SHCOMPACT"
9548   static const char* alt[] =
9549   {
9550        "jmp     @%0%#",
9552        "jmp     @%0"    "\n"
9553     "   sts     %2,r0"
9554   };
9555   return alt[which_alternative];
9557   [(set_attr "needs_delay_slot" "yes,no")
9558    (set_attr "length" "2,4")
9559    (set (attr "fp_mode") (const_string "single"))
9560    (set_attr "type" "jump_ind")])
9562 (define_insn "sibcall_media"
9563   [(call (mem:DI (match_operand 0 "target_reg_operand" "k"))
9564          (match_operand 1 "" ""))
9565    (use (reg:SI PR_MEDIA_REG))
9566    (return)]
9567   "TARGET_SHMEDIA"
9568   "blink        %0, r63"
9569   [(set_attr "type" "jump_media")])
9571 (define_expand "sibcall"
9572   [(parallel
9573     [(call (mem:SI (match_operand 0 "arith_reg_operand" ""))
9574            (match_operand 1 "" ""))
9575      (match_operand 2 "" "")
9576    (use (reg:SI FPSCR_MODES_REG))
9577      (return)])]
9578   ""
9580   if (TARGET_SHMEDIA)
9581     {
9582       operands[0] = shmedia_prepare_call_address (operands[0], 1);
9583       emit_call_insn (gen_sibcall_media (operands[0], operands[1]));
9584       DONE;
9585     }
9586   else if (TARGET_SHCOMPACT && operands[2]
9587            && (INTVAL (operands[2]) & ~ CALL_COOKIE_RET_TRAMP (1)))
9588     {
9589       rtx cookie_rtx = operands[2];
9590       long cookie = INTVAL (cookie_rtx);
9591       rtx func = XEXP (operands[0], 0);
9592       rtx mach, r1;
9594       if (flag_pic)
9595         {
9596           if (GET_CODE (func) == SYMBOL_REF && ! SYMBOL_REF_LOCAL_P (func))
9597             {
9598               rtx reg = gen_reg_rtx (Pmode);
9600               emit_insn (gen_symGOT2reg (reg, func));
9601               func = reg;
9602             }
9603           else
9604             func = legitimize_pic_address (func, Pmode, 0);
9605         }
9607       /* FIXME: if we could tell whether all argument registers are
9608          already taken, we could decide whether to force the use of
9609          MACH_REG or to stick to R0_REG.  Unfortunately, there's no
9610          simple way to tell.  We could use the CALL_COOKIE, but we
9611          can't currently tell a register used for regular argument
9612          passing from one that is unused.  If we leave it up to reload
9613          to decide which register to use, it seems to always choose
9614          R0_REG, which leaves no available registers in SIBCALL_REGS
9615          to hold the address of the trampoline.  */
9616       mach = gen_rtx_REG (SImode, MACH_REG);
9617       r1 = gen_rtx_REG (SImode, R1_REG);
9619       /* Since such a call function may use all call-clobbered
9620          registers, we force a mode switch earlier, so that we don't
9621          run out of registers when adjusting fpscr for the call.  */
9622       emit_insn (gen_force_mode_for_call ());
9624       operands[0]
9625         = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
9626       operands[0] = force_reg (SImode, operands[0]);
9628       /* We don't need a return trampoline, since the callee will
9629          return directly to the upper caller.  */
9630       if (cookie & CALL_COOKIE_RET_TRAMP (1))
9631         {
9632           cookie &= ~ CALL_COOKIE_RET_TRAMP (1);
9633           cookie_rtx = GEN_INT (cookie);
9634         }
9636       emit_move_insn (mach, func);
9637       emit_move_insn (r1, cookie_rtx);
9639       emit_call_insn (gen_sibcall_compact (operands[0], operands[1], mach));
9640       DONE;
9641     }
9642   else if (TARGET_SHCOMPACT && flag_pic
9643            && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
9644            && ! SYMBOL_REF_LOCAL_P (XEXP (operands[0], 0)))
9645     {
9646       rtx reg = gen_reg_rtx (Pmode);
9648       emit_insn (gen_symGOT2reg (reg, XEXP (operands[0], 0)));
9649       XEXP (operands[0], 0) = reg;
9650     }
9651   if (flag_pic && TARGET_SH2
9652       && MEM_P (operands[0])
9653       && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
9654       /* The PLT needs the PIC register, but the epilogue would have
9655          to restore it, so we can only use PC-relative PIC calls for
9656          static functions.  */
9657       && SYMBOL_REF_LOCAL_P (XEXP (operands[0], 0)))
9658     {
9659       emit_call_insn (gen_sibcall_pcrel (XEXP (operands[0], 0), operands[1]));
9660       DONE;
9661     }
9662   else
9663     operands[0] = force_reg (SImode, XEXP (operands[0], 0));
9665   emit_call_insn (gen_sibcalli (operands[0], operands[1]));
9666   DONE;
9669 (define_insn "sibcall_valuei"
9670   [(set (match_operand 0 "" "=rf")
9671         (call (mem:SI (match_operand:SI 1 "register_operand" "k"))
9672               (match_operand 2 "" "")))
9673    (use (reg:SI FPSCR_MODES_REG))
9674    (return)]
9675   "TARGET_SH1"
9676   "jmp  @%1%#"
9677   [(set_attr "needs_delay_slot" "yes")
9678    (set (attr "fp_mode")
9679         (if_then_else (eq_attr "fpu_single" "yes")
9680                       (const_string "single") (const_string "double")))
9681    (set_attr "type" "jump_ind")])
9683 (define_insn "sibcall_valuei_pcrel"
9684   [(set (match_operand 0 "" "=rf")
9685         (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "k"))
9686               (match_operand 2 "" "")))
9687    (use (match_operand 3 "" ""))
9688    (use (reg:SI FPSCR_MODES_REG))
9689    (return)]
9690   "TARGET_SH2"
9692   return       "braf    %1"     "\n"
9693          "%O3:%#";
9695   [(set_attr "needs_delay_slot" "yes")
9696    (set (attr "fp_mode")
9697         (if_then_else (eq_attr "fpu_single" "yes")
9698                       (const_string "single") (const_string "double")))
9699    (set_attr "type" "jump_ind")])
9701 (define_insn_and_split "sibcall_value_pcrel"
9702   [(set (match_operand 0 "" "=rf")
9703         (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
9704               (match_operand 2 "" "")))
9705    (use (reg:SI FPSCR_MODES_REG))
9706    (clobber (match_scratch:SI 3 "=k"))
9707    (return)]
9708   "TARGET_SH2"
9709   "#"
9710   "reload_completed"
9711   [(const_int 0)]
9713   rtx lab = PATTERN (gen_call_site ());
9714   rtx call_insn;
9716   emit_insn (gen_sym_label2reg (operands[3], operands[1], lab));
9717   call_insn = emit_call_insn (gen_sibcall_valuei_pcrel (operands[0],
9718                                                         operands[3],
9719                                                         operands[2],
9720                                                         copy_rtx (lab)));
9721   SIBLING_CALL_P (call_insn) = 1;
9722   DONE;
9724   [(set_attr "needs_delay_slot" "yes")
9725    (set (attr "fp_mode")
9726         (if_then_else (eq_attr "fpu_single" "yes")
9727                       (const_string "single") (const_string "double")))
9728    (set_attr "type" "jump_ind")])
9730 (define_insn "sibcall_value_compact"
9731   [(set (match_operand 0 "" "=rf,rf")
9732         (call (mem:SI (match_operand:SI 1 "register_operand" "k,k"))
9733               (match_operand 2 "" "")))
9734    (return)
9735    (use (match_operand:SI 3 "register_operand" "z,x"))
9736    (use (reg:SI R1_REG))
9737    (use (reg:SI FPSCR_MODES_REG))
9738    ;; We want to make sure the `x' above will only match MACH_REG
9739    ;; because sibcall_epilogue may clobber MACL_REG.
9740    (clobber (reg:SI MACL_REG))]
9741   "TARGET_SHCOMPACT"
9743   static const char* alt[] =
9744   {
9745        "jmp     @%1%#",
9747        "jmp     @%1"    "\n"
9748     "   sts     %3,r0"
9749   };
9750   return alt[which_alternative];
9752   [(set_attr "needs_delay_slot" "yes,no")
9753    (set_attr "length" "2,4")
9754    (set (attr "fp_mode") (const_string "single"))
9755    (set_attr "type" "jump_ind")])
9757 (define_insn "sibcall_value_media"
9758   [(set (match_operand 0 "" "=rf")
9759         (call (mem:DI (match_operand 1 "target_reg_operand" "k"))
9760               (match_operand 2 "" "")))
9761    (use (reg:SI PR_MEDIA_REG))
9762    (return)]
9763   "TARGET_SHMEDIA"
9764   "blink        %1, r63"
9765   [(set_attr "type" "jump_media")])
9767 (define_expand "sibcall_value"
9768   [(parallel
9769     [(set (match_operand 0 "arith_reg_operand" "")
9770           (call (mem:SI (match_operand 1 "arith_reg_operand" ""))
9771                 (match_operand 2 "" "")))
9772      (match_operand 3 "" "")
9773    (use (reg:SI FPSCR_MODES_REG))
9774      (return)])]
9775   ""
9777   if (TARGET_SHMEDIA)
9778     {
9779       operands[1] = shmedia_prepare_call_address (operands[1], 1);
9780       emit_call_insn (gen_sibcall_value_media (operands[0], operands[1],
9781                                                operands[2]));
9782       DONE;
9783     }
9784   else if (TARGET_SHCOMPACT && operands[3]
9785            && (INTVAL (operands[3]) & ~ CALL_COOKIE_RET_TRAMP (1)))
9786     {
9787       rtx cookie_rtx = operands[3];
9788       long cookie = INTVAL (cookie_rtx);
9789       rtx func = XEXP (operands[1], 0);
9790       rtx mach, r1;
9792       if (flag_pic)
9793         {
9794           if (GET_CODE (func) == SYMBOL_REF && ! SYMBOL_REF_LOCAL_P (func))
9795             {
9796               rtx reg = gen_reg_rtx (Pmode);
9798               emit_insn (gen_symGOT2reg (reg, func));
9799               func = reg;
9800             }
9801           else
9802             func = legitimize_pic_address (func, Pmode, 0);
9803         }
9805       /* FIXME: if we could tell whether all argument registers are
9806          already taken, we could decide whether to force the use of
9807          MACH_REG or to stick to R0_REG.  Unfortunately, there's no
9808          simple way to tell.  We could use the CALL_COOKIE, but we
9809          can't currently tell a register used for regular argument
9810          passing from one that is unused.  If we leave it up to reload
9811          to decide which register to use, it seems to always choose
9812          R0_REG, which leaves no available registers in SIBCALL_REGS
9813          to hold the address of the trampoline.  */
9814       mach = gen_rtx_REG (SImode, MACH_REG);
9815       r1 = gen_rtx_REG (SImode, R1_REG);
9817       /* Since such a call function may use all call-clobbered
9818          registers, we force a mode switch earlier, so that we don't
9819          run out of registers when adjusting fpscr for the call.  */
9820       emit_insn (gen_force_mode_for_call ());
9822       operands[1]
9823         = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
9824       operands[1] = force_reg (SImode, operands[1]);
9826       /* We don't need a return trampoline, since the callee will
9827          return directly to the upper caller.  */
9828       if (cookie & CALL_COOKIE_RET_TRAMP (1))
9829         {
9830           cookie &= ~ CALL_COOKIE_RET_TRAMP (1);
9831           cookie_rtx = GEN_INT (cookie);
9832         }
9834       emit_move_insn (mach, func);
9835       emit_move_insn (r1, cookie_rtx);
9837       emit_call_insn (gen_sibcall_value_compact (operands[0], operands[1],
9838                                                  operands[2], mach));
9839       DONE;
9840     }
9841   else if (TARGET_SHCOMPACT && flag_pic
9842            && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
9843            && ! SYMBOL_REF_LOCAL_P (XEXP (operands[1], 0)))
9844     {
9845       rtx reg = gen_reg_rtx (Pmode);
9847       emit_insn (gen_symGOT2reg (reg, XEXP (operands[1], 0)));
9848       XEXP (operands[1], 0) = reg;
9849     }
9850   if (flag_pic && TARGET_SH2
9851       && MEM_P (operands[1])
9852       && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
9853       /* The PLT needs the PIC register, but the epilogue would have
9854          to restore it, so we can only use PC-relative PIC calls for
9855          static functions.  */
9856       && SYMBOL_REF_LOCAL_P (XEXP (operands[1], 0)))
9857     {
9858       emit_call_insn (gen_sibcall_value_pcrel (operands[0],
9859                                                XEXP (operands[1], 0),
9860                                                operands[2]));
9861       DONE;
9862     }
9863   else
9864     operands[1] = force_reg (SImode, XEXP (operands[1], 0));
9866   emit_call_insn (gen_sibcall_valuei (operands[0], operands[1], operands[2]));
9867   DONE;
9870 (define_insn "call_value_pop_compact"
9871   [(set (match_operand 0 "" "=rf")
9872         (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
9873               (match_operand 2 "" "")))
9874    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
9875                                  (match_operand 4 "immediate_operand" "n")))
9876    (match_operand 3 "immediate_operand" "n")
9877    (use (reg:SI R0_REG))
9878    (use (reg:SI R1_REG))
9879    (use (reg:SI FPSCR_MODES_REG))
9880    (clobber (reg:SI PR_REG))]
9881   "TARGET_SHCOMPACT && ! (INTVAL (operands[3]) & CALL_COOKIE_RET_TRAMP (1))"
9882   "jsr  @%1%#"
9883   [(set_attr "type" "call")
9884    (set (attr "fp_mode")
9885         (if_then_else (eq_attr "fpu_single" "yes")
9886                       (const_string "single") (const_string "double")))
9887    (set_attr "needs_delay_slot" "yes")])
9889 (define_insn "call_value_pop_compact_rettramp"
9890   [(set (match_operand 0 "" "=rf")
9891         (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
9892               (match_operand 2 "" "")))
9893    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
9894                                  (match_operand 4 "immediate_operand" "n")))
9895    (match_operand 3 "immediate_operand" "n")
9896    (use (reg:SI R0_REG))
9897    (use (reg:SI R1_REG))
9898    (use (reg:SI FPSCR_MODES_REG))
9899    (clobber (reg:SI R10_REG))
9900    (clobber (reg:SI PR_REG))]
9901   "TARGET_SHCOMPACT && (INTVAL (operands[3]) & CALL_COOKIE_RET_TRAMP (1))"
9902   "jsr  @%1%#"
9903   [(set_attr "type" "call")
9904    (set (attr "fp_mode")
9905         (if_then_else (eq_attr "fpu_single" "yes")
9906                       (const_string "single") (const_string "double")))
9907    (set_attr "needs_delay_slot" "yes")])
9909 (define_expand "call_value_pop"
9910   [(parallel [(set (match_operand 0 "arith_reg_operand" "")
9911                    (call (mem:SI (match_operand 1 "arith_reg_operand" ""))
9912                                  (match_operand 2 "" "")))
9913               (match_operand 3 "" "")
9914               (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
9915                                             (match_operand 4 "" "")))])]
9916   "TARGET_SHCOMPACT"
9918   rtx cookie_rtx;
9919   long cookie;
9920   rtx func;
9921   rtx r0, r1;
9923   gcc_assert (TARGET_SHCOMPACT && operands[3] && INTVAL (operands[3]));
9924   cookie_rtx = operands[3];
9925   cookie = INTVAL (cookie_rtx);
9926   func = XEXP (operands[1], 0);
9928   if (flag_pic)
9929     {
9930       if (GET_CODE (func) == SYMBOL_REF && ! SYMBOL_REF_LOCAL_P (func))
9931         {
9932           rtx reg = gen_reg_rtx (Pmode);
9934           emit_insn (gen_symGOTPLT2reg (reg, func));
9935           func = reg;
9936         }
9937       else
9938         func = legitimize_pic_address (func, Pmode, 0);
9939     }
9941   r0 = gen_rtx_REG (SImode, R0_REG);
9942   r1 = gen_rtx_REG (SImode, R1_REG);
9944   /* Since such a call function may use all call-clobbered
9945      registers, we force a mode switch earlier, so that we don't
9946      run out of registers when adjusting fpscr for the call.  */
9947   emit_insn (gen_force_mode_for_call ());
9949   operands[1] = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
9950                                  SFUNC_GOT);
9951   operands[1] = force_reg (SImode, operands[1]);
9953   emit_move_insn (r0, func);
9954   emit_move_insn (r1, cookie_rtx);
9956   if (cookie & CALL_COOKIE_RET_TRAMP (1))
9957     emit_call_insn (gen_call_value_pop_compact_rettramp
9958                         (operands[0], operands[1], operands[2],
9959                          operands[3], operands[4]));
9960   else
9961     emit_call_insn (gen_call_value_pop_compact
9962                         (operands[0], operands[1], operands[2],
9963                          operands[3], operands[4]));
9965   DONE;
9968 (define_expand "sibcall_epilogue"
9969   [(return)]
9970   ""
9972   sh_expand_epilogue (true);
9973   if (TARGET_SHCOMPACT)
9974     {
9975       rtx_insn *insn;
9976       rtx set;
9978       /* If epilogue clobbers r0, preserve it in macl.  */
9979       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
9980         if ((set = single_set (insn))
9981             && REG_P (SET_DEST (set))
9982             && REGNO (SET_DEST (set)) == R0_REG)
9983           {
9984             rtx r0 = gen_rtx_REG (SImode, R0_REG);
9985             rtx tmp = gen_rtx_REG (SImode, MACL_REG);
9987             /* We can't tell at this point whether the sibcall is a
9988                sibcall_compact and, if it is, whether it uses r0 or
9989                mach as operand 2, so let the instructions that
9990                preserve r0 be optimized away if r0 turns out to be
9991                dead.  */
9992             emit_insn_before (gen_rtx_SET (SImode, tmp, r0), insn);
9993             emit_move_insn (r0, tmp);
9994             break;
9995           }
9996     }
9997   DONE;
10000 (define_insn "indirect_jump_compact"
10001   [(set (pc)
10002         (match_operand:SI 0 "arith_reg_operand" "r"))]
10003   "TARGET_SH1"
10004   "jmp  @%0%#"
10005   [(set_attr "needs_delay_slot" "yes")
10006    (set_attr "type" "jump_ind")])
10008 (define_expand "indirect_jump"
10009   [(set (pc)
10010         (match_operand 0 "register_operand" ""))]
10011   ""
10013   if (GET_MODE (operands[0]) != Pmode)
10014     operands[0] = gen_rtx_SUBREG (Pmode, operands[0], 0);
10017 ;; The use of operand 1 / 2 helps us distinguish case table jumps
10018 ;; which can be present in structured code from indirect jumps which can not
10019 ;; be present in structured code.  This allows -fprofile-arcs to work.
10021 ;; For SH1 processors.
10022 (define_insn "casesi_jump_1"
10023   [(set (pc)
10024         (match_operand:SI 0 "register_operand" "r"))
10025    (use (label_ref (match_operand 1 "" "")))]
10026   "TARGET_SH1"
10027   "jmp  @%0%#"
10028   [(set_attr "needs_delay_slot" "yes")
10029    (set_attr "type" "jump_ind")])
10031 ;; For all later processors.
10032 (define_insn "casesi_jump_2"
10033   [(set (pc) (plus:SI (match_operand:SI 0 "register_operand" "r")
10034                       (label_ref (match_operand 1 "" ""))))
10035    (use (label_ref (match_operand 2 "" "")))]
10036   "TARGET_SH2
10037    && (! INSN_UID (operands[1]) || prev_real_insn (operands[1]) == insn)"
10038   "braf %0%#"
10039   [(set_attr "needs_delay_slot" "yes")
10040    (set_attr "type" "jump_ind")])
10042 (define_insn "casesi_jump_media"
10043   [(set (pc) (match_operand 0 "target_reg_operand" "b"))
10044    (use (label_ref (match_operand 1 "" "")))]
10045   "TARGET_SHMEDIA"
10046   "blink        %0, r63"
10047   [(set_attr "type" "jump_media")])
10049 ;; Call subroutine returning any type.
10050 ;; ??? This probably doesn't work.
10051 (define_expand "untyped_call"
10052   [(parallel [(call (match_operand 0 "" "")
10053                     (const_int 0))
10054               (match_operand 1 "" "")
10055               (match_operand 2 "" "")])]
10056   "(TARGET_SH2E || TARGET_SH2A) || TARGET_SHMEDIA"
10058   if (! TARGET_SHMEDIA)
10059     {
10060       /* RA does not know that the call sets the function value registers.
10061          We avoid problems by claiming that those registers are clobbered
10062          at this point.  */
10063       for (int i = 0; i < XVECLEN (operands[2], 0); i++)
10064         {
10065           rtx set = XVECEXP (operands[2], 0, i);
10066           emit_clobber (SET_SRC (set));
10067         }
10068     }
10070   emit_call_insn (gen_call (operands[0], const0_rtx, const0_rtx));
10072   for (int i = 0; i < XVECLEN (operands[2], 0); i++)
10073     {
10074       rtx set = XVECEXP (operands[2], 0, i);
10075       emit_move_insn (SET_DEST (set), SET_SRC (set));
10076     }
10078   /* The optimizer does not know that the call sets the function value
10079      registers we stored in the result block.  We avoid problems by
10080      claiming that all hard registers are used and clobbered at this
10081      point.  */
10082   emit_insn (gen_blockage ());
10084   DONE;
10087 ;; ------------------------------------------------------------------------
10088 ;; Misc insns
10089 ;; ------------------------------------------------------------------------
10091 (define_insn "dect"
10092   [(set (reg:SI T_REG)
10093         (eq:SI (match_operand:SI 1 "arith_reg_dest" "0") (const_int 1)))
10094    (set (match_operand:SI 0 "arith_reg_dest" "=r")
10095         (plus:SI (match_dup 1) (const_int -1)))]
10096   "TARGET_SH2"
10097   "dt   %0"
10098   [(set_attr "type" "arith")])
10100 (define_insn "nop"
10101   [(const_int 0)]
10102   ""
10103   "nop")
10105 ;; Load address of a label. This is only generated by the casesi expand,
10106 ;; and by machine_dependent_reorg (fixing up fp moves).
10107 ;; This must use unspec, because this only works for labels that are
10108 ;; within range.
10109 (define_insn "mova"
10110   [(set (reg:SI R0_REG)
10111         (unspec:SI [(label_ref (match_operand 0 "" ""))] UNSPEC_MOVA))]
10112   "TARGET_SH1"
10113   "mova %O0,r0"
10114   [(set_attr "in_delay_slot" "no")
10115    (set_attr "type" "arith")])
10117 ;; machine_dependent_reorg will make this a `mova'.
10118 (define_insn "mova_const"
10119   [(set (reg:SI R0_REG)
10120         (unspec:SI [(match_operand 0 "immediate_operand" "i")] UNSPEC_MOVA))]
10121   "TARGET_SH1"
10122   "#"
10123   [(set_attr "in_delay_slot" "no")
10124    (set_attr "type" "arith")])
10126 (define_expand "GOTaddr2picreg"
10127   [(set (reg:SI R0_REG)
10128         (unspec:SI [(const:SI (unspec:SI [(match_dup 1)] UNSPEC_PIC))]
10129                    UNSPEC_MOVA))
10130    (set (match_dup 0) (const:SI (unspec:SI [(match_dup 1)] UNSPEC_PIC)))
10131    (set (match_dup 0) (plus:SI (match_dup 0) (reg:SI R0_REG)))]
10132   ""
10134   if (TARGET_VXWORKS_RTP)
10135     {
10136       rtx gott_base = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE);
10137       rtx gott_index = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
10138       emit_insn (gen_vxworks_picreg (gott_base, gott_index));
10139       DONE;
10140     }
10142   operands[0] = gen_rtx_REG (Pmode, PIC_REG);
10143   operands[1] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);
10145   if (TARGET_SHMEDIA)
10146     {
10147       rtx tr = gen_rtx_REG (Pmode, TR0_REG);
10148       rtx pic = operands[0];
10149       rtx lab = PATTERN (gen_call_site ());
10150       rtx insn, equiv;
10152       equiv = operands[1];
10153       operands[1] = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, operands[1], lab),
10154                                     UNSPEC_PCREL_SYMOFF);
10155       operands[1] = gen_rtx_CONST (Pmode, operands[1]);
10157       if (Pmode == SImode)
10158         {
10159           emit_insn (gen_movsi_const (pic, operands[1]));
10160           emit_insn (gen_ptrel_si (tr, pic, copy_rtx (lab)));
10161         }
10162       else
10163         {
10164           emit_insn (gen_movdi_const (pic, operands[1]));
10165           emit_insn (gen_ptrel_di (tr, pic, copy_rtx (lab)));
10166         }
10168       insn = emit_move_insn (operands[0], tr);
10170       set_unique_reg_note (insn, REG_EQUAL, equiv);
10172       DONE;
10173     }
10176 ;; A helper for GOTaddr2picreg to finish up the initialization of the
10177 ;; PIC register.
10178 (define_expand "vxworks_picreg"
10179   [(set (reg:SI PIC_REG)
10180         (const:SI (unspec:SI [(match_operand:SI 0 "" "")] UNSPEC_PIC)))
10181    (set (reg:SI R0_REG)
10182         (const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PIC)))
10183    (set (reg:SI PIC_REG)
10184         (mem:SI (reg:SI PIC_REG)))
10185    (set (reg:SI PIC_REG)
10186         (mem:SI (plus:SI (reg:SI PIC_REG)
10187                          (reg:SI R0_REG))))]
10188   "TARGET_VXWORKS_RTP")
10190 (define_insn "*ptb"
10191   [(set (match_operand 0 "target_reg_operand" "=b")
10192         (const (unspec [(match_operand 1 "" "Csy")]
10193                              UNSPEC_DATALABEL)))]
10194   "TARGET_SHMEDIA && flag_pic
10195    && satisfies_constraint_Csy (operands[1])"
10196   "ptb/u        datalabel %1, %0"
10197   [(set_attr "type" "ptabs_media")
10198    (set_attr "length" "*")])
10200 (define_insn "ptrel_si"
10201   [(set (match_operand:SI 0 "target_reg_operand" "=b")
10202         (plus:SI (match_operand:SI 1 "register_operand" "r")
10203               (pc)))
10204    (match_operand:SI 2 "" "")]
10205   "TARGET_SHMEDIA"
10206   "%O2: ptrel/u %1, %0"
10207   [(set_attr "type" "ptabs_media")])
10209 (define_insn "ptrel_di"
10210   [(set (match_operand:DI 0 "target_reg_operand" "=b")
10211         (plus:DI (match_operand:DI 1 "register_operand" "r")
10212               (pc)))
10213    (match_operand:DI 2 "" "")]
10214   "TARGET_SHMEDIA"
10215   "%O2: ptrel/u %1, %0"
10216   [(set_attr "type" "ptabs_media")])
10218 (define_expand "builtin_setjmp_receiver"
10219   [(match_operand 0 "" "")]
10220   "flag_pic"
10222   emit_insn (gen_GOTaddr2picreg ());
10223   DONE;
10226 (define_expand "call_site"
10227   [(unspec [(match_dup 0)] UNSPEC_CALLER)]
10228   "TARGET_SH1"
10230   static HOST_WIDE_INT i = 0;
10231   operands[0] = GEN_INT (i);
10232   i++;
10235 ;; op0 = op1 + r12 but hide it before reload completed.  See the comment
10236 ;; in symGOT_load expand.
10237 (define_insn_and_split "chk_guard_add"
10238   [(set (match_operand:SI 0 "register_operand" "=&r")
10239         (unspec:SI [(match_operand:SI 1 "register_operand" "r")
10240                     (reg:SI PIC_REG)]
10241                    UNSPEC_CHKADD))]
10242   "TARGET_SH1"
10243   "#"
10244   "TARGET_SH1 && reload_completed"
10245   [(set (match_dup 0) (reg:SI PIC_REG))
10246    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))]
10247   ""
10248   [(set_attr "type" "arith")])
10250 (define_expand "sym_label2reg"
10251   [(set (match_operand:SI 0 "" "")
10252         (const:SI (unspec:SI [(match_operand:SI 1 "" "")
10253                               (const (plus:SI (match_operand:SI 2 "" "")
10254                                               (const_int 2)))]
10255                              UNSPEC_SYMOFF)))]
10256   "TARGET_SH1" "")
10258 (define_expand "symGOT_load"
10259   [(set (match_dup 2) (match_operand 1 "" ""))
10260    (set (match_dup 3) (plus (match_dup 2) (reg PIC_REG)))
10261    (set (match_operand 0 "" "") (mem (match_dup 3)))]
10262   ""
10264   rtx mem;
10266   operands[2] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
10267   operands[3] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
10269   if (TARGET_SHMEDIA)
10270     {
10271       rtx reg = operands[2];
10273       if (Pmode == DImode)
10274         {      
10275           if (flag_pic > 1)
10276             emit_insn (gen_movdi_const_32bit (reg, operands[1]));
10277           else
10278             emit_insn (gen_movdi_const_16bit (reg, operands[1]));
10279         }
10280       else
10281         {
10282           if (flag_pic > 1)
10283             emit_insn (gen_movsi_const (reg, operands[1]));
10284           else
10285             emit_insn (gen_movsi_const_16bit (reg, operands[1]));
10286         }
10287     }
10288   else
10289     emit_move_insn (operands[2], operands[1]);
10291   /* When stack protector inserts codes after the result is set to
10292      R0, @(rX, r12) will cause a spill failure for R0.  Use a unspec
10293      insn to avoid combining (set A (plus rX r12)) and (set op0 (mem A))
10294      when rX is a GOT address for the guard symbol.  Ugly but doesn't
10295      matter because this is a rare situation.  */
10296   if (!TARGET_SHMEDIA
10297       && flag_stack_protect
10298       && GET_CODE (operands[1]) == CONST
10299       && GET_CODE (XEXP (operands[1], 0)) == UNSPEC
10300       && GET_CODE (XVECEXP (XEXP (operands[1], 0), 0, 0)) == SYMBOL_REF
10301       && strcmp (XSTR (XVECEXP (XEXP (operands[1], 0), 0, 0), 0),
10302                  "__stack_chk_guard") == 0)
10303     emit_insn (gen_chk_guard_add (operands[3], operands[2]));
10304   else
10305     emit_move_insn (operands[3], gen_rtx_PLUS (Pmode, operands[2],
10306                                                gen_rtx_REG (Pmode, PIC_REG)));
10308   /* N.B. This is not constant for a GOTPLT relocation.  */
10309   mem = gen_rtx_MEM (Pmode, operands[3]);
10310   MEM_NOTRAP_P (mem) = 1;
10311   /* ??? Should we have a special alias set for the GOT?  */
10312   emit_move_insn (operands[0], mem);
10314   DONE;
10317 (define_expand "sym2GOT"
10318   [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOT))]
10319   ""
10320   "")
10322 (define_expand "symGOT2reg"
10323   [(match_operand 0 "" "") (match_operand 1 "" "")]
10324   ""
10326   rtx gotsym, insn;
10328   gotsym = gen_sym2GOT (operands[1]);
10329   PUT_MODE (gotsym, Pmode);
10330   insn = emit_insn (gen_symGOT_load (operands[0], gotsym));
10332   MEM_READONLY_P (SET_SRC (PATTERN (insn))) = 1;
10334   DONE;
10337 (define_expand "symGOTPLT2reg"
10338   [(match_operand 0 "" "") (match_operand 1 "" "")]
10339   ""
10341   rtx pltsym = gen_rtx_CONST (Pmode,
10342                               gen_rtx_UNSPEC (Pmode,
10343                                               gen_rtvec (1, operands[1]),
10344                                               UNSPEC_GOTPLT));
10345   emit_insn (gen_symGOT_load (operands[0], pltsym));
10346   DONE;
10349 (define_expand "sym2GOTOFF"
10350   [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTOFF))]
10351   ""
10352   "")
10354 (define_expand "symGOTOFF2reg"
10355   [(match_operand 0 "" "") (match_operand 1 "" "")]
10356   ""
10358   rtx gotoffsym, insn;
10359   rtx t = (!can_create_pseudo_p ()
10360            ? operands[0]
10361            : gen_reg_rtx (GET_MODE (operands[0])));
10363   gotoffsym = gen_sym2GOTOFF (operands[1]);
10364   PUT_MODE (gotoffsym, Pmode);
10365   emit_move_insn (t, gotoffsym);
10366   insn = emit_move_insn (operands[0],
10367                          gen_rtx_PLUS (Pmode, t,
10368                                        gen_rtx_REG (Pmode, PIC_REG)));
10370   set_unique_reg_note (insn, REG_EQUAL, operands[1]);
10372   DONE;
10375 (define_expand "symPLT_label2reg"
10376   [(set (match_operand:SI 0 "" "")
10377         (const:SI
10378          (unspec:SI
10379           [(const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PLT))
10380            (const:SI (plus:SI (match_operand:SI 2 "" "")
10381                               (const_int 2)))] UNSPEC_PCREL_SYMOFF)))
10382    ;; Even though the PIC register is not really used by the call
10383    ;; sequence in which this is expanded, the PLT code assumes the PIC
10384    ;; register is set, so we must not skip its initialization.  Since
10385    ;; we only use this expand as part of calling sequences, and never
10386    ;; to take the address of a function, this is the best point to
10387    ;; insert the (use).  Using the PLT to take the address of a
10388    ;; function would be wrong, not only because the PLT entry could
10389    ;; then be called from a function that doesn't initialize the PIC
10390    ;; register to the proper GOT, but also because pointers to the
10391    ;; same function might not compare equal, should they be set by
10392    ;; different shared libraries.
10393    (use (reg:SI PIC_REG))]
10394   "TARGET_SH1"
10395   "")
10397 (define_expand "sym2PIC"
10398   [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PIC))]
10399   ""
10400   "")
10402 ;; -------------------------------------------------------------------------
10403 ;; TLS code generation.
10405 ;; FIXME: The multi-insn asm blocks should be converted to use
10406 ;; define_insn_and_split.
10407 ;; See the thread [PATCH/RFA] SH TLS support on gcc-patches
10408 ;; <http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01898.html>
10409 ;; for details.
10411 (define_insn "tls_global_dynamic"
10412   [(set (match_operand:SI 0 "register_operand" "=&z")
10413         (call:SI (mem:SI (unspec:SI [(match_operand:SI 1 "" "")]
10414                                   UNSPEC_TLSGD))
10415               (const_int 0)))
10416    (use (reg:SI FPSCR_MODES_REG))
10417    (use (reg:SI PIC_REG))
10418    (clobber (reg:SI PR_REG))
10419    (clobber (scratch:SI))]
10420   "TARGET_SH1"
10422   return       "mov.l   1f,r4"                  "\n"
10423          "      mova    2f,r0"                  "\n"
10424          "      mov.l   2f,r1"                  "\n"
10425          "      add     r0,r1"                  "\n"
10426          "      jsr     @r1"                    "\n"
10427          "      add     r12,r4"                 "\n"
10428          "      bra     3f"                     "\n"
10429          "      nop"                            "\n"
10430          "      .align  2"                      "\n"
10431          "1:    .long   %a1@TLSGD"              "\n"
10432          "2:    .long   __tls_get_addr@PLT"     "\n"
10433          "3:";
10435   [(set_attr "type" "tls_load")
10436    (set_attr "length" "26")])
10438 (define_insn "tls_local_dynamic"
10439   [(set (match_operand:SI 0 "register_operand" "=&z")
10440         (call:SI (mem:SI (unspec:SI [(match_operand:SI 1 "" "")]
10441                                   UNSPEC_TLSLDM))
10442               (const_int 0)))
10443    (use (reg:SI FPSCR_MODES_REG))
10444    (use (reg:SI PIC_REG))
10445    (clobber (reg:SI PR_REG))
10446    (clobber (scratch:SI))]
10447   "TARGET_SH1"
10449   return       "mov.l   1f,r4"                  "\n"
10450          "      mova    2f,r0"                  "\n"
10451          "      mov.l   2f,r1"                  "\n"
10452          "      add     r0,r1"                  "\n"
10453          "      jsr     @r1"                    "\n"
10454          "      add     r12,r4"                 "\n"
10455          "      bra     3f"                     "\n"
10456          "      nop"                            "\n"
10457          "      .align  2"                      "\n"
10458          "1:    .long   %a1@TLSLDM"             "\n"
10459          "2:    .long   __tls_get_addr@PLT"     "\n"
10460          "3:";
10462   [(set_attr "type" "tls_load")
10463    (set_attr "length" "26")])
10465 (define_expand "sym2DTPOFF"
10466   [(const (unspec [(match_operand 0 "" "")] UNSPEC_DTPOFF))]
10467   ""
10468   "")
10470 (define_expand "symDTPOFF2reg"
10471   [(match_operand 0 "" "") (match_operand 1 "" "") (match_operand 2 "" "")]
10472   ""
10474   rtx dtpoffsym;
10475   rtx t = (!can_create_pseudo_p ()
10476            ? operands[0]
10477            : gen_reg_rtx (GET_MODE (operands[0])));
10479   dtpoffsym = gen_sym2DTPOFF (operands[1]);
10480   PUT_MODE (dtpoffsym, Pmode);
10481   emit_move_insn (t, dtpoffsym);
10482   emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, operands[2]));
10483   DONE;
10486 (define_expand "sym2GOTTPOFF"
10487   [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTTPOFF))]
10488   ""
10489   "")
10491 (define_insn "tls_initial_exec"
10492   [(set (match_operand:SI 0 "register_operand" "=&r")
10493         (unspec:SI [(match_operand:SI 1 "" "")]
10494                     UNSPEC_TLSIE))
10495    (use (reg:SI GBR_REG))
10496    (use (reg:SI PIC_REG))
10497    (clobber (reg:SI R0_REG))]
10498   ""
10500   return       "mov.l   1f,r0"          "\n"
10501          "      stc     gbr,%0"         "\n"
10502          "      mov.l   @(r0,r12),r0"   "\n"
10503          "      bra     2f"             "\n"
10504          "      add     r0,%0"          "\n"
10505          "      .align  2"              "\n"
10506          "1:    .long   %a1"            "\n"
10507          "2:";
10509   [(set_attr "type" "tls_load")
10510    (set_attr "length" "16")])
10512 (define_expand "sym2TPOFF"
10513   [(const (unspec [(match_operand 0 "" "")] UNSPEC_TPOFF))]
10514   ""
10515   "")
10517 (define_expand "symTPOFF2reg"
10518   [(match_operand 0 "" "") (match_operand 1 "" "")]
10519   ""
10521   rtx tpoffsym;
10523   tpoffsym = gen_sym2TPOFF (operands[1]);
10524   PUT_MODE (tpoffsym, Pmode);
10525   emit_move_insn (operands[0], tpoffsym);
10526   DONE;
10529 ;;------------------------------------------------------------------------------
10530 ;; Thread pointer getter and setter.
10532 ;; On SH the thread pointer is kept in the GBR.
10533 ;; These patterns are usually expanded from the respective built-in functions.
10534 (define_expand "get_thread_pointersi"
10535   [(set (match_operand:SI 0 "register_operand") (reg:SI GBR_REG))]
10536   "TARGET_SH1")
10538 ;; The store_gbr insn can also be used on !TARGET_SH1 for doing TLS accesses.
10539 (define_insn "store_gbr"
10540   [(set (match_operand:SI 0 "register_operand" "=r") (reg:SI GBR_REG))]
10541   ""
10542   "stc  gbr,%0"
10543   [(set_attr "type" "tls_load")])
10545 (define_expand "set_thread_pointersi"
10546   [(set (reg:SI GBR_REG)
10547         (unspec_volatile:SI [(match_operand:SI 0 "register_operand")]
10548          UNSPECV_GBR))]
10549   "TARGET_SH1")
10551 (define_insn "load_gbr"
10552   [(set (reg:SI GBR_REG)
10553         (unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")]
10554          UNSPECV_GBR))]
10555   "TARGET_SH1"
10556   "ldc  %0,gbr"
10557   [(set_attr "type" "move")])
10559 ;;------------------------------------------------------------------------------
10560 ;; Thread pointer relative memory loads and stores.
10562 ;; On SH there are GBR displacement address modes which can be utilized to
10563 ;; access memory behind the thread pointer.
10564 ;; Since we do not allow using GBR for general purpose memory accesses, these
10565 ;; GBR addressing modes are formed by the combine pass.
10566 ;; This could be done with fewer patterns than below by using a mem predicate
10567 ;; for the GBR mem, but then reload would try to reload addresses with a
10568 ;; zero displacement for some strange reason.
10570 (define_insn "*mov<mode>_gbr_load"
10571   [(set (match_operand:QIHISI 0 "register_operand" "=z")
10572         (mem:QIHISI (plus:SI (reg:SI GBR_REG)
10573                              (match_operand:QIHISI 1 "gbr_displacement"))))]
10574   "TARGET_SH1"
10575   "mov.<bwl>    @(%O1,gbr),%0"
10576   [(set_attr "type" "load")])
10578 (define_insn "*mov<mode>_gbr_load"
10579   [(set (match_operand:QIHISI 0 "register_operand" "=z")
10580         (mem:QIHISI (reg:SI GBR_REG)))]
10581   "TARGET_SH1"
10582   "mov.<bwl>    @(0,gbr),%0"
10583   [(set_attr "type" "load")])
10585 (define_insn "*mov<mode>_gbr_load"
10586   [(set (match_operand:SI 0 "register_operand" "=z")
10587         (sign_extend:SI
10588           (mem:QIHI (plus:SI (reg:SI GBR_REG)
10589                              (match_operand:QIHI 1 "gbr_displacement")))))]
10590   "TARGET_SH1"
10591   "mov.<bw>     @(%O1,gbr),%0"
10592   [(set_attr "type" "load")])
10594 (define_insn "*mov<mode>_gbr_load"
10595   [(set (match_operand:SI 0 "register_operand" "=z")
10596         (sign_extend:SI (mem:QIHI (reg:SI GBR_REG))))]
10597   "TARGET_SH1"
10598   "mov.<bw>     @(0,gbr),%0"
10599   [(set_attr "type" "load")])
10601 (define_insn "*mov<mode>_gbr_store"
10602   [(set (mem:QIHISI (plus:SI (reg:SI GBR_REG)
10603                              (match_operand:QIHISI 0 "gbr_displacement")))
10604         (match_operand:QIHISI 1 "register_operand" "z"))]
10605   "TARGET_SH1"
10606   "mov.<bwl>    %1,@(%O0,gbr)"
10607   [(set_attr "type" "store")])
10609 (define_insn "*mov<mode>_gbr_store"
10610   [(set (mem:QIHISI (reg:SI GBR_REG))
10611         (match_operand:QIHISI 0 "register_operand" "z"))]
10612   "TARGET_SH1"
10613   "mov.<bwl>    %0,@(0,gbr)"
10614   [(set_attr "type" "store")])
10616 ;; DImode memory accesses have to be split in two SImode accesses.
10617 ;; Split them before reload, so that it gets a better chance to figure out
10618 ;; how to deal with the R0 restriction for the individual SImode accesses.
10619 ;; Do not match this insn during or after reload because it can't be split
10620 ;; afterwards.
10621 (define_insn_and_split "*movdi_gbr_load"
10622   [(set (match_operand:DI 0 "register_operand")
10623         (match_operand:DI 1 "gbr_address_mem"))]
10624   "TARGET_SH1 && can_create_pseudo_p ()"
10625   "#"
10626   "&& 1"
10627   [(set (match_dup 3) (match_dup 5))
10628    (set (match_dup 4) (match_dup 6))]
10630   /* Swap low/high part load order on little endian, so that the result reg
10631      of the second load can be used better.  */
10632   int off = TARGET_LITTLE_ENDIAN ? 1 : 0;
10633   operands[3 + off] = gen_lowpart (SImode, operands[0]);
10634   operands[5 + off] = gen_lowpart (SImode, operands[1]);
10635   operands[4 - off] = gen_highpart (SImode, operands[0]);
10636   operands[6 - off] = gen_highpart (SImode, operands[1]);
10639 (define_insn_and_split "*movdi_gbr_store"
10640   [(set (match_operand:DI 0 "gbr_address_mem")
10641         (match_operand:DI 1 "register_operand"))]
10642   "TARGET_SH1 && can_create_pseudo_p ()"
10643   "#"
10644   "&& 1"
10645   [(set (match_dup 3) (match_dup 5))
10646    (set (match_dup 4) (match_dup 6))]
10648   /* Swap low/high part store order on big endian, so that stores of function
10649      call results can save a reg copy.  */
10650   int off = TARGET_LITTLE_ENDIAN ? 0 : 1;
10651   operands[3 + off] = gen_lowpart (SImode, operands[0]);
10652   operands[5 + off] = gen_lowpart (SImode, operands[1]);
10653   operands[4 - off] = gen_highpart (SImode, operands[0]);
10654   operands[6 - off] = gen_highpart (SImode, operands[1]);
10657 ;; Sometimes memory accesses do not get combined with the store_gbr insn,
10658 ;; in particular when the displacements are in the range of the regular move
10659 ;; insns.  Thus, in the first split pass after the combine pass we search
10660 ;; for missed opportunities and try to fix them up ourselves.
10661 ;; If an equivalent GBR address can be determined the load / store is split
10662 ;; into one of the GBR load / store patterns.
10663 ;; All of that must happen before reload (GBR address modes use R0 as the
10664 ;; other operand) and there's no point of doing it if the GBR is not
10665 ;; referenced in a function at all.
10666 (define_split
10667   [(set (match_operand:QIHISIDI 0 "register_operand")
10668         (match_operand:QIHISIDI 1 "memory_operand"))]
10669   "TARGET_SH1 && !reload_in_progress && !reload_completed
10670    && df_regs_ever_live_p (GBR_REG)"
10671   [(set (match_dup 0) (match_dup 1))]
10673   rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[1]);
10674   if (gbr_mem != NULL_RTX)
10675     operands[1] = replace_equiv_address (operands[1], gbr_mem);
10676   else
10677     FAIL;
10680 (define_split
10681   [(set (match_operand:SI 0 "register_operand")
10682         (sign_extend:SI (match_operand:QIHI 1 "memory_operand")))]
10683   "TARGET_SH1 && !reload_in_progress && !reload_completed
10684    && df_regs_ever_live_p (GBR_REG)"
10685   [(set (match_dup 0) (sign_extend:SI (match_dup 1)))]
10687   rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[1]);
10688   if (gbr_mem != NULL_RTX)
10689     operands[1] = replace_equiv_address (operands[1], gbr_mem);
10690   else
10691     FAIL;
10694 ;; On SH2A we've got movu.b and movu.w for doing zero-extending mem loads.
10695 ;; Split those so that a GBR load can be used.
10696 (define_split
10697   [(set (match_operand:SI 0 "register_operand")
10698         (zero_extend:SI (match_operand:QIHI 1 "memory_operand")))]
10699   "TARGET_SH2A && !reload_in_progress && !reload_completed
10700    && df_regs_ever_live_p (GBR_REG)"
10701   [(set (match_dup 2) (match_dup 1))
10702    (set (match_dup 0) (zero_extend:SI (match_dup 2)))]
10704   rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[1]);
10705   if (gbr_mem != NULL_RTX)
10706     {
10707       operands[2] = gen_reg_rtx (GET_MODE (operands[1]));
10708       operands[1] = replace_equiv_address (operands[1], gbr_mem);
10709     }
10710   else
10711     FAIL;
10714 (define_split
10715   [(set (match_operand:QIHISIDI 0 "memory_operand")
10716         (match_operand:QIHISIDI 1 "register_operand"))]
10717   "TARGET_SH1 && !reload_in_progress && !reload_completed
10718    && df_regs_ever_live_p (GBR_REG)"
10719   [(set (match_dup 0) (match_dup 1))]
10721   rtx gbr_mem = sh_find_equiv_gbr_addr (curr_insn, operands[0]);
10722   if (gbr_mem != NULL_RTX)
10723     operands[0] = replace_equiv_address (operands[0], gbr_mem);
10724   else
10725     FAIL;
10728 ;;------------------------------------------------------------------------------
10729 ;; case instruction for switch statements.
10731 ;; operand 0 is index
10732 ;; operand 1 is the minimum bound
10733 ;; operand 2 is the maximum bound - minimum bound + 1
10734 ;; operand 3 is CODE_LABEL for the table;
10735 ;; operand 4 is the CODE_LABEL to go to if index out of range.
10736 (define_expand "casesi"
10737   [(match_operand:SI 0 "arith_reg_operand" "")
10738    (match_operand:SI 1 "arith_reg_operand" "")
10739    (match_operand:SI 2 "arith_reg_operand" "")
10740    (match_operand 3 "" "") (match_operand 4 "" "")]
10741   ""
10743   rtx reg = gen_reg_rtx (SImode);
10744   rtx reg2 = gen_reg_rtx (SImode);
10745   if (TARGET_SHMEDIA)
10746     {
10747       rtx reg = gen_reg_rtx (DImode);
10748       rtx reg2 = gen_reg_rtx (DImode);
10749       rtx reg3 = gen_reg_rtx (Pmode);
10750       rtx reg4 = gen_reg_rtx (Pmode);
10751       rtx reg5 = gen_reg_rtx (Pmode);
10752       rtx load, test;
10754       operands[0] = convert_modes (DImode, SImode, operands[0], 0);
10755       operands[1] = convert_modes (DImode, SImode, operands[1], 0);
10756       operands[2] = convert_modes (DImode, SImode, operands[2], 1);
10758       test = gen_rtx_GT (VOIDmode, operands[1], operands[0]);
10759       emit_jump_insn (gen_cbranchdi4 (test, operands[1], operands[0],
10760                                       operands[4]));
10761       emit_move_insn (reg, gen_rtx_MINUS (DImode, operands[0], operands[1]));
10762       test = gen_rtx_GTU (VOIDmode, reg, operands[2]);
10763       emit_jump_insn (gen_cbranchdi4 (test, reg, operands[2], operands[4]));
10764       emit_insn (gen_casesi_shift_media (reg2, reg, operands[3]));
10765       emit_move_insn (reg3, gen_datalabel_ref (gen_rtx_LABEL_REF
10766                                                (Pmode, operands[3])));
10767       /* Messy: can we subreg to clean this up? */
10768       if (Pmode == DImode)
10769         load = gen_casesi_load_media (reg4, reg3, reg2, operands[3]);
10770       else
10771         load = gen_casesi_load_media (reg4,
10772                                       gen_rtx_SUBREG (DImode, reg3, 0),
10773                                       reg2, operands[3]);
10774       PUT_MODE (SET_SRC (load), Pmode);
10775       emit_insn (load);
10776       /* ??? The following add could be eliminated if we used ptrel.  */
10777       emit_move_insn (reg5, gen_rtx_PLUS (Pmode, reg3, reg4));
10778       emit_jump_insn (gen_casesi_jump_media (reg5, operands[3]));
10779       emit_barrier ();
10780       DONE;
10781     }
10782   operands[1] = copy_to_mode_reg (SImode, operands[1]);
10783   operands[2] = copy_to_mode_reg (SImode, operands[2]);
10784   /* If optimizing, casesi_worker depends on the mode of the instruction
10785      before label it 'uses' - operands[3].  */
10786   emit_insn (gen_casesi_0 (operands[0], operands[1], operands[2], operands[4],
10787                            reg));
10788   emit_insn (gen_casesi_worker_0 (reg2, reg, operands[3]));
10789   if (TARGET_SH2)
10790     emit_jump_insn (gen_casesi_jump_2 (reg2, gen_label_rtx (), operands[3]));
10791   else
10792     emit_jump_insn (gen_casesi_jump_1 (reg2, operands[3]));
10793   /* For SH2 and newer, the ADDR_DIFF_VEC is not actually relative to
10794      operands[3], but to lab.  We will fix this up in
10795      machine_dependent_reorg.  */
10796   emit_barrier ();
10797   DONE;
10800 (define_expand "casesi_0"
10801   [(set (match_operand:SI 4 "" "") (match_operand:SI 0 "arith_reg_operand" ""))
10802    (set (match_dup 4) (minus:SI (match_dup 4)
10803                                 (match_operand:SI 1 "arith_operand" "")))
10804    (set (reg:SI T_REG)
10805         (gtu:SI (match_dup 4)
10806                 (match_operand:SI 2 "arith_reg_operand" "")))
10807    (set (pc)
10808         (if_then_else (ne (reg:SI T_REG)
10809                           (const_int 0))
10810                       (label_ref (match_operand 3 "" ""))
10811                       (pc)))]
10812   "TARGET_SH1"
10813   "")
10815 ;; ??? reload might clobber r0 if we use it explicitly in the RTL before
10816 ;; reload; using a R0_REGS pseudo reg is likely to give poor code.
10817 ;; So we keep the use of r0 hidden in a R0_REGS clobber until after reload.
10818 (define_insn "casesi_worker_0"
10819   [(set (match_operand:SI 0 "register_operand" "=r,r")
10820         (unspec:SI [(match_operand:SI 1 "register_operand" "0,r")
10821                  (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
10822    (clobber (match_scratch:SI 3 "=X,1"))
10823    (clobber (match_scratch:SI 4 "=&z,z"))]
10824   "TARGET_SH1"
10825   "#")
10827 (define_split
10828   [(set (match_operand:SI 0 "register_operand" "")
10829         (unspec:SI [(match_operand:SI 1 "register_operand" "")
10830                     (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
10831    (clobber (match_scratch:SI 3 ""))
10832    (clobber (match_scratch:SI 4 ""))]
10833   "TARGET_SH1 && ! TARGET_SH2 && reload_completed"
10834   [(set (reg:SI R0_REG) (unspec:SI [(label_ref (match_dup 2))] UNSPEC_MOVA))
10835    (parallel [(set (match_dup 0)
10836               (unspec:SI [(reg:SI R0_REG) (match_dup 1)
10837                           (label_ref (match_dup 2))] UNSPEC_CASESI))
10838               (clobber (match_dup 3))])
10839    (set (match_dup 0) (plus:SI (match_dup 0) (reg:SI R0_REG)))]
10841   if (GET_CODE (operands[2]) == CODE_LABEL)
10842     LABEL_NUSES (operands[2])++;
10845 (define_split
10846   [(set (match_operand:SI 0 "register_operand" "")
10847         (unspec:SI [(match_operand:SI 1 "register_operand" "")
10848                     (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
10849    (clobber (match_scratch:SI 3 ""))
10850    (clobber (match_scratch:SI 4 ""))]
10851   "TARGET_SH2 && reload_completed"
10852   [(set (reg:SI R0_REG) (unspec:SI [(label_ref (match_dup 2))] UNSPEC_MOVA))
10853    (parallel [(set (match_dup 0)
10854               (unspec:SI [(reg:SI R0_REG) (match_dup 1)
10855                           (label_ref (match_dup 2))] UNSPEC_CASESI))
10856               (clobber (match_dup 3))])]
10858   if (GET_CODE (operands[2]) == CODE_LABEL)
10859     LABEL_NUSES (operands[2])++;
10862 (define_insn "casesi_worker_1"
10863   [(set (match_operand:SI 0 "register_operand" "=r,r")
10864         (unspec:SI [(reg:SI R0_REG)
10865                     (match_operand:SI 1 "register_operand" "0,r")
10866                     (label_ref (match_operand 2 "" ""))] UNSPEC_CASESI))
10867    (clobber (match_scratch:SI 3 "=X,1"))]
10868   "TARGET_SH1"
10870   rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
10872   gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
10874   switch (GET_MODE (diff_vec))
10875     {
10876     case SImode:
10877       return   "shll2   %1"     "\n"
10878              "  mov.l   @(r0,%1),%0";
10879     case HImode:
10880       return   "add     %1,%1"  "\n"
10881              "  mov.w   @(r0,%1),%0";
10882     case QImode:
10883       if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned)
10884         return         "mov.b   @(r0,%1),%0"    "\n"
10885                "        extu.b  %0,%0";
10886       else
10887         return "mov.b   @(r0,%1),%0";
10889     default:
10890       gcc_unreachable ();
10891     }
10893   [(set_attr "length" "4")])
10895 (define_insn "casesi_worker_2"
10896   [(set (match_operand:SI 0 "register_operand" "=r,r")
10897         (unspec:SI [(reg:SI R0_REG)
10898                     (match_operand:SI 1 "register_operand" "0,r")
10899                     (label_ref (match_operand 2 "" ""))
10900                     (label_ref (match_operand 3 "" ""))] UNSPEC_CASESI))
10901    (clobber (match_operand:SI 4 "" "=X,1"))]
10902   "TARGET_SH2 && reload_completed && flag_pic"
10904   rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
10905   gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
10907   switch (GET_MODE (diff_vec))
10908     {
10909     case SImode:
10910       return   "shll2   %1"             "\n"
10911              "  add     r0,%1"          "\n"
10912              "  mova    %O3,r0"         "\n"
10913              "  mov.l   @(r0,%1),%0";
10914     case HImode:
10915       return   "add     %1,%1"          "\n"
10916              "  add     r0,%1"          "\n"
10917              "  mova    %O3,r0"         "\n"
10918              "  mov.w   @(r0,%1),%0";
10919     case QImode:
10920       if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned)
10921         return         "add     r0,%1"          "\n"
10922                 "       mova    %O3,r0"         "\n"
10923                 "       mov.b   @(r0,%1),%0"    "\n"
10924                 "       extu.b  %0,%0";
10925       else
10926         return         "add     r0,%1"          "\n"
10927                 "       mova    %O3,r0"         "\n"
10928                 "       mov.b   @(r0,%1),%0";
10929     default:
10930       gcc_unreachable ();
10931     }
10933   [(set_attr "length" "8")])
10935 (define_insn "casesi_shift_media"
10936   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
10937         (ashift:DI (match_operand:DI 1 "arith_reg_operand" "r")
10938                    (unspec:DI [(label_ref:DI (match_operand 2 "" ""))]
10939                     UNSPEC_CASESI)))]
10940   "TARGET_SHMEDIA"
10942   rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
10944   gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
10946   switch (GET_MODE (diff_vec))
10947     {
10948     case SImode:
10949       return "shlli     %1, 2, %0";
10950     case HImode:
10951       return "shlli     %1, 1, %0";
10952     case QImode:
10953       if (rtx_equal_p (operands[0], operands[1]))
10954         return "";
10955       return "add       %1, r63, %0";
10956     default:
10957       gcc_unreachable ();
10958     }
10960   [(set_attr "type" "arith_media")])
10962 (define_insn "casesi_load_media"
10963   [(set (match_operand 0 "any_arith_reg_dest" "=r")
10964         (mem (unspec [(match_operand:DI 1 "arith_reg_operand" "r")
10965                       (match_operand:DI 2 "arith_reg_operand" "r")
10966                       (label_ref:DI (match_operand 3 "" ""))] UNSPEC_CASESI)))]
10967   "TARGET_SHMEDIA"
10969   rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[3])));
10971   gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
10973   switch (GET_MODE (diff_vec))
10974     {
10975     case SImode:
10976       return "ldx.l     %1, %2, %0";
10977     case HImode:
10978 #if 0
10979       if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned)
10980         return "ldx.uw  %1, %2, %0";
10981 #endif
10982       return "ldx.w     %1, %2, %0";
10983     case QImode:
10984       if (ADDR_DIFF_VEC_FLAGS (diff_vec).offset_unsigned)
10985         return "ldx.ub  %1, %2, %0";
10986       return "ldx.b     %1, %2, %0";
10987     default:
10988       gcc_unreachable ();
10989     }
10991   [(set_attr "type" "load_media")])
10993 (define_expand "simple_return"
10994   [(simple_return)]
10995  "sh_can_use_simple_return_p ()")
10997 (define_expand "return"
10998   [(return)]
10999  "reload_completed && epilogue_completed"
11001   if (TARGET_SHMEDIA)
11002     {
11003       emit_jump_insn (gen_return_media ());
11004       DONE;
11005     }
11007   if (TARGET_SHCOMPACT
11008       && (crtl->args.info.call_cookie & CALL_COOKIE_RET_TRAMP (1)))
11009     {
11010       emit_jump_insn (gen_shcompact_return_tramp ());
11011       DONE;
11012     }
11015 (define_insn "*<code>_i"
11016   [(any_return)]
11017   "TARGET_SH1 && ! (TARGET_SHCOMPACT
11018                     && (crtl->args.info.call_cookie
11019                         & CALL_COOKIE_RET_TRAMP (1)))
11020    && reload_completed
11021    && ! sh_cfun_trap_exit_p ()"
11023   if (TARGET_SH2A && (dbr_sequence_length () == 0)
11024       && !current_function_interrupt)
11025     return "rts/n";
11026   else
11027     return "%@  %#";
11029   [(set_attr "type" "return")
11030    (set_attr "needs_delay_slot" "yes")])
11032 ;; trapa has no delay slot.
11033 (define_insn "*return_trapa"
11034   [(return)]
11035   "TARGET_SH1 && !TARGET_SHCOMPACT
11036    && reload_completed"
11037   "%@"
11038   [(set_attr "type" "return")])
11040 (define_expand "shcompact_return_tramp"
11041   [(return)]
11042   "TARGET_SHCOMPACT
11043    && (crtl->args.info.call_cookie & CALL_COOKIE_RET_TRAMP (1))"
11045   rtx reg = gen_rtx_REG (Pmode, R0_REG);
11047   function_symbol (reg, "__GCC_shcompact_return_trampoline", SFUNC_STATIC);
11048   emit_jump_insn (gen_shcompact_return_tramp_i ());
11049   DONE;
11052 (define_insn "shcompact_return_tramp_i"
11053   [(parallel [(return) (use (reg:SI R0_REG))])]
11054   "TARGET_SHCOMPACT
11055    && (crtl->args.info.call_cookie & CALL_COOKIE_RET_TRAMP (1))"
11056   "jmp  @r0%#"
11057   [(set_attr "type" "jump_ind")
11058    (set_attr "needs_delay_slot" "yes")])
11060 (define_insn "return_media_i"
11061   [(parallel [(return) (use (match_operand 0 "target_reg_operand" "k"))])]
11062   "TARGET_SHMEDIA && reload_completed"
11063   "blink        %0, r63"
11064   [(set_attr "type" "jump_media")])
11066 (define_insn "return_media_rte"
11067   [(return)]
11068   "TARGET_SHMEDIA && reload_completed && current_function_interrupt"
11069   "rte"
11070   [(set_attr "type" "jump_media")])
11072 (define_expand "return_media"
11073   [(return)]
11074   "TARGET_SHMEDIA && reload_completed"
11076   int tr_regno = sh_media_register_for_return ();
11077   rtx tr;
11079   if (current_function_interrupt)
11080     {
11081       emit_jump_insn (gen_return_media_rte ());
11082       DONE;
11083     }
11084   if (tr_regno < 0)
11085     {
11086       rtx r18 = gen_rtx_REG (Pmode, PR_MEDIA_REG);
11088       gcc_assert (call_really_used_regs[TR0_REG] && !fixed_regs[TR0_REG]);
11089       tr_regno = TR0_REG;
11090       tr = gen_rtx_REG (Pmode, tr_regno);
11091       emit_move_insn (tr, r18);
11092     }
11093   else
11094     tr = gen_rtx_REG (Pmode, tr_regno);
11096   emit_jump_insn (gen_return_media_i (tr));
11097   DONE;
11100 (define_insn "shcompact_preserve_incoming_args"
11101   [(set (match_operand:SI 0 "register_operand" "+r")
11102         (unspec:SI [(match_dup 0)] UNSPEC_COMPACT_ARGS))]
11103   "TARGET_SHCOMPACT"
11104   ""
11105   [(set_attr "length" "0")])
11107 (define_insn "shcompact_incoming_args"
11108   [(set (reg:SI R2_REG) (unspec:SI [(reg:SI R2_REG)] UNSPEC_COMPACT_ARGS))
11109    (set (reg:SI R3_REG) (unspec:SI [(reg:SI R3_REG)] UNSPEC_COMPACT_ARGS))
11110    (set (reg:SI R4_REG) (unspec:SI [(reg:SI R4_REG)] UNSPEC_COMPACT_ARGS))
11111    (set (reg:SI R5_REG) (unspec:SI [(reg:SI R5_REG)] UNSPEC_COMPACT_ARGS))
11112    (set (reg:SI R6_REG) (unspec:SI [(reg:SI R6_REG)] UNSPEC_COMPACT_ARGS))
11113    (set (reg:SI R7_REG) (unspec:SI [(reg:SI R7_REG)] UNSPEC_COMPACT_ARGS))
11114    (set (reg:SI R8_REG) (unspec:SI [(reg:SI R8_REG)] UNSPEC_COMPACT_ARGS))
11115    (set (reg:SI R9_REG) (unspec:SI [(reg:SI R9_REG)] UNSPEC_COMPACT_ARGS))
11116    (set (mem:BLK (reg:SI MACL_REG))
11117         (unspec:BLK [(reg:SI MACH_REG)] UNSPEC_COMPACT_ARGS))
11118    (use (reg:SI R0_REG))
11119    (clobber (reg:SI R0_REG))
11120    (clobber (reg:SI MACL_REG))
11121    (clobber (reg:SI MACH_REG))
11122    (clobber (reg:SI PR_REG))]
11123   "TARGET_SHCOMPACT"
11124   "jsr  @r0%#"
11125   [(set_attr "needs_delay_slot" "yes")])
11127 (define_insn "shmedia_save_restore_regs_compact"
11128   [(set (reg:SI SP_REG)
11129         (plus:SI (reg:SI SP_REG)
11130                  (match_operand:SI 0 "immediate_operand" "i")))
11131    (use (reg:SI R0_REG))
11132    (clobber (reg:SI PR_REG))]
11133   "TARGET_SHCOMPACT
11134    && (INTVAL (operands[0]) == SHMEDIA_REGS_STACK_ADJUST ()
11135        || INTVAL (operands[0]) == - SHMEDIA_REGS_STACK_ADJUST ())"
11136   "jsr @r0%#"
11137   [(set_attr "needs_delay_slot" "yes")])
11139 (define_expand "prologue"
11140   [(const_int 0)]
11141   ""
11143   sh_expand_prologue ();
11144   DONE;
11147 (define_expand "epilogue"
11148   [(return)]
11149   ""
11151   sh_expand_epilogue (false);
11152   if (TARGET_SHMEDIA
11153       || (TARGET_SHCOMPACT
11154           && (crtl->args.info.call_cookie & CALL_COOKIE_RET_TRAMP (1))))
11155     {
11156       emit_jump_insn (gen_return ());
11157       DONE;
11158     }
11161 (define_expand "eh_return"
11162   [(use (match_operand 0 "register_operand" ""))]
11163   ""
11165   rtx ra = operands[0];
11167   if (TARGET_SHMEDIA64)
11168     emit_insn (gen_eh_set_ra_di (ra));
11169   else
11170     emit_insn (gen_eh_set_ra_si (ra));
11172   DONE;
11175 ;; Clobber the return address on the stack.  We can't expand this
11176 ;; until we know where it will be put in the stack frame.
11178 (define_insn "eh_set_ra_si"
11179   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
11180       UNSPECV_EH_RETURN)
11181    (clobber (match_scratch:SI 1 "=&r"))]
11182   "! TARGET_SHMEDIA64"
11183   "#")
11185 (define_insn "eh_set_ra_di"
11186   [(unspec_volatile [(match_operand:DI 0 "register_operand" "r")]
11187       UNSPECV_EH_RETURN)
11188    (clobber (match_scratch:DI 1 "=&r"))]
11189   "TARGET_SHMEDIA64"
11190   "#")
11192 (define_split
11193   [(unspec_volatile [(match_operand 0 "register_operand" "")]
11194       UNSPECV_EH_RETURN)
11195    (clobber (match_scratch 1 ""))]
11196   "reload_completed"
11197   [(const_int 0)]
11199   sh_set_return_address (operands[0], operands[1]);
11200   DONE;
11203 (define_insn "blockage"
11204   [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
11205   ""
11206   ""
11207   [(set_attr "length" "0")])
11209 ;; Define movml instructions for SH2A target.  Currently they are
11210 ;; used to push and pop all banked registers only.
11212 (define_insn "movml_push_banked"
11213   [(set (match_operand:SI 0 "register_operand" "=r")
11214           (plus (match_dup 0) (const_int -32)))
11215    (set (mem:SI (plus:SI (match_dup 0) (const_int 28))) (reg:SI R7_REG))
11216    (set (mem:SI (plus:SI (match_dup 0) (const_int 24))) (reg:SI R6_REG))
11217    (set (mem:SI (plus:SI (match_dup 0) (const_int 20))) (reg:SI R5_REG))
11218    (set (mem:SI (plus:SI (match_dup 0) (const_int 16))) (reg:SI R4_REG))
11219    (set (mem:SI (plus:SI (match_dup 0) (const_int 12))) (reg:SI R3_REG))
11220    (set (mem:SI (plus:SI (match_dup 0) (const_int 8))) (reg:SI R2_REG))
11221    (set (mem:SI (plus:SI (match_dup 0) (const_int 4))) (reg:SI R1_REG))
11222    (set (mem:SI (plus:SI (match_dup 0) (const_int 0))) (reg:SI R0_REG))]
11223   "TARGET_SH2A && REGNO (operands[0]) == 15"
11224   "movml.l      r7,@-r15"
11225   [(set_attr "in_delay_slot" "no")])
11227 (define_insn "movml_pop_banked"
11228   [(set (match_operand:SI 0 "register_operand" "=r")
11229           (plus (match_dup 0) (const_int 32)))
11230    (set (reg:SI R0_REG) (mem:SI (plus:SI (match_dup 0) (const_int -32))))
11231    (set (reg:SI R1_REG) (mem:SI (plus:SI (match_dup 0) (const_int -28))))
11232    (set (reg:SI R2_REG) (mem:SI (plus:SI (match_dup 0) (const_int -24))))
11233    (set (reg:SI R3_REG) (mem:SI (plus:SI (match_dup 0) (const_int -20))))
11234    (set (reg:SI R4_REG) (mem:SI (plus:SI (match_dup 0) (const_int -16))))
11235    (set (reg:SI R5_REG) (mem:SI (plus:SI (match_dup 0) (const_int -12))))
11236    (set (reg:SI R6_REG) (mem:SI (plus:SI (match_dup 0) (const_int -8))))
11237    (set (reg:SI R7_REG) (mem:SI (plus:SI (match_dup 0) (const_int -4))))]
11238   "TARGET_SH2A && REGNO (operands[0]) == 15"
11239   "movml.l      @r15+,r7"
11240   [(set_attr "in_delay_slot" "no")])
11242 ;; ------------------------------------------------------------------------
11243 ;; Scc instructions
11244 ;; ------------------------------------------------------------------------
11246 (define_insn "movt"
11247   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
11248         (match_operand:SI 1 "t_reg_operand"))]
11249   "TARGET_SH1"
11250   "movt %0"
11251   [(set_attr "type" "arith")])
11253 (define_insn "movrt"
11254   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
11255         (xor:SI (match_operand:SI 1 "t_reg_operand" "") (const_int 1)))]
11256   "TARGET_SH2A"
11257   "movrt        %0"
11258   [(set_attr "type" "arith")])
11260 (define_expand "cstore4_media"
11261   [(set (match_operand:SI 0 "register_operand" "=r")
11262         (match_operator:SI 1 "sh_float_comparison_operator"
11263          [(match_operand 2 "logical_operand" "")
11264           (match_operand 3 "cmp_operand" "")]))]
11265   "TARGET_SHMEDIA"
11267   machine_mode mode = GET_MODE (operands[2]);
11268   enum rtx_code code = GET_CODE (operands[1]);
11269   bool invert, swap;
11270   if (mode == VOIDmode)
11271     mode = GET_MODE (operands[3]);
11272   if (operands[2] == const0_rtx)
11273     {
11274       if (code == EQ || code == NE)
11275         operands[2] = operands[3], operands[3] = const0_rtx;
11276     }
11277   else
11278     operands[2] = force_reg (mode, operands[2]);
11279   if (operands[3] != const0_rtx)
11280     operands[3] = force_reg (mode, operands[3]);
11282   switch (code)
11283     {
11284     case GEU:
11285     case GE:
11286       swap = invert = !FLOAT_MODE_P (mode);
11287       break;
11289     case LEU:
11290     case LE:
11291       swap = FLOAT_MODE_P (mode), invert = !swap;
11292       break;
11294     case LTU:
11295     case LT:
11296       swap = true, invert = false;
11297       break;
11299     case GTU:
11300     case GT:
11301     case EQ:
11302     case UNORDERED:
11303       swap = invert = false;
11304       break;
11306     case NE:
11307       swap = invert = true;
11308       break;
11310     default:
11311       gcc_unreachable ();
11312   }
11314   if (swap)
11315     {
11316       std::swap (operands[2], operands[3]);
11317       code = swap_condition (code);
11318     }
11320   if (invert)
11321     {
11322       rtx tem = can_create_pseudo_p () ? gen_reg_rtx (SImode) : operands[0];
11323       code = reverse_condition (code);
11324       operands[1] = gen_rtx_fmt_ee (code, VOIDmode, operands[2], operands[3]);
11325       emit_insn (gen_cstore4_media (tem, operands[1],
11326                                     operands[2], operands[3]));
11327       code = EQ;
11328       operands[2] = tem;
11329       operands[3] = const0_rtx;
11330     }
11332   operands[1] = gen_rtx_fmt_ee (code, VOIDmode, operands[2], operands[3]);
11335 (define_expand "cstoresi4"
11336   [(set (match_operand:SI 0 "register_operand" "=r")
11337         (match_operator:SI 1 "comparison_operator"
11338          [(match_operand:SI 2 "cmpsi_operand" "")
11339           (match_operand:SI 3 "arith_operand" "")]))]
11340   "TARGET_SH1 || TARGET_SHMEDIA"
11342   if (TARGET_SHMEDIA)
11343     {
11344       emit_insn (gen_cstore4_media (operands[0], operands[1],
11345                                     operands[2], operands[3]));
11346       DONE;
11347     }
11349    if (sh_expand_t_scc (operands))
11350      DONE;
11352    if (! currently_expanding_to_rtl)
11353      FAIL;
11354    
11355    sh_emit_compare_and_set (operands, SImode);
11356    DONE;
11359 (define_expand "cstoredi4"
11360   [(set (match_operand:SI 0 "register_operand" "=r")
11361         (match_operator:SI 1 "comparison_operator"
11362          [(match_operand:DI 2 "arith_operand" "")
11363           (match_operand:DI 3 "arith_operand" "")]))]
11364   "TARGET_SH2 || TARGET_SHMEDIA"
11366   if (TARGET_SHMEDIA)
11367     {
11368       emit_insn (gen_cstore4_media (operands[0], operands[1],
11369                                     operands[2], operands[3]));
11370       DONE;
11371     }
11373    if (sh_expand_t_scc (operands))
11374      DONE;
11376    if (! currently_expanding_to_rtl)
11377      FAIL;
11378    
11379    sh_emit_compare_and_set (operands, DImode);
11380    DONE;
11383 ;; Move the complement of the T reg to a reg.
11384 ;; On SH2A the movrt insn can be used.
11385 ;; On anything else than SH2A this has to be done with multiple instructions.
11386 ;; One obvious way would be:
11387 ;;      cmp/eq  ...
11388 ;;      movt    r0
11389 ;;      xor     #1,r0
11391 ;; However, this puts pressure on r0 in most cases and thus the following is
11392 ;; more appealing:
11393 ;;      cmp/eq  ...
11394 ;;      mov     #-1,temp
11395 ;;      negc    temp,dest
11397 ;; If the constant -1 can be CSE-ed or lifted out of a loop it effectively
11398 ;; becomes a one instruction operation.  Moreover, care must be taken that
11399 ;; the insn can still be combined with inverted compare and branch code
11400 ;; around it.  On the other hand, if a function returns the complement of
11401 ;; a previous comparison result in the T bit, the xor #1,r0 approach might
11402 ;; lead to better code.
11403 (define_expand "movnegt"
11404   [(set (match_operand:SI 0 "arith_reg_dest" "")
11405         (xor:SI (match_operand:SI 1 "t_reg_operand" "") (const_int 1)))]
11406   "TARGET_SH1"
11408   if (TARGET_SH2A)
11409     emit_insn (gen_movrt (operands[0], operands[1]));
11410   else
11411     {
11412       rtx val = force_reg (SImode, gen_int_mode (-1, SImode));
11413       emit_insn (gen_movrt_negc (operands[0], operands[1], val));
11414     }
11415   DONE;
11418 (define_insn_and_split "movrt_negc"
11419   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
11420         (xor:SI (match_operand:SI 1 "t_reg_operand") (const_int 1)))
11421    (set (reg:SI T_REG) (const_int 1))
11422    (use (match_operand:SI 2 "arith_reg_operand" "r"))]
11423   "TARGET_SH1"
11424   "negc %2,%0"
11425   "&& 1"
11426   [(const_int 0)]
11428   if (sh_split_movrt_negc_to_movt_xor (curr_insn, operands))
11429     DONE;
11430   else
11431     FAIL;
11433   [(set_attr "type" "arith")])
11435 ;; The -1 constant will not be CSE-ed for the *movrt_negc pattern, but the
11436 ;; pattern can be used by the combine pass.  Using a scratch reg for the
11437 ;; -1 constant results in slightly better register allocations compared to
11438 ;; generating a pseudo reg before reload.
11439 (define_insn_and_split "*movrt_negc"
11440   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
11441         (xor:SI (match_operand:SI 1 "t_reg_operand") (const_int 1)))
11442    (clobber (match_scratch:SI 2 "=r"))
11443    (clobber (reg:SI T_REG))]
11444   "TARGET_SH1 && ! TARGET_SH2A"
11445   "#"
11446   "&& 1"
11447   [(const_int 0)]
11449   if (sh_split_movrt_negc_to_movt_xor (curr_insn, operands))
11450     DONE;
11451   else if (reload_completed)
11452     {
11453       emit_move_insn (operands[2], gen_int_mode (-1, SImode));
11454       emit_insn (gen_movrt_negc (operands[0], operands[1], operands[2]));
11455       DONE;
11456     }
11457   else
11458     FAIL;
11461 ;; Store the negated T bit in a reg using r0 and xor.  This one doesn't
11462 ;; clobber the T bit, which is useful when storing the T bit and the
11463 ;; negated T bit in parallel.  On SH2A the movrt insn can be used for that.
11464 ;; Usually we don't want this insn to be matched, except for cases where the
11465 ;; T bit clobber is really not appreciated.  Hence the extra use on T_REG.
11466 (define_insn_and_split "movrt_xor"
11467   [(set (match_operand:SI 0 "arith_reg_dest" "=z")
11468         (xor:SI (match_operand:SI 1 "t_reg_operand") (const_int 1)))
11469    (use (reg:SI T_REG))]
11470   "TARGET_SH1"
11471   "#"
11472   "&& reload_completed"
11473   [(set (match_dup 0) (reg:SI T_REG))
11474    (set (match_dup 0) (xor:SI (match_dup 0) (const_int 1)))])
11476 ;; Use negc to store the T bit in a MSB of a reg in the following way:
11477 ;;      T = 1: 0x80000000 -> reg
11478 ;;      T = 0: 0x7FFFFFFF -> reg
11479 ;; This works because 0 - 0x80000000 = 0x80000000.
11481 ;; This insn must not match again after it has been split into the constant
11482 ;; load and negc.  This is accomplished by the special negc insn that
11483 ;; has a use on the operand.
11484 (define_insn_and_split "*mov_t_msb_neg"
11485   [(set (match_operand:SI 0 "arith_reg_dest")
11486         (minus:SI (const_int -2147483648)  ;; 0x80000000
11487                   (match_operand 1 "t_reg_operand")))
11488    (clobber (reg:SI T_REG))]
11489   "TARGET_SH1"
11490   "#"
11491   "&& can_create_pseudo_p ()"
11492   [(set (match_dup 2) (const_int -2147483648))
11493    (parallel [(set (match_dup 0) (minus:SI (neg:SI (match_dup 2))
11494                                            (reg:SI T_REG)))
11495               (clobber (reg:SI T_REG))
11496               (use (match_dup 2))])]
11498   operands[2] = gen_reg_rtx (SImode);
11501 (define_insn "*mov_t_msb_neg_negc"
11502   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
11503         (minus:SI (neg:SI (match_operand:SI 1 "arith_reg_operand" "r"))
11504                   (match_operand:SI 2 "t_reg_operand")))
11505    (clobber (reg:SI T_REG))
11506    (use (match_dup 1))]
11507   "TARGET_SH1"
11508   "negc %1,%0"
11509   [(set_attr "type" "arith")])
11511 ;; These are essentially the same as above, but with the inverted T bit.
11512 ;; Combine recognizes the split patterns, but does not take them sometimes
11513 ;; if the T_REG clobber is specified.  Instead it tries to split out the
11514 ;; T bit negation.  Since these splits are supposed to be taken only by
11515 ;; combine, it will see the T_REG clobber of the *mov_t_msb_neg insn, so this
11516 ;; should be fine.
11517 (define_split
11518   [(set (match_operand:SI 0 "arith_reg_dest")
11519         (plus:SI (match_operand 1 "negt_reg_operand")
11520                  (const_int 2147483647)))]  ;; 0x7fffffff
11521   "TARGET_SH1 && can_create_pseudo_p ()"
11522   [(parallel [(set (match_dup 0)
11523                    (minus:SI (const_int -2147483648) (reg:SI T_REG)))
11524               (clobber (reg:SI T_REG))])])
11526 (define_split
11527   [(set (match_operand:SI 0 "arith_reg_dest")
11528         (if_then_else:SI (match_operand 1 "t_reg_operand")
11529                          (const_int 2147483647)  ;; 0x7fffffff
11530                          (const_int -2147483648)))]  ;; 0x80000000
11531   "TARGET_SH1 && can_create_pseudo_p ()"
11532   [(parallel [(set (match_dup 0)
11533                    (minus:SI (const_int -2147483648) (reg:SI T_REG)))
11534               (clobber (reg:SI T_REG))])])
11536 ;; The *negnegt pattern helps the combine pass to figure out how to fold 
11537 ;; an explicit double T bit negation.
11538 (define_insn_and_split "*negnegt"
11539   [(set (reg:SI T_REG)
11540         (eq:SI (match_operand 0 "negt_reg_operand" "") (const_int 0)))]
11541   "TARGET_SH1"
11542   "#"
11543   ""
11544   [(const_int 0)])
11546 ;; Store T bit as all zeros or ones in a reg.
11547 (define_insn "mov_neg_si_t"
11548   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
11549         (neg:SI (match_operand 1 "t_reg_operand" "")))]
11550   "TARGET_SH1"
11551   "subc %0,%0"
11552   [(set_attr "type" "arith")])
11554 ;; Store negated T bit as all zeros or ones in a reg.
11555 ;; Use the following sequence:
11556 ;;      subc    Rn,Rn   ! Rn = Rn - Rn - T; T = T
11557 ;;      not     Rn,Rn   ! Rn = 0 - Rn
11558 (define_split
11559   [(set (match_operand:SI 0 "arith_reg_dest" "")
11560         (neg:SI (match_operand 1 "negt_reg_operand" "")))]
11561   "TARGET_SH1"
11562   [(set (match_dup 0) (neg:SI (reg:SI T_REG)))
11563    (set (match_dup 0) (not:SI (match_dup 0)))])
11565 ;; The *movtt pattern eliminates redundant T bit to T bit moves / tests.
11566 (define_insn_and_split "*movtt"
11567   [(set (reg:SI T_REG)
11568         (eq:SI (match_operand 0 "t_reg_operand" "") (const_int 1)))]
11569   "TARGET_SH1"
11570   "#"
11571   ""
11572   [(const_int 0)])
11574 ;; Invert the T bit.
11575 ;; On SH2A we can use the nott insn.  On anything else this must be done with
11576 ;; multiple insns like:
11577 ;;      movt    Rn
11578 ;;      tst     Rn,Rn
11579 ;; This requires an additional pseudo.  The SH specific sh_treg_combine RTL
11580 ;; pass will look for this insn.  Disallow using it if pseudos can't be
11581 ;; created.
11582 (define_insn_and_split "nott"
11583   [(set (reg:SI T_REG)
11584         (xor:SI (match_operand:SI 0 "t_reg_operand") (const_int 1)))]
11585   "TARGET_SH2A || (TARGET_SH1 && can_create_pseudo_p ())"
11587   gcc_assert (TARGET_SH2A);
11588   return "nott";
11590   "! TARGET_SH2A && can_create_pseudo_p ()"
11591   [(set (match_dup 0) (reg:SI T_REG))
11592    (set (reg:SI T_REG) (eq:SI (match_dup 0) (const_int 0)))]
11594   operands[0] = gen_reg_rtx (SImode);
11597 ;; Store T bit as MSB in a reg.
11598 ;; T = 0: 0x00000000 -> reg
11599 ;; T = 1: 0x80000000 -> reg
11600 (define_insn_and_split "*movt_msb"
11601   [(set (match_operand:SI 0 "arith_reg_dest")
11602         (mult:SI (match_operand:SI 1 "t_reg_operand")
11603                  (const_int -2147483648)))  ;; 0xffffffff80000000
11604    (clobber (reg:SI T_REG))]
11605   "TARGET_SH1"
11606   "#"
11607   "&& 1"
11608   [(set (match_dup 0) (ashift:SI (reg:SI T_REG) (const_int 31)))])
11610 ;; Store inverted T bit as MSB in a reg.
11611 ;; T = 0: 0x80000000 -> reg
11612 ;; T = 1: 0x00000000 -> reg
11613 ;; On SH2A we can get away without clobbering the T_REG using the movrt insn.
11614 ;; On non SH2A we resort to the following sequence:
11615 ;;      movt    Rn
11616 ;;      tst     Rn,Rn
11617 ;;      rotcr   Rn
11618 ;; The T bit value will be modified during the sequence, but the rotcr insn
11619 ;; will restore its original value.
11620 (define_insn_and_split "*negt_msb"
11621   [(set (match_operand:SI 0 "arith_reg_dest")
11622         (match_operand:SI 1 "negt_reg_shl31_operand"))]
11623   "TARGET_SH1"
11624   "#"
11625   "&& can_create_pseudo_p ()"
11626   [(const_int 0)]
11628   rtx tmp = gen_reg_rtx (SImode);
11630   if (TARGET_SH2A)
11631     {
11632       emit_insn (gen_movrt (tmp, get_t_reg_rtx ()));
11633       emit_insn (gen_rotrsi3 (operands[0], tmp, const1_rtx));
11634     }
11635   else
11636     {
11637       emit_move_insn (tmp, get_t_reg_rtx ());
11638       emit_insn (gen_cmpeqsi_t (tmp, const0_rtx));
11639       emit_insn (gen_rotcr (operands[0], tmp, get_t_reg_rtx ()));
11640     }
11641   DONE;
11644 ;; The *cset_zero patterns convert optimizations such as
11645 ;;      "if (test) x = 0;"
11646 ;; to
11647 ;;      "x &= -(test == 0);"
11648 ;; back to conditional branch sequences if zero-displacement branches
11649 ;; are enabled.
11650 ;; FIXME: These patterns can be removed when conditional execution patterns
11651 ;; are implemented, since ifcvt will not perform these optimizations if
11652 ;; conditional execution is supported.
11653 (define_insn "*cset_zero"
11654   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
11655         (and:SI (plus:SI (match_operand:SI 1 "t_reg_operand")
11656                          (const_int -1))
11657                 (match_operand:SI 2 "arith_reg_operand" "0")))]
11658   "TARGET_SH1 && TARGET_ZDCBRANCH"
11660   return       "bf      0f"     "\n"
11661          "      mov     #0,%0"  "\n"
11662          "0:";
11664   [(set_attr "type" "arith") ;; poor approximation
11665    (set_attr "length" "4")])
11667 (define_insn "*cset_zero"
11668   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
11669         (if_then_else:SI (match_operand:SI 1 "cbranch_treg_value")
11670                          (match_operand:SI 2 "arith_reg_operand" "0")
11671                          (const_int 0)))]
11672   "TARGET_SH1 && TARGET_ZDCBRANCH"
11674   int tval = sh_eval_treg_value (operands[1]);
11675   if (tval == true)
11676     return     "bt      0f"     "\n"
11677            "    mov     #0,%0"  "\n"
11678            "0:";
11679   else if (tval == false)
11680     return     "bf      0f"     "\n"
11681            "    mov     #0,%0"  "\n"
11682            "0:";
11683   else
11684     gcc_unreachable ();
11686   [(set_attr "type" "arith") ;; poor approximation
11687    (set_attr "length" "4")])
11689 (define_expand "cstoresf4"
11690   [(set (match_operand:SI 0 "register_operand" "=r")
11691         (match_operator:SI 1 "sh_float_comparison_operator"
11692          [(match_operand:SF 2 "arith_operand" "")
11693           (match_operand:SF 3 "arith_operand" "")]))]
11694   "TARGET_SH2E || TARGET_SHMEDIA_FPU"
11696   if (TARGET_SHMEDIA)
11697     {
11698       emit_insn (gen_cstore4_media (operands[0], operands[1],
11699                                     operands[2], operands[3]));
11700       DONE;
11701     }
11703   if (! currently_expanding_to_rtl)
11704     FAIL;
11705    
11706   sh_emit_compare_and_set (operands, SFmode);
11707   DONE;
11710 (define_expand "cstoredf4"
11711   [(set (match_operand:SI 0 "register_operand" "=r")
11712         (match_operator:SI 1 "sh_float_comparison_operator"
11713          [(match_operand:DF 2 "arith_operand" "")
11714           (match_operand:DF 3 "arith_operand" "")]))]
11715   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
11717   if (TARGET_SHMEDIA)
11718     {
11719       emit_insn (gen_cstore4_media (operands[0], operands[1],
11720                                     operands[2], operands[3]));
11721       DONE;
11722     }
11724   if (! currently_expanding_to_rtl)
11725     FAIL;
11726    
11727   sh_emit_compare_and_set (operands, DFmode);
11728   DONE;
11731 ;; -------------------------------------------------------------------------
11732 ;; Instructions to cope with inline literal tables
11733 ;; -------------------------------------------------------------------------
11735 ;; 2 byte integer in line
11736 (define_insn "consttable_2"
11737  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")
11738                     (match_operand 1 "" "")]
11739                    UNSPECV_CONST2)]
11740  ""
11742   if (operands[1] != const0_rtx)
11743     assemble_integer (operands[0], 2, BITS_PER_UNIT * 2, 1);
11744   return "";
11746  [(set_attr "length" "2")
11747  (set_attr "in_delay_slot" "no")])
11749 ;; 4 byte integer in line
11750 (define_insn "consttable_4"
11751  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")
11752                     (match_operand 1 "" "")]
11753                    UNSPECV_CONST4)]
11754  ""
11756   if (operands[1] != const0_rtx)
11757     {
11758       assemble_integer (operands[0], 4, BITS_PER_UNIT * 4, 1);
11759       mark_symbol_refs_as_used (operands[0]);
11760     }
11761   return "";
11763  [(set_attr "length" "4")
11764   (set_attr "in_delay_slot" "no")])
11766 ;; 8 byte integer in line
11767 (define_insn "consttable_8"
11768  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")
11769                     (match_operand 1 "" "")]
11770                    UNSPECV_CONST8)]
11771  ""
11773   if (operands[1] != const0_rtx)
11774     assemble_integer (operands[0], 8, BITS_PER_UNIT * 8, 1);
11775   return "";
11777  [(set_attr "length" "8")
11778   (set_attr "in_delay_slot" "no")])
11780 ;; 4 byte floating point
11781 (define_insn "consttable_sf"
11782  [(unspec_volatile [(match_operand:SF 0 "general_operand" "=g")
11783                     (match_operand 1 "" "")]
11784                    UNSPECV_CONST4)]
11785  ""
11787   if (operands[1] != const0_rtx)
11788     {
11789       REAL_VALUE_TYPE d;
11790       REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
11791       assemble_real (d, SFmode, GET_MODE_ALIGNMENT (SFmode));
11792     }
11793   return "";
11795  [(set_attr "length" "4")
11796   (set_attr "in_delay_slot" "no")])
11798 ;; 8 byte floating point
11799 (define_insn "consttable_df"
11800  [(unspec_volatile [(match_operand:DF 0 "general_operand" "=g")
11801                     (match_operand 1 "" "")]
11802                    UNSPECV_CONST8)]
11803  ""
11805   if (operands[1] != const0_rtx)
11806     {
11807       REAL_VALUE_TYPE d;
11808       REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
11809       assemble_real (d, DFmode, GET_MODE_ALIGNMENT (DFmode));
11810     }
11811   return "";
11813  [(set_attr "length" "8")
11814   (set_attr "in_delay_slot" "no")])
11816 ;; Alignment is needed for some constant tables; it may also be added for
11817 ;; Instructions at the start of loops, or after unconditional branches.
11818 ;; ??? We would get more accurate lengths if we did instruction
11819 ;; alignment based on the value of INSN_CURRENT_ADDRESS; the approach used
11820 ;; here is too conservative.
11822 ;; align to a two byte boundary
11823 (define_expand "align_2"
11824  [(unspec_volatile [(const_int 1)] UNSPECV_ALIGN)]
11825  ""
11826  "")
11828 ;; Align to a four byte boundary.
11829 ;; align_4 and align_log are instructions for the starts of loops, or
11830 ;; after unconditional branches, which may take up extra room.
11831 (define_expand "align_4"
11832  [(unspec_volatile [(const_int 2)] UNSPECV_ALIGN)]
11833  ""
11834  "")
11836 ;; Align to a cache line boundary.
11837 (define_insn "align_log"
11838  [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPECV_ALIGN)]
11839  ""
11840  ""
11841  [(set_attr "length" "0")
11842   (set_attr "in_delay_slot" "no")])
11844 ;; Emitted at the end of the literal table, used to emit the
11845 ;; 32bit branch labels if needed.
11846 (define_insn "consttable_end"
11847   [(unspec_volatile [(const_int 0)] UNSPECV_CONST_END)]
11848   ""
11850   return output_jump_label_table ();
11852   [(set_attr "in_delay_slot" "no")])
11854 ;; Emitted at the end of the window in the literal table.
11855 (define_insn "consttable_window_end"
11856   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_WINDOW_END)]
11857   ""
11858   ""
11859   [(set_attr "length" "0")
11860    (set_attr "in_delay_slot" "no")])
11862 ;; -------------------------------------------------------------------------
11863 ;; Minimum / maximum operations.
11864 ;; -------------------------------------------------------------------------
11866 ;; The SH2A clips.b and clips.w insns do a signed min-max function.  If smin
11867 ;; and smax standard name patterns are defined, they will be used during
11868 ;; initial expansion and combine will then be able to form the actual min-max
11869 ;; pattern.
11870 ;; The clips.b and clips.w set the SR.CS bit if the value in the register is
11871 ;; clipped, but there is currently no way of making use of this information.
11872 ;; The only way to read or reset the SR.CS bit is by accessing the SR.
11873 (define_expand "<code>si3"
11874   [(parallel [(set (match_operand:SI 0 "arith_reg_dest")
11875                    (SMIN_SMAX:SI (match_operand:SI 1 "arith_reg_operand")
11876                                  (match_operand 2 "const_int_operand")))
11877               (clobber (reg:SI T_REG))])]
11878   "TARGET_SH2A"
11880   /* Force the comparison value into a register, because greater-than
11881      comparisons can work only on registers.  Combine will be able to pick up
11882      the constant value from the REG_EQUAL note when trying to form a min-max
11883      pattern.  */
11884   operands[2] = force_reg (SImode, operands[2]);
11887 ;; Convert
11888 ;;      smax (smin (...))
11889 ;; to
11890 ;;      smin (smax (...))
11891 (define_insn_and_split "*clips"
11892   [(set (match_operand:SI 0 "arith_reg_dest")
11893         (smax:SI (smin:SI (match_operand:SI 1 "arith_reg_operand")
11894                           (match_operand 2 "clips_max_const_int"))
11895                  (match_operand 3 "clips_min_const_int")))]
11896   "TARGET_SH2A"
11897   "#"
11898   "&& 1"
11899   [(set (match_dup 0)
11900         (smin:SI (smax:SI (match_dup 1) (match_dup 3)) (match_dup 2)))])
11902 (define_insn "*clips"
11903   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
11904         (smin:SI (smax:SI (match_operand:SI 1 "arith_reg_operand" "0")
11905                           (match_operand 2 "clips_min_const_int"))
11906                  (match_operand 3 "clips_max_const_int")))]
11907   "TARGET_SH2A"
11909   if (INTVAL (operands[3]) == 127)
11910     return "clips.b     %0";
11911   else if (INTVAL (operands[3]) == 32767)
11912     return "clips.w     %0";
11913   else
11914     gcc_unreachable ();
11916   [(set_attr "type" "arith")])
11918 ;; If the expanded smin or smax patterns were not combined, split them into
11919 ;; a compare and branch sequence, because there are no real smin or smax
11920 ;; insns.
11921 (define_insn_and_split "*<code>si3"
11922   [(set (match_operand:SI 0 "arith_reg_dest")
11923         (SMIN_SMAX:SI (match_operand:SI 1 "arith_reg_operand")
11924                       (match_operand:SI 2 "arith_reg_or_0_or_1_operand")))
11925    (clobber (reg:SI T_REG))]
11926   "TARGET_SH2A && can_create_pseudo_p ()"
11927   "#"
11928   "&& 1"
11929   [(const_int 0)]
11931   rtx skip_label = gen_label_rtx ();
11932   emit_move_insn (operands[0], operands[1]);
11934   rtx cmp_val = operands[2];
11935   if (satisfies_constraint_M (cmp_val))
11936     cmp_val = const0_rtx;
11938   emit_insn (gen_cmpgtsi_t (operands[0], cmp_val));
11939   emit_jump_insn (<CODE> == SMIN
11940                             ? gen_branch_false (skip_label)
11941                             : gen_branch_true (skip_label));
11943   emit_label_after (skip_label, emit_move_insn (operands[0], operands[2]));
11944   DONE;
11947 ;; The SH2A clipu.b and clipu.w insns can be used to implement a min function
11948 ;; with a register and a constant.
11949 ;; The clipu.b and clipu.w set the SR.CS bit if the value in the register is
11950 ;; clipped, but there is currently no way of making use of this information.
11951 ;; The only way to read or reset the SR.CS bit is by accessing the SR.
11952 (define_expand "uminsi3"
11953   [(set (match_operand:SI 0 "arith_reg_dest")
11954         (umin:SI (match_operand:SI 1 "arith_reg_operand")
11955                  (match_operand 2 "const_int_operand")))]
11956   "TARGET_SH2A"
11958   if (INTVAL (operands[2]) == 1)
11959     {
11960       emit_insn (gen_clipu_one (operands[0], operands[1]));
11961       DONE;
11962     }
11963   else if (! clipu_max_const_int (operands[2], VOIDmode))
11964     FAIL;
11967 (define_insn "*clipu"
11968   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
11969         (umin:SI (match_operand:SI 1 "arith_reg_operand" "0")
11970                  (match_operand 2 "clipu_max_const_int")))]
11971   "TARGET_SH2A"
11973   if (INTVAL (operands[2]) == 255)
11974     return "clipu.b     %0";
11975   else if (INTVAL (operands[2]) == 65535)
11976     return "clipu.w     %0";
11977   else
11978     gcc_unreachable ();
11980   [(set_attr "type" "arith")])
11982 (define_insn_and_split "clipu_one"
11983   [(set (match_operand:SI 0 "arith_reg_dest")
11984         (umin:SI (match_operand:SI 1 "arith_reg_operand") (const_int 1)))
11985    (clobber (reg:SI T_REG))]
11986   "TARGET_SH2A"
11987   "#"
11988   "&& can_create_pseudo_p ()"
11989   [(const_int 0)]
11991   emit_insn (gen_cmpeqsi_t (operands[1], const0_rtx));
11992   emit_insn (gen_movnegt (operands[0], get_t_reg_rtx ()));
11993   DONE;
11996 ;; -------------------------------------------------------------------------
11997 ;; Misc
11998 ;; -------------------------------------------------------------------------
12000 ;; String/block move insn.
12002 (define_expand "movmemsi"
12003   [(parallel [(set (mem:BLK (match_operand:BLK 0))
12004                    (mem:BLK (match_operand:BLK 1)))
12005               (use (match_operand:SI 2 "nonmemory_operand"))
12006               (use (match_operand:SI 3 "immediate_operand"))
12007               (clobber (reg:SI PR_REG))
12008               (clobber (reg:SI R4_REG))
12009               (clobber (reg:SI R5_REG))
12010               (clobber (reg:SI R0_REG))])]
12011   "TARGET_SH1 && ! TARGET_SH5"
12013   if (expand_block_move (operands))
12014     DONE;
12015   else
12016     FAIL;
12019 (define_insn "block_move_real"
12020   [(parallel [(set (mem:BLK (reg:SI R4_REG))
12021                    (mem:BLK (reg:SI R5_REG)))
12022               (use (match_operand:SI 0 "arith_reg_operand" "r"))
12023               (clobber (reg:SI PR_REG))
12024               (clobber (reg:SI R0_REG))])]
12025   "TARGET_SH1 && ! TARGET_HARD_SH4"
12026   "jsr  @%0%#"
12027   [(set_attr "type" "sfunc")
12028    (set_attr "needs_delay_slot" "yes")])
12030 (define_insn "block_lump_real"
12031   [(parallel [(set (mem:BLK (reg:SI R4_REG))
12032                    (mem:BLK (reg:SI R5_REG)))
12033               (use (match_operand:SI 0 "arith_reg_operand" "r"))
12034               (use (reg:SI R6_REG))
12035               (clobber (reg:SI PR_REG))
12036               (clobber (reg:SI T_REG))
12037               (clobber (reg:SI R4_REG))
12038               (clobber (reg:SI R5_REG))
12039               (clobber (reg:SI R6_REG))
12040               (clobber (reg:SI R0_REG))])]
12041   "TARGET_SH1 && ! TARGET_HARD_SH4"
12042   "jsr  @%0%#"
12043   [(set_attr "type" "sfunc")
12044    (set_attr "needs_delay_slot" "yes")])
12046 (define_insn "block_move_real_i4"
12047   [(parallel [(set (mem:BLK (reg:SI R4_REG))
12048                    (mem:BLK (reg:SI R5_REG)))
12049               (use (match_operand:SI 0 "arith_reg_operand" "r"))
12050               (clobber (reg:SI PR_REG))
12051               (clobber (reg:SI R0_REG))
12052               (clobber (reg:SI R1_REG))
12053               (clobber (reg:SI R2_REG))])]
12054   "TARGET_HARD_SH4"
12055   "jsr  @%0%#"
12056   [(set_attr "type" "sfunc")
12057    (set_attr "needs_delay_slot" "yes")])
12059 (define_insn "block_lump_real_i4"
12060   [(parallel [(set (mem:BLK (reg:SI R4_REG))
12061                    (mem:BLK (reg:SI R5_REG)))
12062               (use (match_operand:SI 0 "arith_reg_operand" "r"))
12063               (use (reg:SI R6_REG))
12064               (clobber (reg:SI PR_REG))
12065               (clobber (reg:SI T_REG))
12066               (clobber (reg:SI R4_REG))
12067               (clobber (reg:SI R5_REG))
12068               (clobber (reg:SI R6_REG))
12069               (clobber (reg:SI R0_REG))
12070               (clobber (reg:SI R1_REG))
12071               (clobber (reg:SI R2_REG))
12072               (clobber (reg:SI R3_REG))])]
12073   "TARGET_HARD_SH4"
12074   "jsr  @%0%#"
12075   [(set_attr "type" "sfunc")
12076    (set_attr "needs_delay_slot" "yes")])
12078 ;; byte compare pattern
12079 ;; temp = a ^ b;
12080 ;; !((temp & 0xF000) && (temp & 0x0F00) && (temp & 0x00F0) && (temp & 0x000F))
12081 (define_insn "cmpstr_t"
12082   [(set (reg:SI T_REG)
12083         (eq:SI (and:SI
12084                  (and:SI
12085                    (and:SI
12086                      (zero_extract:SI
12087                        (xor:SI (match_operand:SI 0 "arith_reg_operand" "r")
12088                                (match_operand:SI 1 "arith_reg_operand" "r"))
12089                        (const_int 8) (const_int 0))
12090                      (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
12091                                       (const_int 8) (const_int 8)))
12092                     (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
12093                                      (const_int 8) (const_int 16)))
12094                  (zero_extract:SI (xor:SI (match_dup 0) (match_dup 1))
12095                                   (const_int 8) (const_int 24)))
12096                (const_int 0)))]
12097   "TARGET_SH1"
12098   "cmp/str      %0,%1"
12099   [(set_attr "type" "mt_group")])
12101 (define_expand "cmpstrsi"
12102   [(set (match_operand:SI 0 "register_operand")
12103         (compare:SI (match_operand:BLK 1 "memory_operand")
12104                     (match_operand:BLK 2 "memory_operand")))
12105    (use (match_operand 3 "immediate_operand"))]
12106   "TARGET_SH1 && optimize"
12108   if (! optimize_insn_for_size_p () && sh_expand_cmpstr (operands))
12109     DONE;
12110   else
12111     FAIL;
12114 (define_expand "cmpstrnsi"
12115   [(set (match_operand:SI 0 "register_operand")
12116         (compare:SI (match_operand:BLK 1 "memory_operand")
12117                     (match_operand:BLK 2 "memory_operand")))
12118    (use (match_operand:SI 3 "immediate_operand"))
12119    (use (match_operand:SI 4 "immediate_operand"))]
12120   "TARGET_SH1 && optimize"
12122   if (! optimize_insn_for_size_p () && sh_expand_cmpnstr (operands))
12123     DONE;
12124   else
12125     FAIL;
12128 (define_expand "strlensi"
12129   [(set (match_operand:SI 0 "register_operand")
12130         (unspec:SI [(match_operand:BLK 1 "memory_operand")
12131                    (match_operand:SI 2 "immediate_operand")
12132                    (match_operand:SI 3 "immediate_operand")]
12133                   UNSPEC_BUILTIN_STRLEN))]
12134   "TARGET_SH1 && optimize"
12136  if (! optimize_insn_for_size_p () && sh_expand_strlen (operands))
12137    DONE;
12138  else
12139    FAIL;
12142 (define_expand "setmemqi"
12143   [(parallel [(set (match_operand:BLK 0 "memory_operand")
12144                    (match_operand 2 "const_int_operand"))
12145               (use (match_operand:QI 1 "const_int_operand"))
12146               (use (match_operand:QI 3 "const_int_operand"))])]
12147   "TARGET_SH1 && optimize"
12148   {
12149     if (optimize_insn_for_size_p ())
12150        FAIL;
12152     sh_expand_setmem (operands);
12153     DONE;
12154   })
12157 ;; -------------------------------------------------------------------------
12158 ;; Floating point instructions.
12159 ;; -------------------------------------------------------------------------
12161 ;; FIXME: For now we disallow any memory operands for fpscr loads/stores,
12162 ;; except for post-inc loads and pre-dec stores for push/pop purposes.
12163 ;; This avoids problems with reload.  As a consequence, user initiated fpscr
12164 ;; stores to memory will always be ferried through a general register.
12165 ;; User initiated fpscr loads always have to undergo bit masking to preserve
12166 ;; the current fpu mode settings for the compiler generated code.  Thus such
12167 ;; fpscr loads will always have to go through general registers anyways.
12168 (define_insn "lds_fpscr"
12169   [(set (reg:SI FPSCR_REG)
12170         (match_operand:SI 0 "fpscr_movsrc_operand" "r,>"))
12171    (set (reg:SI FPSCR_STAT_REG)
12172         (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_STAT))
12173    (set (reg:SI FPSCR_MODES_REG)
12174         (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))]
12175   "TARGET_FPU_ANY"
12176   "@
12177         lds     %0,fpscr
12178         lds.l   %0,fpscr"
12179   [(set_attr "type" "gp_fpscr,mem_fpscr")])
12181 ;; A move fpscr -> reg schedules like a move mac -> reg.  Thus we use mac_gp
12182 ;; type for it.
12183 (define_insn "sts_fpscr"
12184   [(set (match_operand:SI 0 "fpscr_movdst_operand" "=r,<")
12185         (reg:SI FPSCR_REG))
12186    (use (reg:SI FPSCR_STAT_REG))
12187    (use (reg:SI FPSCR_MODES_REG))]
12188   "TARGET_FPU_ANY"
12189   "@
12190         sts     fpscr,%0
12191         sts.l   fpscr,%0"
12192   [(set_attr "type" "mac_gp,fstore")])
12194 (define_expand "set_fpscr"
12195   [(parallel [(set (reg:SI FPSCR_REG)
12196                    (match_operand:SI 0 "general_operand"))
12197               (set (reg:SI FPSCR_STAT_REG)
12198                    (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))])]
12199   "TARGET_FPU_ANY"
12201   /* We have to mask out the FR, SZ and PR bits.  To do that, we need to
12202      get the current FPSCR value first.
12203      (a & ~mask) | (b & mask) = a ^ ((a ^ b) & mask)  */
12205   rtx mask = force_reg (SImode, GEN_INT (FPSCR_FR | FPSCR_SZ | FPSCR_PR));
12207   rtx a = force_reg (SImode, operands[0]);
12209   rtx b = gen_reg_rtx (SImode);
12210   emit_insn (gen_sts_fpscr (b));
12212   rtx a_xor_b = gen_reg_rtx (SImode);
12213   emit_insn (gen_xorsi3 (a_xor_b, a, b));
12215   rtx a_xor_b_and_mask = gen_reg_rtx (SImode);
12216   emit_insn (gen_andsi3 (a_xor_b_and_mask, a_xor_b, mask));
12218   rtx r = gen_reg_rtx (SImode);
12219   emit_insn (gen_xorsi3 (r, a_xor_b_and_mask, a));
12220   emit_insn (gen_lds_fpscr (r));
12222   DONE;
12225 ;; ??? This uses the fp unit, but has no type indicating that.
12226 ;; If we did that, this would either give a bogus latency or introduce
12227 ;; a bogus FIFO constraint.
12228 ;; Since this insn is currently only used for prologues/epilogues,
12229 ;; it is probably best to claim no function unit, which matches the
12230 ;; current setting.
12231 (define_insn "toggle_sz"
12232   [(set (reg:SI FPSCR_REG)
12233         (xor:SI (reg:SI FPSCR_REG) (const_int FPSCR_SZ)))
12234    (set (reg:SI FPSCR_MODES_REG)
12235         (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))]
12236   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
12237   "fschg"
12238   [(set_attr "type" "fpscr_toggle") (set_attr "fp_set" "unknown")])
12240 ;; Toggle FPU precision PR mode.
12242 (define_insn "toggle_pr"
12243   [(set (reg:SI FPSCR_REG)
12244         (xor:SI (reg:SI FPSCR_REG) (const_int FPSCR_PR)))
12245    (set (reg:SI FPSCR_MODES_REG)
12246         (unspec_volatile:SI [(const_int 0)] UNSPECV_FPSCR_MODES))]
12247   "TARGET_SH4A_FP"
12248   "fpchg"
12249   [(set_attr "type" "fpscr_toggle")])
12251 (define_expand "addsf3"
12252   [(set (match_operand:SF 0 "fp_arith_reg_operand")
12253         (plus:SF (match_operand:SF 1 "fp_arith_reg_operand")
12254                  (match_operand:SF 2 "fp_arith_reg_operand")))]
12255   "TARGET_SH2E || TARGET_SHMEDIA_FPU"
12257   if (TARGET_SH2E)
12258     {
12259       emit_insn (gen_addsf3_i (operands[0], operands[1], operands[2]));
12260       DONE;
12261     }
12264 (define_insn "*addsf3_media"
12265   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12266         (plus:SF (match_operand:SF 1 "fp_arith_reg_operand" "%f")
12267                  (match_operand:SF 2 "fp_arith_reg_operand" "f")))]
12268   "TARGET_SHMEDIA_FPU"
12269   "fadd.s       %1, %2, %0"
12270   [(set_attr "type" "fparith_media")])
12272 (define_insn_and_split "unary_sf_op"
12273   [(set (match_operand:V2SF 0 "fp_arith_reg_operand" "=f")
12274         (vec_select:V2SF
12275          (vec_concat:V2SF
12276           (vec_select:SF
12277            (match_dup 0)
12278            (parallel [(not:BI (match_operand 3 "const_int_operand" "n"))]))
12279           (match_operator:SF 2 "unary_float_operator"
12280             [(vec_select:SF (match_operand:V2SF 1 "fp_arith_reg_operand" "f")
12281                             (parallel [(match_operand 4
12282                                         "const_int_operand" "n")]))]))
12283          (parallel [(not:BI (match_dup 3)) (match_dup 3)])))]
12284   "TARGET_SHMEDIA_FPU"
12285   "#"
12286   "TARGET_SHMEDIA_FPU && reload_completed"
12287   [(set (match_dup 5) (match_dup 6))]
12289   int endian = TARGET_LITTLE_ENDIAN ? 0 : 1;
12290   rtx op1 = gen_rtx_REG (SFmode,
12291                          (true_regnum (operands[1])
12292                           + (INTVAL (operands[4]) ^ endian)));
12294   operands[7] = gen_rtx_REG (SFmode,
12295                              (true_regnum (operands[0])
12296                               + (INTVAL (operands[3]) ^ endian)));
12297   operands[6] = gen_rtx_fmt_e (GET_CODE (operands[2]), SFmode, op1);
12299   [(set_attr "type" "fparith_media")])
12301 (define_insn_and_split "binary_sf_op0"
12302   [(set (match_operand:V2SF 0 "fp_arith_reg_operand" "=f")
12303         (vec_concat:V2SF
12304           (match_operator:SF 3 "binary_float_operator"
12305             [(vec_select:SF (match_operand:V2SF 1 "fp_arith_reg_operand" "f")
12306                             (parallel [(const_int 0)]))
12307              (vec_select:SF (match_operand:V2SF 2 "fp_arith_reg_operand" "f")
12308                             (parallel [(const_int 0)]))])
12309           (vec_select:SF
12310            (match_dup 0)
12311            (parallel [(const_int 1)]))))]
12312   "TARGET_SHMEDIA_FPU"
12313   "#"
12314   "&& reload_completed"
12315   [(set (match_dup 4) (match_dup 5))]
12317   int endian = TARGET_LITTLE_ENDIAN ? 0 : 1;
12318   rtx op1 = gen_rtx_REG (SFmode,
12319                          true_regnum (operands[1]) + endian);
12320   rtx op2 = gen_rtx_REG (SFmode,
12321                          true_regnum (operands[2]) + endian);
12323   operands[4] = gen_rtx_REG (SFmode,
12324                              true_regnum (operands[0]) + endian);
12325   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SFmode, op1, op2);
12327   [(set_attr "type" "fparith_media")])
12329 (define_insn_and_split "binary_sf_op1"
12330   [(set (match_operand:V2SF 0 "fp_arith_reg_operand" "=f")
12331         (vec_concat:V2SF
12332           (vec_select:SF
12333            (match_dup 0)
12334            (parallel [(const_int 0)]))
12335           (match_operator:SF 3 "binary_float_operator"
12336             [(vec_select:SF (match_operand:V2SF 1 "fp_arith_reg_operand" "f")
12337                             (parallel [(const_int 1)]))
12338              (vec_select:SF (match_operand:V2SF 2 "fp_arith_reg_operand" "f")
12339                             (parallel [(const_int 1)]))])))]
12340   "TARGET_SHMEDIA_FPU"
12341   "#"
12342   "&& reload_completed"
12343   [(set (match_dup 4) (match_dup 5))]
12345   int endian = TARGET_LITTLE_ENDIAN ? 0 : 1;
12346   rtx op1 = gen_rtx_REG (SFmode, true_regnum (operands[1]) + (1 ^ endian));
12347   rtx op2 = gen_rtx_REG (SFmode, true_regnum (operands[2]) + (1 ^ endian));
12349   operands[4] = gen_rtx_REG (SFmode, true_regnum (operands[0]) + (1 ^ endian));
12350   operands[5] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SFmode, op1, op2);
12352   [(set_attr "type" "fparith_media")])
12354 (define_insn "addsf3_i"
12355   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12356         (plus:SF (match_operand:SF 1 "fp_arith_reg_operand" "%0")
12357                  (match_operand:SF 2 "fp_arith_reg_operand" "f")))
12358    (clobber (reg:SI FPSCR_STAT_REG))
12359    (use (reg:SI FPSCR_MODES_REG))]
12360   "TARGET_SH2E"
12361   "fadd %2,%0"
12362   [(set_attr "type" "fp")
12363    (set_attr "fp_mode" "single")])
12365 (define_expand "subsf3"
12366   [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
12367         (minus:SF (match_operand:SF 1 "fp_arith_reg_operand" "")
12368                   (match_operand:SF 2 "fp_arith_reg_operand" "")))]
12369   "TARGET_SH2E || TARGET_SHMEDIA_FPU"
12371   if (TARGET_SH2E)
12372     {
12373       emit_insn (gen_subsf3_i (operands[0], operands[1], operands[2]));
12374       DONE;
12375     }
12378 (define_insn "*subsf3_media"
12379   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12380         (minus:SF (match_operand:SF 1 "fp_arith_reg_operand" "f")
12381                   (match_operand:SF 2 "fp_arith_reg_operand" "f")))]
12382   "TARGET_SHMEDIA_FPU"
12383   "fsub.s       %1, %2, %0"
12384   [(set_attr "type" "fparith_media")])
12386 (define_insn "subsf3_i"
12387   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12388         (minus:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")
12389                  (match_operand:SF 2 "fp_arith_reg_operand" "f")))
12390    (clobber (reg:SI FPSCR_STAT_REG))
12391    (use (reg:SI FPSCR_MODES_REG))]
12392   "TARGET_SH2E"
12393   "fsub %2,%0"
12394   [(set_attr "type" "fp")
12395    (set_attr "fp_mode" "single")])
12397 (define_expand "mulsf3"
12398   [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
12399         (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "")
12400                  (match_operand:SF 2 "fp_arith_reg_operand" "")))]
12401   "TARGET_SH2E || TARGET_SHMEDIA_FPU"
12403   if (TARGET_SH2E)
12404     {
12405       emit_insn (gen_mulsf3_i (operands[0], operands[1], operands[2]));
12406       DONE;
12407     }
12410 (define_insn "*mulsf3_media"
12411   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12412         (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "%f")
12413                  (match_operand:SF 2 "fp_arith_reg_operand" "f")))]
12414   "TARGET_SHMEDIA_FPU"
12415   "fmul.s       %1, %2, %0"
12416   [(set_attr "type" "fparith_media")])
12418 (define_insn "mulsf3_i"
12419   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12420         (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "%0")
12421                  (match_operand:SF 2 "fp_arith_reg_operand" "f")))
12422    (clobber (reg:SI FPSCR_STAT_REG))
12423    (use (reg:SI FPSCR_MODES_REG))]
12424   "TARGET_SH2E"
12425   "fmul %2,%0"
12426   [(set_attr "type" "fp")
12427    (set_attr "fp_mode" "single")])
12429 ;; FMA (fused multiply-add) patterns
12430 (define_expand "fmasf4"
12431   [(set (match_operand:SF 0 "fp_arith_reg_operand")
12432         (fma:SF (match_operand:SF 1 "fp_arith_reg_operand")
12433                 (match_operand:SF 2 "fp_arith_reg_operand")
12434                 (match_operand:SF 3 "fp_arith_reg_operand")))]
12435   "TARGET_SH2E || TARGET_SHMEDIA_FPU"
12437   if (TARGET_SH2E)
12438     {
12439       emit_insn (gen_fmasf4_i (operands[0], operands[1], operands[2],
12440                                operands[3]));
12441       DONE;
12442     }
12445 (define_insn "fmasf4_i"
12446   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12447         (fma:SF (match_operand:SF 1 "fp_arith_reg_operand" "w")
12448                 (match_operand:SF 2 "fp_arith_reg_operand" "f")
12449                 (match_operand:SF 3 "fp_arith_reg_operand" "0")))
12450    (clobber (reg:SI FPSCR_STAT_REG))
12451    (use (reg:SI FPSCR_MODES_REG))]
12452   "TARGET_SH2E"
12453   "fmac %1,%2,%0"
12454   [(set_attr "type" "fp")
12455    (set_attr "fp_mode" "single")])
12457 (define_insn "fmasf4_media"
12458   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12459         (fma:SF (match_operand:SF 1 "fp_arith_reg_operand" "f")
12460                 (match_operand:SF 2 "fp_arith_reg_operand" "f")
12461                 (match_operand:SF 3 "fp_arith_reg_operand" "0")))]
12462   "TARGET_SHMEDIA_FPU"
12463   "fmac.s %1, %2, %0"
12464   [(set_attr "type" "fparith_media")])
12466 ;; For some cases such as 'a * b + a' the FMA pattern is not generated by
12467 ;; previous transformations.  If FMA is generally allowed, let the combine
12468 ;; pass utilize it.
12469 (define_insn_and_split "*fmasf4"
12470   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12471         (plus:SF (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "%w")
12472                           (match_operand:SF 2 "fp_arith_reg_operand" "f"))
12473                  (match_operand:SF 3 "arith_reg_operand" "0")))
12474    (clobber (reg:SI FPSCR_STAT_REG))
12475    (use (reg:SI FPSCR_MODES_REG))]
12476   "TARGET_SH2E && flag_fp_contract_mode != FP_CONTRACT_OFF"
12477   "fmac %1,%2,%0"
12478   "&& can_create_pseudo_p ()"
12479   [(parallel [(set (match_dup 0)
12480                    (fma:SF (match_dup 1) (match_dup 2) (match_dup 3)))
12481               (clobber (reg:SI FPSCR_STAT_REG))
12482               (use (reg:SI FPSCR_MODES_REG))])]
12484   /* Change 'b * a + a' into 'a * b + a'.
12485      This is better for register allocation.  */
12486   if (REGNO (operands[2]) == REGNO (operands[3]))
12487     std::swap (operands[1], operands[2]);
12489   [(set_attr "type" "fp")
12490    (set_attr "fp_mode" "single")])
12492 (define_insn "*fmasf4_media"
12493   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12494         (plus:SF (mult:SF (match_operand:SF 1 "fp_arith_reg_operand" "%f")
12495                           (match_operand:SF 2 "fp_arith_reg_operand" "f"))
12496                  (match_operand:SF 3 "fp_arith_reg_operand" "0")))]
12497   "TARGET_SHMEDIA_FPU && flag_fp_contract_mode != FP_CONTRACT_OFF"
12498   "fmac.s %1, %2, %0"
12499   [(set_attr "type" "fparith_media")])
12501 (define_expand "divsf3"
12502   [(set (match_operand:SF 0 "fp_arith_reg_operand")
12503         (div:SF (match_operand:SF 1 "fp_arith_reg_operand")
12504                 (match_operand:SF 2 "fp_arith_reg_operand")))]
12505   "TARGET_SH2E || TARGET_SHMEDIA_FPU"
12507   if (TARGET_SH2E)
12508     {
12509       emit_insn (gen_divsf3_i (operands[0], operands[1], operands[2]));
12510       DONE;
12511     }
12514 (define_insn "*divsf3_media"
12515   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12516         (div:SF (match_operand:SF 1 "fp_arith_reg_operand" "f")
12517                 (match_operand:SF 2 "fp_arith_reg_operand" "f")))]
12518   "TARGET_SHMEDIA_FPU"
12519   "fdiv.s       %1, %2, %0"
12520   [(set_attr "type" "fdiv_media")])
12522 (define_insn "divsf3_i"
12523   [(set (match_operand:SF 0 "fp_arith_reg_dest" "=f")
12524         (div:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")
12525                  (match_operand:SF 2 "fp_arith_reg_operand" "f")))
12526    (clobber (reg:SI FPSCR_STAT_REG))
12527    (use (reg:SI FPSCR_MODES_REG))]
12528   "TARGET_SH2E"
12529   "fdiv %2,%0"
12530   [(set_attr "type" "fdiv")
12531    (set_attr "fp_mode" "single")])
12533 (define_insn "floatdisf2"
12534   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12535         (float:SF (match_operand:DI 1 "fp_arith_reg_operand" "f")))]
12536   "TARGET_SHMEDIA_FPU"
12537   "float.qs %1, %0"
12538   [(set_attr "type" "fpconv_media")])
12540 (define_expand "floatsisf2"
12541   [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
12542         (float:SF (match_operand:SI 1 "fpul_operand" "")))]
12543   "TARGET_SH2E || TARGET_SHMEDIA_FPU"
12545   if (!TARGET_SHMEDIA_FPU)
12546     {
12547       emit_insn (gen_floatsisf2_i4 (operands[0], operands[1]));
12548       DONE;
12549     }
12552 (define_insn "*floatsisf2_media"
12553   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12554         (float:SF (match_operand:SI 1 "fp_arith_reg_operand" "f")))]
12555   "TARGET_SHMEDIA_FPU"
12556   "float.ls     %1, %0"
12557   [(set_attr "type" "fpconv_media")])
12559 (define_insn "floatsisf2_i4"
12560   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12561         (float:SF (match_operand:SI 1 "fpul_operand" "y")))
12562    (clobber (reg:SI FPSCR_STAT_REG))
12563    (use (reg:SI FPSCR_MODES_REG))]
12564   "TARGET_SH2E"
12565   "float        %1,%0"
12566   [(set_attr "type" "fp")
12567    (set_attr "fp_mode" "single")])
12569 (define_insn "fix_truncsfdi2"
12570   [(set (match_operand:DI 0 "fp_arith_reg_dest" "=f")
12571         (fix:DI (match_operand:SF 1 "fp_arith_reg_operand" "f")))]
12572   "TARGET_SHMEDIA_FPU"
12573   "ftrc.sq %1, %0"
12574   [(set_attr "type" "fpconv_media")])
12576 (define_expand "fix_truncsfsi2"
12577   [(set (match_operand:SI 0 "fpul_operand" "=y")
12578         (fix:SI (match_operand:SF 1 "fp_arith_reg_operand" "f")))]
12579   "TARGET_SH2E || TARGET_SHMEDIA_FPU"
12581   if (!TARGET_SHMEDIA_FPU)
12582     {
12583       emit_insn (gen_fix_truncsfsi2_i4 (operands[0], operands[1]));
12584       DONE;
12585     }
12588 (define_insn "*fix_truncsfsi2_media"
12589   [(set (match_operand:SI 0 "fp_arith_reg_operand" "=f")
12590         (fix:SI (match_operand:SF 1 "fp_arith_reg_operand" "f")))]
12591   "TARGET_SHMEDIA_FPU"
12592   "ftrc.sl      %1, %0"
12593   [(set_attr "type" "fpconv_media")])
12595 (define_insn "fix_truncsfsi2_i4"
12596   [(set (match_operand:SI 0 "fpul_operand" "=y")
12597         (fix:SI (match_operand:SF 1 "fp_arith_reg_operand" "f")))
12598    (clobber (reg:SI FPSCR_STAT_REG))
12599    (use (reg:SI FPSCR_MODES_REG))]
12600   "TARGET_SH2E"
12601   "ftrc %1,%0"
12602   [(set_attr "type" "ftrc_s")
12603    (set_attr "fp_mode" "single")])
12605 (define_insn "cmpgtsf_t"
12606   [(set (reg:SI T_REG)
12607         (gt:SI (match_operand:SF 0 "fp_arith_reg_operand" "f")
12608                (match_operand:SF 1 "fp_arith_reg_operand" "f")))
12609    (clobber (reg:SI FPSCR_STAT_REG))
12610    (use (reg:SI FPSCR_MODES_REG))]
12611   "TARGET_SH2E || TARGET_SH4 || TARGET_SH2A_SINGLE"
12612   "fcmp/gt      %1,%0"
12613   [(set_attr "type" "fp_cmp")
12614    (set_attr "fp_mode" "single")])
12616 (define_insn "cmpeqsf_t"
12617   [(set (reg:SI T_REG)
12618         (eq:SI (match_operand:SF 0 "fp_arith_reg_operand" "f")
12619                (match_operand:SF 1 "fp_arith_reg_operand" "f")))
12620    (clobber (reg:SI FPSCR_STAT_REG))
12621    (use (reg:SI FPSCR_MODES_REG))]
12622   "TARGET_SH2E || TARGET_SH4 || TARGET_SH2A_SINGLE"
12623   "fcmp/eq      %1,%0"
12624   [(set_attr "type" "fp_cmp")
12625    (set_attr "fp_mode" "single")])
12627 (define_insn "ieee_ccmpeqsf_t"
12628   [(set (reg:SI T_REG)
12629         (ior:SI (reg:SI T_REG)
12630                 (eq:SI (match_operand:SF 0 "fp_arith_reg_operand" "f")
12631                        (match_operand:SF 1 "fp_arith_reg_operand" "f"))))
12632    (clobber (reg:SI FPSCR_STAT_REG))
12633    (use (reg:SI FPSCR_MODES_REG))]
12634   "TARGET_IEEE && TARGET_SH2E"
12636   return output_ieee_ccmpeq (insn, operands);
12638   [(set_attr "length" "4")
12639    (set_attr "fp_mode" "single")])
12641 (define_insn "cmpeqsf_media"
12642   [(set (match_operand:SI 0 "register_operand" "=r")
12643         (eq:SI (match_operand:SF 1 "fp_arith_reg_operand" "f")
12644                (match_operand:SF 2 "fp_arith_reg_operand" "f")))]
12645   "TARGET_SHMEDIA_FPU"
12646   "fcmpeq.s     %1, %2, %0"
12647   [(set_attr "type" "fcmp_media")])
12649 (define_insn "cmpgtsf_media"
12650   [(set (match_operand:SI 0 "register_operand" "=r")
12651         (gt:SI (match_operand:SF 1 "fp_arith_reg_operand" "f")
12652                (match_operand:SF 2 "fp_arith_reg_operand" "f")))]
12653   "TARGET_SHMEDIA_FPU"
12654   "fcmpgt.s     %1, %2, %0"
12655   [(set_attr "type" "fcmp_media")])
12657 (define_insn "cmpgesf_media"
12658   [(set (match_operand:SI 0 "register_operand" "=r")
12659         (ge:SI (match_operand:SF 1 "fp_arith_reg_operand" "f")
12660                (match_operand:SF 2 "fp_arith_reg_operand" "f")))]
12661   "TARGET_SHMEDIA_FPU"
12662   "fcmpge.s     %1, %2, %0"
12663   [(set_attr "type" "fcmp_media")])
12665 (define_insn "cmpunsf_media"
12666   [(set (match_operand:SI 0 "register_operand" "=r")
12667         (unordered:SI (match_operand:SF 1 "fp_arith_reg_operand" "f")
12668                       (match_operand:SF 2 "fp_arith_reg_operand" "f")))]
12669   "TARGET_SHMEDIA_FPU"
12670   "fcmpun.s     %1, %2, %0"
12671   [(set_attr "type" "fcmp_media")])
12673 (define_expand "cbranchsf4"
12674   [(set (pc)
12675         (if_then_else (match_operator 0 "sh_float_comparison_operator"
12676                        [(match_operand:SF 1 "arith_operand" "")
12677                         (match_operand:SF 2 "arith_operand" "")])
12678                       (match_operand 3 "" "")
12679                       (pc)))]
12680   "TARGET_SH2E || TARGET_SHMEDIA_FPU"
12682   if (TARGET_SHMEDIA)
12683     emit_jump_insn (gen_cbranchfp4_media (operands[0], operands[1], operands[2],
12684                                           operands[3]));
12685   else
12686     sh_emit_compare_and_branch (operands, SFmode);
12687   DONE;
12690 (define_expand "negsf2"
12691   [(set (match_operand:SF 0 "fp_arith_reg_operand")
12692         (neg:SF (match_operand:SF 1 "fp_arith_reg_operand")))]
12693   "TARGET_SH2E || TARGET_SHMEDIA_FPU")
12695 (define_insn "*negsf2_media"
12696   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12697         (neg:SF (match_operand:SF 1 "fp_arith_reg_operand" "f")))]
12698   "TARGET_SHMEDIA_FPU"
12699   "fneg.s       %1, %0"
12700   [(set_attr "type" "fmove_media")])
12702 (define_insn "*negsf2_i"
12703   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12704         (neg:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))]
12705   "TARGET_SH2E"
12706   "fneg %0"
12707   [(set_attr "type" "fmove")])
12709 (define_expand "sqrtsf2"
12710   [(set (match_operand:SF 0 "fp_arith_reg_operand" "")
12711         (sqrt:SF (match_operand:SF 1 "fp_arith_reg_operand" "")))]
12712   "TARGET_SH3E || TARGET_SHMEDIA_FPU"
12714   if (TARGET_SH3E)
12715     {
12716       emit_insn (gen_sqrtsf2_i (operands[0], operands[1]));
12717       DONE;
12718     }
12721 (define_insn "*sqrtsf2_media"
12722   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12723         (sqrt:SF (match_operand:SF 1 "fp_arith_reg_operand" "f")))]
12724   "TARGET_SHMEDIA_FPU"
12725   "fsqrt.s      %1, %0"
12726   [(set_attr "type" "fdiv_media")])
12728 (define_insn "sqrtsf2_i"
12729   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12730         (sqrt:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))
12731    (clobber (reg:SI FPSCR_STAT_REG))
12732    (use (reg:SI FPSCR_MODES_REG))]
12733   "TARGET_SH3E"
12734   "fsqrt        %0"
12735   [(set_attr "type" "fdiv")
12736    (set_attr "fp_mode" "single")])
12738 (define_insn "rsqrtsf2"
12739   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12740         (div:SF (match_operand:SF 1 "immediate_operand" "i")
12741                 (sqrt:SF (match_operand:SF 2 "fp_arith_reg_operand" "0"))))
12742    (clobber (reg:SI FPSCR_STAT_REG))
12743    (use (reg:SI FPSCR_MODES_REG))]
12744   "TARGET_FPU_ANY && TARGET_FSRRA
12745    && operands[1] == CONST1_RTX (SFmode)"
12746   "fsrra        %0"
12747   [(set_attr "type" "fsrra")
12748    (set_attr "fp_mode" "single")])
12750 ;; When the sincos pattern is defined, the builtin functions sin and cos
12751 ;; will be expanded to the sincos pattern and one of the output values will
12752 ;; remain unused.
12753 (define_expand "sincossf3"
12754   [(set (match_operand:SF 0 "nonimmediate_operand")
12755         (unspec:SF [(match_operand:SF 2 "fp_arith_reg_operand")] UNSPEC_FCOSA))
12756    (set (match_operand:SF 1 "nonimmediate_operand")
12757         (unspec:SF [(match_dup 2)] UNSPEC_FSINA))]
12758   "TARGET_FPU_ANY && TARGET_FSCA"
12760   rtx scaled = gen_reg_rtx (SFmode);
12761   rtx truncated = gen_reg_rtx (SImode);
12762   rtx fsca = gen_reg_rtx (V2SFmode);
12763   rtx scale_reg = force_reg (SFmode, sh_fsca_sf2int ());
12765   emit_insn (gen_mulsf3 (scaled, operands[2], scale_reg));
12766   emit_insn (gen_fix_truncsfsi2 (truncated, scaled));
12767   emit_insn (gen_fsca (fsca, truncated, sh_fsca_int2sf ()));
12769   emit_move_insn (operands[0], gen_rtx_SUBREG (SFmode, fsca, 4));
12770   emit_move_insn (operands[1], gen_rtx_SUBREG (SFmode, fsca, 0));
12771   DONE;
12774 (define_insn_and_split "fsca"
12775   [(set (match_operand:V2SF 0 "fp_arith_reg_operand" "=f")
12776         (vec_concat:V2SF
12777          (unspec:SF [(mult:SF
12778                       (float:SF (match_operand:SI 1 "fpul_fsca_operand" "y"))
12779                       (match_operand:SF 2 "fsca_scale_factor" "i"))
12780                     ] UNSPEC_FSINA)
12781          (unspec:SF [(mult:SF (float:SF (match_dup 1)) (match_dup 2))
12782                     ] UNSPEC_FCOSA)))
12783    (clobber (reg:SI FPSCR_STAT_REG))
12784    (use (reg:SI FPSCR_MODES_REG))]
12785   "TARGET_FPU_ANY && TARGET_FSCA"
12786   "fsca fpul,%d0"
12787   "&& !fpul_operand (operands[1], SImode)"
12788   [(const_int 0)]
12790   /* If operands[1] is something like (fix:SF (float:SF (reg:SI))) reduce it
12791      to a simple reg, otherwise reload will have trouble reloading the
12792      pseudo into fpul.  */
12793   rtx x = XEXP (operands[1], 0);
12794   while (x != NULL_RTX && !fpul_operand (x, SImode))
12795     {
12796       gcc_assert (GET_CODE (x) == FIX || GET_CODE (x) == FLOAT);
12797       x = XEXP (x, 0);
12798     }
12799   gcc_assert (x != NULL_RTX && fpul_operand (x, SImode));
12800   emit_insn (gen_fsca (operands[0], x, operands[2]));
12801   DONE;
12803   [(set_attr "type" "fsca")
12804    (set_attr "fp_mode" "single")])
12806 (define_expand "abssf2"
12807   [(set (match_operand:SF 0 "fp_arith_reg_operand")
12808         (abs:SF (match_operand:SF 1 "fp_arith_reg_operand")))]
12809   "TARGET_SH2E || TARGET_SHMEDIA_FPU")
12811 (define_insn "*abssf2_media"
12812   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12813         (abs:SF (match_operand:SF 1 "fp_arith_reg_operand" "f")))]
12814   "TARGET_SHMEDIA_FPU"
12815   "fabs.s       %1, %0"
12816   [(set_attr "type" "fmove_media")])
12818 (define_insn "*abssf2_i"
12819   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
12820         (abs:SF (match_operand:SF 1 "fp_arith_reg_operand" "0")))]
12821   "TARGET_SH2E"
12822   "fabs %0"
12823   [(set_attr "type" "fmove")])
12825 (define_expand "adddf3"
12826   [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
12827         (plus:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
12828                  (match_operand:DF 2 "fp_arith_reg_operand" "")))]
12829   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
12831   if (TARGET_SH4 || TARGET_SH2A_DOUBLE)
12832     {
12833       emit_insn (gen_adddf3_i (operands[0], operands[1], operands[2]));
12834       DONE;
12835     }
12838 (define_insn "*adddf3_media"
12839   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12840         (plus:DF (match_operand:DF 1 "fp_arith_reg_operand" "%f")
12841                  (match_operand:DF 2 "fp_arith_reg_operand" "f")))]
12842   "TARGET_SHMEDIA_FPU"
12843   "fadd.d       %1, %2, %0"
12844   [(set_attr "type" "dfparith_media")])
12846 (define_insn "adddf3_i"
12847   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12848         (plus:DF (match_operand:DF 1 "fp_arith_reg_operand" "%0")
12849                  (match_operand:DF 2 "fp_arith_reg_operand" "f")))
12850    (clobber (reg:SI FPSCR_STAT_REG))
12851    (use (reg:SI FPSCR_MODES_REG))]
12852   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
12853   "fadd %2,%0"
12854   [(set_attr "type" "dfp_arith")
12855    (set_attr "fp_mode" "double")])
12857 (define_expand "subdf3"
12858   [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
12859         (minus:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
12860                   (match_operand:DF 2 "fp_arith_reg_operand" "")))]
12861   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
12863   if (TARGET_SH4 || TARGET_SH2A_DOUBLE)
12864     {
12865       emit_insn (gen_subdf3_i (operands[0], operands[1], operands[2]));
12866       DONE;
12867     }
12870 (define_insn "*subdf3_media"
12871   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12872         (minus:DF (match_operand:DF 1 "fp_arith_reg_operand" "f")
12873                   (match_operand:DF 2 "fp_arith_reg_operand" "f")))]
12874   "TARGET_SHMEDIA_FPU"
12875   "fsub.d       %1, %2, %0"
12876   [(set_attr "type" "dfparith_media")])
12878 (define_insn "subdf3_i"
12879   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12880         (minus:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")
12881                   (match_operand:DF 2 "fp_arith_reg_operand" "f")))
12882    (clobber (reg:SI FPSCR_STAT_REG))
12883    (use (reg:SI FPSCR_MODES_REG))]
12884   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
12885   "fsub %2,%0"
12886   [(set_attr "type" "dfp_arith")
12887    (set_attr "fp_mode" "double")])
12889 (define_expand "muldf3"
12890   [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
12891         (mult:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
12892                  (match_operand:DF 2 "fp_arith_reg_operand" "")))]
12893   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
12895   if (TARGET_SH4 || TARGET_SH2A_DOUBLE)
12896     {
12897       emit_insn (gen_muldf3_i (operands[0], operands[1], operands[2]));
12898       DONE;
12899     }
12902 (define_insn "*muldf3_media"
12903   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12904         (mult:DF (match_operand:DF 1 "fp_arith_reg_operand" "%f")
12905                  (match_operand:DF 2 "fp_arith_reg_operand" "f")))]
12906   "TARGET_SHMEDIA_FPU"
12907   "fmul.d       %1, %2, %0"
12908   [(set_attr "type" "dfmul_media")])
12910 (define_insn "muldf3_i"
12911   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12912         (mult:DF (match_operand:DF 1 "fp_arith_reg_operand" "%0")
12913                  (match_operand:DF 2 "fp_arith_reg_operand" "f")))
12914    (clobber (reg:SI FPSCR_STAT_REG))
12915    (use (reg:SI FPSCR_MODES_REG))]
12916   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
12917   "fmul %2,%0"
12918   [(set_attr "type" "dfp_mul")
12919    (set_attr "fp_mode" "double")])
12921 (define_expand "divdf3"
12922   [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
12923         (div:DF (match_operand:DF 1 "fp_arith_reg_operand" "")
12924                 (match_operand:DF 2 "fp_arith_reg_operand" "")))]
12925   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
12927   if (TARGET_SH4 || TARGET_SH2A_DOUBLE)
12928     {
12929       emit_insn (gen_divdf3_i (operands[0], operands[1], operands[2]));
12930       DONE;
12931     }
12934 (define_insn "*divdf3_media"
12935   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12936         (div:DF (match_operand:DF 1 "fp_arith_reg_operand" "f")
12937                 (match_operand:DF 2 "fp_arith_reg_operand" "f")))]
12938   "TARGET_SHMEDIA_FPU"
12939   "fdiv.d       %1, %2, %0"
12940   [(set_attr "type" "dfdiv_media")])
12942 (define_insn "divdf3_i"
12943   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12944         (div:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")
12945                 (match_operand:DF 2 "fp_arith_reg_operand" "f")))
12946    (clobber (reg:SI FPSCR_STAT_REG))
12947    (use (reg:SI FPSCR_MODES_REG))]
12948   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
12949   "fdiv %2,%0"
12950   [(set_attr "type" "dfdiv")
12951    (set_attr "fp_mode" "double")])
12953 (define_insn "floatdidf2"
12954   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12955         (float:DF (match_operand:DI 1 "fp_arith_reg_operand" "f")))]
12956   "TARGET_SHMEDIA_FPU"
12957   "float.qd     %1, %0"
12958   [(set_attr "type" "dfpconv_media")])
12960 (define_expand "floatsidf2"
12961   [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
12962         (float:DF (match_operand:SI 1 "fpul_operand" "")))]
12963   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
12965   if (TARGET_SH4 || TARGET_SH2A_DOUBLE)
12966     {
12967       emit_insn (gen_floatsidf2_i (operands[0], operands[1]));
12968       DONE;
12969     }
12972 (define_insn "*floatsidf2_media"
12973   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12974         (float:DF (match_operand:SI 1 "fp_arith_reg_operand" "f")))]
12975   "TARGET_SHMEDIA_FPU"
12976   "float.ld     %1, %0"
12977   [(set_attr "type" "dfpconv_media")])
12979 (define_insn "floatsidf2_i"
12980   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
12981         (float:DF (match_operand:SI 1 "fpul_operand" "y")))
12982    (clobber (reg:SI FPSCR_STAT_REG))
12983    (use (reg:SI FPSCR_MODES_REG))]
12984   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
12985   "float        %1,%0"
12986   [(set_attr "type" "dfp_conv")
12987    (set_attr "fp_mode" "double")])
12989 (define_insn "fix_truncdfdi2"
12990   [(set (match_operand:DI 0 "fp_arith_reg_dest" "=f")
12991         (fix:DI (match_operand:DF 1 "fp_arith_reg_operand" "f")))]
12992   "TARGET_SHMEDIA_FPU"
12993   "ftrc.dq      %1, %0"
12994   [(set_attr "type" "dfpconv_media")])
12996 (define_expand "fix_truncdfsi2"
12997   [(set (match_operand:SI 0 "fpul_operand" "")
12998         (fix:SI (match_operand:DF 1 "fp_arith_reg_operand" "")))]
12999   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
13001   if (TARGET_SH4 || TARGET_SH2A_DOUBLE)
13002     {
13003       emit_insn (gen_fix_truncdfsi2_i (operands[0], operands[1]));
13004       DONE;
13005     }
13008 (define_insn "*fix_truncdfsi2_media"
13009   [(set (match_operand:SI 0 "fp_arith_reg_operand" "=f")
13010         (fix:SI (match_operand:DF 1 "fp_arith_reg_operand" "f")))]
13011   "TARGET_SHMEDIA_FPU"
13012   "ftrc.dl      %1, %0"
13013   [(set_attr "type" "dfpconv_media")])
13015 (define_insn "fix_truncdfsi2_i"
13016   [(set (match_operand:SI 0 "fpul_operand" "=y")
13017         (fix:SI (match_operand:DF 1 "fp_arith_reg_operand" "f")))
13018    (clobber (reg:SI FPSCR_STAT_REG))
13019    (use (reg:SI FPSCR_MODES_REG))]
13020   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
13021   "ftrc %1,%0"
13022   [(set_attr "type" "dfp_conv")
13023    (set_attr "dfp_comp" "no")
13024    (set_attr "fp_mode" "double")])
13026 (define_insn "cmpgtdf_t"
13027   [(set (reg:SI T_REG)
13028         (gt:SI (match_operand:DF 0 "fp_arith_reg_operand" "f")
13029                (match_operand:DF 1 "fp_arith_reg_operand" "f")))
13030    (clobber (reg:SI FPSCR_STAT_REG))
13031    (use (reg:SI FPSCR_MODES_REG))]
13032   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
13033   "fcmp/gt      %1,%0"
13034   [(set_attr "type" "dfp_cmp")
13035    (set_attr "fp_mode" "double")])
13037 (define_insn "cmpeqdf_t"
13038   [(set (reg:SI T_REG)
13039         (eq:SI (match_operand:DF 0 "fp_arith_reg_operand" "f")
13040                (match_operand:DF 1 "fp_arith_reg_operand" "f")))
13041    (clobber (reg:SI FPSCR_STAT_REG))
13042    (use (reg:SI FPSCR_MODES_REG))]
13043   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
13044   "fcmp/eq      %1,%0"
13045   [(set_attr "type" "dfp_cmp")
13046    (set_attr "fp_mode" "double")])
13048 (define_insn "*ieee_ccmpeqdf_t"
13049   [(set (reg:SI T_REG)
13050         (ior:SI (reg:SI T_REG)
13051                 (eq:SI (match_operand:DF 0 "fp_arith_reg_operand" "f")
13052                        (match_operand:DF 1 "fp_arith_reg_operand" "f"))))
13053    (clobber (reg:SI FPSCR_STAT_REG))
13054    (use (reg:SI FPSCR_MODES_REG))]
13055   "TARGET_IEEE && (TARGET_SH4 || TARGET_SH2A_DOUBLE)"
13057   return output_ieee_ccmpeq (insn, operands);
13059   [(set_attr "length" "4")
13060    (set_attr "fp_mode" "double")])
13062 (define_insn "cmpeqdf_media"
13063   [(set (match_operand:SI 0 "register_operand" "=r")
13064         (eq:SI (match_operand:DF 1 "fp_arith_reg_operand" "f")
13065                (match_operand:DF 2 "fp_arith_reg_operand" "f")))]
13066   "TARGET_SHMEDIA_FPU"
13067   "fcmpeq.d     %1,%2,%0"
13068   [(set_attr "type" "fcmp_media")])
13070 (define_insn "cmpgtdf_media"
13071   [(set (match_operand:SI 0 "register_operand" "=r")
13072         (gt:SI (match_operand:DF 1 "fp_arith_reg_operand" "f")
13073                (match_operand:DF 2 "fp_arith_reg_operand" "f")))]
13074   "TARGET_SHMEDIA_FPU"
13075   "fcmpgt.d     %1,%2,%0"
13076   [(set_attr "type" "fcmp_media")])
13078 (define_insn "cmpgedf_media"
13079   [(set (match_operand:SI 0 "register_operand" "=r")
13080         (ge:SI (match_operand:DF 1 "fp_arith_reg_operand" "f")
13081                (match_operand:DF 2 "fp_arith_reg_operand" "f")))]
13082   "TARGET_SHMEDIA_FPU"
13083   "fcmpge.d     %1,%2,%0"
13084   [(set_attr "type" "fcmp_media")])
13086 (define_insn "cmpundf_media"
13087   [(set (match_operand:SI 0 "register_operand" "=r")
13088         (unordered:SI (match_operand:DF 1 "fp_arith_reg_operand" "f")
13089                       (match_operand:DF 2 "fp_arith_reg_operand" "f")))]
13090   "TARGET_SHMEDIA_FPU"
13091   "fcmpun.d     %1,%2,%0"
13092   [(set_attr "type" "fcmp_media")])
13094 (define_expand "cbranchdf4"
13095   [(set (pc)
13096         (if_then_else (match_operator 0 "sh_float_comparison_operator"
13097                        [(match_operand:DF 1 "arith_operand" "")
13098                         (match_operand:DF 2 "arith_operand" "")])
13099                       (match_operand 3 "" "")
13100                       (pc)))]
13101   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
13103   if (TARGET_SHMEDIA)
13104     emit_jump_insn (gen_cbranchfp4_media (operands[0], operands[1], operands[2],
13105                                           operands[3]));
13106   else
13107     sh_emit_compare_and_branch (operands, DFmode);
13108   DONE;
13111 (define_expand "negdf2"
13112   [(set (match_operand:DF 0 "fp_arith_reg_operand")
13113         (neg:DF (match_operand:DF 1 "fp_arith_reg_operand")))]
13114   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU")
13116 (define_insn "*negdf2_media"
13117   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
13118         (neg:DF (match_operand:DF 1 "fp_arith_reg_operand" "f")))]
13119   "TARGET_SHMEDIA_FPU"
13120   "fneg.d       %1, %0"
13121   [(set_attr "type" "fmove_media")])
13123 (define_insn "*negdf2_i"
13124   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
13125         (neg:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))]
13126   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
13127   "fneg %0"
13128   [(set_attr "type" "fmove")])
13130 (define_expand "sqrtdf2"
13131   [(set (match_operand:DF 0 "fp_arith_reg_operand")
13132         (sqrt:DF (match_operand:DF 1 "fp_arith_reg_operand")))]
13133   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
13135   if (TARGET_SH4 || TARGET_SH2A_DOUBLE)
13136     {
13137       emit_insn (gen_sqrtdf2_i (operands[0], operands[1]));
13138       DONE;
13139     }
13142 (define_insn "*sqrtdf2_media"
13143   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
13144         (sqrt:DF (match_operand:DF 1 "fp_arith_reg_operand" "f")))]
13145   "TARGET_SHMEDIA_FPU"
13146   "fsqrt.d      %1, %0"
13147   [(set_attr "type" "dfdiv_media")])
13149 (define_insn "sqrtdf2_i"
13150   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
13151         (sqrt:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))
13152    (clobber (reg:SI FPSCR_STAT_REG))
13153    (use (reg:SI FPSCR_MODES_REG))]
13154   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
13155   "fsqrt        %0"
13156   [(set_attr "type" "dfdiv")
13157    (set_attr "fp_mode" "double")])
13159 (define_expand "absdf2"
13160   [(set (match_operand:DF 0 "fp_arith_reg_operand")
13161         (abs:DF (match_operand:DF 1 "fp_arith_reg_operand")))]
13162   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU")
13164 (define_insn "*absdf2_media"
13165   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
13166         (abs:DF (match_operand:DF 1 "fp_arith_reg_operand" "f")))]
13167   "TARGET_SHMEDIA_FPU"
13168   "fabs.d       %1, %0"
13169   [(set_attr "type" "fmove_media")])
13171 (define_insn "*absdf2_i"
13172   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
13173         (abs:DF (match_operand:DF 1 "fp_arith_reg_operand" "0")))]
13174   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
13175   "fabs %0"
13176   [(set_attr "type" "fmove")])
13178 (define_expand "extendsfdf2"
13179   [(set (match_operand:DF 0 "fp_arith_reg_operand" "")
13180         (float_extend:DF (match_operand:SF 1 "fpul_operand" "")))]
13181   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
13183   if (TARGET_SH4 || TARGET_SH2A_DOUBLE)
13184     {
13185       emit_insn (gen_extendsfdf2_i4 (operands[0], operands[1]));
13186       DONE;
13187     }
13190 (define_insn "*extendsfdf2_media"
13191   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
13192         (float_extend:DF (match_operand:SF 1 "fp_arith_reg_operand" "f")))]
13193   "TARGET_SHMEDIA_FPU"
13194   "fcnv.sd      %1, %0"
13195   [(set_attr "type" "dfpconv_media")])
13197 (define_insn "extendsfdf2_i4"
13198   [(set (match_operand:DF 0 "fp_arith_reg_operand" "=f")
13199         (float_extend:DF (match_operand:SF 1 "fpul_operand" "y")))
13200    (clobber (reg:SI FPSCR_STAT_REG))
13201    (use (reg:SI FPSCR_MODES_REG))]
13202   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
13203   "fcnvsd  %1,%0"
13204   [(set_attr "type" "fp")
13205    (set_attr "fp_mode" "double")])
13207 (define_expand "truncdfsf2"
13208   [(set (match_operand:SF 0 "fpul_operand" "")
13209         (float_truncate:SF (match_operand:DF 1 "fp_arith_reg_operand" "")))]
13210   "(TARGET_SH4 || TARGET_SH2A_DOUBLE) || TARGET_SHMEDIA_FPU"
13212   if (TARGET_SH4 || TARGET_SH2A_DOUBLE)
13213     {
13214       emit_insn (gen_truncdfsf2_i4 (operands[0], operands[1]));
13215       DONE;
13216     }
13219 (define_insn "*truncdfsf2_media"
13220   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
13221         (float_truncate:SF (match_operand:DF 1 "fp_arith_reg_operand" "f")))]
13222   "TARGET_SHMEDIA_FPU"
13223   "fcnv.ds      %1, %0"
13224   [(set_attr "type" "dfpconv_media")])
13226 (define_insn "truncdfsf2_i4"
13227   [(set (match_operand:SF 0 "fpul_operand" "=y")
13228         (float_truncate:SF (match_operand:DF 1 "fp_arith_reg_operand" "f")))
13229    (clobber (reg:SI FPSCR_STAT_REG))
13230    (use (reg:SI FPSCR_MODES_REG))]
13231   "(TARGET_SH4 || TARGET_SH2A_DOUBLE)"
13232   "fcnvds  %1,%0"
13233   [(set_attr "type" "fp")
13234    (set_attr "fp_mode" "double")])
13236 ;; -------------------------------------------------------------------------
13237 ;; Bit field extract patterns.
13238 ;; -------------------------------------------------------------------------
13240 ;; These give better code for packed bitfields,  because they allow
13241 ;; auto-increment addresses to be generated.
13243 (define_expand "insv"
13244   [(set (zero_extract:SI (match_operand:QI 0 "memory_operand" "")
13245                          (match_operand:SI 1 "immediate_operand" "")
13246                          (match_operand:SI 2 "immediate_operand" ""))
13247         (match_operand:SI 3 "general_operand" ""))]
13248   "TARGET_SH1 && TARGET_BIG_ENDIAN"
13250   rtx addr_target, orig_address, shift_reg, qi_val;
13251   HOST_WIDE_INT bitsize, size, v = 0;
13252   rtx x = operands[3];
13254   if (TARGET_SH2A && TARGET_BITOPS
13255       && (satisfies_constraint_Sbw (operands[0])
13256           || satisfies_constraint_Sbv (operands[0]))
13257       && satisfies_constraint_M (operands[1])
13258       && satisfies_constraint_K03 (operands[2]))
13259     {
13260       if (satisfies_constraint_N (operands[3]))
13261         {
13262           emit_insn (gen_bclr_m2a (operands[0], operands[2]));
13263           DONE;
13264         }
13265       else if (satisfies_constraint_M (operands[3]))
13266         {
13267           emit_insn (gen_bset_m2a (operands[0], operands[2]));
13268           DONE;
13269         }
13270       else if ((REG_P (operands[3]) && REGNO (operands[3]) == T_REG)
13271                 && satisfies_constraint_M (operands[1]))
13272         {
13273           emit_insn (gen_bst_m2a (operands[0], operands[2]));
13274           DONE;
13275         }
13276       else if (REG_P (operands[3])
13277                && satisfies_constraint_M (operands[1]))
13278         {
13279           emit_insn (gen_bld_reg (operands[3], const0_rtx));
13280           emit_insn (gen_bst_m2a (operands[0], operands[2]));
13281           DONE;
13282         }
13283     }
13284   /* ??? expmed doesn't care for non-register predicates.  */
13285   if (! memory_operand (operands[0], VOIDmode)
13286       || ! immediate_operand (operands[1], VOIDmode)
13287       || ! immediate_operand (operands[2], VOIDmode)
13288       || ! general_operand (x, VOIDmode))
13289     FAIL;
13290   /* If this isn't a 16 / 24 / 32 bit field, or if
13291      it doesn't start on a byte boundary, then fail.  */
13292   bitsize = INTVAL (operands[1]);
13293   if (bitsize < 16 || bitsize > 32 || bitsize % 8 != 0
13294       || (INTVAL (operands[2]) % 8) != 0)
13295     FAIL;
13297   size = bitsize / 8;
13298   orig_address = XEXP (operands[0], 0);
13299   shift_reg = gen_reg_rtx (SImode);
13300   if (CONST_INT_P (x))
13301     {
13302       v = INTVAL (x);
13303       qi_val = force_reg (QImode, GEN_INT (trunc_int_for_mode (v, QImode)));
13304     }
13305   else
13306     {
13307       emit_insn (gen_movsi (shift_reg, operands[3]));
13308       qi_val = gen_rtx_SUBREG (QImode, shift_reg, 3);
13309     }
13310   addr_target = copy_addr_to_reg (plus_constant (Pmode,
13311                                                  orig_address, size - 1));
13313   operands[0] = replace_equiv_address (operands[0], addr_target);
13314   emit_insn (gen_movqi (operands[0], qi_val));
13316   while (size -= 1)
13317     {
13318       if (CONST_INT_P (x))
13319         qi_val
13320           = force_reg (QImode, GEN_INT (trunc_int_for_mode (v >>= 8, QImode)));
13321       else
13322         {
13323           emit_insn (gen_lshrsi3_k (shift_reg, shift_reg, GEN_INT (8)));
13324           qi_val = gen_rtx_SUBREG (QImode, shift_reg, 3);
13325         }
13326       emit_insn (gen_addsi3 (addr_target, addr_target, constm1_rtx));
13327       emit_insn (gen_movqi (operands[0], qi_val));
13328     }
13330   DONE;
13333 (define_insn "movua"
13334   [(set (match_operand:SI 0 "register_operand" "=z")
13335         (unspec:SI [(match_operand:BLK 1 "unaligned_load_operand" "Sua>")]
13336                    UNSPEC_MOVUA))]
13337   "TARGET_SH4A"
13338   "movua.l      %1,%0"
13339   [(set_attr "type" "movua")])
13341 ;; We shouldn't need this, but cse replaces increments with references
13342 ;; to other regs before flow has a chance to create post_inc
13343 ;; addressing modes, and only postreload's cse_move2add brings the
13344 ;; increments back to a usable form.
13345 (define_peephole2
13346   [(set (match_operand:SI 0 "register_operand" "")
13347         (sign_extract:SI (mem:SI (match_operand:SI 1 "register_operand" ""))
13348                          (const_int 32) (const_int 0)))
13349    (set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))]
13350   "TARGET_SH4A && REGNO (operands[0]) != REGNO (operands[1])"
13351   [(set (match_operand:SI 0 "register_operand" "")
13352         (sign_extract:SI (mem:SI (post_inc:SI
13353                                   (match_operand:SI 1 "register_operand" "")))
13354                          (const_int 32) (const_int 0)))]
13355   "")
13357 (define_expand "extv"
13358   [(set (match_operand:SI 0 "register_operand" "")
13359         (sign_extract:SI (match_operand:QI 1 "unaligned_load_operand" "")
13360                          (match_operand 2 "const_int_operand" "")
13361                          (match_operand 3 "const_int_operand" "")))]
13362   "TARGET_SH4A || TARGET_SH2A"
13364   if (TARGET_SH2A && TARGET_BITOPS
13365       && (satisfies_constraint_Sbw (operands[1])
13366           || satisfies_constraint_Sbv (operands[1]))
13367       && satisfies_constraint_M (operands[2])
13368       && satisfies_constraint_K03 (operands[3]))
13369    {
13370       emit_insn (gen_bldsign_m2a (operands[1], operands[3]));
13371       if (REGNO (operands[0]) != T_REG)
13372         emit_insn (gen_movsi (operands[0], gen_rtx_REG (SImode, T_REG)));
13373       DONE;
13374    }
13375   if (TARGET_SH4A
13376       && INTVAL (operands[2]) == 32
13377       && INTVAL (operands[3]) == 0
13378       && MEM_P (operands[1]) && MEM_ALIGN (operands[1]) < 32)
13379     {
13380       rtx src = adjust_address (operands[1], BLKmode, 0);
13381       set_mem_size (src, 4);
13382       emit_insn (gen_movua (operands[0], src));
13383       DONE;
13384     }
13386   FAIL;
13389 (define_expand "extzv"
13390   [(set (match_operand:SI 0 "register_operand" "")
13391         (zero_extract:SI (match_operand:QI 1 "unaligned_load_operand" "")
13392                          (match_operand 2 "const_int_operand" "")
13393                          (match_operand 3 "const_int_operand" "")))]
13394   "TARGET_SH4A || TARGET_SH2A"
13396   if (TARGET_SH2A && TARGET_BITOPS
13397       && (satisfies_constraint_Sbw (operands[1])
13398           || satisfies_constraint_Sbv (operands[1]))
13399       && satisfies_constraint_M (operands[2])
13400       && satisfies_constraint_K03 (operands[3]))
13401     {
13402       emit_insn (gen_bld_m2a (operands[1], operands[3]));
13403       if (REGNO (operands[0]) != T_REG)
13404         emit_insn (gen_movsi (operands[0], gen_rtx_REG (SImode, T_REG)));
13405       DONE;
13406     }
13407   if (TARGET_SH4A
13408       && INTVAL (operands[2]) == 32
13409       && INTVAL (operands[3]) == 0
13410       && MEM_P (operands[1]) && MEM_ALIGN (operands[1]) < 32)
13411     {
13412       rtx src = adjust_address (operands[1], BLKmode, 0);
13413       set_mem_size (src, 4);
13414       emit_insn (gen_movua (operands[0], src));
13415       DONE;
13416     }
13418   FAIL;
13421 ;; SH2A instructions for bitwise operations.
13422 ;; FIXME: Convert multiple instruction insns to insn_and_split.
13423 ;; FIXME: Use iterators to fold at least and,xor,or insn variations.
13425 ;; Clear a bit in a memory location.
13426 (define_insn "bclr_m2a"
13427   [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
13428         (and:QI
13429             (not:QI (ashift:QI (const_int 1)
13430                         (match_operand:QI 1 "const_int_operand" "K03,K03")))
13431             (match_dup 0)))]
13432   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
13433   "@
13434         bclr.b  %1,%0
13435         bclr.b  %1,@(0,%t0)"
13436 [(set_attr "length" "4,4")])
13438 (define_insn "bclrmem_m2a"
13439   [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
13440         (and:QI (match_dup 0)
13441                 (match_operand:QI 1 "const_int_operand" "Psz,Psz")))]
13442   "TARGET_SH2A && satisfies_constraint_Psz (operands[1]) && TARGET_BITOPS"
13443   "@
13444         bclr.b  %W1,%0
13445         bclr.b  %W1,@(0,%t0)"
13446   [(set_attr "length" "4,4")])
13448 ;; Set a bit in a memory location.
13449 (define_insn "bset_m2a"
13450   [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
13451         (ior:QI
13452             (ashift:QI (const_int 1)
13453                        (match_operand:QI 1 "const_int_operand" "K03,K03"))
13454             (match_dup 0)))]
13455   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
13456   "@
13457         bset.b  %1,%0
13458         bset.b  %1,@(0,%t0)"
13459   [(set_attr "length" "4,4")])
13461 (define_insn "bsetmem_m2a"
13462   [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,Sbv")
13463         (ior:QI (match_dup 0)
13464                 (match_operand:QI 1 "const_int_operand" "Pso,Pso")))]
13465   "TARGET_SH2A && satisfies_constraint_Pso (operands[1]) && TARGET_BITOPS"
13466   "@
13467         bset.b  %V1,%0
13468         bset.b  %V1,@(0,%t0)"
13469   [(set_attr "length" "4,4")])
13471 ;;; Transfer the contents of the T bit to a specified bit of memory.
13472 (define_insn "bst_m2a"
13473   [(set (match_operand:QI 0 "bitwise_memory_operand" "+Sbw,m")
13474         (if_then_else (eq (reg:SI T_REG) (const_int 0))
13475             (and:QI
13476                 (not:QI (ashift:QI (const_int 1)
13477                         (match_operand:QI 1 "const_int_operand" "K03,K03")))
13478                 (match_dup 0))
13479             (ior:QI
13480                 (ashift:QI (const_int 1) (match_dup 1))
13481                 (match_dup 0))))]
13482   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
13483   "@
13484         bst.b   %1,%0
13485         bst.b   %1,@(0,%t0)"
13486   [(set_attr "length" "4")])
13488 ;; Store a specified bit of memory in the T bit.
13489 (define_insn "bld_m2a"
13490   [(set (reg:SI T_REG)
13491         (zero_extract:SI
13492             (match_operand:QI 0 "bitwise_memory_operand" "Sbw,Sbv")
13493             (const_int 1)
13494             (match_operand 1 "const_int_operand" "K03,K03")))]
13495   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
13496   "@
13497         bld.b   %1,%0
13498         bld.b   %1,@(0,%t0)"
13499   [(set_attr "length" "4,4")])
13501 ;; Store a specified bit of memory in the T bit.
13502 (define_insn "bldsign_m2a"
13503   [(set (reg:SI T_REG)
13504         (sign_extract:SI
13505             (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
13506             (const_int 1)
13507             (match_operand 1 "const_int_operand" "K03,K03")))]
13508   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
13509   "@
13510         bld.b   %1,%0
13511         bld.b   %1,@(0,%t0)"
13512   [(set_attr "length" "4,4")])
13514 ;; Store a specified bit of the LSB 8 bits of a register in the T bit.
13515 (define_insn "bld_reg"
13516   [(set (reg:SI T_REG)
13517         (zero_extract:SI (match_operand:SI 0 "arith_reg_operand" "r")
13518                          (const_int 1)
13519                          (match_operand 1 "const_int_operand" "K03")))]
13520   "TARGET_SH2A && satisfies_constraint_K03 (operands[1])"
13521   "bld  %1,%0")
13523 (define_insn "*bld_regqi"
13524   [(set (reg:SI T_REG)
13525         (zero_extract:SI (match_operand:QI 0 "arith_reg_operand" "r")
13526                          (const_int 1)
13527                          (match_operand 1 "const_int_operand" "K03")))]
13528   "TARGET_SH2A && satisfies_constraint_K03 (operands[1])"
13529   "bld  %1,%0")
13531 ;; Take logical and of a specified bit of memory with the T bit and
13532 ;; store its result in the T bit.
13533 (define_insn "band_m2a"
13534   [(set (reg:SI T_REG)
13535         (and:SI (reg:SI T_REG)
13536                 (zero_extract:SI
13537                     (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
13538                     (const_int 1)
13539                     (match_operand 1 "const_int_operand" "K03,K03"))))]
13540   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
13541   "@
13542         band.b  %1,%0
13543         band.b  %1,@(0,%t0)"
13544   [(set_attr "length" "4,4")])
13546 (define_insn "bandreg_m2a"
13547   [(set (match_operand:SI 0 "register_operand" "=r,r")
13548         (and:SI (zero_extract:SI
13549                     (match_operand:QI 1 "bitwise_memory_operand" "Sbw,Sbv")
13550                     (const_int 1)
13551                     (match_operand 2 "const_int_operand" "K03,K03"))
13552                 (match_operand:SI 3 "register_operand" "r,r")))]
13553   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[2])"
13555   static const char* alt[] =
13556   {
13557        "band.b  %2,%1"          "\n"
13558     "   movt    %0",
13560        "band.b  %2,@(0,%t1)"    "\n"
13561     "   movt    %0"
13562   };
13563   return alt[which_alternative];
13565   [(set_attr "length" "6,6")])
13567 ;; Take logical or of a specified bit of memory with the T bit and
13568 ;; store its result in the T bit.
13569 (define_insn "bor_m2a"
13570   [(set (reg:SI T_REG)
13571         (ior:SI (reg:SI T_REG)
13572                 (zero_extract:SI
13573                     (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
13574                     (const_int 1)
13575                     (match_operand 1 "const_int_operand" "K03,K03"))))]
13576   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
13577   "@
13578         bor.b   %1,%0
13579         bor.b   %1,@(0,%t0)"
13580   [(set_attr "length" "4,4")])
13582 (define_insn "borreg_m2a"
13583   [(set (match_operand:SI 0 "register_operand" "=r,r")
13584         (ior:SI (zero_extract:SI
13585                     (match_operand:QI 1 "bitwise_memory_operand" "Sbw,Sbv")
13586                     (const_int 1)
13587                     (match_operand 2 "const_int_operand" "K03,K03"))
13588                 (match_operand:SI 3 "register_operand" "=r,r")))]
13589   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[2])"
13591   static const char* alt[] =
13592   {
13593        "bor.b   %2,%1"          "\n"
13594     "   movt    %0",
13596        "bor.b   %2,@(0,%t1)"    "\n"
13597     "   movt    %0"
13598   };
13599   return alt[which_alternative];
13601   [(set_attr "length" "6,6")])
13603 ;; Take exclusive or of a specified bit of memory with the T bit and
13604 ;; store its result in the T bit.
13605 (define_insn "bxor_m2a"
13606   [(set (reg:SI T_REG)
13607         (xor:SI (reg:SI T_REG)
13608                 (zero_extract:SI
13609                     (match_operand:QI 0 "bitwise_memory_operand" "Sbw,m")
13610                     (const_int 1)
13611                     (match_operand 1 "const_int_operand" "K03,K03"))))]
13612   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[1])"
13613   "@
13614         bxor.b  %1,%0
13615         bxor.b  %1,@(0,%t0)"
13616   [(set_attr "length" "4,4")])
13618 (define_insn "bxorreg_m2a"
13619   [(set (match_operand:SI 0 "register_operand" "=r,r")
13620         (xor:SI (zero_extract:SI
13621                     (match_operand:QI 1 "bitwise_memory_operand" "Sbw,Sbv")
13622                     (const_int 1)
13623                     (match_operand 2 "const_int_operand" "K03,K03"))
13624                 (match_operand:SI 3 "register_operand" "=r,r")))]
13625   "TARGET_SH2A && TARGET_BITOPS && satisfies_constraint_K03 (operands[2])"
13627   static const char* alt[] =
13628   {
13629        "bxor.b  %2,%1"          "\n"
13630     "   movt    %0",
13632        "bxor.b  %2,@(0,%t1)"    "\n"
13633     "   movt    %0"
13634   };
13635   return alt[which_alternative];
13637   [(set_attr "length" "6,6")])
13639 ;; -------------------------------------------------------------------------
13640 ;; Peepholes
13641 ;; -------------------------------------------------------------------------
13642 ;; This matches cases where the bit in a memory location is set.
13643 (define_peephole2
13644   [(set (match_operand:SI 0 "register_operand")
13645         (sign_extend:SI (match_operand:QI 1 "bitwise_memory_operand")))
13646    (set (match_dup 0)
13647         (ior:SI (match_dup 0)
13648         (match_operand:SI 2 "const_int_operand")))
13649    (set (match_dup 1)
13650         (match_operand 3 "arith_reg_operand"))]
13651   "TARGET_SH2A && TARGET_BITOPS
13652    && satisfies_constraint_Pso (operands[2])
13653    && REGNO (operands[0]) == REGNO (operands[3])"
13654   [(set (match_dup 1)
13655         (ior:QI (match_dup 1) (match_dup 2)))]
13656   "")
13658 ;; This matches cases where the bit in a memory location is cleared.
13659 (define_peephole2
13660   [(set (match_operand:SI 0 "register_operand")
13661         (sign_extend:SI (match_operand:QI 1 "bitwise_memory_operand")))
13662    (set (match_dup 0)
13663         (and:SI (match_dup 0)
13664         (match_operand:SI 2 "const_int_operand")))
13665    (set (match_dup 1)
13666         (match_operand 3 "arith_reg_operand"))]
13667   "TARGET_SH2A && TARGET_BITOPS
13668    && satisfies_constraint_Psz (operands[2])
13669    && REGNO (operands[0]) == REGNO (operands[3])"
13670   [(set (match_dup 1)
13671         (and:QI (match_dup 1) (match_dup 2)))]
13672   "")
13674 ;; This matches cases where a stack pointer increment at the start of the
13675 ;; epilogue combines with a stack slot read loading the return value.
13676 (define_peephole
13677   [(set (match_operand:SI 0 "arith_reg_operand" "")
13678         (mem:SI (match_operand:SI 1 "arith_reg_operand" "")))
13679    (set (match_dup 1) (plus:SI (match_dup 1) (const_int 4)))]
13680   "TARGET_SH1 && REGNO (operands[1]) != REGNO (operands[0])"
13681   "mov.l        @%1+,%0")
13683 ;; See the comment on the dt combiner pattern above.
13684 (define_peephole
13685   [(set (match_operand:SI 0 "arith_reg_operand" "=r")
13686         (plus:SI (match_dup 0)
13687                  (const_int -1)))
13688    (set (reg:SI T_REG)
13689         (eq:SI (match_dup 0) (const_int 0)))]
13690   "TARGET_SH2"
13691   "dt   %0")
13693 ;; The following peepholes fold load sequences for which reload was not
13694 ;; able to generate a displacement addressing move insn.
13695 ;; This can happen when reload has to transform a move insn 
13696 ;; without displacement into one with displacement.  Or when reload can't
13697 ;; fit a displacement into the insn's constraints.  In the latter case, the
13698 ;; load destination reg remains at r0, which reload compensates by inserting
13699 ;; another mov insn.
13701 ;; Fold sequence:
13702 ;;      mov #54,r0
13703 ;;      mov.{b,w} @(r0,r15),r0
13704 ;;      mov r0,r3
13705 ;; into:
13706 ;;      mov.{b,w} @(54,r15),r3
13708 (define_peephole2
13709   [(set (match_operand:SI 0 "arith_reg_dest" "")
13710         (match_operand:SI 1 "const_int_operand" ""))
13711    (set (match_operand:SI 2 "arith_reg_dest" "")
13712         (sign_extend:SI
13713          (mem:QI (plus:SI (match_dup 0)
13714                           (match_operand:SI 3 "arith_reg_operand" "")))))
13715    (set (match_operand:QI 4 "arith_reg_dest" "")
13716         (match_operand:QI 5 "arith_reg_operand" ""))]
13717   "TARGET_SH2A
13718    && sh_legitimate_index_p (QImode, operands[1], true, true)
13719    && REGNO (operands[2]) == REGNO (operands[5])
13720    && peep2_reg_dead_p (3, operands[5])"
13721   [(set (match_dup 4) (mem:QI (plus:SI (match_dup 3) (match_dup 1))))]
13722   "")
13724 (define_peephole2
13725   [(set (match_operand:SI 0 "arith_reg_dest" "")
13726         (match_operand:SI 1 "const_int_operand" ""))
13727    (set (match_operand:SI 2 "arith_reg_dest" "")
13728         (sign_extend:SI
13729          (mem:HI (plus:SI (match_dup 0)
13730                           (match_operand:SI 3 "arith_reg_operand" "")))))
13731    (set (match_operand:HI 4 "arith_reg_dest" "")
13732         (match_operand:HI 5 "arith_reg_operand" ""))]
13733   "TARGET_SH2A
13734    && sh_legitimate_index_p (HImode, operands[1], true, true)
13735    && REGNO (operands[2]) == REGNO (operands[5])
13736    && peep2_reg_dead_p (3, operands[5])"
13737   [(set (match_dup 4) (mem:HI (plus:SI (match_dup 3) (match_dup 1))))]
13738   "")
13740 ;; Fold sequence:
13741 ;;      mov #54,r0
13742 ;;      mov.{b,w} @(r0,r15),r1
13743 ;; into:
13744 ;;      mov.{b,w} @(54,r15),r1
13746 (define_peephole2
13747   [(set (match_operand:SI 0 "arith_reg_dest" "")
13748         (match_operand:SI 1 "const_int_operand" ""))
13749    (set (match_operand:SI 2 "arith_reg_dest" "")
13750          (sign_extend:SI
13751          (mem:QI (plus:SI (match_dup 0)
13752                           (match_operand:SI 3 "arith_reg_operand" "")))))]
13753   "TARGET_SH2A
13754    && sh_legitimate_index_p (QImode, operands[1], true, true)
13755    && (peep2_reg_dead_p (2, operands[0])
13756        || REGNO (operands[0]) == REGNO (operands[2]))"
13757   [(set (match_dup 2)
13758         (sign_extend:SI (mem:QI (plus:SI (match_dup 3) (match_dup 1)))))]
13759   "")
13761 (define_peephole2
13762   [(set (match_operand:SI 0 "arith_reg_dest" "")
13763         (match_operand:SI 1 "const_int_operand" ""))
13764    (set (match_operand:SI 2 "arith_reg_dest" "")
13765          (sign_extend:SI
13766          (mem:HI (plus:SI (match_dup 0)
13767                           (match_operand:SI 3 "arith_reg_operand" "")))))]
13768   "TARGET_SH2A
13769    && sh_legitimate_index_p (HImode, operands[1], true, true)
13770    && (peep2_reg_dead_p (2, operands[0])
13771        || REGNO (operands[0]) == REGNO (operands[2]))"
13772   [(set (match_dup 2)
13773         (sign_extend:SI (mem:HI (plus:SI (match_dup 3) (match_dup 1)))))]
13774   "")
13776 ;; Fold sequence:
13777 ;;      mov.{b,w} @(r0,r15),r0
13778 ;;      mov r0,r3
13779 ;; into:
13780 ;;      mov.{b,w} @(r0,r15),r3
13782 ;; This can happen when initially a displacement address is picked, where
13783 ;; the destination reg is fixed to r0, and then the address is transformed
13784 ;; into 'r0 + reg'.
13785 (define_peephole2
13786   [(set (match_operand:SI 0 "arith_reg_dest" "")
13787         (sign_extend:SI
13788          (mem:QI (plus:SI (match_operand:SI 1 "arith_reg_operand" "")
13789                           (match_operand:SI 2 "arith_reg_operand" "")))))
13790    (set (match_operand:QI 3 "arith_reg_dest" "")
13791         (match_operand:QI 4 "arith_reg_operand" ""))]
13792   "TARGET_SH1
13793    && REGNO (operands[0]) == REGNO (operands[4])
13794    && peep2_reg_dead_p (2, operands[0])"
13795   [(set (match_dup 3)
13796         (mem:QI (plus:SI (match_dup 1) (match_dup 2))))]
13797   "")
13799 (define_peephole2
13800   [(set (match_operand:SI 0 "arith_reg_dest" "")
13801         (sign_extend:SI
13802          (mem:HI (plus:SI (match_operand:SI 1 "arith_reg_operand" "")
13803                           (match_operand:SI 2 "arith_reg_operand" "")))))
13804    (set (match_operand:HI 3 "arith_reg_dest" "")
13805         (match_operand:HI 4 "arith_reg_operand" ""))]
13806   "TARGET_SH1
13807    && REGNO (operands[0]) == REGNO (operands[4])
13808    && peep2_reg_dead_p (2, operands[0])"
13809   [(set (match_dup 3)
13810         (mem:HI (plus:SI (match_dup 1) (match_dup 2))))]
13811   "")
13813 (define_peephole
13814   [(set (match_operand:SI 0 "register_operand" "=r")
13815         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
13816    (set (mem:SF (match_dup 0))
13817         (match_operand:SF 2 "general_movsrc_operand" ""))]
13818   "TARGET_SH1 && REGNO (operands[0]) == 0
13819    && ((REG_P (operands[2]) && REGNO (operands[2]) < 16)
13820        || (GET_CODE (operands[2]) == SUBREG
13821            && REGNO (SUBREG_REG (operands[2])) < 16))
13822    && reg_unused_after (operands[0], insn)"
13823   "mov.l        %2,@(%0,%1)")
13825 (define_peephole
13826   [(set (match_operand:SI 0 "register_operand" "=r")
13827         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
13828    (set (match_operand:SF 2 "general_movdst_operand" "")
13830         (mem:SF (match_dup 0)))]
13831   "TARGET_SH1 && REGNO (operands[0]) == 0
13832    && ((REG_P (operands[2]) && REGNO (operands[2]) < 16)
13833        || (GET_CODE (operands[2]) == SUBREG
13834            && REGNO (SUBREG_REG (operands[2])) < 16))
13835    && reg_unused_after (operands[0], insn)"
13836   "mov.l        @(%0,%1),%2")
13838 (define_peephole
13839   [(set (match_operand:SI 0 "register_operand" "=r")
13840         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
13841    (set (mem:SF (match_dup 0))
13842         (match_operand:SF 2 "general_movsrc_operand" ""))]
13843   "TARGET_SH2E && REGNO (operands[0]) == 0
13844    && ((REG_P (operands[2])
13845         && FP_OR_XD_REGISTER_P (REGNO (operands[2])))
13846        || (GET_CODE (operands[2]) == SUBREG
13847            && FP_OR_XD_REGISTER_P (REGNO (SUBREG_REG (operands[2])))))
13848    && reg_unused_after (operands[0], insn)"
13849   "fmov{.s|}    %2,@(%0,%1)")
13851 (define_peephole
13852   [(set (match_operand:SI 0 "register_operand" "=r")
13853         (plus:SI (match_dup 0) (match_operand:SI 1 "register_operand" "r")))
13854    (set (match_operand:SF 2 "general_movdst_operand" "")
13856         (mem:SF (match_dup 0)))]
13857   "TARGET_SH2E && REGNO (operands[0]) == 0
13858    && ((REG_P (operands[2])
13859         && FP_OR_XD_REGISTER_P (REGNO (operands[2])))
13860        || (GET_CODE (operands[2]) == SUBREG
13861            && FP_OR_XD_REGISTER_P (REGNO (SUBREG_REG (operands[2])))))
13862    && reg_unused_after (operands[0], insn)"
13863   "fmov{.s|}    @(%0,%1),%2")
13865 ;; Switch to a new stack with its address in sp_switch (a SYMBOL_REF).
13866 (define_insn "sp_switch_1"
13867   [(set (reg:SI SP_REG) (unspec_volatile [(match_operand:SI 0 "" "")]
13868     UNSPECV_SP_SWITCH_B))]
13869   "TARGET_SH1"
13871   return       "mov.l   r0,@-r15"       "\n"
13872          "      mov.l   %0,r0"          "\n"
13873          "      mov.l   @r0,r0"         "\n"
13874          "      mov.l   r15,@-r0"       "\n"
13875          "      mov     r0,r15";
13877   [(set_attr "length" "10")])
13879 ;; Switch back to the original stack for interrupt functions with the
13880 ;; sp_switch attribute.
13881 (define_insn "sp_switch_2"
13882   [(unspec_volatile [(const_int 0)]
13883     UNSPECV_SP_SWITCH_E)]
13884   "TARGET_SH1"
13886   return       "mov.l   @r15,r15"       "\n"
13887          "      mov.l   @r15+,r0";
13889   [(set_attr "length" "4")])
13891 ;; -------------------------------------------------------------------------
13892 ;; Integer vector moves
13893 ;; -------------------------------------------------------------------------
13895 (define_expand "movv8qi"
13896   [(set (match_operand:V8QI 0 "general_movdst_operand" "")
13897         (match_operand:V8QI 1 "general_movsrc_operand" ""))]
13898   "TARGET_SHMEDIA"
13900   prepare_move_operands (operands, V8QImode);
13903 (define_insn "movv8qi_i"
13904   [(set (match_operand:V8QI 0 "general_movdst_operand" "=r,r,r,rl,m")
13905         (match_operand:V8QI 1 "general_movsrc_operand" "r,I16CssZ,nW,m,rlZ"))]
13906   "TARGET_SHMEDIA
13907    && (register_operand (operands[0], V8QImode)
13908        || sh_register_operand (operands[1], V8QImode))"
13909   "@
13910         add     %1, r63, %0
13911         movi    %1, %0
13912         #
13913         ld%M1.q %m1, %0
13914         st%M0.q %m0, %N1"
13915   [(set_attr "type"   "arith_media,arith_media,*,load_media,store_media")
13916    (set_attr "length" "4,4,16,4,4")])
13918 (define_split
13919   [(set (match_operand:V8QI 0 "arith_reg_dest" "")
13920         (subreg:V8QI (const_int 0) 0))]
13921   "TARGET_SHMEDIA"
13922   [(set (match_dup 0)
13923         (const_vector:V8QI [(const_int 0) (const_int 0) (const_int 0)
13924                             (const_int 0) (const_int 0) (const_int 0)
13925                             (const_int 0) (const_int 0)]))])
13927 (define_split
13928   [(set (match_operand 0 "arith_reg_dest" "")
13929         (match_operand 1 "sh_rep_vec" ""))]
13930   "TARGET_SHMEDIA && reload_completed
13931    && GET_MODE (operands[0]) == GET_MODE (operands[1])
13932    && sh_vector_mode_supported_p (GET_MODE (operands[0]))
13933    && GET_MODE_SIZE (GET_MODE (operands[0])) == 8
13934    && (XVECEXP (operands[1], 0, 0) != const0_rtx
13935        || XVECEXP (operands[1], 0, 1) != const0_rtx)
13936    && (XVECEXP (operands[1], 0, 0) != constm1_rtx
13937        || XVECEXP (operands[1], 0, 1) != constm1_rtx)"
13938   [(set (match_dup 0) (match_dup 1))
13939    (match_dup 2)]
13941   int unit_size = GET_MODE_UNIT_SIZE (GET_MODE (operands[1]));
13942   rtx elt1 = XVECEXP (operands[1], 0, 1);
13944   if (unit_size > 2)
13945     operands[2] = gen_mshflo_l (operands[0], operands[0], operands[0]);
13946   else
13947     {
13948       if (unit_size < 2)
13949         operands[0] = gen_rtx_REG (V4HImode, true_regnum (operands[0]));
13950       operands[2] = gen_mperm_w0 (operands[0], operands[0]);
13951     }
13952   operands[0] = gen_rtx_REG (DImode, true_regnum (operands[0]));
13953   operands[1] = XVECEXP (operands[1], 0, 0);
13954   if (unit_size < 2)
13955     {
13956       if (CONST_INT_P (operands[1]) && CONST_INT_P (elt1))
13957         operands[1]
13958           = GEN_INT (TARGET_LITTLE_ENDIAN
13959                      ? (INTVAL (operands[1]) & 0xff) + (INTVAL (elt1) << 8)
13960                      : (INTVAL (operands[1]) << 8) + (INTVAL (elt1) & 0xff));
13961       else
13962         {
13963           operands[0] = gen_rtx_REG (V2QImode, true_regnum (operands[0]));
13964           operands[1]
13965             = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, operands[1], elt1));
13966         }
13967     }
13970 (define_split
13971   [(set (match_operand 0 "arith_reg_dest" "")
13972         (match_operand 1 "sh_const_vec" ""))]
13973   "TARGET_SHMEDIA && reload_completed
13974    && GET_MODE (operands[0]) == GET_MODE (operands[1])
13975    && sh_vector_mode_supported_p (GET_MODE (operands[0]))"
13976   [(set (match_dup 0) (match_dup 1))]
13978   rtx v = operands[1];
13979   machine_mode new_mode
13980     = mode_for_size (GET_MODE_BITSIZE (GET_MODE (v)), MODE_INT, 0);
13982   operands[0] = gen_rtx_REG (new_mode, true_regnum (operands[0]));
13983   operands[1]
13984     = simplify_subreg (new_mode, operands[1], GET_MODE (operands[1]), 0);
13987 (define_expand "movv2hi"
13988   [(set (match_operand:V2HI 0 "general_movdst_operand" "")
13989         (match_operand:V2HI 1 "general_movsrc_operand" ""))]
13990   "TARGET_SHMEDIA"
13992   prepare_move_operands (operands, V2HImode);
13995 (define_insn "movv2hi_i"
13996   [(set (match_operand:V2HI 0 "general_movdst_operand" "=r,r,r,rl,m")
13997         (match_operand:V2HI 1 "general_movsrc_operand" "r,I16CssZ,nW,m,rlZ"))]
13998   "TARGET_SHMEDIA
13999    && (register_operand (operands[0], V2HImode)
14000        || sh_register_operand (operands[1], V2HImode))"
14001   "@
14002         add.l   %1, r63, %0
14003         movi    %1, %0
14004         #
14005         ld%M1.l %m1, %0
14006         st%M0.l %m0, %N1"
14007   [(set_attr "type"   "arith_media,arith_media,*,load_media,store_media")
14008    (set_attr "length" "4,4,16,4,4")
14009    (set (attr "highpart")
14010         (cond [(match_test "sh_contains_memref_p (insn)")
14011                (const_string "user")]
14012               (const_string "ignore")))])
14014 (define_expand "movv4hi"
14015   [(set (match_operand:V4HI 0 "general_movdst_operand" "")
14016         (match_operand:V4HI 1 "general_movsrc_operand" ""))]
14017   "TARGET_SHMEDIA"
14019   prepare_move_operands (operands, V4HImode);
14022 (define_insn "movv4hi_i"
14023   [(set (match_operand:V4HI 0 "general_movdst_operand" "=r,r,r,rl,m")
14024         (match_operand:V4HI 1 "general_movsrc_operand" "r,I16CssZ,nW,m,rlZ"))]
14025   "TARGET_SHMEDIA
14026    && (register_operand (operands[0], V4HImode)
14027        || sh_register_operand (operands[1], V4HImode))"
14028   "@
14029         add     %1, r63, %0
14030         movi    %1, %0
14031         #
14032         ld%M1.q %m1, %0
14033         st%M0.q %m0, %N1"
14034   [(set_attr "type"   "arith_media,arith_media,*,load_media,store_media")
14035    (set_attr "length" "4,4,16,4,4")
14036    (set_attr "highpart" "depend")])
14038 (define_expand "movv2si"
14039   [(set (match_operand:V2SI 0 "general_movdst_operand" "")
14040         (match_operand:V2SI 1 "general_movsrc_operand" ""))]
14041   "TARGET_SHMEDIA"
14043   prepare_move_operands (operands, V2SImode);
14046 (define_insn "movv2si_i"
14047   [(set (match_operand:V2SI 0 "general_movdst_operand" "=r,r,r,rl,m")
14048         (match_operand:V2SI 1 "general_movsrc_operand" "r,I16CssZ,nW,m,rlZ"))]
14049   "TARGET_SHMEDIA
14050    && (register_operand (operands[0], V2SImode)
14051        || sh_register_operand (operands[1], V2SImode))"
14052   "@
14053         add     %1, r63, %0
14054         #
14055         #
14056         ld%M1.q %m1, %0
14057         st%M0.q %m0, %N1"
14058   [(set_attr "type"   "arith_media,arith_media,*,load_media,store_media")
14059    (set_attr "length" "4,4,16,4,4")
14060    (set_attr "highpart" "depend")])
14062 ;; -------------------------------------------------------------------------
14063 ;; Multimedia Intrinsics
14064 ;; -------------------------------------------------------------------------
14066 (define_insn "absv2si2"
14067   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14068         (abs:V2SI (match_operand:V2SI 1 "arith_reg_operand" "r")))]
14069   "TARGET_SHMEDIA"
14070   "mabs.l       %1, %0"
14071   [(set_attr "type" "mcmp_media")
14072    (set_attr "highpart" "depend")])
14074 (define_insn "absv4hi2"
14075   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14076         (abs:V4HI (match_operand:V4HI 1 "arith_reg_operand" "r")))]
14077   "TARGET_SHMEDIA"
14078   "mabs.w       %1, %0"
14079   [(set_attr "type" "mcmp_media")
14080    (set_attr "highpart" "depend")])
14082 (define_insn "addv2si3"
14083   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14084         (plus:V2SI (match_operand:V2SI 1 "arith_reg_operand" "%r")
14085                    (match_operand:V2SI 2 "arith_reg_operand" "r")))]
14086   "TARGET_SHMEDIA"
14087   "madd.l       %1, %2, %0"
14088   [(set_attr "type" "arith_media")
14089    (set_attr "highpart" "depend")])
14091 (define_insn "addv4hi3"
14092   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14093         (plus:V4HI (match_operand:V4HI 1 "arith_reg_operand" "%r")
14094                    (match_operand:V4HI 2 "arith_reg_operand" "r")))]
14095   "TARGET_SHMEDIA"
14096   "madd.w       %1, %2, %0"
14097   [(set_attr "type" "arith_media")
14098    (set_attr "highpart" "depend")])
14100 (define_insn_and_split "addv2hi3"
14101   [(set (match_operand:V2HI 0 "arith_reg_dest" "=r")
14102         (plus:V2HI (match_operand:V2HI 1 "extend_reg_operand" "%r")
14103                    (match_operand:V2HI 2 "extend_reg_operand" "r")))]
14104   "TARGET_SHMEDIA"
14105   "#"
14106   "TARGET_SHMEDIA"
14107   [(const_int 0)]
14109   rtx src0 = simplify_gen_subreg (V4HImode, operands[1], V2HImode, 0);
14110   rtx src1 = simplify_gen_subreg (V4HImode, operands[2], V2HImode, 0);
14111   rtx v4hi_dst = simplify_gen_subreg (V4HImode, operands[0], V2HImode, 0);
14112   rtx di_dst = simplify_gen_subreg (DImode, operands[0], V2HImode, 0);
14113   rtx si_dst = simplify_gen_subreg (SImode, operands[0], V2HImode, 0);
14115   emit_insn (gen_addv4hi3 (v4hi_dst, src0, src1));
14116   emit_insn (gen_truncdisi2 (si_dst, di_dst));
14117   DONE;
14119   [(set_attr "highpart" "must_split")])
14121 (define_insn "ssaddv2si3"
14122   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14123         (ss_plus:V2SI (match_operand:V2SI 1 "arith_reg_operand" "%r")
14124                       (match_operand:V2SI 2 "arith_reg_operand" "r")))]
14125   "TARGET_SHMEDIA"
14126   "madds.l      %1, %2, %0"
14127   [(set_attr "type" "mcmp_media")
14128    (set_attr "highpart" "depend")])
14130 (define_insn "usaddv8qi3"
14131   [(set (match_operand:V8QI 0 "arith_reg_dest" "=r")
14132         (us_plus:V8QI (match_operand:V8QI 1 "arith_reg_operand" "%r")
14133                       (match_operand:V8QI 2 "arith_reg_operand" "r")))]
14134   "TARGET_SHMEDIA"
14135   "madds.ub     %1, %2, %0"
14136   [(set_attr "type" "mcmp_media")
14137    (set_attr "highpart" "depend")])
14139 (define_insn "ssaddv4hi3"
14140   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14141         (ss_plus:V4HI (match_operand:V4HI 1 "arith_reg_operand" "%r")
14142                       (match_operand:V4HI 2 "arith_reg_operand" "r")))]
14143   "TARGET_SHMEDIA"
14144   "madds.w      %1, %2, %0"
14145   [(set_attr "type" "mcmp_media")
14146    (set_attr "highpart" "depend")])
14148 (define_insn "negcmpeqv8qi"
14149   [(set (match_operand:V8QI 0 "arith_reg_dest" "=r")
14150         (neg:V8QI (eq:V8QI
14151                     (match_operand:V8QI 1 "arith_reg_or_0_operand" "%rZ")
14152                     (match_operand:V8QI 2 "arith_reg_or_0_operand" "rZ"))))]
14153   "TARGET_SHMEDIA"
14154   "mcmpeq.b     %N1, %N2, %0"
14155   [(set_attr "type" "mcmp_media")
14156    (set_attr "highpart" "depend")])
14158 (define_insn "negcmpeqv2si"
14159   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14160         (neg:V2SI (eq:V2SI
14161                     (match_operand:V2SI 1 "arith_reg_or_0_operand" "%rZ")
14162                     (match_operand:V2SI 2 "arith_reg_or_0_operand" "rZ"))))]
14163   "TARGET_SHMEDIA"
14164   "mcmpeq.l     %N1, %N2, %0"
14165   [(set_attr "type" "mcmp_media")
14166    (set_attr "highpart" "depend")])
14168 (define_insn "negcmpeqv4hi"
14169   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14170         (neg:V4HI (eq:V4HI
14171                     (match_operand:V4HI 1 "arith_reg_or_0_operand" "%rZ")
14172                     (match_operand:V4HI 2 "arith_reg_or_0_operand" "rZ"))))]
14173   "TARGET_SHMEDIA"
14174   "mcmpeq.w     %N1, %N2, %0"
14175   [(set_attr "type" "mcmp_media")
14176    (set_attr "highpart" "depend")])
14178 (define_insn "negcmpgtuv8qi"
14179   [(set (match_operand:V8QI 0 "arith_reg_dest" "=r")
14180         (neg:V8QI (gtu:V8QI
14181                     (match_operand:V8QI 1 "arith_reg_or_0_operand" "%rZ")
14182                     (match_operand:V8QI 2 "arith_reg_or_0_operand" "rZ"))))]
14183   "TARGET_SHMEDIA"
14184   "mcmpgt.ub    %N1, %N2, %0"
14185   [(set_attr "type" "mcmp_media")
14186    (set_attr "highpart" "depend")])
14188 (define_insn "negcmpgtv2si"
14189   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14190         (neg:V2SI (gt:V2SI
14191                     (match_operand:V2SI 1 "arith_reg_or_0_operand" "%rZ")
14192                     (match_operand:V2SI 2 "arith_reg_or_0_operand" "rZ"))))]
14193   "TARGET_SHMEDIA"
14194   "mcmpgt.l     %N1, %N2, %0"
14195   [(set_attr "type" "mcmp_media")
14196    (set_attr "highpart" "depend")])
14198 (define_insn "negcmpgtv4hi"
14199   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14200         (neg:V4HI (gt:V4HI
14201                     (match_operand:V4HI 1 "arith_reg_or_0_operand" "%rZ")
14202                     (match_operand:V4HI 2 "arith_reg_or_0_operand" "rZ"))))]
14203   "TARGET_SHMEDIA"
14204   "mcmpgt.w     %N1, %N2, %0"
14205   [(set_attr "type" "mcmp_media")
14206    (set_attr "highpart" "depend")])
14208 (define_insn "mcmv"
14209   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
14210         (ior:DI (and:DI (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14211                         (match_operand:DI 2 "arith_reg_operand" "r"))
14212                 (and:DI (match_operand:DI 3 "arith_reg_operand" "0")
14213                         (not:DI (match_dup 2)))))]
14214   "TARGET_SHMEDIA"
14215   "mcmv %N1, %2, %0"
14216   [(set_attr "type" "arith_media")
14217    (set_attr "highpart" "depend")])
14219 (define_insn "mcnvs_lw"
14220   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14221         (vec_concat:V4HI
14222          (ss_truncate:V2HI (match_operand:V2SI 1 "arith_reg_or_0_operand" "rZ"))
14223          (ss_truncate:V2HI
14224            (match_operand:V2SI 2 "arith_reg_or_0_operand" "rZ"))))]
14225   "TARGET_SHMEDIA"
14226   "mcnvs.lw     %N1, %N2, %0"
14227   [(set_attr "type" "mcmp_media")])
14229 (define_insn "mcnvs_wb"
14230   [(set (match_operand:V8QI 0 "arith_reg_dest" "=r")
14231         (vec_concat:V8QI
14232          (ss_truncate:V4QI (match_operand:V4HI 1 "arith_reg_or_0_operand" "rZ"))
14233          (ss_truncate:V4QI
14234            (match_operand:V4HI 2 "arith_reg_or_0_operand" "rZ"))))]
14235   "TARGET_SHMEDIA"
14236   "mcnvs.wb     %N1, %N2, %0"
14237   [(set_attr "type" "mcmp_media")])
14239 (define_insn "mcnvs_wub"
14240   [(set (match_operand:V8QI 0 "arith_reg_dest" "=r")
14241         (vec_concat:V8QI
14242          (us_truncate:V4QI (match_operand:V4HI 1 "arith_reg_or_0_operand" "rZ"))
14243          (us_truncate:V4QI
14244            (match_operand:V4HI 2 "arith_reg_or_0_operand" "rZ"))))]
14245   "TARGET_SHMEDIA"
14246   "mcnvs.wub    %N1, %N2, %0"
14247   [(set_attr "type" "mcmp_media")])
14249 (define_insn "mextr_rl"
14250   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
14251         (ior:DI (lshiftrt:DI (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14252                              (match_operand:HI 3 "mextr_bit_offset" "i"))
14253                 (ashift:DI (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")
14254                            (match_operand:HI 4 "mextr_bit_offset" "i"))))]
14255   "TARGET_SHMEDIA && INTVAL (operands[3]) + INTVAL (operands[4]) == 64"
14257   static char templ[21];
14258   sprintf (templ, "mextr%d      %%N1, %%N2, %%0",
14259            (int) INTVAL (operands[3]) >> 3);
14260   return templ;
14262   [(set_attr "type" "arith_media")])
14264 (define_insn "*mextr_lr"
14265   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
14266         (ior:DI (ashift:DI (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14267                            (match_operand:HI 3 "mextr_bit_offset" "i"))
14268                 (lshiftrt:DI (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")
14269                              (match_operand:HI 4 "mextr_bit_offset" "i"))))]
14270   "TARGET_SHMEDIA && INTVAL (operands[3]) + INTVAL (operands[4]) == 64"
14272   static char templ[21];
14273   sprintf (templ, "mextr%d      %%N2, %%N1, %%0",
14274            (int) INTVAL (operands[4]) >> 3);
14275   return templ;
14277   [(set_attr "type" "arith_media")])
14279 ; mextrN can be modelled with vec_select / vec_concat, but the selection
14280 ; vector then varies depending on endianness.
14281 (define_expand "mextr1"
14282   [(match_operand:DI 0 "arith_reg_dest" "")
14283    (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14284    (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")]
14285   "TARGET_SHMEDIA"
14287   emit_insn (gen_mextr_rl (operands[0], operands[1], operands[2],
14288                            GEN_INT (1 * 8), GEN_INT (7 * 8)));
14289   DONE;
14292 (define_expand "mextr2"
14293   [(match_operand:DI 0 "arith_reg_dest" "")
14294    (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14295    (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")]
14296   "TARGET_SHMEDIA"
14298   emit_insn (gen_mextr_rl (operands[0], operands[1], operands[2],
14299                            GEN_INT (2 * 8), GEN_INT (6 * 8)));
14300   DONE;
14303 (define_expand "mextr3"
14304   [(match_operand:DI 0 "arith_reg_dest" "")
14305    (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14306    (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")]
14307   "TARGET_SHMEDIA"
14309   emit_insn (gen_mextr_rl (operands[0], operands[1], operands[2],
14310                            GEN_INT (3 * 8), GEN_INT (5 * 8)));
14311   DONE;
14314 (define_expand "mextr4"
14315   [(match_operand:DI 0 "arith_reg_dest" "")
14316    (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14317    (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")]
14318   "TARGET_SHMEDIA"
14320   emit_insn (gen_mextr_rl (operands[0], operands[1], operands[2],
14321                            GEN_INT (4 * 8), GEN_INT (4 * 8)));
14322   DONE;
14325 (define_expand "mextr5"
14326   [(match_operand:DI 0 "arith_reg_dest" "")
14327    (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14328    (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")]
14329   "TARGET_SHMEDIA"
14331   emit_insn (gen_mextr_rl (operands[0], operands[1], operands[2],
14332                            GEN_INT (5 * 8), GEN_INT (3 * 8)));
14333   DONE;
14336 (define_expand "mextr6"
14337   [(match_operand:DI 0 "arith_reg_dest" "")
14338    (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14339    (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")]
14340   "TARGET_SHMEDIA"
14342   emit_insn (gen_mextr_rl (operands[0], operands[1], operands[2],
14343                            GEN_INT (6 * 8), GEN_INT (2 * 8)));
14344   DONE;
14347 (define_expand "mextr7"
14348   [(match_operand:DI 0 "arith_reg_dest" "")
14349    (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14350    (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")]
14351   "TARGET_SHMEDIA"
14353   emit_insn (gen_mextr_rl (operands[0], operands[1], operands[2],
14354                            GEN_INT (7 * 8), GEN_INT (1 * 8)));
14355   DONE;
14358 (define_expand "mmacfx_wl"
14359   [(match_operand:V2SI 0 "arith_reg_dest" "")
14360    (match_operand:V2HI 1 "extend_reg_operand" "")
14361    (match_operand:V2HI 2 "extend_reg_operand" "")
14362    (match_operand:V2SI 3 "arith_reg_operand" "")]
14363   "TARGET_SHMEDIA"
14365   emit_insn (gen_mmacfx_wl_i (operands[0], operands[3],
14366                               operands[1], operands[2]));
14367   DONE;
14370 ;; This could be highpart ignore if it only had inputs 2 or 3, but input 1
14371 ;; is depend
14372 (define_insn "mmacfx_wl_i"
14373   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14374         (ss_plus:V2SI
14375          (match_operand:V2SI 1 "arith_reg_operand" "0")
14376          (ss_truncate:V2SI
14377           (ashift:V2DI
14378            (sign_extend:V2DI
14379             (mult:V2SI
14380              (sign_extend:V2SI (match_operand:V2HI 2 "extend_reg_operand" "r"))
14381              (sign_extend:V2SI (match_operand:V2HI 3 "extend_reg_operand" "r"))))
14382            (const_int 1)))))]
14383   "TARGET_SHMEDIA"
14384   "mmacfx.wl    %2, %3, %0"
14385   [(set_attr "type" "mac_media")
14386    (set_attr "highpart" "depend")])
14388 (define_expand "mmacnfx_wl"
14389   [(match_operand:V2SI 0 "arith_reg_dest" "")
14390    (match_operand:V2HI 1 "extend_reg_operand" "")
14391    (match_operand:V2HI 2 "extend_reg_operand" "")
14392    (match_operand:V2SI 3 "arith_reg_operand" "")]
14393   "TARGET_SHMEDIA"
14395   emit_insn (gen_mmacnfx_wl_i (operands[0], operands[3],
14396                                operands[1], operands[2]));
14397   DONE;
14400 (define_insn "mmacnfx_wl_i"
14401   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14402         (ss_minus:V2SI
14403          (match_operand:V2SI 1 "arith_reg_operand" "0")
14404          (ss_truncate:V2SI
14405           (ashift:V2DI
14406            (sign_extend:V2DI
14407             (mult:V2SI
14408              (sign_extend:V2SI (match_operand:V2HI 2 "extend_reg_operand" "r"))
14409              (sign_extend:V2SI (match_operand:V2HI 3 "extend_reg_operand" "r"))))
14410            (const_int 1)))))]
14411   "TARGET_SHMEDIA"
14412   "mmacnfx.wl   %2, %3, %0"
14413   [(set_attr "type" "mac_media")
14414    (set_attr "highpart" "depend")])
14416 (define_insn "mulv2si3"
14417   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14418         (mult:V2SI (match_operand:V2SI 1 "arith_reg_operand" "r")
14419                    (match_operand:V2SI 2 "arith_reg_operand" "r")))]
14420   "TARGET_SHMEDIA"
14421   "mmul.l       %1, %2, %0"
14422   [(set_attr "type" "d2mpy_media")
14423    (set_attr "highpart" "depend")])
14425 (define_insn "mulv4hi3"
14426   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14427         (mult:V4HI (match_operand:V4HI 1 "arith_reg_operand" "r")
14428                    (match_operand:V4HI 2 "arith_reg_operand" "r")))]
14429   "TARGET_SHMEDIA"
14430   "mmul.w       %1, %2, %0"
14431   [(set_attr "type" "dmpy_media")
14432    (set_attr "highpart" "depend")])
14434 (define_insn "mmulfx_l"
14435   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14436         (ss_truncate:V2SI
14437          (ashiftrt:V2DI
14438           (mult:V2DI
14439            (sign_extend:V2DI (match_operand:V2SI 1 "arith_reg_operand" "r"))
14440            (sign_extend:V2DI (match_operand:V2SI 2 "arith_reg_operand" "r")))
14441           (const_int 31))))]
14442   "TARGET_SHMEDIA"
14443   "mmulfx.l     %1, %2, %0"
14444   [(set_attr "type" "d2mpy_media")
14445    (set_attr "highpart" "depend")])
14447 (define_insn "mmulfx_w"
14448   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14449         (ss_truncate:V4HI
14450          (ashiftrt:V4SI
14451           (mult:V4SI
14452            (sign_extend:V4SI (match_operand:V4HI 1 "arith_reg_operand" "r"))
14453            (sign_extend:V4SI (match_operand:V4HI 2 "arith_reg_operand" "r")))
14454           (const_int 15))))]
14455   "TARGET_SHMEDIA"
14456   "mmulfx.w     %1, %2, %0"
14457   [(set_attr "type" "dmpy_media")
14458    (set_attr "highpart" "depend")])
14460 (define_insn "mmulfxrp_w"
14461   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14462         (ss_truncate:V4HI
14463          (ashiftrt:V4SI
14464           (plus:V4SI
14465            (mult:V4SI
14466             (sign_extend:V4SI (match_operand:V4HI 1 "arith_reg_operand" "r"))
14467             (sign_extend:V4SI (match_operand:V4HI 2 "arith_reg_operand" "r")))
14468            (const_int 16384))
14469           (const_int 15))))]
14470   "TARGET_SHMEDIA"
14471   "mmulfxrp.w   %1, %2, %0"
14472   [(set_attr "type" "dmpy_media")
14473    (set_attr "highpart" "depend")])
14476 (define_expand "mmulhi_wl"
14477   [(match_operand:V2SI 0 "arith_reg_dest" "")
14478    (match_operand:V4HI 1 "arith_reg_operand" "")
14479    (match_operand:V4HI 2 "arith_reg_operand" "")]
14480   "TARGET_SHMEDIA"
14482   emit_insn ((TARGET_LITTLE_ENDIAN ? gen_mmul23_wl : gen_mmul01_wl)
14483              (operands[0], operands[1], operands[2]));
14484   DONE;
14487 (define_expand "mmullo_wl"
14488   [(match_operand:V2SI 0 "arith_reg_dest" "")
14489    (match_operand:V4HI 1 "arith_reg_operand" "")
14490    (match_operand:V4HI 2 "arith_reg_operand" "")]
14491   "TARGET_SHMEDIA"
14493   emit_insn ((TARGET_LITTLE_ENDIAN ? gen_mmul01_wl : gen_mmul23_wl)
14494              (operands[0], operands[1], operands[2]));
14495   DONE;
14498 (define_insn "mmul23_wl"
14499   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14500         (vec_select:V2SI
14501          (mult:V4SI
14502           (sign_extend:V4SI (match_operand:V4HI 1 "arith_reg_operand" "r"))
14503           (sign_extend:V4SI (match_operand:V4HI 2 "arith_reg_operand" "r")))
14504          (parallel [(const_int 2) (const_int 3)])))]
14505   "TARGET_SHMEDIA"
14507   return (TARGET_LITTLE_ENDIAN
14508           ? "mmulhi.wl  %1, %2, %0"
14509           : "mmullo.wl  %1, %2, %0");
14511   [(set_attr "type" "dmpy_media")
14512    (set (attr "highpart")
14513         (cond [(eq_attr "endian" "big") (const_string "ignore")]
14514          (const_string "user")))])
14516 (define_insn "mmul01_wl"
14517   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14518         (vec_select:V2SI
14519          (mult:V4SI
14520           (sign_extend:V4SI (match_operand:V4HI 1 "arith_reg_operand" "r"))
14521           (sign_extend:V4SI (match_operand:V4HI 2 "arith_reg_operand" "r")))
14522          (parallel [(const_int 0) (const_int 1)])))]
14523   "TARGET_SHMEDIA"
14525   return (TARGET_LITTLE_ENDIAN
14526           ? "mmullo.wl  %1, %2, %0"
14527           : "mmulhi.wl  %1, %2, %0");
14529   [(set_attr "type" "dmpy_media")
14530    (set (attr "highpart")
14531         (cond [(eq_attr "endian" "little") (const_string "ignore")]
14532          (const_string "user")))])
14535 (define_expand "mmulsum_wq"
14536   [(match_operand:DI 0 "arith_reg_dest" "")
14537    (match_operand:V4HI 1 "arith_reg_operand" "")
14538    (match_operand:V4HI 2 "arith_reg_operand" "")
14539    (match_operand:DI 3 "arith_reg_operand" "")]
14540   "TARGET_SHMEDIA"
14542   emit_insn (gen_mmulsum_wq_i (operands[0], operands[3],
14543                                operands[1], operands[2]));
14544   DONE;
14547 (define_insn "mmulsum_wq_i"
14548   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
14549         (plus:DI (match_operand:DI 1 "arith_reg_operand" "0")
14550          (plus:DI
14551           (plus:DI
14552            (vec_select:DI
14553             (mult:V4DI
14554              (sign_extend:V4DI (match_operand:V4HI 2 "arith_reg_operand" "r"))
14555              (sign_extend:V4DI (match_operand:V4HI 3 "arith_reg_operand" "r")))
14556             (parallel [(const_int 0)]))
14557            (vec_select:DI (mult:V4DI (sign_extend:V4DI (match_dup 2))
14558                                      (sign_extend:V4DI (match_dup 3)))
14559                           (parallel [(const_int 1)])))
14560           (plus:DI
14561            (vec_select:DI (mult:V4DI (sign_extend:V4DI (match_dup 2))
14562                                      (sign_extend:V4DI (match_dup 3)))
14563                           (parallel [(const_int 2)]))
14564            (vec_select:DI (mult:V4DI (sign_extend:V4DI (match_dup 2))
14565                                      (sign_extend:V4DI (match_dup 3)))
14566                           (parallel [(const_int 3)]))))))]
14567   "TARGET_SHMEDIA"
14568   "mmulsum.wq   %2, %3, %0"
14569   [(set_attr "type" "mac_media")])
14571 (define_expand "mperm_w"
14572   [(match_operand:V4HI 0 "arith_reg_dest" "=r")
14573    (match_operand:V4HI 1 "arith_reg_operand" "r")
14574    (match_operand:QI 2 "extend_reg_or_0_operand" "rZ")]
14575   "TARGET_SHMEDIA"
14577   emit_insn ((TARGET_LITTLE_ENDIAN ? gen_mperm_w_little : gen_mperm_w_big)
14578              (operands[0], operands[1], operands[2]));
14579   DONE;
14582 ; This use of vec_select isn't exactly correct according to rtl.texi
14583 ; (because not constant), but it seems a straightforward extension.
14584 (define_insn "mperm_w_little"
14585   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14586         (vec_select:V4HI
14587          (match_operand:V4HI 1 "arith_reg_operand" "r")
14588          (parallel
14589           [(zero_extract:QI (match_operand:QI 2 "extend_reg_or_0_operand" "rZ")
14590                             (const_int 2) (const_int 0))
14591            (zero_extract:QI (match_dup 2) (const_int 2) (const_int 2))
14592            (zero_extract:QI (match_dup 2) (const_int 2) (const_int 4))
14593            (zero_extract:QI (match_dup 2) (const_int 2) (const_int 6))])))]
14594   "TARGET_SHMEDIA && TARGET_LITTLE_ENDIAN"
14595   "mperm.w      %1, %N2, %0"
14596   [(set_attr "type" "arith_media")])
14598 (define_insn "mperm_w_big"
14599   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14600         (vec_select:V4HI
14601          (match_operand:V4HI 1 "arith_reg_operand" "r")
14602          (parallel
14603           [(zero_extract:QI (not:QI (match_operand:QI 2
14604                                      "extend_reg_or_0_operand" "rZ"))
14605                             (const_int 2) (const_int 0))
14606            (zero_extract:QI (not:QI (match_dup 2)) (const_int 2) (const_int 2))
14607            (zero_extract:QI (not:QI (match_dup 2)) (const_int 2) (const_int 4))
14608            (zero_extract:QI (not:QI (match_dup 2))
14609                             (const_int 2) (const_int 6))])))]
14610   "TARGET_SHMEDIA && TARGET_BIG_ENDIAN"
14611   "mperm.w      %1, %N2, %0"
14612   [(set_attr "type" "arith_media")])
14614 (define_insn "mperm_w0"
14615   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14616         (vec_duplicate:V4HI (truncate:HI (match_operand 1
14617                                           "trunc_hi_operand" "r"))))]
14618   "TARGET_SHMEDIA"
14619   "mperm.w      %1, r63, %0"
14620   [(set_attr "type" "arith_media")
14621    (set_attr "highpart" "ignore")])
14623 (define_expand "msad_ubq"
14624   [(match_operand:DI 0 "arith_reg_dest" "")
14625    (match_operand:V8QI 1 "arith_reg_or_0_operand" "")
14626    (match_operand:V8QI 2 "arith_reg_or_0_operand" "")
14627    (match_operand:DI 3 "arith_reg_operand" "")]
14628   "TARGET_SHMEDIA"
14630   emit_insn (gen_msad_ubq_i (operands[0], operands[3],
14631                              operands[1], operands[2]));
14632   DONE;
14635 (define_insn "msad_ubq_i"
14636   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
14637         (plus:DI
14638          (plus:DI
14639           (plus:DI
14640            (plus:DI
14641             (match_operand:DI 1 "arith_reg_operand" "0")
14642             (abs:DI (vec_select:DI
14643                      (minus:V8DI
14644                       (zero_extend:V8DI
14645                        (match_operand:V8QI 2 "arith_reg_or_0_operand" "rZ"))
14646                       (zero_extend:V8DI
14647                        (match_operand:V8QI 3 "arith_reg_or_0_operand" "rZ")))
14648                      (parallel [(const_int 0)]))))
14649            (abs:DI (vec_select:DI (minus:V8DI (zero_extend:V8DI (match_dup 2))
14650                                               (zero_extend:V8DI (match_dup 3)))
14651                                   (parallel [(const_int 1)]))))
14652           (plus:DI
14653            (abs:DI (vec_select:DI (minus:V8DI (zero_extend:V8DI (match_dup 2))
14654                                               (zero_extend:V8DI (match_dup 3)))
14655                                   (parallel [(const_int 2)])))
14656            (abs:DI (vec_select:DI (minus:V8DI (zero_extend:V8DI (match_dup 2))
14657                                               (zero_extend:V8DI (match_dup 3)))
14658                                   (parallel [(const_int 3)])))))
14659          (plus:DI
14660           (plus:DI
14661            (abs:DI (vec_select:DI (minus:V8DI (zero_extend:V8DI (match_dup 2))
14662                                               (zero_extend:V8DI (match_dup 3)))
14663                                   (parallel [(const_int 4)])))
14664            (abs:DI (vec_select:DI (minus:V8DI (zero_extend:V8DI (match_dup 2))
14665                                               (zero_extend:V8DI (match_dup 3)))
14666                                   (parallel [(const_int 5)]))))
14667           (plus:DI
14668            (abs:DI (vec_select:DI (minus:V8DI (zero_extend:V8DI (match_dup 2))
14669                                               (zero_extend:V8DI (match_dup 3)))
14670                                   (parallel [(const_int 6)])))
14671            (abs:DI (vec_select:DI (minus:V8DI (zero_extend:V8DI (match_dup 2))
14672                                               (zero_extend:V8DI (match_dup 3)))
14673                                   (parallel [(const_int 7)])))))))]
14674   "TARGET_SHMEDIA"
14675   "msad.ubq     %N2, %N3, %0"
14676   [(set_attr "type" "mac_media")])
14678 (define_insn "mshalds_l"
14679   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14680         (ss_truncate:V2SI
14681          (ashift:V2DI
14682           (sign_extend:V2DI (match_operand:V2SI 1 "arith_reg_operand" "r"))
14683           (and:DI (match_operand:DI 2 "arith_reg_operand" "r")
14684                   (const_int 31)))))]
14685   "TARGET_SHMEDIA"
14686   "mshalds.l    %1, %2, %0"
14687   [(set_attr "type" "mcmp_media")
14688    (set_attr "highpart" "depend")])
14690 (define_insn "mshalds_w"
14691   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14692         (ss_truncate:V4HI
14693          (ashift:V4SI
14694           (sign_extend:V4SI (match_operand:V4HI 1 "arith_reg_operand" "r"))
14695           (and:DI (match_operand:DI 2 "arith_reg_operand" "r")
14696                   (const_int 15)))))]
14697   "TARGET_SHMEDIA"
14698   "mshalds.w    %1, %2, %0"
14699   [(set_attr "type" "mcmp_media")
14700    (set_attr "highpart" "depend")])
14702 (define_insn "ashrv2si3"
14703   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14704         (ashiftrt:V2SI (match_operand:V2SI 1 "arith_reg_operand" "r")
14705                        (match_operand:DI 2 "arith_reg_operand" "r")))]
14706   "TARGET_SHMEDIA"
14707   "mshard.l     %1, %2, %0"
14708   [(set_attr "type" "arith_media")
14709    (set_attr "highpart" "depend")])
14711 (define_insn "ashrv4hi3"
14712   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14713         (ashiftrt:V4HI (match_operand:V4HI 1 "arith_reg_operand" "r")
14714                        (match_operand:DI 2 "arith_reg_operand" "r")))]
14715   "TARGET_SHMEDIA"
14716   "mshard.w     %1, %2, %0"
14717   [(set_attr "type" "arith_media")
14718    (set_attr "highpart" "depend")])
14720 (define_insn "mshards_q"
14721   [(set (match_operand:HI 0 "arith_reg_dest" "=r")
14722         (ss_truncate:HI
14723          (ashiftrt:DI (match_operand:DI 1 "arith_reg_operand" "r")
14724                       (match_operand:DI 2 "arith_reg_or_0_operand" "rZ"))))]
14725   "TARGET_SHMEDIA"
14726   "mshards.q    %1, %N2, %0"
14727   [(set_attr "type" "mcmp_media")])
14729 (define_expand "mshfhi_b"
14730   [(match_operand:V8QI 0 "arith_reg_dest" "")
14731    (match_operand:V8QI 1 "arith_reg_or_0_operand" "rZ")
14732    (match_operand:V8QI 2 "arith_reg_or_0_operand" "rZ")]
14733   "TARGET_SHMEDIA"
14735   emit_insn ((TARGET_LITTLE_ENDIAN ? gen_mshf4_b : gen_mshf0_b)
14736              (operands[0], operands[1], operands[2]));
14737   DONE;
14740 (define_expand "mshflo_b"
14741   [(match_operand:V8QI 0 "arith_reg_dest" "")
14742    (match_operand:V8QI 1 "arith_reg_or_0_operand" "rZ")
14743    (match_operand:V8QI 2 "arith_reg_or_0_operand" "rZ")]
14744   "TARGET_SHMEDIA"
14746   emit_insn ((TARGET_LITTLE_ENDIAN ? gen_mshf0_b : gen_mshf4_b)
14747              (operands[0], operands[1], operands[2]));
14748   DONE;
14751 (define_insn "mshf4_b"
14752   [(set
14753     (match_operand:V8QI 0 "arith_reg_dest" "=r")
14754     (vec_select:V8QI
14755      (vec_concat:V16QI (match_operand:V8QI 1 "arith_reg_or_0_operand" "rZ")
14756                        (match_operand:V8QI 2 "arith_reg_or_0_operand" "rZ"))
14757      (parallel [(const_int 4) (const_int 12) (const_int 5) (const_int 13)
14758                 (const_int 6) (const_int 14) (const_int 7) (const_int 15)])))]
14759   "TARGET_SHMEDIA"
14761   return (TARGET_LITTLE_ENDIAN
14762           ? "mshfhi.b   %N1, %N2, %0"
14763           : "mshflo.b   %N1, %N2, %0");
14765   [(set_attr "type" "arith_media")
14766    (set (attr "highpart")
14767         (cond [(eq_attr "endian" "big") (const_string "ignore")]
14768          (const_string "user")))])
14770 (define_insn "mshf0_b"
14771   [(set
14772     (match_operand:V8QI 0 "arith_reg_dest" "=r")
14773     (vec_select:V8QI
14774      (vec_concat:V16QI (match_operand:V8QI 1 "arith_reg_or_0_operand" "rZ")
14775                        (match_operand:V8QI 2 "arith_reg_or_0_operand" "rZ"))
14776      (parallel [(const_int 0) (const_int 8) (const_int 1) (const_int 9)
14777                 (const_int 2) (const_int 10) (const_int 3) (const_int 11)])))]
14778   "TARGET_SHMEDIA"
14780   return (TARGET_LITTLE_ENDIAN
14781           ? "mshflo.b   %N1, %N2, %0"
14782           : "mshfhi.b   %N1, %N2, %0");
14784   [(set_attr "type" "arith_media")
14785    (set (attr "highpart")
14786         (cond [(eq_attr "endian" "little") (const_string "ignore")]
14787          (const_string "user")))])
14789 (define_expand "mshfhi_l"
14790   [(match_operand:V2SI 0 "arith_reg_dest" "")
14791    (match_operand:V2SI 1 "arith_reg_or_0_operand" "rZ")
14792    (match_operand:V2SI 2 "arith_reg_or_0_operand" "rZ")]
14793   "TARGET_SHMEDIA"
14795   emit_insn ((TARGET_LITTLE_ENDIAN ? gen_mshf4_l : gen_mshf0_l)
14796              (operands[0], operands[1], operands[2]));
14797   DONE;
14800 (define_expand "mshflo_l"
14801   [(match_operand:V2SI 0 "arith_reg_dest" "")
14802    (match_operand:V2SI 1 "arith_reg_or_0_operand" "rZ")
14803    (match_operand:V2SI 2 "arith_reg_or_0_operand" "rZ")]
14804   "TARGET_SHMEDIA"
14806   emit_insn ((TARGET_LITTLE_ENDIAN ? gen_mshf0_l : gen_mshf4_l)
14807              (operands[0], operands[1], operands[2]));
14808   DONE;
14811 (define_insn "mshf4_l"
14812   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14813         (vec_select:V2SI
14814          (vec_concat:V4SI (match_operand:V2SI 1 "arith_reg_or_0_operand" "rZ")
14815                           (match_operand:V2SI 2 "arith_reg_or_0_operand" "rZ"))
14816          (parallel [(const_int 1) (const_int 3)])))]
14817   "TARGET_SHMEDIA"
14819   return (TARGET_LITTLE_ENDIAN
14820           ? "mshfhi.l   %N1, %N2, %0"
14821           : "mshflo.l   %N1, %N2, %0");
14823   [(set_attr "type" "arith_media")
14824    (set (attr "highpart")
14825         (cond [(eq_attr "endian" "big") (const_string "ignore")]
14826          (const_string "user")))])
14828 (define_insn "mshf0_l"
14829   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
14830         (vec_select:V2SI
14831          (vec_concat:V4SI (match_operand:V2SI 1 "arith_reg_or_0_operand" "rZ")
14832                           (match_operand:V2SI 2 "arith_reg_or_0_operand" "rZ"))
14833          (parallel [(const_int 0) (const_int 2)])))]
14834   "TARGET_SHMEDIA"
14836   return (TARGET_LITTLE_ENDIAN
14837           ? "mshflo.l   %N1, %N2, %0"
14838           : "mshfhi.l   %N1, %N2, %0");
14840   [(set_attr "type" "arith_media")
14841    (set (attr "highpart")
14842         (cond [(eq_attr "endian" "little") (const_string "ignore")]
14843          (const_string "user")))])
14845 (define_expand "mshfhi_w"
14846   [(match_operand:V4HI 0 "arith_reg_dest" "")
14847    (match_operand:V4HI 1 "arith_reg_or_0_operand" "rZ")
14848    (match_operand:V4HI 2 "arith_reg_or_0_operand" "rZ")]
14849   "TARGET_SHMEDIA"
14851   emit_insn ((TARGET_LITTLE_ENDIAN ? gen_mshf4_w : gen_mshf0_w)
14852              (operands[0], operands[1], operands[2]));
14853   DONE;
14856 (define_expand "mshflo_w"
14857   [(match_operand:V4HI 0 "arith_reg_dest" "")
14858    (match_operand:V4HI 1 "arith_reg_or_0_operand" "rZ")
14859    (match_operand:V4HI 2 "arith_reg_or_0_operand" "rZ")]
14860   "TARGET_SHMEDIA"
14862   emit_insn ((TARGET_LITTLE_ENDIAN ? gen_mshf0_w : gen_mshf4_w)
14863              (operands[0], operands[1], operands[2]));
14864   DONE;
14867 (define_insn "mshf4_w"
14868   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14869         (vec_select:V4HI
14870          (vec_concat:V8HI (match_operand:V4HI 1 "arith_reg_or_0_operand" "rZ")
14871                           (match_operand:V4HI 2 "arith_reg_or_0_operand" "rZ"))
14872          (parallel [(const_int 2) (const_int 6) (const_int 3) (const_int 7)])))]
14873   "TARGET_SHMEDIA"
14875   return (TARGET_LITTLE_ENDIAN
14876           ? "mshfhi.w   %N1, %N2, %0"
14877           : "mshflo.w   %N1, %N2, %0");
14879   [(set_attr "type" "arith_media")
14880    (set (attr "highpart")
14881         (cond [(eq_attr "endian" "big") (const_string "ignore")]
14882          (const_string "user")))])
14884 (define_insn "mshf0_w"
14885   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14886         (vec_select:V4HI
14887          (vec_concat:V8HI (match_operand:V4HI 1 "arith_reg_or_0_operand" "rZ")
14888                           (match_operand:V4HI 2 "arith_reg_or_0_operand" "rZ"))
14889          (parallel [(const_int 0) (const_int 4) (const_int 1) (const_int 5)])))]
14890   "TARGET_SHMEDIA"
14892   return (TARGET_LITTLE_ENDIAN
14893           ? "mshflo.w   %N1, %N2, %0"
14894           : "mshfhi.w   %N1, %N2, %0");
14896   [(set_attr "type" "arith_media")
14897    (set (attr "highpart")
14898         (cond [(eq_attr "endian" "little") (const_string "ignore")]
14899          (const_string "user")))])
14901 (define_insn "mshflo_w_x"
14902   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
14903         (vec_select:V4HI
14904          (vec_concat:V4HI (match_operand:V2HI 1 "extend_reg_or_0_operand" "rZ")
14905                           (match_operand:V2HI 2 "extend_reg_or_0_operand" "rZ"))
14906          (parallel [(const_int 2) (const_int 0) (const_int 3) (const_int 1)])))]
14907   "TARGET_SHMEDIA"
14908   "mshflo.w     %N1, %N2, %0"
14909   [(set_attr "type" "arith_media")
14910    (set_attr "highpart" "ignore")])
14912 ;; These are useful to expand ANDs and as combiner patterns.
14913 (define_insn_and_split "mshfhi_l_di"
14914   [(set (match_operand:DI 0 "arith_reg_dest" "=r,f")
14915         (ior:DI (lshiftrt:DI (match_operand:DI 1 "arith_reg_or_0_operand" "rZ,f")
14916                              (const_int 32))
14917                 (and:DI (match_operand:DI 2 "arith_reg_or_0_operand" "rZ,?f")
14918                         (const_int -4294967296))))]
14919   "TARGET_SHMEDIA"
14920   "@
14921         mshfhi.l        %N1, %N2, %0
14922         #"
14923   "TARGET_SHMEDIA && reload_completed
14924    && ! GENERAL_REGISTER_P (true_regnum (operands[0]))"
14925   [(set (match_dup 3) (match_dup 4))
14926    (set (match_dup 5) (match_dup 6))]
14928   operands[3] = gen_lowpart (SImode, operands[0]);
14929   operands[4] = gen_highpart (SImode, operands[1]);
14930   operands[5] = gen_highpart (SImode, operands[0]);
14931   operands[6] = gen_highpart (SImode, operands[2]);
14933   [(set_attr "type" "arith_media")])
14935 (define_insn "*mshfhi_l_di_rev"
14936   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
14937         (ior:DI (and:DI (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14938                         (const_int -4294967296))
14939                 (lshiftrt:DI (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")
14940                              (const_int 32))))]
14941   "TARGET_SHMEDIA"
14942   "mshfhi.l     %N2, %N1, %0"
14943   [(set_attr "type" "arith_media")])
14945 (define_split
14946   [(set (match_operand:DI 0 "arith_reg_dest" "")
14947         (ior:DI (zero_extend:DI (match_operand:SI 1
14948                                               "extend_reg_or_0_operand" ""))
14949                 (and:DI (match_operand:DI 2 "arith_reg_or_0_operand" "")
14950                         (const_int -4294967296))))
14951    (clobber (match_operand:DI 3 "arith_reg_dest" ""))]
14952   "TARGET_SHMEDIA"
14953   [(const_int 0)]
14955   emit_insn (gen_ashldi3_media (operands[3],
14956                                 simplify_gen_subreg (DImode, operands[1],
14957                                                      SImode, 0),
14958                                 GEN_INT (32)));
14959   emit_insn (gen_mshfhi_l_di (operands[0], operands[3], operands[2]));
14960   DONE;
14963 (define_insn "mshflo_l_di"
14964   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
14965         (ior:DI (and:DI (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14966                         (const_int 4294967295))
14967                 (ashift:DI (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")
14968                            (const_int 32))))]
14970   "TARGET_SHMEDIA"
14971   "mshflo.l     %N1, %N2, %0"
14972   [(set_attr "type" "arith_media")
14973    (set_attr "highpart" "ignore")])
14975 (define_insn "*mshflo_l_di_rev"
14976   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
14977         (ior:DI (ashift:DI (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
14978                            (const_int 32))
14979                 (and:DI (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")
14980                         (const_int 4294967295))))]
14982   "TARGET_SHMEDIA"
14983   "mshflo.l     %N2, %N1, %0"
14984   [(set_attr "type" "arith_media")
14985    (set_attr "highpart" "ignore")])
14987 ;; Combiner pattern for trampoline initialization.
14988 (define_insn_and_split "*double_shori"
14989   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
14990         (ior:DI (ashift:DI (match_operand:DI 1 "arith_reg_operand" "0")
14991                            (const_int 32))
14992                 (match_operand:DI 2 "const_int_operand" "n")))]
14993   "TARGET_SHMEDIA
14994    && ! (INTVAL (operands[2]) & ~(unsigned HOST_WIDE_INT) 0xffffffffUL)"
14995   "#"
14996   "rtx_equal_p (operands[0], operands[1])"
14997   [(const_int 0)]
14999   HOST_WIDE_INT v = INTVAL (operands[2]);
15001   emit_insn (gen_shori_media (operands[0], operands[0], GEN_INT (v >> 16)));
15002   emit_insn (gen_shori_media (operands[0], operands[0], GEN_INT (v & 65535)));
15003   DONE;
15005   [(set_attr "highpart" "ignore")])
15007 (define_insn "*mshflo_l_di_x"
15008   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15009         (ior:DI (zero_extend:DI (match_operand:SI 1 "extend_reg_or_0_operand"
15010                                  "rZ"))
15011                 (ashift:DI (match_operand:DI 2 "arith_reg_or_0_operand" "rZ")
15012                            (const_int 32))))]
15013   "TARGET_SHMEDIA"
15014   "mshflo.l     %N1, %N2, %0"
15015   [(set_attr "type" "arith_media")
15016    (set_attr "highpart" "ignore")])
15018 (define_insn_and_split "concat_v2sf"
15019   [(set (match_operand:V2SF 0 "register_operand" "=r,f,f?")
15020 ;;      (vec_concat:V2SF (match_operand:SF 1 "register_operand" "rZ,0,f")
15021         (vec_concat:V2SF (match_operand:SF 1 "register_operand" "rZ,f,f")
15022                          (match_operand:SF 2 "register_operand" "rZ,f,f")))]
15023   "TARGET_SHMEDIA"
15024   "@
15025         mshflo.l        %N1, %N2, %0
15026         #
15027         #"
15028   "TARGET_SHMEDIA && reload_completed
15029    && ! GENERAL_REGISTER_P (true_regnum (operands[0]))"
15030   [(set (match_dup 3) (match_dup 1))
15031    (set (match_dup 4) (match_dup 2))]
15033   operands[3] = simplify_gen_subreg (SFmode, operands[0], V2SFmode, 0);
15034   operands[4] = simplify_gen_subreg (SFmode, operands[0], V2SFmode, 4);
15036   [(set_attr "type" "arith_media")
15037    (set_attr "highpart" "ignore")])
15039 (define_insn "*mshflo_l_di_x_rev"
15040   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15041         (ior:DI (ashift:DI (match_operand:DI 1 "arith_reg_or_0_operand" "rZ")
15042                            (const_int 32))
15043                 (zero_extend:DI
15044                   (match_operand:SI 2 "extend_reg_or_0_operand" "rZ"))))]
15045   "TARGET_SHMEDIA"
15046   "mshflo.l     %N2, %N1, %0"
15047   [(set_attr "type" "arith_media")
15048    (set_attr "highpart" "ignore")])
15050 (define_insn "ashlv2si3"
15051   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
15052         (ashift:V2SI (match_operand:V2SI 1 "arith_reg_operand" "r")
15053                      (match_operand:DI 2 "shift_count_reg_operand" "r")))]
15054   "TARGET_SHMEDIA"
15055   "mshlld.l     %1, %2, %0"
15056   [(set_attr "type" "arith_media")
15057    (set_attr "highpart" "depend")])
15059 (define_split
15060   [(set (match_operand 0 "any_register_operand" "")
15061         (match_operator 3 "shift_operator"
15062           [(match_operand 1 "any_register_operand" "")
15063            (match_operand 2 "shift_count_reg_operand" "")]))]
15064   "TARGET_SHMEDIA && ! register_operand (operands[2], VOIDmode)"
15065   [(set (match_dup 0) (match_dup 3))]
15067   rtx count = operands[2];
15068   machine_mode outer_mode = GET_MODE (operands[2]), inner_mode;
15070   while (GET_CODE (count) == ZERO_EXTEND || GET_CODE (count) == SIGN_EXTEND
15071          || (GET_CODE (count) == SUBREG && SUBREG_BYTE (count) == 0)
15072          || GET_CODE (count) == TRUNCATE)
15073     count = XEXP (count, 0);
15074   inner_mode = GET_MODE (count);
15075   count = simplify_gen_subreg (outer_mode, count, inner_mode,
15076                                subreg_lowpart_offset (outer_mode, inner_mode));
15077   operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), GET_MODE (operands[3]),
15078                                 operands[1], count);
15081 (define_insn "ashlv4hi3"
15082   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
15083         (ashift:V4HI (match_operand:V4HI 1 "arith_reg_operand" "r")
15084                      (match_operand:DI 2 "shift_count_reg_operand" "r")))]
15085   "TARGET_SHMEDIA"
15086   "mshlld.w     %1, %2, %0"
15087   [(set_attr "type" "arith_media")
15088    (set_attr "highpart" "depend")])
15090 (define_insn "lshrv2si3"
15091   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
15092         (lshiftrt:V2SI (match_operand:V2SI 1 "arith_reg_operand" "r")
15093                      (match_operand:DI 2 "shift_count_reg_operand" "r")))]
15094   "TARGET_SHMEDIA"
15095   "mshlrd.l     %1, %2, %0"
15096   [(set_attr "type" "arith_media")
15097    (set_attr "highpart" "depend")])
15099 (define_insn "lshrv4hi3"
15100   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
15101         (lshiftrt:V4HI (match_operand:V4HI 1 "arith_reg_operand" "r")
15102                        (match_operand:DI 2 "shift_count_reg_operand" "r")))]
15103   "TARGET_SHMEDIA"
15104   "mshlrd.w     %1, %2, %0"
15105   [(set_attr "type" "arith_media")
15106    (set_attr "highpart" "depend")])
15108 (define_insn "subv2si3"
15109   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
15110         (minus:V2SI (match_operand:V2SI 1 "arith_reg_or_0_operand" "rZ")
15111                     (match_operand:V2SI 2 "arith_reg_operand" "r")))]
15112   "TARGET_SHMEDIA"
15113   "msub.l       %N1, %2, %0"
15114   [(set_attr "type" "arith_media")
15115    (set_attr "highpart" "depend")])
15117 (define_insn "subv4hi3"
15118   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
15119         (minus:V4HI (match_operand:V4HI 1 "arith_reg_or_0_operand" "rZ")
15120                     (match_operand:V4HI 2 "arith_reg_operand" "r")))]
15121   "TARGET_SHMEDIA"
15122   "msub.w       %N1, %2, %0"
15123   [(set_attr "type" "arith_media")
15124    (set_attr "highpart" "depend")])
15126 (define_insn_and_split "subv2hi3"
15127   [(set (match_operand:V2HI 0 "arith_reg_dest" "=r")
15128         (minus:V2HI (match_operand:V2HI 1 "arith_reg_or_0_operand" "rZ")
15129                    (match_operand:V2HI 2 "arith_reg_operand" "r")))]
15130   "TARGET_SHMEDIA"
15131   "#"
15132   "TARGET_SHMEDIA"
15133   [(const_int 0)]
15135   rtx src0 = simplify_gen_subreg (V4HImode, operands[1], V2HImode, 0);
15136   rtx src1 = simplify_gen_subreg (V4HImode, operands[2], V2HImode, 0);
15137   rtx v4hi_dst = simplify_gen_subreg (V4HImode, operands[0], V2HImode, 0);
15138   rtx di_dst = simplify_gen_subreg (DImode, operands[0], V2HImode, 0);
15139   rtx si_dst = simplify_gen_subreg (SImode, operands[0], V2HImode, 0);
15141   emit_insn (gen_subv4hi3 (v4hi_dst, src0, src1));
15142   emit_insn (gen_truncdisi2 (si_dst, di_dst));
15143   DONE;
15145   [(set_attr "highpart" "must_split")])
15147 (define_insn "sssubv2si3"
15148   [(set (match_operand:V2SI 0 "arith_reg_dest" "=r")
15149         (ss_minus:V2SI (match_operand:V2SI 1 "arith_reg_or_0_operand" "rZ")
15150                        (match_operand:V2SI 2 "arith_reg_operand" "r")))]
15151   "TARGET_SHMEDIA"
15152   "msubs.l      %N1, %2, %0"
15153   [(set_attr "type" "mcmp_media")
15154    (set_attr "highpart" "depend")])
15156 (define_insn "ussubv8qi3"
15157   [(set (match_operand:V8QI 0 "arith_reg_dest" "=r")
15158         (us_minus:V8QI (match_operand:V8QI 1 "arith_reg_or_0_operand" "rZ")
15159                        (match_operand:V8QI 2 "arith_reg_operand" "r")))]
15160   "TARGET_SHMEDIA"
15161   "msubs.ub     %N1, %2, %0"
15162   [(set_attr "type" "mcmp_media")
15163    (set_attr "highpart" "depend")])
15165 (define_insn "sssubv4hi3"
15166   [(set (match_operand:V4HI 0 "arith_reg_dest" "=r")
15167         (ss_minus:V4HI (match_operand:V4HI 1 "arith_reg_or_0_operand" "rZ")
15168                        (match_operand:V4HI 2 "arith_reg_operand" "r")))]
15169   "TARGET_SHMEDIA"
15170   "msubs.w      %N1, %2, %0"
15171   [(set_attr "type" "mcmp_media")
15172    (set_attr "highpart" "depend")])
15174 ;; -------------------------------------------------------------------------
15175 ;; Floating Point Intrinsics
15176 ;; -------------------------------------------------------------------------
15178 (define_insn "fcosa_s"
15179   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
15180         (unspec:SF [(match_operand:SI 1 "fp_arith_reg_operand" "f")]
15181                    UNSPEC_FCOSA))]
15182   "TARGET_SHMEDIA"
15183   "fcosa.s      %1, %0"
15184   [(set_attr "type" "atrans_media")])
15186 (define_insn "fsina_s"
15187   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
15188         (unspec:SF [(match_operand:SI 1 "fp_arith_reg_operand" "f")]
15189                    UNSPEC_FSINA))]
15190   "TARGET_SHMEDIA"
15191   "fsina.s      %1, %0"
15192   [(set_attr "type" "atrans_media")])
15194 (define_insn "fipr"
15195   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
15196         (plus:SF (plus:SF (vec_select:SF (mult:V4SF (match_operand:V4SF 1
15197                                                     "fp_arith_reg_operand" "f")
15198                                                    (match_operand:V4SF 2
15199                                                     "fp_arith_reg_operand" "f"))
15200                                          (parallel [(const_int 0)]))
15201                           (vec_select:SF (mult:V4SF (match_dup 1) (match_dup 2))
15202                                          (parallel [(const_int 1)])))
15203                  (plus:SF (vec_select:SF (mult:V4SF (match_dup 1) (match_dup 2))
15204                                          (parallel [(const_int 2)]))
15205                           (vec_select:SF (mult:V4SF (match_dup 1) (match_dup 2))
15206                                          (parallel [(const_int 3)])))))]
15207   "TARGET_SHMEDIA"
15208   "fipr.s       %1, %2, %0"
15209   [(set_attr "type" "fparith_media")])
15211 (define_insn "fsrra_s"
15212   [(set (match_operand:SF 0 "fp_arith_reg_operand" "=f")
15213         (unspec:SF [(match_operand:SF 1 "fp_arith_reg_operand" "f")]
15214                    UNSPEC_FSRRA))]
15215   "TARGET_SHMEDIA"
15216   "fsrra.s      %1, %0"
15217   [(set_attr "type" "atrans_media")])
15219 (define_insn "ftrv"
15220   [(set (match_operand:V4SF 0 "fp_arith_reg_operand" "=f")
15221         (plus:V4SF
15222          (plus:V4SF
15223           (mult:V4SF
15224            (vec_select:V4SF (match_operand:V16SF 1 "fp_arith_reg_operand" "f")
15225                             (parallel [(const_int 0) (const_int 5)
15226                                        (const_int 10) (const_int 15)]))
15227            (match_operand:V4SF 2 "fp_arith_reg_operand" "f"))
15228           (mult:V4SF
15229            (vec_select:V4SF (match_dup 1)
15230                             (parallel [(const_int 4) (const_int 9)
15231                                        (const_int 14) (const_int 3)]))
15232            (vec_select:V4SF (match_dup 2)
15233                             (parallel [(const_int 1) (const_int 2)
15234                                        (const_int 3) (const_int 0)]))))
15235          (plus:V4SF
15236           (mult:V4SF
15237            (vec_select:V4SF (match_dup 1)
15238                             (parallel [(const_int 8) (const_int 13)
15239                                        (const_int 2) (const_int 7)]))
15240            (vec_select:V4SF (match_dup 2)
15241                             (parallel [(const_int 2) (const_int 3)
15242                                        (const_int 0) (const_int 1)])))
15243           (mult:V4SF
15244            (vec_select:V4SF (match_dup 1)
15245                             (parallel [(const_int 12) (const_int 1)
15246                                        (const_int 6) (const_int 11)]))
15247            (vec_select:V4SF (match_dup 2)
15248                             (parallel [(const_int 3) (const_int 0)
15249                                        (const_int 1) (const_int 2)]))))))]
15250   "TARGET_SHMEDIA"
15251   "ftrv.s %1, %2, %0"
15252   [(set_attr "type" "fparith_media")])
15254 (define_insn "ldhi_l"
15255   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
15256         (zero_extract:SI
15257          (mem:SI (plus:SI (ior:SI (match_operand:QI 1 "ua_address_operand" "p")
15258                                   (const_int 3))
15259                           (const_int -3)))
15260          (plus:SI (and:SI (match_dup 1) (const_int 3)) (const_int 1))
15261          (const_int 0)))]
15262   "TARGET_SHMEDIA32"
15263   "ldhi.l       %U1, %0"
15264   [(set_attr "type" "load_media")])
15266 (define_insn "ldhi_q"
15267   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15268         (zero_extract:DI
15269          (mem:DI (plus:SI (ior:SI (match_operand:QI 1 "ua_address_operand" "p")
15270                                   (const_int 7))
15271                           (const_int -7)))
15272          (plus:SI (and:SI (match_dup 1) (const_int 7)) (const_int 1))
15273          (const_int 0)))]
15274   "TARGET_SHMEDIA32"
15275   "ldhi.q       %U1, %0"
15276   [(set_attr "type" "load_media")])
15278 (define_insn_and_split "*ldhi_q_comb0"
15279   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15280         (zero_extract:DI
15281          (mem:DI (plus:SI (ior:SI (plus:SI
15282                                     (match_operand:SI 1 "register_operand" "r")
15283                                     (match_operand:SI 2 "ua_offset" "I06"))
15284                                   (const_int 7))
15285                           (const_int -7)))
15286          (plus:SI (and:SI (match_dup 1) (const_int 7))
15287                   (const_int 1))
15288          (const_int 0)))]
15289   "TARGET_SHMEDIA32 && (INTVAL (operands[2]) & 7) == 0"
15290   "#"
15291   ""
15292   [(pc)]
15294   emit_insn (gen_ldhi_q (operands[0],
15295                          gen_rtx_PLUS (SImode, operands[1], operands[2])));
15296   DONE;
15299 (define_insn_and_split "*ldhi_q_comb1"
15300   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15301         (zero_extract:DI
15302          (mem:DI (plus:SI (ior:SI (plus:SI
15303                                     (match_operand:SI 1 "register_operand" "r")
15304                                     (match_operand:SI 2 "ua_offset" "I06"))
15305                                   (const_int 7))
15306                           (const_int -7)))
15307          (plus:SI (and:SI (plus:SI (match_dup 1)
15308                                    (match_operand:SI 3 "ua_offset" "I06"))
15309                           (const_int 7))
15310                   (const_int 1))
15311          (const_int 0)))]
15312   "TARGET_SHMEDIA32 && (INTVAL (operands[2]) & -8)
15313    && (INTVAL (operands[2]) & 7) == INTVAL (operands[3])"
15314   "#"
15315   ""
15316   [(pc)]
15318   emit_insn (gen_ldhi_q (operands[0],
15319                          gen_rtx_PLUS (SImode, operands[1], operands[2])));
15320   DONE;
15323 (define_insn "ldlo_l"
15324   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
15325         (zero_extract:SI
15326          (mem:SI (and:SI (match_operand:QI 1 "ua_address_operand" "p")
15327                          (const_int -4)))
15328          (minus:SI (const_int 4) (and:SI (match_dup 1) (const_int 3)))
15329          (and:SI (match_dup 1) (const_int 3))))]
15330   "TARGET_SHMEDIA32"
15331   "ldlo.l       %U1, %0"
15332   [(set_attr "type" "load_media")])
15334 (define_insn "ldlo_q"
15335   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15336         (zero_extract:DI
15337          (mem:DI (and:SI (match_operand:QI 1 "ua_address_operand" "p")
15338                          (const_int -8)))
15339          (minus:SI (const_int 8) (and:SI (match_dup 1) (const_int 7)))
15340          (and:SI (match_dup 1) (const_int 7))))]
15341   "TARGET_SHMEDIA32"
15342   "ldlo.q       %U1, %0"
15343   [(set_attr "type" "load_media")])
15345 (define_insn_and_split "*ldlo_q_comb0"
15346   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15347         (zero_extract:DI
15348          (mem:DI (and:SI (plus:SI (match_operand:SI 1 "register_operand" "r")
15349                                   (match_operand:SI 2 "ua_offset" "I06"))
15350                          (const_int -8)))
15351          (minus:SI (const_int 8) (and:SI (match_dup 1) (const_int 7)))
15352          (and:SI (match_dup 1) (const_int 7))))]
15353   "TARGET_SHMEDIA32 && (INTVAL (operands[2]) & 7) == 0"
15354   "#"
15355   ""
15356   [(pc)]
15358   emit_insn (gen_ldlo_q (operands[0],
15359                          gen_rtx_PLUS (SImode, operands[1], operands[2])));
15360   DONE;
15363 (define_insn_and_split "*ldlo_q_comb1"
15364   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15365         (zero_extract:DI
15366          (mem:DI (and:SI (plus:SI (match_operand:SI 1 "register_operand" "r")
15367                                   (match_operand:SI 2 "ua_offset" "I06"))
15368                          (const_int -8)))
15369          (minus:SI (const_int 8)
15370                    (and:SI (plus:SI (match_dup 1)
15371                                     (match_operand:SI 3 "ua_offset" "I06"))
15372                            (const_int 7)))
15373          (and:SI (plus:SI (match_dup 1) (match_dup 3)) (const_int 7))))]
15374   "TARGET_SHMEDIA32 && (INTVAL (operands[2]) & -8)
15375    && (INTVAL (operands[2]) & 7) == INTVAL (operands[3])"
15376   "#"
15377   ""
15378   [(pc)]
15380   emit_insn (gen_ldlo_q (operands[0],
15381                          gen_rtx_PLUS (SImode, operands[1], operands[2])));
15382   DONE;
15385 (define_insn "sthi_l"
15386   [(set (zero_extract:SI
15387          (mem:SI (plus:SI (ior:SI (match_operand:QI 0 "ua_address_operand" "p")
15388                                   (const_int 3))
15389                           (const_int -3)))
15390          (plus:SI (and:SI (match_dup 0) (const_int 3)) (const_int 1))
15391          (const_int 0))
15392         (match_operand:SI 1 "arith_reg_operand" "r"))]
15393   "TARGET_SHMEDIA32"
15394   "sthi.l       %U0, %1"
15395   [(set_attr "type" "ustore_media")])
15397 ;; All unaligned stores are considered to be 'narrow' because they typically
15398 ;; operate on less that a quadword, and when they operate on a full quadword,
15399 ;; the vanilla store high / store low sequence will cause a stall if not
15400 ;; scheduled apart.
15401 (define_insn "sthi_q"
15402   [(set (zero_extract:DI
15403          (mem:DI (plus:SI (ior:SI (match_operand:QI 0 "ua_address_operand" "p")
15404                                   (const_int 7))
15405                           (const_int -7)))
15406          (plus:SI (and:SI (match_dup 0) (const_int 7)) (const_int 1))
15407          (const_int 0))
15408         (match_operand:DI 1 "arith_reg_operand" "r"))]
15409   "TARGET_SHMEDIA32"
15410   "sthi.q       %U0, %1"
15411   [(set_attr "type" "ustore_media")])
15413 (define_insn_and_split "*sthi_q_comb0"
15414   [(set (zero_extract:DI
15415          (mem:DI (plus:SI (ior:SI (plus:SI
15416                                     (match_operand:SI 0 "register_operand" "r")
15417                                     (match_operand:SI 1 "ua_offset" "I06"))
15418                                   (const_int 7))
15419                           (const_int -7)))
15420          (plus:SI (and:SI (match_dup 0) (const_int 7)) (const_int 1))
15421          (const_int 0))
15422         (match_operand:DI 2 "arith_reg_operand" "r"))]
15423   "TARGET_SHMEDIA32 && (INTVAL (operands[1]) & 7) == 0"
15424   "#"
15425   ""
15426   [(pc)]
15428   emit_insn (gen_sthi_q (gen_rtx_PLUS (SImode, operands[0], operands[1]),
15429                          operands[2]));
15430   DONE;
15433 (define_insn_and_split "*sthi_q_comb1"
15434   [(set (zero_extract:DI
15435          (mem:DI (plus:SI (ior:SI (plus:SI
15436                                     (match_operand:SI 0 "register_operand" "r")
15437                                     (match_operand:SI 1 "ua_offset" "I06"))
15438                                   (const_int 7))
15439                           (const_int -7)))
15440          (plus:SI (and:SI (plus:SI (match_dup 0)
15441                                    (match_operand:SI 2 "ua_offset" "I06"))
15442                           (const_int 7))
15443                   (const_int 1))
15444          (const_int 0))
15445         (match_operand:DI 3 "arith_reg_operand" "r"))]
15446   "TARGET_SHMEDIA32 && (INTVAL (operands[1]) & -8)
15447    && (INTVAL (operands[1]) & 7) == INTVAL (operands[2])"
15448   "#"
15449   ""
15450   [(pc)]
15452   emit_insn (gen_sthi_q (gen_rtx_PLUS (SImode, operands[0], operands[1]),
15453                          operands[3]));
15454   DONE;
15457 ;; This is highpart user because the address is used as full 64 bit.
15458 (define_insn "stlo_l"
15459   [(set (zero_extract:SI
15460          (mem:SI (and:SI (match_operand:QI 0 "ua_address_operand" "p")
15461                          (const_int -4)))
15462          (minus:SI (const_int 4) (and:SI (match_dup 0) (const_int 3)))
15463          (and:SI (match_dup 0) (const_int 3)))
15464         (match_operand:SI 1 "arith_reg_operand" "r"))]
15465   "TARGET_SHMEDIA32"
15466   "stlo.l       %U0, %1"
15467   [(set_attr "type" "ustore_media")])
15469 (define_insn "stlo_q"
15470   [(set (zero_extract:DI
15471          (mem:DI (and:SI (match_operand:QI 0 "ua_address_operand" "p")
15472                          (const_int -8)))
15473          (minus:SI (const_int 8) (and:SI (match_dup 0) (const_int 7)))
15474          (and:SI (match_dup 0) (const_int 7)))
15475         (match_operand:DI 1 "arith_reg_operand" "r"))]
15476   "TARGET_SHMEDIA32"
15477   "stlo.q       %U0, %1"
15478   [(set_attr "type" "ustore_media")])
15480 (define_insn_and_split "*stlo_q_comb0"
15481   [(set (zero_extract:DI
15482          (mem:DI (and:SI (plus:SI (match_operand:SI 0 "register_operand" "r")
15483                                   (match_operand:SI 1 "ua_offset" "I06"))
15484                          (const_int -8)))
15485          (minus:SI (const_int 8) (and:SI (match_dup 0) (const_int 7)))
15486          (and:SI (match_dup 0) (const_int 7)))
15487         (match_operand:DI 2 "arith_reg_operand" "r"))]
15488   "TARGET_SHMEDIA32 && (INTVAL (operands[1]) & 7) == 0"
15489   "#"
15490   ""
15491   [(pc)]
15493   emit_insn (gen_stlo_q (gen_rtx_PLUS (SImode, operands[0], operands[1]),
15494                          operands[2]));
15495   DONE;
15498 (define_insn_and_split "*stlo_q_comb1"
15499   [(set (zero_extract:DI
15500          (mem:DI (and:SI (plus:SI (match_operand:SI 0 "register_operand" "r")
15501                                   (match_operand:SI 1 "ua_offset" "I06"))
15502                          (const_int -8)))
15503          (minus:SI (const_int 8)
15504                    (and:SI (plus:SI (match_dup 0)
15505                                     (match_operand:SI 2 "ua_offset" "I06"))
15506                            (const_int 7)))
15507          (and:SI (plus:SI (match_dup 0) (match_dup 2)) (const_int 7)))
15508         (match_operand:DI 3 "arith_reg_operand" "r"))]
15509   "TARGET_SHMEDIA32 && (INTVAL (operands[1]) & 7) == INTVAL (operands[2])"
15510   "#"
15511   ""
15512   [(pc)]
15514   emit_insn (gen_stlo_q (gen_rtx_PLUS (SImode, operands[0], operands[1]),
15515                          operands[3]));
15516    DONE;
15519 (define_insn "ldhi_l64"
15520   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
15521         (zero_extract:SI
15522          (mem:SI (plus:DI (ior:DI (match_operand:QI 1 "ua_address_operand" "p")
15523                                   (const_int 3))
15524                           (const_int -3)))
15525          (plus:DI (and:DI (match_dup 1) (const_int 3)) (const_int 1))
15526          (const_int 0)))]
15527   "TARGET_SHMEDIA64"
15528   "ldhi.l       %U1, %0"
15529   [(set_attr "type" "load_media")])
15531 (define_insn "ldhi_q64"
15532   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15533         (zero_extract:DI
15534          (mem:DI (plus:DI (ior:DI (match_operand:QI 1 "ua_address_operand" "p")
15535                                   (const_int 7))
15536                           (const_int -7)))
15537          (plus:DI (and:DI (match_dup 1) (const_int 7)) (const_int 1))
15538          (const_int 0)))]
15539   "TARGET_SHMEDIA64"
15540   "ldhi.q       %U1, %0"
15541   [(set_attr "type" "load_media")])
15543 (define_insn "ldlo_l64"
15544   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
15545         (zero_extract:SI
15546          (mem:SI (and:DI (match_operand:QI 1 "ua_address_operand" "p")
15547                          (const_int -4)))
15548          (minus:DI (const_int 4) (and:DI (match_dup 1) (const_int 3)))
15549          (and:DI (match_dup 1) (const_int 3))))]
15550   "TARGET_SHMEDIA64"
15551   "ldlo.l       %U1, %0"
15552   [(set_attr "type" "load_media")])
15554 (define_insn "ldlo_q64"
15555   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15556         (zero_extract:DI
15557          (mem:DI (and:DI (match_operand:QI 1 "ua_address_operand" "p")
15558                          (const_int -8)))
15559          (minus:DI (const_int 8) (and:DI (match_dup 1) (const_int 7)))
15560          (and:DI (match_dup 1) (const_int 7))))]
15561   "TARGET_SHMEDIA64"
15562   "ldlo.q       %U1, %0"
15563   [(set_attr "type" "load_media")])
15565 (define_insn "sthi_l64"
15566   [(set (zero_extract:SI
15567          (mem:SI (plus:DI (ior:DI (match_operand:QI 0 "ua_address_operand" "p")
15568                                   (const_int 3))
15569                           (const_int -3)))
15570          (plus:DI (and:DI (match_dup 0) (const_int 3)) (const_int 1))
15571          (const_int 0))
15572         (match_operand:SI 1 "arith_reg_operand" "r"))]
15573   "TARGET_SHMEDIA64"
15574   "sthi.l       %U0, %1"
15575   [(set_attr "type" "ustore_media")])
15577 (define_insn "sthi_q64"
15578   [(set (zero_extract:DI
15579          (mem:DI (plus:DI (ior:DI (match_operand:QI 0 "ua_address_operand" "p")
15580                                   (const_int 7))
15581                           (const_int -7)))
15582          (plus:DI (and:DI (match_dup 0) (const_int 7)) (const_int 1))
15583          (const_int 0))
15584         (match_operand:DI 1 "arith_reg_operand" "r"))]
15585   "TARGET_SHMEDIA64"
15586   "sthi.q       %U0, %1"
15587   [(set_attr "type" "ustore_media")])
15589 (define_insn "stlo_l64"
15590   [(set (zero_extract:SI
15591          (mem:SI (and:DI (match_operand:QI 0 "ua_address_operand" "p")
15592                          (const_int -4)))
15593          (minus:DI (const_int 4) (and:DI (match_dup 0) (const_int 3)))
15594          (and:DI (match_dup 0) (const_int 3)))
15595         (match_operand:SI 1 "arith_reg_operand" "r"))]
15596   "TARGET_SHMEDIA64"
15597   "stlo.l       %U0, %1"
15598   [(set_attr "type" "ustore_media")])
15600 (define_insn "stlo_q64"
15601   [(set (zero_extract:DI
15602          (mem:DI (and:DI (match_operand:QI 0 "ua_address_operand" "p")
15603                          (const_int -8)))
15604          (minus:DI (const_int 8) (and:DI (match_dup 0) (const_int 7)))
15605          (and:DI (match_dup 0) (const_int 7)))
15606         (match_operand:DI 1 "arith_reg_operand" "r"))]
15607   "TARGET_SHMEDIA64"
15608   "stlo.q       %U0, %1"
15609   [(set_attr "type" "ustore_media")])
15611 (define_insn "nsb"
15612   [(set (match_operand:QI 0 "arith_reg_dest" "=r")
15613         (unspec:QI [(match_operand:DI 1 "arith_reg_operand" "r")]
15614                    UNSPEC_NSB))]
15615   "TARGET_SHMEDIA"
15616   "nsb  %1, %0"
15617   [(set_attr "type" "arith_media")])
15619 (define_insn "nsbsi"
15620   [(set (match_operand:SI 0 "arith_reg_dest" "=r")
15621         (zero_extend:SI
15622          (unspec:QI [(match_operand:DI 1 "arith_reg_operand" "r")]
15623                     UNSPEC_NSB)))]
15624   "TARGET_SHMEDIA"
15625   "nsb  %1, %0"
15626   [(set_attr "type" "arith_media")])
15628 (define_insn "nsbdi"
15629   [(set (match_operand:DI 0 "arith_reg_dest" "=r")
15630         (zero_extend:DI
15631          (unspec:QI [(match_operand:DI 1 "arith_reg_operand" "r")]
15632                     UNSPEC_NSB)))]
15633   "TARGET_SHMEDIA"
15634   "nsb  %1, %0"
15635   [(set_attr "type" "arith_media")])
15637 (define_expand "ffsdi2"
15638   [(set (match_operand:DI 0 "arith_reg_dest" "")
15639         (ffs:DI (match_operand:DI 1 "arith_reg_operand" "")))]
15640   "TARGET_SHMEDIA"
15642   rtx scratch = gen_reg_rtx (DImode);
15643   rtx last;
15645   emit_insn (gen_adddi3 (scratch, operands[1], constm1_rtx));
15646   emit_insn (gen_xordi3 (scratch, operands[1], scratch));
15647   emit_insn (gen_lshrdi3_media (scratch, scratch, const1_rtx));
15648   emit_insn (gen_nsbdi (scratch, scratch));
15649   emit_insn (gen_adddi3 (scratch, scratch, GEN_INT (-64)));
15650   emit_insn (gen_movdicc_false (scratch, operands[1], const0_rtx, scratch));
15651   last = emit_insn (gen_subdi3 (operands[0], const0_rtx, scratch));
15652   set_unique_reg_note (last, REG_EQUAL, gen_rtx_FFS (DImode, operands[0]));
15654   DONE;
15657 (define_expand "ffssi2"
15658   [(set (match_operand:SI 0 "arith_reg_dest" "")
15659         (ffs:SI (match_operand:SI 1 "arith_reg_operand" "")))]
15660   "TARGET_SHMEDIA"
15662   rtx scratch = gen_reg_rtx (SImode);
15663   rtx discratch = gen_reg_rtx (DImode);
15664   rtx last;
15666   emit_insn (gen_adddi3 (discratch,
15667                          simplify_gen_subreg (DImode, operands[1], SImode, 0),
15668                          constm1_rtx));
15669   emit_insn (gen_andcdi3 (discratch,
15670                           simplify_gen_subreg (DImode, operands[1], SImode, 0),
15671                           discratch));
15672   emit_insn (gen_nsbsi (scratch, discratch));
15673   last = emit_insn (gen_subsi3 (operands[0],
15674                                 force_reg (SImode, GEN_INT (63)), scratch));
15675   set_unique_reg_note (last, REG_EQUAL, gen_rtx_FFS (SImode, operands[0]));
15677   DONE;
15680 (define_insn "byterev"
15681   [(set (match_operand:V8QI 0 "arith_reg_dest" "=r")
15682         (vec_select:V8QI (match_operand:V8QI 1 "arith_reg_operand" "r")
15683                          (parallel [(const_int 7) (const_int 6) (const_int 5)
15684                                     (const_int 4) (const_int 3) (const_int 2)
15685                                     (const_int 1) (const_int 0)])))]
15686   "TARGET_SHMEDIA"
15687   "byterev      %1, %0"
15688   [(set_attr "type" "arith_media")])
15690 ;; In user mode, the "pref" instruction will raise a RADDERR exception
15691 ;; for accesses to [0x80000000,0xffffffff].  This makes it an unsuitable
15692 ;; implementation of __builtin_prefetch for VxWorks RTPs.
15693 (define_expand "prefetch"
15694   [(prefetch (match_operand 0 "address_operand" "")
15695              (match_operand:SI 1 "const_int_operand" "")
15696              (match_operand:SI 2 "const_int_operand" ""))]
15697   "(TARGET_SH2A || TARGET_SH3 || TARGET_SH5)
15698    && (TARGET_SHMEDIA || ! TARGET_VXWORKS_RTP)")
15700 (define_insn "*prefetch"
15701   [(prefetch (match_operand:SI 0 "register_operand" "r")
15702              (match_operand:SI 1 "const_int_operand" "n")
15703              (match_operand:SI 2 "const_int_operand" "n"))]
15704   "(TARGET_SH2A || TARGET_SH3 || TARGET_SHCOMPACT) && ! TARGET_VXWORKS_RTP"
15705   "pref @%0"
15706   [(set_attr "type" "other")])
15708 (define_insn "*prefetch_media"
15709   [(prefetch (match_operand:QI 0 "address_operand" "p")
15710              (match_operand:SI 1 "const_int_operand" "n")
15711              (match_operand:SI 2 "const_int_operand" "n"))]
15712   "TARGET_SHMEDIA"
15714   operands[0] = gen_rtx_MEM (QImode, operands[0]);
15715   output_asm_insn ("ld%M0.b     %m0,r63", operands);
15716   return "";
15718   [(set_attr "type" "other")])
15720 (define_insn "alloco_i"
15721   [(set (mem:BLK (match_operand:QI 0 "cache_address_operand" "p"))
15722         (unspec:BLK [(const_int 0)] UNSPEC_ALLOCO))]
15723   "TARGET_SHMEDIA32"
15725   rtx xops[2];
15727   if (GET_CODE (operands[0]) == PLUS)
15728     {
15729       xops[0] = XEXP (operands[0], 0);
15730       xops[1] = XEXP (operands[0], 1);
15731     }
15732   else
15733     {
15734       xops[0] = operands[0];
15735       xops[1] = const0_rtx;
15736     }
15737   output_asm_insn ("alloco      %0, %1", xops);
15738   return "";
15740   [(set_attr "type" "other")])
15742 (define_split
15743   [(set (match_operand 0 "any_register_operand" "")
15744         (match_operand 1 "" ""))]
15745   "TARGET_SHMEDIA && reload_completed"
15746   [(set (match_dup 0) (match_dup 1))]
15748   if (!shmedia_cleanup_truncate (operands[1]))
15749     FAIL;
15752 ;; -------------------------------------------------------------------------
15753 ;; Stack Protector Patterns
15754 ;; -------------------------------------------------------------------------
15756 (define_expand "stack_protect_set"
15757   [(set (match_operand 0 "memory_operand" "")
15758         (match_operand 1 "memory_operand" ""))]
15759   ""
15761   if (TARGET_SHMEDIA)
15762     {
15763       if (TARGET_SHMEDIA64)
15764         emit_insn (gen_stack_protect_set_di_media (operands[0], operands[1]));
15765       else
15766         emit_insn (gen_stack_protect_set_si_media (operands[0], operands[1]));
15767     }
15768   else
15769     emit_insn (gen_stack_protect_set_si (operands[0], operands[1]));
15771   DONE;
15774 (define_insn "stack_protect_set_si"
15775   [(set (match_operand:SI 0 "memory_operand" "=m")
15776         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
15777    (set (match_scratch:SI 2 "=&r") (const_int 0))]
15778   "!TARGET_SHMEDIA"
15780   return       "mov.l   %1,%2"  "\n"
15781          "      mov.l   %2,%0"  "\n"
15782          "      mov     #0,%2";
15784   [(set_attr "type" "other")
15785    (set_attr "length" "6")])
15787 (define_insn "stack_protect_set_si_media"
15788   [(set (match_operand:SI 0 "memory_operand" "=m")
15789         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")] UNSPEC_SP_SET))
15790    (set (match_scratch:SI 2 "=&r") (const_int 0))]
15791   "TARGET_SHMEDIA"
15793   return       "ld%M1.l %m1,%2" "\n"
15794          "      st%M0.l %m0,%2" "\n"
15795          "      movi    0,%2";
15797   [(set_attr "type" "other")
15798    (set_attr "length" "12")])
15800 (define_insn "stack_protect_set_di_media"
15801   [(set (match_operand:DI 0 "memory_operand" "=m")
15802         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")] UNSPEC_SP_SET))
15803    (set (match_scratch:DI 2 "=&r") (const_int 0))]
15804   "TARGET_SHMEDIA64"
15806   return       "ld%M1.q %m1,%2" "\n"
15807          "      st%M0.q %m0,%2" "\n"
15808          "      movi    0,%2";
15810   [(set_attr "type" "other")
15811    (set_attr "length" "12")])
15813 (define_expand "stack_protect_test"
15814   [(match_operand 0 "memory_operand" "")
15815    (match_operand 1 "memory_operand" "")
15816    (match_operand 2 "" "")]
15817   ""
15819   if (TARGET_SHMEDIA)
15820     {
15821       rtx tmp = gen_reg_rtx (GET_MODE (operands[0]));
15822       rtx test;
15824       test = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
15825       if (TARGET_SHMEDIA64)
15826         {
15827           emit_insn (gen_stack_protect_test_di_media (tmp, operands[0],
15828                                                       operands[1]));
15829           emit_jump_insn (gen_cbranchdi4 (test, tmp, const0_rtx, operands[2]));
15830         }
15831       else
15832         {
15833           emit_insn (gen_stack_protect_test_si_media (tmp, operands[0],
15834                                                       operands[1]));
15835           emit_jump_insn (gen_cbranchsi4 (test, tmp, const0_rtx, operands[2]));
15836         }
15837     }
15838   else
15839     {
15840       emit_insn (gen_stack_protect_test_si (operands[0], operands[1]));
15841       emit_jump_insn (gen_branch_true (operands[2]));
15842     }
15844   DONE;
15847 (define_insn "stack_protect_test_si"
15848   [(set (reg:SI T_REG)
15849         (unspec:SI [(match_operand:SI 0 "memory_operand" "m")
15850                     (match_operand:SI 1 "memory_operand" "m")]
15851                    UNSPEC_SP_TEST))
15852   (set (match_scratch:SI 2 "=&r") (const_int 0))
15853   (set (match_scratch:SI 3 "=&r") (const_int 0))]
15854   "!TARGET_SHMEDIA"
15856   return       "mov.l   %0,%2"  "\n"
15857          "      mov.l   %1,%3"  "\n"
15858          "      cmp/eq  %2,%3"  "\n"
15859          "      mov     #0,%2"  "\n"
15860          "      mov     #0,%3";
15862   [(set_attr "type" "other")
15863    (set_attr "length" "10")])
15865 (define_insn "stack_protect_test_si_media"
15866   [(set (match_operand:SI 0 "register_operand" "=&r")
15867         (unspec:SI [(match_operand:SI 1 "memory_operand" "m")
15868                     (match_operand:SI 2 "memory_operand" "m")]
15869                    UNSPEC_SP_TEST))
15870   (set (match_scratch:SI 3 "=&r") (const_int 0))]
15871   "TARGET_SHMEDIA"
15873   return       "ld%M1.l %m1,%0"         "\n"
15874          "      ld%M2.l %m2,%3"         "\n"
15875          "      cmpeq   %0,%3,%0"       "\n"
15876          "      movi    0,%3";
15878   [(set_attr "type" "other")
15879    (set_attr "length" "16")])
15881 (define_insn "stack_protect_test_di_media"
15882   [(set (match_operand:DI 0 "register_operand" "=&r")
15883         (unspec:DI [(match_operand:DI 1 "memory_operand" "m")
15884                     (match_operand:DI 2 "memory_operand" "m")]
15885                    UNSPEC_SP_TEST))
15886   (set (match_scratch:DI 3 "=&r") (const_int 0))]
15887   "TARGET_SHMEDIA64"
15889   return       "ld%M1.q %m1,%0"         "\n"
15890          "      ld%M2.q %m2,%3"         "\n"
15891          "      cmpeq   %0,%3,%0"       "\n"
15892          "      movi    0,%3";
15894   [(set_attr "type" "other")
15895    (set_attr "length" "16")])
15897 ;; -------------------------------------------------------------------------
15898 ;; Atomic operations
15899 ;; -------------------------------------------------------------------------
15901 (include "sync.md")