├── .github └── workflows │ └── rust.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── examples ├── fib.rs ├── fib_large.rs ├── fib_serde.rs └── kth_factor.rs ├── rustfmt.toml ├── src ├── aggregation │ ├── mod.rs │ └── tests.rs ├── error.rs ├── lib.rs ├── sharding │ ├── mod.rs │ └── tests.rs ├── tests.rs ├── utils │ ├── display.rs │ ├── logging.rs │ ├── macros.rs │ ├── mod.rs │ ├── tracing.rs │ └── wasm.rs ├── wasm_ctx.rs └── wasm_snark │ ├── gadgets │ ├── int.rs │ ├── mcc.rs │ ├── mod.rs │ ├── num.rs │ └── utils.rs │ ├── mcc │ ├── mod.rs │ ├── multiset_ops.rs │ └── tests.rs │ ├── mod.rs │ └── switchboard │ ├── alu │ ├── int32.rs │ ├── int64.rs │ └── mod.rs │ ├── mod.rs │ └── tests.rs ├── third-party └── wasmi │ ├── .editorconfig │ ├── .github │ ├── dependabot.yml │ └── workflows │ │ ├── gitspiegel-trigger.yml │ │ ├── publish-benchmarks.yml │ │ └── rust.yml │ ├── .gitignore │ ├── .gitlab-ci.yml │ ├── .gitmodules │ ├── .rustfmt.toml │ ├── CHANGELOG.md │ ├── CODE_OF_CONDUCT.md │ ├── CONTRIBUTING.md │ ├── Cargo.toml │ ├── LICENSE-APACHE │ ├── LICENSE-MIT │ ├── README.md │ ├── SECURITY.md │ ├── crates │ ├── arena │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── component_vec.rs │ │ │ ├── dedup.rs │ │ │ ├── guarded.rs │ │ │ ├── lib.rs │ │ │ └── tests.rs │ ├── cli │ │ ├── Cargo.toml │ │ ├── src │ │ │ ├── args.rs │ │ │ ├── context.rs │ │ │ ├── display.rs │ │ │ ├── main.rs │ │ │ ├── tests.rs │ │ │ └── utils.rs │ │ └── tests │ │ │ ├── run.rs │ │ │ └── wats │ │ │ ├── proc_exit.wat │ │ │ └── simple_print.wat │ ├── core │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── host_error.rs │ │ │ ├── lib.rs │ │ │ ├── nan_preserving_float.rs │ │ │ ├── trap.rs │ │ │ ├── units.rs │ │ │ ├── untyped.rs │ │ │ └── value.rs │ ├── wasi │ │ ├── Cargo.toml │ │ ├── src │ │ │ ├── guest_memory.rs │ │ │ ├── lib.rs │ │ │ └── sync │ │ │ │ ├── mod.rs │ │ │ │ └── snapshots │ │ │ │ ├── mod.rs │ │ │ │ └── preview_1.rs │ │ └── tests │ │ │ ├── mod.rs │ │ │ ├── wasi_wat.rs │ │ │ └── wat │ │ │ └── hello_world.wat │ └── wasmi │ │ ├── Cargo.toml │ │ ├── benches │ │ ├── bench │ │ │ └── mod.rs │ │ ├── benches.rs │ │ ├── wasm │ │ │ ├── bz2.wasm │ │ │ ├── erc1155.wasm │ │ │ ├── erc20.wasm │ │ │ ├── erc721.wasm │ │ │ ├── pulldown-cmark.wasm │ │ │ └── spidermonkey.wasm │ │ └── wat │ │ │ ├── bare_call.wat │ │ │ ├── br_table.wat │ │ │ ├── count_until.wat │ │ │ ├── factorial.wat │ │ │ ├── fibonacci.wat │ │ │ ├── fuse.wat │ │ │ ├── global_bump.wat │ │ │ ├── global_const.wat │ │ │ ├── host_calls.wat │ │ │ ├── is_even.wat │ │ │ ├── memory-fill.wat │ │ │ ├── memory-sum.wat │ │ │ ├── memory-vec-add.wat │ │ │ ├── recursive_ok.wat │ │ │ ├── recursive_scan.wat │ │ │ ├── recursive_trap.wat │ │ │ └── trunc_f2i.wat │ │ ├── src │ │ ├── engine │ │ │ ├── bytecode │ │ │ │ ├── mod.rs │ │ │ │ ├── tests.rs │ │ │ │ └── utils.rs │ │ │ ├── cache.rs │ │ │ ├── code_map.rs │ │ │ ├── config.rs │ │ │ ├── const_pool.rs │ │ │ ├── executor.rs │ │ │ ├── executor_v1.rs │ │ │ ├── func_args.rs │ │ │ ├── func_builder │ │ │ │ ├── control_frame.rs │ │ │ │ ├── control_stack.rs │ │ │ │ ├── error.rs │ │ │ │ ├── inst_builder.rs │ │ │ │ ├── labels.rs │ │ │ │ ├── locals_registry.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── translator.rs │ │ │ │ └── value_stack.rs │ │ │ ├── func_types.rs │ │ │ ├── mod.rs │ │ │ ├── regmach │ │ │ │ ├── bytecode │ │ │ │ │ ├── construct.rs │ │ │ │ │ ├── immediate.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── provider.rs │ │ │ │ │ ├── tests.rs │ │ │ │ │ └── utils.rs │ │ │ │ ├── code_map.rs │ │ │ │ ├── executor │ │ │ │ │ ├── instrs.rs │ │ │ │ │ ├── instrs │ │ │ │ │ │ ├── binary.rs │ │ │ │ │ │ ├── branch.rs │ │ │ │ │ │ ├── call.rs │ │ │ │ │ │ ├── comparison.rs │ │ │ │ │ │ ├── conversion.rs │ │ │ │ │ │ ├── copy.rs │ │ │ │ │ │ ├── global.rs │ │ │ │ │ │ ├── load.rs │ │ │ │ │ │ ├── memory.rs │ │ │ │ │ │ ├── return_.rs │ │ │ │ │ │ ├── select.rs │ │ │ │ │ │ ├── store.rs │ │ │ │ │ │ ├── table.rs │ │ │ │ │ │ └── unary.rs │ │ │ │ │ └── mod.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── stack │ │ │ │ │ ├── calls.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ └── values.rs │ │ │ │ ├── tests │ │ │ │ │ ├── display_wasm.rs │ │ │ │ │ ├── driver.rs │ │ │ │ │ ├── host_calls.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── op │ │ │ │ │ │ ├── binary │ │ │ │ │ │ │ ├── f32_add.rs │ │ │ │ │ │ │ ├── f32_copysign.rs │ │ │ │ │ │ │ ├── f32_div.rs │ │ │ │ │ │ │ ├── f32_max.rs │ │ │ │ │ │ │ ├── f32_min.rs │ │ │ │ │ │ │ ├── f32_mul.rs │ │ │ │ │ │ │ ├── f32_sub.rs │ │ │ │ │ │ │ ├── f64_add.rs │ │ │ │ │ │ │ ├── f64_copysign.rs │ │ │ │ │ │ │ ├── f64_div.rs │ │ │ │ │ │ │ ├── f64_max.rs │ │ │ │ │ │ │ ├── f64_min.rs │ │ │ │ │ │ │ ├── f64_mul.rs │ │ │ │ │ │ │ ├── f64_sub.rs │ │ │ │ │ │ │ ├── i32_add.rs │ │ │ │ │ │ │ ├── i32_and.rs │ │ │ │ │ │ │ ├── i32_div_s.rs │ │ │ │ │ │ │ ├── i32_div_u.rs │ │ │ │ │ │ │ ├── i32_mul.rs │ │ │ │ │ │ │ ├── i32_or.rs │ │ │ │ │ │ │ ├── i32_rem_s.rs │ │ │ │ │ │ │ ├── i32_rem_u.rs │ │ │ │ │ │ │ ├── i32_rotl.rs │ │ │ │ │ │ │ ├── i32_rotr.rs │ │ │ │ │ │ │ ├── i32_shl.rs │ │ │ │ │ │ │ ├── i32_shr_s.rs │ │ │ │ │ │ │ ├── i32_shr_u.rs │ │ │ │ │ │ │ ├── i32_sub.rs │ │ │ │ │ │ │ ├── i32_xor.rs │ │ │ │ │ │ │ ├── i64_add.rs │ │ │ │ │ │ │ ├── i64_and.rs │ │ │ │ │ │ │ ├── i64_div_s.rs │ │ │ │ │ │ │ ├── i64_div_u.rs │ │ │ │ │ │ │ ├── i64_mul.rs │ │ │ │ │ │ │ ├── i64_or.rs │ │ │ │ │ │ │ ├── i64_rem_s.rs │ │ │ │ │ │ │ ├── i64_rem_u.rs │ │ │ │ │ │ │ ├── i64_rotl.rs │ │ │ │ │ │ │ ├── i64_rotr.rs │ │ │ │ │ │ │ ├── i64_shl.rs │ │ │ │ │ │ │ ├── i64_shr_s.rs │ │ │ │ │ │ │ ├── i64_shr_u.rs │ │ │ │ │ │ │ ├── i64_sub.rs │ │ │ │ │ │ │ ├── i64_xor.rs │ │ │ │ │ │ │ └── mod.rs │ │ │ │ │ │ ├── block.rs │ │ │ │ │ │ ├── br.rs │ │ │ │ │ │ ├── br_if.rs │ │ │ │ │ │ ├── br_table.rs │ │ │ │ │ │ ├── call │ │ │ │ │ │ │ ├── imported.rs │ │ │ │ │ │ │ ├── indirect.rs │ │ │ │ │ │ │ ├── internal.rs │ │ │ │ │ │ │ └── mod.rs │ │ │ │ │ │ ├── cmp │ │ │ │ │ │ │ ├── f32_eq.rs │ │ │ │ │ │ │ ├── f32_ge.rs │ │ │ │ │ │ │ ├── f32_gt.rs │ │ │ │ │ │ │ ├── f32_le.rs │ │ │ │ │ │ │ ├── f32_lt.rs │ │ │ │ │ │ │ ├── f32_ne.rs │ │ │ │ │ │ │ ├── f64_eq.rs │ │ │ │ │ │ │ ├── f64_ge.rs │ │ │ │ │ │ │ ├── f64_gt.rs │ │ │ │ │ │ │ ├── f64_le.rs │ │ │ │ │ │ │ ├── f64_lt.rs │ │ │ │ │ │ │ ├── f64_ne.rs │ │ │ │ │ │ │ ├── i32_eq.rs │ │ │ │ │ │ │ ├── i32_eqz.rs │ │ │ │ │ │ │ ├── i32_ge_s.rs │ │ │ │ │ │ │ ├── i32_ge_u.rs │ │ │ │ │ │ │ ├── i32_gt_s.rs │ │ │ │ │ │ │ ├── i32_gt_u.rs │ │ │ │ │ │ │ ├── i32_le_s.rs │ │ │ │ │ │ │ ├── i32_le_u.rs │ │ │ │ │ │ │ ├── i32_lt_s.rs │ │ │ │ │ │ │ ├── i32_lt_u.rs │ │ │ │ │ │ │ ├── i32_ne.rs │ │ │ │ │ │ │ ├── i64_eq.rs │ │ │ │ │ │ │ ├── i64_eqz.rs │ │ │ │ │ │ │ ├── i64_ge_s.rs │ │ │ │ │ │ │ ├── i64_ge_u.rs │ │ │ │ │ │ │ ├── i64_gt_s.rs │ │ │ │ │ │ │ ├── i64_gt_u.rs │ │ │ │ │ │ │ ├── i64_le_s.rs │ │ │ │ │ │ │ ├── i64_le_u.rs │ │ │ │ │ │ │ ├── i64_lt_s.rs │ │ │ │ │ │ │ ├── i64_lt_u.rs │ │ │ │ │ │ │ ├── i64_ne.rs │ │ │ │ │ │ │ └── mod.rs │ │ │ │ │ │ ├── cmp_br.rs │ │ │ │ │ │ ├── global_get.rs │ │ │ │ │ │ ├── global_set.rs │ │ │ │ │ │ ├── i32_eqz.rs │ │ │ │ │ │ ├── if_.rs │ │ │ │ │ │ ├── load.rs │ │ │ │ │ │ ├── local_set.rs │ │ │ │ │ │ ├── loop_.rs │ │ │ │ │ │ ├── memory │ │ │ │ │ │ │ ├── memory_copy.rs │ │ │ │ │ │ │ ├── memory_fill.rs │ │ │ │ │ │ │ ├── memory_grow.rs │ │ │ │ │ │ │ ├── memory_init.rs │ │ │ │ │ │ │ ├── memory_size.rs │ │ │ │ │ │ │ └── mod.rs │ │ │ │ │ │ ├── mod.rs │ │ │ │ │ │ ├── return_.rs │ │ │ │ │ │ ├── return_call │ │ │ │ │ │ │ ├── imported.rs │ │ │ │ │ │ │ ├── indirect.rs │ │ │ │ │ │ │ ├── internal.rs │ │ │ │ │ │ │ └── mod.rs │ │ │ │ │ │ ├── select.rs │ │ │ │ │ │ ├── store │ │ │ │ │ │ │ ├── f32_store.rs │ │ │ │ │ │ │ ├── f64_store.rs │ │ │ │ │ │ │ ├── i32_store.rs │ │ │ │ │ │ │ ├── i32_store16.rs │ │ │ │ │ │ │ ├── i32_store8.rs │ │ │ │ │ │ │ ├── i64_store.rs │ │ │ │ │ │ │ ├── i64_store16.rs │ │ │ │ │ │ │ ├── i64_store32.rs │ │ │ │ │ │ │ ├── i64_store8.rs │ │ │ │ │ │ │ └── mod.rs │ │ │ │ │ │ ├── table │ │ │ │ │ │ │ ├── mod.rs │ │ │ │ │ │ │ ├── table_copy.rs │ │ │ │ │ │ │ ├── table_fill.rs │ │ │ │ │ │ │ ├── table_get.rs │ │ │ │ │ │ │ ├── table_grow.rs │ │ │ │ │ │ │ ├── table_init.rs │ │ │ │ │ │ │ ├── table_set.rs │ │ │ │ │ │ │ └── table_size.rs │ │ │ │ │ │ └── unary │ │ │ │ │ │ │ ├── conversion.rs │ │ │ │ │ │ │ ├── mod.rs │ │ │ │ │ │ │ └── op.rs │ │ │ │ │ └── wasm_type.rs │ │ │ │ ├── translator │ │ │ │ │ ├── control_frame.rs │ │ │ │ │ ├── control_stack.rs │ │ │ │ │ ├── instr_encoder.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── relink_result.rs │ │ │ │ │ ├── stack │ │ │ │ │ │ ├── consts.rs │ │ │ │ │ │ ├── mod.rs │ │ │ │ │ │ ├── provider.rs │ │ │ │ │ │ └── register_alloc.rs │ │ │ │ │ ├── typed_value.rs │ │ │ │ │ ├── utils.rs │ │ │ │ │ ├── visit.rs │ │ │ │ │ └── visit_register.rs │ │ │ │ └── trap.rs │ │ │ ├── resumable.rs │ │ │ ├── stack │ │ │ │ ├── frames.rs │ │ │ │ ├── mod.rs │ │ │ │ └── values │ │ │ │ │ ├── mod.rs │ │ │ │ │ ├── sp.rs │ │ │ │ │ └── tests.rs │ │ │ ├── tests.rs │ │ │ ├── traits.rs │ │ │ ├── translator.rs │ │ │ └── trap.rs │ │ ├── error.rs │ │ ├── externref.rs │ │ ├── foreach_tuple.rs │ │ ├── func │ │ │ ├── caller.rs │ │ │ ├── error.rs │ │ │ ├── func_type.rs │ │ │ ├── funcref.rs │ │ │ ├── into_func.rs │ │ │ ├── mod.rs │ │ │ └── typed_func.rs │ │ ├── global.rs │ │ ├── instance │ │ │ ├── builder.rs │ │ │ ├── exports.rs │ │ │ └── mod.rs │ │ ├── lib.rs │ │ ├── limits.rs │ │ ├── linker.rs │ │ ├── memory │ │ │ ├── buffer.rs │ │ │ ├── data.rs │ │ │ ├── error.rs │ │ │ ├── mod.rs │ │ │ └── tests.rs │ │ ├── module │ │ │ ├── builder.rs │ │ │ ├── compile │ │ │ │ ├── block_type.rs │ │ │ │ └── mod.rs │ │ │ ├── data.rs │ │ │ ├── element.rs │ │ │ ├── error.rs │ │ │ ├── export.rs │ │ │ ├── global.rs │ │ │ ├── import.rs │ │ │ ├── init_expr.rs │ │ │ ├── instantiate │ │ │ │ ├── error.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── pre.rs │ │ │ │ └── tests.rs │ │ │ ├── mod.rs │ │ │ ├── parser.rs │ │ │ ├── read.rs │ │ │ └── utils.rs │ │ ├── reftype.rs │ │ ├── store.rs │ │ ├── table │ │ │ ├── element.rs │ │ │ ├── error.rs │ │ │ ├── mod.rs │ │ │ └── tests.rs │ │ ├── tracer │ │ │ └── mod.rs │ │ ├── tracer_v0 │ │ │ ├── continuations.rs │ │ │ ├── etable │ │ │ │ ├── mod.rs │ │ │ │ ├── pre.rs │ │ │ │ └── step_info.rs │ │ │ ├── mod.rs │ │ │ └── mtable │ │ │ │ ├── imtable.rs │ │ │ │ └── mod.rs │ │ └── value.rs │ │ └── tests │ │ ├── e2e │ │ ├── mod.rs │ │ ├── v1 │ │ │ ├── fuel_consumption_mode.rs │ │ │ ├── fuel_metering.rs │ │ │ ├── func.rs │ │ │ ├── host_calls_wasm.rs │ │ │ ├── mod.rs │ │ │ ├── resource_limiter.rs │ │ │ └── resumable_call.rs │ │ └── wat │ │ │ ├── accumulate_u8.wast │ │ │ └── inc_i32.wast │ │ ├── spec │ │ ├── context.rs │ │ ├── descriptor.rs │ │ ├── error.rs │ │ ├── local │ │ │ └── missing-features │ │ │ │ ├── mutable-global-disabled.wast │ │ │ │ ├── saturating-float-to-int-disabled.wast │ │ │ │ └── sign-extension-disabled.wast │ │ ├── mod.rs │ │ ├── profile.rs │ │ └── run.rs │ │ ├── spec_shim.rs │ │ └── wasms │ │ ├── test_rust.wasm │ │ └── test_rust_1.wasm │ ├── fuzz │ ├── Cargo.toml │ └── fuzz_targets │ │ ├── translate.rs │ │ └── translate_metered.rs │ ├── resources │ └── wasmi-logo.png │ └── scripts │ ├── ci │ ├── benchmarks-report.sh │ └── sync_wait.sh │ └── run-local-ci.sh └── wasm ├── add.wat ├── bls.wasm ├── complete_int_opcodes.wat ├── control_flow └── if_else.wat ├── example.wasm ├── example_2.wat ├── gradient_boosting.wasm ├── int_opcodes.wat ├── k3 ├── hello_env.wasm ├── if_conditional.wasm ├── read_api.wasm └── sc_write.wasm ├── memory ├── load_op.wat ├── load_op_i64.wat ├── load_store.wat ├── mem_grow.wat ├── mem_ops.wat ├── mem_size.wat ├── store_op.wat └── store_op_i64.wat ├── misc ├── br_table.wat ├── bulk-ops-memcopy.wat ├── bulk-ops-memfill.wat ├── bulk-ops.wat ├── bulk_memfill.wat ├── bulk_memfill2.wat ├── count_until.wat ├── divrem.wat ├── factorial.wat ├── fib.wat ├── fuse.wat ├── global_bump.wat ├── global_const.wat ├── host_calls.wat ├── is_even.wat ├── memory-fill.wat ├── memory-sum.wat ├── memory-vec-add.wat ├── recursive_ok.wat ├── recursive_scan.wat ├── recursive_trap.wat ├── trunc_f2i.wat └── uni-poly-eval.wasm ├── nebula ├── basic_arith.wat ├── bit_check.wat ├── eq_func.wat ├── integer_hash.wasm ├── kth_factor.wat └── regression_model.wasm ├── omit_rel_ops.wat ├── rel_ops.wat ├── sb ├── basic.wat ├── basic_i64.wat ├── br_adjust │ └── br_adjust_0.wat ├── call_indirect.wasm ├── dk.wat ├── factorial.wasm ├── polynomial-transform.wasm ├── rotl.wasm ├── small-funcs.wasm └── small-ml.wasm ├── test.wat ├── use_cases ├── code.md ├── data_provenance.wasm ├── defi_transaction.wasm ├── energy_usage.wasm ├── financial_protocol.wasm ├── game_logic.wasm ├── regulatory_compliance.wasm ├── smart_contract_audit.wasm └── toy_rsa.wasm ├── variable ├── global_get_op.wat ├── global_ops.wat ├── global_set_op.wat ├── local_get_op.wat ├── local_get_op_params.wat ├── local_ops.wat ├── local_set_op.wat └── local_tee_op.wat └── zk_ads.wasm /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: zkEngine CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | lint: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v4 17 | 18 | - name: Set up Rust 19 | uses: actions-rs/toolchain@v1 20 | with: 21 | toolchain: stable 22 | profile: minimal 23 | override: true 24 | components: rustfmt, clippy 25 | 26 | - name: Run cargo fmt --check 27 | run: cargo fmt -- --check 28 | 29 | - name: Run cargo clippy 30 | run: cargo clippy --verbose --all-targets --all-features -- -D warnings 31 | 32 | - name: Install wasm32 target 33 | run: rustup target add wasm32-unknown-unknown 34 | 35 | - name: Build for WASM 36 | run: cargo build --target wasm32-unknown-unknown 37 | tests: 38 | runs-on: ubuntu-latest 39 | needs: lint 40 | 41 | steps: 42 | - uses: actions/checkout@v4 43 | 44 | - name: Set up Rust 45 | uses: actions-rs/toolchain@v1 46 | with: 47 | toolchain: stable 48 | profile: minimal 49 | override: true 50 | 51 | - name: Run tests 52 | run: cargo test -r -- --ignored 53 | 54 | 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | pp.json 3 | vk.json -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "zk-engine" 3 | version = "0.1.0" 4 | edition = "2021" 5 | resolver = "2" 6 | 7 | 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 9 | 10 | [dependencies] 11 | nova = { git = "https://github.com/wyattbenno777/arecibo", branch = "hypernova-ivc", package = "arecibo" } 12 | wasmi = { path = "./third-party/wasmi/crates/wasmi" } 13 | serde = { version = "1.0", features = ["derive"] } 14 | serde_json = { version = "1.0" } 15 | ff = "0.13" 16 | itertools = "0.12.0" 17 | wat = "1.200.0" 18 | rand = "0.8.5" 19 | anyhow = "1.0.81" 20 | tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } 21 | tracing = { version = "0.1.40", features = ["log"] } 22 | thiserror = "1.0.61" 23 | tracing-texray = "0.2.0" 24 | 25 | [target.'cfg(target_arch = "wasm32")'.dependencies] 26 | getrandom = { version = "0.2", features = ["js"] } 27 | rustyline = { version = "13.0", features = [ 28 | "derive", 29 | ], default-features = false } 30 | 31 | [target.'cfg(not(target_arch = "wasm32"))'.dependencies] 32 | wasmi_wasi = { path = "./third-party/wasmi/crates/wasi" } 33 | 34 | [patch.crates-io] 35 | # This is needed to ensure halo2curves, which imports pasta-curves, uses the *same* traits in bn256_grumpkin 36 | pasta_curves = { git = "https://github.com/lurk-lab/pasta_curves", branch = "dev" } 37 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 ICME 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/fib.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | use zk_engine::{ 3 | nova::{ 4 | provider::{ipa_pc, Bn256EngineIPA}, 5 | spartan, 6 | traits::Dual, 7 | }, 8 | { 9 | error::ZKWASMError, 10 | utils::logging::init_logger, 11 | wasm_ctx::{WASMArgsBuilder, WASMCtx}, 12 | wasm_snark::{StepSize, WasmSNARK}, 13 | }, 14 | }; 15 | 16 | // Curve Cycle to prove/verify on 17 | pub type E = Bn256EngineIPA; 18 | pub type EE1 = ipa_pc::EvaluationEngine; 19 | pub type EE2 = ipa_pc::EvaluationEngine>; 20 | pub type S1 = spartan::batched::BatchedRelaxedR1CSSNARK; 21 | pub type S2 = spartan::batched::BatchedRelaxedR1CSSNARK, EE2>; 22 | 23 | fn main() -> Result<(), ZKWASMError> { 24 | init_logger(); 25 | 26 | // Specify step size. 27 | // 28 | // Here we choose `10` as the step size because the wasm execution of fib(16) is 253 opcodes. 29 | // meaning zkWASM will run for 26 steps (rounds up). 30 | let step_size = StepSize::new(10); 31 | 32 | // Produce setup material 33 | let pp = WasmSNARK::::setup(step_size); 34 | 35 | // Specify arguments to the WASM and use it to build a `WASMCtx` 36 | let wasm_args = WASMArgsBuilder::default() 37 | .file_path(PathBuf::from("wasm/misc/fib.wat")) 38 | .unwrap() 39 | .invoke("fib") 40 | .func_args(vec![String::from("16")]) 41 | .build(); 42 | let wasm_ctx = WASMCtx::new(wasm_args); 43 | 44 | // Prove wasm execution of fib.wat::fib(16) 45 | let (snark, instance) = WasmSNARK::::prove(&pp, &wasm_ctx, step_size)?; 46 | 47 | // Verify the proof 48 | snark.verify(&pp, &instance)?; 49 | 50 | Ok(()) 51 | } 52 | -------------------------------------------------------------------------------- /examples/fib_large.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | use zk_engine::{ 3 | error::ZKWASMError, 4 | nova::{ 5 | provider::{ipa_pc, Bn256EngineIPA}, 6 | spartan, 7 | traits::Dual, 8 | }, 9 | utils::logging::init_logger, 10 | wasm_ctx::{WASMArgsBuilder, WASMCtx}, 11 | wasm_snark::{StepSize, WasmSNARK}, 12 | }; 13 | 14 | // Curve Cycle to prove/verify on 15 | pub type E = Bn256EngineIPA; 16 | pub type EE1 = ipa_pc::EvaluationEngine; 17 | pub type EE2 = ipa_pc::EvaluationEngine>; 18 | pub type S1 = spartan::batched::BatchedRelaxedR1CSSNARK; 19 | pub type S2 = spartan::batched::BatchedRelaxedR1CSSNARK, EE2>; 20 | 21 | fn main() -> Result<(), ZKWASMError> { 22 | init_logger(); 23 | 24 | // Specify step size. 25 | // 26 | // Here we choose `1_000` as the step size because the wasm execution of fib(1000) is 16,981 27 | // opcodes. meaning zkWASM will run for 17 steps (rounds up). 28 | let step_size = StepSize::new(1_000); 29 | 30 | // Produce setup material 31 | let pp = WasmSNARK::::setup(step_size); 32 | 33 | // Specify arguments to the WASM and use it to build a `WASMCtx` 34 | let wasm_args = WASMArgsBuilder::default() 35 | .file_path(PathBuf::from("wasm/misc/fib.wat")) 36 | .unwrap() 37 | .invoke("fib") 38 | .func_args(vec![String::from("1000")]) 39 | .build(); 40 | let wasm_ctx = WASMCtx::new(wasm_args); 41 | 42 | // Prove wasm execution of fib.wat::fib(1000) 43 | let (snark, instance) = WasmSNARK::::prove(&pp, &wasm_ctx, step_size)?; 44 | 45 | // Verify the proof 46 | snark.verify(&pp, &instance)?; 47 | 48 | Ok(()) 49 | } 50 | -------------------------------------------------------------------------------- /examples/fib_serde.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | use zk_engine::{ 3 | nova::{ 4 | provider::{ipa_pc, Bn256EngineIPA}, 5 | spartan, 6 | traits::Dual, 7 | }, 8 | { 9 | error::ZKWASMError, 10 | utils::logging::init_logger, 11 | wasm_ctx::{WASMArgsBuilder, WASMCtx}, 12 | wasm_snark::{StepSize, WasmSNARK, ZKWASMInstance}, 13 | }, 14 | }; 15 | 16 | // Curve Cycle to prove/verify on 17 | pub type E = Bn256EngineIPA; 18 | pub type EE1 = ipa_pc::EvaluationEngine; 19 | pub type EE2 = ipa_pc::EvaluationEngine>; 20 | pub type S1 = spartan::batched::BatchedRelaxedR1CSSNARK; 21 | pub type S2 = spartan::batched::BatchedRelaxedR1CSSNARK, EE2>; 22 | 23 | fn main() -> Result<(), ZKWASMError> { 24 | init_logger(); 25 | 26 | // Specify step size. 27 | // 28 | // Here we choose `10` as the step size because the wasm execution of fib(16) is 253 opcodes. 29 | // meaning zkWASM will run for 26 steps (rounds up). 30 | let step_size = StepSize::new(10); 31 | 32 | // Produce setup material 33 | let pp = WasmSNARK::::setup(step_size); 34 | 35 | // Specify arguments to the WASM and use it to build a `WASMCtx` 36 | let wasm_args = WASMArgsBuilder::default() 37 | .file_path(PathBuf::from("wasm/misc/fib.wat")) 38 | .unwrap() 39 | .invoke("fib") 40 | .func_args(vec![String::from("16")]) 41 | .build(); 42 | let wasm_ctx = WASMCtx::new(wasm_args); 43 | 44 | // Prove wasm execution of fib.wat::fib(16) 45 | let (snark, instance) = WasmSNARK::::prove(&pp, &wasm_ctx, step_size)?; 46 | 47 | let str_instance = serde_json::to_string(&instance).unwrap(); 48 | let str_snark = serde_json::to_string(&snark).unwrap(); 49 | 50 | let snark: WasmSNARK = serde_json::from_str(&str_snark).unwrap(); 51 | let instance: ZKWASMInstance = serde_json::from_str(&str_instance).unwrap(); 52 | 53 | // Verify the proof 54 | snark.verify(&pp, &instance)?; 55 | 56 | Ok(()) 57 | } 58 | -------------------------------------------------------------------------------- /examples/kth_factor.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | use zk_engine::{ 3 | error::ZKWASMError, 4 | nova::{ 5 | provider::{ipa_pc, Bn256EngineIPA}, 6 | spartan, 7 | traits::Dual, 8 | }, 9 | utils::logging::init_logger, 10 | wasm_ctx::{WASMArgsBuilder, WASMCtx}, 11 | wasm_snark::{StepSize, WasmSNARK}, 12 | }; 13 | 14 | // Curve Cycle to prove/verify on 15 | pub type E = Bn256EngineIPA; 16 | pub type EE1 = ipa_pc::EvaluationEngine; 17 | pub type EE2 = ipa_pc::EvaluationEngine>; 18 | pub type S1 = spartan::batched::BatchedRelaxedR1CSSNARK; 19 | pub type S2 = spartan::batched::BatchedRelaxedR1CSSNARK, EE2>; 20 | 21 | fn main() -> Result<(), ZKWASMError> { 22 | init_logger(); 23 | 24 | // Here we chose execution step size of 1000 since the WASM execution is 7601 opcodes. 25 | // 26 | // However the memory size is 147456 address spaces, so we set memory step size to 50_000. 27 | // Resulting in 3 steps for MCC 28 | let step_size = StepSize::new(1000).set_memory_step_size(50_000); 29 | 30 | // Produce setup material 31 | let pp = WasmSNARK::::setup(step_size); 32 | 33 | let wasm_args = WASMArgsBuilder::default() 34 | .file_path(PathBuf::from("wasm/nebula/kth_factor.wat"))? 35 | .func_args(vec!["250".to_string(), "15".to_string()]) 36 | .invoke("kth_factor") 37 | .build(); 38 | let wasm_ctx = WASMCtx::new(wasm_args); 39 | 40 | let (snark, instance) = WasmSNARK::::prove(&pp, &wasm_ctx, step_size)?; 41 | 42 | // Verify the proof 43 | snark.verify(&pp, &instance)?; 44 | 45 | Ok(()) 46 | } 47 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | tab_spaces = 2 2 | max_width = 100 3 | reorder_imports = true 4 | -------------------------------------------------------------------------------- /src/error.rs: -------------------------------------------------------------------------------- 1 | //! This module defines errors returned by the library. 2 | 3 | use nova::errors::NovaError; 4 | use thiserror::Error; 5 | 6 | /// Errors returned by the zkWASM library 7 | #[derive(Debug, Error)] 8 | pub enum ZKWASMError { 9 | /// Nova error 10 | #[error("NovaError")] 11 | NovaError(#[from] NovaError), 12 | /// There is no circuit available to create a RecursiveSNARK 13 | #[error("NoCircuit")] 14 | NoCircuit, 15 | /// Anyhow Error 16 | #[error("AnyhowError")] 17 | AnyhowError(#[from] anyhow::Error), 18 | /// Wasmi Error 19 | #[error("WasmiError")] 20 | WasmiError(wasmi::Error), 21 | /// Failed to load WASM module 22 | #[error("WasmError: {0}")] 23 | WASMError(String), 24 | /// Something went wrong when verifying the multisets 25 | #[error("MultisetVerificationError")] 26 | MultisetVerificationError, 27 | #[error("Input SNARK needs to be Recursive")] 28 | /// Returned when trying to compress or aggregate an already compressed proof 29 | NotRecursive, 30 | /// Returned when invalid [`TraceSliceValues`] are passed 31 | #[error("InvalidTraceSliceValues: {0}")] 32 | InvalidTraceSliceValues(String), 33 | } 34 | 35 | impl From for ZKWASMError { 36 | fn from(error: wasmi::Error) -> Self { 37 | Self::WasmiError(error) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Nebula based zkVM for WASM ISA 2 | #![allow(clippy::type_complexity)] 3 | #![allow(non_snake_case)] 4 | #![deny(missing_docs)] 5 | pub mod aggregation; 6 | pub mod error; 7 | pub mod sharding; 8 | pub mod utils; 9 | pub mod wasm_ctx; 10 | pub mod wasm_snark; 11 | 12 | #[cfg(test)] 13 | mod tests; 14 | 15 | #[cfg(not(target_arch = "wasm32"))] 16 | pub use wasmi_wasi::WasiCtx; 17 | 18 | // re-export 19 | pub use nova; 20 | -------------------------------------------------------------------------------- /src/utils/logging.rs: -------------------------------------------------------------------------------- 1 | //! Logging utilities 2 | 3 | /// Initializes the logger with the default environment filter. 4 | pub fn init_logger() { 5 | let _ = tracing_subscriber::fmt() 6 | .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) 7 | .try_init(); 8 | } 9 | -------------------------------------------------------------------------------- /src/utils/macros.rs: -------------------------------------------------------------------------------- 1 | //! Macros for logging and timing 2 | 3 | // Macro to start the timer 4 | macro_rules! start_timer { 5 | ($msg:expr) => {{ 6 | tracing::info!("{}...", $msg); 7 | (Instant::now(), $msg) 8 | }}; 9 | } 10 | 11 | // Macro to stop the timer 12 | macro_rules! stop_timer { 13 | ($timer:expr) => {{ 14 | let (start, msg) = $timer; 15 | tracing::info!("{} took {:?}", msg, start.elapsed()); 16 | }}; 17 | } 18 | 19 | pub(crate) use start_timer; 20 | pub(crate) use stop_timer; 21 | -------------------------------------------------------------------------------- /src/utils/mod.rs: -------------------------------------------------------------------------------- 1 | //! Utility code 2 | 3 | mod display; 4 | 5 | pub mod logging; 6 | #[cfg(test)] 7 | pub mod macros; 8 | pub mod tracing; 9 | pub(crate) mod wasm; 10 | -------------------------------------------------------------------------------- /src/wasm_snark/gadgets/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod int; 2 | pub mod mcc; 3 | mod num; 4 | pub mod utils; 5 | -------------------------------------------------------------------------------- /src/wasm_snark/gadgets/utils.rs: -------------------------------------------------------------------------------- 1 | use ff::PrimeField; 2 | use nova::frontend::gadgets::Assignment; 3 | use nova::frontend::{num::AllocatedNum, Boolean, ConstraintSystem, SynthesisError}; 4 | 5 | #[allow(dead_code)] 6 | /// Allocate a variable that is set to zero 7 | pub fn alloc_zero>(mut cs: CS) -> AllocatedNum { 8 | let zero = AllocatedNum::alloc_infallible(cs.namespace(|| "alloc"), || F::ZERO); 9 | cs.enforce( 10 | || "check zero is valid", 11 | |lc| lc, 12 | |lc| lc, 13 | |lc| lc + zero.get_variable(), 14 | ); 15 | zero 16 | } 17 | 18 | /// Allocate a variable that is set to one 19 | pub fn alloc_one>(mut cs: CS) -> AllocatedNum { 20 | let one = AllocatedNum::alloc_infallible(cs.namespace(|| "alloc"), || F::ONE); 21 | cs.enforce( 22 | || "check one is valid", 23 | |lc| lc + CS::one(), 24 | |lc| lc + CS::one(), 25 | |lc| lc + one.get_variable(), 26 | ); 27 | 28 | one 29 | } 30 | 31 | /// If condition return a otherwise b 32 | pub fn conditionally_select>( 33 | mut cs: CS, 34 | a: &AllocatedNum, 35 | b: &AllocatedNum, 36 | condition: &Boolean, 37 | ) -> Result, SynthesisError> { 38 | let c = AllocatedNum::alloc(cs.namespace(|| "conditional select result"), || { 39 | if *condition.get_value().get()? { 40 | Ok(*a.get_value().get()?) 41 | } else { 42 | Ok(*b.get_value().get()?) 43 | } 44 | })?; 45 | 46 | // a * condition + b*(1-condition) = c -> 47 | // a * condition - b*condition = c - b 48 | cs.enforce( 49 | || "conditional select constraint", 50 | |lc| lc + a.get_variable() - b.get_variable(), 51 | |_| condition.lc(CS::one(), Scalar::ONE), 52 | |lc| lc + c.get_variable() - b.get_variable(), 53 | ); 54 | 55 | Ok(c) 56 | } 57 | -------------------------------------------------------------------------------- /third-party/wasmi/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | [*] 3 | indent_style=space 4 | indent_size = 4 5 | end_of_line=lf 6 | charset=utf-8 7 | trim_trailing_whitespace=true 8 | max_line_length=120 9 | insert_final_newline=true 10 | -------------------------------------------------------------------------------- /third-party/wasmi/.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: '/' 5 | schedule: 6 | interval: daily 7 | -------------------------------------------------------------------------------- /third-party/wasmi/.github/workflows/gitspiegel-trigger.yml: -------------------------------------------------------------------------------- 1 | name: gitspiegel sync 2 | 3 | # This workflow doesn't do anything, it's only use is to trigger "workflow_run" 4 | # webhook, that'll be consumed by gitspiegel 5 | # This way, gitspiegel won't do mirroring, unless this workflow runs, 6 | # and running the workflow is protected by GitHub 7 | 8 | on: 9 | pull_request: 10 | types: 11 | - opened 12 | - synchronize 13 | - unlocked 14 | - ready_for_review 15 | - reopened 16 | 17 | jobs: 18 | sync: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Do nothing 22 | run: echo "let's go" 23 | -------------------------------------------------------------------------------- /third-party/wasmi/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /target/ 3 | **/*.rs.bk 4 | Cargo.lock 5 | spec/target 6 | 7 | **/fuzz/corpus/ 8 | **/fuzz/target/ 9 | **/fuzz/artifacts/ 10 | -------------------------------------------------------------------------------- /third-party/wasmi/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "crates/wasmi/tests/spec/testsuite"] 2 | path = crates/wasmi/tests/spec/testsuite 3 | url = https://github.com/WebAssembly/testsuite.git 4 | [submodule "crates/wasmi/benches/wasm_kernel"] 5 | path = crates/wasmi/benches/wasm/wasm_kernel 6 | url = https://github.com/robbepop/wasm_kernel.git 7 | -------------------------------------------------------------------------------- /third-party/wasmi/.rustfmt.toml: -------------------------------------------------------------------------------- 1 | imports_granularity = "Crate" 2 | imports_layout = "HorizontalVertical" 3 | edition = "2021" 4 | -------------------------------------------------------------------------------- /third-party/wasmi/Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["crates/arena", "crates/cli", "crates/core", "crates/wasmi", "crates/wasi"] 3 | exclude = [] 4 | resolver = "2" 5 | 6 | [workspace.package] 7 | authors = [ 8 | "Parity Technologies ", 9 | "Robin Freyler ", 10 | ] 11 | repository = "https://github.com/paritytech/wasmi" 12 | edition = "2021" 13 | readme = "README.md" 14 | license = "MIT/Apache-2.0" 15 | keywords = ["wasm", "webassembly", "interpreter", "vm"] 16 | categories = ["wasm", "no-std", "virtualization"] 17 | 18 | [profile.bench] 19 | lto = "fat" 20 | codegen-units = 1 21 | -------------------------------------------------------------------------------- /third-party/wasmi/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2023 Parity Technologies 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /third-party/wasmi/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting a vulnerability 2 | 3 | If you find something that can be treated as a security vulnerability, please do not use the issue tracker or discuss it in the public forum/channels, as it can cause more damage rather than giving real help to the ecosystem. 4 | 5 | Security vulnerabilities should be reported using [this contact form](https://security-submission.parity.io/). 6 | 7 | If you think that your report might be eligible for the Bug Bounty Program, please mark this during the submission. Please check up-to-date [Parity Bug Bounty Program rules](https://www.parity.io/bug-bounty) for more information about our Bug Bounty Program. 8 | 9 | **Warning:** This is a unified `SECURITY.md` file for the Paritytech GitHub Organization. The presence of this file does not mean that this repository is covered by the Bug Bounty program. Please always check the Bug Bounty Program scope for the information. 10 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/arena/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasmi_arena" 3 | version = "0.4.0" 4 | documentation = "https://docs.rs/wasmi_arena/" 5 | description = "Entity arena data structures for wasmi" 6 | exclude = ["tests/*", "benches/*"] 7 | authors.workspace = true 8 | repository.workspace = true 9 | edition.workspace = true 10 | readme.workspace = true 11 | license.workspace = true 12 | keywords.workspace = true 13 | categories.workspace = true 14 | 15 | [features] 16 | default = ["std"] 17 | std = [] 18 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/arena/src/guarded.rs: -------------------------------------------------------------------------------- 1 | use crate::ArenaIndex; 2 | 3 | /// A guarded entity. 4 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] 5 | pub struct GuardedEntity { 6 | guard_idx: GuardIdx, 7 | entity_idx: EntityIdx, 8 | } 9 | 10 | impl GuardedEntity { 11 | /// Creates a new [`GuardedEntity`]. 12 | pub fn new(guard_idx: GuardIdx, entity_idx: EntityIdx) -> Self { 13 | Self { 14 | guard_idx, 15 | entity_idx, 16 | } 17 | } 18 | } 19 | 20 | impl GuardedEntity 21 | where 22 | GuardIdx: ArenaIndex, 23 | EntityIdx: ArenaIndex, 24 | { 25 | /// Returns the entity index of the [`GuardedEntity`]. 26 | /// 27 | /// Return `None` if the `guard_index` does not match. 28 | pub fn entity_index(&self, guard_index: GuardIdx) -> Option { 29 | if self.guard_idx.into_usize() != guard_index.into_usize() { 30 | return None; 31 | } 32 | Some(self.entity_idx) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasmi_cli" 3 | version = "0.31.0" 4 | documentation = "https://docs.rs/wasmi/" 5 | description = "WebAssembly interpreter" 6 | authors.workspace = true 7 | repository.workspace = true 8 | edition.workspace = true 9 | readme.workspace = true 10 | license.workspace = true 11 | keywords.workspace = true 12 | categories.workspace = true 13 | 14 | [dependencies] 15 | anyhow = "1" 16 | clap = { version = "4", features = ["derive"] } 17 | wasmi = { version = "0.31.0", path = "../wasmi" } 18 | wasmi_wasi = { version = "0.31.0", path = "../wasi" } 19 | wat = "1" 20 | 21 | [dev-dependencies] 22 | assert_cmd = "2.0.7" 23 | 24 | # We need to put this [profile.release] section due to this bug in Cargo: 25 | # https://github.com/rust-lang/cargo/issues/8264 26 | # Uncomment the lines below before publishing a new `wasmi_cli` release to crates.io. 27 | # [profile.release] 28 | # lto = "fat" 29 | # codegen-units = 1 30 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/cli/tests/run.rs: -------------------------------------------------------------------------------- 1 | use assert_cmd::Command; 2 | use std::path::PathBuf; 3 | 4 | #[test] 5 | fn test_simple_print() { 6 | let mut cmd = get_cmd(); 7 | let assert = cmd.arg(get_bin_path("simple_print")).assert(); 8 | let output = assert.get_output(); 9 | let stdout = &output.stdout; 10 | assert!(contains_slice(stdout, b"Hello World")); 11 | if !(contains_slice(stdout, b"Hello World\n")) { 12 | eprint!("UNEQUAL: {}", std::str::from_utf8(stdout).unwrap()); 13 | } 14 | } 15 | 16 | fn contains_slice(slice: &[T], other: &[T]) -> bool 17 | where 18 | T: Eq, 19 | { 20 | if other.is_empty() { 21 | return true; 22 | } 23 | slice.windows(other.len()).any(|window| window == other) 24 | } 25 | 26 | #[test] 27 | fn test_proc_exit() { 28 | let mut cmd = get_cmd(); 29 | let assert = cmd.arg(get_bin_path("proc_exit")).assert(); 30 | assert.failure().code(1); 31 | } 32 | 33 | /// UTILS 34 | 35 | /// gets the path to a wasm binary given it's name 36 | fn get_bin_path(name: &str) -> PathBuf { 37 | let mut path = PathBuf::new(); 38 | path.push("tests"); 39 | path.push("wats"); 40 | path.push(format!("{name}.wat")); 41 | path 42 | } 43 | 44 | fn get_cmd() -> assert_cmd::Command { 45 | Command::cargo_bin("wasmi_cli").expect("could not create wasmi_cli command") 46 | } 47 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/cli/tests/wats/proc_exit.wat: -------------------------------------------------------------------------------- 1 | ;; Test Notes 2 | ;; Tests fd_write and proc_exit wasi 'syscalls' 3 | ;; Also tests environ_get 4 | 5 | (module 6 | (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) 7 | (func $main (export "") 8 | (call $proc_exit (i32.const 1)) 9 | ) 10 | (memory (export "memory") 1) 11 | ) -------------------------------------------------------------------------------- /third-party/wasmi/crates/cli/tests/wats/simple_print.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (import "wasi_snapshot_preview1" "fd_write" (func $fd_write 3 | (param $fd i32) 4 | (param $iovec i32) 5 | (param $iovec_len i32) 6 | (param $size i32) 7 | (result i32)) 8 | ) 9 | 10 | (memory (export "memory") 1) 11 | 12 | (data (i32.const 8) "Hello World\n") 13 | 14 | (func $main (export "") 15 | ;; create iovec 16 | (i32.store (i32.const 0) (i32.const 8)) ;; iovec base 17 | (i32.store (i32.const 4) (i32.const 12)) ;; iovec length 18 | 19 | (call $fd_write 20 | (i32.const 1) ;; fd stdout 21 | (i32.const 0) ;; iovec list 22 | (i32.const 1) ;; iovec_len. 1 iovec here 23 | (i32.const 20) ;; size written 24 | ) 25 | drop ;; func main signature has nothing on stack. no return value, so we drop 26 | ) 27 | 28 | ) 29 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasmi_core" 3 | version = "0.13.0" 4 | documentation = "https://docs.rs/wasmi_core" 5 | description = "Core primitives for the wasmi WebAssembly interpreter" 6 | authors.workspace = true 7 | repository.workspace = true 8 | edition.workspace = true 9 | readme.workspace = true 10 | license.workspace = true 11 | keywords.workspace = true 12 | categories.workspace = true 13 | 14 | [dependencies] 15 | libm = "0.2.1" 16 | num-traits = { version = "0.2.8", default-features = false } 17 | downcast-rs = { version = "1.2", default-features = false } 18 | paste = "1" 19 | serde = { version = "1.0.197", features = ["derive"] } 20 | 21 | [dev-dependencies] 22 | rand = "0.8.2" 23 | 24 | [features] 25 | default = ["std"] 26 | # Use `no-default-features` for a `no_std` build. 27 | std = ["num-traits/std", "downcast-rs/std"] 28 | 29 | [package.metadata.cargo-udeps.ignore] 30 | # cargo-udeps cannot detect that libm is used for no_std targets only. 31 | normal = ["libm"] 32 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/core/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![allow(clippy::all)] 3 | 4 | mod host_error; 5 | mod nan_preserving_float; 6 | mod trap; 7 | mod units; 8 | mod untyped; 9 | mod value; 10 | 11 | #[cfg(not(feature = "std"))] 12 | extern crate alloc; 13 | 14 | #[cfg(feature = "std")] 15 | extern crate std as alloc; 16 | 17 | use self::value::{ 18 | ArithmeticOps, 19 | ExtendInto, 20 | Float, 21 | Integer, 22 | LittleEndianConvert, 23 | SignExtendFrom, 24 | TruncateSaturateInto, 25 | TryTruncateInto, 26 | WrapInto, 27 | }; 28 | pub use self::{ 29 | host_error::HostError, 30 | nan_preserving_float::{F32, F64}, 31 | trap::{Trap, TrapCode}, 32 | units::Pages, 33 | untyped::{ 34 | effective_address, 35 | DecodeUntypedSlice, 36 | EncodeUntypedSlice, 37 | UntypedError, 38 | UntypedValue, 39 | }, 40 | value::ValueType, 41 | }; 42 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasi/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasmi_wasi" 3 | version = "0.31.0" 4 | documentation = "https://docs.rs/wasmi_wasi" 5 | description = "WASI library support for the wasmi interpreter" 6 | authors.workspace = true 7 | repository.workspace = true 8 | edition.workspace = true 9 | readme.workspace = true 10 | license.workspace = true 11 | keywords.workspace = true 12 | categories.workspace = true 13 | 14 | [dependencies] 15 | wasi-common = "2.0" 16 | wasi-cap-std-sync = "2.0" 17 | wiggle = { version = "2.0", default-features = false, features = ["wiggle_metadata"] } 18 | wasmi = { version = "0.31.0", path = "../wasmi" } 19 | 20 | [dev-dependencies] 21 | wat = "1.0.50" 22 | 23 | [features] 24 | default = ["sync"] 25 | sync = [] 26 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasi/src/guest_memory.rs: -------------------------------------------------------------------------------- 1 | use wiggle::{borrow::BorrowChecker, BorrowHandle, GuestError, GuestMemory, Region}; 2 | 3 | /// Lightweight `wasmi::Memory` wrapper so we can implement the 4 | /// `wiggle::GuestMemory` trait on it. 5 | pub struct WasmiGuestMemory<'a> { 6 | mem: &'a mut [u8], 7 | bc: BorrowChecker, 8 | } 9 | 10 | impl<'a> WasmiGuestMemory<'a> { 11 | pub fn new(mem: &'a mut [u8]) -> Self { 12 | Self { 13 | mem, 14 | // Wiggle does not expose any methods for functions to re-enter 15 | // the WebAssembly instance, or expose the memory via non-wiggle 16 | // mechanisms. However, the user-defined code may end up 17 | // re-entering the instance, in which case this is an incorrect 18 | // implementation - we require exactly one BorrowChecker exist per 19 | // instance. 20 | bc: BorrowChecker::new(), 21 | } 22 | } 23 | } 24 | 25 | unsafe impl GuestMemory for WasmiGuestMemory<'_> { 26 | fn base(&self) -> (*mut u8, u32) { 27 | (self.mem.as_ptr() as *mut u8, self.mem.len() as u32) 28 | } 29 | fn has_outstanding_borrows(&self) -> bool { 30 | self.bc.has_outstanding_borrows() 31 | } 32 | fn is_shared_borrowed(&self, r: Region) -> bool { 33 | self.bc.is_shared_borrowed(r) 34 | } 35 | fn is_mut_borrowed(&self, r: Region) -> bool { 36 | self.bc.is_mut_borrowed(r) 37 | } 38 | fn shared_borrow(&self, r: Region) -> Result { 39 | self.bc.shared_borrow(r) 40 | } 41 | fn mut_borrow(&self, r: Region) -> Result { 42 | self.bc.mut_borrow(r) 43 | } 44 | fn shared_unborrow(&self, h: BorrowHandle) { 45 | self.bc.shared_unborrow(h) 46 | } 47 | fn mut_unborrow(&self, h: BorrowHandle) { 48 | self.bc.mut_unborrow(h) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasi/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! This crate provides support for WASI `preview1` for the `wasmi` interpreter. 2 | //! 3 | //! Use [`add_to_linker`] to add all supported WASI definitions to the `wasmi` linker. 4 | 5 | mod guest_memory; 6 | 7 | #[cfg(feature = "sync")] 8 | pub mod sync; 9 | 10 | pub use self::guest_memory::WasmiGuestMemory; 11 | pub use wasi_common::{Error, Table, WasiCtx, WasiDir, WasiFile}; 12 | 13 | /// Sync mode is the "default" of this crate, so we also export it at the top level. 14 | #[cfg(feature = "sync")] 15 | pub use sync::*; 16 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasi/src/sync/mod.rs: -------------------------------------------------------------------------------- 1 | //! Re-export the commonly used wasi-cap-std-sync crate here. This saves 2 | //! consumers of this library from having to keep additional dependencies 3 | //! in sync. 4 | 5 | pub mod snapshots; 6 | 7 | pub use wasi_cap_std_sync::*; 8 | 9 | #[doc(inline)] 10 | pub use self::snapshots::preview_1::add_wasi_snapshot_preview1_to_linker as add_to_linker; 11 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasi/src/sync/snapshots/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod preview_1; 2 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasi/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod wasi_wat; 2 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasi/tests/wasi_wat.rs: -------------------------------------------------------------------------------- 1 | use wasi_cap_std_sync::WasiCtxBuilder; 2 | use wasmi::{Config, Engine, Extern, Instance, Linker, Module, Store}; 3 | use wasmi_wasi::{add_to_linker, WasiCtx}; 4 | 5 | pub fn load_instance_from_wat(wat_bytes: &[u8]) -> (Store, wasmi::Instance) { 6 | let wasm = wat2wasm(wat_bytes); 7 | let config = Config::default(); 8 | let engine = Engine::new(&config); 9 | let module = Module::new(&engine, &wasm[..]).unwrap(); 10 | let mut linker = >::new(&engine); 11 | // add wasi to linker 12 | let wasi = WasiCtxBuilder::new() 13 | .inherit_stdio() 14 | .inherit_args() 15 | .unwrap() 16 | .build(); 17 | let mut store = Store::new(&engine, wasi); 18 | 19 | add_to_linker(&mut linker, |ctx| ctx).unwrap(); 20 | let instance = linker 21 | .instantiate(&mut store, &module) 22 | .unwrap() 23 | .start(&mut store) 24 | .unwrap(); 25 | (store, instance) 26 | } 27 | 28 | /// Converts the `.wat` encoded `bytes` into `.wasm` encoded bytes. 29 | pub fn wat2wasm(bytes: &[u8]) -> Vec { 30 | wat::parse_bytes(bytes).unwrap().into_owned() 31 | } 32 | 33 | fn load() -> (Store, Instance) { 34 | let bytes = include_bytes!("wat/hello_world.wat"); 35 | load_instance_from_wat(bytes) 36 | } 37 | 38 | #[test] 39 | fn test_hello_world() { 40 | let (mut store, instance) = load(); 41 | let f = instance 42 | .get_export(&store, "_start") 43 | .and_then(Extern::into_func) 44 | .unwrap(); 45 | let mut result = []; 46 | f.call(&mut store, &[], &mut result).unwrap(); 47 | } 48 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasi/tests/wat/hello_world.wat: -------------------------------------------------------------------------------- 1 | ;; copied (and slightly adapted) from [wasmtime tutorial](https://github.com/bytecodealliance/wasmtime/blob/main/docs/WASI-tutorial.md) 2 | 3 | (module 4 | ;; Import the required fd_write WASI function which will write the given io vectors to stdout 5 | ;; The function signature for fd_write is: 6 | ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written 7 | (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) 8 | 9 | (memory 1) 10 | (export "memory" (memory 0)) 11 | 12 | ;; Write 'hello world\n' to memory at an offset of 8 bytes 13 | ;; Note the trailing newline which is required for the text to appear 14 | (data (i32.const 8) "hello world\n") 15 | 16 | (func $main (export "_start") 17 | ;; Creating a new io vector within linear memory 18 | (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string 19 | (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string 20 | 21 | (call $fd_write 22 | (i32.const 1) ;; file_descriptor - 1 for stdout 23 | (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 24 | (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. 25 | (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written 26 | ) 27 | drop ;; Discard the number of bytes written from the top of the stack 28 | ) 29 | ) -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasmi" 3 | version = "0.31.0" 4 | documentation = "https://docs.rs/wasmi/" 5 | description = "WebAssembly interpreter" 6 | exclude = ["tests/*", "benches/*"] 7 | authors.workspace = true 8 | repository.workspace = true 9 | edition.workspace = true 10 | readme.workspace = true 11 | license.workspace = true 12 | keywords.workspace = true 13 | categories.workspace = true 14 | 15 | [dependencies] 16 | wasmparser = { version = "0.100.1", package = "wasmparser-nostd", default-features = false } 17 | wasmi_core = { version = "0.13", path = "../core", default-features = false } 18 | wasmi_arena = { version = "0.4", path = "../arena", default-features = false } 19 | spin = { version = "0.9", default-features = false, features = [ 20 | "mutex", 21 | "spin_mutex", 22 | "rwlock", 23 | ] } 24 | smallvec = { version = "1.10.0", features = ["union"] } 25 | multi-stash = { version = "0.2.0" } 26 | anyhow = "1.0" 27 | wat = "1" 28 | serde = { version = "1.0.197", features = ["derive"] } 29 | serde_json = { version = "1.0" } 30 | sha2 = { version = "0.10.6", default-features = false } 31 | hex = { version = "0.4.2" } 32 | 33 | [dev-dependencies] 34 | assert_matches = "1.5" 35 | wast = "64.0" 36 | criterion = { version = "0.5", default-features = false } 37 | 38 | [features] 39 | default = ["std"] 40 | std = ["wasmi_core/std", "wasmi_arena/std", "wasmparser/std", "spin/std"] 41 | 42 | [[bench]] 43 | name = "benches" 44 | harness = false 45 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wasm/bz2.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/third-party/wasmi/crates/wasmi/benches/wasm/bz2.wasm -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wasm/erc1155.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/third-party/wasmi/crates/wasmi/benches/wasm/erc1155.wasm -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wasm/erc20.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/third-party/wasmi/crates/wasmi/benches/wasm/erc20.wasm -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wasm/erc721.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/third-party/wasmi/crates/wasmi/benches/wasm/erc721.wasm -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wasm/pulldown-cmark.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/third-party/wasmi/crates/wasmi/benches/wasm/pulldown-cmark.wasm -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wasm/spidermonkey.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/third-party/wasmi/crates/wasmi/benches/wasm/spidermonkey.wasm -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/bare_call.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "bare_call_0") (param) (result)) 3 | (func (export "bare_call_1") (param i32) (result i32) local.get 0) 4 | (func (export "bare_call_4") (param i32 i64 f32 f64) (result i32 i64 f32 f64) 5 | local.get 0 6 | local.get 1 7 | local.get 2 8 | local.get 3 9 | ) 10 | (func (export "bare_call_16") 11 | (param i32 i64 f32 f64 i32 i64 f32 f64 i32 i64 f32 f64 i32 i64 f32 f64) 12 | (result i32 i64 f32 f64 i32 i64 f32 f64 i32 i64 f32 f64 i32 i64 f32 f64) 13 | local.get 0 14 | local.get 1 15 | local.get 2 16 | local.get 3 17 | local.get 4 18 | local.get 5 19 | local.get 6 20 | local.get 7 21 | local.get 8 22 | local.get 9 23 | local.get 10 24 | local.get 11 25 | local.get 12 26 | local.get 13 27 | local.get 14 28 | local.get 15 29 | ) 30 | ) 31 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/count_until.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `count_until` that takes an input `n`. 2 | ;; The exported function counts an integer `n` times and then returns 0. 3 | (module 4 | (func (export "count_until") (param $limit i32) (result i32) 5 | (local $counter i32) 6 | (loop 7 | (br_if 8 | 0 9 | (i32.ne 10 | (local.tee $counter 11 | (i32.add 12 | (local.get $counter) 13 | (i32.const 1) 14 | ) 15 | ) 16 | (local.get $limit) 17 | ) 18 | ) 19 | ) 20 | (return (local.get $counter)) 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/factorial.wat: -------------------------------------------------------------------------------- 1 | (module 2 | ;; Iterative factorial function, does not use recursion. 3 | (func (export "iterative_factorial") (param i64) (result i64) 4 | (local i64) 5 | (local.set 1 (i64.const 1)) 6 | (block 7 | (br_if 0 (i64.lt_s (local.get 0) (i64.const 2))) 8 | (loop 9 | (local.set 1 (i64.mul (local.get 1) (local.get 0))) 10 | (local.set 0 (i64.add (local.get 0) (i64.const -1))) 11 | (br_if 0 (i64.gt_s (local.get 0) (i64.const 1))) 12 | ) 13 | ) 14 | (local.get 1) 15 | ) 16 | 17 | ;; Recursive trivial factorial function. 18 | (func $rec_fac (export "recursive_factorial") (param i64) (result i64) 19 | (if (result i64) 20 | (i64.eq (local.get 0) (i64.const 0)) 21 | (then (i64.const 1)) 22 | (else 23 | (i64.mul 24 | (local.get 0) 25 | (call $rec_fac 26 | (i64.sub 27 | (local.get 0) 28 | (i64.const 1) 29 | ) 30 | ) 31 | ) 32 | ) 33 | ) 34 | ) 35 | ) 36 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/fuse.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "test") (param $n i32) (result i32) 3 | (local $i i32) 4 | (loop $continue 5 | ;; i += 1 6 | (local.set $i 7 | (i32.add 8 | (local.get $i) 9 | (i32.const 1) 10 | ) 11 | ) 12 | ;; if not((i >= n) and (i <= n)) then continue 13 | ;; Note: The above is equal to: 14 | ;; if i != n then continue 15 | (br_if 16 | $continue 17 | (i32.eqz 18 | (i32.and 19 | (i32.ge_u (local.get $i) (local.get $n)) 20 | (i32.le_u (local.get $i) (local.get $n)) 21 | ) 22 | ) 23 | ) 24 | ) 25 | (return (local.get $i)) 26 | ) 27 | ) 28 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/global_bump.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `bump` that takes an input `n`. 2 | ;; The exported function bumps a global variable `n` times and then returns it. 3 | (module 4 | (global $g (mut i32) (i32.const 0)) 5 | (func $bump (export "bump") (param $n i32) (result i32) 6 | (global.set $g (i32.const 0)) 7 | (block $break 8 | (loop $continue 9 | (br_if ;; if $g == $n then break 10 | $break 11 | (i32.eq 12 | (global.get $g) 13 | (local.get $n) 14 | ) 15 | ) 16 | (global.set $g ;; $g += 1 17 | (i32.add 18 | (global.get $g) 19 | (i32.const 1) 20 | ) 21 | ) 22 | (br $continue) 23 | ) 24 | ) 25 | (return (global.get $g)) 26 | ) 27 | ) 28 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/global_const.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (global $g0 i32 (i32.const 0)) ;; constant 3 | (global $g1 i32 (i32.const 1)) ;; constant 4 | (func (export "call") (param $limit i32) (result i32) 5 | (local $accumulator i32) 6 | (loop $continue 7 | (br_if 8 | $continue 9 | (i32.lt_s 10 | (local.tee $accumulator 11 | (i32.add 12 | (local.get $accumulator) 13 | (i32.add 14 | (global.get $g0) 15 | (global.get $g1) 16 | ) 17 | ) 18 | ) 19 | (local.get $limit) 20 | ) 21 | ) 22 | ) 23 | (return (local.get $accumulator)) 24 | ) 25 | ) 26 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/host_calls.wat: -------------------------------------------------------------------------------- 1 | ;; The below `.wat` file exports a function `call` that takes a `n` of type `i64`. 2 | ;; It will iterate `n` times and call the imported function `host_call` every time. 3 | ;; 4 | ;; This benchmarks tests the performance of host calls. 5 | ;; 6 | ;; After successful execution the `call` function will return `0`. 7 | (module 8 | (import "benchmark" "host_call" (func $host_sub1 (param i64) (result i64))) 9 | (func $call (export "call") (param $n i64) (result i64) 10 | (if (result i64) 11 | (i64.eqz (local.get $n)) 12 | (then 13 | ;; bail out early if n == 0 14 | (return (local.get $n)) 15 | ) 16 | (else 17 | (loop 18 | ;; continue if n != 0, otherwise break out of loop 19 | ;; the $host_call is expected to decrease its input by 1 20 | (br_if 0 21 | (i32.wrap_i64 22 | (local.tee $n (call $host_sub1 (local.get $n))) 23 | ) 24 | ) 25 | ) 26 | (return (local.get $n)) 27 | ) 28 | ) 29 | ) 30 | ) 31 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/is_even.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func $is_even (export "is_even") (param $a i32) (result i32) 3 | (if (result i32) 4 | (i32.eqz (local.get $a)) 5 | (then 6 | (i32.const 1) 7 | ) 8 | (else 9 | (call $is_odd (i32.sub (local.get $a) (i32.const 1))) 10 | ) 11 | ) 12 | ) 13 | (func $is_odd (param $a i32) (result i32) 14 | (if (result i32) 15 | (i32.eqz (local.get $a)) 16 | (then 17 | (i32.const 0) 18 | ) 19 | (else 20 | (call $is_even (i32.sub (local.get $a) (i32.const 1))) 21 | ) 22 | ) 23 | ) 24 | ) 25 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/memory-fill.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `fill` that fills the bytes of the 2 | ;; linear memory with the given `u8`-wrapped `i32` value. 3 | ;; 4 | ;; # Note 5 | ;; 6 | ;; The `len` and `offset` parameters tell where to fill 7 | ;; contents within the linear memory. 8 | (module 9 | (memory (export "mem") 1) 10 | (func (export "fill_bytes") (param $ptr i32) (param $len i32) (param $value i32) 11 | (local $n i32) 12 | (block $exit 13 | (loop $loop 14 | (br_if ;; exit loop if $n == $len 15 | $exit 16 | (i32.eq 17 | (local.get $n) 18 | (local.get $len) 19 | ) 20 | ) 21 | (i32.store8 offset=0 ;; store $value at mem[ptr+n] 22 | (i32.add 23 | (local.get $ptr) 24 | (local.get $n) 25 | ) 26 | (local.get $value) 27 | ) 28 | (local.set $n ;; increment n 29 | (i32.add (local.get $n) (i32.const 1)) 30 | ) 31 | (br $loop) ;; continue loop 32 | ) 33 | ) 34 | (return) 35 | ) 36 | ) 37 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/memory-sum.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `sum` that returns the sum of the linear memory 2 | ;; contents until the given `limit`. 3 | (module 4 | (memory (export "mem") 1) 5 | (func (export "sum_bytes") (param $limit i32) (result i64) 6 | (local $n i32) 7 | (local $sum i64) 8 | (block $exit 9 | (loop $loop 10 | (br_if ;; exit loop if $n == $limit 11 | $exit 12 | (i32.eq 13 | (local.get $n) 14 | (local.get $limit) 15 | ) 16 | ) 17 | (local.set $sum ;; load n-th value from memory and add to sum 18 | (i64.add 19 | (local.get $sum) 20 | (i64.load8_u offset=0 (local.get $n)) 21 | ) 22 | ) 23 | (local.set $n ;; increment n 24 | (i32.add (local.get $n) (i32.const 1)) 25 | ) 26 | (br $loop) ;; continue loop 27 | ) 28 | ) 29 | (return (local.get $sum)) 30 | ) 31 | ) 32 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/recursive_ok.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `call` that takes an input `n`. 2 | ;; The exported function calls itself `n` times. 3 | (module 4 | (func $call (export "call") (param $n i32) (result i32) 5 | (if (result i32) 6 | (local.get $n) 7 | (then 8 | (return 9 | (call $call 10 | (i32.sub 11 | (local.get $n) 12 | (i32.const 1) 13 | ) 14 | ) 15 | ) 16 | ) 17 | (else 18 | (return (local.get $n)) 19 | ) 20 | ) 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/recursive_scan.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `linear_integral` that takes an input `n`. 2 | ;; It recursively calls itself with decreasing `n` and summing 3 | ;; up the chain of `n` values. 4 | ;; Therefore the exported function calls itself `n` times. 5 | ;; 6 | ;; Basically this function describes: f(n) := (n²+n)/2 7 | (module 8 | (func $func (export "func") (param $n i32) (result i32) 9 | (if (result i32) 10 | (i32.eq (local.get $n) (i32.const 0)) 11 | (then 12 | ;; return 0 if $n == 0 13 | (i32.const 0) 14 | ) 15 | (else 16 | ;; return $n + (call $func($n - 1)) otherwise 17 | (i32.add 18 | (call $func 19 | (i32.sub 20 | (local.get $n) 21 | (i32.const 1) 22 | ) 23 | ) 24 | (local.get $n) 25 | ) 26 | ) 27 | ) 28 | ) 29 | ) 30 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/recursive_trap.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `call` that takes an input `n`. 2 | ;; The exported function calls itself `n` times and traps afterwards. 3 | (module 4 | (func $call (export "call") (param $n i32) (result i32) 5 | (if (result i32) 6 | (local.get $n) 7 | (then 8 | (return 9 | (call $call 10 | (i32.sub 11 | (local.get $n) 12 | (i32.const 1) 13 | ) 14 | ) 15 | ) 16 | ) 17 | (else (unreachable)) 18 | ) 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/benches/wat/trunc_f2i.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "trunc_f2i") (param $n i32) (param $input32 f32) (param $input64 f64) (result) 3 | (local $i i32) 4 | (block $exit 5 | (if 6 | (i32.le_u 7 | (local.get $n) 8 | (i32.const 0) 9 | ) 10 | (then (unreachable)) ;; trap if $n <= 0 11 | ) 12 | (local.set $i (local.get $n)) ;; i = n 13 | (loop $continue 14 | (drop 15 | (i32.trunc_f32_s (local.get $input32)) ;; <- under test 16 | ) 17 | (drop 18 | (i32.trunc_f32_u (local.get $input32)) ;; <- under test 19 | ) 20 | (drop 21 | (i64.trunc_f32_s (local.get $input32)) ;; <- under test 22 | ) 23 | (drop 24 | (i64.trunc_f64_u (local.get $input64)) ;; <- under test 25 | ) 26 | (drop 27 | (i32.trunc_f64_s (local.get $input64)) ;; <- under test 28 | ) 29 | (drop 30 | (i32.trunc_f64_u (local.get $input64)) ;; <- under test 31 | ) 32 | (drop 33 | (i64.trunc_f64_s (local.get $input64)) ;; <- under test 34 | ) 35 | (drop 36 | (i64.trunc_f64_u (local.get $input64)) ;; <- under test 37 | ) 38 | (local.set $i ;; i -= 1 39 | (i32.sub (local.get $i) (i32.const 1)) 40 | ) 41 | (br_if $continue (local.get $i)) ;; continue if i != 0 42 | ) 43 | ) 44 | ) 45 | ) 46 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/bytecode/tests.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use core::mem::size_of; 3 | 4 | #[test] 5 | fn size_of_instruction() { 6 | assert_eq!(size_of::(), 8); 7 | assert_eq!(size_of::(), 4); 8 | assert_eq!(size_of::(), 4); 9 | assert_eq!(size_of::(), 4); 10 | assert_eq!(size_of::(), 4); 11 | assert_eq!(size_of::(), 4); 12 | assert_eq!(size_of::(), 4); 13 | assert_eq!(size_of::(), 4); 14 | assert_eq!(size_of::(), 4); 15 | assert_eq!(size_of::(), 4); 16 | assert_eq!(size_of::(), 4); 17 | assert_eq!(size_of::(), 4); 18 | } 19 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/func_builder/mod.rs: -------------------------------------------------------------------------------- 1 | mod control_frame; 2 | mod control_stack; 3 | mod error; 4 | mod inst_builder; 5 | pub(crate) mod labels; 6 | mod locals_registry; 7 | mod translator; 8 | mod value_stack; 9 | 10 | use self::{control_frame::ControlFrame, control_stack::ControlFlowStack}; 11 | pub use self::{ 12 | error::{TranslationError, TranslationErrorInner}, 13 | inst_builder::{Instr, InstructionsBuilder, RelativeDepth}, 14 | translator::{FuncTranslator, FuncTranslatorAllocations}, 15 | }; 16 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/bytecode/tests.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use std::mem::size_of; 3 | 4 | #[test] 5 | fn bytecode_size() { 6 | assert_eq!(size_of::(), 2); 7 | assert_eq!(size_of::(), 4); 8 | assert_eq!(size_of::(), 6); 9 | assert_eq!(size_of::>(), 6); 10 | assert_eq!(size_of::>(), 6); 11 | assert_eq!(size_of::(), 8); 12 | } 13 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/executor/instrs/global.rs: -------------------------------------------------------------------------------- 1 | use super::Executor; 2 | use crate::engine::{ 3 | bytecode::GlobalIdx, 4 | regmach::bytecode::{Const16, Register}, 5 | }; 6 | use wasmi_core::UntypedValue; 7 | 8 | #[cfg(doc)] 9 | use crate::engine::regmach::bytecode::Instruction; 10 | 11 | impl<'ctx, 'engine> Executor<'ctx, 'engine> { 12 | /// Executes an [`Instruction::GlobalGet`]. 13 | #[inline(always)] 14 | pub fn execute_global_get(&mut self, result: Register, global: GlobalIdx) { 15 | let value = self.cache.get_global(self.ctx, global); 16 | self.set_register(result, value); 17 | self.next_instr() 18 | } 19 | 20 | /// Executes an [`Instruction::GlobalSet`]. 21 | #[inline(always)] 22 | pub fn execute_global_set(&mut self, global: GlobalIdx, input: Register) { 23 | let input = self.get_register(input); 24 | self.execute_global_set_impl(global, input) 25 | } 26 | 27 | /// Executes an [`Instruction::GlobalSetI32Imm16`]. 28 | #[inline(always)] 29 | pub fn execute_global_set_i32imm16(&mut self, global: GlobalIdx, input: Const16) { 30 | let input = i32::from(input).into(); 31 | self.execute_global_set_impl(global, input) 32 | } 33 | 34 | /// Executes an [`Instruction::GlobalSetI64Imm16`]. 35 | #[inline(always)] 36 | pub fn execute_global_set_i64imm16(&mut self, global: GlobalIdx, input: Const16) { 37 | let input = i64::from(input).into(); 38 | self.execute_global_set_impl(global, input) 39 | } 40 | 41 | /// Executes a generic `global.set` instruction. 42 | fn execute_global_set_impl(&mut self, global: GlobalIdx, new_value: UntypedValue) { 43 | self.cache.set_global(self.ctx, global, new_value); 44 | self.next_instr() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f32_copysign.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::engine::regmach::bytecode::Sign; 3 | 4 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F32, "copysign"); 5 | 6 | #[test] 7 | #[cfg_attr(miri, ignore)] 8 | fn reg_reg() { 9 | test_binary_reg_reg(WASM_OP, Instruction::f32_copysign) 10 | } 11 | 12 | #[test] 13 | #[cfg_attr(miri, ignore)] 14 | fn reg_imm() { 15 | fn make_instrs(sign: Sign) -> [Instruction; 2] { 16 | [ 17 | Instruction::f32_copysign_imm(Register::from_i16(1), Register::from_i16(0), sign), 18 | Instruction::return_reg(1), 19 | ] 20 | } 21 | test_binary_reg_imm_with(WASM_OP, 1.0_f32, make_instrs(Sign::Pos)).run(); 22 | test_binary_reg_imm_with(WASM_OP, -1.0_f32, make_instrs(Sign::Neg)).run(); 23 | } 24 | 25 | #[test] 26 | #[cfg_attr(miri, ignore)] 27 | fn reg_imm_rev() { 28 | test_binary_reg_imm32_rev(WASM_OP, 1.0_f32, Instruction::f32_copysign) 29 | } 30 | 31 | #[test] 32 | #[cfg_attr(miri, ignore)] 33 | fn consteval() { 34 | let lhs = 13.0_f32; 35 | test_binary_consteval( 36 | WASM_OP, 37 | lhs, 38 | 1.0, 39 | [Instruction::ReturnImm32 { 40 | value: AnyConst32::from(lhs), 41 | }], 42 | ); 43 | test_binary_consteval( 44 | WASM_OP, 45 | lhs, 46 | -1.0, 47 | [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(-lhs), 49 | }], 50 | ); 51 | } 52 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f32_div.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F32, "div"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::f32_div) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm() { 14 | test_binary_reg_imm32(WASM_OP, 1.0_f32, Instruction::f32_div) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm_rev() { 20 | test_binary_reg_imm32_rev(WASM_OP, 1.0_f32, Instruction::f32_div) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_nan() { 26 | test_binary_reg_imm_with(WASM_OP, f32::NAN, [Instruction::return_imm32(f32::NAN)]).run() 27 | } 28 | 29 | #[test] 30 | #[cfg_attr(miri, ignore)] 31 | fn nan_reg() { 32 | test_binary_reg_imm_rev_with(WASM_OP, f32::NAN, [Instruction::return_imm32(f32::NAN)]).run() 33 | } 34 | 35 | #[test] 36 | #[cfg_attr(miri, ignore)] 37 | fn consteval() { 38 | let lhs = 13.0_f32; 39 | let rhs = 5.5; 40 | test_binary_consteval( 41 | WASM_OP, 42 | lhs, 43 | rhs, 44 | [Instruction::ReturnImm32 { 45 | value: AnyConst32::from(lhs / rhs), 46 | }], 47 | ) 48 | } 49 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f32_max.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F32, "max"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::f32_max) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm() { 14 | test_binary_reg_imm32(WASM_OP, 1.0_f32, Instruction::f32_max) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm_rev() { 20 | test_binary_reg_imm32_rev_commutative(WASM_OP, 1.0_f32, Instruction::f32_max) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_nan() { 26 | test_binary_reg_imm_with(WASM_OP, f32::NAN, [Instruction::return_imm32(f32::NAN)]).run() 27 | } 28 | 29 | #[test] 30 | #[cfg_attr(miri, ignore)] 31 | fn nan_reg() { 32 | test_binary_reg_imm_rev_with(WASM_OP, f32::NAN, [Instruction::return_imm32(f32::NAN)]).run() 33 | } 34 | 35 | #[test] 36 | #[cfg_attr(miri, ignore)] 37 | fn reg_neg_infinity() { 38 | let expected = [Instruction::return_reg(0)]; 39 | test_binary_reg_imm_with(WASM_OP, f32::NEG_INFINITY, expected).run() 40 | } 41 | 42 | #[test] 43 | #[cfg_attr(miri, ignore)] 44 | fn reg_neg_infinity_rev() { 45 | let expected = [Instruction::return_reg(0)]; 46 | test_binary_reg_imm_rev_with(WASM_OP, f32::NEG_INFINITY, expected).run() 47 | } 48 | 49 | #[test] 50 | #[cfg_attr(miri, ignore)] 51 | fn consteval() { 52 | let lhs = 1.0_f32; 53 | let rhs = 2.0; 54 | let result = if rhs > lhs { rhs } else { lhs }; 55 | test_binary_consteval( 56 | WASM_OP, 57 | lhs, 58 | rhs, 59 | [Instruction::ReturnImm32 { 60 | value: AnyConst32::from(result), 61 | }], 62 | ) 63 | } 64 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f32_min.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F32, "min"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::f32_min) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm() { 14 | test_binary_reg_imm32(WASM_OP, 1.0_f32, Instruction::f32_min) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm_rev() { 20 | test_binary_reg_imm32_rev_commutative(WASM_OP, 1.0_f32, Instruction::f32_min) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_nan() { 26 | test_binary_reg_imm_with(WASM_OP, f32::NAN, [Instruction::return_imm32(f32::NAN)]).run() 27 | } 28 | 29 | #[test] 30 | #[cfg_attr(miri, ignore)] 31 | fn nan_reg() { 32 | test_binary_reg_imm_rev_with(WASM_OP, f32::NAN, [Instruction::return_imm32(f32::NAN)]).run() 33 | } 34 | 35 | #[test] 36 | #[cfg_attr(miri, ignore)] 37 | fn reg_pos_infinity() { 38 | let expected = [Instruction::return_reg(0)]; 39 | test_binary_reg_imm_with(WASM_OP, f32::INFINITY, expected).run() 40 | } 41 | 42 | #[test] 43 | #[cfg_attr(miri, ignore)] 44 | fn reg_pos_infinity_rev() { 45 | let expected = [Instruction::return_reg(0)]; 46 | test_binary_reg_imm_rev_with(WASM_OP, f32::INFINITY, expected).run() 47 | } 48 | 49 | #[test] 50 | #[cfg_attr(miri, ignore)] 51 | fn consteval() { 52 | let lhs = 1.0_f32; 53 | let rhs = 2.0; 54 | let result = if rhs < lhs { rhs } else { lhs }; 55 | test_binary_consteval( 56 | WASM_OP, 57 | lhs, 58 | rhs, 59 | [Instruction::ReturnImm32 { 60 | value: AnyConst32::from(result), 61 | }], 62 | ) 63 | } 64 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f32_mul.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F32, "mul"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::f32_mul) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm() { 14 | test_binary_reg_imm32(WASM_OP, 1.0_f32, Instruction::f32_mul) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm_rev() { 20 | test_binary_reg_imm32_rev_commutative(WASM_OP, 1.0_f32, Instruction::f32_mul) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_nan() { 26 | test_binary_reg_imm_with(WASM_OP, f32::NAN, [Instruction::return_imm32(f32::NAN)]).run() 27 | } 28 | 29 | #[test] 30 | #[cfg_attr(miri, ignore)] 31 | fn nan_reg() { 32 | test_binary_reg_imm_rev_with(WASM_OP, f32::NAN, [Instruction::return_imm32(f32::NAN)]).run() 33 | } 34 | 35 | #[test] 36 | #[cfg_attr(miri, ignore)] 37 | fn consteval() { 38 | let lhs = 5.0_f32; 39 | let rhs = 13.0; 40 | test_binary_consteval( 41 | WASM_OP, 42 | lhs, 43 | rhs, 44 | [Instruction::ReturnImm32 { 45 | value: AnyConst32::from(lhs * rhs), 46 | }], 47 | ) 48 | } 49 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f32_sub.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F32, "sub"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::f32_sub) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm() { 14 | test_binary_reg_imm32(WASM_OP, 1.0_f32, Instruction::f32_sub) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm_rev() { 20 | test_binary_reg_imm32_rev(WASM_OP, 1.0_f32, Instruction::f32_sub) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_nan() { 26 | test_binary_reg_imm_with(WASM_OP, f32::NAN, [Instruction::return_imm32(f32::NAN)]).run() 27 | } 28 | 29 | #[test] 30 | #[cfg_attr(miri, ignore)] 31 | fn nan_reg() { 32 | test_binary_reg_imm_rev_with(WASM_OP, f32::NAN, [Instruction::return_imm32(f32::NAN)]).run() 33 | } 34 | 35 | #[test] 36 | #[cfg_attr(miri, ignore)] 37 | fn reg_zero() { 38 | // We cannot optimize `x - 0` -> `x` because `-0 - 0` -> `0` according to IEEE. 39 | let expected = [ 40 | Instruction::f32_sub( 41 | Register::from_i16(1), 42 | Register::from_i16(0), 43 | Register::from_i16(-1), 44 | ), 45 | Instruction::return_reg(1), 46 | ]; 47 | testcase_binary_reg_imm(WASM_OP, 0.0_f32) 48 | .expect_func(ExpectedFunc::new(expected).consts([0.0_f32])) 49 | .run() 50 | } 51 | 52 | #[test] 53 | #[cfg_attr(miri, ignore)] 54 | fn consteval() { 55 | let lhs = 13.0_f32; 56 | let rhs = 5.5; 57 | test_binary_consteval( 58 | WASM_OP, 59 | lhs, 60 | rhs, 61 | [Instruction::ReturnImm32 { 62 | value: AnyConst32::from(lhs - rhs), 63 | }], 64 | ) 65 | } 66 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f64_copysign.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::engine::regmach::bytecode::Sign; 3 | 4 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F64, "copysign"); 5 | 6 | #[test] 7 | #[cfg_attr(miri, ignore)] 8 | fn reg_reg() { 9 | test_binary_reg_reg(WASM_OP, Instruction::f64_copysign) 10 | } 11 | 12 | #[test] 13 | #[cfg_attr(miri, ignore)] 14 | fn reg_imm() { 15 | fn make_instrs(sign: Sign) -> [Instruction; 2] { 16 | [ 17 | Instruction::f64_copysign_imm(Register::from_i16(1), Register::from_i16(0), sign), 18 | Instruction::return_reg(1), 19 | ] 20 | } 21 | test_binary_reg_imm_with(WASM_OP, 1.0_f64, make_instrs(Sign::Pos)).run(); 22 | test_binary_reg_imm_with(WASM_OP, -1.0_f64, make_instrs(Sign::Neg)).run(); 23 | } 24 | 25 | #[test] 26 | #[cfg_attr(miri, ignore)] 27 | fn reg_imm_rev() { 28 | test_binary_reg_imm32_rev(WASM_OP, 1.0_f64, Instruction::f64_copysign) 29 | } 30 | 31 | #[test] 32 | #[cfg_attr(miri, ignore)] 33 | fn consteval() { 34 | let lhs = 13.0_f64; 35 | testcase_binary_consteval(WASM_OP, lhs, 1.0) 36 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(lhs)])) 37 | .run(); 38 | testcase_binary_consteval(WASM_OP, lhs, -1.0) 39 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(-lhs)])) 40 | .run(); 41 | } 42 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f64_div.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F64, "div"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::f64_div) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm() { 14 | test_binary_reg_imm32(WASM_OP, 1.0_f64, Instruction::f64_div) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm_rev() { 20 | test_binary_reg_imm32_rev(WASM_OP, 1.0_f64, Instruction::f64_div) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_nan() { 26 | testcase_binary_reg_imm(WASM_OP, f64::NAN) 27 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(f64::NAN)])) 28 | .run(); 29 | } 30 | 31 | #[test] 32 | #[cfg_attr(miri, ignore)] 33 | fn nan_reg() { 34 | testcase_binary_imm_reg(WASM_OP, f64::NAN) 35 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(f64::NAN)])) 36 | .run(); 37 | } 38 | 39 | #[test] 40 | #[cfg_attr(miri, ignore)] 41 | fn consteval() { 42 | let lhs = 12.0_f64; 43 | let rhs = 2.0; 44 | let result = lhs / rhs; 45 | testcase_binary_consteval(WASM_OP, lhs, rhs) 46 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(result)])) 47 | .run(); 48 | } 49 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f64_max.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F64, "max"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::f64_max) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm() { 14 | test_binary_reg_imm32(WASM_OP, 1.0_f64, Instruction::f64_max) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm_rev() { 20 | test_binary_reg_imm32_rev_commutative(WASM_OP, 1.0_f64, Instruction::f64_max) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_nan() { 26 | testcase_binary_reg_imm(WASM_OP, f64::NAN) 27 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(f64::NAN)])) 28 | .run(); 29 | } 30 | 31 | #[test] 32 | #[cfg_attr(miri, ignore)] 33 | fn nan_reg() { 34 | testcase_binary_imm_reg(WASM_OP, f64::NAN) 35 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(f64::NAN)])) 36 | .run(); 37 | } 38 | 39 | #[test] 40 | #[cfg_attr(miri, ignore)] 41 | fn reg_neg_infinity() { 42 | let expected = [Instruction::return_reg(0)]; 43 | test_binary_reg_imm_with(WASM_OP, f64::NEG_INFINITY, expected).run() 44 | } 45 | 46 | #[test] 47 | #[cfg_attr(miri, ignore)] 48 | fn reg_neg_infinity_rev() { 49 | let expected = [Instruction::return_reg(0)]; 50 | test_binary_reg_imm_rev_with(WASM_OP, f64::NEG_INFINITY, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn consteval() { 56 | let lhs = 1.0_f64; 57 | let rhs = 2.0; 58 | let result = if rhs > lhs { rhs } else { lhs }; 59 | testcase_binary_consteval(WASM_OP, lhs, rhs) 60 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(result)])) 61 | .run(); 62 | } 63 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f64_min.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F64, "min"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::f64_min) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm() { 14 | test_binary_reg_imm32(WASM_OP, 1.0_f64, Instruction::f64_min) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm_rev() { 20 | test_binary_reg_imm32_rev_commutative(WASM_OP, 1.0_f64, Instruction::f64_min) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_nan() { 26 | testcase_binary_reg_imm(WASM_OP, f64::NAN) 27 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(f64::NAN)])) 28 | .run(); 29 | } 30 | 31 | #[test] 32 | #[cfg_attr(miri, ignore)] 33 | fn nan_reg() { 34 | testcase_binary_imm_reg(WASM_OP, f64::NAN) 35 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(f64::NAN)])) 36 | .run(); 37 | } 38 | 39 | #[test] 40 | #[cfg_attr(miri, ignore)] 41 | fn reg_pos_infinity() { 42 | let expected = [Instruction::return_reg(0)]; 43 | test_binary_reg_imm_with(WASM_OP, f64::INFINITY, expected).run() 44 | } 45 | 46 | #[test] 47 | #[cfg_attr(miri, ignore)] 48 | fn reg_pos_infinity_rev() { 49 | let expected = [Instruction::return_reg(0)]; 50 | test_binary_reg_imm_rev_with(WASM_OP, f64::INFINITY, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn consteval() { 56 | let lhs = 1.0_f64; 57 | let rhs = 2.0; 58 | let result = if rhs < lhs { rhs } else { lhs }; 59 | testcase_binary_consteval(WASM_OP, lhs, rhs) 60 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(result)])) 61 | .run(); 62 | } 63 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f64_mul.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F64, "mul"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::f64_mul) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm() { 14 | test_binary_reg_imm32(WASM_OP, 1.0_f64, Instruction::f64_mul) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm_rev() { 20 | test_binary_reg_imm32_rev_commutative(WASM_OP, 1.0_f64, Instruction::f64_mul) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_nan() { 26 | testcase_binary_reg_imm(WASM_OP, f64::NAN) 27 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(f64::NAN)])) 28 | .run(); 29 | } 30 | 31 | #[test] 32 | #[cfg_attr(miri, ignore)] 33 | fn nan_reg() { 34 | testcase_binary_imm_reg(WASM_OP, f64::NAN) 35 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(f64::NAN)])) 36 | .run(); 37 | } 38 | 39 | #[test] 40 | #[cfg_attr(miri, ignore)] 41 | fn consteval() { 42 | let lhs = 5.0_f64; 43 | let rhs = 13.0; 44 | let result = lhs * rhs; 45 | testcase_binary_consteval(WASM_OP, lhs, rhs) 46 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(result)])) 47 | .run(); 48 | } 49 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/f64_sub.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::F64, "sub"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::f64_sub) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm() { 14 | test_binary_reg_imm32(WASM_OP, 1.0_f64, Instruction::f64_sub) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm_rev() { 20 | test_binary_reg_imm32_rev(WASM_OP, 1.0_f64, Instruction::f64_sub) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_nan() { 26 | testcase_binary_reg_imm(WASM_OP, f64::NAN) 27 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(f64::NAN)])) 28 | .run(); 29 | } 30 | 31 | #[test] 32 | #[cfg_attr(miri, ignore)] 33 | fn nan_reg() { 34 | testcase_binary_imm_reg(WASM_OP, f64::NAN) 35 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(f64::NAN)])) 36 | .run(); 37 | } 38 | 39 | #[test] 40 | #[cfg_attr(miri, ignore)] 41 | fn reg_zero() { 42 | // We cannot optimize `x - 0` -> `x` because `-0 - 0` -> `0` according to IEEE. 43 | let expected = [ 44 | Instruction::f64_sub( 45 | Register::from_i16(1), 46 | Register::from_i16(0), 47 | Register::from_i16(-1), 48 | ), 49 | Instruction::return_reg(1), 50 | ]; 51 | testcase_binary_reg_imm(WASM_OP, 0.0_f64) 52 | .expect_func(ExpectedFunc::new(expected).consts([0.0_f64])) 53 | .run() 54 | } 55 | 56 | #[test] 57 | #[cfg_attr(miri, ignore)] 58 | fn consteval() { 59 | let lhs = 13.0_f64; 60 | let rhs = 5.5; 61 | let result = lhs - rhs; 62 | testcase_binary_consteval(WASM_OP, lhs, rhs) 63 | .expect_func(ExpectedFunc::new([return_f64imm32_instr(result)])) 64 | .run(); 65 | } 66 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/i32_add.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::I32, "add"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::i32_add) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm16() { 14 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_add_imm16) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm16_rev() { 20 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_add_imm16)) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_imm() { 26 | test_binary_reg_imm32(WASM_OP, i32::MAX, Instruction::i32_add) 27 | } 28 | 29 | #[test] 30 | #[cfg_attr(miri, ignore)] 31 | fn reg_imm_rev() { 32 | test_binary_reg_imm32_rev_commutative(WASM_OP, i32::MAX, Instruction::i32_add) 33 | } 34 | 35 | #[test] 36 | #[cfg_attr(miri, ignore)] 37 | fn reg_zero() { 38 | let expected = [Instruction::return_reg(0)]; 39 | test_binary_reg_imm_with(WASM_OP, 0i32, expected).run() 40 | } 41 | 42 | #[test] 43 | #[cfg_attr(miri, ignore)] 44 | fn reg_zero_rev() { 45 | let expected = [Instruction::return_reg(0)]; 46 | test_binary_reg_imm_rev_with(WASM_OP, 0i32, expected).run() 47 | } 48 | 49 | #[test] 50 | #[cfg_attr(miri, ignore)] 51 | fn consteval() { 52 | let lhs = 1; 53 | let rhs = 2; 54 | test_binary_consteval( 55 | WASM_OP, 56 | lhs, 57 | rhs, 58 | [Instruction::ReturnImm32 { 59 | value: AnyConst32::from_i32(lhs + rhs), 60 | }], 61 | ) 62 | } 63 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/i32_sub.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::I32, "sub"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from_i32(0), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_sub) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_sub_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, Instruction::i32_sub_imm16_rev) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, i32::MAX, Instruction::i32_sub) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, i32::MAX, Instruction::i32_sub) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_zero() { 47 | let expected = [Instruction::return_reg(0)]; 48 | test_binary_reg_imm_with(WASM_OP, 0i32, expected).run() 49 | } 50 | 51 | #[test] 52 | #[cfg_attr(miri, ignore)] 53 | fn consteval() { 54 | let lhs = 1; 55 | let rhs = 2; 56 | test_binary_consteval( 57 | WASM_OP, 58 | lhs, 59 | rhs, 60 | [Instruction::ReturnImm32 { 61 | value: AnyConst32::from_i32(lhs - rhs), 62 | }], 63 | ) 64 | } 65 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/i32_xor.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::I32, "xor"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from_i32(0), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_xor) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_xor_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_xor_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, i32::MAX, Instruction::i32_xor) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev_commutative(WASM_OP, i32::MAX, Instruction::i32_xor) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_zero() { 47 | let expected = [Instruction::return_reg(0)]; 48 | test_binary_reg_imm_with(WASM_OP, 0i32, expected).run() 49 | } 50 | 51 | #[test] 52 | #[cfg_attr(miri, ignore)] 53 | fn reg_zero_rev() { 54 | let expected = [Instruction::return_reg(0)]; 55 | test_binary_reg_imm_rev_with(WASM_OP, 0i32, expected).run() 56 | } 57 | 58 | #[test] 59 | #[cfg_attr(miri, ignore)] 60 | fn consteval() { 61 | let lhs = 10; 62 | let rhs = 20; 63 | test_binary_consteval( 64 | WASM_OP, 65 | lhs, 66 | rhs, 67 | [Instruction::ReturnImm32 { 68 | value: AnyConst32::from_i32(lhs ^ rhs), 69 | }], 70 | ) 71 | } 72 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/i64_add.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::I64, "add"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::i64_add) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm16() { 14 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_add_imm16) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm16_rev() { 20 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_add_imm16)) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_imm() { 26 | test_binary_reg_imm32(WASM_OP, i64::MAX, Instruction::i64_add) 27 | } 28 | 29 | #[test] 30 | #[cfg_attr(miri, ignore)] 31 | fn reg_imm_rev() { 32 | test_binary_reg_imm32_rev_commutative(WASM_OP, i64::MAX, Instruction::i64_add) 33 | } 34 | 35 | #[test] 36 | #[cfg_attr(miri, ignore)] 37 | fn reg_zero() { 38 | let expected = [Instruction::return_reg(0)]; 39 | test_binary_reg_imm_with(WASM_OP, 0i32, expected).run() 40 | } 41 | 42 | #[test] 43 | #[cfg_attr(miri, ignore)] 44 | fn reg_zero_rev() { 45 | let expected = [Instruction::return_reg(0)]; 46 | test_binary_reg_imm_rev_with(WASM_OP, 0i32, expected).run() 47 | } 48 | 49 | #[test] 50 | #[cfg_attr(miri, ignore)] 51 | fn consteval() { 52 | let lhs = 1; 53 | let rhs = 2; 54 | test_binary_consteval(WASM_OP, lhs, rhs, [return_i64imm32_instr(lhs + rhs)]) 55 | } 56 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/i64_mul.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::I64, "mul"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn reg_reg() { 8 | test_binary_reg_reg(WASM_OP, Instruction::i64_mul) 9 | } 10 | 11 | #[test] 12 | #[cfg_attr(miri, ignore)] 13 | fn reg_imm16() { 14 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_mul_imm16) 15 | } 16 | 17 | #[test] 18 | #[cfg_attr(miri, ignore)] 19 | fn reg_imm16_rev() { 20 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_mul_imm16)) 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg_imm() { 26 | test_binary_reg_imm32(WASM_OP, i64::MAX, Instruction::i64_mul) 27 | } 28 | 29 | #[test] 30 | #[cfg_attr(miri, ignore)] 31 | fn reg_imm_rev() { 32 | test_binary_reg_imm32_rev_commutative(WASM_OP, i64::MAX, Instruction::i64_mul) 33 | } 34 | 35 | #[test] 36 | #[cfg_attr(miri, ignore)] 37 | fn reg_zero() { 38 | let expected = [return_i64imm32_instr(0)]; 39 | test_binary_reg_imm_with(WASM_OP, 0_i64, expected).run() 40 | } 41 | 42 | #[test] 43 | #[cfg_attr(miri, ignore)] 44 | fn reg_zero_rev() { 45 | let expected = [return_i64imm32_instr(0)]; 46 | test_binary_reg_imm_rev_with(WASM_OP, 0_i64, expected).run() 47 | } 48 | 49 | #[test] 50 | #[cfg_attr(miri, ignore)] 51 | fn reg_one() { 52 | let expected = [Instruction::return_reg(0)]; 53 | test_binary_reg_imm_with(WASM_OP, 1_i32, expected).run() 54 | } 55 | 56 | #[test] 57 | #[cfg_attr(miri, ignore)] 58 | fn reg_one_rev() { 59 | let expected = [Instruction::return_reg(0)]; 60 | test_binary_reg_imm_rev_with(WASM_OP, 1_i32, expected).run() 61 | } 62 | 63 | #[test] 64 | #[cfg_attr(miri, ignore)] 65 | fn consteval() { 66 | let lhs = 1; 67 | let rhs = 2; 68 | test_binary_consteval(WASM_OP, lhs, rhs, [return_i64imm32_instr(lhs * rhs)]) 69 | } 70 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/i64_sub.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::I64, "sub"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [return_i64imm32_instr(0)]; 9 | test_binary_same_reg(WASM_OP, expected) 10 | } 11 | 12 | #[test] 13 | #[cfg_attr(miri, ignore)] 14 | fn reg_reg() { 15 | test_binary_reg_reg(WASM_OP, Instruction::i64_sub) 16 | } 17 | 18 | #[test] 19 | #[cfg_attr(miri, ignore)] 20 | fn reg_imm16() { 21 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_sub_imm16) 22 | } 23 | 24 | #[test] 25 | #[cfg_attr(miri, ignore)] 26 | fn reg_imm16_rev() { 27 | test_binary_reg_imm16_rev::(WASM_OP, 100, Instruction::i64_sub_imm16_rev) 28 | } 29 | 30 | #[test] 31 | #[cfg_attr(miri, ignore)] 32 | fn reg_imm() { 33 | test_binary_reg_imm32(WASM_OP, i64::MAX, Instruction::i64_sub) 34 | } 35 | 36 | #[test] 37 | #[cfg_attr(miri, ignore)] 38 | fn reg_imm_rev() { 39 | test_binary_reg_imm32_rev(WASM_OP, i64::MAX, Instruction::i64_sub) 40 | } 41 | 42 | #[test] 43 | #[cfg_attr(miri, ignore)] 44 | fn reg_zero() { 45 | let expected = [Instruction::return_reg(0)]; 46 | test_binary_reg_imm_with(WASM_OP, 0i32, expected).run() 47 | } 48 | 49 | #[test] 50 | #[cfg_attr(miri, ignore)] 51 | fn consteval() { 52 | let lhs = 1; 53 | let rhs = 2; 54 | test_binary_consteval(WASM_OP, lhs, rhs, [return_i64imm32_instr(lhs - rhs)]) 55 | } 56 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/i64_xor.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::binary(WasmType::I64, "xor"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [return_i64imm32_instr(0)]; 9 | test_binary_same_reg(WASM_OP, expected) 10 | } 11 | 12 | #[test] 13 | #[cfg_attr(miri, ignore)] 14 | fn reg_reg() { 15 | test_binary_reg_reg(WASM_OP, Instruction::i64_xor) 16 | } 17 | 18 | #[test] 19 | #[cfg_attr(miri, ignore)] 20 | fn reg_imm16() { 21 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_xor_imm16) 22 | } 23 | 24 | #[test] 25 | #[cfg_attr(miri, ignore)] 26 | fn reg_imm16_rev() { 27 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_xor_imm16)) 28 | } 29 | 30 | #[test] 31 | #[cfg_attr(miri, ignore)] 32 | fn reg_imm() { 33 | test_binary_reg_imm32(WASM_OP, i64::MAX, Instruction::i64_xor) 34 | } 35 | 36 | #[test] 37 | #[cfg_attr(miri, ignore)] 38 | fn reg_imm_rev() { 39 | test_binary_reg_imm32_rev_commutative(WASM_OP, i64::MAX, Instruction::i64_xor) 40 | } 41 | 42 | #[test] 43 | #[cfg_attr(miri, ignore)] 44 | fn reg_zero() { 45 | let expected = [Instruction::return_reg(0)]; 46 | test_binary_reg_imm_with(WASM_OP, 0i64, expected).run() 47 | } 48 | 49 | #[test] 50 | #[cfg_attr(miri, ignore)] 51 | fn reg_zero_rev() { 52 | let expected = [Instruction::return_reg(0)]; 53 | test_binary_reg_imm_rev_with(WASM_OP, 0i64, expected).run() 54 | } 55 | 56 | #[test] 57 | #[cfg_attr(miri, ignore)] 58 | fn consteval() { 59 | let lhs = 10; 60 | let rhs = 20; 61 | test_binary_consteval(WASM_OP, lhs, rhs, [return_i64imm32_instr(lhs ^ rhs)]) 62 | } 63 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/binary/mod.rs: -------------------------------------------------------------------------------- 1 | //! Translation tests for all generic binary Wasm instructions that do not fit a certain group. 2 | //! 3 | //! # Note 4 | //! 5 | //! These tests include Wasm arithmetic, logical, bitwise, shift and rotate instructions. 6 | 7 | use super::*; 8 | 9 | mod f32_add; 10 | mod f32_copysign; 11 | mod f32_div; 12 | mod f32_max; 13 | mod f32_min; 14 | mod f32_mul; 15 | mod f32_sub; 16 | mod f64_add; 17 | mod f64_copysign; 18 | mod f64_div; 19 | mod f64_max; 20 | mod f64_min; 21 | mod f64_mul; 22 | mod f64_sub; 23 | mod i32_add; 24 | mod i32_and; 25 | mod i32_div_s; 26 | mod i32_div_u; 27 | mod i32_mul; 28 | mod i32_or; 29 | mod i32_rem_s; 30 | mod i32_rem_u; 31 | mod i32_rotl; 32 | mod i32_rotr; 33 | mod i32_shl; 34 | mod i32_shr_s; 35 | mod i32_shr_u; 36 | mod i32_sub; 37 | mod i32_xor; 38 | mod i64_add; 39 | mod i64_and; 40 | mod i64_div_s; 41 | mod i64_div_u; 42 | mod i64_mul; 43 | mod i64_or; 44 | mod i64_rem_s; 45 | mod i64_rem_u; 46 | mod i64_rotl; 47 | mod i64_rotr; 48 | mod i64_shl; 49 | mod i64_shr_s; 50 | mod i64_shr_u; 51 | mod i64_sub; 52 | mod i64_xor; 53 | 54 | /// Creates an [`Instruction::ReturnF64Imm32`] from the given `f64` value. 55 | /// 56 | /// # Panics 57 | /// 58 | /// If the `value` cannot be converted into `f32` losslessly. 59 | fn return_f64imm32_instr(value: f64) -> Instruction { 60 | let const32 = >::from_f64(value).expect("value must be 32-bit encodable"); 61 | Instruction::return_f64imm32(const32) 62 | } 63 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/call/mod.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | mod imported; 4 | mod indirect; 5 | mod internal; 6 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/f32_eq.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::F32, "eq"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | // We cannot optimize `x == x` to `true` since `x == Nan` or `Nan == x` is always `false`. 9 | let expected = [ 10 | Instruction::f32_eq( 11 | Register::from_i16(1), 12 | Register::from_i16(0), 13 | Register::from_i16(0), 14 | ), 15 | Instruction::return_reg(Register::from_i16(1)), 16 | ]; 17 | test_binary_same_reg(WASM_OP, expected) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_reg() { 23 | test_binary_reg_reg(WASM_OP, Instruction::f32_eq) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm() { 29 | test_binary_reg_imm32(WASM_OP, 1.0_f32, Instruction::f32_eq) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm_rev() { 35 | test_binary_reg_imm32_rev_commutative(WASM_OP, 1.0_f32, Instruction::f32_eq) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_nan() { 41 | test_binary_reg_imm_with(WASM_OP, f32::NAN, [Instruction::return_imm32(false)]).run() 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn nan_reg() { 47 | test_binary_reg_imm_rev_with(WASM_OP, f32::NAN, [Instruction::return_imm32(false)]).run() 48 | } 49 | 50 | #[test] 51 | #[cfg_attr(miri, ignore)] 52 | fn consteval() { 53 | test_binary_consteval( 54 | WASM_OP, 55 | 1.0, 56 | 1.0, 57 | [Instruction::ReturnImm32 { 58 | value: AnyConst32::from(true), 59 | }], 60 | ); 61 | test_binary_consteval( 62 | WASM_OP, 63 | 0.0, 64 | 1.0, 65 | [Instruction::ReturnImm32 { 66 | value: AnyConst32::from(false), 67 | }], 68 | ); 69 | } 70 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/f32_ge.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::F32, "ge"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::f32_ge) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm() { 23 | test_binary_reg_imm32(WASM_OP, 1.0_f32, Instruction::f32_ge) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm_rev() { 29 | test_binary_reg_imm32_rev(WASM_OP, 1.0_f32, Instruction::f32_ge) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_nan() { 35 | test_binary_reg_imm_with(WASM_OP, f32::NAN, [Instruction::return_imm32(false)]).run() 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn nan_reg() { 41 | test_binary_reg_imm_rev_with(WASM_OP, f32::NAN, [Instruction::return_imm32(false)]).run() 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn consteval() { 47 | fn test_with(lhs: f32, rhs: f32, result: bool) { 48 | test_binary_consteval( 49 | WASM_OP, 50 | lhs, 51 | rhs, 52 | [Instruction::ReturnImm32 { 53 | value: AnyConst32::from(result), 54 | }], 55 | ); 56 | } 57 | test_with(1.0, 1.0, true); 58 | test_with(1.0, 2.0, false); 59 | test_with(2.0, 1.0, true); 60 | } 61 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/f32_le.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::F32, "le"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::f32_le) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm() { 23 | test_binary_reg_imm32(WASM_OP, 1.0_f32, Instruction::f32_le) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm_rev() { 29 | test_binary_reg_imm32_rev(WASM_OP, 1.0_f32, Instruction::f32_le) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_nan() { 35 | test_binary_reg_imm_with(WASM_OP, f32::NAN, [Instruction::return_imm32(false)]).run() 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn nan_reg() { 41 | test_binary_reg_imm_rev_with(WASM_OP, f32::NAN, [Instruction::return_imm32(false)]).run() 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn consteval() { 47 | fn test_with(lhs: f32, rhs: f32, result: bool) { 48 | test_binary_consteval( 49 | WASM_OP, 50 | lhs, 51 | rhs, 52 | [Instruction::ReturnImm32 { 53 | value: AnyConst32::from(result), 54 | }], 55 | ); 56 | } 57 | test_with(1.0, 1.0, true); 58 | test_with(1.0, 2.0, true); 59 | test_with(2.0, 1.0, false); 60 | } 61 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/f32_ne.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::F32, "ne"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | // We cannot optimize `x != x` to `false` since `x != Nan` or `Nan != x` is always `true`. 9 | let expected = [ 10 | Instruction::f32_ne( 11 | Register::from_i16(1), 12 | Register::from_i16(0), 13 | Register::from_i16(0), 14 | ), 15 | Instruction::return_reg(Register::from_i16(1)), 16 | ]; 17 | test_binary_same_reg(WASM_OP, expected) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_reg() { 23 | test_binary_reg_reg(WASM_OP, Instruction::f32_ne) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm() { 29 | test_binary_reg_imm32(WASM_OP, 1.0_f32, Instruction::f32_ne) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm_rev() { 35 | test_binary_reg_imm32_rev_commutative(WASM_OP, 1.0_f32, Instruction::f32_ne) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_nan() { 41 | test_binary_reg_imm_with(WASM_OP, f32::NAN, [Instruction::return_imm32(true)]).run() 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn nan_reg() { 47 | test_binary_reg_imm_rev_with(WASM_OP, f32::NAN, [Instruction::return_imm32(true)]).run() 48 | } 49 | 50 | #[test] 51 | #[cfg_attr(miri, ignore)] 52 | fn consteval() { 53 | test_binary_consteval( 54 | WASM_OP, 55 | 1.0, 56 | 1.0, 57 | [Instruction::ReturnImm32 { 58 | value: AnyConst32::from(false), 59 | }], 60 | ); 61 | test_binary_consteval( 62 | WASM_OP, 63 | 0.0, 64 | 1.0, 65 | [Instruction::ReturnImm32 { 66 | value: AnyConst32::from(true), 67 | }], 68 | ); 69 | } 70 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/f64_eq.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::F64, "eq"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | // We cannot optimize `x == x` to `true` since `x == Nan` or `Nan == x` is always `false`. 9 | let expected = [ 10 | Instruction::f64_eq( 11 | Register::from_i16(1), 12 | Register::from_i16(0), 13 | Register::from_i16(0), 14 | ), 15 | Instruction::return_reg(Register::from_i16(1)), 16 | ]; 17 | test_binary_same_reg(WASM_OP, expected) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_reg() { 23 | test_binary_reg_reg(WASM_OP, Instruction::f64_eq) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm() { 29 | test_binary_reg_imm32(WASM_OP, 1.0_f64, Instruction::f64_eq) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm_rev() { 35 | test_binary_reg_imm32_rev_commutative(WASM_OP, 1.0_f64, Instruction::f64_eq) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_nan() { 41 | test_binary_reg_imm_with(WASM_OP, f64::NAN, [Instruction::return_imm32(false)]).run() 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn nan_reg() { 47 | test_binary_reg_imm_rev_with(WASM_OP, f64::NAN, [Instruction::return_imm32(false)]).run() 48 | } 49 | 50 | #[test] 51 | #[cfg_attr(miri, ignore)] 52 | fn consteval() { 53 | test_binary_consteval( 54 | WASM_OP, 55 | 1.0, 56 | 1.0, 57 | [Instruction::ReturnImm32 { 58 | value: AnyConst32::from_i32(1), 59 | }], 60 | ); 61 | test_binary_consteval( 62 | WASM_OP, 63 | 0.0, 64 | 1.0, 65 | [Instruction::ReturnImm32 { 66 | value: AnyConst32::from_i32(0), 67 | }], 68 | ); 69 | } 70 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/f64_ge.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::F64, "ge"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::f64_ge) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm() { 23 | test_binary_reg_imm32(WASM_OP, 1.0, Instruction::f64_ge) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm_rev() { 29 | test_binary_reg_imm32_rev(WASM_OP, 1.0, Instruction::f64_ge) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_nan() { 35 | test_binary_reg_imm_with(WASM_OP, f64::NAN, [Instruction::return_imm32(false)]).run() 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn nan_reg() { 41 | test_binary_reg_imm_rev_with(WASM_OP, f64::NAN, [Instruction::return_imm32(false)]).run() 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn consteval() { 47 | fn test_with(lhs: f64, rhs: f64, result: bool) { 48 | test_binary_consteval( 49 | WASM_OP, 50 | lhs, 51 | rhs, 52 | [Instruction::ReturnImm32 { 53 | value: AnyConst32::from(result), 54 | }], 55 | ); 56 | } 57 | test_with(1.0, 1.0, true); 58 | test_with(1.0, 2.0, false); 59 | test_with(2.0, 1.0, true); 60 | } 61 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/f64_le.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::F64, "le"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::f64_le) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm() { 23 | test_binary_reg_imm32(WASM_OP, 1.0_f64, Instruction::f64_le) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm_rev() { 29 | test_binary_reg_imm32_rev(WASM_OP, 1.0_f64, Instruction::f64_le) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_nan() { 35 | test_binary_reg_imm_with(WASM_OP, f64::NAN, [Instruction::return_imm32(false)]).run() 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn nan_reg() { 41 | test_binary_reg_imm_rev_with(WASM_OP, f64::NAN, [Instruction::return_imm32(false)]).run() 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn consteval() { 47 | fn test_with(lhs: f64, rhs: f64, result: bool) { 48 | test_binary_consteval( 49 | WASM_OP, 50 | lhs, 51 | rhs, 52 | [Instruction::ReturnImm32 { 53 | value: AnyConst32::from(result), 54 | }], 55 | ); 56 | } 57 | test_with(1.0, 1.0, true); 58 | test_with(1.0, 2.0, true); 59 | test_with(2.0, 1.0, false); 60 | } 61 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/f64_ne.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::F64, "ne"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | // We cannot optimize `x != x` to `false` since `x != Nan` or `Nan != x` is always `true`. 9 | let expected = [ 10 | Instruction::f64_ne( 11 | Register::from_i16(1), 12 | Register::from_i16(0), 13 | Register::from_i16(0), 14 | ), 15 | Instruction::return_reg(Register::from_i16(1)), 16 | ]; 17 | test_binary_same_reg(WASM_OP, expected) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_reg() { 23 | test_binary_reg_reg(WASM_OP, Instruction::f64_ne) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm() { 29 | test_binary_reg_imm32(WASM_OP, 1.0_f64, Instruction::f64_ne) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm_rev() { 35 | test_binary_reg_imm32_rev_commutative(WASM_OP, 1.0_f64, Instruction::f64_ne) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_nan() { 41 | test_binary_reg_imm_with(WASM_OP, f64::NAN, [Instruction::return_imm32(true)]).run() 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn nan_reg() { 47 | test_binary_reg_imm_rev_with(WASM_OP, f64::NAN, [Instruction::return_imm32(true)]).run() 48 | } 49 | 50 | #[test] 51 | #[cfg_attr(miri, ignore)] 52 | fn consteval() { 53 | test_binary_consteval( 54 | WASM_OP, 55 | 1.0, 56 | 1.0, 57 | [Instruction::ReturnImm32 { 58 | value: AnyConst32::from(false), 59 | }], 60 | ); 61 | test_binary_consteval( 62 | WASM_OP, 63 | 0.0, 64 | 1.0, 65 | [Instruction::ReturnImm32 { 66 | value: AnyConst32::from(true), 67 | }], 68 | ); 69 | } 70 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_eq.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I32, "eq"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_eq) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_eq_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_eq_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, i32::MAX, Instruction::i32_eq) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev_commutative(WASM_OP, i32::MAX, Instruction::i32_eq) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn consteval() { 47 | test_binary_consteval( 48 | WASM_OP, 49 | 1, 50 | 1, 51 | [Instruction::ReturnImm32 { 52 | value: AnyConst32::from(true), 53 | }], 54 | ); 55 | test_binary_consteval( 56 | WASM_OP, 57 | 42, 58 | 5, 59 | [Instruction::ReturnImm32 { 60 | value: AnyConst32::from(false), 61 | }], 62 | ); 63 | } 64 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_eqz.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const PARAM: WasmType = WasmType::I32; 4 | 5 | #[test] #[cfg_attr(miri, ignore)] 6 | fn reg() { 7 | let wasm = wat2wasm(&format!( 8 | r#" 9 | (module 10 | (func (param {PARAM}) (result i32) 11 | local.get 0 12 | {PARAM}.eqz 13 | ) 14 | ) 15 | "# 16 | )); 17 | TranslationTest::new(wasm) 18 | .expect_func([ 19 | Instruction::i32_eq_imm16( 20 | Register::from_u16(1), 21 | Register::from_u16(0), 22 | Const16::from_i16(0), 23 | ), 24 | Instruction::return_reg(1), 25 | ]) 26 | .run(); 27 | } 28 | 29 | fn imm_with(value: i32) { 30 | let wasm = wat2wasm(&format!( 31 | r#" 32 | (module 33 | (func (result i32) 34 | {PARAM}.const {value} 35 | {PARAM}.eqz 36 | ) 37 | ) 38 | "# 39 | )); 40 | TranslationTest::new(wasm) 41 | .expect_func([Instruction::ReturnImm32 { 42 | value: Const32::from(value == 0), 43 | }]) 44 | .run(); 45 | } 46 | 47 | #[test] #[cfg_attr(miri, ignore)] 48 | fn imm() { 49 | imm_with(0); 50 | imm_with(1); 51 | } 52 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_ge_s.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I32, "ge_s"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_ge_s) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_ge_s_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_le_s_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i32_ge_s) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i32_ge_s) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_min() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(true), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, i32::MIN, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn max_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(true), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, i32::MAX, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_i32; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs >= rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_ge_u.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I32, "ge_u"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_ge_u) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_ge_u_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_le_u_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i32_ge_u) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i32_ge_u) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_min() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(true), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, u32::MIN, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn max_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(true), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, u32::MAX, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_u32; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs >= rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_gt_s.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I32, "gt_s"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(false), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_gt_s) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_gt_s_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_lt_s_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i32_gt_s) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i32_gt_s) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_max() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(false), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, i32::MAX, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn min_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(false), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, i32::MIN, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_i32; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs > rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_gt_u.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I32, "gt_u"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(false), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_gt_u) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_gt_u_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_lt_u_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i32_gt_u) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i32_gt_u) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_max() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(false), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, u32::MAX, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn min_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(false), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, u32::MIN, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_u32; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs > rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_le_s.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I32, "le_s"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_le_s) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_le_s_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_ge_s_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i32_le_s) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i32_le_s) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_max() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(true), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, i32::MAX, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn min_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(true), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, i32::MIN, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_i32; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs <= rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_le_u.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I32, "le_u"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_le_u) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_le_u_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_ge_u_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i32_le_u) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i32_le_u) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_max() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(true), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, u32::MAX, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn min_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(true), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, u32::MIN, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_u32; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs <= rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_lt_s.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I32, "lt_s"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(false), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_lt_s) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_lt_s_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_gt_s_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i32_lt_s) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i32_lt_s) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_min() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(false), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, i32::MIN, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn max_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(false), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, i32::MAX, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_i32; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs < rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_lt_u.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I32, "lt_u"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(false), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_lt_u) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_lt_u_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_gt_u_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i32_lt_u) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i32_lt_u) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_min() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(false), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, u32::MIN, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn max_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(false), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, u32::MAX, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_u32; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs < rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i32_ne.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I32, "ne"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from_i32(0), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i32_ne) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i32_ne_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i32_ne_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, i32::MAX, Instruction::i32_ne) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev_commutative(WASM_OP, i32::MAX, Instruction::i32_ne) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn consteval() { 47 | test_binary_consteval( 48 | WASM_OP, 49 | 1, 50 | 1, 51 | [Instruction::ReturnImm32 { 52 | value: AnyConst32::from_i32(0), 53 | }], 54 | ); 55 | test_binary_consteval( 56 | WASM_OP, 57 | 42, 58 | 5, 59 | [Instruction::ReturnImm32 { 60 | value: AnyConst32::from_i32(1), 61 | }], 62 | ); 63 | } 64 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i64_eq.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I64, "eq"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i64_eq) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_eq_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_eq_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, i64::MAX, Instruction::i64_eq) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev_commutative(WASM_OP, i64::MAX, Instruction::i64_eq) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn consteval() { 47 | test_binary_consteval( 48 | WASM_OP, 49 | 1, 50 | 1, 51 | [Instruction::ReturnImm32 { 52 | value: AnyConst32::from(true), 53 | }], 54 | ); 55 | test_binary_consteval( 56 | WASM_OP, 57 | 42, 58 | 5, 59 | [Instruction::ReturnImm32 { 60 | value: AnyConst32::from(false), 61 | }], 62 | ); 63 | } 64 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i64_eqz.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const PARAM: WasmType = WasmType::I64; 4 | 5 | #[test] #[cfg_attr(miri, ignore)] 6 | fn reg() { 7 | let wasm = wat2wasm(&format!( 8 | r#" 9 | (module 10 | (func (param {PARAM}) (result i32) 11 | local.get 0 12 | {PARAM}.eqz 13 | ) 14 | ) 15 | "# 16 | )); 17 | TranslationTest::new(wasm) 18 | .expect_func([ 19 | Instruction::i64_eq_imm16( 20 | Register::from_u16(1), 21 | Register::from_u16(0), 22 | Const16::from_i16(0), 23 | ), 24 | Instruction::return_reg(1), 25 | ]) 26 | .run(); 27 | } 28 | 29 | fn imm_with(value: i64) { 30 | let wasm = wat2wasm(&format!( 31 | r#" 32 | (module 33 | (func (result i32) 34 | {PARAM}.const {value} 35 | {PARAM}.eqz 36 | ) 37 | ) 38 | "# 39 | )); 40 | TranslationTest::new(wasm) 41 | .expect_func([Instruction::ReturnImm32 { 42 | value: Const32::from(value == 0), 43 | }]) 44 | .run(); 45 | } 46 | 47 | #[test] #[cfg_attr(miri, ignore)] 48 | fn imm() { 49 | imm_with(0); 50 | imm_with(1); 51 | } 52 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i64_ge_s.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I64, "ge_s"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i64_ge_s) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_ge_s_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_le_s_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i64_ge_s) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i64_ge_s) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_min() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(true), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, i64::MIN, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn max_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(true), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, i64::MAX, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_i64; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs >= rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i64_ge_u.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I64, "ge_u"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i64_ge_u) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_ge_u_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_le_u_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i64_ge_u) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i64_ge_u) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_min() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(true), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, u64::MIN, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn max_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(true), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, u64::MAX, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_u64; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs >= rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i64_gt_s.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I64, "gt_s"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(false), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i64_gt_s) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_gt_s_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_lt_s_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i64_gt_s) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i64_gt_s) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_max() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(false), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, i64::MAX, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn min_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(false), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, i64::MIN, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_i64; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs > rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i64_gt_u.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I64, "gt_u"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(false), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i64_gt_u) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_gt_u_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_lt_u_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i64_gt_u) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i64_gt_u) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_max() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(false), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, u64::MAX, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn min_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(false), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, u64::MIN, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_u64; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs > rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i64_le_s.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I64, "le_s"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i64_le_s) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_le_s_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_ge_s_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i64_le_s) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i64_le_s) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_max() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(true), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, i64::MAX, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn min_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(true), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, i64::MIN, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_i64; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs <= rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i64_le_u.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I64, "le_u"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(true), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i64_le_u) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_le_u_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_ge_u_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i64_le_u) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i64_le_u) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_max() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(true), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, u64::MAX, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn min_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(true), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, u64::MIN, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_u64; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs <= rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i64_lt_s.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I64, "lt_s"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from(false), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i64_lt_s) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_lt_s_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_gt_s_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, 100_000, Instruction::i64_lt_s) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev(WASM_OP, 100_000, Instruction::i64_lt_s) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn reg_min() { 47 | let expected = [Instruction::ReturnImm32 { 48 | value: AnyConst32::from(false), 49 | }]; 50 | test_binary_reg_imm_with(WASM_OP, i64::MIN, expected).run() 51 | } 52 | 53 | #[test] 54 | #[cfg_attr(miri, ignore)] 55 | fn max_reg() { 56 | let expected = [Instruction::ReturnImm32 { 57 | value: AnyConst32::from(false), 58 | }]; 59 | test_binary_reg_imm_rev_with(WASM_OP, i64::MAX, expected).run() 60 | } 61 | 62 | #[test] 63 | #[cfg_attr(miri, ignore)] 64 | fn consteval() { 65 | let lhs = 1_i64; 66 | let rhs = 2; 67 | test_binary_consteval( 68 | WASM_OP, 69 | lhs, 70 | rhs, 71 | [Instruction::ReturnImm32 { 72 | value: AnyConst32::from(lhs < rhs), 73 | }], 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/i64_ne.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | const WASM_OP: WasmOp = WasmOp::cmp(WasmType::I64, "ne"); 4 | 5 | #[test] 6 | #[cfg_attr(miri, ignore)] 7 | fn same_reg() { 8 | let expected = [Instruction::ReturnImm32 { 9 | value: AnyConst32::from_i32(0), 10 | }]; 11 | test_binary_same_reg(WASM_OP, expected) 12 | } 13 | 14 | #[test] 15 | #[cfg_attr(miri, ignore)] 16 | fn reg_reg() { 17 | test_binary_reg_reg(WASM_OP, Instruction::i64_ne) 18 | } 19 | 20 | #[test] 21 | #[cfg_attr(miri, ignore)] 22 | fn reg_imm16() { 23 | test_binary_reg_imm16::(WASM_OP, 100, Instruction::i64_ne_imm16) 24 | } 25 | 26 | #[test] 27 | #[cfg_attr(miri, ignore)] 28 | fn reg_imm16_rev() { 29 | test_binary_reg_imm16_rev::(WASM_OP, 100, swap_ops!(Instruction::i64_ne_imm16)) 30 | } 31 | 32 | #[test] 33 | #[cfg_attr(miri, ignore)] 34 | fn reg_imm() { 35 | test_binary_reg_imm32(WASM_OP, i64::MAX, Instruction::i64_ne) 36 | } 37 | 38 | #[test] 39 | #[cfg_attr(miri, ignore)] 40 | fn reg_imm_rev() { 41 | test_binary_reg_imm32_rev_commutative(WASM_OP, i64::MAX, Instruction::i64_ne) 42 | } 43 | 44 | #[test] 45 | #[cfg_attr(miri, ignore)] 46 | fn consteval() { 47 | test_binary_consteval( 48 | WASM_OP, 49 | 1, 50 | 1, 51 | [Instruction::ReturnImm32 { 52 | value: AnyConst32::from_i32(0), 53 | }], 54 | ); 55 | test_binary_consteval( 56 | WASM_OP, 57 | 42, 58 | 5, 59 | [Instruction::ReturnImm32 { 60 | value: AnyConst32::from_i32(1), 61 | }], 62 | ); 63 | } 64 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/cmp/mod.rs: -------------------------------------------------------------------------------- 1 | //! Translation tests for all Wasm comparison instructions. 2 | //! 3 | //! These include the following Wasm instructions: 4 | //! 5 | //! `{i32, i64, f32, f64}.{eq, ne}` 6 | //! `{i32, i64}.{lt_s, lt_u, gt_s, gt_u, le_s, le_u, ge_s, ge_u}` 7 | //! `{f32, f64}.{lt, gt, le, ge}` 8 | //! `{i32, i64}.eqz` 9 | //! 10 | //! # Note 11 | //! 12 | //! Technically `{i32, i64}.eqz` are unary instructions but we still 13 | //! include them here since in `wasmi` bytecode these are represented by 14 | //! more generic comparison instructions. 15 | 16 | use super::*; 17 | 18 | mod f32_eq; 19 | mod f32_ne; 20 | mod f64_eq; 21 | mod f64_ne; 22 | mod i32_eq; 23 | mod i32_ne; 24 | mod i64_eq; 25 | mod i64_ne; 26 | 27 | mod f32_ge; 28 | mod f32_gt; 29 | mod f32_le; 30 | mod f32_lt; 31 | mod f64_ge; 32 | mod f64_gt; 33 | mod f64_le; 34 | mod f64_lt; 35 | 36 | mod i32_ge_s; 37 | mod i32_ge_u; 38 | mod i32_gt_s; 39 | mod i32_gt_u; 40 | mod i32_le_s; 41 | mod i32_le_u; 42 | mod i32_lt_s; 43 | mod i32_lt_u; 44 | 45 | mod i64_ge_s; 46 | mod i64_ge_u; 47 | mod i64_gt_s; 48 | mod i64_gt_u; 49 | mod i64_le_s; 50 | mod i64_le_u; 51 | mod i64_lt_s; 52 | mod i64_lt_u; 53 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/memory/memory_size.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | #[test] 4 | #[cfg_attr(miri, ignore)] 5 | fn reg() { 6 | let wasm = wat2wasm( 7 | r" 8 | (module 9 | (memory $m 10) 10 | (func (result i32) 11 | (memory.size $m) 12 | ) 13 | )", 14 | ); 15 | TranslationTest::new(wasm) 16 | .expect_func_instrs([ 17 | Instruction::memory_size(Register::from_i16(0)), 18 | Instruction::return_reg(Register::from_i16(0)), 19 | ]) 20 | .run(); 21 | } 22 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/memory/mod.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | mod memory_copy; 4 | mod memory_fill; 5 | mod memory_grow; 6 | mod memory_init; 7 | mod memory_size; 8 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/return_call/mod.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | mod imported; 4 | mod indirect; 5 | mod internal; 6 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/table/mod.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | mod table_copy; 4 | mod table_fill; 5 | mod table_get; 6 | mod table_grow; 7 | mod table_init; 8 | mod table_set; 9 | mod table_size; 10 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/tests/op/table/table_size.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::{core::ValueType, engine::regmach::tests::display_wasm::DisplayValueType}; 3 | 4 | fn test_reg(ty: ValueType) { 5 | let display_ty = DisplayValueType::from(ty); 6 | let wasm = wat2wasm(&format!( 7 | r" 8 | (module 9 | (table $t 10 {display_ty}) 10 | (func (result i32) 11 | (table.size $t) 12 | ) 13 | )", 14 | )); 15 | TranslationTest::new(wasm) 16 | .expect_func_instrs([ 17 | Instruction::table_size(Register::from_i16(0), 0), 18 | Instruction::return_reg(Register::from_i16(0)), 19 | ]) 20 | .run(); 21 | } 22 | 23 | #[test] 24 | #[cfg_attr(miri, ignore)] 25 | fn reg() { 26 | test_reg(ValueType::FuncRef); 27 | test_reg(ValueType::ExternRef); 28 | } 29 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/regmach/trap.rs: -------------------------------------------------------------------------------- 1 | use super::bytecode::RegisterSpan; 2 | use crate::{ 3 | core::{Trap, TrapCode}, 4 | Func, 5 | }; 6 | 7 | /// Either a Wasm trap or a host trap with its originating host [`Func`]. 8 | #[derive(Debug)] 9 | pub enum TaggedTrap { 10 | /// The trap is originating from Wasm. 11 | Wasm(Trap), 12 | /// The trap is originating from a host function. 13 | Host { 14 | host_func: Func, 15 | host_trap: Trap, 16 | caller_results: RegisterSpan, 17 | }, 18 | } 19 | 20 | impl TaggedTrap { 21 | /// Creates a [`TaggedTrap`] from a host error. 22 | pub fn host(host_func: Func, host_trap: Trap, caller_results: RegisterSpan) -> Self { 23 | Self::Host { 24 | host_func, 25 | host_trap, 26 | caller_results, 27 | } 28 | } 29 | 30 | /// Returns the [`Trap`] of the [`TaggedTrap`]. 31 | pub fn into_trap(self) -> Trap { 32 | match self { 33 | TaggedTrap::Wasm(trap) => trap, 34 | TaggedTrap::Host { host_trap, .. } => host_trap, 35 | } 36 | } 37 | } 38 | 39 | impl From for TaggedTrap { 40 | fn from(trap: Trap) -> Self { 41 | Self::Wasm(trap) 42 | } 43 | } 44 | 45 | impl From for TaggedTrap { 46 | fn from(trap_code: TrapCode) -> Self { 47 | Self::Wasm(trap_code.into()) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/engine/trap.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | core::{Trap, TrapCode}, 3 | Func, 4 | }; 5 | 6 | /// Either a Wasm trap or a host trap with its originating host [`Func`]. 7 | #[derive(Debug)] 8 | pub enum TaggedTrap { 9 | /// The trap is originating from Wasm. 10 | Wasm(Trap), 11 | /// The trap is originating from a host function. 12 | Host { host_func: Func, host_trap: Trap }, 13 | } 14 | 15 | impl TaggedTrap { 16 | /// Creates a [`TaggedTrap`] from a host error. 17 | pub fn host(host_func: Func, host_trap: Trap) -> Self { 18 | Self::Host { 19 | host_func, 20 | host_trap, 21 | } 22 | } 23 | 24 | /// Returns the [`Trap`] of the [`TaggedTrap`]. 25 | pub fn into_trap(self) -> Trap { 26 | match self { 27 | TaggedTrap::Wasm(trap) => trap, 28 | TaggedTrap::Host { host_trap, .. } => host_trap, 29 | } 30 | } 31 | } 32 | 33 | impl From for TaggedTrap { 34 | fn from(trap: Trap) -> Self { 35 | Self::Wasm(trap) 36 | } 37 | } 38 | 39 | impl From for TaggedTrap { 40 | fn from(trap_code: TrapCode) -> Self { 41 | Self::Wasm(trap_code.into()) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/foreach_tuple.rs: -------------------------------------------------------------------------------- 1 | /// Macro to help implement generic trait implementations for tuple types. 2 | macro_rules! for_each_tuple { 3 | ($mac:ident) => { 4 | $mac!( 0 ); 5 | $mac!( 1 T1); 6 | $mac!( 2 T1 T2); 7 | $mac!( 3 T1 T2 T3); 8 | $mac!( 4 T1 T2 T3 T4); 9 | $mac!( 5 T1 T2 T3 T4 T5); 10 | $mac!( 6 T1 T2 T3 T4 T5 T6); 11 | $mac!( 7 T1 T2 T3 T4 T5 T6 T7); 12 | $mac!( 8 T1 T2 T3 T4 T5 T6 T7 T8); 13 | $mac!( 9 T1 T2 T3 T4 T5 T6 T7 T8 T9); 14 | $mac!(10 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10); 15 | $mac!(11 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11); 16 | $mac!(12 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12); 17 | $mac!(13 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13); 18 | $mac!(14 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14); 19 | $mac!(15 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15); 20 | $mac!(16 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15 T16); 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/func/error.rs: -------------------------------------------------------------------------------- 1 | use core::{fmt, fmt::Display}; 2 | 3 | /// Errors that can occur upon type checking function signatures. 4 | #[derive(Debug)] 5 | pub enum FuncError { 6 | /// The exported function could not be found. 7 | ExportedFuncNotFound, 8 | /// A function parameter did not match the required type. 9 | MismatchingParameterType, 10 | /// Specified an incorrect number of parameters. 11 | MismatchingParameterLen, 12 | /// A function result did not match the required type. 13 | MismatchingResultType, 14 | /// Specified an incorrect number of results. 15 | MismatchingResultLen, 16 | } 17 | 18 | impl Display for FuncError { 19 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 20 | match self { 21 | FuncError::ExportedFuncNotFound => { 22 | write!(f, "could not find exported function") 23 | } 24 | FuncError::MismatchingParameterType => { 25 | write!(f, "encountered incorrect function parameter type") 26 | } 27 | FuncError::MismatchingParameterLen => { 28 | write!(f, "encountered an incorrect number of parameters") 29 | } 30 | FuncError::MismatchingResultType => { 31 | write!(f, "encountered incorrect function result type") 32 | } 33 | FuncError::MismatchingResultLen => { 34 | write!(f, "encountered an incorrect number of results") 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/memory/buffer.rs: -------------------------------------------------------------------------------- 1 | use alloc::vec; 2 | 3 | /// A `Vec`-based byte buffer implementation. 4 | /// 5 | /// # Note 6 | /// 7 | /// This is less efficient than the byte buffer implementation that is 8 | /// based on actual OS provided virtual memory but it is a safe fallback 9 | /// solution fitting any platform. 10 | #[derive(Debug)] 11 | pub struct ByteBuffer { 12 | bytes: Vec, 13 | } 14 | 15 | impl ByteBuffer { 16 | /// Creates a new byte buffer with the given initial length. 17 | /// 18 | /// # Errors 19 | /// 20 | /// - If the initial length is 0. 21 | /// - If the initial length exceeds the maximum supported limit. 22 | pub fn new(initial_len: usize) -> Self { 23 | Self { 24 | bytes: vec![0x00_u8; initial_len], 25 | } 26 | } 27 | 28 | /// Grows the byte buffer to the given `new_size`. 29 | /// 30 | /// # Panics 31 | /// 32 | /// If the current size of the [`ByteBuffer`] is larger than `new_size`. 33 | pub fn grow(&mut self, new_size: usize) { 34 | assert!(new_size >= self.len()); 35 | self.bytes.resize(new_size, 0x00_u8); 36 | } 37 | 38 | /// Returns the length of the byte buffer in bytes. 39 | pub fn len(&self) -> usize { 40 | self.bytes.len() 41 | } 42 | 43 | /// Returns a shared slice to the bytes underlying to the byte buffer. 44 | pub fn data(&self) -> &[u8] { 45 | &self.bytes[..] 46 | } 47 | 48 | /// Returns an exclusive slice to the bytes underlying to the byte buffer. 49 | pub fn data_mut(&mut self) -> &mut [u8] { 50 | &mut self.bytes[..] 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/memory/error.rs: -------------------------------------------------------------------------------- 1 | use super::MemoryType; 2 | use core::{fmt, fmt::Display}; 3 | 4 | /// An error that may occur upon operating with virtual or linear memory. 5 | #[derive(Debug)] 6 | #[non_exhaustive] 7 | pub enum MemoryError { 8 | /// Tried to allocate more virtual memory than technically possible. 9 | OutOfBoundsAllocation, 10 | /// Tried to grow linear memory out of its set bounds. 11 | OutOfBoundsGrowth, 12 | /// Tried to access linear memory out of bounds. 13 | OutOfBoundsAccess, 14 | /// Tried to create an invalid linear memory type. 15 | InvalidMemoryType, 16 | /// Occurs when `ty` is not a subtype of `other`. 17 | InvalidSubtype { 18 | /// The [`MemoryType`] which is not a subtype of `other`. 19 | ty: MemoryType, 20 | /// The [`MemoryType`] which is supposed to be a supertype of `ty`. 21 | other: MemoryType, 22 | }, 23 | /// Tried to create too many memories 24 | TooManyMemories, 25 | } 26 | 27 | impl Display for MemoryError { 28 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 29 | match self { 30 | Self::OutOfBoundsAllocation => { 31 | write!(f, "out of bounds memory allocation") 32 | } 33 | Self::OutOfBoundsGrowth => { 34 | write!(f, "out of bounds memory growth") 35 | } 36 | Self::OutOfBoundsAccess => { 37 | write!(f, "out of bounds memory access") 38 | } 39 | Self::InvalidMemoryType => { 40 | write!(f, "tried to create an invalid virtual memory type") 41 | } 42 | Self::InvalidSubtype { ty, other } => { 43 | write!(f, "memory type {ty:?} is not a subtype of {other:?}",) 44 | } 45 | Self::TooManyMemories => { 46 | write!(f, "too many memories") 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/memory/tests.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | fn memory_type(minimum: u32, maximum: impl Into>) -> MemoryType { 4 | MemoryType::new(minimum, maximum.into()).unwrap() 5 | } 6 | 7 | #[test] 8 | fn subtyping_works() { 9 | assert!(memory_type(0, 1).is_subtype_of(&memory_type(0, 1))); 10 | assert!(memory_type(0, 1).is_subtype_of(&memory_type(0, 2))); 11 | assert!(!memory_type(0, 2).is_subtype_of(&memory_type(0, 1))); 12 | assert!(memory_type(2, None).is_subtype_of(&memory_type(1, None))); 13 | assert!(memory_type(0, None).is_subtype_of(&memory_type(0, None))); 14 | assert!(memory_type(0, 1).is_subtype_of(&memory_type(0, None))); 15 | assert!(!memory_type(0, None).is_subtype_of(&memory_type(0, 1))); 16 | } 17 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/module/error.rs: -------------------------------------------------------------------------------- 1 | use super::ReadError; 2 | use crate::engine::TranslationError; 3 | use core::{ 4 | fmt, 5 | fmt::{Debug, Display}, 6 | }; 7 | use wasmparser::BinaryReaderError as ParserError; 8 | 9 | /// Errors that may occur upon reading, parsing and translating Wasm modules. 10 | #[derive(Debug)] 11 | pub enum ModuleError { 12 | /// Encountered when there is a problem with the Wasm input stream. 13 | Read(ReadError), 14 | /// Encountered when there is a Wasm parsing error. 15 | Parser(ParserError), 16 | /// Encountered when there is a Wasm to `wasmi` translation error. 17 | Translation(TranslationError), 18 | } 19 | 20 | impl Display for ModuleError { 21 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 22 | match self { 23 | ModuleError::Read(error) => Display::fmt(error, f), 24 | ModuleError::Parser(error) => Display::fmt(error, f), 25 | ModuleError::Translation(error) => Display::fmt(error, f), 26 | } 27 | } 28 | } 29 | 30 | impl From for ModuleError { 31 | fn from(error: ReadError) -> Self { 32 | Self::Read(error) 33 | } 34 | } 35 | 36 | impl From for ModuleError { 37 | fn from(error: ParserError) -> Self { 38 | Self::Parser(error) 39 | } 40 | } 41 | 42 | impl From for ModuleError { 43 | fn from(error: TranslationError) -> Self { 44 | Self::Translation(error) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/module/global.rs: -------------------------------------------------------------------------------- 1 | use super::ConstExpr; 2 | use crate::GlobalType; 3 | 4 | /// The index of a global variable within a [`Module`]. 5 | /// 6 | /// [`Module`]: [`super::Module`] 7 | #[derive(Debug, Copy, Clone)] 8 | pub struct GlobalIdx(u32); 9 | 10 | impl From for GlobalIdx { 11 | fn from(index: u32) -> Self { 12 | Self(index) 13 | } 14 | } 15 | 16 | impl GlobalIdx { 17 | /// Returns the [`GlobalIdx`] as `u32`. 18 | pub fn into_u32(self) -> u32 { 19 | self.0 20 | } 21 | } 22 | 23 | /// A global variable definition within a [`Module`]. 24 | /// 25 | /// [`Module`]: [`super::Module`] 26 | #[derive(Debug)] 27 | pub struct Global { 28 | /// The type of the global variable. 29 | global_type: GlobalType, 30 | /// The initial value of the global variable. 31 | /// 32 | /// # Note 33 | /// 34 | /// This is represented by a so called initializer expression 35 | /// that is run at module instantiation time. 36 | init_expr: ConstExpr, 37 | } 38 | 39 | impl From> for Global { 40 | fn from(global: wasmparser::Global<'_>) -> Self { 41 | let global_type = GlobalType::from_wasmparser(global.ty); 42 | let init_expr = ConstExpr::new(global.init_expr); 43 | Self { 44 | global_type, 45 | init_expr, 46 | } 47 | } 48 | } 49 | 50 | impl Global { 51 | /// Splits the [`Global`] into its global type and its global initializer. 52 | pub fn into_type_and_init(self) -> (GlobalType, ConstExpr) { 53 | (self.global_type, self.init_expr) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/reftype.rs: -------------------------------------------------------------------------------- 1 | use crate::core::UntypedValue; 2 | 3 | /// Utility type used to convert between `reftype` and [`UntypedValue`]. 4 | /// 5 | /// # Note 6 | /// 7 | /// This is used for conversions of [`FuncRef`] and [`ExternRef`]. 8 | /// 9 | /// [`FuncRef`]: [`crate::FuncRef`] 10 | /// [`ExternRef`]: [`crate::ExternRef`] 11 | pub union Transposer { 12 | /// The `reftype` based representation. 13 | pub reftype: T, 14 | /// The integer based representation to model pointer types. 15 | pub value: u64, 16 | } 17 | 18 | impl Transposer { 19 | /// Creates a `null` [`Transposer`]. 20 | pub fn null() -> Self { 21 | Self { value: 0 } 22 | } 23 | } 24 | 25 | impl Transposer { 26 | /// Creates a new [`Transposer`] from the given `reftype`. 27 | pub fn new(reftype: T) -> Self { 28 | Transposer { reftype } 29 | } 30 | } 31 | 32 | impl From for Transposer { 33 | fn from(untyped: UntypedValue) -> Self { 34 | Transposer { 35 | value: u64::from(untyped), 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/table/tests.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | fn table_type(element: ValueType, minimum: u32, maximum: impl Into>) -> TableType { 4 | TableType::new(element, minimum, maximum.into()) 5 | } 6 | 7 | use ValueType::{F64, I32}; 8 | 9 | #[test] 10 | fn subtyping_works() { 11 | assert!(!table_type(I32, 0, 1).is_subtype_of(&table_type(F64, 0, 1))); 12 | assert!(table_type(I32, 0, 1).is_subtype_of(&table_type(I32, 0, 1))); 13 | assert!(table_type(I32, 0, 1).is_subtype_of(&table_type(I32, 0, 2))); 14 | assert!(!table_type(I32, 0, 2).is_subtype_of(&table_type(I32, 0, 1))); 15 | assert!(table_type(I32, 2, None).is_subtype_of(&table_type(I32, 1, None))); 16 | assert!(table_type(I32, 0, None).is_subtype_of(&table_type(I32, 0, None))); 17 | assert!(table_type(I32, 0, 1).is_subtype_of(&table_type(I32, 0, None))); 18 | assert!(!table_type(I32, 0, None).is_subtype_of(&table_type(I32, 0, 1))); 19 | } 20 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/src/tracer_v0/mtable/imtable.rs: -------------------------------------------------------------------------------- 1 | use super::LocationType; 2 | 3 | #[derive(Clone, Debug)] 4 | pub struct IMTableEntry { 5 | pub ltype: LocationType, 6 | pub addr: usize, 7 | pub value: u64, 8 | } 9 | 10 | /// Initial Memory Table 11 | #[derive(Debug, Default)] 12 | pub struct IMTable(Vec); 13 | 14 | impl IMTable { 15 | pub fn push(&mut self, addr: usize, value: u64, ltype: LocationType) { 16 | self.0.push(IMTableEntry { addr, value, ltype }) 17 | } 18 | 19 | pub fn entries(&self) -> &[IMTableEntry] { 20 | &self.0 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/tests/e2e/mod.rs: -------------------------------------------------------------------------------- 1 | //! End-to-end tests for `wasmi`. 2 | 3 | mod v1; 4 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/tests/e2e/v1/mod.rs: -------------------------------------------------------------------------------- 1 | mod fuel_consumption_mode; 2 | mod fuel_metering; 3 | mod func; 4 | mod host_calls_wasm; 5 | mod resource_limiter; 6 | mod resumable_call; 7 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/tests/e2e/wat/inc_i32.wast: -------------------------------------------------------------------------------- 1 | ;; /// @file inc_i32.cpp 2 | ;; #include // macro EMSCRIPTEN_KEEPALIVE 3 | ;; #include 4 | ;; extern "C" { 5 | ;; uint32_t EMSCRIPTEN_KEEPALIVE inc_i32(uint32_t param) { 6 | ;; return ++param; 7 | ;; } 8 | ;; } // extern "C" 9 | (module 10 | (type $0 (func (param i32) (result i32))) 11 | (type $1 (func)) 12 | (import "env" "memoryBase" (global $import$0 i32)) 13 | (import "env" "memory" (memory $0 256)) 14 | (import "env" "table" (table 0 anyfunc)) 15 | (import "env" "tableBase" (global $import$3 i32)) 16 | (global $global$0 (mut i32) (i32.const 0)) 17 | (global $global$1 (mut i32) (i32.const 0)) 18 | (export "_inc_i32" (func $0)) 19 | (export "__post_instantiate" (func $2)) 20 | (func $0 (type $0) (param $var$0 i32) (result i32) 21 | (i32.add 22 | (get_local $var$0) 23 | (i32.const 1) 24 | ) 25 | ) 26 | (func $1 (type $1) 27 | (nop) 28 | ) 29 | (func $2 (type $1) 30 | (block $label$0 31 | (set_global $global$0 32 | (get_global $import$0) 33 | ) 34 | (set_global $global$1 35 | (i32.add 36 | (get_global $global$0) 37 | (i32.const 5242880) 38 | ) 39 | ) 40 | (call $1) 41 | ) 42 | ) 43 | ;; custom section "dylink", size 5 44 | ) 45 | 46 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/tests/spec/error.rs: -------------------------------------------------------------------------------- 1 | use std::{error::Error, fmt, fmt::Display}; 2 | use wasmi::Error as WasmiError; 3 | 4 | /// Errors that may occur upon Wasm spec test suite execution. 5 | #[derive(Debug)] 6 | pub enum TestError { 7 | Wasmi(WasmiError), 8 | InstanceNotRegistered { 9 | name: String, 10 | }, 11 | NoModuleInstancesFound, 12 | FuncNotFound { 13 | module_name: Option, 14 | func_name: String, 15 | }, 16 | GlobalNotFound { 17 | module_name: Option, 18 | global_name: String, 19 | }, 20 | } 21 | 22 | impl Error for TestError {} 23 | 24 | impl Display for TestError { 25 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 26 | match self { 27 | Self::InstanceNotRegistered { name } => { 28 | write!(f, "missing module instance with name: {name}") 29 | } 30 | Self::NoModuleInstancesFound => { 31 | write!(f, "found no module instances registered so far") 32 | } 33 | Self::FuncNotFound { 34 | module_name, 35 | func_name, 36 | } => { 37 | write!(f, "missing func exported as: {module_name:?}::{func_name}",) 38 | } 39 | Self::GlobalNotFound { 40 | module_name, 41 | global_name, 42 | } => { 43 | write!( 44 | f, 45 | "missing global variable exported as: {module_name:?}::{global_name}", 46 | ) 47 | } 48 | Self::Wasmi(wasmi_error) => Display::fmt(wasmi_error, f), 49 | } 50 | } 51 | } 52 | 53 | impl From for TestError 54 | where 55 | E: Into, 56 | { 57 | fn from(error: E) -> Self { 58 | Self::Wasmi(error.into()) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/tests/spec/local/missing-features/mutable-global-disabled.wast: -------------------------------------------------------------------------------- 1 | (assert_invalid 2 | (module 3 | (import "m0" "g0" (global (mut i32))) 4 | ) 5 | "mutable global support is not enabled" 6 | ) 7 | 8 | (assert_invalid 9 | (module 10 | (global $g0 (mut i32) (i32.const 0)) 11 | (export "g0" (global $g0)) 12 | ) 13 | "mutable global support is not enabled" 14 | ) 15 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/tests/spec/local/missing-features/saturating-float-to-int-disabled.wast: -------------------------------------------------------------------------------- 1 | (assert_invalid 2 | (module 3 | (func (param f32) (result i32) 4 | local.get 0 5 | i32.trunc_sat_f32_s 6 | ) 7 | ) 8 | "saturating float to int conversions support is not enabled" 9 | ) 10 | 11 | (assert_invalid 12 | (module 13 | (func (param f32) (result i32) 14 | local.get 0 15 | i32.trunc_sat_f32_u 16 | ) 17 | ) 18 | "saturating float to int conversions support is not enabled" 19 | ) 20 | 21 | (assert_invalid 22 | (module 23 | (func (param f64) (result i32) 24 | local.get 0 25 | i32.trunc_sat_f64_s 26 | ) 27 | ) 28 | "saturating float to int conversions support is not enabled" 29 | ) 30 | 31 | (assert_invalid 32 | (module 33 | (func (param f64) (result i32) 34 | local.get 0 35 | i32.trunc_sat_f64_u 36 | ) 37 | ) 38 | "saturating float to int conversions support is not enabled" 39 | ) 40 | 41 | (assert_invalid 42 | (module 43 | (func (param f32) (result i64) 44 | local.get 0 45 | i64.trunc_sat_f32_s 46 | ) 47 | ) 48 | "saturating float to int conversions support is not enabled" 49 | ) 50 | 51 | (assert_invalid 52 | (module 53 | (func (param f32) (result i64) 54 | local.get 0 55 | i64.trunc_sat_f32_u 56 | ) 57 | ) 58 | "saturating float to int conversions support is not enabled" 59 | ) 60 | 61 | (assert_invalid 62 | (module 63 | (func (param f64) (result i64) 64 | local.get 0 65 | i64.trunc_sat_f64_s 66 | ) 67 | ) 68 | "saturating float to int conversions support is not enabled" 69 | ) 70 | 71 | (assert_invalid 72 | (module 73 | (func (param f64) (result i64) 74 | local.get 0 75 | i64.trunc_sat_f64_u 76 | ) 77 | ) 78 | "saturating float to int conversions support is not enabled" 79 | ) 80 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/tests/spec/local/missing-features/sign-extension-disabled.wast: -------------------------------------------------------------------------------- 1 | (assert_invalid 2 | (module 3 | (func (param i32) (result i32) 4 | local.get 0 5 | i32.extend8_s 6 | ) 7 | ) 8 | "sign extension operations support is not enabled" 9 | ) 10 | 11 | (assert_invalid 12 | (module 13 | (func (param i32) (result i32) 14 | local.get 0 15 | i32.extend16_s 16 | ) 17 | ) 18 | "sign extension operations support is not enabled" 19 | ) 20 | 21 | (assert_invalid 22 | (module 23 | (func (param i64) (result i64) 24 | local.get 0 25 | i64.extend8_s 26 | ) 27 | ) 28 | "sign extension operations support is not enabled" 29 | ) 30 | 31 | (assert_invalid 32 | (module 33 | (func (param i64) (result i64) 34 | local.get 0 35 | i64.extend16_s 36 | ) 37 | ) 38 | "sign extension operations support is not enabled" 39 | ) 40 | 41 | (assert_invalid 42 | (module 43 | (func (param i64) (result i64) 44 | local.get 0 45 | i64.extend32_s 46 | ) 47 | ) 48 | "sign extension operations support is not enabled" 49 | ) 50 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/tests/spec_shim.rs: -------------------------------------------------------------------------------- 1 | //! Official spec testsuite. 2 | 3 | mod e2e; 4 | mod spec; 5 | -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/tests/wasms/test_rust.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/third-party/wasmi/crates/wasmi/tests/wasms/test_rust.wasm -------------------------------------------------------------------------------- /third-party/wasmi/crates/wasmi/tests/wasms/test_rust_1.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/third-party/wasmi/crates/wasmi/tests/wasms/test_rust_1.wasm -------------------------------------------------------------------------------- /third-party/wasmi/fuzz/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasmi-fuzz" 3 | version = "0.0.0" 4 | authors = ["Parity Technologies ", "Robin Freyler "] 5 | publish = false 6 | edition = "2021" 7 | 8 | [package.metadata] 9 | cargo-fuzz = true 10 | 11 | [dependencies] 12 | libfuzzer-sys = "0.4" 13 | wasm-smith = "0.11" 14 | 15 | [dependencies.wasmi] 16 | path = "../crates/wasmi" 17 | 18 | # Prevent this from interfering with workspaces 19 | [workspace] 20 | members = ["."] 21 | 22 | [[bin]] 23 | name = "translate" 24 | path = "fuzz_targets/translate.rs" 25 | test = false 26 | doc = false 27 | 28 | [[bin]] 29 | name = "translate_metered" 30 | path = "fuzz_targets/translate_metered.rs" 31 | test = false 32 | doc = false 33 | -------------------------------------------------------------------------------- /third-party/wasmi/fuzz/fuzz_targets/translate.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | use libfuzzer_sys::fuzz_target; 3 | use wasmi::{Engine, Module}; 4 | 5 | fuzz_target!(|data: wasm_smith::Module| { 6 | let wasm = data.to_bytes(); 7 | let engine = Engine::default(); 8 | Module::new(&engine, &mut &wasm[..]).unwrap(); 9 | }); 10 | -------------------------------------------------------------------------------- /third-party/wasmi/fuzz/fuzz_targets/translate_metered.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | use libfuzzer_sys::fuzz_target; 3 | use wasmi::{Engine, Module, Config}; 4 | 5 | fuzz_target!(|data: wasm_smith::Module| { 6 | let wasm = data.to_bytes(); 7 | let mut config = Config::default(); 8 | config.consume_fuel(true); 9 | let engine = Engine::new(&config); 10 | Module::new(&engine, &mut &wasm[..]).unwrap(); 11 | }); 12 | -------------------------------------------------------------------------------- /third-party/wasmi/resources/wasmi-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/third-party/wasmi/resources/wasmi-logo.png -------------------------------------------------------------------------------- /third-party/wasmi/scripts/ci/sync_wait.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Script waits until file benchmarks/criterion/output-criterion.txt 3 | # appears 4 | 5 | for i in $(seq 1 600); do 6 | git pull -q origin gh-pages 7 | sleep 1 8 | ls benchmarks/criterion/output-criterion.txt 2>/dev/null 9 | if [ $? = 0 ]; then 10 | break; 11 | fi 12 | echo "Waiting..." 13 | done 14 | -------------------------------------------------------------------------------- /third-party/wasmi/scripts/run-local-ci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "starting local CI ..." && 4 | echo " Formatting ..." && 5 | cargo +nightly fmt && 6 | echo " Building ..." && 7 | cargo +stable build --workspace && 8 | echo " Building no_std ..." && 9 | cargo +stable build --workspace --exclude wasmi_cli --exclude wasmi_wasi --no-default-features --target thumbv7em-none-eabi && 10 | echo " Clippy ..." && 11 | cargo +stable clippy --workspace -- -D warnings && 12 | echo " Docs ..." && 13 | cargo +stable doc --workspace --all-features --no-deps --document-private-items && 14 | echo " Testing Spec ..." && 15 | cargo +stable test --release --quiet && 16 | echo " Testing Package ..." && 17 | cargo +stable test --package wasmi --quiet && 18 | echo "-------------------------" && 19 | echo "CI passed" 20 | -------------------------------------------------------------------------------- /wasm/add.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "main") (result i32) 3 | i32.const 100 4 | i32.const 42 5 | i32.add 6 | ) 7 | ) -------------------------------------------------------------------------------- /wasm/bls.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/bls.wasm -------------------------------------------------------------------------------- /wasm/control_flow/if_else.wat: -------------------------------------------------------------------------------- 1 | (func (export "main") (param i32) (result i32) 2 | (local i32) 3 | (block 4 | (block 5 | (block 6 | ;; x == 0 7 | local.get 0 8 | i32.eqz 9 | br_if 0 10 | 11 | ;; x == 1 12 | local.get 0 13 | i32.const 1 14 | i32.eq 15 | br_if 1 16 | 17 | ;; the `else` case 18 | i32.const 7 19 | local.set 1 20 | br 2) 21 | i32.const 42 22 | local.set 1 23 | br 1) 24 | i32.const 99 25 | local.set 1) 26 | local.get 1 27 | ) 28 | -------------------------------------------------------------------------------- /wasm/example.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/example.wasm -------------------------------------------------------------------------------- /wasm/example_2.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "my_func") (result i32) 3 | i32.const 100 4 | i32.const 42 5 | i32.add 6 | i32.const 100 7 | i32.add 8 | i32.const 42 9 | i32.mul 10 | ) 11 | ) -------------------------------------------------------------------------------- /wasm/gradient_boosting.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/gradient_boosting.wasm -------------------------------------------------------------------------------- /wasm/k3/hello_env.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/k3/hello_env.wasm -------------------------------------------------------------------------------- /wasm/k3/if_conditional.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/k3/if_conditional.wasm -------------------------------------------------------------------------------- /wasm/k3/read_api.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/k3/read_api.wasm -------------------------------------------------------------------------------- /wasm/k3/sc_write.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/k3/sc_write.wasm -------------------------------------------------------------------------------- /wasm/memory/load_op.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 0) "\ff\00\00\00\fe\00\00\00") 4 | (func (export "call") 5 | (i32.const 0) 6 | (i64.load offset=0) 7 | (drop) 8 | (i32.const 4) 9 | (i64.load offset=4) 10 | (drop) 11 | (i32.const 0) 12 | (i64.load32_u offset=0) 13 | (drop) 14 | (i32.const 0) 15 | (i64.load32_s offset=0) 16 | (drop) 17 | (i32.const 0) 18 | (i64.load16_u offset=0) 19 | (drop) 20 | (i32.const 0) 21 | (i64.load16_s offset=0) 22 | (drop) 23 | (i32.const 0) 24 | (i64.load8_u offset=0) 25 | (drop) 26 | (i32.const 0) 27 | (i64.load8_s offset=0) 28 | (drop) 29 | 30 | (i32.const 0) 31 | (i32.load offset=0) 32 | (drop) 33 | (i32.const 4) 34 | (i32.load offset=0) 35 | (drop) 36 | (i32.const 0) 37 | (i32.load16_u offset=0) 38 | (drop) 39 | (i32.const 0) 40 | (i32.load16_s offset=0) 41 | (drop) 42 | (i32.const 0) 43 | (i32.load8_u offset=0) 44 | (drop) 45 | (i32.const 0) 46 | (i32.load8_s offset=0) 47 | (drop) 48 | ) 49 | ) -------------------------------------------------------------------------------- /wasm/memory/load_op_i64.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 0) "\ff\00\00\00\fe\00\00\00") 4 | (func (export "main") 5 | (i32.const 0) 6 | (i64.load offset=0) 7 | (drop) 8 | (i32.const 4) 9 | (i64.load offset=4) 10 | (drop) 11 | (i32.const 0) 12 | (i64.load32_u offset=0) 13 | (drop) 14 | (i32.const 0) 15 | (i64.load32_s offset=0) 16 | (drop) 17 | (i32.const 0) 18 | (i64.load16_u offset=0) 19 | (drop) 20 | (i32.const 0) 21 | (i64.load16_s offset=0) 22 | (drop) 23 | (i32.const 0) 24 | (i64.load8_u offset=0) 25 | (drop) 26 | (i32.const 0) 27 | (i64.load8_s offset=0) 28 | (drop) 29 | ) 30 | ) -------------------------------------------------------------------------------- /wasm/memory/load_store.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory (export "memory") 1) 3 | (func $main (result i64) 4 | i32.const 0 5 | i64.const 42 6 | i64.store 7 | 8 | i32.const 0 9 | i64.load 10 | ) 11 | (export "main" (func $main)) 12 | ) -------------------------------------------------------------------------------- /wasm/memory/mem_grow.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 1 2) ;; start with one memory page, and max of 2 pages 3 | (func (export "call") (result i32) 4 | 5 | ;; grow memory by 1 page 6 | ;; grow returns in 1 for success and -1 for failure 7 | ;; will fail if you change to more more than 1 page 8 | (memory.grow (i32.const 1)) 9 | i32.const 1 10 | i32.eq 11 | ) 12 | ) -------------------------------------------------------------------------------- /wasm/memory/mem_size.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 2) ;; start with one memory page, and max of 2 pages 3 | (func (export "main") (result i32) 4 | memory.size 5 | i32.const 1 6 | i32.eq 7 | ) 8 | ) -------------------------------------------------------------------------------- /wasm/memory/store_op.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 0) "\ff\00\00\00\fe\00\00\00") 4 | (func (export "call") 5 | (i32.const 0) 6 | (i64.const 0) 7 | (i64.store offset=0) 8 | (i32.const 0) 9 | (i32.const 0) 10 | (i32.store offset=4) 11 | (i32.const 0) 12 | (i64.const 0x432134214) 13 | (i64.store offset=0) 14 | (i32.const 0) 15 | (i64.const 0) 16 | (i64.store32 offset=0) 17 | (i32.const 0) 18 | (i64.const 0) 19 | (i64.store16 offset=0) 20 | (i32.const 0) 21 | (i64.const 0) 22 | (i64.store8 offset=0) 23 | 24 | (i32.const 0) 25 | (i32.const 0) 26 | (i32.store offset=0) 27 | (i32.const 4) 28 | (i32.const 0) 29 | (i32.store offset=0) 30 | (i32.const 0) 31 | (i32.const 0) 32 | (i32.store16 offset=0) 33 | (i32.const 0) 34 | (i32.const 0) 35 | (i32.store8 offset=0) 36 | (i32.const 0) 37 | (i32.const 256) 38 | (i32.store8 offset=0) 39 | ) 40 | ) -------------------------------------------------------------------------------- /wasm/memory/store_op_i64.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory $0 1) 3 | (data (i32.const 0) "\ff\00\00\00\fe\00\00\00") 4 | (func (export "main") 5 | (i32.const 0) 6 | (i64.const 0) 7 | (i64.store offset=0) 8 | (i32.const 0) 9 | (i64.const 0x432134214) 10 | (i64.store offset=0) 11 | (i32.const 0) 12 | (i64.const 0) 13 | (i64.store32 offset=0) 14 | (i32.const 0) 15 | (i64.const 0) 16 | (i64.store16 offset=0) 17 | (i32.const 0) 18 | (i64.const 0) 19 | (i64.store8 offset=0) 20 | ) 21 | ) -------------------------------------------------------------------------------- /wasm/misc/bulk-ops-memcopy.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 8 8) 3 | 4 | ;; The maximum amount of bytes to process per iteration. 5 | (global $MAX_N i64 (i64.const 250000)) 6 | 7 | (func (export "run") (param $N i64) (result i64) 8 | (local $i i32) 9 | (local $n i32) 10 | (if (i64.gt_u (local.get $N) (global.get $MAX_N)) 11 | (then (unreachable)) 12 | ) 13 | (local.set $i (i32.const 0)) 14 | (local.set $n (i32.wrap_i64 (local.get $N))) 15 | (block $break 16 | (loop $continue 17 | ;; if i >= N: break 18 | (br_if $break 19 | (i32.ge_u (local.get $i) (local.get $n)) 20 | ) 21 | ;; mem[n..n*2].copy(mem[0..n]) 22 | (memory.copy 23 | (local.get $i) ;; dst 24 | (i32.const 0) ;; src 25 | (local.get $n) ;; len 26 | ) 27 | ;; i += 1 28 | (local.set $i (i32.add (local.get $i) (i32.const 1))) 29 | (br $continue) 30 | ) 31 | ) 32 | (i64.const 0) 33 | ) 34 | ) 35 | -------------------------------------------------------------------------------- /wasm/misc/bulk-ops-memfill.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 8 8) 3 | 4 | ;; The maximum amount of bytes to process per iteration. 5 | (global $MAX_N i64 (i64.const 250000)) 6 | 7 | (func (export "run") (param $N i64) (result i64) 8 | (local $i i32) 9 | (local $n i32) 10 | (if (i64.gt_u (local.get $N) (global.get $MAX_N)) 11 | (then (unreachable)) 12 | ) 13 | (local.set $i (i32.const 0)) 14 | (local.set $n (i32.wrap_i64 (local.get $N))) 15 | (block $break 16 | (loop $continue 17 | ;; if i >= N: break 18 | (br_if $break 19 | (i32.ge_u (local.get $i) (local.get $n)) 20 | ) 21 | ;; mem[0..n].fill(i) 22 | (memory.fill 23 | (i32.const 0) ;; dst 24 | (local.get $i) ;; value 25 | (local.get $n) ;; len 26 | ) 27 | ;; i += 1 28 | (local.set $i (i32.add (local.get $i) (i32.const 1))) 29 | (br $continue) 30 | ) 31 | ) 32 | (i64.const 0) 33 | ) 34 | ) 35 | -------------------------------------------------------------------------------- /wasm/misc/bulk-ops.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory 8 8) 3 | 4 | ;; The maximum amount of bytes to process per iteration. 5 | (global $MAX_N i64 (i64.const 250000)) 6 | 7 | (func (export "main") (param $N i64) (result i64) 8 | (local $i i32) 9 | (local $n i32) 10 | (if (i64.gt_u (local.get $N) (global.get $MAX_N)) 11 | (then (unreachable)) 12 | ) 13 | (local.set $i (i32.const 0)) 14 | (local.set $n (i32.wrap_i64 (local.get $N))) 15 | (block $break 16 | (loop $continue 17 | ;; if i >= N: break 18 | (br_if $break 19 | (i32.ge_u (local.get $i) (local.get $n)) 20 | ) 21 | ;; mem[0..n].fill(i) 22 | (memory.fill 23 | (i32.const 0) ;; dst 24 | (local.get $i) ;; value 25 | (local.get $n) ;; len 26 | ) 27 | ;; mem[n..n*2].copy(mem[0..n]) 28 | (memory.copy 29 | (local.get $i) ;; dst 30 | (i32.const 0) ;; src 31 | (local.get $n) ;; len 32 | ) 33 | ;; i += 1 34 | (local.set $i (i32.add (local.get $i) (i32.const 1))) 35 | (br $continue) 36 | ) 37 | ) 38 | (i64.const 0) 39 | ) 40 | ) 41 | -------------------------------------------------------------------------------- /wasm/misc/bulk_memfill.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory (export "memory") 1) 3 | ;;(data $d0 (i32.const 0) "\10\20\30\40") 4 | (func $run (result i32) 5 | (i32.const 0) 6 | (i32.const 1) 7 | (i32.const 5) 8 | (memory.fill) 9 | (i32.const 0) 10 | (i32.load) 11 | drop 12 | (i32.const 1) 13 | (i32.load) 14 | ) 15 | (export "run" (func $run)) 16 | ) -------------------------------------------------------------------------------- /wasm/misc/bulk_memfill2.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (memory (export "memory") 1) 3 | ;;(data $d0 (i32.const 0) "\10\20\30\40") 4 | (func $run (result i32) 5 | (i32.const 11) 6 | (i32.const 42) 7 | (i32.const 128) 8 | (memory.fill) 9 | (i32.const 19) 10 | (i32.load align=1) 11 | ) 12 | (export "run" (func $run)) 13 | ) -------------------------------------------------------------------------------- /wasm/misc/count_until.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `count_until` that takes an input `n`. 2 | ;; The exported function counts an integer `n` times and then returns 0. 3 | (module 4 | (func (export "count_until") (param $limit i32) (result i32) 5 | (local $counter i32) 6 | (loop 7 | (br_if 8 | 0 9 | (i32.ne 10 | (local.tee $counter 11 | (i32.add 12 | (local.get $counter) 13 | (i32.const 1) 14 | ) 15 | ) 16 | (local.get $limit) 17 | ) 18 | ) 19 | ) 20 | (return (local.get $counter)) 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /wasm/misc/divrem.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "test") (param $n i32) (result i32) 3 | (local $m i64) 4 | (local $tmp32 i32) 5 | (local $tmp64 i64) 6 | (loop $continue 7 | ;; n -= 1 8 | (local.set $n 9 | (i32.sub 10 | (local.get $n) 11 | (i32.const 1) 12 | ) 13 | ) 14 | ;; m = n 15 | (local.set $m (i64.extend_i32_u (local.get $n))) 16 | ;; execute a bunch of div and rem instructions with immediate `rhs` values 17 | (local.set $tmp32 (i32.div_s (local.get $n) (i32.const 3))) 18 | (local.set $tmp32 (i32.div_u (local.get $n) (i32.const 3))) 19 | (local.set $tmp32 (i32.rem_s (local.get $n) (i32.const 3))) 20 | (local.set $tmp32 (i32.rem_u (local.get $n) (i32.const 3))) 21 | (local.set $tmp64 (i64.div_s (local.get $m) (i64.const 3))) 22 | (local.set $tmp64 (i64.div_u (local.get $m) (i64.const 3))) 23 | (local.set $tmp64 (i64.rem_s (local.get $m) (i64.const 3))) 24 | (local.set $tmp64 (i64.rem_u (local.get $m) (i64.const 3))) 25 | ;; continue if $n != 0 26 | (br_if $continue (local.get $n)) 27 | ) 28 | (return (local.get $n)) 29 | ) 30 | ) 31 | -------------------------------------------------------------------------------- /wasm/misc/factorial.wat: -------------------------------------------------------------------------------- 1 | (module 2 | ;; Iterative factorial function, does not use recursion. 3 | (func (export "iterative_factorial") (param i64) (result i64) 4 | (local i64) 5 | (local.set 1 (i64.const 1)) 6 | (block 7 | (br_if 0 (i64.lt_s (local.get 0) (i64.const 2))) 8 | (loop 9 | (local.set 1 (i64.mul (local.get 1) (local.get 0))) 10 | (local.set 0 (i64.add (local.get 0) (i64.const -1))) 11 | (br_if 0 (i64.gt_s (local.get 0) (i64.const 1))) 12 | ) 13 | ) 14 | (local.get 1) 15 | ) 16 | 17 | ;; Recursive trivial factorial function. 18 | (func $rec_fac (export "recursive_factorial") (param i64) (result i64) 19 | (if (result i64) 20 | (i64.eq (local.get 0) (i64.const 0)) 21 | (then (i64.const 1)) 22 | (else 23 | (i64.mul 24 | (local.get 0) 25 | (call $rec_fac 26 | (i64.sub 27 | (local.get 0) 28 | (i64.const 1) 29 | ) 30 | ) 31 | ) 32 | ) 33 | ) 34 | ) 35 | ) 36 | -------------------------------------------------------------------------------- /wasm/misc/fib.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func $fib (export "fib") (param $N i64) (result i64) 3 | (local $n1 i64) 4 | (local $n2 i64) 5 | (local $tmp i64) 6 | (local $i i64) 7 | ;; return $N for N <= 1 8 | (if 9 | (i64.le_s (local.get $N) (i64.const 1)) 10 | (then (return (local.get $N))) 11 | ) 12 | (local.set $n1 (i64.const 1)) 13 | (local.set $n2 (i64.const 1)) 14 | (local.set $i (i64.const 2)) 15 | ;;since we normally return n2, handle n=1 case specially 16 | (loop $continue 17 | (if 18 | (i64.lt_s (local.get $i) (local.get $N)) 19 | (then 20 | (local.set $tmp (i64.add (local.get $n1) (local.get $n2))) 21 | (local.set $n1 (local.get $n2)) 22 | (local.set $n2 (local.get $tmp)) 23 | (local.set $i (i64.add (local.get $i) (i64.const 1))) 24 | (br $continue) 25 | ) 26 | ) 27 | ) 28 | (local.get $n2) 29 | ) 30 | ) -------------------------------------------------------------------------------- /wasm/misc/fuse.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "test") (param $n i32) (result i32) 3 | (local $i i32) 4 | (loop $continue 5 | ;; i += 1 6 | (local.set $i 7 | (i32.add 8 | (local.get $i) 9 | (i32.const 1) 10 | ) 11 | ) 12 | ;; if not((i >= n) and (i <= n)) then continue 13 | ;; Note: The above is equal to: 14 | ;; if i != n then continue 15 | (br_if 16 | $continue 17 | (i32.eqz 18 | (i32.and 19 | (i32.ge_u (local.get $i) (local.get $n)) 20 | (i32.le_u (local.get $i) (local.get $n)) 21 | ) 22 | ) 23 | ) 24 | ) 25 | (return (local.get $i)) 26 | ) 27 | ) 28 | -------------------------------------------------------------------------------- /wasm/misc/global_bump.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `bump` that takes an input `n`. 2 | ;; The exported function bumps a global variable `n` times and then returns it. 3 | (module 4 | (global $g (mut i32) (i32.const 0)) 5 | (func $bump (export "bump") (param $n i32) (result i32) 6 | (global.set $g (i32.const 0)) 7 | (block $break 8 | (loop $continue 9 | (br_if ;; if $g == $n then break 10 | $break 11 | (i32.eq 12 | (global.get $g) 13 | (local.get $n) 14 | ) 15 | ) 16 | (global.set $g ;; $g += 1 17 | (i32.add 18 | (global.get $g) 19 | (i32.const 1) 20 | ) 21 | ) 22 | (br $continue) 23 | ) 24 | ) 25 | (return (global.get $g)) 26 | ) 27 | ) 28 | -------------------------------------------------------------------------------- /wasm/misc/global_const.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (global $g0 i32 (i32.const 0)) ;; constant 3 | (global $g1 i32 (i32.const 1)) ;; constant 4 | (func (export "call") (param $limit i32) (result i32) 5 | (local $accumulator i32) 6 | (loop $continue 7 | (br_if 8 | $continue 9 | (i32.lt_s 10 | (local.tee $accumulator 11 | (i32.add 12 | (local.get $accumulator) 13 | (i32.add 14 | (global.get $g0) 15 | (global.get $g1) 16 | ) 17 | ) 18 | ) 19 | (local.get $limit) 20 | ) 21 | ) 22 | ) 23 | (return (local.get $accumulator)) 24 | ) 25 | ) 26 | -------------------------------------------------------------------------------- /wasm/misc/is_even.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func $is_even (export "is_even") (param $a i32) (result i32) 3 | (if (result i32) 4 | (i32.eqz (local.get $a)) 5 | (then 6 | (i32.const 1) 7 | ) 8 | (else 9 | (call $is_odd (i32.sub (local.get $a) (i32.const 1))) 10 | ) 11 | ) 12 | ) 13 | (func $is_odd (param $a i32) (result i32) 14 | (if (result i32) 15 | (i32.eqz (local.get $a)) 16 | (then 17 | (i32.const 0) 18 | ) 19 | (else 20 | (call $is_even (i32.sub (local.get $a) (i32.const 1))) 21 | ) 22 | ) 23 | ) 24 | ) 25 | -------------------------------------------------------------------------------- /wasm/misc/memory-fill.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `fill` that fills the bytes of the 2 | ;; linear memory with the given `u8`-wrapped `i32` value. 3 | ;; 4 | ;; # Note 5 | ;; 6 | ;; The `len` and `offset` parameters tell where to fill 7 | ;; contents within the linear memory. 8 | (module 9 | (memory (export "mem") 1) 10 | (func (export "fill_bytes") (param $ptr i32) (param $len i32) (param $value i32) 11 | (local $n i32) 12 | (block $exit 13 | (loop $loop 14 | (br_if ;; exit loop if $n == $len 15 | $exit 16 | (i32.eq 17 | (local.get $n) 18 | (local.get $len) 19 | ) 20 | ) 21 | (i32.store8 offset=0 ;; store $value at mem[ptr+n] 22 | (i32.add 23 | (local.get $ptr) 24 | (local.get $n) 25 | ) 26 | (local.get $value) 27 | ) 28 | (local.set $n ;; increment n 29 | (i32.add (local.get $n) (i32.const 1)) 30 | ) 31 | (br $loop) ;; continue loop 32 | ) 33 | ) 34 | (return) 35 | ) 36 | ) 37 | -------------------------------------------------------------------------------- /wasm/misc/memory-sum.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `sum` that returns the sum of the linear memory 2 | ;; contents until the given `limit`. 3 | (module 4 | (memory (export "mem") 1) 5 | (func (export "sum_bytes") (param $limit i32) (result i64) 6 | (local $n i32) 7 | (local $sum i64) 8 | (block $exit 9 | (loop $loop 10 | (br_if ;; exit loop if $n == $limit 11 | $exit 12 | (i32.eq 13 | (local.get $n) 14 | (local.get $limit) 15 | ) 16 | ) 17 | (local.set $sum ;; load n-th value from memory and add to sum 18 | (i64.add 19 | (local.get $sum) 20 | (i64.load8_u offset=0 (local.get $n)) 21 | ) 22 | ) 23 | (local.set $n ;; increment n 24 | (i32.add (local.get $n) (i32.const 1)) 25 | ) 26 | (br $loop) ;; continue loop 27 | ) 28 | ) 29 | (return (local.get $sum)) 30 | ) 31 | ) 32 | -------------------------------------------------------------------------------- /wasm/misc/recursive_ok.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `call` that takes an input `n`. 2 | ;; The exported function calls itself `n` times. 3 | (module 4 | (func $call (export "call") (param $n i32) (result i32) 5 | (if (result i32) 6 | (local.get $n) 7 | (then 8 | (return 9 | (call $call 10 | (i32.sub 11 | (local.get $n) 12 | (i32.const 1) 13 | ) 14 | ) 15 | ) 16 | ) 17 | (else 18 | (return (local.get $n)) 19 | ) 20 | ) 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /wasm/misc/recursive_scan.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `linear_integral` that takes an input `n`. 2 | ;; It recursively calls itself with decreasing `n` and summing 3 | ;; up the chain of `n` values. 4 | ;; Therefore the exported function calls itself `n` times. 5 | ;; 6 | ;; Basically this function describes: f(n) := (n²+n)/2 7 | (module 8 | (func $func (export "func") (param $n i32) (result i32) 9 | (if (result i32) 10 | (i32.eq (local.get $n) (i32.const 0)) 11 | (then 12 | ;; return 0 if $n == 0 13 | (i32.const 0) 14 | ) 15 | (else 16 | ;; return $n + (call $func($n - 1)) otherwise 17 | (i32.add 18 | (call $func 19 | (i32.sub 20 | (local.get $n) 21 | (i32.const 1) 22 | ) 23 | ) 24 | (local.get $n) 25 | ) 26 | ) 27 | ) 28 | ) 29 | ) 30 | -------------------------------------------------------------------------------- /wasm/misc/recursive_trap.wat: -------------------------------------------------------------------------------- 1 | ;; Exports a function `call` that takes an input `n`. 2 | ;; The exported function calls itself `n` times and traps afterwards. 3 | (module 4 | (func $call (export "call") (param $n i32) (result i32) 5 | (if (result i32) 6 | (local.get $n) 7 | (then 8 | (return 9 | (call $call 10 | (i32.sub 11 | (local.get $n) 12 | (i32.const 1) 13 | ) 14 | ) 15 | ) 16 | ) 17 | (else (unreachable)) 18 | ) 19 | ) 20 | ) 21 | -------------------------------------------------------------------------------- /wasm/misc/trunc_f2i.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "trunc_f2i") (param $n i32) (param $input32 f32) (param $input64 f64) (result) 3 | (local $i i32) 4 | (block $exit 5 | (if 6 | (i32.le_u 7 | (local.get $n) 8 | (i32.const 0) 9 | ) 10 | (then (unreachable)) ;; trap if $n <= 0 11 | ) 12 | (local.set $i (local.get $n)) ;; i = n 13 | (loop $continue 14 | (drop 15 | (i32.trunc_f32_s (local.get $input32)) ;; <- under test 16 | ) 17 | (drop 18 | (i32.trunc_f32_u (local.get $input32)) ;; <- under test 19 | ) 20 | (drop 21 | (i64.trunc_f32_s (local.get $input32)) ;; <- under test 22 | ) 23 | (drop 24 | (i64.trunc_f64_u (local.get $input64)) ;; <- under test 25 | ) 26 | (drop 27 | (i32.trunc_f64_s (local.get $input64)) ;; <- under test 28 | ) 29 | (drop 30 | (i32.trunc_f64_u (local.get $input64)) ;; <- under test 31 | ) 32 | (drop 33 | (i64.trunc_f64_s (local.get $input64)) ;; <- under test 34 | ) 35 | (drop 36 | (i64.trunc_f64_u (local.get $input64)) ;; <- under test 37 | ) 38 | (local.set $i ;; i -= 1 39 | (i32.sub (local.get $i) (i32.const 1)) 40 | ) 41 | (br_if $continue (local.get $i)) ;; continue if i != 0 42 | ) 43 | ) 44 | ) 45 | ) 46 | -------------------------------------------------------------------------------- /wasm/misc/uni-poly-eval.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/misc/uni-poly-eval.wasm -------------------------------------------------------------------------------- /wasm/nebula/basic_arith.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "main") (result i64) 3 | i64.const 1000 4 | i64.const 42 5 | i64.const 42 6 | i64.const 100 7 | i64.add 8 | i64.mul 9 | i64.add 10 | ) 11 | ) -------------------------------------------------------------------------------- /wasm/nebula/bit_check.wat: -------------------------------------------------------------------------------- 1 | (func (;0;) (param i64 i64) (result i64) 2 | local.get 1 3 | i64.const 1 4 | i64.and 5 | local.tee 1 6 | i64.const 1 7 | i64.xor 8 | local.get 0 9 | i64.const -1 10 | i64.xor 11 | i64.const 1 12 | i64.and 13 | i64.mul 14 | local.get 1 15 | local.get 0 16 | i64.and 17 | i64.add) 18 | (export "bit_check" (func 0)) -------------------------------------------------------------------------------- /wasm/nebula/eq_func.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (param i64 i64) (result i64))) 3 | (func (;0;) (type 0) (param i64 i64) (result i64) 4 | local.get 1 5 | i64.const 1 6 | i64.and 7 | local.tee 1 8 | i64.const 1 9 | i64.xor 10 | local.get 0 11 | i64.const -1 12 | i64.xor 13 | i64.const 1 14 | i64.and 15 | i64.mul 16 | local.get 1 17 | local.get 0 18 | i64.and 19 | i64.add) 20 | (func (;1;) (type 0) (param i64 i64) (result i64) 21 | (local i64 i64 i64 i64) 22 | i64.const 0 23 | local.set 2 24 | i64.const 1 25 | local.set 3 26 | loop ;; label = @1 27 | local.get 1 28 | local.get 2 29 | i64.const 1 30 | i64.add 31 | local.tee 4 32 | i64.shr_u 33 | i64.const 1 34 | i64.and 35 | local.tee 5 36 | i64.const 1 37 | i64.xor 38 | local.get 0 39 | local.get 4 40 | i64.shr_s 41 | local.tee 4 42 | i64.const -1 43 | i64.xor 44 | i64.const 1 45 | i64.and 46 | i64.mul 47 | local.get 5 48 | local.get 4 49 | i64.and 50 | i64.add 51 | local.get 1 52 | local.get 2 53 | i64.shr_u 54 | i64.const 1 55 | i64.and 56 | local.tee 4 57 | i64.const 1 58 | i64.xor 59 | local.get 0 60 | local.get 2 61 | i64.shr_s 62 | local.tee 5 63 | i64.const -1 64 | i64.xor 65 | i64.const 1 66 | i64.and 67 | i64.mul 68 | local.get 4 69 | local.get 5 70 | i64.and 71 | i64.add 72 | local.get 3 73 | i64.mul 74 | i64.mul 75 | local.set 3 76 | local.get 2 77 | i64.const 2 78 | i64.add 79 | local.tee 2 80 | i64.const 64 81 | i64.ne 82 | br_if 0 (;@1;) 83 | end 84 | local.get 3) 85 | (export "bit_check" (func 0)) 86 | (export "eq_func" (func 1)) 87 | ) -------------------------------------------------------------------------------- /wasm/nebula/integer_hash.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/nebula/integer_hash.wasm -------------------------------------------------------------------------------- /wasm/nebula/regression_model.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/nebula/regression_model.wasm -------------------------------------------------------------------------------- /wasm/sb/basic.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "main") (result i32) 3 | i32.const 1000 4 | i32.const 42 5 | i32.const 42 6 | i32.const 100 7 | i32.add 8 | i32.sub 9 | i32.mul 10 | i32.const 1000 11 | i32.div_u 12 | i32.const 1000 13 | i32.rem_u 14 | i32.clz 15 | i32.eqz 16 | ) 17 | ) -------------------------------------------------------------------------------- /wasm/sb/basic_i64.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "main") (result i32) 3 | i64.const 1000 4 | i64.const 42 5 | i64.const 42 6 | i64.const 100 7 | i64.add 8 | i64.sub 9 | i64.mul 10 | i64.const 1000 11 | i64.div_u 12 | i64.const 1000 13 | i64.rem_u 14 | i64.clz 15 | i64.eqz 16 | ) 17 | ) -------------------------------------------------------------------------------- /wasm/sb/br_adjust/br_adjust_0.wat: -------------------------------------------------------------------------------- 1 | (func (export "main") (result i32) 2 | (block (result i32) 3 | (drop 4 | (br_if 0 5 | (i32.const 6) 6 | (br_table 0 0 7 | (i32.const 9) 8 | (i32.const 0) 9 | ) 10 | ) 11 | ) 12 | (i32.const 7) 13 | ) 14 | ) -------------------------------------------------------------------------------- /wasm/sb/call_indirect.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/sb/call_indirect.wasm -------------------------------------------------------------------------------- /wasm/sb/dk.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (result i64))) 3 | (type (;1;) (func (param i64 i64) (result i64))) 4 | (func (type 0) (result i64) 5 | i64.const 1000 6 | i64.const 42 7 | i64.const 42 8 | i64.const 100 9 | i64.add 10 | i64.sub 11 | i64.mul 12 | i64.const 1000 13 | i64.div_u 14 | i64.const 1000 15 | i64.rem_u 16 | i64.clz 17 | i64.const 100 18 | call 1 19 | i64.const 1000 20 | i64.add 21 | ) 22 | (func (type 1) (param i64) (param i64) (result i64) 23 | local.get 0 24 | local.get 1 25 | drop 26 | ) 27 | (export "main" (func 0)) 28 | ) -------------------------------------------------------------------------------- /wasm/sb/factorial.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/sb/factorial.wasm -------------------------------------------------------------------------------- /wasm/sb/polynomial-transform.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/sb/polynomial-transform.wasm -------------------------------------------------------------------------------- /wasm/sb/rotl.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/sb/rotl.wasm -------------------------------------------------------------------------------- /wasm/sb/small-funcs.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/sb/small-funcs.wasm -------------------------------------------------------------------------------- /wasm/sb/small-ml.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/sb/small-ml.wasm -------------------------------------------------------------------------------- /wasm/test.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "call") (param i32) (param i32) (result i32) 3 | local.get 0 4 | local.get 1 5 | local.get 0 6 | local.get 1 7 | i32.add 8 | i32.add 9 | i32.mul 10 | ) 11 | ) -------------------------------------------------------------------------------- /wasm/use_cases/code.md: -------------------------------------------------------------------------------- 1 | The Rust code that is compiled into these WASM modules is located in this [repository](https://github.com/Forpee/example_wasms). -------------------------------------------------------------------------------- /wasm/use_cases/data_provenance.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/use_cases/data_provenance.wasm -------------------------------------------------------------------------------- /wasm/use_cases/defi_transaction.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/use_cases/defi_transaction.wasm -------------------------------------------------------------------------------- /wasm/use_cases/energy_usage.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/use_cases/energy_usage.wasm -------------------------------------------------------------------------------- /wasm/use_cases/financial_protocol.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/use_cases/financial_protocol.wasm -------------------------------------------------------------------------------- /wasm/use_cases/game_logic.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/use_cases/game_logic.wasm -------------------------------------------------------------------------------- /wasm/use_cases/regulatory_compliance.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/use_cases/regulatory_compliance.wasm -------------------------------------------------------------------------------- /wasm/use_cases/smart_contract_audit.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/use_cases/smart_contract_audit.wasm -------------------------------------------------------------------------------- /wasm/use_cases/toy_rsa.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/use_cases/toy_rsa.wasm -------------------------------------------------------------------------------- /wasm/variable/global_get_op.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (global $global_i32 i32 (i32.const 0)) 3 | (global $global_i64 i64 (i64.const 0)) 4 | 5 | (func (export "call") 6 | (global.get $global_i32) 7 | (drop) 8 | (global.get $global_i64) 9 | (drop) 10 | ) 11 | ) -------------------------------------------------------------------------------- /wasm/variable/global_ops.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (global $g (mut i32) (i32.const 10)) 3 | ;; Increases $g by $delta and returns the new value. 4 | (func (export "call") (result i32) 5 | (global.set $g 6 | (i32.add 7 | (global.get $g) 8 | (i32.const 20) 9 | ) 10 | ) 11 | (global.get $g) 12 | ) 13 | ) -------------------------------------------------------------------------------- /wasm/variable/global_set_op.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (global $global_i32 (mut i32) (i32.const 10)) 3 | (global $global_i64 (mut i64) (i64.const 10)) 4 | 5 | (func (export "call") 6 | (i32.const 0) 7 | (global.set $global_i32) 8 | (i64.const 0) 9 | (global.set $global_i64) 10 | ) 11 | ) -------------------------------------------------------------------------------- /wasm/variable/local_get_op.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "call") 3 | (local i32 i64) 4 | (local.get 0) 5 | (drop) 6 | (local.get 1) 7 | (drop) 8 | 9 | ) 10 | ) -------------------------------------------------------------------------------- /wasm/variable/local_get_op_params.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "call") (param i32) (result i32) 3 | local.get 0 4 | ) 5 | ) -------------------------------------------------------------------------------- /wasm/variable/local_ops.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "call") (param i32) 3 | (local i32 i64) 4 | (local.get 0) 5 | (drop) 6 | (local.get 1) 7 | (drop) 8 | ) 9 | ) -------------------------------------------------------------------------------- /wasm/variable/local_set_op.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "call") 3 | (local i32 i64) 4 | (i32.const 10) 5 | (local.set 0) 6 | (i64.const 100) 7 | (local.set 1) 8 | (local.get 0) 9 | drop 10 | (local.get 1) 11 | drop 12 | (local.get 0) 13 | drop 14 | ) 15 | ) -------------------------------------------------------------------------------- /wasm/variable/local_tee_op.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func (export "main") 3 | (local i32 i64) 4 | (i32.const 1012) 5 | (local.tee 0) 6 | (drop) 7 | (i64.const 100) 8 | (local.tee 1) 9 | (drop) 10 | (local.get 0) 11 | (drop) 12 | ) 13 | ) -------------------------------------------------------------------------------- /wasm/zk_ads.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ICME-Lab/zkEngine_dev/f35eb017c76448111de27e393f667ce7022dbeb6/wasm/zk_ads.wasm --------------------------------------------------------------------------------