Skip to content

Commit

Permalink
Compiler: Add i64.extend_i32_u opcode
Browse files Browse the repository at this point in the history
This is similar to i64.extend_i32_s of course, but unsigned. Uses the
Conv_U8 IL opcode.
  • Loading branch information
paulirwin committed Oct 28, 2023
1 parent 53d003d commit 133cb41
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions WasmNet.Core/WasmCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ private void CompileInstruction(WasmInstruction instruction)
case WasmOpcode.I64ExtendI32S:
ConvI8();
break;
case WasmOpcode.I64ExtendI32U:
ConvU8();
break;
case WasmOpcode.LocalGet:
LocalGet(instruction);
break;
Expand Down Expand Up @@ -393,6 +396,13 @@ private void MemoryInit(WasmInstruction instruction)
_il.Emit(OpCodes.Callvirt, typeof(ModuleInstance).GetMethod(nameof(ModuleInstance.MemoryInit))!);
}

private void ConvU8()
{
_il.Emit(OpCodes.Conv_U8);
_stack.Pop();
_stack.Push(typeof(long));
}

private void ConvI8()
{
_il.Emit(OpCodes.Conv_I8);
Expand Down
1 change: 1 addition & 0 deletions WasmNet.Core/WasmOpcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public enum WasmOpcode
F64Mul = 0xA2,
F64Div = 0xA3,
I64ExtendI32S = 0xAC,
I64ExtendI32U = 0xAD,
RefFunc = 0xD2,
ExtendedOpcodes = 0xFC,
MemoryInit = 0xFC08,
Expand Down
1 change: 1 addition & 0 deletions WasmNet.Core/WasmReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ or WasmOpcode.I32Store8
case WasmOpcode.F64Mul:
case WasmOpcode.F64Div:
case WasmOpcode.I64ExtendI32S:
case WasmOpcode.I64ExtendI32U:
case WasmOpcode.End:
case WasmOpcode.Return:
case WasmOpcode.Drop:
Expand Down
10 changes: 10 additions & 0 deletions WasmNet.Tests/IntegrationTests/0086-I64ExtendI32U.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; invoke: extend
;; expect: (i64:4294967288)

(module
(memory 1)
(func (export "extend") (result i64)
i32.const -8
i64.extend_i32_u
)
)

0 comments on commit 133cb41

Please sign in to comment.