Commit 0acc511e authored by balazs.kilvady's avatar balazs.kilvady Committed by Commit bot

MIPS: Fix unaligned memory access.

On MIPS32 we can't read a 8 bytes long data from a not 8 bytes aligned memory address.

BUG=
TEST=mjsunit/debug-backtrace

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

Cr-Commit-Position: refs/heads/master@{#29100}
parent 91d869a3
...@@ -2966,7 +2966,7 @@ TranslatedValue TranslatedState::CreateNextTranslatedValue( ...@@ -2966,7 +2966,7 @@ TranslatedValue TranslatedState::CreateNextTranslatedValue(
case Translation::DOUBLE_STACK_SLOT: { case Translation::DOUBLE_STACK_SLOT: {
int slot_offset = SlotOffsetFp(iterator->Next()); int slot_offset = SlotOffsetFp(iterator->Next());
double value = *(reinterpret_cast<double*>(fp + slot_offset)); double value = ReadDoubleValue(fp + slot_offset);
if (trace_file != nullptr) { if (trace_file != nullptr) {
PrintF(trace_file, "%e ; (double) [fp %c %d] ", value, PrintF(trace_file, "%e ; (double) [fp %c %d] ", value,
slot_offset < 0 ? '-' : '+', std::abs(slot_offset)); slot_offset < 0 ? '-' : '+', std::abs(slot_offset));
......
...@@ -1245,46 +1245,11 @@ MaybeHandle<Object> Object::GetProperty(Isolate* isolate, ...@@ -1245,46 +1245,11 @@ MaybeHandle<Object> Object::GetProperty(Isolate* isolate,
} \ } \
} }
#ifndef V8_TARGET_ARCH_MIPS #define READ_DOUBLE_FIELD(p, offset) \
#define READ_DOUBLE_FIELD(p, offset) \ ReadDoubleValue(FIELD_ADDR_CONST(p, offset))
(*reinterpret_cast<const double*>(FIELD_ADDR_CONST(p, offset)))
#else // V8_TARGET_ARCH_MIPS
// Prevent gcc from using load-double (mips ldc1) on (possibly)
// non-64-bit aligned HeapNumber::value.
static inline double read_double_field(const void* p, int offset) {
union conversion {
double d;
uint32_t u[2];
} c;
c.u[0] = (*reinterpret_cast<const uint32_t*>(
FIELD_ADDR_CONST(p, offset)));
c.u[1] = (*reinterpret_cast<const uint32_t*>(
FIELD_ADDR_CONST(p, offset + 4)));
return c.d;
}
#define READ_DOUBLE_FIELD(p, offset) read_double_field(p, offset)
#endif // V8_TARGET_ARCH_MIPS
#ifndef V8_TARGET_ARCH_MIPS
#define WRITE_DOUBLE_FIELD(p, offset, value) \
(*reinterpret_cast<double*>(FIELD_ADDR(p, offset)) = value)
#else // V8_TARGET_ARCH_MIPS
// Prevent gcc from using store-double (mips sdc1) on (possibly)
// non-64-bit aligned HeapNumber::value.
static inline void write_double_field(void* p, int offset,
double value) {
union conversion {
double d;
uint32_t u[2];
} c;
c.d = value;
(*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset))) = c.u[0];
(*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset + 4))) = c.u[1];
}
#define WRITE_DOUBLE_FIELD(p, offset, value) \
write_double_field(p, offset, value)
#endif // V8_TARGET_ARCH_MIPS
#define WRITE_DOUBLE_FIELD(p, offset, value) \
WriteDoubleValue(FIELD_ADDR(p, offset), value)
#define READ_INT_FIELD(p, offset) \ #define READ_INT_FIELD(p, offset) \
(*reinterpret_cast<const int*>(FIELD_ADDR_CONST(p, offset))) (*reinterpret_cast<const int*>(FIELD_ADDR_CONST(p, offset)))
......
...@@ -1708,6 +1708,41 @@ inline uintptr_t GetCurrentStackPosition() { ...@@ -1708,6 +1708,41 @@ inline uintptr_t GetCurrentStackPosition() {
return limit; return limit;
} }
static inline double ReadDoubleValue(const void* p) {
#ifndef V8_TARGET_ARCH_MIPS
return *reinterpret_cast<const double*>(p);
#else // V8_TARGET_ARCH_MIPS
// Prevent compiler from using load-double (mips ldc1) on (possibly)
// non-64-bit aligned address.
union conversion {
double d;
uint32_t u[2];
} c;
const uint32_t* ptr = reinterpret_cast<const uint32_t*>(p);
c.u[0] = *ptr;
c.u[1] = *(ptr + 1);
return c.d;
#endif // V8_TARGET_ARCH_MIPS
}
static inline void WriteDoubleValue(void* p, double value) {
#ifndef V8_TARGET_ARCH_MIPS
*(reinterpret_cast<double*>(p)) = value;
#else // V8_TARGET_ARCH_MIPS
// Prevent compiler from using load-double (mips sdc1) on (possibly)
// non-64-bit aligned address.
union conversion {
double d;
uint32_t u[2];
} c;
c.d = value;
uint32_t* ptr = reinterpret_cast<uint32_t*>(p);
*ptr = c.u[0];
*(ptr + 1) = c.u[1];
#endif // V8_TARGET_ARCH_MIPS
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
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