Index: src/ia32/assembler-ia32.h |
diff --git a/src/ia32/assembler-ia32.h b/src/ia32/assembler-ia32.h |
index fd5cf1ae82e84e8ec1efa933a69af387367f43d6..82ab9135461da2e794c5caaff0c88a2daa0acf6e 100644 |
--- a/src/ia32/assembler-ia32.h |
+++ b/src/ia32/assembler-ia32.h |
@@ -42,10 +42,48 @@ |
#include "src/assembler.h" |
#include "src/compiler.h" |
#include "src/isolate.h" |
+#include "src/utils.h" |
namespace v8 { |
namespace internal { |
+#define GENERAL_REGISTERS(V) \ |
+ V(eax) \ |
+ V(ecx) \ |
+ V(edx) \ |
+ V(ebx) \ |
+ V(esp) \ |
+ V(ebp) \ |
+ V(esi) \ |
+ V(edi) |
+ |
+#define ALLOCATABLE_GENERAL_REGISTERS(V) \ |
+ V(eax) \ |
+ V(ecx) \ |
+ V(edx) \ |
+ V(ebx) \ |
+ V(esi) \ |
+ V(edi) |
+ |
+#define DOUBLE_REGISTERS(V) \ |
+ V(xmm0) \ |
+ V(xmm1) \ |
+ V(xmm2) \ |
+ V(xmm3) \ |
+ V(xmm4) \ |
+ V(xmm5) \ |
+ V(xmm6) \ |
+ V(xmm7) |
+ |
+#define ALLOCATABLE_DOUBLE_REGISTERS(V) \ |
+ V(xmm1) \ |
+ V(xmm2) \ |
+ V(xmm3) \ |
+ V(xmm4) \ |
+ V(xmm5) \ |
+ V(xmm6) \ |
+ V(xmm7) |
+ |
// CPU Registers. |
// |
// 1) We would prefer to use an enum, but enum values are assignment- |
@@ -68,151 +106,86 @@ namespace internal { |
// and best performance in optimized code. |
// |
struct Register { |
- static const int kMaxNumAllocatableRegisters = 6; |
- static int NumAllocatableRegisters() { |
- return kMaxNumAllocatableRegisters; |
- } |
- static const int kNumRegisters = 8; |
- |
- static inline const char* AllocationIndexToString(int index); |
+ enum Code { |
+#define REGISTER_CODE(R) kCode_##R, |
+ GENERAL_REGISTERS(REGISTER_CODE) |
+#undef REGISTER_CODE |
+ kAfterLast, |
+ kCode_no_reg = -1 |
+ }; |
- static inline int ToAllocationIndex(Register reg); |
- |
- static inline Register FromAllocationIndex(int index); |
+ static const int kNumRegisters = Code::kAfterLast; |
static Register from_code(int code) { |
DCHECK(code >= 0); |
DCHECK(code < kNumRegisters); |
- Register r = { code }; |
+ Register r = {code}; |
return r; |
} |
- bool is_valid() const { return 0 <= code_ && code_ < kNumRegisters; } |
- bool is(Register reg) const { return code_ == reg.code_; } |
- // eax, ebx, ecx and edx are byte registers, the rest are not. |
- bool is_byte_register() const { return code_ <= 3; } |
+ const char* ToString(); |
+ bool IsAllocatable() const; |
+ bool is_valid() const { return 0 <= reg_code && reg_code < kNumRegisters; } |
+ bool is(Register reg) const { return reg_code == reg.reg_code; } |
int code() const { |
DCHECK(is_valid()); |
- return code_; |
+ return reg_code; |
} |
int bit() const { |
DCHECK(is_valid()); |
- return 1 << code_; |
+ return 1 << reg_code; |
} |
+ bool is_byte_register() const { return reg_code <= 3; } |
+ |
// Unfortunately we can't make this private in a struct. |
- int code_; |
+ int reg_code; |
}; |
-const int kRegister_eax_Code = 0; |
-const int kRegister_ecx_Code = 1; |
-const int kRegister_edx_Code = 2; |
-const int kRegister_ebx_Code = 3; |
-const int kRegister_esp_Code = 4; |
-const int kRegister_ebp_Code = 5; |
-const int kRegister_esi_Code = 6; |
-const int kRegister_edi_Code = 7; |
-const int kRegister_no_reg_Code = -1; |
- |
-const Register eax = { kRegister_eax_Code }; |
-const Register ecx = { kRegister_ecx_Code }; |
-const Register edx = { kRegister_edx_Code }; |
-const Register ebx = { kRegister_ebx_Code }; |
-const Register esp = { kRegister_esp_Code }; |
-const Register ebp = { kRegister_ebp_Code }; |
-const Register esi = { kRegister_esi_Code }; |
-const Register edi = { kRegister_edi_Code }; |
-const Register no_reg = { kRegister_no_reg_Code }; |
- |
- |
-inline const char* Register::AllocationIndexToString(int index) { |
- DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters); |
- // This is the mapping of allocation indices to registers. |
- const char* const kNames[] = { "eax", "ecx", "edx", "ebx", "esi", "edi" }; |
- return kNames[index]; |
-} |
- |
- |
-inline int Register::ToAllocationIndex(Register reg) { |
- DCHECK(reg.is_valid() && !reg.is(esp) && !reg.is(ebp)); |
- return (reg.code() >= 6) ? reg.code() - 2 : reg.code(); |
-} |
- |
- |
-inline Register Register::FromAllocationIndex(int index) { |
- DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters); |
- return (index >= 4) ? from_code(index + 2) : from_code(index); |
-} |
- |
-struct XMMRegister { |
- static const int kMaxNumAllocatableRegisters = 7; |
- static const int kMaxNumRegisters = 8; |
- static int NumAllocatableRegisters() { |
- return kMaxNumAllocatableRegisters; |
- } |
+#define DECLARE_REGISTER(R) const Register R = {Register::kCode_##R}; |
+GENERAL_REGISTERS(DECLARE_REGISTER) |
+#undef DECLARE_REGISTER |
+const Register no_reg = {Register::kCode_no_reg}; |
- // TODO(turbofan): Proper support for float32. |
- static int NumAllocatableAliasedRegisters() { |
- return NumAllocatableRegisters(); |
- } |
- static int ToAllocationIndex(XMMRegister reg) { |
- DCHECK(reg.code() != 0); |
- return reg.code() - 1; |
- } |
+struct DoubleRegister { |
+ enum Code { |
+#define REGISTER_CODE(R) kCode_##R, |
+ DOUBLE_REGISTERS(REGISTER_CODE) |
+#undef REGISTER_CODE |
+ kAfterLast, |
+ kCode_no_reg = -1 |
+ }; |
- static XMMRegister FromAllocationIndex(int index) { |
- DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters); |
- return from_code(index + 1); |
- } |
+ static const int kMaxNumRegisters = Code::kAfterLast; |
- static XMMRegister from_code(int code) { |
- XMMRegister result = { code }; |
+ static DoubleRegister from_code(int code) { |
+ DoubleRegister result = {code}; |
return result; |
} |
- bool is_valid() const { |
- return 0 <= code_ && code_ < kMaxNumRegisters; |
- } |
+ bool IsAllocatable() const; |
+ bool is_valid() const { return 0 <= reg_code && reg_code < kMaxNumRegisters; } |
int code() const { |
DCHECK(is_valid()); |
- return code_; |
+ return reg_code; |
} |
- bool is(XMMRegister reg) const { return code_ == reg.code_; } |
+ bool is(DoubleRegister reg) const { return reg_code == reg.reg_code; } |
- static const char* AllocationIndexToString(int index) { |
- DCHECK(index >= 0 && index < kMaxNumAllocatableRegisters); |
- const char* const names[] = { |
- "xmm1", |
- "xmm2", |
- "xmm3", |
- "xmm4", |
- "xmm5", |
- "xmm6", |
- "xmm7" |
- }; |
- return names[index]; |
- } |
+ const char* ToString(); |
- int code_; |
+ int reg_code; |
}; |
+#define DECLARE_REGISTER(R) \ |
+ const DoubleRegister R = {DoubleRegister::kCode_##R}; |
+DOUBLE_REGISTERS(DECLARE_REGISTER) |
+#undef DECLARE_REGISTER |
+const DoubleRegister no_double_reg = {DoubleRegister::kCode_no_reg}; |
-typedef XMMRegister DoubleRegister; |
- |
- |
-const XMMRegister xmm0 = { 0 }; |
-const XMMRegister xmm1 = { 1 }; |
-const XMMRegister xmm2 = { 2 }; |
-const XMMRegister xmm3 = { 3 }; |
-const XMMRegister xmm4 = { 4 }; |
-const XMMRegister xmm5 = { 5 }; |
-const XMMRegister xmm6 = { 6 }; |
-const XMMRegister xmm7 = { 7 }; |
-const XMMRegister no_xmm_reg = { -1 }; |
- |
+typedef DoubleRegister XMMRegister; |
enum Condition { |
// any value < 0 is considered no_condition |