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