mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-11-27 18:11:21 +00:00
* Optimize memory initialization handling in AOT loader (#3983) Save memory if the file buffer is always exist before exit. Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * Break aot_create_comp_data into small functions Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * Handle a new scenario where an item is both exported and imported. (#3984) * Error message improvement (#4000) Improve error message in the scenario where the runtime was built with ref types disabled but the module uses reference types feature. * Ensure __heap_base and __data_end global indices are validated against import count (#3996) * Fix table index calculations in wasm_loader and wasm_mini_loader (#4004) * Add an example of how to embed WAMR in Zephyr user mode (#3998) * [fuzzing] Use software bound-check during fuzzing (#4003) * Update CMakeLists.txt of fuzzing - enable software bound-check - enable wasi - disable libc builtin and multiple modules * Fix off-by-one error in result offset calculation for function calls * Check whether related table has funcref elem in opcode call_indirect (#3999) * check whether table has funcref elem in call_indirect * check whether table has funcref elem in call_indirect when gc is enabled * Improve stack consistency by ensuring sufficient space for dummy offsets (#4011) One more corner case: if the `frame_offset` increases and becomes equal to the `frame_offset_boundary` after the last assignment within the for loop. * Add documentation regarding security issues and the status of Wasm proposals (#3972) Add documentation regarding security issues and the status of Wasm proposals. * Enable shrunk memory by default and add related configurations (#4008) - Enable shrunk memory by default and add related configurations - Improve error messages for memory access alignment checks - Add documentation for WAMR shrunk memory build option - Update NuttX workflow to disable shrunk memory build option * build(deps): Bump actions/upload-artifact from 4.5.0 to 4.6.0 (#4021) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.5.0 to 4.6.0. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4.5.0...v4.6.0) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): Bump github/codeql-action from 3.28.0 to 3.28.1 (#4020) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.0 to 3.28.1. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.0...v3.28.1) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Refine read leb int wasm loader of fast interpreter (#4017) * .github: Add shared lib builds (#3975) So far, no workflows would attempt to build the shared version of the iwasm library (namely, vmlib). Note that, as opposed to GC_EH_BUILD_OPTIONS and DEFAULT_BUILD_OPTIONS, the actual default options defined by the build system are assumed, for the sake of simplicity and avoiding repeated code. * fixes for compiling on windows (#4026) * Refine getting const offsets in wasm loader of fast-interp (#4012) - Refine const offsets in loader for fast-interp - handle const cell num overflow - Use const array, remove list * Synchronize the GC spec tests to the commit from December 9. 2024. (#4022) - Synchronize the GC spec tests to the commit from December 9. 2024. - Revise the error messages to be consistent with the spec test cases. - bypass gc spec test on the nuttx platform as a workaround * Fix wasm loader check data segment count (#4039) correctly report error when datacount section has non-zero data segment count while the data section is not present * Update Rust target from 'wasm32-wasi' to 'wasm32-wasip1' in CI (#4050) - update Rust target from 'wasm32-wasi' to 'wasm32-wasip1' in ci * build(deps): Bump github/codeql-action from 3.28.1 to 3.28.5 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.1 to 3.28.5. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.1...v3.28.5) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): Bump github/codeql-action from 3.28.5 to 3.28.8 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.5 to 3.28.8. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.5...v3.28.8) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Use wasm32-wasip1 instead of wasm32-wasi target for rust code (#4057) Rust compiler previously deprecated, and now removed the wasm32-wasi target and replaced it with wasm32-wasip1. This change updates all the occurrences of wasm32-wasi in the context of Rust compilation. covers the wasi-nn/test. * add a validator for aot module (#3995) - Add AOT module validation to ensure memory constraints are met - Enable AOT validator in build configuration and update related source files * Show wasm proposals status during compilation and execution (#3989) - add default build configuration options and enhance message output for WAMR features - Add Wasm proposal status printing functionality * initial * Add versioning support and update CMake configuration * Add versioning information for libraries and executables across multiple platforms * Refactor versioning documentation and adopt semantic versioning guidelines * Remove deprecated version.h file and update versioning documentation * Add version.h and update versioning documentation for embedded platforms * Add workflow to confirm version.h is in sync and integrate it into Android compilation workflow * Cleanup check_version_h workflow by removing unnecessary outputs and permissions * Update memory allocation functions to use allocator user data (#4043) * [fuzzing] execute every exported function (#3959) - Enhance wasm mutator fuzz tests by adding export function execution and random value generation - Use --fuel to limit loop size - Use predefined values and enhance argument logging in execution * In wasm32, fix potential conversion overflow when enlarging 65536 pages (#4064) fix enlarge 65536 pages conversion overflow in wasm32 * fix(aot): ensure value_cmp does not exceed br_count in branch table compilation (#4065) * build(deps): Bump github/codeql-action from 3.28.8 to 3.28.9 (#4074) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.8 to 3.28.9. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.8...v3.28.9) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Unit test:type matching issue and code redundancy (#4079) * Add a conditional check for the macro __STDC_VERSION__ (#4080) * build_llvm.py: Allow to build xtensa target on non-xtensa host Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * [gc] Subtyping fix (#4075) * fix(build_llvm.py): clean up whitespace and formatting in build script Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * feat: add support for EXTERNREF value type and enable AOT validator in fuzz tests (#4083) * fix(unit-test): libc_builtin_test issues (#4073) - uninitialized buffer pointers (crashes) - match integer constant size with printf specifier Signed-off-by: Peter Tatrai <peter.tatrai.ext@siemens.com> * fix(build_llvm_libraries.yml): Correct script path for build_llvm.py Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * fix(aot_emit_aot_file): prevent buffer emission for zero byte_count (#4095) if using a debug building of wamrc to run spec test. there will be: core/iwasm/compilation/aot_emit_aot_file.c:1794:13: runtime error: null pointer passed as argument 2, which is declared to never be null * Cmake improvements (#4076) - Utilizes the standard CMake variable BUILD_SHARED_LIBS to simplify the CMake configuration. - Allows the use of a single library definition for both static and shared library cases, improving maintainability and readability of the CMake configuration. - Install vmlib public header files - Installs the public header files for the vmlib target to the include/iwasm directory. - Install cmake package - Adds the necessary CMake configuration files (iwasmConfig.cmake and iwasmConfigVersion.cmake). - Configures the installation of these files to the appropriate directory (lib/cmake/iwasm). - Ensures compatibility with the same major version. - Improve windows product-mini CMakeLists.txt - Fix missing symbols when linking windows product-mini with shared vmlib - Improve Darwin product-mini CMakeLists.txt --------- Signed-off-by: Peter Tatrai <peter.tatrai.ext@siemens.com> * fix: when load aot init expr,no type_idx set. (#4094) Fix an assertion from *gc_object.c line 91* `bh_assert(rtt_type->type_flag == WASM_TYPE_STRUCT;` * prevent data overflow on 32 bit platform for memory.grow * cr suggestions * cr suggestions * format * cr suggestions * feat: use C linkage in aot_comp_option.h for C++ embeding (#4106) Co-authored-by: xiangjia.xj <xiangjia.xj@alibaba-inc.com> * build(deps): Bump actions/upload-artifact from 4.6.0 to 4.6.1 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.6.0 to 4.6.1. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4.6.0...v4.6.1) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): Bump github/codeql-action from 3.28.9 to 3.28.10 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.9 to 3.28.10. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.9...v3.28.10) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Apply suggestions from code review remove confusing comments. * build(deps): Bump ossf/scorecard-action from 2.4.0 to 2.4.1 Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.4.0 to 2.4.1. - [Release notes](https://github.com/ossf/scorecard-action/releases) - [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md) - [Commits](62b2cac7ed...f49aabe0b5) --- updated-dependencies: - dependency-name: ossf/scorecard-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * fix: add dispose of the debug information builder when destroying compilation context (#4105) Co-authored-by: xiangjia.xj <xiangjia.xj@alibaba-inc.com> * wasm_loader allocates more spaces for elements (#4099) - allocate memory for array initialization based on length - update reference type mapping for struct initialization * log warning instaed of assertion (#4119) * fix: fix load aarch64 aot failed (#4114) Co-authored-by: xiangjia.xj <xiangjia.xj@alibaba-inc.com> * fix: correct typos and improve comments across multiple files by codespell (#4116) Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * avoid Windows perform newline translation (#4128) * Iterate callstack API * wamr bool type * clang-format * meaning of the return bool type in the callback * keep devs notes out of public API * format * support standard frames as well * format * Calculate func_index instead of adding an extra field to wasm frame * ignore frames with no function * update typo in the comment * update signature * add correct frame size for aot standard frames * standard frame is not supported when GC is enabled * Copy read only API behind a flag instead of using user defined callback * Cleaning up * remove unnecessary includes * formatting * define if not defined * formatting * address comments * formatting * remove spare diff line * address comments * clang format * spare line * spare lines * last fixes * identation * fix bug for return value when skip_n is passed * build(deps): Bump github/codeql-action from 3.28.10 to 3.28.11 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.10 to 3.28.11. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.10...v3.28.11) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Expose WAMR_BUILD_GC_HEAP_SIZE_DEFAULT as a CMake option This is wired through to the GC_HEAP_SIZE_DEFAULT constant. Also honor this value when configuring the engine with the wasm_c_api. * Address code review feedback * Move the default heap size initialization * Restore the doc heading. * Fix iwasm build error when WAMR_BUILD_WASI_NN enabled A recent change on ./product-mini/platforms/linux/CMakeLists.txt renamed libiwasm to vmlib, but wasi-nn.cmake still wants to link libiwasm.so. Replace libiwasm with vmlib in wasi-nn.cmake to resolve iwasm build error when WAMR_BUILD_WASI_NN enabled. * include bh_platform.h (#4135) This should guarantee that the various macros required by wasm_proposal.c are defined even if the build system does not supply them to the compiler command. * Merge dev/simd for fast-interp (#4131) * Implement the first few SIMD opcodes for fast interpreter (v128.const, v128.any_true) (#3818) Tested on the following code: ``` (module (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) (memory (export "memory") 1) ;; WASI entry point (func $main (export "_start") v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 v128.any_true if unreachable end v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 v128.any_true i32.const 0 i32.eq if unreachable end i32.const 0 call $proc_exit ) ) ``` * implement POP_V128() This is to simplify the simd implementation for fast interpreter * Add all SIMD operations into wasm_interp_fast switch * Add V128 comparison operations Tested using ``` (module (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) (memory (export "memory") 1) (func $assert_true (param v128) local.get 0 v128.any_true i32.eqz if unreachable end ) (func $main (export "_start") ;; Test v128.not v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 v128.not v128.const i8x16 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 i8x16.eq call $assert_true ;; Test v128.and v128.const i8x16 255 255 255 255 0 0 0 0 255 255 255 255 0 0 0 0 v128.const i8x16 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 v128.and v128.const i8x16 255 255 0 0 0 0 0 0 255 255 0 0 0 0 0 0 i8x16.eq call $assert_true ;; Test v128.andnot v128.const i8x16 255 255 255 255 0 0 0 0 255 255 255 255 0 0 0 0 v128.const i8x16 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 v128.andnot v128.const i8x16 0 0 255 255 0 0 0 0 0 0 255 255 0 0 0 0 i8x16.eq call $assert_true ;; Test v128.or v128.const i8x16 255 255 0 0 0 0 255 255 255 255 0 0 0 0 255 0 v128.const i8x16 0 0 255 255 255 255 0 0 0 0 255 255 255 255 0 0 v128.or v128.const i8x16 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 i8x16.eq call $assert_true ;; Test v128.xor v128.const i8x16 255 255 0 0 255 255 0 0 255 255 0 0 255 255 0 0 v128.const i8x16 255 255 255 255 0 0 0 0 255 255 255 255 0 0 0 0 v128.xor v128.const i8x16 0 0 255 255 255 255 0 0 0 0 255 255 255 255 0 0 i8x16.eq call $assert_true i32.const 0 call $proc_exit ) ) ``` * Add first NEON SIMD opcode implementations to fast interpreter (#3859) Add some implementations of SIMD opcodes using NEON instructions. Tested using: ```wast (module (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32))) (memory (export "memory") 1) (func $assert_true (param v128) local.get 0 v128.any_true i32.eqz if unreachable end ) (func $main (export "_start") i32.const 0 i32.const 32 memory.grow drop i32.const 0 v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 v128.store i32.const 0 v128.load v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 i8x16.eq call $assert_true i32.const 16 v128.const i8x16 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 v128.store i32.const 16 v128.load v128.const i8x16 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 i8x16.eq call $assert_true i32.const 0 v128.load v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 i8x16.eq call $assert_true drop i32.const 0 i32.const 1 memory.grow drop i32.const 0 i64.const 0x7F80FF017E02FE80 i64.store i32.const 0 v128.load8x8_s v128.const i16x8 127 -128 -1 1 126 2 -2 -128 i16x8.eq call $assert_true i32.const 0 i64.const 0x80FE027E01FF807F i64.store i32.const 0 v128.load8x8_u v128.const i16x8 128 254 2 126 1 255 128 127 i16x8.eq call $assert_true i32.const 0 i64.const 0x8000FFFE7FFF0001 i64.store i32.const 0 v128.load16x4_s v128.const i32x4 -32768 -2 32767 1 i32x4.eq call $assert_true i32.const 0 i64.const 0x8000FFFE7FFF0001 i64.store i32.const 0 v128.load16x4_u v128.const i32x4 32768 65534 32767 1 i32x4.eq call $assert_true i32.const 0 i64.const 0x8000000000000001 i64.store i32.const 0 v128.load32x2_s v128.const i64x2 -2147483648 1 i64x2.eq call $assert_true i32.const 0 i64.const 0x8000000000000001 i64.store i32.const 0 v128.load32x2_u v128.const i64x2 2147483648 1 i64x2.eq call $assert_true call $proc_exit ) ) ``` * Emit imm for lane extract and replace (#3906) * Fix replacement value not being correct (#3919) * Implement load lanes opcodes for wasm (#3942) * Implement final SIMD opcodes: store lane (#4001) * Fix load/store (#4054) * Correctly use unsigned functions (#4055) * implement local and function calls for v128 in the fast interpreter * Fix splat opcodes, add V128 handling in preserve_referenced_local and reserve_block_ret * Fix incorrect memory overflow values + SIMD ifdefs * Fix load/load_splat macros * correct endif wasm loader * Update core/iwasm/interpreter/wasm_opcode.h * Fix spec tests when WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS is 0 * Resolve merge conflicts arising from main -> dev/simd_for_interp and implement fast interpreter const offset loader support for V128 * Enable SIMDe tests on CI * Document WAMR_BUILD_LIB_SIMDE --------- Co-authored-by: James Marsh <mrshnja@amazon.co.uk> Co-authored-by: jammar1 <108334558+jammar1@users.noreply.github.com> Co-authored-by: Maks Litskevich <makslit@amazon.com> Co-authored-by: Marcin Kolny <marcin.kolny@gmail.com> Co-authored-by: Wenyong Huang <wenyong.huang@intel.com> * Fix build issues when compiling WAMRC as a cross-compiler (#4112) * Use CMAKE_INSTALL_BINDIR for wamrc installation * Fix wamrc build failure for 32bit non-x86 targets * Handle PIC flags by cmake in wamrc * Use dummy AOT reloc functions when building wamrc AOT reloc functions are used only when loading AOT WebAssembly modules on target, not during AOT compilation. Original code led to build issues when building wamrc as cross-compiler, using arm header on x86 build. * Add option to turn off SIMD support in wamrc * fix(runtest.py): A workaround to bypass errors that occur when deleting temporary files (#4093) - Replace sys.exit with exceptions for better error handling in test assertions - Update exception handling in compile_wast_to_wasm to catch all exceptions - Improve error messages and logging - Use `--ignore-whitespace` option for git apply in spec_test function - Use raw string notation for regex patterns. *The "SyntaxWarning: invalid escape sequence" in Python The warning has been upgraded to SyntaxWarning since Python 3.12, and it is expected to become a SyntaxError in future versions.* - Add early return for non-loadable AOT compilation to prevent unnecessary assertions - Redirect stderr to stdout in test_case for unified output - Update `create_tmpfiles()` to improve clarity and handling of temporary files * build(deps): Bump esbuild, @vitejs/plugin-react and vite (#4149) Bumps [esbuild](https://github.com/evanw/esbuild) to 0.25.1 and updates ancestor dependencies [esbuild](https://github.com/evanw/esbuild), [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/tree/HEAD/packages/plugin-react) and [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite). These dependencies need to be updated together. Updates `esbuild` from 0.14.54 to 0.25.1 - [Release notes](https://github.com/evanw/esbuild/releases) - [Changelog](https://github.com/evanw/esbuild/blob/main/CHANGELOG-2022.md) - [Commits](https://github.com/evanw/esbuild/compare/v0.14.54...v0.25.1) Updates `@vitejs/plugin-react` from 2.0.1 to 4.3.4 - [Release notes](https://github.com/vitejs/vite-plugin-react/releases) - [Changelog](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite-plugin-react/commits/v4.3.4/packages/plugin-react) Updates `vite` from 3.0.9 to 6.2.2 - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v6.2.2/packages/vite) --- updated-dependencies: - dependency-name: esbuild dependency-type: indirect - dependency-name: "@vitejs/plugin-react" dependency-type: direct:development - dependency-name: vite dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update NuttX and NuttX Apps references to releases/12.9 in workflow f… (#4148) * Update NuttX and NuttX Apps references to releases/12.9 in workflow files * Remove Kconfig modification step for NuttX in spec test workflow * platform/nuttx: Flush icache/dcache properly (#4147) Enhance the os_dcache_flush and os_icache_flush functions to ensure proper cache invalidation, improving memory management efficiency. * Added cache invalidation for data cache * Implemented cache invalidation for instruction cache Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * build(deps): Bump github/codeql-action from 3.28.11 to 3.28.12 (#4160) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.11 to 3.28.12. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.11...v3.28.12) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): Bump actions/upload-artifact from 4.6.1 to 4.6.2 (#4159) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.6.1 to 4.6.2. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4.6.1...v4.6.2) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * test: temporarily skip 'skip-stack-guard-page' test case until issue is resolved * nuttx: remove the up_x API for kernel build (#4154) Signed-off-by: buxiasen <buxiasen@xiaomi.com> Co-authored-by: buxiasen <buxiasen@xiaomi.com> * docs: Update build instructions suggestions for using Valgrind (#4164) * build(deps): Bump github/codeql-action from 3.28.12 to 3.28.13 (#4170) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.12 to 3.28.13. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.12...v3.28.13) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * dwarf_extractor.cpp: use macro control to be compatible with lower version toolchain (#4169) * Update cmake min to 3.14 (#4175) 3.14 is used and tested by linux mini-product to fix ``` CMake Error at CMakeLists.txt:4 (cmake_minimum_required): Compatibility with CMake < 3.5 has been removed from CMake. Update the VERSION argument <min> value. Or, use the <min>...<max> syntax to tell CMake that the project requires at least <min> but has been updated to work with policies introduced by <max> or earlier. Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway. ``` * fix format specifier warning on 32bit builds (#4177) * Remove indirect-load for constants on Xtensa Target to improve performance (#4162) * Remove indirect-load for constants on Xtensa Target to improve performance * Remove const intrinsics flags for xtensa instead of adding too much #ifdef * Add AOT_INTRINSIC_FLAG_F32_CONST for xtensa frontend, because espressif xtensa llvm backend does not support float-point immediate for now --------- Co-authored-by: zhanheng1 <Zhanheng.Qin@sony.com> * cmake: Enhance target selection for ARM architectures with FPU (#4185) Improve the target selection logic for ARM architectures in the NuttX platform configuration. * Added support for FPU detection in THUMB and ARM targets * Ensured correct target is set based on architecture and configuration options Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * build(deps): Bump github/codeql-action from 3.28.13 to 3.28.14 (#4184) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.13 to 3.28.14. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.13...v3.28.14) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.28.14 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * aot: add new u64 intrinsics (#4168) * Refactor Dockerfile and update .dockerignore for wasi-nn tests; adjust map-dir parameters in smoke test script (#4158) * Add import memory/table flag assert check for miniloader (#4179) * Fix few integer overflowing (#4161) - fix(interpreter): correct offset calculations in wasm_loader_get_const_offset function - fix(mem-alloc): update offset calculation in gc_migrate for memory migration - add pointer-overflow sanitizer * prevent frame_offset underflow in wasm_loader (#4165) * improve variable naming and code clarity in SIMD operations (#4157) Fix compilation warning about shadow, like ```sh declaration of ‘val’ shadows a previous local [-Wshadow] ``` * fix: Remove unused variables in SIMD_v128_const case (#4197) Fix compiler warnings about unused variables `high` and `low` in the `SIMD_v128_const` case. These variables are only needed inside the `WASM_ENABLE_FAST_INTERP != 0` conditional block, but were incorrectly declared outside of it, causing unused variable warnings. Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * build(deps): Bump github/codeql-action from 3.28.14 to 3.28.15 (#4198) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.14 to 3.28.15. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.14...v3.28.15) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.28.15 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix false native stack overflow detections with HW_BOUND_CHECK (#4196) In call_wasm_with_hw_bound_check/call_native_with_hw_bound_check, ensure to set up the stack boundary (wasm_exec_env_set_thread_info) before checking the overflow. It seems that the problem was introduced by: https://github.com/bytecodealliance/wasm-micro-runtime/pull/2940 * Keep fix the CMake compatibility issue (#4180) ``` CMake Error at CMakeLists.txt:4 (cmake_minimum_required): Compatibility with CMake < 3.5 has been removed from CMake. Update the VERSION argument <min> value. Or, use the <min>...<max> syntax to tell CMake that the project requires at least <min> but has been updated to work with policies introduced by <max> or earlier. Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway. ``` * Fix the error of AOT mode on the "i386-windows-msvc" platform (#4183) * Fix errors on the "i386-windows-msvc" platform * Refactor symbol name handling for AOT COFF32 binary format * Fix preprocessor directive placement for Windows compatibility in aot_reloc_x86_32.c --------- Co-authored-by: liang.he@intel.com <liang.he@intel.com> * debug-engine: fix a few type mismatches (#4189) - use strict prototypes complained by GCC `-Wstrict-prototypes` - use `int*` instead of `int32*` Note: on some targets, int32_t is a long. for example, GCC shipped with the recent ESP-IDF has such a configuration. - https://github.com/apache/nuttx/issues/15755#issuecomment-2635652808 - https://github.com/apache/nuttx/pull/16022 - https://docs.espressif.com/projects/esp-idf/en/stable/esp32/migration-guides/release-5.x/5.0/gcc.html#espressif-toolchain-changes * Replace CMAKE_CURRENT_FUNCTION_LIST_DIR (#4200) `CMAKE_CURRENT_FUNCTION_LIST_DIR` is added in version 3.17 and currently most of `cmake_minimum_required()` with 3.14. Refer to https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_FUNCTION_LIST_DIR.html * Raise CI runner to ubuntu 22.04 (#4191) update workflows and scripts for Ubuntu 22.04 compatibility. It includes - install Intel SGX SDK 2.25 - use a reusable action to install sgx required - keep improve error handling in AOT compilation process in runtest.py add a workaround to fix receiving a shutdown signal problem. Refers to https://github.com/actions/runner-images/issues/6680 and https://github.com/actions/runner-images/discussions/7188 * Remove the dlen to optimize it. (#4193) There are two reasons for this optimization: - The value of dlen can equal 0x1_0000_0000, even in wasm32 mode, because it is derived from (4G-0). This results in a truncation when it is passed to b_memmove_s(). Consequently, s1max becomes 0 and n is greater than s1max. To correct this, a longer type is required. - The dlen is only used to check if there is enough space in b_memmove_s(). However, from a different angle, after confirming that both src+len and dst+len are within the memory range, we can be assured and there is no need for this explicit check. * Add missing casts and improve error handling in performance map functions (#4202) Wrong type of arguments to formatting function. * Raise wasi-sdk to 25 and wabt to 1.0.37 (#4187) Raise wasi-sdk to 25 and wabt to 1.0.37. It includes - Refactor CI workflow to install WASI-SDK and WABT from a composite action - Use ExternalProject to bring wasm-apps for few samples. file/ wasi-threads/ - Refactor sample build and test steps in SGX compilation workflow for improved clarity and efficiency (workaround) Add CMake support for EMSCRIPTEN and WAMRC, update module paths * fix potential memory leak (#4205) * Add missing V128 handling in WASM_OP_BR, reported in #4173 * Update unit test cases (#4214) * Update gc unit test cases * Update aot stack frame unit test cases * fix print_help when libc wasi is enabled (#4218) * LLVM: don't verify instcombine fixpoint (#4219) LLVM 18 and later, instcombine perfoms only one iteration. it performs extra "verify fixpoint" operation when instcombine is specified in certain ways, including how we do so here. a problem is that the verification raises a fatal error when it finds we didn't reach a fixpoint: LLVM ERROR: Instruction Combining did not reach a fixpoint after 1 iterations while it should be rare, it's quite normal not to reach a fixpoint. this commit fixes the issue by simply disabing the verification. cf.41895843b5* LLVMCreateTargetMachineWithOpts: disable large data (#4220) for x86-64, llvm 17 and later sometimes uses "l" prefix for data sections. cf.43249378dabecause our aot file emitter/loader doesn't support such sections, it ends up with load-time errors solving symbols like ".lrodata". this commit fixes it by avoid placing data in the large data sections. references: https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU1feb00a28c* wamrc: add --disable-llvm-jump-tables option (#4224) while ideally a user should not need to care this kind of optimization details, in reality i guess it's sometimes useful. both of clang and GCC expose a similar option. (-fno-jump-tables) * feat(fuzz): add a new fuzzing target about aot compiler (#4121) support llvm-jit running mode as another fuzzing target * bypass vptr santizier (#4231) LLVM, by default, disables the use of C++'s built-in Run-Time Type Information. This decision is primarily driven by concerns about code size and efficiency. But '-fsanitize=vptr' not allowed with '-fno-rtti'. * use a selected llvm libs list to replace the full list (#4232) * set default value of `WAMR_BUILD_REF_TYPES` to 1 in standalone cases (#4227) - set default value of WAMR_BUILD_REF_TYPES to 1 in CMakeLists.txt * teach aot emitter/loader about .srodata and .srodata.cst* sections (#4240) LLVM 19 and later started to use srodata ("small read only data") sections for RISCV. cf. https://github.com/llvm/llvm-project/pull/82214 this commit makes our aot emitter/loader deal with those sections. an alternative would be to disable small data sections completely by setting the "SmallDataLimit" module attribute to zero. however, i feel this commit is more straightforward and consisitent as we are already dealing with sdata sections. * run_clang_format_diff: mention homebrew for clang-format installation (#4237) * platform/nuttx: Fix dcache operation in os_dcache_flush (#4225) Replace up_invalidate_dcache_all() with up_flush_dcache_all() in os_dcache_flush() to properly flush the data cache instead of just invalidating it. This ensures that any modified data in the cache is written back to memory before execution. Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * Use --target to pass a triple in wamrc (#4199) Provide a triple string in the format of <arch>-<vendor>-<os>-<abi> via --target. * fix return types of our 64-bit clz/ctz/popcount intrinsics (#4238) the corresponding LLVM intrinsics' return types are same as their first argument. eg. i64 for llvm.cttz.i64. cf. https://llvm.org/docs/LangRef.html#llvm-cttz-intrinsic this commit changes the return types of our versions of the intrinsics to match llvm versions as our aot compiler, specifically __call_llvm_intrinsic, assumes. strictly speaking, this is a potential AOT ABI change. however, I suppose it isn't a problem for many of 64-bit ABIs out there, where (lower half of) a 64-bit register is used to return a 32-bit value anyway. (for such ABIs, this commit would fix the upper 32-bit value of the register.) * build(deps): Bump github/codeql-action from 3.28.15 to 3.28.17 (#4243) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.15 to 3.28.17. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.15...v3.28.17) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.28.17 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * samples/wasm-c-api: skip aot compilation unless necessary (#4239) * riscv: avoid llvm.cttz.i32/i64 for xip (#4248) LLVM 16 and later expands cttz intrinsic to a table lookup, which involves some relocations. (unless ZBB is available, in which case the native instructions are preferred over the table-based lowering.) cf. https://reviews.llvm.org/D128911 * Add overflow check for preserved local offset in preserve_referenced_local (#4211) * aot_resolve_object_relocation_group: adapt to LLVM 16 (#4250) cf. https://reviews.llvm.org/D123264 * samples/wasm-c-api: remove unused valgrind detection (#4249) - it's unused - valgrind is basically a linux-only software. it isn't a good idea to make it a hard requirement. if we want to use valgrind, it's better to introduce a separate option to control it. * More detail to python setup, and fixed small typo (#4247) * initialize WASI stdio handles to invalid for better error handling (#4092) * initialize WASI stdio handles to invalid for better error handling * implement os_invalid_raw_handle function for consistent invalid handle representation * Modifying build flags to ensure libiwasm.so is built (#4255) * JIT: don't join worker threads twice (#4252) in case of WASM_ENABLE_LAZY_JIT==0, compile_jit_functions should have already joined these threads. joining them again here is an undefined behavior. * aot_resolve_object_relocation_group: adapt to LLVM 19 (#4254) cf. https://github.com/llvm/llvm-project/pull/95031 https://github.com/llvm/llvm-project/pull/89693 * Stop pretending to support extended-const proposal (#4258) As far as I know, we don't implement the proposal at all. ``` spacetanuki% wasm2wat --enable-all data.28.wasm (module (memory (;0;) 1) (data (;0;) (i32.const 42 i32.const 0 i32.sub) "")) spacetanuki% toywasm --load data.28.wasm spacetanuki% ~/git/wasm-micro-runtime/product-mini/platforms/darwin/b.classic/iwasm data.28.wasm WASM module load failed: illegal opcode or constant expression required or type mismatch spacetanuki% ``` data.28.wasm in the above example is a binary version of:8d4f6aa2b0/test/core/data.wast (L184-L187)* Improve readlinkat_dup() to handle symlink size correctly (#4229) * In readlinkat_dup(), use fstatat() to estimate size first. * Reduce additional space in samples/file * build-scripts/build_llvm.py: bump to llvm 18 (#4259) * build-scripts/build_llvm.py: bump to llvm 18 cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4210 why not 20? because, as of writing this, 19 is the latest released version for the xtensa fork of llvm: https://github.com/espressif/llvm-project why not 19? because of a bug in the xtensa fork of llvm: https://github.com/espressif/llvm-project/issues/112 while we can use different versions for different targets, it's nicer to use the same version everywhere when possible. * spec-test-script/runtest.py: --size-level=0 for x86-64 with the recent version of LLVM, wamrc --size-level=1 often generates R_X86_64_32S relocations which fail on load with the infamous error: "relocation truncated to fit R_X86_64_32S failed" it seems that these relocations are often for jump tables. this commit workarounds it with --size-level=0. an alternative is to disable jump tables. (although it seems that jump tables are not the only source of these relocations.) cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3035 it might be better to do this in wamrc itself. however, currently target info is not available there in case of native compilation. related: https://github.com/bytecodealliance/wasm-micro-runtime/issues/3356 * wamr-compiler: size_level=0 for sgx mode cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3035 * fix: improve error handling of snprintf() in send_thread_stop_status() (#4234) Prevent `MAX_PACKET_SIZE - len` from overflowing. * Don't call os_thread_get_stack_boundary unless we actually use it (#4264) Previously, if the user sets their own stack boundary, we still compute the thread stack boundary (which is expensive), then immediately discard the result. This change makes the expensive call only if we need it for sure. * CI: make macos' build_samples_wasm_c_api similar to ubuntu (#4253) * avoid access null pointer (#4262) * disable compiler to prevent get_current_target() crash (#4251) * product-mini/platforms/windows: set C++17 explicitly (#4269) The recent LLVM uses std::optional, which is C++17. * fix buf checking in load_table_section (#4276) Signed-off-by: Su Yihan <yihan.su@intel.com> * Refactor fast-interpreter SIMD compilation flags (#4261) - enable SIMD flag by default unless hardware limitation - use SIMDE flag to control fast-interpreter behavior * Bypass wamr_ide-related components from the release process. (#4268) Mostly because of some observations: - There is no actual usage reported. - Both ide-ext and ide-docker-image have not been maintained for quite a while. - At the very least, there is no need to recompile it every time when there are no modifications. * Set CMAKE_OSX_SYSROOT when building lldb (#4274) CMake 4 no longer sets the CMAKE_OSX_SYSROOT variable by default, causing the lldb build to fail after all GitHub-hosted runners have been upgraded to CMake 4. As a workaround, the variable is set using CMake command line options. There is a PR to fix this issue in the llvm-project: https://github.com/llvm/llvm-project/pull/138020. We might want to remove this workaround after that PR has been merged. * Check for WASM_ENABLE_SIMDE in a couple more places (#4266) For WAMR users who don't use cmake, it's possible that WASM_ENABLE_SIMD is set when WASM_ENABLE_SIMDE isn't. This was causing build failures. * Add error handling for sgx ci (#4222) > Process completed with exit code 143. It will attempt to run spec test scripts three times if they end with code 143. It is a known issue with GitHub-hosted runners. Usually, increasing the swap file can help avoid it. However, sometimes error 143 still occurs. To prevent confusion, let's capture error 143 and allow the CI to pass. * Add select 128 (#4236) Add select 128 * Merge commit from fork * Update version to 2.3.0 (#4171) - Update version to 2.3.0 - Update RELEASE_NOTES.md. Remove commits that forget to squash when PRs were merged, and some updates on commit messages --------- Co-authored-by: James Marsh <mrshnja@amazon.co.uk> Co-authored-by: liang.he@intel.com <liang.he@intel.com> Co-authored-by: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> * Fix SIMD load lane to avoid incompatible pointer types (#4278) * Fixed unit tests on X86_32 (#4279) * fix unit tests on x86_32 * enbale wasm-c-api unit test on X86_32 * enable aot-stack-frame unit test on X86_32 * add ci: unit tests on X86_32 * feat(yml): Add ESP32-P4 and ESP32-C5 support (#4270) - Add ESP32-P4 and ESP32-C5 support - Support for compiler options of different floating-point types in various RISC-V chips * build(deps): Bump github/codeql-action from 3.28.17 to 3.28.18 (#4285) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.17 to 3.28.18. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.17...v3.28.18) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.28.18 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Improve Embedding WAMR guideline (#4263) (#4284) * Fix CMakeList example by adding -lm * Add bh_read_file inclusion to CMakeList * replace non-existing read_binary_to_buffer() to existing bh_read_file_to_buffer() * add #include initialization Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> * add a sample to use cmake package (#4291) - add a sample to use cmake package * feat: Add instruction metering for interpreter (#4122) - add instruction metering support with execution limit - initialize instruction execution limit in exec_env - docs: add instruction metering section to build_wamr documentation * Fix Compiler Error C2491 (#4286) > Data, static data members, and functions can be declared as `dllimports` but not defined as `dllimports`. https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2491?view=msvc-170 * Revert the location to install public headers (#4295) This partly reverts "Cmake improvements". (https://github.com/bytecodealliance/wasm-micro-runtime/pull/4076) Recently we changed the location to install public headers. For example, Old: include/wasm_export.h New: include/iwasm/wasm_export.h For cmake-based user applications using find_package(iwasm), the cmake package, namely target_include_directories(INSTALL_INTERFACE), is expected to add necessary compiler options like -isystem automatically. (See samples/printversion for an example of such user applications.) However, in reality, not every user application uses cmake. This commit reverts the location to install public headers for now, to avoid breakage for non-cmake user applications. In case we want to re-apply the location change in future, we should better communicate to the users. (eg. document migration proceduces in release notes.) Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/4290 References: https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.html * Enhance type checking for function types in loader and improve error handling (#4294) Especially when GC is enabled, a valid item of `module->types` needs additional checks before casting to WASMFuncType. Also, avoid overflowing if reftype_map_count is 0. Additionally, correctly set IN_OSS_FUZZ based on CFLAGS_ENV for sanitizer configuration. Update ASan and UBSan messages for clarity in non-oss-fuzz environments. * Dockerfile.vx-delegate build error fix (#4273) - specify tensorflow version & bugfix * Enable runtime API exposure for MSVC builds (#4287) * updating WASI stdio handle initialization and build options for UVWASI (#4260) * Bump version to 2.3.1 and update release notes (#4303) * Fix a linking error caused by commit #3580d1 (#4311) > **Fix a release-blocking issue** --- Like: ``` vmlib.lib(blocking_op.obj) : error LNK2019: unresolved external symbol __imp_wasm_runtime_begin_blocking_op referenced in function blocking_op_close [D:\a\wasm-micro-runtime\wasm-micro-runtime\wamr-compiler\build\wamrc.vcxproj] vmlib.lib(blocking_op.obj) : error LNK2019: unresolved external symbol __imp_wasm_runtime_end_blocking_op referenced in function blocking_op_close [D:\a\wasm-micro-runtime\wasm-micro-runtime\wamr-compiler\build\wamrc.vcxproj] ``` * add load_by_name in wasi-nn (#4298) * build(deps): Bump ossf/scorecard-action from 2.4.1 to 2.4.2 (#4315) Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.4.1 to 2.4.2. - [Release notes](https://github.com/ossf/scorecard-action/releases) - [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md) - [Commits](f49aabe0b5...05b42c6244) --- updated-dependencies: - dependency-name: ossf/scorecard-action dependency-version: 2.4.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump uvwasi to latest commit #392e1f1 (#4312) * wasi_nn_openvino.c: fix a few printf formats (#4310) * wasi-nn: remove "backends" argument from detect_and_load_backend() (#4309) it seems meaningless and quite confusing to access a table with two aliases ("lookup" and "backends") within a function. no functional changes are intended. * fix wasi-nn abi definitions (#4307) sync with a more appropriate version of the definitions. as we use the "wasi_ephemeral_nn", which is p1-based, it seems more appropriate to use definitions from witx, not wit. it's a bit unfortunate p2-based wasi-nn made gratuitous changes like this from p1. note: this is an ABI change. * wasi-nn: fix shared library filenames for macOS (#4306) tested with openvino * wasi_nn_openvino.c: make this buildable (#4305) * handle nullable heap reference types in import section (#4302) * wasi-nn: protect the backend lookup table with a lock (#4319) this would avoid potential issues when multiple instances happen to make an attempt to load a backend at the same time. Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/4314 * wasi_nn.h: add import_name attribute (#4328) this would fix undefined symbol errors by making it clear these functions are imported. references:e2c698c7e8/llvm/lib/MC/WasmObjectWriter.cpp (L1798-L1799)e2c698c7e8/llvm/lib/Object/WasmObjectFile.cpp (L749-L752)e2c698c7e8/lld/wasm/Symbols.cpp (L203)e2c698c7e8/lld/wasm/Relocations.cpp (L36-L40)* wasi-nn: remove unused wasi_nn_dump_tensor_dimension prototype (#4325) * Add wamrc compilation into Windows CI workflow (#4327) +formatting * Update binary compression steps to follow symlinks for actual files (#4321) By default, zip follows symbolic links and includes the actual files or directories they point to in the archive. * Update Dockerfile for Zephyr SDK and Zephyr-project versioning (#4335) Use a minimum manifest to reduce time consumption * Collective fix: fix some typos (#4337) * wasi-nn: move some host-only things out of wasi_nn_types.h (#4334) cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4324 * wasi-nn: fix the size of tensor->type (#4333) * this enum is (@witx tag u8) in witx * it seems that some wasm modules actually use non-zero padding and cause errors * it's a bad practice to use C enum for ABI description anyway * remove temporary wasi-libc build steps from CI workflows (#4343) Ref: https://github.com/bytecodealliance/wasm-micro-runtime/pull/2465 * wasi_nn.h: make this compatible with wasi_ephemeral_nn (#4330) - wasi_nn.h: make this compatible with wasi_ephemeral_nn cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4323 - fix WASM_ENABLE_WASI_EPHEMERAL_NN build this structure is used by host logic as well. ideally definitions for wasm and host should be separated. until it happens, check __wasm__ to avoid the breakage. * wasi-nn: do not assign wasi_nn_ctx->backend multiple times (#4329) * build(deps): Bump github/codeql-action from 3.28.18 to 3.28.19 (#4346) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.18 to 3.28.19. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.18...v3.28.19) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.28.19 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * wasi_socket_ext.c: avoid tls to make this library-friendly (#4338) * Enable aot memory64 sw bounds checks by default (#4350) - enable aot memory64 sw bounds checks by default * build(deps): Bump requests from 2.32.3 to 2.32.4 in /build-scripts (#4349) Bumps [requests](https://github.com/psf/requests) from 2.32.3 to 2.32.4. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.32.3...v2.32.4) --- updated-dependencies: - dependency-name: requests dependency-version: 2.32.4 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * wasi_nn_types.h: remove a seemingly stale comment (#4348) * add heap-type check for GC when ref.null (#4300) - According to [Link 1](https://webassembly.github.io/gc/core/valid/instructions.html#xref-syntax-instructions-syntax-instr-ref-mathsf-ref-null-mathit-ht), we must ensure that the heap type is valid when ref.null. - According to [Link 2](https://webassembly.github.io/gc/core/valid/types.html#heap-types), a heap type is considered valid if it is either a concrete heap type or an abstract heap type. However, in this function, the check for abstract heap types (absheaptype) was clearly missing, so this condition needs to be added explicitly in the if statement. - When GC is disabled, no change is needed. - When GC is enabled, heap types in WAMR are LEB-encoded values ([Link 3](https://webassembly.github.io/gc/core/appendix/index-types.html)). Therefore, we must use read_leb_int32 to parse the heap type correctly. And we can compute the original type1 using type1 = (uint8)((int32)0x80 + heap_type);. * wamr-wasi-extensions: add a cmake package to provide our wasi extension (#4344) * wasi_ephemeral_nn.h: add a convenience wrapper header * wamr-wasi-extensions: add a cmake package to provide our wasi extension the sample app was tested with: * wasmtime * iwasm with https://github.com/bytecodealliance/wasm-micro-runtime/pull/4308 currently only contains wasi-nn. maybe it makes sense to add lib-socket things as well. cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4288 * wasi_nn_openvino.c: remove the tensor layout adjustment logic (#4308) the logic in question seems like an attempt to work around some application bugs. my wild guess is that it was for classification-example. cf. https://github.com/bytecodealliance/wasmtime/issues/10867 * Update type validation in load_table_import() and load_table() (#4296) Prevent from value type. https://webassembly.github.io/spec/core/valid/types.html#table-types https://webassembly.github.io/gc/core/syntax/types.html#reference-types * Follow #4268 to deprecate wamr_ide-related components (#4341) refer to: Bypass wamr_ide-related components from the release process. (#4268) * clean up incompatible running mode checks in test script and ci (#4342) Rearrange the content of do_execute_in_running_mode() in alphabetical order. Add an incompatible check for x86_32. Now, all belows will be bypassed: - jit, fast-jit, multi-tier-jit - memory64 - multi-memory - simd * Update WABT downloads URL (#4357) Plus, skip unsupported running mode instead quit during wamr compiler test * Modify AOT static PGO to conform to llvm-18 and add a CI job to test static PGO on the coremark benchmark (#4345) * static PGO compatible with llvm18 and add CI job to test static PGO on coremark benchmark * update comments and warning info, bitmaps section in llvm profdata shouldn't be used in PGO * Collective fix for typos and minor bugs (#4369) * wasi-nn: fix backend leak on multiple loads (#4366) cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4340 * build(deps): Bump github/codeql-action from 3.28.19 to 3.29.0 (#4371) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.19 to 3.29.0. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.19...v3.29.0) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.29.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * add validation for array type in load_init_expr(GC only) (#4370) * wasi_nn_openvino.c: remove broken xml check (#4365) `xml.buf[xml.size]` check is broken because it accesses past the end of the buffer. anyway, openvino doesn't seem to care the NUL termination. * wamr-wasi-extensions: add lib-socket things (#4360) * improve installation steps for wasi-sdk and wabt on Windows (#4359) * wasi_ephemeral_nn.h: prefix identfiers to avoid too generic names (#4358) * wasi_nn_openvino.c: add a missing buffer overflow check in get_output (#4353) cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4351 * send an empty/error reply from server (#4362) Signed-off-by: Su Yihan <yihan.su@intel.com> * wasi_nn_openvino.c: remove pre/postprocessing and layout assumptions (#4361) as wasi-nn doesn't have these concepts, the best we can do without risking breaking certain applications here is to pass through tensors as they are. this matches wasmtime's behavior. tested with: * wasmtime classification-example (with this change, this example fails on tensor size mismatch instead of implicitly resizing it.) * license-plate-recognition-barrier-0007, a converted version with non-fp32 output. [1] (with this change, this model outputs integers as expected.) [1]cd7ebe313b/models/public/license-plate-recognition-barrier-0007* add nn-cli example (#4373) an example application with flexible cli options which aims to allow us to perform any wasi-nn operations. eg. ``` --load-graph=file=fixture/model.xml,file=fixture/model.bin,id=graph --init-execution-context=graph-id=graph,id=ctx --set-input=file=fixture/tensor.bgr,context-id=ctx,dim=1,dim=3,dim=224,dim=224 --compute=context-id=ctx --get-output=context-id=ctx,file=output.bin ``` * wasi-nn: apply the shared library hack to darwin as well (#4374) copied from the linux version. i'm a bit skeptical with this workaround though. it might be simpler to prohibit the use of wamr api in these shared libraries. after all, what these libraries do is nothing specific to wasm. * wasi-nn: don't try to deinit uninitialized backend (#4375) cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4339 * core/iwasm/libraries/wasi-nn/test/build.sh: add a tip for intel mac (#4389) i keep forgetting this and had to re-investigate it at least twice. hopefully this can be helpful for others too. * wasi_nn_tensorflowlite.cpp: reject non-fp32 input earlier (#4388) this backend assumes fp32 here and there. it's safer to reject unexpected inputs explicitly. * Fix several issues related to night-run CI and test scripts. (#4385) - remove duplicated options - fix test script - change ci to use binary * core/iwasm/libraries/wasi-nn/test: use the correct version of keras (#4383) --------- Signed-off-by: Huang Qi <huangqi3@xiaomi.com> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Peter Tatrai <peter.tatrai.ext@siemens.com> Signed-off-by: buxiasen <buxiasen@xiaomi.com> Signed-off-by: Su Yihan <yihan.su@intel.com> Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Co-authored-by: Huang Qi <huangqi3@xiaomi.com> Co-authored-by: Marcin Kolny <mkolny@amazon.com> Co-authored-by: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wenyong Huang <wenyong.huang@intel.com> Co-authored-by: Xavier Del Campo <90845888+midokura-xavi92@users.noreply.github.com> Co-authored-by: Tomáš Malý <malytomas@users.noreply.github.com> Co-authored-by: Viacheslav Palchikov <palchikov@gmail.com> Co-authored-by: yangkun27 <yangkun27@xiaomi.com> Co-authored-by: Jérôme Vouillon <jerome.vouillon@gmail.com> Co-authored-by: peter-tatrai <peter.tatrai.ext@siemens.com> Co-authored-by: eric <chenliuyang_1989@163.com> Co-authored-by: TL <tianlong.liang@intel.com> Co-authored-by: jia xiang <58927968+Jiax-cn@users.noreply.github.com> Co-authored-by: xiangjia.xj <xiangjia.xj@alibaba-inc.com> Co-authored-by: Georgii Rylov <godjan@amazon.co.uk> Co-authored-by: Jesse Wilson <jwilson@squareup.com> Co-authored-by: Zhen Kong <zhkon@microsoft.com> Co-authored-by: James Ring <sjr@jdns.org> Co-authored-by: James Marsh <mrshnja@amazon.co.uk> Co-authored-by: jammar1 <108334558+jammar1@users.noreply.github.com> Co-authored-by: Maks Litskevich <makslit@amazon.com> Co-authored-by: Marcin Kolny <marcin.kolny@gmail.com> Co-authored-by: buxiasen <buxiasen@xiaomi.com> Co-authored-by: dongsheng28849455 <68947925+dongsheng28849455@users.noreply.github.com> Co-authored-by: zhanheng1 <Zhanheng.Qin@sony.com> Co-authored-by: Raul Hernandez <raul.hernandez@spaceface.dev> Co-authored-by: YAMAMOTO Takashi <yamamoto@midokura.com> Co-authored-by: a seven <w4454962@users.noreply.github.com> Co-authored-by: Zhenwei Jin <109658203+kylo5aby@users.noreply.github.com> Co-authored-by: Liu Jia <jia3.liu@intel.com> Co-authored-by: Chris Woods <6069113+woodsmc@users.noreply.github.com> Co-authored-by: Su Yihan <yihan.su@intel.com> Co-authored-by: ChenWen <63690793+cwespressif@users.noreply.github.com> Co-authored-by: Krisztian <34309983+kr-t@users.noreply.github.com> Co-authored-by: Alix ANNERAUD <alix@anneraud.fr> Co-authored-by: hongxia <103626902+HongxiaWangSSSS@users.noreply.github.com>
8018 lines
300 KiB
C
8018 lines
300 KiB
C
/*
|
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
*/
|
|
|
|
#include "wasm_interp.h"
|
|
#include "bh_log.h"
|
|
#include "wasm_runtime.h"
|
|
#include "wasm_opcode.h"
|
|
#include "wasm_loader.h"
|
|
#include "wasm_memory.h"
|
|
#include "../common/wasm_exec_env.h"
|
|
#if WASM_ENABLE_GC != 0
|
|
#include "../common/gc/gc_object.h"
|
|
#include "mem_alloc.h"
|
|
#if WASM_ENABLE_STRINGREF != 0
|
|
#include "string_object.h"
|
|
#endif
|
|
#endif
|
|
#if WASM_ENABLE_SHARED_MEMORY != 0
|
|
#include "../common/wasm_shared_memory.h"
|
|
#endif
|
|
|
|
#if WASM_ENABLE_SIMDE != 0
|
|
#include "simde/wasm/simd128.h"
|
|
#endif
|
|
|
|
typedef int32 CellType_I32;
|
|
typedef int64 CellType_I64;
|
|
typedef float32 CellType_F32;
|
|
typedef float64 CellType_F64;
|
|
|
|
#if WASM_ENABLE_THREAD_MGR == 0
|
|
#define get_linear_mem_size() linear_mem_size
|
|
#else
|
|
/**
|
|
* Load memory data size in each time boundary check in
|
|
* multi-threading mode since it may be changed by other
|
|
* threads in memory.grow
|
|
*/
|
|
#define get_linear_mem_size() GET_LINEAR_MEMORY_SIZE(memory)
|
|
#endif
|
|
|
|
#if WASM_ENABLE_SHARED_HEAP != 0
|
|
#define app_addr_in_shared_heap(app_addr, bytes) \
|
|
(shared_heap && (app_addr) >= shared_heap_start_off \
|
|
&& (app_addr) <= shared_heap_end_off - bytes + 1)
|
|
|
|
#define shared_heap_addr_app_to_native(app_addr, native_addr) \
|
|
native_addr = shared_heap_base_addr + ((app_addr)-shared_heap_start_off)
|
|
|
|
#define CHECK_SHARED_HEAP_OVERFLOW(app_addr, bytes, native_addr) \
|
|
if (app_addr_in_shared_heap(app_addr, bytes)) \
|
|
shared_heap_addr_app_to_native(app_addr, native_addr); \
|
|
else
|
|
#else
|
|
#define CHECK_SHARED_HEAP_OVERFLOW(app_addr, bytes, native_addr)
|
|
#endif
|
|
|
|
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|
|
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
|
|
#define CHECK_MEMORY_OVERFLOW(bytes) \
|
|
do { \
|
|
uint64 offset1 = (uint64)offset + (uint64)addr; \
|
|
CHECK_SHARED_HEAP_OVERFLOW(offset1, bytes, maddr) \
|
|
if (disable_bounds_checks || offset1 + bytes <= get_linear_mem_size()) \
|
|
/* If offset1 is in valid range, maddr must also \
|
|
be in valid range, no need to check it again. */ \
|
|
maddr = memory->memory_data + offset1; \
|
|
else \
|
|
goto out_of_bounds; \
|
|
} while (0)
|
|
|
|
#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \
|
|
do { \
|
|
uint64 offset1 = (uint32)(start); \
|
|
CHECK_SHARED_HEAP_OVERFLOW(offset1, bytes, maddr) \
|
|
if (disable_bounds_checks || offset1 + bytes <= get_linear_mem_size()) \
|
|
/* App heap space is not valid space for \
|
|
bulk memory operation */ \
|
|
maddr = memory->memory_data + offset1; \
|
|
else \
|
|
goto out_of_bounds; \
|
|
} while (0)
|
|
#else
|
|
#define CHECK_MEMORY_OVERFLOW(bytes) \
|
|
do { \
|
|
uint64 offset1 = (uint64)offset + (uint64)addr; \
|
|
CHECK_SHARED_HEAP_OVERFLOW(offset1, bytes, maddr) \
|
|
maddr = memory->memory_data + offset1; \
|
|
} while (0)
|
|
|
|
#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \
|
|
do { \
|
|
uint64 offset1 = (uint32)(start); \
|
|
CHECK_SHARED_HEAP_OVERFLOW(offset1, bytes, maddr) \
|
|
maddr = memory->memory_data + offset1; \
|
|
} while (0)
|
|
#endif /* !defined(OS_ENABLE_HW_BOUND_CHECK) \
|
|
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 */
|
|
|
|
#define CHECK_ATOMIC_MEMORY_ACCESS(align) \
|
|
do { \
|
|
if (((uintptr_t)maddr & (align - 1)) != 0) \
|
|
goto unaligned_atomic; \
|
|
} while (0)
|
|
|
|
#if WASM_ENABLE_INSTRUCTION_METERING != 0
|
|
#define CHECK_INSTRUCTION_LIMIT() \
|
|
if (instructions_left == 0) { \
|
|
wasm_set_exception(module, "instruction limit exceeded"); \
|
|
goto got_exception; \
|
|
} \
|
|
else if (instructions_left > 0) \
|
|
instructions_left--;
|
|
|
|
#else
|
|
#define CHECK_INSTRUCTION_LIMIT() (void)0
|
|
#endif
|
|
|
|
static inline uint32
|
|
rotl32(uint32 n, uint32 c)
|
|
{
|
|
const uint32 mask = (31);
|
|
c = c % 32;
|
|
c &= mask;
|
|
return (n << c) | (n >> ((0 - c) & mask));
|
|
}
|
|
|
|
static inline uint32
|
|
rotr32(uint32 n, uint32 c)
|
|
{
|
|
const uint32 mask = (31);
|
|
c = c % 32;
|
|
c &= mask;
|
|
return (n >> c) | (n << ((0 - c) & mask));
|
|
}
|
|
|
|
static inline uint64
|
|
rotl64(uint64 n, uint64 c)
|
|
{
|
|
const uint64 mask = (63);
|
|
c = c % 64;
|
|
c &= mask;
|
|
return (n << c) | (n >> ((0 - c) & mask));
|
|
}
|
|
|
|
static inline uint64
|
|
rotr64(uint64 n, uint64 c)
|
|
{
|
|
const uint64 mask = (63);
|
|
c = c % 64;
|
|
c &= mask;
|
|
return (n >> c) | (n << ((0 - c) & mask));
|
|
}
|
|
|
|
static inline float32
|
|
f32_min(float32 a, float32 b)
|
|
{
|
|
if (isnan(a) || isnan(b))
|
|
return NAN;
|
|
else if (a == 0 && a == b)
|
|
return signbit(a) ? a : b;
|
|
else
|
|
return a > b ? b : a;
|
|
}
|
|
|
|
static inline float32
|
|
f32_max(float32 a, float32 b)
|
|
{
|
|
if (isnan(a) || isnan(b))
|
|
return NAN;
|
|
else if (a == 0 && a == b)
|
|
return signbit(a) ? b : a;
|
|
else
|
|
return a > b ? a : b;
|
|
}
|
|
|
|
static inline float64
|
|
f64_min(float64 a, float64 b)
|
|
{
|
|
if (isnan(a) || isnan(b))
|
|
return NAN;
|
|
else if (a == 0 && a == b)
|
|
return signbit(a) ? a : b;
|
|
else
|
|
return a > b ? b : a;
|
|
}
|
|
|
|
static inline float64
|
|
f64_max(float64 a, float64 b)
|
|
{
|
|
if (isnan(a) || isnan(b))
|
|
return NAN;
|
|
else if (a == 0 && a == b)
|
|
return signbit(a) ? b : a;
|
|
else
|
|
return a > b ? a : b;
|
|
}
|
|
|
|
static inline uint32
|
|
clz32(uint32 type)
|
|
{
|
|
uint32 num = 0;
|
|
if (type == 0)
|
|
return 32;
|
|
while (!(type & 0x80000000)) {
|
|
num++;
|
|
type <<= 1;
|
|
}
|
|
return num;
|
|
}
|
|
|
|
static inline uint32
|
|
clz64(uint64 type)
|
|
{
|
|
uint32 num = 0;
|
|
if (type == 0)
|
|
return 64;
|
|
while (!(type & 0x8000000000000000LL)) {
|
|
num++;
|
|
type <<= 1;
|
|
}
|
|
return num;
|
|
}
|
|
|
|
static inline uint32
|
|
ctz32(uint32 type)
|
|
{
|
|
uint32 num = 0;
|
|
if (type == 0)
|
|
return 32;
|
|
while (!(type & 1)) {
|
|
num++;
|
|
type >>= 1;
|
|
}
|
|
return num;
|
|
}
|
|
|
|
static inline uint32
|
|
ctz64(uint64 type)
|
|
{
|
|
uint32 num = 0;
|
|
if (type == 0)
|
|
return 64;
|
|
while (!(type & 1)) {
|
|
num++;
|
|
type >>= 1;
|
|
}
|
|
return num;
|
|
}
|
|
|
|
static inline uint32
|
|
popcount32(uint32 u)
|
|
{
|
|
uint32 ret = 0;
|
|
while (u) {
|
|
u = (u & (u - 1));
|
|
ret++;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static inline uint32
|
|
popcount64(uint64 u)
|
|
{
|
|
uint32 ret = 0;
|
|
while (u) {
|
|
u = (u & (u - 1));
|
|
ret++;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static float
|
|
local_copysignf(float x, float y)
|
|
{
|
|
union {
|
|
float f;
|
|
uint32 i;
|
|
} ux = { x }, uy = { y };
|
|
ux.i &= 0x7fffffff;
|
|
ux.i |= uy.i & 0x80000000;
|
|
return ux.f;
|
|
}
|
|
|
|
static double
|
|
local_copysign(double x, double y)
|
|
{
|
|
union {
|
|
double f;
|
|
uint64 i;
|
|
} ux = { x }, uy = { y };
|
|
ux.i &= UINT64_MAX / 2;
|
|
ux.i |= uy.i & 1ULL << 63;
|
|
return ux.f;
|
|
}
|
|
|
|
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
|
#define LOAD_U32_WITH_2U16S(addr) (*(uint32 *)(addr))
|
|
#define LOAD_PTR(addr) (*(void **)(addr))
|
|
#else /* else of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
|
static inline uint32
|
|
LOAD_U32_WITH_2U16S(void *addr)
|
|
{
|
|
union {
|
|
uint32 val;
|
|
uint16 u16[2];
|
|
} u;
|
|
|
|
bh_assert(((uintptr_t)addr & 1) == 0);
|
|
u.u16[0] = ((uint16 *)addr)[0];
|
|
u.u16[1] = ((uint16 *)addr)[1];
|
|
return u.val;
|
|
}
|
|
#if UINTPTR_MAX == UINT32_MAX
|
|
#define LOAD_PTR(addr) ((void *)LOAD_U32_WITH_2U16S(addr))
|
|
#elif UINTPTR_MAX == UINT64_MAX
|
|
static inline void *
|
|
LOAD_PTR(void *addr)
|
|
{
|
|
uintptr_t addr1 = (uintptr_t)addr;
|
|
union {
|
|
void *val;
|
|
uint32 u32[2];
|
|
uint16 u16[4];
|
|
} u;
|
|
|
|
bh_assert(((uintptr_t)addr & 1) == 0);
|
|
if ((addr1 & (uintptr_t)7) == 0)
|
|
return *(void **)addr;
|
|
|
|
if ((addr1 & (uintptr_t)3) == 0) {
|
|
u.u32[0] = ((uint32 *)addr)[0];
|
|
u.u32[1] = ((uint32 *)addr)[1];
|
|
}
|
|
else {
|
|
u.u16[0] = ((uint16 *)addr)[0];
|
|
u.u16[1] = ((uint16 *)addr)[1];
|
|
u.u16[2] = ((uint16 *)addr)[2];
|
|
u.u16[3] = ((uint16 *)addr)[3];
|
|
}
|
|
return u.val;
|
|
}
|
|
#endif /* end of UINTPTR_MAX */
|
|
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
static void
|
|
init_frame_refs(uint8 *frame_ref, uint32 cell_num, WASMFunctionInstance *func)
|
|
{
|
|
uint32 i, j;
|
|
|
|
memset(frame_ref, 0, cell_num);
|
|
|
|
for (i = 0, j = 0; i < func->param_count; i++) {
|
|
if (wasm_is_type_reftype(func->param_types[i])
|
|
&& !wasm_is_reftype_i31ref(func->param_types[i])) {
|
|
frame_ref[j++] = 1;
|
|
#if UINTPTR_MAX == UINT64_MAX
|
|
frame_ref[j++] = 1;
|
|
#endif
|
|
}
|
|
else {
|
|
j += wasm_value_type_cell_num(func->param_types[i]);
|
|
}
|
|
}
|
|
|
|
for (i = 0; i < func->local_count; i++) {
|
|
if (wasm_is_type_reftype(func->local_types[i])
|
|
&& !wasm_is_reftype_i31ref(func->local_types[i])) {
|
|
frame_ref[j++] = 1;
|
|
#if UINTPTR_MAX == UINT64_MAX
|
|
frame_ref[j++] = 1;
|
|
#endif
|
|
}
|
|
else {
|
|
j += wasm_value_type_cell_num(func->local_types[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
uint8 *
|
|
wasm_interp_get_frame_ref(WASMInterpFrame *frame)
|
|
{
|
|
return frame->frame_ref;
|
|
}
|
|
|
|
/* Return the corresponding ref slot of the given slot of local
|
|
variable or stack pointer. */
|
|
|
|
#define COMPUTE_FRAME_REF(ref, off) (ref + (unsigned)(off))
|
|
|
|
#define FRAME_REF(off) COMPUTE_FRAME_REF(frame_ref, off)
|
|
|
|
#if UINTPTR_MAX == UINT64_MAX
|
|
#define SET_FRAME_REF(off) *FRAME_REF(off) = *FRAME_REF(off + 1) = 1
|
|
#define CLEAR_FRAME_REF(off) \
|
|
(unsigned)off >= local_cell_num \
|
|
? (*FRAME_REF(off) = *FRAME_REF(off + 1) = 0) \
|
|
: (void)0
|
|
#else
|
|
#define SET_FRAME_REF(off) *FRAME_REF(off) = 1
|
|
#define CLEAR_FRAME_REF(off) \
|
|
(unsigned)off >= local_cell_num ? (*FRAME_REF(off) = 0) : (void)0
|
|
#endif
|
|
|
|
#define FRAME_REF_FOR(frame, p) \
|
|
COMPUTE_FRAME_REF(frame->frame_ref, p - frame->lp)
|
|
|
|
#define CLEAR_FRAME_REF_FOR(p, n) \
|
|
do { \
|
|
int32 ref_i, ref_n = (int32)(n); \
|
|
uint8 *ref = FRAME_REF(p - frame_lp); \
|
|
for (ref_i = 0; ref_i < ref_n; ref_i++) \
|
|
ref[ref_i] = 0; \
|
|
} while (0)
|
|
#endif /* end of WASM_ENABLE_GC != 0 */
|
|
|
|
#define read_uint32(p) \
|
|
(p += sizeof(uint32), LOAD_U32_WITH_2U16S(p - sizeof(uint32)))
|
|
|
|
#define GET_LOCAL_INDEX_TYPE_AND_OFFSET() \
|
|
do { \
|
|
uint32 param_count = cur_func->param_count; \
|
|
local_idx = read_uint32(frame_ip); \
|
|
bh_assert(local_idx < param_count + cur_func->local_count); \
|
|
local_offset = cur_func->local_offsets[local_idx]; \
|
|
if (local_idx < param_count) \
|
|
local_type = cur_func->param_types[local_idx]; \
|
|
else \
|
|
local_type = cur_func->local_types[local_idx - param_count]; \
|
|
} while (0)
|
|
|
|
#define GET_OFFSET() (frame_ip += 2, *(int16 *)(frame_ip - 2))
|
|
|
|
#define SET_OPERAND_I32(off, value) \
|
|
do { \
|
|
*(uint32 *)(frame_lp + *(int16 *)(frame_ip + off)) = value; \
|
|
} while (0)
|
|
#define SET_OPERAND_F32(off, value) \
|
|
do { \
|
|
*(float32 *)(frame_lp + *(int16 *)(frame_ip + off)) = value; \
|
|
} while (0)
|
|
#define SET_OPERAND_I64(off, value) \
|
|
do { \
|
|
uint32 *addr_tmp = frame_lp + *(int16 *)(frame_ip + off); \
|
|
PUT_I64_TO_ADDR(addr_tmp, value); \
|
|
} while (0)
|
|
#define SET_OPERAND_F64(off, value) \
|
|
do { \
|
|
uint32 *addr_tmp = frame_lp + *(int16 *)(frame_ip + off); \
|
|
PUT_F64_TO_ADDR(addr_tmp, value); \
|
|
} while (0)
|
|
#define SET_OPERAND_REF(off, value) \
|
|
do { \
|
|
uint32 *addr_tmp; \
|
|
opnd_off = *(int16 *)(frame_ip + off); \
|
|
addr_tmp = frame_lp + opnd_off; \
|
|
PUT_REF_TO_ADDR(addr_tmp, value); \
|
|
SET_FRAME_REF(ond_off); \
|
|
} while (0)
|
|
|
|
#define SET_OPERAND(op_type, off, value) SET_OPERAND_##op_type(off, value)
|
|
|
|
#define GET_OPERAND_I32(type, off) \
|
|
*(type *)(frame_lp + *(int16 *)(frame_ip + off))
|
|
#define GET_OPERAND_F32(type, off) \
|
|
*(type *)(frame_lp + *(int16 *)(frame_ip + off))
|
|
#define GET_OPERAND_I64(type, off) \
|
|
(type) GET_I64_FROM_ADDR(frame_lp + *(int16 *)(frame_ip + off))
|
|
#define GET_OPERAND_F64(type, off) \
|
|
(type) GET_F64_FROM_ADDR(frame_lp + *(int16 *)(frame_ip + off))
|
|
#define GET_OPERAND_V128(off) \
|
|
GET_V128_FROM_ADDR(frame_lp + *(int16 *)(frame_ip + off))
|
|
#define GET_OPERAND_REF(type, off) \
|
|
(type) GET_REF_FROM_ADDR(frame_lp + *(int16 *)(frame_ip + off))
|
|
|
|
#define GET_OPERAND(type, op_type, off) GET_OPERAND_##op_type(type, off)
|
|
|
|
#define PUSH_I32(value) \
|
|
do { \
|
|
*(int32 *)(frame_lp + GET_OFFSET()) = value; \
|
|
} while (0)
|
|
|
|
#define PUSH_F32(value) \
|
|
do { \
|
|
*(float32 *)(frame_lp + GET_OFFSET()) = value; \
|
|
} while (0)
|
|
|
|
#define PUSH_I64(value) \
|
|
do { \
|
|
uint32 *addr_tmp = frame_lp + GET_OFFSET(); \
|
|
PUT_I64_TO_ADDR(addr_tmp, value); \
|
|
} while (0)
|
|
|
|
#define PUSH_F64(value) \
|
|
do { \
|
|
uint32 *addr_tmp = frame_lp + GET_OFFSET(); \
|
|
PUT_F64_TO_ADDR(addr_tmp, value); \
|
|
} while (0)
|
|
|
|
#define PUSH_REF(value) \
|
|
do { \
|
|
uint32 *addr_tmp; \
|
|
opnd_off = GET_OFFSET(); \
|
|
addr_tmp = frame_lp + opnd_off; \
|
|
PUT_REF_TO_ADDR(addr_tmp, value); \
|
|
SET_FRAME_REF(opnd_off); \
|
|
} while (0)
|
|
|
|
#define PUSH_I31REF(value) \
|
|
do { \
|
|
uint32 *addr_tmp; \
|
|
opnd_off = GET_OFFSET(); \
|
|
addr_tmp = frame_lp + opnd_off; \
|
|
PUT_REF_TO_ADDR(addr_tmp, value); \
|
|
} while (0)
|
|
|
|
#define POP_I32() (*(int32 *)(frame_lp + GET_OFFSET()))
|
|
|
|
#define POP_F32() (*(float32 *)(frame_lp + GET_OFFSET()))
|
|
|
|
#define POP_I64() (GET_I64_FROM_ADDR(frame_lp + GET_OFFSET()))
|
|
|
|
#define POP_V128() (GET_V128_FROM_ADDR(frame_lp + GET_OFFSET()))
|
|
|
|
#define POP_F64() (GET_F64_FROM_ADDR(frame_lp + GET_OFFSET()))
|
|
|
|
#define POP_REF() \
|
|
(opnd_off = GET_OFFSET(), CLEAR_FRAME_REF((unsigned)(opnd_off)), \
|
|
GET_REF_FROM_ADDR(frame_lp + opnd_off))
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
#define SYNC_FRAME_REF() frame->frame_ref = frame_ref
|
|
#define UPDATE_FRAME_REF() frame_ref = frame->frame_ref
|
|
#else
|
|
#define SYNC_FRAME_REF() (void)0
|
|
#define UPDATE_FRAME_REF() (void)0
|
|
#endif
|
|
|
|
#define SYNC_ALL_TO_FRAME() \
|
|
do { \
|
|
frame->ip = frame_ip; \
|
|
SYNC_FRAME_REF(); \
|
|
} while (0)
|
|
|
|
#define UPDATE_ALL_FROM_FRAME() \
|
|
do { \
|
|
frame_ip = frame->ip; \
|
|
UPDATE_FRAME_REF(); \
|
|
} while (0)
|
|
|
|
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
|
#define UPDATE_FRAME_IP_END() (void)0
|
|
#else
|
|
#define UPDATE_FRAME_IP_END() frame_ip_end = wasm_get_func_code_end(cur_func)
|
|
#endif
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
#define RECOVER_FRAME_REF() frame_ref = frame->frame_ref
|
|
#else
|
|
#define RECOVER_FRAME_REF() (void)0
|
|
#endif
|
|
|
|
#define RECOVER_CONTEXT(new_frame) \
|
|
do { \
|
|
frame = (new_frame); \
|
|
cur_func = frame->function; \
|
|
prev_frame = frame->prev_frame; \
|
|
frame_ip = frame->ip; \
|
|
UPDATE_FRAME_IP_END(); \
|
|
frame_lp = frame->lp; \
|
|
RECOVER_FRAME_REF(); \
|
|
} while (0)
|
|
|
|
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
|
#define GET_OPCODE() opcode = *frame_ip++;
|
|
#else
|
|
#define GET_OPCODE() \
|
|
opcode = *frame_ip; \
|
|
frame_ip += 2;
|
|
#endif
|
|
|
|
#define DEF_OP_EQZ(ctype, src_op_type) \
|
|
do { \
|
|
SET_OPERAND(I32, 2, (GET_OPERAND(ctype, src_op_type, 0) == 0)); \
|
|
frame_ip += 4; \
|
|
} while (0)
|
|
|
|
#define DEF_OP_CMP(src_type, src_op_type, cond) \
|
|
do { \
|
|
SET_OPERAND(I32, 4, \
|
|
GET_OPERAND(src_type, src_op_type, 2) \
|
|
cond GET_OPERAND(src_type, src_op_type, 0)); \
|
|
frame_ip += 6; \
|
|
} while (0)
|
|
|
|
#define DEF_OP_BIT_COUNT(src_type, src_op_type, operation) \
|
|
do { \
|
|
SET_OPERAND( \
|
|
src_op_type, 2, \
|
|
(src_type)operation(GET_OPERAND(src_type, src_op_type, 0))); \
|
|
frame_ip += 4; \
|
|
} while (0)
|
|
|
|
#define DEF_OP_NUMERIC(src_type1, src_type2, src_op_type, operation) \
|
|
do { \
|
|
SET_OPERAND(src_op_type, 4, \
|
|
GET_OPERAND(src_type1, src_op_type, 2) \
|
|
operation GET_OPERAND(src_type2, src_op_type, 0)); \
|
|
frame_ip += 6; \
|
|
} while (0)
|
|
|
|
#define DEF_OP_REINTERPRET(src_type, src_op_type) \
|
|
do { \
|
|
SET_OPERAND(src_op_type, 2, GET_OPERAND(src_type, src_op_type, 0)); \
|
|
frame_ip += 4; \
|
|
} while (0)
|
|
|
|
#define DEF_OP_NUMERIC_64 DEF_OP_NUMERIC
|
|
|
|
#define DEF_OP_NUMERIC2(src_type1, src_type2, src_op_type, operation) \
|
|
do { \
|
|
SET_OPERAND(src_op_type, 4, \
|
|
GET_OPERAND(src_type1, src_op_type, 2) operation( \
|
|
GET_OPERAND(src_type2, src_op_type, 0) % 32)); \
|
|
frame_ip += 6; \
|
|
} while (0)
|
|
|
|
#define DEF_OP_NUMERIC2_64(src_type1, src_type2, src_op_type, operation) \
|
|
do { \
|
|
SET_OPERAND(src_op_type, 4, \
|
|
GET_OPERAND(src_type1, src_op_type, 2) operation( \
|
|
GET_OPERAND(src_type2, src_op_type, 0) % 64)); \
|
|
frame_ip += 6; \
|
|
} while (0)
|
|
|
|
#define DEF_ATOMIC_RMW_OPCODE(OP_NAME, op) \
|
|
case WASM_OP_ATOMIC_RMW_I32_##OP_NAME: \
|
|
case WASM_OP_ATOMIC_RMW_I32_##OP_NAME##8_U: \
|
|
case WASM_OP_ATOMIC_RMW_I32_##OP_NAME##16_U: \
|
|
{ \
|
|
uint32 readv, sval; \
|
|
\
|
|
sval = POP_I32(); \
|
|
addr = POP_I32(); \
|
|
\
|
|
if (opcode == WASM_OP_ATOMIC_RMW_I32_##OP_NAME##8_U) { \
|
|
CHECK_MEMORY_OVERFLOW(1); \
|
|
CHECK_ATOMIC_MEMORY_ACCESS(1); \
|
|
\
|
|
shared_memory_lock(memory); \
|
|
readv = (uint32)(*(uint8 *)maddr); \
|
|
*(uint8 *)maddr = (uint8)(readv op sval); \
|
|
shared_memory_unlock(memory); \
|
|
} \
|
|
else if (opcode == WASM_OP_ATOMIC_RMW_I32_##OP_NAME##16_U) { \
|
|
CHECK_MEMORY_OVERFLOW(2); \
|
|
CHECK_ATOMIC_MEMORY_ACCESS(2); \
|
|
\
|
|
shared_memory_lock(memory); \
|
|
readv = (uint32)LOAD_U16(maddr); \
|
|
STORE_U16(maddr, (uint16)(readv op sval)); \
|
|
shared_memory_unlock(memory); \
|
|
} \
|
|
else { \
|
|
CHECK_MEMORY_OVERFLOW(4); \
|
|
CHECK_ATOMIC_MEMORY_ACCESS(4); \
|
|
\
|
|
shared_memory_lock(memory); \
|
|
readv = LOAD_I32(maddr); \
|
|
STORE_U32(maddr, readv op sval); \
|
|
shared_memory_unlock(memory); \
|
|
} \
|
|
PUSH_I32(readv); \
|
|
break; \
|
|
} \
|
|
case WASM_OP_ATOMIC_RMW_I64_##OP_NAME: \
|
|
case WASM_OP_ATOMIC_RMW_I64_##OP_NAME##8_U: \
|
|
case WASM_OP_ATOMIC_RMW_I64_##OP_NAME##16_U: \
|
|
case WASM_OP_ATOMIC_RMW_I64_##OP_NAME##32_U: \
|
|
{ \
|
|
uint64 readv, sval; \
|
|
\
|
|
sval = (uint64)POP_I64(); \
|
|
addr = POP_I32(); \
|
|
\
|
|
if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##8_U) { \
|
|
CHECK_MEMORY_OVERFLOW(1); \
|
|
CHECK_ATOMIC_MEMORY_ACCESS(1); \
|
|
\
|
|
shared_memory_lock(memory); \
|
|
readv = (uint64)(*(uint8 *)maddr); \
|
|
*(uint8 *)maddr = (uint8)(readv op sval); \
|
|
shared_memory_unlock(memory); \
|
|
} \
|
|
else if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##16_U) { \
|
|
CHECK_MEMORY_OVERFLOW(2); \
|
|
CHECK_ATOMIC_MEMORY_ACCESS(2); \
|
|
\
|
|
shared_memory_lock(memory); \
|
|
readv = (uint64)LOAD_U16(maddr); \
|
|
STORE_U16(maddr, (uint16)(readv op sval)); \
|
|
shared_memory_unlock(memory); \
|
|
} \
|
|
else if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##32_U) { \
|
|
CHECK_MEMORY_OVERFLOW(4); \
|
|
CHECK_ATOMIC_MEMORY_ACCESS(4); \
|
|
\
|
|
shared_memory_lock(memory); \
|
|
readv = (uint64)LOAD_U32(maddr); \
|
|
STORE_U32(maddr, (uint32)(readv op sval)); \
|
|
shared_memory_unlock(memory); \
|
|
} \
|
|
else { \
|
|
uint64 op_result; \
|
|
CHECK_MEMORY_OVERFLOW(8); \
|
|
CHECK_ATOMIC_MEMORY_ACCESS(8); \
|
|
\
|
|
shared_memory_lock(memory); \
|
|
readv = (uint64)LOAD_I64(maddr); \
|
|
op_result = readv op sval; \
|
|
STORE_I64(maddr, op_result); \
|
|
shared_memory_unlock(memory); \
|
|
} \
|
|
PUSH_I64(readv); \
|
|
break; \
|
|
}
|
|
|
|
#define DEF_OP_MATH(src_type, src_op_type, method) \
|
|
do { \
|
|
SET_OPERAND(src_op_type, 2, \
|
|
(src_type)method(GET_OPERAND(src_type, src_op_type, 0))); \
|
|
frame_ip += 4; \
|
|
} while (0)
|
|
|
|
#define TRUNC_FUNCTION(func_name, src_type, dst_type, signed_type) \
|
|
static dst_type func_name(src_type src_value, src_type src_min, \
|
|
src_type src_max, dst_type dst_min, \
|
|
dst_type dst_max, bool is_sign) \
|
|
{ \
|
|
dst_type dst_value = 0; \
|
|
if (!isnan(src_value)) { \
|
|
if (src_value <= src_min) \
|
|
dst_value = dst_min; \
|
|
else if (src_value >= src_max) \
|
|
dst_value = dst_max; \
|
|
else { \
|
|
if (is_sign) \
|
|
dst_value = (dst_type)(signed_type)src_value; \
|
|
else \
|
|
dst_value = (dst_type)src_value; \
|
|
} \
|
|
} \
|
|
return dst_value; \
|
|
}
|
|
|
|
TRUNC_FUNCTION(trunc_f32_to_i32, float32, uint32, int32)
|
|
TRUNC_FUNCTION(trunc_f32_to_i64, float32, uint64, int64)
|
|
TRUNC_FUNCTION(trunc_f64_to_i32, float64, uint32, int32)
|
|
TRUNC_FUNCTION(trunc_f64_to_i64, float64, uint64, int64)
|
|
|
|
static bool
|
|
trunc_f32_to_int(WASMModuleInstance *module, uint8 *frame_ip, uint32 *frame_lp,
|
|
float32 src_min, float32 src_max, bool saturating, bool is_i32,
|
|
bool is_sign)
|
|
{
|
|
float32 src_value = GET_OPERAND(float32, F32, 0);
|
|
uint64 dst_value_i64;
|
|
uint32 dst_value_i32;
|
|
|
|
if (!saturating) {
|
|
if (isnan(src_value)) {
|
|
wasm_set_exception(module, "invalid conversion to integer");
|
|
return false;
|
|
}
|
|
else if (src_value <= src_min || src_value >= src_max) {
|
|
wasm_set_exception(module, "integer overflow");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (is_i32) {
|
|
uint32 dst_min = is_sign ? INT32_MIN : 0;
|
|
uint32 dst_max = is_sign ? INT32_MAX : UINT32_MAX;
|
|
dst_value_i32 = trunc_f32_to_i32(src_value, src_min, src_max, dst_min,
|
|
dst_max, is_sign);
|
|
SET_OPERAND(I32, 2, dst_value_i32);
|
|
}
|
|
else {
|
|
uint64 dst_min = is_sign ? INT64_MIN : 0;
|
|
uint64 dst_max = is_sign ? INT64_MAX : UINT64_MAX;
|
|
dst_value_i64 = trunc_f32_to_i64(src_value, src_min, src_max, dst_min,
|
|
dst_max, is_sign);
|
|
SET_OPERAND(I64, 2, dst_value_i64);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
trunc_f64_to_int(WASMModuleInstance *module, uint8 *frame_ip, uint32 *frame_lp,
|
|
float64 src_min, float64 src_max, bool saturating, bool is_i32,
|
|
bool is_sign)
|
|
{
|
|
float64 src_value = GET_OPERAND(float64, F64, 0);
|
|
uint64 dst_value_i64;
|
|
uint32 dst_value_i32;
|
|
|
|
if (!saturating) {
|
|
if (isnan(src_value)) {
|
|
wasm_set_exception(module, "invalid conversion to integer");
|
|
return false;
|
|
}
|
|
else if (src_value <= src_min || src_value >= src_max) {
|
|
wasm_set_exception(module, "integer overflow");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (is_i32) {
|
|
uint32 dst_min = is_sign ? INT32_MIN : 0;
|
|
uint32 dst_max = is_sign ? INT32_MAX : UINT32_MAX;
|
|
dst_value_i32 = trunc_f64_to_i32(src_value, src_min, src_max, dst_min,
|
|
dst_max, is_sign);
|
|
SET_OPERAND(I32, 2, dst_value_i32);
|
|
}
|
|
else {
|
|
uint64 dst_min = is_sign ? INT64_MIN : 0;
|
|
uint64 dst_max = is_sign ? INT64_MAX : UINT64_MAX;
|
|
dst_value_i64 = trunc_f64_to_i64(src_value, src_min, src_max, dst_min,
|
|
dst_max, is_sign);
|
|
SET_OPERAND(I64, 2, dst_value_i64);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
#define DEF_OP_TRUNC_F32(min, max, is_i32, is_sign) \
|
|
do { \
|
|
if (!trunc_f32_to_int(module, frame_ip, frame_lp, min, max, false, \
|
|
is_i32, is_sign)) \
|
|
goto got_exception; \
|
|
frame_ip += 4; \
|
|
} while (0)
|
|
|
|
#define DEF_OP_TRUNC_F64(min, max, is_i32, is_sign) \
|
|
do { \
|
|
if (!trunc_f64_to_int(module, frame_ip, frame_lp, min, max, false, \
|
|
is_i32, is_sign)) \
|
|
goto got_exception; \
|
|
frame_ip += 4; \
|
|
} while (0)
|
|
|
|
#define DEF_OP_TRUNC_SAT_F32(min, max, is_i32, is_sign) \
|
|
do { \
|
|
(void)trunc_f32_to_int(module, frame_ip, frame_lp, min, max, true, \
|
|
is_i32, is_sign); \
|
|
frame_ip += 4; \
|
|
} while (0)
|
|
|
|
#define DEF_OP_TRUNC_SAT_F64(min, max, is_i32, is_sign) \
|
|
do { \
|
|
(void)trunc_f64_to_int(module, frame_ip, frame_lp, min, max, true, \
|
|
is_i32, is_sign); \
|
|
frame_ip += 4; \
|
|
} while (0)
|
|
|
|
#define DEF_OP_CONVERT(dst_type, dst_op_type, src_type, src_op_type) \
|
|
do { \
|
|
dst_type value = (dst_type)(src_type)POP_##src_op_type(); \
|
|
PUSH_##dst_op_type(value); \
|
|
} while (0)
|
|
|
|
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
|
#define CELL_SIZE sizeof(uint8)
|
|
#else
|
|
#define CELL_SIZE (sizeof(uint8) * 2)
|
|
#endif
|
|
|
|
static bool
|
|
copy_stack_values(WASMModuleInstance *module, uint32 *frame_lp, uint32 arity,
|
|
#if WASM_ENABLE_GC != 0
|
|
uint8 *frame_ref,
|
|
#endif
|
|
uint32 total_cell_num, const uint8 *cells,
|
|
const int16 *src_offsets, const uint16 *dst_offsets)
|
|
{
|
|
/* To avoid the overlap issue between src offsets and dst offset,
|
|
* we use 2 steps to do the copy. First step, copy the src values
|
|
* to a tmp buf. Second step, copy the values from tmp buf to dst.
|
|
*/
|
|
bool ret = false;
|
|
uint32 buf[16] = { 0 }, i;
|
|
uint32 *tmp_buf = buf;
|
|
uint8 cell;
|
|
int16 src, buf_index = 0;
|
|
uint16 dst;
|
|
#if WASM_ENABLE_GC != 0
|
|
uint8 ref_buf[4];
|
|
uint8 *tmp_ref_buf = ref_buf;
|
|
#endif
|
|
|
|
/* Allocate memory if the buf is not large enough */
|
|
if (total_cell_num > sizeof(buf) / sizeof(uint32)) {
|
|
uint64 total_size = sizeof(uint32) * (uint64)total_cell_num;
|
|
if (total_size >= UINT32_MAX
|
|
|| !(tmp_buf = wasm_runtime_malloc((uint32)total_size))) {
|
|
wasm_set_exception(module, "allocate memory failed");
|
|
goto fail;
|
|
}
|
|
}
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
if (total_cell_num > sizeof(ref_buf) / sizeof(uint8)) {
|
|
uint64 total_size = sizeof(uint8) * (uint64)total_cell_num;
|
|
if (total_size >= UINT32_MAX
|
|
|| !(tmp_ref_buf = wasm_runtime_malloc((uint32)total_size))) {
|
|
wasm_set_exception(module, "allocate memory failed");
|
|
goto fail;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/* 1) Copy values from src to tmp buf */
|
|
for (i = 0; i < arity; i++) {
|
|
cell = cells[i * CELL_SIZE];
|
|
src = src_offsets[i];
|
|
if (cell == 1) {
|
|
tmp_buf[buf_index] = frame_lp[src];
|
|
#if WASM_ENABLE_GC != 0
|
|
tmp_ref_buf[buf_index] = frame_ref[src];
|
|
frame_ref[src] = 0;
|
|
#endif
|
|
}
|
|
else {
|
|
tmp_buf[buf_index] = frame_lp[src];
|
|
tmp_buf[buf_index + 1] = frame_lp[src + 1];
|
|
#if WASM_ENABLE_GC != 0
|
|
tmp_ref_buf[buf_index] = frame_ref[src];
|
|
tmp_ref_buf[buf_index + 1] = frame_ref[src + 1];
|
|
frame_ref[src] = 0;
|
|
frame_ref[src + 1] = 0;
|
|
#endif
|
|
}
|
|
buf_index += cell;
|
|
}
|
|
|
|
/* 2) Copy values from tmp buf to dest */
|
|
buf_index = 0;
|
|
for (i = 0; i < arity; i++) {
|
|
cell = cells[i * CELL_SIZE];
|
|
dst = dst_offsets[i];
|
|
if (cell == 1) {
|
|
frame_lp[dst] = tmp_buf[buf_index];
|
|
#if WASM_ENABLE_GC != 0
|
|
frame_ref[dst] = tmp_ref_buf[buf_index];
|
|
#endif
|
|
}
|
|
else {
|
|
frame_lp[dst] = tmp_buf[buf_index];
|
|
frame_lp[dst + 1] = tmp_buf[buf_index + 1];
|
|
#if WASM_ENABLE_GC != 0
|
|
frame_ref[dst] = tmp_ref_buf[buf_index];
|
|
frame_ref[dst + 1] = tmp_ref_buf[buf_index + 1];
|
|
#endif
|
|
}
|
|
buf_index += cell;
|
|
}
|
|
|
|
ret = true;
|
|
|
|
fail:
|
|
if (tmp_buf != buf) {
|
|
wasm_runtime_free(tmp_buf);
|
|
}
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
if (tmp_ref_buf != ref_buf) {
|
|
wasm_runtime_free(tmp_ref_buf);
|
|
}
|
|
#endif
|
|
|
|
return ret;
|
|
}
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
#define RECOVER_BR_INFO() \
|
|
do { \
|
|
uint32 arity; \
|
|
/* read arity */ \
|
|
arity = read_uint32(frame_ip); \
|
|
if (arity) { \
|
|
uint32 total_cell; \
|
|
uint16 *dst_offsets = NULL; \
|
|
uint8 *cells; \
|
|
int16 *src_offsets = NULL; \
|
|
/* read total cell num */ \
|
|
total_cell = read_uint32(frame_ip); \
|
|
/* cells */ \
|
|
cells = (uint8 *)frame_ip; \
|
|
frame_ip += arity * CELL_SIZE; \
|
|
/* src offsets */ \
|
|
src_offsets = (int16 *)frame_ip; \
|
|
frame_ip += arity * sizeof(int16); \
|
|
/* dst offsets */ \
|
|
dst_offsets = (uint16 *)frame_ip; \
|
|
frame_ip += arity * sizeof(uint16); \
|
|
if (arity == 1) { \
|
|
if (cells[0] == 1) { \
|
|
frame_lp[dst_offsets[0]] = frame_lp[src_offsets[0]]; \
|
|
/* Ignore constants because they are not reference */ \
|
|
if (src_offsets[0] >= 0) { \
|
|
CLEAR_FRAME_REF((unsigned)(src_offsets[0])); \
|
|
SET_FRAME_REF(dst_offsets[0]); \
|
|
} \
|
|
} \
|
|
else if (cells[0] == 2) { \
|
|
PUT_I64_TO_ADDR( \
|
|
frame_lp + dst_offsets[0], \
|
|
GET_I64_FROM_ADDR(frame_lp + src_offsets[0])); \
|
|
/* Ignore constants because they are not reference */ \
|
|
if (src_offsets[0] >= 0) { \
|
|
CLEAR_FRAME_REF((unsigned)src_offsets[0]); \
|
|
CLEAR_FRAME_REF((unsigned)(src_offsets[0] + 1)); \
|
|
SET_FRAME_REF((unsigned)dst_offsets[0]); \
|
|
SET_FRAME_REF((unsigned)(dst_offsets[0] + 1)); \
|
|
} \
|
|
} \
|
|
else if (cells[0] == 4) { \
|
|
PUT_V128_TO_ADDR( \
|
|
frame_lp + dst_offsets[0], \
|
|
GET_V128_FROM_ADDR(frame_lp + src_offsets[0])); \
|
|
/* Ignore constants because they are not reference */ \
|
|
if (src_offsets[0] >= 0) { \
|
|
CLEAR_FRAME_REF((unsigned)src_offsets[0]); \
|
|
CLEAR_FRAME_REF((unsigned)(src_offsets[0] + 1)); \
|
|
CLEAR_FRAME_REF((unsigned)(src_offsets[0] + 2)); \
|
|
CLEAR_FRAME_REF((unsigned)(src_offsets[0] + 3)); \
|
|
SET_FRAME_REF((unsigned)dst_offsets[0]); \
|
|
SET_FRAME_REF((unsigned)(dst_offsets[0] + 1)); \
|
|
SET_FRAME_REF((unsigned)(dst_offsets[0] + 2)); \
|
|
SET_FRAME_REF((unsigned)(dst_offsets[0] + 3)); \
|
|
} \
|
|
} \
|
|
} \
|
|
else { \
|
|
if (!copy_stack_values(module, frame_lp, arity, frame_ref, \
|
|
total_cell, cells, src_offsets, \
|
|
dst_offsets)) \
|
|
goto got_exception; \
|
|
} \
|
|
} \
|
|
frame_ip = (uint8 *)LOAD_PTR(frame_ip); \
|
|
} while (0)
|
|
#else
|
|
#define RECOVER_BR_INFO() \
|
|
do { \
|
|
uint32 arity; \
|
|
/* read arity */ \
|
|
arity = read_uint32(frame_ip); \
|
|
if (arity) { \
|
|
uint32 total_cell; \
|
|
uint16 *dst_offsets = NULL; \
|
|
uint8 *cells; \
|
|
int16 *src_offsets = NULL; \
|
|
/* read total cell num */ \
|
|
total_cell = read_uint32(frame_ip); \
|
|
/* cells */ \
|
|
cells = (uint8 *)frame_ip; \
|
|
frame_ip += arity * CELL_SIZE; \
|
|
/* src offsets */ \
|
|
src_offsets = (int16 *)frame_ip; \
|
|
frame_ip += arity * sizeof(int16); \
|
|
/* dst offsets */ \
|
|
dst_offsets = (uint16 *)frame_ip; \
|
|
frame_ip += arity * sizeof(uint16); \
|
|
if (arity == 1) { \
|
|
if (cells[0] == 1) \
|
|
frame_lp[dst_offsets[0]] = frame_lp[src_offsets[0]]; \
|
|
else if (cells[0] == 2) { \
|
|
PUT_I64_TO_ADDR( \
|
|
frame_lp + dst_offsets[0], \
|
|
GET_I64_FROM_ADDR(frame_lp + src_offsets[0])); \
|
|
} \
|
|
else if (cells[0] == 4) { \
|
|
PUT_V128_TO_ADDR( \
|
|
frame_lp + dst_offsets[0], \
|
|
GET_V128_FROM_ADDR(frame_lp + src_offsets[0])); \
|
|
} \
|
|
} \
|
|
else { \
|
|
if (!copy_stack_values(module, frame_lp, arity, total_cell, \
|
|
cells, src_offsets, dst_offsets)) \
|
|
goto got_exception; \
|
|
} \
|
|
} \
|
|
frame_ip = (uint8 *)LOAD_PTR(frame_ip); \
|
|
} while (0)
|
|
#endif
|
|
|
|
#define SKIP_BR_INFO() \
|
|
do { \
|
|
uint32 arity; \
|
|
/* read and skip arity */ \
|
|
arity = read_uint32(frame_ip); \
|
|
if (arity) { \
|
|
/* skip total cell num */ \
|
|
frame_ip += sizeof(uint32); \
|
|
/* skip cells, src offsets and dst offsets */ \
|
|
frame_ip += (CELL_SIZE + sizeof(int16) + sizeof(uint16)) * arity; \
|
|
} \
|
|
/* skip target address */ \
|
|
frame_ip += sizeof(uint8 *); \
|
|
} while (0)
|
|
|
|
static inline int32
|
|
sign_ext_8_32(int8 val)
|
|
{
|
|
if (val & 0x80)
|
|
return (int32)val | (int32)0xffffff00;
|
|
return val;
|
|
}
|
|
|
|
static inline int32
|
|
sign_ext_16_32(int16 val)
|
|
{
|
|
if (val & 0x8000)
|
|
return (int32)val | (int32)0xffff0000;
|
|
return val;
|
|
}
|
|
|
|
static inline int64
|
|
sign_ext_8_64(int8 val)
|
|
{
|
|
if (val & 0x80)
|
|
return (int64)val | (int64)0xffffffffffffff00LL;
|
|
return val;
|
|
}
|
|
|
|
static inline int64
|
|
sign_ext_16_64(int16 val)
|
|
{
|
|
if (val & 0x8000)
|
|
return (int64)val | (int64)0xffffffffffff0000LL;
|
|
return val;
|
|
}
|
|
|
|
static inline int64
|
|
sign_ext_32_64(int32 val)
|
|
{
|
|
if (val & (int32)0x80000000)
|
|
return (int64)val | (int64)0xffffffff00000000LL;
|
|
return val;
|
|
}
|
|
|
|
static inline void
|
|
word_copy(uint32 *dest, uint32 *src, unsigned num)
|
|
{
|
|
bh_assert(dest != NULL);
|
|
bh_assert(src != NULL);
|
|
bh_assert(num > 0);
|
|
if (dest != src) {
|
|
/* No overlap buffer */
|
|
bh_assert(!((src < dest) && (dest < src + num)));
|
|
for (; num > 0; num--)
|
|
*dest++ = *src++;
|
|
}
|
|
}
|
|
|
|
static inline WASMInterpFrame *
|
|
ALLOC_FRAME(WASMExecEnv *exec_env, uint32 size, WASMInterpFrame *prev_frame)
|
|
{
|
|
WASMInterpFrame *frame = wasm_exec_env_alloc_wasm_frame(exec_env, size);
|
|
|
|
if (frame) {
|
|
frame->prev_frame = prev_frame;
|
|
#if WASM_ENABLE_PERF_PROFILING != 0
|
|
frame->time_started = os_time_thread_cputime_us();
|
|
#endif
|
|
}
|
|
else {
|
|
wasm_set_exception((WASMModuleInstance *)exec_env->module_inst,
|
|
"wasm operand stack overflow");
|
|
}
|
|
|
|
return frame;
|
|
}
|
|
|
|
static inline void
|
|
FREE_FRAME(WASMExecEnv *exec_env, WASMInterpFrame *frame)
|
|
{
|
|
#if WASM_ENABLE_PERF_PROFILING != 0
|
|
if (frame->function) {
|
|
WASMInterpFrame *prev_frame = frame->prev_frame;
|
|
uint64 time_elapsed = os_time_thread_cputime_us() - frame->time_started;
|
|
|
|
frame->function->total_exec_time += time_elapsed;
|
|
frame->function->total_exec_cnt++;
|
|
|
|
/* parent function */
|
|
if (prev_frame && prev_frame->function)
|
|
prev_frame->function->children_exec_time += time_elapsed;
|
|
}
|
|
#endif
|
|
wasm_exec_env_free_wasm_frame(exec_env, frame);
|
|
}
|
|
|
|
static void
|
|
wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
|
WASMExecEnv *exec_env,
|
|
WASMFunctionInstance *cur_func,
|
|
WASMInterpFrame *prev_frame)
|
|
{
|
|
WASMFunctionImport *func_import = cur_func->u.func_import;
|
|
CApiFuncImport *c_api_func_import = NULL;
|
|
unsigned local_cell_num =
|
|
cur_func->param_cell_num > 2 ? cur_func->param_cell_num : 2;
|
|
unsigned all_cell_num;
|
|
WASMInterpFrame *frame;
|
|
uint32 argv_ret[2], cur_func_index;
|
|
void *native_func_pointer = NULL;
|
|
bool ret;
|
|
#if WASM_ENABLE_GC != 0
|
|
WASMFuncType *func_type;
|
|
uint8 *frame_ref;
|
|
#endif
|
|
|
|
all_cell_num = local_cell_num;
|
|
#if WASM_ENABLE_GC != 0
|
|
all_cell_num += (local_cell_num + 3) / 4;
|
|
#endif
|
|
|
|
if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
|
|
return;
|
|
}
|
|
|
|
if (!(frame =
|
|
ALLOC_FRAME(exec_env, wasm_interp_interp_frame_size(all_cell_num),
|
|
prev_frame)))
|
|
return;
|
|
|
|
frame->function = cur_func;
|
|
frame->ip = NULL;
|
|
frame->lp = frame->operand;
|
|
#if WASM_ENABLE_GC != 0
|
|
frame->frame_ref = (uint8 *)(frame->lp + local_cell_num);
|
|
init_frame_refs(frame->frame_ref, local_cell_num, cur_func);
|
|
#endif
|
|
|
|
wasm_exec_env_set_cur_frame(exec_env, frame);
|
|
|
|
cur_func_index = (uint32)(cur_func - module_inst->e->functions);
|
|
bh_assert(cur_func_index < module_inst->module->import_function_count);
|
|
if (!func_import->call_conv_wasm_c_api) {
|
|
native_func_pointer = module_inst->import_func_ptrs[cur_func_index];
|
|
}
|
|
else if (module_inst->c_api_func_imports) {
|
|
c_api_func_import = module_inst->c_api_func_imports + cur_func_index;
|
|
native_func_pointer = c_api_func_import->func_ptr_linked;
|
|
}
|
|
|
|
if (!native_func_pointer) {
|
|
char buf[128];
|
|
snprintf(buf, sizeof(buf),
|
|
"failed to call unlinked import function (%s, %s)",
|
|
func_import->module_name, func_import->field_name);
|
|
wasm_set_exception((WASMModuleInstance *)module_inst, buf);
|
|
return;
|
|
}
|
|
|
|
if (func_import->call_conv_wasm_c_api) {
|
|
ret = wasm_runtime_invoke_c_api_native(
|
|
(WASMModuleInstanceCommon *)module_inst, native_func_pointer,
|
|
func_import->func_type, cur_func->param_cell_num, frame->lp,
|
|
c_api_func_import->with_env_arg, c_api_func_import->env_arg);
|
|
if (ret) {
|
|
argv_ret[0] = frame->lp[0];
|
|
argv_ret[1] = frame->lp[1];
|
|
}
|
|
}
|
|
else if (!func_import->call_conv_raw) {
|
|
ret = wasm_runtime_invoke_native(
|
|
exec_env, native_func_pointer, func_import->func_type,
|
|
func_import->signature, func_import->attachment, frame->lp,
|
|
cur_func->param_cell_num, argv_ret);
|
|
}
|
|
else {
|
|
ret = wasm_runtime_invoke_native_raw(
|
|
exec_env, native_func_pointer, func_import->func_type,
|
|
func_import->signature, func_import->attachment, frame->lp,
|
|
cur_func->param_cell_num, argv_ret);
|
|
}
|
|
|
|
if (!ret)
|
|
return;
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
func_type = cur_func->u.func_import->func_type;
|
|
if (func_type->result_count
|
|
&& wasm_is_type_reftype(func_type->types[cur_func->param_count])
|
|
&& !wasm_is_reftype_i31ref(func_type->types[cur_func->param_count])) {
|
|
frame_ref = prev_frame->frame_ref + prev_frame->ret_offset;
|
|
#if UINTPTR_MAX == UINT64_MAX
|
|
*frame_ref = *(frame_ref + 1) = 1;
|
|
#else
|
|
*frame_ref = 1;
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
if (cur_func->ret_cell_num == 1) {
|
|
prev_frame->lp[prev_frame->ret_offset] = argv_ret[0];
|
|
}
|
|
else if (cur_func->ret_cell_num == 2) {
|
|
prev_frame->lp[prev_frame->ret_offset] = argv_ret[0];
|
|
prev_frame->lp[prev_frame->ret_offset + 1] = argv_ret[1];
|
|
}
|
|
|
|
FREE_FRAME(exec_env, frame);
|
|
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
|
|
}
|
|
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
static void
|
|
wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|
WASMExecEnv *exec_env,
|
|
WASMFunctionInstance *cur_func,
|
|
WASMInterpFrame *prev_frame);
|
|
|
|
static void
|
|
wasm_interp_call_func_import(WASMModuleInstance *module_inst,
|
|
WASMExecEnv *exec_env,
|
|
WASMFunctionInstance *cur_func,
|
|
WASMInterpFrame *prev_frame)
|
|
{
|
|
WASMModuleInstance *sub_module_inst = cur_func->import_module_inst;
|
|
WASMFunctionInstance *sub_func_inst = cur_func->import_func_inst;
|
|
WASMFunctionImport *func_import = cur_func->u.func_import;
|
|
uint8 *ip = prev_frame->ip;
|
|
char buf[128];
|
|
WASMExecEnv *sub_module_exec_env = NULL;
|
|
uintptr_t aux_stack_origin_boundary = 0;
|
|
uintptr_t aux_stack_origin_bottom = 0;
|
|
|
|
/*
|
|
* perform stack overflow check before calling
|
|
* wasm_interp_call_func_bytecode recursively.
|
|
*/
|
|
if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
|
|
return;
|
|
}
|
|
|
|
if (!sub_func_inst) {
|
|
snprintf(buf, sizeof(buf),
|
|
"failed to call unlinked import function (%s, %s)",
|
|
func_import->module_name, func_import->field_name);
|
|
wasm_set_exception(module_inst, buf);
|
|
return;
|
|
}
|
|
|
|
/* Switch exec_env but keep using the same one by replacing necessary
|
|
* variables */
|
|
sub_module_exec_env = wasm_runtime_get_exec_env_singleton(
|
|
(WASMModuleInstanceCommon *)sub_module_inst);
|
|
if (!sub_module_exec_env) {
|
|
wasm_set_exception(module_inst, "create singleton exec_env failed");
|
|
return;
|
|
}
|
|
|
|
/* - module_inst */
|
|
wasm_exec_env_set_module_inst(exec_env,
|
|
(WASMModuleInstanceCommon *)sub_module_inst);
|
|
/* - aux_stack_boundary */
|
|
aux_stack_origin_boundary = exec_env->aux_stack_boundary;
|
|
exec_env->aux_stack_boundary = sub_module_exec_env->aux_stack_boundary;
|
|
/* - aux_stack_bottom */
|
|
aux_stack_origin_bottom = exec_env->aux_stack_bottom;
|
|
exec_env->aux_stack_bottom = sub_module_exec_env->aux_stack_bottom;
|
|
|
|
/* set ip NULL to make call_func_bytecode return after executing
|
|
this function */
|
|
prev_frame->ip = NULL;
|
|
|
|
/* call function of sub-module*/
|
|
wasm_interp_call_func_bytecode(sub_module_inst, exec_env, sub_func_inst,
|
|
prev_frame);
|
|
|
|
/* restore ip and other replaced */
|
|
prev_frame->ip = ip;
|
|
exec_env->aux_stack_boundary = aux_stack_origin_boundary;
|
|
exec_env->aux_stack_bottom = aux_stack_origin_bottom;
|
|
wasm_exec_env_restore_module_inst(exec_env,
|
|
(WASMModuleInstanceCommon *)module_inst);
|
|
}
|
|
#endif
|
|
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
#define CHECK_SUSPEND_FLAGS() \
|
|
do { \
|
|
WASM_SUSPEND_FLAGS_LOCK(exec_env->wait_lock); \
|
|
if (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags) \
|
|
& WASM_SUSPEND_FLAG_TERMINATE) { \
|
|
/* terminate current thread */ \
|
|
WASM_SUSPEND_FLAGS_UNLOCK(exec_env->wait_lock); \
|
|
return; \
|
|
} \
|
|
/* TODO: support suspend and breakpoint */ \
|
|
WASM_SUSPEND_FLAGS_UNLOCK(exec_env->wait_lock); \
|
|
} while (0)
|
|
#endif
|
|
|
|
#if WASM_ENABLE_OPCODE_COUNTER != 0
|
|
typedef struct OpcodeInfo {
|
|
char *name;
|
|
uint64 count;
|
|
} OpcodeInfo;
|
|
|
|
/* clang-format off */
|
|
#define HANDLE_OPCODE(op) \
|
|
{ \
|
|
#op, 0 \
|
|
}
|
|
DEFINE_GOTO_TABLE(OpcodeInfo, opcode_table);
|
|
#undef HANDLE_OPCODE
|
|
/* clang-format on */
|
|
|
|
static void
|
|
wasm_interp_dump_op_count()
|
|
{
|
|
uint32 i;
|
|
uint64 total_count = 0;
|
|
for (i = 0; i < WASM_OP_IMPDEP; i++)
|
|
total_count += opcode_table[i].count;
|
|
|
|
os_printf("total opcode count: %ld\n", total_count);
|
|
for (i = 0; i < WASM_OP_IMPDEP; i++)
|
|
if (opcode_table[i].count > 0)
|
|
os_printf("\t\t%s count:\t\t%ld,\t\t%.2f%%\n", opcode_table[i].name,
|
|
opcode_table[i].count,
|
|
opcode_table[i].count * 100.0f / total_count);
|
|
}
|
|
#endif
|
|
|
|
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
|
|
|
/* #define HANDLE_OP(opcode) HANDLE_##opcode:printf(#opcode"\n"); */
|
|
#if WASM_ENABLE_OPCODE_COUNTER != 0
|
|
#define HANDLE_OP(opcode) HANDLE_##opcode : opcode_table[opcode].count++;
|
|
#else
|
|
#define HANDLE_OP(opcode) HANDLE_##opcode:
|
|
#endif
|
|
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
|
#define FETCH_OPCODE_AND_DISPATCH() \
|
|
do { \
|
|
const void *p_label_addr = *(void **)frame_ip; \
|
|
frame_ip += sizeof(void *); \
|
|
CHECK_INSTRUCTION_LIMIT(); \
|
|
goto *p_label_addr; \
|
|
} while (0)
|
|
#else
|
|
#if UINTPTR_MAX == UINT64_MAX
|
|
#define FETCH_OPCODE_AND_DISPATCH() \
|
|
do { \
|
|
const void *p_label_addr; \
|
|
bh_assert(((uintptr_t)frame_ip & 1) == 0); \
|
|
/* int32 relative offset was emitted in 64-bit target */ \
|
|
p_label_addr = label_base + (int32)LOAD_U32_WITH_2U16S(frame_ip); \
|
|
frame_ip += sizeof(int32); \
|
|
CHECK_INSTRUCTION_LIMIT(); \
|
|
goto *p_label_addr; \
|
|
} while (0)
|
|
#else
|
|
#define FETCH_OPCODE_AND_DISPATCH() \
|
|
do { \
|
|
const void *p_label_addr; \
|
|
bh_assert(((uintptr_t)frame_ip & 1) == 0); \
|
|
/* uint32 label address was emitted in 32-bit target */ \
|
|
p_label_addr = (void *)(uintptr_t)LOAD_U32_WITH_2U16S(frame_ip); \
|
|
frame_ip += sizeof(int32); \
|
|
CHECK_INSTRUCTION_LIMIT(); \
|
|
goto *p_label_addr; \
|
|
} while (0)
|
|
#endif
|
|
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
|
|
#define HANDLE_OP_END() FETCH_OPCODE_AND_DISPATCH()
|
|
|
|
#else /* else of WASM_ENABLE_LABELS_AS_VALUES */
|
|
|
|
#define HANDLE_OP(opcode) case opcode:
|
|
#define HANDLE_OP_END() continue
|
|
|
|
#endif /* end of WASM_ENABLE_LABELS_AS_VALUES */
|
|
|
|
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
|
static void **global_handle_table;
|
|
#endif
|
|
|
|
static inline uint8 *
|
|
get_global_addr(uint8 *global_data, WASMGlobalInstance *global)
|
|
{
|
|
#if WASM_ENABLE_MULTI_MODULE == 0
|
|
return global_data + global->data_offset;
|
|
#else
|
|
return global->import_global_inst
|
|
? global->import_module_inst->global_data
|
|
+ global->import_global_inst->data_offset
|
|
: global_data + global->data_offset;
|
|
#endif
|
|
}
|
|
|
|
static void
|
|
wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|
WASMExecEnv *exec_env,
|
|
WASMFunctionInstance *cur_func,
|
|
WASMInterpFrame *prev_frame)
|
|
{
|
|
WASMMemoryInstance *memory = wasm_get_default_memory(module);
|
|
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|
|
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|
|
|| WASM_ENABLE_BULK_MEMORY != 0
|
|
uint64 linear_mem_size = 0;
|
|
if (memory)
|
|
#if WASM_ENABLE_THREAD_MGR == 0
|
|
linear_mem_size = memory->memory_data_size;
|
|
#else
|
|
linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory);
|
|
#endif
|
|
#endif
|
|
WASMGlobalInstance *globals = module->e ? module->e->globals : NULL;
|
|
WASMGlobalInstance *global;
|
|
uint8 *global_data = module->global_data;
|
|
uint8 opcode_IMPDEP = WASM_OP_IMPDEP;
|
|
WASMInterpFrame *frame = NULL;
|
|
/* Points to this special opcode so as to jump to the
|
|
* call_method_from_entry. */
|
|
register uint8 *frame_ip = &opcode_IMPDEP; /* cache of frame->ip */
|
|
register uint32 *frame_lp = NULL; /* cache of frame->lp */
|
|
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
|
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 && UINTPTR_MAX == UINT64_MAX
|
|
/* cache of label base addr */
|
|
register uint8 *label_base = &&HANDLE_WASM_OP_UNREACHABLE;
|
|
#endif
|
|
#endif
|
|
#if WASM_ENABLE_GC != 0
|
|
register uint8 *frame_ref = NULL; /* cache of frame->ref */
|
|
uint32 local_cell_num = 0;
|
|
int16 opnd_off;
|
|
#endif
|
|
uint8 *frame_ip_end = frame_ip + 1;
|
|
uint32 cond, count, fidx, tidx, frame_size = 0;
|
|
uint32 all_cell_num = 0;
|
|
int16 addr1, addr2, addr_ret = 0;
|
|
int32 didx, val;
|
|
uint8 *maddr = NULL;
|
|
uint32 local_idx, local_offset, global_idx;
|
|
uint8 opcode = 0, local_type, *global_addr;
|
|
|
|
#if WASM_ENABLE_INSTRUCTION_METERING != 0
|
|
int instructions_left = -1;
|
|
if (exec_env) {
|
|
instructions_left = exec_env->instructions_to_execute;
|
|
}
|
|
#endif
|
|
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|
|
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
|
|
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
|
|
bool disable_bounds_checks = !wasm_runtime_is_bounds_checks_enabled(
|
|
(WASMModuleInstanceCommon *)module);
|
|
#else
|
|
bool disable_bounds_checks = false;
|
|
#endif
|
|
#endif
|
|
#if WASM_ENABLE_GC != 0
|
|
WASMObjectRef gc_obj;
|
|
WASMStructObjectRef struct_obj;
|
|
WASMArrayObjectRef array_obj;
|
|
WASMFuncObjectRef func_obj;
|
|
WASMI31ObjectRef i31_obj;
|
|
WASMExternrefObjectRef externref_obj;
|
|
uint32 type_idx;
|
|
#if WASM_ENABLE_STRINGREF != 0
|
|
WASMString str_obj;
|
|
WASMStringrefObjectRef stringref_obj;
|
|
WASMStringviewWTF8ObjectRef stringview_wtf8_obj;
|
|
WASMStringviewWTF16ObjectRef stringview_wtf16_obj;
|
|
WASMStringviewIterObjectRef stringview_iter_obj;
|
|
#endif
|
|
#endif
|
|
#if WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0
|
|
bool is_return_call = false;
|
|
#endif
|
|
#if WASM_ENABLE_SHARED_HEAP != 0
|
|
WASMSharedHeap *shared_heap = module->e ? module->e->shared_heap : NULL;
|
|
uint8 *shared_heap_base_addr = shared_heap ? shared_heap->base_addr : NULL;
|
|
/*
|
|
#if WASM_ENABLE_MEMORY64 != 0
|
|
uint64 shared_heap_start_off =
|
|
shared_heap ? (is_memory64 ? shared_heap->start_off_mem64
|
|
: shared_heap->start_off_mem32)
|
|
: 0;
|
|
uint64 shared_heap_end_off =
|
|
shared_heap ? (is_memory64 ? UINT64_MAX : UINT32_MAX) : 0;
|
|
#else
|
|
*/ /* TODO: uncomment the code when memory64 is enabled for fast-interp */
|
|
uint64 shared_heap_start_off =
|
|
shared_heap ? shared_heap->start_off_mem32 : 0;
|
|
uint64 shared_heap_end_off = shared_heap ? UINT32_MAX : 0;
|
|
/* #endif */
|
|
#endif /* end of WASM_ENABLE_SHARED_HEAP != 0 */
|
|
|
|
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
|
#define HANDLE_OPCODE(op) &&HANDLE_##op
|
|
DEFINE_GOTO_TABLE(const void *, handle_table);
|
|
#undef HANDLE_OPCODE
|
|
if (exec_env == NULL) {
|
|
global_handle_table = (void **)handle_table;
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
#if WASM_ENABLE_LABELS_AS_VALUES == 0
|
|
while (frame_ip < frame_ip_end) {
|
|
opcode = *frame_ip++;
|
|
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
|
|
frame_ip++;
|
|
#endif
|
|
switch (opcode) {
|
|
#else
|
|
goto *handle_table[WASM_OP_IMPDEP];
|
|
#endif
|
|
/* control instructions */
|
|
HANDLE_OP(WASM_OP_UNREACHABLE)
|
|
{
|
|
wasm_set_exception(module, "unreachable");
|
|
goto got_exception;
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_IF)
|
|
{
|
|
cond = (uint32)POP_I32();
|
|
|
|
if (cond == 0) {
|
|
uint8 *else_addr = (uint8 *)LOAD_PTR(frame_ip);
|
|
if (else_addr == NULL) {
|
|
frame_ip =
|
|
(uint8 *)LOAD_PTR(frame_ip + sizeof(uint8 *));
|
|
}
|
|
else {
|
|
frame_ip = else_addr;
|
|
}
|
|
}
|
|
else {
|
|
frame_ip += sizeof(uint8 *) * 2;
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_ELSE)
|
|
{
|
|
frame_ip = (uint8 *)LOAD_PTR(frame_ip);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_BR)
|
|
{
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
recover_br_info:
|
|
RECOVER_BR_INFO();
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_BR_IF)
|
|
{
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
cond = frame_lp[GET_OFFSET()];
|
|
|
|
if (cond)
|
|
goto recover_br_info;
|
|
else
|
|
SKIP_BR_INFO();
|
|
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_BR_TABLE)
|
|
{
|
|
uint32 arity, br_item_size;
|
|
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
count = read_uint32(frame_ip);
|
|
didx = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
|
|
if (!(didx >= 0 && (uint32)didx < count))
|
|
didx = count;
|
|
|
|
/* all br items must have the same arity and item size,
|
|
so we only calculate the first item size */
|
|
arity = LOAD_U32_WITH_2U16S(frame_ip);
|
|
br_item_size = sizeof(uint32); /* arity */
|
|
if (arity) {
|
|
/* total cell num */
|
|
br_item_size += sizeof(uint32);
|
|
/* cells, src offsets and dst offsets */
|
|
br_item_size +=
|
|
(CELL_SIZE + sizeof(int16) + sizeof(uint16)) * arity;
|
|
}
|
|
/* target address */
|
|
br_item_size += sizeof(uint8 *);
|
|
|
|
frame_ip += br_item_size * didx;
|
|
goto recover_br_info;
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_RETURN)
|
|
{
|
|
uint32 ret_idx;
|
|
WASMFuncType *func_type;
|
|
int32 off;
|
|
uint32 ret_offset;
|
|
uint8 *ret_types;
|
|
if (cur_func->is_import_func)
|
|
func_type = cur_func->u.func_import->func_type;
|
|
else
|
|
func_type = cur_func->u.func->func_type;
|
|
|
|
/* types of each return value */
|
|
ret_types = func_type->types + func_type->param_count;
|
|
ret_offset = prev_frame->ret_offset;
|
|
|
|
for (ret_idx = 0,
|
|
off = (int32)sizeof(int16) * (func_type->result_count - 1);
|
|
ret_idx < func_type->result_count;
|
|
ret_idx++, off -= (int32)sizeof(int16)) {
|
|
if (ret_types[ret_idx] == VALUE_TYPE_I64
|
|
|| ret_types[ret_idx] == VALUE_TYPE_F64) {
|
|
PUT_I64_TO_ADDR(prev_frame->lp + ret_offset,
|
|
GET_OPERAND(uint64, I64, off));
|
|
ret_offset += 2;
|
|
}
|
|
else if (ret_types[ret_idx] == VALUE_TYPE_V128) {
|
|
PUT_V128_TO_ADDR(prev_frame->lp + ret_offset,
|
|
GET_OPERAND_V128(off));
|
|
ret_offset += 4;
|
|
}
|
|
#if WASM_ENABLE_GC != 0
|
|
else if (wasm_is_type_reftype(ret_types[ret_idx])) {
|
|
PUT_REF_TO_ADDR(prev_frame->lp + ret_offset,
|
|
GET_OPERAND(void *, REF, off));
|
|
if (!wasm_is_reftype_i31ref(ret_types[ret_idx])) {
|
|
*(prev_frame->frame_ref + ret_offset) = 1;
|
|
#if UINTPTR_MAX == UINT64_MAX
|
|
*(prev_frame->frame_ref + ret_offset + 1) = 1;
|
|
#endif
|
|
}
|
|
ret_offset += REF_CELL_NUM;
|
|
}
|
|
#endif
|
|
else {
|
|
prev_frame->lp[ret_offset] =
|
|
GET_OPERAND(uint32, I32, off);
|
|
ret_offset++;
|
|
}
|
|
}
|
|
goto return_func;
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_CALL_INDIRECT)
|
|
#if WASM_ENABLE_TAIL_CALL != 0
|
|
HANDLE_OP(WASM_OP_RETURN_CALL_INDIRECT)
|
|
#endif
|
|
{
|
|
WASMFuncType *cur_type, *cur_func_type;
|
|
WASMTableInstance *tbl_inst;
|
|
uint32 tbl_idx;
|
|
|
|
#if WASM_ENABLE_TAIL_CALL != 0
|
|
GET_OPCODE();
|
|
#endif
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
|
|
tidx = read_uint32(frame_ip);
|
|
cur_type = (WASMFuncType *)module->module->types[tidx];
|
|
|
|
tbl_idx = read_uint32(frame_ip);
|
|
bh_assert(tbl_idx < module->table_count);
|
|
|
|
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
|
|
|
val = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
|
|
if ((uint32)val >= tbl_inst->cur_size) {
|
|
wasm_set_exception(module, "undefined element");
|
|
goto got_exception;
|
|
}
|
|
|
|
/* clang-format off */
|
|
#if WASM_ENABLE_GC == 0
|
|
fidx = (uint32)tbl_inst->elems[val];
|
|
if (fidx == (uint32)-1) {
|
|
wasm_set_exception(module, "uninitialized element");
|
|
goto got_exception;
|
|
}
|
|
#else
|
|
func_obj = (WASMFuncObjectRef)tbl_inst->elems[val];
|
|
if (!func_obj) {
|
|
wasm_set_exception(module, "uninitialized element");
|
|
goto got_exception;
|
|
}
|
|
fidx = wasm_func_obj_get_func_idx_bound(func_obj);
|
|
#endif
|
|
/* clang-format on */
|
|
|
|
/*
|
|
* we might be using a table injected by host or
|
|
* another module. in that case, we don't validate
|
|
* the elem value while loading
|
|
*/
|
|
if (fidx >= module->e->function_count) {
|
|
wasm_set_exception(module, "unknown function");
|
|
goto got_exception;
|
|
}
|
|
|
|
/* always call module own functions */
|
|
cur_func = module->e->functions + fidx;
|
|
|
|
if (cur_func->is_import_func)
|
|
cur_func_type = cur_func->u.func_import->func_type;
|
|
else
|
|
cur_func_type = cur_func->u.func->func_type;
|
|
|
|
/* clang-format off */
|
|
#if WASM_ENABLE_GC == 0
|
|
if (cur_type != cur_func_type) {
|
|
wasm_set_exception(module, "indirect call type mismatch");
|
|
goto got_exception;
|
|
}
|
|
#else
|
|
if (!wasm_func_type_is_super_of(cur_type, cur_func_type)) {
|
|
wasm_set_exception(module, "indirect call type mismatch");
|
|
goto got_exception;
|
|
}
|
|
#endif
|
|
/* clang-format on */
|
|
|
|
#if WASM_ENABLE_TAIL_CALL != 0
|
|
if (opcode == WASM_OP_RETURN_CALL_INDIRECT)
|
|
goto call_func_from_return_call;
|
|
#endif
|
|
goto call_func_from_interp;
|
|
}
|
|
|
|
#if WASM_ENABLE_EXCE_HANDLING != 0
|
|
HANDLE_OP(WASM_OP_TRY)
|
|
HANDLE_OP(WASM_OP_CATCH)
|
|
HANDLE_OP(WASM_OP_THROW)
|
|
HANDLE_OP(WASM_OP_RETHROW)
|
|
HANDLE_OP(WASM_OP_DELEGATE)
|
|
HANDLE_OP(WASM_OP_CATCH_ALL)
|
|
HANDLE_OP(EXT_OP_TRY)
|
|
{
|
|
wasm_set_exception(module, "unsupported opcode");
|
|
goto got_exception;
|
|
}
|
|
#endif
|
|
|
|
/* parametric instructions */
|
|
HANDLE_OP(WASM_OP_SELECT)
|
|
{
|
|
cond = frame_lp[GET_OFFSET()];
|
|
addr1 = GET_OFFSET();
|
|
addr2 = GET_OFFSET();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
if (!cond) {
|
|
if (addr_ret != addr1)
|
|
frame_lp[addr_ret] = frame_lp[addr1];
|
|
}
|
|
else {
|
|
if (addr_ret != addr2)
|
|
frame_lp[addr_ret] = frame_lp[addr2];
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_SELECT_64)
|
|
{
|
|
cond = frame_lp[GET_OFFSET()];
|
|
addr1 = GET_OFFSET();
|
|
addr2 = GET_OFFSET();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
if (!cond) {
|
|
if (addr_ret != addr1)
|
|
PUT_I64_TO_ADDR(frame_lp + addr_ret,
|
|
GET_I64_FROM_ADDR(frame_lp + addr1));
|
|
}
|
|
else {
|
|
if (addr_ret != addr2)
|
|
PUT_I64_TO_ADDR(frame_lp + addr_ret,
|
|
GET_I64_FROM_ADDR(frame_lp + addr2));
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
#if WASM_ENABLE_SIMD != 0
|
|
HANDLE_OP(WASM_OP_SELECT_128)
|
|
{
|
|
cond = frame_lp[GET_OFFSET()];
|
|
addr1 = GET_OFFSET();
|
|
addr2 = GET_OFFSET();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
if (!cond) {
|
|
if (addr_ret != addr1)
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret,
|
|
GET_V128_FROM_ADDR(frame_lp + addr1));
|
|
}
|
|
else {
|
|
if (addr_ret != addr2)
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret,
|
|
GET_V128_FROM_ADDR(frame_lp + addr2));
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
#endif
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
HANDLE_OP(WASM_OP_SELECT_T)
|
|
{
|
|
cond = frame_lp[GET_OFFSET()];
|
|
addr1 = GET_OFFSET();
|
|
addr2 = GET_OFFSET();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
if (!cond) {
|
|
if (addr_ret != addr1)
|
|
PUT_REF_TO_ADDR(frame_lp + addr_ret,
|
|
GET_REF_FROM_ADDR(frame_lp + addr1));
|
|
}
|
|
else {
|
|
if (addr_ret != addr2)
|
|
PUT_REF_TO_ADDR(frame_lp + addr_ret,
|
|
GET_REF_FROM_ADDR(frame_lp + addr2));
|
|
}
|
|
{
|
|
uint8 orig_ref = 0;
|
|
/* Ignore constants because they are not reference */
|
|
if (addr1 >= 0) {
|
|
orig_ref = *FRAME_REF(addr1);
|
|
CLEAR_FRAME_REF(addr1);
|
|
}
|
|
if (addr2 >= 0) {
|
|
CLEAR_FRAME_REF(addr2);
|
|
}
|
|
if (orig_ref) {
|
|
SET_FRAME_REF(addr_ret);
|
|
}
|
|
}
|
|
|
|
HANDLE_OP_END();
|
|
}
|
|
#endif
|
|
|
|
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
|
|
HANDLE_OP(WASM_OP_TABLE_GET)
|
|
{
|
|
uint32 tbl_idx, elem_idx;
|
|
WASMTableInstance *tbl_inst;
|
|
|
|
tbl_idx = read_uint32(frame_ip);
|
|
bh_assert(tbl_idx < module->table_count);
|
|
|
|
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
|
|
|
elem_idx = POP_I32();
|
|
if (elem_idx >= tbl_inst->cur_size) {
|
|
wasm_set_exception(module, "out of bounds table access");
|
|
goto got_exception;
|
|
}
|
|
|
|
#if WASM_ENABLE_GC == 0
|
|
PUSH_I32(tbl_inst->elems[elem_idx]);
|
|
#else
|
|
PUSH_REF(tbl_inst->elems[elem_idx]);
|
|
#endif
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_TABLE_SET)
|
|
{
|
|
uint32 tbl_idx, elem_idx;
|
|
WASMTableInstance *tbl_inst;
|
|
table_elem_type_t elem_val;
|
|
|
|
tbl_idx = read_uint32(frame_ip);
|
|
bh_assert(tbl_idx < module->table_count);
|
|
|
|
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
|
|
|
#if WASM_ENABLE_GC == 0
|
|
elem_val = POP_I32();
|
|
#else
|
|
elem_val = POP_REF();
|
|
#endif
|
|
elem_idx = POP_I32();
|
|
if (elem_idx >= tbl_inst->cur_size) {
|
|
wasm_set_exception(module, "out of bounds table access");
|
|
goto got_exception;
|
|
}
|
|
|
|
tbl_inst->elems[elem_idx] = elem_val;
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_REF_NULL)
|
|
{
|
|
#if WASM_ENABLE_GC == 0
|
|
PUSH_I32(NULL_REF);
|
|
#else
|
|
PUSH_REF(NULL_REF);
|
|
#endif
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_REF_IS_NULL)
|
|
{
|
|
#if WASM_ENABLE_GC == 0
|
|
uint32 ref_val;
|
|
ref_val = POP_I32();
|
|
#else
|
|
void *ref_val;
|
|
ref_val = POP_REF();
|
|
#endif
|
|
PUSH_I32(ref_val == NULL_REF ? 1 : 0);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_REF_FUNC)
|
|
{
|
|
uint32 func_idx = read_uint32(frame_ip);
|
|
|
|
#if WASM_ENABLE_GC == 0
|
|
PUSH_I32(func_idx);
|
|
#else
|
|
SYNC_ALL_TO_FRAME();
|
|
if (!(gc_obj = wasm_create_func_obj(module, func_idx, true,
|
|
NULL, 0))) {
|
|
goto got_exception;
|
|
}
|
|
PUSH_REF(gc_obj);
|
|
#endif
|
|
HANDLE_OP_END();
|
|
}
|
|
#endif /* end of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
HANDLE_OP(WASM_OP_CALL_REF)
|
|
{
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
func_obj = POP_REF();
|
|
if (!func_obj) {
|
|
wasm_set_exception(module, "null function reference");
|
|
goto got_exception;
|
|
}
|
|
|
|
fidx = wasm_func_obj_get_func_idx_bound(func_obj);
|
|
cur_func = module->e->functions + fidx;
|
|
goto call_func_from_interp;
|
|
}
|
|
HANDLE_OP(WASM_OP_RETURN_CALL_REF)
|
|
{
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
func_obj = POP_REF();
|
|
if (!func_obj) {
|
|
wasm_set_exception(module, "null function reference");
|
|
goto got_exception;
|
|
}
|
|
|
|
fidx = wasm_func_obj_get_func_idx_bound(func_obj);
|
|
cur_func = module->e->functions + fidx;
|
|
goto call_func_from_return_call;
|
|
}
|
|
HANDLE_OP(WASM_OP_REF_AS_NON_NULL)
|
|
{
|
|
gc_obj = POP_REF();
|
|
if (gc_obj == NULL_REF) {
|
|
wasm_set_exception(module, "null reference");
|
|
goto got_exception;
|
|
}
|
|
PUSH_REF(gc_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
HANDLE_OP(WASM_OP_REF_EQ)
|
|
{
|
|
WASMObjectRef gc_obj1, gc_obj2;
|
|
gc_obj2 = POP_REF();
|
|
gc_obj1 = POP_REF();
|
|
val = wasm_obj_equal(gc_obj1, gc_obj2);
|
|
PUSH_I32(val);
|
|
HANDLE_OP_END();
|
|
}
|
|
HANDLE_OP(WASM_OP_BR_ON_NULL)
|
|
{
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
opnd_off = GET_OFFSET();
|
|
gc_obj = GET_REF_FROM_ADDR(frame_lp + opnd_off);
|
|
if (gc_obj == NULL_REF) {
|
|
CLEAR_FRAME_REF(opnd_off);
|
|
goto recover_br_info;
|
|
}
|
|
else {
|
|
SKIP_BR_INFO();
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
HANDLE_OP(WASM_OP_BR_ON_NON_NULL)
|
|
{
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
opnd_off = GET_OFFSET();
|
|
gc_obj = GET_REF_FROM_ADDR(frame_lp + opnd_off);
|
|
if (gc_obj != NULL_REF) {
|
|
goto recover_br_info;
|
|
}
|
|
else {
|
|
CLEAR_FRAME_REF(opnd_off);
|
|
SKIP_BR_INFO();
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_GC_PREFIX)
|
|
{
|
|
GET_OPCODE();
|
|
|
|
switch (opcode) {
|
|
case WASM_OP_STRUCT_NEW:
|
|
case WASM_OP_STRUCT_NEW_DEFAULT:
|
|
{
|
|
WASMModule *wasm_module = module->module;
|
|
WASMStructType *struct_type;
|
|
WASMRttType *rtt_type;
|
|
WASMValue field_value = { 0 };
|
|
|
|
type_idx = read_uint32(frame_ip);
|
|
struct_type =
|
|
(WASMStructType *)module->module->types[type_idx];
|
|
|
|
if (!(rtt_type = wasm_rtt_type_new(
|
|
(WASMType *)struct_type, type_idx,
|
|
wasm_module->rtt_types,
|
|
wasm_module->type_count,
|
|
&wasm_module->rtt_type_lock))) {
|
|
wasm_set_exception(module,
|
|
"create rtt type failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
struct_obj = wasm_struct_obj_new(exec_env, rtt_type);
|
|
if (!struct_obj) {
|
|
wasm_set_exception(module,
|
|
"create struct object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
if (opcode == WASM_OP_STRUCT_NEW) {
|
|
WASMStructFieldType *fields = struct_type->fields;
|
|
int32 field_count = (int32)struct_type->field_count;
|
|
int32 field_idx;
|
|
uint8 field_type;
|
|
|
|
for (field_idx = field_count - 1; field_idx >= 0;
|
|
field_idx--) {
|
|
field_type = fields[field_idx].field_type;
|
|
if (wasm_is_type_reftype(field_type)) {
|
|
field_value.gc_obj = POP_REF();
|
|
}
|
|
else if (field_type == VALUE_TYPE_I32
|
|
|| field_type == VALUE_TYPE_F32
|
|
|| field_type == PACKED_TYPE_I8
|
|
|| field_type == PACKED_TYPE_I16) {
|
|
field_value.i32 = POP_I32();
|
|
}
|
|
else {
|
|
field_value.i64 = POP_I64();
|
|
}
|
|
wasm_struct_obj_set_field(struct_obj, field_idx,
|
|
&field_value);
|
|
}
|
|
}
|
|
PUSH_REF(struct_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRUCT_GET:
|
|
case WASM_OP_STRUCT_GET_S:
|
|
case WASM_OP_STRUCT_GET_U:
|
|
{
|
|
WASMStructType *struct_type;
|
|
WASMValue field_value = { 0 };
|
|
uint32 field_idx;
|
|
uint8 field_type;
|
|
|
|
type_idx = read_uint32(frame_ip);
|
|
field_idx = read_uint32(frame_ip);
|
|
|
|
struct_type =
|
|
(WASMStructType *)module->module->types[type_idx];
|
|
|
|
struct_obj = POP_REF();
|
|
|
|
if (!struct_obj) {
|
|
wasm_set_exception(module,
|
|
"null structure reference");
|
|
goto got_exception;
|
|
}
|
|
|
|
wasm_struct_obj_get_field(
|
|
struct_obj, field_idx,
|
|
opcode == WASM_OP_STRUCT_GET_S ? true : false,
|
|
&field_value);
|
|
|
|
field_type = struct_type->fields[field_idx].field_type;
|
|
if (wasm_is_reftype_i31ref(field_type)) {
|
|
PUSH_I31REF(field_value.gc_obj);
|
|
}
|
|
else if (wasm_is_type_reftype(field_type)) {
|
|
PUSH_REF(field_value.gc_obj);
|
|
}
|
|
else if (field_type == VALUE_TYPE_I32
|
|
|| field_type == VALUE_TYPE_F32
|
|
|| field_type == PACKED_TYPE_I8
|
|
|| field_type == PACKED_TYPE_I16) {
|
|
PUSH_I32(field_value.i32);
|
|
}
|
|
else {
|
|
PUSH_I64(field_value.i64);
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRUCT_SET:
|
|
{
|
|
WASMStructType *struct_type;
|
|
WASMValue field_value = { 0 };
|
|
uint32 field_idx;
|
|
uint8 field_type;
|
|
|
|
type_idx = read_uint32(frame_ip);
|
|
field_idx = read_uint32(frame_ip);
|
|
|
|
struct_type =
|
|
(WASMStructType *)module->module->types[type_idx];
|
|
field_type = struct_type->fields[field_idx].field_type;
|
|
|
|
if (wasm_is_type_reftype(field_type)) {
|
|
field_value.gc_obj = POP_REF();
|
|
}
|
|
else if (field_type == VALUE_TYPE_I32
|
|
|| field_type == VALUE_TYPE_F32
|
|
|| field_type == PACKED_TYPE_I8
|
|
|| field_type == PACKED_TYPE_I16) {
|
|
field_value.i32 = POP_I32();
|
|
}
|
|
else {
|
|
field_value.i64 = POP_I64();
|
|
}
|
|
|
|
struct_obj = POP_REF();
|
|
if (!struct_obj) {
|
|
wasm_set_exception(module,
|
|
"null structure reference");
|
|
goto got_exception;
|
|
}
|
|
|
|
wasm_struct_obj_set_field(struct_obj, field_idx,
|
|
&field_value);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_ARRAY_NEW:
|
|
case WASM_OP_ARRAY_NEW_DEFAULT:
|
|
case WASM_OP_ARRAY_NEW_FIXED:
|
|
{
|
|
WASMModule *wasm_module = module->module;
|
|
WASMArrayType *array_type;
|
|
WASMRttType *rtt_type;
|
|
WASMValue array_elem = { 0 };
|
|
uint32 array_len, i;
|
|
|
|
type_idx = read_uint32(frame_ip);
|
|
array_type =
|
|
(WASMArrayType *)wasm_module->types[type_idx];
|
|
|
|
if (!(rtt_type = wasm_rtt_type_new(
|
|
(WASMType *)array_type, type_idx,
|
|
wasm_module->rtt_types,
|
|
wasm_module->type_count,
|
|
&wasm_module->rtt_type_lock))) {
|
|
wasm_set_exception(module,
|
|
"create rtt type failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
if (opcode != WASM_OP_ARRAY_NEW_FIXED)
|
|
array_len = POP_I32();
|
|
else
|
|
array_len = read_uint32(frame_ip);
|
|
|
|
if (opcode == WASM_OP_ARRAY_NEW) {
|
|
if (wasm_is_type_reftype(array_type->elem_type)) {
|
|
array_elem.gc_obj = POP_REF();
|
|
}
|
|
else if (array_type->elem_type == VALUE_TYPE_I32
|
|
|| array_type->elem_type == VALUE_TYPE_F32
|
|
|| array_type->elem_type == PACKED_TYPE_I8
|
|
|| array_type->elem_type
|
|
== PACKED_TYPE_I16) {
|
|
array_elem.i32 = POP_I32();
|
|
}
|
|
else {
|
|
array_elem.i64 = POP_I64();
|
|
}
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
array_obj = wasm_array_obj_new(exec_env, rtt_type,
|
|
array_len, &array_elem);
|
|
if (!array_obj) {
|
|
wasm_set_exception(module,
|
|
"create array object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
if (opcode == WASM_OP_ARRAY_NEW_FIXED) {
|
|
for (i = 0; i < array_len; i++) {
|
|
if (wasm_is_type_reftype(
|
|
array_type->elem_type)) {
|
|
array_elem.gc_obj = POP_REF();
|
|
}
|
|
else if (array_type->elem_type == VALUE_TYPE_I32
|
|
|| array_type->elem_type
|
|
== VALUE_TYPE_F32
|
|
|| array_type->elem_type
|
|
== PACKED_TYPE_I8
|
|
|| array_type->elem_type
|
|
== PACKED_TYPE_I16) {
|
|
array_elem.i32 = POP_I32();
|
|
}
|
|
else {
|
|
array_elem.i64 = POP_I64();
|
|
}
|
|
wasm_array_obj_set_elem(
|
|
array_obj, array_len - 1 - i, &array_elem);
|
|
}
|
|
}
|
|
|
|
PUSH_REF(array_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_ARRAY_NEW_DATA:
|
|
{
|
|
WASMModule *wasm_module = module->module;
|
|
WASMArrayType *array_type;
|
|
WASMRttType *rtt_type;
|
|
WASMValue array_elem = { 0 };
|
|
WASMDataSeg *data_seg;
|
|
uint8 *array_elem_base;
|
|
uint32 array_len, data_seg_idx, data_seg_offset;
|
|
uint32 elem_size = 0;
|
|
uint64 total_size;
|
|
|
|
type_idx = read_uint32(frame_ip);
|
|
data_seg_idx = read_uint32(frame_ip);
|
|
data_seg = wasm_module->data_segments[data_seg_idx];
|
|
|
|
array_type =
|
|
(WASMArrayType *)wasm_module->types[type_idx];
|
|
|
|
if (!(rtt_type = wasm_rtt_type_new(
|
|
(WASMType *)array_type, type_idx,
|
|
wasm_module->rtt_types,
|
|
wasm_module->type_count,
|
|
&wasm_module->rtt_type_lock))) {
|
|
wasm_set_exception(module,
|
|
"create rtt type failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
array_len = POP_I32();
|
|
data_seg_offset = POP_I32();
|
|
|
|
switch (array_type->elem_type) {
|
|
case PACKED_TYPE_I8:
|
|
elem_size = 1;
|
|
break;
|
|
case PACKED_TYPE_I16:
|
|
elem_size = 2;
|
|
break;
|
|
case VALUE_TYPE_I32:
|
|
case VALUE_TYPE_F32:
|
|
elem_size = 4;
|
|
break;
|
|
case VALUE_TYPE_I64:
|
|
case VALUE_TYPE_F64:
|
|
elem_size = 8;
|
|
break;
|
|
default:
|
|
bh_assert(0);
|
|
}
|
|
|
|
total_size = (uint64)elem_size * array_len;
|
|
if (data_seg_offset >= data_seg->data_length
|
|
|| total_size
|
|
> data_seg->data_length - data_seg_offset) {
|
|
wasm_set_exception(module,
|
|
"data segment out of bounds");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
array_obj = wasm_array_obj_new(exec_env, rtt_type,
|
|
array_len, &array_elem);
|
|
if (!array_obj) {
|
|
wasm_set_exception(module,
|
|
"create array object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
array_elem_base =
|
|
(uint8 *)wasm_array_obj_first_elem_addr(array_obj);
|
|
bh_memcpy_s(array_elem_base, (uint32)total_size,
|
|
data_seg->data + data_seg_offset,
|
|
(uint32)total_size);
|
|
|
|
PUSH_REF(array_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_ARRAY_NEW_ELEM:
|
|
{
|
|
/* TODO */
|
|
wasm_set_exception(module, "unsupported opcode");
|
|
goto got_exception;
|
|
}
|
|
case WASM_OP_ARRAY_GET:
|
|
case WASM_OP_ARRAY_GET_S:
|
|
case WASM_OP_ARRAY_GET_U:
|
|
{
|
|
WASMArrayType *array_type;
|
|
WASMValue array_elem = { 0 };
|
|
uint32 elem_idx, elem_size_log;
|
|
|
|
type_idx = read_uint32(frame_ip);
|
|
array_type =
|
|
(WASMArrayType *)module->module->types[type_idx];
|
|
|
|
elem_idx = POP_I32();
|
|
array_obj = POP_REF();
|
|
|
|
if (!array_obj) {
|
|
wasm_set_exception(module, "null array reference");
|
|
goto got_exception;
|
|
}
|
|
if (elem_idx >= wasm_array_obj_length(array_obj)) {
|
|
wasm_set_exception(module,
|
|
"out of bounds array access");
|
|
goto got_exception;
|
|
}
|
|
|
|
wasm_array_obj_get_elem(
|
|
array_obj, elem_idx,
|
|
opcode == WASM_OP_ARRAY_GET_S ? true : false,
|
|
&array_elem);
|
|
elem_size_log = wasm_array_obj_elem_size_log(array_obj);
|
|
|
|
if (wasm_is_reftype_i31ref(array_type->elem_type)) {
|
|
PUSH_I31REF(array_elem.gc_obj);
|
|
}
|
|
else if (wasm_is_type_reftype(array_type->elem_type)) {
|
|
PUSH_REF(array_elem.gc_obj);
|
|
}
|
|
else if (elem_size_log < 3) {
|
|
PUSH_I32(array_elem.i32);
|
|
}
|
|
else {
|
|
PUSH_I64(array_elem.i64);
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_ARRAY_SET:
|
|
{
|
|
WASMArrayType *array_type;
|
|
WASMValue array_elem = { 0 };
|
|
uint32 elem_idx;
|
|
|
|
type_idx = read_uint32(frame_ip);
|
|
array_type =
|
|
(WASMArrayType *)module->module->types[type_idx];
|
|
if (wasm_is_type_reftype(array_type->elem_type)) {
|
|
array_elem.gc_obj = POP_REF();
|
|
}
|
|
else if (array_type->elem_type == VALUE_TYPE_I32
|
|
|| array_type->elem_type == VALUE_TYPE_F32
|
|
|| array_type->elem_type == PACKED_TYPE_I8
|
|
|| array_type->elem_type == PACKED_TYPE_I16) {
|
|
array_elem.i32 = POP_I32();
|
|
}
|
|
else {
|
|
array_elem.i64 = POP_I64();
|
|
}
|
|
|
|
elem_idx = POP_I32();
|
|
array_obj = POP_REF();
|
|
|
|
if (!array_obj) {
|
|
wasm_set_exception(module, "null array reference");
|
|
goto got_exception;
|
|
}
|
|
if (elem_idx >= wasm_array_obj_length(array_obj)) {
|
|
wasm_set_exception(module,
|
|
"out of bounds array access");
|
|
goto got_exception;
|
|
}
|
|
|
|
wasm_array_obj_set_elem(array_obj, elem_idx,
|
|
&array_elem);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_ARRAY_LEN:
|
|
{
|
|
uint32 array_len;
|
|
array_obj = POP_REF();
|
|
if (!array_obj) {
|
|
wasm_set_exception(module, "null array reference");
|
|
goto got_exception;
|
|
}
|
|
array_len = wasm_array_obj_length(array_obj);
|
|
PUSH_I32(array_len);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_ARRAY_FILL:
|
|
{
|
|
WASMArrayType *array_type;
|
|
WASMValue fill_value = { 0 };
|
|
uint32 start_offset, len;
|
|
|
|
type_idx = read_uint32(frame_ip);
|
|
|
|
array_type =
|
|
(WASMArrayType *)module->module->types[type_idx];
|
|
|
|
len = POP_I32();
|
|
if (wasm_is_type_reftype(array_type->elem_type)) {
|
|
fill_value.gc_obj = POP_REF();
|
|
}
|
|
else if (array_type->elem_type == VALUE_TYPE_I32
|
|
|| array_type->elem_type == VALUE_TYPE_F32
|
|
|| array_type->elem_type == PACKED_TYPE_I8
|
|
|| array_type->elem_type == PACKED_TYPE_I16) {
|
|
fill_value.i32 = POP_I32();
|
|
}
|
|
else {
|
|
fill_value.i64 = POP_I64();
|
|
}
|
|
start_offset = POP_I32();
|
|
array_obj = POP_REF();
|
|
|
|
if (!array_obj) {
|
|
wasm_set_exception(module, "null array reference");
|
|
goto got_exception;
|
|
}
|
|
|
|
if (len > 0) {
|
|
if ((uint64)start_offset + len
|
|
>= wasm_array_obj_length(array_obj)) {
|
|
wasm_set_exception(
|
|
module, "out of bounds array access");
|
|
goto got_exception;
|
|
}
|
|
|
|
wasm_array_obj_fill(array_obj, start_offset, len,
|
|
&fill_value);
|
|
}
|
|
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_ARRAY_COPY:
|
|
{
|
|
uint32 dst_offset, src_offset, len, src_type_index;
|
|
WASMArrayObjectRef src_obj, dst_obj;
|
|
|
|
type_idx = read_uint32(frame_ip);
|
|
src_type_index = read_uint32(frame_ip);
|
|
|
|
len = POP_I32();
|
|
src_offset = POP_I32();
|
|
src_obj = POP_REF();
|
|
dst_offset = POP_I32();
|
|
dst_obj = POP_REF();
|
|
|
|
if (!src_obj || !dst_obj) {
|
|
wasm_set_exception(module, "null array reference");
|
|
goto got_exception;
|
|
}
|
|
|
|
if (len > 0) {
|
|
if ((dst_offset > UINT32_MAX - len)
|
|
|| (dst_offset + len
|
|
> wasm_array_obj_length(dst_obj))
|
|
|| (src_offset > UINT32_MAX - len)
|
|
|| (src_offset + len
|
|
> wasm_array_obj_length(src_obj))) {
|
|
wasm_set_exception(
|
|
module, "out of bounds array access");
|
|
goto got_exception;
|
|
}
|
|
|
|
wasm_array_obj_copy(dst_obj, dst_offset, src_obj,
|
|
src_offset, len);
|
|
}
|
|
|
|
(void)src_type_index;
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
case WASM_OP_REF_I31:
|
|
{
|
|
uint32 i31_val;
|
|
|
|
i31_val = POP_I32();
|
|
i31_obj = wasm_i31_obj_new(i31_val);
|
|
PUSH_I31REF(i31_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_I31_GET_S:
|
|
case WASM_OP_I31_GET_U:
|
|
{
|
|
uint32 i31_val;
|
|
|
|
i31_obj = (WASMI31ObjectRef)POP_REF();
|
|
if (!i31_obj) {
|
|
wasm_set_exception(module, "null i31 reference");
|
|
goto got_exception;
|
|
}
|
|
i31_val = (uint32)(((uintptr_t)i31_obj) >> 1);
|
|
if (opcode == WASM_OP_I31_GET_S
|
|
&& (i31_val & 0x40000000) /* bit 30 is 1 */)
|
|
/* set bit 31 to 1 */
|
|
i31_val |= 0x80000000;
|
|
PUSH_I32(i31_val);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
case WASM_OP_REF_TEST:
|
|
case WASM_OP_REF_CAST:
|
|
case WASM_OP_REF_TEST_NULLABLE:
|
|
case WASM_OP_REF_CAST_NULLABLE:
|
|
{
|
|
int32 heap_type;
|
|
|
|
heap_type = (int32)read_uint32(frame_ip);
|
|
|
|
gc_obj = POP_REF();
|
|
if (!gc_obj) {
|
|
if (opcode == WASM_OP_REF_TEST
|
|
|| opcode == WASM_OP_REF_TEST_NULLABLE) {
|
|
if (opcode == WASM_OP_REF_TEST)
|
|
PUSH_I32(0);
|
|
else
|
|
PUSH_I32(1);
|
|
}
|
|
else if (opcode == WASM_OP_REF_CAST) {
|
|
wasm_set_exception(module, "cast failure");
|
|
goto got_exception;
|
|
}
|
|
else {
|
|
PUSH_REF(gc_obj);
|
|
}
|
|
}
|
|
else {
|
|
bool castable = false;
|
|
|
|
if (heap_type >= 0) {
|
|
WASMModule *wasm_module = module->module;
|
|
castable = wasm_obj_is_instance_of(
|
|
gc_obj, (uint32)heap_type,
|
|
wasm_module->types,
|
|
wasm_module->type_count);
|
|
}
|
|
else {
|
|
castable =
|
|
wasm_obj_is_type_of(gc_obj, heap_type);
|
|
}
|
|
|
|
if (opcode == WASM_OP_REF_TEST
|
|
|| opcode == WASM_OP_REF_TEST_NULLABLE) {
|
|
if (castable)
|
|
PUSH_I32(1);
|
|
else
|
|
PUSH_I32(0);
|
|
}
|
|
else if (!castable) {
|
|
wasm_set_exception(module, "cast failure");
|
|
goto got_exception;
|
|
}
|
|
else {
|
|
PUSH_REF(gc_obj);
|
|
}
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
case WASM_OP_BR_ON_CAST:
|
|
case WASM_OP_BR_ON_CAST_FAIL:
|
|
{
|
|
int32 heap_type, heap_type_dst;
|
|
uint8 castflags;
|
|
uint16 opnd_off_br;
|
|
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
castflags = *frame_ip++;
|
|
heap_type = (int32)read_uint32(frame_ip);
|
|
heap_type_dst = (int32)read_uint32(frame_ip);
|
|
|
|
opnd_off = GET_OFFSET();
|
|
opnd_off_br = GET_OFFSET();
|
|
gc_obj = GET_REF_FROM_ADDR(frame_lp + opnd_off);
|
|
PUT_REF_TO_ADDR(frame_lp + opnd_off_br, gc_obj);
|
|
|
|
if (!gc_obj) {
|
|
/*
|
|
* castflags should be 0~3:
|
|
* 0: (non-null, non-null)
|
|
* 1: (null, non-null)
|
|
* 2: (non-null, null)
|
|
* 3: (null, null)
|
|
*/
|
|
if (
|
|
/* op is BR_ON_CAST and dst reftype is nullable
|
|
*/
|
|
((opcode == WASM_OP_BR_ON_CAST)
|
|
&& ((castflags == 2) || (castflags == 3)))
|
|
/* op is BR_ON_CAST_FAIL and dst reftype is
|
|
non-nullable */
|
|
|| ((opcode == WASM_OP_BR_ON_CAST_FAIL)
|
|
&& ((castflags == 0)
|
|
|| (castflags == 1)))) {
|
|
CLEAR_FRAME_REF(opnd_off);
|
|
if (!wasm_is_reftype_i31ref(heap_type)) {
|
|
SET_FRAME_REF(opnd_off_br);
|
|
}
|
|
goto recover_br_info;
|
|
}
|
|
}
|
|
else {
|
|
bool castable = false;
|
|
|
|
if (heap_type_dst >= 0) {
|
|
WASMModule *wasm_module = module->module;
|
|
castable = wasm_obj_is_instance_of(
|
|
gc_obj, (uint32)heap_type_dst,
|
|
wasm_module->types,
|
|
wasm_module->type_count);
|
|
}
|
|
else {
|
|
castable =
|
|
wasm_obj_is_type_of(gc_obj, heap_type_dst);
|
|
}
|
|
|
|
if ((castable && (opcode == WASM_OP_BR_ON_CAST))
|
|
|| (!castable
|
|
&& (opcode == WASM_OP_BR_ON_CAST_FAIL))) {
|
|
CLEAR_FRAME_REF(opnd_off);
|
|
if (!wasm_is_reftype_i31ref(heap_type)) {
|
|
SET_FRAME_REF(opnd_off_br);
|
|
}
|
|
goto recover_br_info;
|
|
}
|
|
}
|
|
SKIP_BR_INFO();
|
|
|
|
(void)heap_type_dst;
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
case WASM_OP_ANY_CONVERT_EXTERN:
|
|
{
|
|
externref_obj = POP_REF();
|
|
if (externref_obj == NULL_REF)
|
|
PUSH_REF(NULL_REF);
|
|
else {
|
|
gc_obj = wasm_externref_obj_to_internal_obj(
|
|
externref_obj);
|
|
PUSH_REF(gc_obj);
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_EXTERN_CONVERT_ANY:
|
|
{
|
|
gc_obj = POP_REF();
|
|
if (gc_obj == NULL_REF)
|
|
PUSH_REF(NULL_REF);
|
|
else {
|
|
if (!(externref_obj =
|
|
wasm_internal_obj_to_externref_obj(
|
|
exec_env, gc_obj))) {
|
|
wasm_set_exception(
|
|
module, "create externref object failed");
|
|
goto got_exception;
|
|
}
|
|
PUSH_REF(externref_obj);
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
#if WASM_ENABLE_STRINGREF != 0
|
|
case WASM_OP_STRING_NEW_UTF8:
|
|
case WASM_OP_STRING_NEW_WTF16:
|
|
case WASM_OP_STRING_NEW_LOSSY_UTF8:
|
|
case WASM_OP_STRING_NEW_WTF8:
|
|
{
|
|
uint32 mem_idx, addr, bytes_length, offset = 0;
|
|
EncodingFlag flag = WTF8;
|
|
|
|
mem_idx = (uint32)read_uint32(frame_ip);
|
|
bytes_length = POP_I32();
|
|
addr = POP_I32();
|
|
|
|
CHECK_MEMORY_OVERFLOW(bytes_length);
|
|
|
|
if (opcode == WASM_OP_STRING_NEW_WTF16) {
|
|
flag = WTF16;
|
|
}
|
|
else if (opcode == WASM_OP_STRING_NEW_UTF8) {
|
|
flag = UTF8;
|
|
}
|
|
else if (opcode == WASM_OP_STRING_NEW_LOSSY_UTF8) {
|
|
flag = LOSSY_UTF8;
|
|
}
|
|
else if (opcode == WASM_OP_STRING_NEW_WTF8) {
|
|
flag = WTF8;
|
|
}
|
|
|
|
str_obj = wasm_string_new_with_encoding(
|
|
maddr, bytes_length, flag);
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create string object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
stringref_obj =
|
|
wasm_stringref_obj_new(exec_env, str_obj);
|
|
if (!stringref_obj) {
|
|
wasm_set_exception(module,
|
|
"create stringref failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_REF(stringref_obj);
|
|
|
|
(void)mem_idx;
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_CONST:
|
|
{
|
|
WASMModule *wasm_module = module->module;
|
|
uint32 contents;
|
|
|
|
contents = (uint32)read_uint32(frame_ip);
|
|
|
|
str_obj = wasm_string_new_const(
|
|
(const char *)
|
|
wasm_module->string_literal_ptrs[contents],
|
|
wasm_module->string_literal_lengths[contents]);
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create string object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
stringref_obj =
|
|
wasm_stringref_obj_new(exec_env, str_obj);
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create stringref failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_REF(stringref_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_MEASURE_UTF8:
|
|
case WASM_OP_STRING_MEASURE_WTF8:
|
|
case WASM_OP_STRING_MEASURE_WTF16:
|
|
{
|
|
int32 target_bytes_length;
|
|
EncodingFlag flag = WTF8;
|
|
|
|
stringref_obj = POP_REF();
|
|
|
|
if (opcode == WASM_OP_STRING_MEASURE_WTF16) {
|
|
flag = WTF16;
|
|
}
|
|
else if (opcode == WASM_OP_STRING_MEASURE_UTF8) {
|
|
flag = UTF8;
|
|
}
|
|
else if (opcode == WASM_OP_STRING_MEASURE_WTF8) {
|
|
flag = LOSSY_UTF8;
|
|
}
|
|
target_bytes_length = wasm_string_measure(
|
|
(WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj),
|
|
flag);
|
|
|
|
PUSH_I32(target_bytes_length);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_ENCODE_UTF8:
|
|
case WASM_OP_STRING_ENCODE_WTF16:
|
|
case WASM_OP_STRING_ENCODE_LOSSY_UTF8:
|
|
case WASM_OP_STRING_ENCODE_WTF8:
|
|
{
|
|
uint32 mem_idx, addr;
|
|
int32 target_bytes_length;
|
|
WASMMemoryInstance *memory_inst;
|
|
EncodingFlag flag = WTF8;
|
|
|
|
mem_idx = (uint32)read_uint32(frame_ip);
|
|
addr = POP_I32();
|
|
stringref_obj = POP_REF();
|
|
|
|
str_obj = (WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj);
|
|
|
|
#if WASM_ENABLE_SHARED_HEAP != 0
|
|
if (app_addr_in_shared_heap((uint64)addr, 1))
|
|
shared_heap_addr_app_to_native((uint64)addr, maddr);
|
|
else
|
|
#endif
|
|
{
|
|
memory_inst = module->memories[mem_idx];
|
|
maddr = memory_inst->memory_data + addr;
|
|
}
|
|
|
|
if (opcode == WASM_OP_STRING_ENCODE_WTF16) {
|
|
flag = WTF16;
|
|
count = wasm_string_measure(str_obj, flag);
|
|
target_bytes_length = wasm_string_encode(
|
|
str_obj, 0, count, maddr, NULL, flag);
|
|
}
|
|
else {
|
|
if (opcode == WASM_OP_STRING_ENCODE_UTF8) {
|
|
flag = UTF8;
|
|
}
|
|
else if (opcode
|
|
== WASM_OP_STRING_ENCODE_LOSSY_UTF8) {
|
|
flag = LOSSY_UTF8;
|
|
}
|
|
else if (opcode == WASM_OP_STRING_ENCODE_WTF8) {
|
|
flag = WTF8;
|
|
}
|
|
count = wasm_string_measure(str_obj, flag);
|
|
target_bytes_length = wasm_string_encode(
|
|
str_obj, 0, count, maddr, NULL, flag);
|
|
|
|
if (target_bytes_length == -1) {
|
|
wasm_set_exception(
|
|
module, "isolated surrogate is seen");
|
|
goto got_exception;
|
|
}
|
|
}
|
|
if (target_bytes_length < 0) {
|
|
wasm_set_exception(module,
|
|
"stringref encode failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_I32(target_bytes_length);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_CONCAT:
|
|
{
|
|
WASMStringrefObjectRef stringref_obj1, stringref_obj2;
|
|
|
|
stringref_obj2 = POP_REF();
|
|
stringref_obj1 = POP_REF();
|
|
|
|
str_obj = wasm_string_concat(
|
|
(WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj1),
|
|
(WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj2));
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create string object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
stringref_obj =
|
|
wasm_stringref_obj_new(exec_env, str_obj);
|
|
if (!stringref_obj) {
|
|
wasm_set_exception(module,
|
|
"create stringref failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_REF(stringref_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_EQ:
|
|
{
|
|
WASMStringrefObjectRef stringref_obj1, stringref_obj2;
|
|
int32 is_eq;
|
|
|
|
stringref_obj2 = POP_REF();
|
|
stringref_obj1 = POP_REF();
|
|
|
|
is_eq = wasm_string_eq(
|
|
(WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj1),
|
|
(WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj2));
|
|
|
|
PUSH_I32(is_eq);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_IS_USV_SEQUENCE:
|
|
{
|
|
int32 is_usv_sequence;
|
|
|
|
stringref_obj = POP_REF();
|
|
|
|
is_usv_sequence = wasm_string_is_usv_sequence(
|
|
(WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj));
|
|
|
|
PUSH_I32(is_usv_sequence);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_AS_WTF8:
|
|
{
|
|
stringref_obj = POP_REF();
|
|
|
|
str_obj = wasm_string_create_view(
|
|
(WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj),
|
|
STRING_VIEW_WTF8);
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create string object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
stringview_wtf8_obj =
|
|
wasm_stringview_wtf8_obj_new(exec_env, str_obj);
|
|
if (!stringview_wtf8_obj) {
|
|
wasm_set_exception(module,
|
|
"create stringview wtf8 failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_REF(stringview_wtf8_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRINGVIEW_WTF8_ADVANCE:
|
|
{
|
|
uint32 next_pos, bytes, pos;
|
|
|
|
bytes = POP_I32();
|
|
pos = POP_I32();
|
|
stringview_wtf8_obj = POP_REF();
|
|
|
|
next_pos = wasm_string_advance(
|
|
(WASMString)wasm_stringview_wtf8_obj_get_value(
|
|
stringview_wtf8_obj),
|
|
pos, bytes, NULL);
|
|
|
|
PUSH_I32(next_pos);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRINGVIEW_WTF8_ENCODE_UTF8:
|
|
case WASM_OP_STRINGVIEW_WTF8_ENCODE_LOSSY_UTF8:
|
|
case WASM_OP_STRINGVIEW_WTF8_ENCODE_WTF8:
|
|
{
|
|
uint32 mem_idx, addr, pos, bytes, next_pos;
|
|
int32 bytes_written;
|
|
WASMMemoryInstance *memory_inst;
|
|
EncodingFlag flag = WTF8;
|
|
|
|
if (opcode == WASM_OP_STRINGVIEW_WTF8_ENCODE_UTF8) {
|
|
flag = UTF8;
|
|
}
|
|
else if (opcode
|
|
== WASM_OP_STRINGVIEW_WTF8_ENCODE_LOSSY_UTF8) {
|
|
flag = LOSSY_UTF8;
|
|
}
|
|
else if (opcode
|
|
== WASM_OP_STRINGVIEW_WTF8_ENCODE_WTF8) {
|
|
flag = WTF8;
|
|
}
|
|
|
|
mem_idx = (uint32)read_uint32(frame_ip);
|
|
bytes = POP_I32();
|
|
pos = POP_I32();
|
|
addr = POP_I32();
|
|
stringview_wtf8_obj = POP_REF();
|
|
|
|
#if WASM_ENABLE_SHARED_HEAP != 0
|
|
if (app_addr_in_shared_heap((uint64)addr, 1))
|
|
shared_heap_addr_app_to_native((uint64)addr, maddr);
|
|
else
|
|
#endif
|
|
{
|
|
memory_inst = module->memories[mem_idx];
|
|
maddr = memory_inst->memory_data + addr;
|
|
}
|
|
|
|
bytes_written = wasm_string_encode(
|
|
(WASMString)wasm_stringview_wtf8_obj_get_value(
|
|
stringview_wtf8_obj),
|
|
pos, bytes, maddr, &next_pos, flag);
|
|
|
|
if (bytes_written < 0) {
|
|
if (bytes_written == Isolated_Surrogate) {
|
|
wasm_set_exception(
|
|
module, "isolated surrogate is seen");
|
|
}
|
|
else {
|
|
wasm_set_exception(module, "encode failed");
|
|
}
|
|
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_I32(next_pos);
|
|
PUSH_I32(bytes_written);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRINGVIEW_WTF8_SLICE:
|
|
{
|
|
uint32 start, end;
|
|
|
|
end = POP_I32();
|
|
start = POP_I32();
|
|
stringview_wtf8_obj = POP_REF();
|
|
|
|
str_obj = wasm_string_slice(
|
|
(WASMString)wasm_stringview_wtf8_obj_get_value(
|
|
stringview_wtf8_obj),
|
|
start, end, STRING_VIEW_WTF8);
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create string object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
stringref_obj =
|
|
wasm_stringref_obj_new(exec_env, str_obj);
|
|
if (!stringref_obj) {
|
|
wasm_set_exception(module,
|
|
"create stringref failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_REF(stringref_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_AS_WTF16:
|
|
{
|
|
stringref_obj = POP_REF();
|
|
|
|
str_obj = wasm_string_create_view(
|
|
(WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj),
|
|
STRING_VIEW_WTF16);
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create string object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
stringview_wtf16_obj =
|
|
wasm_stringview_wtf16_obj_new(exec_env, str_obj);
|
|
if (!stringview_wtf16_obj) {
|
|
wasm_set_exception(
|
|
module, "create stringview wtf16 failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_REF(stringview_wtf16_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRINGVIEW_WTF16_LENGTH:
|
|
{
|
|
int32 code_units_length;
|
|
|
|
stringview_wtf16_obj = POP_REF();
|
|
|
|
code_units_length = wasm_string_wtf16_get_length(
|
|
(WASMString)wasm_stringview_wtf16_obj_get_value(
|
|
stringview_wtf16_obj));
|
|
|
|
PUSH_I32(code_units_length);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRINGVIEW_WTF16_GET_CODEUNIT:
|
|
{
|
|
int32 pos;
|
|
uint32 code_unit;
|
|
|
|
pos = POP_I32();
|
|
stringview_wtf16_obj = POP_REF();
|
|
|
|
code_unit = (uint32)wasm_string_get_wtf16_codeunit(
|
|
(WASMString)wasm_stringview_wtf16_obj_get_value(
|
|
stringview_wtf16_obj),
|
|
pos);
|
|
|
|
PUSH_I32(code_unit);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRINGVIEW_WTF16_ENCODE:
|
|
{
|
|
uint32 mem_idx, addr, pos, len, offset = 0;
|
|
int32 written_code_units = 0;
|
|
|
|
mem_idx = (uint32)read_uint32(frame_ip);
|
|
len = POP_I32();
|
|
pos = POP_I32();
|
|
addr = POP_I32();
|
|
stringview_wtf16_obj = POP_REF();
|
|
|
|
CHECK_MEMORY_OVERFLOW(len * sizeof(uint16));
|
|
|
|
/* check 2-byte alignment */
|
|
if (((uintptr_t)maddr & (((uintptr_t)1 << 2) - 1))
|
|
!= 0) {
|
|
wasm_set_exception(module,
|
|
"unaligned memory access");
|
|
goto got_exception;
|
|
}
|
|
|
|
written_code_units = wasm_string_encode(
|
|
(WASMString)wasm_stringview_wtf16_obj_get_value(
|
|
stringview_wtf16_obj),
|
|
pos, len, maddr, NULL, WTF16);
|
|
|
|
PUSH_I32(written_code_units);
|
|
(void)mem_idx;
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRINGVIEW_WTF16_SLICE:
|
|
{
|
|
uint32 start, end;
|
|
|
|
end = POP_I32();
|
|
start = POP_I32();
|
|
stringview_wtf16_obj = POP_REF();
|
|
|
|
str_obj = wasm_string_slice(
|
|
(WASMString)wasm_stringview_wtf16_obj_get_value(
|
|
stringview_wtf16_obj),
|
|
start, end, STRING_VIEW_WTF16);
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create string object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
stringref_obj =
|
|
wasm_stringref_obj_new(exec_env, str_obj);
|
|
if (!stringref_obj) {
|
|
wasm_set_exception(module,
|
|
"create stringref failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_REF(stringref_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_AS_ITER:
|
|
{
|
|
stringref_obj = POP_REF();
|
|
|
|
str_obj = wasm_string_create_view(
|
|
(WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj),
|
|
STRING_VIEW_ITER);
|
|
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create string object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
stringview_iter_obj =
|
|
wasm_stringview_iter_obj_new(exec_env, str_obj, 0);
|
|
if (!stringview_iter_obj) {
|
|
wasm_set_exception(module,
|
|
"create stringview iter failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_REF(stringview_iter_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRINGVIEW_ITER_NEXT:
|
|
{
|
|
uint32 code_point;
|
|
|
|
stringview_iter_obj = POP_REF();
|
|
|
|
code_point = wasm_string_next_codepoint(
|
|
(WASMString)wasm_stringview_iter_obj_get_value(
|
|
stringview_iter_obj),
|
|
wasm_stringview_iter_obj_get_pos(
|
|
stringview_iter_obj));
|
|
|
|
PUSH_I32(code_point);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRINGVIEW_ITER_ADVANCE:
|
|
case WASM_OP_STRINGVIEW_ITER_REWIND:
|
|
{
|
|
uint32 code_points_count, code_points_consumed = 0,
|
|
cur_pos, next_pos = 0;
|
|
|
|
code_points_count = POP_I32();
|
|
stringview_iter_obj = POP_REF();
|
|
|
|
str_obj =
|
|
(WASMString)wasm_stringview_iter_obj_get_value(
|
|
stringview_iter_obj);
|
|
cur_pos = wasm_stringview_iter_obj_get_pos(
|
|
stringview_iter_obj);
|
|
|
|
if (opcode == WASM_OP_STRINGVIEW_ITER_ADVANCE) {
|
|
next_pos = wasm_string_advance(
|
|
str_obj, cur_pos, code_points_count,
|
|
&code_points_consumed);
|
|
}
|
|
else if (opcode == WASM_OP_STRINGVIEW_ITER_REWIND) {
|
|
next_pos = wasm_string_rewind(
|
|
str_obj, cur_pos, code_points_count,
|
|
&code_points_consumed);
|
|
}
|
|
|
|
wasm_stringview_iter_obj_update_pos(stringview_iter_obj,
|
|
next_pos);
|
|
|
|
PUSH_I32(code_points_consumed);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRINGVIEW_ITER_SLICE:
|
|
{
|
|
uint32 code_points_count, cur_pos;
|
|
|
|
code_points_count = POP_I32();
|
|
stringview_iter_obj = POP_REF();
|
|
|
|
cur_pos = wasm_stringview_iter_obj_get_pos(
|
|
stringview_iter_obj);
|
|
|
|
str_obj = wasm_string_slice(
|
|
(WASMString)wasm_stringview_iter_obj_get_value(
|
|
stringview_iter_obj),
|
|
cur_pos, cur_pos + code_points_count,
|
|
STRING_VIEW_ITER);
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create string object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
stringref_obj =
|
|
wasm_stringref_obj_new(exec_env, str_obj);
|
|
if (!stringref_obj) {
|
|
wasm_set_exception(module,
|
|
"create stringref failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_REF(stringref_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_NEW_UTF8_ARRAY:
|
|
case WASM_OP_STRING_NEW_WTF16_ARRAY:
|
|
case WASM_OP_STRING_NEW_LOSSY_UTF8_ARRAY:
|
|
case WASM_OP_STRING_NEW_WTF8_ARRAY:
|
|
{
|
|
uint32 start, end, array_len;
|
|
EncodingFlag flag = WTF8;
|
|
WASMArrayType *array_type;
|
|
void *arr_start_addr;
|
|
|
|
end = POP_I32();
|
|
start = POP_I32();
|
|
array_obj = POP_REF();
|
|
|
|
array_type = (WASMArrayType *)wasm_obj_get_defined_type(
|
|
(WASMObjectRef)array_obj);
|
|
arr_start_addr =
|
|
wasm_array_obj_elem_addr(array_obj, start);
|
|
array_len = wasm_array_obj_length(array_obj);
|
|
|
|
if (start > end || end > array_len) {
|
|
wasm_set_exception(module,
|
|
"out of bounds array access");
|
|
goto got_exception;
|
|
}
|
|
|
|
if (opcode == WASM_OP_STRING_NEW_WTF16_ARRAY) {
|
|
if (array_type->elem_type != VALUE_TYPE_I16) {
|
|
wasm_set_exception(module,
|
|
"array type mismatch");
|
|
goto got_exception;
|
|
}
|
|
flag = WTF16;
|
|
}
|
|
else {
|
|
if (array_type->elem_type != VALUE_TYPE_I8) {
|
|
wasm_set_exception(module,
|
|
"array type mismatch");
|
|
goto got_exception;
|
|
}
|
|
if (opcode == WASM_OP_STRING_NEW_UTF8_ARRAY) {
|
|
flag = UTF8;
|
|
}
|
|
else if (opcode == WASM_OP_STRING_NEW_WTF8_ARRAY) {
|
|
flag = WTF8;
|
|
}
|
|
else if (opcode
|
|
== WASM_OP_STRING_NEW_LOSSY_UTF8_ARRAY) {
|
|
flag = LOSSY_UTF8;
|
|
}
|
|
}
|
|
|
|
str_obj = wasm_string_new_with_encoding(
|
|
arr_start_addr, (end - start), flag);
|
|
if (!str_obj) {
|
|
wasm_set_exception(module,
|
|
"create string object failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
SYNC_ALL_TO_FRAME();
|
|
stringref_obj =
|
|
wasm_stringref_obj_new(exec_env, str_obj);
|
|
if (!stringref_obj) {
|
|
wasm_set_exception(module,
|
|
"create stringref failed");
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_REF(stringref_obj);
|
|
HANDLE_OP_END();
|
|
}
|
|
case WASM_OP_STRING_ENCODE_UTF8_ARRAY:
|
|
case WASM_OP_STRING_ENCODE_WTF16_ARRAY:
|
|
case WASM_OP_STRING_ENCODE_LOSSY_UTF8_ARRAY:
|
|
case WASM_OP_STRING_ENCODE_WTF8_ARRAY:
|
|
{
|
|
uint32 start, array_len, count;
|
|
int32 bytes_written;
|
|
EncodingFlag flag = WTF8;
|
|
WASMArrayType *array_type;
|
|
void *arr_start_addr;
|
|
|
|
start = POP_I32();
|
|
array_obj = POP_REF();
|
|
stringref_obj = POP_REF();
|
|
|
|
str_obj = (WASMString)wasm_stringref_obj_get_value(
|
|
stringref_obj);
|
|
|
|
array_type = (WASMArrayType *)wasm_obj_get_defined_type(
|
|
(WASMObjectRef)array_obj);
|
|
arr_start_addr =
|
|
wasm_array_obj_elem_addr(array_obj, start);
|
|
array_len = wasm_array_obj_length(array_obj);
|
|
|
|
if (start > array_len) {
|
|
wasm_set_exception(module,
|
|
"out of bounds array access");
|
|
goto got_exception;
|
|
}
|
|
|
|
if (opcode == WASM_OP_STRING_ENCODE_WTF16_ARRAY) {
|
|
if (array_type->elem_type != VALUE_TYPE_I16) {
|
|
wasm_set_exception(module,
|
|
"array type mismatch");
|
|
goto got_exception;
|
|
}
|
|
flag = WTF16;
|
|
}
|
|
else {
|
|
if (array_type->elem_type != VALUE_TYPE_I8) {
|
|
wasm_set_exception(module,
|
|
"array type mismatch");
|
|
goto got_exception;
|
|
}
|
|
if (opcode == WASM_OP_STRING_ENCODE_UTF8_ARRAY) {
|
|
flag = UTF8;
|
|
}
|
|
else if (opcode
|
|
== WASM_OP_STRING_ENCODE_WTF8_ARRAY) {
|
|
flag = WTF8;
|
|
}
|
|
else if (
|
|
opcode
|
|
== WASM_OP_STRING_ENCODE_LOSSY_UTF8_ARRAY) {
|
|
flag = LOSSY_UTF8;
|
|
}
|
|
}
|
|
|
|
count = wasm_string_measure(str_obj, flag);
|
|
|
|
bytes_written = wasm_string_encode(
|
|
str_obj, 0, count, arr_start_addr, NULL, flag);
|
|
|
|
if (bytes_written < 0) {
|
|
if (bytes_written == Isolated_Surrogate) {
|
|
wasm_set_exception(
|
|
module, "isolated surrogate is seen");
|
|
}
|
|
else if (bytes_written == Insufficient_Space) {
|
|
wasm_set_exception(
|
|
module, "array space is insufficient");
|
|
}
|
|
else {
|
|
wasm_set_exception(module, "encode failed");
|
|
}
|
|
|
|
goto got_exception;
|
|
}
|
|
|
|
PUSH_I32(bytes_written);
|
|
HANDLE_OP_END();
|
|
}
|
|
#endif /* end of WASM_ENABLE_STRINGREF != 0 */
|
|
|
|
default:
|
|
{
|
|
wasm_set_exception(module, "unsupported opcode");
|
|
goto got_exception;
|
|
}
|
|
}
|
|
}
|
|
#endif /* end of WASM_ENABLE_GC != 0 */
|
|
|
|
/* variable instructions */
|
|
HANDLE_OP(EXT_OP_SET_LOCAL_FAST)
|
|
HANDLE_OP(EXT_OP_TEE_LOCAL_FAST)
|
|
{
|
|
/* clang-format off */
|
|
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
|
local_offset = *frame_ip++;
|
|
#else
|
|
local_offset = *frame_ip;
|
|
frame_ip += 2;
|
|
#endif
|
|
/* clang-format on */
|
|
*(uint32 *)(frame_lp + local_offset) =
|
|
GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(EXT_OP_SET_LOCAL_FAST_I64)
|
|
HANDLE_OP(EXT_OP_TEE_LOCAL_FAST_I64)
|
|
{
|
|
/* clang-format off */
|
|
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
|
local_offset = *frame_ip++;
|
|
#else
|
|
local_offset = *frame_ip;
|
|
frame_ip += 2;
|
|
#endif
|
|
/* clang-format on */
|
|
PUT_I64_TO_ADDR((uint32 *)(frame_lp + local_offset),
|
|
GET_OPERAND(uint64, I64, 0));
|
|
frame_ip += 2;
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
#if WASM_ENABLE_SIMDE != 0
|
|
HANDLE_OP(EXT_OP_SET_LOCAL_FAST_V128)
|
|
HANDLE_OP(EXT_OP_TEE_LOCAL_FAST_V128)
|
|
{
|
|
/* clang-format off */
|
|
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
|
local_offset = *frame_ip++;
|
|
#else
|
|
local_offset = *frame_ip;
|
|
frame_ip += 2;
|
|
#endif
|
|
/* clang-format on */
|
|
PUT_V128_TO_ADDR((uint32 *)(frame_lp + local_offset),
|
|
GET_OPERAND_V128(0));
|
|
frame_ip += 2;
|
|
HANDLE_OP_END();
|
|
}
|
|
#endif
|
|
HANDLE_OP(WASM_OP_GET_GLOBAL)
|
|
{
|
|
global_idx = read_uint32(frame_ip);
|
|
bh_assert(global_idx < module->e->global_count);
|
|
global = globals + global_idx;
|
|
global_addr = get_global_addr(global_data, global);
|
|
addr_ret = GET_OFFSET();
|
|
/* clang-format off */
|
|
#if WASM_ENABLE_GC == 0
|
|
frame_lp[addr_ret] = *(uint32 *)global_addr;
|
|
#else
|
|
if (!wasm_is_type_reftype(global->type))
|
|
frame_lp[addr_ret] = *(uint32 *)global_addr;
|
|
else {
|
|
PUT_REF_TO_ADDR(frame_lp + addr_ret,
|
|
GET_REF_FROM_ADDR((uint32 *)global_addr));
|
|
if (!wasm_is_reftype_i31ref(global->type)) {
|
|
SET_FRAME_REF(addr_ret);
|
|
}
|
|
}
|
|
#endif
|
|
/* clang-format on */
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_GET_GLOBAL_64)
|
|
{
|
|
global_idx = read_uint32(frame_ip);
|
|
bh_assert(global_idx < module->e->global_count);
|
|
global = globals + global_idx;
|
|
global_addr = get_global_addr(global_data, global);
|
|
addr_ret = GET_OFFSET();
|
|
PUT_I64_TO_ADDR(frame_lp + addr_ret,
|
|
GET_I64_FROM_ADDR((uint32 *)global_addr));
|
|
HANDLE_OP_END();
|
|
}
|
|
#if WASM_ENABLE_SIMDE != 0
|
|
HANDLE_OP(WASM_OP_GET_GLOBAL_V128)
|
|
{
|
|
global_idx = read_uint32(frame_ip);
|
|
bh_assert(global_idx < module->e->global_count);
|
|
global = globals + global_idx;
|
|
global_addr = get_global_addr(global_data, global);
|
|
addr_ret = GET_OFFSET();
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret,
|
|
GET_V128_FROM_ADDR((uint32 *)global_addr));
|
|
HANDLE_OP_END();
|
|
}
|
|
#endif
|
|
HANDLE_OP(WASM_OP_SET_GLOBAL)
|
|
{
|
|
global_idx = read_uint32(frame_ip);
|
|
bh_assert(global_idx < module->e->global_count);
|
|
global = globals + global_idx;
|
|
global_addr = get_global_addr(global_data, global);
|
|
addr1 = GET_OFFSET();
|
|
/* clang-format off */
|
|
#if WASM_ENABLE_GC == 0
|
|
*(int32 *)global_addr = frame_lp[addr1];
|
|
#else
|
|
if (!wasm_is_type_reftype(global->type))
|
|
*(int32 *)global_addr = frame_lp[addr1];
|
|
else {
|
|
PUT_REF_TO_ADDR((uint32 *)global_addr,
|
|
GET_REF_FROM_ADDR(frame_lp + addr1));
|
|
CLEAR_FRAME_REF(addr1);
|
|
}
|
|
#endif
|
|
/* clang-format on */
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_SET_GLOBAL_AUX_STACK)
|
|
{
|
|
uint64 aux_stack_top;
|
|
|
|
global_idx = read_uint32(frame_ip);
|
|
bh_assert(global_idx < module->e->global_count);
|
|
global = globals + global_idx;
|
|
global_addr = get_global_addr(global_data, global);
|
|
/* TODO: Memory64 the data type depends on mem idx type */
|
|
aux_stack_top = (uint64)frame_lp[GET_OFFSET()];
|
|
if (aux_stack_top <= (uint64)exec_env->aux_stack_boundary) {
|
|
wasm_set_exception(module, "wasm auxiliary stack overflow");
|
|
goto got_exception;
|
|
}
|
|
if (aux_stack_top > (uint64)exec_env->aux_stack_bottom) {
|
|
wasm_set_exception(module,
|
|
"wasm auxiliary stack underflow");
|
|
goto got_exception;
|
|
}
|
|
*(int32 *)global_addr = (uint32)aux_stack_top;
|
|
#if WASM_ENABLE_MEMORY_PROFILING != 0
|
|
if (module->module->aux_stack_top_global_index != (uint32)-1) {
|
|
uint32 aux_stack_used =
|
|
(uint32)(module->module->aux_stack_bottom
|
|
- *(uint32 *)global_addr);
|
|
if (aux_stack_used > module->e->max_aux_stack_used)
|
|
module->e->max_aux_stack_used = aux_stack_used;
|
|
}
|
|
#endif
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_SET_GLOBAL_64)
|
|
{
|
|
global_idx = read_uint32(frame_ip);
|
|
bh_assert(global_idx < module->e->global_count);
|
|
global = globals + global_idx;
|
|
global_addr = get_global_addr(global_data, global);
|
|
addr1 = GET_OFFSET();
|
|
PUT_I64_TO_ADDR((uint32 *)global_addr,
|
|
GET_I64_FROM_ADDR(frame_lp + addr1));
|
|
HANDLE_OP_END();
|
|
}
|
|
#if WASM_ENABLE_SIMDE != 0
|
|
HANDLE_OP(WASM_OP_SET_GLOBAL_V128)
|
|
{
|
|
global_idx = read_uint32(frame_ip);
|
|
bh_assert(global_idx < module->e->global_count);
|
|
global = globals + global_idx;
|
|
global_addr = get_global_addr(global_data, global);
|
|
addr1 = GET_OFFSET();
|
|
PUT_V128_TO_ADDR((uint32 *)global_addr,
|
|
GET_V128_FROM_ADDR(frame_lp + addr1));
|
|
HANDLE_OP_END();
|
|
}
|
|
#endif
|
|
|
|
/* memory load instructions */
|
|
HANDLE_OP(WASM_OP_I32_LOAD)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
frame_lp[addr_ret] = LOAD_I32(maddr);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LOAD)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(8);
|
|
PUT_I64_TO_ADDR(frame_lp + addr_ret, LOAD_I64(maddr));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_LOAD8_S)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
frame_lp[addr_ret] = sign_ext_8_32(*(int8 *)maddr);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_LOAD8_U)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
frame_lp[addr_ret] = (uint32)(*(uint8 *)(maddr));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_LOAD16_S)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
frame_lp[addr_ret] = sign_ext_16_32(LOAD_I16(maddr));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_LOAD16_U)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
frame_lp[addr_ret] = (uint32)(LOAD_U16(maddr));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LOAD8_S)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
PUT_I64_TO_ADDR(frame_lp + addr_ret,
|
|
sign_ext_8_64(*(int8 *)maddr));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LOAD8_U)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
PUT_I64_TO_ADDR(frame_lp + addr_ret, (uint64)(*(uint8 *)maddr));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LOAD16_S)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
PUT_I64_TO_ADDR(frame_lp + addr_ret,
|
|
sign_ext_16_64(LOAD_I16(maddr)));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LOAD16_U)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
PUT_I64_TO_ADDR(frame_lp + addr_ret, (uint64)(LOAD_U16(maddr)));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LOAD32_S)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
PUT_I64_TO_ADDR(frame_lp + addr_ret,
|
|
sign_ext_32_64(LOAD_I32(maddr)));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LOAD32_U)
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = GET_OPERAND(uint32, I32, 0);
|
|
frame_ip += 2;
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
PUT_I64_TO_ADDR(frame_lp + addr_ret, (uint64)(LOAD_U32(maddr)));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_STORE)
|
|
{
|
|
uint32 offset, addr;
|
|
uint32 sval;
|
|
offset = read_uint32(frame_ip);
|
|
sval = GET_OPERAND(uint32, I32, 0);
|
|
addr = GET_OPERAND(uint32, I32, 2);
|
|
frame_ip += 4;
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
STORE_U32(maddr, sval);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_STORE8)
|
|
{
|
|
uint32 offset, addr;
|
|
uint32 sval;
|
|
offset = read_uint32(frame_ip);
|
|
sval = GET_OPERAND(uint32, I32, 0);
|
|
addr = GET_OPERAND(uint32, I32, 2);
|
|
frame_ip += 4;
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
STORE_U8(maddr, (uint8_t)sval);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_STORE16)
|
|
{
|
|
uint32 offset, addr;
|
|
uint32 sval;
|
|
offset = read_uint32(frame_ip);
|
|
sval = GET_OPERAND(uint32, I32, 0);
|
|
addr = GET_OPERAND(uint32, I32, 2);
|
|
frame_ip += 4;
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
STORE_U16(maddr, (uint16)sval);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_STORE)
|
|
{
|
|
uint32 offset, addr;
|
|
uint64 sval;
|
|
offset = read_uint32(frame_ip);
|
|
sval = GET_OPERAND(uint64, I64, 0);
|
|
addr = GET_OPERAND(uint32, I32, 2);
|
|
frame_ip += 4;
|
|
CHECK_MEMORY_OVERFLOW(8);
|
|
STORE_I64(maddr, sval);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_STORE8)
|
|
{
|
|
uint32 offset, addr;
|
|
uint64 sval;
|
|
offset = read_uint32(frame_ip);
|
|
sval = GET_OPERAND(uint64, I64, 0);
|
|
addr = GET_OPERAND(uint32, I32, 2);
|
|
frame_ip += 4;
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
*(uint8 *)maddr = (uint8)sval;
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_STORE16)
|
|
{
|
|
uint32 offset, addr;
|
|
uint64 sval;
|
|
offset = read_uint32(frame_ip);
|
|
sval = GET_OPERAND(uint64, I64, 0);
|
|
addr = GET_OPERAND(uint32, I32, 2);
|
|
frame_ip += 4;
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
STORE_U16(maddr, (uint16)sval);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_STORE32)
|
|
{
|
|
uint32 offset, addr;
|
|
uint64 sval;
|
|
offset = read_uint32(frame_ip);
|
|
sval = GET_OPERAND(uint64, I64, 0);
|
|
addr = GET_OPERAND(uint32, I32, 2);
|
|
frame_ip += 4;
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
STORE_U32(maddr, (uint32)sval);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* memory size and memory grow instructions */
|
|
HANDLE_OP(WASM_OP_MEMORY_SIZE)
|
|
{
|
|
uint32 reserved;
|
|
addr_ret = GET_OFFSET();
|
|
frame_lp[addr_ret] = memory->cur_page_count;
|
|
(void)reserved;
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_MEMORY_GROW)
|
|
{
|
|
uint32 reserved, delta,
|
|
prev_page_count = memory->cur_page_count;
|
|
|
|
addr1 = GET_OFFSET();
|
|
addr_ret = GET_OFFSET();
|
|
delta = (uint32)frame_lp[addr1];
|
|
|
|
/* TODO: multi-memory wasm_enlarge_memory_with_idx() */
|
|
if (!wasm_enlarge_memory(module, delta)) {
|
|
/* failed to memory.grow, return -1 */
|
|
frame_lp[addr_ret] = -1;
|
|
}
|
|
else {
|
|
/* success, return previous page count */
|
|
frame_lp[addr_ret] = prev_page_count;
|
|
/* update memory size, no need to update memory ptr as
|
|
it isn't changed in wasm_enlarge_memory */
|
|
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|
|
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|
|
|| WASM_ENABLE_BULK_MEMORY != 0
|
|
linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory);
|
|
#endif
|
|
}
|
|
|
|
(void)reserved;
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* constant instructions */
|
|
HANDLE_OP(WASM_OP_F64_CONST)
|
|
HANDLE_OP(WASM_OP_I64_CONST)
|
|
{
|
|
uint8 *orig_ip = frame_ip;
|
|
|
|
frame_ip += sizeof(uint64);
|
|
addr_ret = GET_OFFSET();
|
|
|
|
bh_memcpy_s(frame_lp + addr_ret, sizeof(uint64), orig_ip,
|
|
sizeof(uint64));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_CONST)
|
|
HANDLE_OP(WASM_OP_I32_CONST)
|
|
{
|
|
uint8 *orig_ip = frame_ip;
|
|
|
|
frame_ip += sizeof(uint32);
|
|
addr_ret = GET_OFFSET();
|
|
|
|
bh_memcpy_s(frame_lp + addr_ret, sizeof(uint32), orig_ip,
|
|
sizeof(uint32));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* comparison instructions of i32 */
|
|
HANDLE_OP(WASM_OP_I32_EQZ)
|
|
{
|
|
DEF_OP_EQZ(int32, I32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_EQ)
|
|
{
|
|
DEF_OP_CMP(uint32, I32, ==);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_NE)
|
|
{
|
|
DEF_OP_CMP(uint32, I32, !=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_LT_S)
|
|
{
|
|
DEF_OP_CMP(int32, I32, <);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_LT_U)
|
|
{
|
|
DEF_OP_CMP(uint32, I32, <);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_GT_S)
|
|
{
|
|
DEF_OP_CMP(int32, I32, >);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_GT_U)
|
|
{
|
|
DEF_OP_CMP(uint32, I32, >);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_LE_S)
|
|
{
|
|
DEF_OP_CMP(int32, I32, <=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_LE_U)
|
|
{
|
|
DEF_OP_CMP(uint32, I32, <=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_GE_S)
|
|
{
|
|
DEF_OP_CMP(int32, I32, >=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_GE_U)
|
|
{
|
|
DEF_OP_CMP(uint32, I32, >=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* comparison instructions of i64 */
|
|
HANDLE_OP(WASM_OP_I64_EQZ)
|
|
{
|
|
DEF_OP_EQZ(int64, I64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_EQ)
|
|
{
|
|
DEF_OP_CMP(uint64, I64, ==);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_NE)
|
|
{
|
|
DEF_OP_CMP(uint64, I64, !=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LT_S)
|
|
{
|
|
DEF_OP_CMP(int64, I64, <);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LT_U)
|
|
{
|
|
DEF_OP_CMP(uint64, I64, <);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_GT_S)
|
|
{
|
|
DEF_OP_CMP(int64, I64, >);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_GT_U)
|
|
{
|
|
DEF_OP_CMP(uint64, I64, >);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LE_S)
|
|
{
|
|
DEF_OP_CMP(int64, I64, <=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_LE_U)
|
|
{
|
|
DEF_OP_CMP(uint64, I64, <=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_GE_S)
|
|
{
|
|
DEF_OP_CMP(int64, I64, >=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_GE_U)
|
|
{
|
|
DEF_OP_CMP(uint64, I64, >=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* comparison instructions of f32 */
|
|
HANDLE_OP(WASM_OP_F32_EQ)
|
|
{
|
|
DEF_OP_CMP(float32, F32, ==);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_NE)
|
|
{
|
|
DEF_OP_CMP(float32, F32, !=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_LT)
|
|
{
|
|
DEF_OP_CMP(float32, F32, <);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_GT)
|
|
{
|
|
DEF_OP_CMP(float32, F32, >);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_LE)
|
|
{
|
|
DEF_OP_CMP(float32, F32, <=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_GE)
|
|
{
|
|
DEF_OP_CMP(float32, F32, >=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* comparison instructions of f64 */
|
|
HANDLE_OP(WASM_OP_F64_EQ)
|
|
{
|
|
DEF_OP_CMP(float64, F64, ==);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_NE)
|
|
{
|
|
DEF_OP_CMP(float64, F64, !=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_LT)
|
|
{
|
|
DEF_OP_CMP(float64, F64, <);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_GT)
|
|
{
|
|
DEF_OP_CMP(float64, F64, >);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_LE)
|
|
{
|
|
DEF_OP_CMP(float64, F64, <=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_GE)
|
|
{
|
|
DEF_OP_CMP(float64, F64, >=);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* numeric instructions of i32 */
|
|
HANDLE_OP(WASM_OP_I32_CLZ)
|
|
{
|
|
DEF_OP_BIT_COUNT(uint32, I32, clz32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_CTZ)
|
|
{
|
|
DEF_OP_BIT_COUNT(uint32, I32, ctz32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_POPCNT)
|
|
{
|
|
DEF_OP_BIT_COUNT(uint32, I32, popcount32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_ADD)
|
|
{
|
|
DEF_OP_NUMERIC(uint32, uint32, I32, +);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_SUB)
|
|
{
|
|
DEF_OP_NUMERIC(uint32, uint32, I32, -);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_MUL)
|
|
{
|
|
DEF_OP_NUMERIC(uint32, uint32, I32, *);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_DIV_S)
|
|
{
|
|
int32 a, b;
|
|
|
|
b = frame_lp[GET_OFFSET()];
|
|
a = frame_lp[GET_OFFSET()];
|
|
addr_ret = GET_OFFSET();
|
|
if (a == (int32)0x80000000 && b == -1) {
|
|
wasm_set_exception(module, "integer overflow");
|
|
goto got_exception;
|
|
}
|
|
if (b == 0) {
|
|
wasm_set_exception(module, "integer divide by zero");
|
|
goto got_exception;
|
|
}
|
|
frame_lp[addr_ret] = (a / b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_DIV_U)
|
|
{
|
|
uint32 a, b;
|
|
|
|
addr1 = GET_OFFSET();
|
|
addr2 = GET_OFFSET();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
b = (uint32)frame_lp[addr1];
|
|
a = (uint32)frame_lp[addr2];
|
|
if (b == 0) {
|
|
wasm_set_exception(module, "integer divide by zero");
|
|
goto got_exception;
|
|
}
|
|
frame_lp[addr_ret] = (a / b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_REM_S)
|
|
{
|
|
int32 a, b;
|
|
|
|
addr1 = GET_OFFSET();
|
|
addr2 = GET_OFFSET();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
b = frame_lp[addr1];
|
|
a = frame_lp[addr2];
|
|
if (a == (int32)0x80000000 && b == -1) {
|
|
frame_lp[addr_ret] = 0;
|
|
HANDLE_OP_END();
|
|
}
|
|
if (b == 0) {
|
|
wasm_set_exception(module, "integer divide by zero");
|
|
goto got_exception;
|
|
}
|
|
frame_lp[addr_ret] = (a % b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_REM_U)
|
|
{
|
|
uint32 a, b;
|
|
|
|
addr1 = GET_OFFSET();
|
|
addr2 = GET_OFFSET();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
b = (uint32)frame_lp[addr1];
|
|
a = (uint32)frame_lp[addr2];
|
|
if (b == 0) {
|
|
wasm_set_exception(module, "integer divide by zero");
|
|
goto got_exception;
|
|
}
|
|
frame_lp[addr_ret] = (a % b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_AND)
|
|
{
|
|
DEF_OP_NUMERIC(uint32, uint32, I32, &);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_OR)
|
|
{
|
|
DEF_OP_NUMERIC(uint32, uint32, I32, |);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_XOR)
|
|
{
|
|
DEF_OP_NUMERIC(uint32, uint32, I32, ^);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_SHL)
|
|
{
|
|
DEF_OP_NUMERIC2(uint32, uint32, I32, <<);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_SHR_S)
|
|
{
|
|
DEF_OP_NUMERIC2(int32, uint32, I32, >>);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_SHR_U)
|
|
{
|
|
DEF_OP_NUMERIC2(uint32, uint32, I32, >>);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_ROTL)
|
|
{
|
|
uint32 a, b;
|
|
|
|
b = (uint32)frame_lp[GET_OFFSET()];
|
|
a = (uint32)frame_lp[GET_OFFSET()];
|
|
frame_lp[GET_OFFSET()] = rotl32(a, b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_ROTR)
|
|
{
|
|
uint32 a, b;
|
|
|
|
b = (uint32)frame_lp[GET_OFFSET()];
|
|
a = (uint32)frame_lp[GET_OFFSET()];
|
|
frame_lp[GET_OFFSET()] = rotr32(a, b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* numeric instructions of i64 */
|
|
HANDLE_OP(WASM_OP_I64_CLZ)
|
|
{
|
|
DEF_OP_BIT_COUNT(uint64, I64, clz64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_CTZ)
|
|
{
|
|
DEF_OP_BIT_COUNT(uint64, I64, ctz64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_POPCNT)
|
|
{
|
|
DEF_OP_BIT_COUNT(uint64, I64, popcount64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_ADD)
|
|
{
|
|
DEF_OP_NUMERIC_64(uint64, uint64, I64, +);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_SUB)
|
|
{
|
|
DEF_OP_NUMERIC_64(uint64, uint64, I64, -);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_MUL)
|
|
{
|
|
DEF_OP_NUMERIC_64(uint64, uint64, I64, *);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_DIV_S)
|
|
{
|
|
int64 a, b;
|
|
|
|
b = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
a = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
if (a == (int64)0x8000000000000000LL && b == -1) {
|
|
wasm_set_exception(module, "integer overflow");
|
|
goto got_exception;
|
|
}
|
|
if (b == 0) {
|
|
wasm_set_exception(module, "integer divide by zero");
|
|
goto got_exception;
|
|
}
|
|
PUT_I64_TO_ADDR(frame_lp + GET_OFFSET(), a / b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_DIV_U)
|
|
{
|
|
uint64 a, b;
|
|
|
|
b = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
a = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
if (b == 0) {
|
|
wasm_set_exception(module, "integer divide by zero");
|
|
goto got_exception;
|
|
}
|
|
PUT_I64_TO_ADDR(frame_lp + GET_OFFSET(), a / b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_REM_S)
|
|
{
|
|
int64 a, b;
|
|
|
|
b = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
a = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
if (a == (int64)0x8000000000000000LL && b == -1) {
|
|
*(int64 *)(frame_lp + GET_OFFSET()) = 0;
|
|
HANDLE_OP_END();
|
|
}
|
|
if (b == 0) {
|
|
wasm_set_exception(module, "integer divide by zero");
|
|
goto got_exception;
|
|
}
|
|
PUT_I64_TO_ADDR(frame_lp + GET_OFFSET(), a % b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_REM_U)
|
|
{
|
|
uint64 a, b;
|
|
|
|
b = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
a = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
if (b == 0) {
|
|
wasm_set_exception(module, "integer divide by zero");
|
|
goto got_exception;
|
|
}
|
|
PUT_I64_TO_ADDR(frame_lp + GET_OFFSET(), a % b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_AND)
|
|
{
|
|
DEF_OP_NUMERIC_64(uint64, uint64, I64, &);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_OR)
|
|
{
|
|
DEF_OP_NUMERIC_64(uint64, uint64, I64, |);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_XOR)
|
|
{
|
|
DEF_OP_NUMERIC_64(uint64, uint64, I64, ^);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_SHL)
|
|
{
|
|
DEF_OP_NUMERIC2_64(uint64, uint64, I64, <<);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_SHR_S)
|
|
{
|
|
DEF_OP_NUMERIC2_64(int64, uint64, I64, >>);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_SHR_U)
|
|
{
|
|
DEF_OP_NUMERIC2_64(uint64, uint64, I64, >>);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_ROTL)
|
|
{
|
|
uint64 a, b;
|
|
|
|
b = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
a = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
PUT_I64_TO_ADDR(frame_lp + GET_OFFSET(), rotl64(a, b));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_ROTR)
|
|
{
|
|
uint64 a, b;
|
|
|
|
b = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
a = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
PUT_I64_TO_ADDR(frame_lp + GET_OFFSET(), rotr64(a, b));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* numeric instructions of f32 */
|
|
HANDLE_OP(WASM_OP_F32_ABS)
|
|
{
|
|
DEF_OP_MATH(float32, F32, fabsf);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_NEG)
|
|
{
|
|
uint32 u32 = frame_lp[GET_OFFSET()];
|
|
uint32 sign_bit = u32 & ((uint32)1 << 31);
|
|
addr_ret = GET_OFFSET();
|
|
if (sign_bit)
|
|
frame_lp[addr_ret] = u32 & ~((uint32)1 << 31);
|
|
else
|
|
frame_lp[addr_ret] = u32 | ((uint32)1 << 31);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_CEIL)
|
|
{
|
|
DEF_OP_MATH(float32, F32, ceilf);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_FLOOR)
|
|
{
|
|
DEF_OP_MATH(float32, F32, floorf);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_TRUNC)
|
|
{
|
|
DEF_OP_MATH(float32, F32, truncf);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_NEAREST)
|
|
{
|
|
DEF_OP_MATH(float32, F32, rintf);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_SQRT)
|
|
{
|
|
DEF_OP_MATH(float32, F32, sqrtf);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_ADD)
|
|
{
|
|
DEF_OP_NUMERIC(float32, float32, F32, +);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_SUB)
|
|
{
|
|
DEF_OP_NUMERIC(float32, float32, F32, -);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_MUL)
|
|
{
|
|
DEF_OP_NUMERIC(float32, float32, F32, *);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_DIV)
|
|
{
|
|
DEF_OP_NUMERIC(float32, float32, F32, /);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_MIN)
|
|
{
|
|
float32 a, b;
|
|
|
|
b = *(float32 *)(frame_lp + GET_OFFSET());
|
|
a = *(float32 *)(frame_lp + GET_OFFSET());
|
|
|
|
*(float32 *)(frame_lp + GET_OFFSET()) = f32_min(a, b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_MAX)
|
|
{
|
|
float32 a, b;
|
|
|
|
b = *(float32 *)(frame_lp + GET_OFFSET());
|
|
a = *(float32 *)(frame_lp + GET_OFFSET());
|
|
|
|
*(float32 *)(frame_lp + GET_OFFSET()) = f32_max(a, b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_COPYSIGN)
|
|
{
|
|
float32 a, b;
|
|
|
|
b = *(float32 *)(frame_lp + GET_OFFSET());
|
|
a = *(float32 *)(frame_lp + GET_OFFSET());
|
|
*(float32 *)(frame_lp + GET_OFFSET()) = local_copysignf(a, b);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* numeric instructions of f64 */
|
|
HANDLE_OP(WASM_OP_F64_ABS)
|
|
{
|
|
DEF_OP_MATH(float64, F64, fabs);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_NEG)
|
|
{
|
|
uint64 u64 = GET_I64_FROM_ADDR(frame_lp + GET_OFFSET());
|
|
uint64 sign_bit = u64 & (((uint64)1) << 63);
|
|
if (sign_bit)
|
|
PUT_I64_TO_ADDR(frame_lp + GET_OFFSET(),
|
|
(u64 & ~(((uint64)1) << 63)));
|
|
else
|
|
PUT_I64_TO_ADDR(frame_lp + GET_OFFSET(),
|
|
(u64 | (((uint64)1) << 63)));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_CEIL)
|
|
{
|
|
DEF_OP_MATH(float64, F64, ceil);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_FLOOR)
|
|
{
|
|
DEF_OP_MATH(float64, F64, floor);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_TRUNC)
|
|
{
|
|
DEF_OP_MATH(float64, F64, trunc);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_NEAREST)
|
|
{
|
|
DEF_OP_MATH(float64, F64, rint);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_SQRT)
|
|
{
|
|
DEF_OP_MATH(float64, F64, sqrt);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_ADD)
|
|
{
|
|
DEF_OP_NUMERIC_64(float64, float64, F64, +);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_SUB)
|
|
{
|
|
DEF_OP_NUMERIC_64(float64, float64, F64, -);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_MUL)
|
|
{
|
|
DEF_OP_NUMERIC_64(float64, float64, F64, *);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_DIV)
|
|
{
|
|
DEF_OP_NUMERIC_64(float64, float64, F64, /);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_MIN)
|
|
{
|
|
float64 a, b;
|
|
|
|
b = POP_F64();
|
|
a = POP_F64();
|
|
|
|
PUSH_F64(f64_min(a, b));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_MAX)
|
|
{
|
|
float64 a, b;
|
|
|
|
b = POP_F64();
|
|
a = POP_F64();
|
|
|
|
PUSH_F64(f64_max(a, b));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_COPYSIGN)
|
|
{
|
|
float64 a, b;
|
|
|
|
b = POP_F64();
|
|
a = POP_F64();
|
|
PUSH_F64(local_copysign(a, b));
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* conversions of i32 */
|
|
HANDLE_OP(WASM_OP_I32_WRAP_I64)
|
|
{
|
|
int32 value = (int32)(POP_I64() & 0xFFFFFFFFLL);
|
|
PUSH_I32(value);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_TRUNC_S_F32)
|
|
{
|
|
/* We don't use INT32_MIN/INT32_MAX/UINT32_MIN/UINT32_MAX,
|
|
since float/double values of ieee754 cannot precisely
|
|
represent all int32/uint32/int64/uint64 values, e.g.:
|
|
UINT32_MAX is 4294967295, but (float32)4294967295 is
|
|
4294967296.0f, but not 4294967295.0f. */
|
|
DEF_OP_TRUNC_F32(-2147483904.0f, 2147483648.0f, true, true);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_TRUNC_U_F32)
|
|
{
|
|
DEF_OP_TRUNC_F32(-1.0f, 4294967296.0f, true, false);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_TRUNC_S_F64)
|
|
{
|
|
DEF_OP_TRUNC_F64(-2147483649.0, 2147483648.0, true, true);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_TRUNC_U_F64)
|
|
{
|
|
DEF_OP_TRUNC_F64(-1.0, 4294967296.0, true, false);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* conversions of i64 */
|
|
HANDLE_OP(WASM_OP_I64_EXTEND_S_I32)
|
|
{
|
|
DEF_OP_CONVERT(int64, I64, int32, I32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_EXTEND_U_I32)
|
|
{
|
|
DEF_OP_CONVERT(int64, I64, uint32, I32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_TRUNC_S_F32)
|
|
{
|
|
DEF_OP_TRUNC_F32(-9223373136366403584.0f,
|
|
9223372036854775808.0f, false, true);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_TRUNC_U_F32)
|
|
{
|
|
DEF_OP_TRUNC_F32(-1.0f, 18446744073709551616.0f, false, false);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_TRUNC_S_F64)
|
|
{
|
|
DEF_OP_TRUNC_F64(-9223372036854777856.0, 9223372036854775808.0,
|
|
false, true);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_TRUNC_U_F64)
|
|
{
|
|
DEF_OP_TRUNC_F64(-1.0, 18446744073709551616.0, false, false);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* conversions of f32 */
|
|
HANDLE_OP(WASM_OP_F32_CONVERT_S_I32)
|
|
{
|
|
DEF_OP_CONVERT(float32, F32, int32, I32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_CONVERT_U_I32)
|
|
{
|
|
DEF_OP_CONVERT(float32, F32, uint32, I32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_CONVERT_S_I64)
|
|
{
|
|
DEF_OP_CONVERT(float32, F32, int64, I64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_CONVERT_U_I64)
|
|
{
|
|
DEF_OP_CONVERT(float32, F32, uint64, I64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F32_DEMOTE_F64)
|
|
{
|
|
DEF_OP_CONVERT(float32, F32, float64, F64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* conversions of f64 */
|
|
HANDLE_OP(WASM_OP_F64_CONVERT_S_I32)
|
|
{
|
|
DEF_OP_CONVERT(float64, F64, int32, I32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_CONVERT_U_I32)
|
|
{
|
|
DEF_OP_CONVERT(float64, F64, uint32, I32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_CONVERT_S_I64)
|
|
{
|
|
DEF_OP_CONVERT(float64, F64, int64, I64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_CONVERT_U_I64)
|
|
{
|
|
DEF_OP_CONVERT(float64, F64, uint64, I64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_F64_PROMOTE_F32)
|
|
{
|
|
DEF_OP_CONVERT(float64, F64, float32, F32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
/* reinterpretations */
|
|
HANDLE_OP(WASM_OP_I32_REINTERPRET_F32)
|
|
HANDLE_OP(WASM_OP_F32_REINTERPRET_I32)
|
|
{
|
|
DEF_OP_REINTERPRET(uint32, I32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_REINTERPRET_F64)
|
|
HANDLE_OP(WASM_OP_F64_REINTERPRET_I64)
|
|
{
|
|
DEF_OP_REINTERPRET(int64, I64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(EXT_OP_COPY_STACK_TOP)
|
|
{
|
|
addr1 = GET_OFFSET();
|
|
addr2 = GET_OFFSET();
|
|
frame_lp[addr2] = frame_lp[addr1];
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
/* Ignore constants because they are not reference */
|
|
if (addr1 >= 0) {
|
|
if (*FRAME_REF(addr1)) {
|
|
CLEAR_FRAME_REF(addr1);
|
|
SET_FRAME_REF(addr2);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(EXT_OP_COPY_STACK_TOP_I64)
|
|
{
|
|
addr1 = GET_OFFSET();
|
|
addr2 = GET_OFFSET();
|
|
|
|
PUT_I64_TO_ADDR(frame_lp + addr2,
|
|
GET_I64_FROM_ADDR(frame_lp + addr1));
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
/* Ignore constants because they are not reference */
|
|
if (addr1 >= 0) {
|
|
if (*FRAME_REF(addr1)) {
|
|
CLEAR_FRAME_REF(addr1);
|
|
SET_FRAME_REF(addr2);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
HANDLE_OP_END();
|
|
}
|
|
#if WASM_ENABLE_SIMDE != 0
|
|
HANDLE_OP(EXT_OP_COPY_STACK_TOP_V128)
|
|
{
|
|
addr1 = GET_OFFSET();
|
|
addr2 = GET_OFFSET();
|
|
|
|
PUT_V128_TO_ADDR(frame_lp + addr2,
|
|
GET_V128_FROM_ADDR(frame_lp + addr1));
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
/* Ignore constants because they are not reference */
|
|
if (addr1 >= 0) {
|
|
if (*FRAME_REF(addr1)) {
|
|
CLEAR_FRAME_REF(addr1);
|
|
SET_FRAME_REF(addr2);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
HANDLE_OP_END();
|
|
}
|
|
#endif
|
|
|
|
HANDLE_OP(EXT_OP_COPY_STACK_VALUES)
|
|
{
|
|
uint32 values_count, total_cell;
|
|
uint8 *cells;
|
|
int16 *src_offsets = NULL;
|
|
uint16 *dst_offsets = NULL;
|
|
|
|
/* read values_count */
|
|
values_count = read_uint32(frame_ip);
|
|
/* read total cell num */
|
|
total_cell = read_uint32(frame_ip);
|
|
/* cells */
|
|
cells = (uint8 *)frame_ip;
|
|
frame_ip += values_count * CELL_SIZE;
|
|
/* src offsets */
|
|
src_offsets = (int16 *)frame_ip;
|
|
frame_ip += values_count * sizeof(int16);
|
|
/* dst offsets */
|
|
dst_offsets = (uint16 *)frame_ip;
|
|
frame_ip += values_count * sizeof(uint16);
|
|
|
|
if (!copy_stack_values(module, frame_lp, values_count,
|
|
#if WASM_ENABLE_GC != 0
|
|
frame_ref,
|
|
#endif
|
|
total_cell, cells, src_offsets,
|
|
dst_offsets))
|
|
goto got_exception;
|
|
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_SET_LOCAL)
|
|
{
|
|
opcode = WASM_OP_SET_LOCAL;
|
|
goto handle_op_set_tee_local;
|
|
}
|
|
HANDLE_OP(WASM_OP_TEE_LOCAL)
|
|
{
|
|
opcode = WASM_OP_TEE_LOCAL;
|
|
handle_op_set_tee_local:
|
|
|
|
GET_LOCAL_INDEX_TYPE_AND_OFFSET();
|
|
addr1 = GET_OFFSET();
|
|
|
|
if (local_type == VALUE_TYPE_I32 || local_type == VALUE_TYPE_F32
|
|
#if WASM_ENABLE_REF_TYPES != 0 && WASM_ENABLE_GC == 0
|
|
|| local_type == VALUE_TYPE_FUNCREF
|
|
|| local_type == VALUE_TYPE_EXTERNREF
|
|
#endif
|
|
) {
|
|
*(int32 *)(frame_lp + local_offset) = frame_lp[addr1];
|
|
}
|
|
else if (local_type == VALUE_TYPE_I64
|
|
|| local_type == VALUE_TYPE_F64) {
|
|
PUT_I64_TO_ADDR((uint32 *)(frame_lp + local_offset),
|
|
GET_I64_FROM_ADDR(frame_lp + addr1));
|
|
}
|
|
#if WASM_ENABLE_GC != 0
|
|
else if (wasm_is_type_reftype(local_type)) {
|
|
PUT_REF_TO_ADDR((uint32 *)(frame_lp + local_offset),
|
|
GET_REF_FROM_ADDR(frame_lp + addr1));
|
|
if (opcode == WASM_OP_SET_LOCAL) {
|
|
CLEAR_FRAME_REF(addr1);
|
|
}
|
|
}
|
|
#endif
|
|
else {
|
|
wasm_set_exception(module, "invalid local type");
|
|
goto got_exception;
|
|
}
|
|
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_EXTEND8_S)
|
|
{
|
|
DEF_OP_CONVERT(int32, I32, int8, I32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I32_EXTEND16_S)
|
|
{
|
|
DEF_OP_CONVERT(int32, I32, int16, I32);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_EXTEND8_S)
|
|
{
|
|
DEF_OP_CONVERT(int64, I64, int8, I64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_EXTEND16_S)
|
|
{
|
|
DEF_OP_CONVERT(int64, I64, int16, I64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_I64_EXTEND32_S)
|
|
{
|
|
DEF_OP_CONVERT(int64, I64, int32, I64);
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
HANDLE_OP(WASM_OP_MISC_PREFIX)
|
|
{
|
|
GET_OPCODE();
|
|
switch (opcode) {
|
|
case WASM_OP_I32_TRUNC_SAT_S_F32:
|
|
DEF_OP_TRUNC_SAT_F32(-2147483904.0f, 2147483648.0f,
|
|
true, true);
|
|
break;
|
|
case WASM_OP_I32_TRUNC_SAT_U_F32:
|
|
DEF_OP_TRUNC_SAT_F32(-1.0f, 4294967296.0f, true, false);
|
|
break;
|
|
case WASM_OP_I32_TRUNC_SAT_S_F64:
|
|
DEF_OP_TRUNC_SAT_F64(-2147483649.0, 2147483648.0, true,
|
|
true);
|
|
break;
|
|
case WASM_OP_I32_TRUNC_SAT_U_F64:
|
|
DEF_OP_TRUNC_SAT_F64(-1.0, 4294967296.0, true, false);
|
|
break;
|
|
case WASM_OP_I64_TRUNC_SAT_S_F32:
|
|
DEF_OP_TRUNC_SAT_F32(-9223373136366403584.0f,
|
|
9223372036854775808.0f, false,
|
|
true);
|
|
break;
|
|
case WASM_OP_I64_TRUNC_SAT_U_F32:
|
|
DEF_OP_TRUNC_SAT_F32(-1.0f, 18446744073709551616.0f,
|
|
false, false);
|
|
break;
|
|
case WASM_OP_I64_TRUNC_SAT_S_F64:
|
|
DEF_OP_TRUNC_SAT_F64(-9223372036854777856.0,
|
|
9223372036854775808.0, false,
|
|
true);
|
|
break;
|
|
case WASM_OP_I64_TRUNC_SAT_U_F64:
|
|
DEF_OP_TRUNC_SAT_F64(-1.0, 18446744073709551616.0,
|
|
false, false);
|
|
break;
|
|
#if WASM_ENABLE_BULK_MEMORY != 0
|
|
case WASM_OP_MEMORY_INIT:
|
|
{
|
|
uint32 addr, segment;
|
|
uint64 bytes, offset, seg_len;
|
|
uint8 *data;
|
|
|
|
segment = read_uint32(frame_ip);
|
|
|
|
bytes = (uint64)(uint32)POP_I32();
|
|
offset = (uint64)(uint32)POP_I32();
|
|
addr = POP_I32();
|
|
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
linear_mem_size = get_linear_mem_size();
|
|
#endif
|
|
|
|
#ifndef OS_ENABLE_HW_BOUND_CHECK
|
|
CHECK_BULK_MEMORY_OVERFLOW(addr, bytes, maddr);
|
|
#else
|
|
#if WASM_ENABLE_SHARED_HEAP != 0
|
|
if (app_addr_in_shared_heap((uint64)(uint32)addr,
|
|
bytes))
|
|
shared_heap_addr_app_to_native((uint64)(uint32)addr,
|
|
maddr);
|
|
else
|
|
#endif
|
|
{
|
|
if ((uint64)(uint32)addr + bytes > linear_mem_size)
|
|
goto out_of_bounds;
|
|
maddr = memory->memory_data + (uint32)addr;
|
|
}
|
|
#endif
|
|
if (bh_bitmap_get_bit(module->e->common.data_dropped,
|
|
segment)) {
|
|
seg_len = 0;
|
|
data = NULL;
|
|
}
|
|
else {
|
|
seg_len =
|
|
(uint64)module->module->data_segments[segment]
|
|
->data_length;
|
|
data = module->module->data_segments[segment]->data;
|
|
}
|
|
if (offset + bytes > seg_len)
|
|
goto out_of_bounds;
|
|
|
|
bh_memcpy_s(maddr, (uint32)(linear_mem_size - addr),
|
|
data + offset, (uint32)bytes);
|
|
break;
|
|
}
|
|
case WASM_OP_DATA_DROP:
|
|
{
|
|
uint32 segment;
|
|
|
|
segment = read_uint32(frame_ip);
|
|
bh_bitmap_set_bit(module->e->common.data_dropped,
|
|
segment);
|
|
break;
|
|
}
|
|
case WASM_OP_MEMORY_COPY:
|
|
{
|
|
uint32 dst, src, len;
|
|
uint8 *mdst, *msrc;
|
|
|
|
len = POP_I32();
|
|
src = POP_I32();
|
|
dst = POP_I32();
|
|
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
linear_mem_size = get_linear_mem_size();
|
|
#endif
|
|
|
|
#ifndef OS_ENABLE_HW_BOUND_CHECK
|
|
CHECK_BULK_MEMORY_OVERFLOW(src, len, msrc);
|
|
CHECK_BULK_MEMORY_OVERFLOW(dst, len, mdst);
|
|
#else /* else of OS_ENABLE_HW_BOUND_CHECK */
|
|
#if WASM_ENABLE_SHARED_HEAP != 0
|
|
if (app_addr_in_shared_heap((uint64)src, len))
|
|
shared_heap_addr_app_to_native((uint64)src, msrc);
|
|
else
|
|
#endif
|
|
{
|
|
if ((uint64)(uint32)src + len > linear_mem_size)
|
|
goto out_of_bounds;
|
|
msrc = memory->memory_data + (uint32)src;
|
|
}
|
|
|
|
#if WASM_ENABLE_SHARED_HEAP != 0
|
|
if (app_addr_in_shared_heap((uint64)dst, len)) {
|
|
shared_heap_addr_app_to_native((uint64)dst, mdst);
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
if ((uint64)(uint32)dst + len > linear_mem_size)
|
|
goto out_of_bounds;
|
|
mdst = memory->memory_data + (uint32)dst;
|
|
}
|
|
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
|
|
|
|
/*
|
|
* avoid unnecessary operations
|
|
*
|
|
* since dst and src both are valid indexes in the
|
|
* linear memory, mdst and msrc can't be NULL
|
|
*
|
|
* The spec. converts memory.copy into i32.load8 and
|
|
* i32.store8; the following are runtime-specific
|
|
* optimizations.
|
|
*
|
|
*/
|
|
if (len && mdst != msrc) {
|
|
/* allowing the destination and source to overlap */
|
|
memmove(mdst, msrc, len);
|
|
}
|
|
break;
|
|
}
|
|
case WASM_OP_MEMORY_FILL:
|
|
{
|
|
uint32 dst, len;
|
|
uint8 fill_val, *mdst;
|
|
|
|
len = POP_I32();
|
|
fill_val = POP_I32();
|
|
dst = POP_I32();
|
|
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
linear_mem_size = get_linear_mem_size();
|
|
#endif
|
|
|
|
#ifndef OS_ENABLE_HW_BOUND_CHECK
|
|
CHECK_BULK_MEMORY_OVERFLOW(dst, len, mdst);
|
|
#else
|
|
#if WASM_ENABLE_SHARED_HEAP != 0
|
|
if (app_addr_in_shared_heap((uint64)(uint32)dst, len))
|
|
shared_heap_addr_app_to_native((uint64)(uint32)dst,
|
|
mdst);
|
|
else
|
|
#endif
|
|
{
|
|
if ((uint64)(uint32)dst + len > linear_mem_size)
|
|
goto out_of_bounds;
|
|
mdst = memory->memory_data + (uint32)dst;
|
|
}
|
|
#endif
|
|
|
|
memset(mdst, fill_val, len);
|
|
break;
|
|
}
|
|
#endif /* WASM_ENABLE_BULK_MEMORY */
|
|
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
|
|
case WASM_OP_TABLE_INIT:
|
|
{
|
|
uint32 tbl_idx, elem_idx;
|
|
uint32 n, s, d;
|
|
WASMTableInstance *tbl_inst;
|
|
table_elem_type_t *table_elems;
|
|
InitializerExpression *tbl_seg_init_values = NULL,
|
|
*init_values;
|
|
uint64 i;
|
|
uint32 tbl_seg_len = 0;
|
|
|
|
elem_idx = read_uint32(frame_ip);
|
|
bh_assert(elem_idx < module->module->table_seg_count);
|
|
|
|
tbl_idx = read_uint32(frame_ip);
|
|
bh_assert(tbl_idx < module->module->table_count);
|
|
|
|
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
|
|
|
n = (uint32)POP_I32();
|
|
s = (uint32)POP_I32();
|
|
d = (uint32)POP_I32();
|
|
|
|
if (!bh_bitmap_get_bit(module->e->common.elem_dropped,
|
|
elem_idx)) {
|
|
/* table segment isn't dropped */
|
|
tbl_seg_init_values =
|
|
module->module->table_segments[elem_idx]
|
|
.init_values;
|
|
tbl_seg_len =
|
|
module->module->table_segments[elem_idx]
|
|
.value_count;
|
|
}
|
|
|
|
if (offset_len_out_of_bounds(s, n, tbl_seg_len)
|
|
|| offset_len_out_of_bounds(d, n,
|
|
tbl_inst->cur_size)) {
|
|
wasm_set_exception(module,
|
|
"out of bounds table access");
|
|
goto got_exception;
|
|
}
|
|
|
|
if (!n) {
|
|
break;
|
|
}
|
|
|
|
table_elems = tbl_inst->elems + d;
|
|
init_values = tbl_seg_init_values + s;
|
|
#if WASM_ENABLE_GC != 0
|
|
SYNC_ALL_TO_FRAME();
|
|
#endif
|
|
for (i = 0; i < n; i++) {
|
|
/* UINT32_MAX indicates that it is a null ref */
|
|
bh_assert(init_values[i].init_expr_type
|
|
== INIT_EXPR_TYPE_REFNULL_CONST
|
|
|| init_values[i].init_expr_type
|
|
== INIT_EXPR_TYPE_FUNCREF_CONST);
|
|
#if WASM_ENABLE_GC == 0
|
|
table_elems[i] =
|
|
(table_elem_type_t)init_values[i].u.ref_index;
|
|
#else
|
|
if (init_values[i].u.ref_index != UINT32_MAX) {
|
|
if (!(func_obj = wasm_create_func_obj(
|
|
module, init_values[i].u.ref_index,
|
|
true, NULL, 0))) {
|
|
goto got_exception;
|
|
}
|
|
table_elems[i] = func_obj;
|
|
}
|
|
else {
|
|
table_elems[i] = NULL_REF;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
break;
|
|
}
|
|
case WASM_OP_ELEM_DROP:
|
|
{
|
|
uint32 elem_idx = read_uint32(frame_ip);
|
|
bh_assert(elem_idx < module->module->table_seg_count);
|
|
bh_bitmap_set_bit(module->e->common.elem_dropped,
|
|
elem_idx);
|
|
break;
|
|
}
|
|
case WASM_OP_TABLE_COPY:
|
|
{
|
|
uint32 src_tbl_idx, dst_tbl_idx;
|
|
uint32 n, s, d;
|
|
WASMTableInstance *src_tbl_inst, *dst_tbl_inst;
|
|
|
|
dst_tbl_idx = read_uint32(frame_ip);
|
|
bh_assert(dst_tbl_idx < module->table_count);
|
|
|
|
dst_tbl_inst = wasm_get_table_inst(module, dst_tbl_idx);
|
|
|
|
src_tbl_idx = read_uint32(frame_ip);
|
|
bh_assert(src_tbl_idx < module->table_count);
|
|
|
|
src_tbl_inst = wasm_get_table_inst(module, src_tbl_idx);
|
|
|
|
n = (uint32)POP_I32();
|
|
s = (uint32)POP_I32();
|
|
d = (uint32)POP_I32();
|
|
|
|
if (offset_len_out_of_bounds(d, n,
|
|
dst_tbl_inst->cur_size)
|
|
|| offset_len_out_of_bounds(
|
|
s, n, src_tbl_inst->cur_size)) {
|
|
wasm_set_exception(module,
|
|
"out of bounds table access");
|
|
goto got_exception;
|
|
}
|
|
|
|
/* if s >= d, copy from front to back */
|
|
/* if s < d, copy from back to front */
|
|
/* merge all together */
|
|
bh_memmove_s((uint8 *)dst_tbl_inst
|
|
+ offsetof(WASMTableInstance, elems)
|
|
+ d * sizeof(table_elem_type_t),
|
|
(uint32)((dst_tbl_inst->cur_size - d)
|
|
* sizeof(table_elem_type_t)),
|
|
(uint8 *)src_tbl_inst
|
|
+ offsetof(WASMTableInstance, elems)
|
|
+ s * sizeof(table_elem_type_t),
|
|
(uint32)(n * sizeof(table_elem_type_t)));
|
|
break;
|
|
}
|
|
case WASM_OP_TABLE_GROW:
|
|
{
|
|
uint32 tbl_idx, n, orig_tbl_sz;
|
|
WASMTableInstance *tbl_inst;
|
|
table_elem_type_t init_val;
|
|
|
|
tbl_idx = read_uint32(frame_ip);
|
|
bh_assert(tbl_idx < module->table_count);
|
|
|
|
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
|
|
|
orig_tbl_sz = tbl_inst->cur_size;
|
|
|
|
n = POP_I32();
|
|
#if WASM_ENABLE_GC == 0
|
|
init_val = POP_I32();
|
|
#else
|
|
init_val = POP_REF();
|
|
#endif
|
|
|
|
if (!wasm_enlarge_table(module, tbl_idx, n, init_val)) {
|
|
PUSH_I32(-1);
|
|
}
|
|
else {
|
|
PUSH_I32(orig_tbl_sz);
|
|
}
|
|
|
|
break;
|
|
}
|
|
case WASM_OP_TABLE_SIZE:
|
|
{
|
|
uint32 tbl_idx;
|
|
WASMTableInstance *tbl_inst;
|
|
|
|
tbl_idx = read_uint32(frame_ip);
|
|
bh_assert(tbl_idx < module->table_count);
|
|
|
|
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
|
|
|
PUSH_I32(tbl_inst->cur_size);
|
|
break;
|
|
}
|
|
case WASM_OP_TABLE_FILL:
|
|
{
|
|
uint32 tbl_idx, n, i;
|
|
WASMTableInstance *tbl_inst;
|
|
table_elem_type_t fill_val;
|
|
|
|
tbl_idx = read_uint32(frame_ip);
|
|
bh_assert(tbl_idx < module->table_count);
|
|
|
|
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
|
|
|
n = POP_I32();
|
|
#if WASM_ENABLE_GC == 0
|
|
fill_val = POP_I32();
|
|
#else
|
|
fill_val = POP_REF();
|
|
#endif
|
|
i = POP_I32();
|
|
|
|
if (offset_len_out_of_bounds(i, n,
|
|
tbl_inst->cur_size)) {
|
|
wasm_set_exception(module,
|
|
"out of bounds table access");
|
|
goto got_exception;
|
|
}
|
|
|
|
for (; n != 0; i++, n--) {
|
|
tbl_inst->elems[i] = fill_val;
|
|
}
|
|
|
|
break;
|
|
}
|
|
#endif /* WASM_ENABLE_REF_TYPES */
|
|
default:
|
|
wasm_set_exception(module, "unsupported opcode");
|
|
goto got_exception;
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
#if WASM_ENABLE_SHARED_MEMORY != 0
|
|
HANDLE_OP(WASM_OP_ATOMIC_PREFIX)
|
|
{
|
|
uint32 offset = 0, addr;
|
|
|
|
GET_OPCODE();
|
|
|
|
if (opcode != WASM_OP_ATOMIC_FENCE) {
|
|
offset = read_uint32(frame_ip);
|
|
}
|
|
|
|
switch (opcode) {
|
|
case WASM_OP_ATOMIC_NOTIFY:
|
|
{
|
|
uint32 notify_count, ret;
|
|
|
|
notify_count = POP_I32();
|
|
addr = POP_I32();
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(4);
|
|
|
|
ret = wasm_runtime_atomic_notify(
|
|
(WASMModuleInstanceCommon *)module, maddr,
|
|
notify_count);
|
|
if (ret == (uint32)-1)
|
|
goto got_exception;
|
|
|
|
PUSH_I32(ret);
|
|
break;
|
|
}
|
|
case WASM_OP_ATOMIC_WAIT32:
|
|
{
|
|
uint64 timeout;
|
|
uint32 expect, ret;
|
|
|
|
timeout = POP_I64();
|
|
expect = POP_I32();
|
|
addr = POP_I32();
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(4);
|
|
|
|
ret = wasm_runtime_atomic_wait(
|
|
(WASMModuleInstanceCommon *)module, maddr,
|
|
(uint64)expect, timeout, false);
|
|
if (ret == (uint32)-1)
|
|
goto got_exception;
|
|
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
|
|
PUSH_I32(ret);
|
|
break;
|
|
}
|
|
case WASM_OP_ATOMIC_WAIT64:
|
|
{
|
|
uint64 timeout, expect;
|
|
uint32 ret;
|
|
|
|
timeout = POP_I64();
|
|
expect = POP_I64();
|
|
addr = POP_I32();
|
|
CHECK_MEMORY_OVERFLOW(8);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(8);
|
|
|
|
ret = wasm_runtime_atomic_wait(
|
|
(WASMModuleInstanceCommon *)module, maddr, expect,
|
|
timeout, true);
|
|
if (ret == (uint32)-1)
|
|
goto got_exception;
|
|
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
|
|
PUSH_I32(ret);
|
|
break;
|
|
}
|
|
case WASM_OP_ATOMIC_FENCE:
|
|
{
|
|
os_atomic_thread_fence(os_memory_order_seq_cst);
|
|
break;
|
|
}
|
|
|
|
case WASM_OP_ATOMIC_I32_LOAD:
|
|
case WASM_OP_ATOMIC_I32_LOAD8_U:
|
|
case WASM_OP_ATOMIC_I32_LOAD16_U:
|
|
{
|
|
uint32 readv;
|
|
|
|
addr = POP_I32();
|
|
|
|
if (opcode == WASM_OP_ATOMIC_I32_LOAD8_U) {
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(1);
|
|
shared_memory_lock(memory);
|
|
readv = (uint32)(*(uint8 *)maddr);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else if (opcode == WASM_OP_ATOMIC_I32_LOAD16_U) {
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(2);
|
|
shared_memory_lock(memory);
|
|
readv = (uint32)LOAD_U16(maddr);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else {
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(4);
|
|
shared_memory_lock(memory);
|
|
readv = LOAD_I32(maddr);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
|
|
PUSH_I32(readv);
|
|
break;
|
|
}
|
|
|
|
case WASM_OP_ATOMIC_I64_LOAD:
|
|
case WASM_OP_ATOMIC_I64_LOAD8_U:
|
|
case WASM_OP_ATOMIC_I64_LOAD16_U:
|
|
case WASM_OP_ATOMIC_I64_LOAD32_U:
|
|
{
|
|
uint64 readv;
|
|
|
|
addr = POP_I32();
|
|
|
|
if (opcode == WASM_OP_ATOMIC_I64_LOAD8_U) {
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(1);
|
|
shared_memory_lock(memory);
|
|
readv = (uint64)(*(uint8 *)maddr);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else if (opcode == WASM_OP_ATOMIC_I64_LOAD16_U) {
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(2);
|
|
shared_memory_lock(memory);
|
|
readv = (uint64)LOAD_U16(maddr);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else if (opcode == WASM_OP_ATOMIC_I64_LOAD32_U) {
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(4);
|
|
shared_memory_lock(memory);
|
|
readv = (uint64)LOAD_U32(maddr);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else {
|
|
CHECK_MEMORY_OVERFLOW(8);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(8);
|
|
shared_memory_lock(memory);
|
|
readv = LOAD_I64(maddr);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
|
|
PUSH_I64(readv);
|
|
break;
|
|
}
|
|
case WASM_OP_ATOMIC_I32_STORE:
|
|
case WASM_OP_ATOMIC_I32_STORE8:
|
|
case WASM_OP_ATOMIC_I32_STORE16:
|
|
{
|
|
uint32 sval;
|
|
|
|
sval = (uint32)POP_I32();
|
|
addr = POP_I32();
|
|
|
|
if (opcode == WASM_OP_ATOMIC_I32_STORE8) {
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(1);
|
|
shared_memory_lock(memory);
|
|
*(uint8 *)maddr = (uint8)sval;
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else if (opcode == WASM_OP_ATOMIC_I32_STORE16) {
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(2);
|
|
shared_memory_lock(memory);
|
|
STORE_U16(maddr, (uint16)sval);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else {
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(4);
|
|
shared_memory_lock(memory);
|
|
STORE_U32(maddr, sval);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case WASM_OP_ATOMIC_I64_STORE:
|
|
case WASM_OP_ATOMIC_I64_STORE8:
|
|
case WASM_OP_ATOMIC_I64_STORE16:
|
|
case WASM_OP_ATOMIC_I64_STORE32:
|
|
{
|
|
uint64 sval;
|
|
|
|
sval = (uint64)POP_I64();
|
|
addr = POP_I32();
|
|
|
|
if (opcode == WASM_OP_ATOMIC_I64_STORE8) {
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(1);
|
|
shared_memory_lock(memory);
|
|
*(uint8 *)maddr = (uint8)sval;
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else if (opcode == WASM_OP_ATOMIC_I64_STORE16) {
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(2);
|
|
shared_memory_lock(memory);
|
|
STORE_U16(maddr, (uint16)sval);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else if (opcode == WASM_OP_ATOMIC_I64_STORE32) {
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(4);
|
|
shared_memory_lock(memory);
|
|
STORE_U32(maddr, (uint32)sval);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else {
|
|
CHECK_MEMORY_OVERFLOW(8);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(8);
|
|
shared_memory_lock(memory);
|
|
STORE_I64(maddr, sval);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case WASM_OP_ATOMIC_RMW_I32_CMPXCHG:
|
|
case WASM_OP_ATOMIC_RMW_I32_CMPXCHG8_U:
|
|
case WASM_OP_ATOMIC_RMW_I32_CMPXCHG16_U:
|
|
{
|
|
uint32 readv, sval, expect;
|
|
|
|
sval = POP_I32();
|
|
expect = POP_I32();
|
|
addr = POP_I32();
|
|
|
|
if (opcode == WASM_OP_ATOMIC_RMW_I32_CMPXCHG8_U) {
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(1);
|
|
|
|
expect = (uint8)expect;
|
|
shared_memory_lock(memory);
|
|
readv = (uint32)(*(uint8 *)maddr);
|
|
if (readv == expect)
|
|
*(uint8 *)maddr = (uint8)(sval);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else if (opcode == WASM_OP_ATOMIC_RMW_I32_CMPXCHG16_U) {
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(2);
|
|
|
|
expect = (uint16)expect;
|
|
shared_memory_lock(memory);
|
|
readv = (uint32)LOAD_U16(maddr);
|
|
if (readv == expect)
|
|
STORE_U16(maddr, (uint16)(sval));
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else {
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(4);
|
|
|
|
shared_memory_lock(memory);
|
|
readv = LOAD_I32(maddr);
|
|
if (readv == expect)
|
|
STORE_U32(maddr, sval);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
PUSH_I32(readv);
|
|
break;
|
|
}
|
|
case WASM_OP_ATOMIC_RMW_I64_CMPXCHG:
|
|
case WASM_OP_ATOMIC_RMW_I64_CMPXCHG8_U:
|
|
case WASM_OP_ATOMIC_RMW_I64_CMPXCHG16_U:
|
|
case WASM_OP_ATOMIC_RMW_I64_CMPXCHG32_U:
|
|
{
|
|
uint64 readv, sval, expect;
|
|
|
|
sval = (uint64)POP_I64();
|
|
expect = (uint64)POP_I64();
|
|
addr = POP_I32();
|
|
|
|
if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG8_U) {
|
|
CHECK_MEMORY_OVERFLOW(1);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(1);
|
|
|
|
expect = (uint8)expect;
|
|
shared_memory_lock(memory);
|
|
readv = (uint64)(*(uint8 *)maddr);
|
|
if (readv == expect)
|
|
*(uint8 *)maddr = (uint8)(sval);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG16_U) {
|
|
CHECK_MEMORY_OVERFLOW(2);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(2);
|
|
|
|
expect = (uint16)expect;
|
|
shared_memory_lock(memory);
|
|
readv = (uint64)LOAD_U16(maddr);
|
|
if (readv == expect)
|
|
STORE_U16(maddr, (uint16)(sval));
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG32_U) {
|
|
CHECK_MEMORY_OVERFLOW(4);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(4);
|
|
|
|
expect = (uint32)expect;
|
|
shared_memory_lock(memory);
|
|
readv = (uint64)LOAD_U32(maddr);
|
|
if (readv == expect)
|
|
STORE_U32(maddr, (uint32)(sval));
|
|
shared_memory_unlock(memory);
|
|
}
|
|
else {
|
|
CHECK_MEMORY_OVERFLOW(8);
|
|
CHECK_ATOMIC_MEMORY_ACCESS(8);
|
|
|
|
shared_memory_lock(memory);
|
|
readv = (uint64)LOAD_I64(maddr);
|
|
if (readv == expect)
|
|
STORE_I64(maddr, sval);
|
|
shared_memory_unlock(memory);
|
|
}
|
|
PUSH_I64(readv);
|
|
break;
|
|
}
|
|
|
|
DEF_ATOMIC_RMW_OPCODE(ADD, +);
|
|
DEF_ATOMIC_RMW_OPCODE(SUB, -);
|
|
DEF_ATOMIC_RMW_OPCODE(AND, &);
|
|
DEF_ATOMIC_RMW_OPCODE(OR, |);
|
|
DEF_ATOMIC_RMW_OPCODE(XOR, ^);
|
|
/* xchg, ignore the read value, and store the given
|
|
value: readv * 0 + sval */
|
|
DEF_ATOMIC_RMW_OPCODE(XCHG, *0 +);
|
|
}
|
|
|
|
HANDLE_OP_END();
|
|
}
|
|
#endif
|
|
|
|
HANDLE_OP(WASM_OP_IMPDEP)
|
|
{
|
|
frame = prev_frame;
|
|
frame_ip = frame->ip;
|
|
#if WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0
|
|
is_return_call = false;
|
|
#endif
|
|
goto call_func_from_entry;
|
|
}
|
|
#if WASM_ENABLE_SIMDE != 0
|
|
#define SIMD_V128_TO_SIMDE_V128(s_v) \
|
|
({ \
|
|
bh_assert(sizeof(V128) == sizeof(simde_v128_t)); \
|
|
simde_v128_t se_v; \
|
|
bh_memcpy_s(&se_v, sizeof(simde_v128_t), &(s_v), sizeof(V128)); \
|
|
se_v; \
|
|
})
|
|
|
|
#define SIMDE_V128_TO_SIMD_V128(sv, v) \
|
|
do { \
|
|
bh_assert(sizeof(V128) == sizeof(simde_v128_t)); \
|
|
bh_memcpy_s(&(v), sizeof(V128), &(sv), sizeof(simde_v128_t)); \
|
|
} while (0)
|
|
|
|
HANDLE_OP(WASM_OP_SIMD_PREFIX)
|
|
{
|
|
GET_OPCODE();
|
|
|
|
switch (opcode) {
|
|
/* Memory */
|
|
case SIMD_v128_load:
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
addr = POP_I32();
|
|
addr_ret = GET_OFFSET();
|
|
CHECK_MEMORY_OVERFLOW(16);
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, LOAD_V128(maddr));
|
|
break;
|
|
}
|
|
#define SIMD_LOAD_OP(simde_func) \
|
|
do { \
|
|
uint32 offset, addr; \
|
|
offset = read_uint32(frame_ip); \
|
|
addr = POP_I32(); \
|
|
addr_ret = GET_OFFSET(); \
|
|
CHECK_MEMORY_OVERFLOW(8); \
|
|
\
|
|
simde_v128_t simde_result = simde_func(maddr); \
|
|
\
|
|
V128 result; \
|
|
SIMDE_V128_TO_SIMD_V128(simde_result, result); \
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \
|
|
\
|
|
} while (0)
|
|
case SIMD_v128_load8x8_s:
|
|
{
|
|
SIMD_LOAD_OP(simde_wasm_i16x8_load8x8);
|
|
break;
|
|
}
|
|
case SIMD_v128_load8x8_u:
|
|
{
|
|
SIMD_LOAD_OP(simde_wasm_u16x8_load8x8);
|
|
break;
|
|
}
|
|
case SIMD_v128_load16x4_s:
|
|
{
|
|
SIMD_LOAD_OP(simde_wasm_i32x4_load16x4);
|
|
break;
|
|
}
|
|
case SIMD_v128_load16x4_u:
|
|
{
|
|
SIMD_LOAD_OP(simde_wasm_u32x4_load16x4);
|
|
break;
|
|
}
|
|
case SIMD_v128_load32x2_s:
|
|
{
|
|
SIMD_LOAD_OP(simde_wasm_i64x2_load32x2);
|
|
break;
|
|
}
|
|
case SIMD_v128_load32x2_u:
|
|
{
|
|
SIMD_LOAD_OP(simde_wasm_u64x2_load32x2);
|
|
break;
|
|
}
|
|
#define SIMD_LOAD_SPLAT_OP(simde_func, width) \
|
|
do { \
|
|
uint32 offset, addr; \
|
|
offset = read_uint32(frame_ip); \
|
|
addr = POP_I32(); \
|
|
addr_ret = GET_OFFSET(); \
|
|
CHECK_MEMORY_OVERFLOW(width / 8); \
|
|
\
|
|
simde_v128_t simde_result = simde_func(maddr); \
|
|
\
|
|
V128 result; \
|
|
SIMDE_V128_TO_SIMD_V128(simde_result, result); \
|
|
\
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \
|
|
} while (0)
|
|
|
|
case SIMD_v128_load8_splat:
|
|
{
|
|
SIMD_LOAD_SPLAT_OP(simde_wasm_v128_load8_splat, 8);
|
|
break;
|
|
}
|
|
case SIMD_v128_load16_splat:
|
|
{
|
|
SIMD_LOAD_SPLAT_OP(simde_wasm_v128_load16_splat, 16);
|
|
break;
|
|
}
|
|
case SIMD_v128_load32_splat:
|
|
{
|
|
SIMD_LOAD_SPLAT_OP(simde_wasm_v128_load32_splat, 32);
|
|
break;
|
|
}
|
|
case SIMD_v128_load64_splat:
|
|
{
|
|
SIMD_LOAD_SPLAT_OP(simde_wasm_v128_load64_splat, 64);
|
|
break;
|
|
}
|
|
case SIMD_v128_store:
|
|
{
|
|
uint32 offset, addr;
|
|
offset = read_uint32(frame_ip);
|
|
V128 data = POP_V128();
|
|
addr = POP_I32();
|
|
|
|
CHECK_MEMORY_OVERFLOW(16);
|
|
STORE_V128(maddr, data);
|
|
break;
|
|
}
|
|
|
|
/* Basic */
|
|
case SIMD_v128_const:
|
|
{
|
|
uint8 *orig_ip = frame_ip;
|
|
|
|
frame_ip += sizeof(V128);
|
|
addr_ret = GET_OFFSET();
|
|
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, *(V128 *)orig_ip);
|
|
break;
|
|
}
|
|
/* TODO: Add a faster SIMD implementation */
|
|
case SIMD_v8x16_shuffle:
|
|
{
|
|
V128 indices;
|
|
bh_memcpy_s(&indices, sizeof(V128), frame_ip,
|
|
sizeof(V128));
|
|
frame_ip += sizeof(V128);
|
|
|
|
V128 v2 = POP_V128();
|
|
V128 v1 = POP_V128();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
V128 result;
|
|
for (int i = 0; i < 16; i++) {
|
|
uint8_t index = indices.i8x16[i];
|
|
if (index < 16) {
|
|
result.i8x16[i] = v1.i8x16[index];
|
|
}
|
|
else {
|
|
result.i8x16[i] = v2.i8x16[index - 16];
|
|
}
|
|
}
|
|
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result);
|
|
break;
|
|
}
|
|
case SIMD_v8x16_swizzle:
|
|
{
|
|
V128 v2 = POP_V128();
|
|
V128 v1 = POP_V128();
|
|
addr_ret = GET_OFFSET();
|
|
simde_v128_t simde_result = simde_wasm_i8x16_swizzle(
|
|
SIMD_V128_TO_SIMDE_V128(v1),
|
|
SIMD_V128_TO_SIMDE_V128(v2));
|
|
|
|
V128 result;
|
|
SIMDE_V128_TO_SIMD_V128(simde_result, result);
|
|
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result);
|
|
break;
|
|
}
|
|
|
|
/* Splat */
|
|
#define SIMD_SPLAT_OP(simde_func, pop_func, val_type) \
|
|
do { \
|
|
val_type v = pop_func(); \
|
|
addr_ret = GET_OFFSET(); \
|
|
\
|
|
simde_v128_t simde_result = simde_func(v); \
|
|
\
|
|
V128 result; \
|
|
SIMDE_V128_TO_SIMD_V128(simde_result, result); \
|
|
\
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \
|
|
} while (0)
|
|
|
|
#define SIMD_SPLAT_OP_I32(simde_func) SIMD_SPLAT_OP(simde_func, POP_I32, uint32)
|
|
#define SIMD_SPLAT_OP_I64(simde_func) SIMD_SPLAT_OP(simde_func, POP_I64, uint64)
|
|
#define SIMD_SPLAT_OP_F32(simde_func) \
|
|
SIMD_SPLAT_OP(simde_func, POP_F32, float32)
|
|
#define SIMD_SPLAT_OP_F64(simde_func) \
|
|
SIMD_SPLAT_OP(simde_func, POP_F64, float64)
|
|
|
|
case SIMD_i8x16_splat:
|
|
{
|
|
val = POP_I32();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
simde_v128_t simde_result = simde_wasm_i8x16_splat(val);
|
|
|
|
V128 result;
|
|
SIMDE_V128_TO_SIMD_V128(simde_result, result);
|
|
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_splat:
|
|
{
|
|
SIMD_SPLAT_OP_I32(simde_wasm_i16x8_splat);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_splat:
|
|
{
|
|
SIMD_SPLAT_OP_I32(simde_wasm_i32x4_splat);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_splat:
|
|
{
|
|
SIMD_SPLAT_OP_I64(simde_wasm_i64x2_splat);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_splat:
|
|
{
|
|
SIMD_SPLAT_OP_F32(simde_wasm_f32x4_splat);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_splat:
|
|
{
|
|
SIMD_SPLAT_OP_F64(simde_wasm_f64x2_splat);
|
|
break;
|
|
}
|
|
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
|
|
#define SIMD_LANE_HANDLE_UNALIGNED_ACCESS()
|
|
#else
|
|
#define SIMD_LANE_HANDLE_UNALIGNED_ACCESS() (void)*frame_ip++
|
|
#endif /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */
|
|
|
|
#define SIMD_EXTRACT_LANE_OP(register, return_type, push_elem) \
|
|
do { \
|
|
uint8 lane = *frame_ip++; \
|
|
SIMD_LANE_HANDLE_UNALIGNED_ACCESS(); \
|
|
V128 v = POP_V128(); \
|
|
push_elem((return_type)(v.register[lane])); \
|
|
} while (0)
|
|
#define SIMD_REPLACE_LANE_OP(register, return_type, pop_elem) \
|
|
do { \
|
|
uint8 lane = *frame_ip++; \
|
|
SIMD_LANE_HANDLE_UNALIGNED_ACCESS(); \
|
|
return_type replacement = pop_elem(); \
|
|
V128 v = POP_V128(); \
|
|
v.register[lane] = replacement; \
|
|
addr_ret = GET_OFFSET(); \
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, v); \
|
|
} while (0)
|
|
case SIMD_i8x16_extract_lane_s:
|
|
{
|
|
SIMD_EXTRACT_LANE_OP(i8x16, int8, PUSH_I32);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_extract_lane_u:
|
|
{
|
|
SIMD_EXTRACT_LANE_OP(i8x16, uint8, PUSH_I32);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_replace_lane:
|
|
{
|
|
SIMD_REPLACE_LANE_OP(i8x16, int8, POP_I32);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extract_lane_s:
|
|
{
|
|
SIMD_EXTRACT_LANE_OP(i16x8, int16, PUSH_I32);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extract_lane_u:
|
|
{
|
|
SIMD_EXTRACT_LANE_OP(i16x8, uint16, PUSH_I32);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_replace_lane:
|
|
{
|
|
SIMD_REPLACE_LANE_OP(i16x8, int16, POP_I32);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extract_lane:
|
|
{
|
|
SIMD_EXTRACT_LANE_OP(i32x4, int32, PUSH_I32);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_replace_lane:
|
|
{
|
|
SIMD_REPLACE_LANE_OP(i32x4, int32, POP_I32);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_extract_lane:
|
|
{
|
|
SIMD_EXTRACT_LANE_OP(i64x2, int64, PUSH_I64);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_replace_lane:
|
|
{
|
|
SIMD_REPLACE_LANE_OP(i64x2, int64, POP_I64);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_extract_lane:
|
|
{
|
|
SIMD_EXTRACT_LANE_OP(f32x4, float32, PUSH_F32);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_replace_lane:
|
|
{
|
|
SIMD_REPLACE_LANE_OP(f32x4, float32, POP_F32);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_extract_lane:
|
|
{
|
|
SIMD_EXTRACT_LANE_OP(f64x2, float64, PUSH_F64);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_replace_lane:
|
|
{
|
|
SIMD_REPLACE_LANE_OP(f64x2, float64, POP_F64);
|
|
break;
|
|
}
|
|
|
|
#define SIMD_DOUBLE_OP(simde_func) \
|
|
do { \
|
|
V128 v2 = POP_V128(); \
|
|
V128 v1 = POP_V128(); \
|
|
addr_ret = GET_OFFSET(); \
|
|
\
|
|
simde_v128_t simde_result = simde_func(SIMD_V128_TO_SIMDE_V128(v1), \
|
|
SIMD_V128_TO_SIMDE_V128(v2)); \
|
|
\
|
|
V128 result; \
|
|
SIMDE_V128_TO_SIMD_V128(simde_result, result); \
|
|
\
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \
|
|
} while (0)
|
|
|
|
/* i8x16 comparison operations */
|
|
case SIMD_i8x16_eq:
|
|
{
|
|
V128 v2 = POP_V128();
|
|
V128 v1 = POP_V128();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
simde_v128_t simde_result =
|
|
simde_wasm_i8x16_eq(SIMD_V128_TO_SIMDE_V128(v1),
|
|
SIMD_V128_TO_SIMDE_V128(v2));
|
|
|
|
V128 result;
|
|
SIMDE_V128_TO_SIMD_V128(simde_result, result);
|
|
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_ne:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_ne);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_lt_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_lt);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_lt_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u8x16_lt);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_gt_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_gt);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_gt_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u8x16_gt);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_le_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_le);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_le_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u8x16_le);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_ge_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_ge);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_ge_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u8x16_ge);
|
|
break;
|
|
}
|
|
|
|
/* i16x8 comparison operations */
|
|
case SIMD_i16x8_eq:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_eq);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_ne:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_ne);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_lt_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_lt);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_lt_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_lt);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_gt_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_gt);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_gt_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_gt);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_le_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_le);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_le_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_le);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_ge_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_ge);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_ge_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_ge);
|
|
break;
|
|
}
|
|
|
|
/* i32x4 comparison operations */
|
|
case SIMD_i32x4_eq:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_eq);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_ne:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_ne);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_lt_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_lt);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_lt_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u32x4_lt);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_gt_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_gt);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_gt_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u32x4_gt);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_le_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_le);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_le_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u32x4_le);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_ge_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_ge);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_ge_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u32x4_ge);
|
|
break;
|
|
}
|
|
|
|
/* f32x4 comparison operations */
|
|
case SIMD_f32x4_eq:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_eq);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_ne:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_ne);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_lt:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_lt);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_gt:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_gt);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_le:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_le);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_ge:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_ge);
|
|
break;
|
|
}
|
|
|
|
/* f64x2 comparison operations */
|
|
case SIMD_f64x2_eq:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_eq);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_ne:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_ne);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_lt:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_lt);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_gt:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_gt);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_le:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_le);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_ge:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_ge);
|
|
break;
|
|
}
|
|
|
|
/* v128 bitwise operations */
|
|
#define SIMD_V128_BITWISE_OP_COMMON(result_expr_0, result_expr_1) \
|
|
do { \
|
|
V128 result; \
|
|
result.i64x2[0] = (result_expr_0); \
|
|
result.i64x2[1] = (result_expr_1); \
|
|
addr_ret = GET_OFFSET(); \
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \
|
|
} while (0)
|
|
|
|
case SIMD_v128_not:
|
|
{
|
|
V128 value = POP_V128();
|
|
SIMD_V128_BITWISE_OP_COMMON(~value.i64x2[0],
|
|
~value.i64x2[1]);
|
|
break;
|
|
}
|
|
case SIMD_v128_and:
|
|
{
|
|
V128 v2 = POP_V128();
|
|
V128 v1 = POP_V128();
|
|
SIMD_V128_BITWISE_OP_COMMON(v1.i64x2[0] & v2.i64x2[0],
|
|
v1.i64x2[1] & v2.i64x2[1]);
|
|
break;
|
|
}
|
|
case SIMD_v128_andnot:
|
|
{
|
|
V128 v2 = POP_V128();
|
|
V128 v1 = POP_V128();
|
|
SIMD_V128_BITWISE_OP_COMMON(
|
|
v1.i64x2[0] & (~v2.i64x2[0]),
|
|
v1.i64x2[1] & (~v2.i64x2[1]));
|
|
break;
|
|
}
|
|
case SIMD_v128_or:
|
|
{
|
|
V128 v2 = POP_V128();
|
|
V128 v1 = POP_V128();
|
|
SIMD_V128_BITWISE_OP_COMMON(v1.i64x2[0] | v2.i64x2[0],
|
|
v1.i64x2[1] | v2.i64x2[1]);
|
|
break;
|
|
}
|
|
case SIMD_v128_xor:
|
|
{
|
|
V128 v2 = POP_V128();
|
|
V128 v1 = POP_V128();
|
|
SIMD_V128_BITWISE_OP_COMMON(v1.i64x2[0] ^ v2.i64x2[0],
|
|
v1.i64x2[1] ^ v2.i64x2[1]);
|
|
break;
|
|
}
|
|
case SIMD_v128_bitselect:
|
|
{
|
|
V128 v1 = POP_V128();
|
|
V128 v2 = POP_V128();
|
|
V128 v3 = POP_V128();
|
|
addr_ret = GET_OFFSET();
|
|
|
|
simde_v128_t simde_result = simde_wasm_v128_bitselect(
|
|
SIMD_V128_TO_SIMDE_V128(v3),
|
|
SIMD_V128_TO_SIMDE_V128(v2),
|
|
SIMD_V128_TO_SIMDE_V128(v1));
|
|
|
|
V128 result;
|
|
SIMDE_V128_TO_SIMD_V128(simde_result, result);
|
|
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result);
|
|
break;
|
|
}
|
|
case SIMD_v128_any_true:
|
|
{
|
|
V128 value = POP_V128();
|
|
addr_ret = GET_OFFSET();
|
|
frame_lp[addr_ret] =
|
|
value.i64x2[0] != 0 || value.i64x2[1] != 0;
|
|
break;
|
|
}
|
|
|
|
#define SIMD_LOAD_LANE_COMMON(vec, register, lane, width) \
|
|
do { \
|
|
addr_ret = GET_OFFSET(); \
|
|
CHECK_MEMORY_OVERFLOW(width / 8); \
|
|
if (width == 64) { \
|
|
vec.register[lane] = GET_I64_FROM_ADDR((uint32 *)maddr); \
|
|
} \
|
|
else { \
|
|
vec.register[lane] = *(uint##width *)(maddr); \
|
|
} \
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, vec); \
|
|
} while (0)
|
|
|
|
#define SIMD_LOAD_LANE_OP(register, width) \
|
|
do { \
|
|
uint32 offset, addr; \
|
|
offset = read_uint32(frame_ip); \
|
|
V128 vec = POP_V128(); \
|
|
addr = POP_I32(); \
|
|
int lane = *frame_ip++; \
|
|
SIMD_LANE_HANDLE_UNALIGNED_ACCESS(); \
|
|
SIMD_LOAD_LANE_COMMON(vec, register, lane, width); \
|
|
} while (0)
|
|
|
|
case SIMD_v128_load8_lane:
|
|
{
|
|
SIMD_LOAD_LANE_OP(i8x16, 8);
|
|
break;
|
|
}
|
|
case SIMD_v128_load16_lane:
|
|
{
|
|
SIMD_LOAD_LANE_OP(i16x8, 16);
|
|
break;
|
|
}
|
|
case SIMD_v128_load32_lane:
|
|
{
|
|
SIMD_LOAD_LANE_OP(i32x4, 32);
|
|
break;
|
|
}
|
|
case SIMD_v128_load64_lane:
|
|
{
|
|
SIMD_LOAD_LANE_OP(i64x2, 64);
|
|
break;
|
|
}
|
|
#define SIMD_STORE_LANE_OP(register, width) \
|
|
do { \
|
|
uint32 offset, addr; \
|
|
offset = read_uint32(frame_ip); \
|
|
V128 vec = POP_V128(); \
|
|
addr = POP_I32(); \
|
|
int lane = *frame_ip++; \
|
|
SIMD_LANE_HANDLE_UNALIGNED_ACCESS(); \
|
|
CHECK_MEMORY_OVERFLOW(width / 8); \
|
|
if (width == 64) { \
|
|
STORE_I64(maddr, vec.register[lane]); \
|
|
} \
|
|
else { \
|
|
*(uint##width *)(maddr) = vec.register[lane]; \
|
|
} \
|
|
} while (0)
|
|
|
|
case SIMD_v128_store8_lane:
|
|
{
|
|
SIMD_STORE_LANE_OP(i8x16, 8);
|
|
break;
|
|
}
|
|
|
|
case SIMD_v128_store16_lane:
|
|
{
|
|
SIMD_STORE_LANE_OP(i16x8, 16);
|
|
break;
|
|
}
|
|
|
|
case SIMD_v128_store32_lane:
|
|
{
|
|
SIMD_STORE_LANE_OP(i32x4, 32);
|
|
break;
|
|
}
|
|
|
|
case SIMD_v128_store64_lane:
|
|
{
|
|
SIMD_STORE_LANE_OP(i64x2, 64);
|
|
break;
|
|
}
|
|
#define SIMD_LOAD_ZERO_OP(register, width) \
|
|
do { \
|
|
uint32 offset, addr; \
|
|
offset = read_uint32(frame_ip); \
|
|
addr = POP_I32(); \
|
|
int32 lane = 0; \
|
|
V128 vec = { 0 }; \
|
|
SIMD_LOAD_LANE_COMMON(vec, register, lane, width); \
|
|
} while (0)
|
|
|
|
case SIMD_v128_load32_zero:
|
|
{
|
|
SIMD_LOAD_ZERO_OP(i32x4, 32);
|
|
break;
|
|
}
|
|
case SIMD_v128_load64_zero:
|
|
{
|
|
SIMD_LOAD_ZERO_OP(i64x2, 64);
|
|
break;
|
|
}
|
|
|
|
#define SIMD_SINGLE_OP(simde_func) \
|
|
do { \
|
|
V128 v1 = POP_V128(); \
|
|
addr_ret = GET_OFFSET(); \
|
|
\
|
|
simde_v128_t simde_result = simde_func(SIMD_V128_TO_SIMDE_V128(v1)); \
|
|
\
|
|
V128 result; \
|
|
SIMDE_V128_TO_SIMD_V128(simde_result, result); \
|
|
\
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \
|
|
} while (0)
|
|
|
|
/* Float conversion */
|
|
case SIMD_f32x4_demote_f64x2_zero:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f32x4_demote_f64x2_zero);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_promote_low_f32x4_zero:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f64x2_promote_low_f32x4);
|
|
break;
|
|
}
|
|
|
|
/* i8x16 operations */
|
|
case SIMD_i8x16_abs:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i8x16_abs);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_neg:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i8x16_neg);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_popcnt:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i8x16_popcnt);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_all_true:
|
|
{
|
|
V128 v1 = POP_V128();
|
|
|
|
bool result = simde_wasm_i8x16_all_true(
|
|
SIMD_V128_TO_SIMDE_V128(v1));
|
|
|
|
addr_ret = GET_OFFSET();
|
|
frame_lp[addr_ret] = result;
|
|
break;
|
|
}
|
|
|
|
case SIMD_i8x16_bitmask:
|
|
{
|
|
V128 v1 = POP_V128();
|
|
|
|
uint32_t result = simde_wasm_i8x16_bitmask(
|
|
SIMD_V128_TO_SIMDE_V128(v1));
|
|
|
|
addr_ret = GET_OFFSET();
|
|
frame_lp[addr_ret] = result;
|
|
break;
|
|
}
|
|
case SIMD_i8x16_narrow_i16x8_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_narrow_i16x8);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_narrow_i16x8_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u8x16_narrow_i16x8);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_ceil:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f32x4_ceil);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_floor:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f32x4_floor);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_trunc:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f32x4_trunc);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_nearest:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f32x4_nearest);
|
|
break;
|
|
}
|
|
#define SIMD_LANE_SHIFT(simde_func) \
|
|
do { \
|
|
int32 c = POP_I32(); \
|
|
V128 v1 = POP_V128(); \
|
|
addr_ret = GET_OFFSET(); \
|
|
\
|
|
simde_v128_t simde_result = \
|
|
simde_func(SIMD_V128_TO_SIMDE_V128(v1), c); \
|
|
\
|
|
V128 result; \
|
|
SIMDE_V128_TO_SIMD_V128(simde_result, result); \
|
|
\
|
|
PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \
|
|
} while (0)
|
|
case SIMD_i8x16_shl:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_i8x16_shl);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_shr_s:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_i8x16_shr);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_shr_u:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_u8x16_shr);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_add:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_add);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_add_sat_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_add_sat);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_add_sat_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u8x16_add_sat);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_sub:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_sub);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_sub_sat_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_sub_sat);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_sub_sat_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u8x16_sub_sat);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_ceil:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f64x2_ceil);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_floor:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f64x2_floor);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_min_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_min);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_min_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u8x16_min);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_max_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i8x16_max);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_max_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u8x16_max);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_trunc:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f64x2_trunc);
|
|
break;
|
|
}
|
|
case SIMD_i8x16_avgr_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u8x16_avgr);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extadd_pairwise_i8x16_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i16x8_extadd_pairwise_i8x16);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extadd_pairwise_i8x16_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_u16x8_extadd_pairwise_u8x16);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extadd_pairwise_i16x8_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i32x4_extadd_pairwise_i16x8);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extadd_pairwise_i16x8_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_u32x4_extadd_pairwise_u16x8);
|
|
break;
|
|
}
|
|
|
|
/* i16x8 operations */
|
|
case SIMD_i16x8_abs:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i16x8_abs);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_neg:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i16x8_neg);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_q15mulr_sat_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_q15mulr_sat);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_all_true:
|
|
{
|
|
V128 v1 = POP_V128();
|
|
|
|
bool result = simde_wasm_i16x8_all_true(
|
|
SIMD_V128_TO_SIMDE_V128(v1));
|
|
|
|
addr_ret = GET_OFFSET();
|
|
frame_lp[addr_ret] = result;
|
|
break;
|
|
}
|
|
case SIMD_i16x8_bitmask:
|
|
{
|
|
V128 v1 = POP_V128();
|
|
|
|
uint32_t result = simde_wasm_i16x8_bitmask(
|
|
SIMD_V128_TO_SIMDE_V128(v1));
|
|
|
|
addr_ret = GET_OFFSET();
|
|
frame_lp[addr_ret] = result;
|
|
break;
|
|
}
|
|
case SIMD_i16x8_narrow_i32x4_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_narrow_i32x4);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_narrow_i32x4_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_narrow_i32x4);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extend_low_i8x16_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i16x8_extend_low_i8x16);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extend_high_i8x16_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i16x8_extend_high_i8x16);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extend_low_i8x16_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_u16x8_extend_low_u8x16);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extend_high_i8x16_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_u16x8_extend_high_u8x16);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_shl:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_i16x8_shl);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_shr_s:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_i16x8_shr);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_shr_u:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_u16x8_shr);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_add:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_add);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_add_sat_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_add_sat);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_add_sat_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_add_sat);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_sub:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_sub);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_sub_sat_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_sub_sat);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_sub_sat_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_sub_sat);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_nearest:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f64x2_nearest);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_mul:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_mul);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_min_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_min);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_min_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_min);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_max_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_max);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_max_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_max);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_avgr_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_avgr);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extmul_low_i8x16_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_extmul_low_i8x16);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extmul_high_i8x16_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i16x8_extmul_high_i8x16);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extmul_low_i8x16_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_extmul_low_u8x16);
|
|
break;
|
|
}
|
|
case SIMD_i16x8_extmul_high_i8x16_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u16x8_extmul_high_u8x16);
|
|
break;
|
|
}
|
|
|
|
/* i32x4 operations */
|
|
case SIMD_i32x4_abs:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i32x4_abs);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_neg:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i32x4_neg);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_all_true:
|
|
{
|
|
V128 v1 = POP_V128();
|
|
|
|
bool result = simde_wasm_i32x4_all_true(
|
|
SIMD_V128_TO_SIMDE_V128(v1));
|
|
|
|
addr_ret = GET_OFFSET();
|
|
frame_lp[addr_ret] = result;
|
|
break;
|
|
}
|
|
case SIMD_i32x4_bitmask:
|
|
{
|
|
V128 v1 = POP_V128();
|
|
|
|
uint32_t result = simde_wasm_i32x4_bitmask(
|
|
SIMD_V128_TO_SIMDE_V128(v1));
|
|
|
|
addr_ret = GET_OFFSET();
|
|
frame_lp[addr_ret] = result;
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extend_low_i16x8_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i32x4_extend_low_i16x8);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extend_high_i16x8_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i32x4_extend_high_i16x8);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extend_low_i16x8_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_u32x4_extend_low_u16x8);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extend_high_i16x8_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_u32x4_extend_high_u16x8);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_shl:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_i32x4_shl);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_shr_s:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_i32x4_shr);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_shr_u:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_u32x4_shr);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_add:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_add);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_sub:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_sub);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_mul:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_mul);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_min_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_min);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_min_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u32x4_min);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_max_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_max);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_max_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u32x4_max);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_dot_i16x8_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_dot_i16x8);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extmul_low_i16x8_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_extmul_low_i16x8);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extmul_high_i16x8_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i32x4_extmul_high_i16x8);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extmul_low_i16x8_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u32x4_extmul_low_u16x8);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_extmul_high_i16x8_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u32x4_extmul_high_u16x8);
|
|
break;
|
|
}
|
|
|
|
/* i64x2 operations */
|
|
case SIMD_i64x2_abs:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i64x2_abs);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_neg:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i64x2_neg);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_all_true:
|
|
{
|
|
V128 v1 = POP_V128();
|
|
|
|
bool result = simde_wasm_i64x2_all_true(
|
|
SIMD_V128_TO_SIMDE_V128(v1));
|
|
|
|
addr_ret = GET_OFFSET();
|
|
frame_lp[addr_ret] = result;
|
|
break;
|
|
}
|
|
case SIMD_i64x2_bitmask:
|
|
{
|
|
V128 v1 = POP_V128();
|
|
|
|
uint32_t result = simde_wasm_i64x2_bitmask(
|
|
SIMD_V128_TO_SIMDE_V128(v1));
|
|
|
|
addr_ret = GET_OFFSET();
|
|
frame_lp[addr_ret] = result;
|
|
break;
|
|
}
|
|
case SIMD_i64x2_extend_low_i32x4_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i64x2_extend_low_i32x4);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_extend_high_i32x4_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i64x2_extend_high_i32x4);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_extend_low_i32x4_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_u64x2_extend_low_u32x4);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_extend_high_i32x4_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_u64x2_extend_high_u32x4);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_shl:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_i64x2_shl);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_shr_s:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_i64x2_shr);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_shr_u:
|
|
{
|
|
SIMD_LANE_SHIFT(simde_wasm_u64x2_shr);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_add:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_add);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_sub:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_sub);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_mul:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_mul);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_eq:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_eq);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_ne:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_ne);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_lt_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_lt);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_gt_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_gt);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_le_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_le);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_ge_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_ge);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_extmul_low_i32x4_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_extmul_low_i32x4);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_extmul_high_i32x4_s:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_i64x2_extmul_high_i32x4);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_extmul_low_i32x4_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u64x2_extmul_low_u32x4);
|
|
break;
|
|
}
|
|
case SIMD_i64x2_extmul_high_i32x4_u:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_u64x2_extmul_high_u32x4);
|
|
break;
|
|
}
|
|
|
|
/* f32x4 opertions */
|
|
case SIMD_f32x4_abs:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f32x4_abs);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_neg:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f32x4_neg);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_sqrt:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f32x4_sqrt);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_add:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_add);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_sub:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_sub);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_mul:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_mul);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_div:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_div);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_min:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_min);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_max:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_max);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_pmin:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_pmin);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_pmax:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f32x4_pmax);
|
|
break;
|
|
}
|
|
|
|
/* f64x2 operations */
|
|
case SIMD_f64x2_abs:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f64x2_abs);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_neg:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f64x2_neg);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_sqrt:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f64x2_sqrt);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_add:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_add);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_sub:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_sub);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_mul:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_mul);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_div:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_div);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_min:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_min);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_max:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_max);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_pmin:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_pmin);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_pmax:
|
|
{
|
|
SIMD_DOUBLE_OP(simde_wasm_f64x2_pmax);
|
|
break;
|
|
}
|
|
|
|
/* Conversion operations */
|
|
case SIMD_i32x4_trunc_sat_f32x4_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i32x4_trunc_sat_f32x4);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_trunc_sat_f32x4_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_u32x4_trunc_sat_f32x4);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_convert_i32x4_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f32x4_convert_i32x4);
|
|
break;
|
|
}
|
|
case SIMD_f32x4_convert_i32x4_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f32x4_convert_u32x4);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_trunc_sat_f64x2_s_zero:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_i32x4_trunc_sat_f64x2_zero);
|
|
break;
|
|
}
|
|
case SIMD_i32x4_trunc_sat_f64x2_u_zero:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_u32x4_trunc_sat_f64x2_zero);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_convert_low_i32x4_s:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f64x2_convert_low_i32x4);
|
|
break;
|
|
}
|
|
case SIMD_f64x2_convert_low_i32x4_u:
|
|
{
|
|
SIMD_SINGLE_OP(simde_wasm_f64x2_convert_low_u32x4);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
wasm_set_exception(module, "unsupported SIMD opcode");
|
|
}
|
|
HANDLE_OP_END();
|
|
}
|
|
#endif
|
|
|
|
HANDLE_OP(WASM_OP_CALL)
|
|
{
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
fidx = read_uint32(frame_ip);
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
if (fidx >= module->e->function_count) {
|
|
wasm_set_exception(module, "unknown function");
|
|
goto got_exception;
|
|
}
|
|
#endif
|
|
cur_func = module->e->functions + fidx;
|
|
goto call_func_from_interp;
|
|
}
|
|
|
|
#if WASM_ENABLE_TAIL_CALL != 0
|
|
HANDLE_OP(WASM_OP_RETURN_CALL)
|
|
{
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
fidx = read_uint32(frame_ip);
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
if (fidx >= module->e->function_count) {
|
|
wasm_set_exception(module, "unknown function");
|
|
goto got_exception;
|
|
}
|
|
#endif
|
|
cur_func = module->e->functions + fidx;
|
|
goto call_func_from_return_call;
|
|
}
|
|
#endif /* WASM_ENABLE_TAIL_CALL */
|
|
|
|
#if WASM_ENABLE_LABELS_AS_VALUES == 0
|
|
default:
|
|
wasm_set_exception(module, "unsupported opcode");
|
|
goto got_exception;
|
|
}
|
|
#endif
|
|
|
|
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
|
HANDLE_OP(WASM_OP_UNUSED_0x0a)
|
|
#if WASM_ENABLE_TAIL_CALL == 0
|
|
HANDLE_OP(WASM_OP_RETURN_CALL)
|
|
HANDLE_OP(WASM_OP_RETURN_CALL_INDIRECT)
|
|
#endif
|
|
#if WASM_ENABLE_SHARED_MEMORY == 0
|
|
HANDLE_OP(WASM_OP_ATOMIC_PREFIX)
|
|
#endif
|
|
#if WASM_ENABLE_REF_TYPES == 0 && WASM_ENABLE_GC == 0
|
|
HANDLE_OP(WASM_OP_TABLE_GET)
|
|
HANDLE_OP(WASM_OP_TABLE_SET)
|
|
HANDLE_OP(WASM_OP_REF_NULL)
|
|
HANDLE_OP(WASM_OP_REF_IS_NULL)
|
|
HANDLE_OP(WASM_OP_REF_FUNC)
|
|
#endif
|
|
#if WASM_ENABLE_GC == 0
|
|
/* SELECT_T is converted to SELECT or SELECT_64 */
|
|
HANDLE_OP(WASM_OP_SELECT_T)
|
|
HANDLE_OP(WASM_OP_CALL_REF)
|
|
HANDLE_OP(WASM_OP_RETURN_CALL_REF)
|
|
HANDLE_OP(WASM_OP_REF_EQ)
|
|
HANDLE_OP(WASM_OP_REF_AS_NON_NULL)
|
|
HANDLE_OP(WASM_OP_BR_ON_NULL)
|
|
HANDLE_OP(WASM_OP_BR_ON_NON_NULL)
|
|
HANDLE_OP(WASM_OP_GC_PREFIX)
|
|
#endif
|
|
#if WASM_ENABLE_EXCE_HANDLING == 0
|
|
/* if exception handling is disabled, these opcodes issue a trap */
|
|
HANDLE_OP(WASM_OP_TRY)
|
|
HANDLE_OP(WASM_OP_CATCH)
|
|
HANDLE_OP(WASM_OP_THROW)
|
|
HANDLE_OP(WASM_OP_RETHROW)
|
|
HANDLE_OP(WASM_OP_DELEGATE)
|
|
HANDLE_OP(WASM_OP_CATCH_ALL)
|
|
HANDLE_OP(EXT_OP_TRY)
|
|
#endif
|
|
HANDLE_OP(WASM_OP_UNUSED_0x16)
|
|
HANDLE_OP(WASM_OP_UNUSED_0x17)
|
|
HANDLE_OP(WASM_OP_UNUSED_0x27)
|
|
/* optimized op code */
|
|
HANDLE_OP(WASM_OP_F32_STORE)
|
|
HANDLE_OP(WASM_OP_F64_STORE)
|
|
HANDLE_OP(WASM_OP_F32_LOAD)
|
|
HANDLE_OP(WASM_OP_F64_LOAD)
|
|
HANDLE_OP(EXT_OP_GET_LOCAL_FAST)
|
|
HANDLE_OP(WASM_OP_GET_LOCAL)
|
|
HANDLE_OP(WASM_OP_DROP)
|
|
HANDLE_OP(WASM_OP_DROP_64)
|
|
HANDLE_OP(WASM_OP_BLOCK)
|
|
HANDLE_OP(WASM_OP_LOOP)
|
|
HANDLE_OP(WASM_OP_END)
|
|
HANDLE_OP(WASM_OP_NOP)
|
|
HANDLE_OP(EXT_OP_BLOCK)
|
|
HANDLE_OP(EXT_OP_LOOP)
|
|
HANDLE_OP(EXT_OP_IF)
|
|
HANDLE_OP(EXT_OP_BR_TABLE_CACHE)
|
|
{
|
|
wasm_set_exception(module, "unsupported opcode");
|
|
goto got_exception;
|
|
}
|
|
#endif
|
|
|
|
#if WASM_ENABLE_LABELS_AS_VALUES == 0
|
|
continue;
|
|
#else
|
|
FETCH_OPCODE_AND_DISPATCH();
|
|
#endif
|
|
|
|
#if WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0
|
|
call_func_from_return_call:
|
|
{
|
|
uint32 *lp_base = NULL, *lp = NULL;
|
|
int i;
|
|
|
|
if (cur_func->param_cell_num > 0
|
|
&& !(lp_base = lp = wasm_runtime_malloc(cur_func->param_cell_num
|
|
* sizeof(uint32)))) {
|
|
wasm_set_exception(module, "allocate memory failed");
|
|
goto got_exception;
|
|
}
|
|
for (i = 0; i < cur_func->param_count; i++) {
|
|
if (cur_func->param_types[i] == VALUE_TYPE_I64
|
|
|| cur_func->param_types[i] == VALUE_TYPE_F64) {
|
|
PUT_I64_TO_ADDR(
|
|
lp, GET_OPERAND(uint64, I64,
|
|
2 * (cur_func->param_count - i - 1)));
|
|
lp += 2;
|
|
}
|
|
else {
|
|
*lp = GET_OPERAND(uint32, I32,
|
|
(2 * (cur_func->param_count - i - 1)));
|
|
lp++;
|
|
}
|
|
}
|
|
frame->lp = frame->operand + cur_func->const_cell_num;
|
|
if (lp - lp_base > 0) {
|
|
word_copy(frame->lp, lp_base, lp - lp_base);
|
|
}
|
|
if (lp_base)
|
|
wasm_runtime_free(lp_base);
|
|
FREE_FRAME(exec_env, frame);
|
|
frame_ip += cur_func->param_count * sizeof(int16);
|
|
wasm_exec_env_set_cur_frame(exec_env, (WASMRuntimeFrame *)prev_frame);
|
|
is_return_call = true;
|
|
goto call_func_from_entry;
|
|
}
|
|
#endif /* WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0 */
|
|
|
|
call_func_from_interp:
|
|
{
|
|
/* Only do the copy when it's called from interpreter. */
|
|
WASMInterpFrame *outs_area = wasm_exec_env_wasm_stack_top(exec_env);
|
|
int i;
|
|
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
if (cur_func->is_import_func) {
|
|
outs_area->lp = outs_area->operand
|
|
+ (cur_func->import_func_inst
|
|
? cur_func->import_func_inst->const_cell_num
|
|
: 0);
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
outs_area->lp = outs_area->operand + cur_func->const_cell_num;
|
|
}
|
|
|
|
if ((uint8 *)(outs_area->lp + cur_func->param_cell_num)
|
|
> exec_env->wasm_stack.top_boundary) {
|
|
wasm_set_exception(module, "wasm operand stack overflow");
|
|
goto got_exception;
|
|
}
|
|
|
|
for (i = 0; i < cur_func->param_count; i++) {
|
|
if (cur_func->param_types[i] == VALUE_TYPE_V128) {
|
|
PUT_V128_TO_ADDR(
|
|
outs_area->lp,
|
|
GET_OPERAND_V128(2 * (cur_func->param_count - i - 1)));
|
|
outs_area->lp += 4;
|
|
}
|
|
else if (cur_func->param_types[i] == VALUE_TYPE_I64
|
|
|| cur_func->param_types[i] == VALUE_TYPE_F64) {
|
|
PUT_I64_TO_ADDR(
|
|
outs_area->lp,
|
|
GET_OPERAND(uint64, I64,
|
|
2 * (cur_func->param_count - i - 1)));
|
|
outs_area->lp += 2;
|
|
}
|
|
#if WASM_ENABLE_GC != 0
|
|
else if (wasm_is_type_reftype(cur_func->param_types[i])) {
|
|
PUT_REF_TO_ADDR(
|
|
outs_area->lp,
|
|
GET_OPERAND(void *, REF,
|
|
2 * (cur_func->param_count - i - 1)));
|
|
CLEAR_FRAME_REF(
|
|
*(uint16 *)(frame_ip
|
|
+ (2 * (cur_func->param_count - i - 1))));
|
|
outs_area->lp += REF_CELL_NUM;
|
|
}
|
|
#endif
|
|
else {
|
|
*outs_area->lp = GET_OPERAND(
|
|
uint32, I32, (2 * (cur_func->param_count - i - 1)));
|
|
outs_area->lp++;
|
|
}
|
|
}
|
|
frame_ip += cur_func->param_count * sizeof(int16);
|
|
if (cur_func->ret_cell_num != 0) {
|
|
/* Get the first return value's offset. Since loader emit
|
|
* all return values' offset so we must skip remain return
|
|
* values' offsets.
|
|
*/
|
|
WASMFuncType *func_type;
|
|
if (cur_func->is_import_func)
|
|
func_type = cur_func->u.func_import->func_type;
|
|
else
|
|
func_type = cur_func->u.func->func_type;
|
|
frame->ret_offset = GET_OFFSET();
|
|
frame_ip += 2 * (func_type->result_count - 1);
|
|
}
|
|
SYNC_ALL_TO_FRAME();
|
|
prev_frame = frame;
|
|
#if WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0
|
|
is_return_call = false;
|
|
#endif
|
|
}
|
|
|
|
call_func_from_entry:
|
|
{
|
|
if (cur_func->is_import_func) {
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
if (cur_func->import_func_inst) {
|
|
wasm_interp_call_func_import(module, exec_env, cur_func,
|
|
prev_frame);
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
wasm_interp_call_func_native(module, exec_env, cur_func,
|
|
prev_frame);
|
|
}
|
|
|
|
#if WASM_ENABLE_TAIL_CALL != 0 || WASM_ENABLE_GC != 0
|
|
if (is_return_call) {
|
|
/* the frame was freed before tail calling and
|
|
the prev_frame was set as exec_env's cur_frame,
|
|
so here we recover context from prev_frame */
|
|
RECOVER_CONTEXT(prev_frame);
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
prev_frame = frame->prev_frame;
|
|
cur_func = frame->function;
|
|
UPDATE_ALL_FROM_FRAME();
|
|
}
|
|
|
|
/* update memory size, no need to update memory ptr as
|
|
it isn't changed in wasm_enlarge_memory */
|
|
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|
|
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|
|
|| WASM_ENABLE_BULK_MEMORY != 0
|
|
if (memory)
|
|
linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory);
|
|
#endif
|
|
if (wasm_copy_exception(module, NULL))
|
|
goto got_exception;
|
|
}
|
|
else {
|
|
WASMFunction *cur_wasm_func = cur_func->u.func;
|
|
uint32 cell_num_of_local_stack;
|
|
#if WASM_ENABLE_REF_TYPES != 0 && WASM_ENABLE_GC == 0
|
|
uint32 i, local_cell_idx;
|
|
#endif
|
|
|
|
cell_num_of_local_stack = cur_func->param_cell_num
|
|
+ cur_func->local_cell_num
|
|
+ cur_wasm_func->max_stack_cell_num;
|
|
all_cell_num = cur_func->const_cell_num + cell_num_of_local_stack;
|
|
#if WASM_ENABLE_GC != 0
|
|
/* area of frame_ref */
|
|
all_cell_num += (cell_num_of_local_stack + 3) / 4;
|
|
/* cells occupied by locals, POP_REF should not clear frame_ref for
|
|
* these cells */
|
|
local_cell_num =
|
|
cur_func->param_cell_num + cur_func->local_cell_num;
|
|
#endif
|
|
/* param_cell_num, local_cell_num, const_cell_num and
|
|
max_stack_cell_num are all no larger than UINT16_MAX (checked
|
|
in loader), all_cell_num must be smaller than 1MB */
|
|
bh_assert(all_cell_num < 1 * BH_MB);
|
|
|
|
frame_size = wasm_interp_interp_frame_size(all_cell_num);
|
|
if (!(frame = ALLOC_FRAME(exec_env, frame_size, prev_frame))) {
|
|
frame = prev_frame;
|
|
goto got_exception;
|
|
}
|
|
|
|
/* Initialize the interpreter context. */
|
|
frame->function = cur_func;
|
|
frame_ip = wasm_get_func_code(cur_func);
|
|
frame_ip_end = wasm_get_func_code_end(cur_func);
|
|
|
|
frame_lp = frame->lp =
|
|
frame->operand + cur_wasm_func->const_cell_num;
|
|
|
|
/* Initialize the consts */
|
|
if (cur_wasm_func->const_cell_num > 0) {
|
|
word_copy(frame->operand, (uint32 *)cur_wasm_func->consts,
|
|
cur_wasm_func->const_cell_num);
|
|
}
|
|
|
|
/* Initialize the local variables */
|
|
memset(frame_lp + cur_func->param_cell_num, 0,
|
|
(uint32)(cur_func->local_cell_num * 4));
|
|
|
|
#if WASM_ENABLE_REF_TYPES != 0 && WASM_ENABLE_GC == 0
|
|
/* externref/funcref should be NULL_REF rather than 0 */
|
|
local_cell_idx = cur_func->param_cell_num;
|
|
for (i = 0; i < cur_wasm_func->local_count; i++) {
|
|
if (cur_wasm_func->local_types[i] == VALUE_TYPE_EXTERNREF
|
|
|| cur_wasm_func->local_types[i] == VALUE_TYPE_FUNCREF) {
|
|
*(frame_lp + local_cell_idx) = NULL_REF;
|
|
}
|
|
local_cell_idx +=
|
|
wasm_value_type_cell_num(cur_wasm_func->local_types[i]);
|
|
}
|
|
#endif
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
/* frame->ip is used during GC root set enumeration, so we must
|
|
* initialized this field here */
|
|
frame->ip = frame_ip;
|
|
frame_ref = frame->frame_ref =
|
|
(uint8 *)(frame->lp + (uint32)cell_num_of_local_stack);
|
|
init_frame_refs(frame_ref, (uint32)cell_num_of_local_stack,
|
|
cur_func);
|
|
#endif
|
|
|
|
wasm_exec_env_set_cur_frame(exec_env, (WASMRuntimeFrame *)frame);
|
|
}
|
|
#if WASM_ENABLE_THREAD_MGR != 0
|
|
CHECK_SUSPEND_FLAGS();
|
|
#endif
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
return_func:
|
|
{
|
|
FREE_FRAME(exec_env, frame);
|
|
wasm_exec_env_set_cur_frame(exec_env, (WASMRuntimeFrame *)prev_frame);
|
|
|
|
if (!prev_frame->ip)
|
|
/* Called from native. */
|
|
return;
|
|
|
|
RECOVER_CONTEXT(prev_frame);
|
|
#if WASM_ENABLE_GC != 0
|
|
local_cell_num = cur_func->param_cell_num + cur_func->local_cell_num;
|
|
#endif
|
|
HANDLE_OP_END();
|
|
}
|
|
|
|
(void)frame_ip_end;
|
|
|
|
#if WASM_ENABLE_SHARED_MEMORY != 0
|
|
unaligned_atomic:
|
|
wasm_set_exception(module, "unaligned atomic");
|
|
goto got_exception;
|
|
#endif
|
|
|
|
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|
|
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|
|
|| WASM_ENABLE_BULK_MEMORY != 0
|
|
out_of_bounds:
|
|
wasm_set_exception(module, "out of bounds memory access");
|
|
#endif
|
|
|
|
got_exception:
|
|
SYNC_ALL_TO_FRAME();
|
|
return;
|
|
|
|
#if WASM_ENABLE_LABELS_AS_VALUES == 0
|
|
}
|
|
#else
|
|
FETCH_OPCODE_AND_DISPATCH();
|
|
#endif
|
|
}
|
|
|
|
#if WASM_ENABLE_LABELS_AS_VALUES != 0
|
|
void **
|
|
wasm_interp_get_handle_table(void)
|
|
{
|
|
WASMModuleInstance module;
|
|
memset(&module, 0, sizeof(WASMModuleInstance));
|
|
wasm_interp_call_func_bytecode(&module, NULL, NULL, NULL);
|
|
return global_handle_table;
|
|
}
|
|
#endif
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
bool
|
|
wasm_interp_traverse_gc_rootset(WASMExecEnv *exec_env, void *heap)
|
|
{
|
|
WASMInterpFrame *frame;
|
|
WASMObjectRef gc_obj;
|
|
WASMFunctionInstance *cur_func;
|
|
uint8 *frame_ref;
|
|
uint32 local_cell_num, i;
|
|
|
|
frame = wasm_exec_env_get_cur_frame(exec_env);
|
|
for (; frame; frame = frame->prev_frame) {
|
|
frame_ref = frame->frame_ref;
|
|
cur_func = frame->function;
|
|
|
|
if (!cur_func)
|
|
continue;
|
|
|
|
local_cell_num = cur_func->param_cell_num;
|
|
if (frame->ip)
|
|
local_cell_num +=
|
|
cur_func->local_cell_num + cur_func->u.func->max_stack_cell_num;
|
|
|
|
for (i = 0; i < local_cell_num; i++) {
|
|
if (frame_ref[i]) {
|
|
gc_obj = GET_REF_FROM_ADDR(frame->lp + i);
|
|
if (wasm_obj_is_created_from_heap(gc_obj)) {
|
|
if (mem_allocator_add_root((mem_allocator_t)heap, gc_obj)) {
|
|
return false;
|
|
}
|
|
}
|
|
#if UINTPTR_MAX == UINT64_MAX
|
|
bh_assert(frame_ref[i + 1]);
|
|
i++;
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
void
|
|
wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
|
|
WASMFunctionInstance *function, uint32 argc,
|
|
uint32 argv[])
|
|
{
|
|
WASMRuntimeFrame *prev_frame = wasm_exec_env_get_cur_frame(exec_env);
|
|
WASMInterpFrame *frame, *outs_area;
|
|
|
|
/* Allocate sufficient cells for all kinds of return values. */
|
|
unsigned all_cell_num =
|
|
function->ret_cell_num > 2 ? function->ret_cell_num : 2,
|
|
i;
|
|
/* This frame won't be used by JITed code, so only allocate interp
|
|
frame here. */
|
|
unsigned frame_size;
|
|
|
|
#if WASM_ENABLE_GC != 0
|
|
all_cell_num += (all_cell_num + 3) / 4;
|
|
#endif
|
|
|
|
frame_size = wasm_interp_interp_frame_size(all_cell_num);
|
|
|
|
if (argc < function->param_cell_num) {
|
|
char buf[128];
|
|
snprintf(buf, sizeof(buf),
|
|
"invalid argument count %" PRIu32
|
|
", must be no smaller than %" PRIu32,
|
|
argc, (uint32)function->param_cell_num);
|
|
wasm_set_exception(module_inst, buf);
|
|
return;
|
|
}
|
|
argc = function->param_cell_num;
|
|
|
|
#if defined(OS_ENABLE_HW_BOUND_CHECK) && WASM_DISABLE_STACK_HW_BOUND_CHECK == 0
|
|
/*
|
|
* wasm_runtime_detect_native_stack_overflow is done by
|
|
* call_wasm_with_hw_bound_check.
|
|
*/
|
|
#else
|
|
if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
if (!(frame =
|
|
ALLOC_FRAME(exec_env, frame_size, (WASMInterpFrame *)prev_frame)))
|
|
return;
|
|
|
|
outs_area = wasm_exec_env_wasm_stack_top(exec_env);
|
|
frame->function = NULL;
|
|
frame->ip = NULL;
|
|
/* There is no local variable. */
|
|
frame->lp = frame->operand + 0;
|
|
#if WASM_ENABLE_GC != 0
|
|
frame->frame_ref =
|
|
(uint8 *)(frame->lp
|
|
+ (function->ret_cell_num > 2 ? function->ret_cell_num : 2));
|
|
#endif
|
|
frame->ret_offset = 0;
|
|
|
|
if ((uint8 *)(outs_area->operand + function->const_cell_num + argc)
|
|
> exec_env->wasm_stack.top_boundary) {
|
|
wasm_set_exception((WASMModuleInstance *)exec_env->module_inst,
|
|
"wasm operand stack overflow");
|
|
return;
|
|
}
|
|
|
|
if (argc > 0)
|
|
word_copy(outs_area->operand + function->const_cell_num, argv, argc);
|
|
|
|
wasm_exec_env_set_cur_frame(exec_env, frame);
|
|
|
|
#if defined(os_writegsbase)
|
|
{
|
|
WASMMemoryInstance *memory_inst = wasm_get_default_memory(module_inst);
|
|
if (memory_inst)
|
|
/* write base addr of linear memory to GS segment register */
|
|
os_writegsbase(memory_inst->memory_data);
|
|
}
|
|
#endif
|
|
|
|
if (function->is_import_func) {
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
if (function->import_module_inst) {
|
|
LOG_DEBUG("it is a function of a sub module");
|
|
wasm_interp_call_func_import(module_inst, exec_env, function,
|
|
frame);
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
LOG_DEBUG("it is an native function");
|
|
wasm_interp_call_func_native(module_inst, exec_env, function,
|
|
frame);
|
|
}
|
|
}
|
|
else {
|
|
wasm_interp_call_func_bytecode(module_inst, exec_env, function, frame);
|
|
}
|
|
|
|
/* Output the return value to the caller */
|
|
if (!wasm_copy_exception(module_inst, NULL)) {
|
|
for (i = 0; i < function->ret_cell_num; i++)
|
|
argv[i] = *(frame->lp + i);
|
|
}
|
|
else {
|
|
#if WASM_ENABLE_DUMP_CALL_STACK != 0
|
|
if (wasm_interp_create_call_stack(exec_env)) {
|
|
wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
|
|
FREE_FRAME(exec_env, frame);
|
|
#if WASM_ENABLE_OPCODE_COUNTER != 0
|
|
wasm_interp_dump_op_count();
|
|
#endif
|
|
}
|