fix unaligned 64bit access on MCU (#192)

This commit is contained in:
Xu Jun 2020-03-10 11:48:28 +08:00 committed by GitHub
parent 180ee4c78a
commit 381859d530
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -534,13 +534,16 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
#if WASM_CPU_SUPPORTS_UNALIGNED_64BIT_ACCESS != 0
#define DEF_OP_NUMERIC_64 DEF_OP_NUMERIC
#else
#define DEF_OP_NUMERIC_64(src_type1, src_type2, src_op_type, operation) do {\
src_type1 val1; \
src_type2 val2; \
val1 = (src_type1)GET_##src_op_type##_FROM_ADDR(frame_ip + 2); \
val2 = (src_type2)GET_##src_op_type##_FROM_ADDR(frame_ip); \
val1 operation##= val2; \
PUT_##src_op_type##_TO_ADDR(frame_ip + 4, val1); \
#define DEF_OP_NUMERIC_64(src_type1, src_type2, src_op_type, operation) do { \
src_type1 val1; \
src_type2 val2; \
val1 = \
(src_type1)GET_##src_op_type##_FROM_ADDR(frame_lp + (*(int16*)(frame_ip + 2))); \
val2 = \
(src_type2)GET_##src_op_type##_FROM_ADDR(frame_lp + (*(int16*)(frame_ip))); \
val1 operation##= val2; \
PUT_##src_op_type##_TO_ADDR(frame_lp + (*(int16*)(frame_ip + 4)), val1); \
frame_ip += 6; \
} while (0)
#endif

View File

@ -3054,7 +3054,8 @@ wasm_loader_get_const_offset(WASMLoaderContext *ctx, uint8 type,
}
c->slot_index = operand_offset;
ctx->num_const ++;
LOG_OP("#### new const [%d]: %ld\n", num_const, (int64)val);
LOG_OP("#### new const [%d]: %ld\n",
ctx->num_const, (int64)c->value.i64);
}
/* use negetive index for const */
operand_offset = -(operand_offset + 1);
@ -4300,7 +4301,8 @@ handle_next_reachable_block:
#if WASM_ENABLE_FAST_INTERP != 0
skip_label();
disable_emit = true;
f64 = *(float64 *)p_org;
/* Some MCU may require 8-byte align */
memcpy((uint8*)&f64, p_org, sizeof(float64));
GET_CONST_F64_OFFSET(VALUE_TYPE_F64, f64);
#endif
PUSH_F64();