From ac1796a1281aa6a6c9da3e407cb871d321da9d6c Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 13 Nov 2025 00:57:36 +0100 Subject: Add i32.shr_{s,u} --- private_include/nw/ops.h | 2 ++ src/interp/ops.c | 4 ++-- src/op/CMakeLists.txt | 2 ++ src/op/i32_shr_s.c | 23 +++++++++++++++++++++++ src/op/i32_shr_u.c | 23 +++++++++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/op/i32_shr_s.c create mode 100644 src/op/i32_shr_u.c diff --git a/private_include/nw/ops.h b/private_include/nw/ops.h index d4134d8..9287cfa 100644 --- a/private_include/nw/ops.h +++ b/private_include/nw/ops.h @@ -62,6 +62,8 @@ 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); +void nwp_op_i32_shr_s(struct nw_interp *i); +void nwp_op_i32_shr_u(struct nw_interp *i); void nwp_op_check_no_immediate(struct nw_mod *m); void nwp_op_check_block(struct nw_mod *m); diff --git a/src/interp/ops.c b/src/interp/ops.c index 7fc5848..9f80668 100644 --- a/src/interp/ops.c +++ b/src/interp/ops.c @@ -131,8 +131,8 @@ static void (*const ops[])(struct nw_interp *) = nwp_op_i32_or, /* OP_I32_OR */ NULL, /* OP_I32_XOR */ nwp_op_i32_shl, /* OP_I32_SHL */ - NULL, /* OP_I32_SHR_S */ - NULL, /* OP_I32_SHR_U */ + nwp_op_i32_shr_s, /* OP_I32_SHR_S */ + nwp_op_i32_shr_u, /* OP_I32_SHR_U */ NULL, /* OP_I32_ROTL */ NULL, /* OP_I32_ROTR */ NULL, /* OP_I64_CLZ */ diff --git a/src/op/CMakeLists.txt b/src/op/CMakeLists.txt index 3e1c7f2..7468132 100644 --- a/src/op/CMakeLists.txt +++ b/src/op/CMakeLists.txt @@ -37,6 +37,8 @@ target_sources(${PROJECT_NAME} PRIVATE i32_ne.c i32_or.c i32_shl.c + i32_shr_s.c + i32_shr_u.c i32_store.c i32_store8.c i32_sub.c diff --git a/src/op/i32_shr_s.c b/src/op/i32_shr_s.c new file mode 100644 index 0000000..991b434 --- /dev/null +++ b/src/op/i32_shr_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 +#include + +static int shr_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_shr_s(struct nw_interp *const i) +{ + nwp_arithm(i, NW_TYPE_I32, shr_s); +} diff --git a/src/op/i32_shr_u.c b/src/op/i32_shr_u.c new file mode 100644 index 0000000..72cc2a7 --- /dev/null +++ b/src/op/i32_shr_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 +#include + +static int shr_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_shr_u(struct nw_interp *const i) +{ + nwp_arithm(i, NW_TYPE_I32, shr_u); +} -- cgit v1.2.3