OSDN Git Service

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