зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1409295 part 5 - Use memcpy on little endian platforms. r=luke
--HG-- extra : rebase_source : 2e2bd1267a7d84d8458d6ec7cafef795ee5b6295
This commit is contained in:
Родитель
890dd39ca8
Коммит
228ba6907b
|
@ -12,6 +12,7 @@
|
|||
*/
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/EndianUtils.h"
|
||||
|
||||
#include "jsbytecode.h"
|
||||
#include "jstypes.h"
|
||||
|
@ -136,14 +137,24 @@ UINT16_LO(uint16_t i)
|
|||
static MOZ_ALWAYS_INLINE uint16_t
|
||||
GET_UINT16(const jsbytecode* pc)
|
||||
{
|
||||
#if MOZ_LITTLE_ENDIAN
|
||||
uint16_t result;
|
||||
memcpy(&result, pc + 1, sizeof(result));
|
||||
return result;
|
||||
#else
|
||||
return uint16_t((pc[2] << 8) | pc[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
static MOZ_ALWAYS_INLINE void
|
||||
SET_UINT16(jsbytecode* pc, uint16_t i)
|
||||
{
|
||||
#if MOZ_LITTLE_ENDIAN
|
||||
memcpy(pc + 1, &i, sizeof(i));
|
||||
#else
|
||||
pc[1] = UINT16_LO(i);
|
||||
pc[2] = UINT16_HI(i);
|
||||
#endif
|
||||
}
|
||||
|
||||
static const unsigned UINT16_LIMIT = 1 << 16;
|
||||
|
@ -153,19 +164,32 @@ static const unsigned JUMP_OFFSET_LEN = 4;
|
|||
static const int32_t JUMP_OFFSET_MIN = INT32_MIN;
|
||||
static const int32_t JUMP_OFFSET_MAX = INT32_MAX;
|
||||
|
||||
static MOZ_ALWAYS_INLINE unsigned
|
||||
static MOZ_ALWAYS_INLINE uint32_t
|
||||
GET_UINT24(const jsbytecode* pc)
|
||||
{
|
||||
#if MOZ_LITTLE_ENDIAN
|
||||
// Do a single 32-bit load (for opcode and operand), then shift off the
|
||||
// opcode.
|
||||
uint32_t result;
|
||||
memcpy(&result, pc, 4);
|
||||
return result >> 8;
|
||||
#else
|
||||
return unsigned((pc[3] << 16) | (pc[2] << 8) | pc[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
static MOZ_ALWAYS_INLINE void
|
||||
SET_UINT24(jsbytecode* pc, unsigned i)
|
||||
SET_UINT24(jsbytecode* pc, uint32_t i)
|
||||
{
|
||||
MOZ_ASSERT(i < (1 << 24));
|
||||
|
||||
#if MOZ_LITTLE_ENDIAN
|
||||
memcpy(pc + 1, &i, 3);
|
||||
#else
|
||||
pc[1] = jsbytecode(i);
|
||||
pc[2] = jsbytecode(i >> 8);
|
||||
pc[3] = jsbytecode(i >> 16);
|
||||
#endif
|
||||
}
|
||||
|
||||
static MOZ_ALWAYS_INLINE int8_t
|
||||
|
@ -177,19 +201,29 @@ GET_INT8(const jsbytecode* pc)
|
|||
static MOZ_ALWAYS_INLINE uint32_t
|
||||
GET_UINT32(const jsbytecode* pc)
|
||||
{
|
||||
#if MOZ_LITTLE_ENDIAN
|
||||
uint32_t result;
|
||||
memcpy(&result, pc + 1, sizeof(result));
|
||||
return result;
|
||||
#else
|
||||
return (uint32_t(pc[4]) << 24) |
|
||||
(uint32_t(pc[3]) << 16) |
|
||||
(uint32_t(pc[2]) << 8) |
|
||||
uint32_t(pc[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
static MOZ_ALWAYS_INLINE void
|
||||
SET_UINT32(jsbytecode* pc, uint32_t u)
|
||||
{
|
||||
#if MOZ_LITTLE_ENDIAN
|
||||
memcpy(pc + 1, &u, sizeof(u));
|
||||
#else
|
||||
pc[1] = jsbytecode(u);
|
||||
pc[2] = jsbytecode(u >> 8);
|
||||
pc[3] = jsbytecode(u >> 16);
|
||||
pc[4] = jsbytecode(u >> 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
static MOZ_ALWAYS_INLINE int32_t
|
||||
|
|
Загрузка…
Ссылка в новой задаче