* config/v850/v850-protos.h: Remove the prototypes for
[official-gcc.git] / gcc / config / v850 / v850.md
blobb4dd0285c8d46f50aa670bd3a824a5d91f0df5e3
1 ;; GCC machine description for NEC V850
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2002, 2004, 2005
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Jeff Law (law@cygnus.com).
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 2, 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 COPYING.  If not, write to
20 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
23 ;; The original PO technology requires these to be ordered by speed,
24 ;; so that assigner will pick the fastest.
26 ;; See file "rtl.def" for documentation on define_insn, match_*, et. al.
28 ;; The V851 manual states that the instruction address space is 16M;
29 ;; the various branch/call instructions only have a 22bit offset (4M range).
31 ;; One day we'll probably need to handle calls to targets more than 4M
32 ;; away.
34 ;; The size of instructions in bytes.
36 (define_attr "length" ""
37   (const_int 4))
39 (define_attr "long_calls" "yes,no"
40   (const (if_then_else (symbol_ref "TARGET_LONG_CALLS")
41                        (const_string "yes")
42                        (const_string "no"))))
43             
44 ;; Types of instructions (for scheduling purposes).
46 (define_attr "type" "load,mult,other"
47   (const_string "other"))
49 ;; Condition code settings.
50 ;; none - insn does not affect cc
51 ;; none_0hit - insn does not affect cc but it does modify operand 0
52 ;;      This attribute is used to keep track of when operand 0 changes.
53 ;;      See the description of NOTICE_UPDATE_CC for more info.
54 ;; set_znv - sets z,n,v to usable values; c is unknown.
55 ;; set_zn  - sets z,n to usable values; v,c is unknown.
56 ;; compare - compare instruction
57 ;; clobber - value of cc is unknown
58 (define_attr "cc" "none,none_0hit,set_zn,set_znv,compare,clobber"
59   (const_string "clobber"))
61 ;; Function units for the V850.  As best as I can tell, there's
62 ;; a traditional memory load/use stall as well as a stall if
63 ;; the result of a multiply is used too early.
65 (define_insn_reservation "v850_other" 1
66                          (eq_attr "type" "other")
67                          "nothing")
68 (define_insn_reservation "v850_mult" 2
69                          (eq_attr "type" "mult")
70                          "nothing")
71 (define_insn_reservation "v850_memory" 2
72                          (eq_attr "type" "load")
73                          "nothing")
75 (include "predicates.md")
77 ;; ----------------------------------------------------------------------
78 ;; MOVE INSTRUCTIONS
79 ;; ----------------------------------------------------------------------
81 ;; movqi
83 (define_expand "movqi"
84   [(set (match_operand:QI 0 "general_operand" "")
85         (match_operand:QI 1 "general_operand" ""))]
86   ""
87   "
89   /* One of the ops has to be in a register or 0 */
90   if (!register_operand (operand0, QImode)
91       && !reg_or_0_operand (operand1, QImode))
92     operands[1] = copy_to_mode_reg (QImode, operand1);
93 }")
95 (define_insn "*movqi_internal"
96   [(set (match_operand:QI 0 "general_operand" "=r,r,r,Q,r,m,m")
97         (match_operand:QI 1 "general_operand" "Jr,n,Q,Ir,m,r,I"))]
98   "register_operand (operands[0], QImode)
99    || reg_or_0_operand (operands[1], QImode)"
100   "* return output_move_single (operands);"
101   [(set_attr "length" "2,4,2,2,4,4,4")
102    (set_attr "cc" "none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit")
103    (set_attr "type" "other,other,load,other,load,other,other")])
105 ;; movhi
107 (define_expand "movhi"
108   [(set (match_operand:HI 0 "general_operand" "")
109         (match_operand:HI 1 "general_operand" ""))]
110   ""
111   "
113   /* One of the ops has to be in a register or 0 */
114   if (!register_operand (operand0, HImode)
115       && !reg_or_0_operand (operand1, HImode))
116     operands[1] = copy_to_mode_reg (HImode, operand1);
119 (define_insn "*movhi_internal"
120   [(set (match_operand:HI 0 "general_operand" "=r,r,r,Q,r,m,m")
121         (match_operand:HI 1 "general_operand" "Jr,n,Q,Ir,m,r,I"))]
122   "register_operand (operands[0], HImode)
123    || reg_or_0_operand (operands[1], HImode)"
124   "* return output_move_single (operands);"
125   [(set_attr "length" "2,4,2,2,4,4,4")
126    (set_attr "cc" "none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit")
127    (set_attr "type" "other,other,load,other,load,other,other")])
129 ;; movsi and helpers
131 (define_insn "*movsi_high"
132   [(set (match_operand:SI 0 "register_operand" "=r")
133         (high:SI (match_operand 1 "" "")))]
134   ""
135   "movhi hi(%1),%.,%0"
136   [(set_attr "length" "4")
137    (set_attr "cc" "none_0hit")
138    (set_attr "type" "other")])
140 (define_insn "*movsi_lo"
141   [(set (match_operand:SI 0 "register_operand" "=r")
142         (lo_sum:SI (match_operand:SI 1 "register_operand" "r")
143                    (match_operand:SI 2 "immediate_operand" "i")))]
144   ""
145   "movea lo(%2),%1,%0"
146   [(set_attr "length" "4")
147    (set_attr "cc" "none_0hit")
148    (set_attr "type" "other")])
150 (define_expand "movsi"
151   [(set (match_operand:SI 0 "general_operand" "")
152         (match_operand:SI 1 "general_operand" ""))]
153   ""
154   "
156   /* One of the ops has to be in a register or 0 */
157   if (!register_operand (operand0, SImode)
158       && !reg_or_0_operand (operand1, SImode))
159     operands[1] = copy_to_mode_reg (SImode, operand1);
161   /* Some constants, as well as symbolic operands
162      must be done with HIGH & LO_SUM patterns.  */
163   if (CONSTANT_P (operands[1])
164       && GET_CODE (operands[1]) != HIGH
165       && ! TARGET_V850E
166       && !special_symbolref_operand (operands[1], VOIDmode)
167       && !(GET_CODE (operands[1]) == CONST_INT
168            && (CONST_OK_FOR_J (INTVAL (operands[1]))
169                || CONST_OK_FOR_K (INTVAL (operands[1]))
170                || CONST_OK_FOR_L (INTVAL (operands[1])))))
171     {
172       rtx temp;
174       if (reload_in_progress || reload_completed)
175         temp = operands[0];
176       else
177         temp = gen_reg_rtx (SImode);
179       emit_insn (gen_rtx_SET (SImode, temp,
180                               gen_rtx_HIGH (SImode, operand1)));
181       emit_insn (gen_rtx_SET (SImode, operand0,
182                               gen_rtx_LO_SUM (SImode, temp, operand1)));
183       DONE;
184     }
187 ;; This is the same as the following pattern, except that it includes
188 ;; support for arbitrary 32 bit immediates.
190 ;; ??? This always loads addresses using hilo.  If the only use of this address
191 ;; was in a load/store, then we would get smaller code if we only loaded the
192 ;; upper part with hi, and then put the lower part in the load/store insn.
194 (define_insn "*movsi_internal_v850e"
195   [(set (match_operand:SI 0 "general_operand" "=r,r,r,r,Q,r,r,m,m,r")
196         (match_operand:SI 1 "general_operand" "Jr,K,L,Q,Ir,m,R,r,I,i"))]
197   "TARGET_V850E
198    && (register_operand (operands[0], SImode)
199        || reg_or_0_operand (operands[1], SImode))"
200   "* return output_move_single (operands);"
201   [(set_attr "length" "2,4,4,2,2,4,4,4,4,6")
202    (set_attr "cc" "none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit")
203    (set_attr "type" "other,other,other,load,other,load,other,other,other,other")])
205 (define_insn "*movsi_internal"
206   [(set (match_operand:SI 0 "general_operand" "=r,r,r,r,Q,r,r,m,m")
207         (match_operand:SI 1 "movsi_source_operand" "Jr,K,L,Q,Ir,m,R,r,I"))]
208   "register_operand (operands[0], SImode)
209    || reg_or_0_operand (operands[1], SImode)"
210   "* return output_move_single (operands);"
211   [(set_attr "length" "2,4,4,2,2,4,4,4,4")
212    (set_attr "cc" "none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit")
213    (set_attr "type" "other,other,other,load,other,load,other,other,other")])
217 (define_expand "movdi"
218   [(set (match_operand:DI 0 "general_operand" "")
219         (match_operand:DI 1 "general_operand" ""))]
220   ""
221   "
223   /* One of the ops has to be in a register or 0 */
224   if (!register_operand (operand0, DImode)
225       && !reg_or_0_operand (operand1, DImode))
226     operands[1] = copy_to_mode_reg (DImode, operand1);
229 (define_insn "*movdi_internal"
230   [(set (match_operand:DI 0 "general_operand" "=r,r,r,r,r,m,m,r")
231         (match_operand:DI 1 "general_operand" "Jr,K,L,i,m,r,IG,iF"))]
232   "register_operand (operands[0], DImode)
233    || reg_or_0_operand (operands[1], DImode)"
234   "* return output_move_double (operands);"
235   [(set_attr "length" "4,8,8,16,8,8,8,16")
236    (set_attr "cc" "none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit")
237    (set_attr "type" "other,other,other,other,load,other,other,other")])
239 (define_expand "movsf"
240   [(set (match_operand:SF 0 "general_operand" "")
241         (match_operand:SF 1 "general_operand" ""))]
242   ""
243   "
245   /* One of the ops has to be in a register or 0 */
246   if (!register_operand (operand0, SFmode)
247       && !reg_or_0_operand (operand1, SFmode))
248     operands[1] = copy_to_mode_reg (SFmode, operand1);
251 (define_insn "*movsf_internal"
252   [(set (match_operand:SF 0 "general_operand" "=r,r,r,r,r,Q,r,m,m,r")
253         (match_operand:SF 1 "general_operand" "Jr,K,L,n,Q,Ir,m,r,IG,iF"))]
254   "register_operand (operands[0], SFmode)
255    || reg_or_0_operand (operands[1], SFmode)"
256   "* return output_move_single (operands);"
257   [(set_attr "length" "2,4,4,8,2,2,4,4,4,8")
258    (set_attr "cc" "none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit")
259    (set_attr "type" "other,other,other,other,load,other,load,other,other,other")])
261 (define_expand "movdf"
262   [(set (match_operand:DF 0 "general_operand" "")
263         (match_operand:DF 1 "general_operand" ""))]
264   ""
265   "
267   /* One of the ops has to be in a register or 0 */
268   if (!register_operand (operand0, DFmode)
269       && !reg_or_0_operand (operand1, DFmode))
270     operands[1] = copy_to_mode_reg (DFmode, operand1);
273 (define_insn "*movdf_internal"
274   [(set (match_operand:DF 0 "general_operand" "=r,r,r,r,r,m,m,r")
275         (match_operand:DF 1 "general_operand" "Jr,K,L,i,m,r,IG,iF"))]
276   "register_operand (operands[0], DFmode)
277    || reg_or_0_operand (operands[1], DFmode)"
278   "* return output_move_double (operands);"
279   [(set_attr "length" "4,8,8,16,8,8,8,16")
280    (set_attr "cc" "none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit,none_0hit")
281    (set_attr "type" "other,other,other,other,load,other,other,other")])
284 ;; ----------------------------------------------------------------------
285 ;; TEST INSTRUCTIONS
286 ;; ----------------------------------------------------------------------
288 (define_insn "*v850_tst1"
289   [(set (cc0) (zero_extract:SI (match_operand:QI 0 "memory_operand" "m")
290                                (const_int 1)
291                                (match_operand:QI 1 "const_int_operand" "n")))]
292   ""
293   "tst1 %1,%0"
294   [(set_attr "length" "4")
295    (set_attr "cc" "clobber")])
297 ;; This replaces ld.b;sar;andi with tst1;setf nz.
299 ;; ??? The zero_extract sets the Z bit to the opposite of what one would
300 ;; expect.  This perhaps should be wrapped in a (eq: X (const_int 0)).
302 (define_split
303   [(set (match_operand:SI 0 "register_operand" "")
304         (zero_extract:SI (match_operand:QI 1 "memory_operand" "")
305                          (const_int 1)
306                          (match_operand 2 "const_int_operand" "")))]
307   ""
308   [(set (cc0) (zero_extract:SI (match_dup 1)
309                                (const_int 1)
310                                (match_dup 2)))
311    (set (match_dup 0) (ne:SI (cc0) (const_int 0)))])
313 (define_insn "tstsi"
314   [(set (cc0) (match_operand:SI 0 "register_operand" "r"))]
315   ""
316   "cmp %.,%0"
317   [(set_attr "length" "2")
318    (set_attr "cc" "set_znv")])
320 (define_insn "cmpsi"
321   [(set (cc0)
322         (compare (match_operand:SI 0 "register_operand" "r,r")
323                  (match_operand:SI 1 "reg_or_int5_operand" "r,J")))]
324   ""
325   "@
326   cmp %1,%0
327   cmp %1,%0"
328   [(set_attr "length" "2,2")
329    (set_attr "cc" "compare")])
331 ;; ----------------------------------------------------------------------
332 ;; ADD INSTRUCTIONS
333 ;; ----------------------------------------------------------------------
335 (define_insn "addsi3"
336   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
337         (plus:SI (match_operand:SI 1 "register_operand" "%0,r,r")
338                  (match_operand:SI 2 "nonmemory_operand" "rJ,K,U")))]
339   ""
340   "@
341    add %2,%0
342    addi %2,%1,%0
343    addi %O2(%P2),%1,%0"
344   [(set_attr "length" "2,4,4")
345    (set_attr "cc" "set_zn,set_zn,set_zn")])
347 ;; ----------------------------------------------------------------------
348 ;; SUBTRACT INSTRUCTIONS
349 ;; ----------------------------------------------------------------------
351 (define_insn "subsi3"
352   [(set (match_operand:SI 0 "register_operand" "=r,r")
353         (minus:SI (match_operand:SI 1 "register_operand" "0,r")
354                   (match_operand:SI 2 "register_operand" "r,0")))]
355   ""
356   "@
357   sub %2,%0
358   subr %1,%0"
359   [(set_attr "length" "2,2")
360    (set_attr "cc" "set_zn")])
362 (define_insn "negsi2"
363   [(set (match_operand:SI 0 "register_operand" "=r")
364         (neg:SI (match_operand:SI 1 "register_operand" "0")))]
365   ""
366   "subr %.,%0"
367   [(set_attr "length" "2")
368    (set_attr "cc" "set_zn")])
370 ;; ----------------------------------------------------------------------
371 ;; MULTIPLY INSTRUCTIONS
372 ;; ----------------------------------------------------------------------
374 (define_expand "mulhisi3"
375   [(set (match_operand:SI 0 "register_operand" "")
376         (mult:SI
377           (sign_extend:SI (match_operand:HI 1 "register_operand" ""))
378           (sign_extend:SI (match_operand:HI 2 "nonmemory_operand" ""))))]
379   ""
380   "if (GET_CODE (operands[2]) == CONST_INT)
381      {
382        emit_insn (gen_mulhisi3_internal2 (operands[0], operands[1], operands[2]));
383        DONE;
384      }")
386 (define_insn "*mulhisi3_internal1"
387   [(set (match_operand:SI 0 "register_operand" "=r")
388         (mult:SI
389           (sign_extend:SI (match_operand:HI 1 "register_operand" "%0"))
390           (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
391   ""
392   "mulh %2,%0"
393   [(set_attr "length" "2")
394    (set_attr "cc" "none_0hit")
395    (set_attr "type" "mult")])
397 (define_insn "mulhisi3_internal2"
398   [(set (match_operand:SI 0 "register_operand" "=r,r")
399         (mult:SI
400           (sign_extend:SI (match_operand:HI 1 "register_operand" "%0,r"))
401           (match_operand:HI 2 "const_int_operand" "J,K")))]
402   ""
403   "@
404    mulh %2,%0
405    mulhi %2,%1,%0"
406   [(set_attr "length" "2,4")
407    (set_attr "cc" "none_0hit,none_0hit")
408    (set_attr "type" "mult")])
410 ;; ??? The scheduling info is probably wrong.
412 ;; ??? This instruction can also generate the 32 bit highpart, but using it
413 ;; may increase code size counter to the desired result.
415 ;; ??? This instructions can also give a DImode result.
417 ;; ??? There is unsigned version, but it matters only for the DImode/highpart
418 ;; results.
420 (define_insn "mulsi3"
421   [(set (match_operand:SI 0 "register_operand" "=r")
422         (mult:SI (match_operand:SI 1 "register_operand" "%0")
423                  (match_operand:SI 2 "reg_or_int9_operand" "rO")))]
424   "TARGET_V850E"
425   "mul %2,%1,%."
426   [(set_attr "length" "4")
427    (set_attr "cc" "none_0hit")
428    (set_attr "type" "mult")])
430 ;; ----------------------------------------------------------------------
431 ;; DIVIDE INSTRUCTIONS
432 ;; ----------------------------------------------------------------------
434 ;; ??? These insns do set the Z/N condition codes, except that they are based
435 ;; on only one of the two results, so it doesn't seem to make sense to use
436 ;; them.
438 ;; ??? The scheduling info is probably wrong.
440 (define_insn "divmodsi4"
441   [(set (match_operand:SI 0 "register_operand" "=r")
442         (div:SI (match_operand:SI 1 "register_operand" "0")
443                 (match_operand:SI 2 "register_operand" "r")))
444    (set (match_operand:SI 3 "register_operand" "=r")
445         (mod:SI (match_dup 1)
446                 (match_dup 2)))]
447   "TARGET_V850E"
448   "div %2,%0,%3"
449   [(set_attr "length" "4")
450    (set_attr "cc" "clobber")
451    (set_attr "type" "other")])
452         
453 (define_insn "udivmodsi4"
454   [(set (match_operand:SI 0 "register_operand" "=r")
455         (udiv:SI (match_operand:SI 1 "register_operand" "0")
456                  (match_operand:SI 2 "register_operand" "r")))
457    (set (match_operand:SI 3 "register_operand" "=r")
458         (umod:SI (match_dup 1)
459                  (match_dup 2)))]
460   "TARGET_V850E"
461   "divu %2,%0,%3"
462   [(set_attr "length" "4")
463    (set_attr "cc" "clobber")
464    (set_attr "type" "other")])
465         
466 ;; ??? There is a 2 byte instruction for generating only the quotient.
467 ;; However, it isn't clear how to compute the length field correctly.
469 (define_insn "divmodhi4"
470   [(set (match_operand:HI 0 "register_operand" "=r")
471         (div:HI (match_operand:HI 1 "register_operand" "0")
472                 (match_operand:HI 2 "register_operand" "r")))
473    (set (match_operand:HI 3 "register_operand" "=r")
474         (mod:HI (match_dup 1)
475                 (match_dup 2)))]
476   "TARGET_V850E"
477   "divh %2,%0,%3"
478   [(set_attr "length" "4")
479    (set_attr "cc" "clobber")
480    (set_attr "type" "other")])
482 ;; Half-words are sign-extended by default, so we must zero extend to a word
483 ;; here before doing the divide.
485 (define_insn "udivmodhi4"
486   [(set (match_operand:HI 0 "register_operand" "=r")
487         (udiv:HI (match_operand:HI 1 "register_operand" "0")
488                  (match_operand:HI 2 "register_operand" "r")))
489    (set (match_operand:HI 3 "register_operand" "=r")
490         (umod:HI (match_dup 1)
491                  (match_dup 2)))]
492   "TARGET_V850E"
493   "zxh %0 ; divhu %2,%0,%3"
494   [(set_attr "length" "4")
495    (set_attr "cc" "clobber")
496    (set_attr "type" "other")])
498 ;; ----------------------------------------------------------------------
499 ;; AND INSTRUCTIONS
500 ;; ----------------------------------------------------------------------
502 (define_insn "*v850_clr1_1"
503   [(set (match_operand:QI 0 "memory_operand" "=m")
504         (subreg:QI
505           (and:SI (subreg:SI (match_dup 0) 0)
506                   (match_operand:QI 1 "not_power_of_two_operand" "")) 0))]
507   ""
508   "*
510   rtx xoperands[2];
511   xoperands[0] = operands[0];
512   xoperands[1] = GEN_INT (~INTVAL (operands[1]) & 0xff);
513   output_asm_insn (\"clr1 %M1,%0\", xoperands);
514   return \"\";
516   [(set_attr "length" "4")
517    (set_attr "cc" "clobber")])
519 (define_insn "*v850_clr1_2"
520   [(set (match_operand:HI 0 "indirect_operand" "=m")
521         (subreg:HI
522           (and:SI (subreg:SI (match_dup 0) 0)
523                   (match_operand:HI 1 "not_power_of_two_operand" "")) 0))]
524   ""
525   "*
527   int log2 = exact_log2 (~INTVAL (operands[1]) & 0xffff);
529   rtx xoperands[2];
530   xoperands[0] = gen_rtx_MEM (QImode,
531                               plus_constant (XEXP (operands[0], 0), log2 / 8));
532   xoperands[1] = GEN_INT (log2 % 8);
533   output_asm_insn (\"clr1 %1,%0\", xoperands);
534   return \"\";
536   [(set_attr "length" "4")
537    (set_attr "cc" "clobber")])
539 (define_insn "*v850_clr1_3"
540   [(set (match_operand:SI 0 "indirect_operand" "=m")
541         (and:SI (match_dup 0)
542                 (match_operand:SI 1 "not_power_of_two_operand" "")))]
543   ""
544   "*
546   int log2 = exact_log2 (~INTVAL (operands[1]) & 0xffffffff);
548   rtx xoperands[2];
549   xoperands[0] = gen_rtx_MEM (QImode,
550                               plus_constant (XEXP (operands[0], 0), log2 / 8));
551   xoperands[1] = GEN_INT (log2 % 8);
552   output_asm_insn (\"clr1 %1,%0\", xoperands);
553   return \"\";
555   [(set_attr "length" "4")
556    (set_attr "cc" "clobber")])
558 (define_insn "andsi3"
559   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
560         (and:SI (match_operand:SI 1 "register_operand" "%0,0,r")
561                 (match_operand:SI 2 "nonmemory_operand" "r,I,M")))]
562   ""
563   "@
564   and %2,%0
565   and %.,%0
566   andi %2,%1,%0"
567   [(set_attr "length" "2,2,4")
568    (set_attr "cc" "set_znv")])
570 ;; ----------------------------------------------------------------------
571 ;; OR INSTRUCTIONS
572 ;; ----------------------------------------------------------------------
574 (define_insn "*v850_set1_1"
575   [(set (match_operand:QI 0 "memory_operand" "=m")
576         (subreg:QI (ior:SI (subreg:SI (match_dup 0) 0)
577                            (match_operand 1 "power_of_two_operand" "")) 0))]
578   ""
579   "set1 %M1,%0"
580   [(set_attr "length" "4")
581    (set_attr "cc" "clobber")])
583 (define_insn "*v850_set1_2"
584   [(set (match_operand:HI 0 "indirect_operand" "=m")
585         (subreg:HI (ior:SI (subreg:SI (match_dup 0) 0)
586                            (match_operand 1 "power_of_two_operand" "")) 0))]
587   ""
588   "*
590   int log2 = exact_log2 (INTVAL (operands[1]));
592   if (log2 < 8)
593     return \"set1 %M1,%0\";
594   else
595     {
596       rtx xoperands[2];
597       xoperands[0] = gen_rtx_MEM (QImode,
598                                   plus_constant (XEXP (operands[0], 0),
599                                                  log2 / 8));
600       xoperands[1] = GEN_INT (log2 % 8);
601       output_asm_insn (\"set1 %1,%0\", xoperands);
602     }
603   return \"\";
605   [(set_attr "length" "4")
606    (set_attr "cc" "clobber")])
608 (define_insn "*v850_set1_3"
609   [(set (match_operand:SI 0 "indirect_operand" "=m")
610         (ior:SI (match_dup 0)
611                 (match_operand 1 "power_of_two_operand" "")))]
612   ""
613   "*
615   int log2 = exact_log2 (INTVAL (operands[1]));
617   if (log2 < 8)
618     return \"set1 %M1,%0\";
619   else
620     {
621       rtx xoperands[2];
622       xoperands[0] = gen_rtx_MEM (QImode,
623                                   plus_constant (XEXP (operands[0], 0),
624                                                  log2 / 8));
625       xoperands[1] = GEN_INT (log2 % 8);
626       output_asm_insn (\"set1 %1,%0\", xoperands);
627     }
628   return \"\";
630   [(set_attr "length" "4")
631    (set_attr "cc" "clobber")])
633 (define_insn "iorsi3"
634   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
635         (ior:SI (match_operand:SI 1 "register_operand" "%0,0,r")
636                 (match_operand:SI 2 "nonmemory_operand" "r,I,M")))]
637   ""
638   "@
639   or %2,%0
640   or %.,%0
641   ori %2,%1,%0"
642   [(set_attr "length" "2,2,4")
643    (set_attr "cc" "set_znv")])
645 ;; ----------------------------------------------------------------------
646 ;; XOR INSTRUCTIONS
647 ;; ----------------------------------------------------------------------
649 (define_insn "*v850_not1_1"
650   [(set (match_operand:QI 0 "memory_operand" "=m")
651         (subreg:QI (xor:SI (subreg:SI (match_dup 0) 0)
652                            (match_operand 1 "power_of_two_operand" "")) 0))]
653   ""
654   "not1 %M1,%0"
655   [(set_attr "length" "4")
656    (set_attr "cc" "clobber")])
658 (define_insn "*v850_not1_2"
659   [(set (match_operand:HI 0 "indirect_operand" "=m")
660         (subreg:HI (xor:SI (subreg:SI (match_dup 0) 0)
661                            (match_operand 1 "power_of_two_operand" "")) 0))]
662   ""
663   "*
665   int log2 = exact_log2 (INTVAL (operands[1]));
667   if (log2 < 8)
668     return \"not1 %M1,%0\";
669   else
670     {
671       rtx xoperands[2];
672       xoperands[0] = gen_rtx_MEM (QImode,
673                                   plus_constant (XEXP (operands[0], 0),
674                                                  log2 / 8));
675       xoperands[1] = GEN_INT (log2 % 8);
676       output_asm_insn (\"not1 %1,%0\", xoperands);
677     }
678   return \"\";
680   [(set_attr "length" "4")
681    (set_attr "cc" "clobber")])
683 (define_insn "*v850_not1_3"
684   [(set (match_operand:SI 0 "indirect_operand" "=m")
685         (xor:SI (match_dup 0)
686                 (match_operand 1 "power_of_two_operand" "")))]
687   ""
688   "*
690   int log2 = exact_log2 (INTVAL (operands[1]));
692   if (log2 < 8)
693     return \"not1 %M1,%0\";
694   else
695     {
696       rtx xoperands[2];
697       xoperands[0] = gen_rtx_MEM (QImode,
698                                   plus_constant (XEXP (operands[0], 0),
699                                                  log2 / 8));
700       xoperands[1] = GEN_INT (log2 % 8);
701       output_asm_insn (\"not1 %1,%0\", xoperands);
702     }
703   return \"\";
705   [(set_attr "length" "4")
706    (set_attr "cc" "clobber")])
708 (define_insn "xorsi3"
709   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
710         (xor:SI (match_operand:SI 1 "register_operand" "%0,0,r")
711                 (match_operand:SI 2 "nonmemory_operand" "r,I,M")))]
712   ""
713   "@
714   xor %2,%0
715   xor %.,%0
716   xori %2,%1,%0"
717   [(set_attr "length" "2,2,4")
718    (set_attr "cc" "set_znv")])
720 ;; ----------------------------------------------------------------------
721 ;; NOT INSTRUCTIONS
722 ;; ----------------------------------------------------------------------
724 (define_insn "one_cmplsi2"
725   [(set (match_operand:SI 0 "register_operand" "=r")
726         (not:SI (match_operand:SI 1 "register_operand" "r")))]
727   ""
728   "not %1,%0"
729   [(set_attr "length" "2")
730    (set_attr "cc" "set_znv")])
732 ;; -----------------------------------------------------------------
733 ;; BIT FIELDS
734 ;; -----------------------------------------------------------------
736 ;; ??? Is it worth defining insv and extv for the V850 series?!?
738 ;; An insv pattern would be useful, but does not get used because
739 ;; store_bit_field never calls insv when storing a constant value into a
740 ;; single-bit bitfield.
742 ;; extv/extzv patterns would be useful, but do not get used because
743 ;; optimize_bitfield_compare in fold-const usually converts single
744 ;; bit extracts into an AND with a mask.
746 ;; -----------------------------------------------------------------
747 ;; Scc INSTRUCTIONS
748 ;; -----------------------------------------------------------------
750 (define_insn "sle"
751   [(set (match_operand:SI 0 "register_operand" "=r")
752         (le:SI (cc0) (const_int 0)))]
753   ""
754   "*
756   if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0)
757     return 0;
759   return \"setf le,%0\";
761   [(set_attr "length" "4")
762    (set_attr "cc" "none_0hit")])
764 (define_insn "sleu"
765   [(set (match_operand:SI 0 "register_operand" "=r")
766         (leu:SI (cc0) (const_int 0)))]
767   ""
768   "setf nh,%0"
769   [(set_attr "length" "4")
770    (set_attr "cc" "none_0hit")])
772 (define_insn "sge"
773   [(set (match_operand:SI 0 "register_operand" "=r")
774         (ge:SI (cc0) (const_int 0)))]
775   ""
776   "*
778   if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0)
779     return 0;
781   return \"setf ge,%0\";
783   [(set_attr "length" "4")
784    (set_attr "cc" "none_0hit")])
786 (define_insn "sgeu"
787   [(set (match_operand:SI 0 "register_operand" "=r")
788         (geu:SI (cc0) (const_int 0)))]
789   ""
790   "setf nl,%0"
791   [(set_attr "length" "4")
792    (set_attr "cc" "none_0hit")])
794 (define_insn "slt"
795   [(set (match_operand:SI 0 "register_operand" "=r")
796         (lt:SI (cc0) (const_int 0)))]
797   ""
798   "*
800   if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0)
801     return 0;
803   return \"setf lt,%0\";
805   [(set_attr "length" "4")
806    (set_attr "cc" "none_0hit")])
808 (define_insn "sltu"
809   [(set (match_operand:SI 0 "register_operand" "=r")
810         (ltu:SI (cc0) (const_int 0)))]
811   ""
812   "setf l,%0"
813   [(set_attr "length" "4")
814    (set_attr "cc" "none_0hit")])
816 (define_insn "sgt"
817   [(set (match_operand:SI 0 "register_operand" "=r")
818         (gt:SI (cc0) (const_int 0)))]
819   ""
820   "*
822   if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0)
823     return 0;
825   return \"setf gt,%0\";
827   [(set_attr "length" "4")
828    (set_attr "cc" "none_0hit")])
830 (define_insn "sgtu"
831   [(set (match_operand:SI 0 "register_operand" "=r")
832         (gtu:SI (cc0) (const_int 0)))]
833   ""
834   "setf h,%0"
835   [(set_attr "length" "4")
836    (set_attr "cc" "none_0hit")])
838 (define_insn "seq"
839   [(set (match_operand:SI 0 "register_operand" "=r")
840         (eq:SI (cc0) (const_int 0)))]
841   ""
842   "setf z,%0"
843   [(set_attr "length" "4")
844    (set_attr "cc" "none_0hit")])
846 (define_insn "sne"
847   [(set (match_operand:SI 0 "register_operand" "=r")
848         (ne:SI (cc0) (const_int 0)))]
849   ""
850   "setf nz,%0"
851   [(set_attr "length" "4")
852    (set_attr "cc" "none_0hit")])
854 ;; ----------------------------------------------------------------------
855 ;; CONDITIONAL MOVE INSTRUCTIONS
856 ;; ----------------------------------------------------------------------
858 ;; Instructions using cc0 aren't allowed to have input reloads, so we must
859 ;; hide the fact that this instruction uses cc0.  We do so by including the
860 ;; compare instruction inside it.
862 ;; ??? This is very ugly.  The right way to do this is to modify cmpsi so
863 ;; that it doesn't emit RTL, and then modify the bcc/scc patterns so that
864 ;; they emit RTL for the compare instruction.  Unfortunately, this requires
865 ;; lots of changes that will be hard to sanitize.  So for now, cmpsi still
866 ;; emits RTL, and I get the compare operands here from the previous insn.
868 (define_expand "movsicc"
869   [(set (match_operand:SI 0 "register_operand" "=r")
870         (if_then_else:SI
871          (match_operator 1 "comparison_operator"
872                          [(match_dup 4) (match_dup 5)])
873          (match_operand:SI 2 "reg_or_const_operand" "rJ")
874          (match_operand:SI 3 "reg_or_const_operand" "rI")))]
875   "TARGET_V850E"
876   "
878   rtx insn = get_last_insn_anywhere ();
880   if (   (GET_CODE (operands[2]) == CONST_INT
881        && GET_CODE (operands[3]) == CONST_INT))
882     {
883       int o2 = INTVAL (operands[2]);
884       int o3 = INTVAL (operands[3]);
886       if (o2 == 1 && o3 == 0)
887         FAIL;   /* setf */
888       if (o3 == 1 && o2 == 0)
889         FAIL;   /* setf */
890       if (o2 == 0 && (o3 < -16 || o3 > 15) && exact_log2 (o3) >= 0)
891         FAIL;   /* setf + shift */
892       if (o3 == 0 && (o2 < -16 || o2 > 15) && exact_log2 (o2) >=0)
893         FAIL;   /* setf + shift */
894       if (o2 != 0)
895         operands[2] = copy_to_mode_reg (SImode, operands[2]);
896       if (o3 !=0 )
897         operands[3] = copy_to_mode_reg (SImode, operands[3]);
898     }
899   else
900     {
901       if (GET_CODE (operands[2]) != REG)
902         operands[2] = copy_to_mode_reg (SImode,operands[2]);
903       if (GET_CODE (operands[3]) != REG)
904         operands[3] = copy_to_mode_reg (SImode, operands[3]);
905     }
906   if (GET_CODE (insn) == INSN
907       && GET_CODE (PATTERN (insn)) == SET
908       && SET_DEST (PATTERN (insn)) == cc0_rtx)
909     {
910       rtx src = SET_SRC (PATTERN (insn));
912       if (GET_CODE (src) == COMPARE)
913         {
914           operands[4] = XEXP (src, 0);
915           operands[5] = XEXP (src, 1);
916         }
917       else if (GET_CODE (src) == REG
918                || GET_CODE (src) == SUBREG)
919         {
920           operands[4] = src;
921           operands[5] = const0_rtx;
922         }
923       else
924         abort ();
925     }
926   else
927     abort ();
930 ;; ??? Clobbering the condition codes is overkill.
932 ;; ??? We sometimes emit an unnecessary compare instruction because the
933 ;; condition codes may have already been set by an earlier instruction,
934 ;; but we have no code here to avoid the compare if it is unnecessary.
936 (define_insn "*movsicc_normal"
937   [(set (match_operand:SI 0 "register_operand" "=r")
938         (if_then_else:SI
939          (match_operator 1 "comparison_operator"
940                          [(match_operand:SI 4 "register_operand" "r")
941                           (match_operand:SI 5 "reg_or_int5_operand" "rJ")])
942          (match_operand:SI 2 "reg_or_int5_operand" "rJ")
943          (match_operand:SI 3 "reg_or_0_operand" "rI")))]
944   "TARGET_V850E"
945   "cmp %5,%4 ; cmov %c1,%2,%z3,%0"
946   [(set_attr "length" "6")
947    (set_attr "cc" "clobber")])
949 (define_insn "*movsicc_reversed"
950   [(set (match_operand:SI 0 "register_operand" "=r")
951         (if_then_else:SI
952          (match_operator 1 "comparison_operator"
953                          [(match_operand:SI 4 "register_operand" "r")
954                           (match_operand:SI 5 "reg_or_int5_operand" "rJ")])
955          (match_operand:SI 2 "reg_or_0_operand" "rI")
956          (match_operand:SI 3 "reg_or_int5_operand" "rJ")))]
957   "TARGET_V850E"
958   "cmp %5,%4 ; cmov %C1,%3,%z2,%0"
959   [(set_attr "length" "6")
960    (set_attr "cc" "clobber")])
962 (define_insn "*movsicc_tst1"
963   [(set (match_operand:SI 0 "register_operand" "=r")
964         (if_then_else:SI
965          (match_operator 1 "comparison_operator"
966                          [(zero_extract:SI
967                            (match_operand:QI 2 "memory_operand" "m")
968                            (const_int 1)
969                            (match_operand 3 "const_int_operand" "n"))
970                           (const_int 0)])
971          (match_operand:SI 4 "reg_or_int5_operand" "rJ")
972          (match_operand:SI 5 "reg_or_0_operand" "rI")))]
973   "TARGET_V850E"
974   "tst1 %3,%2 ; cmov %c1,%4,%z5,%0"
975   [(set_attr "length" "8")
976    (set_attr "cc" "clobber")])
978 (define_insn "*movsicc_tst1_reversed"
979   [(set (match_operand:SI 0 "register_operand" "=r")
980         (if_then_else:SI
981          (match_operator 1 "comparison_operator"
982                          [(zero_extract:SI
983                            (match_operand:QI 2 "memory_operand" "m")
984                            (const_int 1)
985                            (match_operand 3 "const_int_operand" "n"))
986                           (const_int 0)])
987          (match_operand:SI 4 "reg_or_0_operand" "rI")
988          (match_operand:SI 5 "reg_or_int5_operand" "rJ")))]
989   "TARGET_V850E"
990   "tst1 %3,%2 ; cmov %C1,%5,%z4,%0"
991   [(set_attr "length" "8")
992    (set_attr "cc" "clobber")])
994 ;; Matching for sasf requires combining 4 instructions, so we provide a
995 ;; dummy pattern to match the first 3, which will always be turned into the
996 ;; second pattern by subsequent combining.  As above, we must include the
997 ;; comparison to avoid input reloads in an insn using cc0.
999 (define_insn "*sasf_1"
1000   [(set (match_operand:SI 0 "register_operand" "")
1001         (ior:SI (match_operator 1 "comparison_operator" [(cc0) (const_int 0)])
1002                 (ashift:SI (match_operand:SI 2 "register_operand" "")
1003                            (const_int 1))))]
1004   "TARGET_V850E"
1005   "* abort ();")
1007 (define_insn "*sasf_2"
1008   [(set (match_operand:SI 0 "register_operand" "=r")
1009         (ior:SI
1010          (match_operator 1 "comparison_operator"
1011                          [(match_operand:SI 3 "register_operand" "r")
1012                           (match_operand:SI 4 "reg_or_int5_operand" "rJ")])
1013          (ashift:SI (match_operand:SI 2 "register_operand" "0")
1014                     (const_int 1))))]
1015   "TARGET_V850E"
1016   "cmp %4,%3 ; sasf %c1,%0"
1017   [(set_attr "length" "6")
1018    (set_attr "cc" "clobber")])
1020 (define_split
1021   [(set (match_operand:SI 0 "register_operand" "")
1022         (if_then_else:SI
1023          (match_operator 1 "comparison_operator"
1024                          [(match_operand:SI 4 "register_operand" "")
1025                           (match_operand:SI 5 "reg_or_int5_operand" "")])
1026          (match_operand:SI 2 "const_int_operand" "")
1027          (match_operand:SI 3 "const_int_operand" "")))]
1028   "TARGET_V850E
1029    && ((INTVAL (operands[2]) ^ INTVAL (operands[3])) == 1)
1030    && ((INTVAL (operands[2]) + INTVAL (operands[3])) != 1)
1031    && (GET_CODE (operands[5]) == CONST_INT
1032       || REGNO (operands[0]) != REGNO (operands[5]))
1033    && REGNO (operands[0]) != REGNO (operands[4])"
1034   [(set (match_dup 0) (match_dup 6))
1035    (set (match_dup 0)
1036         (ior:SI (match_op_dup 7 [(match_dup 4) (match_dup 5)])
1037                 (ashift:SI (match_dup 0) (const_int 1))))]
1038   "
1040   operands[6] = GEN_INT (INTVAL (operands[2]) >> 1);
1041   if (INTVAL (operands[2]) & 0x1)
1042     operands[7] = operands[1];
1043   else
1044     operands[7] = gen_rtx_fmt_ee (reverse_condition (GET_CODE (operands[1])),
1045                                   GET_MODE (operands[1]),
1046                                   XEXP (operands[1], 0), XEXP (operands[1], 1));
1048 ;; ---------------------------------------------------------------------
1049 ;; BYTE SWAP INSTRUCTIONS
1050 ;; ---------------------------------------------------------------------
1052 (define_expand "rotlhi3"
1053   [(set (match_operand:HI 0 "register_operand" "")
1054         (rotate:HI (match_operand:HI 1 "register_operand" "")
1055                    (match_operand:HI 2 "const_int_operand" "")))]
1056   "TARGET_V850E"
1057   "
1059   if (INTVAL (operands[2]) != 8)
1060     FAIL;
1063 (define_insn "*rotlhi3_8"
1064   [(set (match_operand:HI 0 "register_operand" "=r")
1065         (rotate:HI (match_operand:HI 1 "register_operand" "r")
1066                    (const_int 8)))]
1067   "TARGET_V850E"
1068   "bsh %1,%0"
1069   [(set_attr "length" "4")
1070    (set_attr "cc" "clobber")])
1072 (define_expand "rotlsi3"
1073   [(set (match_operand:SI 0 "register_operand" "")
1074         (rotate:SI (match_operand:SI 1 "register_operand" "")
1075                    (match_operand:SI 2 "const_int_operand" "")))]
1076   "TARGET_V850E"
1077   "
1079   if (INTVAL (operands[2]) != 16)
1080     FAIL;
1083 (define_insn "*rotlsi3_16"
1084   [(set (match_operand:SI 0 "register_operand" "=r")
1085         (rotate:SI (match_operand:SI 1 "register_operand" "r")
1086                    (const_int 16)))]
1087   "TARGET_V850E"
1088   "hsw %1,%0"
1089   [(set_attr "length" "4")
1090    (set_attr "cc" "clobber")])
1092 ;; ----------------------------------------------------------------------
1093 ;; JUMP INSTRUCTIONS
1094 ;; ----------------------------------------------------------------------
1096 ;; Conditional jump instructions
1098 (define_expand "ble"
1099   [(set (pc)
1100         (if_then_else (le (cc0)
1101                           (const_int 0))
1102                       (label_ref (match_operand 0 "" ""))
1103                       (pc)))]
1104   ""
1105   "")
1107 (define_expand "bleu"
1108   [(set (pc)
1109         (if_then_else (leu (cc0)
1110                            (const_int 0))
1111                       (label_ref (match_operand 0 "" ""))
1112                       (pc)))]
1113   ""
1114   "")
1116 (define_expand "bge"
1117   [(set (pc)
1118         (if_then_else (ge (cc0)
1119                           (const_int 0))
1120                       (label_ref (match_operand 0 "" ""))
1121                       (pc)))]
1122   ""
1123   "")
1125 (define_expand "bgeu"
1126   [(set (pc)
1127         (if_then_else (geu (cc0)
1128                            (const_int 0))
1129                       (label_ref (match_operand 0 "" ""))
1130                       (pc)))]
1131   ""
1132   "")
1134 (define_expand "blt"
1135   [(set (pc)
1136         (if_then_else (lt (cc0)
1137                           (const_int 0))
1138                       (label_ref (match_operand 0 "" ""))
1139                       (pc)))]
1140   ""
1141   "")
1143 (define_expand "bltu"
1144   [(set (pc)
1145         (if_then_else (ltu (cc0)
1146                            (const_int 0))
1147                       (label_ref (match_operand 0 "" ""))
1148                       (pc)))]
1149   ""
1150   "")
1152 (define_expand "bgt"
1153   [(set (pc)
1154         (if_then_else (gt (cc0)
1155                           (const_int 0))
1156                       (label_ref (match_operand 0 "" ""))
1157                       (pc)))]
1158   ""
1159   "")
1161 (define_expand "bgtu"
1162   [(set (pc)
1163         (if_then_else (gtu (cc0)
1164                            (const_int 0))
1165                       (label_ref (match_operand 0 "" ""))
1166                       (pc)))]
1167   ""
1168   "")
1170 (define_expand "beq"
1171   [(set (pc)
1172         (if_then_else (eq (cc0)
1173                           (const_int 0))
1174                       (label_ref (match_operand 0 "" ""))
1175                       (pc)))]
1176   ""
1177   "")
1179 (define_expand "bne"
1180   [(set (pc)
1181         (if_then_else (ne (cc0)
1182                           (const_int 0))
1183                       (label_ref (match_operand 0 "" ""))
1184                       (pc)))]
1185   ""
1186   "")
1188 (define_insn "*branch_normal"
1189   [(set (pc)
1190         (if_then_else (match_operator 1 "comparison_operator"
1191                                       [(cc0) (const_int 0)])
1192                       (label_ref (match_operand 0 "" ""))
1193                       (pc)))]
1194   ""
1195   "*
1197   if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
1198       && (GET_CODE (operands[1]) == GT
1199           || GET_CODE (operands[1]) == GE
1200           || GET_CODE (operands[1]) == LE
1201           || GET_CODE (operands[1]) == LT))
1202     return 0;
1204   if (get_attr_length (insn) == 2)
1205     return \"b%b1 %l0\";
1206   else
1207     return \"b%B1 .+6 ; jr %l0\";
1209  [(set (attr "length")
1210     (if_then_else (lt (abs (minus (match_dup 0) (pc)))
1211                       (const_int 256))
1212                   (const_int 2)
1213                   (const_int 6)))
1214   (set_attr "cc" "none")])
1216 (define_insn "*branch_invert"
1217   [(set (pc)
1218         (if_then_else (match_operator 1 "comparison_operator"
1219                                       [(cc0) (const_int 0)])
1220                       (pc)
1221                       (label_ref (match_operand 0 "" ""))))]
1222   ""
1223   "*
1225   if ((cc_status.flags & CC_OVERFLOW_UNUSABLE) != 0
1226       && (GET_CODE (operands[1]) == GT
1227           || GET_CODE (operands[1]) == GE
1228           || GET_CODE (operands[1]) == LE
1229           || GET_CODE (operands[1]) == LT))
1230     return 0;
1231   if (get_attr_length (insn) == 2)
1232     return \"b%B1 %l0\";
1233   else
1234     return \"b%b1 .+6 ; jr %l0\";
1236  [(set (attr "length")
1237     (if_then_else (lt (abs (minus (match_dup 0) (pc)))
1238                       (const_int 256))
1239                   (const_int 2)
1240                   (const_int 6)))
1241   (set_attr "cc" "none")])
1243 ;; Unconditional and other jump instructions.
1245 (define_insn "jump"
1246   [(set (pc)
1247         (label_ref (match_operand 0 "" "")))]
1248   ""
1249   "*
1251   if (get_attr_length (insn) == 2)
1252     return \"br %0\";
1253   else
1254     return \"jr %0\";
1256  [(set (attr "length")
1257     (if_then_else (lt (abs (minus (match_dup 0) (pc)))
1258                       (const_int 256))
1259                   (const_int 2)
1260                   (const_int 4)))
1261   (set_attr "cc" "none")])
1263 (define_insn "indirect_jump"
1264   [(set (pc) (match_operand:SI 0 "register_operand" "r"))]
1265   ""
1266   "jmp %0"
1267   [(set_attr "length" "2")
1268    (set_attr "cc" "none")])
1270 (define_insn "tablejump"
1271   [(set (pc) (match_operand:SI 0 "register_operand" "r"))
1272    (use (label_ref (match_operand 1 "" "")))]
1273   ""
1274   "jmp  %0"
1275   [(set_attr "length" "2")
1276    (set_attr "cc" "none")])
1278 (define_insn "switch"
1279   [(set (pc)
1280         (plus:SI
1281          (sign_extend:SI
1282           (mem:HI
1283            (plus:SI (ashift:SI (match_operand:SI 0 "register_operand" "r")
1284                                (const_int 1))
1285                     (label_ref (match_operand 1 "" "")))))
1286          (label_ref (match_dup 1))))]
1287   "TARGET_V850E"
1288   "switch %0"
1289   [(set_attr "length" "2")
1290    (set_attr "cc" "none")])
1292 (define_expand "casesi"
1293   [(match_operand:SI 0 "register_operand" "")
1294    (match_operand:SI 1 "register_operand" "")
1295    (match_operand:SI 2 "register_operand" "")
1296    (match_operand 3 "" "") (match_operand 4 "" "")]
1297   ""
1298   "
1300   rtx reg = gen_reg_rtx (SImode);
1301   rtx tableaddress = gen_reg_rtx (SImode);
1302   rtx mem;
1304   /* Subtract the lower bound from the index.  */
1305   emit_insn (gen_subsi3 (reg, operands[0], operands[1]));
1306   /* Compare the result against the number of table entries.  */
1307   emit_insn (gen_cmpsi (reg, operands[2]));
1308   /* Branch to the default label if out of range of the table.  */
1309   emit_jump_insn (gen_bgtu (operands[4]));
1311   if (! TARGET_BIG_SWITCH && TARGET_V850E)
1312     {
1313       emit_jump_insn (gen_switch (reg, operands[3]));
1314       DONE;
1315     }
1317   /* Shift index for the table array access.  */
1318   emit_insn (gen_ashlsi3 (reg, reg, GEN_INT (TARGET_BIG_SWITCH ? 2 : 1)));
1319   /* Load the table address into a pseudo.  */
1320   emit_insn (gen_movsi (tableaddress,
1321                         gen_rtx_LABEL_REF (Pmode, operands[3])));
1322   /* Add the table address to the index.  */
1323   emit_insn (gen_addsi3 (reg, reg, tableaddress));
1324   /* Load the table entry.  */
1325   mem = gen_const_mem (CASE_VECTOR_MODE, reg);
1326   if (! TARGET_BIG_SWITCH)
1327     {
1328       rtx reg2 = gen_reg_rtx (HImode);
1329       emit_insn (gen_movhi (reg2, mem));
1330       emit_insn (gen_extendhisi2 (reg, reg2));
1331     }
1332   else
1333     emit_insn (gen_movsi (reg, mem));
1334   /* Add the table address.  */
1335   emit_insn (gen_addsi3 (reg, reg, tableaddress));
1336   /* Branch to the switch label.  */
1337   emit_jump_insn (gen_tablejump (reg, operands[3]));
1338   DONE;
1341 ;; Call subroutine with no return value.
1343 (define_expand "call"
1344   [(call (match_operand:QI 0 "general_operand" "")
1345          (match_operand:SI 1 "general_operand" ""))]
1346   ""
1347   "
1349   if (! call_address_operand (XEXP (operands[0], 0), QImode)
1350       || TARGET_LONG_CALLS)
1351     XEXP (operands[0], 0) = force_reg (SImode, XEXP (operands[0], 0));
1352   if (TARGET_LONG_CALLS)
1353     emit_call_insn (gen_call_internal_long (XEXP (operands[0], 0), operands[1]));
1354   else
1355     emit_call_insn (gen_call_internal_short (XEXP (operands[0], 0), operands[1]));
1356   
1357   DONE;
1360 (define_insn "call_internal_short"
1361   [(call (mem:QI (match_operand:SI 0 "call_address_operand" "S,r"))
1362          (match_operand:SI 1 "general_operand" "g,g"))
1363    (clobber (reg:SI 31))]
1364   "! TARGET_LONG_CALLS"
1365   "@
1366   jarl %0,r31
1367   jarl .+4,r31 ; add 4,r31 ; jmp %0"
1368   [(set_attr "length" "4,8")]
1371 (define_insn "call_internal_long"
1372   [(call (mem:QI (match_operand:SI 0 "call_address_operand" "S,r"))
1373          (match_operand:SI 1 "general_operand" "g,g"))
1374    (clobber (reg:SI 31))]
1375   "TARGET_LONG_CALLS"
1376   "*
1377   {
1378   if (which_alternative == 0)
1379     {
1380       if (GET_CODE (operands[0]) == REG)
1381         return \"jarl %0,r31\";
1382       else
1383         return \"movhi hi(%0), r0, r11 ; movea lo(%0), r11, r11 ; jarl .+4,r31 ; add 4, r31 ; jmp r11\";
1384     }
1385   else
1386     return \"jarl .+4,r31 ; add 4,r31 ; jmp %0\";
1387   }"
1388   [(set_attr "length" "16,8")]
1391 ;; Call subroutine, returning value in operand 0
1392 ;; (which must be a hard register).
1394 (define_expand "call_value"
1395   [(set (match_operand 0 "" "")
1396         (call (match_operand:QI 1 "general_operand" "")
1397               (match_operand:SI 2 "general_operand" "")))]
1398   ""
1399   "
1401   if (! call_address_operand (XEXP (operands[1], 0), QImode)
1402       || TARGET_LONG_CALLS)
1403     XEXP (operands[1], 0) = force_reg (SImode, XEXP (operands[1], 0));
1404   if (TARGET_LONG_CALLS)
1405     emit_call_insn (gen_call_value_internal_long (operands[0],
1406                                                   XEXP (operands[1], 0),
1407                                                   operands[2]));
1408   else
1409     emit_call_insn (gen_call_value_internal_short (operands[0],
1410                                                    XEXP (operands[1], 0),
1411                                                    operands[2]));
1412   DONE;
1415 (define_insn "call_value_internal_short"
1416   [(set (match_operand 0 "" "=r,r")
1417         (call (mem:QI (match_operand:SI 1 "call_address_operand" "S,r"))
1418               (match_operand:SI 2 "general_operand" "g,g")))
1419    (clobber (reg:SI 31))]
1420   "! TARGET_LONG_CALLS"
1421   "@
1422   jarl %1,r31
1423   jarl .+4,r31 ; add 4,r31 ; jmp %1"
1424   [(set_attr "length" "4,8")]
1427 (define_insn "call_value_internal_long"
1428   [(set (match_operand 0 "" "=r,r")
1429         (call (mem:QI (match_operand:SI 1 "call_address_operand" "S,r"))
1430               (match_operand:SI 2 "general_operand" "g,g")))
1431    (clobber (reg:SI 31))]
1432   "TARGET_LONG_CALLS"
1433   "*
1434   {
1435   if (which_alternative == 0)
1436     {
1437       if (GET_CODE (operands[1]) == REG)
1438         return \"jarl %1, r31\";
1439       else
1440       /* Reload can generate this pattern....  */
1441         return \"movhi hi(%1), r0, r11 ; movea lo(%1), r11, r11 ; jarl .+4, r31 ; add 4, r31 ; jmp r11\";
1442     }
1443   else
1444     return \"jarl .+4, r31 ; add 4, r31 ; jmp %1\";
1445   }"
1446   [(set_attr "length" "16,8")]
1449 (define_insn "nop"
1450   [(const_int 0)]
1451   ""
1452   "nop"
1453   [(set_attr "length" "2")
1454    (set_attr "cc" "none")])
1456 ;; ----------------------------------------------------------------------
1457 ;; EXTEND INSTRUCTIONS
1458 ;; ----------------------------------------------------------------------
1460 (define_insn ""
1461   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
1462         (zero_extend:SI
1463          (match_operand:HI 1 "nonimmediate_operand" "0,r,T,m")))]
1464   "TARGET_V850E"
1465   "@
1466    zxh %0
1467    andi 65535,%1,%0
1468    sld.hu %1,%0
1469    ld.hu %1,%0"
1470   [(set_attr "length" "2,4,2,4")
1471    (set_attr "cc" "none_0hit,set_znv,none_0hit,none_0hit")])
1473 (define_insn "zero_extendhisi2"
1474   [(set (match_operand:SI 0 "register_operand" "=r")
1475         (zero_extend:SI
1476          (match_operand:HI 1 "register_operand" "r")))]
1477   ""
1478   "andi 65535,%1,%0"
1479   [(set_attr "length" "4")
1480    (set_attr "cc" "set_znv")])
1482 (define_insn ""
1483   [(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
1484         (zero_extend:SI
1485          (match_operand:QI 1 "nonimmediate_operand" "0,r,T,m")))]
1486   "TARGET_V850E"
1487   "@
1488    zxb %0
1489    andi 255,%1,%0
1490    sld.bu %1,%0
1491    ld.bu %1,%0"
1492   [(set_attr "length" "2,4,2,4")
1493    (set_attr "cc" "none_0hit,set_znv,none_0hit,none_0hit")])
1495 (define_insn "zero_extendqisi2"
1496   [(set (match_operand:SI 0 "register_operand" "=r")
1497         (zero_extend:SI
1498          (match_operand:QI 1 "register_operand" "r")))]
1499   ""
1500   "andi 255,%1,%0"
1501   [(set_attr "length" "4")
1502    (set_attr "cc" "set_znv")])
1504 ;;- sign extension instructions
1506 ;; ??? The extendhisi2 pattern should not emit shifts for v850e?
1508 (define_insn "*extendhisi_insn"
1509   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1510         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "0,Q,m")))]
1511   "TARGET_V850E"
1512   "@
1513    sxh %0
1514    sld.h %1,%0
1515    ld.h %1,%0"
1516   [(set_attr "length" "2,2,4")
1517    (set_attr "cc" "none_0hit,none_0hit,none_0hit")])
1519 ;; ??? This is missing a sign extend from memory pattern to match the ld.h
1520 ;; instruction.
1522 (define_expand "extendhisi2"
1523   [(set (match_dup 2)
1524         (ashift:SI (match_operand:HI 1 "register_operand" "")
1525                    (const_int 16)))
1526    (set (match_operand:SI 0 "register_operand" "")
1527        (ashiftrt:SI (match_dup 2)
1528                      (const_int 16)))]
1529   ""
1530   "
1532   operands[1] = gen_lowpart (SImode, operands[1]);
1533   operands[2] = gen_reg_rtx (SImode);
1536 ;; ??? The extendqisi2 pattern should not emit shifts for v850e?
1538 (define_insn "*extendqisi_insn"
1539   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1540         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "0,Q,m")))]
1541   "TARGET_V850E"
1542   "@
1543    sxb %0
1544    sld.b %1,%0
1545    ld.b %1,%0"
1546   [(set_attr "length" "2,2,4")
1547    (set_attr "cc" "none_0hit,none_0hit,none_0hit")])
1549 ;; ??? This is missing a sign extend from memory pattern to match the ld.b
1550 ;; instruction.
1552 (define_expand "extendqisi2"
1553   [(set (match_dup 2)
1554         (ashift:SI (match_operand:QI 1 "register_operand" "")
1555                    (const_int 24)))
1556    (set (match_operand:SI 0 "register_operand" "")
1557         (ashiftrt:SI (match_dup 2)
1558                      (const_int 24)))]
1559   ""
1560   "
1562   operands[1] = gen_lowpart (SImode, operands[1]);
1563   operands[2] = gen_reg_rtx (SImode);
1566 ;; ----------------------------------------------------------------------
1567 ;; SHIFTS
1568 ;; ----------------------------------------------------------------------
1570 (define_insn "ashlsi3"
1571   [(set (match_operand:SI 0 "register_operand" "=r,r")
1572         (ashift:SI
1573          (match_operand:SI 1 "register_operand" "0,0")
1574          (match_operand:SI 2 "nonmemory_operand" "r,N")))]
1575   ""
1576   "@
1577   shl %2,%0
1578   shl %2,%0"
1579   [(set_attr "length" "4,2")
1580    (set_attr "cc" "set_znv")])
1582 (define_insn "lshrsi3"
1583   [(set (match_operand:SI 0 "register_operand" "=r,r")
1584         (lshiftrt:SI
1585          (match_operand:SI 1 "register_operand" "0,0")
1586          (match_operand:SI 2 "nonmemory_operand" "r,N")))]
1587   ""
1588   "@
1589   shr %2,%0
1590   shr %2,%0"
1591   [(set_attr "length" "4,2")
1592    (set_attr "cc" "set_znv")])
1594 (define_insn "ashrsi3"
1595   [(set (match_operand:SI 0 "register_operand" "=r,r")
1596         (ashiftrt:SI
1597          (match_operand:SI 1 "register_operand" "0,0")
1598          (match_operand:SI 2 "nonmemory_operand" "r,N")))]
1599   ""
1600   "@
1601   sar %2,%0
1602   sar %2,%0"
1603   [(set_attr "length" "4,2")
1604    (set_attr "cc" "set_znv")])
1606 ;; ----------------------------------------------------------------------
1607 ;; PROLOGUE/EPILOGUE
1608 ;; ----------------------------------------------------------------------
1609 (define_expand "prologue"
1610   [(const_int 0)]
1611   ""
1612   "expand_prologue (); DONE;")
1614 (define_expand "epilogue"
1615   [(return)]
1616   ""
1617   "
1619   /* Try to use the trivial return first.  Else use the
1620      full epilogue.  */
1621   if (0)
1622     emit_jump_insn (gen_return ());
1623   else
1624     expand_epilogue ();
1625   DONE;
1628 (define_insn "return"
1629   [(return)]
1630   "reload_completed && compute_frame_size (get_frame_size (), (long *)0) == 0"
1631   "jmp [r31]"
1632   [(set_attr "length" "2")
1633    (set_attr "cc" "none")])
1635 (define_insn "return_internal"
1636   [(return)
1637    (use (reg:SI 31))]
1638   ""
1639   "jmp [r31]"
1640   [(set_attr "length" "2")
1641    (set_attr "cc" "none")])
1645 ;; ----------------------------------------------------------------------
1646 ;; HELPER INSTRUCTIONS for saving the prologue and epilog registers
1647 ;; ----------------------------------------------------------------------
1649 ;; This pattern will match a stack adjust RTX followed by any number of push
1650 ;; RTXs.  These RTXs will then be turned into a suitable call to a worker
1651 ;; function.
1654 ;; Actually, convert the RTXs into a PREPARE instruction.
1656 (define_insn ""
1657  [(match_parallel 0 "pattern_is_ok_for_prepare"
1658    [(set (reg:SI 3)
1659          (plus:SI (reg:SI 3) (match_operand:SI 1 "immediate_operand" "i")))
1660     (set (mem:SI (plus:SI (reg:SI 3)
1661                           (match_operand:SI 2 "immediate_operand" "i")))
1662          (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))])]
1663  "TARGET_PROLOG_FUNCTION && TARGET_V850E"
1664  "* return construct_prepare_instruction (operands[0]);
1666  [(set_attr "length" "4")
1667   (set_attr "cc"     "none")])
1669 (define_insn ""
1670  [(match_parallel 0 "pattern_is_ok_for_prologue"
1671    [(set (reg:SI 3)
1672          (plus:SI (reg:SI 3) (match_operand:SI 1 "immediate_operand" "i")))
1673     (set (mem:SI (plus:SI (reg:SI 3)
1674                            (match_operand:SI 2 "immediate_operand" "i")))
1675          (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))])]
1676  "TARGET_PROLOG_FUNCTION && TARGET_V850"
1677  "* return construct_save_jarl (operands[0]);
1679  [(set (attr "length") (if_then_else (eq_attr "long_calls" "yes")
1680                                      (const_string "16")
1681                                      (const_string "4")))
1682   (set_attr "cc"     "clobber")])
1685 ;; Actually, turn the RTXs into a DISPOSE instruction.
1687 (define_insn ""
1688  [(match_parallel 0 "pattern_is_ok_for_dispose"
1689    [(return)
1690     (set (reg:SI 3)
1691          (plus:SI (reg:SI 3) (match_operand:SI 1 "immediate_operand" "i")))
1692     (set (match_operand:SI 2 "register_is_ok_for_epilogue" "=r")
1693          (mem:SI (plus:SI (reg:SI 3)
1694                           (match_operand:SI 3 "immediate_operand" "i"))))])]
1695  "TARGET_PROLOG_FUNCTION && TARGET_V850E"
1696  "* return construct_dispose_instruction (operands[0]);
1698  [(set_attr "length" "4")
1699   (set_attr "cc"     "none")])
1701 ;; This pattern will match a return RTX followed by any number of pop RTXs
1702 ;; and possible a stack adjustment as well.  These RTXs will be turned into
1703 ;; a suitable call to a worker function.
1705 (define_insn ""
1706 [(match_parallel 0 "pattern_is_ok_for_epilogue"
1707    [(return)
1708     (set (reg:SI 3)
1709          (plus:SI (reg:SI 3) (match_operand:SI 1 "immediate_operand" "i")))
1710     (set (match_operand:SI 2 "register_is_ok_for_epilogue" "=r")
1711          (mem:SI (plus:SI (reg:SI 3)
1712                           (match_operand:SI 3 "immediate_operand" "i"))))])]
1713  "TARGET_PROLOG_FUNCTION && TARGET_V850"
1714  "* return construct_restore_jr (operands[0]);
1716  [(set (attr "length") (if_then_else (eq_attr "long_calls" "yes")
1717                                      (const_string "12")
1718                                      (const_string "4")))
1719   (set_attr "cc"     "clobber")])
1721 ;; Initialize an interrupt function.  Do not depend on TARGET_PROLOG_FUNCTION.
1722 (define_insn "callt_save_interrupt"
1723   [(unspec_volatile [(const_int 0)] 2)]
1724     "TARGET_V850E && !TARGET_DISABLE_CALLT"
1725     ;; The CALLT instruction stores the next address of CALLT to CTPC register
1726     ;; without saving its previous value.  So if the interrupt handler
1727     ;; or its caller could possibly execute the CALLT insn, save_interrupt 
1728     ;; MUST NOT be called via CALLT.
1729     "*
1731   output_asm_insn (\"addi -24,   sp, sp\", operands);
1732   output_asm_insn (\"st.w r10,   12[sp]\", operands);
1733   output_asm_insn (\"stsr ctpc,  r10\",    operands);
1734   output_asm_insn (\"st.w r10,   16[sp]\", operands);
1735   output_asm_insn (\"stsr ctpsw, r10\",    operands);
1736   output_asm_insn (\"st.w r10,   20[sp]\", operands);
1737   output_asm_insn (\"callt ctoff(__callt_save_interrupt)\", operands);
1738   return \"\";
1740    [(set_attr "length" "26")
1741     (set_attr "cc" "none")])
1743 (define_insn "callt_return_interrupt"
1744   [(unspec_volatile [(const_int 0)] 3)]
1745   "TARGET_V850E && !TARGET_DISABLE_CALLT"
1746   "callt ctoff(__callt_return_interrupt)"
1747   [(set_attr "length" "2")
1748    (set_attr "cc" "clobber")])
1750 (define_insn "save_interrupt"
1751   [(set (reg:SI 3) (plus:SI (reg:SI 3) (const_int -16)))
1752    (set (mem:SI (plus:SI (reg:SI 3) (const_int -16))) (reg:SI 30))
1753    (set (mem:SI (plus:SI (reg:SI 3) (const_int -12))) (reg:SI 4))
1754    (set (mem:SI (plus:SI (reg:SI 3) (const_int  -8))) (reg:SI 1))
1755    (set (mem:SI (plus:SI (reg:SI 3) (const_int  -4))) (reg:SI 10))]
1756   ""
1757   "*
1759   if (TARGET_PROLOG_FUNCTION && !TARGET_LONG_CALLS)
1760     return \"add -16,sp\;st.w r10,12[sp]\;jarl __save_interrupt,r10\";
1761   else
1762     {
1763       output_asm_insn (\"add   -16, sp\", operands);
1764       output_asm_insn (\"st.w  r10, 12[sp]\", operands);
1765       output_asm_insn (\"st.w  ep, 0[sp]\", operands);
1766       output_asm_insn (\"st.w  gp, 4[sp]\", operands);
1767       output_asm_insn (\"st.w  r1, 8[sp]\", operands);
1768       output_asm_insn (\"movhi hi(__ep), r0, ep\", operands);
1769       output_asm_insn (\"movea lo(__ep), ep, ep\", operands);
1770       output_asm_insn (\"movhi hi(__gp), r0, gp\", operands);
1771       output_asm_insn (\"movea lo(__gp), gp, gp\", operands);
1772       return \"\";
1773     }
1775   [(set (attr "length")
1776         (if_then_else (ne (symbol_ref "TARGET_LONG_CALLS") (const_int 0))
1777                        (const_int 10)
1778                        (const_int 34)))
1779    (set_attr "cc" "clobber")])
1780   
1781 ;; Restore r1, r4, r10, and return from the interrupt
1782 (define_insn "return_interrupt"
1783   [(return)
1784    (set (reg:SI 3)  (plus:SI (reg:SI 3) (const_int 16)))
1785    (set (reg:SI 10) (mem:SI (plus:SI (reg:SI 3) (const_int 12))))
1786    (set (reg:SI 1)  (mem:SI (plus:SI (reg:SI 3) (const_int  8))))
1787    (set (reg:SI 4)  (mem:SI (plus:SI (reg:SI 3) (const_int  4))))
1788    (set (reg:SI 30) (mem:SI (reg:SI 3)))]
1789   ""
1790   "*
1792   if (TARGET_PROLOG_FUNCTION && !TARGET_LONG_CALLS)
1793     return \"jr __return_interrupt\";
1794   else 
1795     {
1796       output_asm_insn (\"ld.w 0[sp],  ep\",   operands);
1797       output_asm_insn (\"ld.w 4[sp],  gp\",   operands);
1798       output_asm_insn (\"ld.w 8[sp],  r1\",   operands);
1799       output_asm_insn (\"ld.w 12[sp], r10\", operands);
1800       output_asm_insn (\"addi 16, sp, sp\",   operands);
1801       output_asm_insn (\"reti\",            operands);
1802       return \"\";
1803     }
1805   [(set (attr "length")
1806         (if_then_else (ne (symbol_ref "TARGET_LONG_CALLS") (const_int 0))
1807                        (const_int 4)
1808                        (const_int 24)))
1809    (set_attr "cc" "clobber")])
1811 ;; Save all registers except for the registers saved in save_interrupt when
1812 ;; an interrupt function makes a call.
1813 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
1814 ;; all of memory.  This blocks insns from being moved across this point.
1815 ;; This is needed because the rest of the compiler is not ready to handle
1816 ;; insns this complicated.
1818 (define_insn "callt_save_all_interrupt"
1819   [(unspec_volatile [(const_int 0)] 0)]
1820   "TARGET_V850E && !TARGET_DISABLE_CALLT"
1821   "callt ctoff(__callt_save_all_interrupt)"
1822   [(set_attr "length" "2")
1823    (set_attr "cc" "none")])
1825 (define_insn "save_all_interrupt"
1826   [(unspec_volatile [(const_int 0)] 0)]
1827   ""
1828   "*
1830   if (TARGET_PROLOG_FUNCTION && !TARGET_LONG_CALLS)
1831     return \"jarl __save_all_interrupt,r10\";
1833   output_asm_insn (\"addi -120, sp, sp\", operands);
1834   output_asm_insn (\"mov ep, r1\", operands);
1835   output_asm_insn (\"mov sp, ep\", operands);
1836   output_asm_insn (\"sst.w r31, 116[ep]\", operands);
1837   output_asm_insn (\"sst.w r2,  112[ep]\", operands);
1838   output_asm_insn (\"sst.w gp,  108[ep]\", operands);
1839   output_asm_insn (\"sst.w r6,  104[ep]\", operands);
1840   output_asm_insn (\"sst.w r7,  100[ep]\", operands);
1841   output_asm_insn (\"sst.w r8,   96[ep]\", operands);
1842   output_asm_insn (\"sst.w r9,   92[ep]\", operands);
1843   output_asm_insn (\"sst.w r11,  88[ep]\", operands);
1844   output_asm_insn (\"sst.w r12,  84[ep]\", operands);
1845   output_asm_insn (\"sst.w r13,  80[ep]\", operands);
1846   output_asm_insn (\"sst.w r14,  76[ep]\", operands);
1847   output_asm_insn (\"sst.w r15,  72[ep]\", operands);
1848   output_asm_insn (\"sst.w r16,  68[ep]\", operands);
1849   output_asm_insn (\"sst.w r17,  64[ep]\", operands);
1850   output_asm_insn (\"sst.w r18,  60[ep]\", operands);
1851   output_asm_insn (\"sst.w r19,  56[ep]\", operands);
1852   output_asm_insn (\"sst.w r20,  52[ep]\", operands);
1853   output_asm_insn (\"sst.w r21,  48[ep]\", operands);
1854   output_asm_insn (\"sst.w r22,  44[ep]\", operands);
1855   output_asm_insn (\"sst.w r23,  40[ep]\", operands);
1856   output_asm_insn (\"sst.w r24,  36[ep]\", operands);
1857   output_asm_insn (\"sst.w r25,  32[ep]\", operands);
1858   output_asm_insn (\"sst.w r26,  28[ep]\", operands);
1859   output_asm_insn (\"sst.w r27,  24[ep]\", operands);
1860   output_asm_insn (\"sst.w r28,  20[ep]\", operands);
1861   output_asm_insn (\"sst.w r29,  16[ep]\", operands);
1862   output_asm_insn (\"mov   r1,   ep\", operands);
1863   return \"\";
1865   [(set (attr "length")
1866         (if_then_else (ne (symbol_ref "TARGET_LONG_CALLS") (const_int 0))
1867                        (const_int 4)
1868                        (const_int 62)
1869         ))
1870    (set_attr "cc" "clobber")])
1872 (define_insn "_save_all_interrupt"
1873   [(unspec_volatile [(const_int 0)] 0)]
1874   "TARGET_V850 && ! TARGET_LONG_CALLS"
1875   "jarl __save_all_interrupt,r10"
1876   [(set_attr "length" "4")
1877    (set_attr "cc" "clobber")])
1879 ;; Restore all registers saved when an interrupt function makes a call.
1880 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
1881 ;; all of memory.  This blocks insns from being moved across this point.
1882 ;; This is needed because the rest of the compiler is not ready to handle
1883 ;; insns this complicated.
1885 (define_insn "callt_restore_all_interrupt"
1886   [(unspec_volatile [(const_int 0)] 1)]
1887   "TARGET_V850E && !TARGET_DISABLE_CALLT"
1888   "callt ctoff(__callt_restore_all_interrupt)"
1889   [(set_attr "length" "2")
1890    (set_attr "cc" "none")])
1892 (define_insn "restore_all_interrupt"
1893   [(unspec_volatile [(const_int 0)] 1)]
1894   ""
1895   "*
1897   if (TARGET_PROLOG_FUNCTION && !TARGET_LONG_CALLS)
1898     return \"jarl __restore_all_interrupt,r10\";
1899   else
1900     {
1901       output_asm_insn (\"mov   ep,      r1\", operands);
1902       output_asm_insn (\"mov   sp,      ep\", operands);
1903       output_asm_insn (\"sld.w 116[ep], r31\", operands);
1904       output_asm_insn (\"sld.w 112[ep], r2\", operands);
1905       output_asm_insn (\"sld.w 108[ep], gp\", operands);
1906       output_asm_insn (\"sld.w 104[ep], r6\", operands);
1907       output_asm_insn (\"sld.w 100[ep], r7\", operands);
1908       output_asm_insn (\"sld.w 96[ep],  r8\", operands);
1909       output_asm_insn (\"sld.w 92[ep],  r9\", operands);
1910       output_asm_insn (\"sld.w 88[ep],  r11\", operands);
1911       output_asm_insn (\"sld.w 84[ep],  r12\", operands);
1912       output_asm_insn (\"sld.w 80[ep],  r13\", operands);
1913       output_asm_insn (\"sld.w 76[ep],  r14\", operands);
1914       output_asm_insn (\"sld.w 72[ep],  r15\", operands);
1915       output_asm_insn (\"sld.w 68[ep],  r16\", operands);
1916       output_asm_insn (\"sld.w 64[ep],  r17\", operands);
1917       output_asm_insn (\"sld.w 60[ep],  r18\", operands);
1918       output_asm_insn (\"sld.w 56[ep],  r19\", operands);
1919       output_asm_insn (\"sld.w 52[ep],  r20\", operands);
1920       output_asm_insn (\"sld.w 48[ep],  r21\", operands);
1921       output_asm_insn (\"sld.w 44[ep],  r22\", operands);
1922       output_asm_insn (\"sld.w 40[ep],  r23\", operands);
1923       output_asm_insn (\"sld.w 36[ep],  r24\", operands);
1924       output_asm_insn (\"sld.w 32[ep],  r25\", operands);
1925       output_asm_insn (\"sld.w 28[ep],  r26\", operands);
1926       output_asm_insn (\"sld.w 24[ep],  r27\", operands);
1927       output_asm_insn (\"sld.w 20[ep],  r28\", operands);
1928       output_asm_insn (\"sld.w 16[ep],  r29\", operands);
1929       output_asm_insn (\"mov   r1,      ep\", operands);
1930       output_asm_insn (\"addi  120, sp, sp\", operands);
1931       return \"\";
1932     }
1934   [(set (attr "length")
1935         (if_then_else (ne (symbol_ref "TARGET_LONG_CALLS") (const_int 0))
1936                        (const_int 4)
1937                        (const_int 62)
1938         ))
1939    (set_attr "cc" "clobber")])
1941 (define_insn "_restore_all_interrupt"
1942   [(unspec_volatile [(const_int 0)] 1)]
1943   "TARGET_V850 && ! TARGET_LONG_CALLS"
1944   "jarl __restore_all_interrupt,r10"
1945   [(set_attr "length" "4")
1946    (set_attr "cc" "clobber")])
1948 ;; Save r6-r9 for a variable argument function
1949 (define_insn "save_r6_r9_v850e"
1950   [(set (mem:SI (reg:SI 3)) (reg:SI 6))
1951    (set (mem:SI (plus:SI (reg:SI 3) (const_int 4))) (reg:SI 7))
1952    (set (mem:SI (plus:SI (reg:SI 3) (const_int 8))) (reg:SI 8))
1953    (set (mem:SI (plus:SI (reg:SI 3) (const_int 12))) (reg:SI 9))
1954   ]
1955   "TARGET_PROLOG_FUNCTION && TARGET_V850E && !TARGET_DISABLE_CALLT"
1956   "callt ctoff(__callt_save_r6_r9)"
1957   [(set_attr "length" "2")
1958    (set_attr "cc" "none")])
1960 (define_insn "save_r6_r9"
1961   [(set (mem:SI (reg:SI 3)) (reg:SI 6))
1962    (set (mem:SI (plus:SI (reg:SI 3) (const_int 4))) (reg:SI 7))
1963    (set (mem:SI (plus:SI (reg:SI 3) (const_int 8))) (reg:SI 8))
1964    (set (mem:SI (plus:SI (reg:SI 3) (const_int 12))) (reg:SI 9))
1965    (clobber (reg:SI 10))]
1966   "TARGET_PROLOG_FUNCTION && ! TARGET_LONG_CALLS"
1967   "jarl __save_r6_r9,r10"
1968   [(set_attr "length" "4")
1969    (set_attr "cc" "clobber")])