[arm] Avoid unaligned access fault in Int32x4/Float32x4::value().

R=zra@google.com

Review-Url: https://codereview.chromium.org/2947783002 .
This commit is contained in:
Ryan Macnak 2017-06-21 09:10:58 -07:00
parent 095ff155fd
commit dddd96cfd2
6 changed files with 36 additions and 20 deletions

View file

@ -663,6 +663,8 @@ inline D bit_copy(const S& source) {
}
#if defined(HOST_ARCH_ARM) || defined(HOST_ARCH_MIPS) || \
defined(HOST_ARCH_ARM64)
// Similar to bit_copy and bit_cast, but does take the type from the argument.
template <typename T>
static inline T ReadUnaligned(const T* ptr) {
@ -672,6 +674,27 @@ static inline T ReadUnaligned(const T* ptr) {
}
// Similar to bit_copy and bit_cast, but does take the type from the argument.
template <typename T>
static inline void StoreUnaligned(T* ptr, T value) {
memcpy(ptr, &value, sizeof(value));
}
#else // !(HOST_ARCH_ARM || HOST_ARCH_MIPS || HOST_ARCH_ARM64)
// Similar to bit_copy and bit_cast, but does take the type from the argument.
template <typename T>
static inline T ReadUnaligned(const T* ptr) {
return *ptr;
}
// Similar to bit_copy and bit_cast, but does take the type from the argument.
template <typename T>
static inline void StoreUnaligned(T* ptr, T value) {
*ptr = value;
}
#endif // !(HOST_ARCH_ARM || HOST_ARCH_MIPS || HOST_ARCH_ARM64)
// On Windows the reentrent version of strtok is called
// strtok_s. Unify on the posix name strtok_r.
#if defined(HOST_OS_WINDOWS)

View file

@ -22379,12 +22379,14 @@ RawFloat32x4* Float32x4::New(simd128_value_t value, Heap::Space space) {
simd128_value_t Float32x4::value() const {
return simd128_value_t().readFrom(&raw_ptr()->value_[0]);
return ReadUnaligned(
reinterpret_cast<const simd128_value_t*>(&raw_ptr()->value_));
}
void Float32x4::set_value(simd128_value_t value) const {
StoreSimd128(&raw_ptr()->value_[0], value);
StoreUnaligned(reinterpret_cast<simd128_value_t*>(&raw()->ptr()->value_),
value);
}
@ -22514,12 +22516,14 @@ int32_t Int32x4::w() const {
simd128_value_t Int32x4::value() const {
return simd128_value_t().readFrom(&raw_ptr()->value_[0]);
return ReadUnaligned(
reinterpret_cast<const simd128_value_t*>(&raw_ptr()->value_));
}
void Int32x4::set_value(simd128_value_t value) const {
StoreSimd128(&raw_ptr()->value_[0], value);
StoreUnaligned(reinterpret_cast<simd128_value_t*>(&raw()->ptr()->value_),
value);
}

View file

@ -7963,29 +7963,15 @@ class TypedData : public Instance {
virtual bool CanonicalizeEquals(const Instance& other) const;
virtual uword ComputeCanonicalTableHash() const;
#if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
#define TYPED_GETTER_SETTER(name, type) \
type Get##name(intptr_t byte_offset) const { \
NoSafepointScope no_safepoint; \
return *reinterpret_cast<type*>(DataAddr(byte_offset)); \
return ReadUnaligned(reinterpret_cast<type*>(DataAddr(byte_offset))); \
} \
void Set##name(intptr_t byte_offset, type value) const { \
NoSafepointScope no_safepoint; \
*reinterpret_cast<type*>(DataAddr(byte_offset)) = value; \
StoreUnaligned(reinterpret_cast<type*>(DataAddr(byte_offset)), value); \
}
#else // defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
#define TYPED_GETTER_SETTER(name, type) \
type Get##name(intptr_t byte_offset) const { \
NoSafepointScope no_safepoint; \
type result; \
memmove(&result, DataAddr(byte_offset), sizeof(type)); \
return result; \
} \
void Set##name(intptr_t byte_offset, type value) const { \
NoSafepointScope no_safepoint; \
memmove(DataAddr(byte_offset), &value, sizeof(type)); \
}
#endif // defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
TYPED_GETTER_SETTER(Int8, int8_t)
TYPED_GETTER_SETTER(Uint8, uint8_t)

View file

@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--max_deoptimization_counter_threshold=1000 --optimization-counter-threshold=10 --no-background-compilation
// VMOptions=--no-intrinsify
// Library tag to be able to run in html test framework.
library float32x4_test;

View file

@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--max_deoptimization_counter_threshold=1000 --optimization-counter-threshold=10 --no-background-compilation
// VMOptions=--no-intrinsify
library float64x2_functional_test;

View file

@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--max_deoptimization_counter_threshold=1000 --optimization-counter-threshold=10 --no-background-compilation
// VMOptions=--no-intrinsify
library int32x4_test;