]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/mips/mips.md
Update copyright years.
[thirdparty/gcc.git] / gcc / config / mips / mips.md
1 ;; Mips.md Machine Description for MIPS based processors
2 ;; Copyright (C) 1989-2022 Free Software Foundation, Inc.
3 ;; Contributed by A. Lichnewsky, lich@inria.inria.fr
4 ;; Changes by Michael Meissner, meissner@osf.org
5 ;; 64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
6 ;; Brendan Eich, brendan@microunity.com.
7
8 ;; This file is part of GCC.
9
10 ;; GCC is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; any later version.
14
15 ;; GCC is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GCC; see the file COPYING3. If not see
22 ;; <http://www.gnu.org/licenses/>.
23
24 (define_enum "processor" [
25 r3000
26 4kc
27 4kp
28 5kc
29 5kf
30 20kc
31 24kc
32 24kf2_1
33 24kf1_1
34 74kc
35 74kf2_1
36 74kf1_1
37 74kf3_2
38 loongson_2e
39 loongson_2f
40 gs464
41 gs464e
42 gs264e
43 m4k
44 octeon
45 octeon2
46 octeon3
47 r3900
48 r6000
49 r4000
50 r4100
51 r4111
52 r4120
53 r4130
54 r4300
55 r4600
56 r4650
57 r4700
58 r5000
59 r5400
60 r5500
61 r5900
62 r7000
63 r8000
64 r9000
65 r10000
66 sb1
67 sb1a
68 sr71000
69 xlr
70 xlp
71 p5600
72 m5100
73 i6400
74 p6600
75 ])
76
77 (define_c_enum "unspec" [
78 ;; Unaligned accesses.
79 UNSPEC_LOAD_LEFT
80 UNSPEC_LOAD_RIGHT
81 UNSPEC_STORE_LEFT
82 UNSPEC_STORE_RIGHT
83
84 ;; Integer operations that are too cumbersome to describe directly.
85 UNSPEC_WSBH
86 UNSPEC_DSBH
87 UNSPEC_DSHD
88
89 ;; Floating-point moves.
90 UNSPEC_LOAD_LOW
91 UNSPEC_LOAD_HIGH
92 UNSPEC_STORE_WORD
93 UNSPEC_MFHC1
94 UNSPEC_MTHC1
95
96 ;; Floating-point environment.
97 UNSPEC_GET_FCSR
98 UNSPEC_SET_FCSR
99
100 ;; HI/LO moves.
101 UNSPEC_MFHI
102 UNSPEC_MTHI
103 UNSPEC_SET_HILO
104
105 ;; GP manipulation.
106 UNSPEC_LOADGP
107 UNSPEC_COPYGP
108 UNSPEC_MOVE_GP
109 UNSPEC_POTENTIAL_CPRESTORE
110 UNSPEC_CPRESTORE
111 UNSPEC_RESTORE_GP
112 UNSPEC_EH_RETURN
113 UNSPEC_GP
114 UNSPEC_SET_GOT_VERSION
115 UNSPEC_UPDATE_GOT_VERSION
116
117 ;; Symbolic accesses.
118 UNSPEC_LOAD_CALL
119 UNSPEC_LOAD_GOT
120 UNSPEC_TLS_LDM
121 UNSPEC_TLS_GET_TP
122 UNSPEC_UNSHIFTED_HIGH
123
124 ;; MIPS16 constant pools.
125 UNSPEC_ALIGN
126 UNSPEC_CONSTTABLE
127 UNSPEC_CONSTTABLE_END
128 UNSPEC_CONSTTABLE_INT
129 UNSPEC_CONSTTABLE_FLOAT
130
131 ;; Blockage and synchronisation.
132 UNSPEC_BLOCKAGE
133 UNSPEC_CLEAR_HAZARD
134 UNSPEC_RDHWR
135 UNSPEC_SYNCI
136 UNSPEC_SYNC
137
138 ;; Cache manipulation.
139 UNSPEC_MIPS_CACHE
140 UNSPEC_R10K_CACHE_BARRIER
141
142 ;; Interrupt handling.
143 UNSPEC_ERET
144 UNSPEC_DERET
145 UNSPEC_DI
146 UNSPEC_EHB
147 UNSPEC_RDPGPR
148 UNSPEC_COP0
149
150 ;; Used in a call expression in place of args_size. It's present for PIC
151 ;; indirect calls where it contains args_size and the function symbol.
152 UNSPEC_CALL_ATTR
153
154 ;; MIPS16 casesi jump table dispatch.
155 UNSPEC_CASESI_DISPATCH
156
157 ;; Stack checking.
158 UNSPEC_PROBE_STACK_RANGE
159
160 ;; The `.insn' pseudo-op.
161 UNSPEC_INSN_PSEUDO
162 ])
163
164 (define_constants
165 [(TLS_GET_TP_REGNUM 3)
166 (GET_FCSR_REGNUM 2)
167 (SET_FCSR_REGNUM 4)
168 (PIC_FUNCTION_ADDR_REGNUM 25)
169 (RETURN_ADDR_REGNUM 31)
170 (CPRESTORE_SLOT_REGNUM 76)
171 (GOT_VERSION_REGNUM 79)
172
173 ;; PIC long branch sequences are never longer than 100 bytes.
174 (MAX_PIC_BRANCH_LENGTH 100)
175 ]
176 )
177
178 (include "predicates.md")
179 (include "constraints.md")
180 \f
181 ;; ....................
182 ;;
183 ;; Attributes
184 ;;
185 ;; ....................
186
187 (define_attr "got" "unset,xgot_high,load"
188 (const_string "unset"))
189
190 ;; For jal instructions, this attribute is DIRECT when the target address
191 ;; is symbolic and INDIRECT when it is a register.
192 (define_attr "jal" "unset,direct,indirect"
193 (const_string "unset"))
194
195 ;; This attribute is YES if the instruction is a jal macro (not a
196 ;; real jal instruction).
197 ;;
198 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
199 ;; an instruction to restore $gp. Direct jals are also macros for
200 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
201 ;; into a register.
202 (define_attr "jal_macro" "no,yes"
203 (cond [(eq_attr "jal" "direct")
204 (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
205 ? JAL_MACRO_YES : JAL_MACRO_NO)")
206 (eq_attr "jal" "indirect")
207 (symbol_ref "(TARGET_CALL_CLOBBERED_GP
208 ? JAL_MACRO_YES : JAL_MACRO_NO)")]
209 (const_string "no")))
210
211 ;; Classification of moves, extensions and truncations. Most values
212 ;; are as for "type" (see below) but there are also the following
213 ;; move-specific values:
214 ;;
215 ;; constN move an N-constraint integer into a MIPS16 register
216 ;; sll0 "sll DEST,SRC,0", which on 64-bit targets is guaranteed
217 ;; to produce a sign-extended DEST, even if SRC is not
218 ;; properly sign-extended
219 ;; ext_ins EXT, DEXT, INS or DINS instruction
220 ;; andi a single ANDI instruction
221 ;; loadpool move a constant into a MIPS16 register by loading it
222 ;; from the pool
223 ;; shift_shift a shift left followed by a shift right
224 ;;
225 ;; This attribute is used to determine the instruction's length and
226 ;; scheduling type. For doubleword moves, the attribute always describes
227 ;; the split instructions; in some cases, it is more appropriate for the
228 ;; scheduling type to be "multi" instead.
229 (define_attr "move_type"
230 "unknown,load,fpload,store,fpstore,mtc,mfc,mtlo,mflo,imul,move,fmove,
231 const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
232 shift_shift"
233 (const_string "unknown"))
234
235 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor,simd_add"
236 (const_string "unknown"))
237
238 ;; Main data type used by the insn
239 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW,
240 V2DI,V4SI,V8HI,V16QI,V2DF,V4SF"
241 (const_string "unknown"))
242
243 ;; True if the main data type is twice the size of a word.
244 (define_attr "dword_mode" "no,yes"
245 (cond [(and (eq_attr "mode" "DI,DF")
246 (not (match_test "TARGET_64BIT")))
247 (const_string "yes")
248
249 (and (eq_attr "mode" "TI,TF")
250 (match_test "TARGET_64BIT"))
251 (const_string "yes")]
252 (const_string "no")))
253
254 ;; True if the main data type is four times of the size of a word.
255 (define_attr "qword_mode" "no,yes"
256 (cond [(and (eq_attr "mode" "TI,TF")
257 (not (match_test "TARGET_64BIT")))
258 (const_string "yes")]
259 (const_string "no")))
260
261 ;; Attributes describing a sync loop. These loops have the form:
262 ;;
263 ;; if (RELEASE_BARRIER == YES) sync
264 ;; 1: OLDVAL = *MEM
265 ;; if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
266 ;; CMP = 0 [delay slot]
267 ;; $TMP1 = OLDVAL & EXCLUSIVE_MASK
268 ;; $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
269 ;; $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
270 ;; $AT |= $TMP1 | $TMP3
271 ;; if (!commit (*MEM = $AT)) goto 1.
272 ;; if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
273 ;; CMP = 1
274 ;; if (ACQUIRE_BARRIER == YES) sync
275 ;; 2:
276 ;;
277 ;; where "$" values are temporaries and where the other values are
278 ;; specified by the attributes below. Values are specified as operand
279 ;; numbers and insns are specified as enums. If no operand number is
280 ;; specified, the following values are used instead:
281 ;;
282 ;; - OLDVAL: $AT
283 ;; - CMP: NONE
284 ;; - NEWVAL: $AT
285 ;; - INCLUSIVE_MASK: -1
286 ;; - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
287 ;; - EXCLUSIVE_MASK: 0
288 ;;
289 ;; MEM and INSN1_OP2 are required.
290 ;;
291 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
292 ;; but the gen* programs don't yet support that.
293 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
294 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
295 (define_attr "sync_cmp" "none,0,1,2,3,4,5" (const_string "none"))
296 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
297 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
298 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
299 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
300 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
301 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
302 (const_string "move"))
303 (define_attr "sync_insn2" "nop,and,xor,not"
304 (const_string "nop"))
305 ;; Memory model specifier.
306 ;; "0"-"9" values specify the operand that stores the memory model value.
307 ;; "10" specifies MEMMODEL_ACQ_REL,
308 ;; "11" specifies MEMMODEL_ACQUIRE.
309 (define_attr "sync_memmodel" "" (const_int 10))
310
311 ;; Accumulator operand for madd patterns.
312 (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))
313
314 ;; Classification of each insn.
315 ;; branch conditional branch
316 ;; jump unconditional jump
317 ;; call unconditional call
318 ;; load load instruction(s)
319 ;; fpload floating point load
320 ;; fpidxload floating point indexed load
321 ;; store store instruction(s)
322 ;; fpstore floating point store
323 ;; fpidxstore floating point indexed store
324 ;; prefetch memory prefetch (register + offset)
325 ;; prefetchx memory indexed prefetch (register + register)
326 ;; condmove conditional moves
327 ;; mtc transfer to coprocessor
328 ;; mfc transfer from coprocessor
329 ;; mthi transfer to a hi register
330 ;; mtlo transfer to a lo register
331 ;; mfhi transfer from a hi register
332 ;; mflo transfer from a lo register
333 ;; const load constant
334 ;; arith integer arithmetic instructions
335 ;; logical integer logical instructions
336 ;; shift integer shift instructions
337 ;; slt set less than instructions
338 ;; signext sign extend instructions
339 ;; clz the clz and clo instructions
340 ;; pop the pop instruction
341 ;; trap trap if instructions
342 ;; imul integer multiply 2 operands
343 ;; imul3 integer multiply 3 operands
344 ;; imul3nc integer multiply 3 operands without clobbering HI/LO
345 ;; imadd integer multiply-add
346 ;; idiv integer divide 2 operands
347 ;; idiv3 integer divide 3 operands
348 ;; move integer register move ({,D}ADD{,U} with rt = 0)
349 ;; fmove floating point register move
350 ;; fadd floating point add/subtract
351 ;; fmul floating point multiply
352 ;; fmadd floating point multiply-add
353 ;; fdiv floating point divide
354 ;; frdiv floating point reciprocal divide
355 ;; frdiv1 floating point reciprocal divide step 1
356 ;; frdiv2 floating point reciprocal divide step 2
357 ;; fabs floating point absolute value
358 ;; fneg floating point negation
359 ;; fcmp floating point compare
360 ;; fcvt floating point convert
361 ;; fsqrt floating point square root
362 ;; frsqrt floating point reciprocal square root
363 ;; frsqrt1 floating point reciprocal square root step1
364 ;; frsqrt2 floating point reciprocal square root step2
365 ;; dspmac DSP MAC instructions not saturating the accumulator
366 ;; dspmacsat DSP MAC instructions that saturate the accumulator
367 ;; accext DSP accumulator extract instructions
368 ;; accmod DSP accumulator modify instructions
369 ;; dspalu DSP ALU instructions not saturating the result
370 ;; dspalusat DSP ALU instructions that saturate the result
371 ;; multi multiword sequence (or user asm statements)
372 ;; atomic atomic memory update instruction
373 ;; syncloop memory atomic operation implemented as a sync loop
374 ;; nop no operation
375 ;; ghost an instruction that produces no real code
376 ;; multimem microMIPS multiword load and store
377 (define_attr "type"
378 "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
379 prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical,
380 shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
381 fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
382 frsqrt,frsqrt1,frsqrt2,dspmac,dspmacsat,accext,accmod,dspalu,dspalusat,
383 multi,atomic,syncloop,nop,ghost,multimem,
384 simd_div,simd_fclass,simd_flog2,simd_fadd,simd_fcvt,simd_fmul,simd_fmadd,
385 simd_fdiv,simd_bitins,simd_bitmov,simd_insert,simd_sld,simd_mul,simd_fcmp,
386 simd_fexp2,simd_int_arith,simd_bit,simd_shift,simd_splat,simd_fill,
387 simd_permute,simd_shf,simd_sat,simd_pcnt,simd_copy,simd_branch,simd_cmsa,
388 simd_fminmax,simd_logic,simd_move,simd_load,simd_store"
389 (cond [(eq_attr "jal" "!unset") (const_string "call")
390 (eq_attr "got" "load") (const_string "load")
391
392 (eq_attr "alu_type" "add,sub") (const_string "arith")
393
394 (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
395
396 ;; If a doubleword move uses these expensive instructions,
397 ;; it is usually better to schedule them in the same way
398 ;; as the singleword form, rather than as "multi".
399 (eq_attr "move_type" "load") (const_string "load")
400 (eq_attr "move_type" "fpload") (const_string "fpload")
401 (eq_attr "move_type" "store") (const_string "store")
402 (eq_attr "move_type" "fpstore") (const_string "fpstore")
403 (eq_attr "move_type" "mtc") (const_string "mtc")
404 (eq_attr "move_type" "mfc") (const_string "mfc")
405 (eq_attr "move_type" "mtlo") (const_string "mtlo")
406 (eq_attr "move_type" "mflo") (const_string "mflo")
407
408 ;; These types of move are always single insns.
409 (eq_attr "move_type" "imul") (const_string "imul")
410 (eq_attr "move_type" "fmove") (const_string "fmove")
411 (eq_attr "move_type" "loadpool") (const_string "load")
412 (eq_attr "move_type" "signext") (const_string "signext")
413 (eq_attr "move_type" "ext_ins") (const_string "arith")
414 (eq_attr "move_type" "arith") (const_string "arith")
415 (eq_attr "move_type" "logical") (const_string "logical")
416 (eq_attr "move_type" "sll0") (const_string "shift")
417 (eq_attr "move_type" "andi") (const_string "logical")
418
419 ;; These types of move are always split.
420 (eq_attr "move_type" "constN,shift_shift")
421 (const_string "multi")
422
423 ;; These types of move are split for quadword modes only.
424 (and (eq_attr "move_type" "move,const")
425 (eq_attr "qword_mode" "yes"))
426 (const_string "multi")
427
428 ;; These types of move are split for doubleword modes only.
429 (and (eq_attr "move_type" "move,const")
430 (eq_attr "dword_mode" "yes"))
431 (const_string "multi")
432 (eq_attr "move_type" "move") (const_string "move")
433 (eq_attr "move_type" "const") (const_string "const")
434 (eq_attr "sync_mem" "!none") (const_string "syncloop")]
435 (const_string "unknown")))
436
437 (define_attr "compact_form" "always,maybe,never"
438 (cond [(eq_attr "jal" "direct")
439 (const_string "always")
440 (eq_attr "jal" "indirect")
441 (const_string "maybe")
442 (eq_attr "type" "jump")
443 (const_string "maybe")]
444 (const_string "never")))
445
446 ;; Mode for conversion types (fcvt)
447 ;; I2S integer to float single (SI/DI to SF)
448 ;; I2D integer to float double (SI/DI to DF)
449 ;; S2I float to integer (SF to SI/DI)
450 ;; D2I float to integer (DF to SI/DI)
451 ;; D2S double to float single
452 ;; S2D float single to double
453
454 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D"
455 (const_string "unknown"))
456
457 ;; Is this an extended instruction in mips16 mode?
458 (define_attr "extended_mips16" "no,yes"
459 (if_then_else (ior ;; In general, constant-pool loads are extended
460 ;; instructions. We don't yet optimize for 16-bit
461 ;; PC-relative references.
462 (eq_attr "move_type" "sll0,loadpool")
463 (eq_attr "jal" "direct")
464 (eq_attr "got" "load"))
465 (const_string "yes")
466 (const_string "no")))
467
468 (define_attr "compression" "none,all,micromips32,micromips"
469 (const_string "none"))
470
471 (define_attr "enabled" "no,yes"
472 (cond [;; The o32 FPXX and FP64A ABI extensions prohibit direct moves between
473 ;; GR_REG and FR_REG for 64-bit values.
474 (and (eq_attr "move_type" "mtc,mfc")
475 (match_test "(TARGET_FLOATXX && !ISA_HAS_MXHC1)
476 || TARGET_O32_FP64A_ABI")
477 (eq_attr "dword_mode" "yes"))
478 (const_string "no")
479 (and (eq_attr "compression" "micromips32,micromips")
480 (match_test "!TARGET_MICROMIPS"))
481 (const_string "no")]
482 (const_string "yes")))
483
484 ;; The number of individual instructions that a non-branch pattern generates,
485 ;; using units of BASE_INSN_LENGTH.
486 (define_attr "insn_count" ""
487 (cond [;; "Ghost" instructions occupy no space.
488 (eq_attr "type" "ghost")
489 (const_int 0)
490
491 ;; Extended instructions count as 2.
492 (and (eq_attr "extended_mips16" "yes")
493 (match_test "TARGET_MIPS16"))
494 (const_int 2)
495
496 ;; A GOT load followed by an add of $gp. This is not used for MIPS16.
497 (eq_attr "got" "xgot_high")
498 (const_int 2)
499
500 ;; SHIFT_SHIFTs are decomposed into two separate instructions.
501 ;; They are extended instructions on MIPS16 targets.
502 (eq_attr "move_type" "shift_shift")
503 (if_then_else (match_test "TARGET_MIPS16")
504 (const_int 4)
505 (const_int 2))
506
507 ;; Check for doubleword moves that are decomposed into two
508 ;; instructions. The individual instructions are unextended
509 ;; MIPS16 ones.
510 (and (eq_attr "move_type" "mtc,mfc,mtlo,mflo,move")
511 (eq_attr "dword_mode" "yes"))
512 (const_int 2)
513
514 ;; Check for quadword moves that are decomposed into four
515 ;; instructions.
516 (and (eq_attr "move_type" "mtc,mfc,move")
517 (eq_attr "qword_mode" "yes"))
518 (const_int 4)
519
520 ;; Constants, loads and stores are handled by external routines.
521 (and (eq_attr "move_type" "const,constN")
522 (eq_attr "dword_mode" "yes"))
523 (symbol_ref "mips_split_const_insns (operands[1])")
524 (eq_attr "move_type" "const,constN")
525 (symbol_ref "mips_const_insns (operands[1])")
526 (eq_attr "move_type" "load,fpload")
527 (symbol_ref "mips_load_store_insns (operands[1], insn)")
528 (eq_attr "move_type" "store,fpstore")
529 (symbol_ref "mips_load_store_insns (operands[0], insn)
530 + (TARGET_FIX_24K ? 1 : 0)")
531
532 ;; In the worst case, a call macro will take 8 instructions:
533 ;;
534 ;; lui $25,%call_hi(FOO)
535 ;; addu $25,$25,$28
536 ;; lw $25,%call_lo(FOO)($25)
537 ;; nop
538 ;; jalr $25
539 ;; nop
540 ;; lw $gp,X($sp)
541 ;; nop
542 (eq_attr "jal_macro" "yes")
543 (const_int 8)
544
545 ;; Various VR4120 errata require a nop to be inserted after a macc
546 ;; instruction. The assembler does this for us, so account for
547 ;; the worst-case length here.
548 (and (eq_attr "type" "imadd")
549 (match_test "TARGET_FIX_VR4120"))
550 (const_int 2)
551
552 ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
553 ;; the result of the second one is missed. The assembler should work
554 ;; around this by inserting a nop after the first dmult.
555 (and (eq_attr "type" "imul,imul3")
556 (eq_attr "mode" "DI")
557 (match_test "TARGET_FIX_VR4120"))
558 (const_int 2)
559
560 (eq_attr "type" "idiv,idiv3")
561 (symbol_ref "mips_idiv_insns (GET_MODE (PATTERN (insn)))")
562
563 ;; simd div have 3 instruction if TARGET_CHECK_ZERO_DIV is true.
564 (eq_attr "type" "simd_div")
565 (if_then_else (match_test "TARGET_CHECK_ZERO_DIV")
566 (const_int 3)
567 (const_int 1))
568
569 (not (eq_attr "sync_mem" "none"))
570 (symbol_ref "mips_sync_loop_insns (insn, operands)")]
571 (const_int 1)))
572
573 ;; Length of instruction in bytes. The default is derived from "insn_count",
574 ;; but there are special cases for branches (which must be handled here)
575 ;; and for compressed single instructions.
576 (define_attr "length" ""
577 (cond [(and (ior (eq_attr "compression" "micromips,all")
578 (and (eq_attr "compression" "micromips32")
579 (eq_attr "mode" "SI,SF")))
580 (eq_attr "dword_mode" "no")
581 (match_test "TARGET_MICROMIPS"))
582 (const_int 2)
583
584 ;; Direct microMIPS branch instructions have a range of
585 ;; [-0x10000,0xfffe], otherwise the range is [-0x20000,0x1fffc].
586 ;; If a branch is outside this range, we have a choice of two
587 ;; sequences.
588 ;;
589 ;; For PIC, an out-of-range branch like:
590 ;;
591 ;; bne r1,r2,target
592 ;; dslot
593 ;;
594 ;; becomes the equivalent of:
595 ;;
596 ;; beq r1,r2,1f
597 ;; dslot
598 ;; la $at,target
599 ;; jr $at
600 ;; nop
601 ;; 1:
602 ;;
603 ;; The non-PIC case is similar except that we use a direct
604 ;; jump instead of an la/jr pair. Since the target of this
605 ;; jump is an absolute 28-bit bit address (the other bits
606 ;; coming from the address of the delay slot) this form cannot
607 ;; cross a 256MB boundary. We could provide the option of
608 ;; using la/jr in this case too, but we do not do so at
609 ;; present.
610 ;;
611 ;; The value we specify here does not account for the delay slot
612 ;; instruction, whose length is added separately. If the RTL
613 ;; pattern has no explicit delay slot, mips_adjust_insn_length
614 ;; will add the length of the implicit nop. The range of
615 ;; [-0x20000, 0x1fffc] from the address of the delay slot
616 ;; therefore translates to a range of:
617 ;;
618 ;; [-(0x20000 - sizeof (branch)), 0x1fffc - sizeof (slot)]
619 ;; == [-0x1fffc, 0x1fff8]
620 ;;
621 ;; from the shorten_branches reference address.
622 (and (eq_attr "type" "branch")
623 (not (match_test "TARGET_MIPS16")))
624 (cond [;; Any variant can handle the 17-bit range.
625 (and (le (minus (match_dup 0) (pc)) (const_int 65532))
626 (le (minus (pc) (match_dup 0)) (const_int 65534)))
627 (const_int 4)
628
629 ;; The 18-bit range is OK other than for microMIPS.
630 (and (not (match_test "TARGET_MICROMIPS"))
631 (and (le (minus (match_dup 0) (pc)) (const_int 131064))
632 (le (minus (pc) (match_dup 0)) (const_int 131068))))
633 (const_int 4)
634
635 ;; The non-PIC case: branch, first delay slot, and J.
636 (match_test "TARGET_ABSOLUTE_JUMPS")
637 (const_int 12)]
638
639 ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
640 ;; mips_adjust_insn_length substitutes the correct length.
641 ;;
642 ;; Note that we can't simply use (symbol_ref ...) here
643 ;; because genattrtab needs to know the maximum length
644 ;; of an insn.
645 (const_int MAX_PIC_BRANCH_LENGTH))
646
647 ;; An unextended MIPS16 branch has a range of [-0x100, 0xfe]
648 ;; from the address of the following instruction, which leads
649 ;; to a range of:
650 ;;
651 ;; [-(0x100 - sizeof (branch)), 0xfe]
652 ;; == [-0xfe, 0xfe]
653 ;;
654 ;; from the shorten_branches reference address. Extended branches
655 ;; likewise have a range of [-0x10000, 0xfffe] from the address
656 ;; of the following instruction, which leads to a range of:
657 ;;
658 ;; [-(0x10000 - sizeof (branch)), 0xfffe]
659 ;; == [-0xfffc, 0xfffe]
660 ;;
661 ;; from the reference address.
662 ;;
663 ;; When a branch is out of range, mips_reorg splits it into a form
664 ;; that uses in-range branches. There are four basic sequences:
665 ;;
666 ;; (1) Absolute addressing with a readable text segment
667 ;; (32-bit addresses):
668 ;;
669 ;; b... foo 2 bytes
670 ;; move $1,$2 2 bytes
671 ;; lw $2,label 2 bytes
672 ;; jr $2 2 bytes
673 ;; move $2,$1 2 bytes
674 ;; .align 2 0 or 2 bytes
675 ;; label:
676 ;; .word target 4 bytes
677 ;; foo:
678 ;; (16 bytes in the worst case)
679 ;;
680 ;; (2) Absolute addressing with a readable text segment
681 ;; (64-bit addresses):
682 ;;
683 ;; b... foo 2 bytes
684 ;; move $1,$2 2 bytes
685 ;; ld $2,label 2 bytes
686 ;; jr $2 2 bytes
687 ;; move $2,$1 2 bytes
688 ;; .align 3 0 to 6 bytes
689 ;; label:
690 ;; .dword target 8 bytes
691 ;; foo:
692 ;; (24 bytes in the worst case)
693 ;;
694 ;; (3) Absolute addressing without a readable text segment
695 ;; (which requires 32-bit addresses at present):
696 ;;
697 ;; b... foo 2 bytes
698 ;; move $1,$2 2 bytes
699 ;; lui $2,%hi(target) 4 bytes
700 ;; sll $2,8 2 bytes
701 ;; sll $2,8 2 bytes
702 ;; addiu $2,%lo(target) 4 bytes
703 ;; jr $2 2 bytes
704 ;; move $2,$1 2 bytes
705 ;; foo:
706 ;; (20 bytes)
707 ;;
708 ;; (4) PIC addressing (which requires 32-bit addresses at present):
709 ;;
710 ;; b... foo 2 bytes
711 ;; move $1,$2 2 bytes
712 ;; lw $2,cprestore 0, 2 or 4 bytes
713 ;; lw $2,%got(target)($2) 4 bytes
714 ;; addiu $2,%lo(target) 4 bytes
715 ;; jr $2 2 bytes
716 ;; move $2,$1 2 bytes
717 ;; foo:
718 ;; (20 bytes in the worst case)
719 (and (eq_attr "type" "branch")
720 (match_test "TARGET_MIPS16"))
721 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
722 (le (minus (pc) (match_dup 0)) (const_int 254)))
723 (const_int 2)
724 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
725 (le (minus (pc) (match_dup 0)) (const_int 65532)))
726 (const_int 4)
727 (and (match_test "TARGET_ABICALLS")
728 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
729 (const_int 20)
730 (match_test "Pmode == SImode")
731 (const_int 16)
732 ] (const_int 24))]
733 (symbol_ref "get_attr_insn_count (insn) * BASE_INSN_LENGTH")))
734
735 ;; Attribute describing the processor.
736 (define_enum_attr "cpu" "processor"
737 (const (symbol_ref "mips_tune")))
738
739 ;; The type of hardware hazard associated with this instruction.
740 ;; DELAY means that the next instruction cannot read the result
741 ;; of this one. HILO means that the next two instructions cannot
742 ;; write to HI or LO.
743 (define_attr "hazard" "none,delay,hilo,forbidden_slot"
744 (cond [(and (eq_attr "type" "load,fpload,fpidxload")
745 (match_test "ISA_HAS_LOAD_DELAY"))
746 (const_string "delay")
747
748 (and (eq_attr "type" "mfc,mtc")
749 (match_test "ISA_HAS_XFER_DELAY"))
750 (const_string "delay")
751
752 (and (eq_attr "type" "fcmp")
753 (match_test "ISA_HAS_FCMP_DELAY"))
754 (const_string "delay")
755
756 ;; The r4000 multiplication patterns include an mflo instruction.
757 (and (eq_attr "type" "imul")
758 (match_test "TARGET_FIX_R4000"))
759 (const_string "hilo")
760
761 (and (eq_attr "type" "mfhi,mflo")
762 (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
763 (const_string "hilo")]
764 (const_string "none")))
765
766 ;; Can the instruction be put into a delay slot?
767 (define_attr "can_delay" "no,yes"
768 (if_then_else (and (eq_attr "type" "!branch,call,jump,simd_branch")
769 (eq_attr "hazard" "none")
770 (match_test "get_attr_insn_count (insn) == 1"))
771 (const_string "yes")
772 (const_string "no")))
773
774 ;; Attribute defining whether or not we can use the branch-likely
775 ;; instructions.
776 (define_attr "branch_likely" "no,yes"
777 (if_then_else (match_test "GENERATE_BRANCHLIKELY")
778 (const_string "yes")
779 (const_string "no")))
780
781 ;; True if an instruction might assign to hi or lo when reloaded.
782 ;; This is used by the TUNE_MACC_CHAINS code.
783 (define_attr "may_clobber_hilo" "no,yes"
784 (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthi,mtlo")
785 (const_string "yes")
786 (const_string "no")))
787
788 ;; Describe a user's asm statement.
789 (define_asm_attributes
790 [(set_attr "type" "multi")
791 (set_attr "can_delay" "no")])
792 \f
793 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
794 ;; from the same template.
795 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
796
797 ;; A copy of GPR that can be used when a pattern has two independent
798 ;; modes.
799 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
800
801 (define_mode_iterator MOVEP1 [SI SF])
802 (define_mode_iterator MOVEP2 [SI SF])
803 (define_mode_iterator JOIN_MODE [HI
804 SI
805 (SF "TARGET_HARD_FLOAT")
806 (DF "TARGET_HARD_FLOAT
807 && TARGET_DOUBLE_FLOAT")])
808
809 ;; This mode iterator allows :HILO to be used as the mode of the
810 ;; concatenated HI and LO registers.
811 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
812
813 ;; This mode iterator allows :P to be used for patterns that operate on
814 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
815 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
816
817 ;; This mode iterator allows :MOVECC to be used anywhere that a
818 ;; conditional-move-type condition is needed.
819 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
820 (CC "TARGET_HARD_FLOAT
821 && !TARGET_LOONGSON_2EF
822 && !TARGET_MIPS5900")])
823
824 ;; This mode iterator allows :FPCC to be used anywhere that an FP condition
825 ;; is needed.
826 (define_mode_iterator FPCC [(CC "!ISA_HAS_CCF")
827 (CCF "ISA_HAS_CCF")])
828
829 ;; 32-bit integer moves for which we provide move patterns.
830 (define_mode_iterator IMOVE32
831 [SI
832 (V2HI "TARGET_DSP")
833 (V4QI "TARGET_DSP")
834 (V2HQ "TARGET_DSP")
835 (V2UHQ "TARGET_DSP")
836 (V2HA "TARGET_DSP")
837 (V2UHA "TARGET_DSP")
838 (V4QQ "TARGET_DSP")
839 (V4UQQ "TARGET_DSP")])
840
841 ;; 64-bit modes for which we provide move patterns.
842 (define_mode_iterator MOVE64
843 [DI DF
844 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
845 (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI")
846 (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI")
847 (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI")])
848
849 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
850 (define_mode_iterator MOVE128 [TI TF])
851
852 ;; This mode iterator allows the QI and HI extension patterns to be
853 ;; defined from the same template.
854 (define_mode_iterator SHORT [QI HI])
855
856 ;; Likewise the 64-bit truncate-and-shift patterns.
857 (define_mode_iterator SUBDI [QI HI SI])
858
859 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
860 ;; floating-point mode is allowed.
861 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
862 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
863 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
864
865 ;; Like ANYF, but only applies to scalar modes.
866 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
867 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
868
869 ;; A floating-point mode for which moves involving FPRs may need to be split.
870 (define_mode_iterator SPLITF
871 [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
872 (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
873 (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
874 (V2SI "!TARGET_64BIT && TARGET_LOONGSON_MMI")
875 (V4HI "!TARGET_64BIT && TARGET_LOONGSON_MMI")
876 (V8QI "!TARGET_64BIT && TARGET_LOONGSON_MMI")
877 (TF "TARGET_64BIT && TARGET_FLOAT64")])
878
879 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
880 ;; 32-bit version and "dsubu" in the 64-bit version.
881 (define_mode_attr d [(SI "") (DI "d")
882 (QQ "") (HQ "") (SQ "") (DQ "d")
883 (UQQ "") (UHQ "") (USQ "") (UDQ "d")
884 (HA "") (SA "") (DA "d")
885 (UHA "") (USA "") (UDA "d")])
886
887 ;; Same as d but upper-case.
888 (define_mode_attr D [(SI "") (DI "D")
889 (QQ "") (HQ "") (SQ "") (DQ "D")
890 (UQQ "") (UHQ "") (USQ "") (UDQ "D")
891 (HA "") (SA "") (DA "D")
892 (UHA "") (USA "") (UDA "D")])
893
894 ;; This attribute gives the length suffix for a load or store instruction.
895 ;; The same suffixes work for zero and sign extensions.
896 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
897 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
898
899 ;; This attributes gives the mode mask of a SHORT.
900 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
901
902 ;; Mode attributes for GPR loads.
903 (define_mode_attr load [(SI "lw") (DI "ld")])
904 ;; Instruction names for stores.
905 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
906
907 ;; Similarly for MIPS IV indexed FPR loads and stores.
908 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
909 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
910
911 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
912 ;; are different. Some forms of unextended addiu have an 8-bit immediate
913 ;; field but the equivalent daddiu has only a 5-bit field.
914 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
915
916 ;; This attribute gives the best constraint to use for registers of
917 ;; a given mode.
918 (define_mode_attr reg [(SI "d") (DI "d") (CC "z") (CCF "f")])
919
920 ;; This attribute gives the format suffix for floating-point operations.
921 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
922
923 ;; This attribute gives the upper-case mode name for one unit of a
924 ;; floating-point mode or vector mode.
925 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF") (V4SF "SF")
926 (V16QI "QI") (V8HI "HI") (V4SI "SI") (V2DI "DI")
927 (V2DF "DF")])
928
929 ;; As above, but in lower case.
930 (define_mode_attr unitmode [(SF "sf") (DF "df") (V2SF "sf") (V4SF "sf")
931 (V16QI "qi") (V8QI "qi") (V8HI "hi") (V4HI "hi")
932 (V4SI "si") (V2SI "si") (V2DI "di") (V2DF "df")])
933
934 ;; This attribute gives the integer mode that has the same size as a
935 ;; fixed-point mode.
936 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
937 (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
938 (HA "HI") (SA "SI") (DA "DI")
939 (UHA "HI") (USA "SI") (UDA "DI")
940 (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
941 (V2HQ "SI") (V2HA "SI")])
942
943 ;; This attribute gives the integer mode that has half the size of
944 ;; the controlling mode.
945 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
946 (V2SI "SI") (V4HI "SI") (V8QI "SI")
947 (TF "DI")])
948
949 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
950 ;;
951 ;; In certain cases, div.s and div.ps may have a rounding error
952 ;; and/or wrong inexact flag.
953 ;;
954 ;; Therefore, we only allow div.s if not working around SB-1 rev2
955 ;; errata or if a slight loss of precision is OK.
956 (define_mode_attr divide_condition
957 [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
958 (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
959
960 ;; This attribute gives the conditions under which SQRT.fmt instructions
961 ;; can be used.
962 (define_mode_attr sqrt_condition
963 [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
964
965 ;; This attribute provides the correct mnemonic for each FP condition mode.
966 (define_mode_attr fpcmp [(CC "c") (CCF "cmp")])
967
968 ;; This code iterator allows signed and unsigned widening multiplications
969 ;; to use the same template.
970 (define_code_iterator any_extend [sign_extend zero_extend])
971
972 ;; This code iterator allows the two right shift instructions to be
973 ;; generated from the same template.
974 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
975
976 ;; This code iterator allows the three shift instructions to be generated
977 ;; from the same template.
978 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
979
980 ;; This code iterator allows unsigned and signed division to be generated
981 ;; from the same template.
982 (define_code_iterator any_div [div udiv])
983
984 ;; This code iterator allows unsigned and signed modulus to be generated
985 ;; from the same template.
986 (define_code_iterator any_mod [mod umod])
987
988 ;; This code iterator allows addition and subtraction to be generated
989 ;; from the same template.
990 (define_code_iterator addsub [plus minus])
991
992 ;; This code iterator allows all native floating-point comparisons to be
993 ;; generated from the same template.
994 (define_code_iterator fcond [unordered uneq unlt unle eq lt le
995 (ordered "ISA_HAS_CCF")
996 (ltgt "ISA_HAS_CCF")
997 (ne "ISA_HAS_CCF")])
998
999 ;; This code iterator is used for comparisons that can be implemented
1000 ;; by swapping the operands.
1001 (define_code_iterator swapped_fcond [ge gt unge ungt])
1002
1003 ;; Equality operators.
1004 (define_code_iterator equality_op [eq ne])
1005
1006 ;; These code iterators allow the signed and unsigned scc operations to use
1007 ;; the same template.
1008 (define_code_iterator any_gt [gt gtu])
1009 (define_code_iterator any_ge [ge geu])
1010 (define_code_iterator any_lt [lt ltu])
1011 (define_code_iterator any_le [le leu])
1012
1013 (define_code_iterator any_return [return simple_return])
1014
1015 ;; <u> expands to an empty string when doing a signed operation and
1016 ;; "u" when doing an unsigned operation.
1017 (define_code_attr u [(sign_extend "") (zero_extend "u")
1018 (div "") (udiv "u")
1019 (mod "") (umod "u")
1020 (gt "") (gtu "u")
1021 (ge "") (geu "u")
1022 (lt "") (ltu "u")
1023 (le "") (leu "u")])
1024
1025 ;; <U> is like <u> except uppercase.
1026 (define_code_attr U [(sign_extend "") (zero_extend "U")])
1027
1028 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
1029 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
1030
1031 ;; <optab> expands to the name of the optab for a particular code.
1032 (define_code_attr optab [(ashift "ashl")
1033 (ashiftrt "ashr")
1034 (lshiftrt "lshr")
1035 (ior "ior")
1036 (xor "xor")
1037 (and "and")
1038 (plus "add")
1039 (minus "sub")
1040 (return "return")
1041 (simple_return "simple_return")])
1042
1043 ;; <insn> expands to the name of the insn that implements a particular code.
1044 (define_code_attr insn [(ashift "sll")
1045 (ashiftrt "sra")
1046 (lshiftrt "srl")
1047 (ior "or")
1048 (xor "xor")
1049 (and "and")
1050 (plus "addu")
1051 (minus "subu")])
1052
1053 ;; <immediate_insn> expands to the name of the insn that implements
1054 ;; a particular code to operate on immediate values.
1055 (define_code_attr immediate_insn [(ior "ori")
1056 (xor "xori")
1057 (and "andi")])
1058
1059 (define_code_attr shift_compression [(ashift "micromips32")
1060 (lshiftrt "micromips32")
1061 (ashiftrt "none")])
1062
1063 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
1064 (define_code_attr fcond [(unordered "un")
1065 (uneq "ueq")
1066 (unlt "ult")
1067 (unle "ule")
1068 (eq "eq")
1069 (lt "lt")
1070 (le "le")
1071 (ordered "or")
1072 (ltgt "ne")
1073 (ne "une")])
1074
1075 ;; Similar, but for swapped conditions.
1076 (define_code_attr swapped_fcond [(ge "le")
1077 (gt "lt")
1078 (unge "ule")
1079 (ungt "ult")])
1080
1081 ;; The value of the bit when the branch is taken for branch_bit patterns.
1082 ;; Comparison is always against zero so this depends on the operator.
1083 (define_code_attr bbv [(eq "0") (ne "1")])
1084
1085 ;; This is the inverse value of bbv.
1086 (define_code_attr bbinv [(eq "1") (ne "0")])
1087
1088 ;; The sel mnemonic to use depending on the condition test.
1089 (define_code_attr sel [(eq "seleqz") (ne "selnez")])
1090 (define_code_attr selinv [(eq "selnez") (ne "seleqz")])
1091 \f
1092 ;; .........................
1093 ;;
1094 ;; Branch, call and jump delay slots
1095 ;;
1096 ;; .........................
1097
1098 (define_delay (and (eq_attr "type" "branch")
1099 (not (match_test "TARGET_MIPS16"))
1100 (eq_attr "branch_likely" "yes"))
1101 [(eq_attr "can_delay" "yes")
1102 (nil)
1103 (eq_attr "can_delay" "yes")])
1104
1105 ;; Branches that have delay slots and don't have likely variants do
1106 ;; not annul on false.
1107 (define_delay (and (eq_attr "type" "branch,simd_branch")
1108 (not (match_test "TARGET_MIPS16"))
1109 (ior (match_test "TARGET_CB_NEVER")
1110 (and (eq_attr "compact_form" "maybe")
1111 (not (match_test "TARGET_CB_ALWAYS")))
1112 (eq_attr "compact_form" "never"))
1113 (eq_attr "branch_likely" "no"))
1114 [(eq_attr "can_delay" "yes")
1115 (nil)
1116 (nil)])
1117
1118 (define_delay (and (eq_attr "type" "jump")
1119 (ior (match_test "TARGET_CB_NEVER")
1120 (and (eq_attr "compact_form" "maybe")
1121 (not (match_test "TARGET_CB_ALWAYS")))
1122 (eq_attr "compact_form" "never")))
1123 [(eq_attr "can_delay" "yes")
1124 (nil)
1125 (nil)])
1126
1127 ;; Call type instructions should never have a compact form as the
1128 ;; type is only used for MIPS16 patterns. For safety put the compact
1129 ;; branch detection condition in anyway.
1130 (define_delay (and (eq_attr "type" "call")
1131 (eq_attr "jal_macro" "no")
1132 (ior (match_test "TARGET_CB_NEVER")
1133 (and (eq_attr "compact_form" "maybe")
1134 (not (match_test "TARGET_CB_ALWAYS")))
1135 (eq_attr "compact_form" "never")))
1136 [(eq_attr "can_delay" "yes")
1137 (nil)
1138 (nil)])
1139 \f
1140 ;; Pipeline descriptions.
1141 ;;
1142 ;; generic.md provides a fallback for processors without a specific
1143 ;; pipeline description. It is derived from the old define_function_unit
1144 ;; version and uses the "alu" and "imuldiv" units declared below.
1145 ;;
1146 ;; Some of the processor-specific files are also derived from old
1147 ;; define_function_unit descriptions and simply override the parts of
1148 ;; generic.md that don't apply. The other processor-specific files
1149 ;; are self-contained.
1150 (define_automaton "alu,imuldiv")
1151
1152 (define_cpu_unit "alu" "alu")
1153 (define_cpu_unit "imuldiv" "imuldiv")
1154
1155 ;; Ghost instructions produce no real code and introduce no hazards.
1156 ;; They exist purely to express an effect on dataflow.
1157 (define_insn_reservation "ghost" 0
1158 (eq_attr "type" "ghost")
1159 "nothing")
1160
1161 (include "i6400.md")
1162 (include "p5600.md")
1163 (include "m5100.md")
1164 (include "p6600.md")
1165 (include "4k.md")
1166 (include "5k.md")
1167 (include "20kc.md")
1168 (include "24k.md")
1169 (include "74k.md")
1170 (include "3000.md")
1171 (include "4000.md")
1172 (include "4100.md")
1173 (include "4130.md")
1174 (include "4300.md")
1175 (include "4600.md")
1176 (include "5000.md")
1177 (include "5400.md")
1178 (include "5500.md")
1179 (include "6000.md")
1180 (include "7000.md")
1181 (include "9000.md")
1182 (include "10000.md")
1183 (include "loongson2ef.md")
1184 (include "gs464.md")
1185 (include "gs464e.md")
1186 (include "gs264e.md")
1187 (include "octeon.md")
1188 (include "sb1.md")
1189 (include "sr71k.md")
1190 (include "xlr.md")
1191 (include "xlp.md")
1192 (include "generic.md")
1193 \f
1194 ;;
1195 ;; ....................
1196 ;;
1197 ;; CONDITIONAL TRAPS
1198 ;;
1199 ;; ....................
1200 ;;
1201
1202 (define_insn "trap"
1203 [(trap_if (const_int 1) (const_int 0))]
1204 ""
1205 {
1206 if (ISA_HAS_COND_TRAP)
1207 return "teq\t$0,$0";
1208 else if (TARGET_MIPS16)
1209 return "break 0";
1210 else
1211 return "break";
1212 }
1213 [(set_attr "type" "trap")])
1214
1215 (define_expand "ctrap<mode>4"
1216 [(trap_if (match_operator 0 "comparison_operator"
1217 [(match_operand:GPR 1 "reg_or_0_operand")
1218 (match_operand:GPR 2 "arith_operand")])
1219 (match_operand 3 "const_0_operand"))]
1220 "ISA_HAS_COND_TRAPI || ISA_HAS_COND_TRAP"
1221 {
1222 mips_expand_conditional_trap (operands[0]);
1223 DONE;
1224 })
1225
1226 (define_insn "*conditional_trap_reg<mode>"
1227 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1228 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1229 (match_operand:GPR 2 "reg_or_0_operand" "dJ")])
1230 (const_int 0))]
1231 "ISA_HAS_COND_TRAP && !ISA_HAS_COND_TRAPI"
1232 "t%C0\t%z1,%2"
1233 [(set_attr "type" "trap")])
1234
1235 (define_insn "*conditional_trap<mode>"
1236 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1237 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1238 (match_operand:GPR 2 "arith_operand" "dI")])
1239 (const_int 0))]
1240 "ISA_HAS_COND_TRAPI"
1241 "t%C0\t%z1,%2"
1242 [(set_attr "type" "trap")])
1243 \f
1244 ;;
1245 ;; ....................
1246 ;;
1247 ;; ADDITION
1248 ;;
1249 ;; ....................
1250 ;;
1251
1252 (define_insn "add<mode>3"
1253 [(set (match_operand:ANYF 0 "register_operand" "=f")
1254 (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1255 (match_operand:ANYF 2 "register_operand" "f")))]
1256 ""
1257 "add.<fmt>\t%0,%1,%2"
1258 [(set_attr "type" "fadd")
1259 (set_attr "mode" "<UNITMODE>")])
1260
1261 (define_expand "add<mode>3"
1262 [(set (match_operand:GPR 0 "register_operand")
1263 (plus:GPR (match_operand:GPR 1 "register_operand")
1264 (match_operand:GPR 2 "arith_operand")))]
1265 "")
1266
1267 (define_insn "*add<mode>3"
1268 [(set (match_operand:GPR 0 "register_operand" "=!u,d,!u,!u,!ks,!d,d")
1269 (plus:GPR (match_operand:GPR 1 "register_operand" "!u,d,!u,!ks,!ks,0,d")
1270 (match_operand:GPR 2 "arith_operand" "!u,d,Uead,Uuw6,Uesp,Usb4,Q")))]
1271 "!TARGET_MIPS16"
1272 {
1273 if (which_alternative == 0
1274 || which_alternative == 1)
1275 return "<d>addu\t%0,%1,%2";
1276 else
1277 return "<d>addiu\t%0,%1,%2";
1278 }
1279 [(set_attr "alu_type" "add")
1280 (set_attr "compression" "micromips32,*,micromips32,micromips32,micromips32,micromips32,*")
1281 (set_attr "mode" "<MODE>")])
1282
1283 (define_insn "*add<mode>3_mips16"
1284 [(set (match_operand:GPR 0 "register_operand" "=ks,ks,d,d,d,d,d,d,d")
1285 (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,ks,ks,0,0,d,d,d")
1286 (match_operand:GPR 2 "arith_operand" "Usd8,Q,Uuw<si8_di5>,Q,Usb<si8_di5>,Q,Usb4,O,d")))]
1287 "TARGET_MIPS16"
1288 "@
1289 <d>addiu\t%0,%2
1290 <d>addiu\t%0,%2
1291 <d>addiu\t%0,%1,%2
1292 <d>addiu\t%0,%1,%2
1293 <d>addiu\t%0,%2
1294 <d>addiu\t%0,%2
1295 <d>addiu\t%0,%1,%2
1296 <d>addiu\t%0,%1,%2
1297 <d>addu\t%0,%1,%2"
1298 [(set_attr "alu_type" "add")
1299 (set_attr "mode" "<MODE>")
1300 (set_attr "extended_mips16" "no,yes,no,yes,no,yes,no,yes,no")])
1301
1302 ;; On the mips16, we can sometimes split an add of a constant which is
1303 ;; a 4 byte instruction into two adds which are both 2 byte
1304 ;; instructions. There are two cases: one where we are adding a
1305 ;; constant plus a register to another register, and one where we are
1306 ;; simply adding a constant to a register.
1307
1308 (define_split
1309 [(set (match_operand:SI 0 "d_operand")
1310 (plus:SI (match_dup 0)
1311 (match_operand:SI 1 "const_int_operand")))]
1312 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1313 && ((INTVAL (operands[1]) > 0x7f
1314 && INTVAL (operands[1]) <= 0x7f + 0x7f)
1315 || (INTVAL (operands[1]) < - 0x80
1316 && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1317 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1318 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1319 {
1320 HOST_WIDE_INT val = INTVAL (operands[1]);
1321
1322 if (val >= 0)
1323 {
1324 operands[1] = GEN_INT (0x7f);
1325 operands[2] = GEN_INT (val - 0x7f);
1326 }
1327 else
1328 {
1329 operands[1] = GEN_INT (- 0x80);
1330 operands[2] = GEN_INT (val + 0x80);
1331 }
1332 })
1333
1334 (define_split
1335 [(set (match_operand:SI 0 "d_operand")
1336 (plus:SI (match_operand:SI 1 "d_operand")
1337 (match_operand:SI 2 "const_int_operand")))]
1338 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1339 && REGNO (operands[0]) != REGNO (operands[1])
1340 && ((INTVAL (operands[2]) > 0x7
1341 && INTVAL (operands[2]) <= 0x7 + 0x7f)
1342 || (INTVAL (operands[2]) < - 0x8
1343 && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1344 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1345 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1346 {
1347 HOST_WIDE_INT val = INTVAL (operands[2]);
1348
1349 if (val >= 0)
1350 {
1351 operands[2] = GEN_INT (0x7);
1352 operands[3] = GEN_INT (val - 0x7);
1353 }
1354 else
1355 {
1356 operands[2] = GEN_INT (- 0x8);
1357 operands[3] = GEN_INT (val + 0x8);
1358 }
1359 })
1360
1361 (define_split
1362 [(set (match_operand:DI 0 "d_operand")
1363 (plus:DI (match_dup 0)
1364 (match_operand:DI 1 "const_int_operand")))]
1365 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1366 && ((INTVAL (operands[1]) > 0xf
1367 && INTVAL (operands[1]) <= 0xf + 0xf)
1368 || (INTVAL (operands[1]) < - 0x10
1369 && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1370 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1371 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1372 {
1373 HOST_WIDE_INT val = INTVAL (operands[1]);
1374
1375 if (val >= 0)
1376 {
1377 operands[1] = GEN_INT (0xf);
1378 operands[2] = GEN_INT (val - 0xf);
1379 }
1380 else
1381 {
1382 operands[1] = GEN_INT (- 0x10);
1383 operands[2] = GEN_INT (val + 0x10);
1384 }
1385 })
1386
1387 (define_split
1388 [(set (match_operand:DI 0 "d_operand")
1389 (plus:DI (match_operand:DI 1 "d_operand")
1390 (match_operand:DI 2 "const_int_operand")))]
1391 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1392 && REGNO (operands[0]) != REGNO (operands[1])
1393 && ((INTVAL (operands[2]) > 0x7
1394 && INTVAL (operands[2]) <= 0x7 + 0xf)
1395 || (INTVAL (operands[2]) < - 0x8
1396 && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1397 [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1398 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1399 {
1400 HOST_WIDE_INT val = INTVAL (operands[2]);
1401
1402 if (val >= 0)
1403 {
1404 operands[2] = GEN_INT (0x7);
1405 operands[3] = GEN_INT (val - 0x7);
1406 }
1407 else
1408 {
1409 operands[2] = GEN_INT (- 0x8);
1410 operands[3] = GEN_INT (val + 0x8);
1411 }
1412 })
1413
1414 (define_insn "*addsi3_extended"
1415 [(set (match_operand:DI 0 "register_operand" "=d,d")
1416 (sign_extend:DI
1417 (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1418 (match_operand:SI 2 "arith_operand" "d,Q"))))]
1419 "TARGET_64BIT && !TARGET_MIPS16"
1420 "@
1421 addu\t%0,%1,%2
1422 addiu\t%0,%1,%2"
1423 [(set_attr "alu_type" "add")
1424 (set_attr "mode" "SI")])
1425
1426 ;; Split this insn so that the addiu splitters can have a crack at it.
1427 ;; Use a conservative length estimate until the split.
1428 (define_insn_and_split "*addsi3_extended_mips16"
1429 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1430 (sign_extend:DI
1431 (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1432 (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1433 "TARGET_64BIT && TARGET_MIPS16"
1434 "#"
1435 "&& reload_completed"
1436 [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1437 { operands[3] = gen_lowpart (SImode, operands[0]); }
1438 [(set_attr "alu_type" "add")
1439 (set_attr "mode" "SI")
1440 (set_attr "extended_mips16" "yes")])
1441
1442 ;; Combiner patterns for unsigned byte-add.
1443
1444 (define_insn "*baddu_si_eb"
1445 [(set (match_operand:SI 0 "register_operand" "=d")
1446 (zero_extend:SI
1447 (subreg:QI
1448 (plus:SI (match_operand:SI 1 "register_operand" "d")
1449 (match_operand:SI 2 "register_operand" "d")) 3)))]
1450 "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1451 "baddu\\t%0,%1,%2"
1452 [(set_attr "alu_type" "add")])
1453
1454 (define_insn "*baddu_si_el"
1455 [(set (match_operand:SI 0 "register_operand" "=d")
1456 (zero_extend:SI
1457 (subreg:QI
1458 (plus:SI (match_operand:SI 1 "register_operand" "d")
1459 (match_operand:SI 2 "register_operand" "d")) 0)))]
1460 "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1461 "baddu\\t%0,%1,%2"
1462 [(set_attr "alu_type" "add")])
1463
1464 (define_insn "*baddu_di<mode>"
1465 [(set (match_operand:GPR 0 "register_operand" "=d")
1466 (zero_extend:GPR
1467 (truncate:QI
1468 (plus:DI (match_operand:DI 1 "register_operand" "d")
1469 (match_operand:DI 2 "register_operand" "d")))))]
1470 "ISA_HAS_BADDU && TARGET_64BIT"
1471 "baddu\\t%0,%1,%2"
1472 [(set_attr "alu_type" "add")])
1473 \f
1474 ;;
1475 ;; ....................
1476 ;;
1477 ;; SUBTRACTION
1478 ;;
1479 ;; ....................
1480 ;;
1481
1482 (define_insn "sub<mode>3"
1483 [(set (match_operand:ANYF 0 "register_operand" "=f")
1484 (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1485 (match_operand:ANYF 2 "register_operand" "f")))]
1486 ""
1487 "sub.<fmt>\t%0,%1,%2"
1488 [(set_attr "type" "fadd")
1489 (set_attr "mode" "<UNITMODE>")])
1490
1491 (define_insn "sub<mode>3"
1492 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
1493 (minus:GPR (match_operand:GPR 1 "register_operand" "!u,d")
1494 (match_operand:GPR 2 "register_operand" "!u,d")))]
1495 ""
1496 "<d>subu\t%0,%1,%2"
1497 [(set_attr "alu_type" "sub")
1498 (set_attr "compression" "micromips32,*")
1499 (set_attr "mode" "<MODE>")])
1500
1501 (define_insn "*subsi3_extended"
1502 [(set (match_operand:DI 0 "register_operand" "=d")
1503 (sign_extend:DI
1504 (minus:SI (match_operand:SI 1 "register_operand" "d")
1505 (match_operand:SI 2 "register_operand" "d"))))]
1506 "TARGET_64BIT"
1507 "subu\t%0,%1,%2"
1508 [(set_attr "alu_type" "sub")
1509 (set_attr "mode" "DI")])
1510 \f
1511 ;;
1512 ;; ....................
1513 ;;
1514 ;; MULTIPLICATION
1515 ;;
1516 ;; ....................
1517 ;;
1518
1519 (define_expand "mul<mode>3"
1520 [(set (match_operand:SCALARF 0 "register_operand")
1521 (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1522 (match_operand:SCALARF 2 "register_operand")))]
1523 ""
1524 "")
1525
1526 (define_insn "*mul<mode>3"
1527 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1528 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1529 (match_operand:SCALARF 2 "register_operand" "f")))]
1530 "!TARGET_4300_MUL_FIX"
1531 "mul.<fmt>\t%0,%1,%2"
1532 [(set_attr "type" "fmul")
1533 (set_attr "mode" "<MODE>")])
1534
1535 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1536 ;; operands may corrupt immediately following multiplies. This is a
1537 ;; simple fix to insert NOPs.
1538
1539 (define_insn "*mul<mode>3_r4300"
1540 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1541 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1542 (match_operand:SCALARF 2 "register_operand" "f")))]
1543 "TARGET_4300_MUL_FIX"
1544 "mul.<fmt>\t%0,%1,%2\;nop"
1545 [(set_attr "type" "fmul")
1546 (set_attr "mode" "<MODE>")
1547 (set_attr "insn_count" "2")])
1548
1549 (define_insn "mulv2sf3"
1550 [(set (match_operand:V2SF 0 "register_operand" "=f")
1551 (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1552 (match_operand:V2SF 2 "register_operand" "f")))]
1553 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1554 "mul.ps\t%0,%1,%2"
1555 [(set_attr "type" "fmul")
1556 (set_attr "mode" "SF")])
1557
1558 ;; The original R4000 has a cpu bug. If a double-word or a variable
1559 ;; shift executes while an integer multiplication is in progress, the
1560 ;; shift may give an incorrect result. Avoid this by keeping the mflo
1561 ;; with the mult on the R4000.
1562 ;;
1563 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1564 ;; (also valid for MIPS R4000MC processors):
1565 ;;
1566 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1567 ;; this errata description.
1568 ;; The following code sequence causes the R4000 to incorrectly
1569 ;; execute the Double Shift Right Arithmetic 32 (dsra32)
1570 ;; instruction. If the dsra32 instruction is executed during an
1571 ;; integer multiply, the dsra32 will only shift by the amount in
1572 ;; specified in the instruction rather than the amount plus 32
1573 ;; bits.
1574 ;; instruction 1: mult rs,rt integer multiply
1575 ;; instruction 2-12: dsra32 rd,rt,rs doubleword shift
1576 ;; right arithmetic + 32
1577 ;; Workaround: A dsra32 instruction placed after an integer
1578 ;; multiply should not be one of the 11 instructions after the
1579 ;; multiply instruction."
1580 ;;
1581 ;; and:
1582 ;;
1583 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1584 ;; the following description.
1585 ;; All extended shifts (shift by n+32) and variable shifts (32 and
1586 ;; 64-bit versions) may produce incorrect results under the
1587 ;; following conditions:
1588 ;; 1) An integer multiply is currently executing
1589 ;; 2) These types of shift instructions are executed immediately
1590 ;; following an integer divide instruction.
1591 ;; Workaround:
1592 ;; 1) Make sure no integer multiply is running wihen these
1593 ;; instruction are executed. If this cannot be predicted at
1594 ;; compile time, then insert a "mfhi" to R0 instruction
1595 ;; immediately after the integer multiply instruction. This
1596 ;; will cause the integer multiply to complete before the shift
1597 ;; is executed.
1598 ;; 2) Separate integer divide and these two classes of shift
1599 ;; instructions by another instruction or a noop."
1600 ;;
1601 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1602 ;; respectively.
1603
1604 (define_expand "mul<mode>3"
1605 [(set (match_operand:GPR 0 "register_operand")
1606 (mult:GPR (match_operand:GPR 1 "register_operand")
1607 (match_operand:GPR 2 "register_operand")))]
1608 "ISA_HAS_<D>MULT || ISA_HAS_R6<D>MUL"
1609 {
1610 rtx lo;
1611
1612 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>MUL)
1613 emit_insn (gen_mul<mode>3_mul3_nohilo (operands[0], operands[1],
1614 operands[2]));
1615 else if (ISA_HAS_<D>MUL3)
1616 emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1617 else if (TARGET_MIPS16)
1618 {
1619 lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1620 emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1621 emit_move_insn (operands[0], lo);
1622 }
1623 else if (TARGET_FIX_R4000)
1624 emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1625 else
1626 emit_insn
1627 (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1628 DONE;
1629 })
1630
1631 (define_insn "mul<mode>3_mul3_nohilo"
1632 [(set (match_operand:GPR 0 "register_operand" "=d")
1633 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1634 (match_operand:GPR 2 "register_operand" "d")))]
1635 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>MUL"
1636 {
1637 if (TARGET_LOONGSON_2EF)
1638 return "<d>multu.g\t%0,%1,%2";
1639 else if (TARGET_LOONGSON_EXT)
1640 return "gs<d>multu\t%0,%1,%2";
1641 else
1642 return "<d>mul\t%0,%1,%2";
1643 }
1644 [(set_attr "type" "imul3nc")
1645 (set_attr "mode" "<MODE>")])
1646
1647 (define_insn "mul<mode>3_mul3"
1648 [(set (match_operand:GPR 0 "register_operand" "=d,l")
1649 (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1650 (match_operand:GPR 2 "register_operand" "d,d")))
1651 (clobber (match_scratch:GPR 3 "=l,X"))]
1652 "ISA_HAS_<D>MUL3"
1653 {
1654 if (which_alternative == 1)
1655 return "<d>mult\t%1,%2";
1656 if (<MODE>mode == SImode && (TARGET_MIPS3900 || TARGET_MIPS5900))
1657 return "mult\t%0,%1,%2";
1658 return "<d>mul\t%0,%1,%2";
1659 }
1660 [(set_attr "type" "imul3,imul")
1661 (set_attr "mode" "<MODE>")])
1662
1663 ;; If a register gets allocated to LO, and we spill to memory, the reload
1664 ;; will include a move from LO to a GPR. Merge it into the multiplication
1665 ;; if it can set the GPR directly.
1666 ;;
1667 ;; Operand 0: LO
1668 ;; Operand 1: GPR (1st multiplication operand)
1669 ;; Operand 2: GPR (2nd multiplication operand)
1670 ;; Operand 3: GPR (destination)
1671 (define_peephole2
1672 [(parallel
1673 [(set (match_operand:SI 0 "lo_operand")
1674 (mult:SI (match_operand:SI 1 "d_operand")
1675 (match_operand:SI 2 "d_operand")))
1676 (clobber (scratch:SI))])
1677 (set (match_operand:SI 3 "d_operand")
1678 (match_dup 0))]
1679 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1680 [(parallel
1681 [(set (match_dup 3)
1682 (mult:SI (match_dup 1)
1683 (match_dup 2)))
1684 (clobber (match_dup 0))])])
1685
1686 (define_insn "mul<mode>3_internal"
1687 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1688 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1689 (match_operand:GPR 2 "register_operand" "d")))]
1690 "ISA_HAS_<D>MULT && !TARGET_FIX_R4000"
1691 "<d>mult\t%1,%2"
1692 [(set_attr "type" "imul")
1693 (set_attr "mode" "<MODE>")])
1694
1695 (define_insn "mul<mode>3_r4000"
1696 [(set (match_operand:GPR 0 "register_operand" "=d")
1697 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1698 (match_operand:GPR 2 "register_operand" "d")))
1699 (clobber (match_scratch:GPR 3 "=l"))]
1700 "ISA_HAS_<D>MULT && TARGET_FIX_R4000"
1701 "<d>mult\t%1,%2\;mflo\t%0"
1702 [(set_attr "type" "imul")
1703 (set_attr "mode" "<MODE>")
1704 (set_attr "insn_count" "2")])
1705
1706 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1707 ;; of "mult; mflo". They have the same latency, but the first form gives
1708 ;; us an extra cycle to compute the operands.
1709
1710 ;; Operand 0: LO
1711 ;; Operand 1: GPR (1st multiplication operand)
1712 ;; Operand 2: GPR (2nd multiplication operand)
1713 ;; Operand 3: GPR (destination)
1714 (define_peephole2
1715 [(set (match_operand:SI 0 "lo_operand")
1716 (mult:SI (match_operand:SI 1 "d_operand")
1717 (match_operand:SI 2 "d_operand")))
1718 (set (match_operand:SI 3 "d_operand")
1719 (match_dup 0))]
1720 "ISA_HAS_MACC && !ISA_HAS_MUL3"
1721 [(set (match_dup 0)
1722 (const_int 0))
1723 (parallel
1724 [(set (match_dup 0)
1725 (plus:SI (mult:SI (match_dup 1)
1726 (match_dup 2))
1727 (match_dup 0)))
1728 (set (match_dup 3)
1729 (plus:SI (mult:SI (match_dup 1)
1730 (match_dup 2))
1731 (match_dup 0)))])])
1732
1733 ;; Multiply-accumulate patterns
1734
1735 ;; This pattern is first matched by combine, which tries to use the
1736 ;; pattern wherever it can. We don't know until later whether it
1737 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1738 ;; so we need to keep both options open.
1739 ;;
1740 ;; The second alternative has a "?" marker because it is generally
1741 ;; one instruction more costly than the first alternative. This "?"
1742 ;; marker is enough to convey the relative costs to the register
1743 ;; allocator.
1744 ;;
1745 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1746 ;; reloads of the other operands, even though operands 4 and 5 need no
1747 ;; copy instructions. Reload therefore thinks that the second alternative
1748 ;; is two reloads more costly than the first. We add "*?*?" to the first
1749 ;; alternative as a counterweight.
1750 ;;
1751 ;; LRA simulates reload but the cost of reloading scratches is lower
1752 ;; than of the classic reload. For the time being, removing the counterweight
1753 ;; for LRA is more profitable.
1754 (define_insn "*mul_acc_si"
1755 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1756 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1757 (match_operand:SI 2 "register_operand" "d,d,d"))
1758 (match_operand:SI 3 "register_operand" "l,l,d")))
1759 (clobber (match_scratch:SI 4 "=X,X,l"))
1760 (clobber (match_scratch:SI 5 "=X,X,&d"))]
1761 "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1762 "@
1763 madd\t%1,%2
1764 madd\t%1,%2
1765 #"
1766 [(set_attr "type" "imadd")
1767 (set_attr "accum_in" "3")
1768 (set_attr "mode" "SI")
1769 (set_attr "insn_count" "1,1,2")
1770 (set (attr "enabled")
1771 (cond [(and (eq_attr "alternative" "0")
1772 (match_test "!mips_lra_flag"))
1773 (const_string "yes")
1774 (and (eq_attr "alternative" "1")
1775 (match_test "mips_lra_flag"))
1776 (const_string "yes")
1777 (eq_attr "alternative" "2")
1778 (const_string "yes")]
1779 (const_string "no")))])
1780
1781 ;; The same idea applies here. The middle alternative needs one less
1782 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1783 (define_insn "*mul_acc_si_r3900"
1784 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d*?,d?")
1785 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d,d")
1786 (match_operand:SI 2 "register_operand" "d,d,d,d"))
1787 (match_operand:SI 3 "register_operand" "l,l,l,d")))
1788 (clobber (match_scratch:SI 4 "=X,X,3,l"))
1789 (clobber (match_scratch:SI 5 "=X,X,X,&d"))]
1790 "TARGET_MIPS3900 && !TARGET_MIPS16"
1791 "@
1792 madd\t%1,%2
1793 madd\t%1,%2
1794 madd\t%0,%1,%2
1795 #"
1796 [(set_attr "type" "imadd")
1797 (set_attr "accum_in" "3")
1798 (set_attr "mode" "SI")
1799 (set_attr "insn_count" "1,1,1,2")
1800 (set (attr "enabled")
1801 (cond [(and (eq_attr "alternative" "0")
1802 (match_test "!mips_lra_flag"))
1803 (const_string "yes")
1804 (and (eq_attr "alternative" "1")
1805 (match_test "mips_lra_flag"))
1806 (const_string "yes")
1807 (eq_attr "alternative" "2,3")
1808 (const_string "yes")]
1809 (const_string "no")))])
1810
1811 ;; Split *mul_acc_si if both the source and destination accumulator
1812 ;; values are GPRs.
1813 (define_split
1814 [(set (match_operand:SI 0 "d_operand")
1815 (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1816 (match_operand:SI 2 "d_operand"))
1817 (match_operand:SI 3 "d_operand")))
1818 (clobber (match_operand:SI 4 "lo_operand"))
1819 (clobber (match_operand:SI 5 "d_operand"))]
1820 "reload_completed"
1821 [(parallel [(set (match_dup 5)
1822 (mult:SI (match_dup 1) (match_dup 2)))
1823 (clobber (match_dup 4))])
1824 (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1825 "")
1826
1827 (define_insn "*macc"
1828 [(set (match_operand:SI 0 "register_operand" "=l,d")
1829 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1830 (match_operand:SI 2 "register_operand" "d,d"))
1831 (match_operand:SI 3 "register_operand" "l,l")))
1832 (clobber (match_scratch:SI 4 "=X,3"))]
1833 "ISA_HAS_MACC"
1834 {
1835 if (which_alternative == 1)
1836 return "macc\t%0,%1,%2";
1837 else if (TARGET_MIPS5500)
1838 return "madd\t%1,%2";
1839 else
1840 /* The VR4130 assumes that there is a two-cycle latency between a macc
1841 that "writes" to $0 and an instruction that reads from it. We avoid
1842 this by assigning to $1 instead. */
1843 return "%[macc\t%@,%1,%2%]";
1844 }
1845 [(set_attr "type" "imadd")
1846 (set_attr "accum_in" "3")
1847 (set_attr "mode" "SI")])
1848
1849 (define_insn "*msac"
1850 [(set (match_operand:SI 0 "register_operand" "=l,d")
1851 (minus:SI (match_operand:SI 1 "register_operand" "l,l")
1852 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1853 (match_operand:SI 3 "register_operand" "d,d"))))
1854 (clobber (match_scratch:SI 4 "=X,1"))]
1855 "ISA_HAS_MSAC"
1856 {
1857 if (which_alternative == 1)
1858 return "msac\t%0,%2,%3";
1859 else if (TARGET_MIPS5500)
1860 return "msub\t%2,%3";
1861 else
1862 return "msac\t$0,%2,%3";
1863 }
1864 [(set_attr "type" "imadd")
1865 (set_attr "accum_in" "1")
1866 (set_attr "mode" "SI")])
1867
1868 ;; An msac-like instruction implemented using negation and a macc.
1869 (define_insn_and_split "*msac_using_macc"
1870 [(set (match_operand:SI 0 "register_operand" "=l,d")
1871 (minus:SI (match_operand:SI 1 "register_operand" "l,l")
1872 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1873 (match_operand:SI 3 "register_operand" "d,d"))))
1874 (clobber (match_scratch:SI 4 "=X,1"))
1875 (clobber (match_scratch:SI 5 "=d,d"))]
1876 "ISA_HAS_MACC && !ISA_HAS_MSAC"
1877 "#"
1878 "&& reload_completed"
1879 [(set (match_dup 5)
1880 (neg:SI (match_dup 3)))
1881 (parallel
1882 [(set (match_dup 0)
1883 (plus:SI (mult:SI (match_dup 2)
1884 (match_dup 5))
1885 (match_dup 1)))
1886 (clobber (match_dup 4))])]
1887 ""
1888 [(set_attr "type" "imadd")
1889 (set_attr "accum_in" "1")
1890 (set_attr "insn_count" "2")])
1891
1892 ;; Patterns generated by the define_peephole2 below.
1893
1894 (define_insn "*macc2"
1895 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1896 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1897 (match_operand:SI 2 "register_operand" "d"))
1898 (match_dup 0)))
1899 (set (match_operand:SI 3 "register_operand" "=d")
1900 (plus:SI (mult:SI (match_dup 1)
1901 (match_dup 2))
1902 (match_dup 0)))]
1903 "ISA_HAS_MACC && reload_completed"
1904 "macc\t%3,%1,%2"
1905 [(set_attr "type" "imadd")
1906 (set_attr "accum_in" "0")
1907 (set_attr "mode" "SI")])
1908
1909 (define_insn "*msac2"
1910 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1911 (minus:SI (match_dup 0)
1912 (mult:SI (match_operand:SI 1 "register_operand" "d")
1913 (match_operand:SI 2 "register_operand" "d"))))
1914 (set (match_operand:SI 3 "register_operand" "=d")
1915 (minus:SI (match_dup 0)
1916 (mult:SI (match_dup 1)
1917 (match_dup 2))))]
1918 "ISA_HAS_MSAC && reload_completed"
1919 "msac\t%3,%1,%2"
1920 [(set_attr "type" "imadd")
1921 (set_attr "accum_in" "0")
1922 (set_attr "mode" "SI")])
1923
1924 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1925 ;; Similarly msac.
1926 ;;
1927 ;; Operand 0: LO
1928 ;; Operand 1: macc/msac
1929 ;; Operand 2: GPR (destination)
1930 (define_peephole2
1931 [(parallel
1932 [(set (match_operand:SI 0 "lo_operand")
1933 (match_operand:SI 1 "macc_msac_operand"))
1934 (clobber (scratch:SI))])
1935 (set (match_operand:SI 2 "d_operand")
1936 (match_dup 0))]
1937 ""
1938 [(parallel [(set (match_dup 0)
1939 (match_dup 1))
1940 (set (match_dup 2)
1941 (match_dup 1))])])
1942
1943 ;; When we have a three-address multiplication instruction, it should
1944 ;; be faster to do a separate multiply and add, rather than moving
1945 ;; something into LO in order to use a macc instruction.
1946 ;;
1947 ;; This peephole needs a scratch register to cater for the case when one
1948 ;; of the multiplication operands is the same as the destination.
1949 ;;
1950 ;; Operand 0: GPR (scratch)
1951 ;; Operand 1: LO
1952 ;; Operand 2: GPR (addend)
1953 ;; Operand 3: GPR (destination)
1954 ;; Operand 4: macc/msac
1955 ;; Operand 5: new multiplication
1956 ;; Operand 6: new addition/subtraction
1957 (define_peephole2
1958 [(match_scratch:SI 0 "d")
1959 (set (match_operand:SI 1 "lo_operand")
1960 (match_operand:SI 2 "d_operand"))
1961 (match_dup 0)
1962 (parallel
1963 [(set (match_operand:SI 3 "d_operand")
1964 (match_operand:SI 4 "macc_msac_operand"))
1965 (clobber (match_dup 1))])]
1966 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1967 [(parallel [(set (match_dup 0)
1968 (match_dup 5))
1969 (clobber (match_dup 1))])
1970 (set (match_dup 3)
1971 (match_dup 6))]
1972 {
1973 operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1974 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1975 operands[2], operands[0]);
1976 })
1977
1978 ;; Same as above, except LO is the initial target of the macc.
1979 ;;
1980 ;; Operand 0: GPR (scratch)
1981 ;; Operand 1: LO
1982 ;; Operand 2: GPR (addend)
1983 ;; Operand 3: macc/msac
1984 ;; Operand 4: GPR (destination)
1985 ;; Operand 5: new multiplication
1986 ;; Operand 6: new addition/subtraction
1987 (define_peephole2
1988 [(match_scratch:SI 0 "d")
1989 (set (match_operand:SI 1 "lo_operand")
1990 (match_operand:SI 2 "d_operand"))
1991 (match_dup 0)
1992 (parallel
1993 [(set (match_dup 1)
1994 (match_operand:SI 3 "macc_msac_operand"))
1995 (clobber (scratch:SI))])
1996 (match_dup 0)
1997 (set (match_operand:SI 4 "d_operand")
1998 (match_dup 1))]
1999 "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
2000 [(parallel [(set (match_dup 0)
2001 (match_dup 5))
2002 (clobber (match_dup 1))])
2003 (set (match_dup 4)
2004 (match_dup 6))]
2005 {
2006 operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
2007 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2008 operands[2], operands[0]);
2009 })
2010
2011 ;; See the comment above *mul_add_si for details.
2012 (define_insn "*mul_sub_si"
2013 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
2014 (minus:SI (match_operand:SI 1 "register_operand" "l,l,d")
2015 (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
2016 (match_operand:SI 3 "register_operand" "d,d,d"))))
2017 (clobber (match_scratch:SI 4 "=X,X,l"))
2018 (clobber (match_scratch:SI 5 "=X,X,&d"))]
2019 "GENERATE_MADD_MSUB"
2020 "@
2021 msub\t%2,%3
2022 msub\t%2,%3
2023 #"
2024 [(set_attr "type" "imadd")
2025 (set_attr "accum_in" "1")
2026 (set_attr "mode" "SI")
2027 (set_attr "insn_count" "1,1,2")
2028 (set (attr "enabled")
2029 (cond [(and (eq_attr "alternative" "0")
2030 (match_test "!mips_lra_flag"))
2031 (const_string "yes")
2032 (and (eq_attr "alternative" "1")
2033 (match_test "mips_lra_flag"))
2034 (const_string "yes")
2035 (eq_attr "alternative" "2")
2036 (const_string "yes")]
2037 (const_string "no")))])
2038
2039 ;; Split *mul_sub_si if both the source and destination accumulator
2040 ;; values are GPRs.
2041 (define_split
2042 [(set (match_operand:SI 0 "d_operand")
2043 (minus:SI (match_operand:SI 1 "d_operand")
2044 (mult:SI (match_operand:SI 2 "d_operand")
2045 (match_operand:SI 3 "d_operand"))))
2046 (clobber (match_operand:SI 4 "lo_operand"))
2047 (clobber (match_operand:SI 5 "d_operand"))]
2048 "reload_completed"
2049 [(parallel [(set (match_dup 5)
2050 (mult:SI (match_dup 2) (match_dup 3)))
2051 (clobber (match_dup 4))])
2052 (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
2053 "")
2054
2055 (define_insn "*muls"
2056 [(set (match_operand:SI 0 "register_operand" "=l,d")
2057 (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
2058 (match_operand:SI 2 "register_operand" "d,d"))))
2059 (clobber (match_scratch:SI 3 "=X,l"))]
2060 "ISA_HAS_MULS"
2061 "@
2062 muls\t$0,%1,%2
2063 muls\t%0,%1,%2"
2064 [(set_attr "type" "imul,imul3")
2065 (set_attr "mode" "SI")])
2066
2067 (define_expand "<u>mulsidi3"
2068 [(set (match_operand:DI 0 "register_operand")
2069 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2070 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2071 "mips_mulsidi3_gen_fn (<CODE>) != NULL"
2072 {
2073 mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
2074 emit_insn (fn (operands[0], operands[1], operands[2]));
2075 DONE;
2076 })
2077
2078 (define_expand "<u>mulsidi3_32bit_r6"
2079 [(set (match_operand:DI 0 "register_operand")
2080 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2081 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2082 "!TARGET_64BIT && ISA_HAS_R6MUL"
2083 {
2084 rtx dest = gen_reg_rtx (DImode);
2085 rtx low = mips_subword (dest, 0);
2086 rtx high = mips_subword (dest, 1);
2087
2088 emit_insn (gen_mulsi3_mul3_nohilo (low, operands[1], operands[2]));
2089 emit_insn (gen_<su>mulsi3_highpart_r6 (high, operands[1], operands[2]));
2090
2091 emit_move_insn (mips_subword (operands[0], 0), low);
2092 emit_move_insn (mips_subword (operands[0], 1), high);
2093 DONE;
2094 })
2095
2096 (define_expand "<u>mulsidi3_32bit_mips16"
2097 [(set (match_operand:DI 0 "register_operand")
2098 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2099 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2100 "!TARGET_64BIT && TARGET_MIPS16"
2101 {
2102 rtx hilo;
2103
2104 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2105 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2106 emit_move_insn (operands[0], hilo);
2107 DONE;
2108 })
2109
2110 ;; As well as being named patterns, these instructions are used by the
2111 ;; __builtin_mips_mult<u>() functions. We must always make those functions
2112 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2113 (define_insn "<u>mulsidi3_32bit"
2114 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2115 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2116 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2117 "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP) && ISA_HAS_MULT"
2118 {
2119 if (ISA_HAS_DSP_MULT)
2120 return "mult<u>\t%q0,%1,%2";
2121 else
2122 return "mult<u>\t%1,%2";
2123 }
2124 [(set_attr "type" "imul")
2125 (set_attr "mode" "SI")])
2126
2127 (define_insn "<u>mulsidi3_32bit_r4000"
2128 [(set (match_operand:DI 0 "register_operand" "=d")
2129 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2130 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2131 (clobber (match_scratch:DI 3 "=x"))]
2132 "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP && ISA_HAS_MULT"
2133 "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2134 [(set_attr "type" "imul")
2135 (set_attr "mode" "SI")
2136 (set_attr "insn_count" "3")])
2137
2138 (define_insn_and_split "<u>mulsidi3_64bit"
2139 [(set (match_operand:DI 0 "register_operand" "=d")
2140 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2141 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2142 (clobber (match_scratch:TI 3 "=x"))
2143 (clobber (match_scratch:DI 4 "=d"))]
2144 "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3
2145 && !TARGET_MIPS16 && ISA_HAS_MULT"
2146 "#"
2147 "&& reload_completed"
2148 [(const_int 0)]
2149 {
2150 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2151 operands[2], operands[4]));
2152 DONE;
2153 }
2154 [(set_attr "type" "imul")
2155 (set_attr "mode" "SI")
2156 (set (attr "insn_count")
2157 (if_then_else (match_test "ISA_HAS_EXT_INS")
2158 (const_int 4)
2159 (const_int 7)))])
2160
2161 (define_expand "<u>mulsidi3_64bit_mips16"
2162 [(set (match_operand:DI 0 "register_operand")
2163 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2164 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2165 "TARGET_64BIT && TARGET_MIPS16"
2166 {
2167 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2168 operands[2], gen_reg_rtx (DImode)));
2169 DONE;
2170 })
2171
2172 (define_expand "<u>mulsidi3_64bit_split"
2173 [(set (match_operand:DI 0 "register_operand")
2174 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2175 (any_extend:DI (match_operand:SI 2 "register_operand"))))
2176 (clobber (match_operand:DI 3 "register_operand"))]
2177 ""
2178 {
2179 rtx hilo;
2180
2181 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2182 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2183
2184 emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
2185 emit_insn (gen_mfhidi_ti (operands[3], hilo));
2186
2187 if (ISA_HAS_EXT_INS)
2188 emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
2189 operands[3]));
2190 else
2191 {
2192 /* Zero-extend the low part. */
2193 mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
2194 mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
2195
2196 /* Shift the high part into place. */
2197 mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
2198
2199 /* OR the two halves together. */
2200 mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
2201 }
2202 DONE;
2203 })
2204
2205 (define_insn "<u>mulsidi3_64bit_hilo"
2206 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2207 (unspec:TI
2208 [(mult:DI
2209 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2210 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
2211 UNSPEC_SET_HILO))]
2212 "TARGET_64BIT && !TARGET_FIX_R4000"
2213 "mult<u>\t%1,%2"
2214 [(set_attr "type" "imul")
2215 (set_attr "mode" "SI")])
2216
2217 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
2218 (define_insn "mulsidi3_64bit_dmul"
2219 [(set (match_operand:DI 0 "register_operand" "=d")
2220 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2221 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2222 (clobber (match_scratch:DI 3 "=l"))]
2223 "ISA_HAS_DMUL3"
2224 "dmul\t%0,%1,%2"
2225 [(set_attr "type" "imul3")
2226 (set_attr "mode" "DI")])
2227
2228 (define_insn "mulsidi3_64bit_r6dmul"
2229 [(set (match_operand:DI 0 "register_operand" "=d")
2230 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2231 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2232 "ISA_HAS_R6DMUL"
2233 "dmul\t%0,%1,%2"
2234 [(set_attr "type" "imul3nc")
2235 (set_attr "mode" "DI")])
2236
2237 ;; Widening multiply with negation.
2238 (define_insn "*muls<u>_di"
2239 [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2240 (neg:DI
2241 (mult:DI
2242 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2243 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2244 "!TARGET_64BIT && ISA_HAS_MULS"
2245 "muls<u>\t$0,%1,%2"
2246 [(set_attr "type" "imul")
2247 (set_attr "mode" "SI")])
2248
2249 ;; As well as being named patterns, these instructions are used by the
2250 ;; __builtin_mips_msub<u>() functions. We must always make those functions
2251 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2252 ;;
2253 ;; This leads to a slight inconsistency. We honor any tuning overrides
2254 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2255 ;; even if !ISA_HAS_DSP_MULT.
2256 (define_insn "<u>msubsidi4"
2257 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2258 (minus:DI
2259 (match_operand:DI 3 "muldiv_target_operand" "0")
2260 (mult:DI
2261 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2262 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2263 "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2264 {
2265 if (ISA_HAS_DSP_MULT)
2266 return "msub<u>\t%q0,%1,%2";
2267 else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2268 return "msub<u>\t%1,%2";
2269 else
2270 return "msac<u>\t$0,%1,%2";
2271 }
2272 [(set_attr "type" "imadd")
2273 (set_attr "accum_in" "3")
2274 (set_attr "mode" "SI")])
2275
2276 ;; _highpart patterns
2277
2278 (define_expand "<su>mulsi3_highpart"
2279 [(set (match_operand:SI 0 "register_operand")
2280 (truncate:SI
2281 (lshiftrt:DI
2282 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2283 (any_extend:DI (match_operand:SI 2 "register_operand")))
2284 (const_int 32))))]
2285 ""
2286 {
2287 if (ISA_HAS_MULHI)
2288 emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2289 operands[1],
2290 operands[2]));
2291 else if (TARGET_MIPS16)
2292 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2293 operands[2]));
2294 else if (ISA_HAS_R6MUL)
2295 emit_insn (gen_<su>mulsi3_highpart_r6 (operands[0], operands[1],
2296 operands[2]));
2297 else
2298 emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2299 operands[2]));
2300 DONE;
2301 })
2302
2303 (define_insn "<su>mulsi3_highpart_r6"
2304 [(set (match_operand:SI 0 "register_operand" "=d")
2305 (truncate:SI
2306 (lshiftrt:DI
2307 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2308 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2309 (const_int 32))))]
2310 "ISA_HAS_R6MUL"
2311 "muh<u>\t%0,%1,%2"
2312 [(set_attr "type" "imul3nc")
2313 (set_attr "mode" "SI")])
2314
2315 (define_insn_and_split "<su>mulsi3_highpart_internal"
2316 [(set (match_operand:SI 0 "register_operand" "=d")
2317 (truncate:SI
2318 (lshiftrt:DI
2319 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2320 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2321 (const_int 32))))
2322 (clobber (match_scratch:SI 3 "=l"))]
2323 "ISA_HAS_MULT && !ISA_HAS_MULHI && !TARGET_MIPS16"
2324 { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2325 "&& reload_completed && !TARGET_FIX_R4000"
2326 [(const_int 0)]
2327 {
2328 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2329 operands[2]));
2330 DONE;
2331 }
2332 [(set_attr "type" "imul")
2333 (set_attr "mode" "SI")
2334 (set_attr "insn_count" "2")])
2335
2336 (define_expand "<su>mulsi3_highpart_split"
2337 [(set (match_operand:SI 0 "register_operand")
2338 (truncate:SI
2339 (lshiftrt:DI
2340 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2341 (any_extend:DI (match_operand:SI 2 "register_operand")))
2342 (const_int 32))))]
2343 ""
2344 {
2345 rtx hilo;
2346
2347 if (TARGET_64BIT)
2348 {
2349 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2350 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2351 emit_insn (gen_mfhisi_ti (operands[0], hilo));
2352 }
2353 else
2354 {
2355 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2356 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2357 emit_insn (gen_mfhisi_di (operands[0], hilo));
2358 }
2359 DONE;
2360 })
2361
2362 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2363 [(set (match_operand:SI 0 "register_operand" "=d")
2364 (truncate:SI
2365 (lshiftrt:DI
2366 (mult:DI
2367 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2368 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2369 (const_int 32))))
2370 (clobber (match_scratch:SI 3 "=l"))]
2371 "ISA_HAS_MULHI"
2372 "mulhi<u>\t%0,%1,%2"
2373 [(set_attr "type" "imul3")
2374 (set_attr "mode" "SI")])
2375
2376 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2377 [(set (match_operand:SI 0 "register_operand" "=d")
2378 (truncate:SI
2379 (lshiftrt:DI
2380 (neg:DI
2381 (mult:DI
2382 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2383 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2384 (const_int 32))))
2385 (clobber (match_scratch:SI 3 "=l"))]
2386 "ISA_HAS_MULHI"
2387 "mulshi<u>\t%0,%1,%2"
2388 [(set_attr "type" "imul3")
2389 (set_attr "mode" "SI")])
2390
2391 ;; Disable unsigned multiplication for -mfix-vr4120. This is for VR4120
2392 ;; errata MD(0), which says that dmultu does not always produce the
2393 ;; correct result.
2394 (define_expand "<su>muldi3_highpart"
2395 [(set (match_operand:DI 0 "register_operand")
2396 (truncate:DI
2397 (lshiftrt:TI
2398 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2399 (any_extend:TI (match_operand:DI 2 "register_operand")))
2400 (const_int 64))))]
2401 "ISA_HAS_R6DMUL
2402 || (ISA_HAS_DMULT
2403 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2404 {
2405 if (TARGET_MIPS16)
2406 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2407 operands[2]));
2408 else if (ISA_HAS_R6DMUL)
2409 emit_insn (gen_<su>muldi3_highpart_r6 (operands[0], operands[1],
2410 operands[2]));
2411 else
2412 emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2413 operands[2]));
2414 DONE;
2415 })
2416
2417 (define_insn "<su>muldi3_highpart_r6"
2418 [(set (match_operand:DI 0 "register_operand" "=d")
2419 (truncate:DI
2420 (lshiftrt:TI
2421 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2422 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2423 (const_int 64))))]
2424 "ISA_HAS_R6DMUL"
2425 "dmuh<u>\t%0,%1,%2"
2426 [(set_attr "type" "imul3nc")
2427 (set_attr "mode" "DI")])
2428
2429 (define_insn_and_split "<su>muldi3_highpart_internal"
2430 [(set (match_operand:DI 0 "register_operand" "=d")
2431 (truncate:DI
2432 (lshiftrt:TI
2433 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2434 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2435 (const_int 64))))
2436 (clobber (match_scratch:DI 3 "=l"))]
2437 "ISA_HAS_DMULT
2438 && !TARGET_MIPS16
2439 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2440 { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2441 "&& reload_completed && !TARGET_FIX_R4000"
2442 [(const_int 0)]
2443 {
2444 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2445 operands[2]));
2446 DONE;
2447 }
2448 [(set_attr "type" "imul")
2449 (set_attr "mode" "DI")
2450 (set_attr "insn_count" "2")])
2451
2452 (define_expand "<su>muldi3_highpart_split"
2453 [(set (match_operand:DI 0 "register_operand")
2454 (truncate:DI
2455 (lshiftrt:TI
2456 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2457 (any_extend:TI (match_operand:DI 2 "register_operand")))
2458 (const_int 64))))]
2459 ""
2460 {
2461 rtx hilo;
2462
2463 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2464 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2465 emit_insn (gen_mfhidi_ti (operands[0], hilo));
2466 DONE;
2467 })
2468
2469 (define_expand "<u>mulditi3"
2470 [(set (match_operand:TI 0 "register_operand")
2471 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2472 (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2473 "ISA_HAS_R6DMUL
2474 || (ISA_HAS_DMULT
2475 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2476 {
2477 rtx hilo, hi, lo;
2478
2479 if (TARGET_MIPS16)
2480 {
2481 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2482 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2483 emit_move_insn (operands[0], hilo);
2484 }
2485 else if (TARGET_FIX_R4000)
2486 emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2487 else if (ISA_HAS_DMULT)
2488 emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2489 operands[2]));
2490 else
2491 {
2492 hi = mips_subword (operands[0], 1);
2493 lo = mips_subword (operands[0], 0);
2494 emit_insn (gen_muldi3_mul3_nohilo (lo, operands[1], operands[2]));
2495 emit_insn (gen_<su>muldi3_highpart_r6 (hi, operands[1], operands[2]));
2496 }
2497 DONE;
2498 })
2499
2500 (define_insn "<u>mulditi3_internal"
2501 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2502 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2503 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2504 "ISA_HAS_DMULT
2505 && !TARGET_FIX_R4000
2506 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2507 "dmult<u>\t%1,%2"
2508 [(set_attr "type" "imul")
2509 (set_attr "mode" "DI")])
2510
2511 (define_insn "<u>mulditi3_r4000"
2512 [(set (match_operand:TI 0 "register_operand" "=d")
2513 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2514 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2515 (clobber (match_scratch:TI 3 "=x"))]
2516 "ISA_HAS_DMULT
2517 && TARGET_FIX_R4000
2518 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2519 "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2520 [(set_attr "type" "imul")
2521 (set_attr "mode" "DI")
2522 (set_attr "insn_count" "3")])
2523
2524 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2525 ;; instruction. The HI/LO registers are used as a 64-bit accumulator.
2526
2527 (define_insn "madsi"
2528 [(set (match_operand:SI 0 "register_operand" "+l")
2529 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2530 (match_operand:SI 2 "register_operand" "d"))
2531 (match_dup 0)))]
2532 "TARGET_MAD"
2533 "mad\t%1,%2"
2534 [(set_attr "type" "imadd")
2535 (set_attr "accum_in" "0")
2536 (set_attr "mode" "SI")])
2537
2538 ;; See the comment above <u>msubsidi4 for the relationship between
2539 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2540 (define_insn "<u>maddsidi4"
2541 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2542 (plus:DI
2543 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2544 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2545 (match_operand:DI 3 "muldiv_target_operand" "0")))]
2546 "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2547 && !TARGET_64BIT"
2548 {
2549 if (TARGET_MAD)
2550 return "mad<u>\t%1,%2";
2551 else if (ISA_HAS_DSP_MULT)
2552 return "madd<u>\t%q0,%1,%2";
2553 else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2554 return "madd<u>\t%1,%2";
2555 else
2556 /* See comment in *macc. */
2557 return "%[macc<u>\t%@,%1,%2%]";
2558 }
2559 [(set_attr "type" "imadd")
2560 (set_attr "accum_in" "3")
2561 (set_attr "mode" "SI")])
2562
2563 ;; Floating point multiply accumulate instructions.
2564
2565 (define_expand "fma<mode>4"
2566 [(set (match_operand:ANYF 0 "register_operand")
2567 (fma:ANYF (match_operand:ANYF 1 "register_operand")
2568 (match_operand:ANYF 2 "register_operand")
2569 (match_operand:ANYF 3 "register_operand")))]
2570 "ISA_HAS_FUSED_MADDF || ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4")
2571
2572 (define_insn "*fma<mode>4_madd3"
2573 [(set (match_operand:ANYF 0 "register_operand" "=f")
2574 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2575 (match_operand:ANYF 2 "register_operand" "f")
2576 (match_operand:ANYF 3 "register_operand" "0")))]
2577 "ISA_HAS_FUSED_MADD3"
2578 "madd.<fmt>\t%0,%1,%2"
2579 [(set_attr "type" "fmadd")
2580 (set_attr "mode" "<UNITMODE>")])
2581
2582 (define_insn "*fma<mode>4_madd4"
2583 [(set (match_operand:ANYF 0 "register_operand" "=f")
2584 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2585 (match_operand:ANYF 2 "register_operand" "f")
2586 (match_operand:ANYF 3 "register_operand" "f")))]
2587 "ISA_HAS_FUSED_MADD4"
2588 "madd.<fmt>\t%0,%3,%1,%2"
2589 [(set_attr "type" "fmadd")
2590 (set_attr "mode" "<UNITMODE>")])
2591
2592 (define_insn "*fma<mode>4_maddf"
2593 [(set (match_operand:ANYF 0 "register_operand" "=f")
2594 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2595 (match_operand:ANYF 2 "register_operand" "f")
2596 (match_operand:ANYF 3 "register_operand" "0")))]
2597 "ISA_HAS_FUSED_MADDF"
2598 "maddf.<fmt>\t%0,%1,%2"
2599 [(set_attr "type" "fmadd")
2600 (set_attr "mode" "<UNITMODE>")])
2601
2602 ;; The fms, fnma, and fnms instructions can be used even when HONOR_NANS
2603 ;; is true because while IEEE 754-2008 requires the negate operation to
2604 ;; negate the sign of a NAN and the MIPS neg instruction does not do this,
2605 ;; the fma part of the instruction has no requirement on how the sign of
2606 ;; a NAN is handled and so the final sign bit of the entire operation is
2607 ;; undefined.
2608
2609 (define_expand "fms<mode>4"
2610 [(set (match_operand:ANYF 0 "register_operand")
2611 (fma:ANYF (match_operand:ANYF 1 "register_operand")
2612 (match_operand:ANYF 2 "register_operand")
2613 (neg:ANYF (match_operand:ANYF 3 "register_operand"))))]
2614 "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)")
2615
2616 (define_insn "*fms<mode>4_msub3"
2617 [(set (match_operand:ANYF 0 "register_operand" "=f")
2618 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2619 (match_operand:ANYF 2 "register_operand" "f")
2620 (neg:ANYF (match_operand:ANYF 3 "register_operand" "0"))))]
2621 "ISA_HAS_FUSED_MADD3"
2622 "msub.<fmt>\t%0,%1,%2"
2623 [(set_attr "type" "fmadd")
2624 (set_attr "mode" "<UNITMODE>")])
2625
2626 (define_insn "*fms<mode>4_msub4"
2627 [(set (match_operand:ANYF 0 "register_operand" "=f")
2628 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2629 (match_operand:ANYF 2 "register_operand" "f")
2630 (neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
2631 "ISA_HAS_FUSED_MADD4"
2632 "msub.<fmt>\t%0,%3,%1,%2"
2633 [(set_attr "type" "fmadd")
2634 (set_attr "mode" "<UNITMODE>")])
2635
2636 ;; fnma is defined in GCC as (fma (neg op1) op2 op3)
2637 ;; (-op1 * op2) + op3 ==> -(op1 * op2) + op3 ==> -((op1 * op2) - op3)
2638 ;; The mips nmsub instructions implement -((op1 * op2) - op3)
2639 ;; This transformation means we may return the wrong signed zero
2640 ;; so we check HONOR_SIGNED_ZEROS.
2641
2642 (define_expand "fnma<mode>4"
2643 [(set (match_operand:ANYF 0 "register_operand")
2644 (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand"))
2645 (match_operand:ANYF 2 "register_operand")
2646 (match_operand:ANYF 3 "register_operand")))]
2647 "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)
2648 && !HONOR_SIGNED_ZEROS (<MODE>mode)")
2649
2650 (define_insn "*fnma<mode>4_nmsub3"
2651 [(set (match_operand:ANYF 0 "register_operand" "=f")
2652 (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2653 (match_operand:ANYF 2 "register_operand" "f")
2654 (match_operand:ANYF 3 "register_operand" "0")))]
2655 "ISA_HAS_FUSED_MADD3 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2656 "nmsub.<fmt>\t%0,%1,%2"
2657 [(set_attr "type" "fmadd")
2658 (set_attr "mode" "<UNITMODE>")])
2659
2660 (define_insn "*fnma<mode>4_nmsub4"
2661 [(set (match_operand:ANYF 0 "register_operand" "=f")
2662 (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2663 (match_operand:ANYF 2 "register_operand" "f")
2664 (match_operand:ANYF 3 "register_operand" "f")))]
2665 "ISA_HAS_FUSED_MADD4 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2666 "nmsub.<fmt>\t%0,%3,%1,%2"
2667 [(set_attr "type" "fmadd")
2668 (set_attr "mode" "<UNITMODE>")])
2669
2670 ;; fnms is defined as: (fma (neg op1) op2 (neg op3))
2671 ;; ((-op1) * op2) - op3 ==> -(op1 * op2) - op3 ==> -((op1 * op2) + op3)
2672 ;; The mips nmadd instructions implement -((op1 * op2) + op3)
2673 ;; This transformation means we may return the wrong signed zero
2674 ;; so we check HONOR_SIGNED_ZEROS.
2675
2676 (define_expand "fnms<mode>4"
2677 [(set (match_operand:ANYF 0 "register_operand")
2678 (fma:ANYF
2679 (neg:ANYF (match_operand:ANYF 1 "register_operand"))
2680 (match_operand:ANYF 2 "register_operand")
2681 (neg:ANYF (match_operand:ANYF 3 "register_operand"))))]
2682 "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)
2683 && !HONOR_SIGNED_ZEROS (<MODE>mode)")
2684
2685 (define_insn "*fnms<mode>4_nmadd3"
2686 [(set (match_operand:ANYF 0 "register_operand" "=f")
2687 (fma:ANYF
2688 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2689 (match_operand:ANYF 2 "register_operand" "f")
2690 (neg:ANYF (match_operand:ANYF 3 "register_operand" "0"))))]
2691 "ISA_HAS_FUSED_MADD3 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2692 "nmadd.<fmt>\t%0,%1,%2"
2693 [(set_attr "type" "fmadd")
2694 (set_attr "mode" "<UNITMODE>")])
2695
2696 (define_insn "*fnms<mode>4_nmadd4"
2697 [(set (match_operand:ANYF 0 "register_operand" "=f")
2698 (fma:ANYF
2699 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2700 (match_operand:ANYF 2 "register_operand" "f")
2701 (neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
2702 "ISA_HAS_FUSED_MADD4 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2703 "nmadd.<fmt>\t%0,%3,%1,%2"
2704 [(set_attr "type" "fmadd")
2705 (set_attr "mode" "<UNITMODE>")])
2706
2707 ;; Non-fused Floating point multiply accumulate instructions.
2708
2709 ;; These instructions are not fused and round in between the multiply
2710 ;; and the add (or subtract) so they are equivalent to the separate
2711 ;; multiply and add/sub instructions.
2712
2713 (define_insn "*madd4<mode>"
2714 [(set (match_operand:ANYF 0 "register_operand" "=f")
2715 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2716 (match_operand:ANYF 2 "register_operand" "f"))
2717 (match_operand:ANYF 3 "register_operand" "f")))]
2718 "ISA_HAS_UNFUSED_MADD4"
2719 "madd.<fmt>\t%0,%3,%1,%2"
2720 [(set_attr "type" "fmadd")
2721 (set_attr "mode" "<UNITMODE>")])
2722
2723 (define_insn "*msub4<mode>"
2724 [(set (match_operand:ANYF 0 "register_operand" "=f")
2725 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2726 (match_operand:ANYF 2 "register_operand" "f"))
2727 (match_operand:ANYF 3 "register_operand" "f")))]
2728 "ISA_HAS_UNFUSED_MADD4"
2729 "msub.<fmt>\t%0,%3,%1,%2"
2730 [(set_attr "type" "fmadd")
2731 (set_attr "mode" "<UNITMODE>")])
2732
2733 ;; Like with the fused fms, fnma, and fnms instructions, these unfused
2734 ;; instructions can be used even if HONOR_NANS is set because while
2735 ;; IEEE 754-2008 requires the negate operation to negate the sign of a
2736 ;; NAN and the MIPS neg instruction does not do this, the multiply and
2737 ;; add (or subtract) part of the instruction has no requirement on how
2738 ;; the sign of a NAN is handled and so the final sign bit of the entire
2739 ;; operation is undefined.
2740
2741 (define_insn "*nmadd4<mode>"
2742 [(set (match_operand:ANYF 0 "register_operand" "=f")
2743 (neg:ANYF (plus:ANYF
2744 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2745 (match_operand:ANYF 2 "register_operand" "f"))
2746 (match_operand:ANYF 3 "register_operand" "f"))))]
2747 "ISA_HAS_UNFUSED_MADD4"
2748 "nmadd.<fmt>\t%0,%3,%1,%2"
2749 [(set_attr "type" "fmadd")
2750 (set_attr "mode" "<UNITMODE>")])
2751
2752 (define_insn "*nmsub4<mode>"
2753 [(set (match_operand:ANYF 0 "register_operand" "=f")
2754 (neg:ANYF (minus:ANYF
2755 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2756 (match_operand:ANYF 2 "register_operand" "f"))
2757 (match_operand:ANYF 3 "register_operand" "f"))))]
2758 "ISA_HAS_UNFUSED_MADD4"
2759 "nmsub.<fmt>\t%0,%3,%1,%2"
2760 [(set_attr "type" "fmadd")
2761 (set_attr "mode" "<UNITMODE>")])
2762
2763 ;; Fast-math Non-fused Floating point multiply accumulate instructions.
2764
2765 ;; These instructions are not fused but the expressions they match are
2766 ;; not exactly what the instruction implements in the sense that they
2767 ;; may not generate the properly signed zeros.
2768
2769 ;; This instruction recognizes ((-op1) * op2) - op3 and generates an
2770 ;; nmadd which is really -((op1 * op2) + op3). They are equivalent
2771 ;; except for the sign bit when the result is zero or NaN.
2772
2773 (define_insn "*nmadd4<mode>_fastmath"
2774 [(set (match_operand:ANYF 0 "register_operand" "=f")
2775 (minus:ANYF
2776 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2777 (match_operand:ANYF 2 "register_operand" "f"))
2778 (match_operand:ANYF 3 "register_operand" "f")))]
2779 "ISA_HAS_UNFUSED_MADD4
2780 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2781 "nmadd.<fmt>\t%0,%3,%1,%2"
2782 [(set_attr "type" "fmadd")
2783 (set_attr "mode" "<UNITMODE>")])
2784
2785 ;; This instruction recognizes (op1 - (op2 * op3) and generates an
2786 ;; nmsub which is really -((op2 * op3) - op1). They are equivalent
2787 ;; except for the sign bit when the result is zero or NaN.
2788
2789 (define_insn "*nmsub4<mode>_fastmath"
2790 [(set (match_operand:ANYF 0 "register_operand" "=f")
2791 (minus:ANYF
2792 (match_operand:ANYF 1 "register_operand" "f")
2793 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2794 (match_operand:ANYF 3 "register_operand" "f"))))]
2795 "ISA_HAS_UNFUSED_MADD4
2796 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2797 "nmsub.<fmt>\t%0,%1,%2,%3"
2798 [(set_attr "type" "fmadd")
2799 (set_attr "mode" "<UNITMODE>")])
2800
2801 ;;
2802 ;; ....................
2803 ;;
2804 ;; DIVISION and REMAINDER
2805 ;;
2806 ;; ....................
2807 ;;
2808
2809 (define_expand "div<mode>3"
2810 [(set (match_operand:ANYF 0 "register_operand")
2811 (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2812 (match_operand:ANYF 2 "register_operand")))]
2813 "<divide_condition>"
2814 {
2815 if (const_1_operand (operands[1], <MODE>mode))
2816 if (!(ISA_HAS_FP_RECIP_RSQRT (<MODE>mode)
2817 && flag_unsafe_math_optimizations))
2818 operands[1] = force_reg (<MODE>mode, operands[1]);
2819 })
2820
2821 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2822 ;;
2823 ;; If an mfc1 or dmfc1 happens to access the floating point register
2824 ;; file at the same time a long latency operation (div, sqrt, recip,
2825 ;; sqrt) iterates an intermediate result back through the floating
2826 ;; point register file bypass, then instead returning the correct
2827 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2828 ;; result of the long latency operation.
2829 ;;
2830 ;; The workaround is to insert an unconditional 'mov' from/to the
2831 ;; long latency op destination register.
2832
2833 (define_insn "*div<mode>3"
2834 [(set (match_operand:ANYF 0 "register_operand" "=f")
2835 (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2836 (match_operand:ANYF 2 "register_operand" "f")))]
2837 "<divide_condition>"
2838 {
2839 if (TARGET_FIX_SB1)
2840 return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2841 else
2842 return "div.<fmt>\t%0,%1,%2";
2843 }
2844 [(set_attr "type" "fdiv")
2845 (set_attr "mode" "<UNITMODE>")
2846 (set (attr "insn_count")
2847 (if_then_else (match_test "TARGET_FIX_SB1")
2848 (const_int 2)
2849 (const_int 1)))])
2850
2851 (define_insn "*recip<mode>3"
2852 [(set (match_operand:ANYF 0 "register_operand" "=f")
2853 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2854 (match_operand:ANYF 2 "register_operand" "f")))]
2855 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2856 {
2857 if (TARGET_FIX_SB1)
2858 return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2859 else
2860 return "recip.<fmt>\t%0,%2";
2861 }
2862 [(set_attr "type" "frdiv")
2863 (set_attr "mode" "<UNITMODE>")
2864 (set (attr "insn_count")
2865 (if_then_else (match_test "TARGET_FIX_SB1")
2866 (const_int 2)
2867 (const_int 1)))])
2868
2869 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2870 ;; with negative operands. We use special libgcc functions instead.
2871 (define_expand "divmod<mode>4"
2872 [(parallel
2873 [(set (match_operand:GPR 0 "register_operand")
2874 (div:GPR (match_operand:GPR 1 "register_operand")
2875 (match_operand:GPR 2 "register_operand")))
2876 (set (match_operand:GPR 3 "register_operand")
2877 (mod:GPR (match_dup 1)
2878 (match_dup 2)))])]
2879 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2880 {
2881 if (TARGET_MIPS16)
2882 {
2883 rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2884 emit_insn (gen_divmod<mode>4_mips16 (operands[0], operands[1],
2885 operands[2], operands[3], lo));
2886 DONE;
2887 }
2888 })
2889
2890 (define_insn_and_split "*divmod<mode>4"
2891 [(set (match_operand:GPR 0 "register_operand" "=l")
2892 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2893 (match_operand:GPR 2 "register_operand" "d")))
2894 (set (match_operand:GPR 3 "register_operand" "=d")
2895 (mod:GPR (match_dup 1)
2896 (match_dup 2)))]
2897 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && !TARGET_MIPS16"
2898 "#"
2899 "&& reload_completed"
2900 [(const_int 0)]
2901 {
2902 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2903 DONE;
2904 }
2905 [(set_attr "type" "idiv")
2906 (set_attr "mode" "<MODE>")
2907 (set_attr "insn_count" "2")])
2908
2909 ;; Expand generates divmod instructions for individual division and modulus
2910 ;; operations. We then rely on CSE to reuse earlier divmods where possible.
2911 ;; This means that, when generating MIPS16 code, it is better not to expose
2912 ;; the fixed LO register until after CSE has finished. However, it's still
2913 ;; better to split before register allocation, so that we don't allocate
2914 ;; one of the scarce MIPS16 registers to an unused result.
2915 (define_insn_and_split "divmod<mode>4_mips16"
2916 [(set (match_operand:GPR 0 "register_operand" "=d")
2917 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2918 (match_operand:GPR 2 "register_operand" "d")))
2919 (set (match_operand:GPR 3 "register_operand" "=d")
2920 (mod:GPR (match_dup 1)
2921 (match_dup 2)))
2922 (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2923 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && TARGET_MIPS16"
2924 "#"
2925 "&& cse_not_expected"
2926 [(const_int 0)]
2927 {
2928 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2929 emit_move_insn (operands[0], operands[4]);
2930 DONE;
2931 }
2932 [(set_attr "type" "idiv")
2933 (set_attr "mode" "<MODE>")
2934 (set_attr "insn_count" "3")])
2935
2936 (define_expand "udivmod<mode>4"
2937 [(parallel
2938 [(set (match_operand:GPR 0 "register_operand")
2939 (udiv:GPR (match_operand:GPR 1 "register_operand")
2940 (match_operand:GPR 2 "register_operand")))
2941 (set (match_operand:GPR 3 "register_operand")
2942 (umod:GPR (match_dup 1)
2943 (match_dup 2)))])]
2944 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2945 {
2946 if (TARGET_MIPS16)
2947 {
2948 rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2949 emit_insn (gen_udivmod<mode>4_mips16 (operands[0], operands[1],
2950 operands[2], operands[3], lo));
2951 DONE;
2952 }
2953 })
2954
2955 (define_insn_and_split "*udivmod<mode>4"
2956 [(set (match_operand:GPR 0 "register_operand" "=l")
2957 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2958 (match_operand:GPR 2 "register_operand" "d")))
2959 (set (match_operand:GPR 3 "register_operand" "=d")
2960 (umod:GPR (match_dup 1)
2961 (match_dup 2)))]
2962 "ISA_HAS_<D>DIV && !TARGET_MIPS16"
2963 "#"
2964 "reload_completed"
2965 [(const_int 0)]
2966 {
2967 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2968 DONE;
2969 }
2970 [(set_attr "type" "idiv")
2971 (set_attr "mode" "<MODE>")
2972 (set_attr "insn_count" "2")])
2973
2974 ;; See the comment above "divmod<mode>4_mips16" for the split timing.
2975 (define_insn_and_split "udivmod<mode>4_mips16"
2976 [(set (match_operand:GPR 0 "register_operand" "=d")
2977 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2978 (match_operand:GPR 2 "register_operand" "d")))
2979 (set (match_operand:GPR 3 "register_operand" "=d")
2980 (umod:GPR (match_dup 1)
2981 (match_dup 2)))
2982 (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2983 "ISA_HAS_<D>DIV && TARGET_MIPS16"
2984 "#"
2985 "cse_not_expected"
2986 [(const_int 0)]
2987 {
2988 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2989 emit_move_insn (operands[0], operands[4]);
2990 DONE;
2991 }
2992 [(set_attr "type" "idiv")
2993 (set_attr "mode" "<MODE>")
2994 (set_attr "insn_count" "3")])
2995
2996 (define_expand "<u>divmod<mode>4_split"
2997 [(set (match_operand:GPR 0 "register_operand")
2998 (any_mod:GPR (match_operand:GPR 1 "register_operand")
2999 (match_operand:GPR 2 "register_operand")))]
3000 ""
3001 {
3002 rtx hilo;
3003
3004 if (TARGET_64BIT)
3005 {
3006 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
3007 emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
3008 operands[2]));
3009 emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
3010 }
3011 else
3012 {
3013 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
3014 emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
3015 operands[2]));
3016 emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
3017 }
3018 DONE;
3019 })
3020
3021 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
3022 [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
3023 (unspec:HILO
3024 [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
3025 (match_operand:GPR 2 "register_operand" "d"))]
3026 UNSPEC_SET_HILO))]
3027 "ISA_HAS_<GPR:D>DIV"
3028 { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
3029 [(set_attr "type" "idiv")
3030 (set_attr "mode" "<GPR:MODE>")])
3031
3032 ;; Integer division and modulus.
3033
3034 (define_insn "<u>div<mode>3"
3035 [(set (match_operand:GPR 0 "register_operand" "=&d")
3036 (any_div:GPR (match_operand:GPR 1 "register_operand" "d")
3037 (match_operand:GPR 2 "register_operand" "d")))]
3038 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>DIV"
3039 {
3040 if (TARGET_LOONGSON_2EF)
3041 return mips_output_division ("<d>div<u>.g\t%0,%1,%2", operands);
3042 else if (TARGET_LOONGSON_EXT)
3043 return mips_output_division ("gs<d>div<u>\t%0,%1,%2", operands);
3044 else
3045 return mips_output_division ("<d>div<u>\t%0,%1,%2", operands);
3046 }
3047 [(set_attr "type" "idiv3")
3048 (set_attr "mode" "<MODE>")])
3049
3050 (define_insn "<u>mod<mode>3"
3051 [(set (match_operand:GPR 0 "register_operand" "=&d")
3052 (any_mod:GPR (match_operand:GPR 1 "register_operand" "d")
3053 (match_operand:GPR 2 "register_operand" "d")))]
3054 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>DIV"
3055 {
3056 if (TARGET_LOONGSON_2EF)
3057 return mips_output_division ("<d>mod<u>.g\t%0,%1,%2", operands);
3058 else if (TARGET_LOONGSON_EXT)
3059 return mips_output_division ("gs<d>mod<u>\t%0,%1,%2", operands);
3060 else
3061 return mips_output_division ("<d>mod<u>\t%0,%1,%2", operands);
3062 }
3063 [(set_attr "type" "idiv3")
3064 (set_attr "mode" "<MODE>")])
3065 \f
3066 ;;
3067 ;; ....................
3068 ;;
3069 ;; SQUARE ROOT
3070 ;;
3071 ;; ....................
3072
3073 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
3074 ;; "*div[sd]f3" comment for details).
3075
3076 (define_insn "sqrt<mode>2"
3077 [(set (match_operand:ANYF 0 "register_operand" "=f")
3078 (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3079 "<sqrt_condition>"
3080 {
3081 if (TARGET_FIX_SB1)
3082 return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
3083 else
3084 return "sqrt.<fmt>\t%0,%1";
3085 }
3086 [(set_attr "type" "fsqrt")
3087 (set_attr "mode" "<UNITMODE>")
3088 (set (attr "insn_count")
3089 (if_then_else (match_test "TARGET_FIX_SB1")
3090 (const_int 2)
3091 (const_int 1)))])
3092
3093 (define_insn "*rsqrt<mode>a"
3094 [(set (match_operand:ANYF 0 "register_operand" "=f")
3095 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
3096 (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
3097 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
3098 {
3099 if (TARGET_FIX_SB1)
3100 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
3101 else
3102 return "rsqrt.<fmt>\t%0,%2";
3103 }
3104 [(set_attr "type" "frsqrt")
3105 (set_attr "mode" "<UNITMODE>")
3106 (set (attr "insn_count")
3107 (if_then_else (match_test "TARGET_FIX_SB1")
3108 (const_int 2)
3109 (const_int 1)))])
3110
3111 (define_insn "*rsqrt<mode>b"
3112 [(set (match_operand:ANYF 0 "register_operand" "=f")
3113 (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
3114 (match_operand:ANYF 2 "register_operand" "f"))))]
3115 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
3116 {
3117 if (TARGET_FIX_SB1)
3118 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
3119 else
3120 return "rsqrt.<fmt>\t%0,%2";
3121 }
3122 [(set_attr "type" "frsqrt")
3123 (set_attr "mode" "<UNITMODE>")
3124 (set (attr "insn_count")
3125 (if_then_else (match_test "TARGET_FIX_SB1")
3126 (const_int 2)
3127 (const_int 1)))])
3128 \f
3129 ;;
3130 ;; ....................
3131 ;;
3132 ;; ABSOLUTE VALUE
3133 ;;
3134 ;; ....................
3135
3136 ;; Do not use the integer abs macro instruction, since that signals an
3137 ;; exception on -2147483648 (sigh).
3138
3139 ;; The "legacy" (as opposed to "2008") form of ABS.fmt is an arithmetic
3140 ;; instruction that treats all NaN inputs as invalid; it does not clear
3141 ;; their sign bit. We therefore can't use that form if the signs of
3142 ;; NaNs matter.
3143
3144 (define_insn "abs<mode>2"
3145 [(set (match_operand:ANYF 0 "register_operand" "=f")
3146 (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3147 "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3148 "abs.<fmt>\t%0,%1"
3149 [(set_attr "type" "fabs")
3150 (set_attr "mode" "<UNITMODE>")])
3151 \f
3152 ;;
3153 ;; ...................
3154 ;;
3155 ;; Count leading zeroes.
3156 ;;
3157 ;; ...................
3158 ;;
3159
3160 (define_insn "clz<mode>2"
3161 [(set (match_operand:GPR 0 "register_operand" "=d")
3162 (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
3163 "ISA_HAS_CLZ_CLO"
3164 "<d>clz\t%0,%1"
3165 [(set_attr "type" "clz")
3166 (set_attr "mode" "<MODE>")])
3167
3168 ;;
3169 ;; ...................
3170 ;;
3171 ;; Count trailing zeroes.
3172 ;;
3173 ;; ...................
3174 ;;
3175
3176 (define_insn "ctz<mode>2"
3177 [(set (match_operand:GPR 0 "register_operand" "=d")
3178 (ctz:GPR (match_operand:GPR 1 "register_operand" "d")))]
3179 "ISA_HAS_CTZ_CTO"
3180 "<d>ctz\t%0,%1"
3181 [(set_attr "type" "clz")
3182 (set_attr "mode" "<MODE>")])
3183
3184
3185 ;;
3186 ;; ...................
3187 ;;
3188 ;; Count number of set bits.
3189 ;;
3190 ;; ...................
3191 ;;
3192
3193 (define_insn "popcount<mode>2"
3194 [(set (match_operand:GPR 0 "register_operand" "=d")
3195 (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
3196 "ISA_HAS_POP"
3197 "<d>pop\t%0,%1"
3198 [(set_attr "type" "pop")
3199 (set_attr "mode" "<MODE>")])
3200
3201 ;; The POP instruction is special as it does not take into account the upper
3202 ;; 32bits and is documented that way.
3203 (define_insn "*popcountdi2_trunc"
3204 [(set (match_operand:SI 0 "register_operand" "=d")
3205 (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
3206 "ISA_HAS_POP && TARGET_64BIT"
3207 "pop\t%0,%1"
3208 [(set_attr "type" "pop")
3209 (set_attr "mode" "SI")])
3210 \f
3211 ;;
3212 ;; ....................
3213 ;;
3214 ;; NEGATION and ONE'S COMPLEMENT
3215 ;;
3216 ;; ....................
3217
3218 (define_insn "negsi2"
3219 [(set (match_operand:SI 0 "register_operand" "=d")
3220 (neg:SI (match_operand:SI 1 "register_operand" "d")))]
3221 ""
3222 {
3223 if (TARGET_MIPS16)
3224 return "neg\t%0,%1";
3225 else
3226 return "subu\t%0,%.,%1";
3227 }
3228 [(set_attr "alu_type" "sub")
3229 (set_attr "mode" "SI")])
3230
3231 (define_insn "negdi2"
3232 [(set (match_operand:DI 0 "register_operand" "=d")
3233 (neg:DI (match_operand:DI 1 "register_operand" "d")))]
3234 "TARGET_64BIT && !TARGET_MIPS16"
3235 "dsubu\t%0,%.,%1"
3236 [(set_attr "alu_type" "sub")
3237 (set_attr "mode" "DI")])
3238
3239 ;; The "legacy" (as opposed to "2008") form of NEG.fmt is an arithmetic
3240 ;; instruction that treats all NaN inputs as invalid; it does not flip
3241 ;; their sign bit. We therefore can't use that form if the signs of
3242 ;; NaNs matter.
3243
3244 (define_insn "neg<mode>2"
3245 [(set (match_operand:ANYF 0 "register_operand" "=f")
3246 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3247 "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3248 "neg.<fmt>\t%0,%1"
3249 [(set_attr "type" "fneg")
3250 (set_attr "mode" "<UNITMODE>")])
3251
3252 (define_insn "one_cmpl<mode>2"
3253 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
3254 (not:GPR (match_operand:GPR 1 "register_operand" "!u,d")))]
3255 ""
3256 {
3257 if (TARGET_MIPS16)
3258 return "not\t%0,%1";
3259 else
3260 return "nor\t%0,%.,%1";
3261 }
3262 [(set_attr "alu_type" "not")
3263 (set_attr "compression" "micromips,*")
3264 (set_attr "mode" "<MODE>")])
3265 \f
3266 ;;
3267 ;; ....................
3268 ;;
3269 ;; LOGICAL
3270 ;;
3271 ;; ....................
3272 ;;
3273
3274 ;; Many of these instructions use trivial define_expands, because we
3275 ;; want to use a different set of constraints when TARGET_MIPS16.
3276
3277 (define_expand "and<mode>3"
3278 [(set (match_operand:GPR 0 "register_operand")
3279 (and:GPR (match_operand:GPR 1 "register_operand")
3280 (match_operand:GPR 2 "and_reg_operand")))])
3281
3282 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
3283 ;; zero_extendsidi2 because of TARGET_TRULY_NOOP_TRUNCATION, so handle these
3284 ;; here. Note that this variant does not trigger for SI mode because we
3285 ;; require a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
3286 ;; sign-extended SImode value.
3287 ;;
3288 ;; These are possible combinations for operand 1 and 2. The table
3289 ;; includes both MIPS and MIPS16 cases. (r=register, mem=memory,
3290 ;; 16=MIPS16, x=match, S=split):
3291 ;;
3292 ;; \ op1 r/EXT r/!EXT mem r/16 mem/16
3293 ;; op2
3294 ;;
3295 ;; andi x x
3296 ;; 0xff x x x x
3297 ;; 0xffff x x x x
3298 ;; 0xffff_ffff x S x S x
3299 ;; low-bitmask x
3300 ;; register x x
3301 ;; register =op1 x
3302
3303 (define_insn "*and<mode>3"
3304 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,!u,d,d,d,!u,d")
3305 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,!u,d,d,d,0,d")
3306 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Uean,K,Yx,Yw,!u,d")))]
3307 "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3308 {
3309 int len;
3310
3311 switch (which_alternative)
3312 {
3313 case 0:
3314 operands[1] = gen_lowpart (QImode, operands[1]);
3315 return "lbu\t%0,%1";
3316 case 1:
3317 operands[1] = gen_lowpart (HImode, operands[1]);
3318 return "lhu\t%0,%1";
3319 case 2:
3320 operands[1] = gen_lowpart (SImode, operands[1]);
3321 return "lwu\t%0,%1";
3322 case 3:
3323 case 4:
3324 return "andi\t%0,%1,%x2";
3325 case 5:
3326 len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
3327 operands[2] = GEN_INT (len);
3328 return "<d>ext\t%0,%1,0,%2";
3329 case 6:
3330 return "#";
3331 case 7:
3332 case 8:
3333 return "and\t%0,%1,%2";
3334 default:
3335 gcc_unreachable ();
3336 }
3337 }
3338 [(set_attr "move_type" "load,load,load,andi,andi,ext_ins,shift_shift,logical,logical")
3339 (set_attr "compression" "*,*,*,micromips,*,*,*,micromips,*")
3340 (set_attr "mode" "<MODE>")])
3341
3342 (define_insn "*and<mode>3_mips16"
3343 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
3344 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%W,W,W,d,0")
3345 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
3346 "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3347 {
3348 switch (which_alternative)
3349 {
3350 case 0:
3351 operands[1] = gen_lowpart (QImode, operands[1]);
3352 return "lbu\t%0,%1";
3353 case 1:
3354 operands[1] = gen_lowpart (HImode, operands[1]);
3355 return "lhu\t%0,%1";
3356 case 2:
3357 operands[1] = gen_lowpart (SImode, operands[1]);
3358 return "lwu\t%0,%1";
3359 case 3:
3360 return "#";
3361 case 4:
3362 return "and\t%0,%2";
3363 default:
3364 gcc_unreachable ();
3365 }
3366 }
3367 [(set_attr "move_type" "load,load,load,shift_shift,logical")
3368 (set_attr "mode" "<MODE>")])
3369
3370 (define_expand "ior<mode>3"
3371 [(set (match_operand:GPR 0 "register_operand")
3372 (ior:GPR (match_operand:GPR 1 "register_operand")
3373 (match_operand:GPR 2 "uns_arith_operand")))]
3374 ""
3375 {
3376 if (TARGET_MIPS16)
3377 operands[2] = force_reg (<MODE>mode, operands[2]);
3378 })
3379
3380 (define_insn "*ior<mode>3"
3381 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3382 (ior:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3383 (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3384 "!TARGET_MIPS16"
3385 "@
3386 or\t%0,%1,%2
3387 or\t%0,%1,%2
3388 ori\t%0,%1,%x2"
3389 [(set_attr "alu_type" "or")
3390 (set_attr "compression" "micromips,*,*")
3391 (set_attr "mode" "<MODE>")])
3392
3393 (define_insn "*ior<mode>3_mips16"
3394 [(set (match_operand:GPR 0 "register_operand" "=d")
3395 (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
3396 (match_operand:GPR 2 "register_operand" "d")))]
3397 "TARGET_MIPS16"
3398 "or\t%0,%2"
3399 [(set_attr "alu_type" "or")
3400 (set_attr "mode" "<MODE>")])
3401
3402 (define_expand "xor<mode>3"
3403 [(set (match_operand:GPR 0 "register_operand")
3404 (xor:GPR (match_operand:GPR 1 "register_operand")
3405 (match_operand:GPR 2 "uns_arith_operand")))]
3406 ""
3407 "")
3408
3409 (define_insn "*xor<mode>3"
3410 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3411 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3412 (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3413 "!TARGET_MIPS16"
3414 "@
3415 xor\t%0,%1,%2
3416 xor\t%0,%1,%2
3417 xori\t%0,%1,%x2"
3418 [(set_attr "alu_type" "xor")
3419 (set_attr "compression" "micromips,*,*")
3420 (set_attr "mode" "<MODE>")])
3421
3422 (define_insn "*xor<mode>3_mips16"
3423 [(set (match_operand:GPR 0 "register_operand" "=d,t,t,t")
3424 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d,d")
3425 (match_operand:GPR 2 "uns_arith_operand" "d,Uub8,K,d")))]
3426 "TARGET_MIPS16"
3427 "@
3428 xor\t%0,%2
3429 cmpi\t%1,%2
3430 cmpi\t%1,%2
3431 cmp\t%1,%2"
3432 [(set_attr "alu_type" "xor")
3433 (set_attr "mode" "<MODE>")
3434 (set_attr "extended_mips16" "no,no,yes,no")])
3435
3436 (define_insn "*nor<mode>3"
3437 [(set (match_operand:GPR 0 "register_operand" "=d")
3438 (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
3439 (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
3440 "!TARGET_MIPS16"
3441 "nor\t%0,%1,%2"
3442 [(set_attr "alu_type" "nor")
3443 (set_attr "mode" "<MODE>")])
3444 \f
3445 ;;
3446 ;; ....................
3447 ;;
3448 ;; TRUNCATION
3449 ;;
3450 ;; ....................
3451
3452
3453
3454 (define_insn "truncdfsf2"
3455 [(set (match_operand:SF 0 "register_operand" "=f")
3456 (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3457 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3458 "cvt.s.d\t%0,%1"
3459 [(set_attr "type" "fcvt")
3460 (set_attr "cnv_mode" "D2S")
3461 (set_attr "mode" "SF")])
3462
3463 ;; Integer truncation patterns. Truncating SImode values to smaller
3464 ;; modes is a no-op, as it is for most other GCC ports. Truncating
3465 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3466 ;; need to make sure that the lower 32 bits are properly sign-extended
3467 ;; (see TARGET_TRULY_NOOP_TRUNCATION). Truncating DImode values into modes
3468 ;; smaller than SImode is equivalent to two separate truncations:
3469 ;;
3470 ;; A B
3471 ;; DI ---> HI == DI ---> SI ---> HI
3472 ;; DI ---> QI == DI ---> SI ---> QI
3473 ;;
3474 ;; Step A needs a real instruction but step B does not.
3475
3476 (define_insn "truncdi<mode>2"
3477 [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3478 (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3479 "TARGET_64BIT"
3480 "@
3481 sll\t%0,%1,0
3482 <store>\t%1,%0"
3483 [(set_attr "move_type" "sll0,store")
3484 (set_attr "mode" "SI")])
3485
3486 ;; Combiner patterns to optimize shift/truncate combinations.
3487
3488 (define_insn "*ashr_trunc<mode>"
3489 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3490 (truncate:SUBDI
3491 (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3492 (match_operand:DI 2 "const_arith_operand" ""))))]
3493 "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3494 "dsra\t%0,%1,%2"
3495 [(set_attr "type" "shift")
3496 (set_attr "mode" "<MODE>")])
3497
3498 (define_insn "*lshr32_trunc<mode>"
3499 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3500 (truncate:SUBDI
3501 (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3502 (const_int 32))))]
3503 "TARGET_64BIT && !TARGET_MIPS16"
3504 "dsra\t%0,%1,32"
3505 [(set_attr "type" "shift")
3506 (set_attr "mode" "<MODE>")])
3507
3508 ;; Logical shift by more than 32 results in proper SI values so truncation is
3509 ;; removed by the middle end. Note that a logical shift by 32 is handled by
3510 ;; the previous pattern.
3511 (define_insn "*<optab>_trunc<mode>_exts"
3512 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3513 (truncate:SUBDI
3514 (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3515 (match_operand:DI 2 "const_arith_operand" ""))))]
3516 "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3517 "exts\t%0,%1,%2,31"
3518 [(set_attr "type" "arith")
3519 (set_attr "mode" "<MODE>")])
3520
3521 ;; This could likely be generalized for any SUBDI mode, and any right
3522 ;; shift, but AFAICT this is used so rarely it is not worth the additional
3523 ;; complexity.
3524 (define_insn ""
3525 [(set (match_operand:SI 0 "register_operand" "=d")
3526 (ashiftrt:SI
3527 (truncate:SI
3528 (ashift:DI (match_operand:DI 1 "register_operand" "d")
3529 (match_operand:DI 2 "const_arith_operand" "")))
3530 (match_operand:DI 3 "const_arith_operand" "")))]
3531 "(ISA_HAS_EXTS && TARGET_64BIT
3532 && UINTVAL (operands[2]) < 32 && UINTVAL (operands[3]) < 32
3533 && UINTVAL (operands[3]) >= UINTVAL (operands[2]))"
3534 {
3535 rtx xoperands[4];
3536 xoperands[0] = operands[0];
3537 xoperands[1] = operands[1];
3538
3539 /* The length of the field is the size of the outer mode less the outer
3540 shift constant. We fix the outer mode as SImode for simplicity. */
3541 unsigned int right_shift = INTVAL (operands[3]);
3542 xoperands[3] = GEN_INT (32 - right_shift);
3543
3544 /* The field starts at the outer shift constant less the inner shift
3545 constant. */
3546 unsigned int left_shift = INTVAL (operands[2]);
3547 xoperands[2] = GEN_INT (right_shift - left_shift);
3548
3549 /* Sanity checks. These constraints are taken from the MIPS ISA
3550 manual. */
3551 gcc_assert (INTVAL (xoperands[2]) >= 0 && INTVAL (xoperands[2]) < 32);
3552 gcc_assert (INTVAL (xoperands[3]) > 0 && INTVAL (xoperands[3]) <= 32);
3553 gcc_assert (INTVAL (xoperands[2]) + INTVAL (xoperands[3]) > 0
3554 && INTVAL (xoperands[2]) + INTVAL (xoperands[3]) <= 32);
3555
3556 output_asm_insn ("exts\t%0,%1,%2,%m3", xoperands);
3557 return "";
3558 }
3559 [(set_attr "type" "arith")
3560 (set_attr "mode" "SI")])
3561 \f
3562 ;;
3563 ;; ....................
3564 ;;
3565 ;; ZERO EXTENSION
3566 ;;
3567 ;; ....................
3568
3569 ;; Extension insns.
3570
3571 (define_expand "zero_extendsidi2"
3572 [(set (match_operand:DI 0 "register_operand")
3573 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3574 "TARGET_64BIT")
3575
3576 (define_insn_and_split "*zero_extendsidi2"
3577 [(set (match_operand:DI 0 "register_operand" "=d,d")
3578 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3579 "TARGET_64BIT && !ISA_HAS_EXT_INS"
3580 "@
3581 #
3582 lwu\t%0,%1"
3583 "&& reload_completed && REG_P (operands[1])"
3584 [(set (match_dup 0)
3585 (ashift:DI (match_dup 1) (const_int 32)))
3586 (set (match_dup 0)
3587 (lshiftrt:DI (match_dup 0) (const_int 32)))]
3588 { operands[1] = gen_lowpart (DImode, operands[1]); }
3589 [(set_attr "move_type" "shift_shift,load")
3590 (set_attr "mode" "DI")])
3591
3592 (define_insn "*zero_extendsidi2_dext"
3593 [(set (match_operand:DI 0 "register_operand" "=d,d")
3594 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3595 "TARGET_64BIT && ISA_HAS_EXT_INS"
3596 "@
3597 dext\t%0,%1,0,32
3598 lwu\t%0,%1"
3599 [(set_attr "move_type" "arith,load")
3600 (set_attr "mode" "DI")])
3601
3602 ;; See the comment before the *and<mode>3 pattern why this is generated by
3603 ;; combine.
3604
3605 (define_split
3606 [(set (match_operand:DI 0 "register_operand")
3607 (and:DI (match_operand:DI 1 "register_operand")
3608 (const_int 4294967295)))]
3609 "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3610 [(set (match_dup 0)
3611 (ashift:DI (match_dup 1) (const_int 32)))
3612 (set (match_dup 0)
3613 (lshiftrt:DI (match_dup 0) (const_int 32)))])
3614
3615 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3616 [(set (match_operand:GPR 0 "register_operand")
3617 (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3618 ""
3619 {
3620 if (TARGET_MIPS16 && !GENERATE_MIPS16E
3621 && !memory_operand (operands[1], <SHORT:MODE>mode))
3622 {
3623 emit_insn (gen_and<GPR:mode>3 (operands[0],
3624 gen_lowpart (<GPR:MODE>mode, operands[1]),
3625 force_reg (<GPR:MODE>mode,
3626 GEN_INT (<SHORT:mask>))));
3627 DONE;
3628 }
3629 })
3630
3631 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3632 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3633 (zero_extend:GPR
3634 (match_operand:SHORT 1 "nonimmediate_operand" "!u,d,m")))]
3635 "!TARGET_MIPS16"
3636 "@
3637 andi\t%0,%1,<SHORT:mask>
3638 andi\t%0,%1,<SHORT:mask>
3639 l<SHORT:size>u\t%0,%1"
3640 [(set_attr "move_type" "andi,andi,load")
3641 (set_attr "compression" "micromips,*,*")
3642 (set_attr "mode" "<GPR:MODE>")])
3643
3644 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3645 [(set (match_operand:GPR 0 "register_operand" "=d")
3646 (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3647 "GENERATE_MIPS16E"
3648 "ze<SHORT:size>\t%0"
3649 ;; This instruction is effectively a special encoding of ANDI.
3650 [(set_attr "move_type" "andi")
3651 (set_attr "mode" "<GPR:MODE>")])
3652
3653 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3654 [(set (match_operand:GPR 0 "register_operand" "=d")
3655 (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3656 "TARGET_MIPS16"
3657 "l<SHORT:size>u\t%0,%1"
3658 [(set_attr "move_type" "load")
3659 (set_attr "mode" "<GPR:MODE>")])
3660
3661 (define_expand "zero_extendqihi2"
3662 [(set (match_operand:HI 0 "register_operand")
3663 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3664 ""
3665 {
3666 if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3667 {
3668 emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3669 operands[1]));
3670 DONE;
3671 }
3672 })
3673
3674 (define_insn "*zero_extendqihi2"
3675 [(set (match_operand:HI 0 "register_operand" "=d,d")
3676 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3677 "!TARGET_MIPS16"
3678 "@
3679 andi\t%0,%1,0x00ff
3680 lbu\t%0,%1"
3681 [(set_attr "move_type" "andi,load")
3682 (set_attr "mode" "HI")])
3683
3684 (define_insn "*zero_extendqihi2_mips16"
3685 [(set (match_operand:HI 0 "register_operand" "=d")
3686 (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3687 "TARGET_MIPS16"
3688 "lbu\t%0,%1"
3689 [(set_attr "move_type" "load")
3690 (set_attr "mode" "HI")])
3691
3692 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3693
3694 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3695 [(set (match_operand:GPR 0 "register_operand" "=d")
3696 (zero_extend:GPR
3697 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3698 "TARGET_64BIT && !TARGET_MIPS16"
3699 {
3700 operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3701 return "andi\t%0,%1,%x2";
3702 }
3703 [(set_attr "alu_type" "and")
3704 (set_attr "mode" "<GPR:MODE>")])
3705
3706 (define_insn "*zero_extendhi_truncqi"
3707 [(set (match_operand:HI 0 "register_operand" "=d")
3708 (zero_extend:HI
3709 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3710 "TARGET_64BIT && !TARGET_MIPS16"
3711 "andi\t%0,%1,0xff"
3712 [(set_attr "alu_type" "and")
3713 (set_attr "mode" "HI")])
3714 \f
3715 ;;
3716 ;; ....................
3717 ;;
3718 ;; SIGN EXTENSION
3719 ;;
3720 ;; ....................
3721
3722 ;; Extension insns.
3723 ;; Those for integer source operand are ordered widest source type first.
3724
3725 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3726 ;; should already be in sign-extended form (see TARGET_TRULY_NOOP_TRUNCATION
3727 ;; and truncdisi2). We can therefore get rid of register->register
3728 ;; instructions if we constrain the source to be in the same register as
3729 ;; the destination.
3730 ;;
3731 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3732 ;; we split them into nothing before the post-reload scheduler runs.
3733 ;; These alternatives therefore have type "move" in order to reflect
3734 ;; what happens if the two pre-reload operands cannot be tied, and are
3735 ;; instead allocated two separate GPRs. We don't distinguish between
3736 ;; the GPR and LO cases because we don't usually know during pre-reload
3737 ;; scheduling whether an operand will be LO or not.
3738 (define_insn_and_split "extendsidi2"
3739 [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3740 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3741 "TARGET_64BIT"
3742 "@
3743 #
3744 #
3745 lw\t%0,%1"
3746 "&& reload_completed && register_operand (operands[1], VOIDmode)"
3747 [(const_int 0)]
3748 {
3749 emit_note (NOTE_INSN_DELETED);
3750 DONE;
3751 }
3752 [(set_attr "move_type" "move,move,load")
3753 (set_attr "mode" "DI")])
3754
3755 (define_expand "extend<SHORT:mode><GPR:mode>2"
3756 [(set (match_operand:GPR 0 "register_operand")
3757 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3758 "")
3759
3760 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3761 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3762 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3763 "GENERATE_MIPS16E"
3764 "@
3765 se<SHORT:size>\t%0
3766 l<SHORT:size>\t%0,%1"
3767 [(set_attr "move_type" "signext,load")
3768 (set_attr "mode" "<GPR:MODE>")])
3769
3770 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3771 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3772 (sign_extend:GPR
3773 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3774 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3775 "@
3776 #
3777 l<SHORT:size>\t%0,%1"
3778 "&& reload_completed && REG_P (operands[1])"
3779 [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3780 (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3781 {
3782 operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3783 operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3784 - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3785 }
3786 [(set_attr "move_type" "shift_shift,load")
3787 (set_attr "mode" "<GPR:MODE>")])
3788
3789 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3790 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3791 (sign_extend:GPR
3792 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3793 "ISA_HAS_SEB_SEH"
3794 "@
3795 se<SHORT:size>\t%0,%1
3796 l<SHORT:size>\t%0,%1"
3797 [(set_attr "move_type" "signext,load")
3798 (set_attr "mode" "<GPR:MODE>")])
3799
3800 (define_expand "extendqihi2"
3801 [(set (match_operand:HI 0 "register_operand")
3802 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3803 "")
3804
3805 (define_insn "*extendqihi2_mips16e"
3806 [(set (match_operand:HI 0 "register_operand" "=d,d")
3807 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3808 "GENERATE_MIPS16E"
3809 "@
3810 seb\t%0
3811 lb\t%0,%1"
3812 [(set_attr "move_type" "signext,load")
3813 (set_attr "mode" "SI")])
3814
3815 (define_insn_and_split "*extendqihi2"
3816 [(set (match_operand:HI 0 "register_operand" "=d,d")
3817 (sign_extend:HI
3818 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3819 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3820 "@
3821 #
3822 lb\t%0,%1"
3823 "&& reload_completed && REG_P (operands[1])"
3824 [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3825 (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3826 {
3827 operands[0] = gen_lowpart (SImode, operands[0]);
3828 operands[1] = gen_lowpart (SImode, operands[1]);
3829 operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3830 - GET_MODE_BITSIZE (QImode));
3831 }
3832 [(set_attr "move_type" "shift_shift,load")
3833 (set_attr "mode" "SI")])
3834
3835 (define_insn "*extendqihi2_seb"
3836 [(set (match_operand:HI 0 "register_operand" "=d,d")
3837 (sign_extend:HI
3838 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3839 "ISA_HAS_SEB_SEH"
3840 "@
3841 seb\t%0,%1
3842 lb\t%0,%1"
3843 [(set_attr "move_type" "signext,load")
3844 (set_attr "mode" "SI")])
3845
3846 ;; Combiner patterns for truncate/sign_extend combinations. The SI versions
3847 ;; use the shift/truncate patterns.
3848
3849 (define_insn_and_split "*extenddi_truncate<mode>"
3850 [(set (match_operand:DI 0 "register_operand" "=d")
3851 (sign_extend:DI
3852 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3853 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3854 "#"
3855 "&& reload_completed"
3856 [(set (match_dup 2)
3857 (ashift:DI (match_dup 1)
3858 (match_dup 3)))
3859 (set (match_dup 0)
3860 (ashiftrt:DI (match_dup 2)
3861 (match_dup 3)))]
3862 {
3863 operands[2] = gen_lowpart (DImode, operands[0]);
3864 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3865 }
3866 [(set_attr "move_type" "shift_shift")
3867 (set_attr "mode" "DI")])
3868
3869 (define_insn_and_split "*extendsi_truncate<mode>"
3870 [(set (match_operand:SI 0 "register_operand" "=d")
3871 (sign_extend:SI
3872 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3873 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3874 "#"
3875 "&& reload_completed"
3876 [(set (match_dup 2)
3877 (ashift:DI (match_dup 1)
3878 (match_dup 3)))
3879 (set (match_dup 0)
3880 (truncate:SI (ashiftrt:DI (match_dup 2)
3881 (match_dup 3))))]
3882 {
3883 operands[2] = gen_lowpart (DImode, operands[0]);
3884 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3885 }
3886 [(set_attr "move_type" "shift_shift")
3887 (set_attr "mode" "SI")])
3888
3889 (define_insn_and_split "*extendhi_truncateqi"
3890 [(set (match_operand:HI 0 "register_operand" "=d")
3891 (sign_extend:HI
3892 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3893 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3894 "#"
3895 "&& reload_completed"
3896 [(set (match_dup 2)
3897 (ashift:DI (match_dup 1)
3898 (const_int 56)))
3899 (set (match_dup 0)
3900 (truncate:HI (ashiftrt:DI (match_dup 2)
3901 (const_int 56))))]
3902 {
3903 operands[2] = gen_lowpart (DImode, operands[0]);
3904 }
3905 [(set_attr "move_type" "shift_shift")
3906 (set_attr "mode" "SI")])
3907
3908 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3909 [(set (match_operand:GPR 0 "register_operand" "=d")
3910 (sign_extend:GPR
3911 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3912 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3913 {
3914 operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3915 return "exts\t%0,%1,0,%m2";
3916 }
3917 [(set_attr "type" "arith")
3918 (set_attr "mode" "<GPR:MODE>")])
3919
3920 (define_insn "*extendhi_truncateqi_exts"
3921 [(set (match_operand:HI 0 "register_operand" "=d")
3922 (sign_extend:HI
3923 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3924 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3925 "exts\t%0,%1,0,7"
3926 [(set_attr "type" "arith")
3927 (set_attr "mode" "SI")])
3928
3929 (define_insn "extendsfdf2"
3930 [(set (match_operand:DF 0 "register_operand" "=f")
3931 (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3932 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3933 "cvt.d.s\t%0,%1"
3934 [(set_attr "type" "fcvt")
3935 (set_attr "cnv_mode" "S2D")
3936 (set_attr "mode" "DF")])
3937 \f
3938 ;;
3939 ;; ....................
3940 ;;
3941 ;; CONVERSIONS
3942 ;;
3943 ;; ....................
3944
3945 (define_expand "fix_truncdfsi2"
3946 [(set (match_operand:SI 0 "register_operand")
3947 (fix:SI (match_operand:DF 1 "register_operand")))]
3948 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3949 {
3950 if (!ISA_HAS_TRUNC_W)
3951 {
3952 emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3953 DONE;
3954 }
3955 })
3956
3957 (define_insn "fix_truncdfsi2_insn"
3958 [(set (match_operand:SI 0 "register_operand" "=f")
3959 (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3960 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3961 "trunc.w.d %0,%1"
3962 [(set_attr "type" "fcvt")
3963 (set_attr "mode" "DF")
3964 (set_attr "cnv_mode" "D2I")])
3965
3966 (define_insn "fix_truncdfsi2_macro"
3967 [(set (match_operand:SI 0 "register_operand" "=f")
3968 (fix:SI (match_operand:DF 1 "register_operand" "f")))
3969 (clobber (match_scratch:DF 2 "=d"))]
3970 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3971 {
3972 if (mips_nomacro.nesting_level > 0)
3973 return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3974 else
3975 return "trunc.w.d %0,%1,%2";
3976 }
3977 [(set_attr "type" "fcvt")
3978 (set_attr "mode" "DF")
3979 (set_attr "cnv_mode" "D2I")
3980 (set_attr "insn_count" "9")])
3981
3982 (define_expand "fix_truncsfsi2"
3983 [(set (match_operand:SI 0 "register_operand")
3984 (fix:SI (match_operand:SF 1 "register_operand")))]
3985 "TARGET_HARD_FLOAT"
3986 {
3987 if (!ISA_HAS_TRUNC_W)
3988 {
3989 emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3990 DONE;
3991 }
3992 })
3993
3994 (define_insn "fix_truncsfsi2_insn"
3995 [(set (match_operand:SI 0 "register_operand" "=f")
3996 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3997 "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3998 "trunc.w.s %0,%1"
3999 [(set_attr "type" "fcvt")
4000 (set_attr "mode" "SF")
4001 (set_attr "cnv_mode" "S2I")])
4002
4003 (define_insn "fix_truncsfsi2_macro"
4004 [(set (match_operand:SI 0 "register_operand" "=f")
4005 (fix:SI (match_operand:SF 1 "register_operand" "f")))
4006 (clobber (match_scratch:SF 2 "=d"))]
4007 "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
4008 {
4009 if (mips_nomacro.nesting_level > 0)
4010 return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
4011 else
4012 return "trunc.w.s %0,%1,%2";
4013 }
4014 [(set_attr "type" "fcvt")
4015 (set_attr "mode" "SF")
4016 (set_attr "cnv_mode" "S2I")
4017 (set_attr "insn_count" "9")])
4018
4019
4020 (define_insn "fix_truncdfdi2"
4021 [(set (match_operand:DI 0 "register_operand" "=f")
4022 (fix:DI (match_operand:DF 1 "register_operand" "f")))]
4023 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4024 "trunc.l.d %0,%1"
4025 [(set_attr "type" "fcvt")
4026 (set_attr "mode" "DF")
4027 (set_attr "cnv_mode" "D2I")])
4028
4029
4030 (define_insn "fix_truncsfdi2"
4031 [(set (match_operand:DI 0 "register_operand" "=f")
4032 (fix:DI (match_operand:SF 1 "register_operand" "f")))]
4033 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4034 "trunc.l.s %0,%1"
4035 [(set_attr "type" "fcvt")
4036 (set_attr "mode" "SF")
4037 (set_attr "cnv_mode" "S2I")])
4038
4039
4040 (define_insn "floatsidf2"
4041 [(set (match_operand:DF 0 "register_operand" "=f")
4042 (float:DF (match_operand:SI 1 "register_operand" "f")))]
4043 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4044 "cvt.d.w\t%0,%1"
4045 [(set_attr "type" "fcvt")
4046 (set_attr "mode" "DF")
4047 (set_attr "cnv_mode" "I2D")])
4048
4049
4050 (define_insn "floatdidf2"
4051 [(set (match_operand:DF 0 "register_operand" "=f")
4052 (float:DF (match_operand:DI 1 "register_operand" "f")))]
4053 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4054 "cvt.d.l\t%0,%1"
4055 [(set_attr "type" "fcvt")
4056 (set_attr "mode" "DF")
4057 (set_attr "cnv_mode" "I2D")])
4058
4059
4060 (define_insn "floatsisf2"
4061 [(set (match_operand:SF 0 "register_operand" "=f")
4062 (float:SF (match_operand:SI 1 "register_operand" "f")))]
4063 "TARGET_HARD_FLOAT"
4064 "cvt.s.w\t%0,%1"
4065 [(set_attr "type" "fcvt")
4066 (set_attr "mode" "SF")
4067 (set_attr "cnv_mode" "I2S")])
4068
4069
4070 (define_insn "floatdisf2"
4071 [(set (match_operand:SF 0 "register_operand" "=f")
4072 (float:SF (match_operand:DI 1 "register_operand" "f")))]
4073 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4074 "cvt.s.l\t%0,%1"
4075 [(set_attr "type" "fcvt")
4076 (set_attr "mode" "SF")
4077 (set_attr "cnv_mode" "I2S")])
4078
4079
4080 (define_expand "fixuns_truncdfsi2"
4081 [(set (match_operand:SI 0 "register_operand")
4082 (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
4083 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4084 {
4085 rtx reg1 = gen_reg_rtx (DFmode);
4086 rtx reg2 = gen_reg_rtx (DFmode);
4087 rtx reg3 = gen_reg_rtx (SImode);
4088 rtx_code_label *label1 = gen_label_rtx ();
4089 rtx_code_label *label2 = gen_label_rtx ();
4090 rtx test;
4091 REAL_VALUE_TYPE offset;
4092
4093 real_2expN (&offset, 31, DFmode);
4094
4095 if (reg1) /* Turn off complaints about unreached code. */
4096 {
4097 mips_emit_move (reg1, const_double_from_real_value (offset, DFmode));
4098 do_pending_stack_adjust ();
4099
4100 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4101 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
4102
4103 emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
4104 emit_jump_insn (gen_rtx_SET (pc_rtx,
4105 gen_rtx_LABEL_REF (VOIDmode, label2)));
4106 emit_barrier ();
4107
4108 emit_label (label1);
4109 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4110 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
4111 (BITMASK_HIGH, SImode)));
4112
4113 emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
4114 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4115
4116 emit_label (label2);
4117
4118 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4119 fields, and can't be used for REG_NOTES anyway). */
4120 emit_use (stack_pointer_rtx);
4121 DONE;
4122 }
4123 })
4124
4125
4126 (define_expand "fixuns_truncdfdi2"
4127 [(set (match_operand:DI 0 "register_operand")
4128 (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
4129 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4130 {
4131 rtx reg1 = gen_reg_rtx (DFmode);
4132 rtx reg2 = gen_reg_rtx (DFmode);
4133 rtx reg3 = gen_reg_rtx (DImode);
4134 rtx_code_label *label1 = gen_label_rtx ();
4135 rtx_code_label *label2 = gen_label_rtx ();
4136 rtx test;
4137 REAL_VALUE_TYPE offset;
4138
4139 real_2expN (&offset, 63, DFmode);
4140
4141 mips_emit_move (reg1, const_double_from_real_value (offset, DFmode));
4142 do_pending_stack_adjust ();
4143
4144 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4145 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
4146
4147 emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
4148 emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4149 emit_barrier ();
4150
4151 emit_label (label1);
4152 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4153 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4154 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4155
4156 emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
4157 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4158
4159 emit_label (label2);
4160
4161 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4162 fields, and can't be used for REG_NOTES anyway). */
4163 emit_use (stack_pointer_rtx);
4164 DONE;
4165 })
4166
4167
4168 (define_expand "fixuns_truncsfsi2"
4169 [(set (match_operand:SI 0 "register_operand")
4170 (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
4171 "TARGET_HARD_FLOAT"
4172 {
4173 rtx reg1 = gen_reg_rtx (SFmode);
4174 rtx reg2 = gen_reg_rtx (SFmode);
4175 rtx reg3 = gen_reg_rtx (SImode);
4176 rtx_code_label *label1 = gen_label_rtx ();
4177 rtx_code_label *label2 = gen_label_rtx ();
4178 rtx test;
4179 REAL_VALUE_TYPE offset;
4180
4181 real_2expN (&offset, 31, SFmode);
4182
4183 mips_emit_move (reg1, const_double_from_real_value (offset, SFmode));
4184 do_pending_stack_adjust ();
4185
4186 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4187 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4188
4189 emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
4190 emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4191 emit_barrier ();
4192
4193 emit_label (label1);
4194 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4195 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
4196 (BITMASK_HIGH, SImode)));
4197
4198 emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
4199 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4200
4201 emit_label (label2);
4202
4203 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4204 fields, and can't be used for REG_NOTES anyway). */
4205 emit_use (stack_pointer_rtx);
4206 DONE;
4207 })
4208
4209
4210 (define_expand "fixuns_truncsfdi2"
4211 [(set (match_operand:DI 0 "register_operand")
4212 (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
4213 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4214 {
4215 rtx reg1 = gen_reg_rtx (SFmode);
4216 rtx reg2 = gen_reg_rtx (SFmode);
4217 rtx reg3 = gen_reg_rtx (DImode);
4218 rtx_code_label *label1 = gen_label_rtx ();
4219 rtx_code_label *label2 = gen_label_rtx ();
4220 rtx test;
4221 REAL_VALUE_TYPE offset;
4222
4223 real_2expN (&offset, 63, SFmode);
4224
4225 mips_emit_move (reg1, const_double_from_real_value (offset, SFmode));
4226 do_pending_stack_adjust ();
4227
4228 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4229 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4230
4231 emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
4232 emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4233 emit_barrier ();
4234
4235 emit_label (label1);
4236 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4237 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4238 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4239
4240 emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
4241 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4242
4243 emit_label (label2);
4244
4245 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4246 fields, and can't be used for REG_NOTES anyway). */
4247 emit_use (stack_pointer_rtx);
4248 DONE;
4249 })
4250 \f
4251 ;;
4252 ;; ....................
4253 ;;
4254 ;; DATA MOVEMENT
4255 ;;
4256 ;; ....................
4257
4258 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
4259
4260 (define_expand "extvmisalign<mode>"
4261 [(set (match_operand:GPR 0 "register_operand")
4262 (sign_extract:GPR (match_operand:BLK 1 "memory_operand")
4263 (match_operand 2 "const_int_operand")
4264 (match_operand 3 "const_int_operand")))]
4265 "ISA_HAS_LWL_LWR"
4266 {
4267 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4268 INTVAL (operands[2]),
4269 INTVAL (operands[3]),
4270 /*unsigned=*/ false))
4271 DONE;
4272 else
4273 FAIL;
4274 })
4275
4276 (define_expand "extv<mode>"
4277 [(set (match_operand:GPR 0 "register_operand")
4278 (sign_extract:GPR (match_operand:GPR 1 "register_operand")
4279 (match_operand 2 "const_int_operand")
4280 (match_operand 3 "const_int_operand")))]
4281 "ISA_HAS_EXTS"
4282 {
4283 if (UINTVAL (operands[2]) > 32)
4284 FAIL;
4285 })
4286
4287 (define_insn "*extv<mode>"
4288 [(set (match_operand:GPR 0 "register_operand" "=d")
4289 (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4290 (match_operand 2 "const_int_operand" "")
4291 (match_operand 3 "const_int_operand" "")))]
4292 "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
4293 "exts\t%0,%1,%3,%m2"
4294 [(set_attr "type" "arith")
4295 (set_attr "mode" "<MODE>")])
4296
4297 (define_expand "extzvmisalign<mode>"
4298 [(set (match_operand:GPR 0 "register_operand")
4299 (zero_extract:GPR (match_operand:BLK 1 "memory_operand")
4300 (match_operand 2 "const_int_operand")
4301 (match_operand 3 "const_int_operand")))]
4302 "ISA_HAS_LWL_LWR"
4303 {
4304 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4305 INTVAL (operands[2]),
4306 INTVAL (operands[3]),
4307 /*unsigned=*/ true))
4308 DONE;
4309 else
4310 FAIL;
4311 })
4312
4313 (define_expand "extzv<mode>"
4314 [(set (match_operand:GPR 0 "register_operand")
4315 (zero_extract:GPR (match_operand:GPR 1 "register_operand")
4316 (match_operand 2 "const_int_operand")
4317 (match_operand 3 "const_int_operand")))]
4318 ""
4319 {
4320 if (!mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4321 INTVAL (operands[3])))
4322 FAIL;
4323 })
4324
4325 (define_insn "*extzv<mode>"
4326 [(set (match_operand:GPR 0 "register_operand" "=d")
4327 (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4328 (match_operand 2 "const_int_operand" "")
4329 (match_operand 3 "const_int_operand" "")))]
4330 "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4331 INTVAL (operands[3]))"
4332 "<d>ext\t%0,%1,%3,%2"
4333 [(set_attr "type" "arith")
4334 (set_attr "mode" "<MODE>")])
4335
4336 (define_insn "*extzv_truncsi_exts"
4337 [(set (match_operand:SI 0 "register_operand" "=d")
4338 (truncate:SI
4339 (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
4340 (match_operand 2 "const_int_operand" "")
4341 (match_operand 3 "const_int_operand" ""))))]
4342 "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
4343 "exts\t%0,%1,%3,31"
4344 [(set_attr "type" "arith")
4345 (set_attr "mode" "SI")])
4346
4347
4348 (define_expand "insvmisalign<mode>"
4349 [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand")
4350 (match_operand 1 "const_int_operand")
4351 (match_operand 2 "const_int_operand"))
4352 (match_operand:GPR 3 "reg_or_0_operand"))]
4353 "ISA_HAS_LWL_LWR"
4354 {
4355 if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
4356 INTVAL (operands[1]),
4357 INTVAL (operands[2])))
4358 DONE;
4359 else
4360 FAIL;
4361 })
4362
4363 (define_expand "insv<mode>"
4364 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand")
4365 (match_operand 1 "const_int_operand")
4366 (match_operand 2 "const_int_operand"))
4367 (match_operand:GPR 3 "reg_or_0_operand"))]
4368 ""
4369 {
4370 if (!mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4371 INTVAL (operands[2])))
4372 FAIL;
4373 })
4374
4375 (define_insn "*insv<mode>"
4376 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
4377 (match_operand:SI 1 "const_int_operand" "")
4378 (match_operand:SI 2 "const_int_operand" ""))
4379 (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
4380 "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4381 INTVAL (operands[2]))"
4382 "<d>ins\t%0,%z3,%2,%1"
4383 [(set_attr "type" "arith")
4384 (set_attr "mode" "<MODE>")])
4385
4386 ;; Combiner pattern for cins (clear and insert bit field). We can
4387 ;; implement mask-and-shift-left operation with this. Note that if
4388 ;; the upper bit of the mask is set in an SImode operation, the mask
4389 ;; itself will be sign-extended. mask_low_and_shift_len will
4390 ;; therefore be greater than our threshold of 32.
4391
4392 (define_insn "*cins<mode>"
4393 [(set (match_operand:GPR 0 "register_operand" "=d")
4394 (and:GPR
4395 (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
4396 (match_operand:GPR 2 "const_int_operand" ""))
4397 (match_operand:GPR 3 "const_int_operand" "")))]
4398 "ISA_HAS_CINS
4399 && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
4400 {
4401 operands[3] =
4402 GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
4403 return "cins\t%0,%1,%2,%m3";
4404 }
4405 [(set_attr "type" "shift")
4406 (set_attr "mode" "<MODE>")])
4407
4408 ;; Unaligned word moves generated by the bit field patterns.
4409 ;;
4410 ;; As far as the rtl is concerned, both the left-part and right-part
4411 ;; instructions can access the whole field. However, the real operand
4412 ;; refers to just the first or the last byte (depending on endianness).
4413 ;; We therefore use two memory operands to each instruction, one to
4414 ;; describe the rtl effect and one to use in the assembly output.
4415 ;;
4416 ;; Operands 0 and 1 are the rtl-level target and source respectively.
4417 ;; This allows us to use the standard length calculations for the "load"
4418 ;; and "store" type attributes.
4419
4420 (define_insn "mov_<load>l"
4421 [(set (match_operand:GPR 0 "register_operand" "=d")
4422 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4423 (match_operand:QI 2 "memory_operand" "ZC")]
4424 UNSPEC_LOAD_LEFT))]
4425 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4426 "<load>l\t%0,%2"
4427 [(set_attr "move_type" "load")
4428 (set_attr "mode" "<MODE>")])
4429
4430 (define_insn "mov_<load>r"
4431 [(set (match_operand:GPR 0 "register_operand" "=d")
4432 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4433 (match_operand:QI 2 "memory_operand" "ZC")
4434 (match_operand:GPR 3 "register_operand" "0")]
4435 UNSPEC_LOAD_RIGHT))]
4436 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4437 "<load>r\t%0,%2"
4438 [(set_attr "move_type" "load")
4439 (set_attr "mode" "<MODE>")])
4440
4441 (define_insn "mov_<store>l"
4442 [(set (match_operand:BLK 0 "memory_operand" "=m")
4443 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4444 (match_operand:QI 2 "memory_operand" "ZC")]
4445 UNSPEC_STORE_LEFT))]
4446 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4447 "<store>l\t%z1,%2"
4448 [(set_attr "move_type" "store")
4449 (set_attr "mode" "<MODE>")])
4450
4451 (define_insn "mov_<store>r"
4452 [(set (match_operand:BLK 0 "memory_operand" "+m")
4453 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4454 (match_operand:QI 2 "memory_operand" "ZC")
4455 (match_dup 0)]
4456 UNSPEC_STORE_RIGHT))]
4457 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4458 "<store>r\t%z1,%2"
4459 [(set_attr "move_type" "store")
4460 (set_attr "mode" "<MODE>")])
4461
4462 ;; Unaligned direct access
4463 (define_expand "movmisalign<mode>"
4464 [(set (match_operand:JOIN_MODE 0)
4465 (match_operand:JOIN_MODE 1))]
4466 "ISA_HAS_UNALIGNED_ACCESS"
4467 {
4468 if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4469 DONE;
4470 })
4471
4472 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
4473 ;; The required value is:
4474 ;;
4475 ;; (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
4476 ;;
4477 ;; which translates to:
4478 ;;
4479 ;; lui op0,%highest(op1)
4480 ;; daddiu op0,op0,%higher(op1)
4481 ;; dsll op0,op0,16
4482 ;; daddiu op0,op0,%hi(op1)
4483 ;; dsll op0,op0,16
4484 ;;
4485 ;; The split is deferred until after flow2 to allow the peephole2 below
4486 ;; to take effect.
4487 (define_insn_and_split "*lea_high64"
4488 [(set (match_operand:DI 0 "register_operand" "=d")
4489 (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
4490 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4491 "#"
4492 "&& epilogue_completed"
4493 [(set (match_dup 0) (high:DI (match_dup 2)))
4494 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
4495 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
4496 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4497 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
4498 {
4499 operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4500 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
4501 }
4502 [(set_attr "insn_count" "5")])
4503
4504 ;; Use a scratch register to reduce the latency of the above pattern
4505 ;; on superscalar machines. The optimized sequence is:
4506 ;;
4507 ;; lui op1,%highest(op2)
4508 ;; lui op0,%hi(op2)
4509 ;; daddiu op1,op1,%higher(op2)
4510 ;; dsll32 op1,op1,0
4511 ;; daddu op1,op1,op0
4512 (define_peephole2
4513 [(set (match_operand:DI 1 "d_operand")
4514 (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4515 (match_scratch:DI 0 "d")]
4516 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4517 [(set (match_dup 1) (high:DI (match_dup 3)))
4518 (set (match_dup 0) (high:DI (match_dup 4)))
4519 (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4520 (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4521 (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4522 {
4523 operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4524 operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4525 })
4526
4527 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4528 ;; SYMBOL_ABSOLUTE X will take 6 cycles. This next pattern allows combine
4529 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4530 ;; used once. We can then use the sequence:
4531 ;;
4532 ;; lui op0,%highest(op1)
4533 ;; lui op2,%hi(op1)
4534 ;; daddiu op0,op0,%higher(op1)
4535 ;; daddiu op2,op2,%lo(op1)
4536 ;; dsll32 op0,op0,0
4537 ;; daddu op0,op0,op2
4538 ;;
4539 ;; which takes 4 cycles on most superscalar targets.
4540 (define_insn_and_split "*lea64"
4541 [(set (match_operand:DI 0 "register_operand" "=d")
4542 (match_operand:DI 1 "absolute_symbolic_operand" ""))
4543 (clobber (match_scratch:DI 2 "=&d"))]
4544 "!TARGET_MIPS16
4545 && TARGET_EXPLICIT_RELOCS
4546 && ABI_HAS_64BIT_SYMBOLS
4547 && cse_not_expected"
4548 "#"
4549 "&& reload_completed"
4550 [(set (match_dup 0) (high:DI (match_dup 3)))
4551 (set (match_dup 2) (high:DI (match_dup 4)))
4552 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4553 (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4554 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4555 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4556 {
4557 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4558 operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4559 }
4560 [(set_attr "insn_count" "6")])
4561
4562 ;; Split HIGHs into:
4563 ;;
4564 ;; li op0,%hi(sym)
4565 ;; sll op0,16
4566 ;;
4567 ;; on MIPS16 targets.
4568 (define_split
4569 [(set (match_operand:P 0 "d_operand")
4570 (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4571 "TARGET_MIPS16 && reload_completed"
4572 [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4573 (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4574
4575 (define_insn "*unshifted_high"
4576 [(set (match_operand:P 0 "d_operand" "=d")
4577 (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4578 UNSPEC_UNSHIFTED_HIGH))]
4579 ""
4580 "li\t%0,%h1"
4581 [(set_attr "extended_mips16" "yes")])
4582
4583 ;; Insns to fetch a symbol from a big GOT.
4584
4585 (define_insn_and_split "*xgot_hi<mode>"
4586 [(set (match_operand:P 0 "register_operand" "=d")
4587 (high:P (match_operand:P 1 "got_disp_operand" "")))]
4588 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4589 "#"
4590 "&& reload_completed"
4591 [(set (match_dup 0) (high:P (match_dup 2)))
4592 (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4593 {
4594 operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4595 operands[3] = pic_offset_table_rtx;
4596 }
4597 [(set_attr "got" "xgot_high")
4598 (set_attr "mode" "<MODE>")])
4599
4600 (define_insn_and_split "*xgot_lo<mode>"
4601 [(set (match_operand:P 0 "register_operand" "=d")
4602 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4603 (match_operand:P 2 "got_disp_operand" "")))]
4604 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4605 "#"
4606 "&& reload_completed"
4607 [(set (match_dup 0)
4608 (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4609 { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4610 [(set_attr "got" "load")
4611 (set_attr "mode" "<MODE>")])
4612
4613 ;; Insns to fetch a symbol from a normal GOT.
4614
4615 (define_insn_and_split "*got_disp<mode>"
4616 [(set (match_operand:P 0 "register_operand" "=d")
4617 (match_operand:P 1 "got_disp_operand" ""))]
4618 "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4619 "#"
4620 "&& reload_completed"
4621 [(set (match_dup 0) (match_dup 2))]
4622 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4623 [(set_attr "got" "load")
4624 (set_attr "mode" "<MODE>")])
4625
4626 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4627
4628 (define_insn_and_split "*got_page<mode>"
4629 [(set (match_operand:P 0 "register_operand" "=d")
4630 (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4631 "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4632 "#"
4633 "&& reload_completed"
4634 [(set (match_dup 0) (match_dup 2))]
4635 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4636 [(set_attr "got" "load")
4637 (set_attr "mode" "<MODE>")])
4638
4639 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4640 (define_expand "unspec_got_<mode>"
4641 [(unspec:P [(match_operand:P 0)
4642 (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4643
4644 ;; Lower-level instructions for loading an address from the GOT.
4645 ;; We could use MEMs, but an unspec gives more optimization
4646 ;; opportunities.
4647
4648 (define_insn "load_got<mode>"
4649 [(set (match_operand:P 0 "register_operand" "=d")
4650 (unspec:P [(match_operand:P 1 "register_operand" "d")
4651 (match_operand:P 2 "immediate_operand" "")]
4652 UNSPEC_LOAD_GOT))]
4653 ""
4654 "<load>\t%0,%R2(%1)"
4655 [(set_attr "got" "load")
4656 (set_attr "mode" "<MODE>")])
4657
4658 ;; Instructions for adding the low 16 bits of an address to a register.
4659 ;; Operand 2 is the address: mips_print_operand works out which relocation
4660 ;; should be applied.
4661
4662 (define_insn "*low<mode>"
4663 [(set (match_operand:P 0 "register_operand" "=d")
4664 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4665 (match_operand:P 2 "immediate_operand" "")))]
4666 "!TARGET_MIPS16"
4667 "<d>addiu\t%0,%1,%R2"
4668 [(set_attr "alu_type" "add")
4669 (set_attr "mode" "<MODE>")])
4670
4671 (define_insn "*low<mode>_mips16"
4672 [(set (match_operand:P 0 "register_operand" "=d")
4673 (lo_sum:P (match_operand:P 1 "register_operand" "0")
4674 (match_operand:P 2 "immediate_operand" "")))]
4675 "TARGET_MIPS16"
4676 "<d>addiu\t%0,%R2"
4677 [(set_attr "alu_type" "add")
4678 (set_attr "mode" "<MODE>")
4679 (set_attr "extended_mips16" "yes")])
4680
4681 ;; Expose MIPS16 uses of the global pointer after reload if the function
4682 ;; is responsible for setting up the register itself.
4683 (define_split
4684 [(set (match_operand:GPR 0 "d_operand")
4685 (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4686 "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4687 [(set (match_dup 0) (match_dup 1))]
4688 { operands[1] = pic_offset_table_rtx; })
4689
4690 ;; Allow combine to split complex const_int load sequences, using operand 2
4691 ;; to store the intermediate results. See move_operand for details.
4692 (define_split
4693 [(set (match_operand:GPR 0 "register_operand")
4694 (match_operand:GPR 1 "splittable_const_int_operand"))
4695 (clobber (match_operand:GPR 2 "register_operand"))]
4696 ""
4697 [(const_int 0)]
4698 {
4699 mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4700 DONE;
4701 })
4702
4703 ;; Likewise, for symbolic operands.
4704 (define_split
4705 [(set (match_operand:P 0 "register_operand")
4706 (match_operand:P 1))
4707 (clobber (match_operand:P 2 "register_operand"))]
4708 "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4709 [(set (match_dup 0) (match_dup 3))]
4710 {
4711 mips_split_symbol (operands[2], operands[1],
4712 MAX_MACHINE_MODE, &operands[3]);
4713 })
4714
4715 ;; 64-bit integer moves
4716
4717 ;; Unlike most other insns, the move insns can't be split with
4718 ;; different predicates, because register spilling and other parts of
4719 ;; the compiler, have memoized the insn number already.
4720
4721 (define_expand "movdi"
4722 [(set (match_operand:DI 0 "")
4723 (match_operand:DI 1 ""))]
4724 ""
4725 {
4726 if (mips_legitimize_move (DImode, operands[0], operands[1]))
4727 DONE;
4728 })
4729
4730 ;; For mips16, we need a special case to handle storing $31 into
4731 ;; memory, since we don't have a constraint to match $31. This
4732 ;; instruction can be generated by save_restore_insns.
4733
4734 (define_insn "*mov<mode>_ra"
4735 [(set (match_operand:GPR 0 "stack_operand" "=m")
4736 (reg:GPR RETURN_ADDR_REGNUM))]
4737 "TARGET_MIPS16"
4738 "<store>\t$31,%0"
4739 [(set_attr "move_type" "store")
4740 (set_attr "mode" "<MODE>")])
4741
4742 (define_insn "*movdi_32bit"
4743 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d,*f,*f,*d,*m,*B*C*D,*B*C*D,*d,*m")
4744 (match_operand:DI 1 "move_operand" "d,i,m,d,*J,*d,*a,*J*d,*m,*f,*f,*d,*m,*B*C*D,*B*C*D"))]
4745 "!TARGET_64BIT && !TARGET_MIPS16
4746 && (register_operand (operands[0], DImode)
4747 || reg_or_0_operand (operands[1], DImode))"
4748 { return mips_output_move (operands[0], operands[1]); }
4749 [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4750 (set (attr "mode")
4751 (if_then_else (eq_attr "move_type" "imul")
4752 (const_string "SI")
4753 (const_string "DI")))])
4754
4755 (define_insn "*movdi_32bit_mips16"
4756 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4757 (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4758 "!TARGET_64BIT && TARGET_MIPS16
4759 && (register_operand (operands[0], DImode)
4760 || register_operand (operands[1], DImode))"
4761 { return mips_output_move (operands[0], operands[1]); }
4762 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4763 (set_attr "mode" "DI")])
4764
4765 (define_insn "*movdi_64bit"
4766 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*d,*m,*a,*d,*B*C*D,*B*C*D,*d,*m")
4767 (match_operand:DI 1 "move_operand" "d,Yd,Yf,m,dJ,*d*J,*m,*f,*f,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4768 "TARGET_64BIT && !TARGET_MIPS16
4769 && (register_operand (operands[0], DImode)
4770 || reg_or_0_operand (operands[1], DImode))"
4771 { return mips_output_move (operands[0], operands[1]); }
4772 [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4773 (set_attr "mode" "DI")])
4774
4775 (define_insn "*movdi_64bit_mips16"
4776 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4777 (match_operand:DI 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4778 "TARGET_64BIT && TARGET_MIPS16
4779 && (register_operand (operands[0], DImode)
4780 || register_operand (operands[1], DImode))"
4781 { return mips_output_move (operands[0], operands[1]); }
4782 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4783 (set_attr "mode" "DI")])
4784
4785 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4786 ;; when the original load is a 4 byte instruction but the add and the
4787 ;; load are 2 2 byte instructions.
4788
4789 (define_split
4790 [(set (match_operand:DI 0 "d_operand")
4791 (mem:DI (plus:DI (match_dup 0)
4792 (match_operand:DI 1 "const_int_operand"))))]
4793 "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4794 && !TARGET_DEBUG_D_MODE
4795 && ((INTVAL (operands[1]) < 0
4796 && INTVAL (operands[1]) >= -0x10)
4797 || (INTVAL (operands[1]) >= 32 * 8
4798 && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4799 || (INTVAL (operands[1]) >= 0
4800 && INTVAL (operands[1]) < 32 * 8
4801 && (INTVAL (operands[1]) & 7) != 0))"
4802 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4803 (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4804 {
4805 HOST_WIDE_INT val = INTVAL (operands[1]);
4806
4807 if (val < 0)
4808 operands[2] = const0_rtx;
4809 else if (val >= 32 * 8)
4810 {
4811 int off = val & 7;
4812
4813 operands[1] = GEN_INT (0x8 + off);
4814 operands[2] = GEN_INT (val - off - 0x8);
4815 }
4816 else
4817 {
4818 int off = val & 7;
4819
4820 operands[1] = GEN_INT (off);
4821 operands[2] = GEN_INT (val - off);
4822 }
4823 })
4824
4825 ;; 32-bit Integer moves
4826
4827 ;; Unlike most other insns, the move insns can't be split with
4828 ;; different predicates, because register spilling and other parts of
4829 ;; the compiler, have memoized the insn number already.
4830
4831 (define_expand "mov<mode>"
4832 [(set (match_operand:IMOVE32 0 "")
4833 (match_operand:IMOVE32 1 ""))]
4834 ""
4835 {
4836 if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4837 DONE;
4838 })
4839
4840 ;; The difference between these two is whether or not ints are allowed
4841 ;; in FP registers (off by default, use -mdebugh to enable).
4842
4843 (define_insn "*mov<mode>_internal"
4844 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,!u,!u,d,e,!u,!ks,d,ZS,ZT,m,*f,*f,*d,*m,*d,*z,*a,*d,*B*C*D,*B*C*D,*d,*m")
4845 (match_operand:IMOVE32 1 "move_operand" "d,J,Udb7,Yd,Yf,ZT,ZS,m,!ks,!kbJ,dJ,*d*J,*m,*f,*f,*z,*d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4846 "!TARGET_MIPS16
4847 && (register_operand (operands[0], <MODE>mode)
4848 || reg_or_0_operand (operands[1], <MODE>mode))"
4849 { return mips_output_move (operands[0], operands[1]); }
4850 [(set_attr "move_type" "move,move,const,const,const,load,load,load,store,store,store,mtc,fpload,mfc,fpstore,mfc,mtc,mtlo,mflo,mtc,fpload,mfc,fpstore")
4851 (set_attr "compression" "all,micromips,micromips,*,*,micromips,micromips,*,micromips,micromips,*,*,*,*,*,*,*,*,*,*,*,*,*")
4852 (set_attr "mode" "SI")])
4853
4854 (define_insn "*mov<mode>_mips16"
4855 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4856 (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4857 "TARGET_MIPS16
4858 && (register_operand (operands[0], <MODE>mode)
4859 || register_operand (operands[1], <MODE>mode))"
4860 { return mips_output_move (operands[0], operands[1]); }
4861 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4862 (set_attr "mode" "SI")])
4863
4864 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4865 ;; when the original load is a 4 byte instruction but the add and the
4866 ;; load are 2 2 byte instructions.
4867
4868 (define_split
4869 [(set (match_operand:SI 0 "d_operand")
4870 (mem:SI (plus:SI (match_dup 0)
4871 (match_operand:SI 1 "const_int_operand"))))]
4872 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4873 && ((INTVAL (operands[1]) < 0
4874 && INTVAL (operands[1]) >= -0x80)
4875 || (INTVAL (operands[1]) >= 32 * 4
4876 && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4877 || (INTVAL (operands[1]) >= 0
4878 && INTVAL (operands[1]) < 32 * 4
4879 && (INTVAL (operands[1]) & 3) != 0))"
4880 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4881 (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4882 {
4883 HOST_WIDE_INT val = INTVAL (operands[1]);
4884
4885 if (val < 0)
4886 operands[2] = const0_rtx;
4887 else if (val >= 32 * 4)
4888 {
4889 int off = val & 3;
4890
4891 operands[1] = GEN_INT (0x7c + off);
4892 operands[2] = GEN_INT (val - off - 0x7c);
4893 }
4894 else
4895 {
4896 int off = val & 3;
4897
4898 operands[1] = GEN_INT (off);
4899 operands[2] = GEN_INT (val - off);
4900 }
4901 })
4902
4903 ;; On the mips16, we can split a load of certain constants into a load
4904 ;; and an add. This turns a 4 byte instruction into 2 2 byte
4905 ;; instructions.
4906
4907 (define_split
4908 [(set (match_operand:SI 0 "d_operand")
4909 (match_operand:SI 1 "const_int_operand"))]
4910 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4911 && INTVAL (operands[1]) >= 0x100
4912 && INTVAL (operands[1]) <= 0xff + 0x7f"
4913 [(set (match_dup 0) (match_dup 1))
4914 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4915 {
4916 int val = INTVAL (operands[1]);
4917
4918 operands[1] = GEN_INT (0xff);
4919 operands[2] = GEN_INT (val - 0xff);
4920 })
4921
4922 ;; MIPS4 supports loading and storing a floating point register from
4923 ;; the sum of two general registers. We use two versions for each of
4924 ;; these four instructions: one where the two general registers are
4925 ;; SImode, and one where they are DImode. This is because general
4926 ;; registers will be in SImode when they hold 32-bit values, but,
4927 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4928 ;; instructions will still work correctly.
4929
4930 ;; ??? Perhaps it would be better to support these instructions by
4931 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends. However, since
4932 ;; these instructions can only be used to load and store floating
4933 ;; point registers, that would probably cause trouble in reload.
4934
4935 (define_insn "*<ANYF:loadx>_<P:mode>"
4936 [(set (match_operand:ANYF 0 "register_operand" "=f")
4937 (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4938 (match_operand:P 2 "register_operand" "d"))))]
4939 "ISA_HAS_LXC1_SXC1"
4940 "<ANYF:loadx>\t%0,%1(%2)"
4941 [(set_attr "type" "fpidxload")
4942 (set_attr "mode" "<ANYF:UNITMODE>")])
4943
4944 (define_insn "*<ANYF:storex>_<P:mode>"
4945 [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4946 (match_operand:P 2 "register_operand" "d")))
4947 (match_operand:ANYF 0 "register_operand" "f"))]
4948 "ISA_HAS_LXC1_SXC1"
4949 "<ANYF:storex>\t%0,%1(%2)"
4950 [(set_attr "type" "fpidxstore")
4951 (set_attr "mode" "<ANYF:UNITMODE>")])
4952
4953 ;; Scaled indexed address load.
4954 ;; Per md.texi, we only need to look for a pattern with multiply in the
4955 ;; address expression, not shift.
4956
4957 (define_insn "*lwxs"
4958 [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4959 (mem:IMOVE32
4960 (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4961 (const_int 4))
4962 (match_operand:P 2 "register_operand" "d"))))]
4963 "ISA_HAS_LWXS"
4964 "lwxs\t%0,%1(%2)"
4965 [(set_attr "type" "load")
4966 (set_attr "mode" "SI")])
4967
4968 ;; 16-bit Integer moves
4969
4970 ;; Unlike most other insns, the move insns can't be split with
4971 ;; different predicates, because register spilling and other parts of
4972 ;; the compiler, have memoized the insn number already.
4973 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4974
4975 (define_expand "movhi"
4976 [(set (match_operand:HI 0 "")
4977 (match_operand:HI 1 ""))]
4978 ""
4979 {
4980 if (mips_legitimize_move (HImode, operands[0], operands[1]))
4981 DONE;
4982 })
4983
4984 (define_insn "*movhi_internal"
4985 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZU,m,*a,*d")
4986 (match_operand:HI 1 "move_operand" "d,J,I,ZU,m,!kbJ,dJ,*d*J,*a"))]
4987 "!TARGET_MIPS16
4988 && (register_operand (operands[0], HImode)
4989 || reg_or_0_operand (operands[1], HImode))"
4990 { return mips_output_move (operands[0], operands[1]); }
4991 [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4992 (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4993 (set_attr "mode" "HI")])
4994
4995 (define_insn "*movhi_mips16"
4996 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4997 (match_operand:HI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4998 "TARGET_MIPS16
4999 && (register_operand (operands[0], HImode)
5000 || register_operand (operands[1], HImode))"
5001 { return mips_output_move (operands[0], operands[1]); }
5002 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5003 (set_attr "mode" "HI")])
5004
5005 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
5006 ;; when the original load is a 4 byte instruction but the add and the
5007 ;; load are 2 2 byte instructions.
5008
5009 (define_split
5010 [(set (match_operand:HI 0 "d_operand")
5011 (mem:HI (plus:SI (match_dup 0)
5012 (match_operand:SI 1 "const_int_operand"))))]
5013 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5014 && ((INTVAL (operands[1]) < 0
5015 && INTVAL (operands[1]) >= -0x80)
5016 || (INTVAL (operands[1]) >= 32 * 2
5017 && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
5018 || (INTVAL (operands[1]) >= 0
5019 && INTVAL (operands[1]) < 32 * 2
5020 && (INTVAL (operands[1]) & 1) != 0))"
5021 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5022 (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
5023 {
5024 HOST_WIDE_INT val = INTVAL (operands[1]);
5025
5026 if (val < 0)
5027 operands[2] = const0_rtx;
5028 else if (val >= 32 * 2)
5029 {
5030 int off = val & 1;
5031
5032 operands[1] = GEN_INT (0x7e + off);
5033 operands[2] = GEN_INT (val - off - 0x7e);
5034 }
5035 else
5036 {
5037 int off = val & 1;
5038
5039 operands[1] = GEN_INT (off);
5040 operands[2] = GEN_INT (val - off);
5041 }
5042 })
5043
5044 ;; 8-bit Integer moves
5045
5046 ;; Unlike most other insns, the move insns can't be split with
5047 ;; different predicates, because register spilling and other parts of
5048 ;; the compiler, have memoized the insn number already.
5049 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
5050
5051 (define_expand "movqi"
5052 [(set (match_operand:QI 0 "")
5053 (match_operand:QI 1 ""))]
5054 ""
5055 {
5056 if (mips_legitimize_move (QImode, operands[0], operands[1]))
5057 DONE;
5058 })
5059
5060 (define_insn "*movqi_internal"
5061 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZV,m,*a,*d")
5062 (match_operand:QI 1 "move_operand" "d,J,I,ZW,m,!kbJ,dJ,*d*J,*a"))]
5063 "!TARGET_MIPS16
5064 && (register_operand (operands[0], QImode)
5065 || reg_or_0_operand (operands[1], QImode))"
5066 { return mips_output_move (operands[0], operands[1]); }
5067 [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
5068 (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
5069 (set_attr "mode" "QI")])
5070
5071 (define_insn "*movqi_mips16"
5072 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5073 (match_operand:QI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
5074 "TARGET_MIPS16
5075 && (register_operand (operands[0], QImode)
5076 || register_operand (operands[1], QImode))"
5077 { return mips_output_move (operands[0], operands[1]); }
5078 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5079 (set_attr "mode" "QI")])
5080
5081 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
5082 ;; when the original load is a 4 byte instruction but the add and the
5083 ;; load are 2 2 byte instructions.
5084
5085 (define_split
5086 [(set (match_operand:QI 0 "d_operand")
5087 (mem:QI (plus:SI (match_dup 0)
5088 (match_operand:SI 1 "const_int_operand"))))]
5089 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5090 && ((INTVAL (operands[1]) < 0
5091 && INTVAL (operands[1]) >= -0x80)
5092 || (INTVAL (operands[1]) >= 32
5093 && INTVAL (operands[1]) <= 31 + 0x7f))"
5094 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5095 (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
5096 {
5097 HOST_WIDE_INT val = INTVAL (operands[1]);
5098
5099 if (val < 0)
5100 operands[2] = const0_rtx;
5101 else
5102 {
5103 operands[1] = GEN_INT (0x7f);
5104 operands[2] = GEN_INT (val - 0x7f);
5105 }
5106 })
5107
5108 ;; 32-bit floating point moves
5109
5110 (define_expand "movsf"
5111 [(set (match_operand:SF 0 "")
5112 (match_operand:SF 1 ""))]
5113 ""
5114 {
5115 if (mips_legitimize_move (SFmode, operands[0], operands[1]))
5116 DONE;
5117 })
5118
5119 (define_insn "movccf"
5120 [(set (match_operand:CCF 0 "nonimmediate_operand" "=f,f,m")
5121 (match_operand:CCF 1 "nonimmediate_operand" "f,m,f"))]
5122 "ISA_HAS_CCF"
5123 { return mips_output_move (operands[0], operands[1]); }
5124 [(set_attr "move_type" "fmove,fpload,fpstore")])
5125
5126 (define_insn "*movsf_hardfloat"
5127 [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5128 (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
5129 "TARGET_HARD_FLOAT
5130 && (register_operand (operands[0], SFmode)
5131 || reg_or_0_operand (operands[1], SFmode))"
5132 { return mips_output_move (operands[0], operands[1]); }
5133 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5134 (set_attr "mode" "SF")])
5135
5136 (define_insn "*movsf_softfloat"
5137 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
5138 (match_operand:SF 1 "move_operand" "Gd,m,d"))]
5139 "TARGET_SOFT_FLOAT && !TARGET_MIPS16
5140 && (register_operand (operands[0], SFmode)
5141 || reg_or_0_operand (operands[1], SFmode))"
5142 { return mips_output_move (operands[0], operands[1]); }
5143 [(set_attr "move_type" "move,load,store")
5144 (set_attr "mode" "SF")])
5145
5146 (define_insn "*movsf_mips16"
5147 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
5148 (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
5149 "TARGET_MIPS16
5150 && (register_operand (operands[0], SFmode)
5151 || register_operand (operands[1], SFmode))"
5152 { return mips_output_move (operands[0], operands[1]); }
5153 [(set_attr "move_type" "move,move,move,load,store")
5154 (set_attr "mode" "SF")])
5155
5156 ;; 64-bit floating point moves
5157
5158 (define_expand "movdf"
5159 [(set (match_operand:DF 0 "")
5160 (match_operand:DF 1 ""))]
5161 ""
5162 {
5163 if (mips_legitimize_move (DFmode, operands[0], operands[1]))
5164 DONE;
5165 })
5166
5167 (define_insn "*movdf_hardfloat"
5168 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5169 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
5170 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
5171 && (register_operand (operands[0], DFmode)
5172 || reg_or_0_operand (operands[1], DFmode))"
5173 { return mips_output_move (operands[0], operands[1]); }
5174 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5175 (set_attr "mode" "DF")])
5176
5177 (define_insn "*movdf_softfloat"
5178 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
5179 (match_operand:DF 1 "move_operand" "dG,m,dG"))]
5180 "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
5181 && (register_operand (operands[0], DFmode)
5182 || reg_or_0_operand (operands[1], DFmode))"
5183 { return mips_output_move (operands[0], operands[1]); }
5184 [(set_attr "move_type" "move,load,store")
5185 (set_attr "mode" "DF")])
5186
5187 (define_insn "*movdf_mips16"
5188 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
5189 (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
5190 "TARGET_MIPS16
5191 && (register_operand (operands[0], DFmode)
5192 || register_operand (operands[1], DFmode))"
5193 { return mips_output_move (operands[0], operands[1]); }
5194 [(set_attr "move_type" "move,move,move,load,store")
5195 (set_attr "mode" "DF")])
5196
5197 ;; 128-bit integer moves
5198
5199 (define_expand "movti"
5200 [(set (match_operand:TI 0)
5201 (match_operand:TI 1))]
5202 "TARGET_64BIT"
5203 {
5204 if (mips_legitimize_move (TImode, operands[0], operands[1]))
5205 DONE;
5206 })
5207
5208 (define_insn "*movti"
5209 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d")
5210 (match_operand:TI 1 "move_operand" "d,i,m,dJ,*J,*d,*a"))]
5211 "TARGET_64BIT
5212 && !TARGET_MIPS16
5213 && (register_operand (operands[0], TImode)
5214 || reg_or_0_operand (operands[1], TImode))"
5215 { return mips_output_move (operands[0], operands[1]); }
5216 [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo")
5217 (set (attr "mode")
5218 (if_then_else (eq_attr "move_type" "imul")
5219 (const_string "SI")
5220 (const_string "TI")))])
5221
5222 (define_insn "*movti_mips16"
5223 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5224 (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
5225 "TARGET_64BIT
5226 && TARGET_MIPS16
5227 && (register_operand (operands[0], TImode)
5228 || register_operand (operands[1], TImode))"
5229 "#"
5230 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5231 (set_attr "mode" "TI")])
5232
5233 ;; 128-bit floating point moves
5234
5235 (define_expand "movtf"
5236 [(set (match_operand:TF 0)
5237 (match_operand:TF 1))]
5238 "TARGET_64BIT"
5239 {
5240 if (mips_legitimize_move (TFmode, operands[0], operands[1]))
5241 DONE;
5242 })
5243
5244 ;; This pattern handles both hard- and soft-float cases.
5245 (define_insn "*movtf"
5246 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
5247 (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
5248 "TARGET_64BIT
5249 && !TARGET_MIPS16
5250 && (register_operand (operands[0], TFmode)
5251 || reg_or_0_operand (operands[1], TFmode))"
5252 "#"
5253 [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
5254 (set_attr "mode" "TF")])
5255
5256 (define_insn "*movtf_mips16"
5257 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
5258 (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
5259 "TARGET_64BIT
5260 && TARGET_MIPS16
5261 && (register_operand (operands[0], TFmode)
5262 || register_operand (operands[1], TFmode))"
5263 "#"
5264 [(set_attr "move_type" "move,move,move,load,store")
5265 (set_attr "mode" "TF")])
5266
5267 (define_split
5268 [(set (match_operand:MOVE64 0 "nonimmediate_operand")
5269 (match_operand:MOVE64 1 "move_operand"))]
5270 "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5271 [(const_int 0)]
5272 {
5273 mips_split_move_insn (operands[0], operands[1], curr_insn);
5274 DONE;
5275 })
5276
5277 (define_split
5278 [(set (match_operand:MOVE128 0 "nonimmediate_operand")
5279 (match_operand:MOVE128 1 "move_operand"))]
5280 "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5281 [(const_int 0)]
5282 {
5283 mips_split_move_insn (operands[0], operands[1], curr_insn);
5284 DONE;
5285 })
5286
5287 ;; When generating mips16 code, split moves of negative constants into
5288 ;; a positive "li" followed by a negation.
5289 (define_split
5290 [(set (match_operand 0 "d_operand")
5291 (match_operand 1 "const_int_operand"))]
5292 "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
5293 [(set (match_dup 2)
5294 (match_dup 3))
5295 (set (match_dup 2)
5296 (neg:SI (match_dup 2)))]
5297 {
5298 operands[2] = gen_lowpart (SImode, operands[0]);
5299 operands[3] = GEN_INT (-INTVAL (operands[1]));
5300 })
5301
5302 ;; 64-bit paired-single floating point moves
5303
5304 (define_expand "movv2sf"
5305 [(set (match_operand:V2SF 0)
5306 (match_operand:V2SF 1))]
5307 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
5308 {
5309 if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
5310 DONE;
5311 })
5312
5313 (define_insn "*movv2sf"
5314 [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5315 (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
5316 "TARGET_HARD_FLOAT
5317 && TARGET_PAIRED_SINGLE_FLOAT
5318 && (register_operand (operands[0], V2SFmode)
5319 || reg_or_0_operand (operands[1], V2SFmode))"
5320 { return mips_output_move (operands[0], operands[1]); }
5321 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5322 (set_attr "mode" "DF")])
5323
5324 ;; Extract the high part of a HI/LO value. See mips_hard_regno_mode_ok_p
5325 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
5326 ;;
5327 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
5328 ;; instead of MFHI. This avoids both the normal MIPS III hi/lo hazards
5329 ;; and the errata related to -mfix-vr4130.
5330 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
5331 [(set (match_operand:GPR 0 "register_operand" "=d")
5332 (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
5333 UNSPEC_MFHI))]
5334 ""
5335 { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
5336 [(set_attr "type" "mfhi")
5337 (set_attr "mode" "<GPR:MODE>")])
5338
5339 ;; Set the high part of a HI/LO value, given that the low part has
5340 ;; already been set. See mips_hard_regno_mode_ok_p for the reason
5341 ;; why we can't just use (reg:GPR HI_REGNUM).
5342 (define_insn "mthi<GPR:mode>_<HILO:mode>"
5343 [(set (match_operand:HILO 0 "register_operand" "=x")
5344 (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
5345 (match_operand:GPR 2 "register_operand" "l")]
5346 UNSPEC_MTHI))]
5347 ""
5348 "mthi\t%z1"
5349 [(set_attr "type" "mthi")
5350 (set_attr "mode" "SI")])
5351
5352 ;; Emit a doubleword move in which exactly one of the operands is
5353 ;; a floating-point register. We can't just emit two normal moves
5354 ;; because of the constraints imposed by the FPU register model;
5355 ;; see mips_cannot_change_mode_class for details. Instead, we keep
5356 ;; the FPR whole and use special patterns to refer to each word of
5357 ;; the other operand.
5358
5359 (define_expand "move_doubleword_fpr<mode>"
5360 [(set (match_operand:SPLITF 0)
5361 (match_operand:SPLITF 1))]
5362 ""
5363 {
5364 if (FP_REG_RTX_P (operands[0]))
5365 {
5366 rtx low = mips_subword (operands[1], 0);
5367 rtx high = mips_subword (operands[1], 1);
5368 emit_insn (gen_load_low<mode> (operands[0], low));
5369 if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5370 emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
5371 else
5372 emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
5373 }
5374 else
5375 {
5376 rtx low = mips_subword (operands[0], 0);
5377 rtx high = mips_subword (operands[0], 1);
5378 emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
5379 if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5380 emit_insn (gen_mfhc1<mode> (high, operands[1]));
5381 else
5382 emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
5383 }
5384 DONE;
5385 })
5386
5387 ;; Load the low word of operand 0 with operand 1.
5388 (define_insn "load_low<mode>"
5389 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5390 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
5391 UNSPEC_LOAD_LOW))]
5392 "TARGET_HARD_FLOAT"
5393 {
5394 operands[0] = mips_subword (operands[0], 0);
5395 return mips_output_move (operands[0], operands[1]);
5396 }
5397 [(set_attr "move_type" "mtc,fpload")
5398 (set_attr "mode" "<HALFMODE>")])
5399
5400 ;; Load the high word of operand 0 from operand 1, preserving the value
5401 ;; in the low word.
5402 (define_insn "load_high<mode>"
5403 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5404 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
5405 (match_operand:SPLITF 2 "register_operand" "0,0")]
5406 UNSPEC_LOAD_HIGH))]
5407 "TARGET_HARD_FLOAT"
5408 {
5409 operands[0] = mips_subword (operands[0], 1);
5410 return mips_output_move (operands[0], operands[1]);
5411 }
5412 [(set_attr "move_type" "mtc,fpload")
5413 (set_attr "mode" "<HALFMODE>")])
5414
5415 ;; Store one word of operand 1 in operand 0. Operand 2 is 1 to store the
5416 ;; high word and 0 to store the low word.
5417 (define_insn "store_word<mode>"
5418 [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
5419 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
5420 (match_operand 2 "const_int_operand")]
5421 UNSPEC_STORE_WORD))]
5422 "TARGET_HARD_FLOAT"
5423 {
5424 operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
5425 return mips_output_move (operands[0], operands[1]);
5426 }
5427 [(set_attr "move_type" "mfc,fpstore")
5428 (set_attr "mode" "<HALFMODE>")])
5429
5430 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
5431 ;; value in the low word.
5432 (define_insn "mthc1<mode>"
5433 [(set (match_operand:SPLITF 0 "register_operand" "=f")
5434 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
5435 (match_operand:SPLITF 2 "register_operand" "0")]
5436 UNSPEC_MTHC1))]
5437 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5438 "mthc1\t%z1,%0"
5439 [(set_attr "move_type" "mtc")
5440 (set_attr "mode" "<HALFMODE>")])
5441
5442 ;; Move high word of operand 1 to operand 0 using mfhc1.
5443 (define_insn "mfhc1<mode>"
5444 [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
5445 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
5446 UNSPEC_MFHC1))]
5447 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5448 "mfhc1\t%0,%1"
5449 [(set_attr "move_type" "mfc")
5450 (set_attr "mode" "<HALFMODE>")])
5451
5452 ;; Move a constant that satisfies CONST_GP_P into operand 0.
5453 (define_expand "load_const_gp_<mode>"
5454 [(set (match_operand:P 0 "register_operand" "=d")
5455 (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
5456
5457 ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset
5458 ;; of _gp from the start of this function. Operand 1 is the incoming
5459 ;; function address.
5460 (define_insn_and_split "loadgp_newabi_<mode>"
5461 [(set (match_operand:P 0 "register_operand" "=&d")
5462 (unspec:P [(match_operand:P 1)
5463 (match_operand:P 2 "register_operand" "d")]
5464 UNSPEC_LOADGP))]
5465 "mips_current_loadgp_style () == LOADGP_NEWABI"
5466 { return mips_must_initialize_gp_p () ? "#" : ""; }
5467 "&& mips_must_initialize_gp_p ()"
5468 [(set (match_dup 0) (match_dup 3))
5469 (set (match_dup 0) (match_dup 4))
5470 (set (match_dup 0) (match_dup 5))]
5471 {
5472 operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
5473 operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
5474 operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
5475 }
5476 [(set_attr "type" "ghost")])
5477
5478 ;; Likewise, for -mno-shared code. Operand 0 is the __gnu_local_gp symbol.
5479 (define_insn_and_split "loadgp_absolute_<mode>"
5480 [(set (match_operand:P 0 "register_operand" "=d")
5481 (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
5482 "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
5483 { return mips_must_initialize_gp_p () ? "#" : ""; }
5484 "&& mips_must_initialize_gp_p ()"
5485 [(const_int 0)]
5486 {
5487 mips_emit_move (operands[0], operands[1]);
5488 DONE;
5489 }
5490 [(set_attr "type" "ghost")])
5491
5492 ;; This blockage instruction prevents the gp load from being
5493 ;; scheduled after an implicit use of gp. It also prevents
5494 ;; the load from being deleted as dead.
5495 (define_insn "loadgp_blockage"
5496 [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5497 ""
5498 ""
5499 [(set_attr "type" "ghost")])
5500
5501 ;; Initialize $gp for RTP PIC. Operand 0 is the __GOTT_BASE__ symbol
5502 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5503 (define_insn_and_split "loadgp_rtp_<mode>"
5504 [(set (match_operand:P 0 "register_operand" "=d")
5505 (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5506 (match_operand:P 2 "symbol_ref_operand")]
5507 UNSPEC_LOADGP))]
5508 "mips_current_loadgp_style () == LOADGP_RTP"
5509 { return mips_must_initialize_gp_p () ? "#" : ""; }
5510 "&& mips_must_initialize_gp_p ()"
5511 [(set (match_dup 0) (high:P (match_dup 3)))
5512 (set (match_dup 0) (unspec:P [(match_dup 0)
5513 (match_dup 3)] UNSPEC_LOAD_GOT))
5514 (set (match_dup 0) (unspec:P [(match_dup 0)
5515 (match_dup 4)] UNSPEC_LOAD_GOT))]
5516 {
5517 operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5518 operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5519 }
5520 [(set_attr "type" "ghost")])
5521
5522 ;; Initialize the global pointer for MIPS16 code. Operand 0 is the
5523 ;; global pointer and operand 1 is the MIPS16 register that holds
5524 ;; the required value.
5525 (define_insn_and_split "copygp_mips16_<mode>"
5526 [(set (match_operand:P 0 "register_operand" "=y")
5527 (unspec:P [(match_operand:P 1 "register_operand" "d")]
5528 UNSPEC_COPYGP))]
5529 "TARGET_MIPS16"
5530 { return mips_must_initialize_gp_p () ? "#" : ""; }
5531 "&& mips_must_initialize_gp_p ()"
5532 [(set (match_dup 0) (match_dup 1))]
5533 ""
5534 [(set_attr "type" "ghost")])
5535
5536 ;; A placeholder for where the cprestore instruction should go,
5537 ;; if we decide we need one. Operand 0 and operand 1 are as for
5538 ;; "cprestore". Operand 2 is a register that holds the gp value.
5539 ;;
5540 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5541 ;; otherwise any register that holds the correct value will do.
5542 (define_insn_and_split "potential_cprestore_<mode>"
5543 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5544 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5545 (match_operand:P 2 "register_operand" "d,d")]
5546 UNSPEC_POTENTIAL_CPRESTORE))
5547 (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5548 "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5549 { return mips_must_initialize_gp_p () ? "#" : ""; }
5550 "mips_must_initialize_gp_p ()"
5551 [(const_int 0)]
5552 {
5553 mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5554 operands[2], operands[3]);
5555 DONE;
5556 }
5557 [(set_attr "type" "ghost")])
5558
5559 ;; Emit a .cprestore directive, which normally expands to a single store
5560 ;; instruction. Operand 0 is a (possibly illegitimate) sp-based MEM
5561 ;; for the cprestore slot. Operand 1 is the offset of the slot from
5562 ;; the stack pointer. (This is redundant with operand 0, but it makes
5563 ;; things a little simpler.)
5564 (define_insn "cprestore_<mode>"
5565 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5566 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5567 (reg:P 28)]
5568 UNSPEC_CPRESTORE))]
5569 "TARGET_CPRESTORE_DIRECTIVE"
5570 {
5571 if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5572 return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5573 else
5574 return ".cprestore\t%1";
5575 }
5576 [(set_attr "type" "store")
5577 (set_attr "insn_count" "1,3")])
5578
5579 (define_insn "use_cprestore_<mode>"
5580 [(set (reg:P CPRESTORE_SLOT_REGNUM)
5581 (match_operand:P 0 "cprestore_load_slot_operand"))]
5582 ""
5583 ""
5584 [(set_attr "type" "ghost")])
5585
5586 ;; Expand in-line code to clear the instruction cache between operand[0] and
5587 ;; operand[1].
5588 (define_expand "clear_cache"
5589 [(match_operand 0 "pmode_register_operand")
5590 (match_operand 1 "pmode_register_operand")]
5591 ""
5592 "
5593 {
5594 if (TARGET_SYNCI)
5595 {
5596 mips_expand_synci_loop (operands[0], operands[1]);
5597 emit_insn (gen_sync ());
5598 emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5599 }
5600 else if (mips_cache_flush_func && mips_cache_flush_func[0])
5601 {
5602 rtx len = gen_reg_rtx (Pmode);
5603 emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5604 MIPS_ICACHE_SYNC (operands[0], len);
5605 }
5606 DONE;
5607 }")
5608
5609 (define_insn "sync"
5610 [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5611 "GENERATE_SYNC"
5612 { return mips_output_sync (); })
5613
5614 (define_insn "synci"
5615 [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5616 UNSPEC_SYNCI)]
5617 "TARGET_SYNCI"
5618 "synci\t0(%0)")
5619
5620 (define_insn "rdhwr_synci_step_<mode>"
5621 [(set (match_operand:P 0 "register_operand" "=d")
5622 (unspec_volatile [(const_int 1)]
5623 UNSPEC_RDHWR))]
5624 "ISA_HAS_SYNCI"
5625 "rdhwr\t%0,$1")
5626
5627 (define_insn "clear_hazard_<mode>"
5628 [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5629 (clobber (reg:P RETURN_ADDR_REGNUM))]
5630 "ISA_HAS_SYNCI"
5631 {
5632 return "%(%<bal\t1f\n"
5633 "\tnop\n"
5634 "1:\t<d>addiu\t$31,$31,12\n"
5635 "\tjr.hb\t$31\n"
5636 "\tnop%>%)";
5637 }
5638 [(set_attr "insn_count" "5")])
5639
5640 ;; Cache operations for R4000-style caches.
5641 (define_insn "mips_cache"
5642 [(set (mem:BLK (scratch))
5643 (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5644 (match_operand:QI 1 "address_operand" "ZD")]
5645 UNSPEC_MIPS_CACHE))]
5646 "ISA_HAS_CACHE"
5647 "cache\t%X0,%a1")
5648
5649 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5650 ;; operation. We keep the pattern distinct so that we can identify
5651 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5652 ;; the operation is never inserted into a delay slot.
5653 (define_insn "r10k_cache_barrier"
5654 [(set (mem:BLK (scratch))
5655 (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5656 "ISA_HAS_CACHE"
5657 "cache\t0x14,0(%$)"
5658 [(set_attr "can_delay" "no")])
5659 \f
5660 ;; Block moves, see mips.c for more details.
5661 ;; Argument 0 is the destination
5662 ;; Argument 1 is the source
5663 ;; Argument 2 is the length
5664 ;; Argument 3 is the alignment
5665
5666 (define_expand "cpymemsi"
5667 [(parallel [(set (match_operand:BLK 0 "general_operand")
5668 (match_operand:BLK 1 "general_operand"))
5669 (use (match_operand:SI 2 ""))
5670 (use (match_operand:SI 3 "const_int_operand"))])]
5671 "!TARGET_MIPS16 && !TARGET_MEMCPY"
5672 {
5673 if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5674 DONE;
5675 else
5676 FAIL;
5677 })
5678 \f
5679 ;;
5680 ;; ....................
5681 ;;
5682 ;; SHIFTS
5683 ;;
5684 ;; ....................
5685
5686 (define_expand "<optab><mode>3"
5687 [(set (match_operand:GPR 0 "register_operand")
5688 (any_shift:GPR (match_operand:GPR 1 "register_operand")
5689 (match_operand:SI 2 "arith_operand")))]
5690 ""
5691 {
5692 /* On the mips16, a shift of more than 8 is a four byte instruction,
5693 so, for a shift between 8 and 16, it is just as fast to do two
5694 shifts of 8 or less. If there is a lot of shifting going on, we
5695 may win in CSE. Otherwise combine will put the shifts back
5696 together again. This can be called by mips_function_arg, so we must
5697 be careful not to allocate a new register if we've reached the
5698 reload pass. */
5699 if (TARGET_MIPS16
5700 && optimize
5701 && CONST_INT_P (operands[2])
5702 && INTVAL (operands[2]) > 8
5703 && INTVAL (operands[2]) <= 16
5704 && !reload_in_progress
5705 && !reload_completed)
5706 {
5707 rtx temp = gen_reg_rtx (<MODE>mode);
5708
5709 emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5710 emit_insn (gen_<optab><mode>3 (operands[0], temp,
5711 GEN_INT (INTVAL (operands[2]) - 8)));
5712 DONE;
5713 }
5714 })
5715
5716 (define_insn "*<optab><mode>3"
5717 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
5718 (any_shift:GPR (match_operand:GPR 1 "register_operand" "!u,d")
5719 (match_operand:SI 2 "arith_operand" "Uib3,dI")))]
5720 "!TARGET_MIPS16"
5721 {
5722 if (CONST_INT_P (operands[2]))
5723 operands[2] = GEN_INT (INTVAL (operands[2])
5724 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5725
5726 return "<d><insn>\t%0,%1,%2";
5727 }
5728 [(set_attr "type" "shift")
5729 (set_attr "compression" "<shift_compression>,none")
5730 (set_attr "mode" "<MODE>")])
5731
5732 (define_insn "*<optab>si3_extend"
5733 [(set (match_operand:DI 0 "register_operand" "=d")
5734 (sign_extend:DI
5735 (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5736 (match_operand:SI 2 "arith_operand" "dI"))))]
5737 "TARGET_64BIT && !TARGET_MIPS16"
5738 {
5739 if (CONST_INT_P (operands[2]))
5740 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5741
5742 return "<insn>\t%0,%1,%2";
5743 }
5744 [(set_attr "type" "shift")
5745 (set_attr "mode" "SI")])
5746
5747 (define_insn "*<optab>si3_mips16"
5748 [(set (match_operand:SI 0 "register_operand" "=d,d,d")
5749 (any_shift:SI (match_operand:SI 1 "register_operand" "0,d,d")
5750 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5751 "TARGET_MIPS16"
5752 {
5753 if (which_alternative == 0)
5754 return "<insn>\t%0,%2";
5755
5756 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5757 return "<insn>\t%0,%1,%2";
5758 }
5759 [(set_attr "type" "shift")
5760 (set_attr "mode" "SI")
5761 (set_attr "extended_mips16" "no,no,yes")])
5762
5763 (define_insn "<GPR:d>lsa"
5764 [(set (match_operand:GPR 0 "register_operand" "=d")
5765 (plus:GPR (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
5766 (match_operand 2 "const_immlsa_operand" ""))
5767 (match_operand:GPR 3 "register_operand" "d")))]
5768 "ISA_HAS_<GPR:D>LSA"
5769 "<GPR:d>lsa\t%0,%1,%3,%2"
5770 [(set_attr "type" "arith")
5771 (set_attr "mode" "<GPR:MODE>")])
5772
5773 ;; We need separate DImode MIPS16 patterns because of the irregularity
5774 ;; of right shifts.
5775 (define_insn "*ashldi3_mips16"
5776 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5777 (ashift:DI (match_operand:DI 1 "register_operand" "0,d,d")
5778 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5779 "TARGET_64BIT && TARGET_MIPS16"
5780 {
5781 if (which_alternative == 0)
5782 return "dsll\t%0,%2";
5783
5784 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5785 return "dsll\t%0,%1,%2";
5786 }
5787 [(set_attr "type" "shift")
5788 (set_attr "mode" "DI")
5789 (set_attr "extended_mips16" "no,no,yes")])
5790
5791 (define_insn "*ashrdi3_mips16"
5792 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5793 (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5794 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5795 "TARGET_64BIT && TARGET_MIPS16"
5796 {
5797 if (CONST_INT_P (operands[2]))
5798 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5799
5800 return "dsra\t%0,%2";
5801 }
5802 [(set_attr "type" "shift")
5803 (set_attr "mode" "DI")
5804 (set_attr "extended_mips16" "no,no,yes")])
5805
5806 (define_insn "*lshrdi3_mips16"
5807 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5808 (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5809 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5810 "TARGET_64BIT && TARGET_MIPS16"
5811 {
5812 if (CONST_INT_P (operands[2]))
5813 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5814
5815 return "dsrl\t%0,%2";
5816 }
5817 [(set_attr "type" "shift")
5818 (set_attr "mode" "DI")
5819 (set_attr "extended_mips16" "no,no,yes")])
5820
5821 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5822
5823 (define_split
5824 [(set (match_operand:GPR 0 "d_operand")
5825 (any_shift:GPR (match_operand:GPR 1 "d_operand")
5826 (match_operand:GPR 2 "const_int_operand")))]
5827 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5828 && INTVAL (operands[2]) > 8
5829 && INTVAL (operands[2]) <= 16"
5830 [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5831 (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5832 { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5833
5834 ;; If we load a byte on the mips16 as a bitfield, the resulting
5835 ;; sequence of instructions is too complicated for combine, because it
5836 ;; involves four instructions: a load, a shift, a constant load into a
5837 ;; register, and an and (the key problem here is that the mips16 does
5838 ;; not have and immediate). We recognize a shift of a load in order
5839 ;; to make it simple enough for combine to understand.
5840 ;;
5841 ;; The instruction count here is the worst case.
5842 (define_insn_and_split ""
5843 [(set (match_operand:SI 0 "register_operand" "=d")
5844 (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5845 (match_operand:SI 2 "immediate_operand" "I")))]
5846 "TARGET_MIPS16"
5847 "#"
5848 "&& 1"
5849 [(set (match_dup 0) (match_dup 1))
5850 (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5851 ""
5852 [(set_attr "type" "load")
5853 (set_attr "mode" "SI")
5854 (set (attr "insn_count")
5855 (symbol_ref "mips_load_store_insns (operands[1], insn) + 2"))])
5856
5857 (define_insn "rotr<mode>3"
5858 [(set (match_operand:GPR 0 "register_operand" "=d")
5859 (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5860 (match_operand:SI 2 "arith_operand" "dI")))]
5861 "ISA_HAS_ROR"
5862 {
5863 if (CONST_INT_P (operands[2]))
5864 operands[2] = GEN_INT (INTVAL (operands[2])
5865 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5866
5867 return "<d>ror\t%0,%1,%2";
5868 }
5869 [(set_attr "type" "shift")
5870 (set_attr "mode" "<MODE>")])
5871
5872 (define_insn "bswaphi2"
5873 [(set (match_operand:HI 0 "register_operand" "=d")
5874 (bswap:HI (match_operand:HI 1 "register_operand" "d")))]
5875 "ISA_HAS_WSBH"
5876 "wsbh\t%0,%1"
5877 [(set_attr "type" "shift")])
5878
5879 (define_insn_and_split "bswapsi2"
5880 [(set (match_operand:SI 0 "register_operand" "=d")
5881 (bswap:SI (match_operand:SI 1 "register_operand" "d")))]
5882 "ISA_HAS_WSBH && ISA_HAS_ROR"
5883 "#"
5884 "&& 1"
5885 [(set (match_dup 0) (unspec:SI [(match_dup 1)] UNSPEC_WSBH))
5886 (set (match_dup 0) (rotatert:SI (match_dup 0) (const_int 16)))]
5887 ""
5888 [(set_attr "insn_count" "2")])
5889
5890 (define_insn_and_split "bswapdi2"
5891 [(set (match_operand:DI 0 "register_operand" "=d")
5892 (bswap:DI (match_operand:DI 1 "register_operand" "d")))]
5893 "TARGET_64BIT && ISA_HAS_WSBH"
5894 "#"
5895 "&& 1"
5896 [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_DSBH))
5897 (set (match_dup 0) (unspec:DI [(match_dup 0)] UNSPEC_DSHD))]
5898 ""
5899 [(set_attr "insn_count" "2")])
5900
5901 (define_insn "wsbh"
5902 [(set (match_operand:SI 0 "register_operand" "=d")
5903 (unspec:SI [(match_operand:SI 1 "register_operand" "d")] UNSPEC_WSBH))]
5904 "ISA_HAS_WSBH"
5905 "wsbh\t%0,%1"
5906 [(set_attr "type" "shift")])
5907
5908 (define_insn "dsbh"
5909 [(set (match_operand:DI 0 "register_operand" "=d")
5910 (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSBH))]
5911 "TARGET_64BIT && ISA_HAS_WSBH"
5912 "dsbh\t%0,%1"
5913 [(set_attr "type" "shift")])
5914
5915 (define_insn "dshd"
5916 [(set (match_operand:DI 0 "register_operand" "=d")
5917 (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSHD))]
5918 "TARGET_64BIT && ISA_HAS_WSBH"
5919 "dshd\t%0,%1"
5920 [(set_attr "type" "shift")])
5921 \f
5922 ;;
5923 ;; ....................
5924 ;;
5925 ;; CONDITIONAL BRANCHES
5926 ;;
5927 ;; ....................
5928
5929 ;; Conditional branches on floating-point equality tests.
5930
5931 (define_insn "*branch_fp_<mode>"
5932 [(set (pc)
5933 (if_then_else
5934 (match_operator 1 "equality_operator"
5935 [(match_operand:FPCC 2 "register_operand" "<reg>")
5936 (const_int 0)])
5937 (label_ref (match_operand 0 "" ""))
5938 (pc)))]
5939 "TARGET_HARD_FLOAT"
5940 {
5941 return mips_output_conditional_branch (insn, operands,
5942 MIPS_BRANCH ("b%F1", "%Z2%0"),
5943 MIPS_BRANCH ("b%W1", "%Z2%0"));
5944 }
5945 [(set_attr "type" "branch")])
5946
5947 (define_insn "*branch_fp_inverted_<mode>"
5948 [(set (pc)
5949 (if_then_else
5950 (match_operator 1 "equality_operator"
5951 [(match_operand:FPCC 2 "register_operand" "<reg>")
5952 (const_int 0)])
5953 (pc)
5954 (label_ref (match_operand 0 "" ""))))]
5955 "TARGET_HARD_FLOAT"
5956 {
5957 return mips_output_conditional_branch (insn, operands,
5958 MIPS_BRANCH ("b%W1", "%Z2%0"),
5959 MIPS_BRANCH ("b%F1", "%Z2%0"));
5960 }
5961 [(set_attr "type" "branch")])
5962
5963 ;; Conditional branches on ordered comparisons with zero.
5964
5965 (define_insn "*branch_order<mode>"
5966 [(set (pc)
5967 (if_then_else
5968 (match_operator 1 "order_operator"
5969 [(match_operand:GPR 2 "register_operand" "d,d")
5970 (match_operand:GPR 3 "reg_or_0_operand" "J,d")])
5971 (label_ref (match_operand 0 "" ""))
5972 (pc)))]
5973 "!TARGET_MIPS16"
5974 { return mips_output_order_conditional_branch (insn, operands, false); }
5975 [(set_attr "type" "branch")
5976 (set_attr "compact_form" "maybe,always")
5977 (set_attr "hazard" "forbidden_slot")])
5978
5979 (define_insn "*branch_order<mode>_inverted"
5980 [(set (pc)
5981 (if_then_else
5982 (match_operator 1 "order_operator"
5983 [(match_operand:GPR 2 "register_operand" "d,d")
5984 (match_operand:GPR 3 "reg_or_0_operand" "J,d")])
5985 (pc)
5986 (label_ref (match_operand 0 "" ""))))]
5987 "!TARGET_MIPS16"
5988 { return mips_output_order_conditional_branch (insn, operands, true); }
5989 [(set_attr "type" "branch")
5990 (set_attr "compact_form" "maybe,always")
5991 (set_attr "hazard" "forbidden_slot")])
5992
5993 ;; Conditional branch on equality comparison.
5994
5995 (define_insn "*branch_equality<mode>"
5996 [(set (pc)
5997 (if_then_else
5998 (match_operator 1 "equality_operator"
5999 [(match_operand:GPR 2 "register_operand" "d")
6000 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
6001 (label_ref (match_operand 0 "" ""))
6002 (pc)))]
6003 "!TARGET_MIPS16"
6004 { return mips_output_equal_conditional_branch (insn, operands, false); }
6005 [(set_attr "type" "branch")
6006 (set_attr "compact_form" "maybe")
6007 (set_attr "hazard" "forbidden_slot")])
6008
6009 (define_insn "*branch_equality<mode>_inverted"
6010 [(set (pc)
6011 (if_then_else
6012 (match_operator 1 "equality_operator"
6013 [(match_operand:GPR 2 "register_operand" "d")
6014 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
6015 (pc)
6016 (label_ref (match_operand 0 "" ""))))]
6017 "!TARGET_MIPS16"
6018 { return mips_output_equal_conditional_branch (insn, operands, true); }
6019 [(set_attr "type" "branch")
6020 (set_attr "compact_form" "maybe")
6021 (set_attr "hazard" "forbidden_slot")])
6022
6023 ;; MIPS16 branches
6024
6025 (define_insn "*branch_equality<mode>_mips16"
6026 [(set (pc)
6027 (if_then_else
6028 (match_operator 1 "equality_operator"
6029 [(match_operand:GPR 2 "register_operand" "d,t")
6030 (const_int 0)])
6031 (label_ref (match_operand 0 "" ""))
6032 (pc)))]
6033 "TARGET_MIPS16"
6034 "@
6035 b%C1z\t%2,%0
6036 bt%C1z\t%0"
6037 [(set_attr "type" "branch")])
6038
6039 (define_insn "*branch_equality<mode>_mips16_inverted"
6040 [(set (pc)
6041 (if_then_else
6042 (match_operator 1 "equality_operator"
6043 [(match_operand:GPR 2 "register_operand" "d,t")
6044 (const_int 0)])
6045 (pc)
6046 (label_ref (match_operand 0 "" ""))))]
6047 "TARGET_MIPS16"
6048 "@
6049 b%N1z\t%2,%0
6050 bt%N1z\t%0"
6051 [(set_attr "type" "branch")])
6052
6053 (define_expand "cbranch<mode>4"
6054 [(set (pc)
6055 (if_then_else (match_operator 0 "comparison_operator"
6056 [(match_operand:GPR 1 "register_operand")
6057 (match_operand:GPR 2 "nonmemory_operand")])
6058 (label_ref (match_operand 3 ""))
6059 (pc)))]
6060 ""
6061 {
6062 mips_expand_conditional_branch (operands);
6063 DONE;
6064 })
6065
6066 (define_expand "cbranch<mode>4"
6067 [(set (pc)
6068 (if_then_else (match_operator 0 "comparison_operator"
6069 [(match_operand:SCALARF 1 "register_operand")
6070 (match_operand:SCALARF 2 "register_operand")])
6071 (label_ref (match_operand 3 ""))
6072 (pc)))]
6073 ""
6074 {
6075 mips_expand_conditional_branch (operands);
6076 DONE;
6077 })
6078
6079 ;; Used to implement built-in functions.
6080 (define_expand "condjump"
6081 [(set (pc)
6082 (if_then_else (match_operand 0)
6083 (label_ref (match_operand 1))
6084 (pc)))])
6085
6086 ;; Branch if bit is set/clear.
6087
6088 (define_insn "*branch_bit<bbv><mode>"
6089 [(set (pc)
6090 (if_then_else
6091 (equality_op (zero_extract:GPR
6092 (match_operand:GPR 1 "register_operand" "d")
6093 (const_int 1)
6094 (match_operand 2 "const_int_operand" ""))
6095 (const_int 0))
6096 (label_ref (match_operand 0 ""))
6097 (pc)))]
6098 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
6099 {
6100 return
6101 mips_output_conditional_branch (insn, operands,
6102 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
6103 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
6104 }
6105 [(set_attr "type" "branch")
6106 (set_attr "branch_likely" "no")])
6107
6108 (define_insn "*branch_bit<bbv><mode>_inverted"
6109 [(set (pc)
6110 (if_then_else
6111 (equality_op (zero_extract:GPR
6112 (match_operand:GPR 1 "register_operand" "d")
6113 (const_int 1)
6114 (match_operand 2 "const_int_operand" ""))
6115 (const_int 0))
6116 (pc)
6117 (label_ref (match_operand 0 ""))))]
6118 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
6119 {
6120 return
6121 mips_output_conditional_branch (insn, operands,
6122 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
6123 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
6124 }
6125 [(set_attr "type" "branch")
6126 (set_attr "branch_likely" "no")])
6127 \f
6128 ;;
6129 ;; ....................
6130 ;;
6131 ;; SETTING A REGISTER FROM A COMPARISON
6132 ;;
6133 ;; ....................
6134
6135 ;; Destination is always set in SI mode.
6136
6137 (define_expand "cstore<mode>4"
6138 [(set (match_operand:SI 0 "register_operand")
6139 (match_operator:SI 1 "mips_cstore_operator"
6140 [(match_operand:GPR 2 "register_operand")
6141 (match_operand:GPR 3 "nonmemory_operand")]))]
6142 ""
6143 {
6144 mips_expand_scc (operands);
6145 DONE;
6146 })
6147
6148 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
6149 [(set (match_operand:GPR2 0 "register_operand" "=d")
6150 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
6151 (const_int 0)))]
6152 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6153 "sltu\t%0,%1,1"
6154 [(set_attr "type" "slt")
6155 (set_attr "mode" "<GPR:MODE>")])
6156
6157 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
6158 [(set (match_operand:GPR2 0 "register_operand" "=t")
6159 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
6160 (const_int 0)))]
6161 "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6162 "sltu\t%1,1"
6163 [(set_attr "type" "slt")
6164 (set_attr "mode" "<GPR:MODE>")])
6165
6166 ;; Generate sltiu unless using seq results in better code.
6167 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
6168 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
6169 (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
6170 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
6171 "ISA_HAS_SEQ_SNE"
6172 "@
6173 seq\t%0,%1,%2
6174 sltiu\t%0,%1,1
6175 seqi\t%0,%1,%2"
6176 [(set_attr "type" "slt")
6177 (set_attr "mode" "<GPR:MODE>")])
6178
6179 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
6180 [(set (match_operand:GPR2 0 "register_operand" "=d")
6181 (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
6182 (const_int 0)))]
6183 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6184 "sltu\t%0,%.,%1"
6185 [(set_attr "type" "slt")
6186 (set_attr "mode" "<GPR:MODE>")])
6187
6188 ;; Generate sltu unless using sne results in better code.
6189 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
6190 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
6191 (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
6192 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
6193 "ISA_HAS_SEQ_SNE"
6194 "@
6195 sne\t%0,%1,%2
6196 sltu\t%0,%.,%1
6197 snei\t%0,%1,%2"
6198 [(set_attr "type" "slt")
6199 (set_attr "mode" "<GPR:MODE>")])
6200
6201 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
6202 [(set (match_operand:GPR2 0 "register_operand" "=d")
6203 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6204 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
6205 "!TARGET_MIPS16"
6206 "slt<u>\t%0,%z2,%1"
6207 [(set_attr "type" "slt")
6208 (set_attr "mode" "<GPR:MODE>")])
6209
6210 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
6211 [(set (match_operand:GPR2 0 "register_operand" "=t")
6212 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6213 (match_operand:GPR 2 "register_operand" "d")))]
6214 "TARGET_MIPS16"
6215 "slt<u>\t%2,%1"
6216 [(set_attr "type" "slt")
6217 (set_attr "mode" "<GPR:MODE>")])
6218
6219 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
6220 [(set (match_operand:GPR2 0 "register_operand" "=d")
6221 (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
6222 (const_int 1)))]
6223 "!TARGET_MIPS16"
6224 "slt<u>\t%0,%.,%1"
6225 [(set_attr "type" "slt")
6226 (set_attr "mode" "<GPR:MODE>")])
6227
6228 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
6229 [(set (match_operand:GPR2 0 "register_operand" "=d")
6230 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6231 (match_operand:GPR 2 "arith_operand" "dI")))]
6232 "!TARGET_MIPS16"
6233 "slt<u>\t%0,%1,%2"
6234 [(set_attr "type" "slt")
6235 (set_attr "mode" "<GPR:MODE>")])
6236
6237 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
6238 [(set (match_operand:GPR2 0 "register_operand" "=t,t,t")
6239 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d,d")
6240 (match_operand:GPR 2 "arith_operand" "d,Uub8,I")))]
6241 "TARGET_MIPS16"
6242 "slt<u>\t%1,%2"
6243 [(set_attr "type" "slt")
6244 (set_attr "mode" "<GPR:MODE>")
6245 (set_attr "extended_mips16" "no,no,yes")])
6246
6247 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
6248 [(set (match_operand:GPR2 0 "register_operand" "=d")
6249 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
6250 (match_operand:GPR 2 "sle_operand" "")))]
6251 "!TARGET_MIPS16"
6252 {
6253 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6254 return "slt<u>\t%0,%1,%2";
6255 }
6256 [(set_attr "type" "slt")
6257 (set_attr "mode" "<GPR:MODE>")])
6258
6259 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
6260 [(set (match_operand:GPR2 0 "register_operand" "=t,t")
6261 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
6262 (match_operand:GPR 2 "sle_operand" "Udb8,i")))]
6263 "TARGET_MIPS16"
6264 {
6265 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6266 return "slt<u>\t%1,%2";
6267 }
6268 [(set_attr "type" "slt")
6269 (set_attr "mode" "<GPR:MODE>")
6270 (set_attr "extended_mips16" "no,yes")])
6271 \f
6272 ;;
6273 ;; ....................
6274 ;;
6275 ;; FLOATING POINT COMPARISONS
6276 ;;
6277 ;; ....................
6278
6279 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6280 [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6281 (fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6282 (match_operand:SCALARF 2 "register_operand" "f")))]
6283 ""
6284 "<fpcmp>.<fcond>.<fmt>\t%Z0%1,%2"
6285 [(set_attr "type" "fcmp")
6286 (set_attr "mode" "FPSW")])
6287
6288 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6289 [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6290 (swapped_fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6291 (match_operand:SCALARF 2 "register_operand" "f")))]
6292 ""
6293 "<fpcmp>.<swapped_fcond>.<fmt>\t%Z0%2,%1"
6294 [(set_attr "type" "fcmp")
6295 (set_attr "mode" "FPSW")])
6296 \f
6297 ;;
6298 ;; ....................
6299 ;;
6300 ;; UNCONDITIONAL BRANCHES
6301 ;;
6302 ;; ....................
6303
6304 ;; Unconditional branches.
6305
6306 (define_expand "jump"
6307 [(set (pc)
6308 (label_ref (match_operand 0)))])
6309
6310 (define_insn "*jump_absolute"
6311 [(set (pc)
6312 (label_ref (match_operand 0)))]
6313 "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
6314 {
6315 if (get_attr_length (insn) <= 8)
6316 {
6317 if (TARGET_CB_MAYBE)
6318 return MIPS_ABSOLUTE_JUMP ("%*b%:\t%l0");
6319 else
6320 return MIPS_ABSOLUTE_JUMP ("%*b\t%l0%/");
6321 }
6322 else
6323 {
6324 if (TARGET_CB_MAYBE && !final_sequence)
6325 return MIPS_ABSOLUTE_JUMP ("%*bc\t%l0");
6326 else
6327 return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/");
6328 }
6329 }
6330 [(set_attr "type" "branch")
6331 (set_attr "compact_form" "maybe")])
6332
6333 (define_insn "*jump_pic"
6334 [(set (pc)
6335 (label_ref (match_operand 0)))]
6336 "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
6337 {
6338 if (get_attr_length (insn) <= 8)
6339 {
6340 if (TARGET_CB_MAYBE)
6341 return "%*b%:\t%l0";
6342 else
6343 return "%*b\t%l0%/";
6344 }
6345 else
6346 {
6347 mips_output_load_label (operands[0]);
6348 if (TARGET_CB_MAYBE)
6349 return "%*jr%:\t%@%]";
6350 else
6351 return "%*jr\t%@%/%]";
6352 }
6353 }
6354 [(set_attr "type" "branch")
6355 (set_attr "compact_form" "maybe")])
6356
6357 ;; We need a different insn for the mips16, because a mips16 branch
6358 ;; does not have a delay slot.
6359
6360 (define_insn "*jump_mips16"
6361 [(set (pc)
6362 (label_ref (match_operand 0 "" "")))]
6363 "TARGET_MIPS16"
6364 "b\t%l0"
6365 [(set_attr "type" "branch")
6366 (set (attr "length")
6367 ;; This calculation is like the normal branch one, but the
6368 ;; range of the unextended instruction is [-0x800, 0x7fe] rather
6369 ;; than [-0x100, 0xfe]. This translates to a range of:
6370 ;;
6371 ;; [-(0x800 - sizeof (branch)), 0x7fe]
6372 ;; == [-0x7fe, 0x7fe]
6373 ;;
6374 ;; from the shorten_branches reference address. Long-branch
6375 ;; sequences will replace this one, so the minimum length
6376 ;; is one instruction shorter than for conditional branches.
6377 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
6378 (le (minus (pc) (match_dup 0)) (const_int 2046)))
6379 (const_int 2)
6380 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
6381 (le (minus (pc) (match_dup 0)) (const_int 65532)))
6382 (const_int 4)
6383 (and (match_test "TARGET_ABICALLS")
6384 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
6385 (const_int 18)
6386 (match_test "Pmode == SImode")
6387 (const_int 14)
6388 ] (const_int 22)))])
6389
6390 (define_expand "indirect_jump"
6391 [(set (pc) (match_operand 0 "register_operand"))]
6392 ""
6393 {
6394 operands[0] = force_reg (Pmode, operands[0]);
6395 emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
6396 DONE;
6397 })
6398
6399 (define_insn "indirect_jump_<mode>"
6400 [(set (pc) (match_operand:P 0 "register_operand" "d"))]
6401 ""
6402 {
6403 return mips_output_jump (operands, 0, -1, false);
6404 }
6405 [(set_attr "type" "jump")
6406 (set_attr "mode" "none")])
6407
6408 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
6409 ;; sequences. Having a dedicated pattern is more convenient than
6410 ;; creating a SEQUENCE for this special case.
6411 (define_insn "indirect_jump_and_restore_<mode>"
6412 [(set (pc) (match_operand:P 1 "register_operand" "d"))
6413 (set (match_operand:P 0 "register_operand" "=d")
6414 (match_operand:P 2 "register_operand" "y"))]
6415 ""
6416 "%(%<jr\t%1\;move\t%0,%2%>%)"
6417 [(set_attr "type" "multi")
6418 (set_attr "extended_mips16" "yes")])
6419
6420 (define_expand "tablejump"
6421 [(set (pc)
6422 (match_operand 0 "register_operand"))
6423 (use (label_ref (match_operand 1 "")))]
6424 "!TARGET_MIPS16_SHORT_JUMP_TABLES"
6425 {
6426 if (TARGET_GPWORD)
6427 operands[0] = expand_binop (Pmode, add_optab, operands[0],
6428 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
6429 else if (TARGET_RTP_PIC)
6430 {
6431 /* When generating RTP PIC, we use case table entries that are relative
6432 to the start of the function. Add the function's address to the
6433 value we loaded. */
6434 rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6435 operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
6436 start, 0, 0, OPTAB_WIDEN);
6437 }
6438
6439 emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
6440 DONE;
6441 })
6442
6443 (define_insn "tablejump_<mode>"
6444 [(set (pc)
6445 (match_operand:P 0 "register_operand" "d"))
6446 (use (label_ref (match_operand 1 "" "")))]
6447 ""
6448 {
6449 return mips_output_jump (operands, 0, -1, false);
6450 }
6451 [(set_attr "type" "jump")
6452 (set_attr "mode" "none")])
6453
6454 ;; For MIPS16, we don't know whether a given jump table will use short or
6455 ;; word-sized offsets until late in compilation, when we are able to determine
6456 ;; the sizes of the insns which comprise the containing function. This
6457 ;; necessitates the use of the casesi rather than the tablejump pattern, since
6458 ;; the latter tries to calculate the index of the offset to jump through early
6459 ;; in compilation, i.e. at expand time, when nothing is known about the
6460 ;; eventual function layout.
6461
6462 (define_expand "casesi"
6463 [(match_operand:SI 0 "register_operand" "") ; index to jump on
6464 (match_operand:SI 1 "const_int_operand" "") ; lower bound
6465 (match_operand:SI 2 "const_int_operand" "") ; total range
6466 (match_operand 3 "" "") ; table label
6467 (match_operand 4 "" "")] ; out of range label
6468 "TARGET_MIPS16_SHORT_JUMP_TABLES"
6469 {
6470 if (operands[1] != const0_rtx)
6471 {
6472 rtx reg = gen_reg_rtx (SImode);
6473 rtx offset = gen_int_mode (-INTVAL (operands[1]), SImode);
6474
6475 if (!arith_operand (offset, SImode))
6476 offset = force_reg (SImode, offset);
6477
6478 emit_insn (gen_addsi3 (reg, operands[0], offset));
6479 operands[0] = reg;
6480 }
6481
6482 if (!arith_operand (operands[0], SImode))
6483 operands[0] = force_reg (SImode, operands[0]);
6484
6485 emit_cmp_and_jump_insns (operands[0], operands[2], GTU,
6486 NULL_RTX, SImode, 1, operands[4]);
6487 emit_jump_insn (PMODE_INSN (gen_casesi_internal_mips16,
6488 (operands[0], operands[3])));
6489 DONE;
6490 })
6491
6492 (define_insn "casesi_internal_mips16_<mode>"
6493 [(set (pc)
6494 (unspec:P [(match_operand:SI 0 "register_operand" "d")
6495 (label_ref (match_operand 1 "" ""))]
6496 UNSPEC_CASESI_DISPATCH))
6497 (clobber (match_scratch:P 2 "=d"))
6498 (clobber (match_scratch:P 3 "=d"))]
6499 "TARGET_MIPS16_SHORT_JUMP_TABLES"
6500 {
6501 rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[1])));
6502
6503 gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
6504
6505 switch (GET_MODE (diff_vec))
6506 {
6507 case E_HImode:
6508 output_asm_insn ("sll\t%3,%0,1", operands);
6509 output_asm_insn ("<d>la\t%2,%1", operands);
6510 output_asm_insn ("<d>addu\t%3,%2,%3", operands);
6511 output_asm_insn ("lh\t%3,0(%3)", operands);
6512 break;
6513
6514 case E_SImode:
6515 output_asm_insn ("sll\t%3,%0,2", operands);
6516 output_asm_insn ("<d>la\t%2,%1", operands);
6517 output_asm_insn ("<d>addu\t%3,%2,%3", operands);
6518 output_asm_insn ("lw\t%3,0(%3)", operands);
6519 break;
6520
6521 default:
6522 gcc_unreachable ();
6523 }
6524
6525 output_asm_insn ("<d>addu\t%2,%2,%3", operands);
6526
6527 if (GENERATE_MIPS16E)
6528 return "jrc\t%2";
6529 else
6530 return "jr\t%2";
6531 }
6532 [(set (attr "insn_count")
6533 (if_then_else (match_test "GENERATE_MIPS16E")
6534 (const_string "6")
6535 (const_string "7")))])
6536
6537 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
6538 ;; While it is possible to either pull it off the stack (in the
6539 ;; o32 case) or recalculate it given t9 and our target label,
6540 ;; it takes 3 or 4 insns to do so.
6541
6542 (define_expand "builtin_setjmp_setup"
6543 [(use (match_operand 0 "register_operand"))]
6544 "TARGET_USE_GOT"
6545 {
6546 rtx addr;
6547
6548 addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
6549 mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
6550 DONE;
6551 })
6552
6553 ;; Restore the gp that we saved above. Despite the earlier comment, it seems
6554 ;; that older code did recalculate the gp from $25. Continue to jump through
6555 ;; $25 for compatibility (we lose nothing by doing so).
6556
6557 (define_expand "builtin_longjmp"
6558 [(use (match_operand 0 "register_operand"))]
6559 "TARGET_USE_GOT"
6560 {
6561 /* The elements of the buffer are, in order: */
6562 int W = GET_MODE_SIZE (Pmode);
6563 rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6564 rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
6565 rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
6566 rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
6567 rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6568 /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
6569 The target is bound to be using $28 as the global pointer
6570 but the current function might not be. */
6571 rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
6572
6573 /* This bit is similar to expand_builtin_longjmp except that it
6574 restores $gp as well. */
6575 mips_emit_move (pv, lab);
6576 /* Restore the frame pointer and stack pointer and gp. We must use a
6577 temporary since the setjmp buffer may be a local. */
6578 fp = copy_to_reg (fp);
6579 gpv = copy_to_reg (gpv);
6580 emit_stack_restore (SAVE_NONLOCAL, stack);
6581
6582 /* Ensure the frame pointer move is not optimized. */
6583 emit_insn (gen_blockage ());
6584 emit_clobber (hard_frame_pointer_rtx);
6585 emit_clobber (frame_pointer_rtx);
6586 emit_clobber (gp);
6587 mips_emit_move (hard_frame_pointer_rtx, fp);
6588 mips_emit_move (gp, gpv);
6589 emit_use (hard_frame_pointer_rtx);
6590 emit_use (stack_pointer_rtx);
6591 emit_use (gp);
6592 emit_indirect_jump (pv);
6593 DONE;
6594 })
6595 \f
6596 ;;
6597 ;; ....................
6598 ;;
6599 ;; Function prologue/epilogue
6600 ;;
6601 ;; ....................
6602 ;;
6603
6604 (define_expand "prologue"
6605 [(const_int 1)]
6606 ""
6607 {
6608 mips_expand_prologue ();
6609 DONE;
6610 })
6611
6612 ;; Block any insns from being moved before this point, since the
6613 ;; profiling call to mcount can use various registers that aren't
6614 ;; saved or used to pass arguments.
6615
6616 (define_insn "blockage"
6617 [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
6618 ""
6619 ""
6620 [(set_attr "type" "ghost")
6621 (set_attr "mode" "none")])
6622
6623 (define_insn "probe_stack_range_<P:mode>"
6624 [(set (match_operand:P 0 "register_operand" "=d")
6625 (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
6626 (match_operand:P 2 "register_operand" "d")]
6627 UNSPEC_PROBE_STACK_RANGE))]
6628 ""
6629 { return mips_output_probe_stack_range (operands[0], operands[2]); }
6630 [(set_attr "type" "unknown")
6631 (set_attr "can_delay" "no")
6632 (set_attr "mode" "<MODE>")])
6633
6634 (define_expand "epilogue"
6635 [(const_int 2)]
6636 ""
6637 {
6638 mips_expand_epilogue (false);
6639 DONE;
6640 })
6641
6642 (define_expand "sibcall_epilogue"
6643 [(const_int 2)]
6644 ""
6645 {
6646 mips_expand_epilogue (true);
6647 DONE;
6648 })
6649
6650 ;; Trivial return. Make it look like a normal return insn as that
6651 ;; allows jump optimizations to work better.
6652
6653 (define_expand "return"
6654 [(simple_return)]
6655 "mips_can_use_return_insn ()"
6656 { mips_expand_before_return (); })
6657
6658 (define_expand "simple_return"
6659 [(simple_return)]
6660 ""
6661 { mips_expand_before_return (); })
6662
6663 (define_insn "*<optab>"
6664 [(any_return)]
6665 ""
6666 {
6667 operands[0] = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
6668 return mips_output_jump (operands, 0, -1, false);
6669 }
6670 [(set_attr "type" "jump")
6671 (set_attr "mode" "none")])
6672
6673 ;; Normal return.
6674
6675 (define_insn "<optab>_internal"
6676 [(any_return)
6677 (use (match_operand 0 "pmode_register_operand" ""))]
6678 ""
6679 {
6680 return mips_output_jump (operands, 0, -1, false);
6681 }
6682 [(set_attr "type" "jump")
6683 (set_attr "mode" "none")])
6684
6685 ;; Exception return.
6686 (define_insn "mips_eret"
6687 [(return)
6688 (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6689 ""
6690 "eret"
6691 [(set_attr "type" "trap")
6692 (set_attr "mode" "none")])
6693
6694 ;; Debug exception return.
6695 (define_insn "mips_deret"
6696 [(return)
6697 (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6698 ""
6699 "deret"
6700 [(set_attr "type" "trap")
6701 (set_attr "mode" "none")])
6702
6703 ;; Disable interrupts.
6704 (define_insn "mips_di"
6705 [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6706 ""
6707 "di"
6708 [(set_attr "type" "trap")
6709 (set_attr "mode" "none")])
6710
6711 ;; Execution hazard barrier.
6712 (define_insn "mips_ehb"
6713 [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6714 ""
6715 "ehb"
6716 [(set_attr "type" "trap")
6717 (set_attr "mode" "none")])
6718
6719 ;; Read GPR from previous shadow register set.
6720 (define_insn "mips_rdpgpr_<mode>"
6721 [(set (match_operand:P 0 "register_operand" "=d")
6722 (unspec_volatile:P [(match_operand:P 1 "register_operand" "d")]
6723 UNSPEC_RDPGPR))]
6724 ""
6725 "rdpgpr\t%0,%1"
6726 [(set_attr "type" "move")
6727 (set_attr "mode" "<MODE>")])
6728
6729 ;; Move involving COP0 registers.
6730 (define_insn "cop0_move"
6731 [(set (match_operand:SI 0 "register_operand" "=B,d")
6732 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6733 UNSPEC_COP0))]
6734 ""
6735 { return mips_output_move (operands[0], operands[1]); }
6736 [(set_attr "type" "mtc,mfc")
6737 (set_attr "mode" "SI")])
6738
6739 ;; This is used in compiling the unwind routines.
6740 (define_expand "eh_return"
6741 [(use (match_operand 0 "general_operand"))]
6742 ""
6743 {
6744 if (GET_MODE (operands[0]) != word_mode)
6745 operands[0] = convert_to_mode (word_mode, operands[0], 0);
6746 if (TARGET_64BIT)
6747 emit_insn (gen_eh_set_lr_di (operands[0]));
6748 else
6749 emit_insn (gen_eh_set_lr_si (operands[0]));
6750 DONE;
6751 })
6752
6753 ;; Clobber the return address on the stack. We can't expand this
6754 ;; until we know where it will be put in the stack frame.
6755
6756 (define_insn "eh_set_lr_si"
6757 [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6758 (clobber (match_scratch:SI 1 "=&d"))]
6759 "! TARGET_64BIT"
6760 "#")
6761
6762 (define_insn "eh_set_lr_di"
6763 [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6764 (clobber (match_scratch:DI 1 "=&d"))]
6765 "TARGET_64BIT"
6766 "#")
6767
6768 (define_split
6769 [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6770 (clobber (match_scratch 1))]
6771 "reload_completed"
6772 [(const_int 0)]
6773 {
6774 mips_set_return_address (operands[0], operands[1]);
6775 DONE;
6776 })
6777
6778 (define_expand "exception_receiver"
6779 [(const_int 0)]
6780 "TARGET_USE_GOT"
6781 {
6782 /* See the comment above load_call<mode> for details. */
6783 emit_insn (gen_set_got_version ());
6784
6785 /* If we have a call-clobbered $gp, restore it from its save slot. */
6786 if (HAVE_restore_gp_si)
6787 emit_insn (gen_restore_gp_si ());
6788 else if (HAVE_restore_gp_di)
6789 emit_insn (gen_restore_gp_di ());
6790 DONE;
6791 })
6792
6793 (define_expand "nonlocal_goto_receiver"
6794 [(const_int 0)]
6795 "TARGET_USE_GOT"
6796 {
6797 /* See the comment above load_call<mode> for details. */
6798 emit_insn (gen_set_got_version ());
6799 DONE;
6800 })
6801
6802 ;; Restore $gp from its .cprestore stack slot. The instruction remains
6803 ;; volatile until all uses of $28 are exposed.
6804 (define_insn_and_split "restore_gp_<mode>"
6805 [(set (reg:P 28)
6806 (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6807 (clobber (match_scratch:P 0 "=&d"))]
6808 "TARGET_CALL_CLOBBERED_GP"
6809 "#"
6810 "&& epilogue_completed"
6811 [(const_int 0)]
6812 {
6813 mips_restore_gp_from_cprestore_slot (operands[0]);
6814 DONE;
6815 }
6816 [(set_attr "type" "ghost")])
6817
6818 ;; Move between $gp and its register save slot.
6819 (define_insn_and_split "move_gp<mode>"
6820 [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6821 (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6822 UNSPEC_MOVE_GP))]
6823 ""
6824 { return mips_must_initialize_gp_p () ? "#" : ""; }
6825 "mips_must_initialize_gp_p ()"
6826 [(const_int 0)]
6827 {
6828 mips_emit_move (operands[0], operands[1]);
6829 DONE;
6830 }
6831 [(set_attr "type" "ghost")])
6832 \f
6833 ;;
6834 ;; ....................
6835 ;;
6836 ;; FUNCTION CALLS
6837 ;;
6838 ;; ....................
6839
6840 ;; Instructions to load a call address from the GOT. The address might
6841 ;; point to a function or to a lazy binding stub. In the latter case,
6842 ;; the stub will use the dynamic linker to resolve the function, which
6843 ;; in turn will change the GOT entry to point to the function's real
6844 ;; address.
6845 ;;
6846 ;; This means that every call, even pure and constant ones, can
6847 ;; potentially modify the GOT entry. And once a stub has been called,
6848 ;; we must not call it again.
6849 ;;
6850 ;; We represent this restriction using an imaginary, fixed, call-saved
6851 ;; register called GOT_VERSION_REGNUM. The idea is to make the register
6852 ;; live throughout the function and to change its value after every
6853 ;; potential call site. This stops any rtx value that uses the register
6854 ;; from being computed before an earlier call. To do this, we:
6855 ;;
6856 ;; - Ensure that the register is live on entry to the function,
6857 ;; so that it is never thought to be used uninitalized.
6858 ;;
6859 ;; - Ensure that the register is live on exit from the function,
6860 ;; so that it is live throughout.
6861 ;;
6862 ;; - Make each call (lazily-bound or not) use the current value
6863 ;; of GOT_VERSION_REGNUM, so that updates of the register are
6864 ;; not moved across call boundaries.
6865 ;;
6866 ;; - Add "ghost" definitions of the register to the beginning of
6867 ;; blocks reached by EH and ABNORMAL_CALL edges, because those
6868 ;; edges may involve calls that normal paths don't. (E.g. the
6869 ;; unwinding code that handles a non-call exception may change
6870 ;; lazily-bound GOT entries.) We do this by making the
6871 ;; exception_receiver and nonlocal_goto_receiver expanders emit
6872 ;; a set_got_version instruction.
6873 ;;
6874 ;; - After each call (lazily-bound or not), use a "ghost"
6875 ;; update_got_version instruction to change the register's value.
6876 ;; This instruction mimics the _possible_ effect of the dynamic
6877 ;; resolver during the call and it remains live even if the call
6878 ;; itself becomes dead.
6879 ;;
6880 ;; - Leave GOT_VERSION_REGNUM out of all register classes.
6881 ;; The register is therefore not a valid register_operand
6882 ;; and cannot be moved to or from other registers.
6883
6884 (define_insn "load_call<mode>"
6885 [(set (match_operand:P 0 "register_operand" "=d")
6886 (unspec:P [(match_operand:P 1 "register_operand" "d")
6887 (match_operand:P 2 "immediate_operand" "")
6888 (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6889 "TARGET_USE_GOT"
6890 "<load>\t%0,%R2(%1)"
6891 [(set_attr "got" "load")
6892 (set_attr "mode" "<MODE>")])
6893
6894 (define_insn "set_got_version"
6895 [(set (reg:SI GOT_VERSION_REGNUM)
6896 (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6897 "TARGET_USE_GOT"
6898 ""
6899 [(set_attr "type" "ghost")])
6900
6901 (define_insn "update_got_version"
6902 [(set (reg:SI GOT_VERSION_REGNUM)
6903 (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6904 "TARGET_USE_GOT"
6905 ""
6906 [(set_attr "type" "ghost")])
6907
6908 ;; Sibling calls. All these patterns use jump instructions.
6909
6910 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6911 ;; addresses if a direct jump is acceptable. Since the 'S' constraint
6912 ;; is defined in terms of call_insn_operand, the same is true of the
6913 ;; constraints.
6914
6915 ;; When we use an indirect jump, we need a register that will be
6916 ;; preserved by the epilogue. Since TARGET_USE_PIC_FN_ADDR_REG forces
6917 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6918 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6919 ;; as well.
6920
6921 (define_expand "sibcall"
6922 [(parallel [(call (match_operand 0 "")
6923 (match_operand 1 ""))
6924 (use (match_operand 2 "")) ;; next_arg_reg
6925 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6926 "TARGET_SIBCALLS"
6927 {
6928 mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6929 operands[1], operands[2], false);
6930 DONE;
6931 })
6932
6933 (define_insn "sibcall_internal"
6934 [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6935 (match_operand 1 "" ""))]
6936 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6937 { return mips_output_jump (operands, 0, 1, false); }
6938 [(set_attr "jal" "indirect,direct")
6939 (set_attr "jal_macro" "no")])
6940
6941 (define_expand "sibcall_value"
6942 [(parallel [(set (match_operand 0 "")
6943 (call (match_operand 1 "")
6944 (match_operand 2 "")))
6945 (use (match_operand 3 ""))])] ;; next_arg_reg
6946 "TARGET_SIBCALLS"
6947 {
6948 mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6949 operands[2], operands[3], false);
6950 DONE;
6951 })
6952
6953 (define_insn "sibcall_value_internal"
6954 [(set (match_operand 0 "register_operand" "")
6955 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6956 (match_operand 2 "" "")))]
6957 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6958 { return mips_output_jump (operands, 1, 2, false); }
6959 [(set_attr "jal" "indirect,direct")
6960 (set_attr "jal_macro" "no")])
6961
6962 (define_insn "sibcall_value_multiple_internal"
6963 [(set (match_operand 0 "register_operand" "")
6964 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6965 (match_operand 2 "" "")))
6966 (set (match_operand 3 "register_operand" "")
6967 (call (mem:SI (match_dup 1))
6968 (match_dup 2)))]
6969 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6970 { return mips_output_jump (operands, 1, 2, false); }
6971 [(set_attr "jal" "indirect,direct")
6972 (set_attr "jal_macro" "no")])
6973
6974 (define_expand "call"
6975 [(parallel [(call (match_operand 0 "")
6976 (match_operand 1 ""))
6977 (use (match_operand 2 "")) ;; next_arg_reg
6978 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6979 ""
6980 {
6981 mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6982 operands[1], operands[2], false);
6983 DONE;
6984 })
6985
6986 ;; This instruction directly corresponds to an assembly-language "jal".
6987 ;; There are four cases:
6988 ;;
6989 ;; - -mno-abicalls:
6990 ;; Both symbolic and register destinations are OK. The pattern
6991 ;; always expands to a single mips instruction.
6992 ;;
6993 ;; - -mabicalls/-mno-explicit-relocs:
6994 ;; Again, both symbolic and register destinations are OK.
6995 ;; The call is treated as a multi-instruction black box.
6996 ;;
6997 ;; - -mabicalls/-mexplicit-relocs with n32 or n64:
6998 ;; Only "jal $25" is allowed. This expands to a single "jalr $25"
6999 ;; instruction.
7000 ;;
7001 ;; - -mabicalls/-mexplicit-relocs with o32 or o64:
7002 ;; Only "jal $25" is allowed. The call is actually two instructions:
7003 ;; "jalr $25" followed by an insn to reload $gp.
7004 ;;
7005 ;; In the last case, we can generate the individual instructions with
7006 ;; a define_split. There are several things to be wary of:
7007 ;;
7008 ;; - We can't expose the load of $gp before reload. If we did,
7009 ;; it might get removed as dead, but reload can introduce new
7010 ;; uses of $gp by rematerializing constants.
7011 ;;
7012 ;; - We shouldn't restore $gp after calls that never return.
7013 ;; It isn't valid to insert instructions between a noreturn
7014 ;; call and the following barrier.
7015 ;;
7016 ;; - The splitter deliberately changes the liveness of $gp. The unsplit
7017 ;; instruction preserves $gp and so have no effect on its liveness.
7018 ;; But once we generate the separate insns, it becomes obvious that
7019 ;; $gp is not live on entry to the call.
7020 ;;
7021 (define_insn_and_split "call_internal"
7022 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
7023 (match_operand 1 "" ""))
7024 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7025 ""
7026 {
7027 return (TARGET_SPLIT_CALLS ? "#"
7028 : mips_output_jump (operands, 0, 1, true));
7029 }
7030 "reload_completed && TARGET_SPLIT_CALLS"
7031 [(const_int 0)]
7032 {
7033 mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
7034 DONE;
7035 }
7036 [(set_attr "jal" "indirect,direct")])
7037
7038 (define_insn "call_split"
7039 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
7040 (match_operand 1 "" ""))
7041 (clobber (reg:SI RETURN_ADDR_REGNUM))
7042 (clobber (reg:SI 28))]
7043 "TARGET_SPLIT_CALLS"
7044 { return mips_output_jump (operands, 0, 1, true); }
7045 [(set_attr "jal" "indirect,direct")
7046 (set_attr "jal_macro" "no")])
7047
7048 ;; A pattern for calls that must be made directly. It is used for
7049 ;; MIPS16 calls that the linker may need to redirect to a hard-float
7050 ;; stub; the linker relies on the call relocation type to detect when
7051 ;; such redirection is needed.
7052 (define_insn_and_split "call_internal_direct"
7053 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
7054 (match_operand 1))
7055 (const_int 1)
7056 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7057 ""
7058 {
7059 return (TARGET_SPLIT_CALLS ? "#"
7060 : mips_output_jump (operands, 0, -1, true));
7061 }
7062 "reload_completed && TARGET_SPLIT_CALLS"
7063 [(const_int 0)]
7064 {
7065 mips_split_call (curr_insn,
7066 gen_call_direct_split (operands[0], operands[1]));
7067 DONE;
7068 }
7069 [(set_attr "jal" "direct")])
7070
7071 (define_insn "call_direct_split"
7072 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
7073 (match_operand 1))
7074 (const_int 1)
7075 (clobber (reg:SI RETURN_ADDR_REGNUM))
7076 (clobber (reg:SI 28))]
7077 "TARGET_SPLIT_CALLS"
7078 { return mips_output_jump (operands, 0, -1, true); }
7079 [(set_attr "jal" "direct")
7080 (set_attr "jal_macro" "no")])
7081
7082 (define_expand "call_value"
7083 [(parallel [(set (match_operand 0 "")
7084 (call (match_operand 1 "")
7085 (match_operand 2 "")))
7086 (use (match_operand 3 ""))])] ;; next_arg_reg
7087 ""
7088 {
7089 mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
7090 operands[2], operands[3], false);
7091 DONE;
7092 })
7093
7094 ;; See comment for call_internal.
7095 (define_insn_and_split "call_value_internal"
7096 [(set (match_operand 0 "register_operand" "")
7097 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7098 (match_operand 2 "" "")))
7099 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7100 ""
7101 {
7102 return (TARGET_SPLIT_CALLS ? "#"
7103 : mips_output_jump (operands, 1, 2, true));
7104 }
7105 "reload_completed && TARGET_SPLIT_CALLS"
7106 [(const_int 0)]
7107 {
7108 mips_split_call (curr_insn,
7109 gen_call_value_split (operands[0], operands[1],
7110 operands[2]));
7111 DONE;
7112 }
7113 [(set_attr "jal" "indirect,direct")])
7114
7115 (define_insn "call_value_split"
7116 [(set (match_operand 0 "register_operand" "")
7117 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7118 (match_operand 2 "" "")))
7119 (clobber (reg:SI RETURN_ADDR_REGNUM))
7120 (clobber (reg:SI 28))]
7121 "TARGET_SPLIT_CALLS"
7122 { return mips_output_jump (operands, 1, 2, true); }
7123 [(set_attr "jal" "indirect,direct")
7124 (set_attr "jal_macro" "no")])
7125
7126 ;; See call_internal_direct.
7127 (define_insn_and_split "call_value_internal_direct"
7128 [(set (match_operand 0 "register_operand")
7129 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
7130 (match_operand 2)))
7131 (const_int 1)
7132 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7133 ""
7134 {
7135 return (TARGET_SPLIT_CALLS ? "#"
7136 : mips_output_jump (operands, 1, -1, true));
7137 }
7138 "reload_completed && TARGET_SPLIT_CALLS"
7139 [(const_int 0)]
7140 {
7141 mips_split_call (curr_insn,
7142 gen_call_value_direct_split (operands[0], operands[1],
7143 operands[2]));
7144 DONE;
7145 }
7146 [(set_attr "jal" "direct")])
7147
7148 (define_insn "call_value_direct_split"
7149 [(set (match_operand 0 "register_operand")
7150 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
7151 (match_operand 2)))
7152 (const_int 1)
7153 (clobber (reg:SI RETURN_ADDR_REGNUM))
7154 (clobber (reg:SI 28))]
7155 "TARGET_SPLIT_CALLS"
7156 { return mips_output_jump (operands, 1, -1, true); }
7157 [(set_attr "jal" "direct")
7158 (set_attr "jal_macro" "no")])
7159
7160 ;; See comment for call_internal.
7161 (define_insn_and_split "call_value_multiple_internal"
7162 [(set (match_operand 0 "register_operand" "")
7163 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7164 (match_operand 2 "" "")))
7165 (set (match_operand 3 "register_operand" "")
7166 (call (mem:SI (match_dup 1))
7167 (match_dup 2)))
7168 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7169 ""
7170 {
7171 return (TARGET_SPLIT_CALLS ? "#"
7172 : mips_output_jump (operands, 1, 2, true));
7173 }
7174 "reload_completed && TARGET_SPLIT_CALLS"
7175 [(const_int 0)]
7176 {
7177 mips_split_call (curr_insn,
7178 gen_call_value_multiple_split (operands[0], operands[1],
7179 operands[2], operands[3]));
7180 DONE;
7181 }
7182 [(set_attr "jal" "indirect,direct")])
7183
7184 (define_insn "call_value_multiple_split"
7185 [(set (match_operand 0 "register_operand" "")
7186 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7187 (match_operand 2 "" "")))
7188 (set (match_operand 3 "register_operand" "")
7189 (call (mem:SI (match_dup 1))
7190 (match_dup 2)))
7191 (clobber (reg:SI RETURN_ADDR_REGNUM))
7192 (clobber (reg:SI 28))]
7193 "TARGET_SPLIT_CALLS"
7194 { return mips_output_jump (operands, 1, 2, true); }
7195 [(set_attr "jal" "indirect,direct")
7196 (set_attr "jal_macro" "no")])
7197
7198 ;; Call subroutine returning any type.
7199
7200 (define_expand "untyped_call"
7201 [(parallel [(call (match_operand 0 "")
7202 (const_int 0))
7203 (match_operand 1 "")
7204 (match_operand 2 "")])]
7205 ""
7206 {
7207 int i;
7208
7209 emit_call_insn (gen_call (operands[0], const0_rtx, NULL, const0_rtx));
7210
7211 for (i = 0; i < XVECLEN (operands[2], 0); i++)
7212 {
7213 rtx set = XVECEXP (operands[2], 0, i);
7214 mips_emit_move (SET_DEST (set), SET_SRC (set));
7215 }
7216
7217 emit_insn (gen_blockage ());
7218 DONE;
7219 })
7220 \f
7221 ;;
7222 ;; ....................
7223 ;;
7224 ;; MISC.
7225 ;;
7226 ;; ....................
7227 ;;
7228
7229
7230 (define_insn "prefetch"
7231 [(prefetch (match_operand:QI 0 "address_operand" "ZD")
7232 (match_operand 1 "const_int_operand" "n")
7233 (match_operand 2 "const_int_operand" "n"))]
7234 "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
7235 {
7236 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT)
7237 {
7238 /* Loongson 2[ef] and Loongson ext use load to $0 for prefetching. */
7239 if (TARGET_64BIT)
7240 return "ld\t$0,%a0";
7241 else
7242 return "lw\t$0,%a0";
7243 }
7244 /* Loongson ext2 implementation pref instructions. */
7245 if (TARGET_LOONGSON_EXT2)
7246 {
7247 operands[1] = mips_loongson_ext2_prefetch_cookie (operands[1],
7248 operands[2]);
7249 return "pref\t%1, %a0";
7250 }
7251 operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
7252 return "pref\t%1,%a0";
7253 }
7254 [(set_attr "type" "prefetch")])
7255
7256 (define_insn "*prefetch_indexed_<mode>"
7257 [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
7258 (match_operand:P 1 "register_operand" "d"))
7259 (match_operand 2 "const_int_operand" "n")
7260 (match_operand 3 "const_int_operand" "n"))]
7261 "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
7262 {
7263 if (TARGET_LOONGSON_EXT)
7264 {
7265 /* Loongson Loongson ext use index load to $0 for prefetching. */
7266 if (TARGET_64BIT)
7267 return "gsldx\t$0,0(%0,%1)";
7268 else
7269 return "gslwx\t$0,0(%0,%1)";
7270 }
7271 /* Loongson ext2 implementation pref instructions. */
7272 if (TARGET_LOONGSON_EXT2)
7273 {
7274 operands[2] = mips_loongson_ext2_prefetch_cookie (operands[2],
7275 operands[3]);
7276 return "prefx\t%2,%1(%0)";
7277 }
7278 operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
7279 return "prefx\t%2,%1(%0)";
7280 }
7281 [(set_attr "type" "prefetchx")])
7282
7283 (define_insn "nop"
7284 [(const_int 0)]
7285 ""
7286 "%(nop%)"
7287 [(set_attr "type" "nop")
7288 (set_attr "mode" "none")])
7289
7290 ;; Like nop, but commented out when outside a .set noreorder block.
7291 (define_insn "hazard_nop"
7292 [(const_int 1)]
7293 ""
7294 {
7295 if (mips_noreorder.nesting_level > 0)
7296 return "nop";
7297 else
7298 return "#nop";
7299 }
7300 [(set_attr "type" "nop")])
7301
7302 ;; The `.insn' pseudo-op.
7303 (define_insn "insn_pseudo"
7304 [(unspec_volatile [(const_int 0)] UNSPEC_INSN_PSEUDO)]
7305 ""
7306 ".insn"
7307 [(set_attr "mode" "none")
7308 (set_attr "insn_count" "0")])
7309 \f
7310 ;; MIPS4 Conditional move instructions.
7311
7312 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
7313 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7314 (if_then_else:GPR
7315 (match_operator 4 "equality_operator"
7316 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7317 (const_int 0)])
7318 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7319 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7320 "ISA_HAS_CONDMOVE"
7321 "@
7322 mov%T4\t%0,%z2,%1
7323 mov%t4\t%0,%z3,%1"
7324 [(set_attr "type" "condmove")
7325 (set_attr "mode" "<GPR:MODE>")])
7326
7327 (define_insn "*mov<GPR:mode>_on_<GPR2:mode>_ne"
7328 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7329 (if_then_else:GPR
7330 (match_operand:GPR2 1 "register_operand" "<GPR2:reg>,<GPR2:reg>")
7331 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7332 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7333 "ISA_HAS_CONDMOVE"
7334 "@
7335 movn\t%0,%z2,%1
7336 movz\t%0,%z3,%1"
7337 [(set_attr "type" "condmove")
7338 (set_attr "mode" "<GPR:MODE>")])
7339
7340 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
7341 [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
7342 (if_then_else:SCALARF
7343 (match_operator 4 "equality_operator"
7344 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7345 (const_int 0)])
7346 (match_operand:SCALARF 2 "register_operand" "f,0")
7347 (match_operand:SCALARF 3 "register_operand" "0,f")))]
7348 "ISA_HAS_FP_CONDMOVE"
7349 "@
7350 mov%T4.<fmt>\t%0,%2,%1
7351 mov%t4.<fmt>\t%0,%3,%1"
7352 [(set_attr "type" "condmove")
7353 (set_attr "mode" "<SCALARF:MODE>")])
7354
7355 (define_insn "*sel<code><GPR:mode>_using_<GPR2:mode>"
7356 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7357 (if_then_else:GPR
7358 (equality_op:GPR2 (match_operand:GPR2 1 "register_operand" "d,d")
7359 (const_int 0))
7360 (match_operand:GPR 2 "reg_or_0_operand" "d,J")
7361 (match_operand:GPR 3 "reg_or_0_operand" "J,d")))]
7362 "ISA_HAS_SEL
7363 && (register_operand (operands[2], <GPR:MODE>mode)
7364 != register_operand (operands[3], <GPR:MODE>mode))"
7365 "@
7366 <sel>\t%0,%2,%1
7367 <selinv>\t%0,%3,%1"
7368 [(set_attr "type" "condmove")
7369 (set_attr "mode" "<GPR:MODE>")])
7370
7371 ;; sel.fmt copies the 3rd argument when the 1st is non-zero and the 2nd
7372 ;; argument if the 1st is zero. This means operand 2 and 3 are
7373 ;; inverted in the instruction.
7374
7375 (define_insn "*sel<mode>"
7376 [(set (match_operand:SCALARF 0 "register_operand" "=f,f,f")
7377 (if_then_else:SCALARF
7378 (ne:CCF (match_operand:CCF 1 "register_operand" "0,f,f")
7379 (const_int 0))
7380 (match_operand:SCALARF 2 "reg_or_0_operand" "f,G,f")
7381 (match_operand:SCALARF 3 "reg_or_0_operand" "f,f,G")))]
7382 "ISA_HAS_SEL && ISA_HAS_CCF"
7383 "@
7384 sel.<fmt>\t%0,%3,%2
7385 seleqz.<fmt>\t%0,%3,%1
7386 selnez.<fmt>\t%0,%2,%1"
7387 [(set_attr "type" "condmove")
7388 (set_attr "mode" "<SCALARF:MODE>")])
7389
7390 ;; These are the main define_expand's used to make conditional moves.
7391
7392 (define_expand "mov<mode>cc"
7393 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7394 (set (match_operand:GPR 0 "register_operand")
7395 (if_then_else:GPR (match_dup 5)
7396 (match_operand:GPR 2 "reg_or_0_operand")
7397 (match_operand:GPR 3 "reg_or_0_operand")))]
7398 "ISA_HAS_CONDMOVE || ISA_HAS_SEL"
7399 {
7400 if (!ISA_HAS_FP_CONDMOVE
7401 && !INTEGRAL_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7402 FAIL;
7403
7404 mips_expand_conditional_move (operands);
7405 DONE;
7406 })
7407
7408 (define_expand "mov<mode>cc"
7409 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7410 (set (match_operand:SCALARF 0 "register_operand")
7411 (if_then_else:SCALARF (match_dup 5)
7412 (match_operand:SCALARF 2 "reg_or_0_operand")
7413 (match_operand:SCALARF 3 "reg_or_0_operand")))]
7414 "ISA_HAS_FP_CONDMOVE
7415 || (ISA_HAS_SEL && ISA_HAS_CCF)"
7416 {
7417 if (ISA_HAS_SEL && !FLOAT_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7418 FAIL;
7419
7420 /* Workaround an LRA bug which means that tied operands in the sel.fmt
7421 pattern lead to the double precision destination of sel.d getting
7422 reloaded with the full register file usable and the restrictions on
7423 whether the CCFmode input can be used in odd-numbered single-precision
7424 registers are ignored. For consistency reasons the CCF mode values
7425 must be guaranteed to only exist in the even-registers because of
7426 the unusual duality between single and double precision values. */
7427 if (ISA_HAS_SEL && <MODE>mode == DFmode
7428 && (!TARGET_ODD_SPREG || TARGET_FLOATXX))
7429 FAIL;
7430
7431 mips_expand_conditional_move (operands);
7432 DONE;
7433 })
7434 \f
7435 ;;
7436 ;; ....................
7437 ;;
7438 ;; mips16 inline constant tables
7439 ;;
7440 ;; ....................
7441 ;;
7442
7443 (define_insn "consttable"
7444 [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
7445 UNSPEC_CONSTTABLE)]
7446 ""
7447 ""
7448 [(set_attr "mode" "none")
7449 (set_attr "insn_count" "0")])
7450
7451 (define_insn "consttable_end"
7452 [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
7453 UNSPEC_CONSTTABLE_END)]
7454 ""
7455 ""
7456 [(set_attr "mode" "none")
7457 (set_attr "insn_count" "0")])
7458
7459 (define_insn "consttable_tls_reloc"
7460 [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
7461 (match_operand 1 "const_int_operand" "")]
7462 UNSPEC_CONSTTABLE_INT)]
7463 "TARGET_MIPS16_PCREL_LOADS"
7464 { return mips_output_tls_reloc_directive (&operands[0]); }
7465 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7466
7467 (define_insn "consttable_int"
7468 [(unspec_volatile [(match_operand 0 "consttable_operand" "")
7469 (match_operand 1 "const_int_operand" "")]
7470 UNSPEC_CONSTTABLE_INT)]
7471 "TARGET_MIPS16"
7472 {
7473 assemble_integer (mips_strip_unspec_address (operands[0]),
7474 INTVAL (operands[1]),
7475 BITS_PER_UNIT * INTVAL (operands[1]), 1);
7476 return "";
7477 }
7478 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7479
7480 (define_insn "consttable_float"
7481 [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
7482 UNSPEC_CONSTTABLE_FLOAT)]
7483 "TARGET_MIPS16"
7484 {
7485 gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
7486 assemble_real (*CONST_DOUBLE_REAL_VALUE (operands[0]),
7487 as_a <scalar_float_mode> (GET_MODE (operands[0])),
7488 GET_MODE_BITSIZE (GET_MODE (operands[0])));
7489 return "";
7490 }
7491 [(set (attr "length")
7492 (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
7493
7494 (define_insn "align"
7495 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
7496 ""
7497 ".align\t%0"
7498 [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
7499 \f
7500 (define_split
7501 [(match_operand 0 "small_data_pattern")]
7502 "reload_completed"
7503 [(match_dup 0)]
7504 { operands[0] = mips_rewrite_small_data (operands[0]); })
7505
7506 ;;
7507 ;; ....................
7508 ;;
7509 ;; MIPS16e Save/Restore
7510 ;;
7511 ;; ....................
7512 ;;
7513
7514 (define_insn "*mips16e_save_restore"
7515 [(match_parallel 0 ""
7516 [(set (match_operand:SI 1 "register_operand")
7517 (plus:SI (match_dup 1)
7518 (match_operand:SI 2 "const_int_operand")))])]
7519 "operands[1] == stack_pointer_rtx
7520 && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
7521 { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
7522 [(set_attr "type" "arith")
7523 (set_attr "extended_mips16" "yes")])
7524
7525 ;; Thread-Local Storage
7526
7527 ;; The TLS base pointer is accessed via "rdhwr $3, $29". No current
7528 ;; MIPS architecture defines this register, and no current
7529 ;; implementation provides it; instead, any OS which supports TLS is
7530 ;; expected to trap and emulate this instruction. rdhwr is part of the
7531 ;; MIPS 32r2 specification, but we use it on any architecture because
7532 ;; we expect it to be emulated. Use .set to force the assembler to
7533 ;; accept it.
7534 ;;
7535 ;; We do not use a constraint to force the destination to be $3
7536 ;; because $3 can appear explicitly as a function return value.
7537 ;; If we leave the use of $3 implicit in the constraints until
7538 ;; reload, we may end up making a $3 return value live across
7539 ;; the instruction, leading to a spill failure when reloading it.
7540 (define_insn_and_split "tls_get_tp_<mode>"
7541 [(set (match_operand:P 0 "register_operand" "=d")
7542 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7543 (clobber (reg:P TLS_GET_TP_REGNUM))]
7544 "HAVE_AS_TLS && !TARGET_MIPS16"
7545 "#"
7546 "&& reload_completed"
7547 [(set (reg:P TLS_GET_TP_REGNUM)
7548 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7549 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7550 ""
7551 [(set_attr "type" "unknown")
7552 (set_attr "mode" "<MODE>")
7553 (set_attr "insn_count" "2")])
7554
7555 (define_insn "*tls_get_tp_<mode>_split"
7556 [(set (reg:P TLS_GET_TP_REGNUM)
7557 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
7558 "HAVE_AS_TLS && !TARGET_MIPS16"
7559 {
7560 if (mips_isa_rev >= 2)
7561 return "rdhwr\t$3,$29";
7562
7563 return ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop";
7564 }
7565 [(set_attr "type" "unknown")
7566 ; Since rdhwr always generates a trap for now, putting it in a delay
7567 ; slot would make the kernel's emulation of it much slower.
7568 (set_attr "can_delay" "no")
7569 (set_attr "mode" "<MODE>")])
7570
7571 ;; In MIPS16 mode, the TLS base pointer is accessed by a
7572 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
7573 ;; accessible in MIPS16.
7574 ;;
7575 ;; This is not represented as a call insn, to avoid the
7576 ;; unnecesarry clobbering of caller-save registers by a
7577 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
7578 ;;
7579 ;; A $25 clobber is added to cater for a $25 load stub added by the
7580 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
7581
7582 (define_insn_and_split "tls_get_tp_mips16_<mode>"
7583 [(set (match_operand:P 0 "register_operand" "=d")
7584 (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
7585 UNSPEC_TLS_GET_TP))
7586 (clobber (reg:P TLS_GET_TP_REGNUM))
7587 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7588 (clobber (reg:P RETURN_ADDR_REGNUM))]
7589 "HAVE_AS_TLS && TARGET_MIPS16"
7590 "#"
7591 "&& reload_completed"
7592 [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
7593 (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
7594 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7595 (clobber (reg:P RETURN_ADDR_REGNUM))])
7596 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7597 ""
7598 [(set_attr "type" "multi")
7599 (set_attr "insn_count" "4")
7600 (set_attr "mode" "<MODE>")])
7601
7602 (define_insn "*tls_get_tp_mips16_call_<mode>"
7603 [(set (reg:P TLS_GET_TP_REGNUM)
7604 (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
7605 UNSPEC_TLS_GET_TP))
7606 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7607 (clobber (reg:P RETURN_ADDR_REGNUM))]
7608 "HAVE_AS_TLS && TARGET_MIPS16"
7609 { return mips_output_jump (operands, 0, -1, true); }
7610 [(set_attr "type" "call")
7611 (set_attr "insn_count" "3")
7612 (set_attr "mode" "<MODE>")])
7613
7614 ;; Named pattern for expanding thread pointer reference.
7615 (define_expand "get_thread_pointer<mode>"
7616 [(match_operand:P 0 "register_operand" "=d")]
7617 "HAVE_AS_TLS"
7618 {
7619 mips_expand_thread_pointer (operands[0]);
7620 DONE;
7621 })
7622
7623 ;; __builtin_mips_get_fcsr: move the FCSR into operand 0.
7624 (define_expand "mips_get_fcsr"
7625 [(set (match_operand:SI 0 "register_operand")
7626 (unspec_volatile:SI [(const_int 0)] UNSPEC_GET_FCSR))]
7627 "TARGET_HARD_FLOAT_ABI"
7628 {
7629 if (TARGET_MIPS16)
7630 {
7631 mips16_expand_get_fcsr (operands[0]);
7632 DONE;
7633 }
7634 })
7635
7636 (define_insn "*mips_get_fcsr"
7637 [(set (match_operand:SI 0 "register_operand" "=d")
7638 (unspec_volatile:SI [(const_int 0)] UNSPEC_GET_FCSR))]
7639 "TARGET_HARD_FLOAT"
7640 "cfc1\t%0,$31")
7641
7642 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7643 (define_insn "mips_get_fcsr_mips16_<mode>"
7644 [(set (reg:SI GET_FCSR_REGNUM)
7645 (unspec:SI [(match_operand:P 0 "call_insn_operand" "dS")]
7646 UNSPEC_GET_FCSR))
7647 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7648 (clobber (reg:P RETURN_ADDR_REGNUM))]
7649 "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7650 { return mips_output_jump (operands, 0, -1, true); }
7651 [(set_attr "type" "call")
7652 (set_attr "insn_count" "3")])
7653
7654 ;; __builtin_mips_set_fcsr: move operand 0 into the FCSR.
7655 (define_expand "mips_set_fcsr"
7656 [(unspec_volatile [(match_operand:SI 0 "register_operand")]
7657 UNSPEC_SET_FCSR)]
7658 "TARGET_HARD_FLOAT_ABI"
7659 {
7660 if (TARGET_MIPS16)
7661 {
7662 mips16_expand_set_fcsr (operands[0]);
7663 DONE;
7664 }
7665 })
7666
7667 (define_insn "*mips_set_fcsr"
7668 [(unspec_volatile [(match_operand:SI 0 "register_operand" "d")]
7669 UNSPEC_SET_FCSR)]
7670 "TARGET_HARD_FLOAT"
7671 "ctc1\t%0,$31")
7672
7673 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7674 (define_insn "mips_set_fcsr_mips16_<mode>"
7675 [(unspec_volatile:SI [(match_operand:P 0 "call_insn_operand" "dS")
7676 (reg:SI SET_FCSR_REGNUM)] UNSPEC_SET_FCSR)
7677 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7678 (clobber (reg:P RETURN_ADDR_REGNUM))]
7679 "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7680 { return mips_output_jump (operands, 0, -1, true); }
7681 [(set_attr "type" "call")
7682 (set_attr "insn_count" "3")])
7683
7684 ;; Match paired HI/SI/SF/DFmode load/stores.
7685 (define_insn "*join2_load_store<JOIN_MODE:mode>"
7686 [(set (match_operand:JOIN_MODE 0 "nonimmediate_operand" "=d,f,m,m")
7687 (match_operand:JOIN_MODE 1 "nonimmediate_operand" "m,m,d,f"))
7688 (set (match_operand:JOIN_MODE 2 "nonimmediate_operand" "=d,f,m,m")
7689 (match_operand:JOIN_MODE 3 "nonimmediate_operand" "m,m,d,f"))]
7690 "ENABLE_LD_ST_PAIRS && reload_completed"
7691 {
7692 bool load_p = (which_alternative == 0 || which_alternative == 1);
7693 /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7694 Hardware does not bond those loads, even when they are consecutive.
7695 However, order of the loads need to be checked for correctness. */
7696 if (!load_p || !reg_overlap_mentioned_p (operands[0], operands[1]))
7697 {
7698 output_asm_insn (mips_output_move (operands[0], operands[1]),
7699 operands);
7700 output_asm_insn (mips_output_move (operands[2], operands[3]),
7701 &operands[2]);
7702 }
7703 else
7704 {
7705 output_asm_insn (mips_output_move (operands[2], operands[3]),
7706 &operands[2]);
7707 output_asm_insn (mips_output_move (operands[0], operands[1]),
7708 operands);
7709 }
7710 return "";
7711 }
7712 [(set_attr "move_type" "load,fpload,store,fpstore")
7713 (set_attr "insn_count" "2,2,2,2")])
7714
7715 ;; 2 HI/SI/SF/DF loads are joined.
7716 ;; P5600 does not support bonding of two LBs, hence QI mode is not included.
7717 ;; The loads must be non-volatile as they might be reordered at the time of asm
7718 ;; generation.
7719 (define_peephole2
7720 [(set (match_operand:JOIN_MODE 0 "register_operand")
7721 (match_operand:JOIN_MODE 1 "non_volatile_mem_operand"))
7722 (set (match_operand:JOIN_MODE 2 "register_operand")
7723 (match_operand:JOIN_MODE 3 "non_volatile_mem_operand"))]
7724 "ENABLE_LD_ST_PAIRS
7725 && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, true)"
7726 [(parallel [(set (match_dup 0)
7727 (match_dup 1))
7728 (set (match_dup 2)
7729 (match_dup 3))])]
7730 "")
7731
7732 ;; 2 HI/SI/SF/DF stores are joined.
7733 ;; P5600 does not support bonding of two SBs, hence QI mode is not included.
7734 (define_peephole2
7735 [(set (match_operand:JOIN_MODE 0 "memory_operand")
7736 (match_operand:JOIN_MODE 1 "register_operand"))
7737 (set (match_operand:JOIN_MODE 2 "memory_operand")
7738 (match_operand:JOIN_MODE 3 "register_operand"))]
7739 "ENABLE_LD_ST_PAIRS
7740 && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, false)"
7741 [(parallel [(set (match_dup 0)
7742 (match_dup 1))
7743 (set (match_dup 2)
7744 (match_dup 3))])]
7745 "")
7746
7747 ;; Match paired HImode loads.
7748 (define_insn "*join2_loadhi"
7749 [(set (match_operand:SI 0 "register_operand" "=r")
7750 (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand" "m")))
7751 (set (match_operand:SI 2 "register_operand" "=r")
7752 (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand" "m")))]
7753 "ENABLE_LD_ST_PAIRS && reload_completed"
7754 {
7755 /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7756 Hardware does not bond those loads, even when they are consecutive.
7757 However, order of the loads need to be checked for correctness. */
7758 if (!reg_overlap_mentioned_p (operands[0], operands[1]))
7759 {
7760 output_asm_insn ("lh<u>\t%0,%1", operands);
7761 output_asm_insn ("lh<u>\t%2,%3", operands);
7762 }
7763 else
7764 {
7765 output_asm_insn ("lh<u>\t%2,%3", operands);
7766 output_asm_insn ("lh<u>\t%0,%1", operands);
7767 }
7768
7769 return "";
7770 }
7771 [(set_attr "move_type" "load")
7772 (set_attr "insn_count" "2")])
7773
7774
7775 ;; 2 HI loads are joined.
7776 (define_peephole2
7777 [(set (match_operand:SI 0 "register_operand")
7778 (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand")))
7779 (set (match_operand:SI 2 "register_operand")
7780 (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand")))]
7781 "ENABLE_LD_ST_PAIRS
7782 && mips_load_store_bonding_p (operands, HImode, true)"
7783 [(parallel [(set (match_dup 0)
7784 (any_extend:SI (match_dup 1)))
7785 (set (match_dup 2)
7786 (any_extend:SI (match_dup 3)))])]
7787 "")
7788
7789 \f
7790 ;; Synchronization instructions.
7791
7792 (include "sync.md")
7793
7794 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
7795
7796 (include "mips-ps-3d.md")
7797
7798 ; The MIPS DSP Instructions.
7799
7800 (include "mips-dsp.md")
7801
7802 ; The MIPS DSP REV 2 Instructions.
7803
7804 (include "mips-dspr2.md")
7805
7806 ; MIPS fixed-point instructions.
7807 (include "mips-fixed.md")
7808
7809 ; microMIPS patterns.
7810 (include "micromips.md")
7811
7812 ; Loongson MultiMedia extensions Instructions (MMI) patterns.
7813 (include "loongson-mmi.md")
7814
7815 ; The MIPS MSA Instructions.
7816 (include "mips-msa.md")
7817
7818 (define_c_enum "unspec" [
7819 UNSPEC_ADDRESS_FIRST
7820 ])