Skip to content

Commit bd97970

Browse files
James Marshloganek
authored andcommitted
Fix load/load_splat macros
1 parent 80e6c98 commit bd97970

File tree

2 files changed

+36
-50
lines changed

2 files changed

+36
-50
lines changed

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3604,7 +3604,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
36043604
global_addr = get_global_addr(global_data, global);
36053605
addr_ret = GET_OFFSET();
36063606
PUT_V128_TO_ADDR(frame_lp + addr_ret,
3607-
GET_V128_FROM_ADDR((uint32 *)global_addr));
3607+
GET_V128_FROM_ADDR((uint32 *)global_addr));
36083608
HANDLE_OP_END();
36093609
}
36103610
#endif
@@ -3683,7 +3683,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
36833683
global_addr = get_global_addr(global_data, global);
36843684
addr1 = GET_OFFSET();
36853685
PUT_V128_TO_ADDR((uint32 *)global_addr,
3686-
GET_V128_FROM_ADDR(frame_lp + addr1));
3686+
GET_V128_FROM_ADDR(frame_lp + addr1));
36873687
HANDLE_OP_END();
36883688
}
36893689
#endif
@@ -5843,66 +5843,54 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
58435843
PUT_V128_TO_ADDR(frame_lp + addr_ret, LOAD_V128(maddr));
58445844
break;
58455845
}
5846-
#define SIMD_LOAD_OP(op_name, simde_func, element_size, num_elements) \
5847-
do { \
5848-
uint32 offset, addr; \
5849-
offset = read_uint32(frame_ip); \
5850-
addr = GET_OPERAND(uint32, I32, 0); \
5851-
frame_ip += 2; \
5852-
addr_ret = GET_OFFSET(); \
5853-
CHECK_MEMORY_OVERFLOW(16); \
5854-
\
5855-
simde_v128_t simde_result = simde_func(maddr); \
5856-
\
5857-
V128 result; \
5858-
SIMDE_V128_TO_SIMD_V128(simde_result, result); \
5859-
\
5860-
V128 reversed_result; \
5861-
for (int i = 0; i < num_elements; i++) { \
5862-
reversed_result.i##element_size##x##num_elements[i] = \
5863-
result.i##element_size##x##num_elements[num_elements - 1 - i]; \
5864-
} \
5865-
PUT_V128_TO_ADDR(frame_lp + addr_ret, reversed_result); \
5866-
\
5867-
break; \
5846+
#define SIMD_LOAD_OP(simde_func, element_size, num_elements) \
5847+
do { \
5848+
uint32 offset, addr; \
5849+
offset = read_uint32(frame_ip); \
5850+
addr = GET_OPERAND(uint32, I32, 0); \
5851+
frame_ip += 2; \
5852+
addr_ret = GET_OFFSET(); \
5853+
CHECK_MEMORY_OVERFLOW(4); \
5854+
\
5855+
simde_v128_t simde_result = simde_func(maddr); \
5856+
\
5857+
V128 result; \
5858+
SIMDE_V128_TO_SIMD_V128(simde_result, result); \
5859+
PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \
5860+
\
5861+
break; \
58685862
} while (0)
58695863
case SIMD_v128_load8x8_s:
58705864
{
5871-
SIMD_LOAD_OP(SIMD_v128_load8x8_s,
5872-
simde_wasm_i16x8_load8x8, 16, 8);
5865+
SIMD_LOAD_OP(simde_wasm_i16x8_load8x8, 16, 8);
58735866
break;
58745867
}
58755868
case SIMD_v128_load8x8_u:
58765869
{
5877-
SIMD_LOAD_OP(SIMD_v128_load8x8_u,
5878-
simde_wasm_u16x8_load8x8, 16, 8);
5870+
SIMD_LOAD_OP(simde_wasm_u16x8_load8x8, 16, 8);
58795871
break;
58805872
}
58815873
case SIMD_v128_load16x4_s:
58825874
{
5883-
SIMD_LOAD_OP(SIMD_v128_load16x4_s,
5884-
simde_wasm_i32x4_load16x4, 32, 4);
5875+
SIMD_LOAD_OP(simde_wasm_i32x4_load16x4, 32, 4);
58855876
break;
58865877
}
58875878
case SIMD_v128_load16x4_u:
58885879
{
5889-
SIMD_LOAD_OP(SIMD_v128_load16x4_u,
5890-
simde_wasm_u32x4_load16x4, 32, 4);
5880+
SIMD_LOAD_OP(simde_wasm_u32x4_load16x4, 32, 4);
58915881
break;
58925882
}
58935883
case SIMD_v128_load32x2_s:
58945884
{
5895-
SIMD_LOAD_OP(SIMD_v128_load32x2_s,
5896-
simde_wasm_i64x2_load32x2, 64, 2);
5885+
SIMD_LOAD_OP(simde_wasm_i64x2_load32x2, 64, 2);
58975886
break;
58985887
}
58995888
case SIMD_v128_load32x2_u:
59005889
{
5901-
SIMD_LOAD_OP(SIMD_v128_load32x2_u,
5902-
simde_wasm_u64x2_load32x2, 64, 2);
5890+
SIMD_LOAD_OP(simde_wasm_u64x2_load32x2, 64, 2);
59035891
break;
59045892
}
5905-
#define SIMD_LOAD_SPLAT_OP(op_name, simde_func) \
5893+
#define SIMD_LOAD_SPLAT_OP(simde_func) \
59065894
do { \
59075895
uint32 offset, addr; \
59085896
offset = read_uint32(frame_ip); \
@@ -5921,26 +5909,22 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
59215909

59225910
case SIMD_v128_load8_splat:
59235911
{
5924-
SIMD_LOAD_SPLAT_OP(SIMD_v128_load8_splat,
5925-
simde_wasm_v128_load8_splat);
5912+
SIMD_LOAD_SPLAT_OP(simde_wasm_v128_load8_splat);
59265913
break;
59275914
}
59285915
case SIMD_v128_load16_splat:
59295916
{
5930-
SIMD_LOAD_SPLAT_OP(SIMD_v128_load16_splat,
5931-
simde_wasm_v128_load16_splat);
5917+
SIMD_LOAD_SPLAT_OP(simde_wasm_v128_load16_splat);
59325918
break;
59335919
}
59345920
case SIMD_v128_load32_splat:
59355921
{
5936-
SIMD_LOAD_SPLAT_OP(SIMD_v128_load32_splat,
5937-
simde_wasm_v128_load32_splat);
5922+
SIMD_LOAD_SPLAT_OP(simde_wasm_v128_load32_splat);
59385923
break;
59395924
}
59405925
case SIMD_v128_load64_splat:
59415926
{
5942-
SIMD_LOAD_SPLAT_OP(SIMD_v128_load64_splat,
5943-
simde_wasm_v128_load64_splat);
5927+
SIMD_LOAD_SPLAT_OP(simde_wasm_v128_load64_splat);
59445928
break;
59455929
}
59465930
case SIMD_v128_store:

core/iwasm/interpreter/wasm_loader.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9135,13 +9135,15 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
91359135
loader_ctx->frame_offset_bottom[i] = preserved_offset;
91369136
}
91379137

9138-
if (is_32bit_type(cur_type))
9139-
i++;
9140-
else if (cur_type == VALUE_TYPE_V128) {
9138+
if (cur_type == VALUE_TYPE_V128) {
91419139
i += 4;
91429140
}
9143-
else
9141+
else if (is_32bit_type(cur_type)) {
9142+
i++;
9143+
}
9144+
else {
91449145
i += 2;
9146+
}
91459147
}
91469148

91479149
(void)error_buf;
@@ -13310,7 +13312,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1331013312
func->has_op_set_global_aux_stack = true;
1331113313
#endif
1331213314
}
13313-
#else /* else of WASM_ENABLE_FAST_INTERP */
13315+
#else /* else of WASM_ENABLE_FAST_INTERP */
1331413316
if (global_type == VALUE_TYPE_I64
1331513317
|| global_type == VALUE_TYPE_F64) {
1331613318
skip_label();

0 commit comments

Comments
 (0)