invoke.texi: Document new MIPS -mllsc and -mno-llsc options.
[gcc.git] / gcc / config / mips / mips.md
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.
9
10 ;; This file is part of GCC.
11
12 ;; GCC is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
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.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GCC; see the file COPYING3. If not see
24 ;; <http://www.gnu.org/licenses/>.
25
26 (define_constants
27 [(UNSPEC_LOAD_DF_LOW 0)
28 (UNSPEC_LOAD_DF_HIGH 1)
29 (UNSPEC_STORE_DF_HIGH 2)
30 (UNSPEC_GET_FNADDR 3)
31 (UNSPEC_BLOCKAGE 4)
32 (UNSPEC_CPRESTORE 5)
33 (UNSPEC_NONLOCAL_GOTO_RECEIVER 6)
34 (UNSPEC_EH_RETURN 7)
35 (UNSPEC_CONSTTABLE_INT 8)
36 (UNSPEC_CONSTTABLE_FLOAT 9)
37 (UNSPEC_ALIGN 14)
38 (UNSPEC_HIGH 17)
39 (UNSPEC_LOAD_LEFT 18)
40 (UNSPEC_LOAD_RIGHT 19)
41 (UNSPEC_STORE_LEFT 20)
42 (UNSPEC_STORE_RIGHT 21)
43 (UNSPEC_LOADGP 22)
44 (UNSPEC_LOAD_CALL 23)
45 (UNSPEC_LOAD_GOT 24)
46 (UNSPEC_GP 25)
47 (UNSPEC_MFHILO 26)
48 (UNSPEC_TLS_LDM 27)
49 (UNSPEC_TLS_GET_TP 28)
50 (UNSPEC_MFHC1 31)
51 (UNSPEC_MTHC1 32)
52 (UNSPEC_CLEAR_HAZARD 33)
53 (UNSPEC_RDHWR 34)
54 (UNSPEC_SYNCI 35)
55 (UNSPEC_SYNC 36)
56 (UNSPEC_COMPARE_AND_SWAP 37)
57 (UNSPEC_SYNC_OLD_OP 38)
58 (UNSPEC_SYNC_NEW_OP 39)
59 (UNSPEC_SYNC_EXCHANGE 40)
60 (UNSPEC_MEMORY_BARRIER 41)
61
62 (UNSPEC_ADDRESS_FIRST 100)
63
64 (FAKE_CALL_REGNO 79)
65
66 ;; For MIPS Paired-Singled Floating Point Instructions.
67
68 (UNSPEC_MOVE_TF_PS 200)
69 (UNSPEC_C 201)
70
71 ;; MIPS64/MIPS32R2 alnv.ps
72 (UNSPEC_ALNV_PS 202)
73
74 ;; MIPS-3D instructions
75 (UNSPEC_CABS 203)
76
77 (UNSPEC_ADDR_PS 204)
78 (UNSPEC_CVT_PW_PS 205)
79 (UNSPEC_CVT_PS_PW 206)
80 (UNSPEC_MULR_PS 207)
81 (UNSPEC_ABS_PS 208)
82
83 (UNSPEC_RSQRT1 209)
84 (UNSPEC_RSQRT2 210)
85 (UNSPEC_RECIP1 211)
86 (UNSPEC_RECIP2 212)
87 (UNSPEC_SINGLE_CC 213)
88 (UNSPEC_SCC 214)
89
90 ;; MIPS DSP ASE Revision 0.98 3/24/2005
91 (UNSPEC_ADDQ 300)
92 (UNSPEC_ADDQ_S 301)
93 (UNSPEC_SUBQ 302)
94 (UNSPEC_SUBQ_S 303)
95 (UNSPEC_ADDSC 304)
96 (UNSPEC_ADDWC 305)
97 (UNSPEC_MODSUB 306)
98 (UNSPEC_RADDU_W_QB 307)
99 (UNSPEC_ABSQ_S 308)
100 (UNSPEC_PRECRQ_QB_PH 309)
101 (UNSPEC_PRECRQ_PH_W 310)
102 (UNSPEC_PRECRQ_RS_PH_W 311)
103 (UNSPEC_PRECRQU_S_QB_PH 312)
104 (UNSPEC_PRECEQ_W_PHL 313)
105 (UNSPEC_PRECEQ_W_PHR 314)
106 (UNSPEC_PRECEQU_PH_QBL 315)
107 (UNSPEC_PRECEQU_PH_QBR 316)
108 (UNSPEC_PRECEQU_PH_QBLA 317)
109 (UNSPEC_PRECEQU_PH_QBRA 318)
110 (UNSPEC_PRECEU_PH_QBL 319)
111 (UNSPEC_PRECEU_PH_QBR 320)
112 (UNSPEC_PRECEU_PH_QBLA 321)
113 (UNSPEC_PRECEU_PH_QBRA 322)
114 (UNSPEC_SHLL 323)
115 (UNSPEC_SHLL_S 324)
116 (UNSPEC_SHRL_QB 325)
117 (UNSPEC_SHRA_PH 326)
118 (UNSPEC_SHRA_R 327)
119 (UNSPEC_MULEU_S_PH_QBL 328)
120 (UNSPEC_MULEU_S_PH_QBR 329)
121 (UNSPEC_MULQ_RS_PH 330)
122 (UNSPEC_MULEQ_S_W_PHL 331)
123 (UNSPEC_MULEQ_S_W_PHR 332)
124 (UNSPEC_DPAU_H_QBL 333)
125 (UNSPEC_DPAU_H_QBR 334)
126 (UNSPEC_DPSU_H_QBL 335)
127 (UNSPEC_DPSU_H_QBR 336)
128 (UNSPEC_DPAQ_S_W_PH 337)
129 (UNSPEC_DPSQ_S_W_PH 338)
130 (UNSPEC_MULSAQ_S_W_PH 339)
131 (UNSPEC_DPAQ_SA_L_W 340)
132 (UNSPEC_DPSQ_SA_L_W 341)
133 (UNSPEC_MAQ_S_W_PHL 342)
134 (UNSPEC_MAQ_S_W_PHR 343)
135 (UNSPEC_MAQ_SA_W_PHL 344)
136 (UNSPEC_MAQ_SA_W_PHR 345)
137 (UNSPEC_BITREV 346)
138 (UNSPEC_INSV 347)
139 (UNSPEC_REPL_QB 348)
140 (UNSPEC_REPL_PH 349)
141 (UNSPEC_CMP_EQ 350)
142 (UNSPEC_CMP_LT 351)
143 (UNSPEC_CMP_LE 352)
144 (UNSPEC_CMPGU_EQ_QB 353)
145 (UNSPEC_CMPGU_LT_QB 354)
146 (UNSPEC_CMPGU_LE_QB 355)
147 (UNSPEC_PICK 356)
148 (UNSPEC_PACKRL_PH 357)
149 (UNSPEC_EXTR_W 358)
150 (UNSPEC_EXTR_R_W 359)
151 (UNSPEC_EXTR_RS_W 360)
152 (UNSPEC_EXTR_S_H 361)
153 (UNSPEC_EXTP 362)
154 (UNSPEC_EXTPDP 363)
155 (UNSPEC_SHILO 364)
156 (UNSPEC_MTHLIP 365)
157 (UNSPEC_WRDSP 366)
158 (UNSPEC_RDDSP 367)
159
160 ;; MIPS DSP ASE REV 2 Revision 0.02 11/24/2006
161 (UNSPEC_ABSQ_S_QB 400)
162 (UNSPEC_ADDU_PH 401)
163 (UNSPEC_ADDU_S_PH 402)
164 (UNSPEC_ADDUH_QB 403)
165 (UNSPEC_ADDUH_R_QB 404)
166 (UNSPEC_APPEND 405)
167 (UNSPEC_BALIGN 406)
168 (UNSPEC_CMPGDU_EQ_QB 407)
169 (UNSPEC_CMPGDU_LT_QB 408)
170 (UNSPEC_CMPGDU_LE_QB 409)
171 (UNSPEC_DPA_W_PH 410)
172 (UNSPEC_DPS_W_PH 411)
173 (UNSPEC_MADD 412)
174 (UNSPEC_MADDU 413)
175 (UNSPEC_MSUB 414)
176 (UNSPEC_MSUBU 415)
177 (UNSPEC_MUL_PH 416)
178 (UNSPEC_MUL_S_PH 417)
179 (UNSPEC_MULQ_RS_W 418)
180 (UNSPEC_MULQ_S_PH 419)
181 (UNSPEC_MULQ_S_W 420)
182 (UNSPEC_MULSA_W_PH 421)
183 (UNSPEC_MULT 422)
184 (UNSPEC_MULTU 423)
185 (UNSPEC_PRECR_QB_PH 424)
186 (UNSPEC_PRECR_SRA_PH_W 425)
187 (UNSPEC_PRECR_SRA_R_PH_W 426)
188 (UNSPEC_PREPEND 427)
189 (UNSPEC_SHRA_QB 428)
190 (UNSPEC_SHRA_R_QB 429)
191 (UNSPEC_SHRL_PH 430)
192 (UNSPEC_SUBU_PH 431)
193 (UNSPEC_SUBU_S_PH 432)
194 (UNSPEC_SUBUH_QB 433)
195 (UNSPEC_SUBUH_R_QB 434)
196 (UNSPEC_ADDQH_PH 435)
197 (UNSPEC_ADDQH_R_PH 436)
198 (UNSPEC_ADDQH_W 437)
199 (UNSPEC_ADDQH_R_W 438)
200 (UNSPEC_SUBQH_PH 439)
201 (UNSPEC_SUBQH_R_PH 440)
202 (UNSPEC_SUBQH_W 441)
203 (UNSPEC_SUBQH_R_W 442)
204 (UNSPEC_DPAX_W_PH 443)
205 (UNSPEC_DPSX_W_PH 444)
206 (UNSPEC_DPAQX_S_W_PH 445)
207 (UNSPEC_DPAQX_SA_W_PH 446)
208 (UNSPEC_DPSQX_S_W_PH 447)
209 (UNSPEC_DPSQX_SA_W_PH 448)
210 ]
211 )
212
213 (include "predicates.md")
214 (include "constraints.md")
215 \f
216 ;; ....................
217 ;;
218 ;; Attributes
219 ;;
220 ;; ....................
221
222 (define_attr "got" "unset,xgot_high,load"
223 (const_string "unset"))
224
225 ;; For jal instructions, this attribute is DIRECT when the target address
226 ;; is symbolic and INDIRECT when it is a register.
227 (define_attr "jal" "unset,direct,indirect"
228 (const_string "unset"))
229
230 ;; This attribute is YES if the instruction is a jal macro (not a
231 ;; real jal instruction).
232 ;;
233 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
234 ;; an instruction to restore $gp. Direct jals are also macros for
235 ;; flag_pic && !TARGET_ABSOLUTE_ABICALLS because they first load
236 ;; the target address into a register.
237 (define_attr "jal_macro" "no,yes"
238 (cond [(eq_attr "jal" "direct")
239 (symbol_ref "TARGET_CALL_CLOBBERED_GP
240 || (flag_pic && !TARGET_ABSOLUTE_ABICALLS)")
241 (eq_attr "jal" "indirect")
242 (symbol_ref "TARGET_CALL_CLOBBERED_GP")]
243 (const_string "no")))
244
245 ;; Classification of each insn.
246 ;; branch conditional branch
247 ;; jump unconditional jump
248 ;; call unconditional call
249 ;; load load instruction(s)
250 ;; fpload floating point load
251 ;; fpidxload floating point indexed load
252 ;; store store instruction(s)
253 ;; fpstore floating point store
254 ;; fpidxstore floating point indexed store
255 ;; prefetch memory prefetch (register + offset)
256 ;; prefetchx memory indexed prefetch (register + register)
257 ;; condmove conditional moves
258 ;; mfc transfer from coprocessor
259 ;; mtc transfer to coprocessor
260 ;; mthilo transfer to hi/lo registers
261 ;; mfhilo transfer from hi/lo registers
262 ;; const load constant
263 ;; arith integer arithmetic instructions
264 ;; logical integer logical instructions
265 ;; shift integer shift instructions
266 ;; slt set less than instructions
267 ;; signext sign extend instructions
268 ;; clz the clz and clo instructions
269 ;; trap trap if instructions
270 ;; imul integer multiply 2 operands
271 ;; imul3 integer multiply 3 operands
272 ;; imadd integer multiply-add
273 ;; idiv integer divide
274 ;; move integer register move ({,D}ADD{,U} with rt = 0)
275 ;; fmove floating point register move
276 ;; fadd floating point add/subtract
277 ;; fmul floating point multiply
278 ;; fmadd floating point multiply-add
279 ;; fdiv floating point divide
280 ;; frdiv floating point reciprocal divide
281 ;; frdiv1 floating point reciprocal divide step 1
282 ;; frdiv2 floating point reciprocal divide step 2
283 ;; fabs floating point absolute value
284 ;; fneg floating point negation
285 ;; fcmp floating point compare
286 ;; fcvt floating point convert
287 ;; fsqrt floating point square root
288 ;; frsqrt floating point reciprocal square root
289 ;; frsqrt1 floating point reciprocal square root step1
290 ;; frsqrt2 floating point reciprocal square root step2
291 ;; multi multiword sequence (or user asm statements)
292 ;; nop no operation
293 (define_attr "type"
294 "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,prefetch,prefetchx,condmove,mfc,mtc,mthilo,mfhilo,const,arith,logical,shift,slt,signext,clz,trap,imul,imul3,imadd,idiv,move,fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,frsqrt,frsqrt1,frsqrt2,multi,nop"
295 (cond [(eq_attr "jal" "!unset") (const_string "call")
296 (eq_attr "got" "load") (const_string "load")]
297 (const_string "unknown")))
298
299 ;; Main data type used by the insn
300 (define_attr "mode" "unknown,none,QI,HI,SI,DI,SF,DF,FPSW"
301 (const_string "unknown"))
302
303 ;; Mode for conversion types (fcvt)
304 ;; I2S integer to float single (SI/DI to SF)
305 ;; I2D integer to float double (SI/DI to DF)
306 ;; S2I float to integer (SF to SI/DI)
307 ;; D2I float to integer (DF to SI/DI)
308 ;; D2S double to float single
309 ;; S2D float single to double
310
311 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D"
312 (const_string "unknown"))
313
314 ;; Is this an extended instruction in mips16 mode?
315 (define_attr "extended_mips16" "no,yes"
316 (const_string "no"))
317
318 ;; Length of instruction in bytes.
319 (define_attr "length" ""
320 (cond [;; Direct branch instructions have a range of [-0x40000,0x3fffc].
321 ;; If a branch is outside this range, we have a choice of two
322 ;; sequences. For PIC, an out-of-range branch like:
323 ;;
324 ;; bne r1,r2,target
325 ;; dslot
326 ;;
327 ;; becomes the equivalent of:
328 ;;
329 ;; beq r1,r2,1f
330 ;; dslot
331 ;; la $at,target
332 ;; jr $at
333 ;; nop
334 ;; 1:
335 ;;
336 ;; where the load address can be up to three instructions long
337 ;; (lw, nop, addiu).
338 ;;
339 ;; The non-PIC case is similar except that we use a direct
340 ;; jump instead of an la/jr pair. Since the target of this
341 ;; jump is an absolute 28-bit bit address (the other bits
342 ;; coming from the address of the delay slot) this form cannot
343 ;; cross a 256MB boundary. We could provide the option of
344 ;; using la/jr in this case too, but we do not do so at
345 ;; present.
346 ;;
347 ;; Note that this value does not account for the delay slot
348 ;; instruction, whose length is added separately. If the RTL
349 ;; pattern has no explicit delay slot, mips_adjust_insn_length
350 ;; will add the length of the implicit nop. The values for
351 ;; forward and backward branches will be different as well.
352 (eq_attr "type" "branch")
353 (cond [(and (le (minus (match_dup 1) (pc)) (const_int 131064))
354 (le (minus (pc) (match_dup 1)) (const_int 131068)))
355 (const_int 4)
356 (ne (symbol_ref "flag_pic") (const_int 0))
357 (const_int 24)
358 ] (const_int 12))
359
360 (eq_attr "got" "load")
361 (const_int 4)
362 (eq_attr "got" "xgot_high")
363 (const_int 8)
364
365 (eq_attr "type" "const")
366 (symbol_ref "mips_const_insns (operands[1]) * 4")
367 (eq_attr "type" "load,fpload")
368 (symbol_ref "mips_load_store_insns (operands[1], insn) * 4")
369 (eq_attr "type" "store,fpstore")
370 (symbol_ref "mips_load_store_insns (operands[0], insn) * 4")
371
372 ;; In the worst case, a call macro will take 8 instructions:
373 ;;
374 ;; lui $25,%call_hi(FOO)
375 ;; addu $25,$25,$28
376 ;; lw $25,%call_lo(FOO)($25)
377 ;; nop
378 ;; jalr $25
379 ;; nop
380 ;; lw $gp,X($sp)
381 ;; nop
382 (eq_attr "jal_macro" "yes")
383 (const_int 32)
384
385 (and (eq_attr "extended_mips16" "yes")
386 (ne (symbol_ref "TARGET_MIPS16") (const_int 0)))
387 (const_int 8)
388
389 ;; Various VR4120 errata require a nop to be inserted after a macc
390 ;; instruction. The assembler does this for us, so account for
391 ;; the worst-case length here.
392 (and (eq_attr "type" "imadd")
393 (ne (symbol_ref "TARGET_FIX_VR4120") (const_int 0)))
394 (const_int 8)
395
396 ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
397 ;; the result of the second one is missed. The assembler should work
398 ;; around this by inserting a nop after the first dmult.
399 (and (eq_attr "type" "imul,imul3")
400 (and (eq_attr "mode" "DI")
401 (ne (symbol_ref "TARGET_FIX_VR4120") (const_int 0))))
402 (const_int 8)
403
404 (eq_attr "type" "idiv")
405 (symbol_ref "mips_idiv_insns () * 4")
406 ] (const_int 4)))
407
408 ;; Attribute describing the processor. This attribute must match exactly
409 ;; with the processor_type enumeration in mips.h.
410 (define_attr "cpu"
411 "r3000,4kc,4kp,5kc,5kf,20kc,24kc,24kf2_1,24kf1_1,74kc,74kf2_1,74kf1_1,74kf3_2,m4k,r3900,r6000,r4000,r4100,r4111,r4120,r4130,r4300,r4600,r4650,r5000,r5400,r5500,r7000,r8000,r9000,sb1,sb1a,sr71000"
412 (const (symbol_ref "mips_tune")))
413
414 ;; The type of hardware hazard associated with this instruction.
415 ;; DELAY means that the next instruction cannot read the result
416 ;; of this one. HILO means that the next two instructions cannot
417 ;; write to HI or LO.
418 (define_attr "hazard" "none,delay,hilo"
419 (cond [(and (eq_attr "type" "load,fpload,fpidxload")
420 (ne (symbol_ref "ISA_HAS_LOAD_DELAY") (const_int 0)))
421 (const_string "delay")
422
423 (and (eq_attr "type" "mfc,mtc")
424 (ne (symbol_ref "ISA_HAS_XFER_DELAY") (const_int 0)))
425 (const_string "delay")
426
427 (and (eq_attr "type" "fcmp")
428 (ne (symbol_ref "ISA_HAS_FCMP_DELAY") (const_int 0)))
429 (const_string "delay")
430
431 ;; The r4000 multiplication patterns include an mflo instruction.
432 (and (eq_attr "type" "imul")
433 (ne (symbol_ref "TARGET_FIX_R4000") (const_int 0)))
434 (const_string "hilo")
435
436 (and (eq_attr "type" "mfhilo")
437 (eq (symbol_ref "ISA_HAS_HILO_INTERLOCKS") (const_int 0)))
438 (const_string "hilo")]
439 (const_string "none")))
440
441 ;; Is it a single instruction?
442 (define_attr "single_insn" "no,yes"
443 (symbol_ref "get_attr_length (insn) == (TARGET_MIPS16 ? 2 : 4)"))
444
445 ;; Can the instruction be put into a delay slot?
446 (define_attr "can_delay" "no,yes"
447 (if_then_else (and (eq_attr "type" "!branch,call,jump")
448 (and (eq_attr "hazard" "none")
449 (eq_attr "single_insn" "yes")))
450 (const_string "yes")
451 (const_string "no")))
452
453 ;; Attribute defining whether or not we can use the branch-likely instructions
454 (define_attr "branch_likely" "no,yes"
455 (const
456 (if_then_else (ne (symbol_ref "GENERATE_BRANCHLIKELY") (const_int 0))
457 (const_string "yes")
458 (const_string "no"))))
459
460 ;; True if an instruction might assign to hi or lo when reloaded.
461 ;; This is used by the TUNE_MACC_CHAINS code.
462 (define_attr "may_clobber_hilo" "no,yes"
463 (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthilo")
464 (const_string "yes")
465 (const_string "no")))
466
467 ;; Describe a user's asm statement.
468 (define_asm_attributes
469 [(set_attr "type" "multi")
470 (set_attr "can_delay" "no")])
471 \f
472 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
473 ;; from the same template.
474 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
475
476 ;; This mode iterator allows :P to be used for patterns that operate on
477 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
478 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
479
480 ;; This mode iterator allows :MOVECC to be used anywhere that a
481 ;; conditional-move-type condition is needed.
482 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT") (CC "TARGET_HARD_FLOAT")])
483
484 ;; This mode iterator allows the QI and HI extension patterns to be defined from
485 ;; the same template.
486 (define_mode_iterator SHORT [QI HI])
487
488 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
489 ;; floating-point mode is allowed.
490 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
491 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
492 (V2SF "TARGET_PAIRED_SINGLE_FLOAT")])
493
494 ;; Like ANYF, but only applies to scalar modes.
495 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
496 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
497
498 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
499 ;; 32-bit version and "dsubu" in the 64-bit version.
500 (define_mode_attr d [(SI "") (DI "d")
501 (QQ "") (HQ "") (SQ "") (DQ "d")
502 (UQQ "") (UHQ "") (USQ "") (UDQ "d")
503 (HA "") (SA "") (DA "d")
504 (UHA "") (USA "") (UDA "d")])
505
506 ;; This attribute gives the length suffix for a sign- or zero-extension
507 ;; instruction.
508 (define_mode_attr size [(QI "b") (HI "h")])
509
510 ;; This attributes gives the mode mask of a SHORT.
511 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
512
513 ;; Mode attributes for GPR loads and stores.
514 (define_mode_attr load [(SI "lw") (DI "ld")])
515 (define_mode_attr store [(SI "sw") (DI "sd")])
516
517 ;; Similarly for MIPS IV indexed FPR loads and stores.
518 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
519 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
520
521 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
522 ;; are different. Some forms of unextended addiu have an 8-bit immediate
523 ;; field but the equivalent daddiu has only a 5-bit field.
524 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
525
526 ;; This attribute gives the best constraint to use for registers of
527 ;; a given mode.
528 (define_mode_attr reg [(SI "d") (DI "d") (CC "z")])
529
530 ;; This attribute gives the format suffix for floating-point operations.
531 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
532
533 ;; This attribute gives the upper-case mode name for one unit of a
534 ;; floating-point mode.
535 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
536
537 ;; This attribute gives the integer mode that has the same size as a
538 ;; fixed-point mode.
539 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
540 (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
541 (HA "HI") (SA "SI") (DA "DI")
542 (UHA "HI") (USA "SI") (UDA "DI")
543 (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
544 (V2HQ "SI") (V2HA "SI")])
545
546 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
547 ;;
548 ;; In certain cases, div.s and div.ps may have a rounding error
549 ;; and/or wrong inexact flag.
550 ;;
551 ;; Therefore, we only allow div.s if not working around SB-1 rev2
552 ;; errata or if a slight loss of precision is OK.
553 (define_mode_attr divide_condition
554 [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
555 (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
556
557 ; This attribute gives the condition for which sqrt instructions exist.
558 (define_mode_attr sqrt_condition
559 [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
560
561 ; This attribute gives the condition for which recip and rsqrt instructions
562 ; exist.
563 (define_mode_attr recip_condition
564 [(SF "ISA_HAS_FP4") (DF "ISA_HAS_FP4") (V2SF "TARGET_SB1")])
565
566 ;; This code iterator allows all branch instructions to be generated from
567 ;; a single define_expand template.
568 (define_code_iterator any_cond [unordered ordered unlt unge uneq ltgt unle ungt
569 eq ne gt ge lt le gtu geu ltu leu])
570
571 ;; This code iterator allows signed and unsigned widening multiplications
572 ;; to use the same template.
573 (define_code_iterator any_extend [sign_extend zero_extend])
574
575 ;; This code iterator allows the three shift instructions to be generated
576 ;; from the same template.
577 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
578
579 ;; This code iterator allows all native floating-point comparisons to be
580 ;; generated from the same template.
581 (define_code_iterator fcond [unordered uneq unlt unle eq lt le])
582
583 ;; This code iterator is used for comparisons that can be implemented
584 ;; by swapping the operands.
585 (define_code_iterator swapped_fcond [ge gt unge ungt])
586
587 ;; <u> expands to an empty string when doing a signed operation and
588 ;; "u" when doing an unsigned operation.
589 (define_code_attr u [(sign_extend "") (zero_extend "u")])
590
591 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
592 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
593
594 ;; <optab> expands to the name of the optab for a particular code.
595 (define_code_attr optab [(ashift "ashl")
596 (ashiftrt "ashr")
597 (lshiftrt "lshr")
598 (ior "ior")
599 (xor "xor")
600 (and "and")])
601
602 ;; <insn> expands to the name of the insn that implements a particular code.
603 (define_code_attr insn [(ashift "sll")
604 (ashiftrt "sra")
605 (lshiftrt "srl")
606 (ior "or")
607 (xor "xor")
608 (and "and")])
609
610 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
611 (define_code_attr fcond [(unordered "un")
612 (uneq "ueq")
613 (unlt "ult")
614 (unle "ule")
615 (eq "eq")
616 (lt "lt")
617 (le "le")])
618
619 ;; Similar, but for swapped conditions.
620 (define_code_attr swapped_fcond [(ge "le")
621 (gt "lt")
622 (unge "ule")
623 (ungt "ult")])
624
625 ;; Atomic fetch bitwise operations.
626 (define_code_iterator fetchop_bit [ior xor and])
627
628 ;; <immediate_insn> expands to the name of the insn that implements
629 ;; a particular code to operate in immediate values.
630 (define_code_attr immediate_insn [(ior "ori") (xor "xori") (and "andi")])
631
632 \f
633 ;; .........................
634 ;;
635 ;; Branch, call and jump delay slots
636 ;;
637 ;; .........................
638
639 (define_delay (and (eq_attr "type" "branch")
640 (eq (symbol_ref "TARGET_MIPS16") (const_int 0)))
641 [(eq_attr "can_delay" "yes")
642 (nil)
643 (and (eq_attr "branch_likely" "yes")
644 (eq_attr "can_delay" "yes"))])
645
646 (define_delay (eq_attr "type" "jump")
647 [(eq_attr "can_delay" "yes")
648 (nil)
649 (nil)])
650
651 (define_delay (and (eq_attr "type" "call")
652 (eq_attr "jal_macro" "no"))
653 [(eq_attr "can_delay" "yes")
654 (nil)
655 (nil)])
656 \f
657 ;; Pipeline descriptions.
658 ;;
659 ;; generic.md provides a fallback for processors without a specific
660 ;; pipeline description. It is derived from the old define_function_unit
661 ;; version and uses the "alu" and "imuldiv" units declared below.
662 ;;
663 ;; Some of the processor-specific files are also derived from old
664 ;; define_function_unit descriptions and simply override the parts of
665 ;; generic.md that don't apply. The other processor-specific files
666 ;; are self-contained.
667 (define_automaton "alu,imuldiv")
668
669 (define_cpu_unit "alu" "alu")
670 (define_cpu_unit "imuldiv" "imuldiv")
671
672 (include "4k.md")
673 (include "5k.md")
674 (include "20kc.md")
675 (include "24k.md")
676 (include "74k.md")
677 (include "3000.md")
678 (include "4000.md")
679 (include "4100.md")
680 (include "4130.md")
681 (include "4300.md")
682 (include "4600.md")
683 (include "5000.md")
684 (include "5400.md")
685 (include "5500.md")
686 (include "6000.md")
687 (include "7000.md")
688 (include "9000.md")
689 (include "sb1.md")
690 (include "sr71k.md")
691 (include "generic.md")
692 \f
693 ;;
694 ;; ....................
695 ;;
696 ;; CONDITIONAL TRAPS
697 ;;
698 ;; ....................
699 ;;
700
701 (define_insn "trap"
702 [(trap_if (const_int 1) (const_int 0))]
703 ""
704 {
705 if (ISA_HAS_COND_TRAP)
706 return "teq\t$0,$0";
707 else if (TARGET_MIPS16)
708 return "break 0";
709 else
710 return "break";
711 }
712 [(set_attr "type" "trap")])
713
714 (define_expand "conditional_trap"
715 [(trap_if (match_operator 0 "comparison_operator"
716 [(match_dup 2) (match_dup 3)])
717 (match_operand 1 "const_int_operand"))]
718 "ISA_HAS_COND_TRAP"
719 {
720 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) == MODE_INT
721 && operands[1] == const0_rtx)
722 {
723 mips_gen_conditional_trap (operands);
724 DONE;
725 }
726 else
727 FAIL;
728 })
729
730 (define_insn "*conditional_trap<mode>"
731 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
732 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
733 (match_operand:GPR 2 "arith_operand" "dI")])
734 (const_int 0))]
735 "ISA_HAS_COND_TRAP"
736 "t%C0\t%z1,%2"
737 [(set_attr "type" "trap")])
738 \f
739 ;;
740 ;; ....................
741 ;;
742 ;; ADDITION
743 ;;
744 ;; ....................
745 ;;
746
747 (define_insn "add<mode>3"
748 [(set (match_operand:ANYF 0 "register_operand" "=f")
749 (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
750 (match_operand:ANYF 2 "register_operand" "f")))]
751 ""
752 "add.<fmt>\t%0,%1,%2"
753 [(set_attr "type" "fadd")
754 (set_attr "mode" "<UNITMODE>")])
755
756 (define_expand "add<mode>3"
757 [(set (match_operand:GPR 0 "register_operand")
758 (plus:GPR (match_operand:GPR 1 "register_operand")
759 (match_operand:GPR 2 "arith_operand")))]
760 "")
761
762 (define_insn "*add<mode>3"
763 [(set (match_operand:GPR 0 "register_operand" "=d,d")
764 (plus:GPR (match_operand:GPR 1 "register_operand" "d,d")
765 (match_operand:GPR 2 "arith_operand" "d,Q")))]
766 "!TARGET_MIPS16"
767 "@
768 <d>addu\t%0,%1,%2
769 <d>addiu\t%0,%1,%2"
770 [(set_attr "type" "arith")
771 (set_attr "mode" "<MODE>")])
772
773 (define_insn "*add<mode>3_mips16"
774 [(set (match_operand:GPR 0 "register_operand" "=ks,d,d,d,d")
775 (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,0,d,d")
776 (match_operand:GPR 2 "arith_operand" "Q,Q,Q,O,d")))]
777 "TARGET_MIPS16"
778 "@
779 <d>addiu\t%0,%2
780 <d>addiu\t%0,%1,%2
781 <d>addiu\t%0,%2
782 <d>addiu\t%0,%1,%2
783 <d>addu\t%0,%1,%2"
784 [(set_attr "type" "arith")
785 (set_attr "mode" "<MODE>")
786 (set_attr_alternative "length"
787 [(if_then_else (match_operand 2 "m16_simm8_8")
788 (const_int 4)
789 (const_int 8))
790 (if_then_else (match_operand 2 "m16_uimm<si8_di5>_4")
791 (const_int 4)
792 (const_int 8))
793 (if_then_else (match_operand 2 "m16_simm<si8_di5>_1")
794 (const_int 4)
795 (const_int 8))
796 (if_then_else (match_operand 2 "m16_simm4_1")
797 (const_int 4)
798 (const_int 8))
799 (const_int 4)])])
800
801 ;; On the mips16, we can sometimes split an add of a constant which is
802 ;; a 4 byte instruction into two adds which are both 2 byte
803 ;; instructions. There are two cases: one where we are adding a
804 ;; constant plus a register to another register, and one where we are
805 ;; simply adding a constant to a register.
806
807 (define_split
808 [(set (match_operand:SI 0 "register_operand")
809 (plus:SI (match_dup 0)
810 (match_operand:SI 1 "const_int_operand")))]
811 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
812 && REG_P (operands[0])
813 && M16_REG_P (REGNO (operands[0]))
814 && GET_CODE (operands[1]) == CONST_INT
815 && ((INTVAL (operands[1]) > 0x7f
816 && INTVAL (operands[1]) <= 0x7f + 0x7f)
817 || (INTVAL (operands[1]) < - 0x80
818 && INTVAL (operands[1]) >= - 0x80 - 0x80))"
819 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
820 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
821 {
822 HOST_WIDE_INT val = INTVAL (operands[1]);
823
824 if (val >= 0)
825 {
826 operands[1] = GEN_INT (0x7f);
827 operands[2] = GEN_INT (val - 0x7f);
828 }
829 else
830 {
831 operands[1] = GEN_INT (- 0x80);
832 operands[2] = GEN_INT (val + 0x80);
833 }
834 })
835
836 (define_split
837 [(set (match_operand:SI 0 "register_operand")
838 (plus:SI (match_operand:SI 1 "register_operand")
839 (match_operand:SI 2 "const_int_operand")))]
840 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
841 && REG_P (operands[0])
842 && M16_REG_P (REGNO (operands[0]))
843 && REG_P (operands[1])
844 && M16_REG_P (REGNO (operands[1]))
845 && REGNO (operands[0]) != REGNO (operands[1])
846 && GET_CODE (operands[2]) == CONST_INT
847 && ((INTVAL (operands[2]) > 0x7
848 && INTVAL (operands[2]) <= 0x7 + 0x7f)
849 || (INTVAL (operands[2]) < - 0x8
850 && INTVAL (operands[2]) >= - 0x8 - 0x80))"
851 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
852 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
853 {
854 HOST_WIDE_INT val = INTVAL (operands[2]);
855
856 if (val >= 0)
857 {
858 operands[2] = GEN_INT (0x7);
859 operands[3] = GEN_INT (val - 0x7);
860 }
861 else
862 {
863 operands[2] = GEN_INT (- 0x8);
864 operands[3] = GEN_INT (val + 0x8);
865 }
866 })
867
868 (define_split
869 [(set (match_operand:DI 0 "register_operand")
870 (plus:DI (match_dup 0)
871 (match_operand:DI 1 "const_int_operand")))]
872 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
873 && REG_P (operands[0])
874 && M16_REG_P (REGNO (operands[0]))
875 && GET_CODE (operands[1]) == CONST_INT
876 && ((INTVAL (operands[1]) > 0xf
877 && INTVAL (operands[1]) <= 0xf + 0xf)
878 || (INTVAL (operands[1]) < - 0x10
879 && INTVAL (operands[1]) >= - 0x10 - 0x10))"
880 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
881 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
882 {
883 HOST_WIDE_INT val = INTVAL (operands[1]);
884
885 if (val >= 0)
886 {
887 operands[1] = GEN_INT (0xf);
888 operands[2] = GEN_INT (val - 0xf);
889 }
890 else
891 {
892 operands[1] = GEN_INT (- 0x10);
893 operands[2] = GEN_INT (val + 0x10);
894 }
895 })
896
897 (define_split
898 [(set (match_operand:DI 0 "register_operand")
899 (plus:DI (match_operand:DI 1 "register_operand")
900 (match_operand:DI 2 "const_int_operand")))]
901 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
902 && REG_P (operands[0])
903 && M16_REG_P (REGNO (operands[0]))
904 && REG_P (operands[1])
905 && M16_REG_P (REGNO (operands[1]))
906 && REGNO (operands[0]) != REGNO (operands[1])
907 && GET_CODE (operands[2]) == CONST_INT
908 && ((INTVAL (operands[2]) > 0x7
909 && INTVAL (operands[2]) <= 0x7 + 0xf)
910 || (INTVAL (operands[2]) < - 0x8
911 && INTVAL (operands[2]) >= - 0x8 - 0x10))"
912 [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
913 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
914 {
915 HOST_WIDE_INT val = INTVAL (operands[2]);
916
917 if (val >= 0)
918 {
919 operands[2] = GEN_INT (0x7);
920 operands[3] = GEN_INT (val - 0x7);
921 }
922 else
923 {
924 operands[2] = GEN_INT (- 0x8);
925 operands[3] = GEN_INT (val + 0x8);
926 }
927 })
928
929 (define_insn "*addsi3_extended"
930 [(set (match_operand:DI 0 "register_operand" "=d,d")
931 (sign_extend:DI
932 (plus:SI (match_operand:SI 1 "register_operand" "d,d")
933 (match_operand:SI 2 "arith_operand" "d,Q"))))]
934 "TARGET_64BIT && !TARGET_MIPS16"
935 "@
936 addu\t%0,%1,%2
937 addiu\t%0,%1,%2"
938 [(set_attr "type" "arith")
939 (set_attr "mode" "SI")])
940
941 ;; Split this insn so that the addiu splitters can have a crack at it.
942 ;; Use a conservative length estimate until the split.
943 (define_insn_and_split "*addsi3_extended_mips16"
944 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
945 (sign_extend:DI
946 (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
947 (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
948 "TARGET_64BIT && TARGET_MIPS16"
949 "#"
950 "&& reload_completed"
951 [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
952 { operands[3] = gen_lowpart (SImode, operands[0]); }
953 [(set_attr "type" "arith")
954 (set_attr "mode" "SI")
955 (set_attr "extended_mips16" "yes")])
956 \f
957 ;;
958 ;; ....................
959 ;;
960 ;; SUBTRACTION
961 ;;
962 ;; ....................
963 ;;
964
965 (define_insn "sub<mode>3"
966 [(set (match_operand:ANYF 0 "register_operand" "=f")
967 (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
968 (match_operand:ANYF 2 "register_operand" "f")))]
969 ""
970 "sub.<fmt>\t%0,%1,%2"
971 [(set_attr "type" "fadd")
972 (set_attr "mode" "<UNITMODE>")])
973
974 (define_insn "sub<mode>3"
975 [(set (match_operand:GPR 0 "register_operand" "=d")
976 (minus:GPR (match_operand:GPR 1 "register_operand" "d")
977 (match_operand:GPR 2 "register_operand" "d")))]
978 ""
979 "<d>subu\t%0,%1,%2"
980 [(set_attr "type" "arith")
981 (set_attr "mode" "<MODE>")])
982
983 (define_insn "*subsi3_extended"
984 [(set (match_operand:DI 0 "register_operand" "=d")
985 (sign_extend:DI
986 (minus:SI (match_operand:SI 1 "register_operand" "d")
987 (match_operand:SI 2 "register_operand" "d"))))]
988 "TARGET_64BIT"
989 "subu\t%0,%1,%2"
990 [(set_attr "type" "arith")
991 (set_attr "mode" "DI")])
992 \f
993 ;;
994 ;; ....................
995 ;;
996 ;; MULTIPLICATION
997 ;;
998 ;; ....................
999 ;;
1000
1001 (define_expand "mul<mode>3"
1002 [(set (match_operand:SCALARF 0 "register_operand")
1003 (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1004 (match_operand:SCALARF 2 "register_operand")))]
1005 ""
1006 "")
1007
1008 (define_insn "*mul<mode>3"
1009 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1010 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1011 (match_operand:SCALARF 2 "register_operand" "f")))]
1012 "!TARGET_4300_MUL_FIX"
1013 "mul.<fmt>\t%0,%1,%2"
1014 [(set_attr "type" "fmul")
1015 (set_attr "mode" "<MODE>")])
1016
1017 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1018 ;; operands may corrupt immediately following multiplies. This is a
1019 ;; simple fix to insert NOPs.
1020
1021 (define_insn "*mul<mode>3_r4300"
1022 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1023 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1024 (match_operand:SCALARF 2 "register_operand" "f")))]
1025 "TARGET_4300_MUL_FIX"
1026 "mul.<fmt>\t%0,%1,%2\;nop"
1027 [(set_attr "type" "fmul")
1028 (set_attr "mode" "<MODE>")
1029 (set_attr "length" "8")])
1030
1031 (define_insn "mulv2sf3"
1032 [(set (match_operand:V2SF 0 "register_operand" "=f")
1033 (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1034 (match_operand:V2SF 2 "register_operand" "f")))]
1035 "TARGET_PAIRED_SINGLE_FLOAT"
1036 "mul.ps\t%0,%1,%2"
1037 [(set_attr "type" "fmul")
1038 (set_attr "mode" "SF")])
1039
1040 ;; The original R4000 has a cpu bug. If a double-word or a variable
1041 ;; shift executes while an integer multiplication is in progress, the
1042 ;; shift may give an incorrect result. Avoid this by keeping the mflo
1043 ;; with the mult on the R4000.
1044 ;;
1045 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1046 ;; (also valid for MIPS R4000MC processors):
1047 ;;
1048 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1049 ;; this errata description.
1050 ;; The following code sequence causes the R4000 to incorrectly
1051 ;; execute the Double Shift Right Arithmetic 32 (dsra32)
1052 ;; instruction. If the dsra32 instruction is executed during an
1053 ;; integer multiply, the dsra32 will only shift by the amount in
1054 ;; specified in the instruction rather than the amount plus 32
1055 ;; bits.
1056 ;; instruction 1: mult rs,rt integer multiply
1057 ;; instruction 2-12: dsra32 rd,rt,rs doubleword shift
1058 ;; right arithmetic + 32
1059 ;; Workaround: A dsra32 instruction placed after an integer
1060 ;; multiply should not be one of the 11 instructions after the
1061 ;; multiply instruction."
1062 ;;
1063 ;; and:
1064 ;;
1065 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1066 ;; the following description.
1067 ;; All extended shifts (shift by n+32) and variable shifts (32 and
1068 ;; 64-bit versions) may produce incorrect results under the
1069 ;; following conditions:
1070 ;; 1) An integer multiply is currently executing
1071 ;; 2) These types of shift instructions are executed immediately
1072 ;; following an integer divide instruction.
1073 ;; Workaround:
1074 ;; 1) Make sure no integer multiply is running wihen these
1075 ;; instruction are executed. If this cannot be predicted at
1076 ;; compile time, then insert a "mfhi" to R0 instruction
1077 ;; immediately after the integer multiply instruction. This
1078 ;; will cause the integer multiply to complete before the shift
1079 ;; is executed.
1080 ;; 2) Separate integer divide and these two classes of shift
1081 ;; instructions by another instruction or a noop."
1082 ;;
1083 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1084 ;; respectively.
1085
1086 (define_expand "mulsi3"
1087 [(set (match_operand:SI 0 "register_operand")
1088 (mult:SI (match_operand:SI 1 "register_operand")
1089 (match_operand:SI 2 "register_operand")))]
1090 ""
1091 {
1092 if (ISA_HAS_MUL3)
1093 emit_insn (gen_mulsi3_mult3 (operands[0], operands[1], operands[2]));
1094 else if (TARGET_FIX_R4000)
1095 emit_insn (gen_mulsi3_r4000 (operands[0], operands[1], operands[2]));
1096 else
1097 emit_insn (gen_mulsi3_internal (operands[0], operands[1], operands[2]));
1098 DONE;
1099 })
1100
1101 (define_expand "muldi3"
1102 [(set (match_operand:DI 0 "register_operand")
1103 (mult:DI (match_operand:DI 1 "register_operand")
1104 (match_operand:DI 2 "register_operand")))]
1105 "TARGET_64BIT"
1106 {
1107 if (TARGET_FIX_R4000)
1108 emit_insn (gen_muldi3_r4000 (operands[0], operands[1], operands[2]));
1109 else
1110 emit_insn (gen_muldi3_internal (operands[0], operands[1], operands[2]));
1111 DONE;
1112 })
1113
1114 (define_insn "mulsi3_mult3"
1115 [(set (match_operand:SI 0 "register_operand" "=d,l")
1116 (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1117 (match_operand:SI 2 "register_operand" "d,d")))
1118 (clobber (match_scratch:SI 3 "=h,h"))
1119 (clobber (match_scratch:SI 4 "=l,X"))]
1120 "ISA_HAS_MUL3"
1121 {
1122 if (which_alternative == 1)
1123 return "mult\t%1,%2";
1124 if (TARGET_MIPS3900)
1125 return "mult\t%0,%1,%2";
1126 return "mul\t%0,%1,%2";
1127 }
1128 [(set_attr "type" "imul3,imul")
1129 (set_attr "mode" "SI")])
1130
1131 ;; If a register gets allocated to LO, and we spill to memory, the reload
1132 ;; will include a move from LO to a GPR. Merge it into the multiplication
1133 ;; if it can set the GPR directly.
1134 ;;
1135 ;; Operand 0: LO
1136 ;; Operand 1: GPR (1st multiplication operand)
1137 ;; Operand 2: GPR (2nd multiplication operand)
1138 ;; Operand 3: HI
1139 ;; Operand 4: GPR (destination)
1140 (define_peephole2
1141 [(parallel
1142 [(set (match_operand:SI 0 "register_operand")
1143 (mult:SI (match_operand:SI 1 "register_operand")
1144 (match_operand:SI 2 "register_operand")))
1145 (clobber (match_operand:SI 3 "register_operand"))
1146 (clobber (scratch:SI))])
1147 (set (match_operand:SI 4 "register_operand")
1148 (unspec [(match_dup 0) (match_dup 3)] UNSPEC_MFHILO))]
1149 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1150 [(parallel
1151 [(set (match_dup 4)
1152 (mult:SI (match_dup 1)
1153 (match_dup 2)))
1154 (clobber (match_dup 3))
1155 (clobber (match_dup 0))])])
1156
1157 (define_insn "mul<mode>3_internal"
1158 [(set (match_operand:GPR 0 "register_operand" "=l")
1159 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1160 (match_operand:GPR 2 "register_operand" "d")))
1161 (clobber (match_scratch:GPR 3 "=h"))]
1162 "!TARGET_FIX_R4000"
1163 "<d>mult\t%1,%2"
1164 [(set_attr "type" "imul")
1165 (set_attr "mode" "<MODE>")])
1166
1167 (define_insn "mul<mode>3_r4000"
1168 [(set (match_operand:GPR 0 "register_operand" "=d")
1169 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1170 (match_operand:GPR 2 "register_operand" "d")))
1171 (clobber (match_scratch:GPR 3 "=h"))
1172 (clobber (match_scratch:GPR 4 "=l"))]
1173 "TARGET_FIX_R4000"
1174 "<d>mult\t%1,%2\;mflo\t%0"
1175 [(set_attr "type" "imul")
1176 (set_attr "mode" "<MODE>")
1177 (set_attr "length" "8")])
1178
1179 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1180 ;; of "mult; mflo". They have the same latency, but the first form gives
1181 ;; us an extra cycle to compute the operands.
1182
1183 ;; Operand 0: LO
1184 ;; Operand 1: GPR (1st multiplication operand)
1185 ;; Operand 2: GPR (2nd multiplication operand)
1186 ;; Operand 3: HI
1187 ;; Operand 4: GPR (destination)
1188 (define_peephole2
1189 [(parallel
1190 [(set (match_operand:SI 0 "register_operand")
1191 (mult:SI (match_operand:SI 1 "register_operand")
1192 (match_operand:SI 2 "register_operand")))
1193 (clobber (match_operand:SI 3 "register_operand"))])
1194 (set (match_operand:SI 4 "register_operand")
1195 (unspec:SI [(match_dup 0) (match_dup 3)] UNSPEC_MFHILO))]
1196 "ISA_HAS_MACC && !ISA_HAS_MUL3"
1197 [(set (match_dup 0)
1198 (const_int 0))
1199 (parallel
1200 [(set (match_dup 0)
1201 (plus:SI (mult:SI (match_dup 1)
1202 (match_dup 2))
1203 (match_dup 0)))
1204 (set (match_dup 4)
1205 (plus:SI (mult:SI (match_dup 1)
1206 (match_dup 2))
1207 (match_dup 0)))
1208 (clobber (match_dup 3))])])
1209
1210 ;; Multiply-accumulate patterns
1211
1212 ;; For processors that can copy the output to a general register:
1213 ;;
1214 ;; The all-d alternative is needed because the combiner will find this
1215 ;; pattern and then register alloc/reload will move registers around to
1216 ;; make them fit, and we don't want to trigger unnecessary loads to LO.
1217 ;;
1218 ;; The last alternative should be made slightly less desirable, but adding
1219 ;; "?" to the constraint is too strong, and causes values to be loaded into
1220 ;; LO even when that's more costly. For now, using "*d" mostly does the
1221 ;; trick.
1222 (define_insn "*mul_acc_si"
1223 [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
1224 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1225 (match_operand:SI 2 "register_operand" "d,d,d"))
1226 (match_operand:SI 3 "register_operand" "0,l,*d")))
1227 (clobber (match_scratch:SI 4 "=h,h,h"))
1228 (clobber (match_scratch:SI 5 "=X,3,l"))
1229 (clobber (match_scratch:SI 6 "=X,X,&d"))]
1230 "(TARGET_MIPS3900
1231 || GENERATE_MADD_MSUB)
1232 && !TARGET_MIPS16"
1233 {
1234 static const char *const madd[] = { "madd\t%1,%2", "madd\t%0,%1,%2" };
1235 if (which_alternative == 2)
1236 return "#";
1237 if (GENERATE_MADD_MSUB && which_alternative != 0)
1238 return "#";
1239 return madd[which_alternative];
1240 }
1241 [(set_attr "type" "imadd")
1242 (set_attr "mode" "SI")
1243 (set_attr "length" "4,4,8")])
1244
1245 ;; Split the above insn if we failed to get LO allocated.
1246 (define_split
1247 [(set (match_operand:SI 0 "register_operand")
1248 (plus:SI (mult:SI (match_operand:SI 1 "register_operand")
1249 (match_operand:SI 2 "register_operand"))
1250 (match_operand:SI 3 "register_operand")))
1251 (clobber (match_scratch:SI 4))
1252 (clobber (match_scratch:SI 5))
1253 (clobber (match_scratch:SI 6))]
1254 "reload_completed && !TARGET_DEBUG_D_MODE
1255 && GP_REG_P (true_regnum (operands[0]))
1256 && GP_REG_P (true_regnum (operands[3]))"
1257 [(parallel [(set (match_dup 6)
1258 (mult:SI (match_dup 1) (match_dup 2)))
1259 (clobber (match_dup 4))
1260 (clobber (match_dup 5))])
1261 (set (match_dup 0) (plus:SI (match_dup 6) (match_dup 3)))]
1262 "")
1263
1264 ;; Splitter to copy result of MADD to a general register
1265 (define_split
1266 [(set (match_operand:SI 0 "register_operand")
1267 (plus:SI (mult:SI (match_operand:SI 1 "register_operand")
1268 (match_operand:SI 2 "register_operand"))
1269 (match_operand:SI 3 "register_operand")))
1270 (clobber (match_scratch:SI 4))
1271 (clobber (match_scratch:SI 5))
1272 (clobber (match_scratch:SI 6))]
1273 "reload_completed && !TARGET_DEBUG_D_MODE
1274 && GP_REG_P (true_regnum (operands[0]))
1275 && true_regnum (operands[3]) == LO_REGNUM"
1276 [(parallel [(set (match_dup 3)
1277 (plus:SI (mult:SI (match_dup 1) (match_dup 2))
1278 (match_dup 3)))
1279 (clobber (match_dup 4))
1280 (clobber (match_dup 5))
1281 (clobber (match_dup 6))])
1282 (set (match_dup 0) (unspec:SI [(match_dup 5) (match_dup 4)] UNSPEC_MFHILO))]
1283 "")
1284
1285 (define_insn "*macc"
1286 [(set (match_operand:SI 0 "register_operand" "=l,d")
1287 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1288 (match_operand:SI 2 "register_operand" "d,d"))
1289 (match_operand:SI 3 "register_operand" "0,l")))
1290 (clobber (match_scratch:SI 4 "=h,h"))
1291 (clobber (match_scratch:SI 5 "=X,3"))]
1292 "ISA_HAS_MACC"
1293 {
1294 if (which_alternative == 1)
1295 return "macc\t%0,%1,%2";
1296 else if (TARGET_MIPS5500)
1297 return "madd\t%1,%2";
1298 else
1299 /* The VR4130 assumes that there is a two-cycle latency between a macc
1300 that "writes" to $0 and an instruction that reads from it. We avoid
1301 this by assigning to $1 instead. */
1302 return "%[macc\t%@,%1,%2%]";
1303 }
1304 [(set_attr "type" "imadd")
1305 (set_attr "mode" "SI")])
1306
1307 (define_insn "*msac"
1308 [(set (match_operand:SI 0 "register_operand" "=l,d")
1309 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1310 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1311 (match_operand:SI 3 "register_operand" "d,d"))))
1312 (clobber (match_scratch:SI 4 "=h,h"))
1313 (clobber (match_scratch:SI 5 "=X,1"))]
1314 "ISA_HAS_MSAC"
1315 {
1316 if (which_alternative == 1)
1317 return "msac\t%0,%2,%3";
1318 else if (TARGET_MIPS5500)
1319 return "msub\t%2,%3";
1320 else
1321 return "msac\t$0,%2,%3";
1322 }
1323 [(set_attr "type" "imadd")
1324 (set_attr "mode" "SI")])
1325
1326 ;; An msac-like instruction implemented using negation and a macc.
1327 (define_insn_and_split "*msac_using_macc"
1328 [(set (match_operand:SI 0 "register_operand" "=l,d")
1329 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1330 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1331 (match_operand:SI 3 "register_operand" "d,d"))))
1332 (clobber (match_scratch:SI 4 "=h,h"))
1333 (clobber (match_scratch:SI 5 "=X,1"))
1334 (clobber (match_scratch:SI 6 "=d,d"))]
1335 "ISA_HAS_MACC && !ISA_HAS_MSAC"
1336 "#"
1337 "&& reload_completed"
1338 [(set (match_dup 6)
1339 (neg:SI (match_dup 3)))
1340 (parallel
1341 [(set (match_dup 0)
1342 (plus:SI (mult:SI (match_dup 2)
1343 (match_dup 6))
1344 (match_dup 1)))
1345 (clobber (match_dup 4))
1346 (clobber (match_dup 5))])]
1347 ""
1348 [(set_attr "type" "imadd")
1349 (set_attr "length" "8")])
1350
1351 ;; Patterns generated by the define_peephole2 below.
1352
1353 (define_insn "*macc2"
1354 [(set (match_operand:SI 0 "register_operand" "=l")
1355 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1356 (match_operand:SI 2 "register_operand" "d"))
1357 (match_dup 0)))
1358 (set (match_operand:SI 3 "register_operand" "=d")
1359 (plus:SI (mult:SI (match_dup 1)
1360 (match_dup 2))
1361 (match_dup 0)))
1362 (clobber (match_scratch:SI 4 "=h"))]
1363 "ISA_HAS_MACC && reload_completed"
1364 "macc\t%3,%1,%2"
1365 [(set_attr "type" "imadd")
1366 (set_attr "mode" "SI")])
1367
1368 (define_insn "*msac2"
1369 [(set (match_operand:SI 0 "register_operand" "=l")
1370 (minus:SI (match_dup 0)
1371 (mult:SI (match_operand:SI 1 "register_operand" "d")
1372 (match_operand:SI 2 "register_operand" "d"))))
1373 (set (match_operand:SI 3 "register_operand" "=d")
1374 (minus:SI (match_dup 0)
1375 (mult:SI (match_dup 1)
1376 (match_dup 2))))
1377 (clobber (match_scratch:SI 4 "=h"))]
1378 "ISA_HAS_MSAC && reload_completed"
1379 "msac\t%3,%1,%2"
1380 [(set_attr "type" "imadd")
1381 (set_attr "mode" "SI")])
1382
1383 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1384 ;; Similarly msac.
1385 ;;
1386 ;; Operand 0: LO
1387 ;; Operand 1: macc/msac
1388 ;; Operand 2: HI
1389 ;; Operand 3: GPR (destination)
1390 (define_peephole2
1391 [(parallel
1392 [(set (match_operand:SI 0 "register_operand")
1393 (match_operand:SI 1 "macc_msac_operand"))
1394 (clobber (match_operand:SI 2 "register_operand"))
1395 (clobber (scratch:SI))])
1396 (set (match_operand:SI 3 "register_operand")
1397 (unspec:SI [(match_dup 0) (match_dup 2)] UNSPEC_MFHILO))]
1398 ""
1399 [(parallel [(set (match_dup 0)
1400 (match_dup 1))
1401 (set (match_dup 3)
1402 (match_dup 1))
1403 (clobber (match_dup 2))])]
1404 "")
1405
1406 ;; When we have a three-address multiplication instruction, it should
1407 ;; be faster to do a separate multiply and add, rather than moving
1408 ;; something into LO in order to use a macc instruction.
1409 ;;
1410 ;; This peephole needs a scratch register to cater for the case when one
1411 ;; of the multiplication operands is the same as the destination.
1412 ;;
1413 ;; Operand 0: GPR (scratch)
1414 ;; Operand 1: LO
1415 ;; Operand 2: GPR (addend)
1416 ;; Operand 3: GPR (destination)
1417 ;; Operand 4: macc/msac
1418 ;; Operand 5: HI
1419 ;; Operand 6: new multiplication
1420 ;; Operand 7: new addition/subtraction
1421 (define_peephole2
1422 [(match_scratch:SI 0 "d")
1423 (set (match_operand:SI 1 "register_operand")
1424 (match_operand:SI 2 "register_operand"))
1425 (match_dup 0)
1426 (parallel
1427 [(set (match_operand:SI 3 "register_operand")
1428 (match_operand:SI 4 "macc_msac_operand"))
1429 (clobber (match_operand:SI 5 "register_operand"))
1430 (clobber (match_dup 1))])]
1431 "ISA_HAS_MUL3
1432 && true_regnum (operands[1]) == LO_REGNUM
1433 && peep2_reg_dead_p (2, operands[1])
1434 && GP_REG_P (true_regnum (operands[3]))"
1435 [(parallel [(set (match_dup 0)
1436 (match_dup 6))
1437 (clobber (match_dup 5))
1438 (clobber (match_dup 1))])
1439 (set (match_dup 3)
1440 (match_dup 7))]
1441 {
1442 operands[6] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1443 operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1444 operands[2], operands[0]);
1445 })
1446
1447 ;; Same as above, except LO is the initial target of the macc.
1448 ;;
1449 ;; Operand 0: GPR (scratch)
1450 ;; Operand 1: LO
1451 ;; Operand 2: GPR (addend)
1452 ;; Operand 3: macc/msac
1453 ;; Operand 4: HI
1454 ;; Operand 5: GPR (destination)
1455 ;; Operand 6: new multiplication
1456 ;; Operand 7: new addition/subtraction
1457 (define_peephole2
1458 [(match_scratch:SI 0 "d")
1459 (set (match_operand:SI 1 "register_operand")
1460 (match_operand:SI 2 "register_operand"))
1461 (match_dup 0)
1462 (parallel
1463 [(set (match_dup 1)
1464 (match_operand:SI 3 "macc_msac_operand"))
1465 (clobber (match_operand:SI 4 "register_operand"))
1466 (clobber (scratch:SI))])
1467 (match_dup 0)
1468 (set (match_operand:SI 5 "register_operand")
1469 (unspec:SI [(match_dup 1) (match_dup 4)] UNSPEC_MFHILO))]
1470 "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1471 [(parallel [(set (match_dup 0)
1472 (match_dup 6))
1473 (clobber (match_dup 4))
1474 (clobber (match_dup 1))])
1475 (set (match_dup 5)
1476 (match_dup 7))]
1477 {
1478 operands[6] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1479 operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1480 operands[2], operands[0]);
1481 })
1482
1483 (define_insn "*mul_sub_si"
1484 [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
1485 (minus:SI (match_operand:SI 1 "register_operand" "0,l,*d")
1486 (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
1487 (match_operand:SI 3 "register_operand" "d,d,d"))))
1488 (clobber (match_scratch:SI 4 "=h,h,h"))
1489 (clobber (match_scratch:SI 5 "=X,1,l"))
1490 (clobber (match_scratch:SI 6 "=X,X,&d"))]
1491 "GENERATE_MADD_MSUB"
1492 "@
1493 msub\t%2,%3
1494 #
1495 #"
1496 [(set_attr "type" "imadd")
1497 (set_attr "mode" "SI")
1498 (set_attr "length" "4,8,8")])
1499
1500 ;; Split the above insn if we failed to get LO allocated.
1501 (define_split
1502 [(set (match_operand:SI 0 "register_operand")
1503 (minus:SI (match_operand:SI 1 "register_operand")
1504 (mult:SI (match_operand:SI 2 "register_operand")
1505 (match_operand:SI 3 "register_operand"))))
1506 (clobber (match_scratch:SI 4))
1507 (clobber (match_scratch:SI 5))
1508 (clobber (match_scratch:SI 6))]
1509 "reload_completed && !TARGET_DEBUG_D_MODE
1510 && GP_REG_P (true_regnum (operands[0]))
1511 && GP_REG_P (true_regnum (operands[1]))"
1512 [(parallel [(set (match_dup 6)
1513 (mult:SI (match_dup 2) (match_dup 3)))
1514 (clobber (match_dup 4))
1515 (clobber (match_dup 5))])
1516 (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 6)))]
1517 "")
1518
1519 ;; Splitter to copy result of MSUB to a general register
1520 (define_split
1521 [(set (match_operand:SI 0 "register_operand")
1522 (minus:SI (match_operand:SI 1 "register_operand")
1523 (mult:SI (match_operand:SI 2 "register_operand")
1524 (match_operand:SI 3 "register_operand"))))
1525 (clobber (match_scratch:SI 4))
1526 (clobber (match_scratch:SI 5))
1527 (clobber (match_scratch:SI 6))]
1528 "reload_completed && !TARGET_DEBUG_D_MODE
1529 && GP_REG_P (true_regnum (operands[0]))
1530 && true_regnum (operands[1]) == LO_REGNUM"
1531 [(parallel [(set (match_dup 1)
1532 (minus:SI (match_dup 1)
1533 (mult:SI (match_dup 2) (match_dup 3))))
1534 (clobber (match_dup 4))
1535 (clobber (match_dup 5))
1536 (clobber (match_dup 6))])
1537 (set (match_dup 0) (unspec:SI [(match_dup 5) (match_dup 4)] UNSPEC_MFHILO))]
1538 "")
1539
1540 (define_insn "*muls"
1541 [(set (match_operand:SI 0 "register_operand" "=l,d")
1542 (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1543 (match_operand:SI 2 "register_operand" "d,d"))))
1544 (clobber (match_scratch:SI 3 "=h,h"))
1545 (clobber (match_scratch:SI 4 "=X,l"))]
1546 "ISA_HAS_MULS"
1547 "@
1548 muls\t$0,%1,%2
1549 muls\t%0,%1,%2"
1550 [(set_attr "type" "imul,imul3")
1551 (set_attr "mode" "SI")])
1552
1553 ;; ??? We could define a mulditi3 pattern when TARGET_64BIT.
1554
1555 (define_expand "<u>mulsidi3"
1556 [(parallel
1557 [(set (match_operand:DI 0 "register_operand")
1558 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1559 (any_extend:DI (match_operand:SI 2 "register_operand"))))
1560 (clobber (scratch:DI))
1561 (clobber (scratch:DI))
1562 (clobber (scratch:DI))])]
1563 "!TARGET_64BIT || !TARGET_FIX_R4000"
1564 {
1565 if (!TARGET_64BIT)
1566 {
1567 if (!TARGET_FIX_R4000)
1568 emit_insn (gen_<u>mulsidi3_32bit_internal (operands[0], operands[1],
1569 operands[2]));
1570 else
1571 emit_insn (gen_<u>mulsidi3_32bit_r4000 (operands[0], operands[1],
1572 operands[2]));
1573 DONE;
1574 }
1575 })
1576
1577 (define_insn "<u>mulsidi3_32bit_internal"
1578 [(set (match_operand:DI 0 "register_operand" "=x")
1579 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1580 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
1581 "!TARGET_64BIT && !TARGET_FIX_R4000 && !TARGET_DSPR2"
1582 "mult<u>\t%1,%2"
1583 [(set_attr "type" "imul")
1584 (set_attr "mode" "SI")])
1585
1586 (define_insn "<u>mulsidi3_32bit_r4000"
1587 [(set (match_operand:DI 0 "register_operand" "=d")
1588 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1589 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1590 (clobber (match_scratch:DI 3 "=x"))]
1591 "!TARGET_64BIT && TARGET_FIX_R4000"
1592 "mult<u>\t%1,%2\;mflo\t%L0;mfhi\t%M0"
1593 [(set_attr "type" "imul")
1594 (set_attr "mode" "SI")
1595 (set_attr "length" "12")])
1596
1597 (define_insn_and_split "*<u>mulsidi3_64bit"
1598 [(set (match_operand:DI 0 "register_operand" "=d")
1599 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1600 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1601 (clobber (match_scratch:DI 3 "=l"))
1602 (clobber (match_scratch:DI 4 "=h"))
1603 (clobber (match_scratch:DI 5 "=d"))]
1604 "TARGET_64BIT && !TARGET_FIX_R4000"
1605 "#"
1606 "&& reload_completed"
1607 [(parallel
1608 [(set (match_dup 3)
1609 (sign_extend:DI
1610 (mult:SI (match_dup 1)
1611 (match_dup 2))))
1612 (set (match_dup 4)
1613 (ashiftrt:DI
1614 (mult:DI (any_extend:DI (match_dup 1))
1615 (any_extend:DI (match_dup 2)))
1616 (const_int 32)))])
1617
1618 ;; OP5 <- LO, OP0 <- HI
1619 (set (match_dup 5) (unspec:DI [(match_dup 3) (match_dup 4)] UNSPEC_MFHILO))
1620 (set (match_dup 0) (unspec:DI [(match_dup 4) (match_dup 3)] UNSPEC_MFHILO))
1621
1622 ;; Zero-extend OP5.
1623 (set (match_dup 5)
1624 (ashift:DI (match_dup 5)
1625 (const_int 32)))
1626 (set (match_dup 5)
1627 (lshiftrt:DI (match_dup 5)
1628 (const_int 32)))
1629
1630 ;; Shift OP0 into place.
1631 (set (match_dup 0)
1632 (ashift:DI (match_dup 0)
1633 (const_int 32)))
1634
1635 ;; OR the two halves together
1636 (set (match_dup 0)
1637 (ior:DI (match_dup 0)
1638 (match_dup 5)))]
1639 ""
1640 [(set_attr "type" "imul")
1641 (set_attr "mode" "SI")
1642 (set_attr "length" "24")])
1643
1644 (define_insn "*<u>mulsidi3_64bit_parts"
1645 [(set (match_operand:DI 0 "register_operand" "=l")
1646 (sign_extend:DI
1647 (mult:SI (match_operand:SI 2 "register_operand" "d")
1648 (match_operand:SI 3 "register_operand" "d"))))
1649 (set (match_operand:DI 1 "register_operand" "=h")
1650 (ashiftrt:DI
1651 (mult:DI (any_extend:DI (match_dup 2))
1652 (any_extend:DI (match_dup 3)))
1653 (const_int 32)))]
1654 "TARGET_64BIT && !TARGET_FIX_R4000"
1655 "mult<u>\t%2,%3"
1656 [(set_attr "type" "imul")
1657 (set_attr "mode" "SI")])
1658
1659 ;; Widening multiply with negation.
1660 (define_insn "*muls<u>_di"
1661 [(set (match_operand:DI 0 "register_operand" "=x")
1662 (neg:DI
1663 (mult:DI
1664 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1665 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1666 "!TARGET_64BIT && ISA_HAS_MULS"
1667 "muls<u>\t$0,%1,%2"
1668 [(set_attr "type" "imul")
1669 (set_attr "mode" "SI")])
1670
1671 (define_insn "<u>msubsidi4"
1672 [(set (match_operand:DI 0 "register_operand" "=ka")
1673 (minus:DI
1674 (match_operand:DI 3 "register_operand" "0")
1675 (mult:DI
1676 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1677 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1678 "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || TARGET_DSPR2)"
1679 {
1680 if (TARGET_DSPR2)
1681 return "msub<u>\t%q0,%1,%2";
1682 else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
1683 return "msub<u>\t%1,%2";
1684 else
1685 return "msac<u>\t$0,%1,%2";
1686 }
1687 [(set_attr "type" "imadd")
1688 (set_attr "mode" "SI")])
1689
1690 ;; _highpart patterns
1691
1692 (define_expand "<su>mulsi3_highpart"
1693 [(set (match_operand:SI 0 "register_operand")
1694 (truncate:SI
1695 (lshiftrt:DI
1696 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1697 (any_extend:DI (match_operand:SI 2 "register_operand")))
1698 (const_int 32))))]
1699 "ISA_HAS_MULHI || !TARGET_FIX_R4000"
1700 {
1701 if (ISA_HAS_MULHI)
1702 emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
1703 operands[1],
1704 operands[2]));
1705 else
1706 emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
1707 operands[2]));
1708 DONE;
1709 })
1710
1711 (define_insn "<su>mulsi3_highpart_internal"
1712 [(set (match_operand:SI 0 "register_operand" "=h")
1713 (truncate:SI
1714 (lshiftrt:DI
1715 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1716 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1717 (const_int 32))))
1718 (clobber (match_scratch:SI 3 "=l"))]
1719 "!ISA_HAS_MULHI && !TARGET_FIX_R4000"
1720 "mult<u>\t%1,%2"
1721 [(set_attr "type" "imul")
1722 (set_attr "mode" "SI")])
1723
1724 (define_insn "<su>mulsi3_highpart_mulhi_internal"
1725 [(set (match_operand:SI 0 "register_operand" "=h,d")
1726 (truncate:SI
1727 (lshiftrt:DI
1728 (mult:DI
1729 (any_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
1730 (any_extend:DI (match_operand:SI 2 "register_operand" "d,d")))
1731 (const_int 32))))
1732 (clobber (match_scratch:SI 3 "=l,l"))
1733 (clobber (match_scratch:SI 4 "=X,h"))]
1734 "ISA_HAS_MULHI"
1735 "@
1736 mult<u>\t%1,%2
1737 mulhi<u>\t%0,%1,%2"
1738 [(set_attr "type" "imul,imul3")
1739 (set_attr "mode" "SI")])
1740
1741 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
1742 [(set (match_operand:SI 0 "register_operand" "=h,d")
1743 (truncate:SI
1744 (lshiftrt:DI
1745 (neg:DI
1746 (mult:DI
1747 (any_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
1748 (any_extend:DI (match_operand:SI 2 "register_operand" "d,d"))))
1749 (const_int 32))))
1750 (clobber (match_scratch:SI 3 "=l,l"))
1751 (clobber (match_scratch:SI 4 "=X,h"))]
1752 "ISA_HAS_MULHI"
1753 "@
1754 mulshi<u>\t%.,%1,%2
1755 mulshi<u>\t%0,%1,%2"
1756 [(set_attr "type" "imul,imul3")
1757 (set_attr "mode" "SI")])
1758
1759 ;; Disable unsigned multiplication for -mfix-vr4120. This is for VR4120
1760 ;; errata MD(0), which says that dmultu does not always produce the
1761 ;; correct result.
1762 (define_insn "<su>muldi3_highpart"
1763 [(set (match_operand:DI 0 "register_operand" "=h")
1764 (truncate:DI
1765 (lshiftrt:TI
1766 (mult:TI
1767 (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
1768 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
1769 (const_int 64))))
1770 (clobber (match_scratch:DI 3 "=l"))]
1771 "TARGET_64BIT && !TARGET_FIX_R4000
1772 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
1773 "dmult<u>\t%1,%2"
1774 [(set_attr "type" "imul")
1775 (set_attr "mode" "DI")])
1776
1777 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
1778 ;; instruction. The HI/LO registers are used as a 64-bit accumulator.
1779
1780 (define_insn "madsi"
1781 [(set (match_operand:SI 0 "register_operand" "+l")
1782 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1783 (match_operand:SI 2 "register_operand" "d"))
1784 (match_dup 0)))
1785 (clobber (match_scratch:SI 3 "=h"))]
1786 "TARGET_MAD"
1787 "mad\t%1,%2"
1788 [(set_attr "type" "imadd")
1789 (set_attr "mode" "SI")])
1790
1791 (define_insn "<u>maddsidi4"
1792 [(set (match_operand:DI 0 "register_operand" "=ka")
1793 (plus:DI
1794 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1795 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1796 (match_operand:DI 3 "register_operand" "0")))]
1797 "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || TARGET_DSPR2)
1798 && !TARGET_64BIT"
1799 {
1800 if (TARGET_MAD)
1801 return "mad<u>\t%1,%2";
1802 else if (TARGET_DSPR2)
1803 return "madd<u>\t%q0,%1,%2";
1804 else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
1805 return "madd<u>\t%1,%2";
1806 else
1807 /* See comment in *macc. */
1808 return "%[macc<u>\t%@,%1,%2%]";
1809 }
1810 [(set_attr "type" "imadd")
1811 (set_attr "mode" "SI")])
1812
1813 ;; Floating point multiply accumulate instructions.
1814
1815 (define_insn "*madd<mode>"
1816 [(set (match_operand:ANYF 0 "register_operand" "=f")
1817 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1818 (match_operand:ANYF 2 "register_operand" "f"))
1819 (match_operand:ANYF 3 "register_operand" "f")))]
1820 "ISA_HAS_FP4 && TARGET_FUSED_MADD"
1821 "madd.<fmt>\t%0,%3,%1,%2"
1822 [(set_attr "type" "fmadd")
1823 (set_attr "mode" "<UNITMODE>")])
1824
1825 (define_insn "*msub<mode>"
1826 [(set (match_operand:ANYF 0 "register_operand" "=f")
1827 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1828 (match_operand:ANYF 2 "register_operand" "f"))
1829 (match_operand:ANYF 3 "register_operand" "f")))]
1830 "ISA_HAS_FP4 && TARGET_FUSED_MADD"
1831 "msub.<fmt>\t%0,%3,%1,%2"
1832 [(set_attr "type" "fmadd")
1833 (set_attr "mode" "<UNITMODE>")])
1834
1835 (define_insn "*nmadd<mode>"
1836 [(set (match_operand:ANYF 0 "register_operand" "=f")
1837 (neg:ANYF (plus:ANYF
1838 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1839 (match_operand:ANYF 2 "register_operand" "f"))
1840 (match_operand:ANYF 3 "register_operand" "f"))))]
1841 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1842 && HONOR_SIGNED_ZEROS (<MODE>mode)
1843 && !HONOR_NANS (<MODE>mode)"
1844 "nmadd.<fmt>\t%0,%3,%1,%2"
1845 [(set_attr "type" "fmadd")
1846 (set_attr "mode" "<UNITMODE>")])
1847
1848 (define_insn "*nmadd<mode>_fastmath"
1849 [(set (match_operand:ANYF 0 "register_operand" "=f")
1850 (minus:ANYF
1851 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
1852 (match_operand:ANYF 2 "register_operand" "f"))
1853 (match_operand:ANYF 3 "register_operand" "f")))]
1854 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1855 && !HONOR_SIGNED_ZEROS (<MODE>mode)
1856 && !HONOR_NANS (<MODE>mode)"
1857 "nmadd.<fmt>\t%0,%3,%1,%2"
1858 [(set_attr "type" "fmadd")
1859 (set_attr "mode" "<UNITMODE>")])
1860
1861 (define_insn "*nmsub<mode>"
1862 [(set (match_operand:ANYF 0 "register_operand" "=f")
1863 (neg:ANYF (minus:ANYF
1864 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
1865 (match_operand:ANYF 3 "register_operand" "f"))
1866 (match_operand:ANYF 1 "register_operand" "f"))))]
1867 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1868 && HONOR_SIGNED_ZEROS (<MODE>mode)
1869 && !HONOR_NANS (<MODE>mode)"
1870 "nmsub.<fmt>\t%0,%1,%2,%3"
1871 [(set_attr "type" "fmadd")
1872 (set_attr "mode" "<UNITMODE>")])
1873
1874 (define_insn "*nmsub<mode>_fastmath"
1875 [(set (match_operand:ANYF 0 "register_operand" "=f")
1876 (minus:ANYF
1877 (match_operand:ANYF 1 "register_operand" "f")
1878 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
1879 (match_operand:ANYF 3 "register_operand" "f"))))]
1880 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1881 && !HONOR_SIGNED_ZEROS (<MODE>mode)
1882 && !HONOR_NANS (<MODE>mode)"
1883 "nmsub.<fmt>\t%0,%1,%2,%3"
1884 [(set_attr "type" "fmadd")
1885 (set_attr "mode" "<UNITMODE>")])
1886 \f
1887 ;;
1888 ;; ....................
1889 ;;
1890 ;; DIVISION and REMAINDER
1891 ;;
1892 ;; ....................
1893 ;;
1894
1895 (define_expand "div<mode>3"
1896 [(set (match_operand:ANYF 0 "register_operand")
1897 (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
1898 (match_operand:ANYF 2 "register_operand")))]
1899 "<divide_condition>"
1900 {
1901 if (const_1_operand (operands[1], <MODE>mode))
1902 if (!(ISA_HAS_FP4 && flag_unsafe_math_optimizations))
1903 operands[1] = force_reg (<MODE>mode, operands[1]);
1904 })
1905
1906 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
1907 ;;
1908 ;; If an mfc1 or dmfc1 happens to access the floating point register
1909 ;; file at the same time a long latency operation (div, sqrt, recip,
1910 ;; sqrt) iterates an intermediate result back through the floating
1911 ;; point register file bypass, then instead returning the correct
1912 ;; register value the mfc1 or dmfc1 operation returns the intermediate
1913 ;; result of the long latency operation.
1914 ;;
1915 ;; The workaround is to insert an unconditional 'mov' from/to the
1916 ;; long latency op destination register.
1917
1918 (define_insn "*div<mode>3"
1919 [(set (match_operand:ANYF 0 "register_operand" "=f")
1920 (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
1921 (match_operand:ANYF 2 "register_operand" "f")))]
1922 "<divide_condition>"
1923 {
1924 if (TARGET_FIX_SB1)
1925 return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
1926 else
1927 return "div.<fmt>\t%0,%1,%2";
1928 }
1929 [(set_attr "type" "fdiv")
1930 (set_attr "mode" "<UNITMODE>")
1931 (set (attr "length")
1932 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1933 (const_int 8)
1934 (const_int 4)))])
1935
1936 (define_insn "*recip<mode>3"
1937 [(set (match_operand:ANYF 0 "register_operand" "=f")
1938 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
1939 (match_operand:ANYF 2 "register_operand" "f")))]
1940 "<recip_condition> && flag_unsafe_math_optimizations"
1941 {
1942 if (TARGET_FIX_SB1)
1943 return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
1944 else
1945 return "recip.<fmt>\t%0,%2";
1946 }
1947 [(set_attr "type" "frdiv")
1948 (set_attr "mode" "<UNITMODE>")
1949 (set (attr "length")
1950 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1951 (const_int 8)
1952 (const_int 4)))])
1953
1954 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
1955 ;; with negative operands. We use special libgcc functions instead.
1956 (define_insn "divmod<mode>4"
1957 [(set (match_operand:GPR 0 "register_operand" "=l")
1958 (div:GPR (match_operand:GPR 1 "register_operand" "d")
1959 (match_operand:GPR 2 "register_operand" "d")))
1960 (set (match_operand:GPR 3 "register_operand" "=h")
1961 (mod:GPR (match_dup 1)
1962 (match_dup 2)))]
1963 "!TARGET_FIX_VR4120"
1964 { return mips_output_division ("<d>div\t$0,%1,%2", operands); }
1965 [(set_attr "type" "idiv")
1966 (set_attr "mode" "<MODE>")])
1967
1968 (define_insn "udivmod<mode>4"
1969 [(set (match_operand:GPR 0 "register_operand" "=l")
1970 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
1971 (match_operand:GPR 2 "register_operand" "d")))
1972 (set (match_operand:GPR 3 "register_operand" "=h")
1973 (umod:GPR (match_dup 1)
1974 (match_dup 2)))]
1975 ""
1976 { return mips_output_division ("<d>divu\t$0,%1,%2", operands); }
1977 [(set_attr "type" "idiv")
1978 (set_attr "mode" "<MODE>")])
1979 \f
1980 ;;
1981 ;; ....................
1982 ;;
1983 ;; SQUARE ROOT
1984 ;;
1985 ;; ....................
1986
1987 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
1988 ;; "*div[sd]f3" comment for details).
1989
1990 (define_insn "sqrt<mode>2"
1991 [(set (match_operand:ANYF 0 "register_operand" "=f")
1992 (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
1993 "<sqrt_condition>"
1994 {
1995 if (TARGET_FIX_SB1)
1996 return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
1997 else
1998 return "sqrt.<fmt>\t%0,%1";
1999 }
2000 [(set_attr "type" "fsqrt")
2001 (set_attr "mode" "<UNITMODE>")
2002 (set (attr "length")
2003 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
2004 (const_int 8)
2005 (const_int 4)))])
2006
2007 (define_insn "*rsqrt<mode>a"
2008 [(set (match_operand:ANYF 0 "register_operand" "=f")
2009 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2010 (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
2011 "<recip_condition> && flag_unsafe_math_optimizations"
2012 {
2013 if (TARGET_FIX_SB1)
2014 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2015 else
2016 return "rsqrt.<fmt>\t%0,%2";
2017 }
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))
2022 (const_int 8)
2023 (const_int 4)))])
2024
2025 (define_insn "*rsqrt<mode>b"
2026 [(set (match_operand:ANYF 0 "register_operand" "=f")
2027 (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2028 (match_operand:ANYF 2 "register_operand" "f"))))]
2029 "<recip_condition> && flag_unsafe_math_optimizations"
2030 {
2031 if (TARGET_FIX_SB1)
2032 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2033 else
2034 return "rsqrt.<fmt>\t%0,%2";
2035 }
2036 [(set_attr "type" "frsqrt")
2037 (set_attr "mode" "<UNITMODE>")
2038 (set (attr "length")
2039 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
2040 (const_int 8)
2041 (const_int 4)))])
2042 \f
2043 ;;
2044 ;; ....................
2045 ;;
2046 ;; ABSOLUTE VALUE
2047 ;;
2048 ;; ....................
2049
2050 ;; Do not use the integer abs macro instruction, since that signals an
2051 ;; exception on -2147483648 (sigh).
2052
2053 ;; abs.fmt is an arithmetic instruction and treats all NaN inputs as
2054 ;; invalid; it does not clear their sign bits. We therefore can't use
2055 ;; abs.fmt if the signs of NaNs matter.
2056
2057 (define_insn "abs<mode>2"
2058 [(set (match_operand:ANYF 0 "register_operand" "=f")
2059 (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2060 "!HONOR_NANS (<MODE>mode)"
2061 "abs.<fmt>\t%0,%1"
2062 [(set_attr "type" "fabs")
2063 (set_attr "mode" "<UNITMODE>")])
2064 \f
2065 ;;
2066 ;; ...................
2067 ;;
2068 ;; Count leading zeroes.
2069 ;;
2070 ;; ...................
2071 ;;
2072
2073 (define_insn "clz<mode>2"
2074 [(set (match_operand:GPR 0 "register_operand" "=d")
2075 (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
2076 "ISA_HAS_CLZ_CLO"
2077 "<d>clz\t%0,%1"
2078 [(set_attr "type" "clz")
2079 (set_attr "mode" "<MODE>")])
2080 \f
2081 ;;
2082 ;; ....................
2083 ;;
2084 ;; NEGATION and ONE'S COMPLEMENT
2085 ;;
2086 ;; ....................
2087
2088 (define_insn "negsi2"
2089 [(set (match_operand:SI 0 "register_operand" "=d")
2090 (neg:SI (match_operand:SI 1 "register_operand" "d")))]
2091 ""
2092 {
2093 if (TARGET_MIPS16)
2094 return "neg\t%0,%1";
2095 else
2096 return "subu\t%0,%.,%1";
2097 }
2098 [(set_attr "type" "arith")
2099 (set_attr "mode" "SI")])
2100
2101 (define_insn "negdi2"
2102 [(set (match_operand:DI 0 "register_operand" "=d")
2103 (neg:DI (match_operand:DI 1 "register_operand" "d")))]
2104 "TARGET_64BIT && !TARGET_MIPS16"
2105 "dsubu\t%0,%.,%1"
2106 [(set_attr "type" "arith")
2107 (set_attr "mode" "DI")])
2108
2109 ;; neg.fmt is an arithmetic instruction and treats all NaN inputs as
2110 ;; invalid; it does not flip their sign bit. We therefore can't use
2111 ;; neg.fmt if the signs of NaNs matter.
2112
2113 (define_insn "neg<mode>2"
2114 [(set (match_operand:ANYF 0 "register_operand" "=f")
2115 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2116 "!HONOR_NANS (<MODE>mode)"
2117 "neg.<fmt>\t%0,%1"
2118 [(set_attr "type" "fneg")
2119 (set_attr "mode" "<UNITMODE>")])
2120
2121 (define_insn "one_cmpl<mode>2"
2122 [(set (match_operand:GPR 0 "register_operand" "=d")
2123 (not:GPR (match_operand:GPR 1 "register_operand" "d")))]
2124 ""
2125 {
2126 if (TARGET_MIPS16)
2127 return "not\t%0,%1";
2128 else
2129 return "nor\t%0,%.,%1";
2130 }
2131 [(set_attr "type" "logical")
2132 (set_attr "mode" "<MODE>")])
2133 \f
2134 ;;
2135 ;; ....................
2136 ;;
2137 ;; LOGICAL
2138 ;;
2139 ;; ....................
2140 ;;
2141
2142 ;; Many of these instructions use trivial define_expands, because we
2143 ;; want to use a different set of constraints when TARGET_MIPS16.
2144
2145 (define_expand "and<mode>3"
2146 [(set (match_operand:GPR 0 "register_operand")
2147 (and:GPR (match_operand:GPR 1 "register_operand")
2148 (match_operand:GPR 2 "uns_arith_operand")))]
2149 ""
2150 {
2151 if (TARGET_MIPS16)
2152 operands[2] = force_reg (<MODE>mode, operands[2]);
2153 })
2154
2155 (define_insn "*and<mode>3"
2156 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2157 (and:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2158 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2159 "!TARGET_MIPS16"
2160 "@
2161 and\t%0,%1,%2
2162 andi\t%0,%1,%x2"
2163 [(set_attr "type" "logical")
2164 (set_attr "mode" "<MODE>")])
2165
2166 (define_insn "*and<mode>3_mips16"
2167 [(set (match_operand:GPR 0 "register_operand" "=d")
2168 (and:GPR (match_operand:GPR 1 "register_operand" "%0")
2169 (match_operand:GPR 2 "register_operand" "d")))]
2170 "TARGET_MIPS16"
2171 "and\t%0,%2"
2172 [(set_attr "type" "logical")
2173 (set_attr "mode" "<MODE>")])
2174
2175 (define_expand "ior<mode>3"
2176 [(set (match_operand:GPR 0 "register_operand")
2177 (ior:GPR (match_operand:GPR 1 "register_operand")
2178 (match_operand:GPR 2 "uns_arith_operand")))]
2179 ""
2180 {
2181 if (TARGET_MIPS16)
2182 operands[2] = force_reg (<MODE>mode, operands[2]);
2183 })
2184
2185 (define_insn "*ior<mode>3"
2186 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2187 (ior:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2188 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2189 "!TARGET_MIPS16"
2190 "@
2191 or\t%0,%1,%2
2192 ori\t%0,%1,%x2"
2193 [(set_attr "type" "logical")
2194 (set_attr "mode" "<MODE>")])
2195
2196 (define_insn "*ior<mode>3_mips16"
2197 [(set (match_operand:GPR 0 "register_operand" "=d")
2198 (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
2199 (match_operand:GPR 2 "register_operand" "d")))]
2200 "TARGET_MIPS16"
2201 "or\t%0,%2"
2202 [(set_attr "type" "logical")
2203 (set_attr "mode" "<MODE>")])
2204
2205 (define_expand "xor<mode>3"
2206 [(set (match_operand:GPR 0 "register_operand")
2207 (xor:GPR (match_operand:GPR 1 "register_operand")
2208 (match_operand:GPR 2 "uns_arith_operand")))]
2209 ""
2210 "")
2211
2212 (define_insn ""
2213 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2214 (xor:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2215 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2216 "!TARGET_MIPS16"
2217 "@
2218 xor\t%0,%1,%2
2219 xori\t%0,%1,%x2"
2220 [(set_attr "type" "logical")
2221 (set_attr "mode" "<MODE>")])
2222
2223 (define_insn ""
2224 [(set (match_operand:GPR 0 "register_operand" "=d,t,t")
2225 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
2226 (match_operand:GPR 2 "uns_arith_operand" "d,K,d")))]
2227 "TARGET_MIPS16"
2228 "@
2229 xor\t%0,%2
2230 cmpi\t%1,%2
2231 cmp\t%1,%2"
2232 [(set_attr "type" "logical,arith,arith")
2233 (set_attr "mode" "<MODE>")
2234 (set_attr_alternative "length"
2235 [(const_int 4)
2236 (if_then_else (match_operand:VOID 2 "m16_uimm8_1")
2237 (const_int 4)
2238 (const_int 8))
2239 (const_int 4)])])
2240
2241 (define_insn "*nor<mode>3"
2242 [(set (match_operand:GPR 0 "register_operand" "=d")
2243 (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
2244 (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
2245 "!TARGET_MIPS16"
2246 "nor\t%0,%1,%2"
2247 [(set_attr "type" "logical")
2248 (set_attr "mode" "<MODE>")])
2249 \f
2250 ;;
2251 ;; ....................
2252 ;;
2253 ;; TRUNCATION
2254 ;;
2255 ;; ....................
2256
2257
2258
2259 (define_insn "truncdfsf2"
2260 [(set (match_operand:SF 0 "register_operand" "=f")
2261 (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
2262 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2263 "cvt.s.d\t%0,%1"
2264 [(set_attr "type" "fcvt")
2265 (set_attr "cnv_mode" "D2S")
2266 (set_attr "mode" "SF")])
2267
2268 ;; Integer truncation patterns. Truncating SImode values to smaller
2269 ;; modes is a no-op, as it is for most other GCC ports. Truncating
2270 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
2271 ;; need to make sure that the lower 32 bits are properly sign-extended
2272 ;; (see TRULY_NOOP_TRUNCATION). Truncating DImode values into modes
2273 ;; smaller than SImode is equivalent to two separate truncations:
2274 ;;
2275 ;; A B
2276 ;; DI ---> HI == DI ---> SI ---> HI
2277 ;; DI ---> QI == DI ---> SI ---> QI
2278 ;;
2279 ;; Step A needs a real instruction but step B does not.
2280
2281 (define_insn "truncdisi2"
2282 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
2283 (truncate:SI (match_operand:DI 1 "register_operand" "d,d")))]
2284 "TARGET_64BIT"
2285 "@
2286 sll\t%0,%1,0
2287 sw\t%1,%0"
2288 [(set_attr "type" "shift,store")
2289 (set_attr "mode" "SI")
2290 (set_attr "extended_mips16" "yes,*")])
2291
2292 (define_insn "truncdihi2"
2293 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,m")
2294 (truncate:HI (match_operand:DI 1 "register_operand" "d,d")))]
2295 "TARGET_64BIT"
2296 "@
2297 sll\t%0,%1,0
2298 sh\t%1,%0"
2299 [(set_attr "type" "shift,store")
2300 (set_attr "mode" "SI")
2301 (set_attr "extended_mips16" "yes,*")])
2302
2303 (define_insn "truncdiqi2"
2304 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,m")
2305 (truncate:QI (match_operand:DI 1 "register_operand" "d,d")))]
2306 "TARGET_64BIT"
2307 "@
2308 sll\t%0,%1,0
2309 sb\t%1,%0"
2310 [(set_attr "type" "shift,store")
2311 (set_attr "mode" "SI")
2312 (set_attr "extended_mips16" "yes,*")])
2313
2314 ;; Combiner patterns to optimize shift/truncate combinations.
2315
2316 (define_insn ""
2317 [(set (match_operand:SI 0 "register_operand" "=d")
2318 (truncate:SI
2319 (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
2320 (match_operand:DI 2 "const_arith_operand" ""))))]
2321 "TARGET_64BIT && !TARGET_MIPS16 && INTVAL (operands[2]) >= 32"
2322 "dsra\t%0,%1,%2"
2323 [(set_attr "type" "shift")
2324 (set_attr "mode" "SI")])
2325
2326 (define_insn ""
2327 [(set (match_operand:SI 0 "register_operand" "=d")
2328 (truncate:SI (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
2329 (const_int 32))))]
2330 "TARGET_64BIT && !TARGET_MIPS16"
2331 "dsra\t%0,%1,32"
2332 [(set_attr "type" "shift")
2333 (set_attr "mode" "SI")])
2334
2335
2336 ;; Combiner patterns for truncate/sign_extend combinations. They use
2337 ;; the shift/truncate patterns above.
2338
2339 (define_insn_and_split ""
2340 [(set (match_operand:SI 0 "register_operand" "=d")
2341 (sign_extend:SI
2342 (truncate:HI (match_operand:DI 1 "register_operand" "d"))))]
2343 "TARGET_64BIT && !TARGET_MIPS16"
2344 "#"
2345 "&& reload_completed"
2346 [(set (match_dup 2)
2347 (ashift:DI (match_dup 1)
2348 (const_int 48)))
2349 (set (match_dup 0)
2350 (truncate:SI (ashiftrt:DI (match_dup 2)
2351 (const_int 48))))]
2352 { operands[2] = gen_lowpart (DImode, operands[0]); })
2353
2354 (define_insn_and_split ""
2355 [(set (match_operand:SI 0 "register_operand" "=d")
2356 (sign_extend:SI
2357 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
2358 "TARGET_64BIT && !TARGET_MIPS16"
2359 "#"
2360 "&& reload_completed"
2361 [(set (match_dup 2)
2362 (ashift:DI (match_dup 1)
2363 (const_int 56)))
2364 (set (match_dup 0)
2365 (truncate:SI (ashiftrt:DI (match_dup 2)
2366 (const_int 56))))]
2367 { operands[2] = gen_lowpart (DImode, operands[0]); })
2368
2369
2370 ;; Combiner patterns to optimize truncate/zero_extend combinations.
2371
2372 (define_insn ""
2373 [(set (match_operand:SI 0 "register_operand" "=d")
2374 (zero_extend:SI (truncate:HI
2375 (match_operand:DI 1 "register_operand" "d"))))]
2376 "TARGET_64BIT && !TARGET_MIPS16"
2377 "andi\t%0,%1,0xffff"
2378 [(set_attr "type" "logical")
2379 (set_attr "mode" "SI")])
2380
2381 (define_insn ""
2382 [(set (match_operand:SI 0 "register_operand" "=d")
2383 (zero_extend:SI (truncate:QI
2384 (match_operand:DI 1 "register_operand" "d"))))]
2385 "TARGET_64BIT && !TARGET_MIPS16"
2386 "andi\t%0,%1,0xff"
2387 [(set_attr "type" "logical")
2388 (set_attr "mode" "SI")])
2389
2390 (define_insn ""
2391 [(set (match_operand:HI 0 "register_operand" "=d")
2392 (zero_extend:HI (truncate:QI
2393 (match_operand:DI 1 "register_operand" "d"))))]
2394 "TARGET_64BIT && !TARGET_MIPS16"
2395 "andi\t%0,%1,0xff"
2396 [(set_attr "type" "logical")
2397 (set_attr "mode" "HI")])
2398 \f
2399 ;;
2400 ;; ....................
2401 ;;
2402 ;; ZERO EXTENSION
2403 ;;
2404 ;; ....................
2405
2406 ;; Extension insns.
2407
2408 (define_insn_and_split "zero_extendsidi2"
2409 [(set (match_operand:DI 0 "register_operand" "=d,d")
2410 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
2411 "TARGET_64BIT"
2412 "@
2413 #
2414 lwu\t%0,%1"
2415 "&& reload_completed && REG_P (operands[1])"
2416 [(set (match_dup 0)
2417 (ashift:DI (match_dup 1) (const_int 32)))
2418 (set (match_dup 0)
2419 (lshiftrt:DI (match_dup 0) (const_int 32)))]
2420 { operands[1] = gen_lowpart (DImode, operands[1]); }
2421 [(set_attr "type" "multi,load")
2422 (set_attr "mode" "DI")
2423 (set_attr "length" "8,*")])
2424
2425 ;; Combine is not allowed to convert this insn into a zero_extendsidi2
2426 ;; because of TRULY_NOOP_TRUNCATION.
2427
2428 (define_insn_and_split "*clear_upper32"
2429 [(set (match_operand:DI 0 "register_operand" "=d,d")
2430 (and:DI (match_operand:DI 1 "nonimmediate_operand" "d,o")
2431 (const_int 4294967295)))]
2432 "TARGET_64BIT"
2433 {
2434 if (which_alternative == 0)
2435 return "#";
2436
2437 operands[1] = gen_lowpart (SImode, operands[1]);
2438 return "lwu\t%0,%1";
2439 }
2440 "&& reload_completed && REG_P (operands[1])"
2441 [(set (match_dup 0)
2442 (ashift:DI (match_dup 1) (const_int 32)))
2443 (set (match_dup 0)
2444 (lshiftrt:DI (match_dup 0) (const_int 32)))]
2445 ""
2446 [(set_attr "type" "multi,load")
2447 (set_attr "mode" "DI")
2448 (set_attr "length" "8,*")])
2449
2450 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
2451 [(set (match_operand:GPR 0 "register_operand")
2452 (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
2453 ""
2454 {
2455 if (TARGET_MIPS16 && !GENERATE_MIPS16E
2456 && !memory_operand (operands[1], <SHORT:MODE>mode))
2457 {
2458 emit_insn (gen_and<GPR:mode>3 (operands[0],
2459 gen_lowpart (<GPR:MODE>mode, operands[1]),
2460 force_reg (<GPR:MODE>mode,
2461 GEN_INT (<SHORT:mask>))));
2462 DONE;
2463 }
2464 })
2465
2466 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
2467 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2468 (zero_extend:GPR
2469 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2470 "!TARGET_MIPS16"
2471 "@
2472 andi\t%0,%1,<SHORT:mask>
2473 l<SHORT:size>u\t%0,%1"
2474 [(set_attr "type" "logical,load")
2475 (set_attr "mode" "<GPR:MODE>")])
2476
2477 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
2478 [(set (match_operand:GPR 0 "register_operand" "=d")
2479 (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
2480 "GENERATE_MIPS16E"
2481 "ze<SHORT:size>\t%0"
2482 [(set_attr "type" "arith")
2483 (set_attr "mode" "<GPR:MODE>")])
2484
2485 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
2486 [(set (match_operand:GPR 0 "register_operand" "=d")
2487 (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
2488 "TARGET_MIPS16"
2489 "l<SHORT:size>u\t%0,%1"
2490 [(set_attr "type" "load")
2491 (set_attr "mode" "<GPR:MODE>")])
2492
2493 (define_expand "zero_extendqihi2"
2494 [(set (match_operand:HI 0 "register_operand")
2495 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
2496 ""
2497 {
2498 if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
2499 {
2500 emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
2501 operands[1]));
2502 DONE;
2503 }
2504 })
2505
2506 (define_insn "*zero_extendqihi2"
2507 [(set (match_operand:HI 0 "register_operand" "=d,d")
2508 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
2509 "!TARGET_MIPS16"
2510 "@
2511 andi\t%0,%1,0x00ff
2512 lbu\t%0,%1"
2513 [(set_attr "type" "logical,load")
2514 (set_attr "mode" "HI")])
2515
2516 (define_insn "*zero_extendqihi2_mips16"
2517 [(set (match_operand:HI 0 "register_operand" "=d")
2518 (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
2519 "TARGET_MIPS16"
2520 "lbu\t%0,%1"
2521 [(set_attr "type" "load")
2522 (set_attr "mode" "HI")])
2523 \f
2524 ;;
2525 ;; ....................
2526 ;;
2527 ;; SIGN EXTENSION
2528 ;;
2529 ;; ....................
2530
2531 ;; Extension insns.
2532 ;; Those for integer source operand are ordered widest source type first.
2533
2534 ;; When TARGET_64BIT, all SImode integer registers should already be in
2535 ;; sign-extended form (see TRULY_NOOP_TRUNCATION and truncdisi2). We can
2536 ;; therefore get rid of register->register instructions if we constrain
2537 ;; the source to be in the same register as the destination.
2538 ;;
2539 ;; The register alternative has type "arith" so that the pre-reload
2540 ;; scheduler will treat it as a move. This reflects what happens if
2541 ;; the register alternative needs a reload.
2542 (define_insn_and_split "extendsidi2"
2543 [(set (match_operand:DI 0 "register_operand" "=d,d")
2544 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,m")))]
2545 "TARGET_64BIT"
2546 "@
2547 #
2548 lw\t%0,%1"
2549 "&& reload_completed && register_operand (operands[1], VOIDmode)"
2550 [(const_int 0)]
2551 {
2552 emit_note (NOTE_INSN_DELETED);
2553 DONE;
2554 }
2555 [(set_attr "type" "arith,load")
2556 (set_attr "mode" "DI")])
2557
2558 (define_expand "extend<SHORT:mode><GPR:mode>2"
2559 [(set (match_operand:GPR 0 "register_operand")
2560 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
2561 "")
2562
2563 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
2564 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2565 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
2566 "GENERATE_MIPS16E"
2567 "@
2568 se<SHORT:size>\t%0
2569 l<SHORT:size>\t%0,%1"
2570 [(set_attr "type" "signext,load")
2571 (set_attr "mode" "<GPR:MODE>")])
2572
2573 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
2574 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2575 (sign_extend:GPR
2576 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2577 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
2578 "@
2579 #
2580 l<SHORT:size>\t%0,%1"
2581 "&& reload_completed && REG_P (operands[1])"
2582 [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
2583 (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
2584 {
2585 operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
2586 operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
2587 - GET_MODE_BITSIZE (<SHORT:MODE>mode));
2588 }
2589 [(set_attr "type" "arith,load")
2590 (set_attr "mode" "<GPR:MODE>")
2591 (set_attr "length" "8,*")])
2592
2593 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
2594 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2595 (sign_extend:GPR
2596 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2597 "ISA_HAS_SEB_SEH"
2598 "@
2599 se<SHORT:size>\t%0,%1
2600 l<SHORT:size>\t%0,%1"
2601 [(set_attr "type" "signext,load")
2602 (set_attr "mode" "<GPR:MODE>")])
2603
2604 (define_expand "extendqihi2"
2605 [(set (match_operand:HI 0 "register_operand")
2606 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
2607 "")
2608
2609 (define_insn "*extendqihi2_mips16e"
2610 [(set (match_operand:HI 0 "register_operand" "=d,d")
2611 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
2612 "GENERATE_MIPS16E"
2613 "@
2614 seb\t%0
2615 lb\t%0,%1"
2616 [(set_attr "type" "signext,load")
2617 (set_attr "mode" "SI")])
2618
2619 (define_insn_and_split "*extendqihi2"
2620 [(set (match_operand:HI 0 "register_operand" "=d,d")
2621 (sign_extend:HI
2622 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
2623 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
2624 "@
2625 #
2626 lb\t%0,%1"
2627 "&& reload_completed && REG_P (operands[1])"
2628 [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
2629 (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
2630 {
2631 operands[0] = gen_lowpart (SImode, operands[0]);
2632 operands[1] = gen_lowpart (SImode, operands[1]);
2633 operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
2634 - GET_MODE_BITSIZE (QImode));
2635 }
2636 [(set_attr "type" "multi,load")
2637 (set_attr "mode" "SI")
2638 (set_attr "length" "8,*")])
2639
2640 (define_insn "*extendqihi2_seb"
2641 [(set (match_operand:HI 0 "register_operand" "=d,d")
2642 (sign_extend:HI
2643 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
2644 "ISA_HAS_SEB_SEH"
2645 "@
2646 seb\t%0,%1
2647 lb\t%0,%1"
2648 [(set_attr "type" "signext,load")
2649 (set_attr "mode" "SI")])
2650
2651 (define_insn "extendsfdf2"
2652 [(set (match_operand:DF 0 "register_operand" "=f")
2653 (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
2654 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2655 "cvt.d.s\t%0,%1"
2656 [(set_attr "type" "fcvt")
2657 (set_attr "cnv_mode" "S2D")
2658 (set_attr "mode" "DF")])
2659 \f
2660 ;;
2661 ;; ....................
2662 ;;
2663 ;; CONVERSIONS
2664 ;;
2665 ;; ....................
2666
2667 (define_expand "fix_truncdfsi2"
2668 [(set (match_operand:SI 0 "register_operand")
2669 (fix:SI (match_operand:DF 1 "register_operand")))]
2670 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2671 {
2672 if (!ISA_HAS_TRUNC_W)
2673 {
2674 emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
2675 DONE;
2676 }
2677 })
2678
2679 (define_insn "fix_truncdfsi2_insn"
2680 [(set (match_operand:SI 0 "register_operand" "=f")
2681 (fix:SI (match_operand:DF 1 "register_operand" "f")))]
2682 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
2683 "trunc.w.d %0,%1"
2684 [(set_attr "type" "fcvt")
2685 (set_attr "mode" "DF")
2686 (set_attr "cnv_mode" "D2I")
2687 (set_attr "length" "4")])
2688
2689 (define_insn "fix_truncdfsi2_macro"
2690 [(set (match_operand:SI 0 "register_operand" "=f")
2691 (fix:SI (match_operand:DF 1 "register_operand" "f")))
2692 (clobber (match_scratch:DF 2 "=d"))]
2693 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
2694 {
2695 if (set_nomacro)
2696 return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
2697 else
2698 return "trunc.w.d %0,%1,%2";
2699 }
2700 [(set_attr "type" "fcvt")
2701 (set_attr "mode" "DF")
2702 (set_attr "cnv_mode" "D2I")
2703 (set_attr "length" "36")])
2704
2705 (define_expand "fix_truncsfsi2"
2706 [(set (match_operand:SI 0 "register_operand")
2707 (fix:SI (match_operand:SF 1 "register_operand")))]
2708 "TARGET_HARD_FLOAT"
2709 {
2710 if (!ISA_HAS_TRUNC_W)
2711 {
2712 emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
2713 DONE;
2714 }
2715 })
2716
2717 (define_insn "fix_truncsfsi2_insn"
2718 [(set (match_operand:SI 0 "register_operand" "=f")
2719 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
2720 "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
2721 "trunc.w.s %0,%1"
2722 [(set_attr "type" "fcvt")
2723 (set_attr "mode" "SF")
2724 (set_attr "cnv_mode" "S2I")
2725 (set_attr "length" "4")])
2726
2727 (define_insn "fix_truncsfsi2_macro"
2728 [(set (match_operand:SI 0 "register_operand" "=f")
2729 (fix:SI (match_operand:SF 1 "register_operand" "f")))
2730 (clobber (match_scratch:SF 2 "=d"))]
2731 "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
2732 {
2733 if (set_nomacro)
2734 return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
2735 else
2736 return "trunc.w.s %0,%1,%2";
2737 }
2738 [(set_attr "type" "fcvt")
2739 (set_attr "mode" "SF")
2740 (set_attr "cnv_mode" "S2I")
2741 (set_attr "length" "36")])
2742
2743
2744 (define_insn "fix_truncdfdi2"
2745 [(set (match_operand:DI 0 "register_operand" "=f")
2746 (fix:DI (match_operand:DF 1 "register_operand" "f")))]
2747 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2748 "trunc.l.d %0,%1"
2749 [(set_attr "type" "fcvt")
2750 (set_attr "mode" "DF")
2751 (set_attr "cnv_mode" "D2I")
2752 (set_attr "length" "4")])
2753
2754
2755 (define_insn "fix_truncsfdi2"
2756 [(set (match_operand:DI 0 "register_operand" "=f")
2757 (fix:DI (match_operand:SF 1 "register_operand" "f")))]
2758 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2759 "trunc.l.s %0,%1"
2760 [(set_attr "type" "fcvt")
2761 (set_attr "mode" "SF")
2762 (set_attr "cnv_mode" "S2I")
2763 (set_attr "length" "4")])
2764
2765
2766 (define_insn "floatsidf2"
2767 [(set (match_operand:DF 0 "register_operand" "=f")
2768 (float:DF (match_operand:SI 1 "register_operand" "f")))]
2769 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2770 "cvt.d.w\t%0,%1"
2771 [(set_attr "type" "fcvt")
2772 (set_attr "mode" "DF")
2773 (set_attr "cnv_mode" "I2D")
2774 (set_attr "length" "4")])
2775
2776
2777 (define_insn "floatdidf2"
2778 [(set (match_operand:DF 0 "register_operand" "=f")
2779 (float:DF (match_operand:DI 1 "register_operand" "f")))]
2780 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2781 "cvt.d.l\t%0,%1"
2782 [(set_attr "type" "fcvt")
2783 (set_attr "mode" "DF")
2784 (set_attr "cnv_mode" "I2D")
2785 (set_attr "length" "4")])
2786
2787
2788 (define_insn "floatsisf2"
2789 [(set (match_operand:SF 0 "register_operand" "=f")
2790 (float:SF (match_operand:SI 1 "register_operand" "f")))]
2791 "TARGET_HARD_FLOAT"
2792 "cvt.s.w\t%0,%1"
2793 [(set_attr "type" "fcvt")
2794 (set_attr "mode" "SF")
2795 (set_attr "cnv_mode" "I2S")
2796 (set_attr "length" "4")])
2797
2798
2799 (define_insn "floatdisf2"
2800 [(set (match_operand:SF 0 "register_operand" "=f")
2801 (float:SF (match_operand:DI 1 "register_operand" "f")))]
2802 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2803 "cvt.s.l\t%0,%1"
2804 [(set_attr "type" "fcvt")
2805 (set_attr "mode" "SF")
2806 (set_attr "cnv_mode" "I2S")
2807 (set_attr "length" "4")])
2808
2809
2810 (define_expand "fixuns_truncdfsi2"
2811 [(set (match_operand:SI 0 "register_operand")
2812 (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
2813 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2814 {
2815 rtx reg1 = gen_reg_rtx (DFmode);
2816 rtx reg2 = gen_reg_rtx (DFmode);
2817 rtx reg3 = gen_reg_rtx (SImode);
2818 rtx label1 = gen_label_rtx ();
2819 rtx label2 = gen_label_rtx ();
2820 REAL_VALUE_TYPE offset;
2821
2822 real_2expN (&offset, 31, DFmode);
2823
2824 if (reg1) /* Turn off complaints about unreached code. */
2825 {
2826 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
2827 do_pending_stack_adjust ();
2828
2829 emit_insn (gen_cmpdf (operands[1], reg1));
2830 emit_jump_insn (gen_bge (label1));
2831
2832 emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
2833 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2834 gen_rtx_LABEL_REF (VOIDmode, label2)));
2835 emit_barrier ();
2836
2837 emit_label (label1);
2838 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
2839 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
2840 (BITMASK_HIGH, SImode)));
2841
2842 emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
2843 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
2844
2845 emit_label (label2);
2846
2847 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2848 fields, and can't be used for REG_NOTES anyway). */
2849 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2850 DONE;
2851 }
2852 })
2853
2854
2855 (define_expand "fixuns_truncdfdi2"
2856 [(set (match_operand:DI 0 "register_operand")
2857 (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
2858 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
2859 {
2860 rtx reg1 = gen_reg_rtx (DFmode);
2861 rtx reg2 = gen_reg_rtx (DFmode);
2862 rtx reg3 = gen_reg_rtx (DImode);
2863 rtx label1 = gen_label_rtx ();
2864 rtx label2 = gen_label_rtx ();
2865 REAL_VALUE_TYPE offset;
2866
2867 real_2expN (&offset, 63, DFmode);
2868
2869 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
2870 do_pending_stack_adjust ();
2871
2872 emit_insn (gen_cmpdf (operands[1], reg1));
2873 emit_jump_insn (gen_bge (label1));
2874
2875 emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
2876 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2877 gen_rtx_LABEL_REF (VOIDmode, label2)));
2878 emit_barrier ();
2879
2880 emit_label (label1);
2881 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
2882 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
2883 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
2884
2885 emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
2886 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
2887
2888 emit_label (label2);
2889
2890 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2891 fields, and can't be used for REG_NOTES anyway). */
2892 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2893 DONE;
2894 })
2895
2896
2897 (define_expand "fixuns_truncsfsi2"
2898 [(set (match_operand:SI 0 "register_operand")
2899 (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
2900 "TARGET_HARD_FLOAT"
2901 {
2902 rtx reg1 = gen_reg_rtx (SFmode);
2903 rtx reg2 = gen_reg_rtx (SFmode);
2904 rtx reg3 = gen_reg_rtx (SImode);
2905 rtx label1 = gen_label_rtx ();
2906 rtx label2 = gen_label_rtx ();
2907 REAL_VALUE_TYPE offset;
2908
2909 real_2expN (&offset, 31, SFmode);
2910
2911 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
2912 do_pending_stack_adjust ();
2913
2914 emit_insn (gen_cmpsf (operands[1], reg1));
2915 emit_jump_insn (gen_bge (label1));
2916
2917 emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
2918 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2919 gen_rtx_LABEL_REF (VOIDmode, label2)));
2920 emit_barrier ();
2921
2922 emit_label (label1);
2923 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
2924 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
2925 (BITMASK_HIGH, SImode)));
2926
2927 emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
2928 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
2929
2930 emit_label (label2);
2931
2932 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2933 fields, and can't be used for REG_NOTES anyway). */
2934 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2935 DONE;
2936 })
2937
2938
2939 (define_expand "fixuns_truncsfdi2"
2940 [(set (match_operand:DI 0 "register_operand")
2941 (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
2942 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
2943 {
2944 rtx reg1 = gen_reg_rtx (SFmode);
2945 rtx reg2 = gen_reg_rtx (SFmode);
2946 rtx reg3 = gen_reg_rtx (DImode);
2947 rtx label1 = gen_label_rtx ();
2948 rtx label2 = gen_label_rtx ();
2949 REAL_VALUE_TYPE offset;
2950
2951 real_2expN (&offset, 63, SFmode);
2952
2953 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
2954 do_pending_stack_adjust ();
2955
2956 emit_insn (gen_cmpsf (operands[1], reg1));
2957 emit_jump_insn (gen_bge (label1));
2958
2959 emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
2960 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2961 gen_rtx_LABEL_REF (VOIDmode, label2)));
2962 emit_barrier ();
2963
2964 emit_label (label1);
2965 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
2966 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
2967 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
2968
2969 emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
2970 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
2971
2972 emit_label (label2);
2973
2974 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2975 fields, and can't be used for REG_NOTES anyway). */
2976 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2977 DONE;
2978 })
2979 \f
2980 ;;
2981 ;; ....................
2982 ;;
2983 ;; DATA MOVEMENT
2984 ;;
2985 ;; ....................
2986
2987 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
2988
2989 (define_expand "extv"
2990 [(set (match_operand 0 "register_operand")
2991 (sign_extract (match_operand:QI 1 "memory_operand")
2992 (match_operand 2 "immediate_operand")
2993 (match_operand 3 "immediate_operand")))]
2994 "!TARGET_MIPS16"
2995 {
2996 if (mips_expand_unaligned_load (operands[0], operands[1],
2997 INTVAL (operands[2]),
2998 INTVAL (operands[3])))
2999 DONE;
3000 else
3001 FAIL;
3002 })
3003
3004 (define_expand "extzv"
3005 [(set (match_operand 0 "register_operand")
3006 (zero_extract (match_operand 1 "nonimmediate_operand")
3007 (match_operand 2 "immediate_operand")
3008 (match_operand 3 "immediate_operand")))]
3009 "!TARGET_MIPS16"
3010 {
3011 if (mips_expand_unaligned_load (operands[0], operands[1],
3012 INTVAL (operands[2]),
3013 INTVAL (operands[3])))
3014 DONE;
3015 else if (mips_use_ins_ext_p (operands[1], operands[2], operands[3]))
3016 {
3017 if (GET_MODE (operands[0]) == DImode)
3018 emit_insn (gen_extzvdi (operands[0], operands[1], operands[2],
3019 operands[3]));
3020 else
3021 emit_insn (gen_extzvsi (operands[0], operands[1], operands[2],
3022 operands[3]));
3023 DONE;
3024 }
3025 else
3026 FAIL;
3027 })
3028
3029 (define_insn "extzv<mode>"
3030 [(set (match_operand:GPR 0 "register_operand" "=d")
3031 (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3032 (match_operand:SI 2 "immediate_operand" "I")
3033 (match_operand:SI 3 "immediate_operand" "I")))]
3034 "mips_use_ins_ext_p (operands[1], operands[2], operands[3])"
3035 "<d>ext\t%0,%1,%3,%2"
3036 [(set_attr "type" "arith")
3037 (set_attr "mode" "<MODE>")])
3038
3039
3040 (define_expand "insv"
3041 [(set (zero_extract (match_operand 0 "nonimmediate_operand")
3042 (match_operand 1 "immediate_operand")
3043 (match_operand 2 "immediate_operand"))
3044 (match_operand 3 "reg_or_0_operand"))]
3045 "!TARGET_MIPS16"
3046 {
3047 if (mips_expand_unaligned_store (operands[0], operands[3],
3048 INTVAL (operands[1]),
3049 INTVAL (operands[2])))
3050 DONE;
3051 else if (mips_use_ins_ext_p (operands[0], operands[1], operands[2]))
3052 {
3053 if (GET_MODE (operands[0]) == DImode)
3054 emit_insn (gen_insvdi (operands[0], operands[1], operands[2],
3055 operands[3]));
3056 else
3057 emit_insn (gen_insvsi (operands[0], operands[1], operands[2],
3058 operands[3]));
3059 DONE;
3060 }
3061 else
3062 FAIL;
3063 })
3064
3065 (define_insn "insv<mode>"
3066 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
3067 (match_operand:SI 1 "immediate_operand" "I")
3068 (match_operand:SI 2 "immediate_operand" "I"))
3069 (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
3070 "mips_use_ins_ext_p (operands[0], operands[1], operands[2])"
3071 "<d>ins\t%0,%z3,%2,%1"
3072 [(set_attr "type" "arith")
3073 (set_attr "mode" "<MODE>")])
3074
3075 ;; Unaligned word moves generated by the bit field patterns.
3076 ;;
3077 ;; As far as the rtl is concerned, both the left-part and right-part
3078 ;; instructions can access the whole field. However, the real operand
3079 ;; refers to just the first or the last byte (depending on endianness).
3080 ;; We therefore use two memory operands to each instruction, one to
3081 ;; describe the rtl effect and one to use in the assembly output.
3082 ;;
3083 ;; Operands 0 and 1 are the rtl-level target and source respectively.
3084 ;; This allows us to use the standard length calculations for the "load"
3085 ;; and "store" type attributes.
3086
3087 (define_insn "mov_<load>l"
3088 [(set (match_operand:GPR 0 "register_operand" "=d")
3089 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3090 (match_operand:QI 2 "memory_operand" "m")]
3091 UNSPEC_LOAD_LEFT))]
3092 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3093 "<load>l\t%0,%2"
3094 [(set_attr "type" "load")
3095 (set_attr "mode" "<MODE>")])
3096
3097 (define_insn "mov_<load>r"
3098 [(set (match_operand:GPR 0 "register_operand" "=d")
3099 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3100 (match_operand:QI 2 "memory_operand" "m")
3101 (match_operand:GPR 3 "register_operand" "0")]
3102 UNSPEC_LOAD_RIGHT))]
3103 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3104 "<load>r\t%0,%2"
3105 [(set_attr "type" "load")
3106 (set_attr "mode" "<MODE>")])
3107
3108 (define_insn "mov_<store>l"
3109 [(set (match_operand:BLK 0 "memory_operand" "=m")
3110 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3111 (match_operand:QI 2 "memory_operand" "m")]
3112 UNSPEC_STORE_LEFT))]
3113 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3114 "<store>l\t%z1,%2"
3115 [(set_attr "type" "store")
3116 (set_attr "mode" "<MODE>")])
3117
3118 (define_insn "mov_<store>r"
3119 [(set (match_operand:BLK 0 "memory_operand" "+m")
3120 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3121 (match_operand:QI 2 "memory_operand" "m")
3122 (match_dup 0)]
3123 UNSPEC_STORE_RIGHT))]
3124 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3125 "<store>r\t%z1,%2"
3126 [(set_attr "type" "store")
3127 (set_attr "mode" "<MODE>")])
3128
3129 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
3130 ;; The required value is:
3131 ;;
3132 ;; (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
3133 ;;
3134 ;; which translates to:
3135 ;;
3136 ;; lui op0,%highest(op1)
3137 ;; daddiu op0,op0,%higher(op1)
3138 ;; dsll op0,op0,16
3139 ;; daddiu op0,op0,%hi(op1)
3140 ;; dsll op0,op0,16
3141 ;;
3142 ;; The split is deferred until after flow2 to allow the peephole2 below
3143 ;; to take effect.
3144 (define_insn_and_split "*lea_high64"
3145 [(set (match_operand:DI 0 "register_operand" "=d")
3146 (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
3147 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3148 "#"
3149 "&& epilogue_completed"
3150 [(set (match_dup 0) (high:DI (match_dup 2)))
3151 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
3152 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
3153 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3154 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
3155 {
3156 operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3157 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
3158 }
3159 [(set_attr "length" "20")])
3160
3161 ;; Use a scratch register to reduce the latency of the above pattern
3162 ;; on superscalar machines. The optimized sequence is:
3163 ;;
3164 ;; lui op1,%highest(op2)
3165 ;; lui op0,%hi(op2)
3166 ;; daddiu op1,op1,%higher(op2)
3167 ;; dsll32 op1,op1,0
3168 ;; daddu op1,op1,op0
3169 (define_peephole2
3170 [(set (match_operand:DI 1 "register_operand")
3171 (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
3172 (match_scratch:DI 0 "d")]
3173 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3174 [(set (match_dup 1) (high:DI (match_dup 3)))
3175 (set (match_dup 0) (high:DI (match_dup 4)))
3176 (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
3177 (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
3178 (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
3179 {
3180 operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
3181 operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
3182 })
3183
3184 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
3185 ;; SYMBOL_ABSOLUTE X will take 6 cycles. This next pattern allows combine
3186 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
3187 ;; used once. We can then use the sequence:
3188 ;;
3189 ;; lui op0,%highest(op1)
3190 ;; lui op2,%hi(op1)
3191 ;; daddiu op0,op0,%higher(op1)
3192 ;; daddiu op2,op2,%lo(op1)
3193 ;; dsll32 op0,op0,0
3194 ;; daddu op0,op0,op2
3195 ;;
3196 ;; which takes 4 cycles on most superscalar targets.
3197 (define_insn_and_split "*lea64"
3198 [(set (match_operand:DI 0 "register_operand" "=d")
3199 (match_operand:DI 1 "absolute_symbolic_operand" ""))
3200 (clobber (match_scratch:DI 2 "=&d"))]
3201 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS && cse_not_expected"
3202 "#"
3203 "&& reload_completed"
3204 [(set (match_dup 0) (high:DI (match_dup 3)))
3205 (set (match_dup 2) (high:DI (match_dup 4)))
3206 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3207 (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
3208 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
3209 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
3210 {
3211 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3212 operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
3213 }
3214 [(set_attr "length" "24")])
3215
3216 ;; Split HIGHs into:
3217 ;;
3218 ;; li op0,%hi(sym)
3219 ;; sll op0,16
3220 ;;
3221 ;; on MIPS16 targets.
3222 (define_split
3223 [(set (match_operand:SI 0 "register_operand" "=d")
3224 (high:SI (match_operand:SI 1 "absolute_symbolic_operand" "")))]
3225 "TARGET_MIPS16 && reload_completed"
3226 [(set (match_dup 0) (match_dup 2))
3227 (set (match_dup 0) (ashift:SI (match_dup 0) (const_int 16)))]
3228 {
3229 operands[2] = mips_unspec_address (operands[1], SYMBOL_32_HIGH);
3230 })
3231
3232 ;; Insns to fetch a symbol from a big GOT.
3233
3234 (define_insn_and_split "*xgot_hi<mode>"
3235 [(set (match_operand:P 0 "register_operand" "=d")
3236 (high:P (match_operand:P 1 "got_disp_operand" "")))]
3237 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
3238 "#"
3239 "&& reload_completed"
3240 [(set (match_dup 0) (high:P (match_dup 2)))
3241 (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
3242 {
3243 operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
3244 operands[3] = pic_offset_table_rtx;
3245 }
3246 [(set_attr "got" "xgot_high")
3247 (set_attr "mode" "<MODE>")])
3248
3249 (define_insn_and_split "*xgot_lo<mode>"
3250 [(set (match_operand:P 0 "register_operand" "=d")
3251 (lo_sum:P (match_operand:P 1 "register_operand" "d")
3252 (match_operand:P 2 "got_disp_operand" "")))]
3253 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
3254 "#"
3255 "&& reload_completed"
3256 [(set (match_dup 0)
3257 (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
3258 { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
3259 [(set_attr "got" "load")
3260 (set_attr "mode" "<MODE>")])
3261
3262 ;; Insns to fetch a symbol from a normal GOT.
3263
3264 (define_insn_and_split "*got_disp<mode>"
3265 [(set (match_operand:P 0 "register_operand" "=d")
3266 (match_operand:P 1 "got_disp_operand" ""))]
3267 "TARGET_EXPLICIT_RELOCS && !TARGET_XGOT"
3268 "#"
3269 "&& reload_completed"
3270 [(set (match_dup 0)
3271 (unspec:P [(match_dup 2) (match_dup 3)] UNSPEC_LOAD_GOT))]
3272 {
3273 operands[2] = pic_offset_table_rtx;
3274 operands[3] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
3275 }
3276 [(set_attr "got" "load")
3277 (set_attr "mode" "<MODE>")])
3278
3279 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
3280
3281 (define_insn_and_split "*got_page<mode>"
3282 [(set (match_operand:P 0 "register_operand" "=d")
3283 (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
3284 "TARGET_EXPLICIT_RELOCS"
3285 "#"
3286 "&& reload_completed"
3287 [(set (match_dup 0)
3288 (unspec:P [(match_dup 2) (match_dup 3)] UNSPEC_LOAD_GOT))]
3289 {
3290 operands[2] = pic_offset_table_rtx;
3291 operands[3] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_PAGE);
3292 }
3293 [(set_attr "got" "load")
3294 (set_attr "mode" "<MODE>")])
3295
3296 ;; Lower-level instructions for loading an address from the GOT.
3297 ;; We could use MEMs, but an unspec gives more optimization
3298 ;; opportunities.
3299
3300 (define_insn "load_got<mode>"
3301 [(set (match_operand:P 0 "register_operand" "=d")
3302 (unspec:P [(match_operand:P 1 "register_operand" "d")
3303 (match_operand:P 2 "immediate_operand" "")]
3304 UNSPEC_LOAD_GOT))]
3305 ""
3306 "<load>\t%0,%R2(%1)"
3307 [(set_attr "type" "load")
3308 (set_attr "mode" "<MODE>")
3309 (set_attr "length" "4")])
3310
3311 ;; Instructions for adding the low 16 bits of an address to a register.
3312 ;; Operand 2 is the address: print_operand works out which relocation
3313 ;; should be applied.
3314
3315 (define_insn "*low<mode>"
3316 [(set (match_operand:P 0 "register_operand" "=d")
3317 (lo_sum:P (match_operand:P 1 "register_operand" "d")
3318 (match_operand:P 2 "immediate_operand" "")))]
3319 "!TARGET_MIPS16"
3320 "<d>addiu\t%0,%1,%R2"
3321 [(set_attr "type" "arith")
3322 (set_attr "mode" "<MODE>")])
3323
3324 (define_insn "*low<mode>_mips16"
3325 [(set (match_operand:P 0 "register_operand" "=d")
3326 (lo_sum:P (match_operand:P 1 "register_operand" "0")
3327 (match_operand:P 2 "immediate_operand" "")))]
3328 "TARGET_MIPS16"
3329 "<d>addiu\t%0,%R2"
3330 [(set_attr "type" "arith")
3331 (set_attr "mode" "<MODE>")
3332 (set_attr "length" "8")])
3333
3334 ;; Allow combine to split complex const_int load sequences, using operand 2
3335 ;; to store the intermediate results. See move_operand for details.
3336 (define_split
3337 [(set (match_operand:GPR 0 "register_operand")
3338 (match_operand:GPR 1 "splittable_const_int_operand"))
3339 (clobber (match_operand:GPR 2 "register_operand"))]
3340 ""
3341 [(const_int 0)]
3342 {
3343 mips_move_integer (operands[0], operands[2], INTVAL (operands[1]));
3344 DONE;
3345 })
3346
3347 ;; Likewise, for symbolic operands.
3348 (define_split
3349 [(set (match_operand:P 0 "register_operand")
3350 (match_operand:P 1))
3351 (clobber (match_operand:P 2 "register_operand"))]
3352 "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
3353 [(set (match_dup 0) (match_dup 3))]
3354 {
3355 mips_split_symbol (operands[2], operands[1],
3356 MAX_MACHINE_MODE, &operands[3]);
3357 })
3358
3359 ;; 64-bit integer moves
3360
3361 ;; Unlike most other insns, the move insns can't be split with
3362 ;; different predicates, because register spilling and other parts of
3363 ;; the compiler, have memoized the insn number already.
3364
3365 (define_expand "movdi"
3366 [(set (match_operand:DI 0 "")
3367 (match_operand:DI 1 ""))]
3368 ""
3369 {
3370 if (mips_legitimize_move (DImode, operands[0], operands[1]))
3371 DONE;
3372 })
3373
3374 ;; For mips16, we need a special case to handle storing $31 into
3375 ;; memory, since we don't have a constraint to match $31. This
3376 ;; instruction can be generated by save_restore_insns.
3377
3378 (define_insn "*mov<mode>_ra"
3379 [(set (match_operand:GPR 0 "stack_operand" "=m")
3380 (reg:GPR 31))]
3381 "TARGET_MIPS16"
3382 "<store>\t$31,%0"
3383 [(set_attr "type" "store")
3384 (set_attr "mode" "<MODE>")])
3385
3386 (define_insn "*movdi_32bit"
3387 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d,*B*C*D,*B*C*D,*d,*m")
3388 (match_operand:DI 1 "move_operand" "d,i,m,d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
3389 "!TARGET_64BIT && !TARGET_FLOAT64 && !TARGET_MIPS16
3390 && (register_operand (operands[0], DImode)
3391 || reg_or_0_operand (operands[1], DImode))"
3392 { return mips_output_move (operands[0], operands[1]); }
3393 [(set_attr "type" "multi,multi,load,store,mthilo,mfhilo,mtc,load,mfc,store")
3394 (set_attr "mode" "DI")
3395 (set_attr "length" "8,16,*,*,8,8,8,*,8,*")])
3396
3397 (define_insn "*movdi_gp32_fp64"
3398 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d,*f,*f,*f,*d,*m")
3399 (match_operand:DI 1 "move_operand" "d,i,m,d,*J*d,*a,*f,*J*d,*m,*f,*f"))]
3400 "!TARGET_64BIT && TARGET_FLOAT64 && !TARGET_MIPS16
3401 && (register_operand (operands[0], DImode)
3402 || reg_or_0_operand (operands[1], DImode))"
3403 { return mips_output_move (operands[0], operands[1]); }
3404 [(set_attr "type" "multi,multi,load,store,mthilo,mfhilo,fmove,mtc,fpload,mfc,fpstore")
3405 (set_attr "mode" "DI")
3406 (set_attr "length" "8,16,*,*,8,8,4,8,*,8,*")])
3407
3408 (define_insn "*movdi_32bit_mips16"
3409 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
3410 (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
3411 "!TARGET_64BIT && TARGET_MIPS16
3412 && (register_operand (operands[0], DImode)
3413 || register_operand (operands[1], DImode))"
3414 { return mips_output_move (operands[0], operands[1]); }
3415 [(set_attr "type" "multi,multi,multi,multi,multi,load,store,mfhilo")
3416 (set_attr "mode" "DI")
3417 (set_attr "length" "8,8,8,8,12,*,*,8")])
3418
3419 (define_insn "*movdi_64bit"
3420 [(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")
3421 (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"))]
3422 "TARGET_64BIT && !TARGET_MIPS16
3423 && (register_operand (operands[0], DImode)
3424 || reg_or_0_operand (operands[1], DImode))"
3425 { return mips_output_move (operands[0], operands[1]); }
3426 [(set_attr "type" "move,const,const,load,store,fmove,mtc,fpload,mfc,fpstore,mthilo,mtc,load,mfc,store")
3427 (set_attr "mode" "DI")
3428 (set_attr "length" "4,*,*,*,*,4,4,*,4,*,4,8,*,8,*")])
3429
3430 (define_insn "*movdi_64bit_mips16"
3431 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m")
3432 (match_operand:DI 1 "move_operand" "d,d,y,K,N,kf,U,m,d"))]
3433 "TARGET_64BIT && TARGET_MIPS16
3434 && (register_operand (operands[0], DImode)
3435 || register_operand (operands[1], DImode))"
3436 { return mips_output_move (operands[0], operands[1]); }
3437 [(set_attr "type" "move,move,move,arith,arith,load,const,load,store")
3438 (set_attr "mode" "DI")
3439 (set_attr_alternative "length"
3440 [(const_int 4)
3441 (const_int 4)
3442 (const_int 4)
3443 (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3444 (const_int 4)
3445 (const_int 8))
3446 (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3447 (const_int 8)
3448 (const_int 12))
3449 (const_int 8)
3450 (const_string "*")
3451 (const_string "*")
3452 (const_string "*")])])
3453
3454
3455 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
3456 ;; when the original load is a 4 byte instruction but the add and the
3457 ;; load are 2 2 byte instructions.
3458
3459 (define_split
3460 [(set (match_operand:DI 0 "register_operand")
3461 (mem:DI (plus:DI (match_dup 0)
3462 (match_operand:DI 1 "const_int_operand"))))]
3463 "TARGET_64BIT && TARGET_MIPS16 && reload_completed
3464 && !TARGET_DEBUG_D_MODE
3465 && REG_P (operands[0])
3466 && M16_REG_P (REGNO (operands[0]))
3467 && GET_CODE (operands[1]) == CONST_INT
3468 && ((INTVAL (operands[1]) < 0
3469 && INTVAL (operands[1]) >= -0x10)
3470 || (INTVAL (operands[1]) >= 32 * 8
3471 && INTVAL (operands[1]) <= 31 * 8 + 0x8)
3472 || (INTVAL (operands[1]) >= 0
3473 && INTVAL (operands[1]) < 32 * 8
3474 && (INTVAL (operands[1]) & 7) != 0))"
3475 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
3476 (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
3477 {
3478 HOST_WIDE_INT val = INTVAL (operands[1]);
3479
3480 if (val < 0)
3481 operands[2] = const0_rtx;
3482 else if (val >= 32 * 8)
3483 {
3484 int off = val & 7;
3485
3486 operands[1] = GEN_INT (0x8 + off);
3487 operands[2] = GEN_INT (val - off - 0x8);
3488 }
3489 else
3490 {
3491 int off = val & 7;
3492
3493 operands[1] = GEN_INT (off);
3494 operands[2] = GEN_INT (val - off);
3495 }
3496 })
3497
3498 ;; 32-bit Integer moves
3499
3500 ;; Unlike most other insns, the move insns can't be split with
3501 ;; different predicates, because register spilling and other parts of
3502 ;; the compiler, have memoized the insn number already.
3503
3504 (define_expand "movsi"
3505 [(set (match_operand:SI 0 "")
3506 (match_operand:SI 1 ""))]
3507 ""
3508 {
3509 if (mips_legitimize_move (SImode, operands[0], operands[1]))
3510 DONE;
3511 })
3512
3513 ;; The difference between these two is whether or not ints are allowed
3514 ;; in FP registers (off by default, use -mdebugh to enable).
3515
3516 (define_insn "*movsi_internal"
3517 [(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")
3518 (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"))]
3519 "!TARGET_MIPS16
3520 && (register_operand (operands[0], SImode)
3521 || reg_or_0_operand (operands[1], SImode))"
3522 { return mips_output_move (operands[0], operands[1]); }
3523 [(set_attr "type" "move,const,const,load,store,fmove,mtc,fpload,mfc,fpstore,mfc,mtc,mthilo,mfhilo,mtc,load,mfc,store")
3524 (set_attr "mode" "SI")
3525 (set_attr "length" "4,*,*,*,*,4,4,*,4,*,4,4,4,4,4,*,4,*")])
3526
3527 (define_insn "*movsi_mips16"
3528 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m")
3529 (match_operand:SI 1 "move_operand" "d,d,y,K,N,kf,U,m,d"))]
3530 "TARGET_MIPS16
3531 && (register_operand (operands[0], SImode)
3532 || register_operand (operands[1], SImode))"
3533 { return mips_output_move (operands[0], operands[1]); }
3534 [(set_attr "type" "move,move,move,arith,arith,load,const,load,store")
3535 (set_attr "mode" "SI")
3536 (set_attr_alternative "length"
3537 [(const_int 4)
3538 (const_int 4)
3539 (const_int 4)
3540 (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3541 (const_int 4)
3542 (const_int 8))
3543 (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3544 (const_int 8)
3545 (const_int 12))
3546 (const_int 8)
3547 (const_string "*")
3548 (const_string "*")
3549 (const_string "*")])])
3550
3551 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
3552 ;; when the original load is a 4 byte instruction but the add and the
3553 ;; load are 2 2 byte instructions.
3554
3555 (define_split
3556 [(set (match_operand:SI 0 "register_operand")
3557 (mem:SI (plus:SI (match_dup 0)
3558 (match_operand:SI 1 "const_int_operand"))))]
3559 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3560 && REG_P (operands[0])
3561 && M16_REG_P (REGNO (operands[0]))
3562 && GET_CODE (operands[1]) == CONST_INT
3563 && ((INTVAL (operands[1]) < 0
3564 && INTVAL (operands[1]) >= -0x80)
3565 || (INTVAL (operands[1]) >= 32 * 4
3566 && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
3567 || (INTVAL (operands[1]) >= 0
3568 && INTVAL (operands[1]) < 32 * 4
3569 && (INTVAL (operands[1]) & 3) != 0))"
3570 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3571 (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
3572 {
3573 HOST_WIDE_INT val = INTVAL (operands[1]);
3574
3575 if (val < 0)
3576 operands[2] = const0_rtx;
3577 else if (val >= 32 * 4)
3578 {
3579 int off = val & 3;
3580
3581 operands[1] = GEN_INT (0x7c + off);
3582 operands[2] = GEN_INT (val - off - 0x7c);
3583 }
3584 else
3585 {
3586 int off = val & 3;
3587
3588 operands[1] = GEN_INT (off);
3589 operands[2] = GEN_INT (val - off);
3590 }
3591 })
3592
3593 ;; On the mips16, we can split a load of certain constants into a load
3594 ;; and an add. This turns a 4 byte instruction into 2 2 byte
3595 ;; instructions.
3596
3597 (define_split
3598 [(set (match_operand:SI 0 "register_operand")
3599 (match_operand:SI 1 "const_int_operand"))]
3600 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3601 && REG_P (operands[0])
3602 && M16_REG_P (REGNO (operands[0]))
3603 && GET_CODE (operands[1]) == CONST_INT
3604 && INTVAL (operands[1]) >= 0x100
3605 && INTVAL (operands[1]) <= 0xff + 0x7f"
3606 [(set (match_dup 0) (match_dup 1))
3607 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
3608 {
3609 int val = INTVAL (operands[1]);
3610
3611 operands[1] = GEN_INT (0xff);
3612 operands[2] = GEN_INT (val - 0xff);
3613 })
3614
3615 ;; This insn handles moving CCmode values. It's really just a
3616 ;; slightly simplified copy of movsi_internal2, with additional cases
3617 ;; to move a condition register to a general register and to move
3618 ;; between the general registers and the floating point registers.
3619
3620 (define_insn "movcc"
3621 [(set (match_operand:CC 0 "nonimmediate_operand" "=d,*d,*d,*m,*d,*f,*f,*f,*m")
3622 (match_operand:CC 1 "general_operand" "z,*d,*m,*d,*f,*d,*f,*m,*f"))]
3623 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3624 { return mips_output_move (operands[0], operands[1]); }
3625 [(set_attr "type" "multi,move,load,store,mfc,mtc,fmove,fpload,fpstore")
3626 (set_attr "mode" "SI")
3627 (set_attr "length" "8,4,*,*,4,4,4,*,*")])
3628
3629 ;; Reload condition code registers. reload_incc and reload_outcc
3630 ;; both handle moves from arbitrary operands into condition code
3631 ;; registers. reload_incc handles the more common case in which
3632 ;; a source operand is constrained to be in a condition-code
3633 ;; register, but has not been allocated to one.
3634 ;;
3635 ;; Sometimes, such as in movcc, we have a CCmode destination whose
3636 ;; constraints do not include 'z'. reload_outcc handles the case
3637 ;; when such an operand is allocated to a condition-code register.
3638 ;;
3639 ;; Note that reloads from a condition code register to some
3640 ;; other location can be done using ordinary moves. Moving
3641 ;; into a GPR takes a single movcc, moving elsewhere takes
3642 ;; two. We can leave these cases to the generic reload code.
3643 (define_expand "reload_incc"
3644 [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
3645 (match_operand:CC 1 "general_operand" ""))
3646 (clobber (match_operand:TF 2 "register_operand" "=&f"))]
3647 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3648 {
3649 mips_emit_fcc_reload (operands[0], operands[1], operands[2]);
3650 DONE;
3651 })
3652
3653 (define_expand "reload_outcc"
3654 [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
3655 (match_operand:CC 1 "register_operand" ""))
3656 (clobber (match_operand:TF 2 "register_operand" "=&f"))]
3657 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3658 {
3659 mips_emit_fcc_reload (operands[0], operands[1], operands[2]);
3660 DONE;
3661 })
3662
3663 ;; MIPS4 supports loading and storing a floating point register from
3664 ;; the sum of two general registers. We use two versions for each of
3665 ;; these four instructions: one where the two general registers are
3666 ;; SImode, and one where they are DImode. This is because general
3667 ;; registers will be in SImode when they hold 32-bit values, but,
3668 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
3669 ;; instructions will still work correctly.
3670
3671 ;; ??? Perhaps it would be better to support these instructions by
3672 ;; modifying GO_IF_LEGITIMATE_ADDRESS and friends. However, since
3673 ;; these instructions can only be used to load and store floating
3674 ;; point registers, that would probably cause trouble in reload.
3675
3676 (define_insn "*<ANYF:loadx>_<P:mode>"
3677 [(set (match_operand:ANYF 0 "register_operand" "=f")
3678 (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
3679 (match_operand:P 2 "register_operand" "d"))))]
3680 "ISA_HAS_FP4"
3681 "<ANYF:loadx>\t%0,%1(%2)"
3682 [(set_attr "type" "fpidxload")
3683 (set_attr "mode" "<ANYF:UNITMODE>")])
3684
3685 (define_insn "*<ANYF:storex>_<P:mode>"
3686 [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
3687 (match_operand:P 2 "register_operand" "d")))
3688 (match_operand:ANYF 0 "register_operand" "f"))]
3689 "ISA_HAS_FP4"
3690 "<ANYF:storex>\t%0,%1(%2)"
3691 [(set_attr "type" "fpidxstore")
3692 (set_attr "mode" "<ANYF:UNITMODE>")])
3693
3694 ;; Scaled indexed address load.
3695 ;; Per md.texi, we only need to look for a pattern with multiply in the
3696 ;; address expression, not shift.
3697
3698 (define_insn "*lwxs"
3699 [(set (match_operand:SI 0 "register_operand" "=d")
3700 (mem:SI (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
3701 (const_int 4))
3702 (match_operand:SI 2 "register_operand" "d"))))]
3703 "ISA_HAS_LWXS"
3704 "lwxs\t%0,%1(%2)"
3705 [(set_attr "type" "load")
3706 (set_attr "mode" "SI")
3707 (set_attr "length" "4")])
3708
3709 ;; 16-bit Integer moves
3710
3711 ;; Unlike most other insns, the move insns can't be split with
3712 ;; different predicates, because register spilling and other parts of
3713 ;; the compiler, have memoized the insn number already.
3714 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
3715
3716 (define_expand "movhi"
3717 [(set (match_operand:HI 0 "")
3718 (match_operand:HI 1 ""))]
3719 ""
3720 {
3721 if (mips_legitimize_move (HImode, operands[0], operands[1]))
3722 DONE;
3723 })
3724
3725 (define_insn "*movhi_internal"
3726 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,m,*d,*f,*f,*x")
3727 (match_operand:HI 1 "move_operand" "d,I,m,dJ,*f,*d,*f,*d"))]
3728 "!TARGET_MIPS16
3729 && (register_operand (operands[0], HImode)
3730 || reg_or_0_operand (operands[1], HImode))"
3731 "@
3732 move\t%0,%1
3733 li\t%0,%1
3734 lhu\t%0,%1
3735 sh\t%z1,%0
3736 mfc1\t%0,%1
3737 mtc1\t%1,%0
3738 mov.s\t%0,%1
3739 mt%0\t%1"
3740 [(set_attr "type" "move,arith,load,store,mfc,mtc,fmove,mthilo")
3741 (set_attr "mode" "HI")
3742 (set_attr "length" "4,4,*,*,4,4,4,4")])
3743
3744 (define_insn "*movhi_mips16"
3745 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m")
3746 (match_operand:HI 1 "move_operand" "d,d,y,K,N,m,d"))]
3747 "TARGET_MIPS16
3748 && (register_operand (operands[0], HImode)
3749 || register_operand (operands[1], HImode))"
3750 "@
3751 move\t%0,%1
3752 move\t%0,%1
3753 move\t%0,%1
3754 li\t%0,%1
3755 #
3756 lhu\t%0,%1
3757 sh\t%1,%0"
3758 [(set_attr "type" "move,move,move,arith,arith,load,store")
3759 (set_attr "mode" "HI")
3760 (set_attr_alternative "length"
3761 [(const_int 4)
3762 (const_int 4)
3763 (const_int 4)
3764 (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3765 (const_int 4)
3766 (const_int 8))
3767 (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3768 (const_int 8)
3769 (const_int 12))
3770 (const_string "*")
3771 (const_string "*")])])
3772
3773
3774 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
3775 ;; when the original load is a 4 byte instruction but the add and the
3776 ;; load are 2 2 byte instructions.
3777
3778 (define_split
3779 [(set (match_operand:HI 0 "register_operand")
3780 (mem:HI (plus:SI (match_dup 0)
3781 (match_operand:SI 1 "const_int_operand"))))]
3782 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3783 && REG_P (operands[0])
3784 && M16_REG_P (REGNO (operands[0]))
3785 && GET_CODE (operands[1]) == CONST_INT
3786 && ((INTVAL (operands[1]) < 0
3787 && INTVAL (operands[1]) >= -0x80)
3788 || (INTVAL (operands[1]) >= 32 * 2
3789 && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
3790 || (INTVAL (operands[1]) >= 0
3791 && INTVAL (operands[1]) < 32 * 2
3792 && (INTVAL (operands[1]) & 1) != 0))"
3793 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3794 (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
3795 {
3796 HOST_WIDE_INT val = INTVAL (operands[1]);
3797
3798 if (val < 0)
3799 operands[2] = const0_rtx;
3800 else if (val >= 32 * 2)
3801 {
3802 int off = val & 1;
3803
3804 operands[1] = GEN_INT (0x7e + off);
3805 operands[2] = GEN_INT (val - off - 0x7e);
3806 }
3807 else
3808 {
3809 int off = val & 1;
3810
3811 operands[1] = GEN_INT (off);
3812 operands[2] = GEN_INT (val - off);
3813 }
3814 })
3815
3816 ;; 8-bit Integer moves
3817
3818 ;; Unlike most other insns, the move insns can't be split with
3819 ;; different predicates, because register spilling and other parts of
3820 ;; the compiler, have memoized the insn number already.
3821 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
3822
3823 (define_expand "movqi"
3824 [(set (match_operand:QI 0 "")
3825 (match_operand:QI 1 ""))]
3826 ""
3827 {
3828 if (mips_legitimize_move (QImode, operands[0], operands[1]))
3829 DONE;
3830 })
3831
3832 (define_insn "*movqi_internal"
3833 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,m,*d,*f,*f,*x")
3834 (match_operand:QI 1 "move_operand" "d,I,m,dJ,*f,*d,*f,*d"))]
3835 "!TARGET_MIPS16
3836 && (register_operand (operands[0], QImode)
3837 || reg_or_0_operand (operands[1], QImode))"
3838 "@
3839 move\t%0,%1
3840 li\t%0,%1
3841 lbu\t%0,%1
3842 sb\t%z1,%0
3843 mfc1\t%0,%1
3844 mtc1\t%1,%0
3845 mov.s\t%0,%1
3846 mt%0\t%1"
3847 [(set_attr "type" "move,arith,load,store,mfc,mtc,fmove,mthilo")
3848 (set_attr "mode" "QI")
3849 (set_attr "length" "4,4,*,*,4,4,4,4")])
3850
3851 (define_insn "*movqi_mips16"
3852 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m")
3853 (match_operand:QI 1 "move_operand" "d,d,y,K,N,m,d"))]
3854 "TARGET_MIPS16
3855 && (register_operand (operands[0], QImode)
3856 || register_operand (operands[1], QImode))"
3857 "@
3858 move\t%0,%1
3859 move\t%0,%1
3860 move\t%0,%1
3861 li\t%0,%1
3862 #
3863 lbu\t%0,%1
3864 sb\t%1,%0"
3865 [(set_attr "type" "move,move,move,arith,arith,load,store")
3866 (set_attr "mode" "QI")
3867 (set_attr "length" "4,4,4,4,8,*,*")])
3868
3869 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
3870 ;; when the original load is a 4 byte instruction but the add and the
3871 ;; load are 2 2 byte instructions.
3872
3873 (define_split
3874 [(set (match_operand:QI 0 "register_operand")
3875 (mem:QI (plus:SI (match_dup 0)
3876 (match_operand:SI 1 "const_int_operand"))))]
3877 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3878 && REG_P (operands[0])
3879 && M16_REG_P (REGNO (operands[0]))
3880 && GET_CODE (operands[1]) == CONST_INT
3881 && ((INTVAL (operands[1]) < 0
3882 && INTVAL (operands[1]) >= -0x80)
3883 || (INTVAL (operands[1]) >= 32
3884 && INTVAL (operands[1]) <= 31 + 0x7f))"
3885 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3886 (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
3887 {
3888 HOST_WIDE_INT val = INTVAL (operands[1]);
3889
3890 if (val < 0)
3891 operands[2] = const0_rtx;
3892 else
3893 {
3894 operands[1] = GEN_INT (0x7f);
3895 operands[2] = GEN_INT (val - 0x7f);
3896 }
3897 })
3898
3899 ;; 32-bit floating point moves
3900
3901 (define_expand "movsf"
3902 [(set (match_operand:SF 0 "")
3903 (match_operand:SF 1 ""))]
3904 ""
3905 {
3906 if (mips_legitimize_move (SFmode, operands[0], operands[1]))
3907 DONE;
3908 })
3909
3910 (define_insn "*movsf_hardfloat"
3911 [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3912 (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
3913 "TARGET_HARD_FLOAT
3914 && (register_operand (operands[0], SFmode)
3915 || reg_or_0_operand (operands[1], SFmode))"
3916 { return mips_output_move (operands[0], operands[1]); }
3917 [(set_attr "type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
3918 (set_attr "mode" "SF")
3919 (set_attr "length" "4,4,*,*,*,4,4,4,*,*")])
3920
3921 (define_insn "*movsf_softfloat"
3922 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
3923 (match_operand:SF 1 "move_operand" "Gd,m,d"))]
3924 "TARGET_SOFT_FLOAT && !TARGET_MIPS16
3925 && (register_operand (operands[0], SFmode)
3926 || reg_or_0_operand (operands[1], SFmode))"
3927 { return mips_output_move (operands[0], operands[1]); }
3928 [(set_attr "type" "move,load,store")
3929 (set_attr "mode" "SF")
3930 (set_attr "length" "4,*,*")])
3931
3932 (define_insn "*movsf_mips16"
3933 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
3934 (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
3935 "TARGET_MIPS16
3936 && (register_operand (operands[0], SFmode)
3937 || register_operand (operands[1], SFmode))"
3938 { return mips_output_move (operands[0], operands[1]); }
3939 [(set_attr "type" "move,move,move,load,store")
3940 (set_attr "mode" "SF")
3941 (set_attr "length" "4,4,4,*,*")])
3942
3943
3944 ;; 64-bit floating point moves
3945
3946 (define_expand "movdf"
3947 [(set (match_operand:DF 0 "")
3948 (match_operand:DF 1 ""))]
3949 ""
3950 {
3951 if (mips_legitimize_move (DFmode, operands[0], operands[1]))
3952 DONE;
3953 })
3954
3955 (define_insn "*movdf_hardfloat_64bit"
3956 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3957 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
3958 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_64BIT
3959 && (register_operand (operands[0], DFmode)
3960 || reg_or_0_operand (operands[1], DFmode))"
3961 { return mips_output_move (operands[0], operands[1]); }
3962 [(set_attr "type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
3963 (set_attr "mode" "DF")
3964 (set_attr "length" "4,4,*,*,*,4,4,4,*,*")])
3965
3966 ;; This pattern applies to both !TARGET_FLOAT64 and TARGET_FLOAT64.
3967 (define_insn "*movdf_hardfloat_32bit"
3968 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3969 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
3970 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT
3971 && (register_operand (operands[0], DFmode)
3972 || reg_or_0_operand (operands[1], DFmode))"
3973 { return mips_output_move (operands[0], operands[1]); }
3974 [(set_attr "type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
3975 (set_attr "mode" "DF")
3976 (set_attr "length" "4,8,*,*,*,8,8,8,*,*")])
3977
3978 (define_insn "*movdf_softfloat"
3979 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m,d,f,f")
3980 (match_operand:DF 1 "move_operand" "dG,m,dG,f,d,f"))]
3981 "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
3982 && (register_operand (operands[0], DFmode)
3983 || reg_or_0_operand (operands[1], DFmode))"
3984 { return mips_output_move (operands[0], operands[1]); }
3985 [(set_attr "type" "multi,load,store,mfc,mtc,fmove")
3986 (set_attr "mode" "DF")
3987 (set_attr "length" "8,*,*,4,4,4")])
3988
3989 (define_insn "*movdf_mips16"
3990 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
3991 (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
3992 "TARGET_MIPS16
3993 && (register_operand (operands[0], DFmode)
3994 || register_operand (operands[1], DFmode))"
3995 { return mips_output_move (operands[0], operands[1]); }
3996 [(set_attr "type" "multi,multi,multi,load,store")
3997 (set_attr "mode" "DF")
3998 (set_attr "length" "8,8,8,*,*")])
3999
4000 (define_split
4001 [(set (match_operand:DI 0 "nonimmediate_operand")
4002 (match_operand:DI 1 "move_operand"))]
4003 "reload_completed && !TARGET_64BIT
4004 && mips_split_64bit_move_p (operands[0], operands[1])"
4005 [(const_int 0)]
4006 {
4007 mips_split_64bit_move (operands[0], operands[1]);
4008 DONE;
4009 })
4010
4011 (define_split
4012 [(set (match_operand:DF 0 "nonimmediate_operand")
4013 (match_operand:DF 1 "move_operand"))]
4014 "reload_completed && !TARGET_64BIT
4015 && mips_split_64bit_move_p (operands[0], operands[1])"
4016 [(const_int 0)]
4017 {
4018 mips_split_64bit_move (operands[0], operands[1]);
4019 DONE;
4020 })
4021
4022 ;; When generating mips16 code, split moves of negative constants into
4023 ;; a positive "li" followed by a negation.
4024 (define_split
4025 [(set (match_operand 0 "register_operand")
4026 (match_operand 1 "const_int_operand"))]
4027 "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
4028 [(set (match_dup 2)
4029 (match_dup 3))
4030 (set (match_dup 2)
4031 (neg:SI (match_dup 2)))]
4032 {
4033 operands[2] = gen_lowpart (SImode, operands[0]);
4034 operands[3] = GEN_INT (-INTVAL (operands[1]));
4035 })
4036
4037 ;; 64-bit paired-single floating point moves
4038
4039 (define_expand "movv2sf"
4040 [(set (match_operand:V2SF 0)
4041 (match_operand:V2SF 1))]
4042 "TARGET_PAIRED_SINGLE_FLOAT"
4043 {
4044 if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
4045 DONE;
4046 })
4047
4048 (define_insn "movv2sf_hardfloat_64bit"
4049 [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4050 (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
4051 "TARGET_PAIRED_SINGLE_FLOAT
4052 && TARGET_64BIT
4053 && (register_operand (operands[0], V2SFmode)
4054 || reg_or_0_operand (operands[1], V2SFmode))"
4055 { return mips_output_move (operands[0], operands[1]); }
4056 [(set_attr "type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4057 (set_attr "mode" "SF")
4058 (set_attr "length" "4,4,*,*,*,4,4,4,*,*")])
4059
4060 ;; The HI and LO registers are not truly independent. If we move an mthi
4061 ;; instruction before an mflo instruction, it will make the result of the
4062 ;; mflo unpredictable. The same goes for mtlo and mfhi.
4063 ;;
4064 ;; We cope with this by making the mflo and mfhi patterns use both HI and LO.
4065 ;; Operand 1 is the register we want, operand 2 is the other one.
4066 ;;
4067 ;; When generating VR4120 or VR4130 code, we use macc{,hi} and
4068 ;; dmacc{,hi} instead of mfhi and mflo. This avoids both the normal
4069 ;; MIPS III hi/lo hazards and the errata related to -mfix-vr4130.
4070
4071 (define_expand "mfhilo_<mode>"
4072 [(set (match_operand:GPR 0 "register_operand")
4073 (unspec:GPR [(match_operand:GPR 1 "register_operand")
4074 (match_operand:GPR 2 "register_operand")]
4075 UNSPEC_MFHILO))])
4076
4077 (define_insn "*mfhilo_<mode>"
4078 [(set (match_operand:GPR 0 "register_operand" "=d,d")
4079 (unspec:GPR [(match_operand:GPR 1 "register_operand" "h,l")
4080 (match_operand:GPR 2 "register_operand" "l,h")]
4081 UNSPEC_MFHILO))]
4082 "!ISA_HAS_MACCHI"
4083 "mf%1\t%0"
4084 [(set_attr "type" "mfhilo")
4085 (set_attr "mode" "<MODE>")])
4086
4087 (define_insn "*mfhilo_<mode>_macc"
4088 [(set (match_operand:GPR 0 "register_operand" "=d,d")
4089 (unspec:GPR [(match_operand:GPR 1 "register_operand" "h,l")
4090 (match_operand:GPR 2 "register_operand" "l,h")]
4091 UNSPEC_MFHILO))]
4092 "ISA_HAS_MACCHI"
4093 "@
4094 <d>macchi\t%0,%.,%.
4095 <d>macc\t%0,%.,%."
4096 [(set_attr "type" "mfhilo")
4097 (set_attr "mode" "<MODE>")])
4098
4099 ;; Patterns for loading or storing part of a paired floating point
4100 ;; register. We need them because odd-numbered floating-point registers
4101 ;; are not fully independent: see mips_split_64bit_move.
4102
4103 ;; Load the low word of operand 0 with operand 1.
4104 (define_insn "load_df_low"
4105 [(set (match_operand:DF 0 "register_operand" "=f,f")
4106 (unspec:DF [(match_operand:SI 1 "general_operand" "dJ,m")]
4107 UNSPEC_LOAD_DF_LOW))]
4108 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
4109 {
4110 operands[0] = mips_subword (operands[0], 0);
4111 return mips_output_move (operands[0], operands[1]);
4112 }
4113 [(set_attr "type" "mtc,fpload")
4114 (set_attr "mode" "SF")])
4115
4116 ;; Load the high word of operand 0 from operand 1, preserving the value
4117 ;; in the low word.
4118 (define_insn "load_df_high"
4119 [(set (match_operand:DF 0 "register_operand" "=f,f")
4120 (unspec:DF [(match_operand:SI 1 "general_operand" "dJ,m")
4121 (match_operand:DF 2 "register_operand" "0,0")]
4122 UNSPEC_LOAD_DF_HIGH))]
4123 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
4124 {
4125 operands[0] = mips_subword (operands[0], 1);
4126 return mips_output_move (operands[0], operands[1]);
4127 }
4128 [(set_attr "type" "mtc,fpload")
4129 (set_attr "mode" "SF")])
4130
4131 ;; Store the high word of operand 1 in operand 0. The corresponding
4132 ;; low-word move is done in the normal way.
4133 (define_insn "store_df_high"
4134 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
4135 (unspec:SI [(match_operand:DF 1 "register_operand" "f,f")]
4136 UNSPEC_STORE_DF_HIGH))]
4137 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
4138 {
4139 operands[1] = mips_subword (operands[1], 1);
4140 return mips_output_move (operands[0], operands[1]);
4141 }
4142 [(set_attr "type" "mfc,fpstore")
4143 (set_attr "mode" "SF")])
4144
4145 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
4146 ;; value in the low word.
4147 (define_insn "mthc1"
4148 [(set (match_operand:DF 0 "register_operand" "=f")
4149 (unspec:DF [(match_operand:SI 1 "general_operand" "dJ")
4150 (match_operand:DF 2 "register_operand" "0")]
4151 UNSPEC_MTHC1))]
4152 "TARGET_HARD_FLOAT && !TARGET_64BIT && ISA_HAS_MXHC1"
4153 "mthc1\t%z1,%0"
4154 [(set_attr "type" "mtc")
4155 (set_attr "mode" "SF")])
4156
4157 ;; Move high word of operand 1 to operand 0 using mfhc1. The corresponding
4158 ;; low-word move is done in the normal way.
4159 (define_insn "mfhc1"
4160 [(set (match_operand:SI 0 "register_operand" "=d")
4161 (unspec:SI [(match_operand:DF 1 "register_operand" "f")]
4162 UNSPEC_MFHC1))]
4163 "TARGET_HARD_FLOAT && !TARGET_64BIT && ISA_HAS_MXHC1"
4164 "mfhc1\t%0,%1"
4165 [(set_attr "type" "mfc")
4166 (set_attr "mode" "SF")])
4167
4168 ;; Move a constant that satisfies CONST_GP_P into operand 0.
4169 (define_expand "load_const_gp"
4170 [(set (match_operand 0 "register_operand" "=d")
4171 (const (unspec [(const_int 0)] UNSPEC_GP)))])
4172
4173 ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset
4174 ;; of _gp from the start of this function. Operand 1 is the incoming
4175 ;; function address.
4176 (define_insn_and_split "loadgp_newabi"
4177 [(unspec_volatile [(match_operand 0 "" "")
4178 (match_operand 1 "register_operand" "")] UNSPEC_LOADGP)]
4179 "mips_current_loadgp_style () == LOADGP_NEWABI"
4180 "#"
4181 ""
4182 [(set (match_dup 2) (match_dup 3))
4183 (set (match_dup 2) (match_dup 4))
4184 (set (match_dup 2) (match_dup 5))]
4185 {
4186 operands[2] = pic_offset_table_rtx;
4187 operands[3] = gen_rtx_HIGH (Pmode, operands[0]);
4188 operands[4] = gen_rtx_PLUS (Pmode, operands[2], operands[1]);
4189 operands[5] = gen_rtx_LO_SUM (Pmode, operands[2], operands[0]);
4190 }
4191 [(set_attr "length" "12")])
4192
4193 ;; Likewise, for -mno-shared code. Operand 0 is the __gnu_local_gp symbol.
4194 (define_insn_and_split "loadgp_absolute"
4195 [(unspec_volatile [(match_operand 0 "" "")] UNSPEC_LOADGP)]
4196 "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
4197 "#"
4198 ""
4199 [(const_int 0)]
4200 {
4201 mips_emit_move (pic_offset_table_rtx, operands[0]);
4202 DONE;
4203 }
4204 [(set_attr "length" "8")])
4205
4206 ;; The use of gp is hidden when not using explicit relocations.
4207 ;; This blockage instruction prevents the gp load from being
4208 ;; scheduled after an implicit use of gp. It also prevents
4209 ;; the load from being deleted as dead.
4210 (define_insn "loadgp_blockage"
4211 [(unspec_volatile [(reg:DI 28)] UNSPEC_BLOCKAGE)]
4212 ""
4213 ""
4214 [(set_attr "type" "unknown")
4215 (set_attr "mode" "none")
4216 (set_attr "length" "0")])
4217
4218 ;; Initialize $gp for RTP PIC. Operand 0 is the __GOTT_BASE__ symbol
4219 ;; and operand 1 is the __GOTT_INDEX__ symbol.
4220 (define_insn "loadgp_rtp"
4221 [(unspec_volatile [(match_operand 0 "symbol_ref_operand")
4222 (match_operand 1 "symbol_ref_operand")] UNSPEC_LOADGP)]
4223 "mips_current_loadgp_style () == LOADGP_RTP"
4224 "#"
4225 [(set_attr "length" "12")])
4226
4227 (define_split
4228 [(unspec_volatile [(match_operand:P 0 "symbol_ref_operand")
4229 (match_operand:P 1 "symbol_ref_operand")] UNSPEC_LOADGP)]
4230 "mips_current_loadgp_style () == LOADGP_RTP"
4231 [(set (match_dup 2) (high:P (match_dup 3)))
4232 (set (match_dup 2) (unspec:P [(match_dup 2)
4233 (match_dup 3)] UNSPEC_LOAD_GOT))
4234 (set (match_dup 2) (unspec:P [(match_dup 2)
4235 (match_dup 4)] UNSPEC_LOAD_GOT))]
4236 {
4237 operands[2] = pic_offset_table_rtx;
4238 operands[3] = mips_unspec_address (operands[0], SYMBOL_ABSOLUTE);
4239 operands[4] = mips_unspec_address (operands[1], SYMBOL_HALF);
4240 })
4241
4242 ;; Emit a .cprestore directive, which normally expands to a single store
4243 ;; instruction. Note that we continue to use .cprestore for explicit reloc
4244 ;; code so that jals inside inline asms will work correctly.
4245 (define_insn "cprestore"
4246 [(unspec_volatile [(match_operand 0 "const_int_operand" "I,i")
4247 (use (reg:SI 28))]
4248 UNSPEC_CPRESTORE)]
4249 ""
4250 {
4251 if (set_nomacro && which_alternative == 1)
4252 return ".set\tmacro\;.cprestore\t%0\;.set\tnomacro";
4253 else
4254 return ".cprestore\t%0";
4255 }
4256 [(set_attr "type" "store")
4257 (set_attr "length" "4,12")])
4258
4259 ;; Expand in-line code to clear the instruction cache between operand[0] and
4260 ;; operand[1].
4261 (define_expand "clear_cache"
4262 [(match_operand 0 "pmode_register_operand")
4263 (match_operand 1 "pmode_register_operand")]
4264 ""
4265 "
4266 {
4267 if (ISA_HAS_SYNCI)
4268 {
4269 mips_expand_synci_loop (operands[0], operands[1]);
4270 emit_insn (gen_sync ());
4271 emit_insn (gen_clear_hazard ());
4272 }
4273 else if (mips_cache_flush_func && mips_cache_flush_func[0])
4274 {
4275 rtx len = gen_reg_rtx (Pmode);
4276 emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
4277 /* Flush both caches. We need to flush the data cache in case
4278 the system has a write-back cache. */
4279 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mips_cache_flush_func),
4280 0, VOIDmode, 3, operands[0], Pmode, len, Pmode,
4281 GEN_INT (3), TYPE_MODE (integer_type_node));
4282 }
4283 DONE;
4284 }")
4285
4286 (define_insn "sync"
4287 [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
4288 "GENERATE_SYNC"
4289 "%|sync%-")
4290
4291 (define_insn "synci"
4292 [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
4293 UNSPEC_SYNCI)]
4294 "ISA_HAS_SYNCI"
4295 "synci\t0(%0)")
4296
4297 (define_insn "rdhwr"
4298 [(set (match_operand:SI 0 "register_operand" "=d")
4299 (unspec_volatile [(match_operand:SI 1 "const_int_operand" "n")]
4300 UNSPEC_RDHWR))]
4301 "ISA_HAS_SYNCI"
4302 "rdhwr\t%0,$%1")
4303
4304 (define_insn "clear_hazard"
4305 [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
4306 (clobber (reg:SI 31))]
4307 "ISA_HAS_SYNCI"
4308 {
4309 return ".set\tpush\n"
4310 "\t.set\tnoreorder\n"
4311 "\t.set\tnomacro\n"
4312 "\tbal\t1f\n"
4313 "\tnop\n"
4314 "1:\taddiu\t$31,$31,12\n"
4315 "\tjr.hb\t$31\n"
4316 "\tnop\n"
4317 "\t.set\tpop";
4318 }
4319 [(set_attr "length" "20")])
4320
4321 ;; Atomic memory operations.
4322
4323 (define_insn "memory_barrier"
4324 [(set (mem:BLK (scratch))
4325 (unspec:BLK [(const_int 0)] UNSPEC_MEMORY_BARRIER))]
4326 "GENERATE_SYNC"
4327 "%|sync%-")
4328
4329 (define_insn "sync_compare_and_swap<mode>"
4330 [(set (match_operand:GPR 0 "register_operand" "=&d,d")
4331 (match_operand:GPR 1 "memory_operand" "+R,R"))
4332 (set (match_dup 1)
4333 (unspec_volatile:GPR [(match_operand:GPR 2 "register_operand" "d,d")
4334 (match_operand:GPR 3 "arith_operand" "I,d")]
4335 UNSPEC_COMPARE_AND_SWAP))]
4336 "GENERATE_LL_SC"
4337 {
4338 if (which_alternative == 0)
4339 return MIPS_COMPARE_AND_SWAP ("<d>", "li");
4340 else
4341 return MIPS_COMPARE_AND_SWAP ("<d>", "move");
4342 }
4343 [(set_attr "length" "28")])
4344
4345 (define_insn "sync_add<mode>"
4346 [(set (match_operand:GPR 0 "memory_operand" "+R,R")
4347 (unspec_volatile:GPR
4348 [(plus:GPR (match_dup 0)
4349 (match_operand:GPR 1 "arith_operand" "I,d"))]
4350 UNSPEC_SYNC_OLD_OP))]
4351 "GENERATE_LL_SC"
4352 {
4353 if (which_alternative == 0)
4354 return MIPS_SYNC_OP ("<d>", "<d>addiu");
4355 else
4356 return MIPS_SYNC_OP ("<d>", "<d>addu");
4357 }
4358 [(set_attr "length" "24")])
4359
4360 (define_insn "sync_sub<mode>"
4361 [(set (match_operand:GPR 0 "memory_operand" "+R")
4362 (unspec_volatile:GPR
4363 [(minus:GPR (match_dup 0)
4364 (match_operand:GPR 1 "register_operand" "d"))]
4365 UNSPEC_SYNC_OLD_OP))]
4366 "GENERATE_LL_SC"
4367 {
4368 return MIPS_SYNC_OP ("<d>", "<d>subu");
4369 }
4370 [(set_attr "length" "24")])
4371
4372 (define_insn "sync_old_add<mode>"
4373 [(set (match_operand:GPR 0 "register_operand" "=&d,d")
4374 (match_operand:GPR 1 "memory_operand" "+R,R"))
4375 (set (match_dup 1)
4376 (unspec_volatile:GPR
4377 [(plus:GPR (match_dup 1)
4378 (match_operand:GPR 2 "arith_operand" "I,d"))]
4379 UNSPEC_SYNC_OLD_OP))]
4380 "GENERATE_LL_SC"
4381 {
4382 if (which_alternative == 0)
4383 return MIPS_SYNC_OLD_OP ("<d>", "<d>addiu");
4384 else
4385 return MIPS_SYNC_OLD_OP ("<d>", "<d>addu");
4386 }
4387 [(set_attr "length" "24")])
4388
4389 (define_insn "sync_old_sub<mode>"
4390 [(set (match_operand:GPR 0 "register_operand" "=&d")
4391 (match_operand:GPR 1 "memory_operand" "+R"))
4392 (set (match_dup 1)
4393 (unspec_volatile:GPR
4394 [(minus:GPR (match_dup 1)
4395 (match_operand:GPR 2 "register_operand" "d"))]
4396 UNSPEC_SYNC_OLD_OP))]
4397 "GENERATE_LL_SC"
4398 {
4399 return MIPS_SYNC_OLD_OP ("<d>", "<d>subu");
4400 }
4401 [(set_attr "length" "24")])
4402
4403 (define_insn "sync_new_add<mode>"
4404 [(set (match_operand:GPR 0 "register_operand" "=&d,d")
4405 (plus:GPR (match_operand:GPR 1 "memory_operand" "+R,R")
4406 (match_operand:GPR 2 "arith_operand" "I,d")))
4407 (set (match_dup 1)
4408 (unspec_volatile:GPR
4409 [(plus:GPR (match_dup 1) (match_dup 2))]
4410 UNSPEC_SYNC_NEW_OP))]
4411 "GENERATE_LL_SC"
4412 {
4413 if (which_alternative == 0)
4414 return MIPS_SYNC_NEW_OP ("<d>", "<d>addiu");
4415 else
4416 return MIPS_SYNC_NEW_OP ("<d>", "<d>addu");
4417 }
4418 [(set_attr "length" "24")])
4419
4420 (define_insn "sync_new_sub<mode>"
4421 [(set (match_operand:GPR 0 "register_operand" "=&d")
4422 (minus:GPR (match_operand:GPR 1 "memory_operand" "+R")
4423 (match_operand:GPR 2 "register_operand" "d")))
4424 (set (match_dup 1)
4425 (unspec_volatile:GPR
4426 [(minus:GPR (match_dup 1) (match_dup 2))]
4427 UNSPEC_SYNC_NEW_OP))]
4428 "GENERATE_LL_SC"
4429 {
4430 return MIPS_SYNC_NEW_OP ("<d>", "<d>subu");
4431 }
4432 [(set_attr "length" "24")])
4433
4434 (define_insn "sync_<optab><mode>"
4435 [(set (match_operand:GPR 0 "memory_operand" "+R,R")
4436 (unspec_volatile:GPR
4437 [(fetchop_bit:GPR (match_operand:GPR 1 "uns_arith_operand" "K,d")
4438 (match_dup 0))]
4439 UNSPEC_SYNC_OLD_OP))]
4440 "GENERATE_LL_SC"
4441 {
4442 if (which_alternative == 0)
4443 return MIPS_SYNC_OP ("<d>", "<immediate_insn>");
4444 else
4445 return MIPS_SYNC_OP ("<d>", "<insn>");
4446 }
4447 [(set_attr "length" "24")])
4448
4449 (define_insn "sync_old_<optab><mode>"
4450 [(set (match_operand:GPR 0 "register_operand" "=&d,d")
4451 (match_operand:GPR 1 "memory_operand" "+R,R"))
4452 (set (match_dup 1)
4453 (unspec_volatile:GPR
4454 [(fetchop_bit:GPR (match_operand:GPR 2 "uns_arith_operand" "K,d")
4455 (match_dup 1))]
4456 UNSPEC_SYNC_OLD_OP))]
4457 "GENERATE_LL_SC"
4458 {
4459 if (which_alternative == 0)
4460 return MIPS_SYNC_OLD_OP ("<d>", "<immediate_insn>");
4461 else
4462 return MIPS_SYNC_OLD_OP ("<d>", "<insn>");
4463 }
4464 [(set_attr "length" "24")])
4465
4466 (define_insn "sync_new_<optab><mode>"
4467 [(set (match_operand:GPR 0 "register_operand" "=&d,d")
4468 (match_operand:GPR 1 "memory_operand" "+R,R"))
4469 (set (match_dup 1)
4470 (unspec_volatile:GPR
4471 [(fetchop_bit:GPR (match_operand:GPR 2 "uns_arith_operand" "K,d")
4472 (match_dup 1))]
4473 UNSPEC_SYNC_NEW_OP))]
4474 "GENERATE_LL_SC"
4475 {
4476 if (which_alternative == 0)
4477 return MIPS_SYNC_NEW_OP ("<d>", "<immediate_insn>");
4478 else
4479 return MIPS_SYNC_NEW_OP ("<d>", "<insn>");
4480 }
4481 [(set_attr "length" "24")])
4482
4483 (define_insn "sync_nand<mode>"
4484 [(set (match_operand:GPR 0 "memory_operand" "+R,R")
4485 (unspec_volatile:GPR [(match_operand:GPR 1 "uns_arith_operand" "K,d")]
4486 UNSPEC_SYNC_OLD_OP))]
4487 "GENERATE_LL_SC"
4488 {
4489 if (which_alternative == 0)
4490 return MIPS_SYNC_NAND ("<d>", "andi");
4491 else
4492 return MIPS_SYNC_NAND ("<d>", "and");
4493 }
4494 [(set_attr "length" "28")])
4495
4496 (define_insn "sync_old_nand<mode>"
4497 [(set (match_operand:GPR 0 "register_operand" "=&d,d")
4498 (match_operand:GPR 1 "memory_operand" "+R,R"))
4499 (set (match_dup 1)
4500 (unspec_volatile:GPR [(match_operand:GPR 2 "uns_arith_operand" "K,d")]
4501 UNSPEC_SYNC_OLD_OP))]
4502 "GENERATE_LL_SC"
4503 {
4504 if (which_alternative == 0)
4505 return MIPS_SYNC_OLD_NAND ("<d>", "andi");
4506 else
4507 return MIPS_SYNC_OLD_NAND ("<d>", "and");
4508 }
4509 [(set_attr "length" "28")])
4510
4511 (define_insn "sync_new_nand<mode>"
4512 [(set (match_operand:GPR 0 "register_operand" "=&d,d")
4513 (match_operand:GPR 1 "memory_operand" "+R,R"))
4514 (set (match_dup 1)
4515 (unspec_volatile:GPR [(match_operand:GPR 2 "uns_arith_operand" "K,d")]
4516 UNSPEC_SYNC_NEW_OP))]
4517 "GENERATE_LL_SC"
4518 {
4519 if (which_alternative == 0)
4520 return MIPS_SYNC_NEW_NAND ("<d>", "andi");
4521 else
4522 return MIPS_SYNC_NEW_NAND ("<d>", "and");
4523 }
4524 [(set_attr "length" "28")])
4525
4526 (define_insn "sync_lock_test_and_set<mode>"
4527 [(set (match_operand:GPR 0 "register_operand" "=&d,d")
4528 (match_operand:GPR 1 "memory_operand" "+R,R"))
4529 (set (match_dup 1)
4530 (unspec_volatile:GPR [(match_operand:GPR 2 "arith_operand" "I,d")]
4531 UNSPEC_SYNC_EXCHANGE))]
4532 "GENERATE_LL_SC"
4533 {
4534 if (which_alternative == 0)
4535 return MIPS_SYNC_EXCHANGE ("<d>", "li");
4536 else
4537 return MIPS_SYNC_EXCHANGE ("<d>", "move");
4538 }
4539 [(set_attr "length" "24")])
4540 \f
4541 ;; Block moves, see mips.c for more details.
4542 ;; Argument 0 is the destination
4543 ;; Argument 1 is the source
4544 ;; Argument 2 is the length
4545 ;; Argument 3 is the alignment
4546
4547 (define_expand "movmemsi"
4548 [(parallel [(set (match_operand:BLK 0 "general_operand")
4549 (match_operand:BLK 1 "general_operand"))
4550 (use (match_operand:SI 2 ""))
4551 (use (match_operand:SI 3 "const_int_operand"))])]
4552 "!TARGET_MIPS16 && !TARGET_MEMCPY"
4553 {
4554 if (mips_expand_block_move (operands[0], operands[1], operands[2]))
4555 DONE;
4556 else
4557 FAIL;
4558 })
4559 \f
4560 ;;
4561 ;; ....................
4562 ;;
4563 ;; SHIFTS
4564 ;;
4565 ;; ....................
4566
4567 (define_expand "<optab><mode>3"
4568 [(set (match_operand:GPR 0 "register_operand")
4569 (any_shift:GPR (match_operand:GPR 1 "register_operand")
4570 (match_operand:SI 2 "arith_operand")))]
4571 ""
4572 {
4573 /* On the mips16, a shift of more than 8 is a four byte instruction,
4574 so, for a shift between 8 and 16, it is just as fast to do two
4575 shifts of 8 or less. If there is a lot of shifting going on, we
4576 may win in CSE. Otherwise combine will put the shifts back
4577 together again. This can be called by function_arg, so we must
4578 be careful not to allocate a new register if we've reached the
4579 reload pass. */
4580 if (TARGET_MIPS16
4581 && optimize
4582 && GET_CODE (operands[2]) == CONST_INT
4583 && INTVAL (operands[2]) > 8
4584 && INTVAL (operands[2]) <= 16
4585 && !reload_in_progress
4586 && !reload_completed)
4587 {
4588 rtx temp = gen_reg_rtx (<MODE>mode);
4589
4590 emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
4591 emit_insn (gen_<optab><mode>3 (operands[0], temp,
4592 GEN_INT (INTVAL (operands[2]) - 8)));
4593 DONE;
4594 }
4595 })
4596
4597 (define_insn "*<optab><mode>3"
4598 [(set (match_operand:GPR 0 "register_operand" "=d")
4599 (any_shift:GPR (match_operand:GPR 1 "register_operand" "d")
4600 (match_operand:SI 2 "arith_operand" "dI")))]
4601 "!TARGET_MIPS16"
4602 {
4603 if (GET_CODE (operands[2]) == CONST_INT)
4604 operands[2] = GEN_INT (INTVAL (operands[2])
4605 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
4606
4607 return "<d><insn>\t%0,%1,%2";
4608 }
4609 [(set_attr "type" "shift")
4610 (set_attr "mode" "<MODE>")])
4611
4612 (define_insn "*<optab>si3_extend"
4613 [(set (match_operand:DI 0 "register_operand" "=d")
4614 (sign_extend:DI
4615 (any_shift:SI (match_operand:SI 1 "register_operand" "d")
4616 (match_operand:SI 2 "arith_operand" "dI"))))]
4617 "TARGET_64BIT && !TARGET_MIPS16"
4618 {
4619 if (GET_CODE (operands[2]) == CONST_INT)
4620 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
4621
4622 return "<insn>\t%0,%1,%2";
4623 }
4624 [(set_attr "type" "shift")
4625 (set_attr "mode" "SI")])
4626
4627 (define_insn "*<optab>si3_mips16"
4628 [(set (match_operand:SI 0 "register_operand" "=d,d")
4629 (any_shift:SI (match_operand:SI 1 "register_operand" "0,d")
4630 (match_operand:SI 2 "arith_operand" "d,I")))]
4631 "TARGET_MIPS16"
4632 {
4633 if (which_alternative == 0)
4634 return "<insn>\t%0,%2";
4635
4636 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
4637 return "<insn>\t%0,%1,%2";
4638 }
4639 [(set_attr "type" "shift")
4640 (set_attr "mode" "SI")
4641 (set_attr_alternative "length"
4642 [(const_int 4)
4643 (if_then_else (match_operand 2 "m16_uimm3_b")
4644 (const_int 4)
4645 (const_int 8))])])
4646
4647 ;; We need separate DImode MIPS16 patterns because of the irregularity
4648 ;; of right shifts.
4649 (define_insn "*ashldi3_mips16"
4650 [(set (match_operand:DI 0 "register_operand" "=d,d")
4651 (ashift:DI (match_operand:DI 1 "register_operand" "0,d")
4652 (match_operand:SI 2 "arith_operand" "d,I")))]
4653 "TARGET_64BIT && TARGET_MIPS16"
4654 {
4655 if (which_alternative == 0)
4656 return "dsll\t%0,%2";
4657
4658 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
4659 return "dsll\t%0,%1,%2";
4660 }
4661 [(set_attr "type" "shift")
4662 (set_attr "mode" "DI")
4663 (set_attr_alternative "length"
4664 [(const_int 4)
4665 (if_then_else (match_operand 2 "m16_uimm3_b")
4666 (const_int 4)
4667 (const_int 8))])])
4668
4669 (define_insn "*ashrdi3_mips16"
4670 [(set (match_operand:DI 0 "register_operand" "=d,d")
4671 (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
4672 (match_operand:SI 2 "arith_operand" "d,I")))]
4673 "TARGET_64BIT && TARGET_MIPS16"
4674 {
4675 if (GET_CODE (operands[2]) == CONST_INT)
4676 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
4677
4678 return "dsra\t%0,%2";
4679 }
4680 [(set_attr "type" "shift")
4681 (set_attr "mode" "DI")
4682 (set_attr_alternative "length"
4683 [(const_int 4)
4684 (if_then_else (match_operand 2 "m16_uimm3_b")
4685 (const_int 4)
4686 (const_int 8))])])
4687
4688 (define_insn "*lshrdi3_mips16"
4689 [(set (match_operand:DI 0 "register_operand" "=d,d")
4690 (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
4691 (match_operand:SI 2 "arith_operand" "d,I")))]
4692 "TARGET_64BIT && TARGET_MIPS16"
4693 {
4694 if (GET_CODE (operands[2]) == CONST_INT)
4695 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
4696
4697 return "dsrl\t%0,%2";
4698 }
4699 [(set_attr "type" "shift")
4700 (set_attr "mode" "DI")
4701 (set_attr_alternative "length"
4702 [(const_int 4)
4703 (if_then_else (match_operand 2 "m16_uimm3_b")
4704 (const_int 4)
4705 (const_int 8))])])
4706
4707 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
4708
4709 (define_split
4710 [(set (match_operand:GPR 0 "register_operand")
4711 (any_shift:GPR (match_operand:GPR 1 "register_operand")
4712 (match_operand:GPR 2 "const_int_operand")))]
4713 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4714 && GET_CODE (operands[2]) == CONST_INT
4715 && INTVAL (operands[2]) > 8
4716 && INTVAL (operands[2]) <= 16"
4717 [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
4718 (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
4719 { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
4720
4721 ;; If we load a byte on the mips16 as a bitfield, the resulting
4722 ;; sequence of instructions is too complicated for combine, because it
4723 ;; involves four instructions: a load, a shift, a constant load into a
4724 ;; register, and an and (the key problem here is that the mips16 does
4725 ;; not have and immediate). We recognize a shift of a load in order
4726 ;; to make it simple enough for combine to understand.
4727 ;;
4728 ;; The length here is the worst case: the length of the split version
4729 ;; will be more accurate.
4730 (define_insn_and_split ""
4731 [(set (match_operand:SI 0 "register_operand" "=d")
4732 (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
4733 (match_operand:SI 2 "immediate_operand" "I")))]
4734 "TARGET_MIPS16"
4735 "#"
4736 ""
4737 [(set (match_dup 0) (match_dup 1))
4738 (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
4739 ""
4740 [(set_attr "type" "load")
4741 (set_attr "mode" "SI")
4742 (set_attr "length" "16")])
4743
4744 (define_insn "rotr<mode>3"
4745 [(set (match_operand:GPR 0 "register_operand" "=d")
4746 (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
4747 (match_operand:SI 2 "arith_operand" "dI")))]
4748 "ISA_HAS_ROR"
4749 {
4750 if (GET_CODE (operands[2]) == CONST_INT)
4751 gcc_assert (INTVAL (operands[2]) >= 0
4752 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
4753
4754 return "<d>ror\t%0,%1,%2";
4755 }
4756 [(set_attr "type" "shift")
4757 (set_attr "mode" "<MODE>")])
4758 \f
4759 ;;
4760 ;; ....................
4761 ;;
4762 ;; COMPARISONS
4763 ;;
4764 ;; ....................
4765
4766 ;; Flow here is rather complex:
4767 ;;
4768 ;; 1) The cmp{si,di,sf,df} routine is called. It deposits the arguments
4769 ;; into cmp_operands[] but generates no RTL.
4770 ;;
4771 ;; 2) The appropriate branch define_expand is called, which then
4772 ;; creates the appropriate RTL for the comparison and branch.
4773 ;; Different CC modes are used, based on what type of branch is
4774 ;; done, so that we can constrain things appropriately. There
4775 ;; are assumptions in the rest of GCC that break if we fold the
4776 ;; operands into the branches for integer operations, and use cc0
4777 ;; for floating point, so we use the fp status register instead.
4778 ;; If needed, an appropriate temporary is created to hold the
4779 ;; of the integer compare.
4780
4781 (define_expand "cmp<mode>"
4782 [(set (cc0)
4783 (compare:CC (match_operand:GPR 0 "register_operand")
4784 (match_operand:GPR 1 "nonmemory_operand")))]
4785 ""
4786 {
4787 cmp_operands[0] = operands[0];
4788 cmp_operands[1] = operands[1];
4789 DONE;
4790 })
4791
4792 (define_expand "cmp<mode>"
4793 [(set (cc0)
4794 (compare:CC (match_operand:SCALARF 0 "register_operand")
4795 (match_operand:SCALARF 1 "register_operand")))]
4796 ""
4797 {
4798 cmp_operands[0] = operands[0];
4799 cmp_operands[1] = operands[1];
4800 DONE;
4801 })
4802 \f
4803 ;;
4804 ;; ....................
4805 ;;
4806 ;; CONDITIONAL BRANCHES
4807 ;;
4808 ;; ....................
4809
4810 ;; Conditional branches on floating-point equality tests.
4811
4812 (define_insn "*branch_fp"
4813 [(set (pc)
4814 (if_then_else
4815 (match_operator 0 "equality_operator"
4816 [(match_operand:CC 2 "register_operand" "z")
4817 (const_int 0)])
4818 (label_ref (match_operand 1 "" ""))
4819 (pc)))]
4820 "TARGET_HARD_FLOAT"
4821 {
4822 return mips_output_conditional_branch (insn, operands,
4823 MIPS_BRANCH ("b%F0", "%Z2%1"),
4824 MIPS_BRANCH ("b%W0", "%Z2%1"));
4825 }
4826 [(set_attr "type" "branch")
4827 (set_attr "mode" "none")])
4828
4829 (define_insn "*branch_fp_inverted"
4830 [(set (pc)
4831 (if_then_else
4832 (match_operator 0 "equality_operator"
4833 [(match_operand:CC 2 "register_operand" "z")
4834 (const_int 0)])
4835 (pc)
4836 (label_ref (match_operand 1 "" ""))))]
4837 "TARGET_HARD_FLOAT"
4838 {
4839 return mips_output_conditional_branch (insn, operands,
4840 MIPS_BRANCH ("b%W0", "%Z2%1"),
4841 MIPS_BRANCH ("b%F0", "%Z2%1"));
4842 }
4843 [(set_attr "type" "branch")
4844 (set_attr "mode" "none")])
4845
4846 ;; Conditional branches on ordered comparisons with zero.
4847
4848 (define_insn "*branch_order<mode>"
4849 [(set (pc)
4850 (if_then_else
4851 (match_operator 0 "order_operator"
4852 [(match_operand:GPR 2 "register_operand" "d")
4853 (const_int 0)])
4854 (label_ref (match_operand 1 "" ""))
4855 (pc)))]
4856 "!TARGET_MIPS16"
4857 { return mips_output_order_conditional_branch (insn, operands, false); }
4858 [(set_attr "type" "branch")
4859 (set_attr "mode" "none")])
4860
4861 (define_insn "*branch_order<mode>_inverted"
4862 [(set (pc)
4863 (if_then_else
4864 (match_operator 0 "order_operator"
4865 [(match_operand:GPR 2 "register_operand" "d")
4866 (const_int 0)])
4867 (pc)
4868 (label_ref (match_operand 1 "" ""))))]
4869 "!TARGET_MIPS16"
4870 { return mips_output_order_conditional_branch (insn, operands, true); }
4871 [(set_attr "type" "branch")
4872 (set_attr "mode" "none")])
4873
4874 ;; Conditional branch on equality comparison.
4875
4876 (define_insn "*branch_equality<mode>"
4877 [(set (pc)
4878 (if_then_else
4879 (match_operator 0 "equality_operator"
4880 [(match_operand:GPR 2 "register_operand" "d")
4881 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
4882 (label_ref (match_operand 1 "" ""))
4883 (pc)))]
4884 "!TARGET_MIPS16"
4885 {
4886 return mips_output_conditional_branch (insn, operands,
4887 MIPS_BRANCH ("b%C0", "%2,%z3,%1"),
4888 MIPS_BRANCH ("b%N0", "%2,%z3,%1"));
4889 }
4890 [(set_attr "type" "branch")
4891 (set_attr "mode" "none")])
4892
4893 (define_insn "*branch_equality<mode>_inverted"
4894 [(set (pc)
4895 (if_then_else
4896 (match_operator 0 "equality_operator"
4897 [(match_operand:GPR 2 "register_operand" "d")
4898 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
4899 (pc)
4900 (label_ref (match_operand 1 "" ""))))]
4901 "!TARGET_MIPS16"
4902 {
4903 return mips_output_conditional_branch (insn, operands,
4904 MIPS_BRANCH ("b%N0", "%2,%z3,%1"),
4905 MIPS_BRANCH ("b%C0", "%2,%z3,%1"));
4906 }
4907 [(set_attr "type" "branch")
4908 (set_attr "mode" "none")])
4909
4910 ;; MIPS16 branches
4911
4912 (define_insn "*branch_equality<mode>_mips16"
4913 [(set (pc)
4914 (if_then_else
4915 (match_operator 0 "equality_operator"
4916 [(match_operand:GPR 1 "register_operand" "d,t")
4917 (const_int 0)])
4918 (match_operand 2 "pc_or_label_operand" "")
4919 (match_operand 3 "pc_or_label_operand" "")))]
4920 "TARGET_MIPS16"
4921 {
4922 if (operands[2] != pc_rtx)
4923 {
4924 if (which_alternative == 0)
4925 return "b%C0z\t%1,%2";
4926 else
4927 return "bt%C0z\t%2";
4928 }
4929 else
4930 {
4931 if (which_alternative == 0)
4932 return "b%N0z\t%1,%3";
4933 else
4934 return "bt%N0z\t%3";
4935 }
4936 }
4937 [(set_attr "type" "branch")
4938 (set_attr "mode" "none")
4939 (set_attr "length" "8")])
4940
4941 (define_expand "b<code>"
4942 [(set (pc)
4943 (if_then_else (any_cond:CC (cc0)
4944 (const_int 0))
4945 (label_ref (match_operand 0 ""))
4946 (pc)))]
4947 ""
4948 {
4949 gen_conditional_branch (operands, <CODE>);
4950 DONE;
4951 })
4952
4953 ;; Used to implement built-in functions.
4954 (define_expand "condjump"
4955 [(set (pc)
4956 (if_then_else (match_operand 0)
4957 (label_ref (match_operand 1))
4958 (pc)))])
4959 \f
4960 ;;
4961 ;; ....................
4962 ;;
4963 ;; SETTING A REGISTER FROM A COMPARISON
4964 ;;
4965 ;; ....................
4966
4967 (define_expand "seq"
4968 [(set (match_operand:SI 0 "register_operand")
4969 (eq:SI (match_dup 1)
4970 (match_dup 2)))]
4971 ""
4972 { if (mips_emit_scc (EQ, operands[0])) DONE; else FAIL; })
4973
4974 (define_insn "*seq_<mode>"
4975 [(set (match_operand:GPR 0 "register_operand" "=d")
4976 (eq:GPR (match_operand:GPR 1 "register_operand" "d")
4977 (const_int 0)))]
4978 "!TARGET_MIPS16"
4979 "sltu\t%0,%1,1"
4980 [(set_attr "type" "slt")
4981 (set_attr "mode" "<MODE>")])
4982
4983 (define_insn "*seq_<mode>_mips16"
4984 [(set (match_operand:GPR 0 "register_operand" "=t")
4985 (eq:GPR (match_operand:GPR 1 "register_operand" "d")
4986 (const_int 0)))]
4987 "TARGET_MIPS16"
4988 "sltu\t%1,1"
4989 [(set_attr "type" "slt")
4990 (set_attr "mode" "<MODE>")])
4991
4992 ;; "sne" uses sltu instructions in which the first operand is $0.
4993 ;; This isn't possible in mips16 code.
4994
4995 (define_expand "sne"
4996 [(set (match_operand:SI 0 "register_operand")
4997 (ne:SI (match_dup 1)
4998 (match_dup 2)))]
4999 "!TARGET_MIPS16"
5000 { if (mips_emit_scc (NE, operands[0])) DONE; else FAIL; })
5001
5002 (define_insn "*sne_<mode>"
5003 [(set (match_operand:GPR 0 "register_operand" "=d")
5004 (ne:GPR (match_operand:GPR 1 "register_operand" "d")
5005 (const_int 0)))]
5006 "!TARGET_MIPS16"
5007 "sltu\t%0,%.,%1"
5008 [(set_attr "type" "slt")
5009 (set_attr "mode" "<MODE>")])
5010
5011 (define_expand "sgt"
5012 [(set (match_operand:SI 0 "register_operand")
5013 (gt:SI (match_dup 1)
5014 (match_dup 2)))]
5015 ""
5016 { if (mips_emit_scc (GT, operands[0])) DONE; else FAIL; })
5017
5018 (define_insn "*sgt_<mode>"
5019 [(set (match_operand:GPR 0 "register_operand" "=d")
5020 (gt:GPR (match_operand:GPR 1 "register_operand" "d")
5021 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5022 "!TARGET_MIPS16"
5023 "slt\t%0,%z2,%1"
5024 [(set_attr "type" "slt")
5025 (set_attr "mode" "<MODE>")])
5026
5027 (define_insn "*sgt_<mode>_mips16"
5028 [(set (match_operand:GPR 0 "register_operand" "=t")
5029 (gt:GPR (match_operand:GPR 1 "register_operand" "d")
5030 (match_operand:GPR 2 "register_operand" "d")))]
5031 "TARGET_MIPS16"
5032 "slt\t%2,%1"
5033 [(set_attr "type" "slt")
5034 (set_attr "mode" "<MODE>")])
5035
5036 (define_expand "sge"
5037 [(set (match_operand:SI 0 "register_operand")
5038 (ge:SI (match_dup 1)
5039 (match_dup 2)))]
5040 ""
5041 { if (mips_emit_scc (GE, operands[0])) DONE; else FAIL; })
5042
5043 (define_insn "*sge_<mode>"
5044 [(set (match_operand:GPR 0 "register_operand" "=d")
5045 (ge:GPR (match_operand:GPR 1 "register_operand" "d")
5046 (const_int 1)))]
5047 "!TARGET_MIPS16"
5048 "slt\t%0,%.,%1"
5049 [(set_attr "type" "slt")
5050 (set_attr "mode" "<MODE>")])
5051
5052 (define_expand "slt"
5053 [(set (match_operand:SI 0 "register_operand")
5054 (lt:SI (match_dup 1)
5055 (match_dup 2)))]
5056 ""
5057 { if (mips_emit_scc (LT, operands[0])) DONE; else FAIL; })
5058
5059 (define_insn "*slt_<mode>"
5060 [(set (match_operand:GPR 0 "register_operand" "=d")
5061 (lt:GPR (match_operand:GPR 1 "register_operand" "d")
5062 (match_operand:GPR 2 "arith_operand" "dI")))]
5063 "!TARGET_MIPS16"
5064 "slt\t%0,%1,%2"
5065 [(set_attr "type" "slt")
5066 (set_attr "mode" "<MODE>")])
5067
5068 (define_insn "*slt_<mode>_mips16"
5069 [(set (match_operand:GPR 0 "register_operand" "=t,t")
5070 (lt:GPR (match_operand:GPR 1 "register_operand" "d,d")
5071 (match_operand:GPR 2 "arith_operand" "d,I")))]
5072 "TARGET_MIPS16"
5073 "slt\t%1,%2"
5074 [(set_attr "type" "slt")
5075 (set_attr "mode" "<MODE>")
5076 (set_attr_alternative "length"
5077 [(const_int 4)
5078 (if_then_else (match_operand 2 "m16_uimm8_1")
5079 (const_int 4)
5080 (const_int 8))])])
5081
5082 (define_expand "sle"
5083 [(set (match_operand:SI 0 "register_operand")
5084 (le:SI (match_dup 1)
5085 (match_dup 2)))]
5086 ""
5087 { if (mips_emit_scc (LE, operands[0])) DONE; else FAIL; })
5088
5089 (define_insn "*sle_<mode>"
5090 [(set (match_operand:GPR 0 "register_operand" "=d")
5091 (le:GPR (match_operand:GPR 1 "register_operand" "d")
5092 (match_operand:GPR 2 "sle_operand" "")))]
5093 "!TARGET_MIPS16"
5094 {
5095 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5096 return "slt\t%0,%1,%2";
5097 }
5098 [(set_attr "type" "slt")
5099 (set_attr "mode" "<MODE>")])
5100
5101 (define_insn "*sle_<mode>_mips16"
5102 [(set (match_operand:GPR 0 "register_operand" "=t")
5103 (le:GPR (match_operand:GPR 1 "register_operand" "d")
5104 (match_operand:GPR 2 "sle_operand" "")))]
5105 "TARGET_MIPS16"
5106 {
5107 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5108 return "slt\t%1,%2";
5109 }
5110 [(set_attr "type" "slt")
5111 (set_attr "mode" "<MODE>")
5112 (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
5113 (const_int 4)
5114 (const_int 8)))])
5115
5116 (define_expand "sgtu"
5117 [(set (match_operand:SI 0 "register_operand")
5118 (gtu:SI (match_dup 1)
5119 (match_dup 2)))]
5120 ""
5121 { if (mips_emit_scc (GTU, operands[0])) DONE; else FAIL; })
5122
5123 (define_insn "*sgtu_<mode>"
5124 [(set (match_operand:GPR 0 "register_operand" "=d")
5125 (gtu:GPR (match_operand:GPR 1 "register_operand" "d")
5126 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5127 "!TARGET_MIPS16"
5128 "sltu\t%0,%z2,%1"
5129 [(set_attr "type" "slt")
5130 (set_attr "mode" "<MODE>")])
5131
5132 (define_insn "*sgtu_<mode>_mips16"
5133 [(set (match_operand:GPR 0 "register_operand" "=t")
5134 (gtu:GPR (match_operand:GPR 1 "register_operand" "d")
5135 (match_operand:GPR 2 "register_operand" "d")))]
5136 "TARGET_MIPS16"
5137 "sltu\t%2,%1"
5138 [(set_attr "type" "slt")
5139 (set_attr "mode" "<MODE>")])
5140
5141 (define_expand "sgeu"
5142 [(set (match_operand:SI 0 "register_operand")
5143 (geu:SI (match_dup 1)
5144 (match_dup 2)))]
5145 ""
5146 { if (mips_emit_scc (GEU, operands[0])) DONE; else FAIL; })
5147
5148 (define_insn "*sge_<mode>"
5149 [(set (match_operand:GPR 0 "register_operand" "=d")
5150 (geu:GPR (match_operand:GPR 1 "register_operand" "d")
5151 (const_int 1)))]
5152 "!TARGET_MIPS16"
5153 "sltu\t%0,%.,%1"
5154 [(set_attr "type" "slt")
5155 (set_attr "mode" "<MODE>")])
5156
5157 (define_expand "sltu"
5158 [(set (match_operand:SI 0 "register_operand")
5159 (ltu:SI (match_dup 1)
5160 (match_dup 2)))]
5161 ""
5162 { if (mips_emit_scc (LTU, operands[0])) DONE; else FAIL; })
5163
5164 (define_insn "*sltu_<mode>"
5165 [(set (match_operand:GPR 0 "register_operand" "=d")
5166 (ltu:GPR (match_operand:GPR 1 "register_operand" "d")
5167 (match_operand:GPR 2 "arith_operand" "dI")))]
5168 "!TARGET_MIPS16"
5169 "sltu\t%0,%1,%2"
5170 [(set_attr "type" "slt")
5171 (set_attr "mode" "<MODE>")])
5172
5173 (define_insn "*sltu_<mode>_mips16"
5174 [(set (match_operand:GPR 0 "register_operand" "=t,t")
5175 (ltu:GPR (match_operand:GPR 1 "register_operand" "d,d")
5176 (match_operand:GPR 2 "arith_operand" "d,I")))]
5177 "TARGET_MIPS16"
5178 "sltu\t%1,%2"
5179 [(set_attr "type" "slt")
5180 (set_attr "mode" "<MODE>")
5181 (set_attr_alternative "length"
5182 [(const_int 4)
5183 (if_then_else (match_operand 2 "m16_uimm8_1")
5184 (const_int 4)
5185 (const_int 8))])])
5186
5187 (define_expand "sleu"
5188 [(set (match_operand:SI 0 "register_operand")
5189 (leu:SI (match_dup 1)
5190 (match_dup 2)))]
5191 ""
5192 { if (mips_emit_scc (LEU, operands[0])) DONE; else FAIL; })
5193
5194 (define_insn "*sleu_<mode>"
5195 [(set (match_operand:GPR 0 "register_operand" "=d")
5196 (leu:GPR (match_operand:GPR 1 "register_operand" "d")
5197 (match_operand:GPR 2 "sleu_operand" "")))]
5198 "!TARGET_MIPS16"
5199 {
5200 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5201 return "sltu\t%0,%1,%2";
5202 }
5203 [(set_attr "type" "slt")
5204 (set_attr "mode" "<MODE>")])
5205
5206 (define_insn "*sleu_<mode>_mips16"
5207 [(set (match_operand:GPR 0 "register_operand" "=t")
5208 (leu:GPR (match_operand:GPR 1 "register_operand" "d")
5209 (match_operand:GPR 2 "sleu_operand" "")))]
5210 "TARGET_MIPS16"
5211 {
5212 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5213 return "sltu\t%1,%2";
5214 }
5215 [(set_attr "type" "slt")
5216 (set_attr "mode" "<MODE>")
5217 (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
5218 (const_int 4)
5219 (const_int 8)))])
5220 \f
5221 ;;
5222 ;; ....................
5223 ;;
5224 ;; FLOATING POINT COMPARISONS
5225 ;;
5226 ;; ....................
5227
5228 (define_insn "s<code>_<mode>"
5229 [(set (match_operand:CC 0 "register_operand" "=z")
5230 (fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5231 (match_operand:SCALARF 2 "register_operand" "f")))]
5232 ""
5233 "c.<fcond>.<fmt>\t%Z0%1,%2"
5234 [(set_attr "type" "fcmp")
5235 (set_attr "mode" "FPSW")])
5236
5237 (define_insn "s<code>_<mode>"
5238 [(set (match_operand:CC 0 "register_operand" "=z")
5239 (swapped_fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5240 (match_operand:SCALARF 2 "register_operand" "f")))]
5241 ""
5242 "c.<swapped_fcond>.<fmt>\t%Z0%2,%1"
5243 [(set_attr "type" "fcmp")
5244 (set_attr "mode" "FPSW")])
5245 \f
5246 ;;
5247 ;; ....................
5248 ;;
5249 ;; UNCONDITIONAL BRANCHES
5250 ;;
5251 ;; ....................
5252
5253 ;; Unconditional branches.
5254
5255 (define_insn "jump"
5256 [(set (pc)
5257 (label_ref (match_operand 0 "" "")))]
5258 "!TARGET_MIPS16"
5259 {
5260 if (flag_pic)
5261 {
5262 if (get_attr_length (insn) <= 8)
5263 return "%*b\t%l0%/";
5264 else
5265 {
5266 output_asm_insn (mips_output_load_label (), operands);
5267 return "%*jr\t%@%/%]";
5268 }
5269 }
5270 else
5271 return "%*j\t%l0%/";
5272 }
5273 [(set_attr "type" "jump")
5274 (set_attr "mode" "none")
5275 (set (attr "length")
5276 ;; We can't use `j' when emitting PIC. Emit a branch if it's
5277 ;; in range, otherwise load the address of the branch target into
5278 ;; $at and then jump to it.
5279 (if_then_else
5280 (ior (eq (symbol_ref "flag_pic") (const_int 0))
5281 (lt (abs (minus (match_dup 0)
5282 (plus (pc) (const_int 4))))
5283 (const_int 131072)))
5284 (const_int 4) (const_int 16)))])
5285
5286 ;; We need a different insn for the mips16, because a mips16 branch
5287 ;; does not have a delay slot.
5288
5289 (define_insn ""
5290 [(set (pc)
5291 (label_ref (match_operand 0 "" "")))]
5292 "TARGET_MIPS16"
5293 "b\t%l0"
5294 [(set_attr "type" "branch")
5295 (set_attr "mode" "none")
5296 (set_attr "length" "8")])
5297
5298 (define_expand "indirect_jump"
5299 [(set (pc) (match_operand 0 "register_operand"))]
5300 ""
5301 {
5302 operands[0] = force_reg (Pmode, operands[0]);
5303 if (Pmode == SImode)
5304 emit_jump_insn (gen_indirect_jumpsi (operands[0]));
5305 else
5306 emit_jump_insn (gen_indirect_jumpdi (operands[0]));
5307 DONE;
5308 })
5309
5310 (define_insn "indirect_jump<mode>"
5311 [(set (pc) (match_operand:P 0 "register_operand" "d"))]
5312 ""
5313 "%*j\t%0%/"
5314 [(set_attr "type" "jump")
5315 (set_attr "mode" "none")])
5316
5317 (define_expand "tablejump"
5318 [(set (pc)
5319 (match_operand 0 "register_operand"))
5320 (use (label_ref (match_operand 1 "")))]
5321 ""
5322 {
5323 if (TARGET_MIPS16_SHORT_JUMP_TABLES)
5324 operands[0] = expand_binop (Pmode, add_optab,
5325 convert_to_mode (Pmode, operands[0], false),
5326 gen_rtx_LABEL_REF (Pmode, operands[1]),
5327 0, 0, OPTAB_WIDEN);
5328 else if (TARGET_GPWORD)
5329 operands[0] = expand_binop (Pmode, add_optab, operands[0],
5330 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
5331 else if (TARGET_RTP_PIC)
5332 {
5333 /* When generating RTP PIC, we use case table entries that are relative
5334 to the start of the function. Add the function's address to the
5335 value we loaded. */
5336 rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5337 operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
5338 start, 0, 0, OPTAB_WIDEN);
5339 }
5340
5341 if (Pmode == SImode)
5342 emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
5343 else
5344 emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
5345 DONE;
5346 })
5347
5348 (define_insn "tablejump<mode>"
5349 [(set (pc)
5350 (match_operand:P 0 "register_operand" "d"))
5351 (use (label_ref (match_operand 1 "" "")))]
5352 ""
5353 "%*j\t%0%/"
5354 [(set_attr "type" "jump")
5355 (set_attr "mode" "none")])
5356
5357 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
5358 ;; While it is possible to either pull it off the stack (in the
5359 ;; o32 case) or recalculate it given t9 and our target label,
5360 ;; it takes 3 or 4 insns to do so.
5361
5362 (define_expand "builtin_setjmp_setup"
5363 [(use (match_operand 0 "register_operand"))]
5364 "TARGET_USE_GOT"
5365 {
5366 rtx addr;
5367
5368 addr = plus_constant (operands[0], GET_MODE_SIZE (Pmode) * 3);
5369 mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
5370 DONE;
5371 })
5372
5373 ;; Restore the gp that we saved above. Despite the earlier comment, it seems
5374 ;; that older code did recalculate the gp from $25. Continue to jump through
5375 ;; $25 for compatibility (we lose nothing by doing so).
5376
5377 (define_expand "builtin_longjmp"
5378 [(use (match_operand 0 "register_operand"))]
5379 "TARGET_USE_GOT"
5380 {
5381 /* The elements of the buffer are, in order: */
5382 int W = GET_MODE_SIZE (Pmode);
5383 rtx fp = gen_rtx_MEM (Pmode, operands[0]);
5384 rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 1*W));
5385 rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 2*W));
5386 rtx gpv = gen_rtx_MEM (Pmode, plus_constant (operands[0], 3*W));
5387 rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5388 /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
5389 The target is bound to be using $28 as the global pointer
5390 but the current function might not be. */
5391 rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
5392
5393 /* This bit is similar to expand_builtin_longjmp except that it
5394 restores $gp as well. */
5395 mips_emit_move (hard_frame_pointer_rtx, fp);
5396 mips_emit_move (pv, lab);
5397 emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
5398 mips_emit_move (gp, gpv);
5399 emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
5400 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
5401 emit_insn (gen_rtx_USE (VOIDmode, gp));
5402 emit_indirect_jump (pv);
5403 DONE;
5404 })
5405 \f
5406 ;;
5407 ;; ....................
5408 ;;
5409 ;; Function prologue/epilogue
5410 ;;
5411 ;; ....................
5412 ;;
5413
5414 (define_expand "prologue"
5415 [(const_int 1)]
5416 ""
5417 {
5418 mips_expand_prologue ();
5419 DONE;
5420 })
5421
5422 ;; Block any insns from being moved before this point, since the
5423 ;; profiling call to mcount can use various registers that aren't
5424 ;; saved or used to pass arguments.
5425
5426 (define_insn "blockage"
5427 [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
5428 ""
5429 ""
5430 [(set_attr "type" "unknown")
5431 (set_attr "mode" "none")
5432 (set_attr "length" "0")])
5433
5434 (define_expand "epilogue"
5435 [(const_int 2)]
5436 ""
5437 {
5438 mips_expand_epilogue (false);
5439 DONE;
5440 })
5441
5442 (define_expand "sibcall_epilogue"
5443 [(const_int 2)]
5444 ""
5445 {
5446 mips_expand_epilogue (true);
5447 DONE;
5448 })
5449
5450 ;; Trivial return. Make it look like a normal return insn as that
5451 ;; allows jump optimizations to work better.
5452
5453 (define_insn "return"
5454 [(return)]
5455 "mips_can_use_return_insn ()"
5456 "%*j\t$31%/"
5457 [(set_attr "type" "jump")
5458 (set_attr "mode" "none")])
5459
5460 ;; Normal return.
5461
5462 (define_insn "return_internal"
5463 [(return)
5464 (use (match_operand 0 "pmode_register_operand" ""))]
5465 ""
5466 "%*j\t%0%/"
5467 [(set_attr "type" "jump")
5468 (set_attr "mode" "none")])
5469
5470 ;; This is used in compiling the unwind routines.
5471 (define_expand "eh_return"
5472 [(use (match_operand 0 "general_operand"))]
5473 ""
5474 {
5475 enum machine_mode gpr_mode = TARGET_64BIT ? DImode : SImode;
5476
5477 if (GET_MODE (operands[0]) != gpr_mode)
5478 operands[0] = convert_to_mode (gpr_mode, operands[0], 0);
5479 if (TARGET_64BIT)
5480 emit_insn (gen_eh_set_lr_di (operands[0]));
5481 else
5482 emit_insn (gen_eh_set_lr_si (operands[0]));
5483
5484 DONE;
5485 })
5486
5487 ;; Clobber the return address on the stack. We can't expand this
5488 ;; until we know where it will be put in the stack frame.
5489
5490 (define_insn "eh_set_lr_si"
5491 [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
5492 (clobber (match_scratch:SI 1 "=&d"))]
5493 "! TARGET_64BIT"
5494 "#")
5495
5496 (define_insn "eh_set_lr_di"
5497 [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
5498 (clobber (match_scratch:DI 1 "=&d"))]
5499 "TARGET_64BIT"
5500 "#")
5501
5502 (define_split
5503 [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
5504 (clobber (match_scratch 1))]
5505 "reload_completed && !TARGET_DEBUG_D_MODE"
5506 [(const_int 0)]
5507 {
5508 mips_set_return_address (operands[0], operands[1]);
5509 DONE;
5510 })
5511
5512 (define_insn_and_split "nonlocal_goto_receiver"
5513 [(set (reg:SI 28)
5514 (unspec_volatile:SI [(const_int 0)] UNSPEC_NONLOCAL_GOTO_RECEIVER))]
5515 "TARGET_CALL_CLOBBERED_GP"
5516 "#"
5517 "&& reload_completed"
5518 [(const_int 0)]
5519 {
5520 mips_restore_gp ();
5521 DONE;
5522 }
5523 [(set_attr "type" "load")
5524 (set_attr "length" "12")])
5525 \f
5526 ;;
5527 ;; ....................
5528 ;;
5529 ;; FUNCTION CALLS
5530 ;;
5531 ;; ....................
5532
5533 ;; Instructions to load a call address from the GOT. The address might
5534 ;; point to a function or to a lazy binding stub. In the latter case,
5535 ;; the stub will use the dynamic linker to resolve the function, which
5536 ;; in turn will change the GOT entry to point to the function's real
5537 ;; address.
5538 ;;
5539 ;; This means that every call, even pure and constant ones, can
5540 ;; potentially modify the GOT entry. And once a stub has been called,
5541 ;; we must not call it again.
5542 ;;
5543 ;; We represent this restriction using an imaginary fixed register that
5544 ;; acts like a GOT version number. By making the register call-clobbered,
5545 ;; we tell the target-independent code that the address could be changed
5546 ;; by any call insn.
5547 (define_insn "load_call<mode>"
5548 [(set (match_operand:P 0 "register_operand" "=d")
5549 (unspec:P [(match_operand:P 1 "register_operand" "r")
5550 (match_operand:P 2 "immediate_operand" "")
5551 (reg:P FAKE_CALL_REGNO)]
5552 UNSPEC_LOAD_CALL))]
5553 "TARGET_USE_GOT"
5554 "<load>\t%0,%R2(%1)"
5555 [(set_attr "type" "load")
5556 (set_attr "mode" "<MODE>")
5557 (set_attr "length" "4")])
5558
5559 ;; Sibling calls. All these patterns use jump instructions.
5560
5561 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
5562 ;; addresses if a direct jump is acceptable. Since the 'S' constraint
5563 ;; is defined in terms of call_insn_operand, the same is true of the
5564 ;; constraints.
5565
5566 ;; When we use an indirect jump, we need a register that will be
5567 ;; preserved by the epilogue. Since TARGET_USE_PIC_FN_ADDR_REG forces
5568 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
5569 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
5570 ;; as well.
5571
5572 (define_expand "sibcall"
5573 [(parallel [(call (match_operand 0 "")
5574 (match_operand 1 ""))
5575 (use (match_operand 2 "")) ;; next_arg_reg
5576 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
5577 "TARGET_SIBCALLS"
5578 {
5579 mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], true);
5580 DONE;
5581 })
5582
5583 (define_insn "sibcall_internal"
5584 [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
5585 (match_operand 1 "" ""))]
5586 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
5587 { return MIPS_CALL ("j", operands, 0); }
5588 [(set_attr "type" "call")])
5589
5590 (define_expand "sibcall_value"
5591 [(parallel [(set (match_operand 0 "")
5592 (call (match_operand 1 "")
5593 (match_operand 2 "")))
5594 (use (match_operand 3 ""))])] ;; next_arg_reg
5595 "TARGET_SIBCALLS"
5596 {
5597 mips_expand_call (operands[0], XEXP (operands[1], 0),
5598 operands[2], operands[3], true);
5599 DONE;
5600 })
5601
5602 (define_insn "sibcall_value_internal"
5603 [(set (match_operand 0 "register_operand" "")
5604 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
5605 (match_operand 2 "" "")))]
5606 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
5607 { return MIPS_CALL ("j", operands, 1); }
5608 [(set_attr "type" "call")])
5609
5610 (define_insn "sibcall_value_multiple_internal"
5611 [(set (match_operand 0 "register_operand" "")
5612 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
5613 (match_operand 2 "" "")))
5614 (set (match_operand 3 "register_operand" "")
5615 (call (mem:SI (match_dup 1))
5616 (match_dup 2)))]
5617 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
5618 { return MIPS_CALL ("j", operands, 1); }
5619 [(set_attr "type" "call")])
5620
5621 (define_expand "call"
5622 [(parallel [(call (match_operand 0 "")
5623 (match_operand 1 ""))
5624 (use (match_operand 2 "")) ;; next_arg_reg
5625 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
5626 ""
5627 {
5628 mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], false);
5629 DONE;
5630 })
5631
5632 ;; This instruction directly corresponds to an assembly-language "jal".
5633 ;; There are four cases:
5634 ;;
5635 ;; - -mno-abicalls:
5636 ;; Both symbolic and register destinations are OK. The pattern
5637 ;; always expands to a single mips instruction.
5638 ;;
5639 ;; - -mabicalls/-mno-explicit-relocs:
5640 ;; Again, both symbolic and register destinations are OK.
5641 ;; The call is treated as a multi-instruction black box.
5642 ;;
5643 ;; - -mabicalls/-mexplicit-relocs with n32 or n64:
5644 ;; Only "jal $25" is allowed. This expands to a single "jalr $25"
5645 ;; instruction.
5646 ;;
5647 ;; - -mabicalls/-mexplicit-relocs with o32 or o64:
5648 ;; Only "jal $25" is allowed. The call is actually two instructions:
5649 ;; "jalr $25" followed by an insn to reload $gp.
5650 ;;
5651 ;; In the last case, we can generate the individual instructions with
5652 ;; a define_split. There are several things to be wary of:
5653 ;;
5654 ;; - We can't expose the load of $gp before reload. If we did,
5655 ;; it might get removed as dead, but reload can introduce new
5656 ;; uses of $gp by rematerializing constants.
5657 ;;
5658 ;; - We shouldn't restore $gp after calls that never return.
5659 ;; It isn't valid to insert instructions between a noreturn
5660 ;; call and the following barrier.
5661 ;;
5662 ;; - The splitter deliberately changes the liveness of $gp. The unsplit
5663 ;; instruction preserves $gp and so have no effect on its liveness.
5664 ;; But once we generate the separate insns, it becomes obvious that
5665 ;; $gp is not live on entry to the call.
5666 ;;
5667 ;; ??? The operands[2] = insn check is a hack to make the original insn
5668 ;; available to the splitter.
5669 (define_insn_and_split "call_internal"
5670 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
5671 (match_operand 1 "" ""))
5672 (clobber (reg:SI 31))]
5673 ""
5674 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0); }
5675 "reload_completed && TARGET_SPLIT_CALLS && (operands[2] = insn)"
5676 [(const_int 0)]
5677 {
5678 emit_call_insn (gen_call_split (operands[0], operands[1]));
5679 if (!find_reg_note (operands[2], REG_NORETURN, 0))
5680 mips_restore_gp ();
5681 DONE;
5682 }
5683 [(set_attr "jal" "indirect,direct")
5684 (set_attr "extended_mips16" "no,yes")])
5685
5686 ;; A pattern for calls that must be made directly. It is used for
5687 ;; MIPS16 calls that the linker may need to redirect to a hard-float
5688 ;; stub; the linker relies on the call relocation type to detect when
5689 ;; such redirection is needed.
5690 (define_insn "call_internal_direct"
5691 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
5692 (match_operand 1))
5693 (const_int 1)
5694 (clobber (reg:SI 31))]
5695 ""
5696 { return MIPS_CALL ("jal", operands, 0); })
5697
5698 (define_insn "call_split"
5699 [(call (mem:SI (match_operand 0 "call_insn_operand" "cS"))
5700 (match_operand 1 "" ""))
5701 (clobber (reg:SI 31))
5702 (clobber (reg:SI 28))]
5703 "TARGET_SPLIT_CALLS"
5704 { return MIPS_CALL ("jal", operands, 0); }
5705 [(set_attr "type" "call")])
5706
5707 (define_expand "call_value"
5708 [(parallel [(set (match_operand 0 "")
5709 (call (match_operand 1 "")
5710 (match_operand 2 "")))
5711 (use (match_operand 3 ""))])] ;; next_arg_reg
5712 ""
5713 {
5714 mips_expand_call (operands[0], XEXP (operands[1], 0),
5715 operands[2], operands[3], false);
5716 DONE;
5717 })
5718
5719 ;; See comment for call_internal.
5720 (define_insn_and_split "call_value_internal"
5721 [(set (match_operand 0 "register_operand" "")
5722 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
5723 (match_operand 2 "" "")))
5724 (clobber (reg:SI 31))]
5725 ""
5726 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1); }
5727 "reload_completed && TARGET_SPLIT_CALLS && (operands[3] = insn)"
5728 [(const_int 0)]
5729 {
5730 emit_call_insn (gen_call_value_split (operands[0], operands[1],
5731 operands[2]));
5732 if (!find_reg_note (operands[3], REG_NORETURN, 0))
5733 mips_restore_gp ();
5734 DONE;
5735 }
5736 [(set_attr "jal" "indirect,direct")
5737 (set_attr "extended_mips16" "no,yes")])
5738
5739 (define_insn "call_value_split"
5740 [(set (match_operand 0 "register_operand" "")
5741 (call (mem:SI (match_operand 1 "call_insn_operand" "cS"))
5742 (match_operand 2 "" "")))
5743 (clobber (reg:SI 31))
5744 (clobber (reg:SI 28))]
5745 "TARGET_SPLIT_CALLS"
5746 { return MIPS_CALL ("jal", operands, 1); }
5747 [(set_attr "type" "call")])
5748
5749 ;; See call_internal_direct.
5750 (define_insn "call_value_internal_direct"
5751 [(set (match_operand 0 "register_operand")
5752 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
5753 (match_operand 2)))
5754 (const_int 1)
5755 (clobber (reg:SI 31))]
5756 ""
5757 { return MIPS_CALL ("jal", operands, 1); })
5758
5759 ;; See comment for call_internal.
5760 (define_insn_and_split "call_value_multiple_internal"
5761 [(set (match_operand 0 "register_operand" "")
5762 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
5763 (match_operand 2 "" "")))
5764 (set (match_operand 3 "register_operand" "")
5765 (call (mem:SI (match_dup 1))
5766 (match_dup 2)))
5767 (clobber (reg:SI 31))]
5768 ""
5769 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1); }
5770 "reload_completed && TARGET_SPLIT_CALLS && (operands[4] = insn)"
5771 [(const_int 0)]
5772 {
5773 emit_call_insn (gen_call_value_multiple_split (operands[0], operands[1],
5774 operands[2], operands[3]));
5775 if (!find_reg_note (operands[4], REG_NORETURN, 0))
5776 mips_restore_gp ();
5777 DONE;
5778 }
5779 [(set_attr "jal" "indirect,direct")
5780 (set_attr "extended_mips16" "no,yes")])
5781
5782 (define_insn "call_value_multiple_split"
5783 [(set (match_operand 0 "register_operand" "")
5784 (call (mem:SI (match_operand 1 "call_insn_operand" "cS"))
5785 (match_operand 2 "" "")))
5786 (set (match_operand 3 "register_operand" "")
5787 (call (mem:SI (match_dup 1))
5788 (match_dup 2)))
5789 (clobber (reg:SI 31))
5790 (clobber (reg:SI 28))]
5791 "TARGET_SPLIT_CALLS"
5792 { return MIPS_CALL ("jal", operands, 1); }
5793 [(set_attr "type" "call")])
5794
5795 ;; Call subroutine returning any type.
5796
5797 (define_expand "untyped_call"
5798 [(parallel [(call (match_operand 0 "")
5799 (const_int 0))
5800 (match_operand 1 "")
5801 (match_operand 2 "")])]
5802 ""
5803 {
5804 int i;
5805
5806 emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
5807
5808 for (i = 0; i < XVECLEN (operands[2], 0); i++)
5809 {
5810 rtx set = XVECEXP (operands[2], 0, i);
5811 mips_emit_move (SET_DEST (set), SET_SRC (set));
5812 }
5813
5814 emit_insn (gen_blockage ());
5815 DONE;
5816 })
5817 \f
5818 ;;
5819 ;; ....................
5820 ;;
5821 ;; MISC.
5822 ;;
5823 ;; ....................
5824 ;;
5825
5826
5827 (define_insn "prefetch"
5828 [(prefetch (match_operand:QI 0 "address_operand" "p")
5829 (match_operand 1 "const_int_operand" "n")
5830 (match_operand 2 "const_int_operand" "n"))]
5831 "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
5832 {
5833 operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
5834 return "pref\t%1,%a0";
5835 }
5836 [(set_attr "type" "prefetch")])
5837
5838 (define_insn "*prefetch_indexed_<mode>"
5839 [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
5840 (match_operand:P 1 "register_operand" "d"))
5841 (match_operand 2 "const_int_operand" "n")
5842 (match_operand 3 "const_int_operand" "n"))]
5843 "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
5844 {
5845 operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
5846 return "prefx\t%2,%1(%0)";
5847 }
5848 [(set_attr "type" "prefetchx")])
5849
5850 (define_insn "nop"
5851 [(const_int 0)]
5852 ""
5853 "%(nop%)"
5854 [(set_attr "type" "nop")
5855 (set_attr "mode" "none")])
5856
5857 ;; Like nop, but commented out when outside a .set noreorder block.
5858 (define_insn "hazard_nop"
5859 [(const_int 1)]
5860 ""
5861 {
5862 if (set_noreorder)
5863 return "nop";
5864 else
5865 return "#nop";
5866 }
5867 [(set_attr "type" "nop")])
5868 \f
5869 ;; MIPS4 Conditional move instructions.
5870
5871 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
5872 [(set (match_operand:GPR 0 "register_operand" "=d,d")
5873 (if_then_else:GPR
5874 (match_operator:MOVECC 4 "equality_operator"
5875 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
5876 (const_int 0)])
5877 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
5878 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
5879 "ISA_HAS_CONDMOVE"
5880 "@
5881 mov%T4\t%0,%z2,%1
5882 mov%t4\t%0,%z3,%1"
5883 [(set_attr "type" "condmove")
5884 (set_attr "mode" "<GPR:MODE>")])
5885
5886 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
5887 [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
5888 (if_then_else:SCALARF
5889 (match_operator:MOVECC 4 "equality_operator"
5890 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
5891 (const_int 0)])
5892 (match_operand:SCALARF 2 "register_operand" "f,0")
5893 (match_operand:SCALARF 3 "register_operand" "0,f")))]
5894 "ISA_HAS_CONDMOVE"
5895 "@
5896 mov%T4.<fmt>\t%0,%2,%1
5897 mov%t4.<fmt>\t%0,%3,%1"
5898 [(set_attr "type" "condmove")
5899 (set_attr "mode" "<SCALARF:MODE>")])
5900
5901 ;; These are the main define_expand's used to make conditional moves.
5902
5903 (define_expand "mov<mode>cc"
5904 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
5905 (set (match_operand:GPR 0 "register_operand")
5906 (if_then_else:GPR (match_dup 5)
5907 (match_operand:GPR 2 "reg_or_0_operand")
5908 (match_operand:GPR 3 "reg_or_0_operand")))]
5909 "ISA_HAS_CONDMOVE"
5910 {
5911 gen_conditional_move (operands);
5912 DONE;
5913 })
5914
5915 (define_expand "mov<mode>cc"
5916 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
5917 (set (match_operand:SCALARF 0 "register_operand")
5918 (if_then_else:SCALARF (match_dup 5)
5919 (match_operand:SCALARF 2 "register_operand")
5920 (match_operand:SCALARF 3 "register_operand")))]
5921 "ISA_HAS_CONDMOVE"
5922 {
5923 gen_conditional_move (operands);
5924 DONE;
5925 })
5926 \f
5927 ;;
5928 ;; ....................
5929 ;;
5930 ;; mips16 inline constant tables
5931 ;;
5932 ;; ....................
5933 ;;
5934
5935 (define_insn "consttable_int"
5936 [(unspec_volatile [(match_operand 0 "consttable_operand" "")
5937 (match_operand 1 "const_int_operand" "")]
5938 UNSPEC_CONSTTABLE_INT)]
5939 "TARGET_MIPS16"
5940 {
5941 assemble_integer (operands[0], INTVAL (operands[1]),
5942 BITS_PER_UNIT * INTVAL (operands[1]), 1);
5943 return "";
5944 }
5945 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
5946
5947 (define_insn "consttable_float"
5948 [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
5949 UNSPEC_CONSTTABLE_FLOAT)]
5950 "TARGET_MIPS16"
5951 {
5952 REAL_VALUE_TYPE d;
5953
5954 gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
5955 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
5956 assemble_real (d, GET_MODE (operands[0]),
5957 GET_MODE_BITSIZE (GET_MODE (operands[0])));
5958 return "";
5959 }
5960 [(set (attr "length")
5961 (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
5962
5963 (define_insn "align"
5964 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
5965 ""
5966 ".align\t%0"
5967 [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
5968 \f
5969 (define_split
5970 [(match_operand 0 "small_data_pattern")]
5971 "reload_completed"
5972 [(match_dup 0)]
5973 { operands[0] = mips_rewrite_small_data (operands[0]); })
5974
5975 ;;
5976 ;; ....................
5977 ;;
5978 ;; MIPS16e Save/Restore
5979 ;;
5980 ;; ....................
5981 ;;
5982
5983 (define_insn "*mips16e_save_restore"
5984 [(match_parallel 0 ""
5985 [(set (match_operand:SI 1 "register_operand")
5986 (plus:SI (match_dup 1)
5987 (match_operand:SI 2 "const_int_operand")))])]
5988 "operands[1] == stack_pointer_rtx
5989 && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
5990 { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
5991 [(set_attr "type" "arith")
5992 (set_attr "extended_mips16" "yes")])
5993
5994 ; Thread-Local Storage
5995
5996 ; The TLS base pointer is accessed via "rdhwr $v1, $29". No current
5997 ; MIPS architecture defines this register, and no current
5998 ; implementation provides it; instead, any OS which supports TLS is
5999 ; expected to trap and emulate this instruction. rdhwr is part of the
6000 ; MIPS 32r2 specification, but we use it on any architecture because
6001 ; we expect it to be emulated. Use .set to force the assembler to
6002 ; accept it.
6003
6004 (define_insn "tls_get_tp_<mode>"
6005 [(set (match_operand:P 0 "register_operand" "=v")
6006 (unspec:P [(const_int 0)]
6007 UNSPEC_TLS_GET_TP))]
6008 "HAVE_AS_TLS && !TARGET_MIPS16"
6009 ".set\tpush\;.set\tmips32r2\t\;rdhwr\t%0,$29\;.set\tpop"
6010 [(set_attr "type" "unknown")
6011 ; Since rdhwr always generates a trap for now, putting it in a delay
6012 ; slot would make the kernel's emulation of it much slower.
6013 (set_attr "can_delay" "no")
6014 (set_attr "mode" "<MODE>")])
6015 \f
6016 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
6017
6018 (include "mips-ps-3d.md")
6019
6020 ; The MIPS DSP Instructions.
6021
6022 (include "mips-dsp.md")
6023
6024 ; The MIPS DSP REV 2 Instructions.
6025
6026 (include "mips-dspr2.md")
6027
6028 ; MIPS fixed-point instructions.
6029 (include "mips-fixed.md")