compiler.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. int sh2_drc_init(SH2 *sh2);
  2. void sh2_drc_finish(SH2 *sh2);
  3. void sh2_drc_wcheck_ram(uint32_t a, unsigned len, SH2 *sh2);
  4. void sh2_drc_wcheck_da(uint32_t a, unsigned len, SH2 *sh2);
  5. #ifdef DRC_SH2
  6. void sh2_drc_mem_setup(SH2 *sh2);
  7. void sh2_drc_flush_all(void);
  8. #else
  9. #define sh2_drc_mem_setup(x)
  10. #define sh2_drc_flush_all()
  11. #define sh2_drc_frame()
  12. #endif
  13. #define BLOCK_INSN_LIMIT 1024
  14. /* op_flags */
  15. #define OF_DELAY_OP (1 << 0)
  16. #define OF_BTARGET (1 << 1)
  17. #define OF_LOOP (3 << 2) // NONE, IDLE, DELAY, POLL loop
  18. #define OF_B_IN_DS (1 << 4)
  19. #define OF_DELAY_INSN (1 << 5) // DT, (TODO ADD+CMP?)
  20. #define OF_POLL_INSN (1 << 6) // MOV @(...),Rn (no post increment), TST @(...)
  21. #define OF_BASIC_LOOP (1 << 7) // pinnable loop without any branches in it
  22. #define OF_IDLE_LOOP (1 << 2)
  23. #define OF_DELAY_LOOP (2 << 2)
  24. #define OF_POLL_LOOP (3 << 2)
  25. unsigned short scan_block(uint32_t base_pc, int is_slave,
  26. unsigned char *op_flags, uint32_t *end_pc,
  27. uint32_t *base_literals, uint32_t *end_literals);
  28. #if defined(DRC_SH2) && defined(__GNUC__) && !defined(__clang__)
  29. // direct access to some host CPU registers used by the DRC if gcc is used.
  30. // XXX MUST match SHR_SR definitions in cpu/drc/emit_*.c; should be moved there
  31. // XXX yuck, there's no portable way to determine register size. Use long long
  32. // if target is 64 bit and data model is ILP32 or LLP64(windows), else long
  33. #if defined(__arm__)
  34. #define DRC_SR_REG "r10"
  35. #define DRC_REG_LL 0 // 32 bit
  36. #elif defined(__aarch64__)
  37. #define DRC_SR_REG "r28"
  38. #define DRC_REG_LL (__ILP32__ || _WIN32)
  39. #elif defined(__mips__)
  40. #define DRC_SR_REG "s6"
  41. #define DRC_REG_LL (_MIPS_SIM == _ABIN32)
  42. #elif defined(__riscv__) || defined(__riscv)
  43. #define DRC_SR_REG "s11"
  44. #define DRC_REG_LL 0 // no ABI for (__ILP32__ && __riscv_xlen != 32)
  45. #elif defined(__powerpc__)
  46. #define DRC_SR_REG "r30"
  47. #define DRC_REG_LL 0 // no ABI for __ILP32__
  48. #elif defined(__i386__)
  49. #define DRC_SR_REG "edi"
  50. #define DRC_REG_LL 0 // 32 bit
  51. #elif defined(__x86_64__)
  52. #define DRC_SR_REG "rbx"
  53. #define DRC_REG_LL (__ILP32__ || _WIN32)
  54. #endif
  55. #endif
  56. #ifdef DRC_SR_REG
  57. // XXX this is more clear but produces too much overhead for slow platforms
  58. extern void REGPARM(1) (*sh2_drc_save_sr)(SH2 *sh2);
  59. extern void REGPARM(1) (*sh2_drc_restore_sr)(SH2 *sh2);
  60. // NB: sh2_sr MUST have register size if optimizing with -O3 (-fif-conversion)
  61. #if DRC_REG_LL
  62. #define DRC_DECLARE_SR register long long _sh2_sr asm(DRC_SR_REG)
  63. #else
  64. #define DRC_DECLARE_SR register long _sh2_sr asm(DRC_SR_REG)
  65. #endif
  66. #define DRC_SAVE_SR(sh2) \
  67. if (likely((sh2->state&(SH2_STATE_RUN|SH2_STATE_SLEEP)) == SH2_STATE_RUN)) \
  68. sh2->sr = (s32)_sh2_sr
  69. // sh2_drc_save_sr(sh2)
  70. #define DRC_RESTORE_SR(sh2) \
  71. if (likely((sh2->state&(SH2_STATE_RUN|SH2_STATE_SLEEP)) == SH2_STATE_RUN)) \
  72. _sh2_sr = (s32)sh2->sr
  73. // sh2_drc_restore_sr(sh2)
  74. #else
  75. #define DRC_DECLARE_SR
  76. #define DRC_SAVE_SR(sh2)
  77. #define DRC_RESTORE_SR(sh2)
  78. #endif