1 ;; Mips.md Machine Description for MIPS based processors
2 ;; Copyright (C) 1989-2014 Free Software Foundation, Inc.
3 ;; Contributed by A. Lichnewsky, lich@inria.inria.fr
4 ;; Changes by Michael Meissner, meissner@osf.org
5 ;; 64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
6 ;; Brendan Eich, brendan@microunity.com.
8 ;; This file is part of GCC.
10 ;; GCC is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; GCC is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GCC; see the file COPYING3. If not see
22 ;; <http://www.gnu.org/licenses/>.
24 (define_enum "processor" [
74 (define_c_enum "unspec" [
75 ;; Unaligned accesses.
81 ;; Integer operations that are too cumbersome to describe directly.
86 ;; Floating-point moves.
93 ;; Floating-point environment.
106 UNSPEC_POTENTIAL_CPRESTORE
111 UNSPEC_SET_GOT_VERSION
112 UNSPEC_UPDATE_GOT_VERSION
114 ;; Symbolic accesses.
119 UNSPEC_UNSHIFTED_HIGH
121 ;; MIPS16 constant pools.
123 UNSPEC_CONSTTABLE_INT
124 UNSPEC_CONSTTABLE_FLOAT
126 ;; Blockage and synchronisation.
133 ;; Cache manipulation.
135 UNSPEC_R10K_CACHE_BARRIER
137 ;; Interrupt handling.
145 ;; Used in a call expression in place of args_size. It's present for PIC
146 ;; indirect calls where it contains args_size and the function symbol.
149 ;; MIPS16 casesi jump table dispatch.
150 UNSPEC_CASESI_DISPATCH
153 UNSPEC_PROBE_STACK_RANGE
157 [(TLS_GET_TP_REGNUM 3)
161 (PIC_FUNCTION_ADDR_REGNUM 25)
162 (RETURN_ADDR_REGNUM 31)
163 (CPRESTORE_SLOT_REGNUM 76)
164 (GOT_VERSION_REGNUM 79)
166 ;; PIC long branch sequences are never longer than 100 bytes.
167 (MAX_PIC_BRANCH_LENGTH 100)
171 (include "predicates.md")
172 (include "constraints.md")
174 ;; ....................
178 ;; ....................
180 (define_attr "got" "unset,xgot_high,load"
181 (const_string "unset"))
183 ;; For jal instructions, this attribute is DIRECT when the target address
184 ;; is symbolic and INDIRECT when it is a register.
185 (define_attr "jal" "unset,direct,indirect"
186 (const_string "unset"))
188 ;; This attribute is YES if the instruction is a jal macro (not a
189 ;; real jal instruction).
191 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
192 ;; an instruction to restore $gp. Direct jals are also macros for
193 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
195 (define_attr "jal_macro" "no,yes"
196 (cond [(eq_attr "jal" "direct")
197 (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
198 ? JAL_MACRO_YES : JAL_MACRO_NO)")
199 (eq_attr "jal" "indirect")
200 (symbol_ref "(TARGET_CALL_CLOBBERED_GP
201 ? JAL_MACRO_YES : JAL_MACRO_NO)")]
202 (const_string "no")))
204 ;; Classification of moves, extensions and truncations. Most values
205 ;; are as for "type" (see below) but there are also the following
206 ;; move-specific values:
208 ;; constN move an N-constraint integer into a MIPS16 register
209 ;; sll0 "sll DEST,SRC,0", which on 64-bit targets is guaranteed
210 ;; to produce a sign-extended DEST, even if SRC is not
211 ;; properly sign-extended
212 ;; ext_ins EXT, DEXT, INS or DINS instruction
213 ;; andi a single ANDI instruction
214 ;; loadpool move a constant into a MIPS16 register by loading it
216 ;; shift_shift a shift left followed by a shift right
218 ;; This attribute is used to determine the instruction's length and
219 ;; scheduling type. For doubleword moves, the attribute always describes
220 ;; the split instructions; in some cases, it is more appropriate for the
221 ;; scheduling type to be "multi" instead.
222 (define_attr "move_type"
223 "unknown,load,fpload,store,fpstore,mtc,mfc,mtlo,mflo,imul,move,fmove,
224 const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
226 (const_string "unknown"))
228 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor"
229 (const_string "unknown"))
231 ;; Main data type used by the insn
232 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW"
233 (const_string "unknown"))
235 ;; True if the main data type is twice the size of a word.
236 (define_attr "dword_mode" "no,yes"
237 (cond [(and (eq_attr "mode" "DI,DF")
238 (not (match_test "TARGET_64BIT")))
241 (and (eq_attr "mode" "TI,TF")
242 (match_test "TARGET_64BIT"))
243 (const_string "yes")]
244 (const_string "no")))
246 ;; Attributes describing a sync loop. These loops have the form:
248 ;; if (RELEASE_BARRIER == YES) sync
250 ;; if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
251 ;; CMP = 0 [delay slot]
252 ;; $TMP1 = OLDVAL & EXCLUSIVE_MASK
253 ;; $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
254 ;; $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
255 ;; $AT |= $TMP1 | $TMP3
256 ;; if (!commit (*MEM = $AT)) goto 1.
257 ;; if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
259 ;; if (ACQUIRE_BARRIER == YES) sync
262 ;; where "$" values are temporaries and where the other values are
263 ;; specified by the attributes below. Values are specified as operand
264 ;; numbers and insns are specified as enums. If no operand number is
265 ;; specified, the following values are used instead:
270 ;; - INCLUSIVE_MASK: -1
271 ;; - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
272 ;; - EXCLUSIVE_MASK: 0
274 ;; MEM and INSN1_OP2 are required.
276 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
277 ;; but the gen* programs don't yet support that.
278 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
279 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
280 (define_attr "sync_cmp" "none,0,1,2,3,4,5" (const_string "none"))
281 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
282 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
283 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
284 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
285 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
286 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
287 (const_string "move"))
288 (define_attr "sync_insn2" "nop,and,xor,not"
289 (const_string "nop"))
290 ;; Memory model specifier.
291 ;; "0"-"9" values specify the operand that stores the memory model value.
292 ;; "10" specifies MEMMODEL_ACQ_REL,
293 ;; "11" specifies MEMMODEL_ACQUIRE.
294 (define_attr "sync_memmodel" "" (const_int 10))
296 ;; Accumulator operand for madd patterns.
297 (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))
299 ;; Classification of each insn.
300 ;; branch conditional branch
301 ;; jump unconditional jump
302 ;; call unconditional call
303 ;; load load instruction(s)
304 ;; fpload floating point load
305 ;; fpidxload floating point indexed load
306 ;; store store instruction(s)
307 ;; fpstore floating point store
308 ;; fpidxstore floating point indexed store
309 ;; prefetch memory prefetch (register + offset)
310 ;; prefetchx memory indexed prefetch (register + register)
311 ;; condmove conditional moves
312 ;; mtc transfer to coprocessor
313 ;; mfc transfer from coprocessor
314 ;; mthi transfer to a hi register
315 ;; mtlo transfer to a lo register
316 ;; mfhi transfer from a hi register
317 ;; mflo transfer from a lo register
318 ;; const load constant
319 ;; arith integer arithmetic instructions
320 ;; logical integer logical instructions
321 ;; shift integer shift instructions
322 ;; slt set less than instructions
323 ;; signext sign extend instructions
324 ;; clz the clz and clo instructions
325 ;; pop the pop instruction
326 ;; trap trap if instructions
327 ;; imul integer multiply 2 operands
328 ;; imul3 integer multiply 3 operands
329 ;; imul3nc integer multiply 3 operands without clobbering HI/LO
330 ;; imadd integer multiply-add
331 ;; idiv integer divide 2 operands
332 ;; idiv3 integer divide 3 operands
333 ;; move integer register move ({,D}ADD{,U} with rt = 0)
334 ;; fmove floating point register move
335 ;; fadd floating point add/subtract
336 ;; fmul floating point multiply
337 ;; fmadd floating point multiply-add
338 ;; fdiv floating point divide
339 ;; frdiv floating point reciprocal divide
340 ;; frdiv1 floating point reciprocal divide step 1
341 ;; frdiv2 floating point reciprocal divide step 2
342 ;; fabs floating point absolute value
343 ;; fneg floating point negation
344 ;; fcmp floating point compare
345 ;; fcvt floating point convert
346 ;; fsqrt floating point square root
347 ;; frsqrt floating point reciprocal square root
348 ;; frsqrt1 floating point reciprocal square root step1
349 ;; frsqrt2 floating point reciprocal square root step2
350 ;; dspmac DSP MAC instructions not saturating the accumulator
351 ;; dspmacsat DSP MAC instructions that saturate the accumulator
352 ;; accext DSP accumulator extract instructions
353 ;; accmod DSP accumulator modify instructions
354 ;; dspalu DSP ALU instructions not saturating the result
355 ;; dspalusat DSP ALU instructions that saturate the result
356 ;; multi multiword sequence (or user asm statements)
357 ;; atomic atomic memory update instruction
358 ;; syncloop memory atomic operation implemented as a sync loop
360 ;; ghost an instruction that produces no real code
361 ;; multimem microMIPS multiword load and store
363 "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
364 prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical,
365 shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
366 fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
367 frsqrt,frsqrt1,frsqrt2,dspmac,dspmacsat,accext,accmod,dspalu,dspalusat,
368 multi,atomic,syncloop,nop,ghost,multimem"
369 (cond [(eq_attr "jal" "!unset") (const_string "call")
370 (eq_attr "got" "load") (const_string "load")
372 (eq_attr "alu_type" "add,sub") (const_string "arith")
374 (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
376 ;; If a doubleword move uses these expensive instructions,
377 ;; it is usually better to schedule them in the same way
378 ;; as the singleword form, rather than as "multi".
379 (eq_attr "move_type" "load") (const_string "load")
380 (eq_attr "move_type" "fpload") (const_string "fpload")
381 (eq_attr "move_type" "store") (const_string "store")
382 (eq_attr "move_type" "fpstore") (const_string "fpstore")
383 (eq_attr "move_type" "mtc") (const_string "mtc")
384 (eq_attr "move_type" "mfc") (const_string "mfc")
385 (eq_attr "move_type" "mtlo") (const_string "mtlo")
386 (eq_attr "move_type" "mflo") (const_string "mflo")
388 ;; These types of move are always single insns.
389 (eq_attr "move_type" "imul") (const_string "imul")
390 (eq_attr "move_type" "fmove") (const_string "fmove")
391 (eq_attr "move_type" "loadpool") (const_string "load")
392 (eq_attr "move_type" "signext") (const_string "signext")
393 (eq_attr "move_type" "ext_ins") (const_string "arith")
394 (eq_attr "move_type" "arith") (const_string "arith")
395 (eq_attr "move_type" "logical") (const_string "logical")
396 (eq_attr "move_type" "sll0") (const_string "shift")
397 (eq_attr "move_type" "andi") (const_string "logical")
399 ;; These types of move are always split.
400 (eq_attr "move_type" "constN,shift_shift")
401 (const_string "multi")
403 ;; These types of move are split for doubleword modes only.
404 (and (eq_attr "move_type" "move,const")
405 (eq_attr "dword_mode" "yes"))
406 (const_string "multi")
407 (eq_attr "move_type" "move") (const_string "move")
408 (eq_attr "move_type" "const") (const_string "const")
409 (eq_attr "sync_mem" "!none") (const_string "syncloop")]
410 (const_string "unknown")))
412 ;; Mode for conversion types (fcvt)
413 ;; I2S integer to float single (SI/DI to SF)
414 ;; I2D integer to float double (SI/DI to DF)
415 ;; S2I float to integer (SF to SI/DI)
416 ;; D2I float to integer (DF to SI/DI)
417 ;; D2S double to float single
418 ;; S2D float single to double
420 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D"
421 (const_string "unknown"))
423 ;; Is this an extended instruction in mips16 mode?
424 (define_attr "extended_mips16" "no,yes"
425 (if_then_else (ior ;; In general, constant-pool loads are extended
426 ;; instructions. We don't yet optimize for 16-bit
427 ;; PC-relative references.
428 (eq_attr "move_type" "sll0,loadpool")
429 (eq_attr "jal" "direct")
430 (eq_attr "got" "load"))
432 (const_string "no")))
434 (define_attr "compression" "none,all,micromips32,micromips"
435 (const_string "none"))
437 (define_attr "enabled" "no,yes"
438 (cond [;; The o32 FPXX and FP64A ABI extensions prohibit direct moves between
439 ;; GR_REG and FR_REG for 64-bit values.
440 (and (eq_attr "move_type" "mtc,mfc")
441 (match_test "(TARGET_FLOATXX && !ISA_HAS_MXHC1)
442 || TARGET_O32_FP64A_ABI")
443 (eq_attr "dword_mode" "yes"))
445 (and (eq_attr "compression" "micromips32,micromips")
446 (match_test "!TARGET_MICROMIPS"))
448 (const_string "yes")))
450 ;; The number of individual instructions that a non-branch pattern generates,
451 ;; using units of BASE_INSN_LENGTH.
452 (define_attr "insn_count" ""
453 (cond [;; "Ghost" instructions occupy no space.
454 (eq_attr "type" "ghost")
457 ;; Extended instructions count as 2.
458 (and (eq_attr "extended_mips16" "yes")
459 (match_test "TARGET_MIPS16"))
462 ;; A GOT load followed by an add of $gp. This is not used for MIPS16.
463 (eq_attr "got" "xgot_high")
466 ;; SHIFT_SHIFTs are decomposed into two separate instructions.
467 ;; They are extended instructions on MIPS16 targets.
468 (eq_attr "move_type" "shift_shift")
469 (if_then_else (match_test "TARGET_MIPS16")
473 ;; Check for doubleword moves that are decomposed into two
474 ;; instructions. The individual instructions are unextended
476 (and (eq_attr "move_type" "mtc,mfc,mtlo,mflo,move")
477 (eq_attr "dword_mode" "yes"))
480 ;; Constants, loads and stores are handled by external routines.
481 (and (eq_attr "move_type" "const,constN")
482 (eq_attr "dword_mode" "yes"))
483 (symbol_ref "mips_split_const_insns (operands[1])")
484 (eq_attr "move_type" "const,constN")
485 (symbol_ref "mips_const_insns (operands[1])")
486 (eq_attr "move_type" "load,fpload")
487 (symbol_ref "mips_load_store_insns (operands[1], insn)")
488 (eq_attr "move_type" "store,fpstore")
489 (symbol_ref "mips_load_store_insns (operands[0], insn)
490 + (TARGET_FIX_24K ? 1 : 0)")
492 ;; In the worst case, a call macro will take 8 instructions:
494 ;; lui $25,%call_hi(FOO)
496 ;; lw $25,%call_lo(FOO)($25)
502 (eq_attr "jal_macro" "yes")
505 ;; Various VR4120 errata require a nop to be inserted after a macc
506 ;; instruction. The assembler does this for us, so account for
507 ;; the worst-case length here.
508 (and (eq_attr "type" "imadd")
509 (match_test "TARGET_FIX_VR4120"))
512 ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
513 ;; the result of the second one is missed. The assembler should work
514 ;; around this by inserting a nop after the first dmult.
515 (and (eq_attr "type" "imul,imul3")
516 (eq_attr "mode" "DI")
517 (match_test "TARGET_FIX_VR4120"))
520 (eq_attr "type" "idiv,idiv3")
521 (symbol_ref "mips_idiv_insns ()")
523 (not (eq_attr "sync_mem" "none"))
524 (symbol_ref "mips_sync_loop_insns (insn, operands)")]
527 ;; Length of instruction in bytes. The default is derived from "insn_count",
528 ;; but there are special cases for branches (which must be handled here)
529 ;; and for compressed single instructions.
530 (define_attr "length" ""
531 (cond [(and (ior (eq_attr "compression" "micromips,all")
532 (and (eq_attr "compression" "micromips32")
533 (eq_attr "mode" "SI,SF")))
534 (eq_attr "dword_mode" "no")
535 (match_test "TARGET_MICROMIPS"))
538 ;; Direct microMIPS branch instructions have a range of
539 ;; [-0x10000,0xfffe], otherwise the range is [-0x20000,0x1fffc].
540 ;; If a branch is outside this range, we have a choice of two
543 ;; For PIC, an out-of-range branch like:
548 ;; becomes the equivalent of:
557 ;; The non-PIC case is similar except that we use a direct
558 ;; jump instead of an la/jr pair. Since the target of this
559 ;; jump is an absolute 28-bit bit address (the other bits
560 ;; coming from the address of the delay slot) this form cannot
561 ;; cross a 256MB boundary. We could provide the option of
562 ;; using la/jr in this case too, but we do not do so at
565 ;; The value we specify here does not account for the delay slot
566 ;; instruction, whose length is added separately. If the RTL
567 ;; pattern has no explicit delay slot, mips_adjust_insn_length
568 ;; will add the length of the implicit nop. The range of
569 ;; [-0x20000, 0x1fffc] from the address of the delay slot
570 ;; therefore translates to a range of:
572 ;; [-(0x20000 - sizeof (branch)), 0x1fffc - sizeof (slot)]
573 ;; == [-0x1fffc, 0x1fff8]
575 ;; from the shorten_branches reference address.
576 (and (eq_attr "type" "branch")
577 (not (match_test "TARGET_MIPS16")))
578 (cond [;; Any variant can handle the 17-bit range.
579 (and (le (minus (match_dup 0) (pc)) (const_int 65532))
580 (le (minus (pc) (match_dup 0)) (const_int 65534)))
583 ;; The 18-bit range is OK other than for microMIPS.
584 (and (not (match_test "TARGET_MICROMIPS"))
585 (and (le (minus (match_dup 0) (pc)) (const_int 131064))
586 (le (minus (pc) (match_dup 0)) (const_int 131068))))
589 ;; The non-PIC case: branch, first delay slot, and J.
590 (match_test "TARGET_ABSOLUTE_JUMPS")
593 ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
594 ;; mips_adjust_insn_length substitutes the correct length.
596 ;; Note that we can't simply use (symbol_ref ...) here
597 ;; because genattrtab needs to know the maximum length
599 (const_int MAX_PIC_BRANCH_LENGTH))
601 ;; An unextended MIPS16 branch has a range of [-0x100, 0xfe]
602 ;; from the address of the following instruction, which leads
605 ;; [-(0x100 - sizeof (branch)), 0xfe]
608 ;; from the shorten_branches reference address. Extended branches
609 ;; likewise have a range of [-0x10000, 0xfffe] from the address
610 ;; of the following instruction, which leads to a range of:
612 ;; [-(0x10000 - sizeof (branch)), 0xfffe]
613 ;; == [-0xfffc, 0xfffe]
615 ;; from the reference address.
617 ;; When a branch is out of range, mips_reorg splits it into a form
618 ;; that uses in-range branches. There are four basic sequences:
620 ;; (1) Absolute addressing with a readable text segment
621 ;; (32-bit addresses):
624 ;; move $1,$2 2 bytes
625 ;; lw $2,label 2 bytes
627 ;; move $2,$1 2 bytes
628 ;; .align 2 0 or 2 bytes
630 ;; .word target 4 bytes
632 ;; (16 bytes in the worst case)
634 ;; (2) Absolute addressing with a readable text segment
635 ;; (64-bit addresses):
638 ;; move $1,$2 2 bytes
639 ;; ld $2,label 2 bytes
641 ;; move $2,$1 2 bytes
642 ;; .align 3 0 to 6 bytes
644 ;; .dword target 8 bytes
646 ;; (24 bytes in the worst case)
648 ;; (3) Absolute addressing without a readable text segment
649 ;; (which requires 32-bit addresses at present):
652 ;; move $1,$2 2 bytes
653 ;; lui $2,%hi(target) 4 bytes
656 ;; addiu $2,%lo(target) 4 bytes
658 ;; move $2,$1 2 bytes
662 ;; (4) PIC addressing (which requires 32-bit addresses at present):
665 ;; move $1,$2 2 bytes
666 ;; lw $2,cprestore 0, 2 or 4 bytes
667 ;; lw $2,%got(target)($2) 4 bytes
668 ;; addiu $2,%lo(target) 4 bytes
670 ;; move $2,$1 2 bytes
672 ;; (20 bytes in the worst case)
673 (and (eq_attr "type" "branch")
674 (match_test "TARGET_MIPS16"))
675 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
676 (le (minus (pc) (match_dup 0)) (const_int 254)))
678 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
679 (le (minus (pc) (match_dup 0)) (const_int 65532)))
681 (and (match_test "TARGET_ABICALLS")
682 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
684 (match_test "Pmode == SImode")
687 (symbol_ref "get_attr_insn_count (insn) * BASE_INSN_LENGTH")))
689 ;; Attribute describing the processor.
690 (define_enum_attr "cpu" "processor"
691 (const (symbol_ref "mips_tune")))
693 ;; The type of hardware hazard associated with this instruction.
694 ;; DELAY means that the next instruction cannot read the result
695 ;; of this one. HILO means that the next two instructions cannot
696 ;; write to HI or LO.
697 (define_attr "hazard" "none,delay,hilo"
698 (cond [(and (eq_attr "type" "load,fpload,fpidxload")
699 (match_test "ISA_HAS_LOAD_DELAY"))
700 (const_string "delay")
702 (and (eq_attr "type" "mfc,mtc")
703 (match_test "ISA_HAS_XFER_DELAY"))
704 (const_string "delay")
706 (and (eq_attr "type" "fcmp")
707 (match_test "ISA_HAS_FCMP_DELAY"))
708 (const_string "delay")
710 ;; The r4000 multiplication patterns include an mflo instruction.
711 (and (eq_attr "type" "imul")
712 (match_test "TARGET_FIX_R4000"))
713 (const_string "hilo")
715 (and (eq_attr "type" "mfhi,mflo")
716 (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
717 (const_string "hilo")]
718 (const_string "none")))
720 ;; Can the instruction be put into a delay slot?
721 (define_attr "can_delay" "no,yes"
722 (if_then_else (and (eq_attr "type" "!branch,call,jump")
723 (eq_attr "hazard" "none")
724 (match_test "get_attr_insn_count (insn) == 1"))
726 (const_string "no")))
728 ;; Attribute defining whether or not we can use the branch-likely
730 (define_attr "branch_likely" "no,yes"
731 (if_then_else (match_test "GENERATE_BRANCHLIKELY")
733 (const_string "no")))
735 ;; True if an instruction might assign to hi or lo when reloaded.
736 ;; This is used by the TUNE_MACC_CHAINS code.
737 (define_attr "may_clobber_hilo" "no,yes"
738 (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthi,mtlo")
740 (const_string "no")))
742 ;; Describe a user's asm statement.
743 (define_asm_attributes
744 [(set_attr "type" "multi")
745 (set_attr "can_delay" "no")])
747 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
748 ;; from the same template.
749 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
751 ;; A copy of GPR that can be used when a pattern has two independent
753 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
755 (define_mode_iterator MOVEP1 [SI SF])
756 (define_mode_iterator MOVEP2 [SI SF])
758 ;; This mode iterator allows :HILO to be used as the mode of the
759 ;; concatenated HI and LO registers.
760 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
762 ;; This mode iterator allows :P to be used for patterns that operate on
763 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
764 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
766 ;; This mode iterator allows :MOVECC to be used anywhere that a
767 ;; conditional-move-type condition is needed.
768 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
769 (CC "TARGET_HARD_FLOAT
770 && !TARGET_LOONGSON_2EF
771 && !TARGET_MIPS5900")])
773 ;; This mode iterator allows :FPCC to be used anywhere that an FP condition
775 (define_mode_iterator FPCC [(CC "!ISA_HAS_CCF")
776 (CCF "ISA_HAS_CCF")])
778 ;; 32-bit integer moves for which we provide move patterns.
779 (define_mode_iterator IMOVE32
788 (V4UQQ "TARGET_DSP")])
790 ;; 64-bit modes for which we provide move patterns.
791 (define_mode_iterator MOVE64
793 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
794 (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
795 (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
796 (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")])
798 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
799 (define_mode_iterator MOVE128 [TI TF])
801 ;; This mode iterator allows the QI and HI extension patterns to be
802 ;; defined from the same template.
803 (define_mode_iterator SHORT [QI HI])
805 ;; Likewise the 64-bit truncate-and-shift patterns.
806 (define_mode_iterator SUBDI [QI HI SI])
808 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
809 ;; floating-point mode is allowed.
810 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
811 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
812 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
814 ;; Like ANYF, but only applies to scalar modes.
815 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
816 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
818 ;; A floating-point mode for which moves involving FPRs may need to be split.
819 (define_mode_iterator SPLITF
820 [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
821 (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
822 (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
823 (V2SI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
824 (V4HI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
825 (V8QI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
826 (TF "TARGET_64BIT && TARGET_FLOAT64")])
828 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
829 ;; 32-bit version and "dsubu" in the 64-bit version.
830 (define_mode_attr d [(SI "") (DI "d")
831 (QQ "") (HQ "") (SQ "") (DQ "d")
832 (UQQ "") (UHQ "") (USQ "") (UDQ "d")
833 (HA "") (SA "") (DA "d")
834 (UHA "") (USA "") (UDA "d")])
836 ;; Same as d but upper-case.
837 (define_mode_attr D [(SI "") (DI "D")
838 (QQ "") (HQ "") (SQ "") (DQ "D")
839 (UQQ "") (UHQ "") (USQ "") (UDQ "D")
840 (HA "") (SA "") (DA "D")
841 (UHA "") (USA "") (UDA "D")])
843 ;; This attribute gives the length suffix for a load or store instruction.
844 ;; The same suffixes work for zero and sign extensions.
845 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
846 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
848 ;; This attributes gives the mode mask of a SHORT.
849 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
851 ;; Mode attributes for GPR loads.
852 (define_mode_attr load [(SI "lw") (DI "ld")])
853 ;; Instruction names for stores.
854 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
856 ;; Similarly for MIPS IV indexed FPR loads and stores.
857 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
858 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
860 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
861 ;; are different. Some forms of unextended addiu have an 8-bit immediate
862 ;; field but the equivalent daddiu has only a 5-bit field.
863 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
865 ;; This attribute gives the best constraint to use for registers of
867 (define_mode_attr reg [(SI "d") (DI "d") (CC "z") (CCF "f")])
869 ;; This attribute gives the format suffix for floating-point operations.
870 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
872 ;; This attribute gives the upper-case mode name for one unit of a
873 ;; floating-point mode.
874 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
876 ;; This attribute gives the integer mode that has the same size as a
878 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
879 (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
880 (HA "HI") (SA "SI") (DA "DI")
881 (UHA "HI") (USA "SI") (UDA "DI")
882 (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
883 (V2HQ "SI") (V2HA "SI")])
885 ;; This attribute gives the integer mode that has half the size of
886 ;; the controlling mode.
887 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
888 (V2SI "SI") (V4HI "SI") (V8QI "SI")
891 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
893 ;; In certain cases, div.s and div.ps may have a rounding error
894 ;; and/or wrong inexact flag.
896 ;; Therefore, we only allow div.s if not working around SB-1 rev2
897 ;; errata or if a slight loss of precision is OK.
898 (define_mode_attr divide_condition
899 [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
900 (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
902 ;; This attribute gives the conditions under which SQRT.fmt instructions
904 (define_mode_attr sqrt_condition
905 [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
907 ;; This attribute provides the correct mnemonic for each FP condition mode.
908 (define_mode_attr fpcmp [(CC "c") (CCF "cmp")])
910 ;; This code iterator allows signed and unsigned widening multiplications
911 ;; to use the same template.
912 (define_code_iterator any_extend [sign_extend zero_extend])
914 ;; This code iterator allows the two right shift instructions to be
915 ;; generated from the same template.
916 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
918 ;; This code iterator allows the three shift instructions to be generated
919 ;; from the same template.
920 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
922 ;; This code iterator allows unsigned and signed division to be generated
923 ;; from the same template.
924 (define_code_iterator any_div [div udiv])
926 ;; This code iterator allows unsigned and signed modulus to be generated
927 ;; from the same template.
928 (define_code_iterator any_mod [mod umod])
930 ;; This code iterator allows all native floating-point comparisons to be
931 ;; generated from the same template.
932 (define_code_iterator fcond [unordered uneq unlt unle eq lt le
933 (ordered "ISA_HAS_CCF")
937 ;; This code iterator is used for comparisons that can be implemented
938 ;; by swapping the operands.
939 (define_code_iterator swapped_fcond [ge gt unge ungt])
941 ;; Equality operators.
942 (define_code_iterator equality_op [eq ne])
944 ;; These code iterators allow the signed and unsigned scc operations to use
945 ;; the same template.
946 (define_code_iterator any_gt [gt gtu])
947 (define_code_iterator any_ge [ge geu])
948 (define_code_iterator any_lt [lt ltu])
949 (define_code_iterator any_le [le leu])
951 (define_code_iterator any_return [return simple_return])
953 ;; <u> expands to an empty string when doing a signed operation and
954 ;; "u" when doing an unsigned operation.
955 (define_code_attr u [(sign_extend "") (zero_extend "u")
963 ;; <U> is like <u> except uppercase.
964 (define_code_attr U [(sign_extend "") (zero_extend "U")])
966 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
967 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
969 ;; <optab> expands to the name of the optab for a particular code.
970 (define_code_attr optab [(ashift "ashl")
979 (simple_return "simple_return")])
981 ;; <insn> expands to the name of the insn that implements a particular code.
982 (define_code_attr insn [(ashift "sll")
991 ;; <immediate_insn> expands to the name of the insn that implements
992 ;; a particular code to operate on immediate values.
993 (define_code_attr immediate_insn [(ior "ori")
997 (define_code_attr shift_compression [(ashift "micromips32")
998 (lshiftrt "micromips32")
1001 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
1002 (define_code_attr fcond [(unordered "un")
1013 ;; Similar, but for swapped conditions.
1014 (define_code_attr swapped_fcond [(ge "le")
1019 ;; The value of the bit when the branch is taken for branch_bit patterns.
1020 ;; Comparison is always against zero so this depends on the operator.
1021 (define_code_attr bbv [(eq "0") (ne "1")])
1023 ;; This is the inverse value of bbv.
1024 (define_code_attr bbinv [(eq "1") (ne "0")])
1026 ;; The sel mnemonic to use depending on the condition test.
1027 (define_code_attr sel [(eq "seleqz") (ne "selnez")])
1028 (define_code_attr selinv [(eq "selnez") (ne "seleqz")])
1030 ;; .........................
1032 ;; Branch, call and jump delay slots
1034 ;; .........................
1036 (define_delay (and (eq_attr "type" "branch")
1037 (not (match_test "TARGET_MIPS16"))
1038 (eq_attr "branch_likely" "yes"))
1039 [(eq_attr "can_delay" "yes")
1041 (eq_attr "can_delay" "yes")])
1043 ;; Branches that don't have likely variants do not annul on false.
1044 (define_delay (and (eq_attr "type" "branch")
1045 (not (match_test "TARGET_MIPS16"))
1046 (eq_attr "branch_likely" "no"))
1047 [(eq_attr "can_delay" "yes")
1051 (define_delay (eq_attr "type" "jump")
1052 [(eq_attr "can_delay" "yes")
1056 (define_delay (and (eq_attr "type" "call")
1057 (eq_attr "jal_macro" "no"))
1058 [(eq_attr "can_delay" "yes")
1062 ;; Pipeline descriptions.
1064 ;; generic.md provides a fallback for processors without a specific
1065 ;; pipeline description. It is derived from the old define_function_unit
1066 ;; version and uses the "alu" and "imuldiv" units declared below.
1068 ;; Some of the processor-specific files are also derived from old
1069 ;; define_function_unit descriptions and simply override the parts of
1070 ;; generic.md that don't apply. The other processor-specific files
1071 ;; are self-contained.
1072 (define_automaton "alu,imuldiv")
1074 (define_cpu_unit "alu" "alu")
1075 (define_cpu_unit "imuldiv" "imuldiv")
1077 ;; Ghost instructions produce no real code and introduce no hazards.
1078 ;; They exist purely to express an effect on dataflow.
1079 (define_insn_reservation "ghost" 0
1080 (eq_attr "type" "ghost")
1083 (include "p5600.md")
1101 (include "10000.md")
1102 (include "loongson2ef.md")
1103 (include "loongson3a.md")
1104 (include "octeon.md")
1106 (include "sr71k.md")
1109 (include "generic.md")
1112 ;; ....................
1114 ;; CONDITIONAL TRAPS
1116 ;; ....................
1120 [(trap_if (const_int 1) (const_int 0))]
1123 if (ISA_HAS_COND_TRAP)
1124 return "teq\t$0,$0";
1125 else if (TARGET_MIPS16)
1130 [(set_attr "type" "trap")])
1132 (define_expand "ctrap<mode>4"
1133 [(trap_if (match_operator 0 "comparison_operator"
1134 [(match_operand:GPR 1 "reg_or_0_operand")
1135 (match_operand:GPR 2 "arith_operand")])
1136 (match_operand 3 "const_0_operand"))]
1137 "ISA_HAS_COND_TRAPI || ISA_HAS_COND_TRAP"
1139 mips_expand_conditional_trap (operands[0]);
1143 (define_insn "*conditional_trap_reg<mode>"
1144 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1145 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1146 (match_operand:GPR 2 "reg_or_0_operand" "dJ")])
1148 "ISA_HAS_COND_TRAP && !ISA_HAS_COND_TRAPI"
1150 [(set_attr "type" "trap")])
1152 (define_insn "*conditional_trap<mode>"
1153 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1154 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1155 (match_operand:GPR 2 "arith_operand" "dI")])
1157 "ISA_HAS_COND_TRAPI"
1159 [(set_attr "type" "trap")])
1162 ;; ....................
1166 ;; ....................
1169 (define_insn "add<mode>3"
1170 [(set (match_operand:ANYF 0 "register_operand" "=f")
1171 (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1172 (match_operand:ANYF 2 "register_operand" "f")))]
1174 "add.<fmt>\t%0,%1,%2"
1175 [(set_attr "type" "fadd")
1176 (set_attr "mode" "<UNITMODE>")])
1178 (define_expand "add<mode>3"
1179 [(set (match_operand:GPR 0 "register_operand")
1180 (plus:GPR (match_operand:GPR 1 "register_operand")
1181 (match_operand:GPR 2 "arith_operand")))]
1184 (define_insn "*add<mode>3"
1185 [(set (match_operand:GPR 0 "register_operand" "=!u,d,!u,!u,!ks,!d,d")
1186 (plus:GPR (match_operand:GPR 1 "register_operand" "!u,d,!u,!ks,!ks,0,d")
1187 (match_operand:GPR 2 "arith_operand" "!u,d,Uead,Uuw6,Uesp,Usb4,Q")))]
1190 if (which_alternative == 0
1191 || which_alternative == 1)
1192 return "<d>addu\t%0,%1,%2";
1194 return "<d>addiu\t%0,%1,%2";
1196 [(set_attr "alu_type" "add")
1197 (set_attr "compression" "micromips32,*,micromips32,micromips32,micromips32,micromips32,*")
1198 (set_attr "mode" "<MODE>")])
1200 (define_insn "*add<mode>3_mips16"
1201 [(set (match_operand:GPR 0 "register_operand" "=ks,ks,d,d,d,d,d,d,d")
1202 (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,ks,ks,0,0,d,d,d")
1203 (match_operand:GPR 2 "arith_operand" "Usd8,Q,Uuw<si8_di5>,Q,Usb<si8_di5>,Q,Usb4,O,d")))]
1215 [(set_attr "alu_type" "add")
1216 (set_attr "mode" "<MODE>")
1217 (set_attr "extended_mips16" "no,yes,no,yes,no,yes,no,yes,no")])
1219 ;; On the mips16, we can sometimes split an add of a constant which is
1220 ;; a 4 byte instruction into two adds which are both 2 byte
1221 ;; instructions. There are two cases: one where we are adding a
1222 ;; constant plus a register to another register, and one where we are
1223 ;; simply adding a constant to a register.
1226 [(set (match_operand:SI 0 "d_operand")
1227 (plus:SI (match_dup 0)
1228 (match_operand:SI 1 "const_int_operand")))]
1229 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1230 && ((INTVAL (operands[1]) > 0x7f
1231 && INTVAL (operands[1]) <= 0x7f + 0x7f)
1232 || (INTVAL (operands[1]) < - 0x80
1233 && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1234 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1235 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1237 HOST_WIDE_INT val = INTVAL (operands[1]);
1241 operands[1] = GEN_INT (0x7f);
1242 operands[2] = GEN_INT (val - 0x7f);
1246 operands[1] = GEN_INT (- 0x80);
1247 operands[2] = GEN_INT (val + 0x80);
1252 [(set (match_operand:SI 0 "d_operand")
1253 (plus:SI (match_operand:SI 1 "d_operand")
1254 (match_operand:SI 2 "const_int_operand")))]
1255 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1256 && REGNO (operands[0]) != REGNO (operands[1])
1257 && ((INTVAL (operands[2]) > 0x7
1258 && INTVAL (operands[2]) <= 0x7 + 0x7f)
1259 || (INTVAL (operands[2]) < - 0x8
1260 && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1261 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1262 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1264 HOST_WIDE_INT val = INTVAL (operands[2]);
1268 operands[2] = GEN_INT (0x7);
1269 operands[3] = GEN_INT (val - 0x7);
1273 operands[2] = GEN_INT (- 0x8);
1274 operands[3] = GEN_INT (val + 0x8);
1279 [(set (match_operand:DI 0 "d_operand")
1280 (plus:DI (match_dup 0)
1281 (match_operand:DI 1 "const_int_operand")))]
1282 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1283 && ((INTVAL (operands[1]) > 0xf
1284 && INTVAL (operands[1]) <= 0xf + 0xf)
1285 || (INTVAL (operands[1]) < - 0x10
1286 && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1287 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1288 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1290 HOST_WIDE_INT val = INTVAL (operands[1]);
1294 operands[1] = GEN_INT (0xf);
1295 operands[2] = GEN_INT (val - 0xf);
1299 operands[1] = GEN_INT (- 0x10);
1300 operands[2] = GEN_INT (val + 0x10);
1305 [(set (match_operand:DI 0 "d_operand")
1306 (plus:DI (match_operand:DI 1 "d_operand")
1307 (match_operand:DI 2 "const_int_operand")))]
1308 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1309 && REGNO (operands[0]) != REGNO (operands[1])
1310 && ((INTVAL (operands[2]) > 0x7
1311 && INTVAL (operands[2]) <= 0x7 + 0xf)
1312 || (INTVAL (operands[2]) < - 0x8
1313 && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1314 [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1315 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1317 HOST_WIDE_INT val = INTVAL (operands[2]);
1321 operands[2] = GEN_INT (0x7);
1322 operands[3] = GEN_INT (val - 0x7);
1326 operands[2] = GEN_INT (- 0x8);
1327 operands[3] = GEN_INT (val + 0x8);
1331 (define_insn "*addsi3_extended"
1332 [(set (match_operand:DI 0 "register_operand" "=d,d")
1334 (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1335 (match_operand:SI 2 "arith_operand" "d,Q"))))]
1336 "TARGET_64BIT && !TARGET_MIPS16"
1340 [(set_attr "alu_type" "add")
1341 (set_attr "mode" "SI")])
1343 ;; Split this insn so that the addiu splitters can have a crack at it.
1344 ;; Use a conservative length estimate until the split.
1345 (define_insn_and_split "*addsi3_extended_mips16"
1346 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1348 (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1349 (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1350 "TARGET_64BIT && TARGET_MIPS16"
1352 "&& reload_completed"
1353 [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1354 { operands[3] = gen_lowpart (SImode, operands[0]); }
1355 [(set_attr "alu_type" "add")
1356 (set_attr "mode" "SI")
1357 (set_attr "extended_mips16" "yes")])
1359 ;; Combiner patterns for unsigned byte-add.
1361 (define_insn "*baddu_si_eb"
1362 [(set (match_operand:SI 0 "register_operand" "=d")
1365 (plus:SI (match_operand:SI 1 "register_operand" "d")
1366 (match_operand:SI 2 "register_operand" "d")) 3)))]
1367 "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1369 [(set_attr "alu_type" "add")])
1371 (define_insn "*baddu_si_el"
1372 [(set (match_operand:SI 0 "register_operand" "=d")
1375 (plus:SI (match_operand:SI 1 "register_operand" "d")
1376 (match_operand:SI 2 "register_operand" "d")) 0)))]
1377 "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1379 [(set_attr "alu_type" "add")])
1381 (define_insn "*baddu_di<mode>"
1382 [(set (match_operand:GPR 0 "register_operand" "=d")
1385 (plus:DI (match_operand:DI 1 "register_operand" "d")
1386 (match_operand:DI 2 "register_operand" "d")))))]
1387 "ISA_HAS_BADDU && TARGET_64BIT"
1389 [(set_attr "alu_type" "add")])
1392 ;; ....................
1396 ;; ....................
1399 (define_insn "sub<mode>3"
1400 [(set (match_operand:ANYF 0 "register_operand" "=f")
1401 (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1402 (match_operand:ANYF 2 "register_operand" "f")))]
1404 "sub.<fmt>\t%0,%1,%2"
1405 [(set_attr "type" "fadd")
1406 (set_attr "mode" "<UNITMODE>")])
1408 (define_insn "sub<mode>3"
1409 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
1410 (minus:GPR (match_operand:GPR 1 "register_operand" "!u,d")
1411 (match_operand:GPR 2 "register_operand" "!u,d")))]
1414 [(set_attr "alu_type" "sub")
1415 (set_attr "compression" "micromips32,*")
1416 (set_attr "mode" "<MODE>")])
1418 (define_insn "*subsi3_extended"
1419 [(set (match_operand:DI 0 "register_operand" "=d")
1421 (minus:SI (match_operand:SI 1 "register_operand" "d")
1422 (match_operand:SI 2 "register_operand" "d"))))]
1425 [(set_attr "alu_type" "sub")
1426 (set_attr "mode" "DI")])
1429 ;; ....................
1433 ;; ....................
1436 (define_expand "mul<mode>3"
1437 [(set (match_operand:SCALARF 0 "register_operand")
1438 (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1439 (match_operand:SCALARF 2 "register_operand")))]
1443 (define_insn "*mul<mode>3"
1444 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1445 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1446 (match_operand:SCALARF 2 "register_operand" "f")))]
1447 "!TARGET_4300_MUL_FIX"
1448 "mul.<fmt>\t%0,%1,%2"
1449 [(set_attr "type" "fmul")
1450 (set_attr "mode" "<MODE>")])
1452 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1453 ;; operands may corrupt immediately following multiplies. This is a
1454 ;; simple fix to insert NOPs.
1456 (define_insn "*mul<mode>3_r4300"
1457 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1458 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1459 (match_operand:SCALARF 2 "register_operand" "f")))]
1460 "TARGET_4300_MUL_FIX"
1461 "mul.<fmt>\t%0,%1,%2\;nop"
1462 [(set_attr "type" "fmul")
1463 (set_attr "mode" "<MODE>")
1464 (set_attr "insn_count" "2")])
1466 (define_insn "mulv2sf3"
1467 [(set (match_operand:V2SF 0 "register_operand" "=f")
1468 (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1469 (match_operand:V2SF 2 "register_operand" "f")))]
1470 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1472 [(set_attr "type" "fmul")
1473 (set_attr "mode" "SF")])
1475 ;; The original R4000 has a cpu bug. If a double-word or a variable
1476 ;; shift executes while an integer multiplication is in progress, the
1477 ;; shift may give an incorrect result. Avoid this by keeping the mflo
1478 ;; with the mult on the R4000.
1480 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1481 ;; (also valid for MIPS R4000MC processors):
1483 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1484 ;; this errata description.
1485 ;; The following code sequence causes the R4000 to incorrectly
1486 ;; execute the Double Shift Right Arithmetic 32 (dsra32)
1487 ;; instruction. If the dsra32 instruction is executed during an
1488 ;; integer multiply, the dsra32 will only shift by the amount in
1489 ;; specified in the instruction rather than the amount plus 32
1491 ;; instruction 1: mult rs,rt integer multiply
1492 ;; instruction 2-12: dsra32 rd,rt,rs doubleword shift
1493 ;; right arithmetic + 32
1494 ;; Workaround: A dsra32 instruction placed after an integer
1495 ;; multiply should not be one of the 11 instructions after the
1496 ;; multiply instruction."
1500 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1501 ;; the following description.
1502 ;; All extended shifts (shift by n+32) and variable shifts (32 and
1503 ;; 64-bit versions) may produce incorrect results under the
1504 ;; following conditions:
1505 ;; 1) An integer multiply is currently executing
1506 ;; 2) These types of shift instructions are executed immediately
1507 ;; following an integer divide instruction.
1509 ;; 1) Make sure no integer multiply is running wihen these
1510 ;; instruction are executed. If this cannot be predicted at
1511 ;; compile time, then insert a "mfhi" to R0 instruction
1512 ;; immediately after the integer multiply instruction. This
1513 ;; will cause the integer multiply to complete before the shift
1515 ;; 2) Separate integer divide and these two classes of shift
1516 ;; instructions by another instruction or a noop."
1518 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1521 (define_expand "mul<mode>3"
1522 [(set (match_operand:GPR 0 "register_operand")
1523 (mult:GPR (match_operand:GPR 1 "register_operand")
1524 (match_operand:GPR 2 "register_operand")))]
1525 "ISA_HAS_<D>MULT || ISA_HAS_R6<D>MUL"
1529 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>MUL)
1530 emit_insn (gen_mul<mode>3_mul3_nohilo (operands[0], operands[1],
1532 else if (ISA_HAS_<D>MUL3)
1533 emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1534 else if (TARGET_MIPS16)
1536 lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1537 emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1538 emit_move_insn (operands[0], lo);
1540 else if (TARGET_FIX_R4000)
1541 emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1544 (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1548 (define_insn "mul<mode>3_mul3_nohilo"
1549 [(set (match_operand:GPR 0 "register_operand" "=d")
1550 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1551 (match_operand:GPR 2 "register_operand" "d")))]
1552 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>MUL"
1554 if (TARGET_LOONGSON_2EF)
1555 return "<d>multu.g\t%0,%1,%2";
1556 else if (TARGET_LOONGSON_3A)
1557 return "gs<d>multu\t%0,%1,%2";
1559 return "<d>mul\t%0,%1,%2";
1561 [(set_attr "type" "imul3nc")
1562 (set_attr "mode" "<MODE>")])
1564 (define_insn "mul<mode>3_mul3"
1565 [(set (match_operand:GPR 0 "register_operand" "=d,l")
1566 (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1567 (match_operand:GPR 2 "register_operand" "d,d")))
1568 (clobber (match_scratch:GPR 3 "=l,X"))]
1571 if (which_alternative == 1)
1572 return "<d>mult\t%1,%2";
1573 if (<MODE>mode == SImode && (TARGET_MIPS3900 || TARGET_MIPS5900))
1574 return "mult\t%0,%1,%2";
1575 return "<d>mul\t%0,%1,%2";
1577 [(set_attr "type" "imul3,imul")
1578 (set_attr "mode" "<MODE>")])
1580 ;; If a register gets allocated to LO, and we spill to memory, the reload
1581 ;; will include a move from LO to a GPR. Merge it into the multiplication
1582 ;; if it can set the GPR directly.
1585 ;; Operand 1: GPR (1st multiplication operand)
1586 ;; Operand 2: GPR (2nd multiplication operand)
1587 ;; Operand 3: GPR (destination)
1590 [(set (match_operand:SI 0 "lo_operand")
1591 (mult:SI (match_operand:SI 1 "d_operand")
1592 (match_operand:SI 2 "d_operand")))
1593 (clobber (scratch:SI))])
1594 (set (match_operand:SI 3 "d_operand")
1596 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1599 (mult:SI (match_dup 1)
1601 (clobber (match_dup 0))])])
1603 (define_insn "mul<mode>3_internal"
1604 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1605 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1606 (match_operand:GPR 2 "register_operand" "d")))]
1607 "ISA_HAS_<D>MULT && !TARGET_FIX_R4000"
1609 [(set_attr "type" "imul")
1610 (set_attr "mode" "<MODE>")])
1612 (define_insn "mul<mode>3_r4000"
1613 [(set (match_operand:GPR 0 "register_operand" "=d")
1614 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1615 (match_operand:GPR 2 "register_operand" "d")))
1616 (clobber (match_scratch:GPR 3 "=l"))]
1617 "ISA_HAS_<D>MULT && TARGET_FIX_R4000"
1618 "<d>mult\t%1,%2\;mflo\t%0"
1619 [(set_attr "type" "imul")
1620 (set_attr "mode" "<MODE>")
1621 (set_attr "insn_count" "2")])
1623 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1624 ;; of "mult; mflo". They have the same latency, but the first form gives
1625 ;; us an extra cycle to compute the operands.
1628 ;; Operand 1: GPR (1st multiplication operand)
1629 ;; Operand 2: GPR (2nd multiplication operand)
1630 ;; Operand 3: GPR (destination)
1632 [(set (match_operand:SI 0 "lo_operand")
1633 (mult:SI (match_operand:SI 1 "d_operand")
1634 (match_operand:SI 2 "d_operand")))
1635 (set (match_operand:SI 3 "d_operand")
1637 "ISA_HAS_MACC && !ISA_HAS_MUL3"
1642 (plus:SI (mult:SI (match_dup 1)
1646 (plus:SI (mult:SI (match_dup 1)
1650 ;; Multiply-accumulate patterns
1652 ;; This pattern is first matched by combine, which tries to use the
1653 ;; pattern wherever it can. We don't know until later whether it
1654 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1655 ;; so we need to keep both options open.
1657 ;; The second alternative has a "?" marker because it is generally
1658 ;; one instruction more costly than the first alternative. This "?"
1659 ;; marker is enough to convey the relative costs to the register
1662 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1663 ;; reloads of the other operands, even though operands 4 and 5 need no
1664 ;; copy instructions. Reload therefore thinks that the second alternative
1665 ;; is two reloads more costly than the first. We add "*?*?" to the first
1666 ;; alternative as a counterweight.
1668 ;; LRA simulates reload but the cost of reloading scratches is lower
1669 ;; than of the classic reload. For the time being, removing the counterweight
1670 ;; for LRA is more profitable.
1671 (define_insn "*mul_acc_si"
1672 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1673 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1674 (match_operand:SI 2 "register_operand" "d,d,d"))
1675 (match_operand:SI 3 "register_operand" "0,0,d")))
1676 (clobber (match_scratch:SI 4 "=X,X,l"))
1677 (clobber (match_scratch:SI 5 "=X,X,&d"))]
1678 "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1683 [(set_attr "type" "imadd")
1684 (set_attr "accum_in" "3")
1685 (set_attr "mode" "SI")
1686 (set_attr "insn_count" "1,1,2")
1687 (set (attr "enabled")
1688 (cond [(and (eq_attr "alternative" "0")
1689 (match_test "!mips_lra_flag"))
1690 (const_string "yes")
1691 (and (eq_attr "alternative" "1")
1692 (match_test "mips_lra_flag"))
1693 (const_string "yes")
1694 (eq_attr "alternative" "2")
1695 (const_string "yes")]
1696 (const_string "no")))])
1698 ;; The same idea applies here. The middle alternative needs one less
1699 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1700 (define_insn "*mul_acc_si_r3900"
1701 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d*?,d?")
1702 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d,d")
1703 (match_operand:SI 2 "register_operand" "d,d,d,d"))
1704 (match_operand:SI 3 "register_operand" "0,0,l,d")))
1705 (clobber (match_scratch:SI 4 "=X,X,3,l"))
1706 (clobber (match_scratch:SI 5 "=X,X,X,&d"))]
1707 "TARGET_MIPS3900 && !TARGET_MIPS16"
1713 [(set_attr "type" "imadd")
1714 (set_attr "accum_in" "3")
1715 (set_attr "mode" "SI")
1716 (set_attr "insn_count" "1,1,1,2")
1717 (set (attr "enabled")
1718 (cond [(and (eq_attr "alternative" "0")
1719 (match_test "!mips_lra_flag"))
1720 (const_string "yes")
1721 (and (eq_attr "alternative" "1")
1722 (match_test "mips_lra_flag"))
1723 (const_string "yes")
1724 (eq_attr "alternative" "2,3")
1725 (const_string "yes")]
1726 (const_string "no")))])
1728 ;; Split *mul_acc_si if both the source and destination accumulator
1731 [(set (match_operand:SI 0 "d_operand")
1732 (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1733 (match_operand:SI 2 "d_operand"))
1734 (match_operand:SI 3 "d_operand")))
1735 (clobber (match_operand:SI 4 "lo_operand"))
1736 (clobber (match_operand:SI 5 "d_operand"))]
1738 [(parallel [(set (match_dup 5)
1739 (mult:SI (match_dup 1) (match_dup 2)))
1740 (clobber (match_dup 4))])
1741 (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1744 (define_insn "*macc"
1745 [(set (match_operand:SI 0 "register_operand" "=l,d")
1746 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1747 (match_operand:SI 2 "register_operand" "d,d"))
1748 (match_operand:SI 3 "register_operand" "0,l")))
1749 (clobber (match_scratch:SI 4 "=X,3"))]
1752 if (which_alternative == 1)
1753 return "macc\t%0,%1,%2";
1754 else if (TARGET_MIPS5500)
1755 return "madd\t%1,%2";
1757 /* The VR4130 assumes that there is a two-cycle latency between a macc
1758 that "writes" to $0 and an instruction that reads from it. We avoid
1759 this by assigning to $1 instead. */
1760 return "%[macc\t%@,%1,%2%]";
1762 [(set_attr "type" "imadd")
1763 (set_attr "accum_in" "3")
1764 (set_attr "mode" "SI")])
1766 (define_insn "*msac"
1767 [(set (match_operand:SI 0 "register_operand" "=l,d")
1768 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1769 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1770 (match_operand:SI 3 "register_operand" "d,d"))))
1771 (clobber (match_scratch:SI 4 "=X,1"))]
1774 if (which_alternative == 1)
1775 return "msac\t%0,%2,%3";
1776 else if (TARGET_MIPS5500)
1777 return "msub\t%2,%3";
1779 return "msac\t$0,%2,%3";
1781 [(set_attr "type" "imadd")
1782 (set_attr "accum_in" "1")
1783 (set_attr "mode" "SI")])
1785 ;; An msac-like instruction implemented using negation and a macc.
1786 (define_insn_and_split "*msac_using_macc"
1787 [(set (match_operand:SI 0 "register_operand" "=l,d")
1788 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1789 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1790 (match_operand:SI 3 "register_operand" "d,d"))))
1791 (clobber (match_scratch:SI 4 "=X,1"))
1792 (clobber (match_scratch:SI 5 "=d,d"))]
1793 "ISA_HAS_MACC && !ISA_HAS_MSAC"
1795 "&& reload_completed"
1797 (neg:SI (match_dup 3)))
1800 (plus:SI (mult:SI (match_dup 2)
1803 (clobber (match_dup 4))])]
1805 [(set_attr "type" "imadd")
1806 (set_attr "accum_in" "1")
1807 (set_attr "insn_count" "2")])
1809 ;; Patterns generated by the define_peephole2 below.
1811 (define_insn "*macc2"
1812 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1813 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1814 (match_operand:SI 2 "register_operand" "d"))
1816 (set (match_operand:SI 3 "register_operand" "=d")
1817 (plus:SI (mult:SI (match_dup 1)
1820 "ISA_HAS_MACC && reload_completed"
1822 [(set_attr "type" "imadd")
1823 (set_attr "accum_in" "0")
1824 (set_attr "mode" "SI")])
1826 (define_insn "*msac2"
1827 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1828 (minus:SI (match_dup 0)
1829 (mult:SI (match_operand:SI 1 "register_operand" "d")
1830 (match_operand:SI 2 "register_operand" "d"))))
1831 (set (match_operand:SI 3 "register_operand" "=d")
1832 (minus:SI (match_dup 0)
1833 (mult:SI (match_dup 1)
1835 "ISA_HAS_MSAC && reload_completed"
1837 [(set_attr "type" "imadd")
1838 (set_attr "accum_in" "0")
1839 (set_attr "mode" "SI")])
1841 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1845 ;; Operand 1: macc/msac
1846 ;; Operand 2: GPR (destination)
1849 [(set (match_operand:SI 0 "lo_operand")
1850 (match_operand:SI 1 "macc_msac_operand"))
1851 (clobber (scratch:SI))])
1852 (set (match_operand:SI 2 "d_operand")
1855 [(parallel [(set (match_dup 0)
1860 ;; When we have a three-address multiplication instruction, it should
1861 ;; be faster to do a separate multiply and add, rather than moving
1862 ;; something into LO in order to use a macc instruction.
1864 ;; This peephole needs a scratch register to cater for the case when one
1865 ;; of the multiplication operands is the same as the destination.
1867 ;; Operand 0: GPR (scratch)
1869 ;; Operand 2: GPR (addend)
1870 ;; Operand 3: GPR (destination)
1871 ;; Operand 4: macc/msac
1872 ;; Operand 5: new multiplication
1873 ;; Operand 6: new addition/subtraction
1875 [(match_scratch:SI 0 "d")
1876 (set (match_operand:SI 1 "lo_operand")
1877 (match_operand:SI 2 "d_operand"))
1880 [(set (match_operand:SI 3 "d_operand")
1881 (match_operand:SI 4 "macc_msac_operand"))
1882 (clobber (match_dup 1))])]
1883 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1884 [(parallel [(set (match_dup 0)
1886 (clobber (match_dup 1))])
1890 operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1891 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1892 operands[2], operands[0]);
1895 ;; Same as above, except LO is the initial target of the macc.
1897 ;; Operand 0: GPR (scratch)
1899 ;; Operand 2: GPR (addend)
1900 ;; Operand 3: macc/msac
1901 ;; Operand 4: GPR (destination)
1902 ;; Operand 5: new multiplication
1903 ;; Operand 6: new addition/subtraction
1905 [(match_scratch:SI 0 "d")
1906 (set (match_operand:SI 1 "lo_operand")
1907 (match_operand:SI 2 "d_operand"))
1911 (match_operand:SI 3 "macc_msac_operand"))
1912 (clobber (scratch:SI))])
1914 (set (match_operand:SI 4 "d_operand")
1916 "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1917 [(parallel [(set (match_dup 0)
1919 (clobber (match_dup 1))])
1923 operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
1924 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
1925 operands[2], operands[0]);
1928 ;; See the comment above *mul_add_si for details.
1929 (define_insn "*mul_sub_si"
1930 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1931 (minus:SI (match_operand:SI 1 "register_operand" "0,0,d")
1932 (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
1933 (match_operand:SI 3 "register_operand" "d,d,d"))))
1934 (clobber (match_scratch:SI 4 "=X,X,l"))
1935 (clobber (match_scratch:SI 5 "=X,X,&d"))]
1936 "GENERATE_MADD_MSUB"
1941 [(set_attr "type" "imadd")
1942 (set_attr "accum_in" "1")
1943 (set_attr "mode" "SI")
1944 (set_attr "insn_count" "1,1,2")
1945 (set (attr "enabled")
1946 (cond [(and (eq_attr "alternative" "0")
1947 (match_test "!mips_lra_flag"))
1948 (const_string "yes")
1949 (and (eq_attr "alternative" "1")
1950 (match_test "mips_lra_flag"))
1951 (const_string "yes")
1952 (eq_attr "alternative" "2")
1953 (const_string "yes")]
1954 (const_string "no")))])
1956 ;; Split *mul_sub_si if both the source and destination accumulator
1959 [(set (match_operand:SI 0 "d_operand")
1960 (minus:SI (match_operand:SI 1 "d_operand")
1961 (mult:SI (match_operand:SI 2 "d_operand")
1962 (match_operand:SI 3 "d_operand"))))
1963 (clobber (match_operand:SI 4 "lo_operand"))
1964 (clobber (match_operand:SI 5 "d_operand"))]
1966 [(parallel [(set (match_dup 5)
1967 (mult:SI (match_dup 2) (match_dup 3)))
1968 (clobber (match_dup 4))])
1969 (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
1972 (define_insn "*muls"
1973 [(set (match_operand:SI 0 "register_operand" "=l,d")
1974 (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1975 (match_operand:SI 2 "register_operand" "d,d"))))
1976 (clobber (match_scratch:SI 3 "=X,l"))]
1981 [(set_attr "type" "imul,imul3")
1982 (set_attr "mode" "SI")])
1984 (define_expand "<u>mulsidi3"
1985 [(set (match_operand:DI 0 "register_operand")
1986 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1987 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1988 "mips_mulsidi3_gen_fn (<CODE>) != NULL"
1990 mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
1991 emit_insn (fn (operands[0], operands[1], operands[2]));
1995 (define_expand "<u>mulsidi3_32bit_r6"
1996 [(set (match_operand:DI 0 "register_operand")
1997 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1998 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1999 "!TARGET_64BIT && ISA_HAS_R6MUL"
2001 rtx dest = gen_reg_rtx (DImode);
2002 rtx low = mips_subword (dest, 0);
2003 rtx high = mips_subword (dest, 1);
2005 emit_insn (gen_mulsi3_mul3_nohilo (low, operands[1], operands[2]));
2006 emit_insn (gen_<su>mulsi3_highpart_r6 (high, operands[1], operands[2]));
2008 emit_move_insn (mips_subword (operands[0], 0), low);
2009 emit_move_insn (mips_subword (operands[0], 1), high);
2013 (define_expand "<u>mulsidi3_32bit_mips16"
2014 [(set (match_operand:DI 0 "register_operand")
2015 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2016 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2017 "!TARGET_64BIT && TARGET_MIPS16"
2021 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2022 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2023 emit_move_insn (operands[0], hilo);
2027 ;; As well as being named patterns, these instructions are used by the
2028 ;; __builtin_mips_mult<u>() functions. We must always make those functions
2029 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2030 (define_insn "<u>mulsidi3_32bit"
2031 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2032 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2033 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2034 "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP) && ISA_HAS_MULT"
2036 if (ISA_HAS_DSP_MULT)
2037 return "mult<u>\t%q0,%1,%2";
2039 return "mult<u>\t%1,%2";
2041 [(set_attr "type" "imul")
2042 (set_attr "mode" "SI")])
2044 (define_insn "<u>mulsidi3_32bit_r4000"
2045 [(set (match_operand:DI 0 "register_operand" "=d")
2046 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2047 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2048 (clobber (match_scratch:DI 3 "=x"))]
2049 "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP && ISA_HAS_MULT"
2050 "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2051 [(set_attr "type" "imul")
2052 (set_attr "mode" "SI")
2053 (set_attr "insn_count" "3")])
2055 (define_insn_and_split "<u>mulsidi3_64bit"
2056 [(set (match_operand:DI 0 "register_operand" "=d")
2057 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2058 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2059 (clobber (match_scratch:TI 3 "=x"))
2060 (clobber (match_scratch:DI 4 "=d"))]
2061 "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3
2062 && !TARGET_MIPS16 && ISA_HAS_MULT"
2064 "&& reload_completed"
2067 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2068 operands[2], operands[4]));
2071 [(set_attr "type" "imul")
2072 (set_attr "mode" "SI")
2073 (set (attr "insn_count")
2074 (if_then_else (match_test "ISA_HAS_EXT_INS")
2078 (define_expand "<u>mulsidi3_64bit_mips16"
2079 [(set (match_operand:DI 0 "register_operand")
2080 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2081 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2082 "TARGET_64BIT && TARGET_MIPS16"
2084 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2085 operands[2], gen_reg_rtx (DImode)));
2089 (define_expand "<u>mulsidi3_64bit_split"
2090 [(set (match_operand:DI 0 "register_operand")
2091 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2092 (any_extend:DI (match_operand:SI 2 "register_operand"))))
2093 (clobber (match_operand:DI 3 "register_operand"))]
2098 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2099 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2101 emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
2102 emit_insn (gen_mfhidi_ti (operands[3], hilo));
2104 if (ISA_HAS_EXT_INS)
2105 emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
2109 /* Zero-extend the low part. */
2110 mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
2111 mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
2113 /* Shift the high part into place. */
2114 mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
2116 /* OR the two halves together. */
2117 mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
2122 (define_insn "<u>mulsidi3_64bit_hilo"
2123 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2126 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2127 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
2129 "TARGET_64BIT && !TARGET_FIX_R4000"
2131 [(set_attr "type" "imul")
2132 (set_attr "mode" "SI")])
2134 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
2135 (define_insn "mulsidi3_64bit_dmul"
2136 [(set (match_operand:DI 0 "register_operand" "=d")
2137 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2138 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2139 (clobber (match_scratch:DI 3 "=l"))]
2142 [(set_attr "type" "imul3")
2143 (set_attr "mode" "DI")])
2145 (define_insn "mulsidi3_64bit_r6dmul"
2146 [(set (match_operand:DI 0 "register_operand" "=d")
2147 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2148 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2151 [(set_attr "type" "imul3nc")
2152 (set_attr "mode" "DI")])
2154 ;; Widening multiply with negation.
2155 (define_insn "*muls<u>_di"
2156 [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2159 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2160 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2161 "!TARGET_64BIT && ISA_HAS_MULS"
2163 [(set_attr "type" "imul")
2164 (set_attr "mode" "SI")])
2166 ;; As well as being named patterns, these instructions are used by the
2167 ;; __builtin_mips_msub<u>() functions. We must always make those functions
2168 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2170 ;; This leads to a slight inconsistency. We honor any tuning overrides
2171 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2172 ;; even if !ISA_HAS_DSP_MULT.
2173 (define_insn "<u>msubsidi4"
2174 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2176 (match_operand:DI 3 "muldiv_target_operand" "0")
2178 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2179 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2180 "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2182 if (ISA_HAS_DSP_MULT)
2183 return "msub<u>\t%q0,%1,%2";
2184 else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2185 return "msub<u>\t%1,%2";
2187 return "msac<u>\t$0,%1,%2";
2189 [(set_attr "type" "imadd")
2190 (set_attr "accum_in" "3")
2191 (set_attr "mode" "SI")])
2193 ;; _highpart patterns
2195 (define_expand "<su>mulsi3_highpart"
2196 [(set (match_operand:SI 0 "register_operand")
2199 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2200 (any_extend:DI (match_operand:SI 2 "register_operand")))
2205 emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2208 else if (TARGET_MIPS16)
2209 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2211 else if (ISA_HAS_R6MUL)
2212 emit_insn (gen_<su>mulsi3_highpart_r6 (operands[0], operands[1],
2215 emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2220 (define_insn "<su>mulsi3_highpart_r6"
2221 [(set (match_operand:SI 0 "register_operand" "=d")
2224 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2225 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2229 [(set_attr "type" "imul3nc")
2230 (set_attr "mode" "SI")])
2232 (define_insn_and_split "<su>mulsi3_highpart_internal"
2233 [(set (match_operand:SI 0 "register_operand" "=d")
2236 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2237 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2239 (clobber (match_scratch:SI 3 "=l"))]
2240 "ISA_HAS_MULT && !ISA_HAS_MULHI && !TARGET_MIPS16"
2241 { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2242 "&& reload_completed && !TARGET_FIX_R4000"
2245 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2249 [(set_attr "type" "imul")
2250 (set_attr "mode" "SI")
2251 (set_attr "insn_count" "2")])
2253 (define_expand "<su>mulsi3_highpart_split"
2254 [(set (match_operand:SI 0 "register_operand")
2257 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2258 (any_extend:DI (match_operand:SI 2 "register_operand")))
2266 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2267 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2268 emit_insn (gen_mfhisi_ti (operands[0], hilo));
2272 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2273 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2274 emit_insn (gen_mfhisi_di (operands[0], hilo));
2279 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2280 [(set (match_operand:SI 0 "register_operand" "=d")
2284 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2285 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2287 (clobber (match_scratch:SI 3 "=l"))]
2289 "mulhi<u>\t%0,%1,%2"
2290 [(set_attr "type" "imul3")
2291 (set_attr "mode" "SI")])
2293 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2294 [(set (match_operand:SI 0 "register_operand" "=d")
2299 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2300 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2302 (clobber (match_scratch:SI 3 "=l"))]
2304 "mulshi<u>\t%0,%1,%2"
2305 [(set_attr "type" "imul3")
2306 (set_attr "mode" "SI")])
2308 ;; Disable unsigned multiplication for -mfix-vr4120. This is for VR4120
2309 ;; errata MD(0), which says that dmultu does not always produce the
2311 (define_expand "<su>muldi3_highpart"
2312 [(set (match_operand:DI 0 "register_operand")
2315 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2316 (any_extend:TI (match_operand:DI 2 "register_operand")))
2320 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2323 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2325 else if (ISA_HAS_R6DMUL)
2326 emit_insn (gen_<su>muldi3_highpart_r6 (operands[0], operands[1],
2329 emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2334 (define_insn "<su>muldi3_highpart_r6"
2335 [(set (match_operand:DI 0 "register_operand" "=d")
2338 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2339 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2343 [(set_attr "type" "imul3nc")
2344 (set_attr "mode" "DI")])
2346 (define_insn_and_split "<su>muldi3_highpart_internal"
2347 [(set (match_operand:DI 0 "register_operand" "=d")
2350 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2351 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2353 (clobber (match_scratch:DI 3 "=l"))]
2356 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2357 { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2358 "&& reload_completed && !TARGET_FIX_R4000"
2361 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2365 [(set_attr "type" "imul")
2366 (set_attr "mode" "DI")
2367 (set_attr "insn_count" "2")])
2369 (define_expand "<su>muldi3_highpart_split"
2370 [(set (match_operand:DI 0 "register_operand")
2373 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2374 (any_extend:TI (match_operand:DI 2 "register_operand")))
2380 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2381 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2382 emit_insn (gen_mfhidi_ti (operands[0], hilo));
2386 (define_expand "<u>mulditi3"
2387 [(set (match_operand:TI 0 "register_operand")
2388 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2389 (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2390 "ISA_HAS_DMULT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2396 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2397 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2398 emit_move_insn (operands[0], hilo);
2400 else if (TARGET_FIX_R4000)
2401 emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2403 emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2408 (define_insn "<u>mulditi3_internal"
2409 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2410 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2411 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2413 && !TARGET_FIX_R4000
2414 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2416 [(set_attr "type" "imul")
2417 (set_attr "mode" "DI")])
2419 (define_insn "<u>mulditi3_r4000"
2420 [(set (match_operand:TI 0 "register_operand" "=d")
2421 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2422 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2423 (clobber (match_scratch:TI 3 "=x"))]
2426 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2427 "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2428 [(set_attr "type" "imul")
2429 (set_attr "mode" "DI")
2430 (set_attr "insn_count" "3")])
2432 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2433 ;; instruction. The HI/LO registers are used as a 64-bit accumulator.
2435 (define_insn "madsi"
2436 [(set (match_operand:SI 0 "register_operand" "+l")
2437 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2438 (match_operand:SI 2 "register_operand" "d"))
2442 [(set_attr "type" "imadd")
2443 (set_attr "accum_in" "0")
2444 (set_attr "mode" "SI")])
2446 ;; See the comment above <u>msubsidi4 for the relationship between
2447 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2448 (define_insn "<u>maddsidi4"
2449 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2451 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2452 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2453 (match_operand:DI 3 "muldiv_target_operand" "0")))]
2454 "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2458 return "mad<u>\t%1,%2";
2459 else if (ISA_HAS_DSP_MULT)
2460 return "madd<u>\t%q0,%1,%2";
2461 else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2462 return "madd<u>\t%1,%2";
2464 /* See comment in *macc. */
2465 return "%[macc<u>\t%@,%1,%2%]";
2467 [(set_attr "type" "imadd")
2468 (set_attr "accum_in" "3")
2469 (set_attr "mode" "SI")])
2471 ;; Floating point multiply accumulate instructions.
2473 (define_insn "*madd4<mode>"
2474 [(set (match_operand:ANYF 0 "register_operand" "=f")
2475 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2476 (match_operand:ANYF 2 "register_operand" "f"))
2477 (match_operand:ANYF 3 "register_operand" "f")))]
2478 "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2479 "madd.<fmt>\t%0,%3,%1,%2"
2480 [(set_attr "type" "fmadd")
2481 (set_attr "accum_in" "3")
2482 (set_attr "mode" "<UNITMODE>")])
2484 (define_insn "fma<mode>4"
2485 [(set (match_operand:ANYF 0 "register_operand" "=f")
2486 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2487 (match_operand:ANYF 2 "register_operand" "f")
2488 (match_operand:ANYF 3 "register_operand" "0")))]
2489 "ISA_HAS_FP_MADDF_MSUBF"
2490 "maddf.<fmt>\t%0,%1,%2"
2491 [(set_attr "type" "fmadd")
2492 (set_attr "mode" "<UNITMODE>")])
2494 (define_insn "*madd3<mode>"
2495 [(set (match_operand:ANYF 0 "register_operand" "=f")
2496 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2497 (match_operand:ANYF 2 "register_operand" "f"))
2498 (match_operand:ANYF 3 "register_operand" "0")))]
2499 "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2500 "madd.<fmt>\t%0,%1,%2"
2501 [(set_attr "type" "fmadd")
2502 (set_attr "accum_in" "3")
2503 (set_attr "mode" "<UNITMODE>")])
2505 (define_insn "*msub4<mode>"
2506 [(set (match_operand:ANYF 0 "register_operand" "=f")
2507 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2508 (match_operand:ANYF 2 "register_operand" "f"))
2509 (match_operand:ANYF 3 "register_operand" "f")))]
2510 "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2511 "msub.<fmt>\t%0,%3,%1,%2"
2512 [(set_attr "type" "fmadd")
2513 (set_attr "accum_in" "3")
2514 (set_attr "mode" "<UNITMODE>")])
2516 (define_insn "*msub3<mode>"
2517 [(set (match_operand:ANYF 0 "register_operand" "=f")
2518 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2519 (match_operand:ANYF 2 "register_operand" "f"))
2520 (match_operand:ANYF 3 "register_operand" "0")))]
2521 "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2522 "msub.<fmt>\t%0,%1,%2"
2523 [(set_attr "type" "fmadd")
2524 (set_attr "accum_in" "3")
2525 (set_attr "mode" "<UNITMODE>")])
2527 (define_insn "*nmadd4<mode>"
2528 [(set (match_operand:ANYF 0 "register_operand" "=f")
2529 (neg:ANYF (plus:ANYF
2530 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2531 (match_operand:ANYF 2 "register_operand" "f"))
2532 (match_operand:ANYF 3 "register_operand" "f"))))]
2533 "ISA_HAS_NMADD4_NMSUB4
2534 && TARGET_FUSED_MADD
2535 && HONOR_SIGNED_ZEROS (<MODE>mode)
2536 && !HONOR_NANS (<MODE>mode)"
2537 "nmadd.<fmt>\t%0,%3,%1,%2"
2538 [(set_attr "type" "fmadd")
2539 (set_attr "accum_in" "3")
2540 (set_attr "mode" "<UNITMODE>")])
2542 (define_insn "*nmadd3<mode>"
2543 [(set (match_operand:ANYF 0 "register_operand" "=f")
2544 (neg:ANYF (plus:ANYF
2545 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2546 (match_operand:ANYF 2 "register_operand" "f"))
2547 (match_operand:ANYF 3 "register_operand" "0"))))]
2548 "ISA_HAS_NMADD3_NMSUB3
2549 && TARGET_FUSED_MADD
2550 && HONOR_SIGNED_ZEROS (<MODE>mode)
2551 && !HONOR_NANS (<MODE>mode)"
2552 "nmadd.<fmt>\t%0,%1,%2"
2553 [(set_attr "type" "fmadd")
2554 (set_attr "accum_in" "3")
2555 (set_attr "mode" "<UNITMODE>")])
2557 (define_insn "*nmadd4<mode>_fastmath"
2558 [(set (match_operand:ANYF 0 "register_operand" "=f")
2560 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2561 (match_operand:ANYF 2 "register_operand" "f"))
2562 (match_operand:ANYF 3 "register_operand" "f")))]
2563 "ISA_HAS_NMADD4_NMSUB4
2564 && TARGET_FUSED_MADD
2565 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2566 && !HONOR_NANS (<MODE>mode)"
2567 "nmadd.<fmt>\t%0,%3,%1,%2"
2568 [(set_attr "type" "fmadd")
2569 (set_attr "accum_in" "3")
2570 (set_attr "mode" "<UNITMODE>")])
2572 (define_insn "*nmadd3<mode>_fastmath"
2573 [(set (match_operand:ANYF 0 "register_operand" "=f")
2575 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2576 (match_operand:ANYF 2 "register_operand" "f"))
2577 (match_operand:ANYF 3 "register_operand" "0")))]
2578 "ISA_HAS_NMADD3_NMSUB3
2579 && TARGET_FUSED_MADD
2580 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2581 && !HONOR_NANS (<MODE>mode)"
2582 "nmadd.<fmt>\t%0,%1,%2"
2583 [(set_attr "type" "fmadd")
2584 (set_attr "accum_in" "3")
2585 (set_attr "mode" "<UNITMODE>")])
2587 (define_insn "*nmsub4<mode>"
2588 [(set (match_operand:ANYF 0 "register_operand" "=f")
2589 (neg:ANYF (minus:ANYF
2590 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2591 (match_operand:ANYF 3 "register_operand" "f"))
2592 (match_operand:ANYF 1 "register_operand" "f"))))]
2593 "ISA_HAS_NMADD4_NMSUB4
2594 && TARGET_FUSED_MADD
2595 && HONOR_SIGNED_ZEROS (<MODE>mode)
2596 && !HONOR_NANS (<MODE>mode)"
2597 "nmsub.<fmt>\t%0,%1,%2,%3"
2598 [(set_attr "type" "fmadd")
2599 (set_attr "accum_in" "1")
2600 (set_attr "mode" "<UNITMODE>")])
2602 (define_insn "*nmsub3<mode>"
2603 [(set (match_operand:ANYF 0 "register_operand" "=f")
2604 (neg:ANYF (minus:ANYF
2605 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2606 (match_operand:ANYF 3 "register_operand" "f"))
2607 (match_operand:ANYF 1 "register_operand" "0"))))]
2608 "ISA_HAS_NMADD3_NMSUB3
2609 && TARGET_FUSED_MADD
2610 && HONOR_SIGNED_ZEROS (<MODE>mode)
2611 && !HONOR_NANS (<MODE>mode)"
2612 "nmsub.<fmt>\t%0,%1,%2"
2613 [(set_attr "type" "fmadd")
2614 (set_attr "accum_in" "1")
2615 (set_attr "mode" "<UNITMODE>")])
2617 (define_insn "*nmsub4<mode>_fastmath"
2618 [(set (match_operand:ANYF 0 "register_operand" "=f")
2620 (match_operand:ANYF 1 "register_operand" "f")
2621 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2622 (match_operand:ANYF 3 "register_operand" "f"))))]
2623 "ISA_HAS_NMADD4_NMSUB4
2624 && TARGET_FUSED_MADD
2625 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2626 && !HONOR_NANS (<MODE>mode)"
2627 "nmsub.<fmt>\t%0,%1,%2,%3"
2628 [(set_attr "type" "fmadd")
2629 (set_attr "accum_in" "1")
2630 (set_attr "mode" "<UNITMODE>")])
2632 (define_insn "*nmsub3<mode>_fastmath"
2633 [(set (match_operand:ANYF 0 "register_operand" "=f")
2635 (match_operand:ANYF 1 "register_operand" "f")
2636 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2637 (match_operand:ANYF 3 "register_operand" "0"))))]
2638 "ISA_HAS_NMADD3_NMSUB3
2639 && TARGET_FUSED_MADD
2640 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2641 && !HONOR_NANS (<MODE>mode)"
2642 "nmsub.<fmt>\t%0,%1,%2"
2643 [(set_attr "type" "fmadd")
2644 (set_attr "accum_in" "1")
2645 (set_attr "mode" "<UNITMODE>")])
2648 ;; ....................
2650 ;; DIVISION and REMAINDER
2652 ;; ....................
2655 (define_expand "div<mode>3"
2656 [(set (match_operand:ANYF 0 "register_operand")
2657 (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2658 (match_operand:ANYF 2 "register_operand")))]
2659 "<divide_condition>"
2661 if (const_1_operand (operands[1], <MODE>mode))
2662 if (!(ISA_HAS_FP_RECIP_RSQRT (<MODE>mode)
2663 && flag_unsafe_math_optimizations))
2664 operands[1] = force_reg (<MODE>mode, operands[1]);
2667 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2669 ;; If an mfc1 or dmfc1 happens to access the floating point register
2670 ;; file at the same time a long latency operation (div, sqrt, recip,
2671 ;; sqrt) iterates an intermediate result back through the floating
2672 ;; point register file bypass, then instead returning the correct
2673 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2674 ;; result of the long latency operation.
2676 ;; The workaround is to insert an unconditional 'mov' from/to the
2677 ;; long latency op destination register.
2679 (define_insn "*div<mode>3"
2680 [(set (match_operand:ANYF 0 "register_operand" "=f")
2681 (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2682 (match_operand:ANYF 2 "register_operand" "f")))]
2683 "<divide_condition>"
2686 return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2688 return "div.<fmt>\t%0,%1,%2";
2690 [(set_attr "type" "fdiv")
2691 (set_attr "mode" "<UNITMODE>")
2692 (set (attr "insn_count")
2693 (if_then_else (match_test "TARGET_FIX_SB1")
2697 (define_insn "*recip<mode>3"
2698 [(set (match_operand:ANYF 0 "register_operand" "=f")
2699 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2700 (match_operand:ANYF 2 "register_operand" "f")))]
2701 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2704 return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2706 return "recip.<fmt>\t%0,%2";
2708 [(set_attr "type" "frdiv")
2709 (set_attr "mode" "<UNITMODE>")
2710 (set (attr "insn_count")
2711 (if_then_else (match_test "TARGET_FIX_SB1")
2715 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2716 ;; with negative operands. We use special libgcc functions instead.
2717 (define_expand "divmod<mode>4"
2719 [(set (match_operand:GPR 0 "register_operand")
2720 (div:GPR (match_operand:GPR 1 "register_operand")
2721 (match_operand:GPR 2 "register_operand")))
2722 (set (match_operand:GPR 3 "register_operand")
2723 (mod:GPR (match_dup 1)
2725 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2729 rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2730 emit_insn (gen_divmod<mode>4_mips16 (operands[0], operands[1],
2731 operands[2], operands[3], lo));
2736 (define_insn_and_split "*divmod<mode>4"
2737 [(set (match_operand:GPR 0 "register_operand" "=l")
2738 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2739 (match_operand:GPR 2 "register_operand" "d")))
2740 (set (match_operand:GPR 3 "register_operand" "=d")
2741 (mod:GPR (match_dup 1)
2743 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && !TARGET_MIPS16"
2745 "&& reload_completed"
2748 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2751 [(set_attr "type" "idiv")
2752 (set_attr "mode" "<MODE>")
2753 (set_attr "insn_count" "2")])
2755 ;; Expand generates divmod instructions for individual division and modulus
2756 ;; operations. We then rely on CSE to reuse earlier divmods where possible.
2757 ;; This means that, when generating MIPS16 code, it is better not to expose
2758 ;; the fixed LO register until after CSE has finished. However, it's still
2759 ;; better to split before register allocation, so that we don't allocate
2760 ;; one of the scarce MIPS16 registers to an unused result.
2761 (define_insn_and_split "divmod<mode>4_mips16"
2762 [(set (match_operand:GPR 0 "register_operand" "=d")
2763 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2764 (match_operand:GPR 2 "register_operand" "d")))
2765 (set (match_operand:GPR 3 "register_operand" "=d")
2766 (mod:GPR (match_dup 1)
2768 (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2769 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && TARGET_MIPS16"
2771 "&& cse_not_expected"
2774 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2775 emit_move_insn (operands[0], operands[4]);
2778 [(set_attr "type" "idiv")
2779 (set_attr "mode" "<MODE>")
2780 (set_attr "insn_count" "3")])
2782 (define_expand "udivmod<mode>4"
2784 [(set (match_operand:GPR 0 "register_operand")
2785 (udiv:GPR (match_operand:GPR 1 "register_operand")
2786 (match_operand:GPR 2 "register_operand")))
2787 (set (match_operand:GPR 3 "register_operand")
2788 (umod:GPR (match_dup 1)
2790 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2794 rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2795 emit_insn (gen_udivmod<mode>4_mips16 (operands[0], operands[1],
2796 operands[2], operands[3], lo));
2801 (define_insn_and_split "*udivmod<mode>4"
2802 [(set (match_operand:GPR 0 "register_operand" "=l")
2803 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2804 (match_operand:GPR 2 "register_operand" "d")))
2805 (set (match_operand:GPR 3 "register_operand" "=d")
2806 (umod:GPR (match_dup 1)
2808 "ISA_HAS_<D>DIV && !TARGET_MIPS16"
2813 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2816 [(set_attr "type" "idiv")
2817 (set_attr "mode" "<MODE>")
2818 (set_attr "insn_count" "2")])
2820 ;; See the comment above "divmod<mode>4_mips16" for the split timing.
2821 (define_insn_and_split "udivmod<mode>4_mips16"
2822 [(set (match_operand:GPR 0 "register_operand" "=d")
2823 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2824 (match_operand:GPR 2 "register_operand" "d")))
2825 (set (match_operand:GPR 3 "register_operand" "=d")
2826 (umod:GPR (match_dup 1)
2828 (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2829 "ISA_HAS_<D>DIV && TARGET_MIPS16"
2834 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2835 emit_move_insn (operands[0], operands[4]);
2838 [(set_attr "type" "idiv")
2839 (set_attr "mode" "<MODE>")
2840 (set_attr "insn_count" "3")])
2842 (define_expand "<u>divmod<mode>4_split"
2843 [(set (match_operand:GPR 0 "register_operand")
2844 (any_mod:GPR (match_operand:GPR 1 "register_operand")
2845 (match_operand:GPR 2 "register_operand")))]
2852 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2853 emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
2855 emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
2859 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2860 emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
2862 emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
2867 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
2868 [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
2870 [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2871 (match_operand:GPR 2 "register_operand" "d"))]
2873 "ISA_HAS_<GPR:D>DIV"
2874 { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
2875 [(set_attr "type" "idiv")
2876 (set_attr "mode" "<GPR:MODE>")])
2878 ;; Integer division and modulus.
2880 (define_insn "<u>div<mode>3"
2881 [(set (match_operand:GPR 0 "register_operand" "=&d")
2882 (any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2883 (match_operand:GPR 2 "register_operand" "d")))]
2884 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>DIV"
2886 if (TARGET_LOONGSON_2EF)
2887 return mips_output_division ("<d>div<u>.g\t%0,%1,%2", operands);
2888 else if (TARGET_LOONGSON_3A)
2889 return mips_output_division ("gs<d>div<u>\t%0,%1,%2", operands);
2891 return mips_output_division ("<d>div<u>\t%0,%1,%2", operands);
2893 [(set_attr "type" "idiv3")
2894 (set_attr "mode" "<MODE>")])
2896 (define_insn "<u>mod<mode>3"
2897 [(set (match_operand:GPR 0 "register_operand" "=&d")
2898 (any_mod:GPR (match_operand:GPR 1 "register_operand" "d")
2899 (match_operand:GPR 2 "register_operand" "d")))]
2900 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>DIV"
2902 if (TARGET_LOONGSON_2EF)
2903 return mips_output_division ("<d>mod<u>.g\t%0,%1,%2", operands);
2904 else if (TARGET_LOONGSON_3A)
2905 return mips_output_division ("gs<d>mod<u>\t%0,%1,%2", operands);
2907 return mips_output_division ("<d>mod<u>\t%0,%1,%2", operands);
2909 [(set_attr "type" "idiv3")
2910 (set_attr "mode" "<MODE>")])
2913 ;; ....................
2917 ;; ....................
2919 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
2920 ;; "*div[sd]f3" comment for details).
2922 (define_insn "sqrt<mode>2"
2923 [(set (match_operand:ANYF 0 "register_operand" "=f")
2924 (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2928 return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
2930 return "sqrt.<fmt>\t%0,%1";
2932 [(set_attr "type" "fsqrt")
2933 (set_attr "mode" "<UNITMODE>")
2934 (set (attr "insn_count")
2935 (if_then_else (match_test "TARGET_FIX_SB1")
2939 (define_insn "*rsqrt<mode>a"
2940 [(set (match_operand:ANYF 0 "register_operand" "=f")
2941 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2942 (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
2943 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2946 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2948 return "rsqrt.<fmt>\t%0,%2";
2950 [(set_attr "type" "frsqrt")
2951 (set_attr "mode" "<UNITMODE>")
2952 (set (attr "insn_count")
2953 (if_then_else (match_test "TARGET_FIX_SB1")
2957 (define_insn "*rsqrt<mode>b"
2958 [(set (match_operand:ANYF 0 "register_operand" "=f")
2959 (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2960 (match_operand:ANYF 2 "register_operand" "f"))))]
2961 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2964 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2966 return "rsqrt.<fmt>\t%0,%2";
2968 [(set_attr "type" "frsqrt")
2969 (set_attr "mode" "<UNITMODE>")
2970 (set (attr "insn_count")
2971 (if_then_else (match_test "TARGET_FIX_SB1")
2976 ;; ....................
2980 ;; ....................
2982 ;; Do not use the integer abs macro instruction, since that signals an
2983 ;; exception on -2147483648 (sigh).
2985 ;; The "legacy" (as opposed to "2008") form of ABS.fmt is an arithmetic
2986 ;; instruction that treats all NaN inputs as invalid; it does not clear
2987 ;; their sign bit. We therefore can't use that form if the signs of
2990 (define_insn "abs<mode>2"
2991 [(set (match_operand:ANYF 0 "register_operand" "=f")
2992 (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2993 "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
2995 [(set_attr "type" "fabs")
2996 (set_attr "mode" "<UNITMODE>")])
2999 ;; ...................
3001 ;; Count leading zeroes.
3003 ;; ...................
3006 (define_insn "clz<mode>2"
3007 [(set (match_operand:GPR 0 "register_operand" "=d")
3008 (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
3011 [(set_attr "type" "clz")
3012 (set_attr "mode" "<MODE>")])
3015 ;; ...................
3017 ;; Count number of set bits.
3019 ;; ...................
3022 (define_insn "popcount<mode>2"
3023 [(set (match_operand:GPR 0 "register_operand" "=d")
3024 (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
3027 [(set_attr "type" "pop")
3028 (set_attr "mode" "<MODE>")])
3030 ;; The POP instruction is special as it does not take into account the upper
3031 ;; 32bits and is documented that way.
3032 (define_insn "*popcountdi2_trunc"
3033 [(set (match_operand:SI 0 "register_operand" "=d")
3034 (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
3035 "ISA_HAS_POP && TARGET_64BIT"
3037 [(set_attr "type" "pop")
3038 (set_attr "mode" "SI")])
3041 ;; ....................
3043 ;; NEGATION and ONE'S COMPLEMENT
3045 ;; ....................
3047 (define_insn "negsi2"
3048 [(set (match_operand:SI 0 "register_operand" "=d")
3049 (neg:SI (match_operand:SI 1 "register_operand" "d")))]
3053 return "neg\t%0,%1";
3055 return "subu\t%0,%.,%1";
3057 [(set_attr "alu_type" "sub")
3058 (set_attr "mode" "SI")])
3060 (define_insn "negdi2"
3061 [(set (match_operand:DI 0 "register_operand" "=d")
3062 (neg:DI (match_operand:DI 1 "register_operand" "d")))]
3063 "TARGET_64BIT && !TARGET_MIPS16"
3065 [(set_attr "alu_type" "sub")
3066 (set_attr "mode" "DI")])
3068 ;; The "legacy" (as opposed to "2008") form of NEG.fmt is an arithmetic
3069 ;; instruction that treats all NaN inputs as invalid; it does not flip
3070 ;; their sign bit. We therefore can't use that form if the signs of
3073 (define_insn "neg<mode>2"
3074 [(set (match_operand:ANYF 0 "register_operand" "=f")
3075 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3076 "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3078 [(set_attr "type" "fneg")
3079 (set_attr "mode" "<UNITMODE>")])
3081 (define_insn "one_cmpl<mode>2"
3082 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
3083 (not:GPR (match_operand:GPR 1 "register_operand" "!u,d")))]
3087 return "not\t%0,%1";
3089 return "nor\t%0,%.,%1";
3091 [(set_attr "alu_type" "not")
3092 (set_attr "compression" "micromips,*")
3093 (set_attr "mode" "<MODE>")])
3096 ;; ....................
3100 ;; ....................
3103 ;; Many of these instructions use trivial define_expands, because we
3104 ;; want to use a different set of constraints when TARGET_MIPS16.
3106 (define_expand "and<mode>3"
3107 [(set (match_operand:GPR 0 "register_operand")
3108 (and:GPR (match_operand:GPR 1 "register_operand")
3109 (match_operand:GPR 2 "and_reg_operand")))])
3111 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
3112 ;; zero_extendsidi2 because of TRULY_NOOP_TRUNCATION, so handle these here.
3113 ;; Note that this variant does not trigger for SI mode because we require
3114 ;; a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
3115 ;; sign-extended SImode value.
3117 ;; These are possible combinations for operand 1 and 2. The table
3118 ;; includes both MIPS and MIPS16 cases. (r=register, mem=memory,
3119 ;; 16=MIPS16, x=match, S=split):
3121 ;; \ op1 r/EXT r/!EXT mem r/16 mem/16
3127 ;; 0xffff_ffff x S x S x
3132 (define_insn "*and<mode>3"
3133 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,!u,d,d,d,!u,d")
3134 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,!u,d,d,d,0,d")
3135 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Uean,K,Yx,Yw,!u,d")))]
3136 "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3140 switch (which_alternative)
3143 operands[1] = gen_lowpart (QImode, operands[1]);
3144 return "lbu\t%0,%1";
3146 operands[1] = gen_lowpart (HImode, operands[1]);
3147 return "lhu\t%0,%1";
3149 operands[1] = gen_lowpart (SImode, operands[1]);
3150 return "lwu\t%0,%1";
3153 return "andi\t%0,%1,%x2";
3155 len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
3156 operands[2] = GEN_INT (len);
3157 return "<d>ext\t%0,%1,0,%2";
3162 return "and\t%0,%1,%2";
3167 [(set_attr "move_type" "load,load,load,andi,andi,ext_ins,shift_shift,logical,logical")
3168 (set_attr "compression" "*,*,*,micromips,*,*,*,micromips,*")
3169 (set_attr "mode" "<MODE>")])
3171 (define_insn "*and<mode>3_mips16"
3172 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
3173 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%W,W,W,d,0")
3174 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
3175 "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3177 switch (which_alternative)
3180 operands[1] = gen_lowpart (QImode, operands[1]);
3181 return "lbu\t%0,%1";
3183 operands[1] = gen_lowpart (HImode, operands[1]);
3184 return "lhu\t%0,%1";
3186 operands[1] = gen_lowpart (SImode, operands[1]);
3187 return "lwu\t%0,%1";
3191 return "and\t%0,%2";
3196 [(set_attr "move_type" "load,load,load,shift_shift,logical")
3197 (set_attr "mode" "<MODE>")])
3199 (define_expand "ior<mode>3"
3200 [(set (match_operand:GPR 0 "register_operand")
3201 (ior:GPR (match_operand:GPR 1 "register_operand")
3202 (match_operand:GPR 2 "uns_arith_operand")))]
3206 operands[2] = force_reg (<MODE>mode, operands[2]);
3209 (define_insn "*ior<mode>3"
3210 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3211 (ior:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3212 (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3218 [(set_attr "alu_type" "or")
3219 (set_attr "compression" "micromips,*,*")
3220 (set_attr "mode" "<MODE>")])
3222 (define_insn "*ior<mode>3_mips16"
3223 [(set (match_operand:GPR 0 "register_operand" "=d")
3224 (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
3225 (match_operand:GPR 2 "register_operand" "d")))]
3228 [(set_attr "alu_type" "or")
3229 (set_attr "mode" "<MODE>")])
3231 (define_expand "xor<mode>3"
3232 [(set (match_operand:GPR 0 "register_operand")
3233 (xor:GPR (match_operand:GPR 1 "register_operand")
3234 (match_operand:GPR 2 "uns_arith_operand")))]
3238 (define_insn "*xor<mode>3"
3239 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3240 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3241 (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3247 [(set_attr "alu_type" "xor")
3248 (set_attr "compression" "micromips,*,*")
3249 (set_attr "mode" "<MODE>")])
3251 (define_insn "*xor<mode>3_mips16"
3252 [(set (match_operand:GPR 0 "register_operand" "=d,t,t,t")
3253 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d,d")
3254 (match_operand:GPR 2 "uns_arith_operand" "d,Uub8,K,d")))]
3261 [(set_attr "alu_type" "xor")
3262 (set_attr "mode" "<MODE>")
3263 (set_attr "extended_mips16" "no,no,yes,no")])
3265 (define_insn "*nor<mode>3"
3266 [(set (match_operand:GPR 0 "register_operand" "=d")
3267 (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
3268 (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
3271 [(set_attr "alu_type" "nor")
3272 (set_attr "mode" "<MODE>")])
3275 ;; ....................
3279 ;; ....................
3283 (define_insn "truncdfsf2"
3284 [(set (match_operand:SF 0 "register_operand" "=f")
3285 (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3286 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3288 [(set_attr "type" "fcvt")
3289 (set_attr "cnv_mode" "D2S")
3290 (set_attr "mode" "SF")])
3292 ;; Integer truncation patterns. Truncating SImode values to smaller
3293 ;; modes is a no-op, as it is for most other GCC ports. Truncating
3294 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3295 ;; need to make sure that the lower 32 bits are properly sign-extended
3296 ;; (see TRULY_NOOP_TRUNCATION). Truncating DImode values into modes
3297 ;; smaller than SImode is equivalent to two separate truncations:
3300 ;; DI ---> HI == DI ---> SI ---> HI
3301 ;; DI ---> QI == DI ---> SI ---> QI
3303 ;; Step A needs a real instruction but step B does not.
3305 (define_insn "truncdi<mode>2"
3306 [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3307 (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3312 [(set_attr "move_type" "sll0,store")
3313 (set_attr "mode" "SI")])
3315 ;; Combiner patterns to optimize shift/truncate combinations.
3317 (define_insn "*ashr_trunc<mode>"
3318 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3320 (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3321 (match_operand:DI 2 "const_arith_operand" ""))))]
3322 "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3324 [(set_attr "type" "shift")
3325 (set_attr "mode" "<MODE>")])
3327 (define_insn "*lshr32_trunc<mode>"
3328 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3330 (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3332 "TARGET_64BIT && !TARGET_MIPS16"
3334 [(set_attr "type" "shift")
3335 (set_attr "mode" "<MODE>")])
3337 ;; Logical shift by more than 32 results in proper SI values so truncation is
3338 ;; removed by the middle end. Note that a logical shift by 32 is handled by
3339 ;; the previous pattern.
3340 (define_insn "*<optab>_trunc<mode>_exts"
3341 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3343 (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3344 (match_operand:DI 2 "const_arith_operand" ""))))]
3345 "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3347 [(set_attr "type" "arith")
3348 (set_attr "mode" "<MODE>")])
3351 ;; ....................
3355 ;; ....................
3359 (define_expand "zero_extendsidi2"
3360 [(set (match_operand:DI 0 "register_operand")
3361 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3364 (define_insn_and_split "*zero_extendsidi2"
3365 [(set (match_operand:DI 0 "register_operand" "=d,d")
3366 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3367 "TARGET_64BIT && !ISA_HAS_EXT_INS"
3371 "&& reload_completed && REG_P (operands[1])"
3373 (ashift:DI (match_dup 1) (const_int 32)))
3375 (lshiftrt:DI (match_dup 0) (const_int 32)))]
3376 { operands[1] = gen_lowpart (DImode, operands[1]); }
3377 [(set_attr "move_type" "shift_shift,load")
3378 (set_attr "mode" "DI")])
3380 (define_insn "*zero_extendsidi2_dext"
3381 [(set (match_operand:DI 0 "register_operand" "=d,d")
3382 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3383 "TARGET_64BIT && ISA_HAS_EXT_INS"
3387 [(set_attr "move_type" "arith,load")
3388 (set_attr "mode" "DI")])
3390 ;; See the comment before the *and<mode>3 pattern why this is generated by
3394 [(set (match_operand:DI 0 "register_operand")
3395 (and:DI (match_operand:DI 1 "register_operand")
3396 (const_int 4294967295)))]
3397 "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3399 (ashift:DI (match_dup 1) (const_int 32)))
3401 (lshiftrt:DI (match_dup 0) (const_int 32)))])
3403 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3404 [(set (match_operand:GPR 0 "register_operand")
3405 (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3408 if (TARGET_MIPS16 && !GENERATE_MIPS16E
3409 && !memory_operand (operands[1], <SHORT:MODE>mode))
3411 emit_insn (gen_and<GPR:mode>3 (operands[0],
3412 gen_lowpart (<GPR:MODE>mode, operands[1]),
3413 force_reg (<GPR:MODE>mode,
3414 GEN_INT (<SHORT:mask>))));
3419 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3420 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3422 (match_operand:SHORT 1 "nonimmediate_operand" "!u,d,m")))]
3425 andi\t%0,%1,<SHORT:mask>
3426 andi\t%0,%1,<SHORT:mask>
3427 l<SHORT:size>u\t%0,%1"
3428 [(set_attr "move_type" "andi,andi,load")
3429 (set_attr "compression" "micromips,*,*")
3430 (set_attr "mode" "<GPR:MODE>")])
3432 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3433 [(set (match_operand:GPR 0 "register_operand" "=d")
3434 (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3436 "ze<SHORT:size>\t%0"
3437 ;; This instruction is effectively a special encoding of ANDI.
3438 [(set_attr "move_type" "andi")
3439 (set_attr "mode" "<GPR:MODE>")])
3441 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3442 [(set (match_operand:GPR 0 "register_operand" "=d")
3443 (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3445 "l<SHORT:size>u\t%0,%1"
3446 [(set_attr "move_type" "load")
3447 (set_attr "mode" "<GPR:MODE>")])
3449 (define_expand "zero_extendqihi2"
3450 [(set (match_operand:HI 0 "register_operand")
3451 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3454 if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3456 emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3462 (define_insn "*zero_extendqihi2"
3463 [(set (match_operand:HI 0 "register_operand" "=d,d")
3464 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3469 [(set_attr "move_type" "andi,load")
3470 (set_attr "mode" "HI")])
3472 (define_insn "*zero_extendqihi2_mips16"
3473 [(set (match_operand:HI 0 "register_operand" "=d")
3474 (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3477 [(set_attr "move_type" "load")
3478 (set_attr "mode" "HI")])
3480 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3482 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3483 [(set (match_operand:GPR 0 "register_operand" "=d")
3485 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3486 "TARGET_64BIT && !TARGET_MIPS16"
3488 operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3489 return "andi\t%0,%1,%x2";
3491 [(set_attr "alu_type" "and")
3492 (set_attr "mode" "<GPR:MODE>")])
3494 (define_insn "*zero_extendhi_truncqi"
3495 [(set (match_operand:HI 0 "register_operand" "=d")
3497 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3498 "TARGET_64BIT && !TARGET_MIPS16"
3500 [(set_attr "alu_type" "and")
3501 (set_attr "mode" "HI")])
3504 ;; ....................
3508 ;; ....................
3511 ;; Those for integer source operand are ordered widest source type first.
3513 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3514 ;; should already be in sign-extended form (see TRULY_NOOP_TRUNCATION
3515 ;; and truncdisi2). We can therefore get rid of register->register
3516 ;; instructions if we constrain the source to be in the same register as
3519 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3520 ;; we split them into nothing before the post-reload scheduler runs.
3521 ;; These alternatives therefore have type "move" in order to reflect
3522 ;; what happens if the two pre-reload operands cannot be tied, and are
3523 ;; instead allocated two separate GPRs. We don't distinguish between
3524 ;; the GPR and LO cases because we don't usually know during pre-reload
3525 ;; scheduling whether an operand will be LO or not.
3526 (define_insn_and_split "extendsidi2"
3527 [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3528 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3534 "&& reload_completed && register_operand (operands[1], VOIDmode)"
3537 emit_note (NOTE_INSN_DELETED);
3540 [(set_attr "move_type" "move,move,load")
3541 (set_attr "mode" "DI")])
3543 (define_expand "extend<SHORT:mode><GPR:mode>2"
3544 [(set (match_operand:GPR 0 "register_operand")
3545 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3548 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3549 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3550 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3554 l<SHORT:size>\t%0,%1"
3555 [(set_attr "move_type" "signext,load")
3556 (set_attr "mode" "<GPR:MODE>")])
3558 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3559 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3561 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3562 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3565 l<SHORT:size>\t%0,%1"
3566 "&& reload_completed && REG_P (operands[1])"
3567 [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3568 (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3570 operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3571 operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3572 - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3574 [(set_attr "move_type" "shift_shift,load")
3575 (set_attr "mode" "<GPR:MODE>")])
3577 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3578 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3580 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3583 se<SHORT:size>\t%0,%1
3584 l<SHORT:size>\t%0,%1"
3585 [(set_attr "move_type" "signext,load")
3586 (set_attr "mode" "<GPR:MODE>")])
3588 (define_expand "extendqihi2"
3589 [(set (match_operand:HI 0 "register_operand")
3590 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3593 (define_insn "*extendqihi2_mips16e"
3594 [(set (match_operand:HI 0 "register_operand" "=d,d")
3595 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3600 [(set_attr "move_type" "signext,load")
3601 (set_attr "mode" "SI")])
3603 (define_insn_and_split "*extendqihi2"
3604 [(set (match_operand:HI 0 "register_operand" "=d,d")
3606 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3607 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3611 "&& reload_completed && REG_P (operands[1])"
3612 [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3613 (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3615 operands[0] = gen_lowpart (SImode, operands[0]);
3616 operands[1] = gen_lowpart (SImode, operands[1]);
3617 operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3618 - GET_MODE_BITSIZE (QImode));
3620 [(set_attr "move_type" "shift_shift,load")
3621 (set_attr "mode" "SI")])
3623 (define_insn "*extendqihi2_seb"
3624 [(set (match_operand:HI 0 "register_operand" "=d,d")
3626 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3631 [(set_attr "move_type" "signext,load")
3632 (set_attr "mode" "SI")])
3634 ;; Combiner patterns for truncate/sign_extend combinations. The SI versions
3635 ;; use the shift/truncate patterns.
3637 (define_insn_and_split "*extenddi_truncate<mode>"
3638 [(set (match_operand:DI 0 "register_operand" "=d")
3640 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3641 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3643 "&& reload_completed"
3645 (ashift:DI (match_dup 1)
3648 (ashiftrt:DI (match_dup 2)
3651 operands[2] = gen_lowpart (DImode, operands[0]);
3652 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3654 [(set_attr "move_type" "shift_shift")
3655 (set_attr "mode" "DI")])
3657 (define_insn_and_split "*extendsi_truncate<mode>"
3658 [(set (match_operand:SI 0 "register_operand" "=d")
3660 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3661 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3663 "&& reload_completed"
3665 (ashift:DI (match_dup 1)
3668 (truncate:SI (ashiftrt:DI (match_dup 2)
3671 operands[2] = gen_lowpart (DImode, operands[0]);
3672 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3674 [(set_attr "move_type" "shift_shift")
3675 (set_attr "mode" "SI")])
3677 (define_insn_and_split "*extendhi_truncateqi"
3678 [(set (match_operand:HI 0 "register_operand" "=d")
3680 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3681 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3683 "&& reload_completed"
3685 (ashift:DI (match_dup 1)
3688 (truncate:HI (ashiftrt:DI (match_dup 2)
3691 operands[2] = gen_lowpart (DImode, operands[0]);
3693 [(set_attr "move_type" "shift_shift")
3694 (set_attr "mode" "SI")])
3696 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3697 [(set (match_operand:GPR 0 "register_operand" "=d")
3699 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3700 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3702 operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3703 return "exts\t%0,%1,0,%m2";
3705 [(set_attr "type" "arith")
3706 (set_attr "mode" "<GPR:MODE>")])
3708 (define_insn "*extendhi_truncateqi_exts"
3709 [(set (match_operand:HI 0 "register_operand" "=d")
3711 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3712 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3714 [(set_attr "type" "arith")
3715 (set_attr "mode" "SI")])
3717 (define_insn "extendsfdf2"
3718 [(set (match_operand:DF 0 "register_operand" "=f")
3719 (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3720 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3722 [(set_attr "type" "fcvt")
3723 (set_attr "cnv_mode" "S2D")
3724 (set_attr "mode" "DF")])
3727 ;; ....................
3731 ;; ....................
3733 (define_expand "fix_truncdfsi2"
3734 [(set (match_operand:SI 0 "register_operand")
3735 (fix:SI (match_operand:DF 1 "register_operand")))]
3736 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3738 if (!ISA_HAS_TRUNC_W)
3740 emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3745 (define_insn "fix_truncdfsi2_insn"
3746 [(set (match_operand:SI 0 "register_operand" "=f")
3747 (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3748 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3750 [(set_attr "type" "fcvt")
3751 (set_attr "mode" "DF")
3752 (set_attr "cnv_mode" "D2I")])
3754 (define_insn "fix_truncdfsi2_macro"
3755 [(set (match_operand:SI 0 "register_operand" "=f")
3756 (fix:SI (match_operand:DF 1 "register_operand" "f")))
3757 (clobber (match_scratch:DF 2 "=d"))]
3758 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3760 if (mips_nomacro.nesting_level > 0)
3761 return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3763 return "trunc.w.d %0,%1,%2";
3765 [(set_attr "type" "fcvt")
3766 (set_attr "mode" "DF")
3767 (set_attr "cnv_mode" "D2I")
3768 (set_attr "insn_count" "9")])
3770 (define_expand "fix_truncsfsi2"
3771 [(set (match_operand:SI 0 "register_operand")
3772 (fix:SI (match_operand:SF 1 "register_operand")))]
3775 if (!ISA_HAS_TRUNC_W)
3777 emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3782 (define_insn "fix_truncsfsi2_insn"
3783 [(set (match_operand:SI 0 "register_operand" "=f")
3784 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3785 "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3787 [(set_attr "type" "fcvt")
3788 (set_attr "mode" "SF")
3789 (set_attr "cnv_mode" "S2I")])
3791 (define_insn "fix_truncsfsi2_macro"
3792 [(set (match_operand:SI 0 "register_operand" "=f")
3793 (fix:SI (match_operand:SF 1 "register_operand" "f")))
3794 (clobber (match_scratch:SF 2 "=d"))]
3795 "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
3797 if (mips_nomacro.nesting_level > 0)
3798 return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
3800 return "trunc.w.s %0,%1,%2";
3802 [(set_attr "type" "fcvt")
3803 (set_attr "mode" "SF")
3804 (set_attr "cnv_mode" "S2I")
3805 (set_attr "insn_count" "9")])
3808 (define_insn "fix_truncdfdi2"
3809 [(set (match_operand:DI 0 "register_operand" "=f")
3810 (fix:DI (match_operand:DF 1 "register_operand" "f")))]
3811 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3813 [(set_attr "type" "fcvt")
3814 (set_attr "mode" "DF")
3815 (set_attr "cnv_mode" "D2I")])
3818 (define_insn "fix_truncsfdi2"
3819 [(set (match_operand:DI 0 "register_operand" "=f")
3820 (fix:DI (match_operand:SF 1 "register_operand" "f")))]
3821 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3823 [(set_attr "type" "fcvt")
3824 (set_attr "mode" "SF")
3825 (set_attr "cnv_mode" "S2I")])
3828 (define_insn "floatsidf2"
3829 [(set (match_operand:DF 0 "register_operand" "=f")
3830 (float:DF (match_operand:SI 1 "register_operand" "f")))]
3831 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3833 [(set_attr "type" "fcvt")
3834 (set_attr "mode" "DF")
3835 (set_attr "cnv_mode" "I2D")])
3838 (define_insn "floatdidf2"
3839 [(set (match_operand:DF 0 "register_operand" "=f")
3840 (float:DF (match_operand:DI 1 "register_operand" "f")))]
3841 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3843 [(set_attr "type" "fcvt")
3844 (set_attr "mode" "DF")
3845 (set_attr "cnv_mode" "I2D")])
3848 (define_insn "floatsisf2"
3849 [(set (match_operand:SF 0 "register_operand" "=f")
3850 (float:SF (match_operand:SI 1 "register_operand" "f")))]
3853 [(set_attr "type" "fcvt")
3854 (set_attr "mode" "SF")
3855 (set_attr "cnv_mode" "I2S")])
3858 (define_insn "floatdisf2"
3859 [(set (match_operand:SF 0 "register_operand" "=f")
3860 (float:SF (match_operand:DI 1 "register_operand" "f")))]
3861 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3863 [(set_attr "type" "fcvt")
3864 (set_attr "mode" "SF")
3865 (set_attr "cnv_mode" "I2S")])
3868 (define_expand "fixuns_truncdfsi2"
3869 [(set (match_operand:SI 0 "register_operand")
3870 (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
3871 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3873 rtx reg1 = gen_reg_rtx (DFmode);
3874 rtx reg2 = gen_reg_rtx (DFmode);
3875 rtx reg3 = gen_reg_rtx (SImode);
3876 rtx_code_label *label1 = gen_label_rtx ();
3877 rtx_code_label *label2 = gen_label_rtx ();
3879 REAL_VALUE_TYPE offset;
3881 real_2expN (&offset, 31, DFmode);
3883 if (reg1) /* Turn off complaints about unreached code. */
3885 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3886 do_pending_stack_adjust ();
3888 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3889 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3891 emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
3892 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3893 gen_rtx_LABEL_REF (VOIDmode, label2)));
3896 emit_label (label1);
3897 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3898 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3899 (BITMASK_HIGH, SImode)));
3901 emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
3902 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3904 emit_label (label2);
3906 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3907 fields, and can't be used for REG_NOTES anyway). */
3908 emit_use (stack_pointer_rtx);
3914 (define_expand "fixuns_truncdfdi2"
3915 [(set (match_operand:DI 0 "register_operand")
3916 (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
3917 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3919 rtx reg1 = gen_reg_rtx (DFmode);
3920 rtx reg2 = gen_reg_rtx (DFmode);
3921 rtx reg3 = gen_reg_rtx (DImode);
3922 rtx_code_label *label1 = gen_label_rtx ();
3923 rtx_code_label *label2 = gen_label_rtx ();
3925 REAL_VALUE_TYPE offset;
3927 real_2expN (&offset, 63, DFmode);
3929 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3930 do_pending_stack_adjust ();
3932 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3933 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3935 emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
3936 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3937 gen_rtx_LABEL_REF (VOIDmode, label2)));
3940 emit_label (label1);
3941 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3942 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3943 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3945 emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
3946 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3948 emit_label (label2);
3950 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3951 fields, and can't be used for REG_NOTES anyway). */
3952 emit_use (stack_pointer_rtx);
3957 (define_expand "fixuns_truncsfsi2"
3958 [(set (match_operand:SI 0 "register_operand")
3959 (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
3962 rtx reg1 = gen_reg_rtx (SFmode);
3963 rtx reg2 = gen_reg_rtx (SFmode);
3964 rtx reg3 = gen_reg_rtx (SImode);
3965 rtx_code_label *label1 = gen_label_rtx ();
3966 rtx_code_label *label2 = gen_label_rtx ();
3968 REAL_VALUE_TYPE offset;
3970 real_2expN (&offset, 31, SFmode);
3972 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3973 do_pending_stack_adjust ();
3975 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3976 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3978 emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
3979 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3980 gen_rtx_LABEL_REF (VOIDmode, label2)));
3983 emit_label (label1);
3984 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3985 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3986 (BITMASK_HIGH, SImode)));
3988 emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
3989 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3991 emit_label (label2);
3993 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3994 fields, and can't be used for REG_NOTES anyway). */
3995 emit_use (stack_pointer_rtx);
4000 (define_expand "fixuns_truncsfdi2"
4001 [(set (match_operand:DI 0 "register_operand")
4002 (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
4003 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4005 rtx reg1 = gen_reg_rtx (SFmode);
4006 rtx reg2 = gen_reg_rtx (SFmode);
4007 rtx reg3 = gen_reg_rtx (DImode);
4008 rtx_code_label *label1 = gen_label_rtx ();
4009 rtx_code_label *label2 = gen_label_rtx ();
4011 REAL_VALUE_TYPE offset;
4013 real_2expN (&offset, 63, SFmode);
4015 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
4016 do_pending_stack_adjust ();
4018 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4019 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4021 emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
4022 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4023 gen_rtx_LABEL_REF (VOIDmode, label2)));
4026 emit_label (label1);
4027 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4028 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4029 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4031 emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
4032 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4034 emit_label (label2);
4036 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4037 fields, and can't be used for REG_NOTES anyway). */
4038 emit_use (stack_pointer_rtx);
4043 ;; ....................
4047 ;; ....................
4049 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
4051 (define_expand "extvmisalign<mode>"
4052 [(set (match_operand:GPR 0 "register_operand")
4053 (sign_extract:GPR (match_operand:BLK 1 "memory_operand")
4054 (match_operand 2 "const_int_operand")
4055 (match_operand 3 "const_int_operand")))]
4058 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4059 INTVAL (operands[2]),
4060 INTVAL (operands[3]),
4061 /*unsigned=*/ false))
4067 (define_expand "extv<mode>"
4068 [(set (match_operand:GPR 0 "register_operand")
4069 (sign_extract:GPR (match_operand:GPR 1 "register_operand")
4070 (match_operand 2 "const_int_operand")
4071 (match_operand 3 "const_int_operand")))]
4074 if (UINTVAL (operands[2]) > 32)
4078 (define_insn "*extv<mode>"
4079 [(set (match_operand:GPR 0 "register_operand" "=d")
4080 (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4081 (match_operand 2 "const_int_operand" "")
4082 (match_operand 3 "const_int_operand" "")))]
4083 "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
4084 "exts\t%0,%1,%3,%m2"
4085 [(set_attr "type" "arith")
4086 (set_attr "mode" "<MODE>")])
4088 (define_expand "extzvmisalign<mode>"
4089 [(set (match_operand:GPR 0 "register_operand")
4090 (zero_extract:GPR (match_operand:BLK 1 "memory_operand")
4091 (match_operand 2 "const_int_operand")
4092 (match_operand 3 "const_int_operand")))]
4095 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4096 INTVAL (operands[2]),
4097 INTVAL (operands[3]),
4098 /*unsigned=*/ true))
4104 (define_expand "extzv<mode>"
4105 [(set (match_operand:GPR 0 "register_operand")
4106 (zero_extract:GPR (match_operand:GPR 1 "register_operand")
4107 (match_operand 2 "const_int_operand")
4108 (match_operand 3 "const_int_operand")))]
4111 if (!mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4112 INTVAL (operands[3])))
4116 (define_insn "*extzv<mode>"
4117 [(set (match_operand:GPR 0 "register_operand" "=d")
4118 (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4119 (match_operand 2 "const_int_operand" "")
4120 (match_operand 3 "const_int_operand" "")))]
4121 "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4122 INTVAL (operands[3]))"
4123 "<d>ext\t%0,%1,%3,%2"
4124 [(set_attr "type" "arith")
4125 (set_attr "mode" "<MODE>")])
4127 (define_insn "*extzv_truncsi_exts"
4128 [(set (match_operand:SI 0 "register_operand" "=d")
4130 (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
4131 (match_operand 2 "const_int_operand" "")
4132 (match_operand 3 "const_int_operand" ""))))]
4133 "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
4135 [(set_attr "type" "arith")
4136 (set_attr "mode" "SI")])
4139 (define_expand "insvmisalign<mode>"
4140 [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand")
4141 (match_operand 1 "const_int_operand")
4142 (match_operand 2 "const_int_operand"))
4143 (match_operand:GPR 3 "reg_or_0_operand"))]
4146 if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
4147 INTVAL (operands[1]),
4148 INTVAL (operands[2])))
4154 (define_expand "insv<mode>"
4155 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand")
4156 (match_operand 1 "const_int_operand")
4157 (match_operand 2 "const_int_operand"))
4158 (match_operand:GPR 3 "reg_or_0_operand"))]
4161 if (!mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4162 INTVAL (operands[2])))
4166 (define_insn "*insv<mode>"
4167 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
4168 (match_operand:SI 1 "const_int_operand" "")
4169 (match_operand:SI 2 "const_int_operand" ""))
4170 (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
4171 "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4172 INTVAL (operands[2]))"
4173 "<d>ins\t%0,%z3,%2,%1"
4174 [(set_attr "type" "arith")
4175 (set_attr "mode" "<MODE>")])
4177 ;; Combiner pattern for cins (clear and insert bit field). We can
4178 ;; implement mask-and-shift-left operation with this. Note that if
4179 ;; the upper bit of the mask is set in an SImode operation, the mask
4180 ;; itself will be sign-extended. mask_low_and_shift_len will
4181 ;; therefore be greater than our threshold of 32.
4183 (define_insn "*cins<mode>"
4184 [(set (match_operand:GPR 0 "register_operand" "=d")
4186 (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
4187 (match_operand:GPR 2 "const_int_operand" ""))
4188 (match_operand:GPR 3 "const_int_operand" "")))]
4190 && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
4193 GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
4194 return "cins\t%0,%1,%2,%m3";
4196 [(set_attr "type" "shift")
4197 (set_attr "mode" "<MODE>")])
4199 ;; Unaligned word moves generated by the bit field patterns.
4201 ;; As far as the rtl is concerned, both the left-part and right-part
4202 ;; instructions can access the whole field. However, the real operand
4203 ;; refers to just the first or the last byte (depending on endianness).
4204 ;; We therefore use two memory operands to each instruction, one to
4205 ;; describe the rtl effect and one to use in the assembly output.
4207 ;; Operands 0 and 1 are the rtl-level target and source respectively.
4208 ;; This allows us to use the standard length calculations for the "load"
4209 ;; and "store" type attributes.
4211 (define_insn "mov_<load>l"
4212 [(set (match_operand:GPR 0 "register_operand" "=d")
4213 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4214 (match_operand:QI 2 "memory_operand" "ZC")]
4216 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4218 [(set_attr "move_type" "load")
4219 (set_attr "mode" "<MODE>")])
4221 (define_insn "mov_<load>r"
4222 [(set (match_operand:GPR 0 "register_operand" "=d")
4223 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4224 (match_operand:QI 2 "memory_operand" "ZC")
4225 (match_operand:GPR 3 "register_operand" "0")]
4226 UNSPEC_LOAD_RIGHT))]
4227 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4229 [(set_attr "move_type" "load")
4230 (set_attr "mode" "<MODE>")])
4232 (define_insn "mov_<store>l"
4233 [(set (match_operand:BLK 0 "memory_operand" "=m")
4234 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4235 (match_operand:QI 2 "memory_operand" "ZC")]
4236 UNSPEC_STORE_LEFT))]
4237 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4239 [(set_attr "move_type" "store")
4240 (set_attr "mode" "<MODE>")])
4242 (define_insn "mov_<store>r"
4243 [(set (match_operand:BLK 0 "memory_operand" "+m")
4244 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4245 (match_operand:QI 2 "memory_operand" "ZC")
4247 UNSPEC_STORE_RIGHT))]
4248 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4250 [(set_attr "move_type" "store")
4251 (set_attr "mode" "<MODE>")])
4253 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
4254 ;; The required value is:
4256 ;; (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
4258 ;; which translates to:
4260 ;; lui op0,%highest(op1)
4261 ;; daddiu op0,op0,%higher(op1)
4263 ;; daddiu op0,op0,%hi(op1)
4266 ;; The split is deferred until after flow2 to allow the peephole2 below
4268 (define_insn_and_split "*lea_high64"
4269 [(set (match_operand:DI 0 "register_operand" "=d")
4270 (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
4271 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4273 "&& epilogue_completed"
4274 [(set (match_dup 0) (high:DI (match_dup 2)))
4275 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
4276 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
4277 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4278 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
4280 operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4281 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
4283 [(set_attr "insn_count" "5")])
4285 ;; Use a scratch register to reduce the latency of the above pattern
4286 ;; on superscalar machines. The optimized sequence is:
4288 ;; lui op1,%highest(op2)
4290 ;; daddiu op1,op1,%higher(op2)
4292 ;; daddu op1,op1,op0
4294 [(set (match_operand:DI 1 "d_operand")
4295 (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4296 (match_scratch:DI 0 "d")]
4297 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4298 [(set (match_dup 1) (high:DI (match_dup 3)))
4299 (set (match_dup 0) (high:DI (match_dup 4)))
4300 (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4301 (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4302 (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4304 operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4305 operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4308 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4309 ;; SYMBOL_ABSOLUTE X will take 6 cycles. This next pattern allows combine
4310 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4311 ;; used once. We can then use the sequence:
4313 ;; lui op0,%highest(op1)
4315 ;; daddiu op0,op0,%higher(op1)
4316 ;; daddiu op2,op2,%lo(op1)
4318 ;; daddu op0,op0,op2
4320 ;; which takes 4 cycles on most superscalar targets.
4321 (define_insn_and_split "*lea64"
4322 [(set (match_operand:DI 0 "register_operand" "=d")
4323 (match_operand:DI 1 "absolute_symbolic_operand" ""))
4324 (clobber (match_scratch:DI 2 "=&d"))]
4326 && TARGET_EXPLICIT_RELOCS
4327 && ABI_HAS_64BIT_SYMBOLS
4328 && cse_not_expected"
4330 "&& reload_completed"
4331 [(set (match_dup 0) (high:DI (match_dup 3)))
4332 (set (match_dup 2) (high:DI (match_dup 4)))
4333 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4334 (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4335 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4336 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4338 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4339 operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4341 [(set_attr "insn_count" "6")])
4343 ;; Split HIGHs into:
4348 ;; on MIPS16 targets.
4350 [(set (match_operand:P 0 "d_operand")
4351 (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4352 "TARGET_MIPS16 && reload_completed"
4353 [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4354 (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4356 (define_insn "*unshifted_high"
4357 [(set (match_operand:P 0 "d_operand" "=d")
4358 (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4359 UNSPEC_UNSHIFTED_HIGH))]
4362 [(set_attr "extended_mips16" "yes")])
4364 ;; Insns to fetch a symbol from a big GOT.
4366 (define_insn_and_split "*xgot_hi<mode>"
4367 [(set (match_operand:P 0 "register_operand" "=d")
4368 (high:P (match_operand:P 1 "got_disp_operand" "")))]
4369 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4371 "&& reload_completed"
4372 [(set (match_dup 0) (high:P (match_dup 2)))
4373 (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4375 operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4376 operands[3] = pic_offset_table_rtx;
4378 [(set_attr "got" "xgot_high")
4379 (set_attr "mode" "<MODE>")])
4381 (define_insn_and_split "*xgot_lo<mode>"
4382 [(set (match_operand:P 0 "register_operand" "=d")
4383 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4384 (match_operand:P 2 "got_disp_operand" "")))]
4385 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4387 "&& reload_completed"
4389 (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4390 { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4391 [(set_attr "got" "load")
4392 (set_attr "mode" "<MODE>")])
4394 ;; Insns to fetch a symbol from a normal GOT.
4396 (define_insn_and_split "*got_disp<mode>"
4397 [(set (match_operand:P 0 "register_operand" "=d")
4398 (match_operand:P 1 "got_disp_operand" ""))]
4399 "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4401 "&& reload_completed"
4402 [(set (match_dup 0) (match_dup 2))]
4403 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4404 [(set_attr "got" "load")
4405 (set_attr "mode" "<MODE>")])
4407 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4409 (define_insn_and_split "*got_page<mode>"
4410 [(set (match_operand:P 0 "register_operand" "=d")
4411 (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4412 "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4414 "&& reload_completed"
4415 [(set (match_dup 0) (match_dup 2))]
4416 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4417 [(set_attr "got" "load")
4418 (set_attr "mode" "<MODE>")])
4420 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4421 (define_expand "unspec_got_<mode>"
4422 [(unspec:P [(match_operand:P 0)
4423 (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4425 ;; Lower-level instructions for loading an address from the GOT.
4426 ;; We could use MEMs, but an unspec gives more optimization
4429 (define_insn "load_got<mode>"
4430 [(set (match_operand:P 0 "register_operand" "=d")
4431 (unspec:P [(match_operand:P 1 "register_operand" "d")
4432 (match_operand:P 2 "immediate_operand" "")]
4435 "<load>\t%0,%R2(%1)"
4436 [(set_attr "got" "load")
4437 (set_attr "mode" "<MODE>")])
4439 ;; Instructions for adding the low 16 bits of an address to a register.
4440 ;; Operand 2 is the address: mips_print_operand works out which relocation
4441 ;; should be applied.
4443 (define_insn "*low<mode>"
4444 [(set (match_operand:P 0 "register_operand" "=d")
4445 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4446 (match_operand:P 2 "immediate_operand" "")))]
4448 "<d>addiu\t%0,%1,%R2"
4449 [(set_attr "alu_type" "add")
4450 (set_attr "mode" "<MODE>")])
4452 (define_insn "*low<mode>_mips16"
4453 [(set (match_operand:P 0 "register_operand" "=d")
4454 (lo_sum:P (match_operand:P 1 "register_operand" "0")
4455 (match_operand:P 2 "immediate_operand" "")))]
4458 [(set_attr "alu_type" "add")
4459 (set_attr "mode" "<MODE>")
4460 (set_attr "extended_mips16" "yes")])
4462 ;; Expose MIPS16 uses of the global pointer after reload if the function
4463 ;; is responsible for setting up the register itself.
4465 [(set (match_operand:GPR 0 "d_operand")
4466 (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4467 "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4468 [(set (match_dup 0) (match_dup 1))]
4469 { operands[1] = pic_offset_table_rtx; })
4471 ;; Allow combine to split complex const_int load sequences, using operand 2
4472 ;; to store the intermediate results. See move_operand for details.
4474 [(set (match_operand:GPR 0 "register_operand")
4475 (match_operand:GPR 1 "splittable_const_int_operand"))
4476 (clobber (match_operand:GPR 2 "register_operand"))]
4480 mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4484 ;; Likewise, for symbolic operands.
4486 [(set (match_operand:P 0 "register_operand")
4487 (match_operand:P 1))
4488 (clobber (match_operand:P 2 "register_operand"))]
4489 "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4490 [(set (match_dup 0) (match_dup 3))]
4492 mips_split_symbol (operands[2], operands[1],
4493 MAX_MACHINE_MODE, &operands[3]);
4496 ;; 64-bit integer moves
4498 ;; Unlike most other insns, the move insns can't be split with
4499 ;; different predicates, because register spilling and other parts of
4500 ;; the compiler, have memoized the insn number already.
4502 (define_expand "movdi"
4503 [(set (match_operand:DI 0 "")
4504 (match_operand:DI 1 ""))]
4507 if (mips_legitimize_move (DImode, operands[0], operands[1]))
4511 ;; For mips16, we need a special case to handle storing $31 into
4512 ;; memory, since we don't have a constraint to match $31. This
4513 ;; instruction can be generated by save_restore_insns.
4515 (define_insn "*mov<mode>_ra"
4516 [(set (match_operand:GPR 0 "stack_operand" "=m")
4517 (reg:GPR RETURN_ADDR_REGNUM))]
4520 [(set_attr "move_type" "store")
4521 (set_attr "mode" "<MODE>")])
4523 (define_insn "*movdi_32bit"
4524 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d,*f,*f,*d,*m,*B*C*D,*B*C*D,*d,*m")
4525 (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"))]
4526 "!TARGET_64BIT && !TARGET_MIPS16
4527 && (register_operand (operands[0], DImode)
4528 || reg_or_0_operand (operands[1], DImode))"
4529 { return mips_output_move (operands[0], operands[1]); }
4530 [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4532 (if_then_else (eq_attr "move_type" "imul")
4534 (const_string "DI")))])
4536 (define_insn "*movdi_32bit_mips16"
4537 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4538 (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4539 "!TARGET_64BIT && TARGET_MIPS16
4540 && (register_operand (operands[0], DImode)
4541 || register_operand (operands[1], DImode))"
4542 { return mips_output_move (operands[0], operands[1]); }
4543 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4544 (set_attr "mode" "DI")])
4546 (define_insn "*movdi_64bit"
4547 [(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")
4548 (match_operand:DI 1 "move_operand" "d,Yd,Yf,m,dJ,*d*J,*m,*f,*f,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4549 "TARGET_64BIT && !TARGET_MIPS16
4550 && (register_operand (operands[0], DImode)
4551 || reg_or_0_operand (operands[1], DImode))"
4552 { return mips_output_move (operands[0], operands[1]); }
4553 [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4554 (set_attr "mode" "DI")])
4556 (define_insn "*movdi_64bit_mips16"
4557 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4558 (match_operand:DI 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4559 "TARGET_64BIT && TARGET_MIPS16
4560 && (register_operand (operands[0], DImode)
4561 || register_operand (operands[1], DImode))"
4562 { return mips_output_move (operands[0], operands[1]); }
4563 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4564 (set_attr "mode" "DI")])
4566 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4567 ;; when the original load is a 4 byte instruction but the add and the
4568 ;; load are 2 2 byte instructions.
4571 [(set (match_operand:DI 0 "d_operand")
4572 (mem:DI (plus:DI (match_dup 0)
4573 (match_operand:DI 1 "const_int_operand"))))]
4574 "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4575 && !TARGET_DEBUG_D_MODE
4576 && ((INTVAL (operands[1]) < 0
4577 && INTVAL (operands[1]) >= -0x10)
4578 || (INTVAL (operands[1]) >= 32 * 8
4579 && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4580 || (INTVAL (operands[1]) >= 0
4581 && INTVAL (operands[1]) < 32 * 8
4582 && (INTVAL (operands[1]) & 7) != 0))"
4583 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4584 (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4586 HOST_WIDE_INT val = INTVAL (operands[1]);
4589 operands[2] = const0_rtx;
4590 else if (val >= 32 * 8)
4594 operands[1] = GEN_INT (0x8 + off);
4595 operands[2] = GEN_INT (val - off - 0x8);
4601 operands[1] = GEN_INT (off);
4602 operands[2] = GEN_INT (val - off);
4606 ;; 32-bit Integer moves
4608 ;; Unlike most other insns, the move insns can't be split with
4609 ;; different predicates, because register spilling and other parts of
4610 ;; the compiler, have memoized the insn number already.
4612 (define_expand "mov<mode>"
4613 [(set (match_operand:IMOVE32 0 "")
4614 (match_operand:IMOVE32 1 ""))]
4617 if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4621 ;; The difference between these two is whether or not ints are allowed
4622 ;; in FP registers (off by default, use -mdebugh to enable).
4624 (define_insn "*mov<mode>_internal"
4625 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,!u,!u,d,e,!u,!ks,d,ZS,ZT,m,*f,*f,*d,*m,*d,*z,*a,*d,*B*C*D,*B*C*D,*d,*m")
4626 (match_operand:IMOVE32 1 "move_operand" "d,J,Udb7,Yd,Yf,ZT,ZS,m,!ks,!kbJ,dJ,*d*J,*m,*f,*f,*z,*d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4628 && (register_operand (operands[0], <MODE>mode)
4629 || reg_or_0_operand (operands[1], <MODE>mode))"
4630 { return mips_output_move (operands[0], operands[1]); }
4631 [(set_attr "move_type" "move,move,const,const,const,load,load,load,store,store,store,mtc,fpload,mfc,fpstore,mfc,mtc,mtlo,mflo,mtc,fpload,mfc,fpstore")
4632 (set_attr "compression" "all,micromips,micromips,*,*,micromips,micromips,*,micromips,micromips,*,*,*,*,*,*,*,*,*,*,*,*,*")
4633 (set_attr "mode" "SI")])
4635 (define_insn "*mov<mode>_mips16"
4636 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4637 (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4639 && (register_operand (operands[0], <MODE>mode)
4640 || register_operand (operands[1], <MODE>mode))"
4641 { return mips_output_move (operands[0], operands[1]); }
4642 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4643 (set_attr "mode" "SI")])
4645 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4646 ;; when the original load is a 4 byte instruction but the add and the
4647 ;; load are 2 2 byte instructions.
4650 [(set (match_operand:SI 0 "d_operand")
4651 (mem:SI (plus:SI (match_dup 0)
4652 (match_operand:SI 1 "const_int_operand"))))]
4653 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4654 && ((INTVAL (operands[1]) < 0
4655 && INTVAL (operands[1]) >= -0x80)
4656 || (INTVAL (operands[1]) >= 32 * 4
4657 && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4658 || (INTVAL (operands[1]) >= 0
4659 && INTVAL (operands[1]) < 32 * 4
4660 && (INTVAL (operands[1]) & 3) != 0))"
4661 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4662 (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4664 HOST_WIDE_INT val = INTVAL (operands[1]);
4667 operands[2] = const0_rtx;
4668 else if (val >= 32 * 4)
4672 operands[1] = GEN_INT (0x7c + off);
4673 operands[2] = GEN_INT (val - off - 0x7c);
4679 operands[1] = GEN_INT (off);
4680 operands[2] = GEN_INT (val - off);
4684 ;; On the mips16, we can split a load of certain constants into a load
4685 ;; and an add. This turns a 4 byte instruction into 2 2 byte
4689 [(set (match_operand:SI 0 "d_operand")
4690 (match_operand:SI 1 "const_int_operand"))]
4691 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4692 && INTVAL (operands[1]) >= 0x100
4693 && INTVAL (operands[1]) <= 0xff + 0x7f"
4694 [(set (match_dup 0) (match_dup 1))
4695 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4697 int val = INTVAL (operands[1]);
4699 operands[1] = GEN_INT (0xff);
4700 operands[2] = GEN_INT (val - 0xff);
4703 ;; MIPS4 supports loading and storing a floating point register from
4704 ;; the sum of two general registers. We use two versions for each of
4705 ;; these four instructions: one where the two general registers are
4706 ;; SImode, and one where they are DImode. This is because general
4707 ;; registers will be in SImode when they hold 32-bit values, but,
4708 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4709 ;; instructions will still work correctly.
4711 ;; ??? Perhaps it would be better to support these instructions by
4712 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends. However, since
4713 ;; these instructions can only be used to load and store floating
4714 ;; point registers, that would probably cause trouble in reload.
4716 (define_insn "*<ANYF:loadx>_<P:mode>"
4717 [(set (match_operand:ANYF 0 "register_operand" "=f")
4718 (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4719 (match_operand:P 2 "register_operand" "d"))))]
4721 "<ANYF:loadx>\t%0,%1(%2)"
4722 [(set_attr "type" "fpidxload")
4723 (set_attr "mode" "<ANYF:UNITMODE>")])
4725 (define_insn "*<ANYF:storex>_<P:mode>"
4726 [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4727 (match_operand:P 2 "register_operand" "d")))
4728 (match_operand:ANYF 0 "register_operand" "f"))]
4730 "<ANYF:storex>\t%0,%1(%2)"
4731 [(set_attr "type" "fpidxstore")
4732 (set_attr "mode" "<ANYF:UNITMODE>")])
4734 ;; Scaled indexed address load.
4735 ;; Per md.texi, we only need to look for a pattern with multiply in the
4736 ;; address expression, not shift.
4738 (define_insn "*lwxs"
4739 [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4741 (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4743 (match_operand:P 2 "register_operand" "d"))))]
4746 [(set_attr "type" "load")
4747 (set_attr "mode" "SI")])
4749 ;; 16-bit Integer moves
4751 ;; Unlike most other insns, the move insns can't be split with
4752 ;; different predicates, because register spilling and other parts of
4753 ;; the compiler, have memoized the insn number already.
4754 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4756 (define_expand "movhi"
4757 [(set (match_operand:HI 0 "")
4758 (match_operand:HI 1 ""))]
4761 if (mips_legitimize_move (HImode, operands[0], operands[1]))
4765 (define_insn "*movhi_internal"
4766 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZU,m,*a,*d")
4767 (match_operand:HI 1 "move_operand" "d,J,I,ZU,m,!kbJ,dJ,*d*J,*a"))]
4769 && (register_operand (operands[0], HImode)
4770 || reg_or_0_operand (operands[1], HImode))"
4771 { return mips_output_move (operands[0], operands[1]); }
4772 [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4773 (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4774 (set_attr "mode" "HI")])
4776 (define_insn "*movhi_mips16"
4777 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4778 (match_operand:HI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4780 && (register_operand (operands[0], HImode)
4781 || register_operand (operands[1], HImode))"
4782 { return mips_output_move (operands[0], operands[1]); }
4783 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4784 (set_attr "mode" "HI")])
4786 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
4787 ;; when the original load is a 4 byte instruction but the add and the
4788 ;; load are 2 2 byte instructions.
4791 [(set (match_operand:HI 0 "d_operand")
4792 (mem:HI (plus:SI (match_dup 0)
4793 (match_operand:SI 1 "const_int_operand"))))]
4794 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4795 && ((INTVAL (operands[1]) < 0
4796 && INTVAL (operands[1]) >= -0x80)
4797 || (INTVAL (operands[1]) >= 32 * 2
4798 && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
4799 || (INTVAL (operands[1]) >= 0
4800 && INTVAL (operands[1]) < 32 * 2
4801 && (INTVAL (operands[1]) & 1) != 0))"
4802 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4803 (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
4805 HOST_WIDE_INT val = INTVAL (operands[1]);
4808 operands[2] = const0_rtx;
4809 else if (val >= 32 * 2)
4813 operands[1] = GEN_INT (0x7e + off);
4814 operands[2] = GEN_INT (val - off - 0x7e);
4820 operands[1] = GEN_INT (off);
4821 operands[2] = GEN_INT (val - off);
4825 ;; 8-bit Integer moves
4827 ;; Unlike most other insns, the move insns can't be split with
4828 ;; different predicates, because register spilling and other parts of
4829 ;; the compiler, have memoized the insn number already.
4830 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4832 (define_expand "movqi"
4833 [(set (match_operand:QI 0 "")
4834 (match_operand:QI 1 ""))]
4837 if (mips_legitimize_move (QImode, operands[0], operands[1]))
4841 (define_insn "*movqi_internal"
4842 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZV,m,*a,*d")
4843 (match_operand:QI 1 "move_operand" "d,J,I,ZW,m,!kbJ,dJ,*d*J,*a"))]
4845 && (register_operand (operands[0], QImode)
4846 || reg_or_0_operand (operands[1], QImode))"
4847 { return mips_output_move (operands[0], operands[1]); }
4848 [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4849 (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4850 (set_attr "mode" "QI")])
4852 (define_insn "*movqi_mips16"
4853 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4854 (match_operand:QI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4856 && (register_operand (operands[0], QImode)
4857 || register_operand (operands[1], QImode))"
4858 { return mips_output_move (operands[0], operands[1]); }
4859 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4860 (set_attr "mode" "QI")])
4862 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
4863 ;; when the original load is a 4 byte instruction but the add and the
4864 ;; load are 2 2 byte instructions.
4867 [(set (match_operand:QI 0 "d_operand")
4868 (mem:QI (plus:SI (match_dup 0)
4869 (match_operand:SI 1 "const_int_operand"))))]
4870 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4871 && ((INTVAL (operands[1]) < 0
4872 && INTVAL (operands[1]) >= -0x80)
4873 || (INTVAL (operands[1]) >= 32
4874 && INTVAL (operands[1]) <= 31 + 0x7f))"
4875 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4876 (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
4878 HOST_WIDE_INT val = INTVAL (operands[1]);
4881 operands[2] = const0_rtx;
4884 operands[1] = GEN_INT (0x7f);
4885 operands[2] = GEN_INT (val - 0x7f);
4889 ;; 32-bit floating point moves
4891 (define_expand "movsf"
4892 [(set (match_operand:SF 0 "")
4893 (match_operand:SF 1 ""))]
4896 if (mips_legitimize_move (SFmode, operands[0], operands[1]))
4900 (define_insn "movccf"
4901 [(set (match_operand:CCF 0 "nonimmediate_operand" "=f,f,m")
4902 (match_operand:CCF 1 "nonimmediate_operand" "f,m,f"))]
4904 { return mips_output_move (operands[0], operands[1]); }
4905 [(set_attr "move_type" "fmove,fpload,fpstore")])
4907 (define_insn "*movsf_hardfloat"
4908 [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4909 (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
4911 && (register_operand (operands[0], SFmode)
4912 || reg_or_0_operand (operands[1], SFmode))"
4913 { return mips_output_move (operands[0], operands[1]); }
4914 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4915 (set_attr "mode" "SF")])
4917 (define_insn "*movsf_softfloat"
4918 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
4919 (match_operand:SF 1 "move_operand" "Gd,m,d"))]
4920 "TARGET_SOFT_FLOAT && !TARGET_MIPS16
4921 && (register_operand (operands[0], SFmode)
4922 || reg_or_0_operand (operands[1], SFmode))"
4923 { return mips_output_move (operands[0], operands[1]); }
4924 [(set_attr "move_type" "move,load,store")
4925 (set_attr "mode" "SF")])
4927 (define_insn "*movsf_mips16"
4928 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
4929 (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
4931 && (register_operand (operands[0], SFmode)
4932 || register_operand (operands[1], SFmode))"
4933 { return mips_output_move (operands[0], operands[1]); }
4934 [(set_attr "move_type" "move,move,move,load,store")
4935 (set_attr "mode" "SF")])
4937 ;; 64-bit floating point moves
4939 (define_expand "movdf"
4940 [(set (match_operand:DF 0 "")
4941 (match_operand:DF 1 ""))]
4944 if (mips_legitimize_move (DFmode, operands[0], operands[1]))
4948 (define_insn "*movdf_hardfloat"
4949 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4950 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
4951 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
4952 && (register_operand (operands[0], DFmode)
4953 || reg_or_0_operand (operands[1], DFmode))"
4954 { return mips_output_move (operands[0], operands[1]); }
4955 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4956 (set_attr "mode" "DF")])
4958 (define_insn "*movdf_softfloat"
4959 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
4960 (match_operand:DF 1 "move_operand" "dG,m,dG"))]
4961 "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
4962 && (register_operand (operands[0], DFmode)
4963 || reg_or_0_operand (operands[1], DFmode))"
4964 { return mips_output_move (operands[0], operands[1]); }
4965 [(set_attr "move_type" "move,load,store")
4966 (set_attr "mode" "DF")])
4968 (define_insn "*movdf_mips16"
4969 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
4970 (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
4972 && (register_operand (operands[0], DFmode)
4973 || register_operand (operands[1], DFmode))"
4974 { return mips_output_move (operands[0], operands[1]); }
4975 [(set_attr "move_type" "move,move,move,load,store")
4976 (set_attr "mode" "DF")])
4978 ;; 128-bit integer moves
4980 (define_expand "movti"
4981 [(set (match_operand:TI 0)
4982 (match_operand:TI 1))]
4985 if (mips_legitimize_move (TImode, operands[0], operands[1]))
4989 (define_insn "*movti"
4990 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d")
4991 (match_operand:TI 1 "move_operand" "d,i,m,dJ,*J,*d,*a"))]
4994 && (register_operand (operands[0], TImode)
4995 || reg_or_0_operand (operands[1], TImode))"
4996 { return mips_output_move (operands[0], operands[1]); }
4997 [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo")
4999 (if_then_else (eq_attr "move_type" "imul")
5001 (const_string "TI")))])
5003 (define_insn "*movti_mips16"
5004 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5005 (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
5008 && (register_operand (operands[0], TImode)
5009 || register_operand (operands[1], TImode))"
5011 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5012 (set_attr "mode" "TI")])
5014 ;; 128-bit floating point moves
5016 (define_expand "movtf"
5017 [(set (match_operand:TF 0)
5018 (match_operand:TF 1))]
5021 if (mips_legitimize_move (TFmode, operands[0], operands[1]))
5025 ;; This pattern handles both hard- and soft-float cases.
5026 (define_insn "*movtf"
5027 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
5028 (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
5031 && (register_operand (operands[0], TFmode)
5032 || reg_or_0_operand (operands[1], TFmode))"
5034 [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
5035 (set_attr "mode" "TF")])
5037 (define_insn "*movtf_mips16"
5038 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
5039 (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
5042 && (register_operand (operands[0], TFmode)
5043 || register_operand (operands[1], TFmode))"
5045 [(set_attr "move_type" "move,move,move,load,store")
5046 (set_attr "mode" "TF")])
5049 [(set (match_operand:MOVE64 0 "nonimmediate_operand")
5050 (match_operand:MOVE64 1 "move_operand"))]
5051 "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5054 mips_split_move_insn (operands[0], operands[1], curr_insn);
5059 [(set (match_operand:MOVE128 0 "nonimmediate_operand")
5060 (match_operand:MOVE128 1 "move_operand"))]
5061 "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5064 mips_split_move_insn (operands[0], operands[1], curr_insn);
5068 ;; When generating mips16 code, split moves of negative constants into
5069 ;; a positive "li" followed by a negation.
5071 [(set (match_operand 0 "d_operand")
5072 (match_operand 1 "const_int_operand"))]
5073 "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
5077 (neg:SI (match_dup 2)))]
5079 operands[2] = gen_lowpart (SImode, operands[0]);
5080 operands[3] = GEN_INT (-INTVAL (operands[1]));
5083 ;; 64-bit paired-single floating point moves
5085 (define_expand "movv2sf"
5086 [(set (match_operand:V2SF 0)
5087 (match_operand:V2SF 1))]
5088 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
5090 if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
5094 (define_insn "*movv2sf"
5095 [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5096 (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
5098 && TARGET_PAIRED_SINGLE_FLOAT
5099 && (register_operand (operands[0], V2SFmode)
5100 || reg_or_0_operand (operands[1], V2SFmode))"
5101 { return mips_output_move (operands[0], operands[1]); }
5102 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5103 (set_attr "mode" "DF")])
5105 ;; Extract the high part of a HI/LO value. See mips_hard_regno_mode_ok_p
5106 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
5108 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
5109 ;; instead of MFHI. This avoids both the normal MIPS III hi/lo hazards
5110 ;; and the errata related to -mfix-vr4130.
5111 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
5112 [(set (match_operand:GPR 0 "register_operand" "=d")
5113 (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
5116 { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
5117 [(set_attr "type" "mfhi")
5118 (set_attr "mode" "<GPR:MODE>")])
5120 ;; Set the high part of a HI/LO value, given that the low part has
5121 ;; already been set. See mips_hard_regno_mode_ok_p for the reason
5122 ;; why we can't just use (reg:GPR HI_REGNUM).
5123 (define_insn "mthi<GPR:mode>_<HILO:mode>"
5124 [(set (match_operand:HILO 0 "register_operand" "=x")
5125 (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
5126 (match_operand:GPR 2 "register_operand" "l")]
5130 [(set_attr "type" "mthi")
5131 (set_attr "mode" "SI")])
5133 ;; Emit a doubleword move in which exactly one of the operands is
5134 ;; a floating-point register. We can't just emit two normal moves
5135 ;; because of the constraints imposed by the FPU register model;
5136 ;; see mips_cannot_change_mode_class for details. Instead, we keep
5137 ;; the FPR whole and use special patterns to refer to each word of
5138 ;; the other operand.
5140 (define_expand "move_doubleword_fpr<mode>"
5141 [(set (match_operand:SPLITF 0)
5142 (match_operand:SPLITF 1))]
5145 if (FP_REG_RTX_P (operands[0]))
5147 rtx low = mips_subword (operands[1], 0);
5148 rtx high = mips_subword (operands[1], 1);
5149 emit_insn (gen_load_low<mode> (operands[0], low));
5150 if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5151 emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
5153 emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
5157 rtx low = mips_subword (operands[0], 0);
5158 rtx high = mips_subword (operands[0], 1);
5159 emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
5160 if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5161 emit_insn (gen_mfhc1<mode> (high, operands[1]));
5163 emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
5168 ;; Load the low word of operand 0 with operand 1.
5169 (define_insn "load_low<mode>"
5170 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5171 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
5175 operands[0] = mips_subword (operands[0], 0);
5176 return mips_output_move (operands[0], operands[1]);
5178 [(set_attr "move_type" "mtc,fpload")
5179 (set_attr "mode" "<HALFMODE>")])
5181 ;; Load the high word of operand 0 from operand 1, preserving the value
5183 (define_insn "load_high<mode>"
5184 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5185 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
5186 (match_operand:SPLITF 2 "register_operand" "0,0")]
5190 operands[0] = mips_subword (operands[0], 1);
5191 return mips_output_move (operands[0], operands[1]);
5193 [(set_attr "move_type" "mtc,fpload")
5194 (set_attr "mode" "<HALFMODE>")])
5196 ;; Store one word of operand 1 in operand 0. Operand 2 is 1 to store the
5197 ;; high word and 0 to store the low word.
5198 (define_insn "store_word<mode>"
5199 [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
5200 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
5201 (match_operand 2 "const_int_operand")]
5202 UNSPEC_STORE_WORD))]
5205 operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
5206 return mips_output_move (operands[0], operands[1]);
5208 [(set_attr "move_type" "mfc,fpstore")
5209 (set_attr "mode" "<HALFMODE>")])
5211 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
5212 ;; value in the low word.
5213 (define_insn "mthc1<mode>"
5214 [(set (match_operand:SPLITF 0 "register_operand" "=f")
5215 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
5216 (match_operand:SPLITF 2 "register_operand" "0")]
5218 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5220 [(set_attr "move_type" "mtc")
5221 (set_attr "mode" "<HALFMODE>")])
5223 ;; Move high word of operand 1 to operand 0 using mfhc1.
5224 (define_insn "mfhc1<mode>"
5225 [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
5226 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
5228 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5230 [(set_attr "move_type" "mfc")
5231 (set_attr "mode" "<HALFMODE>")])
5233 ;; Move a constant that satisfies CONST_GP_P into operand 0.
5234 (define_expand "load_const_gp_<mode>"
5235 [(set (match_operand:P 0 "register_operand" "=d")
5236 (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
5238 ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset
5239 ;; of _gp from the start of this function. Operand 1 is the incoming
5240 ;; function address.
5241 (define_insn_and_split "loadgp_newabi_<mode>"
5242 [(set (match_operand:P 0 "register_operand" "=&d")
5243 (unspec:P [(match_operand:P 1)
5244 (match_operand:P 2 "register_operand" "d")]
5246 "mips_current_loadgp_style () == LOADGP_NEWABI"
5247 { return mips_must_initialize_gp_p () ? "#" : ""; }
5248 "&& mips_must_initialize_gp_p ()"
5249 [(set (match_dup 0) (match_dup 3))
5250 (set (match_dup 0) (match_dup 4))
5251 (set (match_dup 0) (match_dup 5))]
5253 operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
5254 operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
5255 operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
5257 [(set_attr "type" "ghost")])
5259 ;; Likewise, for -mno-shared code. Operand 0 is the __gnu_local_gp symbol.
5260 (define_insn_and_split "loadgp_absolute_<mode>"
5261 [(set (match_operand:P 0 "register_operand" "=d")
5262 (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
5263 "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
5264 { return mips_must_initialize_gp_p () ? "#" : ""; }
5265 "&& mips_must_initialize_gp_p ()"
5268 mips_emit_move (operands[0], operands[1]);
5271 [(set_attr "type" "ghost")])
5273 ;; This blockage instruction prevents the gp load from being
5274 ;; scheduled after an implicit use of gp. It also prevents
5275 ;; the load from being deleted as dead.
5276 (define_insn "loadgp_blockage"
5277 [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5280 [(set_attr "type" "ghost")])
5282 ;; Initialize $gp for RTP PIC. Operand 0 is the __GOTT_BASE__ symbol
5283 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5284 (define_insn_and_split "loadgp_rtp_<mode>"
5285 [(set (match_operand:P 0 "register_operand" "=d")
5286 (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5287 (match_operand:P 2 "symbol_ref_operand")]
5289 "mips_current_loadgp_style () == LOADGP_RTP"
5290 { return mips_must_initialize_gp_p () ? "#" : ""; }
5291 "&& mips_must_initialize_gp_p ()"
5292 [(set (match_dup 0) (high:P (match_dup 3)))
5293 (set (match_dup 0) (unspec:P [(match_dup 0)
5294 (match_dup 3)] UNSPEC_LOAD_GOT))
5295 (set (match_dup 0) (unspec:P [(match_dup 0)
5296 (match_dup 4)] UNSPEC_LOAD_GOT))]
5298 operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5299 operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5301 [(set_attr "type" "ghost")])
5303 ;; Initialize the global pointer for MIPS16 code. Operand 0 is the
5304 ;; global pointer and operand 1 is the MIPS16 register that holds
5305 ;; the required value.
5306 (define_insn_and_split "copygp_mips16_<mode>"
5307 [(set (match_operand:P 0 "register_operand" "=y")
5308 (unspec:P [(match_operand:P 1 "register_operand" "d")]
5311 { return mips_must_initialize_gp_p () ? "#" : ""; }
5312 "&& mips_must_initialize_gp_p ()"
5313 [(set (match_dup 0) (match_dup 1))]
5315 [(set_attr "type" "ghost")])
5317 ;; A placeholder for where the cprestore instruction should go,
5318 ;; if we decide we need one. Operand 0 and operand 1 are as for
5319 ;; "cprestore". Operand 2 is a register that holds the gp value.
5321 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5322 ;; otherwise any register that holds the correct value will do.
5323 (define_insn_and_split "potential_cprestore_<mode>"
5324 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5325 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5326 (match_operand:P 2 "register_operand" "d,d")]
5327 UNSPEC_POTENTIAL_CPRESTORE))
5328 (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5329 "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5330 { return mips_must_initialize_gp_p () ? "#" : ""; }
5331 "mips_must_initialize_gp_p ()"
5334 mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5335 operands[2], operands[3]);
5338 [(set_attr "type" "ghost")])
5340 ;; Emit a .cprestore directive, which normally expands to a single store
5341 ;; instruction. Operand 0 is a (possibly illegitimate) sp-based MEM
5342 ;; for the cprestore slot. Operand 1 is the offset of the slot from
5343 ;; the stack pointer. (This is redundant with operand 0, but it makes
5344 ;; things a little simpler.)
5345 (define_insn "cprestore_<mode>"
5346 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5347 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5350 "TARGET_CPRESTORE_DIRECTIVE"
5352 if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5353 return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5355 return ".cprestore\t%1";
5357 [(set_attr "type" "store")
5358 (set_attr "insn_count" "1,3")])
5360 (define_insn "use_cprestore_<mode>"
5361 [(set (reg:P CPRESTORE_SLOT_REGNUM)
5362 (match_operand:P 0 "cprestore_load_slot_operand"))]
5365 [(set_attr "type" "ghost")])
5367 ;; Expand in-line code to clear the instruction cache between operand[0] and
5369 (define_expand "clear_cache"
5370 [(match_operand 0 "pmode_register_operand")
5371 (match_operand 1 "pmode_register_operand")]
5377 mips_expand_synci_loop (operands[0], operands[1]);
5378 emit_insn (gen_sync ());
5379 emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5381 else if (mips_cache_flush_func && mips_cache_flush_func[0])
5383 rtx len = gen_reg_rtx (Pmode);
5384 emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5385 MIPS_ICACHE_SYNC (operands[0], len);
5391 [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5393 { return mips_output_sync (); })
5395 (define_insn "synci"
5396 [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5401 (define_insn "rdhwr_synci_step_<mode>"
5402 [(set (match_operand:P 0 "register_operand" "=d")
5403 (unspec_volatile [(const_int 1)]
5408 (define_insn "clear_hazard_<mode>"
5409 [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5410 (clobber (reg:P RETURN_ADDR_REGNUM))]
5413 return "%(%<bal\t1f\n"
5415 "1:\t<d>addiu\t$31,$31,12\n"
5419 [(set_attr "insn_count" "5")])
5421 ;; Cache operations for R4000-style caches.
5422 (define_insn "mips_cache"
5423 [(set (mem:BLK (scratch))
5424 (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5425 (match_operand:QI 1 "address_operand" "ZD")]
5426 UNSPEC_MIPS_CACHE))]
5430 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5431 ;; operation. We keep the pattern distinct so that we can identify
5432 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5433 ;; the operation is never inserted into a delay slot.
5434 (define_insn "r10k_cache_barrier"
5435 [(set (mem:BLK (scratch))
5436 (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5439 [(set_attr "can_delay" "no")])
5441 ;; Block moves, see mips.c for more details.
5442 ;; Argument 0 is the destination
5443 ;; Argument 1 is the source
5444 ;; Argument 2 is the length
5445 ;; Argument 3 is the alignment
5447 (define_expand "movmemsi"
5448 [(parallel [(set (match_operand:BLK 0 "general_operand")
5449 (match_operand:BLK 1 "general_operand"))
5450 (use (match_operand:SI 2 ""))
5451 (use (match_operand:SI 3 "const_int_operand"))])]
5452 "!TARGET_MIPS16 && !TARGET_MEMCPY"
5454 if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5461 ;; ....................
5465 ;; ....................
5467 (define_expand "<optab><mode>3"
5468 [(set (match_operand:GPR 0 "register_operand")
5469 (any_shift:GPR (match_operand:GPR 1 "register_operand")
5470 (match_operand:SI 2 "arith_operand")))]
5473 /* On the mips16, a shift of more than 8 is a four byte instruction,
5474 so, for a shift between 8 and 16, it is just as fast to do two
5475 shifts of 8 or less. If there is a lot of shifting going on, we
5476 may win in CSE. Otherwise combine will put the shifts back
5477 together again. This can be called by mips_function_arg, so we must
5478 be careful not to allocate a new register if we've reached the
5482 && CONST_INT_P (operands[2])
5483 && INTVAL (operands[2]) > 8
5484 && INTVAL (operands[2]) <= 16
5485 && !reload_in_progress
5486 && !reload_completed)
5488 rtx temp = gen_reg_rtx (<MODE>mode);
5490 emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5491 emit_insn (gen_<optab><mode>3 (operands[0], temp,
5492 GEN_INT (INTVAL (operands[2]) - 8)));
5497 (define_insn "*<optab><mode>3"
5498 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
5499 (any_shift:GPR (match_operand:GPR 1 "register_operand" "!u,d")
5500 (match_operand:SI 2 "arith_operand" "Uib3,dI")))]
5503 if (CONST_INT_P (operands[2]))
5504 operands[2] = GEN_INT (INTVAL (operands[2])
5505 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5507 return "<d><insn>\t%0,%1,%2";
5509 [(set_attr "type" "shift")
5510 (set_attr "compression" "<shift_compression>,none")
5511 (set_attr "mode" "<MODE>")])
5513 (define_insn "*<optab>si3_extend"
5514 [(set (match_operand:DI 0 "register_operand" "=d")
5516 (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5517 (match_operand:SI 2 "arith_operand" "dI"))))]
5518 "TARGET_64BIT && !TARGET_MIPS16"
5520 if (CONST_INT_P (operands[2]))
5521 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5523 return "<insn>\t%0,%1,%2";
5525 [(set_attr "type" "shift")
5526 (set_attr "mode" "SI")])
5528 (define_insn "*<optab>si3_mips16"
5529 [(set (match_operand:SI 0 "register_operand" "=d,d,d")
5530 (any_shift:SI (match_operand:SI 1 "register_operand" "0,d,d")
5531 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5534 if (which_alternative == 0)
5535 return "<insn>\t%0,%2";
5537 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5538 return "<insn>\t%0,%1,%2";
5540 [(set_attr "type" "shift")
5541 (set_attr "mode" "SI")
5542 (set_attr "extended_mips16" "no,no,yes")])
5544 ;; We need separate DImode MIPS16 patterns because of the irregularity
5546 (define_insn "*ashldi3_mips16"
5547 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5548 (ashift:DI (match_operand:DI 1 "register_operand" "0,d,d")
5549 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5550 "TARGET_64BIT && TARGET_MIPS16"
5552 if (which_alternative == 0)
5553 return "dsll\t%0,%2";
5555 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5556 return "dsll\t%0,%1,%2";
5558 [(set_attr "type" "shift")
5559 (set_attr "mode" "DI")
5560 (set_attr "extended_mips16" "no,no,yes")])
5562 (define_insn "*ashrdi3_mips16"
5563 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5564 (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5565 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5566 "TARGET_64BIT && TARGET_MIPS16"
5568 if (CONST_INT_P (operands[2]))
5569 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5571 return "dsra\t%0,%2";
5573 [(set_attr "type" "shift")
5574 (set_attr "mode" "DI")
5575 (set_attr "extended_mips16" "no,no,yes")])
5577 (define_insn "*lshrdi3_mips16"
5578 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5579 (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5580 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5581 "TARGET_64BIT && TARGET_MIPS16"
5583 if (CONST_INT_P (operands[2]))
5584 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5586 return "dsrl\t%0,%2";
5588 [(set_attr "type" "shift")
5589 (set_attr "mode" "DI")
5590 (set_attr "extended_mips16" "no,no,yes")])
5592 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5595 [(set (match_operand:GPR 0 "d_operand")
5596 (any_shift:GPR (match_operand:GPR 1 "d_operand")
5597 (match_operand:GPR 2 "const_int_operand")))]
5598 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5599 && INTVAL (operands[2]) > 8
5600 && INTVAL (operands[2]) <= 16"
5601 [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5602 (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5603 { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5605 ;; If we load a byte on the mips16 as a bitfield, the resulting
5606 ;; sequence of instructions is too complicated for combine, because it
5607 ;; involves four instructions: a load, a shift, a constant load into a
5608 ;; register, and an and (the key problem here is that the mips16 does
5609 ;; not have and immediate). We recognize a shift of a load in order
5610 ;; to make it simple enough for combine to understand.
5612 ;; The instruction count here is the worst case.
5613 (define_insn_and_split ""
5614 [(set (match_operand:SI 0 "register_operand" "=d")
5615 (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5616 (match_operand:SI 2 "immediate_operand" "I")))]
5620 [(set (match_dup 0) (match_dup 1))
5621 (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5623 [(set_attr "type" "load")
5624 (set_attr "mode" "SI")
5625 (set (attr "insn_count")
5626 (symbol_ref "mips_load_store_insns (operands[1], insn) + 2"))])
5628 (define_insn "rotr<mode>3"
5629 [(set (match_operand:GPR 0 "register_operand" "=d")
5630 (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5631 (match_operand:SI 2 "arith_operand" "dI")))]
5634 if (CONST_INT_P (operands[2]))
5635 gcc_assert (INTVAL (operands[2]) >= 0
5636 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
5638 return "<d>ror\t%0,%1,%2";
5640 [(set_attr "type" "shift")
5641 (set_attr "mode" "<MODE>")])
5643 (define_insn "bswaphi2"
5644 [(set (match_operand:HI 0 "register_operand" "=d")
5645 (bswap:HI (match_operand:HI 1 "register_operand" "d")))]
5648 [(set_attr "type" "shift")])
5650 (define_insn_and_split "bswapsi2"
5651 [(set (match_operand:SI 0 "register_operand" "=d")
5652 (bswap:SI (match_operand:SI 1 "register_operand" "d")))]
5653 "ISA_HAS_WSBH && ISA_HAS_ROR"
5656 [(set (match_dup 0) (unspec:SI [(match_dup 1)] UNSPEC_WSBH))
5657 (set (match_dup 0) (rotatert:SI (match_dup 0) (const_int 16)))]
5659 [(set_attr "insn_count" "2")])
5661 (define_insn_and_split "bswapdi2"
5662 [(set (match_operand:DI 0 "register_operand" "=d")
5663 (bswap:DI (match_operand:DI 1 "register_operand" "d")))]
5664 "TARGET_64BIT && ISA_HAS_WSBH"
5667 [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_DSBH))
5668 (set (match_dup 0) (unspec:DI [(match_dup 0)] UNSPEC_DSHD))]
5670 [(set_attr "insn_count" "2")])
5673 [(set (match_operand:SI 0 "register_operand" "=d")
5674 (unspec:SI [(match_operand:SI 1 "register_operand" "d")] UNSPEC_WSBH))]
5677 [(set_attr "type" "shift")])
5680 [(set (match_operand:DI 0 "register_operand" "=d")
5681 (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSBH))]
5682 "TARGET_64BIT && ISA_HAS_WSBH"
5684 [(set_attr "type" "shift")])
5687 [(set (match_operand:DI 0 "register_operand" "=d")
5688 (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSHD))]
5689 "TARGET_64BIT && ISA_HAS_WSBH"
5691 [(set_attr "type" "shift")])
5694 ;; ....................
5696 ;; CONDITIONAL BRANCHES
5698 ;; ....................
5700 ;; Conditional branches on floating-point equality tests.
5702 (define_insn "*branch_fp_<mode>"
5705 (match_operator 1 "equality_operator"
5706 [(match_operand:FPCC 2 "register_operand" "<reg>")
5708 (label_ref (match_operand 0 "" ""))
5712 return mips_output_conditional_branch (insn, operands,
5713 MIPS_BRANCH ("b%F1", "%Z2%0"),
5714 MIPS_BRANCH ("b%W1", "%Z2%0"));
5716 [(set_attr "type" "branch")])
5718 (define_insn "*branch_fp_inverted_<mode>"
5721 (match_operator 1 "equality_operator"
5722 [(match_operand:FPCC 2 "register_operand" "<reg>")
5725 (label_ref (match_operand 0 "" ""))))]
5728 return mips_output_conditional_branch (insn, operands,
5729 MIPS_BRANCH ("b%W1", "%Z2%0"),
5730 MIPS_BRANCH ("b%F1", "%Z2%0"));
5732 [(set_attr "type" "branch")])
5734 ;; Conditional branches on ordered comparisons with zero.
5736 (define_insn "*branch_order<mode>"
5739 (match_operator 1 "order_operator"
5740 [(match_operand:GPR 2 "register_operand" "d")
5742 (label_ref (match_operand 0 "" ""))
5745 { return mips_output_order_conditional_branch (insn, operands, false); }
5746 [(set_attr "type" "branch")])
5748 (define_insn "*branch_order<mode>_inverted"
5751 (match_operator 1 "order_operator"
5752 [(match_operand:GPR 2 "register_operand" "d")
5755 (label_ref (match_operand 0 "" ""))))]
5757 { return mips_output_order_conditional_branch (insn, operands, true); }
5758 [(set_attr "type" "branch")])
5760 ;; Conditional branch on equality comparison.
5762 (define_insn "*branch_equality<mode>"
5765 (match_operator 1 "equality_operator"
5766 [(match_operand:GPR 2 "register_operand" "d")
5767 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5768 (label_ref (match_operand 0 "" ""))
5772 /* For a simple BNEZ or BEQZ microMIPS branch. */
5773 if (TARGET_MICROMIPS
5774 && operands[3] == const0_rtx
5775 && get_attr_length (insn) <= 8)
5776 return mips_output_conditional_branch (insn, operands,
5778 "%*b%N1z%:\t%2,%0");
5780 return mips_output_conditional_branch (insn, operands,
5781 MIPS_BRANCH ("b%C1", "%2,%z3,%0"),
5782 MIPS_BRANCH ("b%N1", "%2,%z3,%0"));
5784 [(set_attr "type" "branch")])
5786 (define_insn "*branch_equality<mode>_inverted"
5789 (match_operator 1 "equality_operator"
5790 [(match_operand:GPR 2 "register_operand" "d")
5791 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5793 (label_ref (match_operand 0 "" ""))))]
5796 /* For a simple BNEZ or BEQZ microMIPS branch. */
5797 if (TARGET_MICROMIPS
5798 && operands[3] == const0_rtx
5799 && get_attr_length (insn) <= 8)
5800 return mips_output_conditional_branch (insn, operands,
5802 "%*b%C0z%:\t%2,%1");
5804 return mips_output_conditional_branch (insn, operands,
5805 MIPS_BRANCH ("b%N1", "%2,%z3,%0"),
5806 MIPS_BRANCH ("b%C1", "%2,%z3,%0"));
5808 [(set_attr "type" "branch")])
5812 (define_insn "*branch_equality<mode>_mips16"
5815 (match_operator 1 "equality_operator"
5816 [(match_operand:GPR 2 "register_operand" "d,t")
5818 (label_ref (match_operand 0 "" ""))
5824 [(set_attr "type" "branch")])
5826 (define_insn "*branch_equality<mode>_mips16_inverted"
5829 (match_operator 1 "equality_operator"
5830 [(match_operand:GPR 2 "register_operand" "d,t")
5833 (label_ref (match_operand 0 "" ""))))]
5838 [(set_attr "type" "branch")])
5840 (define_expand "cbranch<mode>4"
5842 (if_then_else (match_operator 0 "comparison_operator"
5843 [(match_operand:GPR 1 "register_operand")
5844 (match_operand:GPR 2 "nonmemory_operand")])
5845 (label_ref (match_operand 3 ""))
5849 mips_expand_conditional_branch (operands);
5853 (define_expand "cbranch<mode>4"
5855 (if_then_else (match_operator 0 "comparison_operator"
5856 [(match_operand:SCALARF 1 "register_operand")
5857 (match_operand:SCALARF 2 "register_operand")])
5858 (label_ref (match_operand 3 ""))
5862 mips_expand_conditional_branch (operands);
5866 ;; Used to implement built-in functions.
5867 (define_expand "condjump"
5869 (if_then_else (match_operand 0)
5870 (label_ref (match_operand 1))
5873 ;; Branch if bit is set/clear.
5875 (define_insn "*branch_bit<bbv><mode>"
5878 (equality_op (zero_extract:GPR
5879 (match_operand:GPR 1 "register_operand" "d")
5881 (match_operand 2 "const_int_operand" ""))
5883 (label_ref (match_operand 0 ""))
5885 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5888 mips_output_conditional_branch (insn, operands,
5889 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
5890 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
5892 [(set_attr "type" "branch")
5893 (set_attr "branch_likely" "no")])
5895 (define_insn "*branch_bit<bbv><mode>_inverted"
5898 (equality_op (zero_extract:GPR
5899 (match_operand:GPR 1 "register_operand" "d")
5901 (match_operand 2 "const_int_operand" ""))
5904 (label_ref (match_operand 0 ""))))]
5905 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5908 mips_output_conditional_branch (insn, operands,
5909 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
5910 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
5912 [(set_attr "type" "branch")
5913 (set_attr "branch_likely" "no")])
5916 ;; ....................
5918 ;; SETTING A REGISTER FROM A COMPARISON
5920 ;; ....................
5922 ;; Destination is always set in SI mode.
5924 (define_expand "cstore<mode>4"
5925 [(set (match_operand:SI 0 "register_operand")
5926 (match_operator:SI 1 "mips_cstore_operator"
5927 [(match_operand:GPR 2 "register_operand")
5928 (match_operand:GPR 3 "nonmemory_operand")]))]
5931 mips_expand_scc (operands);
5935 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
5936 [(set (match_operand:GPR2 0 "register_operand" "=d")
5937 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5939 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5941 [(set_attr "type" "slt")
5942 (set_attr "mode" "<GPR:MODE>")])
5944 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
5945 [(set (match_operand:GPR2 0 "register_operand" "=t")
5946 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5948 "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5950 [(set_attr "type" "slt")
5951 (set_attr "mode" "<GPR:MODE>")])
5953 ;; Generate sltiu unless using seq results in better code.
5954 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
5955 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5956 (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5957 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5963 [(set_attr "type" "slt")
5964 (set_attr "mode" "<GPR:MODE>")])
5966 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
5967 [(set (match_operand:GPR2 0 "register_operand" "=d")
5968 (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
5970 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5972 [(set_attr "type" "slt")
5973 (set_attr "mode" "<GPR:MODE>")])
5975 ;; Generate sltu unless using sne results in better code.
5976 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
5977 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5978 (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5979 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5985 [(set_attr "type" "slt")
5986 (set_attr "mode" "<GPR:MODE>")])
5988 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
5989 [(set (match_operand:GPR2 0 "register_operand" "=d")
5990 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5991 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5994 [(set_attr "type" "slt")
5995 (set_attr "mode" "<GPR:MODE>")])
5997 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
5998 [(set (match_operand:GPR2 0 "register_operand" "=t")
5999 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6000 (match_operand:GPR 2 "register_operand" "d")))]
6003 [(set_attr "type" "slt")
6004 (set_attr "mode" "<GPR:MODE>")])
6006 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
6007 [(set (match_operand:GPR2 0 "register_operand" "=d")
6008 (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
6012 [(set_attr "type" "slt")
6013 (set_attr "mode" "<GPR:MODE>")])
6015 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
6016 [(set (match_operand:GPR2 0 "register_operand" "=d")
6017 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6018 (match_operand:GPR 2 "arith_operand" "dI")))]
6021 [(set_attr "type" "slt")
6022 (set_attr "mode" "<GPR:MODE>")])
6024 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
6025 [(set (match_operand:GPR2 0 "register_operand" "=t,t,t")
6026 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d,d")
6027 (match_operand:GPR 2 "arith_operand" "d,Uub8,I")))]
6030 [(set_attr "type" "slt")
6031 (set_attr "mode" "<GPR:MODE>")
6032 (set_attr "extended_mips16" "no,no,yes")])
6034 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
6035 [(set (match_operand:GPR2 0 "register_operand" "=d")
6036 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
6037 (match_operand:GPR 2 "sle_operand" "")))]
6040 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6041 return "slt<u>\t%0,%1,%2";
6043 [(set_attr "type" "slt")
6044 (set_attr "mode" "<GPR:MODE>")])
6046 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
6047 [(set (match_operand:GPR2 0 "register_operand" "=t,t")
6048 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
6049 (match_operand:GPR 2 "sle_operand" "Udb8,i")))]
6052 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6053 return "slt<u>\t%1,%2";
6055 [(set_attr "type" "slt")
6056 (set_attr "mode" "<GPR:MODE>")
6057 (set_attr "extended_mips16" "no,yes")])
6060 ;; ....................
6062 ;; FLOATING POINT COMPARISONS
6064 ;; ....................
6066 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6067 [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6068 (fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6069 (match_operand:SCALARF 2 "register_operand" "f")))]
6071 "<fpcmp>.<fcond>.<fmt>\t%Z0%1,%2"
6072 [(set_attr "type" "fcmp")
6073 (set_attr "mode" "FPSW")])
6075 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6076 [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6077 (swapped_fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6078 (match_operand:SCALARF 2 "register_operand" "f")))]
6080 "<fpcmp>.<swapped_fcond>.<fmt>\t%Z0%2,%1"
6081 [(set_attr "type" "fcmp")
6082 (set_attr "mode" "FPSW")])
6085 ;; ....................
6087 ;; UNCONDITIONAL BRANCHES
6089 ;; ....................
6091 ;; Unconditional branches.
6093 (define_expand "jump"
6095 (label_ref (match_operand 0)))])
6097 (define_insn "*jump_absolute"
6099 (label_ref (match_operand 0)))]
6100 "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
6102 if (get_attr_length (insn) <= 8)
6103 return "%*b\t%l0%/";
6105 return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/");
6107 [(set_attr "type" "branch")])
6109 (define_insn "*jump_pic"
6111 (label_ref (match_operand 0)))]
6112 "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
6114 if (get_attr_length (insn) <= 8)
6115 return "%*b\t%l0%/";
6118 mips_output_load_label (operands[0]);
6119 return "%*jr\t%@%/%]";
6122 [(set_attr "type" "branch")])
6124 ;; We need a different insn for the mips16, because a mips16 branch
6125 ;; does not have a delay slot.
6127 (define_insn "*jump_mips16"
6129 (label_ref (match_operand 0 "" "")))]
6132 [(set_attr "type" "branch")
6133 (set (attr "length")
6134 ;; This calculation is like the normal branch one, but the
6135 ;; range of the unextended instruction is [-0x800, 0x7fe] rather
6136 ;; than [-0x100, 0xfe]. This translates to a range of:
6138 ;; [-(0x800 - sizeof (branch)), 0x7fe]
6139 ;; == [-0x7fe, 0x7fe]
6141 ;; from the shorten_branches reference address. Long-branch
6142 ;; sequences will replace this one, so the minimum length
6143 ;; is one instruction shorter than for conditional branches.
6144 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
6145 (le (minus (pc) (match_dup 0)) (const_int 2046)))
6147 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
6148 (le (minus (pc) (match_dup 0)) (const_int 65532)))
6150 (and (match_test "TARGET_ABICALLS")
6151 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
6153 (match_test "Pmode == SImode")
6155 ] (const_int 22)))])
6157 (define_expand "indirect_jump"
6158 [(set (pc) (match_operand 0 "register_operand"))]
6161 operands[0] = force_reg (Pmode, operands[0]);
6162 emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
6166 (define_insn "indirect_jump_<mode>"
6167 [(set (pc) (match_operand:P 0 "register_operand" "d"))]
6170 if (TARGET_MICROMIPS)
6171 return "%*jr%:\t%0";
6175 [(set_attr "type" "jump")
6176 (set_attr "mode" "none")])
6178 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
6179 ;; sequences. Having a dedicated pattern is more convenient than
6180 ;; creating a SEQUENCE for this special case.
6181 (define_insn "indirect_jump_and_restore_<mode>"
6182 [(set (pc) (match_operand:P 1 "register_operand" "d"))
6183 (set (match_operand:P 0 "register_operand" "=d")
6184 (match_operand:P 2 "register_operand" "y"))]
6186 "%(%<jr\t%1\;move\t%0,%2%>%)"
6187 [(set_attr "type" "multi")
6188 (set_attr "extended_mips16" "yes")])
6190 (define_expand "tablejump"
6192 (match_operand 0 "register_operand"))
6193 (use (label_ref (match_operand 1 "")))]
6194 "!TARGET_MIPS16_SHORT_JUMP_TABLES"
6197 operands[0] = expand_binop (Pmode, add_optab, operands[0],
6198 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
6199 else if (TARGET_RTP_PIC)
6201 /* When generating RTP PIC, we use case table entries that are relative
6202 to the start of the function. Add the function's address to the
6204 rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6205 operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
6206 start, 0, 0, OPTAB_WIDEN);
6209 emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
6213 (define_insn "tablejump_<mode>"
6215 (match_operand:P 0 "register_operand" "d"))
6216 (use (label_ref (match_operand 1 "" "")))]
6219 if (TARGET_MICROMIPS)
6220 return "%*jr%:\t%0";
6224 [(set_attr "type" "jump")
6225 (set_attr "mode" "none")])
6227 ;; For MIPS16, we don't know whether a given jump table will use short or
6228 ;; word-sized offsets until late in compilation, when we are able to determine
6229 ;; the sizes of the insns which comprise the containing function. This
6230 ;; necessitates the use of the casesi rather than the tablejump pattern, since
6231 ;; the latter tries to calculate the index of the offset to jump through early
6232 ;; in compilation, i.e. at expand time, when nothing is known about the
6233 ;; eventual function layout.
6235 (define_expand "casesi"
6236 [(match_operand:SI 0 "register_operand" "") ; index to jump on
6237 (match_operand:SI 1 "const_int_operand" "") ; lower bound
6238 (match_operand:SI 2 "const_int_operand" "") ; total range
6239 (match_operand 3 "" "") ; table label
6240 (match_operand 4 "" "")] ; out of range label
6241 "TARGET_MIPS16_SHORT_JUMP_TABLES"
6243 if (operands[1] != const0_rtx)
6245 rtx reg = gen_reg_rtx (SImode);
6246 rtx offset = gen_int_mode (-INTVAL (operands[1]), SImode);
6248 if (!arith_operand (offset, SImode))
6249 offset = force_reg (SImode, offset);
6251 emit_insn (gen_addsi3 (reg, operands[0], offset));
6255 if (!arith_operand (operands[0], SImode))
6256 operands[0] = force_reg (SImode, operands[0]);
6258 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6260 emit_jump_insn (PMODE_INSN (gen_casesi_internal_mips16,
6261 (operands[0], operands[2],
6262 operands[3], operands[4])));
6267 (define_insn "casesi_internal_mips16_<mode>"
6270 (leu (match_operand:SI 0 "register_operand" "d")
6271 (match_operand:SI 1 "arith_operand" "dI"))
6274 (label_ref (match_operand 2 "" ""))]
6275 UNSPEC_CASESI_DISPATCH)
6276 (label_ref (match_operand 3 "" ""))))
6277 (clobber (match_scratch:P 4 "=d"))
6278 (clobber (match_scratch:P 5 "=d"))
6279 (clobber (reg:SI MIPS16_T_REGNUM))]
6280 "TARGET_MIPS16_SHORT_JUMP_TABLES"
6282 rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
6284 gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
6286 output_asm_insn ("sltu\t%0, %1", operands);
6287 output_asm_insn ("bteqz\t%3", operands);
6289 switch (GET_MODE (diff_vec))
6292 output_asm_insn ("sll\t%5, %0, 1", operands);
6293 output_asm_insn ("la\t%4, %2", operands);
6294 output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6295 output_asm_insn ("lh\t%5, 0(%5)", operands);
6299 output_asm_insn ("sll\t%5, %0, 2", operands);
6300 output_asm_insn ("la\t%4, %2", operands);
6301 output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6302 output_asm_insn ("lw\t%5, 0(%5)", operands);
6309 output_asm_insn ("addu\t%4, %4, %5", operands);
6313 [(set_attr "insn_count" "16")])
6315 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
6316 ;; While it is possible to either pull it off the stack (in the
6317 ;; o32 case) or recalculate it given t9 and our target label,
6318 ;; it takes 3 or 4 insns to do so.
6320 (define_expand "builtin_setjmp_setup"
6321 [(use (match_operand 0 "register_operand"))]
6326 addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
6327 mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
6331 ;; Restore the gp that we saved above. Despite the earlier comment, it seems
6332 ;; that older code did recalculate the gp from $25. Continue to jump through
6333 ;; $25 for compatibility (we lose nothing by doing so).
6335 (define_expand "builtin_longjmp"
6336 [(use (match_operand 0 "register_operand"))]
6339 /* The elements of the buffer are, in order: */
6340 int W = GET_MODE_SIZE (Pmode);
6341 rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6342 rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
6343 rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
6344 rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
6345 rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6346 /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
6347 The target is bound to be using $28 as the global pointer
6348 but the current function might not be. */
6349 rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
6351 /* This bit is similar to expand_builtin_longjmp except that it
6352 restores $gp as well. */
6353 mips_emit_move (hard_frame_pointer_rtx, fp);
6354 mips_emit_move (pv, lab);
6355 emit_stack_restore (SAVE_NONLOCAL, stack);
6356 mips_emit_move (gp, gpv);
6357 emit_use (hard_frame_pointer_rtx);
6358 emit_use (stack_pointer_rtx);
6360 emit_indirect_jump (pv);
6365 ;; ....................
6367 ;; Function prologue/epilogue
6369 ;; ....................
6372 (define_expand "prologue"
6376 mips_expand_prologue ();
6380 ;; Block any insns from being moved before this point, since the
6381 ;; profiling call to mcount can use various registers that aren't
6382 ;; saved or used to pass arguments.
6384 (define_insn "blockage"
6385 [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
6388 [(set_attr "type" "ghost")
6389 (set_attr "mode" "none")])
6391 (define_insn "probe_stack_range_<P:mode>"
6392 [(set (match_operand:P 0 "register_operand" "=d")
6393 (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
6394 (match_operand:P 2 "register_operand" "d")]
6395 UNSPEC_PROBE_STACK_RANGE))]
6397 { return mips_output_probe_stack_range (operands[0], operands[2]); }
6398 [(set_attr "type" "unknown")
6399 (set_attr "can_delay" "no")
6400 (set_attr "mode" "<MODE>")])
6402 (define_expand "epilogue"
6406 mips_expand_epilogue (false);
6410 (define_expand "sibcall_epilogue"
6414 mips_expand_epilogue (true);
6418 ;; Trivial return. Make it look like a normal return insn as that
6419 ;; allows jump optimizations to work better.
6421 (define_expand "return"
6423 "mips_can_use_return_insn ()"
6424 { mips_expand_before_return (); })
6426 (define_expand "simple_return"
6429 { mips_expand_before_return (); })
6431 (define_insn "*<optab>"
6435 if (TARGET_MICROMIPS)
6436 return "%*jr%:\t$31";
6438 return "%*j\t$31%/";
6440 [(set_attr "type" "jump")
6441 (set_attr "mode" "none")])
6445 (define_insn "<optab>_internal"
6447 (use (match_operand 0 "pmode_register_operand" ""))]
6450 if (TARGET_MICROMIPS)
6451 return "%*jr%:\t%0";
6455 [(set_attr "type" "jump")
6456 (set_attr "mode" "none")])
6458 ;; Exception return.
6459 (define_insn "mips_eret"
6461 (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6464 [(set_attr "type" "trap")
6465 (set_attr "mode" "none")])
6467 ;; Debug exception return.
6468 (define_insn "mips_deret"
6470 (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6473 [(set_attr "type" "trap")
6474 (set_attr "mode" "none")])
6476 ;; Disable interrupts.
6477 (define_insn "mips_di"
6478 [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6481 [(set_attr "type" "trap")
6482 (set_attr "mode" "none")])
6484 ;; Execution hazard barrier.
6485 (define_insn "mips_ehb"
6486 [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6489 [(set_attr "type" "trap")
6490 (set_attr "mode" "none")])
6492 ;; Read GPR from previous shadow register set.
6493 (define_insn "mips_rdpgpr"
6494 [(set (match_operand:SI 0 "register_operand" "=d")
6495 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d")]
6499 [(set_attr "type" "move")
6500 (set_attr "mode" "SI")])
6502 ;; Move involving COP0 registers.
6503 (define_insn "cop0_move"
6504 [(set (match_operand:SI 0 "register_operand" "=B,d")
6505 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6508 { return mips_output_move (operands[0], operands[1]); }
6509 [(set_attr "type" "mtc,mfc")
6510 (set_attr "mode" "SI")])
6512 ;; This is used in compiling the unwind routines.
6513 (define_expand "eh_return"
6514 [(use (match_operand 0 "general_operand"))]
6517 if (GET_MODE (operands[0]) != word_mode)
6518 operands[0] = convert_to_mode (word_mode, operands[0], 0);
6520 emit_insn (gen_eh_set_lr_di (operands[0]));
6522 emit_insn (gen_eh_set_lr_si (operands[0]));
6526 ;; Clobber the return address on the stack. We can't expand this
6527 ;; until we know where it will be put in the stack frame.
6529 (define_insn "eh_set_lr_si"
6530 [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6531 (clobber (match_scratch:SI 1 "=&d"))]
6535 (define_insn "eh_set_lr_di"
6536 [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6537 (clobber (match_scratch:DI 1 "=&d"))]
6542 [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6543 (clobber (match_scratch 1))]
6547 mips_set_return_address (operands[0], operands[1]);
6551 (define_expand "exception_receiver"
6555 /* See the comment above load_call<mode> for details. */
6556 emit_insn (gen_set_got_version ());
6558 /* If we have a call-clobbered $gp, restore it from its save slot. */
6559 if (HAVE_restore_gp_si)
6560 emit_insn (gen_restore_gp_si ());
6561 else if (HAVE_restore_gp_di)
6562 emit_insn (gen_restore_gp_di ());
6566 (define_expand "nonlocal_goto_receiver"
6570 /* See the comment above load_call<mode> for details. */
6571 emit_insn (gen_set_got_version ());
6575 ;; Restore $gp from its .cprestore stack slot. The instruction remains
6576 ;; volatile until all uses of $28 are exposed.
6577 (define_insn_and_split "restore_gp_<mode>"
6579 (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6580 (clobber (match_scratch:P 0 "=&d"))]
6581 "TARGET_CALL_CLOBBERED_GP"
6583 "&& epilogue_completed"
6586 mips_restore_gp_from_cprestore_slot (operands[0]);
6589 [(set_attr "type" "ghost")])
6591 ;; Move between $gp and its register save slot.
6592 (define_insn_and_split "move_gp<mode>"
6593 [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6594 (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6597 { return mips_must_initialize_gp_p () ? "#" : ""; }
6598 "mips_must_initialize_gp_p ()"
6601 mips_emit_move (operands[0], operands[1]);
6604 [(set_attr "type" "ghost")])
6607 ;; ....................
6611 ;; ....................
6613 ;; Instructions to load a call address from the GOT. The address might
6614 ;; point to a function or to a lazy binding stub. In the latter case,
6615 ;; the stub will use the dynamic linker to resolve the function, which
6616 ;; in turn will change the GOT entry to point to the function's real
6619 ;; This means that every call, even pure and constant ones, can
6620 ;; potentially modify the GOT entry. And once a stub has been called,
6621 ;; we must not call it again.
6623 ;; We represent this restriction using an imaginary, fixed, call-saved
6624 ;; register called GOT_VERSION_REGNUM. The idea is to make the register
6625 ;; live throughout the function and to change its value after every
6626 ;; potential call site. This stops any rtx value that uses the register
6627 ;; from being computed before an earlier call. To do this, we:
6629 ;; - Ensure that the register is live on entry to the function,
6630 ;; so that it is never thought to be used uninitalized.
6632 ;; - Ensure that the register is live on exit from the function,
6633 ;; so that it is live throughout.
6635 ;; - Make each call (lazily-bound or not) use the current value
6636 ;; of GOT_VERSION_REGNUM, so that updates of the register are
6637 ;; not moved across call boundaries.
6639 ;; - Add "ghost" definitions of the register to the beginning of
6640 ;; blocks reached by EH and ABNORMAL_CALL edges, because those
6641 ;; edges may involve calls that normal paths don't. (E.g. the
6642 ;; unwinding code that handles a non-call exception may change
6643 ;; lazily-bound GOT entries.) We do this by making the
6644 ;; exception_receiver and nonlocal_goto_receiver expanders emit
6645 ;; a set_got_version instruction.
6647 ;; - After each call (lazily-bound or not), use a "ghost"
6648 ;; update_got_version instruction to change the register's value.
6649 ;; This instruction mimics the _possible_ effect of the dynamic
6650 ;; resolver during the call and it remains live even if the call
6651 ;; itself becomes dead.
6653 ;; - Leave GOT_VERSION_REGNUM out of all register classes.
6654 ;; The register is therefore not a valid register_operand
6655 ;; and cannot be moved to or from other registers.
6657 (define_insn "load_call<mode>"
6658 [(set (match_operand:P 0 "register_operand" "=d")
6659 (unspec:P [(match_operand:P 1 "register_operand" "d")
6660 (match_operand:P 2 "immediate_operand" "")
6661 (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6663 "<load>\t%0,%R2(%1)"
6664 [(set_attr "got" "load")
6665 (set_attr "mode" "<MODE>")])
6667 (define_insn "set_got_version"
6668 [(set (reg:SI GOT_VERSION_REGNUM)
6669 (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6672 [(set_attr "type" "ghost")])
6674 (define_insn "update_got_version"
6675 [(set (reg:SI GOT_VERSION_REGNUM)
6676 (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6679 [(set_attr "type" "ghost")])
6681 ;; Sibling calls. All these patterns use jump instructions.
6683 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6684 ;; addresses if a direct jump is acceptable. Since the 'S' constraint
6685 ;; is defined in terms of call_insn_operand, the same is true of the
6688 ;; When we use an indirect jump, we need a register that will be
6689 ;; preserved by the epilogue. Since TARGET_USE_PIC_FN_ADDR_REG forces
6690 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6691 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6694 (define_expand "sibcall"
6695 [(parallel [(call (match_operand 0 "")
6696 (match_operand 1 ""))
6697 (use (match_operand 2 "")) ;; next_arg_reg
6698 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6701 mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6702 operands[1], operands[2], false);
6706 (define_insn "sibcall_internal"
6707 [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6708 (match_operand 1 "" ""))]
6709 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6711 if (TARGET_MICROMIPS)
6712 return MICROMIPS_J ("j", operands, 0);
6714 return MIPS_CALL ("j", operands, 0, 1);
6716 [(set_attr "jal" "indirect,direct")
6717 (set_attr "jal_macro" "no")])
6719 (define_expand "sibcall_value"
6720 [(parallel [(set (match_operand 0 "")
6721 (call (match_operand 1 "")
6722 (match_operand 2 "")))
6723 (use (match_operand 3 ""))])] ;; next_arg_reg
6726 mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6727 operands[2], operands[3], false);
6731 (define_insn "sibcall_value_internal"
6732 [(set (match_operand 0 "register_operand" "")
6733 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6734 (match_operand 2 "" "")))]
6735 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6737 if (TARGET_MICROMIPS)
6738 return MICROMIPS_J ("j", operands, 1);
6740 return MIPS_CALL ("j", operands, 1, 2);
6742 [(set_attr "jal" "indirect,direct")
6743 (set_attr "jal_macro" "no")])
6745 (define_insn "sibcall_value_multiple_internal"
6746 [(set (match_operand 0 "register_operand" "")
6747 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6748 (match_operand 2 "" "")))
6749 (set (match_operand 3 "register_operand" "")
6750 (call (mem:SI (match_dup 1))
6752 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6754 if (TARGET_MICROMIPS)
6755 return MICROMIPS_J ("j", operands, 1);
6757 return MIPS_CALL ("j", operands, 1, 2);
6759 [(set_attr "jal" "indirect,direct")
6760 (set_attr "jal_macro" "no")])
6762 (define_expand "call"
6763 [(parallel [(call (match_operand 0 "")
6764 (match_operand 1 ""))
6765 (use (match_operand 2 "")) ;; next_arg_reg
6766 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6769 mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6770 operands[1], operands[2], false);
6774 ;; This instruction directly corresponds to an assembly-language "jal".
6775 ;; There are four cases:
6778 ;; Both symbolic and register destinations are OK. The pattern
6779 ;; always expands to a single mips instruction.
6781 ;; - -mabicalls/-mno-explicit-relocs:
6782 ;; Again, both symbolic and register destinations are OK.
6783 ;; The call is treated as a multi-instruction black box.
6785 ;; - -mabicalls/-mexplicit-relocs with n32 or n64:
6786 ;; Only "jal $25" is allowed. This expands to a single "jalr $25"
6789 ;; - -mabicalls/-mexplicit-relocs with o32 or o64:
6790 ;; Only "jal $25" is allowed. The call is actually two instructions:
6791 ;; "jalr $25" followed by an insn to reload $gp.
6793 ;; In the last case, we can generate the individual instructions with
6794 ;; a define_split. There are several things to be wary of:
6796 ;; - We can't expose the load of $gp before reload. If we did,
6797 ;; it might get removed as dead, but reload can introduce new
6798 ;; uses of $gp by rematerializing constants.
6800 ;; - We shouldn't restore $gp after calls that never return.
6801 ;; It isn't valid to insert instructions between a noreturn
6802 ;; call and the following barrier.
6804 ;; - The splitter deliberately changes the liveness of $gp. The unsplit
6805 ;; instruction preserves $gp and so have no effect on its liveness.
6806 ;; But once we generate the separate insns, it becomes obvious that
6807 ;; $gp is not live on entry to the call.
6809 (define_insn_and_split "call_internal"
6810 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6811 (match_operand 1 "" ""))
6812 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6814 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, 1); }
6815 "reload_completed && TARGET_SPLIT_CALLS"
6818 mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
6821 [(set_attr "jal" "indirect,direct")])
6823 (define_insn "call_split"
6824 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6825 (match_operand 1 "" ""))
6826 (clobber (reg:SI RETURN_ADDR_REGNUM))
6827 (clobber (reg:SI 28))]
6828 "TARGET_SPLIT_CALLS"
6829 { return MIPS_CALL ("jal", operands, 0, 1); }
6830 [(set_attr "jal" "indirect,direct")
6831 (set_attr "jal_macro" "no")])
6833 ;; A pattern for calls that must be made directly. It is used for
6834 ;; MIPS16 calls that the linker may need to redirect to a hard-float
6835 ;; stub; the linker relies on the call relocation type to detect when
6836 ;; such redirection is needed.
6837 (define_insn_and_split "call_internal_direct"
6838 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6841 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6843 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, -1); }
6844 "reload_completed && TARGET_SPLIT_CALLS"
6847 mips_split_call (curr_insn,
6848 gen_call_direct_split (operands[0], operands[1]));
6851 [(set_attr "jal" "direct")])
6853 (define_insn "call_direct_split"
6854 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6857 (clobber (reg:SI RETURN_ADDR_REGNUM))
6858 (clobber (reg:SI 28))]
6859 "TARGET_SPLIT_CALLS"
6860 { return MIPS_CALL ("jal", operands, 0, -1); }
6861 [(set_attr "jal" "direct")
6862 (set_attr "jal_macro" "no")])
6864 (define_expand "call_value"
6865 [(parallel [(set (match_operand 0 "")
6866 (call (match_operand 1 "")
6867 (match_operand 2 "")))
6868 (use (match_operand 3 ""))])] ;; next_arg_reg
6871 mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
6872 operands[2], operands[3], false);
6876 ;; See comment for call_internal.
6877 (define_insn_and_split "call_value_internal"
6878 [(set (match_operand 0 "register_operand" "")
6879 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6880 (match_operand 2 "" "")))
6881 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6883 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6884 "reload_completed && TARGET_SPLIT_CALLS"
6887 mips_split_call (curr_insn,
6888 gen_call_value_split (operands[0], operands[1],
6892 [(set_attr "jal" "indirect,direct")])
6894 (define_insn "call_value_split"
6895 [(set (match_operand 0 "register_operand" "")
6896 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6897 (match_operand 2 "" "")))
6898 (clobber (reg:SI RETURN_ADDR_REGNUM))
6899 (clobber (reg:SI 28))]
6900 "TARGET_SPLIT_CALLS"
6901 { return MIPS_CALL ("jal", operands, 1, 2); }
6902 [(set_attr "jal" "indirect,direct")
6903 (set_attr "jal_macro" "no")])
6905 ;; See call_internal_direct.
6906 (define_insn_and_split "call_value_internal_direct"
6907 [(set (match_operand 0 "register_operand")
6908 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6911 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6913 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, -1); }
6914 "reload_completed && TARGET_SPLIT_CALLS"
6917 mips_split_call (curr_insn,
6918 gen_call_value_direct_split (operands[0], operands[1],
6922 [(set_attr "jal" "direct")])
6924 (define_insn "call_value_direct_split"
6925 [(set (match_operand 0 "register_operand")
6926 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6929 (clobber (reg:SI RETURN_ADDR_REGNUM))
6930 (clobber (reg:SI 28))]
6931 "TARGET_SPLIT_CALLS"
6932 { return MIPS_CALL ("jal", operands, 1, -1); }
6933 [(set_attr "jal" "direct")
6934 (set_attr "jal_macro" "no")])
6936 ;; See comment for call_internal.
6937 (define_insn_and_split "call_value_multiple_internal"
6938 [(set (match_operand 0 "register_operand" "")
6939 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6940 (match_operand 2 "" "")))
6941 (set (match_operand 3 "register_operand" "")
6942 (call (mem:SI (match_dup 1))
6944 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6946 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6947 "reload_completed && TARGET_SPLIT_CALLS"
6950 mips_split_call (curr_insn,
6951 gen_call_value_multiple_split (operands[0], operands[1],
6952 operands[2], operands[3]));
6955 [(set_attr "jal" "indirect,direct")])
6957 (define_insn "call_value_multiple_split"
6958 [(set (match_operand 0 "register_operand" "")
6959 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6960 (match_operand 2 "" "")))
6961 (set (match_operand 3 "register_operand" "")
6962 (call (mem:SI (match_dup 1))
6964 (clobber (reg:SI RETURN_ADDR_REGNUM))
6965 (clobber (reg:SI 28))]
6966 "TARGET_SPLIT_CALLS"
6967 { return MIPS_CALL ("jal", operands, 1, 2); }
6968 [(set_attr "jal" "indirect,direct")
6969 (set_attr "jal_macro" "no")])
6971 ;; Call subroutine returning any type.
6973 (define_expand "untyped_call"
6974 [(parallel [(call (match_operand 0 "")
6976 (match_operand 1 "")
6977 (match_operand 2 "")])]
6982 emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
6984 for (i = 0; i < XVECLEN (operands[2], 0); i++)
6986 rtx set = XVECEXP (operands[2], 0, i);
6987 mips_emit_move (SET_DEST (set), SET_SRC (set));
6990 emit_insn (gen_blockage ());
6995 ;; ....................
6999 ;; ....................
7003 (define_insn "prefetch"
7004 [(prefetch (match_operand:QI 0 "address_operand" "ZD")
7005 (match_operand 1 "const_int_operand" "n")
7006 (match_operand 2 "const_int_operand" "n"))]
7007 "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
7009 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
7011 /* Loongson 2[ef] and Loongson 3a use load to $0 for prefetching. */
7013 return "ld\t$0,%a0";
7015 return "lw\t$0,%a0";
7017 operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
7018 return "pref\t%1,%a0";
7020 [(set_attr "type" "prefetch")])
7022 (define_insn "*prefetch_indexed_<mode>"
7023 [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
7024 (match_operand:P 1 "register_operand" "d"))
7025 (match_operand 2 "const_int_operand" "n")
7026 (match_operand 3 "const_int_operand" "n"))]
7027 "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
7029 operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
7030 return "prefx\t%2,%1(%0)";
7032 [(set_attr "type" "prefetchx")])
7038 [(set_attr "type" "nop")
7039 (set_attr "mode" "none")])
7041 ;; Like nop, but commented out when outside a .set noreorder block.
7042 (define_insn "hazard_nop"
7046 if (mips_noreorder.nesting_level > 0)
7051 [(set_attr "type" "nop")])
7053 ;; MIPS4 Conditional move instructions.
7055 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
7056 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7058 (match_operator 4 "equality_operator"
7059 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7061 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7062 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7067 [(set_attr "type" "condmove")
7068 (set_attr "mode" "<GPR:MODE>")])
7070 (define_insn "*mov<GPR:mode>_on_<GPR2:mode>_ne"
7071 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7073 (match_operand:GPR2 1 "register_operand" "<GPR2:reg>,<GPR2:reg>")
7074 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7075 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7080 [(set_attr "type" "condmove")
7081 (set_attr "mode" "<GPR:MODE>")])
7083 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
7084 [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
7085 (if_then_else:SCALARF
7086 (match_operator 4 "equality_operator"
7087 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7089 (match_operand:SCALARF 2 "register_operand" "f,0")
7090 (match_operand:SCALARF 3 "register_operand" "0,f")))]
7091 "ISA_HAS_FP_CONDMOVE"
7093 mov%T4.<fmt>\t%0,%2,%1
7094 mov%t4.<fmt>\t%0,%3,%1"
7095 [(set_attr "type" "condmove")
7096 (set_attr "mode" "<SCALARF:MODE>")])
7098 (define_insn "*sel<code><GPR:mode>_using_<GPR2:mode>"
7099 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7101 (equality_op:GPR2 (match_operand:GPR2 1 "register_operand" "d,d")
7103 (match_operand:GPR 2 "reg_or_0_operand" "d,J")
7104 (match_operand:GPR 3 "reg_or_0_operand" "J,d")))]
7106 && (register_operand (operands[2], <GPR:MODE>mode)
7107 != register_operand (operands[3], <GPR:MODE>mode))"
7111 [(set_attr "type" "condmove")
7112 (set_attr "mode" "<GPR:MODE>")])
7114 ;; sel.fmt copies the 3rd argument when the 1st is non-zero and the 2nd
7115 ;; argument if the 1st is zero. This means operand 2 and 3 are
7116 ;; inverted in the instruction.
7118 (define_insn "*sel<mode>"
7119 [(set (match_operand:SCALARF 0 "register_operand" "=f,f,f")
7120 (if_then_else:SCALARF
7121 (ne:CCF (match_operand:CCF 1 "register_operand" "0,f,f")
7123 (match_operand:SCALARF 2 "reg_or_0_operand" "f,G,f")
7124 (match_operand:SCALARF 3 "reg_or_0_operand" "f,f,G")))]
7125 "ISA_HAS_SEL && ISA_HAS_CCF"
7128 seleqz.<fmt>\t%0,%3,%1
7129 selnez.<fmt>\t%0,%2,%1"
7130 [(set_attr "type" "condmove")
7131 (set_attr "mode" "<SCALARF:MODE>")])
7133 ;; These are the main define_expand's used to make conditional moves.
7135 (define_expand "mov<mode>cc"
7136 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7137 (set (match_operand:GPR 0 "register_operand")
7138 (if_then_else:GPR (match_dup 5)
7139 (match_operand:GPR 2 "reg_or_0_operand")
7140 (match_operand:GPR 3 "reg_or_0_operand")))]
7141 "ISA_HAS_CONDMOVE || ISA_HAS_SEL"
7143 if (ISA_HAS_SEL && !INTEGRAL_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7146 mips_expand_conditional_move (operands);
7150 (define_expand "mov<mode>cc"
7151 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7152 (set (match_operand:SCALARF 0 "register_operand")
7153 (if_then_else:SCALARF (match_dup 5)
7154 (match_operand:SCALARF 2 "reg_or_0_operand")
7155 (match_operand:SCALARF 3 "reg_or_0_operand")))]
7156 "ISA_HAS_FP_CONDMOVE
7157 || (ISA_HAS_SEL && ISA_HAS_CCF)"
7159 if (ISA_HAS_SEL && !FLOAT_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7162 /* Workaround an LRA bug which means that tied operands in the sel.fmt
7163 pattern lead to the double precision destination of sel.d getting
7164 reloaded with the full register file usable and the restrictions on
7165 whether the CCFmode input can be used in odd-numbered single-precision
7166 registers are ignored. For consistency reasons the CCF mode values
7167 must be guaranteed to only exist in the even-registers because of
7168 the unusual duality between single and double precision values. */
7169 if (ISA_HAS_SEL && <MODE>mode == DFmode
7170 && (!TARGET_ODD_SPREG || TARGET_FLOATXX))
7173 mips_expand_conditional_move (operands);
7178 ;; ....................
7180 ;; mips16 inline constant tables
7182 ;; ....................
7185 (define_insn "consttable_tls_reloc"
7186 [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
7187 (match_operand 1 "const_int_operand" "")]
7188 UNSPEC_CONSTTABLE_INT)]
7189 "TARGET_MIPS16_PCREL_LOADS"
7190 { return mips_output_tls_reloc_directive (&operands[0]); }
7191 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7193 (define_insn "consttable_int"
7194 [(unspec_volatile [(match_operand 0 "consttable_operand" "")
7195 (match_operand 1 "const_int_operand" "")]
7196 UNSPEC_CONSTTABLE_INT)]
7199 assemble_integer (mips_strip_unspec_address (operands[0]),
7200 INTVAL (operands[1]),
7201 BITS_PER_UNIT * INTVAL (operands[1]), 1);
7204 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7206 (define_insn "consttable_float"
7207 [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
7208 UNSPEC_CONSTTABLE_FLOAT)]
7213 gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
7214 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
7215 assemble_real (d, GET_MODE (operands[0]),
7216 GET_MODE_BITSIZE (GET_MODE (operands[0])));
7219 [(set (attr "length")
7220 (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
7222 (define_insn "align"
7223 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
7226 [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
7229 [(match_operand 0 "small_data_pattern")]
7232 { operands[0] = mips_rewrite_small_data (operands[0]); })
7235 ;; ....................
7237 ;; MIPS16e Save/Restore
7239 ;; ....................
7242 (define_insn "*mips16e_save_restore"
7243 [(match_parallel 0 ""
7244 [(set (match_operand:SI 1 "register_operand")
7245 (plus:SI (match_dup 1)
7246 (match_operand:SI 2 "const_int_operand")))])]
7247 "operands[1] == stack_pointer_rtx
7248 && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
7249 { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
7250 [(set_attr "type" "arith")
7251 (set_attr "extended_mips16" "yes")])
7253 ;; Thread-Local Storage
7255 ;; The TLS base pointer is accessed via "rdhwr $3, $29". No current
7256 ;; MIPS architecture defines this register, and no current
7257 ;; implementation provides it; instead, any OS which supports TLS is
7258 ;; expected to trap and emulate this instruction. rdhwr is part of the
7259 ;; MIPS 32r2 specification, but we use it on any architecture because
7260 ;; we expect it to be emulated. Use .set to force the assembler to
7263 ;; We do not use a constraint to force the destination to be $3
7264 ;; because $3 can appear explicitly as a function return value.
7265 ;; If we leave the use of $3 implicit in the constraints until
7266 ;; reload, we may end up making a $3 return value live across
7267 ;; the instruction, leading to a spill failure when reloading it.
7268 (define_insn_and_split "tls_get_tp_<mode>"
7269 [(set (match_operand:P 0 "register_operand" "=d")
7270 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7271 (clobber (reg:P TLS_GET_TP_REGNUM))]
7272 "HAVE_AS_TLS && !TARGET_MIPS16"
7274 "&& reload_completed"
7275 [(set (reg:P TLS_GET_TP_REGNUM)
7276 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7277 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7279 [(set_attr "type" "unknown")
7280 (set_attr "mode" "<MODE>")
7281 (set_attr "insn_count" "2")])
7283 (define_insn "*tls_get_tp_<mode>_split"
7284 [(set (reg:P TLS_GET_TP_REGNUM)
7285 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
7286 "HAVE_AS_TLS && !TARGET_MIPS16"
7288 if (mips_isa_rev >= 2)
7289 return "rdhwr\t$3,$29";
7291 return ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop";
7293 [(set_attr "type" "unknown")
7294 ; Since rdhwr always generates a trap for now, putting it in a delay
7295 ; slot would make the kernel's emulation of it much slower.
7296 (set_attr "can_delay" "no")
7297 (set_attr "mode" "<MODE>")])
7299 ;; In MIPS16 mode, the TLS base pointer is accessed by a
7300 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
7301 ;; accessible in MIPS16.
7303 ;; This is not represented as a call insn, to avoid the
7304 ;; unnecesarry clobbering of caller-save registers by a
7305 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
7307 ;; A $25 clobber is added to cater for a $25 load stub added by the
7308 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
7310 (define_insn_and_split "tls_get_tp_mips16_<mode>"
7311 [(set (match_operand:P 0 "register_operand" "=d")
7312 (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
7314 (clobber (reg:P TLS_GET_TP_REGNUM))
7315 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7316 (clobber (reg:P RETURN_ADDR_REGNUM))]
7317 "HAVE_AS_TLS && TARGET_MIPS16"
7319 "&& reload_completed"
7320 [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
7321 (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
7322 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7323 (clobber (reg:P RETURN_ADDR_REGNUM))])
7324 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7326 [(set_attr "type" "multi")
7327 (set_attr "insn_count" "4")
7328 (set_attr "mode" "<MODE>")])
7330 (define_insn "*tls_get_tp_mips16_call_<mode>"
7331 [(set (reg:P TLS_GET_TP_REGNUM)
7332 (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
7334 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7335 (clobber (reg:P RETURN_ADDR_REGNUM))]
7336 "HAVE_AS_TLS && TARGET_MIPS16"
7337 { return MIPS_CALL ("jal", operands, 0, -1); }
7338 [(set_attr "type" "call")
7339 (set_attr "insn_count" "3")
7340 (set_attr "mode" "<MODE>")])
7342 ;; Named pattern for expanding thread pointer reference.
7343 (define_expand "get_thread_pointer<mode>"
7344 [(match_operand:P 0 "register_operand" "=d")]
7347 mips_expand_thread_pointer (operands[0]);
7351 ;; __builtin_mips_get_fcsr: move the FCSR into operand 0.
7352 (define_expand "mips_get_fcsr"
7353 [(set (match_operand:SI 0 "register_operand")
7354 (unspec_volatile [(const_int 0)] UNSPEC_GET_FCSR))]
7355 "TARGET_HARD_FLOAT_ABI"
7359 mips16_expand_get_fcsr (operands[0]);
7364 (define_insn "*mips_get_fcsr"
7365 [(set (match_operand:SI 0 "register_operand" "=d")
7366 (unspec_volatile [(const_int 0)] UNSPEC_GET_FCSR))]
7370 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7371 (define_insn "mips_get_fcsr_mips16_<mode>"
7372 [(set (reg:SI GET_FCSR_REGNUM)
7373 (unspec:SI [(match_operand:P 0 "call_insn_operand" "dS")]
7375 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7376 (clobber (reg:P RETURN_ADDR_REGNUM))]
7377 "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7378 { return MIPS_CALL ("jal", operands, 0, -1); }
7379 [(set_attr "type" "call")
7380 (set_attr "insn_count" "3")])
7382 ;; __builtin_mips_set_fcsr: move operand 0 into the FCSR.
7383 (define_expand "mips_set_fcsr"
7384 [(unspec_volatile [(match_operand:SI 0 "register_operand")]
7386 "TARGET_HARD_FLOAT_ABI"
7390 mips16_expand_set_fcsr (operands[0]);
7395 (define_insn "*mips_set_fcsr"
7396 [(unspec_volatile [(match_operand:SI 0 "register_operand" "d")]
7401 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7402 (define_insn "mips_set_fcsr_mips16_<mode>"
7403 [(unspec_volatile:SI [(match_operand:P 0 "call_insn_operand" "dS")
7404 (reg:SI SET_FCSR_REGNUM)] UNSPEC_SET_FCSR)
7405 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7406 (clobber (reg:P RETURN_ADDR_REGNUM))]
7407 "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7408 { return MIPS_CALL ("jal", operands, 0, -1); }
7409 [(set_attr "type" "call")
7410 (set_attr "insn_count" "3")])
7412 ;; Synchronization instructions.
7416 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
7418 (include "mips-ps-3d.md")
7420 ; The MIPS DSP Instructions.
7422 (include "mips-dsp.md")
7424 ; The MIPS DSP REV 2 Instructions.
7426 (include "mips-dspr2.md")
7428 ; MIPS fixed-point instructions.
7429 (include "mips-fixed.md")
7431 ; microMIPS patterns.
7432 (include "micromips.md")
7434 ; ST-Microelectronics Loongson-2E/2F-specific patterns.
7435 (include "loongson.md")
7437 (define_c_enum "unspec" [
7438 UNSPEC_ADDRESS_FIRST