1 ;; Mips.md Machine Description for MIPS based processors
2 ;; Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc.
5 ;; Contributed by A. Lichnewsky, lich@inria.inria.fr
6 ;; Changes by Michael Meissner, meissner@osf.org
7 ;; 64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
8 ;; Brendan Eich, brendan@microunity.com.
10 ;; This file is part of GCC.
12 ;; GCC is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GCC is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GCC; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
28 [(UNSPEC_LOAD_DF_LOW 0)
29 (UNSPEC_LOAD_DF_HIGH 1)
30 (UNSPEC_STORE_DF_HIGH 2)
34 (UNSPEC_NONLOCAL_GOTO_RECEIVER 6)
36 (UNSPEC_CONSTTABLE_INT 8)
37 (UNSPEC_CONSTTABLE_FLOAT 9)
41 (UNSPEC_LOAD_RIGHT 19)
42 (UNSPEC_STORE_LEFT 20)
43 (UNSPEC_STORE_RIGHT 21)
50 (UNSPEC_TLS_GET_TP 28)
54 (UNSPEC_ADDRESS_FIRST 100)
58 ;; For MIPS Paired-Singled Floating Point Instructions.
60 (UNSPEC_MOVE_TF_PS 200)
63 ;; MIPS64/MIPS32R2 alnv.ps
66 ;; MIPS-3D instructions
70 (UNSPEC_CVT_PW_PS 205)
71 (UNSPEC_CVT_PS_PW 206)
79 (UNSPEC_SINGLE_CC 213)
82 ;; MIPS DSP ASE Revision 0.98 3/24/2005
90 (UNSPEC_RADDU_W_QB 307)
92 (UNSPEC_PRECRQ_QB_PH 309)
93 (UNSPEC_PRECRQ_PH_W 310)
94 (UNSPEC_PRECRQ_RS_PH_W 311)
95 (UNSPEC_PRECRQU_S_QB_PH 312)
96 (UNSPEC_PRECEQ_W_PHL 313)
97 (UNSPEC_PRECEQ_W_PHR 314)
98 (UNSPEC_PRECEQU_PH_QBL 315)
99 (UNSPEC_PRECEQU_PH_QBR 316)
100 (UNSPEC_PRECEQU_PH_QBLA 317)
101 (UNSPEC_PRECEQU_PH_QBRA 318)
102 (UNSPEC_PRECEU_PH_QBL 319)
103 (UNSPEC_PRECEU_PH_QBR 320)
104 (UNSPEC_PRECEU_PH_QBLA 321)
105 (UNSPEC_PRECEU_PH_QBRA 322)
111 (UNSPEC_MULEU_S_PH_QBL 328)
112 (UNSPEC_MULEU_S_PH_QBR 329)
113 (UNSPEC_MULQ_RS_PH 330)
114 (UNSPEC_MULEQ_S_W_PHL 331)
115 (UNSPEC_MULEQ_S_W_PHR 332)
116 (UNSPEC_DPAU_H_QBL 333)
117 (UNSPEC_DPAU_H_QBR 334)
118 (UNSPEC_DPSU_H_QBL 335)
119 (UNSPEC_DPSU_H_QBR 336)
120 (UNSPEC_DPAQ_S_W_PH 337)
121 (UNSPEC_DPSQ_S_W_PH 338)
122 (UNSPEC_MULSAQ_S_W_PH 339)
123 (UNSPEC_DPAQ_SA_L_W 340)
124 (UNSPEC_DPSQ_SA_L_W 341)
125 (UNSPEC_MAQ_S_W_PHL 342)
126 (UNSPEC_MAQ_S_W_PHR 343)
127 (UNSPEC_MAQ_SA_W_PHL 344)
128 (UNSPEC_MAQ_SA_W_PHR 345)
136 (UNSPEC_CMPGU_EQ_QB 353)
137 (UNSPEC_CMPGU_LT_QB 354)
138 (UNSPEC_CMPGU_LE_QB 355)
140 (UNSPEC_PACKRL_PH 357)
142 (UNSPEC_EXTR_R_W 359)
143 (UNSPEC_EXTR_RS_W 360)
144 (UNSPEC_EXTR_S_H 361)
152 ;; MIPS DSP ASE REV 2 Revision 0.02 11/24/2006
153 (UNSPEC_ABSQ_S_QB 400)
155 (UNSPEC_ADDU_S_PH 402)
156 (UNSPEC_ADDUH_QB 403)
157 (UNSPEC_ADDUH_R_QB 404)
160 (UNSPEC_CMPGDU_EQ_QB 407)
161 (UNSPEC_CMPGDU_LT_QB 408)
162 (UNSPEC_CMPGDU_LE_QB 409)
163 (UNSPEC_DPA_W_PH 410)
164 (UNSPEC_DPS_W_PH 411)
170 (UNSPEC_MUL_S_PH 417)
171 (UNSPEC_MULQ_RS_W 418)
172 (UNSPEC_MULQ_S_PH 419)
173 (UNSPEC_MULQ_S_W 420)
174 (UNSPEC_MULSA_W_PH 421)
177 (UNSPEC_PRECR_QB_PH 424)
178 (UNSPEC_PRECR_SRA_PH_W 425)
179 (UNSPEC_PRECR_SRA_R_PH_W 426)
182 (UNSPEC_SHRA_R_QB 429)
185 (UNSPEC_SUBU_S_PH 432)
186 (UNSPEC_SUBUH_QB 433)
187 (UNSPEC_SUBUH_R_QB 434)
188 (UNSPEC_ADDQH_PH 435)
189 (UNSPEC_ADDQH_R_PH 436)
191 (UNSPEC_ADDQH_R_W 438)
192 (UNSPEC_SUBQH_PH 439)
193 (UNSPEC_SUBQH_R_PH 440)
195 (UNSPEC_SUBQH_R_W 442)
196 (UNSPEC_DPAX_W_PH 443)
197 (UNSPEC_DPSX_W_PH 444)
198 (UNSPEC_DPAQX_S_W_PH 445)
199 (UNSPEC_DPAQX_SA_W_PH 446)
200 (UNSPEC_DPSQX_S_W_PH 447)
201 (UNSPEC_DPSQX_SA_W_PH 448)
205 (include "predicates.md")
206 (include "constraints.md")
208 ;; ....................
212 ;; ....................
214 (define_attr "got" "unset,xgot_high,load"
215 (const_string "unset"))
217 ;; For jal instructions, this attribute is DIRECT when the target address
218 ;; is symbolic and INDIRECT when it is a register.
219 (define_attr "jal" "unset,direct,indirect"
220 (const_string "unset"))
222 ;; This attribute is YES if the instruction is a jal macro (not a
223 ;; real jal instruction).
225 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
226 ;; an instruction to restore $gp. Direct jals are also macros for
227 ;; flag_pic && !TARGET_ABSOLUTE_ABICALLS because they first load
228 ;; the target address into a register.
229 (define_attr "jal_macro" "no,yes"
230 (cond [(eq_attr "jal" "direct")
231 (symbol_ref "TARGET_CALL_CLOBBERED_GP
232 || (flag_pic && !TARGET_ABSOLUTE_ABICALLS)")
233 (eq_attr "jal" "indirect")
234 (symbol_ref "TARGET_CALL_CLOBBERED_GP")]
235 (const_string "no")))
237 ;; Classification of each insn.
238 ;; branch conditional branch
239 ;; jump unconditional jump
240 ;; call unconditional call
241 ;; load load instruction(s)
242 ;; fpload floating point load
243 ;; fpidxload floating point indexed load
244 ;; store store instruction(s)
245 ;; fpstore floating point store
246 ;; fpidxstore floating point indexed store
247 ;; prefetch memory prefetch (register + offset)
248 ;; prefetchx memory indexed prefetch (register + register)
249 ;; condmove conditional moves
250 ;; mfc transfer from coprocessor
251 ;; mtc transfer to coprocessor
252 ;; mthilo transfer to hi/lo registers
253 ;; mfhilo transfer from hi/lo registers
254 ;; const load constant
255 ;; arith integer arithmetic and logical instructions
256 ;; shift integer shift instructions
257 ;; slt set less than instructions
258 ;; clz the clz and clo instructions
259 ;; trap trap if instructions
260 ;; imul integer multiply 2 operands
261 ;; imul3 integer multiply 3 operands
262 ;; imadd integer multiply-add
263 ;; idiv integer divide
264 ;; fmove floating point register move
265 ;; fadd floating point add/subtract
266 ;; fmul floating point multiply
267 ;; fmadd floating point multiply-add
268 ;; fdiv floating point divide
269 ;; frdiv floating point reciprocal divide
270 ;; frdiv1 floating point reciprocal divide step 1
271 ;; frdiv2 floating point reciprocal divide step 2
272 ;; fabs floating point absolute value
273 ;; fneg floating point negation
274 ;; fcmp floating point compare
275 ;; fcvt floating point convert
276 ;; fsqrt floating point square root
277 ;; frsqrt floating point reciprocal square root
278 ;; frsqrt1 floating point reciprocal square root step1
279 ;; frsqrt2 floating point reciprocal square root step2
280 ;; multi multiword sequence (or user asm statements)
283 "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,prefetch,prefetchx,condmove,mfc,mtc,mthilo,mfhilo,const,arith,shift,slt,clz,trap,imul,imul3,imadd,idiv,fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,frsqrt,frsqrt1,frsqrt2,multi,nop"
284 (cond [(eq_attr "jal" "!unset") (const_string "call")
285 (eq_attr "got" "load") (const_string "load")]
286 (const_string "unknown")))
288 ;; Main data type used by the insn
289 (define_attr "mode" "unknown,none,QI,HI,SI,DI,SF,DF,FPSW"
290 (const_string "unknown"))
292 ;; Mode for conversion types (fcvt)
293 ;; I2S integer to float single (SI/DI to SF)
294 ;; I2D integer to float double (SI/DI to DF)
295 ;; S2I float to integer (SF to SI/DI)
296 ;; D2I float to integer (DF to SI/DI)
297 ;; D2S double to float single
298 ;; S2D float single to double
300 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D"
301 (const_string "unknown"))
303 ;; Is this an extended instruction in mips16 mode?
304 (define_attr "extended_mips16" "no,yes"
307 ;; Length of instruction in bytes.
308 (define_attr "length" ""
309 (cond [;; Direct branch instructions have a range of [-0x40000,0x3fffc].
310 ;; If a branch is outside this range, we have a choice of two
311 ;; sequences. For PIC, an out-of-range branch like:
316 ;; becomes the equivalent of:
325 ;; where the load address can be up to three instructions long
328 ;; The non-PIC case is similar except that we use a direct
329 ;; jump instead of an la/jr pair. Since the target of this
330 ;; jump is an absolute 28-bit bit address (the other bits
331 ;; coming from the address of the delay slot) this form cannot
332 ;; cross a 256MB boundary. We could provide the option of
333 ;; using la/jr in this case too, but we do not do so at
336 ;; Note that this value does not account for the delay slot
337 ;; instruction, whose length is added separately. If the RTL
338 ;; pattern has no explicit delay slot, mips_adjust_insn_length
339 ;; will add the length of the implicit nop. The values for
340 ;; forward and backward branches will be different as well.
341 (eq_attr "type" "branch")
342 (cond [(and (le (minus (match_dup 1) (pc)) (const_int 131064))
343 (le (minus (pc) (match_dup 1)) (const_int 131068)))
345 (ne (symbol_ref "flag_pic") (const_int 0))
349 (eq_attr "got" "load")
351 (eq_attr "got" "xgot_high")
354 (eq_attr "type" "const")
355 (symbol_ref "mips_const_insns (operands[1]) * 4")
356 (eq_attr "type" "load,fpload")
357 (symbol_ref "mips_fetch_insns (operands[1]) * 4")
358 (eq_attr "type" "store,fpstore")
359 (symbol_ref "mips_fetch_insns (operands[0]) * 4")
361 ;; In the worst case, a call macro will take 8 instructions:
363 ;; lui $25,%call_hi(FOO)
365 ;; lw $25,%call_lo(FOO)($25)
371 (eq_attr "jal_macro" "yes")
374 (and (eq_attr "extended_mips16" "yes")
375 (ne (symbol_ref "TARGET_MIPS16") (const_int 0)))
378 ;; Various VR4120 errata require a nop to be inserted after a macc
379 ;; instruction. The assembler does this for us, so account for
380 ;; the worst-case length here.
381 (and (eq_attr "type" "imadd")
382 (ne (symbol_ref "TARGET_FIX_VR4120") (const_int 0)))
385 ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
386 ;; the result of the second one is missed. The assembler should work
387 ;; around this by inserting a nop after the first dmult.
388 (and (eq_attr "type" "imul,imul3")
389 (and (eq_attr "mode" "DI")
390 (ne (symbol_ref "TARGET_FIX_VR4120") (const_int 0))))
393 (eq_attr "type" "idiv")
394 (symbol_ref "mips_idiv_insns () * 4")
397 ;; Attribute describing the processor. This attribute must match exactly
398 ;; with the processor_type enumeration in mips.h.
400 "r3000,4kc,4kp,5kc,5kf,20kc,24kc,24kf,24kx,74kc,74kf,74kx,m4k,r3900,r6000,r4000,r4100,r4111,r4120,r4130,r4300,r4600,r4650,r5000,r5400,r5500,r7000,r8000,r9000,sb1,sb1a,sr71000"
401 (const (symbol_ref "mips_tune")))
403 ;; The type of hardware hazard associated with this instruction.
404 ;; DELAY means that the next instruction cannot read the result
405 ;; of this one. HILO means that the next two instructions cannot
406 ;; write to HI or LO.
407 (define_attr "hazard" "none,delay,hilo"
408 (cond [(and (eq_attr "type" "load,fpload,fpidxload")
409 (ne (symbol_ref "ISA_HAS_LOAD_DELAY") (const_int 0)))
410 (const_string "delay")
412 (and (eq_attr "type" "mfc,mtc")
413 (ne (symbol_ref "ISA_HAS_XFER_DELAY") (const_int 0)))
414 (const_string "delay")
416 (and (eq_attr "type" "fcmp")
417 (ne (symbol_ref "ISA_HAS_FCMP_DELAY") (const_int 0)))
418 (const_string "delay")
420 ;; The r4000 multiplication patterns include an mflo instruction.
421 (and (eq_attr "type" "imul")
422 (ne (symbol_ref "TARGET_FIX_R4000") (const_int 0)))
423 (const_string "hilo")
425 (and (eq_attr "type" "mfhilo")
426 (eq (symbol_ref "ISA_HAS_HILO_INTERLOCKS") (const_int 0)))
427 (const_string "hilo")]
428 (const_string "none")))
430 ;; Is it a single instruction?
431 (define_attr "single_insn" "no,yes"
432 (symbol_ref "get_attr_length (insn) == (TARGET_MIPS16 ? 2 : 4)"))
434 ;; Can the instruction be put into a delay slot?
435 (define_attr "can_delay" "no,yes"
436 (if_then_else (and (eq_attr "type" "!branch,call,jump")
437 (and (eq_attr "hazard" "none")
438 (eq_attr "single_insn" "yes")))
440 (const_string "no")))
442 ;; Attribute defining whether or not we can use the branch-likely instructions
443 (define_attr "branch_likely" "no,yes"
445 (if_then_else (ne (symbol_ref "GENERATE_BRANCHLIKELY") (const_int 0))
447 (const_string "no"))))
449 ;; True if an instruction might assign to hi or lo when reloaded.
450 ;; This is used by the TUNE_MACC_CHAINS code.
451 (define_attr "may_clobber_hilo" "no,yes"
452 (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthilo")
454 (const_string "no")))
456 ;; Describe a user's asm statement.
457 (define_asm_attributes
458 [(set_attr "type" "multi")
459 (set_attr "can_delay" "no")])
461 ;; This mode macro allows 32-bit and 64-bit GPR patterns to be generated
462 ;; from the same template.
463 (define_mode_macro GPR [SI (DI "TARGET_64BIT")])
465 ;; This mode macro allows :P to be used for patterns that operate on
466 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
467 (define_mode_macro P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
469 ;; This mode macro allows :MOVECC to be used anywhere that a
470 ;; conditional-move-type condition is needed.
471 (define_mode_macro MOVECC [SI (DI "TARGET_64BIT") (CC "TARGET_HARD_FLOAT")])
473 ;; This mode macro allows the QI and HI extension patterns to be defined from
474 ;; the same template.
475 (define_mode_macro SHORT [QI HI])
477 ;; This mode macro allows :ANYF to be used wherever a scalar or vector
478 ;; floating-point mode is allowed.
479 (define_mode_macro ANYF [(SF "TARGET_HARD_FLOAT")
480 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
481 (V2SF "TARGET_PAIRED_SINGLE_FLOAT")])
483 ;; Like ANYF, but only applies to scalar modes.
484 (define_mode_macro SCALARF [(SF "TARGET_HARD_FLOAT")
485 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
487 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
488 ;; 32-bit version and "dsubu" in the 64-bit version.
489 (define_mode_attr d [(SI "") (DI "d")])
491 ;; This attribute gives the length suffix for a sign- or zero-extension
493 (define_mode_attr size [(QI "b") (HI "h")])
495 ;; This attributes gives the mode mask of a SHORT.
496 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
498 ;; Mode attributes for GPR loads and stores.
499 (define_mode_attr load [(SI "lw") (DI "ld")])
500 (define_mode_attr store [(SI "sw") (DI "sd")])
502 ;; Similarly for MIPS IV indexed FPR loads and stores.
503 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
504 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
506 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
507 ;; are different. Some forms of unextended addiu have an 8-bit immediate
508 ;; field but the equivalent daddiu has only a 5-bit field.
509 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
511 ;; This attribute gives the best constraint to use for registers of
513 (define_mode_attr reg [(SI "d") (DI "d") (CC "z")])
515 ;; This attribute gives the format suffix for floating-point operations.
516 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
518 ;; This attribute gives the upper-case mode name for one unit of a
519 ;; floating-point mode.
520 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
522 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
524 ;; In certain cases, div.s and div.ps may have a rounding error
525 ;; and/or wrong inexact flag.
527 ;; Therefore, we only allow div.s if not working around SB-1 rev2
528 ;; errata or if a slight loss of precision is OK.
529 (define_mode_attr divide_condition
530 [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
531 (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
533 ; This attribute gives the condition for which sqrt instructions exist.
534 (define_mode_attr sqrt_condition
535 [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
537 ; This attribute gives the condition for which recip and rsqrt instructions
539 (define_mode_attr recip_condition
540 [(SF "ISA_HAS_FP4") (DF "ISA_HAS_FP4") (V2SF "TARGET_SB1")])
542 ;; This code macro allows all branch instructions to be generated from
543 ;; a single define_expand template.
544 (define_code_macro any_cond [unordered ordered unlt unge uneq ltgt unle ungt
545 eq ne gt ge lt le gtu geu ltu leu])
547 ;; This code macro allows signed and unsigned widening multiplications
548 ;; to use the same template.
549 (define_code_macro any_extend [sign_extend zero_extend])
551 ;; This code macro allows the three shift instructions to be generated
552 ;; from the same template.
553 (define_code_macro any_shift [ashift ashiftrt lshiftrt])
555 ;; This code macro allows all native floating-point comparisons to be
556 ;; generated from the same template.
557 (define_code_macro fcond [unordered uneq unlt unle eq lt le])
559 ;; This code macro is used for comparisons that can be implemented
560 ;; by swapping the operands.
561 (define_code_macro swapped_fcond [ge gt unge ungt])
563 ;; <u> expands to an empty string when doing a signed operation and
564 ;; "u" when doing an unsigned operation.
565 (define_code_attr u [(sign_extend "") (zero_extend "u")])
567 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
568 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
570 ;; <optab> expands to the name of the optab for a particular code.
571 (define_code_attr optab [(ashift "ashl")
575 ;; <insn> expands to the name of the insn that implements a particular code.
576 (define_code_attr insn [(ashift "sll")
580 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
581 (define_code_attr fcond [(unordered "un")
589 ;; Similar, but for swapped conditions.
590 (define_code_attr swapped_fcond [(ge "le")
595 ;; .........................
597 ;; Branch, call and jump delay slots
599 ;; .........................
601 (define_delay (and (eq_attr "type" "branch")
602 (eq (symbol_ref "TARGET_MIPS16") (const_int 0)))
603 [(eq_attr "can_delay" "yes")
605 (and (eq_attr "branch_likely" "yes")
606 (eq_attr "can_delay" "yes"))])
608 (define_delay (eq_attr "type" "jump")
609 [(eq_attr "can_delay" "yes")
613 (define_delay (and (eq_attr "type" "call")
614 (eq_attr "jal_macro" "no"))
615 [(eq_attr "can_delay" "yes")
619 ;; Pipeline descriptions.
621 ;; generic.md provides a fallback for processors without a specific
622 ;; pipeline description. It is derived from the old define_function_unit
623 ;; version and uses the "alu" and "imuldiv" units declared below.
625 ;; Some of the processor-specific files are also derived from old
626 ;; define_function_unit descriptions and simply override the parts of
627 ;; generic.md that don't apply. The other processor-specific files
628 ;; are self-contained.
629 (define_automaton "alu,imuldiv")
631 (define_cpu_unit "alu" "alu")
632 (define_cpu_unit "imuldiv" "imuldiv")
652 (include "generic.md")
655 ;; ....................
659 ;; ....................
663 [(trap_if (const_int 1) (const_int 0))]
666 if (ISA_HAS_COND_TRAP)
668 else if (TARGET_MIPS16)
673 [(set_attr "type" "trap")])
675 (define_expand "conditional_trap"
676 [(trap_if (match_operator 0 "comparison_operator"
677 [(match_dup 2) (match_dup 3)])
678 (match_operand 1 "const_int_operand"))]
681 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) == MODE_INT
682 && operands[1] == const0_rtx)
684 mips_gen_conditional_trap (operands);
691 (define_insn "*conditional_trap<mode>"
692 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
693 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
694 (match_operand:GPR 2 "arith_operand" "dI")])
698 [(set_attr "type" "trap")])
701 ;; ....................
705 ;; ....................
708 (define_insn "add<mode>3"
709 [(set (match_operand:ANYF 0 "register_operand" "=f")
710 (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
711 (match_operand:ANYF 2 "register_operand" "f")))]
713 "add.<fmt>\t%0,%1,%2"
714 [(set_attr "type" "fadd")
715 (set_attr "mode" "<UNITMODE>")])
717 (define_expand "add<mode>3"
718 [(set (match_operand:GPR 0 "register_operand")
719 (plus:GPR (match_operand:GPR 1 "register_operand")
720 (match_operand:GPR 2 "arith_operand")))]
723 (define_insn "*add<mode>3"
724 [(set (match_operand:GPR 0 "register_operand" "=d,d")
725 (plus:GPR (match_operand:GPR 1 "register_operand" "d,d")
726 (match_operand:GPR 2 "arith_operand" "d,Q")))]
731 [(set_attr "type" "arith")
732 (set_attr "mode" "<MODE>")])
734 ;; We need to recognize MIPS16 stack pointer additions explicitly, since
735 ;; we don't have a constraint for $sp. These insns will be generated by
736 ;; the save_restore_insns functions.
738 (define_insn "*add<mode>3_sp1"
740 (plus:GPR (reg:GPR 29)
741 (match_operand:GPR 0 "const_arith_operand" "")))]
744 [(set_attr "type" "arith")
745 (set_attr "mode" "<MODE>")
746 (set (attr "length") (if_then_else (match_operand 0 "m16_simm8_8")
750 (define_insn "*add<mode>3_sp2"
751 [(set (match_operand:GPR 0 "register_operand" "=d")
752 (plus:GPR (reg:GPR 29)
753 (match_operand:GPR 1 "const_arith_operand" "")))]
756 [(set_attr "type" "arith")
757 (set_attr "mode" "<MODE>")
758 (set (attr "length") (if_then_else (match_operand 1 "m16_uimm<si8_di5>_4")
762 (define_insn "*add<mode>3_mips16"
763 [(set (match_operand:GPR 0 "register_operand" "=d,d,d")
764 (plus:GPR (match_operand:GPR 1 "register_operand" "0,d,d")
765 (match_operand:GPR 2 "arith_operand" "Q,O,d")))]
771 [(set_attr "type" "arith")
772 (set_attr "mode" "<MODE>")
773 (set_attr_alternative "length"
774 [(if_then_else (match_operand 2 "m16_simm<si8_di5>_1")
777 (if_then_else (match_operand 2 "m16_simm4_1")
783 ;; On the mips16, we can sometimes split an add of a constant which is
784 ;; a 4 byte instruction into two adds which are both 2 byte
785 ;; instructions. There are two cases: one where we are adding a
786 ;; constant plus a register to another register, and one where we are
787 ;; simply adding a constant to a register.
790 [(set (match_operand:SI 0 "register_operand")
791 (plus:SI (match_dup 0)
792 (match_operand:SI 1 "const_int_operand")))]
793 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
794 && REG_P (operands[0])
795 && M16_REG_P (REGNO (operands[0]))
796 && GET_CODE (operands[1]) == CONST_INT
797 && ((INTVAL (operands[1]) > 0x7f
798 && INTVAL (operands[1]) <= 0x7f + 0x7f)
799 || (INTVAL (operands[1]) < - 0x80
800 && INTVAL (operands[1]) >= - 0x80 - 0x80))"
801 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
802 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
804 HOST_WIDE_INT val = INTVAL (operands[1]);
808 operands[1] = GEN_INT (0x7f);
809 operands[2] = GEN_INT (val - 0x7f);
813 operands[1] = GEN_INT (- 0x80);
814 operands[2] = GEN_INT (val + 0x80);
819 [(set (match_operand:SI 0 "register_operand")
820 (plus:SI (match_operand:SI 1 "register_operand")
821 (match_operand:SI 2 "const_int_operand")))]
822 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
823 && REG_P (operands[0])
824 && M16_REG_P (REGNO (operands[0]))
825 && REG_P (operands[1])
826 && M16_REG_P (REGNO (operands[1]))
827 && REGNO (operands[0]) != REGNO (operands[1])
828 && GET_CODE (operands[2]) == CONST_INT
829 && ((INTVAL (operands[2]) > 0x7
830 && INTVAL (operands[2]) <= 0x7 + 0x7f)
831 || (INTVAL (operands[2]) < - 0x8
832 && INTVAL (operands[2]) >= - 0x8 - 0x80))"
833 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
834 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
836 HOST_WIDE_INT val = INTVAL (operands[2]);
840 operands[2] = GEN_INT (0x7);
841 operands[3] = GEN_INT (val - 0x7);
845 operands[2] = GEN_INT (- 0x8);
846 operands[3] = GEN_INT (val + 0x8);
851 [(set (match_operand:DI 0 "register_operand")
852 (plus:DI (match_dup 0)
853 (match_operand:DI 1 "const_int_operand")))]
854 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
855 && REG_P (operands[0])
856 && M16_REG_P (REGNO (operands[0]))
857 && GET_CODE (operands[1]) == CONST_INT
858 && ((INTVAL (operands[1]) > 0xf
859 && INTVAL (operands[1]) <= 0xf + 0xf)
860 || (INTVAL (operands[1]) < - 0x10
861 && INTVAL (operands[1]) >= - 0x10 - 0x10))"
862 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
863 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
865 HOST_WIDE_INT val = INTVAL (operands[1]);
869 operands[1] = GEN_INT (0xf);
870 operands[2] = GEN_INT (val - 0xf);
874 operands[1] = GEN_INT (- 0x10);
875 operands[2] = GEN_INT (val + 0x10);
880 [(set (match_operand:DI 0 "register_operand")
881 (plus:DI (match_operand:DI 1 "register_operand")
882 (match_operand:DI 2 "const_int_operand")))]
883 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
884 && REG_P (operands[0])
885 && M16_REG_P (REGNO (operands[0]))
886 && REG_P (operands[1])
887 && M16_REG_P (REGNO (operands[1]))
888 && REGNO (operands[0]) != REGNO (operands[1])
889 && GET_CODE (operands[2]) == CONST_INT
890 && ((INTVAL (operands[2]) > 0x7
891 && INTVAL (operands[2]) <= 0x7 + 0xf)
892 || (INTVAL (operands[2]) < - 0x8
893 && INTVAL (operands[2]) >= - 0x8 - 0x10))"
894 [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
895 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
897 HOST_WIDE_INT val = INTVAL (operands[2]);
901 operands[2] = GEN_INT (0x7);
902 operands[3] = GEN_INT (val - 0x7);
906 operands[2] = GEN_INT (- 0x8);
907 operands[3] = GEN_INT (val + 0x8);
911 (define_insn "*addsi3_extended"
912 [(set (match_operand:DI 0 "register_operand" "=d,d")
914 (plus:SI (match_operand:SI 1 "register_operand" "d,d")
915 (match_operand:SI 2 "arith_operand" "d,Q"))))]
916 "TARGET_64BIT && !TARGET_MIPS16"
920 [(set_attr "type" "arith")
921 (set_attr "mode" "SI")])
923 ;; Split this insn so that the addiu splitters can have a crack at it.
924 ;; Use a conservative length estimate until the split.
925 (define_insn_and_split "*addsi3_extended_mips16"
926 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
928 (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
929 (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
930 "TARGET_64BIT && TARGET_MIPS16"
932 "&& reload_completed"
933 [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
934 { operands[3] = gen_lowpart (SImode, operands[0]); }
935 [(set_attr "type" "arith")
936 (set_attr "mode" "SI")
937 (set_attr "extended_mips16" "yes")])
940 ;; ....................
944 ;; ....................
947 (define_insn "sub<mode>3"
948 [(set (match_operand:ANYF 0 "register_operand" "=f")
949 (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
950 (match_operand:ANYF 2 "register_operand" "f")))]
952 "sub.<fmt>\t%0,%1,%2"
953 [(set_attr "type" "fadd")
954 (set_attr "mode" "<UNITMODE>")])
956 (define_insn "sub<mode>3"
957 [(set (match_operand:GPR 0 "register_operand" "=d")
958 (minus:GPR (match_operand:GPR 1 "register_operand" "d")
959 (match_operand:GPR 2 "register_operand" "d")))]
962 [(set_attr "type" "arith")
963 (set_attr "mode" "<MODE>")])
965 (define_insn "*subsi3_extended"
966 [(set (match_operand:DI 0 "register_operand" "=d")
968 (minus:SI (match_operand:SI 1 "register_operand" "d")
969 (match_operand:SI 2 "register_operand" "d"))))]
972 [(set_attr "type" "arith")
973 (set_attr "mode" "DI")])
976 ;; ....................
980 ;; ....................
983 (define_expand "mul<mode>3"
984 [(set (match_operand:SCALARF 0 "register_operand")
985 (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
986 (match_operand:SCALARF 2 "register_operand")))]
990 (define_insn "*mul<mode>3"
991 [(set (match_operand:SCALARF 0 "register_operand" "=f")
992 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
993 (match_operand:SCALARF 2 "register_operand" "f")))]
994 "!TARGET_4300_MUL_FIX"
995 "mul.<fmt>\t%0,%1,%2"
996 [(set_attr "type" "fmul")
997 (set_attr "mode" "<MODE>")])
999 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1000 ;; operands may corrupt immediately following multiplies. This is a
1001 ;; simple fix to insert NOPs.
1003 (define_insn "*mul<mode>3_r4300"
1004 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1005 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1006 (match_operand:SCALARF 2 "register_operand" "f")))]
1007 "TARGET_4300_MUL_FIX"
1008 "mul.<fmt>\t%0,%1,%2\;nop"
1009 [(set_attr "type" "fmul")
1010 (set_attr "mode" "<MODE>")
1011 (set_attr "length" "8")])
1013 (define_insn "mulv2sf3"
1014 [(set (match_operand:V2SF 0 "register_operand" "=f")
1015 (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1016 (match_operand:V2SF 2 "register_operand" "f")))]
1017 "TARGET_PAIRED_SINGLE_FLOAT"
1019 [(set_attr "type" "fmul")
1020 (set_attr "mode" "SF")])
1022 ;; The original R4000 has a cpu bug. If a double-word or a variable
1023 ;; shift executes while an integer multiplication is in progress, the
1024 ;; shift may give an incorrect result. Avoid this by keeping the mflo
1025 ;; with the mult on the R4000.
1027 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1028 ;; (also valid for MIPS R4000MC processors):
1030 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1031 ;; this errata description.
1032 ;; The following code sequence causes the R4000 to incorrectly
1033 ;; execute the Double Shift Right Arithmetic 32 (dsra32)
1034 ;; instruction. If the dsra32 instruction is executed during an
1035 ;; integer multiply, the dsra32 will only shift by the amount in
1036 ;; specified in the instruction rather than the amount plus 32
1038 ;; instruction 1: mult rs,rt integer multiply
1039 ;; instruction 2-12: dsra32 rd,rt,rs doubleword shift
1040 ;; right arithmetic + 32
1041 ;; Workaround: A dsra32 instruction placed after an integer
1042 ;; multiply should not be one of the 11 instructions after the
1043 ;; multiply instruction."
1047 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1048 ;; the following description.
1049 ;; All extended shifts (shift by n+32) and variable shifts (32 and
1050 ;; 64-bit versions) may produce incorrect results under the
1051 ;; following conditions:
1052 ;; 1) An integer multiply is currently executing
1053 ;; 2) These types of shift instructions are executed immediately
1054 ;; following an integer divide instruction.
1056 ;; 1) Make sure no integer multiply is running wihen these
1057 ;; instruction are executed. If this cannot be predicted at
1058 ;; compile time, then insert a "mfhi" to R0 instruction
1059 ;; immediately after the integer multiply instruction. This
1060 ;; will cause the integer multiply to complete before the shift
1062 ;; 2) Separate integer divide and these two classes of shift
1063 ;; instructions by another instruction or a noop."
1065 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1068 (define_expand "mulsi3"
1069 [(set (match_operand:SI 0 "register_operand")
1070 (mult:SI (match_operand:SI 1 "register_operand")
1071 (match_operand:SI 2 "register_operand")))]
1075 emit_insn (gen_mulsi3_mult3 (operands[0], operands[1], operands[2]));
1076 else if (TARGET_FIX_R4000)
1077 emit_insn (gen_mulsi3_r4000 (operands[0], operands[1], operands[2]));
1079 emit_insn (gen_mulsi3_internal (operands[0], operands[1], operands[2]));
1083 (define_expand "muldi3"
1084 [(set (match_operand:DI 0 "register_operand")
1085 (mult:DI (match_operand:DI 1 "register_operand")
1086 (match_operand:DI 2 "register_operand")))]
1089 if (TARGET_FIX_R4000)
1090 emit_insn (gen_muldi3_r4000 (operands[0], operands[1], operands[2]));
1092 emit_insn (gen_muldi3_internal (operands[0], operands[1], operands[2]));
1096 (define_insn "mulsi3_mult3"
1097 [(set (match_operand:SI 0 "register_operand" "=d,l")
1098 (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1099 (match_operand:SI 2 "register_operand" "d,d")))
1100 (clobber (match_scratch:SI 3 "=h,h"))
1101 (clobber (match_scratch:SI 4 "=l,X"))]
1104 if (which_alternative == 1)
1105 return "mult\t%1,%2";
1106 if (TARGET_MIPS3900)
1107 return "mult\t%0,%1,%2";
1108 return "mul\t%0,%1,%2";
1110 [(set_attr "type" "imul3,imul")
1111 (set_attr "mode" "SI")])
1113 ;; If a register gets allocated to LO, and we spill to memory, the reload
1114 ;; will include a move from LO to a GPR. Merge it into the multiplication
1115 ;; if it can set the GPR directly.
1118 ;; Operand 1: GPR (1st multiplication operand)
1119 ;; Operand 2: GPR (2nd multiplication operand)
1121 ;; Operand 4: GPR (destination)
1124 [(set (match_operand:SI 0 "register_operand")
1125 (mult:SI (match_operand:SI 1 "register_operand")
1126 (match_operand:SI 2 "register_operand")))
1127 (clobber (match_operand:SI 3 "register_operand"))
1128 (clobber (scratch:SI))])
1129 (set (match_operand:SI 4 "register_operand")
1130 (unspec [(match_dup 0) (match_dup 3)] UNSPEC_MFHILO))]
1131 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1134 (mult:SI (match_dup 1)
1136 (clobber (match_dup 3))
1137 (clobber (match_dup 0))])])
1139 (define_insn "mul<mode>3_internal"
1140 [(set (match_operand:GPR 0 "register_operand" "=l")
1141 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1142 (match_operand:GPR 2 "register_operand" "d")))
1143 (clobber (match_scratch:GPR 3 "=h"))]
1146 [(set_attr "type" "imul")
1147 (set_attr "mode" "<MODE>")])
1149 (define_insn "mul<mode>3_r4000"
1150 [(set (match_operand:GPR 0 "register_operand" "=d")
1151 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1152 (match_operand:GPR 2 "register_operand" "d")))
1153 (clobber (match_scratch:GPR 3 "=h"))
1154 (clobber (match_scratch:GPR 4 "=l"))]
1156 "<d>mult\t%1,%2\;mflo\t%0"
1157 [(set_attr "type" "imul")
1158 (set_attr "mode" "<MODE>")
1159 (set_attr "length" "8")])
1161 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1162 ;; of "mult; mflo". They have the same latency, but the first form gives
1163 ;; us an extra cycle to compute the operands.
1166 ;; Operand 1: GPR (1st multiplication operand)
1167 ;; Operand 2: GPR (2nd multiplication operand)
1169 ;; Operand 4: GPR (destination)
1172 [(set (match_operand:SI 0 "register_operand")
1173 (mult:SI (match_operand:SI 1 "register_operand")
1174 (match_operand:SI 2 "register_operand")))
1175 (clobber (match_operand:SI 3 "register_operand"))])
1176 (set (match_operand:SI 4 "register_operand")
1177 (unspec:SI [(match_dup 0) (match_dup 3)] UNSPEC_MFHILO))]
1178 "ISA_HAS_MACC && !ISA_HAS_MUL3"
1183 (plus:SI (mult:SI (match_dup 1)
1187 (plus:SI (mult:SI (match_dup 1)
1190 (clobber (match_dup 3))])])
1192 ;; Multiply-accumulate patterns
1194 ;; For processors that can copy the output to a general register:
1196 ;; The all-d alternative is needed because the combiner will find this
1197 ;; pattern and then register alloc/reload will move registers around to
1198 ;; make them fit, and we don't want to trigger unnecessary loads to LO.
1200 ;; The last alternative should be made slightly less desirable, but adding
1201 ;; "?" to the constraint is too strong, and causes values to be loaded into
1202 ;; LO even when that's more costly. For now, using "*d" mostly does the
1204 (define_insn "*mul_acc_si"
1205 [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
1206 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1207 (match_operand:SI 2 "register_operand" "d,d,d"))
1208 (match_operand:SI 3 "register_operand" "0,l,*d")))
1209 (clobber (match_scratch:SI 4 "=h,h,h"))
1210 (clobber (match_scratch:SI 5 "=X,3,l"))
1211 (clobber (match_scratch:SI 6 "=X,X,&d"))]
1213 || GENERATE_MADD_MSUB)
1216 static const char *const madd[] = { "madd\t%1,%2", "madd\t%0,%1,%2" };
1217 if (which_alternative == 2)
1219 if (GENERATE_MADD_MSUB && which_alternative != 0)
1221 return madd[which_alternative];
1223 [(set_attr "type" "imadd,imadd,multi")
1224 (set_attr "mode" "SI")
1225 (set_attr "length" "4,4,8")])
1227 ;; Split the above insn if we failed to get LO allocated.
1229 [(set (match_operand:SI 0 "register_operand")
1230 (plus:SI (mult:SI (match_operand:SI 1 "register_operand")
1231 (match_operand:SI 2 "register_operand"))
1232 (match_operand:SI 3 "register_operand")))
1233 (clobber (match_scratch:SI 4))
1234 (clobber (match_scratch:SI 5))
1235 (clobber (match_scratch:SI 6))]
1236 "reload_completed && !TARGET_DEBUG_D_MODE
1237 && GP_REG_P (true_regnum (operands[0]))
1238 && GP_REG_P (true_regnum (operands[3]))"
1239 [(parallel [(set (match_dup 6)
1240 (mult:SI (match_dup 1) (match_dup 2)))
1241 (clobber (match_dup 4))
1242 (clobber (match_dup 5))])
1243 (set (match_dup 0) (plus:SI (match_dup 6) (match_dup 3)))]
1246 ;; Splitter to copy result of MADD to a general register
1248 [(set (match_operand:SI 0 "register_operand")
1249 (plus:SI (mult:SI (match_operand:SI 1 "register_operand")
1250 (match_operand:SI 2 "register_operand"))
1251 (match_operand:SI 3 "register_operand")))
1252 (clobber (match_scratch:SI 4))
1253 (clobber (match_scratch:SI 5))
1254 (clobber (match_scratch:SI 6))]
1255 "reload_completed && !TARGET_DEBUG_D_MODE
1256 && GP_REG_P (true_regnum (operands[0]))
1257 && true_regnum (operands[3]) == LO_REGNUM"
1258 [(parallel [(set (match_dup 3)
1259 (plus:SI (mult:SI (match_dup 1) (match_dup 2))
1261 (clobber (match_dup 4))
1262 (clobber (match_dup 5))
1263 (clobber (match_dup 6))])
1264 (set (match_dup 0) (unspec:SI [(match_dup 5) (match_dup 4)] UNSPEC_MFHILO))]
1267 (define_insn "*macc"
1268 [(set (match_operand:SI 0 "register_operand" "=l,d")
1269 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1270 (match_operand:SI 2 "register_operand" "d,d"))
1271 (match_operand:SI 3 "register_operand" "0,l")))
1272 (clobber (match_scratch:SI 4 "=h,h"))
1273 (clobber (match_scratch:SI 5 "=X,3"))]
1276 if (which_alternative == 1)
1277 return "macc\t%0,%1,%2";
1278 else if (TARGET_MIPS5500)
1279 return "madd\t%1,%2";
1281 /* The VR4130 assumes that there is a two-cycle latency between a macc
1282 that "writes" to $0 and an instruction that reads from it. We avoid
1283 this by assigning to $1 instead. */
1284 return "%[macc\t%@,%1,%2%]";
1286 [(set_attr "type" "imadd")
1287 (set_attr "mode" "SI")])
1289 (define_insn "*msac"
1290 [(set (match_operand:SI 0 "register_operand" "=l,d")
1291 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1292 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1293 (match_operand:SI 3 "register_operand" "d,d"))))
1294 (clobber (match_scratch:SI 4 "=h,h"))
1295 (clobber (match_scratch:SI 5 "=X,1"))]
1298 if (which_alternative == 1)
1299 return "msac\t%0,%2,%3";
1300 else if (TARGET_MIPS5500)
1301 return "msub\t%2,%3";
1303 return "msac\t$0,%2,%3";
1305 [(set_attr "type" "imadd")
1306 (set_attr "mode" "SI")])
1308 ;; An msac-like instruction implemented using negation and a macc.
1309 (define_insn_and_split "*msac_using_macc"
1310 [(set (match_operand:SI 0 "register_operand" "=l,d")
1311 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1312 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1313 (match_operand:SI 3 "register_operand" "d,d"))))
1314 (clobber (match_scratch:SI 4 "=h,h"))
1315 (clobber (match_scratch:SI 5 "=X,1"))
1316 (clobber (match_scratch:SI 6 "=d,d"))]
1317 "ISA_HAS_MACC && !ISA_HAS_MSAC"
1319 "&& reload_completed"
1321 (neg:SI (match_dup 3)))
1324 (plus:SI (mult:SI (match_dup 2)
1327 (clobber (match_dup 4))
1328 (clobber (match_dup 5))])]
1330 [(set_attr "type" "imadd")
1331 (set_attr "length" "8")])
1333 ;; Patterns generated by the define_peephole2 below.
1335 (define_insn "*macc2"
1336 [(set (match_operand:SI 0 "register_operand" "=l")
1337 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1338 (match_operand:SI 2 "register_operand" "d"))
1340 (set (match_operand:SI 3 "register_operand" "=d")
1341 (plus:SI (mult:SI (match_dup 1)
1344 (clobber (match_scratch:SI 4 "=h"))]
1345 "ISA_HAS_MACC && reload_completed"
1347 [(set_attr "type" "imadd")
1348 (set_attr "mode" "SI")])
1350 (define_insn "*msac2"
1351 [(set (match_operand:SI 0 "register_operand" "=l")
1352 (minus:SI (match_dup 0)
1353 (mult:SI (match_operand:SI 1 "register_operand" "d")
1354 (match_operand:SI 2 "register_operand" "d"))))
1355 (set (match_operand:SI 3 "register_operand" "=d")
1356 (minus:SI (match_dup 0)
1357 (mult:SI (match_dup 1)
1359 (clobber (match_scratch:SI 4 "=h"))]
1360 "ISA_HAS_MSAC && reload_completed"
1362 [(set_attr "type" "imadd")
1363 (set_attr "mode" "SI")])
1365 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1369 ;; Operand 1: macc/msac
1371 ;; Operand 3: GPR (destination)
1374 [(set (match_operand:SI 0 "register_operand")
1375 (match_operand:SI 1 "macc_msac_operand"))
1376 (clobber (match_operand:SI 2 "register_operand"))
1377 (clobber (scratch:SI))])
1378 (set (match_operand:SI 3 "register_operand")
1379 (unspec:SI [(match_dup 0) (match_dup 2)] UNSPEC_MFHILO))]
1381 [(parallel [(set (match_dup 0)
1385 (clobber (match_dup 2))])]
1388 ;; When we have a three-address multiplication instruction, it should
1389 ;; be faster to do a separate multiply and add, rather than moving
1390 ;; something into LO in order to use a macc instruction.
1392 ;; This peephole needs a scratch register to cater for the case when one
1393 ;; of the multiplication operands is the same as the destination.
1395 ;; Operand 0: GPR (scratch)
1397 ;; Operand 2: GPR (addend)
1398 ;; Operand 3: GPR (destination)
1399 ;; Operand 4: macc/msac
1401 ;; Operand 6: new multiplication
1402 ;; Operand 7: new addition/subtraction
1404 [(match_scratch:SI 0 "d")
1405 (set (match_operand:SI 1 "register_operand")
1406 (match_operand:SI 2 "register_operand"))
1409 [(set (match_operand:SI 3 "register_operand")
1410 (match_operand:SI 4 "macc_msac_operand"))
1411 (clobber (match_operand:SI 5 "register_operand"))
1412 (clobber (match_dup 1))])]
1414 && true_regnum (operands[1]) == LO_REGNUM
1415 && peep2_reg_dead_p (2, operands[1])
1416 && GP_REG_P (true_regnum (operands[3]))"
1417 [(parallel [(set (match_dup 0)
1419 (clobber (match_dup 5))
1420 (clobber (match_dup 1))])
1424 operands[6] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1425 operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1426 operands[2], operands[0]);
1429 ;; Same as above, except LO is the initial target of the macc.
1431 ;; Operand 0: GPR (scratch)
1433 ;; Operand 2: GPR (addend)
1434 ;; Operand 3: macc/msac
1436 ;; Operand 5: GPR (destination)
1437 ;; Operand 6: new multiplication
1438 ;; Operand 7: new addition/subtraction
1440 [(match_scratch:SI 0 "d")
1441 (set (match_operand:SI 1 "register_operand")
1442 (match_operand:SI 2 "register_operand"))
1446 (match_operand:SI 3 "macc_msac_operand"))
1447 (clobber (match_operand:SI 4 "register_operand"))
1448 (clobber (scratch:SI))])
1450 (set (match_operand:SI 5 "register_operand")
1451 (unspec:SI [(match_dup 1) (match_dup 4)] UNSPEC_MFHILO))]
1452 "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1453 [(parallel [(set (match_dup 0)
1455 (clobber (match_dup 4))
1456 (clobber (match_dup 1))])
1460 operands[6] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1461 operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1462 operands[2], operands[0]);
1465 (define_insn "*mul_sub_si"
1466 [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
1467 (minus:SI (match_operand:SI 1 "register_operand" "0,l,*d")
1468 (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
1469 (match_operand:SI 3 "register_operand" "d,d,d"))))
1470 (clobber (match_scratch:SI 4 "=h,h,h"))
1471 (clobber (match_scratch:SI 5 "=X,1,l"))
1472 (clobber (match_scratch:SI 6 "=X,X,&d"))]
1473 "GENERATE_MADD_MSUB"
1478 [(set_attr "type" "imadd,multi,multi")
1479 (set_attr "mode" "SI")
1480 (set_attr "length" "4,8,8")])
1482 ;; Split the above insn if we failed to get LO allocated.
1484 [(set (match_operand:SI 0 "register_operand")
1485 (minus:SI (match_operand:SI 1 "register_operand")
1486 (mult:SI (match_operand:SI 2 "register_operand")
1487 (match_operand:SI 3 "register_operand"))))
1488 (clobber (match_scratch:SI 4))
1489 (clobber (match_scratch:SI 5))
1490 (clobber (match_scratch:SI 6))]
1491 "reload_completed && !TARGET_DEBUG_D_MODE
1492 && GP_REG_P (true_regnum (operands[0]))
1493 && GP_REG_P (true_regnum (operands[1]))"
1494 [(parallel [(set (match_dup 6)
1495 (mult:SI (match_dup 2) (match_dup 3)))
1496 (clobber (match_dup 4))
1497 (clobber (match_dup 5))])
1498 (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 6)))]
1501 ;; Splitter to copy result of MSUB to a general register
1503 [(set (match_operand:SI 0 "register_operand")
1504 (minus:SI (match_operand:SI 1 "register_operand")
1505 (mult:SI (match_operand:SI 2 "register_operand")
1506 (match_operand:SI 3 "register_operand"))))
1507 (clobber (match_scratch:SI 4))
1508 (clobber (match_scratch:SI 5))
1509 (clobber (match_scratch:SI 6))]
1510 "reload_completed && !TARGET_DEBUG_D_MODE
1511 && GP_REG_P (true_regnum (operands[0]))
1512 && true_regnum (operands[1]) == LO_REGNUM"
1513 [(parallel [(set (match_dup 1)
1514 (minus:SI (match_dup 1)
1515 (mult:SI (match_dup 2) (match_dup 3))))
1516 (clobber (match_dup 4))
1517 (clobber (match_dup 5))
1518 (clobber (match_dup 6))])
1519 (set (match_dup 0) (unspec:SI [(match_dup 5) (match_dup 4)] UNSPEC_MFHILO))]
1522 (define_insn "*muls"
1523 [(set (match_operand:SI 0 "register_operand" "=l,d")
1524 (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1525 (match_operand:SI 2 "register_operand" "d,d"))))
1526 (clobber (match_scratch:SI 3 "=h,h"))
1527 (clobber (match_scratch:SI 4 "=X,l"))]
1532 [(set_attr "type" "imul,imul3")
1533 (set_attr "mode" "SI")])
1535 ;; ??? We could define a mulditi3 pattern when TARGET_64BIT.
1537 (define_expand "<u>mulsidi3"
1539 [(set (match_operand:DI 0 "register_operand")
1540 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1541 (any_extend:DI (match_operand:SI 2 "register_operand"))))
1542 (clobber (scratch:DI))
1543 (clobber (scratch:DI))
1544 (clobber (scratch:DI))])]
1545 "!TARGET_64BIT || !TARGET_FIX_R4000"
1549 if (!TARGET_FIX_R4000)
1550 emit_insn (gen_<u>mulsidi3_32bit_internal (operands[0], operands[1],
1553 emit_insn (gen_<u>mulsidi3_32bit_r4000 (operands[0], operands[1],
1559 (define_insn "<u>mulsidi3_32bit_internal"
1560 [(set (match_operand:DI 0 "register_operand" "=x")
1561 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1562 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
1563 "!TARGET_64BIT && !TARGET_FIX_R4000 && !TARGET_DSPR2"
1565 [(set_attr "type" "imul")
1566 (set_attr "mode" "SI")])
1568 (define_insn "<u>mulsidi3_32bit_r4000"
1569 [(set (match_operand:DI 0 "register_operand" "=d")
1570 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1571 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1572 (clobber (match_scratch:DI 3 "=x"))]
1573 "!TARGET_64BIT && TARGET_FIX_R4000"
1574 "mult<u>\t%1,%2\;mflo\t%L0;mfhi\t%M0"
1575 [(set_attr "type" "imul")
1576 (set_attr "mode" "SI")
1577 (set_attr "length" "12")])
1579 (define_insn_and_split "*<u>mulsidi3_64bit"
1580 [(set (match_operand:DI 0 "register_operand" "=d")
1581 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1582 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1583 (clobber (match_scratch:DI 3 "=l"))
1584 (clobber (match_scratch:DI 4 "=h"))
1585 (clobber (match_scratch:DI 5 "=d"))]
1586 "TARGET_64BIT && !TARGET_FIX_R4000"
1588 "&& reload_completed"
1592 (mult:SI (match_dup 1)
1596 (mult:DI (any_extend:DI (match_dup 1))
1597 (any_extend:DI (match_dup 2)))
1600 ;; OP5 <- LO, OP0 <- HI
1601 (set (match_dup 5) (unspec:DI [(match_dup 3) (match_dup 4)] UNSPEC_MFHILO))
1602 (set (match_dup 0) (unspec:DI [(match_dup 4) (match_dup 3)] UNSPEC_MFHILO))
1606 (ashift:DI (match_dup 5)
1609 (lshiftrt:DI (match_dup 5)
1612 ;; Shift OP0 into place.
1614 (ashift:DI (match_dup 0)
1617 ;; OR the two halves together
1619 (ior:DI (match_dup 0)
1622 [(set_attr "type" "imul")
1623 (set_attr "mode" "SI")
1624 (set_attr "length" "24")])
1626 (define_insn "*<u>mulsidi3_64bit_parts"
1627 [(set (match_operand:DI 0 "register_operand" "=l")
1629 (mult:SI (match_operand:SI 2 "register_operand" "d")
1630 (match_operand:SI 3 "register_operand" "d"))))
1631 (set (match_operand:DI 1 "register_operand" "=h")
1633 (mult:DI (any_extend:DI (match_dup 2))
1634 (any_extend:DI (match_dup 3)))
1636 "TARGET_64BIT && !TARGET_FIX_R4000"
1638 [(set_attr "type" "imul")
1639 (set_attr "mode" "SI")])
1641 ;; Widening multiply with negation.
1642 (define_insn "*muls<u>_di"
1643 [(set (match_operand:DI 0 "register_operand" "=x")
1646 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1647 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1648 "!TARGET_64BIT && ISA_HAS_MULS"
1650 [(set_attr "type" "imul")
1651 (set_attr "mode" "SI")])
1653 (define_insn "<u>msubsidi4"
1654 [(set (match_operand:DI 0 "register_operand" "=ka")
1656 (match_operand:DI 3 "register_operand" "0")
1658 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1659 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1660 "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || TARGET_DSPR2)"
1663 return "msub<u>\t%q0,%1,%2";
1664 else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
1665 return "msub<u>\t%1,%2";
1667 return "msac<u>\t$0,%1,%2";
1669 [(set_attr "type" "imadd")
1670 (set_attr "mode" "SI")])
1672 ;; _highpart patterns
1674 (define_expand "<su>mulsi3_highpart"
1675 [(set (match_operand:SI 0 "register_operand")
1678 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1679 (any_extend:DI (match_operand:SI 2 "register_operand")))
1681 "ISA_HAS_MULHI || !TARGET_FIX_R4000"
1684 emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
1688 emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
1693 (define_insn "<su>mulsi3_highpart_internal"
1694 [(set (match_operand:SI 0 "register_operand" "=h")
1697 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1698 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1700 (clobber (match_scratch:SI 3 "=l"))]
1701 "!ISA_HAS_MULHI && !TARGET_FIX_R4000"
1703 [(set_attr "type" "imul")
1704 (set_attr "mode" "SI")])
1706 (define_insn "<su>mulsi3_highpart_mulhi_internal"
1707 [(set (match_operand:SI 0 "register_operand" "=h,d")
1711 (any_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
1712 (any_extend:DI (match_operand:SI 2 "register_operand" "d,d")))
1714 (clobber (match_scratch:SI 3 "=l,l"))
1715 (clobber (match_scratch:SI 4 "=X,h"))]
1720 [(set_attr "type" "imul,imul3")
1721 (set_attr "mode" "SI")])
1723 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
1724 [(set (match_operand:SI 0 "register_operand" "=h,d")
1729 (any_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
1730 (any_extend:DI (match_operand:SI 2 "register_operand" "d,d"))))
1732 (clobber (match_scratch:SI 3 "=l,l"))
1733 (clobber (match_scratch:SI 4 "=X,h"))]
1737 mulshi<u>\t%0,%1,%2"
1738 [(set_attr "type" "imul,imul3")
1739 (set_attr "mode" "SI")])
1741 ;; Disable unsigned multiplication for -mfix-vr4120. This is for VR4120
1742 ;; errata MD(0), which says that dmultu does not always produce the
1744 (define_insn "<su>muldi3_highpart"
1745 [(set (match_operand:DI 0 "register_operand" "=h")
1749 (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
1750 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
1752 (clobber (match_scratch:DI 3 "=l"))]
1753 "TARGET_64BIT && !TARGET_FIX_R4000
1754 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
1756 [(set_attr "type" "imul")
1757 (set_attr "mode" "DI")])
1759 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
1760 ;; instruction. The HI/LO registers are used as a 64-bit accumulator.
1762 (define_insn "madsi"
1763 [(set (match_operand:SI 0 "register_operand" "+l")
1764 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1765 (match_operand:SI 2 "register_operand" "d"))
1767 (clobber (match_scratch:SI 3 "=h"))]
1770 [(set_attr "type" "imadd")
1771 (set_attr "mode" "SI")])
1773 (define_insn "<u>maddsidi4"
1774 [(set (match_operand:DI 0 "register_operand" "=ka")
1776 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1777 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1778 (match_operand:DI 3 "register_operand" "0")))]
1779 "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || TARGET_DSPR2)
1783 return "mad<u>\t%1,%2";
1784 else if (TARGET_DSPR2)
1785 return "madd<u>\t%q0,%1,%2";
1786 else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
1787 return "madd<u>\t%1,%2";
1789 /* See comment in *macc. */
1790 return "%[macc<u>\t%@,%1,%2%]";
1792 [(set_attr "type" "imadd")
1793 (set_attr "mode" "SI")])
1795 ;; Floating point multiply accumulate instructions.
1797 (define_insn "*madd<mode>"
1798 [(set (match_operand:ANYF 0 "register_operand" "=f")
1799 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1800 (match_operand:ANYF 2 "register_operand" "f"))
1801 (match_operand:ANYF 3 "register_operand" "f")))]
1802 "ISA_HAS_FP4 && TARGET_FUSED_MADD"
1803 "madd.<fmt>\t%0,%3,%1,%2"
1804 [(set_attr "type" "fmadd")
1805 (set_attr "mode" "<UNITMODE>")])
1807 (define_insn "*msub<mode>"
1808 [(set (match_operand:ANYF 0 "register_operand" "=f")
1809 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1810 (match_operand:ANYF 2 "register_operand" "f"))
1811 (match_operand:ANYF 3 "register_operand" "f")))]
1812 "ISA_HAS_FP4 && TARGET_FUSED_MADD"
1813 "msub.<fmt>\t%0,%3,%1,%2"
1814 [(set_attr "type" "fmadd")
1815 (set_attr "mode" "<UNITMODE>")])
1817 (define_insn "*nmadd<mode>"
1818 [(set (match_operand:ANYF 0 "register_operand" "=f")
1819 (neg:ANYF (plus:ANYF
1820 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1821 (match_operand:ANYF 2 "register_operand" "f"))
1822 (match_operand:ANYF 3 "register_operand" "f"))))]
1823 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1824 && HONOR_SIGNED_ZEROS (<MODE>mode)
1825 && !HONOR_NANS (<MODE>mode)"
1826 "nmadd.<fmt>\t%0,%3,%1,%2"
1827 [(set_attr "type" "fmadd")
1828 (set_attr "mode" "<UNITMODE>")])
1830 (define_insn "*nmadd<mode>_fastmath"
1831 [(set (match_operand:ANYF 0 "register_operand" "=f")
1833 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
1834 (match_operand:ANYF 2 "register_operand" "f"))
1835 (match_operand:ANYF 3 "register_operand" "f")))]
1836 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1837 && !HONOR_SIGNED_ZEROS (<MODE>mode)
1838 && !HONOR_NANS (<MODE>mode)"
1839 "nmadd.<fmt>\t%0,%3,%1,%2"
1840 [(set_attr "type" "fmadd")
1841 (set_attr "mode" "<UNITMODE>")])
1843 (define_insn "*nmsub<mode>"
1844 [(set (match_operand:ANYF 0 "register_operand" "=f")
1845 (neg:ANYF (minus:ANYF
1846 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
1847 (match_operand:ANYF 3 "register_operand" "f"))
1848 (match_operand:ANYF 1 "register_operand" "f"))))]
1849 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1850 && HONOR_SIGNED_ZEROS (<MODE>mode)
1851 && !HONOR_NANS (<MODE>mode)"
1852 "nmsub.<fmt>\t%0,%1,%2,%3"
1853 [(set_attr "type" "fmadd")
1854 (set_attr "mode" "<UNITMODE>")])
1856 (define_insn "*nmsub<mode>_fastmath"
1857 [(set (match_operand:ANYF 0 "register_operand" "=f")
1859 (match_operand:ANYF 1 "register_operand" "f")
1860 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
1861 (match_operand:ANYF 3 "register_operand" "f"))))]
1862 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1863 && !HONOR_SIGNED_ZEROS (<MODE>mode)
1864 && !HONOR_NANS (<MODE>mode)"
1865 "nmsub.<fmt>\t%0,%1,%2,%3"
1866 [(set_attr "type" "fmadd")
1867 (set_attr "mode" "<UNITMODE>")])
1870 ;; ....................
1872 ;; DIVISION and REMAINDER
1874 ;; ....................
1877 (define_expand "div<mode>3"
1878 [(set (match_operand:ANYF 0 "register_operand")
1879 (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
1880 (match_operand:ANYF 2 "register_operand")))]
1881 "<divide_condition>"
1883 if (const_1_operand (operands[1], <MODE>mode))
1884 if (!(ISA_HAS_FP4 && flag_unsafe_math_optimizations))
1885 operands[1] = force_reg (<MODE>mode, operands[1]);
1888 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
1890 ;; If an mfc1 or dmfc1 happens to access the floating point register
1891 ;; file at the same time a long latency operation (div, sqrt, recip,
1892 ;; sqrt) iterates an intermediate result back through the floating
1893 ;; point register file bypass, then instead returning the correct
1894 ;; register value the mfc1 or dmfc1 operation returns the intermediate
1895 ;; result of the long latency operation.
1897 ;; The workaround is to insert an unconditional 'mov' from/to the
1898 ;; long latency op destination register.
1900 (define_insn "*div<mode>3"
1901 [(set (match_operand:ANYF 0 "register_operand" "=f")
1902 (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
1903 (match_operand:ANYF 2 "register_operand" "f")))]
1904 "<divide_condition>"
1907 return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
1909 return "div.<fmt>\t%0,%1,%2";
1911 [(set_attr "type" "fdiv")
1912 (set_attr "mode" "<UNITMODE>")
1913 (set (attr "length")
1914 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1918 (define_insn "*recip<mode>3"
1919 [(set (match_operand:ANYF 0 "register_operand" "=f")
1920 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
1921 (match_operand:ANYF 2 "register_operand" "f")))]
1922 "<recip_condition> && flag_unsafe_math_optimizations"
1925 return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
1927 return "recip.<fmt>\t%0,%2";
1929 [(set_attr "type" "frdiv")
1930 (set_attr "mode" "<UNITMODE>")
1931 (set (attr "length")
1932 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1936 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
1937 ;; with negative operands. We use special libgcc functions instead.
1938 (define_insn "divmod<mode>4"
1939 [(set (match_operand:GPR 0 "register_operand" "=l")
1940 (div:GPR (match_operand:GPR 1 "register_operand" "d")
1941 (match_operand:GPR 2 "register_operand" "d")))
1942 (set (match_operand:GPR 3 "register_operand" "=h")
1943 (mod:GPR (match_dup 1)
1945 "!TARGET_FIX_VR4120"
1946 { return mips_output_division ("<d>div\t$0,%1,%2", operands); }
1947 [(set_attr "type" "idiv")
1948 (set_attr "mode" "<MODE>")])
1950 (define_insn "udivmod<mode>4"
1951 [(set (match_operand:GPR 0 "register_operand" "=l")
1952 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
1953 (match_operand:GPR 2 "register_operand" "d")))
1954 (set (match_operand:GPR 3 "register_operand" "=h")
1955 (umod:GPR (match_dup 1)
1958 { return mips_output_division ("<d>divu\t$0,%1,%2", operands); }
1959 [(set_attr "type" "idiv")
1960 (set_attr "mode" "<MODE>")])
1963 ;; ....................
1967 ;; ....................
1969 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
1970 ;; "*div[sd]f3" comment for details).
1972 (define_insn "sqrt<mode>2"
1973 [(set (match_operand:ANYF 0 "register_operand" "=f")
1974 (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
1978 return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
1980 return "sqrt.<fmt>\t%0,%1";
1982 [(set_attr "type" "fsqrt")
1983 (set_attr "mode" "<UNITMODE>")
1984 (set (attr "length")
1985 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1989 (define_insn "*rsqrt<mode>a"
1990 [(set (match_operand:ANYF 0 "register_operand" "=f")
1991 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
1992 (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
1993 "<recip_condition> && flag_unsafe_math_optimizations"
1996 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
1998 return "rsqrt.<fmt>\t%0,%2";
2000 [(set_attr "type" "frsqrt")
2001 (set_attr "mode" "<UNITMODE>")
2002 (set (attr "length")
2003 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
2007 (define_insn "*rsqrt<mode>b"
2008 [(set (match_operand:ANYF 0 "register_operand" "=f")
2009 (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2010 (match_operand:ANYF 2 "register_operand" "f"))))]
2011 "<recip_condition> && flag_unsafe_math_optimizations"
2014 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2016 return "rsqrt.<fmt>\t%0,%2";
2018 [(set_attr "type" "frsqrt")
2019 (set_attr "mode" "<UNITMODE>")
2020 (set (attr "length")
2021 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
2026 ;; ....................
2030 ;; ....................
2032 ;; Do not use the integer abs macro instruction, since that signals an
2033 ;; exception on -2147483648 (sigh).
2035 ;; abs.fmt is an arithmetic instruction and treats all NaN inputs as
2036 ;; invalid; it does not clear their sign bits. We therefore can't use
2037 ;; abs.fmt if the signs of NaNs matter.
2039 (define_insn "abs<mode>2"
2040 [(set (match_operand:ANYF 0 "register_operand" "=f")
2041 (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2042 "!HONOR_NANS (<MODE>mode)"
2044 [(set_attr "type" "fabs")
2045 (set_attr "mode" "<UNITMODE>")])
2048 ;; ...................
2050 ;; Count leading zeroes.
2052 ;; ...................
2055 (define_insn "clz<mode>2"
2056 [(set (match_operand:GPR 0 "register_operand" "=d")
2057 (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
2060 [(set_attr "type" "clz")
2061 (set_attr "mode" "<MODE>")])
2064 ;; ....................
2066 ;; NEGATION and ONE'S COMPLEMENT
2068 ;; ....................
2070 (define_insn "negsi2"
2071 [(set (match_operand:SI 0 "register_operand" "=d")
2072 (neg:SI (match_operand:SI 1 "register_operand" "d")))]
2076 return "neg\t%0,%1";
2078 return "subu\t%0,%.,%1";
2080 [(set_attr "type" "arith")
2081 (set_attr "mode" "SI")])
2083 (define_insn "negdi2"
2084 [(set (match_operand:DI 0 "register_operand" "=d")
2085 (neg:DI (match_operand:DI 1 "register_operand" "d")))]
2086 "TARGET_64BIT && !TARGET_MIPS16"
2088 [(set_attr "type" "arith")
2089 (set_attr "mode" "DI")])
2091 ;; neg.fmt is an arithmetic instruction and treats all NaN inputs as
2092 ;; invalid; it does not flip their sign bit. We therefore can't use
2093 ;; neg.fmt if the signs of NaNs matter.
2095 (define_insn "neg<mode>2"
2096 [(set (match_operand:ANYF 0 "register_operand" "=f")
2097 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2098 "!HONOR_NANS (<MODE>mode)"
2100 [(set_attr "type" "fneg")
2101 (set_attr "mode" "<UNITMODE>")])
2103 (define_insn "one_cmpl<mode>2"
2104 [(set (match_operand:GPR 0 "register_operand" "=d")
2105 (not:GPR (match_operand:GPR 1 "register_operand" "d")))]
2109 return "not\t%0,%1";
2111 return "nor\t%0,%.,%1";
2113 [(set_attr "type" "arith")
2114 (set_attr "mode" "<MODE>")])
2117 ;; ....................
2121 ;; ....................
2124 ;; Many of these instructions use trivial define_expands, because we
2125 ;; want to use a different set of constraints when TARGET_MIPS16.
2127 (define_expand "and<mode>3"
2128 [(set (match_operand:GPR 0 "register_operand")
2129 (and:GPR (match_operand:GPR 1 "register_operand")
2130 (match_operand:GPR 2 "uns_arith_operand")))]
2134 operands[2] = force_reg (<MODE>mode, operands[2]);
2137 (define_insn "*and<mode>3"
2138 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2139 (and:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2140 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2145 [(set_attr "type" "arith")
2146 (set_attr "mode" "<MODE>")])
2148 (define_insn "*and<mode>3_mips16"
2149 [(set (match_operand:GPR 0 "register_operand" "=d")
2150 (and:GPR (match_operand:GPR 1 "register_operand" "%0")
2151 (match_operand:GPR 2 "register_operand" "d")))]
2154 [(set_attr "type" "arith")
2155 (set_attr "mode" "<MODE>")])
2157 (define_expand "ior<mode>3"
2158 [(set (match_operand:GPR 0 "register_operand")
2159 (ior:GPR (match_operand:GPR 1 "register_operand")
2160 (match_operand:GPR 2 "uns_arith_operand")))]
2164 operands[2] = force_reg (<MODE>mode, operands[2]);
2167 (define_insn "*ior<mode>3"
2168 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2169 (ior:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2170 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2175 [(set_attr "type" "arith")
2176 (set_attr "mode" "<MODE>")])
2178 (define_insn "*ior<mode>3_mips16"
2179 [(set (match_operand:GPR 0 "register_operand" "=d")
2180 (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
2181 (match_operand:GPR 2 "register_operand" "d")))]
2184 [(set_attr "type" "arith")
2185 (set_attr "mode" "<MODE>")])
2187 (define_expand "xor<mode>3"
2188 [(set (match_operand:GPR 0 "register_operand")
2189 (xor:GPR (match_operand:GPR 1 "register_operand")
2190 (match_operand:GPR 2 "uns_arith_operand")))]
2195 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2196 (xor:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2197 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2202 [(set_attr "type" "arith")
2203 (set_attr "mode" "<MODE>")])
2206 [(set (match_operand:GPR 0 "register_operand" "=d,t,t")
2207 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
2208 (match_operand:GPR 2 "uns_arith_operand" "d,K,d")))]
2214 [(set_attr "type" "arith")
2215 (set_attr "mode" "<MODE>")
2216 (set_attr_alternative "length"
2218 (if_then_else (match_operand:VOID 2 "m16_uimm8_1")
2223 (define_insn "*nor<mode>3"
2224 [(set (match_operand:GPR 0 "register_operand" "=d")
2225 (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
2226 (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
2229 [(set_attr "type" "arith")
2230 (set_attr "mode" "<MODE>")])
2233 ;; ....................
2237 ;; ....................
2241 (define_insn "truncdfsf2"
2242 [(set (match_operand:SF 0 "register_operand" "=f")
2243 (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
2244 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2246 [(set_attr "type" "fcvt")
2247 (set_attr "cnv_mode" "D2S")
2248 (set_attr "mode" "SF")])
2250 ;; Integer truncation patterns. Truncating SImode values to smaller
2251 ;; modes is a no-op, as it is for most other GCC ports. Truncating
2252 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
2253 ;; need to make sure that the lower 32 bits are properly sign-extended
2254 ;; (see TRULY_NOOP_TRUNCATION). Truncating DImode values into modes
2255 ;; smaller than SImode is equivalent to two separate truncations:
2258 ;; DI ---> HI == DI ---> SI ---> HI
2259 ;; DI ---> QI == DI ---> SI ---> QI
2261 ;; Step A needs a real instruction but step B does not.
2263 (define_insn "truncdisi2"
2264 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
2265 (truncate:SI (match_operand:DI 1 "register_operand" "d,d")))]
2270 [(set_attr "type" "shift,store")
2271 (set_attr "mode" "SI")
2272 (set_attr "extended_mips16" "yes,*")])
2274 (define_insn "truncdihi2"
2275 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,m")
2276 (truncate:HI (match_operand:DI 1 "register_operand" "d,d")))]
2281 [(set_attr "type" "shift,store")
2282 (set_attr "mode" "SI")
2283 (set_attr "extended_mips16" "yes,*")])
2285 (define_insn "truncdiqi2"
2286 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,m")
2287 (truncate:QI (match_operand:DI 1 "register_operand" "d,d")))]
2292 [(set_attr "type" "shift,store")
2293 (set_attr "mode" "SI")
2294 (set_attr "extended_mips16" "yes,*")])
2296 ;; Combiner patterns to optimize shift/truncate combinations.
2299 [(set (match_operand:SI 0 "register_operand" "=d")
2301 (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
2302 (match_operand:DI 2 "const_arith_operand" ""))))]
2303 "TARGET_64BIT && !TARGET_MIPS16 && INTVAL (operands[2]) >= 32"
2305 [(set_attr "type" "shift")
2306 (set_attr "mode" "SI")])
2309 [(set (match_operand:SI 0 "register_operand" "=d")
2310 (truncate:SI (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
2312 "TARGET_64BIT && !TARGET_MIPS16"
2314 [(set_attr "type" "shift")
2315 (set_attr "mode" "SI")])
2318 ;; Combiner patterns for truncate/sign_extend combinations. They use
2319 ;; the shift/truncate patterns above.
2321 (define_insn_and_split ""
2322 [(set (match_operand:SI 0 "register_operand" "=d")
2324 (truncate:HI (match_operand:DI 1 "register_operand" "d"))))]
2325 "TARGET_64BIT && !TARGET_MIPS16"
2327 "&& reload_completed"
2329 (ashift:DI (match_dup 1)
2332 (truncate:SI (ashiftrt:DI (match_dup 2)
2334 { operands[2] = gen_lowpart (DImode, operands[0]); })
2336 (define_insn_and_split ""
2337 [(set (match_operand:SI 0 "register_operand" "=d")
2339 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
2340 "TARGET_64BIT && !TARGET_MIPS16"
2342 "&& reload_completed"
2344 (ashift:DI (match_dup 1)
2347 (truncate:SI (ashiftrt:DI (match_dup 2)
2349 { operands[2] = gen_lowpart (DImode, operands[0]); })
2352 ;; Combiner patterns to optimize truncate/zero_extend combinations.
2355 [(set (match_operand:SI 0 "register_operand" "=d")
2356 (zero_extend:SI (truncate:HI
2357 (match_operand:DI 1 "register_operand" "d"))))]
2358 "TARGET_64BIT && !TARGET_MIPS16"
2359 "andi\t%0,%1,0xffff"
2360 [(set_attr "type" "arith")
2361 (set_attr "mode" "SI")])
2364 [(set (match_operand:SI 0 "register_operand" "=d")
2365 (zero_extend:SI (truncate:QI
2366 (match_operand:DI 1 "register_operand" "d"))))]
2367 "TARGET_64BIT && !TARGET_MIPS16"
2369 [(set_attr "type" "arith")
2370 (set_attr "mode" "SI")])
2373 [(set (match_operand:HI 0 "register_operand" "=d")
2374 (zero_extend:HI (truncate:QI
2375 (match_operand:DI 1 "register_operand" "d"))))]
2376 "TARGET_64BIT && !TARGET_MIPS16"
2378 [(set_attr "type" "arith")
2379 (set_attr "mode" "HI")])
2382 ;; ....................
2386 ;; ....................
2390 (define_insn_and_split "zero_extendsidi2"
2391 [(set (match_operand:DI 0 "register_operand" "=d,d")
2392 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
2397 "&& reload_completed && REG_P (operands[1])"
2399 (ashift:DI (match_dup 1) (const_int 32)))
2401 (lshiftrt:DI (match_dup 0) (const_int 32)))]
2402 { operands[1] = gen_lowpart (DImode, operands[1]); }
2403 [(set_attr "type" "multi,load")
2404 (set_attr "mode" "DI")
2405 (set_attr "length" "8,*")])
2407 ;; Combine is not allowed to convert this insn into a zero_extendsidi2
2408 ;; because of TRULY_NOOP_TRUNCATION.
2410 (define_insn_and_split "*clear_upper32"
2411 [(set (match_operand:DI 0 "register_operand" "=d,d")
2412 (and:DI (match_operand:DI 1 "nonimmediate_operand" "d,o")
2413 (const_int 4294967295)))]
2416 if (which_alternative == 0)
2419 operands[1] = gen_lowpart (SImode, operands[1]);
2420 return "lwu\t%0,%1";
2422 "&& reload_completed && REG_P (operands[1])"
2424 (ashift:DI (match_dup 1) (const_int 32)))
2426 (lshiftrt:DI (match_dup 0) (const_int 32)))]
2428 [(set_attr "type" "multi,load")
2429 (set_attr "mode" "DI")
2430 (set_attr "length" "8,*")])
2432 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
2433 [(set (match_operand:GPR 0 "register_operand")
2434 (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
2437 if (TARGET_MIPS16 && !GENERATE_MIPS16E
2438 && !memory_operand (operands[1], <SHORT:MODE>mode))
2440 emit_insn (gen_and<GPR:mode>3 (operands[0],
2441 gen_lowpart (<GPR:MODE>mode, operands[1]),
2442 force_reg (<GPR:MODE>mode,
2443 GEN_INT (<SHORT:mask>))));
2448 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
2449 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2451 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2454 andi\t%0,%1,<SHORT:mask>
2455 l<SHORT:size>u\t%0,%1"
2456 [(set_attr "type" "arith,load")
2457 (set_attr "mode" "<GPR:MODE>")])
2459 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
2460 [(set (match_operand:GPR 0 "register_operand" "=d")
2461 (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
2463 "ze<SHORT:size>\t%0"
2464 [(set_attr "type" "arith")
2465 (set_attr "mode" "<GPR:MODE>")])
2467 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
2468 [(set (match_operand:GPR 0 "register_operand" "=d")
2469 (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
2471 "l<SHORT:size>u\t%0,%1"
2472 [(set_attr "type" "load")
2473 (set_attr "mode" "<GPR:MODE>")])
2475 (define_expand "zero_extendqihi2"
2476 [(set (match_operand:HI 0 "register_operand")
2477 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
2480 if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
2482 emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
2488 (define_insn "*zero_extendqihi2"
2489 [(set (match_operand:HI 0 "register_operand" "=d,d")
2490 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
2495 [(set_attr "type" "arith,load")
2496 (set_attr "mode" "HI")])
2498 (define_insn "*zero_extendqihi2_mips16"
2499 [(set (match_operand:HI 0 "register_operand" "=d")
2500 (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
2503 [(set_attr "type" "load")
2504 (set_attr "mode" "HI")])
2507 ;; ....................
2511 ;; ....................
2514 ;; Those for integer source operand are ordered widest source type first.
2516 ;; When TARGET_64BIT, all SImode integer registers should already be in
2517 ;; sign-extended form (see TRULY_NOOP_TRUNCATION and truncdisi2). We can
2518 ;; therefore get rid of register->register instructions if we constrain
2519 ;; the source to be in the same register as the destination.
2521 ;; The register alternative has type "arith" so that the pre-reload
2522 ;; scheduler will treat it as a move. This reflects what happens if
2523 ;; the register alternative needs a reload.
2524 (define_insn_and_split "extendsidi2"
2525 [(set (match_operand:DI 0 "register_operand" "=d,d")
2526 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,m")))]
2531 "&& reload_completed && register_operand (operands[1], VOIDmode)"
2534 emit_note (NOTE_INSN_DELETED);
2537 [(set_attr "type" "arith,load")
2538 (set_attr "mode" "DI")])
2540 (define_expand "extend<SHORT:mode><GPR:mode>2"
2541 [(set (match_operand:GPR 0 "register_operand")
2542 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
2545 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
2546 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2547 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
2551 l<SHORT:size>\t%0,%1"
2552 [(set_attr "type" "arith,load")
2553 (set_attr "mode" "<GPR:MODE>")])
2555 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
2556 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2558 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2559 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
2562 l<SHORT:size>\t%0,%1"
2563 "&& reload_completed && REG_P (operands[1])"
2564 [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
2565 (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
2567 operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
2568 operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
2569 - GET_MODE_BITSIZE (<SHORT:MODE>mode));
2571 [(set_attr "type" "arith,load")
2572 (set_attr "mode" "<GPR:MODE>")
2573 (set_attr "length" "8,*")])
2575 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
2576 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2578 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2581 se<SHORT:size>\t%0,%1
2582 l<SHORT:size>\t%0,%1"
2583 [(set_attr "type" "arith,load")
2584 (set_attr "mode" "<GPR:MODE>")])
2586 ;; This pattern generates the same code as extendqisi2; split it into
2587 ;; that form after reload.
2588 (define_insn_and_split "extendqihi2"
2589 [(set (match_operand:HI 0 "register_operand" "=d,d")
2590 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
2594 [(set (match_dup 0) (sign_extend:SI (match_dup 1)))]
2595 { operands[0] = gen_lowpart (SImode, operands[0]); }
2596 [(set_attr "type" "arith,load")
2597 (set_attr "mode" "SI")
2598 (set_attr "length" "8,*")])
2600 (define_insn "extendsfdf2"
2601 [(set (match_operand:DF 0 "register_operand" "=f")
2602 (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
2603 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2605 [(set_attr "type" "fcvt")
2606 (set_attr "cnv_mode" "S2D")
2607 (set_attr "mode" "DF")])
2610 ;; ....................
2614 ;; ....................
2616 (define_expand "fix_truncdfsi2"
2617 [(set (match_operand:SI 0 "register_operand")
2618 (fix:SI (match_operand:DF 1 "register_operand")))]
2619 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2621 if (!ISA_HAS_TRUNC_W)
2623 emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
2628 (define_insn "fix_truncdfsi2_insn"
2629 [(set (match_operand:SI 0 "register_operand" "=f")
2630 (fix:SI (match_operand:DF 1 "register_operand" "f")))]
2631 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
2633 [(set_attr "type" "fcvt")
2634 (set_attr "mode" "DF")
2635 (set_attr "cnv_mode" "D2I")
2636 (set_attr "length" "4")])
2638 (define_insn "fix_truncdfsi2_macro"
2639 [(set (match_operand:SI 0 "register_operand" "=f")
2640 (fix:SI (match_operand:DF 1 "register_operand" "f")))
2641 (clobber (match_scratch:DF 2 "=d"))]
2642 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
2645 return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
2647 return "trunc.w.d %0,%1,%2";
2649 [(set_attr "type" "fcvt")
2650 (set_attr "mode" "DF")
2651 (set_attr "cnv_mode" "D2I")
2652 (set_attr "length" "36")])
2654 (define_expand "fix_truncsfsi2"
2655 [(set (match_operand:SI 0 "register_operand")
2656 (fix:SI (match_operand:SF 1 "register_operand")))]
2659 if (!ISA_HAS_TRUNC_W)
2661 emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
2666 (define_insn "fix_truncsfsi2_insn"
2667 [(set (match_operand:SI 0 "register_operand" "=f")
2668 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
2669 "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
2671 [(set_attr "type" "fcvt")
2672 (set_attr "mode" "SF")
2673 (set_attr "cnv_mode" "S2I")
2674 (set_attr "length" "4")])
2676 (define_insn "fix_truncsfsi2_macro"
2677 [(set (match_operand:SI 0 "register_operand" "=f")
2678 (fix:SI (match_operand:SF 1 "register_operand" "f")))
2679 (clobber (match_scratch:SF 2 "=d"))]
2680 "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
2683 return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
2685 return "trunc.w.s %0,%1,%2";
2687 [(set_attr "type" "fcvt")
2688 (set_attr "mode" "SF")
2689 (set_attr "cnv_mode" "S2I")
2690 (set_attr "length" "36")])
2693 (define_insn "fix_truncdfdi2"
2694 [(set (match_operand:DI 0 "register_operand" "=f")
2695 (fix:DI (match_operand:DF 1 "register_operand" "f")))]
2696 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2698 [(set_attr "type" "fcvt")
2699 (set_attr "mode" "DF")
2700 (set_attr "cnv_mode" "D2I")
2701 (set_attr "length" "4")])
2704 (define_insn "fix_truncsfdi2"
2705 [(set (match_operand:DI 0 "register_operand" "=f")
2706 (fix:DI (match_operand:SF 1 "register_operand" "f")))]
2707 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2709 [(set_attr "type" "fcvt")
2710 (set_attr "mode" "SF")
2711 (set_attr "cnv_mode" "S2I")
2712 (set_attr "length" "4")])
2715 (define_insn "floatsidf2"
2716 [(set (match_operand:DF 0 "register_operand" "=f")
2717 (float:DF (match_operand:SI 1 "register_operand" "f")))]
2718 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2720 [(set_attr "type" "fcvt")
2721 (set_attr "mode" "DF")
2722 (set_attr "cnv_mode" "I2D")
2723 (set_attr "length" "4")])
2726 (define_insn "floatdidf2"
2727 [(set (match_operand:DF 0 "register_operand" "=f")
2728 (float:DF (match_operand:DI 1 "register_operand" "f")))]
2729 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2731 [(set_attr "type" "fcvt")
2732 (set_attr "mode" "DF")
2733 (set_attr "cnv_mode" "I2D")
2734 (set_attr "length" "4")])
2737 (define_insn "floatsisf2"
2738 [(set (match_operand:SF 0 "register_operand" "=f")
2739 (float:SF (match_operand:SI 1 "register_operand" "f")))]
2742 [(set_attr "type" "fcvt")
2743 (set_attr "mode" "SF")
2744 (set_attr "cnv_mode" "I2S")
2745 (set_attr "length" "4")])
2748 (define_insn "floatdisf2"
2749 [(set (match_operand:SF 0 "register_operand" "=f")
2750 (float:SF (match_operand:DI 1 "register_operand" "f")))]
2751 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2753 [(set_attr "type" "fcvt")
2754 (set_attr "mode" "SF")
2755 (set_attr "cnv_mode" "I2S")
2756 (set_attr "length" "4")])
2759 (define_expand "fixuns_truncdfsi2"
2760 [(set (match_operand:SI 0 "register_operand")
2761 (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
2762 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2764 rtx reg1 = gen_reg_rtx (DFmode);
2765 rtx reg2 = gen_reg_rtx (DFmode);
2766 rtx reg3 = gen_reg_rtx (SImode);
2767 rtx label1 = gen_label_rtx ();
2768 rtx label2 = gen_label_rtx ();
2769 REAL_VALUE_TYPE offset;
2771 real_2expN (&offset, 31);
2773 if (reg1) /* Turn off complaints about unreached code. */
2775 emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
2776 do_pending_stack_adjust ();
2778 emit_insn (gen_cmpdf (operands[1], reg1));
2779 emit_jump_insn (gen_bge (label1));
2781 emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
2782 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2783 gen_rtx_LABEL_REF (VOIDmode, label2)));
2786 emit_label (label1);
2787 emit_move_insn (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
2788 emit_move_insn (reg3, GEN_INT (trunc_int_for_mode
2789 (BITMASK_HIGH, SImode)));
2791 emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
2792 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
2794 emit_label (label2);
2796 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2797 fields, and can't be used for REG_NOTES anyway). */
2798 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2804 (define_expand "fixuns_truncdfdi2"
2805 [(set (match_operand:DI 0 "register_operand")
2806 (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
2807 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
2809 rtx reg1 = gen_reg_rtx (DFmode);
2810 rtx reg2 = gen_reg_rtx (DFmode);
2811 rtx reg3 = gen_reg_rtx (DImode);
2812 rtx label1 = gen_label_rtx ();
2813 rtx label2 = gen_label_rtx ();
2814 REAL_VALUE_TYPE offset;
2816 real_2expN (&offset, 63);
2818 emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
2819 do_pending_stack_adjust ();
2821 emit_insn (gen_cmpdf (operands[1], reg1));
2822 emit_jump_insn (gen_bge (label1));
2824 emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
2825 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2826 gen_rtx_LABEL_REF (VOIDmode, label2)));
2829 emit_label (label1);
2830 emit_move_insn (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
2831 emit_move_insn (reg3, GEN_INT (BITMASK_HIGH));
2832 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
2834 emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
2835 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
2837 emit_label (label2);
2839 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2840 fields, and can't be used for REG_NOTES anyway). */
2841 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2846 (define_expand "fixuns_truncsfsi2"
2847 [(set (match_operand:SI 0 "register_operand")
2848 (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
2851 rtx reg1 = gen_reg_rtx (SFmode);
2852 rtx reg2 = gen_reg_rtx (SFmode);
2853 rtx reg3 = gen_reg_rtx (SImode);
2854 rtx label1 = gen_label_rtx ();
2855 rtx label2 = gen_label_rtx ();
2856 REAL_VALUE_TYPE offset;
2858 real_2expN (&offset, 31);
2860 emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
2861 do_pending_stack_adjust ();
2863 emit_insn (gen_cmpsf (operands[1], reg1));
2864 emit_jump_insn (gen_bge (label1));
2866 emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
2867 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2868 gen_rtx_LABEL_REF (VOIDmode, label2)));
2871 emit_label (label1);
2872 emit_move_insn (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
2873 emit_move_insn (reg3, GEN_INT (trunc_int_for_mode
2874 (BITMASK_HIGH, SImode)));
2876 emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
2877 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
2879 emit_label (label2);
2881 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2882 fields, and can't be used for REG_NOTES anyway). */
2883 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2888 (define_expand "fixuns_truncsfdi2"
2889 [(set (match_operand:DI 0 "register_operand")
2890 (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
2891 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
2893 rtx reg1 = gen_reg_rtx (SFmode);
2894 rtx reg2 = gen_reg_rtx (SFmode);
2895 rtx reg3 = gen_reg_rtx (DImode);
2896 rtx label1 = gen_label_rtx ();
2897 rtx label2 = gen_label_rtx ();
2898 REAL_VALUE_TYPE offset;
2900 real_2expN (&offset, 63);
2902 emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
2903 do_pending_stack_adjust ();
2905 emit_insn (gen_cmpsf (operands[1], reg1));
2906 emit_jump_insn (gen_bge (label1));
2908 emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
2909 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2910 gen_rtx_LABEL_REF (VOIDmode, label2)));
2913 emit_label (label1);
2914 emit_move_insn (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
2915 emit_move_insn (reg3, GEN_INT (BITMASK_HIGH));
2916 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
2918 emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
2919 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
2921 emit_label (label2);
2923 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2924 fields, and can't be used for REG_NOTES anyway). */
2925 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2930 ;; ....................
2934 ;; ....................
2936 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
2938 (define_expand "extv"
2939 [(set (match_operand 0 "register_operand")
2940 (sign_extract (match_operand:QI 1 "memory_operand")
2941 (match_operand 2 "immediate_operand")
2942 (match_operand 3 "immediate_operand")))]
2945 if (mips_expand_unaligned_load (operands[0], operands[1],
2946 INTVAL (operands[2]),
2947 INTVAL (operands[3])))
2953 (define_expand "extzv"
2954 [(set (match_operand 0 "register_operand")
2955 (zero_extract (match_operand 1 "nonimmediate_operand")
2956 (match_operand 2 "immediate_operand")
2957 (match_operand 3 "immediate_operand")))]
2960 if (mips_expand_unaligned_load (operands[0], operands[1],
2961 INTVAL (operands[2]),
2962 INTVAL (operands[3])))
2964 else if (mips_use_ins_ext_p (operands[1], operands[2], operands[3]))
2966 if (GET_MODE (operands[0]) == DImode)
2967 emit_insn (gen_extzvdi (operands[0], operands[1], operands[2],
2970 emit_insn (gen_extzvsi (operands[0], operands[1], operands[2],
2978 (define_insn "extzv<mode>"
2979 [(set (match_operand:GPR 0 "register_operand" "=d")
2980 (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
2981 (match_operand:SI 2 "immediate_operand" "I")
2982 (match_operand:SI 3 "immediate_operand" "I")))]
2983 "mips_use_ins_ext_p (operands[1], operands[2], operands[3])"
2984 "<d>ext\t%0,%1,%3,%2"
2985 [(set_attr "type" "arith")
2986 (set_attr "mode" "<MODE>")])
2989 (define_expand "insv"
2990 [(set (zero_extract (match_operand 0 "nonimmediate_operand")
2991 (match_operand 1 "immediate_operand")
2992 (match_operand 2 "immediate_operand"))
2993 (match_operand 3 "reg_or_0_operand"))]
2996 if (mips_expand_unaligned_store (operands[0], operands[3],
2997 INTVAL (operands[1]),
2998 INTVAL (operands[2])))
3000 else if (mips_use_ins_ext_p (operands[0], operands[1], operands[2]))
3002 if (GET_MODE (operands[0]) == DImode)
3003 emit_insn (gen_insvdi (operands[0], operands[1], operands[2],
3006 emit_insn (gen_insvsi (operands[0], operands[1], operands[2],
3014 (define_insn "insv<mode>"
3015 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
3016 (match_operand:SI 1 "immediate_operand" "I")
3017 (match_operand:SI 2 "immediate_operand" "I"))
3018 (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
3019 "mips_use_ins_ext_p (operands[0], operands[1], operands[2])"
3020 "<d>ins\t%0,%z3,%2,%1"
3021 [(set_attr "type" "arith")
3022 (set_attr "mode" "<MODE>")])
3024 ;; Unaligned word moves generated by the bit field patterns.
3026 ;; As far as the rtl is concerned, both the left-part and right-part
3027 ;; instructions can access the whole field. However, the real operand
3028 ;; refers to just the first or the last byte (depending on endianness).
3029 ;; We therefore use two memory operands to each instruction, one to
3030 ;; describe the rtl effect and one to use in the assembly output.
3032 ;; Operands 0 and 1 are the rtl-level target and source respectively.
3033 ;; This allows us to use the standard length calculations for the "load"
3034 ;; and "store" type attributes.
3036 (define_insn "mov_<load>l"
3037 [(set (match_operand:GPR 0 "register_operand" "=d")
3038 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3039 (match_operand:QI 2 "memory_operand" "m")]
3041 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3043 [(set_attr "type" "load")
3044 (set_attr "mode" "<MODE>")])
3046 (define_insn "mov_<load>r"
3047 [(set (match_operand:GPR 0 "register_operand" "=d")
3048 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3049 (match_operand:QI 2 "memory_operand" "m")
3050 (match_operand:GPR 3 "register_operand" "0")]
3051 UNSPEC_LOAD_RIGHT))]
3052 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3054 [(set_attr "type" "load")
3055 (set_attr "mode" "<MODE>")])
3057 (define_insn "mov_<store>l"
3058 [(set (match_operand:BLK 0 "memory_operand" "=m")
3059 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3060 (match_operand:QI 2 "memory_operand" "m")]
3061 UNSPEC_STORE_LEFT))]
3062 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3064 [(set_attr "type" "store")
3065 (set_attr "mode" "<MODE>")])
3067 (define_insn "mov_<store>r"
3068 [(set (match_operand:BLK 0 "memory_operand" "+m")
3069 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3070 (match_operand:QI 2 "memory_operand" "m")
3072 UNSPEC_STORE_RIGHT))]
3073 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3075 [(set_attr "type" "store")
3076 (set_attr "mode" "<MODE>")])
3078 ;; An instruction to calculate the high part of a 64-bit SYMBOL_GENERAL.
3079 ;; The required value is:
3081 ;; (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
3083 ;; which translates to:
3085 ;; lui op0,%highest(op1)
3086 ;; daddiu op0,op0,%higher(op1)
3088 ;; daddiu op0,op0,%hi(op1)
3091 ;; The split is deferred until after flow2 to allow the peephole2 below
3093 (define_insn_and_split "*lea_high64"
3094 [(set (match_operand:DI 0 "register_operand" "=d")
3095 (high:DI (match_operand:DI 1 "general_symbolic_operand" "")))]
3096 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3098 "&& epilogue_completed"
3099 [(set (match_dup 0) (high:DI (match_dup 2)))
3100 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
3101 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
3102 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3103 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
3105 operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3106 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
3108 [(set_attr "length" "20")])
3110 ;; Use a scratch register to reduce the latency of the above pattern
3111 ;; on superscalar machines. The optimized sequence is:
3113 ;; lui op1,%highest(op2)
3115 ;; daddiu op1,op1,%higher(op2)
3117 ;; daddu op1,op1,op0
3119 [(set (match_operand:DI 1 "register_operand")
3120 (high:DI (match_operand:DI 2 "general_symbolic_operand")))
3121 (match_scratch:DI 0 "d")]
3122 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3123 [(set (match_dup 1) (high:DI (match_dup 3)))
3124 (set (match_dup 0) (high:DI (match_dup 4)))
3125 (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
3126 (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
3127 (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
3129 operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
3130 operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
3133 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
3134 ;; SYMBOL_GENERAL X will take 6 cycles. This next pattern allows combine
3135 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
3136 ;; used once. We can then use the sequence:
3138 ;; lui op0,%highest(op1)
3140 ;; daddiu op0,op0,%higher(op1)
3141 ;; daddiu op2,op2,%lo(op1)
3143 ;; daddu op0,op0,op2
3145 ;; which takes 4 cycles on most superscalar targets.
3146 (define_insn_and_split "*lea64"
3147 [(set (match_operand:DI 0 "register_operand" "=d")
3148 (match_operand:DI 1 "general_symbolic_operand" ""))
3149 (clobber (match_scratch:DI 2 "=&d"))]
3150 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS && cse_not_expected"
3152 "&& reload_completed"
3153 [(set (match_dup 0) (high:DI (match_dup 3)))
3154 (set (match_dup 2) (high:DI (match_dup 4)))
3155 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3156 (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
3157 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
3158 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
3160 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3161 operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
3163 [(set_attr "length" "24")])
3165 ;; Insns to fetch a symbol from a big GOT.
3167 (define_insn_and_split "*xgot_hi<mode>"
3168 [(set (match_operand:P 0 "register_operand" "=d")
3169 (high:P (match_operand:P 1 "got_disp_operand" "")))]
3170 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
3172 "&& reload_completed"
3173 [(set (match_dup 0) (high:P (match_dup 2)))
3174 (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
3176 operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
3177 operands[3] = pic_offset_table_rtx;
3179 [(set_attr "got" "xgot_high")
3180 (set_attr "mode" "<MODE>")])
3182 (define_insn_and_split "*xgot_lo<mode>"
3183 [(set (match_operand:P 0 "register_operand" "=d")
3184 (lo_sum:P (match_operand:P 1 "register_operand" "d")
3185 (match_operand:P 2 "got_disp_operand" "")))]
3186 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
3188 "&& reload_completed"
3190 (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
3191 { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
3192 [(set_attr "got" "load")
3193 (set_attr "mode" "<MODE>")])
3195 ;; Insns to fetch a symbol from a normal GOT.
3197 (define_insn_and_split "*got_disp<mode>"
3198 [(set (match_operand:P 0 "register_operand" "=d")
3199 (match_operand:P 1 "got_disp_operand" ""))]
3200 "TARGET_EXPLICIT_RELOCS && !TARGET_XGOT"
3202 "&& reload_completed"
3204 (unspec:P [(match_dup 2) (match_dup 3)] UNSPEC_LOAD_GOT))]
3206 operands[2] = pic_offset_table_rtx;
3207 operands[3] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
3209 [(set_attr "got" "load")
3210 (set_attr "mode" "<MODE>")])
3212 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
3214 (define_insn_and_split "*got_page<mode>"
3215 [(set (match_operand:P 0 "register_operand" "=d")
3216 (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
3217 "TARGET_EXPLICIT_RELOCS"
3219 "&& reload_completed"
3221 (unspec:P [(match_dup 2) (match_dup 3)] UNSPEC_LOAD_GOT))]
3223 operands[2] = pic_offset_table_rtx;
3224 operands[3] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_PAGE);
3226 [(set_attr "got" "load")
3227 (set_attr "mode" "<MODE>")])
3229 ;; Lower-level instructions for loading an address from the GOT.
3230 ;; We could use MEMs, but an unspec gives more optimization
3233 (define_insn "load_got<mode>"
3234 [(set (match_operand:P 0 "register_operand" "=d")
3235 (unspec:P [(match_operand:P 1 "register_operand" "d")
3236 (match_operand:P 2 "immediate_operand" "")]
3239 "<load>\t%0,%R2(%1)"
3240 [(set_attr "type" "load")
3241 (set_attr "mode" "<MODE>")
3242 (set_attr "length" "4")])
3244 ;; Instructions for adding the low 16 bits of an address to a register.
3245 ;; Operand 2 is the address: print_operand works out which relocation
3246 ;; should be applied.
3248 (define_insn "*low<mode>"
3249 [(set (match_operand:P 0 "register_operand" "=d")
3250 (lo_sum:P (match_operand:P 1 "register_operand" "d")
3251 (match_operand:P 2 "immediate_operand" "")))]
3253 "<d>addiu\t%0,%1,%R2"
3254 [(set_attr "type" "arith")
3255 (set_attr "mode" "<MODE>")])
3257 (define_insn "*low<mode>_mips16"
3258 [(set (match_operand:P 0 "register_operand" "=d")
3259 (lo_sum:P (match_operand:P 1 "register_operand" "0")
3260 (match_operand:P 2 "immediate_operand" "")))]
3263 [(set_attr "type" "arith")
3264 (set_attr "mode" "<MODE>")
3265 (set_attr "length" "8")])
3267 ;; Allow combine to split complex const_int load sequences, using operand 2
3268 ;; to store the intermediate results. See move_operand for details.
3270 [(set (match_operand:GPR 0 "register_operand")
3271 (match_operand:GPR 1 "splittable_const_int_operand"))
3272 (clobber (match_operand:GPR 2 "register_operand"))]
3276 mips_move_integer (operands[0], operands[2], INTVAL (operands[1]));
3280 ;; Likewise, for symbolic operands.
3282 [(set (match_operand:P 0 "register_operand")
3283 (match_operand:P 1 "splittable_symbolic_operand"))
3284 (clobber (match_operand:P 2 "register_operand"))]
3286 [(set (match_dup 0) (match_dup 1))]
3287 { operands[1] = mips_split_symbol (operands[2], operands[1]); })
3289 ;; 64-bit integer moves
3291 ;; Unlike most other insns, the move insns can't be split with
3292 ;; different predicates, because register spilling and other parts of
3293 ;; the compiler, have memoized the insn number already.
3295 (define_expand "movdi"
3296 [(set (match_operand:DI 0 "")
3297 (match_operand:DI 1 ""))]
3300 if (mips_legitimize_move (DImode, operands[0], operands[1]))
3304 ;; For mips16, we need a special case to handle storing $31 into
3305 ;; memory, since we don't have a constraint to match $31. This
3306 ;; instruction can be generated by save_restore_insns.
3308 (define_insn "*mov<mode>_ra"
3309 [(set (match_operand:GPR 0 "stack_operand" "=m")
3313 [(set_attr "type" "store")
3314 (set_attr "mode" "<MODE>")])
3316 (define_insn "*movdi_32bit"
3317 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d,*B*C*D,*B*C*D,*d,*m")
3318 (match_operand:DI 1 "move_operand" "d,i,m,d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
3319 "!TARGET_64BIT && !TARGET_FLOAT64 && !TARGET_MIPS16
3320 && (register_operand (operands[0], DImode)
3321 || reg_or_0_operand (operands[1], DImode))"
3322 { return mips_output_move (operands[0], operands[1]); }
3323 [(set_attr "type" "arith,arith,load,store,mthilo,mfhilo,mtc,load,mfc,store")
3324 (set_attr "mode" "DI")
3325 (set_attr "length" "8,16,*,*,8,8,8,*,8,*")])
3327 (define_insn "*movdi_gp32_fp64"
3328 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d,*f,*f,*f,*d,*m")
3329 (match_operand:DI 1 "move_operand" "d,i,m,d,*J*d,*a,*f,*J*d,*m,*f,*f"))]
3330 "!TARGET_64BIT && TARGET_FLOAT64 && !TARGET_MIPS16
3331 && (register_operand (operands[0], DImode)
3332 || reg_or_0_operand (operands[1], DImode))"
3333 { return mips_output_move (operands[0], operands[1]); }
3334 [(set_attr "type" "arith,arith,load,store,mthilo,mfhilo,fmove,mtc,fpload,mfc,fpstore")
3335 (set_attr "mode" "DI")
3336 (set_attr "length" "8,16,*,*,8,8,4,8,*,8,*")])
3338 (define_insn "*movdi_32bit_mips16"
3339 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
3340 (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
3341 "!TARGET_64BIT && TARGET_MIPS16
3342 && (register_operand (operands[0], DImode)
3343 || register_operand (operands[1], DImode))"
3344 { return mips_output_move (operands[0], operands[1]); }
3345 [(set_attr "type" "arith,arith,arith,arith,arith,load,store,mfhilo")
3346 (set_attr "mode" "DI")
3347 (set_attr "length" "8,8,8,8,12,*,*,8")])
3349 (define_insn "*movdi_64bit"
3350 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*f,*d,*m,*x,*B*C*D,*B*C*D,*d,*m")
3351 (match_operand:DI 1 "move_operand" "d,U,T,m,dJ,*f,*d*J,*m,*f,*f,*J*d,*d,*m,*B*C*D,*B*C*D"))]
3352 "TARGET_64BIT && !TARGET_MIPS16
3353 && (register_operand (operands[0], DImode)
3354 || reg_or_0_operand (operands[1], DImode))"
3355 { return mips_output_move (operands[0], operands[1]); }
3356 [(set_attr "type" "arith,const,const,load,store,fmove,mtc,fpload,mfc,fpstore,mthilo,mtc,load,mfc,store")
3357 (set_attr "mode" "DI")
3358 (set_attr "length" "4,*,*,*,*,4,4,*,4,*,4,8,*,8,*")])
3360 (define_insn "*movdi_64bit_mips16"
3361 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,m")
3362 (match_operand:DI 1 "move_operand" "d,d,y,K,N,U,m,d"))]
3363 "TARGET_64BIT && TARGET_MIPS16
3364 && (register_operand (operands[0], DImode)
3365 || register_operand (operands[1], DImode))"
3366 { return mips_output_move (operands[0], operands[1]); }
3367 [(set_attr "type" "arith,arith,arith,arith,arith,const,load,store")
3368 (set_attr "mode" "DI")
3369 (set_attr_alternative "length"
3373 (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3376 (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3381 (const_string "*")])])
3384 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
3385 ;; when the original load is a 4 byte instruction but the add and the
3386 ;; load are 2 2 byte instructions.
3389 [(set (match_operand:DI 0 "register_operand")
3390 (mem:DI (plus:DI (match_dup 0)
3391 (match_operand:DI 1 "const_int_operand"))))]
3392 "TARGET_64BIT && TARGET_MIPS16 && reload_completed
3393 && !TARGET_DEBUG_D_MODE
3394 && REG_P (operands[0])
3395 && M16_REG_P (REGNO (operands[0]))
3396 && GET_CODE (operands[1]) == CONST_INT
3397 && ((INTVAL (operands[1]) < 0
3398 && INTVAL (operands[1]) >= -0x10)
3399 || (INTVAL (operands[1]) >= 32 * 8
3400 && INTVAL (operands[1]) <= 31 * 8 + 0x8)
3401 || (INTVAL (operands[1]) >= 0
3402 && INTVAL (operands[1]) < 32 * 8
3403 && (INTVAL (operands[1]) & 7) != 0))"
3404 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
3405 (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
3407 HOST_WIDE_INT val = INTVAL (operands[1]);
3410 operands[2] = const0_rtx;
3411 else if (val >= 32 * 8)
3415 operands[1] = GEN_INT (0x8 + off);
3416 operands[2] = GEN_INT (val - off - 0x8);
3422 operands[1] = GEN_INT (off);
3423 operands[2] = GEN_INT (val - off);
3427 ;; 32-bit Integer moves
3429 ;; Unlike most other insns, the move insns can't be split with
3430 ;; different predicates, because register spilling and other parts of
3431 ;; the compiler, have memoized the insn number already.
3433 (define_expand "movsi"
3434 [(set (match_operand:SI 0 "")
3435 (match_operand:SI 1 ""))]
3438 if (mips_legitimize_move (SImode, operands[0], operands[1]))
3442 ;; The difference between these two is whether or not ints are allowed
3443 ;; in FP registers (off by default, use -mdebugh to enable).
3445 (define_insn "*movsi_internal"
3446 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*f,*d,*m,*d,*z,*a,*d,*B*C*D,*B*C*D,*d,*m")
3447 (match_operand:SI 1 "move_operand" "d,U,T,m,dJ,*f,*d*J,*m,*f,*f,*z,*d,*J*d,*A,*d,*m,*B*C*D,*B*C*D"))]
3449 && (register_operand (operands[0], SImode)
3450 || reg_or_0_operand (operands[1], SImode))"
3451 { return mips_output_move (operands[0], operands[1]); }
3452 [(set_attr "type" "arith,const,const,load,store,fmove,mtc,fpload,mfc,fpstore,mfc,mtc,mthilo,mfhilo,mtc,load,mfc,store")
3453 (set_attr "mode" "SI")
3454 (set_attr "length" "4,*,*,*,*,4,4,*,4,*,4,4,4,4,4,*,4,*")])
3456 (define_insn "*movsi_mips16"
3457 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,m")
3458 (match_operand:SI 1 "move_operand" "d,d,y,K,N,U,m,d"))]
3460 && (register_operand (operands[0], SImode)
3461 || register_operand (operands[1], SImode))"
3462 { return mips_output_move (operands[0], operands[1]); }
3463 [(set_attr "type" "arith,arith,arith,arith,arith,const,load,store")
3464 (set_attr "mode" "SI")
3465 (set_attr_alternative "length"
3469 (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3472 (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3477 (const_string "*")])])
3479 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
3480 ;; when the original load is a 4 byte instruction but the add and the
3481 ;; load are 2 2 byte instructions.
3484 [(set (match_operand:SI 0 "register_operand")
3485 (mem:SI (plus:SI (match_dup 0)
3486 (match_operand:SI 1 "const_int_operand"))))]
3487 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3488 && REG_P (operands[0])
3489 && M16_REG_P (REGNO (operands[0]))
3490 && GET_CODE (operands[1]) == CONST_INT
3491 && ((INTVAL (operands[1]) < 0
3492 && INTVAL (operands[1]) >= -0x80)
3493 || (INTVAL (operands[1]) >= 32 * 4
3494 && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
3495 || (INTVAL (operands[1]) >= 0
3496 && INTVAL (operands[1]) < 32 * 4
3497 && (INTVAL (operands[1]) & 3) != 0))"
3498 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3499 (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
3501 HOST_WIDE_INT val = INTVAL (operands[1]);
3504 operands[2] = const0_rtx;
3505 else if (val >= 32 * 4)
3509 operands[1] = GEN_INT (0x7c + off);
3510 operands[2] = GEN_INT (val - off - 0x7c);
3516 operands[1] = GEN_INT (off);
3517 operands[2] = GEN_INT (val - off);
3521 ;; On the mips16, we can split a load of certain constants into a load
3522 ;; and an add. This turns a 4 byte instruction into 2 2 byte
3526 [(set (match_operand:SI 0 "register_operand")
3527 (match_operand:SI 1 "const_int_operand"))]
3528 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3529 && REG_P (operands[0])
3530 && M16_REG_P (REGNO (operands[0]))
3531 && GET_CODE (operands[1]) == CONST_INT
3532 && INTVAL (operands[1]) >= 0x100
3533 && INTVAL (operands[1]) <= 0xff + 0x7f"
3534 [(set (match_dup 0) (match_dup 1))
3535 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
3537 int val = INTVAL (operands[1]);
3539 operands[1] = GEN_INT (0xff);
3540 operands[2] = GEN_INT (val - 0xff);
3543 ;; This insn handles moving CCmode values. It's really just a
3544 ;; slightly simplified copy of movsi_internal2, with additional cases
3545 ;; to move a condition register to a general register and to move
3546 ;; between the general registers and the floating point registers.
3548 (define_insn "movcc"
3549 [(set (match_operand:CC 0 "nonimmediate_operand" "=d,*d,*d,*m,*d,*f,*f,*f,*m")
3550 (match_operand:CC 1 "general_operand" "z,*d,*m,*d,*f,*d,*f,*m,*f"))]
3551 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3552 { return mips_output_move (operands[0], operands[1]); }
3553 [(set_attr "type" "multi,arith,load,store,mfc,mtc,fmove,fpload,fpstore")
3554 (set_attr "mode" "SI")
3555 (set_attr "length" "8,4,*,*,4,4,4,*,*")])
3557 ;; Reload condition code registers. reload_incc and reload_outcc
3558 ;; both handle moves from arbitrary operands into condition code
3559 ;; registers. reload_incc handles the more common case in which
3560 ;; a source operand is constrained to be in a condition-code
3561 ;; register, but has not been allocated to one.
3563 ;; Sometimes, such as in movcc, we have a CCmode destination whose
3564 ;; constraints do not include 'z'. reload_outcc handles the case
3565 ;; when such an operand is allocated to a condition-code register.
3567 ;; Note that reloads from a condition code register to some
3568 ;; other location can be done using ordinary moves. Moving
3569 ;; into a GPR takes a single movcc, moving elsewhere takes
3570 ;; two. We can leave these cases to the generic reload code.
3571 (define_expand "reload_incc"
3572 [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
3573 (match_operand:CC 1 "general_operand" ""))
3574 (clobber (match_operand:TF 2 "register_operand" "=&f"))]
3575 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3577 mips_emit_fcc_reload (operands[0], operands[1], operands[2]);
3581 (define_expand "reload_outcc"
3582 [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
3583 (match_operand:CC 1 "register_operand" ""))
3584 (clobber (match_operand:TF 2 "register_operand" "=&f"))]
3585 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3587 mips_emit_fcc_reload (operands[0], operands[1], operands[2]);
3591 ;; MIPS4 supports loading and storing a floating point register from
3592 ;; the sum of two general registers. We use two versions for each of
3593 ;; these four instructions: one where the two general registers are
3594 ;; SImode, and one where they are DImode. This is because general
3595 ;; registers will be in SImode when they hold 32-bit values, but,
3596 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
3597 ;; instructions will still work correctly.
3599 ;; ??? Perhaps it would be better to support these instructions by
3600 ;; modifying GO_IF_LEGITIMATE_ADDRESS and friends. However, since
3601 ;; these instructions can only be used to load and store floating
3602 ;; point registers, that would probably cause trouble in reload.
3604 (define_insn "*<ANYF:loadx>_<P:mode>"
3605 [(set (match_operand:ANYF 0 "register_operand" "=f")
3606 (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
3607 (match_operand:P 2 "register_operand" "d"))))]
3609 "<ANYF:loadx>\t%0,%1(%2)"
3610 [(set_attr "type" "fpidxload")
3611 (set_attr "mode" "<ANYF:UNITMODE>")])
3613 (define_insn "*<ANYF:storex>_<P:mode>"
3614 [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
3615 (match_operand:P 2 "register_operand" "d")))
3616 (match_operand:ANYF 0 "register_operand" "f"))]
3618 "<ANYF:storex>\t%0,%1(%2)"
3619 [(set_attr "type" "fpidxstore")
3620 (set_attr "mode" "<ANYF:UNITMODE>")])
3622 ;; 16-bit Integer moves
3624 ;; Unlike most other insns, the move insns can't be split with
3625 ;; different predicates, because register spilling and other parts of
3626 ;; the compiler, have memoized the insn number already.
3627 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
3629 (define_expand "movhi"
3630 [(set (match_operand:HI 0 "")
3631 (match_operand:HI 1 ""))]
3634 if (mips_legitimize_move (HImode, operands[0], operands[1]))
3638 (define_insn "*movhi_internal"
3639 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,m,*d,*f,*f,*x")
3640 (match_operand:HI 1 "move_operand" "d,I,m,dJ,*f,*d,*f,*d"))]
3642 && (register_operand (operands[0], HImode)
3643 || reg_or_0_operand (operands[1], HImode))"
3653 [(set_attr "type" "arith,arith,load,store,mfc,mtc,fmove,mthilo")
3654 (set_attr "mode" "HI")
3655 (set_attr "length" "4,4,*,*,4,4,4,4")])
3657 (define_insn "*movhi_mips16"
3658 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m")
3659 (match_operand:HI 1 "move_operand" "d,d,y,K,N,m,d"))]
3661 && (register_operand (operands[0], HImode)
3662 || register_operand (operands[1], HImode))"
3671 [(set_attr "type" "arith,arith,arith,arith,arith,load,store")
3672 (set_attr "mode" "HI")
3673 (set_attr_alternative "length"
3677 (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3680 (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3684 (const_string "*")])])
3687 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
3688 ;; when the original load is a 4 byte instruction but the add and the
3689 ;; load are 2 2 byte instructions.
3692 [(set (match_operand:HI 0 "register_operand")
3693 (mem:HI (plus:SI (match_dup 0)
3694 (match_operand:SI 1 "const_int_operand"))))]
3695 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3696 && REG_P (operands[0])
3697 && M16_REG_P (REGNO (operands[0]))
3698 && GET_CODE (operands[1]) == CONST_INT
3699 && ((INTVAL (operands[1]) < 0
3700 && INTVAL (operands[1]) >= -0x80)
3701 || (INTVAL (operands[1]) >= 32 * 2
3702 && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
3703 || (INTVAL (operands[1]) >= 0
3704 && INTVAL (operands[1]) < 32 * 2
3705 && (INTVAL (operands[1]) & 1) != 0))"
3706 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3707 (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
3709 HOST_WIDE_INT val = INTVAL (operands[1]);
3712 operands[2] = const0_rtx;
3713 else if (val >= 32 * 2)
3717 operands[1] = GEN_INT (0x7e + off);
3718 operands[2] = GEN_INT (val - off - 0x7e);
3724 operands[1] = GEN_INT (off);
3725 operands[2] = GEN_INT (val - off);
3729 ;; 8-bit Integer moves
3731 ;; Unlike most other insns, the move insns can't be split with
3732 ;; different predicates, because register spilling and other parts of
3733 ;; the compiler, have memoized the insn number already.
3734 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
3736 (define_expand "movqi"
3737 [(set (match_operand:QI 0 "")
3738 (match_operand:QI 1 ""))]
3741 if (mips_legitimize_move (QImode, operands[0], operands[1]))
3745 (define_insn "*movqi_internal"
3746 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,m,*d,*f,*f,*x")
3747 (match_operand:QI 1 "move_operand" "d,I,m,dJ,*f,*d,*f,*d"))]
3749 && (register_operand (operands[0], QImode)
3750 || reg_or_0_operand (operands[1], QImode))"
3760 [(set_attr "type" "arith,arith,load,store,mfc,mtc,fmove,mthilo")
3761 (set_attr "mode" "QI")
3762 (set_attr "length" "4,4,*,*,4,4,4,4")])
3764 (define_insn "*movqi_mips16"
3765 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m")
3766 (match_operand:QI 1 "move_operand" "d,d,y,K,N,m,d"))]
3768 && (register_operand (operands[0], QImode)
3769 || register_operand (operands[1], QImode))"
3778 [(set_attr "type" "arith,arith,arith,arith,arith,load,store")
3779 (set_attr "mode" "QI")
3780 (set_attr "length" "4,4,4,4,8,*,*")])
3782 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
3783 ;; when the original load is a 4 byte instruction but the add and the
3784 ;; load are 2 2 byte instructions.
3787 [(set (match_operand:QI 0 "register_operand")
3788 (mem:QI (plus:SI (match_dup 0)
3789 (match_operand:SI 1 "const_int_operand"))))]
3790 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3791 && REG_P (operands[0])
3792 && M16_REG_P (REGNO (operands[0]))
3793 && GET_CODE (operands[1]) == CONST_INT
3794 && ((INTVAL (operands[1]) < 0
3795 && INTVAL (operands[1]) >= -0x80)
3796 || (INTVAL (operands[1]) >= 32
3797 && INTVAL (operands[1]) <= 31 + 0x7f))"
3798 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3799 (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
3801 HOST_WIDE_INT val = INTVAL (operands[1]);
3804 operands[2] = const0_rtx;
3807 operands[1] = GEN_INT (0x7f);
3808 operands[2] = GEN_INT (val - 0x7f);
3812 ;; 32-bit floating point moves
3814 (define_expand "movsf"
3815 [(set (match_operand:SF 0 "")
3816 (match_operand:SF 1 ""))]
3819 if (mips_legitimize_move (SFmode, operands[0], operands[1]))
3823 (define_insn "*movsf_hardfloat"
3824 [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3825 (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
3827 && (register_operand (operands[0], SFmode)
3828 || reg_or_0_operand (operands[1], SFmode))"
3829 { return mips_output_move (operands[0], operands[1]); }
3830 [(set_attr "type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,arith,load,store")
3831 (set_attr "mode" "SF")
3832 (set_attr "length" "4,4,*,*,*,4,4,4,*,*")])
3834 (define_insn "*movsf_softfloat"
3835 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
3836 (match_operand:SF 1 "move_operand" "Gd,m,d"))]
3837 "TARGET_SOFT_FLOAT && !TARGET_MIPS16
3838 && (register_operand (operands[0], SFmode)
3839 || reg_or_0_operand (operands[1], SFmode))"
3840 { return mips_output_move (operands[0], operands[1]); }
3841 [(set_attr "type" "arith,load,store")
3842 (set_attr "mode" "SF")
3843 (set_attr "length" "4,*,*")])
3845 (define_insn "*movsf_mips16"
3846 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
3847 (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
3849 && (register_operand (operands[0], SFmode)
3850 || register_operand (operands[1], SFmode))"
3851 { return mips_output_move (operands[0], operands[1]); }
3852 [(set_attr "type" "arith,arith,arith,load,store")
3853 (set_attr "mode" "SF")
3854 (set_attr "length" "4,4,4,*,*")])
3857 ;; 64-bit floating point moves
3859 (define_expand "movdf"
3860 [(set (match_operand:DF 0 "")
3861 (match_operand:DF 1 ""))]
3864 if (mips_legitimize_move (DFmode, operands[0], operands[1]))
3868 (define_insn "*movdf_hardfloat_64bit"
3869 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3870 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
3871 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_64BIT
3872 && (register_operand (operands[0], DFmode)
3873 || reg_or_0_operand (operands[1], DFmode))"
3874 { return mips_output_move (operands[0], operands[1]); }
3875 [(set_attr "type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,arith,load,store")
3876 (set_attr "mode" "DF")
3877 (set_attr "length" "4,4,*,*,*,4,4,4,*,*")])
3879 ;; This pattern applies to both !TARGET_FLOAT64 and TARGET_FLOAT64.
3880 (define_insn "*movdf_hardfloat_32bit"
3881 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3882 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
3883 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT
3884 && (register_operand (operands[0], DFmode)
3885 || reg_or_0_operand (operands[1], DFmode))"
3886 { return mips_output_move (operands[0], operands[1]); }
3887 [(set_attr "type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,arith,load,store")
3888 (set_attr "mode" "DF")
3889 (set_attr "length" "4,8,*,*,*,8,8,8,*,*")])
3891 (define_insn "*movdf_softfloat"
3892 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m,d,f,f")
3893 (match_operand:DF 1 "move_operand" "dG,m,dG,f,d,f"))]
3894 "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
3895 && (register_operand (operands[0], DFmode)
3896 || reg_or_0_operand (operands[1], DFmode))"
3897 { return mips_output_move (operands[0], operands[1]); }
3898 [(set_attr "type" "arith,load,store,mfc,mtc,fmove")
3899 (set_attr "mode" "DF")
3900 (set_attr "length" "8,*,*,4,4,4")])
3902 (define_insn "*movdf_mips16"
3903 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
3904 (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
3906 && (register_operand (operands[0], DFmode)
3907 || register_operand (operands[1], DFmode))"
3908 { return mips_output_move (operands[0], operands[1]); }
3909 [(set_attr "type" "arith,arith,arith,load,store")
3910 (set_attr "mode" "DF")
3911 (set_attr "length" "8,8,8,*,*")])
3914 [(set (match_operand:DI 0 "nonimmediate_operand")
3915 (match_operand:DI 1 "move_operand"))]
3916 "reload_completed && !TARGET_64BIT
3917 && mips_split_64bit_move_p (operands[0], operands[1])"
3920 mips_split_64bit_move (operands[0], operands[1]);
3925 [(set (match_operand:DF 0 "nonimmediate_operand")
3926 (match_operand:DF 1 "move_operand"))]
3927 "reload_completed && !TARGET_64BIT
3928 && mips_split_64bit_move_p (operands[0], operands[1])"
3931 mips_split_64bit_move (operands[0], operands[1]);
3935 ;; When generating mips16 code, split moves of negative constants into
3936 ;; a positive "li" followed by a negation.
3938 [(set (match_operand 0 "register_operand")
3939 (match_operand 1 "const_int_operand"))]
3940 "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
3944 (neg:SI (match_dup 2)))]
3946 operands[2] = gen_lowpart (SImode, operands[0]);
3947 operands[3] = GEN_INT (-INTVAL (operands[1]));
3950 ;; 64-bit paired-single floating point moves
3952 (define_expand "movv2sf"
3953 [(set (match_operand:V2SF 0)
3954 (match_operand:V2SF 1))]
3955 "TARGET_PAIRED_SINGLE_FLOAT"
3957 if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
3961 (define_insn "movv2sf_hardfloat_64bit"
3962 [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3963 (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
3964 "TARGET_PAIRED_SINGLE_FLOAT
3966 && (register_operand (operands[0], V2SFmode)
3967 || reg_or_0_operand (operands[1], V2SFmode))"
3968 { return mips_output_move (operands[0], operands[1]); }
3969 [(set_attr "type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,arith,load,store")
3970 (set_attr "mode" "SF")
3971 (set_attr "length" "4,4,*,*,*,4,4,4,*,*")])
3973 ;; The HI and LO registers are not truly independent. If we move an mthi
3974 ;; instruction before an mflo instruction, it will make the result of the
3975 ;; mflo unpredictable. The same goes for mtlo and mfhi.
3977 ;; We cope with this by making the mflo and mfhi patterns use both HI and LO.
3978 ;; Operand 1 is the register we want, operand 2 is the other one.
3980 ;; When generating VR4120 or VR4130 code, we use macc{,hi} and
3981 ;; dmacc{,hi} instead of mfhi and mflo. This avoids both the normal
3982 ;; MIPS III hi/lo hazards and the errata related to -mfix-vr4130.
3984 (define_expand "mfhilo_<mode>"
3985 [(set (match_operand:GPR 0 "register_operand")
3986 (unspec:GPR [(match_operand:GPR 1 "register_operand")
3987 (match_operand:GPR 2 "register_operand")]
3990 (define_insn "*mfhilo_<mode>"
3991 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3992 (unspec:GPR [(match_operand:GPR 1 "register_operand" "h,l")
3993 (match_operand:GPR 2 "register_operand" "l,h")]
3997 [(set_attr "type" "mfhilo")
3998 (set_attr "mode" "<MODE>")])
4000 (define_insn "*mfhilo_<mode>_macc"
4001 [(set (match_operand:GPR 0 "register_operand" "=d,d")
4002 (unspec:GPR [(match_operand:GPR 1 "register_operand" "h,l")
4003 (match_operand:GPR 2 "register_operand" "l,h")]
4007 if (REGNO (operands[1]) == HI_REGNUM)
4008 return "<d>macchi\t%0,%.,%.";
4010 return "<d>macc\t%0,%.,%.";
4012 [(set_attr "type" "mfhilo")
4013 (set_attr "mode" "<MODE>")])
4015 ;; Patterns for loading or storing part of a paired floating point
4016 ;; register. We need them because odd-numbered floating-point registers
4017 ;; are not fully independent: see mips_split_64bit_move.
4019 ;; Load the low word of operand 0 with operand 1.
4020 (define_insn "load_df_low"
4021 [(set (match_operand:DF 0 "register_operand" "=f,f")
4022 (unspec:DF [(match_operand:SI 1 "general_operand" "dJ,m")]
4023 UNSPEC_LOAD_DF_LOW))]
4024 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
4026 operands[0] = mips_subword (operands[0], 0);
4027 return mips_output_move (operands[0], operands[1]);
4029 [(set_attr "type" "mtc,fpload")
4030 (set_attr "mode" "SF")])
4032 ;; Load the high word of operand 0 from operand 1, preserving the value
4034 (define_insn "load_df_high"
4035 [(set (match_operand:DF 0 "register_operand" "=f,f")
4036 (unspec:DF [(match_operand:SI 1 "general_operand" "dJ,m")
4037 (match_operand:DF 2 "register_operand" "0,0")]
4038 UNSPEC_LOAD_DF_HIGH))]
4039 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
4041 operands[0] = mips_subword (operands[0], 1);
4042 return mips_output_move (operands[0], operands[1]);
4044 [(set_attr "type" "mtc,fpload")
4045 (set_attr "mode" "SF")])
4047 ;; Store the high word of operand 1 in operand 0. The corresponding
4048 ;; low-word move is done in the normal way.
4049 (define_insn "store_df_high"
4050 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
4051 (unspec:SI [(match_operand:DF 1 "register_operand" "f,f")]
4052 UNSPEC_STORE_DF_HIGH))]
4053 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
4055 operands[1] = mips_subword (operands[1], 1);
4056 return mips_output_move (operands[0], operands[1]);
4058 [(set_attr "type" "mfc,fpstore")
4059 (set_attr "mode" "SF")])
4061 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
4062 ;; value in the low word.
4063 (define_insn "mthc1"
4064 [(set (match_operand:DF 0 "register_operand" "=f")
4065 (unspec:DF [(match_operand:SI 1 "general_operand" "dJ")
4066 (match_operand:DF 2 "register_operand" "0")]
4068 "TARGET_HARD_FLOAT && !TARGET_64BIT && ISA_HAS_MXHC1"
4070 [(set_attr "type" "mtc")
4071 (set_attr "mode" "SF")])
4073 ;; Move high word of operand 1 to operand 0 using mfhc1. The corresponding
4074 ;; low-word move is done in the normal way.
4075 (define_insn "mfhc1"
4076 [(set (match_operand:SI 0 "register_operand" "=d")
4077 (unspec:SI [(match_operand:DF 1 "register_operand" "f")]
4079 "TARGET_HARD_FLOAT && !TARGET_64BIT && ISA_HAS_MXHC1"
4081 [(set_attr "type" "mfc")
4082 (set_attr "mode" "SF")])
4084 ;; Move a constant that satisfies CONST_GP_P into operand 0.
4085 (define_expand "load_const_gp"
4086 [(set (match_operand 0 "register_operand" "=d")
4087 (const (unspec [(const_int 0)] UNSPEC_GP)))])
4089 ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset
4090 ;; of _gp from the start of this function. Operand 1 is the incoming
4091 ;; function address.
4092 (define_insn_and_split "loadgp_newabi"
4093 [(unspec_volatile [(match_operand 0 "" "")
4094 (match_operand 1 "register_operand" "")] UNSPEC_LOADGP)]
4095 "mips_current_loadgp_style () == LOADGP_NEWABI"
4098 [(set (match_dup 2) (match_dup 3))
4099 (set (match_dup 2) (match_dup 4))
4100 (set (match_dup 2) (match_dup 5))]
4102 operands[2] = pic_offset_table_rtx;
4103 operands[3] = gen_rtx_HIGH (Pmode, operands[0]);
4104 operands[4] = gen_rtx_PLUS (Pmode, operands[2], operands[1]);
4105 operands[5] = gen_rtx_LO_SUM (Pmode, operands[2], operands[0]);
4107 [(set_attr "length" "12")])
4109 ;; Likewise, for -mno-shared code. Operand 0 is the __gnu_local_gp symbol.
4110 (define_insn_and_split "loadgp_absolute"
4111 [(unspec_volatile [(match_operand 0 "" "")] UNSPEC_LOADGP)]
4112 "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
4117 emit_move_insn (pic_offset_table_rtx, operands[0]);
4120 [(set_attr "length" "8")])
4122 ;; The use of gp is hidden when not using explicit relocations.
4123 ;; This blockage instruction prevents the gp load from being
4124 ;; scheduled after an implicit use of gp. It also prevents
4125 ;; the load from being deleted as dead.
4126 (define_insn "loadgp_blockage"
4127 [(unspec_volatile [(reg:DI 28)] UNSPEC_BLOCKAGE)]
4130 [(set_attr "type" "unknown")
4131 (set_attr "mode" "none")
4132 (set_attr "length" "0")])
4134 ;; Initialize $gp for RTP PIC. Operand 0 is the __GOTT_BASE__ symbol
4135 ;; and operand 1 is the __GOTT_INDEX__ symbol.
4136 (define_insn "loadgp_rtp"
4137 [(unspec_volatile [(match_operand 0 "symbol_ref_operand")
4138 (match_operand 1 "symbol_ref_operand")] UNSPEC_LOADGP)]
4139 "mips_current_loadgp_style () == LOADGP_RTP"
4141 [(set_attr "length" "12")])
4144 [(unspec_volatile [(match_operand:P 0 "symbol_ref_operand")
4145 (match_operand:P 1 "symbol_ref_operand")] UNSPEC_LOADGP)]
4146 "mips_current_loadgp_style () == LOADGP_RTP"
4147 [(set (match_dup 2) (high:P (match_dup 3)))
4148 (set (match_dup 2) (unspec:P [(match_dup 2)
4149 (match_dup 3)] UNSPEC_LOAD_GOT))
4150 (set (match_dup 2) (unspec:P [(match_dup 2)
4151 (match_dup 4)] UNSPEC_LOAD_GOT))]
4153 operands[2] = pic_offset_table_rtx;
4154 operands[3] = mips_unspec_address (operands[0], SYMBOL_GENERAL);
4155 operands[4] = mips_unspec_address (operands[1], SYMBOL_HALF);
4158 ;; Emit a .cprestore directive, which normally expands to a single store
4159 ;; instruction. Note that we continue to use .cprestore for explicit reloc
4160 ;; code so that jals inside inline asms will work correctly.
4161 (define_insn "cprestore"
4162 [(unspec_volatile [(match_operand 0 "const_int_operand" "I,i")
4167 if (set_nomacro && which_alternative == 1)
4168 return ".set\tmacro\;.cprestore\t%0\;.set\tnomacro";
4170 return ".cprestore\t%0";
4172 [(set_attr "type" "store")
4173 (set_attr "length" "4,12")])
4175 ;; Block moves, see mips.c for more details.
4176 ;; Argument 0 is the destination
4177 ;; Argument 1 is the source
4178 ;; Argument 2 is the length
4179 ;; Argument 3 is the alignment
4181 (define_expand "movmemsi"
4182 [(parallel [(set (match_operand:BLK 0 "general_operand")
4183 (match_operand:BLK 1 "general_operand"))
4184 (use (match_operand:SI 2 ""))
4185 (use (match_operand:SI 3 "const_int_operand"))])]
4186 "!TARGET_MIPS16 && !TARGET_MEMCPY"
4188 if (mips_expand_block_move (operands[0], operands[1], operands[2]))
4195 ;; ....................
4199 ;; ....................
4201 (define_expand "<optab><mode>3"
4202 [(set (match_operand:GPR 0 "register_operand")
4203 (any_shift:GPR (match_operand:GPR 1 "register_operand")
4204 (match_operand:SI 2 "arith_operand")))]
4207 /* On the mips16, a shift of more than 8 is a four byte instruction,
4208 so, for a shift between 8 and 16, it is just as fast to do two
4209 shifts of 8 or less. If there is a lot of shifting going on, we
4210 may win in CSE. Otherwise combine will put the shifts back
4211 together again. This can be called by function_arg, so we must
4212 be careful not to allocate a new register if we've reached the
4216 && GET_CODE (operands[2]) == CONST_INT
4217 && INTVAL (operands[2]) > 8
4218 && INTVAL (operands[2]) <= 16
4219 && !reload_in_progress
4220 && !reload_completed)
4222 rtx temp = gen_reg_rtx (<MODE>mode);
4224 emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
4225 emit_insn (gen_<optab><mode>3 (operands[0], temp,
4226 GEN_INT (INTVAL (operands[2]) - 8)));
4231 (define_insn "*<optab><mode>3"
4232 [(set (match_operand:GPR 0 "register_operand" "=d")
4233 (any_shift:GPR (match_operand:GPR 1 "register_operand" "d")
4234 (match_operand:SI 2 "arith_operand" "dI")))]
4237 if (GET_CODE (operands[2]) == CONST_INT)
4238 operands[2] = GEN_INT (INTVAL (operands[2])
4239 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
4241 return "<d><insn>\t%0,%1,%2";
4243 [(set_attr "type" "shift")
4244 (set_attr "mode" "<MODE>")])
4246 (define_insn "*<optab>si3_extend"
4247 [(set (match_operand:DI 0 "register_operand" "=d")
4249 (any_shift:SI (match_operand:SI 1 "register_operand" "d")
4250 (match_operand:SI 2 "arith_operand" "dI"))))]
4251 "TARGET_64BIT && !TARGET_MIPS16"
4253 if (GET_CODE (operands[2]) == CONST_INT)
4254 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
4256 return "<insn>\t%0,%1,%2";
4258 [(set_attr "type" "shift")
4259 (set_attr "mode" "SI")])
4261 (define_insn "*<optab>si3_mips16"
4262 [(set (match_operand:SI 0 "register_operand" "=d,d")
4263 (any_shift:SI (match_operand:SI 1 "register_operand" "0,d")
4264 (match_operand:SI 2 "arith_operand" "d,I")))]
4267 if (which_alternative == 0)
4268 return "<insn>\t%0,%2";
4270 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
4271 return "<insn>\t%0,%1,%2";
4273 [(set_attr "type" "shift")
4274 (set_attr "mode" "SI")
4275 (set_attr_alternative "length"
4277 (if_then_else (match_operand 2 "m16_uimm3_b")
4281 ;; We need separate DImode MIPS16 patterns because of the irregularity
4283 (define_insn "*ashldi3_mips16"
4284 [(set (match_operand:DI 0 "register_operand" "=d,d")
4285 (ashift:DI (match_operand:DI 1 "register_operand" "0,d")
4286 (match_operand:SI 2 "arith_operand" "d,I")))]
4287 "TARGET_64BIT && TARGET_MIPS16"
4289 if (which_alternative == 0)
4290 return "dsll\t%0,%2";
4292 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
4293 return "dsll\t%0,%1,%2";
4295 [(set_attr "type" "shift")
4296 (set_attr "mode" "DI")
4297 (set_attr_alternative "length"
4299 (if_then_else (match_operand 2 "m16_uimm3_b")
4303 (define_insn "*ashrdi3_mips16"
4304 [(set (match_operand:DI 0 "register_operand" "=d,d")
4305 (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
4306 (match_operand:SI 2 "arith_operand" "d,I")))]
4307 "TARGET_64BIT && TARGET_MIPS16"
4309 if (GET_CODE (operands[2]) == CONST_INT)
4310 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
4312 return "dsra\t%0,%2";
4314 [(set_attr "type" "shift")
4315 (set_attr "mode" "DI")
4316 (set_attr_alternative "length"
4318 (if_then_else (match_operand 2 "m16_uimm3_b")
4322 (define_insn "*lshrdi3_mips16"
4323 [(set (match_operand:DI 0 "register_operand" "=d,d")
4324 (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
4325 (match_operand:SI 2 "arith_operand" "d,I")))]
4326 "TARGET_64BIT && TARGET_MIPS16"
4328 if (GET_CODE (operands[2]) == CONST_INT)
4329 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
4331 return "dsrl\t%0,%2";
4333 [(set_attr "type" "shift")
4334 (set_attr "mode" "DI")
4335 (set_attr_alternative "length"
4337 (if_then_else (match_operand 2 "m16_uimm3_b")
4341 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
4344 [(set (match_operand:GPR 0 "register_operand")
4345 (any_shift:GPR (match_operand:GPR 1 "register_operand")
4346 (match_operand:GPR 2 "const_int_operand")))]
4347 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4348 && GET_CODE (operands[2]) == CONST_INT
4349 && INTVAL (operands[2]) > 8
4350 && INTVAL (operands[2]) <= 16"
4351 [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
4352 (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
4353 { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
4355 ;; If we load a byte on the mips16 as a bitfield, the resulting
4356 ;; sequence of instructions is too complicated for combine, because it
4357 ;; involves four instructions: a load, a shift, a constant load into a
4358 ;; register, and an and (the key problem here is that the mips16 does
4359 ;; not have and immediate). We recognize a shift of a load in order
4360 ;; to make it simple enough for combine to understand.
4362 ;; The length here is the worst case: the length of the split version
4363 ;; will be more accurate.
4364 (define_insn_and_split ""
4365 [(set (match_operand:SI 0 "register_operand" "=d")
4366 (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
4367 (match_operand:SI 2 "immediate_operand" "I")))]
4371 [(set (match_dup 0) (match_dup 1))
4372 (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
4374 [(set_attr "type" "load")
4375 (set_attr "mode" "SI")
4376 (set_attr "length" "16")])
4378 (define_insn "rotr<mode>3"
4379 [(set (match_operand:GPR 0 "register_operand" "=d")
4380 (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
4381 (match_operand:SI 2 "arith_operand" "dI")))]
4384 if (GET_CODE (operands[2]) == CONST_INT)
4385 gcc_assert (INTVAL (operands[2]) >= 0
4386 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
4388 return "<d>ror\t%0,%1,%2";
4390 [(set_attr "type" "shift")
4391 (set_attr "mode" "<MODE>")])
4394 ;; ....................
4398 ;; ....................
4400 ;; Flow here is rather complex:
4402 ;; 1) The cmp{si,di,sf,df} routine is called. It deposits the arguments
4403 ;; into cmp_operands[] but generates no RTL.
4405 ;; 2) The appropriate branch define_expand is called, which then
4406 ;; creates the appropriate RTL for the comparison and branch.
4407 ;; Different CC modes are used, based on what type of branch is
4408 ;; done, so that we can constrain things appropriately. There
4409 ;; are assumptions in the rest of GCC that break if we fold the
4410 ;; operands into the branches for integer operations, and use cc0
4411 ;; for floating point, so we use the fp status register instead.
4412 ;; If needed, an appropriate temporary is created to hold the
4413 ;; of the integer compare.
4415 (define_expand "cmp<mode>"
4417 (compare:CC (match_operand:GPR 0 "register_operand")
4418 (match_operand:GPR 1 "nonmemory_operand")))]
4421 cmp_operands[0] = operands[0];
4422 cmp_operands[1] = operands[1];
4426 (define_expand "cmp<mode>"
4428 (compare:CC (match_operand:SCALARF 0 "register_operand")
4429 (match_operand:SCALARF 1 "register_operand")))]
4432 cmp_operands[0] = operands[0];
4433 cmp_operands[1] = operands[1];
4438 ;; ....................
4440 ;; CONDITIONAL BRANCHES
4442 ;; ....................
4444 ;; Conditional branches on floating-point equality tests.
4446 (define_insn "*branch_fp"
4449 (match_operator 0 "equality_operator"
4450 [(match_operand:CC 2 "register_operand" "z")
4452 (label_ref (match_operand 1 "" ""))
4456 return mips_output_conditional_branch (insn, operands,
4457 MIPS_BRANCH ("b%F0", "%Z2%1"),
4458 MIPS_BRANCH ("b%W0", "%Z2%1"));
4460 [(set_attr "type" "branch")
4461 (set_attr "mode" "none")])
4463 (define_insn "*branch_fp_inverted"
4466 (match_operator 0 "equality_operator"
4467 [(match_operand:CC 2 "register_operand" "z")
4470 (label_ref (match_operand 1 "" ""))))]
4473 return mips_output_conditional_branch (insn, operands,
4474 MIPS_BRANCH ("b%W0", "%Z2%1"),
4475 MIPS_BRANCH ("b%F0", "%Z2%1"));
4477 [(set_attr "type" "branch")
4478 (set_attr "mode" "none")])
4480 ;; Conditional branches on ordered comparisons with zero.
4482 (define_insn "*branch_order<mode>"
4485 (match_operator 0 "order_operator"
4486 [(match_operand:GPR 2 "register_operand" "d")
4488 (label_ref (match_operand 1 "" ""))
4491 { return mips_output_order_conditional_branch (insn, operands, false); }
4492 [(set_attr "type" "branch")
4493 (set_attr "mode" "none")])
4495 (define_insn "*branch_order<mode>_inverted"
4498 (match_operator 0 "order_operator"
4499 [(match_operand:GPR 2 "register_operand" "d")
4502 (label_ref (match_operand 1 "" ""))))]
4504 { return mips_output_order_conditional_branch (insn, operands, true); }
4505 [(set_attr "type" "branch")
4506 (set_attr "mode" "none")])
4508 ;; Conditional branch on equality comparison.
4510 (define_insn "*branch_equality<mode>"
4513 (match_operator 0 "equality_operator"
4514 [(match_operand:GPR 2 "register_operand" "d")
4515 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
4516 (label_ref (match_operand 1 "" ""))
4520 return mips_output_conditional_branch (insn, operands,
4521 MIPS_BRANCH ("b%C0", "%2,%z3,%1"),
4522 MIPS_BRANCH ("b%N0", "%2,%z3,%1"));
4524 [(set_attr "type" "branch")
4525 (set_attr "mode" "none")])
4527 (define_insn "*branch_equality<mode>_inverted"
4530 (match_operator 0 "equality_operator"
4531 [(match_operand:GPR 2 "register_operand" "d")
4532 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
4534 (label_ref (match_operand 1 "" ""))))]
4537 return mips_output_conditional_branch (insn, operands,
4538 MIPS_BRANCH ("b%N0", "%2,%z3,%1"),
4539 MIPS_BRANCH ("b%C0", "%2,%z3,%1"));
4541 [(set_attr "type" "branch")
4542 (set_attr "mode" "none")])
4546 (define_insn "*branch_equality<mode>_mips16"
4549 (match_operator 0 "equality_operator"
4550 [(match_operand:GPR 1 "register_operand" "d,t")
4552 (match_operand 2 "pc_or_label_operand" "")
4553 (match_operand 3 "pc_or_label_operand" "")))]
4556 if (operands[2] != pc_rtx)
4558 if (which_alternative == 0)
4559 return "b%C0z\t%1,%2";
4561 return "bt%C0z\t%2";
4565 if (which_alternative == 0)
4566 return "b%N0z\t%1,%3";
4568 return "bt%N0z\t%3";
4571 [(set_attr "type" "branch")
4572 (set_attr "mode" "none")
4573 (set_attr "length" "8")])
4575 (define_expand "b<code>"
4577 (if_then_else (any_cond:CC (cc0)
4579 (label_ref (match_operand 0 ""))
4583 gen_conditional_branch (operands, <CODE>);
4587 ;; Used to implement built-in functions.
4588 (define_expand "condjump"
4590 (if_then_else (match_operand 0)
4591 (label_ref (match_operand 1))
4595 ;; ....................
4597 ;; SETTING A REGISTER FROM A COMPARISON
4599 ;; ....................
4601 (define_expand "seq"
4602 [(set (match_operand:SI 0 "register_operand")
4603 (eq:SI (match_dup 1)
4606 { if (mips_emit_scc (EQ, operands[0])) DONE; else FAIL; })
4608 (define_insn "*seq_<mode>"
4609 [(set (match_operand:GPR 0 "register_operand" "=d")
4610 (eq:GPR (match_operand:GPR 1 "register_operand" "d")
4614 [(set_attr "type" "slt")
4615 (set_attr "mode" "<MODE>")])
4617 (define_insn "*seq_<mode>_mips16"
4618 [(set (match_operand:GPR 0 "register_operand" "=t")
4619 (eq:GPR (match_operand:GPR 1 "register_operand" "d")
4623 [(set_attr "type" "slt")
4624 (set_attr "mode" "<MODE>")])
4626 ;; "sne" uses sltu instructions in which the first operand is $0.
4627 ;; This isn't possible in mips16 code.
4629 (define_expand "sne"
4630 [(set (match_operand:SI 0 "register_operand")
4631 (ne:SI (match_dup 1)
4634 { if (mips_emit_scc (NE, operands[0])) DONE; else FAIL; })
4636 (define_insn "*sne_<mode>"
4637 [(set (match_operand:GPR 0 "register_operand" "=d")
4638 (ne:GPR (match_operand:GPR 1 "register_operand" "d")
4642 [(set_attr "type" "slt")
4643 (set_attr "mode" "<MODE>")])
4645 (define_expand "sgt"
4646 [(set (match_operand:SI 0 "register_operand")
4647 (gt:SI (match_dup 1)
4650 { if (mips_emit_scc (GT, operands[0])) DONE; else FAIL; })
4652 (define_insn "*sgt_<mode>"
4653 [(set (match_operand:GPR 0 "register_operand" "=d")
4654 (gt:GPR (match_operand:GPR 1 "register_operand" "d")
4655 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
4658 [(set_attr "type" "slt")
4659 (set_attr "mode" "<MODE>")])
4661 (define_insn "*sgt_<mode>_mips16"
4662 [(set (match_operand:GPR 0 "register_operand" "=t")
4663 (gt:GPR (match_operand:GPR 1 "register_operand" "d")
4664 (match_operand:GPR 2 "register_operand" "d")))]
4667 [(set_attr "type" "slt")
4668 (set_attr "mode" "<MODE>")])
4670 (define_expand "sge"
4671 [(set (match_operand:SI 0 "register_operand")
4672 (ge:SI (match_dup 1)
4675 { if (mips_emit_scc (GE, operands[0])) DONE; else FAIL; })
4677 (define_insn "*sge_<mode>"
4678 [(set (match_operand:GPR 0 "register_operand" "=d")
4679 (ge:GPR (match_operand:GPR 1 "register_operand" "d")
4683 [(set_attr "type" "slt")
4684 (set_attr "mode" "<MODE>")])
4686 (define_expand "slt"
4687 [(set (match_operand:SI 0 "register_operand")
4688 (lt:SI (match_dup 1)
4691 { if (mips_emit_scc (LT, operands[0])) DONE; else FAIL; })
4693 (define_insn "*slt_<mode>"
4694 [(set (match_operand:GPR 0 "register_operand" "=d")
4695 (lt:GPR (match_operand:GPR 1 "register_operand" "d")
4696 (match_operand:GPR 2 "arith_operand" "dI")))]
4699 [(set_attr "type" "slt")
4700 (set_attr "mode" "<MODE>")])
4702 (define_insn "*slt_<mode>_mips16"
4703 [(set (match_operand:GPR 0 "register_operand" "=t,t")
4704 (lt:GPR (match_operand:GPR 1 "register_operand" "d,d")
4705 (match_operand:GPR 2 "arith_operand" "d,I")))]
4708 [(set_attr "type" "slt")
4709 (set_attr "mode" "<MODE>")
4710 (set_attr_alternative "length"
4712 (if_then_else (match_operand 2 "m16_uimm8_1")
4716 (define_expand "sle"
4717 [(set (match_operand:SI 0 "register_operand")
4718 (le:SI (match_dup 1)
4721 { if (mips_emit_scc (LE, operands[0])) DONE; else FAIL; })
4723 (define_insn "*sle_<mode>"
4724 [(set (match_operand:GPR 0 "register_operand" "=d")
4725 (le:GPR (match_operand:GPR 1 "register_operand" "d")
4726 (match_operand:GPR 2 "sle_operand" "")))]
4729 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
4730 return "slt\t%0,%1,%2";
4732 [(set_attr "type" "slt")
4733 (set_attr "mode" "<MODE>")])
4735 (define_insn "*sle_<mode>_mips16"
4736 [(set (match_operand:GPR 0 "register_operand" "=t")
4737 (le:GPR (match_operand:GPR 1 "register_operand" "d")
4738 (match_operand:GPR 2 "sle_operand" "")))]
4741 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
4742 return "slt\t%1,%2";
4744 [(set_attr "type" "slt")
4745 (set_attr "mode" "<MODE>")
4746 (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
4750 (define_expand "sgtu"
4751 [(set (match_operand:SI 0 "register_operand")
4752 (gtu:SI (match_dup 1)
4755 { if (mips_emit_scc (GTU, operands[0])) DONE; else FAIL; })
4757 (define_insn "*sgtu_<mode>"
4758 [(set (match_operand:GPR 0 "register_operand" "=d")
4759 (gtu:GPR (match_operand:GPR 1 "register_operand" "d")
4760 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
4763 [(set_attr "type" "slt")
4764 (set_attr "mode" "<MODE>")])
4766 (define_insn "*sgtu_<mode>_mips16"
4767 [(set (match_operand:GPR 0 "register_operand" "=t")
4768 (gtu:GPR (match_operand:GPR 1 "register_operand" "d")
4769 (match_operand:GPR 2 "register_operand" "d")))]
4772 [(set_attr "type" "slt")
4773 (set_attr "mode" "<MODE>")])
4775 (define_expand "sgeu"
4776 [(set (match_operand:SI 0 "register_operand")
4777 (geu:SI (match_dup 1)
4780 { if (mips_emit_scc (GEU, operands[0])) DONE; else FAIL; })
4782 (define_insn "*sge_<mode>"
4783 [(set (match_operand:GPR 0 "register_operand" "=d")
4784 (geu:GPR (match_operand:GPR 1 "register_operand" "d")
4788 [(set_attr "type" "slt")
4789 (set_attr "mode" "<MODE>")])
4791 (define_expand "sltu"
4792 [(set (match_operand:SI 0 "register_operand")
4793 (ltu:SI (match_dup 1)
4796 { if (mips_emit_scc (LTU, operands[0])) DONE; else FAIL; })
4798 (define_insn "*sltu_<mode>"
4799 [(set (match_operand:GPR 0 "register_operand" "=d")
4800 (ltu:GPR (match_operand:GPR 1 "register_operand" "d")
4801 (match_operand:GPR 2 "arith_operand" "dI")))]
4804 [(set_attr "type" "slt")
4805 (set_attr "mode" "<MODE>")])
4807 (define_insn "*sltu_<mode>_mips16"
4808 [(set (match_operand:GPR 0 "register_operand" "=t,t")
4809 (ltu:GPR (match_operand:GPR 1 "register_operand" "d,d")
4810 (match_operand:GPR 2 "arith_operand" "d,I")))]
4813 [(set_attr "type" "slt")
4814 (set_attr "mode" "<MODE>")
4815 (set_attr_alternative "length"
4817 (if_then_else (match_operand 2 "m16_uimm8_1")
4821 (define_expand "sleu"
4822 [(set (match_operand:SI 0 "register_operand")
4823 (leu:SI (match_dup 1)
4826 { if (mips_emit_scc (LEU, operands[0])) DONE; else FAIL; })
4828 (define_insn "*sleu_<mode>"
4829 [(set (match_operand:GPR 0 "register_operand" "=d")
4830 (leu:GPR (match_operand:GPR 1 "register_operand" "d")
4831 (match_operand:GPR 2 "sleu_operand" "")))]
4834 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
4835 return "sltu\t%0,%1,%2";
4837 [(set_attr "type" "slt")
4838 (set_attr "mode" "<MODE>")])
4840 (define_insn "*sleu_<mode>_mips16"
4841 [(set (match_operand:GPR 0 "register_operand" "=t")
4842 (leu:GPR (match_operand:GPR 1 "register_operand" "d")
4843 (match_operand:GPR 2 "sleu_operand" "")))]
4846 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
4847 return "sltu\t%1,%2";
4849 [(set_attr "type" "slt")
4850 (set_attr "mode" "<MODE>")
4851 (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
4856 ;; ....................
4858 ;; FLOATING POINT COMPARISONS
4860 ;; ....................
4862 (define_insn "s<code>_<mode>"
4863 [(set (match_operand:CC 0 "register_operand" "=z")
4864 (fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
4865 (match_operand:SCALARF 2 "register_operand" "f")))]
4867 "c.<fcond>.<fmt>\t%Z0%1,%2"
4868 [(set_attr "type" "fcmp")
4869 (set_attr "mode" "FPSW")])
4871 (define_insn "s<code>_<mode>"
4872 [(set (match_operand:CC 0 "register_operand" "=z")
4873 (swapped_fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
4874 (match_operand:SCALARF 2 "register_operand" "f")))]
4876 "c.<swapped_fcond>.<fmt>\t%Z0%2,%1"
4877 [(set_attr "type" "fcmp")
4878 (set_attr "mode" "FPSW")])
4881 ;; ....................
4883 ;; UNCONDITIONAL BRANCHES
4885 ;; ....................
4887 ;; Unconditional branches.
4891 (label_ref (match_operand 0 "" "")))]
4896 if (get_attr_length (insn) <= 8)
4897 return "%*b\t%l0%/";
4900 output_asm_insn (mips_output_load_label (), operands);
4901 return "%*jr\t%@%/%]";
4905 return "%*j\t%l0%/";
4907 [(set_attr "type" "jump")
4908 (set_attr "mode" "none")
4909 (set (attr "length")
4910 ;; We can't use `j' when emitting PIC. Emit a branch if it's
4911 ;; in range, otherwise load the address of the branch target into
4912 ;; $at and then jump to it.
4914 (ior (eq (symbol_ref "flag_pic") (const_int 0))
4915 (lt (abs (minus (match_dup 0)
4916 (plus (pc) (const_int 4))))
4917 (const_int 131072)))
4918 (const_int 4) (const_int 16)))])
4920 ;; We need a different insn for the mips16, because a mips16 branch
4921 ;; does not have a delay slot.
4925 (label_ref (match_operand 0 "" "")))]
4928 [(set_attr "type" "branch")
4929 (set_attr "mode" "none")
4930 (set_attr "length" "8")])
4932 (define_expand "indirect_jump"
4933 [(set (pc) (match_operand 0 "register_operand"))]
4936 operands[0] = force_reg (Pmode, operands[0]);
4937 if (Pmode == SImode)
4938 emit_jump_insn (gen_indirect_jumpsi (operands[0]));
4940 emit_jump_insn (gen_indirect_jumpdi (operands[0]));
4944 (define_insn "indirect_jump<mode>"
4945 [(set (pc) (match_operand:P 0 "register_operand" "d"))]
4948 [(set_attr "type" "jump")
4949 (set_attr "mode" "none")])
4951 (define_expand "tablejump"
4953 (match_operand 0 "register_operand"))
4954 (use (label_ref (match_operand 1 "")))]
4958 operands[0] = expand_binop (Pmode, add_optab,
4959 convert_to_mode (Pmode, operands[0], false),
4960 gen_rtx_LABEL_REF (Pmode, operands[1]),
4962 else if (TARGET_GPWORD)
4963 operands[0] = expand_binop (Pmode, add_optab, operands[0],
4964 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
4965 else if (TARGET_RTP_PIC)
4967 /* When generating RTP PIC, we use case table entries that are relative
4968 to the start of the function. Add the function's address to the
4970 rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
4971 operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
4972 start, 0, 0, OPTAB_WIDEN);
4975 if (Pmode == SImode)
4976 emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
4978 emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
4982 (define_insn "tablejump<mode>"
4984 (match_operand:P 0 "register_operand" "d"))
4985 (use (label_ref (match_operand 1 "" "")))]
4988 [(set_attr "type" "jump")
4989 (set_attr "mode" "none")])
4991 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
4992 ;; While it is possible to either pull it off the stack (in the
4993 ;; o32 case) or recalculate it given t9 and our target label,
4994 ;; it takes 3 or 4 insns to do so.
4996 (define_expand "builtin_setjmp_setup"
4997 [(use (match_operand 0 "register_operand"))]
5002 addr = plus_constant (operands[0], GET_MODE_SIZE (Pmode) * 3);
5003 emit_move_insn (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
5007 ;; Restore the gp that we saved above. Despite the earlier comment, it seems
5008 ;; that older code did recalculate the gp from $25. Continue to jump through
5009 ;; $25 for compatibility (we lose nothing by doing so).
5011 (define_expand "builtin_longjmp"
5012 [(use (match_operand 0 "register_operand"))]
5015 /* The elements of the buffer are, in order: */
5016 int W = GET_MODE_SIZE (Pmode);
5017 rtx fp = gen_rtx_MEM (Pmode, operands[0]);
5018 rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 1*W));
5019 rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 2*W));
5020 rtx gpv = gen_rtx_MEM (Pmode, plus_constant (operands[0], 3*W));
5021 rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5022 /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
5023 The target is bound to be using $28 as the global pointer
5024 but the current function might not be. */
5025 rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
5027 /* This bit is similar to expand_builtin_longjmp except that it
5028 restores $gp as well. */
5029 emit_move_insn (hard_frame_pointer_rtx, fp);
5030 emit_move_insn (pv, lab);
5031 emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
5032 emit_move_insn (gp, gpv);
5033 emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
5034 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
5035 emit_insn (gen_rtx_USE (VOIDmode, gp));
5036 emit_indirect_jump (pv);
5041 ;; ....................
5043 ;; Function prologue/epilogue
5045 ;; ....................
5048 (define_expand "prologue"
5052 mips_expand_prologue ();
5056 ;; Block any insns from being moved before this point, since the
5057 ;; profiling call to mcount can use various registers that aren't
5058 ;; saved or used to pass arguments.
5060 (define_insn "blockage"
5061 [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
5064 [(set_attr "type" "unknown")
5065 (set_attr "mode" "none")
5066 (set_attr "length" "0")])
5068 (define_expand "epilogue"
5072 mips_expand_epilogue (false);
5076 (define_expand "sibcall_epilogue"
5080 mips_expand_epilogue (true);
5084 ;; Trivial return. Make it look like a normal return insn as that
5085 ;; allows jump optimizations to work better.
5087 (define_insn "return"
5089 "mips_can_use_return_insn ()"
5091 [(set_attr "type" "jump")
5092 (set_attr "mode" "none")])
5096 (define_insn "return_internal"
5098 (use (match_operand 0 "pmode_register_operand" ""))]
5101 [(set_attr "type" "jump")
5102 (set_attr "mode" "none")])
5104 ;; This is used in compiling the unwind routines.
5105 (define_expand "eh_return"
5106 [(use (match_operand 0 "general_operand"))]
5109 enum machine_mode gpr_mode = TARGET_64BIT ? DImode : SImode;
5111 if (GET_MODE (operands[0]) != gpr_mode)
5112 operands[0] = convert_to_mode (gpr_mode, operands[0], 0);
5114 emit_insn (gen_eh_set_lr_di (operands[0]));
5116 emit_insn (gen_eh_set_lr_si (operands[0]));
5121 ;; Clobber the return address on the stack. We can't expand this
5122 ;; until we know where it will be put in the stack frame.
5124 (define_insn "eh_set_lr_si"
5125 [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
5126 (clobber (match_scratch:SI 1 "=&d"))]
5130 (define_insn "eh_set_lr_di"
5131 [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
5132 (clobber (match_scratch:DI 1 "=&d"))]
5137 [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
5138 (clobber (match_scratch 1))]
5139 "reload_completed && !TARGET_DEBUG_D_MODE"
5142 mips_set_return_address (operands[0], operands[1]);
5146 (define_insn_and_split "nonlocal_goto_receiver"
5148 (unspec_volatile:SI [(const_int 0)] UNSPEC_NONLOCAL_GOTO_RECEIVER))]
5149 "TARGET_CALL_CLOBBERED_GP"
5151 "&& reload_completed"
5157 [(set_attr "type" "load")
5158 (set_attr "length" "12")])
5161 ;; ....................
5165 ;; ....................
5167 ;; Instructions to load a call address from the GOT. The address might
5168 ;; point to a function or to a lazy binding stub. In the latter case,
5169 ;; the stub will use the dynamic linker to resolve the function, which
5170 ;; in turn will change the GOT entry to point to the function's real
5173 ;; This means that every call, even pure and constant ones, can
5174 ;; potentially modify the GOT entry. And once a stub has been called,
5175 ;; we must not call it again.
5177 ;; We represent this restriction using an imaginary fixed register that
5178 ;; acts like a GOT version number. By making the register call-clobbered,
5179 ;; we tell the target-independent code that the address could be changed
5180 ;; by any call insn.
5181 (define_insn "load_call<mode>"
5182 [(set (match_operand:P 0 "register_operand" "=d")
5183 (unspec:P [(match_operand:P 1 "register_operand" "r")
5184 (match_operand:P 2 "immediate_operand" "")
5185 (reg:P FAKE_CALL_REGNO)]
5188 "<load>\t%0,%R2(%1)"
5189 [(set_attr "type" "load")
5190 (set_attr "mode" "<MODE>")
5191 (set_attr "length" "4")])
5193 ;; Sibling calls. All these patterns use jump instructions.
5195 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
5196 ;; addresses if a direct jump is acceptable. Since the 'S' constraint
5197 ;; is defined in terms of call_insn_operand, the same is true of the
5200 ;; When we use an indirect jump, we need a register that will be
5201 ;; preserved by the epilogue. Since TARGET_USE_PIC_FN_ADDR_REG forces
5202 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
5203 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
5206 (define_expand "sibcall"
5207 [(parallel [(call (match_operand 0 "")
5208 (match_operand 1 ""))
5209 (use (match_operand 2 "")) ;; next_arg_reg
5210 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
5213 mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], true);
5217 (define_insn "sibcall_internal"
5218 [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
5219 (match_operand 1 "" ""))]
5220 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
5221 { return MIPS_CALL ("j", operands, 0); }
5222 [(set_attr "type" "call")])
5224 (define_expand "sibcall_value"
5225 [(parallel [(set (match_operand 0 "")
5226 (call (match_operand 1 "")
5227 (match_operand 2 "")))
5228 (use (match_operand 3 ""))])] ;; next_arg_reg
5231 mips_expand_call (operands[0], XEXP (operands[1], 0),
5232 operands[2], operands[3], true);
5236 (define_insn "sibcall_value_internal"
5237 [(set (match_operand 0 "register_operand" "")
5238 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
5239 (match_operand 2 "" "")))]
5240 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
5241 { return MIPS_CALL ("j", operands, 1); }
5242 [(set_attr "type" "call")])
5244 (define_insn "sibcall_value_multiple_internal"
5245 [(set (match_operand 0 "register_operand" "")
5246 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
5247 (match_operand 2 "" "")))
5248 (set (match_operand 3 "register_operand" "")
5249 (call (mem:SI (match_dup 1))
5251 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
5252 { return MIPS_CALL ("j", operands, 1); }
5253 [(set_attr "type" "call")])
5255 (define_expand "call"
5256 [(parallel [(call (match_operand 0 "")
5257 (match_operand 1 ""))
5258 (use (match_operand 2 "")) ;; next_arg_reg
5259 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
5262 mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], false);
5266 ;; This instruction directly corresponds to an assembly-language "jal".
5267 ;; There are four cases:
5270 ;; Both symbolic and register destinations are OK. The pattern
5271 ;; always expands to a single mips instruction.
5273 ;; - -mabicalls/-mno-explicit-relocs:
5274 ;; Again, both symbolic and register destinations are OK.
5275 ;; The call is treated as a multi-instruction black box.
5277 ;; - -mabicalls/-mexplicit-relocs with n32 or n64:
5278 ;; Only "jal $25" is allowed. This expands to a single "jalr $25"
5281 ;; - -mabicalls/-mexplicit-relocs with o32 or o64:
5282 ;; Only "jal $25" is allowed. The call is actually two instructions:
5283 ;; "jalr $25" followed by an insn to reload $gp.
5285 ;; In the last case, we can generate the individual instructions with
5286 ;; a define_split. There are several things to be wary of:
5288 ;; - We can't expose the load of $gp before reload. If we did,
5289 ;; it might get removed as dead, but reload can introduce new
5290 ;; uses of $gp by rematerializing constants.
5292 ;; - We shouldn't restore $gp after calls that never return.
5293 ;; It isn't valid to insert instructions between a noreturn
5294 ;; call and the following barrier.
5296 ;; - The splitter deliberately changes the liveness of $gp. The unsplit
5297 ;; instruction preserves $gp and so have no effect on its liveness.
5298 ;; But once we generate the separate insns, it becomes obvious that
5299 ;; $gp is not live on entry to the call.
5301 ;; ??? The operands[2] = insn check is a hack to make the original insn
5302 ;; available to the splitter.
5303 (define_insn_and_split "call_internal"
5304 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
5305 (match_operand 1 "" ""))
5306 (clobber (reg:SI 31))]
5308 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0); }
5309 "reload_completed && TARGET_SPLIT_CALLS && (operands[2] = insn)"
5312 emit_call_insn (gen_call_split (operands[0], operands[1]));
5313 if (!find_reg_note (operands[2], REG_NORETURN, 0))
5317 [(set_attr "jal" "indirect,direct")
5318 (set_attr "extended_mips16" "no,yes")])
5320 (define_insn "call_split"
5321 [(call (mem:SI (match_operand 0 "call_insn_operand" "cS"))
5322 (match_operand 1 "" ""))
5323 (clobber (reg:SI 31))
5324 (clobber (reg:SI 28))]
5325 "TARGET_SPLIT_CALLS"
5326 { return MIPS_CALL ("jal", operands, 0); }
5327 [(set_attr "type" "call")])
5329 (define_expand "call_value"
5330 [(parallel [(set (match_operand 0 "")
5331 (call (match_operand 1 "")
5332 (match_operand 2 "")))
5333 (use (match_operand 3 ""))])] ;; next_arg_reg
5336 mips_expand_call (operands[0], XEXP (operands[1], 0),
5337 operands[2], operands[3], false);
5341 ;; See comment for call_internal.
5342 (define_insn_and_split "call_value_internal"
5343 [(set (match_operand 0 "register_operand" "")
5344 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
5345 (match_operand 2 "" "")))
5346 (clobber (reg:SI 31))]
5348 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1); }
5349 "reload_completed && TARGET_SPLIT_CALLS && (operands[3] = insn)"
5352 emit_call_insn (gen_call_value_split (operands[0], operands[1],
5354 if (!find_reg_note (operands[3], REG_NORETURN, 0))
5358 [(set_attr "jal" "indirect,direct")
5359 (set_attr "extended_mips16" "no,yes")])
5361 (define_insn "call_value_split"
5362 [(set (match_operand 0 "register_operand" "")
5363 (call (mem:SI (match_operand 1 "call_insn_operand" "cS"))
5364 (match_operand 2 "" "")))
5365 (clobber (reg:SI 31))
5366 (clobber (reg:SI 28))]
5367 "TARGET_SPLIT_CALLS"
5368 { return MIPS_CALL ("jal", operands, 1); }
5369 [(set_attr "type" "call")])
5371 ;; See comment for call_internal.
5372 (define_insn_and_split "call_value_multiple_internal"
5373 [(set (match_operand 0 "register_operand" "")
5374 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
5375 (match_operand 2 "" "")))
5376 (set (match_operand 3 "register_operand" "")
5377 (call (mem:SI (match_dup 1))
5379 (clobber (reg:SI 31))]
5381 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1); }
5382 "reload_completed && TARGET_SPLIT_CALLS && (operands[4] = insn)"
5385 emit_call_insn (gen_call_value_multiple_split (operands[0], operands[1],
5386 operands[2], operands[3]));
5387 if (!find_reg_note (operands[4], REG_NORETURN, 0))
5391 [(set_attr "jal" "indirect,direct")
5392 (set_attr "extended_mips16" "no,yes")])
5394 (define_insn "call_value_multiple_split"
5395 [(set (match_operand 0 "register_operand" "")
5396 (call (mem:SI (match_operand 1 "call_insn_operand" "cS"))
5397 (match_operand 2 "" "")))
5398 (set (match_operand 3 "register_operand" "")
5399 (call (mem:SI (match_dup 1))
5401 (clobber (reg:SI 31))
5402 (clobber (reg:SI 28))]
5403 "TARGET_SPLIT_CALLS"
5404 { return MIPS_CALL ("jal", operands, 1); }
5405 [(set_attr "type" "call")])
5407 ;; Call subroutine returning any type.
5409 (define_expand "untyped_call"
5410 [(parallel [(call (match_operand 0 "")
5412 (match_operand 1 "")
5413 (match_operand 2 "")])]
5418 emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
5420 for (i = 0; i < XVECLEN (operands[2], 0); i++)
5422 rtx set = XVECEXP (operands[2], 0, i);
5423 emit_move_insn (SET_DEST (set), SET_SRC (set));
5426 emit_insn (gen_blockage ());
5431 ;; ....................
5435 ;; ....................
5439 (define_insn "prefetch"
5440 [(prefetch (match_operand:QI 0 "address_operand" "p")
5441 (match_operand 1 "const_int_operand" "n")
5442 (match_operand 2 "const_int_operand" "n"))]
5443 "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
5445 operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
5446 return "pref\t%1,%a0";
5448 [(set_attr "type" "prefetch")])
5450 (define_insn "*prefetch_indexed_<mode>"
5451 [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
5452 (match_operand:P 1 "register_operand" "d"))
5453 (match_operand 2 "const_int_operand" "n")
5454 (match_operand 3 "const_int_operand" "n"))]
5455 "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
5457 operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
5458 return "prefx\t%2,%1(%0)";
5460 [(set_attr "type" "prefetchx")])
5466 [(set_attr "type" "nop")
5467 (set_attr "mode" "none")])
5469 ;; Like nop, but commented out when outside a .set noreorder block.
5470 (define_insn "hazard_nop"
5479 [(set_attr "type" "nop")])
5481 ;; MIPS4 Conditional move instructions.
5483 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
5484 [(set (match_operand:GPR 0 "register_operand" "=d,d")
5486 (match_operator:MOVECC 4 "equality_operator"
5487 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
5489 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
5490 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
5495 [(set_attr "type" "condmove")
5496 (set_attr "mode" "<GPR:MODE>")])
5498 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
5499 [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
5500 (if_then_else:SCALARF
5501 (match_operator:MOVECC 4 "equality_operator"
5502 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
5504 (match_operand:SCALARF 2 "register_operand" "f,0")
5505 (match_operand:SCALARF 3 "register_operand" "0,f")))]
5508 mov%T4.<fmt>\t%0,%2,%1
5509 mov%t4.<fmt>\t%0,%3,%1"
5510 [(set_attr "type" "condmove")
5511 (set_attr "mode" "<SCALARF:MODE>")])
5513 ;; These are the main define_expand's used to make conditional moves.
5515 (define_expand "mov<mode>cc"
5516 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
5517 (set (match_operand:GPR 0 "register_operand")
5518 (if_then_else:GPR (match_dup 5)
5519 (match_operand:GPR 2 "reg_or_0_operand")
5520 (match_operand:GPR 3 "reg_or_0_operand")))]
5523 gen_conditional_move (operands);
5527 (define_expand "mov<mode>cc"
5528 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
5529 (set (match_operand:SCALARF 0 "register_operand")
5530 (if_then_else:SCALARF (match_dup 5)
5531 (match_operand:SCALARF 2 "register_operand")
5532 (match_operand:SCALARF 3 "register_operand")))]
5535 gen_conditional_move (operands);
5540 ;; ....................
5542 ;; mips16 inline constant tables
5544 ;; ....................
5547 (define_insn "consttable_int"
5548 [(unspec_volatile [(match_operand 0 "consttable_operand" "")
5549 (match_operand 1 "const_int_operand" "")]
5550 UNSPEC_CONSTTABLE_INT)]
5553 assemble_integer (operands[0], INTVAL (operands[1]),
5554 BITS_PER_UNIT * INTVAL (operands[1]), 1);
5557 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
5559 (define_insn "consttable_float"
5560 [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
5561 UNSPEC_CONSTTABLE_FLOAT)]
5566 gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
5567 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
5568 assemble_real (d, GET_MODE (operands[0]),
5569 GET_MODE_BITSIZE (GET_MODE (operands[0])));
5572 [(set (attr "length")
5573 (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
5575 (define_insn "align"
5576 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
5579 [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
5582 [(match_operand 0 "small_data_pattern")]
5585 { operands[0] = mips_rewrite_small_data (operands[0]); })
5588 ;; ....................
5590 ;; MIPS16e Save/Restore
5592 ;; ....................
5595 (define_insn "*mips16e_save_restore"
5596 [(match_parallel 0 ""
5597 [(set (match_operand:SI 1 "register_operand")
5598 (plus:SI (match_dup 1)
5599 (match_operand:SI 2 "const_int_operand")))])]
5600 "operands[1] == stack_pointer_rtx
5601 && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
5602 { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
5603 [(set_attr "type" "arith")
5604 (set_attr "extended_mips16" "yes")])
5606 ; Thread-Local Storage
5608 ; The TLS base pointer is accessed via "rdhwr $v1, $29". No current
5609 ; MIPS architecture defines this register, and no current
5610 ; implementation provides it; instead, any OS which supports TLS is
5611 ; expected to trap and emulate this instruction. rdhwr is part of the
5612 ; MIPS 32r2 specification, but we use it on any architecture because
5613 ; we expect it to be emulated. Use .set to force the assembler to
5616 (define_insn "tls_get_tp_<mode>"
5617 [(set (match_operand:P 0 "register_operand" "=v")
5618 (unspec:P [(const_int 0)]
5619 UNSPEC_TLS_GET_TP))]
5620 "HAVE_AS_TLS && !TARGET_MIPS16"
5621 ".set\tpush\;.set\tmips32r2\t\;rdhwr\t%0,$29\;.set\tpop"
5622 [(set_attr "type" "unknown")
5623 ; Since rdhwr always generates a trap for now, putting it in a delay
5624 ; slot would make the kernel's emulation of it much slower.
5625 (set_attr "can_delay" "no")
5626 (set_attr "mode" "<MODE>")])
5628 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
5630 (include "mips-ps-3d.md")
5632 ; The MIPS DSP Instructions.
5634 (include "mips-dsp.md")
5636 ; The MIPS DSP REV 2 Instructions.
5638 (include "mips-dspr2.md")