aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2025-11-12 00:31:30 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2025-11-12 00:31:30 +0100
commit900fabee73c16bda1542b96d564936e6318d6f58 (patch)
treee0ccc76a7e8fd8590d0aaf97041e39534d755305
parent1e3a4e9ff4d9963aa77dc6135f351f90d927e9e0 (diff)
Add i32_{gt,le}_{s,u}
-rw-r--r--private_include/nw/ops.h4
-rw-r--r--src/interp/ops.c8
-rw-r--r--src/op/CMakeLists.txt4
-rw-r--r--src/op/i32_gt_s.c23
-rw-r--r--src/op/i32_gt_u.c23
-rw-r--r--src/op/i32_le_s.c23
-rw-r--r--src/op/i32_le_u.c23
7 files changed, 104 insertions, 4 deletions
diff --git a/private_include/nw/ops.h b/private_include/nw/ops.h
index 2953ecb..d4134d8 100644
--- a/private_include/nw/ops.h
+++ b/private_include/nw/ops.h
@@ -55,6 +55,10 @@ void nwp_op_i32_eq(struct nw_interp *i);
void nwp_op_i32_ne(struct nw_interp *i);
void nwp_op_i32_lt_s(struct nw_interp *i);
void nwp_op_i32_lt_u(struct nw_interp *i);
+void nwp_op_i32_gt_s(struct nw_interp *i);
+void nwp_op_i32_gt_u(struct nw_interp *i);
+void nwp_op_i32_le_s(struct nw_interp *i);
+void nwp_op_i32_le_u(struct nw_interp *i);
void nwp_op_i32_ge_s(struct nw_interp *i);
void nwp_op_i32_ge_u(struct nw_interp *i);
void nwp_op_i32_shl(struct nw_interp *i);
diff --git a/src/interp/ops.c b/src/interp/ops.c
index 4a76fba..7fc5848 100644
--- a/src/interp/ops.c
+++ b/src/interp/ops.c
@@ -88,10 +88,10 @@ static void (*const ops[])(struct nw_interp *) =
nwp_op_i32_ne, /* OP_I32_NE */
nwp_op_i32_lt_s, /* OP_I32_LT_S */
nwp_op_i32_lt_u, /* OP_I32_LT_U */
- NULL, /* OP_I32_GT_S */
- NULL, /* OP_I32_GT_U */
- NULL, /* OP_I32_LE_S */
- NULL, /* OP_I32_LE_U */
+ nwp_op_i32_gt_s, /* OP_I32_GT_S */
+ nwp_op_i32_gt_u, /* OP_I32_GT_U */
+ nwp_op_i32_le_s, /* OP_I32_LE_S */
+ nwp_op_i32_le_u, /* OP_I32_LE_U */
nwp_op_i32_ge_s, /* OP_I32_GE_S */
nwp_op_i32_ge_u, /* OP_I32_GE_U */
NULL, /* OP_I64_EQZ */
diff --git a/src/op/CMakeLists.txt b/src/op/CMakeLists.txt
index 27f2ff1..3e1c7f2 100644
--- a/src/op/CMakeLists.txt
+++ b/src/op/CMakeLists.txt
@@ -25,8 +25,12 @@ target_sources(${PROJECT_NAME} PRIVATE
i32_eqz.c
i32_ge_s.c
i32_ge_u.c
+ i32_gt_s.c
+ i32_gt_u.c
i32_load.c
i32_load8_u.c
+ i32_le_s.c
+ i32_le_u.c
i32_lt_s.c
i32_lt_u.c
i32_mul.c
diff --git a/src/op/i32_gt_s.c b/src/op/i32_gt_s.c
new file mode 100644
index 0000000..4bdb695
--- /dev/null
+++ b/src/op/i32_gt_s.c
@@ -0,0 +1,23 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#include <nanowasm/nw.h>
+#include <nw/routines.h>
+
+static int gt_s(const struct nw_i_sm_arithm_out *const o,
+ union nw_value *const res)
+{
+ res->i32 = o->left.i32 > o->right.i32;
+ return 0;
+}
+
+void nwp_op_i32_gt_s(struct nw_interp *const i)
+{
+ nwp_arithm(i, NW_TYPE_I32, gt_s);
+}
diff --git a/src/op/i32_gt_u.c b/src/op/i32_gt_u.c
new file mode 100644
index 0000000..da153fe
--- /dev/null
+++ b/src/op/i32_gt_u.c
@@ -0,0 +1,23 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#include <nanowasm/nw.h>
+#include <nw/routines.h>
+
+static int gt_u(const struct nw_i_sm_arithm_out *const o,
+ union nw_value *const res)
+{
+ res->i32 = (unsigned long)o->left.i32 > (unsigned long)o->right.i32;
+ return 0;
+}
+
+void nwp_op_i32_gt_u(struct nw_interp *const i)
+{
+ nwp_arithm(i, NW_TYPE_I32, gt_u);
+}
diff --git a/src/op/i32_le_s.c b/src/op/i32_le_s.c
new file mode 100644
index 0000000..d1534a9
--- /dev/null
+++ b/src/op/i32_le_s.c
@@ -0,0 +1,23 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#include <nanowasm/nw.h>
+#include <nw/routines.h>
+
+static int le_s(const struct nw_i_sm_arithm_out *const o,
+ union nw_value *const res)
+{
+ res->i32 = o->left.i32 <= o->right.i32;
+ return 0;
+}
+
+void nwp_op_i32_le_s(struct nw_interp *const i)
+{
+ nwp_arithm(i, NW_TYPE_I32, le_s);
+}
diff --git a/src/op/i32_le_u.c b/src/op/i32_le_u.c
new file mode 100644
index 0000000..e32fb03
--- /dev/null
+++ b/src/op/i32_le_u.c
@@ -0,0 +1,23 @@
+/*
+ * nanowasm, a tiny WebAssembly/Wasm interpreter
+ * Copyright (C) 2023-2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#include <nanowasm/nw.h>
+#include <nw/routines.h>
+
+static int le_u(const struct nw_i_sm_arithm_out *const o,
+ union nw_value *const res)
+{
+ res->i32 = (unsigned long)o->left.i32 <= (unsigned long)o->right.i32;
+ return 0;
+}
+
+void nwp_op_i32_le_u(struct nw_interp *const i)
+{
+ nwp_arithm(i, NW_TYPE_I32, le_u);
+}