A little 'asinit' CLI tool for quickly setting up a project; Minor refactoring

This commit is contained in:
dcodeIO 2018-04-01 23:46:41 +02:00
parent 6ff69394f0
commit 59a22c1842
16 changed files with 481 additions and 328 deletions

1
.gitattributes vendored
View File

@ -1,4 +1,5 @@
bin/asc text eol=lf
bin/asinit text eol=lf
dist/asc.js -diff
dist/assemblyscript.js -diff
scripts/check-pr.sh eol=lf

View File

@ -13,7 +13,7 @@
const fs = require("fs");
const path = require("path");
const utf8 = require("./util/utf8");
const utf8 = require("@protobufjs/utf8");
const EOL = process.platform === "win32" ? "\r\n" : "\n";
// Use distribution files if present, otherwise run the sources directly

235
bin/asinit Normal file
View File

@ -0,0 +1,235 @@
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const chalk = require("chalk");
const version = require("../package.json").version;
if (process.argv.length < 3) printHelp();
function printHelp() {
console.log([
"Version " + version,
"Syntax: " + chalk.cyan("asinit") + " [project directory]",
"",
chalk.white.bold("Sets up a new AssemblyScript project or updates an existing one."),
"",
"For example, to create a new project in the current directory:",
"",
" " + chalk.cyan("asinit") + " .",
].join("\n"));
process.exit(0);
}
const rl = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});
const projectDir = path.resolve(process.argv[2]);
const compilerDir = path.join(__dirname, "..");
const compilerVersion = require(path.join(compilerDir, "package.json")).version;
const assemblyDir = path.join(projectDir, "assembly");
const tsconfigFile = path.join(assemblyDir, "tsconfig.json");
const definitionsFile = path.relative(assemblyDir, path.join(compilerDir, "std", "assembly.d.ts"));
const entryFile = path.join(assemblyDir, "index.ts");
const buildDir = path.join(projectDir, "build");
const gitignoreFile = path.join(buildDir, ".gitignore");
const packageFile = path.join(projectDir, "package.json");
console.log([
"Version: " + version,
"",
chalk.white.bold([
"This command will make sure that the following files exist in the project",
"directory '" + projectDir + "':"
].join("\n")),
"",
chalk.cyan(" ./assembly"),
" Directory holding the AssemblyScript sources being compiled to WebAssembly.",
"",
chalk.cyan(" ./assembly/tsconfig.json"),
" TypeScript configuration inheriting recommended AssemblyScript settings.",
"",
chalk.cyan(" ./assembly/index.ts"),
" Exemplary entry file being compiled to WebAssembly to get you started.",
"",
chalk.cyan(" ./build"),
" Build artifact directory where compiled WebAssembly files are stored.",
"",
chalk.cyan(" ./build/.gitignore"),
" Git configuration that excludes compiled binaries from source control.",
"",
chalk.cyan(" ./package.json"),
" Package info containing the necessary commands to compile to WebAssembly.",
"",
"The command will try to update existing files to match the correct settings",
"for this instance of the compiler in '" + compilerDir + "'.",
""
].join("\n"));
rl.question(chalk.white.bold("Do you want to proceed?") + " [Y/n] ", answer => {
if (!/^y?$/i.test(answer)) {
process.exit(1);
return;
}
console.log();
ensureProjectDirectory();
ensureAssemblyDirectory();
ensureTsconfigJson();
ensureEntryFile();
ensureBuildDirectory();
ensureGitignore();
ensurePackageJson();
console.log([
chalk.green("Done!"),
"",
"To edit the entry file, open '" + chalk.cyan("assembly/index.ts") + "' in your editor of choice.",
"Create as many additional files as necessary and use them as imports.",
"",
"To build the entry file to WebAssembly when you are ready, run:",
"",
chalk.white.bold(" npm run asbuild"),
"",
"Running the command above creates the following binaries incl. their respective",
"text format representations and source maps:",
"",
chalk.cyan(" ./build/untouched.wasm"),
chalk.cyan(" ./build/untouched.wasm.map"),
chalk.cyan(" ./build/untouched.wat"),
"",
" ^ The untouched WebAssembly module as generated by the compiler.",
" This one matches your sources exactly, without any optimizations.",
"",
chalk.cyan(" ./build/optimized.wasm"),
chalk.cyan(" ./build/optimized.wasm.map"),
chalk.cyan(" ./build/optimized.wat"),
"",
" ^ The optimized WebAssembly module using default optimization settings (-O2s).",
" You can change the optimization settings in '" + chalk.cyan("package.json")+ "'.",
"",
chalk.white.bold("Additional documentation is available at the AssemblyScript wiki:"),
"",
" https://github.com/AssemblyScript/assemblyscript/wiki",
"",
"Have a nice day!"
].join("\n"));
rl.close();
});
function ensureProjectDirectory() {
console.log("- Making sure that the project directory exists...");
if (!fs.existsSync(projectDir)) {
fs.mkdirSync(projectDir);
console.log(chalk.green(" Created: ") + projectDir);
} else {
console.log(chalk.yellow(" Exists: ") + projectDir);
}
console.log();
}
function ensureAssemblyDirectory() {
console.log("- Making sure that the 'assembly' directory exists...");
if (!fs.existsSync(assemblyDir)) {
fs.mkdirSync(assemblyDir);
console.log(chalk.green(" Created: ") + assemblyDir);
} else {
console.log(chalk.yellow(" Exists: ") + assemblyDir);
}
console.log();
}
function ensureTsconfigJson() {
console.log("- Making sure that 'assembly/tsconfig.json' is set up...");
const definitionsPath = definitionsFile.replace(/\\/g, "/");
if (!fs.existsSync(tsconfigFile)) {
fs.writeFileSync(tsconfigFile, JSON.stringify({
"extends": definitionsPath,
"include": [
"./**/*.ts"
]
}, null, 2));
console.log(chalk.green(" Created: ") + tsconfigFile);
} else {
let tsconfig = JSON.parse(fs.readFileSync(tsconfigFile, "utf8"));
tsconfig["extends"] = definitionsPath;
fs.writeFileSync(tsconfigFile, JSON.stringify(tsconfig, null, 2));
console.log(chalk.green(" Updated: ") + tsconfigFile);
}
console.log();
}
function ensureEntryFile() {
console.log("- Making sure that 'assembly/index.ts' exists...");
if (!fs.existsSync(entryFile)) {
fs.writeFileSync(entryFile, [
"// The entry file of your WebAssembly module.",
"",
"export function add(a: i32, b: i32): i32 {",
" return a + b;",
"}"
].join("\n") + "\n");
console.log(chalk.green(" Created: ") + entryFile);
} else {
console.log(chalk.yellow(" Exists: ") + entryFile);
}
console.log();
}
function ensureBuildDirectory() {
console.log("- Making sure that the 'build' directory exists...");
if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir);
console.log(chalk.green(" Created: ") + buildDir);
} else {
console.log(chalk.yellow(" Exists: ") + buildDir);
}
console.log();
}
function ensureGitignore() {
console.log("- Making sure that 'build/.gitignore' is set up...");
if (!fs.existsSync(gitignoreFile)) {
fs.writeFileSync(gitignoreFile, [
"*.wasm",
"*.asm.js"
].join("\n") + "\n");
console.log(chalk.green(" Created: ") + gitignoreFile);
} else {
console.log(chalk.yellow(" Exists: ") + gitignoreFile);
}
console.log();
}
function ensurePackageJson() {
console.log("- Making sure that 'package.json' contains the build commands...")
const entryPath = path.relative(projectDir, entryFile).replace(/\\/g, "/");
const buildUntouched = "asc " + entryPath + " -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate";
const buildOptimized = "asc " + entryPath + " -b build/optimized.wasm -t build/optimized.wat --sourceMap --validate --optimize --noDebug";
const buildAll = "npm run asbuild:untouched && npm run asbuild:optimized";
if (!fs.existsSync(packageFile)) {
fs.writeFileSync(packageFile, JSON.stringify({
"scripts": {
"asbuild:untouched": buildUntouched,
"asbuild:optimized": buildOptimized,
"asbuild": buildAll
}
}, null, 2));
console.log(chalk.green(" Created: ") + packageFile);
} else {
let pkg = JSON.parse(fs.readFileSync(packageFile));
let scripts = pkg["scripts"];
if (!scripts) scripts = {};
if (!scripts["asbuild"]) {
scripts["asbuild:untouched"] = buildUntouched;
scripts["asbuild:optimized"] = buildOptimized;
scripts["asbuild"] = buildAll;
pkg["scripts"] = scripts;
fs.writeFileSync(packageFile, JSON.stringify(pkg, null, 2));
console.log(chalk.green(" Updated: ") + packageFile);
} else {
console.log(chalk.yellow(" Exists: ") + packageFile);
}
}
console.log();
}

