diff --git a/examples/i64-polyfill/i64.untouched.wat b/examples/i64-polyfill/i64.untouched.wat index f65b723e..f75858f6 100644 --- a/examples/i64-polyfill/i64.untouched.wat +++ b/examples/i64-polyfill/i64.untouched.wat @@ -1,9 +1,12 @@ (module (type $i (func (result i32))) + (type $F (func (result f64))) (type $iiv (func (param i32 i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (global $assembly/i64/lo (mut i32) (i32.const 0)) (global $assembly/i64/hi (mut i32) (i32.const 0)) + (global $NaN f64 (f64.const nan:0x8000000000000)) + (global $Infinity f64 (f64.const inf)) (export "getLo" (func $assembly/i64/getLo)) (export "getHi" (func $assembly/i64/getHi)) (export "clz" (func $assembly/i64/clz)) @@ -178,7 +181,10 @@ ;;@ assembly/i64.ts:38:2 (set_global $assembly/i64/lo ;;@ assembly/i64.ts:38:7 - (get_local $2) + (i32.and + (get_local $2) + (i32.const 1) + ) ) ;;@ assembly/i64.ts:39:2 (set_global $assembly/i64/hi diff --git a/examples/mandelbrot/build/optimized.wasm b/examples/mandelbrot/build/optimized.wasm index 05bf2072..5ba79564 100644 Binary files a/examples/mandelbrot/build/optimized.wasm and b/examples/mandelbrot/build/optimized.wasm differ diff --git a/examples/mandelbrot/build/optimized.wat b/examples/mandelbrot/build/optimized.wat index 13940b10..b03e33b2 100644 --- a/examples/mandelbrot/build/optimized.wat +++ b/examples/mandelbrot/build/optimized.wat @@ -297,9 +297,9 @@ (if (result i32) (f64.eq (f64.sub - (tee_local $7 + (tee_local $4 ;;@ assembly/index.ts:36:4 - (tee_local $8 + (tee_local $7 ;;@ assembly/index.ts:36:15 (f64.div ;;@ assembly/index.ts:36:20 @@ -330,7 +330,7 @@ ) ) ) - (get_local $7) + (get_local $4) ) (f64.const 0) ) @@ -341,25 +341,23 @@ (f64.const 2047) (f64.min (f64.max - (tee_local $7 - ;;@ assembly/index.ts:38:39 - (f64.div - (f64.sub - (f64.convert_u/i32 - ;;@ assembly/index.ts:38:40 - (i32.add - (get_local $6) - ;;@ assembly/index.ts:38:52 - (i32.const 1) - ) - ) - ;;@ assembly/index.ts:38:56 - (get_local $8) - ) + ;;@ assembly/index.ts:38:39 + (f64.div + (f64.sub (f64.convert_u/i32 - ;;@ assembly/index.ts:38:64 - (get_local $3) + ;;@ assembly/index.ts:38:40 + (i32.add + (get_local $6) + ;;@ assembly/index.ts:38:52 + (i32.const 1) + ) ) + ;;@ assembly/index.ts:38:56 + (get_local $7) + ) + (f64.convert_u/i32 + ;;@ assembly/index.ts:38:64 + (get_local $3) ) ) (f64.const 0) diff --git a/examples/mandelbrot/build/untouched.wat b/examples/mandelbrot/build/untouched.wat index 04ae6458..18a03559 100644 --- a/examples/mandelbrot/build/untouched.wat +++ b/examples/mandelbrot/build/untouched.wat @@ -13,16 +13,16 @@ (export "computeLine" (func $assembly/index/computeLine)) (export "memory" (memory $0)) (func $isFinite (; 2 ;) (type $Fi) (param $0 f64) (result i32) - ;;@ ~lib/builtins.ts:20:26 + ;;@ ~lib/builtins.ts:22:26 (return - ;;@ ~lib/builtins.ts:20:9 + ;;@ ~lib/builtins.ts:22:9 (f64.eq (f64.sub (get_local $0) - ;;@ ~lib/builtins.ts:20:17 + ;;@ ~lib/builtins.ts:22:17 (get_local $0) ) - ;;@ ~lib/builtins.ts:20:26 + ;;@ ~lib/builtins.ts:22:26 (f64.const 0) ) ) @@ -58,7 +58,9 @@ (local $14 i32) (local $15 f64) (local $16 f64) - (local $17 i32) + (local $17 f64) + (local $18 f64) + (local $19 i32) ;;@ assembly/index.ts:8:2 (set_local $4 ;;@ assembly/index.ts:8:19 @@ -265,7 +267,7 @@ ;;@ assembly/index.ts:27:4 (block $break|2 ;;@ assembly/index.ts:27:9 - (set_local $15 + (set_local $16 ;;@ assembly/index.ts:27:29 (f64.min ;;@ assembly/index.ts:27:33 @@ -284,12 +286,12 @@ (get_local $14) ) ;;@ assembly/index.ts:27:56 - (get_local $15) + (get_local $16) ) (block (block ;;@ assembly/index.ts:28:6 - (set_local $16 + (set_local $17 ;;@ assembly/index.ts:28:18 (f64.add (f64.sub @@ -329,7 +331,7 @@ ;;@ assembly/index.ts:30:6 (set_local $10 ;;@ assembly/index.ts:30:11 - (get_local $16) + (get_local $17) ) ) ;;@ assembly/index.ts:27:71 @@ -346,7 +348,7 @@ ) ) ;;@ assembly/index.ts:36:4 - (set_local $15 + (set_local $18 ;;@ assembly/index.ts:36:15 (f64.div ;;@ assembly/index.ts:36:20 @@ -377,12 +379,12 @@ ) ) ;;@ assembly/index.ts:37:4 - (set_local $17 + (set_local $19 ;;@ assembly/index.ts:37:15 (if (result i32) (call $isFinite ;;@ assembly/index.ts:37:24 - (get_local $15) + (get_local $18) ) ;;@ assembly/index.ts:38:8 (i32.trunc_u/f64 @@ -410,7 +412,7 @@ ) ) ;;@ assembly/index.ts:38:56 - (get_local $15) + (get_local $18) ) (f64.convert_u/i32 ;;@ assembly/index.ts:38:64 @@ -450,7 +452,7 @@ (i32.const 1) ) ;;@ assembly/index.ts:40:37 - (get_local $17) + (get_local $19) ) ) ;;@ assembly/index.ts:12:34 diff --git a/examples/n-body/build/index.asm.js b/examples/n-body/build/index.asm.js index a8431989..745d9a88 100644 --- a/examples/n-body/build/index.asm.js +++ b/examples/n-body/build/index.asm.js @@ -82,7 +82,7 @@ function asmFunc(global, env, buffer) { if ($2 >>> 0 <= 8 >>> 0) return; $4 = (0 - $0 | 0) & 3 | 0; $0 = $0 + $4 | 0; - $1 = Math_imul($1, 16843009); + $1 = Math_imul($1 & 255 | 0, 16843009); HEAP32[$0 >> 2] = $1; $2 = ($2 - $4 | 0) & 4294967292 | 0; HEAP32[(($0 + $2 | 0) - 4 | 0) >> 2] = $1; diff --git a/examples/n-body/build/optimized.wasm b/examples/n-body/build/optimized.wasm index 096ab8bd..140ef9ea 100644 Binary files a/examples/n-body/build/optimized.wasm and b/examples/n-body/build/optimized.wasm differ diff --git a/examples/n-body/build/optimized.wat b/examples/n-body/build/optimized.wat index 4ee6e88b..67a4fc04 100644 --- a/examples/n-body/build/optimized.wat +++ b/examples/n-body/build/optimized.wat @@ -265,7 +265,10 @@ ) (tee_local $1 (i32.mul - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) (i32.const 16843009) ) ) diff --git a/examples/n-body/build/untouched.wat b/examples/n-body/build/untouched.wat index 76031536..2e391e97 100644 --- a/examples/n-body/build/untouched.wat +++ b/examples/n-body/build/untouched.wat @@ -687,8 +687,11 @@ ;;@ ~lib/memory.ts:216:27 (i32.const 255) ) - ;;@ ~lib/memory.ts:216:33 - (get_local $1) + (i32.and + ;;@ ~lib/memory.ts:216:33 + (get_local $1) + (i32.const 255) + ) ) ) ;;@ ~lib/memory.ts:219:2 diff --git a/package-lock.json b/package-lock.json index d496c041..75b67149 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,16 +4,6 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "@mrmlnc/readdir-enhanced": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz", - "integrity": "sha512-bPHp6Ji8b41szTOcaP63VlnbbO5Ny6dwAATtY6JTjh5N2OLrb5Qk/Th5cRkRQhkWCt+EJsYrNB0MiL+Gpn6e3g==", - "dev": true, - "requires": { - "call-me-maybe": "^1.0.1", - "glob-to-regexp": "^0.3.0" - } - }, "@protobufjs/utf8": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", @@ -348,9 +338,9 @@ } }, "babel-core": { - "version": "6.26.3", - "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.3.tgz", - "integrity": "sha512-6jyFLuDmeidKmUEb3NM+/yawG0M2bDZ9Z1qbZP59cyHLz8kYGKYwpJP0UwUKKUiTRNvxfLesJnTedqczP7cTDA==", + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.0.tgz", + "integrity": "sha1-rzL3izGm/O8RnIew/Y2XU/A6C7g=", "dev": true, "requires": { "babel-code-frame": "^6.26.0", @@ -363,15 +353,15 @@ "babel-traverse": "^6.26.0", "babel-types": "^6.26.0", "babylon": "^6.18.0", - "convert-source-map": "^1.5.1", - "debug": "^2.6.9", + "convert-source-map": "^1.5.0", + "debug": "^2.6.8", "json5": "^0.5.1", "lodash": "^4.17.4", "minimatch": "^3.0.4", "path-is-absolute": "^1.0.1", - "private": "^0.1.8", + "private": "^0.1.7", "slash": "^1.0.0", - "source-map": "^0.5.7" + "source-map": "^0.5.6" }, "dependencies": { "babylon": { @@ -838,9 +828,9 @@ } }, "babel-plugin-transform-es2015-modules-commonjs": { - "version": "6.26.2", - "resolved": "https://registry.npmjs.org/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.2.tgz", - "integrity": "sha512-CV9ROOHEdrjcwhIaJNBGMBCodN+1cfkwtM1SbUHmvyy35KGT7fohbpOxkE2uLz1o6odKK2Ck/tz47z+VqQfi9Q==", + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.0.tgz", + "integrity": "sha1-DYOUApt9xqvhqX7xgeAHWN0uXYo=", "dev": true, "requires": { "babel-plugin-transform-strict-mode": "^6.24.1", @@ -1267,9 +1257,9 @@ "dev": true }, "binaryen": { - "version": "47.0.0-nightly.20180503", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-47.0.0-nightly.20180503.tgz", - "integrity": "sha512-kYOHR+3v9iFPHnsbBWXem5c+mYpgWEOvK52KcMa4Af87L1/u89/0A4itry2Y3NKLhiFxx1oIO+k7RDPKG3zV3g==" + "version": "46.0.0-nightly.20180427", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-46.0.0-nightly.20180427.tgz", + "integrity": "sha512-pPG9B3c2n27udyDPkLrhTJcP0ut0fK56RLH/jWUcvAIUMJXgZY3hmxLZMuUiPc2+kERZroKNxpdMf3HRmf/UnQ==" }, "binaryextensions": { "version": "2.1.1", @@ -1504,12 +1494,6 @@ } } }, - "call-me-maybe": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/call-me-maybe/-/call-me-maybe-1.0.1.tgz", - "integrity": "sha1-JtII6onje1y95gJQoV8DHBak1ms=", - "dev": true - }, "camelcase": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", @@ -1783,9 +1767,9 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, "colors": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.2.3.tgz", - "integrity": "sha512-qTfM2pNFeMZcLvf/RbrVAzDEVttZjFhaApfx9dplNjvHSX88Ui66zBRb/4YGob/xUWxDceirgoC1lT676asfCQ==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.2.1.tgz", + "integrity": "sha512-s8+wktIuDSLffCywiwSxQOMqtPxML11a/dtHE17tMn4B1MSWw/C22EKf7M2KGUBcDaVFEGT+S8N02geDXeuNKg==", "dev": true }, "commander": { @@ -2014,9 +1998,9 @@ } }, "deep-extend": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.5.1.tgz", - "integrity": "sha512-N8vBdOa+DF7zkRrDCsaOXoCs/E2fJfx9B9MrKnnSiHNh4ws7eSys6YQE4KvT1cecKmOASYQBhbKjeuDD9lT81w==", + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.4.2.tgz", + "integrity": "sha1-SLaZwn4zS/ifEIkr5DL25MfTSn8=", "dev": true }, "define-property": { @@ -2101,16 +2085,6 @@ "randombytes": "^2.0.0" } }, - "dir-glob": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-2.0.0.tgz", - "integrity": "sha512-37qirFDz8cA5fimp9feo43fSuRo2gHwaIn6dXL8Ber1dGwUosDrGZeCCXq57WnIqE4aQ+u3eQZzsk1yOzhdwag==", - "dev": true, - "requires": { - "arrify": "^1.0.1", - "path-type": "^3.0.0" - } - }, "domain-browser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/domain-browser/-/domain-browser-1.2.0.tgz", @@ -2518,19 +2492,6 @@ "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", "dev": true }, - "fast-glob": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-2.2.1.tgz", - "integrity": "sha512-wSyW1TBK3ia5V+te0rGPXudeMHoUQW6O5Y9oATiaGhpENmEifPDlOdhpsnlj5HoG6ttIvGiY1DdCmI9X2xGMhg==", - "dev": true, - "requires": { - "@mrmlnc/readdir-enhanced": "^2.2.1", - "glob-parent": "^3.1.0", - "is-glob": "^4.0.0", - "merge2": "^1.2.1", - "micromatch": "^3.1.10" - } - }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", @@ -2605,9 +2566,9 @@ } }, "flow-parser": { - "version": "0.71.0", - "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.71.0.tgz", - "integrity": "sha512-rXSvqSBLf8aRI6T3P99jMcUYvZoO1KZcKDkzGJmXvYdNAgRKu7sfGNtxEsn3cX4TgungBuJpX+K8aHRC9/B5MA==", + "version": "0.70.0", + "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.70.0.tgz", + "integrity": "sha512-gGdyVUZWswG5jcINrVDHd3RY4nJptBTAx9mR9thGsrGGmAUR7omgJXQSpR+fXrLtxSTAea3HpAZNU/yzRJc2Cg==", "dev": true }, "flush-write-stream": { @@ -3399,12 +3360,6 @@ } } }, - "glob-to-regexp": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz", - "integrity": "sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs=", - "dev": true - }, "global-modules": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/global-modules/-/global-modules-1.0.0.tgz", @@ -3457,9 +3412,9 @@ } }, "got": { - "version": "8.3.1", - "resolved": "https://registry.npmjs.org/got/-/got-8.3.1.tgz", - "integrity": "sha512-tiLX+bnYm5A56T5N/n9Xo89vMaO1mrS9qoDqj3u/anVooqGozvY/HbXzEpDfbNeKsHCBpK40gSbz8wGYSp3i1w==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/got/-/got-8.3.0.tgz", + "integrity": "sha512-kBNy/S2CGwrYgDSec5KTWGKUvupwkkTVAjIsVFF2shXO13xpZdFP4d4kxa//CLX2tN/rV0aYwK8vY6UKWGn2vQ==", "dev": true, "requires": { "@sindresorhus/is": "^0.7.0", @@ -3741,12 +3696,6 @@ "integrity": "sha1-xg7taebY/bazEEofy8ocGS3FtQE=", "dev": true }, - "ignore": { - "version": "3.3.8", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.8.tgz", - "integrity": "sha512-pUh+xUQQhQzevjRHHFqqcTy0/dP/kS9I8HSrUydhihjuD09W6ldVWFtIrwhXdUJHis3i2rZNqEHpZH/cbinFbg==", - "dev": true - }, "import-local": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/import-local/-/import-local-1.0.0.tgz", @@ -4139,12 +4088,6 @@ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, - "isbinaryfile": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-3.0.2.tgz", - "integrity": "sha1-Sj6XTsDLqQBNP8bN5yCeppNopiE=", - "dev": true - }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -4568,7 +4511,7 @@ }, "onetime": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", "dev": true }, @@ -4679,7 +4622,7 @@ }, "onetime": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", "dev": true }, @@ -4797,17 +4740,16 @@ } }, "mem-fs-editor": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/mem-fs-editor/-/mem-fs-editor-4.0.1.tgz", - "integrity": "sha512-54fptqhSZX1sSYsVVInG2qzUWPPrEv/6qYxHAwXJZQfzDcviJcL+7p/wmupg8SdAOi42m/vilMBemx3D6Sz22g==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mem-fs-editor/-/mem-fs-editor-3.0.2.tgz", + "integrity": "sha1-3Qpuryu4prN3QAZ6pUnrUwEFr58=", "dev": true, "requires": { "commondir": "^1.0.1", - "deep-extend": "^0.5.1", - "ejs": "^2.5.9", + "deep-extend": "^0.4.0", + "ejs": "^2.3.1", "glob": "^7.0.3", - "globby": "^8.0.0", - "isbinaryfile": "^3.0.2", + "globby": "^6.1.0", "mkdirp": "^0.5.0", "multimatch": "^2.0.0", "rimraf": "^2.2.8", @@ -4816,9 +4758,9 @@ }, "dependencies": { "clone": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.1.tgz", - "integrity": "sha1-0hfR6WERjjrJpLi7oyhVU79kfNs=", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", + "integrity": "sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=", "dev": true }, "clone-stats": { @@ -4827,21 +4769,6 @@ "integrity": "sha1-s3gt/4u1R04Yuba/D9/ngvh3doA=", "dev": true }, - "globby": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/globby/-/globby-8.0.1.tgz", - "integrity": "sha512-oMrYrJERnKBLXNLVTqhm3vPEdJ/b2ZE28xN4YARiix1NOIOBPEpOUnm844K1iu/BkphCaf2WNFwMszv8Soi1pw==", - "dev": true, - "requires": { - "array-union": "^1.0.1", - "dir-glob": "^2.0.0", - "fast-glob": "^2.0.2", - "glob": "^7.1.2", - "ignore": "^3.3.5", - "pify": "^3.0.0", - "slash": "^1.0.0" - } - }, "replace-ext": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.0.tgz", @@ -4874,12 +4801,6 @@ "readable-stream": "^2.0.1" } }, - "merge2": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.2.1.tgz", - "integrity": "sha512-wUqcG5pxrAcaFI1lkqkMnk3Q7nUxV/NWfpAFSeWUwG9TRODnBDCUHa75mi3o3vLWQ5N4CQERWCauSlP0I3ZqUg==", - "dev": true - }, "micromatch": { "version": "3.1.10", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz", @@ -5348,7 +5269,7 @@ }, "onetime": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", "dev": true }, @@ -6830,9 +6751,9 @@ } }, "ts-node": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-6.0.2.tgz", - "integrity": "sha512-H/KWK27B3JJAc5WFOBBUxN638DukbV8PptdQgiHWPO2SGDVJzuVOl8Ye0XJ5+FiZIdFtgUuGOJRV4c/XBQ5dBg==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-5.0.1.tgz", + "integrity": "sha512-XK7QmDcNHVmZkVtkiwNDWiERRHPyU8nBqZB1+iv2UhOG0q3RQ9HsZ2CMqISlFbxjrYFGfG2mX7bW4dAyxBVzUw==", "requires": { "arrify": "^1.0.0", "chalk": "^2.3.0", @@ -7417,9 +7338,9 @@ } }, "webpack-cli": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/webpack-cli/-/webpack-cli-2.1.2.tgz", - "integrity": "sha512-2C6bs9gORlzCSgkNZTnj8hnXMxe3g2v+yqiUdB+1l/I3sI36ND4zZStV00yq0eGjE5CNu0eqOQr7YYe+42H2Yw==", + "version": "2.0.15", + "resolved": "https://registry.npmjs.org/webpack-cli/-/webpack-cli-2.0.15.tgz", + "integrity": "sha512-bjNeIUO51D4OsmZ5ufzcpzVoacjxfWNfeBZKYL3jc+EMfCME3TyfdCPSUoKiOnebQChfupQuIRpAnx7L4l3Hew==", "dev": true, "requires": { "chalk": "^2.3.2", @@ -7447,7 +7368,7 @@ "webpack-addons": "^1.1.5", "yargs": "^11.1.0", "yeoman-environment": "^2.0.0", - "yeoman-generator": "^2.0.4" + "yeoman-generator": "^2.0.3" } }, "webpack-sources": { @@ -7670,26 +7591,26 @@ } }, "yeoman-generator": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/yeoman-generator/-/yeoman-generator-2.0.5.tgz", - "integrity": "sha512-rV6tJ8oYzm4mmdF2T3wjY+Q42jKF2YiiD0VKfJ8/0ZYwmhCKC9Xs2346HVLPj/xE13i68psnFJv7iS6gWRkeAg==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/yeoman-generator/-/yeoman-generator-2.0.4.tgz", + "integrity": "sha512-Sgvz3MAkOpEIobcpW3rjEl6bOTNnl8SkibP9z7hYKfIGIlw0QDC2k0MAeXvyE2pLqc2M0Duql+6R7/W9GrJojg==", "dev": true, "requires": { "async": "^2.6.0", "chalk": "^2.3.0", "cli-table": "^0.3.1", - "cross-spawn": "^6.0.5", + "cross-spawn": "^5.1.0", "dargs": "^5.1.0", - "dateformat": "^3.0.3", + "dateformat": "^3.0.2", "debug": "^3.1.0", "detect-conflict": "^1.0.0", "error": "^7.0.2", "find-up": "^2.1.0", "github-username": "^4.0.0", - "istextorbinary": "^2.2.1", - "lodash": "^4.17.10", + "istextorbinary": "^2.1.0", + "lodash": "^4.17.4", "make-dir": "^1.1.0", - "mem-fs-editor": "^4.0.0", + "mem-fs-editor": "^3.0.2", "minimist": "^1.2.0", "pretty-bytes": "^4.0.2", "read-chunk": "^2.1.0", @@ -7711,6 +7632,17 @@ "lodash": "^4.14.0" } }, + "cross-spawn": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", + "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", + "dev": true, + "requires": { + "lru-cache": "^4.0.1", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, "debug": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", @@ -7719,12 +7651,6 @@ "requires": { "ms": "2.0.0" } - }, - "lodash": { - "version": "4.17.10", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", - "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==", - "dev": true } } }, diff --git a/package.json b/package.json index 4f15f987..a06e5a0c 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,11 @@ }, "dependencies": { "@protobufjs/utf8": "^1.1.0", - "binaryen": "47.0.0-nightly.20180503", + "binaryen": "46.0.0-nightly.20180427", "glob": "^7.1.2", "long": "^4.0.0", "minimist": "^1.2.0", - "ts-node": "^6.0.2" + "ts-node": "^5.0.1" }, "devDependencies": { "@types/node": "^9.6.6", @@ -30,7 +30,7 @@ "typedoc-plugin-external-module-name": "^1.1.1", "typescript": "^2.8.3", "webpack": "^4.6.0", - "webpack-cli": "^2.1.2" + "webpack-cli": "^2.0.15" }, "main": "index.js", "types": "index.d.ts", diff --git a/src/builtins.ts b/src/builtins.ts index 687d4bfd..76ce2f41 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -5,7 +5,8 @@ import { Compiler, - ConversionKind + ConversionKind, + WrapMode } from "./compiler"; import { @@ -33,7 +34,12 @@ import { HostOp, NativeType, ExpressionRef, - ExpressionId + ExpressionId, + getExpressionId, + getExpressionType, + getConstValueI64High, + getConstValueI64Low, + getConstValueI32 } from "./module"; import { @@ -151,12 +157,21 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.WRAP); } else { - arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE, WrapMode.WRAP); } switch (compiler.currentType.kind) { - default: { // any integer up to 32-bits incl. bool + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.U8: + case TypeKind.U16: { + ret = module.createUnary(UnaryOp.ClzI32, arg0); + break; + } + case TypeKind.BOOL: // usually overflows + case TypeKind.I32: + case TypeKind.U32: { ret = module.createUnary(UnaryOp.ClzI32, arg0); break; } @@ -185,9 +200,7 @@ export function compileCall( ret = module.createUnary(UnaryOp.ClzI64, arg0); break; } - case TypeKind.F32: - case TypeKind.F64: - case TypeKind.VOID: { + default: { compiler.error( DiagnosticCode.Operation_not_supported, reportNode.range @@ -224,12 +237,21 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.NONE, WrapMode.WRAP); } else { - arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE, WrapMode.WRAP); } switch (compiler.currentType.kind) { - default: { // any integer up to 32-bits incl. bool + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.U8: + case TypeKind.U16: { + ret = module.createUnary(UnaryOp.CtzI32, arg0); + break; + } + case TypeKind.BOOL: // usually overflows + case TypeKind.I32: + case TypeKind.U32: { ret = module.createUnary(UnaryOp.CtzI32, arg0); break; } @@ -258,9 +280,7 @@ export function compileCall( ret = module.createUnary(UnaryOp.CtzI64, arg0); break; } - case TypeKind.F32: - case TypeKind.F64: - case TypeKind.VOID: { + default: { compiler.error( DiagnosticCode.Operation_not_supported, reportNode.range @@ -297,12 +317,21 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.WRAP); } else { - arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE, WrapMode.WRAP); } switch (compiler.currentType.kind) { - default: { // any integer up to 32-bits incl. bool + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.U8: + case TypeKind.U16: { + ret = module.createUnary(UnaryOp.PopcntI32, arg0); + break; + } + case TypeKind.BOOL: // usually overflows + case TypeKind.I32: + case TypeKind.U32: { ret = module.createUnary(UnaryOp.PopcntI32, arg0); break; } @@ -331,9 +360,7 @@ export function compileCall( ret = module.createUnary(UnaryOp.PopcntI64, arg0); break; } - case TypeKind.F32: - case TypeKind.F64: - case TypeKind.VOID: { + default: { compiler.error( DiagnosticCode.Operation_not_supported, reportNode.range @@ -370,18 +397,18 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.WRAP); } else { - arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE, WrapMode.WRAP); } - arg1 = compiler.compileExpression(operands[1], compiler.currentType); + arg1 = compiler.compileExpression(operands[1], compiler.currentType, ConversionKind.IMPLICIT, WrapMode.NONE); switch (compiler.currentType.kind) { case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: case TypeKind.U16: case TypeKind.BOOL: { - ret = compiler.makeSmallIntegerWrap( + ret = compiler.ensureSmallIntegerWrap( module.createBinary(BinaryOp.RotlI32, arg0, arg1), compiler.currentType ); @@ -427,7 +454,7 @@ export function compileCall( break; } } - return ret; + return ret; // possibly overflows } case "rotr": { // rotr(value: T, shift: T) -> T if (operands.length != 2) { @@ -455,18 +482,18 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.WRAP); } else { - arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE, WrapMode.WRAP); } - arg1 = compiler.compileExpression(operands[1], compiler.currentType); + arg1 = compiler.compileExpression(operands[1], compiler.currentType, ConversionKind.IMPLICIT, WrapMode.NONE); switch (compiler.currentType.kind) { case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: case TypeKind.U16: case TypeKind.BOOL: { - ret = compiler.makeSmallIntegerWrap( + ret = compiler.ensureSmallIntegerWrap( module.createBinary(BinaryOp.RotrI32, arg0, arg1), compiler.currentType ); @@ -512,7 +539,7 @@ export function compileCall( break; } } - return ret; + return ret; // possibly overflowws } case "abs": { // abs(value: T) -> T if (operands.length != 1) { @@ -540,18 +567,17 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.WRAP); } else { - arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE, WrapMode.WRAP); } switch (compiler.currentType.kind) { case TypeKind.I8: case TypeKind.I16: - // doesn't need sign-extension here because ifFalse below is either positive - // or MIN_VALUE (-MIN_VALUE == MIN_VALUE) if selected case TypeKind.I32: { - let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.i32); - ret = module.createSelect( + // possibly overflows, e.g. abs(-128) == 128 + let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.i32, false); + ret = module.createSelect( // x > 0 ? x : 0-x module.createTeeLocal(tempLocal.index, arg0), module.createBinary(BinaryOp.SubI32, // ifFalse module.createI32(0), @@ -565,7 +591,7 @@ export function compileCall( break; } case TypeKind.ISIZE: { - let tempLocal = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType); + let tempLocal = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType, false); ret = module.createSelect( module.createTeeLocal(tempLocal.index, arg0), module.createBinary( @@ -586,7 +612,7 @@ export function compileCall( break; } case TypeKind.I64: { - let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.i64); + let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.i64, false); ret = module.createSelect( module.createTeeLocal(tempLocal.index, arg0), module.createBinary(BinaryOp.SubI64, @@ -668,17 +694,24 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.WRAP); } else { - arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE, WrapMode.WRAP); } - arg1 = compiler.compileExpression(operands[1], compiler.currentType); + arg1 = compiler.compileExpression(operands[1], compiler.currentType, ConversionKind.IMPLICIT, WrapMode.WRAP); switch (compiler.currentType.kind) { case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: { - let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i32); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i32); + let flow = compiler.currentFunction.flow; + let tempLocal0 = compiler.currentFunction.getTempLocal( + compiler.currentType, + !flow.canOverflow(arg0, compiler.currentType) + ); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal( + compiler.currentType, + !flow.canOverflow(arg1, compiler.currentType) + ); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -694,8 +727,15 @@ export function compileCall( case TypeKind.U16: case TypeKind.U32: case TypeKind.BOOL: { - let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i32); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i32); + let flow = compiler.currentFunction.flow; + let tempLocal0 = compiler.currentFunction.getTempLocal( + compiler.currentType, + !flow.canOverflow(arg0, compiler.currentType) + ); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal( + compiler.currentType, + !flow.canOverflow(arg1, compiler.currentType) + ); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -708,8 +748,8 @@ export function compileCall( break; } case TypeKind.I64: { - let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i64); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i64); + let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i64, false); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i64, false); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -722,8 +762,8 @@ export function compileCall( break; } case TypeKind.U64: { - let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i64); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i64); + let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i64, false); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i64, false); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -736,8 +776,8 @@ export function compileCall( break; } case TypeKind.ISIZE: { - let tempLocal0 = compiler.currentFunction.getTempLocal(compiler.options.usizeType); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType); + let tempLocal0 = compiler.currentFunction.getTempLocal(compiler.options.usizeType, false); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType, false); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -761,8 +801,8 @@ export function compileCall( ret = module.createUnreachable(); break; } - let tempLocal0 = compiler.currentFunction.getTempLocal(compiler.options.usizeType); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType); + let tempLocal0 = compiler.currentFunction.getTempLocal(compiler.options.usizeType, false); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType, false); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -822,17 +862,24 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.WRAP); } else { - arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE, WrapMode.WRAP); } - arg1 = compiler.compileExpression(operands[1], compiler.currentType); + arg1 = compiler.compileExpression(operands[1], compiler.currentType, ConversionKind.IMPLICIT, WrapMode.WRAP); switch (compiler.currentType.kind) { case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: { - let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i32); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i32); + let flow = compiler.currentFunction.flow; + let tempLocal0 = compiler.currentFunction.getTempLocal( + compiler.currentType, + !flow.canOverflow(arg0, compiler.currentType) + ); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal( + compiler.currentType, + !flow.canOverflow(arg1, compiler.currentType) + ); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -848,8 +895,15 @@ export function compileCall( case TypeKind.U16: case TypeKind.U32: case TypeKind.BOOL: { - let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i32); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i32); + let flow = compiler.currentFunction.flow; + let tempLocal0 = compiler.currentFunction.getTempLocal( + compiler.currentType, + !flow.canOverflow(arg0, compiler.currentType) + ); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal( + compiler.currentType, + !flow.canOverflow(arg1, compiler.currentType) + ); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -862,8 +916,8 @@ export function compileCall( break; } case TypeKind.I64: { - let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i64); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i64); + let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i64, false); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i64, false); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -876,8 +930,8 @@ export function compileCall( break; } case TypeKind.U64: { - let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i64); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i64); + let tempLocal0 = compiler.currentFunction.getTempLocal(Type.i64, false); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(Type.i64, false); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -890,8 +944,8 @@ export function compileCall( break; } case TypeKind.ISIZE: { - let tempLocal0 = compiler.currentFunction.getTempLocal(compiler.options.usizeType); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType); + let tempLocal0 = compiler.currentFunction.getTempLocal(compiler.options.usizeType, false); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType, false); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -915,8 +969,8 @@ export function compileCall( ret = module.createUnreachable(); break; } - let tempLocal0 = compiler.currentFunction.getTempLocal(compiler.options.usizeType); - let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType); + let tempLocal0 = compiler.currentFunction.getTempLocal(compiler.options.usizeType, false); + let tempLocal1 = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType, false); compiler.currentFunction.freeTempLocal(tempLocal0); ret = module.createSelect( module.createTeeLocal(tempLocal0.index, arg0), @@ -976,9 +1030,9 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.NONE); } else { - arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE, WrapMode.NONE); } switch (compiler.currentType.kind) { case TypeKind.USIZE: { @@ -1041,9 +1095,9 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.NONE); } else { - arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE, WrapMode.NONE); } switch (compiler.currentType.kind) { case TypeKind.USIZE: { @@ -1106,11 +1160,11 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.NONE); } else { - arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE, WrapMode.NONE); } - arg1 = compiler.compileExpression(operands[1], compiler.currentType); + arg1 = compiler.compileExpression(operands[1], compiler.currentType, ConversionKind.IMPLICIT, WrapMode.NONE); switch (compiler.currentType.kind) { // TODO: does an integer version make sense? case TypeKind.F32: { ret = module.createBinary(BinaryOp.CopysignF32, arg0, arg1); @@ -1157,9 +1211,9 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.NONE); } else { - arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE, WrapMode.NONE); } switch (compiler.currentType.kind) { case TypeKind.USIZE: { @@ -1222,13 +1276,13 @@ export function compileCall( switch (typeArguments[0].kind) { case TypeKind.I32: case TypeKind.U32: { - arg0 = compiler.compileExpression(operands[0], Type.f32); + arg0 = compiler.compileExpression(operands[0], Type.f32, ConversionKind.IMPLICIT, WrapMode.NONE); ret = module.createUnary(UnaryOp.ReinterpretF32, arg0); break; } case TypeKind.I64: case TypeKind.U64: { - arg0 = compiler.compileExpression(operands[0], Type.f64); + arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.IMPLICIT, WrapMode.NONE); ret = module.createUnary(UnaryOp.ReinterpretF64, arg0); break; } @@ -1248,8 +1302,10 @@ export function compileCall( operands[0], compiler.options.isWasm64 ? Type.f64 - : Type.f32 - ); + : Type.f32, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); ret = module.createUnary( compiler.options.isWasm64 ? UnaryOp.ReinterpretF64 @@ -1259,12 +1315,12 @@ export function compileCall( break; } case TypeKind.F32: { - arg0 = compiler.compileExpression(operands[0], Type.u32); + arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.IMPLICIT, WrapMode.NONE); ret = module.createUnary(UnaryOp.ReinterpretI32, arg0); break; } case TypeKind.F64: { - arg0 = compiler.compileExpression(operands[0], Type.u64); + arg0 = compiler.compileExpression(operands[0], Type.i64, ConversionKind.IMPLICIT, WrapMode.NONE); ret = module.createUnary(UnaryOp.ReinterpretI64, arg0); break; } @@ -1306,9 +1362,9 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.NONE); } else { - arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE, WrapMode.NONE); } switch (compiler.currentType.kind) { // TODO: integer versions (that return f64 or convert)? case TypeKind.F32: { @@ -1358,9 +1414,9 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.NONE); } else { - arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE); + arg0 = compiler.compileExpression(operands[0], Type.f64, ConversionKind.NONE, WrapMode.NONE); } switch (compiler.currentType.kind) { case TypeKind.USIZE: { @@ -1430,7 +1486,12 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType); + arg0 = compiler.compileExpression( + operands[0], + compiler.options.usizeType, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); let offset = operands.length == 2 ? evaluateConstantOffset(compiler, operands[1]) : 0; // reports if (offset < 0) { // reported in evaluateConstantOffset return module.createUnreachable(); @@ -1477,24 +1538,33 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType); + arg0 = compiler.compileExpression( + operands[0], + compiler.options.usizeType, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); arg1 = compiler.compileExpression( operands[1], typeArguments[0], typeArguments[0].is(TypeFlags.INTEGER) - ? ConversionKind.NONE // wraps a larger integer type to a smaller one, i.e. i32.store8 - : ConversionKind.IMPLICIT + ? ConversionKind.NONE // no need to convert to small int (but now might result in a float) + : ConversionKind.IMPLICIT, + WrapMode.NONE ); let type: Type; if ( - compiler.currentType.is(TypeFlags.INTEGER) && typeArguments[0].is(TypeFlags.INTEGER) && - typeArguments[0].size > compiler.currentType.size + ( + !compiler.currentType.is(TypeFlags.INTEGER) || // float to int + compiler.currentType.size < typeArguments[0].size // int to larger int (clear garbage bits) + ) ) { arg1 = compiler.convertExpression( arg1, compiler.currentType, typeArguments[0], ConversionKind.IMPLICIT, + WrapMode.NONE, // still clears garbage bits operands[1] ); type = typeArguments[0]; @@ -1701,16 +1771,27 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.NONE); } else { - arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.NONE); + arg0 = compiler.compileExpressionRetainType(operands[0], Type.i32, WrapMode.NONE); } let type = compiler.currentType; - arg1 = compiler.compileExpression(operands[1], type); - arg2 = compiler.compileExpression(operands[2], Type.i32); + arg1 = compiler.compileExpression(operands[1], type, ConversionKind.IMPLICIT, WrapMode.NONE); + arg2 = compiler.makeIsTrueish( + compiler.compileExpressionRetainType(operands[2], Type.bool, WrapMode.NONE), + compiler.currentType + ); compiler.currentType = type; switch (compiler.currentType.kind) { - default: { // any value type + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.U8: + case TypeKind.U16: + case TypeKind.BOOL: { + ret = module.createSelect(arg0, arg1, arg2); + break; + } + default: { // any other value type ret = module.createSelect(arg0, arg1, arg2); break; } @@ -1768,7 +1849,7 @@ export function compileCall( ); arg0 = module.createUnreachable(); } else { - arg0 = compiler.compileExpression(operands[0], Type.i32); + arg0 = compiler.compileExpression(operands[0], Type.i32, ConversionKind.IMPLICIT, WrapMode.NONE); } if (typeArguments) { compiler.error( @@ -1794,14 +1875,29 @@ export function compileCall( compiler.currentType = Type.void; return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType); - arg1 = compiler.compileExpression(operands[1], compiler.options.usizeType); - arg2 = compiler.compileExpression(operands[2], compiler.options.usizeType); + arg0 = compiler.compileExpression( + operands[0], + compiler.options.usizeType, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); + arg1 = compiler.compileExpression( + operands[1], + compiler.options.usizeType, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); + arg2 = compiler.compileExpression( + operands[2], + compiler.options.usizeType, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); compiler.currentType = Type.void; throw new Error("not implemented"); // return module.createHost(HostOp.MoveMemory, null, [ arg0, arg1, arg2 ]); } - case "set_memory": { // set_memory(dest: usize, value: u32, n: usize) -> void + case "set_memory": { // set_memory(dest: usize, value: u8, n: usize) -> void if (typeArguments) { compiler.error( DiagnosticCode.Type_0_is_not_generic, @@ -1816,9 +1912,24 @@ export function compileCall( compiler.currentType = Type.void; return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], compiler.options.usizeType); - arg1 = compiler.compileExpression(operands[1], Type.u32); - arg2 = compiler.compileExpression(operands[2], compiler.options.usizeType); + arg0 = compiler.compileExpression( + operands[0], + compiler.options.usizeType, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); + arg1 = compiler.compileExpression( + operands[1], + Type.u32, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); + arg2 = compiler.compileExpression( + operands[2], + compiler.options.usizeType, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); compiler.currentType = Type.void; throw new Error("not implemented"); // return module.createHost(HostOp.SetMemory, null, [ arg0, arg1, arg2 ]); @@ -1850,10 +1961,10 @@ export function compileCall( compiler.currentType = typeArguments[0]; return module.createUnreachable(); } - arg0 = compiler.compileExpression( + arg0 = compiler.compileExpressionRetainType( operands[0], compiler.options.usizeType, - ConversionKind.NONE + WrapMode.NONE ); compiler.currentType = typeArguments[0]; if (compiler.currentType.kind != TypeKind.USIZE) { @@ -1900,9 +2011,9 @@ export function compileCall( ); return module.createUnreachable(); } - arg0 = compiler.compileExpression(operands[0], typeArguments[0]); + arg0 = compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.WRAP); } else { - arg0 = compiler.compileExpressionRetainType(operands[0], Type.i32); + arg0 = compiler.compileExpressionRetainType(operands[0], Type.bool, WrapMode.WRAP); } let type = compiler.currentType; @@ -1988,20 +2099,37 @@ export function compileCall( compiler.currentType = Type.void; } else { switch (compiler.currentType.kind) { - default: { // any integer up to 32-bits incl. bool - let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.i32); + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.U8: + case TypeKind.U16: + case TypeKind.BOOL: { + let flow = compiler.currentFunction.flow; + let tempLocal = compiler.currentFunction.getAndFreeTempLocal( + compiler.currentType, + !flow.canOverflow(arg0, compiler.currentType) + ); ret = module.createIf( - module.createUnary(UnaryOp.EqzI32, - module.createTeeLocal(tempLocal.index, arg0) - ), - abort, - module.createGetLocal(tempLocal.index, NativeType.I32) + module.createTeeLocal(tempLocal.index, arg0), + module.createGetLocal(tempLocal.index, NativeType.I32), + abort + ); + break; + } + case TypeKind.I32: + case TypeKind.U32: + default: { + let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.i32, false); + ret = module.createIf( + module.createTeeLocal(tempLocal.index, arg0), + module.createGetLocal(tempLocal.index, NativeType.I32), + abort ); break; } case TypeKind.I64: case TypeKind.U64: { - let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.i64); + let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.i64, false); ret = module.createIf( module.createUnary(UnaryOp.EqzI64, module.createTeeLocal(tempLocal.index, arg0) @@ -2013,7 +2141,7 @@ export function compileCall( } case TypeKind.ISIZE: case TypeKind.USIZE: { - let tempLocal = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType); + let tempLocal = compiler.currentFunction.getAndFreeTempLocal(compiler.options.usizeType, false); ret = module.createIf( module.createUnary( compiler.options.isWasm64 @@ -2027,7 +2155,7 @@ export function compileCall( break; } case TypeKind.F32: { - let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.f32); + let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.f32, false); ret = module.createIf( module.createBinary(BinaryOp.EqF32, module.createTeeLocal(tempLocal.index, arg0), @@ -2039,7 +2167,7 @@ export function compileCall( break; } case TypeKind.F64: { - let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.f64); + let tempLocal = compiler.currentFunction.getAndFreeTempLocal(Type.f64, false); ret = module.createIf( module.createBinary(BinaryOp.EqF64, module.createTeeLocal(tempLocal.index, arg0), @@ -2078,7 +2206,7 @@ export function compileCall( } let flow = compiler.currentFunction.flow; flow.set(FlowFlags.UNCHECKED_CONTEXT); - ret = compiler.compileExpressionRetainType(operands[0], contextualType, false); + ret = compiler.compileExpressionRetainType(operands[0], contextualType, WrapMode.NONE); flow.unset(FlowFlags.UNCHECKED_CONTEXT); return ret; } @@ -2100,7 +2228,12 @@ export function compileCall( compiler.currentType = Type.i8; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.i8, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.i8, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } case "i16": { if (typeArguments) { @@ -2117,7 +2250,12 @@ export function compileCall( compiler.currentType = Type.i16; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.i16, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.i16, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } case "i32": { if (typeArguments) { @@ -2134,7 +2272,12 @@ export function compileCall( compiler.currentType = Type.i32; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.i32, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.i32, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } case "i64": { if (typeArguments) { @@ -2151,7 +2294,12 @@ export function compileCall( compiler.currentType = Type.i64; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.i64, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.i64, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } case "isize": { if (typeArguments) { @@ -2175,7 +2323,8 @@ export function compileCall( compiler.options.isWasm64 ? Type.isize64 : Type.isize32, - ConversionKind.EXPLICIT + ConversionKind.EXPLICIT, + WrapMode.NONE ); } case "u8": { @@ -2193,7 +2342,12 @@ export function compileCall( compiler.currentType = Type.u8; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.u8, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.u8, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } case "u16": { if (typeArguments) { @@ -2210,7 +2364,12 @@ export function compileCall( compiler.currentType = Type.u16; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.u16, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.u16, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } case "u32": { if (typeArguments) { @@ -2227,7 +2386,12 @@ export function compileCall( compiler.currentType = Type.u32; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.u32, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.u32, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } case "u64": { if (typeArguments) { @@ -2244,7 +2408,12 @@ export function compileCall( compiler.currentType = Type.u64; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.u64, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.u64, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } case "usize": { if (typeArguments) { @@ -2264,7 +2433,8 @@ export function compileCall( return compiler.compileExpression( operands[0], compiler.options.usizeType, - ConversionKind.EXPLICIT + ConversionKind.EXPLICIT, + WrapMode.NONE ); } case "bool": { @@ -2282,7 +2452,12 @@ export function compileCall( compiler.currentType = Type.bool; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.bool, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.bool, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } case "f32": { if (typeArguments) { @@ -2299,7 +2474,12 @@ export function compileCall( compiler.currentType = Type.f32; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.f32, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.f32, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } case "f64": { if (typeArguments) { @@ -2316,7 +2496,12 @@ export function compileCall( compiler.currentType = Type.f64; return module.createUnreachable(); } - return compiler.compileExpression(operands[0], Type.f64, ConversionKind.EXPLICIT); + return compiler.compileExpression( + operands[0], + Type.f64, + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } } var expr = deferASMCall(compiler, prototype, operands, contextualType, reportNode); @@ -2460,7 +2645,7 @@ function evaluateConstantType( if (operands.length == 1) { // optional type argument if (typeArguments) { if (typeArguments.length == 1) { - compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, false); + compiler.compileExpression(operands[0], typeArguments[0], ConversionKind.IMPLICIT, WrapMode.NONE); } else { if (typeArguments.length) { compiler.error( @@ -2469,10 +2654,10 @@ function evaluateConstantType( ); return null; } - compiler.compileExpressionRetainType(operands[0], Type.i32, false); + compiler.compileExpressionRetainType(operands[0], Type.i32, WrapMode.NONE); } } else { - compiler.compileExpressionRetainType(operands[0], Type.i32, false); + compiler.compileExpressionRetainType(operands[0], Type.i32, WrapMode.NONE); } return compiler.currentType; } @@ -2494,12 +2679,12 @@ function evaluateConstantOffset(compiler: Compiler, expression: Expression): i32 var expr: ExpressionRef; var value: i32; if (compiler.options.isWasm64) { - expr = compiler.precomputeExpression(expression, Type.usize64); + expr = compiler.precomputeExpression(expression, Type.usize64, ConversionKind.IMPLICIT, WrapMode.NONE); if ( - _BinaryenExpressionGetId(expr) != ExpressionId.Const || - _BinaryenExpressionGetType(expr) != NativeType.I64 || - _BinaryenConstGetValueI64High(expr) != 0 || - (value = _BinaryenConstGetValueI64Low(expr)) < 0 + getExpressionId(expr) != ExpressionId.Const || + getExpressionType(expr) != NativeType.I64 || + getConstValueI64High(expr) != 0 || + (value = getConstValueI64Low(expr)) < 0 ) { compiler.error( DiagnosticCode.Operation_not_supported, @@ -2508,11 +2693,11 @@ function evaluateConstantOffset(compiler: Compiler, expression: Expression): i32 value = -1; } } else { - expr = compiler.precomputeExpression(expression, Type.usize32); + expr = compiler.precomputeExpression(expression, Type.usize32, ConversionKind.IMPLICIT, WrapMode.NONE); if ( - _BinaryenExpressionGetId(expr) != ExpressionId.Const || - _BinaryenExpressionGetType(expr) != NativeType.I32 || - (value = _BinaryenConstGetValueI32(expr)) < 0 + getExpressionId(expr) != ExpressionId.Const || + getExpressionType(expr) != NativeType.I32 || + (value = getConstValueI32(expr)) < 0 ) { compiler.error( DiagnosticCode.Operation_not_supported, @@ -2588,7 +2773,7 @@ export function compileAbort( if (!(abortInstance && compiler.compileFunction(abortInstance))) return module.createUnreachable(); var messageArg = message != null - ? compiler.compileExpression(message, stringType) + ? compiler.compileExpression(message, stringType, ConversionKind.IMPLICIT, WrapMode.NONE) : stringType.toNativeZero(module); var filenameArg = compiler.compileStaticString(reportNode.range.source.normalizedPath); diff --git a/src/compiler.ts b/src/compiler.ts index af2a7645..918586e2 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -24,7 +24,16 @@ import { FunctionRef, ExpressionId, FunctionTypeRef, - GlobalRef + GlobalRef, + getExpressionId, + getExpressionType, + getConstValueI32, + getConstValueI64Low, + getConstValueI64High, + getConstValueF32, + getConstValueF64, + getFunctionBody, + getGetLocalIndex } from "./module"; import { @@ -196,6 +205,14 @@ export const enum ConversionKind { EXPLICIT } +/** Indicates the desired wrap mode of a conversion. */ +export const enum WrapMode { + /** No wrapping. */ + NONE, + /** Wrap small integer values. */ + WRAP +} + /** Compiler interface. */ export class Compiler extends DiagnosticEmitter { @@ -485,7 +502,8 @@ export class Compiler extends DiagnosticEmitter { initExpr = this.compileExpression( // reports declaration.initializer, Type.void, - ConversionKind.NONE + ConversionKind.NONE, + WrapMode.WRAP ); if (this.currentType == Type.void) { this.error( @@ -555,16 +573,21 @@ export class Compiler extends DiagnosticEmitter { // evaluate initializer if present if (declaration && declaration.initializer) { if (!initExpr) { - initExpr = this.compileExpression(declaration.initializer, global.type); + initExpr = this.compileExpression( + declaration.initializer, + global.type, + ConversionKind.IMPLICIT, + WrapMode.WRAP + ); } // check if the initializer is constant - if (_BinaryenExpressionGetId(initExpr) != ExpressionId.Const) { + if (getExpressionId(initExpr) != ExpressionId.Const) { // if a constant global, check if the initializer becomes constant after precompute if (isConstant) { initExpr = this.precomputeExpressionRef(initExpr); - if (_BinaryenExpressionGetId(initExpr) != ExpressionId.Const) { + if (getExpressionId(initExpr) != ExpressionId.Const) { this.warning( DiagnosticCode.Compiling_constant_with_non_constant_initializer_as_mutable, declaration.range @@ -591,37 +614,33 @@ export class Compiler extends DiagnosticEmitter { } else { // compile as-is if (isConstant) { - let exprType = _BinaryenExpressionGetType(initExpr); + let exprType = getExpressionType(initExpr); switch (exprType) { case NativeType.I32: { global.constantValueKind = ConstantValueKind.INTEGER; - global.constantIntegerValue = i64_new(_BinaryenConstGetValueI32(initExpr), 0); + global.constantIntegerValue = i64_new(getConstValueI32(initExpr), 0); break; } case NativeType.I64: { global.constantValueKind = ConstantValueKind.INTEGER; global.constantIntegerValue = i64_new( - _BinaryenConstGetValueI64Low(initExpr), - _BinaryenConstGetValueI64High(initExpr) + getConstValueI64Low(initExpr), + getConstValueI64High(initExpr) ); break; } case NativeType.F32: { global.constantValueKind = ConstantValueKind.FLOAT; - global.constantFloatValue = _BinaryenConstGetValueF32(initExpr); + global.constantFloatValue = getConstValueF32(initExpr); break; } case NativeType.F64: { global.constantValueKind = ConstantValueKind.FLOAT; - global.constantFloatValue = _BinaryenConstGetValueF64(initExpr); + global.constantFloatValue = getConstValueF64(initExpr); break; } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - assert(global.declaration).range - ); return false; } } @@ -676,10 +695,15 @@ export class Compiler extends DiagnosticEmitter { } else { let initExpr: ExpressionRef; if (valueDeclaration.value) { - initExpr = this.compileExpression(valueDeclaration.value, Type.i32); - if (_BinaryenExpressionGetId(initExpr) != ExpressionId.Const) { + initExpr = this.compileExpression( + valueDeclaration.value, + Type.i32, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); + if (getExpressionId(initExpr) != ExpressionId.Const) { initExpr = this.precomputeExpressionRef(initExpr); - if (_BinaryenExpressionGetId(initExpr) != ExpressionId.Const) { + if (getExpressionId(initExpr) != ExpressionId.Const) { if (element.is(CommonFlags.CONST)) { this.warning( DiagnosticCode.Compiling_constant_with_non_constant_initializer_as_mutable, @@ -717,15 +741,11 @@ export class Compiler extends DiagnosticEmitter { this.startFunctionBody.push(module.createSetGlobal(val.internalName, initExpr)); } else { module.addGlobal(val.internalName, NativeType.I32, false, initExpr); - if (_BinaryenExpressionGetType(initExpr) == NativeType.I32) { - val.constantValue = _BinaryenConstGetValueI32(initExpr); + if (getExpressionType(initExpr) == NativeType.I32) { + val.constantValue = getConstValueI32(initExpr); val.set(CommonFlags.INLINED); } else { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - valueDeclaration.range - ); val.constantValue = 0; } } @@ -859,8 +879,14 @@ export class Compiler extends DiagnosticEmitter { if (body.kind == NodeKind.EXPRESSION) { // () => expression assert(!instance.isAny(CommonFlags.CONSTRUCTOR | CommonFlags.GET | CommonFlags.SET)); assert(instance.is(CommonFlags.ARROW)); - stmt = this.compileExpression((body).expression, returnType); + stmt = this.compileExpression( + (body).expression, + returnType, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); flow.set(FlowFlags.RETURNS); + if (!flow.canOverflow(stmt, returnType)) flow.set(FlowFlags.RETURNS_WRAPPED); } else { assert(body.kind == NodeKind.BLOCK); stmt = this.compileStatement(body); @@ -993,14 +1019,7 @@ export class Compiler extends DiagnosticEmitter { } break; } - default: { - assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - member.range - ); - break; - } + default: assert(false); } } } @@ -1412,13 +1431,8 @@ export class Compiler extends DiagnosticEmitter { // otherwise fall-through } default: { - this.error( - DiagnosticCode.Operation_not_supported, - statement.range - ); assert(false); expr = module.createUnreachable(); - break; } } if (this.options.sourceMap) this.addDebugLocation(expr, statement.range); @@ -1442,20 +1456,15 @@ export class Compiler extends DiagnosticEmitter { // optimizer. // Not actually a branch, but can contain its own scoped variables. - var flow = this.currentFunction.flow.enterBranchOrScope(); - this.currentFunction.flow = flow; + var blockFlow = this.currentFunction.flow.enterBranchOrScope(); + this.currentFunction.flow = blockFlow; var stmt = this.module.createBlock(null, this.compileStatements(statements), NativeType.None); - var stmtReturns = flow.is(FlowFlags.RETURNS); - var stmtThrows = flow.is(FlowFlags.THROWS); - var stmtAllocates = flow.is(FlowFlags.ALLOCATES); // Switch back to the parent flow - flow = flow.leaveBranchOrScope(); - this.currentFunction.flow = flow; - if (stmtReturns) flow.set(FlowFlags.RETURNS); - if (stmtThrows) flow.set(FlowFlags.THROWS); - if (stmtAllocates) flow.set(FlowFlags.ALLOCATES); + var parentFlow = blockFlow.leaveBranchOrScope(); + this.currentFunction.flow = parentFlow; + parentFlow.inherit(blockFlow); return stmt; } @@ -1528,7 +1537,7 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; var condExpr = this.makeIsTrueish( - this.compileExpression(statement.condition, Type.i32, ConversionKind.NONE), + this.compileExpression(statement.condition, Type.i32, ConversionKind.NONE, WrapMode.NONE), this.currentType ); @@ -1550,7 +1559,7 @@ export class Compiler extends DiagnosticEmitter { } compileExpressionStatement(statement: ExpressionStatement): ExpressionRef { - var expr = this.compileExpression(statement.expression, Type.void, ConversionKind.NONE); + var expr = this.compileExpression(statement.expression, Type.void, ConversionKind.NONE, WrapMode.NONE); if (this.currentType != Type.void) { expr = this.module.createDrop(expr); this.currentType = Type.void; @@ -1577,19 +1586,24 @@ export class Compiler extends DiagnosticEmitter { ? this.compileStatement(statement.initializer) : module.createNop(); var condition = statement.condition - ? this.compileExpression(statement.condition, Type.i32) + ? this.makeIsTrueish( + this.compileExpressionRetainType(statement.condition, Type.bool, WrapMode.NONE), + this.currentType + ) : module.createI32(1); var incrementor = statement.incrementor - ? this.compileExpression(statement.incrementor, Type.void) + ? this.compileExpression(statement.incrementor, Type.void, ConversionKind.IMPLICIT, WrapMode.NONE) : module.createNop(); var body = this.compileStatement(statement.statement); var alwaysReturns = !statement.condition && flow.is(FlowFlags.RETURNS); + var alwaysReturnsWrapped = !statement.condition && flow.is(FlowFlags.RETURNS_WRAPPED); var alwaysThrows = !statement.condition && flow.is(FlowFlags.THROWS); var alwaysAllocates = !statement.condition && flow.is(FlowFlags.ALLOCATES); // TODO: check other always-true conditions as well, not just omitted if (alwaysReturns) flow.set(FlowFlags.RETURNS); + if (alwaysReturnsWrapped) flow.set(FlowFlags.RETURNS_WRAPPED); if (alwaysThrows) flow.set(FlowFlags.THROWS); if (alwaysAllocates) flow.set(FlowFlags.ALLOCATES); @@ -1626,7 +1640,7 @@ export class Compiler extends DiagnosticEmitter { // The condition doesn't initiate a branch yet var condExpr = this.makeIsTrueish( - this.compileExpression(statement.condition, Type.i32, ConversionKind.NONE), + this.compileExpressionRetainType(statement.condition, Type.bool, WrapMode.NONE), this.currentType ); @@ -1637,10 +1651,10 @@ export class Compiler extends DiagnosticEmitter { // Try to eliminate unnecesssary branches if the condition is constant let condExprPrecomp = this.precomputeExpressionRef(condExpr); if ( - _BinaryenExpressionGetId(condExprPrecomp) == ExpressionId.Const && - _BinaryenExpressionGetType(condExprPrecomp) == NativeType.I32 + getExpressionId(condExprPrecomp) == ExpressionId.Const && + getExpressionType(condExprPrecomp) == NativeType.I32 ) { - return _BinaryenConstGetValueI32(condExprPrecomp) + return getConstValueI32(condExprPrecomp) ? this.compileStatement(ifTrue) : ifFalse ? this.compileStatement(ifFalse) @@ -1649,72 +1663,59 @@ export class Compiler extends DiagnosticEmitter { // Otherwise recompile to the original and let the optimizer decide } else /* if (condExpr != condExprPrecomp) <- not guaranteed */ { condExpr = this.makeIsTrueish( - this.compileExpression(statement.condition, Type.i32, ConversionKind.NONE), + this.compileExpressionRetainType(statement.condition, Type.bool, WrapMode.NONE), this.currentType ); } } // Each arm initiates a branch - var flow = currentFunction.flow.enterBranchOrScope(); - currentFunction.flow = flow; + var ifTrueFlow = currentFunction.flow.enterBranchOrScope(); + currentFunction.flow = ifTrueFlow; var ifTrueExpr = this.compileStatement(ifTrue); - var ifTrueReturns = flow.is(FlowFlags.RETURNS); - var ifTrueThrows = flow.is(FlowFlags.THROWS); - var ifTrueAllocates = flow.is(FlowFlags.ALLOCATES); - flow = flow.leaveBranchOrScope(); - currentFunction.flow = flow; + currentFunction.flow = ifTrueFlow.leaveBranchOrScope(); + var ifFalseFlow: Flow | null; var ifFalseExpr: ExpressionRef = 0; - var ifFalseReturns = false; - var ifFalseThrows = false; - var ifFalseAllocates = false; if (ifFalse) { - flow = flow.enterBranchOrScope(); - currentFunction.flow = flow; + ifFalseFlow = currentFunction.flow.enterBranchOrScope(); + currentFunction.flow = ifFalseFlow; ifFalseExpr = this.compileStatement(ifFalse); - ifFalseReturns = flow.is(FlowFlags.RETURNS); - ifFalseThrows = flow.is(FlowFlags.THROWS); - ifFalseAllocates = flow.is(FlowFlags.ALLOCATES); - flow = flow.leaveBranchOrScope(); - currentFunction.flow = flow; + let parentFlow = ifFalseFlow.leaveBranchOrScope(); + currentFunction.flow = parentFlow; + parentFlow.inheritMutual(ifTrueFlow, ifFalseFlow); } - - if (ifTrueReturns && ifFalseReturns) flow.set(FlowFlags.RETURNS); - if (ifTrueThrows && ifFalseThrows) flow.set(FlowFlags.THROWS); - if (ifTrueAllocates && ifFalseAllocates) flow.set(FlowFlags.ALLOCATES); - return module.createIf(condExpr, ifTrueExpr, ifFalseExpr); } compileReturnStatement(statement: ReturnStatement): ExpressionRef { var module = this.module; var currentFunction = this.currentFunction; - var expression: ExpressionRef = 0; + var expr: ExpressionRef = 0; var flow = currentFunction.flow; // Remember that this flow returns flow.set(FlowFlags.RETURNS); - // When inlining, break to the end of the inlined function's block - if (flow.is(FlowFlags.INLINE_CONTEXT)) { - if (statement.value) { - expression = this.compileExpression( - statement.value, - assert(flow.returnType) - ); - } - return module.createBreak(assert(flow.returnLabel), 0, expression); + if (statement.value) { + let returnType = flow.returnType; + expr = this.compileExpression( + statement.value, + returnType, + ConversionKind.IMPLICIT, + currentFunction.is(CommonFlags.MODULE_EXPORT) + ? WrapMode.WRAP + : WrapMode.NONE + ); + + // Remember whether returning a properly wrapped value + if (!flow.canOverflow(expr, returnType)) flow.set(FlowFlags.RETURNS_WRAPPED); } - // Otherwise return as usual - if (statement.value) { - expression = this.compileExpression( - statement.value, - flow.returnType - ); - } - return module.createReturn(expression); + // When inlining, break to the end of the inlined function's block (no need to wrap) + return flow.is(FlowFlags.INLINE_CONTEXT) + ? module.createBreak(assert(flow.returnLabel), 0, expr) + : module.createReturn(expr); } compileSwitchStatement(statement: SwitchStatement): ExpressionRef { @@ -1725,7 +1726,7 @@ export class Compiler extends DiagnosticEmitter { var context = currentFunction.enterBreakContext(); // introduce a local for evaluating the condition (exactly once) - var tempLocal = currentFunction.getTempLocal(Type.u32); + var tempLocal = currentFunction.getTempLocal(Type.u32, false); var tempLocalIndex = tempLocal.index; var cases = statement.cases; var numCases = cases.length; @@ -1734,7 +1735,7 @@ export class Compiler extends DiagnosticEmitter { var breaks = new Array(1 + numCases); breaks[0] = module.createSetLocal( // initializer tempLocalIndex, - this.compileExpression(statement.condition, Type.u32) + this.compileExpression(statement.condition, Type.u32, ConversionKind.IMPLICIT, WrapMode.NONE) ); // make one br_if per (possibly dynamic) labeled case (binaryen optimizes to br_table where possible) @@ -1747,7 +1748,7 @@ export class Compiler extends DiagnosticEmitter { breaks[breakIndex++] = module.createBreak("case" + i.toString(10) + "|" + context, module.createBinary(BinaryOp.EqI32, module.createGetLocal(tempLocalIndex, NativeType.I32), - this.compileExpression(label, Type.i32) + this.compileExpression(label, Type.u32, ConversionKind.IMPLICIT, WrapMode.NONE) ) ); } else { @@ -1766,6 +1767,7 @@ export class Compiler extends DiagnosticEmitter { // nest blocks in order var currentBlock = module.createBlock("case0|" + context, breaks, NativeType.None); var alwaysReturns = true; + var alwaysReturnsWrapped = true; var alwaysThrows = true; var alwaysAllocates = true; for (let i = 0; i < numCases; ++i) { @@ -1786,15 +1788,10 @@ export class Compiler extends DiagnosticEmitter { for (let j = 0; j < numStatements; ++j) { body[j + 1] = this.compileStatement(statements[j]); } - if (!(fallsThrough || flow.is(FlowFlags.RETURNS))) { - alwaysReturns = false; // ignore fall-throughs - } - if (!(fallsThrough || flow.is(FlowFlags.THROWS))) { - alwaysThrows = false; - } - if (!(fallsThrough || flow.is(FlowFlags.ALLOCATES))) { - alwaysAllocates = false; - } + if (!(fallsThrough || flow.is(FlowFlags.RETURNS))) alwaysReturns = false; // ignore fall-throughs + if (!(fallsThrough || flow.is(FlowFlags.RETURNS_WRAPPED))) alwaysReturnsWrapped = false; // ignore fall-throughs + if (!(fallsThrough || flow.is(FlowFlags.THROWS))) alwaysThrows = false; + if (!(fallsThrough || flow.is(FlowFlags.ALLOCATES))) alwaysAllocates = false; // Switch back to the parent flow currentFunction.flow = flow.leaveBranchOrScope(); @@ -1807,6 +1804,7 @@ export class Compiler extends DiagnosticEmitter { if (defaultIndex >= 0) { let flow = currentFunction.flow; if (alwaysReturns) flow.set(FlowFlags.RETURNS); + if (alwaysReturnsWrapped) flow.set(FlowFlags.RETURNS_WRAPPED); if (alwaysThrows) flow.set(FlowFlags.THROWS); if (alwaysAllocates) flow.set(FlowFlags.ALLOCATES); } @@ -1870,7 +1868,7 @@ export class Compiler extends DiagnosticEmitter { let declaration = declarations[i]; let name = declaration.name.text; let type: Type | null = null; - let init: ExpressionRef = 0; + let initExpr: ExpressionRef = 0; if (declaration.type) { type = program.resolveType( // reports declaration.type, @@ -1878,13 +1876,19 @@ export class Compiler extends DiagnosticEmitter { ); if (!type) continue; if (declaration.initializer) { - init = this.compileExpression(declaration.initializer, type); // reports + initExpr = this.compileExpression( // reports + declaration.initializer, + type, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); } } else if (declaration.initializer) { // infer type using void/NONE for proper literal inference - init = this.compileExpression( // reports + initExpr = this.compileExpression( // reports declaration.initializer, Type.void, - ConversionKind.NONE + ConversionKind.NONE, + WrapMode.NONE ); if (this.currentType == Type.void) { this.error( @@ -1903,36 +1907,32 @@ export class Compiler extends DiagnosticEmitter { } let isInlined = false; if (declaration.is(CommonFlags.CONST)) { - if (init) { - init = this.precomputeExpressionRef(init); - if (_BinaryenExpressionGetId(init) == ExpressionId.Const) { + if (initExpr) { + initExpr = this.precomputeExpressionRef(initExpr); + if (getExpressionId(initExpr) == ExpressionId.Const) { let local = new Local(program, name, -1, type); - switch (_BinaryenExpressionGetType(init)) { + switch (getExpressionType(initExpr)) { case NativeType.I32: { - local = local.withConstantIntegerValue(_BinaryenConstGetValueI32(init), 0); + local = local.withConstantIntegerValue(getConstValueI32(initExpr), 0); break; } case NativeType.I64: { local = local.withConstantIntegerValue( - _BinaryenConstGetValueI64Low(init), - _BinaryenConstGetValueI64High(init) + getConstValueI64Low(initExpr), + getConstValueI64High(initExpr) ); break; } case NativeType.F32: { - local = local.withConstantFloatValue(_BinaryenConstGetValueF32(init)); + local = local.withConstantFloatValue(getConstValueF32(initExpr)); break; } case NativeType.F64: { - local = local.withConstantFloatValue(_BinaryenConstGetValueF64(init)); + local = local.withConstantFloatValue(getConstValueF64(initExpr)); break; } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - declaration.range - ); return this.module.createUnreachable(); } } @@ -1962,16 +1962,20 @@ export class Compiler extends DiagnosticEmitter { } } if (!isInlined) { + let local: Local; if ( declaration.isAny(CommonFlags.LET | CommonFlags.CONST) || flow.is(FlowFlags.INLINE_CONTEXT) ) { // here: not top-level - flow.addScopedLocal(type, name, declaration); // reports + local = flow.addScopedLocal(type, name, false, declaration); // reports } else { - currentFunction.addLocal(type, name, declaration); // reports + local = currentFunction.addLocal(type, name, declaration); // reports } - if (init) { - initializers.push(this.compileAssignmentWithValue(declaration.name, init)); + if (initExpr) { + initializers.push(this.compileAssignmentWithValue(declaration.name, initExpr)); + flow.setLocalWrapped(local.index, !flow.canOverflow(initExpr, type)); + } else { + flow.setLocalWrapped(local.index, true); // zero } } } @@ -1983,7 +1987,7 @@ export class Compiler extends DiagnosticEmitter { } compileVoidStatement(statement: VoidStatement): ExpressionRef { - return this.compileExpression(statement.expression, Type.void, ConversionKind.EXPLICIT, false); + return this.compileExpression(statement.expression, Type.void, ConversionKind.EXPLICIT, WrapMode.NONE); } compileWhileStatement(statement: WhileStatement): ExpressionRef { @@ -1991,7 +1995,7 @@ export class Compiler extends DiagnosticEmitter { // The condition does not yet initialize a branch var condExpr = this.makeIsTrueish( - this.compileExpression(statement.condition, Type.i32, ConversionKind.NONE), + this.compileExpressionRetainType(statement.condition, Type.bool, WrapMode.NONE), this.currentType ); @@ -2002,15 +2006,15 @@ export class Compiler extends DiagnosticEmitter { // Try to eliminate unnecesssary loops if the condition is constant let condExprPrecomp = this.precomputeExpressionRef(condExpr); if ( - _BinaryenExpressionGetId(condExprPrecomp) == ExpressionId.Const && - _BinaryenExpressionGetType(condExprPrecomp) == NativeType.I32 + getExpressionId(condExprPrecomp) == ExpressionId.Const && + getExpressionType(condExprPrecomp) == NativeType.I32 ) { - if (!_BinaryenConstGetValueI32(condExprPrecomp)) return module.createNop(); + if (!getConstValueI32(condExprPrecomp)) return module.createNop(); // Otherwise recompile to the original and let the optimizer decide } else /* if (condExpr != condExprPrecomp) <- not guaranteed */ { condExpr = this.makeIsTrueish( - this.compileExpression(statement.condition, Type.i32, ConversionKind.NONE), + this.compileExpressionRetainType(statement.condition, Type.bool, WrapMode.NONE), this.currentType ); } @@ -2082,7 +2086,7 @@ export class Compiler extends DiagnosticEmitter { element.constantValueKind == ConstantValueKind.INTEGER ? i64_low(element.constantIntegerValue) << shift >> shift : 0 - ); + ); // recognized by canOverflow } case TypeKind.U8: case TypeKind.U16: @@ -2092,7 +2096,7 @@ export class Compiler extends DiagnosticEmitter { element.constantValueKind == ConstantValueKind.INTEGER ? i64_low(element.constantIntegerValue) & mask : 0 - ); + ); // recognized by canOverflow } case TypeKind.I32: case TypeKind.U32: { @@ -2142,8 +2146,8 @@ export class Compiler extends DiagnosticEmitter { compileExpression( expression: Expression, contextualType: Type, - conversionKind: ConversionKind = ConversionKind.IMPLICIT, - wrapSmallIntegers: bool = true + conversionKind: ConversionKind, + wrapMode: WrapMode ): ExpressionRef { this.currentType = contextualType; @@ -2154,7 +2158,7 @@ export class Compiler extends DiagnosticEmitter { break; } case NodeKind.BINARY: { - expr = this.compileBinaryExpression(expression, contextualType, wrapSmallIntegers); + expr = this.compileBinaryExpression(expression, contextualType); break; } case NodeKind.CALL: { @@ -2195,11 +2199,7 @@ export class Compiler extends DiagnosticEmitter { break; } case NodeKind.PARENTHESIZED: { - expr = this.compileParenthesizedExpression( - expression, - contextualType, - wrapSmallIntegers - ); + expr = this.compileParenthesizedExpression(expression, contextualType); break; } case NodeKind.PROPERTYACCESS: { @@ -2219,24 +2219,21 @@ export class Compiler extends DiagnosticEmitter { break; } case NodeKind.UNARYPREFIX: { - expr = this.compileUnaryPrefixExpression(expression, contextualType, wrapSmallIntegers); + expr = this.compileUnaryPrefixExpression(expression, contextualType); break; } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = this.module.createUnreachable(); - break; } } var currentType = this.currentType; if (conversionKind != ConversionKind.NONE && currentType != contextualType) { - expr = this.convertExpression(expr, currentType, contextualType, conversionKind, expression); + expr = this.convertExpression(expr, currentType, contextualType, conversionKind, wrapMode, expression); this.currentType = contextualType; + } else if (wrapMode == WrapMode.WRAP) { + expr = this.ensureSmallIntegerWrap(expr, currentType); } if (this.options.sourceMap) this.addDebugLocation(expr, expression.range); @@ -2246,7 +2243,7 @@ export class Compiler extends DiagnosticEmitter { compileExpressionRetainType( expression: Expression, contextualType: Type, - wrapSmallIntegers: bool = true + wrapMode: WrapMode ): ExpressionRef { return this.compileExpression( expression, @@ -2254,16 +2251,19 @@ export class Compiler extends DiagnosticEmitter { ? Type.i32 : contextualType, ConversionKind.NONE, - wrapSmallIntegers + wrapMode ); } precomputeExpression( expression: Expression, contextualType: Type, - conversionKind: ConversionKind = ConversionKind.IMPLICIT + conversionKind: ConversionKind, + wrapMode: WrapMode ): ExpressionRef { - return this.precomputeExpressionRef(this.compileExpression(expression, contextualType, conversionKind)); + return this.precomputeExpressionRef( + this.compileExpression(expression, contextualType, conversionKind, wrapMode) + ); } precomputeExpressionRef(expr: ExpressionRef): ExpressionRef { @@ -2278,11 +2278,12 @@ export class Compiler extends DiagnosticEmitter { } var funcRef = module.addFunction("__precompute", typeRef, null, expr); module.runPasses([ "precompute" ], funcRef); - var ret = _BinaryenFunctionGetBody(funcRef); + var ret = getFunctionBody(funcRef); module.removeFunction("__precompute"); if (typeRefAdded) { // TODO: also remove the function type somehow if no longer used or make the C-API accept // a `null` typeRef, using an implicit type. + // module.removeFunctionType(typeRef); } return ret; } @@ -2292,6 +2293,7 @@ export class Compiler extends DiagnosticEmitter { fromType: Type, toType: Type, conversionKind: ConversionKind, + wrapMode: WrapMode, reportNode: Node ): ExpressionRef { assert(conversionKind != ConversionKind.NONE); @@ -2350,14 +2352,12 @@ export class Compiler extends DiagnosticEmitter { expr = module.createUnary(UnaryOp.TruncF32ToI64, expr); } else { expr = module.createUnary(UnaryOp.TruncF32ToI32, expr); - if (toType.is(TypeFlags.SHORT)) expr = this.makeSmallIntegerWrap(expr, toType); } } else { if (toType.is(TypeFlags.LONG)) { expr = module.createUnary(UnaryOp.TruncF32ToU64, expr); } else { expr = module.createUnary(UnaryOp.TruncF32ToU32, expr); - if (toType.is(TypeFlags.SHORT)) expr = this.makeSmallIntegerWrap(expr, toType); } } @@ -2368,14 +2368,12 @@ export class Compiler extends DiagnosticEmitter { expr = module.createUnary(UnaryOp.TruncF64ToI64, expr); } else { expr = module.createUnary(UnaryOp.TruncF64ToI32, expr); - if (toType.is(TypeFlags.SHORT)) expr = this.makeSmallIntegerWrap(expr, toType); } } else { if (toType.is(TypeFlags.LONG)) { expr = module.createUnary(UnaryOp.TruncF64ToU64, expr); } else { expr = module.createUnary(UnaryOp.TruncF64ToU32, expr); - if (toType.is(TypeFlags.SHORT)) expr = this.makeSmallIntegerWrap(expr, toType); } } } @@ -2428,37 +2426,39 @@ export class Compiler extends DiagnosticEmitter { // int to int } else { + // i64 to ... if (fromType.is(TypeFlags.LONG)) { - // i64 to i32 + // i64 to i32 or smaller if (!toType.is(TypeFlags.LONG)) { expr = module.createUnary(UnaryOp.WrapI64, expr); // discards upper bits - if (toType.is(TypeFlags.SHORT)) expr = this.makeSmallIntegerWrap(expr, toType); } - // i32 to i64 + // i32 or smaller to i64 } else if (toType.is(TypeFlags.LONG)) { - expr = module.createUnary(toType.is(TypeFlags.SIGNED) ? UnaryOp.ExtendI32 : UnaryOp.ExtendU32, expr); + expr = module.createUnary( + toType.is(TypeFlags.SIGNED) ? UnaryOp.ExtendI32 : UnaryOp.ExtendU32, + this.ensureSmallIntegerWrap(expr, fromType) // must clear garbage bits + ); + wrapMode = WrapMode.NONE; - // i32 or smaller to even smaller or same size int with change of sign - } else if ( - toType.is(TypeFlags.SHORT) && - ( - fromType.size > toType.size || - ( - fromType.size == toType.size && - fromType.is(TypeFlags.SIGNED) != toType.is(TypeFlags.SIGNED) - ) - ) - ) { - expr = this.makeSmallIntegerWrap(expr, toType); + // i32 to i32 + } else { + // small i32 to ... + if (fromType.is(TypeFlags.SHORT)) { + // small i32 to larger i32 + if (fromType.size < toType.size) { + expr = this.ensureSmallIntegerWrap(expr, fromType); // must clear garbage bits + wrapMode = WrapMode.NONE; + } + } } - - // otherwise (smaller) i32/u32 to (same size) i32/u32 } this.currentType = toType; - return expr; + return wrapMode == WrapMode.WRAP + ? this.ensureSmallIntegerWrap(expr, toType) + : expr; } compileAssertionExpression(expression: AssertionExpression, contextualType: Type): ExpressionRef { @@ -2467,7 +2467,7 @@ export class Compiler extends DiagnosticEmitter { this.currentFunction.flow.contextualTypeArguments ); if (!toType) return this.module.createUnreachable(); - return this.compileExpression(expression.expression, toType, ConversionKind.EXPLICIT); + return this.compileExpression(expression.expression, toType, ConversionKind.EXPLICIT, WrapMode.NONE); } private f32ModInstance: Function | null = null; @@ -2477,8 +2477,7 @@ export class Compiler extends DiagnosticEmitter { compileBinaryExpression( expression: BinaryExpression, - contextualType: Type, - wrapSmallIntegers: bool = true + contextualType: Type ): ExpressionRef { var module = this.module; var left = expression.left; @@ -2490,16 +2489,13 @@ export class Compiler extends DiagnosticEmitter { var rightType: Type; var commonType: Type | null; - var condExpr: ExpressionRef; var expr: ExpressionRef; var compound = false; - var possiblyOverflows = false; - var tempLocal: Local | null = null; var operator = expression.operator; switch (operator) { case Token.LESSTHAN: { - leftExpr = this.compileExpressionRetainType(left, contextualType); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -2512,11 +2508,25 @@ export class Compiler extends DiagnosticEmitter { } } - rightExpr = this.compileExpressionRetainType(right, leftType); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, true)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -2577,19 +2587,14 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } this.currentType = Type.bool; break; } case Token.GREATERTHAN: { - leftExpr = this.compileExpressionRetainType(left, contextualType); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -2602,11 +2607,25 @@ export class Compiler extends DiagnosticEmitter { } } - rightExpr = this.compileExpressionRetainType(right, leftType); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, true)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -2667,19 +2686,14 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } this.currentType = Type.bool; break; } case Token.LESSTHAN_EQUALS: { - leftExpr = this.compileExpressionRetainType(left, contextualType); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -2692,11 +2706,25 @@ export class Compiler extends DiagnosticEmitter { } } - rightExpr = this.compileExpressionRetainType(right, leftType); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, true)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -2757,19 +2785,14 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } this.currentType = Type.bool; break; } case Token.GREATERTHAN_EQUALS: { - leftExpr = this.compileExpressionRetainType(left, contextualType); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -2782,11 +2805,25 @@ export class Compiler extends DiagnosticEmitter { } } - rightExpr = this.compileExpressionRetainType(right, leftType); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, true)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -2847,12 +2884,7 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } this.currentType = Type.bool; @@ -2866,7 +2898,7 @@ export class Compiler extends DiagnosticEmitter { // checking for a possible use of unary EQZ. while the most classic of all optimizations, // that's not what the source told us to do. for reference, `!left` emits unary EQZ. - leftExpr = this.compileExpressionRetainType(left, contextualType); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; if (operator == Token.EQUALS_EQUALS) { // check operator overload @@ -2880,11 +2912,25 @@ export class Compiler extends DiagnosticEmitter { } } - rightExpr = this.compileExpressionRetainType(right, leftType); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -2930,12 +2976,7 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } this.currentType = Type.bool; @@ -2943,7 +2984,7 @@ export class Compiler extends DiagnosticEmitter { } case Token.EXCLAMATION_EQUALS_EQUALS: case Token.EXCLAMATION_EQUALS: { - leftExpr = this.compileExpressionRetainType(left, contextualType); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; if (operator == Token.EXCLAMATION_EQUALS) { // check operator overload @@ -2957,11 +2998,25 @@ export class Compiler extends DiagnosticEmitter { } } - rightExpr = this.compileExpressionRetainType(right, leftType); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -3007,10 +3062,6 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); } } @@ -3022,11 +3073,7 @@ export class Compiler extends DiagnosticEmitter { } case Token.PLUS_EQUALS: compound = true; case Token.PLUS: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - false // retains low bits of small integers - ); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -3040,22 +3087,27 @@ export class Compiler extends DiagnosticEmitter { } if (compound) { - rightExpr = this.compileExpression( - right, - leftType, - ConversionKind.IMPLICIT, - false // ^ - ); + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.NONE); } else { - rightExpr = this.compileExpressionRetainType( - right, - leftType, - false // ^ - ); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -3066,11 +3118,11 @@ export class Compiler extends DiagnosticEmitter { } } switch (this.currentType.kind) { - case TypeKind.I8: - case TypeKind.I16: - case TypeKind.U8: - case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; + case TypeKind.I8: // addition might overflow + case TypeKind.I16: // ^ + case TypeKind.U8: // ^ + case TypeKind.U16: // ^ + case TypeKind.BOOL: // ^ case TypeKind.I32: case TypeKind.U32: { expr = module.createBinary(BinaryOp.AddI32, leftExpr, rightExpr); @@ -3102,23 +3154,14 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } break; } case Token.MINUS_EQUALS: compound = true; case Token.MINUS: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - false // retains low bits of small integers - ); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -3132,22 +3175,28 @@ export class Compiler extends DiagnosticEmitter { } if (compound) { - rightExpr = this.compileExpression( - right, - leftType, - ConversionKind.IMPLICIT, - false // ^ - ); + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.NONE); + rightType = this.currentType; } else { - rightExpr = this.compileExpressionRetainType( - right, - leftType, - false // ^ - ); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -3158,11 +3207,11 @@ export class Compiler extends DiagnosticEmitter { } } switch (this.currentType.kind) { - case TypeKind.I8: - case TypeKind.I16: - case TypeKind.U8: - case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; + case TypeKind.I8: // subtraction might overflow + case TypeKind.I16: // ^ + case TypeKind.U8: // ^ + case TypeKind.U16: // ^ + case TypeKind.BOOL: // ^ case TypeKind.I32: case TypeKind.U32: { expr = module.createBinary(BinaryOp.SubI32, leftExpr, rightExpr); @@ -3194,23 +3243,14 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } break; } case Token.ASTERISK_EQUALS: compound = true; case Token.ASTERISK: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - false // retains low bits of small integers - ); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -3224,22 +3264,28 @@ export class Compiler extends DiagnosticEmitter { } if (compound) { - rightExpr = this.compileExpression( - right, - leftType, - ConversionKind.IMPLICIT, - false // ^ - ); + leftExpr = this.ensureSmallIntegerWrap(leftExpr, leftType); + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.WRAP); } else { - rightExpr = this.compileExpressionRetainType( - right, - leftType, - false // ^ - ); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -3254,7 +3300,7 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.I16: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; + case TypeKind.BOOL: case TypeKind.I32: case TypeKind.U32: { expr = module.createBinary(BinaryOp.MulI32, leftExpr, rightExpr); @@ -3286,23 +3332,14 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } break; } case Token.ASTERISK_ASTERISK_EQUALS: compound = true; case Token.ASTERISK_ASTERISK: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - true // must be wrapped - ); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -3318,11 +3355,9 @@ export class Compiler extends DiagnosticEmitter { let instance: Function | null; // Mathf.pow if lhs is f32 (result is f32) - if (this.currentType == Type.f32) { - rightExpr = this.compileExpression( - right, - this.currentType - ); + if (this.currentType.kind == TypeKind.F32) { + rightExpr = this.compileExpression(right, Type.f32, ConversionKind.IMPLICIT, WrapMode.NONE); + rightType = this.currentType; if (!(instance = this.f32PowInstance)) { let namespace = this.program.elementsLookup.get("Mathf"); if (!namespace) { @@ -3354,12 +3389,17 @@ export class Compiler extends DiagnosticEmitter { this.currentType, Type.f64, ConversionKind.IMPLICIT, + WrapMode.NONE, left ); + leftType = this.currentType; rightExpr = this.compileExpression( right, - Type.f64 + Type.f64, + ConversionKind.IMPLICIT, + WrapMode.NONE ); + rightType = this.currentType; if (!(instance = this.f64PowInstance)) { let namespace = this.program.elementsLookup.get("Math"); if (!namespace) { @@ -3392,11 +3432,7 @@ export class Compiler extends DiagnosticEmitter { } case Token.SLASH_EQUALS: compound = true; case Token.SLASH: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - true // TODO: when can division remain unwrapped? does it overflow? - ); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -3410,22 +3446,29 @@ export class Compiler extends DiagnosticEmitter { } if (compound) { - rightExpr = this.compileExpression( - right, - leftType, - ConversionKind.IMPLICIT, - false // ^ - ); + leftExpr = this.ensureSmallIntegerWrap(leftExpr, leftType); + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.WRAP); + rightType = this.currentType; } else { - rightExpr = this.compileExpressionRetainType( - right, - leftType, - false // ^ - ); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, // ! + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, // ! + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -3436,8 +3479,8 @@ export class Compiler extends DiagnosticEmitter { } } switch (this.currentType.kind) { - case TypeKind.I8: - case TypeKind.I16: possiblyOverflows = true; + case TypeKind.I8: // signed div on signed small integers might overflow, e.g. -128/-1 + case TypeKind.I16: // ^ case TypeKind.I32: { expr = module.createBinary(BinaryOp.DivI32, leftExpr, rightExpr); break; @@ -3458,7 +3501,10 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; + case TypeKind.BOOL: { + expr = module.createBinary(BinaryOp.DivU32, leftExpr, rightExpr); + break; + } case TypeKind.U32: { expr = module.createBinary(BinaryOp.DivU32, leftExpr, rightExpr); break; @@ -3487,23 +3533,14 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } break; } case Token.PERCENT_EQUALS: compound = true; case Token.PERCENT: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - true // TODO: when can remainder remain unwrapped? does it overflow? - ); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -3517,22 +3554,29 @@ export class Compiler extends DiagnosticEmitter { } if (compound) { - rightExpr = this.compileExpression( - right, - leftType, - ConversionKind.IMPLICIT, - false // ^ - ); + leftExpr = this.ensureSmallIntegerWrap(leftExpr, leftType); + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.WRAP); + rightType = this.currentType; } else { - rightExpr = this.compileExpressionRetainType( - right, - leftType, - false // ^ - ); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, // ! + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.WRAP, // ! + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -3544,7 +3588,10 @@ export class Compiler extends DiagnosticEmitter { } switch (this.currentType.kind) { case TypeKind.I8: - case TypeKind.I16: + case TypeKind.I16: { + expr = module.createBinary(BinaryOp.RemI32, leftExpr, rightExpr); + break; + } case TypeKind.I32: { expr = module.createBinary(BinaryOp.RemI32, leftExpr, rightExpr); break; @@ -3565,11 +3612,14 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.U8: case TypeKind.U16: - case TypeKind.U32: case TypeKind.BOOL: { expr = module.createBinary(BinaryOp.RemU32, leftExpr, rightExpr); break; } + case TypeKind.U32: { + expr = module.createBinary(BinaryOp.RemU32, leftExpr, rightExpr); + break; + } case TypeKind.USIZE: { expr = module.createBinary( this.options.isWasm64 @@ -3648,36 +3698,25 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } break; } case Token.LESSTHAN_LESSTHAN_EQUALS: compound = true; case Token.LESSTHAN_LESSTHAN: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - false // retains low bits of small integers - ); - rightExpr = this.compileExpression( - right, - this.currentType, - ConversionKind.IMPLICIT, - false // ^ - ); + leftExpr = this.compileExpressionRetainType(left, contextualType.intType, WrapMode.NONE); + leftType = this.currentType; + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.NONE); + rightType = this.currentType; switch (this.currentType.kind) { case TypeKind.I8: case TypeKind.I16: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; - default: { + case TypeKind.BOOL: + case TypeKind.I32: + case TypeKind.U32: { expr = module.createBinary(BinaryOp.ShlI32, leftExpr, rightExpr); break; } @@ -3705,34 +3744,26 @@ export class Compiler extends DiagnosticEmitter { ); return module.createUnreachable(); } - case TypeKind.VOID: { + default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } break; } case Token.GREATERTHAN_GREATERTHAN_EQUALS: compound = true; case Token.GREATERTHAN_GREATERTHAN: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - true // must wrap small integers - ); - rightExpr = this.compileExpression( - right, - this.currentType, - ConversionKind.IMPLICIT, - true // ^ - ); + leftExpr = this.compileExpressionRetainType(left, contextualType.intType, WrapMode.WRAP); // ! + leftType = this.currentType; // ^ must clear garbage bits + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.WRAP); + rightType = this.currentType; switch (this.currentType.kind) { - default: { - // assumes signed shr on signed small integers does not overflow + case TypeKind.I8: + case TypeKind.I16: { + expr = module.createBinary(BinaryOp.ShrI32, leftExpr, rightExpr); + break; + } + case TypeKind.I32: { expr = module.createBinary(BinaryOp.ShrI32, leftExpr, rightExpr); break; } @@ -3752,7 +3783,10 @@ export class Compiler extends DiagnosticEmitter { } case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: // assumes unsigned shr on unsigned small integers does not overflow + case TypeKind.BOOL: { + expr = module.createBinary(BinaryOp.ShrU32, leftExpr, rightExpr); + break; + } case TypeKind.U32: { expr = module.createBinary(BinaryOp.ShrU32, leftExpr, rightExpr); break; @@ -3779,36 +3813,29 @@ export class Compiler extends DiagnosticEmitter { ); return module.createUnreachable(); } - case TypeKind.VOID: { + default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = module.createUnreachable(); - break; } } break; } case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN_EQUALS: compound = true; case Token.GREATERTHAN_GREATERTHAN_GREATERTHAN: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - true // modifies low bits of small integers if unsigned - ); - rightExpr = this.compileExpression( - right, - this.currentType, - ConversionKind.IMPLICIT, - true // ^ - ); + leftExpr = this.compileExpressionRetainType(left, contextualType.intType, WrapMode.WRAP); + leftType = this.currentType; // ^ clear garbage bits + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.NONE); + rightType = this.currentType; switch (this.currentType.kind) { + case TypeKind.U8: + case TypeKind.U16: + case TypeKind.BOOL: { // assumes that unsigned shr on unsigned small integers does not overflow + expr = module.createBinary(BinaryOp.ShrU32, leftExpr, rightExpr); + } case TypeKind.I8: - case TypeKind.I16: possiblyOverflows = true; - default: { - // assumes that unsigned shr on unsigned small integers does not overflow + case TypeKind.I16: + case TypeKind.I32: + case TypeKind.U32: { expr = module.createBinary(BinaryOp.ShrU32, leftExpr, rightExpr); break; } @@ -3817,7 +3844,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.ShrU64, leftExpr, rightExpr); break; } - case TypeKind.USIZE: // TODO: check operator overload + case TypeKind.USIZE: // TODO: operator overload? case TypeKind.ISIZE: { expr = module.createBinary( this.options.isWasm64 @@ -3828,25 +3855,24 @@ export class Compiler extends DiagnosticEmitter { ); break; } - case TypeKind.VOID: { - assert(false); + case TypeKind.F32: + case TypeKind.F64: { this.error( - DiagnosticCode.Operation_not_supported, - expression.range + DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, + expression.range, operatorTokenToString(expression.operator), this.currentType.toString() ); + return module.createUnreachable(); + } + default: { + assert(false); expr = module.createUnreachable(); - break; } } break; } case Token.AMPERSAND_EQUALS: compound = true; case Token.AMPERSAND: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - false // retains low bits of small integers - ); + leftExpr = this.compileExpressionRetainType(left, contextualType.intType, WrapMode.NONE); leftType = this.currentType; // check operator overloadd @@ -3860,22 +3886,28 @@ export class Compiler extends DiagnosticEmitter { } if (compound) { - rightExpr = this.compileExpression( - right, - leftType, - ConversionKind.IMPLICIT, - false // ^ - ); + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.NONE); + rightType = this.currentType; } else { - rightExpr = this.compileExpressionRetainType( - right, - leftType, - false // ^ - ); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -3888,10 +3920,11 @@ export class Compiler extends DiagnosticEmitter { switch (this.currentType.kind) { case TypeKind.I8: case TypeKind.I16: + case TypeKind.I32: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; // if left or right already did - default: { + case TypeKind.BOOL: + case TypeKind.U32: { expr = module.createBinary(BinaryOp.AndI32, leftExpr, rightExpr); break; } @@ -3911,25 +3944,24 @@ export class Compiler extends DiagnosticEmitter { ); break; } - case TypeKind.VOID: { - assert(false); + case TypeKind.F32: + case TypeKind.F64: { this.error( - DiagnosticCode.Operation_not_supported, - expression.range + DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, + expression.range, operatorTokenToString(expression.operator), this.currentType.toString() ); + return module.createUnreachable(); + } + default: { + assert(false); expr = module.createUnreachable(); - break; } } break; } case Token.BAR_EQUALS: compound = true; case Token.BAR: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - false // retains low bits of small integers - ); + leftExpr = this.compileExpressionRetainType(left, contextualType.intType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -3943,22 +3975,28 @@ export class Compiler extends DiagnosticEmitter { } if (compound) { - rightExpr = this.compileExpression( - right, - leftType, - ConversionKind.IMPLICIT, - false // ^ - ); + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.NONE); + rightType = this.currentType; } else { - rightExpr = this.compileExpressionRetainType( - right, - leftType, - false // ^ - ); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -3973,8 +4011,12 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.I16: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; // if left or right already did - default: { + case TypeKind.BOOL: { + expr = module.createBinary(BinaryOp.OrI32, leftExpr, rightExpr); + break; + } + case TypeKind.I32: + case TypeKind.U32: { expr = module.createBinary(BinaryOp.OrI32, leftExpr, rightExpr); break; } @@ -3994,25 +4036,24 @@ export class Compiler extends DiagnosticEmitter { ); break; } - case TypeKind.VOID: { - assert(false); + case TypeKind.F32: + case TypeKind.F64: { this.error( - DiagnosticCode.Operation_not_supported, - expression.range + DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, + expression.range, operatorTokenToString(expression.operator), this.currentType.toString() ); + return module.createUnreachable(); + } + default: { + assert(false); expr = module.createUnreachable(); - break; } } break; } case Token.CARET_EQUALS: compound = true; case Token.CARET: { - leftExpr = this.compileExpressionRetainType( - left, - contextualType, - false // retains low bits of small integers - ); + leftExpr = this.compileExpressionRetainType(left, contextualType.intType, WrapMode.NONE); leftType = this.currentType; // check operator overload @@ -4026,22 +4067,28 @@ export class Compiler extends DiagnosticEmitter { } if (compound) { - rightExpr = this.compileExpression( - right, - leftType, - ConversionKind.IMPLICIT, - false // ^ - ); + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.NONE); + rightType = this.currentType; } else { - rightExpr = this.compileExpressionRetainType( - right, - leftType, - false // ^ - ); + rightExpr = this.compileExpressionRetainType(right, leftType, WrapMode.NONE); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { - leftExpr = this.convertExpression(leftExpr, leftType, commonType, ConversionKind.IMPLICIT, left); - rightExpr = this.convertExpression(rightExpr, rightType, commonType, ConversionKind.IMPLICIT, right); + leftExpr = this.convertExpression( + leftExpr, + leftType, + leftType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + left + ); + rightExpr = this.convertExpression( + rightExpr, + rightType, + rightType = commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + right + ); } else { this.error( DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2, @@ -4056,8 +4103,12 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.I16: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; // if left or right already did - default: { + case TypeKind.BOOL: { + expr = module.createBinary(BinaryOp.XorI32, leftExpr, rightExpr); + break; + } + case TypeKind.I32: + case TypeKind.U32: { expr = module.createBinary(BinaryOp.XorI32, leftExpr, rightExpr); break; } @@ -4077,14 +4128,17 @@ export class Compiler extends DiagnosticEmitter { ); break; } - case TypeKind.VOID: { - assert(false); + case TypeKind.F32: + case TypeKind.F64: { this.error( - DiagnosticCode.Operation_not_supported, - expression.range + DiagnosticCode.The_0_operator_cannot_be_applied_to_type_1, + expression.range, operatorTokenToString(expression.operator), this.currentType.toString() ); + return module.createUnreachable(); + } + default: { + assert(false); expr = module.createUnreachable(); - break; } } break; @@ -4093,42 +4147,32 @@ export class Compiler extends DiagnosticEmitter { // logical (no overloading) case Token.AMPERSAND_AMPERSAND: { // left && right - leftExpr = this.compileExpressionRetainType( - left, - contextualType - ); - rightExpr = this.compileExpression( - right, - this.currentType, - ConversionKind.IMPLICIT, - false - ); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); + leftType = this.currentType; + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.NONE); + rightType = this.currentType; - // clone left if free of side effects - expr = module.cloneExpression(leftExpr, true, 0); + // simplify if cloning left without side effects is possible + if (expr = module.cloneExpression(leftExpr, true, 0)) { + this.makeIsTrueish(leftExpr, this.currentType); + expr = module.createIf( + this.makeIsTrueish(leftExpr, this.currentType), + rightExpr, + expr + ); // if not possible, tee left to a temp. local - if (!expr) { - tempLocal = this.currentFunction.getAndFreeTempLocal(this.currentType); - leftExpr = module.createTeeLocal(tempLocal.index, leftExpr); - } - - possiblyOverflows = this.currentType.is(TypeFlags.SHORT | TypeFlags.INTEGER); - condExpr = this.makeIsTrueish(leftExpr, this.currentType); - - // simplify when cloning left without side effects was successful - if (expr) { - expr = module.createIf( - condExpr, // left - rightExpr, // ? right - expr // : cloned left + } else { + let flow = this.currentFunction.flow; + let tempLocal = this.currentFunction.getAndFreeTempLocal( + this.currentType, + !flow.canOverflow(leftExpr, this.currentType) ); - } - - // otherwise make use of the temp. local - else { expr = module.createIf( - condExpr, + this.makeIsTrueish( + module.createTeeLocal(tempLocal.index, leftExpr), + this.currentType + ), rightExpr, module.createGetLocal( assert(tempLocal).index, // to be sure @@ -4139,42 +4183,31 @@ export class Compiler extends DiagnosticEmitter { break; } case Token.BAR_BAR: { // left || right - leftExpr = this.compileExpressionRetainType( - left, - contextualType - ); - rightExpr = this.compileExpression( - right, - this.currentType, - ConversionKind.IMPLICIT, - false - ); + leftExpr = this.compileExpressionRetainType(left, contextualType, WrapMode.NONE); + leftType = this.currentType; + rightExpr = this.compileExpression(right, leftType, ConversionKind.IMPLICIT, WrapMode.NONE); + rightType = this.currentType; - // clone left if free of side effects - expr = this.module.cloneExpression(leftExpr, true, 0); + // simplify if cloning left without side effects is possible + if (expr = this.module.cloneExpression(leftExpr, true, 0)) { + expr = this.module.createIf( + this.makeIsTrueish(leftExpr, this.currentType), + expr, + rightExpr + ); // if not possible, tee left to a temp. local - if (!expr) { - tempLocal = this.currentFunction.getAndFreeTempLocal(this.currentType); - leftExpr = module.createTeeLocal(tempLocal.index, leftExpr); - } - - possiblyOverflows = this.currentType.is(TypeFlags.SHORT | TypeFlags.INTEGER); // if right did - condExpr = this.makeIsTrueish(leftExpr, this.currentType); - - // simplify when cloning left without side effects was successful - if (expr) { - expr = this.module.createIf( - condExpr, // left - expr, // ? cloned left - rightExpr // : right + } else { + let flow = this.currentFunction.flow; + let tempLocal = this.currentFunction.getAndFreeTempLocal( + this.currentType, + !flow.canOverflow(leftExpr, this.currentType) ); - } - - // otherwise make use of the temp. local - else { expr = module.createIf( - condExpr, + this.makeIsTrueish( + module.createTeeLocal(tempLocal.index, leftExpr), + this.currentType + ), module.createGetLocal( assert(tempLocal).index, // to be sure this.currentType.toNativeType() @@ -4186,18 +4219,9 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); expr = this.module.createUnreachable(); - break; } } - if (possiblyOverflows && wrapSmallIntegers) { - assert(this.currentType.is(TypeFlags.SHORT | TypeFlags.INTEGER)); // must be a small int - expr = this.makeSmallIntegerWrap(expr, this.currentType); - } return compound ? this.compileAssignmentWithValue(left, expr, contextualType != Type.void) : expr; @@ -4214,7 +4238,7 @@ export class Compiler extends DiagnosticEmitter { if (operatorInstance.is(CommonFlags.INSTANCE)) { let parent = assert(operatorInstance.parent); assert(parent.kind == ElementKind.CLASS); - thisArg = this.compileExpression(value, (parent).type); + thisArg = this.compileExpression(value, (parent).type, ConversionKind.IMPLICIT, WrapMode.NONE); argumentExpressions = []; } else { argumentExpressions = [ value ]; @@ -4240,18 +4264,19 @@ export class Compiler extends DiagnosticEmitter { if (operatorInstance.is(CommonFlags.INSTANCE)) { let parent = assert(operatorInstance.parent); assert(parent.kind == ElementKind.CLASS); - thisArg = this.compileExpression(left, (parent).type); + thisArg = this.compileExpression(left, (parent).type, ConversionKind.IMPLICIT, WrapMode.NONE); argumentExpressions = [ right ]; } else { argumentExpressions = [ left, right ]; } - return this.compileCallDirect( + var ret = this.compileCallDirect( operatorInstance, argumentExpressions, reportNode, thisArg, operatorInstance.hasDecorator(DecoratorFlags.INLINE) ); + return ret; } compileAssignment(expression: Expression, valueExpression: Expression, contextualType: Type): ExpressionRef { @@ -4325,7 +4350,7 @@ export class Compiler extends DiagnosticEmitter { } // compile the value and do the assignment - var valueExpr = this.compileExpression(valueExpression, elementType); + var valueExpr = this.compileExpression(valueExpression, elementType, ConversionKind.IMPLICIT, WrapMode.NONE); return this.compileAssignmentWithValue( expression, valueExpr, @@ -4344,7 +4369,8 @@ export class Compiler extends DiagnosticEmitter { switch (target.kind) { case ElementKind.LOCAL: { - this.currentType = tee ? (target).type : Type.void; + let type = (target).type; + this.currentType = tee ? type : Type.void; if ((target).is(CommonFlags.CONST)) { this.error( DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, @@ -4352,6 +4378,8 @@ export class Compiler extends DiagnosticEmitter { ); return module.createUnreachable(); } + let flow = this.currentFunction.flow; + flow.setLocalWrapped((target).index, !flow.canOverflow(valueWithCorrectType, type)); return tee ? module.createTeeLocal((target).index, valueWithCorrectType) : module.createSetLocal((target).index, valueWithCorrectType); @@ -4369,6 +4397,7 @@ export class Compiler extends DiagnosticEmitter { ); return module.createUnreachable(); } + valueWithCorrectType = this.ensureSmallIntegerWrap(valueWithCorrectType, type); // guaranteed if (tee) { let nativeType = type.toNativeType(); let internalName = target.internalName; @@ -4399,13 +4428,23 @@ export class Compiler extends DiagnosticEmitter { let thisExpression = assert(this.program.resolvedThisExpression); let thisExpr = this.compileExpressionRetainType( thisExpression, - this.options.usizeType + this.options.usizeType, + WrapMode.NONE ); let type = (target).type; this.currentType = tee ? type : Type.void; let nativeType = type.toNativeType(); + if (type.kind == TypeKind.BOOL) { + // make sure bools are wrapped (usually are) when storing as 8 bits + valueWithCorrectType = this.ensureSmallIntegerWrap(valueWithCorrectType, type); + } if (tee) { - let tempLocal = this.currentFunction.getAndFreeTempLocal(type); + let currentFunction = this.currentFunction; + let flow = currentFunction.flow; + let tempLocal = currentFunction.getAndFreeTempLocal( + type, + !flow.canOverflow(valueWithCorrectType, type) + ); let tempLocalIndex = tempLocal.index; // TODO: simplify if valueWithCorrectType has no side effects return module.createBlock(null, [ @@ -4441,7 +4480,8 @@ export class Compiler extends DiagnosticEmitter { let thisExpression = assert(this.program.resolvedThisExpression); let thisExpr = this.compileExpressionRetainType( thisExpression, - this.options.usizeType + this.options.usizeType, + WrapMode.NONE ); return this.makeCallDirect(setterInstance, [ thisExpr, valueWithCorrectType ]); } else { @@ -4460,9 +4500,10 @@ export class Compiler extends DiagnosticEmitter { let thisExpression = assert(this.program.resolvedThisExpression); let thisExpr = this.compileExpressionRetainType( thisExpression, - this.options.usizeType + this.options.usizeType, + WrapMode.NONE ); - let tempLocal = this.currentFunction.getAndFreeTempLocal(returnType); + let tempLocal = this.currentFunction.getAndFreeTempLocal(returnType, false); let tempLocalIndex = tempLocal.index; return module.createBlock(null, [ this.makeCallDirect(setterInstance, [ // set and remember the target @@ -4513,15 +4554,19 @@ export class Compiler extends DiagnosticEmitter { let thisExpression = assert(this.program.resolvedThisExpression); let thisExpr = this.compileExpressionRetainType( thisExpression, - this.options.usizeType + this.options.usizeType, + WrapMode.NONE ); let elementExpr = this.compileExpression( elementExpression, - Type.i32 + Type.i32, + ConversionKind.IMPLICIT, + WrapMode.NONE ); if (tee) { - let tempLocalTarget = this.currentFunction.getTempLocal(targetType); - let tempLocalElement = this.currentFunction.getAndFreeTempLocal(this.currentType); + let currentFunction = this.currentFunction; + let tempLocalTarget = currentFunction.getTempLocal(targetType, false); + let tempLocalElement = currentFunction.getAndFreeTempLocal(this.currentType, false); let returnType = indexedGet.signature.returnType; this.currentFunction.freeTempLocal(tempLocalTarget); return module.createBlock(null, [ @@ -4620,7 +4665,7 @@ export class Compiler extends DiagnosticEmitter { if (name !== null && inferredTypes.has(name)) { let inferredType = inferredTypes.get(name); if (inferredType) { - argumentExprs[i] = this.compileExpressionRetainType(argumentExpression, inferredType); + argumentExprs[i] = this.compileExpressionRetainType(argumentExpression, inferredType, WrapMode.NONE); let commonType: Type | null; if (!(commonType = Type.commonCompatible(inferredType, this.currentType, true))) { if (!(commonType = Type.commonCompatible(inferredType, this.currentType, false))) { @@ -4633,7 +4678,7 @@ export class Compiler extends DiagnosticEmitter { } inferredType = commonType; } else { - argumentExprs[i] = this.compileExpressionRetainType(argumentExpression, Type.i32); + argumentExprs[i] = this.compileExpressionRetainType(argumentExpression, Type.i32, WrapMode.NONE); inferredType = this.currentType; // ++numInferred; } @@ -4645,7 +4690,12 @@ export class Compiler extends DiagnosticEmitter { true ); if (!concreteType) return module.createUnreachable(); - argumentExprs[i] = this.compileExpression(argumentExpression, concreteType); + argumentExprs[i] = this.compileExpression( + argumentExpression, + concreteType, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); } } let resolvedTypeArguments = new Array(numTypeParameters); @@ -4677,7 +4727,8 @@ export class Compiler extends DiagnosticEmitter { if (instance.is(CommonFlags.INSTANCE)) { thisExpr = this.compileExpressionRetainType( assert(this.program.resolvedThisExpression), - this.options.usizeType + this.options.usizeType, + WrapMode.NONE ); } @@ -4721,7 +4772,8 @@ export class Compiler extends DiagnosticEmitter { let thisExpression = assert(this.program.resolvedThisExpression); let thisExpr = this.compileExpressionRetainType( thisExpression, - this.options.usizeType + this.options.usizeType, + WrapMode.NONE ); indexArg = module.createLoad( 4, @@ -4741,7 +4793,12 @@ export class Compiler extends DiagnosticEmitter { } case ElementKind.FUNCTION_TARGET: { signature = (target).signature; - indexArg = this.compileExpression(expression.expression, (target).type); + indexArg = this.compileExpression( + expression.expression, + (target).type, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); break; } case ElementKind.PROPERTY: // TODO @@ -4884,7 +4941,9 @@ export class Compiler extends DiagnosticEmitter { for (let i = 0; i < numArguments; ++i, ++index) { operands[index] = this.compileExpression( argumentExpressions[i], - parameterTypes[i] + parameterTypes[i], + ConversionKind.IMPLICIT, + WrapMode.NONE ); } assert(index == numArgumentsInclThis); @@ -4920,14 +4979,14 @@ export class Compiler extends DiagnosticEmitter { if (thisArg) { let parent = assert(instance.parent); assert(parent.kind == ElementKind.CLASS); - if (_BinaryenExpressionGetId(thisArg) == ExpressionId.GetLocal) { + if (getExpressionId(thisArg) == ExpressionId.GetLocal) { flow.addScopedLocalAlias( - _BinaryenGetLocalGetIndex(thisArg), + getGetLocalIndex(thisArg), (parent).type, "this" ); } else { - let thisLocal = flow.addScopedLocal((parent).type, "this"); + let thisLocal = flow.addScopedLocal((parent).type, "this", false); body.push( module.createSetLocal(thisLocal.index, thisArg) ); @@ -4937,16 +4996,23 @@ export class Compiler extends DiagnosticEmitter { for (let i = 0; i < numArguments; ++i) { let paramExpr = this.compileExpression( argumentExpressions[i], - parameterTypes[i] + parameterTypes[i], + ConversionKind.IMPLICIT, + WrapMode.NONE ); - if (_BinaryenExpressionGetId(paramExpr) == ExpressionId.GetLocal) { + if (getExpressionId(paramExpr) == ExpressionId.GetLocal) { flow.addScopedLocalAlias( - _BinaryenGetLocalGetIndex(paramExpr), + getGetLocalIndex(paramExpr), parameterTypes[i], signature.getParameterName(i) ); + // inherits wrap status } else { - let argumentLocal = flow.addScopedLocal(parameterTypes[i], signature.getParameterName(i)); + let argumentLocal = flow.addScopedLocal( + parameterTypes[i], + signature.getParameterName(i), + !flow.canOverflow(paramExpr, parameterTypes[i]) + ); body.push( module.createSetLocal(argumentLocal.index, paramExpr) ); @@ -4957,14 +5023,19 @@ export class Compiler extends DiagnosticEmitter { currentFunction.flow = flow; var numParameters = signature.parameterTypes.length; for (let i = numArguments; i < numParameters; ++i) { - let argumentLocal = flow.addScopedLocal(parameterTypes[i], signature.getParameterName(i)); + let initExpr = this.compileExpression( + assert(declaration.signature.parameterTypes[i].initializer), + parameterTypes[i], + ConversionKind.IMPLICIT, + WrapMode.WRAP + ); + let argumentLocal = flow.addScopedLocal( + parameterTypes[i], + signature.getParameterName(i), + !flow.canOverflow(initExpr, parameterTypes[i]) + ); body.push( - module.createSetLocal(argumentLocal.index, - this.compileExpression( - assert(declaration.signature.parameterTypes[i].initializer), - parameterTypes[i] - ) - ) + module.createSetLocal(argumentLocal.index, initExpr) ); } @@ -5100,7 +5171,9 @@ export class Compiler extends DiagnosticEmitter { module.createSetLocal(operandIndex, this.compileExpression( assert(originalParameterDeclarations[minArguments + i].initializer), - type + type, + ConversionKind.IMPLICIT, + WrapMode.WRAP ) ) ]); @@ -5196,8 +5269,11 @@ export class Compiler extends DiagnosticEmitter { operands.push(parameterTypes[i].toNativeZero(module)); } if (!isCallImport) { // call the trampoline + let original = instance; instance = this.ensureTrampoline(instance); if (!this.compileFunction(instance)) return module.createUnreachable(); + instance.flow.flags = original.flow.flags; + this.program.instancesLookup.set(instance.internalName, instance); // so canOverflow can find it let nativeReturnType = returnType.toNativeType(); this.currentType = returnType; return module.createBlock(null, [ @@ -5209,9 +5285,9 @@ export class Compiler extends DiagnosticEmitter { // otherwise just call through this.currentType = returnType; - return isCallImport - ? module.createCallImport(instance.internalName, operands, returnType.toNativeType()) - : module.createCall(instance.internalName, operands, returnType.toNativeType()); + if (isCallImport) return module.createCallImport(instance.internalName, operands, returnType.toNativeType()); + var ret = module.createCall(instance.internalName, operands, returnType.toNativeType()); + return ret; } /** Compiles an indirect call using an index argument and a signature. */ @@ -5244,7 +5320,9 @@ export class Compiler extends DiagnosticEmitter { for (let i = 0; i < numArguments; ++i, ++index) { operands[index] = this.compileExpression( argumentExpressions[i], - parameterTypes[i] + parameterTypes[i], + ConversionKind.IMPLICIT, + WrapMode.NONE ); } assert(index == numArgumentsInclThis); @@ -5292,7 +5370,7 @@ export class Compiler extends DiagnosticEmitter { module.createI32(numArguments) ), module.createCallIndirect(indexArg, operands, signature.toSignatureString()) - ], returnType.toNativeType()); + ], returnType.toNativeType()); // not necessarily wrapped } compileCommaExpression(expression: CommaExpression, contextualType: Type): ExpressionRef { @@ -5300,9 +5378,19 @@ export class Compiler extends DiagnosticEmitter { var numExpressions = expressions.length; var exprs = new Array(numExpressions--); for (let i = 0; i < numExpressions; ++i) { - exprs[i] = this.compileExpression(expressions[i], Type.void); // drop all + exprs[i] = this.compileExpression( + expressions[i], + Type.void, // drop all + ConversionKind.EXPLICIT, + WrapMode.NONE + ); } - exprs[numExpressions] = this.compileExpression(expressions[numExpressions], contextualType); // except last + exprs[numExpressions] = this.compileExpression( + expressions[numExpressions], + contextualType, // except last + ConversionKind.IMPLICIT, + WrapMode.NONE + ); return this.module.createBlock(null, exprs, this.currentType.toNativeType()); } @@ -5320,7 +5408,12 @@ export class Compiler extends DiagnosticEmitter { ); return this.module.createUnreachable(); } - let thisArg = this.compileExpression(expression.expression, (target).type); + let thisArg = this.compileExpression( + expression.expression, + (target).type, + ConversionKind.IMPLICIT, + WrapMode.NONE + ); return this.compileCallDirect(indexedGet, [ expression.elementExpression ], expression, thisArg); @@ -5377,6 +5470,8 @@ export class Compiler extends DiagnosticEmitter { retainConstantType: bool ): ExpressionRef { var module = this.module; + var currentFunction = this.currentFunction; + // check special keywords first switch (expression.kind) { case NodeKind.NULL: { @@ -5397,7 +5492,6 @@ export class Compiler extends DiagnosticEmitter { return module.createI32(0); } case NodeKind.THIS: { - let currentFunction = this.currentFunction; let flow = currentFunction.flow; if (flow.is(FlowFlags.INLINE_CONTEXT)) { let scopedThis = flow.getScopedLocal("this"); @@ -5431,7 +5525,6 @@ export class Compiler extends DiagnosticEmitter { return module.createUnreachable(); } case NodeKind.SUPER: { - let currentFunction = this.currentFunction; let flow = currentFunction.flow; if (flow.is(FlowFlags.INLINE_CONTEXT)) { let scopedThis = flow.getScopedLocal("this"); @@ -5466,7 +5559,7 @@ export class Compiler extends DiagnosticEmitter { // otherwise resolve var target = this.program.resolveIdentifier( // reports expression, - this.currentFunction, + currentFunction, this.currentEnum ); if (!target) return module.createUnreachable(); @@ -5512,7 +5605,7 @@ export class Compiler extends DiagnosticEmitter { case ElementKind.FUNCTION_PROTOTYPE: { let instance = (target).resolve( null, - this.currentFunction.flow.contextualTypeArguments + currentFunction.flow.contextualTypeArguments ); if (!(instance && this.compileFunction(instance))) return module.createUnreachable(); let index = this.ensureFunctionTableEntry(instance); @@ -5633,10 +5726,6 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); return module.createUnreachable(); } } @@ -5735,10 +5824,6 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - reportNode.range - ); return module.createUnreachable(); } } @@ -5748,35 +5833,33 @@ export class Compiler extends DiagnosticEmitter { let expr: BinaryenExpressionRef; for (let i = 0; i < elementCount; ++i) { exprs[i] = expressions[i] - ? this.compileExpression(expressions[i], elementType) + ? this.compileExpression(expressions[i], elementType, ConversionKind.IMPLICIT, WrapMode.NONE) : elementType.toNativeZero(module); if (isStatic) { expr = this.precomputeExpressionRef(exprs[i]); - if (_BinaryenExpressionGetId(expr) == ExpressionId.Const) { - assert(_BinaryenExpressionGetType(expr) == nativeElementType); + if (getExpressionId(expr) == ExpressionId.Const) { + assert(getExpressionType(expr) == nativeElementType); switch (nativeElementType) { case NativeType.I32: { - changetype(values)[i] = _BinaryenConstGetValueI32(expr); + changetype(values)[i] = getConstValueI32(expr); break; } case NativeType.I64: { changetype(values)[i] = i64_new( - _BinaryenConstGetValueI64Low(expr), - _BinaryenConstGetValueI64High(expr) + getConstValueI64Low(expr), + getConstValueI64High(expr) ); break; } case NativeType.F32: { - changetype(values)[i] = _BinaryenConstGetValueF32(expr); + changetype(values)[i] = getConstValueF32(expr); break; } case NativeType.F64: { - changetype(values)[i] = _BinaryenConstGetValueF64(expr); + changetype(values)[i] = getConstValueF64(expr); break; } - default: { - assert(false); // checked above - } + default: assert(false); // checked above } } else { // TODO: emit a warning if declared 'const' @@ -5849,10 +5932,6 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - reportNode.range - ); return module.createUnreachable(); } } @@ -5881,7 +5960,7 @@ export class Compiler extends DiagnosticEmitter { } let nativeArrayType = arrayType.toNativeType(); let currentFunction = this.currentFunction; - let tempLocal = currentFunction.getTempLocal(arrayType); + let tempLocal = currentFunction.getTempLocal(arrayType, false); let stmts = new Array(2 + elementCount); let index = 0; stmts[index++] = module.createSetLocal(tempLocal.index, @@ -5965,15 +6044,14 @@ export class Compiler extends DiagnosticEmitter { compileParenthesizedExpression( expression: ParenthesizedExpression, - contextualType: Type, - wrapSmallIntegers: bool = true + contextualType: Type ): ExpressionRef { // does not change types, just order return this.compileExpression( expression.expression, contextualType, ConversionKind.NONE, - wrapSmallIntegers + WrapMode.NONE ); } @@ -6023,7 +6101,8 @@ export class Compiler extends DiagnosticEmitter { assert((target).memoryOffset >= 0); let thisExpr = this.compileExpressionRetainType( thisExpression, - this.options.usizeType + this.options.usizeType, + WrapMode.NONE ); this.currentType = (target).type; return module.createLoad( @@ -6054,7 +6133,8 @@ export class Compiler extends DiagnosticEmitter { let thisExpression = assert(program.resolvedThisExpression); let thisExpr = this.compileExpressionRetainType( thisExpression, - this.options.usizeType + this.options.usizeType, + WrapMode.NONE ); this.currentType = signature.returnType; return this.compileCallDirect(instance, [], propertyAccess, thisExpr); @@ -6084,7 +6164,7 @@ export class Compiler extends DiagnosticEmitter { var currentFunction = this.currentFunction; var condExpr = this.makeIsTrueish( - this.compileExpression(expression.condition, Type.u32, ConversionKind.NONE), + this.compileExpressionRetainType(expression.condition, Type.bool, WrapMode.NONE), this.currentType ); @@ -6095,17 +6175,17 @@ export class Compiler extends DiagnosticEmitter { // Try to eliminate unnecesssary branches if the condition is constant let condExprPrecomp = this.precomputeExpressionRef(condExpr); if ( - _BinaryenExpressionGetId(condExprPrecomp) == ExpressionId.Const && - _BinaryenExpressionGetType(condExprPrecomp) == NativeType.I32 + getExpressionId(condExprPrecomp) == ExpressionId.Const && + getExpressionType(condExprPrecomp) == NativeType.I32 ) { - return _BinaryenConstGetValueI32(condExprPrecomp) - ? this.compileExpression(ifThen, contextualType) - : this.compileExpression(ifElse, contextualType); + return getConstValueI32(condExprPrecomp) + ? this.compileExpression(ifThen, contextualType, ConversionKind.IMPLICIT, WrapMode.NONE) + : this.compileExpression(ifElse, contextualType, ConversionKind.IMPLICIT, WrapMode.NONE); // Otherwise recompile to the original and let the optimizer decide } else /* if (condExpr != condExprPrecomp) <- not guaranteed */ { condExpr = this.makeIsTrueish( - this.compileExpression(expression.condition, Type.u32, ConversionKind.NONE), + this.compileExpressionRetainType(expression.condition, Type.bool, WrapMode.NONE), this.currentType ); } @@ -6122,7 +6202,7 @@ export class Compiler extends DiagnosticEmitter { flow = flow.enterBranchOrScope(); currentFunction.flow = flow; - ifThenExpr = this.compileExpressionRetainType(ifThen, contextualType); + ifThenExpr = this.compileExpressionRetainType(ifThen, contextualType, WrapMode.NONE); ifThenType = this.currentType; let ifThenAllocates = flow.is(FlowFlags.ALLOCATES); flow = flow.leaveBranchOrScope(); @@ -6130,7 +6210,7 @@ export class Compiler extends DiagnosticEmitter { flow = flow.enterBranchOrScope(); currentFunction.flow = flow; - ifElseExpr = this.compileExpressionRetainType(ifElse, contextualType); + ifElseExpr = this.compileExpressionRetainType(ifElse, contextualType, WrapMode.NONE); ifElseType = this.currentType; let ifElseAllocates = flow.is(FlowFlags.ALLOCATES); flow = flow.leaveBranchOrScope(); @@ -6140,9 +6220,9 @@ export class Compiler extends DiagnosticEmitter { // otherwise simplify } else { - ifThenExpr = this.compileExpressionRetainType(ifThen, contextualType); + ifThenExpr = this.compileExpressionRetainType(ifThen, contextualType, WrapMode.NONE); ifThenType = this.currentType; - ifElseExpr = this.compileExpressionRetainType(ifElse, contextualType); + ifElseExpr = this.compileExpressionRetainType(ifElse, contextualType, WrapMode.NONE); ifElseType = this.currentType; } var commonType = Type.commonCompatible(ifThenType, ifElseType, false); @@ -6154,8 +6234,22 @@ export class Compiler extends DiagnosticEmitter { this.currentType = contextualType; return this.module.createUnreachable(); } - ifThenExpr = this.convertExpression(ifThenExpr, ifThenType, commonType, ConversionKind.IMPLICIT, ifThen); - ifElseExpr = this.convertExpression(ifElseExpr, ifElseType, commonType, ConversionKind.IMPLICIT, ifElse); + ifThenExpr = this.convertExpression( + ifThenExpr, + ifThenType, + commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + ifThen + ); + ifElseExpr = this.convertExpression( + ifElseExpr, + ifElseType, + commonType, + ConversionKind.IMPLICIT, + WrapMode.NONE, + ifElse + ); this.currentType = commonType; return this.module.createIf(condExpr, ifThenExpr, ifElseExpr); } @@ -6171,9 +6265,9 @@ export class Compiler extends DiagnosticEmitter { ? Type.i32 : contextualType, ConversionKind.NONE, - false // wrapped below + WrapMode.NONE ); - if (_BinaryenExpressionGetId(getValue) == ExpressionId.Unreachable) { + if (getExpressionId(getValue) == ExpressionId.Unreachable) { // shortcut if compiling the getter already failed return getValue; } @@ -6182,7 +6276,6 @@ export class Compiler extends DiagnosticEmitter { var op: BinaryOp; var nativeType: NativeType; var nativeOne: ExpressionRef; - var possiblyOverflows = false; switch (expression.operator) { case Token.PLUS_PLUS: { @@ -6196,10 +6289,11 @@ export class Compiler extends DiagnosticEmitter { switch (currentType.kind) { case TypeKind.I8: case TypeKind.I16: + case TypeKind.I32: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; - default: { + case TypeKind.U32: + case TypeKind.BOOL: { op = BinaryOp.AddI32; nativeType = NativeType.I32; nativeOne = module.createI32(1); @@ -6234,12 +6328,8 @@ export class Compiler extends DiagnosticEmitter { nativeOne = module.createF64(1); break; } - case TypeKind.VOID: { + default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); return module.createUnreachable(); } } @@ -6256,10 +6346,11 @@ export class Compiler extends DiagnosticEmitter { switch (currentType.kind) { case TypeKind.I8: case TypeKind.I16: + case TypeKind.I32: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; - default: { + case TypeKind.U32: + case TypeKind.BOOL: { op = BinaryOp.SubI32; nativeType = NativeType.I32; nativeOne = module.createI32(1); @@ -6294,12 +6385,8 @@ export class Compiler extends DiagnosticEmitter { nativeOne = module.createF64(1); break; } - case TypeKind.VOID: { + default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); return module.createUnreachable(); } } @@ -6307,62 +6394,46 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); return module.createUnreachable(); } } - var setValue: ExpressionRef; - var tempLocal: Local | null = null; - // simplify if dropped anyway if (contextualType == Type.void) { - setValue = module.createBinary(op, - getValue, - nativeOne + return this.compileAssignmentWithValue(expression.operand, + module.createBinary(op, + getValue, + nativeOne + ), + false ); + } - // otherwise use a temp local for the intermediate value - } else { - tempLocal = currentFunction.getTempLocal(currentType); - setValue = module.createBinary(op, + // otherwise use a temp local for the intermediate value (always possibly overflows) + var tempLocal = currentFunction.getTempLocal(currentType, false); + var setValue = this.compileAssignmentWithValue(expression.operand, + module.createBinary(op, this.module.createGetLocal(tempLocal.index, nativeType), nativeOne - ); - } - - if (possiblyOverflows) { - assert(currentType.is(TypeFlags.SHORT | TypeFlags.INTEGER)); - setValue = this.makeSmallIntegerWrap(setValue, currentType); - } - - setValue = this.compileAssignmentWithValue(expression.operand, setValue, false); - // ^ sets currentType = void - if (contextualType == Type.void) { - assert(!tempLocal); - return setValue; - } - + ), + false + ); this.currentType = assert(tempLocal).type; currentFunction.freeTempLocal(tempLocal); + var localIndex = (tempLocal).index; return module.createBlock(null, [ module.createSetLocal(localIndex, getValue), setValue, module.createGetLocal(localIndex, nativeType) - ], nativeType); + ], nativeType); // result of 'x++' / 'x--' might overflow } compileUnaryPrefixExpression( expression: UnaryPrefixExpression, - contextualType: Type, - wrapSmallIntegers: bool = true + contextualType: Type ): ExpressionRef { var module = this.module; - var possiblyOverflows = false; var compound = false; var expr: ExpressionRef; @@ -6381,9 +6452,8 @@ export class Compiler extends DiagnosticEmitter { ? Type.i32 : contextualType, ConversionKind.NONE, - false // wrapped below + WrapMode.NONE ); - possiblyOverflows = this.currentType.is(TypeFlags.SHORT | TypeFlags.INTEGER); // if operand already did break; } case Token.MINUS: { @@ -6409,15 +6479,16 @@ export class Compiler extends DiagnosticEmitter { ? Type.i32 : contextualType, ConversionKind.NONE, - false // wrapped below + WrapMode.NONE ); switch (this.currentType.kind) { case TypeKind.I8: case TypeKind.I16: + case TypeKind.I32: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; // or if operand already did - default: { + case TypeKind.U32: + case TypeKind.BOOL: { expr = module.createBinary(BinaryOp.SubI32, module.createI32(0), expr); break; } @@ -6454,6 +6525,10 @@ export class Compiler extends DiagnosticEmitter { expr = module.createUnary(UnaryOp.NegF64, expr); break; } + default: { + assert(false); + expr = module.createUnreachable(); + } } } break; @@ -6473,15 +6548,16 @@ export class Compiler extends DiagnosticEmitter { ? Type.i32 : contextualType, ConversionKind.NONE, - false // wrapped below + WrapMode.NONE ); switch (this.currentType.kind) { case TypeKind.I8: case TypeKind.I16: + case TypeKind.I32: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; // or if operand already did - default: { + case TypeKind.U32: + case TypeKind.BOOL: { expr = module.createBinary(BinaryOp.AddI32, expr, this.module.createI32(1)); break; } @@ -6518,6 +6594,10 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.AddF64, expr, module.createF64(1)); break; } + default: { + assert(false); + expr = module.createUnreachable(); + } } break; } @@ -6536,15 +6616,16 @@ export class Compiler extends DiagnosticEmitter { ? Type.i32 : contextualType, ConversionKind.NONE, - false // wrapped below + WrapMode.NONE ); switch (this.currentType.kind) { case TypeKind.I8: case TypeKind.I16: + case TypeKind.I32: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; // or if operand already did - default: { + case TypeKind.U32: + case TypeKind.BOOL: { expr = module.createBinary(BinaryOp.SubI32, expr, module.createI32(1)); break; } @@ -6581,6 +6662,10 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.SubF64, expr, module.createF64(1)); break; } + default: { + assert(false); + expr = module.createUnreachable(); + } } break; } @@ -6591,7 +6676,7 @@ export class Compiler extends DiagnosticEmitter { ? Type.i32 : contextualType, ConversionKind.NONE, - true // must wrap small integers + WrapMode.NONE ); expr = this.makeIsFalseish(expr, this.currentType); this.currentType = Type.bool; @@ -6615,15 +6700,16 @@ export class Compiler extends DiagnosticEmitter { contextualType == Type.void ? ConversionKind.NONE : ConversionKind.IMPLICIT, - false // retains low bits of small integers + WrapMode.NONE ); switch (this.currentType.kind) { case TypeKind.I8: case TypeKind.I16: + case TypeKind.I32: case TypeKind.U8: case TypeKind.U16: - case TypeKind.BOOL: possiblyOverflows = true; // or if operand already did - default: { + case TypeKind.U32: + case TypeKind.BOOL: { expr = module.createBinary(BinaryOp.XorI32, expr, module.createI32(-1)); break; } @@ -6652,6 +6738,10 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.XorI64, expr, module.createI64(-1, -1)); break; } + default: { + assert(false); + expr = module.createUnreachable(); + } } break; } @@ -6669,65 +6759,68 @@ export class Compiler extends DiagnosticEmitter { } default: { assert(false); - this.error( - DiagnosticCode.Operation_not_supported, - expression.range - ); return module.createUnreachable(); } } - if (possiblyOverflows && wrapSmallIntegers) { - assert(this.currentType.is(TypeFlags.SHORT | TypeFlags.INTEGER)); - expr = this.makeSmallIntegerWrap(expr, this.currentType); - } return compound ? this.compileAssignmentWithValue(expression.operand, expr, contextualType != Type.void) : expr; } /** Makes sure that a 32-bit integer value is wrapped to a valid value of the specified type. */ - makeSmallIntegerWrap(expr: ExpressionRef, type: Type): ExpressionRef { + ensureSmallIntegerWrap(expr: ExpressionRef, type: Type): ExpressionRef { var module = this.module; + var flow = this.currentFunction.flow; switch (type.kind) { case TypeKind.I8: { // TODO: Use 'i32.extend8_s' once sign-extension-ops lands - expr = module.createBinary(BinaryOp.ShrI32, - module.createBinary(BinaryOp.ShlI32, - expr, + if (flow.canOverflow(expr, type)) { + expr = module.createBinary(BinaryOp.ShrI32, + module.createBinary(BinaryOp.ShlI32, + expr, + module.createI32(24) + ), module.createI32(24) - ), - module.createI32(24) - ); + ); + } break; } case TypeKind.I16: { // TODO: Use 'i32.extend16_s' once sign-extension-ops lands - expr = module.createBinary(BinaryOp.ShrI32, - module.createBinary(BinaryOp.ShlI32, - expr, + if (flow.canOverflow(expr, type)) { + expr = module.createBinary(BinaryOp.ShrI32, + module.createBinary(BinaryOp.ShlI32, + expr, + module.createI32(16) + ), module.createI32(16) - ), - module.createI32(16) - ); + ); + } break; } case TypeKind.U8: { - expr = module.createBinary(BinaryOp.AndI32, - expr, - module.createI32(0xff) - ); + if (flow.canOverflow(expr, type)) { + expr = module.createBinary(BinaryOp.AndI32, + expr, + module.createI32(0xff) + ); + } break; } case TypeKind.U16: { - expr = module.createBinary(BinaryOp.AndI32, - expr, - module.createI32(0xffff) - ); + if (flow.canOverflow(expr, type)) { + expr = module.createBinary(BinaryOp.AndI32, + expr, + module.createI32(0xffff) + ); + } break; } case TypeKind.BOOL: { - expr = module.createBinary(BinaryOp.AndI32, - expr, - module.createI32(0x1) - ); + if (flow.canOverflow(expr, type)) { + expr = module.createBinary(BinaryOp.AndI32, + expr, + module.createI32(0x1) + ); + } break; } } @@ -6738,7 +6831,16 @@ export class Compiler extends DiagnosticEmitter { makeIsFalseish(expr: ExpressionRef, type: Type): ExpressionRef { var module = this.module; switch (type.kind) { - default: { // any native i32 + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.U8: + case TypeKind.U16: + case TypeKind.BOOL: { + expr = this.ensureSmallIntegerWrap(expr, type); + // fall-through + } + case TypeKind.I32: + case TypeKind.U32: { return module.createUnary(UnaryOp.EqzI32, expr); } case TypeKind.I64: @@ -6755,7 +6857,7 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.F64: { return module.createBinary(BinaryOp.EqF64, expr, module.createF64(0)); } - case TypeKind.VOID: { + default: { assert(false); return module.createI32(1); } @@ -6766,7 +6868,16 @@ export class Compiler extends DiagnosticEmitter { makeIsTrueish(expr: ExpressionRef, type: Type): ExpressionRef { var module = this.module; switch (type.kind) { - default: { // any native i32 + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.U8: + case TypeKind.U16: + case TypeKind.BOOL: { + expr = this.ensureSmallIntegerWrap(expr, type); + // fall-through + } + case TypeKind.I32: + case TypeKind.U32: { return expr; } case TypeKind.I64: @@ -6785,7 +6896,7 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.F64: { return module.createBinary(BinaryOp.NeF64, expr, module.createF64(0)); } - case TypeKind.VOID: { + default: { assert(false); return module.createI32(0); } @@ -6799,7 +6910,7 @@ export class Compiler extends DiagnosticEmitter { var nativeSizeType = this.options.nativeSizeType; // allocate the necessary memory and tee the pointer to a temp. local for reuse - var tempLocal = currentFunction.getTempLocal(classInstance.type); + var tempLocal = currentFunction.getTempLocal(classInstance.type, false); var initializers = new Array(); initializers.push( module.createSetLocal(tempLocal.index, @@ -6819,7 +6930,12 @@ export class Compiler extends DiagnosticEmitter { if (fieldDeclaration.initializer) { // use initializer initializers.push(module.createStore(fieldType.byteSize, module.createGetLocal(tempLocal.index, nativeSizeType), - this.compileExpression(fieldDeclaration.initializer, fieldType), // reports + this.compileExpression( // reports + fieldDeclaration.initializer, + fieldType, + ConversionKind.IMPLICIT, + WrapMode.NONE + ), nativeFieldType, field.memoryOffset )); diff --git a/src/decompiler.ts b/src/decompiler.ts index 8f501132..e0c5bb2a 100644 --- a/src/decompiler.ts +++ b/src/decompiler.ts @@ -13,7 +13,48 @@ import { FunctionRef, ExpressionRef, Index, - readString + getFunctionName, + getFunctionBody, + getFunctionParamCount, + getFunctionParamType, + getFunctionResultType, + getExpressionId, + getExpressionType, + getBlockName, + getBlockChildCount, + getBlockChild, + getIfCondition, + getIfTrue, + getIfFalse, + getLoopName, + getLoopBody, + getBreakName, + getBreakCondition, + getGetLocalIndex, + getSetLocalIndex, + getSetLocalValue, + getLoadOffset, + getLoadPtr, + getStoreOffset, + getStorePtr, + getStoreValue, + getConstValueI32, + getConstValueI64Low, + getConstValueI64High, + getConstValueF32, + getConstValueF64, + getUnaryOp, + getUnaryValue, + getBinaryOp, + getBinaryLeft, + getBinaryRight, + getSelectThen, + getSelectElse, + getSelectCondition, + getDropValue, + getReturnValue, + getHostOp, + getHostOperand } from "./module"; // TODO :-) @@ -37,34 +78,34 @@ export class Decompiler { } decompileFunction(func: FunctionRef): void { - var name = readString(_BinaryenFunctionGetName(func)) || "$" + this.functionId.toString(10); - var body = _BinaryenFunctionGetBody(func); + var name = getFunctionName(func) || "$" + this.functionId.toString(10); + var body = getFunctionBody(func); this.push("function "); this.push(name); this.push("("); - for (let i: Index = 0, k: Index = _BinaryenFunctionGetNumParams(func); i < k; ++i) { + for (let i: Index = 0, k: Index = getFunctionParamCount(func); i < k; ++i) { if (i > 0) this.push(", "); this.push("$"); this.push(i.toString(10)); this.push(": "); - this.push(nativeTypeToType(_BinaryenFunctionGetParam(func, i))); + this.push(nativeTypeToType(getFunctionParamType(func, i))); } this.push("): "); - this.push(nativeTypeToType(_BinaryenFunctionGetResult(func))); + this.push(nativeTypeToType(getFunctionResultType(func))); this.push(" "); - if (_BinaryenExpressionGetId(body) != ExpressionId.Block) { + if (getExpressionId(body) != ExpressionId.Block) { this.push("{\n"); } this.decompileExpression(body); - if (_BinaryenExpressionGetId(body) != ExpressionId.Block) { + if (getExpressionId(body) != ExpressionId.Block) { this.push("\n}\n"); } ++this.functionId; } decompileExpression(expr: ExpressionRef): void { - var id = _BinaryenExpressionGetId(expr); - var type = _BinaryenExpressionGetType(expr); + var id = getExpressionId(expr); + var type = getExpressionType(expr); var nested: ExpressionRef; var string: string | null; @@ -72,14 +113,14 @@ export class Decompiler { switch (id) { case ExpressionId.Block: { // TODO: magic - if ((string = readString(_BinaryenBlockGetName(expr))) != null) { + if ((string = getBlockName(expr)) != null) { this.push(string); this.push(": "); } this.push("{\n"); - k = _BinaryenBlockGetNumChildren(expr); + k = getBlockChildCount(expr); for (i = 0; i < k; ++i) { - this.decompileExpression(_BinaryenBlockGetChild(expr, i)); + this.decompileExpression(getBlockChild(expr, i)); } this.push("}\n"); return; @@ -87,38 +128,38 @@ export class Decompiler { case ExpressionId.If: { if (type == NativeType.None) { this.push("if ("); - this.decompileExpression(_BinaryenIfGetCondition(expr)); + this.decompileExpression(getIfCondition(expr)); this.push(") "); - this.decompileExpression(_BinaryenIfGetIfTrue(expr)); - if (nested = _BinaryenIfGetIfFalse(expr)) { + this.decompileExpression(getIfTrue(expr)); + if (nested = getIfFalse(expr)) { this.push(" else "); this.decompileExpression(nested); } } else { - this.decompileExpression(_BinaryenIfGetCondition(expr)); + this.decompileExpression(getIfCondition(expr)); this.push(" ? "); - this.decompileExpression(_BinaryenIfGetIfTrue(expr)); + this.decompileExpression(getIfTrue(expr)); this.push(" : "); - this.decompileExpression(_BinaryenIfGetIfFalse(expr)); + this.decompileExpression(getIfFalse(expr)); } return; } case ExpressionId.Loop: { - if ((string = readString(_BinaryenLoopGetName(expr))) != null) { + if ((string = getLoopName(expr)) != null) { this.push(string); this.push(": "); } this.push("do "); - this.decompileExpression(_BinaryenLoopGetBody(expr)); + this.decompileExpression(getLoopBody(expr)); this.push("while (0);\n"); } case ExpressionId.Break: { - if (nested = _BinaryenBreakGetCondition(expr)) { + if (nested = getBreakCondition(expr)) { this.push("if ("); this.decompileExpression(nested); this.push(") "); } - if ((string = readString(_BinaryenBreakGetName(expr))) != null) { + if ((string = getBreakName(expr)) != null) { this.push("break "); this.push(string); this.push(";\n"); @@ -135,14 +176,14 @@ export class Decompiler { } case ExpressionId.GetLocal: { this.push("$"); - this.push(_BinaryenGetLocalGetIndex(expr).toString(10)); + this.push(getGetLocalIndex(expr).toString(10)); return; } case ExpressionId.SetLocal: { this.push("$"); - this.push(_BinaryenSetLocalGetIndex(expr).toString(10)); + this.push(getSetLocalIndex(expr).toString(10)); this.push(" = "); - this.decompileExpression(_BinaryenSetLocalGetValue(expr)); + this.decompileExpression(getSetLocalValue(expr)); return; } case ExpressionId.GetGlobal: @@ -153,9 +194,9 @@ export class Decompiler { this.push("load<"); this.push(nativeTypeToType(type)); this.push(">("); - this.push(_BinaryenLoadGetOffset(expr).toString(10)); + this.push(getLoadOffset(expr).toString(10)); this.push(" + "); - this.decompileExpression(_BinaryenLoadGetPtr(expr)); + this.decompileExpression(getLoadPtr(expr)); this.push(")"); return; } @@ -163,290 +204,290 @@ export class Decompiler { this.push("store<"); this.push(nativeTypeToType(type)); this.push(">("); - this.push(_BinaryenStoreGetOffset(expr).toString(10)); + this.push(getStoreOffset(expr).toString(10)); this.push(" + "); - this.decompileExpression(_BinaryenStoreGetPtr(expr)); + this.decompileExpression(getStorePtr(expr)); this.push(", "); - this.decompileExpression(_BinaryenStoreGetValue(expr)); + this.decompileExpression(getStoreValue(expr)); this.push(")"); return; } case ExpressionId.Const: { switch (type) { case NativeType.I32: { - this.push(_BinaryenConstGetValueI32(expr).toString(10)); + this.push(getConstValueI32(expr).toString(10)); return; } case NativeType.I64: { this.push( i64_to_string( i64_new( - _BinaryenConstGetValueI64Low(expr), - _BinaryenConstGetValueI64High(expr) + getConstValueI64Low(expr), + getConstValueI64High(expr) ) ) ); return; } case NativeType.F32: { - this.push(_BinaryenConstGetValueF32(expr).toString(10)); + this.push(getConstValueF32(expr).toString(10)); return; } case NativeType.F64: { - this.push(_BinaryenConstGetValueF64(expr).toString(10)); + this.push(getConstValueF64(expr).toString(10)); return; } } break; } case ExpressionId.Unary: { - switch (_BinaryenUnaryGetOp(expr)) { + switch (getUnaryOp(expr)) { case UnaryOp.ClzI32: { this.push("clz("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.CtzI32: { this.push("ctz("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.PopcntI32: { this.push("popcnt("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.NegF32: case UnaryOp.NegF64: { this.push("-"); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.AbsF32: { this.push("abs("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.CeilF32: { this.push("ceil("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.FloorF32: { this.push("floor("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.TruncF32: { this.push("trunc("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.NearestF32: { this.push("nearest("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.SqrtF32: { this.push("sqrt("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.EqzI32: case UnaryOp.EqzI64: { this.push("!"); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ClzI64: { this.push("clz("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.CtzI64: { this.push("ctz("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.PopcntI64: { this.push("popcnt("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.AbsF64: { this.push("abs("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.CeilF64: { this.push("ceil("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.FloorF64: { this.push("floor("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.TruncF64: { this.push("trunc("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.NearestF64: { this.push("nearest("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.SqrtF64: { this.push("sqrt("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.ExtendI32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ExtendU32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.WrapI64: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.TruncF32ToI32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.TruncF32ToI64: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.TruncF32ToU32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.TruncF32ToU64: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.TruncF64ToI32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.TruncF64ToI64: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.TruncF64ToU32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.TruncF64ToU64: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ReinterpretF32: { this.push("reinterpret("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.ReinterpretF64: { this.push("reinterpret("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.ConvertI32ToF32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ConvertI32ToF64: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ConvertU32ToF32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ConvertU32ToF64: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ConvertI64ToF32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ConvertI64ToF64: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ConvertU64ToF32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ConvertU64ToF64: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.PromoteF32: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.DemoteF64: { this.push(""); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); return; } case UnaryOp.ReinterpretI32: { this.push("reinterpret("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } case UnaryOp.ReinterpretI64: { this.push("reinterpret("); - this.decompileExpression(_BinaryenUnaryGetValue(expr)); + this.decompileExpression(getUnaryValue(expr)); this.push(")"); return; } @@ -454,121 +495,121 @@ export class Decompiler { break; } case ExpressionId.Binary: { // TODO: precedence - switch (_BinaryenBinaryGetOp(expr)) { + switch (getBinaryOp(expr)) { case BinaryOp.AddI32: case BinaryOp.AddI64: case BinaryOp.AddF32: case BinaryOp.AddF64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" + "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.SubI32: case BinaryOp.SubI64: case BinaryOp.SubF32: case BinaryOp.SubF64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" - "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.MulI32: case BinaryOp.MulI64: case BinaryOp.MulF32: case BinaryOp.MulF64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" * "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.DivI32: case BinaryOp.DivI64: case BinaryOp.DivF32: case BinaryOp.DivF64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" / "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.DivU32: { this.push("("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" / "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } case BinaryOp.RemI32: case BinaryOp.RemI64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" % "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.RemU32: { this.push("("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" / "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } case BinaryOp.AndI32: case BinaryOp.AndI64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" & "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.OrI32: case BinaryOp.OrI64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" | "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.XorI32: case BinaryOp.XorI64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" ^ "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.ShlI32: case BinaryOp.ShlI64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" << "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.ShrU32: case BinaryOp.ShrU64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" >>> "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.ShrI32: case BinaryOp.ShrI64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" >> "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.RotlI32: { this.push("rotl("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(", "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } case BinaryOp.RotrI32: { this.push("rotr("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(", "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } @@ -576,187 +617,187 @@ export class Decompiler { case BinaryOp.EqI64: case BinaryOp.EqF32: case BinaryOp.EqF64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" == "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.NeI32: case BinaryOp.NeI64: case BinaryOp.NeF32: case BinaryOp.NeF64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" != "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.LtI32: case BinaryOp.LtI64: case BinaryOp.LtF32: case BinaryOp.LtF64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" < "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.LtU32: { this.push(""); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" < "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.LeI32: case BinaryOp.LeI64: case BinaryOp.LeF32: case BinaryOp.LeF64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" <= "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.LeU32: { this.push(""); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" <= "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.GtI32: case BinaryOp.GtI64: case BinaryOp.GtF32: case BinaryOp.GtF64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" > "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.GtU32: { this.push(""); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" > "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.GeI32: case BinaryOp.GeI64: case BinaryOp.GeF32: case BinaryOp.GeF64: { - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" >= "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.GeU32: { this.push(""); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" >= "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.DivU64: { this.push(""); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" / "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.RemU64: { this.push(""); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" % "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.RotlI64: { this.push("rotl("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(", "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } case BinaryOp.RotrI64: { this.push("rotr("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(", "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } case BinaryOp.LtU64: { this.push(""); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" < "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.LeU64: { this.push(""); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" <= "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.GtU64: { this.push(""); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" > "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.GeU64: { this.push(""); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(" >= "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); return; } case BinaryOp.CopysignF32: { this.push("copysign("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(", "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } case BinaryOp.MinF32: { this.push("min("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(", "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } case BinaryOp.MaxF32: { this.push("max("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(", "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } case BinaryOp.CopysignF64: { this.push("copysign("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(", "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } case BinaryOp.MinF64: { this.push("min("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(", "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } case BinaryOp.MaxF64: { this.push("max("); - this.decompileExpression(_BinaryenBinaryGetLeft(expr)); + this.decompileExpression(getBinaryLeft(expr)); this.push(", "); - this.decompileExpression(_BinaryenBinaryGetRight(expr)); + this.decompileExpression(getBinaryRight(expr)); this.push(")"); return; } @@ -767,21 +808,21 @@ export class Decompiler { this.push("select<"); this.push(nativeTypeToType(type)); this.push(">("); - this.decompileExpression(_BinaryenSelectGetIfTrue(expr)); + this.decompileExpression(getSelectThen(expr)); this.push(", "); - this.decompileExpression(_BinaryenSelectGetIfFalse(expr)); + this.decompileExpression(getSelectElse(expr)); this.push(", "); - this.decompileExpression(_BinaryenSelectGetCondition(expr)); + this.decompileExpression(getSelectCondition(expr)); this.push(")"); return; } case ExpressionId.Drop: { - this.decompileExpression(_BinaryenDropGetValue(expr)); + this.decompileExpression(getDropValue(expr)); this.push(";\n"); return; } case ExpressionId.Return: { - if (nested = _BinaryenReturnGetValue(expr)) { + if (nested = getReturnValue(expr)) { this.push("return "); this.decompileExpression(nested); this.push(";\n"); @@ -791,14 +832,14 @@ export class Decompiler { return; } case ExpressionId.Host: { - switch (_BinaryenHostGetOp(expr)) { + switch (getHostOp(expr)) { case HostOp.CurrentMemory: { this.push("current_memory()"); return; } case HostOp.GrowMemory: { this.push("grow_memory("); - this.decompileExpression(_BinaryenHostGetOperand(expr, 0)); + this.decompileExpression(getHostOperand(expr, 0)); this.push(")"); return; } diff --git a/src/glue/js/i64.d.ts b/src/glue/js/i64.d.ts index 5d80e81c..23ca983a 100644 --- a/src/glue/js/i64.d.ts +++ b/src/glue/js/i64.d.ts @@ -2,6 +2,9 @@ declare type I64 = { __Long__: true }; // opaque +declare const i64_zero: I64; +declare const i64_one: I64; + declare function i64_new(lo: i32, hi?: i32): I64; declare function i64_low(value: I64): i32; declare function i64_high(value: I64): i32; @@ -21,6 +24,9 @@ declare function i64_shr(left: I64, right: I64): I64; declare function i64_shr_u(left: I64, right: I64): I64; declare function i64_not(value: I64): I64; +declare function i64_eq(left: I64, right: I64): bool; +declare function i64_ne(left: I64, right: I64): bool; + declare function i64_align(value: I64, alignment: i32): I64; declare function i64_is_i8(value: I64): bool; diff --git a/src/glue/js/i64.js b/src/glue/js/i64.js index 06f52777..43385363 100644 --- a/src/glue/js/i64.js +++ b/src/glue/js/i64.js @@ -1,5 +1,9 @@ const Long = global.Long || require("long"); +global.i64_zero = Long.ZERO; + +global.i64_one = Long.ONE; + global.i64_new = function(lo, hi) { return Long.fromBits(lo, hi); }; @@ -68,6 +72,14 @@ global.i64_not = function(value) { return value.not(); }; +global.i64_eq = function(left, right) { + return left.eq(right); +}; + +global.i64_ne = function(left, right) { + return left.ne(right); +}; + global.i64_align = function(value, alignment) { assert(alignment && (alignment & (alignment - 1)) == 0); var mask = Long.fromInt(alignment - 1); diff --git a/src/glue/wasm/i64.ts b/src/glue/wasm/i64.ts index 67bb3247..633a5f0a 100644 --- a/src/glue/wasm/i64.ts +++ b/src/glue/wasm/i64.ts @@ -2,6 +2,12 @@ type I64 = i64; +@global +const i64_zero: I64 = 0; + +@global +const i64_one: I64 = 1; + @global function i64_new(lo: i32, hi: i32 = 0): I64 { return lo | (hi << 32); @@ -87,6 +93,16 @@ function i64_not(value: I64): I64 { return ~value; } +@global +function i64_eq(left: I64, right: I64): bool { + return left == right; +} + +@global +function i64_ne(left: I64, right: I64): bool { + return left != right; +} + @global function i64_align(value: I64, alignment: i64): I64 { var mask: i64 = alignment - 1; diff --git a/src/module.ts b/src/module.ts index a223827d..ac712349 100644 --- a/src/module.ts +++ b/src/module.ts @@ -346,7 +346,7 @@ export class Module { operands: ExpressionRef[] | null = null ): ExpressionRef { var cStr = allocString(name); - var cArr = allocI32Array(operands); + var cArr = allocPtrArray(operands); try { return _BinaryenHost(this.ref, op, cStr, cArr, operands ? (operands).length : 0); } finally { @@ -485,7 +485,7 @@ export class Module { type: NativeType = NativeType.None ): ExpressionRef { var cStr = allocString(label); - var cArr = allocI32Array(children); + var cArr = allocPtrArray(children); try { return _BinaryenBlock(this.ref, cStr, cArr, children.length, type); } finally { @@ -579,7 +579,7 @@ export class Module { returnType: NativeType ): ExpressionRef { var cStr = allocString(target); - var cArr = allocI32Array(operands); + var cArr = allocPtrArray(operands); try { return _BinaryenCall(this.ref, cStr, cArr, operands && operands.length || 0, returnType); } finally { @@ -594,7 +594,7 @@ export class Module { returnType: NativeType ): ExpressionRef { var cStr = allocString(target); - var cArr = allocI32Array(operands); + var cArr = allocPtrArray(operands); try { return _BinaryenCallImport(this.ref, cStr, cArr, operands && operands.length || 0, returnType); } finally { @@ -608,7 +608,7 @@ export class Module { operands: ExpressionRef[] | null, typeName: string ): ExpressionRef { - var cArr = allocI32Array(operands); + var cArr = allocPtrArray(operands); var cStr = allocString(typeName); try { return _BinaryenCallIndirect(this.ref, index, cArr, operands && operands.length || 0, cStr); @@ -843,7 +843,7 @@ export class Module { } setFunctionTable(funcs: FunctionRef[]): void { - var cArr = allocI32Array(funcs); + var cArr = allocPtrArray(funcs); try { _BinaryenSetFunctionTable(this.ref, cArr, funcs.length); } finally { @@ -943,7 +943,8 @@ export class Module { return Relooper.create(this); } - cloneExpression(expr: ExpressionRef, + cloneExpression( + expr: ExpressionRef, noSideEffects: bool = false, maxDepth: i32 = i32.MAX_VALUE ): ExpressionRef { // currently supports side effect free expressions only @@ -953,7 +954,7 @@ export class Module { var nested1: ExpressionRef, nested2: ExpressionRef; - switch (_BinaryenExpressionGetId(expr)) { + switch (_BinaryenExpressionGetId(expr)) { case ExpressionId.Const: { switch (_BinaryenExpressionGetType(expr)) { case NativeType.I32: { @@ -991,21 +992,23 @@ export class Module { if (!(nested1 = this.cloneExpression(_BinaryenLoadGetPtr(expr), noSideEffects, maxDepth))) { break; } - return _BinaryenLoadIsAtomic(expr) - ? _BinaryenAtomicLoad(this.ref, - _BinaryenLoadGetBytes(expr), - _BinaryenLoadGetOffset(expr), - _BinaryenExpressionGetType(expr), - nested1 - ) - : _BinaryenLoad(this.ref, - _BinaryenLoadGetBytes(expr), - _BinaryenLoadIsSigned(expr) ? 1 : 0, - _BinaryenLoadGetOffset(expr), - _BinaryenLoadGetAlign(expr), - _BinaryenExpressionGetType(expr), - nested1 - ); + return ( + _BinaryenLoadIsAtomic(expr) + ? _BinaryenAtomicLoad(this.ref, + _BinaryenLoadGetBytes(expr), + _BinaryenLoadGetOffset(expr), + _BinaryenExpressionGetType(expr), + nested1 + ) + : _BinaryenLoad(this.ref, + _BinaryenLoadGetBytes(expr), + _BinaryenLoadIsSigned(expr) ? 1 : 0, + _BinaryenLoadGetOffset(expr), + _BinaryenLoadGetAlign(expr), + _BinaryenExpressionGetType(expr), + nested1 + ) + ); } case ExpressionId.Unary: { if (!(nested1 = this.cloneExpression(_BinaryenUnaryGetValue(expr), noSideEffects, maxDepth))) { @@ -1052,6 +1055,206 @@ export class Module { } } +// expressions + +export function getExpressionId(expr: ExpressionRef): ExpressionId { + return _BinaryenExpressionGetId(expr); +} + +export function getExpressionType(expr: ExpressionRef): NativeType { + return _BinaryenExpressionGetType(expr); +} + +export function getConstValueI32(expr: ExpressionRef): i32 { + return _BinaryenConstGetValueI32(expr); +} + +export function getConstValueI64Low(expr: ExpressionRef): i32 { + return _BinaryenConstGetValueI64Low(expr); +} + +export function getConstValueI64High(expr: ExpressionRef): i32 { + return _BinaryenConstGetValueI64High(expr); +} + +export function getConstValueF32(expr: ExpressionRef): f32 { + return _BinaryenConstGetValueF32(expr); +} + +export function getConstValueF64(expr: ExpressionRef): f32 { + return _BinaryenConstGetValueF64(expr); +} + +export function getGetLocalIndex(expr: ExpressionRef): Index { + return _BinaryenGetLocalGetIndex(expr); +} + +export function getSetLocalIndex(expr: ExpressionRef): Index { + return _BinaryenSetLocalGetIndex(expr); +} + +export function getSetLocalValue(expr: ExpressionRef): ExpressionRef { + return _BinaryenSetLocalGetValue(expr); +} + +export function isTeeLocal(expr: ExpressionRef): bool { + return _BinaryenSetLocalIsTee(expr); +} + +export function getBinaryOp(expr: ExpressionRef): BinaryOp { + return _BinaryenBinaryGetOp(expr); +} + +export function getBinaryLeft(expr: ExpressionRef): ExpressionRef { + return _BinaryenBinaryGetLeft(expr); +} + +export function getBinaryRight(expr: ExpressionRef): ExpressionRef { + return _BinaryenBinaryGetRight(expr); +} + +export function getUnaryOp(expr: ExpressionRef): UnaryOp { + return _BinaryenUnaryGetOp(expr); +} + +export function getUnaryValue(expr: ExpressionRef): ExpressionRef { + return _BinaryenUnaryGetValue(expr); +} + +export function getLoadBytes(expr: ExpressionRef): u32 { + return _BinaryenLoadGetBytes(expr); +} + +export function getLoadOffset(expr: ExpressionRef): u32 { + return _BinaryenLoadGetOffset(expr); +} + +export function getLoadPtr(expr: ExpressionRef): ExpressionRef { + return _BinaryenLoadGetPtr(expr); +} + +export function isLoadSigned(expr: ExpressionRef): bool { + return _BinaryenLoadIsSigned(expr); +} + +export function getStoreBytes(expr: ExpressionRef): u32 { + return _BinaryenStoreGetBytes(expr); +} + +export function getStoreOffset(expr: ExpressionRef): u32 { + return _BinaryenStoreGetOffset(expr); +} + +export function getStorePtr(expr: ExpressionRef): ExpressionRef { + return _BinaryenStoreGetPtr(expr); +} + +export function getStoreValue(expr: ExpressionRef): ExpressionRef { + return _BinaryenStoreGetValue(expr); +} + +export function getBlockName(expr: ExpressionRef): string | null { + return readString(_BinaryenBlockGetName(expr)); +} + +export function getBlockChildCount(expr: ExpressionRef): Index { + return _BinaryenBlockGetNumChildren(expr); +} + +export function getBlockChild(expr: ExpressionRef, index: Index): ExpressionRef { + return _BinaryenBlockGetChild(expr, index); +} + +export function getIfCondition(expr: ExpressionRef): ExpressionRef { + return _BinaryenIfGetCondition(expr); +} + +export function getIfTrue(expr: ExpressionRef): ExpressionRef { + return _BinaryenIfGetIfTrue(expr); +} + +export function getIfFalse(expr: ExpressionRef): ExpressionRef { + return _BinaryenIfGetIfFalse(expr); +} + +export function getLoopName(expr: ExpressionRef): string | null { + return readString(_BinaryenLoopGetName(expr)); +} + +export function getLoopBody(expr: ExpressionRef): ExpressionRef { + return _BinaryenLoopGetBody(expr); +} + +export function getBreakName(expr: ExpressionRef): string | null { + return readString(_BinaryenBreakGetName(expr)); +} + +export function getBreakCondition(expr: ExpressionRef): ExpressionRef { + return _BinaryenBreakGetCondition(expr); +} + +export function getSelectThen(expr: ExpressionRef): ExpressionRef { + return _BinaryenSelectGetIfTrue(expr); +} + +export function getSelectElse(expr: ExpressionRef): ExpressionRef { + return _BinaryenSelectGetIfFalse(expr); +} + +export function getSelectCondition(expr: ExpressionRef): ExpressionRef { + return _BinaryenSelectGetCondition(expr); +} + +export function getDropValue(expr: ExpressionRef): ExpressionRef { + return _BinaryenDropGetValue(expr); +} + +export function getReturnValue(expr: ExpressionRef): ExpressionRef { + return _BinaryenReturnGetValue(expr); +} + +export function getCallTarget(expr: ExpressionRef): string | null { + return readString(_BinaryenCallGetTarget(expr)); +} + +export function getHostOp(expr: ExpressionRef): ExpressionRef { + return _BinaryenHostGetOp(expr); +} + +export function getHostOperandCount(expr: ExpressionRef): Index { + return _BinaryenHostGetNumOperands(expr); +} + +export function getHostOperand(expr: ExpressionRef, index: Index): ExpressionRef { + return _BinaryenHostGetOperand(expr, index); +} + +export function getHostName(expr: ExpressionRef): string | null { + return readString(_BinaryenHostGetNameOperand(expr)); +} + +// functions + +export function getFunctionBody(func: FunctionRef): ExpressionRef { + return _BinaryenFunctionGetBody(func); +} + +export function getFunctionName(func: FunctionRef): string | null { + return readString(_BinaryenFunctionGetName(func)); +} + +export function getFunctionParamCount(func: FunctionRef): Index { + return _BinaryenFunctionGetNumParams(func); +} + +export function getFunctionParamType(func: FunctionRef, index: Index): NativeType { + return _BinaryenFunctionGetParam(func, index); +} + +export function getFunctionResultType(func: FunctionRef): NativeType { + return _BinaryenFunctionGetResult(func); +} + export class Relooper { module: Module; @@ -1100,7 +1303,7 @@ export class Relooper { } // export function hasSideEffects(expr: ExpressionRef): bool { -// switch (_BinaryenExpressionGetId(expr)) { +// switch (_BinaryenExpressionGetId(expr = getPtr(expr))) { // case ExpressionId.GetLocal: // case ExpressionId.GetGlobal: // case ExpressionId.Const: @@ -1168,6 +1371,10 @@ function allocI32Array(i32s: i32[] | null): usize { return ptr; } +function allocPtrArray(ptrs: usize[] | null): usize { + return allocI32Array(ptrs); // TODO: WASM64 one day +} + function stringLengthUTF8(str: string): usize { var len = 0; for (let i = 0, k = str.length; i < k; ++i) { diff --git a/src/program.ts b/src/program.ts index b2ebc9b5..09cc9082 100644 --- a/src/program.ts +++ b/src/program.ts @@ -15,6 +15,8 @@ import { import { Type, + TypeKind, + TypeFlags, Signature, typesToString @@ -69,6 +71,34 @@ import { Module, NativeType, FunctionRef, + ExpressionRef, + ExpressionId, + BinaryOp, + UnaryOp, + + getExpressionId, + getGetLocalIndex, + isTeeLocal, + getSetLocalValue, + getBinaryOp, + getConstValueI32, + getBinaryLeft, + getBinaryRight, + getUnaryOp, + getExpressionType, + getLoadBytes, + isLoadSigned, + getIfTrue, + getIfFalse, + getSelectThen, + getSelectElse, + getCallTarget, + getBlockChildCount, + getBlockChild, + getBlockName, + getConstValueF32, + getConstValueF64, + getConstValueI64Low } from "./module"; /** Path delimiter inserted between file system levels. */ @@ -173,6 +203,8 @@ export class Program extends DiagnosticEmitter { options: Options; /** Elements by internal name. */ elementsLookup: Map = new Map(); + /** Class and function instances by internal name. */ + instancesLookup: Map = new Map(); /** Types by internal name. */ typesLookup: Map = noTypesYet; /** Declared type aliases. */ @@ -2671,6 +2703,7 @@ export class FunctionPrototype extends Element { contextualTypeArguments ); this.instances.set(instanceKey, instance); + this.program.instancesLookup.set(internalName, instance); return instance; } @@ -2865,7 +2898,7 @@ export class Function extends Element { private tempF64s: Local[] | null = null; /** Gets a free temporary local of the specified type. */ - getTempLocal(type: Type): Local { + getTempLocal(type: Type, wrapped: bool): Local { var temps: Local[] | null; switch (type.toNativeType()) { case NativeType.I32: { @@ -2886,12 +2919,15 @@ export class Function extends Element { } default: throw new Error("concrete type expected"); } + var local: Local; if (temps && temps.length) { - let ret = temps.pop(); - ret.type = type; - return ret; + local = temps.pop(); + local.type = type; + } else { + local = this.addLocal(type); } - return this.addLocal(type); + this.flow.setLocalWrapped(local.index, wrapped); + return local; } /** Frees the temporary local for reuse. */ @@ -2924,7 +2960,7 @@ export class Function extends Element { } /** Gets and immediately frees a temporary local of the specified type. */ - getAndFreeTempLocal(type: Type): Local { + getAndFreeTempLocal(type: Type, wrapped: bool): Local { var temps: Local[]; switch (type.toNativeType()) { case NativeType.I32: { @@ -2945,11 +2981,15 @@ export class Function extends Element { } default: throw new Error("concrete type expected"); } - if (temps.length > 0) { - return temps[temps.length - 1]; + var local: Local; + if (temps.length) { + local = temps[temps.length - 1]; + local.type = type; + } else { + local = this.addLocal(type); + temps.push(local); } - var local: Local = this.addLocal(type); - temps.push(local); + this.flow.setLocalWrapped(local.index, wrapped); return local; } @@ -3201,6 +3241,7 @@ export class ClassPrototype extends Element { instance = new Class(this, simpleName, internalName, typeArguments, baseClass); instance.contextualTypeArguments = contextualTypeArguments; this.instances.set(instanceKey, instance); + this.program.instancesLookup.set(internalName, instance); var memoryOffset: u32 = 0; if (baseClass) { @@ -3541,7 +3582,9 @@ export const enum FlowFlags { /** This branch is part of inlining a function. */ INLINE_CONTEXT = 1 << 10, /** This branch explicitly requests no bounds checking. */ - UNCHECKED_CONTEXT = 1 << 11 + UNCHECKED_CONTEXT = 1 << 11, + /** This branch returns a properly wrapped value. */ + RETURNS_WRAPPED = 1 << 12 } /** A control flow evaluator. */ @@ -3565,8 +3608,10 @@ export class Flow { contextualTypeArguments: Map | null; /** Scoped local variables. */ scopedLocals: Map | null = null; - /** Scoped global variables. */ - // scopedGlobals: Map | null = null; + /** Local variable wrap states for the first 64 locals. */ + wrappedLocals: I64; + /** Local variable wrap states for locals with index >= 64. */ + wrappedLocalsExt: I64[] | null; /** Creates the parent flow of the specified function. */ static create(currentFunction: Function): Flow { @@ -3579,6 +3624,8 @@ export class Flow { parentFlow.returnLabel = null; parentFlow.returnType = currentFunction.signature.returnType; parentFlow.contextualTypeArguments = currentFunction.contextualTypeArguments; + parentFlow.wrappedLocals = i64_new(0); + parentFlow.wrappedLocalsExt = null; return parentFlow; } @@ -3602,6 +3649,8 @@ export class Flow { branch.returnLabel = this.returnLabel; branch.returnType = this.returnType; branch.contextualTypeArguments = this.contextualTypeArguments; + branch.wrappedLocals = this.wrappedLocals; + branch.wrappedLocalsExt = this.wrappedLocalsExt ? this.wrappedLocalsExt.slice() : null; return branch; } @@ -3619,7 +3668,7 @@ export class Flow { this.scopedLocals = null; } - // Propagate flags to parent + // Propagate conditionaal flags to parent if (this.is(FlowFlags.RETURNS)) { parent.set(FlowFlags.CONDITIONALLY_RETURNS); } @@ -3640,8 +3689,8 @@ export class Flow { } /** Adds a new scoped local of the specified name. */ - addScopedLocal(type: Type, name: string, declaration?: VariableDeclaration): Local { - var scopedLocal = this.currentFunction.getTempLocal(type); + addScopedLocal(type: Type, name: string, wrapped: bool, declaration?: VariableDeclaration): Local { + var scopedLocal = this.currentFunction.getTempLocal(type, false); if (!this.scopedLocals) this.scopedLocals = new Map(); else { let existingLocal = this.scopedLocals.get(name); @@ -3656,6 +3705,7 @@ export class Flow { } } this.scopedLocals.set(name, scopedLocal); + this.setLocalWrapped(scopedLocal.index, wrapped); return scopedLocal; } @@ -3699,26 +3749,360 @@ export class Flow { return this.currentFunction.localsByName.get(name); } - /** Adds a scoped global for an outer scoped local. */ - // addScopedGlobal(scopedLocal: Local): Global { - // var scopedGlobals = this.scopedGlobals; - // var scopedGlobal: Global | null; - // if (!scopedGlobals) { - // this.scopedGlobals = scopedGlobals = new Map(); - // } else { - // scopedGlobal = scopedGlobals.get(scopedLocal); - // if (scopedGlobal) return scopedGlobal; - // } - // scopedGlobal = new Global( - // scopedLocal.program, - // scopedLocal.simpleName, - // this.currentFunction.internalName + INNER_DELIMITER + scopedLocal.internalName, - // scopedLocal.type, - // assert(scopedLocal.declaration) - // ); - // scopedGlobals.set(scopedLocal, scopedGlobal); - // return scopedGlobal; - // } + /** Tests if the local with the specified index is considered wrapped. */ + isLocalWrapped(index: i32): bool { + var map: I64; + var ext: I64[] | null; + if (index < 64) { + if (index < 0) return true; // inlined constant + map = this.wrappedLocals; + } else if (ext = this.wrappedLocalsExt) { + let i = ((index - 64) / 64) | 0; + if (i >= ext.length) return false; + map = ext[i]; + index -= (i + 1) * 64; + } else { + return false; + } + return i64_ne( + i64_and( + map, + i64_shl( + i64_one, + i64_new(index) + ) + ), + i64_zero + ); + } + + /** Sets if the local with the specified index is considered wrapped. */ + setLocalWrapped(index: i32, wrapped: bool): void { + var map: I64; + var i: i32 = -1; + if (index < 64) { + if (index < 0) return; // inlined constant + map = this.wrappedLocals; + } else { + let ext = this.wrappedLocalsExt; + i = ((index - 64) / 64) | 0; + if (!ext) ext = new Array(i + 1); + else while (ext.length <= i) ext.push(i64_new(0)); + map = ext[i]; + index -= (i + 1) * 64; + } + map = wrapped + ? i64_or( + map, + i64_shl( + i64_one, + i64_new(index) + ) + ) + : i64_and( + map, + i64_not( + i64_shl( + i64_one, + i64_new(index) + ) + ) + ); + if (i >= 0) (this.wrappedLocalsExt)[i] = map; + else this.wrappedLocals = map; + } + + /** Inherits flags and local wrap states from the specified flow (e.g. on inner block). */ + inherit(other: Flow): void { + this.flags |= other.flags & ( + FlowFlags.RETURNS | + FlowFlags.RETURNS_WRAPPED | + FlowFlags.THROWS | + FlowFlags.BREAKS | + FlowFlags.CONTINUES | + FlowFlags.ALLOCATES + ); + this.wrappedLocals = other.wrappedLocals; + this.wrappedLocalsExt = other.wrappedLocalsExt; // no need to slice because other flow is finished + } + + /** Inherits mutual flags and local wrap states from the specified flows (e.g. on then/else branches). */ + inheritMutual(left: Flow, right: Flow): void { + // flags set in both arms + this.flags |= left.flags & right.flags & ( + FlowFlags.RETURNS | + FlowFlags.RETURNS_WRAPPED | + FlowFlags.THROWS | + FlowFlags.BREAKS | + FlowFlags.CONTINUES | + FlowFlags.ALLOCATES + ); + // locals wrapped in both arms + this.wrappedLocals = i64_and( + left.wrappedLocals, + right.wrappedLocals + ); + var leftExt = left.wrappedLocalsExt; + var rightExt = right.wrappedLocalsExt; + if (leftExt != null && rightExt != null) { + let thisExt = this.wrappedLocalsExt; + let minLength = min(leftExt.length, rightExt.length); + if (minLength) { + if (!thisExt) thisExt = new Array(minLength); + else while (thisExt.length < minLength) thisExt.push(i64_new(0)); + for (let i = 0; i < minLength; ++i) { + thisExt[i] = i64_and( + leftExt[i], + rightExt[i] + ); + } + } + } + } + + /** + * Tests if an expression can possibly overflow in the context of this flow. Assumes that the + * expression might already have overflown and returns `false` only if the operation neglects + * any possibly combination of garbage bits being present. + */ + canOverflow(expr: ExpressionRef, type: Type): bool { + // TODO: the following catches most common and a few uncommon cases, but there are additional + // opportunities here, obviously. + assert(type != Type.void); + + // types other than i8, u8, i16, u16 and bool do not overflow + if (!type.is(TypeFlags.SHORT | TypeFlags.INTEGER)) return false; + + var operand: ExpressionRef; + switch (getExpressionId(expr)) { + + // overflows if the local isn't wrapped or the conversion does + case ExpressionId.GetLocal: { + let currentFunction = this.currentFunction; + let local = currentFunction.localsByIndex[getGetLocalIndex(expr)]; + return !currentFunction.flow.isLocalWrapped(local.index) + || canConversionOverflow(local.type, type); + } + + // overflows if the value does + case ExpressionId.SetLocal: { + assert(isTeeLocal(expr)); + return this.canOverflow(getSetLocalValue(expr), type); + } + + // never overflows because globals are wrapped on set + case ExpressionId.GetGlobal: return false; + + case ExpressionId.Binary: { + switch (getBinaryOp(expr)) { + + // comparisons do not overflow (result is 0 or 1) + case BinaryOp.EqI32: + case BinaryOp.EqI64: + case BinaryOp.EqF32: + case BinaryOp.EqF64: + case BinaryOp.NeI32: + case BinaryOp.NeI64: + case BinaryOp.NeF32: + case BinaryOp.NeF64: + case BinaryOp.LtI32: + case BinaryOp.LtU32: + case BinaryOp.LtI64: + case BinaryOp.LtU64: + case BinaryOp.LtF32: + case BinaryOp.LtF64: + case BinaryOp.LeI32: + case BinaryOp.LeU32: + case BinaryOp.LeI64: + case BinaryOp.LeU64: + case BinaryOp.LeF32: + case BinaryOp.LeF64: + case BinaryOp.GtI32: + case BinaryOp.GtU32: + case BinaryOp.GtI64: + case BinaryOp.GtU64: + case BinaryOp.GtF32: + case BinaryOp.GtF64: + case BinaryOp.GeI32: + case BinaryOp.GeU32: + case BinaryOp.GeI64: + case BinaryOp.GeU64: + case BinaryOp.GeF32: + case BinaryOp.GeF64: return false; + + // result won't overflow if one side is 0 or if one side is 1 and the other wrapped + case BinaryOp.MulI32: { + return !( + ( + getExpressionId(operand = getBinaryLeft(expr)) == ExpressionId.Const && + ( + getConstValueI32(operand) == 0 || + ( + getConstValueI32(operand) == 1 && + !this.canOverflow(getBinaryRight(expr), type) + ) + ) + ) || ( + getExpressionId(operand = getBinaryRight(expr)) == ExpressionId.Const && + ( + getConstValueI32(operand) == 0 || + ( + getConstValueI32(operand) == 1 && + !this.canOverflow(getBinaryLeft(expr), type) + ) + ) + ) + ); + } + + // result won't overflow if one side is a constant less than this type's mask or one side + // is wrapped + case BinaryOp.AndI32: { + // note that computeSmallIntegerMask returns the mask minus the MSB for signed types + // because signed value garbage bits must be guaranteed to be equal to the MSB. + return !( + ( + ( + getExpressionId(operand = getBinaryLeft(expr)) == ExpressionId.Const && + getConstValueI32(operand) <= type.computeSmallIntegerMask(Type.i32) + ) || !this.canOverflow(operand, type) + ) || ( + ( + getExpressionId(operand = getBinaryRight(expr)) == ExpressionId.Const && + getConstValueI32(operand) <= type.computeSmallIntegerMask(Type.i32) + ) || !this.canOverflow(operand, type) + ) + ); + } + + // overflows if the shift doesn't clear potential garbage bits + case BinaryOp.ShlI32: { + let shift = 32 - type.size; + return getExpressionId(operand = getBinaryRight(expr)) != ExpressionId.Const + || getConstValueI32(operand) < shift; + } + + // overflows if the value does and the shift doesn't clear potential garbage bits + case BinaryOp.ShrI32: { + let shift = 32 - type.size; + return this.canOverflow(getBinaryLeft(expr), type) && ( + getExpressionId(operand = getBinaryRight(expr)) != ExpressionId.Const || + getConstValueI32(operand) < shift + ); + } + + // overflows if the shift does not clear potential garbage bits. if an unsigned value is + // wrapped, it can't overflow. + case BinaryOp.ShrU32: { + let shift = 32 - type.size; + return type.is(TypeFlags.SIGNED) + ? !( + getExpressionId(operand = getBinaryRight(expr)) == ExpressionId.Const && + getConstValueI32(operand) > shift // must clear MSB + ) + : this.canOverflow(getBinaryLeft(expr), type) && !( + getExpressionId(operand = getBinaryRight(expr)) == ExpressionId.Const && + getConstValueI32(operand) >= shift // can leave MSB + ); + } + + // overflows if any side does + case BinaryOp.DivU32: + case BinaryOp.RemI32: + case BinaryOp.RemU32: { + return this.canOverflow(getBinaryLeft(expr), type) + || this.canOverflow(getBinaryRight(expr), type); + } + } + break; + } + + case ExpressionId.Unary: { + switch (getUnaryOp(expr)) { + + // comparisons do not overflow (result is 0 or 1) + case UnaryOp.EqzI32: + case UnaryOp.EqzI64: return false; + + // overflow if the maximum result (32) cannot be represented in the target type + case UnaryOp.ClzI32: + case UnaryOp.CtzI32: + case UnaryOp.PopcntI32: return type.size < 7; + } + break; + } + + // overflows if the value cannot be represented in the target type + case ExpressionId.Const: { + let value: i32 = 0; + switch (getExpressionType(expr)) { + case NativeType.I32: { value = getConstValueI32(expr); break; } + case NativeType.I64: { value = getConstValueI64Low(expr); break; } // discards upper bits + case NativeType.F32: { value = i32(getConstValueF32(expr)); break; } + case NativeType.F64: { value = i32(getConstValueF64(expr)); break; } + default: assert(false); + } + switch (type.kind) { + case TypeKind.I8: return value < i8.MIN_VALUE || value > i8.MAX_VALUE; + case TypeKind.I16: return value < i16.MIN_VALUE || value > i16.MAX_VALUE; + case TypeKind.U8: return value < 0 || value > u8.MAX_VALUE; + case TypeKind.U16: return value < 0 || value > u16.MAX_VALUE; + case TypeKind.BOOL: return (value & ~1) != 0; + } + break; + } + + // overflows if the conversion does + case ExpressionId.Load: { + let fromType: Type; + switch (getLoadBytes(expr)) { + case 1: { fromType = isLoadSigned(expr) ? Type.i8 : Type.u8; break; } + case 2: { fromType = isLoadSigned(expr) ? Type.i16 : Type.u16; break; } + default: { fromType = isLoadSigned(expr) ? Type.i32 : Type.u32; break; } + } + return canConversionOverflow(fromType, type); + } + + // overflows if the result does, which is either + // - the last expression of the block, by contract, if the block doesn't have a label + // - the last expression or the value of an inner br if the block has a label (TODO) + case ExpressionId.Block: { + if (!getBlockName(expr)) { + let size = assert(getBlockChildCount(expr)); + let last = getBlockChild(expr, size - 1); + return this.canOverflow(last, type); + } + // actually, brs with a value that'd be handled here is not emitted atm + break; + } + + // overflows if either side does + case ExpressionId.If: { + return this.canOverflow(getIfTrue(expr), type) + || this.canOverflow(assert(getIfFalse(expr)), type); + } + + // overflows if either side does + case ExpressionId.Select: { + return this.canOverflow(getSelectThen(expr), type) + || this.canOverflow(getSelectElse(expr), type); + } + + // overflows if the call does not return a wrapped value or the conversion does + case ExpressionId.Call: { + let program = this.currentFunction.program; + let instance = assert(program.instancesLookup.get(assert(getCallTarget(expr)))); + assert(instance.kind == ElementKind.FUNCTION); + let returnType = (instance).signature.returnType; + return !(instance).flow.is(FlowFlags.RETURNS_WRAPPED) + || canConversionOverflow(returnType, type); + } + + // doesn't technically overflow + case ExpressionId.Unreachable: return false; + } + return true; + } /** Finalizes this flow. Must be the topmost parent flow of the function. */ finalize(): void { @@ -3729,3 +4113,12 @@ export class Flow { this.contextualTypeArguments = null; } } + +/** Tests if a conversion from one type to another can technically overflow. */ +function canConversionOverflow(fromType: Type, toType: Type): bool { + var fromSize = fromType.byteSize; + var toSize = toType.byteSize; + return !fromType.is(TypeFlags.INTEGER) // non-i32 locals or returns + || fromSize > toSize + || fromType.is(TypeFlags.SIGNED) != toType.is(TypeFlags.SIGNED); +} diff --git a/src/types.ts b/src/types.ts index fe02e5ba..69231bb5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -114,6 +114,24 @@ export class Type { this.nonNullableType = this; } + /** Returns the int type of this type. Defaults to `Type.i32` if this is not an int type. */ + get intType(): Type { + switch (this.kind) { + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.I32: + case TypeKind.I64: + case TypeKind.ISIZE: + case TypeKind.U8: + case TypeKind.U16: + case TypeKind.U32: + case TypeKind.U64: + case TypeKind.USIZE: return this; + case TypeKind.BOOL: + default: return Type.i32; + } + } + /** Computes the sign-extending shift in the target type. */ computeSmallIntegerShift(targetType: Type): u32 { return targetType.size - this.size; @@ -121,7 +139,8 @@ export class Type { /** Computes the truncating mask in the target type. */ computeSmallIntegerMask(targetType: Type): u32 { - return ~0 >>> (targetType.size - this.size); + var size = this.is(TypeFlags.UNSIGNED) ? this.size : this.size - 1; + return ~0 >>> (targetType.size - size); } /** Tests if this type has (all of) the specified flags. */ diff --git a/std/assembly/allocator/buddy.ts b/std/assembly/allocator/buddy.ts index 4d0b4126..481bab08 100644 --- a/std/assembly/allocator/buddy.ts +++ b/std/assembly/allocator/buddy.ts @@ -255,9 +255,9 @@ function node_for_ptr(ptr: usize, bucket: usize): usize { /* * Given the index of a node, this returns the "is split" flag of the parent. */ -function parent_is_split(index: usize): i32 { +function parent_is_split(index: usize): bool { index = (index - 1) / 2; - return (node_is_split$get(index / 8) >>> (index % 8)) & 1; + return ((node_is_split$get(index / 8) >>> (index % 8)) & 1) == 1; } /* diff --git a/std/portable.d.ts b/std/portable.d.ts index be1485c7..f1744728 100644 --- a/std/portable.d.ts +++ b/std/portable.d.ts @@ -247,7 +247,7 @@ declare class Array { shift(): T; some(callbackfn: (element: T, index: i32, array?: Array) => bool): bool; unshift(element: T): i32; - slice(from: i32, to?: i32): T[]; + slice(from?: i32, to?: i32): T[]; splice(start: i32, deleteCount?: i32): void; reverse(): T[]; sort(comparator?: (a: T, b: T) => i32): this; diff --git a/tests/allocators/buddy/optimized.wat b/tests/allocators/buddy/optimized.wat index d2e04ba9..16d945cc 100644 --- a/tests/allocators/buddy/optimized.wat +++ b/tests/allocators/buddy/optimized.wat @@ -229,39 +229,44 @@ ) (func $~lib/allocator/buddy/parent_is_split (; 7 ;) (type $ii) (param $0 i32) (result i32) ;;@ ~lib/allocator/buddy.ts:260:9 - (i32.and - (i32.shr_u + (i32.eq + (i32.and ;;@ ~lib/allocator/buddy.ts:260:10 - (call $~lib/allocator/buddy/node_is_split$get - ;;@ ~lib/allocator/buddy.ts:260:28 - (i32.div_u - ;;@ ~lib/allocator/buddy.ts:259:2 - (tee_local $0 - ;;@ ~lib/allocator/buddy.ts:259:10 - (i32.div_u - (i32.sub - ;;@ ~lib/allocator/buddy.ts:259:11 - (get_local $0) - ;;@ ~lib/allocator/buddy.ts:259:19 - (i32.const 1) + (i32.shr_u + ;;@ ~lib/allocator/buddy.ts:260:11 + (call $~lib/allocator/buddy/node_is_split$get + ;;@ ~lib/allocator/buddy.ts:260:29 + (i32.div_u + ;;@ ~lib/allocator/buddy.ts:259:2 + (tee_local $0 + ;;@ ~lib/allocator/buddy.ts:259:10 + (i32.div_u + (i32.sub + ;;@ ~lib/allocator/buddy.ts:259:11 + (get_local $0) + ;;@ ~lib/allocator/buddy.ts:259:19 + (i32.const 1) + ) + ;;@ ~lib/allocator/buddy.ts:259:24 + (i32.const 2) ) - ;;@ ~lib/allocator/buddy.ts:259:24 - (i32.const 2) ) + ;;@ ~lib/allocator/buddy.ts:260:37 + (i32.const 8) ) - ;;@ ~lib/allocator/buddy.ts:260:36 - (i32.const 8) + ) + ;;@ ~lib/allocator/buddy.ts:260:44 + (i32.and + ;;@ ~lib/allocator/buddy.ts:260:50 + (get_local $0) + ;;@ ~lib/allocator/buddy.ts:260:58 + (i32.const 7) ) ) - ;;@ ~lib/allocator/buddy.ts:260:43 - (i32.and - ;;@ ~lib/allocator/buddy.ts:260:49 - (get_local $0) - ;;@ ~lib/allocator/buddy.ts:260:57 - (i32.const 7) - ) + ;;@ ~lib/allocator/buddy.ts:260:64 + (i32.const 1) ) - ;;@ ~lib/allocator/buddy.ts:260:63 + ;;@ ~lib/allocator/buddy.ts:260:70 (i32.const 1) ) ) @@ -715,22 +720,19 @@ ;;@ ~lib/allocator/buddy.ts:403:6 (if ;;@ ~lib/allocator/buddy.ts:403:10 - (i32.and - (if (result i32) - (tee_local $2 - (i32.ne - (get_local $1) - ;;@ ~lib/allocator/buddy.ts:403:20 - (get_global $~lib/allocator/buddy/bucket_limit) - ) - ) - (get_local $2) - (i32.eqz - ;;@ ~lib/allocator/buddy.ts:403:36 + (if (result i32) + (tee_local $2 + (i32.ne (get_local $1) + ;;@ ~lib/allocator/buddy.ts:403:20 + (get_global $~lib/allocator/buddy/bucket_limit) ) ) - (i32.const 1) + (get_local $2) + (i32.eqz + ;;@ ~lib/allocator/buddy.ts:403:36 + (get_local $1) + ) ) ;;@ ~lib/allocator/buddy.ts:403:49 (block diff --git a/tests/allocators/buddy/untouched.wat b/tests/allocators/buddy/untouched.wat index cb4f8965..ab1b7900 100644 --- a/tests/allocators/buddy/untouched.wat +++ b/tests/allocators/buddy/untouched.wat @@ -349,29 +349,34 @@ (i32.const 2) ) ) - ;;@ ~lib/allocator/buddy.ts:260:63 + ;;@ ~lib/allocator/buddy.ts:260:70 (return ;;@ ~lib/allocator/buddy.ts:260:9 - (i32.and - (i32.shr_u + (i32.eq + (i32.and ;;@ ~lib/allocator/buddy.ts:260:10 - (call $~lib/allocator/buddy/node_is_split$get - ;;@ ~lib/allocator/buddy.ts:260:28 - (i32.div_u + (i32.shr_u + ;;@ ~lib/allocator/buddy.ts:260:11 + (call $~lib/allocator/buddy/node_is_split$get + ;;@ ~lib/allocator/buddy.ts:260:29 + (i32.div_u + (get_local $0) + ;;@ ~lib/allocator/buddy.ts:260:37 + (i32.const 8) + ) + ) + ;;@ ~lib/allocator/buddy.ts:260:44 + (i32.rem_u + ;;@ ~lib/allocator/buddy.ts:260:50 (get_local $0) - ;;@ ~lib/allocator/buddy.ts:260:36 + ;;@ ~lib/allocator/buddy.ts:260:58 (i32.const 8) ) ) - ;;@ ~lib/allocator/buddy.ts:260:43 - (i32.rem_u - ;;@ ~lib/allocator/buddy.ts:260:49 - (get_local $0) - ;;@ ~lib/allocator/buddy.ts:260:57 - (i32.const 8) - ) + ;;@ ~lib/allocator/buddy.ts:260:64 + (i32.const 1) ) - ;;@ ~lib/allocator/buddy.ts:260:63 + ;;@ ~lib/allocator/buddy.ts:260:70 (i32.const 1) ) ) @@ -923,24 +928,21 @@ ;;@ ~lib/allocator/buddy.ts:403:6 (if ;;@ ~lib/allocator/buddy.ts:403:10 - (i32.and - (if (result i32) - (tee_local $7 - (i32.ne - (get_local $2) - ;;@ ~lib/allocator/buddy.ts:403:20 - (get_global $~lib/allocator/buddy/bucket_limit) - ) - ) - (get_local $7) - ;;@ ~lib/allocator/buddy.ts:403:36 - (i32.eq + (if (result i32) + (tee_local $7 + (i32.ne (get_local $2) - ;;@ ~lib/allocator/buddy.ts:403:46 - (i32.const 0) + ;;@ ~lib/allocator/buddy.ts:403:20 + (get_global $~lib/allocator/buddy/bucket_limit) ) ) - (i32.const 1) + (get_local $7) + ;;@ ~lib/allocator/buddy.ts:403:36 + (i32.eq + (get_local $2) + ;;@ ~lib/allocator/buddy.ts:403:46 + (i32.const 0) + ) ) ;;@ ~lib/allocator/buddy.ts:403:49 (block diff --git a/tests/allocators/index.js b/tests/allocators/index.js index 0f99baa8..8f82bd8c 100644 --- a/tests/allocators/index.js +++ b/tests/allocators/index.js @@ -4,7 +4,7 @@ const COMMON_MAX = 1 << 30; function test(file) { console.log("Testing '" + file + "' ...\n"); - const exports = new WebAssembly.Instance(WebAssembly.Module(fs.readFileSync(__dirname + "/" + file)), { + const exports = new WebAssembly.Instance(new WebAssembly.Module(fs.readFileSync(__dirname + "/" + file)), { env: { abort: function(msg, file, line, column) { throw Error("Assertion failed: " + (msg ? "'" + getString(msg) + "' " : "") + "at " + getString(file) + ":" + line + ":" + column); diff --git a/tests/allocators/package.json b/tests/allocators/package.json index 2560ce30..8ec334df 100644 --- a/tests/allocators/package.json +++ b/tests/allocators/package.json @@ -2,6 +2,7 @@ "private": true, "scripts": { "test": "node ./index", - "test:forever": "node ./forever" + "test:forever": "node ./forever", + "test:all": "npm run test tlsf && npm run test buddy && npm run test arena" } } diff --git a/tests/allocators/tlsf/optimized.wat b/tests/allocators/tlsf/optimized.wat index 88f7bda6..057617f2 100644 --- a/tests/allocators/tlsf/optimized.wat +++ b/tests/allocators/tlsf/optimized.wat @@ -1062,7 +1062,7 @@ ;;@ ~lib/allocator/tlsf.ts:369:6 (i32.store ;;@ ~lib/allocator/tlsf.ts:368:6 - (tee_local $2 + (tee_local $0 ;;@ ~lib/allocator/tlsf.ts:368:25 (call $~lib/allocator/tlsf/Block#get:right ;;@ ~lib/allocator/tlsf.ts:368:32 @@ -1072,7 +1072,7 @@ (i32.and ;;@ ~lib/allocator/tlsf.ts:369:6 (i32.load - (get_local $2) + (get_local $0) ) (i32.const -3) ) @@ -1109,7 +1109,7 @@ ;;@ ~lib/allocator/tlsf.ts:446:11 (tee_local $2 ;;@ ~lib/allocator/tlsf.ts:445:4 - (tee_local $3 + (tee_local $4 ;;@ ~lib/allocator/tlsf.ts:445:21 (i32.and (i32.add @@ -1154,7 +1154,7 @@ (i32.const 0) ) ;;@ ~lib/allocator/tlsf.ts:451:11 - (set_local $4 + (set_local $3 ;;@ ~lib/allocator/tlsf.ts:451:25 (i32.const 0) ) @@ -1162,7 +1162,7 @@ (if ;;@ ~lib/allocator/tlsf.ts:451:28 (i32.lt_u - (get_local $4) + (get_local $3) ;;@ ~lib/allocator/tlsf.ts:451:33 (i32.const 32) ) @@ -1174,15 +1174,15 @@ ;;@ ~lib/allocator/tlsf.ts:452:21 (get_local $1) ;;@ ~lib/allocator/tlsf.ts:452:25 - (get_local $4) + (get_local $3) ;;@ ~lib/allocator/tlsf.ts:452:29 (i32.const 0) ) ;;@ ~lib/allocator/tlsf.ts:451:42 - (set_local $4 + (set_local $3 (i32.add ;;@ ~lib/allocator/tlsf.ts:451:44 - (get_local $4) + (get_local $3) (i32.const 1) ) ) @@ -1211,7 +1211,7 @@ (i32.and (i32.add ;;@ ~lib/allocator/tlsf.ts:455:20 - (get_local $3) + (get_local $4) (i32.const 2923) ) (i32.const -8) @@ -1253,7 +1253,7 @@ ;;@ ~lib/allocator/tlsf.ts:466:8 (i32.eqz ;;@ ~lib/allocator/tlsf.ts:465:4 - (tee_local $3 + (tee_local $1 ;;@ ~lib/allocator/tlsf.ts:465:21 (call $~lib/allocator/tlsf/Root#search ;;@ ~lib/allocator/tlsf.ts:465:16 @@ -1262,7 +1262,7 @@ (tee_local $0 ;;@ ~lib/allocator/tlsf.ts:463:11 (select - (tee_local $3 + (tee_local $1 ;;@ ~lib/allocator/tlsf.ts:463:22 (i32.and (i32.add @@ -1274,13 +1274,13 @@ (i32.const -8) ) ) - (tee_local $1 + (tee_local $3 ;;@ ~lib/allocator/tlsf.ts:463:51 (i32.const 16) ) (i32.gt_u - (get_local $3) (get_local $1) + (get_local $3) ) ) ) @@ -1296,16 +1296,16 @@ (grow_memory ;;@ ~lib/allocator/tlsf.ts:471:24 (select - (tee_local $3 + (tee_local $1 ;;@ ~lib/allocator/tlsf.ts:469:6 - (tee_local $1 + (tee_local $3 ;;@ ~lib/allocator/tlsf.ts:469:24 (current_memory) ) ) - (tee_local $5 + (tee_local $4 ;;@ ~lib/allocator/tlsf.ts:470:6 - (tee_local $4 + (tee_local $5 ;;@ ~lib/allocator/tlsf.ts:470:24 (i32.shr_u (i32.and @@ -1324,8 +1324,8 @@ ) ) (i32.gt_s - (get_local $3) - (get_local $5) + (get_local $1) + (get_local $4) ) ) ) @@ -1338,7 +1338,7 @@ (i32.lt_s (grow_memory ;;@ ~lib/allocator/tlsf.ts:473:24 - (get_local $4) + (get_local $5) ) ;;@ ~lib/allocator/tlsf.ts:473:39 (i32.const 0) @@ -1354,7 +1354,7 @@ (get_local $2) ;;@ ~lib/allocator/tlsf.ts:478:21 (i32.shl - (get_local $1) + (get_local $3) ;;@ ~lib/allocator/tlsf.ts:478:43 (i32.const 16) ) @@ -1368,7 +1368,7 @@ ) ) ;;@ ~lib/allocator/tlsf.ts:479:6 - (set_local $3 + (set_local $1 ;;@ ~lib/allocator/tlsf.ts:479:14 (call $~lib/allocator/tlsf/Root#search ;;@ ~lib/allocator/tlsf.ts:479:21 @@ -1386,7 +1386,7 @@ ;;@ ~lib/allocator/tlsf.ts:483:11 (get_local $2) ;;@ ~lib/allocator/tlsf.ts:483:20 - (get_local $3) + (get_local $1) ;;@ ~lib/allocator/tlsf.ts:483:27 (get_local $0) ) diff --git a/tests/allocators/tlsf/untouched.wat b/tests/allocators/tlsf/untouched.wat index c657258a..d17db342 100644 --- a/tests/allocators/tlsf/untouched.wat +++ b/tests/allocators/tlsf/untouched.wat @@ -415,24 +415,21 @@ (if (i32.eqz ;;@ ~lib/allocator/tlsf.ts:260:11 - (i32.and - (if (result i32) - (tee_local $4 - (i32.ge_u - (get_local $3) - ;;@ ~lib/allocator/tlsf.ts:260:19 - (i32.const 16) - ) - ) - ;;@ ~lib/allocator/tlsf.ts:260:37 - (i32.lt_u + (if (result i32) + (tee_local $4 + (i32.ge_u (get_local $3) - ;;@ ~lib/allocator/tlsf.ts:260:44 - (i32.const 1073741824) + ;;@ ~lib/allocator/tlsf.ts:260:19 + (i32.const 16) ) - (get_local $4) ) - (i32.const 1) + ;;@ ~lib/allocator/tlsf.ts:260:37 + (i32.lt_u + (get_local $3) + ;;@ ~lib/allocator/tlsf.ts:260:44 + (i32.const 1073741824) + ) + (get_local $4) ) ) (block @@ -805,6 +802,7 @@ (local $8 i32) (local $9 i32) (local $10 i32) + (local $11 i32) ;;@ ~lib/allocator/tlsf.ts:189:4 (if (i32.eqz @@ -854,37 +852,34 @@ (if (i32.eqz ;;@ ~lib/allocator/tlsf.ts:194:6 - (i32.and - (if (result i32) - (tee_local $4 - (i32.ge_u - (tee_local $3 - ;;@ ~lib/allocator/tlsf.ts:194:14 - (i32.and - (i32.load - (get_local $1) - ) - ;;@ ~lib/allocator/tlsf.ts:194:27 - (i32.xor - ;;@ ~lib/allocator/tlsf.ts:194:28 - (i32.const 3) - (i32.const -1) - ) + (if (result i32) + (tee_local $4 + (i32.ge_u + (tee_local $3 + ;;@ ~lib/allocator/tlsf.ts:194:14 + (i32.and + (i32.load + (get_local $1) + ) + ;;@ ~lib/allocator/tlsf.ts:194:27 + (i32.xor + ;;@ ~lib/allocator/tlsf.ts:194:28 + (i32.const 3) + (i32.const -1) ) ) - ;;@ ~lib/allocator/tlsf.ts:194:37 - (i32.const 16) ) + ;;@ ~lib/allocator/tlsf.ts:194:37 + (i32.const 16) ) - ;;@ ~lib/allocator/tlsf.ts:194:55 - (i32.lt_u - (get_local $3) - ;;@ ~lib/allocator/tlsf.ts:194:62 - (i32.const 1073741824) - ) - (get_local $4) ) - (i32.const 1) + ;;@ ~lib/allocator/tlsf.ts:194:55 + (i32.lt_u + (get_local $3) + ;;@ ~lib/allocator/tlsf.ts:194:62 + (i32.const 1073741824) + ) + (get_local $4) ) ) (block @@ -1129,24 +1124,21 @@ (if (i32.eqz ;;@ ~lib/allocator/tlsf.ts:226:11 - (i32.and - (if (result i32) - (tee_local $7 - (i32.ge_u - (get_local $3) - ;;@ ~lib/allocator/tlsf.ts:226:19 - (i32.const 16) - ) - ) - ;;@ ~lib/allocator/tlsf.ts:226:37 - (i32.lt_u + (if (result i32) + (tee_local $8 + (i32.ge_u (get_local $3) - ;;@ ~lib/allocator/tlsf.ts:226:44 - (i32.const 1073741824) + ;;@ ~lib/allocator/tlsf.ts:226:19 + (i32.const 16) ) - (get_local $7) ) - (i32.const 1) + ;;@ ~lib/allocator/tlsf.ts:226:37 + (i32.lt_u + (get_local $3) + ;;@ ~lib/allocator/tlsf.ts:226:44 + (i32.const 1073741824) + ) + (get_local $8) ) ) (block @@ -1172,12 +1164,12 @@ ;;@ ~lib/allocator/tlsf.ts:230:24 (block ;;@ ~lib/allocator/tlsf.ts:231:6 - (set_local $8 + (set_local $9 ;;@ ~lib/allocator/tlsf.ts:231:11 (i32.const 0) ) ;;@ ~lib/allocator/tlsf.ts:232:6 - (set_local $9 + (set_local $10 ;;@ ~lib/allocator/tlsf.ts:232:11 (i32.div_u ;;@ ~lib/allocator/tlsf.ts:232:17 @@ -1190,7 +1182,7 @@ ;;@ ~lib/allocator/tlsf.ts:233:11 (block ;;@ ~lib/allocator/tlsf.ts:234:6 - (set_local $8 + (set_local $9 ;;@ ~lib/allocator/tlsf.ts:234:11 (call $~lib/allocator/tlsf/fls ;;@ ~lib/allocator/tlsf.ts:234:22 @@ -1198,7 +1190,7 @@ ) ) ;;@ ~lib/allocator/tlsf.ts:235:6 - (set_local $9 + (set_local $10 ;;@ ~lib/allocator/tlsf.ts:235:11 (i32.xor ;;@ ~lib/allocator/tlsf.ts:235:17 @@ -1208,7 +1200,7 @@ ;;@ ~lib/allocator/tlsf.ts:235:26 (i32.sub ;;@ ~lib/allocator/tlsf.ts:235:27 - (get_local $8) + (get_local $9) ;;@ ~lib/allocator/tlsf.ts:235:32 (i32.const 5) ) @@ -1223,9 +1215,9 @@ ) ) ;;@ ~lib/allocator/tlsf.ts:236:6 - (set_local $8 + (set_local $9 (i32.sub - (get_local $8) + (get_local $9) ;;@ ~lib/allocator/tlsf.ts:236:12 (i32.sub (i32.const 8) @@ -1237,15 +1229,15 @@ ) ) ;;@ ~lib/allocator/tlsf.ts:240:4 - (set_local $10 + (set_local $11 ;;@ ~lib/allocator/tlsf.ts:240:20 (call $~lib/allocator/tlsf/Root#getHead ;;@ ~lib/allocator/tlsf.ts:240:15 (get_local $0) ;;@ ~lib/allocator/tlsf.ts:240:28 - (get_local $8) - ;;@ ~lib/allocator/tlsf.ts:240:32 (get_local $9) + ;;@ ~lib/allocator/tlsf.ts:240:32 + (get_local $10) ) ) ;;@ ~lib/allocator/tlsf.ts:241:4 @@ -1258,15 +1250,15 @@ (i32.store offset=8 (get_local $1) ;;@ ~lib/allocator/tlsf.ts:242:17 - (get_local $10) + (get_local $11) ) ;;@ ~lib/allocator/tlsf.ts:243:4 (if ;;@ ~lib/allocator/tlsf.ts:243:8 - (get_local $10) + (get_local $11) ;;@ ~lib/allocator/tlsf.ts:243:14 (i32.store offset=4 - (get_local $10) + (get_local $11) ;;@ ~lib/allocator/tlsf.ts:243:26 (get_local $1) ) @@ -1276,9 +1268,9 @@ ;;@ ~lib/allocator/tlsf.ts:244:4 (get_local $0) ;;@ ~lib/allocator/tlsf.ts:244:17 - (get_local $8) - ;;@ ~lib/allocator/tlsf.ts:244:21 (get_local $9) + ;;@ ~lib/allocator/tlsf.ts:244:21 + (get_local $10) ;;@ ~lib/allocator/tlsf.ts:244:25 (get_local $1) ) @@ -1294,7 +1286,7 @@ ;;@ ~lib/allocator/tlsf.ts:247:19 (i32.const 1) ;;@ ~lib/allocator/tlsf.ts:247:24 - (get_local $8) + (get_local $9) ) ) ) @@ -1303,7 +1295,7 @@ ;;@ ~lib/allocator/tlsf.ts:248:4 (get_local $0) ;;@ ~lib/allocator/tlsf.ts:248:18 - (get_local $8) + (get_local $9) ;;@ ~lib/allocator/tlsf.ts:248:22 (i32.or ;;@ ~lib/allocator/tlsf.ts:248:27 @@ -1311,14 +1303,14 @@ ;;@ ~lib/allocator/tlsf.ts:248:22 (get_local $0) ;;@ ~lib/allocator/tlsf.ts:248:36 - (get_local $8) + (get_local $9) ) ;;@ ~lib/allocator/tlsf.ts:248:42 (i32.shl ;;@ ~lib/allocator/tlsf.ts:248:43 (i32.const 1) ;;@ ~lib/allocator/tlsf.ts:248:48 - (get_local $9) + (get_local $10) ) ) ) @@ -1689,24 +1681,21 @@ (if (i32.eqz ;;@ ~lib/allocator/tlsf.ts:296:11 - (i32.and - (if (result i32) - (tee_local $2 - (i32.ge_u - (get_local $1) - ;;@ ~lib/allocator/tlsf.ts:296:19 - (i32.const 16) - ) - ) - ;;@ ~lib/allocator/tlsf.ts:296:37 - (i32.lt_u + (if (result i32) + (tee_local $2 + (i32.ge_u (get_local $1) - ;;@ ~lib/allocator/tlsf.ts:296:44 - (i32.const 1073741824) + ;;@ ~lib/allocator/tlsf.ts:296:19 + (i32.const 16) ) - (get_local $2) ) - (i32.const 1) + ;;@ ~lib/allocator/tlsf.ts:296:37 + (i32.lt_u + (get_local $1) + ;;@ ~lib/allocator/tlsf.ts:296:44 + (i32.const 1073741824) + ) + (get_local $2) ) ) (block @@ -1984,6 +1973,7 @@ (local $3 i32) (local $4 i32) (local $5 i32) + (local $6 i32) ;;@ ~lib/allocator/tlsf.ts:347:4 (set_local $3 ;;@ ~lib/allocator/tlsf.ts:347:20 @@ -2015,24 +2005,21 @@ (if (i32.eqz ;;@ ~lib/allocator/tlsf.ts:349:11 - (i32.and - (if (result i32) - (tee_local $4 - (i32.ge_u - (get_local $2) - ;;@ ~lib/allocator/tlsf.ts:349:19 - (i32.const 16) - ) - ) - ;;@ ~lib/allocator/tlsf.ts:349:37 - (i32.lt_u + (if (result i32) + (tee_local $4 + (i32.ge_u (get_local $2) - ;;@ ~lib/allocator/tlsf.ts:349:44 - (i32.const 1073741824) + ;;@ ~lib/allocator/tlsf.ts:349:19 + (i32.const 16) ) - (get_local $4) ) - (i32.const 1) + ;;@ ~lib/allocator/tlsf.ts:349:37 + (i32.lt_u + (get_local $2) + ;;@ ~lib/allocator/tlsf.ts:349:44 + (i32.const 1073741824) + ) + (get_local $4) ) ) (block @@ -2177,11 +2164,11 @@ ) ) ;;@ ~lib/allocator/tlsf.ts:368:6 - (set_local $4 + (set_local $6 ;;@ ~lib/allocator/tlsf.ts:368:25 (if (result i32) (i32.eqz - (tee_local $4 + (tee_local $6 ;;@ ~lib/allocator/tlsf.ts:368:32 (call $~lib/allocator/tlsf/Block#get:right (get_local $1) @@ -2197,15 +2184,15 @@ ) (unreachable) ) - (get_local $4) + (get_local $6) ) ) ;;@ ~lib/allocator/tlsf.ts:369:6 (i32.store - (get_local $4) + (get_local $6) (i32.and (i32.load - (get_local $4) + (get_local $6) ) ;;@ ~lib/allocator/tlsf.ts:369:20 (i32.xor @@ -2236,6 +2223,9 @@ (local $6 i32) (local $7 i32) (local $8 i32) + (local $9 i32) + (local $10 i32) + (local $11 i32) ;;@ ~lib/allocator/tlsf.ts:443:2 (set_local $1 ;;@ ~lib/allocator/tlsf.ts:443:13 @@ -2430,7 +2420,7 @@ (set_local $0 ;;@ ~lib/allocator/tlsf.ts:463:11 (select - (tee_local $2 + (tee_local $6 ;;@ ~lib/allocator/tlsf.ts:463:22 (i32.and (i32.add @@ -2447,18 +2437,18 @@ ) ) ) - (tee_local $3 + (tee_local $7 ;;@ ~lib/allocator/tlsf.ts:463:51 (i32.const 16) ) (i32.gt_u - (get_local $2) - (get_local $3) + (get_local $6) + (get_local $7) ) ) ) ;;@ ~lib/allocator/tlsf.ts:465:4 - (set_local $2 + (set_local $6 ;;@ ~lib/allocator/tlsf.ts:465:21 (call $~lib/allocator/tlsf/Root#search ;;@ ~lib/allocator/tlsf.ts:465:16 @@ -2472,17 +2462,17 @@ ;;@ ~lib/allocator/tlsf.ts:466:8 (i32.eqz ;;@ ~lib/allocator/tlsf.ts:466:9 - (get_local $2) + (get_local $6) ) ;;@ ~lib/allocator/tlsf.ts:466:16 (block ;;@ ~lib/allocator/tlsf.ts:469:6 - (set_local $3 + (set_local $7 ;;@ ~lib/allocator/tlsf.ts:469:24 (current_memory) ) ;;@ ~lib/allocator/tlsf.ts:470:6 - (set_local $4 + (set_local $8 ;;@ ~lib/allocator/tlsf.ts:470:24 (i32.shr_u (i32.and @@ -2505,20 +2495,20 @@ ) ) ;;@ ~lib/allocator/tlsf.ts:471:6 - (set_local $6 + (set_local $9 ;;@ ~lib/allocator/tlsf.ts:471:24 (select - (tee_local $6 + (tee_local $9 ;;@ ~lib/allocator/tlsf.ts:471:28 - (get_local $3) + (get_local $7) ) - (tee_local $7 + (tee_local $10 ;;@ ~lib/allocator/tlsf.ts:471:41 - (get_local $4) + (get_local $8) ) (i32.gt_s - (get_local $6) - (get_local $7) + (get_local $9) + (get_local $10) ) ) ) @@ -2528,7 +2518,7 @@ (i32.lt_s (grow_memory ;;@ ~lib/allocator/tlsf.ts:472:22 - (get_local $6) + (get_local $9) ) ;;@ ~lib/allocator/tlsf.ts:472:37 (i32.const 0) @@ -2539,7 +2529,7 @@ (i32.lt_s (grow_memory ;;@ ~lib/allocator/tlsf.ts:473:24 - (get_local $4) + (get_local $8) ) ;;@ ~lib/allocator/tlsf.ts:473:39 (i32.const 0) @@ -2549,7 +2539,7 @@ ) ) ;;@ ~lib/allocator/tlsf.ts:477:6 - (set_local $7 + (set_local $10 ;;@ ~lib/allocator/tlsf.ts:477:23 (current_memory) ) @@ -2560,24 +2550,24 @@ (get_local $1) ;;@ ~lib/allocator/tlsf.ts:478:21 (i32.shl - (get_local $3) + (get_local $7) ;;@ ~lib/allocator/tlsf.ts:478:43 (i32.const 16) ) ;;@ ~lib/allocator/tlsf.ts:478:47 (i32.shl - (get_local $7) + (get_local $10) ;;@ ~lib/allocator/tlsf.ts:478:68 (i32.const 16) ) ) ) ;;@ ~lib/allocator/tlsf.ts:479:6 - (set_local $2 + (set_local $6 ;;@ ~lib/allocator/tlsf.ts:479:14 (if (result i32) (i32.eqz - (tee_local $8 + (tee_local $11 ;;@ ~lib/allocator/tlsf.ts:479:26 (call $~lib/allocator/tlsf/Root#search ;;@ ~lib/allocator/tlsf.ts:479:21 @@ -2596,7 +2586,7 @@ ) (unreachable) ) - (get_local $8) + (get_local $11) ) ) ) @@ -2609,7 +2599,7 @@ (i32.and ;;@ ~lib/allocator/tlsf.ts:482:12 (i32.load - (get_local $2) + (get_local $6) ) ;;@ ~lib/allocator/tlsf.ts:482:25 (i32.xor @@ -2639,7 +2629,7 @@ ;;@ ~lib/allocator/tlsf.ts:483:11 (get_local $1) ;;@ ~lib/allocator/tlsf.ts:483:20 - (get_local $2) + (get_local $6) ;;@ ~lib/allocator/tlsf.ts:483:27 (get_local $0) ) diff --git a/tests/compiler/abi.optimized.wat b/tests/compiler/abi.optimized.wat new file mode 100644 index 00000000..a41dbd5c --- /dev/null +++ b/tests/compiler/abi.optimized.wat @@ -0,0 +1,90 @@ +(module + (type $i (func (result i32))) + (type $iiiiv (func (param i32 i32 i32 i32))) + (type $v (func)) + (import "env" "abort" (func $abort (param i32 i32 i32 i32))) + (global $abi/condition (mut i32) (i32.const 0)) + (global $abi/y (mut i32) (i32.const 0)) + (memory $0 1) + (data (i32.const 4) "\06\00\00\00a\00b\00i\00.\00t\00s") + (export "exported" (func $abi/exported)) + (export "exportedExported" (func $abi/exportedExported)) + (export "exportedInternal" (func $abi/exportedInternal)) + (export "memory" (memory $0)) + (start $start) + (func $abi/exported (; 1 ;) (type $i) (result i32) + (i32.const -128) + ) + (func $abi/exportedExported (; 2 ;) (type $i) (result i32) + (call $abi/exported) + ) + (func $abi/internal (; 3 ;) (type $i) (result i32) + (i32.const 128) + ) + (func $abi/exportedInternal (; 4 ;) (type $i) (result i32) + (i32.shr_s + (i32.shl + (call $abi/internal) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (func $start (; 5 ;) (type $v) + (local $0 i32) + (drop + (call $abi/internal) + ) + (set_global $abi/condition + (i32.const 1) + ) + (set_local $0 + (i32.const 256) + ) + (if + (tee_local $0 + (select + (i32.shr_s + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.and + (get_local $0) + (i32.const 127) + ) + (get_global $abi/condition) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 58) + (i32.const 2) + ) + (unreachable) + ) + ) + (set_global $abi/y + (i32.const 0) + ) + (if + (get_global $abi/y) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 65) + (i32.const 2) + ) + (unreachable) + ) + ) + ) +) diff --git a/tests/compiler/abi.ts b/tests/compiler/abi.ts new file mode 100644 index 00000000..211a7789 --- /dev/null +++ b/tests/compiler/abi.ts @@ -0,0 +1,81 @@ +// NOTE: this test mostly relies on comparing to the fixture because the ABI affects emitted +// instructions, not semantics. + +// exported functions should wrap their returns +export function exported(): i8 { + return 128; +} + +// internal functions should not wrap their returns +function internal(): i8 { + return 128; +} + +// calling a function that already wraps its return should not wrap again +export function exportedExported(): i8 { + return exported(); +} + +// calling a function that does not wrap its return should wrap it +export function exportedInternal(): i8 { + return internal(); +} + +internal(); // keep alive + +var condition = !0; + +// locals not marked as wrapped should be wrapped when necessaray +{ + let x: i8; + x = 256; // overflows to 0 + assert(!x); // should wrap +} + +// locals not marked as wrapped in all branches should be wrapped when necessary +{ + let x: i8; + x = 256; // overflows to 0 + + if (condition) { + x = x / 2; // should sign-extend x on input + } else { + x = x / 2; // ^ + } + assert(!x); // should wrap x +} + +// locals marked as wrapped in all branches should not be wrapped again +{ + let x: i8; // local + x = 256; // overflows to 0 + + if (condition) { + x = x >> 24; // should mark result as wrapped + } else { + x = x & 127; // ^ + } + assert(!x); // should not wrap +} + +// unlike locals, globals are wrapped on assignment +var y: i8; +{ + y = 256; // should wrap + assert(!y); // should not wrap +} + +// certain operations do not overflow, depending on target type +{ + let b: bool; + b = ctz(2); + assert(b); // should wrap + b = clz(1); + assert(b); // should wrap + let x: i8; + x = ctz(2); + assert(x); // should not wrap + x = clz(1); + assert(x); // should not wrap + // TODO: test more? +} diff --git a/tests/compiler/abi.untouched.wat b/tests/compiler/abi.untouched.wat new file mode 100644 index 00000000..45bf9566 --- /dev/null +++ b/tests/compiler/abi.untouched.wat @@ -0,0 +1,302 @@ +(module + (type $i (func (result i32))) + (type $iiiiv (func (param i32 i32 i32 i32))) + (type $v (func)) + (import "env" "abort" (func $abort (param i32 i32 i32 i32))) + (global $abi/condition (mut i32) (i32.const 0)) + (global $abi/y (mut i32) (i32.const 0)) + (global $HEAP_BASE i32 (i32.const 20)) + (memory $0 1) + (data (i32.const 4) "\06\00\00\00a\00b\00i\00.\00t\00s\00") + (export "exported" (func $abi/exported)) + (export "exportedExported" (func $abi/exportedExported)) + (export "exportedInternal" (func $abi/exportedInternal)) + (export "memory" (memory $0)) + (start $start) + (func $abi/exported (; 1 ;) (type $i) (result i32) + (return + (i32.shr_s + (i32.shl + (i32.const 128) + (i32.const 24) + ) + (i32.const 24) + ) + ) + ) + (func $abi/exportedExported (; 2 ;) (type $i) (result i32) + (return + (call $abi/exported) + ) + ) + (func $abi/internal (; 3 ;) (type $i) (result i32) + (return + (i32.const 128) + ) + ) + (func $abi/exportedInternal (; 4 ;) (type $i) (result i32) + (return + (i32.shr_s + (i32.shl + (call $abi/internal) + (i32.const 24) + ) + (i32.const 24) + ) + ) + ) + (func $start (; 5 ;) (type $v) + (local $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (drop + (call $abi/internal) + ) + (set_global $abi/condition + (i32.eqz + (i32.const 0) + ) + ) + (block + (nop) + (set_local $0 + (i32.const 256) + ) + (if + (i32.eqz + (i32.eqz + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 32) + (i32.const 2) + ) + (unreachable) + ) + ) + ) + (block + (nop) + (set_local $1 + (i32.const 256) + ) + (if + (get_global $abi/condition) + (set_local $1 + (i32.div_s + (i32.shr_s + (i32.shl + (get_local $1) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 2) + ) + ) + (set_local $1 + (i32.div_s + (i32.shr_s + (i32.shl + (get_local $1) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 2) + ) + ) + ) + (if + (i32.eqz + (i32.eqz + (i32.shr_s + (i32.shl + (get_local $1) + (i32.const 24) + ) + (i32.const 24) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 45) + (i32.const 2) + ) + (unreachable) + ) + ) + ) + (block + (nop) + (set_local $2 + (i32.const 256) + ) + (if + (get_global $abi/condition) + (set_local $2 + (i32.shr_s + (i32.shr_s + (i32.shl + (get_local $2) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $2 + (i32.and + (get_local $2) + (i32.const 127) + ) + ) + ) + (if + (i32.eqz + (i32.eqz + (get_local $2) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 58) + (i32.const 2) + ) + (unreachable) + ) + ) + ) + (block + (set_global $abi/y + (i32.shr_s + (i32.shl + (i32.const 256) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (if + (i32.eqz + (i32.eqz + (get_global $abi/y) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 65) + (i32.const 2) + ) + (unreachable) + ) + ) + ) + (block + (nop) + (set_local $3 + (i32.ctz + (i32.const 2) + ) + ) + (if + (i32.eqz + (i32.and + (get_local $3) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 72) + (i32.const 2) + ) + (unreachable) + ) + ) + (set_local $3 + (i32.clz + (i32.const 1) + ) + ) + (if + (i32.eqz + (i32.and + (get_local $3) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 74) + (i32.const 2) + ) + (unreachable) + ) + ) + (nop) + (set_local $4 + (i32.ctz + (i32.const 2) + ) + ) + (if + (i32.eqz + (get_local $4) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 77) + (i32.const 2) + ) + (unreachable) + ) + ) + (set_local $4 + (i32.clz + (i32.const 1) + ) + ) + (if + (i32.eqz + (get_local $4) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 79) + (i32.const 2) + ) + (unreachable) + ) + ) + ) + ) +) diff --git a/tests/compiler/assert.ts b/tests/compiler/assert.ts index 97958cca..012e1946 100644 --- a/tests/compiler/assert.ts +++ b/tests/compiler/assert.ts @@ -7,5 +7,4 @@ assert(0x100000000); assert(0x100000000 > 1); // can be used as an expression -if (!assert(true, "must be true")) - unreachable(); +if (!assert(true, "must be true")) unreachable(); diff --git a/tests/compiler/assert.untouched.wat b/tests/compiler/assert.untouched.wat index cc152af9..3d839b02 100644 --- a/tests/compiler/assert.untouched.wat +++ b/tests/compiler/assert.untouched.wat @@ -41,7 +41,7 @@ ) (if (i32.eqz - (i32.gt_s + (i32.gt_u (i32.const 1) (i32.const 0) ) @@ -122,11 +122,10 @@ (if (i32.eqz (if (result i32) - (i32.eqz - (tee_local $0 - (i32.const 1) - ) + (tee_local $0 + (i32.const 1) ) + (get_local $0) (block (call $abort (i32.const 28) @@ -136,7 +135,6 @@ ) (unreachable) ) - (get_local $0) ) ) (unreachable) diff --git a/tests/compiler/binary.optimized.wat b/tests/compiler/binary.optimized.wat index 5c2a3eca..492b64fa 100644 --- a/tests/compiler/binary.optimized.wat +++ b/tests/compiler/binary.optimized.wat @@ -204,63 +204,51 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.gt_s - (get_local $6) - (i32.const 2146435072) - ) - ) - (get_local $5) - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $6) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $7) - (i32.const 0) - ) - (get_local $5) - ) - ) - (i32.const 1) - ) - ) - (get_local $5) - (i32.gt_s - (get_local $10) - (i32.const 2146435072) - ) - ) - (i32.const 1) - ) - ) - (get_local $5) (if (result i32) (tee_local $5 - (i32.eq - (get_local $10) + (i32.gt_s + (get_local $6) (i32.const 2146435072) ) ) - (i32.ne - (get_local $4) - (i32.const 0) - ) (get_local $5) + (tee_local $5 + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $6) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $7) + (i32.const 0) + ) + (get_local $5) + ) + ) + ) + (get_local $5) + (tee_local $5 + (i32.gt_s + (get_local $10) + (i32.const 2146435072) + ) ) ) - (i32.const 1) + (get_local $5) + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $10) + (i32.const 2146435072) + ) + ) + (get_local $4) + (get_local $5) + ) ) (return (f64.add @@ -482,32 +470,26 @@ (get_local $7) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $6) - (i32.const 2146435072) - ) - ) - (get_local $5) - (i32.eqz - (get_local $6) - ) - ) - (i32.const 1) + (i32.eq + (get_local $6) + (i32.const 2146435072) ) ) (get_local $5) - (i32.eq - (get_local $6) - (i32.const 1072693248) + (tee_local $5 + (i32.eqz + (get_local $6) + ) ) ) - (i32.const 1) + (get_local $5) + (i32.eq + (get_local $6) + (i32.const 1072693248) + ) ) (block (if @@ -1568,34 +1550,28 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $3 - (i32.and - (if (result i32) - (tee_local $3 - (i32.eqz - (i32.shl - (get_local $5) - (i32.const 1) - ) - ) - ) - (get_local $3) - (call $isNaN - (get_local $1) - ) + (i32.eqz + (i32.shl + (get_local $5) + (i32.const 1) ) - (i32.const 1) ) ) (get_local $3) - (i32.eq - (get_local $4) - (i32.const 255) + (tee_local $3 + (call $isNaN + (get_local $1) + ) ) ) - (i32.const 1) + (get_local $3) + (i32.eq + (get_local $4) + (i32.const 255) + ) ) (return (f32.div @@ -1999,21 +1975,22 @@ (local $4 i32) (local $5 i32) (local $6 i32) - (local $7 i32) - (local $8 f32) + (local $7 f32) + (local $8 i32) (local $9 f32) (local $10 i32) (local $11 i32) (local $12 f32) - (local $13 f32) + (local $13 i32) (local $14 f32) - (local $15 i32) - (local $16 f32) + (local $15 f32) + (local $16 i32) + (local $17 f32) (block $folding-inner1 (block $folding-inner0 (set_local $5 (i32.and - (tee_local $15 + (tee_local $4 (i32.reinterpret/f32 (get_local $0) ) @@ -2039,21 +2016,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.gt_s - (get_local $5) - (i32.const 2139095040) - ) - ) - (get_local $6) + (if (result i32) + (tee_local $13 (i32.gt_s - (get_local $10) + (get_local $5) (i32.const 2139095040) ) ) - (i32.const 1) + (get_local $13) + (i32.gt_s + (get_local $10) + (i32.const 2139095040) + ) ) (return (f32.add @@ -2064,7 +2038,7 @@ ) (if (i32.lt_s - (get_local $15) + (get_local $4) (i32.const 0) ) (if @@ -2072,7 +2046,7 @@ (get_local $10) (i32.const 1266679808) ) - (set_local $4 + (set_local $16 (i32.const 2) ) (if @@ -2083,12 +2057,12 @@ (if (i32.eq (i32.shl - (tee_local $7 + (tee_local $6 (i32.shr_s (get_local $10) (i32.sub (i32.const 23) - (tee_local $6 + (tee_local $8 (i32.sub (i32.shr_s (get_local $10) @@ -2102,16 +2076,16 @@ ) (i32.sub (i32.const 23) - (get_local $6) + (get_local $8) ) ) (get_local $10) ) - (set_local $4 + (set_local $16 (i32.sub (i32.const 2) (i32.and - (get_local $7) + (get_local $6) (i32.const 1) ) ) @@ -2201,7 +2175,7 @@ ) (if (i32.ge_s - (get_local $15) + (get_local $4) (i32.const 0) ) (return @@ -2217,32 +2191,26 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) - (tee_local $6 - (i32.and - (if (result i32) - (tee_local $6 - (i32.eq - (get_local $5) - (i32.const 2139095040) - ) - ) - (get_local $6) - (i32.eqz - (get_local $5) - ) - ) - (i32.const 1) + (tee_local $13 + (i32.eq + (get_local $5) + (i32.const 2139095040) ) ) - (get_local $6) - (i32.eq - (get_local $5) - (i32.const 1065353216) + (get_local $13) + (tee_local $13 + (i32.eqz + (get_local $5) + ) ) ) - (i32.const 1) + (get_local $13) + (i32.eq + (get_local $5) + (i32.const 1065353216) + ) ) (block (if @@ -2259,7 +2227,7 @@ ) (if (i32.lt_s - (get_local $15) + (get_local $4) (i32.const 0) ) (if @@ -2268,11 +2236,11 @@ (get_local $5) (i32.const 1065353216) ) - (get_local $4) + (get_local $16) ) (if (i32.eq - (get_local $4) + (get_local $16) (i32.const 1) ) (set_local $2 @@ -2305,13 +2273,13 @@ ) (if (i32.lt_s - (get_local $15) + (get_local $4) (i32.const 0) ) (block (if (i32.eqz - (get_local $4) + (get_local $16) ) (return (f32.div @@ -2328,7 +2296,7 @@ ) (if (i32.eq - (get_local $4) + (get_local $16) (i32.const 1) ) (set_local $9 @@ -2426,18 +2394,18 @@ ) ) ) - (set_local $8 + (set_local $7 (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 (f32.add - (tee_local $13 + (tee_local $14 (f32.mul (f32.const 1.44268798828125) (get_local $3) ) ) - (tee_local $14 + (tee_local $15 (f32.sub (f32.mul (get_local $3) @@ -2456,10 +2424,10 @@ ) ) (f32.sub - (get_local $14) + (get_local $15) (f32.sub - (get_local $8) - (get_local $13) + (get_local $7) + (get_local $14) ) ) ) @@ -2503,7 +2471,7 @@ ) (set_local $5 (i32.or - (tee_local $7 + (tee_local $6 (i32.and (get_local $5) (i32.const 8388607) @@ -2512,16 +2480,16 @@ (i32.const 1065353216) ) ) - (set_local $6 + (set_local $8 (if (result i32) (i32.le_s - (get_local $7) + (get_local $6) (i32.const 1885297) ) (i32.const 0) (if (result i32) (i32.lt_s - (get_local $7) + (get_local $6) (i32.const 6140887) ) (i32.const 1) @@ -2547,9 +2515,9 @@ (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 - (tee_local $16 + (tee_local $17 (f32.mul - (tee_local $13 + (tee_local $14 (f32.sub (tee_local $2 (f32.reinterpret/i32 @@ -2560,12 +2528,12 @@ (select (f32.const 1.5) (f32.const 1) - (get_local $6) + (get_local $8) ) ) ) ) - (tee_local $14 + (tee_local $15 (f32.div (f32.const 1) (f32.add @@ -2585,7 +2553,7 @@ (f32.sub (get_local $2) (f32.sub - (tee_local $8 + (tee_local $7 (f32.reinterpret/i32 (i32.add (i32.add @@ -2602,7 +2570,7 @@ (i32.const 4194304) ) (i32.shl - (get_local $6) + (get_local $8) (i32.const 21) ) ) @@ -2620,8 +2588,8 @@ (f32.mul (tee_local $12 (f32.mul - (get_local $16) - (get_local $16) + (get_local $17) + (get_local $17) ) ) (get_local $12) @@ -2661,13 +2629,13 @@ (f32.mul (tee_local $0 (f32.mul - (get_local $14) + (get_local $15) (f32.sub (f32.sub - (get_local $13) + (get_local $14) (f32.mul (get_local $3) - (get_local $8) + (get_local $7) ) ) (f32.mul @@ -2679,14 +2647,14 @@ ) (f32.add (get_local $3) - (get_local $16) + (get_local $17) ) ) ) ) (f32.sub (f32.sub - (tee_local $8 + (tee_local $7 (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 @@ -2713,14 +2681,14 @@ ) ) ) - (set_local $8 + (set_local $7 (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 (f32.add (f32.add (f32.add - (tee_local $16 + (tee_local $17 (f32.mul (f32.const 0.9619140625) (tee_local $0 @@ -2728,21 +2696,21 @@ (i32.and (i32.reinterpret/f32 (f32.add - (tee_local $13 + (tee_local $14 (f32.mul (get_local $3) - (get_local $8) + (get_local $7) ) ) - (tee_local $14 + (tee_local $15 (f32.add (f32.mul (get_local $0) - (get_local $8) + (get_local $7) ) (f32.mul (get_local $2) - (get_local $16) + (get_local $17) ) ) ) @@ -2763,10 +2731,10 @@ ) (f32.mul (f32.sub - (get_local $14) + (get_local $15) (f32.sub (get_local $0) - (get_local $13) + (get_local $14) ) ) (f32.const 0.9617967009544373) @@ -2775,7 +2743,7 @@ (select (f32.const 1.5632208487659227e-06) (f32.const 0) - (get_local $6) + (get_local $8) ) ) ) @@ -2784,7 +2752,7 @@ (select (f32.const 0.5849609375) (f32.const 0) - (get_local $6) + (get_local $8) ) ) ) @@ -2804,12 +2772,12 @@ (f32.sub (f32.sub (f32.sub - (get_local $8) + (get_local $7) (get_local $3) ) (get_local $0) ) - (get_local $16) + (get_local $17) ) ) ) @@ -2817,7 +2785,7 @@ ) (br_if $folding-inner1 (i32.gt_s - (tee_local $7 + (tee_local $6 (i32.reinterpret/f32 (tee_local $2 (f32.add @@ -2837,7 +2805,7 @@ ) ) ) - (get_local $8) + (get_local $7) ) (f32.mul (get_local $1) @@ -2848,7 +2816,7 @@ (tee_local $0 (f32.mul (get_local $0) - (get_local $8) + (get_local $7) ) ) ) @@ -2860,7 +2828,7 @@ ) (if (i32.eq - (get_local $7) + (get_local $6) (i32.const 1124073472) ) (br_if $folding-inner1 @@ -2878,7 +2846,7 @@ (if (i32.gt_s (i32.and - (get_local $7) + (get_local $6) (i32.const 2147483647) ) (i32.const 1125515264) @@ -2886,7 +2854,7 @@ (br $folding-inner0) (if (i32.eq - (get_local $7) + (get_local $6) (i32.const -1021968384) ) (br_if $folding-inner0 @@ -2901,12 +2869,12 @@ ) ) ) - (set_local $6 + (set_local $8 (i32.sub (i32.shr_s - (tee_local $15 + (tee_local $13 (i32.and - (get_local $7) + (get_local $6) (i32.const 2147483647) ) ) @@ -2920,21 +2888,21 @@ ) (if (i32.gt_s - (get_local $15) + (get_local $13) (i32.const 1056964608) ) (block - (set_local $6 + (set_local $8 (i32.sub (i32.shr_s (i32.and (tee_local $4 (i32.add - (get_local $7) + (get_local $6) (i32.shr_s (i32.const 8388608) (i32.add - (get_local $6) + (get_local $8) (i32.const 1) ) ) @@ -2954,7 +2922,7 @@ (i32.xor (i32.shr_s (i32.const 8388607) - (get_local $6) + (get_local $8) ) (i32.const -1) ) @@ -2972,13 +2940,13 @@ ) (i32.sub (i32.const 23) - (get_local $6) + (get_local $8) ) ) ) (if (i32.lt_s - (get_local $7) + (get_local $6) (i32.const 0) ) (set_local $4 @@ -3003,7 +2971,7 @@ (if (result f32) (i32.le_s (i32.shr_s - (tee_local $7 + (tee_local $6 (i32.add (i32.reinterpret/f32 (tee_local $2 @@ -3015,7 +2983,7 @@ (f32.mul (tee_local $2 (f32.add - (tee_local $13 + (tee_local $14 (f32.mul (tee_local $3 (f32.reinterpret/i32 @@ -3033,7 +3001,7 @@ (f32.const 0.693145751953125) ) ) - (tee_local $14 + (tee_local $15 (f32.add (f32.mul (f32.sub @@ -3053,7 +3021,7 @@ ) ) ) - (tee_local $8 + (tee_local $7 (f32.sub (get_local $2) (f32.mul @@ -3093,17 +3061,17 @@ ) ) (f32.sub - (get_local $8) + (get_local $7) (f32.const 2) ) ) (f32.add (tee_local $0 (f32.sub - (get_local $14) + (get_local $15) (f32.sub (get_local $2) - (get_local $13) + (get_local $14) ) ) ) @@ -3133,7 +3101,7 @@ (get_local $4) ) (f32.reinterpret/i32 - (get_local $7) + (get_local $6) ) ) ) @@ -3203,35 +3171,29 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i64.eq - (i64.shl - (get_local $5) - (i64.const 1) - ) - (i64.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) - ) + (i64.eq + (i64.shl + (get_local $5) + (i64.const 1) ) - (i32.const 1) + (i64.const 0) ) ) (get_local $7) - (i32.eq - (get_local $3) - (i32.const 2047) + (tee_local $7 + (call $isNaN + (get_local $1) + ) ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $3) + (i32.const 2047) + ) ) (return (f64.div diff --git a/tests/compiler/binary.untouched.wat b/tests/compiler/binary.untouched.wat index 707cbddb..d53f6d50 100644 --- a/tests/compiler/binary.untouched.wat +++ b/tests/compiler/binary.untouched.wat @@ -242,63 +242,54 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $9 - (i32.and + (if (result i32) + (tee_local $9 + (if (result i32) + (tee_local $9 (if (result i32) (tee_local $9 - (i32.and - (if (result i32) - (tee_local $9 - (i32.gt_s - (get_local $7) - (i32.const 2146435072) - ) - ) - (get_local $9) - (if (result i32) - (tee_local $9 - (i32.eq - (get_local $7) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $4) - (i32.const 0) - ) - (get_local $9) - ) - ) - (i32.const 1) + (i32.gt_s + (get_local $7) + (i32.const 2146435072) ) ) (get_local $9) - (i32.gt_s - (get_local $8) - (i32.const 2146435072) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $7) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $4) + (i32.const 0) + ) + (get_local $9) ) ) - (i32.const 1) - ) - ) - (get_local $9) - (if (result i32) - (tee_local $9 - (i32.eq - (get_local $8) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $6) - (i32.const 0) ) (get_local $9) + (i32.gt_s + (get_local $8) + (i32.const 2146435072) + ) ) ) - (i32.const 1) + (get_local $9) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $8) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $6) + (i32.const 0) + ) + (get_local $9) + ) ) (return (f64.add @@ -538,33 +529,27 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $15 - (i32.and - (if (result i32) - (tee_local $15 - (i32.eq - (get_local $7) - (i32.const 2146435072) - ) - ) - (get_local $15) - (i32.eq - (get_local $7) - (i32.const 0) - ) + (if (result i32) + (tee_local $15 + (if (result i32) + (tee_local $15 + (i32.eq + (get_local $7) + (i32.const 2146435072) ) - (i32.const 1) + ) + (get_local $15) + (i32.eq + (get_local $7) + (i32.const 0) ) ) - (get_local $15) - (i32.eq - (get_local $7) - (i32.const 1072693248) - ) ) - (i32.const 1) + (get_local $15) + (i32.eq + (get_local $7) + (i32.const 1072693248) + ) ) (block (set_local $14 @@ -1772,35 +1757,29 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i32.eq - (i32.shl - (get_local $3) - (i32.const 1) - ) - (i32.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) + (if (result i32) + (tee_local $7 + (if (result i32) + (tee_local $7 + (i32.eq + (i32.shl + (get_local $3) + (i32.const 1) ) + (i32.const 0) ) - (i32.const 1) + ) + (get_local $7) + (call $isNaN + (get_local $1) ) ) - (get_local $7) - (i32.eq - (get_local $4) - (i32.const 255) - ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $4) + (i32.const 255) + ) ) (return (f32.div @@ -2349,21 +2328,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.gt_s - (get_local $4) - (i32.const 2139095040) - ) - ) - (get_local $6) + (if (result i32) + (tee_local $6 (i32.gt_s - (get_local $5) + (get_local $4) (i32.const 2139095040) ) ) - (i32.const 1) + (get_local $6) + (i32.gt_s + (get_local $5) + (i32.const 2139095040) + ) ) (return (f32.add @@ -2535,33 +2511,27 @@ ) (nop) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.and - (if (result i32) - (tee_local $6 - (i32.eq - (get_local $4) - (i32.const 2139095040) - ) - ) - (get_local $6) - (i32.eq - (get_local $4) - (i32.const 0) - ) + (if (result i32) + (tee_local $6 + (if (result i32) + (tee_local $6 + (i32.eq + (get_local $4) + (i32.const 2139095040) ) - (i32.const 1) + ) + (get_local $6) + (i32.eq + (get_local $4) + (i32.const 0) ) ) - (get_local $6) - (i32.eq - (get_local $4) - (i32.const 1065353216) - ) ) - (i32.const 1) + (get_local $6) + (i32.eq + (get_local $4) + (i32.const 1065353216) + ) ) (block (set_local $11 @@ -3668,35 +3638,29 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i64.eq - (i64.shl - (get_local $3) - (i64.const 1) - ) - (i64.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) + (if (result i32) + (tee_local $7 + (if (result i32) + (tee_local $7 + (i64.eq + (i64.shl + (get_local $3) + (i64.const 1) ) + (i64.const 0) ) - (i32.const 1) + ) + (get_local $7) + (call $isNaN + (get_local $1) ) ) - (get_local $7) - (i32.eq - (get_local $4) - (i32.const 2047) - ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $4) + (i32.const 2047) + ) ) (return (f64.div diff --git a/tests/compiler/class.untouched.wat b/tests/compiler/class.untouched.wat index 1198686d..b1671e6e 100644 --- a/tests/compiler/class.untouched.wat +++ b/tests/compiler/class.untouched.wat @@ -103,31 +103,19 @@ ) (i32.store16 offset=4 (get_local $0) - (i32.shr_s - (i32.shl - (i32.add - (i32.const 1) - (i32.const 1) - ) - (i32.const 16) - ) - (i32.const 16) + (i32.add + (i32.const 1) + (i32.const 1) ) ) (i32.store8 offset=6 (get_local $0) - (i32.shr_s - (i32.shl - (i32.add - (i32.add - (i32.const 1) - (i32.const 1) - ) - (i32.const 1) - ) - (i32.const 24) + (i32.add + (i32.add + (i32.const 1) + (i32.const 1) ) - (i32.const 24) + (i32.const 1) ) ) (set_local $1 diff --git a/tests/compiler/mandelbrot.optimized.wat b/tests/compiler/mandelbrot.optimized.wat index 8e3589b2..4c06db65 100644 --- a/tests/compiler/mandelbrot.optimized.wat +++ b/tests/compiler/mandelbrot.optimized.wat @@ -16,32 +16,29 @@ (local $7 f64) (local $8 f64) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_u - (tee_local $1 - (i32.wrap/i64 - (i64.shr_u - (tee_local $3 - (i64.reinterpret/f64 - (get_local $0) - ) + (if (result i32) + (tee_local $5 + (i32.lt_u + (tee_local $1 + (i32.wrap/i64 + (i64.shr_u + (tee_local $3 + (i64.reinterpret/f64 + (get_local $0) ) - (i64.const 32) ) + (i64.const 32) ) ) - (i32.const 1048576) ) - ) - (get_local $5) - (i32.shr_u - (get_local $1) - (i32.const 31) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $5) + (i32.shr_u + (get_local $1) + (i32.const 31) + ) ) (block (if @@ -108,24 +105,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $1) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $1) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $3) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $5) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $3) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $5) ) (return (f64.const 0) diff --git a/tests/compiler/mandelbrot.untouched.wat b/tests/compiler/mandelbrot.untouched.wat index 471254fb..99bccb2f 100644 --- a/tests/compiler/mandelbrot.untouched.wat +++ b/tests/compiler/mandelbrot.untouched.wat @@ -42,24 +42,18 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_u - (get_local $2) - (i32.const 1048576) - ) - ) - (get_local $4) - (i32.and - (i32.shr_u - (get_local $2) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $4 + (i32.lt_u + (get_local $2) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $4) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -130,24 +124,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $4 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $1) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $4) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $1) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $4) ) (return (f64.const 0) diff --git a/tests/compiler/memset.optimized.wat b/tests/compiler/memset.optimized.wat index 6731e357..ae530fed 100644 --- a/tests/compiler/memset.optimized.wat +++ b/tests/compiler/memset.optimized.wat @@ -122,7 +122,10 @@ ) (tee_local $1 (i32.mul - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) (i32.const 16843009) ) ) diff --git a/tests/compiler/memset.untouched.wat b/tests/compiler/memset.untouched.wat index 6621d66c..8744250b 100644 --- a/tests/compiler/memset.untouched.wat +++ b/tests/compiler/memset.untouched.wat @@ -151,7 +151,10 @@ (i32.const -1) (i32.const 255) ) - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) ) ) (i32.store diff --git a/tests/compiler/overflow.optimized.wat b/tests/compiler/overflow.optimized.wat index 5ed7e91a..4a907514 100644 --- a/tests/compiler/overflow.optimized.wat +++ b/tests/compiler/overflow.optimized.wat @@ -11,9 +11,9 @@ (if (i32.ne (tee_local $0 - (i32.const -128) + (i32.const 128) ) - (i32.const -128) + (i32.const 128) ) (block (call $abort @@ -27,17 +27,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 24) + (i32.and + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 1) ) - (i32.const 24) ) + (i32.const 255) ) (i32.const 127) ) @@ -53,19 +50,16 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.add - (get_local $0) - (i32.const 1) - ) - (i32.const 24) + (i32.and + (tee_local $0 + (i32.add + (get_local $0) + (i32.const 1) ) - (i32.const 24) ) + (i32.const 255) ) - (i32.const -128) + (i32.const 128) ) (block (call $abort @@ -79,17 +73,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 24) + (i32.and + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 1) ) - (i32.const 24) ) + (i32.const 255) ) (i32.const 127) ) @@ -105,19 +96,16 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.add - (get_local $0) - (i32.const 1) - ) - (i32.const 24) + (i32.and + (tee_local $0 + (i32.add + (get_local $0) + (i32.const 1) ) - (i32.const 24) ) + (i32.const 255) ) - (i32.const -128) + (i32.const 128) ) (block (call $abort @@ -131,17 +119,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 24) + (i32.and + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 1) ) - (i32.const 24) ) + (i32.const 255) ) (i32.const 127) ) @@ -157,19 +142,16 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.add - (get_local $0) - (i32.const 1) - ) - (i32.const 24) + (i32.and + (tee_local $0 + (i32.add + (get_local $0) + (i32.const 1) ) - (i32.const 24) ) + (i32.const 255) ) - (i32.const -128) + (i32.const 128) ) (block (call $abort @@ -183,17 +165,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 24) + (i32.and + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 1) ) - (i32.const 24) ) + (i32.const 255) ) (i32.const 127) ) @@ -231,9 +210,9 @@ (if (i32.ne (tee_local $0 - (i32.const -32768) + (i32.const 32768) ) - (i32.const -32768) + (i32.const 32768) ) (block (call $abort @@ -247,17 +226,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 16) + (i32.and + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 1) ) - (i32.const 16) ) + (i32.const 65535) ) (i32.const 32767) ) @@ -273,19 +249,16 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.add - (get_local $0) - (i32.const 1) - ) - (i32.const 16) + (i32.and + (tee_local $0 + (i32.add + (get_local $0) + (i32.const 1) ) - (i32.const 16) ) + (i32.const 65535) ) - (i32.const -32768) + (i32.const 32768) ) (block (call $abort @@ -299,17 +272,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 16) + (i32.and + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 1) ) - (i32.const 16) ) + (i32.const 65535) ) (i32.const 32767) ) @@ -325,19 +295,16 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.add - (get_local $0) - (i32.const 1) - ) - (i32.const 16) + (i32.and + (tee_local $0 + (i32.add + (get_local $0) + (i32.const 1) ) - (i32.const 16) ) + (i32.const 65535) ) - (i32.const -32768) + (i32.const 32768) ) (block (call $abort @@ -351,17 +318,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 16) + (i32.and + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 1) ) - (i32.const 16) ) + (i32.const 65535) ) (i32.const 32767) ) @@ -377,19 +341,16 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.add - (get_local $0) - (i32.const 1) - ) - (i32.const 16) + (i32.and + (tee_local $0 + (i32.add + (get_local $0) + (i32.const 1) ) - (i32.const 16) ) + (i32.const 65535) ) - (i32.const -32768) + (i32.const 32768) ) (block (call $abort @@ -403,17 +364,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 16) + (i32.and + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 1) ) - (i32.const 16) ) + (i32.const 65535) ) (i32.const 32767) ) @@ -450,7 +408,10 @@ ) (if (i32.ne - (tee_local $0 + (i32.and + (tee_local $0 + (i32.const -1) + ) (i32.const 255) ) (i32.const 255) @@ -466,14 +427,14 @@ ) ) (if - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.add (get_local $0) (i32.const 1) ) - (i32.const 255) ) + (i32.const 255) ) (block (call $abort @@ -487,14 +448,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.sub (get_local $0) (i32.const 1) ) - (i32.const 255) ) + (i32.const 255) ) (i32.const 255) ) @@ -509,14 +470,14 @@ ) ) (if - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.add (get_local $0) (i32.const 1) ) - (i32.const 255) ) + (i32.const 255) ) (block (call $abort @@ -530,14 +491,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.sub (get_local $0) (i32.const 1) ) - (i32.const 255) ) + (i32.const 255) ) (i32.const 255) ) @@ -552,14 +513,14 @@ ) ) (if - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.add (get_local $0) (i32.const 1) ) - (i32.const 255) ) + (i32.const 255) ) (block (call $abort @@ -573,14 +534,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.sub (get_local $0) (i32.const 1) ) - (i32.const 255) ) + (i32.const 255) ) (i32.const 255) ) @@ -595,14 +556,14 @@ ) ) (if - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.add (get_local $0) (i32.const 1) ) - (i32.const 255) ) + (i32.const 255) ) (block (call $abort @@ -637,7 +598,10 @@ ) (if (i32.ne - (tee_local $0 + (i32.and + (tee_local $0 + (i32.const -1) + ) (i32.const 65535) ) (i32.const 65535) @@ -653,14 +617,14 @@ ) ) (if - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.add (get_local $0) (i32.const 1) ) - (i32.const 65535) ) + (i32.const 65535) ) (block (call $abort @@ -674,14 +638,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.sub (get_local $0) (i32.const 1) ) - (i32.const 65535) ) + (i32.const 65535) ) (i32.const 65535) ) @@ -696,14 +660,14 @@ ) ) (if - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.add (get_local $0) (i32.const 1) ) - (i32.const 65535) ) + (i32.const 65535) ) (block (call $abort @@ -717,14 +681,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.sub (get_local $0) (i32.const 1) ) - (i32.const 65535) ) + (i32.const 65535) ) (i32.const 65535) ) @@ -739,14 +703,14 @@ ) ) (if - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.add (get_local $0) (i32.const 1) ) - (i32.const 65535) ) + (i32.const 65535) ) (block (call $abort @@ -760,14 +724,14 @@ ) (if (i32.ne - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.sub (get_local $0) (i32.const 1) ) - (i32.const 65535) ) + (i32.const 65535) ) (i32.const 65535) ) @@ -782,14 +746,14 @@ ) ) (if - (tee_local $0 - (i32.and + (i32.and + (tee_local $0 (i32.add (get_local $0) (i32.const 1) ) - (i32.const 65535) ) + (i32.const 65535) ) (block (call $abort diff --git a/tests/compiler/overflow.untouched.wat b/tests/compiler/overflow.untouched.wat index 1343f721..738efea3 100644 --- a/tests/compiler/overflow.untouched.wat +++ b/tests/compiler/overflow.untouched.wat @@ -23,21 +23,21 @@ ) (nop) (set_local $0 - (i32.shr_s - (i32.shl - (i32.add - (get_local $0) - (i32.const 1) - ) - (i32.const 24) - ) - (i32.const 24) + (i32.add + (get_local $0) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $0) + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) (i32.const -128) ) ) @@ -52,21 +52,21 @@ ) ) (set_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 24) - ) - (i32.const 24) + (i32.sub + (get_local $0) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $0) + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) (i32.const 127) ) ) @@ -86,15 +86,9 @@ (get_local $0) ) (set_local $0 - (i32.shr_s - (i32.shl - (i32.add - (get_local $2) - (i32.const 1) - ) - (i32.const 24) - ) - (i32.const 24) + (i32.add + (get_local $2) + (i32.const 1) ) ) (get_local $2) @@ -103,7 +97,13 @@ (if (i32.eqz (i32.eq - (get_local $0) + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) (i32.const -128) ) ) @@ -123,15 +123,9 @@ (get_local $0) ) (set_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $2) - (i32.const 1) - ) - (i32.const 24) - ) - (i32.const 24) + (i32.sub + (get_local $2) + (i32.const 1) ) ) (get_local $2) @@ -140,7 +134,13 @@ (if (i32.eqz (i32.eq - (get_local $0) + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) (i32.const 127) ) ) @@ -155,21 +155,21 @@ ) ) (set_local $0 - (i32.shr_s - (i32.shl - (i32.add - (get_local $0) - (i32.const 1) - ) - (i32.const 24) - ) - (i32.const 24) + (i32.add + (get_local $0) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $0) + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) (i32.const -128) ) ) @@ -184,21 +184,21 @@ ) ) (set_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 24) - ) - (i32.const 24) + (i32.sub + (get_local $0) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $0) + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) (i32.const 127) ) ) @@ -214,22 +214,22 @@ ) (set_local $1 (tee_local $0 - (i32.shr_s - (i32.shl - (i32.add - (get_local $0) - (i32.const 1) - ) - (i32.const 24) - ) - (i32.const 24) + (i32.add + (get_local $0) + (i32.const 1) ) ) ) (if (i32.eqz (i32.eq - (get_local $0) + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) (i32.const -128) ) ) @@ -245,22 +245,22 @@ ) (set_local $1 (tee_local $0 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $0) - (i32.const 1) - ) - (i32.const 24) - ) - (i32.const 24) + (i32.sub + (get_local $0) + (i32.const 1) ) ) ) (if (i32.eqz (i32.eq - (get_local $0) + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) (i32.const 127) ) ) @@ -307,21 +307,21 @@ ) (nop) (set_local $2 - (i32.shr_s - (i32.shl - (i32.add - (get_local $2) - (i32.const 1) - ) - (i32.const 16) - ) - (i32.const 16) + (i32.add + (get_local $2) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $2) + (i32.shr_s + (i32.shl + (get_local $2) + (i32.const 16) + ) + (i32.const 16) + ) (i32.const -32768) ) ) @@ -336,21 +336,21 @@ ) ) (set_local $2 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $2) - (i32.const 1) - ) - (i32.const 16) - ) - (i32.const 16) + (i32.sub + (get_local $2) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $2) + (i32.shr_s + (i32.shl + (get_local $2) + (i32.const 16) + ) + (i32.const 16) + ) (i32.const 32767) ) ) @@ -370,15 +370,9 @@ (get_local $2) ) (set_local $2 - (i32.shr_s - (i32.shl - (i32.add - (get_local $4) - (i32.const 1) - ) - (i32.const 16) - ) - (i32.const 16) + (i32.add + (get_local $4) + (i32.const 1) ) ) (get_local $4) @@ -387,7 +381,13 @@ (if (i32.eqz (i32.eq - (get_local $2) + (i32.shr_s + (i32.shl + (get_local $2) + (i32.const 16) + ) + (i32.const 16) + ) (i32.const -32768) ) ) @@ -407,15 +407,9 @@ (get_local $2) ) (set_local $2 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $4) - (i32.const 1) - ) - (i32.const 16) - ) - (i32.const 16) + (i32.sub + (get_local $4) + (i32.const 1) ) ) (get_local $4) @@ -424,7 +418,13 @@ (if (i32.eqz (i32.eq - (get_local $2) + (i32.shr_s + (i32.shl + (get_local $2) + (i32.const 16) + ) + (i32.const 16) + ) (i32.const 32767) ) ) @@ -439,21 +439,21 @@ ) ) (set_local $2 - (i32.shr_s - (i32.shl - (i32.add - (get_local $2) - (i32.const 1) - ) - (i32.const 16) - ) - (i32.const 16) + (i32.add + (get_local $2) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $2) + (i32.shr_s + (i32.shl + (get_local $2) + (i32.const 16) + ) + (i32.const 16) + ) (i32.const -32768) ) ) @@ -468,21 +468,21 @@ ) ) (set_local $2 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $2) - (i32.const 1) - ) - (i32.const 16) - ) - (i32.const 16) + (i32.sub + (get_local $2) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $2) + (i32.shr_s + (i32.shl + (get_local $2) + (i32.const 16) + ) + (i32.const 16) + ) (i32.const 32767) ) ) @@ -498,22 +498,22 @@ ) (set_local $3 (tee_local $2 - (i32.shr_s - (i32.shl - (i32.add - (get_local $2) - (i32.const 1) - ) - (i32.const 16) - ) - (i32.const 16) + (i32.add + (get_local $2) + (i32.const 1) ) ) ) (if (i32.eqz (i32.eq - (get_local $2) + (i32.shr_s + (i32.shl + (get_local $2) + (i32.const 16) + ) + (i32.const 16) + ) (i32.const -32768) ) ) @@ -529,22 +529,22 @@ ) (set_local $3 (tee_local $2 - (i32.shr_s - (i32.shl - (i32.sub - (get_local $2) - (i32.const 1) - ) - (i32.const 16) - ) - (i32.const 16) + (i32.sub + (get_local $2) + (i32.const 1) ) ) ) (if (i32.eqz (i32.eq - (get_local $2) + (i32.shr_s + (i32.shl + (get_local $2) + (i32.const 16) + ) + (i32.const 16) + ) (i32.const 32767) ) ) @@ -591,18 +591,18 @@ ) (nop) (set_local $4 - (i32.and - (i32.sub - (get_local $4) - (i32.const 1) - ) - (i32.const 255) + (i32.sub + (get_local $4) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $4) + (i32.and + (get_local $4) + (i32.const 255) + ) (i32.const 255) ) ) @@ -617,18 +617,18 @@ ) ) (set_local $4 - (i32.and - (i32.add - (get_local $4) - (i32.const 1) - ) - (i32.const 255) + (i32.add + (get_local $4) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $4) + (i32.and + (get_local $4) + (i32.const 255) + ) (i32.const 0) ) ) @@ -648,12 +648,9 @@ (get_local $4) ) (set_local $4 - (i32.and - (i32.sub - (get_local $6) - (i32.const 1) - ) - (i32.const 255) + (i32.sub + (get_local $6) + (i32.const 1) ) ) (get_local $6) @@ -662,7 +659,10 @@ (if (i32.eqz (i32.eq - (get_local $4) + (i32.and + (get_local $4) + (i32.const 255) + ) (i32.const 255) ) ) @@ -682,12 +682,9 @@ (get_local $4) ) (set_local $4 - (i32.and - (i32.add - (get_local $6) - (i32.const 1) - ) - (i32.const 255) + (i32.add + (get_local $6) + (i32.const 1) ) ) (get_local $6) @@ -696,7 +693,10 @@ (if (i32.eqz (i32.eq - (get_local $4) + (i32.and + (get_local $4) + (i32.const 255) + ) (i32.const 0) ) ) @@ -711,18 +711,18 @@ ) ) (set_local $4 - (i32.and - (i32.sub - (get_local $4) - (i32.const 1) - ) - (i32.const 255) + (i32.sub + (get_local $4) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $4) + (i32.and + (get_local $4) + (i32.const 255) + ) (i32.const 255) ) ) @@ -737,18 +737,18 @@ ) ) (set_local $4 - (i32.and - (i32.add - (get_local $4) - (i32.const 1) - ) - (i32.const 255) + (i32.add + (get_local $4) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $4) + (i32.and + (get_local $4) + (i32.const 255) + ) (i32.const 0) ) ) @@ -764,19 +764,19 @@ ) (set_local $5 (tee_local $4 - (i32.and - (i32.sub - (get_local $4) - (i32.const 1) - ) - (i32.const 255) + (i32.sub + (get_local $4) + (i32.const 1) ) ) ) (if (i32.eqz (i32.eq - (get_local $4) + (i32.and + (get_local $4) + (i32.const 255) + ) (i32.const 255) ) ) @@ -792,19 +792,19 @@ ) (set_local $5 (tee_local $4 - (i32.and - (i32.add - (get_local $4) - (i32.const 1) - ) - (i32.const 255) + (i32.add + (get_local $4) + (i32.const 1) ) ) ) (if (i32.eqz (i32.eq - (get_local $4) + (i32.and + (get_local $4) + (i32.const 255) + ) (i32.const 0) ) ) @@ -848,18 +848,18 @@ ) (nop) (set_local $6 - (i32.and - (i32.sub - (get_local $6) - (i32.const 1) - ) - (i32.const 65535) + (i32.sub + (get_local $6) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $6) + (i32.and + (get_local $6) + (i32.const 65535) + ) (i32.const 65535) ) ) @@ -874,18 +874,18 @@ ) ) (set_local $6 - (i32.and - (i32.add - (get_local $6) - (i32.const 1) - ) - (i32.const 65535) + (i32.add + (get_local $6) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $6) + (i32.and + (get_local $6) + (i32.const 65535) + ) (i32.const 0) ) ) @@ -905,12 +905,9 @@ (get_local $6) ) (set_local $6 - (i32.and - (i32.sub - (get_local $8) - (i32.const 1) - ) - (i32.const 65535) + (i32.sub + (get_local $8) + (i32.const 1) ) ) (get_local $8) @@ -919,7 +916,10 @@ (if (i32.eqz (i32.eq - (get_local $6) + (i32.and + (get_local $6) + (i32.const 65535) + ) (i32.const 65535) ) ) @@ -939,12 +939,9 @@ (get_local $6) ) (set_local $6 - (i32.and - (i32.add - (get_local $8) - (i32.const 1) - ) - (i32.const 65535) + (i32.add + (get_local $8) + (i32.const 1) ) ) (get_local $8) @@ -953,7 +950,10 @@ (if (i32.eqz (i32.eq - (get_local $6) + (i32.and + (get_local $6) + (i32.const 65535) + ) (i32.const 0) ) ) @@ -968,18 +968,18 @@ ) ) (set_local $6 - (i32.and - (i32.sub - (get_local $6) - (i32.const 1) - ) - (i32.const 65535) + (i32.sub + (get_local $6) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $6) + (i32.and + (get_local $6) + (i32.const 65535) + ) (i32.const 65535) ) ) @@ -994,18 +994,18 @@ ) ) (set_local $6 - (i32.and - (i32.add - (get_local $6) - (i32.const 1) - ) - (i32.const 65535) + (i32.add + (get_local $6) + (i32.const 1) ) ) (if (i32.eqz (i32.eq - (get_local $6) + (i32.and + (get_local $6) + (i32.const 65535) + ) (i32.const 0) ) ) @@ -1021,19 +1021,19 @@ ) (set_local $7 (tee_local $6 - (i32.and - (i32.sub - (get_local $6) - (i32.const 1) - ) - (i32.const 65535) + (i32.sub + (get_local $6) + (i32.const 1) ) ) ) (if (i32.eqz (i32.eq - (get_local $6) + (i32.and + (get_local $6) + (i32.const 65535) + ) (i32.const 65535) ) ) @@ -1049,19 +1049,19 @@ ) (set_local $7 (tee_local $6 - (i32.and - (i32.add - (get_local $6) - (i32.const 1) - ) - (i32.const 65535) + (i32.add + (get_local $6) + (i32.const 1) ) ) ) (if (i32.eqz (i32.eq - (get_local $6) + (i32.and + (get_local $6) + (i32.const 65535) + ) (i32.const 0) ) ) diff --git a/tests/compiler/portable-conversions.untouched.wat b/tests/compiler/portable-conversions.untouched.wat index 2dac0ce4..2a12cabc 100644 --- a/tests/compiler/portable-conversions.untouched.wat +++ b/tests/compiler/portable-conversions.untouched.wat @@ -10,87 +10,39 @@ (start $start) (func $start (; 0 ;) (type $v) (drop - (i32.shr_s - (i32.shl - (get_global $portable-conversions/i) - (i32.const 24) - ) - (i32.const 24) + (get_global $portable-conversions/i) + ) + (drop + (i32.wrap/i64 + (get_global $portable-conversions/I) ) ) (drop - (i32.shr_s - (i32.shl - (i32.wrap/i64 - (get_global $portable-conversions/I) - ) - (i32.const 24) - ) - (i32.const 24) + (i32.trunc_s/f32 + (get_global $portable-conversions/f) ) ) (drop - (i32.shr_s - (i32.shl - (i32.trunc_s/f32 - (get_global $portable-conversions/f) - ) - (i32.const 24) - ) - (i32.const 24) + (i32.trunc_s/f64 + (get_global $portable-conversions/F) ) ) (drop - (i32.shr_s - (i32.shl - (i32.trunc_s/f64 - (get_global $portable-conversions/F) - ) - (i32.const 24) - ) - (i32.const 24) + (get_global $portable-conversions/i) + ) + (drop + (i32.wrap/i64 + (get_global $portable-conversions/I) ) ) (drop - (i32.shr_s - (i32.shl - (get_global $portable-conversions/i) - (i32.const 16) - ) - (i32.const 16) + (i32.trunc_s/f32 + (get_global $portable-conversions/f) ) ) (drop - (i32.shr_s - (i32.shl - (i32.wrap/i64 - (get_global $portable-conversions/I) - ) - (i32.const 16) - ) - (i32.const 16) - ) - ) - (drop - (i32.shr_s - (i32.shl - (i32.trunc_s/f32 - (get_global $portable-conversions/f) - ) - (i32.const 16) - ) - (i32.const 16) - ) - ) - (drop - (i32.shr_s - (i32.shl - (i32.trunc_s/f64 - (get_global $portable-conversions/F) - ) - (i32.const 16) - ) - (i32.const 16) + (i32.trunc_s/f64 + (get_global $portable-conversions/F) ) ) (drop @@ -148,63 +100,39 @@ ) ) (drop - (i32.and - (get_global $portable-conversions/i) - (i32.const 255) + (get_global $portable-conversions/i) + ) + (drop + (i32.wrap/i64 + (get_global $portable-conversions/I) ) ) (drop - (i32.and - (i32.wrap/i64 - (get_global $portable-conversions/I) - ) - (i32.const 255) + (i32.trunc_u/f32 + (get_global $portable-conversions/f) ) ) (drop - (i32.and - (i32.trunc_u/f32 - (get_global $portable-conversions/f) - ) - (i32.const 255) + (i32.trunc_u/f64 + (get_global $portable-conversions/F) ) ) (drop - (i32.and - (i32.trunc_u/f64 - (get_global $portable-conversions/F) - ) - (i32.const 255) + (get_global $portable-conversions/i) + ) + (drop + (i32.wrap/i64 + (get_global $portable-conversions/I) ) ) (drop - (i32.and - (get_global $portable-conversions/i) - (i32.const 65535) + (i32.trunc_u/f32 + (get_global $portable-conversions/f) ) ) (drop - (i32.and - (i32.wrap/i64 - (get_global $portable-conversions/I) - ) - (i32.const 65535) - ) - ) - (drop - (i32.and - (i32.trunc_u/f32 - (get_global $portable-conversions/f) - ) - (i32.const 65535) - ) - ) - (drop - (i32.and - (i32.trunc_u/f64 - (get_global $portable-conversions/F) - ) - (i32.const 65535) + (i32.trunc_u/f64 + (get_global $portable-conversions/F) ) ) (drop @@ -262,33 +190,21 @@ ) ) (drop - (i32.and - (get_global $portable-conversions/i) - (i32.const 1) + (get_global $portable-conversions/i) + ) + (drop + (i32.wrap/i64 + (get_global $portable-conversions/I) ) ) (drop - (i32.and - (i32.wrap/i64 - (get_global $portable-conversions/I) - ) - (i32.const 1) + (i32.trunc_u/f32 + (get_global $portable-conversions/f) ) ) (drop - (i32.and - (i32.trunc_u/f32 - (get_global $portable-conversions/f) - ) - (i32.const 1) - ) - ) - (drop - (i32.and - (i32.trunc_u/f64 - (get_global $portable-conversions/F) - ) - (i32.const 1) + (i32.trunc_u/f64 + (get_global $portable-conversions/F) ) ) (drop diff --git a/tests/compiler/retain-i32.optimized.wat b/tests/compiler/retain-i32.optimized.wat index b808ae51..38b59e90 100644 --- a/tests/compiler/retain-i32.optimized.wat +++ b/tests/compiler/retain-i32.optimized.wat @@ -10,501 +10,7 @@ (export "memory" (memory $0)) (start $start) (func $retain-i32/test (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32) - (if - (i32.ne - (i32.and - (i32.add - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.add - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 4) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.sub - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.sub - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 5) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.mul - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.mul - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 6) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.and - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.and - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 7) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.or - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.or - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 8) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.xor - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.xor - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 9) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.shl - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.shl - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 10) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.add - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.add - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 13) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.sub - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.sub - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 14) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.mul - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.mul - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 15) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.and - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 16) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.or - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.or - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 17) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.xor - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.xor - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 18) - (i32.const 2) - ) - (unreachable) - ) - ) - (if - (i32.ne - (i32.and - (i32.shl - (get_local $0) - (get_local $1) - ) - (i32.const 255) - ) - (i32.and - (i32.shl - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - (i32.const 255) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 19) - (i32.const 2) - ) - (unreachable) - ) - ) + (nop) ) (func $start (; 2 ;) (type $v) (local $0 i32) diff --git a/tests/compiler/retain-i32.untouched.wat b/tests/compiler/retain-i32.untouched.wat index c15f0ce6..d55eabc3 100644 --- a/tests/compiler/retain-i32.untouched.wat +++ b/tests/compiler/retain-i32.untouched.wat @@ -27,20 +27,8 @@ (i32.shr_s (i32.shl (i32.add - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) + (get_local $0) + (get_local $1) ) (i32.const 24) ) @@ -74,20 +62,8 @@ (i32.shr_s (i32.shl (i32.sub - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) + (get_local $0) + (get_local $1) ) (i32.const 24) ) @@ -121,20 +97,8 @@ (i32.shr_s (i32.shl (i32.mul - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) + (get_local $0) + (get_local $1) ) (i32.const 24) ) @@ -168,20 +132,8 @@ (i32.shr_s (i32.shl (i32.and - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) + (get_local $0) + (get_local $1) ) (i32.const 24) ) @@ -215,20 +167,8 @@ (i32.shr_s (i32.shl (i32.or - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) + (get_local $0) + (get_local $1) ) (i32.const 24) ) @@ -262,20 +202,8 @@ (i32.shr_s (i32.shl (i32.xor - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) + (get_local $0) + (get_local $1) ) (i32.const 24) ) @@ -309,20 +237,8 @@ (i32.shr_s (i32.shl (i32.shl - (i32.shr_s - (i32.shl - (get_local $0) - (i32.const 24) - ) - (i32.const 24) - ) - (i32.shr_s - (i32.shl - (get_local $1) - (i32.const 24) - ) - (i32.const 24) - ) + (get_local $0) + (get_local $1) ) (i32.const 24) ) @@ -352,14 +268,8 @@ ) (i32.and (i32.add - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) + (get_local $0) + (get_local $1) ) (i32.const 255) ) @@ -387,14 +297,8 @@ ) (i32.and (i32.sub - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) + (get_local $0) + (get_local $1) ) (i32.const 255) ) @@ -422,14 +326,8 @@ ) (i32.and (i32.mul - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) + (get_local $0) + (get_local $1) ) (i32.const 255) ) @@ -457,14 +355,8 @@ ) (i32.and (i32.and - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) + (get_local $0) + (get_local $1) ) (i32.const 255) ) @@ -492,14 +384,8 @@ ) (i32.and (i32.or - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) + (get_local $0) + (get_local $1) ) (i32.const 255) ) @@ -527,14 +413,8 @@ ) (i32.and (i32.xor - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) + (get_local $0) + (get_local $1) ) (i32.const 255) ) @@ -562,14 +442,8 @@ ) (i32.and (i32.shl - (i32.and - (get_local $0) - (i32.const 255) - ) - (i32.and - (get_local $1) - (i32.const 255) - ) + (get_local $0) + (get_local $1) ) (i32.const 255) ) @@ -1164,11 +1038,8 @@ ) ) (set_global $retain-i32/ui - (i32.and - (i32.div_u - (i32.const 255) - (i32.const 255) - ) + (i32.div_u + (i32.const 255) (i32.const 255) ) ) diff --git a/tests/compiler/showcase.optimized.wat b/tests/compiler/showcase.optimized.wat index 09a5692c..f4f4e2dd 100644 --- a/tests/compiler/showcase.optimized.wat +++ b/tests/compiler/showcase.optimized.wat @@ -253,63 +253,51 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.gt_s - (get_local $6) - (i32.const 2146435072) - ) - ) - (get_local $5) - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $6) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $7) - (i32.const 0) - ) - (get_local $5) - ) - ) - (i32.const 1) - ) - ) - (get_local $5) - (i32.gt_s - (get_local $10) - (i32.const 2146435072) - ) - ) - (i32.const 1) - ) - ) - (get_local $5) (if (result i32) (tee_local $5 - (i32.eq - (get_local $10) + (i32.gt_s + (get_local $6) (i32.const 2146435072) ) ) - (i32.ne - (get_local $4) - (i32.const 0) - ) (get_local $5) + (tee_local $5 + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $6) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $7) + (i32.const 0) + ) + (get_local $5) + ) + ) + ) + (get_local $5) + (tee_local $5 + (i32.gt_s + (get_local $10) + (i32.const 2146435072) + ) ) ) - (i32.const 1) + (get_local $5) + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $10) + (i32.const 2146435072) + ) + ) + (get_local $4) + (get_local $5) + ) ) (return (f64.add @@ -531,32 +519,26 @@ (get_local $7) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $6) - (i32.const 2146435072) - ) - ) - (get_local $5) - (i32.eqz - (get_local $6) - ) - ) - (i32.const 1) + (i32.eq + (get_local $6) + (i32.const 2146435072) ) ) (get_local $5) - (i32.eq - (get_local $6) - (i32.const 1072693248) + (tee_local $5 + (i32.eqz + (get_local $6) + ) ) ) - (i32.const 1) + (get_local $5) + (i32.eq + (get_local $6) + (i32.const 1072693248) + ) ) (block (if @@ -1617,34 +1599,28 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $3 - (i32.and - (if (result i32) - (tee_local $3 - (i32.eqz - (i32.shl - (get_local $5) - (i32.const 1) - ) - ) - ) - (get_local $3) - (call $isNaN - (get_local $1) - ) + (i32.eqz + (i32.shl + (get_local $5) + (i32.const 1) ) - (i32.const 1) ) ) (get_local $3) - (i32.eq - (get_local $4) - (i32.const 255) + (tee_local $3 + (call $isNaN + (get_local $1) + ) ) ) - (i32.const 1) + (get_local $3) + (i32.eq + (get_local $4) + (i32.const 255) + ) ) (return (f32.div @@ -2048,21 +2024,22 @@ (local $4 i32) (local $5 i32) (local $6 i32) - (local $7 i32) - (local $8 f32) + (local $7 f32) + (local $8 i32) (local $9 f32) (local $10 i32) (local $11 i32) (local $12 f32) - (local $13 f32) + (local $13 i32) (local $14 f32) - (local $15 i32) - (local $16 f32) + (local $15 f32) + (local $16 i32) + (local $17 f32) (block $folding-inner1 (block $folding-inner0 (set_local $5 (i32.and - (tee_local $15 + (tee_local $4 (i32.reinterpret/f32 (get_local $0) ) @@ -2088,21 +2065,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.gt_s - (get_local $5) - (i32.const 2139095040) - ) - ) - (get_local $6) + (if (result i32) + (tee_local $13 (i32.gt_s - (get_local $10) + (get_local $5) (i32.const 2139095040) ) ) - (i32.const 1) + (get_local $13) + (i32.gt_s + (get_local $10) + (i32.const 2139095040) + ) ) (return (f32.add @@ -2113,7 +2087,7 @@ ) (if (i32.lt_s - (get_local $15) + (get_local $4) (i32.const 0) ) (if @@ -2121,7 +2095,7 @@ (get_local $10) (i32.const 1266679808) ) - (set_local $4 + (set_local $16 (i32.const 2) ) (if @@ -2132,12 +2106,12 @@ (if (i32.eq (i32.shl - (tee_local $7 + (tee_local $6 (i32.shr_s (get_local $10) (i32.sub (i32.const 23) - (tee_local $6 + (tee_local $8 (i32.sub (i32.shr_s (get_local $10) @@ -2151,16 +2125,16 @@ ) (i32.sub (i32.const 23) - (get_local $6) + (get_local $8) ) ) (get_local $10) ) - (set_local $4 + (set_local $16 (i32.sub (i32.const 2) (i32.and - (get_local $7) + (get_local $6) (i32.const 1) ) ) @@ -2250,7 +2224,7 @@ ) (if (i32.ge_s - (get_local $15) + (get_local $4) (i32.const 0) ) (return @@ -2266,32 +2240,26 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) - (tee_local $6 - (i32.and - (if (result i32) - (tee_local $6 - (i32.eq - (get_local $5) - (i32.const 2139095040) - ) - ) - (get_local $6) - (i32.eqz - (get_local $5) - ) - ) - (i32.const 1) + (tee_local $13 + (i32.eq + (get_local $5) + (i32.const 2139095040) ) ) - (get_local $6) - (i32.eq - (get_local $5) - (i32.const 1065353216) + (get_local $13) + (tee_local $13 + (i32.eqz + (get_local $5) + ) ) ) - (i32.const 1) + (get_local $13) + (i32.eq + (get_local $5) + (i32.const 1065353216) + ) ) (block (if @@ -2308,7 +2276,7 @@ ) (if (i32.lt_s - (get_local $15) + (get_local $4) (i32.const 0) ) (if @@ -2317,11 +2285,11 @@ (get_local $5) (i32.const 1065353216) ) - (get_local $4) + (get_local $16) ) (if (i32.eq - (get_local $4) + (get_local $16) (i32.const 1) ) (set_local $2 @@ -2354,13 +2322,13 @@ ) (if (i32.lt_s - (get_local $15) + (get_local $4) (i32.const 0) ) (block (if (i32.eqz - (get_local $4) + (get_local $16) ) (return (f32.div @@ -2377,7 +2345,7 @@ ) (if (i32.eq - (get_local $4) + (get_local $16) (i32.const 1) ) (set_local $9 @@ -2475,18 +2443,18 @@ ) ) ) - (set_local $8 + (set_local $7 (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 (f32.add - (tee_local $13 + (tee_local $14 (f32.mul (f32.const 1.44268798828125) (get_local $3) ) ) - (tee_local $14 + (tee_local $15 (f32.sub (f32.mul (get_local $3) @@ -2505,10 +2473,10 @@ ) ) (f32.sub - (get_local $14) + (get_local $15) (f32.sub - (get_local $8) - (get_local $13) + (get_local $7) + (get_local $14) ) ) ) @@ -2552,7 +2520,7 @@ ) (set_local $5 (i32.or - (tee_local $7 + (tee_local $6 (i32.and (get_local $5) (i32.const 8388607) @@ -2561,16 +2529,16 @@ (i32.const 1065353216) ) ) - (set_local $6 + (set_local $8 (if (result i32) (i32.le_s - (get_local $7) + (get_local $6) (i32.const 1885297) ) (i32.const 0) (if (result i32) (i32.lt_s - (get_local $7) + (get_local $6) (i32.const 6140887) ) (i32.const 1) @@ -2596,9 +2564,9 @@ (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 - (tee_local $16 + (tee_local $17 (f32.mul - (tee_local $13 + (tee_local $14 (f32.sub (tee_local $2 (f32.reinterpret/i32 @@ -2609,12 +2577,12 @@ (select (f32.const 1.5) (f32.const 1) - (get_local $6) + (get_local $8) ) ) ) ) - (tee_local $14 + (tee_local $15 (f32.div (f32.const 1) (f32.add @@ -2634,7 +2602,7 @@ (f32.sub (get_local $2) (f32.sub - (tee_local $8 + (tee_local $7 (f32.reinterpret/i32 (i32.add (i32.add @@ -2651,7 +2619,7 @@ (i32.const 4194304) ) (i32.shl - (get_local $6) + (get_local $8) (i32.const 21) ) ) @@ -2669,8 +2637,8 @@ (f32.mul (tee_local $12 (f32.mul - (get_local $16) - (get_local $16) + (get_local $17) + (get_local $17) ) ) (get_local $12) @@ -2710,13 +2678,13 @@ (f32.mul (tee_local $0 (f32.mul - (get_local $14) + (get_local $15) (f32.sub (f32.sub - (get_local $13) + (get_local $14) (f32.mul (get_local $3) - (get_local $8) + (get_local $7) ) ) (f32.mul @@ -2728,14 +2696,14 @@ ) (f32.add (get_local $3) - (get_local $16) + (get_local $17) ) ) ) ) (f32.sub (f32.sub - (tee_local $8 + (tee_local $7 (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 @@ -2762,14 +2730,14 @@ ) ) ) - (set_local $8 + (set_local $7 (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 (f32.add (f32.add (f32.add - (tee_local $16 + (tee_local $17 (f32.mul (f32.const 0.9619140625) (tee_local $0 @@ -2777,21 +2745,21 @@ (i32.and (i32.reinterpret/f32 (f32.add - (tee_local $13 + (tee_local $14 (f32.mul (get_local $3) - (get_local $8) + (get_local $7) ) ) - (tee_local $14 + (tee_local $15 (f32.add (f32.mul (get_local $0) - (get_local $8) + (get_local $7) ) (f32.mul (get_local $2) - (get_local $16) + (get_local $17) ) ) ) @@ -2812,10 +2780,10 @@ ) (f32.mul (f32.sub - (get_local $14) + (get_local $15) (f32.sub (get_local $0) - (get_local $13) + (get_local $14) ) ) (f32.const 0.9617967009544373) @@ -2824,7 +2792,7 @@ (select (f32.const 1.5632208487659227e-06) (f32.const 0) - (get_local $6) + (get_local $8) ) ) ) @@ -2833,7 +2801,7 @@ (select (f32.const 0.5849609375) (f32.const 0) - (get_local $6) + (get_local $8) ) ) ) @@ -2853,12 +2821,12 @@ (f32.sub (f32.sub (f32.sub - (get_local $8) + (get_local $7) (get_local $3) ) (get_local $0) ) - (get_local $16) + (get_local $17) ) ) ) @@ -2866,7 +2834,7 @@ ) (br_if $folding-inner1 (i32.gt_s - (tee_local $7 + (tee_local $6 (i32.reinterpret/f32 (tee_local $2 (f32.add @@ -2886,7 +2854,7 @@ ) ) ) - (get_local $8) + (get_local $7) ) (f32.mul (get_local $1) @@ -2897,7 +2865,7 @@ (tee_local $0 (f32.mul (get_local $0) - (get_local $8) + (get_local $7) ) ) ) @@ -2909,7 +2877,7 @@ ) (if (i32.eq - (get_local $7) + (get_local $6) (i32.const 1124073472) ) (br_if $folding-inner1 @@ -2927,7 +2895,7 @@ (if (i32.gt_s (i32.and - (get_local $7) + (get_local $6) (i32.const 2147483647) ) (i32.const 1125515264) @@ -2935,7 +2903,7 @@ (br $folding-inner0) (if (i32.eq - (get_local $7) + (get_local $6) (i32.const -1021968384) ) (br_if $folding-inner0 @@ -2950,12 +2918,12 @@ ) ) ) - (set_local $6 + (set_local $8 (i32.sub (i32.shr_s - (tee_local $15 + (tee_local $13 (i32.and - (get_local $7) + (get_local $6) (i32.const 2147483647) ) ) @@ -2969,21 +2937,21 @@ ) (if (i32.gt_s - (get_local $15) + (get_local $13) (i32.const 1056964608) ) (block - (set_local $6 + (set_local $8 (i32.sub (i32.shr_s (i32.and (tee_local $4 (i32.add - (get_local $7) + (get_local $6) (i32.shr_s (i32.const 8388608) (i32.add - (get_local $6) + (get_local $8) (i32.const 1) ) ) @@ -3003,7 +2971,7 @@ (i32.xor (i32.shr_s (i32.const 8388607) - (get_local $6) + (get_local $8) ) (i32.const -1) ) @@ -3021,13 +2989,13 @@ ) (i32.sub (i32.const 23) - (get_local $6) + (get_local $8) ) ) ) (if (i32.lt_s - (get_local $7) + (get_local $6) (i32.const 0) ) (set_local $4 @@ -3052,7 +3020,7 @@ (if (result f32) (i32.le_s (i32.shr_s - (tee_local $7 + (tee_local $6 (i32.add (i32.reinterpret/f32 (tee_local $2 @@ -3064,7 +3032,7 @@ (f32.mul (tee_local $2 (f32.add - (tee_local $13 + (tee_local $14 (f32.mul (tee_local $3 (f32.reinterpret/i32 @@ -3082,7 +3050,7 @@ (f32.const 0.693145751953125) ) ) - (tee_local $14 + (tee_local $15 (f32.add (f32.mul (f32.sub @@ -3102,7 +3070,7 @@ ) ) ) - (tee_local $8 + (tee_local $7 (f32.sub (get_local $2) (f32.mul @@ -3142,17 +3110,17 @@ ) ) (f32.sub - (get_local $8) + (get_local $7) (f32.const 2) ) ) (f32.add (tee_local $0 (f32.sub - (get_local $14) + (get_local $15) (f32.sub (get_local $2) - (get_local $13) + (get_local $14) ) ) ) @@ -3182,7 +3150,7 @@ (get_local $4) ) (f32.reinterpret/i32 - (get_local $7) + (get_local $6) ) ) ) @@ -3252,35 +3220,29 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i64.eq - (i64.shl - (get_local $5) - (i64.const 1) - ) - (i64.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) - ) + (i64.eq + (i64.shl + (get_local $5) + (i64.const 1) ) - (i32.const 1) + (i64.const 0) ) ) (get_local $7) - (i32.eq - (get_local $3) - (i32.const 2047) + (tee_local $7 + (call $isNaN + (get_local $1) + ) ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $3) + (i32.const 2047) + ) ) (return (f64.div diff --git a/tests/compiler/showcase.untouched.wat b/tests/compiler/showcase.untouched.wat index 5a01980a..a24e66a7 100644 --- a/tests/compiler/showcase.untouched.wat +++ b/tests/compiler/showcase.untouched.wat @@ -298,63 +298,54 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $9 - (i32.and + (if (result i32) + (tee_local $9 + (if (result i32) + (tee_local $9 (if (result i32) (tee_local $9 - (i32.and - (if (result i32) - (tee_local $9 - (i32.gt_s - (get_local $7) - (i32.const 2146435072) - ) - ) - (get_local $9) - (if (result i32) - (tee_local $9 - (i32.eq - (get_local $7) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $4) - (i32.const 0) - ) - (get_local $9) - ) - ) - (i32.const 1) + (i32.gt_s + (get_local $7) + (i32.const 2146435072) ) ) (get_local $9) - (i32.gt_s - (get_local $8) - (i32.const 2146435072) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $7) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $4) + (i32.const 0) + ) + (get_local $9) ) ) - (i32.const 1) - ) - ) - (get_local $9) - (if (result i32) - (tee_local $9 - (i32.eq - (get_local $8) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $6) - (i32.const 0) ) (get_local $9) + (i32.gt_s + (get_local $8) + (i32.const 2146435072) + ) ) ) - (i32.const 1) + (get_local $9) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $8) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $6) + (i32.const 0) + ) + (get_local $9) + ) ) (return (f64.add @@ -594,33 +585,27 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $15 - (i32.and - (if (result i32) - (tee_local $15 - (i32.eq - (get_local $7) - (i32.const 2146435072) - ) - ) - (get_local $15) - (i32.eq - (get_local $7) - (i32.const 0) - ) + (if (result i32) + (tee_local $15 + (if (result i32) + (tee_local $15 + (i32.eq + (get_local $7) + (i32.const 2146435072) ) - (i32.const 1) + ) + (get_local $15) + (i32.eq + (get_local $7) + (i32.const 0) ) ) - (get_local $15) - (i32.eq - (get_local $7) - (i32.const 1072693248) - ) ) - (i32.const 1) + (get_local $15) + (i32.eq + (get_local $7) + (i32.const 1072693248) + ) ) (block (set_local $14 @@ -1828,35 +1813,29 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i32.eq - (i32.shl - (get_local $3) - (i32.const 1) - ) - (i32.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) + (if (result i32) + (tee_local $7 + (if (result i32) + (tee_local $7 + (i32.eq + (i32.shl + (get_local $3) + (i32.const 1) ) + (i32.const 0) ) - (i32.const 1) + ) + (get_local $7) + (call $isNaN + (get_local $1) ) ) - (get_local $7) - (i32.eq - (get_local $4) - (i32.const 255) - ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $4) + (i32.const 255) + ) ) (return (f32.div @@ -2405,21 +2384,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.gt_s - (get_local $4) - (i32.const 2139095040) - ) - ) - (get_local $6) + (if (result i32) + (tee_local $6 (i32.gt_s - (get_local $5) + (get_local $4) (i32.const 2139095040) ) ) - (i32.const 1) + (get_local $6) + (i32.gt_s + (get_local $5) + (i32.const 2139095040) + ) ) (return (f32.add @@ -2591,33 +2567,27 @@ ) (nop) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.and - (if (result i32) - (tee_local $6 - (i32.eq - (get_local $4) - (i32.const 2139095040) - ) - ) - (get_local $6) - (i32.eq - (get_local $4) - (i32.const 0) - ) + (if (result i32) + (tee_local $6 + (if (result i32) + (tee_local $6 + (i32.eq + (get_local $4) + (i32.const 2139095040) ) - (i32.const 1) + ) + (get_local $6) + (i32.eq + (get_local $4) + (i32.const 0) ) ) - (get_local $6) - (i32.eq - (get_local $4) - (i32.const 1065353216) - ) ) - (i32.const 1) + (get_local $6) + (i32.eq + (get_local $4) + (i32.const 1065353216) + ) ) (block (set_local $11 @@ -3724,35 +3694,29 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i64.eq - (i64.shl - (get_local $3) - (i64.const 1) - ) - (i64.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) + (if (result i32) + (tee_local $7 + (if (result i32) + (tee_local $7 + (i64.eq + (i64.shl + (get_local $3) + (i64.const 1) ) + (i64.const 0) ) - (i32.const 1) + ) + (get_local $7) + (call $isNaN + (get_local $1) ) ) - (get_local $7) - (i32.eq - (get_local $4) - (i32.const 2047) - ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $4) + (i32.const 2047) + ) ) (return (f64.div diff --git a/tests/compiler/std/allocator_arena.optimized.wat b/tests/compiler/std/allocator_arena.optimized.wat index 3005732e..8b34f319 100644 --- a/tests/compiler/std/allocator_arena.optimized.wat +++ b/tests/compiler/std/allocator_arena.optimized.wat @@ -217,7 +217,10 @@ ) (tee_local $1 (i32.mul - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) (i32.const 16843009) ) ) @@ -2024,27 +2027,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory diff --git a/tests/compiler/std/allocator_arena.untouched.wat b/tests/compiler/std/allocator_arena.untouched.wat index 5f3af60f..41c8d90c 100644 --- a/tests/compiler/std/allocator_arena.untouched.wat +++ b/tests/compiler/std/allocator_arena.untouched.wat @@ -261,7 +261,10 @@ (i32.const -1) (i32.const 255) ) - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) ) ) (i32.store @@ -2294,27 +2297,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory diff --git a/tests/compiler/std/array-literal.optimized.wat b/tests/compiler/std/array-literal.optimized.wat index ce2b8d8a..e6354c99 100644 --- a/tests/compiler/std/array-literal.optimized.wat +++ b/tests/compiler/std/array-literal.optimized.wat @@ -296,7 +296,10 @@ ) (tee_local $1 (i32.mul - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) (i32.const 16843009) ) ) diff --git a/tests/compiler/std/array-literal.untouched.wat b/tests/compiler/std/array-literal.untouched.wat index bdcb697b..bfd8958b 100644 --- a/tests/compiler/std/array-literal.untouched.wat +++ b/tests/compiler/std/array-literal.untouched.wat @@ -360,7 +360,10 @@ (i32.const -1) (i32.const 255) ) - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) ) ) (i32.store diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 8cd8bd8f..9a463d95 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -318,7 +318,10 @@ ) (tee_local $1 (i32.mul - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) (i32.const 16843009) ) ) @@ -2223,27 +2226,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory @@ -3024,24 +3024,21 @@ (local $3 i32) (local $4 i32) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eqz - (tee_local $3 - (i32.load offset=4 - (get_local $0) - ) + (if (result i32) + (tee_local $4 + (i32.eqz + (tee_local $3 + (i32.load offset=4 + (get_local $0) ) ) ) - (get_local $4) - (i32.ge_s - (get_local $2) - (get_local $3) - ) ) - (i32.const 1) + (get_local $4) + (i32.ge_s + (get_local $2) + (get_local $3) + ) ) (return (i32.const -1) @@ -3138,24 +3135,21 @@ (local $3 i32) (local $4 i32) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eqz - (tee_local $3 - (i32.load offset=4 - (get_local $0) - ) + (if (result i32) + (tee_local $4 + (i32.eqz + (tee_local $3 + (i32.load offset=4 + (get_local $0) ) ) ) - (get_local $4) - (i32.ge_s - (get_local $2) - (get_local $3) - ) ) - (i32.const 1) + (get_local $4) + (i32.ge_s + (get_local $2) + (get_local $3) + ) ) (return (i32.const 0) @@ -3439,23 +3433,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_s - (get_local $2) - (get_local $4) - ) - ) + (if (result i32) + (tee_local $5 (i32.lt_s (get_local $2) - (i32.load offset=4 - (get_local $0) - ) + (get_local $4) ) - (get_local $5) ) - (i32.const 1) + (i32.lt_s + (get_local $2) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $5) ) (block (if @@ -3463,19 +3454,22 @@ (set_global $~argc (i32.const 3) ) - (call_indirect (type $iiii) - (i32.load offset=8 - (i32.add - (get_local $3) - (i32.shl - (get_local $2) - (i32.const 2) + (i32.and + (call_indirect (type $iiii) + (i32.load offset=8 + (i32.add + (get_local $3) + (i32.shl + (get_local $2) + (i32.const 2) + ) ) ) + (get_local $2) + (get_local $0) + (get_local $1) ) - (get_local $2) - (get_local $0) - (get_local $1) + (i32.const 1) ) ) (return @@ -3552,23 +3546,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_s - (get_local $2) - (get_local $4) - ) - ) + (if (result i32) + (tee_local $5 (i32.lt_s (get_local $2) - (i32.load offset=4 - (get_local $0) - ) + (get_local $4) ) - (get_local $5) ) - (i32.const 1) + (i32.lt_s + (get_local $2) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $5) ) (block (if @@ -3577,19 +3568,22 @@ (i32.const 3) ) (i32.eqz - (call_indirect (type $iiii) - (i32.load offset=8 - (i32.add - (get_local $3) - (i32.shl - (get_local $2) - (i32.const 2) + (i32.and + (call_indirect (type $iiii) + (i32.load offset=8 + (i32.add + (get_local $3) + (i32.shl + (get_local $2) + (i32.const 2) + ) ) ) + (get_local $2) + (get_local $0) + (get_local $1) ) - (get_local $2) - (get_local $0) - (get_local $1) + (i32.const 1) ) ) ) @@ -3667,23 +3661,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_s - (get_local $2) - (get_local $4) - ) - ) + (if (result i32) + (tee_local $5 (i32.lt_s (get_local $2) - (i32.load offset=4 - (get_local $0) - ) + (get_local $4) ) - (get_local $5) ) - (i32.const 1) + (i32.lt_s + (get_local $2) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $5) ) (block (if @@ -3691,19 +3682,22 @@ (set_global $~argc (i32.const 3) ) - (call_indirect (type $iiii) - (i32.load offset=8 - (i32.add - (get_local $3) - (i32.shl - (get_local $2) - (i32.const 2) + (i32.and + (call_indirect (type $iiii) + (i32.load offset=8 + (i32.add + (get_local $3) + (i32.shl + (get_local $2) + (i32.const 2) + ) ) ) + (get_local $2) + (get_local $0) + (get_local $1) ) - (get_local $2) - (get_local $0) - (get_local $1) + (i32.const 1) ) ) (return @@ -3782,23 +3776,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_s - (get_local $2) - (get_local $4) - ) - ) + (if (result i32) + (tee_local $5 (i32.lt_s (get_local $2) - (i32.load offset=4 - (get_local $0) - ) + (get_local $4) ) - (get_local $5) ) - (i32.const 1) + (i32.lt_s + (get_local $2) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $5) ) (block (set_global $~argc @@ -3889,23 +3880,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.lt_s - (get_local $2) - (get_local $4) - ) - ) + (if (result i32) + (tee_local $7 (i32.lt_s (get_local $2) - (i32.load offset=4 - (get_local $0) - ) + (get_local $4) ) - (get_local $7) ) - (i32.const 1) + (i32.lt_s + (get_local $2) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $7) ) (block (set_global $~argc @@ -4017,23 +4005,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.lt_s - (get_local $2) - (get_local $4) - ) - ) + (if (result i32) + (tee_local $7 (i32.lt_s (get_local $2) - (i32.load offset=4 - (get_local $0) - ) + (get_local $4) ) - (get_local $7) ) - (i32.const 1) + (i32.lt_s + (get_local $2) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $7) ) (block (set_global $~argc @@ -4130,23 +4115,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.lt_s - (get_local $2) - (get_local $6) - ) - ) + (if (result i32) + (tee_local $3 (i32.lt_s (get_local $2) - (i32.load offset=4 - (get_local $0) - ) + (get_local $6) ) - (get_local $3) ) - (i32.const 1) + (i32.lt_s + (get_local $2) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $3) ) (block (set_local $3 @@ -4165,11 +4147,14 @@ (set_global $~argc (i32.const 3) ) - (call_indirect (type $iiii) - (get_local $3) - (get_local $2) - (get_local $0) - (get_local $1) + (i32.and + (call_indirect (type $iiii) + (get_local $3) + (get_local $2) + (get_local $0) + (get_local $1) + ) + (i32.const 1) ) ) (drop @@ -4261,23 +4246,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.lt_s - (get_local $3) - (get_local $5) - ) - ) + (if (result i32) + (tee_local $6 (i32.lt_s (get_local $3) - (i32.load offset=4 - (get_local $0) - ) + (get_local $5) ) - (get_local $6) ) - (i32.const 1) + (i32.lt_s + (get_local $3) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $6) ) (block (set_global $~argc @@ -4313,29 +4295,29 @@ (get_local $2) ) (func $start~anonymous|30 (; 61 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - (i32.and - (select - (get_local $0) - (i32.gt_s - (get_local $1) - (i32.const 2) - ) - (get_local $0) + (select + (get_local $0) + (i32.gt_s + (get_local $1) + (i32.const 2) + ) + (i32.and + (get_local $0) + (i32.const 1) ) - (i32.const 1) ) ) (func $start~anonymous|31 (; 62 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - (i32.and - (select - (get_local $0) - (i32.gt_s - (get_local $1) - (i32.const 100) - ) - (get_local $0) + (select + (get_local $0) + (i32.gt_s + (get_local $1) + (i32.const 100) + ) + (i32.and + (get_local $0) + (i32.const 1) ) - (i32.const 1) ) ) (func $start~anonymous|32 (; 63 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) @@ -5773,31 +5755,25 @@ (local $2 i32) (local $3 i32) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $2 - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (get_local $1) - ) - ) - (get_local $2) - (i32.eqz - (get_local $0) - ) - ) - (i32.const 1) + (i32.eq + (get_local $0) + (get_local $1) ) ) (get_local $2) - (i32.eqz - (get_local $1) + (tee_local $2 + (i32.eqz + (get_local $0) + ) ) ) - (i32.const 1) + (get_local $2) + (i32.eqz + (get_local $1) + ) ) (return (i32.const 0) @@ -5857,31 +5833,25 @@ (local $2 i32) (local $3 i32) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $2 - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (get_local $1) - ) - ) - (get_local $2) - (i32.eqz - (get_local $0) - ) - ) - (i32.const 1) + (i32.eq + (get_local $0) + (get_local $1) ) ) (get_local $2) - (i32.eqz - (get_local $1) + (tee_local $2 + (i32.eqz + (get_local $0) + ) ) ) - (i32.const 1) + (get_local $2) + (i32.eqz + (get_local $1) + ) ) (return (i32.const 0) @@ -5961,19 +5931,16 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eqz - (get_local $0) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (i32.eqz - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $2) + (i32.eqz + (get_local $1) + ) ) (return (i32.const 0) @@ -6107,21 +6074,18 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.gt_s - (get_local $0) - (i32.const 0) - ) - ) - (i32.le_s + (if (result i32) + (tee_local $1 + (i32.gt_s (get_local $0) - (i32.const 536870910) + (i32.const 0) ) - (get_local $1) ) - (i32.const 1) + (i32.le_s + (get_local $0) + (i32.const 536870910) + ) + (get_local $1) ) ) (block @@ -8971,10 +8935,13 @@ ) ) (set_global $std/array/boolVal - (call $~lib/array/Array#reduce - (get_global $std/array/arr) - (i32.const 30) - (i32.const 0) + (i32.and + (call $~lib/array/Array#reduce + (get_global $std/array/arr) + (i32.const 30) + (i32.const 0) + ) + (i32.const 1) ) ) (if @@ -8993,10 +8960,13 @@ ) ) (set_global $std/array/boolVal - (call $~lib/array/Array#reduce - (get_global $std/array/arr) - (i32.const 31) - (i32.const 0) + (i32.and + (call $~lib/array/Array#reduce + (get_global $std/array/arr) + (i32.const 31) + (i32.const 0) + ) + (i32.const 1) ) ) (if @@ -9188,10 +9158,13 @@ ) ) (set_global $std/array/boolVal - (call $~lib/array/Array#reduceRight - (get_global $std/array/arr) - (i32.const 37) - (i32.const 0) + (i32.and + (call $~lib/array/Array#reduceRight + (get_global $std/array/arr) + (i32.const 37) + (i32.const 0) + ) + (i32.const 1) ) ) (if @@ -9210,10 +9183,13 @@ ) ) (set_global $std/array/boolVal - (call $~lib/array/Array#reduceRight - (get_global $std/array/arr) - (i32.const 38) - (i32.const 0) + (i32.and + (call $~lib/array/Array#reduceRight + (get_global $std/array/arr) + (i32.const 38) + (i32.const 0) + ) + (i32.const 1) ) ) (if diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index d8f63d4a..61dc4b0a 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -377,7 +377,10 @@ (i32.const -1) (i32.const 255) ) - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) ) ) (i32.store @@ -2526,27 +2529,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory @@ -3489,21 +3489,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eq - (get_local $3) - (i32.const 0) - ) - ) - (get_local $4) - (i32.ge_s - (get_local $2) + (if (result i32) + (tee_local $4 + (i32.eq (get_local $3) + (i32.const 0) ) ) - (i32.const 1) + (get_local $4) + (i32.ge_s + (get_local $2) + (get_local $3) + ) ) (return (i32.const -1) @@ -3617,21 +3614,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eq - (get_local $3) - (i32.const 0) - ) - ) - (get_local $4) - (i32.ge_s - (get_local $2) + (if (result i32) + (tee_local $4 + (i32.eq (get_local $3) + (i32.const 0) ) ) - (i32.const 1) + (get_local $4) + (i32.ge_s + (get_local $2) + (get_local $3) + ) ) (return (i32.const 0) @@ -3945,49 +3939,49 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_s - (get_local $3) - (get_local $4) - ) - ) + (if (result i32) + (tee_local $5 (i32.lt_s (get_local $3) - (i32.load offset=4 - (get_local $0) - ) + (get_local $4) ) - (get_local $5) ) - (i32.const 1) + (i32.lt_s + (get_local $3) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $5) ) (block (block (if - (block (result i32) - (set_global $~argc - (i32.const 3) - ) - (call_indirect (type $iiii) - (block $~lib/internal/arraybuffer/loadUnsafe|inlined.10 (result i32) - (br $~lib/internal/arraybuffer/loadUnsafe|inlined.10 - (i32.load offset=8 - (i32.add - (get_local $2) - (i32.shl - (get_local $3) - (i32.const 2) + (i32.and + (block (result i32) + (set_global $~argc + (i32.const 3) + ) + (call_indirect (type $iiii) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.10 (result i32) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.10 + (i32.load offset=8 + (i32.add + (get_local $2) + (i32.shl + (get_local $3) + (i32.const 2) + ) ) ) ) ) + (get_local $3) + (get_local $0) + (get_local $1) ) - (get_local $3) - (get_local $0) - (get_local $1) ) + (i32.const 1) ) (return (get_local $3) @@ -4083,50 +4077,50 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_s - (get_local $3) - (get_local $4) - ) - ) + (if (result i32) + (tee_local $5 (i32.lt_s (get_local $3) - (i32.load offset=4 - (get_local $0) - ) + (get_local $4) ) - (get_local $5) ) - (i32.const 1) + (i32.lt_s + (get_local $3) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $5) ) (block (block (if (i32.eqz - (block (result i32) - (set_global $~argc - (i32.const 3) - ) - (call_indirect (type $iiii) - (block $~lib/internal/arraybuffer/loadUnsafe|inlined.12 (result i32) - (br $~lib/internal/arraybuffer/loadUnsafe|inlined.12 - (i32.load offset=8 - (i32.add - (get_local $2) - (i32.shl - (get_local $3) - (i32.const 2) + (i32.and + (block (result i32) + (set_global $~argc + (i32.const 3) + ) + (call_indirect (type $iiii) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.12 (result i32) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.12 + (i32.load offset=8 + (i32.add + (get_local $2) + (i32.shl + (get_local $3) + (i32.const 2) + ) ) ) ) ) + (get_local $3) + (get_local $0) + (get_local $1) ) - (get_local $3) - (get_local $0) - (get_local $1) ) + (i32.const 1) ) ) (return @@ -4217,49 +4211,49 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_s - (get_local $3) - (get_local $4) - ) - ) + (if (result i32) + (tee_local $5 (i32.lt_s (get_local $3) - (i32.load offset=4 - (get_local $0) - ) + (get_local $4) ) - (get_local $5) ) - (i32.const 1) + (i32.lt_s + (get_local $3) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $5) ) (block (block (if - (block (result i32) - (set_global $~argc - (i32.const 3) - ) - (call_indirect (type $iiii) - (block $~lib/internal/arraybuffer/loadUnsafe|inlined.14 (result i32) - (br $~lib/internal/arraybuffer/loadUnsafe|inlined.14 - (i32.load offset=8 - (i32.add - (get_local $2) - (i32.shl - (get_local $3) - (i32.const 2) + (i32.and + (block (result i32) + (set_global $~argc + (i32.const 3) + ) + (call_indirect (type $iiii) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.14 (result i32) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.14 + (i32.load offset=8 + (i32.add + (get_local $2) + (i32.shl + (get_local $3) + (i32.const 2) + ) ) ) ) ) + (get_local $3) + (get_local $0) + (get_local $1) ) - (get_local $3) - (get_local $0) - (get_local $1) ) + (i32.const 1) ) (return (i32.const 1) @@ -4351,23 +4345,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_s - (get_local $3) - (get_local $4) - ) - ) + (if (result i32) + (tee_local $5 (i32.lt_s (get_local $3) - (i32.load offset=4 - (get_local $0) - ) + (get_local $4) ) - (get_local $5) ) - (i32.const 1) + (i32.lt_s + (get_local $3) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $5) ) (block (block @@ -4556,23 +4547,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.lt_s - (get_local $6) - (get_local $3) - ) - ) + (if (result i32) + (tee_local $7 (i32.lt_s (get_local $6) - (i32.load offset=4 - (get_local $0) - ) + (get_local $3) ) - (get_local $7) ) - (i32.const 1) + (i32.lt_s + (get_local $6) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $7) ) (block (block @@ -4722,23 +4710,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.lt_s - (get_local $6) - (get_local $3) - ) - ) + (if (result i32) + (tee_local $7 (i32.lt_s (get_local $6) - (i32.load offset=4 - (get_local $0) - ) + (get_local $3) ) - (get_local $7) ) - (i32.const 1) + (i32.lt_s + (get_local $6) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $7) ) (block (block @@ -4861,23 +4846,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.lt_s - (get_local $5) - (get_local $3) - ) - ) + (if (result i32) + (tee_local $6 (i32.lt_s (get_local $5) - (i32.load offset=4 - (get_local $0) - ) + (get_local $3) ) - (get_local $6) ) - (i32.const 1) + (i32.lt_s + (get_local $5) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $6) ) (block (block @@ -4897,16 +4879,19 @@ ) ) (if - (block (result i32) - (set_global $~argc - (i32.const 3) - ) - (call_indirect (type $iiii) - (get_local $6) - (get_local $5) - (get_local $0) - (get_local $1) + (i32.and + (block (result i32) + (set_global $~argc + (i32.const 3) + ) + (call_indirect (type $iiii) + (get_local $6) + (get_local $5) + (get_local $0) + (get_local $1) + ) ) + (i32.const 1) ) (drop (call $~lib/array/Array#push @@ -5017,23 +5002,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.lt_s - (get_local $5) - (get_local $6) - ) - ) + (if (result i32) + (tee_local $7 (i32.lt_s (get_local $5) - (i32.load offset=4 - (get_local $0) - ) + (get_local $6) ) - (get_local $7) ) - (i32.const 1) + (i32.lt_s + (get_local $5) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $7) ) (block (block @@ -5086,16 +5068,16 @@ ) ) (func $start~anonymous|30 (; 66 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - (i32.and - (if (result i32) + (if (result i32) + (i32.and (get_local $0) - (get_local $0) - (i32.gt_s - (get_local $1) - (i32.const 2) - ) + (i32.const 1) + ) + (get_local $0) + (i32.gt_s + (get_local $1) + (i32.const 2) ) - (i32.const 1) ) ) (func $~lib/array/Array#reduce (; 67 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) @@ -5125,23 +5107,20 @@ ) (loop $continue|0 (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.lt_s - (get_local $5) - (get_local $6) - ) - ) + (if (result i32) + (tee_local $7 (i32.lt_s (get_local $5) - (i32.load offset=4 - (get_local $0) - ) + (get_local $6) ) - (get_local $7) ) - (i32.const 1) + (i32.lt_s + (get_local $5) + (i32.load offset=4 + (get_local $0) + ) + ) + (get_local $7) ) (block (block @@ -5188,16 +5167,16 @@ ) ) (func $start~anonymous|31 (; 68 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - (i32.and - (if (result i32) + (if (result i32) + (i32.and (get_local $0) - (get_local $0) - (i32.gt_s - (get_local $1) - (i32.const 100) - ) + (i32.const 1) + ) + (get_local $0) + (i32.gt_s + (get_local $1) + (i32.const 100) ) - (i32.const 1) ) ) (func $start~anonymous|32 (; 69 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) @@ -5317,16 +5296,16 @@ ) ) (func $start~anonymous|37 (; 75 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - (i32.and - (if (result i32) + (if (result i32) + (i32.and (get_local $0) - (get_local $0) - (i32.gt_s - (get_local $1) - (i32.const 2) - ) + (i32.const 1) + ) + (get_local $0) + (i32.gt_s + (get_local $1) + (i32.const 2) ) - (i32.const 1) ) ) (func $~lib/array/Array#reduceRight (; 76 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) @@ -5401,16 +5380,16 @@ ) ) (func $start~anonymous|38 (; 77 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - (i32.and - (if (result i32) + (if (result i32) + (i32.and (get_local $0) - (get_local $0) - (i32.gt_s - (get_local $1) - (i32.const 100) - ) + (i32.const 1) + ) + (get_local $0) + (i32.gt_s + (get_local $1) + (i32.const 100) ) - (i32.const 1) ) ) (func $start~anonymous|39 (; 78 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) @@ -8206,33 +8185,27 @@ (local $5 i32) (local $6 i32) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (get_local $1) - ) - ) - (get_local $2) - (i32.eq - (get_local $0) - (i32.const 0) - ) + (if (result i32) + (tee_local $2 + (if (result i32) + (tee_local $2 + (i32.eq + (get_local $0) + (get_local $1) ) - (i32.const 1) + ) + (get_local $2) + (i32.eq + (get_local $0) + (i32.const 0) ) ) - (get_local $2) - (i32.eq - (get_local $1) - (i32.const 0) - ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $1) + (i32.const 0) + ) ) (return (i32.const 0) @@ -8305,33 +8278,27 @@ (local $5 i32) (local $6 i32) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (get_local $1) - ) - ) - (get_local $2) - (i32.eq - (get_local $0) - (i32.const 0) - ) + (if (result i32) + (tee_local $2 + (if (result i32) + (tee_local $2 + (i32.eq + (get_local $0) + (get_local $1) ) - (i32.const 1) + ) + (get_local $2) + (i32.eq + (get_local $0) + (i32.const 0) ) ) - (get_local $2) - (i32.eq - (get_local $1) - (i32.const 0) - ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $1) + (i32.const 0) + ) ) (return (i32.const 0) @@ -8845,21 +8812,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (i32.const 0) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (i32.eq - (get_local $1) + (get_local $0) (i32.const 0) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $1) + (i32.const 0) + ) ) (return (i32.const 0) @@ -9082,21 +9046,18 @@ (local $2 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.gt_s - (get_local $0) - (i32.const 0) - ) - ) - (i32.le_s + (if (result i32) + (tee_local $1 + (i32.gt_s (get_local $0) - (i32.const 536870910) + (i32.const 0) ) - (get_local $1) ) - (i32.const 1) + (i32.le_s + (get_local $0) + (i32.const 536870910) + ) + (get_local $1) ) ) (block @@ -12356,10 +12317,13 @@ ) ) (set_global $std/array/boolVal - (call $~lib/array/Array#reduce - (get_global $std/array/arr) - (i32.const 30) - (i32.const 0) + (i32.and + (call $~lib/array/Array#reduce + (get_global $std/array/arr) + (i32.const 30) + (i32.const 0) + ) + (i32.const 1) ) ) (if @@ -12380,10 +12344,13 @@ ) ) (set_global $std/array/boolVal - (call $~lib/array/Array#reduce - (get_global $std/array/arr) - (i32.const 31) - (i32.const 0) + (i32.and + (call $~lib/array/Array#reduce + (get_global $std/array/arr) + (i32.const 31) + (i32.const 0) + ) + (i32.const 1) ) ) (if @@ -12594,10 +12561,13 @@ ) ) (set_global $std/array/boolVal - (call $~lib/array/Array#reduceRight - (get_global $std/array/arr) - (i32.const 37) - (i32.const 0) + (i32.and + (call $~lib/array/Array#reduceRight + (get_global $std/array/arr) + (i32.const 37) + (i32.const 0) + ) + (i32.const 1) ) ) (if @@ -12618,10 +12588,13 @@ ) ) (set_global $std/array/boolVal - (call $~lib/array/Array#reduceRight - (get_global $std/array/arr) - (i32.const 38) - (i32.const 0) + (i32.and + (call $~lib/array/Array#reduceRight + (get_global $std/array/arr) + (i32.const 38) + (i32.const 0) + ) + (i32.const 1) ) ) (if diff --git a/tests/compiler/std/arraybuffer.optimized.wat b/tests/compiler/std/arraybuffer.optimized.wat index 7b8b691e..cdb8d111 100644 --- a/tests/compiler/std/arraybuffer.optimized.wat +++ b/tests/compiler/std/arraybuffer.optimized.wat @@ -262,7 +262,10 @@ ) (tee_local $1 (i32.mul - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) (i32.const 16843009) ) ) @@ -2100,27 +2103,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory diff --git a/tests/compiler/std/arraybuffer.untouched.wat b/tests/compiler/std/arraybuffer.untouched.wat index a041a544..16d8643d 100644 --- a/tests/compiler/std/arraybuffer.untouched.wat +++ b/tests/compiler/std/arraybuffer.untouched.wat @@ -317,7 +317,10 @@ (i32.const -1) (i32.const 255) ) - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) ) ) (i32.store @@ -2384,27 +2387,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory diff --git a/tests/compiler/std/libm.optimized.wat b/tests/compiler/std/libm.optimized.wat index 9559aec8..fe66014b 100644 --- a/tests/compiler/std/libm.optimized.wat +++ b/tests/compiler/std/libm.optimized.wat @@ -331,30 +331,27 @@ (i32.const 1) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.lt_u - (tee_local $3 - (i32.wrap/i64 - (i64.shr_u - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 32) + (if (result i32) + (tee_local $6 + (i32.lt_u + (tee_local $3 + (i32.wrap/i64 + (i64.shr_u + (i64.reinterpret/f64 + (get_local $0) ) + (i64.const 32) ) ) - (i32.const 1071284858) ) - ) - (get_local $6) - (i32.shr_u - (get_local $3) - (i32.const 31) + (i32.const 1071284858) ) ) - (i32.const 1) + (get_local $6) + (i32.shr_u + (get_local $3) + (i32.const 31) + ) ) (block (if @@ -623,32 +620,29 @@ (local $7 f64) (local $8 f64) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_u - (tee_local $1 - (i32.wrap/i64 - (i64.shr_u - (tee_local $3 - (i64.reinterpret/f64 - (get_local $0) - ) + (if (result i32) + (tee_local $5 + (i32.lt_u + (tee_local $1 + (i32.wrap/i64 + (i64.shr_u + (tee_local $3 + (i64.reinterpret/f64 + (get_local $0) ) - (i64.const 32) ) + (i64.const 32) ) ) - (i32.const 1048576) ) - ) - (get_local $5) - (i32.shr_u - (get_local $1) - (i32.const 31) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $5) + (i32.shr_u + (get_local $1) + (i32.const 31) + ) ) (block (if @@ -715,24 +709,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $1) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $1) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $3) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $5) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $3) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $5) ) (return (f64.const 0) @@ -1037,21 +1028,18 @@ ) (block (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.lt_u - (get_local $2) - (i32.const 1045430272) - ) - ) - (i32.ge_u + (if (result i32) + (tee_local $3 + (i32.lt_u (get_local $2) - (i32.const 1048576) + (i32.const 1045430272) ) - (get_local $3) ) - (i32.const 1) + (i32.ge_u + (get_local $2) + (i32.const 1048576) + ) + (get_local $3) ) (return (get_local $0) @@ -1786,19 +1774,16 @@ (local $7 i32) (block $folding-inner0 (if - (i32.and - (if (result i32) - (tee_local $2 - (call $isNaN - (get_local $1) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (call $isNaN - (get_local $0) + (get_local $1) ) ) - (i32.const 1) + (get_local $2) + (call $isNaN + (get_local $0) + ) ) (return (f64.add @@ -2010,24 +1995,21 @@ ) ) (br_if $folding-inner0 - (i32.and - (if (result i32) - (tee_local $2 - (i32.lt_u - (i32.add - (get_local $3) - (i32.const 67108864) - ) - (get_local $4) + (if (result i32) + (tee_local $2 + (i32.lt_u + (i32.add + (get_local $3) + (i32.const 67108864) ) - ) - (get_local $2) - (i32.eq (get_local $4) - (i32.const 2146435072) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $4) + (i32.const 2146435072) + ) ) ) (set_local $0 @@ -2666,21 +2648,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_s - (get_local $2) - (i32.const 0) - ) - ) - (get_local $4) - (i32.gt_s + (if (result i32) + (tee_local $4 + (i32.lt_s (get_local $2) - (i32.const 56) + (i32.const 0) ) ) - (i32.const 1) + (get_local $4) + (i32.gt_s + (get_local $2) + (i32.const 56) + ) ) (block (set_local $0 @@ -3284,28 +3263,25 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $10 - (i32.eq - (tee_local $8 - (i32.wrap/i64 - (i64.shr_u - (get_local $5) - (i64.const 52) - ) + (if (result i32) + (tee_local $10 + (i32.eq + (tee_local $8 + (i32.wrap/i64 + (i64.shr_u + (get_local $5) + (i64.const 52) ) ) - (i32.const 2047) ) - ) - (get_local $10) - (i64.eq - (get_local $4) - (i64.const 0) + (i32.const 2047) ) ) - (i32.const 1) + (get_local $10) + (i64.eq + (get_local $4) + (i64.const 0) + ) ) (return (get_local $0) @@ -3525,32 +3501,29 @@ (local $9 f64) (local $10 f64) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_u - (tee_local $2 - (i32.wrap/i64 - (i64.shr_u - (tee_local $4 - (i64.reinterpret/f64 - (get_local $0) - ) + (if (result i32) + (tee_local $5 + (i32.lt_u + (tee_local $2 + (i32.wrap/i64 + (i64.shr_u + (tee_local $4 + (i64.reinterpret/f64 + (get_local $0) ) - (i64.const 32) ) + (i64.const 32) ) ) - (i32.const 1048576) ) - ) - (get_local $5) - (i32.shr_u - (get_local $2) - (i32.const 31) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $5) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -3617,24 +3590,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $4) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $5) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $4) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $5) ) (return (f64.const 0) @@ -3851,32 +3821,29 @@ (local $7 f64) (local $8 i32) (if - (i32.and - (if (result i32) - (tee_local $8 - (i32.lt_u - (tee_local $2 - (i32.wrap/i64 - (i64.shr_u - (tee_local $6 - (i64.reinterpret/f64 - (get_local $0) - ) + (if (result i32) + (tee_local $8 + (i32.lt_u + (tee_local $2 + (i32.wrap/i64 + (i64.shr_u + (tee_local $6 + (i64.reinterpret/f64 + (get_local $0) ) - (i64.const 32) ) + (i64.const 32) ) ) - (i32.const 1048576) ) - ) - (get_local $8) - (i32.shr_u - (get_local $2) - (i32.const 31) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $8) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -3943,24 +3910,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $8 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $8 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $6) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $8) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $6) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $8) ) (return (f64.const 0) @@ -4240,63 +4204,51 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.gt_s - (get_local $6) - (i32.const 2146435072) - ) - ) - (get_local $5) - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $6) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $7) - (i32.const 0) - ) - (get_local $5) - ) - ) - (i32.const 1) - ) - ) - (get_local $5) - (i32.gt_s - (get_local $10) - (i32.const 2146435072) - ) - ) - (i32.const 1) - ) - ) - (get_local $5) (if (result i32) (tee_local $5 - (i32.eq - (get_local $10) + (i32.gt_s + (get_local $6) (i32.const 2146435072) ) ) - (i32.ne - (get_local $4) - (i32.const 0) - ) (get_local $5) + (tee_local $5 + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $6) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $7) + (i32.const 0) + ) + (get_local $5) + ) + ) + ) + (get_local $5) + (tee_local $5 + (i32.gt_s + (get_local $10) + (i32.const 2146435072) + ) ) ) - (i32.const 1) + (get_local $5) + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $10) + (i32.const 2146435072) + ) + ) + (get_local $4) + (get_local $5) + ) ) (return (f64.add @@ -4518,32 +4470,26 @@ (get_local $7) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $6) - (i32.const 2146435072) - ) - ) - (get_local $5) - (i32.eqz - (get_local $6) - ) - ) - (i32.const 1) + (i32.eq + (get_local $6) + (i32.const 2146435072) ) ) (get_local $5) - (i32.eq - (get_local $6) - (i32.const 1072693248) + (tee_local $5 + (i32.eqz + (get_local $6) + ) ) ) - (i32.const 1) + (get_local $5) + (i32.eq + (get_local $6) + (i32.const 1072693248) + ) ) (block (if diff --git a/tests/compiler/std/libm.untouched.wat b/tests/compiler/std/libm.untouched.wat index a9ea356d..45559c7e 100644 --- a/tests/compiler/std/libm.untouched.wat +++ b/tests/compiler/std/libm.untouched.wat @@ -428,24 +428,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.lt_u - (get_local $2) - (i32.const 1071284858) - ) - ) - (get_local $6) - (i32.and - (i32.shr_u - (get_local $2) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $6 + (i32.lt_u + (get_local $2) + (i32.const 1071284858) ) ) - (i32.const 1) + (get_local $6) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -780,24 +774,18 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_u - (get_local $2) - (i32.const 1048576) - ) - ) - (get_local $4) - (i32.and - (i32.shr_u - (get_local $2) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $4 + (i32.lt_u + (get_local $2) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $4) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -868,24 +856,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $4 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $1) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $4) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $1) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $4) ) (return (f64.const 0) @@ -1246,21 +1231,18 @@ ) (block (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_u - (get_local $2) - (i32.const 1045430272) - ) - ) - (i32.ge_u + (if (result i32) + (tee_local $4 + (i32.lt_u (get_local $2) - (i32.const 1048576) + (i32.const 1045430272) ) - (get_local $4) ) - (i32.const 1) + (i32.ge_u + (get_local $2) + (i32.const 1048576) + ) + (get_local $4) ) (return (get_local $0) @@ -2107,19 +2089,16 @@ (local $9 f64) (nop) (if - (i32.and - (if (result i32) - (tee_local $2 - (call $isNaN - (get_local $1) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (call $isNaN - (get_local $0) + (get_local $1) ) ) - (i32.const 1) + (get_local $2) + (call $isNaN + (get_local $0) + ) ) (return (f64.add @@ -2432,27 +2411,24 @@ ) (nop) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.lt_u - (i32.add - (get_local $4) - (i32.shl - (i32.const 64) - (i32.const 20) - ) + (if (result i32) + (tee_local $2 + (i32.lt_u + (i32.add + (get_local $4) + (i32.shl + (i32.const 64) + (i32.const 20) ) - (get_local $6) ) - ) - (get_local $2) - (i32.eq (get_local $6) - (i32.const 2146435072) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $6) + (i32.const 2146435072) + ) ) (return (if (result f64) @@ -3230,21 +3206,18 @@ ) (nop) (if - (i32.and - (if (result i32) - (tee_local $15 - (i32.lt_s - (get_local $3) - (i32.const 0) - ) - ) - (get_local $15) - (i32.gt_s + (if (result i32) + (tee_local $15 + (i32.lt_s (get_local $3) - (i32.const 56) + (i32.const 0) ) ) - (i32.const 1) + (get_local $15) + (i32.gt_s + (get_local $3) + (i32.const 56) + ) ) (block (set_local $14 @@ -3974,21 +3947,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.eq - (get_local $5) - (i32.const 2047) - ) - ) - (get_local $7) - (i64.eq - (get_local $3) - (i64.const 0) + (if (result i32) + (tee_local $7 + (i32.eq + (get_local $5) + (i32.const 2047) ) ) - (i32.const 1) + (get_local $7) + (i64.eq + (get_local $3) + (i64.const 0) + ) ) (return (get_local $0) @@ -4258,24 +4228,18 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_u - (get_local $2) - (i32.const 1048576) - ) - ) - (get_local $4) - (i32.and - (i32.shr_u - (get_local $2) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $4 + (i32.lt_u + (get_local $2) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $4) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -4346,24 +4310,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $4 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $1) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $4) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $1) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $4) ) (return (f64.const 0) @@ -4660,24 +4621,18 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_u - (get_local $2) - (i32.const 1048576) - ) - ) - (get_local $4) - (i32.and - (i32.shr_u - (get_local $2) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $4 + (i32.lt_u + (get_local $2) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $4) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -4748,24 +4703,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $4 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $1) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $4) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $1) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $4) ) (return (f64.const 0) @@ -5133,63 +5085,54 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $9 - (i32.and + (if (result i32) + (tee_local $9 + (if (result i32) + (tee_local $9 (if (result i32) (tee_local $9 - (i32.and - (if (result i32) - (tee_local $9 - (i32.gt_s - (get_local $7) - (i32.const 2146435072) - ) - ) - (get_local $9) - (if (result i32) - (tee_local $9 - (i32.eq - (get_local $7) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $4) - (i32.const 0) - ) - (get_local $9) - ) - ) - (i32.const 1) + (i32.gt_s + (get_local $7) + (i32.const 2146435072) ) ) (get_local $9) - (i32.gt_s - (get_local $8) - (i32.const 2146435072) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $7) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $4) + (i32.const 0) + ) + (get_local $9) ) ) - (i32.const 1) - ) - ) - (get_local $9) - (if (result i32) - (tee_local $9 - (i32.eq - (get_local $8) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $6) - (i32.const 0) ) (get_local $9) + (i32.gt_s + (get_local $8) + (i32.const 2146435072) + ) ) ) - (i32.const 1) + (get_local $9) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $8) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $6) + (i32.const 0) + ) + (get_local $9) + ) ) (return (f64.add @@ -5429,33 +5372,27 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $15 - (i32.and - (if (result i32) - (tee_local $15 - (i32.eq - (get_local $7) - (i32.const 2146435072) - ) - ) - (get_local $15) - (i32.eq - (get_local $7) - (i32.const 0) - ) + (if (result i32) + (tee_local $15 + (if (result i32) + (tee_local $15 + (i32.eq + (get_local $7) + (i32.const 2146435072) ) - (i32.const 1) + ) + (get_local $15) + (i32.eq + (get_local $7) + (i32.const 0) ) ) - (get_local $15) - (i32.eq - (get_local $7) - (i32.const 1072693248) - ) ) - (i32.const 1) + (get_local $15) + (i32.eq + (get_local $7) + (i32.const 1072693248) + ) ) (block (set_local $14 diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 5b5f0c3e..e96936c8 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -240,19 +240,16 @@ (func $std/math/ulperr (; 36 ;) (type $FFFF) (param $0 f64) (param $1 f64) (param $2 f64) (result f64) (local $3 i32) (if - (i32.and - (if (result i32) - (tee_local $3 - (call $isNaN - (get_local $0) - ) - ) + (if (result i32) + (tee_local $3 (call $isNaN - (get_local $1) + (get_local $0) ) - (get_local $3) ) - (i32.const 1) + (call $isNaN + (get_local $1) + ) + (get_local $3) ) (return (f64.const 0) @@ -532,19 +529,16 @@ (func $std/math/ulperrf (; 43 ;) (type $ffff) (param $0 f32) (param $1 f32) (param $2 f32) (result f32) (local $3 i32) (if - (i32.and - (if (result i32) - (tee_local $3 - (call $isNaN - (get_local $0) - ) - ) + (if (result i32) + (tee_local $3 (call $isNaN - (get_local $1) + (get_local $0) ) - (get_local $3) ) - (i32.const 1) + (call $isNaN + (get_local $1) + ) + (get_local $3) ) (return (f32.const 0) @@ -684,35 +678,32 @@ ) (func $std/math/test_abs (; 47 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (f64.abs + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (f64.abs - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.abs - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.abs + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $std/math/test_absf (; 48 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) @@ -979,35 +970,32 @@ ) (func $std/math/test_acos (; 51 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.acos + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.acos - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.acos - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.acos + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/Rf (; 52 ;) (type $ff) (param $0 f32) (result f32) @@ -1235,30 +1223,27 @@ (i32.const 1) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.lt_u - (tee_local $3 - (i32.wrap/i64 - (i64.shr_u - (i64.reinterpret/f64 - (get_local $0) - ) - (i64.const 32) + (if (result i32) + (tee_local $6 + (i32.lt_u + (tee_local $3 + (i32.wrap/i64 + (i64.shr_u + (i64.reinterpret/f64 + (get_local $0) ) + (i64.const 32) ) ) - (i32.const 1071284858) ) - ) - (get_local $6) - (i32.shr_u - (get_local $3) - (i32.const 31) + (i32.const 1071284858) ) ) - (i32.const 1) + (get_local $6) + (i32.shr_u + (get_local $3) + (i32.const 31) + ) ) (block (if @@ -1527,32 +1512,29 @@ (local $7 f64) (local $8 f64) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_u - (tee_local $1 - (i32.wrap/i64 - (i64.shr_u - (tee_local $3 - (i64.reinterpret/f64 - (get_local $0) - ) + (if (result i32) + (tee_local $5 + (i32.lt_u + (tee_local $1 + (i32.wrap/i64 + (i64.shr_u + (tee_local $3 + (i64.reinterpret/f64 + (get_local $0) ) - (i64.const 32) ) + (i64.const 32) ) ) - (i32.const 1048576) ) - ) - (get_local $5) - (i32.shr_u - (get_local $1) - (i32.const 31) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $5) + (i32.shr_u + (get_local $1) + (i32.const 31) + ) ) (block (if @@ -1619,24 +1601,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $1) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $1) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $3) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $5) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $3) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $5) ) (return (f64.const 0) @@ -1871,35 +1850,32 @@ ) (func $std/math/test_acosh (; 58 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.acosh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.acosh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.acosh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.acosh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.log1p (; 59 ;) (type $ff) (param $0 f32) (result f32) @@ -1914,25 +1890,22 @@ (i32.const 1) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.lt_u - (tee_local $3 - (i32.reinterpret/f32 - (get_local $0) - ) + (if (result i32) + (tee_local $6 + (i32.lt_u + (tee_local $3 + (i32.reinterpret/f32 + (get_local $0) ) - (i32.const 1054086096) ) - ) - (get_local $6) - (i32.shr_u - (get_local $3) - (i32.const 31) + (i32.const 1054086096) ) ) - (i32.const 1) + (get_local $6) + (i32.shr_u + (get_local $3) + (i32.const 31) + ) ) (block (if @@ -2161,25 +2134,22 @@ (local $5 f32) (local $6 i32) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.lt_u - (tee_local $1 - (i32.reinterpret/f32 - (get_local $0) - ) + (if (result i32) + (tee_local $6 + (i32.lt_u + (tee_local $1 + (i32.reinterpret/f32 + (get_local $0) ) - (i32.const 8388608) ) - ) - (get_local $6) - (i32.shr_u - (get_local $1) - (i32.const 31) + (i32.const 8388608) ) ) - (i32.const 1) + (get_local $6) + (i32.shr_u + (get_local $1) + (i32.const 31) + ) ) (block (if @@ -2517,21 +2487,18 @@ ) (block (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.lt_u - (get_local $2) - (i32.const 1045430272) - ) - ) - (i32.ge_u + (if (result i32) + (tee_local $3 + (i32.lt_u (get_local $2) - (i32.const 1048576) + (i32.const 1045430272) ) - (get_local $3) ) - (i32.const 1) + (i32.ge_u + (get_local $2) + (i32.const 1048576) + ) + (get_local $3) ) (return (get_local $0) @@ -2661,35 +2628,32 @@ ) (func $std/math/test_asin (; 64 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.asin + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.asin - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.asin - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.asin + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.asin (; 65 ;) (type $ff) (param $0 f32) (result f32) @@ -2744,21 +2708,18 @@ ) (block (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.lt_u - (get_local $1) - (i32.const 964689920) - ) - ) - (i32.ge_u + (if (result i32) + (tee_local $2 + (i32.lt_u (get_local $1) - (i32.const 8388608) + (i32.const 964689920) ) - (get_local $2) ) - (i32.const 1) + (i32.ge_u + (get_local $1) + (i32.const 8388608) + ) + (get_local $2) ) (return (get_local $0) @@ -2960,35 +2921,32 @@ ) (func $std/math/test_asinh (; 68 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.asinh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.asinh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.asinh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.asinh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.asinh (; 69 ;) (type $ff) (param $0 f32) (result f32) @@ -3468,35 +3426,32 @@ ) (func $std/math/test_atan (; 72 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.atan + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.atan - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.atan - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.atan + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.atan (; 73 ;) (type $ff) (param $0 f32) (result f32) @@ -3924,35 +3879,32 @@ ) (func $std/math/test_atanh (; 76 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.atanh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.atanh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.atanh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.atanh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.atanh (; 77 ;) (type $ff) (param $0 f32) (result f32) @@ -4060,19 +4012,16 @@ (local $7 i32) (block $folding-inner0 (if - (i32.and - (if (result i32) - (tee_local $2 - (call $isNaN - (get_local $1) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (call $isNaN - (get_local $0) + (get_local $1) ) ) - (i32.const 1) + (get_local $2) + (call $isNaN + (get_local $0) + ) ) (return (f64.add @@ -4284,24 +4233,21 @@ ) ) (br_if $folding-inner0 - (i32.and - (if (result i32) - (tee_local $2 - (i32.lt_u - (i32.add - (get_local $3) - (i32.const 67108864) - ) - (get_local $4) + (if (result i32) + (tee_local $2 + (i32.lt_u + (i32.add + (get_local $3) + (i32.const 67108864) ) - ) - (get_local $2) - (i32.eq (get_local $4) - (i32.const 2146435072) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $4) + (i32.const 2146435072) + ) ) ) (set_local $0 @@ -4388,37 +4334,34 @@ ) (func $std/math/test_atan2 (; 80 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) - (i32.and + (if (result i32) + (tee_local $5 + (call $std/math/check + (call $~lib/math/NativeMath.atan2 + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) + ) (if (result i32) (tee_local $5 - (call $std/math/check - (call $~lib/math/NativeMath.atan2 - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) - (if (result i32) - (tee_local $5 - (i32.const 0) - ) - (get_local $5) - (call $std/math/check - (call $~lib/math/JSMath.atan2 - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) + (i32.const 0) ) (get_local $5) + (call $std/math/check + (call $~lib/math/JSMath.atan2 + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) (func $~lib/math/NativeMathf.atan2 (; 81 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) @@ -4428,19 +4371,16 @@ (local $5 i32) (block $folding-inner0 (if - (i32.and - (if (result i32) - (tee_local $2 - (call $isNaN - (get_local $1) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (call $isNaN - (get_local $0) + (get_local $1) ) ) - (i32.const 1) + (get_local $2) + (call $isNaN + (get_local $0) + ) ) (return (f32.add @@ -4619,24 +4559,21 @@ ) ) (br_if $folding-inner0 - (i32.and - (if (result i32) - (tee_local $2 - (i32.lt_u - (i32.add - (get_local $4) - (i32.const 218103808) - ) - (get_local $3) + (if (result i32) + (tee_local $2 + (i32.lt_u + (i32.add + (get_local $4) + (i32.const 218103808) ) - ) - (get_local $2) - (i32.eq (get_local $3) - (i32.const 2139095040) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $3) + (i32.const 2139095040) + ) ) ) (set_local $0 @@ -4917,35 +4854,32 @@ ) (func $std/math/test_cbrt (; 84 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.cbrt + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.cbrt - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.cbrt - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.cbrt + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.cbrt (; 85 ;) (type $ff) (param $0 f32) (result f32) @@ -5112,35 +5046,32 @@ ) (func $std/math/test_ceil (; 87 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (f64.ceil + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (f64.ceil - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.ceil - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.ceil + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $std/math/test_ceilf (; 88 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) @@ -5491,21 +5422,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_s - (get_local $2) - (i32.const 0) - ) - ) - (get_local $4) - (i32.gt_s + (if (result i32) + (tee_local $4 + (i32.lt_s (get_local $2) - (i32.const 56) + (i32.const 0) ) ) - (i32.const 1) + (get_local $4) + (i32.gt_s + (get_local $2) + (i32.const 56) + ) ) (block (set_local $0 @@ -5903,35 +5831,32 @@ ) (func $std/math/test_cosh (; 93 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.cosh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.cosh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.cosh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.cosh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.expm1 (; 94 ;) (type $ff) (param $0 f32) (result f32) @@ -6247,21 +6172,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.lt_s - (get_local $2) - (i32.const 0) - ) - ) - (get_local $3) - (i32.gt_s + (if (result i32) + (tee_local $3 + (i32.lt_s (get_local $2) - (i32.const 56) + (i32.const 0) ) ) - (i32.const 1) + (get_local $3) + (i32.gt_s + (get_local $2) + (i32.const 56) + ) ) (block (set_local $0 @@ -6375,20 +6297,17 @@ ) (block (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.ge_u - (get_local $1) - (i32.const 1118925336) - ) + (if (result i32) + (tee_local $5 + (i32.ge_u + (get_local $1) + (i32.const 1118925336) ) - (i32.eqz - (get_local $2) - ) - (get_local $5) ) - (i32.const 1) + (i32.eqz + (get_local $2) + ) + (get_local $5) ) (return (f32.mul @@ -6648,35 +6567,32 @@ ) (func $std/math/test_exp (; 99 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.exp + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.exp - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.exp - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.exp + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $std/math/test_expf (; 100 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) @@ -6691,35 +6607,32 @@ ) (func $std/math/test_expm1 (; 101 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.expm1 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.expm1 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.expm1 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.expm1 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $std/math/test_expm1f (; 102 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) @@ -6734,35 +6647,32 @@ ) (func $std/math/test_floor (; 103 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (f64.floor + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (f64.floor - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.floor - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.floor + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $std/math/test_floorf (; 104 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) @@ -6844,28 +6754,25 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $10 - (i32.eq - (tee_local $8 - (i32.wrap/i64 - (i64.shr_u - (get_local $5) - (i64.const 52) - ) + (if (result i32) + (tee_local $10 + (i32.eq + (tee_local $8 + (i32.wrap/i64 + (i64.shr_u + (get_local $5) + (i64.const 52) ) ) - (i32.const 2047) ) - ) - (get_local $10) - (i64.eq - (get_local $4) - (i64.const 0) + (i32.const 2047) ) ) - (i32.const 1) + (get_local $10) + (i64.eq + (get_local $4) + (i64.const 0) + ) ) (return (get_local $0) @@ -7046,37 +6953,34 @@ ) (func $std/math/test_hypot (; 106 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) - (i32.and + (if (result i32) + (tee_local $5 + (call $std/math/check + (call $~lib/math/NativeMath.hypot + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) + ) (if (result i32) (tee_local $5 - (call $std/math/check - (call $~lib/math/NativeMath.hypot - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) - (if (result i32) - (tee_local $5 - (i32.const 0) - ) - (get_local $5) - (call $std/math/check - (call $~lib/math/JSMath.hypot - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) + (i32.const 0) ) (get_local $5) + (call $std/math/check + (call $~lib/math/JSMath.hypot + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) (func $~lib/math/NativeMathf.hypot (; 107 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) @@ -7135,35 +7039,29 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $4 - (i32.and - (if (result i32) - (tee_local $4 - (i32.ge_u - (get_local $3) - (i32.const 2139095040) - ) - ) - (get_local $4) - (i32.eqz - (get_local $2) - ) - ) - (i32.const 1) + (i32.ge_u + (get_local $3) + (i32.const 2139095040) ) ) (get_local $4) - (i32.ge_u - (i32.sub - (get_local $3) + (tee_local $4 + (i32.eqz (get_local $2) ) - (i32.const 209715200) ) ) - (i32.const 1) + (get_local $4) + (i32.ge_u + (i32.sub + (get_local $3) + (get_local $2) + ) + (i32.const 209715200) + ) ) (return (f32.add @@ -7260,35 +7158,32 @@ ) (func $std/math/test_log (; 109 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.log + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.log - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.log - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.log + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $std/math/test_logf (; 110 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) @@ -7313,32 +7208,29 @@ (local $9 f64) (local $10 f64) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_u - (tee_local $2 - (i32.wrap/i64 - (i64.shr_u - (tee_local $4 - (i64.reinterpret/f64 - (get_local $0) - ) + (if (result i32) + (tee_local $5 + (i32.lt_u + (tee_local $2 + (i32.wrap/i64 + (i64.shr_u + (tee_local $4 + (i64.reinterpret/f64 + (get_local $0) ) - (i64.const 32) ) + (i64.const 32) ) ) - (i32.const 1048576) ) - ) - (get_local $5) - (i32.shr_u - (get_local $2) - (i32.const 31) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $5) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -7405,24 +7297,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $4) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $5) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $4) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $5) ) (return (f64.const 0) @@ -7621,35 +7510,32 @@ ) (func $std/math/test_log10 (; 112 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.log10 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.log10 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.log10 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.log10 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.log10 (; 113 ;) (type $ff) (param $0 f32) (result f32) @@ -7662,25 +7548,22 @@ (local $7 i32) (local $8 f32) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.lt_u - (tee_local $1 - (i32.reinterpret/f32 - (get_local $0) - ) + (if (result i32) + (tee_local $7 + (i32.lt_u + (tee_local $1 + (i32.reinterpret/f32 + (get_local $0) ) - (i32.const 8388608) ) - ) - (get_local $7) - (i32.shr_u - (get_local $1) - (i32.const 31) + (i32.const 8388608) ) ) - (i32.const 1) + (get_local $7) + (i32.shr_u + (get_local $1) + (i32.const 31) + ) ) (block (if @@ -7904,35 +7787,32 @@ ) (func $std/math/test_log1p (; 115 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.log1p + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.log1p - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.log1p - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.log1p + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $std/math/test_log1pf (; 116 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) @@ -7955,32 +7835,29 @@ (local $7 f64) (local $8 i32) (if - (i32.and - (if (result i32) - (tee_local $8 - (i32.lt_u - (tee_local $2 - (i32.wrap/i64 - (i64.shr_u - (tee_local $6 - (i64.reinterpret/f64 - (get_local $0) - ) + (if (result i32) + (tee_local $8 + (i32.lt_u + (tee_local $2 + (i32.wrap/i64 + (i64.shr_u + (tee_local $6 + (i64.reinterpret/f64 + (get_local $0) ) - (i64.const 32) ) + (i64.const 32) ) ) - (i32.const 1048576) ) - ) - (get_local $8) - (i32.shr_u - (get_local $2) - (i32.const 31) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $8) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -8047,24 +7924,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $8 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $8 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $6) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $8) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $6) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $8) ) (return (f64.const 0) @@ -8253,35 +8127,32 @@ ) (func $std/math/test_log2 (; 118 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.log2 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.log2 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.log2 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.log2 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.log2 (; 119 ;) (type $ff) (param $0 f32) (result f32) @@ -8293,25 +8164,22 @@ (local $6 f32) (local $7 i32) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.lt_u - (tee_local $1 - (i32.reinterpret/f32 - (get_local $0) - ) + (if (result i32) + (tee_local $7 + (i32.lt_u + (tee_local $1 + (i32.reinterpret/f32 + (get_local $0) ) - (i32.const 8388608) ) - ) - (get_local $7) - (i32.shr_u - (get_local $1) - (i32.const 31) + (i32.const 8388608) ) ) - (i32.const 1) + (get_local $7) + (i32.shr_u + (get_local $1) + (i32.const 31) + ) ) (block (if @@ -8524,37 +8392,34 @@ ) (func $std/math/test_max (; 121 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) - (i32.and + (if (result i32) + (tee_local $5 + (call $std/math/check + (f64.max + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) + ) (if (result i32) (tee_local $5 - (call $std/math/check - (f64.max - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) - (if (result i32) - (tee_local $5 - (i32.const 0) - ) - (get_local $5) - (call $std/math/check - (call $~lib/math/JSMath.max - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) + (i32.const 0) ) (get_local $5) + (call $std/math/check + (call $~lib/math/JSMath.max + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) (func $std/math/test_maxf (; 122 ;) (type $ffffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32) (result i32) @@ -8570,37 +8435,34 @@ ) (func $std/math/test_min (; 123 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) - (i32.and + (if (result i32) + (tee_local $5 + (call $std/math/check + (f64.min + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) + ) (if (result i32) (tee_local $5 - (call $std/math/check - (f64.min - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) - (if (result i32) - (tee_local $5 - (i32.const 0) - ) - (get_local $5) - (call $std/math/check - (call $~lib/math/JSMath.min - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) + (i32.const 0) ) (get_local $5) + (call $std/math/check + (call $~lib/math/JSMath.min + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) (func $std/math/test_minf (; 124 ;) (type $ffffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32) (result i32) @@ -8653,35 +8515,29 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i64.eq - (i64.shl - (get_local $5) - (i64.const 1) - ) - (i64.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) - ) + (i64.eq + (i64.shl + (get_local $5) + (i64.const 1) ) - (i32.const 1) + (i64.const 0) ) ) (get_local $7) - (i32.eq - (get_local $3) - (i32.const 2047) + (tee_local $7 + (call $isNaN + (get_local $1) + ) ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $3) + (i32.const 2047) + ) ) (return (f64.div @@ -8984,37 +8840,34 @@ ) (func $std/math/test_mod (; 126 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) - (i32.and + (if (result i32) + (tee_local $5 + (call $std/math/check + (call $~lib/math/NativeMath.mod + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) + ) (if (result i32) (tee_local $5 - (call $std/math/check - (call $~lib/math/NativeMath.mod - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) - (if (result i32) - (tee_local $5 - (i32.const 0) - ) - (get_local $5) - (call $std/math/check - (call $std/math/JSOp.mod - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) + (i32.const 0) ) (get_local $5) + (call $std/math/check + (call $std/math/JSOp.mod + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) (func $~lib/math/NativeMathf.mod (; 127 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) @@ -9052,34 +8905,28 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $3 - (i32.and - (if (result i32) - (tee_local $3 - (i32.eqz - (i32.shl - (get_local $5) - (i32.const 1) - ) - ) - ) - (get_local $3) - (call $isNaN - (get_local $1) - ) + (i32.eqz + (i32.shl + (get_local $5) + (i32.const 1) ) - (i32.const 1) ) ) (get_local $3) - (i32.eq - (get_local $4) - (i32.const 255) + (tee_local $3 + (call $isNaN + (get_local $1) + ) ) ) - (i32.const 1) + (get_local $3) + (i32.eq + (get_local $4) + (i32.const 255) + ) ) (return (f32.div @@ -9452,63 +9299,51 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.gt_s - (get_local $6) - (i32.const 2146435072) - ) - ) - (get_local $5) - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $6) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $7) - (i32.const 0) - ) - (get_local $5) - ) - ) - (i32.const 1) - ) - ) - (get_local $5) - (i32.gt_s - (get_local $10) - (i32.const 2146435072) - ) - ) - (i32.const 1) - ) - ) - (get_local $5) (if (result i32) (tee_local $5 - (i32.eq - (get_local $10) + (i32.gt_s + (get_local $6) (i32.const 2146435072) ) ) - (i32.ne - (get_local $4) - (i32.const 0) - ) (get_local $5) + (tee_local $5 + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $6) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $7) + (i32.const 0) + ) + (get_local $5) + ) + ) + ) + (get_local $5) + (tee_local $5 + (i32.gt_s + (get_local $10) + (i32.const 2146435072) + ) ) ) - (i32.const 1) + (get_local $5) + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $10) + (i32.const 2146435072) + ) + ) + (get_local $4) + (get_local $5) + ) ) (return (f64.add @@ -9730,32 +9565,26 @@ (get_local $7) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $6) - (i32.const 2146435072) - ) - ) - (get_local $5) - (i32.eqz - (get_local $6) - ) - ) - (i32.const 1) + (i32.eq + (get_local $6) + (i32.const 2146435072) ) ) (get_local $5) - (i32.eq - (get_local $6) - (i32.const 1072693248) + (tee_local $5 + (i32.eqz + (get_local $6) + ) ) ) - (i32.const 1) + (get_local $5) + (i32.eq + (get_local $6) + (i32.const 1072693248) + ) ) (block (if @@ -10777,37 +10606,34 @@ ) (func $std/math/test_pow (; 130 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) - (i32.and + (if (result i32) + (tee_local $5 + (call $std/math/check + (call $~lib/math/NativeMath.pow + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) + ) (if (result i32) (tee_local $5 - (call $std/math/check - (call $~lib/math/NativeMath.pow - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) - (if (result i32) - (tee_local $5 - (i32.const 0) - ) - (get_local $5) - (call $std/math/check - (call $~lib/math/JSMath.pow - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) + (i32.const 0) ) (get_local $5) + (call $std/math/check + (call $~lib/math/JSMath.pow + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) (func $~lib/math/NativeMathf.pow (; 131 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) @@ -10816,21 +10642,22 @@ (local $4 i32) (local $5 i32) (local $6 i32) - (local $7 i32) - (local $8 f32) + (local $7 f32) + (local $8 i32) (local $9 f32) (local $10 i32) (local $11 i32) (local $12 f32) - (local $13 f32) + (local $13 i32) (local $14 f32) - (local $15 i32) - (local $16 f32) + (local $15 f32) + (local $16 i32) + (local $17 f32) (block $folding-inner1 (block $folding-inner0 (set_local $5 (i32.and - (tee_local $15 + (tee_local $4 (i32.reinterpret/f32 (get_local $0) ) @@ -10856,21 +10683,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.gt_s - (get_local $5) - (i32.const 2139095040) - ) - ) - (get_local $6) + (if (result i32) + (tee_local $13 (i32.gt_s - (get_local $10) + (get_local $5) (i32.const 2139095040) ) ) - (i32.const 1) + (get_local $13) + (i32.gt_s + (get_local $10) + (i32.const 2139095040) + ) ) (return (f32.add @@ -10881,7 +10705,7 @@ ) (if (i32.lt_s - (get_local $15) + (get_local $4) (i32.const 0) ) (if @@ -10889,7 +10713,7 @@ (get_local $10) (i32.const 1266679808) ) - (set_local $4 + (set_local $16 (i32.const 2) ) (if @@ -10900,12 +10724,12 @@ (if (i32.eq (i32.shl - (tee_local $7 + (tee_local $6 (i32.shr_s (get_local $10) (i32.sub (i32.const 23) - (tee_local $6 + (tee_local $8 (i32.sub (i32.shr_s (get_local $10) @@ -10919,16 +10743,16 @@ ) (i32.sub (i32.const 23) - (get_local $6) + (get_local $8) ) ) (get_local $10) ) - (set_local $4 + (set_local $16 (i32.sub (i32.const 2) (i32.and - (get_local $7) + (get_local $6) (i32.const 1) ) ) @@ -11018,7 +10842,7 @@ ) (if (i32.ge_s - (get_local $15) + (get_local $4) (i32.const 0) ) (return @@ -11034,32 +10858,26 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) - (tee_local $6 - (i32.and - (if (result i32) - (tee_local $6 - (i32.eq - (get_local $5) - (i32.const 2139095040) - ) - ) - (get_local $6) - (i32.eqz - (get_local $5) - ) - ) - (i32.const 1) + (tee_local $13 + (i32.eq + (get_local $5) + (i32.const 2139095040) ) ) - (get_local $6) - (i32.eq - (get_local $5) - (i32.const 1065353216) + (get_local $13) + (tee_local $13 + (i32.eqz + (get_local $5) + ) ) ) - (i32.const 1) + (get_local $13) + (i32.eq + (get_local $5) + (i32.const 1065353216) + ) ) (block (if @@ -11076,7 +10894,7 @@ ) (if (i32.lt_s - (get_local $15) + (get_local $4) (i32.const 0) ) (if @@ -11085,11 +10903,11 @@ (get_local $5) (i32.const 1065353216) ) - (get_local $4) + (get_local $16) ) (if (i32.eq - (get_local $4) + (get_local $16) (i32.const 1) ) (set_local $2 @@ -11122,13 +10940,13 @@ ) (if (i32.lt_s - (get_local $15) + (get_local $4) (i32.const 0) ) (block (if (i32.eqz - (get_local $4) + (get_local $16) ) (return (f32.div @@ -11145,7 +10963,7 @@ ) (if (i32.eq - (get_local $4) + (get_local $16) (i32.const 1) ) (set_local $9 @@ -11243,18 +11061,18 @@ ) ) ) - (set_local $8 + (set_local $7 (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 (f32.add - (tee_local $13 + (tee_local $14 (f32.mul (f32.const 1.44268798828125) (get_local $3) ) ) - (tee_local $14 + (tee_local $15 (f32.sub (f32.mul (get_local $3) @@ -11273,10 +11091,10 @@ ) ) (f32.sub - (get_local $14) + (get_local $15) (f32.sub - (get_local $8) - (get_local $13) + (get_local $7) + (get_local $14) ) ) ) @@ -11320,7 +11138,7 @@ ) (set_local $5 (i32.or - (tee_local $7 + (tee_local $6 (i32.and (get_local $5) (i32.const 8388607) @@ -11329,16 +11147,16 @@ (i32.const 1065353216) ) ) - (set_local $6 + (set_local $8 (if (result i32) (i32.le_s - (get_local $7) + (get_local $6) (i32.const 1885297) ) (i32.const 0) (if (result i32) (i32.lt_s - (get_local $7) + (get_local $6) (i32.const 6140887) ) (i32.const 1) @@ -11364,9 +11182,9 @@ (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 - (tee_local $16 + (tee_local $17 (f32.mul - (tee_local $13 + (tee_local $14 (f32.sub (tee_local $2 (f32.reinterpret/i32 @@ -11377,12 +11195,12 @@ (select (f32.const 1.5) (f32.const 1) - (get_local $6) + (get_local $8) ) ) ) ) - (tee_local $14 + (tee_local $15 (f32.div (f32.const 1) (f32.add @@ -11402,7 +11220,7 @@ (f32.sub (get_local $2) (f32.sub - (tee_local $8 + (tee_local $7 (f32.reinterpret/i32 (i32.add (i32.add @@ -11419,7 +11237,7 @@ (i32.const 4194304) ) (i32.shl - (get_local $6) + (get_local $8) (i32.const 21) ) ) @@ -11437,8 +11255,8 @@ (f32.mul (tee_local $12 (f32.mul - (get_local $16) - (get_local $16) + (get_local $17) + (get_local $17) ) ) (get_local $12) @@ -11478,13 +11296,13 @@ (f32.mul (tee_local $0 (f32.mul - (get_local $14) + (get_local $15) (f32.sub (f32.sub - (get_local $13) + (get_local $14) (f32.mul (get_local $3) - (get_local $8) + (get_local $7) ) ) (f32.mul @@ -11496,14 +11314,14 @@ ) (f32.add (get_local $3) - (get_local $16) + (get_local $17) ) ) ) ) (f32.sub (f32.sub - (tee_local $8 + (tee_local $7 (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 @@ -11530,14 +11348,14 @@ ) ) ) - (set_local $8 + (set_local $7 (f32.reinterpret/i32 (i32.and (i32.reinterpret/f32 (f32.add (f32.add (f32.add - (tee_local $16 + (tee_local $17 (f32.mul (f32.const 0.9619140625) (tee_local $0 @@ -11545,21 +11363,21 @@ (i32.and (i32.reinterpret/f32 (f32.add - (tee_local $13 + (tee_local $14 (f32.mul (get_local $3) - (get_local $8) + (get_local $7) ) ) - (tee_local $14 + (tee_local $15 (f32.add (f32.mul (get_local $0) - (get_local $8) + (get_local $7) ) (f32.mul (get_local $2) - (get_local $16) + (get_local $17) ) ) ) @@ -11580,10 +11398,10 @@ ) (f32.mul (f32.sub - (get_local $14) + (get_local $15) (f32.sub (get_local $0) - (get_local $13) + (get_local $14) ) ) (f32.const 0.9617967009544373) @@ -11592,7 +11410,7 @@ (select (f32.const 1.5632208487659227e-06) (f32.const 0) - (get_local $6) + (get_local $8) ) ) ) @@ -11601,7 +11419,7 @@ (select (f32.const 0.5849609375) (f32.const 0) - (get_local $6) + (get_local $8) ) ) ) @@ -11621,12 +11439,12 @@ (f32.sub (f32.sub (f32.sub - (get_local $8) + (get_local $7) (get_local $3) ) (get_local $0) ) - (get_local $16) + (get_local $17) ) ) ) @@ -11634,7 +11452,7 @@ ) (br_if $folding-inner1 (i32.gt_s - (tee_local $7 + (tee_local $6 (i32.reinterpret/f32 (tee_local $2 (f32.add @@ -11654,7 +11472,7 @@ ) ) ) - (get_local $8) + (get_local $7) ) (f32.mul (get_local $1) @@ -11665,7 +11483,7 @@ (tee_local $0 (f32.mul (get_local $0) - (get_local $8) + (get_local $7) ) ) ) @@ -11677,7 +11495,7 @@ ) (if (i32.eq - (get_local $7) + (get_local $6) (i32.const 1124073472) ) (br_if $folding-inner1 @@ -11695,7 +11513,7 @@ (if (i32.gt_s (i32.and - (get_local $7) + (get_local $6) (i32.const 2147483647) ) (i32.const 1125515264) @@ -11703,7 +11521,7 @@ (br $folding-inner0) (if (i32.eq - (get_local $7) + (get_local $6) (i32.const -1021968384) ) (br_if $folding-inner0 @@ -11718,12 +11536,12 @@ ) ) ) - (set_local $6 + (set_local $8 (i32.sub (i32.shr_s - (tee_local $15 + (tee_local $13 (i32.and - (get_local $7) + (get_local $6) (i32.const 2147483647) ) ) @@ -11737,21 +11555,21 @@ ) (if (i32.gt_s - (get_local $15) + (get_local $13) (i32.const 1056964608) ) (block - (set_local $6 + (set_local $8 (i32.sub (i32.shr_s (i32.and (tee_local $4 (i32.add - (get_local $7) + (get_local $6) (i32.shr_s (i32.const 8388608) (i32.add - (get_local $6) + (get_local $8) (i32.const 1) ) ) @@ -11771,7 +11589,7 @@ (i32.xor (i32.shr_s (i32.const 8388607) - (get_local $6) + (get_local $8) ) (i32.const -1) ) @@ -11789,13 +11607,13 @@ ) (i32.sub (i32.const 23) - (get_local $6) + (get_local $8) ) ) ) (if (i32.lt_s - (get_local $7) + (get_local $6) (i32.const 0) ) (set_local $4 @@ -11820,7 +11638,7 @@ (if (result f32) (i32.le_s (i32.shr_s - (tee_local $7 + (tee_local $6 (i32.add (i32.reinterpret/f32 (tee_local $2 @@ -11832,7 +11650,7 @@ (f32.mul (tee_local $2 (f32.add - (tee_local $13 + (tee_local $14 (f32.mul (tee_local $3 (f32.reinterpret/i32 @@ -11850,7 +11668,7 @@ (f32.const 0.693145751953125) ) ) - (tee_local $14 + (tee_local $15 (f32.add (f32.mul (f32.sub @@ -11870,7 +11688,7 @@ ) ) ) - (tee_local $8 + (tee_local $7 (f32.sub (get_local $2) (f32.mul @@ -11910,17 +11728,17 @@ ) ) (f32.sub - (get_local $8) + (get_local $7) (f32.const 2) ) ) (f32.add (tee_local $0 (f32.sub - (get_local $14) + (get_local $15) (f32.sub (get_local $2) - (get_local $13) + (get_local $14) ) ) ) @@ -11950,7 +11768,7 @@ (get_local $4) ) (f32.reinterpret/i32 - (get_local $7) + (get_local $6) ) ) ) @@ -12414,45 +12232,42 @@ ) (func $std/math/test_sign (; 141 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and - (if (result i32) - (tee_local $4 - (call $std/math/check - (select - (f64.copysign - (f64.const 1) + (if (result i32) + (tee_local $4 + (call $std/math/check + (select + (f64.copysign + (f64.const 1) + (get_local $0) + ) + (get_local $0) + (f64.gt + (f64.abs (get_local $0) ) - (get_local $0) - (f64.gt - (f64.abs - (get_local $0) - ) - (f64.const 0) - ) + (f64.const 0) ) - (get_local $1) - (get_local $2) - (get_local $3) ) + (get_local $1) + (get_local $2) + (get_local $3) ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.sign - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + ) + (if (result i32) + (tee_local $4 + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.sign + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $std/math/test_signf (; 142 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) @@ -12516,35 +12331,29 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $4 - (i32.and - (if (result i32) - (tee_local $4 - (i64.eq - (i64.shl - (get_local $7) - (i64.const 1) - ) - (i64.const 0) - ) - ) - (get_local $4) - (call $isNaN - (get_local $1) - ) + (i64.eq + (i64.shl + (get_local $7) + (i64.const 1) ) - (i32.const 1) + (i64.const 0) ) ) (get_local $4) - (i32.eq - (get_local $2) - (i32.const 2047) + (tee_local $4 + (call $isNaN + (get_local $1) + ) ) ) - (i32.const 1) + (get_local $4) + (i32.eq + (get_local $2) + (i32.const 2047) + ) ) (return (f64.div @@ -12880,28 +12689,38 @@ ) ) (if - (i32.and + (if (result i32) + (tee_local $4 + (i32.eq + (get_local $2) + (get_local $6) + ) + ) + (get_local $4) (if (result i32) (tee_local $4 (i32.eq - (get_local $2) + (i32.add + (get_local $2) + (i32.const 1) + ) (get_local $6) ) ) - (get_local $4) (if (result i32) (tee_local $4 - (i32.eq - (i32.add - (get_local $2) - (i32.const 1) + (f64.gt + (f64.mul + (f64.const 2) + (get_local $0) ) - (get_local $6) + (get_local $1) ) ) + (get_local $4) (if (result i32) (tee_local $4 - (f64.gt + (f64.eq (f64.mul (f64.const 2) (get_local $0) @@ -12909,28 +12728,15 @@ (get_local $1) ) ) - (get_local $4) - (if (result i32) - (tee_local $4 - (f64.eq - (f64.mul - (f64.const 2) - (get_local $0) - ) - (get_local $1) - ) - ) - (i32.and - (get_local $8) - (i32.const 1) - ) - (get_local $4) + (i32.and + (get_local $8) + (i32.const 1) ) + (get_local $4) ) - (get_local $4) ) + (get_local $4) ) - (i32.const 1) ) (set_local $0 (f64.sub @@ -12997,34 +12803,28 @@ (get_local $5) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $2 - (i32.and - (if (result i32) - (tee_local $2 - (i32.eqz - (i32.shl - (get_local $7) - (i32.const 1) - ) - ) - ) - (get_local $2) - (call $isNaN - (get_local $1) - ) + (i32.eqz + (i32.shl + (get_local $7) + (i32.const 1) ) - (i32.const 1) ) ) (get_local $2) - (i32.eq - (get_local $3) - (i32.const 255) + (tee_local $2 + (call $isNaN + (get_local $1) + ) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $3) + (i32.const 255) + ) ) (return (f32.div @@ -13339,28 +13139,38 @@ ) ) (if - (i32.and + (if (result i32) + (tee_local $2 + (i32.eq + (get_local $3) + (get_local $6) + ) + ) + (get_local $2) (if (result i32) (tee_local $2 (i32.eq - (get_local $3) + (i32.add + (get_local $3) + (i32.const 1) + ) (get_local $6) ) ) - (get_local $2) (if (result i32) (tee_local $2 - (i32.eq - (i32.add - (get_local $3) - (i32.const 1) + (f32.gt + (f32.mul + (f32.const 2) + (get_local $0) ) - (get_local $6) + (get_local $1) ) ) + (get_local $2) (if (result i32) (tee_local $2 - (f32.gt + (f32.eq (f32.mul (f32.const 2) (get_local $0) @@ -13368,28 +13178,15 @@ (get_local $1) ) ) - (get_local $2) - (if (result i32) - (tee_local $2 - (f32.eq - (f32.mul - (f32.const 2) - (get_local $0) - ) - (get_local $1) - ) - ) - (i32.and - (get_local $5) - (i32.const 1) - ) - (get_local $2) + (i32.and + (get_local $5) + (i32.const 1) ) + (get_local $2) ) - (get_local $2) ) + (get_local $2) ) - (i32.const 1) ) (set_local $0 (f32.sub @@ -13538,35 +13335,32 @@ ) (func $std/math/test_sinh (; 148 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.sinh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.sinh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.sinh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.sinh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.sinh (; 149 ;) (type $ff) (param $0 f32) (result f32) @@ -13689,35 +13483,32 @@ ) (func $std/math/test_sqrt (; 151 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (f64.sqrt + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (f64.sqrt - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.sqrt - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.sqrt + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $std/math/test_sqrtf (; 152 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) @@ -13855,35 +13646,32 @@ ) (func $std/math/test_tanh (; 154 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.tanh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.tanh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.tanh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.tanh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $~lib/math/NativeMathf.tanh (; 155 ;) (type $ff) (param $0 f32) (result f32) @@ -14011,35 +13799,32 @@ ) (func $std/math/test_trunc (; 157 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (f64.trunc + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (f64.trunc - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.const 0) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.trunc - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) + (i32.const 0) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.trunc + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) (func $std/math/test_truncf (; 158 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) @@ -44473,23 +44258,20 @@ (block (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (f64.ge - (tee_local $2 - (call $~lib/math/NativeMath.random) - ) - (f64.const 0) + (if (result i32) + (tee_local $1 + (f64.ge + (tee_local $2 + (call $~lib/math/NativeMath.random) ) + (f64.const 0) ) - (f64.lt - (get_local $2) - (f64.const 1) - ) - (get_local $1) ) - (i32.const 1) + (f64.lt + (get_local $2) + (f64.const 1) + ) + (get_local $1) ) ) (block @@ -44531,23 +44313,20 @@ (block (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (f32.ge - (tee_local $3 - (call $~lib/math/NativeMathf.random) - ) - (f32.const 0) + (if (result i32) + (tee_local $0 + (f32.ge + (tee_local $3 + (call $~lib/math/NativeMathf.random) ) + (f32.const 0) ) - (f32.lt - (get_local $3) - (f32.const 1) - ) - (get_local $0) ) - (i32.const 1) + (f32.lt + (get_local $3) + (f32.const 1) + ) + (get_local $0) ) ) (block diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index 57d3e9ed..a2092e14 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -275,19 +275,16 @@ (local $3 i32) (nop) (if - (i32.and - (if (result i32) - (tee_local $3 - (call $isNaN - (get_local $0) - ) - ) + (if (result i32) + (tee_local $3 (call $isNaN - (get_local $1) + (get_local $0) ) - (get_local $3) ) - (i32.const 1) + (call $isNaN + (get_local $1) + ) + (get_local $3) ) (return (f64.const 0) @@ -597,19 +594,16 @@ (local $3 i32) (nop) (if - (i32.and - (if (result i32) - (tee_local $3 - (call $isNaN - (get_local $0) - ) - ) + (if (result i32) + (tee_local $3 (call $isNaN - (get_local $1) + (get_local $0) ) - (get_local $3) ) - (i32.const 1) + (call $isNaN + (get_local $1) + ) + (get_local $3) ) (return (f32.const 0) @@ -760,41 +754,38 @@ (func $std/math/test_abs (; 47 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and - (if (result i32) - (tee_local $4 - (call $std/math/check - (block $~lib/math/NativeMath.abs|inlined.0 (result f64) - (br $~lib/math/NativeMath.abs|inlined.0 - (f64.abs - (get_local $0) - ) + (if (result i32) + (tee_local $4 + (call $std/math/check + (block $~lib/math/NativeMath.abs|inlined.0 (result f64) + (br $~lib/math/NativeMath.abs|inlined.0 + (f64.abs + (get_local $0) ) ) - (get_local $1) - (get_local $2) - (get_local $3) ) + (get_local $1) + (get_local $2) + (get_local $3) ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.abs - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + ) + (if (result i32) + (tee_local $4 + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.abs + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -1123,37 +1114,34 @@ (func $std/math/test_acos (; 51 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.acos + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.acos - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.acos - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.acos + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -1461,24 +1449,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.lt_u - (get_local $2) - (i32.const 1071284858) - ) - ) - (get_local $6) - (i32.and - (i32.shr_u - (get_local $2) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $6 + (i32.lt_u + (get_local $2) + (i32.const 1071284858) ) ) - (i32.const 1) + (get_local $6) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -1813,24 +1795,18 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_u - (get_local $2) - (i32.const 1048576) - ) - ) - (get_local $4) - (i32.and - (i32.shr_u - (get_local $2) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $4 + (i32.lt_u + (get_local $2) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $4) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -1901,24 +1877,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $4 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $1) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $4) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $1) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $4) ) (return (f64.const 0) @@ -2194,37 +2167,34 @@ (func $std/math/test_acosh (; 58 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.acosh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.acosh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.acosh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.acosh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -2261,24 +2231,18 @@ (i32.const 1) ) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.lt_u - (get_local $1) - (i32.const 1054086096) - ) - ) - (get_local $5) - (i32.and - (i32.shr_u - (get_local $1) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $5 + (i32.lt_u + (get_local $1) + (i32.const 1054086096) ) ) - (i32.const 1) + (get_local $5) + (i32.shr_u + (get_local $1) + (i32.const 31) + ) ) (block (if @@ -2562,24 +2526,18 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.lt_u - (get_local $1) - (i32.const 8388608) - ) - ) - (get_local $3) - (i32.and - (i32.shr_u - (get_local $1) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $3 + (i32.lt_u + (get_local $1) + (i32.const 8388608) ) ) - (i32.const 1) + (get_local $3) + (i32.shr_u + (get_local $1) + (i32.const 31) + ) ) (block (if @@ -2983,21 +2941,18 @@ ) (block (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_u - (get_local $2) - (i32.const 1045430272) - ) - ) - (i32.ge_u + (if (result i32) + (tee_local $4 + (i32.lt_u (get_local $2) - (i32.const 1048576) + (i32.const 1045430272) ) - (get_local $4) ) - (i32.const 1) + (i32.ge_u + (get_local $2) + (i32.const 1048576) + ) + (get_local $4) ) (return (get_local $0) @@ -3145,37 +3100,34 @@ (func $std/math/test_asin (; 64 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.asin + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.asin - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.asin - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.asin + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -3236,21 +3188,18 @@ ) (block (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.lt_u - (get_local $2) - (i32.const 964689920) - ) - ) - (i32.ge_u + (if (result i32) + (tee_local $3 + (i32.lt_u (get_local $2) - (i32.const 8388608) + (i32.const 964689920) ) - (get_local $3) ) - (i32.const 1) + (i32.ge_u + (get_local $2) + (i32.const 8388608) + ) + (get_local $3) ) (return (get_local $0) @@ -3479,37 +3428,34 @@ (func $std/math/test_asinh (; 68 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.asinh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.asinh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.asinh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.asinh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -4073,37 +4019,34 @@ (func $std/math/test_atan (; 72 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.atan + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.atan - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.atan - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.atan + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -4600,37 +4543,34 @@ (func $std/math/test_atanh (; 76 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.atanh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.atanh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.atanh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.atanh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -4760,19 +4700,16 @@ (local $9 f64) (nop) (if - (i32.and - (if (result i32) - (tee_local $2 - (call $isNaN - (get_local $1) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (call $isNaN - (get_local $0) + (get_local $1) ) ) - (i32.const 1) + (get_local $2) + (call $isNaN + (get_local $0) + ) ) (return (f64.add @@ -5085,27 +5022,24 @@ ) (nop) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.lt_u - (i32.add - (get_local $4) - (i32.shl - (i32.const 64) - (i32.const 20) - ) + (if (result i32) + (tee_local $2 + (i32.lt_u + (i32.add + (get_local $4) + (i32.shl + (i32.const 64) + (i32.const 20) ) - (get_local $6) ) - ) - (get_local $2) - (i32.eq (get_local $6) - (i32.const 2146435072) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $6) + (i32.const 2146435072) + ) ) (return (if (result f64) @@ -5232,39 +5166,36 @@ (func $std/math/test_atan2 (; 80 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) (return - (i32.and + (if (result i32) + (tee_local $5 + (call $std/math/check + (call $~lib/math/NativeMath.atan2 + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) + ) (if (result i32) (tee_local $5 - (call $std/math/check - (call $~lib/math/NativeMath.atan2 - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) - (if (result i32) - (tee_local $5 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $5) - (call $std/math/check - (call $~lib/math/JSMath.atan2 - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) + (i32.eqz + (i32.const 1) ) ) (get_local $5) + (call $std/math/check + (call $~lib/math/JSMath.atan2 + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) ) @@ -5276,19 +5207,16 @@ (local $6 f32) (nop) (if - (i32.and - (if (result i32) - (tee_local $2 - (call $isNaN - (get_local $1) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (call $isNaN - (get_local $0) + (get_local $1) ) ) - (i32.const 1) + (get_local $2) + (call $isNaN + (get_local $0) + ) ) (return (f32.add @@ -5562,27 +5490,24 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.lt_u - (i32.add - (get_local $3) - (i32.shl - (i32.const 26) - (i32.const 23) - ) + (if (result i32) + (tee_local $2 + (i32.lt_u + (i32.add + (get_local $3) + (i32.shl + (i32.const 26) + (i32.const 23) ) - (get_local $4) ) - ) - (get_local $2) - (i32.eq (get_local $4) - (i32.const 2139095040) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $4) + (i32.const 2139095040) + ) ) (return (if (result f32) @@ -5942,37 +5867,34 @@ (func $std/math/test_cbrt (; 84 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.cbrt + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.cbrt - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.cbrt - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.cbrt + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -6166,41 +6088,38 @@ (func $std/math/test_ceil (; 87 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and - (if (result i32) - (tee_local $4 - (call $std/math/check - (block $~lib/math/NativeMath.ceil|inlined.0 (result f64) - (br $~lib/math/NativeMath.ceil|inlined.0 - (f64.ceil - (get_local $0) - ) + (if (result i32) + (tee_local $4 + (call $std/math/check + (block $~lib/math/NativeMath.ceil|inlined.0 (result f64) + (br $~lib/math/NativeMath.ceil|inlined.0 + (f64.ceil + (get_local $0) ) ) - (get_local $1) - (get_local $2) - (get_local $3) ) + (get_local $1) + (get_local $2) + (get_local $3) ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.ceil - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + ) + (if (result i32) + (tee_local $4 + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.ceil + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -6601,21 +6520,18 @@ ) (nop) (if - (i32.and - (if (result i32) - (tee_local $15 - (i32.lt_s - (get_local $3) - (i32.const 0) - ) - ) - (get_local $15) - (i32.gt_s + (if (result i32) + (tee_local $15 + (i32.lt_s (get_local $3) - (i32.const 56) + (i32.const 0) ) ) - (i32.const 1) + (get_local $15) + (i32.gt_s + (get_local $3) + (i32.const 56) + ) ) (block (set_local $14 @@ -7093,37 +7009,34 @@ (func $std/math/test_cosh (; 93 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.cosh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.cosh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.cosh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.cosh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -7480,21 +7393,18 @@ ) (nop) (if - (i32.and - (if (result i32) - (tee_local $15 - (i32.lt_s - (get_local $6) - (i32.const 0) - ) - ) - (get_local $15) - (i32.gt_s + (if (result i32) + (tee_local $15 + (i32.lt_s (get_local $6) - (i32.const 56) + (i32.const 0) ) ) - (i32.const 1) + (get_local $15) + (i32.gt_s + (get_local $6) + (i32.const 56) + ) ) (block (set_local $14 @@ -7623,20 +7533,17 @@ ) (block (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.ge_u - (get_local $1) - (i32.const 1118925336) - ) + (if (result i32) + (tee_local $3 + (i32.ge_u + (get_local $1) + (i32.const 1118925336) ) - (i32.eqz - (get_local $2) - ) - (get_local $3) ) - (i32.const 1) + (i32.eqz + (get_local $2) + ) + (get_local $3) ) (block (set_local $0 @@ -7954,37 +7861,34 @@ (func $std/math/test_exp (; 99 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.exp + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.exp - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.exp - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.exp + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -8003,37 +7907,34 @@ (func $std/math/test_expm1 (; 101 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.expm1 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.expm1 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.expm1 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.expm1 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -8052,41 +7953,38 @@ (func $std/math/test_floor (; 103 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and - (if (result i32) - (tee_local $4 - (call $std/math/check - (block $~lib/math/NativeMath.floor|inlined.0 (result f64) - (br $~lib/math/NativeMath.floor|inlined.0 - (f64.floor - (get_local $0) - ) + (if (result i32) + (tee_local $4 + (call $std/math/check + (block $~lib/math/NativeMath.floor|inlined.0 (result f64) + (br $~lib/math/NativeMath.floor|inlined.0 + (f64.floor + (get_local $0) ) ) - (get_local $1) - (get_local $2) - (get_local $3) ) + (get_local $1) + (get_local $2) + (get_local $3) ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.floor - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + ) + (if (result i32) + (tee_local $4 + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.floor + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -8197,21 +8095,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.eq - (get_local $5) - (i32.const 2047) - ) - ) - (get_local $7) - (i64.eq - (get_local $3) - (i64.const 0) + (if (result i32) + (tee_local $7 + (i32.eq + (get_local $5) + (i32.const 2047) ) ) - (i32.const 1) + (get_local $7) + (i64.eq + (get_local $3) + (i64.const 0) + ) ) (return (get_local $0) @@ -8410,39 +8305,36 @@ (func $std/math/test_hypot (; 106 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) (return - (i32.and + (if (result i32) + (tee_local $5 + (call $std/math/check + (call $~lib/math/NativeMath.hypot + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) + ) (if (result i32) (tee_local $5 - (call $std/math/check - (call $~lib/math/NativeMath.hypot - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) - (if (result i32) - (tee_local $5 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $5) - (call $std/math/check - (call $~lib/math/JSMath.hypot - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) + (i32.eqz + (i32.const 1) ) ) (get_local $5) + (call $std/math/check + (call $~lib/math/JSMath.hypot + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) ) @@ -8515,42 +8407,36 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.ge_u - (get_local $2) - (i32.shl - (i32.const 255) - (i32.const 23) - ) - ) - ) - (get_local $5) - (i32.eq - (get_local $3) - (i32.const 0) + (if (result i32) + (tee_local $5 + (if (result i32) + (tee_local $5 + (i32.ge_u + (get_local $2) + (i32.shl + (i32.const 255) + (i32.const 23) ) ) - (i32.const 1) ) - ) - (get_local $5) - (i32.ge_u - (i32.sub - (get_local $2) + (get_local $5) + (i32.eq (get_local $3) - ) - (i32.shl - (i32.const 25) - (i32.const 23) + (i32.const 0) ) ) ) - (i32.const 1) + (get_local $5) + (i32.ge_u + (i32.sub + (get_local $2) + (get_local $3) + ) + (i32.shl + (i32.const 25) + (i32.const 23) + ) + ) ) (return (f32.add @@ -8664,37 +8550,34 @@ (func $std/math/test_log (; 109 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.log + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.log - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.log - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.log + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -8747,24 +8630,18 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_u - (get_local $2) - (i32.const 1048576) - ) - ) - (get_local $4) - (i32.and - (i32.shr_u - (get_local $2) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $4 + (i32.lt_u + (get_local $2) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $4) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -8835,24 +8712,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $4 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $1) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $4) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $1) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $4) ) (return (f64.const 0) @@ -9102,37 +8976,34 @@ (func $std/math/test_log10 (; 112 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.log10 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.log10 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.log10 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.log10 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -9161,24 +9032,18 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.lt_u - (get_local $1) - (i32.const 8388608) - ) - ) - (get_local $3) - (i32.and - (i32.shr_u - (get_local $1) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $3 + (i32.lt_u + (get_local $1) + (i32.const 8388608) ) ) - (i32.const 1) + (get_local $3) + (i32.shr_u + (get_local $1) + (i32.const 31) + ) ) (block (if @@ -9446,37 +9311,34 @@ (func $std/math/test_log1p (; 115 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.log1p + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.log1p - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.log1p - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.log1p + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -9528,24 +9390,18 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.lt_u - (get_local $2) - (i32.const 1048576) - ) - ) - (get_local $4) - (i32.and - (i32.shr_u - (get_local $2) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $4 + (i32.lt_u + (get_local $2) + (i32.const 1048576) ) ) - (i32.const 1) + (get_local $4) + (i32.shr_u + (get_local $2) + (i32.const 31) + ) ) (block (if @@ -9616,24 +9472,21 @@ (get_local $0) ) (if - (i32.and - (if (result i32) - (tee_local $4 - (i32.eq - (get_local $2) - (i32.const 1072693248) - ) + (if (result i32) + (tee_local $4 + (i32.eq + (get_local $2) + (i32.const 1072693248) ) - (i64.eq - (i64.shl - (get_local $1) - (i64.const 32) - ) - (i64.const 0) - ) - (get_local $4) ) - (i32.const 1) + (i64.eq + (i64.shl + (get_local $1) + (i64.const 32) + ) + (i64.const 0) + ) + (get_local $4) ) (return (f64.const 0) @@ -9871,37 +9724,34 @@ (func $std/math/test_log2 (; 118 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.log2 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.log2 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.log2 - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.log2 + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -9931,24 +9781,18 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.lt_u - (get_local $1) - (i32.const 8388608) - ) - ) - (get_local $3) - (i32.and - (i32.shr_u - (get_local $1) - (i32.const 31) - ) - (i32.const 1) + (if (result i32) + (tee_local $3 + (i32.lt_u + (get_local $1) + (i32.const 8388608) ) ) - (i32.const 1) + (get_local $3) + (i32.shr_u + (get_local $1) + (i32.const 31) + ) ) (block (if @@ -10207,43 +10051,40 @@ (func $std/math/test_max (; 121 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) (return - (i32.and - (if (result i32) - (tee_local $5 - (call $std/math/check - (block $~lib/math/NativeMath.max|inlined.0 (result f64) - (br $~lib/math/NativeMath.max|inlined.0 - (f64.max - (get_local $0) - (get_local $1) - ) + (if (result i32) + (tee_local $5 + (call $std/math/check + (block $~lib/math/NativeMath.max|inlined.0 (result f64) + (br $~lib/math/NativeMath.max|inlined.0 + (f64.max + (get_local $0) + (get_local $1) ) ) - (get_local $2) - (get_local $3) - (get_local $4) ) + (get_local $2) + (get_local $3) + (get_local $4) ) - (if (result i32) - (tee_local $5 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $5) - (call $std/math/check - (call $~lib/math/JSMath.max - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) + ) + (if (result i32) + (tee_local $5 + (i32.eqz + (i32.const 1) ) ) (get_local $5) + (call $std/math/check + (call $~lib/math/JSMath.max + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) ) @@ -10267,43 +10108,40 @@ (func $std/math/test_min (; 123 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) (return - (i32.and - (if (result i32) - (tee_local $5 - (call $std/math/check - (block $~lib/math/NativeMath.min|inlined.0 (result f64) - (br $~lib/math/NativeMath.min|inlined.0 - (f64.min - (get_local $0) - (get_local $1) - ) + (if (result i32) + (tee_local $5 + (call $std/math/check + (block $~lib/math/NativeMath.min|inlined.0 (result f64) + (br $~lib/math/NativeMath.min|inlined.0 + (f64.min + (get_local $0) + (get_local $1) ) ) - (get_local $2) - (get_local $3) - (get_local $4) ) + (get_local $2) + (get_local $3) + (get_local $4) ) - (if (result i32) - (tee_local $5 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $5) - (call $std/math/check - (call $~lib/math/JSMath.min - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) + ) + (if (result i32) + (tee_local $5 + (i32.eqz + (i32.const 1) ) ) (get_local $5) + (call $std/math/check + (call $~lib/math/JSMath.min + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) ) @@ -10373,35 +10211,29 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i64.eq - (i64.shl - (get_local $3) - (i64.const 1) - ) - (i64.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) + (if (result i32) + (tee_local $7 + (if (result i32) + (tee_local $7 + (i64.eq + (i64.shl + (get_local $3) + (i64.const 1) ) + (i64.const 0) ) - (i32.const 1) + ) + (get_local $7) + (call $isNaN + (get_local $1) ) ) - (get_local $7) - (i32.eq - (get_local $4) - (i32.const 2047) - ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $4) + (i32.const 2047) + ) ) (return (f64.div @@ -10778,39 +10610,36 @@ (func $std/math/test_mod (; 126 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) (return - (i32.and + (if (result i32) + (tee_local $5 + (call $std/math/check + (call $~lib/math/NativeMath.mod + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) + ) (if (result i32) (tee_local $5 - (call $std/math/check - (call $~lib/math/NativeMath.mod - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) - (if (result i32) - (tee_local $5 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $5) - (call $std/math/check - (call $std/math/JSOp.mod - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) + (i32.eqz + (i32.const 1) ) ) (get_local $5) + (call $std/math/check + (call $std/math/JSOp.mod + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) ) @@ -10857,35 +10686,29 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i32.eq - (i32.shl - (get_local $3) - (i32.const 1) - ) - (i32.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) + (if (result i32) + (tee_local $7 + (if (result i32) + (tee_local $7 + (i32.eq + (i32.shl + (get_local $3) + (i32.const 1) ) + (i32.const 0) ) - (i32.const 1) + ) + (get_local $7) + (call $isNaN + (get_local $1) ) ) - (get_local $7) - (i32.eq - (get_local $4) - (i32.const 255) - ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $4) + (i32.const 255) + ) ) (return (f32.div @@ -11361,63 +11184,54 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $9 - (i32.and + (if (result i32) + (tee_local $9 + (if (result i32) + (tee_local $9 (if (result i32) (tee_local $9 - (i32.and - (if (result i32) - (tee_local $9 - (i32.gt_s - (get_local $7) - (i32.const 2146435072) - ) - ) - (get_local $9) - (if (result i32) - (tee_local $9 - (i32.eq - (get_local $7) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $4) - (i32.const 0) - ) - (get_local $9) - ) - ) - (i32.const 1) + (i32.gt_s + (get_local $7) + (i32.const 2146435072) ) ) (get_local $9) - (i32.gt_s - (get_local $8) - (i32.const 2146435072) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $7) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $4) + (i32.const 0) + ) + (get_local $9) ) ) - (i32.const 1) - ) - ) - (get_local $9) - (if (result i32) - (tee_local $9 - (i32.eq - (get_local $8) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $6) - (i32.const 0) ) (get_local $9) + (i32.gt_s + (get_local $8) + (i32.const 2146435072) + ) ) ) - (i32.const 1) + (get_local $9) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $8) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $6) + (i32.const 0) + ) + (get_local $9) + ) ) (return (f64.add @@ -11657,33 +11471,27 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $15 - (i32.and - (if (result i32) - (tee_local $15 - (i32.eq - (get_local $7) - (i32.const 2146435072) - ) - ) - (get_local $15) - (i32.eq - (get_local $7) - (i32.const 0) - ) + (if (result i32) + (tee_local $15 + (if (result i32) + (tee_local $15 + (i32.eq + (get_local $7) + (i32.const 2146435072) ) - (i32.const 1) + ) + (get_local $15) + (i32.eq + (get_local $7) + (i32.const 0) ) ) - (get_local $15) - (i32.eq - (get_local $7) - (i32.const 1072693248) - ) ) - (i32.const 1) + (get_local $15) + (i32.eq + (get_local $7) + (i32.const 1072693248) + ) ) (block (set_local $14 @@ -12843,39 +12651,36 @@ (func $std/math/test_pow (; 130 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) (return - (i32.and + (if (result i32) + (tee_local $5 + (call $std/math/check + (call $~lib/math/NativeMath.pow + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) + ) (if (result i32) (tee_local $5 - (call $std/math/check - (call $~lib/math/NativeMath.pow - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) - ) - ) - (if (result i32) - (tee_local $5 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $5) - (call $std/math/check - (call $~lib/math/JSMath.pow - (get_local $0) - (get_local $1) - ) - (get_local $2) - (get_local $3) - (get_local $4) + (i32.eqz + (i32.const 1) ) ) (get_local $5) + (call $std/math/check + (call $~lib/math/JSMath.pow + (get_local $0) + (get_local $1) + ) + (get_local $2) + (get_local $3) + (get_local $4) + ) ) - (i32.const 1) + (get_local $5) ) ) ) @@ -12948,21 +12753,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.gt_s - (get_local $4) - (i32.const 2139095040) - ) - ) - (get_local $6) + (if (result i32) + (tee_local $6 (i32.gt_s - (get_local $5) + (get_local $4) (i32.const 2139095040) ) ) - (i32.const 1) + (get_local $6) + (i32.gt_s + (get_local $5) + (i32.const 2139095040) + ) ) (return (f32.add @@ -13134,33 +12936,27 @@ ) (nop) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.and - (if (result i32) - (tee_local $6 - (i32.eq - (get_local $4) - (i32.const 2139095040) - ) - ) - (get_local $6) - (i32.eq - (get_local $4) - (i32.const 0) - ) + (if (result i32) + (tee_local $6 + (if (result i32) + (tee_local $6 + (i32.eq + (get_local $4) + (i32.const 2139095040) ) - (i32.const 1) + ) + (get_local $6) + (i32.eq + (get_local $4) + (i32.const 0) ) ) - (get_local $6) - (i32.eq - (get_local $4) - (i32.const 1065353216) - ) ) - (i32.const 1) + (get_local $6) + (i32.eq + (get_local $4) + (i32.const 1065353216) + ) ) (block (set_local $11 @@ -14748,51 +14544,48 @@ (func $std/math/test_sign (; 141 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and - (if (result i32) - (tee_local $4 - (call $std/math/check - (block $~lib/math/NativeMath.sign|inlined.0 (result f64) - (br $~lib/math/NativeMath.sign|inlined.0 - (if (result f64) - (f64.gt - (f64.abs - (get_local $0) - ) - (f64.const 0) - ) - (f64.copysign - (f64.const 1) + (if (result i32) + (tee_local $4 + (call $std/math/check + (block $~lib/math/NativeMath.sign|inlined.0 (result f64) + (br $~lib/math/NativeMath.sign|inlined.0 + (if (result f64) + (f64.gt + (f64.abs (get_local $0) ) + (f64.const 0) + ) + (f64.copysign + (f64.const 1) (get_local $0) ) + (get_local $0) ) ) - (get_local $1) - (get_local $2) - (get_local $3) ) + (get_local $1) + (get_local $2) + (get_local $3) ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.sign - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + ) + (if (result i32) + (tee_local $4 + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.sign + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -14882,35 +14675,29 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $8 - (i32.and - (if (result i32) - (tee_local $8 - (i64.eq - (i64.shl - (get_local $3) - (i64.const 1) - ) - (i64.const 0) - ) - ) - (get_local $8) - (call $isNaN - (get_local $1) + (if (result i32) + (tee_local $8 + (if (result i32) + (tee_local $8 + (i64.eq + (i64.shl + (get_local $3) + (i64.const 1) ) + (i64.const 0) ) - (i32.const 1) + ) + (get_local $8) + (call $isNaN + (get_local $1) ) ) - (get_local $8) - (i32.eq - (get_local $4) - (i32.const 2047) - ) ) - (i32.const 1) + (get_local $8) + (i32.eq + (get_local $4) + (i32.const 2047) + ) ) (return (f64.div @@ -15317,28 +15104,38 @@ ) ) (if - (i32.and + (if (result i32) + (tee_local $8 + (i32.eq + (get_local $4) + (get_local $5) + ) + ) + (get_local $8) (if (result i32) (tee_local $8 (i32.eq - (get_local $4) + (i32.add + (get_local $4) + (i32.const 1) + ) (get_local $5) ) ) - (get_local $8) (if (result i32) (tee_local $8 - (i32.eq - (i32.add - (get_local $4) - (i32.const 1) + (f64.gt + (f64.mul + (f64.const 2) + (get_local $0) ) - (get_local $5) + (get_local $1) ) ) + (get_local $8) (if (result i32) (tee_local $8 - (f64.gt + (f64.eq (f64.mul (f64.const 2) (get_local $0) @@ -15346,31 +15143,15 @@ (get_local $1) ) ) - (get_local $8) - (if (result i32) - (tee_local $8 - (f64.eq - (f64.mul - (f64.const 2) - (get_local $0) - ) - (get_local $1) - ) - ) - (i32.and - (i32.and - (get_local $11) - (i32.const 1) - ) - (i32.const 1) - ) - (get_local $8) + (i32.and + (get_local $11) + (i32.const 1) ) + (get_local $8) ) - (get_local $8) ) + (get_local $8) ) - (i32.const 1) ) (block (set_local $0 @@ -15466,35 +15247,29 @@ (get_local $2) ) (if - (i32.and - (if (result i32) - (tee_local $10 - (i32.and - (if (result i32) - (tee_local $10 - (i32.eq - (i32.shl - (get_local $3) - (i32.const 1) - ) - (i32.const 0) - ) - ) - (get_local $10) - (call $isNaN - (get_local $1) + (if (result i32) + (tee_local $10 + (if (result i32) + (tee_local $10 + (i32.eq + (i32.shl + (get_local $3) + (i32.const 1) ) + (i32.const 0) ) - (i32.const 1) + ) + (get_local $10) + (call $isNaN + (get_local $1) ) ) - (get_local $10) - (i32.eq - (get_local $4) - (i32.const 255) - ) ) - (i32.const 1) + (get_local $10) + (i32.eq + (get_local $4) + (i32.const 255) + ) ) (return (f32.div @@ -15889,28 +15664,38 @@ ) ) (if - (i32.and + (if (result i32) + (tee_local $10 + (i32.eq + (get_local $4) + (get_local $5) + ) + ) + (get_local $10) (if (result i32) (tee_local $10 (i32.eq - (get_local $4) + (i32.add + (get_local $4) + (i32.const 1) + ) (get_local $5) ) ) - (get_local $10) (if (result i32) (tee_local $10 - (i32.eq - (i32.add - (get_local $4) - (i32.const 1) + (f32.gt + (f32.mul + (f32.const 2) + (get_local $0) ) - (get_local $5) + (get_local $1) ) ) + (get_local $10) (if (result i32) (tee_local $10 - (f32.gt + (f32.eq (f32.mul (f32.const 2) (get_local $0) @@ -15918,31 +15703,15 @@ (get_local $1) ) ) - (get_local $10) - (if (result i32) - (tee_local $10 - (f32.eq - (f32.mul - (f32.const 2) - (get_local $0) - ) - (get_local $1) - ) - ) - (i32.and - (i32.and - (get_local $11) - (i32.const 1) - ) - (i32.const 1) - ) - (get_local $10) + (i32.and + (get_local $11) + (i32.const 1) ) + (get_local $10) ) - (get_local $10) ) + (get_local $10) ) - (i32.const 1) ) (block (set_local $0 @@ -16120,37 +15889,34 @@ (func $std/math/test_sinh (; 148 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.sinh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.sinh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.sinh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.sinh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -16292,41 +16058,38 @@ (func $std/math/test_sqrt (; 151 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and - (if (result i32) - (tee_local $4 - (call $std/math/check - (block $~lib/math/NativeMath.sqrt|inlined.0 (result f64) - (br $~lib/math/NativeMath.sqrt|inlined.0 - (f64.sqrt - (get_local $0) - ) + (if (result i32) + (tee_local $4 + (call $std/math/check + (block $~lib/math/NativeMath.sqrt|inlined.0 (result f64) + (br $~lib/math/NativeMath.sqrt|inlined.0 + (f64.sqrt + (get_local $0) ) ) - (get_local $1) - (get_local $2) - (get_local $3) ) + (get_local $1) + (get_local $2) + (get_local $3) ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.sqrt - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + ) + (if (result i32) + (tee_local $4 + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.sqrt + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -16495,37 +16258,34 @@ (func $std/math/test_tanh (; 154 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and + (if (result i32) + (tee_local $4 + (call $std/math/check + (call $~lib/math/NativeMath.tanh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) + ) (if (result i32) (tee_local $4 - (call $std/math/check - (call $~lib/math/NativeMath.tanh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) - ) - ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.tanh - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.tanh + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -16679,41 +16439,38 @@ (func $std/math/test_trunc (; 157 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) (return - (i32.and - (if (result i32) - (tee_local $4 - (call $std/math/check - (block $~lib/math/NativeMath.trunc|inlined.0 (result f64) - (br $~lib/math/NativeMath.trunc|inlined.0 - (f64.trunc - (get_local $0) - ) + (if (result i32) + (tee_local $4 + (call $std/math/check + (block $~lib/math/NativeMath.trunc|inlined.0 (result f64) + (br $~lib/math/NativeMath.trunc|inlined.0 + (f64.trunc + (get_local $0) ) ) - (get_local $1) - (get_local $2) - (get_local $3) ) + (get_local $1) + (get_local $2) + (get_local $3) ) - (if (result i32) - (tee_local $4 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $4) - (call $std/math/check - (call $~lib/math/JSMath.trunc - (get_local $0) - ) - (get_local $1) - (get_local $2) - (get_local $3) + ) + (if (result i32) + (tee_local $4 + (i32.eqz + (i32.const 1) ) ) (get_local $4) + (call $std/math/check + (call $~lib/math/JSMath.trunc + (get_local $0) + ) + (get_local $1) + (get_local $2) + (get_local $3) + ) ) - (i32.const 1) + (get_local $4) ) ) ) @@ -47809,21 +47566,18 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $2 - (f64.ge - (get_local $1) - (f64.const 0) - ) - ) - (f64.lt + (if (result i32) + (tee_local $2 + (f64.ge (get_local $1) - (f64.const 1) + (f64.const 0) ) - (get_local $2) ) - (i32.const 1) + (f64.lt + (get_local $1) + (f64.const 1) + ) + (get_local $2) ) ) (block @@ -47877,21 +47631,18 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $5 - (f32.ge - (get_local $4) - (f32.const 0) - ) - ) - (f32.lt + (if (result i32) + (tee_local $5 + (f32.ge (get_local $4) - (f32.const 1) + (f32.const 0) ) - (get_local $5) ) - (i32.const 1) + (f32.lt + (get_local $4) + (f32.const 1) + ) + (get_local $5) ) ) (block diff --git a/tests/compiler/std/mod.optimized.wat b/tests/compiler/std/mod.optimized.wat index dde4a35f..95b275c2 100644 --- a/tests/compiler/std/mod.optimized.wat +++ b/tests/compiler/std/mod.optimized.wat @@ -60,35 +60,29 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i64.eq - (i64.shl - (get_local $5) - (i64.const 1) - ) - (i64.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) - ) + (i64.eq + (i64.shl + (get_local $5) + (i64.const 1) ) - (i32.const 1) + (i64.const 0) ) ) (get_local $7) - (i32.eq - (get_local $3) - (i32.const 2047) + (tee_local $7 + (call $isNaN + (get_local $1) + ) ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $3) + (i32.const 2047) + ) ) (return (f64.div @@ -425,33 +419,30 @@ ) (func $std/mod/test_fmod (; 5 ;) (type $FFFi) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) (local $3 i32) - (i32.and + (if (result i32) + (tee_local $3 + (call $std/mod/check + (call $~lib/math/NativeMath.mod + (get_local $0) + (get_local $1) + ) + (get_local $2) + ) + ) (if (result i32) (tee_local $3 - (call $std/mod/check - (call $~lib/math/NativeMath.mod - (get_local $0) - (get_local $1) - ) - (get_local $2) - ) - ) - (if (result i32) - (tee_local $3 - (i32.const 0) - ) - (get_local $3) - (call $std/mod/check - (call $std/mod/JSOp.mod - (get_local $0) - (get_local $1) - ) - (get_local $2) - ) + (i32.const 0) ) (get_local $3) + (call $std/mod/check + (call $std/mod/JSOp.mod + (get_local $0) + (get_local $1) + ) + (get_local $2) + ) ) - (i32.const 1) + (get_local $3) ) ) (func $isNaN (; 6 ;) (type $fi) (param $0 f32) (result i32) @@ -495,34 +486,28 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $3 - (i32.and - (if (result i32) - (tee_local $3 - (i32.eqz - (i32.shl - (get_local $5) - (i32.const 1) - ) - ) - ) - (get_local $3) - (call $isNaN - (get_local $1) - ) + (i32.eqz + (i32.shl + (get_local $5) + (i32.const 1) ) - (i32.const 1) ) ) (get_local $3) - (i32.eq - (get_local $4) - (i32.const 255) + (tee_local $3 + (call $isNaN + (get_local $1) + ) ) ) - (i32.const 1) + (get_local $3) + (i32.eq + (get_local $4) + (i32.const 255) + ) ) (return (f32.div diff --git a/tests/compiler/std/mod.untouched.wat b/tests/compiler/std/mod.untouched.wat index 546d86f1..c1bd6439 100644 --- a/tests/compiler/std/mod.untouched.wat +++ b/tests/compiler/std/mod.untouched.wat @@ -78,35 +78,29 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i64.eq - (i64.shl - (get_local $3) - (i64.const 1) - ) - (i64.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) + (if (result i32) + (tee_local $7 + (if (result i32) + (tee_local $7 + (i64.eq + (i64.shl + (get_local $3) + (i64.const 1) ) + (i64.const 0) ) - (i32.const 1) + ) + (get_local $7) + (call $isNaN + (get_local $1) ) ) - (get_local $7) - (i32.eq - (get_local $4) - (i32.const 2047) - ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $4) + (i32.const 2047) + ) ) (return (f64.div @@ -521,35 +515,32 @@ (func $std/mod/test_fmod (; 5 ;) (type $FFFi) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) (local $3 i32) (return - (i32.and + (if (result i32) + (tee_local $3 + (call $std/mod/check + (call $~lib/math/NativeMath.mod + (get_local $0) + (get_local $1) + ) + (get_local $2) + ) + ) (if (result i32) (tee_local $3 - (call $std/mod/check - (call $~lib/math/NativeMath.mod - (get_local $0) - (get_local $1) - ) - (get_local $2) - ) - ) - (if (result i32) - (tee_local $3 - (i32.eqz - (i32.const 1) - ) - ) - (get_local $3) - (call $std/mod/check - (call $std/mod/JSOp.mod - (get_local $0) - (get_local $1) - ) - (get_local $2) + (i32.eqz + (i32.const 1) ) ) (get_local $3) + (call $std/mod/check + (call $std/mod/JSOp.mod + (get_local $0) + (get_local $1) + ) + (get_local $2) + ) ) - (i32.const 1) + (get_local $3) ) ) ) @@ -604,35 +595,29 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $7 - (i32.and - (if (result i32) - (tee_local $7 - (i32.eq - (i32.shl - (get_local $3) - (i32.const 1) - ) - (i32.const 0) - ) - ) - (get_local $7) - (call $isNaN - (get_local $1) + (if (result i32) + (tee_local $7 + (if (result i32) + (tee_local $7 + (i32.eq + (i32.shl + (get_local $3) + (i32.const 1) ) + (i32.const 0) ) - (i32.const 1) + ) + (get_local $7) + (call $isNaN + (get_local $1) ) ) - (get_local $7) - (i32.eq - (get_local $4) - (i32.const 255) - ) ) - (i32.const 1) + (get_local $7) + (i32.eq + (get_local $4) + (i32.const 255) + ) ) (return (f32.div diff --git a/tests/compiler/std/operator-overloading.optimized.wat b/tests/compiler/std/operator-overloading.optimized.wat index 553cb52d..a5fb640a 100644 --- a/tests/compiler/std/operator-overloading.optimized.wat +++ b/tests/compiler/std/operator-overloading.optimized.wat @@ -471,63 +471,51 @@ ) ) (if - (i32.and + (if (result i32) (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.gt_s - (get_local $6) - (i32.const 2146435072) - ) - ) - (get_local $5) - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $6) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $7) - (i32.const 0) - ) - (get_local $5) - ) - ) - (i32.const 1) - ) - ) - (get_local $5) - (i32.gt_s - (get_local $10) - (i32.const 2146435072) - ) - ) - (i32.const 1) - ) - ) - (get_local $5) (if (result i32) (tee_local $5 - (i32.eq - (get_local $10) + (i32.gt_s + (get_local $6) (i32.const 2146435072) ) ) - (i32.ne - (get_local $4) - (i32.const 0) - ) (get_local $5) + (tee_local $5 + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $6) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $7) + (i32.const 0) + ) + (get_local $5) + ) + ) + ) + (get_local $5) + (tee_local $5 + (i32.gt_s + (get_local $10) + (i32.const 2146435072) + ) ) ) - (i32.const 1) + (get_local $5) + (if (result i32) + (tee_local $5 + (i32.eq + (get_local $10) + (i32.const 2146435072) + ) + ) + (get_local $4) + (get_local $5) + ) ) (return (f64.add @@ -749,32 +737,26 @@ (get_local $7) ) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $5 - (i32.and - (if (result i32) - (tee_local $5 - (i32.eq - (get_local $6) - (i32.const 2146435072) - ) - ) - (get_local $5) - (i32.eqz - (get_local $6) - ) - ) - (i32.const 1) + (i32.eq + (get_local $6) + (i32.const 2146435072) ) ) (get_local $5) - (i32.eq - (get_local $6) - (i32.const 1072693248) + (tee_local $5 + (i32.eqz + (get_local $6) + ) ) ) - (i32.const 1) + (get_local $5) + (i32.eq + (get_local $6) + (i32.const 1072693248) + ) ) (block (if @@ -1892,164 +1874,146 @@ ) (func $std/operator-overloading/Tester.equals (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.eq - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) (func $std/operator-overloading/Tester.notEquals (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) - (i32.and - (if (result i32) - (tee_local $2 - (i32.ne - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.ne - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.ne + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) (func $std/operator-overloading/Tester.greater (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) - (i32.and - (if (result i32) - (tee_local $2 - (i32.gt_s - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.gt_s - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.gt_s + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) (func $std/operator-overloading/Tester.greaterEquals (; 17 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) - (i32.and - (if (result i32) - (tee_local $2 - (i32.ge_s - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.ge_s - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.ge_s + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) (func $std/operator-overloading/Tester.less (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) - (i32.and - (if (result i32) - (tee_local $2 - (i32.lt_s - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.lt_s - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.lt_s + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) (func $std/operator-overloading/Tester.lessEquals (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) - (i32.and - (if (result i32) - (tee_local $2 - (i32.le_s - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.le_s - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.le_s + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) (func $start (; 20 ;) (type $v) @@ -2089,25 +2053,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/a) - ) - (i32.const 3) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/a) ) - (i32.const 5) + (i32.const 3) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/a) + ) + (i32.const 5) + ) + (get_local $0) ) ) (block @@ -2142,24 +2103,21 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eqz - (i32.load - (get_global $std/operator-overloading/s) - ) - ) - ) - (i32.eq - (i32.load offset=4 + (if (result i32) + (tee_local $0 + (i32.eqz + (i32.load (get_global $std/operator-overloading/s) ) - (i32.const 6) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/s) + ) + (i32.const 6) + ) + (get_local $0) ) ) (block @@ -2194,25 +2152,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/m) - ) - (i32.const 6) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/m) ) - (i32.const 10) + (i32.const 6) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/m) + ) + (i32.const 10) + ) + (get_local $0) ) ) (block @@ -2247,25 +2202,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/d) - ) - (i32.const 2) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/d) ) - (i32.const 5) + (i32.const 2) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/d) + ) + (i32.const 5) + ) + (get_local $0) ) ) (block @@ -2300,24 +2252,21 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/f) - ) - (i32.const 4) - ) - ) - (i32.eqz - (i32.load offset=4 + (if (result i32) + (tee_local $0 + (i32.eq + (i32.load (get_global $std/operator-overloading/f) ) + (i32.const 4) ) - (get_local $0) ) - (i32.const 1) + (i32.eqz + (i32.load offset=4 + (get_global $std/operator-overloading/f) + ) + ) + (get_local $0) ) ) (block @@ -2352,25 +2301,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/p) - ) - (i32.const 16) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/p) ) - (i32.const 243) + (i32.const 16) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/p) + ) + (i32.const 243) + ) + (get_local $0) ) ) (block @@ -2405,25 +2351,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/n) - ) - (i32.const 15) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/n) ) (i32.const 15) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/n) + ) + (i32.const 15) + ) + (get_local $0) ) ) (block @@ -2458,25 +2401,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/o) - ) - (i32.const 65535) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/o) ) - (i32.const 255) + (i32.const 65535) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/o) + ) + (i32.const 255) + ) + (get_local $0) ) ) (block @@ -2511,25 +2451,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/x) - ) - (i32.const 65535) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/x) ) - (i32.const 255) + (i32.const 65535) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/x) + ) + (i32.const 255) + ) + (get_local $0) ) ) (block @@ -2829,25 +2766,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/ais) - ) - (i32.const 3) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/ais) ) - (i32.const 5) + (i32.const 3) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/ais) + ) + (i32.const 5) + ) + (get_local $0) ) ) (block @@ -2901,25 +2835,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/aii) - ) - (i32.const 3) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/aii) ) - (i32.const 5) + (i32.const 3) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/aii) + ) + (i32.const 5) + ) + (get_local $0) ) ) (block diff --git a/tests/compiler/std/operator-overloading.untouched.wat b/tests/compiler/std/operator-overloading.untouched.wat index b5142e08..46970700 100644 --- a/tests/compiler/std/operator-overloading.untouched.wat +++ b/tests/compiler/std/operator-overloading.untouched.wat @@ -549,63 +549,54 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $9 - (i32.and + (if (result i32) + (tee_local $9 + (if (result i32) + (tee_local $9 (if (result i32) (tee_local $9 - (i32.and - (if (result i32) - (tee_local $9 - (i32.gt_s - (get_local $7) - (i32.const 2146435072) - ) - ) - (get_local $9) - (if (result i32) - (tee_local $9 - (i32.eq - (get_local $7) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $4) - (i32.const 0) - ) - (get_local $9) - ) - ) - (i32.const 1) + (i32.gt_s + (get_local $7) + (i32.const 2146435072) ) ) (get_local $9) - (i32.gt_s - (get_local $8) - (i32.const 2146435072) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $7) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $4) + (i32.const 0) + ) + (get_local $9) ) ) - (i32.const 1) - ) - ) - (get_local $9) - (if (result i32) - (tee_local $9 - (i32.eq - (get_local $8) - (i32.const 2146435072) - ) - ) - (i32.ne - (get_local $6) - (i32.const 0) ) (get_local $9) + (i32.gt_s + (get_local $8) + (i32.const 2146435072) + ) ) ) - (i32.const 1) + (get_local $9) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $8) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $6) + (i32.const 0) + ) + (get_local $9) + ) ) (return (f64.add @@ -845,33 +836,27 @@ (i32.const 0) ) (if - (i32.and - (if (result i32) - (tee_local $15 - (i32.and - (if (result i32) - (tee_local $15 - (i32.eq - (get_local $7) - (i32.const 2146435072) - ) - ) - (get_local $15) - (i32.eq - (get_local $7) - (i32.const 0) - ) + (if (result i32) + (tee_local $15 + (if (result i32) + (tee_local $15 + (i32.eq + (get_local $7) + (i32.const 2146435072) ) - (i32.const 1) + ) + (get_local $15) + (i32.eq + (get_local $7) + (i32.const 0) ) ) - (get_local $15) - (i32.eq - (get_local $7) - (i32.const 1072693248) - ) ) - (i32.const 1) + (get_local $15) + (i32.eq + (get_local $7) + (i32.const 1072693248) + ) ) (block (set_local $14 @@ -2135,174 +2120,156 @@ (func $std/operator-overloading/Tester.equals (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.eq - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) ) (func $std/operator-overloading/Tester.notEquals (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return - (i32.and - (if (result i32) - (tee_local $2 - (i32.ne - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.ne - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.ne + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) ) (func $std/operator-overloading/Tester.greater (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return - (i32.and - (if (result i32) - (tee_local $2 - (i32.gt_s - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.gt_s - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.gt_s + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) ) (func $std/operator-overloading/Tester.greaterEquals (; 17 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return - (i32.and - (if (result i32) - (tee_local $2 - (i32.ge_s - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.ge_s - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.ge_s + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) ) (func $std/operator-overloading/Tester.less (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return - (i32.and - (if (result i32) - (tee_local $2 - (i32.lt_s - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.lt_s - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.lt_s + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) ) (func $std/operator-overloading/Tester.lessEquals (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return - (i32.and - (if (result i32) - (tee_local $2 - (i32.le_s - (i32.load - (get_local $0) - ) - (i32.load - (get_local $1) - ) - ) - ) + (if (result i32) + (tee_local $2 (i32.le_s - (i32.load offset=4 + (i32.load (get_local $0) ) - (i32.load offset=4 + (i32.load (get_local $1) ) ) - (get_local $2) ) - (i32.const 1) + (i32.le_s + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + (get_local $2) ) ) ) @@ -2407,25 +2374,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/a) - ) - (i32.const 3) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/a) ) - (i32.const 5) + (i32.const 3) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/a) + ) + (i32.const 5) + ) + (get_local $0) ) ) (block @@ -2460,25 +2424,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/s) - ) - (i32.const 0) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/s) ) - (i32.const 6) + (i32.const 0) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/s) + ) + (i32.const 6) + ) + (get_local $0) ) ) (block @@ -2513,25 +2474,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/m) - ) - (i32.const 6) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/m) ) - (i32.const 10) + (i32.const 6) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/m) + ) + (i32.const 10) + ) + (get_local $0) ) ) (block @@ -2566,25 +2524,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/d) - ) - (i32.const 2) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/d) ) - (i32.const 5) + (i32.const 2) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/d) + ) + (i32.const 5) + ) + (get_local $0) ) ) (block @@ -2619,25 +2574,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/f) - ) - (i32.const 4) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/f) ) - (i32.const 0) + (i32.const 4) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/f) + ) + (i32.const 0) + ) + (get_local $0) ) ) (block @@ -2672,25 +2624,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/p) - ) - (i32.const 16) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/p) ) - (i32.const 243) + (i32.const 16) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/p) + ) + (i32.const 243) + ) + (get_local $0) ) ) (block @@ -2725,25 +2674,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/n) - ) - (i32.const 15) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/n) ) (i32.const 15) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/n) + ) + (i32.const 15) + ) + (get_local $0) ) ) (block @@ -2778,25 +2724,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/o) - ) - (i32.const 65535) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/o) ) - (i32.const 255) + (i32.const 65535) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/o) + ) + (i32.const 255) + ) + (get_local $0) ) ) (block @@ -2831,25 +2774,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (i32.load - (get_global $std/operator-overloading/x) - ) - (i32.const 65535) - ) - ) + (if (result i32) + (tee_local $0 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/x) ) - (i32.const 255) + (i32.const 65535) ) - (get_local $0) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/x) + ) + (i32.const 255) + ) + (get_local $0) ) ) (block @@ -3177,25 +3117,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (i32.load - (get_global $std/operator-overloading/ais) - ) - (i32.const 3) - ) - ) + (if (result i32) + (tee_local $2 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/ais) ) - (i32.const 5) + (i32.const 3) ) - (get_local $2) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/ais) + ) + (i32.const 5) + ) + (get_local $2) ) ) (block @@ -3255,25 +3192,22 @@ ) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $4 - (i32.eq - (i32.load - (get_global $std/operator-overloading/aii) - ) - (i32.const 3) - ) - ) + (if (result i32) + (tee_local $4 (i32.eq - (i32.load offset=4 + (i32.load (get_global $std/operator-overloading/aii) ) - (i32.const 5) + (i32.const 3) ) - (get_local $4) ) - (i32.const 1) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/aii) + ) + (i32.const 5) + ) + (get_local $4) ) ) (block diff --git a/tests/compiler/std/polyfills.optimized.wat b/tests/compiler/std/polyfills.optimized.wat index 3cfa9844..6106433f 100644 --- a/tests/compiler/std/polyfills.optimized.wat +++ b/tests/compiler/std/polyfills.optimized.wat @@ -13,18 +13,12 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (i32.const 1) - (i32.const 1) - ) - ) - (get_local $1) - (i32.const 0) + (if (result i32) + (tee_local $1 + (i32.const 1) ) - (i32.const 1) + (get_local $1) + (i32.const 0) ) ) (block @@ -38,31 +32,34 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $1 - (i32.const 1) - ) - (get_local $1) - (i32.const 0) + (if (result i32) + (tee_local $1 + (i32.const 1) ) - (i32.const 1) + (get_local $1) + (i32.const 0) ) (return (i32.or - (i32.and - (i32.shl - (get_local $0) + (i32.or + (i32.and + (i32.shl + (get_local $0) + (i32.const 8) + ) + (i32.const 65280) + ) + (i32.shr_u + (i32.and + (get_local $0) + (i32.const 65535) + ) (i32.const 8) ) - (i32.const 65280) ) (i32.and - (i32.shr_u - (get_local $0) - (i32.const 8) - ) - (i32.const 255) + (get_local $0) + (i32.const -65536) ) ) ) @@ -73,27 +70,18 @@ (local $1 i32) (if (i32.eqz - (i32.and + (if (result i32) (if (result i32) (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (i32.const 1) - (i32.const 1) - ) - ) - (get_local $1) - (i32.const 0) - ) - (i32.const 1) - ) + (i32.const 1) ) (get_local $1) - (i32.const 0) + (tee_local $1 + (i32.const 0) + ) ) - (i32.const 1) + (get_local $1) + (i32.const 0) ) ) (block @@ -114,18 +102,12 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (i32.const 1) - (i32.const 1) - ) - ) - (get_local $1) - (i32.const 0) + (if (result i32) + (tee_local $1 + (i32.const 1) ) - (i32.const 1) + (get_local $1) + (i32.const 0) ) ) (block @@ -139,38 +121,38 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $1 - (i32.const 1) - ) - (get_local $1) - (i32.const 0) + (if (result i32) + (tee_local $1 + (i32.const 1) ) - (i32.const 1) + (get_local $1) + (i32.const 0) ) (return - (i32.shr_s - (i32.shl - (i32.or - (i32.and + (i32.or + (i32.or + (i32.and + (i32.shl + (get_local $0) + (i32.const 8) + ) + (i32.const 65280) + ) + (i32.and + (i32.shr_s (i32.shl (get_local $0) - (i32.const 8) + (i32.const 16) ) - (i32.const -256) - ) - (i32.and - (i32.shr_s - (get_local $0) - (i32.const 8) - ) - (i32.const 255) + (i32.const 24) ) + (i32.const 255) ) - (i32.const 16) ) - (i32.const 16) + (i32.and + (get_local $0) + (i32.const -65536) + ) ) ) ) @@ -180,27 +162,18 @@ (local $1 i32) (if (i32.eqz - (i32.and + (if (result i32) (if (result i32) (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (i32.const 1) - (i32.const 1) - ) - ) - (get_local $1) - (i32.const 0) - ) - (i32.const 1) - ) + (i32.const 1) ) (get_local $1) - (i32.const 0) + (tee_local $1 + (i32.const 0) + ) ) - (i32.const 1) + (get_local $1) + (i32.const 0) ) ) (block @@ -221,27 +194,12 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (i32.const 0) - (i32.const 1) - ) - ) - (get_local $1) - (i32.const 1) - ) - (i32.const 1) - ) - ) - (get_local $1) - (i32.const 0) + (if (result i32) + (tee_local $1 + (i32.const 1) ) - (i32.const 1) + (get_local $1) + (i32.const 0) ) ) (block @@ -275,28 +233,7 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (i32.const 0) - (i32.const 1) - ) - ) - (get_local $1) - (i32.const 0) - ) - (i32.const 1) - ) - ) - (get_local $1) - (i32.const 1) - ) - (i32.const 1) - ) + (i32.const 1) ) (block (call $abort @@ -349,19 +286,7 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (i32.const 0) - (i32.const 1) - ) - ) - (get_local $1) - (i32.const 1) - ) - (i32.const 1) - ) + (i32.const 1) ) (block (call $abort @@ -373,61 +298,36 @@ (unreachable) ) ) - (if - (i32.and - (if (result i32) - (tee_local $1 - (i32.const 0) - ) - (get_local $1) - (i32.const 1) - ) - (i32.const 1) - ) - (return + (return + (i32.or (i32.or - (i32.or - (i32.and - (i32.shl - (get_local $0) - (i32.const 8) - ) - (i32.const 65280) - ) - (i32.and - (i32.shr_u - (get_local $0) - (i32.const 8) - ) - (i32.const 255) + (i32.and + (i32.shl + (get_local $0) + (i32.const 8) ) + (i32.const 65280) ) (i32.and - (get_local $0) - (i32.const -65536) + (i32.shr_u + (get_local $0) + (i32.const 8) + ) + (i32.const 255) ) ) + (i32.and + (get_local $0) + (i32.const -65536) + ) ) ) - (get_local $0) ) (func $~lib/polyfills/bswap16 (; 8 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (i32.const 0) - (i32.const 1) - ) - ) - (get_local $1) - (i32.const 1) - ) - (i32.const 1) - ) + (i32.const 1) ) (block (call $abort @@ -439,49 +339,39 @@ (unreachable) ) ) - (if - (i32.and - (if (result i32) - (tee_local $1 - (i32.const 0) - ) - (get_local $1) - (i32.const 1) - ) - (i32.const 1) - ) - (return + (return + (i32.or (i32.or - (i32.or - (i32.and - (i32.shl - (get_local $0) - (i32.const 8) - ) - (i32.const 65280) - ) - (i32.and - (i32.shr_s - (get_local $0) - (i32.const 8) - ) - (i32.const 255) + (i32.and + (i32.shl + (get_local $0) + (i32.const 8) ) + (i32.const 65280) ) (i32.and - (get_local $0) - (i32.const -65536) + (i32.shr_s + (get_local $0) + (i32.const 8) + ) + (i32.const 255) ) ) + (i32.and + (get_local $0) + (i32.const -65536) + ) ) ) - (get_local $0) ) (func $start (; 9 ;) (type $v) (if (i32.ne - (call $~lib/polyfills/bswap - (i32.const 43707) + (i32.and + (call $~lib/polyfills/bswap + (i32.const 43707) + ) + (i32.const 65535) ) (i32.const 48042) ) @@ -497,10 +387,13 @@ ) (if (i32.ne - (call $~lib/polyfills/bswap - (i32.const -21829) + (i32.and + (call $~lib/polyfills/bswap + (i32.const 43707) + ) + (i32.const 65535) ) - (i32.const -17494) + (i32.const 48042) ) (block (call $abort @@ -616,8 +509,11 @@ ) (if (i32.ne - (call $~lib/polyfills/bswap16 - (i32.const 43707) + (i32.and + (call $~lib/polyfills/bswap16 + (i32.const 43707) + ) + (i32.const 65535) ) (i32.const 48042) ) @@ -633,10 +529,13 @@ ) (if (i32.ne - (call $~lib/polyfills/bswap16 - (i32.const -21829) + (i32.and + (call $~lib/polyfills/bswap16 + (i32.const 43707) + ) + (i32.const 65535) ) - (i32.const -17494) + (i32.const 48042) ) (block (call $abort diff --git a/tests/compiler/std/polyfills.untouched.wat b/tests/compiler/std/polyfills.untouched.wat index d6f0b940..7c2f7e01 100644 --- a/tests/compiler/std/polyfills.untouched.wat +++ b/tests/compiler/std/polyfills.untouched.wat @@ -15,33 +15,27 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 2) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 2) - (i32.const 2) - ) + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 + (i32.eq + (i32.const 2) + (i32.const 1) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 2) + (i32.const 2) ) ) - (get_local $1) - (i32.eq - (i32.const 2) - (i32.const 4) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 2) + (i32.const 4) + ) ) ) (block @@ -55,52 +49,46 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 2) - (i32.const 2) - ) - ) - (get_local $1) + (if (result i32) + (tee_local $1 (i32.eq (i32.const 2) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 2) + (i32.const 4) + ) ) (return - (i32.and + (i32.or (i32.or - (i32.or - (i32.and - (i32.shl - (get_local $0) - (i32.const 8) - ) - (i32.const 65280) - ) - (i32.and - (i32.shr_u - (get_local $0) - (i32.const 8) - ) - (i32.const 255) + (i32.and + (i32.shl + (get_local $0) + (i32.const 8) ) + (i32.const 65280) ) (i32.and - (get_local $0) - (i32.and - (i32.wrap/i64 - (i64.const 4294901760) + (i32.shr_u + (i32.and + (get_local $0) + (i32.const 65535) ) - (i32.const 65535) + (i32.const 8) ) + (i32.const 255) + ) + ) + (i32.and + (get_local $0) + (i32.wrap/i64 + (i64.const 4294901760) ) ) - (i32.const 65535) ) ) ) @@ -112,45 +100,36 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 (if (result i32) (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 2) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 2) - (i32.const 2) - ) - ) + (i32.eq + (i32.const 2) (i32.const 1) ) ) (get_local $1) (i32.eq (i32.const 2) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 2) + (i32.const 4) ) ) - (get_local $1) - (i32.eq - (i32.const 2) - (i32.const 8) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 2) + (i32.const 8) + ) ) ) (block @@ -178,33 +157,27 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 2) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 2) - (i32.const 2) - ) + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 + (i32.eq + (i32.const 2) + (i32.const 1) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 2) + (i32.const 2) ) ) - (get_local $1) - (i32.eq - (i32.const 2) - (i32.const 4) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 2) + (i32.const 4) + ) ) ) (block @@ -218,64 +191,49 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 2) - (i32.const 2) - ) - ) - (get_local $1) + (if (result i32) + (tee_local $1 (i32.eq (i32.const 2) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 2) + (i32.const 4) + ) ) (return - (i32.shr_s - (i32.shl - (i32.or - (i32.or - (i32.and - (i32.shl - (get_local $0) - (i32.const 8) - ) - (i32.shr_s - (i32.shl - (i32.const 65280) - (i32.const 16) - ) - (i32.const 16) - ) - ) - (i32.and - (i32.shr_s - (get_local $0) - (i32.const 8) - ) - (i32.const 255) - ) - ) - (i32.and + (i32.or + (i32.or + (i32.and + (i32.shl (get_local $0) + (i32.const 8) + ) + (i32.const 65280) + ) + (i32.and + (i32.shr_s (i32.shr_s (i32.shl - (i32.wrap/i64 - (i64.const 4294901760) - ) + (get_local $0) (i32.const 16) ) (i32.const 16) ) + (i32.const 8) ) + (i32.const 255) + ) + ) + (i32.and + (get_local $0) + (i32.wrap/i64 + (i64.const 4294901760) ) - (i32.const 16) ) - (i32.const 16) ) ) ) @@ -287,45 +245,36 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 (if (result i32) (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 2) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 2) - (i32.const 2) - ) - ) + (i32.eq + (i32.const 2) (i32.const 1) ) ) (get_local $1) (i32.eq (i32.const 2) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 2) + (i32.const 4) ) ) - (get_local $1) - (i32.eq - (i32.const 2) - (i32.const 8) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 2) + (i32.const 8) + ) ) ) (block @@ -353,45 +302,36 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 (if (result i32) (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 4) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 2) - ) - ) + (i32.eq + (i32.const 4) (i32.const 1) ) ) (get_local $1) (i32.eq (i32.const 4) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 4) ) ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 8) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 8) + ) ) ) (block @@ -432,45 +372,36 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 (if (result i32) (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 4) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 2) - ) - ) + (i32.eq + (i32.const 4) (i32.const 1) ) ) (get_local $1) (i32.eq (i32.const 4) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 4) ) ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 8) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 8) + ) ) ) (block @@ -514,45 +445,36 @@ (local $4 i64) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 (if (result i32) (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 8) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 8) - (i32.const 2) - ) - ) + (i32.eq + (i32.const 8) (i32.const 1) ) ) (get_local $1) (i32.eq (i32.const 8) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 8) + (i32.const 4) ) ) - (get_local $1) - (i32.eq - (i32.const 8) - (i32.const 8) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 8) + (i32.const 8) + ) ) ) (block @@ -629,45 +551,36 @@ (local $4 i64) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 (if (result i32) (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 8) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 8) - (i32.const 2) - ) - ) + (i32.eq + (i32.const 8) (i32.const 1) ) ) (get_local $1) (i32.eq (i32.const 8) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 8) + (i32.const 4) ) ) - (get_local $1) - (i32.eq - (i32.const 8) - (i32.const 8) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 8) + (i32.const 8) + ) ) ) (block @@ -741,45 +654,36 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 (if (result i32) (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 4) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 2) - ) - ) + (i32.eq + (i32.const 4) (i32.const 1) ) ) (get_local $1) (i32.eq (i32.const 4) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 4) ) ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 8) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 8) + ) ) ) (block @@ -820,45 +724,36 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 (if (result i32) (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 4) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 2) - ) - ) + (i32.eq + (i32.const 4) (i32.const 1) ) ) (get_local $1) (i32.eq (i32.const 4) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 4) ) ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 8) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 8) + ) ) ) (block @@ -899,33 +794,27 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 4) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 2) - ) + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 + (i32.eq + (i32.const 4) + (i32.const 1) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 2) ) ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 4) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 4) + ) ) ) (block @@ -939,21 +828,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 4) - (i32.const 2) - ) - ) - (get_local $1) + (if (result i32) + (tee_local $1 (i32.eq (i32.const 4) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 4) + ) ) (return (i32.or @@ -988,33 +874,27 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 4) - (i32.const 1) - ) - ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 2) - ) + (if (result i32) + (tee_local $1 + (if (result i32) + (tee_local $1 + (i32.eq + (i32.const 4) + (i32.const 1) ) - (i32.const 1) + ) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 2) ) ) - (get_local $1) - (i32.eq - (i32.const 4) - (i32.const 4) - ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 4) + ) ) ) (block @@ -1028,21 +908,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $1 - (i32.eq - (i32.const 4) - (i32.const 2) - ) - ) - (get_local $1) + (if (result i32) + (tee_local $1 (i32.eq (i32.const 4) - (i32.const 4) + (i32.const 2) ) ) - (i32.const 1) + (get_local $1) + (i32.eq + (i32.const 4) + (i32.const 4) + ) ) (return (i32.or @@ -1077,8 +954,11 @@ (if (i32.eqz (i32.eq - (call $~lib/polyfills/bswap - (i32.const 43707) + (i32.and + (call $~lib/polyfills/bswap + (i32.const 43707) + ) + (i32.const 65535) ) (i32.const 48042) ) @@ -1096,14 +976,14 @@ (if (i32.eqz (i32.eq - (call $~lib/polyfills/bswap - (i32.shr_s - (i32.shl + (i32.shr_s + (i32.shl + (call $~lib/polyfills/bswap (i32.const 43707) - (i32.const 16) ) (i32.const 16) ) + (i32.const 16) ) (i32.shr_s (i32.shl @@ -1241,8 +1121,11 @@ (if (i32.eqz (i32.eq - (call $~lib/polyfills/bswap16 - (i32.const 43707) + (i32.and + (call $~lib/polyfills/bswap16 + (i32.const 43707) + ) + (i32.const 65535) ) (i32.const 48042) ) @@ -1260,14 +1143,14 @@ (if (i32.eqz (i32.eq - (call $~lib/polyfills/bswap16 - (i32.shr_s - (i32.shl + (i32.shr_s + (i32.shl + (call $~lib/polyfills/bswap16 (i32.const 43707) - (i32.const 16) ) (i32.const 16) ) + (i32.const 16) ) (i32.shr_s (i32.shl diff --git a/tests/compiler/std/set.optimized.wat b/tests/compiler/std/set.optimized.wat index e74846b3..f79a43fa 100644 --- a/tests/compiler/std/set.optimized.wat +++ b/tests/compiler/std/set.optimized.wat @@ -1695,27 +1695,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory diff --git a/tests/compiler/std/set.untouched.wat b/tests/compiler/std/set.untouched.wat index 99836340..37dc21c5 100644 --- a/tests/compiler/std/set.untouched.wat +++ b/tests/compiler/std/set.untouched.wat @@ -1950,27 +1950,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory diff --git a/tests/compiler/std/static-array.optimized.wat b/tests/compiler/std/static-array.optimized.wat index f22d8292..3ae1b5f0 100644 --- a/tests/compiler/std/static-array.optimized.wat +++ b/tests/compiler/std/static-array.optimized.wat @@ -185,7 +185,10 @@ ) (tee_local $1 (i32.mul - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) (i32.const 16843009) ) ) @@ -2110,27 +2113,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory diff --git a/tests/compiler/std/static-array.untouched.wat b/tests/compiler/std/static-array.untouched.wat index 1a6efd6d..f623a4e0 100644 --- a/tests/compiler/std/static-array.untouched.wat +++ b/tests/compiler/std/static-array.untouched.wat @@ -228,7 +228,10 @@ (i32.const -1) (i32.const 255) ) - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) ) ) (i32.store @@ -2405,27 +2408,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index aa20a079..37063f27 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -628,21 +628,18 @@ (if (get_local $1) (if - (i32.and - (if (result i32) - (tee_local $0 - (i32.lt_s - (get_local $1) - (i32.const 2) - ) - ) - (get_local $0) - (i32.gt_s + (if (result i32) + (tee_local $0 + (i32.lt_s (get_local $1) - (i32.const 36) + (i32.const 2) ) ) - (i32.const 1) + (get_local $0) + (i32.gt_s + (get_local $1) + (i32.const 36) + ) ) (return (f64.const nan:0x8000000000000) @@ -650,21 +647,18 @@ ) (set_local $1 (if (result i32) - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (get_local $2) - (i32.const 48) - ) + (if (result i32) + (tee_local $0 + (i32.eq + (get_local $2) + (i32.const 48) ) - (i32.gt_s - (get_local $4) - (i32.const 2) - ) - (get_local $0) ) - (i32.const 1) + (i32.gt_s + (get_local $4) + (i32.const 2) + ) + (get_local $0) ) (block $break|0 (result i32) (block $case6|0 @@ -791,67 +785,58 @@ (i32.ge_s (tee_local $2 (if (result i32) - (i32.and - (if (result i32) - (tee_local $0 - (i32.ge_s - (tee_local $2 - (i32.load16_u offset=4 - (get_local $3) - ) + (if (result i32) + (tee_local $0 + (i32.ge_s + (tee_local $2 + (i32.load16_u offset=4 + (get_local $3) ) - (i32.const 48) ) + (i32.const 48) ) - (i32.le_s - (get_local $2) - (i32.const 57) - ) - (get_local $0) ) - (i32.const 1) + (i32.le_s + (get_local $2) + (i32.const 57) + ) + (get_local $0) ) (i32.sub (get_local $2) (i32.const 48) ) (if (result i32) - (i32.and - (if (result i32) - (tee_local $0 - (i32.ge_s - (get_local $2) - (i32.const 65) - ) - ) - (i32.le_s + (if (result i32) + (tee_local $0 + (i32.ge_s (get_local $2) - (i32.const 90) + (i32.const 65) ) - (get_local $0) ) - (i32.const 1) + (i32.le_s + (get_local $2) + (i32.const 90) + ) + (get_local $0) ) (i32.sub (get_local $2) (i32.const 55) ) (if (result i32) - (i32.and - (if (result i32) - (tee_local $0 - (i32.ge_s - (get_local $2) - (i32.const 97) - ) - ) - (i32.le_s + (if (result i32) + (tee_local $0 + (i32.ge_s (get_local $2) - (i32.const 122) + (i32.const 97) ) - (get_local $0) ) - (i32.const 1) + (i32.le_s + (get_local $2) + (i32.const 122) + ) + (get_local $0) ) (i32.sub (get_local $2) @@ -1065,25 +1050,22 @@ ) (block (if - (i32.and - (if (result i32) - (tee_local $0 - (i32.eq - (tee_local $2 - (i32.load16_u offset=4 - (get_local $1) - ) - ) - (i32.const 69) - ) - ) - (get_local $0) + (if (result i32) + (tee_local $0 (i32.eq - (get_local $2) - (i32.const 101) + (tee_local $2 + (i32.load16_u offset=4 + (get_local $1) + ) + ) + (i32.const 69) ) ) - (i32.const 1) + (get_local $0) + (i32.eq + (get_local $2) + (i32.const 101) + ) ) (block (call $abort @@ -1268,21 +1250,18 @@ (local $1 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.gt_s - (get_local $0) - (i32.const 0) - ) - ) - (i32.le_s + (if (result i32) + (tee_local $1 + (i32.gt_s (get_local $0) - (i32.const 536870910) + (i32.const 0) ) - (get_local $1) ) - (i32.const 1) + (i32.le_s + (get_local $0) + (i32.const 536870910) + ) + (get_local $1) ) ) (block @@ -2897,27 +2876,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory @@ -3290,19 +3266,16 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eqz - (get_local $0) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (i32.eqz - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $2) + (i32.eqz + (get_local $1) + ) ) (return (i32.const 0) @@ -3352,31 +3325,25 @@ (local $2 i32) (local $3 i32) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $2 - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (get_local $1) - ) - ) - (get_local $2) - (i32.eqz - (get_local $0) - ) - ) - (i32.const 1) + (i32.eq + (get_local $0) + (get_local $1) ) ) (get_local $2) - (i32.eqz - (get_local $1) + (tee_local $2 + (i32.eqz + (get_local $0) + ) ) ) - (i32.const 1) + (get_local $2) + (i32.eqz + (get_local $1) + ) ) (return (i32.const 0) @@ -3445,19 +3412,16 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eqz - (get_local $0) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (i32.eqz - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $2) + (i32.eqz + (get_local $1) + ) ) (return (i32.const 0) @@ -3519,31 +3483,25 @@ (local $2 i32) (local $3 i32) (if - (i32.and + (if (result i32) (if (result i32) (tee_local $2 - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (get_local $1) - ) - ) - (get_local $2) - (i32.eqz - (get_local $0) - ) - ) - (i32.const 1) + (i32.eq + (get_local $0) + (get_local $1) ) ) (get_local $2) - (i32.eqz - (get_local $1) + (tee_local $2 + (i32.eqz + (get_local $0) + ) ) ) - (i32.const 1) + (get_local $2) + (i32.eqz + (get_local $1) + ) ) (return (i32.const 0) @@ -3612,19 +3570,16 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eqz - (get_local $0) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (i32.eqz - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $2) + (i32.eqz + (get_local $1) + ) ) (return (i32.const 0) @@ -3706,24 +3661,21 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - ) - (get_local $2) - (i32.gt_s - (i32.mul - (get_local $3) - (get_local $1) - ) - (i32.const 268435456) + (if (result i32) + (tee_local $2 + (i32.lt_s + (get_local $1) + (i32.const 0) ) ) - (i32.const 1) + (get_local $2) + (i32.gt_s + (i32.mul + (get_local $3) + (get_local $1) + ) + (i32.const 268435456) + ) ) (block (call $abort @@ -3736,19 +3688,16 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eqz - (get_local $1) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (i32.eqz - (get_local $3) + (get_local $1) ) ) - (i32.const 1) + (get_local $2) + (i32.eqz + (get_local $3) + ) ) (return (i32.const 332) diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index 3731c274..4e5dc1df 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -750,21 +750,18 @@ (get_local $1) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.eq - (get_local $4) - (i32.const 48) - ) + (if (result i32) + (tee_local $6 + (i32.eq + (get_local $4) + (i32.const 48) ) - (i32.gt_s - (get_local $2) - (i32.const 2) - ) - (get_local $6) ) - (i32.const 1) + (i32.gt_s + (get_local $2) + (i32.const 2) + ) + (get_local $6) ) (block $break|0 (block $case6|0 @@ -891,21 +888,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.lt_s - (get_local $1) - (i32.const 2) - ) - ) - (get_local $6) - (i32.gt_s + (if (result i32) + (tee_local $6 + (i32.lt_s (get_local $1) - (i32.const 36) + (i32.const 2) ) ) - (i32.const 1) + (get_local $6) + (i32.gt_s + (get_local $1) + (i32.const 36) + ) ) (return (f64.const nan:0x8000000000000) @@ -938,21 +932,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.ge_s - (get_local $4) - (i32.const 48) - ) - ) - (i32.le_s + (if (result i32) + (tee_local $6 + (i32.ge_s (get_local $4) - (i32.const 57) + (i32.const 48) ) - (get_local $6) ) - (i32.const 1) + (i32.le_s + (get_local $4) + (i32.const 57) + ) + (get_local $6) ) (set_local $4 (i32.sub @@ -961,21 +952,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.ge_s - (get_local $4) - (i32.const 65) - ) - ) - (i32.le_s + (if (result i32) + (tee_local $6 + (i32.ge_s (get_local $4) - (i32.const 90) + (i32.const 65) ) - (get_local $6) ) - (i32.const 1) + (i32.le_s + (get_local $4) + (i32.const 90) + ) + (get_local $6) ) (set_local $4 (i32.sub @@ -987,21 +975,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.ge_s - (get_local $4) - (i32.const 97) - ) - ) - (i32.le_s + (if (result i32) + (tee_local $6 + (i32.ge_s (get_local $4) - (i32.const 122) + (i32.const 97) ) - (get_local $6) ) - (i32.const 1) + (i32.le_s + (get_local $4) + (i32.const 122) + ) + (get_local $6) ) (set_local $4 (i32.sub @@ -1249,21 +1234,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $6 - (i32.eq - (get_local $3) - (i32.const 69) - ) - ) - (get_local $6) + (if (result i32) + (tee_local $6 (i32.eq (get_local $3) - (i32.const 101) + (i32.const 69) ) ) - (i32.const 1) + (get_local $6) + (i32.eq + (get_local $3) + (i32.const 101) + ) ) (if (i32.eqz @@ -1483,21 +1465,18 @@ (local $2 i32) (if (i32.eqz - (i32.and - (if (result i32) - (tee_local $1 - (i32.gt_s - (get_local $0) - (i32.const 0) - ) - ) - (i32.le_s + (if (result i32) + (tee_local $1 + (i32.gt_s (get_local $0) - (i32.const 536870910) + (i32.const 0) ) - (get_local $1) ) - (i32.const 1) + (i32.le_s + (get_local $0) + (i32.const 536870910) + ) + (get_local $1) ) ) (block @@ -3342,27 +3321,24 @@ (return) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.le_u - (i32.add - (get_local $1) - (get_local $2) - ) - (get_local $0) - ) - ) - (get_local $3) + (if (result i32) + (tee_local $3 (i32.le_u (i32.add - (get_local $0) + (get_local $1) (get_local $2) ) - (get_local $1) + (get_local $0) ) ) - (i32.const 1) + (get_local $3) + (i32.le_u + (i32.add + (get_local $0) + (get_local $2) + ) + (get_local $1) + ) ) (block (call $~lib/memory/copy_memory @@ -3783,21 +3759,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (i32.const 0) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (i32.eq - (get_local $1) + (get_local $0) (i32.const 0) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $1) + (i32.const 0) + ) ) (return (i32.const 0) @@ -3855,33 +3828,27 @@ (local $5 i32) (local $6 i32) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (get_local $1) - ) - ) - (get_local $2) - (i32.eq - (get_local $0) - (i32.const 0) - ) + (if (result i32) + (tee_local $2 + (if (result i32) + (tee_local $2 + (i32.eq + (get_local $0) + (get_local $1) ) - (i32.const 1) + ) + (get_local $2) + (i32.eq + (get_local $0) + (i32.const 0) ) ) - (get_local $2) - (i32.eq - (get_local $1) - (i32.const 0) - ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $1) + (i32.const 0) + ) ) (return (i32.const 0) @@ -3963,21 +3930,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (i32.const 0) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (i32.eq - (get_local $1) + (get_local $0) (i32.const 0) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $1) + (i32.const 0) + ) ) (return (i32.const 0) @@ -4052,33 +4016,27 @@ (local $5 i32) (local $6 i32) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (get_local $1) - ) - ) - (get_local $2) - (i32.eq - (get_local $0) - (i32.const 0) - ) + (if (result i32) + (tee_local $2 + (if (result i32) + (tee_local $2 + (i32.eq + (get_local $0) + (get_local $1) ) - (i32.const 1) + ) + (get_local $2) + (i32.eq + (get_local $0) + (i32.const 0) ) ) - (get_local $2) - (i32.eq - (get_local $1) - (i32.const 0) - ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $1) + (i32.const 0) + ) ) (return (i32.const 0) @@ -4160,21 +4118,18 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $2 - (i32.eq - (get_local $0) - (i32.const 0) - ) - ) - (get_local $2) + (if (result i32) + (tee_local $2 (i32.eq - (get_local $1) + (get_local $0) (i32.const 0) ) ) - (i32.const 1) + (get_local $2) + (i32.eq + (get_local $1) + (i32.const 0) + ) ) (return (i32.const 0) @@ -4271,27 +4226,24 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - ) - (get_local $3) - (i32.gt_s - (i32.mul - (get_local $2) - (get_local $1) - ) - (i32.shl - (i32.const 1) - (i32.const 28) - ) + (if (result i32) + (tee_local $3 + (i32.lt_s + (get_local $1) + (i32.const 0) + ) + ) + (get_local $3) + (i32.gt_s + (i32.mul + (get_local $2) + (get_local $1) + ) + (i32.shl + (i32.const 1) + (i32.const 28) ) ) - (i32.const 1) ) (block (call $abort @@ -4304,20 +4256,17 @@ ) ) (if - (i32.and - (if (result i32) - (tee_local $3 - (i32.eq - (get_local $1) - (i32.const 0) - ) - ) - (get_local $3) - (i32.eqz - (get_local $2) + (if (result i32) + (tee_local $3 + (i32.eq + (get_local $1) + (i32.const 0) ) ) - (i32.const 1) + (get_local $3) + (i32.eqz + (get_local $2) + ) ) (return (i32.const 332) diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index 7b2f149c..313cc83f 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -262,7 +262,10 @@ ) (tee_local $1 (i32.mul - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) (i32.const 16843009) ) ) @@ -1964,9 +1967,12 @@ (i32.const 256) ) (if - (call $~lib/internal/typedarray/TypedArray#__get - (get_global $std/typedarray/clampedArr) - (i32.const 0) + (i32.and + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 0) + ) + (i32.const 255) ) (block (call $abort @@ -1980,9 +1986,12 @@ ) (if (i32.ne - (call $~lib/internal/typedarray/TypedArray#__get - (get_global $std/typedarray/clampedArr) - (i32.const 1) + (i32.and + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 1) + ) + (i32.const 255) ) (i32.const 2) ) @@ -1998,9 +2007,12 @@ ) (if (i32.ne - (call $~lib/internal/typedarray/TypedArray#__get - (get_global $std/typedarray/clampedArr) - (i32.const 2) + (i32.and + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 2) + ) + (i32.const 255) ) (i32.const 255) ) diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index 4edfa8c3..6954d7f3 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -318,7 +318,10 @@ (i32.const -1) (i32.const 255) ) - (get_local $1) + (i32.and + (get_local $1) + (i32.const 255) + ) ) ) (i32.store @@ -3099,9 +3102,12 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#__get - (get_global $std/typedarray/clampedArr) - (i32.const 0) + (i32.and + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 0) + ) + (i32.const 255) ) (i32.const 0) ) @@ -3119,9 +3125,12 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#__get - (get_global $std/typedarray/clampedArr) - (i32.const 1) + (i32.and + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 1) + ) + (i32.const 255) ) (i32.const 2) ) @@ -3139,9 +3148,12 @@ (if (i32.eqz (i32.eq - (call $~lib/internal/typedarray/TypedArray#__get - (get_global $std/typedarray/clampedArr) - (i32.const 2) + (i32.and + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/clampedArr) + (i32.const 2) + ) + (i32.const 255) ) (i32.const 255) )