2003-09-12 Dave Brolley <brolley@redhat.com>
[external/binutils.git] / sim / frv / profile-fr500.c
1 /* frv simulator fr500 dependent profiling code.
2
3    Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
4    Contributed by Red Hat
5
6 This file is part of the GNU simulators.
7
8 This program 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 This program 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 along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 */
23 #define WANT_CPU
24 #define WANT_CPU_FRVBF
25
26 #include "sim-main.h"
27 #include "bfd.h"
28
29 #if WITH_PROFILE_MODEL_P
30
31 #include "profile.h"
32 #include "profile-fr500.h"
33
34 /* Initialize cycle counting for an insn.
35    FIRST_P is non-zero if this is the first insn in a set of parallel
36    insns.  */
37 void
38 fr500_model_insn_before (SIM_CPU *cpu, int first_p)
39 {
40   if (first_p)
41     {
42       MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
43       FRV_PROFILE_STATE *ps = CPU_PROFILE_STATE (cpu);
44       ps->cur_gr_complex = ps->prev_gr_complex;
45       d->cur_fpop     = d->prev_fpop;
46       d->cur_media    = d->prev_media;
47       d->cur_cc_complex = d->prev_cc_complex;
48     }
49 }
50
51 /* Record the cycles computed for an insn.
52    LAST_P is non-zero if this is the last insn in a set of parallel insns,
53    and we update the total cycle count.
54    CYCLES is the cycle count of the insn.  */
55 void
56 fr500_model_insn_after (SIM_CPU *cpu, int last_p, int cycles)
57 {
58   if (last_p)
59     {
60       MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
61       FRV_PROFILE_STATE *ps = CPU_PROFILE_STATE (cpu);
62       ps->prev_gr_complex = ps->cur_gr_complex;
63       d->prev_fpop     = d->cur_fpop;
64       d->prev_media    = d->cur_media;
65       d->prev_cc_complex = d->cur_cc_complex;
66     }
67 }
68
69 static void
70 set_use_is_fpop (SIM_CPU *cpu, INT fr)
71 {
72   MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
73   fr500_reset_fr_flags (cpu, (fr));
74   d->cur_fpop |=  (((DI)1) << (fr));
75 }
76
77 static void
78 set_use_not_fpop (SIM_CPU *cpu, INT fr)
79 {
80   MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
81   d->cur_fpop &= ~(((DI)1) << (fr));
82 }
83
84 static int
85 use_is_fpop (SIM_CPU *cpu, INT fr)
86 {
87   MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
88   return d->prev_fpop & (((DI)1) << (fr));
89 }
90
91 static void
92 set_use_is_media ( SIM_CPU *cpu, INT fr)
93 {
94   MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
95   fr500_reset_fr_flags (cpu, (fr));
96   d->cur_media |=  (((DI)1) << (fr));
97 }
98
99 static void
100 set_use_not_media (SIM_CPU *cpu, INT fr)
101 {
102   MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
103   d->cur_media &= ~(((DI)1) << (fr));
104 }
105
106 static int
107 use_is_media (SIM_CPU *cpu, INT fr)
108 {
109   MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
110   return d->prev_media & (((DI)1) << (fr));
111 }
112
113 static void
114 set_use_is_cc_complex (SIM_CPU *cpu, INT cc)
115 {
116   MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
117   fr500_reset_cc_flags (cpu, cc);
118   d->cur_cc_complex |= (((DI)1) << (cc));
119 }
120
121 static void
122 set_use_not_cc_complex (SIM_CPU *cpu, INT cc)
123 {
124   MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
125   d->cur_cc_complex &= ~(((DI)1) << (cc));
126 }
127
128 static int
129 use_is_cc_complex (SIM_CPU *cpu, INT cc)
130 {
131   MODEL_FR500_DATA *d = CPU_MODEL_DATA (cpu);
132   return d->prev_cc_complex &   (((DI)1) << (cc));
133 }
134
135 void
136 fr500_reset_fr_flags (SIM_CPU *cpu, INT fr)
137 {
138   set_use_not_fpop (cpu, fr);
139   set_use_not_media (cpu, fr);
140 }
141
142 void
143 fr500_reset_cc_flags (SIM_CPU *cpu, INT cc)
144 {
145   set_use_not_cc_complex (cpu, cc);
146 }
147
148 /* Latency of floating point registers may be less than recorded when followed
149    by another floating point insn.  */
150 static void
151 adjust_float_register_busy (SIM_CPU *cpu, INT in_FRi, INT in_FRj, INT out_FRk,
152                             int cycles)
153 {
154   /* If the registers were previously used in a floating point op,
155      then their latency will be less than previously recorded.
156      See Table 13-13 in the LSI.  */
157   if (in_FRi >= 0)
158     if (use_is_fpop (cpu, in_FRi))
159       decrease_FR_busy (cpu, in_FRi, cycles);
160     else
161       enforce_full_fr_latency (cpu, in_FRi);
162   
163   if (in_FRj >= 0 && in_FRj != in_FRi)
164     if (use_is_fpop (cpu, in_FRj))
165       decrease_FR_busy (cpu, in_FRj, cycles);
166     else
167       enforce_full_fr_latency (cpu, in_FRj);
168
169   if (out_FRk >= 0 && out_FRk != in_FRi && out_FRk != in_FRj)
170     if (use_is_fpop (cpu, out_FRk))
171       decrease_FR_busy (cpu, out_FRk, cycles);
172     else
173       enforce_full_fr_latency (cpu, out_FRk);
174 }
175
176 /* Latency of floating point registers may be less than recorded when followed
177    by another floating point insn.  */
178 static void
179 adjust_double_register_busy (SIM_CPU *cpu, INT in_FRi, INT in_FRj, INT out_FRk,
180                             int cycles)
181 {
182   /* If the registers were previously used in a floating point op,
183      then their latency will be less than previously recorded.
184      See Table 13-13 in the LSI.  */
185   adjust_float_register_busy (cpu, in_FRi, in_FRj, out_FRk, cycles);
186   if (in_FRi >= 0)  ++in_FRi;
187   if (in_FRj >= 0)  ++in_FRj;
188   if (out_FRk >= 0) ++out_FRk;
189   adjust_float_register_busy (cpu, in_FRi, in_FRj, out_FRk, cycles);
190 }
191
192 /* Latency of floating point registers is less than recorded when followed
193    by another floating point insn.  */
194 static void
195 restore_float_register_busy (SIM_CPU *cpu, INT in_FRi, INT in_FRj, INT out_FRk,
196                              int cycles)
197 {
198   /* If the registers were previously used in a floating point op,
199      then their latency will be less than previously recorded.
200      See Table 13-13 in the LSI.  */
201   if (in_FRi >= 0 && use_is_fpop (cpu, in_FRi))
202     increase_FR_busy (cpu, in_FRi, cycles);
203   if (in_FRj != in_FRi && use_is_fpop (cpu, in_FRj))
204     increase_FR_busy (cpu, in_FRj, cycles);
205   if (out_FRk != in_FRi && out_FRk != in_FRj && use_is_fpop (cpu, out_FRk))
206     increase_FR_busy (cpu, out_FRk, cycles);
207 }
208
209 /* Latency of floating point registers is less than recorded when followed
210    by another floating point insn.  */
211 static void
212 restore_double_register_busy (SIM_CPU *cpu, INT in_FRi, INT in_FRj, INT out_FRk,
213                             int cycles)
214 {
215   /* If the registers were previously used in a floating point op,
216      then their latency will be less than previously recorded.
217      See Table 13-13 in the LSI.  */
218   restore_float_register_busy (cpu, in_FRi, in_FRj, out_FRk, cycles);
219   if (in_FRi >= 0)  ++in_FRi;
220   if (in_FRj >= 0)  ++in_FRj;
221   if (out_FRk >= 0) ++out_FRk;
222   restore_float_register_busy (cpu, in_FRi, in_FRj, out_FRk, cycles);
223 }
224
225 int
226 frvbf_model_fr500_u_exec (SIM_CPU *cpu, const IDESC *idesc,
227                           int unit_num, int referenced)
228 {
229   return idesc->timing->units[unit_num].done;
230 }
231
232 int
233 frvbf_model_fr500_u_integer (SIM_CPU *cpu, const IDESC *idesc,
234                              int unit_num, int referenced,
235                              INT in_GRi, INT in_GRj, INT out_GRk,
236                              INT out_ICCi_1)
237 {
238   int cycles;
239
240   if (model_insn == FRV_INSN_MODEL_PASS_1)
241     {
242       /* icc0-icc4 are the upper 4 fields of the CCR.  */
243       if (out_ICCi_1 >= 0)
244         out_ICCi_1 += 4;
245
246       /* The entire VLIW insn must wait if there is a dependency on a register
247          which is not ready yet.
248          The latency of the registers may be less than previously recorded,
249          depending on how they were used previously.
250          See Table 13-8 in the LSI.  */
251       if (in_GRi != out_GRk && in_GRi >= 0)
252         {
253           if (use_is_gr_complex (cpu, in_GRi))
254             decrease_GR_busy (cpu, in_GRi, 1);
255         }
256       if (in_GRj != out_GRk && in_GRj != in_GRi && in_GRj >= 0)
257         {
258           if (use_is_gr_complex (cpu, in_GRj))
259             decrease_GR_busy (cpu, in_GRj, 1);
260         }
261       vliw_wait_for_GR (cpu, in_GRi);
262       vliw_wait_for_GR (cpu, in_GRj);
263       vliw_wait_for_GR (cpu, out_GRk);
264       vliw_wait_for_CCR (cpu, out_ICCi_1);
265       handle_resource_wait (cpu);
266       load_wait_for_GR (cpu, in_GRi);
267       load_wait_for_GR (cpu, in_GRj);
268       load_wait_for_GR (cpu, out_GRk);
269       trace_vliw_wait_cycles (cpu);
270       return 0;
271     }
272
273   /* GRk is available immediately to the next VLIW insn as is ICCi_1.  */
274   cycles = idesc->timing->units[unit_num].done;
275   return cycles;
276 }
277
278 int
279 frvbf_model_fr500_u_imul (SIM_CPU *cpu, const IDESC *idesc,
280                           int unit_num, int referenced,
281                           INT in_GRi, INT in_GRj, INT out_GRk, INT out_ICCi_1)
282 {
283   int cycles;
284   /* icc0-icc4 are the upper 4 fields of the CCR.  */
285   if (out_ICCi_1 >= 0)
286     out_ICCi_1 += 4;
287
288   if (model_insn == FRV_INSN_MODEL_PASS_1)
289     {
290       /* The entire VLIW insn must wait if there is a dependency on a register
291          which is not ready yet.
292          The latency of the registers may be less than previously recorded,
293          depending on how they were used previously.
294          See Table 13-8 in the LSI.  */
295       if (in_GRi != out_GRk && in_GRi >= 0)
296         {
297           if (use_is_gr_complex (cpu, in_GRi))
298             decrease_GR_busy (cpu, in_GRi, 1);
299         }
300       if (in_GRj != out_GRk && in_GRj != in_GRi && in_GRj >= 0)
301         {
302           if (use_is_gr_complex (cpu, in_GRj))
303             decrease_GR_busy (cpu, in_GRj, 1);
304         }
305       vliw_wait_for_GR (cpu, in_GRi);
306       vliw_wait_for_GR (cpu, in_GRj);
307       vliw_wait_for_GRdouble (cpu, out_GRk);
308       vliw_wait_for_CCR (cpu, out_ICCi_1);
309       handle_resource_wait (cpu);
310       load_wait_for_GR (cpu, in_GRi);
311       load_wait_for_GR (cpu, in_GRj);
312       load_wait_for_GRdouble (cpu, out_GRk);
313       trace_vliw_wait_cycles (cpu);
314       return 0;
315     }
316
317   /* GRk has a latency of 2 cycles.  */
318   cycles = idesc->timing->units[unit_num].done;
319   update_GRdouble_latency (cpu, out_GRk, cycles + 2);
320   set_use_is_gr_complex (cpu, out_GRk);
321   set_use_is_gr_complex (cpu, out_GRk + 1);
322
323   /* ICCi_1 has a latency of 1 cycle.  */
324   update_CCR_latency (cpu, out_ICCi_1, cycles + 1);
325
326   return cycles;
327 }
328
329 int
330 frvbf_model_fr500_u_idiv (SIM_CPU *cpu, const IDESC *idesc,
331                           int unit_num, int referenced,
332                           INT in_GRi, INT in_GRj, INT out_GRk, INT out_ICCi_1)
333 {
334   int cycles;
335   FRV_VLIW *vliw;
336   int slot;
337
338   /* icc0-icc4 are the upper 4 fields of the CCR.  */
339   if (out_ICCi_1 >= 0)
340     out_ICCi_1 += 4;
341
342   vliw = CPU_VLIW (cpu);
343   slot = vliw->next_slot - 1;
344   slot = (*vliw->current_vliw)[slot] - UNIT_I0;
345
346   if (model_insn == FRV_INSN_MODEL_PASS_1)
347     {
348       /* The entire VLIW insn must wait if there is a dependency on a register
349          which is not ready yet.
350          The latency of the registers may be less than previously recorded,
351          depending on how they were used previously.
352          See Table 13-8 in the LSI.  */
353       if (in_GRi != out_GRk && in_GRi >= 0)
354         {
355           if (use_is_gr_complex (cpu, in_GRi))
356             decrease_GR_busy (cpu, in_GRi, 1);
357         }
358       if (in_GRj != out_GRk && in_GRj != in_GRi && in_GRj >= 0)
359         {
360           if (use_is_gr_complex (cpu, in_GRj))
361             decrease_GR_busy (cpu, in_GRj, 1);
362         }
363       vliw_wait_for_GR (cpu, in_GRi);
364       vliw_wait_for_GR (cpu, in_GRj);
365       vliw_wait_for_GR (cpu, out_GRk);
366       vliw_wait_for_CCR (cpu, out_ICCi_1);
367       vliw_wait_for_idiv_resource (cpu, slot);
368       handle_resource_wait (cpu);
369       load_wait_for_GR (cpu, in_GRi);
370       load_wait_for_GR (cpu, in_GRj);
371       load_wait_for_GR (cpu, out_GRk);
372       trace_vliw_wait_cycles (cpu);
373       return 0;
374     }
375
376   /* GRk has a latency of 19 cycles!  */
377   cycles = idesc->timing->units[unit_num].done;
378   update_GR_latency (cpu, out_GRk, cycles + 19);
379   set_use_is_gr_complex (cpu, out_GRk);
380
381   /* ICCi_1 has a latency of 19 cycles.  */
382   update_CCR_latency (cpu, out_ICCi_1, cycles + 19);
383   set_use_is_cc_complex (cpu, out_ICCi_1);
384
385   if (CGEN_ATTR_VALUE(idesc, idesc->attrs, CGEN_INSN_NON_EXCEPTING))
386     {
387       /* GNER has a latency of 18 cycles.  */
388       update_SPR_latency (cpu, GNER_FOR_GR (out_GRk), cycles + 18);
389     }
390
391   /* the idiv resource has a latency of 18 cycles!  */
392   update_idiv_resource_latency (cpu, slot, cycles + 18);
393
394   return cycles;
395 }
396
397 int
398 frvbf_model_fr500_u_branch (SIM_CPU *cpu, const IDESC *idesc,
399                             int unit_num, int referenced,
400                             INT in_GRi, INT in_GRj,
401                             INT in_ICCi_2, INT in_FCCi_2)
402 {
403   int cycles;
404   FRV_PROFILE_STATE *ps;
405
406   if (model_insn == FRV_INSN_MODEL_PASS_1)
407     {
408       /* icc0-icc4 are the upper 4 fields of the CCR.  */
409       if (in_ICCi_2 >= 0)
410         in_ICCi_2 += 4;
411
412       /* The entire VLIW insn must wait if there is a dependency on a register
413          which is not ready yet.
414          The latency of the registers may be less than previously recorded,
415          depending on how they were used previously.
416          See Table 13-8 in the LSI.  */
417       if (in_GRi >= 0)
418         {
419           if (use_is_gr_complex (cpu, in_GRi))
420             decrease_GR_busy (cpu, in_GRi, 1);
421         }
422       if (in_GRj != in_GRi && in_GRj >= 0)
423         {
424           if (use_is_gr_complex (cpu, in_GRj))
425             decrease_GR_busy (cpu, in_GRj, 1);
426         }
427       vliw_wait_for_GR (cpu, in_GRi);
428       vliw_wait_for_GR (cpu, in_GRj);
429       vliw_wait_for_CCR (cpu, in_ICCi_2);
430       vliw_wait_for_CCR (cpu, in_FCCi_2);
431       handle_resource_wait (cpu);
432       load_wait_for_GR (cpu, in_GRi);
433       load_wait_for_GR (cpu, in_GRj);
434       trace_vliw_wait_cycles (cpu);
435       return 0;
436     }
437
438   /* When counting branches taken or not taken, don't consider branches after
439      the first taken branch in a vliw insn.  */
440   ps = CPU_PROFILE_STATE (cpu);
441   if (! ps->vliw_branch_taken)
442     {
443       /* (1 << 4): The pc is the 5th element in inputs, outputs.
444          ??? can be cleaned up */
445       PROFILE_DATA *p = CPU_PROFILE_DATA (cpu);
446       int taken = (referenced & (1 << 4)) != 0;
447       if (taken)
448         {
449           ++PROFILE_MODEL_TAKEN_COUNT (p);
450           ps->vliw_branch_taken = 1;
451         }
452       else
453         ++PROFILE_MODEL_UNTAKEN_COUNT (p);
454     }
455
456   cycles = idesc->timing->units[unit_num].done;
457   return cycles;
458 }
459
460 int
461 frvbf_model_fr500_u_trap (SIM_CPU *cpu, const IDESC *idesc,
462                           int unit_num, int referenced,
463                           INT in_GRi, INT in_GRj,
464                           INT in_ICCi_2, INT in_FCCi_2)
465 {
466   int cycles;
467
468   if (model_insn == FRV_INSN_MODEL_PASS_1)
469     {
470       /* icc0-icc4 are the upper 4 fields of the CCR.  */
471       if (in_ICCi_2 >= 0)
472         in_ICCi_2 += 4;
473
474       /* The entire VLIW insn must wait if there is a dependency on a register
475          which is not ready yet.
476          The latency of the registers may be less than previously recorded,
477          depending on how they were used previously.
478          See Table 13-8 in the LSI.  */
479       if (in_GRi >= 0)
480         {
481           if (use_is_gr_complex (cpu, in_GRi))
482             decrease_GR_busy (cpu, in_GRi, 1);
483         }
484       if (in_GRj != in_GRi && in_GRj >= 0)
485         {
486           if (use_is_gr_complex (cpu, in_GRj))
487             decrease_GR_busy (cpu, in_GRj, 1);
488         }
489       vliw_wait_for_GR (cpu, in_GRi);
490       vliw_wait_for_GR (cpu, in_GRj);
491       vliw_wait_for_CCR (cpu, in_ICCi_2);
492       vliw_wait_for_CCR (cpu, in_FCCi_2);
493       handle_resource_wait (cpu);
494       load_wait_for_GR (cpu, in_GRi);
495       load_wait_for_GR (cpu, in_GRj);
496       trace_vliw_wait_cycles (cpu);
497       return 0;
498     }
499
500   cycles = idesc->timing->units[unit_num].done;
501   return cycles;
502 }
503
504 int
505 frvbf_model_fr500_u_check (SIM_CPU *cpu, const IDESC *idesc,
506                            int unit_num, int referenced,
507                            INT in_ICCi_3, INT in_FCCi_3)
508 {
509   int cycles;
510
511   if (model_insn == FRV_INSN_MODEL_PASS_1)
512     {
513       /* icc0-icc4 are the upper 4 fields of the CCR.  */
514       if (in_ICCi_3 >= 0)
515         in_ICCi_3 += 4;
516
517       /* The entire VLIW insn must wait if there is a dependency on a register
518          which is not ready yet.  */
519       vliw_wait_for_CCR (cpu, in_ICCi_3);
520       vliw_wait_for_CCR (cpu, in_FCCi_3);
521       handle_resource_wait (cpu);
522       trace_vliw_wait_cycles (cpu);
523       return 0;
524     }
525
526   cycles = idesc->timing->units[unit_num].done;
527   return cycles;
528 }
529
530 int
531 frvbf_model_fr500_u_clrgr (SIM_CPU *cpu, const IDESC *idesc,
532                            int unit_num, int referenced,
533                            INT in_GRk)
534 {
535   int cycles;
536
537   if (model_insn == FRV_INSN_MODEL_PASS_1)
538     {
539       /* Wait for both GNER registers or just the one specified.  */
540       if (in_GRk == -1)
541         {
542           vliw_wait_for_SPR (cpu, H_SPR_GNER0);
543           vliw_wait_for_SPR (cpu, H_SPR_GNER1);
544         }
545       else
546         vliw_wait_for_SPR (cpu, GNER_FOR_GR (in_GRk));
547       handle_resource_wait (cpu);
548       trace_vliw_wait_cycles (cpu);
549       return 0;
550     }
551
552   cycles = idesc->timing->units[unit_num].done;
553   return cycles;
554 }
555
556 int
557 frvbf_model_fr500_u_clrfr (SIM_CPU *cpu, const IDESC *idesc,
558                            int unit_num, int referenced,
559                            INT in_FRk)
560 {
561   int cycles;
562
563   if (model_insn == FRV_INSN_MODEL_PASS_1)
564     {
565       /* Wait for both GNER registers or just the one specified.  */
566       if (in_FRk == -1)
567         {
568           vliw_wait_for_SPR (cpu, H_SPR_FNER0);
569           vliw_wait_for_SPR (cpu, H_SPR_FNER1);
570         }
571       else
572         vliw_wait_for_SPR (cpu, FNER_FOR_FR (in_FRk));
573       handle_resource_wait (cpu);
574       trace_vliw_wait_cycles (cpu);
575       return 0;
576     }
577
578   cycles = idesc->timing->units[unit_num].done;
579   return cycles;
580 }
581
582 int
583 frvbf_model_fr500_u_set_hilo (SIM_CPU *cpu, const IDESC *idesc,
584                              int unit_num, int referenced,
585                              INT out_GRkhi, INT out_GRklo)
586 {
587   int cycles;
588
589   if (model_insn == FRV_INSN_MODEL_PASS_1)
590     {
591       /* The entire VLIW insn must wait if there is a dependency on a GR
592          which is not ready yet.  */
593       vliw_wait_for_GR (cpu, out_GRkhi);
594       vliw_wait_for_GR (cpu, out_GRklo);
595       handle_resource_wait (cpu);
596       load_wait_for_GR (cpu, out_GRkhi);
597       load_wait_for_GR (cpu, out_GRklo);
598       trace_vliw_wait_cycles (cpu);
599       return 0;
600     }
601
602   /* GRk is available immediately to the next VLIW insn.  */
603   cycles = idesc->timing->units[unit_num].done;
604
605   set_use_not_gr_complex (cpu, out_GRkhi);
606   set_use_not_gr_complex (cpu, out_GRklo);
607
608   return cycles;
609 }
610
611 int
612 frvbf_model_fr500_u_gr_load (SIM_CPU *cpu, const IDESC *idesc,
613                              int unit_num, int referenced,
614                              INT in_GRi, INT in_GRj,
615                              INT out_GRk, INT out_GRdoublek)
616 {
617   int cycles;
618
619   if (model_insn == FRV_INSN_MODEL_PASS_1)
620     {
621       /* The entire VLIW insn must wait if there is a dependency on a register
622          which is not ready yet.
623          The latency of the registers may be less than previously recorded,
624          depending on how they were used previously.
625          See Table 13-8 in the LSI.  */
626       if (in_GRi != out_GRk && in_GRi != out_GRdoublek
627           && in_GRi != out_GRdoublek + 1 && in_GRi >= 0)
628         {
629           if (use_is_gr_complex (cpu, in_GRi))
630             decrease_GR_busy (cpu, in_GRi, 1);
631         }
632       if (in_GRj != in_GRi && in_GRj != out_GRk && in_GRj != out_GRdoublek
633           && in_GRj != out_GRdoublek + 1 && in_GRj >= 0)
634
635         {
636           if (use_is_gr_complex (cpu, in_GRj))
637             decrease_GR_busy (cpu, in_GRj, 1);
638         }
639       vliw_wait_for_GR (cpu, in_GRi);
640       vliw_wait_for_GR (cpu, in_GRj);
641       vliw_wait_for_GR (cpu, out_GRk);
642       vliw_wait_for_GRdouble (cpu, out_GRdoublek);
643       handle_resource_wait (cpu);
644       load_wait_for_GR (cpu, in_GRi);
645       load_wait_for_GR (cpu, in_GRj);
646       load_wait_for_GR (cpu, out_GRk);
647       load_wait_for_GRdouble (cpu, out_GRdoublek);
648       trace_vliw_wait_cycles (cpu);
649       return 0;
650     }
651
652   cycles = idesc->timing->units[unit_num].done;
653
654   /* The latency of GRk for a load will depend on how long it takes to retrieve
655      the the data from the cache or memory.  */
656   update_GR_latency_for_load (cpu, out_GRk, cycles);
657   update_GRdouble_latency_for_load (cpu, out_GRdoublek, cycles);
658
659   set_use_is_gr_complex (cpu, out_GRk);
660   set_use_is_gr_complex (cpu, out_GRdoublek);
661   set_use_is_gr_complex (cpu, out_GRdoublek + 1);
662
663   return cycles;
664 }
665
666 int
667 frvbf_model_fr500_u_gr_store (SIM_CPU *cpu, const IDESC *idesc,
668                               int unit_num, int referenced,
669                               INT in_GRi, INT in_GRj,
670                               INT in_GRk, INT in_GRdoublek)
671 {
672   int cycles;
673
674   if (model_insn == FRV_INSN_MODEL_PASS_1)
675     {
676       /* The entire VLIW insn must wait if there is a dependency on a register
677          which is not ready yet.
678          The latency of the registers may be less than previously recorded,
679          depending on how they were used previously.
680          See Table 13-8 in the LSI.  */
681       if (in_GRi >= 0)
682         {
683           if (use_is_gr_complex (cpu, in_GRi))
684             decrease_GR_busy (cpu, in_GRi, 1);
685         }
686       if (in_GRj != in_GRi && in_GRj >= 0)
687         {
688           if (use_is_gr_complex (cpu, in_GRj))
689             decrease_GR_busy (cpu, in_GRj, 1);
690         }
691       if (in_GRk != in_GRi && in_GRk != in_GRj && in_GRk >= 0)
692         {
693           if (use_is_gr_complex (cpu, in_GRk))
694             decrease_GR_busy (cpu, in_GRk, 1);
695         }
696       if (in_GRdoublek != in_GRi && in_GRdoublek != in_GRj
697           && in_GRdoublek + 1 != in_GRi && in_GRdoublek + 1 != in_GRj
698           && in_GRdoublek >= 0)
699         {
700           if (use_is_gr_complex (cpu, in_GRdoublek))
701             decrease_GR_busy (cpu, in_GRdoublek, 1);
702           if (use_is_gr_complex (cpu, in_GRdoublek + 1))
703             decrease_GR_busy (cpu, in_GRdoublek + 1, 1);
704         }
705       vliw_wait_for_GR (cpu, in_GRi);
706       vliw_wait_for_GR (cpu, in_GRj);
707       vliw_wait_for_GR (cpu, in_GRk);
708       vliw_wait_for_GRdouble (cpu, in_GRdoublek);
709       handle_resource_wait (cpu);
710       load_wait_for_GR (cpu, in_GRi);
711       load_wait_for_GR (cpu, in_GRj);
712       load_wait_for_GR (cpu, in_GRk);
713       load_wait_for_GRdouble (cpu, in_GRdoublek);
714       trace_vliw_wait_cycles (cpu);
715       return 0;
716     }
717
718   cycles = idesc->timing->units[unit_num].done;
719
720   return cycles;
721 }
722
723 int
724 frvbf_model_fr500_u_gr_r_store (SIM_CPU *cpu, const IDESC *idesc,
725                                 int unit_num, int referenced,
726                                 INT in_GRi, INT in_GRj,
727                                 INT in_GRk, INT in_GRdoublek)
728 {
729   int cycles = frvbf_model_fr500_u_gr_store (cpu, idesc, unit_num, referenced,
730                                              in_GRi, in_GRj, in_GRk,
731                                              in_GRdoublek);
732
733   if (model_insn == FRV_INSN_MODEL_PASS_2)
734     {
735       if (CPU_RSTR_INVALIDATE(cpu))
736         request_cache_invalidate (cpu, CPU_DATA_CACHE (cpu), cycles);
737     }
738
739   return cycles;
740 }
741
742 int
743 frvbf_model_fr500_u_fr_load (SIM_CPU *cpu, const IDESC *idesc,
744                              int unit_num, int referenced,
745                              INT in_GRi, INT in_GRj,
746                              INT out_FRk, INT out_FRdoublek)
747 {
748   int cycles;
749
750   if (model_insn == FRV_INSN_MODEL_PASS_1)
751     {
752       /* The entire VLIW insn must wait if there is a dependency on a register
753          which is not ready yet.
754          The latency of the registers may be less than previously recorded,
755          depending on how they were used previously.
756          See Table 13-8 in the LSI.  */
757       if (in_GRi >= 0)
758         {
759           if (use_is_gr_complex (cpu, in_GRi))
760             decrease_GR_busy (cpu, in_GRi, 1);
761         }
762       if (in_GRj != in_GRi && in_GRj >= 0)
763         {
764           if (use_is_gr_complex (cpu, in_GRj))
765             decrease_GR_busy (cpu, in_GRj, 1);
766         }
767       if (out_FRk >= 0)
768         {
769           if (use_is_media (cpu, out_FRk))
770             decrease_FR_busy (cpu, out_FRk, 1);
771           else
772             adjust_float_register_busy (cpu, -1, -1, out_FRk, 1);
773         }
774       if (out_FRdoublek >= 0)
775         {
776           if (use_is_media (cpu, out_FRdoublek))
777             decrease_FR_busy (cpu, out_FRdoublek, 1);
778           else
779             adjust_float_register_busy (cpu, -1, -1, out_FRdoublek, 1);
780           if (use_is_media (cpu, out_FRdoublek + 1))
781             decrease_FR_busy (cpu, out_FRdoublek + 1, 1);
782           else
783             adjust_float_register_busy (cpu, -1, -1, out_FRdoublek + 1, 1);
784         }
785       vliw_wait_for_GR (cpu, in_GRi);
786       vliw_wait_for_GR (cpu, in_GRj);
787       vliw_wait_for_FR (cpu, out_FRk);
788       vliw_wait_for_FRdouble (cpu, out_FRdoublek);
789       handle_resource_wait (cpu);
790       load_wait_for_GR (cpu, in_GRi);
791       load_wait_for_GR (cpu, in_GRj);
792       load_wait_for_FR (cpu, out_FRk);
793       load_wait_for_FRdouble (cpu, out_FRdoublek);
794       trace_vliw_wait_cycles (cpu);
795       return 0;
796     }
797
798   cycles = idesc->timing->units[unit_num].done;
799
800   /* The latency of FRk for a load will depend on how long it takes to retrieve
801      the the data from the cache or memory.  */
802   update_FR_latency_for_load (cpu, out_FRk, cycles);
803   update_FRdouble_latency_for_load (cpu, out_FRdoublek, cycles);
804
805   fr500_reset_fr_flags (cpu, out_FRk);
806
807   return cycles;
808 }
809
810 int
811 frvbf_model_fr500_u_fr_store (SIM_CPU *cpu, const IDESC *idesc,
812                               int unit_num, int referenced,
813                               INT in_GRi, INT in_GRj,
814                               INT in_FRk, INT in_FRdoublek)
815 {
816   int cycles;
817
818   if (model_insn == FRV_INSN_MODEL_PASS_1)
819     {
820       /* The entire VLIW insn must wait if there is a dependency on a register
821          which is not ready yet.
822          The latency of the registers may be less than previously recorded,
823          depending on how they were used previously.
824          See Table 13-8 in the LSI.  */
825       if (in_GRi >= 0)
826         {
827           if (use_is_gr_complex (cpu, in_GRi))
828             decrease_GR_busy (cpu, in_GRi, 1);
829         }
830       if (in_GRj != in_GRi && in_GRj >= 0)
831         {
832           if (use_is_gr_complex (cpu, in_GRj))
833             decrease_GR_busy (cpu, in_GRj, 1);
834         }
835       if (in_FRk >= 0)
836         {
837           if (use_is_media (cpu, in_FRk))
838             decrease_FR_busy (cpu, in_FRk, 1);
839           else
840             adjust_float_register_busy (cpu, -1, -1, in_FRk, 1);
841         }
842       if (in_FRdoublek >= 0)
843         {
844           if (use_is_media (cpu, in_FRdoublek))
845             decrease_FR_busy (cpu, in_FRdoublek, 1);
846           else
847             adjust_float_register_busy (cpu, -1, -1, in_FRdoublek, 1);
848           if (use_is_media (cpu, in_FRdoublek + 1))
849             decrease_FR_busy (cpu, in_FRdoublek + 1, 1);
850           else
851             adjust_float_register_busy (cpu, -1, -1, in_FRdoublek + 1, 1);
852         }
853       vliw_wait_for_GR (cpu, in_GRi);
854       vliw_wait_for_GR (cpu, in_GRj);
855       vliw_wait_for_FR (cpu, in_FRk);
856       vliw_wait_for_FRdouble (cpu, in_FRdoublek);
857       handle_resource_wait (cpu);
858       load_wait_for_GR (cpu, in_GRi);
859       load_wait_for_GR (cpu, in_GRj);
860       load_wait_for_FR (cpu, in_FRk);
861       load_wait_for_FRdouble (cpu, in_FRdoublek);
862       trace_vliw_wait_cycles (cpu);
863       return 0;
864     }
865
866   cycles = idesc->timing->units[unit_num].done;
867
868   return cycles;
869 }
870
871 int
872 frvbf_model_fr500_u_fr_r_store (SIM_CPU *cpu, const IDESC *idesc,
873                                 int unit_num, int referenced,
874                                 INT in_GRi, INT in_GRj,
875                                 INT in_FRk, INT in_FRdoublek)
876 {
877   int cycles = frvbf_model_fr500_u_fr_store (cpu, idesc, unit_num, referenced,
878                                              in_GRi, in_GRj, in_FRk,
879                                              in_FRdoublek);
880
881   if (model_insn == FRV_INSN_MODEL_PASS_2)
882     {
883       if (CPU_RSTR_INVALIDATE(cpu))
884         request_cache_invalidate (cpu, CPU_DATA_CACHE (cpu), cycles);
885     }
886
887   return cycles;
888 }
889
890 int
891 frvbf_model_fr500_u_swap (SIM_CPU *cpu, const IDESC *idesc,
892                           int unit_num, int referenced,
893                           INT in_GRi, INT in_GRj, INT out_GRk)
894 {
895   int cycles;
896
897   if (model_insn == FRV_INSN_MODEL_PASS_1)
898     {
899       /* The entire VLIW insn must wait if there is a dependency on a register
900          which is not ready yet.
901          The latency of the registers may be less than previously recorded,
902          depending on how they were used previously.
903          See Table 13-8 in the LSI.  */
904       if (in_GRi != out_GRk && in_GRi >= 0)
905         {
906           if (use_is_gr_complex (cpu, in_GRi))
907             decrease_GR_busy (cpu, in_GRi, 1);
908         }
909       if (in_GRj != out_GRk && in_GRj != in_GRi && in_GRj >= 0)
910         {
911           if (use_is_gr_complex (cpu, in_GRj))
912             decrease_GR_busy (cpu, in_GRj, 1);
913         }
914       vliw_wait_for_GR (cpu, in_GRi);
915       vliw_wait_for_GR (cpu, in_GRj);
916       vliw_wait_for_GR (cpu, out_GRk);
917       handle_resource_wait (cpu);
918       load_wait_for_GR (cpu, in_GRi);
919       load_wait_for_GR (cpu, in_GRj);
920       load_wait_for_GR (cpu, out_GRk);
921       trace_vliw_wait_cycles (cpu);
922       return 0;
923     }
924
925   cycles = idesc->timing->units[unit_num].done;
926
927   /* The latency of GRk will depend on how long it takes to swap
928      the the data from the cache or memory.  */
929   update_GR_latency_for_swap (cpu, out_GRk, cycles);
930   set_use_is_gr_complex (cpu, out_GRk);
931
932   return cycles;
933 }
934
935 int
936 frvbf_model_fr500_u_fr2fr (SIM_CPU *cpu, const IDESC *idesc,
937                            int unit_num, int referenced,
938                            INT in_FRj, INT out_FRk)
939 {
940   int cycles;
941
942   if (model_insn == FRV_INSN_MODEL_PASS_1)
943     {
944       /* The entire VLIW insn must wait if there is a dependency on a register
945          which is not ready yet.  */
946       if (in_FRj >= 0)
947         {
948           if (use_is_media (cpu, in_FRj))
949             decrease_FR_busy (cpu, in_FRj, 1);
950           else
951             adjust_float_register_busy (cpu, -1, in_FRj, -1, 1);
952         }
953       if (out_FRk >= 0 && out_FRk != in_FRj)
954         {
955           if (use_is_media (cpu, out_FRk))
956             decrease_FR_busy (cpu, out_FRk, 1);
957           else
958             adjust_float_register_busy (cpu, -1, -1, out_FRk, 1);
959         }
960       vliw_wait_for_FR (cpu, in_FRj);
961       vliw_wait_for_FR (cpu, out_FRk);
962       handle_resource_wait (cpu);
963       load_wait_for_FR (cpu, in_FRj);
964       load_wait_for_FR (cpu, out_FRk);
965       trace_vliw_wait_cycles (cpu);
966       return 0;
967     }
968
969   /* The latency of FRj is 3 cycles.  */
970   cycles = idesc->timing->units[unit_num].done;
971   update_FR_latency (cpu, out_FRk, cycles + 3);
972
973   return cycles;
974 }
975
976 int
977 frvbf_model_fr500_u_fr2gr (SIM_CPU *cpu, const IDESC *idesc,
978                            int unit_num, int referenced,
979                            INT in_FRk, INT out_GRj)
980 {
981   int cycles;
982
983   if (model_insn == FRV_INSN_MODEL_PASS_1)
984     {
985       /* The entire VLIW insn must wait if there is a dependency on a register
986          which is not ready yet.  */
987       if (in_FRk >= 0)
988         {
989           if (use_is_media (cpu, in_FRk))
990             decrease_FR_busy (cpu, in_FRk, 1);
991           else
992             adjust_float_register_busy (cpu, -1, in_FRk, -1, 1);
993         }
994       vliw_wait_for_FR (cpu, in_FRk);
995       vliw_wait_for_GR (cpu, out_GRj);
996       handle_resource_wait (cpu);
997       load_wait_for_FR (cpu, in_FRk);
998       load_wait_for_GR (cpu, out_GRj);
999       trace_vliw_wait_cycles (cpu);
1000       return 0;
1001     }
1002
1003   /* The latency of GRj is 2 cycles.  */
1004   cycles = idesc->timing->units[unit_num].done;
1005   update_GR_latency (cpu, out_GRj, cycles + 2);
1006   set_use_is_gr_complex (cpu, out_GRj);
1007
1008   return cycles;
1009 }
1010
1011 int
1012 frvbf_model_fr500_u_spr2gr (SIM_CPU *cpu, const IDESC *idesc,
1013                            int unit_num, int referenced,
1014                            INT in_spr, INT out_GRj)
1015 {
1016   int cycles;
1017
1018   if (model_insn == FRV_INSN_MODEL_PASS_1)
1019     {
1020       /* The entire VLIW insn must wait if there is a dependency on a register
1021          which is not ready yet.  */
1022       vliw_wait_for_SPR (cpu, in_spr);
1023       vliw_wait_for_GR (cpu, out_GRj);
1024       handle_resource_wait (cpu);
1025       load_wait_for_GR (cpu, out_GRj);
1026       trace_vliw_wait_cycles (cpu);
1027       return 0;
1028     }
1029
1030   cycles = idesc->timing->units[unit_num].done;
1031
1032 #if 0 /* no latency?  */
1033   /* The latency of GRj is 2 cycles.  */
1034   update_GR_latency (cpu, out_GRj, cycles + 2);
1035 #endif
1036
1037   return cycles;
1038 }
1039
1040 int
1041 frvbf_model_fr500_u_gr2fr (SIM_CPU *cpu, const IDESC *idesc,
1042                            int unit_num, int referenced,
1043                            INT in_GRj, INT out_FRk)
1044 {
1045   int cycles;
1046
1047   if (model_insn == FRV_INSN_MODEL_PASS_1)
1048     {
1049       /* The entire VLIW insn must wait if there is a dependency on a register
1050          which is not ready yet.
1051          The latency of the registers may be less than previously recorded,
1052          depending on how they were used previously.
1053          See Table 13-8 in the LSI.  */
1054       if (in_GRj >= 0)
1055         {
1056           if (use_is_gr_complex (cpu, in_GRj))
1057             decrease_GR_busy (cpu, in_GRj, 1);
1058         }
1059       if (out_FRk >= 0)
1060         {
1061           if (use_is_media (cpu, out_FRk))
1062             decrease_FR_busy (cpu, out_FRk, 1);
1063           else
1064             adjust_float_register_busy (cpu, -1, out_FRk, -1, 1);
1065         }
1066       vliw_wait_for_GR (cpu, in_GRj);
1067       vliw_wait_for_FR (cpu, out_FRk);
1068       handle_resource_wait (cpu);
1069       load_wait_for_GR (cpu, in_GRj);
1070       load_wait_for_FR (cpu, out_FRk);
1071       trace_vliw_wait_cycles (cpu);
1072       return 0;
1073     }
1074
1075   /* The latency of FRk is 2 cycles.  */
1076   cycles = idesc->timing->units[unit_num].done;
1077   update_FR_latency (cpu, out_FRk, cycles + 2);
1078
1079   /* Mark this use of the register as NOT a floating point op.  */
1080   fr500_reset_fr_flags (cpu, out_FRk);
1081
1082   return cycles;
1083 }
1084
1085 int
1086 frvbf_model_fr500_u_gr2spr (SIM_CPU *cpu, const IDESC *idesc,
1087                             int unit_num, int referenced,
1088                             INT in_GRj, INT out_spr)
1089 {
1090   int cycles;
1091
1092   if (model_insn == FRV_INSN_MODEL_PASS_1)
1093     {
1094       /* The entire VLIW insn must wait if there is a dependency on a register
1095          which is not ready yet.
1096          The latency of the registers may be less than previously recorded,
1097          depending on how they were used previously.
1098          See Table 13-8 in the LSI.  */
1099       if (in_GRj >= 0)
1100         {
1101           if (use_is_gr_complex (cpu, in_GRj))
1102             decrease_GR_busy (cpu, in_GRj, 1);
1103         }
1104       vliw_wait_for_GR (cpu, in_GRj);
1105       vliw_wait_for_SPR (cpu, out_spr);
1106       handle_resource_wait (cpu);
1107       load_wait_for_GR (cpu, in_GRj);
1108       trace_vliw_wait_cycles (cpu);
1109       return 0;
1110     }
1111
1112   cycles = idesc->timing->units[unit_num].done;
1113
1114 #if 0
1115   /* The latency of spr is ? cycles.  */
1116   update_SPR_latency (cpu, out_spr, cycles + ?);
1117 #endif
1118
1119   return cycles;
1120 }
1121
1122 int
1123 frvbf_model_fr500_u_ici (SIM_CPU *cpu, const IDESC *idesc,
1124                          int unit_num, int referenced,
1125                          INT in_GRi, INT in_GRj)
1126 {
1127   int cycles;
1128
1129   if (model_insn == FRV_INSN_MODEL_PASS_1)
1130     {
1131       /* The entire VLIW insn must wait if there is a dependency on a register
1132          which is not ready yet.
1133          The latency of the registers may be less than previously recorded,
1134          depending on how they were used previously.
1135          See Table 13-8 in the LSI.  */
1136       if (in_GRi >= 0)
1137         {
1138           if (use_is_gr_complex (cpu, in_GRi))
1139             decrease_GR_busy (cpu, in_GRi, 1);
1140         }
1141       if (in_GRj != in_GRi && in_GRj >= 0)
1142         {
1143           if (use_is_gr_complex (cpu, in_GRj))
1144             decrease_GR_busy (cpu, in_GRj, 1);
1145         }
1146       vliw_wait_for_GR (cpu, in_GRi);
1147       vliw_wait_for_GR (cpu, in_GRj);
1148       handle_resource_wait (cpu);
1149       load_wait_for_GR (cpu, in_GRi);
1150       load_wait_for_GR (cpu, in_GRj);
1151       trace_vliw_wait_cycles (cpu);
1152       return 0;
1153     }
1154
1155   cycles = idesc->timing->units[unit_num].done;
1156   request_cache_invalidate (cpu, CPU_INSN_CACHE (cpu), cycles);
1157   return cycles;
1158 }
1159
1160 int
1161 frvbf_model_fr500_u_dci (SIM_CPU *cpu, const IDESC *idesc,
1162                          int unit_num, int referenced,
1163                          INT in_GRi, INT in_GRj)
1164 {
1165   int cycles;
1166
1167   if (model_insn == FRV_INSN_MODEL_PASS_1)
1168     {
1169       /* The entire VLIW insn must wait if there is a dependency on a register
1170          which is not ready yet.
1171          The latency of the registers may be less than previously recorded,
1172          depending on how they were used previously.
1173          See Table 13-8 in the LSI.  */
1174       if (in_GRi >= 0)
1175         {
1176           if (use_is_gr_complex (cpu, in_GRi))
1177             decrease_GR_busy (cpu, in_GRi, 1);
1178         }
1179       if (in_GRj != in_GRi && in_GRj >= 0)
1180         {
1181           if (use_is_gr_complex (cpu, in_GRj))
1182             decrease_GR_busy (cpu, in_GRj, 1);
1183         }
1184       vliw_wait_for_GR (cpu, in_GRi);
1185       vliw_wait_for_GR (cpu, in_GRj);
1186       handle_resource_wait (cpu);
1187       load_wait_for_GR (cpu, in_GRi);
1188       load_wait_for_GR (cpu, in_GRj);
1189       trace_vliw_wait_cycles (cpu);
1190       return 0;
1191     }
1192
1193   cycles = idesc->timing->units[unit_num].done;
1194   request_cache_invalidate (cpu, CPU_DATA_CACHE (cpu), cycles);
1195   return cycles;
1196 }
1197
1198 int
1199 frvbf_model_fr500_u_dcf (SIM_CPU *cpu, const IDESC *idesc,
1200                          int unit_num, int referenced,
1201                          INT in_GRi, INT in_GRj)
1202 {
1203   int cycles;
1204
1205   if (model_insn == FRV_INSN_MODEL_PASS_1)
1206     {
1207       /* The entire VLIW insn must wait if there is a dependency on a register
1208          which is not ready yet.
1209          The latency of the registers may be less than previously recorded,
1210          depending on how they were used previously.
1211          See Table 13-8 in the LSI.  */
1212       if (in_GRi >= 0)
1213         {
1214           if (use_is_gr_complex (cpu, in_GRi))
1215             decrease_GR_busy (cpu, in_GRi, 1);
1216         }
1217       if (in_GRj != in_GRi && in_GRj >= 0)
1218         {
1219           if (use_is_gr_complex (cpu, in_GRj))
1220             decrease_GR_busy (cpu, in_GRj, 1);
1221         }
1222       vliw_wait_for_GR (cpu, in_GRi);
1223       vliw_wait_for_GR (cpu, in_GRj);
1224       handle_resource_wait (cpu);
1225       load_wait_for_GR (cpu, in_GRi);
1226       load_wait_for_GR (cpu, in_GRj);
1227       trace_vliw_wait_cycles (cpu);
1228       return 0;
1229     }
1230
1231   cycles = idesc->timing->units[unit_num].done;
1232   request_cache_flush (cpu, CPU_DATA_CACHE (cpu), cycles);
1233   return cycles;
1234 }
1235
1236 int
1237 frvbf_model_fr500_u_icpl (SIM_CPU *cpu, const IDESC *idesc,
1238                           int unit_num, int referenced,
1239                           INT in_GRi, INT in_GRj)
1240 {
1241   int cycles;
1242
1243   if (model_insn == FRV_INSN_MODEL_PASS_1)
1244     {
1245       /* The entire VLIW insn must wait if there is a dependency on a register
1246          which is not ready yet.
1247          The latency of the registers may be less than previously recorded,
1248          depending on how they were used previously.
1249          See Table 13-8 in the LSI.  */
1250       if (in_GRi >= 0)
1251         {
1252           if (use_is_gr_complex (cpu, in_GRi))
1253             decrease_GR_busy (cpu, in_GRi, 1);
1254         }
1255       if (in_GRj != in_GRi && in_GRj >= 0)
1256         {
1257           if (use_is_gr_complex (cpu, in_GRj))
1258             decrease_GR_busy (cpu, in_GRj, 1);
1259         }
1260       vliw_wait_for_GR (cpu, in_GRi);
1261       vliw_wait_for_GR (cpu, in_GRj);
1262       handle_resource_wait (cpu);
1263       load_wait_for_GR (cpu, in_GRi);
1264       load_wait_for_GR (cpu, in_GRj);
1265       trace_vliw_wait_cycles (cpu);
1266       return 0;
1267     }
1268
1269   cycles = idesc->timing->units[unit_num].done;
1270   request_cache_preload (cpu, CPU_INSN_CACHE (cpu), cycles);
1271   return cycles;
1272 }
1273
1274 int
1275 frvbf_model_fr500_u_dcpl (SIM_CPU *cpu, const IDESC *idesc,
1276                           int unit_num, int referenced,
1277                           INT in_GRi, INT in_GRj)
1278 {
1279   int cycles;
1280
1281   if (model_insn == FRV_INSN_MODEL_PASS_1)
1282     {
1283       /* The entire VLIW insn must wait if there is a dependency on a register
1284          which is not ready yet.
1285          The latency of the registers may be less than previously recorded,
1286          depending on how they were used previously.
1287          See Table 13-8 in the LSI.  */
1288       if (in_GRi >= 0)
1289         {
1290           if (use_is_gr_complex (cpu, in_GRi))
1291             decrease_GR_busy (cpu, in_GRi, 1);
1292         }
1293       if (in_GRj != in_GRi && in_GRj >= 0)
1294         {
1295           if (use_is_gr_complex (cpu, in_GRj))
1296             decrease_GR_busy (cpu, in_GRj, 1);
1297         }
1298       vliw_wait_for_GR (cpu, in_GRi);
1299       vliw_wait_for_GR (cpu, in_GRj);
1300       handle_resource_wait (cpu);
1301       load_wait_for_GR (cpu, in_GRi);
1302       load_wait_for_GR (cpu, in_GRj);
1303       trace_vliw_wait_cycles (cpu);
1304       return 0;
1305     }
1306
1307   cycles = idesc->timing->units[unit_num].done;
1308   request_cache_preload (cpu, CPU_DATA_CACHE (cpu), cycles);
1309   return cycles;
1310 }
1311
1312 int
1313 frvbf_model_fr500_u_icul (SIM_CPU *cpu, const IDESC *idesc,
1314                           int unit_num, int referenced,
1315                           INT in_GRi, INT in_GRj)
1316 {
1317   int cycles;
1318
1319   if (model_insn == FRV_INSN_MODEL_PASS_1)
1320     {
1321       /* The entire VLIW insn must wait if there is a dependency on a register
1322          which is not ready yet.
1323          The latency of the registers may be less than previously recorded,
1324          depending on how they were used previously.
1325          See Table 13-8 in the LSI.  */
1326       if (in_GRi >= 0)
1327         {
1328           if (use_is_gr_complex (cpu, in_GRi))
1329             decrease_GR_busy (cpu, in_GRi, 1);
1330         }
1331       if (in_GRj != in_GRi && in_GRj >= 0)
1332         {
1333           if (use_is_gr_complex (cpu, in_GRj))
1334             decrease_GR_busy (cpu, in_GRj, 1);
1335         }
1336       vliw_wait_for_GR (cpu, in_GRi);
1337       vliw_wait_for_GR (cpu, in_GRj);
1338       handle_resource_wait (cpu);
1339       load_wait_for_GR (cpu, in_GRi);
1340       load_wait_for_GR (cpu, in_GRj);
1341       trace_vliw_wait_cycles (cpu);
1342       return 0;
1343     }
1344
1345   cycles = idesc->timing->units[unit_num].done;
1346   request_cache_unlock (cpu, CPU_INSN_CACHE (cpu), cycles);
1347   return cycles;
1348 }
1349
1350 int
1351 frvbf_model_fr500_u_dcul (SIM_CPU *cpu, const IDESC *idesc,
1352                           int unit_num, int referenced,
1353                           INT in_GRi, INT in_GRj)
1354 {
1355   int cycles;
1356
1357   if (model_insn == FRV_INSN_MODEL_PASS_1)
1358     {
1359       /* The entire VLIW insn must wait if there is a dependency on a register
1360          which is not ready yet.
1361          The latency of the registers may be less than previously recorded,
1362          depending on how they were used previously.
1363          See Table 13-8 in the LSI.  */
1364       if (in_GRi >= 0)
1365         {
1366           if (use_is_gr_complex (cpu, in_GRi))
1367             decrease_GR_busy (cpu, in_GRi, 1);
1368         }
1369       if (in_GRj != in_GRi && in_GRj >= 0)
1370         {
1371           if (use_is_gr_complex (cpu, in_GRj))
1372             decrease_GR_busy (cpu, in_GRj, 1);
1373         }
1374       vliw_wait_for_GR (cpu, in_GRi);
1375       vliw_wait_for_GR (cpu, in_GRj);
1376       handle_resource_wait (cpu);
1377       load_wait_for_GR (cpu, in_GRi);
1378       load_wait_for_GR (cpu, in_GRj);
1379       trace_vliw_wait_cycles (cpu);
1380       return 0;
1381     }
1382
1383   cycles = idesc->timing->units[unit_num].done;
1384   request_cache_unlock (cpu, CPU_DATA_CACHE (cpu), cycles);
1385   return cycles;
1386 }
1387
1388 /* Top up the post-processing time of the given FR by the given number of
1389    cycles.  */
1390 static void
1391 update_FR_ptime (SIM_CPU *cpu, INT out_FR, int cycles)
1392 {
1393   if (out_FR >= 0)
1394     {
1395       FRV_PROFILE_STATE *ps = CPU_PROFILE_STATE (cpu);
1396       /* If a load is pending on this register, then add the cycles to
1397          the post processing time for this register. Otherwise apply it
1398          directly to the latency of the register.  */
1399       if (! load_pending_for_register (cpu, out_FR, 1, REGTYPE_FR))
1400         {
1401           int *fr = ps->fr_latency;
1402           fr[out_FR] += cycles;
1403         }
1404       else
1405         ps->fr_ptime[out_FR] += cycles;
1406     }
1407 }
1408
1409 static void
1410 update_FRdouble_ptime (SIM_CPU *cpu, INT out_FR, int cycles)
1411 {
1412   if (out_FR >= 0)
1413     {
1414       FRV_PROFILE_STATE *ps = CPU_PROFILE_STATE (cpu);
1415       /* If a load is pending on this register, then add the cycles to
1416          the post processing time for this register. Otherwise apply it
1417          directly to the latency of the register.  */
1418       if (! load_pending_for_register (cpu, out_FR, 2, REGTYPE_FR))
1419         {
1420           int *fr = ps->fr_latency;
1421           fr[out_FR] += cycles;
1422           if (out_FR < 63)
1423             fr[out_FR + 1] += cycles;
1424         }
1425       else
1426         {
1427           ps->fr_ptime[out_FR] += cycles;
1428           if (out_FR < 63)
1429             ps->fr_ptime[out_FR + 1] += cycles;
1430         }
1431     }
1432 }
1433
1434 int
1435 frvbf_model_fr500_u_float_arith (SIM_CPU *cpu, const IDESC *idesc,
1436                                  int unit_num, int referenced,
1437                                  INT in_FRi, INT in_FRj,
1438                                  INT in_FRdoublei, INT in_FRdoublej,
1439                                  INT out_FRk, INT out_FRdoublek)
1440 {
1441   int cycles;
1442   FRV_PROFILE_STATE *ps;
1443
1444   if (model_insn == FRV_INSN_MODEL_PASS_1)
1445     return 0;
1446
1447   /* The preprocessing can execute right away.  */
1448   cycles = idesc->timing->units[unit_num].done;
1449
1450   /* The post processing must wait if there is a dependency on a FR
1451      which is not ready yet.  */
1452   adjust_float_register_busy (cpu, in_FRi, in_FRj, out_FRk, 1);
1453   adjust_double_register_busy (cpu, in_FRdoublei, in_FRdoublej, out_FRdoublek,
1454                                1);
1455   ps = CPU_PROFILE_STATE (cpu);
1456   ps->post_wait = cycles;
1457   post_wait_for_FR (cpu, in_FRi);
1458   post_wait_for_FR (cpu, in_FRj);
1459   post_wait_for_FR (cpu, out_FRk);
1460   post_wait_for_FRdouble (cpu, in_FRdoublei);
1461   post_wait_for_FRdouble (cpu, in_FRdoublej);
1462   post_wait_for_FRdouble (cpu, out_FRdoublek);
1463   restore_float_register_busy (cpu, in_FRi, in_FRj, out_FRk, 1);
1464   restore_double_register_busy (cpu, in_FRdoublei, in_FRdoublej, out_FRdoublek,
1465                                 1);
1466
1467   /* The latency of FRk will be at least the latency of the other inputs.  */
1468   update_FR_latency (cpu, out_FRk, ps->post_wait);
1469   update_FRdouble_latency (cpu, out_FRdoublek, ps->post_wait);
1470
1471   /* Once initiated, post-processing will take 3 cycles.  */
1472   update_FR_ptime (cpu, out_FRk, 3);
1473   update_FRdouble_ptime (cpu, out_FRdoublek, 3);
1474
1475   /* Mark this use of the register as a floating point op.  */
1476   if (out_FRk >= 0)
1477     set_use_is_fpop (cpu, out_FRk);
1478   if (out_FRdoublek >= 0)
1479     {
1480       set_use_is_fpop (cpu, out_FRdoublek);
1481       if (out_FRdoublek < 63)
1482         set_use_is_fpop (cpu, out_FRdoublek + 1);
1483     }
1484
1485   return cycles;
1486 }
1487
1488 int
1489 frvbf_model_fr500_u_float_dual_arith (SIM_CPU *cpu, const IDESC *idesc,
1490                                       int unit_num, int referenced,
1491                                       INT in_FRi, INT in_FRj,
1492                                       INT in_FRdoublei, INT in_FRdoublej,
1493                                       INT out_FRk, INT out_FRdoublek)
1494 {
1495   int cycles;
1496   INT dual_FRi;
1497   INT dual_FRj;
1498   INT dual_FRk;
1499   INT dual_FRdoublei;
1500   INT dual_FRdoublej;
1501   INT dual_FRdoublek;
1502   FRV_PROFILE_STATE *ps;
1503
1504   if (model_insn == FRV_INSN_MODEL_PASS_1)
1505     return 0;
1506
1507   /* The preprocessing can execute right away.  */
1508   cycles = idesc->timing->units[unit_num].done;
1509
1510   /* The post processing must wait if there is a dependency on a FR
1511      which is not ready yet.  */
1512   dual_FRi = DUAL_REG (in_FRi);
1513   dual_FRj = DUAL_REG (in_FRj);
1514   dual_FRk = DUAL_REG (out_FRk);
1515   dual_FRdoublei = DUAL_DOUBLE (in_FRdoublei);
1516   dual_FRdoublej = DUAL_DOUBLE (in_FRdoublej);
1517   dual_FRdoublek = DUAL_DOUBLE (out_FRdoublek);
1518
1519   adjust_float_register_busy (cpu, in_FRi, in_FRj, out_FRk, 1);
1520   adjust_float_register_busy (cpu, dual_FRi, dual_FRj, dual_FRk, 1);
1521   adjust_double_register_busy (cpu, in_FRdoublei, in_FRdoublej, out_FRdoublek,
1522                                1);
1523   adjust_double_register_busy (cpu, dual_FRdoublei, dual_FRdoublej,
1524                                dual_FRdoublek, 1);
1525   ps = CPU_PROFILE_STATE (cpu);
1526   ps->post_wait = cycles;
1527   post_wait_for_FR (cpu, in_FRi);
1528   post_wait_for_FR (cpu, in_FRj);
1529   post_wait_for_FR (cpu, out_FRk);
1530   post_wait_for_FR (cpu, dual_FRi);
1531   post_wait_for_FR (cpu, dual_FRj);
1532   post_wait_for_FR (cpu, dual_FRk);
1533   post_wait_for_FRdouble (cpu, in_FRdoublei);
1534   post_wait_for_FRdouble (cpu, in_FRdoublej);
1535   post_wait_for_FRdouble (cpu, out_FRdoublek);
1536   post_wait_for_FRdouble (cpu, dual_FRdoublei);
1537   post_wait_for_FRdouble (cpu, dual_FRdoublej);
1538   post_wait_for_FRdouble (cpu, dual_FRdoublek);
1539   restore_float_register_busy (cpu, in_FRi, in_FRj, out_FRk, 1);
1540   restore_float_register_busy (cpu, dual_FRi, dual_FRj, dual_FRk, 1);
1541   restore_double_register_busy (cpu, in_FRdoublei, in_FRdoublej, out_FRdoublek,
1542                                 1);
1543   restore_double_register_busy (cpu, dual_FRdoublei, dual_FRdoublej,
1544                                 dual_FRdoublek, 1);
1545
1546   /* The latency of FRk will be at least the latency of the other inputs.  */
1547   update_FR_latency (cpu, out_FRk, ps->post_wait);
1548   update_FR_latency (cpu, dual_FRk, ps->post_wait);
1549   update_FRdouble_latency (cpu, out_FRdoublek, ps->post_wait);
1550   update_FRdouble_latency (cpu, dual_FRdoublek, ps->post_wait);
1551
1552   /* Once initiated, post-processing will take 3 cycles.  */
1553   update_FR_ptime (cpu, out_FRk, 3);
1554   update_FR_ptime (cpu, dual_FRk, 3);
1555   update_FRdouble_ptime (cpu, out_FRdoublek, 3);
1556   update_FRdouble_ptime (cpu, dual_FRdoublek, 3);
1557
1558   /* Mark this use of the register as a floating point op.  */
1559   if (out_FRk >= 0)
1560     set_use_is_fpop (cpu, out_FRk);
1561   if (dual_FRk >= 0)
1562     set_use_is_fpop (cpu, dual_FRk);
1563   if (out_FRdoublek >= 0)
1564     {
1565       set_use_is_fpop (cpu, out_FRdoublek);
1566       if (out_FRdoublek < 63)
1567         set_use_is_fpop (cpu, out_FRdoublek + 1);
1568     }
1569   if (dual_FRdoublek >= 0)
1570     {
1571       set_use_is_fpop (cpu, dual_FRdoublek);
1572       if (dual_FRdoublek < 63)
1573         set_use_is_fpop (cpu, dual_FRdoublek + 1);
1574     }
1575
1576   return cycles;
1577 }
1578
1579 int
1580 frvbf_model_fr500_u_float_div (SIM_CPU *cpu, const IDESC *idesc,
1581                                int unit_num, int referenced,
1582                                INT in_FRi, INT in_FRj, INT out_FRk)
1583 {
1584   int cycles;
1585   FRV_VLIW *vliw;
1586   int slot;
1587   FRV_PROFILE_STATE *ps;
1588
1589   if (model_insn == FRV_INSN_MODEL_PASS_1)
1590     return 0;
1591
1592   cycles = idesc->timing->units[unit_num].done;
1593
1594   /* The post processing must wait if there is a dependency on a FR
1595      which is not ready yet.  */
1596   adjust_float_register_busy (cpu, in_FRi, in_FRj, out_FRk, 1);
1597   ps = CPU_PROFILE_STATE (cpu);
1598   ps->post_wait = cycles;
1599   post_wait_for_FR (cpu, in_FRi);
1600   post_wait_for_FR (cpu, in_FRj);
1601   post_wait_for_FR (cpu, out_FRk);
1602   vliw = CPU_VLIW (cpu);
1603   slot = vliw->next_slot - 1;
1604   slot = (*vliw->current_vliw)[slot] - UNIT_FM0;
1605   post_wait_for_fdiv (cpu, slot);
1606   restore_float_register_busy (cpu, in_FRi, in_FRj, out_FRk, 1);
1607
1608   /* The latency of FRk will be at least the latency of the other inputs.  */
1609   /* Once initiated, post-processing will take 10 cycles.  */
1610   update_FR_latency (cpu, out_FRk, ps->post_wait);
1611   update_FR_ptime (cpu, out_FRk, 10);
1612
1613   /* The latency of the fdiv unit will be at least the latency of the other
1614      inputs.  Once initiated, post-processing will take 9 cycles.  */
1615   update_fdiv_resource_latency (cpu, slot, ps->post_wait + 9);
1616
1617   /* Mark this use of the register as a floating point op.  */
1618   set_use_is_fpop (cpu, out_FRk);
1619
1620   return cycles;
1621 }
1622
1623 int
1624 frvbf_model_fr500_u_float_sqrt (SIM_CPU *cpu, const IDESC *idesc,
1625                                 int unit_num, int referenced,
1626                                 INT in_FRj, INT in_FRdoublej,
1627                                 INT out_FRk, INT out_FRdoublek)
1628 {
1629   int cycles;
1630   FRV_VLIW *vliw;
1631   int slot;
1632   FRV_PROFILE_STATE *ps;
1633
1634   if (model_insn == FRV_INSN_MODEL_PASS_1)
1635     return 0;
1636
1637   cycles = idesc->timing->units[unit_num].done;
1638
1639   /* The post processing must wait if there is a dependency on a FR
1640      which is not ready yet.  */
1641   adjust_float_register_busy (cpu, -1, in_FRj, out_FRk, 1);
1642   adjust_double_register_busy (cpu, -1, in_FRdoublej, out_FRdoublek, 1);
1643   ps = CPU_PROFILE_STATE (cpu);
1644   ps->post_wait = cycles;
1645   post_wait_for_FR (cpu, in_FRj);
1646   post_wait_for_FR (cpu, out_FRk);
1647   post_wait_for_FRdouble (cpu, in_FRdoublej);
1648   post_wait_for_FRdouble (cpu, out_FRdoublek);
1649   vliw = CPU_VLIW (cpu);
1650   slot = vliw->next_slot - 1;
1651   slot = (*vliw->current_vliw)[slot] - UNIT_FM0;
1652   post_wait_for_fsqrt (cpu, slot);
1653   restore_float_register_busy (cpu, -1, in_FRj, out_FRk, 1);
1654   restore_double_register_busy (cpu, -1, in_FRdoublej, out_FRdoublek, 1);
1655
1656   /* The latency of FRk will be at least the latency of the other inputs.  */
1657   update_FR_latency (cpu, out_FRk, ps->post_wait);
1658   update_FRdouble_latency (cpu, out_FRdoublek, ps->post_wait);
1659
1660   /* Once initiated, post-processing will take 15 cycles.  */
1661   update_FR_ptime (cpu, out_FRk, 15);
1662   update_FRdouble_ptime (cpu, out_FRdoublek, 15);
1663
1664   /* The latency of the sqrt unit will be the latency of the other
1665      inputs plus 14 cycles.  */
1666   update_fsqrt_resource_latency (cpu, slot, ps->post_wait + 14);
1667
1668   /* Mark this use of the register as a floating point op.  */
1669   if (out_FRk >= 0)
1670     set_use_is_fpop (cpu, out_FRk);
1671   if (out_FRdoublek >= 0)
1672     {
1673       set_use_is_fpop (cpu, out_FRdoublek);
1674       if (out_FRdoublek < 63)
1675         set_use_is_fpop (cpu, out_FRdoublek + 1);
1676     }
1677
1678   return cycles;
1679 }
1680
1681 int
1682 frvbf_model_fr500_u_float_dual_sqrt (SIM_CPU *cpu, const IDESC *idesc,
1683                                      int unit_num, int referenced,
1684                                      INT in_FRj, INT out_FRk)
1685 {
1686   int cycles;
1687   FRV_VLIW *vliw;
1688   int slot;
1689   INT dual_FRj;
1690   INT dual_FRk;
1691   FRV_PROFILE_STATE *ps;
1692
1693   if (model_insn == FRV_INSN_MODEL_PASS_1)
1694     return 0;
1695
1696   cycles = idesc->timing->units[unit_num].done;
1697
1698   /* The post processing must wait if there is a dependency on a FR
1699      which is not ready yet.  */
1700   dual_FRj = DUAL_REG (in_FRj);
1701   dual_FRk = DUAL_REG (out_FRk);
1702   adjust_float_register_busy (cpu, -1, in_FRj, out_FRk, 1);
1703   adjust_float_register_busy (cpu, -1, dual_FRj, dual_FRk, 1);
1704   ps = CPU_PROFILE_STATE (cpu);
1705   ps->post_wait = cycles;
1706   post_wait_for_FR (cpu, in_FRj);
1707   post_wait_for_FR (cpu, out_FRk);
1708   post_wait_for_FR (cpu, dual_FRj);
1709   post_wait_for_FR (cpu, dual_FRk);
1710
1711   vliw = CPU_VLIW (cpu);
1712   slot = vliw->next_slot - 1;
1713   slot = (*vliw->current_vliw)[slot] - UNIT_FM0;
1714   post_wait_for_fsqrt (cpu, slot);
1715   restore_float_register_busy (cpu, -1, in_FRj, out_FRk, 1);
1716   restore_float_register_busy (cpu, -1, dual_FRj, dual_FRk, 1);
1717
1718   /* The latency of FRk will be at least the latency of the other inputs.  */
1719   update_FR_latency (cpu, out_FRk, ps->post_wait);
1720   update_FR_latency (cpu, dual_FRk, ps->post_wait);
1721
1722   /* Once initiated, post-processing will take 15 cycles.  */
1723   update_FR_ptime (cpu, out_FRk, 15);
1724   update_FR_ptime (cpu, dual_FRk, 15);
1725
1726   /* The latency of the sqrt unit will be at least the latency of the other
1727      inputs.  */
1728   update_fsqrt_resource_latency (cpu, slot, ps->post_wait + 14);
1729
1730   /* Mark this use of the register as a floating point op.  */
1731   if (out_FRk >= 0)
1732     set_use_is_fpop (cpu, out_FRk);
1733   if (dual_FRk >= 0)
1734     set_use_is_fpop (cpu, dual_FRk);
1735
1736   return cycles;
1737 }
1738
1739 int
1740 frvbf_model_fr500_u_float_compare (SIM_CPU *cpu, const IDESC *idesc,
1741                                    int unit_num, int referenced,
1742                                    INT in_FRi, INT in_FRj,
1743                                    INT in_FRdoublei, INT in_FRdoublej,
1744                                    INT out_FCCi_2)
1745 {
1746   int cycles;
1747   FRV_PROFILE_STATE *ps;
1748
1749   if (model_insn == FRV_INSN_MODEL_PASS_1)
1750     return 0;
1751
1752   /* The preprocessing can execute right away.  */
1753   cycles = idesc->timing->units[unit_num].done;
1754
1755   /* The post processing must wait if there is a dependency on a FR
1756      which is not ready yet.  */
1757   adjust_double_register_busy (cpu, in_FRdoublei, in_FRdoublej, -1, 1);
1758   ps = CPU_PROFILE_STATE (cpu);
1759   ps->post_wait = cycles;
1760   post_wait_for_FR (cpu, in_FRi);
1761   post_wait_for_FR (cpu, in_FRj);
1762   post_wait_for_FRdouble (cpu, in_FRdoublei);
1763   post_wait_for_FRdouble (cpu, in_FRdoublej);
1764   post_wait_for_CCR (cpu, out_FCCi_2);
1765   restore_double_register_busy (cpu, in_FRdoublei, in_FRdoublej, -1, 1);
1766
1767   /* The latency of FCCi_2 will be the latency of the other inputs plus 3
1768      cycles.  */
1769   update_CCR_latency (cpu, out_FCCi_2, ps->post_wait + 3);
1770
1771   return cycles;
1772 }
1773
1774 int
1775 frvbf_model_fr500_u_float_dual_compare (SIM_CPU *cpu, const IDESC *idesc,
1776                                         int unit_num, int referenced,
1777                                         INT in_FRi, INT in_FRj,
1778                                         INT out_FCCi_2)
1779 {
1780   int cycles;
1781   INT dual_FRi;
1782   INT dual_FRj;
1783   INT dual_FCCi_2;
1784   FRV_PROFILE_STATE *ps;
1785
1786   if (model_insn == FRV_INSN_MODEL_PASS_1)
1787     return 0;
1788
1789   /* The preprocessing can execute right away.  */
1790   cycles = idesc->timing->units[unit_num].done;
1791
1792   /* The post processing must wait if there is a dependency on a FR
1793      which is not ready yet.  */
1794   ps = CPU_PROFILE_STATE (cpu);
1795   ps->post_wait = cycles;
1796   dual_FRi = DUAL_REG (in_FRi);
1797   dual_FRj = DUAL_REG (in_FRj);
1798   dual_FCCi_2 = out_FCCi_2 + 1;
1799   adjust_float_register_busy (cpu, in_FRi, in_FRj, -1, 1);
1800   adjust_float_register_busy (cpu, dual_FRi, dual_FRj, -1, 1);
1801   post_wait_for_FR (cpu, in_FRi);
1802   post_wait_for_FR (cpu, in_FRj);
1803   post_wait_for_FR (cpu, dual_FRi);
1804   post_wait_for_FR (cpu, dual_FRj);
1805   post_wait_for_CCR (cpu, out_FCCi_2);
1806   post_wait_for_CCR (cpu, dual_FCCi_2);
1807   restore_float_register_busy (cpu, in_FRi, in_FRj, -1, 1);
1808   restore_float_register_busy (cpu, dual_FRi, dual_FRj, -1, 1);
1809
1810   /* The latency of FCCi_2 will be the latency of the other inputs plus 3
1811      cycles.  */
1812   update_CCR_latency (cpu, out_FCCi_2, ps->post_wait + 3);
1813   update_CCR_latency (cpu, dual_FCCi_2, ps->post_wait + 3);
1814
1815   return cycles;
1816 }
1817
1818 int
1819 frvbf_model_fr500_u_float_convert (SIM_CPU *cpu, const IDESC *idesc,
1820                                    int unit_num, int referenced,
1821                                    INT in_FRj, INT in_FRintj, INT in_FRdoublej,
1822                                    INT out_FRk, INT out_FRintk,
1823                                    INT out_FRdoublek)
1824 {
1825   int cycles;
1826   FRV_PROFILE_STATE *ps;
1827
1828   if (model_insn == FRV_INSN_MODEL_PASS_1)
1829     return 0;
1830
1831   /* The preprocessing can execute right away.  */
1832   cycles = idesc->timing->units[unit_num].done;
1833
1834   /* The post processing must wait if there is a dependency on a FR
1835      which is not ready yet.  */
1836   ps = CPU_PROFILE_STATE (cpu);
1837   ps->post_wait = cycles;
1838   adjust_float_register_busy (cpu, -1, in_FRj, out_FRk, 1);
1839   adjust_float_register_busy (cpu, -1, in_FRintj, out_FRintk, 1);
1840   adjust_double_register_busy (cpu, -1, in_FRdoublej, out_FRdoublek, 1);
1841   post_wait_for_FR (cpu, in_FRj);
1842   post_wait_for_FR (cpu, in_FRintj);
1843   post_wait_for_FRdouble (cpu, in_FRdoublej);
1844   post_wait_for_FR (cpu, out_FRk);
1845   post_wait_for_FR (cpu, out_FRintk);
1846   post_wait_for_FRdouble (cpu, out_FRdoublek);
1847   restore_float_register_busy (cpu, -1, in_FRj, out_FRk, 1);
1848   restore_float_register_busy (cpu, -1, in_FRintj, out_FRintk, 1);
1849   restore_double_register_busy (cpu, -1, in_FRdoublej, out_FRdoublek, 1);
1850
1851   /* The latency of FRk will be at least the latency of the other inputs.  */
1852   update_FR_latency (cpu, out_FRk, ps->post_wait);
1853   update_FR_latency (cpu, out_FRintk, ps->post_wait);
1854   update_FRdouble_latency (cpu, out_FRdoublek, ps->post_wait);
1855
1856   /* Once initiated, post-processing will take 3 cycles.  */
1857   update_FR_ptime (cpu, out_FRk, 3);
1858   update_FR_ptime (cpu, out_FRintk, 3);
1859   update_FRdouble_ptime (cpu, out_FRdoublek, 3);
1860
1861   /* Mark this use of the register as a floating point op.  */
1862   if (out_FRk >= 0)
1863     set_use_is_fpop (cpu, out_FRk);
1864   if (out_FRintk >= 0)
1865     set_use_is_fpop (cpu, out_FRintk);
1866   if (out_FRdoublek >= 0)
1867     {
1868       set_use_is_fpop (cpu, out_FRdoublek);
1869       set_use_is_fpop (cpu, out_FRdoublek + 1);
1870     }
1871
1872   return cycles;
1873 }
1874
1875 int
1876 frvbf_model_fr500_u_float_dual_convert (SIM_CPU *cpu, const IDESC *idesc,
1877                                         int unit_num, int referenced,
1878                                         INT in_FRj, INT in_FRintj,
1879                                         INT out_FRk, INT out_FRintk)
1880 {
1881   int cycles;
1882   INT dual_FRj;
1883   INT dual_FRintj;
1884   INT dual_FRk;
1885   INT dual_FRintk;
1886   FRV_PROFILE_STATE *ps;
1887
1888   if (model_insn == FRV_INSN_MODEL_PASS_1)
1889     return 0;
1890
1891   /* The preprocessing can execute right away.  */
1892   cycles = idesc->timing->units[unit_num].done;
1893
1894   /* The post processing must wait if there is a dependency on a FR
1895      which is not ready yet.  */
1896   ps = CPU_PROFILE_STATE (cpu);
1897   ps->post_wait = cycles;
1898   dual_FRj = DUAL_REG (in_FRj);
1899   dual_FRintj = DUAL_REG (in_FRintj);
1900   dual_FRk = DUAL_REG (out_FRk);
1901   dual_FRintk = DUAL_REG (out_FRintk);
1902   adjust_float_register_busy (cpu, -1, in_FRj, out_FRk, 1);
1903   adjust_float_register_busy (cpu, -1, dual_FRj, dual_FRk, 1);
1904   adjust_float_register_busy (cpu, -1, in_FRintj, out_FRintk, 1);
1905   adjust_float_register_busy (cpu, -1, dual_FRintj, dual_FRintk, 1);
1906   post_wait_for_FR (cpu, in_FRj);
1907   post_wait_for_FR (cpu, in_FRintj);
1908   post_wait_for_FR (cpu, out_FRk);
1909   post_wait_for_FR (cpu, out_FRintk);
1910   post_wait_for_FR (cpu, dual_FRj);
1911   post_wait_for_FR (cpu, dual_FRintj);
1912   post_wait_for_FR (cpu, dual_FRk);
1913   post_wait_for_FR (cpu, dual_FRintk);
1914   restore_float_register_busy (cpu, -1, in_FRj, out_FRk, 1);
1915   restore_float_register_busy (cpu, -1, dual_FRj, dual_FRk, 1);
1916   restore_float_register_busy (cpu, -1, in_FRintj, out_FRintk, 1);
1917   restore_float_register_busy (cpu, -1, dual_FRintj, dual_FRintk, 1);
1918
1919   /* The latency of FRk will be at least the latency of the other inputs.  */
1920   update_FR_latency (cpu, out_FRk, ps->post_wait);
1921   update_FR_latency (cpu, out_FRintk, ps->post_wait);
1922   update_FR_latency (cpu, dual_FRk, ps->post_wait);
1923   update_FR_latency (cpu, dual_FRintk, ps->post_wait);
1924
1925   /* Once initiated, post-processing will take 3 cycles.  */
1926   update_FR_ptime (cpu, out_FRk, 3);
1927   update_FR_ptime (cpu, out_FRintk, 3);
1928   update_FR_ptime (cpu, dual_FRk, 3);
1929   update_FR_ptime (cpu, dual_FRintk, 3);
1930
1931   /* Mark this use of the register as a floating point op.  */
1932   if (out_FRk >= 0)
1933     set_use_is_fpop (cpu, out_FRk);
1934   if (out_FRintk >= 0)
1935     set_use_is_fpop (cpu, out_FRintk);
1936
1937   return cycles;
1938 }
1939
1940 int
1941 frvbf_model_fr500_u_media (SIM_CPU *cpu, const IDESC *idesc,
1942                            int unit_num, int referenced,
1943                            INT in_FRi, INT in_FRj, INT in_ACC40Si, INT in_ACCGi,
1944                            INT out_FRk,
1945                            INT out_ACC40Sk, INT out_ACC40Uk, INT out_ACCGk)
1946 {
1947   int cycles;
1948   FRV_PROFILE_STATE *ps;
1949   const CGEN_INSN *insn;
1950   int is_media_s1;
1951   int is_media_s2;
1952   int busy_adjustment[] = {0, 0, 0};
1953   int *fr;
1954   int *acc;
1955
1956   if (model_insn == FRV_INSN_MODEL_PASS_1)
1957     return 0;
1958
1959   /* The preprocessing can execute right away.  */
1960   cycles = idesc->timing->units[unit_num].done;
1961
1962   ps = CPU_PROFILE_STATE (cpu);
1963   insn = idesc->idata;
1964
1965   /* If the previous use of the registers was a media op,
1966      then their latency will be less than previously recorded.
1967      See Table 13-13 in the LSI.  */
1968   if (in_FRi >= 0)
1969     {
1970       if (use_is_media (cpu, in_FRi))
1971         {
1972           busy_adjustment[0] = 2;
1973           decrease_FR_busy (cpu, in_FRi, busy_adjustment[0]);
1974         }
1975       else
1976         enforce_full_fr_latency (cpu, in_FRi);
1977     }
1978   if (in_FRj >= 0 && in_FRj != in_FRi)
1979     {
1980       if (use_is_media (cpu, in_FRj))
1981         {
1982           busy_adjustment[1] = 2;
1983           decrease_FR_busy (cpu, in_FRj, busy_adjustment[1]);
1984         }
1985       else
1986         enforce_full_fr_latency (cpu, in_FRj);
1987     }
1988   if (out_FRk >= 0 && out_FRk != in_FRi && out_FRk != in_FRj)
1989     {
1990       if (use_is_media (cpu, out_FRk))
1991         {
1992           busy_adjustment[2] = 2;
1993           decrease_FR_busy (cpu, out_FRk, busy_adjustment[2]);
1994         }
1995       else
1996         enforce_full_fr_latency (cpu, out_FRk);
1997     }
1998
1999   /* The post processing must wait if there is a dependency on a FR
2000      which is not ready yet.  */
2001   ps->post_wait = cycles;
2002   post_wait_for_FR (cpu, in_FRi);
2003   post_wait_for_FR (cpu, in_FRj);
2004   post_wait_for_FR (cpu, out_FRk);
2005   post_wait_for_ACC (cpu, in_ACC40Si);
2006   post_wait_for_ACC (cpu, in_ACCGi);
2007   post_wait_for_ACC (cpu, out_ACC40Sk);
2008   post_wait_for_ACC (cpu, out_ACC40Uk);
2009   post_wait_for_ACC (cpu, out_ACCGk);
2010
2011   /* Restore the busy cycles of the registers we used.  */
2012   fr = ps->fr_busy;
2013   if (in_FRi >= 0)
2014     fr[in_FRi] += busy_adjustment[0];
2015   if (in_FRj >= 0)
2016     fr[in_FRj] += busy_adjustment[1];
2017   if (out_FRk >= 0)
2018     fr[out_FRk] += busy_adjustment[2];
2019
2020   /* The latency of tht output register will be at least the latency of the
2021      other inputs.  Once initiated, post-processing will take 3 cycles.  */
2022   if (out_FRk >= 0)
2023     {
2024       update_FR_latency (cpu, out_FRk, ps->post_wait);
2025       update_FR_ptime (cpu, out_FRk, 3);
2026       /* Mark this use of the register as a media op.  */
2027       set_use_is_media (cpu, out_FRk);
2028     }
2029   /* The latency of tht output accumulator will be at least the latency of the
2030      other inputs.  Once initiated, post-processing will take 1 cycle.  */
2031   if (out_ACC40Sk >= 0)
2032     update_ACC_latency (cpu, out_ACC40Sk, ps->post_wait + 1);
2033   if (out_ACC40Uk >= 0)
2034     update_ACC_latency (cpu, out_ACC40Uk, ps->post_wait + 1);
2035   if (out_ACCGk >= 0)
2036     update_ACC_latency (cpu, out_ACCGk, ps->post_wait + 1);
2037
2038   return cycles;
2039 }
2040
2041 int
2042 frvbf_model_fr500_u_media_quad_arith (SIM_CPU *cpu, const IDESC *idesc,
2043                                        int unit_num, int referenced,
2044                                        INT in_FRi, INT in_FRj,
2045                                        INT out_FRk)
2046 {
2047   int cycles;
2048   INT dual_FRi;
2049   INT dual_FRj;
2050   INT dual_FRk;
2051   FRV_PROFILE_STATE *ps;
2052   int busy_adjustment[] = {0, 0, 0, 0, 0, 0};
2053   int *fr;
2054
2055   if (model_insn == FRV_INSN_MODEL_PASS_1)
2056     return 0;
2057
2058   /* The preprocessing can execute right away.  */
2059   cycles = idesc->timing->units[unit_num].done;
2060
2061   ps = CPU_PROFILE_STATE (cpu);
2062   dual_FRi = DUAL_REG (in_FRi);
2063   dual_FRj = DUAL_REG (in_FRj);
2064   dual_FRk = DUAL_REG (out_FRk);
2065
2066   /* If the previous use of the registers was a media op,
2067      then their latency will be less than previously recorded.
2068      See Table 13-13 in the LSI.  */
2069   if (use_is_media (cpu, in_FRi))
2070     {
2071       busy_adjustment[0] = 2;
2072       decrease_FR_busy (cpu, in_FRi, busy_adjustment[0]);
2073     }
2074   else
2075     enforce_full_fr_latency (cpu, in_FRi);
2076   if (dual_FRi >= 0 && use_is_media (cpu, dual_FRi))
2077     {
2078       busy_adjustment[1] = 2;
2079       decrease_FR_busy (cpu, dual_FRi, busy_adjustment[1]);
2080     }
2081   else
2082     enforce_full_fr_latency (cpu, dual_FRi);
2083   if (in_FRj != in_FRi)
2084     {
2085       if (use_is_media (cpu, in_FRj))
2086         {
2087           busy_adjustment[2] = 2;
2088           decrease_FR_busy (cpu, in_FRj, busy_adjustment[2]);
2089         }
2090       else
2091         enforce_full_fr_latency (cpu, in_FRj);
2092       if (dual_FRj >= 0 && use_is_media (cpu, dual_FRj))
2093         {
2094           busy_adjustment[3] = 2;
2095           decrease_FR_busy (cpu, dual_FRj, busy_adjustment[3]);
2096         }
2097       else
2098         enforce_full_fr_latency (cpu, dual_FRj + 1);
2099     }
2100   if (out_FRk != in_FRi && out_FRk != in_FRj)
2101     {
2102       if (use_is_media (cpu, out_FRk))
2103         {
2104           busy_adjustment[4] = 2;
2105           decrease_FR_busy (cpu, out_FRk, busy_adjustment[4]);
2106         }
2107       else
2108         enforce_full_fr_latency (cpu, out_FRk);
2109       if (dual_FRk >= 0 && use_is_media (cpu, dual_FRk))
2110         {
2111           busy_adjustment[5] = 2;
2112           decrease_FR_busy (cpu, dual_FRk, busy_adjustment[5]);
2113         }
2114       else
2115         enforce_full_fr_latency (cpu, dual_FRk);
2116     }
2117
2118   /* The post processing must wait if there is a dependency on a FR
2119      which is not ready yet.  */
2120   ps->post_wait = cycles;
2121   post_wait_for_FR (cpu, in_FRi);
2122   post_wait_for_FR (cpu, dual_FRi);
2123   post_wait_for_FR (cpu, in_FRj);
2124   post_wait_for_FR (cpu, dual_FRj);
2125   post_wait_for_FR (cpu, out_FRk);
2126   post_wait_for_FR (cpu, dual_FRk);
2127
2128   /* Restore the busy cycles of the registers we used.  */
2129   fr = ps->fr_busy;
2130   fr[in_FRi] += busy_adjustment[0];
2131   if (dual_FRi >= 0)
2132     fr[dual_FRi] += busy_adjustment[1];
2133   fr[in_FRj] += busy_adjustment[2];
2134   if (dual_FRj >= 0)
2135     fr[dual_FRj] += busy_adjustment[3];
2136   fr[out_FRk] += busy_adjustment[4];
2137   if (dual_FRk >= 0)
2138     fr[dual_FRk] += busy_adjustment[5];
2139
2140   /* The latency of tht output register will be at least the latency of the
2141      other inputs.  */
2142   update_FR_latency (cpu, out_FRk, ps->post_wait);
2143
2144   /* Once initiated, post-processing will take 3 cycles.  */
2145   update_FR_ptime (cpu, out_FRk, 3);
2146
2147   /* Mark this use of the register as a media op.  */
2148   set_use_is_media (cpu, out_FRk);
2149   if (dual_FRk >= 0)
2150     {
2151       update_FR_latency (cpu, dual_FRk, ps->post_wait);
2152       update_FR_ptime (cpu, dual_FRk, 3);
2153       /* Mark this use of the register as a media op.  */
2154       set_use_is_media (cpu, dual_FRk);
2155     }
2156
2157   return cycles;
2158 }
2159
2160 int
2161 frvbf_model_fr500_u_media_dual_mul (SIM_CPU *cpu, const IDESC *idesc,
2162                                     int unit_num, int referenced,
2163                                     INT in_FRi, INT in_FRj,
2164                                     INT out_ACC40Sk, INT out_ACC40Uk)
2165 {
2166   int cycles;
2167   INT dual_ACC40Sk;
2168   INT dual_ACC40Uk;
2169   FRV_PROFILE_STATE *ps;
2170   int busy_adjustment[] = {0, 0, 0, 0, 0, 0};
2171   int *fr;
2172   int *acc;
2173
2174   if (model_insn == FRV_INSN_MODEL_PASS_1)
2175     return 0;
2176
2177   /* The preprocessing can execute right away.  */
2178   cycles = idesc->timing->units[unit_num].done;
2179
2180   ps = CPU_PROFILE_STATE (cpu);
2181   dual_ACC40Sk = DUAL_REG (out_ACC40Sk);
2182   dual_ACC40Uk = DUAL_REG (out_ACC40Uk);
2183
2184   /* If the previous use of the registers was a media op,
2185      then their latency will be less than previously recorded.
2186      See Table 13-13 in the LSI.  */
2187   if (use_is_media (cpu, in_FRi))
2188     {
2189       busy_adjustment[0] = 2;
2190       decrease_FR_busy (cpu, in_FRi, busy_adjustment[0]);
2191     }
2192   else
2193     enforce_full_fr_latency (cpu, in_FRi);
2194   if (in_FRj != in_FRi)
2195     {
2196       if (use_is_media (cpu, in_FRj))
2197         {
2198           busy_adjustment[1] = 2;
2199           decrease_FR_busy (cpu, in_FRj, busy_adjustment[1]);
2200         }
2201       else
2202         enforce_full_fr_latency (cpu, in_FRj);
2203     }
2204   if (out_ACC40Sk >= 0)
2205     {
2206       busy_adjustment[2] = 1;
2207       decrease_ACC_busy (cpu, out_ACC40Sk, busy_adjustment[2]);
2208     }
2209   if (dual_ACC40Sk >= 0)
2210     {
2211       busy_adjustment[3] = 1;
2212       decrease_ACC_busy (cpu, dual_ACC40Sk, busy_adjustment[3]);
2213     }
2214   if (out_ACC40Uk >= 0)
2215     {
2216       busy_adjustment[4] = 1;
2217       decrease_ACC_busy (cpu, out_ACC40Uk, busy_adjustment[4]);
2218     }
2219   if (dual_ACC40Uk >= 0)
2220     {
2221       busy_adjustment[5] = 1;
2222       decrease_ACC_busy (cpu, dual_ACC40Uk, busy_adjustment[5]);
2223     }
2224
2225   /* The post processing must wait if there is a dependency on a FR
2226      which is not ready yet.  */
2227   ps->post_wait = cycles;
2228   post_wait_for_FR (cpu, in_FRi);
2229   post_wait_for_FR (cpu, in_FRj);
2230   post_wait_for_ACC (cpu, out_ACC40Sk);
2231   post_wait_for_ACC (cpu, dual_ACC40Sk);
2232   post_wait_for_ACC (cpu, out_ACC40Uk);
2233   post_wait_for_ACC (cpu, dual_ACC40Uk);
2234
2235   /* Restore the busy cycles of the registers we used.  */
2236   fr = ps->fr_busy;
2237   acc = ps->acc_busy;
2238   fr[in_FRi] += busy_adjustment[0];
2239   fr[in_FRj] += busy_adjustment[1];
2240   if (out_ACC40Sk >= 0)
2241     acc[out_ACC40Sk] += busy_adjustment[2];
2242   if (dual_ACC40Sk >= 0)
2243     acc[dual_ACC40Sk] += busy_adjustment[3];
2244   if (out_ACC40Uk >= 0)
2245     acc[out_ACC40Uk] += busy_adjustment[4];
2246   if (dual_ACC40Uk >= 0)
2247     acc[dual_ACC40Uk] += busy_adjustment[5];
2248
2249   /* The latency of tht output register will be at least the latency of the
2250      other inputs.  Once initiated, post-processing will take 1 cycle.  */
2251   if (out_ACC40Sk >= 0)
2252     update_ACC_latency (cpu, out_ACC40Sk, ps->post_wait + 1);
2253   if (dual_ACC40Sk >= 0)
2254     update_ACC_latency (cpu, dual_ACC40Sk, ps->post_wait + 1);
2255   if (out_ACC40Uk >= 0)
2256     update_ACC_latency (cpu, out_ACC40Uk, ps->post_wait + 1);
2257   if (dual_ACC40Uk >= 0)
2258     update_ACC_latency (cpu, dual_ACC40Uk, ps->post_wait + 1);
2259
2260   return cycles;
2261 }
2262
2263 int
2264 frvbf_model_fr500_u_media_quad_mul (SIM_CPU *cpu, const IDESC *idesc,
2265                                     int unit_num, int referenced,
2266                                     INT in_FRi, INT in_FRj,
2267                                     INT out_ACC40Sk, INT out_ACC40Uk)
2268 {
2269   int cycles;
2270   INT FRi_1;
2271   INT FRj_1;
2272   INT ACC40Sk_1;
2273   INT ACC40Sk_2;
2274   INT ACC40Sk_3;
2275   INT ACC40Uk_1;
2276   INT ACC40Uk_2;
2277   INT ACC40Uk_3;
2278   FRV_PROFILE_STATE *ps;
2279   int busy_adjustment[] = {0, 0, 0, 0, 0, 0, 0 ,0};
2280   int *fr;
2281   int *acc;
2282
2283   if (model_insn == FRV_INSN_MODEL_PASS_1)
2284     return 0;
2285
2286   /* The preprocessing can execute right away.  */
2287   cycles = idesc->timing->units[unit_num].done;
2288
2289   FRi_1 = DUAL_REG (in_FRi);
2290   FRj_1 = DUAL_REG (in_FRj);
2291   ACC40Sk_1 = DUAL_REG (out_ACC40Sk);
2292   ACC40Sk_2 = DUAL_REG (ACC40Sk_1);
2293   ACC40Sk_3 = DUAL_REG (ACC40Sk_2);
2294   ACC40Uk_1 = DUAL_REG (out_ACC40Uk);
2295   ACC40Uk_2 = DUAL_REG (ACC40Uk_1);
2296   ACC40Uk_3 = DUAL_REG (ACC40Uk_2);
2297
2298   /* If the previous use of the registers was a media op,
2299      then their latency will be less than previously recorded.
2300      See Table 13-13 in the LSI.  */
2301   ps = CPU_PROFILE_STATE (cpu);
2302   if (use_is_media (cpu, in_FRi))
2303     {
2304       busy_adjustment[0] = 2;
2305       decrease_FR_busy (cpu, in_FRi, busy_adjustment[0]);
2306     }
2307   else
2308     enforce_full_fr_latency (cpu, in_FRi);
2309   if (FRi_1 >= 0)
2310     {
2311       if (use_is_media (cpu, FRi_1))
2312         {
2313           busy_adjustment[1] = 2;
2314           decrease_FR_busy (cpu, FRi_1, busy_adjustment[1]);
2315         }
2316       else
2317         enforce_full_fr_latency (cpu, FRi_1);
2318     }
2319   if (in_FRj != in_FRi)
2320     {
2321       if (use_is_media (cpu, in_FRj))
2322         {
2323           busy_adjustment[2] = 2;
2324           decrease_FR_busy (cpu, in_FRj, busy_adjustment[2]);
2325         }
2326       else
2327         enforce_full_fr_latency (cpu, in_FRj);
2328       if (FRj_1 >= 0)
2329         {
2330           if (use_is_media (cpu, FRj_1))
2331             {
2332               busy_adjustment[3] = 2;
2333               decrease_FR_busy (cpu, FRj_1, busy_adjustment[3]);
2334             }
2335           else
2336             enforce_full_fr_latency (cpu, FRj_1);
2337         }
2338     }
2339   if (out_ACC40Sk >= 0)
2340     {
2341       busy_adjustment[4] = 1;
2342       decrease_ACC_busy (cpu, out_ACC40Sk, busy_adjustment[4]);
2343
2344       if (ACC40Sk_1 >= 0)
2345         {
2346           busy_adjustment[5] = 1;
2347           decrease_ACC_busy (cpu, ACC40Sk_1, busy_adjustment[5]);
2348         }
2349       if (ACC40Sk_2 >= 0)
2350         {
2351           busy_adjustment[6] = 1;
2352           decrease_ACC_busy (cpu, ACC40Sk_2, busy_adjustment[6]);
2353         }
2354       if (ACC40Sk_3 >= 0)
2355         {
2356           busy_adjustment[7] = 1;
2357           decrease_ACC_busy (cpu, ACC40Sk_3, busy_adjustment[7]);
2358         }
2359     }
2360   else if (out_ACC40Uk >= 0)
2361     {
2362       busy_adjustment[4] = 1;
2363       decrease_ACC_busy (cpu, out_ACC40Uk, busy_adjustment[4]);
2364
2365       if (ACC40Uk_1 >= 0)
2366         {
2367           busy_adjustment[5] = 1;
2368           decrease_ACC_busy (cpu, ACC40Uk_1, busy_adjustment[5]);
2369         }
2370       if (ACC40Uk_2 >= 0)
2371         {
2372           busy_adjustment[6] = 1;
2373           decrease_ACC_busy (cpu, ACC40Uk_2, busy_adjustment[6]);
2374         }
2375       if (ACC40Uk_3 >= 0)
2376         {
2377           busy_adjustment[7] = 1;
2378           decrease_ACC_busy (cpu, ACC40Uk_3, busy_adjustment[7]);
2379         }
2380     }
2381
2382   /* The post processing must wait if there is a dependency on a FR
2383      which is not ready yet.  */
2384   ps->post_wait = cycles;
2385   post_wait_for_FR (cpu, in_FRi);
2386   post_wait_for_FR (cpu, FRi_1);
2387   post_wait_for_FR (cpu, in_FRj);
2388   post_wait_for_FR (cpu, FRj_1);
2389   post_wait_for_ACC (cpu, out_ACC40Sk);
2390   post_wait_for_ACC (cpu, ACC40Sk_1);
2391   post_wait_for_ACC (cpu, ACC40Sk_2);
2392   post_wait_for_ACC (cpu, ACC40Sk_3);
2393   post_wait_for_ACC (cpu, out_ACC40Uk);
2394   post_wait_for_ACC (cpu, ACC40Uk_1);
2395   post_wait_for_ACC (cpu, ACC40Uk_2);
2396   post_wait_for_ACC (cpu, ACC40Uk_3);
2397
2398   /* Restore the busy cycles of the registers we used.  */
2399   fr = ps->fr_busy;
2400   acc = ps->acc_busy;
2401   fr[in_FRi] += busy_adjustment[0];
2402   if (FRi_1 >= 0)
2403     fr[FRi_1] += busy_adjustment[1];
2404   fr[in_FRj] += busy_adjustment[2];
2405   if (FRj_1 > 0)
2406     fr[FRj_1] += busy_adjustment[3];
2407   if (out_ACC40Sk >= 0)
2408     {
2409       acc[out_ACC40Sk] += busy_adjustment[4];
2410       if (ACC40Sk_1 >= 0)
2411         acc[ACC40Sk_1] += busy_adjustment[5];
2412       if (ACC40Sk_2 >= 0)
2413         acc[ACC40Sk_2] += busy_adjustment[6];
2414       if (ACC40Sk_3 >= 0)
2415         acc[ACC40Sk_3] += busy_adjustment[7];
2416     }
2417   else if (out_ACC40Uk >= 0)
2418     {
2419       acc[out_ACC40Uk] += busy_adjustment[4];
2420       if (ACC40Uk_1 >= 0)
2421         acc[ACC40Uk_1] += busy_adjustment[5];
2422       if (ACC40Uk_2 >= 0)
2423         acc[ACC40Uk_2] += busy_adjustment[6];
2424       if (ACC40Uk_3 >= 0)
2425         acc[ACC40Uk_3] += busy_adjustment[7];
2426     }
2427
2428   /* The latency of tht output register will be at least the latency of the
2429      other inputs.  Once initiated, post-processing will take 1 cycle.  */
2430   if (out_ACC40Sk >= 0)
2431     {
2432       update_ACC_latency (cpu, out_ACC40Sk, ps->post_wait + 1);
2433       if (ACC40Sk_1 >= 0)
2434         update_ACC_latency (cpu, ACC40Sk_1, ps->post_wait + 1);
2435       if (ACC40Sk_2 >= 0)
2436         update_ACC_latency (cpu, ACC40Sk_2, ps->post_wait + 1);
2437       if (ACC40Sk_3 >= 0)
2438         update_ACC_latency (cpu, ACC40Sk_3, ps->post_wait + 1);
2439     }
2440   else if (out_ACC40Uk >= 0)
2441     {
2442       update_ACC_latency (cpu, out_ACC40Uk, ps->post_wait + 1);
2443       if (ACC40Uk_1 >= 0)
2444         update_ACC_latency (cpu, ACC40Uk_1, ps->post_wait + 1);
2445       if (ACC40Uk_2 >= 0)
2446         update_ACC_latency (cpu, ACC40Uk_2, ps->post_wait + 1);
2447       if (ACC40Uk_3 >= 0)
2448         update_ACC_latency (cpu, ACC40Uk_3, ps->post_wait + 1);
2449     }
2450
2451   return cycles;
2452 }
2453
2454 int
2455 frvbf_model_fr500_u_media_quad_complex (SIM_CPU *cpu, const IDESC *idesc,
2456                                         int unit_num, int referenced,
2457                                         INT in_FRi, INT in_FRj,
2458                                         INT out_ACC40Sk)
2459 {
2460   int cycles;
2461   INT FRi_1;
2462   INT FRj_1;
2463   INT ACC40Sk_1;
2464   FRV_PROFILE_STATE *ps;
2465   int busy_adjustment[] = {0, 0, 0, 0, 0, 0};
2466   int *fr;
2467   int *acc;
2468
2469   if (model_insn == FRV_INSN_MODEL_PASS_1)
2470     return 0;
2471
2472   /* The preprocessing can execute right away.  */
2473   cycles = idesc->timing->units[unit_num].done;
2474
2475   FRi_1 = DUAL_REG (in_FRi);
2476   FRj_1 = DUAL_REG (in_FRj);
2477   ACC40Sk_1 = DUAL_REG (out_ACC40Sk);
2478
2479   /* If the previous use of the registers was a media op,
2480      then their latency will be less than previously recorded.
2481      See Table 13-13 in the LSI.  */
2482   ps = CPU_PROFILE_STATE (cpu);
2483   if (use_is_media (cpu, in_FRi))
2484     {
2485       busy_adjustment[0] = 2;
2486       decrease_FR_busy (cpu, in_FRi, busy_adjustment[0]);
2487     }
2488   else
2489     enforce_full_fr_latency (cpu, in_FRi);
2490   if (FRi_1 >= 0)
2491     {
2492       if (use_is_media (cpu, FRi_1))
2493         {
2494           busy_adjustment[1] = 2;
2495           decrease_FR_busy (cpu, FRi_1, busy_adjustment[1]);
2496         }
2497       else
2498         enforce_full_fr_latency (cpu, FRi_1);
2499     }
2500   if (in_FRj != in_FRi)
2501     {
2502       if (use_is_media (cpu, in_FRj))
2503         {
2504           busy_adjustment[2] = 2;
2505           decrease_FR_busy (cpu, in_FRj, busy_adjustment[2]);
2506         }
2507       else
2508         enforce_full_fr_latency (cpu, in_FRj);
2509       if (FRj_1 >= 0)
2510         {
2511           if (use_is_media (cpu, FRj_1))
2512             {
2513               busy_adjustment[3] = 2;
2514               decrease_FR_busy (cpu, FRj_1, busy_adjustment[3]);
2515             }
2516           else
2517             enforce_full_fr_latency (cpu, FRj_1);
2518         }
2519     }
2520   if (out_ACC40Sk >= 0)
2521     {
2522       busy_adjustment[4] = 1;
2523       decrease_ACC_busy (cpu, out_ACC40Sk, busy_adjustment[4]);
2524
2525       if (ACC40Sk_1 >= 0)
2526         {
2527           busy_adjustment[5] = 1;
2528           decrease_ACC_busy (cpu, ACC40Sk_1, busy_adjustment[5]);
2529         }
2530     }
2531
2532   /* The post processing must wait if there is a dependency on a FR
2533      which is not ready yet.  */
2534   ps->post_wait = cycles;
2535   post_wait_for_FR (cpu, in_FRi);
2536   post_wait_for_FR (cpu, FRi_1);
2537   post_wait_for_FR (cpu, in_FRj);
2538   post_wait_for_FR (cpu, FRj_1);
2539   post_wait_for_ACC (cpu, out_ACC40Sk);
2540   post_wait_for_ACC (cpu, ACC40Sk_1);
2541
2542   /* Restore the busy cycles of the registers we used.  */
2543   fr = ps->fr_busy;
2544   acc = ps->acc_busy;
2545   fr[in_FRi] += busy_adjustment[0];
2546   if (FRi_1 >= 0)
2547     fr[FRi_1] += busy_adjustment[1];
2548   fr[in_FRj] += busy_adjustment[2];
2549   if (FRj_1 > 0)
2550     fr[FRj_1] += busy_adjustment[3];
2551   if (out_ACC40Sk >= 0)
2552     {
2553       acc[out_ACC40Sk] += busy_adjustment[4];
2554       if (ACC40Sk_1 >= 0)
2555         acc[ACC40Sk_1] += busy_adjustment[5];
2556     }
2557
2558   /* The latency of tht output register will be at least the latency of the
2559      other inputs.  Once initiated, post-processing will take 1 cycle.  */
2560   if (out_ACC40Sk >= 0)
2561     {
2562       update_ACC_latency (cpu, out_ACC40Sk, ps->post_wait + 1);
2563       if (ACC40Sk_1 >= 0)
2564         update_ACC_latency (cpu, ACC40Sk_1, ps->post_wait + 1);
2565     }
2566
2567   return cycles;
2568 }
2569
2570 int
2571 frvbf_model_fr500_u_media_dual_expand (SIM_CPU *cpu, const IDESC *idesc,
2572                                        int unit_num, int referenced,
2573                                        INT in_FRi,
2574                                        INT out_FRk)
2575 {
2576   int cycles;
2577   INT dual_FRk;
2578   FRV_PROFILE_STATE *ps;
2579   int busy_adjustment[] = {0, 0, 0};
2580   int *fr;
2581
2582   if (model_insn == FRV_INSN_MODEL_PASS_1)
2583     return 0;
2584
2585   /* The preprocessing can execute right away.  */
2586   cycles = idesc->timing->units[unit_num].done;
2587
2588   /* If the previous use of the registers was a media op,
2589      then their latency will be less than previously recorded.
2590      See Table 13-13 in the LSI.  */
2591   dual_FRk = DUAL_REG (out_FRk);
2592   ps = CPU_PROFILE_STATE (cpu);
2593   if (use_is_media (cpu, in_FRi))
2594     {
2595       busy_adjustment[0] = 2;
2596       decrease_FR_busy (cpu, in_FRi, busy_adjustment[0]);
2597     }
2598   else
2599     enforce_full_fr_latency (cpu, in_FRi);
2600   if (out_FRk != in_FRi)
2601     {
2602       if (use_is_media (cpu, out_FRk))
2603         {
2604           busy_adjustment[1] = 2;
2605           decrease_FR_busy (cpu, out_FRk, busy_adjustment[1]);
2606         }
2607       else
2608         enforce_full_fr_latency (cpu, out_FRk);
2609     }
2610   if (dual_FRk >= 0 && dual_FRk != in_FRi)
2611     {
2612       if (use_is_media (cpu, dual_FRk))
2613         {
2614           busy_adjustment[2] = 2;
2615           decrease_FR_busy (cpu, dual_FRk, busy_adjustment[2]);
2616         }
2617       else
2618         enforce_full_fr_latency (cpu, dual_FRk);
2619     }
2620
2621   /* The post processing must wait if there is a dependency on a FR
2622      which is not ready yet.  */
2623   ps->post_wait = cycles;
2624   post_wait_for_FR (cpu, in_FRi);
2625   post_wait_for_FR (cpu, out_FRk);
2626   post_wait_for_FR (cpu, dual_FRk);
2627
2628   /* Restore the busy cycles of the registers we used.  */
2629   fr = ps->fr_busy;
2630   fr[in_FRi] += busy_adjustment[0];
2631   fr[out_FRk] += busy_adjustment[1];
2632   if (dual_FRk >= 0)
2633     fr[dual_FRk] += busy_adjustment[2];
2634
2635   /* The latency of tht output register will be at least the latency of the
2636      other inputs.  Once initiated, post-processing will take 3 cycles.  */
2637   update_FR_latency (cpu, out_FRk, ps->post_wait);
2638   update_FR_ptime (cpu, out_FRk, 3);
2639
2640   /* Mark this use of the register as a media op.  */
2641   set_use_is_media (cpu, out_FRk);
2642   if (dual_FRk >= 0)
2643     {
2644       update_FR_latency (cpu, dual_FRk, ps->post_wait);
2645       update_FR_ptime (cpu, dual_FRk, 3);
2646
2647       /* Mark this use of the register as a media op.  */
2648       set_use_is_media (cpu, dual_FRk);
2649     }
2650
2651   return cycles;
2652 }
2653
2654 int
2655 frvbf_model_fr500_u_media_dual_unpack (SIM_CPU *cpu, const IDESC *idesc,
2656                                        int unit_num, int referenced,
2657                                        INT in_FRi,
2658                                        INT out_FRk)
2659 {
2660   int cycles;
2661   INT FRi_1;
2662   INT FRk_1;
2663   INT FRk_2;
2664   INT FRk_3;
2665   FRV_PROFILE_STATE *ps;
2666   int busy_adjustment[] = {0, 0, 0, 0, 0, 0};
2667   int *fr;
2668
2669   if (model_insn == FRV_INSN_MODEL_PASS_1)
2670     return 0;
2671
2672   /* The preprocessing can execute right away.  */
2673   cycles = idesc->timing->units[unit_num].done;
2674
2675   FRi_1 = DUAL_REG (in_FRi);
2676   FRk_1 = DUAL_REG (out_FRk);
2677   FRk_2 = DUAL_REG (FRk_1);
2678   FRk_3 = DUAL_REG (FRk_2);
2679
2680   /* If the previous use of the registers was a media op,
2681      then their latency will be less than previously recorded.
2682      See Table 13-13 in the LSI.  */
2683   ps = CPU_PROFILE_STATE (cpu);
2684   if (use_is_media (cpu, in_FRi))
2685     {
2686       busy_adjustment[0] = 2;
2687       decrease_FR_busy (cpu, in_FRi, busy_adjustment[0]);
2688     }
2689   else
2690     enforce_full_fr_latency (cpu, in_FRi);
2691   if (FRi_1 >= 0 && use_is_media (cpu, FRi_1))
2692     {
2693       busy_adjustment[1] = 2;
2694       decrease_FR_busy (cpu, FRi_1, busy_adjustment[1]);
2695     }
2696   else
2697     enforce_full_fr_latency (cpu, FRi_1);
2698   if (out_FRk != in_FRi)
2699     {
2700       if (use_is_media (cpu, out_FRk))
2701         {
2702           busy_adjustment[2] = 2;
2703           decrease_FR_busy (cpu, out_FRk, busy_adjustment[2]);
2704         }
2705       else
2706         enforce_full_fr_latency (cpu, out_FRk);
2707       if (FRk_1 >= 0 && FRk_1 != in_FRi)
2708         {
2709           if (use_is_media (cpu, FRk_1))
2710             {
2711               busy_adjustment[3] = 2;
2712               decrease_FR_busy (cpu, FRk_1, busy_adjustment[3]);
2713             }
2714           else
2715             enforce_full_fr_latency (cpu, FRk_1);
2716         }
2717       if (FRk_2 >= 0 && FRk_2 != in_FRi)
2718         {
2719           if (use_is_media (cpu, FRk_2))
2720             {
2721               busy_adjustment[4] = 2;
2722               decrease_FR_busy (cpu, FRk_2, busy_adjustment[4]);
2723             }
2724           else
2725             enforce_full_fr_latency (cpu, FRk_2);
2726         }
2727       if (FRk_3 >= 0 && FRk_3 != in_FRi)
2728         {
2729           if (use_is_media (cpu, FRk_3))
2730             {
2731               busy_adjustment[5] = 2;
2732               decrease_FR_busy (cpu, FRk_3, busy_adjustment[5]);
2733             }
2734           else
2735             enforce_full_fr_latency (cpu, FRk_3);
2736         }
2737     }
2738
2739   /* The post processing must wait if there is a dependency on a FR
2740      which is not ready yet.  */
2741   ps->post_wait = cycles;
2742   post_wait_for_FR (cpu, in_FRi);
2743   post_wait_for_FR (cpu, FRi_1);
2744   post_wait_for_FR (cpu, out_FRk);
2745   post_wait_for_FR (cpu, FRk_1);
2746   post_wait_for_FR (cpu, FRk_2);
2747   post_wait_for_FR (cpu, FRk_3);
2748
2749   /* Restore the busy cycles of the registers we used.  */
2750   fr = ps->fr_busy;
2751   fr[in_FRi] += busy_adjustment[0];
2752   if (FRi_1 >= 0)
2753     fr[FRi_1] += busy_adjustment[1];
2754   fr[out_FRk] += busy_adjustment[2];
2755   if (FRk_1 >= 0)
2756     fr[FRk_1] += busy_adjustment[3];
2757   if (FRk_2 >= 0)
2758     fr[FRk_2] += busy_adjustment[4];
2759   if (FRk_3 >= 0)
2760     fr[FRk_3] += busy_adjustment[5];
2761
2762   /* The latency of tht output register will be at least the latency of the
2763      other inputs.  Once initiated, post-processing will take 3 cycles.  */
2764   update_FR_latency (cpu, out_FRk, ps->post_wait);
2765   update_FR_ptime (cpu, out_FRk, 3);
2766
2767   /* Mark this use of the register as a media op.  */
2768   set_use_is_media (cpu, out_FRk);
2769   if (FRk_1 >= 0)
2770     {
2771       update_FR_latency (cpu, FRk_1, ps->post_wait);
2772       update_FR_ptime (cpu, FRk_1, 3);
2773
2774       /* Mark this use of the register as a media op.  */
2775       set_use_is_media (cpu, FRk_1);
2776     }
2777   if (FRk_2 >= 0)
2778     {
2779       update_FR_latency (cpu, FRk_2, ps->post_wait);
2780       update_FR_ptime (cpu, FRk_2, 3);
2781
2782       /* Mark this use of the register as a media op.  */
2783       set_use_is_media (cpu, FRk_2);
2784     }
2785   if (FRk_3 >= 0)
2786     {
2787       update_FR_latency (cpu, FRk_3, ps->post_wait);
2788       update_FR_ptime (cpu, FRk_3, 3);
2789
2790       /* Mark this use of the register as a media op.  */
2791       set_use_is_media (cpu, FRk_3);
2792     }
2793
2794   return cycles;
2795 }
2796
2797 int
2798 frvbf_model_fr500_u_media_dual_btoh (SIM_CPU *cpu, const IDESC *idesc,
2799                                      int unit_num, int referenced,
2800                                      INT in_FRj,
2801                                      INT out_FRk)
2802 {
2803   return frvbf_model_fr500_u_media_dual_expand (cpu, idesc, unit_num,
2804                                                 referenced, in_FRj, out_FRk);
2805 }
2806
2807 int
2808 frvbf_model_fr500_u_media_dual_htob (SIM_CPU *cpu, const IDESC *idesc,
2809                                      int unit_num, int referenced,
2810                                      INT in_FRj,
2811                                      INT out_FRk)
2812 {
2813   int cycles;
2814   INT dual_FRj;
2815   FRV_PROFILE_STATE *ps;
2816   int busy_adjustment[] = {0, 0, 0};
2817   int *fr;
2818
2819   if (model_insn == FRV_INSN_MODEL_PASS_1)
2820     return 0;
2821
2822   /* The preprocessing can execute right away.  */
2823   cycles = idesc->timing->units[unit_num].done;
2824
2825   /* If the previous use of the registers was a media op,
2826      then their latency will be less than previously recorded.
2827      See Table 13-13 in the LSI.  */
2828   dual_FRj = DUAL_REG (in_FRj);
2829   ps = CPU_PROFILE_STATE (cpu);
2830   if (use_is_media (cpu, in_FRj))
2831     {
2832       busy_adjustment[0] = 2;
2833       decrease_FR_busy (cpu, in_FRj, busy_adjustment[0]);
2834     }
2835   else
2836     enforce_full_fr_latency (cpu, in_FRj);
2837   if (dual_FRj >= 0)
2838     {
2839       if (use_is_media (cpu, dual_FRj))
2840         {
2841           busy_adjustment[1] = 2;
2842           decrease_FR_busy (cpu, dual_FRj, busy_adjustment[1]);
2843         }
2844       else
2845         enforce_full_fr_latency (cpu, dual_FRj);
2846     }
2847   if (out_FRk != in_FRj)
2848     {
2849       if (use_is_media (cpu, out_FRk))
2850         {
2851           busy_adjustment[2] = 2;
2852           decrease_FR_busy (cpu, out_FRk, busy_adjustment[2]);
2853         }
2854       else
2855         enforce_full_fr_latency (cpu, out_FRk);
2856     }
2857
2858   /* The post processing must wait if there is a dependency on a FR
2859      which is not ready yet.  */
2860   ps->post_wait = cycles;
2861   post_wait_for_FR (cpu, in_FRj);
2862   post_wait_for_FR (cpu, dual_FRj);
2863   post_wait_for_FR (cpu, out_FRk);
2864
2865   /* Restore the busy cycles of the registers we used.  */
2866   fr = ps->fr_busy;
2867   fr[in_FRj] += busy_adjustment[0];
2868   if (dual_FRj >= 0)
2869     fr[dual_FRj] += busy_adjustment[1];
2870   fr[out_FRk] += busy_adjustment[2];
2871
2872   /* The latency of tht output register will be at least the latency of the
2873      other inputs.  */
2874   update_FR_latency (cpu, out_FRk, ps->post_wait);
2875
2876   /* Once initiated, post-processing will take 3 cycles.  */
2877   update_FR_ptime (cpu, out_FRk, 3);
2878
2879   /* Mark this use of the register as a media op.  */
2880   set_use_is_media (cpu, out_FRk);
2881
2882   return cycles;
2883 }
2884
2885 int
2886 frvbf_model_fr500_u_media_dual_btohe (SIM_CPU *cpu, const IDESC *idesc,
2887                                       int unit_num, int referenced,
2888                                       INT in_FRj,
2889                                       INT out_FRk)
2890 {
2891   int cycles;
2892   INT FRk_1;
2893   INT FRk_2;
2894   INT FRk_3;
2895   FRV_PROFILE_STATE *ps;
2896   int busy_adjustment[] = {0, 0, 0, 0, 0};
2897   int *fr;
2898
2899   if (model_insn == FRV_INSN_MODEL_PASS_1)
2900     return 0;
2901
2902   /* The preprocessing can execute right away.  */
2903   cycles = idesc->timing->units[unit_num].done;
2904
2905   FRk_1 = DUAL_REG (out_FRk);
2906   FRk_2 = DUAL_REG (FRk_1);
2907   FRk_3 = DUAL_REG (FRk_2);
2908
2909   /* If the previous use of the registers was a media op,
2910      then their latency will be less than previously recorded.
2911      See Table 13-13 in the LSI.  */
2912   ps = CPU_PROFILE_STATE (cpu);
2913   if (use_is_media (cpu, in_FRj))
2914     {
2915       busy_adjustment[0] = 2;
2916       decrease_FR_busy (cpu, in_FRj, busy_adjustment[0]);
2917     }
2918   else
2919     enforce_full_fr_latency (cpu, in_FRj);
2920   if (out_FRk != in_FRj)
2921     {
2922       if (use_is_media (cpu, out_FRk))
2923         {
2924           busy_adjustment[1] = 2;
2925           decrease_FR_busy (cpu, out_FRk, busy_adjustment[1]);
2926         }
2927       else
2928         enforce_full_fr_latency (cpu, out_FRk);
2929       if (FRk_1 >= 0 && FRk_1 != in_FRj)
2930         {
2931           if (use_is_media (cpu, FRk_1))
2932             {
2933               busy_adjustment[2] = 2;
2934               decrease_FR_busy (cpu, FRk_1, busy_adjustment[2]);
2935             }
2936           else
2937             enforce_full_fr_latency (cpu, FRk_1);
2938         }
2939       if (FRk_2 >= 0 && FRk_2 != in_FRj)
2940         {
2941           if (use_is_media (cpu, FRk_2))
2942             {
2943               busy_adjustment[3] = 2;
2944               decrease_FR_busy (cpu, FRk_2, busy_adjustment[3]);
2945             }
2946           else
2947             enforce_full_fr_latency (cpu, FRk_2);
2948         }
2949       if (FRk_3 >= 0 && FRk_3 != in_FRj)
2950         {
2951           if (use_is_media (cpu, FRk_3))
2952             {
2953               busy_adjustment[4] = 2;
2954               decrease_FR_busy (cpu, FRk_3, busy_adjustment[4]);
2955             }
2956           else
2957             enforce_full_fr_latency (cpu, FRk_3);
2958         }
2959     }
2960
2961   /* The post processing must wait if there is a dependency on a FR
2962      which is not ready yet.  */
2963   ps->post_wait = cycles;
2964   post_wait_for_FR (cpu, in_FRj);
2965   post_wait_for_FR (cpu, out_FRk);
2966   post_wait_for_FR (cpu, FRk_1);
2967   post_wait_for_FR (cpu, FRk_2);
2968   post_wait_for_FR (cpu, FRk_3);
2969
2970   /* Restore the busy cycles of the registers we used.  */
2971   fr = ps->fr_busy;
2972   fr[in_FRj] += busy_adjustment[0];
2973   fr[out_FRk] += busy_adjustment[1];
2974   if (FRk_1 >= 0)
2975     fr[FRk_1] += busy_adjustment[2];
2976   if (FRk_2 >= 0)
2977     fr[FRk_2] += busy_adjustment[3];
2978   if (FRk_3 >= 0)
2979     fr[FRk_3] += busy_adjustment[4];
2980
2981   /* The latency of tht output register will be at least the latency of the
2982      other inputs.  Once initiated, post-processing will take 3 cycles.  */
2983   update_FR_latency (cpu, out_FRk, ps->post_wait);
2984   update_FR_ptime (cpu, out_FRk, 3);
2985
2986   /* Mark this use of the register as a media op.  */
2987   set_use_is_media (cpu, out_FRk);
2988   if (FRk_1 >= 0)
2989     {
2990       update_FR_latency (cpu, FRk_1, ps->post_wait);
2991       update_FR_ptime (cpu, FRk_1, 3);
2992
2993       /* Mark this use of the register as a media op.  */
2994       set_use_is_media (cpu, FRk_1);
2995     }
2996   if (FRk_2 >= 0)
2997     {
2998       update_FR_latency (cpu, FRk_2, ps->post_wait);
2999       update_FR_ptime (cpu, FRk_2, 3);
3000
3001       /* Mark this use of the register as a media op.  */
3002       set_use_is_media (cpu, FRk_2);
3003     }
3004   if (FRk_3 >= 0)
3005     {
3006       update_FR_latency (cpu, FRk_3, ps->post_wait);
3007       update_FR_ptime (cpu, FRk_3, 3);
3008
3009       /* Mark this use of the register as a media op.  */
3010       set_use_is_media (cpu, FRk_3);
3011     }
3012
3013   return cycles;
3014 }
3015
3016 int
3017 frvbf_model_fr500_u_barrier (SIM_CPU *cpu, const IDESC *idesc,
3018                              int unit_num, int referenced)
3019 {
3020   int cycles;
3021   if (model_insn == FRV_INSN_MODEL_PASS_1)
3022     {
3023       int i;
3024       /* Wait for ALL resources.  */
3025       for (i = 0; i < 64; ++i)
3026         {
3027           enforce_full_fr_latency (cpu, i);
3028           vliw_wait_for_GR (cpu, i);
3029           vliw_wait_for_FR (cpu, i);
3030           vliw_wait_for_ACC (cpu, i);
3031         }
3032       for (i = 0; i < 8; ++i)
3033         vliw_wait_for_CCR (cpu, i);
3034       for (i = 0; i < 2; ++i)
3035         {
3036           vliw_wait_for_idiv_resource (cpu, i);
3037           vliw_wait_for_fdiv_resource (cpu, i);
3038           vliw_wait_for_fsqrt_resource (cpu, i);
3039         }
3040       handle_resource_wait (cpu);
3041       for (i = 0; i < 64; ++i)
3042         {
3043           load_wait_for_GR (cpu, i);
3044           load_wait_for_FR (cpu, i);
3045         }
3046       trace_vliw_wait_cycles (cpu);
3047       return 0;
3048     }
3049
3050   cycles = idesc->timing->units[unit_num].done;
3051   return cycles;
3052 }
3053
3054 int
3055 frvbf_model_fr500_u_membar (SIM_CPU *cpu, const IDESC *idesc,
3056                             int unit_num, int referenced)
3057 {
3058   int cycles;
3059   if (model_insn == FRV_INSN_MODEL_PASS_1)
3060     {
3061       int i;
3062       /* Wait for ALL resources, except GR and ICC.  */
3063       for (i = 0; i < 64; ++i)
3064         {
3065           enforce_full_fr_latency (cpu, i);
3066           vliw_wait_for_FR (cpu, i);
3067           vliw_wait_for_ACC (cpu, i);
3068         }
3069       for (i = 0; i < 4; ++i)
3070         vliw_wait_for_CCR (cpu, i);
3071       for (i = 0; i < 2; ++i)
3072         {
3073           vliw_wait_for_idiv_resource (cpu, i);
3074           vliw_wait_for_fdiv_resource (cpu, i);
3075           vliw_wait_for_fsqrt_resource (cpu, i);
3076         }
3077       handle_resource_wait (cpu);
3078       for (i = 0; i < 64; ++i)
3079         {
3080           load_wait_for_FR (cpu, i);
3081         }
3082       trace_vliw_wait_cycles (cpu);
3083       return 0;
3084     }
3085
3086   cycles = idesc->timing->units[unit_num].done;
3087   return cycles;
3088 }
3089
3090 /* The frv machine is a fictional implementation of the fr500 which implements
3091    all frv architectural features.  */
3092 int
3093 frvbf_model_frv_u_exec (SIM_CPU *cpu, const IDESC *idesc,
3094                             int unit_num, int referenced)
3095 {
3096   return idesc->timing->units[unit_num].done;
3097 }
3098
3099 /* The simple machine is a fictional implementation of the fr500 which
3100    implements limited frv architectural features.  */
3101 int
3102 frvbf_model_simple_u_exec (SIM_CPU *cpu, const IDESC *idesc,
3103                             int unit_num, int referenced)
3104 {
3105   return idesc->timing->units[unit_num].done;
3106 }
3107
3108 /* The tomcat machine is models a prototype fr500 machine which had a few
3109    bugs and restrictions to work around.  */
3110 int
3111 frvbf_model_tomcat_u_exec (SIM_CPU *cpu, const IDESC *idesc,
3112                             int unit_num, int referenced)
3113 {
3114   return idesc->timing->units[unit_num].done;
3115 }
3116
3117 #endif /* WITH_PROFILE_MODEL_P */