View File

@ -1,78 +0,0 @@
// see: https://github.com/dcodeIO/protobuf.js/tree/master/lib/utf8
exports.length = function utf8_length(string) {
var len = 0,
c = 0;
for (var i = 0; i < string.length; ++i) {
c = string.charCodeAt(i);
if (c < 128) {
len += 1;
} else if (c < 2048) {
len += 2;
} else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
++i;
len += 4;
} else {
len += 3;
}
}
return len;
};
exports.read = function utf8_read(buffer, start, end) {
var len = end - start;
if (len < 1)
return "";
var parts = null,
chunk = [],
i = 0, t;
while (start < end) {
t = buffer[start++];
if (t < 128) {
chunk[i++] = t;
} else if (t > 191 && t < 224) {
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
} else if (t > 239 && t < 365) {
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
chunk[i++] = 0xD800 + (t >> 10);
chunk[i++] = 0xDC00 + (t & 1023);
} else {
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
}
if (i > 8191) {
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
i = 0;
}
}
if (parts) {
if (i) parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
return parts.join("");
}
return String.fromCharCode.apply(String, chunk.slice(0, i));
};
exports.write = function utf8_write(string, buffer, offset) {
var start = offset,
c1, c2;
for (var i = 0; i < string.length; ++i) {
c1 = string.charCodeAt(i);
if (c1 < 128) {
buffer[offset++] = c1;
} else if (c1 < 2048) {
buffer[offset++] = c1 >> 6 | 192;
buffer[offset++] = c1 & 63 | 128;
} else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
++i;
buffer[offset++] = c1 >> 18 | 240;
buffer[offset++] = c1 >> 12 & 63 | 128;
buffer[offset++] = c1 >> 6 & 63 | 128;
buffer[offset++] = c1 & 63 | 128;
} else {
buffer[offset++] = c1 >> 12 | 224;
buffer[offset++] = c1 >> 6 & 63 | 128;
buffer[offset++] = c1 & 63 | 128;
}
}
return offset - start;
};

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

5
package-lock.json generated
View File

@ -4,6 +4,11 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@protobufjs/utf8": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz",
"integrity": "sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA="
},
"@sindresorhus/is": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.7.0.tgz",

View File

