OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1779 uint16_t h; | 1779 uint16_t h; |
1780 uint8_t b[2]; | 1780 uint8_t b[2]; |
1781 } c; | 1781 } c; |
1782 c.h = value; | 1782 c.h = value; |
1783 uint8_t* ptr = reinterpret_cast<uint8_t*>(p); | 1783 uint8_t* ptr = reinterpret_cast<uint8_t*>(p); |
1784 *ptr = c.b[0]; | 1784 *ptr = c.b[0]; |
1785 *(ptr + 1) = c.b[1]; | 1785 *(ptr + 1) = c.b[1]; |
1786 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 | 1786 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 |
1787 } | 1787 } |
1788 | 1788 |
1789 | |
1790 static inline void WriteUnalignedUInt32(void* p, uint32_t value) { | |
titzer
2016/01/19 16:00:55
Would it be enough to just do a memmove(p, &value,
ivica.bogosavljevic
2016/01/20 10:32:57
I would like to point out that the MIPS specific c
akos.palfi.imgtec
2016/01/21 21:00:22
Thanks, great idea. I've removed the unions and ha
akos.palfi.imgtec
2016/01/21 21:07:35
I think other archs support unaligned fixups in ha
| |
1791 #if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64) | |
1792 *(reinterpret_cast<uint32_t*>(p)) = value; | |
1793 #else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 | |
1794 // Prevent compiler from using store-half (mips sh) on (possibly) | |
1795 // non-16-bit aligned address. | |
1796 union conversion { | |
1797 uint32_t h; | |
1798 uint8_t b[4]; | |
1799 } c; | |
1800 c.h = value; | |
1801 uint8_t* ptr = reinterpret_cast<uint8_t*>(p); | |
1802 *ptr = c.b[0]; | |
1803 *(ptr + 1) = c.b[1]; | |
1804 *(ptr + 2) = c.b[2]; | |
1805 *(ptr + 3) = c.b[3]; | |
1806 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 | |
1807 } | |
1808 | |
1809 | |
1810 template <typename V> | |
1811 static inline V ReadUnalignedValue(const void* p) { | |
1812 #if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64) | |
1813 return *reinterpret_cast<const V*>(p); | |
1814 #else | |
1815 union conversion { | |
1816 V d; | |
1817 uint8_t u[sizeof(V)]; | |
1818 } c; | |
1819 const uint8_t* ptr = reinterpret_cast<const uint8_t*>(p); | |
1820 for (int i = 0; i < sizeof(V); i++) { | |
1821 c.u[i] = *(ptr + i); | |
1822 } | |
1823 return c.d; | |
1824 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 | |
1825 } | |
1826 | |
1827 | |
1789 } // namespace internal | 1828 } // namespace internal |
1790 } // namespace v8 | 1829 } // namespace v8 |
1791 | 1830 |
1792 #endif // V8_UTILS_H_ | 1831 #endif // V8_UTILS_H_ |
OLD | NEW |