zend_jit_x86.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend JIT |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | https://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Dmitry Stogov <dmitry@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifndef HAVE_JIT_X86_H
  19. #define HAVE_JIT_X86_H
  20. typedef enum _zend_reg {
  21. ZREG_NONE = -1,
  22. ZREG_R0,
  23. ZREG_R1,
  24. ZREG_R2,
  25. ZREG_R3,
  26. ZREG_R4,
  27. ZREG_R5,
  28. ZREG_R6,
  29. ZREG_R7,
  30. #if defined(__x86_64__) || defined(_WIN64)
  31. ZREG_R8,
  32. ZREG_R9,
  33. ZREG_R10,
  34. ZREG_R11,
  35. ZREG_R12,
  36. ZREG_R13,
  37. ZREG_R14,
  38. ZREG_R15,
  39. #endif
  40. ZREG_XMM0,
  41. ZREG_XMM1,
  42. ZREG_XMM2,
  43. ZREG_XMM3,
  44. ZREG_XMM4,
  45. ZREG_XMM5,
  46. ZREG_XMM6,
  47. ZREG_XMM7,
  48. #if defined(__x86_64__) || defined(_WIN64)
  49. ZREG_XMM8,
  50. ZREG_XMM9,
  51. ZREG_XMM10,
  52. ZREG_XMM11,
  53. ZREG_XMM12,
  54. ZREG_XMM13,
  55. ZREG_XMM14,
  56. ZREG_XMM15,
  57. #endif
  58. ZREG_NUM,
  59. ZREG_THIS, /* used for delayed FETCH_THIS deoptimization */
  60. /* pseudo constants used by deoptimizer */
  61. ZREG_LONG_MIN_MINUS_1,
  62. ZREG_LONG_MIN,
  63. ZREG_LONG_MAX,
  64. ZREG_LONG_MAX_PLUS_1,
  65. ZREG_NULL,
  66. ZREG_ZVAL_TRY_ADDREF,
  67. ZREG_ZVAL_COPY_GPR0,
  68. } zend_reg;
  69. typedef struct _zend_jit_registers_buf {
  70. #if defined(__x86_64__) || defined(_WIN64)
  71. uint64_t gpr[16]; /* general purpose integer register */
  72. double fpr[16]; /* floating point registers */
  73. #else
  74. uint32_t gpr[8]; /* general purpose integer register */
  75. double fpr[8]; /* floating point registers */
  76. #endif
  77. } zend_jit_registers_buf;
  78. #define ZREG_FIRST_FPR ZREG_XMM0
  79. #define ZREG_COPY ZREG_R0
  80. #define ZREG_RAX ZREG_R0
  81. #define ZREG_RCX ZREG_R1
  82. #define ZREG_RDX ZREG_R2
  83. #define ZREG_RBX ZREG_R3
  84. #define ZREG_RSP ZREG_R4
  85. #define ZREG_RBP ZREG_R5
  86. #define ZREG_RSI ZREG_R6
  87. #define ZREG_RDI ZREG_R7
  88. #ifdef _WIN64
  89. # define ZREG_FP ZREG_R14
  90. # define ZREG_IP ZREG_R15
  91. #elif defined(__x86_64__)
  92. # define ZREG_FP ZREG_R14
  93. # define ZREG_IP ZREG_R15
  94. #else
  95. # define ZREG_FP ZREG_RSI
  96. # define ZREG_IP ZREG_RDI
  97. #endif
  98. #define ZREG_RX ZREG_IP
  99. typedef uint32_t zend_regset;
  100. #define ZEND_REGSET_64BIT 0
  101. #ifdef _WIN64
  102. # define ZEND_REGSET_FIXED \
  103. (ZEND_REGSET(ZREG_RSP) | ZEND_REGSET(ZREG_R14) | ZEND_REGSET(ZREG_R15))
  104. # define ZEND_REGSET_GP \
  105. ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_R0, ZREG_R15), ZEND_REGSET_FIXED)
  106. # define ZEND_REGSET_FP \
  107. ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_XMM0, ZREG_XMM15), ZEND_REGSET_FIXED)
  108. # define ZEND_REGSET_SCRATCH \
  109. (ZEND_REGSET(ZREG_RAX) | ZEND_REGSET(ZREG_RDX) | ZEND_REGSET(ZREG_RCX) | ZEND_REGSET_INTERVAL(ZREG_R8, ZREG_R11) | ZEND_REGSET_FP)
  110. # define ZEND_REGSET_PRESERVED \
  111. (ZEND_REGSET(ZREG_RBX) | ZEND_REGSET(ZREG_RBP) | ZEND_REGSET(ZREG_R12) | ZEND_REGSET(ZREG_R13) | ZEND_REGSET(ZREG_RDI) | ZEND_REGSET(ZREG_RSI))
  112. #elif defined(__x86_64__)
  113. # define ZEND_REGSET_FIXED \
  114. (ZEND_REGSET(ZREG_RSP) | ZEND_REGSET(ZREG_R14) | ZEND_REGSET(ZREG_R15))
  115. # define ZEND_REGSET_GP \
  116. ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_R0, ZREG_R15), ZEND_REGSET_FIXED)
  117. # define ZEND_REGSET_FP \
  118. ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_XMM0, ZREG_XMM15), ZEND_REGSET_FIXED)
  119. # define ZEND_REGSET_SCRATCH \
  120. (ZEND_REGSET(ZREG_RAX) | ZEND_REGSET(ZREG_RDI) | ZEND_REGSET(ZREG_RSI) | ZEND_REGSET(ZREG_RDX) | ZEND_REGSET(ZREG_RCX) | ZEND_REGSET_INTERVAL(ZREG_R8, ZREG_R11) | ZEND_REGSET_FP)
  121. # define ZEND_REGSET_PRESERVED \
  122. (ZEND_REGSET(ZREG_RBX) | ZEND_REGSET(ZREG_RBP) | ZEND_REGSET(ZREG_R12) | ZEND_REGSET(ZREG_R13))
  123. #else
  124. # define ZEND_REGSET_FIXED \
  125. (ZEND_REGSET(ZREG_RSP) | ZEND_REGSET(ZREG_RSI) | ZEND_REGSET(ZREG_RDI))
  126. # define ZEND_REGSET_GP \
  127. ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_R0, ZREG_R7), ZEND_REGSET_FIXED)
  128. # define ZEND_REGSET_FP \
  129. ZEND_REGSET_DIFFERENCE(ZEND_REGSET_INTERVAL(ZREG_XMM0, ZREG_XMM7), ZEND_REGSET_FIXED)
  130. # define ZEND_REGSET_SCRATCH \
  131. (ZEND_REGSET(ZREG_RAX) | ZEND_REGSET(ZREG_RCX) | ZEND_REGSET(ZREG_RDX) | ZEND_REGSET_FP)
  132. # define ZEND_REGSET_PRESERVED \
  133. (ZEND_REGSET(ZREG_RBX) | ZEND_REGSET(ZREG_RBP))
  134. #endif
  135. #define ZEND_REGSET_LOW_PRIORITY \
  136. (ZEND_REGSET(ZREG_R0) | ZEND_REGSET(ZREG_R1) | ZEND_REGSET(ZREG_XMM0) | ZEND_REGSET(ZREG_XMM1))
  137. #endif /* ZEND_JIT_X86_H */