profile.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /* Profiling definitions for the FRV simulator
  2. Copyright (C) 1998-2015 Free Software Foundation, Inc.
  3. Contributed by Red Hat.
  4. This file is part of the GNU Simulators.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef PROFILE_H
  16. #define PROFILE_H
  17. #include "frv-desc.h"
  18. /* This struct defines the state of profiling. All fields are of general
  19. use to all machines. */
  20. typedef struct
  21. {
  22. long vliw_insns; /* total number of VLIW insns. */
  23. long vliw_wait; /* number of cycles that the current VLIW insn must wait. */
  24. long post_wait; /* number of cycles that post processing in the current
  25. VLIW insn must wait. */
  26. long vliw_cycles;/* number of cycles used by current VLIW insn. */
  27. int past_first_p; /* Not the first insns in the VLIW */
  28. /* Register latencies. Must be signed since they can be temporarily
  29. negative. */
  30. int gr_busy[64]; /* Cycles until GR is available. */
  31. int fr_busy[64]; /* Cycles until FR is available. */
  32. int acc_busy[64]; /* Cycles until FR is available. */
  33. int ccr_busy[8]; /* Cycles until ICC/FCC is available. */
  34. int spr_busy[4096]; /* Cycles until spr is available. */
  35. int idiv_busy[2]; /* Cycles until integer division unit is available. */
  36. int fdiv_busy[2]; /* Cycles until float division unit is available. */
  37. int fsqrt_busy[2]; /* Cycles until square root unit is available. */
  38. int float_busy[4]; /* Cycles until floating point unit is available. */
  39. int media_busy[4]; /* Cycles until media unit is available. */
  40. int branch_penalty; /* Cycles until branch is complete. */
  41. int gr_latency[64]; /* Cycles until target GR is available. */
  42. int fr_latency[64]; /* Cycles until target FR is available. */
  43. int acc_latency[64]; /* Cycles until target FR is available. */
  44. int ccr_latency[8]; /* Cycles until target ICC/FCC is available. */
  45. int spr_latency[4096]; /* Cycles until target spr is available. */
  46. /* Some registers are busy for a shorter number of cycles than normal
  47. depending on how they are used next. the xxx_busy_adjust arrays keep track
  48. of how many cycles to adjust down.
  49. */
  50. int fr_busy_adjust[64];
  51. int acc_busy_adjust[64];
  52. /* Register flags. Each bit represents one register. */
  53. DI cur_gr_complex;
  54. DI prev_gr_complex;
  55. /* Keep track of the total queued post-processing time required before a
  56. resource is available. This is applied to the resource's latency once all
  57. pending loads for the resource are completed. */
  58. int fr_ptime[64];
  59. int branch_hint; /* hint field from branch insn. */
  60. USI branch_address; /* Address of predicted branch. */
  61. USI insn_fetch_address;/* Address of sequential insns fetched. */
  62. int mclracc_acc; /* ACC number of register cleared by mclracc. */
  63. int mclracc_A; /* A field of mclracc. */
  64. /* We need to know when the first branch of a vliw insn is taken, so that
  65. we don't consider the remaining branches in the vliw insn. */
  66. int vliw_branch_taken;
  67. /* Keep track of the maximum load stall for each VLIW insn. */
  68. int vliw_load_stall;
  69. /* Need to know if all cache entries are affected by various cache
  70. operations. */
  71. int all_cache_entries;
  72. } FRV_PROFILE_STATE;
  73. #define DUAL_REG(reg) ((reg) >= 0 && (reg) < 63 ? (reg) + 1 : -1)
  74. #define DUAL_DOUBLE(reg) ((reg) >= 0 && (reg) < 61 ? (reg) + 2 : -1)
  75. /* Return the GNER register associated with the given GR register.
  76. There is no GNER associated with gr0. */
  77. #define GNER_FOR_GR(gr) ((gr) > 63 ? -1 : \
  78. (gr) > 31 ? H_SPR_GNER0 : \
  79. (gr) > 0 ? H_SPR_GNER1 : \
  80. -1)
  81. /* Return the GNER register associated with the given GR register.
  82. There is no GNER associated with gr0. */
  83. #define FNER_FOR_FR(fr) ((fr) > 63 ? -1 : \
  84. (fr) > 31 ? H_SPR_FNER0 : \
  85. (fr) > 0 ? H_SPR_FNER1 : \
  86. -1)
  87. /* Top up the latency of the given GR by the given number of cycles. */
  88. void update_GR_latency (SIM_CPU *, INT, int);
  89. void update_GRdouble_latency (SIM_CPU *, INT, int);
  90. void update_GR_latency_for_load (SIM_CPU *, INT, int);
  91. void update_GRdouble_latency_for_load (SIM_CPU *, INT, int);
  92. void update_GR_latency_for_swap (SIM_CPU *, INT, int);
  93. void update_FR_latency (SIM_CPU *, INT, int);
  94. void update_FRdouble_latency (SIM_CPU *, INT, int);
  95. void update_FR_latency_for_load (SIM_CPU *, INT, int);
  96. void update_FRdouble_latency_for_load (SIM_CPU *, INT, int);
  97. void update_FR_ptime (SIM_CPU *, INT, int);
  98. void update_FRdouble_ptime (SIM_CPU *, INT, int);
  99. void decrease_ACC_busy (SIM_CPU *, INT, int);
  100. void decrease_FR_busy (SIM_CPU *, INT, int);
  101. void decrease_GR_busy (SIM_CPU *, INT, int);
  102. void increase_FR_busy (SIM_CPU *, INT, int);
  103. void increase_ACC_busy (SIM_CPU *, INT, int);
  104. void update_ACC_latency (SIM_CPU *, INT, int);
  105. void update_CCR_latency (SIM_CPU *, INT, int);
  106. void update_SPR_latency (SIM_CPU *, INT, int);
  107. void update_idiv_resource_latency (SIM_CPU *, INT, int);
  108. void update_fdiv_resource_latency (SIM_CPU *, INT, int);
  109. void update_fsqrt_resource_latency (SIM_CPU *, INT, int);
  110. void update_float_resource_latency (SIM_CPU *, INT, int);
  111. void update_media_resource_latency (SIM_CPU *, INT, int);
  112. void update_branch_penalty (SIM_CPU *, int);
  113. void update_ACC_ptime (SIM_CPU *, INT, int);
  114. void update_SPR_ptime (SIM_CPU *, INT, int);
  115. void vliw_wait_for_GR (SIM_CPU *, INT);
  116. void vliw_wait_for_GRdouble (SIM_CPU *, INT);
  117. void vliw_wait_for_FR (SIM_CPU *, INT);
  118. void vliw_wait_for_FRdouble (SIM_CPU *, INT);
  119. void vliw_wait_for_CCR (SIM_CPU *, INT);
  120. void vliw_wait_for_ACC (SIM_CPU *, INT);
  121. void vliw_wait_for_SPR (SIM_CPU *, INT);
  122. void vliw_wait_for_idiv_resource (SIM_CPU *, INT);
  123. void vliw_wait_for_fdiv_resource (SIM_CPU *, INT);
  124. void vliw_wait_for_fsqrt_resource (SIM_CPU *, INT);
  125. void vliw_wait_for_float_resource (SIM_CPU *, INT);
  126. void vliw_wait_for_media_resource (SIM_CPU *, INT);
  127. void load_wait_for_GR (SIM_CPU *, INT);
  128. void load_wait_for_FR (SIM_CPU *, INT);
  129. void load_wait_for_GRdouble (SIM_CPU *, INT);
  130. void load_wait_for_FRdouble (SIM_CPU *, INT);
  131. void enforce_full_fr_latency (SIM_CPU *, INT);
  132. void enforce_full_acc_latency (SIM_CPU *, INT);
  133. int post_wait_for_FR (SIM_CPU *, INT);
  134. int post_wait_for_FRdouble (SIM_CPU *, INT);
  135. int post_wait_for_ACC (SIM_CPU *, INT);
  136. int post_wait_for_CCR (SIM_CPU *, INT);
  137. int post_wait_for_SPR (SIM_CPU *, INT);
  138. int post_wait_for_fdiv (SIM_CPU *, INT);
  139. int post_wait_for_fsqrt (SIM_CPU *, INT);
  140. int post_wait_for_float (SIM_CPU *, INT);
  141. int post_wait_for_media (SIM_CPU *, INT);
  142. void trace_vliw_wait_cycles (SIM_CPU *);
  143. void handle_resource_wait (SIM_CPU *);
  144. void request_cache_load (SIM_CPU *, INT, int, int);
  145. void request_cache_flush (SIM_CPU *, FRV_CACHE *, int);
  146. void request_cache_invalidate (SIM_CPU *, FRV_CACHE *, int);
  147. void request_cache_preload (SIM_CPU *, FRV_CACHE *, int);
  148. void request_cache_unlock (SIM_CPU *, FRV_CACHE *, int);
  149. int load_pending_for_register (SIM_CPU *, int, int, int);
  150. void set_use_is_gr_complex (SIM_CPU *, INT);
  151. void set_use_not_gr_complex (SIM_CPU *, INT);
  152. int use_is_gr_complex (SIM_CPU *, INT);
  153. typedef struct
  154. {
  155. SI address;
  156. unsigned reqno;
  157. } FRV_INSN_FETCH_BUFFER;
  158. extern FRV_INSN_FETCH_BUFFER frv_insn_fetch_buffer[];
  159. PROFILE_INFO_CPU_CALLBACK_FN frv_profile_info;
  160. enum {
  161. /* Simulator specific profile bits begin here. */
  162. /* Profile caches. */
  163. PROFILE_CACHE_IDX = PROFILE_NEXT_IDX,
  164. /* Profile parallelization. */
  165. PROFILE_PARALLEL_IDX
  166. };
  167. /* Masks so WITH_PROFILE can have symbolic values.
  168. The case choice here is on purpose. The lowercase parts are args to
  169. --with-profile. */
  170. #define PROFILE_cache (1 << PROFILE_INSN_IDX)
  171. #define PROFILE_parallel (1 << PROFILE_INSN_IDX)
  172. /* Preprocessor macros to simplify tests of WITH_PROFILE. */
  173. #define WITH_PROFILE_CACHE_P (WITH_PROFILE & PROFILE_insn)
  174. #define WITH_PROFILE_PARALLEL_P (WITH_PROFILE & PROFILE_insn)
  175. #define FRV_COUNT_CYCLES(cpu, condition) \
  176. ((PROFILE_MODEL_P (cpu) && (condition)) || frv_interrupt_state.timer.enabled)
  177. /* Modelling support. */
  178. extern int frv_save_profile_model_p;
  179. extern enum FRV_INSN_MODELING {
  180. FRV_INSN_NO_MODELING = 0,
  181. FRV_INSN_MODEL_PASS_1,
  182. FRV_INSN_MODEL_PASS_2,
  183. FRV_INSN_MODEL_WRITEBACK
  184. } model_insn;
  185. void
  186. frv_model_advance_cycles (SIM_CPU *, int);
  187. void
  188. frv_model_trace_wait_cycles (SIM_CPU *, int, const char *);
  189. /* Register types for queued load requests. */
  190. #define REGTYPE_NONE 0
  191. #define REGTYPE_FR 1
  192. #define REGTYPE_ACC 2
  193. #endif /* PROFILE_H */