Reviewers: jochen, Rodolph Perfetta (ARM),
Message:
PTAL. Is this safe to replace memcpy? This speeds up the simulator by ~20%:
Richards: 51.5 (before)
Richards: 63.9 (after)
Description:
A64: Replace memcpy with reinterpret_cast assignment in simulator and
decoder.
BUG=
Please review this at https://codereview.chromium.org/169223004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+30, -12 lines):
M src/a64/instructions-a64.h
M src/a64/simulator-a64.h
M src/a64/simulator-a64.cc
Index: src/a64/instructions-a64.h
diff --git a/src/a64/instructions-a64.h b/src/a64/instructions-a64.h
index
472d4bf9fd76d367c0200f4d0b1156546f0ca34e..1d19e68a4984204b1138f719550d5e6526a6d8ea
100644
--- a/src/a64/instructions-a64.h
+++ b/src/a64/instructions-a64.h
@@ -116,13 +116,11 @@ enum Reg31Mode {
class Instruction {
public:
Instr InstructionBits() const {
- Instr bits;
- memcpy(&bits, this, sizeof(bits));
- return bits;
+ return *reinterpret_cast<Instr*>(const_cast<Instruction*>(this));
}
void SetInstructionBits(Instr new_instr) {
- memcpy(this, &new_instr, sizeof(new_instr));
+ *reinterpret_cast<Instr*>(this) = new_instr;
}
int Bit(int pos) const {
@@ -367,15 +365,15 @@ class Instruction {
uint32_t Literal32() {
uint32_t literal;
- memcpy(&literal, LiteralAddress(), sizeof(literal));
-
+ uint32_t* buffer = &literal;
+ *buffer = *reinterpret_cast<uint32_t*>(LiteralAddress());
return literal;
}
uint64_t Literal64() {
uint64_t literal;
- memcpy(&literal, LiteralAddress(), sizeof(literal));
-
+ uint64_t* buffer = &literal;
+ *buffer = *reinterpret_cast<uint64_t*>(LiteralAddress());
return literal;
}
Index: src/a64/simulator-a64.cc
diff --git a/src/a64/simulator-a64.cc b/src/a64/simulator-a64.cc
index
e0a0d62a02a695128f50cbc2821c2c776e89401e..f015603ae964fdeedcd16def8f69eddfdf642a1f
100644
--- a/src/a64/simulator-a64.cc
+++ b/src/a64/simulator-a64.cc
@@ -139,7 +139,7 @@ void Simulator::CallVoid(byte* entry, CallArgument*
args) {
char * stack = reinterpret_cast<char*>(entry_stack);
std::vector<int64_t>::const_iterator it;
for (it = stack_args.begin(); it != stack_args.end(); it++) {
- memcpy(stack, &(*it), sizeof(*it));
+ *reinterpret_cast<int64_t*>(stack) = *it;
stack += sizeof(*it);
}
@@ -1469,7 +1469,17 @@ uint64_t Simulator::MemoryRead(uint8_t* address,
unsigned num_bytes) {
ASSERT(address != NULL);
ASSERT((num_bytes > 0) && (num_bytes <= sizeof(uint64_t)));
uint64_t read = 0;
- memcpy(&read, address, num_bytes);
+ if (num_bytes == 8) {
+ read = *reinterpret_cast<uint64_t*>(address);
+ } else if (num_bytes == 4) {
+ read = *reinterpret_cast<uint32_t*>(address);
+ } else if (num_bytes == 2) {
+ read = *reinterpret_cast<uint16_t*>(address);
+ } else if (num_bytes == 1) {
+ read = *reinterpret_cast<uint8_t*>(address);
+ } else {
+ UNREACHABLE();
+ }
return read;
}
@@ -1511,7 +1521,17 @@ void Simulator::MemoryWrite(uint8_t* address,
ASSERT((num_bytes > 0) && (num_bytes <= sizeof(uint64_t)));
LogWrite(address, value, num_bytes);
- memcpy(address, &value, num_bytes);
+ if (num_bytes == 8) {
+ *reinterpret_cast<uint64_t*>(address) = static_cast<uint64_t>(value);
+ } else if (num_bytes == 4) {
+ *reinterpret_cast<uint32_t*>(address) = static_cast<uint32_t>(value);
+ } else if (num_bytes == 2) {
+ *reinterpret_cast<uint16_t*>(address) = static_cast<uint16_t>(value);
+ } else if (num_bytes == 1) {
+ *reinterpret_cast<uint8_t*>(address) = static_cast<uint8_t>(value);
+ } else {
+ UNREACHABLE();
+ }
}
Index: src/a64/simulator-a64.h
diff --git a/src/a64/simulator-a64.h b/src/a64/simulator-a64.h
index
535f287096a317e9ce157b17c033f2184399d0ed..beac0c8f7546694c89f2d2e5a30a89e2ef6283a3
100644
--- a/src/a64/simulator-a64.h
+++ b/src/a64/simulator-a64.h
@@ -321,7 +321,7 @@ class Simulator : public DecoderVisitor {
template <typename T>
void set_pc(T new_pc) {
ASSERT(sizeof(T) == sizeof(pc_));
- memcpy(&pc_, &new_pc, sizeof(T));
+ *reinterpret_cast<T*>(&pc_) = new_pc;
pc_modified_ = true;
}
Instruction* pc() { return pc_; }
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.