typenative 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1004) hide show
  1. package/CHANGELOG.md +412 -0
  2. package/README.md +1 -1
  3. package/bin/cli.js +18 -8
  4. package/bin/go/overrides.js +21 -1
  5. package/bin/index.js +48 -25
  6. package/bin/main.js +2 -1
  7. package/bin/node/assert.js +54 -15
  8. package/bin/node/async_hooks.js +69 -10
  9. package/bin/node/buffer.js +321 -7
  10. package/bin/node/child_process.js +154 -8
  11. package/bin/node/cluster.js +436 -32
  12. package/bin/node/crypto.js +814 -5
  13. package/bin/node/crypto_curves.js +142 -0
  14. package/bin/node/crypto_keys.js +1147 -48
  15. package/bin/node/crypto_pem.js +313 -0
  16. package/bin/node/crypto_pkcs12.js +17 -0
  17. package/bin/node/dgram.js +161 -10
  18. package/bin/node/diagnostics_channel.js +5 -1
  19. package/bin/node/events.js +358 -8
  20. package/bin/node/ffi.js +933 -0
  21. package/bin/node/fs.js +334 -6
  22. package/bin/node/http.js +630 -55
  23. package/bin/node/http2.js +1141 -88
  24. package/bin/node/intl.js +4576 -0
  25. package/bin/node/intl_data.js +65412 -0
  26. package/bin/node/module_v8.js +155 -16
  27. package/bin/node/net.js +59 -10
  28. package/bin/node/path.js +5 -1
  29. package/bin/node/process.js +342 -3
  30. package/bin/node/readline.js +558 -8
  31. package/bin/node/registry.js +2 -0
  32. package/bin/node/sqlite.js +51 -2
  33. package/bin/node/stream.js +370 -32
  34. package/bin/node/stream_web.js +422 -15
  35. package/bin/node/system_extra.js +154 -1
  36. package/bin/node/temporal.js +96 -0
  37. package/bin/node/temporal_runtime.js +5075 -0
  38. package/bin/node/temporal_zones.js +460 -0
  39. package/bin/node/test.js +153 -8
  40. package/bin/node/test_coverage.js +58 -0
  41. package/bin/node/test_report.js +3 -3
  42. package/bin/node/test_run.js +7 -1
  43. package/bin/node/timers.js +123 -0
  44. package/bin/node/tls.js +346 -12
  45. package/bin/node/tls_roots.js +122 -0
  46. package/bin/node/typed_arrays.js +867 -93
  47. package/bin/node/url.js +657 -0
  48. package/bin/node/util.js +441 -2
  49. package/bin/node/util_extra.js +6 -0
  50. package/bin/node/wasi.js +214 -0
  51. package/bin/node/webassembly.js +1122 -0
  52. package/bin/node/websocket.js +763 -0
  53. package/bin/node/worker_threads.js +434 -52
  54. package/bin/node/zlib.js +338 -9
  55. package/bin/node/zlib_zip.js +2392 -0
  56. package/bin/transpiler.js +2083 -254
  57. package/bin/typecheck-node.js +49 -17
  58. package/bin/version.js +1 -1
  59. package/conformance.md +160 -113
  60. package/examples/README.md +21 -20
  61. package/examples/angular-templates/README.md +12 -12
  62. package/examples/desktop-notes/README.md +7 -7
  63. package/examples/dupe-finder/README.md +4 -4
  64. package/examples/fibonacci/README.md +6 -6
  65. package/examples/hello-world/README.md +4 -4
  66. package/examples/json-server/README.md +13 -12
  67. package/examples/mandelbrot-png/README.md +4 -4
  68. package/examples/marked-cli/README.md +16 -17
  69. package/examples/openai-chat/README.md +5 -5
  70. package/examples/react-compiler/README.md +10 -10
  71. package/examples/todo-cli/README.md +8 -8
  72. package/examples/yaml-cli/README.md +10 -10
  73. package/govendor/github.com/cloudflare/circl/.golangci.yaml +64 -0
  74. package/govendor/github.com/cloudflare/circl/.semgrepignore +1 -0
  75. package/govendor/github.com/cloudflare/circl/AGENTS.md +91 -0
  76. package/govendor/github.com/cloudflare/circl/CITATION.cff +30 -0
  77. package/govendor/github.com/cloudflare/circl/LICENSE +57 -0
  78. package/govendor/github.com/cloudflare/circl/Makefile +70 -0
  79. package/govendor/github.com/cloudflare/circl/README.md +206 -0
  80. package/govendor/github.com/cloudflare/circl/REVIEW.md +83 -0
  81. package/govendor/github.com/cloudflare/circl/codecov.yml +21 -0
  82. package/govendor/github.com/cloudflare/circl/dh/x448/curve.go +104 -0
  83. package/govendor/github.com/cloudflare/circl/dh/x448/curve_amd64.go +30 -0
  84. package/govendor/github.com/cloudflare/circl/dh/x448/curve_amd64.h +111 -0
  85. package/govendor/github.com/cloudflare/circl/dh/x448/curve_amd64.s +194 -0
  86. package/govendor/github.com/cloudflare/circl/dh/x448/curve_generic.go +100 -0
  87. package/govendor/github.com/cloudflare/circl/dh/x448/curve_noasm.go +11 -0
  88. package/govendor/github.com/cloudflare/circl/dh/x448/doc.go +19 -0
  89. package/govendor/github.com/cloudflare/circl/dh/x448/key.go +46 -0
  90. package/govendor/github.com/cloudflare/circl/dh/x448/table.go +460 -0
  91. package/govendor/github.com/cloudflare/circl/doc.go +8 -0
  92. package/govendor/github.com/cloudflare/circl/ecc/goldilocks/constants.go +71 -0
  93. package/govendor/github.com/cloudflare/circl/ecc/goldilocks/curve.go +90 -0
  94. package/govendor/github.com/cloudflare/circl/ecc/goldilocks/isogeny.go +52 -0
  95. package/govendor/github.com/cloudflare/circl/ecc/goldilocks/point.go +181 -0
  96. package/govendor/github.com/cloudflare/circl/ecc/goldilocks/scalar.go +203 -0
  97. package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twist.go +138 -0
  98. package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twistPoint.go +135 -0
  99. package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twistTables.go +216 -0
  100. package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twist_basemult.go +62 -0
  101. package/govendor/github.com/cloudflare/circl/go.mod +3 -0
  102. package/govendor/github.com/cloudflare/circl/internal/conv/conv.go +173 -0
  103. package/govendor/github.com/cloudflare/circl/internal/sha3/doc.go +62 -0
  104. package/govendor/github.com/cloudflare/circl/internal/sha3/hashes.go +69 -0
  105. package/govendor/github.com/cloudflare/circl/internal/sha3/keccakf.go +391 -0
  106. package/govendor/github.com/cloudflare/circl/internal/sha3/rc.go +29 -0
  107. package/govendor/github.com/cloudflare/circl/internal/sha3/sha3.go +200 -0
  108. package/govendor/github.com/cloudflare/circl/internal/sha3/sha3_s390x.s +33 -0
  109. package/govendor/github.com/cloudflare/circl/internal/sha3/shake.go +119 -0
  110. package/govendor/github.com/cloudflare/circl/internal/sha3/xor.go +15 -0
  111. package/govendor/github.com/cloudflare/circl/internal/sha3/xor_generic.go +33 -0
  112. package/govendor/github.com/cloudflare/circl/internal/sha3/xor_unaligned.go +61 -0
  113. package/govendor/github.com/cloudflare/circl/math/fp448/fp.go +164 -0
  114. package/govendor/github.com/cloudflare/circl/math/fp448/fp_amd64.go +43 -0
  115. package/govendor/github.com/cloudflare/circl/math/fp448/fp_amd64.h +591 -0
  116. package/govendor/github.com/cloudflare/circl/math/fp448/fp_amd64.s +75 -0
  117. package/govendor/github.com/cloudflare/circl/math/fp448/fp_generic.go +339 -0
  118. package/govendor/github.com/cloudflare/circl/math/fp448/fp_noasm.go +12 -0
  119. package/govendor/github.com/cloudflare/circl/math/fp448/fuzzer.go +75 -0
  120. package/govendor/github.com/cloudflare/circl/math/integer.go +16 -0
  121. package/govendor/github.com/cloudflare/circl/math/mlsbset/mlsbset.go +145 -0
  122. package/govendor/github.com/cloudflare/circl/math/mlsbset/power.go +64 -0
  123. package/govendor/github.com/cloudflare/circl/math/primes.go +34 -0
  124. package/govendor/github.com/cloudflare/circl/math/wnaf.go +84 -0
  125. package/govendor/github.com/cloudflare/circl/sign/ed448/ed448.go +417 -0
  126. package/govendor/github.com/cloudflare/circl/sign/ed448/signapi.go +89 -0
  127. package/govendor/github.com/cloudflare/circl/sign/sign.go +119 -0
  128. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/LICENSE +17 -0
  129. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/README.md +72 -0
  130. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/compressedbytepoints.go +18 -0
  131. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/curve.go +1310 -0
  132. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/curve_embedded.go +14 -0
  133. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/curve_precompute.go +14 -0
  134. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/doc.go +59 -0
  135. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdh.go +21 -0
  136. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/README.md +52 -0
  137. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/doc.go +42 -0
  138. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/error.go +134 -0
  139. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/signature.go +1001 -0
  140. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ellipticadaptor.go +296 -0
  141. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/error.go +67 -0
  142. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/field.go +1696 -0
  143. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/go.mod +3 -0
  144. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/loadprecomputed.go +91 -0
  145. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/modnscalar.go +1105 -0
  146. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/nonce.go +263 -0
  147. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/privkey.go +111 -0
  148. package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/pubkey.go +236 -0
  149. package/govendor/github.com/ebitengine/purego/LICENSE +201 -0
  150. package/govendor/github.com/ebitengine/purego/README.md +124 -0
  151. package/govendor/github.com/ebitengine/purego/abi_amd64.h +99 -0
  152. package/govendor/github.com/ebitengine/purego/abi_arm64.h +39 -0
  153. package/govendor/github.com/ebitengine/purego/abi_loong64.h +60 -0
  154. package/govendor/github.com/ebitengine/purego/cdecl.go +11 -0
  155. package/govendor/github.com/ebitengine/purego/cgo.go +19 -0
  156. package/govendor/github.com/ebitengine/purego/dlerror.go +17 -0
  157. package/govendor/github.com/ebitengine/purego/dlfcn.go +99 -0
  158. package/govendor/github.com/ebitengine/purego/dlfcn_android.go +34 -0
  159. package/govendor/github.com/ebitengine/purego/dlfcn_darwin.go +20 -0
  160. package/govendor/github.com/ebitengine/purego/dlfcn_freebsd.go +14 -0
  161. package/govendor/github.com/ebitengine/purego/dlfcn_linux.go +16 -0
  162. package/govendor/github.com/ebitengine/purego/dlfcn_netbsd.go +15 -0
  163. package/govendor/github.com/ebitengine/purego/dlfcn_nocgo_freebsd.go +11 -0
  164. package/govendor/github.com/ebitengine/purego/dlfcn_nocgo_linux.go +19 -0
  165. package/govendor/github.com/ebitengine/purego/dlfcn_nocgo_netbsd.go +11 -0
  166. package/govendor/github.com/ebitengine/purego/dlfcn_playground.go +24 -0
  167. package/govendor/github.com/ebitengine/purego/dlfcn_stubs.s +22 -0
  168. package/govendor/github.com/ebitengine/purego/func.go +780 -0
  169. package/govendor/github.com/ebitengine/purego/gen.go +6 -0
  170. package/govendor/github.com/ebitengine/purego/go.mod +3 -0
  171. package/govendor/github.com/ebitengine/purego/go_runtime.go +19 -0
  172. package/govendor/github.com/ebitengine/purego/internal/cgo/dlfcn_cgo_unix.go +56 -0
  173. package/govendor/github.com/ebitengine/purego/internal/cgo/empty.go +6 -0
  174. package/govendor/github.com/ebitengine/purego/internal/cgo/syscall_cgo_unix.go +49 -0
  175. package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_amd64.h +99 -0
  176. package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_arm64.h +39 -0
  177. package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_loong64.h +60 -0
  178. package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_ppc64x.h +195 -0
  179. package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_riscv64.h +72 -0
  180. package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_386.s +29 -0
  181. package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_amd64.s +39 -0
  182. package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_arm.s +58 -0
  183. package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_arm64.s +35 -0
  184. package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_loong64.s +38 -0
  185. package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_ppc64le.s +79 -0
  186. package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_riscv64.s +36 -0
  187. package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_s390x.s +52 -0
  188. package/govendor/github.com/ebitengine/purego/internal/fakecgo/callbacks.go +93 -0
  189. package/govendor/github.com/ebitengine/purego/internal/fakecgo/doc.go +32 -0
  190. package/govendor/github.com/ebitengine/purego/internal/fakecgo/fakecgo.go +14 -0
  191. package/govendor/github.com/ebitengine/purego/internal/fakecgo/freebsd.go +27 -0
  192. package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_darwin.go +86 -0
  193. package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_freebsd.go +77 -0
  194. package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_libinit.go +72 -0
  195. package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_linux.go +77 -0
  196. package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_netbsd.go +83 -0
  197. package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_setenv.go +18 -0
  198. package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_util.go +38 -0
  199. package/govendor/github.com/ebitengine/purego/internal/fakecgo/iscgo.go +19 -0
  200. package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo.go +37 -0
  201. package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_darwin.go +37 -0
  202. package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_freebsd.go +27 -0
  203. package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_linux.go +27 -0
  204. package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_netbsd.go +36 -0
  205. package/govendor/github.com/ebitengine/purego/internal/fakecgo/linux.go +189 -0
  206. package/govendor/github.com/ebitengine/purego/internal/fakecgo/netbsd.go +23 -0
  207. package/govendor/github.com/ebitengine/purego/internal/fakecgo/setenv.go +19 -0
  208. package/govendor/github.com/ebitengine/purego/internal/fakecgo/threadentry_amd64.go +15 -0
  209. package/govendor/github.com/ebitengine/purego/internal/fakecgo/threadentry_noasm.go +24 -0
  210. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_386.s +130 -0
  211. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_amd64.s +124 -0
  212. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_arm.s +131 -0
  213. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_arm64.s +81 -0
  214. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_386.s +78 -0
  215. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_amd64.s +69 -0
  216. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_arm.s +69 -0
  217. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_arm64.s +60 -0
  218. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_loong64.s +60 -0
  219. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_ppc64le.s +69 -0
  220. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_riscv64.s +60 -0
  221. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_s390x.s +51 -0
  222. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_loong64.s +78 -0
  223. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_ppc64le.s +132 -0
  224. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_riscv64.s +76 -0
  225. package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_s390x.s +158 -0
  226. package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols.go +165 -0
  227. package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_darwin.go +59 -0
  228. package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_freebsd.go +48 -0
  229. package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_linux.go +158 -0
  230. package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_netbsd.go +59 -0
  231. package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_darwin.s +19 -0
  232. package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_freebsd.s +16 -0
  233. package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_linux.s +46 -0
  234. package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_netbsd.s +19 -0
  235. package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_stubs.s +55 -0
  236. package/govendor/github.com/ebitengine/purego/internal/strings/strings.go +40 -0
  237. package/govendor/github.com/ebitengine/purego/is_ios.go +13 -0
  238. package/govendor/github.com/ebitengine/purego/nocgo.go +25 -0
  239. package/govendor/github.com/ebitengine/purego/struct_amd64.go +518 -0
  240. package/govendor/github.com/ebitengine/purego/struct_arm.go +100 -0
  241. package/govendor/github.com/ebitengine/purego/struct_arm64.go +757 -0
  242. package/govendor/github.com/ebitengine/purego/struct_loong64.go +244 -0
  243. package/govendor/github.com/ebitengine/purego/struct_other.go +54 -0
  244. package/govendor/github.com/ebitengine/purego/struct_ppc64le.go +180 -0
  245. package/govendor/github.com/ebitengine/purego/struct_riscv64.go +158 -0
  246. package/govendor/github.com/ebitengine/purego/struct_s390x.go +158 -0
  247. package/govendor/github.com/ebitengine/purego/sys_386.s +153 -0
  248. package/govendor/github.com/ebitengine/purego/sys_amd64.s +206 -0
  249. package/govendor/github.com/ebitengine/purego/sys_arm.s +153 -0
  250. package/govendor/github.com/ebitengine/purego/sys_arm64.s +133 -0
  251. package/govendor/github.com/ebitengine/purego/sys_loong64.s +131 -0
  252. package/govendor/github.com/ebitengine/purego/sys_ppc64le.s +126 -0
  253. package/govendor/github.com/ebitengine/purego/sys_riscv64.s +135 -0
  254. package/govendor/github.com/ebitengine/purego/sys_s390x.s +148 -0
  255. package/govendor/github.com/ebitengine/purego/sys_unix_386.s +234 -0
  256. package/govendor/github.com/ebitengine/purego/sys_unix_arm.s +99 -0
  257. package/govendor/github.com/ebitengine/purego/sys_unix_arm64.s +75 -0
  258. package/govendor/github.com/ebitengine/purego/sys_unix_loong64.s +79 -0
  259. package/govendor/github.com/ebitengine/purego/sys_unix_ppc64le.s +114 -0
  260. package/govendor/github.com/ebitengine/purego/sys_unix_riscv64.s +79 -0
  261. package/govendor/github.com/ebitengine/purego/sys_unix_s390x.s +111 -0
  262. package/govendor/github.com/ebitengine/purego/syscall.go +95 -0
  263. package/govendor/github.com/ebitengine/purego/syscall_32bit.go +97 -0
  264. package/govendor/github.com/ebitengine/purego/syscall_cgo_linux.go +20 -0
  265. package/govendor/github.com/ebitengine/purego/syscall_notstackargs.go +55 -0
  266. package/govendor/github.com/ebitengine/purego/syscall_ppc64le.go +73 -0
  267. package/govendor/github.com/ebitengine/purego/syscall_stackargs_ppc64le.go +38 -0
  268. package/govendor/github.com/ebitengine/purego/syscall_stackargs_s390x.go +38 -0
  269. package/govendor/github.com/ebitengine/purego/syscall_unix.go +392 -0
  270. package/govendor/github.com/ebitengine/purego/syscall_windows.go +54 -0
  271. package/govendor/github.com/ebitengine/purego/zcallback_386.s +4014 -0
  272. package/govendor/github.com/ebitengine/purego/zcallback_amd64.s +2014 -0
  273. package/govendor/github.com/ebitengine/purego/zcallback_arm.s +4014 -0
  274. package/govendor/github.com/ebitengine/purego/zcallback_arm64.s +4014 -0
  275. package/govendor/github.com/ebitengine/purego/zcallback_loong64.s +4014 -0
  276. package/govendor/github.com/ebitengine/purego/zcallback_ppc64le.s +4014 -0
  277. package/govendor/github.com/ebitengine/purego/zcallback_riscv64.s +4051 -0
  278. package/govendor/github.com/ebitengine/purego/zcallback_s390x.s +4015 -0
  279. package/govendor/github.com/klauspost/compress/.gitattributes +3 -0
  280. package/govendor/github.com/klauspost/compress/.goreleaser.yml +132 -0
  281. package/govendor/github.com/klauspost/compress/AGENTS.md +106 -0
  282. package/govendor/github.com/klauspost/compress/LICENSE +304 -0
  283. package/govendor/github.com/klauspost/compress/README.md +766 -0
  284. package/govendor/github.com/klauspost/compress/SECURITY.md +25 -0
  285. package/govendor/github.com/klauspost/compress/compressible.go +85 -0
  286. package/govendor/github.com/klauspost/compress/fse/README.md +79 -0
  287. package/govendor/github.com/klauspost/compress/fse/bitreader.go +122 -0
  288. package/govendor/github.com/klauspost/compress/fse/bitwriter.go +167 -0
  289. package/govendor/github.com/klauspost/compress/fse/bytereader.go +47 -0
  290. package/govendor/github.com/klauspost/compress/fse/compress.go +685 -0
  291. package/govendor/github.com/klauspost/compress/fse/decompress.go +383 -0
  292. package/govendor/github.com/klauspost/compress/fse/fse.go +150 -0
  293. package/govendor/github.com/klauspost/compress/gen.sh +4 -0
  294. package/govendor/github.com/klauspost/compress/go.mod +3 -0
  295. package/govendor/github.com/klauspost/compress/huff0/README.md +89 -0
  296. package/govendor/github.com/klauspost/compress/huff0/bitreader.go +323 -0
  297. package/govendor/github.com/klauspost/compress/huff0/bitwriter.go +97 -0
  298. package/govendor/github.com/klauspost/compress/huff0/build_table.go +168 -0
  299. package/govendor/github.com/klauspost/compress/huff0/compress.go +747 -0
  300. package/govendor/github.com/klauspost/compress/huff0/decompress.go +1188 -0
  301. package/govendor/github.com/klauspost/compress/huff0/decompress_amd64.go +128 -0
  302. package/govendor/github.com/klauspost/compress/huff0/decompress_amd64.s +3476 -0
  303. package/govendor/github.com/klauspost/compress/huff0/decompress_arm64.go +72 -0
  304. package/govendor/github.com/klauspost/compress/huff0/decompress_arm64.s +1648 -0
  305. package/govendor/github.com/klauspost/compress/huff0/decompress_asm.go +252 -0
  306. package/govendor/github.com/klauspost/compress/huff0/decompress_generic.go +278 -0
  307. package/govendor/github.com/klauspost/compress/huff0/huff0.go +337 -0
  308. package/govendor/github.com/klauspost/compress/internal/cpuinfo/cpuinfo.go +34 -0
  309. package/govendor/github.com/klauspost/compress/internal/cpuinfo/cpuinfo_amd64.go +10 -0
  310. package/govendor/github.com/klauspost/compress/internal/cpuinfo/cpuinfo_amd64.s +34 -0
  311. package/govendor/github.com/klauspost/compress/internal/le/le.go +5 -0
  312. package/govendor/github.com/klauspost/compress/internal/le/unsafe_disabled.go +42 -0
  313. package/govendor/github.com/klauspost/compress/internal/le/unsafe_enabled.go +52 -0
  314. package/govendor/github.com/klauspost/compress/internal/regmask/regmask.go +50 -0
  315. package/govendor/github.com/klauspost/compress/internal/regmask/regmask_386.go +39 -0
  316. package/govendor/github.com/klauspost/compress/internal/snapref/LICENSE +27 -0
  317. package/govendor/github.com/klauspost/compress/internal/snapref/decode.go +264 -0
  318. package/govendor/github.com/klauspost/compress/internal/snapref/decode_other.go +113 -0
  319. package/govendor/github.com/klauspost/compress/internal/snapref/encode.go +291 -0
  320. package/govendor/github.com/klauspost/compress/internal/snapref/encode_other.go +250 -0
  321. package/govendor/github.com/klauspost/compress/internal/snapref/snappy.go +98 -0
  322. package/govendor/github.com/klauspost/compress/s2sx.mod +3 -0
  323. package/govendor/github.com/klauspost/compress/s2sx.sum +0 -0
  324. package/govendor/github.com/klauspost/compress/zstd/README.md +487 -0
  325. package/govendor/github.com/klauspost/compress/zstd/bitreader.go +176 -0
  326. package/govendor/github.com/klauspost/compress/zstd/bitwriter.go +151 -0
  327. package/govendor/github.com/klauspost/compress/zstd/blockdec.go +728 -0
  328. package/govendor/github.com/klauspost/compress/zstd/blockenc.go +923 -0
  329. package/govendor/github.com/klauspost/compress/zstd/blocktype_string.go +85 -0
  330. package/govendor/github.com/klauspost/compress/zstd/bytebuf.go +131 -0
  331. package/govendor/github.com/klauspost/compress/zstd/bytereader.go +82 -0
  332. package/govendor/github.com/klauspost/compress/zstd/decodeheader.go +261 -0
  333. package/govendor/github.com/klauspost/compress/zstd/decoder.go +995 -0
  334. package/govendor/github.com/klauspost/compress/zstd/decoder_options.go +213 -0
  335. package/govendor/github.com/klauspost/compress/zstd/dict.go +605 -0
  336. package/govendor/github.com/klauspost/compress/zstd/enc_base.go +200 -0
  337. package/govendor/github.com/klauspost/compress/zstd/enc_best.go +572 -0
  338. package/govendor/github.com/klauspost/compress/zstd/enc_better.go +1262 -0
  339. package/govendor/github.com/klauspost/compress/zstd/enc_dfast.go +1136 -0
  340. package/govendor/github.com/klauspost/compress/zstd/enc_fast.go +892 -0
  341. package/govendor/github.com/klauspost/compress/zstd/enc_jobs.go +352 -0
  342. package/govendor/github.com/klauspost/compress/zstd/encoder.go +881 -0
  343. package/govendor/github.com/klauspost/compress/zstd/encoder_options.go +422 -0
  344. package/govendor/github.com/klauspost/compress/zstd/framedec.go +404 -0
  345. package/govendor/github.com/klauspost/compress/zstd/frameenc.go +137 -0
  346. package/govendor/github.com/klauspost/compress/zstd/fse_decoder.go +333 -0
  347. package/govendor/github.com/klauspost/compress/zstd/fse_decoder_amd64.s +132 -0
  348. package/govendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s +148 -0
  349. package/govendor/github.com/klauspost/compress/zstd/fse_decoder_asm.go +70 -0
  350. package/govendor/github.com/klauspost/compress/zstd/fse_decoder_generic.go +71 -0
  351. package/govendor/github.com/klauspost/compress/zstd/fse_encoder.go +701 -0
  352. package/govendor/github.com/klauspost/compress/zstd/fse_predefined.go +168 -0
  353. package/govendor/github.com/klauspost/compress/zstd/hash.go +57 -0
  354. package/govendor/github.com/klauspost/compress/zstd/history.go +119 -0
  355. package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/LICENSE.txt +22 -0
  356. package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/README.md +71 -0
  357. package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash.go +242 -0
  358. package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_amd64.s +210 -0
  359. package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_arm64.s +184 -0
  360. package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_asm.go +11 -0
  361. package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_other.go +75 -0
  362. package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_safe.go +11 -0
  363. package/govendor/github.com/klauspost/compress/zstd/matchlen_amd64.go +15 -0
  364. package/govendor/github.com/klauspost/compress/zstd/matchlen_amd64.s +66 -0
  365. package/govendor/github.com/klauspost/compress/zstd/matchlen_generic.go +37 -0
  366. package/govendor/github.com/klauspost/compress/zstd/seqdec.go +620 -0
  367. package/govendor/github.com/klauspost/compress/zstd/seqdec_amd64.go +115 -0
  368. package/govendor/github.com/klauspost/compress/zstd/seqdec_amd64.s +4762 -0
  369. package/govendor/github.com/klauspost/compress/zstd/seqdec_arm64.go +81 -0
  370. package/govendor/github.com/klauspost/compress/zstd/seqdec_arm64.s +2919 -0
  371. package/govendor/github.com/klauspost/compress/zstd/seqdec_asm.go +327 -0
  372. package/govendor/github.com/klauspost/compress/zstd/seqdec_generic.go +258 -0
  373. package/govendor/github.com/klauspost/compress/zstd/seqenc.go +159 -0
  374. package/govendor/github.com/klauspost/compress/zstd/simple.go +54 -0
  375. package/govendor/github.com/klauspost/compress/zstd/snappy.go +447 -0
  376. package/govendor/github.com/klauspost/compress/zstd/zip.go +141 -0
  377. package/govendor/github.com/klauspost/compress/zstd/zstd.go +126 -0
  378. package/govendor/github.com/tetratelabs/wazero/.editorconfig +7 -0
  379. package/govendor/github.com/tetratelabs/wazero/.gitattributes +2 -0
  380. package/govendor/github.com/tetratelabs/wazero/.gitmodules +3 -0
  381. package/govendor/github.com/tetratelabs/wazero/CONTRIBUTING.md +75 -0
  382. package/govendor/github.com/tetratelabs/wazero/LICENSE +201 -0
  383. package/govendor/github.com/tetratelabs/wazero/Makefile +385 -0
  384. package/govendor/github.com/tetratelabs/wazero/NOTICE +2 -0
  385. package/govendor/github.com/tetratelabs/wazero/RATIONALE.md +1577 -0
  386. package/govendor/github.com/tetratelabs/wazero/README.md +135 -0
  387. package/govendor/github.com/tetratelabs/wazero/api/features.go +228 -0
  388. package/govendor/github.com/tetratelabs/wazero/api/wasm.go +766 -0
  389. package/govendor/github.com/tetratelabs/wazero/builder.go +367 -0
  390. package/govendor/github.com/tetratelabs/wazero/cache.go +123 -0
  391. package/govendor/github.com/tetratelabs/wazero/codecov.yml +9 -0
  392. package/govendor/github.com/tetratelabs/wazero/config.go +899 -0
  393. package/govendor/github.com/tetratelabs/wazero/experimental/checkpoint.go +35 -0
  394. package/govendor/github.com/tetratelabs/wazero/experimental/close.go +63 -0
  395. package/govendor/github.com/tetratelabs/wazero/experimental/compilationworkers.go +19 -0
  396. package/govendor/github.com/tetratelabs/wazero/experimental/experimental.go +41 -0
  397. package/govendor/github.com/tetratelabs/wazero/experimental/features.go +39 -0
  398. package/govendor/github.com/tetratelabs/wazero/experimental/importresolver.go +19 -0
  399. package/govendor/github.com/tetratelabs/wazero/experimental/listener.go +324 -0
  400. package/govendor/github.com/tetratelabs/wazero/experimental/memory.go +52 -0
  401. package/govendor/github.com/tetratelabs/wazero/experimental/sys/dir.go +92 -0
  402. package/govendor/github.com/tetratelabs/wazero/experimental/sys/errno.go +98 -0
  403. package/govendor/github.com/tetratelabs/wazero/experimental/sys/error.go +45 -0
  404. package/govendor/github.com/tetratelabs/wazero/experimental/sys/file.go +356 -0
  405. package/govendor/github.com/tetratelabs/wazero/experimental/sys/fs.go +292 -0
  406. package/govendor/github.com/tetratelabs/wazero/experimental/sys/oflag.go +70 -0
  407. package/govendor/github.com/tetratelabs/wazero/experimental/sys/poll.go +48 -0
  408. package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno.go +106 -0
  409. package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno_notwindows.go +13 -0
  410. package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno_unsupported.go +7 -0
  411. package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno_windows.go +37 -0
  412. package/govendor/github.com/tetratelabs/wazero/experimental/sys/time.go +10 -0
  413. package/govendor/github.com/tetratelabs/wazero/experimental/sys/unimplemented.go +160 -0
  414. package/govendor/github.com/tetratelabs/wazero/fsconfig.go +213 -0
  415. package/govendor/github.com/tetratelabs/wazero/go.mod +3 -0
  416. package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/args.go +97 -0
  417. package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/clock.go +116 -0
  418. package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/environ.go +100 -0
  419. package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/fs.go +2015 -0
  420. package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/poll.go +247 -0
  421. package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/proc.go +44 -0
  422. package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/random.go +55 -0
  423. package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/sched.go +22 -0
  424. package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/sock.go +188 -0
  425. package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/wasi.go +314 -0
  426. package/govendor/github.com/tetratelabs/wazero/internal/descriptor/table.go +149 -0
  427. package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/compiler.go +3884 -0
  428. package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/format.go +22 -0
  429. package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/interpreter.go +4963 -0
  430. package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/operations.go +2978 -0
  431. package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/signature.go +825 -0
  432. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/abi.go +170 -0
  433. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/backend.go +3 -0
  434. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/compiler.go +402 -0
  435. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/compiler_lower.go +226 -0
  436. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/go_call.go +33 -0
  437. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi.go +186 -0
  438. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_entry_amd64.go +9 -0
  439. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_entry_amd64.s +29 -0
  440. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_entry_preamble.go +248 -0
  441. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_go_call.go +440 -0
  442. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/cond.go +168 -0
  443. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/ext.go +35 -0
  444. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/instr.go +2495 -0
  445. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/instr_encoding.go +1714 -0
  446. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/lower_constant.go +71 -0
  447. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/lower_mem.go +187 -0
  448. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine.go +3782 -0
  449. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine_pro_epi_logue.go +334 -0
  450. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine_regalloc.go +352 -0
  451. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine_vec.go +992 -0
  452. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/operands.go +336 -0
  453. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/reg.go +181 -0
  454. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/stack.go +130 -0
  455. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi.go +376 -0
  456. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_entry_arm64.go +9 -0
  457. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_entry_arm64.s +29 -0
  458. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_entry_preamble.go +233 -0
  459. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_go_call.go +430 -0
  460. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/cond.go +215 -0
  461. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/instr.go +2562 -0
  462. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/instr_encoding.go +2357 -0
  463. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_constant.go +301 -0
  464. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_instr.go +2227 -0
  465. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_instr_operands.go +340 -0
  466. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_mem.go +451 -0
  467. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine.go +631 -0
  468. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine_pro_epi_logue.go +486 -0
  469. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine_regalloc.go +351 -0
  470. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine_relocation.go +128 -0
  471. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/reg.go +397 -0
  472. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/unwind_stack.go +84 -0
  473. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/machine.go +119 -0
  474. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/api.go +124 -0
  475. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/reg.go +123 -0
  476. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/regalloc.go +1189 -0
  477. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/regset.go +96 -0
  478. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/vdef.go +19 -0
  479. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/call_engine.go +884 -0
  480. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine.go +1008 -0
  481. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine_cache.go +347 -0
  482. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/entrypoint_amd64.go +13 -0
  483. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/entrypoint_arm64.go +13 -0
  484. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/entrypoint_other.go +15 -0
  485. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/frontend.go +663 -0
  486. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go +5045 -0
  487. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/misc.go +10 -0
  488. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/sort_id.go +13 -0
  489. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/hostmodule.go +88 -0
  490. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/isa_amd64.go +30 -0
  491. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/isa_arm64.go +32 -0
  492. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/isa_other.go +29 -0
  493. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/memmove.go +11 -0
  494. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/module_engine.go +403 -0
  495. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/basic_block.go +381 -0
  496. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/basic_block_sort.go +32 -0
  497. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/builder.go +790 -0
  498. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/cmp.go +107 -0
  499. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/funcref.go +12 -0
  500. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go +3024 -0
  501. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/pass.go +393 -0
  502. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/pass_blk_layouts.go +334 -0
  503. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/pass_cfg.go +313 -0
  504. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/signature.go +49 -0
  505. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/ssa.go +14 -0
  506. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/type.go +115 -0
  507. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/vs.go +114 -0
  508. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/debug_options.go +189 -0
  509. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/exitcode.go +150 -0
  510. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/offsetdata.go +248 -0
  511. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/perfmap.go +96 -0
  512. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/perfmap_disabled.go +5 -0
  513. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/perfmap_enabled.go +5 -0
  514. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/pool.go +215 -0
  515. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/ptr.go +15 -0
  516. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/queue.go +26 -0
  517. package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/resetmap.go +11 -0
  518. package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/checkpoint.go +10 -0
  519. package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/close.go +5 -0
  520. package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/compilationworkers.go +6 -0
  521. package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/expctxkeys.go +2 -0
  522. package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/importresolver.go +6 -0
  523. package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/listener.go +7 -0
  524. package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/memory.go +4 -0
  525. package/govendor/github.com/tetratelabs/wazero/internal/filecache/compilationcache.go +42 -0
  526. package/govendor/github.com/tetratelabs/wazero/internal/filecache/file_cache.go +76 -0
  527. package/govendor/github.com/tetratelabs/wazero/internal/ieee754/ieee754.go +29 -0
  528. package/govendor/github.com/tetratelabs/wazero/internal/internalapi/internal.go +9 -0
  529. package/govendor/github.com/tetratelabs/wazero/internal/leb128/leb128.go +285 -0
  530. package/govendor/github.com/tetratelabs/wazero/internal/moremath/moremath.go +271 -0
  531. package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid.go +26 -0
  532. package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid_amd64.go +22 -0
  533. package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid_arm64.go +13 -0
  534. package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid_unsupported.go +5 -0
  535. package/govendor/github.com/tetratelabs/wazero/internal/platform/crypto.go +17 -0
  536. package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_linux.go +72 -0
  537. package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_other.go +19 -0
  538. package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_unix.go +14 -0
  539. package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_unsupported.go +22 -0
  540. package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_windows.go +31 -0
  541. package/govendor/github.com/tetratelabs/wazero/internal/platform/path.go +6 -0
  542. package/govendor/github.com/tetratelabs/wazero/internal/platform/path_windows.go +17 -0
  543. package/govendor/github.com/tetratelabs/wazero/internal/platform/platform.go +71 -0
  544. package/govendor/github.com/tetratelabs/wazero/internal/platform/time.go +76 -0
  545. package/govendor/github.com/tetratelabs/wazero/internal/platform/time_notwindows.go +11 -0
  546. package/govendor/github.com/tetratelabs/wazero/internal/platform/time_windows.go +40 -0
  547. package/govendor/github.com/tetratelabs/wazero/internal/sock/sock.go +89 -0
  548. package/govendor/github.com/tetratelabs/wazero/internal/sock/sock_supported.go +11 -0
  549. package/govendor/github.com/tetratelabs/wazero/internal/sock/sock_unsupported.go +10 -0
  550. package/govendor/github.com/tetratelabs/wazero/internal/sys/fs.go +458 -0
  551. package/govendor/github.com/tetratelabs/wazero/internal/sys/lazy.go +135 -0
  552. package/govendor/github.com/tetratelabs/wazero/internal/sys/stdio.go +125 -0
  553. package/govendor/github.com/tetratelabs/wazero/internal/sys/sys.go +228 -0
  554. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/adapter.go +105 -0
  555. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/datasync_linux.go +12 -0
  556. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/datasync_unsupported.go +14 -0
  557. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/dir.go +24 -0
  558. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/dirfs.go +137 -0
  559. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file.go +576 -0
  560. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file_unix.go +39 -0
  561. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file_unsupported.go +28 -0
  562. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file_windows.go +133 -0
  563. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens.go +29 -0
  564. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_darwin.go +42 -0
  565. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_darwin.s +8 -0
  566. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_linux.go +38 -0
  567. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_unsupported.go +18 -0
  568. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_windows.go +42 -0
  569. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/ino_unix.go +22 -0
  570. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/ino_unsupported.go +17 -0
  571. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/ino_windows.go +28 -0
  572. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/nonblock_unix.go +17 -0
  573. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/nonblock_unsupported.go +13 -0
  574. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/nonblock_windows.go +23 -0
  575. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/oflag.go +38 -0
  576. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_bsd.go +26 -0
  577. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_darwin.go +26 -0
  578. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_supported.go +30 -0
  579. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_unix.go +20 -0
  580. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_unsupported.go +16 -0
  581. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_windows.go +163 -0
  582. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/osfile.go +318 -0
  583. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll.go +17 -0
  584. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_darwin.go +55 -0
  585. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_darwin.s +8 -0
  586. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_linux.go +57 -0
  587. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_unsupported.go +12 -0
  588. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_windows.go +224 -0
  589. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/readfs.go +117 -0
  590. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/rename_unix.go +16 -0
  591. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/rename_unsupported.go +16 -0
  592. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/rename_windows.go +55 -0
  593. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock.go +186 -0
  594. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_supported.go +76 -0
  595. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_unix.go +48 -0
  596. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_unsupported.go +79 -0
  597. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_windows.go +80 -0
  598. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat.go +16 -0
  599. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat_supported.go +40 -0
  600. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat_unsupported.go +40 -0
  601. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat_windows.go +118 -0
  602. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sync.go +13 -0
  603. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sync_windows.go +20 -0
  604. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/syscall6_darwin.go +13 -0
  605. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sysfs.go +6 -0
  606. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/unlink_unix.go +17 -0
  607. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/unlink_unsupported.go +14 -0
  608. package/govendor/github.com/tetratelabs/wazero/internal/sysfs/unlink_windows.go +25 -0
  609. package/govendor/github.com/tetratelabs/wazero/internal/u32/u32.go +11 -0
  610. package/govendor/github.com/tetratelabs/wazero/internal/u64/u64.go +15 -0
  611. package/govendor/github.com/tetratelabs/wazero/internal/version/version.go +52 -0
  612. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/args.go +6 -0
  613. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/clock.go +16 -0
  614. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/environ.go +6 -0
  615. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/errno.go +314 -0
  616. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/fs.go +164 -0
  617. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/poll.go +15 -0
  618. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/proc.go +6 -0
  619. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/random.go +3 -0
  620. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/rights.go +148 -0
  621. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/sched.go +3 -0
  622. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/sock.go +71 -0
  623. package/govendor/github.com/tetratelabs/wazero/internal/wasip1/wasi.go +26 -0
  624. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/code.go +124 -0
  625. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/const_expr.go +116 -0
  626. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/custom.go +22 -0
  627. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/data.go +79 -0
  628. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/decoder.go +235 -0
  629. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/element.go +250 -0
  630. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/errors.go +11 -0
  631. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/export.go +32 -0
  632. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/function.go +56 -0
  633. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/global.go +50 -0
  634. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/header.go +9 -0
  635. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/import.go +68 -0
  636. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/limits.go +47 -0
  637. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/memory.go +42 -0
  638. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/names.go +151 -0
  639. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/section.go +309 -0
  640. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/table.go +79 -0
  641. package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/value.go +97 -0
  642. package/govendor/github.com/tetratelabs/wazero/internal/wasm/const_expr.go +259 -0
  643. package/govendor/github.com/tetratelabs/wazero/internal/wasm/counts.go +53 -0
  644. package/govendor/github.com/tetratelabs/wazero/internal/wasm/engine.go +76 -0
  645. package/govendor/github.com/tetratelabs/wazero/internal/wasm/exception.go +9 -0
  646. package/govendor/github.com/tetratelabs/wazero/internal/wasm/func_validation.go +2804 -0
  647. package/govendor/github.com/tetratelabs/wazero/internal/wasm/function_definition.go +210 -0
  648. package/govendor/github.com/tetratelabs/wazero/internal/wasm/global.go +55 -0
  649. package/govendor/github.com/tetratelabs/wazero/internal/wasm/gofunc.go +279 -0
  650. package/govendor/github.com/tetratelabs/wazero/internal/wasm/host.go +179 -0
  651. package/govendor/github.com/tetratelabs/wazero/internal/wasm/instruction.go +1962 -0
  652. package/govendor/github.com/tetratelabs/wazero/internal/wasm/memory.go +475 -0
  653. package/govendor/github.com/tetratelabs/wazero/internal/wasm/memory_definition.go +128 -0
  654. package/govendor/github.com/tetratelabs/wazero/internal/wasm/module.go +1359 -0
  655. package/govendor/github.com/tetratelabs/wazero/internal/wasm/module_instance.go +251 -0
  656. package/govendor/github.com/tetratelabs/wazero/internal/wasm/module_instance_lookup.go +73 -0
  657. package/govendor/github.com/tetratelabs/wazero/internal/wasm/store.go +726 -0
  658. package/govendor/github.com/tetratelabs/wazero/internal/wasm/store_module_list.go +95 -0
  659. package/govendor/github.com/tetratelabs/wazero/internal/wasm/table.go +321 -0
  660. package/govendor/github.com/tetratelabs/wazero/internal/wasmdebug/debug.go +170 -0
  661. package/govendor/github.com/tetratelabs/wazero/internal/wasmdebug/dwarf.go +225 -0
  662. package/govendor/github.com/tetratelabs/wazero/internal/wasmruntime/errors.go +54 -0
  663. package/govendor/github.com/tetratelabs/wazero/netlify.toml +15 -0
  664. package/govendor/github.com/tetratelabs/wazero/runtime.go +399 -0
  665. package/govendor/github.com/tetratelabs/wazero/sys/clock.go +26 -0
  666. package/govendor/github.com/tetratelabs/wazero/sys/error.go +83 -0
  667. package/govendor/github.com/tetratelabs/wazero/sys/stat.go +105 -0
  668. package/govendor/github.com/tetratelabs/wazero/sys/stat_bsd.go +29 -0
  669. package/govendor/github.com/tetratelabs/wazero/sys/stat_posix.go +29 -0
  670. package/govendor/github.com/tetratelabs/wazero/sys/stat_unsupported.go +14 -0
  671. package/govendor/github.com/tetratelabs/wazero/sys/stat_windows.go +24 -0
  672. package/govendor/golang.org/x/crypto/LICENSE +27 -0
  673. package/govendor/golang.org/x/crypto/PATENTS +22 -0
  674. package/govendor/golang.org/x/crypto/cryptobyte/asn1/asn1.go +46 -0
  675. package/govendor/golang.org/x/crypto/cryptobyte/asn1.go +825 -0
  676. package/govendor/golang.org/x/crypto/cryptobyte/builder.go +350 -0
  677. package/govendor/golang.org/x/crypto/cryptobyte/string.go +183 -0
  678. package/govendor/golang.org/x/crypto/go.mod +3 -0
  679. package/govendor/golang.org/x/crypto/pbkdf2/pbkdf2.go +30 -0
  680. package/govendor/golang.org/x/net/LICENSE +27 -0
  681. package/govendor/golang.org/x/net/PATENTS +22 -0
  682. package/govendor/golang.org/x/net/dns/dnsmessage/message.go +2733 -0
  683. package/govendor/golang.org/x/net/dns/dnsmessage/svcb.go +333 -0
  684. package/govendor/golang.org/x/net/go.mod +3 -0
  685. package/govendor/golang.org/x/net/http/httpguts/guts.go +50 -0
  686. package/govendor/golang.org/x/net/http/httpguts/httplex.go +347 -0
  687. package/govendor/golang.org/x/net/http2/README.md +19 -0
  688. package/govendor/golang.org/x/net/http2/ascii.go +65 -0
  689. package/govendor/golang.org/x/net/http2/ciphers.go +641 -0
  690. package/govendor/golang.org/x/net/http2/client_conn_pool.go +301 -0
  691. package/govendor/golang.org/x/net/http2/client_priority_go126.go +20 -0
  692. package/govendor/golang.org/x/net/http2/client_priority_go127.go +13 -0
  693. package/govendor/golang.org/x/net/http2/clientconn.go +57 -0
  694. package/govendor/golang.org/x/net/http2/config.go +171 -0
  695. package/govendor/golang.org/x/net/http2/config_go125.go +15 -0
  696. package/govendor/golang.org/x/net/http2/config_go126.go +15 -0
  697. package/govendor/golang.org/x/net/http2/databuffer.go +146 -0
  698. package/govendor/golang.org/x/net/http2/errors.go +145 -0
  699. package/govendor/golang.org/x/net/http2/flow.go +175 -0
  700. package/govendor/golang.org/x/net/http2/frame.go +1887 -0
  701. package/govendor/golang.org/x/net/http2/gotrack.go +181 -0
  702. package/govendor/golang.org/x/net/http2/hpack/encode.go +244 -0
  703. package/govendor/golang.org/x/net/http2/hpack/hpack.go +522 -0
  704. package/govendor/golang.org/x/net/http2/hpack/huffman.go +226 -0
  705. package/govendor/golang.org/x/net/http2/hpack/static_table.go +188 -0
  706. package/govendor/golang.org/x/net/http2/hpack/tables.go +426 -0
  707. package/govendor/golang.org/x/net/http2/http2.go +415 -0
  708. package/govendor/golang.org/x/net/http2/pipe.go +184 -0
  709. package/govendor/golang.org/x/net/http2/server.go +3239 -0
  710. package/govendor/golang.org/x/net/http2/server_common.go +268 -0
  711. package/govendor/golang.org/x/net/http2/server_wrap.go +217 -0
  712. package/govendor/golang.org/x/net/http2/transport.go +3084 -0
  713. package/govendor/golang.org/x/net/http2/transport_common.go +516 -0
  714. package/govendor/golang.org/x/net/http2/transport_wrap.go +583 -0
  715. package/govendor/golang.org/x/net/http2/unencrypted.go +32 -0
  716. package/govendor/golang.org/x/net/http2/write.go +381 -0
  717. package/govendor/golang.org/x/net/http2/writesched.go +253 -0
  718. package/govendor/golang.org/x/net/http2/writesched_common.go +90 -0
  719. package/govendor/golang.org/x/net/http2/writesched_priority_rfc7540.go +420 -0
  720. package/govendor/golang.org/x/net/http2/writesched_priority_rfc9218.go +226 -0
  721. package/govendor/golang.org/x/net/http2/writesched_random.go +81 -0
  722. package/govendor/golang.org/x/net/http2/writesched_roundrobin.go +121 -0
  723. package/govendor/golang.org/x/net/idna/idna.go +884 -0
  724. package/govendor/golang.org/x/net/idna/punycode.go +220 -0
  725. package/govendor/golang.org/x/net/idna/tables15.0.0.go +5144 -0
  726. package/govendor/golang.org/x/net/idna/tables17.0.0.go +5302 -0
  727. package/govendor/golang.org/x/net/idna/trie.go +51 -0
  728. package/govendor/golang.org/x/net/idna/trieval.go +119 -0
  729. package/govendor/golang.org/x/net/internal/httpcommon/README.md +7 -0
  730. package/govendor/golang.org/x/net/internal/httpcommon/ascii.go +53 -0
  731. package/govendor/golang.org/x/net/internal/httpcommon/gzip.go +132 -0
  732. package/govendor/golang.org/x/net/internal/httpcommon/headermap.go +115 -0
  733. package/govendor/golang.org/x/net/internal/httpcommon/request.go +503 -0
  734. package/govendor/golang.org/x/net/internal/httpsfv/httpsfv.go +665 -0
  735. package/govendor/golang.org/x/sys/cpu/asm_aix_ppc64.s +17 -0
  736. package/govendor/golang.org/x/sys/cpu/asm_darwin_arm64_gc.s +12 -0
  737. package/govendor/golang.org/x/sys/cpu/asm_darwin_x86_gc.s +17 -0
  738. package/govendor/golang.org/x/sys/cpu/byteorder.go +66 -0
  739. package/govendor/golang.org/x/sys/cpu/cpu.go +357 -0
  740. package/govendor/golang.org/x/sys/cpu/cpu_aix.go +33 -0
  741. package/govendor/golang.org/x/sys/cpu/cpu_arm.go +73 -0
  742. package/govendor/golang.org/x/sys/cpu/cpu_arm64.go +191 -0
  743. package/govendor/golang.org/x/sys/cpu/cpu_arm64.s +35 -0
  744. package/govendor/golang.org/x/sys/cpu/cpu_darwin_arm64.go +67 -0
  745. package/govendor/golang.org/x/sys/cpu/cpu_darwin_arm64_other.go +31 -0
  746. package/govendor/golang.org/x/sys/cpu/cpu_darwin_x86.go +61 -0
  747. package/govendor/golang.org/x/sys/cpu/cpu_gc_arm64.go +12 -0
  748. package/govendor/golang.org/x/sys/cpu/cpu_gc_riscv64.go +11 -0
  749. package/govendor/golang.org/x/sys/cpu/cpu_gc_s390x.go +21 -0
  750. package/govendor/golang.org/x/sys/cpu/cpu_gc_x86.go +15 -0
  751. package/govendor/golang.org/x/sys/cpu/cpu_gc_x86.s +26 -0
  752. package/govendor/golang.org/x/sys/cpu/cpu_gccgo_arm64.go +12 -0
  753. package/govendor/golang.org/x/sys/cpu/cpu_gccgo_s390x.go +22 -0
  754. package/govendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c +37 -0
  755. package/govendor/golang.org/x/sys/cpu/cpu_gccgo_x86.go +25 -0
  756. package/govendor/golang.org/x/sys/cpu/cpu_linux.go +15 -0
  757. package/govendor/golang.org/x/sys/cpu/cpu_linux_arm.go +39 -0
  758. package/govendor/golang.org/x/sys/cpu/cpu_linux_arm64.go +120 -0
  759. package/govendor/golang.org/x/sys/cpu/cpu_linux_loong64.go +22 -0
  760. package/govendor/golang.org/x/sys/cpu/cpu_linux_mips64x.go +22 -0
  761. package/govendor/golang.org/x/sys/cpu/cpu_linux_noinit.go +9 -0
  762. package/govendor/golang.org/x/sys/cpu/cpu_linux_ppc64x.go +34 -0
  763. package/govendor/golang.org/x/sys/cpu/cpu_linux_riscv64.go +173 -0
  764. package/govendor/golang.org/x/sys/cpu/cpu_linux_s390x.go +40 -0
  765. package/govendor/golang.org/x/sys/cpu/cpu_loong64.go +62 -0
  766. package/govendor/golang.org/x/sys/cpu/cpu_loong64.s +13 -0
  767. package/govendor/golang.org/x/sys/cpu/cpu_mips64x.go +15 -0
  768. package/govendor/golang.org/x/sys/cpu/cpu_mipsx.go +11 -0
  769. package/govendor/golang.org/x/sys/cpu/cpu_netbsd_amd64.go +47 -0
  770. package/govendor/golang.org/x/sys/cpu/cpu_netbsd_arm64.go +173 -0
  771. package/govendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.go +65 -0
  772. package/govendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.s +11 -0
  773. package/govendor/golang.org/x/sys/cpu/cpu_other_arm.go +9 -0
  774. package/govendor/golang.org/x/sys/cpu/cpu_other_arm64.go +11 -0
  775. package/govendor/golang.org/x/sys/cpu/cpu_other_mips64x.go +11 -0
  776. package/govendor/golang.org/x/sys/cpu/cpu_other_ppc64x.go +12 -0
  777. package/govendor/golang.org/x/sys/cpu/cpu_other_riscv64.go +11 -0
  778. package/govendor/golang.org/x/sys/cpu/cpu_other_x86.go +11 -0
  779. package/govendor/golang.org/x/sys/cpu/cpu_ppc64x.go +16 -0
  780. package/govendor/golang.org/x/sys/cpu/cpu_riscv64.go +33 -0
  781. package/govendor/golang.org/x/sys/cpu/cpu_riscv64.s +17 -0
  782. package/govendor/golang.org/x/sys/cpu/cpu_s390x.go +172 -0
  783. package/govendor/golang.org/x/sys/cpu/cpu_s390x.s +57 -0
  784. package/govendor/golang.org/x/sys/cpu/cpu_sparc64.go +12 -0
  785. package/govendor/golang.org/x/sys/cpu/cpu_wasm.go +17 -0
  786. package/govendor/golang.org/x/sys/cpu/cpu_windows.go +26 -0
  787. package/govendor/golang.org/x/sys/cpu/cpu_windows_arm64.go +38 -0
  788. package/govendor/golang.org/x/sys/cpu/cpu_x86.go +259 -0
  789. package/govendor/golang.org/x/sys/cpu/cpu_zos.go +10 -0
  790. package/govendor/golang.org/x/sys/cpu/cpu_zos_s390x.go +25 -0
  791. package/govendor/golang.org/x/sys/cpu/endian_big.go +10 -0
  792. package/govendor/golang.org/x/sys/cpu/endian_little.go +10 -0
  793. package/govendor/golang.org/x/sys/cpu/hwcap_linux.go +71 -0
  794. package/govendor/golang.org/x/sys/cpu/parse.go +55 -0
  795. package/govendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go +53 -0
  796. package/govendor/golang.org/x/sys/cpu/runtime_auxv.go +16 -0
  797. package/govendor/golang.org/x/sys/cpu/runtime_auxv_go121.go +18 -0
  798. package/govendor/golang.org/x/sys/cpu/syscall_aix_gccgo.go +26 -0
  799. package/govendor/golang.org/x/sys/cpu/syscall_aix_ppc64_gc.go +35 -0
  800. package/govendor/golang.org/x/sys/cpu/syscall_darwin_arm64_gc.go +54 -0
  801. package/govendor/golang.org/x/sys/cpu/syscall_darwin_x86_gc.go +98 -0
  802. package/govendor/golang.org/x/sys/cpu/zcpu_windows.go +48 -0
  803. package/govendor/golang.org/x/sys/unix/asm_linux_ppc64x.s +20 -0
  804. package/govendor/golang.org/x/sys/unix/asm_linux_sparc64.s +48 -0
  805. package/govendor/golang.org/x/sys/unix/asm_zos_s390x.s +4 -186
  806. package/govendor/golang.org/x/sys/unix/bpxsvc_zos.s +9 -9
  807. package/govendor/golang.org/x/sys/unix/fcntl_darwin.go +2 -2
  808. package/govendor/golang.org/x/sys/unix/mkerrors.sh +1 -1
  809. package/govendor/golang.org/x/sys/unix/ptrace_zos.go +537 -0
  810. package/govendor/golang.org/x/sys/unix/ptrace_zos_singlestep.go +425 -0
  811. package/govendor/golang.org/x/sys/unix/syscall_darwin.go +1 -0
  812. package/govendor/golang.org/x/sys/unix/syscall_freebsd.go +9 -0
  813. package/govendor/golang.org/x/sys/unix/syscall_linux.go +20 -1
  814. package/govendor/golang.org/x/sys/unix/syscall_linux_sparc64.go +3 -3
  815. package/govendor/golang.org/x/sys/unix/syscall_netbsd.go +9 -0
  816. package/govendor/golang.org/x/sys/unix/syscall_unix_gc.go +1 -1
  817. package/govendor/golang.org/x/sys/unix/syscall_zos_s390x.go +0 -4
  818. package/govendor/golang.org/x/sys/unix/xattr_bsd.go +12 -12
  819. package/govendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go +6 -0
  820. package/govendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go +6 -0
  821. package/govendor/golang.org/x/sys/unix/zerrors_linux.go +32 -0
  822. package/govendor/golang.org/x/sys/unix/zerrors_linux_386.go +2 -0
  823. package/govendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +2 -0
  824. package/govendor/golang.org/x/sys/unix/zerrors_linux_arm.go +2 -0
  825. package/govendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +2 -0
  826. package/govendor/golang.org/x/sys/unix/zerrors_linux_loong64.go +2 -0
  827. package/govendor/golang.org/x/sys/unix/zerrors_linux_mips.go +2 -0
  828. package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +2 -0
  829. package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +2 -0
  830. package/govendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +2 -0
  831. package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +2 -0
  832. package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +2 -0
  833. package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +2 -0
  834. package/govendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +2 -0
  835. package/govendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +2 -0
  836. package/govendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +2 -0
  837. package/govendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +11 -0
  838. package/govendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +11 -0
  839. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go +159 -0
  840. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go +159 -0
  841. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go +159 -0
  842. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm64.go +159 -0
  843. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_riscv64.go +159 -0
  844. package/govendor/golang.org/x/sys/unix/zsyscall_linux.go +28 -1
  845. package/govendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +3 -3
  846. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go +159 -0
  847. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go +159 -0
  848. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go +159 -0
  849. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm64.go +159 -0
  850. package/govendor/golang.org/x/sys/unix/zsysnum_zos_s390x.go +13 -0
  851. package/govendor/golang.org/x/sys/unix/ztypes_linux.go +65 -36
  852. package/govendor/golang.org/x/sys/unix/ztypes_linux_386.go +6 -0
  853. package/govendor/golang.org/x/sys/unix/ztypes_linux_amd64.go +7 -0
  854. package/govendor/golang.org/x/sys/unix/ztypes_linux_arm.go +6 -0
  855. package/govendor/golang.org/x/sys/unix/ztypes_linux_arm64.go +7 -0
  856. package/govendor/golang.org/x/sys/unix/ztypes_linux_loong64.go +7 -0
  857. package/govendor/golang.org/x/sys/unix/ztypes_linux_mips.go +6 -0
  858. package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64.go +7 -0
  859. package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go +7 -0
  860. package/govendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go +6 -0
  861. package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc.go +6 -0
  862. package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go +7 -0
  863. package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go +7 -0
  864. package/govendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go +7 -0
  865. package/govendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +7 -0
  866. package/govendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go +10 -5
  867. package/govendor/golang.org/x/sys/unix/ztypes_zos_s390x.go +78 -0
  868. package/govendor/golang.org/x/text/.gitattributes +10 -0
  869. package/govendor/golang.org/x/text/CONTRIBUTING.md +26 -0
  870. package/govendor/golang.org/x/text/LICENSE +27 -0
  871. package/govendor/golang.org/x/text/PATENTS +22 -0
  872. package/govendor/golang.org/x/text/README.md +81 -0
  873. package/govendor/golang.org/x/text/cases/cases.go +162 -0
  874. package/govendor/golang.org/x/text/cases/context.go +376 -0
  875. package/govendor/golang.org/x/text/cases/fold.go +34 -0
  876. package/govendor/golang.org/x/text/cases/icu.go +61 -0
  877. package/govendor/golang.org/x/text/cases/info.go +82 -0
  878. package/govendor/golang.org/x/text/cases/map.go +816 -0
  879. package/govendor/golang.org/x/text/cases/tables15.0.0.go +2527 -0
  880. package/govendor/golang.org/x/text/cases/tables17.0.0.go +2642 -0
  881. package/govendor/golang.org/x/text/cases/trieval.go +217 -0
  882. package/govendor/golang.org/x/text/codereview.cfg +1 -0
  883. package/govendor/golang.org/x/text/collate/collate.go +402 -0
  884. package/govendor/golang.org/x/text/collate/index.go +32 -0
  885. package/govendor/golang.org/x/text/collate/option.go +239 -0
  886. package/govendor/golang.org/x/text/collate/sort.go +81 -0
  887. package/govendor/golang.org/x/text/collate/tables.go +73789 -0
  888. package/govendor/golang.org/x/text/currency/common.go +67 -0
  889. package/govendor/golang.org/x/text/currency/currency.go +185 -0
  890. package/govendor/golang.org/x/text/currency/format.go +220 -0
  891. package/govendor/golang.org/x/text/currency/query.go +152 -0
  892. package/govendor/golang.org/x/text/currency/tables.go +2629 -0
  893. package/govendor/golang.org/x/text/doc.go +16 -0
  894. package/govendor/golang.org/x/text/feature/plural/common.go +70 -0
  895. package/govendor/golang.org/x/text/feature/plural/message.go +244 -0
  896. package/govendor/golang.org/x/text/feature/plural/plural.go +262 -0
  897. package/govendor/golang.org/x/text/feature/plural/tables.go +552 -0
  898. package/govendor/golang.org/x/text/go.mod +3 -0
  899. package/govendor/golang.org/x/text/internal/catmsg/catmsg.go +417 -0
  900. package/govendor/golang.org/x/text/internal/catmsg/codec.go +407 -0
  901. package/govendor/golang.org/x/text/internal/catmsg/varint.go +62 -0
  902. package/govendor/golang.org/x/text/internal/colltab/collelem.go +374 -0
  903. package/govendor/golang.org/x/text/internal/colltab/colltab.go +105 -0
  904. package/govendor/golang.org/x/text/internal/colltab/contract.go +145 -0
  905. package/govendor/golang.org/x/text/internal/colltab/iter.go +178 -0
  906. package/govendor/golang.org/x/text/internal/colltab/numeric.go +236 -0
  907. package/govendor/golang.org/x/text/internal/colltab/table.go +275 -0
  908. package/govendor/golang.org/x/text/internal/colltab/trie.go +159 -0
  909. package/govendor/golang.org/x/text/internal/colltab/weighter.go +31 -0
  910. package/govendor/golang.org/x/text/internal/format/format.go +41 -0
  911. package/govendor/golang.org/x/text/internal/format/parser.go +358 -0
  912. package/govendor/golang.org/x/text/internal/internal.go +49 -0
  913. package/govendor/golang.org/x/text/internal/language/common.go +16 -0
  914. package/govendor/golang.org/x/text/internal/language/compact/compact.go +61 -0
  915. package/govendor/golang.org/x/text/internal/language/compact/language.go +260 -0
  916. package/govendor/golang.org/x/text/internal/language/compact/parents.go +120 -0
  917. package/govendor/golang.org/x/text/internal/language/compact/tables.go +1015 -0
  918. package/govendor/golang.org/x/text/internal/language/compact/tags.go +91 -0
  919. package/govendor/golang.org/x/text/internal/language/compact.go +29 -0
  920. package/govendor/golang.org/x/text/internal/language/compose.go +167 -0
  921. package/govendor/golang.org/x/text/internal/language/coverage.go +28 -0
  922. package/govendor/golang.org/x/text/internal/language/language.go +627 -0
  923. package/govendor/golang.org/x/text/internal/language/lookup.go +412 -0
  924. package/govendor/golang.org/x/text/internal/language/match.go +226 -0
  925. package/govendor/golang.org/x/text/internal/language/parse.go +608 -0
  926. package/govendor/golang.org/x/text/internal/language/tables.go +3494 -0
  927. package/govendor/golang.org/x/text/internal/language/tags.go +48 -0
  928. package/govendor/golang.org/x/text/internal/match.go +67 -0
  929. package/govendor/golang.org/x/text/internal/number/common.go +55 -0
  930. package/govendor/golang.org/x/text/internal/number/decimal.go +500 -0
  931. package/govendor/golang.org/x/text/internal/number/format.go +533 -0
  932. package/govendor/golang.org/x/text/internal/number/number.go +152 -0
  933. package/govendor/golang.org/x/text/internal/number/pattern.go +485 -0
  934. package/govendor/golang.org/x/text/internal/number/roundingmode_string.go +30 -0
  935. package/govendor/golang.org/x/text/internal/number/tables.go +1219 -0
  936. package/govendor/golang.org/x/text/internal/stringset/set.go +86 -0
  937. package/govendor/golang.org/x/text/internal/tag/tag.go +100 -0
  938. package/govendor/golang.org/x/text/language/coverage.go +187 -0
  939. package/govendor/golang.org/x/text/language/display/dict.go +92 -0
  940. package/govendor/golang.org/x/text/language/display/display.go +420 -0
  941. package/govendor/golang.org/x/text/language/display/lookup.go +253 -0
  942. package/govendor/golang.org/x/text/language/display/tables.go +53114 -0
  943. package/govendor/golang.org/x/text/language/doc.go +98 -0
  944. package/govendor/golang.org/x/text/language/language.go +605 -0
  945. package/govendor/golang.org/x/text/language/match.go +735 -0
  946. package/govendor/golang.org/x/text/language/parse.go +258 -0
  947. package/govendor/golang.org/x/text/language/tables.go +298 -0
  948. package/govendor/golang.org/x/text/language/tags.go +145 -0
  949. package/govendor/golang.org/x/text/message/catalog/catalog.go +365 -0
  950. package/govendor/golang.org/x/text/message/catalog/dict.go +133 -0
  951. package/govendor/golang.org/x/text/secure/bidirule/bidirule.go +346 -0
  952. package/govendor/golang.org/x/text/transform/transform.go +709 -0
  953. package/govendor/golang.org/x/text/unicode/bidi/bidi.go +359 -0
  954. package/govendor/golang.org/x/text/unicode/bidi/bracket.go +335 -0
  955. package/govendor/golang.org/x/text/unicode/bidi/core.go +1050 -0
  956. package/govendor/golang.org/x/text/unicode/bidi/prop.go +206 -0
  957. package/govendor/golang.org/x/text/unicode/bidi/tables15.0.0.go +2042 -0
  958. package/govendor/golang.org/x/text/unicode/bidi/tables17.0.0.go +2135 -0
  959. package/govendor/golang.org/x/text/unicode/bidi/trieval.go +48 -0
  960. package/govendor/golang.org/x/text/unicode/norm/composition.go +524 -0
  961. package/govendor/golang.org/x/text/unicode/norm/forminfo.go +296 -0
  962. package/govendor/golang.org/x/text/unicode/norm/input.go +109 -0
  963. package/govendor/golang.org/x/text/unicode/norm/iter.go +454 -0
  964. package/govendor/golang.org/x/text/unicode/norm/normalize.go +613 -0
  965. package/govendor/golang.org/x/text/unicode/norm/readwriter.go +125 -0
  966. package/govendor/golang.org/x/text/unicode/norm/tables15.0.0.go +7907 -0
  967. package/govendor/golang.org/x/text/unicode/norm/tables17.0.0.go +8104 -0
  968. package/govendor/golang.org/x/text/unicode/norm/transform.go +89 -0
  969. package/govendor/golang.org/x/text/unicode/norm/trie.go +54 -0
  970. package/govendor/manifest.txt +11 -2
  971. package/package.json +2 -1
  972. package/performance/README.md +87 -35
  973. package/performance/arr-for-of.ts +29 -0
  974. package/performance/arr-push-local.ts +39 -0
  975. package/performance/arr-slice-concat.ts +24 -0
  976. package/performance/async-promise-all.ts +38 -0
  977. package/performance/bigint-arith.ts +36 -0
  978. package/performance/buf-encode.ts +29 -0
  979. package/performance/class-accessors.ts +48 -0
  980. package/performance/date-format.ts +18 -0
  981. package/performance/fn-rest-spread.ts +43 -0
  982. package/performance/gen-next.ts +32 -0
  983. package/performance/iter-helpers.ts +38 -0
  984. package/performance/json-any.ts +30 -0
  985. package/performance/map-iterate.ts +26 -0
  986. package/performance/map-number-keys.ts +37 -0
  987. package/performance/num-hash-imul.ts +36 -0
  988. package/performance/obj-keys-entries.ts +44 -0
  989. package/performance/obj-optional-chain.ts +42 -0
  990. package/performance/obj-record-dict.ts +24 -0
  991. package/performance/obj-spread-destructure.ts +40 -0
  992. package/performance/regex-replace-fn.ts +24 -0
  993. package/performance/str-methods.ts +24 -0
  994. package/performance/str-switch-compare.ts +50 -0
  995. package/performance/str-unicode.ts +25 -0
  996. package/performance/typed-array.ts +30 -0
  997. package/performance/union-typeof.ts +40 -0
  998. package/performance/wasm-call.ts +63 -0
  999. package/tsparser/go.mod +1 -1
  1000. package/tsparser/go.sum +2 -2
  1001. package/types/typenative-npm.d.ts +836 -69
  1002. package/types/typenative.d.ts +1224 -23
  1003. package/govendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go +0 -22
  1004. package/govendor/golang.org/x/sys/windows/types_windows_arm.go +0 -35
@@ -0,0 +1,4963 @@
1
+ package interpreter
2
+
3
+ import (
4
+ "context"
5
+ "encoding/binary"
6
+ "errors"
7
+ "fmt"
8
+ "math"
9
+ "math/bits"
10
+ "slices"
11
+ "sync"
12
+ "unsafe"
13
+
14
+ "github.com/tetratelabs/wazero/api"
15
+ "github.com/tetratelabs/wazero/experimental"
16
+ "github.com/tetratelabs/wazero/internal/expctxkeys"
17
+ "github.com/tetratelabs/wazero/internal/filecache"
18
+ "github.com/tetratelabs/wazero/internal/internalapi"
19
+ "github.com/tetratelabs/wazero/internal/moremath"
20
+ "github.com/tetratelabs/wazero/internal/wasm"
21
+ "github.com/tetratelabs/wazero/internal/wasmdebug"
22
+ "github.com/tetratelabs/wazero/internal/wasmruntime"
23
+ )
24
+
25
+ // callStackCeiling is the maximum WebAssembly call frame stack height. This allows wazero to raise
26
+ // wasm.ErrCallStackOverflow instead of overflowing the Go runtime.
27
+ //
28
+ // The default value should suffice for most use cases. Those wishing to change this can via `go build -ldflags`.
29
+ var callStackCeiling = 2000
30
+
31
+ type compiledFunctionWithCount struct {
32
+ funcs []compiledFunction
33
+ refCount int
34
+ }
35
+
36
+ // engine is an interpreter implementation of wasm.Engine
37
+ type engine struct {
38
+ enabledFeatures api.CoreFeatures
39
+ compiledFunctions map[wasm.ModuleID]*compiledFunctionWithCount // guarded by mutex.
40
+ mux sync.Mutex
41
+ }
42
+
43
+ func NewEngine(_ context.Context, enabledFeatures api.CoreFeatures, _ filecache.Cache) wasm.Engine {
44
+ return &engine{
45
+ enabledFeatures: enabledFeatures,
46
+ compiledFunctions: map[wasm.ModuleID]*compiledFunctionWithCount{},
47
+ }
48
+ }
49
+
50
+ // Close implements the same method as documented on wasm.Engine.
51
+ func (e *engine) Close() (err error) {
52
+ e.mux.Lock()
53
+ defer e.mux.Unlock()
54
+ clear(e.compiledFunctions)
55
+ return
56
+ }
57
+
58
+ // CompiledModuleCount implements the same method as documented on wasm.Engine.
59
+ func (e *engine) CompiledModuleCount() uint32 {
60
+ e.mux.Lock()
61
+ defer e.mux.Unlock()
62
+ return uint32(len(e.compiledFunctions))
63
+ }
64
+
65
+ // DeleteCompiledModule implements the same method as documented on wasm.Engine.
66
+ func (e *engine) DeleteCompiledModule(m *wasm.Module) {
67
+ e.deleteCompiledFunctions(m)
68
+ }
69
+
70
+ func (e *engine) deleteCompiledFunctions(module *wasm.Module) {
71
+ e.mux.Lock()
72
+ defer e.mux.Unlock()
73
+ cf, ok := e.compiledFunctions[module.ID]
74
+ if !ok {
75
+ return
76
+ }
77
+ cf.refCount--
78
+ if cf.refCount > 0 {
79
+ return
80
+ }
81
+ delete(e.compiledFunctions, module.ID)
82
+ }
83
+
84
+ func (e *engine) addCompiledFunctions(module *wasm.Module, fs []compiledFunction) {
85
+ e.mux.Lock()
86
+ defer e.mux.Unlock()
87
+ if c, ok := e.compiledFunctions[module.ID]; ok {
88
+ c.refCount++
89
+ return
90
+ }
91
+ e.compiledFunctions[module.ID] = &compiledFunctionWithCount{funcs: fs, refCount: 1}
92
+ }
93
+
94
+ func (e *engine) getCompiledFunctions(module *wasm.Module, increaseRefCount bool) (fs []compiledFunction, ok bool) {
95
+ e.mux.Lock()
96
+ defer e.mux.Unlock()
97
+ cf, ok := e.compiledFunctions[module.ID]
98
+ if ok {
99
+ fs = cf.funcs
100
+ if increaseRefCount {
101
+ cf.refCount++
102
+ }
103
+ }
104
+ return
105
+ }
106
+
107
+ // moduleEngine implements wasm.ModuleEngine
108
+ type moduleEngine struct {
109
+ // codes are the compiled functions in a module instances.
110
+ // The index is module instance-scoped.
111
+ functions []function
112
+
113
+ // parentEngine holds *engine from which this module engine is created from.
114
+ parentEngine *engine
115
+ }
116
+
117
+ // GetGlobalValue implements the same method as documented on wasm.ModuleEngine.
118
+ func (e *moduleEngine) GetGlobalValue(wasm.Index) (lo, hi uint64) {
119
+ panic("BUG: GetGlobalValue should never be called on interpreter mode")
120
+ }
121
+
122
+ // SetGlobalValue implements the same method as documented on wasm.ModuleEngine.
123
+ func (e *moduleEngine) SetGlobalValue(idx wasm.Index, lo, hi uint64) {
124
+ panic("BUG: SetGlobalValue should never be called on interpreter mode")
125
+ }
126
+
127
+ // OwnsGlobals implements the same method as documented on wasm.ModuleEngine.
128
+ func (e *moduleEngine) OwnsGlobals() bool { return false }
129
+
130
+ // MemoryGrown implements wasm.ModuleEngine.
131
+ func (e *moduleEngine) MemoryGrown() {}
132
+
133
+ // restorable is implemented by panic values that can restore callEngine state.
134
+ // Both *snapshot (snapshotter API) and *thrownException (exception handling)
135
+ // implement this interface.
136
+ type restorable interface {
137
+ // canRestore unwinds ce.frames to callerFrameCount and checks whether a
138
+ // handler exists at that depth. If no handler is found, the caller
139
+ // re-panics and the next outer callWithUnwind unwinds further.
140
+ canRestore(ce *callEngine, callerFrameCount int) bool
141
+ // doRestore restores the callEngine state to the given stack frame depth.
142
+ doRestore(ce *callEngine, callerFrameCount int)
143
+ }
144
+
145
+ // thrownException is the panic value for wasm exception propagation.
146
+ type thrownException struct {
147
+ exception *wasm.Exception
148
+ // Fields populated by canRestore for doRestore.
149
+ clause *exceptionTableCatchClause
150
+ values []uint64
151
+ }
152
+
153
+ func (t *thrownException) canRestore(ce *callEngine, callerFrameCount int) bool {
154
+ ce.frames = ce.frames[:callerFrameCount]
155
+ frame := ce.frames[callerFrameCount-1]
156
+ t.clause, t.values = searchExceptionTable(t.exception, frame)
157
+ return t.clause != nil
158
+ }
159
+
160
+ func (t *thrownException) doRestore(ce *callEngine, callerFrameCount int) {
161
+ frame := ce.frames[callerFrameCount-1]
162
+ ce.applyExceptionHandler(frame, t.clause, t.values)
163
+ t.clause, t.values = nil, nil
164
+ }
165
+
166
+ // callEngine holds context per moduleEngine.Call, and shared across all the
167
+ // function calls originating from the same moduleEngine.Call execution.
168
+ //
169
+ // This implements api.Function.
170
+ type callEngine struct {
171
+ internalapi.WazeroOnlyType
172
+
173
+ // stack contains the operands.
174
+ // Note that all the values are represented as uint64.
175
+ stack []uint64
176
+
177
+ // frames are the function call stack.
178
+ frames []*callFrame
179
+
180
+ // f is the initial function for this call engine.
181
+ f *function
182
+
183
+ // stackiterator for Listeners to walk frames and stack.
184
+ stackIterator stackIterator
185
+ }
186
+
187
+ // matchCatchClause checks whether a single catch clause matches the given exception.
188
+ // Returns whether it matched and the values to push onto the stack.
189
+ func matchCatchClause(kind byte, clauseTag *wasm.TagInstance, exn *wasm.Exception) (matched bool, values []uint64) {
190
+ switch kind {
191
+ case wasm.CatchKindCatch:
192
+ if exn.Tag == clauseTag {
193
+ return true, slices.Clone(exn.Params)
194
+ }
195
+ case wasm.CatchKindCatchRef:
196
+ if exn.Tag == clauseTag {
197
+ values = slices.Clone(exn.Params)
198
+ values = append(values, uint64(uintptr(unsafe.Pointer(exn))))
199
+ return true, values
200
+ }
201
+ case wasm.CatchKindCatchAll:
202
+ return true, nil
203
+ case wasm.CatchKindCatchAllRef:
204
+ return true, []uint64{uint64(uintptr(unsafe.Pointer(exn)))}
205
+ }
206
+ return false, nil
207
+ }
208
+
209
+ // searchExceptionTable searches the compiled function's static exception table
210
+ // for a handler matching the given exception at the current PC. Returns the
211
+ // matched clause and catch values, or nil if no handler matches. Searches
212
+ // backwards so inner try_tables (which have higher indices) are checked first.
213
+ // This function is pure — it does not modify callEngine state.
214
+ func searchExceptionTable(exn *wasm.Exception, frame *callFrame) (*exceptionTableCatchClause, []uint64) {
215
+ table := frame.f.parent.exceptionTable
216
+ pc := frame.pc
217
+ for i := len(table) - 1; i >= 0; i-- {
218
+ entry := &table[i]
219
+ if pc < entry.startPC || pc >= entry.endPC {
220
+ continue
221
+ }
222
+ for j := range entry.clauses {
223
+ clause := &entry.clauses[j]
224
+ var clauseTag *wasm.TagInstance
225
+ if clause.kind == wasm.CatchKindCatch || clause.kind == wasm.CatchKindCatchRef {
226
+ clauseTag = frame.f.moduleInstance.Tags[clause.tagIndex]
227
+ }
228
+ matched, values := matchCatchClause(clause.kind, clauseTag, exn)
229
+ if matched {
230
+ return clause, values
231
+ }
232
+ }
233
+ }
234
+ return nil, nil
235
+ }
236
+
237
+ // applyExceptionHandler applies a matched exception table clause to the callEngine state.
238
+ func (ce *callEngine) applyExceptionHandler(frame *callFrame, clause *exceptionTableCatchClause, values []uint64) {
239
+ ce.stack = ce.stack[:frame.base-frame.f.funcType.ParamNumInUint64+clause.targetStackDepth]
240
+ ce.stack = append(ce.stack, values...)
241
+ frame.pc = clause.targetPC
242
+ }
243
+
244
+ // callWithUnwind calls the target function with support for stack unwinding
245
+ // (exception handling and snapshot restores). Returns true if the frame was
246
+ // unwound (caller should refresh frame/body/bodyLen and continue the loop).
247
+ // Returns false on normal return (caller should do frame.pc++).
248
+ func (ce *callEngine) callWithUnwind(ctx context.Context, m *wasm.ModuleInstance, tf *function) bool {
249
+ // Short-circuit: skip defer/recover overhead when neither exception
250
+ // handlers nor the snapshotter are active for the calling frame.
251
+ frame := ce.frames[len(ce.frames)-1]
252
+ if len(frame.f.parent.exceptionTable) == 0 && ctx.Value(expctxkeys.EnableSnapshotterKey{}) == nil {
253
+ ce.callFunction(ctx, m, tf)
254
+ return false
255
+ }
256
+
257
+ callerFrameCount := len(ce.frames)
258
+ caught := false
259
+ func() {
260
+ defer func() {
261
+ if r := recover(); r != nil {
262
+ if v, ok := r.(restorable); ok && v.canRestore(ce, callerFrameCount) {
263
+ v.doRestore(ce, callerFrameCount)
264
+ caught = true
265
+ return
266
+ }
267
+ panic(r)
268
+ }
269
+ }()
270
+ ce.callFunction(ctx, m, tf)
271
+ }()
272
+ return caught
273
+ }
274
+
275
+ func (e *moduleEngine) newCallEngine(compiled *function) *callEngine {
276
+ return &callEngine{f: compiled}
277
+ }
278
+
279
+ func (ce *callEngine) pushValue(v uint64) {
280
+ ce.stack = append(ce.stack, v)
281
+ }
282
+
283
+ func (ce *callEngine) pushValues(v []uint64) {
284
+ ce.stack = append(ce.stack, v...)
285
+ }
286
+
287
+ func (ce *callEngine) popValue() (v uint64) {
288
+ // No need to check stack bound
289
+ // as we can assume that all the operations
290
+ // are valid thanks to validateFunction
291
+ // at module validation phase
292
+ // and interpreterir translation
293
+ // before compilation.
294
+ stackTopIndex := len(ce.stack) - 1
295
+ v = ce.stack[stackTopIndex]
296
+ ce.stack = ce.stack[:stackTopIndex]
297
+ return
298
+ }
299
+
300
+ func (ce *callEngine) popValues(v []uint64) {
301
+ stackTopIndex := len(ce.stack) - len(v)
302
+ copy(v, ce.stack[stackTopIndex:])
303
+ ce.stack = ce.stack[:stackTopIndex]
304
+ }
305
+
306
+ // peekValues peeks api.ValueType values from the stack and returns them.
307
+ func (ce *callEngine) peekValues(count int) []uint64 {
308
+ if count == 0 {
309
+ return nil
310
+ }
311
+ stackLen := len(ce.stack)
312
+ return ce.stack[stackLen-count : stackLen]
313
+ }
314
+
315
+ func (ce *callEngine) drop(raw uint64) {
316
+ r := inclusiveRangeFromU64(raw)
317
+ if r.Start == -1 {
318
+ return
319
+ } else if r.Start == 0 {
320
+ ce.stack = ce.stack[:int32(len(ce.stack))-1-r.End]
321
+ } else {
322
+ newStack := ce.stack[:int32(len(ce.stack))-1-r.End]
323
+ newStack = append(newStack, ce.stack[int32(len(ce.stack))-r.Start:]...)
324
+ ce.stack = newStack
325
+ }
326
+ }
327
+
328
+ func (ce *callEngine) pushFrame(frame *callFrame) {
329
+ if callStackCeiling <= len(ce.frames) {
330
+ panic(wasmruntime.ErrRuntimeStackOverflow)
331
+ }
332
+ ce.frames = append(ce.frames, frame)
333
+ }
334
+
335
+ func (ce *callEngine) popFrame() (frame *callFrame) {
336
+ // No need to check stack bound as we can assume that all the operations are valid thanks to validateFunction at
337
+ // module validation phase and interpreterir translation before compilation.
338
+ oneLess := len(ce.frames) - 1
339
+ frame = ce.frames[oneLess]
340
+ ce.frames = ce.frames[:oneLess]
341
+ return
342
+ }
343
+
344
+ type callFrame struct {
345
+ // pc is the program counter representing the current position in code.body.
346
+ pc uint64
347
+ // f is the compiled function used in this function frame.
348
+ f *function
349
+ // base index in the frame of this function, used to detect the count of
350
+ // values on the stack.
351
+ base int
352
+ }
353
+
354
+ type compiledFunction struct {
355
+ source *wasm.Module
356
+ body []unionOperation
357
+ exceptionTable []exceptionTableEntry
358
+ listener experimental.FunctionListener
359
+ offsetsInWasmBinary []uint64
360
+ hostFn interface{}
361
+ ensureTermination bool
362
+ index wasm.Index
363
+ }
364
+
365
+ type function struct {
366
+ funcType *wasm.FunctionType
367
+ moduleInstance *wasm.ModuleInstance
368
+ typeID wasm.FunctionTypeID
369
+ parent *compiledFunction
370
+ }
371
+
372
+ // functionFromUintptr resurrects the original *function from the given uintptr
373
+ // which comes from either funcref table or OpcodeRefFunc instruction.
374
+ func functionFromUintptr(ptr uintptr) *function {
375
+ // Wraps ptrs as the double pointer in order to avoid the unsafe access as detected by race detector.
376
+ //
377
+ // For example, if we have (*function)(unsafe.Pointer(ptr)) instead, then the race detector's "checkptr"
378
+ // subroutine wanrs as "checkptr: pointer arithmetic result points to invalid allocation"
379
+ // https://github.com/golang/go/blob/go1.24.0/src/runtime/checkptr.go#L69
380
+ var wrapped *uintptr = &ptr
381
+ return *(**function)(unsafe.Pointer(wrapped))
382
+ }
383
+
384
+ type snapshot struct {
385
+ stack []uint64
386
+ frames []*callFrame
387
+ pc uint64
388
+
389
+ ret []uint64
390
+
391
+ ce *callEngine
392
+ }
393
+
394
+ // Snapshot implements the same method as documented on experimental.Snapshotter.
395
+ func (ce *callEngine) Snapshot() experimental.Snapshot {
396
+ return &snapshot{
397
+ stack: slices.Clone(ce.stack),
398
+ frames: slices.Clone(ce.frames),
399
+ ce: ce,
400
+ }
401
+ }
402
+
403
+ // Restore implements the same method as documented on experimental.Snapshot.
404
+ func (s *snapshot) Restore(ret []uint64) {
405
+ s.ret = ret
406
+ panic(s)
407
+ }
408
+
409
+ func (s *snapshot) canRestore(ce *callEngine, _ int) bool {
410
+ return s.ce == ce
411
+ }
412
+
413
+ func (s *snapshot) doRestore(_ *callEngine, _ int) {
414
+ ce := s.ce
415
+
416
+ ce.stack = s.stack
417
+ ce.frames = s.frames
418
+ ce.frames[len(ce.frames)-1].pc = s.pc
419
+
420
+ copy(ce.stack[len(ce.stack)-len(s.ret):], s.ret)
421
+ }
422
+
423
+ // Error implements the same method on error.
424
+ func (s *snapshot) Error() string {
425
+ return "unhandled snapshot restore, this generally indicates restore was called from a different " +
426
+ "exported function invocation than snapshot"
427
+ }
428
+
429
+ // stackIterator implements experimental.StackIterator.
430
+ type stackIterator struct {
431
+ stack []uint64
432
+ frames []*callFrame
433
+ started bool
434
+ fn *function
435
+ pc uint64
436
+ }
437
+
438
+ func (si *stackIterator) reset(stack []uint64, frames []*callFrame, f *function) {
439
+ si.fn = f
440
+ si.pc = 0
441
+ si.stack = stack
442
+ si.frames = frames
443
+ si.started = false
444
+ }
445
+
446
+ func (si *stackIterator) clear() {
447
+ si.stack = nil
448
+ si.frames = nil
449
+ si.started = false
450
+ si.fn = nil
451
+ }
452
+
453
+ // Next implements the same method as documented on experimental.StackIterator.
454
+ func (si *stackIterator) Next() bool {
455
+ if !si.started {
456
+ si.started = true
457
+ return true
458
+ }
459
+
460
+ if len(si.frames) == 0 {
461
+ return false
462
+ }
463
+
464
+ frame := si.frames[len(si.frames)-1]
465
+ si.stack = si.stack[:frame.base]
466
+ si.fn = frame.f
467
+ si.pc = frame.pc
468
+ si.frames = si.frames[:len(si.frames)-1]
469
+ return true
470
+ }
471
+
472
+ // Function implements the same method as documented on
473
+ // experimental.StackIterator.
474
+ func (si *stackIterator) Function() experimental.InternalFunction {
475
+ return internalFunction{si.fn}
476
+ }
477
+
478
+ // ProgramCounter implements the same method as documented on
479
+ // experimental.StackIterator.
480
+ func (si *stackIterator) ProgramCounter() experimental.ProgramCounter {
481
+ return experimental.ProgramCounter(si.pc)
482
+ }
483
+
484
+ // internalFunction implements experimental.InternalFunction.
485
+ type internalFunction struct{ *function }
486
+
487
+ // Definition implements the same method as documented on
488
+ // experimental.InternalFunction.
489
+ func (f internalFunction) Definition() api.FunctionDefinition {
490
+ return f.definition()
491
+ }
492
+
493
+ // SourceOffsetForPC implements the same method as documented on
494
+ // experimental.InternalFunction.
495
+ func (f internalFunction) SourceOffsetForPC(pc experimental.ProgramCounter) uint64 {
496
+ offsetsMap := f.parent.offsetsInWasmBinary
497
+ if uint64(pc) < uint64(len(offsetsMap)) {
498
+ return offsetsMap[pc]
499
+ }
500
+ return 0
501
+ }
502
+
503
+ // interpreter mode doesn't maintain call frames in the stack, so pass the zero size to the IR.
504
+ const callFrameStackSize = 0
505
+
506
+ // CompileModule implements the same method as documented on wasm.Engine.
507
+ func (e *engine) CompileModule(_ context.Context, module *wasm.Module, listeners []experimental.FunctionListener, ensureTermination bool) error {
508
+ if _, ok := e.getCompiledFunctions(module, true); ok { // cache hit!
509
+ return nil
510
+ }
511
+
512
+ funcs := make([]compiledFunction, len(module.FunctionSection))
513
+ irCompiler, err := newCompiler(e.enabledFeatures, callFrameStackSize, module, ensureTermination)
514
+ if err != nil {
515
+ return err
516
+ }
517
+ imported := module.ImportFunctionCount
518
+ for i := range module.CodeSection {
519
+ var lsn experimental.FunctionListener
520
+ if i < len(listeners) {
521
+ lsn = listeners[i]
522
+ }
523
+
524
+ compiled := &funcs[i]
525
+ // If this is the host function, there's nothing to do as the runtime representation of
526
+ // host function in interpreter is its Go function itself as opposed to Wasm functions,
527
+ // which need to be compiled down to
528
+ if codeSeg := &module.CodeSection[i]; codeSeg.GoFunc != nil {
529
+ compiled.hostFn = codeSeg.GoFunc
530
+ } else {
531
+ ir, err := irCompiler.Next()
532
+ if err != nil {
533
+ return err
534
+ }
535
+ err = e.lowerIR(ir, compiled)
536
+ if err != nil {
537
+ def := module.FunctionDefinition(uint32(i) + module.ImportFunctionCount)
538
+ return fmt.Errorf("failed to lower func[%s] to interpreterir: %w", def.DebugName(), err)
539
+ }
540
+ }
541
+ compiled.source = module
542
+ compiled.ensureTermination = ensureTermination
543
+ compiled.listener = lsn
544
+ compiled.index = imported + uint32(i)
545
+ }
546
+ e.addCompiledFunctions(module, funcs)
547
+ return nil
548
+ }
549
+
550
+ // NewModuleEngine implements the same method as documented on wasm.Engine.
551
+ func (e *engine) NewModuleEngine(module *wasm.Module, instance *wasm.ModuleInstance) (wasm.ModuleEngine, error) {
552
+ me := &moduleEngine{
553
+ parentEngine: e,
554
+ functions: make([]function, len(module.FunctionSection)+int(module.ImportFunctionCount)),
555
+ }
556
+
557
+ codes, ok := e.getCompiledFunctions(module, false)
558
+ if !ok {
559
+ return nil, errors.New("source module must be compiled before instantiation")
560
+ }
561
+
562
+ for i := range codes {
563
+ c := &codes[i]
564
+ offset := i + int(module.ImportFunctionCount)
565
+ typeIndex := module.FunctionSection[i]
566
+ me.functions[offset] = function{
567
+ moduleInstance: instance,
568
+ typeID: instance.TypeIDs[typeIndex],
569
+ funcType: &module.TypeSection[typeIndex],
570
+ parent: c,
571
+ }
572
+ }
573
+ return me, nil
574
+ }
575
+
576
+ // lowerIR lowers the interpreterir operations to engine friendly struct.
577
+ func (e *engine) lowerIR(ir *compilationResult, ret *compiledFunction) error {
578
+ // Copy the body from the result.
579
+ ret.body = slices.Clone(ir.Operations)
580
+ // Also copy the offsets if necessary.
581
+ if offsets := ir.IROperationSourceOffsetsInWasmBinary; len(offsets) > 0 {
582
+ ret.offsetsInWasmBinary = slices.Clone(offsets)
583
+ }
584
+
585
+ labelAddressResolutions := [labelKindNum][]uint64{}
586
+
587
+ // First, we iterate all labels, and resolve the address.
588
+ for i := range ret.body {
589
+ op := &ret.body[i]
590
+ switch op.Kind {
591
+ case operationKindLabel:
592
+ label := label(op.U1)
593
+ address := uint64(i)
594
+
595
+ kind, fid := label.Kind(), label.FrameID()
596
+ frameToAddresses := labelAddressResolutions[label.Kind()]
597
+ // Expand the slice if necessary.
598
+ if diff := fid - len(frameToAddresses) + 1; diff > 0 {
599
+ frameToAddresses = append(frameToAddresses, make([]uint64, diff)...)
600
+ }
601
+ frameToAddresses[fid] = address
602
+ labelAddressResolutions[kind] = frameToAddresses
603
+ }
604
+ }
605
+
606
+ // Then resolve the label as the index to the body.
607
+ for i := range ret.body {
608
+ op := &ret.body[i]
609
+ switch op.Kind {
610
+ case operationKindBr:
611
+ e.setLabelAddress(&op.U1, label(op.U1), labelAddressResolutions)
612
+ case operationKindBrIf:
613
+ e.setLabelAddress(&op.U1, label(op.U1), labelAddressResolutions)
614
+ e.setLabelAddress(&op.U2, label(op.U2), labelAddressResolutions)
615
+ case operationKindBrTable:
616
+ for j := 0; j < len(op.Us); j += 2 {
617
+ target := op.Us[j]
618
+ e.setLabelAddress(&op.Us[j], label(target), labelAddressResolutions)
619
+ }
620
+ case operationKindTailCallReturnCallIndirect:
621
+ e.setLabelAddress(&op.Us[1], label(op.Us[1]), labelAddressResolutions)
622
+ case operationKindBrOnNull:
623
+ e.setLabelAddress(&op.U1, label(op.U1), labelAddressResolutions)
624
+ e.setLabelAddress(&op.U2, label(op.U2), labelAddressResolutions)
625
+ case operationKindBrOnNonNull:
626
+ e.setLabelAddress(&op.U1, label(op.U1), labelAddressResolutions)
627
+ e.setLabelAddress(&op.U2, label(op.U2), labelAddressResolutions)
628
+ case operationKindReturnCallRef:
629
+ e.setLabelAddress(&op.Us[1], label(op.Us[1]), labelAddressResolutions)
630
+ }
631
+ }
632
+
633
+ // Resolve exception table entries (translate labels to PC).
634
+ if len(ir.PendingExceptionTable) > 0 {
635
+ ret.exceptionTable = make([]exceptionTableEntry, len(ir.PendingExceptionTable))
636
+ for i, pe := range ir.PendingExceptionTable {
637
+ contLabel := newLabel(labelKindContinuation, pe.continuationFrameID)
638
+ var endPC uint64
639
+ e.setLabelAddress(&endPC, contLabel, labelAddressResolutions)
640
+
641
+ clauses := make([]exceptionTableCatchClause, len(pe.clauses))
642
+ for j, clause := range pe.clauses {
643
+ var targetPC uint64
644
+ e.setLabelAddress(&targetPC, clause.targetLabel, labelAddressResolutions)
645
+ clauses[j] = exceptionTableCatchClause{
646
+ kind: clause.kind,
647
+ tagIndex: clause.tagIndex,
648
+ targetPC: targetPC,
649
+ targetStackDepth: clause.targetStackDepth,
650
+ }
651
+ }
652
+
653
+ ret.exceptionTable[i] = exceptionTableEntry{
654
+ startPC: uint64(pe.startOpIndex),
655
+ endPC: endPC,
656
+ clauses: clauses,
657
+ }
658
+ }
659
+ }
660
+
661
+ return nil
662
+ }
663
+
664
+ func (e *engine) setLabelAddress(op *uint64, label label, labelAddressResolutions [labelKindNum][]uint64) {
665
+ if label.IsReturnTarget() {
666
+ // Jmp to the end of the possible binary.
667
+ *op = math.MaxUint64
668
+ } else {
669
+ *op = labelAddressResolutions[label.Kind()][label.FrameID()]
670
+ }
671
+ }
672
+
673
+ // ResolveImportedFunction implements wasm.ModuleEngine.
674
+ func (e *moduleEngine) ResolveImportedFunction(index, descFunc, indexInImportedModule wasm.Index, importedModuleEngine wasm.ModuleEngine) {
675
+ imported := importedModuleEngine.(*moduleEngine)
676
+ e.functions[index] = imported.functions[indexInImportedModule]
677
+ }
678
+
679
+ // ResolveImportedMemory implements wasm.ModuleEngine.
680
+ func (e *moduleEngine) ResolveImportedMemory(wasm.ModuleEngine) {}
681
+
682
+ // DoneInstantiation implements wasm.ModuleEngine.
683
+ func (e *moduleEngine) DoneInstantiation() {}
684
+
685
+ // FunctionInstanceReference implements the same method as documented on wasm.ModuleEngine.
686
+ func (e *moduleEngine) FunctionInstanceReference(funcIndex wasm.Index) wasm.Reference {
687
+ return uintptr(unsafe.Pointer(&e.functions[funcIndex]))
688
+ }
689
+
690
+ // NewFunction implements the same method as documented on wasm.ModuleEngine.
691
+ func (e *moduleEngine) NewFunction(index wasm.Index) (ce api.Function) {
692
+ // Note: The input parameters are pre-validated, so a compiled function is only absent on close. Updates to
693
+ // code on close aren't locked, neither is this read.
694
+ compiled := &e.functions[index]
695
+ return e.newCallEngine(compiled)
696
+ }
697
+
698
+ // LookupFunction implements the same method as documented on wasm.ModuleEngine.
699
+ func (e *moduleEngine) LookupFunction(t *wasm.TableInstance, typeId wasm.FunctionTypeID, tableOffset wasm.Index) (*wasm.ModuleInstance, wasm.Index) {
700
+ if tableOffset >= uint32(len(t.References)) {
701
+ panic(wasmruntime.ErrRuntimeInvalidTableAccess)
702
+ }
703
+ rawPtr := t.References[tableOffset]
704
+ if rawPtr == 0 {
705
+ panic(wasmruntime.ErrRuntimeInvalidTableAccess)
706
+ }
707
+
708
+ tf := functionFromUintptr(rawPtr)
709
+ if tf.typeID != typeId {
710
+ panic(wasmruntime.ErrRuntimeIndirectCallTypeMismatch)
711
+ }
712
+ return tf.moduleInstance, tf.parent.index
713
+ }
714
+
715
+ // Definition implements the same method as documented on api.Function.
716
+ func (ce *callEngine) Definition() api.FunctionDefinition {
717
+ return ce.f.definition()
718
+ }
719
+
720
+ func (f *function) definition() api.FunctionDefinition {
721
+ compiled := f.parent
722
+ return compiled.source.FunctionDefinition(compiled.index)
723
+ }
724
+
725
+ // Call implements the same method as documented on api.Function.
726
+ func (ce *callEngine) Call(ctx context.Context, params ...uint64) (results []uint64, err error) {
727
+ ft := ce.f.funcType
728
+ if n := ft.ParamNumInUint64; n != len(params) {
729
+ return nil, fmt.Errorf("expected %d params, but passed %d", n, len(params))
730
+ }
731
+ return ce.call(ctx, params, nil)
732
+ }
733
+
734
+ // CallWithStack implements the same method as documented on api.Function.
735
+ func (ce *callEngine) CallWithStack(ctx context.Context, stack []uint64) error {
736
+ params, results, err := wasm.SplitCallStack(ce.f.funcType, stack)
737
+ if err != nil {
738
+ return err
739
+ }
740
+ _, err = ce.call(ctx, params, results)
741
+ return err
742
+ }
743
+
744
+ func (ce *callEngine) call(ctx context.Context, params, results []uint64) (_ []uint64, err error) {
745
+ m := ce.f.moduleInstance
746
+ if ce.f.parent.ensureTermination {
747
+ select {
748
+ case <-ctx.Done():
749
+ // If the provided context is already done, close the call context
750
+ // and return the error.
751
+ m.CloseWithCtxErr(ctx)
752
+ return nil, m.FailIfClosed()
753
+ default:
754
+ }
755
+ }
756
+
757
+ if ctx.Value(expctxkeys.EnableSnapshotterKey{}) != nil {
758
+ ctx = context.WithValue(ctx, expctxkeys.SnapshotterKey{}, ce)
759
+ }
760
+
761
+ defer func() {
762
+ // If the module closed during the call, and the call didn't err for another reason, set an ExitError.
763
+ if err == nil {
764
+ err = m.FailIfClosed()
765
+ }
766
+ // TODO: ^^ Will not fail if the function was imported from a closed module.
767
+
768
+ if v := recover(); v != nil {
769
+ err = ce.recoverOnCall(ctx, m, v)
770
+ }
771
+ }()
772
+
773
+ ce.pushValues(params)
774
+
775
+ if ce.f.parent.ensureTermination {
776
+ done := m.CloseModuleOnCanceledOrTimeout(ctx)
777
+ defer done()
778
+ }
779
+
780
+ ce.callFunction(ctx, m, ce.f)
781
+
782
+ // This returns a safe copy of the results, instead of a slice view. If we
783
+ // returned a re-slice, the caller could accidentally or purposefully
784
+ // corrupt the stack of subsequent calls.
785
+ ft := ce.f.funcType
786
+ if results == nil && ft.ResultNumInUint64 > 0 {
787
+ results = make([]uint64, ft.ResultNumInUint64)
788
+ }
789
+ ce.popValues(results)
790
+ return results, nil
791
+ }
792
+
793
+ // functionListenerInvocation captures arguments needed to perform function
794
+ // listener invocations when unwinding the call stack.
795
+ type functionListenerInvocation struct {
796
+ experimental.FunctionListener
797
+ def api.FunctionDefinition
798
+ }
799
+
800
+ // recoverOnCall takes the recovered value `recoverOnCall`, and wraps it
801
+ // with the call frame stack traces. Also, reset the state of callEngine
802
+ // so that it can be used for the subsequent calls.
803
+ func (ce *callEngine) recoverOnCall(ctx context.Context, m *wasm.ModuleInstance, v interface{}) (err error) {
804
+ if s, ok := v.(*snapshot); ok {
805
+ // A snapshot that wasn't handled was created by a different call engine possibly from a nested wasm invocation,
806
+ // let it propagate up to be handled by the caller.
807
+ panic(s)
808
+ }
809
+
810
+ // If an exception reached the top level without being caught, convert it to an uncaught exception error.
811
+ if _, ok := v.(*thrownException); ok {
812
+ v = wasmruntime.ErrRuntimeUncaughtException
813
+ }
814
+
815
+ builder := wasmdebug.NewErrorBuilder()
816
+ frameCount := len(ce.frames)
817
+ functionListeners := make([]functionListenerInvocation, 0, 16)
818
+
819
+ if frameCount > wasmdebug.MaxFrames {
820
+ frameCount = wasmdebug.MaxFrames
821
+ }
822
+ for i := 0; i < frameCount; i++ {
823
+ frame := ce.popFrame()
824
+ f := frame.f
825
+ def := f.definition()
826
+ var sources []string
827
+ if parent := frame.f.parent; parent.body != nil && len(parent.offsetsInWasmBinary) > 0 {
828
+ sources = parent.source.DWARFLines.Line(parent.offsetsInWasmBinary[frame.pc])
829
+ }
830
+ builder.AddFrame(def.DebugName(), def.ParamTypes(), def.ResultTypes(), sources)
831
+ if f.parent.listener != nil {
832
+ functionListeners = append(functionListeners, functionListenerInvocation{
833
+ FunctionListener: f.parent.listener,
834
+ def: f.definition(),
835
+ })
836
+ }
837
+ }
838
+
839
+ err = builder.FromRecovered(v)
840
+ for i := range functionListeners {
841
+ functionListeners[i].Abort(ctx, m, functionListeners[i].def, err)
842
+ }
843
+
844
+ // Allows the reuse of CallEngine.
845
+ ce.stack, ce.frames = ce.stack[:0], ce.frames[:0]
846
+ return
847
+ }
848
+
849
+ func (ce *callEngine) callFunction(ctx context.Context, m *wasm.ModuleInstance, f *function) {
850
+ if f.parent.hostFn != nil {
851
+ ce.callGoFuncWithStack(ctx, m, f)
852
+ } else if lsn := f.parent.listener; lsn != nil {
853
+ ce.callNativeFuncWithListener(ctx, m, f, lsn)
854
+ } else {
855
+ ce.callNativeFunc(ctx, m, f)
856
+ }
857
+ }
858
+
859
+ func (ce *callEngine) callGoFunc(ctx context.Context, m *wasm.ModuleInstance, f *function, stack []uint64) {
860
+ typ := f.funcType
861
+ lsn := f.parent.listener
862
+ if lsn != nil {
863
+ params := stack[:typ.ParamNumInUint64]
864
+ ce.stackIterator.reset(ce.stack, ce.frames, f)
865
+ lsn.Before(ctx, m, f.definition(), params, &ce.stackIterator)
866
+ ce.stackIterator.clear()
867
+ }
868
+ frame := &callFrame{f: f, base: len(ce.stack)}
869
+ ce.pushFrame(frame)
870
+
871
+ fn := f.parent.hostFn
872
+ switch fn := fn.(type) {
873
+ case api.GoModuleFunction:
874
+ fn.Call(ctx, m, stack)
875
+ case api.GoFunction:
876
+ fn.Call(ctx, stack)
877
+ }
878
+
879
+ ce.popFrame()
880
+ if lsn != nil {
881
+ // TODO: This doesn't get the error due to use of panic to propagate them.
882
+ results := stack[:typ.ResultNumInUint64]
883
+ lsn.After(ctx, m, f.definition(), results)
884
+ }
885
+ }
886
+
887
+ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance, f *function) {
888
+ frame := &callFrame{f: f, base: len(ce.stack)}
889
+ moduleInst := f.moduleInstance
890
+ functions := moduleInst.Engine.(*moduleEngine).functions
891
+ memoryInst := moduleInst.MemoryInstance
892
+ globals := moduleInst.Globals
893
+ tables := moduleInst.Tables
894
+ typeIDs := moduleInst.TypeIDs
895
+ dataInstances := moduleInst.DataInstances
896
+ elementInstances := moduleInst.ElementInstances
897
+ ce.pushFrame(frame)
898
+ body := frame.f.parent.body
899
+ bodyLen := uint64(len(body))
900
+ for frame.pc < bodyLen {
901
+ op := &body[frame.pc]
902
+ // TODO: add description of each operation/case
903
+ // on, for example, how many args are used,
904
+ // how the stack is modified, etc.
905
+ switch op.Kind {
906
+ case operationKindBuiltinFunctionCheckExitCode:
907
+ if err := m.FailIfClosed(); err != nil {
908
+ panic(err)
909
+ }
910
+ frame.pc++
911
+ case operationKindUnreachable:
912
+ panic(wasmruntime.ErrRuntimeUnreachable)
913
+ case operationKindBr:
914
+ frame.pc = op.U1
915
+ case operationKindBrIf:
916
+ if ce.popValue() > 0 {
917
+ ce.drop(op.U3)
918
+ frame.pc = op.U1
919
+ } else {
920
+ frame.pc = op.U2
921
+ }
922
+ case operationKindBrTable:
923
+ v := ce.popValue()
924
+ defaultAt := uint64(len(op.Us))/2 - 1
925
+ if v > defaultAt {
926
+ v = defaultAt
927
+ }
928
+ v *= 2
929
+ ce.drop(op.Us[v+1])
930
+ frame.pc = op.Us[v]
931
+ case operationKindCall:
932
+ frameUnwound := ce.callWithUnwind(ctx, f.moduleInstance, &functions[op.U1])
933
+ if frameUnwound {
934
+ frame = ce.frames[len(ce.frames)-1]
935
+ body = frame.f.parent.body
936
+ bodyLen = uint64(len(body))
937
+ continue
938
+ }
939
+ frame.pc++
940
+ case operationKindCallIndirect:
941
+ offset := ce.popValue()
942
+ table := tables[op.U2]
943
+ tf := ce.functionForOffset(table, offset, typeIDs[op.U1])
944
+
945
+ frameUnwound := ce.callWithUnwind(ctx, f.moduleInstance, tf)
946
+ if frameUnwound {
947
+ frame = ce.frames[len(ce.frames)-1]
948
+ body = frame.f.parent.body
949
+ bodyLen = uint64(len(body))
950
+ continue
951
+ }
952
+ frame.pc++
953
+ case operationKindDrop:
954
+ ce.drop(op.U1)
955
+ frame.pc++
956
+ case operationKindSelect:
957
+ c := ce.popValue()
958
+ if op.B3 { // Target is vector.
959
+ x2Hi, x2Lo := ce.popValue(), ce.popValue()
960
+ if c == 0 {
961
+ _, _ = ce.popValue(), ce.popValue() // discard the x1's lo and hi bits.
962
+ ce.pushValue(x2Lo)
963
+ ce.pushValue(x2Hi)
964
+ }
965
+ } else {
966
+ v2 := ce.popValue()
967
+ if c == 0 {
968
+ _ = ce.popValue()
969
+ ce.pushValue(v2)
970
+ }
971
+ }
972
+ frame.pc++
973
+ case operationKindPick:
974
+ index := len(ce.stack) - 1 - int(op.U1)
975
+ ce.pushValue(ce.stack[index])
976
+ if op.B3 { // V128 value target.
977
+ ce.pushValue(ce.stack[index+1])
978
+ }
979
+ frame.pc++
980
+ case operationKindSet:
981
+ if op.B3 { // V128 value target.
982
+ lowIndex := len(ce.stack) - 1 - int(op.U1)
983
+ highIndex := lowIndex + 1
984
+ hi, lo := ce.popValue(), ce.popValue()
985
+ ce.stack[lowIndex], ce.stack[highIndex] = lo, hi
986
+ } else {
987
+ index := len(ce.stack) - 1 - int(op.U1)
988
+ ce.stack[index] = ce.popValue()
989
+ }
990
+ frame.pc++
991
+ case operationKindGlobalGet:
992
+ g := globals[op.U1]
993
+ ce.pushValue(g.Val)
994
+ if g.Type.ValType == wasm.ValueTypeV128 {
995
+ ce.pushValue(g.ValHi)
996
+ }
997
+ frame.pc++
998
+ case operationKindGlobalSet:
999
+ g := globals[op.U1]
1000
+ if g.Type.ValType == wasm.ValueTypeV128 {
1001
+ g.ValHi = ce.popValue()
1002
+ }
1003
+ g.Val = ce.popValue()
1004
+ frame.pc++
1005
+ case operationKindLoad:
1006
+ offset := ce.popMemoryOffset(op)
1007
+ switch unsignedType(op.B1) {
1008
+ case unsignedTypeI32, unsignedTypeF32:
1009
+ if val, ok := memoryInst.ReadUint32Le(offset); !ok {
1010
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1011
+ } else {
1012
+ ce.pushValue(uint64(val))
1013
+ }
1014
+ case unsignedTypeI64, unsignedTypeF64:
1015
+ if val, ok := memoryInst.ReadUint64Le(offset); !ok {
1016
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1017
+ } else {
1018
+ ce.pushValue(val)
1019
+ }
1020
+ }
1021
+ frame.pc++
1022
+ case operationKindLoad8:
1023
+ val, ok := memoryInst.ReadByte(ce.popMemoryOffset(op))
1024
+ if !ok {
1025
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1026
+ }
1027
+
1028
+ switch signedInt(op.B1) {
1029
+ case signedInt32:
1030
+ ce.pushValue(uint64(uint32(int8(val))))
1031
+ case signedInt64:
1032
+ ce.pushValue(uint64(int8(val)))
1033
+ case signedUint32, signedUint64:
1034
+ ce.pushValue(uint64(val))
1035
+ }
1036
+ frame.pc++
1037
+ case operationKindLoad16:
1038
+
1039
+ val, ok := memoryInst.ReadUint16Le(ce.popMemoryOffset(op))
1040
+ if !ok {
1041
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1042
+ }
1043
+
1044
+ switch signedInt(op.B1) {
1045
+ case signedInt32:
1046
+ ce.pushValue(uint64(uint32(int16(val))))
1047
+ case signedInt64:
1048
+ ce.pushValue(uint64(int16(val)))
1049
+ case signedUint32, signedUint64:
1050
+ ce.pushValue(uint64(val))
1051
+ }
1052
+ frame.pc++
1053
+ case operationKindLoad32:
1054
+ val, ok := memoryInst.ReadUint32Le(ce.popMemoryOffset(op))
1055
+ if !ok {
1056
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1057
+ }
1058
+
1059
+ if op.B1 == 1 { // Signed
1060
+ ce.pushValue(uint64(int32(val)))
1061
+ } else {
1062
+ ce.pushValue(uint64(val))
1063
+ }
1064
+ frame.pc++
1065
+ case operationKindStore:
1066
+ val := ce.popValue()
1067
+ offset := ce.popMemoryOffset(op)
1068
+ switch unsignedType(op.B1) {
1069
+ case unsignedTypeI32, unsignedTypeF32:
1070
+ if !memoryInst.WriteUint32Le(offset, uint32(val)) {
1071
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1072
+ }
1073
+ case unsignedTypeI64, unsignedTypeF64:
1074
+ if !memoryInst.WriteUint64Le(offset, val) {
1075
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1076
+ }
1077
+ }
1078
+ frame.pc++
1079
+ case operationKindStore8:
1080
+ val := byte(ce.popValue())
1081
+ offset := ce.popMemoryOffset(op)
1082
+ if !memoryInst.WriteByte(offset, val) {
1083
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1084
+ }
1085
+ frame.pc++
1086
+ case operationKindStore16:
1087
+ val := uint16(ce.popValue())
1088
+ offset := ce.popMemoryOffset(op)
1089
+ if !memoryInst.WriteUint16Le(offset, val) {
1090
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1091
+ }
1092
+ frame.pc++
1093
+ case operationKindStore32:
1094
+ val := uint32(ce.popValue())
1095
+ offset := ce.popMemoryOffset(op)
1096
+ if !memoryInst.WriteUint32Le(offset, val) {
1097
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1098
+ }
1099
+ frame.pc++
1100
+ case operationKindMemorySize:
1101
+ ce.pushValue(uint64(memoryInst.Pages()))
1102
+ frame.pc++
1103
+ case operationKindMemoryGrow:
1104
+ n := ce.popValue()
1105
+ if res, ok := memoryInst.Grow(uint32(n)); !ok {
1106
+ ce.pushValue(uint64(0xffffffff)) // = -1 in signed 32-bit integer.
1107
+ } else {
1108
+ ce.pushValue(uint64(res))
1109
+ }
1110
+ frame.pc++
1111
+ case operationKindConstI32, operationKindConstI64,
1112
+ operationKindConstF32, operationKindConstF64:
1113
+ ce.pushValue(op.U1)
1114
+ frame.pc++
1115
+ case operationKindEq:
1116
+ var b bool
1117
+ switch unsignedType(op.B1) {
1118
+ case unsignedTypeI32:
1119
+ v2, v1 := ce.popValue(), ce.popValue()
1120
+ b = uint32(v1) == uint32(v2)
1121
+ case unsignedTypeI64:
1122
+ v2, v1 := ce.popValue(), ce.popValue()
1123
+ b = v1 == v2
1124
+ case unsignedTypeF32:
1125
+ v2, v1 := ce.popValue(), ce.popValue()
1126
+ b = math.Float32frombits(uint32(v2)) == math.Float32frombits(uint32(v1))
1127
+ case unsignedTypeF64:
1128
+ v2, v1 := ce.popValue(), ce.popValue()
1129
+ b = math.Float64frombits(v2) == math.Float64frombits(v1)
1130
+ }
1131
+ if b {
1132
+ ce.pushValue(1)
1133
+ } else {
1134
+ ce.pushValue(0)
1135
+ }
1136
+ frame.pc++
1137
+ case operationKindNe:
1138
+ var b bool
1139
+ switch unsignedType(op.B1) {
1140
+ case unsignedTypeI32:
1141
+ v2, v1 := ce.popValue(), ce.popValue()
1142
+ b = uint32(v1) != uint32(v2)
1143
+ case unsignedTypeI64:
1144
+ v2, v1 := ce.popValue(), ce.popValue()
1145
+ b = v1 != v2
1146
+ case unsignedTypeF32:
1147
+ v2, v1 := ce.popValue(), ce.popValue()
1148
+ b = math.Float32frombits(uint32(v2)) != math.Float32frombits(uint32(v1))
1149
+ case unsignedTypeF64:
1150
+ v2, v1 := ce.popValue(), ce.popValue()
1151
+ b = math.Float64frombits(v2) != math.Float64frombits(v1)
1152
+ }
1153
+ if b {
1154
+ ce.pushValue(1)
1155
+ } else {
1156
+ ce.pushValue(0)
1157
+ }
1158
+ frame.pc++
1159
+ case operationKindEqz:
1160
+ v := ce.popValue()
1161
+ if unsignedInt(op.B1) == unsignedInt32 {
1162
+ v = uint64(uint32(v))
1163
+ }
1164
+ if v == 0 {
1165
+ ce.pushValue(1)
1166
+ } else {
1167
+ ce.pushValue(0)
1168
+ }
1169
+ frame.pc++
1170
+ case operationKindLt:
1171
+ v2 := ce.popValue()
1172
+ v1 := ce.popValue()
1173
+ var b bool
1174
+ switch signedType(op.B1) {
1175
+ case signedTypeInt32:
1176
+ b = int32(v1) < int32(v2)
1177
+ case signedTypeInt64:
1178
+ b = int64(v1) < int64(v2)
1179
+ case signedTypeUint32:
1180
+ b = uint32(v1) < uint32(v2)
1181
+ case signedTypeUint64:
1182
+ b = v1 < v2
1183
+ case signedTypeFloat32:
1184
+ b = math.Float32frombits(uint32(v1)) < math.Float32frombits(uint32(v2))
1185
+ case signedTypeFloat64:
1186
+ b = math.Float64frombits(v1) < math.Float64frombits(v2)
1187
+ }
1188
+ if b {
1189
+ ce.pushValue(1)
1190
+ } else {
1191
+ ce.pushValue(0)
1192
+ }
1193
+ frame.pc++
1194
+ case operationKindGt:
1195
+ v2 := ce.popValue()
1196
+ v1 := ce.popValue()
1197
+ var b bool
1198
+ switch signedType(op.B1) {
1199
+ case signedTypeInt32:
1200
+ b = int32(v1) > int32(v2)
1201
+ case signedTypeInt64:
1202
+ b = int64(v1) > int64(v2)
1203
+ case signedTypeUint32:
1204
+ b = uint32(v1) > uint32(v2)
1205
+ case signedTypeUint64:
1206
+ b = v1 > v2
1207
+ case signedTypeFloat32:
1208
+ b = math.Float32frombits(uint32(v1)) > math.Float32frombits(uint32(v2))
1209
+ case signedTypeFloat64:
1210
+ b = math.Float64frombits(v1) > math.Float64frombits(v2)
1211
+ }
1212
+ if b {
1213
+ ce.pushValue(1)
1214
+ } else {
1215
+ ce.pushValue(0)
1216
+ }
1217
+ frame.pc++
1218
+ case operationKindLe:
1219
+ v2 := ce.popValue()
1220
+ v1 := ce.popValue()
1221
+ var b bool
1222
+ switch signedType(op.B1) {
1223
+ case signedTypeInt32:
1224
+ b = int32(v1) <= int32(v2)
1225
+ case signedTypeInt64:
1226
+ b = int64(v1) <= int64(v2)
1227
+ case signedTypeUint32:
1228
+ b = uint32(v1) <= uint32(v2)
1229
+ case signedTypeUint64:
1230
+ b = v1 <= v2
1231
+ case signedTypeFloat32:
1232
+ b = math.Float32frombits(uint32(v1)) <= math.Float32frombits(uint32(v2))
1233
+ case signedTypeFloat64:
1234
+ b = math.Float64frombits(v1) <= math.Float64frombits(v2)
1235
+ }
1236
+ if b {
1237
+ ce.pushValue(1)
1238
+ } else {
1239
+ ce.pushValue(0)
1240
+ }
1241
+ frame.pc++
1242
+ case operationKindGe:
1243
+ v2 := ce.popValue()
1244
+ v1 := ce.popValue()
1245
+ var b bool
1246
+ switch signedType(op.B1) {
1247
+ case signedTypeInt32:
1248
+ b = int32(v1) >= int32(v2)
1249
+ case signedTypeInt64:
1250
+ b = int64(v1) >= int64(v2)
1251
+ case signedTypeUint32:
1252
+ b = uint32(v1) >= uint32(v2)
1253
+ case signedTypeUint64:
1254
+ b = v1 >= v2
1255
+ case signedTypeFloat32:
1256
+ b = math.Float32frombits(uint32(v1)) >= math.Float32frombits(uint32(v2))
1257
+ case signedTypeFloat64:
1258
+ b = math.Float64frombits(v1) >= math.Float64frombits(v2)
1259
+ }
1260
+ if b {
1261
+ ce.pushValue(1)
1262
+ } else {
1263
+ ce.pushValue(0)
1264
+ }
1265
+ frame.pc++
1266
+ case operationKindAdd:
1267
+ v2 := ce.popValue()
1268
+ v1 := ce.popValue()
1269
+ switch unsignedType(op.B1) {
1270
+ case unsignedTypeI32:
1271
+ v := uint32(v1) + uint32(v2)
1272
+ ce.pushValue(uint64(v))
1273
+ case unsignedTypeI64:
1274
+ ce.pushValue(v1 + v2)
1275
+ case unsignedTypeF32:
1276
+ ce.pushValue(addFloat32bits(uint32(v1), uint32(v2)))
1277
+ case unsignedTypeF64:
1278
+ v := math.Float64frombits(v1) + math.Float64frombits(v2)
1279
+ ce.pushValue(math.Float64bits(v))
1280
+ }
1281
+ frame.pc++
1282
+ case operationKindSub:
1283
+ v2 := ce.popValue()
1284
+ v1 := ce.popValue()
1285
+ switch unsignedType(op.B1) {
1286
+ case unsignedTypeI32:
1287
+ ce.pushValue(uint64(uint32(v1) - uint32(v2)))
1288
+ case unsignedTypeI64:
1289
+ ce.pushValue(v1 - v2)
1290
+ case unsignedTypeF32:
1291
+ ce.pushValue(subFloat32bits(uint32(v1), uint32(v2)))
1292
+ case unsignedTypeF64:
1293
+ v := math.Float64frombits(v1) - math.Float64frombits(v2)
1294
+ ce.pushValue(math.Float64bits(v))
1295
+ }
1296
+ frame.pc++
1297
+ case operationKindMul:
1298
+ v2 := ce.popValue()
1299
+ v1 := ce.popValue()
1300
+ switch unsignedType(op.B1) {
1301
+ case unsignedTypeI32:
1302
+ ce.pushValue(uint64(uint32(v1) * uint32(v2)))
1303
+ case unsignedTypeI64:
1304
+ ce.pushValue(v1 * v2)
1305
+ case unsignedTypeF32:
1306
+ ce.pushValue(mulFloat32bits(uint32(v1), uint32(v2)))
1307
+ case unsignedTypeF64:
1308
+ v := math.Float64frombits(v2) * math.Float64frombits(v1)
1309
+ ce.pushValue(math.Float64bits(v))
1310
+ }
1311
+ frame.pc++
1312
+ case operationKindClz:
1313
+ v := ce.popValue()
1314
+ if op.B1 == 0 {
1315
+ // unsignedInt32
1316
+ ce.pushValue(uint64(bits.LeadingZeros32(uint32(v))))
1317
+ } else {
1318
+ // unsignedInt64
1319
+ ce.pushValue(uint64(bits.LeadingZeros64(v)))
1320
+ }
1321
+ frame.pc++
1322
+ case operationKindCtz:
1323
+ v := ce.popValue()
1324
+ if op.B1 == 0 {
1325
+ // unsignedInt32
1326
+ ce.pushValue(uint64(bits.TrailingZeros32(uint32(v))))
1327
+ } else {
1328
+ // unsignedInt64
1329
+ ce.pushValue(uint64(bits.TrailingZeros64(v)))
1330
+ }
1331
+ frame.pc++
1332
+ case operationKindPopcnt:
1333
+ v := ce.popValue()
1334
+ if op.B1 == 0 {
1335
+ // unsignedInt32
1336
+ ce.pushValue(uint64(bits.OnesCount32(uint32(v))))
1337
+ } else {
1338
+ // unsignedInt64
1339
+ ce.pushValue(uint64(bits.OnesCount64(v)))
1340
+ }
1341
+ frame.pc++
1342
+ case operationKindDiv:
1343
+ // If an integer, check we won't divide by zero.
1344
+ t := signedType(op.B1)
1345
+ v2, v1 := ce.popValue(), ce.popValue()
1346
+ switch t {
1347
+ case signedTypeFloat32, signedTypeFloat64: // not integers
1348
+ case signedTypeInt32, signedTypeUint32:
1349
+ if uint32(v2) == 0 {
1350
+ panic(wasmruntime.ErrRuntimeIntegerDivideByZero)
1351
+ }
1352
+ default:
1353
+ if v2 == 0 {
1354
+ panic(wasmruntime.ErrRuntimeIntegerDivideByZero)
1355
+ }
1356
+ }
1357
+
1358
+ switch t {
1359
+ case signedTypeInt32:
1360
+ d := int32(v2)
1361
+ n := int32(v1)
1362
+ if n == math.MinInt32 && d == -1 {
1363
+ panic(wasmruntime.ErrRuntimeIntegerOverflow)
1364
+ }
1365
+ ce.pushValue(uint64(uint32(n / d)))
1366
+ case signedTypeInt64:
1367
+ d := int64(v2)
1368
+ n := int64(v1)
1369
+ if n == math.MinInt64 && d == -1 {
1370
+ panic(wasmruntime.ErrRuntimeIntegerOverflow)
1371
+ }
1372
+ ce.pushValue(uint64(n / d))
1373
+ case signedTypeUint32:
1374
+ d := uint32(v2)
1375
+ n := uint32(v1)
1376
+ ce.pushValue(uint64(n / d))
1377
+ case signedTypeUint64:
1378
+ d := v2
1379
+ n := v1
1380
+ ce.pushValue(n / d)
1381
+ case signedTypeFloat32:
1382
+ ce.pushValue(divFloat32bits(uint32(v1), uint32(v2)))
1383
+ case signedTypeFloat64:
1384
+ ce.pushValue(math.Float64bits(math.Float64frombits(v1) / math.Float64frombits(v2)))
1385
+ }
1386
+ frame.pc++
1387
+ case operationKindRem:
1388
+ v2, v1 := ce.popValue(), ce.popValue()
1389
+ switch signedInt(op.B1) {
1390
+ case signedInt32, signedUint32:
1391
+ if uint32(v2) == 0 {
1392
+ panic(wasmruntime.ErrRuntimeIntegerDivideByZero)
1393
+ }
1394
+ default:
1395
+ if v2 == 0 {
1396
+ panic(wasmruntime.ErrRuntimeIntegerDivideByZero)
1397
+ }
1398
+ }
1399
+ switch signedInt(op.B1) {
1400
+ case signedInt32:
1401
+ d := int32(v2)
1402
+ n := int32(v1)
1403
+ ce.pushValue(uint64(uint32(n % d)))
1404
+ case signedInt64:
1405
+ d := int64(v2)
1406
+ n := int64(v1)
1407
+ ce.pushValue(uint64(n % d))
1408
+ case signedUint32:
1409
+ d := uint32(v2)
1410
+ n := uint32(v1)
1411
+ ce.pushValue(uint64(n % d))
1412
+ case signedUint64:
1413
+ d := v2
1414
+ n := v1
1415
+ ce.pushValue(n % d)
1416
+ }
1417
+ frame.pc++
1418
+ case operationKindAnd:
1419
+ v2 := ce.popValue()
1420
+ v1 := ce.popValue()
1421
+ if op.B1 == 0 {
1422
+ // unsignedInt32
1423
+ ce.pushValue(uint64(uint32(v2) & uint32(v1)))
1424
+ } else {
1425
+ // unsignedInt64
1426
+ ce.pushValue(uint64(v2 & v1))
1427
+ }
1428
+ frame.pc++
1429
+ case operationKindOr:
1430
+ v2 := ce.popValue()
1431
+ v1 := ce.popValue()
1432
+ if op.B1 == 0 {
1433
+ // unsignedInt32
1434
+ ce.pushValue(uint64(uint32(v2) | uint32(v1)))
1435
+ } else {
1436
+ // unsignedInt64
1437
+ ce.pushValue(uint64(v2 | v1))
1438
+ }
1439
+ frame.pc++
1440
+ case operationKindXor:
1441
+ v2 := ce.popValue()
1442
+ v1 := ce.popValue()
1443
+ if op.B1 == 0 {
1444
+ // unsignedInt32
1445
+ ce.pushValue(uint64(uint32(v2) ^ uint32(v1)))
1446
+ } else {
1447
+ // unsignedInt64
1448
+ ce.pushValue(uint64(v2 ^ v1))
1449
+ }
1450
+ frame.pc++
1451
+ case operationKindShl:
1452
+ v2 := ce.popValue()
1453
+ v1 := ce.popValue()
1454
+ if op.B1 == 0 {
1455
+ // unsignedInt32
1456
+ ce.pushValue(uint64(uint32(v1) << (uint32(v2) % 32)))
1457
+ } else {
1458
+ // unsignedInt64
1459
+ ce.pushValue(v1 << (v2 % 64))
1460
+ }
1461
+ frame.pc++
1462
+ case operationKindShr:
1463
+ v2 := ce.popValue()
1464
+ v1 := ce.popValue()
1465
+ switch signedInt(op.B1) {
1466
+ case signedInt32:
1467
+ ce.pushValue(uint64(uint32(int32(v1) >> (uint32(v2) % 32))))
1468
+ case signedInt64:
1469
+ ce.pushValue(uint64(int64(v1) >> (v2 % 64)))
1470
+ case signedUint32:
1471
+ ce.pushValue(uint64(uint32(v1) >> (uint32(v2) % 32)))
1472
+ case signedUint64:
1473
+ ce.pushValue(v1 >> (v2 % 64))
1474
+ }
1475
+ frame.pc++
1476
+ case operationKindRotl:
1477
+ v2 := ce.popValue()
1478
+ v1 := ce.popValue()
1479
+ if op.B1 == 0 {
1480
+ // unsignedInt32
1481
+ ce.pushValue(uint64(bits.RotateLeft32(uint32(v1), int(v2))))
1482
+ } else {
1483
+ // unsignedInt64
1484
+ ce.pushValue(uint64(bits.RotateLeft64(v1, int(v2))))
1485
+ }
1486
+ frame.pc++
1487
+ case operationKindRotr:
1488
+ v2 := ce.popValue()
1489
+ v1 := ce.popValue()
1490
+ if op.B1 == 0 {
1491
+ // unsignedInt32
1492
+ ce.pushValue(uint64(bits.RotateLeft32(uint32(v1), -int(v2))))
1493
+ } else {
1494
+ // unsignedInt64
1495
+ ce.pushValue(uint64(bits.RotateLeft64(v1, -int(v2))))
1496
+ }
1497
+ frame.pc++
1498
+ case operationKindAbs:
1499
+ if op.B1 == 0 {
1500
+ // float32
1501
+ const mask uint32 = 1 << 31
1502
+ ce.pushValue(uint64(uint32(ce.popValue()) &^ mask))
1503
+ } else {
1504
+ // float64
1505
+ const mask uint64 = 1 << 63
1506
+ ce.pushValue(ce.popValue() &^ mask)
1507
+ }
1508
+ frame.pc++
1509
+ case operationKindNeg:
1510
+ if op.B1 == 0 {
1511
+ // float32
1512
+ v := -math.Float32frombits(uint32(ce.popValue()))
1513
+ ce.pushValue(uint64(math.Float32bits(v)))
1514
+ } else {
1515
+ // float64
1516
+ v := -math.Float64frombits(ce.popValue())
1517
+ ce.pushValue(math.Float64bits(v))
1518
+ }
1519
+ frame.pc++
1520
+ case operationKindCeil:
1521
+ if op.B1 == 0 {
1522
+ // float32
1523
+ v := moremath.WasmCompatCeilF32(math.Float32frombits(uint32(ce.popValue())))
1524
+ ce.pushValue(uint64(math.Float32bits(v)))
1525
+ } else {
1526
+ // float64
1527
+ v := moremath.WasmCompatCeilF64(math.Float64frombits(ce.popValue()))
1528
+ ce.pushValue(math.Float64bits(v))
1529
+ }
1530
+ frame.pc++
1531
+ case operationKindFloor:
1532
+ if op.B1 == 0 {
1533
+ // float32
1534
+ v := moremath.WasmCompatFloorF32(math.Float32frombits(uint32(ce.popValue())))
1535
+ ce.pushValue(uint64(math.Float32bits(v)))
1536
+ } else {
1537
+ // float64
1538
+ v := moremath.WasmCompatFloorF64(math.Float64frombits(ce.popValue()))
1539
+ ce.pushValue(math.Float64bits(v))
1540
+ }
1541
+ frame.pc++
1542
+ case operationKindTrunc:
1543
+ if op.B1 == 0 {
1544
+ // float32
1545
+ v := moremath.WasmCompatTruncF32(math.Float32frombits(uint32(ce.popValue())))
1546
+ ce.pushValue(uint64(math.Float32bits(v)))
1547
+ } else {
1548
+ // float64
1549
+ v := moremath.WasmCompatTruncF64(math.Float64frombits(ce.popValue()))
1550
+ ce.pushValue(math.Float64bits(v))
1551
+ }
1552
+ frame.pc++
1553
+ case operationKindNearest:
1554
+ if op.B1 == 0 {
1555
+ // float32
1556
+ f := math.Float32frombits(uint32(ce.popValue()))
1557
+ ce.pushValue(uint64(math.Float32bits(moremath.WasmCompatNearestF32(f))))
1558
+ } else {
1559
+ // float64
1560
+ f := math.Float64frombits(ce.popValue())
1561
+ ce.pushValue(math.Float64bits(moremath.WasmCompatNearestF64(f)))
1562
+ }
1563
+ frame.pc++
1564
+ case operationKindSqrt:
1565
+ if op.B1 == 0 {
1566
+ // float32
1567
+ v := math.Sqrt(float64(math.Float32frombits(uint32(ce.popValue()))))
1568
+ ce.pushValue(uint64(math.Float32bits(float32(v))))
1569
+ } else {
1570
+ // float64
1571
+ v := math.Sqrt(math.Float64frombits(ce.popValue()))
1572
+ ce.pushValue(math.Float64bits(v))
1573
+ }
1574
+ frame.pc++
1575
+ case operationKindMin:
1576
+ if op.B1 == 0 {
1577
+ // float32
1578
+ ce.pushValue(wasmCompatMin32bits(uint32(ce.popValue()), uint32(ce.popValue())))
1579
+ } else {
1580
+ v2 := math.Float64frombits(ce.popValue())
1581
+ v1 := math.Float64frombits(ce.popValue())
1582
+ ce.pushValue(math.Float64bits(moremath.WasmCompatMin64(v1, v2)))
1583
+ }
1584
+ frame.pc++
1585
+ case operationKindMax:
1586
+ if op.B1 == 0 {
1587
+ ce.pushValue(wasmCompatMax32bits(uint32(ce.popValue()), uint32(ce.popValue())))
1588
+ } else {
1589
+ // float64
1590
+ v2 := math.Float64frombits(ce.popValue())
1591
+ v1 := math.Float64frombits(ce.popValue())
1592
+ ce.pushValue(math.Float64bits(moremath.WasmCompatMax64(v1, v2)))
1593
+ }
1594
+ frame.pc++
1595
+ case operationKindCopysign:
1596
+ if op.B1 == 0 {
1597
+ // float32
1598
+ v2 := uint32(ce.popValue())
1599
+ v1 := uint32(ce.popValue())
1600
+ const signbit = 1 << 31
1601
+ ce.pushValue(uint64(v1&^signbit | v2&signbit))
1602
+ } else {
1603
+ // float64
1604
+ v2 := ce.popValue()
1605
+ v1 := ce.popValue()
1606
+ const signbit = 1 << 63
1607
+ ce.pushValue(v1&^signbit | v2&signbit)
1608
+ }
1609
+ frame.pc++
1610
+ case operationKindI32WrapFromI64:
1611
+ ce.pushValue(uint64(uint32(ce.popValue())))
1612
+ frame.pc++
1613
+ case operationKindITruncFromF:
1614
+ if op.B1 == 0 {
1615
+ // float32
1616
+ switch signedInt(op.B2) {
1617
+ case signedInt32:
1618
+ v := math.Trunc(float64(math.Float32frombits(uint32(ce.popValue()))))
1619
+ if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN
1620
+ if op.B3 {
1621
+ // non-trapping conversion must cast nan to zero.
1622
+ v = 0
1623
+ } else {
1624
+ panic(wasmruntime.ErrRuntimeInvalidConversionToInteger)
1625
+ }
1626
+ } else if v < math.MinInt32 || v > math.MaxInt32 {
1627
+ if op.B3 {
1628
+ // non-trapping conversion must "saturate" the value for overflowing sources.
1629
+ if v < 0 {
1630
+ v = math.MinInt32
1631
+ } else {
1632
+ v = math.MaxInt32
1633
+ }
1634
+ } else {
1635
+ panic(wasmruntime.ErrRuntimeIntegerOverflow)
1636
+ }
1637
+ }
1638
+ ce.pushValue(uint64(uint32(int32(v))))
1639
+ case signedInt64:
1640
+ v := math.Trunc(float64(math.Float32frombits(uint32(ce.popValue()))))
1641
+ res := int64(v)
1642
+ if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN
1643
+ if op.B3 {
1644
+ // non-trapping conversion must cast nan to zero.
1645
+ res = 0
1646
+ } else {
1647
+ panic(wasmruntime.ErrRuntimeInvalidConversionToInteger)
1648
+ }
1649
+ } else if v < math.MinInt64 || v >= math.MaxInt64 {
1650
+ // Note: math.MaxInt64 is rounded up to math.MaxInt64+1 in 64-bit float representation,
1651
+ // and that's why we use '>=' not '>' to check overflow.
1652
+ if op.B3 {
1653
+ // non-trapping conversion must "saturate" the value for overflowing sources.
1654
+ if v < 0 {
1655
+ res = math.MinInt64
1656
+ } else {
1657
+ res = math.MaxInt64
1658
+ }
1659
+ } else {
1660
+ panic(wasmruntime.ErrRuntimeIntegerOverflow)
1661
+ }
1662
+ }
1663
+ ce.pushValue(uint64(res))
1664
+ case signedUint32:
1665
+ v := math.Trunc(float64(math.Float32frombits(uint32(ce.popValue()))))
1666
+ if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN
1667
+ if op.B3 {
1668
+ // non-trapping conversion must cast nan to zero.
1669
+ v = 0
1670
+ } else {
1671
+ panic(wasmruntime.ErrRuntimeInvalidConversionToInteger)
1672
+ }
1673
+ } else if v < 0 || v > math.MaxUint32 {
1674
+ if op.B3 {
1675
+ // non-trapping conversion must "saturate" the value for overflowing source.
1676
+ if v < 0 {
1677
+ v = 0
1678
+ } else {
1679
+ v = math.MaxUint32
1680
+ }
1681
+ } else {
1682
+ panic(wasmruntime.ErrRuntimeIntegerOverflow)
1683
+ }
1684
+ }
1685
+ ce.pushValue(uint64(uint32(v)))
1686
+ case signedUint64:
1687
+ v := math.Trunc(float64(math.Float32frombits(uint32(ce.popValue()))))
1688
+ res := uint64(v)
1689
+ if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN
1690
+ if op.B3 {
1691
+ // non-trapping conversion must cast nan to zero.
1692
+ res = 0
1693
+ } else {
1694
+ panic(wasmruntime.ErrRuntimeInvalidConversionToInteger)
1695
+ }
1696
+ } else if v < 0 || v >= math.MaxUint64 {
1697
+ // Note: math.MaxUint64 is rounded up to math.MaxUint64+1 in 64-bit float representation,
1698
+ // and that's why we use '>=' not '>' to check overflow.
1699
+ if op.B3 {
1700
+ // non-trapping conversion must "saturate" the value for overflowing source.
1701
+ if v < 0 {
1702
+ res = 0
1703
+ } else {
1704
+ res = math.MaxUint64
1705
+ }
1706
+ } else {
1707
+ panic(wasmruntime.ErrRuntimeIntegerOverflow)
1708
+ }
1709
+ }
1710
+ ce.pushValue(res)
1711
+ }
1712
+ } else {
1713
+ // float64
1714
+ switch signedInt(op.B2) {
1715
+ case signedInt32:
1716
+ v := math.Trunc(math.Float64frombits(ce.popValue()))
1717
+ if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN
1718
+ if op.B3 {
1719
+ // non-trapping conversion must cast nan to zero.
1720
+ v = 0
1721
+ } else {
1722
+ panic(wasmruntime.ErrRuntimeInvalidConversionToInteger)
1723
+ }
1724
+ } else if v < math.MinInt32 || v > math.MaxInt32 {
1725
+ if op.B3 {
1726
+ // non-trapping conversion must "saturate" the value for overflowing source.
1727
+ if v < 0 {
1728
+ v = math.MinInt32
1729
+ } else {
1730
+ v = math.MaxInt32
1731
+ }
1732
+ } else {
1733
+ panic(wasmruntime.ErrRuntimeIntegerOverflow)
1734
+ }
1735
+ }
1736
+ ce.pushValue(uint64(uint32(int32(v))))
1737
+ case signedInt64:
1738
+ v := math.Trunc(math.Float64frombits(ce.popValue()))
1739
+ res := int64(v)
1740
+ if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN
1741
+ if op.B3 {
1742
+ // non-trapping conversion must cast nan to zero.
1743
+ res = 0
1744
+ } else {
1745
+ panic(wasmruntime.ErrRuntimeInvalidConversionToInteger)
1746
+ }
1747
+ } else if v < math.MinInt64 || v >= math.MaxInt64 {
1748
+ // Note: math.MaxInt64 is rounded up to math.MaxInt64+1 in 64-bit float representation,
1749
+ // and that's why we use '>=' not '>' to check overflow.
1750
+ if op.B3 {
1751
+ // non-trapping conversion must "saturate" the value for overflowing source.
1752
+ if v < 0 {
1753
+ res = math.MinInt64
1754
+ } else {
1755
+ res = math.MaxInt64
1756
+ }
1757
+ } else {
1758
+ panic(wasmruntime.ErrRuntimeIntegerOverflow)
1759
+ }
1760
+ }
1761
+ ce.pushValue(uint64(res))
1762
+ case signedUint32:
1763
+ v := math.Trunc(math.Float64frombits(ce.popValue()))
1764
+ if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN
1765
+ if op.B3 {
1766
+ // non-trapping conversion must cast nan to zero.
1767
+ v = 0
1768
+ } else {
1769
+ panic(wasmruntime.ErrRuntimeInvalidConversionToInteger)
1770
+ }
1771
+ } else if v < 0 || v > math.MaxUint32 {
1772
+ if op.B3 {
1773
+ // non-trapping conversion must "saturate" the value for overflowing source.
1774
+ if v < 0 {
1775
+ v = 0
1776
+ } else {
1777
+ v = math.MaxUint32
1778
+ }
1779
+ } else {
1780
+ panic(wasmruntime.ErrRuntimeIntegerOverflow)
1781
+ }
1782
+ }
1783
+ ce.pushValue(uint64(uint32(v)))
1784
+ case signedUint64:
1785
+ v := math.Trunc(math.Float64frombits(ce.popValue()))
1786
+ res := uint64(v)
1787
+ if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN
1788
+ if op.B3 {
1789
+ // non-trapping conversion must cast nan to zero.
1790
+ res = 0
1791
+ } else {
1792
+ panic(wasmruntime.ErrRuntimeInvalidConversionToInteger)
1793
+ }
1794
+ } else if v < 0 || v >= math.MaxUint64 {
1795
+ // Note: math.MaxUint64 is rounded up to math.MaxUint64+1 in 64-bit float representation,
1796
+ // and that's why we use '>=' not '>' to check overflow.
1797
+ if op.B3 {
1798
+ // non-trapping conversion must "saturate" the value for overflowing source.
1799
+ if v < 0 {
1800
+ res = 0
1801
+ } else {
1802
+ res = math.MaxUint64
1803
+ }
1804
+ } else {
1805
+ panic(wasmruntime.ErrRuntimeIntegerOverflow)
1806
+ }
1807
+ }
1808
+ ce.pushValue(res)
1809
+ }
1810
+ }
1811
+ frame.pc++
1812
+ case operationKindFConvertFromI:
1813
+ switch signedInt(op.B1) {
1814
+ case signedInt32:
1815
+ if op.B2 == 0 {
1816
+ // float32
1817
+ v := float32(int32(ce.popValue()))
1818
+ ce.pushValue(uint64(math.Float32bits(v)))
1819
+ } else {
1820
+ // float64
1821
+ v := float64(int32(ce.popValue()))
1822
+ ce.pushValue(math.Float64bits(v))
1823
+ }
1824
+ case signedInt64:
1825
+ if op.B2 == 0 {
1826
+ // float32
1827
+ v := float32(int64(ce.popValue()))
1828
+ ce.pushValue(uint64(math.Float32bits(v)))
1829
+ } else {
1830
+ // float64
1831
+ v := float64(int64(ce.popValue()))
1832
+ ce.pushValue(math.Float64bits(v))
1833
+ }
1834
+ case signedUint32:
1835
+ if op.B2 == 0 {
1836
+ // float32
1837
+ v := float32(uint32(ce.popValue()))
1838
+ ce.pushValue(uint64(math.Float32bits(v)))
1839
+ } else {
1840
+ // float64
1841
+ v := float64(uint32(ce.popValue()))
1842
+ ce.pushValue(math.Float64bits(v))
1843
+ }
1844
+ case signedUint64:
1845
+ if op.B2 == 0 {
1846
+ // float32
1847
+ v := float32(ce.popValue())
1848
+ ce.pushValue(uint64(math.Float32bits(v)))
1849
+ } else {
1850
+ // float64
1851
+ v := float64(ce.popValue())
1852
+ ce.pushValue(math.Float64bits(v))
1853
+ }
1854
+ }
1855
+ frame.pc++
1856
+ case operationKindF32DemoteFromF64:
1857
+ v := float32(math.Float64frombits(ce.popValue()))
1858
+ ce.pushValue(uint64(math.Float32bits(v)))
1859
+ frame.pc++
1860
+ case operationKindF64PromoteFromF32:
1861
+ v := float64(math.Float32frombits(uint32(ce.popValue())))
1862
+ ce.pushValue(math.Float64bits(v))
1863
+ frame.pc++
1864
+ case operationKindExtend:
1865
+ if op.B1 == 1 {
1866
+ // Signed.
1867
+ v := int64(int32(ce.popValue()))
1868
+ ce.pushValue(uint64(v))
1869
+ } else {
1870
+ v := uint64(uint32(ce.popValue()))
1871
+ ce.pushValue(v)
1872
+ }
1873
+ frame.pc++
1874
+ case operationKindSignExtend32From8:
1875
+ v := uint32(int8(ce.popValue()))
1876
+ ce.pushValue(uint64(v))
1877
+ frame.pc++
1878
+ case operationKindSignExtend32From16:
1879
+ v := uint32(int16(ce.popValue()))
1880
+ ce.pushValue(uint64(v))
1881
+ frame.pc++
1882
+ case operationKindSignExtend64From8:
1883
+ v := int64(int8(ce.popValue()))
1884
+ ce.pushValue(uint64(v))
1885
+ frame.pc++
1886
+ case operationKindSignExtend64From16:
1887
+ v := int64(int16(ce.popValue()))
1888
+ ce.pushValue(uint64(v))
1889
+ frame.pc++
1890
+ case operationKindSignExtend64From32:
1891
+ v := int64(int32(ce.popValue()))
1892
+ ce.pushValue(uint64(v))
1893
+ frame.pc++
1894
+ case operationKindMemoryInit:
1895
+ dataInstance := dataInstances[op.U1]
1896
+ copySize := ce.popValue()
1897
+ inDataOffset := ce.popValue()
1898
+ inMemoryOffset := ce.popValue()
1899
+ if inDataOffset+copySize > uint64(len(dataInstance)) ||
1900
+ inMemoryOffset+copySize > uint64(len(memoryInst.Buffer)) {
1901
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1902
+ } else if copySize != 0 {
1903
+ copy(memoryInst.Buffer[inMemoryOffset:inMemoryOffset+copySize], dataInstance[inDataOffset:])
1904
+ }
1905
+ frame.pc++
1906
+ case operationKindDataDrop:
1907
+ dataInstances[op.U1] = nil
1908
+ frame.pc++
1909
+ case operationKindMemoryCopy:
1910
+ memLen := uint64(len(memoryInst.Buffer))
1911
+ copySize := ce.popValue()
1912
+ sourceOffset := ce.popValue()
1913
+ destinationOffset := ce.popValue()
1914
+ if sourceOffset+copySize > memLen || destinationOffset+copySize > memLen {
1915
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1916
+ } else if copySize != 0 {
1917
+ copy(memoryInst.Buffer[destinationOffset:],
1918
+ memoryInst.Buffer[sourceOffset:sourceOffset+copySize])
1919
+ }
1920
+ frame.pc++
1921
+ case operationKindMemoryFill:
1922
+ fillSize := ce.popValue()
1923
+ value := byte(ce.popValue())
1924
+ offset := ce.popValue()
1925
+ if fillSize+offset > uint64(len(memoryInst.Buffer)) {
1926
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
1927
+ } else if fillSize != 0 {
1928
+ // Uses the copy trick for faster filling the buffer with the value.
1929
+ // https://github.com/golang/go/blob/go1.24.0/src/bytes/bytes.go#L664-L673
1930
+ buf := memoryInst.Buffer[offset : offset+fillSize]
1931
+ if value == 0 {
1932
+ clear(buf)
1933
+ } else {
1934
+ buf[0] = value
1935
+ for i := 1; i < len(buf); {
1936
+ chunk := min(i, 8192)
1937
+ i += copy(buf[i:], buf[:chunk])
1938
+ }
1939
+ }
1940
+ }
1941
+ frame.pc++
1942
+ case operationKindTableInit:
1943
+ elementInstance := elementInstances[op.U1]
1944
+ copySize := ce.popValue()
1945
+ inElementOffset := ce.popValue()
1946
+ inTableOffset := ce.popValue()
1947
+ table := tables[op.U2]
1948
+ if inElementOffset+copySize > uint64(len(elementInstance)) ||
1949
+ inTableOffset+copySize > uint64(len(table.References)) {
1950
+ panic(wasmruntime.ErrRuntimeInvalidTableAccess)
1951
+ } else if copySize != 0 {
1952
+ copy(table.References[inTableOffset:inTableOffset+copySize], elementInstance[inElementOffset:])
1953
+ }
1954
+ frame.pc++
1955
+ case operationKindElemDrop:
1956
+ elementInstances[op.U1] = nil
1957
+ frame.pc++
1958
+ case operationKindTableCopy:
1959
+ srcTable, dstTable := tables[op.U1].References, tables[op.U2].References
1960
+ copySize := ce.popValue()
1961
+ sourceOffset := ce.popValue()
1962
+ destinationOffset := ce.popValue()
1963
+ if sourceOffset+copySize > uint64(len(srcTable)) || destinationOffset+copySize > uint64(len(dstTable)) {
1964
+ panic(wasmruntime.ErrRuntimeInvalidTableAccess)
1965
+ } else if copySize != 0 {
1966
+ copy(dstTable[destinationOffset:], srcTable[sourceOffset:sourceOffset+copySize])
1967
+ }
1968
+ frame.pc++
1969
+ case operationKindRefFunc:
1970
+ ce.pushValue(uint64(uintptr(unsafe.Pointer(&functions[op.U1]))))
1971
+ frame.pc++
1972
+ case operationKindTableGet:
1973
+ table := tables[op.U1]
1974
+
1975
+ offset := ce.popValue()
1976
+ if offset >= uint64(len(table.References)) {
1977
+ panic(wasmruntime.ErrRuntimeInvalidTableAccess)
1978
+ }
1979
+
1980
+ ce.pushValue(uint64(table.References[offset]))
1981
+ frame.pc++
1982
+ case operationKindTableSet:
1983
+ table := tables[op.U1]
1984
+ ref := ce.popValue()
1985
+
1986
+ offset := ce.popValue()
1987
+ if offset >= uint64(len(table.References)) {
1988
+ panic(wasmruntime.ErrRuntimeInvalidTableAccess)
1989
+ }
1990
+
1991
+ table.References[offset] = uintptr(ref) // externrefs are opaque uint64.
1992
+ frame.pc++
1993
+ case operationKindTableSize:
1994
+ table := tables[op.U1]
1995
+ ce.pushValue(uint64(len(table.References)))
1996
+ frame.pc++
1997
+ case operationKindTableGrow:
1998
+ table := tables[op.U1]
1999
+ num, ref := ce.popValue(), ce.popValue()
2000
+ ret := table.Grow(uint32(num), uintptr(ref))
2001
+ ce.pushValue(uint64(ret))
2002
+ frame.pc++
2003
+ case operationKindTableFill:
2004
+ table := tables[op.U1]
2005
+ num := ce.popValue()
2006
+ ref := uintptr(ce.popValue())
2007
+ offset := ce.popValue()
2008
+ if num+offset > uint64(len(table.References)) {
2009
+ panic(wasmruntime.ErrRuntimeInvalidTableAccess)
2010
+ } else if num > 0 {
2011
+ // Uses the copy trick for faster filling the region with the value.
2012
+ // https://github.com/golang/go/blob/go1.24.0/src/slices/slices.go#L514-L517
2013
+ targetRegion := table.References[offset : offset+num]
2014
+ targetRegion[0] = ref
2015
+ for i := 1; i < len(targetRegion); i *= 2 {
2016
+ copy(targetRegion[i:], targetRegion[:i])
2017
+ }
2018
+ }
2019
+ frame.pc++
2020
+ case operationKindV128Const:
2021
+ lo, hi := op.U1, op.U2
2022
+ ce.pushValue(lo)
2023
+ ce.pushValue(hi)
2024
+ frame.pc++
2025
+ case operationKindV128Add:
2026
+ yHigh, yLow := ce.popValue(), ce.popValue()
2027
+ xHigh, xLow := ce.popValue(), ce.popValue()
2028
+ switch op.B1 {
2029
+ case shapeI8x16:
2030
+ ce.pushValue(
2031
+ uint64(uint8(xLow>>8)+uint8(yLow>>8))<<8 | uint64(uint8(xLow)+uint8(yLow)) |
2032
+ uint64(uint8(xLow>>24)+uint8(yLow>>24))<<24 | uint64(uint8(xLow>>16)+uint8(yLow>>16))<<16 |
2033
+ uint64(uint8(xLow>>40)+uint8(yLow>>40))<<40 | uint64(uint8(xLow>>32)+uint8(yLow>>32))<<32 |
2034
+ uint64(uint8(xLow>>56)+uint8(yLow>>56))<<56 | uint64(uint8(xLow>>48)+uint8(yLow>>48))<<48,
2035
+ )
2036
+ ce.pushValue(
2037
+ uint64(uint8(xHigh>>8)+uint8(yHigh>>8))<<8 | uint64(uint8(xHigh)+uint8(yHigh)) |
2038
+ uint64(uint8(xHigh>>24)+uint8(yHigh>>24))<<24 | uint64(uint8(xHigh>>16)+uint8(yHigh>>16))<<16 |
2039
+ uint64(uint8(xHigh>>40)+uint8(yHigh>>40))<<40 | uint64(uint8(xHigh>>32)+uint8(yHigh>>32))<<32 |
2040
+ uint64(uint8(xHigh>>56)+uint8(yHigh>>56))<<56 | uint64(uint8(xHigh>>48)+uint8(yHigh>>48))<<48,
2041
+ )
2042
+ case shapeI16x8:
2043
+ ce.pushValue(
2044
+ uint64(uint16(xLow>>16+yLow>>16))<<16 | uint64(uint16(xLow)+uint16(yLow)) |
2045
+ uint64(uint16(xLow>>48+yLow>>48))<<48 | uint64(uint16(xLow>>32+yLow>>32))<<32,
2046
+ )
2047
+ ce.pushValue(
2048
+ uint64(uint16(xHigh>>16)+uint16(yHigh>>16))<<16 | uint64(uint16(xHigh)+uint16(yHigh)) |
2049
+ uint64(uint16(xHigh>>48)+uint16(yHigh>>48))<<48 | uint64(uint16(xHigh>>32)+uint16(yHigh>>32))<<32,
2050
+ )
2051
+ case shapeI32x4:
2052
+ ce.pushValue(uint64(uint32(xLow>>32)+uint32(yLow>>32))<<32 | uint64(uint32(xLow)+uint32(yLow)))
2053
+ ce.pushValue(uint64(uint32(xHigh>>32)+uint32(yHigh>>32))<<32 | uint64(uint32(xHigh)+uint32(yHigh)))
2054
+ case shapeI64x2:
2055
+ ce.pushValue(xLow + yLow)
2056
+ ce.pushValue(xHigh + yHigh)
2057
+ case shapeF32x4:
2058
+ ce.pushValue(
2059
+ addFloat32bits(uint32(xLow), uint32(yLow)) | addFloat32bits(uint32(xLow>>32), uint32(yLow>>32))<<32,
2060
+ )
2061
+ ce.pushValue(
2062
+ addFloat32bits(uint32(xHigh), uint32(yHigh)) | addFloat32bits(uint32(xHigh>>32), uint32(yHigh>>32))<<32,
2063
+ )
2064
+ case shapeF64x2:
2065
+ ce.pushValue(math.Float64bits(math.Float64frombits(xLow) + math.Float64frombits(yLow)))
2066
+ ce.pushValue(math.Float64bits(math.Float64frombits(xHigh) + math.Float64frombits(yHigh)))
2067
+ }
2068
+ frame.pc++
2069
+ case operationKindV128Sub:
2070
+ yHigh, yLow := ce.popValue(), ce.popValue()
2071
+ xHigh, xLow := ce.popValue(), ce.popValue()
2072
+ switch op.B1 {
2073
+ case shapeI8x16:
2074
+ ce.pushValue(
2075
+ uint64(uint8(xLow>>8)-uint8(yLow>>8))<<8 | uint64(uint8(xLow)-uint8(yLow)) |
2076
+ uint64(uint8(xLow>>24)-uint8(yLow>>24))<<24 | uint64(uint8(xLow>>16)-uint8(yLow>>16))<<16 |
2077
+ uint64(uint8(xLow>>40)-uint8(yLow>>40))<<40 | uint64(uint8(xLow>>32)-uint8(yLow>>32))<<32 |
2078
+ uint64(uint8(xLow>>56)-uint8(yLow>>56))<<56 | uint64(uint8(xLow>>48)-uint8(yLow>>48))<<48,
2079
+ )
2080
+ ce.pushValue(
2081
+ uint64(uint8(xHigh>>8)-uint8(yHigh>>8))<<8 | uint64(uint8(xHigh)-uint8(yHigh)) |
2082
+ uint64(uint8(xHigh>>24)-uint8(yHigh>>24))<<24 | uint64(uint8(xHigh>>16)-uint8(yHigh>>16))<<16 |
2083
+ uint64(uint8(xHigh>>40)-uint8(yHigh>>40))<<40 | uint64(uint8(xHigh>>32)-uint8(yHigh>>32))<<32 |
2084
+ uint64(uint8(xHigh>>56)-uint8(yHigh>>56))<<56 | uint64(uint8(xHigh>>48)-uint8(yHigh>>48))<<48,
2085
+ )
2086
+ case shapeI16x8:
2087
+ ce.pushValue(
2088
+ uint64(uint16(xLow>>16)-uint16(yLow>>16))<<16 | uint64(uint16(xLow)-uint16(yLow)) |
2089
+ uint64(uint16(xLow>>48)-uint16(yLow>>48))<<48 | uint64(uint16(xLow>>32)-uint16(yLow>>32))<<32,
2090
+ )
2091
+ ce.pushValue(
2092
+ uint64(uint16(xHigh>>16)-uint16(yHigh>>16))<<16 | uint64(uint16(xHigh)-uint16(yHigh)) |
2093
+ uint64(uint16(xHigh>>48)-uint16(yHigh>>48))<<48 | uint64(uint16(xHigh>>32)-uint16(yHigh>>32))<<32,
2094
+ )
2095
+ case shapeI32x4:
2096
+ ce.pushValue(uint64(uint32(xLow>>32-yLow>>32))<<32 | uint64(uint32(xLow)-uint32(yLow)))
2097
+ ce.pushValue(uint64(uint32(xHigh>>32-yHigh>>32))<<32 | uint64(uint32(xHigh)-uint32(yHigh)))
2098
+ case shapeI64x2:
2099
+ ce.pushValue(xLow - yLow)
2100
+ ce.pushValue(xHigh - yHigh)
2101
+ case shapeF32x4:
2102
+ ce.pushValue(
2103
+ subFloat32bits(uint32(xLow), uint32(yLow)) | subFloat32bits(uint32(xLow>>32), uint32(yLow>>32))<<32,
2104
+ )
2105
+ ce.pushValue(
2106
+ subFloat32bits(uint32(xHigh), uint32(yHigh)) | subFloat32bits(uint32(xHigh>>32), uint32(yHigh>>32))<<32,
2107
+ )
2108
+ case shapeF64x2:
2109
+ ce.pushValue(math.Float64bits(math.Float64frombits(xLow) - math.Float64frombits(yLow)))
2110
+ ce.pushValue(math.Float64bits(math.Float64frombits(xHigh) - math.Float64frombits(yHigh)))
2111
+ }
2112
+ frame.pc++
2113
+ case operationKindV128Load:
2114
+ offset := ce.popMemoryOffset(op)
2115
+ switch op.B1 {
2116
+ case v128LoadType128:
2117
+ lo, ok := memoryInst.ReadUint64Le(offset)
2118
+ if !ok {
2119
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2120
+ }
2121
+ ce.pushValue(lo)
2122
+ hi, ok := memoryInst.ReadUint64Le(offset + 8)
2123
+ if !ok {
2124
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2125
+ }
2126
+ ce.pushValue(hi)
2127
+ case v128LoadType8x8s:
2128
+ data, ok := memoryInst.Read(offset, 8)
2129
+ if !ok {
2130
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2131
+ }
2132
+ ce.pushValue(
2133
+ uint64(uint16(int8(data[3])))<<48 | uint64(uint16(int8(data[2])))<<32 | uint64(uint16(int8(data[1])))<<16 | uint64(uint16(int8(data[0]))),
2134
+ )
2135
+ ce.pushValue(
2136
+ uint64(uint16(int8(data[7])))<<48 | uint64(uint16(int8(data[6])))<<32 | uint64(uint16(int8(data[5])))<<16 | uint64(uint16(int8(data[4]))),
2137
+ )
2138
+ case v128LoadType8x8u:
2139
+ data, ok := memoryInst.Read(offset, 8)
2140
+ if !ok {
2141
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2142
+ }
2143
+ ce.pushValue(
2144
+ uint64(data[3])<<48 | uint64(data[2])<<32 | uint64(data[1])<<16 | uint64(data[0]),
2145
+ )
2146
+ ce.pushValue(
2147
+ uint64(data[7])<<48 | uint64(data[6])<<32 | uint64(data[5])<<16 | uint64(data[4]),
2148
+ )
2149
+ case v128LoadType16x4s:
2150
+ data, ok := memoryInst.Read(offset, 8)
2151
+ if !ok {
2152
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2153
+ }
2154
+ ce.pushValue(
2155
+ uint64(int16(binary.LittleEndian.Uint16(data[2:])))<<32 |
2156
+ uint64(uint32(int16(binary.LittleEndian.Uint16(data)))),
2157
+ )
2158
+ ce.pushValue(
2159
+ uint64(uint32(int16(binary.LittleEndian.Uint16(data[6:]))))<<32 |
2160
+ uint64(uint32(int16(binary.LittleEndian.Uint16(data[4:])))),
2161
+ )
2162
+ case v128LoadType16x4u:
2163
+ data, ok := memoryInst.Read(offset, 8)
2164
+ if !ok {
2165
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2166
+ }
2167
+ ce.pushValue(
2168
+ uint64(binary.LittleEndian.Uint16(data[2:]))<<32 | uint64(binary.LittleEndian.Uint16(data)),
2169
+ )
2170
+ ce.pushValue(
2171
+ uint64(binary.LittleEndian.Uint16(data[6:]))<<32 | uint64(binary.LittleEndian.Uint16(data[4:])),
2172
+ )
2173
+ case v128LoadType32x2s:
2174
+ data, ok := memoryInst.Read(offset, 8)
2175
+ if !ok {
2176
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2177
+ }
2178
+ ce.pushValue(uint64(int32(binary.LittleEndian.Uint32(data))))
2179
+ ce.pushValue(uint64(int32(binary.LittleEndian.Uint32(data[4:]))))
2180
+ case v128LoadType32x2u:
2181
+ data, ok := memoryInst.Read(offset, 8)
2182
+ if !ok {
2183
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2184
+ }
2185
+ ce.pushValue(uint64(binary.LittleEndian.Uint32(data)))
2186
+ ce.pushValue(uint64(binary.LittleEndian.Uint32(data[4:])))
2187
+ case v128LoadType8Splat:
2188
+ v, ok := memoryInst.ReadByte(offset)
2189
+ if !ok {
2190
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2191
+ }
2192
+ v8 := uint64(v)<<56 | uint64(v)<<48 | uint64(v)<<40 | uint64(v)<<32 |
2193
+ uint64(v)<<24 | uint64(v)<<16 | uint64(v)<<8 | uint64(v)
2194
+ ce.pushValue(v8)
2195
+ ce.pushValue(v8)
2196
+ case v128LoadType16Splat:
2197
+ v, ok := memoryInst.ReadUint16Le(offset)
2198
+ if !ok {
2199
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2200
+ }
2201
+ v4 := uint64(v)<<48 | uint64(v)<<32 | uint64(v)<<16 | uint64(v)
2202
+ ce.pushValue(v4)
2203
+ ce.pushValue(v4)
2204
+ case v128LoadType32Splat:
2205
+ v, ok := memoryInst.ReadUint32Le(offset)
2206
+ if !ok {
2207
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2208
+ }
2209
+ vv := uint64(v)<<32 | uint64(v)
2210
+ ce.pushValue(vv)
2211
+ ce.pushValue(vv)
2212
+ case v128LoadType64Splat:
2213
+ lo, ok := memoryInst.ReadUint64Le(offset)
2214
+ if !ok {
2215
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2216
+ }
2217
+ ce.pushValue(lo)
2218
+ ce.pushValue(lo)
2219
+ case v128LoadType32zero:
2220
+ lo, ok := memoryInst.ReadUint32Le(offset)
2221
+ if !ok {
2222
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2223
+ }
2224
+ ce.pushValue(uint64(lo))
2225
+ ce.pushValue(0)
2226
+ case v128LoadType64zero:
2227
+ lo, ok := memoryInst.ReadUint64Le(offset)
2228
+ if !ok {
2229
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2230
+ }
2231
+ ce.pushValue(lo)
2232
+ ce.pushValue(0)
2233
+ }
2234
+ frame.pc++
2235
+ case operationKindV128LoadLane:
2236
+ hi, lo := ce.popValue(), ce.popValue()
2237
+ offset := ce.popMemoryOffset(op)
2238
+ switch op.B1 {
2239
+ case 8:
2240
+ b, ok := memoryInst.ReadByte(offset)
2241
+ if !ok {
2242
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2243
+ }
2244
+ if op.B2 < 8 {
2245
+ s := op.B2 << 3
2246
+ lo = (lo & ^(0xff << s)) | uint64(b)<<s
2247
+ } else {
2248
+ s := (op.B2 - 8) << 3
2249
+ hi = (hi & ^(0xff << s)) | uint64(b)<<s
2250
+ }
2251
+ case 16:
2252
+ b, ok := memoryInst.ReadUint16Le(offset)
2253
+ if !ok {
2254
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2255
+ }
2256
+ if op.B2 < 4 {
2257
+ s := op.B2 << 4
2258
+ lo = (lo & ^(0xff_ff << s)) | uint64(b)<<s
2259
+ } else {
2260
+ s := (op.B2 - 4) << 4
2261
+ hi = (hi & ^(0xff_ff << s)) | uint64(b)<<s
2262
+ }
2263
+ case 32:
2264
+ b, ok := memoryInst.ReadUint32Le(offset)
2265
+ if !ok {
2266
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2267
+ }
2268
+ if op.B2 < 2 {
2269
+ s := op.B2 << 5
2270
+ lo = (lo & ^(0xff_ff_ff_ff << s)) | uint64(b)<<s
2271
+ } else {
2272
+ s := (op.B2 - 2) << 5
2273
+ hi = (hi & ^(0xff_ff_ff_ff << s)) | uint64(b)<<s
2274
+ }
2275
+ case 64:
2276
+ b, ok := memoryInst.ReadUint64Le(offset)
2277
+ if !ok {
2278
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2279
+ }
2280
+ if op.B2 == 0 {
2281
+ lo = b
2282
+ } else {
2283
+ hi = b
2284
+ }
2285
+ }
2286
+ ce.pushValue(lo)
2287
+ ce.pushValue(hi)
2288
+ frame.pc++
2289
+ case operationKindV128Store:
2290
+ hi, lo := ce.popValue(), ce.popValue()
2291
+ offset := ce.popMemoryOffset(op)
2292
+ // Write the upper bytes first to trigger an early error if the memory access is out of bounds.
2293
+ // Otherwise, the lower bytes might be written to memory, but the upper bytes might not.
2294
+ if uint64(offset)+8 > math.MaxUint32 {
2295
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2296
+ }
2297
+ if ok := memoryInst.WriteUint64Le(offset+8, hi); !ok {
2298
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2299
+ }
2300
+ if ok := memoryInst.WriteUint64Le(offset, lo); !ok {
2301
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2302
+ }
2303
+ frame.pc++
2304
+ case operationKindV128StoreLane:
2305
+ hi, lo := ce.popValue(), ce.popValue()
2306
+ offset := ce.popMemoryOffset(op)
2307
+ var ok bool
2308
+ switch op.B1 {
2309
+ case 8:
2310
+ if op.B2 < 8 {
2311
+ ok = memoryInst.WriteByte(offset, byte(lo>>(op.B2*8)))
2312
+ } else {
2313
+ ok = memoryInst.WriteByte(offset, byte(hi>>((op.B2-8)*8)))
2314
+ }
2315
+ case 16:
2316
+ if op.B2 < 4 {
2317
+ ok = memoryInst.WriteUint16Le(offset, uint16(lo>>(op.B2*16)))
2318
+ } else {
2319
+ ok = memoryInst.WriteUint16Le(offset, uint16(hi>>((op.B2-4)*16)))
2320
+ }
2321
+ case 32:
2322
+ if op.B2 < 2 {
2323
+ ok = memoryInst.WriteUint32Le(offset, uint32(lo>>(op.B2*32)))
2324
+ } else {
2325
+ ok = memoryInst.WriteUint32Le(offset, uint32(hi>>((op.B2-2)*32)))
2326
+ }
2327
+ case 64:
2328
+ if op.B2 == 0 {
2329
+ ok = memoryInst.WriteUint64Le(offset, lo)
2330
+ } else {
2331
+ ok = memoryInst.WriteUint64Le(offset, hi)
2332
+ }
2333
+ }
2334
+ if !ok {
2335
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
2336
+ }
2337
+ frame.pc++
2338
+ case operationKindV128ReplaceLane:
2339
+ v := ce.popValue()
2340
+ hi, lo := ce.popValue(), ce.popValue()
2341
+ switch op.B1 {
2342
+ case shapeI8x16:
2343
+ if op.B2 < 8 {
2344
+ s := op.B2 << 3
2345
+ lo = (lo & ^(0xff << s)) | uint64(byte(v))<<s
2346
+ } else {
2347
+ s := (op.B2 - 8) << 3
2348
+ hi = (hi & ^(0xff << s)) | uint64(byte(v))<<s
2349
+ }
2350
+ case shapeI16x8:
2351
+ if op.B2 < 4 {
2352
+ s := op.B2 << 4
2353
+ lo = (lo & ^(0xff_ff << s)) | uint64(uint16(v))<<s
2354
+ } else {
2355
+ s := (op.B2 - 4) << 4
2356
+ hi = (hi & ^(0xff_ff << s)) | uint64(uint16(v))<<s
2357
+ }
2358
+ case shapeI32x4, shapeF32x4:
2359
+ if op.B2 < 2 {
2360
+ s := op.B2 << 5
2361
+ lo = (lo & ^(0xff_ff_ff_ff << s)) | uint64(uint32(v))<<s
2362
+ } else {
2363
+ s := (op.B2 - 2) << 5
2364
+ hi = (hi & ^(0xff_ff_ff_ff << s)) | uint64(uint32(v))<<s
2365
+ }
2366
+ case shapeI64x2, shapeF64x2:
2367
+ if op.B2 == 0 {
2368
+ lo = v
2369
+ } else {
2370
+ hi = v
2371
+ }
2372
+ }
2373
+ ce.pushValue(lo)
2374
+ ce.pushValue(hi)
2375
+ frame.pc++
2376
+ case operationKindV128ExtractLane:
2377
+ hi, lo := ce.popValue(), ce.popValue()
2378
+ var v uint64
2379
+ switch op.B1 {
2380
+ case shapeI8x16:
2381
+ var u8 byte
2382
+ if op.B2 < 8 {
2383
+ u8 = byte(lo >> (op.B2 * 8))
2384
+ } else {
2385
+ u8 = byte(hi >> ((op.B2 - 8) * 8))
2386
+ }
2387
+ if op.B3 {
2388
+ // sign-extend.
2389
+ v = uint64(uint32(int8(u8)))
2390
+ } else {
2391
+ v = uint64(u8)
2392
+ }
2393
+ case shapeI16x8:
2394
+ var u16 uint16
2395
+ if op.B2 < 4 {
2396
+ u16 = uint16(lo >> (op.B2 * 16))
2397
+ } else {
2398
+ u16 = uint16(hi >> ((op.B2 - 4) * 16))
2399
+ }
2400
+ if op.B3 {
2401
+ // sign-extend.
2402
+ v = uint64(uint32(int16(u16)))
2403
+ } else {
2404
+ v = uint64(u16)
2405
+ }
2406
+ case shapeI32x4, shapeF32x4:
2407
+ if op.B2 < 2 {
2408
+ v = uint64(uint32(lo >> (op.B2 * 32)))
2409
+ } else {
2410
+ v = uint64(uint32(hi >> ((op.B2 - 2) * 32)))
2411
+ }
2412
+ case shapeI64x2, shapeF64x2:
2413
+ if op.B2 == 0 {
2414
+ v = lo
2415
+ } else {
2416
+ v = hi
2417
+ }
2418
+ }
2419
+ ce.pushValue(v)
2420
+ frame.pc++
2421
+ case operationKindV128Splat:
2422
+ v := ce.popValue()
2423
+ var hi, lo uint64
2424
+ switch op.B1 {
2425
+ case shapeI8x16:
2426
+ v8 := uint64(byte(v))<<56 | uint64(byte(v))<<48 | uint64(byte(v))<<40 | uint64(byte(v))<<32 |
2427
+ uint64(byte(v))<<24 | uint64(byte(v))<<16 | uint64(byte(v))<<8 | uint64(byte(v))
2428
+ hi, lo = v8, v8
2429
+ case shapeI16x8:
2430
+ v4 := uint64(uint16(v))<<48 | uint64(uint16(v))<<32 | uint64(uint16(v))<<16 | uint64(uint16(v))
2431
+ hi, lo = v4, v4
2432
+ case shapeI32x4, shapeF32x4:
2433
+ v2 := uint64(uint32(v))<<32 | uint64(uint32(v))
2434
+ lo, hi = v2, v2
2435
+ case shapeI64x2, shapeF64x2:
2436
+ lo, hi = v, v
2437
+ }
2438
+ ce.pushValue(lo)
2439
+ ce.pushValue(hi)
2440
+ frame.pc++
2441
+ case operationKindV128Swizzle:
2442
+ idxHi, idxLo := ce.popValue(), ce.popValue()
2443
+ baseHi, baseLo := ce.popValue(), ce.popValue()
2444
+ var newVal [16]byte
2445
+ for i := 0; i < 16; i++ {
2446
+ var id byte
2447
+ if i < 8 {
2448
+ id = byte(idxLo >> (i * 8))
2449
+ } else {
2450
+ id = byte(idxHi >> ((i - 8) * 8))
2451
+ }
2452
+ if id < 8 {
2453
+ newVal[i] = byte(baseLo >> (id * 8))
2454
+ } else if id < 16 {
2455
+ newVal[i] = byte(baseHi >> ((id - 8) * 8))
2456
+ }
2457
+ }
2458
+ ce.pushValue(binary.LittleEndian.Uint64(newVal[:8]))
2459
+ ce.pushValue(binary.LittleEndian.Uint64(newVal[8:]))
2460
+ frame.pc++
2461
+ case operationKindV128Shuffle:
2462
+ xHi, xLo, yHi, yLo := ce.popValue(), ce.popValue(), ce.popValue(), ce.popValue()
2463
+ var newVal [16]byte
2464
+ for i, l := range op.Us {
2465
+ if l < 8 {
2466
+ newVal[i] = byte(yLo >> (l * 8))
2467
+ } else if l < 16 {
2468
+ newVal[i] = byte(yHi >> ((l - 8) * 8))
2469
+ } else if l < 24 {
2470
+ newVal[i] = byte(xLo >> ((l - 16) * 8))
2471
+ } else if l < 32 {
2472
+ newVal[i] = byte(xHi >> ((l - 24) * 8))
2473
+ }
2474
+ }
2475
+ ce.pushValue(binary.LittleEndian.Uint64(newVal[:8]))
2476
+ ce.pushValue(binary.LittleEndian.Uint64(newVal[8:]))
2477
+ frame.pc++
2478
+ case operationKindV128AnyTrue:
2479
+ hi, lo := ce.popValue(), ce.popValue()
2480
+ if hi != 0 || lo != 0 {
2481
+ ce.pushValue(1)
2482
+ } else {
2483
+ ce.pushValue(0)
2484
+ }
2485
+ frame.pc++
2486
+ case operationKindV128AllTrue:
2487
+ hi, lo := ce.popValue(), ce.popValue()
2488
+ var ret bool
2489
+ switch op.B1 {
2490
+ case shapeI8x16:
2491
+ ret = (uint8(lo) != 0) && (uint8(lo>>8) != 0) && (uint8(lo>>16) != 0) && (uint8(lo>>24) != 0) &&
2492
+ (uint8(lo>>32) != 0) && (uint8(lo>>40) != 0) && (uint8(lo>>48) != 0) && (uint8(lo>>56) != 0) &&
2493
+ (uint8(hi) != 0) && (uint8(hi>>8) != 0) && (uint8(hi>>16) != 0) && (uint8(hi>>24) != 0) &&
2494
+ (uint8(hi>>32) != 0) && (uint8(hi>>40) != 0) && (uint8(hi>>48) != 0) && (uint8(hi>>56) != 0)
2495
+ case shapeI16x8:
2496
+ ret = (uint16(lo) != 0) && (uint16(lo>>16) != 0) && (uint16(lo>>32) != 0) && (uint16(lo>>48) != 0) &&
2497
+ (uint16(hi) != 0) && (uint16(hi>>16) != 0) && (uint16(hi>>32) != 0) && (uint16(hi>>48) != 0)
2498
+ case shapeI32x4:
2499
+ ret = (uint32(lo) != 0) && (uint32(lo>>32) != 0) &&
2500
+ (uint32(hi) != 0) && (uint32(hi>>32) != 0)
2501
+ case shapeI64x2:
2502
+ ret = (lo != 0) &&
2503
+ (hi != 0)
2504
+ }
2505
+ if ret {
2506
+ ce.pushValue(1)
2507
+ } else {
2508
+ ce.pushValue(0)
2509
+ }
2510
+ frame.pc++
2511
+ case operationKindV128BitMask:
2512
+ // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#bitmask-extraction
2513
+ hi, lo := ce.popValue(), ce.popValue()
2514
+ var res uint64
2515
+ switch op.B1 {
2516
+ case shapeI8x16:
2517
+ for i := 0; i < 8; i++ {
2518
+ if int8(lo>>(i*8)) < 0 {
2519
+ res |= 1 << i
2520
+ }
2521
+ }
2522
+ for i := 0; i < 8; i++ {
2523
+ if int8(hi>>(i*8)) < 0 {
2524
+ res |= 1 << (i + 8)
2525
+ }
2526
+ }
2527
+ case shapeI16x8:
2528
+ for i := 0; i < 4; i++ {
2529
+ if int16(lo>>(i*16)) < 0 {
2530
+ res |= 1 << i
2531
+ }
2532
+ }
2533
+ for i := 0; i < 4; i++ {
2534
+ if int16(hi>>(i*16)) < 0 {
2535
+ res |= 1 << (i + 4)
2536
+ }
2537
+ }
2538
+ case shapeI32x4:
2539
+ for i := 0; i < 2; i++ {
2540
+ if int32(lo>>(i*32)) < 0 {
2541
+ res |= 1 << i
2542
+ }
2543
+ }
2544
+ for i := 0; i < 2; i++ {
2545
+ if int32(hi>>(i*32)) < 0 {
2546
+ res |= 1 << (i + 2)
2547
+ }
2548
+ }
2549
+ case shapeI64x2:
2550
+ if int64(lo) < 0 {
2551
+ res |= 0b01
2552
+ }
2553
+ if int(hi) < 0 {
2554
+ res |= 0b10
2555
+ }
2556
+ }
2557
+ ce.pushValue(res)
2558
+ frame.pc++
2559
+ case operationKindV128And:
2560
+ x2Hi, x2Lo := ce.popValue(), ce.popValue()
2561
+ x1Hi, x1Lo := ce.popValue(), ce.popValue()
2562
+ ce.pushValue(x1Lo & x2Lo)
2563
+ ce.pushValue(x1Hi & x2Hi)
2564
+ frame.pc++
2565
+ case operationKindV128Not:
2566
+ hi, lo := ce.popValue(), ce.popValue()
2567
+ ce.pushValue(^lo)
2568
+ ce.pushValue(^hi)
2569
+ frame.pc++
2570
+ case operationKindV128Or:
2571
+ x2Hi, x2Lo := ce.popValue(), ce.popValue()
2572
+ x1Hi, x1Lo := ce.popValue(), ce.popValue()
2573
+ ce.pushValue(x1Lo | x2Lo)
2574
+ ce.pushValue(x1Hi | x2Hi)
2575
+ frame.pc++
2576
+ case operationKindV128Xor:
2577
+ x2Hi, x2Lo := ce.popValue(), ce.popValue()
2578
+ x1Hi, x1Lo := ce.popValue(), ce.popValue()
2579
+ ce.pushValue(x1Lo ^ x2Lo)
2580
+ ce.pushValue(x1Hi ^ x2Hi)
2581
+ frame.pc++
2582
+ case operationKindV128Bitselect:
2583
+ // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#bitwise-select
2584
+ cHi, cLo := ce.popValue(), ce.popValue()
2585
+ x2Hi, x2Lo := ce.popValue(), ce.popValue()
2586
+ x1Hi, x1Lo := ce.popValue(), ce.popValue()
2587
+ // v128.or(v128.and(v1, c), v128.and(v2, v128.not(c)))
2588
+ ce.pushValue((x1Lo & cLo) | (x2Lo & (^cLo)))
2589
+ ce.pushValue((x1Hi & cHi) | (x2Hi & (^cHi)))
2590
+ frame.pc++
2591
+ case operationKindV128AndNot:
2592
+ x2Hi, x2Lo := ce.popValue(), ce.popValue()
2593
+ x1Hi, x1Lo := ce.popValue(), ce.popValue()
2594
+ ce.pushValue(x1Lo & (^x2Lo))
2595
+ ce.pushValue(x1Hi & (^x2Hi))
2596
+ frame.pc++
2597
+ case operationKindV128Shl:
2598
+ s := ce.popValue()
2599
+ hi, lo := ce.popValue(), ce.popValue()
2600
+ switch op.B1 {
2601
+ case shapeI8x16:
2602
+ s = s % 8
2603
+ lo = uint64(uint8(lo<<s)) |
2604
+ uint64(uint8((lo>>8)<<s))<<8 |
2605
+ uint64(uint8((lo>>16)<<s))<<16 |
2606
+ uint64(uint8((lo>>24)<<s))<<24 |
2607
+ uint64(uint8((lo>>32)<<s))<<32 |
2608
+ uint64(uint8((lo>>40)<<s))<<40 |
2609
+ uint64(uint8((lo>>48)<<s))<<48 |
2610
+ uint64(uint8((lo>>56)<<s))<<56
2611
+ hi = uint64(uint8(hi<<s)) |
2612
+ uint64(uint8((hi>>8)<<s))<<8 |
2613
+ uint64(uint8((hi>>16)<<s))<<16 |
2614
+ uint64(uint8((hi>>24)<<s))<<24 |
2615
+ uint64(uint8((hi>>32)<<s))<<32 |
2616
+ uint64(uint8((hi>>40)<<s))<<40 |
2617
+ uint64(uint8((hi>>48)<<s))<<48 |
2618
+ uint64(uint8((hi>>56)<<s))<<56
2619
+ case shapeI16x8:
2620
+ s = s % 16
2621
+ lo = uint64(uint16(lo<<s)) |
2622
+ uint64(uint16((lo>>16)<<s))<<16 |
2623
+ uint64(uint16((lo>>32)<<s))<<32 |
2624
+ uint64(uint16((lo>>48)<<s))<<48
2625
+ hi = uint64(uint16(hi<<s)) |
2626
+ uint64(uint16((hi>>16)<<s))<<16 |
2627
+ uint64(uint16((hi>>32)<<s))<<32 |
2628
+ uint64(uint16((hi>>48)<<s))<<48
2629
+ case shapeI32x4:
2630
+ s = s % 32
2631
+ lo = uint64(uint32(lo<<s)) | uint64(uint32((lo>>32)<<s))<<32
2632
+ hi = uint64(uint32(hi<<s)) | uint64(uint32((hi>>32)<<s))<<32
2633
+ case shapeI64x2:
2634
+ s = s % 64
2635
+ lo = lo << s
2636
+ hi = hi << s
2637
+ }
2638
+ ce.pushValue(lo)
2639
+ ce.pushValue(hi)
2640
+ frame.pc++
2641
+ case operationKindV128Shr:
2642
+ s := ce.popValue()
2643
+ hi, lo := ce.popValue(), ce.popValue()
2644
+ switch op.B1 {
2645
+ case shapeI8x16:
2646
+ s = s % 8
2647
+ if op.B3 { // signed
2648
+ lo = uint64(uint8(int8(lo)>>s)) |
2649
+ uint64(uint8(int8(lo>>8)>>s))<<8 |
2650
+ uint64(uint8(int8(lo>>16)>>s))<<16 |
2651
+ uint64(uint8(int8(lo>>24)>>s))<<24 |
2652
+ uint64(uint8(int8(lo>>32)>>s))<<32 |
2653
+ uint64(uint8(int8(lo>>40)>>s))<<40 |
2654
+ uint64(uint8(int8(lo>>48)>>s))<<48 |
2655
+ uint64(uint8(int8(lo>>56)>>s))<<56
2656
+ hi = uint64(uint8(int8(hi)>>s)) |
2657
+ uint64(uint8(int8(hi>>8)>>s))<<8 |
2658
+ uint64(uint8(int8(hi>>16)>>s))<<16 |
2659
+ uint64(uint8(int8(hi>>24)>>s))<<24 |
2660
+ uint64(uint8(int8(hi>>32)>>s))<<32 |
2661
+ uint64(uint8(int8(hi>>40)>>s))<<40 |
2662
+ uint64(uint8(int8(hi>>48)>>s))<<48 |
2663
+ uint64(uint8(int8(hi>>56)>>s))<<56
2664
+ } else {
2665
+ lo = uint64(uint8(lo)>>s) |
2666
+ uint64(uint8(lo>>8)>>s)<<8 |
2667
+ uint64(uint8(lo>>16)>>s)<<16 |
2668
+ uint64(uint8(lo>>24)>>s)<<24 |
2669
+ uint64(uint8(lo>>32)>>s)<<32 |
2670
+ uint64(uint8(lo>>40)>>s)<<40 |
2671
+ uint64(uint8(lo>>48)>>s)<<48 |
2672
+ uint64(uint8(lo>>56)>>s)<<56
2673
+ hi = uint64(uint8(hi)>>s) |
2674
+ uint64(uint8(hi>>8)>>s)<<8 |
2675
+ uint64(uint8(hi>>16)>>s)<<16 |
2676
+ uint64(uint8(hi>>24)>>s)<<24 |
2677
+ uint64(uint8(hi>>32)>>s)<<32 |
2678
+ uint64(uint8(hi>>40)>>s)<<40 |
2679
+ uint64(uint8(hi>>48)>>s)<<48 |
2680
+ uint64(uint8(hi>>56)>>s)<<56
2681
+ }
2682
+ case shapeI16x8:
2683
+ s = s % 16
2684
+ if op.B3 { // signed
2685
+ lo = uint64(uint16(int16(lo)>>s)) |
2686
+ uint64(uint16(int16(lo>>16)>>s))<<16 |
2687
+ uint64(uint16(int16(lo>>32)>>s))<<32 |
2688
+ uint64(uint16(int16(lo>>48)>>s))<<48
2689
+ hi = uint64(uint16(int16(hi)>>s)) |
2690
+ uint64(uint16(int16(hi>>16)>>s))<<16 |
2691
+ uint64(uint16(int16(hi>>32)>>s))<<32 |
2692
+ uint64(uint16(int16(hi>>48)>>s))<<48
2693
+ } else {
2694
+ lo = uint64(uint16(lo)>>s) |
2695
+ uint64(uint16(lo>>16)>>s)<<16 |
2696
+ uint64(uint16(lo>>32)>>s)<<32 |
2697
+ uint64(uint16(lo>>48)>>s)<<48
2698
+ hi = uint64(uint16(hi)>>s) |
2699
+ uint64(uint16(hi>>16)>>s)<<16 |
2700
+ uint64(uint16(hi>>32)>>s)<<32 |
2701
+ uint64(uint16(hi>>48)>>s)<<48
2702
+ }
2703
+ case shapeI32x4:
2704
+ s = s % 32
2705
+ if op.B3 {
2706
+ lo = uint64(uint32(int32(lo)>>s)) | uint64(uint32(int32(lo>>32)>>s))<<32
2707
+ hi = uint64(uint32(int32(hi)>>s)) | uint64(uint32(int32(hi>>32)>>s))<<32
2708
+ } else {
2709
+ lo = uint64(uint32(lo)>>s) | uint64(uint32(lo>>32)>>s)<<32
2710
+ hi = uint64(uint32(hi)>>s) | uint64(uint32(hi>>32)>>s)<<32
2711
+ }
2712
+ case shapeI64x2:
2713
+ s = s % 64
2714
+ if op.B3 { // signed
2715
+ lo = uint64(int64(lo) >> s)
2716
+ hi = uint64(int64(hi) >> s)
2717
+ } else {
2718
+ lo = lo >> s
2719
+ hi = hi >> s
2720
+ }
2721
+
2722
+ }
2723
+ ce.pushValue(lo)
2724
+ ce.pushValue(hi)
2725
+ frame.pc++
2726
+ case operationKindV128Cmp:
2727
+ x2Hi, x2Lo := ce.popValue(), ce.popValue()
2728
+ x1Hi, x1Lo := ce.popValue(), ce.popValue()
2729
+ var result []bool
2730
+ switch op.B1 {
2731
+ case v128CmpTypeI8x16Eq:
2732
+ result = []bool{
2733
+ byte(x1Lo>>0) == byte(x2Lo>>0), byte(x1Lo>>8) == byte(x2Lo>>8),
2734
+ byte(x1Lo>>16) == byte(x2Lo>>16), byte(x1Lo>>24) == byte(x2Lo>>24),
2735
+ byte(x1Lo>>32) == byte(x2Lo>>32), byte(x1Lo>>40) == byte(x2Lo>>40),
2736
+ byte(x1Lo>>48) == byte(x2Lo>>48), byte(x1Lo>>56) == byte(x2Lo>>56),
2737
+ byte(x1Hi>>0) == byte(x2Hi>>0), byte(x1Hi>>8) == byte(x2Hi>>8),
2738
+ byte(x1Hi>>16) == byte(x2Hi>>16), byte(x1Hi>>24) == byte(x2Hi>>24),
2739
+ byte(x1Hi>>32) == byte(x2Hi>>32), byte(x1Hi>>40) == byte(x2Hi>>40),
2740
+ byte(x1Hi>>48) == byte(x2Hi>>48), byte(x1Hi>>56) == byte(x2Hi>>56),
2741
+ }
2742
+ case v128CmpTypeI8x16Ne:
2743
+ result = []bool{
2744
+ byte(x1Lo>>0) != byte(x2Lo>>0), byte(x1Lo>>8) != byte(x2Lo>>8),
2745
+ byte(x1Lo>>16) != byte(x2Lo>>16), byte(x1Lo>>24) != byte(x2Lo>>24),
2746
+ byte(x1Lo>>32) != byte(x2Lo>>32), byte(x1Lo>>40) != byte(x2Lo>>40),
2747
+ byte(x1Lo>>48) != byte(x2Lo>>48), byte(x1Lo>>56) != byte(x2Lo>>56),
2748
+ byte(x1Hi>>0) != byte(x2Hi>>0), byte(x1Hi>>8) != byte(x2Hi>>8),
2749
+ byte(x1Hi>>16) != byte(x2Hi>>16), byte(x1Hi>>24) != byte(x2Hi>>24),
2750
+ byte(x1Hi>>32) != byte(x2Hi>>32), byte(x1Hi>>40) != byte(x2Hi>>40),
2751
+ byte(x1Hi>>48) != byte(x2Hi>>48), byte(x1Hi>>56) != byte(x2Hi>>56),
2752
+ }
2753
+ case v128CmpTypeI8x16LtS:
2754
+ result = []bool{
2755
+ int8(x1Lo>>0) < int8(x2Lo>>0), int8(x1Lo>>8) < int8(x2Lo>>8),
2756
+ int8(x1Lo>>16) < int8(x2Lo>>16), int8(x1Lo>>24) < int8(x2Lo>>24),
2757
+ int8(x1Lo>>32) < int8(x2Lo>>32), int8(x1Lo>>40) < int8(x2Lo>>40),
2758
+ int8(x1Lo>>48) < int8(x2Lo>>48), int8(x1Lo>>56) < int8(x2Lo>>56),
2759
+ int8(x1Hi>>0) < int8(x2Hi>>0), int8(x1Hi>>8) < int8(x2Hi>>8),
2760
+ int8(x1Hi>>16) < int8(x2Hi>>16), int8(x1Hi>>24) < int8(x2Hi>>24),
2761
+ int8(x1Hi>>32) < int8(x2Hi>>32), int8(x1Hi>>40) < int8(x2Hi>>40),
2762
+ int8(x1Hi>>48) < int8(x2Hi>>48), int8(x1Hi>>56) < int8(x2Hi>>56),
2763
+ }
2764
+ case v128CmpTypeI8x16LtU:
2765
+ result = []bool{
2766
+ byte(x1Lo>>0) < byte(x2Lo>>0), byte(x1Lo>>8) < byte(x2Lo>>8),
2767
+ byte(x1Lo>>16) < byte(x2Lo>>16), byte(x1Lo>>24) < byte(x2Lo>>24),
2768
+ byte(x1Lo>>32) < byte(x2Lo>>32), byte(x1Lo>>40) < byte(x2Lo>>40),
2769
+ byte(x1Lo>>48) < byte(x2Lo>>48), byte(x1Lo>>56) < byte(x2Lo>>56),
2770
+ byte(x1Hi>>0) < byte(x2Hi>>0), byte(x1Hi>>8) < byte(x2Hi>>8),
2771
+ byte(x1Hi>>16) < byte(x2Hi>>16), byte(x1Hi>>24) < byte(x2Hi>>24),
2772
+ byte(x1Hi>>32) < byte(x2Hi>>32), byte(x1Hi>>40) < byte(x2Hi>>40),
2773
+ byte(x1Hi>>48) < byte(x2Hi>>48), byte(x1Hi>>56) < byte(x2Hi>>56),
2774
+ }
2775
+ case v128CmpTypeI8x16GtS:
2776
+ result = []bool{
2777
+ int8(x1Lo>>0) > int8(x2Lo>>0), int8(x1Lo>>8) > int8(x2Lo>>8),
2778
+ int8(x1Lo>>16) > int8(x2Lo>>16), int8(x1Lo>>24) > int8(x2Lo>>24),
2779
+ int8(x1Lo>>32) > int8(x2Lo>>32), int8(x1Lo>>40) > int8(x2Lo>>40),
2780
+ int8(x1Lo>>48) > int8(x2Lo>>48), int8(x1Lo>>56) > int8(x2Lo>>56),
2781
+ int8(x1Hi>>0) > int8(x2Hi>>0), int8(x1Hi>>8) > int8(x2Hi>>8),
2782
+ int8(x1Hi>>16) > int8(x2Hi>>16), int8(x1Hi>>24) > int8(x2Hi>>24),
2783
+ int8(x1Hi>>32) > int8(x2Hi>>32), int8(x1Hi>>40) > int8(x2Hi>>40),
2784
+ int8(x1Hi>>48) > int8(x2Hi>>48), int8(x1Hi>>56) > int8(x2Hi>>56),
2785
+ }
2786
+ case v128CmpTypeI8x16GtU:
2787
+ result = []bool{
2788
+ byte(x1Lo>>0) > byte(x2Lo>>0), byte(x1Lo>>8) > byte(x2Lo>>8),
2789
+ byte(x1Lo>>16) > byte(x2Lo>>16), byte(x1Lo>>24) > byte(x2Lo>>24),
2790
+ byte(x1Lo>>32) > byte(x2Lo>>32), byte(x1Lo>>40) > byte(x2Lo>>40),
2791
+ byte(x1Lo>>48) > byte(x2Lo>>48), byte(x1Lo>>56) > byte(x2Lo>>56),
2792
+ byte(x1Hi>>0) > byte(x2Hi>>0), byte(x1Hi>>8) > byte(x2Hi>>8),
2793
+ byte(x1Hi>>16) > byte(x2Hi>>16), byte(x1Hi>>24) > byte(x2Hi>>24),
2794
+ byte(x1Hi>>32) > byte(x2Hi>>32), byte(x1Hi>>40) > byte(x2Hi>>40),
2795
+ byte(x1Hi>>48) > byte(x2Hi>>48), byte(x1Hi>>56) > byte(x2Hi>>56),
2796
+ }
2797
+ case v128CmpTypeI8x16LeS:
2798
+ result = []bool{
2799
+ int8(x1Lo>>0) <= int8(x2Lo>>0), int8(x1Lo>>8) <= int8(x2Lo>>8),
2800
+ int8(x1Lo>>16) <= int8(x2Lo>>16), int8(x1Lo>>24) <= int8(x2Lo>>24),
2801
+ int8(x1Lo>>32) <= int8(x2Lo>>32), int8(x1Lo>>40) <= int8(x2Lo>>40),
2802
+ int8(x1Lo>>48) <= int8(x2Lo>>48), int8(x1Lo>>56) <= int8(x2Lo>>56),
2803
+ int8(x1Hi>>0) <= int8(x2Hi>>0), int8(x1Hi>>8) <= int8(x2Hi>>8),
2804
+ int8(x1Hi>>16) <= int8(x2Hi>>16), int8(x1Hi>>24) <= int8(x2Hi>>24),
2805
+ int8(x1Hi>>32) <= int8(x2Hi>>32), int8(x1Hi>>40) <= int8(x2Hi>>40),
2806
+ int8(x1Hi>>48) <= int8(x2Hi>>48), int8(x1Hi>>56) <= int8(x2Hi>>56),
2807
+ }
2808
+ case v128CmpTypeI8x16LeU:
2809
+ result = []bool{
2810
+ byte(x1Lo>>0) <= byte(x2Lo>>0), byte(x1Lo>>8) <= byte(x2Lo>>8),
2811
+ byte(x1Lo>>16) <= byte(x2Lo>>16), byte(x1Lo>>24) <= byte(x2Lo>>24),
2812
+ byte(x1Lo>>32) <= byte(x2Lo>>32), byte(x1Lo>>40) <= byte(x2Lo>>40),
2813
+ byte(x1Lo>>48) <= byte(x2Lo>>48), byte(x1Lo>>56) <= byte(x2Lo>>56),
2814
+ byte(x1Hi>>0) <= byte(x2Hi>>0), byte(x1Hi>>8) <= byte(x2Hi>>8),
2815
+ byte(x1Hi>>16) <= byte(x2Hi>>16), byte(x1Hi>>24) <= byte(x2Hi>>24),
2816
+ byte(x1Hi>>32) <= byte(x2Hi>>32), byte(x1Hi>>40) <= byte(x2Hi>>40),
2817
+ byte(x1Hi>>48) <= byte(x2Hi>>48), byte(x1Hi>>56) <= byte(x2Hi>>56),
2818
+ }
2819
+ case v128CmpTypeI8x16GeS:
2820
+ result = []bool{
2821
+ int8(x1Lo>>0) >= int8(x2Lo>>0), int8(x1Lo>>8) >= int8(x2Lo>>8),
2822
+ int8(x1Lo>>16) >= int8(x2Lo>>16), int8(x1Lo>>24) >= int8(x2Lo>>24),
2823
+ int8(x1Lo>>32) >= int8(x2Lo>>32), int8(x1Lo>>40) >= int8(x2Lo>>40),
2824
+ int8(x1Lo>>48) >= int8(x2Lo>>48), int8(x1Lo>>56) >= int8(x2Lo>>56),
2825
+ int8(x1Hi>>0) >= int8(x2Hi>>0), int8(x1Hi>>8) >= int8(x2Hi>>8),
2826
+ int8(x1Hi>>16) >= int8(x2Hi>>16), int8(x1Hi>>24) >= int8(x2Hi>>24),
2827
+ int8(x1Hi>>32) >= int8(x2Hi>>32), int8(x1Hi>>40) >= int8(x2Hi>>40),
2828
+ int8(x1Hi>>48) >= int8(x2Hi>>48), int8(x1Hi>>56) >= int8(x2Hi>>56),
2829
+ }
2830
+ case v128CmpTypeI8x16GeU:
2831
+ result = []bool{
2832
+ byte(x1Lo>>0) >= byte(x2Lo>>0), byte(x1Lo>>8) >= byte(x2Lo>>8),
2833
+ byte(x1Lo>>16) >= byte(x2Lo>>16), byte(x1Lo>>24) >= byte(x2Lo>>24),
2834
+ byte(x1Lo>>32) >= byte(x2Lo>>32), byte(x1Lo>>40) >= byte(x2Lo>>40),
2835
+ byte(x1Lo>>48) >= byte(x2Lo>>48), byte(x1Lo>>56) >= byte(x2Lo>>56),
2836
+ byte(x1Hi>>0) >= byte(x2Hi>>0), byte(x1Hi>>8) >= byte(x2Hi>>8),
2837
+ byte(x1Hi>>16) >= byte(x2Hi>>16), byte(x1Hi>>24) >= byte(x2Hi>>24),
2838
+ byte(x1Hi>>32) >= byte(x2Hi>>32), byte(x1Hi>>40) >= byte(x2Hi>>40),
2839
+ byte(x1Hi>>48) >= byte(x2Hi>>48), byte(x1Hi>>56) >= byte(x2Hi>>56),
2840
+ }
2841
+ case v128CmpTypeI16x8Eq:
2842
+ result = []bool{
2843
+ uint16(x1Lo>>0) == uint16(x2Lo>>0), uint16(x1Lo>>16) == uint16(x2Lo>>16),
2844
+ uint16(x1Lo>>32) == uint16(x2Lo>>32), uint16(x1Lo>>48) == uint16(x2Lo>>48),
2845
+ uint16(x1Hi>>0) == uint16(x2Hi>>0), uint16(x1Hi>>16) == uint16(x2Hi>>16),
2846
+ uint16(x1Hi>>32) == uint16(x2Hi>>32), uint16(x1Hi>>48) == uint16(x2Hi>>48),
2847
+ }
2848
+ case v128CmpTypeI16x8Ne:
2849
+ result = []bool{
2850
+ uint16(x1Lo>>0) != uint16(x2Lo>>0), uint16(x1Lo>>16) != uint16(x2Lo>>16),
2851
+ uint16(x1Lo>>32) != uint16(x2Lo>>32), uint16(x1Lo>>48) != uint16(x2Lo>>48),
2852
+ uint16(x1Hi>>0) != uint16(x2Hi>>0), uint16(x1Hi>>16) != uint16(x2Hi>>16),
2853
+ uint16(x1Hi>>32) != uint16(x2Hi>>32), uint16(x1Hi>>48) != uint16(x2Hi>>48),
2854
+ }
2855
+ case v128CmpTypeI16x8LtS:
2856
+ result = []bool{
2857
+ int16(x1Lo>>0) < int16(x2Lo>>0), int16(x1Lo>>16) < int16(x2Lo>>16),
2858
+ int16(x1Lo>>32) < int16(x2Lo>>32), int16(x1Lo>>48) < int16(x2Lo>>48),
2859
+ int16(x1Hi>>0) < int16(x2Hi>>0), int16(x1Hi>>16) < int16(x2Hi>>16),
2860
+ int16(x1Hi>>32) < int16(x2Hi>>32), int16(x1Hi>>48) < int16(x2Hi>>48),
2861
+ }
2862
+ case v128CmpTypeI16x8LtU:
2863
+ result = []bool{
2864
+ uint16(x1Lo>>0) < uint16(x2Lo>>0), uint16(x1Lo>>16) < uint16(x2Lo>>16),
2865
+ uint16(x1Lo>>32) < uint16(x2Lo>>32), uint16(x1Lo>>48) < uint16(x2Lo>>48),
2866
+ uint16(x1Hi>>0) < uint16(x2Hi>>0), uint16(x1Hi>>16) < uint16(x2Hi>>16),
2867
+ uint16(x1Hi>>32) < uint16(x2Hi>>32), uint16(x1Hi>>48) < uint16(x2Hi>>48),
2868
+ }
2869
+ case v128CmpTypeI16x8GtS:
2870
+ result = []bool{
2871
+ int16(x1Lo>>0) > int16(x2Lo>>0), int16(x1Lo>>16) > int16(x2Lo>>16),
2872
+ int16(x1Lo>>32) > int16(x2Lo>>32), int16(x1Lo>>48) > int16(x2Lo>>48),
2873
+ int16(x1Hi>>0) > int16(x2Hi>>0), int16(x1Hi>>16) > int16(x2Hi>>16),
2874
+ int16(x1Hi>>32) > int16(x2Hi>>32), int16(x1Hi>>48) > int16(x2Hi>>48),
2875
+ }
2876
+ case v128CmpTypeI16x8GtU:
2877
+ result = []bool{
2878
+ uint16(x1Lo>>0) > uint16(x2Lo>>0), uint16(x1Lo>>16) > uint16(x2Lo>>16),
2879
+ uint16(x1Lo>>32) > uint16(x2Lo>>32), uint16(x1Lo>>48) > uint16(x2Lo>>48),
2880
+ uint16(x1Hi>>0) > uint16(x2Hi>>0), uint16(x1Hi>>16) > uint16(x2Hi>>16),
2881
+ uint16(x1Hi>>32) > uint16(x2Hi>>32), uint16(x1Hi>>48) > uint16(x2Hi>>48),
2882
+ }
2883
+ case v128CmpTypeI16x8LeS:
2884
+ result = []bool{
2885
+ int16(x1Lo>>0) <= int16(x2Lo>>0), int16(x1Lo>>16) <= int16(x2Lo>>16),
2886
+ int16(x1Lo>>32) <= int16(x2Lo>>32), int16(x1Lo>>48) <= int16(x2Lo>>48),
2887
+ int16(x1Hi>>0) <= int16(x2Hi>>0), int16(x1Hi>>16) <= int16(x2Hi>>16),
2888
+ int16(x1Hi>>32) <= int16(x2Hi>>32), int16(x1Hi>>48) <= int16(x2Hi>>48),
2889
+ }
2890
+ case v128CmpTypeI16x8LeU:
2891
+ result = []bool{
2892
+ uint16(x1Lo>>0) <= uint16(x2Lo>>0), uint16(x1Lo>>16) <= uint16(x2Lo>>16),
2893
+ uint16(x1Lo>>32) <= uint16(x2Lo>>32), uint16(x1Lo>>48) <= uint16(x2Lo>>48),
2894
+ uint16(x1Hi>>0) <= uint16(x2Hi>>0), uint16(x1Hi>>16) <= uint16(x2Hi>>16),
2895
+ uint16(x1Hi>>32) <= uint16(x2Hi>>32), uint16(x1Hi>>48) <= uint16(x2Hi>>48),
2896
+ }
2897
+ case v128CmpTypeI16x8GeS:
2898
+ result = []bool{
2899
+ int16(x1Lo>>0) >= int16(x2Lo>>0), int16(x1Lo>>16) >= int16(x2Lo>>16),
2900
+ int16(x1Lo>>32) >= int16(x2Lo>>32), int16(x1Lo>>48) >= int16(x2Lo>>48),
2901
+ int16(x1Hi>>0) >= int16(x2Hi>>0), int16(x1Hi>>16) >= int16(x2Hi>>16),
2902
+ int16(x1Hi>>32) >= int16(x2Hi>>32), int16(x1Hi>>48) >= int16(x2Hi>>48),
2903
+ }
2904
+ case v128CmpTypeI16x8GeU:
2905
+ result = []bool{
2906
+ uint16(x1Lo>>0) >= uint16(x2Lo>>0), uint16(x1Lo>>16) >= uint16(x2Lo>>16),
2907
+ uint16(x1Lo>>32) >= uint16(x2Lo>>32), uint16(x1Lo>>48) >= uint16(x2Lo>>48),
2908
+ uint16(x1Hi>>0) >= uint16(x2Hi>>0), uint16(x1Hi>>16) >= uint16(x2Hi>>16),
2909
+ uint16(x1Hi>>32) >= uint16(x2Hi>>32), uint16(x1Hi>>48) >= uint16(x2Hi>>48),
2910
+ }
2911
+ case v128CmpTypeI32x4Eq:
2912
+ result = []bool{
2913
+ uint32(x1Lo>>0) == uint32(x2Lo>>0), uint32(x1Lo>>32) == uint32(x2Lo>>32),
2914
+ uint32(x1Hi>>0) == uint32(x2Hi>>0), uint32(x1Hi>>32) == uint32(x2Hi>>32),
2915
+ }
2916
+ case v128CmpTypeI32x4Ne:
2917
+ result = []bool{
2918
+ uint32(x1Lo>>0) != uint32(x2Lo>>0), uint32(x1Lo>>32) != uint32(x2Lo>>32),
2919
+ uint32(x1Hi>>0) != uint32(x2Hi>>0), uint32(x1Hi>>32) != uint32(x2Hi>>32),
2920
+ }
2921
+ case v128CmpTypeI32x4LtS:
2922
+ result = []bool{
2923
+ int32(x1Lo>>0) < int32(x2Lo>>0), int32(x1Lo>>32) < int32(x2Lo>>32),
2924
+ int32(x1Hi>>0) < int32(x2Hi>>0), int32(x1Hi>>32) < int32(x2Hi>>32),
2925
+ }
2926
+ case v128CmpTypeI32x4LtU:
2927
+ result = []bool{
2928
+ uint32(x1Lo>>0) < uint32(x2Lo>>0), uint32(x1Lo>>32) < uint32(x2Lo>>32),
2929
+ uint32(x1Hi>>0) < uint32(x2Hi>>0), uint32(x1Hi>>32) < uint32(x2Hi>>32),
2930
+ }
2931
+ case v128CmpTypeI32x4GtS:
2932
+ result = []bool{
2933
+ int32(x1Lo>>0) > int32(x2Lo>>0), int32(x1Lo>>32) > int32(x2Lo>>32),
2934
+ int32(x1Hi>>0) > int32(x2Hi>>0), int32(x1Hi>>32) > int32(x2Hi>>32),
2935
+ }
2936
+ case v128CmpTypeI32x4GtU:
2937
+ result = []bool{
2938
+ uint32(x1Lo>>0) > uint32(x2Lo>>0), uint32(x1Lo>>32) > uint32(x2Lo>>32),
2939
+ uint32(x1Hi>>0) > uint32(x2Hi>>0), uint32(x1Hi>>32) > uint32(x2Hi>>32),
2940
+ }
2941
+ case v128CmpTypeI32x4LeS:
2942
+ result = []bool{
2943
+ int32(x1Lo>>0) <= int32(x2Lo>>0), int32(x1Lo>>32) <= int32(x2Lo>>32),
2944
+ int32(x1Hi>>0) <= int32(x2Hi>>0), int32(x1Hi>>32) <= int32(x2Hi>>32),
2945
+ }
2946
+ case v128CmpTypeI32x4LeU:
2947
+ result = []bool{
2948
+ uint32(x1Lo>>0) <= uint32(x2Lo>>0), uint32(x1Lo>>32) <= uint32(x2Lo>>32),
2949
+ uint32(x1Hi>>0) <= uint32(x2Hi>>0), uint32(x1Hi>>32) <= uint32(x2Hi>>32),
2950
+ }
2951
+ case v128CmpTypeI32x4GeS:
2952
+ result = []bool{
2953
+ int32(x1Lo>>0) >= int32(x2Lo>>0), int32(x1Lo>>32) >= int32(x2Lo>>32),
2954
+ int32(x1Hi>>0) >= int32(x2Hi>>0), int32(x1Hi>>32) >= int32(x2Hi>>32),
2955
+ }
2956
+ case v128CmpTypeI32x4GeU:
2957
+ result = []bool{
2958
+ uint32(x1Lo>>0) >= uint32(x2Lo>>0), uint32(x1Lo>>32) >= uint32(x2Lo>>32),
2959
+ uint32(x1Hi>>0) >= uint32(x2Hi>>0), uint32(x1Hi>>32) >= uint32(x2Hi>>32),
2960
+ }
2961
+ case v128CmpTypeI64x2Eq:
2962
+ result = []bool{x1Lo == x2Lo, x1Hi == x2Hi}
2963
+ case v128CmpTypeI64x2Ne:
2964
+ result = []bool{x1Lo != x2Lo, x1Hi != x2Hi}
2965
+ case v128CmpTypeI64x2LtS:
2966
+ result = []bool{int64(x1Lo) < int64(x2Lo), int64(x1Hi) < int64(x2Hi)}
2967
+ case v128CmpTypeI64x2GtS:
2968
+ result = []bool{int64(x1Lo) > int64(x2Lo), int64(x1Hi) > int64(x2Hi)}
2969
+ case v128CmpTypeI64x2LeS:
2970
+ result = []bool{int64(x1Lo) <= int64(x2Lo), int64(x1Hi) <= int64(x2Hi)}
2971
+ case v128CmpTypeI64x2GeS:
2972
+ result = []bool{int64(x1Lo) >= int64(x2Lo), int64(x1Hi) >= int64(x2Hi)}
2973
+ case v128CmpTypeF32x4Eq:
2974
+ result = []bool{
2975
+ math.Float32frombits(uint32(x1Lo>>0)) == math.Float32frombits(uint32(x2Lo>>0)),
2976
+ math.Float32frombits(uint32(x1Lo>>32)) == math.Float32frombits(uint32(x2Lo>>32)),
2977
+ math.Float32frombits(uint32(x1Hi>>0)) == math.Float32frombits(uint32(x2Hi>>0)),
2978
+ math.Float32frombits(uint32(x1Hi>>32)) == math.Float32frombits(uint32(x2Hi>>32)),
2979
+ }
2980
+ case v128CmpTypeF32x4Ne:
2981
+ result = []bool{
2982
+ math.Float32frombits(uint32(x1Lo>>0)) != math.Float32frombits(uint32(x2Lo>>0)),
2983
+ math.Float32frombits(uint32(x1Lo>>32)) != math.Float32frombits(uint32(x2Lo>>32)),
2984
+ math.Float32frombits(uint32(x1Hi>>0)) != math.Float32frombits(uint32(x2Hi>>0)),
2985
+ math.Float32frombits(uint32(x1Hi>>32)) != math.Float32frombits(uint32(x2Hi>>32)),
2986
+ }
2987
+ case v128CmpTypeF32x4Lt:
2988
+ result = []bool{
2989
+ math.Float32frombits(uint32(x1Lo>>0)) < math.Float32frombits(uint32(x2Lo>>0)),
2990
+ math.Float32frombits(uint32(x1Lo>>32)) < math.Float32frombits(uint32(x2Lo>>32)),
2991
+ math.Float32frombits(uint32(x1Hi>>0)) < math.Float32frombits(uint32(x2Hi>>0)),
2992
+ math.Float32frombits(uint32(x1Hi>>32)) < math.Float32frombits(uint32(x2Hi>>32)),
2993
+ }
2994
+ case v128CmpTypeF32x4Gt:
2995
+ result = []bool{
2996
+ math.Float32frombits(uint32(x1Lo>>0)) > math.Float32frombits(uint32(x2Lo>>0)),
2997
+ math.Float32frombits(uint32(x1Lo>>32)) > math.Float32frombits(uint32(x2Lo>>32)),
2998
+ math.Float32frombits(uint32(x1Hi>>0)) > math.Float32frombits(uint32(x2Hi>>0)),
2999
+ math.Float32frombits(uint32(x1Hi>>32)) > math.Float32frombits(uint32(x2Hi>>32)),
3000
+ }
3001
+ case v128CmpTypeF32x4Le:
3002
+ result = []bool{
3003
+ math.Float32frombits(uint32(x1Lo>>0)) <= math.Float32frombits(uint32(x2Lo>>0)),
3004
+ math.Float32frombits(uint32(x1Lo>>32)) <= math.Float32frombits(uint32(x2Lo>>32)),
3005
+ math.Float32frombits(uint32(x1Hi>>0)) <= math.Float32frombits(uint32(x2Hi>>0)),
3006
+ math.Float32frombits(uint32(x1Hi>>32)) <= math.Float32frombits(uint32(x2Hi>>32)),
3007
+ }
3008
+ case v128CmpTypeF32x4Ge:
3009
+ result = []bool{
3010
+ math.Float32frombits(uint32(x1Lo>>0)) >= math.Float32frombits(uint32(x2Lo>>0)),
3011
+ math.Float32frombits(uint32(x1Lo>>32)) >= math.Float32frombits(uint32(x2Lo>>32)),
3012
+ math.Float32frombits(uint32(x1Hi>>0)) >= math.Float32frombits(uint32(x2Hi>>0)),
3013
+ math.Float32frombits(uint32(x1Hi>>32)) >= math.Float32frombits(uint32(x2Hi>>32)),
3014
+ }
3015
+ case v128CmpTypeF64x2Eq:
3016
+ result = []bool{
3017
+ math.Float64frombits(x1Lo) == math.Float64frombits(x2Lo),
3018
+ math.Float64frombits(x1Hi) == math.Float64frombits(x2Hi),
3019
+ }
3020
+ case v128CmpTypeF64x2Ne:
3021
+ result = []bool{
3022
+ math.Float64frombits(x1Lo) != math.Float64frombits(x2Lo),
3023
+ math.Float64frombits(x1Hi) != math.Float64frombits(x2Hi),
3024
+ }
3025
+ case v128CmpTypeF64x2Lt:
3026
+ result = []bool{
3027
+ math.Float64frombits(x1Lo) < math.Float64frombits(x2Lo),
3028
+ math.Float64frombits(x1Hi) < math.Float64frombits(x2Hi),
3029
+ }
3030
+ case v128CmpTypeF64x2Gt:
3031
+ result = []bool{
3032
+ math.Float64frombits(x1Lo) > math.Float64frombits(x2Lo),
3033
+ math.Float64frombits(x1Hi) > math.Float64frombits(x2Hi),
3034
+ }
3035
+ case v128CmpTypeF64x2Le:
3036
+ result = []bool{
3037
+ math.Float64frombits(x1Lo) <= math.Float64frombits(x2Lo),
3038
+ math.Float64frombits(x1Hi) <= math.Float64frombits(x2Hi),
3039
+ }
3040
+ case v128CmpTypeF64x2Ge:
3041
+ result = []bool{
3042
+ math.Float64frombits(x1Lo) >= math.Float64frombits(x2Lo),
3043
+ math.Float64frombits(x1Hi) >= math.Float64frombits(x2Hi),
3044
+ }
3045
+ }
3046
+
3047
+ var retLo, retHi uint64
3048
+ laneNum := len(result)
3049
+ switch laneNum {
3050
+ case 16:
3051
+ for i, b := range result {
3052
+ if b {
3053
+ if i < 8 {
3054
+ retLo |= 0xff << (i * 8)
3055
+ } else {
3056
+ retHi |= 0xff << ((i - 8) * 8)
3057
+ }
3058
+ }
3059
+ }
3060
+ case 8:
3061
+ for i, b := range result {
3062
+ if b {
3063
+ if i < 4 {
3064
+ retLo |= 0xffff << (i * 16)
3065
+ } else {
3066
+ retHi |= 0xffff << ((i - 4) * 16)
3067
+ }
3068
+ }
3069
+ }
3070
+ case 4:
3071
+ for i, b := range result {
3072
+ if b {
3073
+ if i < 2 {
3074
+ retLo |= 0xffff_ffff << (i * 32)
3075
+ } else {
3076
+ retHi |= 0xffff_ffff << ((i - 2) * 32)
3077
+ }
3078
+ }
3079
+ }
3080
+ case 2:
3081
+ if result[0] {
3082
+ retLo = ^uint64(0)
3083
+ }
3084
+ if result[1] {
3085
+ retHi = ^uint64(0)
3086
+ }
3087
+ }
3088
+
3089
+ ce.pushValue(retLo)
3090
+ ce.pushValue(retHi)
3091
+ frame.pc++
3092
+ case operationKindV128AddSat:
3093
+ x2hi, x2Lo := ce.popValue(), ce.popValue()
3094
+ x1hi, x1Lo := ce.popValue(), ce.popValue()
3095
+
3096
+ var retLo, retHi uint64
3097
+
3098
+ // Lane-wise addition while saturating the overflowing values.
3099
+ // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#saturating-integer-addition
3100
+ switch op.B1 {
3101
+ case shapeI8x16:
3102
+ for i := 0; i < 16; i++ {
3103
+ var v, w byte
3104
+ if i < 8 {
3105
+ v, w = byte(x1Lo>>(i*8)), byte(x2Lo>>(i*8))
3106
+ } else {
3107
+ v, w = byte(x1hi>>((i-8)*8)), byte(x2hi>>((i-8)*8))
3108
+ }
3109
+
3110
+ var uv uint64
3111
+ if op.B3 { // signed
3112
+ if subbed := int64(int8(v)) + int64(int8(w)); subbed < math.MinInt8 {
3113
+ uv = uint64(byte(0x80))
3114
+ } else if subbed > math.MaxInt8 {
3115
+ uv = uint64(byte(0x7f))
3116
+ } else {
3117
+ uv = uint64(byte(int8(subbed)))
3118
+ }
3119
+ } else {
3120
+ if subbed := int64(v) + int64(w); subbed < 0 {
3121
+ uv = uint64(byte(0))
3122
+ } else if subbed > math.MaxUint8 {
3123
+ uv = uint64(byte(0xff))
3124
+ } else {
3125
+ uv = uint64(byte(subbed))
3126
+ }
3127
+ }
3128
+
3129
+ if i < 8 { // first 8 lanes are on lower 64bits.
3130
+ retLo |= uv << (i * 8)
3131
+ } else {
3132
+ retHi |= uv << ((i - 8) * 8)
3133
+ }
3134
+ }
3135
+ case shapeI16x8:
3136
+ for i := 0; i < 8; i++ {
3137
+ var v, w uint16
3138
+ if i < 4 {
3139
+ v, w = uint16(x1Lo>>(i*16)), uint16(x2Lo>>(i*16))
3140
+ } else {
3141
+ v, w = uint16(x1hi>>((i-4)*16)), uint16(x2hi>>((i-4)*16))
3142
+ }
3143
+
3144
+ var uv uint64
3145
+ if op.B3 { // signed
3146
+ if added := int64(int16(v)) + int64(int16(w)); added < math.MinInt16 {
3147
+ uv = uint64(uint16(0x8000))
3148
+ } else if added > math.MaxInt16 {
3149
+ uv = uint64(uint16(0x7fff))
3150
+ } else {
3151
+ uv = uint64(uint16(int16(added)))
3152
+ }
3153
+ } else {
3154
+ if added := int64(v) + int64(w); added < 0 {
3155
+ uv = uint64(uint16(0))
3156
+ } else if added > math.MaxUint16 {
3157
+ uv = uint64(uint16(0xffff))
3158
+ } else {
3159
+ uv = uint64(uint16(added))
3160
+ }
3161
+ }
3162
+
3163
+ if i < 4 { // first 4 lanes are on lower 64bits.
3164
+ retLo |= uv << (i * 16)
3165
+ } else {
3166
+ retHi |= uv << ((i - 4) * 16)
3167
+ }
3168
+ }
3169
+ }
3170
+
3171
+ ce.pushValue(retLo)
3172
+ ce.pushValue(retHi)
3173
+ frame.pc++
3174
+ case operationKindV128SubSat:
3175
+ x2hi, x2Lo := ce.popValue(), ce.popValue()
3176
+ x1hi, x1Lo := ce.popValue(), ce.popValue()
3177
+
3178
+ var retLo, retHi uint64
3179
+
3180
+ // Lane-wise subtraction while saturating the overflowing values.
3181
+ // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#saturating-integer-subtraction
3182
+ switch op.B1 {
3183
+ case shapeI8x16:
3184
+ for i := 0; i < 16; i++ {
3185
+ var v, w byte
3186
+ if i < 8 {
3187
+ v, w = byte(x1Lo>>(i*8)), byte(x2Lo>>(i*8))
3188
+ } else {
3189
+ v, w = byte(x1hi>>((i-8)*8)), byte(x2hi>>((i-8)*8))
3190
+ }
3191
+
3192
+ var uv uint64
3193
+ if op.B3 { // signed
3194
+ if subbed := int64(int8(v)) - int64(int8(w)); subbed < math.MinInt8 {
3195
+ uv = uint64(byte(0x80))
3196
+ } else if subbed > math.MaxInt8 {
3197
+ uv = uint64(byte(0x7f))
3198
+ } else {
3199
+ uv = uint64(byte(int8(subbed)))
3200
+ }
3201
+ } else {
3202
+ if subbed := int64(v) - int64(w); subbed < 0 {
3203
+ uv = uint64(byte(0))
3204
+ } else if subbed > math.MaxUint8 {
3205
+ uv = uint64(byte(0xff))
3206
+ } else {
3207
+ uv = uint64(byte(subbed))
3208
+ }
3209
+ }
3210
+
3211
+ if i < 8 {
3212
+ retLo |= uv << (i * 8)
3213
+ } else {
3214
+ retHi |= uv << ((i - 8) * 8)
3215
+ }
3216
+ }
3217
+ case shapeI16x8:
3218
+ for i := 0; i < 8; i++ {
3219
+ var v, w uint16
3220
+ if i < 4 {
3221
+ v, w = uint16(x1Lo>>(i*16)), uint16(x2Lo>>(i*16))
3222
+ } else {
3223
+ v, w = uint16(x1hi>>((i-4)*16)), uint16(x2hi>>((i-4)*16))
3224
+ }
3225
+
3226
+ var uv uint64
3227
+ if op.B3 { // signed
3228
+ if subbed := int64(int16(v)) - int64(int16(w)); subbed < math.MinInt16 {
3229
+ uv = uint64(uint16(0x8000))
3230
+ } else if subbed > math.MaxInt16 {
3231
+ uv = uint64(uint16(0x7fff))
3232
+ } else {
3233
+ uv = uint64(uint16(int16(subbed)))
3234
+ }
3235
+ } else {
3236
+ if subbed := int64(v) - int64(w); subbed < 0 {
3237
+ uv = uint64(uint16(0))
3238
+ } else if subbed > math.MaxUint16 {
3239
+ uv = uint64(uint16(0xffff))
3240
+ } else {
3241
+ uv = uint64(uint16(subbed))
3242
+ }
3243
+ }
3244
+
3245
+ if i < 4 {
3246
+ retLo |= uv << (i * 16)
3247
+ } else {
3248
+ retHi |= uv << ((i - 4) * 16)
3249
+ }
3250
+ }
3251
+ }
3252
+
3253
+ ce.pushValue(retLo)
3254
+ ce.pushValue(retHi)
3255
+ frame.pc++
3256
+ case operationKindV128Mul:
3257
+ x2hi, x2lo := ce.popValue(), ce.popValue()
3258
+ x1hi, x1lo := ce.popValue(), ce.popValue()
3259
+ var retLo, retHi uint64
3260
+ switch op.B1 {
3261
+ case shapeI16x8:
3262
+ retHi = uint64(uint16(x1hi)*uint16(x2hi)) | (uint64(uint16(x1hi>>16)*uint16(x2hi>>16)) << 16) |
3263
+ (uint64(uint16(x1hi>>32)*uint16(x2hi>>32)) << 32) | (uint64(uint16(x1hi>>48)*uint16(x2hi>>48)) << 48)
3264
+ retLo = uint64(uint16(x1lo)*uint16(x2lo)) | (uint64(uint16(x1lo>>16)*uint16(x2lo>>16)) << 16) |
3265
+ (uint64(uint16(x1lo>>32)*uint16(x2lo>>32)) << 32) | (uint64(uint16(x1lo>>48)*uint16(x2lo>>48)) << 48)
3266
+ case shapeI32x4:
3267
+ retHi = uint64(uint32(x1hi)*uint32(x2hi)) | (uint64(uint32(x1hi>>32)*uint32(x2hi>>32)) << 32)
3268
+ retLo = uint64(uint32(x1lo)*uint32(x2lo)) | (uint64(uint32(x1lo>>32)*uint32(x2lo>>32)) << 32)
3269
+ case shapeI64x2:
3270
+ retHi = x1hi * x2hi
3271
+ retLo = x1lo * x2lo
3272
+ case shapeF32x4:
3273
+ retHi = mulFloat32bits(uint32(x1hi), uint32(x2hi)) | mulFloat32bits(uint32(x1hi>>32), uint32(x2hi>>32))<<32
3274
+ retLo = mulFloat32bits(uint32(x1lo), uint32(x2lo)) | mulFloat32bits(uint32(x1lo>>32), uint32(x2lo>>32))<<32
3275
+ case shapeF64x2:
3276
+ retHi = math.Float64bits(math.Float64frombits(x1hi) * math.Float64frombits(x2hi))
3277
+ retLo = math.Float64bits(math.Float64frombits(x1lo) * math.Float64frombits(x2lo))
3278
+ }
3279
+ ce.pushValue(retLo)
3280
+ ce.pushValue(retHi)
3281
+ frame.pc++
3282
+ case operationKindV128Div:
3283
+ x2hi, x2lo := ce.popValue(), ce.popValue()
3284
+ x1hi, x1lo := ce.popValue(), ce.popValue()
3285
+ var retLo, retHi uint64
3286
+ if op.B1 == shapeF64x2 {
3287
+ retHi = math.Float64bits(math.Float64frombits(x1hi) / math.Float64frombits(x2hi))
3288
+ retLo = math.Float64bits(math.Float64frombits(x1lo) / math.Float64frombits(x2lo))
3289
+ } else {
3290
+ retHi = divFloat32bits(uint32(x1hi), uint32(x2hi)) | divFloat32bits(uint32(x1hi>>32), uint32(x2hi>>32))<<32
3291
+ retLo = divFloat32bits(uint32(x1lo), uint32(x2lo)) | divFloat32bits(uint32(x1lo>>32), uint32(x2lo>>32))<<32
3292
+ }
3293
+ ce.pushValue(retLo)
3294
+ ce.pushValue(retHi)
3295
+ frame.pc++
3296
+ case operationKindV128Neg:
3297
+ hi, lo := ce.popValue(), ce.popValue()
3298
+ switch op.B1 {
3299
+ case shapeI8x16:
3300
+ lo = uint64(-byte(lo)) | (uint64(-byte(lo>>8)) << 8) |
3301
+ (uint64(-byte(lo>>16)) << 16) | (uint64(-byte(lo>>24)) << 24) |
3302
+ (uint64(-byte(lo>>32)) << 32) | (uint64(-byte(lo>>40)) << 40) |
3303
+ (uint64(-byte(lo>>48)) << 48) | (uint64(-byte(lo>>56)) << 56)
3304
+ hi = uint64(-byte(hi)) | (uint64(-byte(hi>>8)) << 8) |
3305
+ (uint64(-byte(hi>>16)) << 16) | (uint64(-byte(hi>>24)) << 24) |
3306
+ (uint64(-byte(hi>>32)) << 32) | (uint64(-byte(hi>>40)) << 40) |
3307
+ (uint64(-byte(hi>>48)) << 48) | (uint64(-byte(hi>>56)) << 56)
3308
+ case shapeI16x8:
3309
+ hi = uint64(-uint16(hi)) | (uint64(-uint16(hi>>16)) << 16) |
3310
+ (uint64(-uint16(hi>>32)) << 32) | (uint64(-uint16(hi>>48)) << 48)
3311
+ lo = uint64(-uint16(lo)) | (uint64(-uint16(lo>>16)) << 16) |
3312
+ (uint64(-uint16(lo>>32)) << 32) | (uint64(-uint16(lo>>48)) << 48)
3313
+ case shapeI32x4:
3314
+ hi = uint64(-uint32(hi)) | (uint64(-uint32(hi>>32)) << 32)
3315
+ lo = uint64(-uint32(lo)) | (uint64(-uint32(lo>>32)) << 32)
3316
+ case shapeI64x2:
3317
+ hi = -hi
3318
+ lo = -lo
3319
+ case shapeF32x4:
3320
+ hi = uint64(math.Float32bits(-math.Float32frombits(uint32(hi)))) |
3321
+ (uint64(math.Float32bits(-math.Float32frombits(uint32(hi>>32)))) << 32)
3322
+ lo = uint64(math.Float32bits(-math.Float32frombits(uint32(lo)))) |
3323
+ (uint64(math.Float32bits(-math.Float32frombits(uint32(lo>>32)))) << 32)
3324
+ case shapeF64x2:
3325
+ hi = math.Float64bits(-math.Float64frombits(hi))
3326
+ lo = math.Float64bits(-math.Float64frombits(lo))
3327
+ }
3328
+ ce.pushValue(lo)
3329
+ ce.pushValue(hi)
3330
+ frame.pc++
3331
+ case operationKindV128Sqrt:
3332
+ hi, lo := ce.popValue(), ce.popValue()
3333
+ if op.B1 == shapeF64x2 {
3334
+ hi = math.Float64bits(math.Sqrt(math.Float64frombits(hi)))
3335
+ lo = math.Float64bits(math.Sqrt(math.Float64frombits(lo)))
3336
+ } else {
3337
+ hi = uint64(math.Float32bits(float32(math.Sqrt(float64(math.Float32frombits(uint32(hi))))))) |
3338
+ (uint64(math.Float32bits(float32(math.Sqrt(float64(math.Float32frombits(uint32(hi>>32))))))) << 32)
3339
+ lo = uint64(math.Float32bits(float32(math.Sqrt(float64(math.Float32frombits(uint32(lo))))))) |
3340
+ (uint64(math.Float32bits(float32(math.Sqrt(float64(math.Float32frombits(uint32(lo>>32))))))) << 32)
3341
+ }
3342
+ ce.pushValue(lo)
3343
+ ce.pushValue(hi)
3344
+ frame.pc++
3345
+ case operationKindV128Abs:
3346
+ hi, lo := ce.popValue(), ce.popValue()
3347
+ switch op.B1 {
3348
+ case shapeI8x16:
3349
+ lo = uint64(i8Abs(byte(lo))) | (uint64(i8Abs(byte(lo>>8))) << 8) |
3350
+ (uint64(i8Abs(byte(lo>>16))) << 16) | (uint64(i8Abs(byte(lo>>24))) << 24) |
3351
+ (uint64(i8Abs(byte(lo>>32))) << 32) | (uint64(i8Abs(byte(lo>>40))) << 40) |
3352
+ (uint64(i8Abs(byte(lo>>48))) << 48) | (uint64(i8Abs(byte(lo>>56))) << 56)
3353
+ hi = uint64(i8Abs(byte(hi))) | (uint64(i8Abs(byte(hi>>8))) << 8) |
3354
+ (uint64(i8Abs(byte(hi>>16))) << 16) | (uint64(i8Abs(byte(hi>>24))) << 24) |
3355
+ (uint64(i8Abs(byte(hi>>32))) << 32) | (uint64(i8Abs(byte(hi>>40))) << 40) |
3356
+ (uint64(i8Abs(byte(hi>>48))) << 48) | (uint64(i8Abs(byte(hi>>56))) << 56)
3357
+ case shapeI16x8:
3358
+ hi = uint64(i16Abs(uint16(hi))) | (uint64(i16Abs(uint16(hi>>16))) << 16) |
3359
+ (uint64(i16Abs(uint16(hi>>32))) << 32) | (uint64(i16Abs(uint16(hi>>48))) << 48)
3360
+ lo = uint64(i16Abs(uint16(lo))) | (uint64(i16Abs(uint16(lo>>16))) << 16) |
3361
+ (uint64(i16Abs(uint16(lo>>32))) << 32) | (uint64(i16Abs(uint16(lo>>48))) << 48)
3362
+ case shapeI32x4:
3363
+ hi = uint64(i32Abs(uint32(hi))) | (uint64(i32Abs(uint32(hi>>32))) << 32)
3364
+ lo = uint64(i32Abs(uint32(lo))) | (uint64(i32Abs(uint32(lo>>32))) << 32)
3365
+ case shapeI64x2:
3366
+ if int64(hi) < 0 {
3367
+ hi = -hi
3368
+ }
3369
+ if int64(lo) < 0 {
3370
+ lo = -lo
3371
+ }
3372
+ case shapeF32x4:
3373
+ hi = hi &^ (1<<31 | 1<<63)
3374
+ lo = lo &^ (1<<31 | 1<<63)
3375
+ case shapeF64x2:
3376
+ hi = hi &^ (1 << 63)
3377
+ lo = lo &^ (1 << 63)
3378
+ }
3379
+ ce.pushValue(lo)
3380
+ ce.pushValue(hi)
3381
+ frame.pc++
3382
+ case operationKindV128Popcnt:
3383
+ hi, lo := ce.popValue(), ce.popValue()
3384
+ var retLo, retHi uint64
3385
+ for i := 0; i < 16; i++ {
3386
+ var v byte
3387
+ if i < 8 {
3388
+ v = byte(lo >> (i * 8))
3389
+ } else {
3390
+ v = byte(hi >> ((i - 8) * 8))
3391
+ }
3392
+
3393
+ var cnt uint64
3394
+ for i := 0; i < 8; i++ {
3395
+ if (v>>i)&0b1 != 0 {
3396
+ cnt++
3397
+ }
3398
+ }
3399
+
3400
+ if i < 8 {
3401
+ retLo |= cnt << (i * 8)
3402
+ } else {
3403
+ retHi |= cnt << ((i - 8) * 8)
3404
+ }
3405
+ }
3406
+ ce.pushValue(retLo)
3407
+ ce.pushValue(retHi)
3408
+ frame.pc++
3409
+ case operationKindV128Min:
3410
+ x2hi, x2lo := ce.popValue(), ce.popValue()
3411
+ x1hi, x1lo := ce.popValue(), ce.popValue()
3412
+ var retLo, retHi uint64
3413
+ switch op.B1 {
3414
+ case shapeI8x16:
3415
+ if op.B3 { // signed
3416
+ retLo = uint64(i8MinS(uint8(x1lo>>8), uint8(x2lo>>8)))<<8 | uint64(i8MinS(uint8(x1lo), uint8(x2lo))) |
3417
+ uint64(i8MinS(uint8(x1lo>>24), uint8(x2lo>>24)))<<24 | uint64(i8MinS(uint8(x1lo>>16), uint8(x2lo>>16)))<<16 |
3418
+ uint64(i8MinS(uint8(x1lo>>40), uint8(x2lo>>40)))<<40 | uint64(i8MinS(uint8(x1lo>>32), uint8(x2lo>>32)))<<32 |
3419
+ uint64(i8MinS(uint8(x1lo>>56), uint8(x2lo>>56)))<<56 | uint64(i8MinS(uint8(x1lo>>48), uint8(x2lo>>48)))<<48
3420
+ retHi = uint64(i8MinS(uint8(x1hi>>8), uint8(x2hi>>8)))<<8 | uint64(i8MinS(uint8(x1hi), uint8(x2hi))) |
3421
+ uint64(i8MinS(uint8(x1hi>>24), uint8(x2hi>>24)))<<24 | uint64(i8MinS(uint8(x1hi>>16), uint8(x2hi>>16)))<<16 |
3422
+ uint64(i8MinS(uint8(x1hi>>40), uint8(x2hi>>40)))<<40 | uint64(i8MinS(uint8(x1hi>>32), uint8(x2hi>>32)))<<32 |
3423
+ uint64(i8MinS(uint8(x1hi>>56), uint8(x2hi>>56)))<<56 | uint64(i8MinS(uint8(x1hi>>48), uint8(x2hi>>48)))<<48
3424
+ } else {
3425
+ retLo = uint64(i8MinU(uint8(x1lo>>8), uint8(x2lo>>8)))<<8 | uint64(i8MinU(uint8(x1lo), uint8(x2lo))) |
3426
+ uint64(i8MinU(uint8(x1lo>>24), uint8(x2lo>>24)))<<24 | uint64(i8MinU(uint8(x1lo>>16), uint8(x2lo>>16)))<<16 |
3427
+ uint64(i8MinU(uint8(x1lo>>40), uint8(x2lo>>40)))<<40 | uint64(i8MinU(uint8(x1lo>>32), uint8(x2lo>>32)))<<32 |
3428
+ uint64(i8MinU(uint8(x1lo>>56), uint8(x2lo>>56)))<<56 | uint64(i8MinU(uint8(x1lo>>48), uint8(x2lo>>48)))<<48
3429
+ retHi = uint64(i8MinU(uint8(x1hi>>8), uint8(x2hi>>8)))<<8 | uint64(i8MinU(uint8(x1hi), uint8(x2hi))) |
3430
+ uint64(i8MinU(uint8(x1hi>>24), uint8(x2hi>>24)))<<24 | uint64(i8MinU(uint8(x1hi>>16), uint8(x2hi>>16)))<<16 |
3431
+ uint64(i8MinU(uint8(x1hi>>40), uint8(x2hi>>40)))<<40 | uint64(i8MinU(uint8(x1hi>>32), uint8(x2hi>>32)))<<32 |
3432
+ uint64(i8MinU(uint8(x1hi>>56), uint8(x2hi>>56)))<<56 | uint64(i8MinU(uint8(x1hi>>48), uint8(x2hi>>48)))<<48
3433
+ }
3434
+ case shapeI16x8:
3435
+ if op.B3 { // signed
3436
+ retLo = uint64(i16MinS(uint16(x1lo), uint16(x2lo))) |
3437
+ uint64(i16MinS(uint16(x1lo>>16), uint16(x2lo>>16)))<<16 |
3438
+ uint64(i16MinS(uint16(x1lo>>32), uint16(x2lo>>32)))<<32 |
3439
+ uint64(i16MinS(uint16(x1lo>>48), uint16(x2lo>>48)))<<48
3440
+ retHi = uint64(i16MinS(uint16(x1hi), uint16(x2hi))) |
3441
+ uint64(i16MinS(uint16(x1hi>>16), uint16(x2hi>>16)))<<16 |
3442
+ uint64(i16MinS(uint16(x1hi>>32), uint16(x2hi>>32)))<<32 |
3443
+ uint64(i16MinS(uint16(x1hi>>48), uint16(x2hi>>48)))<<48
3444
+ } else {
3445
+ retLo = uint64(i16MinU(uint16(x1lo), uint16(x2lo))) |
3446
+ uint64(i16MinU(uint16(x1lo>>16), uint16(x2lo>>16)))<<16 |
3447
+ uint64(i16MinU(uint16(x1lo>>32), uint16(x2lo>>32)))<<32 |
3448
+ uint64(i16MinU(uint16(x1lo>>48), uint16(x2lo>>48)))<<48
3449
+ retHi = uint64(i16MinU(uint16(x1hi), uint16(x2hi))) |
3450
+ uint64(i16MinU(uint16(x1hi>>16), uint16(x2hi>>16)))<<16 |
3451
+ uint64(i16MinU(uint16(x1hi>>32), uint16(x2hi>>32)))<<32 |
3452
+ uint64(i16MinU(uint16(x1hi>>48), uint16(x2hi>>48)))<<48
3453
+ }
3454
+ case shapeI32x4:
3455
+ if op.B3 { // signed
3456
+ retLo = uint64(i32MinS(uint32(x1lo), uint32(x2lo))) |
3457
+ uint64(i32MinS(uint32(x1lo>>32), uint32(x2lo>>32)))<<32
3458
+ retHi = uint64(i32MinS(uint32(x1hi), uint32(x2hi))) |
3459
+ uint64(i32MinS(uint32(x1hi>>32), uint32(x2hi>>32)))<<32
3460
+ } else {
3461
+ retLo = uint64(i32MinU(uint32(x1lo), uint32(x2lo))) |
3462
+ uint64(i32MinU(uint32(x1lo>>32), uint32(x2lo>>32)))<<32
3463
+ retHi = uint64(i32MinU(uint32(x1hi), uint32(x2hi))) |
3464
+ uint64(i32MinU(uint32(x1hi>>32), uint32(x2hi>>32)))<<32
3465
+ }
3466
+ case shapeF32x4:
3467
+ retHi = wasmCompatMin32bits(uint32(x1hi), uint32(x2hi)) |
3468
+ wasmCompatMin32bits(uint32(x1hi>>32), uint32(x2hi>>32))<<32
3469
+ retLo = wasmCompatMin32bits(uint32(x1lo), uint32(x2lo)) |
3470
+ wasmCompatMin32bits(uint32(x1lo>>32), uint32(x2lo>>32))<<32
3471
+ case shapeF64x2:
3472
+ retHi = math.Float64bits(moremath.WasmCompatMin64(
3473
+ math.Float64frombits(x1hi),
3474
+ math.Float64frombits(x2hi),
3475
+ ))
3476
+ retLo = math.Float64bits(moremath.WasmCompatMin64(
3477
+ math.Float64frombits(x1lo),
3478
+ math.Float64frombits(x2lo),
3479
+ ))
3480
+ }
3481
+ ce.pushValue(retLo)
3482
+ ce.pushValue(retHi)
3483
+ frame.pc++
3484
+ case operationKindV128Max:
3485
+ x2hi, x2lo := ce.popValue(), ce.popValue()
3486
+ x1hi, x1lo := ce.popValue(), ce.popValue()
3487
+ var retLo, retHi uint64
3488
+ switch op.B1 {
3489
+ case shapeI8x16:
3490
+ if op.B3 { // signed
3491
+ retLo = uint64(i8MaxS(uint8(x1lo>>8), uint8(x2lo>>8)))<<8 | uint64(i8MaxS(uint8(x1lo), uint8(x2lo))) |
3492
+ uint64(i8MaxS(uint8(x1lo>>24), uint8(x2lo>>24)))<<24 | uint64(i8MaxS(uint8(x1lo>>16), uint8(x2lo>>16)))<<16 |
3493
+ uint64(i8MaxS(uint8(x1lo>>40), uint8(x2lo>>40)))<<40 | uint64(i8MaxS(uint8(x1lo>>32), uint8(x2lo>>32)))<<32 |
3494
+ uint64(i8MaxS(uint8(x1lo>>56), uint8(x2lo>>56)))<<56 | uint64(i8MaxS(uint8(x1lo>>48), uint8(x2lo>>48)))<<48
3495
+ retHi = uint64(i8MaxS(uint8(x1hi>>8), uint8(x2hi>>8)))<<8 | uint64(i8MaxS(uint8(x1hi), uint8(x2hi))) |
3496
+ uint64(i8MaxS(uint8(x1hi>>24), uint8(x2hi>>24)))<<24 | uint64(i8MaxS(uint8(x1hi>>16), uint8(x2hi>>16)))<<16 |
3497
+ uint64(i8MaxS(uint8(x1hi>>40), uint8(x2hi>>40)))<<40 | uint64(i8MaxS(uint8(x1hi>>32), uint8(x2hi>>32)))<<32 |
3498
+ uint64(i8MaxS(uint8(x1hi>>56), uint8(x2hi>>56)))<<56 | uint64(i8MaxS(uint8(x1hi>>48), uint8(x2hi>>48)))<<48
3499
+ } else {
3500
+ retLo = uint64(i8MaxU(uint8(x1lo>>8), uint8(x2lo>>8)))<<8 | uint64(i8MaxU(uint8(x1lo), uint8(x2lo))) |
3501
+ uint64(i8MaxU(uint8(x1lo>>24), uint8(x2lo>>24)))<<24 | uint64(i8MaxU(uint8(x1lo>>16), uint8(x2lo>>16)))<<16 |
3502
+ uint64(i8MaxU(uint8(x1lo>>40), uint8(x2lo>>40)))<<40 | uint64(i8MaxU(uint8(x1lo>>32), uint8(x2lo>>32)))<<32 |
3503
+ uint64(i8MaxU(uint8(x1lo>>56), uint8(x2lo>>56)))<<56 | uint64(i8MaxU(uint8(x1lo>>48), uint8(x2lo>>48)))<<48
3504
+ retHi = uint64(i8MaxU(uint8(x1hi>>8), uint8(x2hi>>8)))<<8 | uint64(i8MaxU(uint8(x1hi), uint8(x2hi))) |
3505
+ uint64(i8MaxU(uint8(x1hi>>24), uint8(x2hi>>24)))<<24 | uint64(i8MaxU(uint8(x1hi>>16), uint8(x2hi>>16)))<<16 |
3506
+ uint64(i8MaxU(uint8(x1hi>>40), uint8(x2hi>>40)))<<40 | uint64(i8MaxU(uint8(x1hi>>32), uint8(x2hi>>32)))<<32 |
3507
+ uint64(i8MaxU(uint8(x1hi>>56), uint8(x2hi>>56)))<<56 | uint64(i8MaxU(uint8(x1hi>>48), uint8(x2hi>>48)))<<48
3508
+ }
3509
+ case shapeI16x8:
3510
+ if op.B3 { // signed
3511
+ retLo = uint64(i16MaxS(uint16(x1lo), uint16(x2lo))) |
3512
+ uint64(i16MaxS(uint16(x1lo>>16), uint16(x2lo>>16)))<<16 |
3513
+ uint64(i16MaxS(uint16(x1lo>>32), uint16(x2lo>>32)))<<32 |
3514
+ uint64(i16MaxS(uint16(x1lo>>48), uint16(x2lo>>48)))<<48
3515
+ retHi = uint64(i16MaxS(uint16(x1hi), uint16(x2hi))) |
3516
+ uint64(i16MaxS(uint16(x1hi>>16), uint16(x2hi>>16)))<<16 |
3517
+ uint64(i16MaxS(uint16(x1hi>>32), uint16(x2hi>>32)))<<32 |
3518
+ uint64(i16MaxS(uint16(x1hi>>48), uint16(x2hi>>48)))<<48
3519
+ } else {
3520
+ retLo = uint64(i16MaxU(uint16(x1lo), uint16(x2lo))) |
3521
+ uint64(i16MaxU(uint16(x1lo>>16), uint16(x2lo>>16)))<<16 |
3522
+ uint64(i16MaxU(uint16(x1lo>>32), uint16(x2lo>>32)))<<32 |
3523
+ uint64(i16MaxU(uint16(x1lo>>48), uint16(x2lo>>48)))<<48
3524
+ retHi = uint64(i16MaxU(uint16(x1hi), uint16(x2hi))) |
3525
+ uint64(i16MaxU(uint16(x1hi>>16), uint16(x2hi>>16)))<<16 |
3526
+ uint64(i16MaxU(uint16(x1hi>>32), uint16(x2hi>>32)))<<32 |
3527
+ uint64(i16MaxU(uint16(x1hi>>48), uint16(x2hi>>48)))<<48
3528
+ }
3529
+ case shapeI32x4:
3530
+ if op.B3 { // signed
3531
+ retLo = uint64(i32MaxS(uint32(x1lo), uint32(x2lo))) |
3532
+ uint64(i32MaxS(uint32(x1lo>>32), uint32(x2lo>>32)))<<32
3533
+ retHi = uint64(i32MaxS(uint32(x1hi), uint32(x2hi))) |
3534
+ uint64(i32MaxS(uint32(x1hi>>32), uint32(x2hi>>32)))<<32
3535
+ } else {
3536
+ retLo = uint64(i32MaxU(uint32(x1lo), uint32(x2lo))) |
3537
+ uint64(i32MaxU(uint32(x1lo>>32), uint32(x2lo>>32)))<<32
3538
+ retHi = uint64(i32MaxU(uint32(x1hi), uint32(x2hi))) |
3539
+ uint64(i32MaxU(uint32(x1hi>>32), uint32(x2hi>>32)))<<32
3540
+ }
3541
+ case shapeF32x4:
3542
+ retHi = wasmCompatMax32bits(uint32(x1hi), uint32(x2hi)) |
3543
+ wasmCompatMax32bits(uint32(x1hi>>32), uint32(x2hi>>32))<<32
3544
+ retLo = wasmCompatMax32bits(uint32(x1lo), uint32(x2lo)) |
3545
+ wasmCompatMax32bits(uint32(x1lo>>32), uint32(x2lo>>32))<<32
3546
+ case shapeF64x2:
3547
+ retHi = math.Float64bits(moremath.WasmCompatMax64(
3548
+ math.Float64frombits(x1hi),
3549
+ math.Float64frombits(x2hi),
3550
+ ))
3551
+ retLo = math.Float64bits(moremath.WasmCompatMax64(
3552
+ math.Float64frombits(x1lo),
3553
+ math.Float64frombits(x2lo),
3554
+ ))
3555
+ }
3556
+ ce.pushValue(retLo)
3557
+ ce.pushValue(retHi)
3558
+ frame.pc++
3559
+ case operationKindV128AvgrU:
3560
+ x2hi, x2lo := ce.popValue(), ce.popValue()
3561
+ x1hi, x1lo := ce.popValue(), ce.popValue()
3562
+ var retLo, retHi uint64
3563
+ switch op.B1 {
3564
+ case shapeI8x16:
3565
+ retLo = uint64(i8RoundingAverage(uint8(x1lo>>8), uint8(x2lo>>8)))<<8 | uint64(i8RoundingAverage(uint8(x1lo), uint8(x2lo))) |
3566
+ uint64(i8RoundingAverage(uint8(x1lo>>24), uint8(x2lo>>24)))<<24 | uint64(i8RoundingAverage(uint8(x1lo>>16), uint8(x2lo>>16)))<<16 |
3567
+ uint64(i8RoundingAverage(uint8(x1lo>>40), uint8(x2lo>>40)))<<40 | uint64(i8RoundingAverage(uint8(x1lo>>32), uint8(x2lo>>32)))<<32 |
3568
+ uint64(i8RoundingAverage(uint8(x1lo>>56), uint8(x2lo>>56)))<<56 | uint64(i8RoundingAverage(uint8(x1lo>>48), uint8(x2lo>>48)))<<48
3569
+ retHi = uint64(i8RoundingAverage(uint8(x1hi>>8), uint8(x2hi>>8)))<<8 | uint64(i8RoundingAverage(uint8(x1hi), uint8(x2hi))) |
3570
+ uint64(i8RoundingAverage(uint8(x1hi>>24), uint8(x2hi>>24)))<<24 | uint64(i8RoundingAverage(uint8(x1hi>>16), uint8(x2hi>>16)))<<16 |
3571
+ uint64(i8RoundingAverage(uint8(x1hi>>40), uint8(x2hi>>40)))<<40 | uint64(i8RoundingAverage(uint8(x1hi>>32), uint8(x2hi>>32)))<<32 |
3572
+ uint64(i8RoundingAverage(uint8(x1hi>>56), uint8(x2hi>>56)))<<56 | uint64(i8RoundingAverage(uint8(x1hi>>48), uint8(x2hi>>48)))<<48
3573
+ case shapeI16x8:
3574
+ retLo = uint64(i16RoundingAverage(uint16(x1lo), uint16(x2lo))) |
3575
+ uint64(i16RoundingAverage(uint16(x1lo>>16), uint16(x2lo>>16)))<<16 |
3576
+ uint64(i16RoundingAverage(uint16(x1lo>>32), uint16(x2lo>>32)))<<32 |
3577
+ uint64(i16RoundingAverage(uint16(x1lo>>48), uint16(x2lo>>48)))<<48
3578
+ retHi = uint64(i16RoundingAverage(uint16(x1hi), uint16(x2hi))) |
3579
+ uint64(i16RoundingAverage(uint16(x1hi>>16), uint16(x2hi>>16)))<<16 |
3580
+ uint64(i16RoundingAverage(uint16(x1hi>>32), uint16(x2hi>>32)))<<32 |
3581
+ uint64(i16RoundingAverage(uint16(x1hi>>48), uint16(x2hi>>48)))<<48
3582
+ }
3583
+ ce.pushValue(retLo)
3584
+ ce.pushValue(retHi)
3585
+ frame.pc++
3586
+ case operationKindV128Pmin:
3587
+ x2hi, x2lo := ce.popValue(), ce.popValue()
3588
+ x1hi, x1lo := ce.popValue(), ce.popValue()
3589
+ var retLo, retHi uint64
3590
+ if op.B1 == shapeF32x4 {
3591
+ if flt32(math.Float32frombits(uint32(x2lo)), math.Float32frombits(uint32(x1lo))) {
3592
+ retLo = x2lo & 0x00000000_ffffffff
3593
+ } else {
3594
+ retLo = x1lo & 0x00000000_ffffffff
3595
+ }
3596
+ if flt32(math.Float32frombits(uint32(x2lo>>32)), math.Float32frombits(uint32(x1lo>>32))) {
3597
+ retLo |= x2lo & 0xffffffff_00000000
3598
+ } else {
3599
+ retLo |= x1lo & 0xffffffff_00000000
3600
+ }
3601
+ if flt32(math.Float32frombits(uint32(x2hi)), math.Float32frombits(uint32(x1hi))) {
3602
+ retHi = x2hi & 0x00000000_ffffffff
3603
+ } else {
3604
+ retHi = x1hi & 0x00000000_ffffffff
3605
+ }
3606
+ if flt32(math.Float32frombits(uint32(x2hi>>32)), math.Float32frombits(uint32(x1hi>>32))) {
3607
+ retHi |= x2hi & 0xffffffff_00000000
3608
+ } else {
3609
+ retHi |= x1hi & 0xffffffff_00000000
3610
+ }
3611
+ } else {
3612
+ if flt64(math.Float64frombits(x2lo), math.Float64frombits(x1lo)) {
3613
+ retLo = x2lo
3614
+ } else {
3615
+ retLo = x1lo
3616
+ }
3617
+ if flt64(math.Float64frombits(x2hi), math.Float64frombits(x1hi)) {
3618
+ retHi = x2hi
3619
+ } else {
3620
+ retHi = x1hi
3621
+ }
3622
+ }
3623
+ ce.pushValue(retLo)
3624
+ ce.pushValue(retHi)
3625
+ frame.pc++
3626
+ case operationKindV128Pmax:
3627
+ x2hi, x2lo := ce.popValue(), ce.popValue()
3628
+ x1hi, x1lo := ce.popValue(), ce.popValue()
3629
+ var retLo, retHi uint64
3630
+ if op.B1 == shapeF32x4 {
3631
+ if flt32(math.Float32frombits(uint32(x1lo)), math.Float32frombits(uint32(x2lo))) {
3632
+ retLo = x2lo & 0x00000000_ffffffff
3633
+ } else {
3634
+ retLo = x1lo & 0x00000000_ffffffff
3635
+ }
3636
+ if flt32(math.Float32frombits(uint32(x1lo>>32)), math.Float32frombits(uint32(x2lo>>32))) {
3637
+ retLo |= x2lo & 0xffffffff_00000000
3638
+ } else {
3639
+ retLo |= x1lo & 0xffffffff_00000000
3640
+ }
3641
+ if flt32(math.Float32frombits(uint32(x1hi)), math.Float32frombits(uint32(x2hi))) {
3642
+ retHi = x2hi & 0x00000000_ffffffff
3643
+ } else {
3644
+ retHi = x1hi & 0x00000000_ffffffff
3645
+ }
3646
+ if flt32(math.Float32frombits(uint32(x1hi>>32)), math.Float32frombits(uint32(x2hi>>32))) {
3647
+ retHi |= x2hi & 0xffffffff_00000000
3648
+ } else {
3649
+ retHi |= x1hi & 0xffffffff_00000000
3650
+ }
3651
+ } else {
3652
+ if flt64(math.Float64frombits(x1lo), math.Float64frombits(x2lo)) {
3653
+ retLo = x2lo
3654
+ } else {
3655
+ retLo = x1lo
3656
+ }
3657
+ if flt64(math.Float64frombits(x1hi), math.Float64frombits(x2hi)) {
3658
+ retHi = x2hi
3659
+ } else {
3660
+ retHi = x1hi
3661
+ }
3662
+ }
3663
+ ce.pushValue(retLo)
3664
+ ce.pushValue(retHi)
3665
+ frame.pc++
3666
+ case operationKindV128Ceil:
3667
+ hi, lo := ce.popValue(), ce.popValue()
3668
+ if op.B1 == shapeF32x4 {
3669
+ lo = uint64(math.Float32bits(moremath.WasmCompatCeilF32(math.Float32frombits(uint32(lo))))) |
3670
+ (uint64(math.Float32bits(moremath.WasmCompatCeilF32(math.Float32frombits(uint32(lo>>32))))) << 32)
3671
+ hi = uint64(math.Float32bits(moremath.WasmCompatCeilF32(math.Float32frombits(uint32(hi))))) |
3672
+ (uint64(math.Float32bits(moremath.WasmCompatCeilF32(math.Float32frombits(uint32(hi>>32))))) << 32)
3673
+ } else {
3674
+ lo = math.Float64bits(moremath.WasmCompatCeilF64(math.Float64frombits(lo)))
3675
+ hi = math.Float64bits(moremath.WasmCompatCeilF64(math.Float64frombits(hi)))
3676
+ }
3677
+ ce.pushValue(lo)
3678
+ ce.pushValue(hi)
3679
+ frame.pc++
3680
+ case operationKindV128Floor:
3681
+ hi, lo := ce.popValue(), ce.popValue()
3682
+ if op.B1 == shapeF32x4 {
3683
+ lo = uint64(math.Float32bits(moremath.WasmCompatFloorF32(math.Float32frombits(uint32(lo))))) |
3684
+ (uint64(math.Float32bits(moremath.WasmCompatFloorF32(math.Float32frombits(uint32(lo>>32))))) << 32)
3685
+ hi = uint64(math.Float32bits(moremath.WasmCompatFloorF32(math.Float32frombits(uint32(hi))))) |
3686
+ (uint64(math.Float32bits(moremath.WasmCompatFloorF32(math.Float32frombits(uint32(hi>>32))))) << 32)
3687
+ } else {
3688
+ lo = math.Float64bits(moremath.WasmCompatFloorF64(math.Float64frombits(lo)))
3689
+ hi = math.Float64bits(moremath.WasmCompatFloorF64(math.Float64frombits(hi)))
3690
+ }
3691
+ ce.pushValue(lo)
3692
+ ce.pushValue(hi)
3693
+ frame.pc++
3694
+ case operationKindV128Trunc:
3695
+ hi, lo := ce.popValue(), ce.popValue()
3696
+ if op.B1 == shapeF32x4 {
3697
+ lo = uint64(math.Float32bits(moremath.WasmCompatTruncF32(math.Float32frombits(uint32(lo))))) |
3698
+ (uint64(math.Float32bits(moremath.WasmCompatTruncF32(math.Float32frombits(uint32(lo>>32))))) << 32)
3699
+ hi = uint64(math.Float32bits(moremath.WasmCompatTruncF32(math.Float32frombits(uint32(hi))))) |
3700
+ (uint64(math.Float32bits(moremath.WasmCompatTruncF32(math.Float32frombits(uint32(hi>>32))))) << 32)
3701
+ } else {
3702
+ lo = math.Float64bits(moremath.WasmCompatTruncF64(math.Float64frombits(lo)))
3703
+ hi = math.Float64bits(moremath.WasmCompatTruncF64(math.Float64frombits(hi)))
3704
+ }
3705
+ ce.pushValue(lo)
3706
+ ce.pushValue(hi)
3707
+ frame.pc++
3708
+ case operationKindV128Nearest:
3709
+ hi, lo := ce.popValue(), ce.popValue()
3710
+ if op.B1 == shapeF32x4 {
3711
+ lo = uint64(math.Float32bits(moremath.WasmCompatNearestF32(math.Float32frombits(uint32(lo))))) |
3712
+ (uint64(math.Float32bits(moremath.WasmCompatNearestF32(math.Float32frombits(uint32(lo>>32))))) << 32)
3713
+ hi = uint64(math.Float32bits(moremath.WasmCompatNearestF32(math.Float32frombits(uint32(hi))))) |
3714
+ (uint64(math.Float32bits(moremath.WasmCompatNearestF32(math.Float32frombits(uint32(hi>>32))))) << 32)
3715
+ } else {
3716
+ lo = math.Float64bits(moremath.WasmCompatNearestF64(math.Float64frombits(lo)))
3717
+ hi = math.Float64bits(moremath.WasmCompatNearestF64(math.Float64frombits(hi)))
3718
+ }
3719
+ ce.pushValue(lo)
3720
+ ce.pushValue(hi)
3721
+ frame.pc++
3722
+ case operationKindV128Extend:
3723
+ hi, lo := ce.popValue(), ce.popValue()
3724
+ var origin uint64
3725
+ if op.B3 { // use lower 64 bits
3726
+ origin = lo
3727
+ } else {
3728
+ origin = hi
3729
+ }
3730
+
3731
+ signed := op.B2 == 1
3732
+
3733
+ var retHi, retLo uint64
3734
+ switch op.B1 {
3735
+ case shapeI8x16:
3736
+ for i := 0; i < 8; i++ {
3737
+ v8 := byte(origin >> (i * 8))
3738
+
3739
+ var v16 uint16
3740
+ if signed {
3741
+ v16 = uint16(int8(v8))
3742
+ } else {
3743
+ v16 = uint16(v8)
3744
+ }
3745
+
3746
+ if i < 4 {
3747
+ retLo |= uint64(v16) << (i * 16)
3748
+ } else {
3749
+ retHi |= uint64(v16) << ((i - 4) * 16)
3750
+ }
3751
+ }
3752
+ case shapeI16x8:
3753
+ for i := 0; i < 4; i++ {
3754
+ v16 := uint16(origin >> (i * 16))
3755
+
3756
+ var v32 uint32
3757
+ if signed {
3758
+ v32 = uint32(int16(v16))
3759
+ } else {
3760
+ v32 = uint32(v16)
3761
+ }
3762
+
3763
+ if i < 2 {
3764
+ retLo |= uint64(v32) << (i * 32)
3765
+ } else {
3766
+ retHi |= uint64(v32) << ((i - 2) * 32)
3767
+ }
3768
+ }
3769
+ case shapeI32x4:
3770
+ v32Lo := uint32(origin)
3771
+ v32Hi := uint32(origin >> 32)
3772
+ if signed {
3773
+ retLo = uint64(int32(v32Lo))
3774
+ retHi = uint64(int32(v32Hi))
3775
+ } else {
3776
+ retLo = uint64(v32Lo)
3777
+ retHi = uint64(v32Hi)
3778
+ }
3779
+ }
3780
+ ce.pushValue(retLo)
3781
+ ce.pushValue(retHi)
3782
+ frame.pc++
3783
+ case operationKindV128ExtMul:
3784
+ x2Hi, x2Lo := ce.popValue(), ce.popValue()
3785
+ x1Hi, x1Lo := ce.popValue(), ce.popValue()
3786
+ var x1, x2 uint64
3787
+ if op.B3 { // use lower 64 bits
3788
+ x1, x2 = x1Lo, x2Lo
3789
+ } else {
3790
+ x1, x2 = x1Hi, x2Hi
3791
+ }
3792
+
3793
+ signed := op.B2 == 1
3794
+
3795
+ var retLo, retHi uint64
3796
+ switch op.B1 {
3797
+ case shapeI8x16:
3798
+ for i := 0; i < 8; i++ {
3799
+ v1, v2 := byte(x1>>(i*8)), byte(x2>>(i*8))
3800
+
3801
+ var v16 uint16
3802
+ if signed {
3803
+ v16 = uint16(int16(int8(v1)) * int16(int8(v2)))
3804
+ } else {
3805
+ v16 = uint16(v1) * uint16(v2)
3806
+ }
3807
+
3808
+ if i < 4 {
3809
+ retLo |= uint64(v16) << (i * 16)
3810
+ } else {
3811
+ retHi |= uint64(v16) << ((i - 4) * 16)
3812
+ }
3813
+ }
3814
+ case shapeI16x8:
3815
+ for i := 0; i < 4; i++ {
3816
+ v1, v2 := uint16(x1>>(i*16)), uint16(x2>>(i*16))
3817
+
3818
+ var v32 uint32
3819
+ if signed {
3820
+ v32 = uint32(int32(int16(v1)) * int32(int16(v2)))
3821
+ } else {
3822
+ v32 = uint32(v1) * uint32(v2)
3823
+ }
3824
+
3825
+ if i < 2 {
3826
+ retLo |= uint64(v32) << (i * 32)
3827
+ } else {
3828
+ retHi |= uint64(v32) << ((i - 2) * 32)
3829
+ }
3830
+ }
3831
+ case shapeI32x4:
3832
+ v1Lo, v2Lo := uint32(x1), uint32(x2)
3833
+ v1Hi, v2Hi := uint32(x1>>32), uint32(x2>>32)
3834
+ if signed {
3835
+ retLo = uint64(int64(int32(v1Lo)) * int64(int32(v2Lo)))
3836
+ retHi = uint64(int64(int32(v1Hi)) * int64(int32(v2Hi)))
3837
+ } else {
3838
+ retLo = uint64(v1Lo) * uint64(v2Lo)
3839
+ retHi = uint64(v1Hi) * uint64(v2Hi)
3840
+ }
3841
+ }
3842
+
3843
+ ce.pushValue(retLo)
3844
+ ce.pushValue(retHi)
3845
+ frame.pc++
3846
+ case operationKindV128Q15mulrSatS:
3847
+ x2hi, x2Lo := ce.popValue(), ce.popValue()
3848
+ x1hi, x1Lo := ce.popValue(), ce.popValue()
3849
+ var retLo, retHi uint64
3850
+ for i := 0; i < 8; i++ {
3851
+ var v, w int16
3852
+ if i < 4 {
3853
+ v, w = int16(uint16(x1Lo>>(i*16))), int16(uint16(x2Lo>>(i*16)))
3854
+ } else {
3855
+ v, w = int16(uint16(x1hi>>((i-4)*16))), int16(uint16(x2hi>>((i-4)*16)))
3856
+ }
3857
+
3858
+ var uv uint64
3859
+ // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#saturating-integer-q-format-rounding-multiplication
3860
+ if calc := ((int32(v) * int32(w)) + 0x4000) >> 15; calc < math.MinInt16 {
3861
+ uv = uint64(uint16(0x8000))
3862
+ } else if calc > math.MaxInt16 {
3863
+ uv = uint64(uint16(0x7fff))
3864
+ } else {
3865
+ uv = uint64(uint16(int16(calc)))
3866
+ }
3867
+
3868
+ if i < 4 {
3869
+ retLo |= uv << (i * 16)
3870
+ } else {
3871
+ retHi |= uv << ((i - 4) * 16)
3872
+ }
3873
+ }
3874
+
3875
+ ce.pushValue(retLo)
3876
+ ce.pushValue(retHi)
3877
+ frame.pc++
3878
+ case operationKindV128ExtAddPairwise:
3879
+ hi, lo := ce.popValue(), ce.popValue()
3880
+
3881
+ signed := op.B3
3882
+
3883
+ var retLo, retHi uint64
3884
+ switch op.B1 {
3885
+ case shapeI8x16:
3886
+ for i := 0; i < 8; i++ {
3887
+ var v1, v2 byte
3888
+ if i < 4 {
3889
+ v1, v2 = byte(lo>>((i*2)*8)), byte(lo>>((i*2+1)*8))
3890
+ } else {
3891
+ v1, v2 = byte(hi>>(((i-4)*2)*8)), byte(hi>>(((i-4)*2+1)*8))
3892
+ }
3893
+
3894
+ var v16 uint16
3895
+ if signed {
3896
+ v16 = uint16(int16(int8(v1)) + int16(int8(v2)))
3897
+ } else {
3898
+ v16 = uint16(v1) + uint16(v2)
3899
+ }
3900
+
3901
+ if i < 4 {
3902
+ retLo |= uint64(v16) << (i * 16)
3903
+ } else {
3904
+ retHi |= uint64(v16) << ((i - 4) * 16)
3905
+ }
3906
+ }
3907
+ case shapeI16x8:
3908
+ for i := 0; i < 4; i++ {
3909
+ var v1, v2 uint16
3910
+ if i < 2 {
3911
+ v1, v2 = uint16(lo>>((i*2)*16)), uint16(lo>>((i*2+1)*16))
3912
+ } else {
3913
+ v1, v2 = uint16(hi>>(((i-2)*2)*16)), uint16(hi>>(((i-2)*2+1)*16))
3914
+ }
3915
+
3916
+ var v32 uint32
3917
+ if signed {
3918
+ v32 = uint32(int32(int16(v1)) + int32(int16(v2)))
3919
+ } else {
3920
+ v32 = uint32(v1) + uint32(v2)
3921
+ }
3922
+
3923
+ if i < 2 {
3924
+ retLo |= uint64(v32) << (i * 32)
3925
+ } else {
3926
+ retHi |= uint64(v32) << ((i - 2) * 32)
3927
+ }
3928
+ }
3929
+ }
3930
+ ce.pushValue(retLo)
3931
+ ce.pushValue(retHi)
3932
+ frame.pc++
3933
+ case operationKindV128FloatPromote:
3934
+ _, toPromote := ce.popValue(), ce.popValue()
3935
+ ce.pushValue(math.Float64bits(float64(math.Float32frombits(uint32(toPromote)))))
3936
+ ce.pushValue(math.Float64bits(float64(math.Float32frombits(uint32(toPromote >> 32)))))
3937
+ frame.pc++
3938
+ case operationKindV128FloatDemote:
3939
+ hi, lo := ce.popValue(), ce.popValue()
3940
+ ce.pushValue(
3941
+ uint64(math.Float32bits(float32(math.Float64frombits(lo)))) |
3942
+ (uint64(math.Float32bits(float32(math.Float64frombits(hi)))) << 32),
3943
+ )
3944
+ ce.pushValue(0)
3945
+ frame.pc++
3946
+ case operationKindV128FConvertFromI:
3947
+ hi, lo := ce.popValue(), ce.popValue()
3948
+ v1, v2, v3, v4 := uint32(lo), uint32(lo>>32), uint32(hi), uint32(hi>>32)
3949
+ signed := op.B3
3950
+
3951
+ var retLo, retHi uint64
3952
+ switch op.B1 { // Destination shape.
3953
+ case shapeF32x4: // f32x4 from signed/unsigned i32x4
3954
+ if signed {
3955
+ retLo = uint64(math.Float32bits(float32(int32(v1)))) |
3956
+ (uint64(math.Float32bits(float32(int32(v2)))) << 32)
3957
+ retHi = uint64(math.Float32bits(float32(int32(v3)))) |
3958
+ (uint64(math.Float32bits(float32(int32(v4)))) << 32)
3959
+ } else {
3960
+ retLo = uint64(math.Float32bits(float32(v1))) |
3961
+ (uint64(math.Float32bits(float32(v2))) << 32)
3962
+ retHi = uint64(math.Float32bits(float32(v3))) |
3963
+ (uint64(math.Float32bits(float32(v4))) << 32)
3964
+ }
3965
+ case shapeF64x2: // f64x2 from signed/unsigned i32x4
3966
+ if signed {
3967
+ retLo, retHi = math.Float64bits(float64(int32(v1))), math.Float64bits(float64(int32(v2)))
3968
+ } else {
3969
+ retLo, retHi = math.Float64bits(float64(v1)), math.Float64bits(float64(v2))
3970
+ }
3971
+ }
3972
+
3973
+ ce.pushValue(retLo)
3974
+ ce.pushValue(retHi)
3975
+ frame.pc++
3976
+ case operationKindV128Narrow:
3977
+ x2Hi, x2Lo := ce.popValue(), ce.popValue()
3978
+ x1Hi, x1Lo := ce.popValue(), ce.popValue()
3979
+ signed := op.B3
3980
+
3981
+ var retLo, retHi uint64
3982
+ switch op.B1 {
3983
+ case shapeI16x8: // signed/unsigned i16x8 to i8x16
3984
+ for i := 0; i < 8; i++ {
3985
+ var v16 uint16
3986
+ if i < 4 {
3987
+ v16 = uint16(x1Lo >> (i * 16))
3988
+ } else {
3989
+ v16 = uint16(x1Hi >> ((i - 4) * 16))
3990
+ }
3991
+
3992
+ var v byte
3993
+ if signed {
3994
+ if s := int16(v16); s > math.MaxInt8 {
3995
+ v = math.MaxInt8
3996
+ } else if s < math.MinInt8 {
3997
+ s = math.MinInt8
3998
+ v = byte(s)
3999
+ } else {
4000
+ v = byte(v16)
4001
+ }
4002
+ } else {
4003
+ if s := int16(v16); s > math.MaxUint8 {
4004
+ v = math.MaxUint8
4005
+ } else if s < 0 {
4006
+ v = 0
4007
+ } else {
4008
+ v = byte(v16)
4009
+ }
4010
+ }
4011
+ retLo |= uint64(v) << (i * 8)
4012
+ }
4013
+ for i := 0; i < 8; i++ {
4014
+ var v16 uint16
4015
+ if i < 4 {
4016
+ v16 = uint16(x2Lo >> (i * 16))
4017
+ } else {
4018
+ v16 = uint16(x2Hi >> ((i - 4) * 16))
4019
+ }
4020
+
4021
+ var v byte
4022
+ if signed {
4023
+ if s := int16(v16); s > math.MaxInt8 {
4024
+ v = math.MaxInt8
4025
+ } else if s < math.MinInt8 {
4026
+ s = math.MinInt8
4027
+ v = byte(s)
4028
+ } else {
4029
+ v = byte(v16)
4030
+ }
4031
+ } else {
4032
+ if s := int16(v16); s > math.MaxUint8 {
4033
+ v = math.MaxUint8
4034
+ } else if s < 0 {
4035
+ v = 0
4036
+ } else {
4037
+ v = byte(v16)
4038
+ }
4039
+ }
4040
+ retHi |= uint64(v) << (i * 8)
4041
+ }
4042
+ case shapeI32x4: // signed/unsigned i32x4 to i16x8
4043
+ for i := 0; i < 4; i++ {
4044
+ var v32 uint32
4045
+ if i < 2 {
4046
+ v32 = uint32(x1Lo >> (i * 32))
4047
+ } else {
4048
+ v32 = uint32(x1Hi >> ((i - 2) * 32))
4049
+ }
4050
+
4051
+ var v uint16
4052
+ if signed {
4053
+ if s := int32(v32); s > math.MaxInt16 {
4054
+ v = math.MaxInt16
4055
+ } else if s < math.MinInt16 {
4056
+ s = math.MinInt16
4057
+ v = uint16(s)
4058
+ } else {
4059
+ v = uint16(v32)
4060
+ }
4061
+ } else {
4062
+ if s := int32(v32); s > math.MaxUint16 {
4063
+ v = math.MaxUint16
4064
+ } else if s < 0 {
4065
+ v = 0
4066
+ } else {
4067
+ v = uint16(v32)
4068
+ }
4069
+ }
4070
+ retLo |= uint64(v) << (i * 16)
4071
+ }
4072
+
4073
+ for i := 0; i < 4; i++ {
4074
+ var v32 uint32
4075
+ if i < 2 {
4076
+ v32 = uint32(x2Lo >> (i * 32))
4077
+ } else {
4078
+ v32 = uint32(x2Hi >> ((i - 2) * 32))
4079
+ }
4080
+
4081
+ var v uint16
4082
+ if signed {
4083
+ if s := int32(v32); s > math.MaxInt16 {
4084
+ v = math.MaxInt16
4085
+ } else if s < math.MinInt16 {
4086
+ s = math.MinInt16
4087
+ v = uint16(s)
4088
+ } else {
4089
+ v = uint16(v32)
4090
+ }
4091
+ } else {
4092
+ if s := int32(v32); s > math.MaxUint16 {
4093
+ v = math.MaxUint16
4094
+ } else if s < 0 {
4095
+ v = 0
4096
+ } else {
4097
+ v = uint16(v32)
4098
+ }
4099
+ }
4100
+ retHi |= uint64(v) << (i * 16)
4101
+ }
4102
+ }
4103
+ ce.pushValue(retLo)
4104
+ ce.pushValue(retHi)
4105
+ frame.pc++
4106
+ case operationKindV128Dot:
4107
+ x2Hi, x2Lo := ce.popValue(), ce.popValue()
4108
+ x1Hi, x1Lo := ce.popValue(), ce.popValue()
4109
+ lo, hi := v128Dot(x1Hi, x1Lo, x2Hi, x2Lo)
4110
+ ce.pushValue(lo)
4111
+ ce.pushValue(hi)
4112
+ frame.pc++
4113
+ case operationKindV128ITruncSatFromF:
4114
+ hi, lo := ce.popValue(), ce.popValue()
4115
+ signed := op.B3
4116
+ var retLo, retHi uint64
4117
+
4118
+ switch op.B1 {
4119
+ case shapeF32x4: // f32x4 to i32x4
4120
+ for i, f64 := range [4]float64{
4121
+ math.Trunc(float64(math.Float32frombits(uint32(lo)))),
4122
+ math.Trunc(float64(math.Float32frombits(uint32(lo >> 32)))),
4123
+ math.Trunc(float64(math.Float32frombits(uint32(hi)))),
4124
+ math.Trunc(float64(math.Float32frombits(uint32(hi >> 32)))),
4125
+ } {
4126
+
4127
+ var v uint32
4128
+ if math.IsNaN(f64) {
4129
+ v = 0
4130
+ } else if signed {
4131
+ if f64 < math.MinInt32 {
4132
+ f64 = math.MinInt32
4133
+ } else if f64 > math.MaxInt32 {
4134
+ f64 = math.MaxInt32
4135
+ }
4136
+ v = uint32(int32(f64))
4137
+ } else {
4138
+ if f64 < 0 {
4139
+ f64 = 0
4140
+ } else if f64 > math.MaxUint32 {
4141
+ f64 = math.MaxUint32
4142
+ }
4143
+ v = uint32(f64)
4144
+ }
4145
+
4146
+ if i < 2 {
4147
+ retLo |= uint64(v) << (i * 32)
4148
+ } else {
4149
+ retHi |= uint64(v) << ((i - 2) * 32)
4150
+ }
4151
+ }
4152
+
4153
+ case shapeF64x2: // f64x2 to i32x4
4154
+ for i, f := range [2]float64{
4155
+ math.Trunc(math.Float64frombits(lo)),
4156
+ math.Trunc(math.Float64frombits(hi)),
4157
+ } {
4158
+ var v uint32
4159
+ if math.IsNaN(f) {
4160
+ v = 0
4161
+ } else if signed {
4162
+ if f < math.MinInt32 {
4163
+ f = math.MinInt32
4164
+ } else if f > math.MaxInt32 {
4165
+ f = math.MaxInt32
4166
+ }
4167
+ v = uint32(int32(f))
4168
+ } else {
4169
+ if f < 0 {
4170
+ f = 0
4171
+ } else if f > math.MaxUint32 {
4172
+ f = math.MaxUint32
4173
+ }
4174
+ v = uint32(f)
4175
+ }
4176
+
4177
+ retLo |= uint64(v) << (i * 32)
4178
+ }
4179
+ }
4180
+
4181
+ ce.pushValue(retLo)
4182
+ ce.pushValue(retHi)
4183
+ frame.pc++
4184
+ case operationKindAtomicMemoryWait:
4185
+ timeout := int64(ce.popValue())
4186
+ exp := ce.popValue()
4187
+ offset := ce.popMemoryOffset(op)
4188
+ // Runtime instead of validation error because the spec intends to allow binaries to include
4189
+ // such instructions as long as they are not executed.
4190
+ if !memoryInst.Shared {
4191
+ panic(wasmruntime.ErrRuntimeExpectedSharedMemory)
4192
+ }
4193
+
4194
+ switch unsignedType(op.B1) {
4195
+ case unsignedTypeI32:
4196
+ if offset%4 != 0 {
4197
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4198
+ }
4199
+ if int(offset) > len(memoryInst.Buffer)-4 {
4200
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4201
+ }
4202
+ ce.pushValue(memoryInst.Wait32(offset, uint32(exp), timeout, func(mem *wasm.MemoryInstance, offset uint32) uint32 {
4203
+ mem.Mux.Lock()
4204
+ defer mem.Mux.Unlock()
4205
+ value, _ := mem.ReadUint32Le(offset)
4206
+ return value
4207
+ }))
4208
+ case unsignedTypeI64:
4209
+ if offset%8 != 0 {
4210
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4211
+ }
4212
+ if int(offset) > len(memoryInst.Buffer)-8 {
4213
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4214
+ }
4215
+ ce.pushValue(memoryInst.Wait64(offset, exp, timeout, func(mem *wasm.MemoryInstance, offset uint32) uint64 {
4216
+ mem.Mux.Lock()
4217
+ defer mem.Mux.Unlock()
4218
+ value, _ := mem.ReadUint64Le(offset)
4219
+ return value
4220
+ }))
4221
+ }
4222
+ frame.pc++
4223
+ case operationKindAtomicMemoryNotify:
4224
+ count := ce.popValue()
4225
+ offset := ce.popMemoryOffset(op)
4226
+ if offset%4 != 0 {
4227
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4228
+ }
4229
+ // Just a bounds check
4230
+ if offset >= memoryInst.Size() {
4231
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4232
+ }
4233
+ res := memoryInst.Notify(offset, uint32(count))
4234
+ ce.pushValue(uint64(res))
4235
+ frame.pc++
4236
+ case operationKindAtomicFence:
4237
+ // Memory not required for fence only
4238
+ if memoryInst != nil {
4239
+ // An empty critical section can be used as a synchronization primitive, which is what
4240
+ // fence is. Probably, there are no spectests or defined behavior to confirm this yet.
4241
+ memoryInst.Mux.Lock()
4242
+ memoryInst.Mux.Unlock() //nolint:staticcheck
4243
+ }
4244
+ frame.pc++
4245
+ case operationKindAtomicLoad:
4246
+ offset := ce.popMemoryOffset(op)
4247
+ switch unsignedType(op.B1) {
4248
+ case unsignedTypeI32:
4249
+ if offset%4 != 0 {
4250
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4251
+ }
4252
+ memoryInst.Mux.Lock()
4253
+ val, ok := memoryInst.ReadUint32Le(offset)
4254
+ memoryInst.Mux.Unlock()
4255
+ if !ok {
4256
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4257
+ }
4258
+ ce.pushValue(uint64(val))
4259
+ case unsignedTypeI64:
4260
+ if offset%8 != 0 {
4261
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4262
+ }
4263
+ memoryInst.Mux.Lock()
4264
+ val, ok := memoryInst.ReadUint64Le(offset)
4265
+ memoryInst.Mux.Unlock()
4266
+ if !ok {
4267
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4268
+ }
4269
+ ce.pushValue(val)
4270
+ }
4271
+ frame.pc++
4272
+ case operationKindAtomicLoad8:
4273
+ offset := ce.popMemoryOffset(op)
4274
+ memoryInst.Mux.Lock()
4275
+ val, ok := memoryInst.ReadByte(offset)
4276
+ memoryInst.Mux.Unlock()
4277
+ if !ok {
4278
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4279
+ }
4280
+ ce.pushValue(uint64(val))
4281
+ frame.pc++
4282
+ case operationKindAtomicLoad16:
4283
+ offset := ce.popMemoryOffset(op)
4284
+ if offset%2 != 0 {
4285
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4286
+ }
4287
+ memoryInst.Mux.Lock()
4288
+ val, ok := memoryInst.ReadUint16Le(offset)
4289
+ memoryInst.Mux.Unlock()
4290
+ if !ok {
4291
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4292
+ }
4293
+ ce.pushValue(uint64(val))
4294
+ frame.pc++
4295
+ case operationKindAtomicStore:
4296
+ val := ce.popValue()
4297
+ offset := ce.popMemoryOffset(op)
4298
+ switch unsignedType(op.B1) {
4299
+ case unsignedTypeI32:
4300
+ if offset%4 != 0 {
4301
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4302
+ }
4303
+ memoryInst.Mux.Lock()
4304
+ ok := memoryInst.WriteUint32Le(offset, uint32(val))
4305
+ memoryInst.Mux.Unlock()
4306
+ if !ok {
4307
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4308
+ }
4309
+ case unsignedTypeI64:
4310
+ if offset%8 != 0 {
4311
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4312
+ }
4313
+ memoryInst.Mux.Lock()
4314
+ ok := memoryInst.WriteUint64Le(offset, val)
4315
+ memoryInst.Mux.Unlock()
4316
+ if !ok {
4317
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4318
+ }
4319
+ }
4320
+ frame.pc++
4321
+ case operationKindAtomicStore8:
4322
+ val := byte(ce.popValue())
4323
+ offset := ce.popMemoryOffset(op)
4324
+ memoryInst.Mux.Lock()
4325
+ ok := memoryInst.WriteByte(offset, val)
4326
+ memoryInst.Mux.Unlock()
4327
+ if !ok {
4328
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4329
+ }
4330
+ frame.pc++
4331
+ case operationKindAtomicStore16:
4332
+ val := uint16(ce.popValue())
4333
+ offset := ce.popMemoryOffset(op)
4334
+ if offset%2 != 0 {
4335
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4336
+ }
4337
+ memoryInst.Mux.Lock()
4338
+ ok := memoryInst.WriteUint16Le(offset, val)
4339
+ memoryInst.Mux.Unlock()
4340
+ if !ok {
4341
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4342
+ }
4343
+ frame.pc++
4344
+ case operationKindAtomicRMW:
4345
+ val := ce.popValue()
4346
+ offset := ce.popMemoryOffset(op)
4347
+ switch unsignedType(op.B1) {
4348
+ case unsignedTypeI32:
4349
+ if offset%4 != 0 {
4350
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4351
+ }
4352
+ memoryInst.Mux.Lock()
4353
+ old, ok := memoryInst.ReadUint32Le(offset)
4354
+ if !ok {
4355
+ memoryInst.Mux.Unlock()
4356
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4357
+ }
4358
+ var newVal uint32
4359
+ switch atomicArithmeticOp(op.B2) {
4360
+ case atomicArithmeticOpAdd:
4361
+ newVal = old + uint32(val)
4362
+ case atomicArithmeticOpSub:
4363
+ newVal = old - uint32(val)
4364
+ case atomicArithmeticOpAnd:
4365
+ newVal = old & uint32(val)
4366
+ case atomicArithmeticOpOr:
4367
+ newVal = old | uint32(val)
4368
+ case atomicArithmeticOpXor:
4369
+ newVal = old ^ uint32(val)
4370
+ case atomicArithmeticOpNop:
4371
+ newVal = uint32(val)
4372
+ }
4373
+ memoryInst.WriteUint32Le(offset, newVal)
4374
+ memoryInst.Mux.Unlock()
4375
+ ce.pushValue(uint64(old))
4376
+ case unsignedTypeI64:
4377
+ if offset%8 != 0 {
4378
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4379
+ }
4380
+ memoryInst.Mux.Lock()
4381
+ old, ok := memoryInst.ReadUint64Le(offset)
4382
+ if !ok {
4383
+ memoryInst.Mux.Unlock()
4384
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4385
+ }
4386
+ var newVal uint64
4387
+ switch atomicArithmeticOp(op.B2) {
4388
+ case atomicArithmeticOpAdd:
4389
+ newVal = old + val
4390
+ case atomicArithmeticOpSub:
4391
+ newVal = old - val
4392
+ case atomicArithmeticOpAnd:
4393
+ newVal = old & val
4394
+ case atomicArithmeticOpOr:
4395
+ newVal = old | val
4396
+ case atomicArithmeticOpXor:
4397
+ newVal = old ^ val
4398
+ case atomicArithmeticOpNop:
4399
+ newVal = val
4400
+ }
4401
+ memoryInst.WriteUint64Le(offset, newVal)
4402
+ memoryInst.Mux.Unlock()
4403
+ ce.pushValue(old)
4404
+ }
4405
+ frame.pc++
4406
+ case operationKindAtomicRMW8:
4407
+ val := ce.popValue()
4408
+ offset := ce.popMemoryOffset(op)
4409
+ memoryInst.Mux.Lock()
4410
+ old, ok := memoryInst.ReadByte(offset)
4411
+ if !ok {
4412
+ memoryInst.Mux.Unlock()
4413
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4414
+ }
4415
+ arg := byte(val)
4416
+ var newVal byte
4417
+ switch atomicArithmeticOp(op.B2) {
4418
+ case atomicArithmeticOpAdd:
4419
+ newVal = old + arg
4420
+ case atomicArithmeticOpSub:
4421
+ newVal = old - arg
4422
+ case atomicArithmeticOpAnd:
4423
+ newVal = old & arg
4424
+ case atomicArithmeticOpOr:
4425
+ newVal = old | arg
4426
+ case atomicArithmeticOpXor:
4427
+ newVal = old ^ arg
4428
+ case atomicArithmeticOpNop:
4429
+ newVal = arg
4430
+ }
4431
+ memoryInst.WriteByte(offset, newVal)
4432
+ memoryInst.Mux.Unlock()
4433
+ ce.pushValue(uint64(old))
4434
+ frame.pc++
4435
+ case operationKindAtomicRMW16:
4436
+ val := ce.popValue()
4437
+ offset := ce.popMemoryOffset(op)
4438
+ if offset%2 != 0 {
4439
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4440
+ }
4441
+ memoryInst.Mux.Lock()
4442
+ old, ok := memoryInst.ReadUint16Le(offset)
4443
+ if !ok {
4444
+ memoryInst.Mux.Unlock()
4445
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4446
+ }
4447
+ arg := uint16(val)
4448
+ var newVal uint16
4449
+ switch atomicArithmeticOp(op.B2) {
4450
+ case atomicArithmeticOpAdd:
4451
+ newVal = old + arg
4452
+ case atomicArithmeticOpSub:
4453
+ newVal = old - arg
4454
+ case atomicArithmeticOpAnd:
4455
+ newVal = old & arg
4456
+ case atomicArithmeticOpOr:
4457
+ newVal = old | arg
4458
+ case atomicArithmeticOpXor:
4459
+ newVal = old ^ arg
4460
+ case atomicArithmeticOpNop:
4461
+ newVal = arg
4462
+ }
4463
+ memoryInst.WriteUint16Le(offset, newVal)
4464
+ memoryInst.Mux.Unlock()
4465
+ ce.pushValue(uint64(old))
4466
+ frame.pc++
4467
+ case operationKindAtomicRMWCmpxchg:
4468
+ rep := ce.popValue()
4469
+ exp := ce.popValue()
4470
+ offset := ce.popMemoryOffset(op)
4471
+ switch unsignedType(op.B1) {
4472
+ case unsignedTypeI32:
4473
+ if offset%4 != 0 {
4474
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4475
+ }
4476
+ memoryInst.Mux.Lock()
4477
+ old, ok := memoryInst.ReadUint32Le(offset)
4478
+ if !ok {
4479
+ memoryInst.Mux.Unlock()
4480
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4481
+ }
4482
+ if old == uint32(exp) {
4483
+ memoryInst.WriteUint32Le(offset, uint32(rep))
4484
+ }
4485
+ memoryInst.Mux.Unlock()
4486
+ ce.pushValue(uint64(old))
4487
+ case unsignedTypeI64:
4488
+ if offset%8 != 0 {
4489
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4490
+ }
4491
+ memoryInst.Mux.Lock()
4492
+ old, ok := memoryInst.ReadUint64Le(offset)
4493
+ if !ok {
4494
+ memoryInst.Mux.Unlock()
4495
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4496
+ }
4497
+ if old == exp {
4498
+ memoryInst.WriteUint64Le(offset, rep)
4499
+ }
4500
+ memoryInst.Mux.Unlock()
4501
+ ce.pushValue(old)
4502
+ }
4503
+ frame.pc++
4504
+ case operationKindAtomicRMW8Cmpxchg:
4505
+ rep := byte(ce.popValue())
4506
+ exp := byte(ce.popValue())
4507
+ offset := ce.popMemoryOffset(op)
4508
+ memoryInst.Mux.Lock()
4509
+ old, ok := memoryInst.ReadByte(offset)
4510
+ if !ok {
4511
+ memoryInst.Mux.Unlock()
4512
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4513
+ }
4514
+ if old == exp {
4515
+ memoryInst.WriteByte(offset, rep)
4516
+ }
4517
+ memoryInst.Mux.Unlock()
4518
+ ce.pushValue(uint64(old))
4519
+ frame.pc++
4520
+ case operationKindAtomicRMW16Cmpxchg:
4521
+ rep := uint16(ce.popValue())
4522
+ exp := uint16(ce.popValue())
4523
+ offset := ce.popMemoryOffset(op)
4524
+ if offset%2 != 0 {
4525
+ panic(wasmruntime.ErrRuntimeUnalignedAtomic)
4526
+ }
4527
+ memoryInst.Mux.Lock()
4528
+ old, ok := memoryInst.ReadUint16Le(offset)
4529
+ if !ok {
4530
+ memoryInst.Mux.Unlock()
4531
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4532
+ }
4533
+ if old == exp {
4534
+ memoryInst.WriteUint16Le(offset, rep)
4535
+ }
4536
+ memoryInst.Mux.Unlock()
4537
+ ce.pushValue(uint64(old))
4538
+ frame.pc++
4539
+ case operationKindThrow:
4540
+ tagIndex := uint32(op.U1)
4541
+ tag := moduleInst.Tags[tagIndex]
4542
+ paramCount := len(tag.Type.Params)
4543
+ params := make([]uint64, paramCount)
4544
+ for i := paramCount - 1; i >= 0; i-- {
4545
+ params[i] = ce.popValue()
4546
+ }
4547
+ exn := &wasm.Exception{Tag: tag, Params: params}
4548
+ if clause, values := searchExceptionTable(exn, frame); clause != nil {
4549
+ ce.applyExceptionHandler(frame, clause, values)
4550
+ continue
4551
+ }
4552
+ panic(&thrownException{exception: exn})
4553
+
4554
+ case operationKindThrowRef:
4555
+ v := ce.popValue()
4556
+ if v == 0 {
4557
+ panic(wasmruntime.ErrRuntimeNullReference) // throw_ref on null exnref traps
4558
+ }
4559
+ // Read the Exception pointer directly from the uint64 value to avoid
4560
+ // conversion from uintptr into unsafe.Pointer, which triggers checkptr.
4561
+ exn := *(**wasm.Exception)(unsafe.Pointer(&v))
4562
+ if clause, values := searchExceptionTable(exn, frame); clause != nil {
4563
+ ce.applyExceptionHandler(frame, clause, values)
4564
+ continue
4565
+ }
4566
+ panic(&thrownException{exception: exn})
4567
+
4568
+ case operationKindTailCallReturnCall:
4569
+ f := &functions[op.U1]
4570
+ ce.dropForTailCall(frame, f)
4571
+ body, bodyLen = ce.resetPc(frame, f)
4572
+
4573
+ case operationKindTailCallReturnCallIndirect:
4574
+ offset := ce.popValue()
4575
+ table := tables[op.U2]
4576
+ tf := ce.functionForOffset(table, offset, typeIDs[op.U1])
4577
+
4578
+ // We are allowing proper tail calls only across functions that belong to the same
4579
+ // module; for indirect calls, we have to enforce it at run-time.
4580
+ // For details, see internal/engine/RATIONALE.md
4581
+ if tf.moduleInstance != f.moduleInstance {
4582
+ // Revert to a normal call.
4583
+ frameUnwound := ce.callWithUnwind(ctx, f.moduleInstance, tf)
4584
+ if frameUnwound {
4585
+ frame = ce.frames[len(ce.frames)-1]
4586
+ body = frame.f.parent.body
4587
+ bodyLen = uint64(len(body))
4588
+ continue
4589
+ }
4590
+ // Return
4591
+ ce.drop(op.Us[0])
4592
+ // Jump to the function frame (return)
4593
+ frame.pc = op.Us[1]
4594
+ continue
4595
+ }
4596
+
4597
+ ce.dropForTailCall(frame, tf)
4598
+ body, bodyLen = ce.resetPc(frame, tf)
4599
+
4600
+ case operationKindCallRef:
4601
+ ref := ce.popValue()
4602
+ if ref == 0 {
4603
+ panic(wasmruntime.ErrRuntimeNullReference)
4604
+ }
4605
+ tf := functionFromUintptr(uintptr(ref))
4606
+
4607
+ frameUnwound := ce.callWithUnwind(ctx, f.moduleInstance, tf)
4608
+ if frameUnwound {
4609
+ frame = ce.frames[len(ce.frames)-1]
4610
+ body = frame.f.parent.body
4611
+ bodyLen = uint64(len(body))
4612
+ continue
4613
+ }
4614
+ frame.pc++
4615
+
4616
+ case operationKindReturnCallRef:
4617
+ ref := ce.popValue()
4618
+ if ref == 0 {
4619
+ panic(wasmruntime.ErrRuntimeNullReference)
4620
+ }
4621
+ tf := functionFromUintptr(uintptr(ref))
4622
+
4623
+ if tf.moduleInstance != f.moduleInstance {
4624
+ frameUnwound := ce.callWithUnwind(ctx, f.moduleInstance, tf)
4625
+ if frameUnwound {
4626
+ frame = ce.frames[len(ce.frames)-1]
4627
+ body = frame.f.parent.body
4628
+ bodyLen = uint64(len(body))
4629
+ continue
4630
+ }
4631
+ ce.drop(op.Us[0])
4632
+ frame.pc = op.Us[1]
4633
+ continue
4634
+ }
4635
+
4636
+ ce.dropForTailCall(frame, tf)
4637
+ body, bodyLen = ce.resetPc(frame, tf)
4638
+
4639
+ case operationKindRefAsNonNull:
4640
+ ref := ce.popValue()
4641
+ if ref == 0 {
4642
+ panic(wasmruntime.ErrRuntimeNullReference)
4643
+ }
4644
+ ce.pushValue(ref)
4645
+ frame.pc++
4646
+
4647
+ case operationKindBrOnNull:
4648
+ ref := ce.popValue()
4649
+ if ref == 0 {
4650
+ ce.drop(op.U3)
4651
+ frame.pc = op.U1
4652
+ } else {
4653
+ ce.pushValue(ref)
4654
+ frame.pc = op.U2
4655
+ }
4656
+
4657
+ case operationKindBrOnNonNull:
4658
+ ref := ce.popValue()
4659
+ if ref != 0 {
4660
+ ce.drop(op.U3)
4661
+ ce.pushValue(ref)
4662
+ frame.pc = op.U1
4663
+ } else {
4664
+ frame.pc = op.U2
4665
+ }
4666
+
4667
+ default:
4668
+ frame.pc++
4669
+ }
4670
+ }
4671
+ ce.popFrame()
4672
+ }
4673
+
4674
+ func (ce *callEngine) dropForTailCall(frame *callFrame, f *function) {
4675
+ base := frame.base - frame.f.funcType.ParamNumInUint64
4676
+ paramCount := f.funcType.ParamNumInUint64
4677
+ ce.stack = append(ce.stack[:base], ce.stack[len(ce.stack)-paramCount:]...)
4678
+ }
4679
+
4680
+ func (ce *callEngine) resetPc(frame *callFrame, f *function) (body []unionOperation, bodyLen uint64) {
4681
+ // The compiler is currently allowing proper tail call only across functions
4682
+ // that belong to the same module; thus, we can overwrite the frame in-place.
4683
+ // For details, see internal/engine/RATIONALE.md
4684
+ frame.f = f
4685
+ frame.base = len(ce.stack)
4686
+ frame.pc = 0
4687
+ body = frame.f.parent.body
4688
+ bodyLen = uint64(len(body))
4689
+ return body, bodyLen
4690
+ }
4691
+
4692
+ func (ce *callEngine) functionForOffset(table *wasm.TableInstance, offset uint64, expectedTypeID wasm.FunctionTypeID) *function {
4693
+ if offset >= uint64(len(table.References)) {
4694
+ panic(wasmruntime.ErrRuntimeInvalidTableAccess)
4695
+ }
4696
+ rawPtr := table.References[offset]
4697
+ if rawPtr == 0 {
4698
+ panic(wasmruntime.ErrRuntimeInvalidTableAccess)
4699
+ }
4700
+
4701
+ tf := functionFromUintptr(rawPtr)
4702
+ if tf.typeID != expectedTypeID {
4703
+ panic(wasmruntime.ErrRuntimeIndirectCallTypeMismatch)
4704
+ }
4705
+ return tf
4706
+ }
4707
+
4708
+ func wasmCompatMax32bits(v1, v2 uint32) uint64 {
4709
+ return uint64(math.Float32bits(moremath.WasmCompatMax32(
4710
+ math.Float32frombits(v1),
4711
+ math.Float32frombits(v2),
4712
+ )))
4713
+ }
4714
+
4715
+ func wasmCompatMin32bits(v1, v2 uint32) uint64 {
4716
+ return uint64(math.Float32bits(moremath.WasmCompatMin32(
4717
+ math.Float32frombits(v1),
4718
+ math.Float32frombits(v2),
4719
+ )))
4720
+ }
4721
+
4722
+ func addFloat32bits(v1, v2 uint32) uint64 {
4723
+ return uint64(math.Float32bits(math.Float32frombits(v1) + math.Float32frombits(v2)))
4724
+ }
4725
+
4726
+ func subFloat32bits(v1, v2 uint32) uint64 {
4727
+ return uint64(math.Float32bits(math.Float32frombits(v1) - math.Float32frombits(v2)))
4728
+ }
4729
+
4730
+ func mulFloat32bits(v1, v2 uint32) uint64 {
4731
+ return uint64(math.Float32bits(math.Float32frombits(v1) * math.Float32frombits(v2)))
4732
+ }
4733
+
4734
+ func divFloat32bits(v1, v2 uint32) uint64 {
4735
+ return uint64(math.Float32bits(math.Float32frombits(v1) / math.Float32frombits(v2)))
4736
+ }
4737
+
4738
+ // https://www.w3.org/TR/2022/WD-wasm-core-2-20220419/exec/numerics.html#xref-exec-numerics-op-flt-mathrm-flt-n-z-1-z-2
4739
+ func flt32(z1, z2 float32) bool {
4740
+ if z1 != z1 || z2 != z2 {
4741
+ return false
4742
+ } else if z1 == z2 {
4743
+ return false
4744
+ } else if math.IsInf(float64(z1), 1) {
4745
+ return false
4746
+ } else if math.IsInf(float64(z1), -1) {
4747
+ return true
4748
+ } else if math.IsInf(float64(z2), 1) {
4749
+ return true
4750
+ } else if math.IsInf(float64(z2), -1) {
4751
+ return false
4752
+ }
4753
+ return z1 < z2
4754
+ }
4755
+
4756
+ // https://www.w3.org/TR/2022/WD-wasm-core-2-20220419/exec/numerics.html#xref-exec-numerics-op-flt-mathrm-flt-n-z-1-z-2
4757
+ func flt64(z1, z2 float64) bool {
4758
+ if z1 != z1 || z2 != z2 {
4759
+ return false
4760
+ } else if z1 == z2 {
4761
+ return false
4762
+ } else if math.IsInf(z1, 1) {
4763
+ return false
4764
+ } else if math.IsInf(z1, -1) {
4765
+ return true
4766
+ } else if math.IsInf(z2, 1) {
4767
+ return true
4768
+ } else if math.IsInf(z2, -1) {
4769
+ return false
4770
+ }
4771
+ return z1 < z2
4772
+ }
4773
+
4774
+ func i8RoundingAverage(v1, v2 byte) byte {
4775
+ // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#lane-wise-integer-rounding-average
4776
+ return byte((uint16(v1) + uint16(v2) + uint16(1)) / 2)
4777
+ }
4778
+
4779
+ func i16RoundingAverage(v1, v2 uint16) uint16 {
4780
+ // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#lane-wise-integer-rounding-average
4781
+ return uint16((uint32(v1) + uint32(v2) + 1) / 2)
4782
+ }
4783
+
4784
+ func i8Abs(v byte) byte {
4785
+ if i := int8(v); i < 0 {
4786
+ return byte(-i)
4787
+ } else {
4788
+ return byte(i)
4789
+ }
4790
+ }
4791
+
4792
+ func i8MaxU(v1, v2 byte) byte {
4793
+ if v1 < v2 {
4794
+ return v2
4795
+ } else {
4796
+ return v1
4797
+ }
4798
+ }
4799
+
4800
+ func i8MinU(v1, v2 byte) byte {
4801
+ if v1 > v2 {
4802
+ return v2
4803
+ } else {
4804
+ return v1
4805
+ }
4806
+ }
4807
+
4808
+ func i8MaxS(v1, v2 byte) byte {
4809
+ if int8(v1) < int8(v2) {
4810
+ return v2
4811
+ } else {
4812
+ return v1
4813
+ }
4814
+ }
4815
+
4816
+ func i8MinS(v1, v2 byte) byte {
4817
+ if int8(v1) > int8(v2) {
4818
+ return v2
4819
+ } else {
4820
+ return v1
4821
+ }
4822
+ }
4823
+
4824
+ func i16MaxU(v1, v2 uint16) uint16 {
4825
+ if v1 < v2 {
4826
+ return v2
4827
+ } else {
4828
+ return v1
4829
+ }
4830
+ }
4831
+
4832
+ func i16MinU(v1, v2 uint16) uint16 {
4833
+ if v1 > v2 {
4834
+ return v2
4835
+ } else {
4836
+ return v1
4837
+ }
4838
+ }
4839
+
4840
+ func i16MaxS(v1, v2 uint16) uint16 {
4841
+ if int16(v1) < int16(v2) {
4842
+ return v2
4843
+ } else {
4844
+ return v1
4845
+ }
4846
+ }
4847
+
4848
+ func i16MinS(v1, v2 uint16) uint16 {
4849
+ if int16(v1) > int16(v2) {
4850
+ return v2
4851
+ } else {
4852
+ return v1
4853
+ }
4854
+ }
4855
+
4856
+ func i32MaxU(v1, v2 uint32) uint32 {
4857
+ if v1 < v2 {
4858
+ return v2
4859
+ } else {
4860
+ return v1
4861
+ }
4862
+ }
4863
+
4864
+ func i32MinU(v1, v2 uint32) uint32 {
4865
+ if v1 > v2 {
4866
+ return v2
4867
+ } else {
4868
+ return v1
4869
+ }
4870
+ }
4871
+
4872
+ func i32MaxS(v1, v2 uint32) uint32 {
4873
+ if int32(v1) < int32(v2) {
4874
+ return v2
4875
+ } else {
4876
+ return v1
4877
+ }
4878
+ }
4879
+
4880
+ func i32MinS(v1, v2 uint32) uint32 {
4881
+ if int32(v1) > int32(v2) {
4882
+ return v2
4883
+ } else {
4884
+ return v1
4885
+ }
4886
+ }
4887
+
4888
+ func i16Abs(v uint16) uint16 {
4889
+ if i := int16(v); i < 0 {
4890
+ return uint16(-i)
4891
+ } else {
4892
+ return uint16(i)
4893
+ }
4894
+ }
4895
+
4896
+ func i32Abs(v uint32) uint32 {
4897
+ if i := int32(v); i < 0 {
4898
+ return uint32(-i)
4899
+ } else {
4900
+ return uint32(i)
4901
+ }
4902
+ }
4903
+
4904
+ func (ce *callEngine) callNativeFuncWithListener(ctx context.Context, m *wasm.ModuleInstance, f *function, fnl experimental.FunctionListener) context.Context {
4905
+ def, typ := f.definition(), f.funcType
4906
+
4907
+ ce.stackIterator.reset(ce.stack, ce.frames, f)
4908
+ fnl.Before(ctx, m, def, ce.peekValues(typ.ParamNumInUint64), &ce.stackIterator)
4909
+ ce.stackIterator.clear()
4910
+ ce.callNativeFunc(ctx, m, f)
4911
+ fnl.After(ctx, m, def, ce.peekValues(typ.ResultNumInUint64))
4912
+ return ctx
4913
+ }
4914
+
4915
+ // popMemoryOffset takes a memory offset off the stack for use in load and store instructions.
4916
+ // As the top of stack value is 64-bit, this ensures it is in range before returning it.
4917
+ func (ce *callEngine) popMemoryOffset(op *unionOperation) uint32 {
4918
+ // Memory addresses are i32; mask to 32 bits to ignore any
4919
+ // garbage in the upper bits of the uint64 stack slot.
4920
+ offset := op.U2 + uint64(uint32(ce.popValue()))
4921
+ if offset > math.MaxUint32 {
4922
+ panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess)
4923
+ }
4924
+ return uint32(offset)
4925
+ }
4926
+
4927
+ func (ce *callEngine) callGoFuncWithStack(ctx context.Context, m *wasm.ModuleInstance, f *function) {
4928
+ typ := f.funcType
4929
+ paramLen := typ.ParamNumInUint64
4930
+ resultLen := typ.ResultNumInUint64
4931
+ stackLen := paramLen
4932
+
4933
+ // In the interpreter engine, ce.stack may only have capacity to store
4934
+ // parameters. Grow when there are more results than parameters.
4935
+ if growLen := resultLen - paramLen; growLen > 0 {
4936
+ ce.stack = append(ce.stack, make([]uint64, growLen)...)
4937
+ stackLen += growLen
4938
+ }
4939
+
4940
+ // Pass the stack elements to the go function.
4941
+ stack := ce.stack[len(ce.stack)-stackLen:]
4942
+ ce.callGoFunc(ctx, m, f, stack)
4943
+
4944
+ // Shrink the stack when there were more parameters than results.
4945
+ if shrinkLen := paramLen - resultLen; shrinkLen > 0 {
4946
+ ce.stack = ce.stack[0 : len(ce.stack)-shrinkLen]
4947
+ }
4948
+ }
4949
+
4950
+ // v128Dot performs a dot product of two 64-bit vectors.
4951
+ // Note: for some reason (which I suspect is due to a bug in Go compiler's regalloc),
4952
+ // inlining this function causes a bug which happens **only when** we run with -race AND arm64 AND Go 1.22.
4953
+ func v128Dot(x1Hi, x1Lo, x2Hi, x2Lo uint64) (uint64, uint64) {
4954
+ r1 := int32(int16(x1Lo>>0)) * int32(int16(x2Lo>>0))
4955
+ r2 := int32(int16(x1Lo>>16)) * int32(int16(x2Lo>>16))
4956
+ r3 := int32(int16(x1Lo>>32)) * int32(int16(x2Lo>>32))
4957
+ r4 := int32(int16(x1Lo>>48)) * int32(int16(x2Lo>>48))
4958
+ r5 := int32(int16(x1Hi>>0)) * int32(int16(x2Hi>>0))
4959
+ r6 := int32(int16(x1Hi>>16)) * int32(int16(x2Hi>>16))
4960
+ r7 := int32(int16(x1Hi>>32)) * int32(int16(x2Hi>>32))
4961
+ r8 := int32(int16(x1Hi>>48)) * int32(int16(x2Hi>>48))
4962
+ return uint64(uint32(r1+r2)) | (uint64(uint32(r3+r4)) << 32), uint64(uint32(r5+r6)) | (uint64(uint32(r7+r8)) << 32)
4963
+ }