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
4 ;; Free Software Foundation, Inc.
5 ;; Contributed by A. Lichnewsky, lich@inria.inria.fr
6 ;; Changes by Michael Meissner, meissner@osf.org
7 ;; 64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
8 ;; Brendan Eich, brendan@microunity.com.
10 ;; This file is part of GCC.
12 ;; GCC is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GCC is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GCC; see the file COPYING3. If not see
24 ;; <http://www.gnu.org/licenses/>.
26 (define_enum "processor" [
68 (define_c_enum "unspec" [
69 ;; Unaligned accesses.
75 ;; Floating-point moves.
91 UNSPEC_POTENTIAL_CPRESTORE
96 UNSPEC_SET_GOT_VERSION
97 UNSPEC_UPDATE_GOT_VERSION
105 ;; MIPS16 constant pools.
107 UNSPEC_CONSTTABLE_INT
108 UNSPEC_CONSTTABLE_FLOAT
110 ;; Blockage and synchronisation.
117 ;; Cache manipulation.
119 UNSPEC_R10K_CACHE_BARRIER
121 ;; Interrupt handling.
129 ;; Used in a call expression in place of args_size. It's present for PIC
130 ;; indirect calls where it contains args_size and the function symbol.
135 [(TLS_GET_TP_REGNUM 3)
136 (RETURN_ADDR_REGNUM 31)
137 (CPRESTORE_SLOT_REGNUM 76)
138 (GOT_VERSION_REGNUM 79)
140 ;; PIC long branch sequences are never longer than 100 bytes.
141 (MAX_PIC_BRANCH_LENGTH 100)
145 (include "predicates.md")
146 (include "constraints.md")
148 ;; ....................
152 ;; ....................
154 (define_attr "got" "unset,xgot_high,load"
155 (const_string "unset"))
157 ;; For jal instructions, this attribute is DIRECT when the target address
158 ;; is symbolic and INDIRECT when it is a register.
159 (define_attr "jal" "unset,direct,indirect"
160 (const_string "unset"))
162 ;; This attribute is YES if the instruction is a jal macro (not a
163 ;; real jal instruction).
165 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
166 ;; an instruction to restore $gp. Direct jals are also macros for
167 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
169 (define_attr "jal_macro" "no,yes"
170 (cond [(eq_attr "jal" "direct")
171 (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
172 ? JAL_MACRO_YES : JAL_MACRO_NO)")
173 (eq_attr "jal" "indirect")
174 (symbol_ref "(TARGET_CALL_CLOBBERED_GP
175 ? JAL_MACRO_YES : JAL_MACRO_NO)")]
176 (const_string "no")))
178 ;; Classification of moves, extensions and truncations. Most values
179 ;; are as for "type" (see below) but there are also the following
180 ;; move-specific values:
182 ;; constN move an N-constraint integer into a MIPS16 register
183 ;; sll0 "sll DEST,SRC,0", which on 64-bit targets is guaranteed
184 ;; to produce a sign-extended DEST, even if SRC is not
185 ;; properly sign-extended
186 ;; ext_ins EXT, DEXT, INS or DINS instruction
187 ;; andi a single ANDI instruction
188 ;; loadpool move a constant into a MIPS16 register by loading it
190 ;; shift_shift a shift left followed by a shift right
191 ;; lui_movf an LUI followed by a MOVF (for d<-z CC moves)
193 ;; This attribute is used to determine the instruction's length and
194 ;; scheduling type. For doubleword moves, the attribute always describes
195 ;; the split instructions; in some cases, it is more appropriate for the
196 ;; scheduling type to be "multi" instead.
197 (define_attr "move_type"
198 "unknown,load,fpload,store,fpstore,mtc,mfc,mthilo,mfhilo,move,fmove,
199 const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
200 shift_shift,lui_movf"
201 (const_string "unknown"))
203 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor"
204 (const_string "unknown"))
206 ;; Main data type used by the insn
207 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW"
208 (const_string "unknown"))
210 ;; True if the main data type is twice the size of a word.
211 (define_attr "dword_mode" "no,yes"
212 (cond [(and (eq_attr "mode" "DI,DF")
213 (not (match_test "TARGET_64BIT")))
216 (and (eq_attr "mode" "TI,TF")
217 (match_test "TARGET_64BIT"))
218 (const_string "yes")]
219 (const_string "no")))
221 ;; Classification of each insn.
222 ;; branch conditional branch
223 ;; jump unconditional jump
224 ;; call unconditional call
225 ;; load load instruction(s)
226 ;; fpload floating point load
227 ;; fpidxload floating point indexed load
228 ;; store store instruction(s)
229 ;; fpstore floating point store
230 ;; fpidxstore floating point indexed store
231 ;; prefetch memory prefetch (register + offset)
232 ;; prefetchx memory indexed prefetch (register + register)
233 ;; condmove conditional moves
234 ;; mtc transfer to coprocessor
235 ;; mfc transfer from coprocessor
236 ;; mthilo transfer to hi/lo registers
237 ;; mfhilo transfer from hi/lo registers
238 ;; const load constant
239 ;; arith integer arithmetic instructions
240 ;; logical integer logical instructions
241 ;; shift integer shift instructions
242 ;; slt set less than instructions
243 ;; signext sign extend instructions
244 ;; clz the clz and clo instructions
245 ;; pop the pop instruction
246 ;; trap trap if instructions
247 ;; imul integer multiply 2 operands
248 ;; imul3 integer multiply 3 operands
249 ;; imul3nc integer multiply 3 operands without clobbering HI/LO
250 ;; imadd integer multiply-add
251 ;; idiv integer divide 2 operands
252 ;; idiv3 integer divide 3 operands
253 ;; move integer register move ({,D}ADD{,U} with rt = 0)
254 ;; fmove floating point register move
255 ;; fadd floating point add/subtract
256 ;; fmul floating point multiply
257 ;; fmadd floating point multiply-add
258 ;; fdiv floating point divide
259 ;; frdiv floating point reciprocal divide
260 ;; frdiv1 floating point reciprocal divide step 1
261 ;; frdiv2 floating point reciprocal divide step 2
262 ;; fabs floating point absolute value
263 ;; fneg floating point negation
264 ;; fcmp floating point compare
265 ;; fcvt floating point convert
266 ;; fsqrt floating point square root
267 ;; frsqrt floating point reciprocal square root
268 ;; frsqrt1 floating point reciprocal square root step1
269 ;; frsqrt2 floating point reciprocal square root step2
270 ;; multi multiword sequence (or user asm statements)
272 ;; ghost an instruction that produces no real code
274 "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
275 prefetch,prefetchx,condmove,mtc,mfc,mthilo,mfhilo,const,arith,logical,
276 shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
277 fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
278 frsqrt,frsqrt1,frsqrt2,multi,nop,ghost"
279 (cond [(eq_attr "jal" "!unset") (const_string "call")
280 (eq_attr "got" "load") (const_string "load")
282 (eq_attr "alu_type" "add,sub") (const_string "arith")
284 (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
286 ;; If a doubleword move uses these expensive instructions,
287 ;; it is usually better to schedule them in the same way
288 ;; as the singleword form, rather than as "multi".
289 (eq_attr "move_type" "load") (const_string "load")
290 (eq_attr "move_type" "fpload") (const_string "fpload")
291 (eq_attr "move_type" "store") (const_string "store")
292 (eq_attr "move_type" "fpstore") (const_string "fpstore")
293 (eq_attr "move_type" "mtc") (const_string "mtc")
294 (eq_attr "move_type" "mfc") (const_string "mfc")
295 (eq_attr "move_type" "mthilo") (const_string "mthilo")
296 (eq_attr "move_type" "mfhilo") (const_string "mfhilo")
298 ;; These types of move are always single insns.
299 (eq_attr "move_type" "fmove") (const_string "fmove")
300 (eq_attr "move_type" "loadpool") (const_string "load")
301 (eq_attr "move_type" "signext") (const_string "signext")
302 (eq_attr "move_type" "ext_ins") (const_string "arith")
303 (eq_attr "move_type" "arith") (const_string "arith")
304 (eq_attr "move_type" "logical") (const_string "logical")
305 (eq_attr "move_type" "sll0") (const_string "shift")
306 (eq_attr "move_type" "andi") (const_string "logical")
308 ;; These types of move are always split.
309 (eq_attr "move_type" "constN,shift_shift")
310 (const_string "multi")
312 ;; These types of move are split for doubleword modes only.
313 (and (eq_attr "move_type" "move,const")
314 (eq_attr "dword_mode" "yes"))
315 (const_string "multi")
316 (eq_attr "move_type" "move") (const_string "move")
317 (eq_attr "move_type" "const") (const_string "const")]
318 ;; We classify "lui_movf" as "unknown" rather than "multi"
319 ;; because we don't split it. FIXME: we should split instead.
320 (const_string "unknown")))
322 ;; Mode for conversion types (fcvt)
323 ;; I2S integer to float single (SI/DI to SF)
324 ;; I2D integer to float double (SI/DI to DF)
325 ;; S2I float to integer (SF to SI/DI)
326 ;; D2I float to integer (DF to SI/DI)
327 ;; D2S double to float single
328 ;; S2D float single to double
330 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D"
331 (const_string "unknown"))
333 ;; Is this an extended instruction in mips16 mode?
334 (define_attr "extended_mips16" "no,yes"
335 (if_then_else (ior (eq_attr "move_type" "sll0")
336 (eq_attr "type" "branch")
337 (eq_attr "jal" "direct"))
339 (const_string "no")))
341 ;; Attributes describing a sync loop. These loops have the form:
343 ;; if (RELEASE_BARRIER == YES) sync
345 ;; if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
346 ;; $TMP1 = OLDVAL & EXCLUSIVE_MASK
347 ;; $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
348 ;; $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
349 ;; $AT |= $TMP1 | $TMP3
350 ;; if (!commit (*MEM = $AT)) goto 1.
351 ;; if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
355 ;; where "$" values are temporaries and where the other values are
356 ;; specified by the attributes below. Values are specified as operand
357 ;; numbers and insns are specified as enums. If no operand number is
358 ;; specified, the following values are used instead:
362 ;; - INCLUSIVE_MASK: -1
363 ;; - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
364 ;; - EXCLUSIVE_MASK: 0
366 ;; MEM and INSN1_OP2 are required.
368 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
369 ;; but the gen* programs don't yet support that.
370 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
371 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
372 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
373 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
374 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
375 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
376 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
377 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
378 (const_string "move"))
379 (define_attr "sync_insn2" "nop,and,xor,not"
380 (const_string "nop"))
381 (define_attr "sync_release_barrier" "yes,no"
382 (const_string "yes"))
384 ;; Length of instruction in bytes.
385 (define_attr "length" ""
386 (cond [(and (eq_attr "extended_mips16" "yes")
387 (match_test "TARGET_MIPS16"))
390 ;; Direct branch instructions have a range of [-0x20000,0x1fffc],
391 ;; relative to the address of the delay slot. If a branch is
392 ;; outside this range, we have a choice of two sequences.
393 ;; For PIC, an out-of-range branch like:
398 ;; becomes the equivalent of:
407 ;; The non-PIC case is similar except that we use a direct
408 ;; jump instead of an la/jr pair. Since the target of this
409 ;; jump is an absolute 28-bit bit address (the other bits
410 ;; coming from the address of the delay slot) this form cannot
411 ;; cross a 256MB boundary. We could provide the option of
412 ;; using la/jr in this case too, but we do not do so at
415 ;; Note that this value does not account for the delay slot
416 ;; instruction, whose length is added separately. If the RTL
417 ;; pattern has no explicit delay slot, mips_adjust_insn_length
418 ;; will add the length of the implicit nop. The values for
419 ;; forward and backward branches will be different as well.
420 (eq_attr "type" "branch")
421 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 131064))
422 (le (minus (pc) (match_dup 0)) (const_int 131068)))
425 ;; The non-PIC case: branch, first delay slot, and J.
426 (match_test "TARGET_ABSOLUTE_JUMPS")
429 ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
430 ;; mips_adjust_insn_length substitutes the correct length.
432 ;; Note that we can't simply use (symbol_ref ...) here
433 ;; because genattrtab needs to know the maximum length
435 (const_int MAX_PIC_BRANCH_LENGTH))
437 ;; "Ghost" instructions occupy no space.
438 (eq_attr "type" "ghost")
441 (eq_attr "got" "load")
442 (if_then_else (match_test "TARGET_MIPS16")
445 (eq_attr "got" "xgot_high")
448 ;; In general, constant-pool loads are extended instructions.
449 (eq_attr "move_type" "loadpool")
452 ;; LUI_MOVFs are decomposed into two separate instructions.
453 (eq_attr "move_type" "lui_movf")
456 ;; SHIFT_SHIFTs are decomposed into two separate instructions.
457 ;; They are extended instructions on MIPS16 targets.
458 (eq_attr "move_type" "shift_shift")
459 (if_then_else (match_test "TARGET_MIPS16")
463 ;; Check for doubleword moves that are decomposed into two
465 (and (eq_attr "move_type" "mtc,mfc,mthilo,mfhilo,move")
466 (eq_attr "dword_mode" "yes"))
469 ;; Doubleword CONST{,N} moves are split into two word
471 (and (eq_attr "move_type" "const,constN")
472 (eq_attr "dword_mode" "yes"))
473 (symbol_ref "mips_split_const_insns (operands[1]) * 4")
475 ;; Otherwise, constants, loads and stores are handled by external
477 (eq_attr "move_type" "const,constN")
478 (symbol_ref "mips_const_insns (operands[1]) * 4")
479 (eq_attr "move_type" "load,fpload")
480 (symbol_ref "mips_load_store_insns (operands[1], insn) * 4")
481 (eq_attr "move_type" "store,fpstore")
482 (cond [(not (match_test "TARGET_FIX_24K"))
483 (symbol_ref "mips_load_store_insns (operands[0], insn) * 4")]
484 (symbol_ref "mips_load_store_insns (operands[0], insn) * 4 + 4"))
486 ;; In the worst case, a call macro will take 8 instructions:
488 ;; lui $25,%call_hi(FOO)
490 ;; lw $25,%call_lo(FOO)($25)
496 (eq_attr "jal_macro" "yes")
499 ;; Various VR4120 errata require a nop to be inserted after a macc
500 ;; instruction. The assembler does this for us, so account for
501 ;; the worst-case length here.
502 (and (eq_attr "type" "imadd")
503 (match_test "TARGET_FIX_VR4120"))
506 ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
507 ;; the result of the second one is missed. The assembler should work
508 ;; around this by inserting a nop after the first dmult.
509 (and (eq_attr "type" "imul,imul3")
510 (and (eq_attr "mode" "DI")
511 (match_test "TARGET_FIX_VR4120")))
514 (eq_attr "type" "idiv,idiv3")
515 (symbol_ref "mips_idiv_insns () * 4")
517 (not (eq_attr "sync_mem" "none"))
518 (symbol_ref "mips_sync_loop_insns (insn, operands) * 4")
521 ;; Attribute describing the processor.
522 (define_enum_attr "cpu" "processor"
523 (const (symbol_ref "mips_tune")))
525 ;; The type of hardware hazard associated with this instruction.
526 ;; DELAY means that the next instruction cannot read the result
527 ;; of this one. HILO means that the next two instructions cannot
528 ;; write to HI or LO.
529 (define_attr "hazard" "none,delay,hilo"
530 (cond [(and (eq_attr "type" "load,fpload,fpidxload")
531 (match_test "ISA_HAS_LOAD_DELAY"))
532 (const_string "delay")
534 (and (eq_attr "type" "mfc,mtc")
535 (match_test "ISA_HAS_XFER_DELAY"))
536 (const_string "delay")
538 (and (eq_attr "type" "fcmp")
539 (match_test "ISA_HAS_FCMP_DELAY"))
540 (const_string "delay")
542 ;; The r4000 multiplication patterns include an mflo instruction.
543 (and (eq_attr "type" "imul")
544 (match_test "TARGET_FIX_R4000"))
545 (const_string "hilo")
547 (and (eq_attr "type" "mfhilo")
548 (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
549 (const_string "hilo")]
550 (const_string "none")))
552 ;; Is it a single instruction?
553 (define_attr "single_insn" "no,yes"
554 (symbol_ref "(get_attr_length (insn) == (TARGET_MIPS16 ? 2 : 4)
555 ? SINGLE_INSN_YES : SINGLE_INSN_NO)"))
557 ;; Can the instruction be put into a delay slot?
558 (define_attr "can_delay" "no,yes"
559 (if_then_else (and (eq_attr "type" "!branch,call,jump")
560 (and (eq_attr "hazard" "none")
561 (eq_attr "single_insn" "yes")))
563 (const_string "no")))
565 ;; Attribute defining whether or not we can use the branch-likely
567 (define_attr "branch_likely" "no,yes"
568 (if_then_else (match_test "GENERATE_BRANCHLIKELY")
570 (const_string "no")))
572 ;; True if an instruction might assign to hi or lo when reloaded.
573 ;; This is used by the TUNE_MACC_CHAINS code.
574 (define_attr "may_clobber_hilo" "no,yes"
575 (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthilo")
577 (const_string "no")))
579 ;; Describe a user's asm statement.
580 (define_asm_attributes
581 [(set_attr "type" "multi")
582 (set_attr "can_delay" "no")])
584 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
585 ;; from the same template.
586 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
588 ;; A copy of GPR that can be used when a pattern has two independent
590 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
592 ;; This mode iterator allows :HILO to be used as the mode of the
593 ;; concatenated HI and LO registers.
594 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
596 ;; This mode iterator allows :P to be used for patterns that operate on
597 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
598 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
600 ;; This mode iterator allows :MOVECC to be used anywhere that a
601 ;; conditional-move-type condition is needed.
602 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
603 (CC "TARGET_HARD_FLOAT && !TARGET_LOONGSON_2EF")])
605 ;; 32-bit integer moves for which we provide move patterns.
606 (define_mode_iterator IMOVE32
615 (V4UQQ "TARGET_DSP")])
617 ;; 64-bit modes for which we provide move patterns.
618 (define_mode_iterator MOVE64
620 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
621 (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
622 (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
623 (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")])
625 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
626 (define_mode_iterator MOVE128 [TI TF])
628 ;; This mode iterator allows the QI and HI extension patterns to be
629 ;; defined from the same template.
630 (define_mode_iterator SHORT [QI HI])
632 ;; Likewise the 64-bit truncate-and-shift patterns.
633 (define_mode_iterator SUBDI [QI HI SI])
635 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
636 ;; floating-point mode is allowed.
637 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
638 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
639 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
641 ;; Like ANYF, but only applies to scalar modes.
642 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
643 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
645 ;; A floating-point mode for which moves involving FPRs may need to be split.
646 (define_mode_iterator SPLITF
647 [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
648 (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
649 (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
650 (V2SI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
651 (V4HI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
652 (V8QI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
653 (TF "TARGET_64BIT && TARGET_FLOAT64")])
655 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
656 ;; 32-bit version and "dsubu" in the 64-bit version.
657 (define_mode_attr d [(SI "") (DI "d")
658 (QQ "") (HQ "") (SQ "") (DQ "d")
659 (UQQ "") (UHQ "") (USQ "") (UDQ "d")
660 (HA "") (SA "") (DA "d")
661 (UHA "") (USA "") (UDA "d")])
663 ;; Same as d but upper-case.
664 (define_mode_attr D [(SI "") (DI "D")
665 (QQ "") (HQ "") (SQ "") (DQ "D")
666 (UQQ "") (UHQ "") (USQ "") (UDQ "D")
667 (HA "") (SA "") (DA "D")
668 (UHA "") (USA "") (UDA "D")])
670 ;; This attribute gives the length suffix for a sign- or zero-extension
672 (define_mode_attr size [(QI "b") (HI "h")])
674 ;; This attributes gives the mode mask of a SHORT.
675 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
677 ;; Mode attributes for GPR loads.
678 (define_mode_attr load [(SI "lw") (DI "ld")])
679 ;; Instruction names for stores.
680 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
682 ;; Similarly for MIPS IV indexed FPR loads and stores.
683 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
684 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
686 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
687 ;; are different. Some forms of unextended addiu have an 8-bit immediate
688 ;; field but the equivalent daddiu has only a 5-bit field.
689 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
691 ;; This attribute gives the best constraint to use for registers of
693 (define_mode_attr reg [(SI "d") (DI "d") (CC "z")])
695 ;; This attribute gives the format suffix for floating-point operations.
696 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
698 ;; This attribute gives the upper-case mode name for one unit of a
699 ;; floating-point mode.
700 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
702 ;; This attribute gives the integer mode that has the same size as a
704 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
705 (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
706 (HA "HI") (SA "SI") (DA "DI")
707 (UHA "HI") (USA "SI") (UDA "DI")
708 (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
709 (V2HQ "SI") (V2HA "SI")])
711 ;; This attribute gives the integer mode that has half the size of
712 ;; the controlling mode.
713 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
714 (V2SI "SI") (V4HI "SI") (V8QI "SI")
717 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
719 ;; In certain cases, div.s and div.ps may have a rounding error
720 ;; and/or wrong inexact flag.
722 ;; Therefore, we only allow div.s if not working around SB-1 rev2
723 ;; errata or if a slight loss of precision is OK.
724 (define_mode_attr divide_condition
725 [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
726 (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
728 ;; This attribute gives the conditions under which SQRT.fmt instructions
730 (define_mode_attr sqrt_condition
731 [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
733 ;; This attribute gives the conditions under which RECIP.fmt and RSQRT.fmt
734 ;; instructions can be used. The MIPS32 and MIPS64 ISAs say that RECIP.D
735 ;; and RSQRT.D are unpredictable when doubles are stored in pairs of FPRs,
736 ;; so for safety's sake, we apply this restriction to all targets.
737 (define_mode_attr recip_condition
739 (DF "ISA_HAS_FP4 && TARGET_FLOAT64")
740 (V2SF "TARGET_SB1")])
742 ;; This code iterator allows signed and unsigned widening multiplications
743 ;; to use the same template.
744 (define_code_iterator any_extend [sign_extend zero_extend])
746 ;; This code iterator allows the two right shift instructions to be
747 ;; generated from the same template.
748 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
750 ;; This code iterator allows the three shift instructions to be generated
751 ;; from the same template.
752 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
754 ;; This code iterator allows unsigned and signed division to be generated
755 ;; from the same template.
756 (define_code_iterator any_div [div udiv])
758 ;; This code iterator allows unsigned and signed modulus to be generated
759 ;; from the same template.
760 (define_code_iterator any_mod [mod umod])
762 ;; This code iterator allows all native floating-point comparisons to be
763 ;; generated from the same template.
764 (define_code_iterator fcond [unordered uneq unlt unle eq lt le])
766 ;; This code iterator is used for comparisons that can be implemented
767 ;; by swapping the operands.
768 (define_code_iterator swapped_fcond [ge gt unge ungt])
770 ;; Equality operators.
771 (define_code_iterator equality_op [eq ne])
773 ;; These code iterators allow the signed and unsigned scc operations to use
774 ;; the same template.
775 (define_code_iterator any_gt [gt gtu])
776 (define_code_iterator any_ge [ge geu])
777 (define_code_iterator any_lt [lt ltu])
778 (define_code_iterator any_le [le leu])
780 (define_code_iterator any_return [return simple_return])
782 ;; <u> expands to an empty string when doing a signed operation and
783 ;; "u" when doing an unsigned operation.
784 (define_code_attr u [(sign_extend "") (zero_extend "u")
792 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
793 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
795 ;; <optab> expands to the name of the optab for a particular code.
796 (define_code_attr optab [(ashift "ashl")
805 (simple_return "simple_return")])
807 ;; <insn> expands to the name of the insn that implements a particular code.
808 (define_code_attr insn [(ashift "sll")
817 ;; <immediate_insn> expands to the name of the insn that implements
818 ;; a particular code to operate on immediate values.
819 (define_code_attr immediate_insn [(ior "ori")
823 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
824 (define_code_attr fcond [(unordered "un")
832 ;; Similar, but for swapped conditions.
833 (define_code_attr swapped_fcond [(ge "le")
838 ;; The value of the bit when the branch is taken for branch_bit patterns.
839 ;; Comparison is always against zero so this depends on the operator.
840 (define_code_attr bbv [(eq "0") (ne "1")])
842 ;; This is the inverse value of bbv.
843 (define_code_attr bbinv [(eq "1") (ne "0")])
845 ;; .........................
847 ;; Branch, call and jump delay slots
849 ;; .........................
851 (define_delay (and (eq_attr "type" "branch")
852 (not (match_test "TARGET_MIPS16"))
853 (eq_attr "branch_likely" "yes"))
854 [(eq_attr "can_delay" "yes")
856 (eq_attr "can_delay" "yes")])
858 ;; Branches that don't have likely variants do not annul on false.
859 (define_delay (and (eq_attr "type" "branch")
860 (not (match_test "TARGET_MIPS16"))
861 (eq_attr "branch_likely" "no"))
862 [(eq_attr "can_delay" "yes")
866 (define_delay (eq_attr "type" "jump")
867 [(eq_attr "can_delay" "yes")
871 (define_delay (and (eq_attr "type" "call")
872 (eq_attr "jal_macro" "no"))
873 [(eq_attr "can_delay" "yes")
877 ;; Pipeline descriptions.
879 ;; generic.md provides a fallback for processors without a specific
880 ;; pipeline description. It is derived from the old define_function_unit
881 ;; version and uses the "alu" and "imuldiv" units declared below.
883 ;; Some of the processor-specific files are also derived from old
884 ;; define_function_unit descriptions and simply override the parts of
885 ;; generic.md that don't apply. The other processor-specific files
886 ;; are self-contained.
887 (define_automaton "alu,imuldiv")
889 (define_cpu_unit "alu" "alu")
890 (define_cpu_unit "imuldiv" "imuldiv")
892 ;; Ghost instructions produce no real code and introduce no hazards.
893 ;; They exist purely to express an effect on dataflow.
894 (define_insn_reservation "ghost" 0
895 (eq_attr "type" "ghost")
916 (include "loongson2ef.md")
917 (include "loongson3a.md")
918 (include "octeon.md")
922 (include "generic.md")
925 ;; ....................
929 ;; ....................
933 [(trap_if (const_int 1) (const_int 0))]
936 if (ISA_HAS_COND_TRAP)
938 else if (TARGET_MIPS16)
943 [(set_attr "type" "trap")])
945 (define_expand "ctrap<mode>4"
946 [(trap_if (match_operator 0 "comparison_operator"
947 [(match_operand:GPR 1 "reg_or_0_operand")
948 (match_operand:GPR 2 "arith_operand")])
949 (match_operand 3 "const_0_operand"))]
952 mips_expand_conditional_trap (operands[0]);
956 (define_insn "*conditional_trap<mode>"
957 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
958 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
959 (match_operand:GPR 2 "arith_operand" "dI")])
963 [(set_attr "type" "trap")])
966 ;; ....................
970 ;; ....................
973 (define_insn "add<mode>3"
974 [(set (match_operand:ANYF 0 "register_operand" "=f")
975 (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
976 (match_operand:ANYF 2 "register_operand" "f")))]
978 "add.<fmt>\t%0,%1,%2"
979 [(set_attr "type" "fadd")
980 (set_attr "mode" "<UNITMODE>")])
982 (define_expand "add<mode>3"
983 [(set (match_operand:GPR 0 "register_operand")
984 (plus:GPR (match_operand:GPR 1 "register_operand")
985 (match_operand:GPR 2 "arith_operand")))]
988 (define_insn "*add<mode>3"
989 [(set (match_operand:GPR 0 "register_operand" "=d,d")
990 (plus:GPR (match_operand:GPR 1 "register_operand" "d,d")
991 (match_operand:GPR 2 "arith_operand" "d,Q")))]
996 [(set_attr "alu_type" "add")
997 (set_attr "mode" "<MODE>")])
999 (define_insn "*add<mode>3_mips16"
1000 [(set (match_operand:GPR 0 "register_operand" "=ks,d,d,d,d")
1001 (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,0,d,d")
1002 (match_operand:GPR 2 "arith_operand" "Q,Q,Q,O,d")))]
1010 [(set_attr "alu_type" "add")
1011 (set_attr "mode" "<MODE>")
1012 (set_attr_alternative "length"
1013 [(if_then_else (match_operand 2 "m16_simm8_8")
1016 (if_then_else (match_operand 2 "m16_uimm<si8_di5>_4")
1019 (if_then_else (match_operand 2 "m16_simm<si8_di5>_1")
1022 (if_then_else (match_operand 2 "m16_simm4_1")
1027 ;; On the mips16, we can sometimes split an add of a constant which is
1028 ;; a 4 byte instruction into two adds which are both 2 byte
1029 ;; instructions. There are two cases: one where we are adding a
1030 ;; constant plus a register to another register, and one where we are
1031 ;; simply adding a constant to a register.
1034 [(set (match_operand:SI 0 "d_operand")
1035 (plus:SI (match_dup 0)
1036 (match_operand:SI 1 "const_int_operand")))]
1037 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1038 && ((INTVAL (operands[1]) > 0x7f
1039 && INTVAL (operands[1]) <= 0x7f + 0x7f)
1040 || (INTVAL (operands[1]) < - 0x80
1041 && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1042 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1043 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1045 HOST_WIDE_INT val = INTVAL (operands[1]);
1049 operands[1] = GEN_INT (0x7f);
1050 operands[2] = GEN_INT (val - 0x7f);
1054 operands[1] = GEN_INT (- 0x80);
1055 operands[2] = GEN_INT (val + 0x80);
1060 [(set (match_operand:SI 0 "d_operand")
1061 (plus:SI (match_operand:SI 1 "d_operand")
1062 (match_operand:SI 2 "const_int_operand")))]
1063 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1064 && REGNO (operands[0]) != REGNO (operands[1])
1065 && ((INTVAL (operands[2]) > 0x7
1066 && INTVAL (operands[2]) <= 0x7 + 0x7f)
1067 || (INTVAL (operands[2]) < - 0x8
1068 && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1069 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1070 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1072 HOST_WIDE_INT val = INTVAL (operands[2]);
1076 operands[2] = GEN_INT (0x7);
1077 operands[3] = GEN_INT (val - 0x7);
1081 operands[2] = GEN_INT (- 0x8);
1082 operands[3] = GEN_INT (val + 0x8);
1087 [(set (match_operand:DI 0 "d_operand")
1088 (plus:DI (match_dup 0)
1089 (match_operand:DI 1 "const_int_operand")))]
1090 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1091 && ((INTVAL (operands[1]) > 0xf
1092 && INTVAL (operands[1]) <= 0xf + 0xf)
1093 || (INTVAL (operands[1]) < - 0x10
1094 && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1095 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1096 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1098 HOST_WIDE_INT val = INTVAL (operands[1]);
1102 operands[1] = GEN_INT (0xf);
1103 operands[2] = GEN_INT (val - 0xf);
1107 operands[1] = GEN_INT (- 0x10);
1108 operands[2] = GEN_INT (val + 0x10);
1113 [(set (match_operand:DI 0 "d_operand")
1114 (plus:DI (match_operand:DI 1 "d_operand")
1115 (match_operand:DI 2 "const_int_operand")))]
1116 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1117 && REGNO (operands[0]) != REGNO (operands[1])
1118 && ((INTVAL (operands[2]) > 0x7
1119 && INTVAL (operands[2]) <= 0x7 + 0xf)
1120 || (INTVAL (operands[2]) < - 0x8
1121 && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1122 [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1123 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1125 HOST_WIDE_INT val = INTVAL (operands[2]);
1129 operands[2] = GEN_INT (0x7);
1130 operands[3] = GEN_INT (val - 0x7);
1134 operands[2] = GEN_INT (- 0x8);
1135 operands[3] = GEN_INT (val + 0x8);
1139 (define_insn "*addsi3_extended"
1140 [(set (match_operand:DI 0 "register_operand" "=d,d")
1142 (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1143 (match_operand:SI 2 "arith_operand" "d,Q"))))]
1144 "TARGET_64BIT && !TARGET_MIPS16"
1148 [(set_attr "alu_type" "add")
1149 (set_attr "mode" "SI")])
1151 ;; Split this insn so that the addiu splitters can have a crack at it.
1152 ;; Use a conservative length estimate until the split.
1153 (define_insn_and_split "*addsi3_extended_mips16"
1154 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1156 (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1157 (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1158 "TARGET_64BIT && TARGET_MIPS16"
1160 "&& reload_completed"
1161 [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1162 { operands[3] = gen_lowpart (SImode, operands[0]); }
1163 [(set_attr "alu_type" "add")
1164 (set_attr "mode" "SI")
1165 (set_attr "extended_mips16" "yes")])
1167 ;; Combiner patterns for unsigned byte-add.
1169 (define_insn "*baddu_si_eb"
1170 [(set (match_operand:SI 0 "register_operand" "=d")
1173 (plus:SI (match_operand:SI 1 "register_operand" "d")
1174 (match_operand:SI 2 "register_operand" "d")) 3)))]
1175 "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1177 [(set_attr "alu_type" "add")])
1179 (define_insn "*baddu_si_el"
1180 [(set (match_operand:SI 0 "register_operand" "=d")
1183 (plus:SI (match_operand:SI 1 "register_operand" "d")
1184 (match_operand:SI 2 "register_operand" "d")) 0)))]
1185 "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1187 [(set_attr "alu_type" "add")])
1189 (define_insn "*baddu_di<mode>"
1190 [(set (match_operand:GPR 0 "register_operand" "=d")
1193 (plus:DI (match_operand:DI 1 "register_operand" "d")
1194 (match_operand:DI 2 "register_operand" "d")))))]
1195 "ISA_HAS_BADDU && TARGET_64BIT"
1197 [(set_attr "alu_type" "add")])
1200 ;; ....................
1204 ;; ....................
1207 (define_insn "sub<mode>3"
1208 [(set (match_operand:ANYF 0 "register_operand" "=f")
1209 (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1210 (match_operand:ANYF 2 "register_operand" "f")))]
1212 "sub.<fmt>\t%0,%1,%2"
1213 [(set_attr "type" "fadd")
1214 (set_attr "mode" "<UNITMODE>")])
1216 (define_insn "sub<mode>3"
1217 [(set (match_operand:GPR 0 "register_operand" "=d")
1218 (minus:GPR (match_operand:GPR 1 "register_operand" "d")
1219 (match_operand:GPR 2 "register_operand" "d")))]
1222 [(set_attr "alu_type" "sub")
1223 (set_attr "mode" "<MODE>")])
1225 (define_insn "*subsi3_extended"
1226 [(set (match_operand:DI 0 "register_operand" "=d")
1228 (minus:SI (match_operand:SI 1 "register_operand" "d")
1229 (match_operand:SI 2 "register_operand" "d"))))]
1232 [(set_attr "alu_type" "sub")
1233 (set_attr "mode" "DI")])
1236 ;; ....................
1240 ;; ....................
1243 (define_expand "mul<mode>3"
1244 [(set (match_operand:SCALARF 0 "register_operand")
1245 (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1246 (match_operand:SCALARF 2 "register_operand")))]
1250 (define_insn "*mul<mode>3"
1251 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1252 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1253 (match_operand:SCALARF 2 "register_operand" "f")))]
1254 "!TARGET_4300_MUL_FIX"
1255 "mul.<fmt>\t%0,%1,%2"
1256 [(set_attr "type" "fmul")
1257 (set_attr "mode" "<MODE>")])
1259 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1260 ;; operands may corrupt immediately following multiplies. This is a
1261 ;; simple fix to insert NOPs.
1263 (define_insn "*mul<mode>3_r4300"
1264 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1265 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1266 (match_operand:SCALARF 2 "register_operand" "f")))]
1267 "TARGET_4300_MUL_FIX"
1268 "mul.<fmt>\t%0,%1,%2\;nop"
1269 [(set_attr "type" "fmul")
1270 (set_attr "mode" "<MODE>")
1271 (set_attr "length" "8")])
1273 (define_insn "mulv2sf3"
1274 [(set (match_operand:V2SF 0 "register_operand" "=f")
1275 (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1276 (match_operand:V2SF 2 "register_operand" "f")))]
1277 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1279 [(set_attr "type" "fmul")
1280 (set_attr "mode" "SF")])
1282 ;; The original R4000 has a cpu bug. If a double-word or a variable
1283 ;; shift executes while an integer multiplication is in progress, the
1284 ;; shift may give an incorrect result. Avoid this by keeping the mflo
1285 ;; with the mult on the R4000.
1287 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1288 ;; (also valid for MIPS R4000MC processors):
1290 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1291 ;; this errata description.
1292 ;; The following code sequence causes the R4000 to incorrectly
1293 ;; execute the Double Shift Right Arithmetic 32 (dsra32)
1294 ;; instruction. If the dsra32 instruction is executed during an
1295 ;; integer multiply, the dsra32 will only shift by the amount in
1296 ;; specified in the instruction rather than the amount plus 32
1298 ;; instruction 1: mult rs,rt integer multiply
1299 ;; instruction 2-12: dsra32 rd,rt,rs doubleword shift
1300 ;; right arithmetic + 32
1301 ;; Workaround: A dsra32 instruction placed after an integer
1302 ;; multiply should not be one of the 11 instructions after the
1303 ;; multiply instruction."
1307 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1308 ;; the following description.
1309 ;; All extended shifts (shift by n+32) and variable shifts (32 and
1310 ;; 64-bit versions) may produce incorrect results under the
1311 ;; following conditions:
1312 ;; 1) An integer multiply is currently executing
1313 ;; 2) These types of shift instructions are executed immediately
1314 ;; following an integer divide instruction.
1316 ;; 1) Make sure no integer multiply is running wihen these
1317 ;; instruction are executed. If this cannot be predicted at
1318 ;; compile time, then insert a "mfhi" to R0 instruction
1319 ;; immediately after the integer multiply instruction. This
1320 ;; will cause the integer multiply to complete before the shift
1322 ;; 2) Separate integer divide and these two classes of shift
1323 ;; instructions by another instruction or a noop."
1325 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1328 (define_expand "mul<mode>3"
1329 [(set (match_operand:GPR 0 "register_operand")
1330 (mult:GPR (match_operand:GPR 1 "register_operand")
1331 (match_operand:GPR 2 "register_operand")))]
1336 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
1337 emit_insn (gen_mul<mode>3_mul3_loongson (operands[0], operands[1],
1339 else if (ISA_HAS_<D>MUL3)
1340 emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1341 else if (TARGET_MIPS16)
1343 lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1344 emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1345 emit_move_insn (operands[0], lo);
1347 else if (TARGET_FIX_R4000)
1348 emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1351 (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1355 (define_insn "mul<mode>3_mul3_loongson"
1356 [(set (match_operand:GPR 0 "register_operand" "=d")
1357 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1358 (match_operand:GPR 2 "register_operand" "d")))]
1359 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A"
1361 if (TARGET_LOONGSON_2EF)
1362 return "<d>multu.g\t%0,%1,%2";
1364 return "gs<d>multu\t%0,%1,%2";
1366 [(set_attr "type" "imul3nc")
1367 (set_attr "mode" "<MODE>")])
1369 (define_insn "mul<mode>3_mul3"
1370 [(set (match_operand:GPR 0 "register_operand" "=d,l")
1371 (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1372 (match_operand:GPR 2 "register_operand" "d,d")))
1373 (clobber (match_scratch:GPR 3 "=l,X"))]
1376 if (which_alternative == 1)
1377 return "<d>mult\t%1,%2";
1378 if (<MODE>mode == SImode && TARGET_MIPS3900)
1379 return "mult\t%0,%1,%2";
1380 return "<d>mul\t%0,%1,%2";
1382 [(set_attr "type" "imul3,imul")
1383 (set_attr "mode" "<MODE>")])
1385 ;; If a register gets allocated to LO, and we spill to memory, the reload
1386 ;; will include a move from LO to a GPR. Merge it into the multiplication
1387 ;; if it can set the GPR directly.
1390 ;; Operand 1: GPR (1st multiplication operand)
1391 ;; Operand 2: GPR (2nd multiplication operand)
1392 ;; Operand 3: GPR (destination)
1395 [(set (match_operand:SI 0 "lo_operand")
1396 (mult:SI (match_operand:SI 1 "d_operand")
1397 (match_operand:SI 2 "d_operand")))
1398 (clobber (scratch:SI))])
1399 (set (match_operand:SI 3 "d_operand")
1401 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1404 (mult:SI (match_dup 1)
1406 (clobber (match_dup 0))])])
1408 (define_insn "mul<mode>3_internal"
1409 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1410 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1411 (match_operand:GPR 2 "register_operand" "d")))]
1414 [(set_attr "type" "imul")
1415 (set_attr "mode" "<MODE>")])
1417 (define_insn "mul<mode>3_r4000"
1418 [(set (match_operand:GPR 0 "register_operand" "=d")
1419 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1420 (match_operand:GPR 2 "register_operand" "d")))
1421 (clobber (match_scratch:GPR 3 "=l"))]
1423 "<d>mult\t%1,%2\;mflo\t%0"
1424 [(set_attr "type" "imul")
1425 (set_attr "mode" "<MODE>")
1426 (set_attr "length" "8")])
1428 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1429 ;; of "mult; mflo". They have the same latency, but the first form gives
1430 ;; us an extra cycle to compute the operands.
1433 ;; Operand 1: GPR (1st multiplication operand)
1434 ;; Operand 2: GPR (2nd multiplication operand)
1435 ;; Operand 3: GPR (destination)
1437 [(set (match_operand:SI 0 "lo_operand")
1438 (mult:SI (match_operand:SI 1 "d_operand")
1439 (match_operand:SI 2 "d_operand")))
1440 (set (match_operand:SI 3 "d_operand")
1442 "ISA_HAS_MACC && !ISA_HAS_MUL3"
1447 (plus:SI (mult:SI (match_dup 1)
1451 (plus:SI (mult:SI (match_dup 1)
1455 ;; Multiply-accumulate patterns
1457 ;; This pattern is first matched by combine, which tries to use the
1458 ;; pattern wherever it can. We don't know until later whether it
1459 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1460 ;; so we need to keep both options open.
1462 ;; The second alternative has a "?" marker because it is generally
1463 ;; one instruction more costly than the first alternative. This "?"
1464 ;; marker is enough to convey the relative costs to the register
1467 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1468 ;; reloads of the other operands, even though operands 4 and 5 need no
1469 ;; copy instructions. Reload therefore thinks that the second alternative
1470 ;; is two reloads more costly than the first. We add "*?*?" to the first
1471 ;; alternative as a counterweight.
1472 (define_insn "*mul_acc_si"
1473 [(set (match_operand:SI 0 "register_operand" "=l*?*?,d?")
1474 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1475 (match_operand:SI 2 "register_operand" "d,d"))
1476 (match_operand:SI 3 "register_operand" "0,d")))
1477 (clobber (match_scratch:SI 4 "=X,l"))
1478 (clobber (match_scratch:SI 5 "=X,&d"))]
1479 "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1483 [(set_attr "type" "imadd")
1484 (set_attr "mode" "SI")
1485 (set_attr "length" "4,8")])
1487 ;; The same idea applies here. The middle alternative needs one less
1488 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1489 (define_insn "*mul_acc_si_r3900"
1490 [(set (match_operand:SI 0 "register_operand" "=l*?*?,d*?,d?")
1491 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1492 (match_operand:SI 2 "register_operand" "d,d,d"))
1493 (match_operand:SI 3 "register_operand" "0,l,d")))
1494 (clobber (match_scratch:SI 4 "=X,3,l"))
1495 (clobber (match_scratch:SI 5 "=X,X,&d"))]
1496 "TARGET_MIPS3900 && !TARGET_MIPS16"
1501 [(set_attr "type" "imadd")
1502 (set_attr "mode" "SI")
1503 (set_attr "length" "4,4,8")])
1505 ;; Split *mul_acc_si if both the source and destination accumulator
1508 [(set (match_operand:SI 0 "d_operand")
1509 (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1510 (match_operand:SI 2 "d_operand"))
1511 (match_operand:SI 3 "d_operand")))
1512 (clobber (match_operand:SI 4 "lo_operand"))
1513 (clobber (match_operand:SI 5 "d_operand"))]
1515 [(parallel [(set (match_dup 5)
1516 (mult:SI (match_dup 1) (match_dup 2)))
1517 (clobber (match_dup 4))])
1518 (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1521 (define_insn "*macc"
1522 [(set (match_operand:SI 0 "register_operand" "=l,d")
1523 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1524 (match_operand:SI 2 "register_operand" "d,d"))
1525 (match_operand:SI 3 "register_operand" "0,l")))
1526 (clobber (match_scratch:SI 4 "=X,3"))]
1529 if (which_alternative == 1)
1530 return "macc\t%0,%1,%2";
1531 else if (TARGET_MIPS5500)
1532 return "madd\t%1,%2";
1534 /* The VR4130 assumes that there is a two-cycle latency between a macc
1535 that "writes" to $0 and an instruction that reads from it. We avoid
1536 this by assigning to $1 instead. */
1537 return "%[macc\t%@,%1,%2%]";
1539 [(set_attr "type" "imadd")
1540 (set_attr "mode" "SI")])
1542 (define_insn "*msac"
1543 [(set (match_operand:SI 0 "register_operand" "=l,d")
1544 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1545 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1546 (match_operand:SI 3 "register_operand" "d,d"))))
1547 (clobber (match_scratch:SI 4 "=X,1"))]
1550 if (which_alternative == 1)
1551 return "msac\t%0,%2,%3";
1552 else if (TARGET_MIPS5500)
1553 return "msub\t%2,%3";
1555 return "msac\t$0,%2,%3";
1557 [(set_attr "type" "imadd")
1558 (set_attr "mode" "SI")])
1560 ;; An msac-like instruction implemented using negation and a macc.
1561 (define_insn_and_split "*msac_using_macc"
1562 [(set (match_operand:SI 0 "register_operand" "=l,d")
1563 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1564 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1565 (match_operand:SI 3 "register_operand" "d,d"))))
1566 (clobber (match_scratch:SI 4 "=X,1"))
1567 (clobber (match_scratch:SI 5 "=d,d"))]
1568 "ISA_HAS_MACC && !ISA_HAS_MSAC"
1570 "&& reload_completed"
1572 (neg:SI (match_dup 3)))
1575 (plus:SI (mult:SI (match_dup 2)
1578 (clobber (match_dup 4))])]
1580 [(set_attr "type" "imadd")
1581 (set_attr "length" "8")])
1583 ;; Patterns generated by the define_peephole2 below.
1585 (define_insn "*macc2"
1586 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1587 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1588 (match_operand:SI 2 "register_operand" "d"))
1590 (set (match_operand:SI 3 "register_operand" "=d")
1591 (plus:SI (mult:SI (match_dup 1)
1594 "ISA_HAS_MACC && reload_completed"
1596 [(set_attr "type" "imadd")
1597 (set_attr "mode" "SI")])
1599 (define_insn "*msac2"
1600 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1601 (minus:SI (match_dup 0)
1602 (mult:SI (match_operand:SI 1 "register_operand" "d")
1603 (match_operand:SI 2 "register_operand" "d"))))
1604 (set (match_operand:SI 3 "register_operand" "=d")
1605 (minus:SI (match_dup 0)
1606 (mult:SI (match_dup 1)
1608 "ISA_HAS_MSAC && reload_completed"
1610 [(set_attr "type" "imadd")
1611 (set_attr "mode" "SI")])
1613 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1617 ;; Operand 1: macc/msac
1618 ;; Operand 2: GPR (destination)
1621 [(set (match_operand:SI 0 "lo_operand")
1622 (match_operand:SI 1 "macc_msac_operand"))
1623 (clobber (scratch:SI))])
1624 (set (match_operand:SI 2 "d_operand")
1627 [(parallel [(set (match_dup 0)
1632 ;; When we have a three-address multiplication instruction, it should
1633 ;; be faster to do a separate multiply and add, rather than moving
1634 ;; something into LO in order to use a macc instruction.
1636 ;; This peephole needs a scratch register to cater for the case when one
1637 ;; of the multiplication operands is the same as the destination.
1639 ;; Operand 0: GPR (scratch)
1641 ;; Operand 2: GPR (addend)
1642 ;; Operand 3: GPR (destination)
1643 ;; Operand 4: macc/msac
1644 ;; Operand 5: new multiplication
1645 ;; Operand 6: new addition/subtraction
1647 [(match_scratch:SI 0 "d")
1648 (set (match_operand:SI 1 "lo_operand")
1649 (match_operand:SI 2 "d_operand"))
1652 [(set (match_operand:SI 3 "d_operand")
1653 (match_operand:SI 4 "macc_msac_operand"))
1654 (clobber (match_dup 1))])]
1655 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1656 [(parallel [(set (match_dup 0)
1658 (clobber (match_dup 1))])
1662 operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1663 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1664 operands[2], operands[0]);
1667 ;; Same as above, except LO is the initial target of the macc.
1669 ;; Operand 0: GPR (scratch)
1671 ;; Operand 2: GPR (addend)
1672 ;; Operand 3: macc/msac
1673 ;; Operand 4: GPR (destination)
1674 ;; Operand 5: new multiplication
1675 ;; Operand 6: new addition/subtraction
1677 [(match_scratch:SI 0 "d")
1678 (set (match_operand:SI 1 "lo_operand")
1679 (match_operand:SI 2 "d_operand"))
1683 (match_operand:SI 3 "macc_msac_operand"))
1684 (clobber (scratch:SI))])
1686 (set (match_operand:SI 4 "d_operand")
1688 "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1689 [(parallel [(set (match_dup 0)
1691 (clobber (match_dup 1))])
1695 operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
1696 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
1697 operands[2], operands[0]);
1700 ;; See the comment above *mul_add_si for details.
1701 (define_insn "*mul_sub_si"
1702 [(set (match_operand:SI 0 "register_operand" "=l*?*?,d?")
1703 (minus:SI (match_operand:SI 1 "register_operand" "0,d")
1704 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1705 (match_operand:SI 3 "register_operand" "d,d"))))
1706 (clobber (match_scratch:SI 4 "=X,l"))
1707 (clobber (match_scratch:SI 5 "=X,&d"))]
1708 "GENERATE_MADD_MSUB"
1712 [(set_attr "type" "imadd")
1713 (set_attr "mode" "SI")
1714 (set_attr "length" "4,8")])
1716 ;; Split *mul_sub_si if both the source and destination accumulator
1719 [(set (match_operand:SI 0 "d_operand")
1720 (minus:SI (match_operand:SI 1 "d_operand")
1721 (mult:SI (match_operand:SI 2 "d_operand")
1722 (match_operand:SI 3 "d_operand"))))
1723 (clobber (match_operand:SI 4 "lo_operand"))
1724 (clobber (match_operand:SI 5 "d_operand"))]
1726 [(parallel [(set (match_dup 5)
1727 (mult:SI (match_dup 2) (match_dup 3)))
1728 (clobber (match_dup 4))])
1729 (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
1732 (define_insn "*muls"
1733 [(set (match_operand:SI 0 "register_operand" "=l,d")
1734 (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1735 (match_operand:SI 2 "register_operand" "d,d"))))
1736 (clobber (match_scratch:SI 3 "=X,l"))]
1741 [(set_attr "type" "imul,imul3")
1742 (set_attr "mode" "SI")])
1744 (define_expand "<u>mulsidi3"
1745 [(set (match_operand:DI 0 "register_operand")
1746 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1747 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1748 "mips_mulsidi3_gen_fn (<CODE>) != NULL"
1750 mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
1751 emit_insn (fn (operands[0], operands[1], operands[2]));
1755 (define_expand "<u>mulsidi3_32bit_mips16"
1756 [(set (match_operand:DI 0 "register_operand")
1757 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1758 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1759 "!TARGET_64BIT && TARGET_MIPS16"
1763 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
1764 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
1765 emit_move_insn (operands[0], hilo);
1769 ;; As well as being named patterns, these instructions are used by the
1770 ;; __builtin_mips_mult<u>() functions. We must always make those functions
1771 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
1772 (define_insn "<u>mulsidi3_32bit"
1773 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
1774 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1775 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
1776 "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP)"
1778 if (ISA_HAS_DSP_MULT)
1779 return "mult<u>\t%q0,%1,%2";
1781 return "mult<u>\t%1,%2";
1783 [(set_attr "type" "imul")
1784 (set_attr "mode" "SI")])
1786 (define_insn "<u>mulsidi3_32bit_r4000"
1787 [(set (match_operand:DI 0 "register_operand" "=d")
1788 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1789 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1790 (clobber (match_scratch:DI 3 "=x"))]
1791 "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP"
1792 "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
1793 [(set_attr "type" "imul")
1794 (set_attr "mode" "SI")
1795 (set_attr "length" "12")])
1797 (define_insn_and_split "<u>mulsidi3_64bit"
1798 [(set (match_operand:DI 0 "register_operand" "=d")
1799 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1800 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1801 (clobber (match_scratch:TI 3 "=x"))
1802 (clobber (match_scratch:DI 4 "=d"))]
1803 "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3 && !TARGET_MIPS16"
1805 "&& reload_completed"
1808 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
1809 operands[2], operands[4]));
1812 [(set_attr "type" "imul")
1813 (set_attr "mode" "SI")
1814 (set (attr "length")
1815 (if_then_else (match_test "ISA_HAS_EXT_INS")
1819 (define_expand "<u>mulsidi3_64bit_mips16"
1820 [(set (match_operand:DI 0 "register_operand")
1821 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1822 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1823 "TARGET_64BIT && TARGET_MIPS16"
1825 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
1826 operands[2], gen_reg_rtx (DImode)));
1830 (define_expand "<u>mulsidi3_64bit_split"
1831 [(set (match_operand:DI 0 "register_operand")
1832 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1833 (any_extend:DI (match_operand:SI 2 "register_operand"))))
1834 (clobber (match_operand:DI 3 "register_operand"))]
1839 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
1840 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
1842 emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
1843 emit_insn (gen_mfhidi_ti (operands[3], hilo));
1845 if (ISA_HAS_EXT_INS)
1846 emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
1850 /* Zero-extend the low part. */
1851 mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
1852 mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
1854 /* Shift the high part into place. */
1855 mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
1857 /* OR the two halves together. */
1858 mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
1863 (define_insn "<u>mulsidi3_64bit_hilo"
1864 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
1867 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1868 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
1870 "TARGET_64BIT && !TARGET_FIX_R4000"
1872 [(set_attr "type" "imul")
1873 (set_attr "mode" "SI")])
1875 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
1876 (define_insn "mulsidi3_64bit_dmul"
1877 [(set (match_operand:DI 0 "register_operand" "=d")
1878 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
1879 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1880 (clobber (match_scratch:DI 3 "=l"))]
1881 "TARGET_64BIT && ISA_HAS_DMUL3"
1883 [(set_attr "type" "imul3")
1884 (set_attr "mode" "DI")])
1886 ;; Widening multiply with negation.
1887 (define_insn "*muls<u>_di"
1888 [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
1891 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1892 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1893 "!TARGET_64BIT && ISA_HAS_MULS"
1895 [(set_attr "type" "imul")
1896 (set_attr "mode" "SI")])
1898 ;; As well as being named patterns, these instructions are used by the
1899 ;; __builtin_mips_msub<u>() functions. We must always make those functions
1900 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
1902 ;; This leads to a slight inconsistency. We honor any tuning overrides
1903 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
1904 ;; even if !ISA_HAS_DSP_MULT.
1905 (define_insn "<u>msubsidi4"
1906 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
1908 (match_operand:DI 3 "muldiv_target_operand" "0")
1910 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1911 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1912 "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
1914 if (ISA_HAS_DSP_MULT)
1915 return "msub<u>\t%q0,%1,%2";
1916 else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
1917 return "msub<u>\t%1,%2";
1919 return "msac<u>\t$0,%1,%2";
1921 [(set_attr "type" "imadd")
1922 (set_attr "mode" "SI")])
1924 ;; _highpart patterns
1926 (define_expand "<su>mulsi3_highpart"
1927 [(set (match_operand:SI 0 "register_operand")
1930 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1931 (any_extend:DI (match_operand:SI 2 "register_operand")))
1936 emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
1939 else if (TARGET_MIPS16)
1940 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
1943 emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
1948 (define_insn_and_split "<su>mulsi3_highpart_internal"
1949 [(set (match_operand:SI 0 "register_operand" "=d")
1952 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1953 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1955 (clobber (match_scratch:SI 3 "=l"))]
1956 "!ISA_HAS_MULHI && !TARGET_MIPS16"
1957 { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
1958 "&& reload_completed && !TARGET_FIX_R4000"
1961 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
1965 [(set_attr "type" "imul")
1966 (set_attr "mode" "SI")
1967 (set_attr "length" "8")])
1969 (define_expand "<su>mulsi3_highpart_split"
1970 [(set (match_operand:SI 0 "register_operand")
1973 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1974 (any_extend:DI (match_operand:SI 2 "register_operand")))
1982 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
1983 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
1984 emit_insn (gen_mfhisi_ti (operands[0], hilo));
1988 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
1989 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
1990 emit_insn (gen_mfhisi_di (operands[0], hilo));
1995 (define_insn "<su>mulsi3_highpart_mulhi_internal"
1996 [(set (match_operand:SI 0 "register_operand" "=d")
2000 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2001 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2003 (clobber (match_scratch:SI 3 "=l"))]
2005 "mulhi<u>\t%0,%1,%2"
2006 [(set_attr "type" "imul3")
2007 (set_attr "mode" "SI")])
2009 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2010 [(set (match_operand:SI 0 "register_operand" "=d")
2015 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2016 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2018 (clobber (match_scratch:SI 3 "=l"))]
2020 "mulshi<u>\t%0,%1,%2"
2021 [(set_attr "type" "imul3")
2022 (set_attr "mode" "SI")])
2024 ;; Disable unsigned multiplication for -mfix-vr4120. This is for VR4120
2025 ;; errata MD(0), which says that dmultu does not always produce the
2027 (define_expand "<su>muldi3_highpart"
2028 [(set (match_operand:DI 0 "register_operand")
2031 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2032 (any_extend:TI (match_operand:DI 2 "register_operand")))
2034 "TARGET_64BIT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2037 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2040 emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2045 (define_insn_and_split "<su>muldi3_highpart_internal"
2046 [(set (match_operand:DI 0 "register_operand" "=d")
2049 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2050 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2052 (clobber (match_scratch:DI 3 "=l"))]
2055 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2056 { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2057 "&& reload_completed && !TARGET_FIX_R4000"
2060 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2064 [(set_attr "type" "imul")
2065 (set_attr "mode" "DI")
2066 (set_attr "length" "8")])
2068 (define_expand "<su>muldi3_highpart_split"
2069 [(set (match_operand:DI 0 "register_operand")
2072 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2073 (any_extend:TI (match_operand:DI 2 "register_operand")))
2079 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2080 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2081 emit_insn (gen_mfhidi_ti (operands[0], hilo));
2085 (define_expand "<u>mulditi3"
2086 [(set (match_operand:TI 0 "register_operand")
2087 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2088 (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2089 "TARGET_64BIT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2095 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2096 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2097 emit_move_insn (operands[0], hilo);
2099 else if (TARGET_FIX_R4000)
2100 emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2102 emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2107 (define_insn "<u>mulditi3_internal"
2108 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2109 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2110 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2112 && !TARGET_FIX_R4000
2113 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2115 [(set_attr "type" "imul")
2116 (set_attr "mode" "DI")])
2118 (define_insn "<u>mulditi3_r4000"
2119 [(set (match_operand:TI 0 "register_operand" "=d")
2120 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2121 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2122 (clobber (match_scratch:TI 3 "=x"))]
2125 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2126 "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2127 [(set_attr "type" "imul")
2128 (set_attr "mode" "DI")
2129 (set_attr "length" "12")])
2131 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2132 ;; instruction. The HI/LO registers are used as a 64-bit accumulator.
2134 (define_insn "madsi"
2135 [(set (match_operand:SI 0 "register_operand" "+l")
2136 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2137 (match_operand:SI 2 "register_operand" "d"))
2141 [(set_attr "type" "imadd")
2142 (set_attr "mode" "SI")])
2144 ;; See the comment above <u>msubsidi4 for the relationship between
2145 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2146 (define_insn "<u>maddsidi4"
2147 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2149 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2150 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2151 (match_operand:DI 3 "muldiv_target_operand" "0")))]
2152 "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2156 return "mad<u>\t%1,%2";
2157 else if (ISA_HAS_DSP_MULT)
2158 return "madd<u>\t%q0,%1,%2";
2159 else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2160 return "madd<u>\t%1,%2";
2162 /* See comment in *macc. */
2163 return "%[macc<u>\t%@,%1,%2%]";
2165 [(set_attr "type" "imadd")
2166 (set_attr "mode" "SI")])
2168 ;; Floating point multiply accumulate instructions.
2170 (define_insn "*madd4<mode>"
2171 [(set (match_operand:ANYF 0 "register_operand" "=f")
2172 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2173 (match_operand:ANYF 2 "register_operand" "f"))
2174 (match_operand:ANYF 3 "register_operand" "f")))]
2175 "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2176 "madd.<fmt>\t%0,%3,%1,%2"
2177 [(set_attr "type" "fmadd")
2178 (set_attr "mode" "<UNITMODE>")])
2180 (define_insn "*madd3<mode>"
2181 [(set (match_operand:ANYF 0 "register_operand" "=f")
2182 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2183 (match_operand:ANYF 2 "register_operand" "f"))
2184 (match_operand:ANYF 3 "register_operand" "0")))]
2185 "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2186 "madd.<fmt>\t%0,%1,%2"
2187 [(set_attr "type" "fmadd")
2188 (set_attr "mode" "<UNITMODE>")])
2190 (define_insn "*msub4<mode>"
2191 [(set (match_operand:ANYF 0 "register_operand" "=f")
2192 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2193 (match_operand:ANYF 2 "register_operand" "f"))
2194 (match_operand:ANYF 3 "register_operand" "f")))]
2195 "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2196 "msub.<fmt>\t%0,%3,%1,%2"
2197 [(set_attr "type" "fmadd")
2198 (set_attr "mode" "<UNITMODE>")])
2200 (define_insn "*msub3<mode>"
2201 [(set (match_operand:ANYF 0 "register_operand" "=f")
2202 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2203 (match_operand:ANYF 2 "register_operand" "f"))
2204 (match_operand:ANYF 3 "register_operand" "0")))]
2205 "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2206 "msub.<fmt>\t%0,%1,%2"
2207 [(set_attr "type" "fmadd")
2208 (set_attr "mode" "<UNITMODE>")])
2210 (define_insn "*nmadd4<mode>"
2211 [(set (match_operand:ANYF 0 "register_operand" "=f")
2212 (neg:ANYF (plus:ANYF
2213 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2214 (match_operand:ANYF 2 "register_operand" "f"))
2215 (match_operand:ANYF 3 "register_operand" "f"))))]
2216 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2217 && TARGET_FUSED_MADD
2218 && HONOR_SIGNED_ZEROS (<MODE>mode)
2219 && !HONOR_NANS (<MODE>mode)"
2220 "nmadd.<fmt>\t%0,%3,%1,%2"
2221 [(set_attr "type" "fmadd")
2222 (set_attr "mode" "<UNITMODE>")])
2224 (define_insn "*nmadd3<mode>"
2225 [(set (match_operand:ANYF 0 "register_operand" "=f")
2226 (neg:ANYF (plus:ANYF
2227 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2228 (match_operand:ANYF 2 "register_operand" "f"))
2229 (match_operand:ANYF 3 "register_operand" "0"))))]
2230 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2231 && TARGET_FUSED_MADD
2232 && HONOR_SIGNED_ZEROS (<MODE>mode)
2233 && !HONOR_NANS (<MODE>mode)"
2234 "nmadd.<fmt>\t%0,%1,%2"
2235 [(set_attr "type" "fmadd")
2236 (set_attr "mode" "<UNITMODE>")])
2238 (define_insn "*nmadd4<mode>_fastmath"
2239 [(set (match_operand:ANYF 0 "register_operand" "=f")
2241 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2242 (match_operand:ANYF 2 "register_operand" "f"))
2243 (match_operand:ANYF 3 "register_operand" "f")))]
2244 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2245 && TARGET_FUSED_MADD
2246 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2247 && !HONOR_NANS (<MODE>mode)"
2248 "nmadd.<fmt>\t%0,%3,%1,%2"
2249 [(set_attr "type" "fmadd")
2250 (set_attr "mode" "<UNITMODE>")])
2252 (define_insn "*nmadd3<mode>_fastmath"
2253 [(set (match_operand:ANYF 0 "register_operand" "=f")
2255 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2256 (match_operand:ANYF 2 "register_operand" "f"))
2257 (match_operand:ANYF 3 "register_operand" "0")))]
2258 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2259 && TARGET_FUSED_MADD
2260 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2261 && !HONOR_NANS (<MODE>mode)"
2262 "nmadd.<fmt>\t%0,%1,%2"
2263 [(set_attr "type" "fmadd")
2264 (set_attr "mode" "<UNITMODE>")])
2266 (define_insn "*nmsub4<mode>"
2267 [(set (match_operand:ANYF 0 "register_operand" "=f")
2268 (neg:ANYF (minus:ANYF
2269 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2270 (match_operand:ANYF 3 "register_operand" "f"))
2271 (match_operand:ANYF 1 "register_operand" "f"))))]
2272 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2273 && TARGET_FUSED_MADD
2274 && HONOR_SIGNED_ZEROS (<MODE>mode)
2275 && !HONOR_NANS (<MODE>mode)"
2276 "nmsub.<fmt>\t%0,%1,%2,%3"
2277 [(set_attr "type" "fmadd")
2278 (set_attr "mode" "<UNITMODE>")])
2280 (define_insn "*nmsub3<mode>"
2281 [(set (match_operand:ANYF 0 "register_operand" "=f")
2282 (neg:ANYF (minus:ANYF
2283 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2284 (match_operand:ANYF 3 "register_operand" "f"))
2285 (match_operand:ANYF 1 "register_operand" "0"))))]
2286 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2287 && TARGET_FUSED_MADD
2288 && HONOR_SIGNED_ZEROS (<MODE>mode)
2289 && !HONOR_NANS (<MODE>mode)"
2290 "nmsub.<fmt>\t%0,%1,%2"
2291 [(set_attr "type" "fmadd")
2292 (set_attr "mode" "<UNITMODE>")])
2294 (define_insn "*nmsub4<mode>_fastmath"
2295 [(set (match_operand:ANYF 0 "register_operand" "=f")
2297 (match_operand:ANYF 1 "register_operand" "f")
2298 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2299 (match_operand:ANYF 3 "register_operand" "f"))))]
2300 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2301 && TARGET_FUSED_MADD
2302 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2303 && !HONOR_NANS (<MODE>mode)"
2304 "nmsub.<fmt>\t%0,%1,%2,%3"
2305 [(set_attr "type" "fmadd")
2306 (set_attr "mode" "<UNITMODE>")])
2308 (define_insn "*nmsub3<mode>_fastmath"
2309 [(set (match_operand:ANYF 0 "register_operand" "=f")
2311 (match_operand:ANYF 1 "register_operand" "f")
2312 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2313 (match_operand:ANYF 3 "register_operand" "0"))))]
2314 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2315 && TARGET_FUSED_MADD
2316 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2317 && !HONOR_NANS (<MODE>mode)"
2318 "nmsub.<fmt>\t%0,%1,%2"
2319 [(set_attr "type" "fmadd")
2320 (set_attr "mode" "<UNITMODE>")])
2323 ;; ....................
2325 ;; DIVISION and REMAINDER
2327 ;; ....................
2330 (define_expand "div<mode>3"
2331 [(set (match_operand:ANYF 0 "register_operand")
2332 (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2333 (match_operand:ANYF 2 "register_operand")))]
2334 "<divide_condition>"
2336 if (const_1_operand (operands[1], <MODE>mode))
2337 if (!(<recip_condition> && flag_unsafe_math_optimizations))
2338 operands[1] = force_reg (<MODE>mode, operands[1]);
2341 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2343 ;; If an mfc1 or dmfc1 happens to access the floating point register
2344 ;; file at the same time a long latency operation (div, sqrt, recip,
2345 ;; sqrt) iterates an intermediate result back through the floating
2346 ;; point register file bypass, then instead returning the correct
2347 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2348 ;; result of the long latency operation.
2350 ;; The workaround is to insert an unconditional 'mov' from/to the
2351 ;; long latency op destination register.
2353 (define_insn "*div<mode>3"
2354 [(set (match_operand:ANYF 0 "register_operand" "=f")
2355 (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2356 (match_operand:ANYF 2 "register_operand" "f")))]
2357 "<divide_condition>"
2360 return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2362 return "div.<fmt>\t%0,%1,%2";
2364 [(set_attr "type" "fdiv")
2365 (set_attr "mode" "<UNITMODE>")
2366 (set (attr "length")
2367 (if_then_else (match_test "TARGET_FIX_SB1")
2371 (define_insn "*recip<mode>3"
2372 [(set (match_operand:ANYF 0 "register_operand" "=f")
2373 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2374 (match_operand:ANYF 2 "register_operand" "f")))]
2375 "<recip_condition> && flag_unsafe_math_optimizations"
2378 return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2380 return "recip.<fmt>\t%0,%2";
2382 [(set_attr "type" "frdiv")
2383 (set_attr "mode" "<UNITMODE>")
2384 (set (attr "length")
2385 (if_then_else (match_test "TARGET_FIX_SB1")
2389 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2390 ;; with negative operands. We use special libgcc functions instead.
2391 (define_expand "divmod<mode>4"
2392 [(set (match_operand:GPR 0 "register_operand")
2393 (div:GPR (match_operand:GPR 1 "register_operand")
2394 (match_operand:GPR 2 "register_operand")))
2395 (set (match_operand:GPR 3 "register_operand")
2396 (mod:GPR (match_dup 1)
2398 "!TARGET_FIX_VR4120"
2402 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1],
2404 emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, LO_REGNUM));
2407 emit_insn (gen_divmod<mode>4_internal (operands[0], operands[1],
2408 operands[2], operands[3]));
2412 (define_insn_and_split "divmod<mode>4_internal"
2413 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
2414 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2415 (match_operand:GPR 2 "register_operand" "d")))
2416 (set (match_operand:GPR 3 "register_operand" "=d")
2417 (mod:GPR (match_dup 1)
2419 "!TARGET_FIX_VR4120 && !TARGET_MIPS16"
2421 "&& reload_completed"
2424 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2427 [(set_attr "type" "idiv")
2428 (set_attr "mode" "<MODE>")
2429 (set_attr "length" "8")])
2431 (define_expand "udivmod<mode>4"
2432 [(set (match_operand:GPR 0 "register_operand")
2433 (udiv:GPR (match_operand:GPR 1 "register_operand")
2434 (match_operand:GPR 2 "register_operand")))
2435 (set (match_operand:GPR 3 "register_operand")
2436 (umod:GPR (match_dup 1)
2442 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1],
2444 emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, LO_REGNUM));
2447 emit_insn (gen_udivmod<mode>4_internal (operands[0], operands[1],
2448 operands[2], operands[3]));
2452 (define_insn_and_split "udivmod<mode>4_internal"
2453 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
2454 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2455 (match_operand:GPR 2 "register_operand" "d")))
2456 (set (match_operand:GPR 3 "register_operand" "=d")
2457 (umod:GPR (match_dup 1)
2464 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2467 [(set_attr "type" "idiv")
2468 (set_attr "mode" "<MODE>")
2469 (set_attr "length" "8")])
2471 (define_expand "<u>divmod<mode>4_split"
2472 [(set (match_operand:GPR 0 "register_operand")
2473 (any_mod:GPR (match_operand:GPR 1 "register_operand")
2474 (match_operand:GPR 2 "register_operand")))]
2481 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2482 emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
2484 emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
2488 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2489 emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
2491 emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
2496 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
2497 [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
2499 [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2500 (match_operand:GPR 2 "register_operand" "d"))]
2503 { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
2504 [(set_attr "type" "idiv")
2505 (set_attr "mode" "<GPR:MODE>")])
2508 ;; ....................
2512 ;; ....................
2514 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
2515 ;; "*div[sd]f3" comment for details).
2517 (define_insn "sqrt<mode>2"
2518 [(set (match_operand:ANYF 0 "register_operand" "=f")
2519 (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2523 return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
2525 return "sqrt.<fmt>\t%0,%1";
2527 [(set_attr "type" "fsqrt")
2528 (set_attr "mode" "<UNITMODE>")
2529 (set (attr "length")
2530 (if_then_else (match_test "TARGET_FIX_SB1")
2534 (define_insn "*rsqrt<mode>a"
2535 [(set (match_operand:ANYF 0 "register_operand" "=f")
2536 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2537 (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
2538 "<recip_condition> && flag_unsafe_math_optimizations"
2541 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2543 return "rsqrt.<fmt>\t%0,%2";
2545 [(set_attr "type" "frsqrt")
2546 (set_attr "mode" "<UNITMODE>")
2547 (set (attr "length")
2548 (if_then_else (match_test "TARGET_FIX_SB1")
2552 (define_insn "*rsqrt<mode>b"
2553 [(set (match_operand:ANYF 0 "register_operand" "=f")
2554 (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2555 (match_operand:ANYF 2 "register_operand" "f"))))]
2556 "<recip_condition> && flag_unsafe_math_optimizations"
2559 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2561 return "rsqrt.<fmt>\t%0,%2";
2563 [(set_attr "type" "frsqrt")
2564 (set_attr "mode" "<UNITMODE>")
2565 (set (attr "length")
2566 (if_then_else (match_test "TARGET_FIX_SB1")
2571 ;; ....................
2575 ;; ....................
2577 ;; Do not use the integer abs macro instruction, since that signals an
2578 ;; exception on -2147483648 (sigh).
2580 ;; abs.fmt is an arithmetic instruction and treats all NaN inputs as
2581 ;; invalid; it does not clear their sign bits. We therefore can't use
2582 ;; abs.fmt if the signs of NaNs matter.
2584 (define_insn "abs<mode>2"
2585 [(set (match_operand:ANYF 0 "register_operand" "=f")
2586 (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2587 "!HONOR_NANS (<MODE>mode)"
2589 [(set_attr "type" "fabs")
2590 (set_attr "mode" "<UNITMODE>")])
2593 ;; ...................
2595 ;; Count leading zeroes.
2597 ;; ...................
2600 (define_insn "clz<mode>2"
2601 [(set (match_operand:GPR 0 "register_operand" "=d")
2602 (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
2605 [(set_attr "type" "clz")
2606 (set_attr "mode" "<MODE>")])
2609 ;; ...................
2611 ;; Count number of set bits.
2613 ;; ...................
2616 (define_insn "popcount<mode>2"
2617 [(set (match_operand:GPR 0 "register_operand" "=d")
2618 (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
2621 [(set_attr "type" "pop")
2622 (set_attr "mode" "<MODE>")])
2625 ;; ....................
2627 ;; NEGATION and ONE'S COMPLEMENT
2629 ;; ....................
2631 (define_insn "negsi2"
2632 [(set (match_operand:SI 0 "register_operand" "=d")
2633 (neg:SI (match_operand:SI 1 "register_operand" "d")))]
2637 return "neg\t%0,%1";
2639 return "subu\t%0,%.,%1";
2641 [(set_attr "alu_type" "sub")
2642 (set_attr "mode" "SI")])
2644 (define_insn "negdi2"
2645 [(set (match_operand:DI 0 "register_operand" "=d")
2646 (neg:DI (match_operand:DI 1 "register_operand" "d")))]
2647 "TARGET_64BIT && !TARGET_MIPS16"
2649 [(set_attr "alu_type" "sub")
2650 (set_attr "mode" "DI")])
2652 ;; neg.fmt is an arithmetic instruction and treats all NaN inputs as
2653 ;; invalid; it does not flip their sign bit. We therefore can't use
2654 ;; neg.fmt if the signs of NaNs matter.
2656 (define_insn "neg<mode>2"
2657 [(set (match_operand:ANYF 0 "register_operand" "=f")
2658 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2659 "!HONOR_NANS (<MODE>mode)"
2661 [(set_attr "type" "fneg")
2662 (set_attr "mode" "<UNITMODE>")])
2664 (define_insn "one_cmpl<mode>2"
2665 [(set (match_operand:GPR 0 "register_operand" "=d")
2666 (not:GPR (match_operand:GPR 1 "register_operand" "d")))]
2670 return "not\t%0,%1";
2672 return "nor\t%0,%.,%1";
2674 [(set_attr "alu_type" "not")
2675 (set_attr "mode" "<MODE>")])
2678 ;; ....................
2682 ;; ....................
2685 ;; Many of these instructions use trivial define_expands, because we
2686 ;; want to use a different set of constraints when TARGET_MIPS16.
2688 (define_expand "and<mode>3"
2689 [(set (match_operand:GPR 0 "register_operand")
2690 (and:GPR (match_operand:GPR 1 "register_operand")
2691 (match_operand:GPR 2 "and_reg_operand")))])
2693 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
2694 ;; zero_extendsidi2 because of TRULY_NOOP_TRUNCATION, so handle these here.
2695 ;; Note that this variant does not trigger for SI mode because we require
2696 ;; a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
2697 ;; sign-extended SImode value.
2699 ;; These are possible combinations for operand 1 and 2. The table
2700 ;; includes both MIPS and MIPS16 cases. (r=register, mem=memory,
2701 ;; 16=MIPS16, x=match, S=split):
2703 ;; \ op1 r/EXT r/!EXT mem r/16 mem/16
2709 ;; 0xffff_ffff x S x S x
2714 (define_insn "*and<mode>3"
2715 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d,d,d")
2716 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,d,d,d,d")
2717 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,K,Yx,Yw,d")))]
2718 "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
2722 switch (which_alternative)
2725 operands[1] = gen_lowpart (QImode, operands[1]);
2726 return "lbu\t%0,%1";
2728 operands[1] = gen_lowpart (HImode, operands[1]);
2729 return "lhu\t%0,%1";
2731 operands[1] = gen_lowpart (SImode, operands[1]);
2732 return "lwu\t%0,%1";
2734 return "andi\t%0,%1,%x2";
2736 len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
2737 operands[2] = GEN_INT (len);
2738 return "<d>ext\t%0,%1,0,%2";
2742 return "and\t%0,%1,%2";
2747 [(set_attr "move_type" "load,load,load,andi,ext_ins,shift_shift,logical")
2748 (set_attr "mode" "<MODE>")])
2750 (define_insn "*and<mode>3_mips16"
2751 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
2752 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%o,o,W,d,0")
2753 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
2754 "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
2756 switch (which_alternative)
2759 operands[1] = gen_lowpart (QImode, operands[1]);
2760 return "lbu\t%0,%1";
2762 operands[1] = gen_lowpart (HImode, operands[1]);
2763 return "lhu\t%0,%1";
2765 operands[1] = gen_lowpart (SImode, operands[1]);
2766 return "lwu\t%0,%1";
2770 return "and\t%0,%2";
2775 [(set_attr "move_type" "load,load,load,shift_shift,logical")
2776 (set_attr "mode" "<MODE>")])
2778 (define_expand "ior<mode>3"
2779 [(set (match_operand:GPR 0 "register_operand")
2780 (ior:GPR (match_operand:GPR 1 "register_operand")
2781 (match_operand:GPR 2 "uns_arith_operand")))]
2785 operands[2] = force_reg (<MODE>mode, operands[2]);
2788 (define_insn "*ior<mode>3"
2789 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2790 (ior:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2791 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2796 [(set_attr "alu_type" "or")
2797 (set_attr "mode" "<MODE>")])
2799 (define_insn "*ior<mode>3_mips16"
2800 [(set (match_operand:GPR 0 "register_operand" "=d")
2801 (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
2802 (match_operand:GPR 2 "register_operand" "d")))]
2805 [(set_attr "alu_type" "or")
2806 (set_attr "mode" "<MODE>")])
2808 (define_expand "xor<mode>3"
2809 [(set (match_operand:GPR 0 "register_operand")
2810 (xor:GPR (match_operand:GPR 1 "register_operand")
2811 (match_operand:GPR 2 "uns_arith_operand")))]
2816 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2817 (xor:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2818 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2823 [(set_attr "alu_type" "xor")
2824 (set_attr "mode" "<MODE>")])
2827 [(set (match_operand:GPR 0 "register_operand" "=d,t,t")
2828 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
2829 (match_operand:GPR 2 "uns_arith_operand" "d,K,d")))]
2835 [(set_attr "alu_type" "xor")
2836 (set_attr "mode" "<MODE>")
2837 (set_attr_alternative "length"
2839 (if_then_else (match_operand:VOID 2 "m16_uimm8_1")
2844 (define_insn "*nor<mode>3"
2845 [(set (match_operand:GPR 0 "register_operand" "=d")
2846 (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
2847 (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
2850 [(set_attr "alu_type" "nor")
2851 (set_attr "mode" "<MODE>")])
2854 ;; ....................
2858 ;; ....................
2862 (define_insn "truncdfsf2"
2863 [(set (match_operand:SF 0 "register_operand" "=f")
2864 (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
2865 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2867 [(set_attr "type" "fcvt")
2868 (set_attr "cnv_mode" "D2S")
2869 (set_attr "mode" "SF")])
2871 ;; Integer truncation patterns. Truncating SImode values to smaller
2872 ;; modes is a no-op, as it is for most other GCC ports. Truncating
2873 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
2874 ;; need to make sure that the lower 32 bits are properly sign-extended
2875 ;; (see TRULY_NOOP_TRUNCATION). Truncating DImode values into modes
2876 ;; smaller than SImode is equivalent to two separate truncations:
2879 ;; DI ---> HI == DI ---> SI ---> HI
2880 ;; DI ---> QI == DI ---> SI ---> QI
2882 ;; Step A needs a real instruction but step B does not.
2884 (define_insn "truncdi<mode>2"
2885 [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
2886 (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
2891 [(set_attr "move_type" "sll0,store")
2892 (set_attr "mode" "SI")])
2894 ;; Combiner patterns to optimize shift/truncate combinations.
2896 (define_insn "*ashr_trunc<mode>"
2897 [(set (match_operand:SUBDI 0 "register_operand" "=d")
2899 (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
2900 (match_operand:DI 2 "const_arith_operand" ""))))]
2901 "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
2903 [(set_attr "type" "shift")
2904 (set_attr "mode" "<MODE>")])
2906 (define_insn "*lshr32_trunc<mode>"
2907 [(set (match_operand:SUBDI 0 "register_operand" "=d")
2909 (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
2911 "TARGET_64BIT && !TARGET_MIPS16"
2913 [(set_attr "type" "shift")
2914 (set_attr "mode" "<MODE>")])
2916 ;; Logical shift by more than 32 results in proper SI values so truncation is
2917 ;; removed by the middle end. Note that a logical shift by 32 is handled by
2918 ;; the previous pattern.
2919 (define_insn "*<optab>_trunc<mode>_exts"
2920 [(set (match_operand:SUBDI 0 "register_operand" "=d")
2922 (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
2923 (match_operand:DI 2 "const_arith_operand" ""))))]
2924 "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
2926 [(set_attr "type" "arith")
2927 (set_attr "mode" "<MODE>")])
2930 ;; ....................
2934 ;; ....................
2938 (define_expand "zero_extendsidi2"
2939 [(set (match_operand:DI 0 "register_operand")
2940 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
2943 (define_insn_and_split "*zero_extendsidi2"
2944 [(set (match_operand:DI 0 "register_operand" "=d,d")
2945 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
2946 "TARGET_64BIT && !ISA_HAS_EXT_INS"
2950 "&& reload_completed && REG_P (operands[1])"
2952 (ashift:DI (match_dup 1) (const_int 32)))
2954 (lshiftrt:DI (match_dup 0) (const_int 32)))]
2955 { operands[1] = gen_lowpart (DImode, operands[1]); }
2956 [(set_attr "move_type" "shift_shift,load")
2957 (set_attr "mode" "DI")])
2959 (define_insn "*zero_extendsidi2_dext"
2960 [(set (match_operand:DI 0 "register_operand" "=d,d")
2961 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
2962 "TARGET_64BIT && ISA_HAS_EXT_INS"
2966 [(set_attr "move_type" "arith,load")
2967 (set_attr "mode" "DI")])
2969 ;; See the comment before the *and<mode>3 pattern why this is generated by
2973 [(set (match_operand:DI 0 "register_operand")
2974 (and:DI (match_operand:DI 1 "register_operand")
2975 (const_int 4294967295)))]
2976 "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
2978 (ashift:DI (match_dup 1) (const_int 32)))
2980 (lshiftrt:DI (match_dup 0) (const_int 32)))])
2982 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
2983 [(set (match_operand:GPR 0 "register_operand")
2984 (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
2987 if (TARGET_MIPS16 && !GENERATE_MIPS16E
2988 && !memory_operand (operands[1], <SHORT:MODE>mode))
2990 emit_insn (gen_and<GPR:mode>3 (operands[0],
2991 gen_lowpart (<GPR:MODE>mode, operands[1]),
2992 force_reg (<GPR:MODE>mode,
2993 GEN_INT (<SHORT:mask>))));
2998 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
2999 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3001 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3004 andi\t%0,%1,<SHORT:mask>
3005 l<SHORT:size>u\t%0,%1"
3006 [(set_attr "move_type" "andi,load")
3007 (set_attr "mode" "<GPR:MODE>")])
3009 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3010 [(set (match_operand:GPR 0 "register_operand" "=d")
3011 (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3013 "ze<SHORT:size>\t%0"
3014 ;; This instruction is effectively a special encoding of ANDI.
3015 [(set_attr "move_type" "andi")
3016 (set_attr "mode" "<GPR:MODE>")])
3018 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3019 [(set (match_operand:GPR 0 "register_operand" "=d")
3020 (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3022 "l<SHORT:size>u\t%0,%1"
3023 [(set_attr "move_type" "load")
3024 (set_attr "mode" "<GPR:MODE>")])
3026 (define_expand "zero_extendqihi2"
3027 [(set (match_operand:HI 0 "register_operand")
3028 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3031 if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3033 emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3039 (define_insn "*zero_extendqihi2"
3040 [(set (match_operand:HI 0 "register_operand" "=d,d")
3041 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3046 [(set_attr "move_type" "andi,load")
3047 (set_attr "mode" "HI")])
3049 (define_insn "*zero_extendqihi2_mips16"
3050 [(set (match_operand:HI 0 "register_operand" "=d")
3051 (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3054 [(set_attr "move_type" "load")
3055 (set_attr "mode" "HI")])
3057 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3059 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3060 [(set (match_operand:GPR 0 "register_operand" "=d")
3062 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3063 "TARGET_64BIT && !TARGET_MIPS16"
3065 operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3066 return "andi\t%0,%1,%x2";
3068 [(set_attr "alu_type" "and")
3069 (set_attr "mode" "<GPR:MODE>")])
3071 (define_insn "*zero_extendhi_truncqi"
3072 [(set (match_operand:HI 0 "register_operand" "=d")
3074 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3075 "TARGET_64BIT && !TARGET_MIPS16"
3077 [(set_attr "alu_type" "and")
3078 (set_attr "mode" "HI")])
3081 ;; ....................
3085 ;; ....................
3088 ;; Those for integer source operand are ordered widest source type first.
3090 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3091 ;; should already be in sign-extended form (see TRULY_NOOP_TRUNCATION
3092 ;; and truncdisi2). We can therefore get rid of register->register
3093 ;; instructions if we constrain the source to be in the same register as
3096 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3097 ;; we split them into nothing before the post-reload scheduler runs.
3098 ;; These alternatives therefore have type "move" in order to reflect
3099 ;; what happens if the two pre-reload operands cannot be tied, and are
3100 ;; instead allocated two separate GPRs. We don't distinguish between
3101 ;; the GPR and LO cases because we don't usually know during pre-reload
3102 ;; scheduling whether an operand will be LO or not.
3103 (define_insn_and_split "extendsidi2"
3104 [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3105 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3111 "&& reload_completed && register_operand (operands[1], VOIDmode)"
3114 emit_note (NOTE_INSN_DELETED);
3117 [(set_attr "move_type" "move,move,load")
3118 (set_attr "mode" "DI")])
3120 (define_expand "extend<SHORT:mode><GPR:mode>2"
3121 [(set (match_operand:GPR 0 "register_operand")
3122 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3125 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3126 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3127 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3131 l<SHORT:size>\t%0,%1"
3132 [(set_attr "move_type" "signext,load")
3133 (set_attr "mode" "<GPR:MODE>")])
3135 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3136 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3138 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3139 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3142 l<SHORT:size>\t%0,%1"
3143 "&& reload_completed && REG_P (operands[1])"
3144 [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3145 (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3147 operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3148 operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3149 - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3151 [(set_attr "move_type" "shift_shift,load")
3152 (set_attr "mode" "<GPR:MODE>")])
3154 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3155 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3157 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3160 se<SHORT:size>\t%0,%1
3161 l<SHORT:size>\t%0,%1"
3162 [(set_attr "move_type" "signext,load")
3163 (set_attr "mode" "<GPR:MODE>")])
3165 (define_expand "extendqihi2"
3166 [(set (match_operand:HI 0 "register_operand")
3167 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3170 (define_insn "*extendqihi2_mips16e"
3171 [(set (match_operand:HI 0 "register_operand" "=d,d")
3172 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3177 [(set_attr "move_type" "signext,load")
3178 (set_attr "mode" "SI")])
3180 (define_insn_and_split "*extendqihi2"
3181 [(set (match_operand:HI 0 "register_operand" "=d,d")
3183 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3184 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3188 "&& reload_completed && REG_P (operands[1])"
3189 [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3190 (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3192 operands[0] = gen_lowpart (SImode, operands[0]);
3193 operands[1] = gen_lowpart (SImode, operands[1]);
3194 operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3195 - GET_MODE_BITSIZE (QImode));
3197 [(set_attr "move_type" "shift_shift,load")
3198 (set_attr "mode" "SI")])
3200 (define_insn "*extendqihi2_seb"
3201 [(set (match_operand:HI 0 "register_operand" "=d,d")
3203 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3208 [(set_attr "move_type" "signext,load")
3209 (set_attr "mode" "SI")])
3211 ;; Combiner patterns for truncate/sign_extend combinations. The SI versions
3212 ;; use the shift/truncate patterns.
3214 (define_insn_and_split "*extenddi_truncate<mode>"
3215 [(set (match_operand:DI 0 "register_operand" "=d")
3217 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3218 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3220 "&& reload_completed"
3222 (ashift:DI (match_dup 1)
3225 (ashiftrt:DI (match_dup 2)
3228 operands[2] = gen_lowpart (DImode, operands[0]);
3229 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3231 [(set_attr "move_type" "shift_shift")
3232 (set_attr "mode" "DI")])
3234 (define_insn_and_split "*extendsi_truncate<mode>"
3235 [(set (match_operand:SI 0 "register_operand" "=d")
3237 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3238 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3240 "&& reload_completed"
3242 (ashift:DI (match_dup 1)
3245 (truncate:SI (ashiftrt:DI (match_dup 2)
3248 operands[2] = gen_lowpart (DImode, operands[0]);
3249 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3251 [(set_attr "move_type" "shift_shift")
3252 (set_attr "mode" "SI")])
3254 (define_insn_and_split "*extendhi_truncateqi"
3255 [(set (match_operand:HI 0 "register_operand" "=d")
3257 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3258 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3260 "&& reload_completed"
3262 (ashift:DI (match_dup 1)
3265 (truncate:HI (ashiftrt:DI (match_dup 2)
3268 operands[2] = gen_lowpart (DImode, operands[0]);
3270 [(set_attr "move_type" "shift_shift")
3271 (set_attr "mode" "SI")])
3273 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3274 [(set (match_operand:GPR 0 "register_operand" "=d")
3276 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3277 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3279 operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3280 return "exts\t%0,%1,0,%m2";
3282 [(set_attr "type" "arith")
3283 (set_attr "mode" "<GPR:MODE>")])
3285 (define_insn "*extendhi_truncateqi_exts"
3286 [(set (match_operand:HI 0 "register_operand" "=d")
3288 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3289 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3291 [(set_attr "type" "arith")
3292 (set_attr "mode" "SI")])
3294 (define_insn "extendsfdf2"
3295 [(set (match_operand:DF 0 "register_operand" "=f")
3296 (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3297 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3299 [(set_attr "type" "fcvt")
3300 (set_attr "cnv_mode" "S2D")
3301 (set_attr "mode" "DF")])
3304 ;; ....................
3308 ;; ....................
3310 (define_expand "fix_truncdfsi2"
3311 [(set (match_operand:SI 0 "register_operand")
3312 (fix:SI (match_operand:DF 1 "register_operand")))]
3313 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3315 if (!ISA_HAS_TRUNC_W)
3317 emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3322 (define_insn "fix_truncdfsi2_insn"
3323 [(set (match_operand:SI 0 "register_operand" "=f")
3324 (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3325 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3327 [(set_attr "type" "fcvt")
3328 (set_attr "mode" "DF")
3329 (set_attr "cnv_mode" "D2I")])
3331 (define_insn "fix_truncdfsi2_macro"
3332 [(set (match_operand:SI 0 "register_operand" "=f")
3333 (fix:SI (match_operand:DF 1 "register_operand" "f")))
3334 (clobber (match_scratch:DF 2 "=d"))]
3335 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3337 if (mips_nomacro.nesting_level > 0)
3338 return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3340 return "trunc.w.d %0,%1,%2";
3342 [(set_attr "type" "fcvt")
3343 (set_attr "mode" "DF")
3344 (set_attr "cnv_mode" "D2I")
3345 (set_attr "length" "36")])
3347 (define_expand "fix_truncsfsi2"
3348 [(set (match_operand:SI 0 "register_operand")
3349 (fix:SI (match_operand:SF 1 "register_operand")))]
3352 if (!ISA_HAS_TRUNC_W)
3354 emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3359 (define_insn "fix_truncsfsi2_insn"
3360 [(set (match_operand:SI 0 "register_operand" "=f")
3361 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3362 "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3364 [(set_attr "type" "fcvt")
3365 (set_attr "mode" "SF")
3366 (set_attr "cnv_mode" "S2I")])
3368 (define_insn "fix_truncsfsi2_macro"
3369 [(set (match_operand:SI 0 "register_operand" "=f")
3370 (fix:SI (match_operand:SF 1 "register_operand" "f")))
3371 (clobber (match_scratch:SF 2 "=d"))]
3372 "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
3374 if (mips_nomacro.nesting_level > 0)
3375 return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
3377 return "trunc.w.s %0,%1,%2";
3379 [(set_attr "type" "fcvt")
3380 (set_attr "mode" "SF")
3381 (set_attr "cnv_mode" "S2I")
3382 (set_attr "length" "36")])
3385 (define_insn "fix_truncdfdi2"
3386 [(set (match_operand:DI 0 "register_operand" "=f")
3387 (fix:DI (match_operand:DF 1 "register_operand" "f")))]
3388 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3390 [(set_attr "type" "fcvt")
3391 (set_attr "mode" "DF")
3392 (set_attr "cnv_mode" "D2I")])
3395 (define_insn "fix_truncsfdi2"
3396 [(set (match_operand:DI 0 "register_operand" "=f")
3397 (fix:DI (match_operand:SF 1 "register_operand" "f")))]
3398 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3400 [(set_attr "type" "fcvt")
3401 (set_attr "mode" "SF")
3402 (set_attr "cnv_mode" "S2I")])
3405 (define_insn "floatsidf2"
3406 [(set (match_operand:DF 0 "register_operand" "=f")
3407 (float:DF (match_operand:SI 1 "register_operand" "f")))]
3408 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3410 [(set_attr "type" "fcvt")
3411 (set_attr "mode" "DF")
3412 (set_attr "cnv_mode" "I2D")])
3415 (define_insn "floatdidf2"
3416 [(set (match_operand:DF 0 "register_operand" "=f")
3417 (float:DF (match_operand:DI 1 "register_operand" "f")))]
3418 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3420 [(set_attr "type" "fcvt")
3421 (set_attr "mode" "DF")
3422 (set_attr "cnv_mode" "I2D")])
3425 (define_insn "floatsisf2"
3426 [(set (match_operand:SF 0 "register_operand" "=f")
3427 (float:SF (match_operand:SI 1 "register_operand" "f")))]
3430 [(set_attr "type" "fcvt")
3431 (set_attr "mode" "SF")
3432 (set_attr "cnv_mode" "I2S")])
3435 (define_insn "floatdisf2"
3436 [(set (match_operand:SF 0 "register_operand" "=f")
3437 (float:SF (match_operand:DI 1 "register_operand" "f")))]
3438 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3440 [(set_attr "type" "fcvt")
3441 (set_attr "mode" "SF")
3442 (set_attr "cnv_mode" "I2S")])
3445 (define_expand "fixuns_truncdfsi2"
3446 [(set (match_operand:SI 0 "register_operand")
3447 (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
3448 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3450 rtx reg1 = gen_reg_rtx (DFmode);
3451 rtx reg2 = gen_reg_rtx (DFmode);
3452 rtx reg3 = gen_reg_rtx (SImode);
3453 rtx label1 = gen_label_rtx ();
3454 rtx label2 = gen_label_rtx ();
3456 REAL_VALUE_TYPE offset;
3458 real_2expN (&offset, 31, DFmode);
3460 if (reg1) /* Turn off complaints about unreached code. */
3462 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3463 do_pending_stack_adjust ();
3465 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3466 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3468 emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
3469 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3470 gen_rtx_LABEL_REF (VOIDmode, label2)));
3473 emit_label (label1);
3474 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3475 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3476 (BITMASK_HIGH, SImode)));
3478 emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
3479 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3481 emit_label (label2);
3483 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3484 fields, and can't be used for REG_NOTES anyway). */
3485 emit_use (stack_pointer_rtx);
3491 (define_expand "fixuns_truncdfdi2"
3492 [(set (match_operand:DI 0 "register_operand")
3493 (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
3494 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3496 rtx reg1 = gen_reg_rtx (DFmode);
3497 rtx reg2 = gen_reg_rtx (DFmode);
3498 rtx reg3 = gen_reg_rtx (DImode);
3499 rtx label1 = gen_label_rtx ();
3500 rtx label2 = gen_label_rtx ();
3502 REAL_VALUE_TYPE offset;
3504 real_2expN (&offset, 63, DFmode);
3506 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3507 do_pending_stack_adjust ();
3509 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3510 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3512 emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
3513 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3514 gen_rtx_LABEL_REF (VOIDmode, label2)));
3517 emit_label (label1);
3518 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3519 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3520 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3522 emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
3523 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3525 emit_label (label2);
3527 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3528 fields, and can't be used for REG_NOTES anyway). */
3529 emit_use (stack_pointer_rtx);
3534 (define_expand "fixuns_truncsfsi2"
3535 [(set (match_operand:SI 0 "register_operand")
3536 (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
3539 rtx reg1 = gen_reg_rtx (SFmode);
3540 rtx reg2 = gen_reg_rtx (SFmode);
3541 rtx reg3 = gen_reg_rtx (SImode);
3542 rtx label1 = gen_label_rtx ();
3543 rtx label2 = gen_label_rtx ();
3545 REAL_VALUE_TYPE offset;
3547 real_2expN (&offset, 31, SFmode);
3549 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3550 do_pending_stack_adjust ();
3552 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3553 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3555 emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
3556 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3557 gen_rtx_LABEL_REF (VOIDmode, label2)));
3560 emit_label (label1);
3561 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3562 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3563 (BITMASK_HIGH, SImode)));
3565 emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
3566 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3568 emit_label (label2);
3570 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3571 fields, and can't be used for REG_NOTES anyway). */
3572 emit_use (stack_pointer_rtx);
3577 (define_expand "fixuns_truncsfdi2"
3578 [(set (match_operand:DI 0 "register_operand")
3579 (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
3580 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3582 rtx reg1 = gen_reg_rtx (SFmode);
3583 rtx reg2 = gen_reg_rtx (SFmode);
3584 rtx reg3 = gen_reg_rtx (DImode);
3585 rtx label1 = gen_label_rtx ();
3586 rtx label2 = gen_label_rtx ();
3588 REAL_VALUE_TYPE offset;
3590 real_2expN (&offset, 63, SFmode);
3592 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3593 do_pending_stack_adjust ();
3595 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3596 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3598 emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
3599 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3600 gen_rtx_LABEL_REF (VOIDmode, label2)));
3603 emit_label (label1);
3604 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3605 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3606 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3608 emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
3609 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3611 emit_label (label2);
3613 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3614 fields, and can't be used for REG_NOTES anyway). */
3615 emit_use (stack_pointer_rtx);
3620 ;; ....................
3624 ;; ....................
3626 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
3628 (define_expand "extv"
3629 [(set (match_operand 0 "register_operand")
3630 (sign_extract (match_operand 1 "nonimmediate_operand")
3631 (match_operand 2 "const_int_operand")
3632 (match_operand 3 "const_int_operand")))]
3635 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3636 INTVAL (operands[2]),
3637 INTVAL (operands[3])))
3639 else if (register_operand (operands[1], GET_MODE (operands[0]))
3640 && ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32)
3642 if (GET_MODE (operands[0]) == DImode)
3643 emit_insn (gen_extvdi (operands[0], operands[1], operands[2],
3646 emit_insn (gen_extvsi (operands[0], operands[1], operands[2],
3654 (define_insn "extv<mode>"
3655 [(set (match_operand:GPR 0 "register_operand" "=d")
3656 (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3657 (match_operand 2 "const_int_operand" "")
3658 (match_operand 3 "const_int_operand" "")))]
3659 "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
3660 "exts\t%0,%1,%3,%m2"
3661 [(set_attr "type" "arith")
3662 (set_attr "mode" "<MODE>")])
3665 (define_expand "extzv"
3666 [(set (match_operand 0 "register_operand")
3667 (zero_extract (match_operand 1 "nonimmediate_operand")
3668 (match_operand 2 "const_int_operand")
3669 (match_operand 3 "const_int_operand")))]
3672 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3673 INTVAL (operands[2]),
3674 INTVAL (operands[3])))
3676 else if (mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3677 INTVAL (operands[3])))
3679 if (GET_MODE (operands[0]) == DImode)
3680 emit_insn (gen_extzvdi (operands[0], operands[1], operands[2],
3683 emit_insn (gen_extzvsi (operands[0], operands[1], operands[2],
3691 (define_insn "extzv<mode>"
3692 [(set (match_operand:GPR 0 "register_operand" "=d")
3693 (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3694 (match_operand 2 "const_int_operand" "")
3695 (match_operand 3 "const_int_operand" "")))]
3696 "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3697 INTVAL (operands[3]))"
3698 "<d>ext\t%0,%1,%3,%2"
3699 [(set_attr "type" "arith")
3700 (set_attr "mode" "<MODE>")])
3702 (define_insn "*extzv_truncsi_exts"
3703 [(set (match_operand:SI 0 "register_operand" "=d")
3705 (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
3706 (match_operand 2 "const_int_operand" "")
3707 (match_operand 3 "const_int_operand" ""))))]
3708 "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3710 [(set_attr "type" "arith")
3711 (set_attr "mode" "SI")])
3714 (define_expand "insv"
3715 [(set (zero_extract (match_operand 0 "nonimmediate_operand")
3716 (match_operand 1 "immediate_operand")
3717 (match_operand 2 "immediate_operand"))
3718 (match_operand 3 "reg_or_0_operand"))]
3721 if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
3722 INTVAL (operands[1]),
3723 INTVAL (operands[2])))
3725 else if (mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3726 INTVAL (operands[2])))
3728 if (GET_MODE (operands[0]) == DImode)
3729 emit_insn (gen_insvdi (operands[0], operands[1], operands[2],
3732 emit_insn (gen_insvsi (operands[0], operands[1], operands[2],
3740 (define_insn "insv<mode>"
3741 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
3742 (match_operand:SI 1 "immediate_operand" "I")
3743 (match_operand:SI 2 "immediate_operand" "I"))
3744 (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
3745 "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3746 INTVAL (operands[2]))"
3747 "<d>ins\t%0,%z3,%2,%1"
3748 [(set_attr "type" "arith")
3749 (set_attr "mode" "<MODE>")])
3751 ;; Combiner pattern for cins (clear and insert bit field). We can
3752 ;; implement mask-and-shift-left operation with this. Note that if
3753 ;; the upper bit of the mask is set in an SImode operation, the mask
3754 ;; itself will be sign-extended. mask_low_and_shift_len will
3755 ;; therefore be greater than our threshold of 32.
3757 (define_insn "*cins<mode>"
3758 [(set (match_operand:GPR 0 "register_operand" "=d")
3760 (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
3761 (match_operand:GPR 2 "const_int_operand" ""))
3762 (match_operand:GPR 3 "const_int_operand" "")))]
3764 && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
3767 GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
3768 return "cins\t%0,%1,%2,%m3";
3770 [(set_attr "type" "shift")
3771 (set_attr "mode" "<MODE>")])
3773 ;; Unaligned word moves generated by the bit field patterns.
3775 ;; As far as the rtl is concerned, both the left-part and right-part
3776 ;; instructions can access the whole field. However, the real operand
3777 ;; refers to just the first or the last byte (depending on endianness).
3778 ;; We therefore use two memory operands to each instruction, one to
3779 ;; describe the rtl effect and one to use in the assembly output.
3781 ;; Operands 0 and 1 are the rtl-level target and source respectively.
3782 ;; This allows us to use the standard length calculations for the "load"
3783 ;; and "store" type attributes.
3785 (define_insn "mov_<load>l"
3786 [(set (match_operand:GPR 0 "register_operand" "=d")
3787 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3788 (match_operand:QI 2 "memory_operand" "m")]
3790 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3792 [(set_attr "move_type" "load")
3793 (set_attr "mode" "<MODE>")])
3795 (define_insn "mov_<load>r"
3796 [(set (match_operand:GPR 0 "register_operand" "=d")
3797 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3798 (match_operand:QI 2 "memory_operand" "m")
3799 (match_operand:GPR 3 "register_operand" "0")]
3800 UNSPEC_LOAD_RIGHT))]
3801 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3803 [(set_attr "move_type" "load")
3804 (set_attr "mode" "<MODE>")])
3806 (define_insn "mov_<store>l"
3807 [(set (match_operand:BLK 0 "memory_operand" "=m")
3808 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3809 (match_operand:QI 2 "memory_operand" "m")]
3810 UNSPEC_STORE_LEFT))]
3811 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3813 [(set_attr "move_type" "store")
3814 (set_attr "mode" "<MODE>")])
3816 (define_insn "mov_<store>r"
3817 [(set (match_operand:BLK 0 "memory_operand" "+m")
3818 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3819 (match_operand:QI 2 "memory_operand" "m")
3821 UNSPEC_STORE_RIGHT))]
3822 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3824 [(set_attr "move_type" "store")
3825 (set_attr "mode" "<MODE>")])
3827 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
3828 ;; The required value is:
3830 ;; (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
3832 ;; which translates to:
3834 ;; lui op0,%highest(op1)
3835 ;; daddiu op0,op0,%higher(op1)
3837 ;; daddiu op0,op0,%hi(op1)
3840 ;; The split is deferred until after flow2 to allow the peephole2 below
3842 (define_insn_and_split "*lea_high64"
3843 [(set (match_operand:DI 0 "register_operand" "=d")
3844 (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
3845 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3847 "&& epilogue_completed"
3848 [(set (match_dup 0) (high:DI (match_dup 2)))
3849 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
3850 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
3851 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3852 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
3854 operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3855 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
3857 [(set_attr "length" "20")])
3859 ;; Use a scratch register to reduce the latency of the above pattern
3860 ;; on superscalar machines. The optimized sequence is:
3862 ;; lui op1,%highest(op2)
3864 ;; daddiu op1,op1,%higher(op2)
3866 ;; daddu op1,op1,op0
3868 [(set (match_operand:DI 1 "d_operand")
3869 (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
3870 (match_scratch:DI 0 "d")]
3871 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3872 [(set (match_dup 1) (high:DI (match_dup 3)))
3873 (set (match_dup 0) (high:DI (match_dup 4)))
3874 (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
3875 (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
3876 (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
3878 operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
3879 operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
3882 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
3883 ;; SYMBOL_ABSOLUTE X will take 6 cycles. This next pattern allows combine
3884 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
3885 ;; used once. We can then use the sequence:
3887 ;; lui op0,%highest(op1)
3889 ;; daddiu op0,op0,%higher(op1)
3890 ;; daddiu op2,op2,%lo(op1)
3892 ;; daddu op0,op0,op2
3894 ;; which takes 4 cycles on most superscalar targets.
3895 (define_insn_and_split "*lea64"
3896 [(set (match_operand:DI 0 "register_operand" "=d")
3897 (match_operand:DI 1 "absolute_symbolic_operand" ""))
3898 (clobber (match_scratch:DI 2 "=&d"))]
3899 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS && cse_not_expected"
3901 "&& reload_completed"
3902 [(set (match_dup 0) (high:DI (match_dup 3)))
3903 (set (match_dup 2) (high:DI (match_dup 4)))
3904 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3905 (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
3906 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
3907 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
3909 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3910 operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
3912 [(set_attr "length" "24")])
3914 ;; Split HIGHs into:
3919 ;; on MIPS16 targets.
3921 [(set (match_operand:SI 0 "d_operand")
3922 (high:SI (match_operand:SI 1 "absolute_symbolic_operand")))]
3923 "TARGET_MIPS16 && reload_completed"
3924 [(set (match_dup 0) (match_dup 2))
3925 (set (match_dup 0) (ashift:SI (match_dup 0) (const_int 16)))]
3927 operands[2] = mips_unspec_address (operands[1], SYMBOL_32_HIGH);
3930 ;; Insns to fetch a symbol from a big GOT.
3932 (define_insn_and_split "*xgot_hi<mode>"
3933 [(set (match_operand:P 0 "register_operand" "=d")
3934 (high:P (match_operand:P 1 "got_disp_operand" "")))]
3935 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
3937 "&& reload_completed"
3938 [(set (match_dup 0) (high:P (match_dup 2)))
3939 (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
3941 operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
3942 operands[3] = pic_offset_table_rtx;
3944 [(set_attr "got" "xgot_high")
3945 (set_attr "mode" "<MODE>")])
3947 (define_insn_and_split "*xgot_lo<mode>"
3948 [(set (match_operand:P 0 "register_operand" "=d")
3949 (lo_sum:P (match_operand:P 1 "register_operand" "d")
3950 (match_operand:P 2 "got_disp_operand" "")))]
3951 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
3953 "&& reload_completed"
3955 (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
3956 { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
3957 [(set_attr "got" "load")
3958 (set_attr "mode" "<MODE>")])
3960 ;; Insns to fetch a symbol from a normal GOT.
3962 (define_insn_and_split "*got_disp<mode>"
3963 [(set (match_operand:P 0 "register_operand" "=d")
3964 (match_operand:P 1 "got_disp_operand" ""))]
3965 "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
3967 "&& reload_completed"
3968 [(set (match_dup 0) (match_dup 2))]
3969 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
3970 [(set_attr "got" "load")
3971 (set_attr "mode" "<MODE>")])
3973 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
3975 (define_insn_and_split "*got_page<mode>"
3976 [(set (match_operand:P 0 "register_operand" "=d")
3977 (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
3978 "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
3980 "&& reload_completed"
3981 [(set (match_dup 0) (match_dup 2))]
3982 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
3983 [(set_attr "got" "load")
3984 (set_attr "mode" "<MODE>")])
3986 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
3987 (define_expand "unspec_got_<mode>"
3988 [(unspec:P [(match_operand:P 0)
3989 (match_operand:P 1)] UNSPEC_LOAD_GOT)])
3991 ;; Lower-level instructions for loading an address from the GOT.
3992 ;; We could use MEMs, but an unspec gives more optimization
3995 (define_insn "load_got<mode>"
3996 [(set (match_operand:P 0 "register_operand" "=d")
3997 (unspec:P [(match_operand:P 1 "register_operand" "d")
3998 (match_operand:P 2 "immediate_operand" "")]
4001 "<load>\t%0,%R2(%1)"
4002 [(set_attr "got" "load")
4003 (set_attr "mode" "<MODE>")])
4005 ;; Instructions for adding the low 16 bits of an address to a register.
4006 ;; Operand 2 is the address: mips_print_operand works out which relocation
4007 ;; should be applied.
4009 (define_insn "*low<mode>"
4010 [(set (match_operand:P 0 "register_operand" "=d")
4011 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4012 (match_operand:P 2 "immediate_operand" "")))]
4014 "<d>addiu\t%0,%1,%R2"
4015 [(set_attr "alu_type" "add")
4016 (set_attr "mode" "<MODE>")])
4018 (define_insn "*low<mode>_mips16"
4019 [(set (match_operand:P 0 "register_operand" "=d")
4020 (lo_sum:P (match_operand:P 1 "register_operand" "0")
4021 (match_operand:P 2 "immediate_operand" "")))]
4024 [(set_attr "alu_type" "add")
4025 (set_attr "mode" "<MODE>")
4026 (set_attr "extended_mips16" "yes")])
4028 ;; Expose MIPS16 uses of the global pointer after reload if the function
4029 ;; is responsible for setting up the register itself.
4031 [(set (match_operand:GPR 0 "d_operand")
4032 (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4033 "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4034 [(set (match_dup 0) (match_dup 1))]
4035 { operands[1] = pic_offset_table_rtx; })
4037 ;; Allow combine to split complex const_int load sequences, using operand 2
4038 ;; to store the intermediate results. See move_operand for details.
4040 [(set (match_operand:GPR 0 "register_operand")
4041 (match_operand:GPR 1 "splittable_const_int_operand"))
4042 (clobber (match_operand:GPR 2 "register_operand"))]
4046 mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4050 ;; Likewise, for symbolic operands.
4052 [(set (match_operand:P 0 "register_operand")
4053 (match_operand:P 1))
4054 (clobber (match_operand:P 2 "register_operand"))]
4055 "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4056 [(set (match_dup 0) (match_dup 3))]
4058 mips_split_symbol (operands[2], operands[1],
4059 MAX_MACHINE_MODE, &operands[3]);
4062 ;; 64-bit integer moves
4064 ;; Unlike most other insns, the move insns can't be split with
4065 ;; different predicates, because register spilling and other parts of
4066 ;; the compiler, have memoized the insn number already.
4068 (define_expand "movdi"
4069 [(set (match_operand:DI 0 "")
4070 (match_operand:DI 1 ""))]
4073 if (mips_legitimize_move (DImode, operands[0], operands[1]))
4077 ;; For mips16, we need a special case to handle storing $31 into
4078 ;; memory, since we don't have a constraint to match $31. This
4079 ;; instruction can be generated by save_restore_insns.
4081 (define_insn "*mov<mode>_ra"
4082 [(set (match_operand:GPR 0 "stack_operand" "=m")
4083 (reg:GPR RETURN_ADDR_REGNUM))]
4086 [(set_attr "move_type" "store")
4087 (set_attr "mode" "<MODE>")])
4089 (define_insn "*movdi_32bit"
4090 [(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")
4091 (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"))]
4092 "!TARGET_64BIT && !TARGET_MIPS16
4093 && (register_operand (operands[0], DImode)
4094 || reg_or_0_operand (operands[1], DImode))"
4095 { return mips_output_move (operands[0], operands[1]); }
4096 [(set_attr "move_type" "move,const,load,store,mthilo,mfhilo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4097 (set_attr "mode" "DI")])
4099 (define_insn "*movdi_32bit_mips16"
4100 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4101 (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4102 "!TARGET_64BIT && TARGET_MIPS16
4103 && (register_operand (operands[0], DImode)
4104 || register_operand (operands[1], DImode))"
4105 { return mips_output_move (operands[0], operands[1]); }
4106 [(set_attr "move_type" "move,move,move,const,constN,load,store,mfhilo")
4107 (set_attr "mode" "DI")])
4109 (define_insn "*movdi_64bit"
4110 [(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")
4111 (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"))]
4112 "TARGET_64BIT && !TARGET_MIPS16
4113 && (register_operand (operands[0], DImode)
4114 || reg_or_0_operand (operands[1], DImode))"
4115 { return mips_output_move (operands[0], operands[1]); }
4116 [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mthilo,mfhilo,mtc,fpload,mfc,fpstore")
4117 (set_attr "mode" "DI")])
4119 (define_insn "*movdi_64bit_mips16"
4120 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4121 (match_operand:DI 1 "move_operand" "d,d,y,K,N,U,kf,m,d,*a"))]
4122 "TARGET_64BIT && TARGET_MIPS16
4123 && (register_operand (operands[0], DImode)
4124 || register_operand (operands[1], DImode))"
4125 { return mips_output_move (operands[0], operands[1]); }
4126 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mfhilo")
4127 (set_attr "mode" "DI")])
4129 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4130 ;; when the original load is a 4 byte instruction but the add and the
4131 ;; load are 2 2 byte instructions.
4134 [(set (match_operand:DI 0 "d_operand")
4135 (mem:DI (plus:DI (match_dup 0)
4136 (match_operand:DI 1 "const_int_operand"))))]
4137 "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4138 && !TARGET_DEBUG_D_MODE
4139 && ((INTVAL (operands[1]) < 0
4140 && INTVAL (operands[1]) >= -0x10)
4141 || (INTVAL (operands[1]) >= 32 * 8
4142 && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4143 || (INTVAL (operands[1]) >= 0
4144 && INTVAL (operands[1]) < 32 * 8
4145 && (INTVAL (operands[1]) & 7) != 0))"
4146 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4147 (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4149 HOST_WIDE_INT val = INTVAL (operands[1]);
4152 operands[2] = const0_rtx;
4153 else if (val >= 32 * 8)
4157 operands[1] = GEN_INT (0x8 + off);
4158 operands[2] = GEN_INT (val - off - 0x8);
4164 operands[1] = GEN_INT (off);
4165 operands[2] = GEN_INT (val - off);
4169 ;; 32-bit Integer moves
4171 ;; Unlike most other insns, the move insns can't be split with
4172 ;; different predicates, because register spilling and other parts of
4173 ;; the compiler, have memoized the insn number already.
4175 (define_expand "mov<mode>"
4176 [(set (match_operand:IMOVE32 0 "")
4177 (match_operand:IMOVE32 1 ""))]
4180 if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4184 ;; The difference between these two is whether or not ints are allowed
4185 ;; in FP registers (off by default, use -mdebugh to enable).
4187 (define_insn "*mov<mode>_internal"
4188 [(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")
4189 (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"))]
4191 && (register_operand (operands[0], <MODE>mode)
4192 || reg_or_0_operand (operands[1], <MODE>mode))"
4193 { return mips_output_move (operands[0], operands[1]); }
4194 [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mfc,mtc,mthilo,mfhilo,mtc,fpload,mfc,fpstore")
4195 (set_attr "mode" "SI")])
4197 (define_insn "*mov<mode>_mips16"
4198 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4199 (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,U,kf,m,d,*a"))]
4201 && (register_operand (operands[0], <MODE>mode)
4202 || register_operand (operands[1], <MODE>mode))"
4203 { return mips_output_move (operands[0], operands[1]); }
4204 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mfhilo")
4205 (set_attr "mode" "SI")])
4207 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4208 ;; when the original load is a 4 byte instruction but the add and the
4209 ;; load are 2 2 byte instructions.
4212 [(set (match_operand:SI 0 "d_operand")
4213 (mem:SI (plus:SI (match_dup 0)
4214 (match_operand:SI 1 "const_int_operand"))))]
4215 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4216 && ((INTVAL (operands[1]) < 0
4217 && INTVAL (operands[1]) >= -0x80)
4218 || (INTVAL (operands[1]) >= 32 * 4
4219 && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4220 || (INTVAL (operands[1]) >= 0
4221 && INTVAL (operands[1]) < 32 * 4
4222 && (INTVAL (operands[1]) & 3) != 0))"
4223 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4224 (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4226 HOST_WIDE_INT val = INTVAL (operands[1]);
4229 operands[2] = const0_rtx;
4230 else if (val >= 32 * 4)
4234 operands[1] = GEN_INT (0x7c + off);
4235 operands[2] = GEN_INT (val - off - 0x7c);
4241 operands[1] = GEN_INT (off);
4242 operands[2] = GEN_INT (val - off);
4246 ;; On the mips16, we can split a load of certain constants into a load
4247 ;; and an add. This turns a 4 byte instruction into 2 2 byte
4251 [(set (match_operand:SI 0 "d_operand")
4252 (match_operand:SI 1 "const_int_operand"))]
4253 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4254 && INTVAL (operands[1]) >= 0x100
4255 && INTVAL (operands[1]) <= 0xff + 0x7f"
4256 [(set (match_dup 0) (match_dup 1))
4257 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4259 int val = INTVAL (operands[1]);
4261 operands[1] = GEN_INT (0xff);
4262 operands[2] = GEN_INT (val - 0xff);
4265 ;; This insn handles moving CCmode values. It's really just a
4266 ;; slightly simplified copy of movsi_internal2, with additional cases
4267 ;; to move a condition register to a general register and to move
4268 ;; between the general registers and the floating point registers.
4270 (define_insn "movcc"
4271 [(set (match_operand:CC 0 "nonimmediate_operand" "=d,*d,*d,*m,*d,*f,*f,*f,*m")
4272 (match_operand:CC 1 "general_operand" "z,*d,*m,*d,*f,*d,*f,*m,*f"))]
4273 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4274 { return mips_output_move (operands[0], operands[1]); }
4275 [(set_attr "move_type" "lui_movf,move,load,store,mfc,mtc,fmove,fpload,fpstore")
4276 (set_attr "mode" "SI")])
4278 ;; Reload condition code registers. reload_incc and reload_outcc
4279 ;; both handle moves from arbitrary operands into condition code
4280 ;; registers. reload_incc handles the more common case in which
4281 ;; a source operand is constrained to be in a condition-code
4282 ;; register, but has not been allocated to one.
4284 ;; Sometimes, such as in movcc, we have a CCmode destination whose
4285 ;; constraints do not include 'z'. reload_outcc handles the case
4286 ;; when such an operand is allocated to a condition-code register.
4288 ;; Note that reloads from a condition code register to some
4289 ;; other location can be done using ordinary moves. Moving
4290 ;; into a GPR takes a single movcc, moving elsewhere takes
4291 ;; two. We can leave these cases to the generic reload code.
4292 (define_expand "reload_incc"
4293 [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
4294 (match_operand:CC 1 "general_operand" ""))
4295 (clobber (match_operand:TF 2 "register_operand" "=&f"))]
4296 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4298 mips_expand_fcc_reload (operands[0], operands[1], operands[2]);
4302 (define_expand "reload_outcc"
4303 [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
4304 (match_operand:CC 1 "register_operand" ""))
4305 (clobber (match_operand:TF 2 "register_operand" "=&f"))]
4306 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4308 mips_expand_fcc_reload (operands[0], operands[1], operands[2]);
4312 ;; MIPS4 supports loading and storing a floating point register from
4313 ;; the sum of two general registers. We use two versions for each of
4314 ;; these four instructions: one where the two general registers are
4315 ;; SImode, and one where they are DImode. This is because general
4316 ;; registers will be in SImode when they hold 32-bit values, but,
4317 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4318 ;; instructions will still work correctly.
4320 ;; ??? Perhaps it would be better to support these instructions by
4321 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends. However, since
4322 ;; these instructions can only be used to load and store floating
4323 ;; point registers, that would probably cause trouble in reload.
4325 (define_insn "*<ANYF:loadx>_<P:mode>"
4326 [(set (match_operand:ANYF 0 "register_operand" "=f")
4327 (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4328 (match_operand:P 2 "register_operand" "d"))))]
4330 "<ANYF:loadx>\t%0,%1(%2)"
4331 [(set_attr "type" "fpidxload")
4332 (set_attr "mode" "<ANYF:UNITMODE>")])
4334 (define_insn "*<ANYF:storex>_<P:mode>"
4335 [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4336 (match_operand:P 2 "register_operand" "d")))
4337 (match_operand:ANYF 0 "register_operand" "f"))]
4339 "<ANYF:storex>\t%0,%1(%2)"
4340 [(set_attr "type" "fpidxstore")
4341 (set_attr "mode" "<ANYF:UNITMODE>")])
4343 ;; Scaled indexed address load.
4344 ;; Per md.texi, we only need to look for a pattern with multiply in the
4345 ;; address expression, not shift.
4347 (define_insn "*lwxs"
4348 [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4350 (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4352 (match_operand:P 2 "register_operand" "d"))))]
4355 [(set_attr "type" "load")
4356 (set_attr "mode" "SI")])
4358 ;; 16-bit Integer moves
4360 ;; Unlike most other insns, the move insns can't be split with
4361 ;; different predicates, because register spilling and other parts of
4362 ;; the compiler, have memoized the insn number already.
4363 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4365 (define_expand "movhi"
4366 [(set (match_operand:HI 0 "")
4367 (match_operand:HI 1 ""))]
4370 if (mips_legitimize_move (HImode, operands[0], operands[1]))
4374 (define_insn "*movhi_internal"
4375 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4376 (match_operand:HI 1 "move_operand" "d,I,m,dJ,*d*J,*a"))]
4378 && (register_operand (operands[0], HImode)
4379 || reg_or_0_operand (operands[1], HImode))"
4380 { return mips_output_move (operands[0], operands[1]); }
4381 [(set_attr "move_type" "move,const,load,store,mthilo,mfhilo")
4382 (set_attr "mode" "HI")])
4384 (define_insn "*movhi_mips16"
4385 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4386 (match_operand:HI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4388 && (register_operand (operands[0], HImode)
4389 || register_operand (operands[1], HImode))"
4390 { return mips_output_move (operands[0], operands[1]); }
4391 [(set_attr "move_type" "move,move,move,const,constN,load,store,mfhilo")
4392 (set_attr "mode" "HI")])
4394 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
4395 ;; when the original load is a 4 byte instruction but the add and the
4396 ;; load are 2 2 byte instructions.
4399 [(set (match_operand:HI 0 "d_operand")
4400 (mem:HI (plus:SI (match_dup 0)
4401 (match_operand:SI 1 "const_int_operand"))))]
4402 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4403 && ((INTVAL (operands[1]) < 0
4404 && INTVAL (operands[1]) >= -0x80)
4405 || (INTVAL (operands[1]) >= 32 * 2
4406 && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
4407 || (INTVAL (operands[1]) >= 0
4408 && INTVAL (operands[1]) < 32 * 2
4409 && (INTVAL (operands[1]) & 1) != 0))"
4410 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4411 (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
4413 HOST_WIDE_INT val = INTVAL (operands[1]);
4416 operands[2] = const0_rtx;
4417 else if (val >= 32 * 2)
4421 operands[1] = GEN_INT (0x7e + off);
4422 operands[2] = GEN_INT (val - off - 0x7e);
4428 operands[1] = GEN_INT (off);
4429 operands[2] = GEN_INT (val - off);
4433 ;; 8-bit Integer moves
4435 ;; Unlike most other insns, the move insns can't be split with
4436 ;; different predicates, because register spilling and other parts of
4437 ;; the compiler, have memoized the insn number already.
4438 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4440 (define_expand "movqi"
4441 [(set (match_operand:QI 0 "")
4442 (match_operand:QI 1 ""))]
4445 if (mips_legitimize_move (QImode, operands[0], operands[1]))
4449 (define_insn "*movqi_internal"
4450 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4451 (match_operand:QI 1 "move_operand" "d,I,m,dJ,*d*J,*a"))]
4453 && (register_operand (operands[0], QImode)
4454 || reg_or_0_operand (operands[1], QImode))"
4455 { return mips_output_move (operands[0], operands[1]); }
4456 [(set_attr "move_type" "move,const,load,store,mthilo,mfhilo")
4457 (set_attr "mode" "QI")])
4459 (define_insn "*movqi_mips16"
4460 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4461 (match_operand:QI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4463 && (register_operand (operands[0], QImode)
4464 || register_operand (operands[1], QImode))"
4465 { return mips_output_move (operands[0], operands[1]); }
4466 [(set_attr "move_type" "move,move,move,const,constN,load,store,mfhilo")
4467 (set_attr "mode" "QI")])
4469 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
4470 ;; when the original load is a 4 byte instruction but the add and the
4471 ;; load are 2 2 byte instructions.
4474 [(set (match_operand:QI 0 "d_operand")
4475 (mem:QI (plus:SI (match_dup 0)
4476 (match_operand:SI 1 "const_int_operand"))))]
4477 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4478 && ((INTVAL (operands[1]) < 0
4479 && INTVAL (operands[1]) >= -0x80)
4480 || (INTVAL (operands[1]) >= 32
4481 && INTVAL (operands[1]) <= 31 + 0x7f))"
4482 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4483 (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
4485 HOST_WIDE_INT val = INTVAL (operands[1]);
4488 operands[2] = const0_rtx;
4491 operands[1] = GEN_INT (0x7f);
4492 operands[2] = GEN_INT (val - 0x7f);
4496 ;; 32-bit floating point moves
4498 (define_expand "movsf"
4499 [(set (match_operand:SF 0 "")
4500 (match_operand:SF 1 ""))]
4503 if (mips_legitimize_move (SFmode, operands[0], operands[1]))
4507 (define_insn "*movsf_hardfloat"
4508 [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4509 (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
4511 && (register_operand (operands[0], SFmode)
4512 || reg_or_0_operand (operands[1], SFmode))"
4513 { return mips_output_move (operands[0], operands[1]); }
4514 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4515 (set_attr "mode" "SF")])
4517 (define_insn "*movsf_softfloat"
4518 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
4519 (match_operand:SF 1 "move_operand" "Gd,m,d"))]
4520 "TARGET_SOFT_FLOAT && !TARGET_MIPS16
4521 && (register_operand (operands[0], SFmode)
4522 || reg_or_0_operand (operands[1], SFmode))"
4523 { return mips_output_move (operands[0], operands[1]); }
4524 [(set_attr "move_type" "move,load,store")
4525 (set_attr "mode" "SF")])
4527 (define_insn "*movsf_mips16"
4528 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
4529 (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
4531 && (register_operand (operands[0], SFmode)
4532 || register_operand (operands[1], SFmode))"
4533 { return mips_output_move (operands[0], operands[1]); }
4534 [(set_attr "move_type" "move,move,move,load,store")
4535 (set_attr "mode" "SF")])
4537 ;; 64-bit floating point moves
4539 (define_expand "movdf"
4540 [(set (match_operand:DF 0 "")
4541 (match_operand:DF 1 ""))]
4544 if (mips_legitimize_move (DFmode, operands[0], operands[1]))
4548 (define_insn "*movdf_hardfloat"
4549 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4550 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
4551 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
4552 && (register_operand (operands[0], DFmode)
4553 || reg_or_0_operand (operands[1], DFmode))"
4554 { return mips_output_move (operands[0], operands[1]); }
4555 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4556 (set_attr "mode" "DF")])
4558 (define_insn "*movdf_softfloat"
4559 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
4560 (match_operand:DF 1 "move_operand" "dG,m,dG"))]
4561 "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
4562 && (register_operand (operands[0], DFmode)
4563 || reg_or_0_operand (operands[1], DFmode))"
4564 { return mips_output_move (operands[0], operands[1]); }
4565 [(set_attr "move_type" "move,load,store")
4566 (set_attr "mode" "DF")])
4568 (define_insn "*movdf_mips16"
4569 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
4570 (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
4572 && (register_operand (operands[0], DFmode)
4573 || register_operand (operands[1], DFmode))"
4574 { return mips_output_move (operands[0], operands[1]); }
4575 [(set_attr "move_type" "move,move,move,load,store")
4576 (set_attr "mode" "DF")])
4578 ;; 128-bit integer moves
4580 (define_expand "movti"
4581 [(set (match_operand:TI 0)
4582 (match_operand:TI 1))]
4585 if (mips_legitimize_move (TImode, operands[0], operands[1]))
4589 (define_insn "*movti"
4590 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4591 (match_operand:TI 1 "move_operand" "d,i,m,dJ,*d*J,*a"))]
4594 && (register_operand (operands[0], TImode)
4595 || reg_or_0_operand (operands[1], TImode))"
4597 [(set_attr "move_type" "move,const,load,store,mthilo,mfhilo")
4598 (set_attr "mode" "TI")])
4600 (define_insn "*movti_mips16"
4601 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4602 (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4605 && (register_operand (operands[0], TImode)
4606 || register_operand (operands[1], TImode))"
4608 [(set_attr "move_type" "move,move,move,const,constN,load,store,mfhilo")
4609 (set_attr "mode" "TI")])
4611 ;; 128-bit floating point moves
4613 (define_expand "movtf"
4614 [(set (match_operand:TF 0)
4615 (match_operand:TF 1))]
4618 if (mips_legitimize_move (TFmode, operands[0], operands[1]))
4622 ;; This pattern handles both hard- and soft-float cases.
4623 (define_insn "*movtf"
4624 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
4625 (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
4628 && (register_operand (operands[0], TFmode)
4629 || reg_or_0_operand (operands[1], TFmode))"
4631 [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
4632 (set_attr "mode" "TF")])
4634 (define_insn "*movtf_mips16"
4635 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
4636 (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
4639 && (register_operand (operands[0], TFmode)
4640 || register_operand (operands[1], TFmode))"
4642 [(set_attr "move_type" "move,move,move,load,store")
4643 (set_attr "mode" "TF")])
4646 [(set (match_operand:MOVE64 0 "nonimmediate_operand")
4647 (match_operand:MOVE64 1 "move_operand"))]
4648 "reload_completed && !TARGET_64BIT
4649 && mips_split_64bit_move_p (operands[0], operands[1])"
4652 mips_split_doubleword_move (operands[0], operands[1]);
4657 [(set (match_operand:MOVE128 0 "nonimmediate_operand")
4658 (match_operand:MOVE128 1 "move_operand"))]
4659 "TARGET_64BIT && reload_completed"
4662 mips_split_doubleword_move (operands[0], operands[1]);
4666 ;; When generating mips16 code, split moves of negative constants into
4667 ;; a positive "li" followed by a negation.
4669 [(set (match_operand 0 "d_operand")
4670 (match_operand 1 "const_int_operand"))]
4671 "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
4675 (neg:SI (match_dup 2)))]
4677 operands[2] = gen_lowpart (SImode, operands[0]);
4678 operands[3] = GEN_INT (-INTVAL (operands[1]));
4681 ;; 64-bit paired-single floating point moves
4683 (define_expand "movv2sf"
4684 [(set (match_operand:V2SF 0)
4685 (match_operand:V2SF 1))]
4686 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
4688 if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
4692 (define_insn "*movv2sf"
4693 [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4694 (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
4696 && TARGET_PAIRED_SINGLE_FLOAT
4697 && (register_operand (operands[0], V2SFmode)
4698 || reg_or_0_operand (operands[1], V2SFmode))"
4699 { return mips_output_move (operands[0], operands[1]); }
4700 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4701 (set_attr "mode" "DF")])
4703 ;; Extract the high part of a HI/LO value. See mips_hard_regno_mode_ok_p
4704 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
4706 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
4707 ;; instead of MFHI. This avoids both the normal MIPS III hi/lo hazards
4708 ;; and the errata related to -mfix-vr4130.
4709 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
4710 [(set (match_operand:GPR 0 "register_operand" "=d")
4711 (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
4714 { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
4715 [(set_attr "move_type" "mfhilo")
4716 (set_attr "mode" "<GPR:MODE>")])
4718 ;; Set the high part of a HI/LO value, given that the low part has
4719 ;; already been set. See mips_hard_regno_mode_ok_p for the reason
4720 ;; why we can't just use (reg:GPR HI_REGNUM).
4721 (define_insn "mthi<GPR:mode>_<HILO:mode>"
4722 [(set (match_operand:HILO 0 "register_operand" "=x")
4723 (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4724 (match_operand:GPR 2 "register_operand" "l")]
4728 [(set_attr "move_type" "mthilo")
4729 (set_attr "mode" "SI")])
4731 ;; Emit a doubleword move in which exactly one of the operands is
4732 ;; a floating-point register. We can't just emit two normal moves
4733 ;; because of the constraints imposed by the FPU register model;
4734 ;; see mips_cannot_change_mode_class for details. Instead, we keep
4735 ;; the FPR whole and use special patterns to refer to each word of
4736 ;; the other operand.
4738 (define_expand "move_doubleword_fpr<mode>"
4739 [(set (match_operand:SPLITF 0)
4740 (match_operand:SPLITF 1))]
4743 if (FP_REG_RTX_P (operands[0]))
4745 rtx low = mips_subword (operands[1], 0);
4746 rtx high = mips_subword (operands[1], 1);
4747 emit_insn (gen_load_low<mode> (operands[0], low));
4748 if (TARGET_FLOAT64 && !TARGET_64BIT)
4749 emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
4751 emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
4755 rtx low = mips_subword (operands[0], 0);
4756 rtx high = mips_subword (operands[0], 1);
4757 emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
4758 if (TARGET_FLOAT64 && !TARGET_64BIT)
4759 emit_insn (gen_mfhc1<mode> (high, operands[1]));
4761 emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
4766 ;; Load the low word of operand 0 with operand 1.
4767 (define_insn "load_low<mode>"
4768 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4769 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
4773 operands[0] = mips_subword (operands[0], 0);
4774 return mips_output_move (operands[0], operands[1]);
4776 [(set_attr "move_type" "mtc,fpload")
4777 (set_attr "mode" "<HALFMODE>")])
4779 ;; Load the high word of operand 0 from operand 1, preserving the value
4781 (define_insn "load_high<mode>"
4782 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4783 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
4784 (match_operand:SPLITF 2 "register_operand" "0,0")]
4788 operands[0] = mips_subword (operands[0], 1);
4789 return mips_output_move (operands[0], operands[1]);
4791 [(set_attr "move_type" "mtc,fpload")
4792 (set_attr "mode" "<HALFMODE>")])
4794 ;; Store one word of operand 1 in operand 0. Operand 2 is 1 to store the
4795 ;; high word and 0 to store the low word.
4796 (define_insn "store_word<mode>"
4797 [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
4798 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
4799 (match_operand 2 "const_int_operand")]
4800 UNSPEC_STORE_WORD))]
4803 operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
4804 return mips_output_move (operands[0], operands[1]);
4806 [(set_attr "move_type" "mfc,fpstore")
4807 (set_attr "mode" "<HALFMODE>")])
4809 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
4810 ;; value in the low word.
4811 (define_insn "mthc1<mode>"
4812 [(set (match_operand:SPLITF 0 "register_operand" "=f")
4813 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
4814 (match_operand:SPLITF 2 "register_operand" "0")]
4816 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4818 [(set_attr "move_type" "mtc")
4819 (set_attr "mode" "<HALFMODE>")])
4821 ;; Move high word of operand 1 to operand 0 using mfhc1.
4822 (define_insn "mfhc1<mode>"
4823 [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
4824 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
4826 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4828 [(set_attr "move_type" "mfc")
4829 (set_attr "mode" "<HALFMODE>")])
4831 ;; Move a constant that satisfies CONST_GP_P into operand 0.
4832 (define_expand "load_const_gp_<mode>"
4833 [(set (match_operand:P 0 "register_operand" "=d")
4834 (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
4836 ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset
4837 ;; of _gp from the start of this function. Operand 1 is the incoming
4838 ;; function address.
4839 (define_insn_and_split "loadgp_newabi_<mode>"
4840 [(set (match_operand:P 0 "register_operand" "=d")
4841 (unspec:P [(match_operand:P 1)
4842 (match_operand:P 2 "register_operand" "d")]
4844 "mips_current_loadgp_style () == LOADGP_NEWABI"
4845 { return mips_must_initialize_gp_p () ? "#" : ""; }
4846 "&& mips_must_initialize_gp_p ()"
4847 [(set (match_dup 0) (match_dup 3))
4848 (set (match_dup 0) (match_dup 4))
4849 (set (match_dup 0) (match_dup 5))]
4851 operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
4852 operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
4853 operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
4855 [(set_attr "type" "ghost")])
4857 ;; Likewise, for -mno-shared code. Operand 0 is the __gnu_local_gp symbol.
4858 (define_insn_and_split "loadgp_absolute_<mode>"
4859 [(set (match_operand:P 0 "register_operand" "=d")
4860 (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
4861 "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
4862 { return mips_must_initialize_gp_p () ? "#" : ""; }
4863 "&& mips_must_initialize_gp_p ()"
4866 mips_emit_move (operands[0], operands[1]);
4869 [(set_attr "type" "ghost")])
4871 ;; This blockage instruction prevents the gp load from being
4872 ;; scheduled after an implicit use of gp. It also prevents
4873 ;; the load from being deleted as dead.
4874 (define_insn "loadgp_blockage"
4875 [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
4878 [(set_attr "type" "ghost")])
4880 ;; Initialize $gp for RTP PIC. Operand 0 is the __GOTT_BASE__ symbol
4881 ;; and operand 1 is the __GOTT_INDEX__ symbol.
4882 (define_insn_and_split "loadgp_rtp_<mode>"
4883 [(set (match_operand:P 0 "register_operand" "=d")
4884 (unspec:P [(match_operand:P 1 "symbol_ref_operand")
4885 (match_operand:P 2 "symbol_ref_operand")]
4887 "mips_current_loadgp_style () == LOADGP_RTP"
4888 { return mips_must_initialize_gp_p () ? "#" : ""; }
4889 "&& mips_must_initialize_gp_p ()"
4890 [(set (match_dup 0) (high:P (match_dup 3)))
4891 (set (match_dup 0) (unspec:P [(match_dup 0)
4892 (match_dup 3)] UNSPEC_LOAD_GOT))
4893 (set (match_dup 0) (unspec:P [(match_dup 0)
4894 (match_dup 4)] UNSPEC_LOAD_GOT))]
4896 operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
4897 operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
4899 [(set_attr "type" "ghost")])
4901 ;; Initialize the global pointer for MIPS16 code. Operand 0 is the
4902 ;; global pointer and operand 1 is the MIPS16 register that holds
4903 ;; the required value.
4904 (define_insn_and_split "copygp_mips16_<mode>"
4905 [(set (match_operand:P 0 "register_operand" "=y")
4906 (unspec:P [(match_operand:P 1 "register_operand" "d")]
4909 { return mips_must_initialize_gp_p () ? "#" : ""; }
4910 "&& mips_must_initialize_gp_p ()"
4911 [(set (match_dup 0) (match_dup 1))]
4913 [(set_attr "type" "ghost")])
4915 ;; A placeholder for where the cprestore instruction should go,
4916 ;; if we decide we need one. Operand 0 and operand 1 are as for
4917 ;; "cprestore". Operand 2 is a register that holds the gp value.
4919 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
4920 ;; otherwise any register that holds the correct value will do.
4921 (define_insn_and_split "potential_cprestore_<mode>"
4922 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
4923 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
4924 (match_operand:P 2 "register_operand" "d,d")]
4925 UNSPEC_POTENTIAL_CPRESTORE))
4926 (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
4927 "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
4928 { return mips_must_initialize_gp_p () ? "#" : ""; }
4929 "mips_must_initialize_gp_p ()"
4932 mips_save_gp_to_cprestore_slot (operands[0], operands[1],
4933 operands[2], operands[3]);
4936 [(set_attr "type" "ghost")])
4938 ;; Emit a .cprestore directive, which normally expands to a single store
4939 ;; instruction. Operand 0 is a (possibly illegitimate) sp-based MEM
4940 ;; for the cprestore slot. Operand 1 is the offset of the slot from
4941 ;; the stack pointer. (This is redundant with operand 0, but it makes
4942 ;; things a little simpler.)
4943 (define_insn "cprestore_<mode>"
4944 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
4945 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
4948 "TARGET_CPRESTORE_DIRECTIVE"
4950 if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
4951 return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
4953 return ".cprestore\t%1";
4955 [(set_attr "type" "store")
4956 (set_attr "length" "4,12")])
4958 (define_insn "use_cprestore_<mode>"
4959 [(set (reg:P CPRESTORE_SLOT_REGNUM)
4960 (match_operand:P 0 "cprestore_load_slot_operand"))]
4963 [(set_attr "type" "ghost")])
4965 ;; Expand in-line code to clear the instruction cache between operand[0] and
4967 (define_expand "clear_cache"
4968 [(match_operand 0 "pmode_register_operand")
4969 (match_operand 1 "pmode_register_operand")]
4975 mips_expand_synci_loop (operands[0], operands[1]);
4976 emit_insn (gen_sync ());
4977 emit_insn (PMODE_INSN (gen_clear_hazard, ()));
4979 else if (mips_cache_flush_func && mips_cache_flush_func[0])
4981 rtx len = gen_reg_rtx (Pmode);
4982 emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
4983 MIPS_ICACHE_SYNC (operands[0], len);
4989 [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
4991 { return mips_output_sync (); })
4993 (define_insn "synci"
4994 [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
4999 (define_insn "rdhwr_synci_step_<mode>"
5000 [(set (match_operand:P 0 "register_operand" "=d")
5001 (unspec_volatile [(const_int 1)]
5006 (define_insn "clear_hazard_<mode>"
5007 [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5008 (clobber (reg:P RETURN_ADDR_REGNUM))]
5011 return "%(%<bal\t1f\n"
5013 "1:\t<d>addiu\t$31,$31,12\n"
5017 [(set_attr "length" "20")])
5019 ;; Cache operations for R4000-style caches.
5020 (define_insn "mips_cache"
5021 [(set (mem:BLK (scratch))
5022 (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5023 (match_operand:QI 1 "address_operand" "p")]
5024 UNSPEC_MIPS_CACHE))]
5028 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5029 ;; operation. We keep the pattern distinct so that we can identify
5030 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5031 ;; the operation is never inserted into a delay slot.
5032 (define_insn "r10k_cache_barrier"
5033 [(set (mem:BLK (scratch))
5034 (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5037 [(set_attr "can_delay" "no")])
5039 ;; Block moves, see mips.c for more details.
5040 ;; Argument 0 is the destination
5041 ;; Argument 1 is the source
5042 ;; Argument 2 is the length
5043 ;; Argument 3 is the alignment
5045 (define_expand "movmemsi"
5046 [(parallel [(set (match_operand:BLK 0 "general_operand")
5047 (match_operand:BLK 1 "general_operand"))
5048 (use (match_operand:SI 2 ""))
5049 (use (match_operand:SI 3 "const_int_operand"))])]
5050 "!TARGET_MIPS16 && !TARGET_MEMCPY"
5052 if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5059 ;; ....................
5063 ;; ....................
5065 (define_expand "<optab><mode>3"
5066 [(set (match_operand:GPR 0 "register_operand")
5067 (any_shift:GPR (match_operand:GPR 1 "register_operand")
5068 (match_operand:SI 2 "arith_operand")))]
5071 /* On the mips16, a shift of more than 8 is a four byte instruction,
5072 so, for a shift between 8 and 16, it is just as fast to do two
5073 shifts of 8 or less. If there is a lot of shifting going on, we
5074 may win in CSE. Otherwise combine will put the shifts back
5075 together again. This can be called by mips_function_arg, so we must
5076 be careful not to allocate a new register if we've reached the
5080 && CONST_INT_P (operands[2])
5081 && INTVAL (operands[2]) > 8
5082 && INTVAL (operands[2]) <= 16
5083 && !reload_in_progress
5084 && !reload_completed)
5086 rtx temp = gen_reg_rtx (<MODE>mode);
5088 emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5089 emit_insn (gen_<optab><mode>3 (operands[0], temp,
5090 GEN_INT (INTVAL (operands[2]) - 8)));
5095 (define_insn "*<optab><mode>3"
5096 [(set (match_operand:GPR 0 "register_operand" "=d")
5097 (any_shift:GPR (match_operand:GPR 1 "register_operand" "d")
5098 (match_operand:SI 2 "arith_operand" "dI")))]
5101 if (CONST_INT_P (operands[2]))
5102 operands[2] = GEN_INT (INTVAL (operands[2])
5103 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5105 return "<d><insn>\t%0,%1,%2";
5107 [(set_attr "type" "shift")
5108 (set_attr "mode" "<MODE>")])
5110 (define_insn "*<optab>si3_extend"
5111 [(set (match_operand:DI 0 "register_operand" "=d")
5113 (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5114 (match_operand:SI 2 "arith_operand" "dI"))))]
5115 "TARGET_64BIT && !TARGET_MIPS16"
5117 if (CONST_INT_P (operands[2]))
5118 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5120 return "<insn>\t%0,%1,%2";
5122 [(set_attr "type" "shift")
5123 (set_attr "mode" "SI")])
5125 (define_insn "*<optab>si3_mips16"
5126 [(set (match_operand:SI 0 "register_operand" "=d,d")
5127 (any_shift:SI (match_operand:SI 1 "register_operand" "0,d")
5128 (match_operand:SI 2 "arith_operand" "d,I")))]
5131 if (which_alternative == 0)
5132 return "<insn>\t%0,%2";
5134 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5135 return "<insn>\t%0,%1,%2";
5137 [(set_attr "type" "shift")
5138 (set_attr "mode" "SI")
5139 (set_attr_alternative "length"
5141 (if_then_else (match_operand 2 "m16_uimm3_b")
5145 ;; We need separate DImode MIPS16 patterns because of the irregularity
5147 (define_insn "*ashldi3_mips16"
5148 [(set (match_operand:DI 0 "register_operand" "=d,d")
5149 (ashift:DI (match_operand:DI 1 "register_operand" "0,d")
5150 (match_operand:SI 2 "arith_operand" "d,I")))]
5151 "TARGET_64BIT && TARGET_MIPS16"
5153 if (which_alternative == 0)
5154 return "dsll\t%0,%2";
5156 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5157 return "dsll\t%0,%1,%2";
5159 [(set_attr "type" "shift")
5160 (set_attr "mode" "DI")
5161 (set_attr_alternative "length"
5163 (if_then_else (match_operand 2 "m16_uimm3_b")
5167 (define_insn "*ashrdi3_mips16"
5168 [(set (match_operand:DI 0 "register_operand" "=d,d")
5169 (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
5170 (match_operand:SI 2 "arith_operand" "d,I")))]
5171 "TARGET_64BIT && TARGET_MIPS16"
5173 if (CONST_INT_P (operands[2]))
5174 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5176 return "dsra\t%0,%2";
5178 [(set_attr "type" "shift")
5179 (set_attr "mode" "DI")
5180 (set_attr_alternative "length"
5182 (if_then_else (match_operand 2 "m16_uimm3_b")
5186 (define_insn "*lshrdi3_mips16"
5187 [(set (match_operand:DI 0 "register_operand" "=d,d")
5188 (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
5189 (match_operand:SI 2 "arith_operand" "d,I")))]
5190 "TARGET_64BIT && TARGET_MIPS16"
5192 if (CONST_INT_P (operands[2]))
5193 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5195 return "dsrl\t%0,%2";
5197 [(set_attr "type" "shift")
5198 (set_attr "mode" "DI")
5199 (set_attr_alternative "length"
5201 (if_then_else (match_operand 2 "m16_uimm3_b")
5205 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5208 [(set (match_operand:GPR 0 "d_operand")
5209 (any_shift:GPR (match_operand:GPR 1 "d_operand")
5210 (match_operand:GPR 2 "const_int_operand")))]
5211 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5212 && INTVAL (operands[2]) > 8
5213 && INTVAL (operands[2]) <= 16"
5214 [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5215 (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5216 { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5218 ;; If we load a byte on the mips16 as a bitfield, the resulting
5219 ;; sequence of instructions is too complicated for combine, because it
5220 ;; involves four instructions: a load, a shift, a constant load into a
5221 ;; register, and an and (the key problem here is that the mips16 does
5222 ;; not have and immediate). We recognize a shift of a load in order
5223 ;; to make it simple enough for combine to understand.
5225 ;; The length here is the worst case: the length of the split version
5226 ;; will be more accurate.
5227 (define_insn_and_split ""
5228 [(set (match_operand:SI 0 "register_operand" "=d")
5229 (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5230 (match_operand:SI 2 "immediate_operand" "I")))]
5234 [(set (match_dup 0) (match_dup 1))
5235 (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5237 [(set_attr "type" "load")
5238 (set_attr "mode" "SI")
5239 (set_attr "length" "16")])
5241 (define_insn "rotr<mode>3"
5242 [(set (match_operand:GPR 0 "register_operand" "=d")
5243 (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5244 (match_operand:SI 2 "arith_operand" "dI")))]
5247 if (CONST_INT_P (operands[2]))
5248 gcc_assert (INTVAL (operands[2]) >= 0
5249 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
5251 return "<d>ror\t%0,%1,%2";
5253 [(set_attr "type" "shift")
5254 (set_attr "mode" "<MODE>")])
5257 ;; ....................
5259 ;; CONDITIONAL BRANCHES
5261 ;; ....................
5263 ;; Conditional branches on floating-point equality tests.
5265 (define_insn "*branch_fp"
5268 (match_operator 1 "equality_operator"
5269 [(match_operand:CC 2 "register_operand" "z")
5271 (label_ref (match_operand 0 "" ""))
5275 return mips_output_conditional_branch (insn, operands,
5276 MIPS_BRANCH ("b%F1", "%Z2%0"),
5277 MIPS_BRANCH ("b%W1", "%Z2%0"));
5279 [(set_attr "type" "branch")])
5281 (define_insn "*branch_fp_inverted"
5284 (match_operator 1 "equality_operator"
5285 [(match_operand:CC 2 "register_operand" "z")
5288 (label_ref (match_operand 0 "" ""))))]
5291 return mips_output_conditional_branch (insn, operands,
5292 MIPS_BRANCH ("b%W1", "%Z2%0"),
5293 MIPS_BRANCH ("b%F1", "%Z2%0"));
5295 [(set_attr "type" "branch")])
5297 ;; Conditional branches on ordered comparisons with zero.
5299 (define_insn "*branch_order<mode>"
5302 (match_operator 1 "order_operator"
5303 [(match_operand:GPR 2 "register_operand" "d")
5305 (label_ref (match_operand 0 "" ""))
5308 { return mips_output_order_conditional_branch (insn, operands, false); }
5309 [(set_attr "type" "branch")])
5311 (define_insn "*branch_order<mode>_inverted"
5314 (match_operator 1 "order_operator"
5315 [(match_operand:GPR 2 "register_operand" "d")
5318 (label_ref (match_operand 0 "" ""))))]
5320 { return mips_output_order_conditional_branch (insn, operands, true); }
5321 [(set_attr "type" "branch")])
5323 ;; Conditional branch on equality comparison.
5325 (define_insn "*branch_equality<mode>"
5328 (match_operator 1 "equality_operator"
5329 [(match_operand:GPR 2 "register_operand" "d")
5330 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5331 (label_ref (match_operand 0 "" ""))
5335 return mips_output_conditional_branch (insn, operands,
5336 MIPS_BRANCH ("b%C1", "%2,%z3,%0"),
5337 MIPS_BRANCH ("b%N1", "%2,%z3,%0"));
5339 [(set_attr "type" "branch")])
5341 (define_insn "*branch_equality<mode>_inverted"
5344 (match_operator 1 "equality_operator"
5345 [(match_operand:GPR 2 "register_operand" "d")
5346 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5348 (label_ref (match_operand 0 "" ""))))]
5351 return mips_output_conditional_branch (insn, operands,
5352 MIPS_BRANCH ("b%N1", "%2,%z3,%0"),
5353 MIPS_BRANCH ("b%C1", "%2,%z3,%0"));
5355 [(set_attr "type" "branch")])
5359 (define_insn "*branch_equality<mode>_mips16"
5362 (match_operator 0 "equality_operator"
5363 [(match_operand:GPR 1 "register_operand" "d,t")
5365 (match_operand 2 "pc_or_label_operand" "")
5366 (match_operand 3 "pc_or_label_operand" "")))]
5369 if (operands[2] != pc_rtx)
5371 if (which_alternative == 0)
5372 return "b%C0z\t%1,%2";
5374 return "bt%C0z\t%2";
5378 if (which_alternative == 0)
5379 return "b%N0z\t%1,%3";
5381 return "bt%N0z\t%3";
5384 [(set_attr "type" "branch")])
5386 (define_expand "cbranch<mode>4"
5388 (if_then_else (match_operator 0 "comparison_operator"
5389 [(match_operand:GPR 1 "register_operand")
5390 (match_operand:GPR 2 "nonmemory_operand")])
5391 (label_ref (match_operand 3 ""))
5395 mips_expand_conditional_branch (operands);
5399 (define_expand "cbranch<mode>4"
5401 (if_then_else (match_operator 0 "comparison_operator"
5402 [(match_operand:SCALARF 1 "register_operand")
5403 (match_operand:SCALARF 2 "register_operand")])
5404 (label_ref (match_operand 3 ""))
5408 mips_expand_conditional_branch (operands);
5412 ;; Used to implement built-in functions.
5413 (define_expand "condjump"
5415 (if_then_else (match_operand 0)
5416 (label_ref (match_operand 1))
5419 ;; Branch if bit is set/clear.
5421 (define_insn "*branch_bit<bbv><mode>"
5424 (equality_op (zero_extract:GPR
5425 (match_operand:GPR 1 "register_operand" "d")
5427 (match_operand 2 "const_int_operand" ""))
5429 (label_ref (match_operand 0 ""))
5431 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5434 mips_output_conditional_branch (insn, operands,
5435 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
5436 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
5438 [(set_attr "type" "branch")
5439 (set_attr "branch_likely" "no")])
5441 (define_insn "*branch_bit<bbv><mode>_inverted"
5444 (equality_op (zero_extract:GPR
5445 (match_operand:GPR 1 "register_operand" "d")
5447 (match_operand 2 "const_int_operand" ""))
5450 (label_ref (match_operand 0 ""))))]
5451 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5454 mips_output_conditional_branch (insn, operands,
5455 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
5456 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
5458 [(set_attr "type" "branch")
5459 (set_attr "branch_likely" "no")])
5462 ;; ....................
5464 ;; SETTING A REGISTER FROM A COMPARISON
5466 ;; ....................
5468 ;; Destination is always set in SI mode.
5470 (define_expand "cstore<mode>4"
5471 [(set (match_operand:SI 0 "register_operand")
5472 (match_operator:SI 1 "mips_cstore_operator"
5473 [(match_operand:GPR 2 "register_operand")
5474 (match_operand:GPR 3 "nonmemory_operand")]))]
5477 mips_expand_scc (operands);
5481 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
5482 [(set (match_operand:GPR2 0 "register_operand" "=d")
5483 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5485 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5487 [(set_attr "type" "slt")
5488 (set_attr "mode" "<GPR:MODE>")])
5490 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
5491 [(set (match_operand:GPR2 0 "register_operand" "=t")
5492 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5494 "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5496 [(set_attr "type" "slt")
5497 (set_attr "mode" "<GPR:MODE>")])
5499 ;; Generate sltiu unless using seq results in better code.
5500 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
5501 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5502 (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5503 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5509 [(set_attr "type" "slt")
5510 (set_attr "mode" "<GPR:MODE>")])
5512 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
5513 [(set (match_operand:GPR2 0 "register_operand" "=d")
5514 (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
5516 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5518 [(set_attr "type" "slt")
5519 (set_attr "mode" "<GPR:MODE>")])
5521 ;; Generate sltu unless using sne results in better code.
5522 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
5523 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5524 (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5525 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5531 [(set_attr "type" "slt")
5532 (set_attr "mode" "<GPR:MODE>")])
5534 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
5535 [(set (match_operand:GPR2 0 "register_operand" "=d")
5536 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5537 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5540 [(set_attr "type" "slt")
5541 (set_attr "mode" "<GPR:MODE>")])
5543 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
5544 [(set (match_operand:GPR2 0 "register_operand" "=t")
5545 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5546 (match_operand:GPR 2 "register_operand" "d")))]
5549 [(set_attr "type" "slt")
5550 (set_attr "mode" "<GPR:MODE>")])
5552 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
5553 [(set (match_operand:GPR2 0 "register_operand" "=d")
5554 (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
5558 [(set_attr "type" "slt")
5559 (set_attr "mode" "<GPR:MODE>")])
5561 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
5562 [(set (match_operand:GPR2 0 "register_operand" "=d")
5563 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5564 (match_operand:GPR 2 "arith_operand" "dI")))]
5567 [(set_attr "type" "slt")
5568 (set_attr "mode" "<GPR:MODE>")])
5570 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
5571 [(set (match_operand:GPR2 0 "register_operand" "=t,t")
5572 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
5573 (match_operand:GPR 2 "arith_operand" "d,I")))]
5576 [(set_attr "type" "slt")
5577 (set_attr "mode" "<GPR:MODE>")
5578 (set_attr_alternative "length"
5580 (if_then_else (match_operand 2 "m16_uimm8_1")
5584 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
5585 [(set (match_operand:GPR2 0 "register_operand" "=d")
5586 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
5587 (match_operand:GPR 2 "sle_operand" "")))]
5590 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5591 return "slt<u>\t%0,%1,%2";
5593 [(set_attr "type" "slt")
5594 (set_attr "mode" "<GPR:MODE>")])
5596 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
5597 [(set (match_operand:GPR2 0 "register_operand" "=t")
5598 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
5599 (match_operand:GPR 2 "sle_operand" "")))]
5602 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5603 return "slt<u>\t%1,%2";
5605 [(set_attr "type" "slt")
5606 (set_attr "mode" "<GPR:MODE>")
5607 (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
5612 ;; ....................
5614 ;; FLOATING POINT COMPARISONS
5616 ;; ....................
5618 (define_insn "s<code>_<mode>"
5619 [(set (match_operand:CC 0 "register_operand" "=z")
5620 (fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5621 (match_operand:SCALARF 2 "register_operand" "f")))]
5623 "c.<fcond>.<fmt>\t%Z0%1,%2"
5624 [(set_attr "type" "fcmp")
5625 (set_attr "mode" "FPSW")])
5627 (define_insn "s<code>_<mode>"
5628 [(set (match_operand:CC 0 "register_operand" "=z")
5629 (swapped_fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5630 (match_operand:SCALARF 2 "register_operand" "f")))]
5632 "c.<swapped_fcond>.<fmt>\t%Z0%2,%1"
5633 [(set_attr "type" "fcmp")
5634 (set_attr "mode" "FPSW")])
5637 ;; ....................
5639 ;; UNCONDITIONAL BRANCHES
5641 ;; ....................
5643 ;; Unconditional branches.
5645 (define_expand "jump"
5647 (label_ref (match_operand 0)))])
5649 (define_insn "*jump_absolute"
5651 (label_ref (match_operand 0)))]
5652 "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
5653 { return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/"); }
5654 [(set_attr "type" "jump")])
5656 (define_insn "*jump_pic"
5658 (label_ref (match_operand 0)))]
5659 "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
5661 if (get_attr_length (insn) <= 8)
5662 return "%*b\t%l0%/";
5665 mips_output_load_label (operands[0]);
5666 return "%*jr\t%@%/%]";
5669 [(set_attr "type" "branch")])
5671 ;; We need a different insn for the mips16, because a mips16 branch
5672 ;; does not have a delay slot.
5674 (define_insn "*jump_mips16"
5676 (label_ref (match_operand 0 "" "")))]
5679 [(set_attr "type" "branch")])
5681 (define_expand "indirect_jump"
5682 [(set (pc) (match_operand 0 "register_operand"))]
5685 operands[0] = force_reg (Pmode, operands[0]);
5686 emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
5690 (define_insn "indirect_jump_<mode>"
5691 [(set (pc) (match_operand:P 0 "register_operand" "d"))]
5694 [(set_attr "type" "jump")
5695 (set_attr "mode" "none")])
5697 (define_expand "tablejump"
5699 (match_operand 0 "register_operand"))
5700 (use (label_ref (match_operand 1 "")))]
5703 if (TARGET_MIPS16_SHORT_JUMP_TABLES)
5704 operands[0] = expand_binop (Pmode, add_optab,
5705 convert_to_mode (Pmode, operands[0], false),
5706 gen_rtx_LABEL_REF (Pmode, operands[1]),
5708 else if (TARGET_GPWORD)
5709 operands[0] = expand_binop (Pmode, add_optab, operands[0],
5710 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
5711 else if (TARGET_RTP_PIC)
5713 /* When generating RTP PIC, we use case table entries that are relative
5714 to the start of the function. Add the function's address to the
5716 rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5717 operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
5718 start, 0, 0, OPTAB_WIDEN);
5721 emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
5725 (define_insn "tablejump_<mode>"
5727 (match_operand:P 0 "register_operand" "d"))
5728 (use (label_ref (match_operand 1 "" "")))]
5731 [(set_attr "type" "jump")
5732 (set_attr "mode" "none")])
5734 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
5735 ;; While it is possible to either pull it off the stack (in the
5736 ;; o32 case) or recalculate it given t9 and our target label,
5737 ;; it takes 3 or 4 insns to do so.
5739 (define_expand "builtin_setjmp_setup"
5740 [(use (match_operand 0 "register_operand"))]
5745 addr = plus_constant (operands[0], GET_MODE_SIZE (Pmode) * 3);
5746 mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
5750 ;; Restore the gp that we saved above. Despite the earlier comment, it seems
5751 ;; that older code did recalculate the gp from $25. Continue to jump through
5752 ;; $25 for compatibility (we lose nothing by doing so).
5754 (define_expand "builtin_longjmp"
5755 [(use (match_operand 0 "register_operand"))]
5758 /* The elements of the buffer are, in order: */
5759 int W = GET_MODE_SIZE (Pmode);
5760 rtx fp = gen_rtx_MEM (Pmode, operands[0]);
5761 rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 1*W));
5762 rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 2*W));
5763 rtx gpv = gen_rtx_MEM (Pmode, plus_constant (operands[0], 3*W));
5764 rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5765 /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
5766 The target is bound to be using $28 as the global pointer
5767 but the current function might not be. */
5768 rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
5770 /* This bit is similar to expand_builtin_longjmp except that it
5771 restores $gp as well. */
5772 mips_emit_move (hard_frame_pointer_rtx, fp);
5773 mips_emit_move (pv, lab);
5774 emit_stack_restore (SAVE_NONLOCAL, stack);
5775 mips_emit_move (gp, gpv);
5776 emit_use (hard_frame_pointer_rtx);
5777 emit_use (stack_pointer_rtx);
5779 emit_indirect_jump (pv);
5784 ;; ....................
5786 ;; Function prologue/epilogue
5788 ;; ....................
5791 (define_expand "prologue"
5795 mips_expand_prologue ();
5799 ;; Block any insns from being moved before this point, since the
5800 ;; profiling call to mcount can use various registers that aren't
5801 ;; saved or used to pass arguments.
5803 (define_insn "blockage"
5804 [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
5807 [(set_attr "type" "ghost")
5808 (set_attr "mode" "none")])
5810 (define_expand "epilogue"
5814 mips_expand_epilogue (false);
5818 (define_expand "sibcall_epilogue"
5822 mips_expand_epilogue (true);
5826 ;; Trivial return. Make it look like a normal return insn as that
5827 ;; allows jump optimizations to work better.
5829 (define_expand "return"
5831 "mips_can_use_return_insn ()"
5832 { mips_expand_before_return (); })
5834 (define_expand "simple_return"
5837 { mips_expand_before_return (); })
5839 (define_insn "*<optab>"
5843 [(set_attr "type" "jump")
5844 (set_attr "mode" "none")])
5848 (define_insn "<optab>_internal"
5850 (use (match_operand 0 "pmode_register_operand" ""))]
5853 [(set_attr "type" "jump")
5854 (set_attr "mode" "none")])
5856 ;; Exception return.
5857 (define_insn "mips_eret"
5859 (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
5862 [(set_attr "type" "trap")
5863 (set_attr "mode" "none")])
5865 ;; Debug exception return.
5866 (define_insn "mips_deret"
5868 (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
5871 [(set_attr "type" "trap")
5872 (set_attr "mode" "none")])
5874 ;; Disable interrupts.
5875 (define_insn "mips_di"
5876 [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
5879 [(set_attr "type" "trap")
5880 (set_attr "mode" "none")])
5882 ;; Execution hazard barrier.
5883 (define_insn "mips_ehb"
5884 [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
5887 [(set_attr "type" "trap")
5888 (set_attr "mode" "none")])
5890 ;; Read GPR from previous shadow register set.
5891 (define_insn "mips_rdpgpr"
5892 [(set (match_operand:SI 0 "register_operand" "=d")
5893 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d")]
5897 [(set_attr "type" "move")
5898 (set_attr "mode" "SI")])
5900 ;; Move involving COP0 registers.
5901 (define_insn "cop0_move"
5902 [(set (match_operand:SI 0 "register_operand" "=B,d")
5903 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
5906 { return mips_output_move (operands[0], operands[1]); }
5907 [(set_attr "type" "mtc,mfc")
5908 (set_attr "mode" "SI")])
5910 ;; This is used in compiling the unwind routines.
5911 (define_expand "eh_return"
5912 [(use (match_operand 0 "general_operand"))]
5915 if (GET_MODE (operands[0]) != word_mode)
5916 operands[0] = convert_to_mode (word_mode, operands[0], 0);
5918 emit_insn (gen_eh_set_lr_di (operands[0]));
5920 emit_insn (gen_eh_set_lr_si (operands[0]));
5924 ;; Clobber the return address on the stack. We can't expand this
5925 ;; until we know where it will be put in the stack frame.
5927 (define_insn "eh_set_lr_si"
5928 [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
5929 (clobber (match_scratch:SI 1 "=&d"))]
5933 (define_insn "eh_set_lr_di"
5934 [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
5935 (clobber (match_scratch:DI 1 "=&d"))]
5940 [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
5941 (clobber (match_scratch 1))]
5945 mips_set_return_address (operands[0], operands[1]);
5949 (define_expand "exception_receiver"
5953 /* See the comment above load_call<mode> for details. */
5954 emit_insn (gen_set_got_version ());
5956 /* If we have a call-clobbered $gp, restore it from its save slot. */
5957 if (HAVE_restore_gp_si)
5958 emit_insn (gen_restore_gp_si ());
5959 else if (HAVE_restore_gp_di)
5960 emit_insn (gen_restore_gp_di ());
5964 (define_expand "nonlocal_goto_receiver"
5968 /* See the comment above load_call<mode> for details. */
5969 emit_insn (gen_set_got_version ());
5973 ;; Restore $gp from its .cprestore stack slot. The instruction remains
5974 ;; volatile until all uses of $28 are exposed.
5975 (define_insn_and_split "restore_gp_<mode>"
5977 (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
5978 (clobber (match_scratch:P 0 "=&d"))]
5979 "TARGET_CALL_CLOBBERED_GP"
5981 "&& epilogue_completed"
5984 mips_restore_gp_from_cprestore_slot (operands[0]);
5987 [(set_attr "type" "ghost")])
5989 ;; Move between $gp and its register save slot.
5990 (define_insn_and_split "move_gp<mode>"
5991 [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
5992 (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
5995 { return mips_must_initialize_gp_p () ? "#" : ""; }
5996 "mips_must_initialize_gp_p ()"
5999 mips_emit_move (operands[0], operands[1]);
6002 [(set_attr "type" "ghost")])
6005 ;; ....................
6009 ;; ....................
6011 ;; Instructions to load a call address from the GOT. The address might
6012 ;; point to a function or to a lazy binding stub. In the latter case,
6013 ;; the stub will use the dynamic linker to resolve the function, which
6014 ;; in turn will change the GOT entry to point to the function's real
6017 ;; This means that every call, even pure and constant ones, can
6018 ;; potentially modify the GOT entry. And once a stub has been called,
6019 ;; we must not call it again.
6021 ;; We represent this restriction using an imaginary, fixed, call-saved
6022 ;; register called GOT_VERSION_REGNUM. The idea is to make the register
6023 ;; live throughout the function and to change its value after every
6024 ;; potential call site. This stops any rtx value that uses the register
6025 ;; from being computed before an earlier call. To do this, we:
6027 ;; - Ensure that the register is live on entry to the function,
6028 ;; so that it is never thought to be used uninitalized.
6030 ;; - Ensure that the register is live on exit from the function,
6031 ;; so that it is live throughout.
6033 ;; - Make each call (lazily-bound or not) use the current value
6034 ;; of GOT_VERSION_REGNUM, so that updates of the register are
6035 ;; not moved across call boundaries.
6037 ;; - Add "ghost" definitions of the register to the beginning of
6038 ;; blocks reached by EH and ABNORMAL_CALL edges, because those
6039 ;; edges may involve calls that normal paths don't. (E.g. the
6040 ;; unwinding code that handles a non-call exception may change
6041 ;; lazily-bound GOT entries.) We do this by making the
6042 ;; exception_receiver and nonlocal_goto_receiver expanders emit
6043 ;; a set_got_version instruction.
6045 ;; - After each call (lazily-bound or not), use a "ghost"
6046 ;; update_got_version instruction to change the register's value.
6047 ;; This instruction mimics the _possible_ effect of the dynamic
6048 ;; resolver during the call and it remains live even if the call
6049 ;; itself becomes dead.
6051 ;; - Leave GOT_VERSION_REGNUM out of all register classes.
6052 ;; The register is therefore not a valid register_operand
6053 ;; and cannot be moved to or from other registers.
6055 (define_insn "load_call<mode>"
6056 [(set (match_operand:P 0 "register_operand" "=d")
6057 (unspec:P [(match_operand:P 1 "register_operand" "d")
6058 (match_operand:P 2 "immediate_operand" "")
6059 (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6061 "<load>\t%0,%R2(%1)"
6062 [(set_attr "got" "load")
6063 (set_attr "mode" "<MODE>")])
6065 (define_insn "set_got_version"
6066 [(set (reg:SI GOT_VERSION_REGNUM)
6067 (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6070 [(set_attr "type" "ghost")])
6072 (define_insn "update_got_version"
6073 [(set (reg:SI GOT_VERSION_REGNUM)
6074 (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6077 [(set_attr "type" "ghost")])
6079 ;; Sibling calls. All these patterns use jump instructions.
6081 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6082 ;; addresses if a direct jump is acceptable. Since the 'S' constraint
6083 ;; is defined in terms of call_insn_operand, the same is true of the
6086 ;; When we use an indirect jump, we need a register that will be
6087 ;; preserved by the epilogue. Since TARGET_USE_PIC_FN_ADDR_REG forces
6088 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6089 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6092 (define_expand "sibcall"
6093 [(parallel [(call (match_operand 0 "")
6094 (match_operand 1 ""))
6095 (use (match_operand 2 "")) ;; next_arg_reg
6096 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6099 mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6100 operands[1], operands[2], false);
6104 (define_insn "sibcall_internal"
6105 [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6106 (match_operand 1 "" ""))]
6107 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6108 { return MIPS_CALL ("j", operands, 0, 1); }
6109 [(set_attr "type" "call")])
6111 (define_expand "sibcall_value"
6112 [(parallel [(set (match_operand 0 "")
6113 (call (match_operand 1 "")
6114 (match_operand 2 "")))
6115 (use (match_operand 3 ""))])] ;; next_arg_reg
6118 mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6119 operands[2], operands[3], false);
6123 (define_insn "sibcall_value_internal"
6124 [(set (match_operand 0 "register_operand" "")
6125 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6126 (match_operand 2 "" "")))]
6127 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6128 { return MIPS_CALL ("j", operands, 1, 2); }
6129 [(set_attr "type" "call")])
6131 (define_insn "sibcall_value_multiple_internal"
6132 [(set (match_operand 0 "register_operand" "")
6133 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6134 (match_operand 2 "" "")))
6135 (set (match_operand 3 "register_operand" "")
6136 (call (mem:SI (match_dup 1))
6138 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6139 { return MIPS_CALL ("j", operands, 1, 2); }
6140 [(set_attr "type" "call")])
6142 (define_expand "call"
6143 [(parallel [(call (match_operand 0 "")
6144 (match_operand 1 ""))
6145 (use (match_operand 2 "")) ;; next_arg_reg
6146 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6149 mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6150 operands[1], operands[2], false);
6154 ;; This instruction directly corresponds to an assembly-language "jal".
6155 ;; There are four cases:
6158 ;; Both symbolic and register destinations are OK. The pattern
6159 ;; always expands to a single mips instruction.
6161 ;; - -mabicalls/-mno-explicit-relocs:
6162 ;; Again, both symbolic and register destinations are OK.
6163 ;; The call is treated as a multi-instruction black box.
6165 ;; - -mabicalls/-mexplicit-relocs with n32 or n64:
6166 ;; Only "jal $25" is allowed. This expands to a single "jalr $25"
6169 ;; - -mabicalls/-mexplicit-relocs with o32 or o64:
6170 ;; Only "jal $25" is allowed. The call is actually two instructions:
6171 ;; "jalr $25" followed by an insn to reload $gp.
6173 ;; In the last case, we can generate the individual instructions with
6174 ;; a define_split. There are several things to be wary of:
6176 ;; - We can't expose the load of $gp before reload. If we did,
6177 ;; it might get removed as dead, but reload can introduce new
6178 ;; uses of $gp by rematerializing constants.
6180 ;; - We shouldn't restore $gp after calls that never return.
6181 ;; It isn't valid to insert instructions between a noreturn
6182 ;; call and the following barrier.
6184 ;; - The splitter deliberately changes the liveness of $gp. The unsplit
6185 ;; instruction preserves $gp and so have no effect on its liveness.
6186 ;; But once we generate the separate insns, it becomes obvious that
6187 ;; $gp is not live on entry to the call.
6189 (define_insn_and_split "call_internal"
6190 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6191 (match_operand 1 "" ""))
6192 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6194 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, 1); }
6195 "reload_completed && TARGET_SPLIT_CALLS"
6198 mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
6201 [(set_attr "jal" "indirect,direct")])
6203 (define_insn "call_split"
6204 [(call (mem:SI (match_operand 0 "call_insn_operand" "cS"))
6205 (match_operand 1 "" ""))
6206 (clobber (reg:SI RETURN_ADDR_REGNUM))
6207 (clobber (reg:SI 28))]
6208 "TARGET_SPLIT_CALLS"
6209 { return MIPS_CALL ("jal", operands, 0, 1); }
6210 [(set_attr "type" "call")])
6212 ;; A pattern for calls that must be made directly. It is used for
6213 ;; MIPS16 calls that the linker may need to redirect to a hard-float
6214 ;; stub; the linker relies on the call relocation type to detect when
6215 ;; such redirection is needed.
6216 (define_insn_and_split "call_internal_direct"
6217 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6220 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6222 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, -1); }
6223 "reload_completed && TARGET_SPLIT_CALLS"
6226 mips_split_call (curr_insn,
6227 gen_call_direct_split (operands[0], operands[1]));
6230 [(set_attr "type" "call")])
6232 (define_insn "call_direct_split"
6233 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6236 (clobber (reg:SI RETURN_ADDR_REGNUM))
6237 (clobber (reg:SI 28))]
6238 "TARGET_SPLIT_CALLS"
6239 { return MIPS_CALL ("jal", operands, 0, -1); }
6240 [(set_attr "type" "call")])
6242 (define_expand "call_value"
6243 [(parallel [(set (match_operand 0 "")
6244 (call (match_operand 1 "")
6245 (match_operand 2 "")))
6246 (use (match_operand 3 ""))])] ;; next_arg_reg
6249 mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
6250 operands[2], operands[3], false);
6254 ;; See comment for call_internal.
6255 (define_insn_and_split "call_value_internal"
6256 [(set (match_operand 0 "register_operand" "")
6257 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6258 (match_operand 2 "" "")))
6259 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6261 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6262 "reload_completed && TARGET_SPLIT_CALLS"
6265 mips_split_call (curr_insn,
6266 gen_call_value_split (operands[0], operands[1],
6270 [(set_attr "jal" "indirect,direct")])
6272 (define_insn "call_value_split"
6273 [(set (match_operand 0 "register_operand" "")
6274 (call (mem:SI (match_operand 1 "call_insn_operand" "cS"))
6275 (match_operand 2 "" "")))
6276 (clobber (reg:SI RETURN_ADDR_REGNUM))
6277 (clobber (reg:SI 28))]
6278 "TARGET_SPLIT_CALLS"
6279 { return MIPS_CALL ("jal", operands, 1, 2); }
6280 [(set_attr "type" "call")])
6282 ;; See call_internal_direct.
6283 (define_insn_and_split "call_value_internal_direct"
6284 [(set (match_operand 0 "register_operand")
6285 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6288 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6290 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, -1); }
6291 "reload_completed && TARGET_SPLIT_CALLS"
6294 mips_split_call (curr_insn,
6295 gen_call_value_direct_split (operands[0], operands[1],
6299 [(set_attr "type" "call")])
6301 (define_insn "call_value_direct_split"
6302 [(set (match_operand 0 "register_operand")
6303 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6306 (clobber (reg:SI RETURN_ADDR_REGNUM))
6307 (clobber (reg:SI 28))]
6308 "TARGET_SPLIT_CALLS"
6309 { return MIPS_CALL ("jal", operands, 1, -1); }
6310 [(set_attr "type" "call")])
6312 ;; See comment for call_internal.
6313 (define_insn_and_split "call_value_multiple_internal"
6314 [(set (match_operand 0 "register_operand" "")
6315 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6316 (match_operand 2 "" "")))
6317 (set (match_operand 3 "register_operand" "")
6318 (call (mem:SI (match_dup 1))
6320 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6322 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6323 "reload_completed && TARGET_SPLIT_CALLS"
6326 mips_split_call (curr_insn,
6327 gen_call_value_multiple_split (operands[0], operands[1],
6328 operands[2], operands[3]));
6331 [(set_attr "jal" "indirect,direct")])
6333 (define_insn "call_value_multiple_split"
6334 [(set (match_operand 0 "register_operand" "")
6335 (call (mem:SI (match_operand 1 "call_insn_operand" "cS"))
6336 (match_operand 2 "" "")))
6337 (set (match_operand 3 "register_operand" "")
6338 (call (mem:SI (match_dup 1))
6340 (clobber (reg:SI RETURN_ADDR_REGNUM))
6341 (clobber (reg:SI 28))]
6342 "TARGET_SPLIT_CALLS"
6343 { return MIPS_CALL ("jal", operands, 1, 2); }
6344 [(set_attr "type" "call")])
6346 ;; Call subroutine returning any type.
6348 (define_expand "untyped_call"
6349 [(parallel [(call (match_operand 0 "")
6351 (match_operand 1 "")
6352 (match_operand 2 "")])]
6357 emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
6359 for (i = 0; i < XVECLEN (operands[2], 0); i++)
6361 rtx set = XVECEXP (operands[2], 0, i);
6362 mips_emit_move (SET_DEST (set), SET_SRC (set));
6365 emit_insn (gen_blockage ());
6370 ;; ....................
6374 ;; ....................
6378 (define_insn "prefetch"
6379 [(prefetch (match_operand:QI 0 "address_operand" "p")
6380 (match_operand 1 "const_int_operand" "n")
6381 (match_operand 2 "const_int_operand" "n"))]
6382 "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
6384 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
6385 /* Loongson 2[ef] and Loongson 3a use load to $0 to perform prefetching. */
6386 return "ld\t$0,%a0";
6387 operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
6388 return "pref\t%1,%a0";
6390 [(set_attr "type" "prefetch")])
6392 (define_insn "*prefetch_indexed_<mode>"
6393 [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
6394 (match_operand:P 1 "register_operand" "d"))
6395 (match_operand 2 "const_int_operand" "n")
6396 (match_operand 3 "const_int_operand" "n"))]
6397 "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
6399 operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
6400 return "prefx\t%2,%1(%0)";
6402 [(set_attr "type" "prefetchx")])
6408 [(set_attr "type" "nop")
6409 (set_attr "mode" "none")])
6411 ;; Like nop, but commented out when outside a .set noreorder block.
6412 (define_insn "hazard_nop"
6416 if (mips_noreorder.nesting_level > 0)
6421 [(set_attr "type" "nop")])
6423 ;; MIPS4 Conditional move instructions.
6425 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
6426 [(set (match_operand:GPR 0 "register_operand" "=d,d")
6428 (match_operator:MOVECC 4 "equality_operator"
6429 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
6431 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
6432 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
6437 [(set_attr "type" "condmove")
6438 (set_attr "mode" "<GPR:MODE>")])
6440 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
6441 [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
6442 (if_then_else:SCALARF
6443 (match_operator:MOVECC 4 "equality_operator"
6444 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
6446 (match_operand:SCALARF 2 "register_operand" "f,0")
6447 (match_operand:SCALARF 3 "register_operand" "0,f")))]
6448 "ISA_HAS_FP_CONDMOVE"
6450 mov%T4.<fmt>\t%0,%2,%1
6451 mov%t4.<fmt>\t%0,%3,%1"
6452 [(set_attr "type" "condmove")
6453 (set_attr "mode" "<SCALARF:MODE>")])
6455 ;; These are the main define_expand's used to make conditional moves.
6457 (define_expand "mov<mode>cc"
6458 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6459 (set (match_operand:GPR 0 "register_operand")
6460 (if_then_else:GPR (match_dup 5)
6461 (match_operand:GPR 2 "reg_or_0_operand")
6462 (match_operand:GPR 3 "reg_or_0_operand")))]
6465 mips_expand_conditional_move (operands);
6469 (define_expand "mov<mode>cc"
6470 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6471 (set (match_operand:SCALARF 0 "register_operand")
6472 (if_then_else:SCALARF (match_dup 5)
6473 (match_operand:SCALARF 2 "register_operand")
6474 (match_operand:SCALARF 3 "register_operand")))]
6475 "ISA_HAS_FP_CONDMOVE"
6477 mips_expand_conditional_move (operands);
6482 ;; ....................
6484 ;; mips16 inline constant tables
6486 ;; ....................
6489 (define_insn "consttable_int"
6490 [(unspec_volatile [(match_operand 0 "consttable_operand" "")
6491 (match_operand 1 "const_int_operand" "")]
6492 UNSPEC_CONSTTABLE_INT)]
6495 assemble_integer (operands[0], INTVAL (operands[1]),
6496 BITS_PER_UNIT * INTVAL (operands[1]), 1);
6499 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
6501 (define_insn "consttable_float"
6502 [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
6503 UNSPEC_CONSTTABLE_FLOAT)]
6508 gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
6509 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
6510 assemble_real (d, GET_MODE (operands[0]),
6511 GET_MODE_BITSIZE (GET_MODE (operands[0])));
6514 [(set (attr "length")
6515 (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
6517 (define_insn "align"
6518 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
6521 [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
6524 [(match_operand 0 "small_data_pattern")]
6527 { operands[0] = mips_rewrite_small_data (operands[0]); })
6530 ;; ....................
6532 ;; MIPS16e Save/Restore
6534 ;; ....................
6537 (define_insn "*mips16e_save_restore"
6538 [(match_parallel 0 ""
6539 [(set (match_operand:SI 1 "register_operand")
6540 (plus:SI (match_dup 1)
6541 (match_operand:SI 2 "const_int_operand")))])]
6542 "operands[1] == stack_pointer_rtx
6543 && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
6544 { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
6545 [(set_attr "type" "arith")
6546 (set_attr "extended_mips16" "yes")])
6548 ;; Thread-Local Storage
6550 ;; The TLS base pointer is accessed via "rdhwr $3, $29". No current
6551 ;; MIPS architecture defines this register, and no current
6552 ;; implementation provides it; instead, any OS which supports TLS is
6553 ;; expected to trap and emulate this instruction. rdhwr is part of the
6554 ;; MIPS 32r2 specification, but we use it on any architecture because
6555 ;; we expect it to be emulated. Use .set to force the assembler to
6558 ;; We do not use a constraint to force the destination to be $3
6559 ;; because $3 can appear explicitly as a function return value.
6560 ;; If we leave the use of $3 implicit in the constraints until
6561 ;; reload, we may end up making a $3 return value live across
6562 ;; the instruction, leading to a spill failure when reloading it.
6563 (define_insn_and_split "tls_get_tp_<mode>"
6564 [(set (match_operand:P 0 "register_operand" "=d")
6565 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
6566 (clobber (reg:P TLS_GET_TP_REGNUM))]
6567 "HAVE_AS_TLS && !TARGET_MIPS16"
6569 "&& reload_completed"
6570 [(set (reg:P TLS_GET_TP_REGNUM)
6571 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
6572 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
6574 [(set_attr "type" "unknown")
6575 ; Since rdhwr always generates a trap for now, putting it in a delay
6576 ; slot would make the kernel's emulation of it much slower.
6577 (set_attr "can_delay" "no")
6578 (set_attr "mode" "<MODE>")
6579 (set_attr "length" "8")])
6581 (define_insn "*tls_get_tp_<mode>_split"
6582 [(set (reg:P TLS_GET_TP_REGNUM)
6583 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
6584 "HAVE_AS_TLS && !TARGET_MIPS16"
6585 ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop"
6586 [(set_attr "type" "unknown")
6587 ; See tls_get_tp_<mode>
6588 (set_attr "can_delay" "no")
6589 (set_attr "mode" "<MODE>")])
6591 ;; Synchronization instructions.
6595 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
6597 (include "mips-ps-3d.md")
6599 ; The MIPS DSP Instructions.
6601 (include "mips-dsp.md")
6603 ; The MIPS DSP REV 2 Instructions.
6605 (include "mips-dspr2.md")
6607 ; MIPS fixed-point instructions.
6608 (include "mips-fixed.md")
6610 ; ST-Microelectronics Loongson-2E/2F-specific patterns.
6611 (include "loongson.md")
6613 (define_c_enum "unspec" [
6614 UNSPEC_ADDRESS_FIRST