OSDN Git Service

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