OSDN Git Service

734b3749ada86ede8c35b1eebf26dbdd03a30be1
[pf3gnuchains/gcc-fork.git] / gcc / config / fr30 / fr30.md
1 ;; FR30 machine description.
2 ;; Copyright (C) 1998, 1999, 2000, 2002, 2004, 2005
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Cygnus Solutions.
5
6 ;; This file is part of GCC.
7
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.
12
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.
17
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, 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
22
23 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
24
25 ;;{{{ Attributes 
26
27 (define_attr "length" "" (const_int 2))
28
29 ;; Used to distinguish between small memory model targets and big mode targets.
30
31 (define_attr "size" "small,big"
32   (const (if_then_else (symbol_ref "TARGET_SMALL_MODEL")
33                        (const_string "small")
34                        (const_string "big"))))
35
36
37 ;; Define an attribute to be used by the delay slot code.
38 ;; An instruction by default is considered to be 'delyabable'
39 ;; that is, it can be placed into a delay slot, but it is not
40 ;; itself a delayed branch type instruction.  An instruction
41 ;; whose type is 'delayed' is one which has a delay slot, and
42 ;; an instruction whose delay_type is 'other' is one which does
43 ;; not have a delay slot, nor can it be placed into a delay slot.
44
45 (define_attr "delay_type" "delayable,delayed,other" (const_string "delayable"))
46
47 ;;}}} \f
48 ;;{{{ Delay Slot Specifications 
49
50 (define_delay (eq_attr "delay_type" "delayed")
51   [(and (eq_attr "delay_type" "delayable")
52         (eq_attr "length" "2"))
53    (nil)
54    (nil)]
55 )
56
57 (include "predicates.md")
58
59 ;;}}}
60 ;;{{{ Moves 
61
62 ;;{{{ Comment 
63
64 ;; Wrap moves in define_expand to prevent memory->memory moves from being
65 ;; generated at the RTL level, which generates better code for most machines
66 ;; which can't do mem->mem moves.
67
68 ;; If operand 0 is a `subreg' with mode M of a register whose own mode is wider
69 ;; than M, the effect of this instruction is to store the specified value in
70 ;; the part of the register that corresponds to mode M.  The effect on the rest
71 ;; of the register is undefined.
72
73 ;; This class of patterns is special in several ways.  First of all, each of
74 ;; these names *must* be defined, because there is no other way to copy a datum
75 ;; from one place to another.
76
77 ;; Second, these patterns are not used solely in the RTL generation pass.  Even
78 ;; the reload pass can generate move insns to copy values from stack slots into
79 ;; temporary registers.  When it does so, one of the operands is a hard
80 ;; register and the other is an operand that can need to be reloaded into a
81 ;; register.
82
83 ;; Therefore, when given such a pair of operands, the pattern must
84 ;; generate RTL which needs no reloading and needs no temporary
85 ;; registers--no registers other than the operands.  For example, if
86 ;; you support the pattern with a `define_expand', then in such a
87 ;; case the `define_expand' mustn't call `force_reg' or any other such
88 ;; function which might generate new pseudo registers.
89
90 ;; This requirement exists even for subword modes on a RISC machine
91 ;; where fetching those modes from memory normally requires several
92 ;; insns and some temporary registers.  Look in `spur.md' to see how
93 ;; the requirement can be satisfied.
94
95 ;; During reload a memory reference with an invalid address may be passed as an
96 ;; operand.  Such an address will be replaced with a valid address later in the
97 ;; reload pass.  In this case, nothing may be done with the address except to
98 ;; use it as it stands.  If it is copied, it will not be replaced with a valid
99 ;; address.  No attempt should be made to make such an address into a valid
100 ;; address and no routine (such as `change_address') that will do so may be
101 ;; called.  Note that `general_operand' will fail when applied to such an
102 ;; address.
103 ;;
104 ;; The global variable `reload_in_progress' (which must be explicitly declared
105 ;; if required) can be used to determine whether such special handling is
106 ;; required.
107 ;;
108 ;; The variety of operands that have reloads depends on the rest of
109 ;; the machine description, but typically on a RISC machine these can
110 ;; only be pseudo registers that did not get hard registers, while on
111 ;; other machines explicit memory references will get optional
112 ;; reloads.
113 ;;
114 ;; If a scratch register is required to move an object to or from memory, it
115 ;; can be allocated using `gen_reg_rtx' prior to reload.  But this is
116 ;; impossible during and after reload.  If there are cases needing scratch
117 ;; registers after reload, you must define `SECONDARY_INPUT_RELOAD_CLASS' and
118 ;; perhaps also `SECONDARY_OUTPUT_RELOAD_CLASS' to detect them, and provide
119 ;; patterns `reload_inM' or `reload_outM' to handle them.
120
121 ;; The constraints on a `moveM' must permit moving any hard register to any
122 ;; other hard register provided that `HARD_REGNO_MODE_OK' permits mode M in
123 ;; both registers and `REGISTER_MOVE_COST' applied to their classes returns a
124 ;; value of 2.
125
126 ;; It is obligatory to support floating point `moveM' instructions
127 ;; into and out of any registers that can hold fixed point values,
128 ;; because unions and structures (which have modes `SImode' or
129 ;; `DImode') can be in those registers and they may have floating
130 ;; point members.
131
132 ;; There may also be a need to support fixed point `moveM' instructions in and
133 ;; out of floating point registers.  Unfortunately, I have forgotten why this
134 ;; was so, and I don't know whether it is still true.  If `HARD_REGNO_MODE_OK'
135 ;; rejects fixed point values in floating point registers, then the constraints
136 ;; of the fixed point `moveM' instructions must be designed to avoid ever
137 ;; trying to reload into a floating point register.
138
139 ;;}}}
140 ;;{{{ Push and Pop  
141
142 ;; Push a register onto the stack
143 (define_insn "movsi_push"
144   [(set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
145         (match_operand:SI 0 "register_operand" "a"))]
146   ""
147   "st   %0, @-r15"
148 )
149
150 ;; Pop a register off the stack
151 (define_insn "movsi_pop"
152   [(set:SI (match_operand:SI 0 "register_operand" "=a")
153         (mem:SI (post_inc:SI (reg:SI 15))))]
154   ""
155   "ld   @r15+, %0"
156 )
157
158 ;;}}}
159 ;;{{{ 1 Byte Moves 
160
161 (define_expand "movqi"
162   [(set (match_operand:QI 0 "general_operand" "")
163         (match_operand:QI 1 "general_operand" ""))]
164   ""
165   "
166 {
167   if (!reload_in_progress
168       && !reload_completed
169       && GET_CODE (operands[0]) == MEM
170       && (GET_CODE (operands[1]) == MEM
171          || immediate_operand (operands[1], QImode)))
172     operands[1] = copy_to_mode_reg (QImode, operands[1]);
173 }")
174
175 (define_insn "movqi_unsigned_register_load"
176   [(set (match_operand:SI 0 "register_operand"              "=r")
177         (zero_extend:SI (match_operand:QI 1 "memory_operand" "m")))]
178   ""
179   "ldub %1, %0"
180 )
181
182 (define_expand "movqi_signed_register_load"
183   [(set (match_operand:SI 0 "register_operand"               "")
184         (sign_extend:SI (match_operand:QI 1 "memory_operand" "")))]
185   ""
186   "
187   emit_insn (gen_movqi_unsigned_register_load (operands[0], operands[1]));
188   emit_insn (gen_extendqisi2 (operands[0], operands[0]));
189   DONE;
190   "
191 )
192
193 (define_insn "*movqi_internal"
194   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,red,m,r")
195         (match_operand:QI 1 "general_operand"       "i,red,r,rm"))]
196   ""
197   "@
198    ldi:8\\t#%A1, %0
199    mov  \\t%1, %0
200    stb  \\t%1, %0
201    ldub \\t%1, %0"
202 )
203
204 ;;}}}
205 ;;{{{ 2 Byte Moves 
206
207 (define_expand "movhi"
208   [(set (match_operand:HI 0 "general_operand" "")
209         (match_operand:HI 1 "general_operand" ""))]
210   ""
211   "
212 {
213   if (!reload_in_progress
214       && !reload_completed
215       && GET_CODE (operands[0]) == MEM
216       && (GET_CODE (operands[1]) == MEM
217          || immediate_operand (operands[1], HImode)))
218     operands[1] = copy_to_mode_reg (HImode, operands[1]);
219 }")
220
221 (define_insn "movhi_unsigned_register_load"
222   [(set (match_operand:SI 0 "register_operand" "=r")
223         (zero_extend:SI (match_operand:HI 1 "memory_operand" "m")))]
224   ""
225   "lduh %1, %0"
226 )
227
228 (define_expand "movhi_signed_register_load"
229   [(set (match_operand:SI 0 "register_operand" "")
230         (sign_extend:SI (match_operand:HI 1 "memory_operand" "")))]
231   ""
232   "
233   emit_insn (gen_movhi_unsigned_register_load (operands[0], operands[1]));
234   emit_insn (gen_extendhisi2 (operands[0], operands[0]));
235   DONE;
236   "
237 )
238
239 (define_insn "*movhi_internal"
240   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,r,red,m,r")
241         (match_operand:HI 1 "general_operand"       "L,M,n,red,r,rm"))]
242   ""
243   "@
244    ldi:8 \\t#%1, %0
245    ldi:20\\t#%1, %0
246    ldi:32\\t#%1, %0
247    mov   \\t%1, %0
248    sth   \\t%1, %0
249    lduh  \\t%1, %0"
250   [(set_attr "length" "*,4,6,*,*,*")]
251 )
252
253 ;;}}}
254 ;;{{{ 4 Byte Moves 
255
256 ;; If the destination is a MEM and the source is a
257 ;; MEM or an CONST_INT move the source into a register.
258 (define_expand "movsi"
259   [(set (match_operand:SI 0 "nonimmediate_operand" "")
260         (match_operand:SI 1 "general_operand" ""))]
261   ""
262   "{
263   if (!reload_in_progress
264       && !reload_completed
265       && GET_CODE(operands[0]) == MEM
266       && (GET_CODE (operands[1]) == MEM
267           || immediate_operand (operands[1], SImode)))
268      operands[1] = copy_to_mode_reg (SImode, operands[1]);
269   }"
270 )
271
272 ;; We can do some clever tricks when loading certain immediate
273 ;; values.  We implement these tricks as define_splits, rather
274 ;; than putting the code into the define_expand "movsi" above,
275 ;; because if we put them there, they will be evaluated at RTL
276 ;; generation time and then the combiner pass will come along
277 ;; and replace the multiple insns that have been generated with
278 ;; the original, slower, load insns.  (The combiner pass only
279 ;; cares about reducing the number of instructions, it does not
280 ;; care about instruction lengths or speeds).  Splits are
281 ;; evaluated after the combine pass and before the scheduling
282 ;; passes, so that they are the perfect place to put this
283 ;; intelligence.
284 ;;
285 ;; XXX we probably ought to implement these for QI and HI mode
286 ;; loads as well.
287
288 ;; If we are loading a small negative constant we can save space
289 ;; and time by loading the positive value and then sign extending it.
290 (define_split
291   [(set (match_operand:SI 0 "register_operand"  "")
292         (match_operand:SI 1 "const_int_operand" ""))]
293    "INTVAL (operands[1]) <= -1 && INTVAL (operands[1]) >= -128"
294    [(set:SI (match_dup 0) (match_dup 1))
295     (set:SI (match_dup 0) (sign_extend:SI (match_dup 2)))]
296    "{
297    operands[1] = GEN_INT (INTVAL (operands[1]) & 0xff);
298    operands[2] = gen_lowpart (QImode, operands[0]);
299    }"
300 )
301
302 ;; If we are loading a large negative constant, one which does
303 ;; not have any of its bottom 24 bit set, then we can save time
304 ;; and space by loading the byte value and shifting it into place.
305 (define_split
306   [(set (match_operand:SI 0 "register_operand"  "")
307         (match_operand:SI 1 "const_int_operand" ""))]
308    "(INTVAL (operands[1]) < 0) && ((INTVAL (operands[1]) & 0x00ffffff) == 0)"
309    [(set:SI (match_dup 0) (match_dup 2))
310     (parallel [(set:SI (match_dup 0) (ashift:SI (match_dup 0) (const_int 24)))
311                (clobber (reg:CC 16))])]
312    "{
313    HOST_WIDE_INT val = INTVAL (operands[1]);
314    operands[2] = GEN_INT (val >> 24);
315    }"
316 )
317
318 ;; If we are loading a large positive constant, one which has bits
319 ;; in the top byte set, but whose set bits all lie within an 8 bit
320 ;; range, then we can save time and space by loading the byte value
321 ;; and shifting it into place.
322 (define_split
323   [(set (match_operand:SI 0 "register_operand"  "")
324         (match_operand:SI 1 "const_int_operand" ""))]
325    "(INTVAL (operands[1]) > 0x00ffffff)
326    && ((INTVAL (operands[1]) >> exact_log2 (INTVAL (operands[1]) & (- INTVAL (operands[1])))) < 0x100)"
327    [(set:SI (match_dup 0) (match_dup 2))
328     (parallel [(set:SI (match_dup 0) (ashift:SI (match_dup 0) (match_dup 3)))
329                (clobber (reg:CC 16))])]
330    "{
331    HOST_WIDE_INT val = INTVAL (operands[1]);
332    int shift = exact_log2 (val & ( - val));
333    operands[2] = GEN_INT (val >> shift);
334    operands[3] = GEN_INT (shift);
335    }"
336 )
337
338 ;; When TARGET_SMALL_MODEL is defined we assume that all symbolic
339 ;; values are addresses which will fit in 20 bits.
340
341 (define_insn "movsi_internal"
342   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,red,m,r")
343         (match_operand:SI 1 "general_operand"       "L,M,n,i,rde,r,rm"))]
344   ""
345   "*
346   {
347     switch (which_alternative)
348     {
349     case 0: return   \"ldi:8 \\t#%1, %0\";
350     case 1: return   \"ldi:20\\t#%1, %0\";
351     case 2: return   \"ldi:32\\t#%1, %0\";
352     case 3: if (TARGET_SMALL_MODEL)
353               return \"ldi:20\\t%1, %0\";
354             else
355               return \"ldi:32\\t%1, %0\";
356     case 4: return   \"mov   \\t%1, %0\";
357     case 5: return   \"st    \\t%1, %0\";
358     case 6: return   \"ld    \\t%1, %0\";
359     default: gcc_unreachable ();               
360     }
361   }"
362   [(set (attr "length") (cond [(eq_attr "alternative" "1") (const_int 4)
363                                (eq_attr "alternative" "2") (const_int 6)
364                                (eq_attr "alternative" "3") 
365                                         (if_then_else (eq_attr "size" "small")
366                                                       (const_int 4)
367                                                       (const_int 6))]
368                               (const_int 2)))]
369 )
370
371 ;;}}}
372 ;;{{{ 8 Byte Moves
373
374 ;; Note - the FR30 does not have an 8 byte load/store instruction
375 ;; but we have to support this pattern because some other patterns
376 ;; (e.g. muldisi2) can produce a DImode result.
377 ;; (This code is stolen from the M32R port.)
378
379 (define_expand "movdi"
380   [(set (match_operand:DI 0 "general_operand" "")
381         (match_operand:DI 1 "general_operand" ""))]
382   ""
383   "
384   /* Everything except mem = const or mem = mem can be done easily.  */
385   
386   if (GET_CODE (operands[0]) == MEM)
387     operands[1] = force_reg (DImode, operands[1]);
388   ")
389
390 ;; We use an insn and a split so that we can generate
391 ;; RTL rather than text from fr30_move_double().
392
393 (define_insn "*movdi_insn"
394   [(set (match_operand:DI 0 "nonimmediate_di_operand" "=r,r,m,r")
395         (match_operand:DI 1 "di_operand"               "r,m,r,nF"))]
396   "register_operand (operands[0], DImode) || register_operand (operands[1], DImode)"
397   "#"
398   [(set_attr "length" "4,8,12,12")]
399 )
400
401 (define_split
402   [(set (match_operand:DI 0 "nonimmediate_di_operand" "")
403         (match_operand:DI 1 "di_operand" ""))]
404   "reload_completed"
405   [(match_dup 2)]
406   "operands[2] = fr30_move_double (operands);")
407
408 ;;}}}
409 ;;{{{ Load & Store Multiple Registers 
410
411 ;; The load multiple and store multiple patterns are implemented
412 ;; as peepholes because the only time they are expected to occur
413 ;; is during function prologues and epilogues.
414
415 (define_peephole
416   [(set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
417            (match_operand:SI 0 "high_register_operand" "h"))
418    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
419            (match_operand:SI 1 "high_register_operand" "h"))
420    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
421            (match_operand:SI 2 "high_register_operand" "h"))
422    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
423            (match_operand:SI 3 "high_register_operand" "h"))]
424   "fr30_check_multiple_regs (operands, 4, 1)"
425   "stm1 (%0, %1, %2, %3)"
426   [(set_attr "delay_type" "other")]
427 )
428
429 (define_peephole
430   [(set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
431            (match_operand:SI 0 "high_register_operand" "h"))
432    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
433            (match_operand:SI 1 "high_register_operand" "h"))
434    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
435            (match_operand:SI 2 "high_register_operand" "h"))]
436   "fr30_check_multiple_regs (operands, 3, 1)"
437   "stm1 (%0, %1, %2)"
438   [(set_attr "delay_type" "other")]
439 )
440
441 (define_peephole
442   [(set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
443            (match_operand:SI 0 "high_register_operand" "h"))
444    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
445            (match_operand:SI 1 "high_register_operand" "h"))]
446   "fr30_check_multiple_regs (operands, 2, 1)"
447   "stm1 (%0, %1)"
448   [(set_attr "delay_type" "other")]
449 )
450
451 (define_peephole
452   [(set:SI (match_operand:SI 0 "high_register_operand" "h")
453            (mem:SI (post_inc:SI (reg:SI 15))))
454    (set:SI (match_operand:SI 1 "high_register_operand" "h")
455            (mem:SI (post_inc:SI (reg:SI 15))))
456    (set:SI (match_operand:SI 2 "high_register_operand" "h")
457            (mem:SI (post_inc:SI (reg:SI 15))))
458    (set:SI (match_operand:SI 3 "high_register_operand" "h")
459            (mem:SI (post_inc:SI (reg:SI 15))))]
460   "fr30_check_multiple_regs (operands, 4, 0)"
461   "ldm1 (%0, %1, %2, %3)"
462   [(set_attr "delay_type" "other")]
463 )
464
465 (define_peephole
466   [(set:SI (match_operand:SI 0 "high_register_operand" "h")
467            (mem:SI (post_inc:SI (reg:SI 15))))
468    (set:SI (match_operand:SI 1 "high_register_operand" "h")
469            (mem:SI (post_inc:SI (reg:SI 15))))
470    (set:SI (match_operand:SI 2 "high_register_operand" "h")
471            (mem:SI (post_inc:SI (reg:SI 15))))]
472   "fr30_check_multiple_regs (operands, 3, 0)"
473   "ldm1 (%0, %1, %2)"
474   [(set_attr "delay_type" "other")]
475 )
476
477 (define_peephole
478   [(set:SI (match_operand:SI 0 "high_register_operand" "h")
479            (mem:SI (post_inc:SI (reg:SI 15))))
480    (set:SI (match_operand:SI 1 "high_register_operand" "h")
481            (mem:SI (post_inc:SI (reg:SI 15))))]
482   "fr30_check_multiple_regs (operands, 2, 0)"
483   "ldm1 (%0, %1)"
484   [(set_attr "delay_type" "other")]
485 )
486
487 (define_peephole
488   [(set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
489            (match_operand:SI 0 "low_register_operand" "l"))
490    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
491            (match_operand:SI 1 "low_register_operand" "l"))
492    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
493            (match_operand:SI 2 "low_register_operand" "l"))
494    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
495            (match_operand:SI 3 "low_register_operand" "l"))]
496   "fr30_check_multiple_regs (operands, 4, 1)"
497   "stm0 (%0, %1, %2, %3)"
498   [(set_attr "delay_type" "other")]
499 )
500
501 (define_peephole
502   [(set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
503            (match_operand:SI 0 "low_register_operand" "l"))
504    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
505            (match_operand:SI 1 "low_register_operand" "l"))
506    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
507            (match_operand:SI 2 "low_register_operand" "l"))]
508   "fr30_check_multiple_regs (operands, 3, 1)"
509   "stm0 (%0, %1, %2)"
510   [(set_attr "delay_type" "other")]
511 )
512
513 (define_peephole
514   [(set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
515            (match_operand:SI 0 "low_register_operand" "l"))
516    (set:SI (mem:SI (pre_dec:SI (reg:SI 15)))
517            (match_operand:SI 1 "low_register_operand" "l"))]
518   "fr30_check_multiple_regs (operands, 2, 1)"
519   "stm0 (%0, %1)"
520   [(set_attr "delay_type" "other")]
521 )
522
523 ;;}}}
524 ;;{{{ Floating Point Moves 
525
526 ;; Note - Patterns for SF mode moves are compulsory, but
527 ;; patterns for DF are optional, as GCC can synthesize them.
528
529 (define_expand "movsf"
530   [(set (match_operand:SF 0 "general_operand" "")
531         (match_operand:SF 1 "general_operand" ""))]
532   ""
533   "{
534   if (!reload_in_progress && !reload_completed
535       && memory_operand (operands[0], SFmode)
536       && memory_operand (operands[1], SFmode))
537     operands[1] = copy_to_mode_reg (SFmode, operands[1]);
538   }"
539 )
540
541 (define_insn "*movsf_internal"
542   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,red,m,r")
543         (match_operand:SF 1 "general_operand"      "Fn,i,rde,r,rm"))]
544   ""
545   "*
546   {
547     switch (which_alternative)
548     {
549     case 0: return   \"ldi:32\\t%1, %0\";
550     case 1: if (TARGET_SMALL_MODEL)
551               return \"ldi:20\\t%1, %0\";
552             else
553               return \"ldi:32\\t%1, %0\";
554     case 2: return   \"mov   \\t%1, %0\";
555     case 3: return   \"st    \\t%1, %0\";
556     case 4: return   \"ld    \\t%1, %0\";
557     default: gcc_unreachable ();               
558     }
559   }"
560   [(set (attr "length") (cond [(eq_attr "alternative" "0") (const_int 6)
561                                (eq_attr "alternative" "1") 
562                                         (if_then_else (eq_attr "size" "small")
563                                                       (const_int 4)
564                                                       (const_int 6))]
565                               (const_int 2)))]
566 )
567
568 (define_insn "*movsf_constant_store"
569   [(set (match_operand:SF 0 "memory_operand"    "=m")
570         (match_operand:SF 1 "immediate_operand" "F"))]
571   ""
572   "*
573   {
574   const char *    ldi_instr;
575   const char *    tmp_reg;
576   static char     buffer[100];
577
578   ldi_instr = fr30_const_double_is_zero (operands[1])
579             ? ldi_instr = \"ldi:8\" : \"ldi:32\";
580
581   tmp_reg = reg_names [COMPILER_SCRATCH_REGISTER];
582   
583   sprintf (buffer, \"%s\\t#%%1, %s\\t;\\n\\tst\\t%s, %%0\\t; Created by movsf_constant_store\",
584     ldi_instr, tmp_reg, tmp_reg);
585
586   return buffer;
587   }"
588   [(set_attr "length" "8")]
589 )
590
591 ;;}}}
592
593 ;;}}} \f
594 ;;{{{ Conversions 
595
596 ;; Signed conversions from a smaller integer to a larger integer
597
598 (define_insn "extendqisi2"
599   [(set (match_operand:SI 0 "register_operand"                "=r")
600         (sign_extend:SI (match_operand:QI 1 "register_operand" "0")))]
601   ""
602   "extsb        %0"
603 )
604
605 (define_insn "extendhisi2"
606   [(set (match_operand:SI 0 "register_operand"                "=r")
607         (sign_extend:SI (match_operand:HI 1 "register_operand" "0")))]
608   ""
609   "extsh        %0"
610 )
611
612 ;; Unsigned conversions from a smaller integer to a larger integer
613
614 (define_insn "zero_extendqisi2"
615   [(set (match_operand:SI 0 "register_operand"                "=r")
616         (zero_extend:SI (match_operand:QI 1 "register_operand" "0")))]
617   ""
618   "extub        %0"
619 )
620
621 (define_insn "zero_extendhisi2"
622   [(set (match_operand:SI 0 "register_operand"                "=r")
623         (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))]
624   ""
625   "extuh        %0"
626 )
627
628 ;;}}} \f
629 ;;{{{ Arithmetic 
630
631 ;;{{{ Addition 
632
633 ;; This is a special pattern just for adjusting the stack size.
634 (define_insn "add_to_stack"
635   [(set (reg:SI 15)
636         (plus:SI (reg:SI 15)
637                  (match_operand:SI 0 "stack_add_operand" "i")))]
638   ""
639   "addsp        %0"
640 )
641
642 ;; We need some trickery to be able to handle the addition of
643 ;; large (i.e. outside +/- 16) constants.  We need to be able to
644 ;; handle this because reload assumes that it can generate add
645 ;; instructions with arbitrary sized constants.
646 (define_expand "addsi3"
647   [(set (match_operand:SI 0 "register_operand"           "")
648         (plus:SI (match_operand:SI 1 "register_operand"  "")
649                  (match_operand:SI 2 "nonmemory_operand" "")))]
650   ""
651   "{
652   if (   GET_CODE (operands[2]) == REG
653       || GET_CODE (operands[2]) == SUBREG)
654     emit_insn (gen_addsi_regs (operands[0], operands[1], operands[2]));
655   else if (GET_CODE (operands[2]) != CONST_INT)
656     emit_insn (gen_addsi_big_int (operands[0], operands[1], operands[2]));
657   else if (   (REGNO (operands[1]) != FRAME_POINTER_REGNUM)
658            && (REGNO (operands[1]) != ARG_POINTER_REGNUM)
659            && (INTVAL (operands[2]) >= -16)
660            && (INTVAL (operands[2]) <= 15))
661     emit_insn (gen_addsi_small_int (operands[0], operands[1], operands[2]));
662   else
663     emit_insn (gen_addsi_big_int (operands[0], operands[1], operands[2]));
664   DONE;
665   }"
666 )
667
668 (define_insn "addsi_regs"
669   [(set (match_operand:SI 0 "register_operand"          "=r")
670         (plus:SI (match_operand:SI 1 "register_operand" "%0")
671                  (match_operand:SI 2 "register_operand"  "r")))]
672   ""
673   "addn %2, %0"
674 )
675
676 ;; Do not allow an eliminable register in the source register.  It
677 ;; might be eliminated in favor of the stack pointer, probably
678 ;; increasing the offset, and so rendering the instruction illegal.
679 (define_insn "addsi_small_int"
680   [(set (match_operand:SI 0 "register_operand"              "=r,r")
681         (plus:SI (match_operand:SI 1 "register_operand"      "0,0")
682                  (match_operand:SI 2 "add_immediate_operand" "I,J")))]
683   "   (REGNO (operands[1]) != FRAME_POINTER_REGNUM)
684    && (REGNO (operands[1]) != ARG_POINTER_REGNUM)"
685   "@
686    addn %2, %0
687    addn2        %2, %0"
688 )
689
690 (define_expand "addsi_big_int"
691   [(set (match_operand:SI 0 "register_operand"           "")
692         (plus:SI (match_operand:SI 1 "register_operand"  "")
693                  (match_operand:SI 2 "immediate_operand" "")))]
694   ""
695   "{
696   /* Cope with the possibility that ops 0 and 1 are the same register.  */
697   if (REGNO (operands[0]) == REGNO (operands[1]))
698     {
699       if (reload_in_progress || reload_completed)
700         {
701           rtx reg = gen_rtx_REG (SImode, 0/*COMPILER_SCRATCH_REGISTER*/);
702           
703           emit_insn (gen_movsi (reg, operands[2]));
704           emit_insn (gen_addsi_regs (operands[0], operands[0], reg));
705         }
706       else
707         {
708           operands[2] = force_reg (SImode, operands[2]);
709           emit_insn (gen_addsi_regs (operands[0], operands[0], operands[2]));
710         }
711     }
712   else
713     {
714       emit_insn (gen_movsi (operands[0], operands[2]));
715       emit_insn (gen_addsi_regs (operands[0], operands[0], operands[1]));
716     }
717   DONE;
718   }"
719 )
720
721 (define_insn "*addsi_for_reload"
722   [(set (match_operand:SI 0 "register_operand"         "=&r,r,r")
723         (plus:SI (match_operand:SI 1 "register_operand"  "r,r,r")
724                  (match_operand:SI 2 "immediate_operand" "L,M,n")))]
725   "reload_in_progress || reload_completed"
726   "@
727   ldi:8\\t#%2, %0  \\n\\taddn\\t%1, %0
728   ldi:20\\t#%2, %0 \\n\\taddn\\t%1, %0
729   ldi:32\\t#%2, %0 \\n\\taddn\\t%1, %0"
730   [(set_attr "length" "4,6,8")]
731 )
732
733 ;;}}}
734 ;;{{{ Subtraction 
735
736 (define_insn "subsi3"
737   [(set (match_operand:SI 0 "register_operand"       "=r")
738         (minus:SI (match_operand:SI 1 "register_operand" "0")
739                   (match_operand:SI 2 "register_operand" "r")))]
740   ""
741   "subn %2, %0"
742 )
743
744 ;;}}}
745 ;;{{{ Multiplication 
746
747 ;; Signed multiplication producing 64 bit results from 32 bit inputs
748 (define_insn "mulsidi3"
749   [(set (match_operand:DI 0 "register_operand"                             "=r")
750            (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "%r"))
751                     (sign_extend:DI (match_operand:SI 2 "register_operand"  "r"))))
752    (clobber (reg:CC 16))]
753   ""
754   "mul  %2, %1\\n\\tmov\\tmdh, %0\\n\\tmov\\tmdl, %p0"
755   [(set_attr "length" "6")]
756 )
757
758 ;; Unsigned multiplication producing 64 bit results from 32 bit inputs
759 (define_insn "umulsidi3"
760   [(set (match_operand:DI 0 "register_operand"                             "=r")
761            (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "%r"))
762                     (zero_extend:DI (match_operand:SI 2 "register_operand"  "r"))))
763    (clobber (reg:CC 16))]
764   ""
765   "mulu %2, %1\\n\\tmov\\tmdh, %0\\n\\tmov\\tmdl, %p0"
766   [(set_attr "length" "6")]
767 )
768
769 ;; Signed multiplication producing 32 bit result from 16 bit inputs
770 (define_insn "mulhisi3"
771   [(set (match_operand:SI 0 "register_operand"                             "=r")
772            (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%r"))
773                     (sign_extend:SI (match_operand:HI 2 "register_operand"  "r"))))
774    (clobber (reg:CC 16))]
775   ""
776   "mulh %2, %1\\n\\tmov\\tmdl, %0"
777   [(set_attr "length" "4")]
778 )
779
780 ;; Unsigned multiplication producing 32 bit result from 16 bit inputs
781 (define_insn "umulhisi3"
782   [(set (match_operand:SI 0 "register_operand"                             "=r")
783            (mult:SI (zero_extend:SI (match_operand:HI 1 "register_operand" "%r"))
784                     (zero_extend:SI (match_operand:HI 2 "register_operand"  "r"))))
785    (clobber (reg:CC 16))]
786   ""
787   "muluh        %2, %1\\n\\tmov\\tmdl, %0"
788   [(set_attr "length" "4")]
789 )
790
791 ;; Signed multiplication producing 32 bit result from 32 bit inputs
792 (define_insn "mulsi3"
793   [(set (match_operand:SI 0 "register_operand"             "=r")
794            (mult:SI (match_operand:SI 1 "register_operand" "%r")
795                     (match_operand:SI 2 "register_operand"  "r")))
796    (clobber (reg:CC 16))]
797   ""
798   "mul  %2, %1\\n\\tmov\\tmdl, %0"
799   [(set_attr "length" "4")]
800 )
801
802 ;;}}}
803 ;;{{{ Negation 
804
805 (define_expand "negsi2"
806   [(set (match_operand:SI 0 "register_operand"         "")
807         (neg:SI (match_operand:SI 1 "register_operand" "")))]
808   ""
809   "{
810   if (REGNO (operands[0]) == REGNO (operands[1]))
811     {
812       if (reload_in_progress || reload_completed)
813         {
814           rtx reg = gen_rtx_REG (SImode, 0/*COMPILER_SCRATCH_REGISTER*/);
815           
816           emit_insn (gen_movsi (reg, const0_rtx));
817           emit_insn (gen_subsi3 (reg, reg, operands[0]));
818           emit_insn (gen_movsi (operands[0], reg));
819         }
820       else
821         {
822           rtx reg = gen_reg_rtx (SImode);
823         
824           emit_insn (gen_movsi (reg, const0_rtx));
825           emit_insn (gen_subsi3 (reg, reg, operands[0]));
826           emit_insn (gen_movsi (operands[0], reg));
827         }
828     }
829   else
830     {
831       emit_insn (gen_movsi_internal (operands[0], const0_rtx));
832       emit_insn (gen_subsi3 (operands[0], operands[0], operands[1]));
833     }
834   DONE;
835   }"
836 )
837
838 ;;}}}
839
840 ;;}}} \f
841 ;;{{{ Shifts 
842
843 ;; Arithmetic Shift Left
844 (define_insn "ashlsi3"
845   [(set (match_operand:SI 0 "register_operand"            "=r,r,r")
846         (ashift:SI (match_operand:SI 1 "register_operand"  "0,0,0")
847                    (match_operand:SI 2 "nonmemory_operand" "r,I,K")))
848    (clobber (reg:CC 16))]
849   ""
850   "@
851   lsl   %2, %0
852   lsl   %2, %0
853   lsl2  %x2, %0"
854 )
855
856 ;; Arithmetic Shift Right
857 (define_insn "ashrsi3"
858   [(set (match_operand:SI 0 "register_operand"              "=r,r,r")
859         (ashiftrt:SI (match_operand:SI 1 "register_operand"  "0,0,0")
860                      (match_operand:SI 2 "nonmemory_operand" "r,I,K")))
861    (clobber (reg:CC 16))]
862   ""
863   "@
864   asr   %2, %0
865   asr   %2, %0
866   asr2  %x2, %0"
867 )
868
869 ;; Logical Shift Right
870 (define_insn "lshrsi3"
871   [(set (match_operand:SI 0 "register_operand"              "=r,r,r")
872         (lshiftrt:SI (match_operand:SI 1 "register_operand"  "0,0,0")
873                      (match_operand:SI 2 "nonmemory_operand" "r,I,K")))
874    (clobber (reg:CC 16))]
875   ""
876   "@
877   lsr   %2, %0
878   lsr   %2, %0
879   lsr2  %x2, %0"
880 )
881
882 ;;}}} \f
883 ;;{{{ Logical Operations 
884
885 ;; Logical AND, 32 bit integers
886 (define_insn "andsi3"
887   [(set (match_operand:SI 0 "register_operand"         "=r")
888         (and:SI (match_operand:SI 1 "register_operand" "%r")
889                 (match_operand:SI 2 "register_operand"  "0")))
890    (clobber (reg:CC 16))]
891   ""
892   "and  %1, %0"
893 )
894
895 ;; Inclusive OR, 32 bit integers
896 (define_insn "iorsi3"
897   [(set (match_operand:SI 0 "register_operand"         "=r")
898         (ior:SI (match_operand:SI 1 "register_operand" "%r")
899                 (match_operand:SI 2 "register_operand"  "0")))
900    (clobber (reg:CC 16))]
901   ""
902   "or   %1, %0"
903 )
904
905 ;; Exclusive OR, 32 bit integers
906 (define_insn "xorsi3"
907   [(set (match_operand:SI 0 "register_operand"         "=r")
908         (xor:SI (match_operand:SI 1 "register_operand" "%r")
909                 (match_operand:SI 2 "register_operand"  "0")))
910    (clobber (reg:CC 16))]
911   ""
912   "eor  %1, %0"
913 )
914
915 ;; One's complement, 32 bit integers
916 (define_expand "one_cmplsi2"
917   [(set (match_operand:SI 0 "register_operand"         "")
918         (not:SI (match_operand:SI 1 "register_operand" "")))]
919   ""
920   "{
921   if (REGNO (operands[0]) == REGNO (operands[1]))
922     {
923       if (reload_in_progress || reload_completed)
924         {
925           rtx reg = gen_rtx_REG (SImode, 0/*COMPILER_SCRATCH_REGISTER*/);
926           
927           emit_insn (gen_movsi (reg, constm1_rtx));
928           emit_insn (gen_xorsi3 (operands[0], operands[0], reg));
929         }
930       else
931         {
932           rtx reg = gen_reg_rtx (SImode);
933         
934           emit_insn (gen_movsi (reg, constm1_rtx));
935           emit_insn (gen_xorsi3 (operands[0], operands[0], reg));
936         }
937     }
938   else
939     {
940       emit_insn (gen_movsi_internal (operands[0], constm1_rtx));
941       emit_insn (gen_xorsi3 (operands[0], operands[1], operands[0]));
942     }
943   DONE;
944   }"
945 )
946
947 ;;}}} \f
948 ;;{{{ Comparisons 
949
950 ;; Note, we store the operands in the comparison insns, and use them later
951 ;; when generating the branch or scc operation.
952
953 ;; First the routines called by the machine independent part of the compiler
954 (define_expand "cmpsi"
955   [(set (reg:CC 16)
956         (compare:CC (match_operand:SI 0 "register_operand"  "")
957                     (match_operand:SI 1 "nonmemory_operand" "")))]
958   ""
959   "{
960   fr30_compare_op0 = operands[0];
961   fr30_compare_op1 = operands[1];
962   DONE;
963   }"
964 )
965
966 ;; Now, the actual comparisons, generated by the branch and/or scc operations
967
968 (define_insn "*cmpsi_internal"
969   [(set (reg:CC 16)
970         (compare:CC (match_operand:SI 0 "register_operand"  "r,r,r")
971                     (match_operand:SI 1 "nonmemory_operand" "r,I,J")))]
972   ""
973   "@
974   cmp   %1, %0
975   cmp   %1, %0
976   cmp2  %1, %0"
977 )
978
979 ;;}}} \f
980 ;;{{{ Branches 
981
982 ;; Define_expands called by the machine independent part of the compiler
983 ;; to allocate a new comparison register
984
985 (define_expand "beq"
986   [(set (reg:CC 16)
987         (compare:CC (match_dup 1)
988                     (match_dup 2)))
989    (set (pc)
990         (if_then_else (eq:CC (reg:CC 16)
991                              (const_int 0))
992                       (label_ref (match_operand 0 "" ""))
993                       (pc)))]
994   ""
995   "{
996   operands[1] = fr30_compare_op0;
997   operands[2] = fr30_compare_op1;
998   }"
999 )
1000
1001 (define_expand "bne"
1002   [(set (reg:CC 16)
1003         (compare:CC (match_dup 1)
1004                     (match_dup 2)))
1005    (set (pc)
1006         (if_then_else (ne:CC (reg:CC 16)
1007                              (const_int 0))
1008                       (label_ref (match_operand 0 "" ""))
1009                       (pc)))]
1010   ""
1011   "{
1012   operands[1] = fr30_compare_op0;
1013   operands[2] = fr30_compare_op1;
1014   }"
1015 )
1016
1017 (define_expand "blt"
1018   [(set (reg:CC 16)
1019         (compare:CC (match_dup 1)
1020                     (match_dup 2)))
1021    (set (pc)
1022         (if_then_else (lt:CC (reg:CC 16)
1023                              (const_int 0))
1024                       (label_ref (match_operand 0 "" ""))
1025                       (pc)))]
1026   ""
1027   "{
1028   operands[1] = fr30_compare_op0;
1029   operands[2] = fr30_compare_op1;
1030   }"
1031 )
1032
1033 (define_expand "ble"
1034   [(set (reg:CC 16)
1035         (compare:CC (match_dup 1)
1036                     (match_dup 2)))
1037    (set (pc)
1038         (if_then_else (le:CC (reg:CC 16)
1039                              (const_int 0))
1040                       (label_ref (match_operand 0 "" ""))
1041                       (pc)))]
1042   ""
1043   "{
1044   operands[1] = fr30_compare_op0;
1045   operands[2] = fr30_compare_op1;
1046   }"
1047 )
1048
1049 (define_expand "bgt"
1050   [(set (reg:CC 16)
1051         (compare:CC (match_dup 1)
1052                     (match_dup 2)))
1053    (set (pc)
1054         (if_then_else (gt:CC (reg:CC 16)
1055                              (const_int 0))
1056                       (label_ref (match_operand 0 "" ""))
1057                       (pc)))]
1058   ""
1059   "{
1060   operands[1] = fr30_compare_op0;
1061   operands[2] = fr30_compare_op1;
1062   }"
1063 )
1064
1065 (define_expand "bge"
1066   [(set (reg:CC 16)
1067         (compare:CC (match_dup 1)
1068                     (match_dup 2)))
1069    (set (pc)
1070         (if_then_else (ge:CC (reg:CC 16)
1071                              (const_int 0))
1072                       (label_ref (match_operand 0 "" ""))
1073                       (pc)))]
1074   ""
1075   "{
1076   operands[1] = fr30_compare_op0;
1077   operands[2] = fr30_compare_op1;
1078   }"
1079 )
1080
1081 (define_expand "bltu"
1082   [(set (reg:CC 16)
1083         (compare:CC (match_dup 1)
1084                     (match_dup 2)))
1085    (set (pc)
1086         (if_then_else (ltu:CC (reg:CC 16)
1087                               (const_int 0))
1088                       (label_ref (match_operand 0 "" ""))
1089                       (pc)))]
1090   ""
1091   "{
1092   operands[1] = fr30_compare_op0;
1093   operands[2] = fr30_compare_op1;
1094   }"
1095 )
1096
1097 (define_expand "bleu"
1098   [(set (reg:CC 16)
1099         (compare:CC (match_dup 1)
1100                     (match_dup 2)))
1101    (set (pc)
1102         (if_then_else (leu:CC (reg:CC 16)
1103                               (const_int 0))
1104                       (label_ref (match_operand 0 "" ""))
1105                       (pc)))]
1106   ""
1107   "{
1108   operands[1] = fr30_compare_op0;
1109   operands[2] = fr30_compare_op1;
1110   }"
1111 )
1112
1113 (define_expand "bgtu"
1114   [(set (reg:CC 16)
1115         (compare:CC (match_dup 1)
1116                     (match_dup 2)))
1117    (set (pc)
1118         (if_then_else (gtu:CC (reg:CC 16)
1119                               (const_int 0))
1120                       (label_ref (match_operand 0 "" ""))
1121                       (pc)))]
1122   ""
1123   "{
1124   operands[1] = fr30_compare_op0;
1125   operands[2] = fr30_compare_op1;
1126   }"
1127 )
1128
1129 (define_expand "bgeu"
1130   [(set (reg:CC 16)
1131         (compare:CC (match_dup 1)
1132                     (match_dup 2)))
1133    (set (pc)
1134         (if_then_else (geu:CC (reg:CC 16)
1135                               (const_int 0))
1136                       (label_ref (match_operand 0 "" ""))
1137                       (pc)))]
1138   ""
1139   "{
1140   operands[1] = fr30_compare_op0;
1141   operands[2] = fr30_compare_op1;
1142   }"
1143 )
1144
1145 ;; Actual branches.  We must allow for the (label_ref) and the (pc) to be
1146 ;; swapped.  If they are swapped, it reverses the sense of the branch.
1147
1148 ;; This pattern matches the (branch-if-true) branches generated above.
1149 ;; It generates two different instruction sequences depending upon how
1150 ;; far away the destination is.
1151
1152 ;; The calculation for the instruction length is derived as follows:
1153 ;; The branch instruction has a 9 bit signed displacement so we have
1154 ;; this inequality for the displacement:
1155 ;;
1156 ;;               -256 <= pc < 256
1157 ;; or
1158 ;;         -256 + 256 <= pc + 256 < 256 + 256
1159 ;; i.e.
1160 ;;                  0 <= pc + 256 < 512 
1161 ;;
1162 ;; if we consider the displacement as an unsigned value, then negative
1163 ;; displacements become very large positive displacements, and the
1164 ;; inequality becomes:
1165 ;;
1166 ;;              pc + 256 < 512
1167 ;;
1168 ;; In order to allow for the fact that the real branch instruction works
1169 ;; from pc + 2, we increase the offset to 258.
1170 ;;
1171 ;; Note - we do not have to worry about whether the branch is delayed or
1172 ;; not, as branch shortening happens after delay slot reorganization.
1173
1174 (define_insn "*branch_true"
1175   [(set (pc)
1176         (if_then_else (match_operator:CC 0 "comparison_operator"
1177                                          [(reg:CC 16)
1178                                           (const_int 0)])
1179                       (label_ref (match_operand 1 "" ""))
1180                       (pc)))]
1181   ""
1182   "*
1183   {
1184     if (get_attr_length (insn) == 2)
1185       return \"b%b0%#\\t%l1\";
1186     else
1187       {
1188         static char   buffer [100];
1189         const char *  tmp_reg; 
1190         const char *  ldi_insn;
1191         
1192         tmp_reg = reg_names [COMPILER_SCRATCH_REGISTER];
1193         
1194         ldi_insn = TARGET_SMALL_MODEL ? \"ldi:20\" : \"ldi:32\";
1195
1196         /* The code produced here is, for say the EQ case:
1197
1198                Bne  1f
1199                LDI  <label>, r0
1200                JMP  r0
1201              1:                                         */
1202              
1203         sprintf (buffer,
1204           \"b%%B0\\t1f\\t;\\n\\t%s\\t%%l1, %s\\t;\\n\\tjmp%%#\\t@%s\\t;\\n1:\",
1205           ldi_insn, tmp_reg, tmp_reg);
1206  
1207         return buffer;
1208     }
1209   }"
1210   [(set (attr "length") (if_then_else
1211                           (ltu
1212                             (plus
1213                               (minus
1214                                 (match_dup 1)
1215                                 (pc))
1216                               (const_int 254))
1217                             (const_int 506))
1218                           (const_int 2)
1219                           (if_then_else (eq_attr "size" "small")
1220                                         (const_int 8)
1221                                         (const_int 10))))
1222    (set_attr "delay_type" "delayed")]
1223 )
1224
1225
1226 ;; This pattern is a duplicate of the previous one, except that the
1227 ;; branch occurs if the test is false, so the %B operator is used.
1228 (define_insn "*branch_false"
1229   [(set (pc)
1230         (if_then_else (match_operator:CC 0 "comparison_operator"
1231                                          [(reg:CC 16)
1232                                           (const_int 0)])
1233                       (pc)
1234                       (label_ref (match_operand 1 "" ""))))]
1235   ""
1236   "*
1237   {
1238     if (get_attr_length (insn) == 2)
1239       return \"b%B0%#\\t%l1 \";
1240     else
1241       {
1242         static char   buffer [100];
1243         const char *  tmp_reg; 
1244         const char *  ldi_insn;
1245         
1246         tmp_reg = reg_names [COMPILER_SCRATCH_REGISTER];
1247         
1248         ldi_insn = TARGET_SMALL_MODEL ? \"ldi:20\" : \"ldi:32\";
1249
1250         sprintf (buffer,
1251           \"b%%b0\\t1f\\t;\\n\\t%s\\t%%l1, %s\\t;\\n\\tjmp%%#\\t@%s\\t;\\n1:\",
1252           ldi_insn, tmp_reg, tmp_reg);
1253  
1254         return buffer;
1255       }
1256   }"
1257   [(set (attr "length") (if_then_else (ltu (plus (minus (match_dup 1) (pc))
1258                                                  (const_int 254))
1259                                            (const_int 506))
1260                                       (const_int 2)
1261                                       (if_then_else (eq_attr "size" "small")
1262                                                     (const_int 8)
1263                                                     (const_int 10))))
1264    (set_attr "delay_type" "delayed")]
1265 )
1266
1267 ;;}}} \f
1268 ;;{{{ Calls & Jumps 
1269
1270 ;; Subroutine call instruction returning no value.  Operand 0 is the function
1271 ;; to call; operand 1 is the number of bytes of arguments pushed (in mode
1272 ;; `SImode', except it is normally a `const_int'); operand 2 is the number of
1273 ;; registers used as operands.
1274
1275 (define_insn "call"
1276   [(call (match_operand 0 "call_operand" "Qm")
1277          (match_operand 1 ""             "g"))
1278    (clobber (reg:SI 17))]
1279   ""
1280   "call%#\\t%0"
1281   [(set_attr "delay_type" "delayed")]
1282 )
1283
1284 ;; Subroutine call instruction returning a value.  Operand 0 is the hard
1285 ;; register in which the value is returned.  There are three more operands, the
1286 ;; same as the three operands of the `call' instruction (but with numbers
1287 ;; increased by one).
1288
1289 ;; Subroutines that return `BLKmode' objects use the `call' insn.
1290
1291 (define_insn "call_value"
1292   [(set (match_operand 0 "register_operand"  "=r")
1293         (call (match_operand 1 "call_operand" "Qm")
1294               (match_operand 2 ""             "g")))
1295    (clobber (reg:SI 17))]
1296   ""
1297   "call%#\\t%1"
1298   [(set_attr "delay_type" "delayed")]
1299 )
1300
1301 ;; Normal unconditional jump.
1302 ;; For a description of the computation of the length 
1303 ;; attribute see the branch patterns above.
1304 ;;
1305 ;; Although this instruction really clobbers r0, flow
1306 ;; relies on jump being simplejump_p in several places
1307 ;; and as r0 is fixed, this doesn't change anything
1308 (define_insn "jump"
1309   [(set (pc) (label_ref (match_operand 0 "" "")))]
1310   ""
1311   "*
1312   {
1313     if (get_attr_length (insn) == 2)
1314        return \"bra%#\\t%0\";
1315     else
1316       {
1317         static char   buffer [100];
1318         const char *  tmp_reg; 
1319         const char *  ldi_insn;
1320         
1321         tmp_reg = reg_names [COMPILER_SCRATCH_REGISTER];
1322
1323         ldi_insn = TARGET_SMALL_MODEL ? \"ldi:20\" : \"ldi:32\";
1324
1325         sprintf (buffer, \"%s\\t%%0, %s\\t;\\n\\tjmp%%#\\t@%s\\t;\",
1326           ldi_insn, tmp_reg, tmp_reg);
1327  
1328         return buffer;
1329       }
1330   }"
1331   [(set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1332                                                 (const_int 254))
1333                                           (const_int 506))
1334                                      (const_int 2)
1335                                      (if_then_else (eq_attr "size" "small")
1336                                                    (const_int 6)
1337                                                    (const_int 8))))
1338    (set_attr "delay_type" "delayed")]
1339 )
1340
1341 ;; Indirect jump through a register
1342 (define_insn "indirect_jump"
1343   [(set (pc) (match_operand:SI 0 "nonimmediate_operand" "r"))]
1344   "GET_CODE (operands[0]) != MEM || GET_CODE (XEXP (operands[0], 0)) != PLUS"
1345   "jmp%#\\t@%0"
1346   [(set_attr "delay_type" "delayed")]
1347 )
1348
1349 (define_insn "tablejump"
1350   [(set (pc) (match_operand:SI 0 "register_operand" "r"))
1351    (use (label_ref (match_operand 1 "" "")))]
1352   ""
1353   "jmp%#\\t@%0"
1354   [(set_attr "delay_type" "delayed")]
1355 )
1356
1357 ;;}}} \f
1358 ;;{{{ Function Prologues and Epilogues 
1359
1360 ;; Called after register allocation to add any instructions needed for the
1361 ;; prologue.  Using a prologue insn is favored compared to putting all of the
1362 ;; instructions in output_function_prologue(), since it allows the scheduler
1363 ;; to intermix instructions with the saves of the caller saved registers.  In
1364 ;; some cases, it might be necessary to emit a barrier instruction as the last
1365 ;; insn to prevent such scheduling.
1366 (define_expand "prologue"
1367   [(clobber (const_int 0))]
1368   ""
1369   "{
1370   fr30_expand_prologue ();
1371   DONE;
1372   }"
1373 )
1374
1375 ;; Called after register allocation to add any instructions needed for the
1376 ;; epilogue.  Using an epilogue insn is favored compared to putting all of the
1377 ;; instructions in output_function_epilogue(), since it allows the scheduler
1378 ;; to intermix instructions with the restores of the caller saved registers.
1379 ;; In some cases, it might be necessary to emit a barrier instruction as the
1380 ;; first insn to prevent such scheduling.
1381 (define_expand "epilogue"
1382   [(return)]
1383   ""
1384   "{
1385   fr30_expand_epilogue ();
1386   DONE;
1387   }"
1388 )
1389
1390 (define_insn "return_from_func"
1391   [(return)
1392    (use (reg:SI 17))]
1393   "reload_completed"
1394   "ret%#"
1395   [(set_attr "delay_type" "delayed")]
1396 )
1397
1398 (define_insn "leave_func"
1399   [(set (reg:SI 15) (reg:SI 14))
1400    (set (reg:SI 14) (mem:SI (post_inc:SI (reg:SI 15))))]
1401   "reload_completed"
1402   "leave"
1403 )
1404
1405 (define_insn "enter_func"
1406   [(set:SI (mem:SI (minus:SI (reg:SI 15)
1407                              (const_int 4)))
1408            (reg:SI 14))
1409    (set:SI (reg:SI 14)
1410            (minus:SI (reg:SI 15)
1411                      (const_int 4)))
1412    (set:SI (reg:SI 15)
1413            (minus:SI (reg:SI 15)
1414                      (match_operand 0 "immediate_operand" "i")))]
1415   "reload_completed"
1416   "enter        #%0"
1417   [(set_attr "delay_type" "other")]
1418 )
1419
1420 ;;}}} \f
1421 ;;{{{ Miscellaneous 
1422
1423 ;; No operation, needed in case the user uses -g but not -O.
1424 (define_insn "nop"
1425   [(const_int 0)]
1426   ""
1427   "nop"
1428 )
1429
1430 ;; Pseudo instruction that prevents the scheduler from moving code above this
1431 ;; point.
1432 (define_insn "blockage"
1433   [(unspec_volatile [(const_int 0)] 0)]
1434   ""
1435   ""
1436   [(set_attr "length" "0")]
1437 )
1438 ;;}}} \f
1439   
1440 ;; Local Variables:
1441 ;; mode: md
1442 ;; folded-file: t
1443 ;; End: