src/lj_target_arm.h - luajit-2.0-src

Data types defined

Macros defined

Source code

  1. /*
  2. ** Definitions for ARM CPUs.
  3. ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
  4. */

  5. #ifndef _LJ_TARGET_ARM_H
  6. #define _LJ_TARGET_ARM_H

  7. /* -- Registers IDs ------------------------------------------------------- */

  8. #define GPRDEF(_) \
  9.   _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \
  10.   _(R8) _(R9) _(R10) _(R11) _(R12) _(SP) _(LR) _(PC)
  11. #if LJ_SOFTFP
  12. #define FPRDEF(_)
  13. #else
  14. #define FPRDEF(_) \
  15.   _(D0) _(D1) _(D2) _(D3) _(D4) _(D5) _(D6) _(D7) \
  16.   _(D8) _(D9) _(D10) _(D11) _(D12) _(D13) _(D14) _(D15)
  17. #endif
  18. #define VRIDDEF(_)

  19. #define RIDENUM(name)        RID_##name,

  20. enum {
  21.   GPRDEF(RIDENUM)                /* General-purpose registers (GPRs). */
  22.   FPRDEF(RIDENUM)                /* Floating-point registers (FPRs). */
  23.   RID_MAX,
  24.   RID_TMP = RID_LR,

  25.   /* Calling conventions. */
  26.   RID_RET = RID_R0,
  27.   RID_RETLO = RID_R0,
  28.   RID_RETHI = RID_R1,
  29. #if LJ_SOFTFP
  30.   RID_FPRET = RID_R0,
  31. #else
  32.   RID_FPRET = RID_D0,
  33. #endif

  34.   /* These definitions must match with the *.dasc file(s): */
  35.   RID_BASE = RID_R9,                /* Interpreter BASE. */
  36.   RID_LPC = RID_R6,                /* Interpreter PC. */
  37.   RID_DISPATCH = RID_R7,        /* Interpreter DISPATCH table. */
  38.   RID_LREG = RID_R8,                /* Interpreter L. */

  39.   /* Register ranges [min, max) and number of registers. */
  40.   RID_MIN_GPR = RID_R0,
  41.   RID_MAX_GPR = RID_PC+1,
  42.   RID_MIN_FPR = RID_MAX_GPR,
  43. #if LJ_SOFTFP
  44.   RID_MAX_FPR = RID_MIN_FPR,
  45. #else
  46.   RID_MAX_FPR = RID_D15+1,
  47. #endif
  48.   RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
  49.   RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR
  50. };

  51. #define RID_NUM_KREF                RID_NUM_GPR
  52. #define RID_MIN_KREF                RID_R0

  53. /* -- Register sets ------------------------------------------------------- */

  54. /* Make use of all registers, except sp, lr and pc. */
  55. #define RSET_GPR                (RSET_RANGE(RID_MIN_GPR, RID_R12+1))
  56. #define RSET_GPREVEN \
  57.   (RID2RSET(RID_R0)|RID2RSET(RID_R2)|RID2RSET(RID_R4)|RID2RSET(RID_R6)| \
  58.    RID2RSET(RID_R8)|RID2RSET(RID_R10))
  59. #define RSET_GPRODD \
  60.   (RID2RSET(RID_R1)|RID2RSET(RID_R3)|RID2RSET(RID_R5)|RID2RSET(RID_R7)| \
  61.    RID2RSET(RID_R9)|RID2RSET(RID_R11))
  62. #if LJ_SOFTFP
  63. #define RSET_FPR                0
  64. #else
  65. #define RSET_FPR                (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR))
  66. #endif
  67. #define RSET_ALL                (RSET_GPR|RSET_FPR)
  68. #define RSET_INIT                RSET_ALL

  69. /* ABI-specific register sets. lr is an implicit scratch register. */
  70. #define RSET_SCRATCH_GPR_        (RSET_RANGE(RID_R0, RID_R3+1)|RID2RSET(RID_R12))
  71. #ifdef __APPLE__
  72. #define RSET_SCRATCH_GPR        (RSET_SCRATCH_GPR_|RID2RSET(RID_R9))
  73. #else
  74. #define RSET_SCRATCH_GPR        RSET_SCRATCH_GPR_
  75. #endif
  76. #if LJ_SOFTFP
  77. #define RSET_SCRATCH_FPR        0
  78. #else
  79. #define RSET_SCRATCH_FPR        (RSET_RANGE(RID_D0, RID_D7+1))
  80. #endif
  81. #define RSET_SCRATCH                (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)
  82. #define REGARG_FIRSTGPR                RID_R0
  83. #define REGARG_LASTGPR                RID_R3
  84. #define REGARG_NUMGPR                4
  85. #if LJ_ABI_SOFTFP
  86. #define REGARG_FIRSTFPR                0
  87. #define REGARG_LASTFPR                0
  88. #define REGARG_NUMFPR                0
  89. #else
  90. #define REGARG_FIRSTFPR                RID_D0
  91. #define REGARG_LASTFPR                RID_D7
  92. #define REGARG_NUMFPR                8
  93. #endif

  94. /* -- Spill slots --------------------------------------------------------- */

  95. /* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
  96. **
  97. ** SPS_FIXED: Available fixed spill slots in interpreter frame.
  98. ** This definition must match with the *.dasc file(s).
  99. **
  100. ** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.
  101. */
  102. #define SPS_FIXED        2
  103. #define SPS_FIRST        2

  104. #define SPOFS_TMP        0

  105. #define sps_scale(slot)                (4 * (int32_t)(slot))
  106. #define sps_align(slot)                (((slot) - SPS_FIXED + 1) & ~1)

  107. /* -- Exit state ---------------------------------------------------------- */

  108. /* This definition must match with the *.dasc file(s). */
  109. typedef struct {
  110. #if !LJ_SOFTFP
  111.   lua_Number fpr[RID_NUM_FPR];        /* Floating-point registers. */
  112. #endif
  113.   int32_t gpr[RID_NUM_GPR];        /* General-purpose registers. */
  114.   int32_t spill[256];                /* Spill slots. */
  115. } ExitState;

  116. /* PC after instruction that caused an exit. Used to find the trace number. */
  117. #define EXITSTATE_PCREG                RID_PC
  118. /* Highest exit + 1 indicates stack check. */
  119. #define EXITSTATE_CHECKEXIT        1

  120. #define EXITSTUB_SPACING        4
  121. #define EXITSTUBS_PER_GROUP     32

  122. /* -- Instructions -------------------------------------------------------- */

  123. /* Instruction fields. */
  124. #define ARMF_CC(ai, cc)        (((ai) ^ ARMI_CCAL) | ((cc) << 28))
  125. #define ARMF_N(r)        ((r) << 16)
  126. #define ARMF_D(r)        ((r) << 12)
  127. #define ARMF_S(r)        ((r) << 8)
  128. #define ARMF_M(r)        (r)
  129. #define ARMF_SH(sh, n)        (((sh) << 5) | ((n) << 7))
  130. #define ARMF_RSH(sh, r)        (0x10 | ((sh) << 5) | ARMF_S(r))

  131. typedef enum ARMIns {
  132.   ARMI_CCAL = 0xe0000000,
  133.   ARMI_S = 0x000100000,
  134.   ARMI_K12 = 0x02000000,
  135.   ARMI_KNEG = 0x00200000,
  136.   ARMI_LS_W = 0x00200000,
  137.   ARMI_LS_U = 0x00800000,
  138.   ARMI_LS_P = 0x01000000,
  139.   ARMI_LS_R = 0x02000000,
  140.   ARMI_LSX_I = 0x00400000,

  141.   ARMI_AND = 0xe0000000,
  142.   ARMI_EOR = 0xe0200000,
  143.   ARMI_SUB = 0xe0400000,
  144.   ARMI_RSB = 0xe0600000,
  145.   ARMI_ADD = 0xe0800000,
  146.   ARMI_ADC = 0xe0a00000,
  147.   ARMI_SBC = 0xe0c00000,
  148.   ARMI_RSC = 0xe0e00000,
  149.   ARMI_TST = 0xe1100000,
  150.   ARMI_TEQ = 0xe1300000,
  151.   ARMI_CMP = 0xe1500000,
  152.   ARMI_CMN = 0xe1700000,
  153.   ARMI_ORR = 0xe1800000,
  154.   ARMI_MOV = 0xe1a00000,
  155.   ARMI_BIC = 0xe1c00000,
  156.   ARMI_MVN = 0xe1e00000,

  157.   ARMI_NOP = 0xe1a00000,

  158.   ARMI_MUL = 0xe0000090,
  159.   ARMI_SMULL = 0xe0c00090,

  160.   ARMI_LDR = 0xe4100000,
  161.   ARMI_LDRB = 0xe4500000,
  162.   ARMI_LDRH = 0xe01000b0,
  163.   ARMI_LDRSB = 0xe01000d0,
  164.   ARMI_LDRSH = 0xe01000f0,
  165.   ARMI_LDRD = 0xe00000d0,
  166.   ARMI_STR = 0xe4000000,
  167.   ARMI_STRB = 0xe4400000,
  168.   ARMI_STRH = 0xe00000b0,
  169.   ARMI_STRD = 0xe00000f0,
  170.   ARMI_PUSH = 0xe92d0000,

  171.   ARMI_B = 0xea000000,
  172.   ARMI_BL = 0xeb000000,
  173.   ARMI_BLX = 0xfa000000,
  174.   ARMI_BLXr = 0xe12fff30,

  175.   /* ARMv6 */
  176.   ARMI_REV = 0xe6bf0f30,
  177.   ARMI_SXTB = 0xe6af0070,
  178.   ARMI_SXTH = 0xe6bf0070,
  179.   ARMI_UXTB = 0xe6ef0070,
  180.   ARMI_UXTH = 0xe6ff0070,

  181.   /* ARMv6T2 */
  182.   ARMI_MOVW = 0xe3000000,
  183.   ARMI_MOVT = 0xe3400000,

  184.   /* VFP */
  185.   ARMI_VMOV_D = 0xeeb00b40,
  186.   ARMI_VMOV_S = 0xeeb00a40,
  187.   ARMI_VMOVI_D = 0xeeb00b00,

  188.   ARMI_VMOV_R_S = 0xee100a10,
  189.   ARMI_VMOV_S_R = 0xee000a10,
  190.   ARMI_VMOV_RR_D = 0xec500b10,
  191.   ARMI_VMOV_D_RR = 0xec400b10,

  192.   ARMI_VADD_D = 0xee300b00,
  193.   ARMI_VSUB_D = 0xee300b40,
  194.   ARMI_VMUL_D = 0xee200b00,
  195.   ARMI_VMLA_D = 0xee000b00,
  196.   ARMI_VMLS_D = 0xee000b40,
  197.   ARMI_VNMLS_D = 0xee100b00,
  198.   ARMI_VDIV_D = 0xee800b00,

  199.   ARMI_VABS_D = 0xeeb00bc0,
  200.   ARMI_VNEG_D = 0xeeb10b40,
  201.   ARMI_VSQRT_D = 0xeeb10bc0,

  202.   ARMI_VCMP_D = 0xeeb40b40,
  203.   ARMI_VCMPZ_D = 0xeeb50b40,

  204.   ARMI_VMRS = 0xeef1fa10,

  205.   ARMI_VCVT_S32_F32 = 0xeebd0ac0,
  206.   ARMI_VCVT_S32_F64 = 0xeebd0bc0,
  207.   ARMI_VCVT_U32_F32 = 0xeebc0ac0,
  208.   ARMI_VCVT_U32_F64 = 0xeebc0bc0,
  209.   ARMI_VCVT_F32_S32 = 0xeeb80ac0,
  210.   ARMI_VCVT_F64_S32 = 0xeeb80bc0,
  211.   ARMI_VCVT_F32_U32 = 0xeeb80a40,
  212.   ARMI_VCVT_F64_U32 = 0xeeb80b40,
  213.   ARMI_VCVT_F32_F64 = 0xeeb70bc0,
  214.   ARMI_VCVT_F64_F32 = 0xeeb70ac0,

  215.   ARMI_VLDR_S = 0xed100a00,
  216.   ARMI_VLDR_D = 0xed100b00,
  217.   ARMI_VSTR_S = 0xed000a00,
  218.   ARMI_VSTR_D = 0xed000b00,
  219. } ARMIns;

  220. typedef enum ARMShift {
  221.   ARMSH_LSL, ARMSH_LSR, ARMSH_ASR, ARMSH_ROR
  222. } ARMShift;

  223. /* ARM condition codes. */
  224. typedef enum ARMCC {
  225.   CC_EQ, CC_NE, CC_CS, CC_CC, CC_MI, CC_PL, CC_VS, CC_VC,
  226.   CC_HI, CC_LS, CC_GE, CC_LT, CC_GT, CC_LE, CC_AL,
  227.   CC_HS = CC_CS, CC_LO = CC_CC
  228. } ARMCC;

  229. #endif