Simplify DoubleRegister for the ia32 port.

R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/284503002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21284 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2014-05-13 09:05:00 +00:00
parent 2b9de3866f
commit abeb747c92
6 changed files with 45 additions and 84 deletions

View File

@ -62,21 +62,6 @@ ExternalReference ExternalReference::cpu_features() {
}
int DoubleRegister::NumAllocatableRegisters() {
return XMMRegister::kNumAllocatableRegisters;
}
int DoubleRegister::NumRegisters() {
return XMMRegister::kNumRegisters;
}
const char* DoubleRegister::AllocationIndexToString(int index) {
return XMMRegister::AllocationIndexToString(index);
}
void CpuFeatures::Probe(bool serializer_enabled) {
ASSERT(!initialized_);
ASSERT(supported_ == 0);

View File

@ -141,71 +141,41 @@ inline Register Register::FromAllocationIndex(int index) {
}
struct DoubleRegister {
static const int kMaxNumRegisters = 8;
struct XMMRegister {
static const int kMaxNumAllocatableRegisters = 7;
static int NumAllocatableRegisters();
static int NumRegisters();
static const char* AllocationIndexToString(int index);
static const int kMaxNumRegisters = 8;
static int NumAllocatableRegisters() {
return kMaxNumAllocatableRegisters;
}
static int ToAllocationIndex(DoubleRegister reg) {
static int ToAllocationIndex(XMMRegister reg) {
ASSERT(reg.code() != 0);
return reg.code() - 1;
}
static DoubleRegister FromAllocationIndex(int index) {
ASSERT(index >= 0 && index < NumAllocatableRegisters());
static XMMRegister FromAllocationIndex(int index) {
ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters);
return from_code(index + 1);
}
static DoubleRegister from_code(int code) {
DoubleRegister result = { code };
static XMMRegister from_code(int code) {
XMMRegister result = { code };
return result;
}
bool is_valid() const {
return 0 <= code_ && code_ < NumRegisters();
return 0 <= code_ && code_ < kMaxNumRegisters;
}
int code() const {
ASSERT(is_valid());
return code_;
}
int code_;
};
const DoubleRegister double_register_0 = { 0 };
const DoubleRegister double_register_1 = { 1 };
const DoubleRegister double_register_2 = { 2 };
const DoubleRegister double_register_3 = { 3 };
const DoubleRegister double_register_4 = { 4 };
const DoubleRegister double_register_5 = { 5 };
const DoubleRegister double_register_6 = { 6 };
const DoubleRegister double_register_7 = { 7 };
const DoubleRegister no_double_reg = { -1 };
struct XMMRegister : DoubleRegister {
static const int kNumAllocatableRegisters = 7;
static const int kNumRegisters = 8;
static XMMRegister from_code(int code) {
STATIC_ASSERT(sizeof(XMMRegister) == sizeof(DoubleRegister));
XMMRegister result;
result.code_ = code;
return result;
}
bool is(XMMRegister reg) const { return code_ == reg.code_; }
static XMMRegister FromAllocationIndex(int index) {
ASSERT(index >= 0 && index < NumAllocatableRegisters());
return from_code(index + 1);
}
static const char* AllocationIndexToString(int index) {
ASSERT(index >= 0 && index < kNumAllocatableRegisters);
ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters);
const char* const names[] = {
"xmm1",
"xmm2",
@ -217,18 +187,23 @@ struct XMMRegister : DoubleRegister {
};
return names[index];
}
int code_;
};
#define xmm0 (static_cast<const XMMRegister&>(double_register_0))
#define xmm1 (static_cast<const XMMRegister&>(double_register_1))
#define xmm2 (static_cast<const XMMRegister&>(double_register_2))
#define xmm3 (static_cast<const XMMRegister&>(double_register_3))
#define xmm4 (static_cast<const XMMRegister&>(double_register_4))
#define xmm5 (static_cast<const XMMRegister&>(double_register_5))
#define xmm6 (static_cast<const XMMRegister&>(double_register_6))
#define xmm7 (static_cast<const XMMRegister&>(double_register_7))
#define no_xmm_reg (static_cast<const XMMRegister&>(no_double_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 };
enum Condition {

View File

@ -480,8 +480,8 @@ void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
// restore them.
__ pushad();
if (save_doubles_ == kSaveFPRegs) {
__ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters));
for (int i = 0; i < XMMRegister::kNumRegisters; i++) {
__ sub(esp, Immediate(kDoubleSize * XMMRegister::kMaxNumRegisters));
for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) {
XMMRegister reg = XMMRegister::from_code(i);
__ movsd(Operand(esp, i * kDoubleSize), reg);
}
@ -496,11 +496,11 @@ void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
ExternalReference::store_buffer_overflow_function(isolate()),
argument_count);
if (save_doubles_ == kSaveFPRegs) {
for (int i = 0; i < XMMRegister::kNumRegisters; i++) {
for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) {
XMMRegister reg = XMMRegister::from_code(i);
__ movsd(reg, Operand(esp, i * kDoubleSize));
}
__ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters));
__ add(esp, Immediate(kDoubleSize * XMMRegister::kMaxNumRegisters));
}
__ popad();
__ ret(0);

View File

@ -336,9 +336,9 @@ class RecordWriteStub: public PlatformCodeStub {
if (!scratch0_.is(edx) && !scratch1_.is(edx)) masm->push(edx);
if (mode == kSaveFPRegs) {
masm->sub(esp,
Immediate(kDoubleSize * (XMMRegister::kNumRegisters - 1)));
Immediate(kDoubleSize * (XMMRegister::kMaxNumRegisters - 1)));
// Save all XMM registers except XMM0.
for (int i = XMMRegister::kNumRegisters - 1; i > 0; i--) {
for (int i = XMMRegister::kMaxNumRegisters - 1; i > 0; i--) {
XMMRegister reg = XMMRegister::from_code(i);
masm->movsd(Operand(esp, (i - 1) * kDoubleSize), reg);
}
@ -349,12 +349,12 @@ class RecordWriteStub: public PlatformCodeStub {
SaveFPRegsMode mode) {
if (mode == kSaveFPRegs) {
// Restore all XMM registers except XMM0.
for (int i = XMMRegister::kNumRegisters - 1; i > 0; i--) {
for (int i = XMMRegister::kMaxNumRegisters - 1; i > 0; i--) {
XMMRegister reg = XMMRegister::from_code(i);
masm->movsd(reg, Operand(esp, (i - 1) * kDoubleSize));
}
masm->add(esp,
Immediate(kDoubleSize * (XMMRegister::kNumRegisters - 1)));
Immediate(kDoubleSize * (XMMRegister::kMaxNumRegisters - 1)));
}
if (!scratch0_.is(edx) && !scratch1_.is(edx)) masm->pop(edx);
if (!scratch0_.is(eax) && !scratch1_.is(eax)) masm->pop(eax);

View File

@ -187,7 +187,7 @@ void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) {
}
input_->SetRegister(esp.code(), reinterpret_cast<intptr_t>(frame->sp()));
input_->SetRegister(ebp.code(), reinterpret_cast<intptr_t>(frame->fp()));
for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) {
for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; i++) {
input_->SetDoubleRegister(i, 0.0);
}
@ -209,7 +209,7 @@ void Deoptimizer::SetPlatformCompiledStubRegisters(
void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) {
for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) {
for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) {
double double_value = input_->GetDoubleRegister(i);
output_frame->SetDoubleRegister(i, double_value);
}
@ -239,9 +239,9 @@ void Deoptimizer::EntryGenerator::Generate() {
const int kNumberOfRegisters = Register::kNumRegisters;
const int kDoubleRegsSize = kDoubleSize *
XMMRegister::kNumAllocatableRegisters;
XMMRegister::kMaxNumAllocatableRegisters;
__ sub(esp, Immediate(kDoubleRegsSize));
for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) {
for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) {
XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i);
int offset = i * kDoubleSize;
__ movsd(Operand(esp, offset), xmm_reg);
@ -290,7 +290,7 @@ void Deoptimizer::EntryGenerator::Generate() {
int double_regs_offset = FrameDescription::double_registers_offset();
// Fill in the double input registers.
for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) {
for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) {
int dst_offset = i * kDoubleSize + double_regs_offset;
int src_offset = i * kDoubleSize;
__ movsd(xmm0, Operand(esp, src_offset));
@ -373,7 +373,7 @@ void Deoptimizer::EntryGenerator::Generate() {
__ j(below, &outer_push_loop);
// In case of a failed STUB, we have to restore the XMM registers.
for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) {
for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) {
XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i);
int src_offset = i * kDoubleSize + double_regs_offset;
__ movsd(xmm_reg, Operand(ebx, src_offset));

View File

@ -971,10 +971,11 @@ void MacroAssembler::EnterExitFramePrologue() {
void MacroAssembler::EnterExitFrameEpilogue(int argc, bool save_doubles) {
// Optionally save all XMM registers.
if (save_doubles) {
int space = XMMRegister::kNumRegisters * kDoubleSize + argc * kPointerSize;
int space = XMMRegister::kMaxNumRegisters * kDoubleSize +
argc * kPointerSize;
sub(esp, Immediate(space));
const int offset = -2 * kPointerSize;
for (int i = 0; i < XMMRegister::kNumRegisters; i++) {
for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) {
XMMRegister reg = XMMRegister::from_code(i);
movsd(Operand(ebp, offset - ((i + 1) * kDoubleSize)), reg);
}
@ -1017,7 +1018,7 @@ void MacroAssembler::LeaveExitFrame(bool save_doubles) {
// Optionally restore all XMM registers.
if (save_doubles) {
const int offset = -2 * kPointerSize;
for (int i = 0; i < XMMRegister::kNumRegisters; i++) {
for (int i = 0; i < XMMRegister::kMaxNumRegisters; i++) {
XMMRegister reg = XMMRegister::from_code(i);
movsd(reg, Operand(ebp, offset - ((i + 1) * kDoubleSize)));
}