1 ;; Machine description the Motorola MCore
2 ;; Copyright (C) 1993, 1999, 2000, 2004, 2005, 2007
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Motorola.
6 ;; This file is part of GCC.
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3. If not see
20 ;; <http://www.gnu.org/licenses/>.
22 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
26 ;; -------------------------------------------------------------------------
28 ;; -------------------------------------------------------------------------
32 (define_attr "type" "brcond,branch,jmp,load,store,move,alu,shift"
35 ;; If a branch destination is within -2048..2047 bytes away from the
36 ;; instruction it can be 2 bytes long. All other conditional branches
37 ;; are 10 bytes long, and all other unconditional branches are 8 bytes.
39 ;; the assembler handles the long-branch span case for us if we use
40 ;; the "jb*" mnemonics for jumps/branches. This pushes the span
41 ;; calculations and the literal table placement into the assembler,
42 ;; where their interactions can be managed in a single place.
44 ;; All MCORE instructions are two bytes long.
46 (define_attr "length" "" (const_int 2))
48 ;; Scheduling. We only model a simple load latency.
49 (define_insn_reservation "any_insn" 1
50 (eq_attr "type" "!load")
52 (define_insn_reservation "memory" 2
53 (eq_attr "type" "load")
56 (include "predicates.md")
58 ;; -------------------------------------------------------------------------
60 ;; -------------------------------------------------------------------------
64 (sign_extract:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
66 (match_operand:SI 1 "mcore_literal_K_operand" "K")))]
69 [(set_attr "type" "shift")])
73 (zero_extract:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
75 (match_operand:SI 1 "mcore_literal_K_operand" "K")))]
78 [(set_attr "type" "shift")])
80 ;;; This is created by combine.
83 (ne:CC (zero_extract:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
85 (match_operand:SI 1 "mcore_literal_K_operand" "K"))
89 [(set_attr "type" "shift")])
92 ;; Created by combine from conditional patterns below (see sextb/btsti rx,31)
96 (ne:CC (lshiftrt:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
99 "GET_CODE(operands[0]) == SUBREG &&
100 GET_MODE(SUBREG_REG(operands[0])) == QImode"
102 [(set_attr "type" "shift")])
106 (ne:CC (lshiftrt:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
109 "GET_CODE(operands[0]) == SUBREG &&
110 GET_MODE(SUBREG_REG(operands[0])) == HImode"
112 [(set_attr "type" "shift")])
116 (if_then_else (ne (eq:CC (zero_extract:SI
117 (match_operand:SI 0 "mcore_arith_reg_operand" "")
119 (match_operand:SI 1 "mcore_literal_K_operand" ""))
122 (label_ref (match_operand 2 "" ""))
126 (zero_extract:SI (match_dup 0) (const_int 1) (match_dup 1)))
127 (set (pc) (if_then_else (eq (reg:CC 17) (const_int 0))
128 (label_ref (match_dup 2))
134 (if_then_else (eq (ne:CC (zero_extract:SI
135 (match_operand:SI 0 "mcore_arith_reg_operand" "")
137 (match_operand:SI 1 "mcore_literal_K_operand" ""))
140 (label_ref (match_operand 2 "" ""))
144 (zero_extract:SI (match_dup 0) (const_int 1) (match_dup 1)))
145 (set (pc) (if_then_else (eq (reg:CC 17) (const_int 0))
146 (label_ref (match_dup 2))
150 ;; XXX - disabled by nickc because it fails on libiberty/fnmatch.c
152 ;; ; Experimental - relax immediates for and, andn, or, and tst to allow
153 ;; ; any immediate value (or an immediate at all -- or, andn, & tst).
154 ;; ; This is done to allow bit field masks to fold together in combine.
155 ;; ; The reload phase will force the immediate into a register at the
156 ;; ; very end. This helps in some cases, but hurts in others: we'd
157 ;; ; really like to cse these immediates. However, there is a phase
158 ;; ; ordering problem here. cse picks up individual masks and cse's
159 ;; ; those, but not folded masks (cse happens before combine). It's
160 ;; ; not clear what the best solution is because we really want cse
161 ;; ; before combine (leaving the bit field masks alone). To pick up
162 ;; ; relaxed immediates use -mrelax-immediates. It might take some
163 ;; ; experimenting to see which does better (i.e. regular imms vs.
164 ;; ; arbitrary imms) for a particular code. BRC
168 ;; (ne:CC (and:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
169 ;; (match_operand:SI 1 "mcore_arith_any_imm_operand" "rI"))
171 ;; "TARGET_RELAX_IMM"
176 ;; (ne:CC (and:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
177 ;; (match_operand:SI 1 "mcore_arith_M_operand" "r"))
179 ;; "!TARGET_RELAX_IMM"
184 (ne:CC (and:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
185 (match_operand:SI 1 "mcore_arith_M_operand" "r"))
194 (ne:CC (ne:SI (leu:CC (match_operand:SI 0 "mcore_arith_reg_operand" "")
195 (match_operand:SI 1 "mcore_arith_reg_operand" ""))
198 (clobber (match_operand:CC 2 "mcore_arith_reg_operand" ""))])]
200 [(set (reg:CC 17) (ne:SI (match_dup 0) (const_int 0)))
201 (set (reg:CC 17) (leu:CC (match_dup 0) (match_dup 1)))])
203 ;; -------------------------------------------------------------------------
204 ;; SImode signed integer comparisons
205 ;; -------------------------------------------------------------------------
207 (define_insn "decne_t"
208 [(set (reg:CC 17) (ne:CC (plus:SI (match_operand:SI 0 "mcore_arith_reg_operand" "+r")
212 (plus:SI (match_dup 0)
217 ;; The combiner seems to prefer the following to the former.
220 [(set (reg:CC 17) (ne:CC (match_operand:SI 0 "mcore_arith_reg_operand" "+r")
223 (plus:SI (match_dup 0)
228 (define_insn "cmpnesi_t"
229 [(set (reg:CC 17) (ne:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
230 (match_operand:SI 1 "mcore_arith_reg_operand" "r")))]
234 (define_insn "cmpneisi_t"
235 [(set (reg:CC 17) (ne:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
236 (match_operand:SI 1 "mcore_arith_K_operand" "K")))]
240 (define_insn "cmpgtsi_t"
241 [(set (reg:CC 17) (gt:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
242 (match_operand:SI 1 "mcore_arith_reg_operand" "r")))]
247 [(set (reg:CC 17) (gt:CC (plus:SI
248 (match_operand:SI 0 "mcore_arith_reg_operand" "+r")
251 (set (match_dup 0) (plus:SI (match_dup 0) (const_int -1)))]
255 (define_insn "cmpltsi_t"
256 [(set (reg:CC 17) (lt:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
257 (match_operand:SI 1 "mcore_arith_reg_operand" "r")))]
262 (define_insn "cmpltisi_t"
263 [(set (reg:CC 17) (lt:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
264 (match_operand:SI 1 "mcore_arith_J_operand" "J")))]
270 [(set (reg:CC 17) (lt:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
276 [(set (reg:CC 17) (lt:CC (plus:SI
277 (match_operand:SI 0 "mcore_arith_reg_operand" "+r")
280 (set (match_dup 0) (plus:SI (match_dup 0) (const_int -1)))]
284 ;; -------------------------------------------------------------------------
285 ;; SImode unsigned integer comparisons
286 ;; -------------------------------------------------------------------------
288 (define_insn "cmpgeusi_t"
289 [(set (reg:CC 17) (geu:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
290 (match_operand:SI 1 "mcore_arith_reg_operand" "r")))]
294 (define_insn "cmpgeusi_0"
295 [(set (reg:CC 17) (geu:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
300 (define_insn "cmpleusi_t"
301 [(set (reg:CC 17) (leu:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
302 (match_operand:SI 1 "mcore_arith_reg_operand" "r")))]
306 ;; -------------------------------------------------------------------------
307 ;; Logical operations
308 ;; -------------------------------------------------------------------------
310 ;; Logical AND clearing a single bit. andsi3 knows that we have this
311 ;; pattern and allows the constant literal pass through.
314 ;; RBE 2/97: don't need this pattern any longer...
315 ;; RBE: I don't think we need both "S" and exact_log2() clauses.
317 ;; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
318 ;; (and:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
319 ;; (match_operand:SI 2 "const_int_operand" "S")))]
320 ;; "mcore_arith_S_operand (operands[2])"
324 (define_insn "andnsi3"
325 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
326 (and:SI (not:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r"))
327 (match_operand:SI 2 "mcore_arith_reg_operand" "0")))]
331 (define_expand "andsi3"
332 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
333 (and:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
334 (match_operand:SI 2 "nonmemory_operand" "")))]
338 if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0
339 && ! mcore_arith_S_operand (operands[2]))
341 HOST_WIDE_INT not_value = ~ INTVAL (operands[2]);
343 if ( CONST_OK_FOR_I (not_value)
344 || CONST_OK_FOR_M (not_value)
345 || CONST_OK_FOR_N (not_value))
347 operands[2] = copy_to_mode_reg (SImode, GEN_INT (not_value));
348 emit_insn (gen_andnsi3 (operands[0], operands[2], operands[1]));
353 if (! mcore_arith_K_S_operand (operands[2], SImode))
354 operands[2] = copy_to_mode_reg (SImode, operands[2]);
358 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
359 (and:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0,r,0")
360 (match_operand:SI 2 "mcore_arith_any_imm_operand" "r,K,0,S")))]
364 switch (which_alternative)
366 case 0: return \"and %0,%2\";
367 case 1: return \"andi %0,%2\";
368 case 2: return \"and %0,%1\";
369 /* case -1: return \"bclri %0,%Q2\"; will not happen */
370 case 3: return mcore_output_bclri (operands[0], INTVAL (operands[2]));
371 default: gcc_unreachable ();
375 ;; This was the old "S" which was "!(2^n)" */
376 ;; case -1: return \"bclri %0,%Q2\"; will not happen */
379 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
380 (and:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0,r,0")
381 (match_operand:SI 2 "mcore_arith_K_S_operand" "r,K,0,S")))]
385 switch (which_alternative)
387 case 0: return \"and %0,%2\";
388 case 1: return \"andi %0,%2\";
389 case 2: return \"and %0,%1\";
390 case 3: return mcore_output_bclri (operands[0], INTVAL (operands[2]));
391 default: gcc_unreachable ();
395 ;(define_insn "iorsi3"
396 ; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
397 ; (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
398 ; (match_operand:SI 2 "mcore_arith_reg_operand" "r")))]
402 ; need an expand to resolve ambiguity betw. the two iors below.
403 (define_expand "iorsi3"
404 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
405 (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
406 (match_operand:SI 2 "nonmemory_operand" "")))]
410 if (! mcore_arith_M_operand (operands[2], SImode))
411 operands[2] = copy_to_mode_reg (SImode, operands[2]);
415 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r")
416 (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0,0,0")
417 (match_operand:SI 2 "mcore_arith_any_imm_operand" "r,M,T")))]
421 switch (which_alternative)
423 case 0: return \"or %0,%2\";
424 case 1: return \"bseti %0,%P2\";
425 case 2: return mcore_output_bseti (operands[0], INTVAL (operands[2]));
426 default: gcc_unreachable ();
431 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r")
432 (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0,0,0")
433 (match_operand:SI 2 "mcore_arith_M_operand" "r,M,T")))]
437 switch (which_alternative)
439 case 0: return \"or %0,%2\";
440 case 1: return \"bseti %0,%P2\";
441 case 2: return mcore_output_bseti (operands[0], INTVAL (operands[2]));
442 default: gcc_unreachable ();
447 ; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
448 ; (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
449 ; (match_operand:SI 2 "const_int_operand" "M")))]
450 ; "exact_log2 (INTVAL (operands[2])) >= 0"
454 ; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
455 ; (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
456 ; (match_operand:SI 2 "const_int_operand" "i")))]
457 ; "mcore_num_ones (INTVAL (operands[2])) < 3"
458 ; "* return mcore_output_bseti (operands[0], INTVAL (operands[2]));")
460 (define_insn "xorsi3"
461 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
462 (xor:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
463 (match_operand:SI 2 "mcore_arith_reg_operand" "r")))]
467 ; these patterns give better code then gcc invents if
468 ; left to its own devices
470 (define_insn "anddi3"
471 [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=r")
472 (and:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
473 (match_operand:DI 2 "mcore_arith_reg_operand" "r")))]
475 "and %0,%2\;and %R0,%R2"
476 [(set_attr "length" "4")])
478 (define_insn "iordi3"
479 [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=r")
480 (ior:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
481 (match_operand:DI 2 "mcore_arith_reg_operand" "r")))]
483 "or %0,%2\;or %R0,%R2"
484 [(set_attr "length" "4")])
486 (define_insn "xordi3"
487 [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=r")
488 (xor:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
489 (match_operand:DI 2 "mcore_arith_reg_operand" "r")))]
491 "xor %0,%2\;xor %R0,%R2"
492 [(set_attr "length" "4")])
494 ;; -------------------------------------------------------------------------
495 ;; Shifts and rotates
496 ;; -------------------------------------------------------------------------
498 ;; Only allow these if the shift count is a convenient constant.
499 (define_expand "rotlsi3"
500 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
501 (rotate:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
502 (match_operand:SI 2 "nonmemory_operand" "")))]
504 "if (! mcore_literal_K_operand (operands[2], SImode))
508 ;; We can only do constant rotates, which is what this pattern provides.
509 ;; The combiner will put it together for us when we do:
510 ;; (x << N) | (x >> (32 - N))
512 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
513 (rotate:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
514 (match_operand:SI 2 "mcore_literal_K_operand" "K")))]
517 [(set_attr "type" "shift")])
519 (define_insn "ashlsi3"
520 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r")
521 (ashift:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0")
522 (match_operand:SI 2 "mcore_arith_K_operand_not_0" "r,K")))]
527 [(set_attr "type" "shift")])
530 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
531 (ashift:SI (const_int 1)
532 (match_operand:SI 1 "mcore_arith_reg_operand" "r")))]
535 [(set_attr "type" "shift")])
537 (define_insn "ashrsi3"
538 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r")
539 (ashiftrt:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0")
540 (match_operand:SI 2 "mcore_arith_K_operand_not_0" "r,K")))]
545 [(set_attr "type" "shift")])
547 (define_insn "lshrsi3"
548 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r")
549 (lshiftrt:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0")
550 (match_operand:SI 2 "mcore_arith_K_operand_not_0" "r,K")))]
555 [(set_attr "type" "shift")])
557 ;(define_expand "ashldi3"
558 ; [(parallel[(set (match_operand:DI 0 "mcore_arith_reg_operand" "")
559 ; (ashift:DI (match_operand:DI 1 "mcore_arith_reg_operand" "")
560 ; (match_operand:DI 2 "immediate_operand" "")))
562 ; (clobber (reg:CC 17))])]
567 ; if (GET_CODE (operands[2]) != CONST_INT
568 ; || INTVAL (operands[2]) != 1)
573 ; [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=r")
574 ; (ashift:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")
576 ; (clobber (reg:CC 17))]
578 ; "lsli %R0,0\;rotli %0,0"
579 ; [(set_attr "length" "4") (set_attr "type" "shift")])
581 ;; -------------------------------------------------------------------------
582 ;; Index instructions
583 ;; -------------------------------------------------------------------------
584 ;; The second of each set of patterns is borrowed from the alpha.md file.
585 ;; These variants of the above insns can occur if the second operand
586 ;; is the frame pointer. This is a kludge, but there doesn't
587 ;; seem to be a way around it. Only recognize them while reloading.
589 ;; We must use reload_operand for some operands in case frame pointer
590 ;; elimination put a MEM with invalid address there. Otherwise,
591 ;; the result of the substitution will not match this pattern, and reload
592 ;; will not be able to correctly fix the result.
594 ;; indexing longlongs or doubles (8 bytes)
596 (define_insn "indexdi_t"
597 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
598 (plus:SI (mult:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
600 (match_operand:SI 2 "mcore_arith_reg_operand" "0")))]
603 if (! mcore_is_same_reg (operands[1], operands[2]))
605 output_asm_insn (\"ixw\\t%0,%1\", operands);
606 output_asm_insn (\"ixw\\t%0,%1\", operands);
610 output_asm_insn (\"ixh\\t%0,%1\", operands);
611 output_asm_insn (\"ixh\\t%0,%1\", operands);
615 ;; if operands[1] == operands[2], the first option above is wrong! -- dac
616 ;; was this... -- dac
617 ;; ixw %0,%1\;ixw %0,%1"
619 [(set_attr "length" "4")])
622 [(set (match_operand:SI 0 "mcore_reload_operand" "=r,r,r")
623 (plus:SI (plus:SI (mult:SI (match_operand:SI 1 "mcore_reload_operand" "r,r,r")
625 (match_operand:SI 2 "mcore_arith_reg_operand" "0,0,0"))
626 (match_operand:SI 3 "mcore_addsub_operand" "r,J,L")))]
629 ixw %0,%1\;ixw %0,%1\;addu %0,%3
630 ixw %0,%1\;ixw %0,%1\;addi %0,%3
631 ixw %0,%1\;ixw %0,%1\;subi %0,%M3"
632 [(set_attr "length" "6")])
634 ;; indexing longs (4 bytes)
636 (define_insn "indexsi_t"
637 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
638 (plus:SI (mult:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
640 (match_operand:SI 2 "mcore_arith_reg_operand" "0")))]
645 [(set (match_operand:SI 0 "mcore_reload_operand" "=r,r,r")
646 (plus:SI (plus:SI (mult:SI (match_operand:SI 1 "mcore_reload_operand" "r,r,r")
648 (match_operand:SI 2 "mcore_arith_reg_operand" "0,0,0"))
649 (match_operand:SI 3 "mcore_addsub_operand" "r,J,L")))]
652 ixw %0,%1\;addu %0,%3
653 ixw %0,%1\;addi %0,%3
654 ixw %0,%1\;subi %0,%M3"
655 [(set_attr "length" "4")])
657 ;; indexing shorts (2 bytes)
659 (define_insn "indexhi_t"
660 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
661 (plus:SI (mult:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
663 (match_operand:SI 2 "mcore_arith_reg_operand" "0")))]
668 [(set (match_operand:SI 0 "mcore_reload_operand" "=r,r,r")
669 (plus:SI (plus:SI (mult:SI (match_operand:SI 1 "mcore_reload_operand" "r,r,r")
671 (match_operand:SI 2 "mcore_arith_reg_operand" "0,0,0"))
672 (match_operand:SI 3 "mcore_addsub_operand" "r,J,L")))]
675 ixh %0,%1\;addu %0,%3
676 ixh %0,%1\;addi %0,%3
677 ixh %0,%1\;subi %0,%M3"
678 [(set_attr "length" "4")])
681 ;; Other sizes may be handy for indexing.
682 ;; the tradeoffs to consider when adding these are
683 ;; code size, execution time [vs. mul it is easy to win],
684 ;; and register pressure -- these patterns don't use an extra
685 ;; register to build the offset from the base
686 ;; and whether the compiler will not come up with some other idiom.
689 ;; -------------------------------------------------------------------------
690 ;; Addition, Subtraction instructions
691 ;; -------------------------------------------------------------------------
693 (define_expand "addsi3"
694 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
695 (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
696 (match_operand:SI 2 "nonmemory_operand" "")))]
700 extern int flag_omit_frame_pointer;
702 /* If this is an add to the frame pointer, then accept it as is so
703 that we can later fold in the fp/sp offset from frame pointer
705 if (flag_omit_frame_pointer
706 && GET_CODE (operands[1]) == REG
707 && (REGNO (operands[1]) == VIRTUAL_STACK_VARS_REGNUM
708 || REGNO (operands[1]) == FRAME_POINTER_REGNUM))
710 emit_insn (gen_addsi3_fp (operands[0], operands[1], operands[2]));
714 /* Convert adds to subtracts if this makes loading the constant cheaper.
715 But only if we are allowed to generate new pseudos. */
716 if (! (reload_in_progress || reload_completed)
717 && GET_CODE (operands[2]) == CONST_INT
718 && INTVAL (operands[2]) < -32)
720 HOST_WIDE_INT neg_value = - INTVAL (operands[2]);
722 if ( CONST_OK_FOR_I (neg_value)
723 || CONST_OK_FOR_M (neg_value)
724 || CONST_OK_FOR_N (neg_value))
726 operands[2] = copy_to_mode_reg (SImode, GEN_INT (neg_value));
727 emit_insn (gen_subsi3 (operands[0], operands[1], operands[2]));
732 if (! mcore_addsub_operand (operands[2], SImode))
733 operands[2] = copy_to_mode_reg (SImode, operands[2]);
736 ;; RBE: for some constants which are not in the range which allows
737 ;; us to do a single operation, we will try a paired addi/addi instead
738 ;; of a movi/addi. This relieves some register pressure at the expense
739 ;; of giving away some potential constant reuse.
741 ;; RBE 6/17/97: this didn't buy us anything, but I keep the pattern
742 ;; for later reference
744 ;; (define_insn "addsi3_i2"
745 ;; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
746 ;; (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
747 ;; (match_operand:SI 2 "const_int_operand" "g")))]
748 ;; "GET_CODE(operands[2]) == CONST_INT
749 ;; && ((INTVAL (operands[2]) > 32 && INTVAL(operands[2]) <= 64)
750 ;; || (INTVAL (operands[2]) < -32 && INTVAL(operands[2]) >= -64))"
753 ;; HOST_WIDE_INT n = INTVAL(operands[2]);
756 ;; operands[2] = GEN_INT(n - 32);
757 ;; return \"addi\\t%0,32\;addi\\t%0,%2\";
762 ;; operands[2] = GEN_INT(n - 32);
763 ;; return \"subi\\t%0,32\;subi\\t%0,%2\";
766 ;; [(set_attr "length" "4")])
768 (define_insn "addsi3_i"
769 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r")
770 (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0,0,0")
771 (match_operand:SI 2 "mcore_addsub_operand" "r,J,L")))]
778 ;; This exists so that address computations based on the frame pointer
779 ;; can be folded in when frame pointer elimination occurs. Ordinarily
780 ;; this would be bad because it allows insns which would require reloading,
781 ;; but without it, we get multiple adds where one would do.
783 (define_insn "addsi3_fp"
784 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r")
785 (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0,0,0")
786 (match_operand:SI 2 "immediate_operand" "r,J,L")))]
787 "flag_omit_frame_pointer
788 && (reload_in_progress || reload_completed || REGNO (operands[1]) == FRAME_POINTER_REGNUM)"
794 ;; RBE: for some constants which are not in the range which allows
795 ;; us to do a single operation, we will try a paired addi/addi instead
796 ;; of a movi/addi. This relieves some register pressure at the expense
797 ;; of giving away some potential constant reuse.
799 ;; RBE 6/17/97: this didn't buy us anything, but I keep the pattern
800 ;; for later reference
802 ;; (define_insn "subsi3_i2"
803 ;; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
804 ;; (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
805 ;; (match_operand:SI 2 "const_int_operand" "g")))]
806 ;; "TARGET_RBETEST && GET_CODE(operands[2]) == CONST_INT
807 ;; && ((INTVAL (operands[2]) > 32 && INTVAL(operands[2]) <= 64)
808 ;; || (INTVAL (operands[2]) < -32 && INTVAL(operands[2]) >= -64))"
811 ;; HOST_WIDE_INT n = INTVAL(operands[2]);
814 ;; operands[2] = GEN_INT( n - 32);
815 ;; return \"subi\\t%0,32\;subi\\t%0,%2\";
820 ;; operands[2] = GEN_INT(n - 32);
821 ;; return \"addi\\t%0,32\;addi\\t%0,%2\";
824 ;; [(set_attr "length" "4")])
826 ;(define_insn "subsi3"
827 ; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
828 ; (minus:SI (match_operand:SI 1 "mcore_arith_K_operand" "0,0,r,K")
829 ; (match_operand:SI 2 "mcore_arith_J_operand" "r,J,0,0")))]
837 (define_insn "subsi3"
838 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r")
839 (minus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0,r")
840 (match_operand:SI 2 "mcore_arith_J_operand" "r,J,0")))]
848 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
849 (minus:SI (match_operand:SI 1 "mcore_literal_K_operand" "K")
850 (match_operand:SI 2 "mcore_arith_reg_operand" "0")))]
854 (define_insn "adddi3"
855 [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
856 (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
857 (match_operand:DI 2 "mcore_arith_reg_operand" "r")))
858 (clobber (reg:CC 17))]
862 if (TARGET_LITTLE_END)
863 return \"cmplt %0,%0\;addc %0,%2\;addc %R0,%R2\";
864 return \"cmplt %R0,%R0\;addc %R0,%R2\;addc %0,%2\";
866 [(set_attr "length" "6")])
868 ;; special case for "longlong += 1"
870 [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
871 (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")
873 (clobber (reg:CC 17))]
877 if (TARGET_LITTLE_END)
878 return \"addi %0,1\;cmpnei %0,0\;incf %R0\";
879 return \"addi %R0,1\;cmpnei %R0,0\;incf %0\";
881 [(set_attr "length" "6")])
883 ;; special case for "longlong -= 1"
885 [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
886 (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")
888 (clobber (reg:CC 17))]
892 if (TARGET_LITTLE_END)
893 return \"cmpnei %0,0\;decf %R0\;subi %0,1\";
894 return \"cmpnei %R0,0\;decf %0\;subi %R0,1\";
896 [(set_attr "length" "6")])
898 ;; special case for "longlong += const_int"
899 ;; we have to use a register for the const_int because we don't
900 ;; have an unsigned compare immediate... only +/- 1 get to
901 ;; play the no-extra register game because they compare with 0.
902 ;; This winds up working out for any literal that is synthesized
903 ;; with a single instruction. The more complicated ones look
904 ;; like the get broken into subreg's to get initialized too soon
905 ;; for us to catch here. -- RBE 4/25/96
906 ;; only allow for-sure positive values.
909 [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
910 (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")
911 (match_operand:SI 2 "const_int_operand" "r")))
912 (clobber (reg:CC 17))]
913 "GET_CODE (operands[2]) == CONST_INT
914 && INTVAL (operands[2]) > 0 && ! (INTVAL (operands[2]) & 0x80000000)"
917 gcc_assert (GET_MODE (operands[2]) == SImode);
918 if (TARGET_LITTLE_END)
919 return \"addu %0,%2\;cmphs %0,%2\;incf %R0\";
920 return \"addu %R0,%2\;cmphs %R0,%2\;incf %0\";
922 [(set_attr "length" "6")])
924 ;; optimize "long long" + "unsigned long"
925 ;; won't trigger because of how the extension is expanded upstream.
927 ;; [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
928 ;; (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
929 ;; (zero_extend:DI (match_operand:SI 2 "mcore_arith_reg_operand" "r"))))
930 ;; (clobber (reg:CC 17))]
932 ;; "cmplt %R0,%R0\;addc %R0,%2\;inct %0"
933 ;; [(set_attr "length" "6")])
935 ;; optimize "long long" + "signed long"
936 ;; won't trigger because of how the extension is expanded upstream.
938 ;; [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
939 ;; (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
940 ;; (sign_extend:DI (match_operand:SI 2 "mcore_arith_reg_operand" "r"))))
941 ;; (clobber (reg:CC 17))]
943 ;; "cmplt %R0,%R0\;addc %R0,%2\;inct %0\;btsti %2,31\;dect %0"
944 ;; [(set_attr "length" "6")])
946 (define_insn "subdi3"
947 [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
948 (minus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")
949 (match_operand:DI 2 "mcore_arith_reg_operand" "r")))
950 (clobber (reg:CC 17))]
954 if (TARGET_LITTLE_END)
955 return \"cmphs %0,%0\;subc %0,%2\;subc %R0,%R2\";
956 return \"cmphs %R0,%R0\;subc %R0,%R2\;subc %0,%2\";
958 [(set_attr "length" "6")])
960 ;; -------------------------------------------------------------------------
961 ;; Multiplication instructions
962 ;; -------------------------------------------------------------------------
964 (define_insn "mulsi3"
965 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
966 (mult:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
967 (match_operand:SI 2 "mcore_arith_reg_operand" "r")))]
972 ;; 32/32 signed division -- added to the MCORE instruction set spring 1997
974 ;; Different constraints based on the architecture revision...
976 (define_expand "divsi3"
977 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
978 (div:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
979 (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
983 ;; MCORE Revision 1.50: restricts the divisor to be in r1. (6/97)
986 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
987 (div:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
988 (match_operand:SI 2 "mcore_arith_reg_operand" "b")))]
993 ;; 32/32 signed division -- added to the MCORE instruction set spring 1997
995 ;; Different constraints based on the architecture revision...
997 (define_expand "udivsi3"
998 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
999 (udiv:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
1000 (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
1004 ;; MCORE Revision 1.50: restricts the divisor to be in r1. (6/97)
1006 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1007 (udiv:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
1008 (match_operand:SI 2 "mcore_arith_reg_operand" "b")))]
1012 ;; -------------------------------------------------------------------------
1014 ;; -------------------------------------------------------------------------
1016 (define_insn "negsi2"
1017 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1018 (neg:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")))]
1022 return \"rsubi %0,0\";
1026 (define_insn "abssi2"
1027 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1028 (abs:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")))]
1032 (define_insn "negdi2"
1033 [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
1034 (neg:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")))
1035 (clobber (reg:CC 17))]
1039 if (TARGET_LITTLE_END)
1040 return \"cmpnei %0,0\\n\\trsubi %0,0\\n\\tnot %R0\\n\\tincf %R0\";
1041 return \"cmpnei %R0,0\\n\\trsubi %R0,0\\n\\tnot %0\\n\\tincf %0\";
1043 [(set_attr "length" "8")])
1045 (define_insn "one_cmplsi2"
1046 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1047 (not:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")))]
1051 ;; -------------------------------------------------------------------------
1052 ;; Zero extension instructions
1053 ;; -------------------------------------------------------------------------
1055 (define_expand "zero_extendhisi2"
1056 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1057 (zero_extend:SI (match_operand:HI 1 "mcore_arith_reg_operand" "")))]
1062 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r")
1063 (zero_extend:SI (match_operand:HI 1 "general_operand" "0,m")))]
1068 [(set_attr "type" "shift,load")])
1070 ;; ldh gives us a free zero-extension. The combiner picks up on this.
1072 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1073 (zero_extend:SI (mem:HI (match_operand:SI 1 "mcore_arith_reg_operand" "r"))))]
1076 [(set_attr "type" "load")])
1079 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1080 (zero_extend:SI (mem:HI (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
1081 (match_operand:SI 2 "const_int_operand" "")))))]
1082 "(INTVAL (operands[2]) >= 0) &&
1083 (INTVAL (operands[2]) < 32) &&
1084 ((INTVAL (operands[2])&1) == 0)"
1086 [(set_attr "type" "load")])
1088 (define_expand "zero_extendqisi2"
1089 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1090 (zero_extend:SI (match_operand:QI 1 "general_operand" "")))]
1094 ;; RBE: XXX: we don't recognize that the xtrb3 kills the CC register.
1096 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,b,r")
1097 (zero_extend:SI (match_operand:QI 1 "general_operand" "0,r,m")))]
1103 [(set_attr "type" "shift,shift,load")])
1105 ;; ldb gives us a free zero-extension. The combiner picks up on this.
1107 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1108 (zero_extend:SI (mem:QI (match_operand:SI 1 "mcore_arith_reg_operand" "r"))))]
1111 [(set_attr "type" "load")])
1114 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1115 (zero_extend:SI (mem:QI (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
1116 (match_operand:SI 2 "const_int_operand" "")))))]
1117 "(INTVAL (operands[2]) >= 0) &&
1118 (INTVAL (operands[2]) < 16)"
1120 [(set_attr "type" "load")])
1122 (define_expand "zero_extendqihi2"
1123 [(set (match_operand:HI 0 "mcore_arith_reg_operand" "")
1124 (zero_extend:HI (match_operand:QI 1 "general_operand" "")))]
1128 ;; RBE: XXX: we don't recognize that the xtrb3 kills the CC register.
1130 [(set (match_operand:HI 0 "mcore_arith_reg_operand" "=r,b,r")
1131 (zero_extend:HI (match_operand:QI 1 "general_operand" "0,r,m")))]
1137 [(set_attr "type" "shift,shift,load")])
1139 ;; ldb gives us a free zero-extension. The combiner picks up on this.
1140 ;; this doesn't catch references that are into a structure.
1141 ;; note that normally the compiler uses the above insn, unless it turns
1142 ;; out that we're dealing with a volatile...
1144 [(set (match_operand:HI 0 "mcore_arith_reg_operand" "=r")
1145 (zero_extend:HI (mem:QI (match_operand:SI 1 "mcore_arith_reg_operand" "r"))))]
1148 [(set_attr "type" "load")])
1151 [(set (match_operand:HI 0 "mcore_arith_reg_operand" "=r")
1152 (zero_extend:HI (mem:QI (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
1153 (match_operand:SI 2 "const_int_operand" "")))))]
1154 "(INTVAL (operands[2]) >= 0) &&
1155 (INTVAL (operands[2]) < 16)"
1157 [(set_attr "type" "load")])
1160 ;; -------------------------------------------------------------------------
1161 ;; Sign extension instructions
1162 ;; -------------------------------------------------------------------------
1164 (define_expand "extendsidi2"
1165 [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=r")
1166 (match_operand:SI 1 "mcore_arith_reg_operand" "r"))]
1172 if (TARGET_LITTLE_END)
1177 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], low),
1179 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], high),
1180 gen_rtx_ASHIFTRT (SImode,
1181 gen_rtx_SUBREG (SImode, operands[0], low),
1187 (define_insn "extendhisi2"
1188 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1189 (sign_extend:SI (match_operand:HI 1 "mcore_arith_reg_operand" "0")))]
1193 (define_insn "extendqisi2"
1194 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1195 (sign_extend:SI (match_operand:QI 1 "mcore_arith_reg_operand" "0")))]
1199 (define_insn "extendqihi2"
1200 [(set (match_operand:HI 0 "mcore_arith_reg_operand" "=r")
1201 (sign_extend:HI (match_operand:QI 1 "mcore_arith_reg_operand" "0")))]
1205 ;; -------------------------------------------------------------------------
1206 ;; Move instructions
1207 ;; -------------------------------------------------------------------------
1211 (define_expand "movsi"
1212 [(set (match_operand:SI 0 "general_operand" "")
1213 (match_operand:SI 1 "general_operand" ""))]
1217 if (GET_CODE (operands[0]) == MEM)
1218 operands[1] = force_reg (SImode, operands[1]);
1222 [(set (match_operand:SI 0 "mcore_general_movdst_operand" "=r,r,a,r,a,r,m")
1223 (match_operand:SI 1 "mcore_general_movsrc_operand" "r,P,i,c,R,m,r"))]
1224 "(register_operand (operands[0], SImode)
1225 || register_operand (operands[1], SImode))"
1226 "* return mcore_output_move (insn, operands, SImode);"
1227 [(set_attr "type" "move,move,move,move,load,load,store")])
1233 (define_expand "movhi"
1234 [(set (match_operand:HI 0 "general_operand" "")
1235 (match_operand:HI 1 "general_operand" ""))]
1239 if (GET_CODE (operands[0]) == MEM)
1240 operands[1] = force_reg (HImode, operands[1]);
1241 else if (CONSTANT_P (operands[1])
1242 && (GET_CODE (operands[1]) != CONST_INT
1243 || (! CONST_OK_FOR_I (INTVAL (operands[1]))
1244 && ! CONST_OK_FOR_M (INTVAL (operands[1]))
1245 && ! CONST_OK_FOR_N (INTVAL (operands[1]))))
1246 && ! reload_completed && ! reload_in_progress)
1248 rtx reg = gen_reg_rtx (SImode);
1249 emit_insn (gen_movsi (reg, operands[1]));
1250 operands[1] = gen_lowpart (HImode, reg);
1255 [(set (match_operand:HI 0 "mcore_general_movdst_operand" "=r,r,a,r,r,m")
1256 (match_operand:HI 1 "mcore_general_movsrc_operand" "r,P,i,c,m,r"))]
1257 "(register_operand (operands[0], HImode)
1258 || register_operand (operands[1], HImode))"
1259 "* return mcore_output_move (insn, operands, HImode);"
1260 [(set_attr "type" "move,move,move,move,load,store")])
1266 (define_expand "movqi"
1267 [(set (match_operand:QI 0 "general_operand" "")
1268 (match_operand:QI 1 "general_operand" ""))]
1272 if (GET_CODE (operands[0]) == MEM)
1273 operands[1] = force_reg (QImode, operands[1]);
1274 else if (CONSTANT_P (operands[1])
1275 && (GET_CODE (operands[1]) != CONST_INT
1276 || (! CONST_OK_FOR_I (INTVAL (operands[1]))
1277 && ! CONST_OK_FOR_M (INTVAL (operands[1]))
1278 && ! CONST_OK_FOR_N (INTVAL (operands[1]))))
1279 && ! reload_completed && ! reload_in_progress)
1281 rtx reg = gen_reg_rtx (SImode);
1282 emit_insn (gen_movsi (reg, operands[1]));
1283 operands[1] = gen_lowpart (QImode, reg);
1288 [(set (match_operand:QI 0 "mcore_general_movdst_operand" "=r,r,a,r,r,m")
1289 (match_operand:QI 1 "mcore_general_movsrc_operand" "r,P,i,c,m,r"))]
1290 "(register_operand (operands[0], QImode)
1291 || register_operand (operands[1], QImode))"
1292 "* return mcore_output_move (insn, operands, QImode);"
1293 [(set_attr "type" "move,move,move,move,load,store")])
1298 (define_expand "movdi"
1299 [(set (match_operand:DI 0 "general_operand" "")
1300 (match_operand:DI 1 "general_operand" ""))]
1304 if (GET_CODE (operands[0]) == MEM)
1305 operands[1] = force_reg (DImode, operands[1]);
1306 else if (GET_CODE (operands[1]) == CONST_INT
1307 && ! CONST_OK_FOR_I (INTVAL (operands[1]))
1308 && ! CONST_OK_FOR_M (INTVAL (operands[1]))
1309 && ! CONST_OK_FOR_N (INTVAL (operands[1])))
1312 for (i = 0; i < UNITS_PER_WORD * 2; i += UNITS_PER_WORD)
1313 emit_move_insn (simplify_gen_subreg (SImode, operands[0], DImode, i),
1314 simplify_gen_subreg (SImode, operands[1], DImode, i));
1319 (define_insn "movdi_i"
1320 [(set (match_operand:DI 0 "general_operand" "=r,r,r,r,a,r,m")
1321 (match_operand:DI 1 "mcore_general_movsrc_operand" "I,M,N,r,R,m,r"))]
1323 "* return mcore_output_movedouble (operands, DImode);"
1324 [(set_attr "length" "4") (set_attr "type" "move,move,move,move,load,load,store")])
1328 (define_expand "movsf"
1329 [(set (match_operand:SF 0 "general_operand" "")
1330 (match_operand:SF 1 "general_operand" ""))]
1334 if (GET_CODE (operands[0]) == MEM)
1335 operands[1] = force_reg (SFmode, operands[1]);
1338 (define_insn "movsf_i"
1339 [(set (match_operand:SF 0 "general_operand" "=r,r,m")
1340 (match_operand:SF 1 "general_operand" "r,m,r"))]
1346 [(set_attr "type" "move,load,store")])
1350 (define_expand "movdf"
1351 [(set (match_operand:DF 0 "general_operand" "")
1352 (match_operand:DF 1 "general_operand" ""))]
1356 if (GET_CODE (operands[0]) == MEM)
1357 operands[1] = force_reg (DFmode, operands[1]);
1360 (define_insn "movdf_k"
1361 [(set (match_operand:DF 0 "general_operand" "=r,r,m")
1362 (match_operand:DF 1 "general_operand" "r,m,r"))]
1364 "* return mcore_output_movedouble (operands, DFmode);"
1365 [(set_attr "length" "4") (set_attr "type" "move,load,store")])
1368 ;; Load/store multiple
1370 ;; ??? This is not currently used.
1372 [(set (match_operand:TI 0 "mcore_arith_reg_operand" "=r")
1373 (mem:TI (match_operand:SI 1 "mcore_arith_reg_operand" "r")))]
1377 ;; ??? This is not currently used.
1379 [(set (mem:TI (match_operand:SI 0 "mcore_arith_reg_operand" "r"))
1380 (match_operand:TI 1 "mcore_arith_reg_operand" "r"))]
1384 (define_expand "load_multiple"
1385 [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
1386 (match_operand:SI 1 "" ""))
1387 (use (match_operand:SI 2 "" ""))])]
1391 int regno, count, i;
1393 /* Support only loading a constant number of registers from memory and
1394 only if at least two registers. The last register must be r15. */
1395 if (GET_CODE (operands[2]) != CONST_INT
1396 || INTVAL (operands[2]) < 2
1397 || GET_CODE (operands[1]) != MEM
1398 || XEXP (operands[1], 0) != stack_pointer_rtx
1399 || GET_CODE (operands[0]) != REG
1400 || REGNO (operands[0]) + INTVAL (operands[2]) != 16)
1403 count = INTVAL (operands[2]);
1404 regno = REGNO (operands[0]);
1406 operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
1408 for (i = 0; i < count; i++)
1409 XVECEXP (operands[3], 0, i)
1410 = gen_rtx_SET (VOIDmode,
1411 gen_rtx_REG (SImode, regno + i),
1412 gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx,
1417 [(match_parallel 0 "mcore_load_multiple_operation"
1418 [(set (match_operand:SI 1 "mcore_arith_reg_operand" "=r")
1419 (mem:SI (match_operand:SI 2 "register_operand" "r")))])]
1420 "GET_CODE (operands[2]) == REG && REGNO (operands[2]) == STACK_POINTER_REGNUM"
1423 (define_expand "store_multiple"
1424 [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
1425 (match_operand:SI 1 "" ""))
1426 (use (match_operand:SI 2 "" ""))])]
1430 int regno, count, i;
1432 /* Support only storing a constant number of registers to memory and
1433 only if at least two registers. The last register must be r15. */
1434 if (GET_CODE (operands[2]) != CONST_INT
1435 || INTVAL (operands[2]) < 2
1436 || GET_CODE (operands[0]) != MEM
1437 || XEXP (operands[0], 0) != stack_pointer_rtx
1438 || GET_CODE (operands[1]) != REG
1439 || REGNO (operands[1]) + INTVAL (operands[2]) != 16)
1442 count = INTVAL (operands[2]);
1443 regno = REGNO (operands[1]);
1445 operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
1447 for (i = 0; i < count; i++)
1448 XVECEXP (operands[3], 0, i)
1449 = gen_rtx_SET (VOIDmode,
1450 gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx,
1452 gen_rtx_REG (SImode, regno + i));
1456 [(match_parallel 0 "mcore_store_multiple_operation"
1457 [(set (mem:SI (match_operand:SI 2 "register_operand" "r"))
1458 (match_operand:SI 1 "mcore_arith_reg_operand" "r"))])]
1459 "GET_CODE (operands[2]) == REG && REGNO (operands[2]) == STACK_POINTER_REGNUM"
1462 ;; ------------------------------------------------------------------------
1463 ;; Define the real conditional branch instructions.
1464 ;; ------------------------------------------------------------------------
1466 ;; At top-level, condition test are eq/ne, because we
1467 ;; are comparing against the condition register (which
1468 ;; has the result of the true relational test
1470 (define_insn "branch_true"
1471 [(set (pc) (if_then_else (ne (reg:CC 17) (const_int 0))
1472 (label_ref (match_operand 0 "" ""))
1476 [(set_attr "type" "brcond")])
1478 (define_insn "branch_false"
1479 [(set (pc) (if_then_else (eq (reg:CC 17) (const_int 0))
1480 (label_ref (match_operand 0 "" ""))
1484 [(set_attr "type" "brcond")])
1486 (define_insn "inverse_branch_true"
1487 [(set (pc) (if_then_else (ne (reg:CC 17) (const_int 0))
1489 (label_ref (match_operand 0 "" ""))))]
1492 [(set_attr "type" "brcond")])
1494 (define_insn "inverse_branch_false"
1495 [(set (pc) (if_then_else (eq (reg:CC 17) (const_int 0))
1497 (label_ref (match_operand 0 "" ""))))]
1500 [(set_attr "type" "brcond")])
1502 ;; Conditional branch insns
1504 (define_expand "cbranchsi4"
1506 (if_then_else (match_operator:SI 0 "ordered_comparison_operator"
1507 [(match_operand:SI 1 "mcore_compare_operand")
1508 (match_operand:SI 2 "nonmemory_operand")])
1509 (label_ref (match_operand 3 ""))
1515 invert = mcore_gen_compare (GET_CODE (operands[0]),
1516 operands[1], operands[2]);
1519 emit_jump_insn (gen_branch_false (operands[3]));
1521 emit_jump_insn (gen_branch_true (operands[3]));
1527 ;; ------------------------------------------------------------------------
1528 ;; Jump and linkage insns
1529 ;; ------------------------------------------------------------------------
1531 (define_insn "jump_real"
1533 (label_ref (match_operand 0 "" "")))]
1536 [(set_attr "type" "branch")])
1538 (define_expand "jump"
1539 [(set (pc) (label_ref (match_operand 0 "" "")))]
1543 emit_jump_insn (gen_jump_real (operand0));
1548 (define_insn "indirect_jump"
1550 (match_operand:SI 0 "mcore_arith_reg_operand" "r"))]
1553 [(set_attr "type" "jmp")])
1555 (define_expand "call"
1556 [(parallel[(call (match_operand:SI 0 "" "")
1557 (match_operand 1 "" ""))
1558 (clobber (reg:SI 15))])]
1562 if (GET_CODE (operands[0]) == MEM
1563 && ! register_operand (XEXP (operands[0], 0), SImode)
1564 && ! mcore_symbolic_address_p (XEXP (operands[0], 0)))
1565 operands[0] = gen_rtx_MEM (GET_MODE (operands[0]),
1566 force_reg (Pmode, XEXP (operands[0], 0)));
1569 (define_insn "call_internal"
1570 [(call (mem:SI (match_operand:SI 0 "mcore_call_address_operand" "riR"))
1571 (match_operand 1 "" ""))
1572 (clobber (reg:SI 15))]
1574 "* return mcore_output_call (operands, 0);")
1576 (define_expand "call_value"
1577 [(parallel[(set (match_operand 0 "register_operand" "")
1578 (call (match_operand:SI 1 "" "")
1579 (match_operand 2 "" "")))
1580 (clobber (reg:SI 15))])]
1584 if (GET_CODE (operands[0]) == MEM
1585 && ! register_operand (XEXP (operands[0], 0), SImode)
1586 && ! mcore_symbolic_address_p (XEXP (operands[0], 0)))
1587 operands[1] = gen_rtx_MEM (GET_MODE (operands[1]),
1588 force_reg (Pmode, XEXP (operands[1], 0)));
1591 (define_insn "call_value_internal"
1592 [(set (match_operand 0 "register_operand" "=r")
1593 (call (mem:SI (match_operand:SI 1 "mcore_call_address_operand" "riR"))
1594 (match_operand 2 "" "")))
1595 (clobber (reg:SI 15))]
1597 "* return mcore_output_call (operands, 1);")
1599 (define_insn "call_value_struct"
1600 [(parallel [(set (match_parallel 0 ""
1601 [(expr_list (match_operand 3 "register_operand" "") (match_operand 4 "immediate_operand" ""))
1602 (expr_list (match_operand 5 "register_operand" "") (match_operand 6 "immediate_operand" ""))])
1603 (call (match_operand:SI 1 "" "")
1604 (match_operand 2 "" "")))
1605 (clobber (reg:SI 15))])]
1607 "* return mcore_output_call (operands, 1);"
1611 ;; ------------------------------------------------------------------------
1613 ;; ------------------------------------------------------------------------
1620 (define_insn "tablejump"
1622 (match_operand:SI 0 "mcore_arith_reg_operand" "r"))
1623 (use (label_ref (match_operand 1 "" "")))]
1626 [(set_attr "type" "jmp")])
1628 (define_insn "*return"
1630 "reload_completed && ! mcore_naked_function_p ()"
1632 [(set_attr "type" "jmp")])
1634 (define_insn "*no_return"
1636 "reload_completed && mcore_naked_function_p ()"
1638 [(set_attr "length" "0")]
1641 (define_expand "prologue"
1644 "mcore_expand_prolog (); DONE;")
1646 (define_expand "epilogue"
1649 "mcore_expand_epilog ();")
1651 ;; ------------------------------------------------------------------------
1653 ;; ------------------------------------------------------------------------
1656 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1657 (ne:SI (reg:CC 17) (const_int 0)))]
1660 [(set_attr "type" "move")])
1663 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1664 (eq:SI (reg:CC 17) (const_int 0)))]
1667 [(set_attr "type" "move")])
1669 ; in 0.97 use (LE 0) with (LT 1) and complement c. BRC
1672 (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1673 (ne:SI (gt:CC (match_operand:SI 1 "mcore_arith_reg_operand" "")
1676 (clobber (reg:SI 17))])]
1679 (lt:CC (match_dup 1) (const_int 1)))
1680 (set (match_dup 0) (eq:SI (reg:CC 17) (const_int 0)))])
1683 (define_expand "cstoresi4"
1684 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1685 (match_operator:SI 1 "ordered_comparison_operator"
1686 [(match_operand:SI 2 "mcore_compare_operand" "")
1687 (match_operand:SI 3 "nonmemory_operand" "")]))]
1692 invert = mcore_gen_compare (GET_CODE (operands[1]),
1693 operands[2], operands[3]);
1696 emit_insn (gen_mvcv (operands[0]));
1698 emit_insn (gen_mvc (operands[0]));
1702 (define_insn "incscc"
1703 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1704 (plus:SI (ne (reg:CC 17) (const_int 0))
1705 (match_operand:SI 1 "mcore_arith_reg_operand" "0")))]
1709 (define_insn "incscc_false"
1710 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1711 (plus:SI (eq (reg:CC 17) (const_int 0))
1712 (match_operand:SI 1 "mcore_arith_reg_operand" "0")))]
1716 (define_insn "decscc"
1717 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1718 (minus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
1719 (ne (reg:CC 17) (const_int 0))))]
1723 (define_insn "decscc_false"
1724 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1725 (minus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
1726 (eq (reg:CC 17) (const_int 0))))]
1730 ;; ------------------------------------------------------------------------
1731 ;; Conditional move patterns.
1732 ;; ------------------------------------------------------------------------
1734 (define_expand "smaxsi3"
1736 (lt:CC (match_operand:SI 1 "mcore_arith_reg_operand" "")
1737 (match_operand:SI 2 "mcore_arith_reg_operand" "")))
1738 (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1739 (if_then_else:SI (eq (reg:CC 17) (const_int 0))
1740 (match_dup 1) (match_dup 2)))]
1745 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1746 (smax:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
1747 (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
1750 (lt:SI (match_dup 1) (match_dup 2)))
1752 (if_then_else:SI (eq (reg:CC 17) (const_int 0))
1753 (match_dup 1) (match_dup 2)))]
1756 ; no tstgt in 0.97, so just use cmplti (btsti x,31) and reverse move
1759 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1760 (smax:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
1764 (lt:CC (match_dup 1) (const_int 0)))
1766 (if_then_else:SI (eq (reg:CC 17) (const_int 0))
1767 (match_dup 1) (const_int 0)))]
1770 (define_expand "sminsi3"
1772 (lt:CC (match_operand:SI 1 "mcore_arith_reg_operand" "")
1773 (match_operand:SI 2 "mcore_arith_reg_operand" "")))
1774 (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1775 (if_then_else:SI (ne (reg:CC 17) (const_int 0))
1776 (match_dup 1) (match_dup 2)))]
1781 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1782 (smin:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
1783 (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
1786 (lt:SI (match_dup 1) (match_dup 2)))
1788 (if_then_else:SI (ne (reg:CC 17) (const_int 0))
1789 (match_dup 1) (match_dup 2)))]
1793 ; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1794 ; (smin:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
1798 ; (gt:CC (match_dup 1) (const_int 0)))
1799 ; (set (match_dup 0)
1800 ; (if_then_else:SI (eq (reg:CC 17) (const_int 0))
1801 ; (match_dup 1) (const_int 0)))]
1804 ; changed these unsigned patterns to use geu instead of ltu. it appears
1805 ; that the c-torture & ssrl test suites didn't catch these! only showed
1806 ; up in friedman's clib work. BRC 7/7/95
1808 (define_expand "umaxsi3"
1810 (geu:CC (match_operand:SI 1 "mcore_arith_reg_operand" "")
1811 (match_operand:SI 2 "mcore_arith_reg_operand" "")))
1812 (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1813 (if_then_else:SI (eq (reg:CC 17) (const_int 0))
1814 (match_dup 2) (match_dup 1)))]
1819 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1820 (umax:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
1821 (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
1824 (geu:SI (match_dup 1) (match_dup 2)))
1826 (if_then_else:SI (eq (reg:CC 17) (const_int 0))
1827 (match_dup 2) (match_dup 1)))]
1830 (define_expand "uminsi3"
1832 (geu:CC (match_operand:SI 1 "mcore_arith_reg_operand" "")
1833 (match_operand:SI 2 "mcore_arith_reg_operand" "")))
1834 (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1835 (if_then_else:SI (ne (reg:CC 17) (const_int 0))
1836 (match_dup 2) (match_dup 1)))]
1841 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1842 (umin:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
1843 (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
1846 (geu:SI (match_dup 1) (match_dup 2)))
1848 (if_then_else:SI (ne (reg:CC 17) (const_int 0))
1849 (match_dup 2) (match_dup 1)))]
1852 ;; ------------------------------------------------------------------------
1853 ;; conditional move patterns really start here
1854 ;; ------------------------------------------------------------------------
1856 ;; the "movtK" patterns are experimental. they are intended to account for
1857 ;; gcc's mucking on code such as:
1859 ;; free_ent = ((block_compress) ? 257 : 256 );
1861 ;; these patterns help to get a tstne/bgeni/inct (or equivalent) sequence
1862 ;; when both arms have constants that are +/- 1 of each other.
1864 ;; note in the following patterns that the "movtK" ones should be the first
1865 ;; one defined in each sequence. this is because the general pattern also
1866 ;; matches, so use ordering to determine priority (it's easier this way than
1867 ;; adding conditions to the general patterns). BRC
1869 ;; the U and Q constraints are necessary to ensure that reload does the
1870 ;; 'right thing'. U constrains the operand to 0 and Q to 1 for use in the
1871 ;; clrt & clrf and clrt/inct & clrf/incf patterns. BRC 6/26
1873 ;; ??? there appears to be some problems with these movtK patterns for ops
1874 ;; other than eq & ne. need to fix. 6/30 BRC
1876 ;; ------------------------------------------------------------------------
1878 ;; ------------------------------------------------------------------------
1880 ; experimental conditional move with two constants +/- 1 BRC
1882 (define_insn "movtK_1"
1883 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1885 (ne (reg:CC 17) (const_int 0))
1886 (match_operand:SI 1 "mcore_arith_O_operand" "O")
1887 (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
1888 " GET_CODE (operands[1]) == CONST_INT
1889 && GET_CODE (operands[2]) == CONST_INT
1890 && ( (INTVAL (operands[1]) - INTVAL (operands[2]) == 1)
1891 || (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
1892 "* return mcore_output_cmov (operands, 1, NULL);"
1893 [(set_attr "length" "4")])
1895 (define_insn "movt0"
1896 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
1898 (ne (reg:CC 17) (const_int 0))
1899 (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
1900 (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
1908 ;; ------------------------------------------------------------------------
1910 ;; ------------------------------------------------------------------------
1912 ; experimental conditional move with two constants +/- 1 BRC
1913 (define_insn "movtK_2"
1914 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1916 (eq (reg:CC 17) (const_int 0))
1917 (match_operand:SI 1 "mcore_arith_O_operand" "O")
1918 (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
1919 " GET_CODE (operands[1]) == CONST_INT
1920 && GET_CODE (operands[2]) == CONST_INT
1921 && ( (INTVAL (operands[1]) - INTVAL (operands[2]) == 1)
1922 || (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
1923 "* return mcore_output_cmov (operands, 0, NULL);"
1924 [(set_attr "length" "4")])
1926 (define_insn "movf0"
1927 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
1929 (eq (reg:CC 17) (const_int 0))
1930 (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
1931 (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
1939 ; turns lsli rx,imm/btsti rx,31 into btsti rx,imm. not done by a peephole
1940 ; because the instructions are not adjacent (peepholes are related by posn -
1941 ; not by dataflow). BRC
1944 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
1945 (if_then_else:SI (eq (zero_extract:SI
1946 (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
1948 (match_operand:SI 2 "mcore_literal_K_operand" "K,K,K,K"))
1950 (match_operand:SI 3 "mcore_arith_imm_operand" "r,0,U,0")
1951 (match_operand:SI 4 "mcore_arith_imm_operand" "0,r,0,U")))]
1954 btsti %1,%2\;movf %0,%3
1955 btsti %1,%2\;movt %0,%4
1956 btsti %1,%2\;clrf %0
1957 btsti %1,%2\;clrt %0"
1958 [(set_attr "length" "4")])
1960 ; turns sextb rx/btsti rx,31 into btsti rx,7. must be QImode to be safe. BRC
1963 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
1964 (if_then_else:SI (eq (lshiftrt:SI
1965 (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
1968 (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
1969 (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
1970 "GET_CODE (operands[1]) == SUBREG &&
1971 GET_MODE (SUBREG_REG (operands[1])) == QImode"
1973 btsti %1,7\;movf %0,%2
1974 btsti %1,7\;movt %0,%3
1976 btsti %1,7\;clrt %0"
1977 [(set_attr "length" "4")])
1980 ;; ------------------------------------------------------------------------
1982 ;; ------------------------------------------------------------------------
1984 ;; Combine creates this from an andn instruction in a scc sequence.
1985 ;; We must recognize it to get conditional moves generated.
1987 ; experimental conditional move with two constants +/- 1 BRC
1988 (define_insn "movtK_3"
1989 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1991 (ne (match_operand:SI 1 "mcore_arith_reg_operand" "r")
1993 (match_operand:SI 2 "mcore_arith_O_operand" "O")
1994 (match_operand:SI 3 "mcore_arith_O_operand" "O")))]
1995 " GET_CODE (operands[2]) == CONST_INT
1996 && GET_CODE (operands[3]) == CONST_INT
1997 && ( (INTVAL (operands[2]) - INTVAL (operands[3]) == 1)
1998 || (INTVAL (operands[3]) - INTVAL (operands[2]) == 1))"
2001 rtx out_operands[4];
2002 out_operands[0] = operands[0];
2003 out_operands[1] = operands[2];
2004 out_operands[2] = operands[3];
2005 out_operands[3] = operands[1];
2007 return mcore_output_cmov (out_operands, 1, \"cmpnei %3,0\");
2010 [(set_attr "length" "6")])
2012 (define_insn "movt2"
2013 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2014 (if_then_else:SI (ne (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2016 (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2017 (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2020 cmpnei %1,0\;movt %0,%2
2021 cmpnei %1,0\;movf %0,%3
2022 cmpnei %1,0\;clrt %0
2023 cmpnei %1,0\;clrf %0"
2024 [(set_attr "length" "4")])
2026 ; turns lsli rx,imm/btsti rx,31 into btsti rx,imm. not done by a peephole
2027 ; because the instructions are not adjacent (peepholes are related by posn -
2028 ; not by dataflow). BRC
2031 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2032 (if_then_else:SI (ne (zero_extract:SI
2033 (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2035 (match_operand:SI 2 "mcore_literal_K_operand" "K,K,K,K"))
2037 (match_operand:SI 3 "mcore_arith_imm_operand" "r,0,U,0")
2038 (match_operand:SI 4 "mcore_arith_imm_operand" "0,r,0,U")))]
2041 btsti %1,%2\;movt %0,%3
2042 btsti %1,%2\;movf %0,%4
2043 btsti %1,%2\;clrt %0
2044 btsti %1,%2\;clrf %0"
2045 [(set_attr "length" "4")])
2047 ; turns sextb rx/btsti rx,31 into btsti rx,7. must be QImode to be safe. BRC
2050 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2051 (if_then_else:SI (ne (lshiftrt:SI
2052 (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2055 (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2056 (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2057 "GET_CODE (operands[1]) == SUBREG &&
2058 GET_MODE (SUBREG_REG (operands[1])) == QImode"
2060 btsti %1,7\;movt %0,%2
2061 btsti %1,7\;movf %0,%3
2063 btsti %1,7\;clrf %0"
2064 [(set_attr "length" "4")])
2066 ;; ------------------------------------------------------------------------
2068 ;; ------------------------------------------------------------------------
2070 ; experimental conditional move with two constants +/- 1 BRC
2071 (define_insn "movtK_4"
2072 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2074 (eq (eq:SI (reg:CC 17) (const_int 0)) (const_int 0))
2075 (match_operand:SI 1 "mcore_arith_O_operand" "O")
2076 (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
2077 "GET_CODE (operands[1]) == CONST_INT &&
2078 GET_CODE (operands[2]) == CONST_INT &&
2079 ((INTVAL (operands[1]) - INTVAL (operands[2]) == 1) ||
2080 (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
2081 "* return mcore_output_cmov(operands, 1, NULL);"
2082 [(set_attr "length" "4")])
2084 (define_insn "movt3"
2085 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2087 (eq (eq:SI (reg:CC 17) (const_int 0)) (const_int 0))
2088 (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
2089 (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
2097 ;; ------------------------------------------------------------------------
2099 ;; ------------------------------------------------------------------------
2101 ; experimental conditional move with two constants +/- 1 BRC
2102 (define_insn "movtK_5"
2103 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2105 (eq (ne:SI (reg:CC 17) (const_int 0)) (const_int 0))
2106 (match_operand:SI 1 "mcore_arith_O_operand" "O")
2107 (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
2108 "GET_CODE (operands[1]) == CONST_INT &&
2109 GET_CODE (operands[2]) == CONST_INT &&
2110 ((INTVAL (operands[1]) - INTVAL (operands[2]) == 1) ||
2111 (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
2112 "* return mcore_output_cmov (operands, 0, NULL);"
2113 [(set_attr "length" "4")])
2115 (define_insn "movf1"
2116 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2118 (eq (ne:SI (reg:CC 17) (const_int 0)) (const_int 0))
2119 (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
2120 (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
2128 ;; ------------------------------------------------------------------------
2130 ;; ------------------------------------------------------------------------
2132 ;; Combine creates this from an andn instruction in a scc sequence.
2133 ;; We must recognize it to get conditional moves generated.
2135 ; experimental conditional move with two constants +/- 1 BRC
2137 (define_insn "movtK_6"
2138 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2140 (eq (match_operand:SI 1 "mcore_arith_reg_operand" "r")
2142 (match_operand:SI 2 "mcore_arith_O_operand" "O")
2143 (match_operand:SI 3 "mcore_arith_O_operand" "O")))]
2144 "GET_CODE (operands[1]) == CONST_INT &&
2145 GET_CODE (operands[2]) == CONST_INT &&
2146 ((INTVAL (operands[2]) - INTVAL (operands[3]) == 1) ||
2147 (INTVAL (operands[3]) - INTVAL (operands[2]) == 1))"
2150 rtx out_operands[4];
2151 out_operands[0] = operands[0];
2152 out_operands[1] = operands[2];
2153 out_operands[2] = operands[3];
2154 out_operands[3] = operands[1];
2156 return mcore_output_cmov (out_operands, 0, \"cmpnei %3,0\");
2158 [(set_attr "length" "6")])
2160 (define_insn "movf3"
2161 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2162 (if_then_else:SI (eq (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2164 (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2165 (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2168 cmpnei %1,0\;movf %0,%2
2169 cmpnei %1,0\;movt %0,%3
2170 cmpnei %1,0\;clrf %0
2171 cmpnei %1,0\;clrt %0"
2172 [(set_attr "length" "4")])
2174 ;; ------------------------------------------------------------------------
2176 ;; ------------------------------------------------------------------------
2178 ; experimental conditional move with two constants +/- 1 BRC
2179 (define_insn "movtK_7"
2180 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2182 (ne (eq:SI (reg:CC 17) (const_int 0)) (const_int 0))
2183 (match_operand:SI 1 "mcore_arith_O_operand" "O")
2184 (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
2185 "GET_CODE (operands[1]) == CONST_INT &&
2186 GET_CODE (operands[2]) == CONST_INT &&
2187 ((INTVAL (operands[1]) - INTVAL (operands[2]) == 1) ||
2188 (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
2189 "* return mcore_output_cmov (operands, 0, NULL);"
2190 [(set_attr "length" "4")])
2192 (define_insn "movf4"
2193 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2195 (ne (eq:SI (reg:CC 17) (const_int 0)) (const_int 0))
2196 (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
2197 (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
2205 ;; ------------------------------------------------------------------------
2207 ;; ------------------------------------------------------------------------
2209 ; experimental conditional move with two constants +/- 1 BRC
2210 (define_insn "movtK_8"
2211 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2213 (ne (ne:SI (reg:CC 17) (const_int 0)) (const_int 0))
2214 (match_operand:SI 1 "mcore_arith_O_operand" "O")
2215 (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
2216 "GET_CODE (operands[1]) == CONST_INT &&
2217 GET_CODE (operands[2]) == CONST_INT &&
2218 ((INTVAL (operands[1]) - INTVAL (operands[2]) == 1) ||
2219 (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
2220 "* return mcore_output_cmov (operands, 1, NULL);"
2221 [(set_attr "length" "4")])
2223 (define_insn "movt4"
2224 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2226 (ne (ne:SI (reg:CC 17) (const_int 0)) (const_int 0))
2227 (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
2228 (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
2236 ;; Also need patterns to recognize lt/ge, since otherwise the compiler will
2237 ;; try to output not/asri/tstne/movf.
2239 ;; ------------------------------------------------------------------------
2241 ;; ------------------------------------------------------------------------
2243 ; experimental conditional move with two constants +/- 1 BRC
2244 (define_insn "movtK_9"
2245 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2247 (lt (match_operand:SI 1 "mcore_arith_reg_operand" "r")
2249 (match_operand:SI 2 "mcore_arith_O_operand" "O")
2250 (match_operand:SI 3 "mcore_arith_O_operand" "O")))]
2251 "GET_CODE (operands[2]) == CONST_INT &&
2252 GET_CODE (operands[3]) == CONST_INT &&
2253 ((INTVAL (operands[2]) - INTVAL (operands[3]) == 1) ||
2254 (INTVAL (operands[3]) - INTVAL (operands[2]) == 1))"
2257 rtx out_operands[4];
2258 out_operands[0] = operands[0];
2259 out_operands[1] = operands[2];
2260 out_operands[2] = operands[3];
2261 out_operands[3] = operands[1];
2263 return mcore_output_cmov (out_operands, 1, \"btsti %3,31\");
2265 [(set_attr "length" "6")])
2267 (define_insn "movt5"
2268 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2269 (if_then_else:SI (lt (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2271 (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2272 (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2275 btsti %1,31\;movt %0,%2
2276 btsti %1,31\;movf %0,%3
2277 btsti %1,31\;clrt %0
2278 btsti %1,31\;clrf %0"
2279 [(set_attr "length" "4")])
2282 ;; ------------------------------------------------------------------------
2284 ;; ------------------------------------------------------------------------
2286 ; experimental conditional move with two constants +/- 1 BRC
2287 (define_insn "movtK_10"
2288 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2290 (ge (match_operand:SI 1 "mcore_arith_reg_operand" "r")
2292 (match_operand:SI 2 "mcore_arith_O_operand" "O")
2293 (match_operand:SI 3 "mcore_arith_O_operand" "O")))]
2294 "GET_CODE (operands[2]) == CONST_INT &&
2295 GET_CODE (operands[3]) == CONST_INT &&
2296 ((INTVAL (operands[2]) - INTVAL (operands[3]) == 1) ||
2297 (INTVAL (operands[3]) - INTVAL (operands[2]) == 1))"
2300 rtx out_operands[4];
2301 out_operands[0] = operands[0];
2302 out_operands[1] = operands[2];
2303 out_operands[2] = operands[3];
2304 out_operands[3] = operands[1];
2306 return mcore_output_cmov (out_operands, 0, \"btsti %3,31\");
2308 [(set_attr "length" "6")])
2310 (define_insn "movf5"
2311 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2312 (if_then_else:SI (ge (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2314 (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2315 (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2318 btsti %1,31\;movf %0,%2
2319 btsti %1,31\;movt %0,%3
2320 btsti %1,31\;clrf %0
2321 btsti %1,31\;clrt %0"
2322 [(set_attr "length" "4")])
2324 ;; ------------------------------------------------------------------------
2325 ;; Bitfield extract (xtrbN)
2326 ;; ------------------------------------------------------------------------
2328 ; sometimes we're better off using QI/HI mode and letting the machine indep.
2329 ; part expand insv and extv.
2331 ; e.g., sequences like:a [an insertion]
2334 ; movi r7,0x00ffffff
2336 ; stw r8,(r6) r8 dead
2341 ; stb r8,(r6) r8 dead
2343 ; it looks like always using SI mode is a win except in this type of code
2344 ; (when adjacent bit fields collapse on a byte or halfword boundary). when
2345 ; expanding with SI mode, non-adjacent bit field masks fold, but with QI/HI
2346 ; mode, they do not. one thought is to add some peepholes to cover cases
2347 ; like the above, but this is not a general solution.
2349 ; -mword-bitfields expands/inserts using SI mode. otherwise, do it with
2350 ; the smallest mode possible (using the machine indep. expansions). BRC
2352 ;(define_expand "extv"
2353 ; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2354 ; (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2355 ; (match_operand:SI 2 "const_int_operand" "")
2356 ; (match_operand:SI 3 "const_int_operand" "")))
2357 ; (clobber (reg:CC 17))]
2361 ; if (INTVAL (operands[1]) != 8 || INTVAL (operands[2]) % 8 != 0)
2363 ; if (TARGET_W_FIELD)
2365 ; rtx lshft = GEN_INT (32 - (INTVAL (operands[2]) + INTVAL (operands[3])));
2366 ; rtx rshft = GEN_INT (32 - INTVAL (operands[2]));
2368 ; emit_insn (gen_rtx_SET (SImode, operands[0], operands[1]));
2369 ; emit_insn (gen_rtx_SET (SImode, operands[0],
2370 ; gen_rtx_ASHIFT (SImode, operands[0], lshft)));
2371 ; emit_insn (gen_rtx_SET (SImode, operands[0],
2372 ; gen_rtx_ASHIFTRT (SImode, operands[0], rshft)));
2380 (define_expand "extv"
2381 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2382 (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2383 (match_operand:SI 2 "const_int_operand" "")
2384 (match_operand:SI 3 "const_int_operand" "")))
2385 (clobber (reg:CC 17))]
2389 if (INTVAL (operands[2]) == 8 && INTVAL (operands[3]) % 8 == 0)
2391 /* 8-bit field, aligned properly, use the xtrb[0123]+sext sequence. */
2392 /* not DONE, not FAIL, but let the RTL get generated.... */
2394 else if (TARGET_W_FIELD)
2396 /* Arbitrary placement; note that the tree->rtl generator will make
2397 something close to this if we return FAIL */
2398 rtx lshft = GEN_INT (32 - (INTVAL (operands[2]) + INTVAL (operands[3])));
2399 rtx rshft = GEN_INT (32 - INTVAL (operands[2]));
2400 rtx tmp1 = gen_reg_rtx (SImode);
2401 rtx tmp2 = gen_reg_rtx (SImode);
2403 emit_insn (gen_rtx_SET (SImode, tmp1, operands[1]));
2404 emit_insn (gen_rtx_SET (SImode, tmp2,
2405 gen_rtx_ASHIFT (SImode, tmp1, lshft)));
2406 emit_insn (gen_rtx_SET (SImode, operands[0],
2407 gen_rtx_ASHIFTRT (SImode, tmp2, rshft)));
2412 /* Let the caller choose an alternate sequence. */
2417 (define_expand "extzv"
2418 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2419 (zero_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2420 (match_operand:SI 2 "const_int_operand" "")
2421 (match_operand:SI 3 "const_int_operand" "")))
2422 (clobber (reg:CC 17))]
2426 if (INTVAL (operands[2]) == 8 && INTVAL (operands[3]) % 8 == 0)
2428 /* 8-bit field, aligned properly, use the xtrb[0123] sequence. */
2429 /* Let the template generate some RTL.... */
2431 else if (CONST_OK_FOR_K ((1 << INTVAL (operands[2])) - 1))
2433 /* A narrow bit-field (<=5 bits) means we can do a shift to put
2434 it in place and then use an andi to extract it.
2435 This is as good as a shiftleft/shiftright. */
2438 rtx mask = GEN_INT ((1 << INTVAL (operands[2])) - 1);
2440 if (INTVAL (operands[3]) == 0)
2442 shifted = operands[1];
2446 rtx rshft = GEN_INT (INTVAL (operands[3]));
2447 shifted = gen_reg_rtx (SImode);
2448 emit_insn (gen_rtx_SET (SImode, shifted,
2449 gen_rtx_LSHIFTRT (SImode, operands[1], rshft)));
2451 emit_insn (gen_rtx_SET (SImode, operands[0],
2452 gen_rtx_AND (SImode, shifted, mask)));
2455 else if (TARGET_W_FIELD)
2457 /* Arbitrary pattern; play shift/shift games to get it.
2458 * this is pretty much what the caller will do if we say FAIL */
2459 rtx lshft = GEN_INT (32 - (INTVAL (operands[2]) + INTVAL (operands[3])));
2460 rtx rshft = GEN_INT (32 - INTVAL (operands[2]));
2461 rtx tmp1 = gen_reg_rtx (SImode);
2462 rtx tmp2 = gen_reg_rtx (SImode);
2464 emit_insn (gen_rtx_SET (SImode, tmp1, operands[1]));
2465 emit_insn (gen_rtx_SET (SImode, tmp2,
2466 gen_rtx_ASHIFT (SImode, tmp1, lshft)));
2467 emit_insn (gen_rtx_SET (SImode, operands[0],
2468 gen_rtx_LSHIFTRT (SImode, tmp2, rshft)));
2473 /* Make the compiler figure out some alternative mechanism. */
2477 /* Emit the RTL pattern; something will match it later. */
2480 (define_expand "insv"
2481 [(set (zero_extract:SI (match_operand:SI 0 "mcore_arith_reg_operand" "")
2482 (match_operand:SI 1 "const_int_operand" "")
2483 (match_operand:SI 2 "const_int_operand" ""))
2484 (match_operand:SI 3 "general_operand" ""))
2485 (clobber (reg:CC 17))]
2489 if (mcore_expand_insv (operands))
2500 ;; the xtrb[0123] instructions handily get at 8-bit fields on nice boundaries.
2501 ;; but then, they do force you through r1.
2503 ;; the combiner will build such patterns for us, so we'll make them available
2506 ;; Note that we have both SIGNED and UNSIGNED versions of these...
2510 ;; These no longer worry about the clobbering of CC bit; not sure this is
2513 ;; the SIGNED versions of these
2516 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,b")
2517 (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,r") (const_int 8) (const_int 24)))]
2521 xtrb0 %0,%1\;sextb %0"
2522 [(set_attr "type" "shift")])
2525 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=b")
2526 (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r") (const_int 8) (const_int 16)))]
2528 "xtrb1 %0,%1\;sextb %0"
2529 [(set_attr "type" "shift")])
2532 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=b")
2533 (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r") (const_int 8) (const_int 8)))]
2535 "xtrb2 %0,%1\;sextb %0"
2536 [(set_attr "type" "shift")])
2539 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2540 (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0") (const_int 8) (const_int 0)))]
2543 [(set_attr "type" "shift")])
2545 ;; the UNSIGNED uses of xtrb[0123]
2548 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,b")
2549 (zero_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,r") (const_int 8) (const_int 24)))]
2554 [(set_attr "type" "shift")])
2557 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=b")
2558 (zero_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r") (const_int 8) (const_int 16)))]
2561 [(set_attr "type" "shift")])
2564 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=b")
2565 (zero_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r") (const_int 8) (const_int 8)))]
2568 [(set_attr "type" "shift")])
2570 ;; This can be peepholed if it follows a ldb ...
2572 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,b")
2573 (zero_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,r") (const_int 8) (const_int 0)))]
2577 xtrb3 %0,%1\;zextb %0"
2578 [(set_attr "type" "shift")])
2581 ;; ------------------------------------------------------------------------
2582 ;; Block move - adapted from m88k.md
2583 ;; ------------------------------------------------------------------------
2585 (define_expand "movmemsi"
2586 [(parallel [(set (mem:BLK (match_operand:BLK 0 "" ""))
2587 (mem:BLK (match_operand:BLK 1 "" "")))
2588 (use (match_operand:SI 2 "general_operand" ""))
2589 (use (match_operand:SI 3 "immediate_operand" ""))])]
2593 if (mcore_expand_block_move (operands))
2599 ;; ;;; ??? These patterns are meant to be generated from expand_block_move,
2600 ;; ;;; but they currently are not.
2603 ;; [(set (match_operand:QI 0 "mcore_arith_reg_operand" "=r")
2604 ;; (match_operand:BLK 1 "mcore_general_movsrc_operand" "m"))]
2607 ;; [(set_attr "type" "load")])
2610 ;; [(set (match_operand:HI 0 "mcore_arith_reg_operand" "=r")
2611 ;; (match_operand:BLK 1 "mcore_general_movsrc_operand" "m"))]
2614 ;; [(set_attr "type" "load")])
2617 ;; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2618 ;; (match_operand:BLK 1 "mcore_general_movsrc_operand" "m"))]
2621 ;; [(set_attr "type" "load")])
2624 ;; [(set (match_operand:BLK 0 "mcore_general_movdst_operand" "=m")
2625 ;; (match_operand:QI 1 "mcore_arith_reg_operand" "r"))]
2628 ;; [(set_attr "type" "store")])
2631 ;; [(set (match_operand:BLK 0 "mcore_general_movdst_operand" "=m")
2632 ;; (match_operand:HI 1 "mcore_arith_reg_operand" "r"))]
2635 ;; [(set_attr "type" "store")])
2638 ;; [(set (match_operand:BLK 0 "mcore_general_movdst_operand" "=m")
2639 ;; (match_operand:SI 1 "mcore_arith_reg_operand" "r"))]
2642 ;; [(set_attr "type" "store")])
2644 ;; ------------------------------------------------------------------------
2645 ;; Misc Optimizing quirks
2646 ;; ------------------------------------------------------------------------
2648 ;; pair to catch constructs like: (int *)((p+=4)-4) which happen
2649 ;; in stdarg/varargs traversal. This changes a 3 insn sequence to a 2
2650 ;; insn sequence. -- RBE 11/30/95
2653 (set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2654 (match_operand:SI 1 "mcore_arith_reg_operand" "+r"))
2655 (set (match_dup 1) (plus:SI (match_dup 1) (match_operand 2 "mcore_arith_any_imm_operand" "")))])]
2656 "GET_CODE(operands[2]) == CONST_INT"
2658 [(set_attr "length" "4")])
2662 (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2663 (match_operand:SI 1 "mcore_arith_reg_operand" ""))
2664 (set (match_dup 1) (plus:SI (match_dup 1) (match_operand 2 "mcore_arith_any_imm_operand" "")))])]
2665 "GET_CODE(operands[2]) == CONST_INT &&
2666 operands[0] != operands[1]"
2667 [(set (match_dup 0) (match_dup 1))
2668 (set (match_dup 1) (plus:SI (match_dup 1) (match_dup 2)))])
2673 ; note: in the following patterns, use mcore_is_dead() to ensure that the
2674 ; reg we may be trashing really is dead. reload doesn't always mark
2675 ; deaths, so mcore_is_dead() (see mcore.c) scans forward to find its death. BRC
2677 ;;; A peephole to convert the 3 instruction sequence generated by reload
2678 ;;; to load a FP-offset address into a 2 instruction sequence.
2679 ;;; ??? This probably never matches anymore.
2681 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "r")
2682 (match_operand:SI 1 "const_int_operand" "J"))
2683 (set (match_dup 0) (neg:SI (match_dup 0)))
2685 (plus:SI (match_dup 0)
2686 (match_operand:SI 2 "mcore_arith_reg_operand" "r")))]
2687 "CONST_OK_FOR_J (INTVAL (operands[1]))"
2688 "error\;mov %0,%2\;subi %0,%1")
2690 ;; Moves of inlinable constants are done late, so when a 'not' is generated
2691 ;; it is never combined with the following 'and' to generate an 'andn' b/c
2692 ;; the combiner never sees it. use a peephole to pick up this case (happens
2693 ;; mostly with bitfields) BRC
2696 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "r")
2697 (match_operand:SI 1 "const_int_operand" "i"))
2698 (set (match_operand:SI 2 "mcore_arith_reg_operand" "r")
2699 (and:SI (match_dup 2) (match_dup 0)))]
2700 "mcore_const_trick_uses_not (INTVAL (operands[1])) &&
2701 operands[0] != operands[2] &&
2702 mcore_is_dead (insn, operands[0])"
2703 "* return mcore_output_andn (insn, operands);")
2705 ; when setting or clearing just two bits, it's cheapest to use two bseti's
2706 ; or bclri's. only happens when relaxing immediates. BRC
2709 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2710 (match_operand:SI 1 "const_int_operand" ""))
2711 (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
2712 (ior:SI (match_dup 2) (match_dup 0)))]
2714 && mcore_num_ones (INTVAL (operands[1])) == 2
2715 && mcore_is_dead (insn, operands[0])"
2716 "* return mcore_output_bseti (operands[2], INTVAL (operands[1]));")
2719 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2720 (match_operand:SI 1 "const_int_operand" ""))
2721 (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
2722 (and:SI (match_dup 2) (match_dup 0)))]
2723 "TARGET_HARDLIT && mcore_num_zeros (INTVAL (operands[1])) == 2 &&
2724 mcore_is_dead (insn, operands[0])"
2725 "* return mcore_output_bclri (operands[2], INTVAL (operands[1]));")
2727 ; change an and with a mask that has a single cleared bit into a bclri. this
2728 ; handles QI and HI mode values using the knowledge that the most significant
2729 ; bits don't matter.
2732 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2733 (match_operand:SI 1 "const_int_operand" ""))
2734 (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
2735 (and:SI (match_operand:SI 3 "mcore_arith_reg_operand" "")
2737 "GET_CODE (operands[3]) == SUBREG &&
2738 GET_MODE (SUBREG_REG (operands[3])) == QImode &&
2739 mcore_num_zeros (INTVAL (operands[1]) | 0xffffff00) == 1 &&
2740 mcore_is_dead (insn, operands[0])"
2742 if (! mcore_is_same_reg (operands[2], operands[3]))
2743 output_asm_insn (\"mov\\t%2,%3\", operands);
2744 return mcore_output_bclri (operands[2], INTVAL (operands[1]) | 0xffffff00);")
2746 /* Do not fold these together -- mode is lost at final output phase. */
2749 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2750 (match_operand:SI 1 "const_int_operand" ""))
2751 (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
2752 (and:SI (match_operand:SI 3 "mcore_arith_reg_operand" "")
2754 "GET_CODE (operands[3]) == SUBREG &&
2755 GET_MODE (SUBREG_REG (operands[3])) == HImode &&
2756 mcore_num_zeros (INTVAL (operands[1]) | 0xffff0000) == 1 &&
2757 operands[2] == operands[3] &&
2758 mcore_is_dead (insn, operands[0])"
2760 if (! mcore_is_same_reg (operands[2], operands[3]))
2761 output_asm_insn (\"mov\\t%2,%3\", operands);
2762 return mcore_output_bclri (operands[2], INTVAL (operands[1]) | 0xffff0000);")
2764 ; This peephole helps when using -mwide-bitfields to widen fields so they
2765 ; collapse. This, however, has the effect that a narrower mode is not used
2768 ; e.g., sequences like:
2771 ; movi r7,0x00ffffff
2773 ; stw r8,(r6) r8 dead
2775 ; get peepholed to become:
2778 ; stb r8,(r6) r8 dead
2780 ; Do only easy addresses that have no offset. This peephole is also applied
2781 ; to halfwords. We need to check that the load is non-volatile before we get
2785 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2786 (match_operand:SI 1 "memory_operand" ""))
2787 (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
2788 (match_operand:SI 3 "const_int_operand" ""))
2789 (set (match_dup 0) (and:SI (match_dup 0) (match_dup 2)))
2790 (set (match_operand:SI 4 "memory_operand" "") (match_dup 0))]
2791 "mcore_is_dead (insn, operands[0]) &&
2792 ! MEM_VOLATILE_P (operands[1]) &&
2793 mcore_is_dead (insn, operands[2]) &&
2794 (mcore_byte_offset (INTVAL (operands[3])) > -1 ||
2795 mcore_halfword_offset (INTVAL (operands[3])) > -1) &&
2796 ! MEM_VOLATILE_P (operands[4]) &&
2797 GET_CODE (XEXP (operands[4], 0)) == REG"
2801 enum machine_mode mode;
2802 rtx base_reg = XEXP (operands[4], 0);
2804 if ((ofs = mcore_byte_offset (INTVAL (operands[3]))) > -1)
2806 else if ((ofs = mcore_halfword_offset (INTVAL (operands[3]))) > -1)
2812 operands[4] = gen_rtx_MEM (mode,
2813 gen_rtx_PLUS (SImode, base_reg, GEN_INT(ofs)));
2815 operands[4] = gen_rtx_MEM (mode, base_reg);
2818 return \"movi %0,0\\n\\tst.b %0,%4\";
2820 return \"movi %0,0\\n\\tst.h %0,%4\";
2823 ; from sop11. get btsti's for (LT A 0) where A is a QI or HI value
2826 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "r")
2827 (sign_extend:SI (match_operand:QI 1 "mcore_arith_reg_operand" "0")))
2829 (lt:CC (match_dup 0)
2831 "mcore_is_dead (insn, operands[0])"
2835 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "r")
2836 (sign_extend:SI (match_operand:HI 1 "mcore_arith_reg_operand" "0")))
2838 (lt:CC (match_dup 0)
2840 "mcore_is_dead (insn, operands[0])"
2843 ; Pick up a tst. This combination happens because the immediate is not
2844 ; allowed to fold into one of the operands of the tst. Does not happen
2845 ; when relaxing immediates. BRC
2848 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2849 (match_operand:SI 1 "mcore_arith_reg_operand" ""))
2851 (and:SI (match_dup 0)
2852 (match_operand:SI 2 "mcore_literal_K_operand" "")))
2853 (set (reg:CC 17) (ne:CC (match_dup 0) (const_int 0)))]
2854 "mcore_is_dead (insn, operands[0])"
2855 "movi %0,%2\;tst %1,%0")
2858 [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2859 (if_then_else:SI (ne (zero_extract:SI
2860 (match_operand:SI 1 "mcore_arith_reg_operand" "")
2862 (match_operand:SI 2 "mcore_literal_K_operand" ""))
2864 (match_operand:SI 3 "mcore_arith_imm_operand" "")
2865 (match_operand:SI 4 "mcore_arith_imm_operand" "")))
2866 (set (reg:CC 17) (ne:CC (match_dup 0) (const_int 0)))]
2870 unsigned int op0 = REGNO (operands[0]);
2872 if (GET_CODE (operands[3]) == REG)
2874 if (REGNO (operands[3]) == op0 && GET_CODE (operands[4]) == CONST_INT
2875 && INTVAL (operands[4]) == 0)
2876 return \"btsti %1,%2\\n\\tclrf %0\";
2877 else if (GET_CODE (operands[4]) == REG)
2879 if (REGNO (operands[4]) == op0)
2880 return \"btsti %1,%2\\n\\tmovf %0,%3\";
2881 else if (REGNO (operands[3]) == op0)
2882 return \"btsti %1,%2\\n\\tmovt %0,%4\";
2887 else if (GET_CODE (operands[3]) == CONST_INT
2888 && INTVAL (operands[3]) == 0
2889 && GET_CODE (operands[4]) == REG)
2890 return \"btsti %1,%2\\n\\tclrt %0\";
2895 ; experimental - do the constant folding ourselves. note that this isn't
2896 ; re-applied like we'd really want. i.e., four ands collapse into two
2897 ; instead of one. this is because peepholes are applied as a sliding
2898 ; window. the peephole does not generate new rtl's, but instead slides
2899 ; across the rtl's generating machine instructions. it would be nice
2900 ; if the peephole optimizer is changed to re-apply patterns and to gen
2901 ; new rtl's. this is more flexible. the pattern below helps when we're
2902 ; not using relaxed immediates. BRC
2905 ; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2906 ; (match_operand:SI 1 "const_int_operand" ""))
2907 ; (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
2908 ; (and:SI (match_dup 2) (match_dup 0)))
2909 ; (set (match_dup 0)
2910 ; (match_operand:SI 3 "const_int_operand" ""))
2911 ; (set (match_dup 2)
2912 ; (and:SI (match_dup 2) (match_dup 0)))]
2913 ; "!TARGET_RELAX_IMM && mcore_is_dead (insn, operands[0]) &&
2914 ; mcore_const_ok_for_inline (INTVAL (operands[1]) & INTVAL (operands[3]))"
2917 ; rtx out_operands[2];
2918 ; out_operands[0] = operands[0];
2919 ; out_operands[1] = GEN_INT (INTVAL (operands[1]) & INTVAL (operands[3]));
2921 ; output_inline_const (SImode, out_operands);
2923 ; output_asm_insn (\"and %2,%0\", operands);
2928 ; BRC: for inlining get rid of extra test - experimental
2930 ; [(set (match_operand:SI 0 "mcore_arith_reg_operand" "r")
2931 ; (ne:SI (reg:CC 17) (const_int 0)))
2932 ; (set (reg:CC 17) (ne:CC (match_dup 0) (const_int 0)))
2934 ; (if_then_else (eq (reg:CC 17) (const_int 0))
2935 ; (label_ref (match_operand 1 "" ""))
2940 ; if (get_attr_length (insn) == 10)
2942 ; output_asm_insn (\"bt 2f\\n\\tjmpi [1f]\", operands);
2943 ; output_asm_insn (\".align 2\\n1:\", operands);
2944 ; output_asm_insn (\".long %1\\n2:\", operands);
2947 ; return \"bf %l1\";
2951 ;;; Special patterns for dealing with the constant pool.
2953 ;;; 4 byte integer in line.
2955 (define_insn "consttable_4"
2956 [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 0)]
2960 assemble_integer (operands[0], 4, BITS_PER_WORD, 1);
2963 [(set_attr "length" "4")])
2965 ;;; align to a four byte boundary.
2967 (define_insn "align_4"
2968 [(unspec_volatile [(const_int 0)] 1)]
2972 ;;; Handle extra constant pool entries created during final pass.
2974 (define_insn "consttable_end"
2975 [(unspec_volatile [(const_int 0)] 2)]
2977 "* return mcore_output_jump_label_table ();")
2980 ;; Stack allocation -- in particular, for alloca().
2981 ;; this is *not* what we use for entry into functions.
2983 ;; This is how we allocate stack space. If we are allocating a
2984 ;; constant amount of space and we know it is less than 4096
2985 ;; bytes, we need do nothing.
2987 ;; If it is more than 4096 bytes, we need to probe the stack
2990 ;; operands[1], the distance is a POSITIVE number indicating that we
2991 ;; are allocating stack space
2993 (define_expand "allocate_stack"
2996 (match_operand:SI 1 "general_operand" "")))
2997 (set (match_operand:SI 0 "register_operand" "=r")
3002 /* If he wants no probing, just do it for him. */
3003 if (mcore_stack_increment == 0)
3005 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,operands[1]));
3006 ;; emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
3010 /* For small constant growth, we unroll the code. */
3011 if (GET_CODE (operands[1]) == CONST_INT
3012 && INTVAL (operands[1]) < 8 * STACK_UNITS_MAXSTEP)
3014 HOST_WIDE_INT left = INTVAL(operands[1]);
3016 /* If it's a long way, get close enough for a last shot. */
3017 if (left >= STACK_UNITS_MAXSTEP)
3019 rtx tmp = gen_reg_rtx (Pmode);
3020 emit_insn (gen_movsi (tmp, GEN_INT (STACK_UNITS_MAXSTEP)));
3023 rtx memref = gen_rtx_MEM (SImode, stack_pointer_rtx);
3025 MEM_VOLATILE_P (memref) = 1;
3026 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
3027 emit_insn (gen_movsi (memref, stack_pointer_rtx));
3028 left -= STACK_UNITS_MAXSTEP;
3030 while (left > STACK_UNITS_MAXSTEP);
3032 /* Perform the final adjustment. */
3033 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-left)));
3034 ;; emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
3040 rtx loop_label = gen_label_rtx ();
3041 rtx step = gen_reg_rtx (Pmode);
3042 rtx tmp = gen_reg_rtx (Pmode);
3046 emit_insn (gen_movsi (tmp, operands[1]));
3047 emit_insn (gen_movsi (step, GEN_INT (STACK_UNITS_MAXSTEP)));
3049 if (GET_CODE (operands[1]) != CONST_INT)
3051 out_label = gen_label_rtx ();
3052 test = gen_rtx_GEU (VOIDmode, step, tmp); /* quick out */
3053 emit_jump_insn (gen_cbranchsi4 (test, step, tmp, out_label));
3056 /* Run a loop that steps it incrementally. */
3057 emit_label (loop_label);
3059 /* Extend a step, probe, and adjust remaining count. */
3060 emit_insn(gen_subsi3(stack_pointer_rtx, stack_pointer_rtx, step));
3061 memref = gen_rtx_MEM (SImode, stack_pointer_rtx);
3062 MEM_VOLATILE_P (memref) = 1;
3063 emit_insn(gen_movsi(memref, stack_pointer_rtx));
3064 emit_insn(gen_subsi3(tmp, tmp, step));
3066 /* Loop condition -- going back up. */
3067 test = gen_rtx_LTU (VOIDmode, step, tmp);
3068 emit_jump_insn (gen_cbranchsi4 (test, step, tmp, loop_label));
3071 emit_label (out_label);
3073 /* Bump the residual. */
3074 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
3075 ;; emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
3078 /* simple one-shot -- ensure register and do a subtract.
3079 * This does NOT comply with the ABI. */
3080 emit_insn (gen_movsi (tmp, operands[1]));
3081 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
3082 ;; emit_move_insn (operands[0], virtual_stack_dynamic_rtx);