Merged with mainline at revision 128810.
[official-gcc.git] / gcc / config / mcore / mcore.md
blob74906993e209d4d668cbaaf00dd345d311a02a93
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)
11 ;; any later version.
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 ;; -------------------------------------------------------------------------
27 ;; Attributes
28 ;; -------------------------------------------------------------------------
30 ; Target CPU.
32 (define_attr "type" "brcond,branch,jmp,load,store,move,alu,shift"
33   (const_string "alu"))
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")
51                          "nothing")
52 (define_insn_reservation "memory" 2
53                          (eq_attr "type" "load")
54                          "nothing")
56 (include "predicates.md")
58 ;; -------------------------------------------------------------------------
59 ;; Test and bit test
60 ;; -------------------------------------------------------------------------
62 (define_insn ""
63   [(set (reg:SI 17) 
64         (sign_extract:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
65                          (const_int 1)
66                          (match_operand:SI 1 "mcore_literal_K_operand" "K")))]
67   ""
68   "btsti        %0,%1"
69   [(set_attr "type" "shift")])
71 (define_insn ""
72   [(set (reg:SI 17) 
73         (zero_extract:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
74                          (const_int 1)
75                          (match_operand:SI 1 "mcore_literal_K_operand" "K")))]
76   ""
77   "btsti        %0,%1"
78   [(set_attr "type" "shift")])
80 ;;; This is created by combine.
81 (define_insn ""
82   [(set (reg:CC 17)
83         (ne:CC (zero_extract:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
84                                 (const_int 1)
85                                 (match_operand:SI 1 "mcore_literal_K_operand" "K"))
86                (const_int 0)))]
87   ""
88   "btsti        %0,%1"
89   [(set_attr "type" "shift")])
92 ;; Created by combine from conditional patterns below (see sextb/btsti rx,31)
94 (define_insn ""
95   [(set (reg:CC 17)
96         (ne:CC (lshiftrt:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
97                             (const_int 7))
98                (const_int 0)))]
99   "GET_CODE(operands[0]) == SUBREG && 
100       GET_MODE(SUBREG_REG(operands[0])) == QImode"
101   "btsti        %0,7"
102   [(set_attr "type" "shift")])
104 (define_insn ""
105   [(set (reg:CC 17)
106         (ne:CC (lshiftrt:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
107                             (const_int 15))
108                (const_int 0)))]
109   "GET_CODE(operands[0]) == SUBREG && 
110       GET_MODE(SUBREG_REG(operands[0])) == HImode"
111   "btsti        %0,15"
112   [(set_attr "type" "shift")])
114 (define_split
115   [(set (pc)
116         (if_then_else (ne (eq:CC (zero_extract:SI
117                                   (match_operand:SI 0 "mcore_arith_reg_operand" "")
118                                   (const_int 1)
119                                   (match_operand:SI 1 "mcore_literal_K_operand" ""))
120                                  (const_int 0))
121                           (const_int 0))
122                       (label_ref (match_operand 2 "" ""))
123                       (pc)))]
124   ""
125   [(set (reg:CC 17)
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))
129                            (pc)))]
130   "")
132 (define_split
133   [(set (pc)
134         (if_then_else (eq (ne:CC (zero_extract:SI
135                                   (match_operand:SI 0 "mcore_arith_reg_operand" "")
136                                   (const_int 1)
137                                   (match_operand:SI 1 "mcore_literal_K_operand" ""))
138                                  (const_int 0))
139                           (const_int 0))
140                       (label_ref (match_operand 2 "" ""))
141                       (pc)))]
142   ""
143   [(set (reg:CC 17)
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))
147                            (pc)))]
148   "")
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
165 ;; 
166 ;; (define_insn ""
167 ;;   [(set (reg:CC 17)
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"))
170 ;;             (const_int 0)))]
171 ;;   "TARGET_RELAX_IMM"
172 ;;   "tst       %0,%1")
173 ;; 
174 ;; (define_insn ""
175 ;;   [(set (reg:CC 17)
176 ;;      (ne:CC (and:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
177 ;;                     (match_operand:SI 1 "mcore_arith_M_operand" "r"))
178 ;;             (const_int 0)))]
179 ;;   "!TARGET_RELAX_IMM"
180 ;;   "tst       %0,%1")
182 (define_insn ""
183   [(set (reg:CC 17)
184         (ne:CC (and:SI (match_operand:SI 0 "mcore_arith_reg_operand" "r")
185                        (match_operand:SI 1 "mcore_arith_M_operand" "r"))
186                (const_int 0)))]
187   ""
188   "tst  %0,%1")
191 (define_split 
192   [(parallel[
193       (set (reg:CC 17)
194            (ne:CC (ne:SI (leu:CC (match_operand:SI 0 "mcore_arith_reg_operand" "")
195                                  (match_operand:SI 1 "mcore_arith_reg_operand" ""))
196                          (const_int 0))
197                   (const_int 0)))
198       (clobber (match_operand:CC 2 "mcore_arith_reg_operand" ""))])]
199   ""
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")
209                                     (const_int -1))               
210                            (const_int 0)))
211    (set (match_dup 0)
212         (plus:SI (match_dup 0)
213                  (const_int -1)))]
214   ""
215   "decne        %0")
217 ;; The combiner seems to prefer the following to the former.
219 (define_insn ""
220   [(set (reg:CC 17) (ne:CC (match_operand:SI 0 "mcore_arith_reg_operand" "+r")
221                            (const_int 1)))
222    (set (match_dup 0)
223         (plus:SI (match_dup 0)
224                  (const_int -1)))]
225   ""
226   "decne        %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")))]
231   ""
232   "cmpne        %0,%1")
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")))]
237   ""
238   "cmpnei       %0,%1")
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")))]
243   ""
244   "cmplt        %1,%0")
246 (define_insn ""
247   [(set (reg:CC 17) (gt:CC (plus:SI
248                             (match_operand:SI 0 "mcore_arith_reg_operand" "+r")
249                             (const_int -1))
250                            (const_int 0)))
251    (set (match_dup 0) (plus:SI (match_dup 0) (const_int -1)))]
252   ""
253   "decgt        %0")
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")))]
258   ""
259   "cmplt        %0,%1")
261 ; cmplti is 1-32
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")))]
265   ""
266   "cmplti       %0,%1")
268 ; covers cmplti x,0
269 (define_insn ""
270   [(set (reg:CC 17) (lt:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
271                          (const_int 0)))]
272   ""
273   "btsti        %0,31")
275 (define_insn ""
276   [(set (reg:CC 17) (lt:CC (plus:SI
277                             (match_operand:SI 0 "mcore_arith_reg_operand" "+r")
278                             (const_int -1))
279                            (const_int 0)))
280    (set (match_dup 0) (plus:SI (match_dup 0) (const_int -1)))]
281   ""
282   "declt        %0")
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")))]
291   ""
292   "cmphs        %0,%1")
294 (define_insn "cmpgeusi_0"
295   [(set (reg:CC 17) (geu:CC (match_operand:SI 0 "mcore_arith_reg_operand" "r")
296                             (const_int 0)))]
297   ""
298   "cmpnei       %0, 0")
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")))]
303   ""
304   "cmphs        %1,%0")
306 ;; We save the compare operands in the cmpxx patterns and use them when
307 ;; we generate the branch.
309 ;; We accept constants here, in case we can modify them to ones which
310 ;; are more efficient to load.  E.g. change 'x <= 62' to 'x < 63'.
312 (define_expand "cmpsi"
313   [(set (reg:CC 17) (compare:CC (match_operand:SI 0 "mcore_compare_operand" "")
314                                 (match_operand:SI 1 "nonmemory_operand" "")))]
315   ""
316   "
317 { arch_compare_op0 = operands[0];
318   arch_compare_op1 = operands[1];
319   DONE;
322 ;; -------------------------------------------------------------------------
323 ;; Logical operations
324 ;; -------------------------------------------------------------------------
326 ;; Logical AND clearing a single bit.  andsi3 knows that we have this
327 ;; pattern and allows the constant literal pass through.
330 ;; RBE 2/97: don't need this pattern any longer...
331 ;; RBE: I don't think we need both "S" and exact_log2() clauses.
332 ;;(define_insn ""
333 ;;  [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
334 ;;      (and:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
335 ;;              (match_operand:SI 2 "const_int_operand" "S")))]
336 ;;  "mcore_arith_S_operand (operands[2])"
337 ;;  "bclri      %0,%Q2")
340 (define_insn "andnsi3"
341   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
342         (and:SI (not:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r"))
343                 (match_operand:SI 2 "mcore_arith_reg_operand" "0")))]
344   ""
345   "andn %0,%1")
347 (define_expand "andsi3"
348   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
349         (and:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
350                 (match_operand:SI 2 "nonmemory_operand" "")))]
351   ""
352   "
354   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0
355       && ! mcore_arith_S_operand (operands[2]))
356     {
357       HOST_WIDE_INT not_value = ~ INTVAL (operands[2]);
359       if (   CONST_OK_FOR_I (not_value)
360           || CONST_OK_FOR_M (not_value)
361           || CONST_OK_FOR_N (not_value))
362         {
363           operands[2] = copy_to_mode_reg (SImode, GEN_INT (not_value));
364           emit_insn (gen_andnsi3 (operands[0], operands[2], operands[1]));
365           DONE;
366         }
367     }
369   if (! mcore_arith_K_S_operand (operands[2], SImode))
370     operands[2] = copy_to_mode_reg (SImode, operands[2]);
373 (define_insn ""
374   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
375         (and:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0,r,0")
376                 (match_operand:SI 2 "mcore_arith_any_imm_operand" "r,K,0,S")))]
377   "TARGET_RELAX_IMM"
378   "*
380    switch (which_alternative)
381      {
382      case 0: return \"and       %0,%2\";
383      case 1: return \"andi      %0,%2\";
384      case 2: return \"and       %0,%1\";
385      /* case -1: return \"bclri %0,%Q2\";        will not happen */
386      case 3: return mcore_output_bclri (operands[0], INTVAL (operands[2]));
387      default: gcc_unreachable ();
388      }
391 ;; This was the old "S" which was "!(2^n)" */
392 ;; case -1: return \"bclri      %0,%Q2\";        will not happen */
394 (define_insn ""
395   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
396         (and:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0,r,0")
397                 (match_operand:SI 2 "mcore_arith_K_S_operand" "r,K,0,S")))]
398   "!TARGET_RELAX_IMM"
399   "*
401    switch (which_alternative)
402      {
403      case 0: return \"and       %0,%2\";
404      case 1: return \"andi      %0,%2\";
405      case 2: return \"and       %0,%1\";
406      case 3: return mcore_output_bclri (operands[0], INTVAL (operands[2]));
407      default: gcc_unreachable ();
408      }
411 ;(define_insn "iorsi3"
412 ;  [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
413 ;       (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
414 ;               (match_operand:SI 2 "mcore_arith_reg_operand" "r")))]
415 ;  ""
416 ;  "or  %0,%2")
418 ; need an expand to resolve ambiguity betw. the two iors below.
419 (define_expand "iorsi3"
420   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
421         (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
422                 (match_operand:SI 2 "nonmemory_operand" "")))]
423   ""
424   "
426    if (! mcore_arith_M_operand (operands[2], SImode))
427       operands[2] = copy_to_mode_reg (SImode, operands[2]);
430 (define_insn ""
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_any_imm_operand" "r,M,T")))]
434   "TARGET_RELAX_IMM"
435   "*
437    switch (which_alternative)
438      {
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 ();
443      }
446 (define_insn ""
447   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r")
448         (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0,0,0")
449                 (match_operand:SI 2 "mcore_arith_M_operand" "r,M,T")))]
450   "!TARGET_RELAX_IMM"
451   "*
453    switch (which_alternative)
454      {
455      case 0: return \"or        %0,%2\";
456      case 1: return \"bseti     %0,%P2\";
457      case 2: return mcore_output_bseti (operands[0], INTVAL (operands[2]));
458      default: gcc_unreachable ();
459      }
462 ;(define_insn ""
463 ;  [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
464 ;       (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
465 ;               (match_operand:SI 2 "const_int_operand" "M")))]
466 ;  "exact_log2 (INTVAL (operands[2])) >= 0"
467 ;  "bseti       %0,%P2")
469 ;(define_insn ""
470 ;  [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
471 ;       (ior:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
472 ;               (match_operand:SI 2 "const_int_operand" "i")))]
473 ;  "mcore_num_ones (INTVAL (operands[2])) < 3"
474 ;  "* return mcore_output_bseti (operands[0], INTVAL (operands[2]));")
476 (define_insn "xorsi3"
477   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
478         (xor:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
479                 (match_operand:SI 2 "mcore_arith_reg_operand" "r")))]
480   ""
481   "xor  %0,%2")
483 ; these patterns give better code then gcc invents if
484 ; left to its own devices
486 (define_insn "anddi3"
487   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=r")
488         (and:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
489                 (match_operand:DI 2 "mcore_arith_reg_operand" "r")))]
490   ""
491   "and  %0,%2\;and      %R0,%R2"
492   [(set_attr "length" "4")])
494 (define_insn "iordi3"
495   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=r")
496         (ior:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
497                 (match_operand:DI 2 "mcore_arith_reg_operand" "r")))]
498   ""
499   "or   %0,%2\;or       %R0,%R2"
500   [(set_attr "length" "4")])
502 (define_insn "xordi3"
503   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=r")
504         (xor:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
505                 (match_operand:DI 2 "mcore_arith_reg_operand" "r")))]
506   ""
507   "xor  %0,%2\;xor      %R0,%R2"
508   [(set_attr "length" "4")])
510 ;; -------------------------------------------------------------------------
511 ;; Shifts and rotates
512 ;; -------------------------------------------------------------------------
514 ;; Only allow these if the shift count is a convenient constant.
515 (define_expand "rotlsi3"
516   [(set (match_operand:SI            0 "mcore_arith_reg_operand" "")
517         (rotate:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
518                    (match_operand:SI 2 "nonmemory_operand" "")))]
519   ""
520   "if (! mcore_literal_K_operand (operands[2], SImode))
521          FAIL;
522   ")
524 ;; We can only do constant rotates, which is what this pattern provides.
525 ;; The combiner will put it together for us when we do:
526 ;;      (x << N) | (x >> (32 - N))
527 (define_insn ""
528   [(set (match_operand:SI              0 "mcore_arith_reg_operand" "=r")
529         (rotate:SI (match_operand:SI   1 "mcore_arith_reg_operand"  "0")
530                      (match_operand:SI 2 "mcore_literal_K_operand"  "K")))]
531   ""
532   "rotli        %0,%2"
533   [(set_attr "type" "shift")])
535 (define_insn "ashlsi3"
536   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r")
537         (ashift:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0")
538                    (match_operand:SI 2 "mcore_arith_K_operand_not_0" "r,K")))]
539   ""
540   "@
541         lsl     %0,%2
542         lsli    %0,%2"
543   [(set_attr "type" "shift")])
545 (define_insn ""
546   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
547         (ashift:SI (const_int 1)
548                    (match_operand:SI 1 "mcore_arith_reg_operand" "r")))]
549   ""
550   "bgenr        %0,%1"
551   [(set_attr "type" "shift")])
553 (define_insn "ashrsi3"
554   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r")
555         (ashiftrt:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0")
556                      (match_operand:SI 2 "mcore_arith_K_operand_not_0" "r,K")))]
557   ""
558   "@
559         asr     %0,%2
560         asri    %0,%2"
561   [(set_attr "type" "shift")])
563 (define_insn "lshrsi3"
564   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r")
565         (lshiftrt:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0")
566                      (match_operand:SI 2 "mcore_arith_K_operand_not_0" "r,K")))]
567   ""
568   "@
569         lsr     %0,%2
570         lsri    %0,%2"
571   [(set_attr "type" "shift")])
573 ;(define_expand "ashldi3"
574 ;  [(parallel[(set (match_operand:DI 0 "mcore_arith_reg_operand" "")
575 ;                 (ashift:DI (match_operand:DI 1 "mcore_arith_reg_operand" "")
576 ;                            (match_operand:DI 2 "immediate_operand" "")))
578 ;            (clobber (reg:CC 17))])]
579 ;           
580 ;  ""
581 ;  "
583 ;  if (GET_CODE (operands[2]) != CONST_INT
584 ;      || INTVAL (operands[2]) != 1)
585 ;    FAIL;
586 ;}")
588 ;(define_insn ""
589 ;  [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=r")
590 ;       (ashift:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")
591 ;                    (const_int 1)))
592 ;   (clobber (reg:CC 17))]
593 ;  ""
594 ;  "lsli        %R0,0\;rotli    %0,0"
595 ;  [(set_attr "length" "4") (set_attr "type" "shift")])
597 ;; -------------------------------------------------------------------------
598 ;; Index instructions
599 ;; -------------------------------------------------------------------------
600 ;; The second of each set of patterns is borrowed from the alpha.md file.
601 ;; These variants of the above insns can occur if the second operand
602 ;; is the frame pointer.  This is a kludge, but there doesn't
603 ;; seem to be a way around it.  Only recognize them while reloading.
605 ;; We must use reload_operand for some operands in case frame pointer
606 ;; elimination put a MEM with invalid address there.  Otherwise,
607 ;; the result of the substitution will not match this pattern, and reload
608 ;; will not be able to correctly fix the result.
610 ;; indexing longlongs or doubles (8 bytes)
612 (define_insn "indexdi_t"
613   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
614         (plus:SI (mult:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
615                           (const_int 8))
616                  (match_operand:SI 2 "mcore_arith_reg_operand" "0")))]
617   ""
618   "*
619     if (! mcore_is_same_reg (operands[1], operands[2]))
620       {
621         output_asm_insn (\"ixw\\t%0,%1\", operands);
622         output_asm_insn (\"ixw\\t%0,%1\", operands);
623       }
624     else
625       {
626         output_asm_insn (\"ixh\\t%0,%1\", operands);
627         output_asm_insn (\"ixh\\t%0,%1\", operands);
628       }
629     return \"\";
630   "
631 ;; if operands[1] == operands[2], the first option above is wrong! -- dac
632 ;; was this... -- dac
633 ;; ixw  %0,%1\;ixw      %0,%1"
635   [(set_attr "length" "4")])
637 (define_insn ""
638   [(set (match_operand:SI 0 "mcore_reload_operand" "=r,r,r")
639         (plus:SI (plus:SI (mult:SI (match_operand:SI 1 "mcore_reload_operand" "r,r,r")
640                                    (const_int 8))
641                           (match_operand:SI 2 "mcore_arith_reg_operand" "0,0,0"))
642                  (match_operand:SI 3 "mcore_addsub_operand" "r,J,L")))]
643   "reload_in_progress"
644   "@
645         ixw     %0,%1\;ixw      %0,%1\;addu     %0,%3
646         ixw     %0,%1\;ixw      %0,%1\;addi     %0,%3
647         ixw     %0,%1\;ixw      %0,%1\;subi     %0,%M3"
648   [(set_attr "length" "6")])
650 ;; indexing longs (4 bytes)
652 (define_insn "indexsi_t"
653   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
654         (plus:SI (mult:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
655                           (const_int 4))
656                  (match_operand:SI 2 "mcore_arith_reg_operand" "0")))]
657   ""
658   "ixw  %0,%1")
660 (define_insn ""
661   [(set (match_operand:SI 0 "mcore_reload_operand" "=r,r,r")
662         (plus:SI (plus:SI (mult:SI (match_operand:SI 1 "mcore_reload_operand" "r,r,r")
663                                    (const_int 4))
664                           (match_operand:SI 2 "mcore_arith_reg_operand" "0,0,0"))
665                  (match_operand:SI 3 "mcore_addsub_operand" "r,J,L")))]
666   "reload_in_progress"
667   "@
668         ixw     %0,%1\;addu     %0,%3
669         ixw     %0,%1\;addi     %0,%3
670         ixw     %0,%1\;subi     %0,%M3"
671   [(set_attr "length" "4")])
673 ;; indexing shorts (2 bytes)
675 (define_insn "indexhi_t"
676   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
677         (plus:SI (mult:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
678                           (const_int 2))
679                  (match_operand:SI 2 "mcore_arith_reg_operand" "0")))]
680   ""
681   "ixh  %0,%1")
683 (define_insn ""
684   [(set (match_operand:SI 0 "mcore_reload_operand" "=r,r,r")
685         (plus:SI (plus:SI (mult:SI (match_operand:SI 1 "mcore_reload_operand" "r,r,r")
686                                    (const_int 2))
687                           (match_operand:SI 2 "mcore_arith_reg_operand" "0,0,0"))
688                  (match_operand:SI 3 "mcore_addsub_operand" "r,J,L")))]
689   "reload_in_progress"
690   "@
691         ixh     %0,%1\;addu     %0,%3
692         ixh     %0,%1\;addi     %0,%3
693         ixh     %0,%1\;subi     %0,%M3"
694   [(set_attr "length" "4")])
697 ;; Other sizes may be handy for indexing. 
698 ;; the tradeoffs to consider when adding these are
699 ;;      code size, execution time [vs. mul it is easy to win],
700 ;;      and register pressure -- these patterns don't use an extra
701 ;;      register to build the offset from the base
702 ;;      and whether the compiler will not come up with some other idiom.
705 ;; -------------------------------------------------------------------------
706 ;; Addition, Subtraction instructions
707 ;; -------------------------------------------------------------------------
709 (define_expand "addsi3"
710   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
711         (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
712                  (match_operand:SI 2 "nonmemory_operand" "")))]
713   ""
714   "
716   extern int flag_omit_frame_pointer;
718   /* If this is an add to the frame pointer, then accept it as is so
719      that we can later fold in the fp/sp offset from frame pointer
720      elimination.  */
721   if (flag_omit_frame_pointer
722       && GET_CODE (operands[1]) == REG
723       && (REGNO (operands[1]) == VIRTUAL_STACK_VARS_REGNUM
724           || REGNO (operands[1]) == FRAME_POINTER_REGNUM))
725     {
726       emit_insn (gen_addsi3_fp (operands[0], operands[1], operands[2]));
727       DONE;
728     }
730   /* Convert adds to subtracts if this makes loading the constant cheaper.
731      But only if we are allowed to generate new pseudos.  */
732   if (! (reload_in_progress || reload_completed)
733       && GET_CODE (operands[2]) == CONST_INT
734       && INTVAL (operands[2]) < -32)
735     {
736       HOST_WIDE_INT neg_value = - INTVAL (operands[2]);
738       if (   CONST_OK_FOR_I (neg_value)
739           || CONST_OK_FOR_M (neg_value)
740           || CONST_OK_FOR_N (neg_value))
741         {
742           operands[2] = copy_to_mode_reg (SImode, GEN_INT (neg_value));
743           emit_insn (gen_subsi3 (operands[0], operands[1], operands[2]));
744           DONE;
745         }
746     } 
748   if (! mcore_addsub_operand (operands[2], SImode))
749     operands[2] = copy_to_mode_reg (SImode, operands[2]);
752 ;; RBE: for some constants which are not in the range which allows
753 ;; us to do a single operation, we will try a paired addi/addi instead
754 ;; of a movi/addi. This relieves some register pressure at the expense
755 ;; of giving away some potential constant reuse.
757 ;; RBE 6/17/97: this didn't buy us anything, but I keep the pattern
758 ;; for later reference
759 ;; 
760 ;; (define_insn "addsi3_i2"
761 ;;   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
762 ;;      (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
763 ;;               (match_operand:SI 2 "const_int_operand" "g")))]
764 ;;   "GET_CODE(operands[2]) == CONST_INT
765 ;;    && ((INTVAL (operands[2]) > 32 && INTVAL(operands[2]) <= 64)
766 ;;        || (INTVAL (operands[2]) < -32 && INTVAL(operands[2]) >= -64))"
767 ;;   "*
768 ;; {
769 ;;    HOST_WIDE_INT n = INTVAL(operands[2]);
770 ;;    if (n > 0)
771 ;;      {
772 ;;        operands[2] = GEN_INT(n - 32);
773 ;;        return \"addi\\t%0,32\;addi\\t%0,%2\";
774 ;;      }
775 ;;    else
776 ;;      {
777 ;;        n = (-n);
778 ;;        operands[2] = GEN_INT(n - 32);
779 ;;        return \"subi\\t%0,32\;subi\\t%0,%2\";
780 ;;      }
781 ;; }"
782 ;;  [(set_attr "length" "4")])
784 (define_insn "addsi3_i"
785   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r")
786         (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0,0,0")
787                  (match_operand:SI 2 "mcore_addsub_operand" "r,J,L")))]
788   ""
789   "@
790         addu    %0,%2
791         addi    %0,%2
792         subi    %0,%M2")
794 ;; This exists so that address computations based on the frame pointer
795 ;; can be folded in when frame pointer elimination occurs.  Ordinarily
796 ;; this would be bad because it allows insns which would require reloading,
797 ;; but without it, we get multiple adds where one would do.
799 (define_insn "addsi3_fp"
800   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r")
801         (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0,0,0")
802                  (match_operand:SI 2 "immediate_operand" "r,J,L")))]
803   "flag_omit_frame_pointer
804    && (reload_in_progress || reload_completed || REGNO (operands[1]) == FRAME_POINTER_REGNUM)"
805   "@
806         addu    %0,%2
807         addi    %0,%2
808         subi    %0,%M2")
810 ;; RBE: for some constants which are not in the range which allows
811 ;; us to do a single operation, we will try a paired addi/addi instead
812 ;; of a movi/addi. This relieves some register pressure at the expense
813 ;; of giving away some potential constant reuse.
815 ;; RBE 6/17/97: this didn't buy us anything, but I keep the pattern
816 ;; for later reference
817 ;; 
818 ;; (define_insn "subsi3_i2"
819 ;;   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
820 ;;      (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
821 ;;               (match_operand:SI 2 "const_int_operand" "g")))]
822 ;;   "TARGET_RBETEST && GET_CODE(operands[2]) == CONST_INT
823 ;;    && ((INTVAL (operands[2]) > 32 && INTVAL(operands[2]) <= 64)
824 ;;        || (INTVAL (operands[2]) < -32 && INTVAL(operands[2]) >= -64))"
825 ;;   "*
826 ;; {
827 ;;    HOST_WIDE_INT n = INTVAL(operands[2]);
828 ;;    if ( n > 0)
829 ;;      {
830 ;;        operands[2] = GEN_INT( n - 32);
831 ;;        return \"subi\\t%0,32\;subi\\t%0,%2\";
832 ;;      }
833 ;;    else
834 ;;      {
835 ;;        n = (-n);
836 ;;        operands[2] = GEN_INT(n - 32);
837 ;;        return \"addi\\t%0,32\;addi\\t%0,%2\";
838 ;;      }
839 ;; }"
840 ;;   [(set_attr "length" "4")])
842 ;(define_insn "subsi3"
843 ;  [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
844 ;       (minus:SI (match_operand:SI 1 "mcore_arith_K_operand" "0,0,r,K")
845 ;                 (match_operand:SI 2 "mcore_arith_J_operand" "r,J,0,0")))]
846 ;  ""
847 ;  "@
848 ;       sub     %0,%2
849 ;       subi    %0,%2
850 ;       rsub    %0,%1
851 ;       rsubi   %0,%1")
853 (define_insn "subsi3"
854   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r")
855         (minus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,0,r")
856                   (match_operand:SI 2 "mcore_arith_J_operand" "r,J,0")))]
857   ""
858   "@
859         subu    %0,%2
860         subi    %0,%2
861         rsub    %0,%1")
863 (define_insn ""
864   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
865         (minus:SI (match_operand:SI 1 "mcore_literal_K_operand" "K")
866                   (match_operand:SI 2 "mcore_arith_reg_operand" "0")))]
867   ""
868   "rsubi        %0,%1")
870 (define_insn "adddi3"
871   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
872         (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
873                  (match_operand:DI 2 "mcore_arith_reg_operand" "r")))
874    (clobber (reg:CC 17))]
875   ""
876   "*
877   {
878     if (TARGET_LITTLE_END)
879       return \"cmplt    %0,%0\;addc     %0,%2\;addc     %R0,%R2\";
880     return \"cmplt      %R0,%R0\;addc   %R0,%R2\;addc   %0,%2\";
881   }"
882   [(set_attr "length" "6")])
884 ;; special case for "longlong += 1"
885 (define_insn ""
886   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
887         (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")
888                  (const_int 1)))
889    (clobber (reg:CC 17))]
890   ""
891   "*
892   {
893    if (TARGET_LITTLE_END)
894       return \"addi     %0,1\;cmpnei %0,0\;incf %R0\";
895     return \"addi       %R0,1\;cmpnei %R0,0\;incf       %0\";
896   }"
897   [(set_attr "length" "6")])
899 ;; special case for "longlong -= 1"
900 (define_insn ""
901   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
902         (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")
903                  (const_int -1)))
904    (clobber (reg:CC 17))]
905   ""
906   "*
907   {
908     if (TARGET_LITTLE_END)
909        return \"cmpnei %0,0\;decf       %R0\;subi       %0,1\";
910     return \"cmpnei %R0,0\;decf %0\;subi        %R0,1\";
911   }"
912   [(set_attr "length" "6")])
914 ;; special case for "longlong += const_int"
915 ;; we have to use a register for the const_int because we don't
916 ;; have an unsigned compare immediate... only +/- 1 get to
917 ;; play the no-extra register game because they compare with 0.
918 ;; This winds up working out for any literal that is synthesized
919 ;; with a single instruction. The more complicated ones look
920 ;; like the get broken into subreg's to get initialized too soon
921 ;; for us to catch here. -- RBE 4/25/96
922 ;; only allow for-sure positive values.
924 (define_insn ""
925   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
926         (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")
927                  (match_operand:SI 2 "const_int_operand" "r")))
928    (clobber (reg:CC 17))]
929   "GET_CODE (operands[2]) == CONST_INT
930    && INTVAL (operands[2]) > 0 && ! (INTVAL (operands[2]) & 0x80000000)"
931   "*
933   gcc_assert (GET_MODE (operands[2]) == SImode);
934   if (TARGET_LITTLE_END)
935     return \"addu       %0,%2\;cmphs    %0,%2\;incf     %R0\";
936   return \"addu %R0,%2\;cmphs   %R0,%2\;incf    %0\";
938   [(set_attr "length" "6")])
940 ;; optimize "long long" + "unsigned long"
941 ;; won't trigger because of how the extension is expanded upstream.
942 ;; (define_insn ""
943 ;;   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
944 ;;      (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
945 ;;               (zero_extend:DI (match_operand:SI 2 "mcore_arith_reg_operand" "r"))))
946 ;;    (clobber (reg:CC 17))]
947 ;;   "0"
948 ;;   "cmplt     %R0,%R0\;addc   %R0,%2\;inct    %0"
949 ;;   [(set_attr "length" "6")])
951 ;; optimize "long long" + "signed long"
952 ;; won't trigger because of how the extension is expanded upstream.
953 ;; (define_insn ""
954 ;;   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
955 ;;      (plus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "%0")
956 ;;               (sign_extend:DI (match_operand:SI 2 "mcore_arith_reg_operand" "r"))))
957 ;;    (clobber (reg:CC 17))]
958 ;;   "0"
959 ;;   "cmplt     %R0,%R0\;addc   %R0,%2\;inct    %0\;btsti       %2,31\;dect     %0"
960 ;;   [(set_attr "length" "6")])
962 (define_insn "subdi3"
963   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
964         (minus:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")
965                   (match_operand:DI 2 "mcore_arith_reg_operand" "r")))
966    (clobber (reg:CC 17))]
967   ""
968   "*
969   {
970     if (TARGET_LITTLE_END)
971       return \"cmphs    %0,%0\;subc     %0,%2\;subc     %R0,%R2\";
972     return \"cmphs      %R0,%R0\;subc   %R0,%R2\;subc   %0,%2\";
973   }"
974   [(set_attr "length" "6")])
976 ;; -------------------------------------------------------------------------
977 ;; Multiplication instructions
978 ;; -------------------------------------------------------------------------
980 (define_insn "mulsi3"
981   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
982         (mult:SI (match_operand:SI 1 "mcore_arith_reg_operand" "%0")
983                  (match_operand:SI 2 "mcore_arith_reg_operand" "r")))]
984   ""
985   "mult %0,%2")
988 ;; 32/32 signed division -- added to the MCORE instruction set spring 1997
990 ;; Different constraints based on the architecture revision...
992 (define_expand "divsi3"
993   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
994         (div:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
995                 (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
996   "TARGET_DIV"
997   "")
999 ;; MCORE Revision 1.50: restricts the divisor to be in r1. (6/97)
1001 (define_insn ""
1002   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1003         (div:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
1004                 (match_operand:SI 2 "mcore_arith_reg_operand" "b")))]
1005   "TARGET_DIV"
1006   "divs %0,%2")
1009 ;; 32/32 signed division -- added to the MCORE instruction set spring 1997
1011 ;; Different constraints based on the architecture revision...
1013 (define_expand "udivsi3"
1014   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1015         (udiv:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
1016                  (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
1017   "TARGET_DIV"
1018   "")
1020 ;; MCORE Revision 1.50: restricts the divisor to be in r1. (6/97)
1021 (define_insn ""
1022   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1023         (udiv:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
1024                  (match_operand:SI 2 "mcore_arith_reg_operand" "b")))]
1025   "TARGET_DIV"
1026   "divu %0,%2")
1028 ;; -------------------------------------------------------------------------
1029 ;; Unary arithmetic
1030 ;; -------------------------------------------------------------------------
1032 (define_insn "negsi2"
1033   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1034         (neg:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")))]
1035   ""
1036   "*
1038    return \"rsubi       %0,0\";
1042 (define_insn "abssi2"
1043   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1044         (abs:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")))]
1045   ""
1046   "abs  %0")
1047              
1048 (define_insn "negdi2"
1049   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=&r")
1050         (neg:DI (match_operand:DI 1 "mcore_arith_reg_operand" "0")))
1051    (clobber (reg:CC 17))]
1052   ""
1053   "*
1055    if (TARGET_LITTLE_END)
1056      return \"cmpnei    %0,0\\n\\trsubi %0,0\\n\\tnot   %R0\\n\\tincf   %R0\";
1057    return \"cmpnei      %R0,0\\n\\trsubi        %R0,0\\n\\tnot  %0\\n\\tincf    %0\";
1059   [(set_attr "length" "8")])
1061 (define_insn "one_cmplsi2"
1062   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1063         (not:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")))]
1064   ""
1065   "not  %0")
1067 ;; -------------------------------------------------------------------------
1068 ;; Zero extension instructions
1069 ;; -------------------------------------------------------------------------
1071 (define_expand "zero_extendhisi2"
1072   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1073         (zero_extend:SI (match_operand:HI 1 "mcore_arith_reg_operand" "")))]
1074   ""
1075   "")
1077 (define_insn ""
1078   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r")
1079         (zero_extend:SI (match_operand:HI 1 "general_operand" "0,m")))]
1080   ""
1081   "@
1082         zexth   %0
1083         ld.h    %0,%1"
1084   [(set_attr "type" "shift,load")])
1086 ;; ldh gives us a free zero-extension. The combiner picks up on this.
1087 (define_insn ""
1088   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1089         (zero_extend:SI (mem:HI (match_operand:SI 1 "mcore_arith_reg_operand" "r"))))]
1090   ""
1091   "ld.h %0,(%1)"
1092   [(set_attr "type" "load")])
1094 (define_insn ""
1095   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1096         (zero_extend:SI (mem:HI (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
1097                                          (match_operand:SI 2 "const_int_operand" "")))))]
1098   "(INTVAL (operands[2]) >= 0) &&
1099    (INTVAL (operands[2]) < 32) &&
1100    ((INTVAL (operands[2])&1) == 0)"
1101   "ld.h %0,(%1,%2)"
1102   [(set_attr "type" "load")])
1104 (define_expand "zero_extendqisi2"
1105   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1106         (zero_extend:SI (match_operand:QI 1 "general_operand" "")))]
1107   ""
1108   "") 
1110 ;; RBE: XXX: we don't recognize that the xtrb3 kills the CC register.
1111 (define_insn ""
1112   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,b,r")
1113         (zero_extend:SI (match_operand:QI 1 "general_operand" "0,r,m")))]
1114   ""
1115   "@
1116         zextb   %0
1117         xtrb3   %0,%1
1118         ld.b    %0,%1"
1119   [(set_attr "type" "shift,shift,load")])
1121 ;; ldb gives us a free zero-extension. The combiner picks up on this.
1122 (define_insn ""
1123   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1124         (zero_extend:SI (mem:QI (match_operand:SI 1 "mcore_arith_reg_operand" "r"))))]
1125   ""
1126   "ld.b %0,(%1)"
1127   [(set_attr "type" "load")])
1129 (define_insn ""
1130   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1131         (zero_extend:SI (mem:QI (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
1132                                          (match_operand:SI 2 "const_int_operand" "")))))]
1133   "(INTVAL (operands[2]) >= 0) &&
1134    (INTVAL (operands[2]) < 16)"
1135   "ld.b %0,(%1,%2)"
1136   [(set_attr "type" "load")])
1138 (define_expand "zero_extendqihi2"
1139   [(set (match_operand:HI 0 "mcore_arith_reg_operand" "")
1140         (zero_extend:HI (match_operand:QI 1 "general_operand" "")))]
1141   ""
1142   "") 
1144 ;; RBE: XXX: we don't recognize that the xtrb3 kills the CC register.
1145 (define_insn ""
1146   [(set (match_operand:HI 0 "mcore_arith_reg_operand" "=r,b,r")
1147         (zero_extend:HI (match_operand:QI 1 "general_operand" "0,r,m")))]
1148   ""
1149   "@
1150         zextb   %0
1151         xtrb3   %0,%1
1152         ld.b    %0,%1"
1153   [(set_attr "type" "shift,shift,load")])
1155 ;; ldb gives us a free zero-extension. The combiner picks up on this.
1156 ;; this doesn't catch references that are into a structure.
1157 ;; note that normally the compiler uses the above insn, unless it turns
1158 ;; out that we're dealing with a volatile...
1159 (define_insn ""
1160   [(set (match_operand:HI 0 "mcore_arith_reg_operand" "=r")
1161         (zero_extend:HI (mem:QI (match_operand:SI 1 "mcore_arith_reg_operand" "r"))))]
1162   ""
1163   "ld.b %0,(%1)"
1164   [(set_attr "type" "load")])
1166 (define_insn ""
1167   [(set (match_operand:HI 0 "mcore_arith_reg_operand" "=r")
1168         (zero_extend:HI (mem:QI (plus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r")
1169                                          (match_operand:SI 2 "const_int_operand" "")))))]
1170   "(INTVAL (operands[2]) >= 0) &&
1171    (INTVAL (operands[2]) < 16)"
1172   "ld.b %0,(%1,%2)"
1173   [(set_attr "type" "load")])
1176 ;; -------------------------------------------------------------------------
1177 ;; Sign extension instructions
1178 ;; -------------------------------------------------------------------------
1180 (define_expand "extendsidi2"
1181   [(set (match_operand:DI 0 "mcore_arith_reg_operand" "=r") 
1182         (match_operand:SI 1 "mcore_arith_reg_operand" "r"))]
1183   ""
1184   "
1185   {
1186     int low, high;
1188     if (TARGET_LITTLE_END)
1189       low = 0, high = 4;
1190     else
1191       low = 4, high = 0;
1192     
1193     emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], low),
1194               operands[1]));
1195     emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], high),
1196               gen_rtx_ASHIFTRT (SImode,
1197                                gen_rtx_SUBREG (SImode, operands[0], low),
1198                                GEN_INT (31))));
1199     DONE;
1200   }"
1203 (define_insn "extendhisi2"
1204   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1205         (sign_extend:SI (match_operand:HI 1 "mcore_arith_reg_operand" "0")))]
1206   ""
1207   "sexth        %0")
1209 (define_insn "extendqisi2"
1210   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1211         (sign_extend:SI (match_operand:QI 1 "mcore_arith_reg_operand" "0")))]
1212   ""
1213   "sextb        %0")
1215 (define_insn "extendqihi2"
1216   [(set (match_operand:HI 0 "mcore_arith_reg_operand" "=r")
1217         (sign_extend:HI (match_operand:QI 1 "mcore_arith_reg_operand" "0")))]
1218   ""
1219   "sextb        %0")
1221 ;; -------------------------------------------------------------------------
1222 ;; Move instructions
1223 ;; -------------------------------------------------------------------------
1225 ;; SImode
1227 (define_expand "movsi"
1228   [(set (match_operand:SI 0 "general_operand" "")
1229         (match_operand:SI 1 "general_operand" ""))]
1230   ""
1231   "
1233   if (GET_CODE (operands[0]) == MEM)
1234     operands[1] = force_reg (SImode, operands[1]);
1237 (define_insn ""
1238   [(set (match_operand:SI 0 "mcore_general_movdst_operand" "=r,r,a,r,a,r,m")
1239         (match_operand:SI 1 "mcore_general_movsrc_operand"  "r,P,i,c,R,m,r"))]
1240   "(register_operand (operands[0], SImode)
1241     || register_operand (operands[1], SImode))"
1242   "* return mcore_output_move (insn, operands, SImode);"
1243   [(set_attr "type" "move,move,move,move,load,load,store")])
1246 ;; HImode
1249 (define_expand "movhi"
1250   [(set (match_operand:HI 0 "general_operand" "")
1251         (match_operand:HI 1 "general_operand"  ""))]
1252   ""
1253   "
1255   if (GET_CODE (operands[0]) == MEM)
1256     operands[1] = force_reg (HImode, operands[1]);
1257   else if (CONSTANT_P (operands[1])
1258            && (GET_CODE (operands[1]) != CONST_INT
1259                || (! CONST_OK_FOR_I (INTVAL (operands[1]))
1260                    && ! CONST_OK_FOR_M (INTVAL (operands[1]))
1261                    && ! CONST_OK_FOR_N (INTVAL (operands[1]))))
1262            && ! reload_completed && ! reload_in_progress)
1263     {
1264       rtx reg = gen_reg_rtx (SImode);
1265       emit_insn (gen_movsi (reg, operands[1]));
1266       operands[1] = gen_lowpart (HImode, reg);
1267     }
1269   
1270 (define_insn ""
1271   [(set (match_operand:HI 0 "mcore_general_movdst_operand" "=r,r,a,r,r,m")
1272         (match_operand:HI 1 "mcore_general_movsrc_operand"  "r,P,i,c,m,r"))]
1273   "(register_operand (operands[0], HImode)
1274     || register_operand (operands[1], HImode))"
1275   "* return mcore_output_move (insn, operands, HImode);"
1276   [(set_attr "type" "move,move,move,move,load,store")])
1279 ;; QImode
1282 (define_expand "movqi"
1283   [(set (match_operand:QI 0 "general_operand" "")
1284         (match_operand:QI 1 "general_operand"  ""))]
1285   ""
1286   "
1288   if (GET_CODE (operands[0]) == MEM)
1289     operands[1] = force_reg (QImode, operands[1]);
1290   else if (CONSTANT_P (operands[1])
1291            && (GET_CODE (operands[1]) != CONST_INT
1292                || (! CONST_OK_FOR_I (INTVAL (operands[1]))
1293                    && ! CONST_OK_FOR_M (INTVAL (operands[1]))
1294                    && ! CONST_OK_FOR_N (INTVAL (operands[1]))))
1295            && ! reload_completed && ! reload_in_progress)
1296     {
1297       rtx reg = gen_reg_rtx (SImode);
1298       emit_insn (gen_movsi (reg, operands[1]));
1299       operands[1] = gen_lowpart (QImode, reg);
1300     }
1302   
1303 (define_insn ""
1304   [(set (match_operand:QI 0 "mcore_general_movdst_operand" "=r,r,a,r,r,m")
1305         (match_operand:QI 1 "mcore_general_movsrc_operand"  "r,P,i,c,m,r"))]
1306   "(register_operand (operands[0], QImode)
1307     || register_operand (operands[1], QImode))"
1308   "* return mcore_output_move (insn, operands, QImode);"
1309    [(set_attr "type" "move,move,move,move,load,store")])
1312 ;; DImode
1314 (define_expand "movdi"
1315   [(set (match_operand:DI 0 "general_operand" "")
1316         (match_operand:DI 1 "general_operand" ""))]
1317   ""
1318   "
1320   if (GET_CODE (operands[0]) == MEM)
1321     operands[1] = force_reg (DImode, operands[1]);
1322   else if (GET_CODE (operands[1]) == CONST_INT
1323            && ! CONST_OK_FOR_I (INTVAL (operands[1]))
1324            && ! CONST_OK_FOR_M (INTVAL (operands[1]))
1325            && ! CONST_OK_FOR_N (INTVAL (operands[1])))
1326     {
1327       int i;
1328       for (i = 0; i < UNITS_PER_WORD * 2; i += UNITS_PER_WORD)
1329         emit_move_insn (simplify_gen_subreg (SImode, operands[0], DImode, i),
1330                         simplify_gen_subreg (SImode, operands[1], DImode, i));
1331       DONE;
1332     }
1335 (define_insn "movdi_i"
1336   [(set (match_operand:DI 0 "general_operand" "=r,r,r,r,a,r,m")
1337         (match_operand:DI 1 "mcore_general_movsrc_operand" "I,M,N,r,R,m,r"))]
1338   ""
1339   "* return mcore_output_movedouble (operands, DImode);"
1340   [(set_attr "length" "4") (set_attr "type" "move,move,move,move,load,load,store")])
1342 ;; SFmode
1344 (define_expand "movsf"
1345   [(set (match_operand:SF 0 "general_operand" "")
1346         (match_operand:SF 1 "general_operand" ""))]
1347   ""
1348   "
1350   if (GET_CODE (operands[0]) == MEM)
1351     operands[1] = force_reg (SFmode, operands[1]);
1354 (define_insn "movsf_i"
1355   [(set (match_operand:SF 0 "general_operand" "=r,r,m")
1356         (match_operand:SF 1 "general_operand"  "r,m,r"))]
1357   ""
1358   "@
1359         mov     %0,%1
1360         ld.w    %0,%1
1361         st.w    %1,%0"
1362   [(set_attr "type" "move,load,store")])
1364 ;; DFmode
1366 (define_expand "movdf"
1367   [(set (match_operand:DF 0 "general_operand" "")
1368         (match_operand:DF 1 "general_operand" ""))]
1369   ""
1370   "
1372   if (GET_CODE (operands[0]) == MEM)
1373     operands[1] = force_reg (DFmode, operands[1]);
1376 (define_insn "movdf_k"
1377   [(set (match_operand:DF 0 "general_operand" "=r,r,m")
1378         (match_operand:DF 1 "general_operand" "r,m,r"))]
1379   ""
1380   "* return mcore_output_movedouble (operands, DFmode);"
1381   [(set_attr "length" "4") (set_attr "type" "move,load,store")])
1384 ;; Load/store multiple
1386 ;; ??? This is not currently used.
1387 (define_insn "ldm"
1388   [(set (match_operand:TI 0 "mcore_arith_reg_operand" "=r")
1389         (mem:TI (match_operand:SI 1 "mcore_arith_reg_operand" "r")))]
1390   ""
1391   "ldq  %U0,(%1)")
1393 ;; ??? This is not currently used.
1394 (define_insn "stm"
1395   [(set (mem:TI (match_operand:SI 0 "mcore_arith_reg_operand" "r"))
1396         (match_operand:TI 1 "mcore_arith_reg_operand" "r"))]
1397   ""
1398   "stq  %U1,(%0)")
1400 (define_expand "load_multiple"
1401   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
1402                           (match_operand:SI 1 "" ""))
1403                      (use (match_operand:SI 2 "" ""))])]
1404   ""
1405   "
1407   int regno, count, i;
1409   /* Support only loading a constant number of registers from memory and
1410      only if at least two registers.  The last register must be r15.  */
1411   if (GET_CODE (operands[2]) != CONST_INT
1412       || INTVAL (operands[2]) < 2
1413       || GET_CODE (operands[1]) != MEM
1414       || XEXP (operands[1], 0) != stack_pointer_rtx
1415       || GET_CODE (operands[0]) != REG
1416       || REGNO (operands[0]) + INTVAL (operands[2]) != 16)
1417     FAIL;
1419   count = INTVAL (operands[2]);
1420   regno = REGNO (operands[0]);
1422   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
1424   for (i = 0; i < count; i++)
1425     XVECEXP (operands[3], 0, i)
1426       = gen_rtx_SET (VOIDmode,
1427                  gen_rtx_REG (SImode, regno + i),
1428                  gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx,
1429                                                       i * 4)));
1432 (define_insn ""
1433   [(match_parallel 0 "mcore_load_multiple_operation"
1434                    [(set (match_operand:SI 1 "mcore_arith_reg_operand" "=r")
1435                          (mem:SI (match_operand:SI 2 "register_operand" "r")))])]
1436   "GET_CODE (operands[2]) == REG && REGNO (operands[2]) == STACK_POINTER_REGNUM"
1437   "ldm  %1-r15,(%2)")
1439 (define_expand "store_multiple"
1440   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
1441                           (match_operand:SI 1 "" ""))
1442                      (use (match_operand:SI 2 "" ""))])]
1443   ""
1444   "
1446   int regno, count, i;
1448   /* Support only storing a constant number of registers to memory and
1449      only if at least two registers.  The last register must be r15.  */
1450   if (GET_CODE (operands[2]) != CONST_INT
1451       || INTVAL (operands[2]) < 2
1452       || GET_CODE (operands[0]) != MEM
1453       || XEXP (operands[0], 0) != stack_pointer_rtx
1454       || GET_CODE (operands[1]) != REG
1455       || REGNO (operands[1]) + INTVAL (operands[2]) != 16)
1456     FAIL;
1458   count = INTVAL (operands[2]);
1459   regno = REGNO (operands[1]);
1461   operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
1463   for (i = 0; i < count; i++)
1464     XVECEXP (operands[3], 0, i)
1465       = gen_rtx_SET (VOIDmode,
1466                  gen_rtx_MEM (SImode, plus_constant (stack_pointer_rtx,
1467                                                       i * 4)),
1468                  gen_rtx_REG (SImode, regno + i));
1471 (define_insn ""
1472   [(match_parallel 0 "mcore_store_multiple_operation"
1473                    [(set (mem:SI (match_operand:SI 2 "register_operand" "r"))
1474                          (match_operand:SI 1 "mcore_arith_reg_operand" "r"))])]
1475   "GET_CODE (operands[2]) == REG && REGNO (operands[2]) == STACK_POINTER_REGNUM"
1476   "stm  %1-r15,(%2)")
1478 ;; ------------------------------------------------------------------------
1479 ;; Define the real conditional branch instructions.
1480 ;; ------------------------------------------------------------------------
1482 (define_insn "branch_true"
1483   [(set (pc) (if_then_else (ne (reg:CC 17) (const_int 0))
1484                            (label_ref (match_operand 0 "" ""))
1485                            (pc)))]
1486   ""
1487   "jbt  %l0"
1488   [(set_attr "type" "brcond")])
1490 (define_insn "branch_false"
1491   [(set (pc) (if_then_else (eq (reg:CC 17) (const_int 0))
1492                            (label_ref (match_operand 0 "" ""))
1493                            (pc)))]
1494   ""
1495   "jbf  %l0"
1496   [(set_attr "type" "brcond")])
1498 (define_insn "inverse_branch_true"
1499   [(set (pc) (if_then_else (ne (reg:CC 17) (const_int 0))
1500                            (pc)
1501                            (label_ref (match_operand 0 "" ""))))]
1502   ""
1503   "jbf  %l0"
1504   [(set_attr "type" "brcond")])
1506 (define_insn "inverse_branch_false"
1507   [(set (pc) (if_then_else (eq (reg:CC 17) (const_int 0))
1508                            (pc)
1509                            (label_ref (match_operand 0 "" ""))))]
1510   ""
1511   "jbt  %l0"
1512   [(set_attr "type" "brcond")])
1514 ;; Conditional branch insns
1516 ;; At top-level, condition test are eq/ne, because we
1517 ;; are comparing against the condition register (which
1518 ;; has the result of the true relational test
1520 ; There is no beq compare, so we reverse the branch arms.
1522 (define_expand "beq"
1523   [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1524                            (pc)
1525                            (label_ref (match_operand 0 "" ""))))]
1526   ""
1527   "
1529   operands[1] = mcore_gen_compare_reg (EQ);
1532 (define_expand "bne"
1533   [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1534                            (label_ref (match_operand 0 "" ""))
1535                            (pc)))]
1536   ""
1537   "
1539   operands[1] = mcore_gen_compare_reg (NE);
1542 ; check whether (GT A imm) can become (LE A imm) with the branch reversed.  
1543 ; if so, emit a (LT A imm + 1) in place of the (LE A imm).  BRC
1545 (define_expand "bgt"
1546   [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1547                            (label_ref (match_operand 0 "" ""))
1548                            (pc)))]
1549   ""
1550   "
1552   if (mcore_modify_comparison (LE))
1553     {
1554       emit_jump_insn (gen_reverse_blt (operands[0]));
1555       DONE;
1556     }
1557   operands[1] = mcore_gen_compare_reg (GT);
1560 ; There is no ble compare, so we reverse the branch arms.
1561 ; reversed the condition and branch arms for ble -- the check_dbra_loop()
1562 ; transformation assumes that ble uses a branch-true with the label as
1563 ; as the target. BRC
1565 ; check whether (LE A imm) can become (LT A imm + 1).
1567 (define_expand "ble"
1568   [(set (pc) (if_then_else (eq (match_dup 1) (const_int 0))
1569                            (label_ref (match_operand 0 "" ""))
1570                            (pc)))]
1571   ""
1572   "
1574   if (mcore_modify_comparison (LE))
1575     {
1576       emit_jump_insn (gen_blt (operands[0]));
1577       DONE;
1578     }
1579   operands[1] = mcore_gen_compare_reg (LE);
1582 ; make generating a reversed blt simple
1583 (define_expand "reverse_blt"
1584   [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1585                            (pc)
1586                            (label_ref (match_operand 0 "" ""))))]
1587   ""
1588   "
1590   operands[1] = mcore_gen_compare_reg (LT);
1593 (define_expand "blt"
1594   [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1595                            (label_ref (match_operand 0 "" ""))
1596                            (pc)))]
1597   ""
1598   "
1600   operands[1] = mcore_gen_compare_reg (LT);
1603 ; There is no bge compare, so we reverse the branch arms.
1605 (define_expand "bge"
1606   [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1607                            (pc)
1608                            (label_ref (match_operand 0 "" ""))))]
1609   ""
1610   "
1612   operands[1] = mcore_gen_compare_reg (GE);
1615 ; There is no gtu compare, so we reverse the branch arms
1617 ;(define_expand "bgtu"
1618 ;  [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1619 ;                          (pc)
1620 ;                          (label_ref (match_operand 0 "" ""))))]
1621 ;  ""
1622 ;  "
1624 ;  if (GET_CODE (arch_compare_op1) == CONST_INT
1625 ;      && INTVAL (arch_compare_op1) == 0)
1626 ;    operands[1] = mcore_gen_compare_reg (NE);
1627 ;  else 
1628 ;    { if (mcore_modify_comparison (GTU))
1629 ;       {
1630 ;         emit_jump_insn (gen_bgeu (operands[0]));
1631 ;         DONE;
1632 ;       }
1633 ;      operands[1] = mcore_gen_compare_reg (LEU);
1634 ;    }
1635 ;}")
1637 (define_expand "bgtu"
1638   [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1639                            (pc)
1640                            (label_ref (match_operand 0 "" ""))))]
1641   ""
1642   "
1644   if (GET_CODE (arch_compare_op1) == CONST_INT
1645       && INTVAL (arch_compare_op1) == 0)
1646     {
1647       /* The inverse of '> 0' for an unsigned test is
1648          '== 0' but we do not have such an instruction available.
1649          Instead we must reverse the branch (back to the normal
1650          ordering) and test '!= 0'.  */
1651          
1652       operands[1] = mcore_gen_compare_reg (NE);
1653       
1654       emit_jump_insn (gen_rtx_SET (VOIDmode,
1655         pc_rtx,
1656         gen_rtx_IF_THEN_ELSE (VOIDmode,
1657         gen_rtx_NE (VOIDmode,
1658         operands[1],
1659         const0_rtx),
1660         gen_rtx_LABEL_REF (VOIDmode,operands[0]),
1661         pc_rtx)));
1662       DONE;           
1663     }
1664   operands[1] = mcore_gen_compare_reg (GTU);
1668 (define_expand "bleu"
1669   [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1670                            (label_ref (match_operand 0 "" ""))
1671                            (pc)))]
1672   ""
1673   "
1675   operands[1] = mcore_gen_compare_reg (LEU);
1678 ; There is no bltu compare, so we reverse the branch arms
1679 (define_expand "bltu"
1680   [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1681                            (pc)
1682                            (label_ref (match_operand 0 "" ""))))]
1683   ""
1684   "
1686   operands[1] = mcore_gen_compare_reg (LTU);
1689 (define_expand "bgeu"
1690   [(set (pc) (if_then_else (ne (match_dup 1) (const_int 0))
1691                            (label_ref (match_operand 0 "" ""))
1692                            (pc)))]
1693   ""
1694   "
1697   operands[1] = mcore_gen_compare_reg (GEU);
1700 ;; ------------------------------------------------------------------------
1701 ;; Jump and linkage insns
1702 ;; ------------------------------------------------------------------------
1704 (define_insn "jump_real"
1705   [(set (pc)
1706         (label_ref (match_operand 0 "" "")))]
1707   ""
1708   "jbr  %l0"
1709   [(set_attr "type" "branch")])
1711 (define_expand "jump"
1712  [(set (pc) (label_ref (match_operand 0 "" "")))]
1713  ""
1716   emit_jump_insn (gen_jump_real (operand0));
1717   DONE;
1721 (define_insn "indirect_jump"
1722   [(set (pc)
1723         (match_operand:SI 0 "mcore_arith_reg_operand" "r"))]
1724   ""
1725   "jmp  %0"
1726   [(set_attr "type" "jmp")])
1728 (define_expand "call"
1729   [(parallel[(call (match_operand:SI 0 "" "")
1730                    (match_operand 1 "" ""))
1731              (clobber (reg:SI 15))])]
1732   ""
1733   "
1735   if (GET_CODE (operands[0]) == MEM
1736       && ! register_operand (XEXP (operands[0], 0), SImode)
1737       && ! mcore_symbolic_address_p (XEXP (operands[0], 0)))
1738     operands[0] = gen_rtx_MEM (GET_MODE (operands[0]),
1739                            force_reg (Pmode, XEXP (operands[0], 0)));
1742 (define_insn "call_internal"
1743   [(call (mem:SI (match_operand:SI 0 "mcore_call_address_operand" "riR"))
1744          (match_operand 1 "" ""))
1745    (clobber (reg:SI 15))]
1746   ""
1747   "* return mcore_output_call (operands, 0);")
1749 (define_expand "call_value"
1750   [(parallel[(set (match_operand 0 "register_operand" "")
1751                   (call (match_operand:SI 1 "" "")
1752                         (match_operand 2 "" "")))
1753              (clobber (reg:SI 15))])]
1754   ""
1755   "
1757   if (GET_CODE (operands[0]) == MEM
1758       && ! register_operand (XEXP (operands[0], 0), SImode)
1759       && ! mcore_symbolic_address_p (XEXP (operands[0], 0)))
1760     operands[1] = gen_rtx_MEM (GET_MODE (operands[1]),
1761                            force_reg (Pmode, XEXP (operands[1], 0)));
1764 (define_insn "call_value_internal"
1765   [(set (match_operand 0 "register_operand" "=r")
1766         (call (mem:SI (match_operand:SI 1 "mcore_call_address_operand" "riR"))
1767               (match_operand 2 "" "")))
1768    (clobber (reg:SI 15))]
1769   ""
1770   "* return mcore_output_call (operands, 1);")
1772 (define_insn "call_value_struct"
1773   [(parallel [(set (match_parallel 0 ""
1774                      [(expr_list (match_operand 3 "register_operand" "") (match_operand 4 "immediate_operand" ""))
1775                       (expr_list (match_operand 5 "register_operand" "") (match_operand 6 "immediate_operand" ""))])
1776                   (call (match_operand:SI 1 "" "")
1777                         (match_operand 2 "" "")))
1778              (clobber (reg:SI 15))])]
1779   ""
1780   "* return mcore_output_call (operands, 1);"
1784 ;; ------------------------------------------------------------------------
1785 ;; Misc insns
1786 ;; ------------------------------------------------------------------------
1788 (define_insn "nop"
1789   [(const_int 0)]
1790   ""
1791   "or   r0,r0")
1793 (define_insn "tablejump"
1794   [(set (pc)
1795         (match_operand:SI 0 "mcore_arith_reg_operand" "r"))
1796    (use (label_ref (match_operand 1 "" "")))]
1797   ""
1798   "jmp  %0"
1799   [(set_attr "type" "jmp")])
1801 (define_insn "*return"
1802  [(return)]
1803  "reload_completed && ! mcore_naked_function_p ()"
1804  "jmp   r15"
1805  [(set_attr "type" "jmp")])
1807 (define_insn "*no_return"
1808  [(return)]
1809  "reload_completed && mcore_naked_function_p ()"
1810  ""
1811  [(set_attr "length" "0")]
1814 (define_expand "prologue"
1815   [(const_int 0)]
1816   ""
1817   "mcore_expand_prolog (); DONE;")
1819 (define_expand "epilogue"
1820   [(return)]
1821   ""
1822   "mcore_expand_epilog ();")
1824 ;; ------------------------------------------------------------------------
1825 ;; Scc instructions
1826 ;; ------------------------------------------------------------------------
1828 (define_insn "mvc"
1829   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1830         (ne:SI (reg:CC 17) (const_int 0)))]
1831   ""
1832   "mvc  %0"
1833   [(set_attr "type" "move")])
1835 (define_insn "mvcv"
1836   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1837         (eq:SI (reg:CC 17) (const_int 0)))]
1838   ""
1839   "mvcv %0"
1840   [(set_attr "type" "move")])
1842 ; in 0.97 use (LE 0) with (LT 1) and complement c.  BRC
1843 (define_split 
1844   [(parallel[
1845      (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1846           (ne:SI (gt:CC (match_operand:SI 1 "mcore_arith_reg_operand" "")
1847                         (const_int 0))
1848                  (const_int 0)))
1849      (clobber (reg:SI 17))])]
1850   ""
1851   [(set (reg:CC 17)
1852         (lt:CC (match_dup 1) (const_int 1)))
1853    (set (match_dup 0) (eq:SI (reg:CC 17) (const_int 0)))])
1854      
1856 (define_expand "seq"
1857   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1858         (eq:SI (match_dup 1) (const_int 0)))]
1859   ""
1860   "
1862   operands[1] = mcore_gen_compare_reg (NE);
1865 (define_expand "sne"
1866   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1867         (ne:SI (match_dup 1) (const_int 0)))]
1868   ""
1869   "
1871   operands[1] = mcore_gen_compare_reg (NE);
1874 (define_expand "slt"
1875   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1876         (ne:SI (match_dup 1) (const_int 0)))]
1877   ""
1878   "
1880   operands[1] = mcore_gen_compare_reg (LT);
1883 ; make generating a LT with the comparison reversed easy.  BRC
1884 (define_expand "reverse_slt"
1885   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1886         (eq:SI (match_dup 1) (const_int 0)))]
1887   ""
1888   "
1890   operands[1] = mcore_gen_compare_reg (LT);
1893 (define_expand "sge"
1894   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1895         (eq:SI (match_dup 1) (const_int 0)))]
1896   ""
1897   "
1899   operands[1] = mcore_gen_compare_reg (LT);
1902 ; check whether (GT A imm) can become (LE A imm) with the comparison
1903 ; reversed.  if so, emit a (LT A imm + 1) in place of the (LE A imm).  BRC
1905 (define_expand "sgt"
1906   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1907         (ne:SI (match_dup 1) (const_int 0)))]
1908   ""
1909   "
1911   if (mcore_modify_comparison (LE))
1912     {
1913       emit_insn (gen_reverse_slt (operands[0]));
1914       DONE;
1915     }
1916   
1917   operands[1] = mcore_gen_compare_reg (GT);
1920 (define_expand "sle"
1921   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1922         (eq:SI (match_dup 1) (const_int 0)))]
1923   ""
1924   "
1926   if (mcore_modify_comparison (LE))
1927     {
1928       emit_insn (gen_slt (operands[0]));
1929       DONE;
1930     }
1931   operands[1] = mcore_gen_compare_reg (GT);
1934 (define_expand "sltu"
1935   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1936         (eq:SI (match_dup 1) (const_int 0)))]
1937   ""
1938   "
1940   operands[1] = mcore_gen_compare_reg (GEU);
1943 (define_expand "sgeu"
1944   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1945         (ne:SI (match_dup 1) (const_int 0)))]
1946   ""
1947   "
1949   operands[1] = mcore_gen_compare_reg (GEU);
1952 (define_expand "sgtu"
1953   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1954         (eq:SI (match_dup 1) (const_int 0)))]
1955   ""
1956   "
1958   operands[1] = mcore_gen_compare_reg (LEU);
1961 (define_expand "sleu"
1962   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
1963         (ne:SI (match_dup 1) (const_int 0)))]
1964   ""
1965   "
1967   operands[1] = mcore_gen_compare_reg (LEU);
1970 (define_insn "incscc"
1971   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1972         (plus:SI (ne (reg:CC 17) (const_int 0))
1973                  (match_operand:SI 1 "mcore_arith_reg_operand" "0")))]
1974   ""
1975   "inct %0")
1977 (define_insn "incscc_false"
1978   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1979         (plus:SI (eq (reg:CC 17) (const_int 0))
1980                  (match_operand:SI 1 "mcore_arith_reg_operand" "0")))]
1981   ""
1982   "incf %0")
1984 (define_insn "decscc"
1985   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1986         (minus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
1987                   (ne (reg:CC 17) (const_int 0))))]
1988   ""
1989   "dect %0")
1991 (define_insn "decscc_false"
1992   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
1993         (minus:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0")
1994                   (eq (reg:CC 17) (const_int 0))))]
1995   ""
1996   "decf %0")
1998 ;; ------------------------------------------------------------------------
1999 ;; Conditional move patterns.
2000 ;; ------------------------------------------------------------------------
2002 (define_expand "smaxsi3"
2003   [(set (reg:CC 17)
2004         (lt:CC (match_operand:SI 1 "mcore_arith_reg_operand" "")
2005                (match_operand:SI 2 "mcore_arith_reg_operand" "")))
2006    (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2007         (if_then_else:SI (eq (reg:CC 17) (const_int 0))
2008                          (match_dup 1) (match_dup 2)))]
2009   ""
2010   "")
2011                
2012 (define_split
2013   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2014         (smax:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2015                  (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
2016   ""
2017   [(set (reg:CC 17)
2018         (lt:SI (match_dup 1) (match_dup 2)))
2019    (set (match_dup 0)
2020         (if_then_else:SI (eq (reg:CC 17) (const_int 0))
2021                          (match_dup 1) (match_dup 2)))]
2022   "")
2024 ; no tstgt in 0.97, so just use cmplti (btsti x,31) and reverse move 
2025 ; condition  BRC
2026 (define_split
2027   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2028         (smax:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2029                  (const_int 0)))]
2030   ""
2031   [(set (reg:CC 17)
2032         (lt:CC (match_dup 1) (const_int 0)))
2033    (set (match_dup 0)
2034         (if_then_else:SI (eq (reg:CC 17) (const_int 0))
2035                          (match_dup 1) (const_int 0)))]
2036   "")
2038 (define_expand "sminsi3"
2039   [(set (reg:CC 17)
2040         (lt:CC (match_operand:SI 1 "mcore_arith_reg_operand" "")
2041                (match_operand:SI 2 "mcore_arith_reg_operand" "")))
2042    (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2043         (if_then_else:SI (ne (reg:CC 17) (const_int 0))
2044                          (match_dup 1) (match_dup 2)))]
2045   ""
2046   "")
2048 (define_split
2049   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2050         (smin:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2051                  (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
2052   ""
2053   [(set (reg:CC 17)
2054         (lt:SI (match_dup 1) (match_dup 2)))
2055    (set (match_dup 0)
2056         (if_then_else:SI (ne (reg:CC 17) (const_int 0))
2057                          (match_dup 1) (match_dup 2)))]
2058   "")
2060 ;(define_split
2061 ;  [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2062 ;        (smin:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2063 ;                 (const_int 0)))]
2064 ;  ""
2065 ;  [(set (reg:CC 17)
2066 ;        (gt:CC (match_dup 1) (const_int 0)))
2067 ;   (set (match_dup 0)
2068 ;        (if_then_else:SI (eq (reg:CC 17) (const_int 0))
2069 ;                         (match_dup 1) (const_int 0)))]
2070 ;  "")
2072 ; changed these unsigned patterns to use geu instead of ltu.  it appears
2073 ; that the c-torture & ssrl test suites didn't catch these!  only showed
2074 ; up in friedman's clib work.   BRC 7/7/95
2076 (define_expand "umaxsi3"
2077   [(set (reg:CC 17)
2078         (geu:CC (match_operand:SI 1 "mcore_arith_reg_operand" "")
2079                 (match_operand:SI 2 "mcore_arith_reg_operand" "")))
2080    (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2081         (if_then_else:SI (eq (reg:CC 17) (const_int 0))
2082                          (match_dup 2) (match_dup 1)))]
2083   ""
2084   "")
2085                
2086 (define_split
2087   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2088         (umax:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2089                  (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
2090   ""
2091   [(set (reg:CC 17)
2092         (geu:SI (match_dup 1) (match_dup 2)))
2093    (set (match_dup 0)
2094         (if_then_else:SI (eq (reg:CC 17) (const_int 0))
2095                          (match_dup 2) (match_dup 1)))]
2096   "")
2098 (define_expand "uminsi3"
2099   [(set (reg:CC 17)
2100         (geu:CC (match_operand:SI 1 "mcore_arith_reg_operand" "")
2101                 (match_operand:SI 2 "mcore_arith_reg_operand" "")))
2102    (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2103         (if_then_else:SI (ne (reg:CC 17) (const_int 0))
2104                          (match_dup 2) (match_dup 1)))]
2105   ""
2106   "")
2108 (define_split
2109   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2110         (umin:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2111                  (match_operand:SI 2 "mcore_arith_reg_operand" "")))]
2112   ""
2113   [(set (reg:CC 17)
2114         (geu:SI (match_dup 1) (match_dup 2)))
2115    (set (match_dup 0)
2116         (if_then_else:SI (ne (reg:CC 17) (const_int 0))
2117                          (match_dup 2) (match_dup 1)))]
2118   "")
2120 ;; ------------------------------------------------------------------------
2121 ;; conditional move patterns really start here
2122 ;; ------------------------------------------------------------------------
2124 ;; the "movtK" patterns are experimental.  they are intended to account for
2125 ;; gcc's mucking on code such as:
2127 ;;            free_ent = ((block_compress) ? 257 : 256 );
2129 ;; these patterns help to get a tstne/bgeni/inct (or equivalent) sequence
2130 ;; when both arms have constants that are +/- 1 of each other.
2132 ;; note in the following patterns that the "movtK" ones should be the first
2133 ;; one defined in each sequence.  this is because the general pattern also
2134 ;; matches, so use ordering to determine priority (it's easier this way than
2135 ;; adding conditions to the general patterns).   BRC
2137 ;; the U and Q constraints are necessary to ensure that reload does the
2138 ;; 'right thing'.  U constrains the operand to 0 and Q to 1 for use in the
2139 ;; clrt & clrf and clrt/inct & clrf/incf patterns.    BRC 6/26
2141 ;; ??? there appears to be some problems with these movtK patterns for ops
2142 ;; other than eq & ne.  need to fix.  6/30 BRC
2144 ;; ------------------------------------------------------------------------
2145 ;; ne 
2146 ;; ------------------------------------------------------------------------
2148 ; experimental conditional move with two constants +/- 1  BRC
2150 (define_insn "movtK_1"
2151   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2152         (if_then_else:SI
2153             (ne (reg:CC 17) (const_int 0))
2154           (match_operand:SI 1 "mcore_arith_O_operand" "O")
2155           (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
2156   "  GET_CODE (operands[1]) == CONST_INT
2157   && GET_CODE (operands[2]) == CONST_INT
2158   && (   (INTVAL (operands[1]) - INTVAL (operands[2]) == 1)
2159       || (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
2160   "* return mcore_output_cmov (operands, 1, NULL);"
2161   [(set_attr "length" "4")])
2163 (define_insn "movt0"
2164   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2165         (if_then_else:SI
2166          (ne (reg:CC 17) (const_int 0))
2167          (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
2168          (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
2169   ""
2170   "@
2171     movt        %0,%1
2172     movf        %0,%2
2173     clrt        %0
2174     clrf        %0")
2176 ;; ------------------------------------------------------------------------
2177 ;; eq
2178 ;; ------------------------------------------------------------------------
2180 ; experimental conditional move with two constants +/- 1  BRC
2181 (define_insn "movtK_2"
2182   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2183         (if_then_else:SI
2184             (eq (reg:CC 17) (const_int 0))
2185           (match_operand:SI 1 "mcore_arith_O_operand" "O")
2186           (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
2187   "  GET_CODE (operands[1]) == CONST_INT
2188   && GET_CODE (operands[2]) == CONST_INT
2189   && (   (INTVAL (operands[1]) - INTVAL (operands[2]) == 1)
2190       || (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
2191   "* return mcore_output_cmov (operands, 0, NULL);"
2192   [(set_attr "length" "4")])
2194 (define_insn "movf0"
2195   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2196         (if_then_else:SI
2197          (eq (reg:CC 17) (const_int 0))
2198          (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
2199          (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
2200   ""
2201   "@
2202     movf        %0,%1
2203     movt        %0,%2
2204     clrf        %0
2205     clrt        %0")
2207 ; turns lsli rx,imm/btsti rx,31 into btsti rx,imm.  not done by a peephole
2208 ; because the instructions are not adjacent (peepholes are related by posn -
2209 ; not by dataflow).   BRC
2211 (define_insn ""
2212   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2213         (if_then_else:SI (eq (zero_extract:SI 
2214                               (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2215                               (const_int 1)
2216                               (match_operand:SI 2 "mcore_literal_K_operand" "K,K,K,K"))
2217                              (const_int 0))
2218                          (match_operand:SI 3 "mcore_arith_imm_operand" "r,0,U,0")
2219                          (match_operand:SI 4 "mcore_arith_imm_operand" "0,r,0,U")))]
2220   ""
2221   "@
2222     btsti       %1,%2\;movf     %0,%3
2223     btsti       %1,%2\;movt     %0,%4
2224     btsti       %1,%2\;clrf     %0
2225     btsti       %1,%2\;clrt     %0"
2226   [(set_attr "length" "4")])
2228 ; turns sextb rx/btsti rx,31 into btsti rx,7.  must be QImode to be safe.  BRC
2230 (define_insn ""
2231   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2232         (if_then_else:SI (eq (lshiftrt:SI 
2233                               (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2234                               (const_int 7))
2235                              (const_int 0))
2236                          (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2237                          (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2238   "GET_CODE (operands[1]) == SUBREG && 
2239       GET_MODE (SUBREG_REG (operands[1])) == QImode"
2240   "@
2241     btsti       %1,7\;movf      %0,%2
2242     btsti       %1,7\;movt      %0,%3
2243     btsti       %1,7\;clrf      %0
2244     btsti       %1,7\;clrt      %0"
2245   [(set_attr "length" "4")])
2248 ;; ------------------------------------------------------------------------
2249 ;; ne
2250 ;; ------------------------------------------------------------------------
2252 ;; Combine creates this from an andn instruction in a scc sequence.
2253 ;; We must recognize it to get conditional moves generated.
2255 ; experimental conditional move with two constants +/- 1  BRC
2256 (define_insn "movtK_3"
2257   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2258         (if_then_else:SI
2259             (ne (match_operand:SI 1 "mcore_arith_reg_operand" "r") 
2260                 (const_int 0))
2261           (match_operand:SI 2 "mcore_arith_O_operand" "O")
2262           (match_operand:SI 3 "mcore_arith_O_operand" "O")))]
2263   "  GET_CODE (operands[2]) == CONST_INT
2264   && GET_CODE (operands[3]) == CONST_INT
2265   && (   (INTVAL (operands[2]) - INTVAL (operands[3]) == 1)
2266       || (INTVAL (operands[3]) - INTVAL (operands[2]) == 1))"
2267   "*
2269   rtx out_operands[4];
2270   out_operands[0] = operands[0];
2271   out_operands[1] = operands[2];
2272   out_operands[2] = operands[3];
2273   out_operands[3] = operands[1];
2275   return mcore_output_cmov (out_operands, 1, \"cmpnei   %3,0\");
2278   [(set_attr "length" "6")])
2280 (define_insn "movt2"
2281   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2282         (if_then_else:SI (ne (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2283                              (const_int 0))
2284                          (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2285                          (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2286   ""      
2287   "@
2288     cmpnei      %1,0\;movt      %0,%2
2289     cmpnei      %1,0\;movf      %0,%3
2290     cmpnei      %1,0\;clrt      %0
2291     cmpnei      %1,0\;clrf      %0"
2292   [(set_attr "length" "4")])
2294 ; turns lsli rx,imm/btsti rx,31 into btsti rx,imm.  not done by a peephole
2295 ; because the instructions are not adjacent (peepholes are related by posn -
2296 ; not by dataflow).   BRC
2298 (define_insn ""
2299  [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2300         (if_then_else:SI (ne (zero_extract:SI 
2301                               (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2302                               (const_int 1)
2303                               (match_operand:SI 2 "mcore_literal_K_operand" "K,K,K,K"))
2304                              (const_int 0))
2305                          (match_operand:SI 3 "mcore_arith_imm_operand" "r,0,U,0")
2306                          (match_operand:SI 4 "mcore_arith_imm_operand" "0,r,0,U")))]
2307   ""
2308   "@
2309     btsti       %1,%2\;movt     %0,%3
2310     btsti       %1,%2\;movf     %0,%4
2311     btsti       %1,%2\;clrt     %0
2312     btsti       %1,%2\;clrf     %0"
2313   [(set_attr "length" "4")])
2315 ; turns sextb rx/btsti rx,31 into btsti rx,7.  must be QImode to be safe.  BRC
2317 (define_insn ""
2318   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2319         (if_then_else:SI (ne (lshiftrt:SI 
2320                               (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2321                               (const_int 7))
2322                              (const_int 0))
2323                          (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2324                          (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2325   "GET_CODE (operands[1]) == SUBREG && 
2326       GET_MODE (SUBREG_REG (operands[1])) == QImode"
2327   "@
2328     btsti       %1,7\;movt      %0,%2
2329     btsti       %1,7\;movf      %0,%3
2330     btsti       %1,7\;clrt      %0
2331     btsti       %1,7\;clrf      %0"
2332   [(set_attr "length" "4")])
2334 ;; ------------------------------------------------------------------------
2335 ;; eq/eq
2336 ;; ------------------------------------------------------------------------
2338 ; experimental conditional move with two constants +/- 1  BRC
2339 (define_insn "movtK_4"
2340   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2341         (if_then_else:SI
2342             (eq (eq:SI (reg:CC 17) (const_int 0)) (const_int 0))
2343           (match_operand:SI 1 "mcore_arith_O_operand" "O")
2344           (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
2345   "GET_CODE (operands[1]) == CONST_INT &&
2346    GET_CODE (operands[2]) == CONST_INT &&
2347    ((INTVAL (operands[1]) - INTVAL (operands[2]) == 1) ||
2348    (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
2349   "* return mcore_output_cmov(operands, 1, NULL);"
2350   [(set_attr "length" "4")])
2352 (define_insn "movt3"
2353   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2354         (if_then_else:SI
2355          (eq (eq:SI (reg:CC 17) (const_int 0)) (const_int 0))
2356          (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
2357          (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
2358   ""
2359   "@
2360     movt        %0,%1
2361     movf        %0,%2
2362     clrt        %0
2363     clrf        %0")
2365 ;; ------------------------------------------------------------------------
2366 ;; eq/ne
2367 ;; ------------------------------------------------------------------------
2369 ; experimental conditional move with two constants +/- 1  BRC
2370 (define_insn "movtK_5"
2371   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2372         (if_then_else:SI
2373             (eq (ne:SI (reg:CC 17) (const_int 0)) (const_int 0))
2374           (match_operand:SI 1 "mcore_arith_O_operand" "O")
2375           (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
2376   "GET_CODE (operands[1]) == CONST_INT &&
2377    GET_CODE (operands[2]) == CONST_INT &&
2378    ((INTVAL (operands[1]) - INTVAL (operands[2]) == 1) ||
2379     (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
2380   "* return mcore_output_cmov (operands, 0, NULL);"
2381   [(set_attr "length" "4")])
2383 (define_insn "movf1"
2384   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2385         (if_then_else:SI
2386          (eq (ne:SI (reg:CC 17) (const_int 0)) (const_int 0))
2387          (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
2388          (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
2389   ""
2390   "@
2391     movf        %0,%1
2392     movt        %0,%2
2393     clrf        %0
2394     clrt        %0")
2396 ;; ------------------------------------------------------------------------
2397 ;; eq
2398 ;; ------------------------------------------------------------------------
2400 ;; Combine creates this from an andn instruction in a scc sequence.
2401 ;; We must recognize it to get conditional moves generated.
2403 ; experimental conditional move with two constants +/- 1  BRC
2405 (define_insn "movtK_6"
2406   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2407         (if_then_else:SI
2408             (eq (match_operand:SI 1 "mcore_arith_reg_operand" "r") 
2409                 (const_int 0))
2410           (match_operand:SI 2 "mcore_arith_O_operand" "O")
2411           (match_operand:SI 3 "mcore_arith_O_operand" "O")))]
2412   "GET_CODE (operands[1]) == CONST_INT &&
2413    GET_CODE (operands[2]) == CONST_INT &&
2414    ((INTVAL (operands[2]) - INTVAL (operands[3]) == 1) ||
2415     (INTVAL (operands[3]) - INTVAL (operands[2]) == 1))"
2416   "* 
2418    rtx out_operands[4];
2419    out_operands[0] = operands[0];
2420    out_operands[1] = operands[2];
2421    out_operands[2] = operands[3];
2422    out_operands[3] = operands[1];
2424    return mcore_output_cmov (out_operands, 0, \"cmpnei  %3,0\");
2426   [(set_attr "length" "6")])
2428 (define_insn "movf3"
2429   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2430         (if_then_else:SI (eq (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2431                              (const_int 0))
2432                          (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2433                          (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2434   ""
2435   "@
2436     cmpnei      %1,0\;movf      %0,%2
2437     cmpnei      %1,0\;movt      %0,%3
2438     cmpnei      %1,0\;clrf      %0
2439     cmpnei      %1,0\;clrt      %0"
2440   [(set_attr "length" "4")])
2442 ;; ------------------------------------------------------------------------
2443 ;; ne/eq
2444 ;; ------------------------------------------------------------------------
2446 ; experimental conditional move with two constants +/- 1  BRC
2447 (define_insn "movtK_7"
2448   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2449         (if_then_else:SI
2450             (ne (eq:SI (reg:CC 17) (const_int 0)) (const_int 0))
2451           (match_operand:SI 1 "mcore_arith_O_operand" "O")
2452           (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
2453   "GET_CODE (operands[1]) == CONST_INT &&
2454    GET_CODE (operands[2]) == CONST_INT &&
2455    ((INTVAL (operands[1]) - INTVAL (operands[2]) == 1) ||
2456     (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
2457   "* return mcore_output_cmov (operands, 0, NULL);"
2458   [(set_attr "length" "4")])
2460 (define_insn "movf4"
2461   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2462         (if_then_else:SI
2463          (ne (eq:SI (reg:CC 17) (const_int 0)) (const_int 0))
2464          (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
2465          (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
2466   ""
2467   "@
2468     movf        %0,%1
2469     movt        %0,%2
2470     clrf        %0
2471     clrt        %0")
2473 ;; ------------------------------------------------------------------------
2474 ;; ne/ne
2475 ;; ------------------------------------------------------------------------
2477 ; experimental conditional move with two constants +/- 1  BRC
2478 (define_insn "movtK_8"
2479   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2480         (if_then_else:SI
2481             (ne (ne:SI (reg:CC 17) (const_int 0)) (const_int 0))
2482           (match_operand:SI 1 "mcore_arith_O_operand" "O")
2483           (match_operand:SI 2 "mcore_arith_O_operand" "O")))]
2484   "GET_CODE (operands[1]) == CONST_INT &&
2485    GET_CODE (operands[2]) == CONST_INT &&
2486    ((INTVAL (operands[1]) - INTVAL (operands[2]) == 1) ||
2487     (INTVAL (operands[2]) - INTVAL (operands[1]) == 1))"
2488   "* return mcore_output_cmov (operands, 1, NULL);"
2489   [(set_attr "length" "4")])
2491 (define_insn "movt4"
2492   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2493         (if_then_else:SI
2494          (ne (ne:SI (reg:CC 17) (const_int 0)) (const_int 0))
2495          (match_operand:SI 1 "mcore_arith_imm_operand" "r,0,U,0")
2496          (match_operand:SI 2 "mcore_arith_imm_operand" "0,r,0,U")))]
2497   ""
2498   "@
2499     movt        %0,%1
2500     movf        %0,%2
2501     clrt        %0
2502     clrf        %0")
2504 ;; Also need patterns to recognize lt/ge, since otherwise the compiler will
2505 ;; try to output not/asri/tstne/movf.
2507 ;; ------------------------------------------------------------------------
2508 ;; lt
2509 ;; ------------------------------------------------------------------------
2511 ; experimental conditional move with two constants +/- 1  BRC
2512 (define_insn "movtK_9"
2513   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2514         (if_then_else:SI
2515             (lt (match_operand:SI 1 "mcore_arith_reg_operand" "r") 
2516                 (const_int 0))
2517           (match_operand:SI 2 "mcore_arith_O_operand" "O")
2518           (match_operand:SI 3 "mcore_arith_O_operand" "O")))]
2519   "GET_CODE (operands[2]) == CONST_INT &&
2520    GET_CODE (operands[3]) == CONST_INT &&
2521    ((INTVAL (operands[2]) - INTVAL (operands[3]) == 1) ||
2522     (INTVAL (operands[3]) - INTVAL (operands[2]) == 1))"
2523   "*
2525    rtx out_operands[4];
2526    out_operands[0] = operands[0];
2527    out_operands[1] = operands[2];
2528    out_operands[2] = operands[3];
2529    out_operands[3] = operands[1];
2531    return mcore_output_cmov (out_operands, 1, \"btsti   %3,31\");
2533   [(set_attr "length" "6")])
2535 (define_insn "movt5"
2536   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2537         (if_then_else:SI (lt (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2538                              (const_int 0))
2539                          (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2540                          (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2541   ""
2542   "@
2543     btsti       %1,31\;movt     %0,%2
2544     btsti       %1,31\;movf     %0,%3
2545     btsti       %1,31\;clrt     %0
2546     btsti       %1,31\;clrf     %0"
2547   [(set_attr "length" "4")])
2550 ;; ------------------------------------------------------------------------
2551 ;; ge
2552 ;; ------------------------------------------------------------------------
2554 ; experimental conditional move with two constants +/- 1  BRC
2555 (define_insn "movtK_10"
2556   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2557         (if_then_else:SI
2558             (ge (match_operand:SI 1 "mcore_arith_reg_operand" "r") 
2559                 (const_int 0))
2560           (match_operand:SI 2 "mcore_arith_O_operand" "O")
2561           (match_operand:SI 3 "mcore_arith_O_operand" "O")))]
2562   "GET_CODE (operands[2]) == CONST_INT &&
2563    GET_CODE (operands[3]) == CONST_INT &&
2564    ((INTVAL (operands[2]) - INTVAL (operands[3]) == 1) ||
2565     (INTVAL (operands[3]) - INTVAL (operands[2]) == 1))"
2566   "*
2568   rtx out_operands[4];
2569   out_operands[0] = operands[0];
2570   out_operands[1] = operands[2];
2571   out_operands[2] = operands[3];
2572   out_operands[3] = operands[1];
2574    return mcore_output_cmov (out_operands, 0, \"btsti   %3,31\");
2576   [(set_attr "length" "6")])
2578 (define_insn "movf5"
2579   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,r,r,r")
2580         (if_then_else:SI (ge (match_operand:SI 1 "mcore_arith_reg_operand" "r,r,r,r")
2581                              (const_int 0))
2582                          (match_operand:SI 2 "mcore_arith_imm_operand" "r,0,U,0")
2583                          (match_operand:SI 3 "mcore_arith_imm_operand" "0,r,0,U")))]
2584   ""
2585   "@
2586     btsti       %1,31\;movf     %0,%2
2587     btsti       %1,31\;movt     %0,%3
2588     btsti       %1,31\;clrf     %0
2589     btsti       %1,31\;clrt     %0"
2590   [(set_attr "length" "4")])
2592 ;; ------------------------------------------------------------------------
2593 ;; Bitfield extract (xtrbN)
2594 ;; ------------------------------------------------------------------------
2596 ; sometimes we're better off using QI/HI mode and letting the machine indep.
2597 ; part expand insv and extv.
2599 ; e.g., sequences like:a        [an insertion]
2601 ;      ldw r8,(r6)
2602 ;      movi r7,0x00ffffff
2603 ;      and r8,r7                 r7 dead
2604 ;      stw r8,(r6)                r8 dead
2606 ; become:
2608 ;      movi r8,0
2609 ;      stb r8,(r6)              r8 dead
2611 ; it looks like always using SI mode is a win except in this type of code 
2612 ; (when adjacent bit fields collapse on a byte or halfword boundary).  when
2613 ; expanding with SI mode, non-adjacent bit field masks fold, but with QI/HI
2614 ; mode, they do not.  one thought is to add some peepholes to cover cases
2615 ; like the above, but this is not a general solution.
2617 ; -mword-bitfields expands/inserts using SI mode.  otherwise, do it with
2618 ; the smallest mode possible (using the machine indep. expansions).  BRC
2620 ;(define_expand "extv"
2621 ;  [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2622 ;       (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2623 ;                        (match_operand:SI 2 "const_int_operand" "")
2624 ;                        (match_operand:SI 3 "const_int_operand" "")))
2625 ;   (clobber (reg:CC 17))]
2626 ;  ""
2627 ;  "
2629 ;  if (INTVAL (operands[1]) != 8 || INTVAL (operands[2]) % 8 != 0)
2630 ;    {
2631 ;     if (TARGET_W_FIELD)
2632 ;       {
2633 ;        rtx lshft = GEN_INT (32 - (INTVAL (operands[2]) + INTVAL (operands[3])));
2634 ;        rtx rshft = GEN_INT (32 - INTVAL (operands[2]));
2636 ;        emit_insn (gen_rtx_SET (SImode, operands[0], operands[1]));
2637 ;        emit_insn (gen_rtx_SET (SImode, operands[0],
2638 ;                            gen_rtx_ASHIFT (SImode, operands[0], lshft)));
2639 ;        emit_insn (gen_rtx_SET (SImode, operands[0],
2640 ;                            gen_rtx_ASHIFTRT (SImode, operands[0], rshft)));
2641 ;        DONE;
2642 ;     }
2643 ;     else
2644 ;        FAIL;
2645 ;  }
2646 ;}")
2648 (define_expand "extv"
2649   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2650         (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2651                          (match_operand:SI 2 "const_int_operand" "")
2652                          (match_operand:SI 3 "const_int_operand" "")))
2653    (clobber (reg:CC 17))]
2654   ""
2655   "
2657   if (INTVAL (operands[2]) == 8 && INTVAL (operands[3]) % 8 == 0)
2658     {
2659        /* 8-bit field, aligned properly, use the xtrb[0123]+sext sequence.  */
2660        /* not DONE, not FAIL, but let the RTL get generated....  */
2661     }
2662   else if (TARGET_W_FIELD)
2663     {
2664       /* Arbitrary placement; note that the tree->rtl generator will make
2665          something close to this if we return FAIL  */
2666       rtx lshft = GEN_INT (32 - (INTVAL (operands[2]) + INTVAL (operands[3])));
2667       rtx rshft = GEN_INT (32 - INTVAL (operands[2]));
2668       rtx tmp1 = gen_reg_rtx (SImode);
2669       rtx tmp2 = gen_reg_rtx (SImode);
2671       emit_insn (gen_rtx_SET (SImode, tmp1, operands[1]));
2672       emit_insn (gen_rtx_SET (SImode, tmp2,
2673                          gen_rtx_ASHIFT (SImode, tmp1, lshft)));
2674       emit_insn (gen_rtx_SET (SImode, operands[0],
2675                          gen_rtx_ASHIFTRT (SImode, tmp2, rshft)));
2676       DONE;
2677     }
2678   else
2679     {
2680       /* Let the caller choose an alternate sequence.  */
2681       FAIL;
2682     }
2685 (define_expand "extzv"
2686   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2687         (zero_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "")
2688                          (match_operand:SI 2 "const_int_operand" "")
2689                          (match_operand:SI 3 "const_int_operand" "")))
2690    (clobber (reg:CC 17))]
2691   ""
2692   "
2694   if (INTVAL (operands[2]) == 8 && INTVAL (operands[3]) % 8 == 0)
2695     {
2696        /* 8-bit field, aligned properly, use the xtrb[0123] sequence.  */
2697        /* Let the template generate some RTL....  */
2698     }
2699   else if (CONST_OK_FOR_K ((1 << INTVAL (operands[2])) - 1))
2700     {
2701       /* A narrow bit-field (<=5 bits) means we can do a shift to put
2702          it in place and then use an andi to extract it.
2703          This is as good as a shiftleft/shiftright.  */
2705       rtx shifted;
2706       rtx mask = GEN_INT ((1 << INTVAL (operands[2])) - 1);
2708       if (INTVAL (operands[3]) == 0)
2709         {
2710           shifted = operands[1];
2711         }
2712       else
2713         {
2714           rtx rshft = GEN_INT (INTVAL (operands[3]));
2715           shifted = gen_reg_rtx (SImode);
2716           emit_insn (gen_rtx_SET (SImode, shifted,
2717                          gen_rtx_LSHIFTRT (SImode, operands[1], rshft)));
2718         }
2719      emit_insn (gen_rtx_SET (SImode, operands[0],
2720                        gen_rtx_AND (SImode, shifted, mask)));
2721      DONE;
2722    }
2723  else if (TARGET_W_FIELD)
2724    {
2725      /* Arbitrary pattern; play shift/shift games to get it. 
2726       * this is pretty much what the caller will do if we say FAIL */
2727      rtx lshft = GEN_INT (32 - (INTVAL (operands[2]) + INTVAL (operands[3])));
2728      rtx rshft = GEN_INT (32 - INTVAL (operands[2]));
2729      rtx tmp1 = gen_reg_rtx (SImode);
2730      rtx tmp2 = gen_reg_rtx (SImode);
2732      emit_insn (gen_rtx_SET (SImode, tmp1, operands[1]));
2733      emit_insn (gen_rtx_SET (SImode, tmp2,
2734                          gen_rtx_ASHIFT (SImode, tmp1, lshft)));
2735      emit_insn (gen_rtx_SET (SImode, operands[0],
2736                        gen_rtx_LSHIFTRT (SImode, tmp2, rshft)));
2737      DONE;
2738    }
2739  else
2740    {
2741      /* Make the compiler figure out some alternative mechanism.  */
2742      FAIL;
2743    }
2745  /* Emit the RTL pattern; something will match it later.  */
2748 (define_expand "insv"
2749   [(set (zero_extract:SI (match_operand:SI 0 "mcore_arith_reg_operand" "")
2750                          (match_operand:SI 1 "const_int_operand" "")
2751                          (match_operand:SI 2 "const_int_operand" ""))
2752         (match_operand:SI 3 "general_operand" ""))
2753    (clobber (reg:CC 17))]
2754   ""
2755   "
2757   if (mcore_expand_insv (operands))
2758     {
2759       DONE;
2760     }
2761   else
2762     {
2763       FAIL;
2764     }
2768 ;; the xtrb[0123] instructions handily get at 8-bit fields on nice boundaries.
2769 ;; but then, they do force you through r1.
2771 ;; the combiner will build such patterns for us, so we'll make them available
2772 ;; for its use.
2774 ;; Note that we have both SIGNED and UNSIGNED versions of these...
2778 ;; These no longer worry about the clobbering of CC bit; not sure this is
2779 ;; good...
2781 ;; the SIGNED versions of these
2783 (define_insn ""
2784   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,b")
2785         (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,r") (const_int 8) (const_int 24)))]
2786   ""
2787   "@
2788         asri    %0,24
2789         xtrb0   %0,%1\;sextb    %0"
2790   [(set_attr "type" "shift")])
2792 (define_insn ""
2793   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=b")
2794         (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r") (const_int 8) (const_int 16)))]
2795   ""
2796   "xtrb1        %0,%1\;sextb    %0"
2797   [(set_attr "type" "shift")])
2799 (define_insn ""
2800   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=b")
2801         (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r") (const_int 8) (const_int 8)))]
2802   ""
2803   "xtrb2        %0,%1\;sextb    %0"
2804   [(set_attr "type" "shift")])
2806 (define_insn ""
2807   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2808         (sign_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0") (const_int 8) (const_int 0)))]
2809   ""
2810   "sextb        %0"
2811   [(set_attr "type" "shift")])
2813 ;; the UNSIGNED uses of xtrb[0123]
2815 (define_insn ""
2816   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,b")
2817         (zero_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,r") (const_int 8) (const_int 24)))]
2818   ""
2819   "@
2820         lsri    %0,24
2821         xtrb0   %0,%1"
2822   [(set_attr "type" "shift")])
2824 (define_insn ""
2825   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=b")
2826         (zero_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r") (const_int 8) (const_int 16)))]
2827   ""
2828   "xtrb1        %0,%1"
2829   [(set_attr "type" "shift")])
2831 (define_insn ""
2832   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=b")
2833         (zero_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "r") (const_int 8) (const_int 8)))]
2834   ""
2835   "xtrb2        %0,%1"
2836   [(set_attr "type" "shift")])
2838 ;; This can be peepholed if it follows a ldb ...
2839 (define_insn ""
2840   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r,b")
2841         (zero_extract:SI (match_operand:SI 1 "mcore_arith_reg_operand" "0,r") (const_int 8) (const_int 0)))]
2842   ""
2843   "@
2844         zextb   %0
2845         xtrb3   %0,%1\;zextb    %0"
2846   [(set_attr "type" "shift")])
2849 ;; ------------------------------------------------------------------------
2850 ;; Block move - adapted from m88k.md
2851 ;; ------------------------------------------------------------------------
2853 (define_expand "movmemsi"
2854   [(parallel [(set (mem:BLK (match_operand:BLK 0 "" ""))
2855                    (mem:BLK (match_operand:BLK 1 "" "")))
2856               (use (match_operand:SI 2 "general_operand" ""))
2857               (use (match_operand:SI 3 "immediate_operand" ""))])]
2858   ""
2859   "
2861   if (mcore_expand_block_move (operands))
2862     DONE;
2863   else
2864     FAIL;
2867 ;; ;;; ??? These patterns are meant to be generated from expand_block_move,
2868 ;; ;;; but they currently are not.
2869 ;; 
2870 ;; (define_insn ""
2871 ;;   [(set (match_operand:QI 0 "mcore_arith_reg_operand" "=r")
2872 ;;      (match_operand:BLK 1 "mcore_general_movsrc_operand" "m"))]
2873 ;;   ""
2874 ;;   "ld.b      %0,%1"
2875 ;;   [(set_attr "type" "load")])
2876 ;; 
2877 ;; (define_insn ""
2878 ;;   [(set (match_operand:HI 0 "mcore_arith_reg_operand" "=r")
2879 ;;      (match_operand:BLK 1 "mcore_general_movsrc_operand" "m"))]
2880 ;;   ""
2881 ;;   "ld.h      %0,%1"
2882 ;;   [(set_attr "type" "load")])
2883 ;; 
2884 ;; (define_insn ""
2885 ;;   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2886 ;;      (match_operand:BLK 1 "mcore_general_movsrc_operand" "m"))]
2887 ;;   ""
2888 ;;   "ld.w      %0,%1"
2889 ;;   [(set_attr "type" "load")])
2890 ;; 
2891 ;; (define_insn ""
2892 ;;   [(set (match_operand:BLK 0 "mcore_general_movdst_operand" "=m")
2893 ;;      (match_operand:QI 1 "mcore_arith_reg_operand" "r"))]
2894 ;;   ""
2895 ;;   "st.b      %1,%0"
2896 ;;   [(set_attr "type" "store")])
2897 ;; 
2898 ;; (define_insn ""
2899 ;;   [(set (match_operand:BLK 0 "mcore_general_movdst_operand" "=m")
2900 ;;      (match_operand:HI 1 "mcore_arith_reg_operand" "r"))]
2901 ;;   ""
2902 ;;   "st.h      %1,%0"
2903 ;;   [(set_attr "type" "store")])
2904 ;; 
2905 ;; (define_insn ""
2906 ;;   [(set (match_operand:BLK 0 "mcore_general_movdst_operand" "=m")
2907 ;;      (match_operand:SI 1 "mcore_arith_reg_operand" "r"))]
2908 ;;   ""
2909 ;;   "st.w      %1,%0"
2910 ;;   [(set_attr "type" "store")])
2912 ;; ------------------------------------------------------------------------
2913 ;; Misc Optimizing quirks
2914 ;; ------------------------------------------------------------------------
2916 ;; pair to catch constructs like:  (int *)((p+=4)-4) which happen
2917 ;; in stdarg/varargs traversal. This changes a 3 insn sequence to a 2
2918 ;; insn sequence. -- RBE 11/30/95
2919 (define_insn ""
2920   [(parallel[
2921       (set (match_operand:SI 0 "mcore_arith_reg_operand" "=r")
2922            (match_operand:SI 1 "mcore_arith_reg_operand" "+r"))
2923       (set (match_dup 1) (plus:SI (match_dup 1) (match_operand 2 "mcore_arith_any_imm_operand" "")))])]
2924   "GET_CODE(operands[2]) == CONST_INT"
2925   "#"
2926   [(set_attr "length" "4")])
2928 (define_split 
2929   [(parallel[
2930       (set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2931            (match_operand:SI 1 "mcore_arith_reg_operand" ""))
2932       (set (match_dup 1) (plus:SI (match_dup 1) (match_operand 2 "mcore_arith_any_imm_operand" "")))])]
2933   "GET_CODE(operands[2]) == CONST_INT &&
2934    operands[0] != operands[1]"
2935   [(set (match_dup 0) (match_dup 1))
2936    (set (match_dup 1) (plus:SI (match_dup 1) (match_dup 2)))])
2939 ;;; Peepholes
2941 ; note: in the following patterns, use mcore_is_dead() to ensure that the
2942 ; reg we may be trashing really is dead.  reload doesn't always mark
2943 ; deaths, so mcore_is_dead() (see mcore.c) scans forward to find its death.  BRC
2945 ;;; A peephole to convert the 3 instruction sequence generated by reload
2946 ;;; to load a FP-offset address into a 2 instruction sequence.
2947 ;;; ??? This probably never matches anymore.
2948 (define_peephole
2949   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "r")
2950         (match_operand:SI 1 "const_int_operand" "J"))
2951    (set (match_dup 0) (neg:SI (match_dup 0)))
2952    (set (match_dup 0)
2953         (plus:SI (match_dup 0)
2954                  (match_operand:SI 2 "mcore_arith_reg_operand" "r")))]
2955   "CONST_OK_FOR_J (INTVAL (operands[1]))"
2956   "error\;mov   %0,%2\;subi     %0,%1")
2958 ;; Moves of inlinable constants are done late, so when a 'not' is generated
2959 ;; it is never combined with the following 'and' to generate an 'andn' b/c 
2960 ;; the combiner never sees it.  use a peephole to pick up this case (happens
2961 ;; mostly with bitfields)  BRC
2963 (define_peephole
2964   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "r")
2965         (match_operand:SI 1 "const_int_operand" "i"))
2966    (set (match_operand:SI 2 "mcore_arith_reg_operand" "r")
2967         (and:SI (match_dup 2) (match_dup 0)))]
2968   "mcore_const_trick_uses_not (INTVAL (operands[1])) &&
2969         operands[0] != operands[2] &&
2970         mcore_is_dead (insn, operands[0])"
2971   "* return mcore_output_andn (insn, operands);")
2973 ; when setting or clearing just two bits, it's cheapest to use two bseti's 
2974 ; or bclri's.  only happens when relaxing immediates.  BRC
2976 (define_peephole
2977   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2978         (match_operand:SI 1 "const_int_operand" ""))
2979    (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
2980         (ior:SI (match_dup 2) (match_dup 0)))]
2981   "TARGET_HARDLIT
2982    && mcore_num_ones (INTVAL (operands[1])) == 2
2983    && mcore_is_dead (insn, operands[0])"
2984   "* return mcore_output_bseti (operands[2], INTVAL (operands[1]));")
2986 (define_peephole
2987   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
2988         (match_operand:SI 1 "const_int_operand" ""))
2989    (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
2990         (and:SI (match_dup 2) (match_dup 0)))]
2991   "TARGET_HARDLIT && mcore_num_zeros (INTVAL (operands[1])) == 2 &&
2992        mcore_is_dead (insn, operands[0])"
2993   "* return mcore_output_bclri (operands[2], INTVAL (operands[1]));")
2995 ; change an and with a mask that has a single cleared bit into a bclri.  this
2996 ; handles QI and HI mode values using the knowledge that the most significant
2997 ; bits don't matter.
2999 (define_peephole
3000   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
3001         (match_operand:SI 1 "const_int_operand" ""))
3002    (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
3003         (and:SI (match_operand:SI 3 "mcore_arith_reg_operand" "")
3004                 (match_dup 0)))]
3005   "GET_CODE (operands[3]) == SUBREG && 
3006       GET_MODE (SUBREG_REG (operands[3])) == QImode &&
3007       mcore_num_zeros (INTVAL (operands[1]) | 0xffffff00) == 1 &&
3008       mcore_is_dead (insn, operands[0])"
3010   if (! mcore_is_same_reg (operands[2], operands[3]))
3011     output_asm_insn (\"mov\\t%2,%3\", operands);
3012   return mcore_output_bclri (operands[2], INTVAL (operands[1]) | 0xffffff00);")
3014 /* Do not fold these together -- mode is lost at final output phase.  */
3016 (define_peephole
3017   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
3018         (match_operand:SI 1 "const_int_operand" ""))
3019    (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
3020         (and:SI (match_operand:SI 3 "mcore_arith_reg_operand" "")
3021                 (match_dup 0)))]
3022   "GET_CODE (operands[3]) == SUBREG && 
3023       GET_MODE (SUBREG_REG (operands[3])) == HImode &&
3024       mcore_num_zeros (INTVAL (operands[1]) | 0xffff0000) == 1 &&
3025       operands[2] == operands[3] &&
3026       mcore_is_dead (insn, operands[0])"
3028   if (! mcore_is_same_reg (operands[2], operands[3]))
3029     output_asm_insn (\"mov\\t%2,%3\", operands);
3030   return mcore_output_bclri (operands[2], INTVAL (operands[1]) | 0xffff0000);")
3032 ; This peephole helps when using -mwide-bitfields to widen fields so they 
3033 ; collapse.   This, however, has the effect that a narrower mode is not used
3034 ; when desirable.  
3036 ; e.g., sequences like:
3038 ;      ldw r8,(r6)
3039 ;      movi r7,0x00ffffff
3040 ;      and r8,r7                 r7 dead
3041 ;      stw r8,(r6)                r8 dead
3043 ; get peepholed to become:
3045 ;      movi r8,0
3046 ;      stb r8,(r6)              r8 dead
3048 ; Do only easy addresses that have no offset.  This peephole is also applied 
3049 ; to halfwords.  We need to check that the load is non-volatile before we get
3050 ; rid of it.
3052 (define_peephole
3053   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
3054         (match_operand:SI 1 "memory_operand" ""))
3055    (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
3056         (match_operand:SI 3 "const_int_operand" ""))
3057    (set (match_dup 0) (and:SI (match_dup 0) (match_dup 2)))
3058    (set (match_operand:SI 4 "memory_operand" "") (match_dup 0))]
3059   "mcore_is_dead (insn, operands[0]) &&
3060    ! MEM_VOLATILE_P (operands[1]) &&
3061    mcore_is_dead (insn, operands[2]) && 
3062    (mcore_byte_offset (INTVAL (operands[3])) > -1 || 
3063     mcore_halfword_offset (INTVAL (operands[3])) > -1) &&
3064    ! MEM_VOLATILE_P (operands[4]) &&
3065    GET_CODE (XEXP (operands[4], 0)) == REG"
3068    int ofs;
3069    enum machine_mode mode;
3070    rtx base_reg = XEXP (operands[4], 0);
3072    if ((ofs = mcore_byte_offset (INTVAL (operands[3]))) > -1)
3073       mode = QImode;
3074    else if ((ofs = mcore_halfword_offset (INTVAL (operands[3]))) > -1)
3075       mode = HImode;
3076    else
3077       gcc_unreachable ();
3079    if (ofs > 0) 
3080       operands[4] = gen_rtx_MEM (mode, 
3081                               gen_rtx_PLUS (SImode, base_reg, GEN_INT(ofs)));
3082    else
3083       operands[4] = gen_rtx_MEM (mode, base_reg);
3085    if (mode == QImode)
3086       return \"movi     %0,0\\n\\tst.b  %0,%4\";
3088    return \"movi        %0,0\\n\\tst.h  %0,%4\";
3091 ; from sop11. get btsti's for (LT A 0) where A is a QI or HI value
3093 (define_peephole
3094   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "r")
3095         (sign_extend:SI (match_operand:QI 1 "mcore_arith_reg_operand" "0")))
3096    (set (reg:CC 17)
3097         (lt:CC (match_dup 0)
3098             (const_int 0)))]
3099   "mcore_is_dead (insn, operands[0])"
3100   "btsti        %0,7")
3102 (define_peephole
3103   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "r")
3104         (sign_extend:SI (match_operand:HI 1 "mcore_arith_reg_operand" "0")))
3105    (set (reg:CC 17)
3106         (lt:CC (match_dup 0)
3107             (const_int 0)))]
3108   "mcore_is_dead (insn, operands[0])"
3109   "btsti        %0,15")
3111 ; Pick up a tst.  This combination happens because the immediate is not
3112 ; allowed to fold into one of the operands of the tst.  Does not happen
3113 ; when relaxing immediates.  BRC
3115 (define_peephole
3116   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
3117         (match_operand:SI 1 "mcore_arith_reg_operand" ""))
3118    (set (match_dup 0)
3119         (and:SI (match_dup 0)
3120                 (match_operand:SI 2 "mcore_literal_K_operand" "")))
3121    (set (reg:CC 17) (ne:CC (match_dup 0) (const_int 0)))]
3122   "mcore_is_dead (insn, operands[0])"
3123   "movi %0,%2\;tst      %1,%0")
3125 (define_peephole
3126   [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
3127         (if_then_else:SI (ne (zero_extract:SI 
3128                                 (match_operand:SI 1 "mcore_arith_reg_operand" "")
3129                                 (const_int 1)
3130                                 (match_operand:SI 2 "mcore_literal_K_operand" ""))
3131                              (const_int 0))
3132            (match_operand:SI 3 "mcore_arith_imm_operand" "")
3133            (match_operand:SI 4 "mcore_arith_imm_operand" "")))
3134     (set (reg:CC 17) (ne:CC (match_dup 0) (const_int 0)))]
3135   ""
3138   unsigned int op0 = REGNO (operands[0]);
3140   if (GET_CODE (operands[3]) == REG)
3141     {
3142      if (REGNO (operands[3]) == op0 && GET_CODE (operands[4]) == CONST_INT
3143          && INTVAL (operands[4]) == 0)
3144         return \"btsti  %1,%2\\n\\tclrf %0\";
3145      else if (GET_CODE (operands[4]) == REG)
3146        {
3147         if (REGNO (operands[4]) == op0)
3148            return \"btsti       %1,%2\\n\\tmovf %0,%3\";
3149         else if (REGNO (operands[3]) == op0)
3150            return \"btsti       %1,%2\\n\\tmovt %0,%4\";
3151        }
3153      gcc_unreachable ();
3154     }
3155   else if (GET_CODE (operands[3]) == CONST_INT
3156            && INTVAL (operands[3]) == 0
3157            && GET_CODE (operands[4]) == REG)
3158      return \"btsti     %1,%2\\n\\tclrt %0\";
3160   gcc_unreachable ();
3163 ; experimental - do the constant folding ourselves.  note that this isn't
3164 ;   re-applied like we'd really want.  i.e., four ands collapse into two
3165 ;   instead of one.  this is because peepholes are applied as a sliding
3166 ;   window.  the peephole does not generate new rtl's, but instead slides
3167 ;   across the rtl's generating machine instructions.  it would be nice
3168 ;   if the peephole optimizer is changed to re-apply patterns and to gen
3169 ;   new rtl's.  this is more flexible.  the pattern below helps when we're
3170 ;   not using relaxed immediates.   BRC
3172 ;(define_peephole
3173 ;  [(set (match_operand:SI 0 "mcore_arith_reg_operand" "")
3174 ;        (match_operand:SI 1 "const_int_operand" ""))
3175 ;   (set (match_operand:SI 2 "mcore_arith_reg_operand" "")
3176 ;          (and:SI (match_dup 2) (match_dup 0)))
3177 ;   (set (match_dup 0)
3178 ;        (match_operand:SI 3 "const_int_operand" ""))
3179 ;   (set (match_dup 2)
3180 ;           (and:SI (match_dup 2) (match_dup 0)))]
3181 ;  "!TARGET_RELAX_IMM && mcore_is_dead (insn, operands[0]) &&
3182 ;       mcore_const_ok_for_inline (INTVAL (operands[1]) & INTVAL (operands[3]))"
3183 ;  "*
3185 ;  rtx out_operands[2];
3186 ;  out_operands[0] = operands[0];
3187 ;  out_operands[1] = GEN_INT (INTVAL (operands[1]) & INTVAL (operands[3]));
3188 ;  
3189 ;  output_inline_const (SImode, out_operands);
3191 ;  output_asm_insn (\"and       %2,%0\", operands);
3193 ;  return \"\";   
3194 ;}")
3196 ; BRC: for inlining get rid of extra test - experimental
3197 ;(define_peephole
3198 ;  [(set (match_operand:SI 0 "mcore_arith_reg_operand" "r")
3199 ;          (ne:SI (reg:CC 17) (const_int 0)))
3200 ;   (set (reg:CC 17) (ne:CC (match_dup 0) (const_int 0)))
3201 ;   (set (pc) 
3202 ;       (if_then_else (eq (reg:CC 17) (const_int 0))
3203 ;         (label_ref (match_operand 1 "" ""))
3204 ;         (pc)))]
3205 ;   ""
3206 ;   "*
3208 ;  if (get_attr_length (insn) == 10)
3209 ;    {
3210 ;      output_asm_insn (\"bt    2f\\n\\tjmpi    [1f]\", operands);
3211 ;      output_asm_insn (\".align        2\\n1:\", operands);
3212 ;      output_asm_insn (\".long %1\\n2:\", operands);
3213 ;      return \"\";
3214 ;    }
3215 ;  return \"bf  %l1\";
3216 ;}")
3219 ;;; Special patterns for dealing with the constant pool.
3221 ;;; 4 byte integer in line.
3223 (define_insn "consttable_4"
3224  [(unspec_volatile [(match_operand:SI 0 "general_operand" "=g")] 0)]
3225  ""
3226  "*
3228   assemble_integer (operands[0], 4, BITS_PER_WORD, 1);
3229   return \"\";
3231  [(set_attr "length" "4")])
3233 ;;; align to a four byte boundary.
3235 (define_insn "align_4"
3236  [(unspec_volatile [(const_int 0)] 1)]
3237  ""
3238  ".align 2")
3240 ;;; Handle extra constant pool entries created during final pass.
3242 (define_insn "consttable_end"
3243   [(unspec_volatile [(const_int 0)] 2)]
3244   ""
3245   "* return mcore_output_jump_label_table ();")
3248 ;; Stack allocation -- in particular, for alloca().
3249 ;; this is *not* what we use for entry into functions.
3251 ;; This is how we allocate stack space.  If we are allocating a
3252 ;; constant amount of space and we know it is less than 4096
3253 ;; bytes, we need do nothing.
3255 ;; If it is more than 4096 bytes, we need to probe the stack
3256 ;; periodically. 
3258 ;; operands[1], the distance is a POSITIVE number indicating that we
3259 ;; are allocating stack space
3261 (define_expand "allocate_stack"
3262   [(set (reg:SI 0)
3263         (plus:SI (reg:SI 0)
3264                  (match_operand:SI 1 "general_operand" "")))
3265    (set (match_operand:SI 0 "register_operand" "=r")
3266         (match_dup 2))]
3267   ""
3268   "
3270   /* If he wants no probing, just do it for him.  */
3271   if (mcore_stack_increment == 0)
3272     {
3273       emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,operands[1]));
3274 ;;      emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
3275       DONE;
3276     }
3278   /* For small constant growth, we unroll the code.  */
3279   if (GET_CODE (operands[1]) == CONST_INT
3280       && INTVAL (operands[1]) < 8 * STACK_UNITS_MAXSTEP)
3281     {
3282       HOST_WIDE_INT left = INTVAL(operands[1]);
3284       /* If it's a long way, get close enough for a last shot.  */
3285       if (left >= STACK_UNITS_MAXSTEP)
3286         {
3287           rtx tmp = gen_reg_rtx (Pmode);
3288           emit_insn (gen_movsi (tmp, GEN_INT (STACK_UNITS_MAXSTEP)));
3289           do
3290             {
3291               rtx memref = gen_rtx_MEM (SImode, stack_pointer_rtx);
3293               MEM_VOLATILE_P (memref) = 1;
3294               emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
3295               emit_insn (gen_movsi (memref, stack_pointer_rtx));
3296               left -= STACK_UNITS_MAXSTEP;
3297             }
3298           while (left > STACK_UNITS_MAXSTEP);
3299         }
3300       /* Perform the final adjustment.  */
3301       emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, GEN_INT (-left)));
3302 ;;      emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
3303       DONE;
3304     }
3305   else
3306     {
3307       rtx out_label = 0;
3308       rtx loop_label = gen_label_rtx ();
3309       rtx step = gen_reg_rtx (Pmode);
3310       rtx tmp = gen_reg_rtx (Pmode);
3311       rtx memref;
3313 #if 1
3314       emit_insn (gen_movsi (tmp, operands[1]));
3315       emit_insn (gen_movsi (step, GEN_INT (STACK_UNITS_MAXSTEP)));
3317       if (GET_CODE (operands[1]) != CONST_INT)
3318         {
3319           out_label = gen_label_rtx ();
3320           emit_insn (gen_cmpsi (step, tmp));            /* quick out */
3321           emit_jump_insn (gen_bgeu (out_label));
3322         }
3324       /* Run a loop that steps it incrementally.  */
3325       emit_label (loop_label);
3327       /* Extend a step, probe, and adjust remaining count.  */
3328       emit_insn(gen_subsi3(stack_pointer_rtx, stack_pointer_rtx, step));
3329       memref = gen_rtx_MEM (SImode, stack_pointer_rtx);
3330       MEM_VOLATILE_P (memref) = 1;
3331       emit_insn(gen_movsi(memref, stack_pointer_rtx));
3332       emit_insn(gen_subsi3(tmp, tmp, step));
3334       /* Loop condition -- going back up.  */
3335       emit_insn (gen_cmpsi (step, tmp));
3336       emit_jump_insn (gen_bltu (loop_label));
3338       if (out_label)
3339         emit_label (out_label);
3341       /* Bump the residual.  */
3342       emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
3343 ;;      emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
3344       DONE;
3345 #else
3346       /* simple one-shot -- ensure register and do a subtract.
3347        * This does NOT comply with the ABI.  */
3348       emit_insn (gen_movsi (tmp, operands[1]));
3349       emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
3350 ;;      emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
3351       DONE;
3352 #endif
3353     }