Reverting merge from trunk
[official-gcc.git] / gcc / config / mips / mips.md
blob3554beb30337a1b6417674c5dc3c84161da65133
1 ;;  Mips.md          Machine Description for MIPS based processors
2 ;;  Copyright (C) 1989-2013 Free Software Foundation, Inc.
3 ;;  Contributed by   A. Lichnewsky, lich@inria.inria.fr
4 ;;  Changes by       Michael Meissner, meissner@osf.org
5 ;;  64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
6 ;;  Brendan Eich, brendan@microunity.com.
8 ;; This file is part of GCC.
10 ;; GCC is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; any later version.
15 ;; GCC is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GCC; see the file COPYING3.  If not see
22 ;; <http://www.gnu.org/licenses/>.
24 (define_enum "processor" [
25   r3000
26   4kc
27   4kp
28   5kc
29   5kf
30   20kc
31   24kc
32   24kf2_1
33   24kf1_1
34   74kc
35   74kf2_1
36   74kf1_1
37   74kf3_2
38   loongson_2e
39   loongson_2f
40   loongson_3a
41   m4k
42   octeon
43   octeon2
44   r3900
45   r6000
46   r4000
47   r4100
48   r4111
49   r4120
50   r4130
51   r4300
52   r4600
53   r4650
54   r4700
55   r5000
56   r5400
57   r5500
58   r5900
59   r7000
60   r8000
61   r9000
62   r10000
63   sb1
64   sb1a
65   sr71000
66   xlr
67   xlp
70 (define_c_enum "unspec" [
71   ;; Unaligned accesses.
72   UNSPEC_LOAD_LEFT
73   UNSPEC_LOAD_RIGHT
74   UNSPEC_STORE_LEFT
75   UNSPEC_STORE_RIGHT
77   ;; Integer operations that are too cumbersome to describe directly.
78   UNSPEC_WSBH
79   UNSPEC_DSBH
80   UNSPEC_DSHD
82   ;; Floating-point moves.
83   UNSPEC_LOAD_LOW
84   UNSPEC_LOAD_HIGH
85   UNSPEC_STORE_WORD
86   UNSPEC_MFHC1
87   UNSPEC_MTHC1
89   ;; HI/LO moves.
90   UNSPEC_MFHI
91   UNSPEC_MTHI
92   UNSPEC_SET_HILO
94   ;; GP manipulation.
95   UNSPEC_LOADGP
96   UNSPEC_COPYGP
97   UNSPEC_MOVE_GP
98   UNSPEC_POTENTIAL_CPRESTORE
99   UNSPEC_CPRESTORE
100   UNSPEC_RESTORE_GP
101   UNSPEC_EH_RETURN
102   UNSPEC_GP
103   UNSPEC_SET_GOT_VERSION
104   UNSPEC_UPDATE_GOT_VERSION
106   ;; Symbolic accesses.
107   UNSPEC_LOAD_CALL
108   UNSPEC_LOAD_GOT
109   UNSPEC_TLS_LDM
110   UNSPEC_TLS_GET_TP
111   UNSPEC_UNSHIFTED_HIGH
113   ;; MIPS16 constant pools.
114   UNSPEC_ALIGN
115   UNSPEC_CONSTTABLE_INT
116   UNSPEC_CONSTTABLE_FLOAT
118   ;; Blockage and synchronisation.
119   UNSPEC_BLOCKAGE
120   UNSPEC_CLEAR_HAZARD
121   UNSPEC_RDHWR
122   UNSPEC_SYNCI
123   UNSPEC_SYNC
125   ;; Cache manipulation.
126   UNSPEC_MIPS_CACHE
127   UNSPEC_R10K_CACHE_BARRIER
129   ;; Interrupt handling.
130   UNSPEC_ERET
131   UNSPEC_DERET
132   UNSPEC_DI
133   UNSPEC_EHB
134   UNSPEC_RDPGPR
135   UNSPEC_COP0
137   ;; Used in a call expression in place of args_size.  It's present for PIC
138   ;; indirect calls where it contains args_size and the function symbol.
139   UNSPEC_CALL_ATTR
141   ;; MIPS16 casesi jump table dispatch.
142   UNSPEC_CASESI_DISPATCH
144   ;; Stack checking.
145   UNSPEC_PROBE_STACK_RANGE
148 (define_constants
149   [(TLS_GET_TP_REGNUM           3)
150    (MIPS16_T_REGNUM             24)
151    (PIC_FUNCTION_ADDR_REGNUM    25)
152    (RETURN_ADDR_REGNUM          31)
153    (CPRESTORE_SLOT_REGNUM       76)
154    (GOT_VERSION_REGNUM          79)
156    ;; PIC long branch sequences are never longer than 100 bytes.
157    (MAX_PIC_BRANCH_LENGTH       100)
158   ]
161 (include "predicates.md")
162 (include "constraints.md")
164 ;; ....................
166 ;;      Attributes
168 ;; ....................
170 (define_attr "got" "unset,xgot_high,load"
171   (const_string "unset"))
173 ;; For jal instructions, this attribute is DIRECT when the target address
174 ;; is symbolic and INDIRECT when it is a register.
175 (define_attr "jal" "unset,direct,indirect"
176   (const_string "unset"))
178 ;; This attribute is YES if the instruction is a jal macro (not a
179 ;; real jal instruction).
181 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
182 ;; an instruction to restore $gp.  Direct jals are also macros for
183 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
184 ;; into a register.
185 (define_attr "jal_macro" "no,yes"
186   (cond [(eq_attr "jal" "direct")
187          (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
188                        ? JAL_MACRO_YES : JAL_MACRO_NO)")
189          (eq_attr "jal" "indirect")
190          (symbol_ref "(TARGET_CALL_CLOBBERED_GP
191                        ? JAL_MACRO_YES : JAL_MACRO_NO)")]
192         (const_string "no")))
194 ;; Classification of moves, extensions and truncations.  Most values
195 ;; are as for "type" (see below) but there are also the following
196 ;; move-specific values:
198 ;; constN       move an N-constraint integer into a MIPS16 register
199 ;; sll0         "sll DEST,SRC,0", which on 64-bit targets is guaranteed
200 ;;              to produce a sign-extended DEST, even if SRC is not
201 ;;              properly sign-extended
202 ;; ext_ins      EXT, DEXT, INS or DINS instruction
203 ;; andi         a single ANDI instruction
204 ;; loadpool     move a constant into a MIPS16 register by loading it
205 ;;              from the pool
206 ;; shift_shift  a shift left followed by a shift right
208 ;; This attribute is used to determine the instruction's length and
209 ;; scheduling type.  For doubleword moves, the attribute always describes
210 ;; the split instructions; in some cases, it is more appropriate for the
211 ;; scheduling type to be "multi" instead.
212 (define_attr "move_type"
213   "unknown,load,fpload,store,fpstore,mtc,mfc,mtlo,mflo,imul,move,fmove,
214    const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
215    shift_shift"
216   (const_string "unknown"))
218 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor"
219   (const_string "unknown"))
221 ;; Main data type used by the insn
222 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW"
223   (const_string "unknown"))
225 ;; True if the main data type is twice the size of a word.
226 (define_attr "dword_mode" "no,yes"
227   (cond [(and (eq_attr "mode" "DI,DF")
228               (not (match_test "TARGET_64BIT")))
229          (const_string "yes")
231          (and (eq_attr "mode" "TI,TF")
232               (match_test "TARGET_64BIT"))
233          (const_string "yes")]
234         (const_string "no")))
236 ;; Attributes describing a sync loop.  These loops have the form:
238 ;;       if (RELEASE_BARRIER == YES) sync
239 ;;    1: OLDVAL = *MEM
240 ;;       if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
241 ;;         CMP  = 0 [delay slot]
242 ;;       $TMP1 = OLDVAL & EXCLUSIVE_MASK
243 ;;       $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
244 ;;       $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
245 ;;       $AT |= $TMP1 | $TMP3
246 ;;       if (!commit (*MEM = $AT)) goto 1.
247 ;;         if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
248 ;;       CMP  = 1
249 ;;       if (ACQUIRE_BARRIER == YES) sync
250 ;;    2:
252 ;; where "$" values are temporaries and where the other values are
253 ;; specified by the attributes below.  Values are specified as operand
254 ;; numbers and insns are specified as enums.  If no operand number is
255 ;; specified, the following values are used instead:
257 ;;    - OLDVAL: $AT
258 ;;    - CMP: NONE
259 ;;    - NEWVAL: $AT
260 ;;    - INCLUSIVE_MASK: -1
261 ;;    - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
262 ;;    - EXCLUSIVE_MASK: 0
264 ;; MEM and INSN1_OP2 are required.
266 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
267 ;; but the gen* programs don't yet support that.
268 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
269 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
270 (define_attr "sync_cmp" "none,0,1,2,3,4,5" (const_string "none"))
271 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
272 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
273 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
274 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
275 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
276 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
277   (const_string "move"))
278 (define_attr "sync_insn2" "nop,and,xor,not"
279   (const_string "nop"))
280 ;; Memory model specifier.
281 ;; "0"-"9" values specify the operand that stores the memory model value.
282 ;; "10" specifies MEMMODEL_ACQ_REL,
283 ;; "11" specifies MEMMODEL_ACQUIRE.
284 (define_attr "sync_memmodel" "" (const_int 10))
286 ;; Accumulator operand for madd patterns.
287 (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))
289 ;; Classification of each insn.
290 ;; branch       conditional branch
291 ;; jump         unconditional jump
292 ;; call         unconditional call
293 ;; load         load instruction(s)
294 ;; fpload       floating point load
295 ;; fpidxload    floating point indexed load
296 ;; store        store instruction(s)
297 ;; fpstore      floating point store
298 ;; fpidxstore   floating point indexed store
299 ;; prefetch     memory prefetch (register + offset)
300 ;; prefetchx    memory indexed prefetch (register + register)
301 ;; condmove     conditional moves
302 ;; mtc          transfer to coprocessor
303 ;; mfc          transfer from coprocessor
304 ;; mthi         transfer to a hi register
305 ;; mtlo         transfer to a lo register
306 ;; mfhi         transfer from a hi register
307 ;; mflo         transfer from a lo register
308 ;; const        load constant
309 ;; arith        integer arithmetic instructions
310 ;; logical      integer logical instructions
311 ;; shift        integer shift instructions
312 ;; slt          set less than instructions
313 ;; signext      sign extend instructions
314 ;; clz          the clz and clo instructions
315 ;; pop          the pop instruction
316 ;; trap         trap if instructions
317 ;; imul         integer multiply 2 operands
318 ;; imul3        integer multiply 3 operands
319 ;; imul3nc      integer multiply 3 operands without clobbering HI/LO
320 ;; imadd        integer multiply-add
321 ;; idiv         integer divide 2 operands
322 ;; idiv3        integer divide 3 operands
323 ;; move         integer register move ({,D}ADD{,U} with rt = 0)
324 ;; fmove        floating point register move
325 ;; fadd         floating point add/subtract
326 ;; fmul         floating point multiply
327 ;; fmadd        floating point multiply-add
328 ;; fdiv         floating point divide
329 ;; frdiv        floating point reciprocal divide
330 ;; frdiv1       floating point reciprocal divide step 1
331 ;; frdiv2       floating point reciprocal divide step 2
332 ;; fabs         floating point absolute value
333 ;; fneg         floating point negation
334 ;; fcmp         floating point compare
335 ;; fcvt         floating point convert
336 ;; fsqrt        floating point square root
337 ;; frsqrt       floating point reciprocal square root
338 ;; frsqrt1      floating point reciprocal square root step1
339 ;; frsqrt2      floating point reciprocal square root step2
340 ;; dspmac       DSP MAC instructions not saturating the accumulator
341 ;; dspmacsat    DSP MAC instructions that saturate the accumulator
342 ;; accext       DSP accumulator extract instructions
343 ;; accmod       DSP accumulator modify instructions
344 ;; dspalu       DSP ALU instructions not saturating the result
345 ;; dspalusat    DSP ALU instructions that saturate the result
346 ;; multi        multiword sequence (or user asm statements)
347 ;; atomic       atomic memory update instruction
348 ;; syncloop     memory atomic operation implemented as a sync loop
349 ;; nop          no operation
350 ;; ghost        an instruction that produces no real code
351 ;; multimem     microMIPS multiword load and store
352 (define_attr "type"
353   "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
354    prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical,
355    shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
356    fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
357    frsqrt,frsqrt1,frsqrt2,dspmac,dspmacsat,accext,accmod,dspalu,dspalusat,
358    multi,atomic,syncloop,nop,ghost,multimem"
359   (cond [(eq_attr "jal" "!unset") (const_string "call")
360          (eq_attr "got" "load") (const_string "load")
362          (eq_attr "alu_type" "add,sub") (const_string "arith")
364          (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
366          ;; If a doubleword move uses these expensive instructions,
367          ;; it is usually better to schedule them in the same way
368          ;; as the singleword form, rather than as "multi".
369          (eq_attr "move_type" "load") (const_string "load")
370          (eq_attr "move_type" "fpload") (const_string "fpload")
371          (eq_attr "move_type" "store") (const_string "store")
372          (eq_attr "move_type" "fpstore") (const_string "fpstore")
373          (eq_attr "move_type" "mtc") (const_string "mtc")
374          (eq_attr "move_type" "mfc") (const_string "mfc")
375          (eq_attr "move_type" "mtlo") (const_string "mtlo")
376          (eq_attr "move_type" "mflo") (const_string "mflo")
378          ;; These types of move are always single insns.
379          (eq_attr "move_type" "imul") (const_string "imul")
380          (eq_attr "move_type" "fmove") (const_string "fmove")
381          (eq_attr "move_type" "loadpool") (const_string "load")
382          (eq_attr "move_type" "signext") (const_string "signext")
383          (eq_attr "move_type" "ext_ins") (const_string "arith")
384          (eq_attr "move_type" "arith") (const_string "arith")
385          (eq_attr "move_type" "logical") (const_string "logical")
386          (eq_attr "move_type" "sll0") (const_string "shift")
387          (eq_attr "move_type" "andi") (const_string "logical")
389          ;; These types of move are always split.
390          (eq_attr "move_type" "constN,shift_shift")
391            (const_string "multi")
393          ;; These types of move are split for doubleword modes only.
394          (and (eq_attr "move_type" "move,const")
395               (eq_attr "dword_mode" "yes"))
396            (const_string "multi")
397          (eq_attr "move_type" "move") (const_string "move")
398          (eq_attr "move_type" "const") (const_string "const")
399          (eq_attr "sync_mem" "!none") (const_string "syncloop")]
400         (const_string "unknown")))
402 ;; Mode for conversion types (fcvt)
403 ;; I2S          integer to float single (SI/DI to SF)
404 ;; I2D          integer to float double (SI/DI to DF)
405 ;; S2I          float to integer (SF to SI/DI)
406 ;; D2I          float to integer (DF to SI/DI)
407 ;; D2S          double to float single
408 ;; S2D          float single to double
410 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D" 
411   (const_string "unknown"))
413 ;; Is this an extended instruction in mips16 mode?
414 (define_attr "extended_mips16" "no,yes"
415   (if_then_else (ior ;; In general, constant-pool loads are extended
416                      ;; instructions.  We don't yet optimize for 16-bit
417                      ;; PC-relative references.
418                      (eq_attr "move_type" "sll0,loadpool")
419                      (eq_attr "jal" "direct")
420                      (eq_attr "got" "load"))
421                 (const_string "yes")
422                 (const_string "no")))
424 (define_attr "compression" "none,all,micromips"
425   (const_string "none"))
427 (define_attr "enabled" "no,yes"
428   (if_then_else (ior (eq_attr "compression" "all,none")
429                      (and (eq_attr "compression" "micromips")
430                           (match_test "TARGET_MICROMIPS")))
431                 (const_string "yes")
432                 (const_string "no")))
434 ;; The number of individual instructions that a non-branch pattern generates,
435 ;; using units of BASE_INSN_LENGTH.
436 (define_attr "insn_count" ""
437   (cond [;; "Ghost" instructions occupy no space.
438          (eq_attr "type" "ghost")
439          (const_int 0)
441          ;; Extended instructions count as 2.
442          (and (eq_attr "extended_mips16" "yes")
443               (match_test "TARGET_MIPS16"))
444          (const_int 2)
446          ;; A GOT load followed by an add of $gp.  This is not used for MIPS16.
447          (eq_attr "got" "xgot_high")
448          (const_int 2)
450          ;; SHIFT_SHIFTs are decomposed into two separate instructions.
451          ;; They are extended instructions on MIPS16 targets.
452          (eq_attr "move_type" "shift_shift")
453          (if_then_else (match_test "TARGET_MIPS16")
454                        (const_int 4)
455                        (const_int 2))
457          ;; Check for doubleword moves that are decomposed into two
458          ;; instructions.  The individual instructions are unextended
459          ;; MIPS16 ones.
460          (and (eq_attr "move_type" "mtc,mfc,mtlo,mflo,move")
461               (eq_attr "dword_mode" "yes"))
462          (const_int 2)
464          ;; Constants, loads and stores are handled by external routines.
465          (and (eq_attr "move_type" "const,constN")
466               (eq_attr "dword_mode" "yes"))
467          (symbol_ref "mips_split_const_insns (operands[1])")
468          (eq_attr "move_type" "const,constN")
469          (symbol_ref "mips_const_insns (operands[1])")
470          (eq_attr "move_type" "load,fpload")
471          (symbol_ref "mips_load_store_insns (operands[1], insn)")
472          (eq_attr "move_type" "store,fpstore")
473          (symbol_ref "mips_load_store_insns (operands[0], insn)
474                       + (TARGET_FIX_24K ? 1 : 0)")
476          ;; In the worst case, a call macro will take 8 instructions:
477          ;;
478          ;;     lui $25,%call_hi(FOO)
479          ;;     addu $25,$25,$28
480          ;;     lw $25,%call_lo(FOO)($25)
481          ;;     nop
482          ;;     jalr $25
483          ;;     nop
484          ;;     lw $gp,X($sp)
485          ;;     nop
486          (eq_attr "jal_macro" "yes")
487          (const_int 8)
489          ;; Various VR4120 errata require a nop to be inserted after a macc
490          ;; instruction.  The assembler does this for us, so account for
491          ;; the worst-case length here.
492          (and (eq_attr "type" "imadd")
493               (match_test "TARGET_FIX_VR4120"))
494          (const_int 2)
496          ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
497          ;; the result of the second one is missed.  The assembler should work
498          ;; around this by inserting a nop after the first dmult.
499          (and (eq_attr "type" "imul,imul3")
500               (eq_attr "mode" "DI")
501               (match_test "TARGET_FIX_VR4120"))
502          (const_int 2)
504          (eq_attr "type" "idiv,idiv3")
505          (symbol_ref "mips_idiv_insns ()")
507          (not (eq_attr "sync_mem" "none"))
508          (symbol_ref "mips_sync_loop_insns (insn, operands)")]
509         (const_int 1)))
511 ;; Length of instruction in bytes.  The default is derived from "insn_count",
512 ;; but there are special cases for branches (which must be handled here)
513 ;; and for compressed single instructions.
514 (define_attr "length" ""
515    (cond [(and (eq_attr "compression" "micromips,all")
516                (eq_attr "dword_mode" "no")
517                (match_test "TARGET_MICROMIPS"))
518           (const_int 2)
520           ;; Direct microMIPS branch instructions have a range of
521           ;; [-0x10000,0xfffe], otherwise the range is [-0x20000,0x1fffc].
522           ;; If a branch is outside this range, we have a choice of two
523           ;; sequences.
524           ;;
525           ;; For PIC, an out-of-range branch like:
526           ;;
527           ;;    bne     r1,r2,target
528           ;;    dslot
529           ;;
530           ;; becomes the equivalent of:
531           ;;
532           ;;    beq     r1,r2,1f
533           ;;    dslot
534           ;;    la      $at,target
535           ;;    jr      $at
536           ;;    nop
537           ;; 1:
538           ;;
539           ;; The non-PIC case is similar except that we use a direct
540           ;; jump instead of an la/jr pair.  Since the target of this
541           ;; jump is an absolute 28-bit bit address (the other bits
542           ;; coming from the address of the delay slot) this form cannot
543           ;; cross a 256MB boundary.  We could provide the option of
544           ;; using la/jr in this case too, but we do not do so at
545           ;; present.
546           ;;
547           ;; The value we specify here does not account for the delay slot
548           ;; instruction, whose length is added separately.  If the RTL
549           ;; pattern has no explicit delay slot, mips_adjust_insn_length
550           ;; will add the length of the implicit nop.  The range of
551           ;; [-0x20000, 0x1fffc] from the address of the delay slot
552           ;; therefore translates to a range of:
553           ;;
554           ;;    [-(0x20000 - sizeof (branch)), 0x1fffc - sizeof (slot)]
555           ;; == [-0x1fffc, 0x1fff8]
556           ;;
557           ;; from the shorten_branches reference address.
558           (and (eq_attr "type" "branch")
559                (not (match_test "TARGET_MIPS16")))
560           (cond [;; Any variant can handle the 17-bit range.
561                  (and (le (minus (match_dup 0) (pc)) (const_int 65532))
562                       (le (minus (pc) (match_dup 0)) (const_int 65534)))
563                    (const_int 4)
565                  ;; The 18-bit range is OK other than for microMIPS.
566                  (and (not (match_test "TARGET_MICROMIPS"))
567                       (and (le (minus (match_dup 0) (pc)) (const_int 131064))
568                            (le (minus (pc) (match_dup 0)) (const_int 131068))))
569                    (const_int 4)
571                  ;; The non-PIC case: branch, first delay slot, and J.
572                  (match_test "TARGET_ABSOLUTE_JUMPS")
573                    (const_int 12)]
575                  ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
576                  ;; mips_adjust_insn_length substitutes the correct length.
577                  ;;
578                  ;; Note that we can't simply use (symbol_ref ...) here
579                  ;; because genattrtab needs to know the maximum length
580                  ;; of an insn.
581                  (const_int MAX_PIC_BRANCH_LENGTH))
583           ;; An unextended MIPS16 branch has a range of [-0x100, 0xfe]
584           ;; from the address of the following instruction, which leads
585           ;; to a range of:
586           ;;
587           ;;    [-(0x100 - sizeof (branch)), 0xfe]
588           ;; == [-0xfe, 0xfe]
589           ;;
590           ;; from the shorten_branches reference address.  Extended branches
591           ;; likewise have a range of [-0x10000, 0xfffe] from the address
592           ;; of the following instruction, which leads to a range of:
593           ;;
594           ;;    [-(0x10000 - sizeof (branch)), 0xfffe]
595           ;; == [-0xfffc, 0xfffe]
596           ;;
597           ;; from the reference address.
598           ;;
599           ;; When a branch is out of range, mips_reorg splits it into a form
600           ;; that uses in-range branches.  There are four basic sequences:
601           ;;
602           ;; (1) Absolute addressing with a readable text segment
603           ;;     (32-bit addresses):
604           ;;
605           ;;     b... foo               2 bytes
606           ;;     move $1,$2             2 bytes
607           ;;     lw $2,label            2 bytes
608           ;;     jr $2                  2 bytes
609           ;;     move $2,$1             2 bytes
610           ;;     .align 2               0 or 2 bytes
611           ;; label:
612           ;;     .word target           4 bytes
613           ;; foo:
614           ;;                            (16 bytes in the worst case)
615           ;;
616           ;; (2) Absolute addressing with a readable text segment
617           ;;     (64-bit addresses):
618           ;;
619           ;;     b... foo               2 bytes
620           ;;     move $1,$2             2 bytes
621           ;;     ld $2,label            2 bytes
622           ;;     jr $2                  2 bytes
623           ;;     move $2,$1             2 bytes
624           ;;     .align 3               0 to 6 bytes
625           ;; label:
626           ;;     .dword target          8 bytes
627           ;; foo:
628           ;;                            (24 bytes in the worst case)
629           ;;
630           ;; (3) Absolute addressing without a readable text segment
631           ;;     (which requires 32-bit addresses at present):
632           ;;
633           ;;     b... foo               2 bytes
634           ;;     move $1,$2             2 bytes
635           ;;     lui $2,%hi(target)     4 bytes
636           ;;     sll $2,8               2 bytes
637           ;;     sll $2,8               2 bytes
638           ;;     addiu $2,%lo(target)   4 bytes
639           ;;     jr $2                  2 bytes
640           ;;     move $2,$1             2 bytes
641           ;; foo:
642           ;;                            (20 bytes)
643           ;;
644           ;; (4) PIC addressing (which requires 32-bit addresses at present):
645           ;;
646           ;;     b... foo               2 bytes
647           ;;     move $1,$2             2 bytes
648           ;;     lw $2,cprestore        0, 2 or 4 bytes
649           ;;     lw $2,%got(target)($2) 4 bytes
650           ;;     addiu $2,%lo(target)   4 bytes
651           ;;     jr $2                  2 bytes
652           ;;     move $2,$1             2 bytes
653           ;; foo:
654           ;;                            (20 bytes in the worst case)
655           (and (eq_attr "type" "branch")
656                (match_test "TARGET_MIPS16"))
657           (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
658                       (le (minus (pc) (match_dup 0)) (const_int 254)))
659                  (const_int 2)
660                  (and (le (minus (match_dup 0) (pc)) (const_int 65534))
661                       (le (minus (pc) (match_dup 0)) (const_int 65532)))
662                  (const_int 4)
663                  (and (match_test "TARGET_ABICALLS")
664                       (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
665                  (const_int 20)
666                  (match_test "Pmode == SImode")
667                  (const_int 16)
668                  ] (const_int 24))]
669          (symbol_ref "get_attr_insn_count (insn) * BASE_INSN_LENGTH")))
671 ;; Attribute describing the processor.
672 (define_enum_attr "cpu" "processor"
673   (const (symbol_ref "mips_tune")))
675 ;; The type of hardware hazard associated with this instruction.
676 ;; DELAY means that the next instruction cannot read the result
677 ;; of this one.  HILO means that the next two instructions cannot
678 ;; write to HI or LO.
679 (define_attr "hazard" "none,delay,hilo"
680   (cond [(and (eq_attr "type" "load,fpload,fpidxload")
681               (match_test "ISA_HAS_LOAD_DELAY"))
682          (const_string "delay")
684          (and (eq_attr "type" "mfc,mtc")
685               (match_test "ISA_HAS_XFER_DELAY"))
686          (const_string "delay")
688          (and (eq_attr "type" "fcmp")
689               (match_test "ISA_HAS_FCMP_DELAY"))
690          (const_string "delay")
692          ;; The r4000 multiplication patterns include an mflo instruction.
693          (and (eq_attr "type" "imul")
694               (match_test "TARGET_FIX_R4000"))
695          (const_string "hilo")
697          (and (eq_attr "type" "mfhi,mflo")
698               (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
699          (const_string "hilo")]
700         (const_string "none")))
702 ;; Can the instruction be put into a delay slot?
703 (define_attr "can_delay" "no,yes"
704   (if_then_else (and (eq_attr "type" "!branch,call,jump")
705                      (eq_attr "hazard" "none")
706                      (match_test "get_attr_insn_count (insn) == 1"))
707                 (const_string "yes")
708                 (const_string "no")))
710 ;; Attribute defining whether or not we can use the branch-likely
711 ;; instructions.
712 (define_attr "branch_likely" "no,yes"
713   (if_then_else (match_test "GENERATE_BRANCHLIKELY")
714                 (const_string "yes")
715                 (const_string "no")))
717 ;; True if an instruction might assign to hi or lo when reloaded.
718 ;; This is used by the TUNE_MACC_CHAINS code.
719 (define_attr "may_clobber_hilo" "no,yes"
720   (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthi,mtlo")
721                 (const_string "yes")
722                 (const_string "no")))
724 ;; Describe a user's asm statement.
725 (define_asm_attributes
726   [(set_attr "type" "multi")
727    (set_attr "can_delay" "no")])
729 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
730 ;; from the same template.
731 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
733 ;; A copy of GPR that can be used when a pattern has two independent
734 ;; modes.
735 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
737 (define_mode_iterator MOVEP1 [SI SF])
738 (define_mode_iterator MOVEP2 [SI SF])
740 ;; This mode iterator allows :HILO to be used as the mode of the
741 ;; concatenated HI and LO registers.
742 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
744 ;; This mode iterator allows :P to be used for patterns that operate on
745 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
746 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
748 ;; This mode iterator allows :MOVECC to be used anywhere that a
749 ;; conditional-move-type condition is needed.
750 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
751                               (CC "TARGET_HARD_FLOAT
752                                    && !TARGET_LOONGSON_2EF
753                                    && !TARGET_MIPS5900")])
755 ;; 32-bit integer moves for which we provide move patterns.
756 (define_mode_iterator IMOVE32
757   [SI
758    (V2HI "TARGET_DSP")
759    (V4QI "TARGET_DSP")
760    (V2HQ "TARGET_DSP")
761    (V2UHQ "TARGET_DSP")
762    (V2HA "TARGET_DSP")
763    (V2UHA "TARGET_DSP")
764    (V4QQ "TARGET_DSP")
765    (V4UQQ "TARGET_DSP")])
767 ;; 64-bit modes for which we provide move patterns.
768 (define_mode_iterator MOVE64
769   [DI DF
770    (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
771    (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
772    (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
773    (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")])
775 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
776 (define_mode_iterator MOVE128 [TI TF])
778 ;; This mode iterator allows the QI and HI extension patterns to be
779 ;; defined from the same template.
780 (define_mode_iterator SHORT [QI HI])
782 ;; Likewise the 64-bit truncate-and-shift patterns.
783 (define_mode_iterator SUBDI [QI HI SI])
785 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
786 ;; floating-point mode is allowed.
787 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
788                             (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
789                             (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
791 ;; Like ANYF, but only applies to scalar modes.
792 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
793                                (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
795 ;; A floating-point mode for which moves involving FPRs may need to be split.
796 (define_mode_iterator SPLITF
797   [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
798    (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
799    (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
800    (V2SI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
801    (V4HI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
802    (V8QI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
803    (TF "TARGET_64BIT && TARGET_FLOAT64")])
805 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
806 ;; 32-bit version and "dsubu" in the 64-bit version.
807 (define_mode_attr d [(SI "") (DI "d")
808                      (QQ "") (HQ "") (SQ "") (DQ "d")
809                      (UQQ "") (UHQ "") (USQ "") (UDQ "d")
810                      (HA "") (SA "") (DA "d")
811                      (UHA "") (USA "") (UDA "d")])
813 ;; Same as d but upper-case.
814 (define_mode_attr D [(SI "") (DI "D")
815                      (QQ "") (HQ "") (SQ "") (DQ "D")
816                      (UQQ "") (UHQ "") (USQ "") (UDQ "D")
817                      (HA "") (SA "") (DA "D")
818                      (UHA "") (USA "") (UDA "D")])
820 ;; This attribute gives the length suffix for a load or store instruction.
821 ;; The same suffixes work for zero and sign extensions.
822 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
823 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
825 ;; This attributes gives the mode mask of a SHORT.
826 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
828 ;; Mode attributes for GPR loads.
829 (define_mode_attr load [(SI "lw") (DI "ld")])
830 ;; Instruction names for stores.
831 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
833 ;; Similarly for MIPS IV indexed FPR loads and stores.
834 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
835 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
837 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
838 ;; are different.  Some forms of unextended addiu have an 8-bit immediate
839 ;; field but the equivalent daddiu has only a 5-bit field.
840 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
842 ;; This attribute gives the best constraint to use for registers of
843 ;; a given mode.
844 (define_mode_attr reg [(SI "d") (DI "d") (CC "z")])
846 ;; This attribute gives the format suffix for floating-point operations.
847 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
849 ;; This attribute gives the upper-case mode name for one unit of a
850 ;; floating-point mode.
851 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
853 ;; This attribute gives the integer mode that has the same size as a
854 ;; fixed-point mode.
855 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
856                          (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
857                          (HA "HI") (SA "SI") (DA "DI")
858                          (UHA "HI") (USA "SI") (UDA "DI")
859                          (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
860                          (V2HQ "SI") (V2HA "SI")])
862 ;; This attribute gives the integer mode that has half the size of
863 ;; the controlling mode.
864 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
865                             (V2SI "SI") (V4HI "SI") (V8QI "SI")
866                             (TF "DI")])
868 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
870 ;; In certain cases, div.s and div.ps may have a rounding error
871 ;; and/or wrong inexact flag.
873 ;; Therefore, we only allow div.s if not working around SB-1 rev2
874 ;; errata or if a slight loss of precision is OK.
875 (define_mode_attr divide_condition
876   [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
877    (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
879 ;; This attribute gives the conditions under which SQRT.fmt instructions
880 ;; can be used.
881 (define_mode_attr sqrt_condition
882   [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
884 ;; This attribute gives the conditions under which RECIP.fmt and RSQRT.fmt
885 ;; instructions can be used.  The MIPS32 and MIPS64 ISAs say that RECIP.D
886 ;; and RSQRT.D are unpredictable when doubles are stored in pairs of FPRs,
887 ;; so for safety's sake, we apply this restriction to all targets.
888 (define_mode_attr recip_condition
889   [(SF "ISA_HAS_FP4")
890    (DF "ISA_HAS_FP4 && TARGET_FLOAT64")
891    (V2SF "TARGET_SB1")])
893 ;; This code iterator allows signed and unsigned widening multiplications
894 ;; to use the same template.
895 (define_code_iterator any_extend [sign_extend zero_extend])
897 ;; This code iterator allows the two right shift instructions to be
898 ;; generated from the same template.
899 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
901 ;; This code iterator allows the three shift instructions to be generated
902 ;; from the same template.
903 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
905 ;; This code iterator allows unsigned and signed division to be generated
906 ;; from the same template.
907 (define_code_iterator any_div [div udiv])
909 ;; This code iterator allows unsigned and signed modulus to be generated
910 ;; from the same template.
911 (define_code_iterator any_mod [mod umod])
913 ;; This code iterator allows all native floating-point comparisons to be
914 ;; generated from the same template.
915 (define_code_iterator fcond [unordered uneq unlt unle eq lt le])
917 ;; This code iterator is used for comparisons that can be implemented
918 ;; by swapping the operands.
919 (define_code_iterator swapped_fcond [ge gt unge ungt])
921 ;; Equality operators.
922 (define_code_iterator equality_op [eq ne])
924 ;; These code iterators allow the signed and unsigned scc operations to use
925 ;; the same template.
926 (define_code_iterator any_gt [gt gtu])
927 (define_code_iterator any_ge [ge geu])
928 (define_code_iterator any_lt [lt ltu])
929 (define_code_iterator any_le [le leu])
931 (define_code_iterator any_return [return simple_return])
933 ;; <u> expands to an empty string when doing a signed operation and
934 ;; "u" when doing an unsigned operation.
935 (define_code_attr u [(sign_extend "") (zero_extend "u")
936                      (div "") (udiv "u")
937                      (mod "") (umod "u")
938                      (gt "") (gtu "u")
939                      (ge "") (geu "u")
940                      (lt "") (ltu "u")
941                      (le "") (leu "u")])
943 ;; <U> is like <u> except uppercase.
944 (define_code_attr U [(sign_extend "") (zero_extend "U")])
946 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
947 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
949 ;; <optab> expands to the name of the optab for a particular code.
950 (define_code_attr optab [(ashift "ashl")
951                          (ashiftrt "ashr")
952                          (lshiftrt "lshr")
953                          (ior "ior")
954                          (xor "xor")
955                          (and "and")
956                          (plus "add")
957                          (minus "sub")
958                          (return "return")
959                          (simple_return "simple_return")])
961 ;; <insn> expands to the name of the insn that implements a particular code.
962 (define_code_attr insn [(ashift "sll")
963                         (ashiftrt "sra")
964                         (lshiftrt "srl")
965                         (ior "or")
966                         (xor "xor")
967                         (and "and")
968                         (plus "addu")
969                         (minus "subu")])
971 ;; <immediate_insn> expands to the name of the insn that implements
972 ;; a particular code to operate on immediate values.
973 (define_code_attr immediate_insn [(ior "ori")
974                                   (xor "xori")
975                                   (and "andi")])
977 (define_code_attr shift_compression [(ashift "micromips")
978                                      (lshiftrt "micromips")
979                                      (ashiftrt "none")])
981 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
982 (define_code_attr fcond [(unordered "un")
983                          (uneq "ueq")
984                          (unlt "ult")
985                          (unle "ule")
986                          (eq "eq")
987                          (lt "lt")
988                          (le "le")])
990 ;; Similar, but for swapped conditions.
991 (define_code_attr swapped_fcond [(ge "le")
992                                  (gt "lt")
993                                  (unge "ule")
994                                  (ungt "ult")])
996 ;; The value of the bit when the branch is taken for branch_bit patterns.
997 ;; Comparison is always against zero so this depends on the operator.
998 (define_code_attr bbv [(eq "0") (ne "1")])
1000 ;; This is the inverse value of bbv.
1001 (define_code_attr bbinv [(eq "1") (ne "0")])
1003 ;; .........................
1005 ;;      Branch, call and jump delay slots
1007 ;; .........................
1009 (define_delay (and (eq_attr "type" "branch")
1010                    (not (match_test "TARGET_MIPS16"))
1011                    (eq_attr "branch_likely" "yes"))
1012   [(eq_attr "can_delay" "yes")
1013    (nil)
1014    (eq_attr "can_delay" "yes")])
1016 ;; Branches that don't have likely variants do not annul on false.
1017 (define_delay (and (eq_attr "type" "branch")
1018                    (not (match_test "TARGET_MIPS16"))
1019                    (eq_attr "branch_likely" "no"))
1020   [(eq_attr "can_delay" "yes")
1021    (nil)
1022    (nil)])
1024 (define_delay (eq_attr "type" "jump")
1025   [(eq_attr "can_delay" "yes")
1026    (nil)
1027    (nil)])
1029 (define_delay (and (eq_attr "type" "call")
1030                    (eq_attr "jal_macro" "no"))
1031   [(eq_attr "can_delay" "yes")
1032    (nil)
1033    (nil)])
1035 ;; Pipeline descriptions.
1037 ;; generic.md provides a fallback for processors without a specific
1038 ;; pipeline description.  It is derived from the old define_function_unit
1039 ;; version and uses the "alu" and "imuldiv" units declared below.
1041 ;; Some of the processor-specific files are also derived from old
1042 ;; define_function_unit descriptions and simply override the parts of
1043 ;; generic.md that don't apply.  The other processor-specific files
1044 ;; are self-contained.
1045 (define_automaton "alu,imuldiv")
1047 (define_cpu_unit "alu" "alu")
1048 (define_cpu_unit "imuldiv" "imuldiv")
1050 ;; Ghost instructions produce no real code and introduce no hazards.
1051 ;; They exist purely to express an effect on dataflow.
1052 (define_insn_reservation "ghost" 0
1053   (eq_attr "type" "ghost")
1054   "nothing")
1056 (include "4k.md")
1057 (include "5k.md")
1058 (include "20kc.md")
1059 (include "24k.md")
1060 (include "74k.md")
1061 (include "3000.md")
1062 (include "4000.md")
1063 (include "4100.md")
1064 (include "4130.md")
1065 (include "4300.md")
1066 (include "4600.md")
1067 (include "5000.md")
1068 (include "5400.md")
1069 (include "5500.md")
1070 (include "6000.md")
1071 (include "7000.md")
1072 (include "9000.md")
1073 (include "10000.md")
1074 (include "loongson2ef.md")
1075 (include "loongson3a.md")
1076 (include "octeon.md")
1077 (include "sb1.md")
1078 (include "sr71k.md")
1079 (include "xlr.md")
1080 (include "xlp.md")
1081 (include "generic.md")
1084 ;;  ....................
1086 ;;      CONDITIONAL TRAPS
1088 ;;  ....................
1091 (define_insn "trap"
1092   [(trap_if (const_int 1) (const_int 0))]
1093   ""
1095   if (ISA_HAS_COND_TRAP)
1096     return "teq\t$0,$0";
1097   else if (TARGET_MIPS16)
1098     return "break 0";
1099   else
1100     return "break";
1102   [(set_attr "type" "trap")])
1104 (define_expand "ctrap<mode>4"
1105   [(trap_if (match_operator 0 "comparison_operator"
1106                             [(match_operand:GPR 1 "reg_or_0_operand")
1107                              (match_operand:GPR 2 "arith_operand")])
1108             (match_operand 3 "const_0_operand"))]
1109   "ISA_HAS_COND_TRAP"
1111   mips_expand_conditional_trap (operands[0]);
1112   DONE;
1115 (define_insn "*conditional_trap<mode>"
1116   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1117                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1118                                  (match_operand:GPR 2 "arith_operand" "dI")])
1119             (const_int 0))]
1120   "ISA_HAS_COND_TRAP"
1121   "t%C0\t%z1,%2"
1122   [(set_attr "type" "trap")])
1125 ;;  ....................
1127 ;;      ADDITION
1129 ;;  ....................
1132 (define_insn "add<mode>3"
1133   [(set (match_operand:ANYF 0 "register_operand" "=f")
1134         (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1135                    (match_operand:ANYF 2 "register_operand" "f")))]
1136   ""
1137   "add.<fmt>\t%0,%1,%2"
1138   [(set_attr "type" "fadd")
1139    (set_attr "mode" "<UNITMODE>")])
1141 (define_expand "add<mode>3"
1142   [(set (match_operand:GPR 0 "register_operand")
1143         (plus:GPR (match_operand:GPR 1 "register_operand")
1144                   (match_operand:GPR 2 "arith_operand")))]
1145   "")
1147 (define_insn "*add<mode>3"
1148   [(set (match_operand:GPR 0 "register_operand" "=!u,d,!u,!u,!ks,!d,d")
1149         (plus:GPR (match_operand:GPR 1 "register_operand" "!u,d,!u,!ks,!ks,0,d")
1150                   (match_operand:GPR 2 "arith_operand" "!u,d,Uead,Uuw6,Uesp,Usb4,Q")))]
1151   "!TARGET_MIPS16"
1153   if (which_alternative == 0 
1154       || which_alternative == 1)
1155     return "<d>addu\t%0,%1,%2";
1156   else
1157     return "<d>addiu\t%0,%1,%2";
1159   [(set_attr "alu_type" "add")
1160    (set_attr "compression" "micromips,*,micromips,micromips,micromips,micromips,*")
1161    (set_attr "mode" "<MODE>")])
1163 (define_insn "*add<mode>3_mips16"
1164   [(set (match_operand:GPR 0 "register_operand" "=ks,ks,d,d,d,d,d,d,d")
1165         (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,ks,ks,0,0,d,d,d")
1166                   (match_operand:GPR 2 "arith_operand" "Usd8,Q,Uuw<si8_di5>,Q,Usb<si8_di5>,Q,Usb4,O,d")))]
1167   "TARGET_MIPS16"
1168   "@
1169     <d>addiu\t%0,%2
1170     <d>addiu\t%0,%2
1171     <d>addiu\t%0,%1,%2
1172     <d>addiu\t%0,%1,%2
1173     <d>addiu\t%0,%2
1174     <d>addiu\t%0,%2
1175     <d>addiu\t%0,%1,%2
1176     <d>addiu\t%0,%1,%2
1177     <d>addu\t%0,%1,%2"
1178   [(set_attr "alu_type" "add")
1179    (set_attr "mode" "<MODE>")
1180    (set_attr "extended_mips16" "no,yes,no,yes,no,yes,no,yes,no")])
1182 ;; On the mips16, we can sometimes split an add of a constant which is
1183 ;; a 4 byte instruction into two adds which are both 2 byte
1184 ;; instructions.  There are two cases: one where we are adding a
1185 ;; constant plus a register to another register, and one where we are
1186 ;; simply adding a constant to a register.
1188 (define_split
1189   [(set (match_operand:SI 0 "d_operand")
1190         (plus:SI (match_dup 0)
1191                  (match_operand:SI 1 "const_int_operand")))]
1192   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1193    && ((INTVAL (operands[1]) > 0x7f
1194         && INTVAL (operands[1]) <= 0x7f + 0x7f)
1195        || (INTVAL (operands[1]) < - 0x80
1196            && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1197   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1198    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1200   HOST_WIDE_INT val = INTVAL (operands[1]);
1202   if (val >= 0)
1203     {
1204       operands[1] = GEN_INT (0x7f);
1205       operands[2] = GEN_INT (val - 0x7f);
1206     }
1207   else
1208     {
1209       operands[1] = GEN_INT (- 0x80);
1210       operands[2] = GEN_INT (val + 0x80);
1211     }
1214 (define_split
1215   [(set (match_operand:SI 0 "d_operand")
1216         (plus:SI (match_operand:SI 1 "d_operand")
1217                  (match_operand:SI 2 "const_int_operand")))]
1218   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1219    && REGNO (operands[0]) != REGNO (operands[1])
1220    && ((INTVAL (operands[2]) > 0x7
1221         && INTVAL (operands[2]) <= 0x7 + 0x7f)
1222        || (INTVAL (operands[2]) < - 0x8
1223            && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1224   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1225    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1227   HOST_WIDE_INT val = INTVAL (operands[2]);
1229   if (val >= 0)
1230     {
1231       operands[2] = GEN_INT (0x7);
1232       operands[3] = GEN_INT (val - 0x7);
1233     }
1234   else
1235     {
1236       operands[2] = GEN_INT (- 0x8);
1237       operands[3] = GEN_INT (val + 0x8);
1238     }
1241 (define_split
1242   [(set (match_operand:DI 0 "d_operand")
1243         (plus:DI (match_dup 0)
1244                  (match_operand:DI 1 "const_int_operand")))]
1245   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1246    && ((INTVAL (operands[1]) > 0xf
1247         && INTVAL (operands[1]) <= 0xf + 0xf)
1248        || (INTVAL (operands[1]) < - 0x10
1249            && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1250   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1251    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1253   HOST_WIDE_INT val = INTVAL (operands[1]);
1255   if (val >= 0)
1256     {
1257       operands[1] = GEN_INT (0xf);
1258       operands[2] = GEN_INT (val - 0xf);
1259     }
1260   else
1261     {
1262       operands[1] = GEN_INT (- 0x10);
1263       operands[2] = GEN_INT (val + 0x10);
1264     }
1267 (define_split
1268   [(set (match_operand:DI 0 "d_operand")
1269         (plus:DI (match_operand:DI 1 "d_operand")
1270                  (match_operand:DI 2 "const_int_operand")))]
1271   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1272    && REGNO (operands[0]) != REGNO (operands[1])
1273    && ((INTVAL (operands[2]) > 0x7
1274         && INTVAL (operands[2]) <= 0x7 + 0xf)
1275        || (INTVAL (operands[2]) < - 0x8
1276            && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1277   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1278    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1280   HOST_WIDE_INT val = INTVAL (operands[2]);
1282   if (val >= 0)
1283     {
1284       operands[2] = GEN_INT (0x7);
1285       operands[3] = GEN_INT (val - 0x7);
1286     }
1287   else
1288     {
1289       operands[2] = GEN_INT (- 0x8);
1290       operands[3] = GEN_INT (val + 0x8);
1291     }
1294 (define_insn "*addsi3_extended"
1295   [(set (match_operand:DI 0 "register_operand" "=d,d")
1296         (sign_extend:DI
1297              (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1298                       (match_operand:SI 2 "arith_operand" "d,Q"))))]
1299   "TARGET_64BIT && !TARGET_MIPS16"
1300   "@
1301     addu\t%0,%1,%2
1302     addiu\t%0,%1,%2"
1303   [(set_attr "alu_type" "add")
1304    (set_attr "mode" "SI")])
1306 ;; Split this insn so that the addiu splitters can have a crack at it.
1307 ;; Use a conservative length estimate until the split.
1308 (define_insn_and_split "*addsi3_extended_mips16"
1309   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1310         (sign_extend:DI
1311              (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1312                       (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1313   "TARGET_64BIT && TARGET_MIPS16"
1314   "#"
1315   "&& reload_completed"
1316   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1317   { operands[3] = gen_lowpart (SImode, operands[0]); }
1318   [(set_attr "alu_type" "add")
1319    (set_attr "mode" "SI")
1320    (set_attr "extended_mips16" "yes")])
1322 ;; Combiner patterns for unsigned byte-add.
1324 (define_insn "*baddu_si"
1325   [(set (match_operand:SI 0 "register_operand" "=d")
1326         (zero_extend:SI
1327          (plus:QI (match_operand:QI 1 "register_operand" "d")
1328                   (match_operand:QI 2 "register_operand" "d"))))]
1329   "ISA_HAS_BADDU"
1330   "baddu\\t%0,%1,%2"
1331   [(set_attr "alu_type" "add")])
1333 (define_insn "*baddu_di<mode>"
1334   [(set (match_operand:GPR 0 "register_operand" "=d")
1335         (zero_extend:GPR
1336          (plus:QI (truncate:QI (match_operand:DI 1 "register_operand" "d"))
1337                   (truncate:QI (match_operand:DI 2 "register_operand" "d")))))]
1338   "ISA_HAS_BADDU && TARGET_64BIT"
1339   "baddu\\t%0,%1,%2"
1340   [(set_attr "alu_type" "add")])
1343 ;;  ....................
1345 ;;      SUBTRACTION
1347 ;;  ....................
1350 (define_insn "sub<mode>3"
1351   [(set (match_operand:ANYF 0 "register_operand" "=f")
1352         (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1353                     (match_operand:ANYF 2 "register_operand" "f")))]
1354   ""
1355   "sub.<fmt>\t%0,%1,%2"
1356   [(set_attr "type" "fadd")
1357    (set_attr "mode" "<UNITMODE>")])
1359 (define_insn "sub<mode>3"
1360   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
1361         (minus:GPR (match_operand:GPR 1 "register_operand" "!u,d")
1362                    (match_operand:GPR 2 "register_operand" "!u,d")))]
1363   ""
1364   "<d>subu\t%0,%1,%2"
1365   [(set_attr "alu_type" "sub")
1366    (set_attr "compression" "micromips,*")
1367    (set_attr "mode" "<MODE>")])
1369 (define_insn "*subsi3_extended"
1370   [(set (match_operand:DI 0 "register_operand" "=d")
1371         (sign_extend:DI
1372             (minus:SI (match_operand:SI 1 "register_operand" "d")
1373                       (match_operand:SI 2 "register_operand" "d"))))]
1374   "TARGET_64BIT"
1375   "subu\t%0,%1,%2"
1376   [(set_attr "alu_type" "sub")
1377    (set_attr "mode" "DI")])
1380 ;;  ....................
1382 ;;      MULTIPLICATION
1384 ;;  ....................
1387 (define_expand "mul<mode>3"
1388   [(set (match_operand:SCALARF 0 "register_operand")
1389         (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1390                       (match_operand:SCALARF 2 "register_operand")))]
1391   ""
1392   "")
1394 (define_insn "*mul<mode>3"
1395   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1396         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1397                       (match_operand:SCALARF 2 "register_operand" "f")))]
1398   "!TARGET_4300_MUL_FIX"
1399   "mul.<fmt>\t%0,%1,%2"
1400   [(set_attr "type" "fmul")
1401    (set_attr "mode" "<MODE>")])
1403 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1404 ;; operands may corrupt immediately following multiplies. This is a
1405 ;; simple fix to insert NOPs.
1407 (define_insn "*mul<mode>3_r4300"
1408   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1409         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1410                       (match_operand:SCALARF 2 "register_operand" "f")))]
1411   "TARGET_4300_MUL_FIX"
1412   "mul.<fmt>\t%0,%1,%2\;nop"
1413   [(set_attr "type" "fmul")
1414    (set_attr "mode" "<MODE>")
1415    (set_attr "insn_count" "2")])
1417 (define_insn "mulv2sf3"
1418   [(set (match_operand:V2SF 0 "register_operand" "=f")
1419         (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1420                    (match_operand:V2SF 2 "register_operand" "f")))]
1421   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1422   "mul.ps\t%0,%1,%2"
1423   [(set_attr "type" "fmul")
1424    (set_attr "mode" "SF")])
1426 ;; The original R4000 has a cpu bug.  If a double-word or a variable
1427 ;; shift executes while an integer multiplication is in progress, the
1428 ;; shift may give an incorrect result.  Avoid this by keeping the mflo
1429 ;; with the mult on the R4000.
1431 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1432 ;; (also valid for MIPS R4000MC processors):
1434 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1435 ;;      this errata description.
1436 ;;      The following code sequence causes the R4000 to incorrectly
1437 ;;      execute the Double Shift Right Arithmetic 32 (dsra32)
1438 ;;      instruction.  If the dsra32 instruction is executed during an
1439 ;;      integer multiply, the dsra32 will only shift by the amount in
1440 ;;      specified in the instruction rather than the amount plus 32
1441 ;;      bits.
1442 ;;      instruction 1:          mult    rs,rt           integer multiply
1443 ;;      instruction 2-12:       dsra32  rd,rt,rs        doubleword shift
1444 ;;                                                      right arithmetic + 32
1445 ;;      Workaround: A dsra32 instruction placed after an integer
1446 ;;      multiply should not be one of the 11 instructions after the
1447 ;;      multiply instruction."
1449 ;; and:
1451 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1452 ;;      the following description.
1453 ;;      All extended shifts (shift by n+32) and variable shifts (32 and
1454 ;;      64-bit versions) may produce incorrect results under the
1455 ;;      following conditions:
1456 ;;      1) An integer multiply is currently executing
1457 ;;      2) These types of shift instructions are executed immediately
1458 ;;         following an integer divide instruction.
1459 ;;      Workaround:
1460 ;;      1) Make sure no integer multiply is running wihen these
1461 ;;         instruction are executed.  If this cannot be predicted at
1462 ;;         compile time, then insert a "mfhi" to R0 instruction
1463 ;;         immediately after the integer multiply instruction.  This
1464 ;;         will cause the integer multiply to complete before the shift
1465 ;;         is executed.
1466 ;;      2) Separate integer divide and these two classes of shift
1467 ;;         instructions by another instruction or a noop."
1469 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1470 ;; respectively.
1472 (define_expand "mul<mode>3"
1473   [(set (match_operand:GPR 0 "register_operand")
1474         (mult:GPR (match_operand:GPR 1 "register_operand")
1475                   (match_operand:GPR 2 "register_operand")))]
1476   "ISA_HAS_<D>MULT"
1478   rtx lo;
1480   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
1481     emit_insn (gen_mul<mode>3_mul3_loongson (operands[0], operands[1],
1482                                              operands[2]));
1483   else if (ISA_HAS_<D>MUL3)
1484     emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1485   else if (TARGET_MIPS16)
1486     {
1487       lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1488       emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1489       emit_move_insn (operands[0], lo);
1490     }
1491   else if (TARGET_FIX_R4000)
1492     emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1493   else
1494     emit_insn
1495       (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1496   DONE;
1499 (define_insn "mul<mode>3_mul3_loongson"
1500   [(set (match_operand:GPR 0 "register_operand" "=d")
1501         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1502                   (match_operand:GPR 2 "register_operand" "d")))]
1503   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A"
1505   if (TARGET_LOONGSON_2EF)
1506     return "<d>multu.g\t%0,%1,%2";
1507   else
1508     return "gs<d>multu\t%0,%1,%2";
1510   [(set_attr "type" "imul3nc")
1511    (set_attr "mode" "<MODE>")])
1513 (define_insn "mul<mode>3_mul3"
1514   [(set (match_operand:GPR 0 "register_operand" "=d,l")
1515         (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1516                   (match_operand:GPR 2 "register_operand" "d,d")))
1517    (clobber (match_scratch:GPR 3 "=l,X"))]
1518   "ISA_HAS_<D>MUL3"
1520   if (which_alternative == 1)
1521     return "<d>mult\t%1,%2";
1522   if (<MODE>mode == SImode && (TARGET_MIPS3900 || TARGET_MIPS5900))
1523     return "mult\t%0,%1,%2";
1524   return "<d>mul\t%0,%1,%2";
1526   [(set_attr "type" "imul3,imul")
1527    (set_attr "mode" "<MODE>")])
1529 ;; If a register gets allocated to LO, and we spill to memory, the reload
1530 ;; will include a move from LO to a GPR.  Merge it into the multiplication
1531 ;; if it can set the GPR directly.
1533 ;; Operand 0: LO
1534 ;; Operand 1: GPR (1st multiplication operand)
1535 ;; Operand 2: GPR (2nd multiplication operand)
1536 ;; Operand 3: GPR (destination)
1537 (define_peephole2
1538   [(parallel
1539        [(set (match_operand:SI 0 "lo_operand")
1540              (mult:SI (match_operand:SI 1 "d_operand")
1541                       (match_operand:SI 2 "d_operand")))
1542         (clobber (scratch:SI))])
1543    (set (match_operand:SI 3 "d_operand")
1544         (match_dup 0))]
1545   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1546   [(parallel
1547        [(set (match_dup 3)
1548              (mult:SI (match_dup 1)
1549                       (match_dup 2)))
1550         (clobber (match_dup 0))])])
1552 (define_insn "mul<mode>3_internal"
1553   [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1554         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1555                   (match_operand:GPR 2 "register_operand" "d")))]
1556   "ISA_HAS_<D>MULT && !TARGET_FIX_R4000"
1557   "<d>mult\t%1,%2"
1558   [(set_attr "type" "imul")
1559    (set_attr "mode" "<MODE>")])
1561 (define_insn "mul<mode>3_r4000"
1562   [(set (match_operand:GPR 0 "register_operand" "=d")
1563         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1564                   (match_operand:GPR 2 "register_operand" "d")))
1565    (clobber (match_scratch:GPR 3 "=l"))]
1566   "ISA_HAS_<D>MULT && TARGET_FIX_R4000"
1567   "<d>mult\t%1,%2\;mflo\t%0"
1568   [(set_attr "type" "imul")
1569    (set_attr "mode" "<MODE>")
1570    (set_attr "insn_count" "2")])
1572 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1573 ;; of "mult; mflo".  They have the same latency, but the first form gives
1574 ;; us an extra cycle to compute the operands.
1576 ;; Operand 0: LO
1577 ;; Operand 1: GPR (1st multiplication operand)
1578 ;; Operand 2: GPR (2nd multiplication operand)
1579 ;; Operand 3: GPR (destination)
1580 (define_peephole2
1581   [(set (match_operand:SI 0 "lo_operand")
1582         (mult:SI (match_operand:SI 1 "d_operand")
1583                  (match_operand:SI 2 "d_operand")))
1584    (set (match_operand:SI 3 "d_operand")
1585         (match_dup 0))]
1586   "ISA_HAS_MACC && !ISA_HAS_MUL3"
1587   [(set (match_dup 0)
1588         (const_int 0))
1589    (parallel
1590        [(set (match_dup 0)
1591              (plus:SI (mult:SI (match_dup 1)
1592                                (match_dup 2))
1593                       (match_dup 0)))
1594         (set (match_dup 3)
1595              (plus:SI (mult:SI (match_dup 1)
1596                                (match_dup 2))
1597                       (match_dup 0)))])])
1599 ;; Multiply-accumulate patterns
1601 ;; This pattern is first matched by combine, which tries to use the
1602 ;; pattern wherever it can.  We don't know until later whether it
1603 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1604 ;; so we need to keep both options open.
1606 ;; The second alternative has a "?" marker because it is generally
1607 ;; one instruction more costly than the first alternative.  This "?"
1608 ;; marker is enough to convey the relative costs to the register
1609 ;; allocator.
1611 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1612 ;; reloads of the other operands, even though operands 4 and 5 need no
1613 ;; copy instructions.  Reload therefore thinks that the second alternative
1614 ;; is two reloads more costly than the first.  We add "*?*?" to the first
1615 ;; alternative as a counterweight.
1616 (define_insn "*mul_acc_si"
1617   [(set (match_operand:SI 0 "register_operand" "=l*?*?,d?")
1618         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1619                           (match_operand:SI 2 "register_operand" "d,d"))
1620                  (match_operand:SI 3 "register_operand" "0,d")))
1621    (clobber (match_scratch:SI 4 "=X,l"))
1622    (clobber (match_scratch:SI 5 "=X,&d"))]
1623   "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1624   "@
1625     madd\t%1,%2
1626     #"
1627   [(set_attr "type"     "imadd")
1628    (set_attr "accum_in" "3")
1629    (set_attr "mode"     "SI")
1630    (set_attr "insn_count" "1,2")])
1632 ;; The same idea applies here.  The middle alternative needs one less
1633 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1634 (define_insn "*mul_acc_si_r3900"
1635   [(set (match_operand:SI 0 "register_operand" "=l*?*?,d*?,d?")
1636         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1637                           (match_operand:SI 2 "register_operand" "d,d,d"))
1638                  (match_operand:SI 3 "register_operand" "0,l,d")))
1639    (clobber (match_scratch:SI 4 "=X,3,l"))
1640    (clobber (match_scratch:SI 5 "=X,X,&d"))]
1641   "TARGET_MIPS3900 && !TARGET_MIPS16"
1642   "@
1643     madd\t%1,%2
1644     madd\t%0,%1,%2
1645     #"
1646   [(set_attr "type"     "imadd")
1647    (set_attr "accum_in" "3")
1648    (set_attr "mode"     "SI")
1649    (set_attr "insn_count" "1,1,2")])
1651 ;; Split *mul_acc_si if both the source and destination accumulator
1652 ;; values are GPRs.
1653 (define_split
1654   [(set (match_operand:SI 0 "d_operand")
1655         (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1656                           (match_operand:SI 2 "d_operand"))
1657                  (match_operand:SI 3 "d_operand")))
1658    (clobber (match_operand:SI 4 "lo_operand"))
1659    (clobber (match_operand:SI 5 "d_operand"))]
1660   "reload_completed"
1661   [(parallel [(set (match_dup 5)
1662                    (mult:SI (match_dup 1) (match_dup 2)))
1663               (clobber (match_dup 4))])
1664    (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1665   "")
1667 (define_insn "*macc"
1668   [(set (match_operand:SI 0 "register_operand" "=l,d")
1669         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1670                           (match_operand:SI 2 "register_operand" "d,d"))
1671                  (match_operand:SI 3 "register_operand" "0,l")))
1672    (clobber (match_scratch:SI 4 "=X,3"))]
1673   "ISA_HAS_MACC"
1675   if (which_alternative == 1)
1676     return "macc\t%0,%1,%2";
1677   else if (TARGET_MIPS5500)
1678     return "madd\t%1,%2";
1679   else
1680     /* The VR4130 assumes that there is a two-cycle latency between a macc
1681        that "writes" to $0 and an instruction that reads from it.  We avoid
1682        this by assigning to $1 instead.  */
1683     return "%[macc\t%@,%1,%2%]";
1685   [(set_attr "type" "imadd")
1686    (set_attr "accum_in" "3")
1687    (set_attr "mode" "SI")])
1689 (define_insn "*msac"
1690   [(set (match_operand:SI 0 "register_operand" "=l,d")
1691         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1692                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1693                            (match_operand:SI 3 "register_operand" "d,d"))))
1694    (clobber (match_scratch:SI 4 "=X,1"))]
1695   "ISA_HAS_MSAC"
1697   if (which_alternative == 1)
1698     return "msac\t%0,%2,%3";
1699   else if (TARGET_MIPS5500)
1700     return "msub\t%2,%3";
1701   else
1702     return "msac\t$0,%2,%3";
1704   [(set_attr "type"     "imadd")
1705    (set_attr "accum_in" "1")
1706    (set_attr "mode"     "SI")])
1708 ;; An msac-like instruction implemented using negation and a macc.
1709 (define_insn_and_split "*msac_using_macc"
1710   [(set (match_operand:SI 0 "register_operand" "=l,d")
1711         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1712                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1713                            (match_operand:SI 3 "register_operand" "d,d"))))
1714    (clobber (match_scratch:SI 4 "=X,1"))
1715    (clobber (match_scratch:SI 5 "=d,d"))]
1716   "ISA_HAS_MACC && !ISA_HAS_MSAC"
1717   "#"
1718   "&& reload_completed"
1719   [(set (match_dup 5)
1720         (neg:SI (match_dup 3)))
1721    (parallel
1722        [(set (match_dup 0)
1723              (plus:SI (mult:SI (match_dup 2)
1724                                (match_dup 5))
1725                       (match_dup 1)))
1726         (clobber (match_dup 4))])]
1727   ""
1728   [(set_attr "type"     "imadd")
1729    (set_attr "accum_in" "1")
1730    (set_attr "insn_count" "2")])
1732 ;; Patterns generated by the define_peephole2 below.
1734 (define_insn "*macc2"
1735   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1736         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1737                           (match_operand:SI 2 "register_operand" "d"))
1738                  (match_dup 0)))
1739    (set (match_operand:SI 3 "register_operand" "=d")
1740         (plus:SI (mult:SI (match_dup 1)
1741                           (match_dup 2))
1742                  (match_dup 0)))]
1743   "ISA_HAS_MACC && reload_completed"
1744   "macc\t%3,%1,%2"
1745   [(set_attr "type"     "imadd")
1746    (set_attr "accum_in" "0")
1747    (set_attr "mode"     "SI")])
1749 (define_insn "*msac2"
1750   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1751         (minus:SI (match_dup 0)
1752                   (mult:SI (match_operand:SI 1 "register_operand" "d")
1753                            (match_operand:SI 2 "register_operand" "d"))))
1754    (set (match_operand:SI 3 "register_operand" "=d")
1755         (minus:SI (match_dup 0)
1756                   (mult:SI (match_dup 1)
1757                            (match_dup 2))))]
1758   "ISA_HAS_MSAC && reload_completed"
1759   "msac\t%3,%1,%2"
1760   [(set_attr "type"     "imadd")
1761    (set_attr "accum_in" "0")
1762    (set_attr "mode"     "SI")])
1764 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1765 ;; Similarly msac.
1767 ;; Operand 0: LO
1768 ;; Operand 1: macc/msac
1769 ;; Operand 2: GPR (destination)
1770 (define_peephole2
1771   [(parallel
1772        [(set (match_operand:SI 0 "lo_operand")
1773              (match_operand:SI 1 "macc_msac_operand"))
1774         (clobber (scratch:SI))])
1775    (set (match_operand:SI 2 "d_operand")
1776         (match_dup 0))]
1777   ""
1778   [(parallel [(set (match_dup 0)
1779                    (match_dup 1))
1780               (set (match_dup 2)
1781                    (match_dup 1))])])
1783 ;; When we have a three-address multiplication instruction, it should
1784 ;; be faster to do a separate multiply and add, rather than moving
1785 ;; something into LO in order to use a macc instruction.
1787 ;; This peephole needs a scratch register to cater for the case when one
1788 ;; of the multiplication operands is the same as the destination.
1790 ;; Operand 0: GPR (scratch)
1791 ;; Operand 1: LO
1792 ;; Operand 2: GPR (addend)
1793 ;; Operand 3: GPR (destination)
1794 ;; Operand 4: macc/msac
1795 ;; Operand 5: new multiplication
1796 ;; Operand 6: new addition/subtraction
1797 (define_peephole2
1798   [(match_scratch:SI 0 "d")
1799    (set (match_operand:SI 1 "lo_operand")
1800         (match_operand:SI 2 "d_operand"))
1801    (match_dup 0)
1802    (parallel
1803        [(set (match_operand:SI 3 "d_operand")
1804              (match_operand:SI 4 "macc_msac_operand"))
1805         (clobber (match_dup 1))])]
1806   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1807   [(parallel [(set (match_dup 0)
1808                    (match_dup 5))
1809               (clobber (match_dup 1))])
1810    (set (match_dup 3)
1811         (match_dup 6))]
1813   operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1814   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1815                                 operands[2], operands[0]);
1818 ;; Same as above, except LO is the initial target of the macc.
1820 ;; Operand 0: GPR (scratch)
1821 ;; Operand 1: LO
1822 ;; Operand 2: GPR (addend)
1823 ;; Operand 3: macc/msac
1824 ;; Operand 4: GPR (destination)
1825 ;; Operand 5: new multiplication
1826 ;; Operand 6: new addition/subtraction
1827 (define_peephole2
1828   [(match_scratch:SI 0 "d")
1829    (set (match_operand:SI 1 "lo_operand")
1830         (match_operand:SI 2 "d_operand"))
1831    (match_dup 0)
1832    (parallel
1833        [(set (match_dup 1)
1834              (match_operand:SI 3 "macc_msac_operand"))
1835         (clobber (scratch:SI))])
1836    (match_dup 0)
1837    (set (match_operand:SI 4 "d_operand")
1838         (match_dup 1))]
1839   "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1840   [(parallel [(set (match_dup 0)
1841                    (match_dup 5))
1842               (clobber (match_dup 1))])
1843    (set (match_dup 4)
1844         (match_dup 6))]
1846   operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
1847   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
1848                                 operands[2], operands[0]);
1851 ;; See the comment above *mul_add_si for details.
1852 (define_insn "*mul_sub_si"
1853   [(set (match_operand:SI 0 "register_operand" "=l*?*?,d?")
1854         (minus:SI (match_operand:SI 1 "register_operand" "0,d")
1855                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1856                            (match_operand:SI 3 "register_operand" "d,d"))))
1857    (clobber (match_scratch:SI 4 "=X,l"))
1858    (clobber (match_scratch:SI 5 "=X,&d"))]
1859   "GENERATE_MADD_MSUB"
1860   "@
1861    msub\t%2,%3
1862    #"
1863   [(set_attr "type"     "imadd")
1864    (set_attr "accum_in" "1")
1865    (set_attr "mode"     "SI")
1866    (set_attr "insn_count" "1,2")])
1868 ;; Split *mul_sub_si if both the source and destination accumulator
1869 ;; values are GPRs.
1870 (define_split
1871   [(set (match_operand:SI 0 "d_operand")
1872         (minus:SI (match_operand:SI 1 "d_operand")
1873                   (mult:SI (match_operand:SI 2 "d_operand")
1874                            (match_operand:SI 3 "d_operand"))))
1875    (clobber (match_operand:SI 4 "lo_operand"))
1876    (clobber (match_operand:SI 5 "d_operand"))]
1877   "reload_completed"
1878   [(parallel [(set (match_dup 5)
1879                    (mult:SI (match_dup 2) (match_dup 3)))
1880               (clobber (match_dup 4))])
1881    (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
1882   "")
1884 (define_insn "*muls"
1885   [(set (match_operand:SI 0 "register_operand" "=l,d")
1886         (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1887                          (match_operand:SI 2 "register_operand" "d,d"))))
1888    (clobber (match_scratch:SI 3 "=X,l"))]
1889   "ISA_HAS_MULS"
1890   "@
1891    muls\t$0,%1,%2
1892    muls\t%0,%1,%2"
1893   [(set_attr "type"     "imul,imul3")
1894    (set_attr "mode"     "SI")])
1896 (define_expand "<u>mulsidi3"
1897   [(set (match_operand:DI 0 "register_operand")
1898         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1899                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1900   "mips_mulsidi3_gen_fn (<CODE>) != NULL"
1902   mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
1903   emit_insn (fn (operands[0], operands[1], operands[2]));
1904   DONE;
1907 (define_expand "<u>mulsidi3_32bit_mips16"
1908   [(set (match_operand:DI 0 "register_operand")
1909         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1910                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1911   "!TARGET_64BIT && TARGET_MIPS16"
1913   rtx hilo;
1915   hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
1916   emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
1917   emit_move_insn (operands[0], hilo);
1918   DONE;
1921 ;; As well as being named patterns, these instructions are used by the
1922 ;; __builtin_mips_mult<u>() functions.  We must always make those functions
1923 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
1924 (define_insn "<u>mulsidi3_32bit"
1925   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
1926         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1927                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
1928   "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP)"
1930   if (ISA_HAS_DSP_MULT)
1931     return "mult<u>\t%q0,%1,%2";
1932   else
1933     return "mult<u>\t%1,%2";
1935   [(set_attr "type" "imul")
1936    (set_attr "mode" "SI")])
1938 (define_insn "<u>mulsidi3_32bit_r4000"
1939   [(set (match_operand:DI 0 "register_operand" "=d")
1940         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1941                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1942    (clobber (match_scratch:DI 3 "=x"))]
1943   "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP"
1944   "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
1945   [(set_attr "type" "imul")
1946    (set_attr "mode" "SI")
1947    (set_attr "insn_count" "3")])
1949 (define_insn_and_split "<u>mulsidi3_64bit"
1950   [(set (match_operand:DI 0 "register_operand" "=d")
1951         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1952                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1953    (clobber (match_scratch:TI 3 "=x"))
1954    (clobber (match_scratch:DI 4 "=d"))]
1955   "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3 && !TARGET_MIPS16"
1956   "#"
1957   "&& reload_completed"
1958   [(const_int 0)]
1960   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
1961                                           operands[2], operands[4]));
1962   DONE;
1964   [(set_attr "type" "imul")
1965    (set_attr "mode" "SI")
1966    (set (attr "insn_count")
1967         (if_then_else (match_test "ISA_HAS_EXT_INS")
1968                       (const_int 4)
1969                       (const_int 7)))])
1971 (define_expand "<u>mulsidi3_64bit_mips16"
1972   [(set (match_operand:DI 0 "register_operand")
1973         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1974                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1975   "TARGET_64BIT && TARGET_MIPS16"
1977   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
1978                                           operands[2], gen_reg_rtx (DImode)));
1979   DONE;
1982 (define_expand "<u>mulsidi3_64bit_split"
1983   [(set (match_operand:DI 0 "register_operand")
1984         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1985                  (any_extend:DI (match_operand:SI 2 "register_operand"))))
1986    (clobber (match_operand:DI 3 "register_operand"))]
1987   ""
1989   rtx hilo;
1991   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
1992   emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
1994   emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
1995   emit_insn (gen_mfhidi_ti (operands[3], hilo));
1997   if (ISA_HAS_EXT_INS)
1998     emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
1999                            operands[3]));
2000   else
2001     {
2002       /* Zero-extend the low part.  */
2003       mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
2004       mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
2006       /* Shift the high part into place.  */
2007       mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
2009       /* OR the two halves together.  */
2010       mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
2011     }
2012   DONE;
2015 (define_insn "<u>mulsidi3_64bit_hilo"
2016   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2017         (unspec:TI
2018           [(mult:DI
2019              (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2020              (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
2021           UNSPEC_SET_HILO))]
2022   "TARGET_64BIT && !TARGET_FIX_R4000"
2023   "mult<u>\t%1,%2"
2024   [(set_attr "type" "imul")
2025    (set_attr "mode" "SI")])
2027 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
2028 (define_insn "mulsidi3_64bit_dmul"
2029   [(set (match_operand:DI 0 "register_operand" "=d")
2030         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2031                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2032    (clobber (match_scratch:DI 3 "=l"))]
2033   "ISA_HAS_DMUL3"
2034   "dmul\t%0,%1,%2"
2035   [(set_attr "type" "imul3")
2036    (set_attr "mode" "DI")])
2038 ;; Widening multiply with negation.
2039 (define_insn "*muls<u>_di"
2040   [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2041         (neg:DI
2042          (mult:DI
2043           (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2044           (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2045   "!TARGET_64BIT && ISA_HAS_MULS"
2046   "muls<u>\t$0,%1,%2"
2047   [(set_attr "type" "imul")
2048    (set_attr "mode" "SI")])
2050 ;; As well as being named patterns, these instructions are used by the
2051 ;; __builtin_mips_msub<u>() functions.  We must always make those functions
2052 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2054 ;; This leads to a slight inconsistency.  We honor any tuning overrides
2055 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2056 ;; even if !ISA_HAS_DSP_MULT.
2057 (define_insn "<u>msubsidi4"
2058   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2059         (minus:DI
2060            (match_operand:DI 3 "muldiv_target_operand" "0")
2061            (mult:DI
2062               (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2063               (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2064   "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2066   if (ISA_HAS_DSP_MULT)
2067     return "msub<u>\t%q0,%1,%2";
2068   else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2069     return "msub<u>\t%1,%2";
2070   else
2071     return "msac<u>\t$0,%1,%2";
2073   [(set_attr "type" "imadd")
2074    (set_attr "accum_in" "3")
2075    (set_attr "mode" "SI")])
2077 ;; _highpart patterns
2079 (define_expand "<su>mulsi3_highpart"
2080   [(set (match_operand:SI 0 "register_operand")
2081         (truncate:SI
2082          (lshiftrt:DI
2083           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2084                    (any_extend:DI (match_operand:SI 2 "register_operand")))
2085           (const_int 32))))]
2086   ""
2088   if (ISA_HAS_MULHI)
2089     emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2090                                                        operands[1],
2091                                                        operands[2]));
2092   else if (TARGET_MIPS16)
2093     emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2094                                               operands[2]));
2095   else
2096     emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2097                                                  operands[2]));
2098   DONE;
2101 (define_insn_and_split "<su>mulsi3_highpart_internal"
2102   [(set (match_operand:SI 0 "register_operand" "=d")
2103         (truncate:SI
2104          (lshiftrt:DI
2105           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2106                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2107           (const_int 32))))
2108    (clobber (match_scratch:SI 3 "=l"))]
2109   "!ISA_HAS_MULHI && !TARGET_MIPS16"
2110   { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2111   "&& reload_completed && !TARGET_FIX_R4000"
2112   [(const_int 0)]
2114   emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2115                                             operands[2]));
2116   DONE;
2118   [(set_attr "type" "imul")
2119    (set_attr "mode" "SI")
2120    (set_attr "insn_count" "2")])
2122 (define_expand "<su>mulsi3_highpart_split"
2123   [(set (match_operand:SI 0 "register_operand")
2124         (truncate:SI
2125          (lshiftrt:DI
2126           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2127                    (any_extend:DI (match_operand:SI 2 "register_operand")))
2128           (const_int 32))))]
2129   ""
2131   rtx hilo;
2133   if (TARGET_64BIT)
2134     {
2135       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2136       emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2137       emit_insn (gen_mfhisi_ti (operands[0], hilo));
2138     }
2139   else
2140     {
2141       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2142       emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2143       emit_insn (gen_mfhisi_di (operands[0], hilo));
2144     }
2145   DONE;
2148 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2149   [(set (match_operand:SI 0 "register_operand" "=d")
2150         (truncate:SI
2151          (lshiftrt:DI
2152           (mult:DI
2153            (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2154            (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2155           (const_int 32))))
2156    (clobber (match_scratch:SI 3 "=l"))]
2157   "ISA_HAS_MULHI"
2158   "mulhi<u>\t%0,%1,%2"
2159   [(set_attr "type" "imul3")
2160    (set_attr "mode" "SI")])
2162 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2163   [(set (match_operand:SI 0 "register_operand" "=d")
2164         (truncate:SI
2165          (lshiftrt:DI
2166           (neg:DI
2167            (mult:DI
2168             (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2169             (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2170           (const_int 32))))
2171    (clobber (match_scratch:SI 3 "=l"))]
2172   "ISA_HAS_MULHI"
2173   "mulshi<u>\t%0,%1,%2"
2174   [(set_attr "type" "imul3")
2175    (set_attr "mode" "SI")])
2177 ;; Disable unsigned multiplication for -mfix-vr4120.  This is for VR4120
2178 ;; errata MD(0), which says that dmultu does not always produce the
2179 ;; correct result.
2180 (define_expand "<su>muldi3_highpart"
2181   [(set (match_operand:DI 0 "register_operand")
2182         (truncate:DI
2183          (lshiftrt:TI
2184           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2185                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2186           (const_int 64))))]
2187   "ISA_HAS_DMULT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2189   if (TARGET_MIPS16)
2190     emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2191                                               operands[2]));
2192   else
2193     emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2194                                                  operands[2]));
2195   DONE;
2198 (define_insn_and_split "<su>muldi3_highpart_internal"
2199   [(set (match_operand:DI 0 "register_operand" "=d")
2200         (truncate:DI
2201          (lshiftrt:TI
2202           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2203                    (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2204           (const_int 64))))
2205    (clobber (match_scratch:DI 3 "=l"))]
2206   "ISA_HAS_DMULT
2207    && !TARGET_MIPS16
2208    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2209   { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2210   "&& reload_completed && !TARGET_FIX_R4000"
2211   [(const_int 0)]
2213   emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2214                                             operands[2]));
2215   DONE;
2217   [(set_attr "type" "imul")
2218    (set_attr "mode" "DI")
2219    (set_attr "insn_count" "2")])
2221 (define_expand "<su>muldi3_highpart_split"
2222   [(set (match_operand:DI 0 "register_operand")
2223         (truncate:DI
2224          (lshiftrt:TI
2225           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2226                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2227           (const_int 64))))]
2228   ""
2230   rtx hilo;
2232   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2233   emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2234   emit_insn (gen_mfhidi_ti (operands[0], hilo));
2235   DONE;
2238 (define_expand "<u>mulditi3"
2239   [(set (match_operand:TI 0 "register_operand")
2240         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2241                  (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2242   "ISA_HAS_DMULT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2244   rtx hilo;
2246   if (TARGET_MIPS16)
2247     {
2248       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2249       emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2250       emit_move_insn (operands[0], hilo);
2251     }
2252   else if (TARGET_FIX_R4000)
2253     emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2254   else
2255     emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2256                                          operands[2]));
2257   DONE;
2260 (define_insn "<u>mulditi3_internal"
2261   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2262         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2263                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2264   "ISA_HAS_DMULT
2265    && !TARGET_FIX_R4000
2266    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2267   "dmult<u>\t%1,%2"
2268   [(set_attr "type" "imul")
2269    (set_attr "mode" "DI")])
2271 (define_insn "<u>mulditi3_r4000"
2272   [(set (match_operand:TI 0 "register_operand" "=d")
2273         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2274                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2275    (clobber (match_scratch:TI 3 "=x"))]
2276   "ISA_HAS_DMULT
2277    && TARGET_FIX_R4000
2278    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2279   "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2280   [(set_attr "type" "imul")
2281    (set_attr "mode" "DI")
2282    (set_attr "insn_count" "3")])
2284 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2285 ;; instruction.  The HI/LO registers are used as a 64-bit accumulator.
2287 (define_insn "madsi"
2288   [(set (match_operand:SI 0 "register_operand" "+l")
2289         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2290                           (match_operand:SI 2 "register_operand" "d"))
2291                  (match_dup 0)))]
2292   "TARGET_MAD"
2293   "mad\t%1,%2"
2294   [(set_attr "type"     "imadd")
2295    (set_attr "accum_in" "0")
2296    (set_attr "mode"     "SI")])
2298 ;; See the comment above <u>msubsidi4 for the relationship between
2299 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2300 (define_insn "<u>maddsidi4"
2301   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2302         (plus:DI
2303          (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2304                   (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2305          (match_operand:DI 3 "muldiv_target_operand" "0")))]
2306   "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2307    && !TARGET_64BIT"
2309   if (TARGET_MAD)
2310     return "mad<u>\t%1,%2";
2311   else if (ISA_HAS_DSP_MULT)
2312     return "madd<u>\t%q0,%1,%2";
2313   else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2314     return "madd<u>\t%1,%2";
2315   else
2316     /* See comment in *macc.  */
2317     return "%[macc<u>\t%@,%1,%2%]";
2319   [(set_attr "type" "imadd")
2320    (set_attr "accum_in" "3")
2321    (set_attr "mode" "SI")])
2323 ;; Floating point multiply accumulate instructions.
2325 (define_insn "*madd4<mode>"
2326   [(set (match_operand:ANYF 0 "register_operand" "=f")
2327         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2328                               (match_operand:ANYF 2 "register_operand" "f"))
2329                    (match_operand:ANYF 3 "register_operand" "f")))]
2330   "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2331   "madd.<fmt>\t%0,%3,%1,%2"
2332   [(set_attr "type" "fmadd")
2333    (set_attr "accum_in" "3")
2334    (set_attr "mode" "<UNITMODE>")])
2336 (define_insn "*madd3<mode>"
2337   [(set (match_operand:ANYF 0 "register_operand" "=f")
2338         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2339                               (match_operand:ANYF 2 "register_operand" "f"))
2340                    (match_operand:ANYF 3 "register_operand" "0")))]
2341   "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2342   "madd.<fmt>\t%0,%1,%2"
2343   [(set_attr "type" "fmadd")
2344    (set_attr "accum_in" "3")
2345    (set_attr "mode" "<UNITMODE>")])
2347 (define_insn "*msub4<mode>"
2348   [(set (match_operand:ANYF 0 "register_operand" "=f")
2349         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2350                                (match_operand:ANYF 2 "register_operand" "f"))
2351                     (match_operand:ANYF 3 "register_operand" "f")))]
2352   "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2353   "msub.<fmt>\t%0,%3,%1,%2"
2354   [(set_attr "type" "fmadd")
2355    (set_attr "accum_in" "3")
2356    (set_attr "mode" "<UNITMODE>")])
2358 (define_insn "*msub3<mode>"
2359   [(set (match_operand:ANYF 0 "register_operand" "=f")
2360         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2361                                (match_operand:ANYF 2 "register_operand" "f"))
2362                     (match_operand:ANYF 3 "register_operand" "0")))]
2363   "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2364   "msub.<fmt>\t%0,%1,%2"
2365   [(set_attr "type" "fmadd")
2366    (set_attr "accum_in" "3")
2367    (set_attr "mode" "<UNITMODE>")])
2369 (define_insn "*nmadd4<mode>"
2370   [(set (match_operand:ANYF 0 "register_operand" "=f")
2371         (neg:ANYF (plus:ANYF
2372                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2373                               (match_operand:ANYF 2 "register_operand" "f"))
2374                    (match_operand:ANYF 3 "register_operand" "f"))))]
2375   "ISA_HAS_NMADD4_NMSUB4
2376    && TARGET_FUSED_MADD
2377    && HONOR_SIGNED_ZEROS (<MODE>mode)
2378    && !HONOR_NANS (<MODE>mode)"
2379   "nmadd.<fmt>\t%0,%3,%1,%2"
2380   [(set_attr "type" "fmadd")
2381    (set_attr "accum_in" "3")
2382    (set_attr "mode" "<UNITMODE>")])
2384 (define_insn "*nmadd3<mode>"
2385   [(set (match_operand:ANYF 0 "register_operand" "=f")
2386         (neg:ANYF (plus:ANYF
2387                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2388                               (match_operand:ANYF 2 "register_operand" "f"))
2389                    (match_operand:ANYF 3 "register_operand" "0"))))]
2390   "ISA_HAS_NMADD3_NMSUB3
2391    && TARGET_FUSED_MADD
2392    && HONOR_SIGNED_ZEROS (<MODE>mode)
2393    && !HONOR_NANS (<MODE>mode)"
2394   "nmadd.<fmt>\t%0,%1,%2"
2395   [(set_attr "type" "fmadd")
2396    (set_attr "accum_in" "3")
2397    (set_attr "mode" "<UNITMODE>")])
2399 (define_insn "*nmadd4<mode>_fastmath"
2400   [(set (match_operand:ANYF 0 "register_operand" "=f")
2401         (minus:ANYF
2402          (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2403                     (match_operand:ANYF 2 "register_operand" "f"))
2404          (match_operand:ANYF 3 "register_operand" "f")))]
2405   "ISA_HAS_NMADD4_NMSUB4
2406    && TARGET_FUSED_MADD
2407    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2408    && !HONOR_NANS (<MODE>mode)"
2409   "nmadd.<fmt>\t%0,%3,%1,%2"
2410   [(set_attr "type" "fmadd")
2411    (set_attr "accum_in" "3")
2412    (set_attr "mode" "<UNITMODE>")])
2414 (define_insn "*nmadd3<mode>_fastmath"
2415   [(set (match_operand:ANYF 0 "register_operand" "=f")
2416         (minus:ANYF
2417          (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2418                     (match_operand:ANYF 2 "register_operand" "f"))
2419          (match_operand:ANYF 3 "register_operand" "0")))]
2420   "ISA_HAS_NMADD3_NMSUB3
2421    && TARGET_FUSED_MADD
2422    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2423    && !HONOR_NANS (<MODE>mode)"
2424   "nmadd.<fmt>\t%0,%1,%2"
2425   [(set_attr "type" "fmadd")
2426    (set_attr "accum_in" "3")
2427    (set_attr "mode" "<UNITMODE>")])
2429 (define_insn "*nmsub4<mode>"
2430   [(set (match_operand:ANYF 0 "register_operand" "=f")
2431         (neg:ANYF (minus:ANYF
2432                    (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2433                               (match_operand:ANYF 3 "register_operand" "f"))
2434                    (match_operand:ANYF 1 "register_operand" "f"))))]
2435   "ISA_HAS_NMADD4_NMSUB4
2436    && TARGET_FUSED_MADD
2437    && HONOR_SIGNED_ZEROS (<MODE>mode)
2438    && !HONOR_NANS (<MODE>mode)"
2439   "nmsub.<fmt>\t%0,%1,%2,%3"
2440   [(set_attr "type" "fmadd")
2441    (set_attr "accum_in" "1")
2442    (set_attr "mode" "<UNITMODE>")])
2444 (define_insn "*nmsub3<mode>"
2445   [(set (match_operand:ANYF 0 "register_operand" "=f")
2446         (neg:ANYF (minus:ANYF
2447                    (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2448                               (match_operand:ANYF 3 "register_operand" "f"))
2449                    (match_operand:ANYF 1 "register_operand" "0"))))]
2450   "ISA_HAS_NMADD3_NMSUB3
2451    && TARGET_FUSED_MADD
2452    && HONOR_SIGNED_ZEROS (<MODE>mode)
2453    && !HONOR_NANS (<MODE>mode)"
2454   "nmsub.<fmt>\t%0,%1,%2"
2455   [(set_attr "type" "fmadd")
2456    (set_attr "accum_in" "1")
2457    (set_attr "mode" "<UNITMODE>")])
2459 (define_insn "*nmsub4<mode>_fastmath"
2460   [(set (match_operand:ANYF 0 "register_operand" "=f")
2461         (minus:ANYF
2462          (match_operand:ANYF 1 "register_operand" "f")
2463          (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2464                     (match_operand:ANYF 3 "register_operand" "f"))))]
2465   "ISA_HAS_NMADD4_NMSUB4
2466    && TARGET_FUSED_MADD
2467    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2468    && !HONOR_NANS (<MODE>mode)"
2469   "nmsub.<fmt>\t%0,%1,%2,%3"
2470   [(set_attr "type" "fmadd")
2471    (set_attr "accum_in" "1")
2472    (set_attr "mode" "<UNITMODE>")])
2474 (define_insn "*nmsub3<mode>_fastmath"
2475   [(set (match_operand:ANYF 0 "register_operand" "=f")
2476         (minus:ANYF
2477          (match_operand:ANYF 1 "register_operand" "f")
2478          (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2479                     (match_operand:ANYF 3 "register_operand" "0"))))]
2480   "ISA_HAS_NMADD3_NMSUB3
2481    && TARGET_FUSED_MADD
2482    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2483    && !HONOR_NANS (<MODE>mode)"
2484   "nmsub.<fmt>\t%0,%1,%2"
2485   [(set_attr "type" "fmadd")
2486    (set_attr "accum_in" "1")
2487    (set_attr "mode" "<UNITMODE>")])
2490 ;;  ....................
2492 ;;      DIVISION and REMAINDER
2494 ;;  ....................
2497 (define_expand "div<mode>3"
2498   [(set (match_operand:ANYF 0 "register_operand")
2499         (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2500                   (match_operand:ANYF 2 "register_operand")))]
2501   "<divide_condition>"
2503   if (const_1_operand (operands[1], <MODE>mode))
2504     if (!(<recip_condition> && flag_unsafe_math_optimizations))
2505       operands[1] = force_reg (<MODE>mode, operands[1]);
2508 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2510 ;; If an mfc1 or dmfc1 happens to access the floating point register
2511 ;; file at the same time a long latency operation (div, sqrt, recip,
2512 ;; sqrt) iterates an intermediate result back through the floating
2513 ;; point register file bypass, then instead returning the correct
2514 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2515 ;; result of the long latency operation.
2517 ;; The workaround is to insert an unconditional 'mov' from/to the
2518 ;; long latency op destination register.
2520 (define_insn "*div<mode>3"
2521   [(set (match_operand:ANYF 0 "register_operand" "=f")
2522         (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2523                   (match_operand:ANYF 2 "register_operand" "f")))]
2524   "<divide_condition>"
2526   if (TARGET_FIX_SB1)
2527     return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2528   else
2529     return "div.<fmt>\t%0,%1,%2";
2531   [(set_attr "type" "fdiv")
2532    (set_attr "mode" "<UNITMODE>")
2533    (set (attr "insn_count")
2534         (if_then_else (match_test "TARGET_FIX_SB1")
2535                       (const_int 2)
2536                       (const_int 1)))])
2538 (define_insn "*recip<mode>3"
2539   [(set (match_operand:ANYF 0 "register_operand" "=f")
2540         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2541                   (match_operand:ANYF 2 "register_operand" "f")))]
2542   "<recip_condition> && flag_unsafe_math_optimizations"
2544   if (TARGET_FIX_SB1)
2545     return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2546   else
2547     return "recip.<fmt>\t%0,%2";
2549   [(set_attr "type" "frdiv")
2550    (set_attr "mode" "<UNITMODE>")
2551    (set (attr "insn_count")
2552         (if_then_else (match_test "TARGET_FIX_SB1")
2553                       (const_int 2)
2554                       (const_int 1)))])
2556 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2557 ;; with negative operands.  We use special libgcc functions instead.
2559 ;; Expand generates divmod instructions for individual division and modulus
2560 ;; operations.  We then rely on CSE to reuse earlier divmods where possible.
2561 ;; This means that, when generating MIPS16 code, it is better not to expose
2562 ;; the fixed LO register until after CSE has finished.  However, it's still
2563 ;; better to split before register allocation, so that we don't allocate
2564 ;; one of the scarce MIPS16 registers to an unused result.
2565 (define_insn_and_split "divmod<mode>4"
2566   [(set (match_operand:GPR 0 "register_operand" "=kl")
2567         (div:GPR (match_operand:GPR 1 "register_operand" "d")
2568                  (match_operand:GPR 2 "register_operand" "d")))
2569    (set (match_operand:GPR 3 "register_operand" "=d")
2570         (mod:GPR (match_dup 1)
2571                  (match_dup 2)))]
2572   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2573   "#"
2574   "&& ((TARGET_MIPS16 && cse_not_expected) || reload_completed)"
2575   [(const_int 0)]
2577   emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2578   if (TARGET_MIPS16)
2579     emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, LO_REGNUM));
2580   DONE;
2582  [(set_attr "type" "idiv")
2583   (set_attr "mode" "<MODE>")
2584   ;; Worst case for MIPS16.
2585   (set_attr "insn_count" "3")])
2587 ;; See the comment above "divmod<mode>4" for the MIPS16 handling.
2588 (define_insn_and_split "udivmod<mode>4"
2589   [(set (match_operand:GPR 0 "register_operand" "=kl")
2590         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2591                   (match_operand:GPR 2 "register_operand" "d")))
2592    (set (match_operand:GPR 3 "register_operand" "=d")
2593         (umod:GPR (match_dup 1)
2594                   (match_dup 2)))]
2595   "ISA_HAS_<D>DIV"
2596   "#"
2597   "(TARGET_MIPS16 && cse_not_expected) || reload_completed"
2598   [(const_int 0)]
2600   emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2601   if (TARGET_MIPS16)
2602     emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, LO_REGNUM));
2603   DONE;
2605   [(set_attr "type" "idiv")
2606    (set_attr "mode" "<MODE>")
2607    ;; Worst case for MIPS16.
2608    (set_attr "insn_count" "3")])
2610 (define_expand "<u>divmod<mode>4_split"
2611   [(set (match_operand:GPR 0 "register_operand")
2612         (any_mod:GPR (match_operand:GPR 1 "register_operand")
2613                      (match_operand:GPR 2 "register_operand")))]
2614   ""
2616   rtx hilo;
2618   if (TARGET_64BIT)
2619     {
2620       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2621       emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
2622                                                operands[2]));
2623       emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
2624     }
2625   else
2626     {
2627       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2628       emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
2629                                                operands[2]));
2630       emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
2631     }
2632   DONE;
2635 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
2636   [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
2637         (unspec:HILO
2638           [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2639                         (match_operand:GPR 2 "register_operand" "d"))]
2640           UNSPEC_SET_HILO))]
2641   "ISA_HAS_<GPR:D>DIV"
2642   { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
2643   [(set_attr "type" "idiv")
2644    (set_attr "mode" "<GPR:MODE>")])
2647 ;;  ....................
2649 ;;      SQUARE ROOT
2651 ;;  ....................
2653 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
2654 ;; "*div[sd]f3" comment for details).
2656 (define_insn "sqrt<mode>2"
2657   [(set (match_operand:ANYF 0 "register_operand" "=f")
2658         (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2659   "<sqrt_condition>"
2661   if (TARGET_FIX_SB1)
2662     return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
2663   else
2664     return "sqrt.<fmt>\t%0,%1";
2666   [(set_attr "type" "fsqrt")
2667    (set_attr "mode" "<UNITMODE>")
2668    (set (attr "insn_count")
2669         (if_then_else (match_test "TARGET_FIX_SB1")
2670                       (const_int 2)
2671                       (const_int 1)))])
2673 (define_insn "*rsqrt<mode>a"
2674   [(set (match_operand:ANYF 0 "register_operand" "=f")
2675         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2676                   (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
2677   "<recip_condition> && flag_unsafe_math_optimizations"
2679   if (TARGET_FIX_SB1)
2680     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2681   else
2682     return "rsqrt.<fmt>\t%0,%2";
2684   [(set_attr "type" "frsqrt")
2685    (set_attr "mode" "<UNITMODE>")
2686    (set (attr "insn_count")
2687         (if_then_else (match_test "TARGET_FIX_SB1")
2688                       (const_int 2)
2689                       (const_int 1)))])
2691 (define_insn "*rsqrt<mode>b"
2692   [(set (match_operand:ANYF 0 "register_operand" "=f")
2693         (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2694                              (match_operand:ANYF 2 "register_operand" "f"))))]
2695   "<recip_condition> && flag_unsafe_math_optimizations"
2697   if (TARGET_FIX_SB1)
2698     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2699   else
2700     return "rsqrt.<fmt>\t%0,%2";
2702   [(set_attr "type" "frsqrt")
2703    (set_attr "mode" "<UNITMODE>")
2704    (set (attr "insn_count")
2705         (if_then_else (match_test "TARGET_FIX_SB1")
2706                       (const_int 2)
2707                       (const_int 1)))])
2710 ;;  ....................
2712 ;;      ABSOLUTE VALUE
2714 ;;  ....................
2716 ;; Do not use the integer abs macro instruction, since that signals an
2717 ;; exception on -2147483648 (sigh).
2719 ;; The "legacy" (as opposed to "2008") form of ABS.fmt is an arithmetic
2720 ;; instruction that treats all NaN inputs as invalid; it does not clear
2721 ;; their sign bit.  We therefore can't use that form if the signs of
2722 ;; NaNs matter.
2724 (define_insn "abs<mode>2"
2725   [(set (match_operand:ANYF 0 "register_operand" "=f")
2726         (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2727   "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
2728   "abs.<fmt>\t%0,%1"
2729   [(set_attr "type" "fabs")
2730    (set_attr "mode" "<UNITMODE>")])
2733 ;;  ...................
2735 ;;  Count leading zeroes.
2737 ;;  ...................
2740 (define_insn "clz<mode>2"
2741   [(set (match_operand:GPR 0 "register_operand" "=d")
2742         (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
2743   "ISA_HAS_CLZ_CLO"
2744   "<d>clz\t%0,%1"
2745   [(set_attr "type" "clz")
2746    (set_attr "mode" "<MODE>")])
2749 ;;  ...................
2751 ;;  Count number of set bits.
2753 ;;  ...................
2756 (define_insn "popcount<mode>2"
2757   [(set (match_operand:GPR 0 "register_operand" "=d")
2758         (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
2759   "ISA_HAS_POP"
2760   "<d>pop\t%0,%1"
2761   [(set_attr "type" "pop")
2762    (set_attr "mode" "<MODE>")])
2764 ;; The POP instruction is special as it does not take into account the upper
2765 ;; 32bits and is documented that way.
2766 (define_insn "*popcountdi2_trunc"
2767   [(set (match_operand:SI 0 "register_operand" "=d")
2768        (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
2769   "ISA_HAS_POP && TARGET_64BIT"
2770   "pop\t%0,%1"
2771   [(set_attr "type" "pop")
2772    (set_attr "mode" "SI")])
2775 ;;  ....................
2777 ;;      NEGATION and ONE'S COMPLEMENT
2779 ;;  ....................
2781 (define_insn "negsi2"
2782   [(set (match_operand:SI 0 "register_operand" "=d")
2783         (neg:SI (match_operand:SI 1 "register_operand" "d")))]
2784   ""
2786   if (TARGET_MIPS16)
2787     return "neg\t%0,%1";
2788   else
2789     return "subu\t%0,%.,%1";
2791   [(set_attr "alu_type" "sub")
2792    (set_attr "mode"     "SI")])
2794 (define_insn "negdi2"
2795   [(set (match_operand:DI 0 "register_operand" "=d")
2796         (neg:DI (match_operand:DI 1 "register_operand" "d")))]
2797   "TARGET_64BIT && !TARGET_MIPS16"
2798   "dsubu\t%0,%.,%1"
2799   [(set_attr "alu_type" "sub")
2800    (set_attr "mode"     "DI")])
2802 ;; The "legacy" (as opposed to "2008") form of NEG.fmt is an arithmetic
2803 ;; instruction that treats all NaN inputs as invalid; it does not flip
2804 ;; their sign bit.  We therefore can't use that form if the signs of
2805 ;; NaNs matter.
2807 (define_insn "neg<mode>2"
2808   [(set (match_operand:ANYF 0 "register_operand" "=f")
2809         (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2810   "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
2811   "neg.<fmt>\t%0,%1"
2812   [(set_attr "type" "fneg")
2813    (set_attr "mode" "<UNITMODE>")])
2815 (define_insn "one_cmpl<mode>2"
2816   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
2817         (not:GPR (match_operand:GPR 1 "register_operand" "!u,d")))]
2818   ""
2820   if (TARGET_MIPS16)
2821     return "not\t%0,%1";
2822   else
2823     return "nor\t%0,%.,%1";
2825   [(set_attr "alu_type" "not")
2826    (set_attr "compression" "micromips,*")
2827    (set_attr "mode" "<MODE>")])
2830 ;;  ....................
2832 ;;      LOGICAL
2834 ;;  ....................
2837 ;; Many of these instructions use trivial define_expands, because we
2838 ;; want to use a different set of constraints when TARGET_MIPS16.
2840 (define_expand "and<mode>3"
2841   [(set (match_operand:GPR 0 "register_operand")
2842         (and:GPR (match_operand:GPR 1 "register_operand")
2843                  (match_operand:GPR 2 "and_reg_operand")))])
2845 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
2846 ;; zero_extendsidi2 because of TRULY_NOOP_TRUNCATION, so handle these here.
2847 ;; Note that this variant does not trigger for SI mode because we require
2848 ;; a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
2849 ;; sign-extended SImode value.
2851 ;; These are possible combinations for operand 1 and 2.  The table
2852 ;; includes both MIPS and MIPS16 cases.  (r=register, mem=memory,
2853 ;; 16=MIPS16, x=match, S=split):
2855 ;;     \ op1    r/EXT   r/!EXT  mem   r/16   mem/16
2856 ;;  op2
2858 ;;  andi           x     x
2859 ;;  0xff           x     x       x             x
2860 ;;  0xffff         x     x       x             x
2861 ;;  0xffff_ffff    x     S       x     S       x
2862 ;;  low-bitmask    x
2863 ;;  register       x     x
2864 ;;  register =op1                      x
2866 (define_insn "*and<mode>3"
2867   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,!u,d,d,d,!u,d")
2868         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,!u,d,d,d,0,d")
2869                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Uean,K,Yx,Yw,!u,d")))]
2870   "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
2872   int len;
2874   switch (which_alternative)
2875     {
2876     case 0:
2877       operands[1] = gen_lowpart (QImode, operands[1]);
2878       return "lbu\t%0,%1";
2879     case 1:
2880       operands[1] = gen_lowpart (HImode, operands[1]);
2881       return "lhu\t%0,%1";
2882     case 2:
2883       operands[1] = gen_lowpart (SImode, operands[1]);
2884       return "lwu\t%0,%1";
2885     case 3:
2886     case 4:
2887       return "andi\t%0,%1,%x2";
2888     case 5:
2889       len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
2890       operands[2] = GEN_INT (len);
2891       return "<d>ext\t%0,%1,0,%2";
2892     case 6:
2893       return "#";
2894     case 7:
2895     case 8:
2896       return "and\t%0,%1,%2";
2897     default:
2898       gcc_unreachable ();
2899     }
2901   [(set_attr "move_type" "load,load,load,andi,andi,ext_ins,shift_shift,logical,logical")
2902    (set_attr "compression" "*,*,*,micromips,*,*,*,micromips,*")
2903    (set_attr "mode" "<MODE>")])
2905 (define_insn "*and<mode>3_mips16"
2906   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
2907         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%W,W,W,d,0")
2908                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
2909   "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
2911   switch (which_alternative)
2912     {
2913     case 0:
2914       operands[1] = gen_lowpart (QImode, operands[1]);
2915       return "lbu\t%0,%1";
2916     case 1:
2917       operands[1] = gen_lowpart (HImode, operands[1]);
2918       return "lhu\t%0,%1";
2919     case 2:
2920       operands[1] = gen_lowpart (SImode, operands[1]);
2921       return "lwu\t%0,%1";
2922     case 3:
2923       return "#";
2924     case 4:
2925       return "and\t%0,%2";
2926     default:
2927       gcc_unreachable ();
2928     }
2930   [(set_attr "move_type" "load,load,load,shift_shift,logical")
2931    (set_attr "mode" "<MODE>")])
2933 (define_expand "ior<mode>3"
2934   [(set (match_operand:GPR 0 "register_operand")
2935         (ior:GPR (match_operand:GPR 1 "register_operand")
2936                  (match_operand:GPR 2 "uns_arith_operand")))]
2937   ""
2939   if (TARGET_MIPS16)
2940     operands[2] = force_reg (<MODE>mode, operands[2]);
2943 (define_insn "*ior<mode>3"
2944   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
2945         (ior:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
2946                  (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
2947   "!TARGET_MIPS16"
2948   "@
2949    or\t%0,%1,%2
2950    or\t%0,%1,%2
2951    ori\t%0,%1,%x2"
2952   [(set_attr "alu_type" "or")
2953    (set_attr "compression" "micromips,*,*")
2954    (set_attr "mode" "<MODE>")])
2956 (define_insn "*ior<mode>3_mips16"
2957   [(set (match_operand:GPR 0 "register_operand" "=d")
2958         (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
2959                  (match_operand:GPR 2 "register_operand" "d")))]
2960   "TARGET_MIPS16"
2961   "or\t%0,%2"
2962   [(set_attr "alu_type" "or")
2963    (set_attr "mode" "<MODE>")])
2965 (define_expand "xor<mode>3"
2966   [(set (match_operand:GPR 0 "register_operand")
2967         (xor:GPR (match_operand:GPR 1 "register_operand")
2968                  (match_operand:GPR 2 "uns_arith_operand")))]
2969   ""
2970   "")
2972 (define_insn "*xor<mode>3"
2973   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
2974         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
2975                  (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
2976   "!TARGET_MIPS16"
2977   "@
2978    xor\t%0,%1,%2
2979    xor\t%0,%1,%2
2980    xori\t%0,%1,%x2"
2981   [(set_attr "alu_type" "xor")
2982    (set_attr "compression" "micromips,*,*")
2983    (set_attr "mode" "<MODE>")])
2985 (define_insn "*xor<mode>3_mips16"
2986   [(set (match_operand:GPR 0 "register_operand" "=d,t,t,t")
2987         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d,d")
2988                  (match_operand:GPR 2 "uns_arith_operand" "d,Uub8,K,d")))]
2989   "TARGET_MIPS16"
2990   "@
2991    xor\t%0,%2
2992    cmpi\t%1,%2
2993    cmpi\t%1,%2
2994    cmp\t%1,%2"
2995   [(set_attr "alu_type" "xor")
2996    (set_attr "mode" "<MODE>")
2997    (set_attr "extended_mips16" "no,no,yes,no")])
2999 (define_insn "*nor<mode>3"
3000   [(set (match_operand:GPR 0 "register_operand" "=d")
3001         (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
3002                  (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
3003   "!TARGET_MIPS16"
3004   "nor\t%0,%1,%2"
3005   [(set_attr "alu_type" "nor")
3006    (set_attr "mode" "<MODE>")])
3009 ;;  ....................
3011 ;;      TRUNCATION
3013 ;;  ....................
3017 (define_insn "truncdfsf2"
3018   [(set (match_operand:SF 0 "register_operand" "=f")
3019         (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3020   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3021   "cvt.s.d\t%0,%1"
3022   [(set_attr "type"     "fcvt")
3023    (set_attr "cnv_mode" "D2S")   
3024    (set_attr "mode"     "SF")])
3026 ;; Integer truncation patterns.  Truncating SImode values to smaller
3027 ;; modes is a no-op, as it is for most other GCC ports.  Truncating
3028 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3029 ;; need to make sure that the lower 32 bits are properly sign-extended
3030 ;; (see TRULY_NOOP_TRUNCATION).  Truncating DImode values into modes
3031 ;; smaller than SImode is equivalent to two separate truncations:
3033 ;;                        A       B
3034 ;;    DI ---> HI  ==  DI ---> SI ---> HI
3035 ;;    DI ---> QI  ==  DI ---> SI ---> QI
3037 ;; Step A needs a real instruction but step B does not.
3039 (define_insn "truncdi<mode>2"
3040   [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3041         (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3042   "TARGET_64BIT"
3043   "@
3044     sll\t%0,%1,0
3045     <store>\t%1,%0"
3046   [(set_attr "move_type" "sll0,store")
3047    (set_attr "mode" "SI")])
3049 ;; Combiner patterns to optimize shift/truncate combinations.
3051 (define_insn "*ashr_trunc<mode>"
3052   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3053         (truncate:SUBDI
3054           (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3055                        (match_operand:DI 2 "const_arith_operand" ""))))]
3056   "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3057   "dsra\t%0,%1,%2"
3058   [(set_attr "type" "shift")
3059    (set_attr "mode" "<MODE>")])
3061 (define_insn "*lshr32_trunc<mode>"
3062   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3063         (truncate:SUBDI
3064           (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3065                        (const_int 32))))]
3066   "TARGET_64BIT && !TARGET_MIPS16"
3067   "dsra\t%0,%1,32"
3068   [(set_attr "type" "shift")
3069    (set_attr "mode" "<MODE>")])
3071 ;; Logical shift by more than 32 results in proper SI values so truncation is
3072 ;; removed by the middle end.  Note that a logical shift by 32 is handled by
3073 ;; the previous pattern.
3074 (define_insn "*<optab>_trunc<mode>_exts"
3075   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3076         (truncate:SUBDI
3077          (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3078                          (match_operand:DI 2 "const_arith_operand" ""))))]
3079   "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3080   "exts\t%0,%1,%2,31"
3081   [(set_attr "type" "arith")
3082    (set_attr "mode" "<MODE>")])
3085 ;;  ....................
3087 ;;      ZERO EXTENSION
3089 ;;  ....................
3091 ;; Extension insns.
3093 (define_expand "zero_extendsidi2"
3094   [(set (match_operand:DI 0 "register_operand")
3095         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3096   "TARGET_64BIT")
3098 (define_insn_and_split "*zero_extendsidi2"
3099   [(set (match_operand:DI 0 "register_operand" "=d,d")
3100         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3101   "TARGET_64BIT && !ISA_HAS_EXT_INS"
3102   "@
3103    #
3104    lwu\t%0,%1"
3105   "&& reload_completed && REG_P (operands[1])"
3106   [(set (match_dup 0)
3107         (ashift:DI (match_dup 1) (const_int 32)))
3108    (set (match_dup 0)
3109         (lshiftrt:DI (match_dup 0) (const_int 32)))]
3110   { operands[1] = gen_lowpart (DImode, operands[1]); }
3111   [(set_attr "move_type" "shift_shift,load")
3112    (set_attr "mode" "DI")])
3114 (define_insn "*zero_extendsidi2_dext"
3115   [(set (match_operand:DI 0 "register_operand" "=d,d")
3116         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3117   "TARGET_64BIT && ISA_HAS_EXT_INS"
3118   "@
3119    dext\t%0,%1,0,32
3120    lwu\t%0,%1"
3121   [(set_attr "move_type" "arith,load")
3122    (set_attr "mode" "DI")])
3124 ;; See the comment before the *and<mode>3 pattern why this is generated by
3125 ;; combine.
3127 (define_split
3128   [(set (match_operand:DI 0 "register_operand")
3129         (and:DI (match_operand:DI 1 "register_operand")
3130                 (const_int 4294967295)))]
3131   "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3132   [(set (match_dup 0)
3133         (ashift:DI (match_dup 1) (const_int 32)))
3134    (set (match_dup 0)
3135         (lshiftrt:DI (match_dup 0) (const_int 32)))])
3137 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3138   [(set (match_operand:GPR 0 "register_operand")
3139         (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3140   ""
3142   if (TARGET_MIPS16 && !GENERATE_MIPS16E
3143       && !memory_operand (operands[1], <SHORT:MODE>mode))
3144     {
3145       emit_insn (gen_and<GPR:mode>3 (operands[0],
3146                                      gen_lowpart (<GPR:MODE>mode, operands[1]),
3147                                      force_reg (<GPR:MODE>mode,
3148                                                 GEN_INT (<SHORT:mask>))));
3149       DONE;
3150     }
3153 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3154   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3155         (zero_extend:GPR
3156              (match_operand:SHORT 1 "nonimmediate_operand" "!u,d,m")))]
3157   "!TARGET_MIPS16"
3158   "@
3159    andi\t%0,%1,<SHORT:mask>
3160    andi\t%0,%1,<SHORT:mask>
3161    l<SHORT:size>u\t%0,%1"
3162   [(set_attr "move_type" "andi,andi,load")
3163    (set_attr "compression" "micromips,*,*")
3164    (set_attr "mode" "<GPR:MODE>")])
3166 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3167   [(set (match_operand:GPR 0 "register_operand" "=d")
3168         (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3169   "GENERATE_MIPS16E"
3170   "ze<SHORT:size>\t%0"
3171   ;; This instruction is effectively a special encoding of ANDI.
3172   [(set_attr "move_type" "andi")
3173    (set_attr "mode" "<GPR:MODE>")])
3175 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3176   [(set (match_operand:GPR 0 "register_operand" "=d")
3177         (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3178   "TARGET_MIPS16"
3179   "l<SHORT:size>u\t%0,%1"
3180   [(set_attr "move_type" "load")
3181    (set_attr "mode" "<GPR:MODE>")])
3183 (define_expand "zero_extendqihi2"
3184   [(set (match_operand:HI 0 "register_operand")
3185         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3186   ""
3188   if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3189     {
3190       emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3191                                        operands[1]));
3192       DONE;
3193     }
3196 (define_insn "*zero_extendqihi2"
3197   [(set (match_operand:HI 0 "register_operand" "=d,d")
3198         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3199   "!TARGET_MIPS16"
3200   "@
3201    andi\t%0,%1,0x00ff
3202    lbu\t%0,%1"
3203   [(set_attr "move_type" "andi,load")
3204    (set_attr "mode" "HI")])
3206 (define_insn "*zero_extendqihi2_mips16"
3207   [(set (match_operand:HI 0 "register_operand" "=d")
3208         (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3209   "TARGET_MIPS16"
3210   "lbu\t%0,%1"
3211   [(set_attr "move_type" "load")
3212    (set_attr "mode" "HI")])
3214 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3216 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3217   [(set (match_operand:GPR 0 "register_operand" "=d")
3218         (zero_extend:GPR
3219             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3220   "TARGET_64BIT && !TARGET_MIPS16"
3222   operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3223   return "andi\t%0,%1,%x2";
3225   [(set_attr "alu_type" "and")
3226    (set_attr "mode" "<GPR:MODE>")])
3228 (define_insn "*zero_extendhi_truncqi"
3229   [(set (match_operand:HI 0 "register_operand" "=d")
3230         (zero_extend:HI
3231             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3232   "TARGET_64BIT && !TARGET_MIPS16"
3233   "andi\t%0,%1,0xff"
3234   [(set_attr "alu_type" "and")
3235    (set_attr "mode" "HI")])
3238 ;;  ....................
3240 ;;      SIGN EXTENSION
3242 ;;  ....................
3244 ;; Extension insns.
3245 ;; Those for integer source operand are ordered widest source type first.
3247 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3248 ;; should already be in sign-extended form (see TRULY_NOOP_TRUNCATION
3249 ;; and truncdisi2).  We can therefore get rid of register->register
3250 ;; instructions if we constrain the source to be in the same register as
3251 ;; the destination.
3253 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3254 ;; we split them into nothing before the post-reload scheduler runs.
3255 ;; These alternatives therefore have type "move" in order to reflect
3256 ;; what happens if the two pre-reload operands cannot be tied, and are
3257 ;; instead allocated two separate GPRs.  We don't distinguish between
3258 ;; the GPR and LO cases because we don't usually know during pre-reload
3259 ;; scheduling whether an operand will be LO or not.
3260 (define_insn_and_split "extendsidi2"
3261   [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3262         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3263   "TARGET_64BIT"
3264   "@
3265    #
3266    #
3267    lw\t%0,%1"
3268   "&& reload_completed && register_operand (operands[1], VOIDmode)"
3269   [(const_int 0)]
3271   emit_note (NOTE_INSN_DELETED);
3272   DONE;
3274   [(set_attr "move_type" "move,move,load")
3275    (set_attr "mode" "DI")])
3277 (define_expand "extend<SHORT:mode><GPR:mode>2"
3278   [(set (match_operand:GPR 0 "register_operand")
3279         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3280   "")
3282 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3283   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3284         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3285   "GENERATE_MIPS16E"
3286   "@
3287    se<SHORT:size>\t%0
3288    l<SHORT:size>\t%0,%1"
3289   [(set_attr "move_type" "signext,load")
3290    (set_attr "mode" "<GPR:MODE>")])
3292 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3293   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3294         (sign_extend:GPR
3295              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3296   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3297   "@
3298    #
3299    l<SHORT:size>\t%0,%1"
3300   "&& reload_completed && REG_P (operands[1])"
3301   [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3302    (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3304   operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3305   operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3306                          - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3308   [(set_attr "move_type" "shift_shift,load")
3309    (set_attr "mode" "<GPR:MODE>")])
3311 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3312   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3313         (sign_extend:GPR
3314              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3315   "ISA_HAS_SEB_SEH"
3316   "@
3317    se<SHORT:size>\t%0,%1
3318    l<SHORT:size>\t%0,%1"
3319   [(set_attr "move_type" "signext,load")
3320    (set_attr "mode" "<GPR:MODE>")])
3322 (define_expand "extendqihi2"
3323   [(set (match_operand:HI 0 "register_operand")
3324         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3325   "")
3327 (define_insn "*extendqihi2_mips16e"
3328   [(set (match_operand:HI 0 "register_operand" "=d,d")
3329         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3330   "GENERATE_MIPS16E"
3331   "@
3332    seb\t%0
3333    lb\t%0,%1"
3334   [(set_attr "move_type" "signext,load")
3335    (set_attr "mode" "SI")])
3337 (define_insn_and_split "*extendqihi2"
3338   [(set (match_operand:HI 0 "register_operand" "=d,d")
3339         (sign_extend:HI
3340              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3341   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3342   "@
3343    #
3344    lb\t%0,%1"
3345   "&& reload_completed && REG_P (operands[1])"
3346   [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3347    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3349   operands[0] = gen_lowpart (SImode, operands[0]);
3350   operands[1] = gen_lowpart (SImode, operands[1]);
3351   operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3352                          - GET_MODE_BITSIZE (QImode));
3354   [(set_attr "move_type" "shift_shift,load")
3355    (set_attr "mode" "SI")])
3357 (define_insn "*extendqihi2_seb"
3358   [(set (match_operand:HI 0 "register_operand" "=d,d")
3359         (sign_extend:HI
3360              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3361   "ISA_HAS_SEB_SEH"
3362   "@
3363    seb\t%0,%1
3364    lb\t%0,%1"
3365   [(set_attr "move_type" "signext,load")
3366    (set_attr "mode" "SI")])
3368 ;; Combiner patterns for truncate/sign_extend combinations.  The SI versions
3369 ;; use the shift/truncate patterns.
3371 (define_insn_and_split "*extenddi_truncate<mode>"
3372   [(set (match_operand:DI 0 "register_operand" "=d")
3373         (sign_extend:DI
3374             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3375   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3376   "#"
3377   "&& reload_completed"
3378   [(set (match_dup 2)
3379         (ashift:DI (match_dup 1)
3380                    (match_dup 3)))
3381    (set (match_dup 0)
3382         (ashiftrt:DI (match_dup 2)
3383                      (match_dup 3)))]
3385   operands[2] = gen_lowpart (DImode, operands[0]);
3386   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3388   [(set_attr "move_type" "shift_shift")
3389    (set_attr "mode" "DI")])
3391 (define_insn_and_split "*extendsi_truncate<mode>"
3392   [(set (match_operand:SI 0 "register_operand" "=d")
3393         (sign_extend:SI
3394             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3395   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3396   "#"
3397   "&& reload_completed"
3398   [(set (match_dup 2)
3399         (ashift:DI (match_dup 1)
3400                    (match_dup 3)))
3401    (set (match_dup 0)
3402         (truncate:SI (ashiftrt:DI (match_dup 2)
3403                                   (match_dup 3))))]
3405   operands[2] = gen_lowpart (DImode, operands[0]);
3406   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3408   [(set_attr "move_type" "shift_shift")
3409    (set_attr "mode" "SI")])
3411 (define_insn_and_split "*extendhi_truncateqi"
3412   [(set (match_operand:HI 0 "register_operand" "=d")
3413         (sign_extend:HI
3414             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3415   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3416   "#"
3417   "&& reload_completed"
3418   [(set (match_dup 2)
3419         (ashift:DI (match_dup 1)
3420                    (const_int 56)))
3421    (set (match_dup 0)
3422         (truncate:HI (ashiftrt:DI (match_dup 2)
3423                                   (const_int 56))))]
3425   operands[2] = gen_lowpart (DImode, operands[0]);
3427   [(set_attr "move_type" "shift_shift")
3428    (set_attr "mode" "SI")])
3430 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3431   [(set (match_operand:GPR 0 "register_operand" "=d")
3432         (sign_extend:GPR
3433             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3434   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3436   operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3437   return "exts\t%0,%1,0,%m2";
3439   [(set_attr "type" "arith")
3440    (set_attr "mode" "<GPR:MODE>")])
3442 (define_insn "*extendhi_truncateqi_exts"
3443   [(set (match_operand:HI 0 "register_operand" "=d")
3444         (sign_extend:HI
3445             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3446   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3447   "exts\t%0,%1,0,7"
3448   [(set_attr "type" "arith")
3449    (set_attr "mode" "SI")])
3451 (define_insn "extendsfdf2"
3452   [(set (match_operand:DF 0 "register_operand" "=f")
3453         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3454   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3455   "cvt.d.s\t%0,%1"
3456   [(set_attr "type"     "fcvt")
3457    (set_attr "cnv_mode" "S2D")   
3458    (set_attr "mode"     "DF")])
3461 ;;  ....................
3463 ;;      CONVERSIONS
3465 ;;  ....................
3467 (define_expand "fix_truncdfsi2"
3468   [(set (match_operand:SI 0 "register_operand")
3469         (fix:SI (match_operand:DF 1 "register_operand")))]
3470   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3472   if (!ISA_HAS_TRUNC_W)
3473     {
3474       emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3475       DONE;
3476     }
3479 (define_insn "fix_truncdfsi2_insn"
3480   [(set (match_operand:SI 0 "register_operand" "=f")
3481         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3482   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3483   "trunc.w.d %0,%1"
3484   [(set_attr "type"     "fcvt")
3485    (set_attr "mode"     "DF")
3486    (set_attr "cnv_mode" "D2I")])
3488 (define_insn "fix_truncdfsi2_macro"
3489   [(set (match_operand:SI 0 "register_operand" "=f")
3490         (fix:SI (match_operand:DF 1 "register_operand" "f")))
3491    (clobber (match_scratch:DF 2 "=d"))]
3492   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3494   if (mips_nomacro.nesting_level > 0)
3495     return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3496   else
3497     return "trunc.w.d %0,%1,%2";
3499   [(set_attr "type"     "fcvt")
3500    (set_attr "mode"     "DF")
3501    (set_attr "cnv_mode" "D2I")
3502    (set_attr "insn_count" "9")])
3504 (define_expand "fix_truncsfsi2"
3505   [(set (match_operand:SI 0 "register_operand")
3506         (fix:SI (match_operand:SF 1 "register_operand")))]
3507   "TARGET_HARD_FLOAT"
3509   if (!ISA_HAS_TRUNC_W)
3510     {
3511       emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3512       DONE;
3513     }
3516 (define_insn "fix_truncsfsi2_insn"
3517   [(set (match_operand:SI 0 "register_operand" "=f")
3518         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3519   "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3520   "trunc.w.s %0,%1"
3521   [(set_attr "type"     "fcvt")
3522    (set_attr "mode"     "SF")
3523    (set_attr "cnv_mode" "S2I")])
3525 (define_insn "fix_truncsfsi2_macro"
3526   [(set (match_operand:SI 0 "register_operand" "=f")
3527         (fix:SI (match_operand:SF 1 "register_operand" "f")))
3528    (clobber (match_scratch:SF 2 "=d"))]
3529   "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
3531   if (mips_nomacro.nesting_level > 0)
3532     return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
3533   else
3534     return "trunc.w.s %0,%1,%2";
3536   [(set_attr "type"     "fcvt")
3537    (set_attr "mode"     "SF")
3538    (set_attr "cnv_mode" "S2I")
3539    (set_attr "insn_count" "9")])
3542 (define_insn "fix_truncdfdi2"
3543   [(set (match_operand:DI 0 "register_operand" "=f")
3544         (fix:DI (match_operand:DF 1 "register_operand" "f")))]
3545   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3546   "trunc.l.d %0,%1"
3547   [(set_attr "type"     "fcvt")
3548    (set_attr "mode"     "DF")
3549    (set_attr "cnv_mode" "D2I")])
3552 (define_insn "fix_truncsfdi2"
3553   [(set (match_operand:DI 0 "register_operand" "=f")
3554         (fix:DI (match_operand:SF 1 "register_operand" "f")))]
3555   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3556   "trunc.l.s %0,%1"
3557   [(set_attr "type"     "fcvt")
3558    (set_attr "mode"     "SF")
3559    (set_attr "cnv_mode" "S2I")])
3562 (define_insn "floatsidf2"
3563   [(set (match_operand:DF 0 "register_operand" "=f")
3564         (float:DF (match_operand:SI 1 "register_operand" "f")))]
3565   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3566   "cvt.d.w\t%0,%1"
3567   [(set_attr "type"     "fcvt")
3568    (set_attr "mode"     "DF")
3569    (set_attr "cnv_mode" "I2D")])
3572 (define_insn "floatdidf2"
3573   [(set (match_operand:DF 0 "register_operand" "=f")
3574         (float:DF (match_operand:DI 1 "register_operand" "f")))]
3575   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3576   "cvt.d.l\t%0,%1"
3577   [(set_attr "type"     "fcvt")
3578    (set_attr "mode"     "DF")
3579    (set_attr "cnv_mode" "I2D")])
3582 (define_insn "floatsisf2"
3583   [(set (match_operand:SF 0 "register_operand" "=f")
3584         (float:SF (match_operand:SI 1 "register_operand" "f")))]
3585   "TARGET_HARD_FLOAT"
3586   "cvt.s.w\t%0,%1"
3587   [(set_attr "type"     "fcvt")
3588    (set_attr "mode"     "SF")
3589    (set_attr "cnv_mode" "I2S")])
3592 (define_insn "floatdisf2"
3593   [(set (match_operand:SF 0 "register_operand" "=f")
3594         (float:SF (match_operand:DI 1 "register_operand" "f")))]
3595   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3596   "cvt.s.l\t%0,%1"
3597   [(set_attr "type"     "fcvt")
3598    (set_attr "mode"     "SF")
3599    (set_attr "cnv_mode" "I2S")])
3602 (define_expand "fixuns_truncdfsi2"
3603   [(set (match_operand:SI 0 "register_operand")
3604         (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
3605   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3607   rtx reg1 = gen_reg_rtx (DFmode);
3608   rtx reg2 = gen_reg_rtx (DFmode);
3609   rtx reg3 = gen_reg_rtx (SImode);
3610   rtx label1 = gen_label_rtx ();
3611   rtx label2 = gen_label_rtx ();
3612   rtx test;
3613   REAL_VALUE_TYPE offset;
3615   real_2expN (&offset, 31, DFmode);
3617   if (reg1)                     /* Turn off complaints about unreached code.  */
3618     {
3619       mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3620       do_pending_stack_adjust ();
3622       test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3623       emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3625       emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
3626       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3627                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
3628       emit_barrier ();
3630       emit_label (label1);
3631       mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3632       mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3633                                      (BITMASK_HIGH, SImode)));
3635       emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
3636       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3638       emit_label (label2);
3640       /* Allow REG_NOTES to be set on last insn (labels don't have enough
3641          fields, and can't be used for REG_NOTES anyway).  */
3642       emit_use (stack_pointer_rtx);
3643       DONE;
3644     }
3648 (define_expand "fixuns_truncdfdi2"
3649   [(set (match_operand:DI 0 "register_operand")
3650         (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
3651   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3653   rtx reg1 = gen_reg_rtx (DFmode);
3654   rtx reg2 = gen_reg_rtx (DFmode);
3655   rtx reg3 = gen_reg_rtx (DImode);
3656   rtx label1 = gen_label_rtx ();
3657   rtx label2 = gen_label_rtx ();
3658   rtx test;
3659   REAL_VALUE_TYPE offset;
3661   real_2expN (&offset, 63, DFmode);
3663   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3664   do_pending_stack_adjust ();
3666   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3667   emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3669   emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
3670   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3671                                gen_rtx_LABEL_REF (VOIDmode, label2)));
3672   emit_barrier ();
3674   emit_label (label1);
3675   mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3676   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3677   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3679   emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
3680   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3682   emit_label (label2);
3684   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3685      fields, and can't be used for REG_NOTES anyway).  */
3686   emit_use (stack_pointer_rtx);
3687   DONE;
3691 (define_expand "fixuns_truncsfsi2"
3692   [(set (match_operand:SI 0 "register_operand")
3693         (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
3694   "TARGET_HARD_FLOAT"
3696   rtx reg1 = gen_reg_rtx (SFmode);
3697   rtx reg2 = gen_reg_rtx (SFmode);
3698   rtx reg3 = gen_reg_rtx (SImode);
3699   rtx label1 = gen_label_rtx ();
3700   rtx label2 = gen_label_rtx ();
3701   rtx test;
3702   REAL_VALUE_TYPE offset;
3704   real_2expN (&offset, 31, SFmode);
3706   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3707   do_pending_stack_adjust ();
3709   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3710   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3712   emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
3713   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3714                                gen_rtx_LABEL_REF (VOIDmode, label2)));
3715   emit_barrier ();
3717   emit_label (label1);
3718   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3719   mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3720                                  (BITMASK_HIGH, SImode)));
3722   emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
3723   emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3725   emit_label (label2);
3727   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3728      fields, and can't be used for REG_NOTES anyway).  */
3729   emit_use (stack_pointer_rtx);
3730   DONE;
3734 (define_expand "fixuns_truncsfdi2"
3735   [(set (match_operand:DI 0 "register_operand")
3736         (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
3737   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3739   rtx reg1 = gen_reg_rtx (SFmode);
3740   rtx reg2 = gen_reg_rtx (SFmode);
3741   rtx reg3 = gen_reg_rtx (DImode);
3742   rtx label1 = gen_label_rtx ();
3743   rtx label2 = gen_label_rtx ();
3744   rtx test;
3745   REAL_VALUE_TYPE offset;
3747   real_2expN (&offset, 63, SFmode);
3749   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3750   do_pending_stack_adjust ();
3752   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3753   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3755   emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
3756   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3757                                gen_rtx_LABEL_REF (VOIDmode, label2)));
3758   emit_barrier ();
3760   emit_label (label1);
3761   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3762   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3763   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3765   emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
3766   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3768   emit_label (label2);
3770   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3771      fields, and can't be used for REG_NOTES anyway).  */
3772   emit_use (stack_pointer_rtx);
3773   DONE;
3777 ;;  ....................
3779 ;;      DATA MOVEMENT
3781 ;;  ....................
3783 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
3785 (define_expand "extvmisalign<mode>"
3786   [(set (match_operand:GPR 0 "register_operand")
3787         (sign_extract:GPR (match_operand:BLK 1 "memory_operand")
3788                           (match_operand 2 "const_int_operand")
3789                           (match_operand 3 "const_int_operand")))]
3790   "!TARGET_MIPS16"
3792   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3793                                          INTVAL (operands[2]),
3794                                          INTVAL (operands[3]),
3795                                          /*unsigned=*/ false))
3796     DONE;
3797   else
3798     FAIL;
3801 (define_expand "extv<mode>"
3802   [(set (match_operand:GPR 0 "register_operand")
3803         (sign_extract:GPR (match_operand:GPR 1 "register_operand")
3804                           (match_operand 2 "const_int_operand")
3805                           (match_operand 3 "const_int_operand")))]
3806   "ISA_HAS_EXTS"
3808   if (UINTVAL (operands[2]) > 32)
3809     FAIL;
3812 (define_insn "*extv<mode>"
3813   [(set (match_operand:GPR 0 "register_operand" "=d")
3814         (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3815                           (match_operand 2 "const_int_operand" "")
3816                           (match_operand 3 "const_int_operand" "")))]
3817   "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
3818   "exts\t%0,%1,%3,%m2"
3819   [(set_attr "type"     "arith")
3820    (set_attr "mode"     "<MODE>")])
3822 (define_expand "extzvmisalign<mode>"
3823   [(set (match_operand:GPR 0 "register_operand")
3824         (zero_extract:GPR (match_operand:BLK 1 "memory_operand")
3825                           (match_operand 2 "const_int_operand")
3826                           (match_operand 3 "const_int_operand")))]
3827   "!TARGET_MIPS16"
3829   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3830                                          INTVAL (operands[2]),
3831                                          INTVAL (operands[3]),
3832                                          /*unsigned=*/ true))
3833     DONE;
3834   else
3835     FAIL;
3838 (define_expand "extzv<mode>"
3839   [(set (match_operand:GPR 0 "register_operand")
3840         (zero_extract:GPR (match_operand:GPR 1 "register_operand")
3841                           (match_operand 2 "const_int_operand")
3842                           (match_operand 3 "const_int_operand")))]
3843   ""
3845   if (!mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3846                            INTVAL (operands[3])))
3847     FAIL;
3850 (define_insn "*extzv<mode>"
3851   [(set (match_operand:GPR 0 "register_operand" "=d")
3852         (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3853                           (match_operand 2 "const_int_operand" "")
3854                           (match_operand 3 "const_int_operand" "")))]
3855   "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3856                        INTVAL (operands[3]))"
3857   "<d>ext\t%0,%1,%3,%2"
3858   [(set_attr "type"     "arith")
3859    (set_attr "mode"     "<MODE>")])
3861 (define_insn "*extzv_truncsi_exts"
3862   [(set (match_operand:SI 0 "register_operand" "=d")
3863         (truncate:SI
3864          (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
3865                           (match_operand 2 "const_int_operand" "")
3866                           (match_operand 3 "const_int_operand" ""))))]
3867   "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3868   "exts\t%0,%1,%3,31"
3869   [(set_attr "type"     "arith")
3870    (set_attr "mode"     "SI")])
3873 (define_expand "insvmisalign<mode>"
3874   [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand")
3875                           (match_operand 1 "const_int_operand")
3876                           (match_operand 2 "const_int_operand"))
3877         (match_operand:GPR 3 "reg_or_0_operand"))]
3878   "!TARGET_MIPS16"
3880   if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
3881                                           INTVAL (operands[1]),
3882                                           INTVAL (operands[2])))
3883     DONE;
3884   else
3885     FAIL;
3888 (define_expand "insv<mode>"
3889   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand")
3890                           (match_operand 1 "const_int_operand")
3891                           (match_operand 2 "const_int_operand"))
3892         (match_operand:GPR 3 "reg_or_0_operand"))]
3893   ""
3895   if (!mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3896                            INTVAL (operands[2])))
3897     FAIL;
3900 (define_insn "*insv<mode>"
3901   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
3902                           (match_operand:SI 1 "const_int_operand" "")
3903                           (match_operand:SI 2 "const_int_operand" ""))
3904         (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
3905   "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3906                        INTVAL (operands[2]))"
3907   "<d>ins\t%0,%z3,%2,%1"
3908   [(set_attr "type"     "arith")
3909    (set_attr "mode"     "<MODE>")])
3911 ;; Combiner pattern for cins (clear and insert bit field).  We can
3912 ;; implement mask-and-shift-left operation with this.  Note that if
3913 ;; the upper bit of the mask is set in an SImode operation, the mask
3914 ;; itself will be sign-extended.  mask_low_and_shift_len will
3915 ;; therefore be greater than our threshold of 32.
3917 (define_insn "*cins<mode>"
3918   [(set (match_operand:GPR 0 "register_operand" "=d")
3919         (and:GPR
3920          (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
3921                      (match_operand:GPR 2 "const_int_operand" ""))
3922          (match_operand:GPR 3 "const_int_operand" "")))]
3923   "ISA_HAS_CINS
3924    && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
3926   operands[3] =
3927     GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
3928   return "cins\t%0,%1,%2,%m3";
3930   [(set_attr "type"     "shift")
3931    (set_attr "mode"     "<MODE>")])
3933 ;; Unaligned word moves generated by the bit field patterns.
3935 ;; As far as the rtl is concerned, both the left-part and right-part
3936 ;; instructions can access the whole field.  However, the real operand
3937 ;; refers to just the first or the last byte (depending on endianness).
3938 ;; We therefore use two memory operands to each instruction, one to
3939 ;; describe the rtl effect and one to use in the assembly output.
3941 ;; Operands 0 and 1 are the rtl-level target and source respectively.
3942 ;; This allows us to use the standard length calculations for the "load"
3943 ;; and "store" type attributes.
3945 (define_insn "mov_<load>l"
3946   [(set (match_operand:GPR 0 "register_operand" "=d")
3947         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3948                      (match_operand:QI 2 "memory_operand" "ZC")]
3949                     UNSPEC_LOAD_LEFT))]
3950   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3951   "<load>l\t%0,%2"
3952   [(set_attr "move_type" "load")
3953    (set_attr "mode" "<MODE>")])
3955 (define_insn "mov_<load>r"
3956   [(set (match_operand:GPR 0 "register_operand" "=d")
3957         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3958                      (match_operand:QI 2 "memory_operand" "ZC")
3959                      (match_operand:GPR 3 "register_operand" "0")]
3960                     UNSPEC_LOAD_RIGHT))]
3961   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3962   "<load>r\t%0,%2"
3963   [(set_attr "move_type" "load")
3964    (set_attr "mode" "<MODE>")])
3966 (define_insn "mov_<store>l"
3967   [(set (match_operand:BLK 0 "memory_operand" "=m")
3968         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3969                      (match_operand:QI 2 "memory_operand" "ZC")]
3970                     UNSPEC_STORE_LEFT))]
3971   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3972   "<store>l\t%z1,%2"
3973   [(set_attr "move_type" "store")
3974    (set_attr "mode" "<MODE>")])
3976 (define_insn "mov_<store>r"
3977   [(set (match_operand:BLK 0 "memory_operand" "+m")
3978         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3979                      (match_operand:QI 2 "memory_operand" "ZC")
3980                      (match_dup 0)]
3981                     UNSPEC_STORE_RIGHT))]
3982   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3983   "<store>r\t%z1,%2"
3984   [(set_attr "move_type" "store")
3985    (set_attr "mode" "<MODE>")])
3987 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
3988 ;; The required value is:
3990 ;;      (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
3992 ;; which translates to:
3994 ;;      lui     op0,%highest(op1)
3995 ;;      daddiu  op0,op0,%higher(op1)
3996 ;;      dsll    op0,op0,16
3997 ;;      daddiu  op0,op0,%hi(op1)
3998 ;;      dsll    op0,op0,16
4000 ;; The split is deferred until after flow2 to allow the peephole2 below
4001 ;; to take effect.
4002 (define_insn_and_split "*lea_high64"
4003   [(set (match_operand:DI 0 "register_operand" "=d")
4004         (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
4005   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4006   "#"
4007   "&& epilogue_completed"
4008   [(set (match_dup 0) (high:DI (match_dup 2)))
4009    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
4010    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
4011    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4012    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
4014   operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4015   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
4017   [(set_attr "insn_count" "5")])
4019 ;; Use a scratch register to reduce the latency of the above pattern
4020 ;; on superscalar machines.  The optimized sequence is:
4022 ;;      lui     op1,%highest(op2)
4023 ;;      lui     op0,%hi(op2)
4024 ;;      daddiu  op1,op1,%higher(op2)
4025 ;;      dsll32  op1,op1,0
4026 ;;      daddu   op1,op1,op0
4027 (define_peephole2
4028   [(set (match_operand:DI 1 "d_operand")
4029         (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4030    (match_scratch:DI 0 "d")]
4031   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4032   [(set (match_dup 1) (high:DI (match_dup 3)))
4033    (set (match_dup 0) (high:DI (match_dup 4)))
4034    (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4035    (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4036    (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4038   operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4039   operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4042 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4043 ;; SYMBOL_ABSOLUTE X will take 6 cycles.  This next pattern allows combine
4044 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4045 ;; used once.  We can then use the sequence:
4047 ;;      lui     op0,%highest(op1)
4048 ;;      lui     op2,%hi(op1)
4049 ;;      daddiu  op0,op0,%higher(op1)
4050 ;;      daddiu  op2,op2,%lo(op1)
4051 ;;      dsll32  op0,op0,0
4052 ;;      daddu   op0,op0,op2
4054 ;; which takes 4 cycles on most superscalar targets.
4055 (define_insn_and_split "*lea64"
4056   [(set (match_operand:DI 0 "register_operand" "=d")
4057         (match_operand:DI 1 "absolute_symbolic_operand" ""))
4058    (clobber (match_scratch:DI 2 "=&d"))]
4059   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS && cse_not_expected"
4060   "#"
4061   "&& reload_completed"
4062   [(set (match_dup 0) (high:DI (match_dup 3)))
4063    (set (match_dup 2) (high:DI (match_dup 4)))
4064    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4065    (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4066    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4067    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4069   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4070   operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4072   [(set_attr "insn_count" "6")])
4074 ;; Split HIGHs into:
4076 ;;      li op0,%hi(sym)
4077 ;;      sll op0,16
4079 ;; on MIPS16 targets.
4080 (define_split
4081   [(set (match_operand:P 0 "d_operand")
4082         (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4083   "TARGET_MIPS16 && reload_completed"
4084   [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4085    (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4087 (define_insn "*unshifted_high"
4088   [(set (match_operand:P 0 "d_operand" "=d")
4089         (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4090                   UNSPEC_UNSHIFTED_HIGH))]
4091   ""
4092   "li\t%0,%h1"
4093   [(set_attr "extended_mips16" "yes")])
4095 ;; Insns to fetch a symbol from a big GOT.
4097 (define_insn_and_split "*xgot_hi<mode>"
4098   [(set (match_operand:P 0 "register_operand" "=d")
4099         (high:P (match_operand:P 1 "got_disp_operand" "")))]
4100   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4101   "#"
4102   "&& reload_completed"
4103   [(set (match_dup 0) (high:P (match_dup 2)))
4104    (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4106   operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4107   operands[3] = pic_offset_table_rtx;
4109   [(set_attr "got" "xgot_high")
4110    (set_attr "mode" "<MODE>")])
4112 (define_insn_and_split "*xgot_lo<mode>"
4113   [(set (match_operand:P 0 "register_operand" "=d")
4114         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4115                   (match_operand:P 2 "got_disp_operand" "")))]
4116   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4117   "#"
4118   "&& reload_completed"
4119   [(set (match_dup 0)
4120         (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4121   { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4122   [(set_attr "got" "load")
4123    (set_attr "mode" "<MODE>")])
4125 ;; Insns to fetch a symbol from a normal GOT.
4127 (define_insn_and_split "*got_disp<mode>"
4128   [(set (match_operand:P 0 "register_operand" "=d")
4129         (match_operand:P 1 "got_disp_operand" ""))]
4130   "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4131   "#"
4132   "&& reload_completed"
4133   [(set (match_dup 0) (match_dup 2))]
4134   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4135   [(set_attr "got" "load")
4136    (set_attr "mode" "<MODE>")])
4138 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4140 (define_insn_and_split "*got_page<mode>"
4141   [(set (match_operand:P 0 "register_operand" "=d")
4142         (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4143   "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4144   "#"
4145   "&& reload_completed"
4146   [(set (match_dup 0) (match_dup 2))]
4147   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4148   [(set_attr "got" "load")
4149    (set_attr "mode" "<MODE>")])
4151 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4152 (define_expand "unspec_got_<mode>"
4153   [(unspec:P [(match_operand:P 0)
4154               (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4156 ;; Lower-level instructions for loading an address from the GOT.
4157 ;; We could use MEMs, but an unspec gives more optimization
4158 ;; opportunities.
4160 (define_insn "load_got<mode>"
4161   [(set (match_operand:P 0 "register_operand" "=d")
4162         (unspec:P [(match_operand:P 1 "register_operand" "d")
4163                    (match_operand:P 2 "immediate_operand" "")]
4164                   UNSPEC_LOAD_GOT))]
4165   ""
4166   "<load>\t%0,%R2(%1)"
4167   [(set_attr "got" "load")
4168    (set_attr "mode" "<MODE>")])
4170 ;; Instructions for adding the low 16 bits of an address to a register.
4171 ;; Operand 2 is the address: mips_print_operand works out which relocation
4172 ;; should be applied.
4174 (define_insn "*low<mode>"
4175   [(set (match_operand:P 0 "register_operand" "=d")
4176         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4177                   (match_operand:P 2 "immediate_operand" "")))]
4178   "!TARGET_MIPS16"
4179   "<d>addiu\t%0,%1,%R2"
4180   [(set_attr "alu_type" "add")
4181    (set_attr "mode" "<MODE>")])
4183 (define_insn "*low<mode>_mips16"
4184   [(set (match_operand:P 0 "register_operand" "=d")
4185         (lo_sum:P (match_operand:P 1 "register_operand" "0")
4186                   (match_operand:P 2 "immediate_operand" "")))]
4187   "TARGET_MIPS16"
4188   "<d>addiu\t%0,%R2"
4189   [(set_attr "alu_type" "add")
4190    (set_attr "mode" "<MODE>")
4191    (set_attr "extended_mips16" "yes")])
4193 ;; Expose MIPS16 uses of the global pointer after reload if the function
4194 ;; is responsible for setting up the register itself.
4195 (define_split
4196   [(set (match_operand:GPR 0 "d_operand")
4197         (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4198   "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4199   [(set (match_dup 0) (match_dup 1))]
4200   { operands[1] = pic_offset_table_rtx; })
4202 ;; Allow combine to split complex const_int load sequences, using operand 2
4203 ;; to store the intermediate results.  See move_operand for details.
4204 (define_split
4205   [(set (match_operand:GPR 0 "register_operand")
4206         (match_operand:GPR 1 "splittable_const_int_operand"))
4207    (clobber (match_operand:GPR 2 "register_operand"))]
4208   ""
4209   [(const_int 0)]
4211   mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4212   DONE;
4215 ;; Likewise, for symbolic operands.
4216 (define_split
4217   [(set (match_operand:P 0 "register_operand")
4218         (match_operand:P 1))
4219    (clobber (match_operand:P 2 "register_operand"))]
4220   "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4221   [(set (match_dup 0) (match_dup 3))]
4223   mips_split_symbol (operands[2], operands[1],
4224                      MAX_MACHINE_MODE, &operands[3]);
4227 ;; 64-bit integer moves
4229 ;; Unlike most other insns, the move insns can't be split with
4230 ;; different predicates, because register spilling and other parts of
4231 ;; the compiler, have memoized the insn number already.
4233 (define_expand "movdi"
4234   [(set (match_operand:DI 0 "")
4235         (match_operand:DI 1 ""))]
4236   ""
4238   if (mips_legitimize_move (DImode, operands[0], operands[1]))
4239     DONE;
4242 ;; For mips16, we need a special case to handle storing $31 into
4243 ;; memory, since we don't have a constraint to match $31.  This
4244 ;; instruction can be generated by save_restore_insns.
4246 (define_insn "*mov<mode>_ra"
4247   [(set (match_operand:GPR 0 "stack_operand" "=m")
4248         (reg:GPR RETURN_ADDR_REGNUM))]
4249   "TARGET_MIPS16"
4250   "<store>\t$31,%0"
4251   [(set_attr "move_type" "store")
4252    (set_attr "mode" "<MODE>")])
4254 (define_insn "*movdi_32bit"
4255   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d,*f,*f,*d,*m,*B*C*D,*B*C*D,*d,*m")
4256         (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"))]
4257   "!TARGET_64BIT && !TARGET_MIPS16
4258    && (register_operand (operands[0], DImode)
4259        || reg_or_0_operand (operands[1], DImode))"
4260   { return mips_output_move (operands[0], operands[1]); }
4261   [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4262    (set (attr "mode")
4263         (if_then_else (eq_attr "move_type" "imul")
4264                       (const_string "SI")
4265                       (const_string "DI")))])
4267 (define_insn "*movdi_32bit_mips16"
4268   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4269         (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4270   "!TARGET_64BIT && TARGET_MIPS16
4271    && (register_operand (operands[0], DImode)
4272        || register_operand (operands[1], DImode))"
4273   { return mips_output_move (operands[0], operands[1]); }
4274   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4275    (set_attr "mode" "DI")])
4277 (define_insn "*movdi_64bit"
4278   [(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")
4279         (match_operand:DI 1 "move_operand" "d,Yd,Yf,m,dJ,*d*J,*m,*f,*f,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4280   "TARGET_64BIT && !TARGET_MIPS16
4281    && (register_operand (operands[0], DImode)
4282        || reg_or_0_operand (operands[1], DImode))"
4283   { return mips_output_move (operands[0], operands[1]); }
4284   [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4285    (set_attr "mode" "DI")])
4287 (define_insn "*movdi_64bit_mips16"
4288   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4289         (match_operand:DI 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4290   "TARGET_64BIT && TARGET_MIPS16
4291    && (register_operand (operands[0], DImode)
4292        || register_operand (operands[1], DImode))"
4293   { return mips_output_move (operands[0], operands[1]); }
4294   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4295    (set_attr "mode" "DI")])
4297 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4298 ;; when the original load is a 4 byte instruction but the add and the
4299 ;; load are 2 2 byte instructions.
4301 (define_split
4302   [(set (match_operand:DI 0 "d_operand")
4303         (mem:DI (plus:DI (match_dup 0)
4304                          (match_operand:DI 1 "const_int_operand"))))]
4305   "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4306    && !TARGET_DEBUG_D_MODE
4307    && ((INTVAL (operands[1]) < 0
4308         && INTVAL (operands[1]) >= -0x10)
4309        || (INTVAL (operands[1]) >= 32 * 8
4310            && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4311        || (INTVAL (operands[1]) >= 0
4312            && INTVAL (operands[1]) < 32 * 8
4313            && (INTVAL (operands[1]) & 7) != 0))"
4314   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4315    (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4317   HOST_WIDE_INT val = INTVAL (operands[1]);
4319   if (val < 0)
4320     operands[2] = const0_rtx;
4321   else if (val >= 32 * 8)
4322     {
4323       int off = val & 7;
4325       operands[1] = GEN_INT (0x8 + off);
4326       operands[2] = GEN_INT (val - off - 0x8);
4327     }
4328   else
4329     {
4330       int off = val & 7;
4332       operands[1] = GEN_INT (off);
4333       operands[2] = GEN_INT (val - off);
4334     }
4337 ;; 32-bit Integer moves
4339 ;; Unlike most other insns, the move insns can't be split with
4340 ;; different predicates, because register spilling and other parts of
4341 ;; the compiler, have memoized the insn number already.
4343 (define_expand "mov<mode>"
4344   [(set (match_operand:IMOVE32 0 "")
4345         (match_operand:IMOVE32 1 ""))]
4346   ""
4348   if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4349     DONE;
4352 ;; The difference between these two is whether or not ints are allowed
4353 ;; in FP registers (off by default, use -mdebugh to enable).
4355 (define_insn "*mov<mode>_internal"
4356   [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,!u,!u,d,e,!u,!ks,d,ZS,ZT,m,*f,*f,*d,*m,*d,*z,*a,*d,*B*C*D,*B*C*D,*d,*m")
4357         (match_operand:IMOVE32 1 "move_operand" "d,J,Udb7,Yd,Yf,ZT,ZS,m,!ks,!u,dJ,*d*J,*m,*f,*f,*z,*d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4358   "!TARGET_MIPS16
4359    && (register_operand (operands[0], <MODE>mode)
4360        || reg_or_0_operand (operands[1], <MODE>mode))"
4361   { return mips_output_move (operands[0], operands[1]); }
4362   [(set_attr "move_type" "move,move,const,const,const,load,load,load,store,store,store,mtc,fpload,mfc,fpstore,mfc,mtc,mtlo,mflo,mtc,fpload,mfc,fpstore")
4363    (set_attr "compression" "all,micromips,micromips,*,*,micromips,micromips,*,micromips,micromips,*,*,*,*,*,*,*,*,*,*,*,*,*")
4364    (set_attr "mode" "SI")])
4366 (define_insn "*mov<mode>_mips16"
4367   [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4368         (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4369   "TARGET_MIPS16
4370    && (register_operand (operands[0], <MODE>mode)
4371        || register_operand (operands[1], <MODE>mode))"
4372   { return mips_output_move (operands[0], operands[1]); }
4373   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4374    (set_attr "mode" "SI")])
4376 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4377 ;; when the original load is a 4 byte instruction but the add and the
4378 ;; load are 2 2 byte instructions.
4380 (define_split
4381   [(set (match_operand:SI 0 "d_operand")
4382         (mem:SI (plus:SI (match_dup 0)
4383                          (match_operand:SI 1 "const_int_operand"))))]
4384   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4385    && ((INTVAL (operands[1]) < 0
4386         && INTVAL (operands[1]) >= -0x80)
4387        || (INTVAL (operands[1]) >= 32 * 4
4388            && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4389        || (INTVAL (operands[1]) >= 0
4390            && INTVAL (operands[1]) < 32 * 4
4391            && (INTVAL (operands[1]) & 3) != 0))"
4392   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4393    (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4395   HOST_WIDE_INT val = INTVAL (operands[1]);
4397   if (val < 0)
4398     operands[2] = const0_rtx;
4399   else if (val >= 32 * 4)
4400     {
4401       int off = val & 3;
4403       operands[1] = GEN_INT (0x7c + off);
4404       operands[2] = GEN_INT (val - off - 0x7c);
4405     }
4406   else
4407     {
4408       int off = val & 3;
4410       operands[1] = GEN_INT (off);
4411       operands[2] = GEN_INT (val - off);
4412     }
4415 ;; On the mips16, we can split a load of certain constants into a load
4416 ;; and an add.  This turns a 4 byte instruction into 2 2 byte
4417 ;; instructions.
4419 (define_split
4420   [(set (match_operand:SI 0 "d_operand")
4421         (match_operand:SI 1 "const_int_operand"))]
4422   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4423    && INTVAL (operands[1]) >= 0x100
4424    && INTVAL (operands[1]) <= 0xff + 0x7f"
4425   [(set (match_dup 0) (match_dup 1))
4426    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4428   int val = INTVAL (operands[1]);
4430   operands[1] = GEN_INT (0xff);
4431   operands[2] = GEN_INT (val - 0xff);
4434 ;; MIPS4 supports loading and storing a floating point register from
4435 ;; the sum of two general registers.  We use two versions for each of
4436 ;; these four instructions: one where the two general registers are
4437 ;; SImode, and one where they are DImode.  This is because general
4438 ;; registers will be in SImode when they hold 32-bit values, but,
4439 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4440 ;; instructions will still work correctly.
4442 ;; ??? Perhaps it would be better to support these instructions by
4443 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends.  However, since
4444 ;; these instructions can only be used to load and store floating
4445 ;; point registers, that would probably cause trouble in reload.
4447 (define_insn "*<ANYF:loadx>_<P:mode>"
4448   [(set (match_operand:ANYF 0 "register_operand" "=f")
4449         (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4450                           (match_operand:P 2 "register_operand" "d"))))]
4451   "ISA_HAS_FP4"
4452   "<ANYF:loadx>\t%0,%1(%2)"
4453   [(set_attr "type" "fpidxload")
4454    (set_attr "mode" "<ANYF:UNITMODE>")])
4456 (define_insn "*<ANYF:storex>_<P:mode>"
4457   [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4458                           (match_operand:P 2 "register_operand" "d")))
4459         (match_operand:ANYF 0 "register_operand" "f"))]
4460   "ISA_HAS_FP4"
4461   "<ANYF:storex>\t%0,%1(%2)"
4462   [(set_attr "type" "fpidxstore")
4463    (set_attr "mode" "<ANYF:UNITMODE>")])
4465 ;; Scaled indexed address load.
4466 ;; Per md.texi, we only need to look for a pattern with multiply in the
4467 ;; address expression, not shift.
4469 (define_insn "*lwxs"
4470   [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4471         (mem:IMOVE32
4472           (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4473                           (const_int 4))
4474                   (match_operand:P 2 "register_operand" "d"))))]
4475   "ISA_HAS_LWXS"
4476   "lwxs\t%0,%1(%2)"
4477   [(set_attr "type"     "load")
4478    (set_attr "mode"     "SI")])
4480 ;; 16-bit Integer moves
4482 ;; Unlike most other insns, the move insns can't be split with
4483 ;; different predicates, because register spilling and other parts of
4484 ;; the compiler, have memoized the insn number already.
4485 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4487 (define_expand "movhi"
4488   [(set (match_operand:HI 0 "")
4489         (match_operand:HI 1 ""))]
4490   ""
4492   if (mips_legitimize_move (HImode, operands[0], operands[1]))
4493     DONE;
4496 (define_insn "*movhi_internal"
4497   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZU,m,*a,*d")
4498         (match_operand:HI 1 "move_operand"         "d,J,I,ZU,m,!u,dJ,*d*J,*a"))]
4499   "!TARGET_MIPS16
4500    && (register_operand (operands[0], HImode)
4501        || reg_or_0_operand (operands[1], HImode))"
4502   { return mips_output_move (operands[0], operands[1]); }
4503   [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4504    (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4505    (set_attr "mode" "HI")])
4507 (define_insn "*movhi_mips16"
4508   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4509         (match_operand:HI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
4510   "TARGET_MIPS16
4511    && (register_operand (operands[0], HImode)
4512        || register_operand (operands[1], HImode))"
4513   { return mips_output_move (operands[0], operands[1]); }
4514   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4515    (set_attr "mode" "HI")])
4517 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
4518 ;; when the original load is a 4 byte instruction but the add and the
4519 ;; load are 2 2 byte instructions.
4521 (define_split
4522   [(set (match_operand:HI 0 "d_operand")
4523         (mem:HI (plus:SI (match_dup 0)
4524                          (match_operand:SI 1 "const_int_operand"))))]
4525   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4526    && ((INTVAL (operands[1]) < 0
4527         && INTVAL (operands[1]) >= -0x80)
4528        || (INTVAL (operands[1]) >= 32 * 2
4529            && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
4530        || (INTVAL (operands[1]) >= 0
4531            && INTVAL (operands[1]) < 32 * 2
4532            && (INTVAL (operands[1]) & 1) != 0))"
4533   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4534    (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
4536   HOST_WIDE_INT val = INTVAL (operands[1]);
4538   if (val < 0)
4539     operands[2] = const0_rtx;
4540   else if (val >= 32 * 2)
4541     {
4542       int off = val & 1;
4544       operands[1] = GEN_INT (0x7e + off);
4545       operands[2] = GEN_INT (val - off - 0x7e);
4546     }
4547   else
4548     {
4549       int off = val & 1;
4551       operands[1] = GEN_INT (off);
4552       operands[2] = GEN_INT (val - off);
4553     }
4556 ;; 8-bit Integer moves
4558 ;; Unlike most other insns, the move insns can't be split with
4559 ;; different predicates, because register spilling and other parts of
4560 ;; the compiler, have memoized the insn number already.
4561 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4563 (define_expand "movqi"
4564   [(set (match_operand:QI 0 "")
4565         (match_operand:QI 1 ""))]
4566   ""
4568   if (mips_legitimize_move (QImode, operands[0], operands[1]))
4569     DONE;
4572 (define_insn "*movqi_internal"
4573   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZV,m,*a,*d")
4574         (match_operand:QI 1 "move_operand"         "d,J,I,ZW,m,!u,dJ,*d*J,*a"))]
4575   "!TARGET_MIPS16
4576    && (register_operand (operands[0], QImode)
4577        || reg_or_0_operand (operands[1], QImode))"
4578   { return mips_output_move (operands[0], operands[1]); }
4579   [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4580    (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4581    (set_attr "mode" "QI")])
4583 (define_insn "*movqi_mips16"
4584   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4585         (match_operand:QI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
4586   "TARGET_MIPS16
4587    && (register_operand (operands[0], QImode)
4588        || register_operand (operands[1], QImode))"
4589   { return mips_output_move (operands[0], operands[1]); }
4590   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4591    (set_attr "mode" "QI")])
4593 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
4594 ;; when the original load is a 4 byte instruction but the add and the
4595 ;; load are 2 2 byte instructions.
4597 (define_split
4598   [(set (match_operand:QI 0 "d_operand")
4599         (mem:QI (plus:SI (match_dup 0)
4600                          (match_operand:SI 1 "const_int_operand"))))]
4601   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4602    && ((INTVAL (operands[1]) < 0
4603         && INTVAL (operands[1]) >= -0x80)
4604        || (INTVAL (operands[1]) >= 32
4605            && INTVAL (operands[1]) <= 31 + 0x7f))"
4606   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4607    (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
4609   HOST_WIDE_INT val = INTVAL (operands[1]);
4611   if (val < 0)
4612     operands[2] = const0_rtx;
4613   else
4614     {
4615       operands[1] = GEN_INT (0x7f);
4616       operands[2] = GEN_INT (val - 0x7f);
4617     }
4620 ;; 32-bit floating point moves
4622 (define_expand "movsf"
4623   [(set (match_operand:SF 0 "")
4624         (match_operand:SF 1 ""))]
4625   ""
4627   if (mips_legitimize_move (SFmode, operands[0], operands[1]))
4628     DONE;
4631 (define_insn "*movsf_hardfloat"
4632   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4633         (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
4634   "TARGET_HARD_FLOAT
4635    && (register_operand (operands[0], SFmode)
4636        || reg_or_0_operand (operands[1], SFmode))"
4637   { return mips_output_move (operands[0], operands[1]); }
4638   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4639    (set_attr "mode" "SF")])
4641 (define_insn "*movsf_softfloat"
4642   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
4643         (match_operand:SF 1 "move_operand" "Gd,m,d"))]
4644   "TARGET_SOFT_FLOAT && !TARGET_MIPS16
4645    && (register_operand (operands[0], SFmode)
4646        || reg_or_0_operand (operands[1], SFmode))"
4647   { return mips_output_move (operands[0], operands[1]); }
4648   [(set_attr "move_type" "move,load,store")
4649    (set_attr "mode" "SF")])
4651 (define_insn "*movsf_mips16"
4652   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
4653         (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
4654   "TARGET_MIPS16
4655    && (register_operand (operands[0], SFmode)
4656        || register_operand (operands[1], SFmode))"
4657   { return mips_output_move (operands[0], operands[1]); }
4658   [(set_attr "move_type" "move,move,move,load,store")
4659    (set_attr "mode" "SF")])
4661 ;; 64-bit floating point moves
4663 (define_expand "movdf"
4664   [(set (match_operand:DF 0 "")
4665         (match_operand:DF 1 ""))]
4666   ""
4668   if (mips_legitimize_move (DFmode, operands[0], operands[1]))
4669     DONE;
4672 (define_insn "*movdf_hardfloat"
4673   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4674         (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
4675   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
4676    && (register_operand (operands[0], DFmode)
4677        || reg_or_0_operand (operands[1], DFmode))"
4678   { return mips_output_move (operands[0], operands[1]); }
4679   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4680    (set_attr "mode" "DF")])
4682 (define_insn "*movdf_softfloat"
4683   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
4684         (match_operand:DF 1 "move_operand" "dG,m,dG"))]
4685   "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
4686    && (register_operand (operands[0], DFmode)
4687        || reg_or_0_operand (operands[1], DFmode))"
4688   { return mips_output_move (operands[0], operands[1]); }
4689   [(set_attr "move_type" "move,load,store")
4690    (set_attr "mode" "DF")])
4692 (define_insn "*movdf_mips16"
4693   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
4694         (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
4695   "TARGET_MIPS16
4696    && (register_operand (operands[0], DFmode)
4697        || register_operand (operands[1], DFmode))"
4698   { return mips_output_move (operands[0], operands[1]); }
4699   [(set_attr "move_type" "move,move,move,load,store")
4700    (set_attr "mode" "DF")])
4702 ;; 128-bit integer moves
4704 (define_expand "movti"
4705   [(set (match_operand:TI 0)
4706         (match_operand:TI 1))]
4707   "TARGET_64BIT"
4709   if (mips_legitimize_move (TImode, operands[0], operands[1]))
4710     DONE;
4713 (define_insn "*movti"
4714   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d")
4715         (match_operand:TI 1 "move_operand" "d,i,m,dJ,*J,*d,*a"))]
4716   "TARGET_64BIT
4717    && !TARGET_MIPS16
4718    && (register_operand (operands[0], TImode)
4719        || reg_or_0_operand (operands[1], TImode))"
4720   { return mips_output_move (operands[0], operands[1]); }
4721   [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo")
4722    (set (attr "mode")
4723         (if_then_else (eq_attr "move_type" "imul")
4724                       (const_string "SI")
4725                       (const_string "TI")))])
4727 (define_insn "*movti_mips16"
4728   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4729         (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4730   "TARGET_64BIT
4731    && TARGET_MIPS16
4732    && (register_operand (operands[0], TImode)
4733        || register_operand (operands[1], TImode))"
4734   "#"
4735   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4736    (set_attr "mode" "TI")])
4738 ;; 128-bit floating point moves
4740 (define_expand "movtf"
4741   [(set (match_operand:TF 0)
4742         (match_operand:TF 1))]
4743   "TARGET_64BIT"
4745   if (mips_legitimize_move (TFmode, operands[0], operands[1]))
4746     DONE;
4749 ;; This pattern handles both hard- and soft-float cases.
4750 (define_insn "*movtf"
4751   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
4752         (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
4753   "TARGET_64BIT
4754    && !TARGET_MIPS16
4755    && (register_operand (operands[0], TFmode)
4756        || reg_or_0_operand (operands[1], TFmode))"
4757   "#"
4758   [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
4759    (set_attr "mode" "TF")])
4761 (define_insn "*movtf_mips16"
4762   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
4763         (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
4764   "TARGET_64BIT
4765    && TARGET_MIPS16
4766    && (register_operand (operands[0], TFmode)
4767        || register_operand (operands[1], TFmode))"
4768   "#"
4769   [(set_attr "move_type" "move,move,move,load,store")
4770    (set_attr "mode" "TF")])
4772 (define_split
4773   [(set (match_operand:MOVE64 0 "nonimmediate_operand")
4774         (match_operand:MOVE64 1 "move_operand"))]
4775   "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
4776   [(const_int 0)]
4778   mips_split_move_insn (operands[0], operands[1], curr_insn);
4779   DONE;
4782 (define_split
4783   [(set (match_operand:MOVE128 0 "nonimmediate_operand")
4784         (match_operand:MOVE128 1 "move_operand"))]
4785   "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
4786   [(const_int 0)]
4788   mips_split_move_insn (operands[0], operands[1], curr_insn);
4789   DONE;
4792 ;; When generating mips16 code, split moves of negative constants into
4793 ;; a positive "li" followed by a negation.
4794 (define_split
4795   [(set (match_operand 0 "d_operand")
4796         (match_operand 1 "const_int_operand"))]
4797   "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
4798   [(set (match_dup 2)
4799         (match_dup 3))
4800    (set (match_dup 2)
4801         (neg:SI (match_dup 2)))]
4803   operands[2] = gen_lowpart (SImode, operands[0]);
4804   operands[3] = GEN_INT (-INTVAL (operands[1]));
4807 ;; 64-bit paired-single floating point moves
4809 (define_expand "movv2sf"
4810   [(set (match_operand:V2SF 0)
4811         (match_operand:V2SF 1))]
4812   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
4814   if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
4815     DONE;
4818 (define_insn "*movv2sf"
4819   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4820         (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
4821   "TARGET_HARD_FLOAT
4822    && TARGET_PAIRED_SINGLE_FLOAT
4823    && (register_operand (operands[0], V2SFmode)
4824        || reg_or_0_operand (operands[1], V2SFmode))"
4825   { return mips_output_move (operands[0], operands[1]); }
4826   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4827    (set_attr "mode" "DF")])
4829 ;; Extract the high part of a HI/LO value.  See mips_hard_regno_mode_ok_p
4830 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
4832 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
4833 ;; instead of MFHI.  This avoids both the normal MIPS III hi/lo hazards
4834 ;; and the errata related to -mfix-vr4130.
4835 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
4836   [(set (match_operand:GPR 0 "register_operand" "=d")
4837         (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
4838                     UNSPEC_MFHI))]
4839   ""
4840   { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
4841   [(set_attr "type" "mfhi")
4842    (set_attr "mode" "<GPR:MODE>")])
4844 ;; Set the high part of a HI/LO value, given that the low part has
4845 ;; already been set.  See mips_hard_regno_mode_ok_p for the reason
4846 ;; why we can't just use (reg:GPR HI_REGNUM).
4847 (define_insn "mthi<GPR:mode>_<HILO:mode>"
4848   [(set (match_operand:HILO 0 "register_operand" "=x")
4849         (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4850                       (match_operand:GPR 2 "register_operand" "l")]
4851                      UNSPEC_MTHI))]
4852   ""
4853   "mthi\t%z1"
4854   [(set_attr "type" "mthi")
4855    (set_attr "mode" "SI")])
4857 ;; Emit a doubleword move in which exactly one of the operands is
4858 ;; a floating-point register.  We can't just emit two normal moves
4859 ;; because of the constraints imposed by the FPU register model;
4860 ;; see mips_cannot_change_mode_class for details.  Instead, we keep
4861 ;; the FPR whole and use special patterns to refer to each word of
4862 ;; the other operand.
4864 (define_expand "move_doubleword_fpr<mode>"
4865   [(set (match_operand:SPLITF 0)
4866         (match_operand:SPLITF 1))]
4867   ""
4869   if (FP_REG_RTX_P (operands[0]))
4870     {
4871       rtx low = mips_subword (operands[1], 0);
4872       rtx high = mips_subword (operands[1], 1);
4873       emit_insn (gen_load_low<mode> (operands[0], low));
4874       if (TARGET_FLOAT64 && !TARGET_64BIT)
4875         emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
4876       else
4877         emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
4878     }
4879   else
4880     {
4881       rtx low = mips_subword (operands[0], 0);
4882       rtx high = mips_subword (operands[0], 1);
4883       emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
4884       if (TARGET_FLOAT64 && !TARGET_64BIT)
4885         emit_insn (gen_mfhc1<mode> (high, operands[1]));
4886       else
4887         emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
4888     }
4889   DONE;
4892 ;; Load the low word of operand 0 with operand 1.
4893 (define_insn "load_low<mode>"
4894   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4895         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
4896                        UNSPEC_LOAD_LOW))]
4897   "TARGET_HARD_FLOAT"
4899   operands[0] = mips_subword (operands[0], 0);
4900   return mips_output_move (operands[0], operands[1]);
4902   [(set_attr "move_type" "mtc,fpload")
4903    (set_attr "mode" "<HALFMODE>")])
4905 ;; Load the high word of operand 0 from operand 1, preserving the value
4906 ;; in the low word.
4907 (define_insn "load_high<mode>"
4908   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4909         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
4910                         (match_operand:SPLITF 2 "register_operand" "0,0")]
4911                        UNSPEC_LOAD_HIGH))]
4912   "TARGET_HARD_FLOAT"
4914   operands[0] = mips_subword (operands[0], 1);
4915   return mips_output_move (operands[0], operands[1]);
4917   [(set_attr "move_type" "mtc,fpload")
4918    (set_attr "mode" "<HALFMODE>")])
4920 ;; Store one word of operand 1 in operand 0.  Operand 2 is 1 to store the
4921 ;; high word and 0 to store the low word.
4922 (define_insn "store_word<mode>"
4923   [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
4924         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
4925                             (match_operand 2 "const_int_operand")]
4926                            UNSPEC_STORE_WORD))]
4927   "TARGET_HARD_FLOAT"
4929   operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
4930   return mips_output_move (operands[0], operands[1]);
4932   [(set_attr "move_type" "mfc,fpstore")
4933    (set_attr "mode" "<HALFMODE>")])
4935 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
4936 ;; value in the low word.
4937 (define_insn "mthc1<mode>"
4938   [(set (match_operand:SPLITF 0 "register_operand" "=f")
4939         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
4940                         (match_operand:SPLITF 2 "register_operand" "0")]
4941                        UNSPEC_MTHC1))]
4942   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4943   "mthc1\t%z1,%0"
4944   [(set_attr "move_type" "mtc")
4945    (set_attr "mode" "<HALFMODE>")])
4947 ;; Move high word of operand 1 to operand 0 using mfhc1.
4948 (define_insn "mfhc1<mode>"
4949   [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
4950         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
4951                             UNSPEC_MFHC1))]
4952   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4953   "mfhc1\t%0,%1"
4954   [(set_attr "move_type" "mfc")
4955    (set_attr "mode" "<HALFMODE>")])
4957 ;; Move a constant that satisfies CONST_GP_P into operand 0.
4958 (define_expand "load_const_gp_<mode>"
4959   [(set (match_operand:P 0 "register_operand" "=d")
4960         (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
4962 ;; Insn to initialize $gp for n32/n64 abicalls.  Operand 0 is the offset
4963 ;; of _gp from the start of this function.  Operand 1 is the incoming
4964 ;; function address.
4965 (define_insn_and_split "loadgp_newabi_<mode>"
4966   [(set (match_operand:P 0 "register_operand" "=&d")
4967         (unspec:P [(match_operand:P 1)
4968                    (match_operand:P 2 "register_operand" "d")]
4969                   UNSPEC_LOADGP))]
4970   "mips_current_loadgp_style () == LOADGP_NEWABI"
4971   { return mips_must_initialize_gp_p () ? "#" : ""; }
4972   "&& mips_must_initialize_gp_p ()"
4973   [(set (match_dup 0) (match_dup 3))
4974    (set (match_dup 0) (match_dup 4))
4975    (set (match_dup 0) (match_dup 5))]
4977   operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
4978   operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
4979   operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
4981   [(set_attr "type" "ghost")])
4983 ;; Likewise, for -mno-shared code.  Operand 0 is the __gnu_local_gp symbol.
4984 (define_insn_and_split "loadgp_absolute_<mode>"
4985   [(set (match_operand:P 0 "register_operand" "=d")
4986         (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
4987   "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
4988   { return mips_must_initialize_gp_p () ? "#" : ""; }
4989   "&& mips_must_initialize_gp_p ()"
4990   [(const_int 0)]
4992   mips_emit_move (operands[0], operands[1]);
4993   DONE;
4995   [(set_attr "type" "ghost")])
4997 ;; This blockage instruction prevents the gp load from being
4998 ;; scheduled after an implicit use of gp.  It also prevents
4999 ;; the load from being deleted as dead.
5000 (define_insn "loadgp_blockage"
5001   [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5002   ""
5003   ""
5004   [(set_attr "type" "ghost")])
5006 ;; Initialize $gp for RTP PIC.  Operand 0 is the __GOTT_BASE__ symbol
5007 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5008 (define_insn_and_split "loadgp_rtp_<mode>"
5009   [(set (match_operand:P 0 "register_operand" "=d")
5010         (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5011                    (match_operand:P 2 "symbol_ref_operand")]
5012                   UNSPEC_LOADGP))]
5013   "mips_current_loadgp_style () == LOADGP_RTP"
5014   { return mips_must_initialize_gp_p () ? "#" : ""; }
5015   "&& mips_must_initialize_gp_p ()"
5016   [(set (match_dup 0) (high:P (match_dup 3)))
5017    (set (match_dup 0) (unspec:P [(match_dup 0)
5018                                  (match_dup 3)] UNSPEC_LOAD_GOT))
5019    (set (match_dup 0) (unspec:P [(match_dup 0)
5020                                  (match_dup 4)] UNSPEC_LOAD_GOT))]
5022   operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5023   operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5025   [(set_attr "type" "ghost")])
5027 ;; Initialize the global pointer for MIPS16 code.  Operand 0 is the
5028 ;; global pointer and operand 1 is the MIPS16 register that holds
5029 ;; the required value.
5030 (define_insn_and_split "copygp_mips16_<mode>"
5031   [(set (match_operand:P 0 "register_operand" "=y")
5032         (unspec:P [(match_operand:P 1 "register_operand" "d")]
5033                   UNSPEC_COPYGP))]
5034   "TARGET_MIPS16"
5035   { return mips_must_initialize_gp_p () ? "#" : ""; }
5036   "&& mips_must_initialize_gp_p ()"
5037   [(set (match_dup 0) (match_dup 1))]
5038   ""
5039   [(set_attr "type" "ghost")])
5041 ;; A placeholder for where the cprestore instruction should go,
5042 ;; if we decide we need one.  Operand 0 and operand 1 are as for
5043 ;; "cprestore".  Operand 2 is a register that holds the gp value.
5045 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5046 ;; otherwise any register that holds the correct value will do.
5047 (define_insn_and_split "potential_cprestore_<mode>"
5048   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5049         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5050                    (match_operand:P 2 "register_operand" "d,d")]
5051                   UNSPEC_POTENTIAL_CPRESTORE))
5052    (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5053   "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5054   { return mips_must_initialize_gp_p () ? "#" : ""; }
5055   "mips_must_initialize_gp_p ()"
5056   [(const_int 0)]
5058   mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5059                                   operands[2], operands[3]);
5060   DONE;
5062   [(set_attr "type" "ghost")])
5064 ;; Emit a .cprestore directive, which normally expands to a single store
5065 ;; instruction.  Operand 0 is a (possibly illegitimate) sp-based MEM
5066 ;; for the cprestore slot.  Operand 1 is the offset of the slot from
5067 ;; the stack pointer.  (This is redundant with operand 0, but it makes
5068 ;; things a little simpler.)
5069 (define_insn "cprestore_<mode>"
5070   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5071         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5072                    (reg:P 28)]
5073                   UNSPEC_CPRESTORE))]
5074   "TARGET_CPRESTORE_DIRECTIVE"
5076   if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5077     return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5078   else
5079     return ".cprestore\t%1";
5081   [(set_attr "type" "store")
5082    (set_attr "insn_count" "1,3")])
5084 (define_insn "use_cprestore_<mode>"
5085   [(set (reg:P CPRESTORE_SLOT_REGNUM)
5086         (match_operand:P 0 "cprestore_load_slot_operand"))]
5087   ""
5088   ""
5089   [(set_attr "type" "ghost")])
5091 ;; Expand in-line code to clear the instruction cache between operand[0] and
5092 ;; operand[1].
5093 (define_expand "clear_cache"
5094   [(match_operand 0 "pmode_register_operand")
5095    (match_operand 1 "pmode_register_operand")]
5096   ""
5097   "
5099   if (TARGET_SYNCI)
5100     {
5101       mips_expand_synci_loop (operands[0], operands[1]);
5102       emit_insn (gen_sync ());
5103       emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5104     }
5105   else if (mips_cache_flush_func && mips_cache_flush_func[0])
5106     {
5107       rtx len = gen_reg_rtx (Pmode);
5108       emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5109       MIPS_ICACHE_SYNC (operands[0], len);
5110     }
5111   DONE;
5114 (define_insn "sync"
5115   [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5116   "GENERATE_SYNC"
5117   { return mips_output_sync (); })
5119 (define_insn "synci"
5120   [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5121                     UNSPEC_SYNCI)]
5122   "TARGET_SYNCI"
5123   "synci\t0(%0)")
5125 (define_insn "rdhwr_synci_step_<mode>"
5126   [(set (match_operand:P 0 "register_operand" "=d")
5127         (unspec_volatile [(const_int 1)]
5128         UNSPEC_RDHWR))]
5129   "ISA_HAS_SYNCI"
5130   "rdhwr\t%0,$1")
5132 (define_insn "clear_hazard_<mode>"
5133   [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5134    (clobber (reg:P RETURN_ADDR_REGNUM))]
5135   "ISA_HAS_SYNCI"
5137   return "%(%<bal\t1f\n"
5138          "\tnop\n"
5139          "1:\t<d>addiu\t$31,$31,12\n"
5140          "\tjr.hb\t$31\n"
5141          "\tnop%>%)";
5143   [(set_attr "insn_count" "5")])
5145 ;; Cache operations for R4000-style caches.
5146 (define_insn "mips_cache"
5147   [(set (mem:BLK (scratch))
5148         (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5149                      (match_operand:QI 1 "address_operand" "p")]
5150                     UNSPEC_MIPS_CACHE))]
5151   "ISA_HAS_CACHE"
5152   "cache\t%X0,%a1")
5154 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5155 ;; operation.  We keep the pattern distinct so that we can identify
5156 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5157 ;; the operation is never inserted into a delay slot.
5158 (define_insn "r10k_cache_barrier"
5159   [(set (mem:BLK (scratch))
5160         (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5161   "ISA_HAS_CACHE"
5162   "cache\t0x14,0(%$)"
5163   [(set_attr "can_delay" "no")])
5165 ;; Block moves, see mips.c for more details.
5166 ;; Argument 0 is the destination
5167 ;; Argument 1 is the source
5168 ;; Argument 2 is the length
5169 ;; Argument 3 is the alignment
5171 (define_expand "movmemsi"
5172   [(parallel [(set (match_operand:BLK 0 "general_operand")
5173                    (match_operand:BLK 1 "general_operand"))
5174               (use (match_operand:SI 2 ""))
5175               (use (match_operand:SI 3 "const_int_operand"))])]
5176   "!TARGET_MIPS16 && !TARGET_MEMCPY"
5178   if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5179     DONE;
5180   else
5181     FAIL;
5185 ;;  ....................
5187 ;;      SHIFTS
5189 ;;  ....................
5191 (define_expand "<optab><mode>3"
5192   [(set (match_operand:GPR 0 "register_operand")
5193         (any_shift:GPR (match_operand:GPR 1 "register_operand")
5194                        (match_operand:SI 2 "arith_operand")))]
5195   ""
5197   /* On the mips16, a shift of more than 8 is a four byte instruction,
5198      so, for a shift between 8 and 16, it is just as fast to do two
5199      shifts of 8 or less.  If there is a lot of shifting going on, we
5200      may win in CSE.  Otherwise combine will put the shifts back
5201      together again.  This can be called by mips_function_arg, so we must
5202      be careful not to allocate a new register if we've reached the
5203      reload pass.  */
5204   if (TARGET_MIPS16
5205       && optimize
5206       && CONST_INT_P (operands[2])
5207       && INTVAL (operands[2]) > 8
5208       && INTVAL (operands[2]) <= 16
5209       && !reload_in_progress
5210       && !reload_completed)
5211     {
5212       rtx temp = gen_reg_rtx (<MODE>mode);
5214       emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5215       emit_insn (gen_<optab><mode>3 (operands[0], temp,
5216                                      GEN_INT (INTVAL (operands[2]) - 8)));
5217       DONE;
5218     }
5221 (define_insn "*<optab><mode>3"
5222   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
5223         (any_shift:GPR (match_operand:GPR 1 "register_operand" "!u,d")
5224                        (match_operand:SI 2 "arith_operand" "Uib3,dI")))]
5225   "!TARGET_MIPS16"
5227   if (CONST_INT_P (operands[2]))
5228     operands[2] = GEN_INT (INTVAL (operands[2])
5229                            & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5231   return "<d><insn>\t%0,%1,%2";
5233   [(set_attr "type" "shift")
5234    (set_attr "compression" "<shift_compression>,none")
5235    (set_attr "mode" "<MODE>")])
5237 (define_insn "*<optab>si3_extend"
5238   [(set (match_operand:DI 0 "register_operand" "=d")
5239         (sign_extend:DI
5240            (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5241                          (match_operand:SI 2 "arith_operand" "dI"))))]
5242   "TARGET_64BIT && !TARGET_MIPS16"
5244   if (CONST_INT_P (operands[2]))
5245     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5247   return "<insn>\t%0,%1,%2";
5249   [(set_attr "type" "shift")
5250    (set_attr "mode" "SI")])
5252 (define_insn "*<optab>si3_mips16"
5253   [(set (match_operand:SI 0 "register_operand" "=d,d,d")
5254         (any_shift:SI (match_operand:SI 1 "register_operand" "0,d,d")
5255                       (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5256   "TARGET_MIPS16"
5258   if (which_alternative == 0)
5259     return "<insn>\t%0,%2";
5261   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5262   return "<insn>\t%0,%1,%2";
5264   [(set_attr "type" "shift")
5265    (set_attr "mode" "SI")
5266    (set_attr "extended_mips16" "no,no,yes")])
5268 ;; We need separate DImode MIPS16 patterns because of the irregularity
5269 ;; of right shifts.
5270 (define_insn "*ashldi3_mips16"
5271   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5272         (ashift:DI (match_operand:DI 1 "register_operand" "0,d,d")
5273                    (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5274   "TARGET_64BIT && TARGET_MIPS16"
5276   if (which_alternative == 0)
5277     return "dsll\t%0,%2";
5279   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5280   return "dsll\t%0,%1,%2";
5282   [(set_attr "type" "shift")
5283    (set_attr "mode" "DI")
5284    (set_attr "extended_mips16" "no,no,yes")])
5286 (define_insn "*ashrdi3_mips16"
5287   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5288         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5289                      (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5290   "TARGET_64BIT && TARGET_MIPS16"
5292   if (CONST_INT_P (operands[2]))
5293     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5295   return "dsra\t%0,%2";
5297   [(set_attr "type" "shift")
5298    (set_attr "mode" "DI")
5299    (set_attr "extended_mips16" "no,no,yes")])
5301 (define_insn "*lshrdi3_mips16"
5302   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5303         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5304                      (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5305   "TARGET_64BIT && TARGET_MIPS16"
5307   if (CONST_INT_P (operands[2]))
5308     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5310   return "dsrl\t%0,%2";
5312   [(set_attr "type" "shift")
5313    (set_attr "mode" "DI")
5314    (set_attr "extended_mips16" "no,no,yes")])
5316 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5318 (define_split
5319   [(set (match_operand:GPR 0 "d_operand")
5320         (any_shift:GPR (match_operand:GPR 1 "d_operand")
5321                        (match_operand:GPR 2 "const_int_operand")))]
5322   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5323    && INTVAL (operands[2]) > 8
5324    && INTVAL (operands[2]) <= 16"
5325   [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5326    (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5327   { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5329 ;; If we load a byte on the mips16 as a bitfield, the resulting
5330 ;; sequence of instructions is too complicated for combine, because it
5331 ;; involves four instructions: a load, a shift, a constant load into a
5332 ;; register, and an and (the key problem here is that the mips16 does
5333 ;; not have and immediate).  We recognize a shift of a load in order
5334 ;; to make it simple enough for combine to understand.
5336 ;; The instruction count here is the worst case.
5337 (define_insn_and_split ""
5338   [(set (match_operand:SI 0 "register_operand" "=d")
5339         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5340                      (match_operand:SI 2 "immediate_operand" "I")))]
5341   "TARGET_MIPS16"
5342   "#"
5343   ""
5344   [(set (match_dup 0) (match_dup 1))
5345    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5346   ""
5347   [(set_attr "type"     "load")
5348    (set_attr "mode"     "SI")
5349    (set (attr "insn_count")
5350         (symbol_ref "mips_load_store_insns (operands[1], insn) + 2"))])
5352 (define_insn "rotr<mode>3"
5353   [(set (match_operand:GPR 0 "register_operand" "=d")
5354         (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5355                       (match_operand:SI 2 "arith_operand" "dI")))]
5356   "ISA_HAS_ROR"
5358   if (CONST_INT_P (operands[2]))
5359     gcc_assert (INTVAL (operands[2]) >= 0
5360                 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
5362   return "<d>ror\t%0,%1,%2";
5364   [(set_attr "type" "shift")
5365    (set_attr "mode" "<MODE>")])
5367 (define_insn "bswaphi2"
5368   [(set (match_operand:HI 0 "register_operand" "=d")
5369         (bswap:HI (match_operand:HI 1 "register_operand" "d")))]
5370   "ISA_HAS_WSBH"
5371   "wsbh\t%0,%1"
5372   [(set_attr "type" "shift")])
5374 (define_insn_and_split "bswapsi2"
5375   [(set (match_operand:SI 0 "register_operand" "=d")
5376         (bswap:SI (match_operand:SI 1 "register_operand" "d")))]
5377   "ISA_HAS_WSBH && ISA_HAS_ROR"
5378   "#"
5379   ""
5380   [(set (match_dup 0) (unspec:SI [(match_dup 1)] UNSPEC_WSBH))
5381    (set (match_dup 0) (rotatert:SI (match_dup 0) (const_int 16)))]
5382   ""
5383   [(set_attr "insn_count" "2")])
5385 (define_insn_and_split "bswapdi2"
5386   [(set (match_operand:DI 0 "register_operand" "=d")
5387         (bswap:DI (match_operand:DI 1 "register_operand" "d")))]
5388   "TARGET_64BIT && ISA_HAS_WSBH"
5389   "#"
5390   ""
5391   [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_DSBH))
5392    (set (match_dup 0) (unspec:DI [(match_dup 0)] UNSPEC_DSHD))]
5393   ""
5394   [(set_attr "insn_count" "2")])
5396 (define_insn "wsbh"
5397   [(set (match_operand:SI 0 "register_operand" "=d")
5398         (unspec:SI [(match_operand:SI 1 "register_operand" "d")] UNSPEC_WSBH))]
5399   "ISA_HAS_WSBH"
5400   "wsbh\t%0,%1"
5401   [(set_attr "type" "shift")])
5403 (define_insn "dsbh"
5404   [(set (match_operand:DI 0 "register_operand" "=d")
5405         (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSBH))]
5406   "TARGET_64BIT && ISA_HAS_WSBH"
5407   "dsbh\t%0,%1"
5408   [(set_attr "type" "shift")])
5410 (define_insn "dshd"
5411   [(set (match_operand:DI 0 "register_operand" "=d")
5412         (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSHD))]
5413   "TARGET_64BIT && ISA_HAS_WSBH"
5414   "dshd\t%0,%1"
5415   [(set_attr "type" "shift")])
5418 ;;  ....................
5420 ;;      CONDITIONAL BRANCHES
5422 ;;  ....................
5424 ;; Conditional branches on floating-point equality tests.
5426 (define_insn "*branch_fp"
5427   [(set (pc)
5428         (if_then_else
5429          (match_operator 1 "equality_operator"
5430                          [(match_operand:CC 2 "register_operand" "z")
5431                           (const_int 0)])
5432          (label_ref (match_operand 0 "" ""))
5433          (pc)))]
5434   "TARGET_HARD_FLOAT"
5436   return mips_output_conditional_branch (insn, operands,
5437                                          MIPS_BRANCH ("b%F1", "%Z2%0"),
5438                                          MIPS_BRANCH ("b%W1", "%Z2%0"));
5440   [(set_attr "type" "branch")])
5442 (define_insn "*branch_fp_inverted"
5443   [(set (pc)
5444         (if_then_else
5445          (match_operator 1 "equality_operator"
5446                          [(match_operand:CC 2 "register_operand" "z")
5447                           (const_int 0)])
5448          (pc)
5449          (label_ref (match_operand 0 "" ""))))]
5450   "TARGET_HARD_FLOAT"
5452   return mips_output_conditional_branch (insn, operands,
5453                                          MIPS_BRANCH ("b%W1", "%Z2%0"),
5454                                          MIPS_BRANCH ("b%F1", "%Z2%0"));
5456   [(set_attr "type" "branch")])
5458 ;; Conditional branches on ordered comparisons with zero.
5460 (define_insn "*branch_order<mode>"
5461   [(set (pc)
5462         (if_then_else
5463          (match_operator 1 "order_operator"
5464                          [(match_operand:GPR 2 "register_operand" "d")
5465                           (const_int 0)])
5466          (label_ref (match_operand 0 "" ""))
5467          (pc)))]
5468   "!TARGET_MIPS16"
5469   { return mips_output_order_conditional_branch (insn, operands, false); }
5470   [(set_attr "type" "branch")])
5472 (define_insn "*branch_order<mode>_inverted"
5473   [(set (pc)
5474         (if_then_else
5475          (match_operator 1 "order_operator"
5476                          [(match_operand:GPR 2 "register_operand" "d")
5477                           (const_int 0)])
5478          (pc)
5479          (label_ref (match_operand 0 "" ""))))]
5480   "!TARGET_MIPS16"
5481   { return mips_output_order_conditional_branch (insn, operands, true); }
5482   [(set_attr "type" "branch")])
5484 ;; Conditional branch on equality comparison.
5486 (define_insn "*branch_equality<mode>"
5487   [(set (pc)
5488         (if_then_else
5489          (match_operator 1 "equality_operator"
5490                          [(match_operand:GPR 2 "register_operand" "d")
5491                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5492          (label_ref (match_operand 0 "" ""))
5493          (pc)))]
5494   "!TARGET_MIPS16"
5496   /* For a simple BNEZ or BEQZ microMIPS branch.  */
5497   if (TARGET_MICROMIPS
5498       && operands[3] == const0_rtx
5499       && get_attr_length (insn) <= 8)
5500     return mips_output_conditional_branch (insn, operands,
5501                                            "%*b%C1z%:\t%2,%0",
5502                                            "%*b%N1z%:\t%2,%0");
5504   return mips_output_conditional_branch (insn, operands,
5505                                          MIPS_BRANCH ("b%C1", "%2,%z3,%0"),
5506                                          MIPS_BRANCH ("b%N1", "%2,%z3,%0"));
5508   [(set_attr "type" "branch")])
5510 (define_insn "*branch_equality<mode>_inverted"
5511   [(set (pc)
5512         (if_then_else
5513          (match_operator 1 "equality_operator"
5514                          [(match_operand:GPR 2 "register_operand" "d")
5515                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5516          (pc)
5517          (label_ref (match_operand 0 "" ""))))]
5518   "!TARGET_MIPS16"
5520   /* For a simple BNEZ or BEQZ microMIPS branch.  */
5521   if (TARGET_MICROMIPS
5522       && operands[3] == const0_rtx
5523       && get_attr_length (insn) <= 8)
5524     return mips_output_conditional_branch (insn, operands,
5525                                            "%*b%N0z%:\t%2,%1",
5526                                            "%*b%C0z%:\t%2,%1");
5528   return mips_output_conditional_branch (insn, operands,
5529                                          MIPS_BRANCH ("b%N1", "%2,%z3,%0"),
5530                                          MIPS_BRANCH ("b%C1", "%2,%z3,%0"));
5532   [(set_attr "type" "branch")])
5534 ;; MIPS16 branches
5536 (define_insn "*branch_equality<mode>_mips16"
5537   [(set (pc)
5538         (if_then_else
5539          (match_operator 1 "equality_operator"
5540                          [(match_operand:GPR 2 "register_operand" "d,t")
5541                           (const_int 0)])
5542          (label_ref (match_operand 0 "" ""))
5543          (pc)))]
5544   "TARGET_MIPS16"
5545   "@
5546    b%C1z\t%2,%0
5547    bt%C1z\t%0"
5548   [(set_attr "type" "branch")])
5550 (define_insn "*branch_equality<mode>_mips16_inverted"
5551   [(set (pc)
5552         (if_then_else
5553          (match_operator 1 "equality_operator"
5554                          [(match_operand:GPR 2 "register_operand" "d,t")
5555                           (const_int 0)])
5556          (pc)
5557          (label_ref (match_operand 0 "" ""))))]
5558   "TARGET_MIPS16"
5559   "@
5560    b%N1z\t%2,%0
5561    bt%N1z\t%0"
5562   [(set_attr "type" "branch")])
5564 (define_expand "cbranch<mode>4"
5565   [(set (pc)
5566         (if_then_else (match_operator 0 "comparison_operator"
5567                        [(match_operand:GPR 1 "register_operand")
5568                         (match_operand:GPR 2 "nonmemory_operand")])
5569                       (label_ref (match_operand 3 ""))
5570                       (pc)))]
5571   ""
5573   mips_expand_conditional_branch (operands);
5574   DONE;
5577 (define_expand "cbranch<mode>4"
5578   [(set (pc)
5579         (if_then_else (match_operator 0 "comparison_operator"
5580                        [(match_operand:SCALARF 1 "register_operand")
5581                         (match_operand:SCALARF 2 "register_operand")])
5582                       (label_ref (match_operand 3 ""))
5583                       (pc)))]
5584   ""
5586   mips_expand_conditional_branch (operands);
5587   DONE;
5590 ;; Used to implement built-in functions.
5591 (define_expand "condjump"
5592   [(set (pc)
5593         (if_then_else (match_operand 0)
5594                       (label_ref (match_operand 1))
5595                       (pc)))])
5597 ;; Branch if bit is set/clear.
5599 (define_insn "*branch_bit<bbv><mode>"
5600   [(set (pc)
5601         (if_then_else
5602          (equality_op (zero_extract:GPR
5603                        (match_operand:GPR 1 "register_operand" "d")
5604                        (const_int 1)
5605                        (match_operand 2 "const_int_operand" ""))
5606                       (const_int 0))
5607          (label_ref (match_operand 0 ""))
5608          (pc)))]
5609   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5611   return
5612     mips_output_conditional_branch (insn, operands,
5613                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
5614                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
5616   [(set_attr "type"          "branch")
5617    (set_attr "branch_likely" "no")])
5619 (define_insn "*branch_bit<bbv><mode>_inverted"
5620   [(set (pc)
5621         (if_then_else
5622          (equality_op (zero_extract:GPR
5623                        (match_operand:GPR 1 "register_operand" "d")
5624                        (const_int 1)
5625                        (match_operand 2 "const_int_operand" ""))
5626                       (const_int 0))
5627          (pc)
5628          (label_ref (match_operand 0 ""))))]
5629   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5631   return
5632     mips_output_conditional_branch (insn, operands,
5633                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
5634                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
5636   [(set_attr "type"          "branch")
5637    (set_attr "branch_likely" "no")])
5640 ;;  ....................
5642 ;;      SETTING A REGISTER FROM A COMPARISON
5644 ;;  ....................
5646 ;; Destination is always set in SI mode.
5648 (define_expand "cstore<mode>4"
5649   [(set (match_operand:SI 0 "register_operand")
5650         (match_operator:SI 1 "mips_cstore_operator"
5651          [(match_operand:GPR 2 "register_operand")
5652           (match_operand:GPR 3 "nonmemory_operand")]))]
5653   ""
5655   mips_expand_scc (operands);
5656   DONE;
5659 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
5660   [(set (match_operand:GPR2 0 "register_operand" "=d")
5661         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5662                  (const_int 0)))]
5663   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5664   "sltu\t%0,%1,1"
5665   [(set_attr "type" "slt")
5666    (set_attr "mode" "<GPR:MODE>")])
5668 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
5669   [(set (match_operand:GPR2 0 "register_operand" "=t")
5670         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5671                  (const_int 0)))]
5672   "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5673   "sltu\t%1,1"
5674   [(set_attr "type" "slt")
5675    (set_attr "mode" "<GPR:MODE>")])
5677 ;; Generate sltiu unless using seq results in better code.
5678 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
5679   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5680         (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5681                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5682   "ISA_HAS_SEQ_SNE"
5683   "@
5684    seq\t%0,%1,%2
5685    sltiu\t%0,%1,1
5686    seqi\t%0,%1,%2"
5687   [(set_attr "type" "slt")
5688    (set_attr "mode" "<GPR:MODE>")])
5690 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
5691   [(set (match_operand:GPR2 0 "register_operand" "=d")
5692         (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
5693                  (const_int 0)))]
5694   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5695   "sltu\t%0,%.,%1"
5696   [(set_attr "type" "slt")
5697    (set_attr "mode" "<GPR:MODE>")])
5699 ;; Generate sltu unless using sne results in better code.
5700 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
5701   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5702         (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5703                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5704   "ISA_HAS_SEQ_SNE"
5705   "@
5706    sne\t%0,%1,%2
5707    sltu\t%0,%.,%1
5708    snei\t%0,%1,%2"
5709   [(set_attr "type" "slt")
5710    (set_attr "mode" "<GPR:MODE>")])
5712 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
5713   [(set (match_operand:GPR2 0 "register_operand" "=d")
5714         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5715                      (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5716   "!TARGET_MIPS16"
5717   "slt<u>\t%0,%z2,%1"
5718   [(set_attr "type" "slt")
5719    (set_attr "mode" "<GPR:MODE>")])
5721 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
5722   [(set (match_operand:GPR2 0 "register_operand" "=t")
5723         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5724                      (match_operand:GPR 2 "register_operand" "d")))]
5725   "TARGET_MIPS16"
5726   "slt<u>\t%2,%1"
5727   [(set_attr "type" "slt")
5728    (set_attr "mode" "<GPR:MODE>")])
5730 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
5731   [(set (match_operand:GPR2 0 "register_operand" "=d")
5732         (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
5733                      (const_int 1)))]
5734   "!TARGET_MIPS16"
5735   "slt<u>\t%0,%.,%1"
5736   [(set_attr "type" "slt")
5737    (set_attr "mode" "<GPR:MODE>")])
5739 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
5740   [(set (match_operand:GPR2 0 "register_operand" "=d")
5741         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5742                      (match_operand:GPR 2 "arith_operand" "dI")))]
5743   "!TARGET_MIPS16"
5744   "slt<u>\t%0,%1,%2"
5745   [(set_attr "type" "slt")
5746    (set_attr "mode" "<GPR:MODE>")])
5748 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
5749   [(set (match_operand:GPR2 0 "register_operand" "=t,t,t")
5750         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d,d")
5751                      (match_operand:GPR 2 "arith_operand" "d,Uub8,I")))]
5752   "TARGET_MIPS16"
5753   "slt<u>\t%1,%2"
5754   [(set_attr "type" "slt")
5755    (set_attr "mode" "<GPR:MODE>")
5756    (set_attr "extended_mips16" "no,no,yes")])
5758 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
5759   [(set (match_operand:GPR2 0 "register_operand" "=d")
5760         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
5761                      (match_operand:GPR 2 "sle_operand" "")))]
5762   "!TARGET_MIPS16"
5764   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5765   return "slt<u>\t%0,%1,%2";
5767   [(set_attr "type" "slt")
5768    (set_attr "mode" "<GPR:MODE>")])
5770 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
5771   [(set (match_operand:GPR2 0 "register_operand" "=t,t")
5772         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
5773                      (match_operand:GPR 2 "sle_operand" "Udb8,i")))]
5774   "TARGET_MIPS16"
5776   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5777   return "slt<u>\t%1,%2";
5779   [(set_attr "type" "slt")
5780    (set_attr "mode" "<GPR:MODE>")
5781    (set_attr "extended_mips16" "no,yes")])
5784 ;;  ....................
5786 ;;      FLOATING POINT COMPARISONS
5788 ;;  ....................
5790 (define_insn "s<code>_<mode>"
5791   [(set (match_operand:CC 0 "register_operand" "=z")
5792         (fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5793                   (match_operand:SCALARF 2 "register_operand" "f")))]
5794   ""
5795   "c.<fcond>.<fmt>\t%Z0%1,%2"
5796   [(set_attr "type" "fcmp")
5797    (set_attr "mode" "FPSW")])
5799 (define_insn "s<code>_<mode>"
5800   [(set (match_operand:CC 0 "register_operand" "=z")
5801         (swapped_fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5802                           (match_operand:SCALARF 2 "register_operand" "f")))]
5803   ""
5804   "c.<swapped_fcond>.<fmt>\t%Z0%2,%1"
5805   [(set_attr "type" "fcmp")
5806    (set_attr "mode" "FPSW")])
5809 ;;  ....................
5811 ;;      UNCONDITIONAL BRANCHES
5813 ;;  ....................
5815 ;; Unconditional branches.
5817 (define_expand "jump"
5818   [(set (pc)
5819         (label_ref (match_operand 0)))])
5821 (define_insn "*jump_absolute"
5822   [(set (pc)
5823         (label_ref (match_operand 0)))]
5824   "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
5826   /* Use a branch for microMIPS.  The assembler will choose
5827      a 16-bit branch, a 32-bit branch, or a 32-bit jump.  */
5828   if (TARGET_MICROMIPS && !TARGET_ABICALLS_PIC2)
5829     return "%*b\t%l0%/";
5830   else
5831     return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/");
5833   [(set_attr "type" "jump")])
5835 (define_insn "*jump_pic"
5836   [(set (pc)
5837         (label_ref (match_operand 0)))]
5838   "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
5840   if (get_attr_length (insn) <= 8)
5841     return "%*b\t%l0%/";
5842   else
5843     {
5844       mips_output_load_label (operands[0]);
5845       return "%*jr\t%@%/%]";
5846     }
5848   [(set_attr "type" "branch")])
5850 ;; We need a different insn for the mips16, because a mips16 branch
5851 ;; does not have a delay slot.
5853 (define_insn "*jump_mips16"
5854   [(set (pc)
5855         (label_ref (match_operand 0 "" "")))]
5856   "TARGET_MIPS16"
5857   "b\t%l0"
5858   [(set_attr "type" "branch")
5859    (set (attr "length")
5860         ;; This calculation is like the normal branch one, but the
5861         ;; range of the unextended instruction is [-0x800, 0x7fe] rather
5862         ;; than [-0x100, 0xfe].  This translates to a range of:
5863         ;;
5864         ;;    [-(0x800 - sizeof (branch)), 0x7fe]
5865         ;; == [-0x7fe, 0x7fe]
5866         ;;
5867         ;; from the shorten_branches reference address.  Long-branch
5868         ;; sequences will replace this one, so the minimum length
5869         ;; is one instruction shorter than for conditional branches.
5870         (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
5871                     (le (minus (pc) (match_dup 0)) (const_int 2046)))
5872                (const_int 2)
5873                (and (le (minus (match_dup 0) (pc)) (const_int 65534))
5874                     (le (minus (pc) (match_dup 0)) (const_int 65532)))
5875                (const_int 4)
5876                (and (match_test "TARGET_ABICALLS")
5877                     (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
5878                (const_int 18)
5879                (match_test "Pmode == SImode")
5880                (const_int 14)
5881                ] (const_int 22)))])
5883 (define_expand "indirect_jump"
5884   [(set (pc) (match_operand 0 "register_operand"))]
5885   ""
5887   operands[0] = force_reg (Pmode, operands[0]);
5888   emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
5889   DONE;
5892 (define_insn "indirect_jump_<mode>"
5893   [(set (pc) (match_operand:P 0 "register_operand" "d"))]
5894   ""
5896   if (TARGET_MICROMIPS)
5897     return "%*jr%:\t%0";
5898   else
5899     return "%*j\t%0%/";
5901   [(set_attr "type" "jump")
5902    (set_attr "mode" "none")])
5904 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
5905 ;; sequences.  Having a dedicated pattern is more convenient than
5906 ;; creating a SEQUENCE for this special case.
5907 (define_insn "indirect_jump_and_restore_<mode>"
5908   [(set (pc) (match_operand:P 1 "register_operand" "d"))
5909    (set (match_operand:P 0 "register_operand" "=d")
5910         (match_operand:P 2 "register_operand" "y"))]
5911   ""
5912   "%(%<jr\t%1\;move\t%0,%2%>%)"
5913   [(set_attr "type" "multi")
5914    (set_attr "extended_mips16" "yes")])
5916 (define_expand "tablejump"
5917   [(set (pc)
5918         (match_operand 0 "register_operand"))
5919    (use (label_ref (match_operand 1 "")))]
5920   "!TARGET_MIPS16_SHORT_JUMP_TABLES"
5922   if (TARGET_GPWORD)
5923     operands[0] = expand_binop (Pmode, add_optab, operands[0],
5924                                 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
5925   else if (TARGET_RTP_PIC)
5926     {
5927       /* When generating RTP PIC, we use case table entries that are relative
5928          to the start of the function.  Add the function's address to the
5929          value we loaded.  */
5930       rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5931       operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
5932                                   start, 0, 0, OPTAB_WIDEN);
5933     }
5935   emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
5936   DONE;
5939 (define_insn "tablejump_<mode>"
5940   [(set (pc)
5941         (match_operand:P 0 "register_operand" "d"))
5942    (use (label_ref (match_operand 1 "" "")))]
5943   ""
5945   if (TARGET_MICROMIPS)
5946     return "%*jr%:\t%0";
5947   else
5948     return "%*j\t%0%/";
5950   [(set_attr "type" "jump")
5951    (set_attr "mode" "none")])
5953 ;; For MIPS16, we don't know whether a given jump table will use short or
5954 ;; word-sized offsets until late in compilation, when we are able to determine
5955 ;; the sizes of the insns which comprise the containing function.  This
5956 ;; necessitates the use of the casesi rather than the tablejump pattern, since
5957 ;; the latter tries to calculate the index of the offset to jump through early
5958 ;; in compilation, i.e. at expand time, when nothing is known about the
5959 ;; eventual function layout.
5961 (define_expand "casesi"
5962   [(match_operand:SI 0 "register_operand" "")   ; index to jump on
5963    (match_operand:SI 1 "const_int_operand" "")  ; lower bound
5964    (match_operand:SI 2 "const_int_operand" "")  ; total range
5965    (match_operand 3 "" "")                      ; table label
5966    (match_operand 4 "" "")]                     ; out of range label
5967   "TARGET_MIPS16_SHORT_JUMP_TABLES"
5969   if (operands[1] != const0_rtx)
5970     {
5971       rtx reg = gen_reg_rtx (SImode);
5972       rtx offset = gen_int_mode (-INTVAL (operands[1]), SImode);
5973       
5974       if (!arith_operand (offset, SImode))
5975         offset = force_reg (SImode, offset);
5976       
5977       emit_insn (gen_addsi3 (reg, operands[0], offset));
5978       operands[0] = reg;
5979     }
5981   if (!arith_operand (operands[0], SImode))
5982     operands[0] = force_reg (SImode, operands[0]);
5984   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5986   emit_jump_insn (PMODE_INSN (gen_casesi_internal_mips16,
5987                               (operands[0], operands[2],
5988                                operands[3], operands[4])));
5990   DONE;
5993 (define_insn "casesi_internal_mips16_<mode>"
5994   [(set (pc)
5995      (if_then_else
5996        (leu (match_operand:SI 0 "register_operand" "d")
5997             (match_operand:SI 1 "arith_operand" "dI"))
5998        (unspec:P
5999         [(match_dup 0)
6000          (label_ref (match_operand 2 "" ""))]
6001         UNSPEC_CASESI_DISPATCH)
6002        (label_ref (match_operand 3 "" ""))))
6003    (clobber (match_scratch:P 4 "=d"))
6004    (clobber (match_scratch:P 5 "=d"))
6005    (clobber (reg:SI MIPS16_T_REGNUM))]
6006   "TARGET_MIPS16_SHORT_JUMP_TABLES"
6008   rtx diff_vec = PATTERN (NEXT_INSN (operands[2]));
6010   gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
6011   
6012   output_asm_insn ("sltu\t%0, %1", operands);
6013   output_asm_insn ("bteqz\t%3", operands);
6014   
6015   switch (GET_MODE (diff_vec))
6016     {
6017     case HImode:
6018       output_asm_insn ("sll\t%5, %0, 1", operands);
6019       output_asm_insn ("la\t%4, %2", operands);
6020       output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6021       output_asm_insn ("lh\t%5, 0(%5)", operands);
6022       break;
6023     
6024     case SImode:
6025       output_asm_insn ("sll\t%5, %0, 2", operands);
6026       output_asm_insn ("la\t%4, %2", operands);
6027       output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6028       output_asm_insn ("lw\t%5, 0(%5)", operands);
6029       break;
6031     default:
6032       gcc_unreachable ();
6033     }
6034   
6035   output_asm_insn ("addu\t%4, %4, %5", operands);
6036   
6037   return "j\t%4";
6039   [(set_attr "insn_count" "16")])
6041 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
6042 ;; While it is possible to either pull it off the stack (in the
6043 ;; o32 case) or recalculate it given t9 and our target label,
6044 ;; it takes 3 or 4 insns to do so.
6046 (define_expand "builtin_setjmp_setup"
6047   [(use (match_operand 0 "register_operand"))]
6048   "TARGET_USE_GOT"
6050   rtx addr;
6052   addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
6053   mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
6054   DONE;
6057 ;; Restore the gp that we saved above.  Despite the earlier comment, it seems
6058 ;; that older code did recalculate the gp from $25.  Continue to jump through
6059 ;; $25 for compatibility (we lose nothing by doing so).
6061 (define_expand "builtin_longjmp"
6062   [(use (match_operand 0 "register_operand"))]
6063   "TARGET_USE_GOT"
6065   /* The elements of the buffer are, in order:  */
6066   int W = GET_MODE_SIZE (Pmode);
6067   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6068   rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
6069   rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
6070   rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
6071   rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6072   /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
6073      The target is bound to be using $28 as the global pointer
6074      but the current function might not be.  */
6075   rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
6077   /* This bit is similar to expand_builtin_longjmp except that it
6078      restores $gp as well.  */
6079   mips_emit_move (hard_frame_pointer_rtx, fp);
6080   mips_emit_move (pv, lab);
6081   emit_stack_restore (SAVE_NONLOCAL, stack);
6082   mips_emit_move (gp, gpv);
6083   emit_use (hard_frame_pointer_rtx);
6084   emit_use (stack_pointer_rtx);
6085   emit_use (gp);
6086   emit_indirect_jump (pv);
6087   DONE;
6091 ;;  ....................
6093 ;;      Function prologue/epilogue
6095 ;;  ....................
6098 (define_expand "prologue"
6099   [(const_int 1)]
6100   ""
6102   mips_expand_prologue ();
6103   DONE;
6106 ;; Block any insns from being moved before this point, since the
6107 ;; profiling call to mcount can use various registers that aren't
6108 ;; saved or used to pass arguments.
6110 (define_insn "blockage"
6111   [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
6112   ""
6113   ""
6114   [(set_attr "type" "ghost")
6115    (set_attr "mode" "none")])
6117 (define_insn "probe_stack_range_<P:mode>"
6118   [(set (match_operand:P 0 "register_operand" "=d")
6119         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
6120                             (match_operand:P 2 "register_operand" "d")]
6121                             UNSPEC_PROBE_STACK_RANGE))]
6122   ""
6123  { return mips_output_probe_stack_range (operands[0], operands[2]); }
6124   [(set_attr "type" "unknown")
6125    (set_attr "can_delay" "no")
6126    (set_attr "mode" "<MODE>")])
6128 (define_expand "epilogue"
6129   [(const_int 2)]
6130   ""
6132   mips_expand_epilogue (false);
6133   DONE;
6136 (define_expand "sibcall_epilogue"
6137   [(const_int 2)]
6138   ""
6140   mips_expand_epilogue (true);
6141   DONE;
6144 ;; Trivial return.  Make it look like a normal return insn as that
6145 ;; allows jump optimizations to work better.
6147 (define_expand "return"
6148   [(simple_return)]
6149   "mips_can_use_return_insn ()"
6150   { mips_expand_before_return (); })
6152 (define_expand "simple_return"
6153   [(simple_return)]
6154   ""
6155   { mips_expand_before_return (); })
6157 (define_insn "*<optab>"
6158   [(any_return)]
6159   ""
6160   "%*j\t$31%/"
6161   [(set_attr "type"     "jump")
6162    (set_attr "mode"     "none")])
6164 ;; Normal return.
6166 (define_insn "<optab>_internal"
6167   [(any_return)
6168    (use (match_operand 0 "pmode_register_operand" ""))]
6169   ""
6171   if (TARGET_MICROMIPS)
6172     return "%*jr%:\t%0";
6173   else
6174     return "%*j\t%0%/";
6176   [(set_attr "type"     "jump")
6177    (set_attr "mode"     "none")])
6179 ;; Exception return.
6180 (define_insn "mips_eret"
6181   [(return)
6182    (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6183   ""
6184   "eret"
6185   [(set_attr "type"     "trap")
6186    (set_attr "mode"     "none")])
6188 ;; Debug exception return.
6189 (define_insn "mips_deret"
6190   [(return)
6191    (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6192   ""
6193   "deret"
6194   [(set_attr "type"     "trap")
6195    (set_attr "mode"     "none")])
6197 ;; Disable interrupts.
6198 (define_insn "mips_di"
6199   [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6200   ""
6201   "di"
6202   [(set_attr "type"     "trap")
6203    (set_attr "mode"     "none")])
6205 ;; Execution hazard barrier.
6206 (define_insn "mips_ehb"
6207   [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6208   ""
6209   "ehb"
6210   [(set_attr "type"     "trap")
6211    (set_attr "mode"     "none")])
6213 ;; Read GPR from previous shadow register set.
6214 (define_insn "mips_rdpgpr"
6215   [(set (match_operand:SI 0 "register_operand" "=d")
6216         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d")]
6217                             UNSPEC_RDPGPR))]
6218   ""
6219   "rdpgpr\t%0,%1"
6220   [(set_attr "type"     "move")
6221    (set_attr "mode"     "SI")])
6223 ;; Move involving COP0 registers.
6224 (define_insn "cop0_move"
6225   [(set (match_operand:SI 0 "register_operand" "=B,d")
6226         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6227                             UNSPEC_COP0))]
6228   ""
6229 { return mips_output_move (operands[0], operands[1]); }
6230   [(set_attr "type"     "mtc,mfc")
6231    (set_attr "mode"     "SI")])
6233 ;; This is used in compiling the unwind routines.
6234 (define_expand "eh_return"
6235   [(use (match_operand 0 "general_operand"))]
6236   ""
6238   if (GET_MODE (operands[0]) != word_mode)
6239     operands[0] = convert_to_mode (word_mode, operands[0], 0);
6240   if (TARGET_64BIT)
6241     emit_insn (gen_eh_set_lr_di (operands[0]));
6242   else
6243     emit_insn (gen_eh_set_lr_si (operands[0]));
6244   DONE;
6247 ;; Clobber the return address on the stack.  We can't expand this
6248 ;; until we know where it will be put in the stack frame.
6250 (define_insn "eh_set_lr_si"
6251   [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6252    (clobber (match_scratch:SI 1 "=&d"))]
6253   "! TARGET_64BIT"
6254   "#")
6256 (define_insn "eh_set_lr_di"
6257   [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6258    (clobber (match_scratch:DI 1 "=&d"))]
6259   "TARGET_64BIT"
6260   "#")
6262 (define_split
6263   [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6264    (clobber (match_scratch 1))]
6265   "reload_completed"
6266   [(const_int 0)]
6268   mips_set_return_address (operands[0], operands[1]);
6269   DONE;
6272 (define_expand "exception_receiver"
6273   [(const_int 0)]
6274   "TARGET_USE_GOT"
6276   /* See the comment above load_call<mode> for details.  */
6277   emit_insn (gen_set_got_version ());
6279   /* If we have a call-clobbered $gp, restore it from its save slot.  */
6280   if (HAVE_restore_gp_si)
6281     emit_insn (gen_restore_gp_si ());
6282   else if (HAVE_restore_gp_di)
6283     emit_insn (gen_restore_gp_di ());
6284   DONE;
6287 (define_expand "nonlocal_goto_receiver"
6288   [(const_int 0)]
6289   "TARGET_USE_GOT"
6291   /* See the comment above load_call<mode> for details.  */
6292   emit_insn (gen_set_got_version ());
6293   DONE;
6296 ;; Restore $gp from its .cprestore stack slot.  The instruction remains
6297 ;; volatile until all uses of $28 are exposed.
6298 (define_insn_and_split "restore_gp_<mode>"
6299   [(set (reg:P 28)
6300         (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6301    (clobber (match_scratch:P 0 "=&d"))]
6302   "TARGET_CALL_CLOBBERED_GP"
6303   "#"
6304   "&& epilogue_completed"
6305   [(const_int 0)]
6307   mips_restore_gp_from_cprestore_slot (operands[0]);
6308   DONE;
6310   [(set_attr "type" "ghost")])
6312 ;; Move between $gp and its register save slot.
6313 (define_insn_and_split "move_gp<mode>"
6314   [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6315         (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6316                     UNSPEC_MOVE_GP))]
6317   ""
6318   { return mips_must_initialize_gp_p () ? "#" : ""; }
6319   "mips_must_initialize_gp_p ()"
6320   [(const_int 0)]
6322   mips_emit_move (operands[0], operands[1]);
6323   DONE;
6325   [(set_attr "type" "ghost")])
6328 ;;  ....................
6330 ;;      FUNCTION CALLS
6332 ;;  ....................
6334 ;; Instructions to load a call address from the GOT.  The address might
6335 ;; point to a function or to a lazy binding stub.  In the latter case,
6336 ;; the stub will use the dynamic linker to resolve the function, which
6337 ;; in turn will change the GOT entry to point to the function's real
6338 ;; address.
6340 ;; This means that every call, even pure and constant ones, can
6341 ;; potentially modify the GOT entry.  And once a stub has been called,
6342 ;; we must not call it again.
6344 ;; We represent this restriction using an imaginary, fixed, call-saved
6345 ;; register called GOT_VERSION_REGNUM.  The idea is to make the register
6346 ;; live throughout the function and to change its value after every
6347 ;; potential call site.  This stops any rtx value that uses the register
6348 ;; from being computed before an earlier call.  To do this, we:
6350 ;;    - Ensure that the register is live on entry to the function,
6351 ;;      so that it is never thought to be used uninitalized.
6353 ;;    - Ensure that the register is live on exit from the function,
6354 ;;      so that it is live throughout.
6356 ;;    - Make each call (lazily-bound or not) use the current value
6357 ;;      of GOT_VERSION_REGNUM, so that updates of the register are
6358 ;;      not moved across call boundaries.
6360 ;;    - Add "ghost" definitions of the register to the beginning of
6361 ;;      blocks reached by EH and ABNORMAL_CALL edges, because those
6362 ;;      edges may involve calls that normal paths don't.  (E.g. the
6363 ;;      unwinding code that handles a non-call exception may change
6364 ;;      lazily-bound GOT entries.)  We do this by making the
6365 ;;      exception_receiver and nonlocal_goto_receiver expanders emit
6366 ;;      a set_got_version instruction.
6368 ;;    - After each call (lazily-bound or not), use a "ghost"
6369 ;;      update_got_version instruction to change the register's value.
6370 ;;      This instruction mimics the _possible_ effect of the dynamic
6371 ;;      resolver during the call and it remains live even if the call
6372 ;;      itself becomes dead.
6374 ;;    - Leave GOT_VERSION_REGNUM out of all register classes.
6375 ;;      The register is therefore not a valid register_operand
6376 ;;      and cannot be moved to or from other registers.
6378 (define_insn "load_call<mode>"
6379   [(set (match_operand:P 0 "register_operand" "=d")
6380         (unspec:P [(match_operand:P 1 "register_operand" "d")
6381                    (match_operand:P 2 "immediate_operand" "")
6382                    (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6383   "TARGET_USE_GOT"
6384   "<load>\t%0,%R2(%1)"
6385   [(set_attr "got" "load")
6386    (set_attr "mode" "<MODE>")])
6388 (define_insn "set_got_version"
6389   [(set (reg:SI GOT_VERSION_REGNUM)
6390         (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6391   "TARGET_USE_GOT"
6392   ""
6393   [(set_attr "type" "ghost")])
6395 (define_insn "update_got_version"
6396   [(set (reg:SI GOT_VERSION_REGNUM)
6397         (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6398   "TARGET_USE_GOT"
6399   ""
6400   [(set_attr "type" "ghost")])
6402 ;; Sibling calls.  All these patterns use jump instructions.
6404 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6405 ;; addresses if a direct jump is acceptable.  Since the 'S' constraint
6406 ;; is defined in terms of call_insn_operand, the same is true of the
6407 ;; constraints.
6409 ;; When we use an indirect jump, we need a register that will be
6410 ;; preserved by the epilogue.  Since TARGET_USE_PIC_FN_ADDR_REG forces
6411 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6412 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6413 ;; as well.
6415 (define_expand "sibcall"
6416   [(parallel [(call (match_operand 0 "")
6417                     (match_operand 1 ""))
6418               (use (match_operand 2 ""))        ;; next_arg_reg
6419               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
6420   "TARGET_SIBCALLS"
6422   mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6423                     operands[1], operands[2], false);
6424   DONE;
6427 (define_insn "sibcall_internal"
6428   [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6429          (match_operand 1 "" ""))]
6430   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6432   if (TARGET_MICROMIPS)
6433     return MICROMIPS_J ("j", operands, 0);
6434   else
6435     return MIPS_CALL ("j", operands, 0, 1);
6437   [(set_attr "jal" "indirect,direct")
6438    (set_attr "jal_macro" "no")])
6440 (define_expand "sibcall_value"
6441   [(parallel [(set (match_operand 0 "")
6442                    (call (match_operand 1 "")
6443                          (match_operand 2 "")))
6444               (use (match_operand 3 ""))])]             ;; next_arg_reg
6445   "TARGET_SIBCALLS"
6447   mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6448                     operands[2], operands[3], false);
6449   DONE;
6452 (define_insn "sibcall_value_internal"
6453   [(set (match_operand 0 "register_operand" "")
6454         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6455               (match_operand 2 "" "")))]
6456   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6458   if (TARGET_MICROMIPS)
6459     return MICROMIPS_J ("j", operands, 1);
6460   else
6461     return MIPS_CALL ("j", operands, 1, 2);
6463   [(set_attr "jal" "indirect,direct")
6464    (set_attr "jal_macro" "no")])
6466 (define_insn "sibcall_value_multiple_internal"
6467   [(set (match_operand 0 "register_operand" "")
6468         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6469               (match_operand 2 "" "")))
6470    (set (match_operand 3 "register_operand" "")
6471         (call (mem:SI (match_dup 1))
6472               (match_dup 2)))]
6473   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6475   if (TARGET_MICROMIPS)
6476     return MICROMIPS_J ("j", operands, 1);
6477   else
6478     return MIPS_CALL ("j", operands, 1, 2);
6480   [(set_attr "jal" "indirect,direct")
6481    (set_attr "jal_macro" "no")])
6483 (define_expand "call"
6484   [(parallel [(call (match_operand 0 "")
6485                     (match_operand 1 ""))
6486               (use (match_operand 2 ""))        ;; next_arg_reg
6487               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
6488   ""
6490   mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6491                     operands[1], operands[2], false);
6492   DONE;
6495 ;; This instruction directly corresponds to an assembly-language "jal".
6496 ;; There are four cases:
6498 ;;    - -mno-abicalls:
6499 ;;        Both symbolic and register destinations are OK.  The pattern
6500 ;;        always expands to a single mips instruction.
6502 ;;    - -mabicalls/-mno-explicit-relocs:
6503 ;;        Again, both symbolic and register destinations are OK.
6504 ;;        The call is treated as a multi-instruction black box.
6506 ;;    - -mabicalls/-mexplicit-relocs with n32 or n64:
6507 ;;        Only "jal $25" is allowed.  This expands to a single "jalr $25"
6508 ;;        instruction.
6510 ;;    - -mabicalls/-mexplicit-relocs with o32 or o64:
6511 ;;        Only "jal $25" is allowed.  The call is actually two instructions:
6512 ;;        "jalr $25" followed by an insn to reload $gp.
6514 ;; In the last case, we can generate the individual instructions with
6515 ;; a define_split.  There are several things to be wary of:
6517 ;;   - We can't expose the load of $gp before reload.  If we did,
6518 ;;     it might get removed as dead, but reload can introduce new
6519 ;;     uses of $gp by rematerializing constants.
6521 ;;   - We shouldn't restore $gp after calls that never return.
6522 ;;     It isn't valid to insert instructions between a noreturn
6523 ;;     call and the following barrier.
6525 ;;   - The splitter deliberately changes the liveness of $gp.  The unsplit
6526 ;;     instruction preserves $gp and so have no effect on its liveness.
6527 ;;     But once we generate the separate insns, it becomes obvious that
6528 ;;     $gp is not live on entry to the call.
6530 (define_insn_and_split "call_internal"
6531   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6532          (match_operand 1 "" ""))
6533    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6534   ""
6535   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, 1); }
6536   "reload_completed && TARGET_SPLIT_CALLS"
6537   [(const_int 0)]
6539   mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
6540   DONE;
6542   [(set_attr "jal" "indirect,direct")])
6544 (define_insn "call_split"
6545   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6546          (match_operand 1 "" ""))
6547    (clobber (reg:SI RETURN_ADDR_REGNUM))
6548    (clobber (reg:SI 28))]
6549   "TARGET_SPLIT_CALLS"
6550   { return MIPS_CALL ("jal", operands, 0, 1); }
6551   [(set_attr "jal" "indirect,direct")
6552    (set_attr "jal_macro" "no")])
6554 ;; A pattern for calls that must be made directly.  It is used for
6555 ;; MIPS16 calls that the linker may need to redirect to a hard-float
6556 ;; stub; the linker relies on the call relocation type to detect when
6557 ;; such redirection is needed.
6558 (define_insn_and_split "call_internal_direct"
6559   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6560          (match_operand 1))
6561    (const_int 1)
6562    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6563   ""
6564   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, -1); }
6565   "reload_completed && TARGET_SPLIT_CALLS"
6566   [(const_int 0)]
6568   mips_split_call (curr_insn,
6569                    gen_call_direct_split (operands[0], operands[1]));
6570   DONE;
6572   [(set_attr "jal" "direct")])
6574 (define_insn "call_direct_split"
6575   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6576          (match_operand 1))
6577    (const_int 1)
6578    (clobber (reg:SI RETURN_ADDR_REGNUM))
6579    (clobber (reg:SI 28))]
6580   "TARGET_SPLIT_CALLS"
6581   { return MIPS_CALL ("jal", operands, 0, -1); }
6582   [(set_attr "jal" "direct")
6583    (set_attr "jal_macro" "no")])
6585 (define_expand "call_value"
6586   [(parallel [(set (match_operand 0 "")
6587                    (call (match_operand 1 "")
6588                          (match_operand 2 "")))
6589               (use (match_operand 3 ""))])]             ;; next_arg_reg
6590   ""
6592   mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
6593                     operands[2], operands[3], false);
6594   DONE;
6597 ;; See comment for call_internal.
6598 (define_insn_and_split "call_value_internal"
6599   [(set (match_operand 0 "register_operand" "")
6600         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6601               (match_operand 2 "" "")))
6602    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6603   ""
6604   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6605   "reload_completed && TARGET_SPLIT_CALLS"
6606   [(const_int 0)]
6608   mips_split_call (curr_insn,
6609                    gen_call_value_split (operands[0], operands[1],
6610                                          operands[2]));
6611   DONE;
6613   [(set_attr "jal" "indirect,direct")])
6615 (define_insn "call_value_split"
6616   [(set (match_operand 0 "register_operand" "")
6617         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6618               (match_operand 2 "" "")))
6619    (clobber (reg:SI RETURN_ADDR_REGNUM))
6620    (clobber (reg:SI 28))]
6621   "TARGET_SPLIT_CALLS"
6622   { return MIPS_CALL ("jal", operands, 1, 2); }
6623   [(set_attr "jal" "indirect,direct")
6624    (set_attr "jal_macro" "no")])
6626 ;; See call_internal_direct.
6627 (define_insn_and_split "call_value_internal_direct"
6628   [(set (match_operand 0 "register_operand")
6629         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6630               (match_operand 2)))
6631    (const_int 1)
6632    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6633   ""
6634   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, -1); }
6635   "reload_completed && TARGET_SPLIT_CALLS"
6636   [(const_int 0)]
6638   mips_split_call (curr_insn,
6639                    gen_call_value_direct_split (operands[0], operands[1],
6640                                                 operands[2]));
6641   DONE;
6643   [(set_attr "jal" "direct")])
6645 (define_insn "call_value_direct_split"
6646   [(set (match_operand 0 "register_operand")
6647         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6648               (match_operand 2)))
6649    (const_int 1)
6650    (clobber (reg:SI RETURN_ADDR_REGNUM))
6651    (clobber (reg:SI 28))]
6652   "TARGET_SPLIT_CALLS"
6653   { return MIPS_CALL ("jal", operands, 1, -1); }
6654   [(set_attr "jal" "direct")
6655    (set_attr "jal_macro" "no")])
6657 ;; See comment for call_internal.
6658 (define_insn_and_split "call_value_multiple_internal"
6659   [(set (match_operand 0 "register_operand" "")
6660         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6661               (match_operand 2 "" "")))
6662    (set (match_operand 3 "register_operand" "")
6663         (call (mem:SI (match_dup 1))
6664               (match_dup 2)))
6665    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6666   ""
6667   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6668   "reload_completed && TARGET_SPLIT_CALLS"
6669   [(const_int 0)]
6671   mips_split_call (curr_insn,
6672                    gen_call_value_multiple_split (operands[0], operands[1],
6673                                                   operands[2], operands[3]));
6674   DONE;
6676   [(set_attr "jal" "indirect,direct")])
6678 (define_insn "call_value_multiple_split"
6679   [(set (match_operand 0 "register_operand" "")
6680         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6681               (match_operand 2 "" "")))
6682    (set (match_operand 3 "register_operand" "")
6683         (call (mem:SI (match_dup 1))
6684               (match_dup 2)))
6685    (clobber (reg:SI RETURN_ADDR_REGNUM))
6686    (clobber (reg:SI 28))]
6687   "TARGET_SPLIT_CALLS"
6688   { return MIPS_CALL ("jal", operands, 1, 2); }
6689   [(set_attr "jal" "indirect,direct")
6690    (set_attr "jal_macro" "no")])
6692 ;; Call subroutine returning any type.
6694 (define_expand "untyped_call"
6695   [(parallel [(call (match_operand 0 "")
6696                     (const_int 0))
6697               (match_operand 1 "")
6698               (match_operand 2 "")])]
6699   ""
6701   int i;
6703   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
6705   for (i = 0; i < XVECLEN (operands[2], 0); i++)
6706     {
6707       rtx set = XVECEXP (operands[2], 0, i);
6708       mips_emit_move (SET_DEST (set), SET_SRC (set));
6709     }
6711   emit_insn (gen_blockage ());
6712   DONE;
6716 ;;  ....................
6718 ;;      MISC.
6720 ;;  ....................
6724 (define_insn "prefetch"
6725   [(prefetch (match_operand:QI 0 "address_operand" "ZD")
6726              (match_operand 1 "const_int_operand" "n")
6727              (match_operand 2 "const_int_operand" "n"))]
6728   "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
6730   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
6731     {
6732       /* Loongson 2[ef] and Loongson 3a use load to $0 for prefetching.  */
6733       if (TARGET_64BIT)
6734         return "ld\t$0,%a0";
6735       else
6736         return "lw\t$0,%a0";
6737     }
6738   operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
6739   return "pref\t%1,%a0";
6741   [(set_attr "type" "prefetch")])
6743 (define_insn "*prefetch_indexed_<mode>"
6744   [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
6745                      (match_operand:P 1 "register_operand" "d"))
6746              (match_operand 2 "const_int_operand" "n")
6747              (match_operand 3 "const_int_operand" "n"))]
6748   "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
6750   operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
6751   return "prefx\t%2,%1(%0)";
6753   [(set_attr "type" "prefetchx")])
6755 (define_insn "nop"
6756   [(const_int 0)]
6757   ""
6758   "%(nop%)"
6759   [(set_attr "type"     "nop")
6760    (set_attr "mode"     "none")])
6762 ;; Like nop, but commented out when outside a .set noreorder block.
6763 (define_insn "hazard_nop"
6764   [(const_int 1)]
6765   ""
6766   {
6767     if (mips_noreorder.nesting_level > 0)
6768       return "nop";
6769     else
6770       return "#nop";
6771   }
6772   [(set_attr "type"     "nop")])
6774 ;; MIPS4 Conditional move instructions.
6776 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
6777   [(set (match_operand:GPR 0 "register_operand" "=d,d")
6778         (if_then_else:GPR
6779          (match_operator:MOVECC 4 "equality_operator"
6780                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
6781                  (const_int 0)])
6782          (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
6783          (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
6784   "ISA_HAS_CONDMOVE"
6785   "@
6786     mov%T4\t%0,%z2,%1
6787     mov%t4\t%0,%z3,%1"
6788   [(set_attr "type" "condmove")
6789    (set_attr "mode" "<GPR:MODE>")])
6791 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
6792   [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
6793         (if_then_else:SCALARF
6794          (match_operator:MOVECC 4 "equality_operator"
6795                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
6796                  (const_int 0)])
6797          (match_operand:SCALARF 2 "register_operand" "f,0")
6798          (match_operand:SCALARF 3 "register_operand" "0,f")))]
6799   "ISA_HAS_FP_CONDMOVE"
6800   "@
6801     mov%T4.<fmt>\t%0,%2,%1
6802     mov%t4.<fmt>\t%0,%3,%1"
6803   [(set_attr "type" "condmove")
6804    (set_attr "mode" "<SCALARF:MODE>")])
6806 ;; These are the main define_expand's used to make conditional moves.
6808 (define_expand "mov<mode>cc"
6809   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6810    (set (match_operand:GPR 0 "register_operand")
6811         (if_then_else:GPR (match_dup 5)
6812                           (match_operand:GPR 2 "reg_or_0_operand")
6813                           (match_operand:GPR 3 "reg_or_0_operand")))]
6814   "ISA_HAS_CONDMOVE"
6816   mips_expand_conditional_move (operands);
6817   DONE;
6820 (define_expand "mov<mode>cc"
6821   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6822    (set (match_operand:SCALARF 0 "register_operand")
6823         (if_then_else:SCALARF (match_dup 5)
6824                               (match_operand:SCALARF 2 "register_operand")
6825                               (match_operand:SCALARF 3 "register_operand")))]
6826   "ISA_HAS_FP_CONDMOVE"
6828   mips_expand_conditional_move (operands);
6829   DONE;
6833 ;;  ....................
6835 ;;      mips16 inline constant tables
6837 ;;  ....................
6840 (define_insn "consttable_tls_reloc"
6841   [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
6842                      (match_operand 1 "const_int_operand" "")]
6843                     UNSPEC_CONSTTABLE_INT)]
6844   "TARGET_MIPS16_PCREL_LOADS"
6845   { return mips_output_tls_reloc_directive (&operands[0]); }
6846   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
6848 (define_insn "consttable_int"
6849   [(unspec_volatile [(match_operand 0 "consttable_operand" "")
6850                      (match_operand 1 "const_int_operand" "")]
6851                     UNSPEC_CONSTTABLE_INT)]
6852   "TARGET_MIPS16"
6854   assemble_integer (mips_strip_unspec_address (operands[0]),
6855                     INTVAL (operands[1]),
6856                     BITS_PER_UNIT * INTVAL (operands[1]), 1);
6857   return "";
6859   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
6861 (define_insn "consttable_float"
6862   [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
6863                     UNSPEC_CONSTTABLE_FLOAT)]
6864   "TARGET_MIPS16"
6866   REAL_VALUE_TYPE d;
6868   gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
6869   REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
6870   assemble_real (d, GET_MODE (operands[0]),
6871                  GET_MODE_BITSIZE (GET_MODE (operands[0])));
6872   return "";
6874   [(set (attr "length")
6875         (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
6877 (define_insn "align"
6878   [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
6879   ""
6880   ".align\t%0"
6881   [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
6883 (define_split
6884   [(match_operand 0 "small_data_pattern")]
6885   "reload_completed"
6886   [(match_dup 0)]
6887   { operands[0] = mips_rewrite_small_data (operands[0]); })
6890 ;;  ....................
6892 ;;      MIPS16e Save/Restore
6894 ;;  ....................
6897 (define_insn "*mips16e_save_restore"
6898   [(match_parallel 0 ""
6899        [(set (match_operand:SI 1 "register_operand")
6900              (plus:SI (match_dup 1)
6901                       (match_operand:SI 2 "const_int_operand")))])]
6902   "operands[1] == stack_pointer_rtx
6903    && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
6904   { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
6905   [(set_attr "type" "arith")
6906    (set_attr "extended_mips16" "yes")])
6908 ;; Thread-Local Storage
6910 ;; The TLS base pointer is accessed via "rdhwr $3, $29".  No current
6911 ;; MIPS architecture defines this register, and no current
6912 ;; implementation provides it; instead, any OS which supports TLS is
6913 ;; expected to trap and emulate this instruction.  rdhwr is part of the
6914 ;; MIPS 32r2 specification, but we use it on any architecture because
6915 ;; we expect it to be emulated.  Use .set to force the assembler to
6916 ;; accept it.
6918 ;; We do not use a constraint to force the destination to be $3
6919 ;; because $3 can appear explicitly as a function return value.
6920 ;; If we leave the use of $3 implicit in the constraints until
6921 ;; reload, we may end up making a $3 return value live across
6922 ;; the instruction, leading to a spill failure when reloading it.
6923 (define_insn_and_split "tls_get_tp_<mode>"
6924   [(set (match_operand:P 0 "register_operand" "=d")
6925         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
6926    (clobber (reg:P TLS_GET_TP_REGNUM))]
6927   "HAVE_AS_TLS && !TARGET_MIPS16"
6928   "#"
6929   "&& reload_completed"
6930   [(set (reg:P TLS_GET_TP_REGNUM)
6931         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
6932    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
6933   ""
6934   [(set_attr "type" "unknown")
6935    (set_attr "mode" "<MODE>")
6936    (set_attr "insn_count" "2")])
6938 (define_insn "*tls_get_tp_<mode>_split"
6939   [(set (reg:P TLS_GET_TP_REGNUM)
6940         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
6941   "HAVE_AS_TLS && !TARGET_MIPS16"
6942   ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop"
6943   [(set_attr "type" "unknown")
6944    ; Since rdhwr always generates a trap for now, putting it in a delay
6945    ; slot would make the kernel's emulation of it much slower.
6946    (set_attr "can_delay" "no")
6947    (set_attr "mode" "<MODE>")])
6949 ;; In MIPS16 mode, the TLS base pointer is accessed by a
6950 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
6951 ;; accessible in MIPS16.
6953 ;; This is not represented as a call insn, to avoid the
6954 ;; unnecesarry clobbering of caller-save registers by a
6955 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
6957 ;; A $25 clobber is added to cater for a $25 load stub added by the
6958 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
6960 (define_insn_and_split "tls_get_tp_mips16_<mode>"
6961   [(set (match_operand:P 0 "register_operand" "=d")
6962         (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
6963                   UNSPEC_TLS_GET_TP))
6964    (clobber (reg:P TLS_GET_TP_REGNUM))
6965    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
6966    (clobber (reg:P RETURN_ADDR_REGNUM))]
6967   "HAVE_AS_TLS && TARGET_MIPS16"
6968   "#"
6969   "&& reload_completed"
6970   [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
6971                    (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
6972               (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
6973               (clobber (reg:P RETURN_ADDR_REGNUM))])
6974    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
6975   ""
6976   [(set_attr "type" "multi")
6977    (set_attr "insn_count" "4")
6978    (set_attr "mode" "<MODE>")])
6980 (define_insn "*tls_get_tp_mips16_call_<mode>"
6981   [(set (reg:P TLS_GET_TP_REGNUM)
6982         (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
6983                   UNSPEC_TLS_GET_TP))
6984    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
6985    (clobber (reg:P RETURN_ADDR_REGNUM))]
6986   "HAVE_AS_TLS && TARGET_MIPS16"
6987   { return MIPS_CALL ("jal", operands, 0, -1); }
6988   [(set_attr "type" "call")
6989    (set_attr "insn_count" "3")
6990    (set_attr "mode" "<MODE>")])
6992 ;; Named pattern for expanding thread pointer reference.
6993 (define_expand "get_thread_pointer<mode>"
6994   [(match_operand:P 0 "register_operand" "=d")]
6995   "HAVE_AS_TLS"
6997   mips_expand_thread_pointer (operands[0]);
6998   DONE;
7002 ;; Synchronization instructions.
7004 (include "sync.md")
7006 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
7008 (include "mips-ps-3d.md")
7010 ; The MIPS DSP Instructions.
7012 (include "mips-dsp.md")
7014 ; The MIPS DSP REV 2 Instructions.
7016 (include "mips-dspr2.md")
7018 ; MIPS fixed-point instructions.
7019 (include "mips-fixed.md")
7021 ; microMIPS patterns.
7022 (include "micromips.md")
7024 ; ST-Microelectronics Loongson-2E/2F-specific patterns.
7025 (include "loongson.md")
7027 (define_c_enum "unspec" [
7028   UNSPEC_ADDRESS_FIRST