@ -11,6 +11,7 @@
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
},
"dependencies": {
"@protobufjs/utf8": "^1.1.0",
"binaryen": "45.0.0-nightly.20180330",
"glob": "^7.1.2",
"long": "^4.0.0",
@ -34,7 +35,8 @@
"main": "index.js",
"types": "index.d.ts",
"bin": {
"asc": "bin/asc"
"asc": "bin/asc",
"asinit": "bin/asinit"
},
"engines": {
"node": ">=8"

View File

@ -43,7 +43,6 @@ import {
Global,
FunctionPrototype,
Class,
ClassPrototype,
Field
} from "./program";

View File

@ -69,6 +69,44 @@ import {
// TODO: sin, cos, tan
function R(z: f64): f64 { // Rational approximation of (asin(x)-x)/x^3
const // see: musl/src/math/asin.c and SUN COPYRIGHT NOTICE above
pS0 = reinterpret<f64>(0x3FC5555555555555), // 1.66666666666666657415e-01
pS1 = reinterpret<f64>(0xBFD4D61203EB6F7D), // -3.25565818622400915405e-01
pS2 = reinterpret<f64>(0x3FC9C1550E884455), // 2.01212532134862925881e-01
pS3 = reinterpret<f64>(0xBFA48228B5688F3B), // -4.00555345006794114027e-02
pS4 = reinterpret<f64>(0x3F49EFE07501B288), // 7.91534994289814532176e-04
pS5 = reinterpret<f64>(0x3F023DE10DFDF709), // 3.47933107596021167570e-05
qS1 = reinterpret<f64>(0xC0033A271C8A2D4B), // -2.40339491173441421878e+00
qS2 = reinterpret<f64>(0x40002AE59C598AC8), // 2.02094576023350569471e+00
qS3 = reinterpret<f64>(0xBFE6066C1B8D0159), // -6.88283971605453293030e-01
qS4 = reinterpret<f64>(0x3FB3B8C5B12E9282); // 7.70381505559019352791e-02
var p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
var q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
return p / q;
}
function expo2(x: f64): f64 { // exp(x)/2 for x >= log(DBL_MAX)
const // see: musl/src/math/__expo2.c
k = <u32>2043,
kln2 = reinterpret<f64>(0x40962066151ADD8B); // 0x1.62066151add8bp+10
var scale = reinterpret<f64>(<u64>((<u32>0x3FF + k / 2) << 20) << 32);
return NativeMath.exp(x - kln2) * scale * scale;
}
var random_seeded = false;
var random_state0: u64;
var random_state1: u64;
function murmurHash3(h: u64): u64 { // Force all bits of a hash block to avalanche
h ^= h >> 33; // see: https://github.com/aappleby/smhasher
h *= 0xFF51AFD7ED558CCD;
h ^= h >> 33;
h *= 0xC4CEB9FE1A85EC53;
h ^= h >> 33;
return h;
}
export namespace NativeMath {
export const E = reinterpret<f64>(0x4005BF0A8B145769); // 2.7182818284590452354
@ -84,23 +122,6 @@ export namespace NativeMath {
return builtin_abs<f64>(x);
}
function __R(z: f64): f64 { // see: musl/src/math/acos.c and SUN COPYRIGHT NOTICE above
const
pS0 = reinterpret<f64>(0x3FC5555555555555), // 1.66666666666666657415e-01
pS1 = reinterpret<f64>(0xBFD4D61203EB6F7D), // -3.25565818622400915405e-01
pS2 = reinterpret<f64>(0x3FC9C1550E884455), // 2.01212532134862925881e-01
pS3 = reinterpret<f64>(0xBFA48228B5688F3B), // -4.00555345006794114027e-02
pS4 = reinterpret<f64>(0x3F49EFE07501B288), // 7.91534994289814532176e-04
pS5 = reinterpret<f64>(0x3F023DE10DFDF709), // 3.47933107596021167570e-05
qS1 = reinterpret<f64>(0xC0033A271C8A2D4B), // -2.40339491173441421878e+00
qS2 = reinterpret<f64>(0x40002AE59C598AC8), // 2.02094576023350569471e+00
qS3 = reinterpret<f64>(0xBFE6066C1B8D0159), // -6.88283971605453293030e-01
qS4 = reinterpret<f64>(0x3FB3B8C5B12E9282); // 7.70381505559019352791e-02
var p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
var q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
return p / q;
}
export function acos(x: f64): f64 { // see: musl/src/math/acos.c and SUN COPYRIGHT NOTICE above
const
pio2_hi = reinterpret<f64>(0x3FF921FB54442D18), // 1.57079632679489655800e+00
@ -118,20 +139,20 @@ export namespace NativeMath {
}
if (ix < 0x3FE00000) {
if (ix <= 0x3C600000) return pio2_hi + Ox1p_120f;
return pio2_hi - (x - (pio2_lo - x * __R(x * x)));
return pio2_hi - (x - (pio2_lo - x * R(x * x)));
}
var s: f64, w: f64, z: f64;
if (hx >> 31) {
z = (1.0 + x) * 0.5;
s = builtin_sqrt<f64>(z);
w = __R(z) * s - pio2_lo;
w = R(z) * s - pio2_lo;
return 2 * (pio2_hi - (s + w));
}
z = (1.0 - x) * 0.5;
s = builtin_sqrt<f64>(z);
var df = reinterpret<f64>(reinterpret<u64>(s) & 0xFFFFFFFF00000000);
var c = (z - df * df) / (s + df);
w = __R(z) * s + c;
w = R(z) * s + c;
return 2 * (df + w);
}
@ -157,11 +178,11 @@ export namespace NativeMath {
}
if (ix < 0x3FE00000) {
if (ix < 0x3E500000 && ix >= 0x00100000) return x;
return x + x * __R(x * x);
return x + x * R(x * x);
}
var z = (1.0 - builtin_abs<f64>(x)) * 0.5;
var s = builtin_sqrt<f64>(z);
var r = __R(z);
var r = R(z);
if (ix >= 0x3FEF3333) x = pio2_hi - (2 * (s + s * r) - pio2_lo);
else {
let f = reinterpret<f64>(reinterpret<u64>(s) & 0xFFFFFFFF00000000);
@ -330,9 +351,9 @@ export namespace NativeMath {
B2 = <u32>696219795,
P0 = reinterpret<f64>(0x3FFE03E60F61E692), // 1.87595182427177009643
P1 = reinterpret<f64>(0xBFFE28E092F02420), // -1.88497979543377169875
P2 = reinterpret<f64>(0x3FF9F1604A49d6C2), // 1.621429720105354466140
P2 = reinterpret<f64>(0x3FF9F1604A49D6C2), // 1.621429720105354466140
P3 = reinterpret<f64>(0xBFE844CBBEE751D9), // -0.758397934778766047437
P4 = reinterpret<f64>(0x3FC2B000d4E4EDD7), // 0.145996192886612446982
P4 = reinterpret<f64>(0x3FC2B000D4E4EDD7), // 0.145996192886612446982
Ox1p54 = reinterpret<f64>(0x4350000000000000);
var u = reinterpret<u64>(x);
var hx = <u32>(u >> 32) & 0x7FFFFFFF;
@ -372,14 +393,6 @@ export namespace NativeMath {
return 0;
}
function __expo2(x: f64): f64 { // see: musl/src/math/__expo2.c
const
k = <u32>2043,
kln2 = reinterpret<f64>(0x40962066151ADD8B); // 0x1.62066151add8bp+10
var scale = reinterpret<f64>(<u64>((<u32>0x3FF + k / 2) << 20) << 32);
return exp(x - kln2) * scale * scale;
}
export function cosh(x: f64): f64 { // see: musl/src/math/cosh.c
var u = reinterpret<u64>(x);
u &= 0x7FFFFFFFFFFFFFFF;
@ -395,7 +408,7 @@ export namespace NativeMath {
t = exp(x);
return 0.5 * (t + 1 / t);
}
t = __expo2(x);
t = expo2(x);
return t;
}
@ -551,7 +564,7 @@ export namespace NativeMath {
z = Ox1p700;
x *= Ox1p_700;
y *= Ox1p_700;
} else if (ey < 0x3ff - 450) {
} else if (ey < 0x3FF - 450) {
z = Ox1p_700;
x *= Ox1p700;
y *= Ox1p700;
@ -609,9 +622,9 @@ export namespace NativeMath {
var w = z * z;
var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
var R = t2 + t1;
var r = t2 + t1;
var dk = k;
return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
return s * (hfsq + r) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
}
export function log10(x: f64): f64 { // see: musl/src/math/log10.c and SUN COPYRIGHT NOTICE above
@ -638,12 +651,12 @@ export namespace NativeMath {
x *= Ox1p54;
u = reinterpret<u64>(x);
hx = <u32>(u >> 32);
} else if (hx >= 0x7ff00000) return x;
else if (hx == 0x3ff00000 && u << 32 == 0) return 0;
hx += 0x3ff00000 - 0x3fe6a09e;
k += <i32>(hx >> 20) - 0x3ff;
} else if (hx >= 0x7FF00000) return x;
else if (hx == 0x3FF00000 && u << 32 == 0) return 0;
hx += 0x3FF00000 - 0x3FE6A09E;
k += <i32>(hx >> 20) - 0x3FF;
hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
u = <u64>hx << 32 | (u & 0xffffffff);
u = <u64>hx << 32 | (u & 0xFFFFFFFF);
x = reinterpret<f64>(u);
var f = x - 1.0;
var hfsq = 0.5 * f * f;
@ -652,12 +665,12 @@ export namespace NativeMath {
var w = z * z;
var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
var R = t2 + t1;
var r = t2 + t1;
var hi = f - hfsq;
u = reinterpret<u64>(hi);
u &= 0xFFFFFFFF00000000;
hi = reinterpret<f64>(u);
var lo = f - hi - hfsq + s * (hfsq + R);
var lo = f - hi - hfsq + s * (hfsq + r);
var val_hi = hi * ivln10hi;
var dk = <f64>k;
var y = dk * log10_2hi;
@ -715,15 +728,15 @@ export namespace NativeMath {
var w = z * z;
var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
var R = t2 + t1;
var r = t2 + t1;
var dk = <f64>k;
return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
return s * (hfsq + r) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
}
export function log2(x: f64): f64 { // see: musl/src/math/log2.c and SUN COPYRIGHT NOTICE above
const
ivln2hi = reinterpret<f64>(0x3ff7154765200000), // 1.44269504072144627571e+00
ivln2lo = reinterpret<f64>(0x3de705fc2eefa200), // 1.67517131648865118353e-10
ivln2hi = reinterpret<f64>(0x3FF7154765200000), // 1.44269504072144627571e+00
ivln2lo = reinterpret<f64>(0x3DE705FC2EEFA200), // 1.67517131648865118353e-10
Lg1 = reinterpret<f64>(0x3FE5555555555593), // 6.666666666666735130e-01
Lg2 = reinterpret<f64>(0x3FD999999997FA04), // 3.999999999940941908e-01
Lg3 = reinterpret<f64>(0x3FD2492494229359), // 2.857142874366239149e-01
@ -756,12 +769,12 @@ export namespace NativeMath {
var w = z * z;
var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
var R = t2 + t1;
var r = t2 + t1;
var hi = f - hfsq;
u = reinterpret<u64>(hi);
u &= 0xFFFFFFFF00000000;
hi = reinterpret<f64>(u);
var lo = f - hi - hfsq + s * (hfsq + R);
var lo = f - hi - hfsq + s * (hfsq + r);
var val_hi = hi * ivln2hi;
var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;
var y = <f64>k;
@ -1000,7 +1013,7 @@ export namespace NativeMath {
export function round(x: f64): f64 { // see: musl/src/math/round.c
const toint = 1.0 / f64.EPSILON;
var ux = reinterpret<u64>(x);
var e = <i32>(ux >> 52 & 0x7ff);
var e = <i32>(ux >> 52 & 0x7FF);
if (e >= 0x3FF + 52) return x;
if (e < 0x3FF - 1) return 0 * x;
var y: f64;
@ -1045,7 +1058,7 @@ export namespace NativeMath {
}
return h * (t + t / (t + 1));
}
t = 2 * h * __expo2(absx);
t = 2 * h * expo2(absx);
return t;
}
@ -1220,15 +1233,33 @@ export namespace NativeMath {
}
x = reinterpret<f64>(uxi);
if (sy) y = -y;
if (ex == ey || (ex + 1 == ey && (2.0 * x > y || (2.0 * x == y && <bool>(q % 2))))) {
if (ex == ey || (ex + 1 == ey && (2.0 * x > y || (2.0 * x == y && <bool>(q & 1))))) {
x -= y;
++q;
}
q &= 0x7FFFFFFF;
return sx ? -x : x;
}
}
function Rf(z: f32): f32 { // Rational approximation of (asin(x)-x)/x^3
const // see: musl/src/math/asinf.c and SUN COPYRIGHT NOTICE above
pS0 = reinterpret<f32>(0x3E2AAA75), // 1.6666586697e-01f
pS1 = reinterpret<f32>(0xBD2F13BA), // -4.2743422091e-02f
pS2 = reinterpret<f32>(0xBC0DD36B), // -8.6563630030e-03f
qS1 = reinterpret<f32>(0xBF34E5AE); // -7.0662963390e-01f
var p = z * (pS0 + z * (pS1 + z * pS2));
var q: f32 = 1 + z * qS1;
return p / q;
}
function expo2f(x: f32): f32 { // exp(x)/2 for x >= log(DBL_MAX)
const // see: musl/src/math/__expo2f.c
k = <u32>235,
kln2 = reinterpret<f32>(0x4322E3BC); // 0x1.45c778p+7f
var scale = reinterpret<f32>(<u32>(0x7F + k / 2) << 23);
return NativeMathf.exp(x - kln2) * scale * scale;
}
export namespace NativeMathf {
export const E = <f32>NativeMath.E;
@ -1244,17 +1275,6 @@ export namespace NativeMathf {
return builtin_abs<f32>(x);
}
function __R(z: f32): f32 { // see: musl/src/math/asinf.c and SUN COPYRIGHT NOTICE above
const
pS0 = reinterpret<f32>(0x3E2AAA75), // 1.6666586697e-01f
pS1 = reinterpret<f32>(0xBD2F13BA), // -4.2743422091e-02f
pS2 = reinterpret<f32>(0xBC0DD36B), // -8.6563630030e-03f
qS1 = reinterpret<f32>(0xBF34E5AE); // -7.0662963390e-01f
var p = z * (pS0 + z * (pS1 + z * pS2));
var q: f32 = 1 + z * qS1;
return p / q;
}
export function acos(x: f32): f32 { // see: musl/src/math/acosf.c and SUN COPYRIGHT NOTICE above
const
pio2_hi = reinterpret<f32>(0x3FC90FDA), // 1.5707962513e+00f
@ -1271,13 +1291,13 @@ export namespace NativeMathf {
}
if (ix < 0x3F000000) {
if (ix <= 0x32800000) return pio2_hi + Ox1p_120f;
return pio2_hi - (x - (pio2_lo - x * __R(x * x)));
return pio2_hi - (x - (pio2_lo - x * Rf(x * x)));
}
var z: f32, w: f32, s: f32;
if (hx >> 31) {
z = (1 + x) * 0.5;
s = builtin_sqrt<f32>(z);
w = __R(z) * s - pio2_lo;
w = Rf(z) * s - pio2_lo;
return 2 * (pio2_hi - (s + w));
}
z = (1 - x) * 0.5;
@ -1285,7 +1305,7 @@ export namespace NativeMathf {
hx = reinterpret<u32>(s);
var df = reinterpret<f32>(hx & 0xFFFFF000);
var c = (z - df * df) / (s + df);
w = __R(z) * s + c;
w = Rf(z) * s + c;
return 2 * (df + w);
}
@ -1305,16 +1325,16 @@ export namespace NativeMathf {
var hx = reinterpret<u32>(x);
var ix = hx & 0x7FFFFFFF;
if (ix >= 0x3F800000) {
if (ix == 0x3f800000) return x * pio2 + Ox1p_120f;
if (ix == 0x3F800000) return x * pio2 + Ox1p_120f;
return 0 / (x - x);
}
if (ix < 0x3F000000) {
if (ix < 0x39800000 && ix >= 0x00800000) return x;
return x + x * __R(x * x);
return x + x * Rf(x * x);
}
var z: f32 = (1 - builtin_abs<f32>(x)) * 0.5;
var s = builtin_sqrt<f64>(z); // sic
x = <f32>(pio2 - 2 * (s + s * __R(z)));
x = <f32>(pio2 - 2 * (s + s * Rf(z)));
if (hx >> 31) return -x;
return x;
}
@ -1340,7 +1360,7 @@ export namespace NativeMathf {
atanhi3 = reinterpret<f32>(0x3FC90FDA), // 1.5707962513e+00f
atanlo0 = reinterpret<f32>(0x31AC3769), // 5.0121582440e-09f
atanlo1 = reinterpret<f32>(0x33222168), // 3.7748947079e-08f
atanlo2 = reinterpret<f32>(0x33140fB4), // 3.4473217170e-08f
atanlo2 = reinterpret<f32>(0x33140FB4), // 3.4473217170e-08f
atanlo3 = reinterpret<f32>(0x33A22168), // 7.5497894159e-08f
aT0 = reinterpret<f32>(0x3EAAAAA9), // 3.3333328366e-01f
aT1 = reinterpret<f32>(0xBE4CCA98), // -1.9999158382e-01f
@ -1420,27 +1440,27 @@ export namespace NativeMathf {
iy &= 0x7FFFFFFF;
if (iy == 0) {
switch (m) {
case 0:
case 1: return y;
case 2: return pi;
case 3: return -pi;
case 0:
case 1: return y;
case 2: return pi;
case 3: return -pi;
}
}
if (ix == 0) return m & 1 ? -pi / 2 : pi / 2;
if (ix == 0x7F800000) {
if (iy == 0x7F800000) {
switch (m) {
case 0: return pi / 4;
case 1: return -pi / 4;
case 2: return 3 * pi / 4;
case 3: return -3 * pi / 4;
case 0: return pi / 4;
case 1: return -pi / 4;
case 2: return 3 * pi / 4;
case 3: return -3 * pi / 4;
}
} else {
switch (m) {
case 0: return 0;
case 1: return -0;
case 2: return pi;
case 3: return -pi;
case 0: return 0;
case 1: return -0;
case 2: return pi;
case 3: return -pi;
}
}
}
@ -1510,7 +1530,7 @@ export namespace NativeMathf {
let t = exp(x);
return 0.5 * (t + 1 / t);
}
return __expo2(x);
return expo2f(x);
}
export function floor(x: f32): f32 {
@ -1699,10 +1719,10 @@ export namespace NativeMathf {
var w = z * z;
var t1 = w * (Lg2 + w * Lg4);
var t2 = z * (Lg1 + w * Lg3);
var R = t2 + t1;
var r = t2 + t1;
var hfsq = <f32>0.5 * f * f;
var dk = <f32>k;
return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
return s * (hfsq + r) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
}
export function log10(x: f32): f32 { // see: musl/src/math/log10f.c and SUN COPYRIGHT NOTICE above
@ -1727,7 +1747,7 @@ export namespace NativeMathf {
} else if (ix >= 0x7F800000) return x;
else if (ix == 0x3F800000) return 0;
ix += 0x3F800000 - 0x3F3504F3;
k += <i32>(ix >> 23) - 0x7f;
k += <i32>(ix >> 23) - 0x7F;
ix = (ix & 0x007FFFFF) + 0x3F3504F3;
x = reinterpret<f32>(ix);
var f = x - 1.0;
@ -1736,13 +1756,13 @@ export namespace NativeMathf {
var w = z * z;
var t1 = w * (Lg2 + w * Lg4);
var t2 = z * (Lg1 + w * Lg3);
var R = t2 + t1;
var r = t2 + t1;
var hfsq: f32 = 0.5 * f * f;
var hi = f - hfsq;
ix = reinterpret<u32>(hi);
ix &= 0xFFFFF000;
hi = reinterpret<f32>(ix);
var lo = f - hi - hfsq + s * (hfsq + R);
var lo = f - hi - hfsq + s * (hfsq + r);
var dk = <f32>k;
return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;
}
@ -1774,7 +1794,7 @@ export namespace NativeMathf {
let uf: f32 = 1 + x;
let iu = reinterpret<u32>(uf);
iu += 0x3F800000 - 0x3F3504F3;
k = <i32>(iu >> 23) - 0x7f;
k = <i32>(iu >> 23) - 0x7F;
if (k < 25) {
c = k >= 2 ? 1 - (uf - x) : x - (uf - 1);
c /= uf;
@ -1787,16 +1807,16 @@ export namespace NativeMathf {
var w = z * z;
var t1 = w * (Lg2 + w * Lg4);
var t2 = z * (Lg1 + w * Lg3);
var R = t2 + t1;
var r = t2 + t1;
var hfsq: f32 = 0.5 * f * f;
var dk = <f32>k;
return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
return s * (hfsq + r) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
}
export function log2(x: f32): f32 { // see: musl/src/math/log2f.c and SUN COPYRIGHT NOTICE above
const
ivln2hi = reinterpret<f32>(0x3fb8b000), // 1.4428710938e+00f
ivln2lo = reinterpret<f32>(0xb9389ad4), // -1.7605285393e-04
ivln2hi = reinterpret<f32>(0x3FB8B000), // 1.4428710938e+00f
ivln2lo = reinterpret<f32>(0xB9389AD4), // -1.7605285393e-04
Lg1 = reinterpret<f32>(0x3F2AAAAA), // 0xaaaaaa.0p-24f, 0.66666662693f
Lg2 = reinterpret<f32>(0x3ECCCE13), // 0xccce13.0p-25f, 0.40000972152f
Lg3 = reinterpret<f32>(0x3E91E9EE), // 0x91e9ee.0p-25f, 0.28498786688f
@ -1810,8 +1830,8 @@ export namespace NativeMathf {
k -= 25;
x *= Ox1p25f;
ix = reinterpret<u32>(x);
} else if (ix >= 0x7f800000) return x;
else if (ix == 0x3f800000) return 0;
} else if (ix >= 0x7F800000) return x;
else if (ix == 0x3F800000) return 0;
ix += 0x3F800000 - 0x3F3504F3;
k += <i32>(ix >> 23) - 0x7F;
ix = (ix & 0x007FFFFF) + 0x3F3504F3;
@ -1822,13 +1842,13 @@ export namespace NativeMathf {
var w = z * z;
var t1 = w * (Lg2 + w * Lg4);
var t2 = z * (Lg1 + w * Lg3);
var R = t2 + t1;
var r = t2 + t1;
var hfsq: f32 = 0.5 * f * f;
var hi = f - hfsq;
var u = reinterpret<u32>(hi);
u &= 0xFFFFF000;
hi = reinterpret<f32>(u);
var lo: f32 = f - hi - hfsq + s * (hfsq + R);
var lo: f32 = f - hi - hfsq + s * (hfsq + r);
var dk = <f32>k;
return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + dk;
}
@ -1851,7 +1871,7 @@ export namespace NativeMathf {
L1 = reinterpret<f32>(0x3F19999A), // 6.0000002384e-01f
L2 = reinterpret<f32>(0x3EDB6DB7), // 4.2857143283e-01f
L3 = reinterpret<f32>(0x3EAAAAAB), // 3.3333334327e-01f
L4 = reinterpret<f32>(0x3E8bA305), // 2.7272811532e-01f
L4 = reinterpret<f32>(0x3E8BA305), // 2.7272811532e-01f
L5 = reinterpret<f32>(0x3E6C3255), // 2.3066075146e-01f
L6 = reinterpret<f32>(0x3E53F142), // 2.0697501302e-01f
P1 = reinterpret<f32>(0x3E2AAAAB), // 1.6666667163e-01f
@ -1866,7 +1886,7 @@ export namespace NativeMathf {
cp = reinterpret<f32>(0x3F76384F), // 9.6179670095e-01
cp_h = reinterpret<f32>(0x3F764000), // 9.6191406250e-01
cp_l = reinterpret<f32>(0xB8F623C6), // -1.1736857402e-04
ivln2 = reinterpret<f32>(0x3FB8AA3b), // 1.4426950216e+00
ivln2 = reinterpret<f32>(0x3FB8AA3B), // 1.4426950216e+00
ivln2_h = reinterpret<f32>(0x3FB8AA00), // 1.4426879883e+00
ivln2_l = reinterpret<f32>(0x36ECA570); // 7.0526075433e-06
var hx = reinterpret<i32>(x);
@ -2033,7 +2053,7 @@ export namespace NativeMathf {
export function round(x: f32): f32 { // see: musl/src/math/roundf.c
const toint = <f32>1.0 / f32.EPSILON;
var ux = reinterpret<u32>(x);
var e = <i32>(ux >> 23 & 0xff);
var e = <i32>(ux >> 23 & 0xFF);
if (e >= 0x7F + 23) return x;
if (e < 0x7F - 1) return 0 * x;
var y: f32;
@ -2062,14 +2082,6 @@ export namespace NativeMathf {
return 0;
}
function __expo2(x: f32): f32 { // see: musl/src/math/__expo2f.c
const
k = <u32>235,
kln2 = reinterpret<f32>(0x4322E3BC); // 0x1.45c778p+7f
var scale = reinterpret<f32>(<u32>(0x7F + k / 2) << 23);
return exp(x - kln2) * scale * scale;
}
export function sinh(x: f32): f32 { // see: musl/src/math/sinhf.c
var u = reinterpret<u32>(x);
var h: f32 = 0.5;
@ -2077,7 +2089,7 @@ export namespace NativeMathf {
u &= 0x7FFFFFFF;
var absx = reinterpret<f32>(u);
var t: f32;
if (u < 0x42b17217) {
if (u < 0x42B17217) {
t = expm1(absx);
if (u < 0x3F800000) {
if (u < 0x3F800000 - (12 << 23)) return x;
@ -2085,7 +2097,7 @@ export namespace NativeMathf {
}
return h * (t + t / (t + 1));
}
t = 2 * h * __expo2(absx);
t = 2 * h * expo2f(absx);
return t;
}
@ -2258,24 +2270,10 @@ export namespace NativeMathf {
}
x = reinterpret<f32>(uxi);
if (sy) y = -y;
if (ex == ey || (ex + 1 == ey && (<f32>2 * x > y || (<f32>2 * x == y && <bool>(q % 2))))) {
if (ex == ey || (ex + 1 == ey && (<f32>2 * x > y || (<f32>2 * x == y && <bool>(q & 1))))) {
x -= y;
q++;
}
q &= 0x7FFFFFFF;
return sx ? -x : x;
}
}
var random_seeded = false;
var random_state0: u64;
var random_state1: u64;
function murmurHash3(h: u64): u64 {
h ^= h >> 33;
h *= 0xFF51AFD7ED558CCD;
h ^= h >> 33;
h *= 0xC4CEB9FE1A85EC53;
h ^= h >> 33;
return h;
}

22
tests/binaryen/libm.html Normal file
View File

@ -0,0 +1,22 @@
<script src="https://rawgit.com/AssemblyScript/binaryen.js/master/index.js"></script>
<script>
var libm;
// fetch("../compiler/std/libm.optimized.wat") // doesn't work: too large?
// .then(str => Binaryen.parseText(str))
// .then(module => module.emitBinary())
fetch("libm.wasm")
.then(res => res.arrayBuffer())
.then(buf => WebAssembly.instantiate(buf, {}))
.then(module => {
libm = module.instance.exports;
Object.keys(libm).forEach(key => {
var val = libm[key];
if (typeof val === "function") {
console.log("libm." + key + "(...)");
} else {
console.log("libm." + key + " = " + val);
}
});
})
.catch(err => { throw err; });
</script>

View File

@ -65,7 +65,7 @@
(get_local $0)
)
)
(func "$(lib)/math/NativeMath.__R" (; 2 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/R" (; 2 ;) (type $FF) (param $0 f64) (result f64)
(f64.div
(f64.mul
(get_local $0)
@ -217,7 +217,7 @@
(f64.const 6.123233995736766e-17)
(f64.mul
(get_local $0)
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(f64.mul
(get_local $0)
(get_local $0)
@ -256,7 +256,7 @@
)
(f64.sub
(f64.mul
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $0)
)
(get_local $1)
@ -295,7 +295,7 @@
)
(f64.add
(f64.mul
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $0)
)
(get_local $1)
@ -1066,7 +1066,7 @@
(get_local $0)
(f64.mul
(get_local $0)
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(f64.mul
(get_local $0)
(get_local $0)
@ -1093,7 +1093,7 @@
)
)
(set_local $4
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $1)
)
)
@ -3110,7 +3110,7 @@
(get_local $3)
)
)
(func "$(lib)/math/NativeMath.__expo2" (; 30 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/expo2" (; 30 ;) (type $FF) (param $0 f64) (result f64)
(local $1 f64)
(f64.mul
(f64.mul
@ -3210,7 +3210,7 @@
)
)
)
(call "$(lib)/math/NativeMath.__expo2"
(call "$(lib)/math/expo2"
(get_local $0)
)
)
@ -5889,7 +5889,7 @@
(f64.const 2)
(get_local $2)
)
(call "$(lib)/math/NativeMath.__expo2"
(call "$(lib)/math/expo2"
(get_local $1)
)
)

View File

@ -73,7 +73,7 @@
)
)
)
(func "$(lib)/math/NativeMath.__R" (; 2 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/R" (; 2 ;) (type $FF) (param $0 f64) (result f64)
(local $1 f64)
(local $2 f64)
(nop)
@ -260,7 +260,7 @@
(f64.const 6.123233995736766e-17)
(f64.mul
(get_local $0)
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(f64.mul
(get_local $0)
(get_local $0)
@ -297,7 +297,7 @@
(set_local $5
(f64.sub
(f64.mul
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $6)
)
(get_local $4)
@ -361,7 +361,7 @@
(set_local $5
(f64.add
(f64.mul
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $6)
)
(get_local $4)
@ -1270,7 +1270,7 @@
(get_local $0)
(f64.mul
(get_local $0)
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(f64.mul
(get_local $0)
(get_local $0)
@ -1298,7 +1298,7 @@
)
)
(set_local $6
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $4)
)
)
@ -3709,7 +3709,7 @@
)
)
)
(func "$(lib)/math/NativeMath.__expo2" (; 30 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/expo2" (; 30 ;) (type $FF) (param $0 f64) (result f64)
(local $1 f64)
(nop)
(set_local $1
@ -3847,7 +3847,7 @@
)
)
(set_local $3
(call "$(lib)/math/NativeMath.__expo2"
(call "$(lib)/math/expo2"
(get_local $0)
)
)
@ -6981,7 +6981,7 @@
(f64.const 2)
(get_local $2)
)
(call "$(lib)/math/NativeMath.__expo2"
(call "$(lib)/math/expo2"
(get_local $3)
)
)

View File

@ -755,7 +755,7 @@
(get_local $3)
)
)
(func "$(lib)/math/NativeMath.__R" (; 47 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/R" (; 47 ;) (type $FF) (param $0 f64) (result f64)
(f64.div
(f64.mul
(get_local $0)
@ -907,7 +907,7 @@
(f64.const 6.123233995736766e-17)
(f64.mul
(get_local $0)
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(f64.mul
(get_local $0)
(get_local $0)
@ -946,7 +946,7 @@
)
(f64.sub
(f64.mul
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $0)
)
(get_local $1)
@ -985,7 +985,7 @@
)
(f64.add
(f64.mul
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $0)
)
(get_local $1)
@ -1040,7 +1040,7 @@
(i32.const 1)
)
)
(func "$(lib)/math/NativeMathf.__R" (; 50 ;) (type $ff) (param $0 f32) (result f32)
(func "$(lib)/math/Rf" (; 50 ;) (type $ff) (param $0 f32) (result f32)
(f32.div
(f32.mul
(get_local $0)
@ -1142,7 +1142,7 @@
(f32.const 7.549789415861596e-08)
(f32.mul
(get_local $0)
(call "$(lib)/math/NativeMathf.__R"
(call "$(lib)/math/Rf"
(f32.mul
(get_local $0)
(get_local $0)
@ -1181,7 +1181,7 @@
)
(f32.sub
(f32.mul
(call "$(lib)/math/NativeMathf.__R"
(call "$(lib)/math/Rf"
(get_local $0)
)
(get_local $1)
@ -1220,7 +1220,7 @@
)
(f32.add
(f32.mul
(call "$(lib)/math/NativeMathf.__R"
(call "$(lib)/math/Rf"
(get_local $0)
)
(get_local $1)
@ -2572,7 +2572,7 @@
(get_local $0)
(f64.mul
(get_local $0)
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(f64.mul
(get_local $0)
(get_local $0)
@ -2599,7 +2599,7 @@
)
)
(set_local $4
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $1)
)
)
@ -2799,7 +2799,7 @@
(get_local $0)
(f32.mul
(get_local $0)
(call "$(lib)/math/NativeMathf.__R"
(call "$(lib)/math/Rf"
(f32.mul
(get_local $0)
(get_local $0)
@ -2837,7 +2837,7 @@
(f64.mul
(get_local $3)
(f64.promote/f32
(call "$(lib)/math/NativeMathf.__R"
(call "$(lib)/math/Rf"
(get_local $0)
)
)
@ -5863,7 +5863,7 @@
(get_local $3)
)
)
(func "$(lib)/math/NativeMath.__expo2" (; 91 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/expo2" (; 91 ;) (type $FF) (param $0 f64) (result f64)
(local $1 f64)
(f64.mul
(f64.mul
@ -5963,7 +5963,7 @@
)
)
)
(call "$(lib)/math/NativeMath.__expo2"
(call "$(lib)/math/expo2"
(get_local $0)
)
)
@ -6606,7 +6606,7 @@
(get_local $1)
)
)
(func "$(lib)/math/NativeMathf.__expo2" (; 96 ;) (type $ff) (param $0 f32) (result f32)
(func "$(lib)/math/expo2f" (; 96 ;) (type $ff) (param $0 f32) (result f32)
(local $1 f32)
(f32.mul
(f32.mul
@ -6698,7 +6698,7 @@
)
)
)
(call "$(lib)/math/NativeMathf.__expo2"
(call "$(lib)/math/expo2f"
(get_local $0)
)
)
@ -12134,7 +12134,7 @@
(call $abort
(i32.const 0)
(i32.const 32)
(i32.const 980)
(i32.const 993)
(i32.const 4)
)
(unreachable)
@ -12589,8 +12589,8 @@
(local $4 i32)
(local $5 i64)
(local $6 i32)
(local $7 i32)
(local $8 i64)
(local $7 i64)
(local $8 i32)
(local $9 i64)
(local $10 f64)
(local $11 i32)
@ -12613,7 +12613,7 @@
(i32.wrap/i64
(i64.and
(i64.shr_u
(tee_local $8
(tee_local $7
(i64.reinterpret/f64
(get_local $1)
)
@ -12633,7 +12633,7 @@
(tee_local $4
(i64.eq
(i64.shl
(get_local $8)
(get_local $7)
(i64.const 1)
)
(i64.const 0)
@ -12744,17 +12744,17 @@
(set_local $4
(i32.wrap/i64
(i64.shr_u
(get_local $8)
(get_local $7)
(i64.const 63)
)
)
)
(set_local $8
(set_local $7
(if (result i64)
(get_local $6)
(i64.or
(i64.and
(get_local $8)
(get_local $7)
(i64.const 4503599627370495)
)
(i64.const 4503599627370496)
@ -12762,7 +12762,7 @@
(block (result i64)
(set_local $5
(i64.shl
(get_local $8)
(get_local $7)
(i64.const 12)
)
)
@ -12793,7 +12793,7 @@
)
)
(i64.shl
(get_local $8)
(get_local $7)
(i64.extend_u/i32
(i32.sub
(i32.const 1)
@ -12847,7 +12847,7 @@
(tee_local $5
(i64.sub
(get_local $3)
(get_local $8)
(get_local $7)
)
)
(i64.const 63)
@ -12858,9 +12858,9 @@
(set_local $3
(get_local $5)
)
(set_local $7
(set_local $8
(i32.add
(get_local $7)
(get_local $8)
(i32.const 1)
)
)
@ -12872,9 +12872,9 @@
(i64.const 1)
)
)
(set_local $7
(set_local $8
(i32.shl
(get_local $7)
(get_local $8)
(i32.const 1)
)
)
@ -12894,7 +12894,7 @@
(tee_local $5
(i64.sub
(get_local $3)
(get_local $8)
(get_local $7)
)
)
(i64.const 63)
@ -12905,9 +12905,9 @@
(set_local $3
(get_local $5)
)
(set_local $7
(set_local $8
(i32.add
(get_local $7)
(get_local $8)
(i32.const 1)
)
)
@ -13033,7 +13033,7 @@
)
)
(i32.and
(get_local $7)
(get_local $8)
(i32.const 1)
)
(get_local $4)
@ -13044,18 +13044,10 @@
)
(i32.const 1)
)
(block
(set_local $0
(f64.sub
(get_local $0)
(get_local $1)
)
)
(set_local $7
(i32.add
(get_local $7)
(i32.const 1)
)
(set_local $0
(f64.sub
(get_local $0)
(get_local $1)
)
)
)
@ -13504,10 +13496,7 @@
)
)
(i32.and
(i32.rem_s
(get_local $5)
(i32.const 2)
)
(get_local $5)
(i32.const 1)
)
(get_local $2)
@ -13518,18 +13507,10 @@
)
(i32.const 1)
)
(block
(set_local $0
(f32.sub
(get_local $0)
(get_local $1)
)
)
(set_local $5
(i32.add
(get_local $5)
(i32.const 1)
)
(set_local $0
(f32.sub
(get_local $0)
(get_local $1)
)
)
)
@ -13666,7 +13647,7 @@
(f64.const 2)
(get_local $2)
)
(call "$(lib)/math/NativeMath.__expo2"
(call "$(lib)/math/expo2"
(get_local $1)
)
)
@ -13807,7 +13788,7 @@
(f32.const 2)
(get_local $2)
)
(call "$(lib)/math/NativeMathf.__expo2"
(call "$(lib)/math/expo2f"
(get_local $1)
)
)

View File

@ -831,7 +831,7 @@
)
)
)
(func "$(lib)/math/NativeMath.__R" (; 47 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/R" (; 47 ;) (type $FF) (param $0 f64) (result f64)
(local $1 f64)
(local $2 f64)
(nop)
@ -1018,7 +1018,7 @@
(f64.const 6.123233995736766e-17)
(f64.mul
(get_local $0)
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(f64.mul
(get_local $0)
(get_local $0)
@ -1055,7 +1055,7 @@
(set_local $5
(f64.sub
(f64.mul
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $6)
)
(get_local $4)
@ -1119,7 +1119,7 @@
(set_local $5
(f64.add
(f64.mul
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $6)
)
(get_local $4)
@ -1174,7 +1174,7 @@
)
)
)
(func "$(lib)/math/NativeMathf.__R" (; 50 ;) (type $ff) (param $0 f32) (result f32)
(func "$(lib)/math/Rf" (; 50 ;) (type $ff) (param $0 f32) (result f32)
(local $1 f32)
(local $2 f32)
(nop)
@ -1302,7 +1302,7 @@
(f32.const 7.549789415861596e-08)
(f32.mul
(get_local $0)
(call "$(lib)/math/NativeMathf.__R"
(call "$(lib)/math/Rf"
(f32.mul
(get_local $0)
(get_local $0)
@ -1339,7 +1339,7 @@
(set_local $4
(f32.sub
(f32.mul
(call "$(lib)/math/NativeMathf.__R"
(call "$(lib)/math/Rf"
(get_local $3)
)
(get_local $5)
@ -1406,7 +1406,7 @@
(set_local $4
(f32.add
(f32.mul
(call "$(lib)/math/NativeMathf.__R"
(call "$(lib)/math/Rf"
(get_local $3)
)
(get_local $5)
@ -3024,7 +3024,7 @@
(get_local $0)
(f64.mul
(get_local $0)
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(f64.mul
(get_local $0)
(get_local $0)
@ -3052,7 +3052,7 @@
)
)
(set_local $6
(call "$(lib)/math/NativeMath.__R"
(call "$(lib)/math/R"
(get_local $4)
)
)
@ -3277,7 +3277,7 @@
(get_local $0)
(f32.mul
(get_local $0)
(call "$(lib)/math/NativeMathf.__R"
(call "$(lib)/math/Rf"
(f32.mul
(get_local $0)
(get_local $0)
@ -3321,7 +3321,7 @@
(f64.mul
(get_local $5)
(f64.promote/f32
(call "$(lib)/math/NativeMathf.__R"
(call "$(lib)/math/Rf"
(get_local $4)
)
)
@ -6995,7 +6995,7 @@
)
)
)
(func "$(lib)/math/NativeMath.__expo2" (; 91 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/expo2" (; 91 ;) (type $FF) (param $0 f64) (result f64)
(local $1 f64)
(nop)
(set_local $1
@ -7133,7 +7133,7 @@
)
)
(set_local $3
(call "$(lib)/math/NativeMath.__expo2"
(call "$(lib)/math/expo2"
(get_local $0)
)
)
@ -7861,7 +7861,7 @@
)
)
)
(func "$(lib)/math/NativeMathf.__expo2" (; 96 ;) (type $ff) (param $0 f32) (result f32)
(func "$(lib)/math/expo2f" (; 96 ;) (type $ff) (param $0 f32) (result f32)
(local $1 f32)
(nop)
(set_local $1
@ -7984,7 +7984,7 @@
)
)
(return
(call "$(lib)/math/NativeMathf.__expo2"
(call "$(lib)/math/expo2f"
(get_local $0)
)
)
@ -14353,7 +14353,7 @@
(call $abort
(i32.const 0)
(i32.const 32)
(i32.const 980)
(i32.const 993)
(i32.const 4)
)
(unreachable)
@ -15431,9 +15431,9 @@
)
)
(i32.and
(i32.rem_u
(i32.and
(get_local $12)
(i32.const 2)
(i32.const 1)
)
(i32.const 1)
)
@ -15460,12 +15460,6 @@
)
)
)
(set_local $12
(i32.and
(get_local $12)
(i32.const 2147483647)
)
)
(return
(if (result f64)
(get_local $6)
@ -16013,9 +16007,9 @@
)
)
(i32.and
(i32.rem_s
(i32.and
(get_local $12)
(i32.const 2)
(i32.const 1)
)
(i32.const 1)
)
@ -16042,12 +16036,6 @@
)
)
)
(set_local $12
(i32.and
(get_local $12)
(i32.const 2147483647)
)
)
(return
(if (result f32)
(get_local $6)
@ -16197,7 +16185,7 @@
(f64.const 2)
(get_local $2)
)
(call "$(lib)/math/NativeMath.__expo2"
(call "$(lib)/math/expo2"
(get_local $3)
)
)
@ -16357,7 +16345,7 @@
(f32.const 2)
(get_local $2)
)
(call "$(lib)/math/NativeMathf.__expo2"
(call "$(lib)/math/expo2f"
(get_local $3)
)
)