Skip to content

Commit

Permalink
Compiler: Add i64.[lt|le|gt|ge]_[s|u] opcodes
Browse files Browse the repository at this point in the history
These share the same CIL opcodes as their 32-bit counterparts.
  • Loading branch information
paulirwin committed Oct 28, 2023
1 parent 7fa0091 commit 7b7e4bc
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 16 deletions.
16 changes: 8 additions & 8 deletions WasmNet.Core/WasmCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,34 +188,34 @@ private void CompileInstruction(WasmInstruction instruction)
case WasmOpcode.I32Ne or WasmOpcode.I64Ne or WasmOpcode.F32Ne or WasmOpcode.F64Ne:
NotEqual();
break;
case WasmOpcode.I32LtS:
case WasmOpcode.I32LtS or WasmOpcode.I64LtS:
Clt();
break;
case WasmOpcode.I32LtU:
case WasmOpcode.I32LtU or WasmOpcode.I64LtU:
Clt_Un();
break;
case WasmOpcode.I32GtS:
case WasmOpcode.I32GtS or WasmOpcode.I64GtS:
Cgt();
break;
case WasmOpcode.I32GtU:
case WasmOpcode.I32GtU or WasmOpcode.I64GtU:
Cgt_Un();
break;
case WasmOpcode.I32GeS:
case WasmOpcode.I32GeS or WasmOpcode.I64GeS:
// >= is the same as !(<)
Clt();
I32Eqz();
break;
case WasmOpcode.I32GeU:
case WasmOpcode.I32GeU or WasmOpcode.I64GeU:
// >= is the same as !(<)
Clt_Un();
I32Eqz();
break;
case WasmOpcode.I32LeS:
case WasmOpcode.I32LeS or WasmOpcode.I64LeS:
// <= is the same as !(>)
Cgt();
I32Eqz();
break;
case WasmOpcode.I32LeU:
case WasmOpcode.I32LeU or WasmOpcode.I64LeU:
// <= is the same as !(>)
Cgt_Un();
I32Eqz();
Expand Down
8 changes: 8 additions & 0 deletions WasmNet.Core/WasmOpcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public enum WasmOpcode
I64Eqz = 0x50,
I64Eq = 0x51,
I64Ne = 0x52,
I64LtS = 0x53,
I64LtU = 0x54,
I64GtS = 0x55,
I64GtU = 0x56,
I64LeS = 0x57,
I64LeU = 0x58,
I64GeS = 0x59,
I64GeU = 0x5A,
F32Eq = 0x5B,
F32Ne = 0x5C,
F64Eq = 0x61,
Expand Down
8 changes: 8 additions & 0 deletions WasmNet.Core/WasmReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,14 @@ or WasmOpcode.I64Load32S
case WasmOpcode.I64Eqz:
case WasmOpcode.I64Eq:
case WasmOpcode.I64Ne:
case WasmOpcode.I64LtS:
case WasmOpcode.I64LtU:
case WasmOpcode.I64GtS:
case WasmOpcode.I64GtU:
case WasmOpcode.I64LeS:
case WasmOpcode.I64LeU:
case WasmOpcode.I64GeS:
case WasmOpcode.I64GeU:
case WasmOpcode.F32Add:
case WasmOpcode.F32Sub:
case WasmOpcode.F32Mul:
Expand Down
1 change: 0 additions & 1 deletion WasmNet.Tests/IntegrationTests/0062-I32GeS.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
;; expect: (i32:0)

(module
(memory 1)
(func (export "ges") (result i32)
i32.const 10
i32.const 42
Expand Down
1 change: 0 additions & 1 deletion WasmNet.Tests/IntegrationTests/0063-I32LtS.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
;; expect: (i32:1)

(module
(memory 1)
(func (export "lts") (result i32)
i32.const 10
i32.const 42
Expand Down
1 change: 0 additions & 1 deletion WasmNet.Tests/IntegrationTests/0064-I32LeS.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
;; expect: (i32:1)

(module
(memory 1)
(func (export "les") (result i32)
i32.const 42
i32.const 42
Expand Down
1 change: 0 additions & 1 deletion WasmNet.Tests/IntegrationTests/0065-I32GtS.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
;; expect: (i32:0)

(module
(memory 1)
(func (export "gts") (result i32)
i32.const 42
i32.const 42
Expand Down
1 change: 0 additions & 1 deletion WasmNet.Tests/IntegrationTests/0077-I32GeU.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
;; expect: (i32:0)

(module
(memory 1)
(func (export "geu") (result i32)
i32.const 10
i32.const 42
Expand Down
1 change: 0 additions & 1 deletion WasmNet.Tests/IntegrationTests/0078-I32LtU.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
;; expect: (i32:1)

(module
(memory 1)
(func (export "ltu") (result i32)
i32.const 10
i32.const 42
Expand Down
1 change: 0 additions & 1 deletion WasmNet.Tests/IntegrationTests/0079-I32LeU.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
;; expect: (i32:1)

(module
(memory 1)
(func (export "leu") (result i32)
i32.const 42
i32.const 42
Expand Down
1 change: 0 additions & 1 deletion WasmNet.Tests/IntegrationTests/0080-I32GtU.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
;; expect: (i32:0)

(module
(memory 1)
(func (export "gtu") (result i32)
i32.const 42
i32.const 42
Expand Down
10 changes: 10 additions & 0 deletions WasmNet.Tests/IntegrationTests/0109-I64LtS.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; invoke: lts
;; expect: (i32:1)

(module
(func (export "lts") (result i32)
i64.const -10
i64.const 42
i64.lt_s
)
)
10 changes: 10 additions & 0 deletions WasmNet.Tests/IntegrationTests/0110-I64LtU.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; invoke: ltu
;; expect: (i32:1)

(module
(func (export "ltu") (result i32)
i64.const 10
i64.const 42
i64.lt_u
)
)
10 changes: 10 additions & 0 deletions WasmNet.Tests/IntegrationTests/0111-I64GtS.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; invoke: gts
;; expect: (i32:1)

(module
(func (export "gts") (result i32)
i64.const 42
i64.const -42
i64.gt_s
)
)
10 changes: 10 additions & 0 deletions WasmNet.Tests/IntegrationTests/0112-I64GtU.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; invoke: gtu
;; expect: (i32:1)

(module
(func (export "gtu") (result i32)
i64.const 42
i64.const 1
i64.gt_u
)
)
10 changes: 10 additions & 0 deletions WasmNet.Tests/IntegrationTests/0113-I64LeS.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; invoke: les
;; expect: (i32:1)

(module
(func (export "les") (result i32)
i64.const -42
i64.const -42
i64.le_s
)
)
10 changes: 10 additions & 0 deletions WasmNet.Tests/IntegrationTests/0114-I64LeU.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; invoke: leu
;; expect: (i32:1)

(module
(func (export "leu") (result i32)
i64.const 42
i64.const 42
i64.le_u
)
)
10 changes: 10 additions & 0 deletions WasmNet.Tests/IntegrationTests/0115-I64GeS.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; invoke: ges
;; expect: (i32:1)

(module
(func (export "ges") (result i32)
i64.const -42
i64.const -42
i64.ge_s
)
)
10 changes: 10 additions & 0 deletions WasmNet.Tests/IntegrationTests/0116-I64GeU.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; invoke: geu
;; expect: (i32:1)

(module
(func (export "geu") (result i32)
i64.const 42
i64.const 42
i64.ge_u
)
)

0 comments on commit 7b7e4bc

Please sign in to comment.