1 ;; Mips.md Machine Description for MIPS based processors
2 ;; Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5 ;; Free Software Foundation, Inc.
6 ;; Contributed by A. Lichnewsky, lich@inria.inria.fr
7 ;; Changes by Michael Meissner, meissner@osf.org
8 ;; 64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
9 ;; Brendan Eich, brendan@microunity.com.
11 ;; This file is part of GCC.
13 ;; GCC is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
18 ;; GCC is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GCC; see the file COPYING3. If not see
25 ;; <http://www.gnu.org/licenses/>.
27 (define_enum "processor" [
72 (define_c_enum "unspec" [
73 ;; Unaligned accesses.
79 ;; Floating-point moves.
95 UNSPEC_POTENTIAL_CPRESTORE
100 UNSPEC_SET_GOT_VERSION
101 UNSPEC_UPDATE_GOT_VERSION
103 ;; Symbolic accesses.
108 UNSPEC_UNSHIFTED_HIGH
110 ;; MIPS16 constant pools.
112 UNSPEC_CONSTTABLE_INT
113 UNSPEC_CONSTTABLE_FLOAT
115 ;; Blockage and synchronisation.
122 ;; Cache manipulation.
124 UNSPEC_R10K_CACHE_BARRIER
126 ;; Interrupt handling.
134 ;; Used in a call expression in place of args_size. It's present for PIC
135 ;; indirect calls where it contains args_size and the function symbol.
140 [(TLS_GET_TP_REGNUM 3)
141 (PIC_FUNCTION_ADDR_REGNUM 25)
142 (RETURN_ADDR_REGNUM 31)
143 (CPRESTORE_SLOT_REGNUM 76)
144 (GOT_VERSION_REGNUM 79)
146 ;; PIC long branch sequences are never longer than 100 bytes.
147 (MAX_PIC_BRANCH_LENGTH 100)
151 (include "predicates.md")
152 (include "constraints.md")
154 ;; ....................
158 ;; ....................
160 (define_attr "got" "unset,xgot_high,load"
161 (const_string "unset"))
163 ;; For jal instructions, this attribute is DIRECT when the target address
164 ;; is symbolic and INDIRECT when it is a register.
165 (define_attr "jal" "unset,direct,indirect"
166 (const_string "unset"))
168 ;; This attribute is YES if the instruction is a jal macro (not a
169 ;; real jal instruction).
171 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
172 ;; an instruction to restore $gp. Direct jals are also macros for
173 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
175 (define_attr "jal_macro" "no,yes"
176 (cond [(eq_attr "jal" "direct")
177 (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
178 ? JAL_MACRO_YES : JAL_MACRO_NO)")
179 (eq_attr "jal" "indirect")
180 (symbol_ref "(TARGET_CALL_CLOBBERED_GP
181 ? JAL_MACRO_YES : JAL_MACRO_NO)")]
182 (const_string "no")))
184 ;; Classification of moves, extensions and truncations. Most values
185 ;; are as for "type" (see below) but there are also the following
186 ;; move-specific values:
188 ;; constN move an N-constraint integer into a MIPS16 register
189 ;; sll0 "sll DEST,SRC,0", which on 64-bit targets is guaranteed
190 ;; to produce a sign-extended DEST, even if SRC is not
191 ;; properly sign-extended
192 ;; ext_ins EXT, DEXT, INS or DINS instruction
193 ;; andi a single ANDI instruction
194 ;; loadpool move a constant into a MIPS16 register by loading it
196 ;; shift_shift a shift left followed by a shift right
197 ;; lui_movf an LUI followed by a MOVF (for d<-z CC moves)
199 ;; This attribute is used to determine the instruction's length and
200 ;; scheduling type. For doubleword moves, the attribute always describes
201 ;; the split instructions; in some cases, it is more appropriate for the
202 ;; scheduling type to be "multi" instead.
203 (define_attr "move_type"
204 "unknown,load,fpload,store,fpstore,mtc,mfc,mtlo,mflo,move,fmove,
205 const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
206 shift_shift,lui_movf"
207 (const_string "unknown"))
209 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor"
210 (const_string "unknown"))
212 ;; Main data type used by the insn
213 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW"
214 (const_string "unknown"))
216 ;; True if the main data type is twice the size of a word.
217 (define_attr "dword_mode" "no,yes"
218 (cond [(and (eq_attr "mode" "DI,DF")
219 (not (match_test "TARGET_64BIT")))
222 (and (eq_attr "mode" "TI,TF")
223 (match_test "TARGET_64BIT"))
224 (const_string "yes")]
225 (const_string "no")))
227 ;; Attributes describing a sync loop. These loops have the form:
229 ;; if (RELEASE_BARRIER == YES) sync
231 ;; if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
232 ;; CMP = 0 [delay slot]
233 ;; $TMP1 = OLDVAL & EXCLUSIVE_MASK
234 ;; $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
235 ;; $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
236 ;; $AT |= $TMP1 | $TMP3
237 ;; if (!commit (*MEM = $AT)) goto 1.
238 ;; if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
240 ;; if (ACQUIRE_BARRIER == YES) sync
243 ;; where "$" values are temporaries and where the other values are
244 ;; specified by the attributes below. Values are specified as operand
245 ;; numbers and insns are specified as enums. If no operand number is
246 ;; specified, the following values are used instead:
251 ;; - INCLUSIVE_MASK: -1
252 ;; - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
253 ;; - EXCLUSIVE_MASK: 0
255 ;; MEM and INSN1_OP2 are required.
257 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
258 ;; but the gen* programs don't yet support that.
259 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
260 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
261 (define_attr "sync_cmp" "none,0,1,2,3,4,5" (const_string "none"))
262 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
263 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
264 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
265 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
266 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
267 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
268 (const_string "move"))
269 (define_attr "sync_insn2" "nop,and,xor,not"
270 (const_string "nop"))
271 ;; Memory model specifier.
272 ;; "0"-"9" values specify the operand that stores the memory model value.
273 ;; "10" specifies MEMMODEL_ACQ_REL,
274 ;; "11" specifies MEMMODEL_ACQUIRE.
275 (define_attr "sync_memmodel" "" (const_int 10))
278 ;; Classification of each insn.
279 ;; branch conditional branch
280 ;; jump unconditional jump
281 ;; call unconditional call
282 ;; load load instruction(s)
283 ;; fpload floating point load
284 ;; fpidxload floating point indexed load
285 ;; store store instruction(s)
286 ;; fpstore floating point store
287 ;; fpidxstore floating point indexed store
288 ;; prefetch memory prefetch (register + offset)
289 ;; prefetchx memory indexed prefetch (register + register)
290 ;; condmove conditional moves
291 ;; mtc transfer to coprocessor
292 ;; mfc transfer from coprocessor
293 ;; mthi transfer to a hi register
294 ;; mtlo transfer to a lo register
295 ;; mfhi transfer from a hi register
296 ;; mflo transfer from a lo register
297 ;; const load constant
298 ;; arith integer arithmetic instructions
299 ;; logical integer logical instructions
300 ;; shift integer shift instructions
301 ;; slt set less than instructions
302 ;; signext sign extend instructions
303 ;; clz the clz and clo instructions
304 ;; pop the pop instruction
305 ;; trap trap if instructions
306 ;; imul integer multiply 2 operands
307 ;; imul3 integer multiply 3 operands
308 ;; imul3nc integer multiply 3 operands without clobbering HI/LO
309 ;; imadd integer multiply-add
310 ;; idiv integer divide 2 operands
311 ;; idiv3 integer divide 3 operands
312 ;; move integer register move ({,D}ADD{,U} with rt = 0)
313 ;; fmove floating point register move
314 ;; fadd floating point add/subtract
315 ;; fmul floating point multiply
316 ;; fmadd floating point multiply-add
317 ;; fdiv floating point divide
318 ;; frdiv floating point reciprocal divide
319 ;; frdiv1 floating point reciprocal divide step 1
320 ;; frdiv2 floating point reciprocal divide step 2
321 ;; fabs floating point absolute value
322 ;; fneg floating point negation
323 ;; fcmp floating point compare
324 ;; fcvt floating point convert
325 ;; fsqrt floating point square root
326 ;; frsqrt floating point reciprocal square root
327 ;; frsqrt1 floating point reciprocal square root step1
328 ;; frsqrt2 floating point reciprocal square root step2
329 ;; multi multiword sequence (or user asm statements)
330 ;; atomic atomic memory update instruction
331 ;; syncloop memory atomic operation implemented as a sync loop
333 ;; ghost an instruction that produces no real code
335 "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
336 prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical,
337 shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
338 fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
339 frsqrt,frsqrt1,frsqrt2,multi,atomic,syncloop,nop,ghost"
340 (cond [(eq_attr "jal" "!unset") (const_string "call")
341 (eq_attr "got" "load") (const_string "load")
343 (eq_attr "alu_type" "add,sub") (const_string "arith")
345 (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
347 ;; If a doubleword move uses these expensive instructions,
348 ;; it is usually better to schedule them in the same way
349 ;; as the singleword form, rather than as "multi".
350 (eq_attr "move_type" "load") (const_string "load")
351 (eq_attr "move_type" "fpload") (const_string "fpload")
352 (eq_attr "move_type" "store") (const_string "store")
353 (eq_attr "move_type" "fpstore") (const_string "fpstore")
354 (eq_attr "move_type" "mtc") (const_string "mtc")
355 (eq_attr "move_type" "mfc") (const_string "mfc")
356 (eq_attr "move_type" "mtlo") (const_string "mtlo")
357 (eq_attr "move_type" "mflo") (const_string "mflo")
359 ;; These types of move are always single insns.
360 (eq_attr "move_type" "fmove") (const_string "fmove")
361 (eq_attr "move_type" "loadpool") (const_string "load")
362 (eq_attr "move_type" "signext") (const_string "signext")
363 (eq_attr "move_type" "ext_ins") (const_string "arith")
364 (eq_attr "move_type" "arith") (const_string "arith")
365 (eq_attr "move_type" "logical") (const_string "logical")
366 (eq_attr "move_type" "sll0") (const_string "shift")
367 (eq_attr "move_type" "andi") (const_string "logical")
369 ;; These types of move are always split.
370 (eq_attr "move_type" "constN,shift_shift")
371 (const_string "multi")
373 ;; These types of move are split for doubleword modes only.
374 (and (eq_attr "move_type" "move,const")
375 (eq_attr "dword_mode" "yes"))
376 (const_string "multi")
377 (eq_attr "move_type" "move") (const_string "move")
378 (eq_attr "move_type" "const") (const_string "const")
379 (eq_attr "sync_mem" "!none") (const_string "syncloop")]
380 ;; We classify "lui_movf" as "unknown" rather than "multi"
381 ;; because we don't split it. FIXME: we should split instead.
382 (const_string "unknown")))
384 ;; Mode for conversion types (fcvt)
385 ;; I2S integer to float single (SI/DI to SF)
386 ;; I2D integer to float double (SI/DI to DF)
387 ;; S2I float to integer (SF to SI/DI)
388 ;; D2I float to integer (DF to SI/DI)
389 ;; D2S double to float single
390 ;; S2D float single to double
392 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D"
393 (const_string "unknown"))
395 ;; Is this an extended instruction in mips16 mode?
396 (define_attr "extended_mips16" "no,yes"
397 (if_then_else (ior (eq_attr "move_type" "sll0")
398 (eq_attr "type" "branch")
399 (eq_attr "jal" "direct"))
401 (const_string "no")))
403 ;; Length of instruction in bytes.
404 (define_attr "length" ""
405 (cond [;; Direct branch instructions have a range of [-0x20000,0x1fffc],
406 ;; relative to the address of the delay slot. If a branch is
407 ;; outside this range, we have a choice of two sequences.
408 ;; For PIC, an out-of-range branch like:
413 ;; becomes the equivalent of:
422 ;; The non-PIC case is similar except that we use a direct
423 ;; jump instead of an la/jr pair. Since the target of this
424 ;; jump is an absolute 28-bit bit address (the other bits
425 ;; coming from the address of the delay slot) this form cannot
426 ;; cross a 256MB boundary. We could provide the option of
427 ;; using la/jr in this case too, but we do not do so at
430 ;; The value we specify here does not account for the delay slot
431 ;; instruction, whose length is added separately. If the RTL
432 ;; pattern has no explicit delay slot, mips_adjust_insn_length
433 ;; will add the length of the implicit nop. The range of
434 ;; [-0x20000, 0x1fffc] from the address of the delay slot
435 ;; therefore translates to a range of:
437 ;; [-(0x20000 - sizeof (branch)), 0x1fffc - sizeof (slot)]
438 ;; == [-0x1fffc, 0x1fff8]
440 ;; from the shorten_branches reference address.
441 (and (eq_attr "type" "branch")
442 (not (match_test "TARGET_MIPS16")))
443 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 131064))
444 (le (minus (pc) (match_dup 0)) (const_int 131068)))
447 ;; The non-PIC case: branch, first delay slot, and J.
448 (match_test "TARGET_ABSOLUTE_JUMPS")
451 ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
452 ;; mips_adjust_insn_length substitutes the correct length.
454 ;; Note that we can't simply use (symbol_ref ...) here
455 ;; because genattrtab needs to know the maximum length
457 (const_int MAX_PIC_BRANCH_LENGTH))
459 ;; An unextended MIPS16 branch has a range of [-0x100, 0xfe]
460 ;; from the address of the following instruction, which leads
463 ;; [-(0x100 - sizeof (branch)), 0xfe]
466 ;; from the shorten_branches reference address. Extended branches
467 ;; likewise have a range of [-0x10000, 0xfffe] from the address
468 ;; of the following instruction, which leads to a range of:
470 ;; [-(0x10000 - sizeof (branch)), 0xfffe]
471 ;; == [-0xfffc, 0xfffe]
473 ;; from the reference address.
475 ;; When a branch is out of range, mips_reorg splits it into a form
476 ;; that uses in-range branches. There are four basic sequences:
478 ;; (1) Absolute addressing with a readable text segment
479 ;; (32-bit addresses):
482 ;; move $1,$2 2 bytes
483 ;; lw $2,label 2 bytes
485 ;; move $2,$1 2 bytes
486 ;; .align 2 0 or 2 bytes
488 ;; .word target 4 bytes
490 ;; (16 bytes in the worst case)
492 ;; (2) Absolute addressing with a readable text segment
493 ;; (64-bit addresses):
496 ;; move $1,$2 2 bytes
497 ;; ld $2,label 2 bytes
499 ;; move $2,$1 2 bytes
500 ;; .align 3 0 to 6 bytes
502 ;; .dword target 8 bytes
504 ;; (24 bytes in the worst case)
506 ;; (3) Absolute addressing without a readable text segment
507 ;; (which requires 32-bit addresses at present):
510 ;; move $1,$2 2 bytes
511 ;; lui $2,%hi(target) 4 bytes
514 ;; addiu $2,%lo(target) 4 bytes
516 ;; move $2,$1 2 bytes
520 ;; (4) PIC addressing (which requires 32-bit addresses at present):
523 ;; move $1,$2 2 bytes
524 ;; lw $2,cprestore 0, 2 or 4 bytes
525 ;; lw $2,%got(target)($2) 4 bytes
526 ;; addiu $2,%lo(target) 4 bytes
528 ;; move $2,$1 2 bytes
530 ;; (20 bytes in the worst case)
532 ;; Note that the conditions test adjusted lengths, whereas the
533 ;; result is an unadjusted length, and is thus twice the true value.
534 (and (eq_attr "type" "branch")
535 (match_test "TARGET_MIPS16"))
536 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
537 (le (minus (pc) (match_dup 0)) (const_int 254)))
539 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
540 (le (minus (pc) (match_dup 0)) (const_int 65532)))
542 (and (match_test "TARGET_ABICALLS")
543 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
545 (match_test "Pmode == SImode")
549 (and (eq_attr "extended_mips16" "yes")
550 (match_test "TARGET_MIPS16"))
553 ;; "Ghost" instructions occupy no space.
554 (eq_attr "type" "ghost")
557 (eq_attr "got" "load")
558 (if_then_else (match_test "TARGET_MIPS16")
561 (eq_attr "got" "xgot_high")
564 ;; In general, constant-pool loads are extended instructions.
565 (eq_attr "move_type" "loadpool")
568 ;; LUI_MOVFs are decomposed into two separate instructions.
569 (eq_attr "move_type" "lui_movf")
572 ;; SHIFT_SHIFTs are decomposed into two separate instructions.
573 ;; They are extended instructions on MIPS16 targets.
574 (eq_attr "move_type" "shift_shift")
575 (if_then_else (match_test "TARGET_MIPS16")
579 ;; Check for doubleword moves that are decomposed into two
581 (and (eq_attr "move_type" "mtc,mfc,mtlo,mflo,move")
582 (eq_attr "dword_mode" "yes"))
585 ;; Doubleword CONST{,N} moves are split into two word
587 (and (eq_attr "move_type" "const,constN")
588 (eq_attr "dword_mode" "yes"))
589 (symbol_ref "mips_split_const_insns (operands[1]) * 4")
591 ;; Otherwise, constants, loads and stores are handled by external
593 (eq_attr "move_type" "const,constN")
594 (symbol_ref "mips_const_insns (operands[1]) * 4")
595 (eq_attr "move_type" "load,fpload")
596 (symbol_ref "mips_load_store_insns (operands[1], insn) * 4")
597 (eq_attr "move_type" "store,fpstore")
598 (cond [(not (match_test "TARGET_FIX_24K"))
599 (symbol_ref "mips_load_store_insns (operands[0], insn) * 4")]
600 (symbol_ref "mips_load_store_insns (operands[0], insn) * 4 + 4"))
602 ;; In the worst case, a call macro will take 8 instructions:
604 ;; lui $25,%call_hi(FOO)
606 ;; lw $25,%call_lo(FOO)($25)
612 (eq_attr "jal_macro" "yes")
615 ;; Various VR4120 errata require a nop to be inserted after a macc
616 ;; instruction. The assembler does this for us, so account for
617 ;; the worst-case length here.
618 (and (eq_attr "type" "imadd")
619 (match_test "TARGET_FIX_VR4120"))
622 ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
623 ;; the result of the second one is missed. The assembler should work
624 ;; around this by inserting a nop after the first dmult.
625 (and (eq_attr "type" "imul,imul3")
626 (and (eq_attr "mode" "DI")
627 (match_test "TARGET_FIX_VR4120")))
630 (eq_attr "type" "idiv,idiv3")
631 (symbol_ref "mips_idiv_insns () * 4")
633 (not (eq_attr "sync_mem" "none"))
634 (symbol_ref "mips_sync_loop_insns (insn, operands) * 4")
637 ;; Attribute describing the processor.
638 (define_enum_attr "cpu" "processor"
639 (const (symbol_ref "mips_tune")))
641 ;; The type of hardware hazard associated with this instruction.
642 ;; DELAY means that the next instruction cannot read the result
643 ;; of this one. HILO means that the next two instructions cannot
644 ;; write to HI or LO.
645 (define_attr "hazard" "none,delay,hilo"
646 (cond [(and (eq_attr "type" "load,fpload,fpidxload")
647 (match_test "ISA_HAS_LOAD_DELAY"))
648 (const_string "delay")
650 (and (eq_attr "type" "mfc,mtc")
651 (match_test "ISA_HAS_XFER_DELAY"))
652 (const_string "delay")
654 (and (eq_attr "type" "fcmp")
655 (match_test "ISA_HAS_FCMP_DELAY"))
656 (const_string "delay")
658 ;; The r4000 multiplication patterns include an mflo instruction.
659 (and (eq_attr "type" "imul")
660 (match_test "TARGET_FIX_R4000"))
661 (const_string "hilo")
663 (and (eq_attr "type" "mfhi,mflo")
664 (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
665 (const_string "hilo")]
666 (const_string "none")))
668 ;; Is it a single instruction?
669 (define_attr "single_insn" "no,yes"
670 (symbol_ref "(get_attr_length (insn) == (TARGET_MIPS16 ? 2 : 4)
671 ? SINGLE_INSN_YES : SINGLE_INSN_NO)"))
673 ;; Can the instruction be put into a delay slot?
674 (define_attr "can_delay" "no,yes"
675 (if_then_else (and (eq_attr "type" "!branch,call,jump")
676 (and (eq_attr "hazard" "none")
677 (eq_attr "single_insn" "yes")))
679 (const_string "no")))
681 ;; Attribute defining whether or not we can use the branch-likely
683 (define_attr "branch_likely" "no,yes"
684 (if_then_else (match_test "GENERATE_BRANCHLIKELY")
686 (const_string "no")))
688 ;; True if an instruction might assign to hi or lo when reloaded.
689 ;; This is used by the TUNE_MACC_CHAINS code.
690 (define_attr "may_clobber_hilo" "no,yes"
691 (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthi,mtlo")
693 (const_string "no")))
695 ;; Describe a user's asm statement.
696 (define_asm_attributes
697 [(set_attr "type" "multi")
698 (set_attr "can_delay" "no")])
700 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
701 ;; from the same template.
702 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
704 ;; A copy of GPR that can be used when a pattern has two independent
706 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
708 ;; This mode iterator allows :HILO to be used as the mode of the
709 ;; concatenated HI and LO registers.
710 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
712 ;; This mode iterator allows :P to be used for patterns that operate on
713 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
714 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
716 ;; This mode iterator allows :MOVECC to be used anywhere that a
717 ;; conditional-move-type condition is needed.
718 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
719 (CC "TARGET_HARD_FLOAT && !TARGET_LOONGSON_2EF")])
721 ;; 32-bit integer moves for which we provide move patterns.
722 (define_mode_iterator IMOVE32
731 (V4UQQ "TARGET_DSP")])
733 ;; 64-bit modes for which we provide move patterns.
734 (define_mode_iterator MOVE64
736 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
737 (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
738 (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
739 (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")])
741 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
742 (define_mode_iterator MOVE128 [TI TF])
744 ;; This mode iterator allows the QI and HI extension patterns to be
745 ;; defined from the same template.
746 (define_mode_iterator SHORT [QI HI])
748 ;; Likewise the 64-bit truncate-and-shift patterns.
749 (define_mode_iterator SUBDI [QI HI SI])
751 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
752 ;; floating-point mode is allowed.
753 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
754 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
755 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
757 ;; Like ANYF, but only applies to scalar modes.
758 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
759 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
761 ;; A floating-point mode for which moves involving FPRs may need to be split.
762 (define_mode_iterator SPLITF
763 [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
764 (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
765 (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
766 (V2SI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
767 (V4HI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
768 (V8QI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
769 (TF "TARGET_64BIT && TARGET_FLOAT64")])
771 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
772 ;; 32-bit version and "dsubu" in the 64-bit version.
773 (define_mode_attr d [(SI "") (DI "d")
774 (QQ "") (HQ "") (SQ "") (DQ "d")
775 (UQQ "") (UHQ "") (USQ "") (UDQ "d")
776 (HA "") (SA "") (DA "d")
777 (UHA "") (USA "") (UDA "d")])
779 ;; Same as d but upper-case.
780 (define_mode_attr D [(SI "") (DI "D")
781 (QQ "") (HQ "") (SQ "") (DQ "D")
782 (UQQ "") (UHQ "") (USQ "") (UDQ "D")
783 (HA "") (SA "") (DA "D")
784 (UHA "") (USA "") (UDA "D")])
786 ;; This attribute gives the length suffix for a load or store instruction.
787 ;; The same suffixes work for zero and sign extensions.
788 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
789 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
791 ;; This attributes gives the mode mask of a SHORT.
792 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
794 ;; Mode attributes for GPR loads.
795 (define_mode_attr load [(SI "lw") (DI "ld")])
796 ;; Instruction names for stores.
797 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
799 ;; Similarly for MIPS IV indexed FPR loads and stores.
800 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
801 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
803 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
804 ;; are different. Some forms of unextended addiu have an 8-bit immediate
805 ;; field but the equivalent daddiu has only a 5-bit field.
806 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
808 ;; This attribute gives the best constraint to use for registers of
810 (define_mode_attr reg [(SI "d") (DI "d") (CC "z")])
812 ;; This attribute gives the format suffix for floating-point operations.
813 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
815 ;; This attribute gives the upper-case mode name for one unit of a
816 ;; floating-point mode.
817 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
819 ;; This attribute gives the integer mode that has the same size as a
821 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
822 (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
823 (HA "HI") (SA "SI") (DA "DI")
824 (UHA "HI") (USA "SI") (UDA "DI")
825 (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
826 (V2HQ "SI") (V2HA "SI")])
828 ;; This attribute gives the integer mode that has half the size of
829 ;; the controlling mode.
830 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
831 (V2SI "SI") (V4HI "SI") (V8QI "SI")
834 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
836 ;; In certain cases, div.s and div.ps may have a rounding error
837 ;; and/or wrong inexact flag.
839 ;; Therefore, we only allow div.s if not working around SB-1 rev2
840 ;; errata or if a slight loss of precision is OK.
841 (define_mode_attr divide_condition
842 [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
843 (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
845 ;; This attribute gives the conditions under which SQRT.fmt instructions
847 (define_mode_attr sqrt_condition
848 [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
850 ;; This attribute gives the conditions under which RECIP.fmt and RSQRT.fmt
851 ;; instructions can be used. The MIPS32 and MIPS64 ISAs say that RECIP.D
852 ;; and RSQRT.D are unpredictable when doubles are stored in pairs of FPRs,
853 ;; so for safety's sake, we apply this restriction to all targets.
854 (define_mode_attr recip_condition
856 (DF "ISA_HAS_FP4 && TARGET_FLOAT64")
857 (V2SF "TARGET_SB1")])
859 ;; This code iterator allows signed and unsigned widening multiplications
860 ;; to use the same template.
861 (define_code_iterator any_extend [sign_extend zero_extend])
863 ;; This code iterator allows the two right shift instructions to be
864 ;; generated from the same template.
865 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
867 ;; This code iterator allows the three shift instructions to be generated
868 ;; from the same template.
869 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
871 ;; This code iterator allows unsigned and signed division to be generated
872 ;; from the same template.
873 (define_code_iterator any_div [div udiv])
875 ;; This code iterator allows unsigned and signed modulus to be generated
876 ;; from the same template.
877 (define_code_iterator any_mod [mod umod])
879 ;; This code iterator allows all native floating-point comparisons to be
880 ;; generated from the same template.
881 (define_code_iterator fcond [unordered uneq unlt unle eq lt le])
883 ;; This code iterator is used for comparisons that can be implemented
884 ;; by swapping the operands.
885 (define_code_iterator swapped_fcond [ge gt unge ungt])
887 ;; Equality operators.
888 (define_code_iterator equality_op [eq ne])
890 ;; These code iterators allow the signed and unsigned scc operations to use
891 ;; the same template.
892 (define_code_iterator any_gt [gt gtu])
893 (define_code_iterator any_ge [ge geu])
894 (define_code_iterator any_lt [lt ltu])
895 (define_code_iterator any_le [le leu])
897 (define_code_iterator any_return [return simple_return])
899 ;; <u> expands to an empty string when doing a signed operation and
900 ;; "u" when doing an unsigned operation.
901 (define_code_attr u [(sign_extend "") (zero_extend "u")
909 ;; <U> is like <u> except uppercase.
910 (define_code_attr U [(sign_extend "") (zero_extend "U")])
912 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
913 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
915 ;; <optab> expands to the name of the optab for a particular code.
916 (define_code_attr optab [(ashift "ashl")
925 (simple_return "simple_return")])
927 ;; <insn> expands to the name of the insn that implements a particular code.
928 (define_code_attr insn [(ashift "sll")
937 ;; <immediate_insn> expands to the name of the insn that implements
938 ;; a particular code to operate on immediate values.
939 (define_code_attr immediate_insn [(ior "ori")
943 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
944 (define_code_attr fcond [(unordered "un")
952 ;; Similar, but for swapped conditions.
953 (define_code_attr swapped_fcond [(ge "le")
958 ;; The value of the bit when the branch is taken for branch_bit patterns.
959 ;; Comparison is always against zero so this depends on the operator.
960 (define_code_attr bbv [(eq "0") (ne "1")])
962 ;; This is the inverse value of bbv.
963 (define_code_attr bbinv [(eq "1") (ne "0")])
965 ;; .........................
967 ;; Branch, call and jump delay slots
969 ;; .........................
971 (define_delay (and (eq_attr "type" "branch")
972 (not (match_test "TARGET_MIPS16"))
973 (eq_attr "branch_likely" "yes"))
974 [(eq_attr "can_delay" "yes")
976 (eq_attr "can_delay" "yes")])
978 ;; Branches that don't have likely variants do not annul on false.
979 (define_delay (and (eq_attr "type" "branch")
980 (not (match_test "TARGET_MIPS16"))
981 (eq_attr "branch_likely" "no"))
982 [(eq_attr "can_delay" "yes")
986 (define_delay (eq_attr "type" "jump")
987 [(eq_attr "can_delay" "yes")
991 (define_delay (and (eq_attr "type" "call")
992 (eq_attr "jal_macro" "no"))
993 [(eq_attr "can_delay" "yes")
997 ;; Pipeline descriptions.
999 ;; generic.md provides a fallback for processors without a specific
1000 ;; pipeline description. It is derived from the old define_function_unit
1001 ;; version and uses the "alu" and "imuldiv" units declared below.
1003 ;; Some of the processor-specific files are also derived from old
1004 ;; define_function_unit descriptions and simply override the parts of
1005 ;; generic.md that don't apply. The other processor-specific files
1006 ;; are self-contained.
1007 (define_automaton "alu,imuldiv")
1009 (define_cpu_unit "alu" "alu")
1010 (define_cpu_unit "imuldiv" "imuldiv")
1012 ;; Ghost instructions produce no real code and introduce no hazards.
1013 ;; They exist purely to express an effect on dataflow.
1014 (define_insn_reservation "ghost" 0
1015 (eq_attr "type" "ghost")
1035 (include "10000.md")
1036 (include "loongson2ef.md")
1037 (include "loongson3a.md")
1038 (include "octeon.md")
1040 (include "sr71k.md")
1043 (include "generic.md")
1046 ;; ....................
1048 ;; CONDITIONAL TRAPS
1050 ;; ....................
1054 [(trap_if (const_int 1) (const_int 0))]
1057 if (ISA_HAS_COND_TRAP)
1058 return "teq\t$0,$0";
1059 else if (TARGET_MIPS16)
1064 [(set_attr "type" "trap")])
1066 (define_expand "ctrap<mode>4"
1067 [(trap_if (match_operator 0 "comparison_operator"
1068 [(match_operand:GPR 1 "reg_or_0_operand")
1069 (match_operand:GPR 2 "arith_operand")])
1070 (match_operand 3 "const_0_operand"))]
1073 mips_expand_conditional_trap (operands[0]);
1077 (define_insn "*conditional_trap<mode>"
1078 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1079 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1080 (match_operand:GPR 2 "arith_operand" "dI")])
1084 [(set_attr "type" "trap")])
1087 ;; ....................
1091 ;; ....................
1094 (define_insn "add<mode>3"
1095 [(set (match_operand:ANYF 0 "register_operand" "=f")
1096 (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1097 (match_operand:ANYF 2 "register_operand" "f")))]
1099 "add.<fmt>\t%0,%1,%2"
1100 [(set_attr "type" "fadd")
1101 (set_attr "mode" "<UNITMODE>")])
1103 (define_expand "add<mode>3"
1104 [(set (match_operand:GPR 0 "register_operand")
1105 (plus:GPR (match_operand:GPR 1 "register_operand")
1106 (match_operand:GPR 2 "arith_operand")))]
1109 (define_insn "*add<mode>3"
1110 [(set (match_operand:GPR 0 "register_operand" "=d,d")
1111 (plus:GPR (match_operand:GPR 1 "register_operand" "d,d")
1112 (match_operand:GPR 2 "arith_operand" "d,Q")))]
1117 [(set_attr "alu_type" "add")
1118 (set_attr "mode" "<MODE>")])
1120 (define_insn "*add<mode>3_mips16"
1121 [(set (match_operand:GPR 0 "register_operand" "=ks,d,d,d,d")
1122 (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,0,d,d")
1123 (match_operand:GPR 2 "arith_operand" "Q,Q,Q,O,d")))]
1131 [(set_attr "alu_type" "add")
1132 (set_attr "mode" "<MODE>")
1133 (set_attr_alternative "length"
1134 [(if_then_else (match_operand 2 "m16_simm8_8")
1137 (if_then_else (match_operand 2 "m16_uimm<si8_di5>_4")
1140 (if_then_else (match_operand 2 "m16_simm<si8_di5>_1")
1143 (if_then_else (match_operand 2 "m16_simm4_1")
1148 ;; On the mips16, we can sometimes split an add of a constant which is
1149 ;; a 4 byte instruction into two adds which are both 2 byte
1150 ;; instructions. There are two cases: one where we are adding a
1151 ;; constant plus a register to another register, and one where we are
1152 ;; simply adding a constant to a register.
1155 [(set (match_operand:SI 0 "d_operand")
1156 (plus:SI (match_dup 0)
1157 (match_operand:SI 1 "const_int_operand")))]
1158 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1159 && ((INTVAL (operands[1]) > 0x7f
1160 && INTVAL (operands[1]) <= 0x7f + 0x7f)
1161 || (INTVAL (operands[1]) < - 0x80
1162 && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1163 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1164 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1166 HOST_WIDE_INT val = INTVAL (operands[1]);
1170 operands[1] = GEN_INT (0x7f);
1171 operands[2] = GEN_INT (val - 0x7f);
1175 operands[1] = GEN_INT (- 0x80);
1176 operands[2] = GEN_INT (val + 0x80);
1181 [(set (match_operand:SI 0 "d_operand")
1182 (plus:SI (match_operand:SI 1 "d_operand")
1183 (match_operand:SI 2 "const_int_operand")))]
1184 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1185 && REGNO (operands[0]) != REGNO (operands[1])
1186 && ((INTVAL (operands[2]) > 0x7
1187 && INTVAL (operands[2]) <= 0x7 + 0x7f)
1188 || (INTVAL (operands[2]) < - 0x8
1189 && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1190 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1191 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1193 HOST_WIDE_INT val = INTVAL (operands[2]);
1197 operands[2] = GEN_INT (0x7);
1198 operands[3] = GEN_INT (val - 0x7);
1202 operands[2] = GEN_INT (- 0x8);
1203 operands[3] = GEN_INT (val + 0x8);
1208 [(set (match_operand:DI 0 "d_operand")
1209 (plus:DI (match_dup 0)
1210 (match_operand:DI 1 "const_int_operand")))]
1211 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1212 && ((INTVAL (operands[1]) > 0xf
1213 && INTVAL (operands[1]) <= 0xf + 0xf)
1214 || (INTVAL (operands[1]) < - 0x10
1215 && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1216 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1217 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1219 HOST_WIDE_INT val = INTVAL (operands[1]);
1223 operands[1] = GEN_INT (0xf);
1224 operands[2] = GEN_INT (val - 0xf);
1228 operands[1] = GEN_INT (- 0x10);
1229 operands[2] = GEN_INT (val + 0x10);
1234 [(set (match_operand:DI 0 "d_operand")
1235 (plus:DI (match_operand:DI 1 "d_operand")
1236 (match_operand:DI 2 "const_int_operand")))]
1237 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1238 && REGNO (operands[0]) != REGNO (operands[1])
1239 && ((INTVAL (operands[2]) > 0x7
1240 && INTVAL (operands[2]) <= 0x7 + 0xf)
1241 || (INTVAL (operands[2]) < - 0x8
1242 && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1243 [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1244 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1246 HOST_WIDE_INT val = INTVAL (operands[2]);
1250 operands[2] = GEN_INT (0x7);
1251 operands[3] = GEN_INT (val - 0x7);
1255 operands[2] = GEN_INT (- 0x8);
1256 operands[3] = GEN_INT (val + 0x8);
1260 (define_insn "*addsi3_extended"
1261 [(set (match_operand:DI 0 "register_operand" "=d,d")
1263 (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1264 (match_operand:SI 2 "arith_operand" "d,Q"))))]
1265 "TARGET_64BIT && !TARGET_MIPS16"
1269 [(set_attr "alu_type" "add")
1270 (set_attr "mode" "SI")])
1272 ;; Split this insn so that the addiu splitters can have a crack at it.
1273 ;; Use a conservative length estimate until the split.
1274 (define_insn_and_split "*addsi3_extended_mips16"
1275 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1277 (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1278 (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1279 "TARGET_64BIT && TARGET_MIPS16"
1281 "&& reload_completed"
1282 [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1283 { operands[3] = gen_lowpart (SImode, operands[0]); }
1284 [(set_attr "alu_type" "add")
1285 (set_attr "mode" "SI")
1286 (set_attr "extended_mips16" "yes")])
1288 ;; Combiner patterns for unsigned byte-add.
1290 (define_insn "*baddu_si_eb"
1291 [(set (match_operand:SI 0 "register_operand" "=d")
1294 (plus:SI (match_operand:SI 1 "register_operand" "d")
1295 (match_operand:SI 2 "register_operand" "d")) 3)))]
1296 "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1298 [(set_attr "alu_type" "add")])
1300 (define_insn "*baddu_si_el"
1301 [(set (match_operand:SI 0 "register_operand" "=d")
1304 (plus:SI (match_operand:SI 1 "register_operand" "d")
1305 (match_operand:SI 2 "register_operand" "d")) 0)))]
1306 "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1308 [(set_attr "alu_type" "add")])
1310 (define_insn "*baddu_di<mode>"
1311 [(set (match_operand:GPR 0 "register_operand" "=d")
1314 (plus:DI (match_operand:DI 1 "register_operand" "d")
1315 (match_operand:DI 2 "register_operand" "d")))))]
1316 "ISA_HAS_BADDU && TARGET_64BIT"
1318 [(set_attr "alu_type" "add")])
1321 ;; ....................
1325 ;; ....................
1328 (define_insn "sub<mode>3"
1329 [(set (match_operand:ANYF 0 "register_operand" "=f")
1330 (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1331 (match_operand:ANYF 2 "register_operand" "f")))]
1333 "sub.<fmt>\t%0,%1,%2"
1334 [(set_attr "type" "fadd")
1335 (set_attr "mode" "<UNITMODE>")])
1337 (define_insn "sub<mode>3"
1338 [(set (match_operand:GPR 0 "register_operand" "=d")
1339 (minus:GPR (match_operand:GPR 1 "register_operand" "d")
1340 (match_operand:GPR 2 "register_operand" "d")))]
1343 [(set_attr "alu_type" "sub")
1344 (set_attr "mode" "<MODE>")])
1346 (define_insn "*subsi3_extended"
1347 [(set (match_operand:DI 0 "register_operand" "=d")
1349 (minus:SI (match_operand:SI 1 "register_operand" "d")
1350 (match_operand:SI 2 "register_operand" "d"))))]
1353 [(set_attr "alu_type" "sub")
1354 (set_attr "mode" "DI")])
1357 ;; ....................
1361 ;; ....................
1364 (define_expand "mul<mode>3"
1365 [(set (match_operand:SCALARF 0 "register_operand")
1366 (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1367 (match_operand:SCALARF 2 "register_operand")))]
1371 (define_insn "*mul<mode>3"
1372 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1373 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1374 (match_operand:SCALARF 2 "register_operand" "f")))]
1375 "!TARGET_4300_MUL_FIX"
1376 "mul.<fmt>\t%0,%1,%2"
1377 [(set_attr "type" "fmul")
1378 (set_attr "mode" "<MODE>")])
1380 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1381 ;; operands may corrupt immediately following multiplies. This is a
1382 ;; simple fix to insert NOPs.
1384 (define_insn "*mul<mode>3_r4300"
1385 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1386 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1387 (match_operand:SCALARF 2 "register_operand" "f")))]
1388 "TARGET_4300_MUL_FIX"
1389 "mul.<fmt>\t%0,%1,%2\;nop"
1390 [(set_attr "type" "fmul")
1391 (set_attr "mode" "<MODE>")
1392 (set_attr "length" "8")])
1394 (define_insn "mulv2sf3"
1395 [(set (match_operand:V2SF 0 "register_operand" "=f")
1396 (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1397 (match_operand:V2SF 2 "register_operand" "f")))]
1398 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1400 [(set_attr "type" "fmul")
1401 (set_attr "mode" "SF")])
1403 ;; The original R4000 has a cpu bug. If a double-word or a variable
1404 ;; shift executes while an integer multiplication is in progress, the
1405 ;; shift may give an incorrect result. Avoid this by keeping the mflo
1406 ;; with the mult on the R4000.
1408 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1409 ;; (also valid for MIPS R4000MC processors):
1411 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1412 ;; this errata description.
1413 ;; The following code sequence causes the R4000 to incorrectly
1414 ;; execute the Double Shift Right Arithmetic 32 (dsra32)
1415 ;; instruction. If the dsra32 instruction is executed during an
1416 ;; integer multiply, the dsra32 will only shift by the amount in
1417 ;; specified in the instruction rather than the amount plus 32
1419 ;; instruction 1: mult rs,rt integer multiply
1420 ;; instruction 2-12: dsra32 rd,rt,rs doubleword shift
1421 ;; right arithmetic + 32
1422 ;; Workaround: A dsra32 instruction placed after an integer
1423 ;; multiply should not be one of the 11 instructions after the
1424 ;; multiply instruction."
1428 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1429 ;; the following description.
1430 ;; All extended shifts (shift by n+32) and variable shifts (32 and
1431 ;; 64-bit versions) may produce incorrect results under the
1432 ;; following conditions:
1433 ;; 1) An integer multiply is currently executing
1434 ;; 2) These types of shift instructions are executed immediately
1435 ;; following an integer divide instruction.
1437 ;; 1) Make sure no integer multiply is running wihen these
1438 ;; instruction are executed. If this cannot be predicted at
1439 ;; compile time, then insert a "mfhi" to R0 instruction
1440 ;; immediately after the integer multiply instruction. This
1441 ;; will cause the integer multiply to complete before the shift
1443 ;; 2) Separate integer divide and these two classes of shift
1444 ;; instructions by another instruction or a noop."
1446 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1449 (define_expand "mul<mode>3"
1450 [(set (match_operand:GPR 0 "register_operand")
1451 (mult:GPR (match_operand:GPR 1 "register_operand")
1452 (match_operand:GPR 2 "register_operand")))]
1457 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
1458 emit_insn (gen_mul<mode>3_mul3_loongson (operands[0], operands[1],
1460 else if (ISA_HAS_<D>MUL3)
1461 emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1462 else if (TARGET_MIPS16)
1464 lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1465 emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1466 emit_move_insn (operands[0], lo);
1468 else if (TARGET_FIX_R4000)
1469 emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1472 (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1476 (define_insn "mul<mode>3_mul3_loongson"
1477 [(set (match_operand:GPR 0 "register_operand" "=d")
1478 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1479 (match_operand:GPR 2 "register_operand" "d")))]
1480 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A"
1482 if (TARGET_LOONGSON_2EF)
1483 return "<d>multu.g\t%0,%1,%2";
1485 return "gs<d>multu\t%0,%1,%2";
1487 [(set_attr "type" "imul3nc")
1488 (set_attr "mode" "<MODE>")])
1490 (define_insn "mul<mode>3_mul3"
1491 [(set (match_operand:GPR 0 "register_operand" "=d,l")
1492 (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1493 (match_operand:GPR 2 "register_operand" "d,d")))
1494 (clobber (match_scratch:GPR 3 "=l,X"))]
1497 if (which_alternative == 1)
1498 return "<d>mult\t%1,%2";
1499 if (<MODE>mode == SImode && TARGET_MIPS3900)
1500 return "mult\t%0,%1,%2";
1501 return "<d>mul\t%0,%1,%2";
1503 [(set_attr "type" "imul3,imul")
1504 (set_attr "mode" "<MODE>")])
1506 ;; If a register gets allocated to LO, and we spill to memory, the reload
1507 ;; will include a move from LO to a GPR. Merge it into the multiplication
1508 ;; if it can set the GPR directly.
1511 ;; Operand 1: GPR (1st multiplication operand)
1512 ;; Operand 2: GPR (2nd multiplication operand)
1513 ;; Operand 3: GPR (destination)
1516 [(set (match_operand:SI 0 "lo_operand")
1517 (mult:SI (match_operand:SI 1 "d_operand")
1518 (match_operand:SI 2 "d_operand")))
1519 (clobber (scratch:SI))])
1520 (set (match_operand:SI 3 "d_operand")
1522 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1525 (mult:SI (match_dup 1)
1527 (clobber (match_dup 0))])])
1529 (define_insn "mul<mode>3_internal"
1530 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1531 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1532 (match_operand:GPR 2 "register_operand" "d")))]
1535 [(set_attr "type" "imul")
1536 (set_attr "mode" "<MODE>")])
1538 (define_insn "mul<mode>3_r4000"
1539 [(set (match_operand:GPR 0 "register_operand" "=d")
1540 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1541 (match_operand:GPR 2 "register_operand" "d")))
1542 (clobber (match_scratch:GPR 3 "=l"))]
1544 "<d>mult\t%1,%2\;mflo\t%0"
1545 [(set_attr "type" "imul")
1546 (set_attr "mode" "<MODE>")
1547 (set_attr "length" "8")])
1549 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1550 ;; of "mult; mflo". They have the same latency, but the first form gives
1551 ;; us an extra cycle to compute the operands.
1554 ;; Operand 1: GPR (1st multiplication operand)
1555 ;; Operand 2: GPR (2nd multiplication operand)
1556 ;; Operand 3: GPR (destination)
1558 [(set (match_operand:SI 0 "lo_operand")
1559 (mult:SI (match_operand:SI 1 "d_operand")
1560 (match_operand:SI 2 "d_operand")))
1561 (set (match_operand:SI 3 "d_operand")
1563 "ISA_HAS_MACC && !ISA_HAS_MUL3"
1568 (plus:SI (mult:SI (match_dup 1)
1572 (plus:SI (mult:SI (match_dup 1)
1576 ;; Multiply-accumulate patterns
1578 ;; This pattern is first matched by combine, which tries to use the
1579 ;; pattern wherever it can. We don't know until later whether it
1580 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1581 ;; so we need to keep both options open.
1583 ;; The second alternative has a "?" marker because it is generally
1584 ;; one instruction more costly than the first alternative. This "?"
1585 ;; marker is enough to convey the relative costs to the register
1588 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1589 ;; reloads of the other operands, even though operands 4 and 5 need no
1590 ;; copy instructions. Reload therefore thinks that the second alternative
1591 ;; is two reloads more costly than the first. We add "*?*?" to the first
1592 ;; alternative as a counterweight.
1593 (define_insn "*mul_acc_si"
1594 [(set (match_operand:SI 0 "register_operand" "=l*?*?,d?")
1595 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1596 (match_operand:SI 2 "register_operand" "d,d"))
1597 (match_operand:SI 3 "register_operand" "0,d")))
1598 (clobber (match_scratch:SI 4 "=X,l"))
1599 (clobber (match_scratch:SI 5 "=X,&d"))]
1600 "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1604 [(set_attr "type" "imadd")
1605 (set_attr "mode" "SI")
1606 (set_attr "length" "4,8")])
1608 ;; The same idea applies here. The middle alternative needs one less
1609 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1610 (define_insn "*mul_acc_si_r3900"
1611 [(set (match_operand:SI 0 "register_operand" "=l*?*?,d*?,d?")
1612 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1613 (match_operand:SI 2 "register_operand" "d,d,d"))
1614 (match_operand:SI 3 "register_operand" "0,l,d")))
1615 (clobber (match_scratch:SI 4 "=X,3,l"))
1616 (clobber (match_scratch:SI 5 "=X,X,&d"))]
1617 "TARGET_MIPS3900 && !TARGET_MIPS16"
1622 [(set_attr "type" "imadd")
1623 (set_attr "mode" "SI")
1624 (set_attr "length" "4,4,8")])
1626 ;; Split *mul_acc_si if both the source and destination accumulator
1629 [(set (match_operand:SI 0 "d_operand")
1630 (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1631 (match_operand:SI 2 "d_operand"))
1632 (match_operand:SI 3 "d_operand")))
1633 (clobber (match_operand:SI 4 "lo_operand"))
1634 (clobber (match_operand:SI 5 "d_operand"))]
1636 [(parallel [(set (match_dup 5)
1637 (mult:SI (match_dup 1) (match_dup 2)))
1638 (clobber (match_dup 4))])
1639 (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1642 (define_insn "*macc"
1643 [(set (match_operand:SI 0 "register_operand" "=l,d")
1644 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1645 (match_operand:SI 2 "register_operand" "d,d"))
1646 (match_operand:SI 3 "register_operand" "0,l")))
1647 (clobber (match_scratch:SI 4 "=X,3"))]
1650 if (which_alternative == 1)
1651 return "macc\t%0,%1,%2";
1652 else if (TARGET_MIPS5500)
1653 return "madd\t%1,%2";
1655 /* The VR4130 assumes that there is a two-cycle latency between a macc
1656 that "writes" to $0 and an instruction that reads from it. We avoid
1657 this by assigning to $1 instead. */
1658 return "%[macc\t%@,%1,%2%]";
1660 [(set_attr "type" "imadd")
1661 (set_attr "mode" "SI")])
1663 (define_insn "*msac"
1664 [(set (match_operand:SI 0 "register_operand" "=l,d")
1665 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1666 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1667 (match_operand:SI 3 "register_operand" "d,d"))))
1668 (clobber (match_scratch:SI 4 "=X,1"))]
1671 if (which_alternative == 1)
1672 return "msac\t%0,%2,%3";
1673 else if (TARGET_MIPS5500)
1674 return "msub\t%2,%3";
1676 return "msac\t$0,%2,%3";
1678 [(set_attr "type" "imadd")
1679 (set_attr "mode" "SI")])
1681 ;; An msac-like instruction implemented using negation and a macc.
1682 (define_insn_and_split "*msac_using_macc"
1683 [(set (match_operand:SI 0 "register_operand" "=l,d")
1684 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1685 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1686 (match_operand:SI 3 "register_operand" "d,d"))))
1687 (clobber (match_scratch:SI 4 "=X,1"))
1688 (clobber (match_scratch:SI 5 "=d,d"))]
1689 "ISA_HAS_MACC && !ISA_HAS_MSAC"
1691 "&& reload_completed"
1693 (neg:SI (match_dup 3)))
1696 (plus:SI (mult:SI (match_dup 2)
1699 (clobber (match_dup 4))])]
1701 [(set_attr "type" "imadd")
1702 (set_attr "length" "8")])
1704 ;; Patterns generated by the define_peephole2 below.
1706 (define_insn "*macc2"
1707 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1708 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1709 (match_operand:SI 2 "register_operand" "d"))
1711 (set (match_operand:SI 3 "register_operand" "=d")
1712 (plus:SI (mult:SI (match_dup 1)
1715 "ISA_HAS_MACC && reload_completed"
1717 [(set_attr "type" "imadd")
1718 (set_attr "mode" "SI")])
1720 (define_insn "*msac2"
1721 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1722 (minus:SI (match_dup 0)
1723 (mult:SI (match_operand:SI 1 "register_operand" "d")
1724 (match_operand:SI 2 "register_operand" "d"))))
1725 (set (match_operand:SI 3 "register_operand" "=d")
1726 (minus:SI (match_dup 0)
1727 (mult:SI (match_dup 1)
1729 "ISA_HAS_MSAC && reload_completed"
1731 [(set_attr "type" "imadd")
1732 (set_attr "mode" "SI")])
1734 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1738 ;; Operand 1: macc/msac
1739 ;; Operand 2: GPR (destination)
1742 [(set (match_operand:SI 0 "lo_operand")
1743 (match_operand:SI 1 "macc_msac_operand"))
1744 (clobber (scratch:SI))])
1745 (set (match_operand:SI 2 "d_operand")
1748 [(parallel [(set (match_dup 0)
1753 ;; When we have a three-address multiplication instruction, it should
1754 ;; be faster to do a separate multiply and add, rather than moving
1755 ;; something into LO in order to use a macc instruction.
1757 ;; This peephole needs a scratch register to cater for the case when one
1758 ;; of the multiplication operands is the same as the destination.
1760 ;; Operand 0: GPR (scratch)
1762 ;; Operand 2: GPR (addend)
1763 ;; Operand 3: GPR (destination)
1764 ;; Operand 4: macc/msac
1765 ;; Operand 5: new multiplication
1766 ;; Operand 6: new addition/subtraction
1768 [(match_scratch:SI 0 "d")
1769 (set (match_operand:SI 1 "lo_operand")
1770 (match_operand:SI 2 "d_operand"))
1773 [(set (match_operand:SI 3 "d_operand")
1774 (match_operand:SI 4 "macc_msac_operand"))
1775 (clobber (match_dup 1))])]
1776 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1777 [(parallel [(set (match_dup 0)
1779 (clobber (match_dup 1))])
1783 operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1784 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1785 operands[2], operands[0]);
1788 ;; Same as above, except LO is the initial target of the macc.
1790 ;; Operand 0: GPR (scratch)
1792 ;; Operand 2: GPR (addend)
1793 ;; Operand 3: macc/msac
1794 ;; Operand 4: GPR (destination)
1795 ;; Operand 5: new multiplication
1796 ;; Operand 6: new addition/subtraction
1798 [(match_scratch:SI 0 "d")
1799 (set (match_operand:SI 1 "lo_operand")
1800 (match_operand:SI 2 "d_operand"))
1804 (match_operand:SI 3 "macc_msac_operand"))
1805 (clobber (scratch:SI))])
1807 (set (match_operand:SI 4 "d_operand")
1809 "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1810 [(parallel [(set (match_dup 0)
1812 (clobber (match_dup 1))])
1816 operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
1817 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
1818 operands[2], operands[0]);
1821 ;; See the comment above *mul_add_si for details.
1822 (define_insn "*mul_sub_si"
1823 [(set (match_operand:SI 0 "register_operand" "=l*?*?,d?")
1824 (minus:SI (match_operand:SI 1 "register_operand" "0,d")
1825 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1826 (match_operand:SI 3 "register_operand" "d,d"))))
1827 (clobber (match_scratch:SI 4 "=X,l"))
1828 (clobber (match_scratch:SI 5 "=X,&d"))]
1829 "GENERATE_MADD_MSUB"
1833 [(set_attr "type" "imadd")
1834 (set_attr "mode" "SI")
1835 (set_attr "length" "4,8")])
1837 ;; Split *mul_sub_si if both the source and destination accumulator
1840 [(set (match_operand:SI 0 "d_operand")
1841 (minus:SI (match_operand:SI 1 "d_operand")
1842 (mult:SI (match_operand:SI 2 "d_operand")
1843 (match_operand:SI 3 "d_operand"))))
1844 (clobber (match_operand:SI 4 "lo_operand"))
1845 (clobber (match_operand:SI 5 "d_operand"))]
1847 [(parallel [(set (match_dup 5)
1848 (mult:SI (match_dup 2) (match_dup 3)))
1849 (clobber (match_dup 4))])
1850 (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
1853 (define_insn "*muls"
1854 [(set (match_operand:SI 0 "register_operand" "=l,d")
1855 (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1856 (match_operand:SI 2 "register_operand" "d,d"))))
1857 (clobber (match_scratch:SI 3 "=X,l"))]
1862 [(set_attr "type" "imul,imul3")
1863 (set_attr "mode" "SI")])
1865 (define_expand "<u>mulsidi3"
1866 [(set (match_operand:DI 0 "register_operand")
1867 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1868 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1869 "mips_mulsidi3_gen_fn (<CODE>) != NULL"
1871 mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
1872 emit_insn (fn (operands[0], operands[1], operands[2]));
1876 (define_expand "<u>mulsidi3_32bit_mips16"
1877 [(set (match_operand:DI 0 "register_operand")
1878 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1879 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1880 "!TARGET_64BIT && TARGET_MIPS16"
1884 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
1885 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
1886 emit_move_insn (operands[0], hilo);
1890 ;; As well as being named patterns, these instructions are used by the
1891 ;; __builtin_mips_mult<u>() functions. We must always make those functions
1892 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
1893 (define_insn "<u>mulsidi3_32bit"
1894 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
1895 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1896 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
1897 "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP)"
1899 if (ISA_HAS_DSP_MULT)
1900 return "mult<u>\t%q0,%1,%2";
1902 return "mult<u>\t%1,%2";
1904 [(set_attr "type" "imul")
1905 (set_attr "mode" "SI")])
1907 (define_insn "<u>mulsidi3_32bit_r4000"
1908 [(set (match_operand:DI 0 "register_operand" "=d")
1909 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1910 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1911 (clobber (match_scratch:DI 3 "=x"))]
1912 "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP"
1913 "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
1914 [(set_attr "type" "imul")
1915 (set_attr "mode" "SI")
1916 (set_attr "length" "12")])
1918 (define_insn_and_split "<u>mulsidi3_64bit"
1919 [(set (match_operand:DI 0 "register_operand" "=d")
1920 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1921 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1922 (clobber (match_scratch:TI 3 "=x"))
1923 (clobber (match_scratch:DI 4 "=d"))]
1924 "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3 && !TARGET_MIPS16"
1926 "&& reload_completed"
1929 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
1930 operands[2], operands[4]));
1933 [(set_attr "type" "imul")
1934 (set_attr "mode" "SI")
1935 (set (attr "length")
1936 (if_then_else (match_test "ISA_HAS_EXT_INS")
1940 (define_expand "<u>mulsidi3_64bit_mips16"
1941 [(set (match_operand:DI 0 "register_operand")
1942 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1943 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1944 "TARGET_64BIT && TARGET_MIPS16"
1946 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
1947 operands[2], gen_reg_rtx (DImode)));
1951 (define_expand "<u>mulsidi3_64bit_split"
1952 [(set (match_operand:DI 0 "register_operand")
1953 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1954 (any_extend:DI (match_operand:SI 2 "register_operand"))))
1955 (clobber (match_operand:DI 3 "register_operand"))]
1960 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
1961 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
1963 emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
1964 emit_insn (gen_mfhidi_ti (operands[3], hilo));
1966 if (ISA_HAS_EXT_INS)
1967 emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
1971 /* Zero-extend the low part. */
1972 mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
1973 mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
1975 /* Shift the high part into place. */
1976 mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
1978 /* OR the two halves together. */
1979 mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
1984 (define_insn "<u>mulsidi3_64bit_hilo"
1985 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
1988 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1989 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
1991 "TARGET_64BIT && !TARGET_FIX_R4000"
1993 [(set_attr "type" "imul")
1994 (set_attr "mode" "SI")])
1996 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
1997 (define_insn "mulsidi3_64bit_dmul"
1998 [(set (match_operand:DI 0 "register_operand" "=d")
1999 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2000 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2001 (clobber (match_scratch:DI 3 "=l"))]
2002 "TARGET_64BIT && ISA_HAS_DMUL3"
2004 [(set_attr "type" "imul3")
2005 (set_attr "mode" "DI")])
2007 ;; Widening multiply with negation.
2008 (define_insn "*muls<u>_di"
2009 [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2012 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2013 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2014 "!TARGET_64BIT && ISA_HAS_MULS"
2016 [(set_attr "type" "imul")
2017 (set_attr "mode" "SI")])
2019 ;; As well as being named patterns, these instructions are used by the
2020 ;; __builtin_mips_msub<u>() functions. We must always make those functions
2021 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2023 ;; This leads to a slight inconsistency. We honor any tuning overrides
2024 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2025 ;; even if !ISA_HAS_DSP_MULT.
2026 (define_insn "<u>msubsidi4"
2027 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2029 (match_operand:DI 3 "muldiv_target_operand" "0")
2031 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2032 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2033 "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2035 if (ISA_HAS_DSP_MULT)
2036 return "msub<u>\t%q0,%1,%2";
2037 else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2038 return "msub<u>\t%1,%2";
2040 return "msac<u>\t$0,%1,%2";
2042 [(set_attr "type" "imadd")
2043 (set_attr "mode" "SI")])
2045 ;; _highpart patterns
2047 (define_expand "<su>mulsi3_highpart"
2048 [(set (match_operand:SI 0 "register_operand")
2051 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2052 (any_extend:DI (match_operand:SI 2 "register_operand")))
2057 emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2060 else if (TARGET_MIPS16)
2061 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2064 emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2069 (define_insn_and_split "<su>mulsi3_highpart_internal"
2070 [(set (match_operand:SI 0 "register_operand" "=d")
2073 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2074 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2076 (clobber (match_scratch:SI 3 "=l"))]
2077 "!ISA_HAS_MULHI && !TARGET_MIPS16"
2078 { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2079 "&& reload_completed && !TARGET_FIX_R4000"
2082 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2086 [(set_attr "type" "imul")
2087 (set_attr "mode" "SI")
2088 (set_attr "length" "8")])
2090 (define_expand "<su>mulsi3_highpart_split"
2091 [(set (match_operand:SI 0 "register_operand")
2094 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2095 (any_extend:DI (match_operand:SI 2 "register_operand")))
2103 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2104 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2105 emit_insn (gen_mfhisi_ti (operands[0], hilo));
2109 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2110 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2111 emit_insn (gen_mfhisi_di (operands[0], hilo));
2116 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2117 [(set (match_operand:SI 0 "register_operand" "=d")
2121 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2122 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2124 (clobber (match_scratch:SI 3 "=l"))]
2126 "mulhi<u>\t%0,%1,%2"
2127 [(set_attr "type" "imul3")
2128 (set_attr "mode" "SI")])
2130 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2131 [(set (match_operand:SI 0 "register_operand" "=d")
2136 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2137 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2139 (clobber (match_scratch:SI 3 "=l"))]
2141 "mulshi<u>\t%0,%1,%2"
2142 [(set_attr "type" "imul3")
2143 (set_attr "mode" "SI")])
2145 ;; Disable unsigned multiplication for -mfix-vr4120. This is for VR4120
2146 ;; errata MD(0), which says that dmultu does not always produce the
2148 (define_expand "<su>muldi3_highpart"
2149 [(set (match_operand:DI 0 "register_operand")
2152 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2153 (any_extend:TI (match_operand:DI 2 "register_operand")))
2155 "TARGET_64BIT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2158 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2161 emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2166 (define_insn_and_split "<su>muldi3_highpart_internal"
2167 [(set (match_operand:DI 0 "register_operand" "=d")
2170 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2171 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2173 (clobber (match_scratch:DI 3 "=l"))]
2176 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2177 { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2178 "&& reload_completed && !TARGET_FIX_R4000"
2181 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2185 [(set_attr "type" "imul")
2186 (set_attr "mode" "DI")
2187 (set_attr "length" "8")])
2189 (define_expand "<su>muldi3_highpart_split"
2190 [(set (match_operand:DI 0 "register_operand")
2193 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2194 (any_extend:TI (match_operand:DI 2 "register_operand")))
2200 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2201 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2202 emit_insn (gen_mfhidi_ti (operands[0], hilo));
2206 (define_expand "<u>mulditi3"
2207 [(set (match_operand:TI 0 "register_operand")
2208 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2209 (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2210 "TARGET_64BIT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2216 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2217 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2218 emit_move_insn (operands[0], hilo);
2220 else if (TARGET_FIX_R4000)
2221 emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2223 emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2228 (define_insn "<u>mulditi3_internal"
2229 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2230 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2231 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2233 && !TARGET_FIX_R4000
2234 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2236 [(set_attr "type" "imul")
2237 (set_attr "mode" "DI")])
2239 (define_insn "<u>mulditi3_r4000"
2240 [(set (match_operand:TI 0 "register_operand" "=d")
2241 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2242 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2243 (clobber (match_scratch:TI 3 "=x"))]
2246 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2247 "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2248 [(set_attr "type" "imul")
2249 (set_attr "mode" "DI")
2250 (set_attr "length" "12")])
2252 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2253 ;; instruction. The HI/LO registers are used as a 64-bit accumulator.
2255 (define_insn "madsi"
2256 [(set (match_operand:SI 0 "register_operand" "+l")
2257 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2258 (match_operand:SI 2 "register_operand" "d"))
2262 [(set_attr "type" "imadd")
2263 (set_attr "mode" "SI")])
2265 ;; See the comment above <u>msubsidi4 for the relationship between
2266 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2267 (define_insn "<u>maddsidi4"
2268 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2270 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2271 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2272 (match_operand:DI 3 "muldiv_target_operand" "0")))]
2273 "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2277 return "mad<u>\t%1,%2";
2278 else if (ISA_HAS_DSP_MULT)
2279 return "madd<u>\t%q0,%1,%2";
2280 else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2281 return "madd<u>\t%1,%2";
2283 /* See comment in *macc. */
2284 return "%[macc<u>\t%@,%1,%2%]";
2286 [(set_attr "type" "imadd")
2287 (set_attr "mode" "SI")])
2289 ;; Floating point multiply accumulate instructions.
2291 (define_insn "*madd4<mode>"
2292 [(set (match_operand:ANYF 0 "register_operand" "=f")
2293 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2294 (match_operand:ANYF 2 "register_operand" "f"))
2295 (match_operand:ANYF 3 "register_operand" "f")))]
2296 "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2297 "madd.<fmt>\t%0,%3,%1,%2"
2298 [(set_attr "type" "fmadd")
2299 (set_attr "mode" "<UNITMODE>")])
2301 (define_insn "*madd3<mode>"
2302 [(set (match_operand:ANYF 0 "register_operand" "=f")
2303 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2304 (match_operand:ANYF 2 "register_operand" "f"))
2305 (match_operand:ANYF 3 "register_operand" "0")))]
2306 "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2307 "madd.<fmt>\t%0,%1,%2"
2308 [(set_attr "type" "fmadd")
2309 (set_attr "mode" "<UNITMODE>")])
2311 (define_insn "*msub4<mode>"
2312 [(set (match_operand:ANYF 0 "register_operand" "=f")
2313 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2314 (match_operand:ANYF 2 "register_operand" "f"))
2315 (match_operand:ANYF 3 "register_operand" "f")))]
2316 "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2317 "msub.<fmt>\t%0,%3,%1,%2"
2318 [(set_attr "type" "fmadd")
2319 (set_attr "mode" "<UNITMODE>")])
2321 (define_insn "*msub3<mode>"
2322 [(set (match_operand:ANYF 0 "register_operand" "=f")
2323 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2324 (match_operand:ANYF 2 "register_operand" "f"))
2325 (match_operand:ANYF 3 "register_operand" "0")))]
2326 "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2327 "msub.<fmt>\t%0,%1,%2"
2328 [(set_attr "type" "fmadd")
2329 (set_attr "mode" "<UNITMODE>")])
2331 (define_insn "*nmadd4<mode>"
2332 [(set (match_operand:ANYF 0 "register_operand" "=f")
2333 (neg:ANYF (plus:ANYF
2334 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2335 (match_operand:ANYF 2 "register_operand" "f"))
2336 (match_operand:ANYF 3 "register_operand" "f"))))]
2337 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2338 && TARGET_FUSED_MADD
2339 && HONOR_SIGNED_ZEROS (<MODE>mode)
2340 && !HONOR_NANS (<MODE>mode)"
2341 "nmadd.<fmt>\t%0,%3,%1,%2"
2342 [(set_attr "type" "fmadd")
2343 (set_attr "mode" "<UNITMODE>")])
2345 (define_insn "*nmadd3<mode>"
2346 [(set (match_operand:ANYF 0 "register_operand" "=f")
2347 (neg:ANYF (plus:ANYF
2348 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2349 (match_operand:ANYF 2 "register_operand" "f"))
2350 (match_operand:ANYF 3 "register_operand" "0"))))]
2351 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2352 && TARGET_FUSED_MADD
2353 && HONOR_SIGNED_ZEROS (<MODE>mode)
2354 && !HONOR_NANS (<MODE>mode)"
2355 "nmadd.<fmt>\t%0,%1,%2"
2356 [(set_attr "type" "fmadd")
2357 (set_attr "mode" "<UNITMODE>")])
2359 (define_insn "*nmadd4<mode>_fastmath"
2360 [(set (match_operand:ANYF 0 "register_operand" "=f")
2362 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2363 (match_operand:ANYF 2 "register_operand" "f"))
2364 (match_operand:ANYF 3 "register_operand" "f")))]
2365 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2366 && TARGET_FUSED_MADD
2367 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2368 && !HONOR_NANS (<MODE>mode)"
2369 "nmadd.<fmt>\t%0,%3,%1,%2"
2370 [(set_attr "type" "fmadd")
2371 (set_attr "mode" "<UNITMODE>")])
2373 (define_insn "*nmadd3<mode>_fastmath"
2374 [(set (match_operand:ANYF 0 "register_operand" "=f")
2376 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2377 (match_operand:ANYF 2 "register_operand" "f"))
2378 (match_operand:ANYF 3 "register_operand" "0")))]
2379 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2380 && TARGET_FUSED_MADD
2381 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2382 && !HONOR_NANS (<MODE>mode)"
2383 "nmadd.<fmt>\t%0,%1,%2"
2384 [(set_attr "type" "fmadd")
2385 (set_attr "mode" "<UNITMODE>")])
2387 (define_insn "*nmsub4<mode>"
2388 [(set (match_operand:ANYF 0 "register_operand" "=f")
2389 (neg:ANYF (minus:ANYF
2390 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2391 (match_operand:ANYF 3 "register_operand" "f"))
2392 (match_operand:ANYF 1 "register_operand" "f"))))]
2393 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2394 && TARGET_FUSED_MADD
2395 && HONOR_SIGNED_ZEROS (<MODE>mode)
2396 && !HONOR_NANS (<MODE>mode)"
2397 "nmsub.<fmt>\t%0,%1,%2,%3"
2398 [(set_attr "type" "fmadd")
2399 (set_attr "mode" "<UNITMODE>")])
2401 (define_insn "*nmsub3<mode>"
2402 [(set (match_operand:ANYF 0 "register_operand" "=f")
2403 (neg:ANYF (minus:ANYF
2404 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2405 (match_operand:ANYF 3 "register_operand" "f"))
2406 (match_operand:ANYF 1 "register_operand" "0"))))]
2407 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2408 && TARGET_FUSED_MADD
2409 && HONOR_SIGNED_ZEROS (<MODE>mode)
2410 && !HONOR_NANS (<MODE>mode)"
2411 "nmsub.<fmt>\t%0,%1,%2"
2412 [(set_attr "type" "fmadd")
2413 (set_attr "mode" "<UNITMODE>")])
2415 (define_insn "*nmsub4<mode>_fastmath"
2416 [(set (match_operand:ANYF 0 "register_operand" "=f")
2418 (match_operand:ANYF 1 "register_operand" "f")
2419 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2420 (match_operand:ANYF 3 "register_operand" "f"))))]
2421 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2422 && TARGET_FUSED_MADD
2423 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2424 && !HONOR_NANS (<MODE>mode)"
2425 "nmsub.<fmt>\t%0,%1,%2,%3"
2426 [(set_attr "type" "fmadd")
2427 (set_attr "mode" "<UNITMODE>")])
2429 (define_insn "*nmsub3<mode>_fastmath"
2430 [(set (match_operand:ANYF 0 "register_operand" "=f")
2432 (match_operand:ANYF 1 "register_operand" "f")
2433 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2434 (match_operand:ANYF 3 "register_operand" "0"))))]
2435 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2436 && TARGET_FUSED_MADD
2437 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2438 && !HONOR_NANS (<MODE>mode)"
2439 "nmsub.<fmt>\t%0,%1,%2"
2440 [(set_attr "type" "fmadd")
2441 (set_attr "mode" "<UNITMODE>")])
2444 ;; ....................
2446 ;; DIVISION and REMAINDER
2448 ;; ....................
2451 (define_expand "div<mode>3"
2452 [(set (match_operand:ANYF 0 "register_operand")
2453 (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2454 (match_operand:ANYF 2 "register_operand")))]
2455 "<divide_condition>"
2457 if (const_1_operand (operands[1], <MODE>mode))
2458 if (!(<recip_condition> && flag_unsafe_math_optimizations))
2459 operands[1] = force_reg (<MODE>mode, operands[1]);
2462 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2464 ;; If an mfc1 or dmfc1 happens to access the floating point register
2465 ;; file at the same time a long latency operation (div, sqrt, recip,
2466 ;; sqrt) iterates an intermediate result back through the floating
2467 ;; point register file bypass, then instead returning the correct
2468 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2469 ;; result of the long latency operation.
2471 ;; The workaround is to insert an unconditional 'mov' from/to the
2472 ;; long latency op destination register.
2474 (define_insn "*div<mode>3"
2475 [(set (match_operand:ANYF 0 "register_operand" "=f")
2476 (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2477 (match_operand:ANYF 2 "register_operand" "f")))]
2478 "<divide_condition>"
2481 return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2483 return "div.<fmt>\t%0,%1,%2";
2485 [(set_attr "type" "fdiv")
2486 (set_attr "mode" "<UNITMODE>")
2487 (set (attr "length")
2488 (if_then_else (match_test "TARGET_FIX_SB1")
2492 (define_insn "*recip<mode>3"
2493 [(set (match_operand:ANYF 0 "register_operand" "=f")
2494 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2495 (match_operand:ANYF 2 "register_operand" "f")))]
2496 "<recip_condition> && flag_unsafe_math_optimizations"
2499 return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2501 return "recip.<fmt>\t%0,%2";
2503 [(set_attr "type" "frdiv")
2504 (set_attr "mode" "<UNITMODE>")
2505 (set (attr "length")
2506 (if_then_else (match_test "TARGET_FIX_SB1")
2510 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2511 ;; with negative operands. We use special libgcc functions instead.
2512 (define_expand "divmod<mode>4"
2513 [(set (match_operand:GPR 0 "register_operand")
2514 (div:GPR (match_operand:GPR 1 "register_operand")
2515 (match_operand:GPR 2 "register_operand")))
2516 (set (match_operand:GPR 3 "register_operand")
2517 (mod:GPR (match_dup 1)
2519 "!TARGET_FIX_VR4120"
2523 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1],
2525 emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, LO_REGNUM));
2528 emit_insn (gen_divmod<mode>4_internal (operands[0], operands[1],
2529 operands[2], operands[3]));
2533 (define_insn_and_split "divmod<mode>4_internal"
2534 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
2535 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2536 (match_operand:GPR 2 "register_operand" "d")))
2537 (set (match_operand:GPR 3 "register_operand" "=d")
2538 (mod:GPR (match_dup 1)
2540 "!TARGET_FIX_VR4120 && !TARGET_MIPS16"
2542 "&& reload_completed"
2545 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2548 [(set_attr "type" "idiv")
2549 (set_attr "mode" "<MODE>")
2550 (set_attr "length" "8")])
2552 (define_expand "udivmod<mode>4"
2553 [(set (match_operand:GPR 0 "register_operand")
2554 (udiv:GPR (match_operand:GPR 1 "register_operand")
2555 (match_operand:GPR 2 "register_operand")))
2556 (set (match_operand:GPR 3 "register_operand")
2557 (umod:GPR (match_dup 1)
2563 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1],
2565 emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, LO_REGNUM));
2568 emit_insn (gen_udivmod<mode>4_internal (operands[0], operands[1],
2569 operands[2], operands[3]));
2573 (define_insn_and_split "udivmod<mode>4_internal"
2574 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
2575 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2576 (match_operand:GPR 2 "register_operand" "d")))
2577 (set (match_operand:GPR 3 "register_operand" "=d")
2578 (umod:GPR (match_dup 1)
2585 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2588 [(set_attr "type" "idiv")
2589 (set_attr "mode" "<MODE>")
2590 (set_attr "length" "8")])
2592 (define_expand "<u>divmod<mode>4_split"
2593 [(set (match_operand:GPR 0 "register_operand")
2594 (any_mod:GPR (match_operand:GPR 1 "register_operand")
2595 (match_operand:GPR 2 "register_operand")))]
2602 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2603 emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
2605 emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
2609 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2610 emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
2612 emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
2617 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
2618 [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
2620 [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2621 (match_operand:GPR 2 "register_operand" "d"))]
2624 { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
2625 [(set_attr "type" "idiv")
2626 (set_attr "mode" "<GPR:MODE>")])
2629 ;; ....................
2633 ;; ....................
2635 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
2636 ;; "*div[sd]f3" comment for details).
2638 (define_insn "sqrt<mode>2"
2639 [(set (match_operand:ANYF 0 "register_operand" "=f")
2640 (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2644 return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
2646 return "sqrt.<fmt>\t%0,%1";
2648 [(set_attr "type" "fsqrt")
2649 (set_attr "mode" "<UNITMODE>")
2650 (set (attr "length")
2651 (if_then_else (match_test "TARGET_FIX_SB1")
2655 (define_insn "*rsqrt<mode>a"
2656 [(set (match_operand:ANYF 0 "register_operand" "=f")
2657 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2658 (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
2659 "<recip_condition> && flag_unsafe_math_optimizations"
2662 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2664 return "rsqrt.<fmt>\t%0,%2";
2666 [(set_attr "type" "frsqrt")
2667 (set_attr "mode" "<UNITMODE>")
2668 (set (attr "length")
2669 (if_then_else (match_test "TARGET_FIX_SB1")
2673 (define_insn "*rsqrt<mode>b"
2674 [(set (match_operand:ANYF 0 "register_operand" "=f")
2675 (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2676 (match_operand:ANYF 2 "register_operand" "f"))))]
2677 "<recip_condition> && flag_unsafe_math_optimizations"
2680 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2682 return "rsqrt.<fmt>\t%0,%2";
2684 [(set_attr "type" "frsqrt")
2685 (set_attr "mode" "<UNITMODE>")
2686 (set (attr "length")
2687 (if_then_else (match_test "TARGET_FIX_SB1")
2692 ;; ....................
2696 ;; ....................
2698 ;; Do not use the integer abs macro instruction, since that signals an
2699 ;; exception on -2147483648 (sigh).
2701 ;; abs.fmt is an arithmetic instruction and treats all NaN inputs as
2702 ;; invalid; it does not clear their sign bits. We therefore can't use
2703 ;; abs.fmt if the signs of NaNs matter.
2705 (define_insn "abs<mode>2"
2706 [(set (match_operand:ANYF 0 "register_operand" "=f")
2707 (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2708 "!HONOR_NANS (<MODE>mode)"
2710 [(set_attr "type" "fabs")
2711 (set_attr "mode" "<UNITMODE>")])
2714 ;; ...................
2716 ;; Count leading zeroes.
2718 ;; ...................
2721 (define_insn "clz<mode>2"
2722 [(set (match_operand:GPR 0 "register_operand" "=d")
2723 (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
2726 [(set_attr "type" "clz")
2727 (set_attr "mode" "<MODE>")])
2730 ;; ...................
2732 ;; Count number of set bits.
2734 ;; ...................
2737 (define_insn "popcount<mode>2"
2738 [(set (match_operand:GPR 0 "register_operand" "=d")
2739 (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
2742 [(set_attr "type" "pop")
2743 (set_attr "mode" "<MODE>")])
2745 ;; The POP instruction is special as it does not take into account the upper
2746 ;; 32bits and is documented that way.
2747 (define_insn "*popcountdi2_trunc"
2748 [(set (match_operand:SI 0 "register_operand" "=d")
2749 (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
2750 "ISA_HAS_POP && TARGET_64BIT"
2752 [(set_attr "type" "pop")
2753 (set_attr "mode" "SI")])
2756 ;; ....................
2758 ;; NEGATION and ONE'S COMPLEMENT
2760 ;; ....................
2762 (define_insn "negsi2"
2763 [(set (match_operand:SI 0 "register_operand" "=d")
2764 (neg:SI (match_operand:SI 1 "register_operand" "d")))]
2768 return "neg\t%0,%1";
2770 return "subu\t%0,%.,%1";
2772 [(set_attr "alu_type" "sub")
2773 (set_attr "mode" "SI")])
2775 (define_insn "negdi2"
2776 [(set (match_operand:DI 0 "register_operand" "=d")
2777 (neg:DI (match_operand:DI 1 "register_operand" "d")))]
2778 "TARGET_64BIT && !TARGET_MIPS16"
2780 [(set_attr "alu_type" "sub")
2781 (set_attr "mode" "DI")])
2783 ;; neg.fmt is an arithmetic instruction and treats all NaN inputs as
2784 ;; invalid; it does not flip their sign bit. We therefore can't use
2785 ;; neg.fmt if the signs of NaNs matter.
2787 (define_insn "neg<mode>2"
2788 [(set (match_operand:ANYF 0 "register_operand" "=f")
2789 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2790 "!HONOR_NANS (<MODE>mode)"
2792 [(set_attr "type" "fneg")
2793 (set_attr "mode" "<UNITMODE>")])
2795 (define_insn "one_cmpl<mode>2"
2796 [(set (match_operand:GPR 0 "register_operand" "=d")
2797 (not:GPR (match_operand:GPR 1 "register_operand" "d")))]
2801 return "not\t%0,%1";
2803 return "nor\t%0,%.,%1";
2805 [(set_attr "alu_type" "not")
2806 (set_attr "mode" "<MODE>")])
2809 ;; ....................
2813 ;; ....................
2816 ;; Many of these instructions use trivial define_expands, because we
2817 ;; want to use a different set of constraints when TARGET_MIPS16.
2819 (define_expand "and<mode>3"
2820 [(set (match_operand:GPR 0 "register_operand")
2821 (and:GPR (match_operand:GPR 1 "register_operand")
2822 (match_operand:GPR 2 "and_reg_operand")))])
2824 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
2825 ;; zero_extendsidi2 because of TRULY_NOOP_TRUNCATION, so handle these here.
2826 ;; Note that this variant does not trigger for SI mode because we require
2827 ;; a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
2828 ;; sign-extended SImode value.
2830 ;; These are possible combinations for operand 1 and 2. The table
2831 ;; includes both MIPS and MIPS16 cases. (r=register, mem=memory,
2832 ;; 16=MIPS16, x=match, S=split):
2834 ;; \ op1 r/EXT r/!EXT mem r/16 mem/16
2840 ;; 0xffff_ffff x S x S x
2845 (define_insn "*and<mode>3"
2846 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d,d,d")
2847 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,d,d,d,d")
2848 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,K,Yx,Yw,d")))]
2849 "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
2853 switch (which_alternative)
2856 operands[1] = gen_lowpart (QImode, operands[1]);
2857 return "lbu\t%0,%1";
2859 operands[1] = gen_lowpart (HImode, operands[1]);
2860 return "lhu\t%0,%1";
2862 operands[1] = gen_lowpart (SImode, operands[1]);
2863 return "lwu\t%0,%1";
2865 return "andi\t%0,%1,%x2";
2867 len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
2868 operands[2] = GEN_INT (len);
2869 return "<d>ext\t%0,%1,0,%2";
2873 return "and\t%0,%1,%2";
2878 [(set_attr "move_type" "load,load,load,andi,ext_ins,shift_shift,logical")
2879 (set_attr "mode" "<MODE>")])
2881 (define_insn "*and<mode>3_mips16"
2882 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
2883 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%o,o,W,d,0")
2884 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
2885 "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
2887 switch (which_alternative)
2890 operands[1] = gen_lowpart (QImode, operands[1]);
2891 return "lbu\t%0,%1";
2893 operands[1] = gen_lowpart (HImode, operands[1]);
2894 return "lhu\t%0,%1";
2896 operands[1] = gen_lowpart (SImode, operands[1]);
2897 return "lwu\t%0,%1";
2901 return "and\t%0,%2";
2906 [(set_attr "move_type" "load,load,load,shift_shift,logical")
2907 (set_attr "mode" "<MODE>")])
2909 (define_expand "ior<mode>3"
2910 [(set (match_operand:GPR 0 "register_operand")
2911 (ior:GPR (match_operand:GPR 1 "register_operand")
2912 (match_operand:GPR 2 "uns_arith_operand")))]
2916 operands[2] = force_reg (<MODE>mode, operands[2]);
2919 (define_insn "*ior<mode>3"
2920 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2921 (ior:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2922 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2927 [(set_attr "alu_type" "or")
2928 (set_attr "mode" "<MODE>")])
2930 (define_insn "*ior<mode>3_mips16"
2931 [(set (match_operand:GPR 0 "register_operand" "=d")
2932 (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
2933 (match_operand:GPR 2 "register_operand" "d")))]
2936 [(set_attr "alu_type" "or")
2937 (set_attr "mode" "<MODE>")])
2939 (define_expand "xor<mode>3"
2940 [(set (match_operand:GPR 0 "register_operand")
2941 (xor:GPR (match_operand:GPR 1 "register_operand")
2942 (match_operand:GPR 2 "uns_arith_operand")))]
2947 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2948 (xor:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2949 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2954 [(set_attr "alu_type" "xor")
2955 (set_attr "mode" "<MODE>")])
2958 [(set (match_operand:GPR 0 "register_operand" "=d,t,t")
2959 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
2960 (match_operand:GPR 2 "uns_arith_operand" "d,K,d")))]
2966 [(set_attr "alu_type" "xor")
2967 (set_attr "mode" "<MODE>")
2968 (set_attr_alternative "length"
2970 (if_then_else (match_operand:VOID 2 "m16_uimm8_1")
2975 (define_insn "*nor<mode>3"
2976 [(set (match_operand:GPR 0 "register_operand" "=d")
2977 (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
2978 (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
2981 [(set_attr "alu_type" "nor")
2982 (set_attr "mode" "<MODE>")])
2985 ;; ....................
2989 ;; ....................
2993 (define_insn "truncdfsf2"
2994 [(set (match_operand:SF 0 "register_operand" "=f")
2995 (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
2996 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2998 [(set_attr "type" "fcvt")
2999 (set_attr "cnv_mode" "D2S")
3000 (set_attr "mode" "SF")])
3002 ;; Integer truncation patterns. Truncating SImode values to smaller
3003 ;; modes is a no-op, as it is for most other GCC ports. Truncating
3004 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3005 ;; need to make sure that the lower 32 bits are properly sign-extended
3006 ;; (see TRULY_NOOP_TRUNCATION). Truncating DImode values into modes
3007 ;; smaller than SImode is equivalent to two separate truncations:
3010 ;; DI ---> HI == DI ---> SI ---> HI
3011 ;; DI ---> QI == DI ---> SI ---> QI
3013 ;; Step A needs a real instruction but step B does not.
3015 (define_insn "truncdi<mode>2"
3016 [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3017 (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3022 [(set_attr "move_type" "sll0,store")
3023 (set_attr "mode" "SI")])
3025 ;; Combiner patterns to optimize shift/truncate combinations.
3027 (define_insn "*ashr_trunc<mode>"
3028 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3030 (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3031 (match_operand:DI 2 "const_arith_operand" ""))))]
3032 "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3034 [(set_attr "type" "shift")
3035 (set_attr "mode" "<MODE>")])
3037 (define_insn "*lshr32_trunc<mode>"
3038 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3040 (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3042 "TARGET_64BIT && !TARGET_MIPS16"
3044 [(set_attr "type" "shift")
3045 (set_attr "mode" "<MODE>")])
3047 ;; Logical shift by more than 32 results in proper SI values so truncation is
3048 ;; removed by the middle end. Note that a logical shift by 32 is handled by
3049 ;; the previous pattern.
3050 (define_insn "*<optab>_trunc<mode>_exts"
3051 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3053 (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3054 (match_operand:DI 2 "const_arith_operand" ""))))]
3055 "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3057 [(set_attr "type" "arith")
3058 (set_attr "mode" "<MODE>")])
3061 ;; ....................
3065 ;; ....................
3069 (define_expand "zero_extendsidi2"
3070 [(set (match_operand:DI 0 "register_operand")
3071 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3074 (define_insn_and_split "*zero_extendsidi2"
3075 [(set (match_operand:DI 0 "register_operand" "=d,d")
3076 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3077 "TARGET_64BIT && !ISA_HAS_EXT_INS"
3081 "&& reload_completed && REG_P (operands[1])"
3083 (ashift:DI (match_dup 1) (const_int 32)))
3085 (lshiftrt:DI (match_dup 0) (const_int 32)))]
3086 { operands[1] = gen_lowpart (DImode, operands[1]); }
3087 [(set_attr "move_type" "shift_shift,load")
3088 (set_attr "mode" "DI")])
3090 (define_insn "*zero_extendsidi2_dext"
3091 [(set (match_operand:DI 0 "register_operand" "=d,d")
3092 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3093 "TARGET_64BIT && ISA_HAS_EXT_INS"
3097 [(set_attr "move_type" "arith,load")
3098 (set_attr "mode" "DI")])
3100 ;; See the comment before the *and<mode>3 pattern why this is generated by
3104 [(set (match_operand:DI 0 "register_operand")
3105 (and:DI (match_operand:DI 1 "register_operand")
3106 (const_int 4294967295)))]
3107 "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3109 (ashift:DI (match_dup 1) (const_int 32)))
3111 (lshiftrt:DI (match_dup 0) (const_int 32)))])
3113 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3114 [(set (match_operand:GPR 0 "register_operand")
3115 (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3118 if (TARGET_MIPS16 && !GENERATE_MIPS16E
3119 && !memory_operand (operands[1], <SHORT:MODE>mode))
3121 emit_insn (gen_and<GPR:mode>3 (operands[0],
3122 gen_lowpart (<GPR:MODE>mode, operands[1]),
3123 force_reg (<GPR:MODE>mode,
3124 GEN_INT (<SHORT:mask>))));
3129 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3130 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3132 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3135 andi\t%0,%1,<SHORT:mask>
3136 l<SHORT:size>u\t%0,%1"
3137 [(set_attr "move_type" "andi,load")
3138 (set_attr "mode" "<GPR:MODE>")])
3140 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3141 [(set (match_operand:GPR 0 "register_operand" "=d")
3142 (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3144 "ze<SHORT:size>\t%0"
3145 ;; This instruction is effectively a special encoding of ANDI.
3146 [(set_attr "move_type" "andi")
3147 (set_attr "mode" "<GPR:MODE>")])
3149 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3150 [(set (match_operand:GPR 0 "register_operand" "=d")
3151 (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3153 "l<SHORT:size>u\t%0,%1"
3154 [(set_attr "move_type" "load")
3155 (set_attr "mode" "<GPR:MODE>")])
3157 (define_expand "zero_extendqihi2"
3158 [(set (match_operand:HI 0 "register_operand")
3159 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3162 if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3164 emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3170 (define_insn "*zero_extendqihi2"
3171 [(set (match_operand:HI 0 "register_operand" "=d,d")
3172 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3177 [(set_attr "move_type" "andi,load")
3178 (set_attr "mode" "HI")])
3180 (define_insn "*zero_extendqihi2_mips16"
3181 [(set (match_operand:HI 0 "register_operand" "=d")
3182 (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3185 [(set_attr "move_type" "load")
3186 (set_attr "mode" "HI")])
3188 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3190 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3191 [(set (match_operand:GPR 0 "register_operand" "=d")
3193 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3194 "TARGET_64BIT && !TARGET_MIPS16"
3196 operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3197 return "andi\t%0,%1,%x2";
3199 [(set_attr "alu_type" "and")
3200 (set_attr "mode" "<GPR:MODE>")])
3202 (define_insn "*zero_extendhi_truncqi"
3203 [(set (match_operand:HI 0 "register_operand" "=d")
3205 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3206 "TARGET_64BIT && !TARGET_MIPS16"
3208 [(set_attr "alu_type" "and")
3209 (set_attr "mode" "HI")])
3212 ;; ....................
3216 ;; ....................
3219 ;; Those for integer source operand are ordered widest source type first.
3221 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3222 ;; should already be in sign-extended form (see TRULY_NOOP_TRUNCATION
3223 ;; and truncdisi2). We can therefore get rid of register->register
3224 ;; instructions if we constrain the source to be in the same register as
3227 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3228 ;; we split them into nothing before the post-reload scheduler runs.
3229 ;; These alternatives therefore have type "move" in order to reflect
3230 ;; what happens if the two pre-reload operands cannot be tied, and are
3231 ;; instead allocated two separate GPRs. We don't distinguish between
3232 ;; the GPR and LO cases because we don't usually know during pre-reload
3233 ;; scheduling whether an operand will be LO or not.
3234 (define_insn_and_split "extendsidi2"
3235 [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3236 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3242 "&& reload_completed && register_operand (operands[1], VOIDmode)"
3245 emit_note (NOTE_INSN_DELETED);
3248 [(set_attr "move_type" "move,move,load")
3249 (set_attr "mode" "DI")])
3251 (define_expand "extend<SHORT:mode><GPR:mode>2"
3252 [(set (match_operand:GPR 0 "register_operand")
3253 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3256 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3257 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3258 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3262 l<SHORT:size>\t%0,%1"
3263 [(set_attr "move_type" "signext,load")
3264 (set_attr "mode" "<GPR:MODE>")])
3266 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3267 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3269 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3270 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3273 l<SHORT:size>\t%0,%1"
3274 "&& reload_completed && REG_P (operands[1])"
3275 [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3276 (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3278 operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3279 operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3280 - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3282 [(set_attr "move_type" "shift_shift,load")
3283 (set_attr "mode" "<GPR:MODE>")])
3285 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3286 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3288 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3291 se<SHORT:size>\t%0,%1
3292 l<SHORT:size>\t%0,%1"
3293 [(set_attr "move_type" "signext,load")
3294 (set_attr "mode" "<GPR:MODE>")])
3296 (define_expand "extendqihi2"
3297 [(set (match_operand:HI 0 "register_operand")
3298 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3301 (define_insn "*extendqihi2_mips16e"
3302 [(set (match_operand:HI 0 "register_operand" "=d,d")
3303 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3308 [(set_attr "move_type" "signext,load")
3309 (set_attr "mode" "SI")])
3311 (define_insn_and_split "*extendqihi2"
3312 [(set (match_operand:HI 0 "register_operand" "=d,d")
3314 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3315 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3319 "&& reload_completed && REG_P (operands[1])"
3320 [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3321 (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3323 operands[0] = gen_lowpart (SImode, operands[0]);
3324 operands[1] = gen_lowpart (SImode, operands[1]);
3325 operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3326 - GET_MODE_BITSIZE (QImode));
3328 [(set_attr "move_type" "shift_shift,load")
3329 (set_attr "mode" "SI")])
3331 (define_insn "*extendqihi2_seb"
3332 [(set (match_operand:HI 0 "register_operand" "=d,d")
3334 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3339 [(set_attr "move_type" "signext,load")
3340 (set_attr "mode" "SI")])
3342 ;; Combiner patterns for truncate/sign_extend combinations. The SI versions
3343 ;; use the shift/truncate patterns.
3345 (define_insn_and_split "*extenddi_truncate<mode>"
3346 [(set (match_operand:DI 0 "register_operand" "=d")
3348 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3349 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3351 "&& reload_completed"
3353 (ashift:DI (match_dup 1)
3356 (ashiftrt:DI (match_dup 2)
3359 operands[2] = gen_lowpart (DImode, operands[0]);
3360 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3362 [(set_attr "move_type" "shift_shift")
3363 (set_attr "mode" "DI")])
3365 (define_insn_and_split "*extendsi_truncate<mode>"
3366 [(set (match_operand:SI 0 "register_operand" "=d")
3368 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3369 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3371 "&& reload_completed"
3373 (ashift:DI (match_dup 1)
3376 (truncate:SI (ashiftrt:DI (match_dup 2)
3379 operands[2] = gen_lowpart (DImode, operands[0]);
3380 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3382 [(set_attr "move_type" "shift_shift")
3383 (set_attr "mode" "SI")])
3385 (define_insn_and_split "*extendhi_truncateqi"
3386 [(set (match_operand:HI 0 "register_operand" "=d")
3388 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3389 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3391 "&& reload_completed"
3393 (ashift:DI (match_dup 1)
3396 (truncate:HI (ashiftrt:DI (match_dup 2)
3399 operands[2] = gen_lowpart (DImode, operands[0]);
3401 [(set_attr "move_type" "shift_shift")
3402 (set_attr "mode" "SI")])
3404 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3405 [(set (match_operand:GPR 0 "register_operand" "=d")
3407 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3408 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3410 operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3411 return "exts\t%0,%1,0,%m2";
3413 [(set_attr "type" "arith")
3414 (set_attr "mode" "<GPR:MODE>")])
3416 (define_insn "*extendhi_truncateqi_exts"
3417 [(set (match_operand:HI 0 "register_operand" "=d")
3419 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3420 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3422 [(set_attr "type" "arith")
3423 (set_attr "mode" "SI")])
3425 (define_insn "extendsfdf2"
3426 [(set (match_operand:DF 0 "register_operand" "=f")
3427 (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3428 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3430 [(set_attr "type" "fcvt")
3431 (set_attr "cnv_mode" "S2D")
3432 (set_attr "mode" "DF")])
3435 ;; ....................
3439 ;; ....................
3441 (define_expand "fix_truncdfsi2"
3442 [(set (match_operand:SI 0 "register_operand")
3443 (fix:SI (match_operand:DF 1 "register_operand")))]
3444 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3446 if (!ISA_HAS_TRUNC_W)
3448 emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3453 (define_insn "fix_truncdfsi2_insn"
3454 [(set (match_operand:SI 0 "register_operand" "=f")
3455 (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3456 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3458 [(set_attr "type" "fcvt")
3459 (set_attr "mode" "DF")
3460 (set_attr "cnv_mode" "D2I")])
3462 (define_insn "fix_truncdfsi2_macro"
3463 [(set (match_operand:SI 0 "register_operand" "=f")
3464 (fix:SI (match_operand:DF 1 "register_operand" "f")))
3465 (clobber (match_scratch:DF 2 "=d"))]
3466 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3468 if (mips_nomacro.nesting_level > 0)
3469 return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3471 return "trunc.w.d %0,%1,%2";
3473 [(set_attr "type" "fcvt")
3474 (set_attr "mode" "DF")
3475 (set_attr "cnv_mode" "D2I")
3476 (set_attr "length" "36")])
3478 (define_expand "fix_truncsfsi2"
3479 [(set (match_operand:SI 0 "register_operand")
3480 (fix:SI (match_operand:SF 1 "register_operand")))]
3483 if (!ISA_HAS_TRUNC_W)
3485 emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3490 (define_insn "fix_truncsfsi2_insn"
3491 [(set (match_operand:SI 0 "register_operand" "=f")
3492 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3493 "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3495 [(set_attr "type" "fcvt")
3496 (set_attr "mode" "SF")
3497 (set_attr "cnv_mode" "S2I")])
3499 (define_insn "fix_truncsfsi2_macro"
3500 [(set (match_operand:SI 0 "register_operand" "=f")
3501 (fix:SI (match_operand:SF 1 "register_operand" "f")))
3502 (clobber (match_scratch:SF 2 "=d"))]
3503 "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
3505 if (mips_nomacro.nesting_level > 0)
3506 return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
3508 return "trunc.w.s %0,%1,%2";
3510 [(set_attr "type" "fcvt")
3511 (set_attr "mode" "SF")
3512 (set_attr "cnv_mode" "S2I")
3513 (set_attr "length" "36")])
3516 (define_insn "fix_truncdfdi2"
3517 [(set (match_operand:DI 0 "register_operand" "=f")
3518 (fix:DI (match_operand:DF 1 "register_operand" "f")))]
3519 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3521 [(set_attr "type" "fcvt")
3522 (set_attr "mode" "DF")
3523 (set_attr "cnv_mode" "D2I")])
3526 (define_insn "fix_truncsfdi2"
3527 [(set (match_operand:DI 0 "register_operand" "=f")
3528 (fix:DI (match_operand:SF 1 "register_operand" "f")))]
3529 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3531 [(set_attr "type" "fcvt")
3532 (set_attr "mode" "SF")
3533 (set_attr "cnv_mode" "S2I")])
3536 (define_insn "floatsidf2"
3537 [(set (match_operand:DF 0 "register_operand" "=f")
3538 (float:DF (match_operand:SI 1 "register_operand" "f")))]
3539 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3541 [(set_attr "type" "fcvt")
3542 (set_attr "mode" "DF")
3543 (set_attr "cnv_mode" "I2D")])
3546 (define_insn "floatdidf2"
3547 [(set (match_operand:DF 0 "register_operand" "=f")
3548 (float:DF (match_operand:DI 1 "register_operand" "f")))]
3549 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3551 [(set_attr "type" "fcvt")
3552 (set_attr "mode" "DF")
3553 (set_attr "cnv_mode" "I2D")])
3556 (define_insn "floatsisf2"
3557 [(set (match_operand:SF 0 "register_operand" "=f")
3558 (float:SF (match_operand:SI 1 "register_operand" "f")))]
3561 [(set_attr "type" "fcvt")
3562 (set_attr "mode" "SF")
3563 (set_attr "cnv_mode" "I2S")])
3566 (define_insn "floatdisf2"
3567 [(set (match_operand:SF 0 "register_operand" "=f")
3568 (float:SF (match_operand:DI 1 "register_operand" "f")))]
3569 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3571 [(set_attr "type" "fcvt")
3572 (set_attr "mode" "SF")
3573 (set_attr "cnv_mode" "I2S")])
3576 (define_expand "fixuns_truncdfsi2"
3577 [(set (match_operand:SI 0 "register_operand")
3578 (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
3579 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3581 rtx reg1 = gen_reg_rtx (DFmode);
3582 rtx reg2 = gen_reg_rtx (DFmode);
3583 rtx reg3 = gen_reg_rtx (SImode);
3584 rtx label1 = gen_label_rtx ();
3585 rtx label2 = gen_label_rtx ();
3587 REAL_VALUE_TYPE offset;
3589 real_2expN (&offset, 31, DFmode);
3591 if (reg1) /* Turn off complaints about unreached code. */
3593 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3594 do_pending_stack_adjust ();
3596 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3597 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3599 emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
3600 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3601 gen_rtx_LABEL_REF (VOIDmode, label2)));
3604 emit_label (label1);
3605 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3606 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3607 (BITMASK_HIGH, SImode)));
3609 emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
3610 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3612 emit_label (label2);
3614 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3615 fields, and can't be used for REG_NOTES anyway). */
3616 emit_use (stack_pointer_rtx);
3622 (define_expand "fixuns_truncdfdi2"
3623 [(set (match_operand:DI 0 "register_operand")
3624 (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
3625 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3627 rtx reg1 = gen_reg_rtx (DFmode);
3628 rtx reg2 = gen_reg_rtx (DFmode);
3629 rtx reg3 = gen_reg_rtx (DImode);
3630 rtx label1 = gen_label_rtx ();
3631 rtx label2 = gen_label_rtx ();
3633 REAL_VALUE_TYPE offset;
3635 real_2expN (&offset, 63, DFmode);
3637 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3638 do_pending_stack_adjust ();
3640 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3641 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3643 emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
3644 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3645 gen_rtx_LABEL_REF (VOIDmode, label2)));
3648 emit_label (label1);
3649 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3650 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3651 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3653 emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
3654 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3656 emit_label (label2);
3658 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3659 fields, and can't be used for REG_NOTES anyway). */
3660 emit_use (stack_pointer_rtx);
3665 (define_expand "fixuns_truncsfsi2"
3666 [(set (match_operand:SI 0 "register_operand")
3667 (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
3670 rtx reg1 = gen_reg_rtx (SFmode);
3671 rtx reg2 = gen_reg_rtx (SFmode);
3672 rtx reg3 = gen_reg_rtx (SImode);
3673 rtx label1 = gen_label_rtx ();
3674 rtx label2 = gen_label_rtx ();
3676 REAL_VALUE_TYPE offset;
3678 real_2expN (&offset, 31, SFmode);
3680 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3681 do_pending_stack_adjust ();
3683 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3684 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3686 emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
3687 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3688 gen_rtx_LABEL_REF (VOIDmode, label2)));
3691 emit_label (label1);
3692 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3693 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3694 (BITMASK_HIGH, SImode)));
3696 emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
3697 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3699 emit_label (label2);
3701 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3702 fields, and can't be used for REG_NOTES anyway). */
3703 emit_use (stack_pointer_rtx);
3708 (define_expand "fixuns_truncsfdi2"
3709 [(set (match_operand:DI 0 "register_operand")
3710 (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
3711 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3713 rtx reg1 = gen_reg_rtx (SFmode);
3714 rtx reg2 = gen_reg_rtx (SFmode);
3715 rtx reg3 = gen_reg_rtx (DImode);
3716 rtx label1 = gen_label_rtx ();
3717 rtx label2 = gen_label_rtx ();
3719 REAL_VALUE_TYPE offset;
3721 real_2expN (&offset, 63, SFmode);
3723 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3724 do_pending_stack_adjust ();
3726 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3727 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3729 emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
3730 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3731 gen_rtx_LABEL_REF (VOIDmode, label2)));
3734 emit_label (label1);
3735 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3736 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3737 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3739 emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
3740 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3742 emit_label (label2);
3744 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3745 fields, and can't be used for REG_NOTES anyway). */
3746 emit_use (stack_pointer_rtx);
3751 ;; ....................
3755 ;; ....................
3757 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
3759 (define_expand "extv"
3760 [(set (match_operand 0 "register_operand")
3761 (sign_extract (match_operand 1 "nonimmediate_operand")
3762 (match_operand 2 "const_int_operand")
3763 (match_operand 3 "const_int_operand")))]
3766 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3767 INTVAL (operands[2]),
3768 INTVAL (operands[3]),
3769 /*unsigned=*/ false))
3771 else if (register_operand (operands[1], GET_MODE (operands[0]))
3772 && ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32)
3774 if (GET_MODE (operands[0]) == DImode)
3775 emit_insn (gen_extvdi (operands[0], operands[1], operands[2],
3778 emit_insn (gen_extvsi (operands[0], operands[1], operands[2],
3786 (define_insn "extv<mode>"
3787 [(set (match_operand:GPR 0 "register_operand" "=d")
3788 (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3789 (match_operand 2 "const_int_operand" "")
3790 (match_operand 3 "const_int_operand" "")))]
3791 "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
3792 "exts\t%0,%1,%3,%m2"
3793 [(set_attr "type" "arith")
3794 (set_attr "mode" "<MODE>")])
3797 (define_expand "extzv"
3798 [(set (match_operand 0 "register_operand")
3799 (zero_extract (match_operand 1 "nonimmediate_operand")
3800 (match_operand 2 "const_int_operand")
3801 (match_operand 3 "const_int_operand")))]
3804 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3805 INTVAL (operands[2]),
3806 INTVAL (operands[3]),
3809 else if (mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3810 INTVAL (operands[3])))
3812 if (GET_MODE (operands[0]) == DImode)
3813 emit_insn (gen_extzvdi (operands[0], operands[1], operands[2],
3816 emit_insn (gen_extzvsi (operands[0], operands[1], operands[2],
3824 (define_insn "extzv<mode>"
3825 [(set (match_operand:GPR 0 "register_operand" "=d")
3826 (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3827 (match_operand 2 "const_int_operand" "")
3828 (match_operand 3 "const_int_operand" "")))]
3829 "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3830 INTVAL (operands[3]))"
3831 "<d>ext\t%0,%1,%3,%2"
3832 [(set_attr "type" "arith")
3833 (set_attr "mode" "<MODE>")])
3835 (define_insn "*extzv_truncsi_exts"
3836 [(set (match_operand:SI 0 "register_operand" "=d")
3838 (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
3839 (match_operand 2 "const_int_operand" "")
3840 (match_operand 3 "const_int_operand" ""))))]
3841 "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3843 [(set_attr "type" "arith")
3844 (set_attr "mode" "SI")])
3847 (define_expand "insv"
3848 [(set (zero_extract (match_operand 0 "nonimmediate_operand")
3849 (match_operand 1 "immediate_operand")
3850 (match_operand 2 "immediate_operand"))
3851 (match_operand 3 "reg_or_0_operand"))]
3854 if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
3855 INTVAL (operands[1]),
3856 INTVAL (operands[2])))
3858 else if (mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3859 INTVAL (operands[2])))
3861 if (GET_MODE (operands[0]) == DImode)
3862 emit_insn (gen_insvdi (operands[0], operands[1], operands[2],
3865 emit_insn (gen_insvsi (operands[0], operands[1], operands[2],
3873 (define_insn "insv<mode>"
3874 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
3875 (match_operand:SI 1 "immediate_operand" "I")
3876 (match_operand:SI 2 "immediate_operand" "I"))
3877 (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
3878 "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3879 INTVAL (operands[2]))"
3880 "<d>ins\t%0,%z3,%2,%1"
3881 [(set_attr "type" "arith")
3882 (set_attr "mode" "<MODE>")])
3884 ;; Combiner pattern for cins (clear and insert bit field). We can
3885 ;; implement mask-and-shift-left operation with this. Note that if
3886 ;; the upper bit of the mask is set in an SImode operation, the mask
3887 ;; itself will be sign-extended. mask_low_and_shift_len will
3888 ;; therefore be greater than our threshold of 32.
3890 (define_insn "*cins<mode>"
3891 [(set (match_operand:GPR 0 "register_operand" "=d")
3893 (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
3894 (match_operand:GPR 2 "const_int_operand" ""))
3895 (match_operand:GPR 3 "const_int_operand" "")))]
3897 && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
3900 GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
3901 return "cins\t%0,%1,%2,%m3";
3903 [(set_attr "type" "shift")
3904 (set_attr "mode" "<MODE>")])
3906 ;; Unaligned word moves generated by the bit field patterns.
3908 ;; As far as the rtl is concerned, both the left-part and right-part
3909 ;; instructions can access the whole field. However, the real operand
3910 ;; refers to just the first or the last byte (depending on endianness).
3911 ;; We therefore use two memory operands to each instruction, one to
3912 ;; describe the rtl effect and one to use in the assembly output.
3914 ;; Operands 0 and 1 are the rtl-level target and source respectively.
3915 ;; This allows us to use the standard length calculations for the "load"
3916 ;; and "store" type attributes.
3918 (define_insn "mov_<load>l"
3919 [(set (match_operand:GPR 0 "register_operand" "=d")
3920 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3921 (match_operand:QI 2 "memory_operand" "m")]
3923 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3925 [(set_attr "move_type" "load")
3926 (set_attr "mode" "<MODE>")])
3928 (define_insn "mov_<load>r"
3929 [(set (match_operand:GPR 0 "register_operand" "=d")
3930 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3931 (match_operand:QI 2 "memory_operand" "m")
3932 (match_operand:GPR 3 "register_operand" "0")]
3933 UNSPEC_LOAD_RIGHT))]
3934 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3936 [(set_attr "move_type" "load")
3937 (set_attr "mode" "<MODE>")])
3939 (define_insn "mov_<store>l"
3940 [(set (match_operand:BLK 0 "memory_operand" "=m")
3941 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3942 (match_operand:QI 2 "memory_operand" "m")]
3943 UNSPEC_STORE_LEFT))]
3944 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3946 [(set_attr "move_type" "store")
3947 (set_attr "mode" "<MODE>")])
3949 (define_insn "mov_<store>r"
3950 [(set (match_operand:BLK 0 "memory_operand" "+m")
3951 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3952 (match_operand:QI 2 "memory_operand" "m")
3954 UNSPEC_STORE_RIGHT))]
3955 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3957 [(set_attr "move_type" "store")
3958 (set_attr "mode" "<MODE>")])
3960 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
3961 ;; The required value is:
3963 ;; (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
3965 ;; which translates to:
3967 ;; lui op0,%highest(op1)
3968 ;; daddiu op0,op0,%higher(op1)
3970 ;; daddiu op0,op0,%hi(op1)
3973 ;; The split is deferred until after flow2 to allow the peephole2 below
3975 (define_insn_and_split "*lea_high64"
3976 [(set (match_operand:DI 0 "register_operand" "=d")
3977 (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
3978 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3980 "&& epilogue_completed"
3981 [(set (match_dup 0) (high:DI (match_dup 2)))
3982 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
3983 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
3984 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3985 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
3987 operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3988 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
3990 [(set_attr "length" "20")])
3992 ;; Use a scratch register to reduce the latency of the above pattern
3993 ;; on superscalar machines. The optimized sequence is:
3995 ;; lui op1,%highest(op2)
3997 ;; daddiu op1,op1,%higher(op2)
3999 ;; daddu op1,op1,op0
4001 [(set (match_operand:DI 1 "d_operand")
4002 (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4003 (match_scratch:DI 0 "d")]
4004 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4005 [(set (match_dup 1) (high:DI (match_dup 3)))
4006 (set (match_dup 0) (high:DI (match_dup 4)))
4007 (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4008 (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4009 (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4011 operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4012 operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4015 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4016 ;; SYMBOL_ABSOLUTE X will take 6 cycles. This next pattern allows combine
4017 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4018 ;; used once. We can then use the sequence:
4020 ;; lui op0,%highest(op1)
4022 ;; daddiu op0,op0,%higher(op1)
4023 ;; daddiu op2,op2,%lo(op1)
4025 ;; daddu op0,op0,op2
4027 ;; which takes 4 cycles on most superscalar targets.
4028 (define_insn_and_split "*lea64"
4029 [(set (match_operand:DI 0 "register_operand" "=d")
4030 (match_operand:DI 1 "absolute_symbolic_operand" ""))
4031 (clobber (match_scratch:DI 2 "=&d"))]
4032 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS && cse_not_expected"
4034 "&& reload_completed"
4035 [(set (match_dup 0) (high:DI (match_dup 3)))
4036 (set (match_dup 2) (high:DI (match_dup 4)))
4037 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4038 (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4039 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4040 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4042 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4043 operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4045 [(set_attr "length" "24")])
4047 ;; Split HIGHs into:
4052 ;; on MIPS16 targets.
4054 [(set (match_operand:P 0 "d_operand")
4055 (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4056 "TARGET_MIPS16 && reload_completed"
4057 [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4058 (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4060 (define_insn "*unshifted_high"
4061 [(set (match_operand:P 0 "d_operand" "=d")
4062 (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4063 UNSPEC_UNSHIFTED_HIGH))]
4066 [(set_attr "extended_mips16" "yes")])
4068 ;; Insns to fetch a symbol from a big GOT.
4070 (define_insn_and_split "*xgot_hi<mode>"
4071 [(set (match_operand:P 0 "register_operand" "=d")
4072 (high:P (match_operand:P 1 "got_disp_operand" "")))]
4073 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4075 "&& reload_completed"
4076 [(set (match_dup 0) (high:P (match_dup 2)))
4077 (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4079 operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4080 operands[3] = pic_offset_table_rtx;
4082 [(set_attr "got" "xgot_high")
4083 (set_attr "mode" "<MODE>")])
4085 (define_insn_and_split "*xgot_lo<mode>"
4086 [(set (match_operand:P 0 "register_operand" "=d")
4087 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4088 (match_operand:P 2 "got_disp_operand" "")))]
4089 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4091 "&& reload_completed"
4093 (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4094 { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4095 [(set_attr "got" "load")
4096 (set_attr "mode" "<MODE>")])
4098 ;; Insns to fetch a symbol from a normal GOT.
4100 (define_insn_and_split "*got_disp<mode>"
4101 [(set (match_operand:P 0 "register_operand" "=d")
4102 (match_operand:P 1 "got_disp_operand" ""))]
4103 "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4105 "&& reload_completed"
4106 [(set (match_dup 0) (match_dup 2))]
4107 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4108 [(set_attr "got" "load")
4109 (set_attr "mode" "<MODE>")])
4111 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4113 (define_insn_and_split "*got_page<mode>"
4114 [(set (match_operand:P 0 "register_operand" "=d")
4115 (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4116 "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4118 "&& reload_completed"
4119 [(set (match_dup 0) (match_dup 2))]
4120 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4121 [(set_attr "got" "load")
4122 (set_attr "mode" "<MODE>")])
4124 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4125 (define_expand "unspec_got_<mode>"
4126 [(unspec:P [(match_operand:P 0)
4127 (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4129 ;; Lower-level instructions for loading an address from the GOT.
4130 ;; We could use MEMs, but an unspec gives more optimization
4133 (define_insn "load_got<mode>"
4134 [(set (match_operand:P 0 "register_operand" "=d")
4135 (unspec:P [(match_operand:P 1 "register_operand" "d")
4136 (match_operand:P 2 "immediate_operand" "")]
4139 "<load>\t%0,%R2(%1)"
4140 [(set_attr "got" "load")
4141 (set_attr "mode" "<MODE>")])
4143 ;; Instructions for adding the low 16 bits of an address to a register.
4144 ;; Operand 2 is the address: mips_print_operand works out which relocation
4145 ;; should be applied.
4147 (define_insn "*low<mode>"
4148 [(set (match_operand:P 0 "register_operand" "=d")
4149 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4150 (match_operand:P 2 "immediate_operand" "")))]
4152 "<d>addiu\t%0,%1,%R2"
4153 [(set_attr "alu_type" "add")
4154 (set_attr "mode" "<MODE>")])
4156 (define_insn "*low<mode>_mips16"
4157 [(set (match_operand:P 0 "register_operand" "=d")
4158 (lo_sum:P (match_operand:P 1 "register_operand" "0")
4159 (match_operand:P 2 "immediate_operand" "")))]
4162 [(set_attr "alu_type" "add")
4163 (set_attr "mode" "<MODE>")
4164 (set_attr "extended_mips16" "yes")])
4166 ;; Expose MIPS16 uses of the global pointer after reload if the function
4167 ;; is responsible for setting up the register itself.
4169 [(set (match_operand:GPR 0 "d_operand")
4170 (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4171 "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4172 [(set (match_dup 0) (match_dup 1))]
4173 { operands[1] = pic_offset_table_rtx; })
4175 ;; Allow combine to split complex const_int load sequences, using operand 2
4176 ;; to store the intermediate results. See move_operand for details.
4178 [(set (match_operand:GPR 0 "register_operand")
4179 (match_operand:GPR 1 "splittable_const_int_operand"))
4180 (clobber (match_operand:GPR 2 "register_operand"))]
4184 mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4188 ;; Likewise, for symbolic operands.
4190 [(set (match_operand:P 0 "register_operand")
4191 (match_operand:P 1))
4192 (clobber (match_operand:P 2 "register_operand"))]
4193 "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4194 [(set (match_dup 0) (match_dup 3))]
4196 mips_split_symbol (operands[2], operands[1],
4197 MAX_MACHINE_MODE, &operands[3]);
4200 ;; 64-bit integer moves
4202 ;; Unlike most other insns, the move insns can't be split with
4203 ;; different predicates, because register spilling and other parts of
4204 ;; the compiler, have memoized the insn number already.
4206 (define_expand "movdi"
4207 [(set (match_operand:DI 0 "")
4208 (match_operand:DI 1 ""))]
4211 if (mips_legitimize_move (DImode, operands[0], operands[1]))
4215 ;; For mips16, we need a special case to handle storing $31 into
4216 ;; memory, since we don't have a constraint to match $31. This
4217 ;; instruction can be generated by save_restore_insns.
4219 (define_insn "*mov<mode>_ra"
4220 [(set (match_operand:GPR 0 "stack_operand" "=m")
4221 (reg:GPR RETURN_ADDR_REGNUM))]
4224 [(set_attr "move_type" "store")
4225 (set_attr "mode" "<MODE>")])
4227 (define_insn "*movdi_32bit"
4228 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d,*f,*f,*d,*m,*B*C*D,*B*C*D,*d,*m")
4229 (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"))]
4230 "!TARGET_64BIT && !TARGET_MIPS16
4231 && (register_operand (operands[0], DImode)
4232 || reg_or_0_operand (operands[1], DImode))"
4233 { return mips_output_move (operands[0], operands[1]); }
4234 [(set_attr "move_type" "move,const,load,store,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4235 (set_attr "mode" "DI")])
4237 (define_insn "*movdi_32bit_mips16"
4238 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4239 (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4240 "!TARGET_64BIT && TARGET_MIPS16
4241 && (register_operand (operands[0], DImode)
4242 || register_operand (operands[1], DImode))"
4243 { return mips_output_move (operands[0], operands[1]); }
4244 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4245 (set_attr "mode" "DI")])
4247 (define_insn "*movdi_64bit"
4248 [(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")
4249 (match_operand:DI 1 "move_operand" "d,U,T,m,dJ,*d*J,*m,*f,*f,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4250 "TARGET_64BIT && !TARGET_MIPS16
4251 && (register_operand (operands[0], DImode)
4252 || reg_or_0_operand (operands[1], DImode))"
4253 { return mips_output_move (operands[0], operands[1]); }
4254 [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4255 (set_attr "mode" "DI")])
4257 (define_insn "*movdi_64bit_mips16"
4258 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4259 (match_operand:DI 1 "move_operand" "d,d,y,K,N,U,kf,m,d,*a"))]
4260 "TARGET_64BIT && TARGET_MIPS16
4261 && (register_operand (operands[0], DImode)
4262 || register_operand (operands[1], DImode))"
4263 { return mips_output_move (operands[0], operands[1]); }
4264 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4265 (set_attr "mode" "DI")])
4267 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4268 ;; when the original load is a 4 byte instruction but the add and the
4269 ;; load are 2 2 byte instructions.
4272 [(set (match_operand:DI 0 "d_operand")
4273 (mem:DI (plus:DI (match_dup 0)
4274 (match_operand:DI 1 "const_int_operand"))))]
4275 "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4276 && !TARGET_DEBUG_D_MODE
4277 && ((INTVAL (operands[1]) < 0
4278 && INTVAL (operands[1]) >= -0x10)
4279 || (INTVAL (operands[1]) >= 32 * 8
4280 && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4281 || (INTVAL (operands[1]) >= 0
4282 && INTVAL (operands[1]) < 32 * 8
4283 && (INTVAL (operands[1]) & 7) != 0))"
4284 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4285 (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4287 HOST_WIDE_INT val = INTVAL (operands[1]);
4290 operands[2] = const0_rtx;
4291 else if (val >= 32 * 8)
4295 operands[1] = GEN_INT (0x8 + off);
4296 operands[2] = GEN_INT (val - off - 0x8);
4302 operands[1] = GEN_INT (off);
4303 operands[2] = GEN_INT (val - off);
4307 ;; 32-bit Integer moves
4309 ;; Unlike most other insns, the move insns can't be split with
4310 ;; different predicates, because register spilling and other parts of
4311 ;; the compiler, have memoized the insn number already.
4313 (define_expand "mov<mode>"
4314 [(set (match_operand:IMOVE32 0 "")
4315 (match_operand:IMOVE32 1 ""))]
4318 if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4322 ;; The difference between these two is whether or not ints are allowed
4323 ;; in FP registers (off by default, use -mdebugh to enable).
4325 (define_insn "*mov<mode>_internal"
4326 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*d,*m,*d,*z,*a,*d,*B*C*D,*B*C*D,*d,*m")
4327 (match_operand:IMOVE32 1 "move_operand" "d,U,T,m,dJ,*d*J,*m,*f,*f,*z,*d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4329 && (register_operand (operands[0], <MODE>mode)
4330 || reg_or_0_operand (operands[1], <MODE>mode))"
4331 { return mips_output_move (operands[0], operands[1]); }
4332 [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mfc,mtc,mtlo,mflo,mtc,fpload,mfc,fpstore")
4333 (set_attr "mode" "SI")])
4335 (define_insn "*mov<mode>_mips16"
4336 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4337 (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,U,kf,m,d,*a"))]
4339 && (register_operand (operands[0], <MODE>mode)
4340 || register_operand (operands[1], <MODE>mode))"
4341 { return mips_output_move (operands[0], operands[1]); }
4342 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4343 (set_attr "mode" "SI")])
4345 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4346 ;; when the original load is a 4 byte instruction but the add and the
4347 ;; load are 2 2 byte instructions.
4350 [(set (match_operand:SI 0 "d_operand")
4351 (mem:SI (plus:SI (match_dup 0)
4352 (match_operand:SI 1 "const_int_operand"))))]
4353 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4354 && ((INTVAL (operands[1]) < 0
4355 && INTVAL (operands[1]) >= -0x80)
4356 || (INTVAL (operands[1]) >= 32 * 4
4357 && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4358 || (INTVAL (operands[1]) >= 0
4359 && INTVAL (operands[1]) < 32 * 4
4360 && (INTVAL (operands[1]) & 3) != 0))"
4361 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4362 (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4364 HOST_WIDE_INT val = INTVAL (operands[1]);
4367 operands[2] = const0_rtx;
4368 else if (val >= 32 * 4)
4372 operands[1] = GEN_INT (0x7c + off);
4373 operands[2] = GEN_INT (val - off - 0x7c);
4379 operands[1] = GEN_INT (off);
4380 operands[2] = GEN_INT (val - off);
4384 ;; On the mips16, we can split a load of certain constants into a load
4385 ;; and an add. This turns a 4 byte instruction into 2 2 byte
4389 [(set (match_operand:SI 0 "d_operand")
4390 (match_operand:SI 1 "const_int_operand"))]
4391 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4392 && INTVAL (operands[1]) >= 0x100
4393 && INTVAL (operands[1]) <= 0xff + 0x7f"
4394 [(set (match_dup 0) (match_dup 1))
4395 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4397 int val = INTVAL (operands[1]);
4399 operands[1] = GEN_INT (0xff);
4400 operands[2] = GEN_INT (val - 0xff);
4403 ;; This insn handles moving CCmode values. It's really just a
4404 ;; slightly simplified copy of movsi_internal2, with additional cases
4405 ;; to move a condition register to a general register and to move
4406 ;; between the general registers and the floating point registers.
4408 (define_insn "movcc"
4409 [(set (match_operand:CC 0 "nonimmediate_operand" "=d,*d,*d,*m,*d,*f,*f,*f,*m")
4410 (match_operand:CC 1 "general_operand" "z,*d,*m,*d,*f,*d,*f,*m,*f"))]
4411 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4412 { return mips_output_move (operands[0], operands[1]); }
4413 [(set_attr "move_type" "lui_movf,move,load,store,mfc,mtc,fmove,fpload,fpstore")
4414 (set_attr "mode" "SI")])
4416 ;; Reload condition code registers. reload_incc and reload_outcc
4417 ;; both handle moves from arbitrary operands into condition code
4418 ;; registers. reload_incc handles the more common case in which
4419 ;; a source operand is constrained to be in a condition-code
4420 ;; register, but has not been allocated to one.
4422 ;; Sometimes, such as in movcc, we have a CCmode destination whose
4423 ;; constraints do not include 'z'. reload_outcc handles the case
4424 ;; when such an operand is allocated to a condition-code register.
4426 ;; Note that reloads from a condition code register to some
4427 ;; other location can be done using ordinary moves. Moving
4428 ;; into a GPR takes a single movcc, moving elsewhere takes
4429 ;; two. We can leave these cases to the generic reload code.
4430 (define_expand "reload_incc"
4431 [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
4432 (match_operand:CC 1 "general_operand" ""))
4433 (clobber (match_operand:TF 2 "register_operand" "=&f"))]
4434 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4436 mips_expand_fcc_reload (operands[0], operands[1], operands[2]);
4440 (define_expand "reload_outcc"
4441 [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
4442 (match_operand:CC 1 "register_operand" ""))
4443 (clobber (match_operand:TF 2 "register_operand" "=&f"))]
4444 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4446 mips_expand_fcc_reload (operands[0], operands[1], operands[2]);
4450 ;; MIPS4 supports loading and storing a floating point register from
4451 ;; the sum of two general registers. We use two versions for each of
4452 ;; these four instructions: one where the two general registers are
4453 ;; SImode, and one where they are DImode. This is because general
4454 ;; registers will be in SImode when they hold 32-bit values, but,
4455 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4456 ;; instructions will still work correctly.
4458 ;; ??? Perhaps it would be better to support these instructions by
4459 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends. However, since
4460 ;; these instructions can only be used to load and store floating
4461 ;; point registers, that would probably cause trouble in reload.
4463 (define_insn "*<ANYF:loadx>_<P:mode>"
4464 [(set (match_operand:ANYF 0 "register_operand" "=f")
4465 (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4466 (match_operand:P 2 "register_operand" "d"))))]
4468 "<ANYF:loadx>\t%0,%1(%2)"
4469 [(set_attr "type" "fpidxload")
4470 (set_attr "mode" "<ANYF:UNITMODE>")])
4472 (define_insn "*<ANYF:storex>_<P:mode>"
4473 [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4474 (match_operand:P 2 "register_operand" "d")))
4475 (match_operand:ANYF 0 "register_operand" "f"))]
4477 "<ANYF:storex>\t%0,%1(%2)"
4478 [(set_attr "type" "fpidxstore")
4479 (set_attr "mode" "<ANYF:UNITMODE>")])
4481 ;; Scaled indexed address load.
4482 ;; Per md.texi, we only need to look for a pattern with multiply in the
4483 ;; address expression, not shift.
4485 (define_insn "*lwxs"
4486 [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4488 (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4490 (match_operand:P 2 "register_operand" "d"))))]
4493 [(set_attr "type" "load")
4494 (set_attr "mode" "SI")])
4496 ;; 16-bit Integer moves
4498 ;; Unlike most other insns, the move insns can't be split with
4499 ;; different predicates, because register spilling and other parts of
4500 ;; the compiler, have memoized the insn number already.
4501 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4503 (define_expand "movhi"
4504 [(set (match_operand:HI 0 "")
4505 (match_operand:HI 1 ""))]
4508 if (mips_legitimize_move (HImode, operands[0], operands[1]))
4512 (define_insn "*movhi_internal"
4513 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4514 (match_operand:HI 1 "move_operand" "d,I,m,dJ,*d*J,*a"))]
4516 && (register_operand (operands[0], HImode)
4517 || reg_or_0_operand (operands[1], HImode))"
4518 { return mips_output_move (operands[0], operands[1]); }
4519 [(set_attr "move_type" "move,const,load,store,mtlo,mflo")
4520 (set_attr "mode" "HI")])
4522 (define_insn "*movhi_mips16"
4523 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4524 (match_operand:HI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4526 && (register_operand (operands[0], HImode)
4527 || register_operand (operands[1], HImode))"
4528 { return mips_output_move (operands[0], operands[1]); }
4529 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4530 (set_attr "mode" "HI")])
4532 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
4533 ;; when the original load is a 4 byte instruction but the add and the
4534 ;; load are 2 2 byte instructions.
4537 [(set (match_operand:HI 0 "d_operand")
4538 (mem:HI (plus:SI (match_dup 0)
4539 (match_operand:SI 1 "const_int_operand"))))]
4540 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4541 && ((INTVAL (operands[1]) < 0
4542 && INTVAL (operands[1]) >= -0x80)
4543 || (INTVAL (operands[1]) >= 32 * 2
4544 && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
4545 || (INTVAL (operands[1]) >= 0
4546 && INTVAL (operands[1]) < 32 * 2
4547 && (INTVAL (operands[1]) & 1) != 0))"
4548 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4549 (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
4551 HOST_WIDE_INT val = INTVAL (operands[1]);
4554 operands[2] = const0_rtx;
4555 else if (val >= 32 * 2)
4559 operands[1] = GEN_INT (0x7e + off);
4560 operands[2] = GEN_INT (val - off - 0x7e);
4566 operands[1] = GEN_INT (off);
4567 operands[2] = GEN_INT (val - off);
4571 ;; 8-bit Integer moves
4573 ;; Unlike most other insns, the move insns can't be split with
4574 ;; different predicates, because register spilling and other parts of
4575 ;; the compiler, have memoized the insn number already.
4576 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4578 (define_expand "movqi"
4579 [(set (match_operand:QI 0 "")
4580 (match_operand:QI 1 ""))]
4583 if (mips_legitimize_move (QImode, operands[0], operands[1]))
4587 (define_insn "*movqi_internal"
4588 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4589 (match_operand:QI 1 "move_operand" "d,I,m,dJ,*d*J,*a"))]
4591 && (register_operand (operands[0], QImode)
4592 || reg_or_0_operand (operands[1], QImode))"
4593 { return mips_output_move (operands[0], operands[1]); }
4594 [(set_attr "move_type" "move,const,load,store,mtlo,mflo")
4595 (set_attr "mode" "QI")])
4597 (define_insn "*movqi_mips16"
4598 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4599 (match_operand:QI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4601 && (register_operand (operands[0], QImode)
4602 || register_operand (operands[1], QImode))"
4603 { return mips_output_move (operands[0], operands[1]); }
4604 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4605 (set_attr "mode" "QI")])
4607 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
4608 ;; when the original load is a 4 byte instruction but the add and the
4609 ;; load are 2 2 byte instructions.
4612 [(set (match_operand:QI 0 "d_operand")
4613 (mem:QI (plus:SI (match_dup 0)
4614 (match_operand:SI 1 "const_int_operand"))))]
4615 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4616 && ((INTVAL (operands[1]) < 0
4617 && INTVAL (operands[1]) >= -0x80)
4618 || (INTVAL (operands[1]) >= 32
4619 && INTVAL (operands[1]) <= 31 + 0x7f))"
4620 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4621 (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
4623 HOST_WIDE_INT val = INTVAL (operands[1]);
4626 operands[2] = const0_rtx;
4629 operands[1] = GEN_INT (0x7f);
4630 operands[2] = GEN_INT (val - 0x7f);
4634 ;; 32-bit floating point moves
4636 (define_expand "movsf"
4637 [(set (match_operand:SF 0 "")
4638 (match_operand:SF 1 ""))]
4641 if (mips_legitimize_move (SFmode, operands[0], operands[1]))
4645 (define_insn "*movsf_hardfloat"
4646 [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4647 (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
4649 && (register_operand (operands[0], SFmode)
4650 || reg_or_0_operand (operands[1], SFmode))"
4651 { return mips_output_move (operands[0], operands[1]); }
4652 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4653 (set_attr "mode" "SF")])
4655 (define_insn "*movsf_softfloat"
4656 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
4657 (match_operand:SF 1 "move_operand" "Gd,m,d"))]
4658 "TARGET_SOFT_FLOAT && !TARGET_MIPS16
4659 && (register_operand (operands[0], SFmode)
4660 || reg_or_0_operand (operands[1], SFmode))"
4661 { return mips_output_move (operands[0], operands[1]); }
4662 [(set_attr "move_type" "move,load,store")
4663 (set_attr "mode" "SF")])
4665 (define_insn "*movsf_mips16"
4666 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
4667 (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
4669 && (register_operand (operands[0], SFmode)
4670 || register_operand (operands[1], SFmode))"
4671 { return mips_output_move (operands[0], operands[1]); }
4672 [(set_attr "move_type" "move,move,move,load,store")
4673 (set_attr "mode" "SF")])
4675 ;; 64-bit floating point moves
4677 (define_expand "movdf"
4678 [(set (match_operand:DF 0 "")
4679 (match_operand:DF 1 ""))]
4682 if (mips_legitimize_move (DFmode, operands[0], operands[1]))
4686 (define_insn "*movdf_hardfloat"
4687 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4688 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
4689 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
4690 && (register_operand (operands[0], DFmode)
4691 || reg_or_0_operand (operands[1], DFmode))"
4692 { return mips_output_move (operands[0], operands[1]); }
4693 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4694 (set_attr "mode" "DF")])
4696 (define_insn "*movdf_softfloat"
4697 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
4698 (match_operand:DF 1 "move_operand" "dG,m,dG"))]
4699 "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
4700 && (register_operand (operands[0], DFmode)
4701 || reg_or_0_operand (operands[1], DFmode))"
4702 { return mips_output_move (operands[0], operands[1]); }
4703 [(set_attr "move_type" "move,load,store")
4704 (set_attr "mode" "DF")])
4706 (define_insn "*movdf_mips16"
4707 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
4708 (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
4710 && (register_operand (operands[0], DFmode)
4711 || register_operand (operands[1], DFmode))"
4712 { return mips_output_move (operands[0], operands[1]); }
4713 [(set_attr "move_type" "move,move,move,load,store")
4714 (set_attr "mode" "DF")])
4716 ;; 128-bit integer moves
4718 (define_expand "movti"
4719 [(set (match_operand:TI 0)
4720 (match_operand:TI 1))]
4723 if (mips_legitimize_move (TImode, operands[0], operands[1]))
4727 (define_insn "*movti"
4728 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4729 (match_operand:TI 1 "move_operand" "d,i,m,dJ,*d*J,*a"))]
4732 && (register_operand (operands[0], TImode)
4733 || reg_or_0_operand (operands[1], TImode))"
4735 [(set_attr "move_type" "move,const,load,store,mtlo,mflo")
4736 (set_attr "mode" "TI")])
4738 (define_insn "*movti_mips16"
4739 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4740 (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4743 && (register_operand (operands[0], TImode)
4744 || register_operand (operands[1], TImode))"
4746 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4747 (set_attr "mode" "TI")])
4749 ;; 128-bit floating point moves
4751 (define_expand "movtf"
4752 [(set (match_operand:TF 0)
4753 (match_operand:TF 1))]
4756 if (mips_legitimize_move (TFmode, operands[0], operands[1]))
4760 ;; This pattern handles both hard- and soft-float cases.
4761 (define_insn "*movtf"
4762 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
4763 (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
4766 && (register_operand (operands[0], TFmode)
4767 || reg_or_0_operand (operands[1], TFmode))"
4769 [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
4770 (set_attr "mode" "TF")])
4772 (define_insn "*movtf_mips16"
4773 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
4774 (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
4777 && (register_operand (operands[0], TFmode)
4778 || register_operand (operands[1], TFmode))"
4780 [(set_attr "move_type" "move,move,move,load,store")
4781 (set_attr "mode" "TF")])
4784 [(set (match_operand:MOVE64 0 "nonimmediate_operand")
4785 (match_operand:MOVE64 1 "move_operand"))]
4786 "reload_completed && !TARGET_64BIT
4787 && mips_split_64bit_move_p (operands[0], operands[1])"
4790 mips_split_doubleword_move (operands[0], operands[1]);
4795 [(set (match_operand:MOVE128 0 "nonimmediate_operand")
4796 (match_operand:MOVE128 1 "move_operand"))]
4797 "TARGET_64BIT && reload_completed"
4800 mips_split_doubleword_move (operands[0], operands[1]);
4804 ;; When generating mips16 code, split moves of negative constants into
4805 ;; a positive "li" followed by a negation.
4807 [(set (match_operand 0 "d_operand")
4808 (match_operand 1 "const_int_operand"))]
4809 "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
4813 (neg:SI (match_dup 2)))]
4815 operands[2] = gen_lowpart (SImode, operands[0]);
4816 operands[3] = GEN_INT (-INTVAL (operands[1]));
4819 ;; 64-bit paired-single floating point moves
4821 (define_expand "movv2sf"
4822 [(set (match_operand:V2SF 0)
4823 (match_operand:V2SF 1))]
4824 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
4826 if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
4830 (define_insn "*movv2sf"
4831 [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4832 (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
4834 && TARGET_PAIRED_SINGLE_FLOAT
4835 && (register_operand (operands[0], V2SFmode)
4836 || reg_or_0_operand (operands[1], V2SFmode))"
4837 { return mips_output_move (operands[0], operands[1]); }
4838 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4839 (set_attr "mode" "DF")])
4841 ;; Extract the high part of a HI/LO value. See mips_hard_regno_mode_ok_p
4842 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
4844 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
4845 ;; instead of MFHI. This avoids both the normal MIPS III hi/lo hazards
4846 ;; and the errata related to -mfix-vr4130.
4847 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
4848 [(set (match_operand:GPR 0 "register_operand" "=d")
4849 (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
4852 { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
4853 [(set_attr "type" "mfhi")
4854 (set_attr "mode" "<GPR:MODE>")])
4856 ;; Set the high part of a HI/LO value, given that the low part has
4857 ;; already been set. See mips_hard_regno_mode_ok_p for the reason
4858 ;; why we can't just use (reg:GPR HI_REGNUM).
4859 (define_insn "mthi<GPR:mode>_<HILO:mode>"
4860 [(set (match_operand:HILO 0 "register_operand" "=x")
4861 (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4862 (match_operand:GPR 2 "register_operand" "l")]
4866 [(set_attr "type" "mthi")
4867 (set_attr "mode" "SI")])
4869 ;; Emit a doubleword move in which exactly one of the operands is
4870 ;; a floating-point register. We can't just emit two normal moves
4871 ;; because of the constraints imposed by the FPU register model;
4872 ;; see mips_cannot_change_mode_class for details. Instead, we keep
4873 ;; the FPR whole and use special patterns to refer to each word of
4874 ;; the other operand.
4876 (define_expand "move_doubleword_fpr<mode>"
4877 [(set (match_operand:SPLITF 0)
4878 (match_operand:SPLITF 1))]
4881 if (FP_REG_RTX_P (operands[0]))
4883 rtx low = mips_subword (operands[1], 0);
4884 rtx high = mips_subword (operands[1], 1);
4885 emit_insn (gen_load_low<mode> (operands[0], low));
4886 if (TARGET_FLOAT64 && !TARGET_64BIT)
4887 emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
4889 emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
4893 rtx low = mips_subword (operands[0], 0);
4894 rtx high = mips_subword (operands[0], 1);
4895 emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
4896 if (TARGET_FLOAT64 && !TARGET_64BIT)
4897 emit_insn (gen_mfhc1<mode> (high, operands[1]));
4899 emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
4904 ;; Load the low word of operand 0 with operand 1.
4905 (define_insn "load_low<mode>"
4906 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4907 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
4911 operands[0] = mips_subword (operands[0], 0);
4912 return mips_output_move (operands[0], operands[1]);
4914 [(set_attr "move_type" "mtc,fpload")
4915 (set_attr "mode" "<HALFMODE>")])
4917 ;; Load the high word of operand 0 from operand 1, preserving the value
4919 (define_insn "load_high<mode>"
4920 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4921 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
4922 (match_operand:SPLITF 2 "register_operand" "0,0")]
4926 operands[0] = mips_subword (operands[0], 1);
4927 return mips_output_move (operands[0], operands[1]);
4929 [(set_attr "move_type" "mtc,fpload")
4930 (set_attr "mode" "<HALFMODE>")])
4932 ;; Store one word of operand 1 in operand 0. Operand 2 is 1 to store the
4933 ;; high word and 0 to store the low word.
4934 (define_insn "store_word<mode>"
4935 [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
4936 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
4937 (match_operand 2 "const_int_operand")]
4938 UNSPEC_STORE_WORD))]
4941 operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
4942 return mips_output_move (operands[0], operands[1]);
4944 [(set_attr "move_type" "mfc,fpstore")
4945 (set_attr "mode" "<HALFMODE>")])
4947 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
4948 ;; value in the low word.
4949 (define_insn "mthc1<mode>"
4950 [(set (match_operand:SPLITF 0 "register_operand" "=f")
4951 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
4952 (match_operand:SPLITF 2 "register_operand" "0")]
4954 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4956 [(set_attr "move_type" "mtc")
4957 (set_attr "mode" "<HALFMODE>")])
4959 ;; Move high word of operand 1 to operand 0 using mfhc1.
4960 (define_insn "mfhc1<mode>"
4961 [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
4962 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
4964 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4966 [(set_attr "move_type" "mfc")
4967 (set_attr "mode" "<HALFMODE>")])
4969 ;; Move a constant that satisfies CONST_GP_P into operand 0.
4970 (define_expand "load_const_gp_<mode>"
4971 [(set (match_operand:P 0 "register_operand" "=d")
4972 (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
4974 ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset
4975 ;; of _gp from the start of this function. Operand 1 is the incoming
4976 ;; function address.
4977 (define_insn_and_split "loadgp_newabi_<mode>"
4978 [(set (match_operand:P 0 "register_operand" "=&d")
4979 (unspec:P [(match_operand:P 1)
4980 (match_operand:P 2 "register_operand" "d")]
4982 "mips_current_loadgp_style () == LOADGP_NEWABI"
4983 { return mips_must_initialize_gp_p () ? "#" : ""; }
4984 "&& mips_must_initialize_gp_p ()"
4985 [(set (match_dup 0) (match_dup 3))
4986 (set (match_dup 0) (match_dup 4))
4987 (set (match_dup 0) (match_dup 5))]
4989 operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
4990 operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
4991 operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
4993 [(set_attr "type" "ghost")])
4995 ;; Likewise, for -mno-shared code. Operand 0 is the __gnu_local_gp symbol.
4996 (define_insn_and_split "loadgp_absolute_<mode>"
4997 [(set (match_operand:P 0 "register_operand" "=d")
4998 (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
4999 "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
5000 { return mips_must_initialize_gp_p () ? "#" : ""; }
5001 "&& mips_must_initialize_gp_p ()"
5004 mips_emit_move (operands[0], operands[1]);
5007 [(set_attr "type" "ghost")])
5009 ;; This blockage instruction prevents the gp load from being
5010 ;; scheduled after an implicit use of gp. It also prevents
5011 ;; the load from being deleted as dead.
5012 (define_insn "loadgp_blockage"
5013 [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5016 [(set_attr "type" "ghost")])
5018 ;; Initialize $gp for RTP PIC. Operand 0 is the __GOTT_BASE__ symbol
5019 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5020 (define_insn_and_split "loadgp_rtp_<mode>"
5021 [(set (match_operand:P 0 "register_operand" "=d")
5022 (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5023 (match_operand:P 2 "symbol_ref_operand")]
5025 "mips_current_loadgp_style () == LOADGP_RTP"
5026 { return mips_must_initialize_gp_p () ? "#" : ""; }
5027 "&& mips_must_initialize_gp_p ()"
5028 [(set (match_dup 0) (high:P (match_dup 3)))
5029 (set (match_dup 0) (unspec:P [(match_dup 0)
5030 (match_dup 3)] UNSPEC_LOAD_GOT))
5031 (set (match_dup 0) (unspec:P [(match_dup 0)
5032 (match_dup 4)] UNSPEC_LOAD_GOT))]
5034 operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5035 operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5037 [(set_attr "type" "ghost")])
5039 ;; Initialize the global pointer for MIPS16 code. Operand 0 is the
5040 ;; global pointer and operand 1 is the MIPS16 register that holds
5041 ;; the required value.
5042 (define_insn_and_split "copygp_mips16_<mode>"
5043 [(set (match_operand:P 0 "register_operand" "=y")
5044 (unspec:P [(match_operand:P 1 "register_operand" "d")]
5047 { return mips_must_initialize_gp_p () ? "#" : ""; }
5048 "&& mips_must_initialize_gp_p ()"
5049 [(set (match_dup 0) (match_dup 1))]
5051 [(set_attr "type" "ghost")])
5053 ;; A placeholder for where the cprestore instruction should go,
5054 ;; if we decide we need one. Operand 0 and operand 1 are as for
5055 ;; "cprestore". Operand 2 is a register that holds the gp value.
5057 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5058 ;; otherwise any register that holds the correct value will do.
5059 (define_insn_and_split "potential_cprestore_<mode>"
5060 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5061 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5062 (match_operand:P 2 "register_operand" "d,d")]
5063 UNSPEC_POTENTIAL_CPRESTORE))
5064 (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5065 "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5066 { return mips_must_initialize_gp_p () ? "#" : ""; }
5067 "mips_must_initialize_gp_p ()"
5070 mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5071 operands[2], operands[3]);
5074 [(set_attr "type" "ghost")])
5076 ;; Emit a .cprestore directive, which normally expands to a single store
5077 ;; instruction. Operand 0 is a (possibly illegitimate) sp-based MEM
5078 ;; for the cprestore slot. Operand 1 is the offset of the slot from
5079 ;; the stack pointer. (This is redundant with operand 0, but it makes
5080 ;; things a little simpler.)
5081 (define_insn "cprestore_<mode>"
5082 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5083 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5086 "TARGET_CPRESTORE_DIRECTIVE"
5088 if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5089 return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5091 return ".cprestore\t%1";
5093 [(set_attr "type" "store")
5094 (set_attr "length" "4,12")])
5096 (define_insn "use_cprestore_<mode>"
5097 [(set (reg:P CPRESTORE_SLOT_REGNUM)
5098 (match_operand:P 0 "cprestore_load_slot_operand"))]
5101 [(set_attr "type" "ghost")])
5103 ;; Expand in-line code to clear the instruction cache between operand[0] and
5105 (define_expand "clear_cache"
5106 [(match_operand 0 "pmode_register_operand")
5107 (match_operand 1 "pmode_register_operand")]
5113 mips_expand_synci_loop (operands[0], operands[1]);
5114 emit_insn (gen_sync ());
5115 emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5117 else if (mips_cache_flush_func && mips_cache_flush_func[0])
5119 rtx len = gen_reg_rtx (Pmode);
5120 emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5121 MIPS_ICACHE_SYNC (operands[0], len);
5127 [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5129 { return mips_output_sync (); })
5131 (define_insn "synci"
5132 [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5137 (define_insn "rdhwr_synci_step_<mode>"
5138 [(set (match_operand:P 0 "register_operand" "=d")
5139 (unspec_volatile [(const_int 1)]
5144 (define_insn "clear_hazard_<mode>"
5145 [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5146 (clobber (reg:P RETURN_ADDR_REGNUM))]
5149 return "%(%<bal\t1f\n"
5151 "1:\t<d>addiu\t$31,$31,12\n"
5155 [(set_attr "length" "20")])
5157 ;; Cache operations for R4000-style caches.
5158 (define_insn "mips_cache"
5159 [(set (mem:BLK (scratch))
5160 (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5161 (match_operand:QI 1 "address_operand" "p")]
5162 UNSPEC_MIPS_CACHE))]
5166 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5167 ;; operation. We keep the pattern distinct so that we can identify
5168 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5169 ;; the operation is never inserted into a delay slot.
5170 (define_insn "r10k_cache_barrier"
5171 [(set (mem:BLK (scratch))
5172 (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5175 [(set_attr "can_delay" "no")])
5177 ;; Block moves, see mips.c for more details.
5178 ;; Argument 0 is the destination
5179 ;; Argument 1 is the source
5180 ;; Argument 2 is the length
5181 ;; Argument 3 is the alignment
5183 (define_expand "movmemsi"
5184 [(parallel [(set (match_operand:BLK 0 "general_operand")
5185 (match_operand:BLK 1 "general_operand"))
5186 (use (match_operand:SI 2 ""))
5187 (use (match_operand:SI 3 "const_int_operand"))])]
5188 "!TARGET_MIPS16 && !TARGET_MEMCPY"
5190 if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5197 ;; ....................
5201 ;; ....................
5203 (define_expand "<optab><mode>3"
5204 [(set (match_operand:GPR 0 "register_operand")
5205 (any_shift:GPR (match_operand:GPR 1 "register_operand")
5206 (match_operand:SI 2 "arith_operand")))]
5209 /* On the mips16, a shift of more than 8 is a four byte instruction,
5210 so, for a shift between 8 and 16, it is just as fast to do two
5211 shifts of 8 or less. If there is a lot of shifting going on, we
5212 may win in CSE. Otherwise combine will put the shifts back
5213 together again. This can be called by mips_function_arg, so we must
5214 be careful not to allocate a new register if we've reached the
5218 && CONST_INT_P (operands[2])
5219 && INTVAL (operands[2]) > 8
5220 && INTVAL (operands[2]) <= 16
5221 && !reload_in_progress
5222 && !reload_completed)
5224 rtx temp = gen_reg_rtx (<MODE>mode);
5226 emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5227 emit_insn (gen_<optab><mode>3 (operands[0], temp,
5228 GEN_INT (INTVAL (operands[2]) - 8)));
5233 (define_insn "*<optab><mode>3"
5234 [(set (match_operand:GPR 0 "register_operand" "=d")
5235 (any_shift:GPR (match_operand:GPR 1 "register_operand" "d")
5236 (match_operand:SI 2 "arith_operand" "dI")))]
5239 if (CONST_INT_P (operands[2]))
5240 operands[2] = GEN_INT (INTVAL (operands[2])
5241 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5243 return "<d><insn>\t%0,%1,%2";
5245 [(set_attr "type" "shift")
5246 (set_attr "mode" "<MODE>")])
5248 (define_insn "*<optab>si3_extend"
5249 [(set (match_operand:DI 0 "register_operand" "=d")
5251 (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5252 (match_operand:SI 2 "arith_operand" "dI"))))]
5253 "TARGET_64BIT && !TARGET_MIPS16"
5255 if (CONST_INT_P (operands[2]))
5256 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5258 return "<insn>\t%0,%1,%2";
5260 [(set_attr "type" "shift")
5261 (set_attr "mode" "SI")])
5263 (define_insn "*<optab>si3_mips16"
5264 [(set (match_operand:SI 0 "register_operand" "=d,d")
5265 (any_shift:SI (match_operand:SI 1 "register_operand" "0,d")
5266 (match_operand:SI 2 "arith_operand" "d,I")))]
5269 if (which_alternative == 0)
5270 return "<insn>\t%0,%2";
5272 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5273 return "<insn>\t%0,%1,%2";
5275 [(set_attr "type" "shift")
5276 (set_attr "mode" "SI")
5277 (set_attr_alternative "length"
5279 (if_then_else (match_operand 2 "m16_uimm3_b")
5283 ;; We need separate DImode MIPS16 patterns because of the irregularity
5285 (define_insn "*ashldi3_mips16"
5286 [(set (match_operand:DI 0 "register_operand" "=d,d")
5287 (ashift:DI (match_operand:DI 1 "register_operand" "0,d")
5288 (match_operand:SI 2 "arith_operand" "d,I")))]
5289 "TARGET_64BIT && TARGET_MIPS16"
5291 if (which_alternative == 0)
5292 return "dsll\t%0,%2";
5294 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5295 return "dsll\t%0,%1,%2";
5297 [(set_attr "type" "shift")
5298 (set_attr "mode" "DI")
5299 (set_attr_alternative "length"
5301 (if_then_else (match_operand 2 "m16_uimm3_b")
5305 (define_insn "*ashrdi3_mips16"
5306 [(set (match_operand:DI 0 "register_operand" "=d,d")
5307 (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
5308 (match_operand:SI 2 "arith_operand" "d,I")))]
5309 "TARGET_64BIT && TARGET_MIPS16"
5311 if (CONST_INT_P (operands[2]))
5312 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5314 return "dsra\t%0,%2";
5316 [(set_attr "type" "shift")
5317 (set_attr "mode" "DI")
5318 (set_attr_alternative "length"
5320 (if_then_else (match_operand 2 "m16_uimm3_b")
5324 (define_insn "*lshrdi3_mips16"
5325 [(set (match_operand:DI 0 "register_operand" "=d,d")
5326 (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
5327 (match_operand:SI 2 "arith_operand" "d,I")))]
5328 "TARGET_64BIT && TARGET_MIPS16"
5330 if (CONST_INT_P (operands[2]))
5331 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5333 return "dsrl\t%0,%2";
5335 [(set_attr "type" "shift")
5336 (set_attr "mode" "DI")
5337 (set_attr_alternative "length"
5339 (if_then_else (match_operand 2 "m16_uimm3_b")
5343 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5346 [(set (match_operand:GPR 0 "d_operand")
5347 (any_shift:GPR (match_operand:GPR 1 "d_operand")
5348 (match_operand:GPR 2 "const_int_operand")))]
5349 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5350 && INTVAL (operands[2]) > 8
5351 && INTVAL (operands[2]) <= 16"
5352 [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5353 (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5354 { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5356 ;; If we load a byte on the mips16 as a bitfield, the resulting
5357 ;; sequence of instructions is too complicated for combine, because it
5358 ;; involves four instructions: a load, a shift, a constant load into a
5359 ;; register, and an and (the key problem here is that the mips16 does
5360 ;; not have and immediate). We recognize a shift of a load in order
5361 ;; to make it simple enough for combine to understand.
5363 ;; The length here is the worst case: the length of the split version
5364 ;; will be more accurate.
5365 (define_insn_and_split ""
5366 [(set (match_operand:SI 0 "register_operand" "=d")
5367 (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5368 (match_operand:SI 2 "immediate_operand" "I")))]
5372 [(set (match_dup 0) (match_dup 1))
5373 (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5375 [(set_attr "type" "load")
5376 (set_attr "mode" "SI")
5377 (set_attr "length" "16")])
5379 (define_insn "rotr<mode>3"
5380 [(set (match_operand:GPR 0 "register_operand" "=d")
5381 (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5382 (match_operand:SI 2 "arith_operand" "dI")))]
5385 if (CONST_INT_P (operands[2]))
5386 gcc_assert (INTVAL (operands[2]) >= 0
5387 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
5389 return "<d>ror\t%0,%1,%2";
5391 [(set_attr "type" "shift")
5392 (set_attr "mode" "<MODE>")])
5395 ;; ....................
5397 ;; CONDITIONAL BRANCHES
5399 ;; ....................
5401 ;; Conditional branches on floating-point equality tests.
5403 (define_insn "*branch_fp"
5406 (match_operator 1 "equality_operator"
5407 [(match_operand:CC 2 "register_operand" "z")
5409 (label_ref (match_operand 0 "" ""))
5413 return mips_output_conditional_branch (insn, operands,
5414 MIPS_BRANCH ("b%F1", "%Z2%0"),
5415 MIPS_BRANCH ("b%W1", "%Z2%0"));
5417 [(set_attr "type" "branch")])
5419 (define_insn "*branch_fp_inverted"
5422 (match_operator 1 "equality_operator"
5423 [(match_operand:CC 2 "register_operand" "z")
5426 (label_ref (match_operand 0 "" ""))))]
5429 return mips_output_conditional_branch (insn, operands,
5430 MIPS_BRANCH ("b%W1", "%Z2%0"),
5431 MIPS_BRANCH ("b%F1", "%Z2%0"));
5433 [(set_attr "type" "branch")])
5435 ;; Conditional branches on ordered comparisons with zero.
5437 (define_insn "*branch_order<mode>"
5440 (match_operator 1 "order_operator"
5441 [(match_operand:GPR 2 "register_operand" "d")
5443 (label_ref (match_operand 0 "" ""))
5446 { return mips_output_order_conditional_branch (insn, operands, false); }
5447 [(set_attr "type" "branch")])
5449 (define_insn "*branch_order<mode>_inverted"
5452 (match_operator 1 "order_operator"
5453 [(match_operand:GPR 2 "register_operand" "d")
5456 (label_ref (match_operand 0 "" ""))))]
5458 { return mips_output_order_conditional_branch (insn, operands, true); }
5459 [(set_attr "type" "branch")])
5461 ;; Conditional branch on equality comparison.
5463 (define_insn "*branch_equality<mode>"
5466 (match_operator 1 "equality_operator"
5467 [(match_operand:GPR 2 "register_operand" "d")
5468 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5469 (label_ref (match_operand 0 "" ""))
5473 return mips_output_conditional_branch (insn, operands,
5474 MIPS_BRANCH ("b%C1", "%2,%z3,%0"),
5475 MIPS_BRANCH ("b%N1", "%2,%z3,%0"));
5477 [(set_attr "type" "branch")])
5479 (define_insn "*branch_equality<mode>_inverted"
5482 (match_operator 1 "equality_operator"
5483 [(match_operand:GPR 2 "register_operand" "d")
5484 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5486 (label_ref (match_operand 0 "" ""))))]
5489 return mips_output_conditional_branch (insn, operands,
5490 MIPS_BRANCH ("b%N1", "%2,%z3,%0"),
5491 MIPS_BRANCH ("b%C1", "%2,%z3,%0"));
5493 [(set_attr "type" "branch")])
5497 (define_insn "*branch_equality<mode>_mips16"
5500 (match_operator 1 "equality_operator"
5501 [(match_operand:GPR 2 "register_operand" "d,t")
5503 (label_ref (match_operand 0 "" ""))
5509 [(set_attr "type" "branch")])
5511 (define_insn "*branch_equality<mode>_mips16_inverted"
5514 (match_operator 1 "equality_operator"
5515 [(match_operand:GPR 2 "register_operand" "d,t")
5518 (label_ref (match_operand 0 "" ""))))]
5523 [(set_attr "type" "branch")])
5525 (define_expand "cbranch<mode>4"
5527 (if_then_else (match_operator 0 "comparison_operator"
5528 [(match_operand:GPR 1 "register_operand")
5529 (match_operand:GPR 2 "nonmemory_operand")])
5530 (label_ref (match_operand 3 ""))
5534 mips_expand_conditional_branch (operands);
5538 (define_expand "cbranch<mode>4"
5540 (if_then_else (match_operator 0 "comparison_operator"
5541 [(match_operand:SCALARF 1 "register_operand")
5542 (match_operand:SCALARF 2 "register_operand")])
5543 (label_ref (match_operand 3 ""))
5547 mips_expand_conditional_branch (operands);
5551 ;; Used to implement built-in functions.
5552 (define_expand "condjump"
5554 (if_then_else (match_operand 0)
5555 (label_ref (match_operand 1))
5558 ;; Branch if bit is set/clear.
5560 (define_insn "*branch_bit<bbv><mode>"
5563 (equality_op (zero_extract:GPR
5564 (match_operand:GPR 1 "register_operand" "d")
5566 (match_operand 2 "const_int_operand" ""))
5568 (label_ref (match_operand 0 ""))
5570 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5573 mips_output_conditional_branch (insn, operands,
5574 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
5575 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
5577 [(set_attr "type" "branch")
5578 (set_attr "branch_likely" "no")])
5580 (define_insn "*branch_bit<bbv><mode>_inverted"
5583 (equality_op (zero_extract:GPR
5584 (match_operand:GPR 1 "register_operand" "d")
5586 (match_operand 2 "const_int_operand" ""))
5589 (label_ref (match_operand 0 ""))))]
5590 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5593 mips_output_conditional_branch (insn, operands,
5594 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
5595 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
5597 [(set_attr "type" "branch")
5598 (set_attr "branch_likely" "no")])
5601 ;; ....................
5603 ;; SETTING A REGISTER FROM A COMPARISON
5605 ;; ....................
5607 ;; Destination is always set in SI mode.
5609 (define_expand "cstore<mode>4"
5610 [(set (match_operand:SI 0 "register_operand")
5611 (match_operator:SI 1 "mips_cstore_operator"
5612 [(match_operand:GPR 2 "register_operand")
5613 (match_operand:GPR 3 "nonmemory_operand")]))]
5616 mips_expand_scc (operands);
5620 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
5621 [(set (match_operand:GPR2 0 "register_operand" "=d")
5622 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5624 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5626 [(set_attr "type" "slt")
5627 (set_attr "mode" "<GPR:MODE>")])
5629 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
5630 [(set (match_operand:GPR2 0 "register_operand" "=t")
5631 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5633 "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5635 [(set_attr "type" "slt")
5636 (set_attr "mode" "<GPR:MODE>")])
5638 ;; Generate sltiu unless using seq results in better code.
5639 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
5640 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5641 (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5642 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5648 [(set_attr "type" "slt")
5649 (set_attr "mode" "<GPR:MODE>")])
5651 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
5652 [(set (match_operand:GPR2 0 "register_operand" "=d")
5653 (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
5655 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5657 [(set_attr "type" "slt")
5658 (set_attr "mode" "<GPR:MODE>")])
5660 ;; Generate sltu unless using sne results in better code.
5661 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
5662 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5663 (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5664 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5670 [(set_attr "type" "slt")
5671 (set_attr "mode" "<GPR:MODE>")])
5673 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
5674 [(set (match_operand:GPR2 0 "register_operand" "=d")
5675 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5676 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5679 [(set_attr "type" "slt")
5680 (set_attr "mode" "<GPR:MODE>")])
5682 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
5683 [(set (match_operand:GPR2 0 "register_operand" "=t")
5684 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5685 (match_operand:GPR 2 "register_operand" "d")))]
5688 [(set_attr "type" "slt")
5689 (set_attr "mode" "<GPR:MODE>")])
5691 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
5692 [(set (match_operand:GPR2 0 "register_operand" "=d")
5693 (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
5697 [(set_attr "type" "slt")
5698 (set_attr "mode" "<GPR:MODE>")])
5700 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
5701 [(set (match_operand:GPR2 0 "register_operand" "=d")
5702 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5703 (match_operand:GPR 2 "arith_operand" "dI")))]
5706 [(set_attr "type" "slt")
5707 (set_attr "mode" "<GPR:MODE>")])
5709 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
5710 [(set (match_operand:GPR2 0 "register_operand" "=t,t")
5711 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
5712 (match_operand:GPR 2 "arith_operand" "d,I")))]
5715 [(set_attr "type" "slt")
5716 (set_attr "mode" "<GPR:MODE>")
5717 (set_attr_alternative "length"
5719 (if_then_else (match_operand 2 "m16_uimm8_1")
5723 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
5724 [(set (match_operand:GPR2 0 "register_operand" "=d")
5725 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
5726 (match_operand:GPR 2 "sle_operand" "")))]
5729 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5730 return "slt<u>\t%0,%1,%2";
5732 [(set_attr "type" "slt")
5733 (set_attr "mode" "<GPR:MODE>")])
5735 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
5736 [(set (match_operand:GPR2 0 "register_operand" "=t")
5737 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
5738 (match_operand:GPR 2 "sle_operand" "")))]
5741 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5742 return "slt<u>\t%1,%2";
5744 [(set_attr "type" "slt")
5745 (set_attr "mode" "<GPR:MODE>")
5746 (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
5751 ;; ....................
5753 ;; FLOATING POINT COMPARISONS
5755 ;; ....................
5757 (define_insn "s<code>_<mode>"
5758 [(set (match_operand:CC 0 "register_operand" "=z")
5759 (fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5760 (match_operand:SCALARF 2 "register_operand" "f")))]
5762 "c.<fcond>.<fmt>\t%Z0%1,%2"
5763 [(set_attr "type" "fcmp")
5764 (set_attr "mode" "FPSW")])
5766 (define_insn "s<code>_<mode>"
5767 [(set (match_operand:CC 0 "register_operand" "=z")
5768 (swapped_fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5769 (match_operand:SCALARF 2 "register_operand" "f")))]
5771 "c.<swapped_fcond>.<fmt>\t%Z0%2,%1"
5772 [(set_attr "type" "fcmp")
5773 (set_attr "mode" "FPSW")])
5776 ;; ....................
5778 ;; UNCONDITIONAL BRANCHES
5780 ;; ....................
5782 ;; Unconditional branches.
5784 (define_expand "jump"
5786 (label_ref (match_operand 0)))])
5788 (define_insn "*jump_absolute"
5790 (label_ref (match_operand 0)))]
5791 "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
5792 { return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/"); }
5793 [(set_attr "type" "jump")])
5795 (define_insn "*jump_pic"
5797 (label_ref (match_operand 0)))]
5798 "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
5800 if (get_attr_length (insn) <= 8)
5801 return "%*b\t%l0%/";
5804 mips_output_load_label (operands[0]);
5805 return "%*jr\t%@%/%]";
5808 [(set_attr "type" "branch")])
5810 ;; We need a different insn for the mips16, because a mips16 branch
5811 ;; does not have a delay slot.
5813 (define_insn "*jump_mips16"
5815 (label_ref (match_operand 0 "" "")))]
5818 [(set_attr "type" "branch")
5819 (set (attr "length")
5820 ;; This calculation is like the normal branch one, but the
5821 ;; range of the unextended instruction is [-0x800, 0x7fe] rather
5822 ;; than [-0x100, 0xfe]. This translates to a range of:
5824 ;; [-(0x800 - sizeof (branch)), 0x7fe]
5825 ;; == [-0x7fe, 0x7fe]
5827 ;; from the shorten_branches reference address. Long-branch
5828 ;; sequences will replace this one, so the minimum length
5829 ;; is one instruction shorter than for conditional branches.
5830 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
5831 (le (minus (pc) (match_dup 0)) (const_int 2046)))
5833 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
5834 (le (minus (pc) (match_dup 0)) (const_int 65532)))
5836 (and (match_test "TARGET_ABICALLS")
5837 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
5839 (match_test "Pmode == SImode")
5841 ] (const_int 44)))])
5843 (define_expand "indirect_jump"
5844 [(set (pc) (match_operand 0 "register_operand"))]
5847 operands[0] = force_reg (Pmode, operands[0]);
5848 emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
5852 (define_insn "indirect_jump_<mode>"
5853 [(set (pc) (match_operand:P 0 "register_operand" "d"))]
5856 [(set_attr "type" "jump")
5857 (set_attr "mode" "none")])
5859 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
5860 ;; sequences. Having a dedicated pattern is more convenient than
5861 ;; creating a SEQUENCE for this special case.
5862 (define_insn "indirect_jump_and_restore_<mode>"
5863 [(set (pc) (match_operand:P 1 "register_operand" "d"))
5864 (set (match_operand:P 0 "register_operand" "=d")
5865 (match_operand:P 2 "register_operand" "y"))]
5867 "%(%<jr\t%1\;move\t%0,%2%>%)"
5868 [(set_attr "type" "multi")
5869 (set_attr "extended_mips16" "yes")])
5871 (define_expand "tablejump"
5873 (match_operand 0 "register_operand"))
5874 (use (label_ref (match_operand 1 "")))]
5877 if (TARGET_MIPS16_SHORT_JUMP_TABLES)
5878 operands[0] = expand_binop (Pmode, add_optab,
5879 convert_to_mode (Pmode, operands[0], false),
5880 gen_rtx_LABEL_REF (Pmode, operands[1]),
5882 else if (TARGET_GPWORD)
5883 operands[0] = expand_binop (Pmode, add_optab, operands[0],
5884 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
5885 else if (TARGET_RTP_PIC)
5887 /* When generating RTP PIC, we use case table entries that are relative
5888 to the start of the function. Add the function's address to the
5890 rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5891 operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
5892 start, 0, 0, OPTAB_WIDEN);
5895 emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
5899 (define_insn "tablejump_<mode>"
5901 (match_operand:P 0 "register_operand" "d"))
5902 (use (label_ref (match_operand 1 "" "")))]
5905 [(set_attr "type" "jump")
5906 (set_attr "mode" "none")])
5908 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
5909 ;; While it is possible to either pull it off the stack (in the
5910 ;; o32 case) or recalculate it given t9 and our target label,
5911 ;; it takes 3 or 4 insns to do so.
5913 (define_expand "builtin_setjmp_setup"
5914 [(use (match_operand 0 "register_operand"))]
5919 addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
5920 mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
5924 ;; Restore the gp that we saved above. Despite the earlier comment, it seems
5925 ;; that older code did recalculate the gp from $25. Continue to jump through
5926 ;; $25 for compatibility (we lose nothing by doing so).
5928 (define_expand "builtin_longjmp"
5929 [(use (match_operand 0 "register_operand"))]
5932 /* The elements of the buffer are, in order: */
5933 int W = GET_MODE_SIZE (Pmode);
5934 rtx fp = gen_rtx_MEM (Pmode, operands[0]);
5935 rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
5936 rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
5937 rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
5938 rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5939 /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
5940 The target is bound to be using $28 as the global pointer
5941 but the current function might not be. */
5942 rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
5944 /* This bit is similar to expand_builtin_longjmp except that it
5945 restores $gp as well. */
5946 mips_emit_move (hard_frame_pointer_rtx, fp);
5947 mips_emit_move (pv, lab);
5948 emit_stack_restore (SAVE_NONLOCAL, stack);
5949 mips_emit_move (gp, gpv);
5950 emit_use (hard_frame_pointer_rtx);
5951 emit_use (stack_pointer_rtx);
5953 emit_indirect_jump (pv);
5958 ;; ....................
5960 ;; Function prologue/epilogue
5962 ;; ....................
5965 (define_expand "prologue"
5969 mips_expand_prologue ();
5973 ;; Block any insns from being moved before this point, since the
5974 ;; profiling call to mcount can use various registers that aren't
5975 ;; saved or used to pass arguments.
5977 (define_insn "blockage"
5978 [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
5981 [(set_attr "type" "ghost")
5982 (set_attr "mode" "none")])
5984 (define_expand "epilogue"
5988 mips_expand_epilogue (false);
5992 (define_expand "sibcall_epilogue"
5996 mips_expand_epilogue (true);
6000 ;; Trivial return. Make it look like a normal return insn as that
6001 ;; allows jump optimizations to work better.
6003 (define_expand "return"
6005 "mips_can_use_return_insn ()"
6006 { mips_expand_before_return (); })
6008 (define_expand "simple_return"
6011 { mips_expand_before_return (); })
6013 (define_insn "*<optab>"
6017 [(set_attr "type" "jump")
6018 (set_attr "mode" "none")])
6022 (define_insn "<optab>_internal"
6024 (use (match_operand 0 "pmode_register_operand" ""))]
6027 [(set_attr "type" "jump")
6028 (set_attr "mode" "none")])
6030 ;; Exception return.
6031 (define_insn "mips_eret"
6033 (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6036 [(set_attr "type" "trap")
6037 (set_attr "mode" "none")])
6039 ;; Debug exception return.
6040 (define_insn "mips_deret"
6042 (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6045 [(set_attr "type" "trap")
6046 (set_attr "mode" "none")])
6048 ;; Disable interrupts.
6049 (define_insn "mips_di"
6050 [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6053 [(set_attr "type" "trap")
6054 (set_attr "mode" "none")])
6056 ;; Execution hazard barrier.
6057 (define_insn "mips_ehb"
6058 [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6061 [(set_attr "type" "trap")
6062 (set_attr "mode" "none")])
6064 ;; Read GPR from previous shadow register set.
6065 (define_insn "mips_rdpgpr"
6066 [(set (match_operand:SI 0 "register_operand" "=d")
6067 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d")]
6071 [(set_attr "type" "move")
6072 (set_attr "mode" "SI")])
6074 ;; Move involving COP0 registers.
6075 (define_insn "cop0_move"
6076 [(set (match_operand:SI 0 "register_operand" "=B,d")
6077 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6080 { return mips_output_move (operands[0], operands[1]); }
6081 [(set_attr "type" "mtc,mfc")
6082 (set_attr "mode" "SI")])
6084 ;; This is used in compiling the unwind routines.
6085 (define_expand "eh_return"
6086 [(use (match_operand 0 "general_operand"))]
6089 if (GET_MODE (operands[0]) != word_mode)
6090 operands[0] = convert_to_mode (word_mode, operands[0], 0);
6092 emit_insn (gen_eh_set_lr_di (operands[0]));
6094 emit_insn (gen_eh_set_lr_si (operands[0]));
6098 ;; Clobber the return address on the stack. We can't expand this
6099 ;; until we know where it will be put in the stack frame.
6101 (define_insn "eh_set_lr_si"
6102 [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6103 (clobber (match_scratch:SI 1 "=&d"))]
6107 (define_insn "eh_set_lr_di"
6108 [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6109 (clobber (match_scratch:DI 1 "=&d"))]
6114 [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6115 (clobber (match_scratch 1))]
6119 mips_set_return_address (operands[0], operands[1]);
6123 (define_expand "exception_receiver"
6127 /* See the comment above load_call<mode> for details. */
6128 emit_insn (gen_set_got_version ());
6130 /* If we have a call-clobbered $gp, restore it from its save slot. */
6131 if (HAVE_restore_gp_si)
6132 emit_insn (gen_restore_gp_si ());
6133 else if (HAVE_restore_gp_di)
6134 emit_insn (gen_restore_gp_di ());
6138 (define_expand "nonlocal_goto_receiver"
6142 /* See the comment above load_call<mode> for details. */
6143 emit_insn (gen_set_got_version ());
6147 ;; Restore $gp from its .cprestore stack slot. The instruction remains
6148 ;; volatile until all uses of $28 are exposed.
6149 (define_insn_and_split "restore_gp_<mode>"
6151 (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6152 (clobber (match_scratch:P 0 "=&d"))]
6153 "TARGET_CALL_CLOBBERED_GP"
6155 "&& epilogue_completed"
6158 mips_restore_gp_from_cprestore_slot (operands[0]);
6161 [(set_attr "type" "ghost")])
6163 ;; Move between $gp and its register save slot.
6164 (define_insn_and_split "move_gp<mode>"
6165 [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6166 (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6169 { return mips_must_initialize_gp_p () ? "#" : ""; }
6170 "mips_must_initialize_gp_p ()"
6173 mips_emit_move (operands[0], operands[1]);
6176 [(set_attr "type" "ghost")])
6179 ;; ....................
6183 ;; ....................
6185 ;; Instructions to load a call address from the GOT. The address might
6186 ;; point to a function or to a lazy binding stub. In the latter case,
6187 ;; the stub will use the dynamic linker to resolve the function, which
6188 ;; in turn will change the GOT entry to point to the function's real
6191 ;; This means that every call, even pure and constant ones, can
6192 ;; potentially modify the GOT entry. And once a stub has been called,
6193 ;; we must not call it again.
6195 ;; We represent this restriction using an imaginary, fixed, call-saved
6196 ;; register called GOT_VERSION_REGNUM. The idea is to make the register
6197 ;; live throughout the function and to change its value after every
6198 ;; potential call site. This stops any rtx value that uses the register
6199 ;; from being computed before an earlier call. To do this, we:
6201 ;; - Ensure that the register is live on entry to the function,
6202 ;; so that it is never thought to be used uninitalized.
6204 ;; - Ensure that the register is live on exit from the function,
6205 ;; so that it is live throughout.
6207 ;; - Make each call (lazily-bound or not) use the current value
6208 ;; of GOT_VERSION_REGNUM, so that updates of the register are
6209 ;; not moved across call boundaries.
6211 ;; - Add "ghost" definitions of the register to the beginning of
6212 ;; blocks reached by EH and ABNORMAL_CALL edges, because those
6213 ;; edges may involve calls that normal paths don't. (E.g. the
6214 ;; unwinding code that handles a non-call exception may change
6215 ;; lazily-bound GOT entries.) We do this by making the
6216 ;; exception_receiver and nonlocal_goto_receiver expanders emit
6217 ;; a set_got_version instruction.
6219 ;; - After each call (lazily-bound or not), use a "ghost"
6220 ;; update_got_version instruction to change the register's value.
6221 ;; This instruction mimics the _possible_ effect of the dynamic
6222 ;; resolver during the call and it remains live even if the call
6223 ;; itself becomes dead.
6225 ;; - Leave GOT_VERSION_REGNUM out of all register classes.
6226 ;; The register is therefore not a valid register_operand
6227 ;; and cannot be moved to or from other registers.
6229 (define_insn "load_call<mode>"
6230 [(set (match_operand:P 0 "register_operand" "=d")
6231 (unspec:P [(match_operand:P 1 "register_operand" "d")
6232 (match_operand:P 2 "immediate_operand" "")
6233 (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6235 "<load>\t%0,%R2(%1)"
6236 [(set_attr "got" "load")
6237 (set_attr "mode" "<MODE>")])
6239 (define_insn "set_got_version"
6240 [(set (reg:SI GOT_VERSION_REGNUM)
6241 (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6244 [(set_attr "type" "ghost")])
6246 (define_insn "update_got_version"
6247 [(set (reg:SI GOT_VERSION_REGNUM)
6248 (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6251 [(set_attr "type" "ghost")])
6253 ;; Sibling calls. All these patterns use jump instructions.
6255 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6256 ;; addresses if a direct jump is acceptable. Since the 'S' constraint
6257 ;; is defined in terms of call_insn_operand, the same is true of the
6260 ;; When we use an indirect jump, we need a register that will be
6261 ;; preserved by the epilogue. Since TARGET_USE_PIC_FN_ADDR_REG forces
6262 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6263 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6266 (define_expand "sibcall"
6267 [(parallel [(call (match_operand 0 "")
6268 (match_operand 1 ""))
6269 (use (match_operand 2 "")) ;; next_arg_reg
6270 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6273 mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6274 operands[1], operands[2], false);
6278 (define_insn "sibcall_internal"
6279 [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6280 (match_operand 1 "" ""))]
6281 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6282 { return MIPS_CALL ("j", operands, 0, 1); }
6283 [(set_attr "jal" "indirect,direct")
6284 (set_attr "jal_macro" "no")])
6286 (define_expand "sibcall_value"
6287 [(parallel [(set (match_operand 0 "")
6288 (call (match_operand 1 "")
6289 (match_operand 2 "")))
6290 (use (match_operand 3 ""))])] ;; next_arg_reg
6293 mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6294 operands[2], operands[3], false);
6298 (define_insn "sibcall_value_internal"
6299 [(set (match_operand 0 "register_operand" "")
6300 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6301 (match_operand 2 "" "")))]
6302 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6303 { return MIPS_CALL ("j", operands, 1, 2); }
6304 [(set_attr "jal" "indirect,direct")
6305 (set_attr "jal_macro" "no")])
6307 (define_insn "sibcall_value_multiple_internal"
6308 [(set (match_operand 0 "register_operand" "")
6309 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6310 (match_operand 2 "" "")))
6311 (set (match_operand 3 "register_operand" "")
6312 (call (mem:SI (match_dup 1))
6314 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6315 { return MIPS_CALL ("j", operands, 1, 2); }
6316 [(set_attr "jal" "indirect,direct")
6317 (set_attr "jal_macro" "no")])
6319 (define_expand "call"
6320 [(parallel [(call (match_operand 0 "")
6321 (match_operand 1 ""))
6322 (use (match_operand 2 "")) ;; next_arg_reg
6323 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6326 mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6327 operands[1], operands[2], false);
6331 ;; This instruction directly corresponds to an assembly-language "jal".
6332 ;; There are four cases:
6335 ;; Both symbolic and register destinations are OK. The pattern
6336 ;; always expands to a single mips instruction.
6338 ;; - -mabicalls/-mno-explicit-relocs:
6339 ;; Again, both symbolic and register destinations are OK.
6340 ;; The call is treated as a multi-instruction black box.
6342 ;; - -mabicalls/-mexplicit-relocs with n32 or n64:
6343 ;; Only "jal $25" is allowed. This expands to a single "jalr $25"
6346 ;; - -mabicalls/-mexplicit-relocs with o32 or o64:
6347 ;; Only "jal $25" is allowed. The call is actually two instructions:
6348 ;; "jalr $25" followed by an insn to reload $gp.
6350 ;; In the last case, we can generate the individual instructions with
6351 ;; a define_split. There are several things to be wary of:
6353 ;; - We can't expose the load of $gp before reload. If we did,
6354 ;; it might get removed as dead, but reload can introduce new
6355 ;; uses of $gp by rematerializing constants.
6357 ;; - We shouldn't restore $gp after calls that never return.
6358 ;; It isn't valid to insert instructions between a noreturn
6359 ;; call and the following barrier.
6361 ;; - The splitter deliberately changes the liveness of $gp. The unsplit
6362 ;; instruction preserves $gp and so have no effect on its liveness.
6363 ;; But once we generate the separate insns, it becomes obvious that
6364 ;; $gp is not live on entry to the call.
6366 (define_insn_and_split "call_internal"
6367 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6368 (match_operand 1 "" ""))
6369 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6371 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, 1); }
6372 "reload_completed && TARGET_SPLIT_CALLS"
6375 mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
6378 [(set_attr "jal" "indirect,direct")])
6380 (define_insn "call_split"
6381 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6382 (match_operand 1 "" ""))
6383 (clobber (reg:SI RETURN_ADDR_REGNUM))
6384 (clobber (reg:SI 28))]
6385 "TARGET_SPLIT_CALLS"
6386 { return MIPS_CALL ("jal", operands, 0, 1); }
6387 [(set_attr "jal" "indirect,direct")
6388 (set_attr "jal_macro" "no")])
6390 ;; A pattern for calls that must be made directly. It is used for
6391 ;; MIPS16 calls that the linker may need to redirect to a hard-float
6392 ;; stub; the linker relies on the call relocation type to detect when
6393 ;; such redirection is needed.
6394 (define_insn_and_split "call_internal_direct"
6395 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6398 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6400 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, -1); }
6401 "reload_completed && TARGET_SPLIT_CALLS"
6404 mips_split_call (curr_insn,
6405 gen_call_direct_split (operands[0], operands[1]));
6408 [(set_attr "jal" "direct")])
6410 (define_insn "call_direct_split"
6411 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6414 (clobber (reg:SI RETURN_ADDR_REGNUM))
6415 (clobber (reg:SI 28))]
6416 "TARGET_SPLIT_CALLS"
6417 { return MIPS_CALL ("jal", operands, 0, -1); }
6418 [(set_attr "jal" "direct")
6419 (set_attr "jal_macro" "no")])
6421 (define_expand "call_value"
6422 [(parallel [(set (match_operand 0 "")
6423 (call (match_operand 1 "")
6424 (match_operand 2 "")))
6425 (use (match_operand 3 ""))])] ;; next_arg_reg
6428 mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
6429 operands[2], operands[3], false);
6433 ;; See comment for call_internal.
6434 (define_insn_and_split "call_value_internal"
6435 [(set (match_operand 0 "register_operand" "")
6436 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6437 (match_operand 2 "" "")))
6438 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6440 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6441 "reload_completed && TARGET_SPLIT_CALLS"
6444 mips_split_call (curr_insn,
6445 gen_call_value_split (operands[0], operands[1],
6449 [(set_attr "jal" "indirect,direct")])
6451 (define_insn "call_value_split"
6452 [(set (match_operand 0 "register_operand" "")
6453 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6454 (match_operand 2 "" "")))
6455 (clobber (reg:SI RETURN_ADDR_REGNUM))
6456 (clobber (reg:SI 28))]
6457 "TARGET_SPLIT_CALLS"
6458 { return MIPS_CALL ("jal", operands, 1, 2); }
6459 [(set_attr "jal" "indirect,direct")
6460 (set_attr "jal_macro" "no")])
6462 ;; See call_internal_direct.
6463 (define_insn_and_split "call_value_internal_direct"
6464 [(set (match_operand 0 "register_operand")
6465 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6468 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6470 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, -1); }
6471 "reload_completed && TARGET_SPLIT_CALLS"
6474 mips_split_call (curr_insn,
6475 gen_call_value_direct_split (operands[0], operands[1],
6479 [(set_attr "jal" "direct")])
6481 (define_insn "call_value_direct_split"
6482 [(set (match_operand 0 "register_operand")
6483 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6486 (clobber (reg:SI RETURN_ADDR_REGNUM))
6487 (clobber (reg:SI 28))]
6488 "TARGET_SPLIT_CALLS"
6489 { return MIPS_CALL ("jal", operands, 1, -1); }
6490 [(set_attr "jal" "direct")
6491 (set_attr "jal_macro" "no")])
6493 ;; See comment for call_internal.
6494 (define_insn_and_split "call_value_multiple_internal"
6495 [(set (match_operand 0 "register_operand" "")
6496 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6497 (match_operand 2 "" "")))
6498 (set (match_operand 3 "register_operand" "")
6499 (call (mem:SI (match_dup 1))
6501 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6503 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6504 "reload_completed && TARGET_SPLIT_CALLS"
6507 mips_split_call (curr_insn,
6508 gen_call_value_multiple_split (operands[0], operands[1],
6509 operands[2], operands[3]));
6512 [(set_attr "jal" "indirect,direct")])
6514 (define_insn "call_value_multiple_split"
6515 [(set (match_operand 0 "register_operand" "")
6516 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6517 (match_operand 2 "" "")))
6518 (set (match_operand 3 "register_operand" "")
6519 (call (mem:SI (match_dup 1))
6521 (clobber (reg:SI RETURN_ADDR_REGNUM))
6522 (clobber (reg:SI 28))]
6523 "TARGET_SPLIT_CALLS"
6524 { return MIPS_CALL ("jal", operands, 1, 2); }
6525 [(set_attr "jal" "indirect,direct")
6526 (set_attr "jal_macro" "no")])
6528 ;; Call subroutine returning any type.
6530 (define_expand "untyped_call"
6531 [(parallel [(call (match_operand 0 "")
6533 (match_operand 1 "")
6534 (match_operand 2 "")])]
6539 emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
6541 for (i = 0; i < XVECLEN (operands[2], 0); i++)
6543 rtx set = XVECEXP (operands[2], 0, i);
6544 mips_emit_move (SET_DEST (set), SET_SRC (set));
6547 emit_insn (gen_blockage ());
6552 ;; ....................
6556 ;; ....................
6560 (define_insn "prefetch"
6561 [(prefetch (match_operand:QI 0 "address_operand" "p")
6562 (match_operand 1 "const_int_operand" "n")
6563 (match_operand 2 "const_int_operand" "n"))]
6564 "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
6566 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
6567 /* Loongson 2[ef] and Loongson 3a use load to $0 to perform prefetching. */
6568 return "ld\t$0,%a0";
6569 operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
6570 return "pref\t%1,%a0";
6572 [(set_attr "type" "prefetch")])
6574 (define_insn "*prefetch_indexed_<mode>"
6575 [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
6576 (match_operand:P 1 "register_operand" "d"))
6577 (match_operand 2 "const_int_operand" "n")
6578 (match_operand 3 "const_int_operand" "n"))]
6579 "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
6581 operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
6582 return "prefx\t%2,%1(%0)";
6584 [(set_attr "type" "prefetchx")])
6590 [(set_attr "type" "nop")
6591 (set_attr "mode" "none")])
6593 ;; Like nop, but commented out when outside a .set noreorder block.
6594 (define_insn "hazard_nop"
6598 if (mips_noreorder.nesting_level > 0)
6603 [(set_attr "type" "nop")])
6605 ;; MIPS4 Conditional move instructions.
6607 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
6608 [(set (match_operand:GPR 0 "register_operand" "=d,d")
6610 (match_operator:MOVECC 4 "equality_operator"
6611 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
6613 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
6614 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
6619 [(set_attr "type" "condmove")
6620 (set_attr "mode" "<GPR:MODE>")])
6622 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
6623 [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
6624 (if_then_else:SCALARF
6625 (match_operator:MOVECC 4 "equality_operator"
6626 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
6628 (match_operand:SCALARF 2 "register_operand" "f,0")
6629 (match_operand:SCALARF 3 "register_operand" "0,f")))]
6630 "ISA_HAS_FP_CONDMOVE"
6632 mov%T4.<fmt>\t%0,%2,%1
6633 mov%t4.<fmt>\t%0,%3,%1"
6634 [(set_attr "type" "condmove")
6635 (set_attr "mode" "<SCALARF:MODE>")])
6637 ;; These are the main define_expand's used to make conditional moves.
6639 (define_expand "mov<mode>cc"
6640 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6641 (set (match_operand:GPR 0 "register_operand")
6642 (if_then_else:GPR (match_dup 5)
6643 (match_operand:GPR 2 "reg_or_0_operand")
6644 (match_operand:GPR 3 "reg_or_0_operand")))]
6647 mips_expand_conditional_move (operands);
6651 (define_expand "mov<mode>cc"
6652 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6653 (set (match_operand:SCALARF 0 "register_operand")
6654 (if_then_else:SCALARF (match_dup 5)
6655 (match_operand:SCALARF 2 "register_operand")
6656 (match_operand:SCALARF 3 "register_operand")))]
6657 "ISA_HAS_FP_CONDMOVE"
6659 mips_expand_conditional_move (operands);
6664 ;; ....................
6666 ;; mips16 inline constant tables
6668 ;; ....................
6671 (define_insn "consttable_tls_reloc"
6672 [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
6673 (match_operand 1 "const_int_operand" "")]
6674 UNSPEC_CONSTTABLE_INT)]
6675 "TARGET_MIPS16_PCREL_LOADS"
6676 { return mips_output_tls_reloc_directive (&operands[0]); }
6677 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
6679 (define_insn "consttable_int"
6680 [(unspec_volatile [(match_operand 0 "consttable_operand" "")
6681 (match_operand 1 "const_int_operand" "")]
6682 UNSPEC_CONSTTABLE_INT)]
6685 assemble_integer (mips_strip_unspec_address (operands[0]),
6686 INTVAL (operands[1]),
6687 BITS_PER_UNIT * INTVAL (operands[1]), 1);
6690 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
6692 (define_insn "consttable_float"
6693 [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
6694 UNSPEC_CONSTTABLE_FLOAT)]
6699 gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
6700 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
6701 assemble_real (d, GET_MODE (operands[0]),
6702 GET_MODE_BITSIZE (GET_MODE (operands[0])));
6705 [(set (attr "length")
6706 (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
6708 (define_insn "align"
6709 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
6712 [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
6715 [(match_operand 0 "small_data_pattern")]
6718 { operands[0] = mips_rewrite_small_data (operands[0]); })
6721 ;; ....................
6723 ;; MIPS16e Save/Restore
6725 ;; ....................
6728 (define_insn "*mips16e_save_restore"
6729 [(match_parallel 0 ""
6730 [(set (match_operand:SI 1 "register_operand")
6731 (plus:SI (match_dup 1)
6732 (match_operand:SI 2 "const_int_operand")))])]
6733 "operands[1] == stack_pointer_rtx
6734 && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
6735 { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
6736 [(set_attr "type" "arith")
6737 (set_attr "extended_mips16" "yes")])
6739 ;; Thread-Local Storage
6741 ;; The TLS base pointer is accessed via "rdhwr $3, $29". No current
6742 ;; MIPS architecture defines this register, and no current
6743 ;; implementation provides it; instead, any OS which supports TLS is
6744 ;; expected to trap and emulate this instruction. rdhwr is part of the
6745 ;; MIPS 32r2 specification, but we use it on any architecture because
6746 ;; we expect it to be emulated. Use .set to force the assembler to
6749 ;; We do not use a constraint to force the destination to be $3
6750 ;; because $3 can appear explicitly as a function return value.
6751 ;; If we leave the use of $3 implicit in the constraints until
6752 ;; reload, we may end up making a $3 return value live across
6753 ;; the instruction, leading to a spill failure when reloading it.
6754 (define_insn_and_split "tls_get_tp_<mode>"
6755 [(set (match_operand:P 0 "register_operand" "=d")
6756 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
6757 (clobber (reg:P TLS_GET_TP_REGNUM))]
6758 "HAVE_AS_TLS && !TARGET_MIPS16"
6760 "&& reload_completed"
6761 [(set (reg:P TLS_GET_TP_REGNUM)
6762 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
6763 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
6765 [(set_attr "type" "unknown")
6766 ; Since rdhwr always generates a trap for now, putting it in a delay
6767 ; slot would make the kernel's emulation of it much slower.
6768 (set_attr "can_delay" "no")
6769 (set_attr "mode" "<MODE>")
6770 (set_attr "length" "8")])
6772 (define_insn "*tls_get_tp_<mode>_split"
6773 [(set (reg:P TLS_GET_TP_REGNUM)
6774 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
6775 "HAVE_AS_TLS && !TARGET_MIPS16"
6776 ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop"
6777 [(set_attr "type" "unknown")
6778 ; See tls_get_tp_<mode>
6779 (set_attr "can_delay" "no")
6780 (set_attr "mode" "<MODE>")])
6782 ;; In MIPS16 mode, the TLS base pointer is accessed by a
6783 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
6784 ;; accessible in MIPS16.
6786 ;; This is not represented as a call insn, to avoid the
6787 ;; unnecesarry clobbering of caller-save registers by a
6788 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
6790 ;; A $25 clobber is added to cater for a $25 load stub added by the
6791 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
6793 (define_insn_and_split "tls_get_tp_mips16_<mode>"
6794 [(set (match_operand:P 0 "register_operand" "=d")
6795 (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
6797 (clobber (reg:P TLS_GET_TP_REGNUM))
6798 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
6799 (clobber (reg:P RETURN_ADDR_REGNUM))]
6800 "HAVE_AS_TLS && TARGET_MIPS16"
6802 "&& reload_completed"
6803 [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
6804 (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
6805 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
6806 (clobber (reg:P RETURN_ADDR_REGNUM))])
6807 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
6809 [(set_attr "type" "multi")
6810 (set_attr "length" "16")
6811 (set_attr "mode" "<MODE>")])
6813 (define_insn "*tls_get_tp_mips16_call_<mode>"
6814 [(set (reg:P TLS_GET_TP_REGNUM)
6815 (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
6817 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
6818 (clobber (reg:P RETURN_ADDR_REGNUM))]
6819 "HAVE_AS_TLS && TARGET_MIPS16"
6820 { return MIPS_CALL ("jal", operands, 0, -1); }
6821 [(set_attr "type" "call")
6822 (set_attr "length" "12")
6823 (set_attr "mode" "<MODE>")])
6825 ;; Synchronization instructions.
6829 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
6831 (include "mips-ps-3d.md")
6833 ; The MIPS DSP Instructions.
6835 (include "mips-dsp.md")
6837 ; The MIPS DSP REV 2 Instructions.
6839 (include "mips-dspr2.md")
6841 ; MIPS fixed-point instructions.
6842 (include "mips-fixed.md")
6844 ; ST-Microelectronics Loongson-2E/2F-specific patterns.
6845 (include "loongson.md")
6847 (define_c_enum "unspec" [
6848 UNSPEC_ADDRESS_FIRST