DFGFPRInfo.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright (C) 2011 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef DFGFPRInfo_h
  26. #define DFGFPRInfo_h
  27. #if ENABLE(DFG_JIT)
  28. #include "DFGRegisterBank.h"
  29. #include "MacroAssembler.h"
  30. namespace JSC { namespace DFG {
  31. typedef MacroAssembler::FPRegisterID FPRReg;
  32. #define InvalidFPRReg ((FPRReg)-1)
  33. #if CPU(X86) || CPU(X86_64)
  34. class FPRInfo {
  35. public:
  36. typedef FPRReg RegisterType;
  37. static const unsigned numberOfRegisters = 6;
  38. // Temporary registers.
  39. static const FPRReg fpRegT0 = X86Registers::xmm0;
  40. static const FPRReg fpRegT1 = X86Registers::xmm1;
  41. static const FPRReg fpRegT2 = X86Registers::xmm2;
  42. static const FPRReg fpRegT3 = X86Registers::xmm3;
  43. static const FPRReg fpRegT4 = X86Registers::xmm4;
  44. static const FPRReg fpRegT5 = X86Registers::xmm5;
  45. #if CPU(X86_64)
  46. // Only X86_64 passes aguments in xmm registers
  47. static const FPRReg argumentFPR0 = X86Registers::xmm0; // fpRegT0
  48. static const FPRReg argumentFPR1 = X86Registers::xmm1; // fpRegT1
  49. static const FPRReg argumentFPR2 = X86Registers::xmm2; // fpRegT2
  50. static const FPRReg argumentFPR3 = X86Registers::xmm3; // fpRegT3
  51. #endif
  52. // On X86 the return will actually be on the x87 stack,
  53. // so we'll copy to xmm0 for sanity!
  54. static const FPRReg returnValueFPR = X86Registers::xmm0; // fpRegT0
  55. // FPRReg mapping is direct, the machine regsiter numbers can
  56. // be used directly as indices into the FPR RegisterBank.
  57. COMPILE_ASSERT(X86Registers::xmm0 == 0, xmm0_is_0);
  58. COMPILE_ASSERT(X86Registers::xmm1 == 1, xmm1_is_1);
  59. COMPILE_ASSERT(X86Registers::xmm2 == 2, xmm2_is_2);
  60. COMPILE_ASSERT(X86Registers::xmm3 == 3, xmm3_is_3);
  61. COMPILE_ASSERT(X86Registers::xmm4 == 4, xmm4_is_4);
  62. COMPILE_ASSERT(X86Registers::xmm5 == 5, xmm5_is_5);
  63. static FPRReg toRegister(unsigned index)
  64. {
  65. return (FPRReg)index;
  66. }
  67. static unsigned toIndex(FPRReg reg)
  68. {
  69. return (unsigned)reg;
  70. }
  71. static const char* debugName(FPRReg reg)
  72. {
  73. ASSERT(reg != InvalidFPRReg);
  74. #if CPU(X86_64)
  75. ASSERT(static_cast<int>(reg) < 16);
  76. static const char* nameForRegister[16] = {
  77. "xmm0", "xmm1", "xmm2", "xmm3",
  78. "xmm4", "xmm5", "xmm6", "xmm7",
  79. "xmm8", "xmm9", "xmm10", "xmm11",
  80. "xmm12", "xmm13", "xmm14", "xmm15"
  81. };
  82. #elif CPU(X86)
  83. ASSERT(static_cast<int>(reg) < 8);
  84. static const char* nameForRegister[8] = {
  85. "xmm0", "xmm1", "xmm2", "xmm3",
  86. "xmm4", "xmm5", "xmm6", "xmm7"
  87. };
  88. #endif
  89. return nameForRegister[reg];
  90. }
  91. };
  92. #endif
  93. #if CPU(ARM)
  94. class FPRInfo {
  95. public:
  96. typedef FPRReg RegisterType;
  97. static const unsigned numberOfRegisters = 6;
  98. // Temporary registers.
  99. // d7 is use by the MacroAssembler as fpTempRegister.
  100. static const FPRReg fpRegT0 = ARMRegisters::d0;
  101. static const FPRReg fpRegT1 = ARMRegisters::d1;
  102. static const FPRReg fpRegT2 = ARMRegisters::d2;
  103. static const FPRReg fpRegT3 = ARMRegisters::d3;
  104. static const FPRReg fpRegT4 = ARMRegisters::d4;
  105. static const FPRReg fpRegT5 = ARMRegisters::d5;
  106. // ARMv7 doesn't pass arguments in fp registers. The return
  107. // value is also actually in integer registers, for now
  108. // we'll return in d0 for simplicity.
  109. static const FPRReg returnValueFPR = ARMRegisters::d0; // fpRegT0
  110. #if CPU(ARM_HARDFP)
  111. static const FPRReg argumentFPR0 = ARMRegisters::d0; // fpRegT0
  112. static const FPRReg argumentFPR1 = ARMRegisters::d1; // fpRegT1
  113. #endif
  114. // FPRReg mapping is direct, the machine regsiter numbers can
  115. // be used directly as indices into the FPR RegisterBank.
  116. COMPILE_ASSERT(ARMRegisters::d0 == 0, d0_is_0);
  117. COMPILE_ASSERT(ARMRegisters::d1 == 1, d1_is_1);
  118. COMPILE_ASSERT(ARMRegisters::d2 == 2, d2_is_2);
  119. COMPILE_ASSERT(ARMRegisters::d3 == 3, d3_is_3);
  120. COMPILE_ASSERT(ARMRegisters::d4 == 4, d4_is_4);
  121. COMPILE_ASSERT(ARMRegisters::d5 == 5, d5_is_5);
  122. static FPRReg toRegister(unsigned index)
  123. {
  124. return (FPRReg)index;
  125. }
  126. static unsigned toIndex(FPRReg reg)
  127. {
  128. return (unsigned)reg;
  129. }
  130. static const char* debugName(FPRReg reg)
  131. {
  132. ASSERT(reg != InvalidFPRReg);
  133. ASSERT(static_cast<int>(reg) < 32);
  134. static const char* nameForRegister[32] = {
  135. "d0", "d1", "d2", "d3",
  136. "d4", "d5", "d6", "d7",
  137. "d8", "d9", "d10", "d11",
  138. "d12", "d13", "d14", "d15",
  139. "d16", "d17", "d18", "d19",
  140. "d20", "d21", "d22", "d23",
  141. "d24", "d25", "d26", "d27",
  142. "d28", "d29", "d30", "d31"
  143. };
  144. return nameForRegister[reg];
  145. }
  146. };
  147. #endif
  148. #if CPU(MIPS)
  149. class FPRInfo {
  150. public:
  151. typedef FPRReg RegisterType;
  152. static const unsigned numberOfRegisters = 6;
  153. // Temporary registers.
  154. static const FPRReg fpRegT0 = MIPSRegisters::f0;
  155. static const FPRReg fpRegT1 = MIPSRegisters::f4;
  156. static const FPRReg fpRegT2 = MIPSRegisters::f6;
  157. static const FPRReg fpRegT3 = MIPSRegisters::f8;
  158. static const FPRReg fpRegT4 = MIPSRegisters::f10;
  159. static const FPRReg fpRegT5 = MIPSRegisters::f18;
  160. static const FPRReg returnValueFPR = MIPSRegisters::f0;
  161. static const FPRReg argumentFPR0 = MIPSRegisters::f12;
  162. static const FPRReg argumentFPR1 = MIPSRegisters::f14;
  163. static FPRReg toRegister(unsigned index)
  164. {
  165. static const FPRReg registerForIndex[numberOfRegisters] = {
  166. fpRegT0, fpRegT1, fpRegT2, fpRegT3, fpRegT4, fpRegT5 };
  167. ASSERT(index < numberOfRegisters);
  168. return registerForIndex[index];
  169. }
  170. static unsigned toIndex(FPRReg reg)
  171. {
  172. ASSERT(reg != InvalidFPRReg);
  173. ASSERT(reg < 20);
  174. static const unsigned indexForRegister[20] = {
  175. 0, InvalidIndex, InvalidIndex, InvalidIndex,
  176. 1, InvalidIndex, 2, InvalidIndex,
  177. 3, InvalidIndex, 4, InvalidIndex,
  178. InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex,
  179. InvalidIndex, InvalidIndex, 5, InvalidIndex,
  180. };
  181. unsigned result = indexForRegister[reg];
  182. ASSERT(result != InvalidIndex);
  183. return result;
  184. }
  185. static const char* debugName(FPRReg reg)
  186. {
  187. ASSERT(reg != InvalidFPRReg);
  188. ASSERT(reg < 32);
  189. static const char* nameForRegister[32] = {
  190. "f0", "f1", "f2", "f3",
  191. "f4", "f5", "f6", "f7",
  192. "f8", "f9", "f10", "f11",
  193. "f12", "f13", "f14", "f15"
  194. "f16", "f17", "f18", "f19"
  195. "f20", "f21", "f22", "f23"
  196. "f24", "f25", "f26", "f27"
  197. "f28", "f29", "f30", "f31"
  198. };
  199. return nameForRegister[reg];
  200. }
  201. private:
  202. static const unsigned InvalidIndex = 0xffffffff;
  203. };
  204. #endif
  205. typedef RegisterBank<FPRInfo>::iterator fpr_iterator;
  206. } } // namespace JSC::DFG
  207. #endif
  208. #endif