Revert "Do away with variable length memcpy to Set/Get registers in simulator"

This reverts r21148, it broke tests in debug mode, e.g.
mjsunit/regress/regress-observe-map-cache or mjsunit/debug-stepout-scope-part5.

TBR=bmeurer@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21449 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e61b69f5
This diff is collapsed.
...@@ -133,28 +133,35 @@ class SimSystemRegister { ...@@ -133,28 +133,35 @@ class SimSystemRegister {
// Represent a register (r0-r31, v0-v31). // Represent a register (r0-r31, v0-v31).
template<int kSizeInBytes>
class SimRegisterBase { class SimRegisterBase {
public: public:
template<typename T> template<typename T>
void Set(T new_value) { void Set(T new_value, unsigned size = sizeof(T)) {
value_ = 0; ASSERT(size <= kSizeInBytes);
memcpy(&value_, &new_value, sizeof(T)); ASSERT(size <= sizeof(new_value));
// All AArch64 registers are zero-extending; Writing a W register clears the
// top bits of the corresponding X register.
memset(value_, 0, kSizeInBytes);
memcpy(value_, &new_value, size);
} }
// Copy 'size' bytes of the register to the result, and zero-extend to fill
// the result.
template<typename T> template<typename T>
T Get() const { T Get(unsigned size = sizeof(T)) const {
ASSERT(size <= kSizeInBytes);
T result; T result;
memcpy(&result, &value_, sizeof(T)); memset(&result, 0, sizeof(result));
memcpy(&result, value_, size);
return result; return result;
} }
protected: protected:
int64_t value_; uint8_t value_[kSizeInBytes];
}; };
typedef SimRegisterBase<kXRegSize> SimRegister; // r0-r31
typedef SimRegisterBase<kDRegSize> SimFPRegister; // v0-v31
typedef SimRegisterBase SimRegister; // r0-r31
typedef SimRegisterBase SimFPRegister; // v0-v31
class Simulator : public DecoderVisitor { class Simulator : public DecoderVisitor {
...@@ -321,53 +328,86 @@ class Simulator : public DecoderVisitor { ...@@ -321,53 +328,86 @@ class Simulator : public DecoderVisitor {
VISITOR_LIST(DECLARE) VISITOR_LIST(DECLARE)
#undef DECLARE #undef DECLARE
bool IsZeroRegister(unsigned code, Reg31Mode r31mode) const {
return ((code == 31) && (r31mode == Reg31IsZeroRegister));
}
// Register accessors. // Register accessors.
// Return 'size' bits of the value of an integer register, as the specified // Return 'size' bits of the value of an integer register, as the specified
// type. The value is zero-extended to fill the result. // type. The value is zero-extended to fill the result.
// //
// The only supported values of 'size' are kXRegSizeInBits and
// kWRegSizeInBits.
template<typename T> template<typename T>
T reg(unsigned code, Reg31Mode r31mode = Reg31IsZeroRegister) const { T reg(unsigned size, unsigned code,
Reg31Mode r31mode = Reg31IsZeroRegister) const {
unsigned size_in_bytes = size / 8;
ASSERT(size_in_bytes <= sizeof(T));
ASSERT((size == kXRegSizeInBits) || (size == kWRegSizeInBits));
ASSERT(code < kNumberOfRegisters); ASSERT(code < kNumberOfRegisters);
if (IsZeroRegister(code, r31mode)) {
return 0; if ((code == 31) && (r31mode == Reg31IsZeroRegister)) {
T result;
memset(&result, 0, sizeof(result));
return result;
} }
return registers_[code].Get<T>(); return registers_[code].Get<T>(size_in_bytes);
}
// Like reg(), but infer the access size from the template type.
template<typename T>
T reg(unsigned code, Reg31Mode r31mode = Reg31IsZeroRegister) const {
return reg<T>(sizeof(T) * 8, code, r31mode);
} }
// Common specialized accessors for the reg() template. // Common specialized accessors for the reg() template.
int32_t wreg(unsigned code, Reg31Mode r31mode = Reg31IsZeroRegister) const { int32_t wreg(unsigned code,
Reg31Mode r31mode = Reg31IsZeroRegister) const {
return reg<int32_t>(code, r31mode); return reg<int32_t>(code, r31mode);
} }
int64_t xreg(unsigned code, Reg31Mode r31mode = Reg31IsZeroRegister) const { int64_t xreg(unsigned code,
Reg31Mode r31mode = Reg31IsZeroRegister) const {
return reg<int64_t>(code, r31mode); return reg<int64_t>(code, r31mode);
} }
int64_t reg(unsigned size, unsigned code,
Reg31Mode r31mode = Reg31IsZeroRegister) const {
return reg<int64_t>(size, code, r31mode);
}
// Write 'size' bits of 'value' into an integer register. The value is // Write 'size' bits of 'value' into an integer register. The value is
// zero-extended. This behaviour matches AArch64 register writes. // zero-extended. This behaviour matches AArch64 register writes.
//
// The only supported values of 'size' are kXRegSizeInBits and
// kWRegSizeInBits.
template<typename T>
void set_reg(unsigned size, unsigned code, T value,
Reg31Mode r31mode = Reg31IsZeroRegister) {
unsigned size_in_bytes = size / 8;
ASSERT(size_in_bytes <= sizeof(T));
ASSERT((size == kXRegSizeInBits) || (size == kWRegSizeInBits));
ASSERT(code < kNumberOfRegisters);
if ((code == 31) && (r31mode == Reg31IsZeroRegister)) {
return;
}
return registers_[code].Set(value, size_in_bytes);
}
// Like set_reg(), but infer the access size from the template type. // Like set_reg(), but infer the access size from the template type.
template<typename T> template<typename T>
void set_reg(unsigned code, T value, void set_reg(unsigned code, T value,
Reg31Mode r31mode = Reg31IsZeroRegister) { Reg31Mode r31mode = Reg31IsZeroRegister) {
ASSERT(code < kNumberOfRegisters); set_reg(sizeof(value) * 8, code, value, r31mode);
if (!IsZeroRegister(code, r31mode))
registers_[code].Set(value);
} }
// Common specialized accessors for the set_reg() template. // Common specialized accessors for the set_reg() template.
void set_wreg(unsigned code, int32_t value, void set_wreg(unsigned code, int32_t value,
Reg31Mode r31mode = Reg31IsZeroRegister) { Reg31Mode r31mode = Reg31IsZeroRegister) {
set_reg(code, value, r31mode); set_reg(kWRegSizeInBits, code, value, r31mode);
} }
void set_xreg(unsigned code, int64_t value, void set_xreg(unsigned code, int64_t value,
Reg31Mode r31mode = Reg31IsZeroRegister) { Reg31Mode r31mode = Reg31IsZeroRegister) {
set_reg(code, value, r31mode); set_reg(kXRegSizeInBits, code, value, r31mode);
} }
// Commonly-used special cases. // Commonly-used special cases.
...@@ -392,10 +432,24 @@ class Simulator : public DecoderVisitor { ...@@ -392,10 +432,24 @@ class Simulator : public DecoderVisitor {
Address get_sp() { return reg<Address>(31, Reg31IsStackPointer); } Address get_sp() { return reg<Address>(31, Reg31IsStackPointer); }
// Return 'size' bits of the value of a floating-point register, as the
// specified type. The value is zero-extended to fill the result.
//
// The only supported values of 'size' are kDRegSizeInBits and
// kSRegSizeInBits.
template<typename T>
T fpreg(unsigned size, unsigned code) const {
unsigned size_in_bytes = size / 8;
ASSERT(size_in_bytes <= sizeof(T));
ASSERT((size == kDRegSizeInBits) || (size == kSRegSizeInBits));
ASSERT(code < kNumberOfFPRegisters);
return fpregisters_[code].Get<T>(size_in_bytes);
}
// Like fpreg(), but infer the access size from the template type.
template<typename T> template<typename T>
T fpreg(unsigned code) const { T fpreg(unsigned code) const {
ASSERT(code < kNumberOfRegisters); return fpreg<T>(sizeof(T) * 8, code);
return fpregisters_[code].Get<T>();
} }
// Common specialized accessors for the fpreg() template. // Common specialized accessors for the fpreg() template.
...@@ -431,7 +485,7 @@ class Simulator : public DecoderVisitor { ...@@ -431,7 +485,7 @@ class Simulator : public DecoderVisitor {
void set_fpreg(unsigned code, T value) { void set_fpreg(unsigned code, T value) {
ASSERT((sizeof(value) == kDRegSize) || (sizeof(value) == kSRegSize)); ASSERT((sizeof(value) == kDRegSize) || (sizeof(value) == kSRegSize));
ASSERT(code < kNumberOfFPRegisters); ASSERT(code < kNumberOfFPRegisters);
fpregisters_[code].Set(value); fpregisters_[code].Set(value, sizeof(value));
} }
// Common specialized accessors for the set_fpreg() template. // Common specialized accessors for the set_fpreg() template.
...@@ -571,19 +625,14 @@ class Simulator : public DecoderVisitor { ...@@ -571,19 +625,14 @@ class Simulator : public DecoderVisitor {
return !ConditionPassed(cond); return !ConditionPassed(cond);
} }
template<typename T> void AddSubHelper(Instruction* instr, int64_t op2);
void AddSubHelper(Instruction* instr, T op2); int64_t AddWithCarry(unsigned reg_size,
template<typename T> bool set_flags,
T AddWithCarry(bool set_flags, int64_t src1,
T src1, int64_t src2,
T src2, int64_t carry_in = 0);
T carry_in = 0); void LogicalHelper(Instruction* instr, int64_t op2);
template<typename T> void ConditionalCompareHelper(Instruction* instr, int64_t op2);
void AddSubWithCarry(Instruction* instr);
template<typename T>
void LogicalHelper(Instruction* instr, T op2);
template<typename T>
void ConditionalCompareHelper(Instruction* instr, T op2);
void LoadStoreHelper(Instruction* instr, void LoadStoreHelper(Instruction* instr,
int64_t offset, int64_t offset,
AddrMode addrmode); AddrMode addrmode);
...@@ -610,21 +659,18 @@ class Simulator : public DecoderVisitor { ...@@ -610,21 +659,18 @@ class Simulator : public DecoderVisitor {
void MemoryWrite64(uint8_t* address, uint64_t value); void MemoryWrite64(uint8_t* address, uint64_t value);
void MemoryWriteFP64(uint8_t* address, double value); void MemoryWriteFP64(uint8_t* address, double value);
int64_t ShiftOperand(unsigned reg_size,
template <typename T> int64_t value,
T ShiftOperand(T value, Shift shift_type,
unsigned amount);
int64_t Rotate(unsigned reg_width,
int64_t value,
Shift shift_type, Shift shift_type,
unsigned amount); unsigned amount);
template <typename T> int64_t ExtendValue(unsigned reg_width,
T ExtendValue(T value, int64_t value,
Extend extend_type, Extend extend_type,
unsigned left_shift = 0); unsigned left_shift = 0);
template <typename T>
void Extract(Instruction* instr);
template <typename T>
void DataProcessing2Source(Instruction* instr);
template <typename T>
void BitfieldHelper(Instruction* instr);
uint64_t ReverseBits(uint64_t value, unsigned num_bits); uint64_t ReverseBits(uint64_t value, unsigned num_bits);
uint64_t ReverseBytes(uint64_t value, ReverseByteMode mode); uint64_t ReverseBytes(uint64_t value, ReverseByteMode mode);
...@@ -750,9 +796,8 @@ class Simulator : public DecoderVisitor { ...@@ -750,9 +796,8 @@ class Simulator : public DecoderVisitor {
// is irrelevant, and is not checked here. // is irrelevant, and is not checked here.
} }
template <typename T> static int CalcNFlag(uint64_t result, unsigned reg_size) {
static int CalcNFlag(T result) { return (result >> (reg_size - 1)) & 1;
return (result >> (sizeof(T) * 8 - 1)) & 1;
} }
static int CalcZFlag(uint64_t result) { static int CalcZFlag(uint64_t result) {
......
...@@ -233,25 +233,6 @@ inline int32_t WhichPowerOf2Abs(int32_t x) { ...@@ -233,25 +233,6 @@ inline int32_t WhichPowerOf2Abs(int32_t x) {
} }
// Obtains the unsigned type corresponding to T
// available in C++11 as std::make_unsigned
template<typename T>
struct make_unsigned {
typedef T type;
};
// Template specializations necessary to have make_unsigned work
template<> struct make_unsigned<int32_t> {
typedef uint32_t type;
};
template<> struct make_unsigned<int64_t> {
typedef uint64_t type;
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// BitField is a help template for encoding and decode bitfield with // BitField is a help template for encoding and decode bitfield with
// unsigned content. // unsigned content.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment