Skip to content

Commit e609948

Browse files
committed
Implement load lanes opcodes for wasm
1 parent cfcb946 commit e609948

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6391,20 +6391,53 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
63916391
break;
63926392
}
63936393

6394-
// TODO:
6395-
/* load lane operations */
6394+
#define SIMD_LOAD_LANE_OP(register, width) \
6395+
do { \
6396+
uint32 offset, addr; \
6397+
offset = read_uint32(frame_ip); \
6398+
V128 vec = POP_V128(); \
6399+
int32 base = POP_I32(); \
6400+
offset += base; \
6401+
int lane = *frame_ip++; \
6402+
addr = GET_OPERAND(uint32, I32, 0); \
6403+
addr_ret = GET_OFFSET(); \
6404+
CHECK_MEMORY_OVERFLOW(width / 8); \
6405+
if (width == 64) { \
6406+
vec.register[lane] = GET_I64_FROM_ADDR(maddr); \
6407+
} \
6408+
else { \
6409+
vec.register[lane] = *(uint##width *)(maddr); \
6410+
} \
6411+
PUT_V128_TO_ADDR(frame_lp + addr_ret, vec); \
6412+
} while (0)
6413+
63966414
case SIMD_v128_load8_lane:
6415+
{
6416+
SIMD_LOAD_LANE_OP(i8x16, 8);
6417+
break;
6418+
}
63976419
case SIMD_v128_load16_lane:
6420+
{
6421+
SIMD_LOAD_LANE_OP(i16x8, 16);
6422+
break;
6423+
}
63986424
case SIMD_v128_load32_lane:
6425+
{
6426+
SIMD_LOAD_LANE_OP(i32x4, 32);
6427+
break;
6428+
}
63996429
case SIMD_v128_load64_lane:
6430+
{
6431+
SIMD_LOAD_LANE_OP(i64x2, 64);
6432+
break;
6433+
}
64006434
case SIMD_v128_store8_lane:
64016435
case SIMD_v128_store16_lane:
64026436
case SIMD_v128_store32_lane:
64036437
case SIMD_v128_store64_lane:
64046438
case SIMD_v128_load32_zero:
64056439
case SIMD_v128_load64_zero:
64066440
{
6407-
wasm_set_exception(module, "unsupported SIMD opcode");
64086441
break;
64096442
}
64106443

core/iwasm/interpreter/wasm_loader.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15368,9 +15368,14 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1536815368
error_buf_size)) {
1536915369
goto fail;
1537015370
}
15371-
15371+
#if WASM_ENABLE_FAST_INTERP != 0
15372+
emit_uint32(loader_ctx, mem_offset);
15373+
#endif
1537215374
POP_V128();
1537315375
POP_MEM_OFFSET();
15376+
#if WASM_ENABLE_FAST_INTERP != 0
15377+
emit_byte(loader_ctx, lane);
15378+
#endif
1537415379
if (opcode1 < SIMD_v128_store8_lane) {
1537515380
PUSH_V128();
1537615381
}

0 commit comments

Comments
 (0)