OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / config / mips / mips.md
1 ;;  Mips.md          Machine Description for MIPS based processors
2 ;;  Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;;  1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;;  Free Software Foundation, Inc.
5 ;;  Contributed by   A. Lichnewsky, lich@inria.inria.fr
6 ;;  Changes by       Michael Meissner, meissner@osf.org
7 ;;  64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
8 ;;  Brendan Eich, brendan@microunity.com.
9
10 ;; This file is part of GCC.
11
12 ;; GCC is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
17 ;; GCC is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GCC; see the file COPYING3.  If not see
24 ;; <http://www.gnu.org/licenses/>.
25
26 (define_constants
27   [(UNSPEC_LOAD_LOW              0)
28    (UNSPEC_LOAD_HIGH             1)
29    (UNSPEC_STORE_WORD            2)
30    (UNSPEC_GET_FNADDR            3)
31    (UNSPEC_BLOCKAGE              4)
32    (UNSPEC_CPRESTORE             5)
33    (UNSPEC_EH_RECEIVER           6)
34    (UNSPEC_EH_RETURN             7)
35    (UNSPEC_CONSTTABLE_INT        8)
36    (UNSPEC_CONSTTABLE_FLOAT      9)
37    (UNSPEC_ALIGN                14)
38    (UNSPEC_HIGH                 17)
39    (UNSPEC_LOAD_LEFT            18)
40    (UNSPEC_LOAD_RIGHT           19)
41    (UNSPEC_STORE_LEFT           20)
42    (UNSPEC_STORE_RIGHT          21)
43    (UNSPEC_LOADGP               22)
44    (UNSPEC_LOAD_CALL            23)
45    (UNSPEC_LOAD_GOT             24)
46    (UNSPEC_GP                   25)
47    (UNSPEC_MFHILO               26)
48    (UNSPEC_TLS_LDM              27)
49    (UNSPEC_TLS_GET_TP           28)
50    (UNSPEC_MFHC1                31)
51    (UNSPEC_MTHC1                32)
52    (UNSPEC_CLEAR_HAZARD         33)
53    (UNSPEC_RDHWR                34)
54    (UNSPEC_SYNCI                35)
55    (UNSPEC_SYNC                 36)
56    (UNSPEC_COMPARE_AND_SWAP     37)
57    (UNSPEC_SYNC_OLD_OP          38)
58    (UNSPEC_SYNC_NEW_OP          39)
59    (UNSPEC_SYNC_EXCHANGE        40)
60    (UNSPEC_MEMORY_BARRIER       41)
61    
62    (UNSPEC_ADDRESS_FIRST        100)
63
64    (FAKE_CALL_REGNO             79)
65
66    ;; For MIPS Paired-Singled Floating Point Instructions.
67
68    (UNSPEC_MOVE_TF_PS           200)
69    (UNSPEC_C                    201)
70
71    ;; MIPS64/MIPS32R2 alnv.ps
72    (UNSPEC_ALNV_PS              202)
73
74    ;; MIPS-3D instructions
75    (UNSPEC_CABS                 203)
76
77    (UNSPEC_ADDR_PS              204)
78    (UNSPEC_CVT_PW_PS            205)
79    (UNSPEC_CVT_PS_PW            206)
80    (UNSPEC_MULR_PS              207)
81    (UNSPEC_ABS_PS               208)
82
83    (UNSPEC_RSQRT1               209)
84    (UNSPEC_RSQRT2               210)
85    (UNSPEC_RECIP1               211)
86    (UNSPEC_RECIP2               212)
87    (UNSPEC_SINGLE_CC            213)
88    (UNSPEC_SCC                  214)
89
90    ;; MIPS DSP ASE Revision 0.98 3/24/2005
91    (UNSPEC_ADDQ                 300)
92    (UNSPEC_ADDQ_S               301)
93    (UNSPEC_SUBQ                 302)
94    (UNSPEC_SUBQ_S               303)
95    (UNSPEC_ADDSC                304)
96    (UNSPEC_ADDWC                305)
97    (UNSPEC_MODSUB               306)
98    (UNSPEC_RADDU_W_QB           307)
99    (UNSPEC_ABSQ_S               308)
100    (UNSPEC_PRECRQ_QB_PH         309)
101    (UNSPEC_PRECRQ_PH_W          310)
102    (UNSPEC_PRECRQ_RS_PH_W       311)
103    (UNSPEC_PRECRQU_S_QB_PH      312)
104    (UNSPEC_PRECEQ_W_PHL         313)
105    (UNSPEC_PRECEQ_W_PHR         314)
106    (UNSPEC_PRECEQU_PH_QBL       315)
107    (UNSPEC_PRECEQU_PH_QBR       316)
108    (UNSPEC_PRECEQU_PH_QBLA      317)
109    (UNSPEC_PRECEQU_PH_QBRA      318)
110    (UNSPEC_PRECEU_PH_QBL        319)
111    (UNSPEC_PRECEU_PH_QBR        320)
112    (UNSPEC_PRECEU_PH_QBLA       321)
113    (UNSPEC_PRECEU_PH_QBRA       322)
114    (UNSPEC_SHLL                 323)
115    (UNSPEC_SHLL_S               324)
116    (UNSPEC_SHRL_QB              325)
117    (UNSPEC_SHRA_PH              326)
118    (UNSPEC_SHRA_R               327)
119    (UNSPEC_MULEU_S_PH_QBL       328)
120    (UNSPEC_MULEU_S_PH_QBR       329)
121    (UNSPEC_MULQ_RS_PH           330)
122    (UNSPEC_MULEQ_S_W_PHL        331)
123    (UNSPEC_MULEQ_S_W_PHR        332)
124    (UNSPEC_DPAU_H_QBL           333)
125    (UNSPEC_DPAU_H_QBR           334)
126    (UNSPEC_DPSU_H_QBL           335)
127    (UNSPEC_DPSU_H_QBR           336)
128    (UNSPEC_DPAQ_S_W_PH          337)
129    (UNSPEC_DPSQ_S_W_PH          338)
130    (UNSPEC_MULSAQ_S_W_PH        339)
131    (UNSPEC_DPAQ_SA_L_W          340)
132    (UNSPEC_DPSQ_SA_L_W          341)
133    (UNSPEC_MAQ_S_W_PHL          342)
134    (UNSPEC_MAQ_S_W_PHR          343)
135    (UNSPEC_MAQ_SA_W_PHL         344)
136    (UNSPEC_MAQ_SA_W_PHR         345)
137    (UNSPEC_BITREV               346)
138    (UNSPEC_INSV                 347)
139    (UNSPEC_REPL_QB              348)
140    (UNSPEC_REPL_PH              349)
141    (UNSPEC_CMP_EQ               350)
142    (UNSPEC_CMP_LT               351)
143    (UNSPEC_CMP_LE               352)
144    (UNSPEC_CMPGU_EQ_QB          353)
145    (UNSPEC_CMPGU_LT_QB          354)
146    (UNSPEC_CMPGU_LE_QB          355)
147    (UNSPEC_PICK                 356)
148    (UNSPEC_PACKRL_PH            357)
149    (UNSPEC_EXTR_W               358)
150    (UNSPEC_EXTR_R_W             359)
151    (UNSPEC_EXTR_RS_W            360)
152    (UNSPEC_EXTR_S_H             361)
153    (UNSPEC_EXTP                 362)
154    (UNSPEC_EXTPDP               363)
155    (UNSPEC_SHILO                364)
156    (UNSPEC_MTHLIP               365)
157    (UNSPEC_WRDSP                366)
158    (UNSPEC_RDDSP                367)
159
160    ;; MIPS DSP ASE REV 2 Revision 0.02 11/24/2006
161    (UNSPEC_ABSQ_S_QB            400)
162    (UNSPEC_ADDU_PH              401)
163    (UNSPEC_ADDU_S_PH            402)
164    (UNSPEC_ADDUH_QB             403)
165    (UNSPEC_ADDUH_R_QB           404)
166    (UNSPEC_APPEND               405)
167    (UNSPEC_BALIGN               406)
168    (UNSPEC_CMPGDU_EQ_QB         407)
169    (UNSPEC_CMPGDU_LT_QB         408)
170    (UNSPEC_CMPGDU_LE_QB         409)
171    (UNSPEC_DPA_W_PH             410)
172    (UNSPEC_DPS_W_PH             411)
173    (UNSPEC_MADD                 412)
174    (UNSPEC_MADDU                413)
175    (UNSPEC_MSUB                 414)
176    (UNSPEC_MSUBU                415)
177    (UNSPEC_MUL_PH               416)
178    (UNSPEC_MUL_S_PH             417)
179    (UNSPEC_MULQ_RS_W            418)
180    (UNSPEC_MULQ_S_PH            419)
181    (UNSPEC_MULQ_S_W             420)
182    (UNSPEC_MULSA_W_PH           421)
183    (UNSPEC_MULT                 422)
184    (UNSPEC_MULTU                423)
185    (UNSPEC_PRECR_QB_PH          424)
186    (UNSPEC_PRECR_SRA_PH_W       425)
187    (UNSPEC_PRECR_SRA_R_PH_W     426)
188    (UNSPEC_PREPEND              427)
189    (UNSPEC_SHRA_QB              428)
190    (UNSPEC_SHRA_R_QB            429)
191    (UNSPEC_SHRL_PH              430)
192    (UNSPEC_SUBU_PH              431)
193    (UNSPEC_SUBU_S_PH            432)
194    (UNSPEC_SUBUH_QB             433)
195    (UNSPEC_SUBUH_R_QB           434)
196    (UNSPEC_ADDQH_PH             435)
197    (UNSPEC_ADDQH_R_PH           436)
198    (UNSPEC_ADDQH_W              437)
199    (UNSPEC_ADDQH_R_W            438)
200    (UNSPEC_SUBQH_PH             439)
201    (UNSPEC_SUBQH_R_PH           440)
202    (UNSPEC_SUBQH_W              441)
203    (UNSPEC_SUBQH_R_W            442)
204    (UNSPEC_DPAX_W_PH            443)
205    (UNSPEC_DPSX_W_PH            444)
206    (UNSPEC_DPAQX_S_W_PH         445)
207    (UNSPEC_DPAQX_SA_W_PH        446)
208    (UNSPEC_DPSQX_S_W_PH         447)
209    (UNSPEC_DPSQX_SA_W_PH        448)
210   ]
211 )
212
213 (include "predicates.md")
214 (include "constraints.md")
215 \f
216 ;; ....................
217 ;;
218 ;;      Attributes
219 ;;
220 ;; ....................
221
222 (define_attr "got" "unset,xgot_high,load"
223   (const_string "unset"))
224
225 ;; For jal instructions, this attribute is DIRECT when the target address
226 ;; is symbolic and INDIRECT when it is a register.
227 (define_attr "jal" "unset,direct,indirect"
228   (const_string "unset"))
229
230 ;; This attribute is YES if the instruction is a jal macro (not a
231 ;; real jal instruction).
232 ;;
233 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
234 ;; an instruction to restore $gp.  Direct jals are also macros for
235 ;; flag_pic && !TARGET_ABSOLUTE_ABICALLS because they first load
236 ;; the target address into a register.
237 (define_attr "jal_macro" "no,yes"
238   (cond [(eq_attr "jal" "direct")
239          (symbol_ref "TARGET_CALL_CLOBBERED_GP
240                       || (flag_pic && !TARGET_ABSOLUTE_ABICALLS)")
241          (eq_attr "jal" "indirect")
242          (symbol_ref "TARGET_CALL_CLOBBERED_GP")]
243         (const_string "no")))
244
245 ;; Classification of each insn.
246 ;; branch       conditional branch
247 ;; jump         unconditional jump
248 ;; call         unconditional call
249 ;; load         load instruction(s)
250 ;; fpload       floating point load
251 ;; fpidxload    floating point indexed load
252 ;; store        store instruction(s)
253 ;; fpstore      floating point store
254 ;; fpidxstore   floating point indexed store
255 ;; prefetch     memory prefetch (register + offset)
256 ;; prefetchx    memory indexed prefetch (register + register)
257 ;; condmove     conditional moves
258 ;; mfc          transfer from coprocessor
259 ;; mtc          transfer to coprocessor
260 ;; mthilo       transfer to hi/lo registers
261 ;; mfhilo       transfer from hi/lo registers
262 ;; const        load constant
263 ;; arith        integer arithmetic instructions
264 ;; logical      integer logical instructions
265 ;; shift        integer shift instructions
266 ;; slt          set less than instructions
267 ;; signext      sign extend instructions
268 ;; clz          the clz and clo instructions
269 ;; trap         trap if instructions
270 ;; imul         integer multiply 2 operands
271 ;; imul3        integer multiply 3 operands
272 ;; imadd        integer multiply-add
273 ;; idiv         integer divide
274 ;; move         integer register move ({,D}ADD{,U} with rt = 0)
275 ;; fmove        floating point register move
276 ;; fadd         floating point add/subtract
277 ;; fmul         floating point multiply
278 ;; fmadd        floating point multiply-add
279 ;; fdiv         floating point divide
280 ;; frdiv        floating point reciprocal divide
281 ;; frdiv1       floating point reciprocal divide step 1
282 ;; frdiv2       floating point reciprocal divide step 2
283 ;; fabs         floating point absolute value
284 ;; fneg         floating point negation
285 ;; fcmp         floating point compare
286 ;; fcvt         floating point convert
287 ;; fsqrt        floating point square root
288 ;; frsqrt       floating point reciprocal square root
289 ;; frsqrt1      floating point reciprocal square root step1
290 ;; frsqrt2      floating point reciprocal square root step2
291 ;; multi        multiword sequence (or user asm statements)
292 ;; nop          no operation
293 (define_attr "type"
294   "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,prefetch,prefetchx,condmove,mfc,mtc,mthilo,mfhilo,const,arith,logical,shift,slt,signext,clz,trap,imul,imul3,imadd,idiv,move,fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,frsqrt,frsqrt1,frsqrt2,multi,nop"
295   (cond [(eq_attr "jal" "!unset") (const_string "call")
296          (eq_attr "got" "load") (const_string "load")]
297         (const_string "unknown")))
298
299 ;; Main data type used by the insn
300 (define_attr "mode" "unknown,none,QI,HI,SI,DI,SF,DF,FPSW"
301   (const_string "unknown"))
302
303 ;; Mode for conversion types (fcvt)
304 ;; I2S          integer to float single (SI/DI to SF)
305 ;; I2D          integer to float double (SI/DI to DF)
306 ;; S2I          float to integer (SF to SI/DI)
307 ;; D2I          float to integer (DF to SI/DI)
308 ;; D2S          double to float single
309 ;; S2D          float single to double
310
311 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D" 
312   (const_string "unknown"))
313
314 ;; Is this an extended instruction in mips16 mode?
315 (define_attr "extended_mips16" "no,yes"
316   (const_string "no"))
317
318 ;; Length of instruction in bytes.
319 (define_attr "length" ""
320    (cond [;; Direct branch instructions have a range of [-0x40000,0x3fffc].
321           ;; If a branch is outside this range, we have a choice of two
322           ;; sequences.  For PIC, an out-of-range branch like:
323           ;;
324           ;;    bne     r1,r2,target
325           ;;    dslot
326           ;;
327           ;; becomes the equivalent of:
328           ;;
329           ;;    beq     r1,r2,1f
330           ;;    dslot
331           ;;    la      $at,target
332           ;;    jr      $at
333           ;;    nop
334           ;; 1:
335           ;;
336           ;; where the load address can be up to three instructions long
337           ;; (lw, nop, addiu).
338           ;;
339           ;; The non-PIC case is similar except that we use a direct
340           ;; jump instead of an la/jr pair.  Since the target of this
341           ;; jump is an absolute 28-bit bit address (the other bits
342           ;; coming from the address of the delay slot) this form cannot
343           ;; cross a 256MB boundary.  We could provide the option of
344           ;; using la/jr in this case too, but we do not do so at
345           ;; present.
346           ;;
347           ;; Note that this value does not account for the delay slot
348           ;; instruction, whose length is added separately.  If the RTL
349           ;; pattern has no explicit delay slot, mips_adjust_insn_length
350           ;; will add the length of the implicit nop.  The values for
351           ;; forward and backward branches will be different as well.
352           (eq_attr "type" "branch")
353           (cond [(and (le (minus (match_dup 1) (pc)) (const_int 131064))
354                       (le (minus (pc) (match_dup 1)) (const_int 131068)))
355                   (const_int 4)
356                  (ne (symbol_ref "flag_pic") (const_int 0))
357                  (const_int 24)
358                  ] (const_int 12))
359
360           (eq_attr "got" "load")
361           (const_int 4)
362           (eq_attr "got" "xgot_high")
363           (const_int 8)
364
365           (eq_attr "type" "const")
366           (symbol_ref "mips_const_insns (operands[1]) * 4")
367           (eq_attr "type" "load,fpload")
368           (symbol_ref "mips_load_store_insns (operands[1], insn) * 4")
369           (eq_attr "type" "store,fpstore")
370           (symbol_ref "mips_load_store_insns (operands[0], insn) * 4")
371
372           ;; In the worst case, a call macro will take 8 instructions:
373           ;;
374           ;;     lui $25,%call_hi(FOO)
375           ;;     addu $25,$25,$28
376           ;;     lw $25,%call_lo(FOO)($25)
377           ;;     nop
378           ;;     jalr $25
379           ;;     nop
380           ;;     lw $gp,X($sp)
381           ;;     nop
382           (eq_attr "jal_macro" "yes")
383           (const_int 32)
384
385           (and (eq_attr "extended_mips16" "yes")
386                (ne (symbol_ref "TARGET_MIPS16") (const_int 0)))
387           (const_int 8)
388
389           ;; Various VR4120 errata require a nop to be inserted after a macc
390           ;; instruction.  The assembler does this for us, so account for
391           ;; the worst-case length here.
392           (and (eq_attr "type" "imadd")
393                (ne (symbol_ref "TARGET_FIX_VR4120") (const_int 0)))
394           (const_int 8)
395
396           ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
397           ;; the result of the second one is missed.  The assembler should work
398           ;; around this by inserting a nop after the first dmult.
399           (and (eq_attr "type" "imul,imul3")
400                (and (eq_attr "mode" "DI")
401                     (ne (symbol_ref "TARGET_FIX_VR4120") (const_int 0))))
402           (const_int 8)
403
404           (eq_attr "type" "idiv")
405           (symbol_ref "mips_idiv_insns () * 4")
406           ] (const_int 4)))
407
408 ;; Attribute describing the processor.  This attribute must match exactly
409 ;; with the processor_type enumeration in mips.h.
410 (define_attr "cpu"
411   "r3000,4kc,4kp,5kc,5kf,20kc,24kc,24kf2_1,24kf1_1,74kc,74kf2_1,74kf1_1,74kf3_2,m4k,r3900,r6000,r4000,r4100,r4111,r4120,r4130,r4300,r4600,r4650,r5000,r5400,r5500,r7000,r8000,r9000,sb1,sb1a,sr71000"
412   (const (symbol_ref "mips_tune")))
413
414 ;; The type of hardware hazard associated with this instruction.
415 ;; DELAY means that the next instruction cannot read the result
416 ;; of this one.  HILO means that the next two instructions cannot
417 ;; write to HI or LO.
418 (define_attr "hazard" "none,delay,hilo"
419   (cond [(and (eq_attr "type" "load,fpload,fpidxload")
420               (ne (symbol_ref "ISA_HAS_LOAD_DELAY") (const_int 0)))
421          (const_string "delay")
422
423          (and (eq_attr "type" "mfc,mtc")
424               (ne (symbol_ref "ISA_HAS_XFER_DELAY") (const_int 0)))
425          (const_string "delay")
426
427          (and (eq_attr "type" "fcmp")
428               (ne (symbol_ref "ISA_HAS_FCMP_DELAY") (const_int 0)))
429          (const_string "delay")
430
431          ;; The r4000 multiplication patterns include an mflo instruction.
432          (and (eq_attr "type" "imul")
433               (ne (symbol_ref "TARGET_FIX_R4000") (const_int 0)))
434          (const_string "hilo")
435
436          (and (eq_attr "type" "mfhilo")
437               (eq (symbol_ref "ISA_HAS_HILO_INTERLOCKS") (const_int 0)))
438          (const_string "hilo")]
439         (const_string "none")))
440
441 ;; Indicates which SET in an instruction pattern induces a hazard.
442 ;; Only meaningful when "hazard" is not "none".  SINGLE means that
443 ;; the pattern has only one set while the other values are indexes
444 ;; into a PARALLEL vector.
445 ;;
446 ;; Hazardous instructions with multiple sets should generally put the
447 ;; hazardous set first.  The only purpose of this attribute is to force
448 ;; each multi-set pattern to explicitly assert that this condition holds.
449 (define_attr "hazard_set" "single,0"
450   (const_string "single"))
451
452 ;; Is it a single instruction?
453 (define_attr "single_insn" "no,yes"
454   (symbol_ref "get_attr_length (insn) == (TARGET_MIPS16 ? 2 : 4)"))
455
456 ;; Can the instruction be put into a delay slot?
457 (define_attr "can_delay" "no,yes"
458   (if_then_else (and (eq_attr "type" "!branch,call,jump")
459                      (and (eq_attr "hazard" "none")
460                           (eq_attr "single_insn" "yes")))
461                 (const_string "yes")
462                 (const_string "no")))
463
464 ;; Attribute defining whether or not we can use the branch-likely instructions
465 (define_attr "branch_likely" "no,yes"
466   (const
467    (if_then_else (ne (symbol_ref "GENERATE_BRANCHLIKELY") (const_int 0))
468                  (const_string "yes")
469                  (const_string "no"))))
470
471 ;; True if an instruction might assign to hi or lo when reloaded.
472 ;; This is used by the TUNE_MACC_CHAINS code.
473 (define_attr "may_clobber_hilo" "no,yes"
474   (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthilo")
475                 (const_string "yes")
476                 (const_string "no")))
477
478 ;; Describe a user's asm statement.
479 (define_asm_attributes
480   [(set_attr "type" "multi")
481    (set_attr "can_delay" "no")])
482 \f
483 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
484 ;; from the same template.
485 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
486
487 ;; This mode iterator allows :P to be used for patterns that operate on
488 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
489 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
490
491 ;; This mode iterator allows :MOVECC to be used anywhere that a
492 ;; conditional-move-type condition is needed.
493 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT") (CC "TARGET_HARD_FLOAT")])
494
495 ;; 64-bit modes for which we provide move patterns.
496 (define_mode_iterator MOVE64
497   [DI DF (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
498
499 ;; This mode iterator allows the QI and HI extension patterns to be
500 ;; defined from the same template.
501 (define_mode_iterator SHORT [QI HI])
502
503 ;; Likewise the 64-bit truncate-and-shift patterns.
504 (define_mode_iterator SUBDI [QI HI SI])
505
506 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
507 ;; floating-point mode is allowed.
508 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
509                             (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
510                             (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
511
512 ;; Like ANYF, but only applies to scalar modes.
513 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
514                                (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
515
516 ;; A floating-point mode for which moves involving FPRs may need to be split.
517 (define_mode_iterator SPLITF
518   [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
519    (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
520    (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
521    (TF "TARGET_64BIT && TARGET_FLOAT64")])
522
523 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
524 ;; 32-bit version and "dsubu" in the 64-bit version.
525 (define_mode_attr d [(SI "") (DI "d")
526                      (QQ "") (HQ "") (SQ "") (DQ "d")
527                      (UQQ "") (UHQ "") (USQ "") (UDQ "d")
528                      (HA "") (SA "") (DA "d")
529                      (UHA "") (USA "") (UDA "d")])
530
531 ;; This attribute gives the length suffix for a sign- or zero-extension
532 ;; instruction.
533 (define_mode_attr size [(QI "b") (HI "h")])
534
535 ;; This attributes gives the mode mask of a SHORT.
536 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
537
538 ;; Mode attributes for GPR loads and stores.
539 (define_mode_attr load [(SI "lw") (DI "ld")])
540 (define_mode_attr store [(SI "sw") (DI "sd")])
541
542 ;; Similarly for MIPS IV indexed FPR loads and stores.
543 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
544 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
545
546 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
547 ;; are different.  Some forms of unextended addiu have an 8-bit immediate
548 ;; field but the equivalent daddiu has only a 5-bit field.
549 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
550
551 ;; This attribute gives the best constraint to use for registers of
552 ;; a given mode.
553 (define_mode_attr reg [(SI "d") (DI "d") (CC "z")])
554
555 ;; This attribute gives the format suffix for floating-point operations.
556 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
557
558 ;; This attribute gives the upper-case mode name for one unit of a
559 ;; floating-point mode.
560 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
561
562 ;; This attribute gives the integer mode that has the same size as a
563 ;; fixed-point mode.
564 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
565                          (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
566                          (HA "HI") (SA "SI") (DA "DI")
567                          (UHA "HI") (USA "SI") (UDA "DI")
568                          (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
569                          (V2HQ "SI") (V2HA "SI")])
570
571 ;; This attribute gives the integer mode that has half the size of
572 ;; the controlling mode.
573 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI") (TF "DI")])
574
575 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
576 ;;
577 ;; In certain cases, div.s and div.ps may have a rounding error
578 ;; and/or wrong inexact flag.
579 ;;
580 ;; Therefore, we only allow div.s if not working around SB-1 rev2
581 ;; errata or if a slight loss of precision is OK.
582 (define_mode_attr divide_condition
583   [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
584    (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
585
586 ;; This attribute gives the conditions under which SQRT.fmt instructions
587 ;; can be used.
588 (define_mode_attr sqrt_condition
589   [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
590
591 ;; This attribute gives the conditions under which RECIP.fmt and RSQRT.fmt
592 ;; instructions can be used.  The MIPS32 and MIPS64 ISAs say that RECIP.D
593 ;; and RSQRT.D are unpredictable when doubles are stored in pairs of FPRs,
594 ;; so for safety's sake, we apply this restriction to all targets.
595 (define_mode_attr recip_condition
596   [(SF "ISA_HAS_FP4")
597    (DF "ISA_HAS_FP4 && TARGET_FLOAT64")
598    (V2SF "TARGET_SB1")])
599
600 ;; This code iterator allows all branch instructions to be generated from
601 ;; a single define_expand template.
602 (define_code_iterator any_cond [unordered ordered unlt unge uneq ltgt unle ungt
603                                 eq ne gt ge lt le gtu geu ltu leu])
604
605 ;; This code iterator allows signed and unsigned widening multiplications
606 ;; to use the same template.
607 (define_code_iterator any_extend [sign_extend zero_extend])
608
609 ;; This code iterator allows the three shift instructions to be generated
610 ;; from the same template.
611 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
612
613 ;; This code iterator allows all native floating-point comparisons to be
614 ;; generated from the same template.
615 (define_code_iterator fcond [unordered uneq unlt unle eq lt le])
616
617 ;; This code iterator is used for comparisons that can be implemented
618 ;; by swapping the operands.
619 (define_code_iterator swapped_fcond [ge gt unge ungt])
620
621 ;; <u> expands to an empty string when doing a signed operation and
622 ;; "u" when doing an unsigned operation.
623 (define_code_attr u [(sign_extend "") (zero_extend "u")])
624
625 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
626 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
627
628 ;; <optab> expands to the name of the optab for a particular code.
629 (define_code_attr optab [(ashift "ashl")
630                          (ashiftrt "ashr")
631                          (lshiftrt "lshr")
632                          (ior "ior")
633                          (xor "xor")
634                          (and "and")])
635
636 ;; <insn> expands to the name of the insn that implements a particular code.
637 (define_code_attr insn [(ashift "sll")
638                         (ashiftrt "sra")
639                         (lshiftrt "srl")
640                         (ior "or")
641                         (xor "xor")
642                         (and "and")])
643
644 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
645 (define_code_attr fcond [(unordered "un")
646                          (uneq "ueq")
647                          (unlt "ult")
648                          (unle "ule")
649                          (eq "eq")
650                          (lt "lt")
651                          (le "le")])
652
653 ;; Similar, but for swapped conditions.
654 (define_code_attr swapped_fcond [(ge "le")
655                                  (gt "lt")
656                                  (unge "ule")
657                                  (ungt "ult")])
658
659 ;; Atomic fetch bitwise operations.
660 (define_code_iterator fetchop_bit [ior xor and])
661
662 ;; <immediate_insn> expands to the name of the insn that implements
663 ;; a particular code to operate in immediate values.
664 (define_code_attr immediate_insn [(ior "ori") (xor "xori") (and "andi")])
665
666 \f
667 ;; .........................
668 ;;
669 ;;      Branch, call and jump delay slots
670 ;;
671 ;; .........................
672
673 (define_delay (and (eq_attr "type" "branch")
674                    (eq (symbol_ref "TARGET_MIPS16") (const_int 0)))
675   [(eq_attr "can_delay" "yes")
676    (nil)
677    (and (eq_attr "branch_likely" "yes")
678         (eq_attr "can_delay" "yes"))])
679
680 (define_delay (eq_attr "type" "jump")
681   [(eq_attr "can_delay" "yes")
682    (nil)
683    (nil)])
684
685 (define_delay (and (eq_attr "type" "call")
686                    (eq_attr "jal_macro" "no"))
687   [(eq_attr "can_delay" "yes")
688    (nil)
689    (nil)])
690 \f
691 ;; Pipeline descriptions.
692 ;;
693 ;; generic.md provides a fallback for processors without a specific
694 ;; pipeline description.  It is derived from the old define_function_unit
695 ;; version and uses the "alu" and "imuldiv" units declared below.
696 ;;
697 ;; Some of the processor-specific files are also derived from old
698 ;; define_function_unit descriptions and simply override the parts of
699 ;; generic.md that don't apply.  The other processor-specific files
700 ;; are self-contained.
701 (define_automaton "alu,imuldiv")
702
703 (define_cpu_unit "alu" "alu")
704 (define_cpu_unit "imuldiv" "imuldiv")
705
706 (include "4k.md")
707 (include "5k.md")
708 (include "20kc.md")
709 (include "24k.md")
710 (include "74k.md")
711 (include "3000.md")
712 (include "4000.md")
713 (include "4100.md")
714 (include "4130.md")
715 (include "4300.md")
716 (include "4600.md")
717 (include "5000.md")
718 (include "5400.md")
719 (include "5500.md")
720 (include "6000.md")
721 (include "7000.md")
722 (include "9000.md")
723 (include "sb1.md")
724 (include "sr71k.md")
725 (include "generic.md")
726 \f
727 ;;
728 ;;  ....................
729 ;;
730 ;;      CONDITIONAL TRAPS
731 ;;
732 ;;  ....................
733 ;;
734
735 (define_insn "trap"
736   [(trap_if (const_int 1) (const_int 0))]
737   ""
738 {
739   if (ISA_HAS_COND_TRAP)
740     return "teq\t$0,$0";
741   else if (TARGET_MIPS16)
742     return "break 0";
743   else
744     return "break";
745 }
746   [(set_attr "type" "trap")])
747
748 (define_expand "conditional_trap"
749   [(trap_if (match_operator 0 "comparison_operator"
750                             [(match_dup 2) (match_dup 3)])
751             (match_operand 1 "const_int_operand"))]
752   "ISA_HAS_COND_TRAP"
753 {
754   if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) == MODE_INT
755       && operands[1] == const0_rtx)
756     {
757       mips_expand_conditional_trap (GET_CODE (operands[0]));
758       DONE;
759     }
760   FAIL;
761 })
762
763 (define_insn "*conditional_trap<mode>"
764   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
765                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
766                                  (match_operand:GPR 2 "arith_operand" "dI")])
767             (const_int 0))]
768   "ISA_HAS_COND_TRAP"
769   "t%C0\t%z1,%2"
770   [(set_attr "type" "trap")])
771 \f
772 ;;
773 ;;  ....................
774 ;;
775 ;;      ADDITION
776 ;;
777 ;;  ....................
778 ;;
779
780 (define_insn "add<mode>3"
781   [(set (match_operand:ANYF 0 "register_operand" "=f")
782         (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
783                    (match_operand:ANYF 2 "register_operand" "f")))]
784   ""
785   "add.<fmt>\t%0,%1,%2"
786   [(set_attr "type" "fadd")
787    (set_attr "mode" "<UNITMODE>")])
788
789 (define_expand "add<mode>3"
790   [(set (match_operand:GPR 0 "register_operand")
791         (plus:GPR (match_operand:GPR 1 "register_operand")
792                   (match_operand:GPR 2 "arith_operand")))]
793   "")
794
795 (define_insn "*add<mode>3"
796   [(set (match_operand:GPR 0 "register_operand" "=d,d")
797         (plus:GPR (match_operand:GPR 1 "register_operand" "d,d")
798                   (match_operand:GPR 2 "arith_operand" "d,Q")))]
799   "!TARGET_MIPS16"
800   "@
801     <d>addu\t%0,%1,%2
802     <d>addiu\t%0,%1,%2"
803   [(set_attr "type" "arith")
804    (set_attr "mode" "<MODE>")])
805
806 (define_insn "*add<mode>3_mips16"
807   [(set (match_operand:GPR 0 "register_operand" "=ks,d,d,d,d")
808         (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,0,d,d")
809                   (match_operand:GPR 2 "arith_operand" "Q,Q,Q,O,d")))]
810   "TARGET_MIPS16"
811   "@
812     <d>addiu\t%0,%2
813     <d>addiu\t%0,%1,%2
814     <d>addiu\t%0,%2
815     <d>addiu\t%0,%1,%2
816     <d>addu\t%0,%1,%2"
817   [(set_attr "type" "arith")
818    (set_attr "mode" "<MODE>")
819    (set_attr_alternative "length"
820                 [(if_then_else (match_operand 2 "m16_simm8_8")
821                                (const_int 4)
822                                (const_int 8))
823                  (if_then_else (match_operand 2 "m16_uimm<si8_di5>_4")
824                                (const_int 4)
825                                (const_int 8))
826                  (if_then_else (match_operand 2 "m16_simm<si8_di5>_1")
827                                (const_int 4)
828                                (const_int 8))
829                  (if_then_else (match_operand 2 "m16_simm4_1")
830                                (const_int 4)
831                                (const_int 8))
832                  (const_int 4)])])
833
834 ;; On the mips16, we can sometimes split an add of a constant which is
835 ;; a 4 byte instruction into two adds which are both 2 byte
836 ;; instructions.  There are two cases: one where we are adding a
837 ;; constant plus a register to another register, and one where we are
838 ;; simply adding a constant to a register.
839
840 (define_split
841   [(set (match_operand:SI 0 "register_operand")
842         (plus:SI (match_dup 0)
843                  (match_operand:SI 1 "const_int_operand")))]
844   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
845    && REG_P (operands[0])
846    && M16_REG_P (REGNO (operands[0]))
847    && GET_CODE (operands[1]) == CONST_INT
848    && ((INTVAL (operands[1]) > 0x7f
849         && INTVAL (operands[1]) <= 0x7f + 0x7f)
850        || (INTVAL (operands[1]) < - 0x80
851            && INTVAL (operands[1]) >= - 0x80 - 0x80))"
852   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
853    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
854 {
855   HOST_WIDE_INT val = INTVAL (operands[1]);
856
857   if (val >= 0)
858     {
859       operands[1] = GEN_INT (0x7f);
860       operands[2] = GEN_INT (val - 0x7f);
861     }
862   else
863     {
864       operands[1] = GEN_INT (- 0x80);
865       operands[2] = GEN_INT (val + 0x80);
866     }
867 })
868
869 (define_split
870   [(set (match_operand:SI 0 "register_operand")
871         (plus:SI (match_operand:SI 1 "register_operand")
872                  (match_operand:SI 2 "const_int_operand")))]
873   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
874    && REG_P (operands[0])
875    && M16_REG_P (REGNO (operands[0]))
876    && REG_P (operands[1])
877    && M16_REG_P (REGNO (operands[1]))
878    && REGNO (operands[0]) != REGNO (operands[1])
879    && GET_CODE (operands[2]) == CONST_INT
880    && ((INTVAL (operands[2]) > 0x7
881         && INTVAL (operands[2]) <= 0x7 + 0x7f)
882        || (INTVAL (operands[2]) < - 0x8
883            && INTVAL (operands[2]) >= - 0x8 - 0x80))"
884   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
885    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
886 {
887   HOST_WIDE_INT val = INTVAL (operands[2]);
888
889   if (val >= 0)
890     {
891       operands[2] = GEN_INT (0x7);
892       operands[3] = GEN_INT (val - 0x7);
893     }
894   else
895     {
896       operands[2] = GEN_INT (- 0x8);
897       operands[3] = GEN_INT (val + 0x8);
898     }
899 })
900
901 (define_split
902   [(set (match_operand:DI 0 "register_operand")
903         (plus:DI (match_dup 0)
904                  (match_operand:DI 1 "const_int_operand")))]
905   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
906    && REG_P (operands[0])
907    && M16_REG_P (REGNO (operands[0]))
908    && GET_CODE (operands[1]) == CONST_INT
909    && ((INTVAL (operands[1]) > 0xf
910         && INTVAL (operands[1]) <= 0xf + 0xf)
911        || (INTVAL (operands[1]) < - 0x10
912            && INTVAL (operands[1]) >= - 0x10 - 0x10))"
913   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
914    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
915 {
916   HOST_WIDE_INT val = INTVAL (operands[1]);
917
918   if (val >= 0)
919     {
920       operands[1] = GEN_INT (0xf);
921       operands[2] = GEN_INT (val - 0xf);
922     }
923   else
924     {
925       operands[1] = GEN_INT (- 0x10);
926       operands[2] = GEN_INT (val + 0x10);
927     }
928 })
929
930 (define_split
931   [(set (match_operand:DI 0 "register_operand")
932         (plus:DI (match_operand:DI 1 "register_operand")
933                  (match_operand:DI 2 "const_int_operand")))]
934   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
935    && REG_P (operands[0])
936    && M16_REG_P (REGNO (operands[0]))
937    && REG_P (operands[1])
938    && M16_REG_P (REGNO (operands[1]))
939    && REGNO (operands[0]) != REGNO (operands[1])
940    && GET_CODE (operands[2]) == CONST_INT
941    && ((INTVAL (operands[2]) > 0x7
942         && INTVAL (operands[2]) <= 0x7 + 0xf)
943        || (INTVAL (operands[2]) < - 0x8
944            && INTVAL (operands[2]) >= - 0x8 - 0x10))"
945   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
946    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
947 {
948   HOST_WIDE_INT val = INTVAL (operands[2]);
949
950   if (val >= 0)
951     {
952       operands[2] = GEN_INT (0x7);
953       operands[3] = GEN_INT (val - 0x7);
954     }
955   else
956     {
957       operands[2] = GEN_INT (- 0x8);
958       operands[3] = GEN_INT (val + 0x8);
959     }
960 })
961
962 (define_insn "*addsi3_extended"
963   [(set (match_operand:DI 0 "register_operand" "=d,d")
964         (sign_extend:DI
965              (plus:SI (match_operand:SI 1 "register_operand" "d,d")
966                       (match_operand:SI 2 "arith_operand" "d,Q"))))]
967   "TARGET_64BIT && !TARGET_MIPS16"
968   "@
969     addu\t%0,%1,%2
970     addiu\t%0,%1,%2"
971   [(set_attr "type" "arith")
972    (set_attr "mode" "SI")])
973
974 ;; Split this insn so that the addiu splitters can have a crack at it.
975 ;; Use a conservative length estimate until the split.
976 (define_insn_and_split "*addsi3_extended_mips16"
977   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
978         (sign_extend:DI
979              (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
980                       (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
981   "TARGET_64BIT && TARGET_MIPS16"
982   "#"
983   "&& reload_completed"
984   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
985   { operands[3] = gen_lowpart (SImode, operands[0]); }
986   [(set_attr "type" "arith")
987    (set_attr "mode" "SI")
988    (set_attr "extended_mips16" "yes")])
989 \f
990 ;;
991 ;;  ....................
992 ;;
993 ;;      SUBTRACTION
994 ;;
995 ;;  ....................
996 ;;
997
998 (define_insn "sub<mode>3"
999   [(set (match_operand:ANYF 0 "register_operand" "=f")
1000         (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1001                     (match_operand:ANYF 2 "register_operand" "f")))]
1002   ""
1003   "sub.<fmt>\t%0,%1,%2"
1004   [(set_attr "type" "fadd")
1005    (set_attr "mode" "<UNITMODE>")])
1006
1007 (define_insn "sub<mode>3"
1008   [(set (match_operand:GPR 0 "register_operand" "=d")
1009         (minus:GPR (match_operand:GPR 1 "register_operand" "d")
1010                    (match_operand:GPR 2 "register_operand" "d")))]
1011   ""
1012   "<d>subu\t%0,%1,%2"
1013   [(set_attr "type" "arith")
1014    (set_attr "mode" "<MODE>")])
1015
1016 (define_insn "*subsi3_extended"
1017   [(set (match_operand:DI 0 "register_operand" "=d")
1018         (sign_extend:DI
1019             (minus:SI (match_operand:SI 1 "register_operand" "d")
1020                       (match_operand:SI 2 "register_operand" "d"))))]
1021   "TARGET_64BIT"
1022   "subu\t%0,%1,%2"
1023   [(set_attr "type" "arith")
1024    (set_attr "mode" "DI")])
1025 \f
1026 ;;
1027 ;;  ....................
1028 ;;
1029 ;;      MULTIPLICATION
1030 ;;
1031 ;;  ....................
1032 ;;
1033
1034 (define_expand "mul<mode>3"
1035   [(set (match_operand:SCALARF 0 "register_operand")
1036         (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1037                       (match_operand:SCALARF 2 "register_operand")))]
1038   ""
1039   "")
1040
1041 (define_insn "*mul<mode>3"
1042   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1043         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1044                       (match_operand:SCALARF 2 "register_operand" "f")))]
1045   "!TARGET_4300_MUL_FIX"
1046   "mul.<fmt>\t%0,%1,%2"
1047   [(set_attr "type" "fmul")
1048    (set_attr "mode" "<MODE>")])
1049
1050 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1051 ;; operands may corrupt immediately following multiplies. This is a
1052 ;; simple fix to insert NOPs.
1053
1054 (define_insn "*mul<mode>3_r4300"
1055   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1056         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1057                       (match_operand:SCALARF 2 "register_operand" "f")))]
1058   "TARGET_4300_MUL_FIX"
1059   "mul.<fmt>\t%0,%1,%2\;nop"
1060   [(set_attr "type" "fmul")
1061    (set_attr "mode" "<MODE>")
1062    (set_attr "length" "8")])
1063
1064 (define_insn "mulv2sf3"
1065   [(set (match_operand:V2SF 0 "register_operand" "=f")
1066         (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1067                    (match_operand:V2SF 2 "register_operand" "f")))]
1068   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1069   "mul.ps\t%0,%1,%2"
1070   [(set_attr "type" "fmul")
1071    (set_attr "mode" "SF")])
1072
1073 ;; The original R4000 has a cpu bug.  If a double-word or a variable
1074 ;; shift executes while an integer multiplication is in progress, the
1075 ;; shift may give an incorrect result.  Avoid this by keeping the mflo
1076 ;; with the mult on the R4000.
1077 ;;
1078 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1079 ;; (also valid for MIPS R4000MC processors):
1080 ;;
1081 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1082 ;;      this errata description.
1083 ;;      The following code sequence causes the R4000 to incorrectly
1084 ;;      execute the Double Shift Right Arithmetic 32 (dsra32)
1085 ;;      instruction.  If the dsra32 instruction is executed during an
1086 ;;      integer multiply, the dsra32 will only shift by the amount in
1087 ;;      specified in the instruction rather than the amount plus 32
1088 ;;      bits.
1089 ;;      instruction 1:          mult    rs,rt           integer multiply
1090 ;;      instruction 2-12:       dsra32  rd,rt,rs        doubleword shift
1091 ;;                                                      right arithmetic + 32
1092 ;;      Workaround: A dsra32 instruction placed after an integer
1093 ;;      multiply should not be one of the 11 instructions after the
1094 ;;      multiply instruction."
1095 ;;
1096 ;; and:
1097 ;;
1098 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1099 ;;      the following description.
1100 ;;      All extended shifts (shift by n+32) and variable shifts (32 and
1101 ;;      64-bit versions) may produce incorrect results under the
1102 ;;      following conditions:
1103 ;;      1) An integer multiply is currently executing
1104 ;;      2) These types of shift instructions are executed immediately
1105 ;;         following an integer divide instruction.
1106 ;;      Workaround:
1107 ;;      1) Make sure no integer multiply is running wihen these
1108 ;;         instruction are executed.  If this cannot be predicted at
1109 ;;         compile time, then insert a "mfhi" to R0 instruction
1110 ;;         immediately after the integer multiply instruction.  This
1111 ;;         will cause the integer multiply to complete before the shift
1112 ;;         is executed.
1113 ;;      2) Separate integer divide and these two classes of shift
1114 ;;         instructions by another instruction or a noop."
1115 ;;
1116 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1117 ;; respectively.
1118
1119 (define_expand "mulsi3"
1120   [(set (match_operand:SI 0 "register_operand")
1121         (mult:SI (match_operand:SI 1 "register_operand")
1122                  (match_operand:SI 2 "register_operand")))]
1123   ""
1124 {
1125   if (ISA_HAS_MUL3)
1126     emit_insn (gen_mulsi3_mult3 (operands[0], operands[1], operands[2]));
1127   else if (TARGET_FIX_R4000)
1128     emit_insn (gen_mulsi3_r4000 (operands[0], operands[1], operands[2]));
1129   else
1130     emit_insn (gen_mulsi3_internal (operands[0], operands[1], operands[2]));
1131   DONE;
1132 })
1133
1134 (define_expand "muldi3"
1135   [(set (match_operand:DI 0 "register_operand")
1136         (mult:DI (match_operand:DI 1 "register_operand")
1137                  (match_operand:DI 2 "register_operand")))]
1138   "TARGET_64BIT"
1139 {
1140   if (TARGET_FIX_R4000)
1141     emit_insn (gen_muldi3_r4000 (operands[0], operands[1], operands[2]));
1142   else
1143     emit_insn (gen_muldi3_internal (operands[0], operands[1], operands[2]));
1144   DONE;
1145 })
1146
1147 (define_insn "mulsi3_mult3"
1148   [(set (match_operand:SI 0 "register_operand" "=d,l")
1149         (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1150                  (match_operand:SI 2 "register_operand" "d,d")))
1151    (clobber (match_scratch:SI 3 "=h,h"))
1152    (clobber (match_scratch:SI 4 "=l,X"))]
1153   "ISA_HAS_MUL3"
1154 {
1155   if (which_alternative == 1)
1156     return "mult\t%1,%2";
1157   if (TARGET_MIPS3900)
1158     return "mult\t%0,%1,%2";
1159   return "mul\t%0,%1,%2";
1160 }
1161   [(set_attr "type" "imul3,imul")
1162    (set_attr "mode" "SI")])
1163
1164 ;; If a register gets allocated to LO, and we spill to memory, the reload
1165 ;; will include a move from LO to a GPR.  Merge it into the multiplication
1166 ;; if it can set the GPR directly.
1167 ;;
1168 ;; Operand 0: LO
1169 ;; Operand 1: GPR (1st multiplication operand)
1170 ;; Operand 2: GPR (2nd multiplication operand)
1171 ;; Operand 3: HI
1172 ;; Operand 4: GPR (destination)
1173 (define_peephole2
1174   [(parallel
1175        [(set (match_operand:SI 0 "register_operand")
1176              (mult:SI (match_operand:SI 1 "register_operand")
1177                       (match_operand:SI 2 "register_operand")))
1178         (clobber (match_operand:SI 3 "register_operand"))
1179         (clobber (scratch:SI))])
1180    (set (match_operand:SI 4 "register_operand")
1181         (unspec [(match_dup 0) (match_dup 3)] UNSPEC_MFHILO))]
1182   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1183   [(parallel
1184        [(set (match_dup 4)
1185              (mult:SI (match_dup 1)
1186                       (match_dup 2)))
1187         (clobber (match_dup 3))
1188         (clobber (match_dup 0))])])
1189
1190 (define_insn "mul<mode>3_internal"
1191   [(set (match_operand:GPR 0 "register_operand" "=l")
1192         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1193                   (match_operand:GPR 2 "register_operand" "d")))
1194    (clobber (match_scratch:GPR 3 "=h"))]
1195   "!TARGET_FIX_R4000"
1196   "<d>mult\t%1,%2"
1197   [(set_attr "type" "imul")
1198    (set_attr "mode" "<MODE>")])
1199
1200 (define_insn "mul<mode>3_r4000"
1201   [(set (match_operand:GPR 0 "register_operand" "=d")
1202         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1203                   (match_operand:GPR 2 "register_operand" "d")))
1204    (clobber (match_scratch:GPR 3 "=h"))
1205    (clobber (match_scratch:GPR 4 "=l"))]
1206   "TARGET_FIX_R4000"
1207   "<d>mult\t%1,%2\;mflo\t%0"
1208   [(set_attr "type" "imul")
1209    (set_attr "mode" "<MODE>")
1210    (set_attr "length" "8")])
1211
1212 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1213 ;; of "mult; mflo".  They have the same latency, but the first form gives
1214 ;; us an extra cycle to compute the operands.
1215
1216 ;; Operand 0: LO
1217 ;; Operand 1: GPR (1st multiplication operand)
1218 ;; Operand 2: GPR (2nd multiplication operand)
1219 ;; Operand 3: HI
1220 ;; Operand 4: GPR (destination)
1221 (define_peephole2
1222   [(parallel
1223        [(set (match_operand:SI 0 "register_operand")
1224              (mult:SI (match_operand:SI 1 "register_operand")
1225                       (match_operand:SI 2 "register_operand")))
1226         (clobber (match_operand:SI 3 "register_operand"))])
1227    (set (match_operand:SI 4 "register_operand")
1228         (unspec:SI [(match_dup 0) (match_dup 3)] UNSPEC_MFHILO))]
1229   "ISA_HAS_MACC && !ISA_HAS_MUL3"
1230   [(set (match_dup 0)
1231         (const_int 0))
1232    (parallel
1233        [(set (match_dup 0)
1234              (plus:SI (mult:SI (match_dup 1)
1235                                (match_dup 2))
1236                       (match_dup 0)))
1237         (set (match_dup 4)
1238              (plus:SI (mult:SI (match_dup 1)
1239                                (match_dup 2))
1240                       (match_dup 0)))
1241         (clobber (match_dup 3))])])
1242
1243 ;; Multiply-accumulate patterns
1244
1245 ;; For processors that can copy the output to a general register:
1246 ;;
1247 ;; The all-d alternative is needed because the combiner will find this
1248 ;; pattern and then register alloc/reload will move registers around to
1249 ;; make them fit, and we don't want to trigger unnecessary loads to LO.
1250 ;;
1251 ;; The last alternative should be made slightly less desirable, but adding
1252 ;; "?" to the constraint is too strong, and causes values to be loaded into
1253 ;; LO even when that's more costly.  For now, using "*d" mostly does the
1254 ;; trick.
1255 (define_insn "*mul_acc_si"
1256   [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
1257         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1258                           (match_operand:SI 2 "register_operand" "d,d,d"))
1259                  (match_operand:SI 3 "register_operand" "0,l,*d")))
1260    (clobber (match_scratch:SI 4 "=h,h,h"))
1261    (clobber (match_scratch:SI 5 "=X,3,l"))
1262    (clobber (match_scratch:SI 6 "=X,X,&d"))]
1263   "(TARGET_MIPS3900
1264    || GENERATE_MADD_MSUB)
1265    && !TARGET_MIPS16"
1266 {
1267   static const char *const madd[] = { "madd\t%1,%2", "madd\t%0,%1,%2" };
1268   if (which_alternative == 2)
1269     return "#";
1270   if (GENERATE_MADD_MSUB && which_alternative != 0)
1271     return "#";
1272   return madd[which_alternative];
1273 }
1274   [(set_attr "type"     "imadd")
1275    (set_attr "mode"     "SI")
1276    (set_attr "length"   "4,4,8")])
1277
1278 ;; Split the above insn if we failed to get LO allocated.
1279 (define_split
1280   [(set (match_operand:SI 0 "register_operand")
1281         (plus:SI (mult:SI (match_operand:SI 1 "register_operand")
1282                           (match_operand:SI 2 "register_operand"))
1283                  (match_operand:SI 3 "register_operand")))
1284    (clobber (match_scratch:SI 4))
1285    (clobber (match_scratch:SI 5))
1286    (clobber (match_scratch:SI 6))]
1287   "reload_completed && !TARGET_DEBUG_D_MODE
1288    && GP_REG_P (true_regnum (operands[0]))
1289    && GP_REG_P (true_regnum (operands[3]))"
1290   [(parallel [(set (match_dup 6)
1291                    (mult:SI (match_dup 1) (match_dup 2)))
1292               (clobber (match_dup 4))
1293               (clobber (match_dup 5))])
1294    (set (match_dup 0) (plus:SI (match_dup 6) (match_dup 3)))]
1295   "")
1296
1297 ;; Splitter to copy result of MADD to a general register
1298 (define_split
1299   [(set (match_operand:SI                   0 "register_operand")
1300         (plus:SI (mult:SI (match_operand:SI 1 "register_operand")
1301                           (match_operand:SI 2 "register_operand"))
1302                  (match_operand:SI          3 "register_operand")))
1303    (clobber (match_scratch:SI               4))
1304    (clobber (match_scratch:SI               5))
1305    (clobber (match_scratch:SI               6))]
1306   "reload_completed && !TARGET_DEBUG_D_MODE
1307    && GP_REG_P (true_regnum (operands[0]))
1308    && true_regnum (operands[3]) == LO_REGNUM"
1309   [(parallel [(set (match_dup 3)
1310                    (plus:SI (mult:SI (match_dup 1) (match_dup 2))
1311                             (match_dup 3)))
1312               (clobber (match_dup 4))
1313               (clobber (match_dup 5))
1314               (clobber (match_dup 6))])
1315    (set (match_dup 0) (unspec:SI [(match_dup 5) (match_dup 4)] UNSPEC_MFHILO))]
1316   "")
1317
1318 (define_insn "*macc"
1319   [(set (match_operand:SI 0 "register_operand" "=l,d")
1320         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1321                           (match_operand:SI 2 "register_operand" "d,d"))
1322                  (match_operand:SI 3 "register_operand" "0,l")))
1323    (clobber (match_scratch:SI 4 "=h,h"))
1324    (clobber (match_scratch:SI 5 "=X,3"))]
1325   "ISA_HAS_MACC"
1326 {
1327   if (which_alternative == 1)
1328     return "macc\t%0,%1,%2";
1329   else if (TARGET_MIPS5500)
1330     return "madd\t%1,%2";
1331   else
1332     /* The VR4130 assumes that there is a two-cycle latency between a macc
1333        that "writes" to $0 and an instruction that reads from it.  We avoid
1334        this by assigning to $1 instead.  */
1335     return "%[macc\t%@,%1,%2%]";
1336 }
1337   [(set_attr "type" "imadd")
1338    (set_attr "mode" "SI")])
1339
1340 (define_insn "*msac"
1341   [(set (match_operand:SI 0 "register_operand" "=l,d")
1342         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1343                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1344                            (match_operand:SI 3 "register_operand" "d,d"))))
1345    (clobber (match_scratch:SI 4 "=h,h"))
1346    (clobber (match_scratch:SI 5 "=X,1"))]
1347   "ISA_HAS_MSAC"
1348 {
1349   if (which_alternative == 1)
1350     return "msac\t%0,%2,%3";
1351   else if (TARGET_MIPS5500)
1352     return "msub\t%2,%3";
1353   else
1354     return "msac\t$0,%2,%3";
1355 }
1356   [(set_attr "type"     "imadd")
1357    (set_attr "mode"     "SI")])
1358
1359 ;; An msac-like instruction implemented using negation and a macc.
1360 (define_insn_and_split "*msac_using_macc"
1361   [(set (match_operand:SI 0 "register_operand" "=l,d")
1362         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1363                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1364                            (match_operand:SI 3 "register_operand" "d,d"))))
1365    (clobber (match_scratch:SI 4 "=h,h"))
1366    (clobber (match_scratch:SI 5 "=X,1"))
1367    (clobber (match_scratch:SI 6 "=d,d"))]
1368   "ISA_HAS_MACC && !ISA_HAS_MSAC"
1369   "#"
1370   "&& reload_completed"
1371   [(set (match_dup 6)
1372         (neg:SI (match_dup 3)))
1373    (parallel
1374        [(set (match_dup 0)
1375              (plus:SI (mult:SI (match_dup 2)
1376                                (match_dup 6))
1377                       (match_dup 1)))
1378         (clobber (match_dup 4))
1379         (clobber (match_dup 5))])]
1380   ""
1381   [(set_attr "type"     "imadd")
1382    (set_attr "length"   "8")])
1383
1384 ;; Patterns generated by the define_peephole2 below.
1385
1386 (define_insn "*macc2"
1387   [(set (match_operand:SI 0 "register_operand" "=l")
1388         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1389                           (match_operand:SI 2 "register_operand" "d"))
1390                  (match_dup 0)))
1391    (set (match_operand:SI 3 "register_operand" "=d")
1392         (plus:SI (mult:SI (match_dup 1)
1393                           (match_dup 2))
1394                  (match_dup 0)))
1395    (clobber (match_scratch:SI 4 "=h"))]
1396   "ISA_HAS_MACC && reload_completed"
1397   "macc\t%3,%1,%2"
1398   [(set_attr "type"     "imadd")
1399    (set_attr "mode"     "SI")])
1400
1401 (define_insn "*msac2"
1402   [(set (match_operand:SI 0 "register_operand" "=l")
1403         (minus:SI (match_dup 0)
1404                   (mult:SI (match_operand:SI 1 "register_operand" "d")
1405                            (match_operand:SI 2 "register_operand" "d"))))
1406    (set (match_operand:SI 3 "register_operand" "=d")
1407         (minus:SI (match_dup 0)
1408                   (mult:SI (match_dup 1)
1409                            (match_dup 2))))
1410    (clobber (match_scratch:SI 4 "=h"))]
1411   "ISA_HAS_MSAC && reload_completed"
1412   "msac\t%3,%1,%2"
1413   [(set_attr "type"     "imadd")
1414    (set_attr "mode"     "SI")])
1415
1416 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1417 ;; Similarly msac.
1418 ;;
1419 ;; Operand 0: LO
1420 ;; Operand 1: macc/msac
1421 ;; Operand 2: HI
1422 ;; Operand 3: GPR (destination)
1423 (define_peephole2
1424   [(parallel
1425        [(set (match_operand:SI 0 "register_operand")
1426              (match_operand:SI 1 "macc_msac_operand"))
1427         (clobber (match_operand:SI 2 "register_operand"))
1428         (clobber (scratch:SI))])
1429    (set (match_operand:SI 3 "register_operand")
1430         (unspec:SI [(match_dup 0) (match_dup 2)] UNSPEC_MFHILO))]
1431   ""
1432   [(parallel [(set (match_dup 0)
1433                    (match_dup 1))
1434               (set (match_dup 3)
1435                    (match_dup 1))
1436               (clobber (match_dup 2))])]
1437   "")
1438
1439 ;; When we have a three-address multiplication instruction, it should
1440 ;; be faster to do a separate multiply and add, rather than moving
1441 ;; something into LO in order to use a macc instruction.
1442 ;;
1443 ;; This peephole needs a scratch register to cater for the case when one
1444 ;; of the multiplication operands is the same as the destination.
1445 ;;
1446 ;; Operand 0: GPR (scratch)
1447 ;; Operand 1: LO
1448 ;; Operand 2: GPR (addend)
1449 ;; Operand 3: GPR (destination)
1450 ;; Operand 4: macc/msac
1451 ;; Operand 5: HI
1452 ;; Operand 6: new multiplication
1453 ;; Operand 7: new addition/subtraction
1454 (define_peephole2
1455   [(match_scratch:SI 0 "d")
1456    (set (match_operand:SI 1 "register_operand")
1457         (match_operand:SI 2 "register_operand"))
1458    (match_dup 0)
1459    (parallel
1460        [(set (match_operand:SI 3 "register_operand")
1461              (match_operand:SI 4 "macc_msac_operand"))
1462         (clobber (match_operand:SI 5 "register_operand"))
1463         (clobber (match_dup 1))])]
1464   "ISA_HAS_MUL3
1465    && true_regnum (operands[1]) == LO_REGNUM
1466    && peep2_reg_dead_p (2, operands[1])
1467    && GP_REG_P (true_regnum (operands[3]))"
1468   [(parallel [(set (match_dup 0)
1469                    (match_dup 6))
1470               (clobber (match_dup 5))
1471               (clobber (match_dup 1))])
1472    (set (match_dup 3)
1473         (match_dup 7))]
1474 {
1475   operands[6] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1476   operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1477                                 operands[2], operands[0]);
1478 })
1479
1480 ;; Same as above, except LO is the initial target of the macc.
1481 ;;
1482 ;; Operand 0: GPR (scratch)
1483 ;; Operand 1: LO
1484 ;; Operand 2: GPR (addend)
1485 ;; Operand 3: macc/msac
1486 ;; Operand 4: HI
1487 ;; Operand 5: GPR (destination)
1488 ;; Operand 6: new multiplication
1489 ;; Operand 7: new addition/subtraction
1490 (define_peephole2
1491   [(match_scratch:SI 0 "d")
1492    (set (match_operand:SI 1 "register_operand")
1493         (match_operand:SI 2 "register_operand"))
1494    (match_dup 0)
1495    (parallel
1496        [(set (match_dup 1)
1497              (match_operand:SI 3 "macc_msac_operand"))
1498         (clobber (match_operand:SI 4 "register_operand"))
1499         (clobber (scratch:SI))])
1500    (match_dup 0)
1501    (set (match_operand:SI 5 "register_operand")
1502         (unspec:SI [(match_dup 1) (match_dup 4)] UNSPEC_MFHILO))]
1503   "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1504   [(parallel [(set (match_dup 0)
1505                    (match_dup 6))
1506               (clobber (match_dup 4))
1507               (clobber (match_dup 1))])
1508    (set (match_dup 5)
1509         (match_dup 7))]
1510 {
1511   operands[6] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1512   operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1513                                 operands[2], operands[0]);
1514 })
1515
1516 (define_insn "*mul_sub_si"
1517   [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
1518         (minus:SI (match_operand:SI 1 "register_operand" "0,l,*d")
1519                   (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
1520                            (match_operand:SI 3 "register_operand" "d,d,d"))))
1521    (clobber (match_scratch:SI 4 "=h,h,h"))
1522    (clobber (match_scratch:SI 5 "=X,1,l"))
1523    (clobber (match_scratch:SI 6 "=X,X,&d"))]
1524   "GENERATE_MADD_MSUB"
1525   "@
1526    msub\t%2,%3
1527    #
1528    #"
1529   [(set_attr "type"     "imadd")
1530    (set_attr "mode"     "SI")
1531    (set_attr "length"   "4,8,8")])
1532
1533 ;; Split the above insn if we failed to get LO allocated.
1534 (define_split
1535   [(set (match_operand:SI 0 "register_operand")
1536         (minus:SI (match_operand:SI 1 "register_operand")
1537                   (mult:SI (match_operand:SI 2 "register_operand")
1538                            (match_operand:SI 3 "register_operand"))))
1539    (clobber (match_scratch:SI 4))
1540    (clobber (match_scratch:SI 5))
1541    (clobber (match_scratch:SI 6))]
1542   "reload_completed && !TARGET_DEBUG_D_MODE
1543    && GP_REG_P (true_regnum (operands[0]))
1544    && GP_REG_P (true_regnum (operands[1]))"
1545   [(parallel [(set (match_dup 6)
1546                    (mult:SI (match_dup 2) (match_dup 3)))
1547               (clobber (match_dup 4))
1548               (clobber (match_dup 5))])
1549    (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 6)))]
1550   "")
1551
1552 ;; Splitter to copy result of MSUB to a general register
1553 (define_split
1554   [(set (match_operand:SI 0 "register_operand")
1555         (minus:SI (match_operand:SI 1 "register_operand")
1556                   (mult:SI (match_operand:SI 2 "register_operand")
1557                            (match_operand:SI 3 "register_operand"))))
1558    (clobber (match_scratch:SI 4))
1559    (clobber (match_scratch:SI 5))
1560    (clobber (match_scratch:SI 6))]
1561   "reload_completed && !TARGET_DEBUG_D_MODE
1562    && GP_REG_P (true_regnum (operands[0]))
1563    && true_regnum (operands[1]) == LO_REGNUM"
1564   [(parallel [(set (match_dup 1)
1565                    (minus:SI (match_dup 1)
1566                              (mult:SI (match_dup 2) (match_dup 3))))
1567               (clobber (match_dup 4))
1568               (clobber (match_dup 5))
1569               (clobber (match_dup 6))])
1570    (set (match_dup 0) (unspec:SI [(match_dup 5) (match_dup 4)] UNSPEC_MFHILO))]
1571   "")
1572
1573 (define_insn "*muls"
1574   [(set (match_operand:SI                  0 "register_operand" "=l,d")
1575         (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1576                          (match_operand:SI 2 "register_operand" "d,d"))))
1577    (clobber (match_scratch:SI              3                    "=h,h"))
1578    (clobber (match_scratch:SI              4                    "=X,l"))]
1579   "ISA_HAS_MULS"
1580   "@
1581    muls\t$0,%1,%2
1582    muls\t%0,%1,%2"
1583   [(set_attr "type"     "imul,imul3")
1584    (set_attr "mode"     "SI")])
1585
1586 ;; ??? We could define a mulditi3 pattern when TARGET_64BIT.
1587
1588 (define_expand "<u>mulsidi3"
1589   [(parallel
1590       [(set (match_operand:DI 0 "register_operand")
1591             (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1592                      (any_extend:DI (match_operand:SI 2 "register_operand"))))
1593        (clobber (scratch:DI))
1594        (clobber (scratch:DI))
1595        (clobber (scratch:DI))])]
1596   "!TARGET_64BIT || !TARGET_FIX_R4000"
1597 {
1598   if (!TARGET_64BIT)
1599     {
1600       if (!TARGET_FIX_R4000)
1601         emit_insn (gen_<u>mulsidi3_32bit_internal (operands[0], operands[1],
1602                                                    operands[2]));
1603       else
1604         emit_insn (gen_<u>mulsidi3_32bit_r4000 (operands[0], operands[1],
1605                                                 operands[2]));
1606       DONE;
1607     }
1608 })
1609
1610 (define_insn "<u>mulsidi3_32bit_internal"
1611   [(set (match_operand:DI 0 "register_operand" "=x")
1612         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1613                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
1614   "!TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DSPR2"
1615   "mult<u>\t%1,%2"
1616   [(set_attr "type" "imul")
1617    (set_attr "mode" "SI")])
1618
1619 (define_insn "<u>mulsidi3_32bit_r4000"
1620   [(set (match_operand:DI 0 "register_operand" "=d")
1621         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1622                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1623    (clobber (match_scratch:DI 3 "=x"))]
1624   "!TARGET_64BIT && TARGET_FIX_R4000"
1625   "mult<u>\t%1,%2\;mflo\t%L0;mfhi\t%M0"
1626   [(set_attr "type" "imul")
1627    (set_attr "mode" "SI")
1628    (set_attr "length" "12")])
1629
1630 (define_insn_and_split "*<u>mulsidi3_64bit"
1631   [(set (match_operand:DI 0 "register_operand" "=d")
1632         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1633                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1634    (clobber (match_scratch:DI 3 "=l"))
1635    (clobber (match_scratch:DI 4 "=h"))
1636    (clobber (match_scratch:DI 5 "=d"))]
1637   "TARGET_64BIT && !TARGET_FIX_R4000"
1638   "#"
1639   "&& reload_completed"
1640   [(parallel
1641        [(set (match_dup 3)
1642              (sign_extend:DI
1643                 (mult:SI (match_dup 1)
1644                          (match_dup 2))))
1645         (set (match_dup 4)
1646              (ashiftrt:DI
1647                 (mult:DI (any_extend:DI (match_dup 1))
1648                          (any_extend:DI (match_dup 2)))
1649                 (const_int 32)))])
1650
1651    ;; OP5 <- LO, OP0 <- HI
1652    (set (match_dup 5) (unspec:DI [(match_dup 3) (match_dup 4)] UNSPEC_MFHILO))
1653    (set (match_dup 0) (unspec:DI [(match_dup 4) (match_dup 3)] UNSPEC_MFHILO))
1654
1655    ;; Zero-extend OP5.
1656    (set (match_dup 5)
1657         (ashift:DI (match_dup 5)
1658                    (const_int 32)))
1659    (set (match_dup 5)
1660         (lshiftrt:DI (match_dup 5)
1661                      (const_int 32)))
1662
1663    ;; Shift OP0 into place.
1664    (set (match_dup 0)
1665         (ashift:DI (match_dup 0)
1666                    (const_int 32)))
1667
1668    ;; OR the two halves together
1669    (set (match_dup 0)
1670         (ior:DI (match_dup 0)
1671                 (match_dup 5)))]
1672   ""
1673   [(set_attr "type" "imul")
1674    (set_attr "mode" "SI")
1675    (set_attr "length" "24")])
1676
1677 (define_insn "*<u>mulsidi3_64bit_parts"
1678   [(set (match_operand:DI 0 "register_operand" "=l")
1679         (sign_extend:DI
1680            (mult:SI (match_operand:SI 2 "register_operand" "d")
1681                     (match_operand:SI 3 "register_operand" "d"))))
1682    (set (match_operand:DI 1 "register_operand" "=h")
1683         (ashiftrt:DI
1684            (mult:DI (any_extend:DI (match_dup 2))
1685                     (any_extend:DI (match_dup 3)))
1686            (const_int 32)))]
1687   "TARGET_64BIT && !TARGET_FIX_R4000"
1688   "mult<u>\t%2,%3"
1689   [(set_attr "type" "imul")
1690    (set_attr "mode" "SI")])
1691
1692 ;; Widening multiply with negation.
1693 (define_insn "*muls<u>_di"
1694   [(set (match_operand:DI 0 "register_operand" "=x")
1695         (neg:DI
1696          (mult:DI
1697           (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1698           (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1699   "!TARGET_64BIT && ISA_HAS_MULS"
1700   "muls<u>\t$0,%1,%2"
1701   [(set_attr "type" "imul")
1702    (set_attr "mode" "SI")])
1703
1704 (define_insn "<u>msubsidi4"
1705   [(set (match_operand:DI 0 "register_operand" "=ka")
1706         (minus:DI
1707            (match_operand:DI 3 "register_operand" "0")
1708            (mult:DI
1709               (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1710               (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1711   "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSPR2)"
1712 {
1713   if (ISA_HAS_DSPR2)
1714     return "msub<u>\t%q0,%1,%2";
1715   else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
1716     return "msub<u>\t%1,%2";
1717   else
1718     return "msac<u>\t$0,%1,%2";
1719 }
1720   [(set_attr "type" "imadd")
1721    (set_attr "mode" "SI")])
1722
1723 ;; _highpart patterns
1724
1725 (define_expand "<su>mulsi3_highpart"
1726   [(set (match_operand:SI 0 "register_operand")
1727         (truncate:SI
1728          (lshiftrt:DI
1729           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1730                    (any_extend:DI (match_operand:SI 2 "register_operand")))
1731           (const_int 32))))]
1732   "ISA_HAS_MULHI || !TARGET_FIX_R4000"
1733 {
1734   if (ISA_HAS_MULHI)
1735     emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
1736                                                        operands[1],
1737                                                        operands[2]));
1738   else
1739     emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
1740                                                  operands[2]));
1741   DONE;
1742 })
1743
1744 (define_insn "<su>mulsi3_highpart_internal"
1745   [(set (match_operand:SI 0 "register_operand" "=h")
1746         (truncate:SI
1747          (lshiftrt:DI
1748           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1749                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1750           (const_int 32))))
1751    (clobber (match_scratch:SI 3 "=l"))]
1752   "!ISA_HAS_MULHI && !TARGET_FIX_R4000"
1753   "mult<u>\t%1,%2"
1754   [(set_attr "type" "imul")
1755    (set_attr "mode" "SI")])
1756
1757 (define_insn "<su>mulsi3_highpart_mulhi_internal"
1758   [(set (match_operand:SI 0 "register_operand" "=h,d")
1759         (truncate:SI
1760          (lshiftrt:DI
1761           (mult:DI
1762            (any_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
1763            (any_extend:DI (match_operand:SI 2 "register_operand" "d,d")))
1764           (const_int 32))))
1765    (clobber (match_scratch:SI 3 "=l,l"))
1766    (clobber (match_scratch:SI 4 "=X,h"))]
1767   "ISA_HAS_MULHI"
1768   "@
1769    mult<u>\t%1,%2
1770    mulhi<u>\t%0,%1,%2"
1771   [(set_attr "type" "imul,imul3")
1772    (set_attr "mode" "SI")])
1773
1774 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
1775   [(set (match_operand:SI 0 "register_operand" "=h,d")
1776         (truncate:SI
1777          (lshiftrt:DI
1778           (neg:DI
1779            (mult:DI
1780             (any_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
1781             (any_extend:DI (match_operand:SI 2 "register_operand" "d,d"))))
1782           (const_int 32))))
1783    (clobber (match_scratch:SI 3 "=l,l"))
1784    (clobber (match_scratch:SI 4 "=X,h"))]
1785   "ISA_HAS_MULHI"
1786   "@
1787    mulshi<u>\t%.,%1,%2
1788    mulshi<u>\t%0,%1,%2"
1789   [(set_attr "type" "imul,imul3")
1790    (set_attr "mode" "SI")])
1791
1792 ;; Disable unsigned multiplication for -mfix-vr4120.  This is for VR4120
1793 ;; errata MD(0), which says that dmultu does not always produce the
1794 ;; correct result.
1795 (define_insn "<su>muldi3_highpart"
1796   [(set (match_operand:DI 0 "register_operand" "=h")
1797         (truncate:DI
1798          (lshiftrt:TI
1799           (mult:TI
1800            (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
1801            (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
1802           (const_int 64))))
1803    (clobber (match_scratch:DI 3 "=l"))]
1804   "TARGET_64BIT && !TARGET_FIX_R4000
1805    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
1806   "dmult<u>\t%1,%2"
1807   [(set_attr "type" "imul")
1808    (set_attr "mode" "DI")])
1809
1810 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
1811 ;; instruction.  The HI/LO registers are used as a 64-bit accumulator.
1812
1813 (define_insn "madsi"
1814   [(set (match_operand:SI 0 "register_operand" "+l")
1815         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1816                           (match_operand:SI 2 "register_operand" "d"))
1817                  (match_dup 0)))
1818    (clobber (match_scratch:SI 3 "=h"))]
1819   "TARGET_MAD"
1820   "mad\t%1,%2"
1821   [(set_attr "type"     "imadd")
1822    (set_attr "mode"     "SI")])
1823
1824 (define_insn "<u>maddsidi4"
1825   [(set (match_operand:DI 0 "register_operand" "=ka")
1826         (plus:DI
1827          (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1828                   (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1829          (match_operand:DI 3 "register_operand" "0")))]
1830   "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSPR2)
1831    && !TARGET_64BIT"
1832 {
1833   if (TARGET_MAD)
1834     return "mad<u>\t%1,%2";
1835   else if (ISA_HAS_DSPR2)
1836     return "madd<u>\t%q0,%1,%2";
1837   else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
1838     return "madd<u>\t%1,%2";
1839   else
1840     /* See comment in *macc.  */
1841     return "%[macc<u>\t%@,%1,%2%]";
1842 }
1843   [(set_attr "type" "imadd")
1844    (set_attr "mode" "SI")])
1845
1846 ;; Floating point multiply accumulate instructions.
1847
1848 (define_insn "*madd<mode>"
1849   [(set (match_operand:ANYF 0 "register_operand" "=f")
1850         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1851                               (match_operand:ANYF 2 "register_operand" "f"))
1852                    (match_operand:ANYF 3 "register_operand" "f")))]
1853   "ISA_HAS_FP4 && TARGET_FUSED_MADD"
1854   "madd.<fmt>\t%0,%3,%1,%2"
1855   [(set_attr "type" "fmadd")
1856    (set_attr "mode" "<UNITMODE>")])
1857
1858 (define_insn "*msub<mode>"
1859   [(set (match_operand:ANYF 0 "register_operand" "=f")
1860         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1861                                (match_operand:ANYF 2 "register_operand" "f"))
1862                     (match_operand:ANYF 3 "register_operand" "f")))]
1863   "ISA_HAS_FP4 && TARGET_FUSED_MADD"
1864   "msub.<fmt>\t%0,%3,%1,%2"
1865   [(set_attr "type" "fmadd")
1866    (set_attr "mode" "<UNITMODE>")])
1867
1868 (define_insn "*nmadd<mode>"
1869   [(set (match_operand:ANYF 0 "register_operand" "=f")
1870         (neg:ANYF (plus:ANYF
1871                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1872                               (match_operand:ANYF 2 "register_operand" "f"))
1873                    (match_operand:ANYF 3 "register_operand" "f"))))]
1874   "ISA_HAS_NMADD_NMSUB (<MODE>mode)
1875    && TARGET_FUSED_MADD
1876    && HONOR_SIGNED_ZEROS (<MODE>mode)
1877    && !HONOR_NANS (<MODE>mode)"
1878   "nmadd.<fmt>\t%0,%3,%1,%2"
1879   [(set_attr "type" "fmadd")
1880    (set_attr "mode" "<UNITMODE>")])
1881
1882 (define_insn "*nmadd<mode>_fastmath"
1883   [(set (match_operand:ANYF 0 "register_operand" "=f")
1884         (minus:ANYF
1885          (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
1886                     (match_operand:ANYF 2 "register_operand" "f"))
1887          (match_operand:ANYF 3 "register_operand" "f")))]
1888   "ISA_HAS_NMADD_NMSUB (<MODE>mode)
1889    && TARGET_FUSED_MADD
1890    && !HONOR_SIGNED_ZEROS (<MODE>mode)
1891    && !HONOR_NANS (<MODE>mode)"
1892   "nmadd.<fmt>\t%0,%3,%1,%2"
1893   [(set_attr "type" "fmadd")
1894    (set_attr "mode" "<UNITMODE>")])
1895
1896 (define_insn "*nmsub<mode>"
1897   [(set (match_operand:ANYF 0 "register_operand" "=f")
1898         (neg:ANYF (minus:ANYF
1899                    (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
1900                               (match_operand:ANYF 3 "register_operand" "f"))
1901                    (match_operand:ANYF 1 "register_operand" "f"))))]
1902   "ISA_HAS_NMADD_NMSUB (<MODE>mode)
1903    && TARGET_FUSED_MADD
1904    && HONOR_SIGNED_ZEROS (<MODE>mode)
1905    && !HONOR_NANS (<MODE>mode)"
1906   "nmsub.<fmt>\t%0,%1,%2,%3"
1907   [(set_attr "type" "fmadd")
1908    (set_attr "mode" "<UNITMODE>")])
1909
1910 (define_insn "*nmsub<mode>_fastmath"
1911   [(set (match_operand:ANYF 0 "register_operand" "=f")
1912         (minus:ANYF
1913          (match_operand:ANYF 1 "register_operand" "f")
1914          (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
1915                     (match_operand:ANYF 3 "register_operand" "f"))))]
1916   "ISA_HAS_NMADD_NMSUB (<MODE>mode)
1917    && TARGET_FUSED_MADD
1918    && !HONOR_SIGNED_ZEROS (<MODE>mode)
1919    && !HONOR_NANS (<MODE>mode)"
1920   "nmsub.<fmt>\t%0,%1,%2,%3"
1921   [(set_attr "type" "fmadd")
1922    (set_attr "mode" "<UNITMODE>")])
1923 \f
1924 ;;
1925 ;;  ....................
1926 ;;
1927 ;;      DIVISION and REMAINDER
1928 ;;
1929 ;;  ....................
1930 ;;
1931
1932 (define_expand "div<mode>3"
1933   [(set (match_operand:ANYF 0 "register_operand")
1934         (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
1935                   (match_operand:ANYF 2 "register_operand")))]
1936   "<divide_condition>"
1937 {
1938   if (const_1_operand (operands[1], <MODE>mode))
1939     if (!(ISA_HAS_FP4 && flag_unsafe_math_optimizations))
1940       operands[1] = force_reg (<MODE>mode, operands[1]);
1941 })
1942
1943 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
1944 ;;
1945 ;; If an mfc1 or dmfc1 happens to access the floating point register
1946 ;; file at the same time a long latency operation (div, sqrt, recip,
1947 ;; sqrt) iterates an intermediate result back through the floating
1948 ;; point register file bypass, then instead returning the correct
1949 ;; register value the mfc1 or dmfc1 operation returns the intermediate
1950 ;; result of the long latency operation.
1951 ;;
1952 ;; The workaround is to insert an unconditional 'mov' from/to the
1953 ;; long latency op destination register.
1954
1955 (define_insn "*div<mode>3"
1956   [(set (match_operand:ANYF 0 "register_operand" "=f")
1957         (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
1958                   (match_operand:ANYF 2 "register_operand" "f")))]
1959   "<divide_condition>"
1960 {
1961   if (TARGET_FIX_SB1)
1962     return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
1963   else
1964     return "div.<fmt>\t%0,%1,%2";
1965 }
1966   [(set_attr "type" "fdiv")
1967    (set_attr "mode" "<UNITMODE>")
1968    (set (attr "length")
1969         (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1970                       (const_int 8)
1971                       (const_int 4)))])
1972
1973 (define_insn "*recip<mode>3"
1974   [(set (match_operand:ANYF 0 "register_operand" "=f")
1975         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
1976                   (match_operand:ANYF 2 "register_operand" "f")))]
1977   "<recip_condition> && flag_unsafe_math_optimizations"
1978 {
1979   if (TARGET_FIX_SB1)
1980     return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
1981   else
1982     return "recip.<fmt>\t%0,%2";
1983 }
1984   [(set_attr "type" "frdiv")
1985    (set_attr "mode" "<UNITMODE>")
1986    (set (attr "length")
1987         (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1988                       (const_int 8)
1989                       (const_int 4)))])
1990
1991 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
1992 ;; with negative operands.  We use special libgcc functions instead.
1993 (define_insn "divmod<mode>4"
1994   [(set (match_operand:GPR 0 "register_operand" "=l")
1995         (div:GPR (match_operand:GPR 1 "register_operand" "d")
1996                  (match_operand:GPR 2 "register_operand" "d")))
1997    (set (match_operand:GPR 3 "register_operand" "=h")
1998         (mod:GPR (match_dup 1)
1999                  (match_dup 2)))]
2000   "!TARGET_FIX_VR4120"
2001   { return mips_output_division ("<d>div\t$0,%1,%2", operands); }
2002   [(set_attr "type" "idiv")
2003    (set_attr "mode" "<MODE>")])
2004
2005 (define_insn "udivmod<mode>4"
2006   [(set (match_operand:GPR 0 "register_operand" "=l")
2007         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2008                   (match_operand:GPR 2 "register_operand" "d")))
2009    (set (match_operand:GPR 3 "register_operand" "=h")
2010         (umod:GPR (match_dup 1)
2011                   (match_dup 2)))]
2012   ""
2013   { return mips_output_division ("<d>divu\t$0,%1,%2", operands); }
2014   [(set_attr "type" "idiv")
2015    (set_attr "mode" "<MODE>")])
2016 \f
2017 ;;
2018 ;;  ....................
2019 ;;
2020 ;;      SQUARE ROOT
2021 ;;
2022 ;;  ....................
2023
2024 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
2025 ;; "*div[sd]f3" comment for details).
2026
2027 (define_insn "sqrt<mode>2"
2028   [(set (match_operand:ANYF 0 "register_operand" "=f")
2029         (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2030   "<sqrt_condition>"
2031 {
2032   if (TARGET_FIX_SB1)
2033     return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
2034   else
2035     return "sqrt.<fmt>\t%0,%1";
2036 }
2037   [(set_attr "type" "fsqrt")
2038    (set_attr "mode" "<UNITMODE>")
2039    (set (attr "length")
2040         (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
2041                       (const_int 8)
2042                       (const_int 4)))])
2043
2044 (define_insn "*rsqrt<mode>a"
2045   [(set (match_operand:ANYF 0 "register_operand" "=f")
2046         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2047                   (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
2048   "<recip_condition> && flag_unsafe_math_optimizations"
2049 {
2050   if (TARGET_FIX_SB1)
2051     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2052   else
2053     return "rsqrt.<fmt>\t%0,%2";
2054 }
2055   [(set_attr "type" "frsqrt")
2056    (set_attr "mode" "<UNITMODE>")
2057    (set (attr "length")
2058         (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
2059                       (const_int 8)
2060                       (const_int 4)))])
2061
2062 (define_insn "*rsqrt<mode>b"
2063   [(set (match_operand:ANYF 0 "register_operand" "=f")
2064         (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2065                              (match_operand:ANYF 2 "register_operand" "f"))))]
2066   "<recip_condition> && flag_unsafe_math_optimizations"
2067 {
2068   if (TARGET_FIX_SB1)
2069     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2070   else
2071     return "rsqrt.<fmt>\t%0,%2";
2072 }
2073   [(set_attr "type" "frsqrt")
2074    (set_attr "mode" "<UNITMODE>")
2075    (set (attr "length")
2076         (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
2077                       (const_int 8)
2078                       (const_int 4)))])
2079 \f
2080 ;;
2081 ;;  ....................
2082 ;;
2083 ;;      ABSOLUTE VALUE
2084 ;;
2085 ;;  ....................
2086
2087 ;; Do not use the integer abs macro instruction, since that signals an
2088 ;; exception on -2147483648 (sigh).
2089
2090 ;; abs.fmt is an arithmetic instruction and treats all NaN inputs as
2091 ;; invalid; it does not clear their sign bits.  We therefore can't use
2092 ;; abs.fmt if the signs of NaNs matter.
2093
2094 (define_insn "abs<mode>2"
2095   [(set (match_operand:ANYF 0 "register_operand" "=f")
2096         (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2097   "!HONOR_NANS (<MODE>mode)"
2098   "abs.<fmt>\t%0,%1"
2099   [(set_attr "type" "fabs")
2100    (set_attr "mode" "<UNITMODE>")])
2101 \f
2102 ;;
2103 ;;  ...................
2104 ;;
2105 ;;  Count leading zeroes.
2106 ;;
2107 ;;  ...................
2108 ;;
2109
2110 (define_insn "clz<mode>2"
2111   [(set (match_operand:GPR 0 "register_operand" "=d")
2112         (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
2113   "ISA_HAS_CLZ_CLO"
2114   "<d>clz\t%0,%1"
2115   [(set_attr "type" "clz")
2116    (set_attr "mode" "<MODE>")])
2117 \f
2118 ;;
2119 ;;  ....................
2120 ;;
2121 ;;      NEGATION and ONE'S COMPLEMENT
2122 ;;
2123 ;;  ....................
2124
2125 (define_insn "negsi2"
2126   [(set (match_operand:SI 0 "register_operand" "=d")
2127         (neg:SI (match_operand:SI 1 "register_operand" "d")))]
2128   ""
2129 {
2130   if (TARGET_MIPS16)
2131     return "neg\t%0,%1";
2132   else
2133     return "subu\t%0,%.,%1";
2134 }
2135   [(set_attr "type"     "arith")
2136    (set_attr "mode"     "SI")])
2137
2138 (define_insn "negdi2"
2139   [(set (match_operand:DI 0 "register_operand" "=d")
2140         (neg:DI (match_operand:DI 1 "register_operand" "d")))]
2141   "TARGET_64BIT && !TARGET_MIPS16"
2142   "dsubu\t%0,%.,%1"
2143   [(set_attr "type"     "arith")
2144    (set_attr "mode"     "DI")])
2145
2146 ;; neg.fmt is an arithmetic instruction and treats all NaN inputs as
2147 ;; invalid; it does not flip their sign bit.  We therefore can't use
2148 ;; neg.fmt if the signs of NaNs matter.
2149
2150 (define_insn "neg<mode>2"
2151   [(set (match_operand:ANYF 0 "register_operand" "=f")
2152         (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2153   "!HONOR_NANS (<MODE>mode)"
2154   "neg.<fmt>\t%0,%1"
2155   [(set_attr "type" "fneg")
2156    (set_attr "mode" "<UNITMODE>")])
2157
2158 (define_insn "one_cmpl<mode>2"
2159   [(set (match_operand:GPR 0 "register_operand" "=d")
2160         (not:GPR (match_operand:GPR 1 "register_operand" "d")))]
2161   ""
2162 {
2163   if (TARGET_MIPS16)
2164     return "not\t%0,%1";
2165   else
2166     return "nor\t%0,%.,%1";
2167 }
2168   [(set_attr "type" "logical")
2169    (set_attr "mode" "<MODE>")])
2170 \f
2171 ;;
2172 ;;  ....................
2173 ;;
2174 ;;      LOGICAL
2175 ;;
2176 ;;  ....................
2177 ;;
2178
2179 ;; Many of these instructions use trivial define_expands, because we
2180 ;; want to use a different set of constraints when TARGET_MIPS16.
2181
2182 (define_expand "and<mode>3"
2183   [(set (match_operand:GPR 0 "register_operand")
2184         (and:GPR (match_operand:GPR 1 "register_operand")
2185                  (match_operand:GPR 2 "uns_arith_operand")))]
2186   ""
2187 {
2188   if (TARGET_MIPS16)
2189     operands[2] = force_reg (<MODE>mode, operands[2]);
2190 })
2191
2192 (define_insn "*and<mode>3"
2193   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2194         (and:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2195                  (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2196   "!TARGET_MIPS16"
2197   "@
2198    and\t%0,%1,%2
2199    andi\t%0,%1,%x2"
2200   [(set_attr "type" "logical")
2201    (set_attr "mode" "<MODE>")])
2202
2203 (define_insn "*and<mode>3_mips16"
2204   [(set (match_operand:GPR 0 "register_operand" "=d")
2205         (and:GPR (match_operand:GPR 1 "register_operand" "%0")
2206                  (match_operand:GPR 2 "register_operand" "d")))]
2207   "TARGET_MIPS16"
2208   "and\t%0,%2"
2209   [(set_attr "type" "logical")
2210    (set_attr "mode" "<MODE>")])
2211
2212 (define_expand "ior<mode>3"
2213   [(set (match_operand:GPR 0 "register_operand")
2214         (ior:GPR (match_operand:GPR 1 "register_operand")
2215                  (match_operand:GPR 2 "uns_arith_operand")))]
2216   ""
2217 {
2218   if (TARGET_MIPS16)
2219     operands[2] = force_reg (<MODE>mode, operands[2]);
2220 })
2221
2222 (define_insn "*ior<mode>3"
2223   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2224         (ior:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2225                  (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2226   "!TARGET_MIPS16"
2227   "@
2228    or\t%0,%1,%2
2229    ori\t%0,%1,%x2"
2230   [(set_attr "type" "logical")
2231    (set_attr "mode" "<MODE>")])
2232
2233 (define_insn "*ior<mode>3_mips16"
2234   [(set (match_operand:GPR 0 "register_operand" "=d")
2235         (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
2236                  (match_operand:GPR 2 "register_operand" "d")))]
2237   "TARGET_MIPS16"
2238   "or\t%0,%2"
2239   [(set_attr "type" "logical")
2240    (set_attr "mode" "<MODE>")])
2241
2242 (define_expand "xor<mode>3"
2243   [(set (match_operand:GPR 0 "register_operand")
2244         (xor:GPR (match_operand:GPR 1 "register_operand")
2245                  (match_operand:GPR 2 "uns_arith_operand")))]
2246   ""
2247   "")
2248
2249 (define_insn ""
2250   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2251         (xor:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2252                  (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2253   "!TARGET_MIPS16"
2254   "@
2255    xor\t%0,%1,%2
2256    xori\t%0,%1,%x2"
2257   [(set_attr "type" "logical")
2258    (set_attr "mode" "<MODE>")])
2259
2260 (define_insn ""
2261   [(set (match_operand:GPR 0 "register_operand" "=d,t,t")
2262         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
2263                  (match_operand:GPR 2 "uns_arith_operand" "d,K,d")))]
2264   "TARGET_MIPS16"
2265   "@
2266    xor\t%0,%2
2267    cmpi\t%1,%2
2268    cmp\t%1,%2"
2269   [(set_attr "type" "logical,arith,arith")
2270    (set_attr "mode" "<MODE>")
2271    (set_attr_alternative "length"
2272                 [(const_int 4)
2273                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1")
2274                                (const_int 4)
2275                                (const_int 8))
2276                  (const_int 4)])])
2277
2278 (define_insn "*nor<mode>3"
2279   [(set (match_operand:GPR 0 "register_operand" "=d")
2280         (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
2281                  (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
2282   "!TARGET_MIPS16"
2283   "nor\t%0,%1,%2"
2284   [(set_attr "type" "logical")
2285    (set_attr "mode" "<MODE>")])
2286 \f
2287 ;;
2288 ;;  ....................
2289 ;;
2290 ;;      TRUNCATION
2291 ;;
2292 ;;  ....................
2293
2294
2295
2296 (define_insn "truncdfsf2"
2297   [(set (match_operand:SF 0 "register_operand" "=f")
2298         (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
2299   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2300   "cvt.s.d\t%0,%1"
2301   [(set_attr "type"     "fcvt")
2302    (set_attr "cnv_mode" "D2S")   
2303    (set_attr "mode"     "SF")])
2304
2305 ;; Integer truncation patterns.  Truncating SImode values to smaller
2306 ;; modes is a no-op, as it is for most other GCC ports.  Truncating
2307 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
2308 ;; need to make sure that the lower 32 bits are properly sign-extended
2309 ;; (see TRULY_NOOP_TRUNCATION).  Truncating DImode values into modes
2310 ;; smaller than SImode is equivalent to two separate truncations:
2311 ;;
2312 ;;                        A       B
2313 ;;    DI ---> HI  ==  DI ---> SI ---> HI
2314 ;;    DI ---> QI  ==  DI ---> SI ---> QI
2315 ;;
2316 ;; Step A needs a real instruction but step B does not.
2317
2318 (define_insn "truncdisi2"
2319   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
2320         (truncate:SI (match_operand:DI 1 "register_operand" "d,d")))]
2321   "TARGET_64BIT"
2322   "@
2323     sll\t%0,%1,0
2324     sw\t%1,%0"
2325   [(set_attr "type" "shift,store")
2326    (set_attr "mode" "SI")
2327    (set_attr "extended_mips16" "yes,*")])
2328
2329 (define_insn "truncdihi2"
2330   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,m")
2331         (truncate:HI (match_operand:DI 1 "register_operand" "d,d")))]
2332   "TARGET_64BIT"
2333   "@
2334     sll\t%0,%1,0
2335     sh\t%1,%0"
2336   [(set_attr "type" "shift,store")
2337    (set_attr "mode" "SI")
2338    (set_attr "extended_mips16" "yes,*")])
2339
2340 (define_insn "truncdiqi2"
2341   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,m")
2342         (truncate:QI (match_operand:DI 1 "register_operand" "d,d")))]
2343   "TARGET_64BIT"
2344   "@
2345     sll\t%0,%1,0
2346     sb\t%1,%0"
2347   [(set_attr "type" "shift,store")
2348    (set_attr "mode" "SI")
2349    (set_attr "extended_mips16" "yes,*")])
2350
2351 ;; Combiner patterns to optimize shift/truncate combinations.
2352
2353 (define_insn ""
2354   [(set (match_operand:SUBDI 0 "register_operand" "=d")
2355         (truncate:SUBDI
2356           (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
2357                        (match_operand:DI 2 "const_arith_operand" ""))))]
2358   "TARGET_64BIT && !TARGET_MIPS16 && INTVAL (operands[2]) >= 32"
2359   "dsra\t%0,%1,%2"
2360   [(set_attr "type" "shift")
2361    (set_attr "mode" "SI")])
2362
2363 (define_insn ""
2364   [(set (match_operand:SUBDI 0 "register_operand" "=d")
2365         (truncate:SUBDI
2366           (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
2367                        (const_int 32))))]
2368   "TARGET_64BIT && !TARGET_MIPS16"
2369   "dsra\t%0,%1,32"
2370   [(set_attr "type" "shift")
2371    (set_attr "mode" "SI")])
2372
2373
2374 ;; Combiner patterns for truncate/sign_extend combinations.  The SI versions
2375 ;; use the shift/truncate patterns above.
2376
2377 (define_insn_and_split "*extenddi_truncate<mode>"
2378   [(set (match_operand:DI 0 "register_operand" "=d")
2379         (sign_extend:DI
2380             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
2381   "TARGET_64BIT && !TARGET_MIPS16"
2382   "#"
2383   "&& reload_completed"
2384   [(set (match_dup 2)
2385         (ashift:DI (match_dup 1)
2386                    (match_dup 3)))
2387    (set (match_dup 0)
2388         (ashiftrt:DI (match_dup 2)
2389                      (match_dup 3)))]
2390 {
2391   operands[2] = gen_lowpart (DImode, operands[0]);
2392   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
2393 })
2394
2395 (define_insn_and_split "*extendsi_truncate<mode>"
2396   [(set (match_operand:SI 0 "register_operand" "=d")
2397         (sign_extend:SI
2398             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
2399   "TARGET_64BIT && !TARGET_MIPS16"
2400   "#"
2401   "&& reload_completed"
2402   [(set (match_dup 2)
2403         (ashift:DI (match_dup 1)
2404                    (match_dup 3)))
2405    (set (match_dup 0)
2406         (truncate:SI (ashiftrt:DI (match_dup 2)
2407                                   (match_dup 3))))]
2408 {
2409   operands[2] = gen_lowpart (DImode, operands[0]);
2410   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
2411 })
2412
2413 ;; Combiner patterns to optimize truncate/zero_extend combinations.
2414
2415 (define_insn "*zero_extend<mode>_trunchi"
2416   [(set (match_operand:GPR 0 "register_operand" "=d")
2417         (zero_extend:GPR
2418             (truncate:HI (match_operand:DI 1 "register_operand" "d"))))]
2419   "TARGET_64BIT && !TARGET_MIPS16"
2420   "andi\t%0,%1,0xffff"
2421   [(set_attr "type" "logical")
2422    (set_attr "mode" "<MODE>")])
2423
2424 (define_insn "*zero_extend<mode>_truncqi"
2425   [(set (match_operand:GPR 0 "register_operand" "=d")
2426         (zero_extend:GPR
2427             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
2428   "TARGET_64BIT && !TARGET_MIPS16"
2429   "andi\t%0,%1,0xff"
2430   [(set_attr "type" "logical")
2431    (set_attr "mode" "<MODE>")])
2432
2433 (define_insn ""
2434   [(set (match_operand:HI 0 "register_operand" "=d")
2435         (zero_extend:HI
2436             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
2437   "TARGET_64BIT && !TARGET_MIPS16"
2438   "andi\t%0,%1,0xff"
2439   [(set_attr "type" "logical")
2440    (set_attr "mode" "HI")])
2441 \f
2442 ;;
2443 ;;  ....................
2444 ;;
2445 ;;      ZERO EXTENSION
2446 ;;
2447 ;;  ....................
2448
2449 ;; Extension insns.
2450
2451 (define_insn_and_split "zero_extendsidi2"
2452   [(set (match_operand:DI 0 "register_operand" "=d,d")
2453         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
2454   "TARGET_64BIT"
2455   "@
2456    #
2457    lwu\t%0,%1"
2458   "&& reload_completed && REG_P (operands[1])"
2459   [(set (match_dup 0)
2460         (ashift:DI (match_dup 1) (const_int 32)))
2461    (set (match_dup 0)
2462         (lshiftrt:DI (match_dup 0) (const_int 32)))]
2463   { operands[1] = gen_lowpart (DImode, operands[1]); }
2464   [(set_attr "type" "multi,load")
2465    (set_attr "mode" "DI")
2466    (set_attr "length" "8,*")])
2467
2468 ;; Combine is not allowed to convert this insn into a zero_extendsidi2
2469 ;; because of TRULY_NOOP_TRUNCATION.
2470
2471 (define_insn_and_split "*clear_upper32"
2472   [(set (match_operand:DI 0 "register_operand" "=d,d")
2473         (and:DI (match_operand:DI 1 "nonimmediate_operand" "d,W")
2474                 (const_int 4294967295)))]
2475   "TARGET_64BIT"
2476 {
2477   if (which_alternative == 0)
2478     return "#";
2479
2480   operands[1] = gen_lowpart (SImode, operands[1]);
2481   return "lwu\t%0,%1";
2482 }
2483   "&& reload_completed && REG_P (operands[1])"
2484   [(set (match_dup 0)
2485         (ashift:DI (match_dup 1) (const_int 32)))
2486    (set (match_dup 0)
2487         (lshiftrt:DI (match_dup 0) (const_int 32)))]
2488   ""
2489   [(set_attr "type" "multi,load")
2490    (set_attr "mode" "DI")
2491    (set_attr "length" "8,*")])
2492
2493 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
2494   [(set (match_operand:GPR 0 "register_operand")
2495         (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
2496   ""
2497 {
2498   if (TARGET_MIPS16 && !GENERATE_MIPS16E
2499       && !memory_operand (operands[1], <SHORT:MODE>mode))
2500     {
2501       emit_insn (gen_and<GPR:mode>3 (operands[0],
2502                                      gen_lowpart (<GPR:MODE>mode, operands[1]),
2503                                      force_reg (<GPR:MODE>mode,
2504                                                 GEN_INT (<SHORT:mask>))));
2505       DONE;
2506     }
2507 })
2508
2509 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
2510   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2511         (zero_extend:GPR
2512              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2513   "!TARGET_MIPS16"
2514   "@
2515    andi\t%0,%1,<SHORT:mask>
2516    l<SHORT:size>u\t%0,%1"
2517   [(set_attr "type" "logical,load")
2518    (set_attr "mode" "<GPR:MODE>")])
2519
2520 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
2521   [(set (match_operand:GPR 0 "register_operand" "=d")
2522         (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
2523   "GENERATE_MIPS16E"
2524   "ze<SHORT:size>\t%0"
2525   [(set_attr "type" "arith")
2526    (set_attr "mode" "<GPR:MODE>")])
2527
2528 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
2529   [(set (match_operand:GPR 0 "register_operand" "=d")
2530         (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
2531   "TARGET_MIPS16"
2532   "l<SHORT:size>u\t%0,%1"
2533   [(set_attr "type" "load")
2534    (set_attr "mode" "<GPR:MODE>")])
2535
2536 (define_expand "zero_extendqihi2"
2537   [(set (match_operand:HI 0 "register_operand")
2538         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
2539   ""
2540 {
2541   if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
2542     {
2543       emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
2544                                        operands[1]));
2545       DONE;
2546     }
2547 })
2548
2549 (define_insn "*zero_extendqihi2"
2550   [(set (match_operand:HI 0 "register_operand" "=d,d")
2551         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
2552   "!TARGET_MIPS16"
2553   "@
2554    andi\t%0,%1,0x00ff
2555    lbu\t%0,%1"
2556   [(set_attr "type" "logical,load")
2557    (set_attr "mode" "HI")])
2558
2559 (define_insn "*zero_extendqihi2_mips16"
2560   [(set (match_operand:HI 0 "register_operand" "=d")
2561         (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
2562   "TARGET_MIPS16"
2563   "lbu\t%0,%1"
2564   [(set_attr "type" "load")
2565    (set_attr "mode" "HI")])
2566 \f
2567 ;;
2568 ;;  ....................
2569 ;;
2570 ;;      SIGN EXTENSION
2571 ;;
2572 ;;  ....................
2573
2574 ;; Extension insns.
2575 ;; Those for integer source operand are ordered widest source type first.
2576
2577 ;; When TARGET_64BIT, all SImode integer registers should already be in
2578 ;; sign-extended form (see TRULY_NOOP_TRUNCATION and truncdisi2).  We can
2579 ;; therefore get rid of register->register instructions if we constrain
2580 ;; the source to be in the same register as the destination.
2581 ;;
2582 ;; The register alternative has type "arith" so that the pre-reload
2583 ;; scheduler will treat it as a move.  This reflects what happens if
2584 ;; the register alternative needs a reload.
2585 (define_insn_and_split "extendsidi2"
2586   [(set (match_operand:DI 0 "register_operand" "=d,d")
2587         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,m")))]
2588   "TARGET_64BIT"
2589   "@
2590    #
2591    lw\t%0,%1"
2592   "&& reload_completed && register_operand (operands[1], VOIDmode)"
2593   [(const_int 0)]
2594 {
2595   emit_note (NOTE_INSN_DELETED);
2596   DONE;
2597 }
2598   [(set_attr "type" "arith,load")
2599    (set_attr "mode" "DI")])
2600
2601 (define_expand "extend<SHORT:mode><GPR:mode>2"
2602   [(set (match_operand:GPR 0 "register_operand")
2603         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
2604   "")
2605
2606 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
2607   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2608         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
2609   "GENERATE_MIPS16E"
2610   "@
2611    se<SHORT:size>\t%0
2612    l<SHORT:size>\t%0,%1"
2613   [(set_attr "type" "signext,load")
2614    (set_attr "mode" "<GPR:MODE>")])
2615
2616 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
2617   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2618         (sign_extend:GPR
2619              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2620   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
2621   "@
2622    #
2623    l<SHORT:size>\t%0,%1"
2624   "&& reload_completed && REG_P (operands[1])"
2625   [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
2626    (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
2627 {
2628   operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
2629   operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
2630                          - GET_MODE_BITSIZE (<SHORT:MODE>mode));
2631 }
2632   [(set_attr "type" "arith,load")
2633    (set_attr "mode" "<GPR:MODE>")
2634    (set_attr "length" "8,*")])
2635
2636 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
2637   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2638         (sign_extend:GPR
2639              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2640   "ISA_HAS_SEB_SEH"
2641   "@
2642    se<SHORT:size>\t%0,%1
2643    l<SHORT:size>\t%0,%1"
2644   [(set_attr "type" "signext,load")
2645    (set_attr "mode" "<GPR:MODE>")])
2646
2647 (define_expand "extendqihi2"
2648   [(set (match_operand:HI 0 "register_operand")
2649         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
2650   "")
2651
2652 (define_insn "*extendqihi2_mips16e"
2653   [(set (match_operand:HI 0 "register_operand" "=d,d")
2654         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
2655   "GENERATE_MIPS16E"
2656   "@
2657    seb\t%0
2658    lb\t%0,%1"
2659   [(set_attr "type" "signext,load")
2660    (set_attr "mode" "SI")])
2661
2662 (define_insn_and_split "*extendqihi2"
2663   [(set (match_operand:HI 0 "register_operand" "=d,d")
2664         (sign_extend:HI
2665              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
2666   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
2667   "@
2668    #
2669    lb\t%0,%1"
2670   "&& reload_completed && REG_P (operands[1])"
2671   [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
2672    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
2673 {
2674   operands[0] = gen_lowpart (SImode, operands[0]);
2675   operands[1] = gen_lowpart (SImode, operands[1]);
2676   operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
2677                          - GET_MODE_BITSIZE (QImode));
2678 }
2679   [(set_attr "type" "multi,load")
2680    (set_attr "mode" "SI")
2681    (set_attr "length" "8,*")])
2682
2683 (define_insn "*extendqihi2_seb"
2684   [(set (match_operand:HI 0 "register_operand" "=d,d")
2685         (sign_extend:HI
2686              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
2687   "ISA_HAS_SEB_SEH"
2688   "@
2689    seb\t%0,%1
2690    lb\t%0,%1"
2691   [(set_attr "type" "signext,load")
2692    (set_attr "mode" "SI")])
2693
2694 (define_insn "extendsfdf2"
2695   [(set (match_operand:DF 0 "register_operand" "=f")
2696         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
2697   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2698   "cvt.d.s\t%0,%1"
2699   [(set_attr "type"     "fcvt")
2700    (set_attr "cnv_mode" "S2D")   
2701    (set_attr "mode"     "DF")])
2702 \f
2703 ;;
2704 ;;  ....................
2705 ;;
2706 ;;      CONVERSIONS
2707 ;;
2708 ;;  ....................
2709
2710 (define_expand "fix_truncdfsi2"
2711   [(set (match_operand:SI 0 "register_operand")
2712         (fix:SI (match_operand:DF 1 "register_operand")))]
2713   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2714 {
2715   if (!ISA_HAS_TRUNC_W)
2716     {
2717       emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
2718       DONE;
2719     }
2720 })
2721
2722 (define_insn "fix_truncdfsi2_insn"
2723   [(set (match_operand:SI 0 "register_operand" "=f")
2724         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
2725   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
2726   "trunc.w.d %0,%1"
2727   [(set_attr "type"     "fcvt")
2728    (set_attr "mode"     "DF")
2729    (set_attr "cnv_mode" "D2I")
2730    (set_attr "length"   "4")])
2731
2732 (define_insn "fix_truncdfsi2_macro"
2733   [(set (match_operand:SI 0 "register_operand" "=f")
2734         (fix:SI (match_operand:DF 1 "register_operand" "f")))
2735    (clobber (match_scratch:DF 2 "=d"))]
2736   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
2737 {
2738   if (set_nomacro)
2739     return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
2740   else
2741     return "trunc.w.d %0,%1,%2";
2742 }
2743   [(set_attr "type"     "fcvt")
2744    (set_attr "mode"     "DF")
2745    (set_attr "cnv_mode" "D2I")
2746    (set_attr "length"   "36")])
2747
2748 (define_expand "fix_truncsfsi2"
2749   [(set (match_operand:SI 0 "register_operand")
2750         (fix:SI (match_operand:SF 1 "register_operand")))]
2751   "TARGET_HARD_FLOAT"
2752 {
2753   if (!ISA_HAS_TRUNC_W)
2754     {
2755       emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
2756       DONE;
2757     }
2758 })
2759
2760 (define_insn "fix_truncsfsi2_insn"
2761   [(set (match_operand:SI 0 "register_operand" "=f")
2762         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
2763   "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
2764   "trunc.w.s %0,%1"
2765   [(set_attr "type"     "fcvt")
2766    (set_attr "mode"     "SF")
2767    (set_attr "cnv_mode" "S2I")
2768    (set_attr "length"   "4")])
2769
2770 (define_insn "fix_truncsfsi2_macro"
2771   [(set (match_operand:SI 0 "register_operand" "=f")
2772         (fix:SI (match_operand:SF 1 "register_operand" "f")))
2773    (clobber (match_scratch:SF 2 "=d"))]
2774   "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
2775 {
2776   if (set_nomacro)
2777     return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
2778   else
2779     return "trunc.w.s %0,%1,%2";
2780 }
2781   [(set_attr "type"     "fcvt")
2782    (set_attr "mode"     "SF")
2783    (set_attr "cnv_mode" "S2I")
2784    (set_attr "length"   "36")])
2785
2786
2787 (define_insn "fix_truncdfdi2"
2788   [(set (match_operand:DI 0 "register_operand" "=f")
2789         (fix:DI (match_operand:DF 1 "register_operand" "f")))]
2790   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2791   "trunc.l.d %0,%1"
2792   [(set_attr "type"     "fcvt")
2793    (set_attr "mode"     "DF")
2794    (set_attr "cnv_mode" "D2I")
2795    (set_attr "length"   "4")])
2796
2797
2798 (define_insn "fix_truncsfdi2"
2799   [(set (match_operand:DI 0 "register_operand" "=f")
2800         (fix:DI (match_operand:SF 1 "register_operand" "f")))]
2801   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2802   "trunc.l.s %0,%1"
2803   [(set_attr "type"     "fcvt")
2804    (set_attr "mode"     "SF")
2805    (set_attr "cnv_mode" "S2I")
2806    (set_attr "length"   "4")])
2807
2808
2809 (define_insn "floatsidf2"
2810   [(set (match_operand:DF 0 "register_operand" "=f")
2811         (float:DF (match_operand:SI 1 "register_operand" "f")))]
2812   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2813   "cvt.d.w\t%0,%1"
2814   [(set_attr "type"     "fcvt")
2815    (set_attr "mode"     "DF")
2816    (set_attr "cnv_mode" "I2D")   
2817    (set_attr "length"   "4")])
2818
2819
2820 (define_insn "floatdidf2"
2821   [(set (match_operand:DF 0 "register_operand" "=f")
2822         (float:DF (match_operand:DI 1 "register_operand" "f")))]
2823   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2824   "cvt.d.l\t%0,%1"
2825   [(set_attr "type"     "fcvt")
2826    (set_attr "mode"     "DF")
2827    (set_attr "cnv_mode" "I2D")   
2828    (set_attr "length"   "4")])
2829
2830
2831 (define_insn "floatsisf2"
2832   [(set (match_operand:SF 0 "register_operand" "=f")
2833         (float:SF (match_operand:SI 1 "register_operand" "f")))]
2834   "TARGET_HARD_FLOAT"
2835   "cvt.s.w\t%0,%1"
2836   [(set_attr "type"     "fcvt")
2837    (set_attr "mode"     "SF")
2838    (set_attr "cnv_mode" "I2S")   
2839    (set_attr "length"   "4")])
2840
2841
2842 (define_insn "floatdisf2"
2843   [(set (match_operand:SF 0 "register_operand" "=f")
2844         (float:SF (match_operand:DI 1 "register_operand" "f")))]
2845   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2846   "cvt.s.l\t%0,%1"
2847   [(set_attr "type"     "fcvt")
2848    (set_attr "mode"     "SF")
2849    (set_attr "cnv_mode" "I2S")   
2850    (set_attr "length"   "4")])
2851
2852
2853 (define_expand "fixuns_truncdfsi2"
2854   [(set (match_operand:SI 0 "register_operand")
2855         (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
2856   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2857 {
2858   rtx reg1 = gen_reg_rtx (DFmode);
2859   rtx reg2 = gen_reg_rtx (DFmode);
2860   rtx reg3 = gen_reg_rtx (SImode);
2861   rtx label1 = gen_label_rtx ();
2862   rtx label2 = gen_label_rtx ();
2863   REAL_VALUE_TYPE offset;
2864
2865   real_2expN (&offset, 31, DFmode);
2866
2867   if (reg1)                     /* Turn off complaints about unreached code.  */
2868     {
2869       mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
2870       do_pending_stack_adjust ();
2871
2872       emit_insn (gen_cmpdf (operands[1], reg1));
2873       emit_jump_insn (gen_bge (label1));
2874
2875       emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
2876       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2877                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
2878       emit_barrier ();
2879
2880       emit_label (label1);
2881       mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
2882       mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
2883                                      (BITMASK_HIGH, SImode)));
2884
2885       emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
2886       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
2887
2888       emit_label (label2);
2889
2890       /* Allow REG_NOTES to be set on last insn (labels don't have enough
2891          fields, and can't be used for REG_NOTES anyway).  */
2892       emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2893       DONE;
2894     }
2895 })
2896
2897
2898 (define_expand "fixuns_truncdfdi2"
2899   [(set (match_operand:DI 0 "register_operand")
2900         (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
2901   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
2902 {
2903   rtx reg1 = gen_reg_rtx (DFmode);
2904   rtx reg2 = gen_reg_rtx (DFmode);
2905   rtx reg3 = gen_reg_rtx (DImode);
2906   rtx label1 = gen_label_rtx ();
2907   rtx label2 = gen_label_rtx ();
2908   REAL_VALUE_TYPE offset;
2909
2910   real_2expN (&offset, 63, DFmode);
2911
2912   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
2913   do_pending_stack_adjust ();
2914
2915   emit_insn (gen_cmpdf (operands[1], reg1));
2916   emit_jump_insn (gen_bge (label1));
2917
2918   emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
2919   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2920                                gen_rtx_LABEL_REF (VOIDmode, label2)));
2921   emit_barrier ();
2922
2923   emit_label (label1);
2924   mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
2925   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
2926   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
2927
2928   emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
2929   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
2930
2931   emit_label (label2);
2932
2933   /* Allow REG_NOTES to be set on last insn (labels don't have enough
2934      fields, and can't be used for REG_NOTES anyway).  */
2935   emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2936   DONE;
2937 })
2938
2939
2940 (define_expand "fixuns_truncsfsi2"
2941   [(set (match_operand:SI 0 "register_operand")
2942         (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
2943   "TARGET_HARD_FLOAT"
2944 {
2945   rtx reg1 = gen_reg_rtx (SFmode);
2946   rtx reg2 = gen_reg_rtx (SFmode);
2947   rtx reg3 = gen_reg_rtx (SImode);
2948   rtx label1 = gen_label_rtx ();
2949   rtx label2 = gen_label_rtx ();
2950   REAL_VALUE_TYPE offset;
2951
2952   real_2expN (&offset, 31, SFmode);
2953
2954   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
2955   do_pending_stack_adjust ();
2956
2957   emit_insn (gen_cmpsf (operands[1], reg1));
2958   emit_jump_insn (gen_bge (label1));
2959
2960   emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
2961   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2962                                gen_rtx_LABEL_REF (VOIDmode, label2)));
2963   emit_barrier ();
2964
2965   emit_label (label1);
2966   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
2967   mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
2968                                  (BITMASK_HIGH, SImode)));
2969
2970   emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
2971   emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
2972
2973   emit_label (label2);
2974
2975   /* Allow REG_NOTES to be set on last insn (labels don't have enough
2976      fields, and can't be used for REG_NOTES anyway).  */
2977   emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2978   DONE;
2979 })
2980
2981
2982 (define_expand "fixuns_truncsfdi2"
2983   [(set (match_operand:DI 0 "register_operand")
2984         (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
2985   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
2986 {
2987   rtx reg1 = gen_reg_rtx (SFmode);
2988   rtx reg2 = gen_reg_rtx (SFmode);
2989   rtx reg3 = gen_reg_rtx (DImode);
2990   rtx label1 = gen_label_rtx ();
2991   rtx label2 = gen_label_rtx ();
2992   REAL_VALUE_TYPE offset;
2993
2994   real_2expN (&offset, 63, SFmode);
2995
2996   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
2997   do_pending_stack_adjust ();
2998
2999   emit_insn (gen_cmpsf (operands[1], reg1));
3000   emit_jump_insn (gen_bge (label1));
3001
3002   emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
3003   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3004                                gen_rtx_LABEL_REF (VOIDmode, label2)));
3005   emit_barrier ();
3006
3007   emit_label (label1);
3008   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3009   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3010   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3011
3012   emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
3013   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3014
3015   emit_label (label2);
3016
3017   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3018      fields, and can't be used for REG_NOTES anyway).  */
3019   emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
3020   DONE;
3021 })
3022 \f
3023 ;;
3024 ;;  ....................
3025 ;;
3026 ;;      DATA MOVEMENT
3027 ;;
3028 ;;  ....................
3029
3030 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
3031
3032 (define_expand "extv"
3033   [(set (match_operand 0 "register_operand")
3034         (sign_extract (match_operand:QI 1 "memory_operand")
3035                       (match_operand 2 "immediate_operand")
3036                       (match_operand 3 "immediate_operand")))]
3037   "!TARGET_MIPS16"
3038 {
3039   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3040                                          INTVAL (operands[2]),
3041                                          INTVAL (operands[3])))
3042     DONE;
3043   else
3044     FAIL;
3045 })
3046
3047 (define_expand "extzv"
3048   [(set (match_operand 0 "register_operand")
3049         (zero_extract (match_operand 1 "nonimmediate_operand")
3050                       (match_operand 2 "immediate_operand")
3051                       (match_operand 3 "immediate_operand")))]
3052   "!TARGET_MIPS16"
3053 {
3054   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3055                                          INTVAL (operands[2]),
3056                                          INTVAL (operands[3])))
3057     DONE;
3058   else if (mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3059                                INTVAL (operands[3])))
3060     {
3061       if (GET_MODE (operands[0]) == DImode)
3062         emit_insn (gen_extzvdi (operands[0], operands[1], operands[2],
3063                                 operands[3]));
3064       else
3065         emit_insn (gen_extzvsi (operands[0], operands[1], operands[2],
3066                                 operands[3]));
3067       DONE;
3068     }
3069   else
3070     FAIL;
3071 })
3072
3073 (define_insn "extzv<mode>"
3074   [(set (match_operand:GPR 0 "register_operand" "=d")
3075         (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3076                           (match_operand:SI 2 "immediate_operand" "I")
3077                           (match_operand:SI 3 "immediate_operand" "I")))]
3078   "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3079                        INTVAL (operands[3]))"
3080   "<d>ext\t%0,%1,%3,%2"
3081   [(set_attr "type"     "arith")
3082    (set_attr "mode"     "<MODE>")])
3083
3084
3085 (define_expand "insv"
3086   [(set (zero_extract (match_operand 0 "nonimmediate_operand")
3087                       (match_operand 1 "immediate_operand")
3088                       (match_operand 2 "immediate_operand"))
3089         (match_operand 3 "reg_or_0_operand"))]
3090   "!TARGET_MIPS16"
3091 {
3092   if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
3093                                           INTVAL (operands[1]),
3094                                           INTVAL (operands[2])))
3095     DONE;
3096   else if (mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3097                                INTVAL (operands[2])))
3098     {
3099       if (GET_MODE (operands[0]) == DImode)
3100         emit_insn (gen_insvdi (operands[0], operands[1], operands[2],
3101                                operands[3]));
3102       else
3103         emit_insn (gen_insvsi (operands[0], operands[1], operands[2],
3104                                operands[3]));
3105       DONE;
3106    }
3107    else
3108      FAIL;
3109 })
3110
3111 (define_insn "insv<mode>"
3112   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
3113                           (match_operand:SI 1 "immediate_operand" "I")
3114                           (match_operand:SI 2 "immediate_operand" "I"))
3115         (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
3116   "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3117                        INTVAL (operands[2]))"
3118   "<d>ins\t%0,%z3,%2,%1"
3119   [(set_attr "type"     "arith")
3120    (set_attr "mode"     "<MODE>")])
3121
3122 ;; Unaligned word moves generated by the bit field patterns.
3123 ;;
3124 ;; As far as the rtl is concerned, both the left-part and right-part
3125 ;; instructions can access the whole field.  However, the real operand
3126 ;; refers to just the first or the last byte (depending on endianness).
3127 ;; We therefore use two memory operands to each instruction, one to
3128 ;; describe the rtl effect and one to use in the assembly output.
3129 ;;
3130 ;; Operands 0 and 1 are the rtl-level target and source respectively.
3131 ;; This allows us to use the standard length calculations for the "load"
3132 ;; and "store" type attributes.
3133
3134 (define_insn "mov_<load>l"
3135   [(set (match_operand:GPR 0 "register_operand" "=d")
3136         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3137                      (match_operand:QI 2 "memory_operand" "m")]
3138                     UNSPEC_LOAD_LEFT))]
3139   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3140   "<load>l\t%0,%2"
3141   [(set_attr "type" "load")
3142    (set_attr "mode" "<MODE>")])
3143
3144 (define_insn "mov_<load>r"
3145   [(set (match_operand:GPR 0 "register_operand" "=d")
3146         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3147                      (match_operand:QI 2 "memory_operand" "m")
3148                      (match_operand:GPR 3 "register_operand" "0")]
3149                     UNSPEC_LOAD_RIGHT))]
3150   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3151   "<load>r\t%0,%2"
3152   [(set_attr "type" "load")
3153    (set_attr "mode" "<MODE>")])
3154
3155 (define_insn "mov_<store>l"
3156   [(set (match_operand:BLK 0 "memory_operand" "=m")
3157         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3158                      (match_operand:QI 2 "memory_operand" "m")]
3159                     UNSPEC_STORE_LEFT))]
3160   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3161   "<store>l\t%z1,%2"
3162   [(set_attr "type" "store")
3163    (set_attr "mode" "<MODE>")])
3164
3165 (define_insn "mov_<store>r"
3166   [(set (match_operand:BLK 0 "memory_operand" "+m")
3167         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3168                      (match_operand:QI 2 "memory_operand" "m")
3169                      (match_dup 0)]
3170                     UNSPEC_STORE_RIGHT))]
3171   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3172   "<store>r\t%z1,%2"
3173   [(set_attr "type" "store")
3174    (set_attr "mode" "<MODE>")])
3175
3176 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
3177 ;; The required value is:
3178 ;;
3179 ;;      (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
3180 ;;
3181 ;; which translates to:
3182 ;;
3183 ;;      lui     op0,%highest(op1)
3184 ;;      daddiu  op0,op0,%higher(op1)
3185 ;;      dsll    op0,op0,16
3186 ;;      daddiu  op0,op0,%hi(op1)
3187 ;;      dsll    op0,op0,16
3188 ;;
3189 ;; The split is deferred until after flow2 to allow the peephole2 below
3190 ;; to take effect.
3191 (define_insn_and_split "*lea_high64"
3192   [(set (match_operand:DI 0 "register_operand" "=d")
3193         (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
3194   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3195   "#"
3196   "&& epilogue_completed"
3197   [(set (match_dup 0) (high:DI (match_dup 2)))
3198    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
3199    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
3200    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3201    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
3202 {
3203   operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3204   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
3205 }
3206   [(set_attr "length" "20")])
3207
3208 ;; Use a scratch register to reduce the latency of the above pattern
3209 ;; on superscalar machines.  The optimized sequence is:
3210 ;;
3211 ;;      lui     op1,%highest(op2)
3212 ;;      lui     op0,%hi(op2)
3213 ;;      daddiu  op1,op1,%higher(op2)
3214 ;;      dsll32  op1,op1,0
3215 ;;      daddu   op1,op1,op0
3216 (define_peephole2
3217   [(set (match_operand:DI 1 "register_operand")
3218         (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
3219    (match_scratch:DI 0 "d")]
3220   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3221   [(set (match_dup 1) (high:DI (match_dup 3)))
3222    (set (match_dup 0) (high:DI (match_dup 4)))
3223    (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
3224    (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
3225    (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
3226 {
3227   operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
3228   operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
3229 })
3230
3231 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
3232 ;; SYMBOL_ABSOLUTE X will take 6 cycles.  This next pattern allows combine
3233 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
3234 ;; used once.  We can then use the sequence:
3235 ;;
3236 ;;      lui     op0,%highest(op1)
3237 ;;      lui     op2,%hi(op1)
3238 ;;      daddiu  op0,op0,%higher(op1)
3239 ;;      daddiu  op2,op2,%lo(op1)
3240 ;;      dsll32  op0,op0,0
3241 ;;      daddu   op0,op0,op2
3242 ;;
3243 ;; which takes 4 cycles on most superscalar targets.
3244 (define_insn_and_split "*lea64"
3245   [(set (match_operand:DI 0 "register_operand" "=d")
3246         (match_operand:DI 1 "absolute_symbolic_operand" ""))
3247    (clobber (match_scratch:DI 2 "=&d"))]
3248   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS && cse_not_expected"
3249   "#"
3250   "&& reload_completed"
3251   [(set (match_dup 0) (high:DI (match_dup 3)))
3252    (set (match_dup 2) (high:DI (match_dup 4)))
3253    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3254    (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
3255    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
3256    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
3257 {
3258   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3259   operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
3260 }
3261   [(set_attr "length" "24")])
3262
3263 ;; Split HIGHs into:
3264 ;;
3265 ;;      li op0,%hi(sym)
3266 ;;      sll op0,16
3267 ;;
3268 ;; on MIPS16 targets.
3269 (define_split
3270   [(set (match_operand:SI 0 "register_operand" "=d")
3271         (high:SI (match_operand:SI 1 "absolute_symbolic_operand" "")))]
3272   "TARGET_MIPS16 && reload_completed"
3273   [(set (match_dup 0) (match_dup 2))
3274    (set (match_dup 0) (ashift:SI (match_dup 0) (const_int 16)))]
3275 {
3276   operands[2] = mips_unspec_address (operands[1], SYMBOL_32_HIGH);
3277 })
3278
3279 ;; Insns to fetch a symbol from a big GOT.
3280
3281 (define_insn_and_split "*xgot_hi<mode>"
3282   [(set (match_operand:P 0 "register_operand" "=d")
3283         (high:P (match_operand:P 1 "got_disp_operand" "")))]
3284   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
3285   "#"
3286   "&& reload_completed"
3287   [(set (match_dup 0) (high:P (match_dup 2)))
3288    (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
3289 {
3290   operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
3291   operands[3] = pic_offset_table_rtx;
3292 }
3293   [(set_attr "got" "xgot_high")
3294    (set_attr "mode" "<MODE>")])
3295
3296 (define_insn_and_split "*xgot_lo<mode>"
3297   [(set (match_operand:P 0 "register_operand" "=d")
3298         (lo_sum:P (match_operand:P 1 "register_operand" "d")
3299                   (match_operand:P 2 "got_disp_operand" "")))]
3300   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
3301   "#"
3302   "&& reload_completed"
3303   [(set (match_dup 0)
3304         (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
3305   { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
3306   [(set_attr "got" "load")
3307    (set_attr "mode" "<MODE>")])
3308
3309 ;; Insns to fetch a symbol from a normal GOT.
3310
3311 (define_insn_and_split "*got_disp<mode>"
3312   [(set (match_operand:P 0 "register_operand" "=d")
3313         (match_operand:P 1 "got_disp_operand" ""))]
3314   "TARGET_EXPLICIT_RELOCS && !TARGET_XGOT"
3315   "#"
3316   "&& reload_completed"
3317   [(set (match_dup 0)
3318         (unspec:P [(match_dup 2) (match_dup 3)] UNSPEC_LOAD_GOT))]
3319 {
3320   operands[2] = pic_offset_table_rtx;
3321   operands[3] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
3322 }
3323   [(set_attr "got" "load")
3324    (set_attr "mode" "<MODE>")])
3325
3326 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
3327
3328 (define_insn_and_split "*got_page<mode>"
3329   [(set (match_operand:P 0 "register_operand" "=d")
3330         (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
3331   "TARGET_EXPLICIT_RELOCS"
3332   "#"
3333   "&& reload_completed"
3334   [(set (match_dup 0)
3335         (unspec:P [(match_dup 2) (match_dup 3)] UNSPEC_LOAD_GOT))]
3336 {
3337   operands[2] = pic_offset_table_rtx;
3338   operands[3] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_PAGE);
3339 }
3340   [(set_attr "got" "load")
3341    (set_attr "mode" "<MODE>")])
3342
3343 ;; Lower-level instructions for loading an address from the GOT.
3344 ;; We could use MEMs, but an unspec gives more optimization
3345 ;; opportunities.
3346
3347 (define_insn "load_got<mode>"
3348   [(set (match_operand:P 0 "register_operand" "=d")
3349         (unspec:P [(match_operand:P 1 "register_operand" "d")
3350                    (match_operand:P 2 "immediate_operand" "")]
3351                   UNSPEC_LOAD_GOT))]
3352   ""
3353   "<load>\t%0,%R2(%1)"
3354   [(set_attr "type" "load")
3355    (set_attr "mode" "<MODE>")
3356    (set_attr "length" "4")])
3357
3358 ;; Instructions for adding the low 16 bits of an address to a register.
3359 ;; Operand 2 is the address: mips_print_operand works out which relocation
3360 ;; should be applied.
3361
3362 (define_insn "*low<mode>"
3363   [(set (match_operand:P 0 "register_operand" "=d")
3364         (lo_sum:P (match_operand:P 1 "register_operand" "d")
3365                   (match_operand:P 2 "immediate_operand" "")))]
3366   "!TARGET_MIPS16"
3367   "<d>addiu\t%0,%1,%R2"
3368   [(set_attr "type" "arith")
3369    (set_attr "mode" "<MODE>")])
3370
3371 (define_insn "*low<mode>_mips16"
3372   [(set (match_operand:P 0 "register_operand" "=d")
3373         (lo_sum:P (match_operand:P 1 "register_operand" "0")
3374                   (match_operand:P 2 "immediate_operand" "")))]
3375   "TARGET_MIPS16"
3376   "<d>addiu\t%0,%R2"
3377   [(set_attr "type" "arith")
3378    (set_attr "mode" "<MODE>")
3379    (set_attr "length" "8")])
3380
3381 ;; Allow combine to split complex const_int load sequences, using operand 2
3382 ;; to store the intermediate results.  See move_operand for details.
3383 (define_split
3384   [(set (match_operand:GPR 0 "register_operand")
3385         (match_operand:GPR 1 "splittable_const_int_operand"))
3386    (clobber (match_operand:GPR 2 "register_operand"))]
3387   ""
3388   [(const_int 0)]
3389 {
3390   mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
3391   DONE;
3392 })
3393
3394 ;; Likewise, for symbolic operands.
3395 (define_split
3396   [(set (match_operand:P 0 "register_operand")
3397         (match_operand:P 1))
3398    (clobber (match_operand:P 2 "register_operand"))]
3399   "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
3400   [(set (match_dup 0) (match_dup 3))]
3401 {
3402   mips_split_symbol (operands[2], operands[1],
3403                      MAX_MACHINE_MODE, &operands[3]);
3404 })
3405
3406 ;; 64-bit integer moves
3407
3408 ;; Unlike most other insns, the move insns can't be split with
3409 ;; different predicates, because register spilling and other parts of
3410 ;; the compiler, have memoized the insn number already.
3411
3412 (define_expand "movdi"
3413   [(set (match_operand:DI 0 "")
3414         (match_operand:DI 1 ""))]
3415   ""
3416 {
3417   if (mips_legitimize_move (DImode, operands[0], operands[1]))
3418     DONE;
3419 })
3420
3421 ;; For mips16, we need a special case to handle storing $31 into
3422 ;; memory, since we don't have a constraint to match $31.  This
3423 ;; instruction can be generated by save_restore_insns.
3424
3425 (define_insn "*mov<mode>_ra"
3426   [(set (match_operand:GPR 0 "stack_operand" "=m")
3427         (reg:GPR 31))]
3428   "TARGET_MIPS16"
3429   "<store>\t$31,%0"
3430   [(set_attr "type" "store")
3431    (set_attr "mode" "<MODE>")])
3432
3433 (define_insn "*movdi_32bit"
3434   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d,*B*C*D,*B*C*D,*d,*m")
3435         (match_operand:DI 1 "move_operand" "d,i,m,d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
3436   "!TARGET_64BIT && !TARGET_FLOAT64 && !TARGET_MIPS16
3437    && (register_operand (operands[0], DImode)
3438        || reg_or_0_operand (operands[1], DImode))"
3439   { return mips_output_move (operands[0], operands[1]); }
3440   [(set_attr "type"     "multi,multi,load,store,mthilo,mfhilo,mtc,load,mfc,store")
3441    (set_attr "mode"     "DI")
3442    (set_attr "length"   "8,16,*,*,8,8,8,*,8,*")])
3443
3444 (define_insn "*movdi_gp32_fp64"
3445   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d,*f,*f,*d,*m")
3446         (match_operand:DI 1 "move_operand" "d,i,m,d,*J*d,*a,*J*d,*m,*f,*f"))]
3447   "!TARGET_64BIT && TARGET_FLOAT64 && !TARGET_MIPS16
3448    && (register_operand (operands[0], DImode)
3449        || reg_or_0_operand (operands[1], DImode))"
3450   { return mips_output_move (operands[0], operands[1]); }
3451   [(set_attr "type"     "multi,multi,load,store,mthilo,mfhilo,mtc,fpload,mfc,fpstore")
3452    (set_attr "mode"     "DI")
3453    (set_attr "length"   "8,16,*,*,8,8,8,*,8,*")])
3454
3455 (define_insn "*movdi_32bit_mips16"
3456   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
3457         (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
3458   "!TARGET_64BIT && TARGET_MIPS16
3459    && (register_operand (operands[0], DImode)
3460        || register_operand (operands[1], DImode))"
3461   { return mips_output_move (operands[0], operands[1]); }
3462   [(set_attr "type"     "multi,multi,multi,multi,multi,load,store,mfhilo")
3463    (set_attr "mode"     "DI")
3464    (set_attr "length"   "8,8,8,8,12,*,*,8")])
3465
3466 (define_insn "*movdi_64bit"
3467   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*d,*m,*x,*B*C*D,*B*C*D,*d,*m")
3468         (match_operand:DI 1 "move_operand" "d,U,T,m,dJ,*d*J,*m,*f,*f,*J*d,*d,*m,*B*C*D,*B*C*D"))]
3469   "TARGET_64BIT && !TARGET_MIPS16
3470    && (register_operand (operands[0], DImode)
3471        || reg_or_0_operand (operands[1], DImode))"
3472   { return mips_output_move (operands[0], operands[1]); }
3473   [(set_attr "type"     "move,const,const,load,store,mtc,fpload,mfc,fpstore,mthilo,mtc,load,mfc,store")
3474    (set_attr "mode"     "DI")
3475    (set_attr "length"   "4,*,*,*,*,4,*,4,*,4,8,*,8,*")])
3476
3477 (define_insn "*movdi_64bit_mips16"
3478   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m")
3479         (match_operand:DI 1 "move_operand" "d,d,y,K,N,kf,U,m,d"))]
3480   "TARGET_64BIT && TARGET_MIPS16
3481    && (register_operand (operands[0], DImode)
3482        || register_operand (operands[1], DImode))"
3483   { return mips_output_move (operands[0], operands[1]); }
3484   [(set_attr "type"     "move,move,move,arith,arith,load,const,load,store")
3485    (set_attr "mode"     "DI")
3486    (set_attr_alternative "length"
3487                 [(const_int 4)
3488                  (const_int 4)
3489                  (const_int 4)
3490                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3491                                (const_int 4)
3492                                (const_int 8))
3493                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3494                                (const_int 8)
3495                                (const_int 12))
3496                  (const_int 8)
3497                  (const_string "*")
3498                  (const_string "*")
3499                  (const_string "*")])])
3500
3501
3502 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
3503 ;; when the original load is a 4 byte instruction but the add and the
3504 ;; load are 2 2 byte instructions.
3505
3506 (define_split
3507   [(set (match_operand:DI 0 "register_operand")
3508         (mem:DI (plus:DI (match_dup 0)
3509                          (match_operand:DI 1 "const_int_operand"))))]
3510   "TARGET_64BIT && TARGET_MIPS16 && reload_completed
3511    && !TARGET_DEBUG_D_MODE
3512    && REG_P (operands[0])
3513    && M16_REG_P (REGNO (operands[0]))
3514    && GET_CODE (operands[1]) == CONST_INT
3515    && ((INTVAL (operands[1]) < 0
3516         && INTVAL (operands[1]) >= -0x10)
3517        || (INTVAL (operands[1]) >= 32 * 8
3518            && INTVAL (operands[1]) <= 31 * 8 + 0x8)
3519        || (INTVAL (operands[1]) >= 0
3520            && INTVAL (operands[1]) < 32 * 8
3521            && (INTVAL (operands[1]) & 7) != 0))"
3522   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
3523    (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
3524 {
3525   HOST_WIDE_INT val = INTVAL (operands[1]);
3526
3527   if (val < 0)
3528     operands[2] = const0_rtx;
3529   else if (val >= 32 * 8)
3530     {
3531       int off = val & 7;
3532
3533       operands[1] = GEN_INT (0x8 + off);
3534       operands[2] = GEN_INT (val - off - 0x8);
3535     }
3536   else
3537     {
3538       int off = val & 7;
3539
3540       operands[1] = GEN_INT (off);
3541       operands[2] = GEN_INT (val - off);
3542     }
3543 })
3544
3545 ;; 32-bit Integer moves
3546
3547 ;; Unlike most other insns, the move insns can't be split with
3548 ;; different predicates, because register spilling and other parts of
3549 ;; the compiler, have memoized the insn number already.
3550
3551 (define_expand "movsi"
3552   [(set (match_operand:SI 0 "")
3553         (match_operand:SI 1 ""))]
3554   ""
3555 {
3556   if (mips_legitimize_move (SImode, operands[0], operands[1]))
3557     DONE;
3558 })
3559
3560 ;; The difference between these two is whether or not ints are allowed
3561 ;; in FP registers (off by default, use -mdebugh to enable).
3562
3563 (define_insn "*movsi_internal"
3564   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*d,*m,*d,*z,*a,*d,*B*C*D,*B*C*D,*d,*m")
3565         (match_operand:SI 1 "move_operand" "d,U,T,m,dJ,*d*J,*m,*f,*f,*z,*d,*J*d,*A,*d,*m,*B*C*D,*B*C*D"))]
3566   "!TARGET_MIPS16
3567    && (register_operand (operands[0], SImode)
3568        || reg_or_0_operand (operands[1], SImode))"
3569   { return mips_output_move (operands[0], operands[1]); }
3570   [(set_attr "type"     "move,const,const,load,store,mtc,fpload,mfc,fpstore,mfc,mtc,mthilo,mfhilo,mtc,load,mfc,store")
3571    (set_attr "mode"     "SI")
3572    (set_attr "length"   "4,*,*,*,*,4,*,4,*,4,4,4,4,4,*,4,*")])
3573
3574 (define_insn "*movsi_mips16"
3575   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m")
3576         (match_operand:SI 1 "move_operand" "d,d,y,K,N,kf,U,m,d"))]
3577   "TARGET_MIPS16
3578    && (register_operand (operands[0], SImode)
3579        || register_operand (operands[1], SImode))"
3580   { return mips_output_move (operands[0], operands[1]); }
3581   [(set_attr "type"     "move,move,move,arith,arith,load,const,load,store")
3582    (set_attr "mode"     "SI")
3583    (set_attr_alternative "length"
3584                 [(const_int 4)
3585                  (const_int 4)
3586                  (const_int 4)
3587                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3588                                (const_int 4)
3589                                (const_int 8))
3590                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3591                                (const_int 8)
3592                                (const_int 12))
3593                  (const_int 8)
3594                  (const_string "*")
3595                  (const_string "*")
3596                  (const_string "*")])])
3597
3598 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
3599 ;; when the original load is a 4 byte instruction but the add and the
3600 ;; load are 2 2 byte instructions.
3601
3602 (define_split
3603   [(set (match_operand:SI 0 "register_operand")
3604         (mem:SI (plus:SI (match_dup 0)
3605                          (match_operand:SI 1 "const_int_operand"))))]
3606   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3607    && REG_P (operands[0])
3608    && M16_REG_P (REGNO (operands[0]))
3609    && GET_CODE (operands[1]) == CONST_INT
3610    && ((INTVAL (operands[1]) < 0
3611         && INTVAL (operands[1]) >= -0x80)
3612        || (INTVAL (operands[1]) >= 32 * 4
3613            && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
3614        || (INTVAL (operands[1]) >= 0
3615            && INTVAL (operands[1]) < 32 * 4
3616            && (INTVAL (operands[1]) & 3) != 0))"
3617   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3618    (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
3619 {
3620   HOST_WIDE_INT val = INTVAL (operands[1]);
3621
3622   if (val < 0)
3623     operands[2] = const0_rtx;
3624   else if (val >= 32 * 4)
3625     {
3626       int off = val & 3;
3627
3628       operands[1] = GEN_INT (0x7c + off);
3629       operands[2] = GEN_INT (val - off - 0x7c);
3630     }
3631   else
3632     {
3633       int off = val & 3;
3634
3635       operands[1] = GEN_INT (off);
3636       operands[2] = GEN_INT (val - off);
3637     }
3638 })
3639
3640 ;; On the mips16, we can split a load of certain constants into a load
3641 ;; and an add.  This turns a 4 byte instruction into 2 2 byte
3642 ;; instructions.
3643
3644 (define_split
3645   [(set (match_operand:SI 0 "register_operand")
3646         (match_operand:SI 1 "const_int_operand"))]
3647   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3648    && REG_P (operands[0])
3649    && M16_REG_P (REGNO (operands[0]))
3650    && GET_CODE (operands[1]) == CONST_INT
3651    && INTVAL (operands[1]) >= 0x100
3652    && INTVAL (operands[1]) <= 0xff + 0x7f"
3653   [(set (match_dup 0) (match_dup 1))
3654    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
3655 {
3656   int val = INTVAL (operands[1]);
3657
3658   operands[1] = GEN_INT (0xff);
3659   operands[2] = GEN_INT (val - 0xff);
3660 })
3661
3662 ;; This insn handles moving CCmode values.  It's really just a
3663 ;; slightly simplified copy of movsi_internal2, with additional cases
3664 ;; to move a condition register to a general register and to move
3665 ;; between the general registers and the floating point registers.
3666
3667 (define_insn "movcc"
3668   [(set (match_operand:CC 0 "nonimmediate_operand" "=d,*d,*d,*m,*d,*f,*f,*f,*m")
3669         (match_operand:CC 1 "general_operand" "z,*d,*m,*d,*f,*d,*f,*m,*f"))]
3670   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3671   { return mips_output_move (operands[0], operands[1]); }
3672   [(set_attr "type"     "multi,move,load,store,mfc,mtc,fmove,fpload,fpstore")
3673    (set_attr "mode"     "SI")
3674    (set_attr "length"   "8,4,*,*,4,4,4,*,*")])
3675
3676 ;; Reload condition code registers.  reload_incc and reload_outcc
3677 ;; both handle moves from arbitrary operands into condition code
3678 ;; registers.  reload_incc handles the more common case in which
3679 ;; a source operand is constrained to be in a condition-code
3680 ;; register, but has not been allocated to one.
3681 ;;
3682 ;; Sometimes, such as in movcc, we have a CCmode destination whose
3683 ;; constraints do not include 'z'.  reload_outcc handles the case
3684 ;; when such an operand is allocated to a condition-code register.
3685 ;;
3686 ;; Note that reloads from a condition code register to some
3687 ;; other location can be done using ordinary moves.  Moving
3688 ;; into a GPR takes a single movcc, moving elsewhere takes
3689 ;; two.  We can leave these cases to the generic reload code.
3690 (define_expand "reload_incc"
3691   [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
3692         (match_operand:CC 1 "general_operand" ""))
3693    (clobber (match_operand:TF 2 "register_operand" "=&f"))]
3694   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3695 {
3696   mips_expand_fcc_reload (operands[0], operands[1], operands[2]);
3697   DONE;
3698 })
3699
3700 (define_expand "reload_outcc"
3701   [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
3702         (match_operand:CC 1 "register_operand" ""))
3703    (clobber (match_operand:TF 2 "register_operand" "=&f"))]
3704   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3705 {
3706   mips_expand_fcc_reload (operands[0], operands[1], operands[2]);
3707   DONE;
3708 })
3709
3710 ;; MIPS4 supports loading and storing a floating point register from
3711 ;; the sum of two general registers.  We use two versions for each of
3712 ;; these four instructions: one where the two general registers are
3713 ;; SImode, and one where they are DImode.  This is because general
3714 ;; registers will be in SImode when they hold 32-bit values, but,
3715 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
3716 ;; instructions will still work correctly.
3717
3718 ;; ??? Perhaps it would be better to support these instructions by
3719 ;; modifying GO_IF_LEGITIMATE_ADDRESS and friends.  However, since
3720 ;; these instructions can only be used to load and store floating
3721 ;; point registers, that would probably cause trouble in reload.
3722
3723 (define_insn "*<ANYF:loadx>_<P:mode>"
3724   [(set (match_operand:ANYF 0 "register_operand" "=f")
3725         (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
3726                           (match_operand:P 2 "register_operand" "d"))))]
3727   "ISA_HAS_FP4"
3728   "<ANYF:loadx>\t%0,%1(%2)"
3729   [(set_attr "type" "fpidxload")
3730    (set_attr "mode" "<ANYF:UNITMODE>")])
3731
3732 (define_insn "*<ANYF:storex>_<P:mode>"
3733   [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
3734                           (match_operand:P 2 "register_operand" "d")))
3735         (match_operand:ANYF 0 "register_operand" "f"))]
3736   "ISA_HAS_FP4"
3737   "<ANYF:storex>\t%0,%1(%2)"
3738   [(set_attr "type" "fpidxstore")
3739    (set_attr "mode" "<ANYF:UNITMODE>")])
3740
3741 ;; Scaled indexed address load.
3742 ;; Per md.texi, we only need to look for a pattern with multiply in the
3743 ;; address expression, not shift.
3744
3745 (define_insn "*lwxs"
3746   [(set (match_operand:SI 0 "register_operand" "=d")
3747         (mem:SI (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
3748                                   (const_int 4))
3749                          (match_operand:SI 2 "register_operand" "d"))))]
3750   "ISA_HAS_LWXS"
3751   "lwxs\t%0,%1(%2)"
3752   [(set_attr "type"     "load")
3753    (set_attr "mode"     "SI")
3754    (set_attr "length"   "4")])
3755
3756 ;; 16-bit Integer moves
3757
3758 ;; Unlike most other insns, the move insns can't be split with
3759 ;; different predicates, because register spilling and other parts of
3760 ;; the compiler, have memoized the insn number already.
3761 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
3762
3763 (define_expand "movhi"
3764   [(set (match_operand:HI 0 "")
3765         (match_operand:HI 1 ""))]
3766   ""
3767 {
3768   if (mips_legitimize_move (HImode, operands[0], operands[1]))
3769     DONE;
3770 })
3771
3772 (define_insn "*movhi_internal"
3773   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,m,*x")
3774         (match_operand:HI 1 "move_operand"         "d,I,m,dJ,*d"))]
3775   "!TARGET_MIPS16
3776    && (register_operand (operands[0], HImode)
3777        || reg_or_0_operand (operands[1], HImode))"
3778   "@
3779     move\t%0,%1
3780     li\t%0,%1
3781     lhu\t%0,%1
3782     sh\t%z1,%0
3783     mt%0\t%1"
3784   [(set_attr "type"     "move,arith,load,store,mthilo")
3785    (set_attr "mode"     "HI")
3786    (set_attr "length"   "4,4,*,*,4")])
3787
3788 (define_insn "*movhi_mips16"
3789   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m")
3790         (match_operand:HI 1 "move_operand"         "d,d,y,K,N,m,d"))]
3791   "TARGET_MIPS16
3792    && (register_operand (operands[0], HImode)
3793        || register_operand (operands[1], HImode))"
3794   "@
3795     move\t%0,%1
3796     move\t%0,%1
3797     move\t%0,%1
3798     li\t%0,%1
3799     #
3800     lhu\t%0,%1
3801     sh\t%1,%0"
3802   [(set_attr "type"     "move,move,move,arith,arith,load,store")
3803    (set_attr "mode"     "HI")
3804    (set_attr_alternative "length"
3805                 [(const_int 4)
3806                  (const_int 4)
3807                  (const_int 4)
3808                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3809                                (const_int 4)
3810                                (const_int 8))
3811                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3812                                (const_int 8)
3813                                (const_int 12))
3814                  (const_string "*")
3815                  (const_string "*")])])
3816
3817
3818 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
3819 ;; when the original load is a 4 byte instruction but the add and the
3820 ;; load are 2 2 byte instructions.
3821
3822 (define_split
3823   [(set (match_operand:HI 0 "register_operand")
3824         (mem:HI (plus:SI (match_dup 0)
3825                          (match_operand:SI 1 "const_int_operand"))))]
3826   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3827    && REG_P (operands[0])
3828    && M16_REG_P (REGNO (operands[0]))
3829    && GET_CODE (operands[1]) == CONST_INT
3830    && ((INTVAL (operands[1]) < 0
3831         && INTVAL (operands[1]) >= -0x80)
3832        || (INTVAL (operands[1]) >= 32 * 2
3833            && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
3834        || (INTVAL (operands[1]) >= 0
3835            && INTVAL (operands[1]) < 32 * 2
3836            && (INTVAL (operands[1]) & 1) != 0))"
3837   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3838    (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
3839 {
3840   HOST_WIDE_INT val = INTVAL (operands[1]);
3841
3842   if (val < 0)
3843     operands[2] = const0_rtx;
3844   else if (val >= 32 * 2)
3845     {
3846       int off = val & 1;
3847
3848       operands[1] = GEN_INT (0x7e + off);
3849       operands[2] = GEN_INT (val - off - 0x7e);
3850     }
3851   else
3852     {
3853       int off = val & 1;
3854
3855       operands[1] = GEN_INT (off);
3856       operands[2] = GEN_INT (val - off);
3857     }
3858 })
3859
3860 ;; 8-bit Integer moves
3861
3862 ;; Unlike most other insns, the move insns can't be split with
3863 ;; different predicates, because register spilling and other parts of
3864 ;; the compiler, have memoized the insn number already.
3865 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
3866
3867 (define_expand "movqi"
3868   [(set (match_operand:QI 0 "")
3869         (match_operand:QI 1 ""))]
3870   ""
3871 {
3872   if (mips_legitimize_move (QImode, operands[0], operands[1]))
3873     DONE;
3874 })
3875
3876 (define_insn "*movqi_internal"
3877   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,m,*x")
3878         (match_operand:QI 1 "move_operand"         "d,I,m,dJ,*d"))]
3879   "!TARGET_MIPS16
3880    && (register_operand (operands[0], QImode)
3881        || reg_or_0_operand (operands[1], QImode))"
3882   "@
3883     move\t%0,%1
3884     li\t%0,%1
3885     lbu\t%0,%1
3886     sb\t%z1,%0
3887     mt%0\t%1"
3888   [(set_attr "type"     "move,arith,load,store,mthilo")
3889    (set_attr "mode"     "QI")
3890    (set_attr "length"   "4,4,*,*,4")])
3891
3892 (define_insn "*movqi_mips16"
3893   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m")
3894         (match_operand:QI 1 "move_operand"         "d,d,y,K,N,m,d"))]
3895   "TARGET_MIPS16
3896    && (register_operand (operands[0], QImode)
3897        || register_operand (operands[1], QImode))"
3898   "@
3899     move\t%0,%1
3900     move\t%0,%1
3901     move\t%0,%1
3902     li\t%0,%1
3903     #
3904     lbu\t%0,%1
3905     sb\t%1,%0"
3906   [(set_attr "type"     "move,move,move,arith,arith,load,store")
3907    (set_attr "mode"     "QI")
3908    (set_attr "length"   "4,4,4,4,8,*,*")])
3909
3910 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
3911 ;; when the original load is a 4 byte instruction but the add and the
3912 ;; load are 2 2 byte instructions.
3913
3914 (define_split
3915   [(set (match_operand:QI 0 "register_operand")
3916         (mem:QI (plus:SI (match_dup 0)
3917                          (match_operand:SI 1 "const_int_operand"))))]
3918   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3919    && REG_P (operands[0])
3920    && M16_REG_P (REGNO (operands[0]))
3921    && GET_CODE (operands[1]) == CONST_INT
3922    && ((INTVAL (operands[1]) < 0
3923         && INTVAL (operands[1]) >= -0x80)
3924        || (INTVAL (operands[1]) >= 32
3925            && INTVAL (operands[1]) <= 31 + 0x7f))"
3926   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3927    (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
3928 {
3929   HOST_WIDE_INT val = INTVAL (operands[1]);
3930
3931   if (val < 0)
3932     operands[2] = const0_rtx;
3933   else
3934     {
3935       operands[1] = GEN_INT (0x7f);
3936       operands[2] = GEN_INT (val - 0x7f);
3937     }
3938 })
3939
3940 ;; 32-bit floating point moves
3941
3942 (define_expand "movsf"
3943   [(set (match_operand:SF 0 "")
3944         (match_operand:SF 1 ""))]
3945   ""
3946 {
3947   if (mips_legitimize_move (SFmode, operands[0], operands[1]))
3948     DONE;
3949 })
3950
3951 (define_insn "*movsf_hardfloat"
3952   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3953         (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
3954   "TARGET_HARD_FLOAT
3955    && (register_operand (operands[0], SFmode)
3956        || reg_or_0_operand (operands[1], SFmode))"
3957   { return mips_output_move (operands[0], operands[1]); }
3958   [(set_attr "type"     "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
3959    (set_attr "mode"     "SF")
3960    (set_attr "length"   "4,4,*,*,*,4,4,4,*,*")])
3961
3962 (define_insn "*movsf_softfloat"
3963   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
3964         (match_operand:SF 1 "move_operand" "Gd,m,d"))]
3965   "TARGET_SOFT_FLOAT && !TARGET_MIPS16
3966    && (register_operand (operands[0], SFmode)
3967        || reg_or_0_operand (operands[1], SFmode))"
3968   { return mips_output_move (operands[0], operands[1]); }
3969   [(set_attr "type"     "move,load,store")
3970    (set_attr "mode"     "SF")
3971    (set_attr "length"   "4,*,*")])
3972
3973 (define_insn "*movsf_mips16"
3974   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
3975         (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
3976   "TARGET_MIPS16
3977    && (register_operand (operands[0], SFmode)
3978        || register_operand (operands[1], SFmode))"
3979   { return mips_output_move (operands[0], operands[1]); }
3980   [(set_attr "type"     "move,move,move,load,store")
3981    (set_attr "mode"     "SF")
3982    (set_attr "length"   "4,4,4,*,*")])
3983
3984
3985 ;; 64-bit floating point moves
3986
3987 (define_expand "movdf"
3988   [(set (match_operand:DF 0 "")
3989         (match_operand:DF 1 ""))]
3990   ""
3991 {
3992   if (mips_legitimize_move (DFmode, operands[0], operands[1]))
3993     DONE;
3994 })
3995
3996 (define_insn "*movdf_hardfloat_64bit"
3997   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3998         (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
3999   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_64BIT
4000    && (register_operand (operands[0], DFmode)
4001        || reg_or_0_operand (operands[1], DFmode))"
4002   { return mips_output_move (operands[0], operands[1]); }
4003   [(set_attr "type"     "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4004    (set_attr "mode"     "DF")
4005    (set_attr "length"   "4,4,*,*,*,4,4,4,*,*")])
4006
4007 ;; This pattern applies to both !TARGET_FLOAT64 and TARGET_FLOAT64.
4008 (define_insn "*movdf_hardfloat_32bit"
4009   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4010         (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
4011   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT
4012    && (register_operand (operands[0], DFmode)
4013        || reg_or_0_operand (operands[1], DFmode))"
4014   { return mips_output_move (operands[0], operands[1]); }
4015   [(set_attr "type"     "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4016    (set_attr "mode"     "DF")
4017    (set_attr "length"   "4,8,*,*,*,8,8,8,*,*")])
4018
4019 (define_insn "*movdf_softfloat"
4020   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m,d,f,f")
4021         (match_operand:DF 1 "move_operand" "dG,m,dG,f,d,f"))]
4022   "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
4023    && (register_operand (operands[0], DFmode)
4024        || reg_or_0_operand (operands[1], DFmode))"
4025   { return mips_output_move (operands[0], operands[1]); }
4026   [(set_attr "type"     "multi,load,store,mfc,mtc,fmove")
4027    (set_attr "mode"     "DF")
4028    (set_attr "length"   "8,*,*,4,4,4")])
4029
4030 (define_insn "*movdf_mips16"
4031   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
4032         (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
4033   "TARGET_MIPS16
4034    && (register_operand (operands[0], DFmode)
4035        || register_operand (operands[1], DFmode))"
4036   { return mips_output_move (operands[0], operands[1]); }
4037   [(set_attr "type"     "multi,multi,multi,load,store")
4038    (set_attr "mode"     "DF")
4039    (set_attr "length"   "8,8,8,*,*")])
4040
4041 ;; 128-bit floating point moves
4042
4043 (define_expand "movtf"
4044   [(set (match_operand:TF 0 "")
4045         (match_operand:TF 1 ""))]
4046   ""
4047 {
4048   if (mips_legitimize_move (TFmode, operands[0], operands[1]))
4049     DONE;
4050 })
4051
4052 ;; This pattern handles both hard- and soft-float cases.
4053 (define_insn_and_split "*movtf_internal"
4054   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,R,f,dR")
4055         (match_operand:TF 1 "move_operand" "dGR,dG,dGR,f"))]
4056   ""
4057   "#"
4058   "&& reload_completed"
4059   [(const_int 0)]
4060 {
4061   mips_split_doubleword_move (operands[0], operands[1]);
4062   DONE;
4063 }
4064   [(set_attr "type" "multi")
4065    (set_attr "length" "16")])
4066
4067 (define_split
4068   [(set (match_operand:MOVE64 0 "nonimmediate_operand")
4069         (match_operand:MOVE64 1 "move_operand"))]
4070   "reload_completed && !TARGET_64BIT
4071    && mips_split_64bit_move_p (operands[0], operands[1])"
4072   [(const_int 0)]
4073 {
4074   mips_split_doubleword_move (operands[0], operands[1]);
4075   DONE;
4076 })
4077
4078 ;; When generating mips16 code, split moves of negative constants into
4079 ;; a positive "li" followed by a negation.
4080 (define_split
4081   [(set (match_operand 0 "register_operand")
4082         (match_operand 1 "const_int_operand"))]
4083   "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
4084   [(set (match_dup 2)
4085         (match_dup 3))
4086    (set (match_dup 2)
4087         (neg:SI (match_dup 2)))]
4088 {
4089   operands[2] = gen_lowpart (SImode, operands[0]);
4090   operands[3] = GEN_INT (-INTVAL (operands[1]));
4091 })
4092
4093 ;; 64-bit paired-single floating point moves
4094
4095 (define_expand "movv2sf"
4096   [(set (match_operand:V2SF 0)
4097         (match_operand:V2SF 1))]
4098   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
4099 {
4100   if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
4101     DONE;
4102 })
4103
4104 (define_insn "movv2sf_hardfloat_64bit"
4105   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4106         (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
4107   "TARGET_HARD_FLOAT
4108    && TARGET_PAIRED_SINGLE_FLOAT
4109    && TARGET_64BIT
4110    && (register_operand (operands[0], V2SFmode)
4111        || reg_or_0_operand (operands[1], V2SFmode))"
4112   { return mips_output_move (operands[0], operands[1]); }
4113   [(set_attr "type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4114    (set_attr "mode" "SF")
4115    (set_attr "length" "4,4,*,*,*,4,4,4,*,*")])
4116
4117 (define_insn "movv2sf_hardfloat_32bit"
4118   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4119         (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
4120   "TARGET_HARD_FLOAT
4121    && TARGET_PAIRED_SINGLE_FLOAT
4122    && !TARGET_64BIT
4123    && (register_operand (operands[0], V2SFmode)
4124        || reg_or_0_operand (operands[1], V2SFmode))"
4125   { return mips_output_move (operands[0], operands[1]); }
4126   [(set_attr "type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4127    (set_attr "mode" "SF")
4128    (set_attr "length" "4,8,*,*,*,8,8,8,*,*")])
4129
4130 ;; The HI and LO registers are not truly independent.  If we move an mthi
4131 ;; instruction before an mflo instruction, it will make the result of the
4132 ;; mflo unpredictable.  The same goes for mtlo and mfhi.
4133 ;;
4134 ;; We cope with this by making the mflo and mfhi patterns use both HI and LO.
4135 ;; Operand 1 is the register we want, operand 2 is the other one.
4136 ;;
4137 ;; When generating VR4120 or VR4130 code, we use macc{,hi} and
4138 ;; dmacc{,hi} instead of mfhi and mflo.  This avoids both the normal
4139 ;; MIPS III hi/lo hazards and the errata related to -mfix-vr4130.
4140
4141 (define_expand "mfhilo_<mode>"
4142   [(set (match_operand:GPR 0 "register_operand")
4143         (unspec:GPR [(match_operand:GPR 1 "register_operand")
4144                      (match_operand:GPR 2 "register_operand")]
4145                     UNSPEC_MFHILO))])
4146
4147 (define_insn "*mfhilo_<mode>"
4148   [(set (match_operand:GPR 0 "register_operand" "=d,d")
4149         (unspec:GPR [(match_operand:GPR 1 "register_operand" "h,l")
4150                      (match_operand:GPR 2 "register_operand" "l,h")]
4151                     UNSPEC_MFHILO))]
4152   "!ISA_HAS_MACCHI"
4153   "mf%1\t%0"
4154   [(set_attr "type" "mfhilo")
4155    (set_attr "mode" "<MODE>")])
4156
4157 (define_insn "*mfhilo_<mode>_macc"
4158   [(set (match_operand:GPR 0 "register_operand" "=d,d")
4159         (unspec:GPR [(match_operand:GPR 1 "register_operand" "h,l")
4160                      (match_operand:GPR 2 "register_operand" "l,h")]
4161                     UNSPEC_MFHILO))]
4162   "ISA_HAS_MACCHI"
4163   "@
4164    <d>macchi\t%0,%.,%.
4165    <d>macc\t%0,%.,%."
4166   [(set_attr "type" "mfhilo")
4167    (set_attr "mode" "<MODE>")])
4168
4169 ;; Emit a doubleword move in which exactly one of the operands is
4170 ;; a floating-point register.  We can't just emit two normal moves
4171 ;; because of the constraints imposed by the FPU register model;
4172 ;; see mips_cannot_change_mode_class for details.  Instead, we keep
4173 ;; the FPR whole and use special patterns to refer to each word of
4174 ;; the other operand.
4175
4176 (define_expand "move_doubleword_fpr<mode>"
4177   [(set (match_operand:SPLITF 0)
4178         (match_operand:SPLITF 1))]
4179   ""
4180 {
4181   if (FP_REG_RTX_P (operands[0]))
4182     {
4183       rtx low = mips_subword (operands[1], 0);
4184       rtx high = mips_subword (operands[1], 1);
4185       emit_insn (gen_load_low<mode> (operands[0], low));
4186       if (ISA_HAS_MXHC1)
4187         emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
4188       else
4189         emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
4190     }
4191   else
4192     {
4193       rtx low = mips_subword (operands[0], 0);
4194       rtx high = mips_subword (operands[0], 1);
4195       emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
4196       if (ISA_HAS_MXHC1)
4197         emit_insn (gen_mfhc1<mode> (high, operands[1]));
4198       else
4199         emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
4200     }
4201   DONE;
4202 })
4203
4204 ;; Load the low word of operand 0 with operand 1.
4205 (define_insn "load_low<mode>"
4206   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4207         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
4208                        UNSPEC_LOAD_LOW))]
4209   "TARGET_HARD_FLOAT"
4210 {
4211   operands[0] = mips_subword (operands[0], 0);
4212   return mips_output_move (operands[0], operands[1]);
4213 }
4214   [(set_attr "type" "mtc,fpload")
4215    (set_attr "mode" "<HALFMODE>")])
4216
4217 ;; Load the high word of operand 0 from operand 1, preserving the value
4218 ;; in the low word.
4219 (define_insn "load_high<mode>"
4220   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4221         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
4222                         (match_operand:SPLITF 2 "register_operand" "0,0")]
4223                        UNSPEC_LOAD_HIGH))]
4224   "TARGET_HARD_FLOAT"
4225 {
4226   operands[0] = mips_subword (operands[0], 1);
4227   return mips_output_move (operands[0], operands[1]);
4228 }
4229   [(set_attr "type" "mtc,fpload")
4230    (set_attr "mode" "<HALFMODE>")])
4231
4232 ;; Store one word of operand 1 in operand 0.  Operand 2 is 1 to store the
4233 ;; high word and 0 to store the low word.
4234 (define_insn "store_word<mode>"
4235   [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
4236         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
4237                             (match_operand 2 "const_int_operand")]
4238                            UNSPEC_STORE_WORD))]
4239   "TARGET_HARD_FLOAT"
4240 {
4241   operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
4242   return mips_output_move (operands[0], operands[1]);
4243 }
4244   [(set_attr "type" "mfc,fpstore")
4245    (set_attr "mode" "<HALFMODE>")])
4246
4247 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
4248 ;; value in the low word.
4249 (define_insn "mthc1<mode>"
4250   [(set (match_operand:SPLITF 0 "register_operand" "=f")
4251         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ")
4252                         (match_operand:SPLITF 2 "register_operand" "0")]
4253                        UNSPEC_MTHC1))]
4254   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4255   "mthc1\t%z1,%0"
4256   [(set_attr "type" "mtc")
4257    (set_attr "mode" "<HALFMODE>")])
4258
4259 ;; Move high word of operand 1 to operand 0 using mfhc1.
4260 (define_insn "mfhc1<mode>"
4261   [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
4262         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
4263                             UNSPEC_MFHC1))]
4264   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4265   "mfhc1\t%0,%1"
4266   [(set_attr "type" "mfc")
4267    (set_attr "mode" "<HALFMODE>")])
4268
4269 ;; Move a constant that satisfies CONST_GP_P into operand 0.
4270 (define_expand "load_const_gp"
4271   [(set (match_operand 0 "register_operand" "=d")
4272         (const (unspec [(const_int 0)] UNSPEC_GP)))])
4273
4274 ;; Insn to initialize $gp for n32/n64 abicalls.  Operand 0 is the offset
4275 ;; of _gp from the start of this function.  Operand 1 is the incoming
4276 ;; function address.
4277 (define_insn_and_split "loadgp_newabi_<mode>"
4278   [(set (match_operand:P 0 "register_operand" "=d")
4279         (unspec_volatile:P [(match_operand:P 1)
4280                             (match_operand:P 2 "register_operand" "d")]
4281                            UNSPEC_LOADGP))]
4282   "mips_current_loadgp_style () == LOADGP_NEWABI"
4283   "#"
4284   ""
4285   [(set (match_dup 0) (match_dup 3))
4286    (set (match_dup 0) (match_dup 4))
4287    (set (match_dup 0) (match_dup 5))]
4288 {
4289   operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
4290   operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
4291   operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
4292 }
4293   [(set_attr "length" "12")])
4294
4295 ;; Likewise, for -mno-shared code.  Operand 0 is the __gnu_local_gp symbol.
4296 (define_insn_and_split "loadgp_absolute_<mode>"
4297   [(set (match_operand:P 0 "register_operand" "=d")
4298         (unspec_volatile:P [(match_operand:P 1)] UNSPEC_LOADGP))]
4299   "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
4300   "#"
4301   ""
4302   [(const_int 0)]
4303 {
4304   mips_emit_move (operands[0], operands[1]);
4305   DONE;
4306 }
4307   [(set_attr "length" "8")])
4308
4309 ;; The use of gp is hidden when not using explicit relocations.
4310 ;; This blockage instruction prevents the gp load from being
4311 ;; scheduled after an implicit use of gp.  It also prevents
4312 ;; the load from being deleted as dead.
4313 (define_insn "loadgp_blockage"
4314   [(unspec_volatile [(reg:DI 28)] UNSPEC_BLOCKAGE)]
4315   ""
4316   ""
4317   [(set_attr "type"     "unknown")
4318    (set_attr "mode"     "none")
4319    (set_attr "length"   "0")])
4320
4321 ;; Initialize $gp for RTP PIC.  Operand 0 is the __GOTT_BASE__ symbol
4322 ;; and operand 1 is the __GOTT_INDEX__ symbol.
4323 (define_insn_and_split "loadgp_rtp_<mode>"
4324   [(set (match_operand:P 0 "register_operand" "=d")
4325         (unspec_volatile:P [(match_operand:P 1 "symbol_ref_operand")
4326                             (match_operand:P 2 "symbol_ref_operand")]
4327                            UNSPEC_LOADGP))]
4328   "mips_current_loadgp_style () == LOADGP_RTP"
4329   "#"
4330   ""
4331   [(set (match_dup 0) (high:P (match_dup 3)))
4332    (set (match_dup 0) (unspec:P [(match_dup 0)
4333                                  (match_dup 3)] UNSPEC_LOAD_GOT))
4334    (set (match_dup 0) (unspec:P [(match_dup 0)
4335                                  (match_dup 4)] UNSPEC_LOAD_GOT))]
4336 {
4337   operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
4338   operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
4339 }
4340   [(set_attr "length" "12")])
4341
4342 ;; Emit a .cprestore directive, which normally expands to a single store
4343 ;; instruction.  Note that we continue to use .cprestore for explicit reloc
4344 ;; code so that jals inside inline asms will work correctly.
4345 (define_insn "cprestore"
4346   [(unspec_volatile [(match_operand 0 "const_int_operand" "I,i")
4347                      (use (reg:SI 28))]
4348                     UNSPEC_CPRESTORE)]
4349   ""
4350 {
4351   if (set_nomacro && which_alternative == 1)
4352     return ".set\tmacro\;.cprestore\t%0\;.set\tnomacro";
4353   else
4354     return ".cprestore\t%0";
4355 }
4356   [(set_attr "type" "store")
4357    (set_attr "length" "4,12")])
4358
4359 ;; Expand in-line code to clear the instruction cache between operand[0] and
4360 ;; operand[1].
4361 (define_expand "clear_cache"
4362   [(match_operand 0 "pmode_register_operand")
4363    (match_operand 1 "pmode_register_operand")]
4364   ""
4365   "
4366 {
4367   if (ISA_HAS_SYNCI)
4368     {
4369       mips_expand_synci_loop (operands[0], operands[1]);
4370       emit_insn (gen_sync ());
4371       emit_insn (gen_clear_hazard ());
4372     }
4373   else if (mips_cache_flush_func && mips_cache_flush_func[0])
4374     {
4375       rtx len = gen_reg_rtx (Pmode);
4376       emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
4377       MIPS_ICACHE_SYNC (operands[0], len);
4378     }
4379   DONE;
4380 }")
4381
4382 (define_insn "sync"
4383   [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
4384   "GENERATE_SYNC"
4385   "%|sync%-")
4386
4387 (define_insn "synci"
4388   [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
4389                     UNSPEC_SYNCI)]
4390   "ISA_HAS_SYNCI"
4391   "synci\t0(%0)")
4392
4393 (define_insn "rdhwr"
4394   [(set (match_operand:SI 0 "register_operand" "=d")
4395         (unspec_volatile [(match_operand:SI 1 "const_int_operand" "n")]
4396         UNSPEC_RDHWR))]
4397   "ISA_HAS_SYNCI"
4398   "rdhwr\t%0,$%1")
4399
4400 (define_insn "clear_hazard"
4401   [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
4402    (clobber (reg:SI 31))]
4403   "ISA_HAS_SYNCI"
4404 {
4405   return "%(%<bal\t1f\n"
4406          "\tnop\n"
4407          "1:\taddiu\t$31,$31,12\n"
4408          "\tjr.hb\t$31\n"
4409          "\tnop%>%)";
4410 }
4411   [(set_attr "length" "20")])
4412
4413 ;; Atomic memory operations.
4414
4415 (define_insn "memory_barrier"
4416   [(set (mem:BLK (scratch))
4417         (unspec:BLK [(const_int 0)] UNSPEC_MEMORY_BARRIER))]
4418   "GENERATE_SYNC"
4419   "%|sync%-")
4420
4421 (define_insn "sync_compare_and_swap<mode>"
4422   [(set (match_operand:GPR 0 "register_operand" "=&d,&d")
4423         (match_operand:GPR 1 "memory_operand" "+R,R"))
4424    (set (match_dup 1)
4425         (unspec_volatile:GPR [(match_operand:GPR 2 "reg_or_0_operand" "dJ,dJ")
4426                               (match_operand:GPR 3 "arith_operand" "I,d")]
4427          UNSPEC_COMPARE_AND_SWAP))]
4428   "GENERATE_LL_SC"
4429 {
4430   if (which_alternative == 0)
4431     return MIPS_COMPARE_AND_SWAP ("<d>", "li");
4432   else
4433     return MIPS_COMPARE_AND_SWAP ("<d>", "move");
4434 }
4435   [(set_attr "length" "32")])
4436
4437 (define_insn "sync_add<mode>"
4438   [(set (match_operand:GPR 0 "memory_operand" "+R,R")
4439         (unspec_volatile:GPR
4440           [(plus:GPR (match_dup 0)
4441                               (match_operand:GPR 1 "arith_operand" "I,d"))]
4442          UNSPEC_SYNC_OLD_OP))]
4443   "GENERATE_LL_SC"
4444 {
4445   if (which_alternative == 0)
4446     return MIPS_SYNC_OP ("<d>", "<d>addiu");    
4447   else
4448     return MIPS_SYNC_OP ("<d>", "<d>addu");     
4449 }
4450   [(set_attr "length" "28")])
4451
4452 (define_insn "sync_sub<mode>"
4453   [(set (match_operand:GPR 0 "memory_operand" "+R")
4454         (unspec_volatile:GPR
4455           [(minus:GPR (match_dup 0)
4456                               (match_operand:GPR 1 "register_operand" "d"))]
4457          UNSPEC_SYNC_OLD_OP))]
4458   "GENERATE_LL_SC"
4459 {
4460   return MIPS_SYNC_OP ("<d>", "<d>subu");       
4461 }
4462   [(set_attr "length" "28")])
4463
4464 (define_insn "sync_old_add<mode>"
4465   [(set (match_operand:GPR 0 "register_operand" "=d,&d")
4466         (match_operand:GPR 1 "memory_operand" "+R,R"))
4467    (set (match_dup 1)
4468         (unspec_volatile:GPR
4469           [(plus:GPR (match_dup 1)
4470                      (match_operand:GPR 2 "arith_operand" "I,d"))]
4471          UNSPEC_SYNC_OLD_OP))]
4472   "GENERATE_LL_SC"
4473 {
4474   if (which_alternative == 0)
4475     return MIPS_SYNC_OLD_OP ("<d>", "<d>addiu");        
4476   else
4477     return MIPS_SYNC_OLD_OP ("<d>", "<d>addu"); 
4478 }
4479   [(set_attr "length" "28")])
4480
4481 (define_insn "sync_old_sub<mode>"
4482   [(set (match_operand:GPR 0 "register_operand" "=&d")
4483         (match_operand:GPR 1 "memory_operand" "+R"))
4484    (set (match_dup 1)
4485         (unspec_volatile:GPR
4486           [(minus:GPR (match_dup 1)
4487                       (match_operand:GPR 2 "register_operand" "d"))]
4488          UNSPEC_SYNC_OLD_OP))]
4489   "GENERATE_LL_SC"
4490 {
4491   return MIPS_SYNC_OLD_OP ("<d>", "<d>subu");   
4492 }
4493   [(set_attr "length" "28")])
4494
4495 (define_insn "sync_new_add<mode>"
4496   [(set (match_operand:GPR 0 "register_operand" "=d,&d")
4497         (plus:GPR (match_operand:GPR 1 "memory_operand" "+R,R")
4498                   (match_operand:GPR 2 "arith_operand" "I,d")))
4499    (set (match_dup 1)
4500         (unspec_volatile:GPR
4501           [(plus:GPR (match_dup 1) (match_dup 2))]
4502          UNSPEC_SYNC_NEW_OP))]
4503   "GENERATE_LL_SC"
4504 {
4505   if (which_alternative == 0)
4506     return MIPS_SYNC_NEW_OP ("<d>", "<d>addiu");        
4507   else
4508     return MIPS_SYNC_NEW_OP ("<d>", "<d>addu"); 
4509 }
4510   [(set_attr "length" "28")])
4511
4512 (define_insn "sync_new_sub<mode>"
4513   [(set (match_operand:GPR 0 "register_operand" "=&d")
4514         (minus:GPR (match_operand:GPR 1 "memory_operand" "+R")
4515                    (match_operand:GPR 2 "register_operand" "d")))
4516    (set (match_dup 1)
4517         (unspec_volatile:GPR
4518           [(minus:GPR (match_dup 1) (match_dup 2))]
4519          UNSPEC_SYNC_NEW_OP))]
4520   "GENERATE_LL_SC"
4521 {
4522   return MIPS_SYNC_NEW_OP ("<d>", "<d>subu");   
4523 }
4524   [(set_attr "length" "28")])
4525
4526 (define_insn "sync_<optab><mode>"
4527   [(set (match_operand:GPR 0 "memory_operand" "+R,R")
4528         (unspec_volatile:GPR
4529           [(fetchop_bit:GPR (match_operand:GPR 1 "uns_arith_operand" "K,d")
4530                               (match_dup 0))]
4531          UNSPEC_SYNC_OLD_OP))]
4532   "GENERATE_LL_SC"
4533 {
4534   if (which_alternative == 0)
4535     return MIPS_SYNC_OP ("<d>", "<immediate_insn>");    
4536   else
4537     return MIPS_SYNC_OP ("<d>", "<insn>");      
4538 }
4539   [(set_attr "length" "28")])
4540
4541 (define_insn "sync_old_<optab><mode>"
4542   [(set (match_operand:GPR 0 "register_operand" "=d,&d")
4543         (match_operand:GPR 1 "memory_operand" "+R,R"))
4544    (set (match_dup 1)
4545         (unspec_volatile:GPR
4546           [(fetchop_bit:GPR (match_operand:GPR 2 "uns_arith_operand" "K,d")
4547                             (match_dup 1))]
4548          UNSPEC_SYNC_OLD_OP))]
4549   "GENERATE_LL_SC"
4550 {
4551   if (which_alternative == 0)
4552     return MIPS_SYNC_OLD_OP ("<d>", "<immediate_insn>");        
4553   else
4554     return MIPS_SYNC_OLD_OP ("<d>", "<insn>");  
4555 }
4556   [(set_attr "length" "28")])
4557
4558 (define_insn "sync_new_<optab><mode>"
4559   [(set (match_operand:GPR 0 "register_operand" "=d,&d")
4560         (match_operand:GPR 1 "memory_operand" "+R,R"))
4561    (set (match_dup 1)
4562         (unspec_volatile:GPR
4563           [(fetchop_bit:GPR (match_operand:GPR 2 "uns_arith_operand" "K,d")
4564                             (match_dup 1))]
4565          UNSPEC_SYNC_NEW_OP))]
4566   "GENERATE_LL_SC"
4567 {
4568   if (which_alternative == 0)
4569     return MIPS_SYNC_NEW_OP ("<d>", "<immediate_insn>");        
4570   else
4571     return MIPS_SYNC_NEW_OP ("<d>", "<insn>");  
4572 }
4573   [(set_attr "length" "28")])
4574
4575 (define_insn "sync_nand<mode>"
4576   [(set (match_operand:GPR 0 "memory_operand" "+R,R")
4577         (unspec_volatile:GPR [(match_operand:GPR 1 "uns_arith_operand" "K,d")]
4578          UNSPEC_SYNC_OLD_OP))]
4579   "GENERATE_LL_SC"
4580 {
4581   if (which_alternative == 0)
4582     return MIPS_SYNC_NAND ("<d>", "andi");      
4583   else
4584     return MIPS_SYNC_NAND ("<d>", "and");       
4585 }
4586   [(set_attr "length" "32")])
4587
4588 (define_insn "sync_old_nand<mode>"
4589   [(set (match_operand:GPR 0 "register_operand" "=d,&d")
4590         (match_operand:GPR 1 "memory_operand" "+R,R"))
4591    (set (match_dup 1)
4592         (unspec_volatile:GPR [(match_operand:GPR 2 "uns_arith_operand" "K,d")]
4593          UNSPEC_SYNC_OLD_OP))]
4594   "GENERATE_LL_SC"
4595 {
4596   if (which_alternative == 0)
4597     return MIPS_SYNC_OLD_NAND ("<d>", "andi");  
4598   else
4599     return MIPS_SYNC_OLD_NAND ("<d>", "and");   
4600 }
4601   [(set_attr "length" "32")])
4602
4603 (define_insn "sync_new_nand<mode>"
4604   [(set (match_operand:GPR 0 "register_operand" "=d,&d")
4605         (match_operand:GPR 1 "memory_operand" "+R,R"))
4606    (set (match_dup 1)
4607         (unspec_volatile:GPR [(match_operand:GPR 2 "uns_arith_operand" "K,d")]
4608          UNSPEC_SYNC_NEW_OP))]
4609   "GENERATE_LL_SC"
4610 {
4611   if (which_alternative == 0)
4612     return MIPS_SYNC_NEW_NAND ("<d>", "andi");  
4613   else
4614     return MIPS_SYNC_NEW_NAND ("<d>", "and");   
4615 }
4616   [(set_attr "length" "32")])
4617
4618 (define_insn "sync_lock_test_and_set<mode>"
4619   [(set (match_operand:GPR 0 "register_operand" "=d,&d")
4620         (match_operand:GPR 1 "memory_operand" "+R,R"))
4621    (set (match_dup 1)
4622         (unspec_volatile:GPR [(match_operand:GPR 2 "arith_operand" "I,d")]
4623          UNSPEC_SYNC_EXCHANGE))]
4624   "GENERATE_LL_SC"
4625 {
4626   if (which_alternative == 0)
4627     return MIPS_SYNC_EXCHANGE ("<d>", "li");
4628   else
4629     return MIPS_SYNC_EXCHANGE ("<d>", "move");
4630 }
4631   [(set_attr "length" "24")])
4632 \f
4633 ;; Block moves, see mips.c for more details.
4634 ;; Argument 0 is the destination
4635 ;; Argument 1 is the source
4636 ;; Argument 2 is the length
4637 ;; Argument 3 is the alignment
4638
4639 (define_expand "movmemsi"
4640   [(parallel [(set (match_operand:BLK 0 "general_operand")
4641                    (match_operand:BLK 1 "general_operand"))
4642               (use (match_operand:SI 2 ""))
4643               (use (match_operand:SI 3 "const_int_operand"))])]
4644   "!TARGET_MIPS16 && !TARGET_MEMCPY"
4645 {
4646   if (mips_expand_block_move (operands[0], operands[1], operands[2]))
4647     DONE;
4648   else
4649     FAIL;
4650 })
4651 \f
4652 ;;
4653 ;;  ....................
4654 ;;
4655 ;;      SHIFTS
4656 ;;
4657 ;;  ....................
4658
4659 (define_expand "<optab><mode>3"
4660   [(set (match_operand:GPR 0 "register_operand")
4661         (any_shift:GPR (match_operand:GPR 1 "register_operand")
4662                        (match_operand:SI 2 "arith_operand")))]
4663   ""
4664 {
4665   /* On the mips16, a shift of more than 8 is a four byte instruction,
4666      so, for a shift between 8 and 16, it is just as fast to do two
4667      shifts of 8 or less.  If there is a lot of shifting going on, we
4668      may win in CSE.  Otherwise combine will put the shifts back
4669      together again.  This can be called by mips_function_arg, so we must
4670      be careful not to allocate a new register if we've reached the
4671      reload pass.  */
4672   if (TARGET_MIPS16
4673       && optimize
4674       && GET_CODE (operands[2]) == CONST_INT
4675       && INTVAL (operands[2]) > 8
4676       && INTVAL (operands[2]) <= 16
4677       && !reload_in_progress
4678       && !reload_completed)
4679     {
4680       rtx temp = gen_reg_rtx (<MODE>mode);
4681
4682       emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
4683       emit_insn (gen_<optab><mode>3 (operands[0], temp,
4684                                      GEN_INT (INTVAL (operands[2]) - 8)));
4685       DONE;
4686     }
4687 })
4688
4689 (define_insn "*<optab><mode>3"
4690   [(set (match_operand:GPR 0 "register_operand" "=d")
4691         (any_shift:GPR (match_operand:GPR 1 "register_operand" "d")
4692                        (match_operand:SI 2 "arith_operand" "dI")))]
4693   "!TARGET_MIPS16"
4694 {
4695   if (GET_CODE (operands[2]) == CONST_INT)
4696     operands[2] = GEN_INT (INTVAL (operands[2])
4697                            & (GET_MODE_BITSIZE (<MODE>mode) - 1));
4698
4699   return "<d><insn>\t%0,%1,%2";
4700 }
4701   [(set_attr "type" "shift")
4702    (set_attr "mode" "<MODE>")])
4703
4704 (define_insn "*<optab>si3_extend"
4705   [(set (match_operand:DI 0 "register_operand" "=d")
4706         (sign_extend:DI
4707            (any_shift:SI (match_operand:SI 1 "register_operand" "d")
4708                          (match_operand:SI 2 "arith_operand" "dI"))))]
4709   "TARGET_64BIT && !TARGET_MIPS16"
4710 {
4711   if (GET_CODE (operands[2]) == CONST_INT)
4712     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
4713
4714   return "<insn>\t%0,%1,%2";
4715 }
4716   [(set_attr "type" "shift")
4717    (set_attr "mode" "SI")])
4718
4719 (define_insn "*<optab>si3_mips16"
4720   [(set (match_operand:SI 0 "register_operand" "=d,d")
4721         (any_shift:SI (match_operand:SI 1 "register_operand" "0,d")
4722                       (match_operand:SI 2 "arith_operand" "d,I")))]
4723   "TARGET_MIPS16"
4724 {
4725   if (which_alternative == 0)
4726     return "<insn>\t%0,%2";
4727
4728   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
4729   return "<insn>\t%0,%1,%2";
4730 }
4731   [(set_attr "type" "shift")
4732    (set_attr "mode" "SI")
4733    (set_attr_alternative "length"
4734                 [(const_int 4)
4735                  (if_then_else (match_operand 2 "m16_uimm3_b")
4736                                (const_int 4)
4737                                (const_int 8))])])
4738
4739 ;; We need separate DImode MIPS16 patterns because of the irregularity
4740 ;; of right shifts.
4741 (define_insn "*ashldi3_mips16"
4742   [(set (match_operand:DI 0 "register_operand" "=d,d")
4743         (ashift:DI (match_operand:DI 1 "register_operand" "0,d")
4744                    (match_operand:SI 2 "arith_operand" "d,I")))]
4745   "TARGET_64BIT && TARGET_MIPS16"
4746 {
4747   if (which_alternative == 0)
4748     return "dsll\t%0,%2";
4749
4750   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
4751   return "dsll\t%0,%1,%2";
4752 }
4753   [(set_attr "type" "shift")
4754    (set_attr "mode" "DI")
4755    (set_attr_alternative "length"
4756                 [(const_int 4)
4757                  (if_then_else (match_operand 2 "m16_uimm3_b")
4758                                (const_int 4)
4759                                (const_int 8))])])
4760
4761 (define_insn "*ashrdi3_mips16"
4762   [(set (match_operand:DI 0 "register_operand" "=d,d")
4763         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
4764                      (match_operand:SI 2 "arith_operand" "d,I")))]
4765   "TARGET_64BIT && TARGET_MIPS16"
4766 {
4767   if (GET_CODE (operands[2]) == CONST_INT)
4768     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
4769
4770   return "dsra\t%0,%2";
4771 }
4772   [(set_attr "type" "shift")
4773    (set_attr "mode" "DI")
4774    (set_attr_alternative "length"
4775                 [(const_int 4)
4776                  (if_then_else (match_operand 2 "m16_uimm3_b")
4777                                (const_int 4)
4778                                (const_int 8))])])
4779
4780 (define_insn "*lshrdi3_mips16"
4781   [(set (match_operand:DI 0 "register_operand" "=d,d")
4782         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
4783                      (match_operand:SI 2 "arith_operand" "d,I")))]
4784   "TARGET_64BIT && TARGET_MIPS16"
4785 {
4786   if (GET_CODE (operands[2]) == CONST_INT)
4787     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
4788
4789   return "dsrl\t%0,%2";
4790 }
4791   [(set_attr "type" "shift")
4792    (set_attr "mode" "DI")
4793    (set_attr_alternative "length"
4794                 [(const_int 4)
4795                  (if_then_else (match_operand 2 "m16_uimm3_b")
4796                                (const_int 4)
4797                                (const_int 8))])])
4798
4799 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
4800
4801 (define_split
4802   [(set (match_operand:GPR 0 "register_operand")
4803         (any_shift:GPR (match_operand:GPR 1 "register_operand")
4804                        (match_operand:GPR 2 "const_int_operand")))]
4805   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4806    && GET_CODE (operands[2]) == CONST_INT
4807    && INTVAL (operands[2]) > 8
4808    && INTVAL (operands[2]) <= 16"
4809   [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
4810    (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
4811   { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
4812
4813 ;; If we load a byte on the mips16 as a bitfield, the resulting
4814 ;; sequence of instructions is too complicated for combine, because it
4815 ;; involves four instructions: a load, a shift, a constant load into a
4816 ;; register, and an and (the key problem here is that the mips16 does
4817 ;; not have and immediate).  We recognize a shift of a load in order
4818 ;; to make it simple enough for combine to understand.
4819 ;;
4820 ;; The length here is the worst case: the length of the split version
4821 ;; will be more accurate.
4822 (define_insn_and_split ""
4823   [(set (match_operand:SI 0 "register_operand" "=d")
4824         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
4825                      (match_operand:SI 2 "immediate_operand" "I")))]
4826   "TARGET_MIPS16"
4827   "#"
4828   ""
4829   [(set (match_dup 0) (match_dup 1))
4830    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
4831   ""
4832   [(set_attr "type"     "load")
4833    (set_attr "mode"     "SI")
4834    (set_attr "length"   "16")])
4835
4836 (define_insn "rotr<mode>3"
4837   [(set (match_operand:GPR 0 "register_operand" "=d")
4838         (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
4839                       (match_operand:SI 2 "arith_operand" "dI")))]
4840   "ISA_HAS_ROR"
4841 {
4842   if (GET_CODE (operands[2]) == CONST_INT)
4843     gcc_assert (INTVAL (operands[2]) >= 0
4844                 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
4845
4846   return "<d>ror\t%0,%1,%2";
4847 }
4848   [(set_attr "type" "shift")
4849    (set_attr "mode" "<MODE>")])
4850 \f
4851 ;;
4852 ;;  ....................
4853 ;;
4854 ;;      COMPARISONS
4855 ;;
4856 ;;  ....................
4857
4858 ;; Flow here is rather complex:
4859 ;;
4860 ;;  1)  The cmp{si,di,sf,df} routine is called.  It deposits the arguments
4861 ;;      into cmp_operands[] but generates no RTL.
4862 ;;
4863 ;;  2)  The appropriate branch define_expand is called, which then
4864 ;;      creates the appropriate RTL for the comparison and branch.
4865 ;;      Different CC modes are used, based on what type of branch is
4866 ;;      done, so that we can constrain things appropriately.  There
4867 ;;      are assumptions in the rest of GCC that break if we fold the
4868 ;;      operands into the branches for integer operations, and use cc0
4869 ;;      for floating point, so we use the fp status register instead.
4870 ;;      If needed, an appropriate temporary is created to hold the
4871 ;;      of the integer compare.
4872
4873 (define_expand "cmp<mode>"
4874   [(set (cc0)
4875         (compare:CC (match_operand:GPR 0 "register_operand")
4876                     (match_operand:GPR 1 "nonmemory_operand")))]
4877   ""
4878 {
4879   cmp_operands[0] = operands[0];
4880   cmp_operands[1] = operands[1];
4881   DONE;
4882 })
4883
4884 (define_expand "cmp<mode>"
4885   [(set (cc0)
4886         (compare:CC (match_operand:SCALARF 0 "register_operand")
4887                     (match_operand:SCALARF 1 "register_operand")))]
4888   ""
4889 {
4890   cmp_operands[0] = operands[0];
4891   cmp_operands[1] = operands[1];
4892   DONE;
4893 })
4894 \f
4895 ;;
4896 ;;  ....................
4897 ;;
4898 ;;      CONDITIONAL BRANCHES
4899 ;;
4900 ;;  ....................
4901
4902 ;; Conditional branches on floating-point equality tests.
4903
4904 (define_insn "*branch_fp"
4905   [(set (pc)
4906         (if_then_else
4907          (match_operator 0 "equality_operator"
4908                          [(match_operand:CC 2 "register_operand" "z")
4909                           (const_int 0)])
4910          (label_ref (match_operand 1 "" ""))
4911          (pc)))]
4912   "TARGET_HARD_FLOAT"
4913 {
4914   return mips_output_conditional_branch (insn, operands,
4915                                          MIPS_BRANCH ("b%F0", "%Z2%1"),
4916                                          MIPS_BRANCH ("b%W0", "%Z2%1"));
4917 }
4918   [(set_attr "type" "branch")
4919    (set_attr "mode" "none")])
4920
4921 (define_insn "*branch_fp_inverted"
4922   [(set (pc)
4923         (if_then_else
4924          (match_operator 0 "equality_operator"
4925                          [(match_operand:CC 2 "register_operand" "z")
4926                           (const_int 0)])
4927          (pc)
4928          (label_ref (match_operand 1 "" ""))))]
4929   "TARGET_HARD_FLOAT"
4930 {
4931   return mips_output_conditional_branch (insn, operands,
4932                                          MIPS_BRANCH ("b%W0", "%Z2%1"),
4933                                          MIPS_BRANCH ("b%F0", "%Z2%1"));
4934 }
4935   [(set_attr "type" "branch")
4936    (set_attr "mode" "none")])
4937
4938 ;; Conditional branches on ordered comparisons with zero.
4939
4940 (define_insn "*branch_order<mode>"
4941   [(set (pc)
4942         (if_then_else
4943          (match_operator 0 "order_operator"
4944                          [(match_operand:GPR 2 "register_operand" "d")
4945                           (const_int 0)])
4946          (label_ref (match_operand 1 "" ""))
4947          (pc)))]
4948   "!TARGET_MIPS16"
4949   { return mips_output_order_conditional_branch (insn, operands, false); }
4950   [(set_attr "type" "branch")
4951    (set_attr "mode" "none")])
4952
4953 (define_insn "*branch_order<mode>_inverted"
4954   [(set (pc)
4955         (if_then_else
4956          (match_operator 0 "order_operator"
4957                          [(match_operand:GPR 2 "register_operand" "d")
4958                           (const_int 0)])
4959          (pc)
4960          (label_ref (match_operand 1 "" ""))))]
4961   "!TARGET_MIPS16"
4962   { return mips_output_order_conditional_branch (insn, operands, true); }
4963   [(set_attr "type" "branch")
4964    (set_attr "mode" "none")])
4965
4966 ;; Conditional branch on equality comparison.
4967
4968 (define_insn "*branch_equality<mode>"
4969   [(set (pc)
4970         (if_then_else
4971          (match_operator 0 "equality_operator"
4972                          [(match_operand:GPR 2 "register_operand" "d")
4973                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
4974          (label_ref (match_operand 1 "" ""))
4975          (pc)))]
4976   "!TARGET_MIPS16"
4977 {
4978   return mips_output_conditional_branch (insn, operands,
4979                                          MIPS_BRANCH ("b%C0", "%2,%z3,%1"),
4980                                          MIPS_BRANCH ("b%N0", "%2,%z3,%1"));
4981 }
4982   [(set_attr "type" "branch")
4983    (set_attr "mode" "none")])
4984
4985 (define_insn "*branch_equality<mode>_inverted"
4986   [(set (pc)
4987         (if_then_else
4988          (match_operator 0 "equality_operator"
4989                          [(match_operand:GPR 2 "register_operand" "d")
4990                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
4991          (pc)
4992          (label_ref (match_operand 1 "" ""))))]
4993   "!TARGET_MIPS16"
4994 {
4995   return mips_output_conditional_branch (insn, operands,
4996                                          MIPS_BRANCH ("b%N0", "%2,%z3,%1"),
4997                                          MIPS_BRANCH ("b%C0", "%2,%z3,%1"));
4998 }
4999   [(set_attr "type" "branch")
5000    (set_attr "mode" "none")])
5001
5002 ;; MIPS16 branches
5003
5004 (define_insn "*branch_equality<mode>_mips16"
5005   [(set (pc)
5006         (if_then_else
5007          (match_operator 0 "equality_operator"
5008                          [(match_operand:GPR 1 "register_operand" "d,t")
5009                           (const_int 0)])
5010          (match_operand 2 "pc_or_label_operand" "")
5011          (match_operand 3 "pc_or_label_operand" "")))]
5012   "TARGET_MIPS16"
5013 {
5014   if (operands[2] != pc_rtx)
5015     {
5016       if (which_alternative == 0)
5017         return "b%C0z\t%1,%2";
5018       else
5019         return "bt%C0z\t%2";
5020     }
5021   else
5022     {
5023       if (which_alternative == 0)
5024         return "b%N0z\t%1,%3";
5025       else
5026         return "bt%N0z\t%3";
5027     }
5028 }
5029   [(set_attr "type" "branch")
5030    (set_attr "mode" "none")
5031    (set_attr "length" "8")])
5032
5033 (define_expand "b<code>"
5034   [(set (pc)
5035         (if_then_else (any_cond:CC (cc0)
5036                                    (const_int 0))
5037                       (label_ref (match_operand 0 ""))
5038                       (pc)))]
5039   ""
5040 {
5041   mips_expand_conditional_branch (operands, <CODE>);
5042   DONE;
5043 })
5044
5045 ;; Used to implement built-in functions.
5046 (define_expand "condjump"
5047   [(set (pc)
5048         (if_then_else (match_operand 0)
5049                       (label_ref (match_operand 1))
5050                       (pc)))])
5051 \f
5052 ;;
5053 ;;  ....................
5054 ;;
5055 ;;      SETTING A REGISTER FROM A COMPARISON
5056 ;;
5057 ;;  ....................
5058
5059 (define_expand "seq"
5060   [(set (match_operand:SI 0 "register_operand")
5061         (eq:SI (match_dup 1)
5062                (match_dup 2)))]
5063   ""
5064   { if (mips_expand_scc (EQ, operands[0])) DONE; else FAIL; })
5065
5066 (define_insn "*seq_<mode>"
5067   [(set (match_operand:GPR 0 "register_operand" "=d")
5068         (eq:GPR (match_operand:GPR 1 "register_operand" "d")
5069                 (const_int 0)))]
5070   "!TARGET_MIPS16"
5071   "sltu\t%0,%1,1"
5072   [(set_attr "type" "slt")
5073    (set_attr "mode" "<MODE>")])
5074
5075 (define_insn "*seq_<mode>_mips16"
5076   [(set (match_operand:GPR 0 "register_operand" "=t")
5077         (eq:GPR (match_operand:GPR 1 "register_operand" "d")
5078                 (const_int 0)))]
5079   "TARGET_MIPS16"
5080   "sltu\t%1,1"
5081   [(set_attr "type" "slt")
5082    (set_attr "mode" "<MODE>")])
5083
5084 ;; "sne" uses sltu instructions in which the first operand is $0.
5085 ;; This isn't possible in mips16 code.
5086
5087 (define_expand "sne"
5088   [(set (match_operand:SI 0 "register_operand")
5089         (ne:SI (match_dup 1)
5090                (match_dup 2)))]
5091   "!TARGET_MIPS16"
5092   { if (mips_expand_scc (NE, operands[0])) DONE; else FAIL; })
5093
5094 (define_insn "*sne_<mode>"
5095   [(set (match_operand:GPR 0 "register_operand" "=d")
5096         (ne:GPR (match_operand:GPR 1 "register_operand" "d")
5097                 (const_int 0)))]
5098   "!TARGET_MIPS16"
5099   "sltu\t%0,%.,%1"
5100   [(set_attr "type" "slt")
5101    (set_attr "mode" "<MODE>")])
5102
5103 (define_expand "sgt"
5104   [(set (match_operand:SI 0 "register_operand")
5105         (gt:SI (match_dup 1)
5106                (match_dup 2)))]
5107   ""
5108   { if (mips_expand_scc (GT, operands[0])) DONE; else FAIL; })
5109
5110 (define_insn "*sgt_<mode>"
5111   [(set (match_operand:GPR 0 "register_operand" "=d")
5112         (gt:GPR (match_operand:GPR 1 "register_operand" "d")
5113                 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5114   "!TARGET_MIPS16"
5115   "slt\t%0,%z2,%1"
5116   [(set_attr "type" "slt")
5117    (set_attr "mode" "<MODE>")])
5118
5119 (define_insn "*sgt_<mode>_mips16"
5120   [(set (match_operand:GPR 0 "register_operand" "=t")
5121         (gt:GPR (match_operand:GPR 1 "register_operand" "d")
5122                 (match_operand:GPR 2 "register_operand" "d")))]
5123   "TARGET_MIPS16"
5124   "slt\t%2,%1"
5125   [(set_attr "type" "slt")
5126    (set_attr "mode" "<MODE>")])
5127
5128 (define_expand "sge"
5129   [(set (match_operand:SI 0 "register_operand")
5130         (ge:SI (match_dup 1)
5131                (match_dup 2)))]
5132   ""
5133   { if (mips_expand_scc (GE, operands[0])) DONE; else FAIL; })
5134
5135 (define_insn "*sge_<mode>"
5136   [(set (match_operand:GPR 0 "register_operand" "=d")
5137         (ge:GPR (match_operand:GPR 1 "register_operand" "d")
5138                 (const_int 1)))]
5139   "!TARGET_MIPS16"
5140   "slt\t%0,%.,%1"
5141   [(set_attr "type" "slt")
5142    (set_attr "mode" "<MODE>")])
5143
5144 (define_expand "slt"
5145   [(set (match_operand:SI 0 "register_operand")
5146         (lt:SI (match_dup 1)
5147                (match_dup 2)))]
5148   ""
5149   { if (mips_expand_scc (LT, operands[0])) DONE; else FAIL; })
5150
5151 (define_insn "*slt_<mode>"
5152   [(set (match_operand:GPR 0 "register_operand" "=d")
5153         (lt:GPR (match_operand:GPR 1 "register_operand" "d")
5154                 (match_operand:GPR 2 "arith_operand" "dI")))]
5155   "!TARGET_MIPS16"
5156   "slt\t%0,%1,%2"
5157   [(set_attr "type" "slt")
5158    (set_attr "mode" "<MODE>")])
5159
5160 (define_insn "*slt_<mode>_mips16"
5161   [(set (match_operand:GPR 0 "register_operand" "=t,t")
5162         (lt:GPR (match_operand:GPR 1 "register_operand" "d,d")
5163                 (match_operand:GPR 2 "arith_operand" "d,I")))]
5164   "TARGET_MIPS16"
5165   "slt\t%1,%2"
5166   [(set_attr "type" "slt")
5167    (set_attr "mode" "<MODE>")
5168    (set_attr_alternative "length"
5169                 [(const_int 4)
5170                  (if_then_else (match_operand 2 "m16_uimm8_1")
5171                                (const_int 4)
5172                                (const_int 8))])])
5173
5174 (define_expand "sle"
5175   [(set (match_operand:SI 0 "register_operand")
5176         (le:SI (match_dup 1)
5177                (match_dup 2)))]
5178   ""
5179   { if (mips_expand_scc (LE, operands[0])) DONE; else FAIL; })
5180
5181 (define_insn "*sle_<mode>"
5182   [(set (match_operand:GPR 0 "register_operand" "=d")
5183         (le:GPR (match_operand:GPR 1 "register_operand" "d")
5184                 (match_operand:GPR 2 "sle_operand" "")))]
5185   "!TARGET_MIPS16"
5186 {
5187   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5188   return "slt\t%0,%1,%2";
5189 }
5190   [(set_attr "type" "slt")
5191    (set_attr "mode" "<MODE>")])
5192
5193 (define_insn "*sle_<mode>_mips16"
5194   [(set (match_operand:GPR 0 "register_operand" "=t")
5195         (le:GPR (match_operand:GPR 1 "register_operand" "d")
5196                 (match_operand:GPR 2 "sle_operand" "")))]
5197   "TARGET_MIPS16"
5198 {
5199   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5200   return "slt\t%1,%2";
5201 }
5202   [(set_attr "type" "slt")
5203    (set_attr "mode" "<MODE>")
5204    (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
5205                                       (const_int 4)
5206                                       (const_int 8)))])
5207
5208 (define_expand "sgtu"
5209   [(set (match_operand:SI 0 "register_operand")
5210         (gtu:SI (match_dup 1)
5211                 (match_dup 2)))]
5212   ""
5213   { if (mips_expand_scc (GTU, operands[0])) DONE; else FAIL; })
5214
5215 (define_insn "*sgtu_<mode>"
5216   [(set (match_operand:GPR 0 "register_operand" "=d")
5217         (gtu:GPR (match_operand:GPR 1 "register_operand" "d")
5218                  (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5219   "!TARGET_MIPS16"
5220   "sltu\t%0,%z2,%1"
5221   [(set_attr "type" "slt")
5222    (set_attr "mode" "<MODE>")])
5223
5224 (define_insn "*sgtu_<mode>_mips16"
5225   [(set (match_operand:GPR 0 "register_operand" "=t")
5226         (gtu:GPR (match_operand:GPR 1 "register_operand" "d")
5227                  (match_operand:GPR 2 "register_operand" "d")))]
5228   "TARGET_MIPS16"
5229   "sltu\t%2,%1"
5230   [(set_attr "type" "slt")
5231    (set_attr "mode" "<MODE>")])
5232
5233 (define_expand "sgeu"
5234   [(set (match_operand:SI 0 "register_operand")
5235         (geu:SI (match_dup 1)
5236                 (match_dup 2)))]
5237   ""
5238   { if (mips_expand_scc (GEU, operands[0])) DONE; else FAIL; })
5239
5240 (define_insn "*sge_<mode>"
5241   [(set (match_operand:GPR 0 "register_operand" "=d")
5242         (geu:GPR (match_operand:GPR 1 "register_operand" "d")
5243                  (const_int 1)))]
5244   "!TARGET_MIPS16"
5245   "sltu\t%0,%.,%1"
5246   [(set_attr "type" "slt")
5247    (set_attr "mode" "<MODE>")])
5248
5249 (define_expand "sltu"
5250   [(set (match_operand:SI 0 "register_operand")
5251         (ltu:SI (match_dup 1)
5252                 (match_dup 2)))]
5253   ""
5254   { if (mips_expand_scc (LTU, operands[0])) DONE; else FAIL; })
5255
5256 (define_insn "*sltu_<mode>"
5257   [(set (match_operand:GPR 0 "register_operand" "=d")
5258         (ltu:GPR (match_operand:GPR 1 "register_operand" "d")
5259                  (match_operand:GPR 2 "arith_operand" "dI")))]
5260   "!TARGET_MIPS16"
5261   "sltu\t%0,%1,%2"
5262   [(set_attr "type" "slt")
5263    (set_attr "mode" "<MODE>")])
5264
5265 (define_insn "*sltu_<mode>_mips16"
5266   [(set (match_operand:GPR 0 "register_operand" "=t,t")
5267         (ltu:GPR (match_operand:GPR 1 "register_operand" "d,d")
5268                  (match_operand:GPR 2 "arith_operand" "d,I")))]
5269   "TARGET_MIPS16"
5270   "sltu\t%1,%2"
5271   [(set_attr "type" "slt")
5272    (set_attr "mode" "<MODE>")
5273    (set_attr_alternative "length"
5274                 [(const_int 4)
5275                  (if_then_else (match_operand 2 "m16_uimm8_1")
5276                                (const_int 4)
5277                                (const_int 8))])])
5278
5279 (define_expand "sleu"
5280   [(set (match_operand:SI 0 "register_operand")
5281         (leu:SI (match_dup 1)
5282                 (match_dup 2)))]
5283   ""
5284   { if (mips_expand_scc (LEU, operands[0])) DONE; else FAIL; })
5285
5286 (define_insn "*sleu_<mode>"
5287   [(set (match_operand:GPR 0 "register_operand" "=d")
5288         (leu:GPR (match_operand:GPR 1 "register_operand" "d")
5289                  (match_operand:GPR 2 "sleu_operand" "")))]
5290   "!TARGET_MIPS16"
5291 {
5292   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5293   return "sltu\t%0,%1,%2";
5294 }
5295   [(set_attr "type" "slt")
5296    (set_attr "mode" "<MODE>")])
5297
5298 (define_insn "*sleu_<mode>_mips16"
5299   [(set (match_operand:GPR 0 "register_operand" "=t")
5300         (leu:GPR (match_operand:GPR 1 "register_operand" "d")
5301                  (match_operand:GPR 2 "sleu_operand" "")))]
5302   "TARGET_MIPS16"
5303 {
5304   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5305   return "sltu\t%1,%2";
5306 }
5307   [(set_attr "type" "slt")
5308    (set_attr "mode" "<MODE>")
5309    (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
5310                                       (const_int 4)
5311                                       (const_int 8)))])
5312 \f
5313 ;;
5314 ;;  ....................
5315 ;;
5316 ;;      FLOATING POINT COMPARISONS
5317 ;;
5318 ;;  ....................
5319
5320 (define_insn "s<code>_<mode>"
5321   [(set (match_operand:CC 0 "register_operand" "=z")
5322         (fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5323                   (match_operand:SCALARF 2 "register_operand" "f")))]
5324   ""
5325   "c.<fcond>.<fmt>\t%Z0%1,%2"
5326   [(set_attr "type" "fcmp")
5327    (set_attr "mode" "FPSW")])
5328
5329 (define_insn "s<code>_<mode>"
5330   [(set (match_operand:CC 0 "register_operand" "=z")
5331         (swapped_fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5332                           (match_operand:SCALARF 2 "register_operand" "f")))]
5333   ""
5334   "c.<swapped_fcond>.<fmt>\t%Z0%2,%1"
5335   [(set_attr "type" "fcmp")
5336    (set_attr "mode" "FPSW")])
5337 \f
5338 ;;
5339 ;;  ....................
5340 ;;
5341 ;;      UNCONDITIONAL BRANCHES
5342 ;;
5343 ;;  ....................
5344
5345 ;; Unconditional branches.
5346
5347 (define_insn "jump"
5348   [(set (pc)
5349         (label_ref (match_operand 0 "" "")))]
5350   "!TARGET_MIPS16"
5351 {
5352   if (flag_pic)
5353     {
5354       if (get_attr_length (insn) <= 8)
5355         return "%*b\t%l0%/";
5356       else
5357         {
5358           output_asm_insn (mips_output_load_label (), operands);
5359           return "%*jr\t%@%/%]";
5360         }
5361     }
5362   else
5363     return "%*j\t%l0%/";
5364 }
5365   [(set_attr "type"     "jump")
5366    (set_attr "mode"     "none")
5367    (set (attr "length")
5368         ;; We can't use `j' when emitting PIC.  Emit a branch if it's
5369         ;; in range, otherwise load the address of the branch target into
5370         ;; $at and then jump to it.
5371         (if_then_else
5372          (ior (eq (symbol_ref "flag_pic") (const_int 0))
5373               (lt (abs (minus (match_dup 0)
5374                               (plus (pc) (const_int 4))))
5375                   (const_int 131072)))
5376          (const_int 4) (const_int 16)))])
5377
5378 ;; We need a different insn for the mips16, because a mips16 branch
5379 ;; does not have a delay slot.
5380
5381 (define_insn ""
5382   [(set (pc)
5383         (label_ref (match_operand 0 "" "")))]
5384   "TARGET_MIPS16"
5385   "b\t%l0"
5386   [(set_attr "type"     "branch")
5387    (set_attr "mode"     "none")
5388    (set_attr "length"   "8")])
5389
5390 (define_expand "indirect_jump"
5391   [(set (pc) (match_operand 0 "register_operand"))]
5392   ""
5393 {
5394   operands[0] = force_reg (Pmode, operands[0]);
5395   if (Pmode == SImode)
5396     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
5397   else
5398     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
5399   DONE;
5400 })
5401
5402 (define_insn "indirect_jump<mode>"
5403   [(set (pc) (match_operand:P 0 "register_operand" "d"))]
5404   ""
5405   "%*j\t%0%/"
5406   [(set_attr "type" "jump")
5407    (set_attr "mode" "none")])
5408
5409 (define_expand "tablejump"
5410   [(set (pc)
5411         (match_operand 0 "register_operand"))
5412    (use (label_ref (match_operand 1 "")))]
5413   ""
5414 {
5415   if (TARGET_MIPS16_SHORT_JUMP_TABLES)
5416     operands[0] = expand_binop (Pmode, add_optab,
5417                                 convert_to_mode (Pmode, operands[0], false),
5418                                 gen_rtx_LABEL_REF (Pmode, operands[1]),
5419                                 0, 0, OPTAB_WIDEN);
5420   else if (TARGET_GPWORD)
5421     operands[0] = expand_binop (Pmode, add_optab, operands[0],
5422                                 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
5423   else if (TARGET_RTP_PIC)
5424     {
5425       /* When generating RTP PIC, we use case table entries that are relative
5426          to the start of the function.  Add the function's address to the
5427          value we loaded.  */
5428       rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5429       operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
5430                                   start, 0, 0, OPTAB_WIDEN);
5431     }
5432
5433   if (Pmode == SImode)
5434     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
5435   else
5436     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
5437   DONE;
5438 })
5439
5440 (define_insn "tablejump<mode>"
5441   [(set (pc)
5442         (match_operand:P 0 "register_operand" "d"))
5443    (use (label_ref (match_operand 1 "" "")))]
5444   ""
5445   "%*j\t%0%/"
5446   [(set_attr "type" "jump")
5447    (set_attr "mode" "none")])
5448
5449 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
5450 ;; While it is possible to either pull it off the stack (in the
5451 ;; o32 case) or recalculate it given t9 and our target label,
5452 ;; it takes 3 or 4 insns to do so.
5453
5454 (define_expand "builtin_setjmp_setup"
5455   [(use (match_operand 0 "register_operand"))]
5456   "TARGET_USE_GOT"
5457 {
5458   rtx addr;
5459
5460   addr = plus_constant (operands[0], GET_MODE_SIZE (Pmode) * 3);
5461   mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
5462   DONE;
5463 })
5464
5465 ;; Restore the gp that we saved above.  Despite the earlier comment, it seems
5466 ;; that older code did recalculate the gp from $25.  Continue to jump through
5467 ;; $25 for compatibility (we lose nothing by doing so).
5468
5469 (define_expand "builtin_longjmp"
5470   [(use (match_operand 0 "register_operand"))]
5471   "TARGET_USE_GOT"
5472 {
5473   /* The elements of the buffer are, in order:  */
5474   int W = GET_MODE_SIZE (Pmode);
5475   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
5476   rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 1*W));
5477   rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 2*W));
5478   rtx gpv = gen_rtx_MEM (Pmode, plus_constant (operands[0], 3*W));
5479   rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5480   /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
5481      The target is bound to be using $28 as the global pointer
5482      but the current function might not be.  */
5483   rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
5484
5485   /* This bit is similar to expand_builtin_longjmp except that it
5486      restores $gp as well.  */
5487   mips_emit_move (hard_frame_pointer_rtx, fp);
5488   mips_emit_move (pv, lab);
5489   emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
5490   mips_emit_move (gp, gpv);
5491   emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
5492   emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
5493   emit_insn (gen_rtx_USE (VOIDmode, gp));
5494   emit_indirect_jump (pv);
5495   DONE;
5496 })
5497 \f
5498 ;;
5499 ;;  ....................
5500 ;;
5501 ;;      Function prologue/epilogue
5502 ;;
5503 ;;  ....................
5504 ;;
5505
5506 (define_expand "prologue"
5507   [(const_int 1)]
5508   ""
5509 {
5510   mips_expand_prologue ();
5511   DONE;
5512 })
5513
5514 ;; Block any insns from being moved before this point, since the
5515 ;; profiling call to mcount can use various registers that aren't
5516 ;; saved or used to pass arguments.
5517
5518 (define_insn "blockage"
5519   [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
5520   ""
5521   ""
5522   [(set_attr "type"     "unknown")
5523    (set_attr "mode"     "none")
5524    (set_attr "length"   "0")])
5525
5526 (define_expand "epilogue"
5527   [(const_int 2)]
5528   ""
5529 {
5530   mips_expand_epilogue (false);
5531   DONE;
5532 })
5533
5534 (define_expand "sibcall_epilogue"
5535   [(const_int 2)]
5536   ""
5537 {
5538   mips_expand_epilogue (true);
5539   DONE;
5540 })
5541
5542 ;; Trivial return.  Make it look like a normal return insn as that
5543 ;; allows jump optimizations to work better.
5544
5545 (define_insn "return"
5546   [(return)]
5547   "mips_can_use_return_insn ()"
5548   "%*j\t$31%/"
5549   [(set_attr "type"     "jump")
5550    (set_attr "mode"     "none")])
5551
5552 ;; Normal return.
5553
5554 (define_insn "return_internal"
5555   [(return)
5556    (use (match_operand 0 "pmode_register_operand" ""))]
5557   ""
5558   "%*j\t%0%/"
5559   [(set_attr "type"     "jump")
5560    (set_attr "mode"     "none")])
5561
5562 ;; This is used in compiling the unwind routines.
5563 (define_expand "eh_return"
5564   [(use (match_operand 0 "general_operand"))]
5565   ""
5566 {
5567   if (GET_MODE (operands[0]) != word_mode)
5568     operands[0] = convert_to_mode (word_mode, operands[0], 0);
5569   if (TARGET_64BIT)
5570     emit_insn (gen_eh_set_lr_di (operands[0]));
5571   else
5572     emit_insn (gen_eh_set_lr_si (operands[0]));
5573   DONE;
5574 })
5575
5576 ;; Clobber the return address on the stack.  We can't expand this
5577 ;; until we know where it will be put in the stack frame.
5578
5579 (define_insn "eh_set_lr_si"
5580   [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
5581    (clobber (match_scratch:SI 1 "=&d"))]
5582   "! TARGET_64BIT"
5583   "#")
5584
5585 (define_insn "eh_set_lr_di"
5586   [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
5587    (clobber (match_scratch:DI 1 "=&d"))]
5588   "TARGET_64BIT"
5589   "#")
5590
5591 (define_split
5592   [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
5593    (clobber (match_scratch 1))]
5594   "reload_completed && !TARGET_DEBUG_D_MODE"
5595   [(const_int 0)]
5596 {
5597   mips_set_return_address (operands[0], operands[1]);
5598   DONE;
5599 })
5600
5601 (define_insn_and_split "exception_receiver"
5602   [(set (reg:SI 28)
5603         (unspec_volatile:SI [(const_int 0)] UNSPEC_EH_RECEIVER))]
5604   "TARGET_CALL_CLOBBERED_GP"
5605   "#"
5606   "&& reload_completed"
5607   [(const_int 0)]
5608 {
5609   mips_restore_gp ();
5610   DONE;
5611 }
5612   [(set_attr "type"   "load")
5613    (set_attr "length" "12")])
5614 \f
5615 ;;
5616 ;;  ....................
5617 ;;
5618 ;;      FUNCTION CALLS
5619 ;;
5620 ;;  ....................
5621
5622 ;; Instructions to load a call address from the GOT.  The address might
5623 ;; point to a function or to a lazy binding stub.  In the latter case,
5624 ;; the stub will use the dynamic linker to resolve the function, which
5625 ;; in turn will change the GOT entry to point to the function's real
5626 ;; address.
5627 ;;
5628 ;; This means that every call, even pure and constant ones, can
5629 ;; potentially modify the GOT entry.  And once a stub has been called,
5630 ;; we must not call it again.
5631 ;;
5632 ;; We represent this restriction using an imaginary fixed register that
5633 ;; is set by the GOT load and used by the call.  By making this register
5634 ;; call-clobbered, and by making the GOT load the only way of setting
5635 ;; the register, we ensure that the load cannot be moved past a call.
5636 (define_insn "load_call<mode>"
5637   [(set (match_operand:P 0 "register_operand" "=d")
5638         (unspec:P [(match_operand:P 1 "register_operand" "r")
5639                    (match_operand:P 2 "immediate_operand" "")]
5640                   UNSPEC_LOAD_CALL))
5641    (set (reg:P FAKE_CALL_REGNO)
5642         (unspec:P [(match_dup 2)] UNSPEC_LOAD_CALL))]
5643   "TARGET_USE_GOT"
5644   "<load>\t%0,%R2(%1)"
5645   [(set_attr "type" "load")
5646    (set_attr "mode" "<MODE>")
5647    (set_attr "hazard_set" "0")
5648    (set_attr "length" "4")])
5649
5650 ;; Sibling calls.  All these patterns use jump instructions.
5651
5652 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
5653 ;; addresses if a direct jump is acceptable.  Since the 'S' constraint
5654 ;; is defined in terms of call_insn_operand, the same is true of the
5655 ;; constraints.
5656
5657 ;; When we use an indirect jump, we need a register that will be
5658 ;; preserved by the epilogue.  Since TARGET_USE_PIC_FN_ADDR_REG forces
5659 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
5660 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
5661 ;; as well.
5662
5663 (define_expand "sibcall"
5664   [(parallel [(call (match_operand 0 "")
5665                     (match_operand 1 ""))
5666               (use (match_operand 2 ""))        ;; next_arg_reg
5667               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
5668   "TARGET_SIBCALLS"
5669 {
5670   mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], true);
5671   DONE;
5672 })
5673
5674 (define_insn "sibcall_internal"
5675   [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
5676          (match_operand 1 "" ""))]
5677   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
5678   { return MIPS_CALL ("j", operands, 0); }
5679   [(set_attr "type" "call")])
5680
5681 (define_expand "sibcall_value"
5682   [(parallel [(set (match_operand 0 "")
5683                    (call (match_operand 1 "")
5684                          (match_operand 2 "")))
5685               (use (match_operand 3 ""))])]             ;; next_arg_reg
5686   "TARGET_SIBCALLS"
5687 {
5688   mips_expand_call (operands[0], XEXP (operands[1], 0),
5689                     operands[2], operands[3], true);
5690   DONE;
5691 })
5692
5693 (define_insn "sibcall_value_internal"
5694   [(set (match_operand 0 "register_operand" "")
5695         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
5696               (match_operand 2 "" "")))]
5697   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
5698   { return MIPS_CALL ("j", operands, 1); }
5699   [(set_attr "type" "call")])
5700
5701 (define_insn "sibcall_value_multiple_internal"
5702   [(set (match_operand 0 "register_operand" "")
5703         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
5704               (match_operand 2 "" "")))
5705    (set (match_operand 3 "register_operand" "")
5706         (call (mem:SI (match_dup 1))
5707               (match_dup 2)))]
5708   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
5709   { return MIPS_CALL ("j", operands, 1); }
5710   [(set_attr "type" "call")])
5711
5712 (define_expand "call"
5713   [(parallel [(call (match_operand 0 "")
5714                     (match_operand 1 ""))
5715               (use (match_operand 2 ""))        ;; next_arg_reg
5716               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
5717   ""
5718 {
5719   mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], false);
5720   DONE;
5721 })
5722
5723 ;; This instruction directly corresponds to an assembly-language "jal".
5724 ;; There are four cases:
5725 ;;
5726 ;;    - -mno-abicalls:
5727 ;;        Both symbolic and register destinations are OK.  The pattern
5728 ;;        always expands to a single mips instruction.
5729 ;;
5730 ;;    - -mabicalls/-mno-explicit-relocs:
5731 ;;        Again, both symbolic and register destinations are OK.
5732 ;;        The call is treated as a multi-instruction black box.
5733 ;;
5734 ;;    - -mabicalls/-mexplicit-relocs with n32 or n64:
5735 ;;        Only "jal $25" is allowed.  This expands to a single "jalr $25"
5736 ;;        instruction.
5737 ;;
5738 ;;    - -mabicalls/-mexplicit-relocs with o32 or o64:
5739 ;;        Only "jal $25" is allowed.  The call is actually two instructions:
5740 ;;        "jalr $25" followed by an insn to reload $gp.
5741 ;;
5742 ;; In the last case, we can generate the individual instructions with
5743 ;; a define_split.  There are several things to be wary of:
5744 ;;
5745 ;;   - We can't expose the load of $gp before reload.  If we did,
5746 ;;     it might get removed as dead, but reload can introduce new
5747 ;;     uses of $gp by rematerializing constants.
5748 ;;
5749 ;;   - We shouldn't restore $gp after calls that never return.
5750 ;;     It isn't valid to insert instructions between a noreturn
5751 ;;     call and the following barrier.
5752 ;;
5753 ;;   - The splitter deliberately changes the liveness of $gp.  The unsplit
5754 ;;     instruction preserves $gp and so have no effect on its liveness.
5755 ;;     But once we generate the separate insns, it becomes obvious that
5756 ;;     $gp is not live on entry to the call.
5757 ;;
5758 ;; ??? The operands[2] = insn check is a hack to make the original insn
5759 ;; available to the splitter.
5760 (define_insn_and_split "call_internal"
5761   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
5762          (match_operand 1 "" ""))
5763    (clobber (reg:SI 31))]
5764   ""
5765   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0); }
5766   "reload_completed && TARGET_SPLIT_CALLS && (operands[2] = insn)"
5767   [(const_int 0)]
5768 {
5769   emit_call_insn (gen_call_split (operands[0], operands[1]));
5770   if (!find_reg_note (operands[2], REG_NORETURN, 0))
5771     mips_restore_gp ();
5772   DONE;
5773 }
5774   [(set_attr "jal" "indirect,direct")
5775    (set_attr "extended_mips16" "no,yes")])
5776
5777 ;; A pattern for calls that must be made directly.  It is used for
5778 ;; MIPS16 calls that the linker may need to redirect to a hard-float
5779 ;; stub; the linker relies on the call relocation type to detect when
5780 ;; such redirection is needed.
5781 (define_insn "call_internal_direct"
5782   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
5783          (match_operand 1))
5784    (const_int 1)
5785    (clobber (reg:SI 31))]
5786   ""
5787   { return MIPS_CALL ("jal", operands, 0); })
5788
5789 (define_insn "call_split"
5790   [(call (mem:SI (match_operand 0 "call_insn_operand" "cS"))
5791          (match_operand 1 "" ""))
5792    (clobber (reg:SI 31))
5793    (clobber (reg:SI 28))]
5794   "TARGET_SPLIT_CALLS"
5795   { return MIPS_CALL ("jal", operands, 0); }
5796   [(set_attr "type" "call")])
5797
5798 (define_expand "call_value"
5799   [(parallel [(set (match_operand 0 "")
5800                    (call (match_operand 1 "")
5801                          (match_operand 2 "")))
5802               (use (match_operand 3 ""))])]             ;; next_arg_reg
5803   ""
5804 {
5805   mips_expand_call (operands[0], XEXP (operands[1], 0),
5806                     operands[2], operands[3], false);
5807   DONE;
5808 })
5809
5810 ;; See comment for call_internal.
5811 (define_insn_and_split "call_value_internal"
5812   [(set (match_operand 0 "register_operand" "")
5813         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
5814               (match_operand 2 "" "")))
5815    (clobber (reg:SI 31))]
5816   ""
5817   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1); }
5818   "reload_completed && TARGET_SPLIT_CALLS && (operands[3] = insn)"
5819   [(const_int 0)]
5820 {
5821   emit_call_insn (gen_call_value_split (operands[0], operands[1],
5822                                         operands[2]));
5823   if (!find_reg_note (operands[3], REG_NORETURN, 0))
5824     mips_restore_gp ();
5825   DONE;
5826 }
5827   [(set_attr "jal" "indirect,direct")
5828    (set_attr "extended_mips16" "no,yes")])
5829
5830 (define_insn "call_value_split"
5831   [(set (match_operand 0 "register_operand" "")
5832         (call (mem:SI (match_operand 1 "call_insn_operand" "cS"))
5833               (match_operand 2 "" "")))
5834    (clobber (reg:SI 31))
5835    (clobber (reg:SI 28))]
5836   "TARGET_SPLIT_CALLS"
5837   { return MIPS_CALL ("jal", operands, 1); }
5838   [(set_attr "type" "call")])
5839
5840 ;; See call_internal_direct.
5841 (define_insn "call_value_internal_direct"
5842   [(set (match_operand 0 "register_operand")
5843         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
5844               (match_operand 2)))
5845    (const_int 1)
5846    (clobber (reg:SI 31))]
5847   ""
5848   { return MIPS_CALL ("jal", operands, 1); })
5849
5850 ;; See comment for call_internal.
5851 (define_insn_and_split "call_value_multiple_internal"
5852   [(set (match_operand 0 "register_operand" "")
5853         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
5854               (match_operand 2 "" "")))
5855    (set (match_operand 3 "register_operand" "")
5856         (call (mem:SI (match_dup 1))
5857               (match_dup 2)))
5858    (clobber (reg:SI 31))]
5859   ""
5860   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1); }
5861   "reload_completed && TARGET_SPLIT_CALLS && (operands[4] = insn)"
5862   [(const_int 0)]
5863 {
5864   emit_call_insn (gen_call_value_multiple_split (operands[0], operands[1],
5865                                                  operands[2], operands[3]));
5866   if (!find_reg_note (operands[4], REG_NORETURN, 0))
5867     mips_restore_gp ();
5868   DONE;
5869 }
5870   [(set_attr "jal" "indirect,direct")
5871    (set_attr "extended_mips16" "no,yes")])
5872
5873 (define_insn "call_value_multiple_split"
5874   [(set (match_operand 0 "register_operand" "")
5875         (call (mem:SI (match_operand 1 "call_insn_operand" "cS"))
5876               (match_operand 2 "" "")))
5877    (set (match_operand 3 "register_operand" "")
5878         (call (mem:SI (match_dup 1))
5879               (match_dup 2)))
5880    (clobber (reg:SI 31))
5881    (clobber (reg:SI 28))]
5882   "TARGET_SPLIT_CALLS"
5883   { return MIPS_CALL ("jal", operands, 1); }
5884   [(set_attr "type" "call")])
5885
5886 ;; Call subroutine returning any type.
5887
5888 (define_expand "untyped_call"
5889   [(parallel [(call (match_operand 0 "")
5890                     (const_int 0))
5891               (match_operand 1 "")
5892               (match_operand 2 "")])]
5893   ""
5894 {
5895   int i;
5896
5897   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
5898
5899   for (i = 0; i < XVECLEN (operands[2], 0); i++)
5900     {
5901       rtx set = XVECEXP (operands[2], 0, i);
5902       mips_emit_move (SET_DEST (set), SET_SRC (set));
5903     }
5904
5905   emit_insn (gen_blockage ());
5906   DONE;
5907 })
5908 \f
5909 ;;
5910 ;;  ....................
5911 ;;
5912 ;;      MISC.
5913 ;;
5914 ;;  ....................
5915 ;;
5916
5917
5918 (define_insn "prefetch"
5919   [(prefetch (match_operand:QI 0 "address_operand" "p")
5920              (match_operand 1 "const_int_operand" "n")
5921              (match_operand 2 "const_int_operand" "n"))]
5922   "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
5923 {
5924   operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
5925   return "pref\t%1,%a0";
5926 }
5927   [(set_attr "type" "prefetch")])
5928
5929 (define_insn "*prefetch_indexed_<mode>"
5930   [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
5931                      (match_operand:P 1 "register_operand" "d"))
5932              (match_operand 2 "const_int_operand" "n")
5933              (match_operand 3 "const_int_operand" "n"))]
5934   "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
5935 {
5936   operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
5937   return "prefx\t%2,%1(%0)";
5938 }
5939   [(set_attr "type" "prefetchx")])
5940
5941 (define_insn "nop"
5942   [(const_int 0)]
5943   ""
5944   "%(nop%)"
5945   [(set_attr "type"     "nop")
5946    (set_attr "mode"     "none")])
5947
5948 ;; Like nop, but commented out when outside a .set noreorder block.
5949 (define_insn "hazard_nop"
5950   [(const_int 1)]
5951   ""
5952   {
5953     if (set_noreorder)
5954       return "nop";
5955     else
5956       return "#nop";
5957   }
5958   [(set_attr "type"     "nop")])
5959 \f
5960 ;; MIPS4 Conditional move instructions.
5961
5962 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
5963   [(set (match_operand:GPR 0 "register_operand" "=d,d")
5964         (if_then_else:GPR
5965          (match_operator:MOVECC 4 "equality_operator"
5966                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
5967                  (const_int 0)])
5968          (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
5969          (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
5970   "ISA_HAS_CONDMOVE"
5971   "@
5972     mov%T4\t%0,%z2,%1
5973     mov%t4\t%0,%z3,%1"
5974   [(set_attr "type" "condmove")
5975    (set_attr "mode" "<GPR:MODE>")])
5976
5977 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
5978   [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
5979         (if_then_else:SCALARF
5980          (match_operator:MOVECC 4 "equality_operator"
5981                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
5982                  (const_int 0)])
5983          (match_operand:SCALARF 2 "register_operand" "f,0")
5984          (match_operand:SCALARF 3 "register_operand" "0,f")))]
5985   "ISA_HAS_CONDMOVE"
5986   "@
5987     mov%T4.<fmt>\t%0,%2,%1
5988     mov%t4.<fmt>\t%0,%3,%1"
5989   [(set_attr "type" "condmove")
5990    (set_attr "mode" "<SCALARF:MODE>")])
5991
5992 ;; These are the main define_expand's used to make conditional moves.
5993
5994 (define_expand "mov<mode>cc"
5995   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
5996    (set (match_operand:GPR 0 "register_operand")
5997         (if_then_else:GPR (match_dup 5)
5998                           (match_operand:GPR 2 "reg_or_0_operand")
5999                           (match_operand:GPR 3 "reg_or_0_operand")))]
6000   "ISA_HAS_CONDMOVE"
6001 {
6002   mips_expand_conditional_move (operands);
6003   DONE;
6004 })
6005
6006 (define_expand "mov<mode>cc"
6007   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6008    (set (match_operand:SCALARF 0 "register_operand")
6009         (if_then_else:SCALARF (match_dup 5)
6010                               (match_operand:SCALARF 2 "register_operand")
6011                               (match_operand:SCALARF 3 "register_operand")))]
6012   "ISA_HAS_CONDMOVE"
6013 {
6014   mips_expand_conditional_move (operands);
6015   DONE;
6016 })
6017 \f
6018 ;;
6019 ;;  ....................
6020 ;;
6021 ;;      mips16 inline constant tables
6022 ;;
6023 ;;  ....................
6024 ;;
6025
6026 (define_insn "consttable_int"
6027   [(unspec_volatile [(match_operand 0 "consttable_operand" "")
6028                      (match_operand 1 "const_int_operand" "")]
6029                     UNSPEC_CONSTTABLE_INT)]
6030   "TARGET_MIPS16"
6031 {
6032   assemble_integer (operands[0], INTVAL (operands[1]),
6033                     BITS_PER_UNIT * INTVAL (operands[1]), 1);
6034   return "";
6035 }
6036   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
6037
6038 (define_insn "consttable_float"
6039   [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
6040                     UNSPEC_CONSTTABLE_FLOAT)]
6041   "TARGET_MIPS16"
6042 {
6043   REAL_VALUE_TYPE d;
6044
6045   gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
6046   REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
6047   assemble_real (d, GET_MODE (operands[0]),
6048                  GET_MODE_BITSIZE (GET_MODE (operands[0])));
6049   return "";
6050 }
6051   [(set (attr "length")
6052         (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
6053
6054 (define_insn "align"
6055   [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
6056   ""
6057   ".align\t%0"
6058   [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
6059 \f
6060 (define_split
6061   [(match_operand 0 "small_data_pattern")]
6062   "reload_completed"
6063   [(match_dup 0)]
6064   { operands[0] = mips_rewrite_small_data (operands[0]); })
6065
6066 ;;
6067 ;;  ....................
6068 ;;
6069 ;;      MIPS16e Save/Restore
6070 ;;
6071 ;;  ....................
6072 ;;
6073
6074 (define_insn "*mips16e_save_restore"
6075   [(match_parallel 0 ""
6076        [(set (match_operand:SI 1 "register_operand")
6077              (plus:SI (match_dup 1)
6078                       (match_operand:SI 2 "const_int_operand")))])]
6079   "operands[1] == stack_pointer_rtx
6080    && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
6081   { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
6082   [(set_attr "type" "arith")
6083    (set_attr "extended_mips16" "yes")])
6084
6085 ; Thread-Local Storage
6086
6087 ; The TLS base pointer is accessed via "rdhwr $v1, $29".  No current
6088 ; MIPS architecture defines this register, and no current
6089 ; implementation provides it; instead, any OS which supports TLS is
6090 ; expected to trap and emulate this instruction.  rdhwr is part of the
6091 ; MIPS 32r2 specification, but we use it on any architecture because
6092 ; we expect it to be emulated.  Use .set to force the assembler to
6093 ; accept it.
6094
6095 (define_insn "tls_get_tp_<mode>"
6096   [(set (match_operand:P 0 "register_operand" "=v")
6097         (unspec:P [(const_int 0)]
6098                   UNSPEC_TLS_GET_TP))]
6099   "HAVE_AS_TLS && !TARGET_MIPS16"
6100   ".set\tpush\;.set\tmips32r2\t\;rdhwr\t%0,$29\;.set\tpop"
6101   [(set_attr "type" "unknown")
6102    ; Since rdhwr always generates a trap for now, putting it in a delay
6103    ; slot would make the kernel's emulation of it much slower.
6104    (set_attr "can_delay" "no")
6105    (set_attr "mode" "<MODE>")])
6106 \f
6107 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
6108
6109 (include "mips-ps-3d.md")
6110
6111 ; The MIPS DSP Instructions.
6112
6113 (include "mips-dsp.md")
6114
6115 ; The MIPS DSP REV 2 Instructions.
6116
6117 (include "mips-dspr2.md")
6118
6119 ; MIPS fixed-point instructions.
6120 (include "mips-fixed.md")