Skip to content

Commit 06653eb

Browse files
abelstukertolauwae
authored andcommitted
Add support for extension instructions
1 parent 24bc0cc commit 06653eb

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/Interpreter/instructions.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,31 @@ bool i_instr_conversion(Module *m, uint8_t opcode) {
12681268
return true;
12691269
}
12701270

1271+
bool i_instr_extension(Module *m, uint8_t opcode) {
1272+
auto &v = m->stack[m->sp].value;
1273+
1274+
switch (opcode) {
1275+
case 0xc0: // i32.extend8_s
1276+
v.int32 = static_cast<int8_t>(v.int32);
1277+
break;
1278+
case 0xc1: // i32.extend16_s
1279+
v.int32 = static_cast<int16_t>(v.int32);
1280+
break;
1281+
case 0xc2: // i64.extend8_s
1282+
v.int64 = static_cast<int8_t>(v.int64);
1283+
break;
1284+
case 0xc3: // i64.extend16_s
1285+
v.int64 = static_cast<int16_t>(v.int64);
1286+
break;
1287+
case 0xc4: // i64.extend32_s
1288+
v.int64 = static_cast<int32_t>(v.int64);
1289+
break;
1290+
default:
1291+
return false;
1292+
}
1293+
return true;
1294+
}
1295+
12711296
/**
12721297
* 0xe0 ... 0xe3 callback operations
12731298
*/

src/Interpreter/instructions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ bool i_instr_binary_f64(Module *m, uint8_t opcode);
7272

7373
bool i_instr_conversion(Module *m, uint8_t opcode);
7474

75+
bool i_instr_extension(Module *m, uint8_t opcode);
76+
7577
bool i_instr_callback(Module *m, uint8_t opcode);

src/Interpreter/interpreter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ bool Interpreter::interpret(Module *m, bool waiting) {
436436
success &= i_instr_conversion(m, opcode);
437437
continue;
438438

439+
// extension operations
440+
case 0xc0 ... 0xc4:
441+
success &= i_instr_extension(m, opcode);
442+
continue;
443+
439444
// callback operations
440445
case 0xe0 ... 0xe3:
441446
success &= i_instr_callback(m, opcode);

0 commit comments

Comments
 (0)