diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-09-29 18:14:35 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-02 17:31:37 -0700 |
commit | 6e8ba9140b706ed30977e083f6d25c05af08076e (patch) | |
tree | 0b04c01236d4165e105340df911c5ae1f61d0ab1 /src | |
parent | d229313b7dc08e40a160ace49a38acd5be5503b3 (diff) |
optimize Math.x to Math_x
Diffstat (limited to 'src')
-rw-r--r-- | src/fastLong.js | 12 | ||||
-rw-r--r-- | src/jsifier.js | 4 | ||||
-rw-r--r-- | src/library.js | 104 | ||||
-rw-r--r-- | src/modules.js | 2 | ||||
-rw-r--r-- | src/parseTools.js | 20 | ||||
-rw-r--r-- | src/preamble.js | 17 |
6 files changed, 88 insertions, 71 deletions
diff --git a/src/fastLong.js b/src/fastLong.js index 4f6efd9f..2b70b2fb 100644 --- a/src/fastLong.js +++ b/src/fastLong.js @@ -5,12 +5,12 @@ function ___muldsi3($a, $b) { var $1 = 0, $2 = 0, $3 = 0, $6 = 0, $8 = 0, $11 = 0, $12 = 0; $1 = $a & 65535; $2 = $b & 65535; - $3 = Math.imul($2, $1) | 0; + $3 = Math_imul($2, $1) | 0; $6 = $a >>> 16; - $8 = ($3 >>> 16) + (Math.imul($2, $6) | 0) | 0; + $8 = ($3 >>> 16) + (Math_imul($2, $6) | 0) | 0; $11 = $b >>> 16; - $12 = Math.imul($11, $1) | 0; - return (tempRet0 = (($8 >>> 16) + (Math.imul($11, $6) | 0) | 0) + ((($8 & 65535) + $12 | 0) >>> 16) | 0, 0 | ($8 + $12 << 16 | $3 & 65535)) | 0; + $12 = Math_imul($11, $1) | 0; + return (tempRet0 = (($8 >>> 16) + (Math_imul($11, $6) | 0) | 0) + ((($8 & 65535) + $12 | 0) >>> 16) | 0, 0 | ($8 + $12 << 16 | $3 & 65535)) | 0; } function ___divdi3($a$0, $a$1, $b$0, $b$1) { $a$0 = $a$0 | 0; @@ -63,8 +63,8 @@ function ___muldi3($a$0, $a$1, $b$0, $b$1) { $y_sroa_0_0_extract_trunc = $b$0; $1$0 = ___muldsi3($x_sroa_0_0_extract_trunc, $y_sroa_0_0_extract_trunc) | 0; $1$1 = tempRet0; - $2 = Math.imul($a$1, $y_sroa_0_0_extract_trunc) | 0; - return (tempRet0 = ((Math.imul($b$1, $x_sroa_0_0_extract_trunc) | 0) + $2 | 0) + $1$1 | $1$1 & 0, 0 | $1$0 & -1) | 0; + $2 = Math_imul($a$1, $y_sroa_0_0_extract_trunc) | 0; + return (tempRet0 = ((Math_imul($b$1, $x_sroa_0_0_extract_trunc) | 0) + $2 | 0) + $1$1 | $1$1 & 0, 0 | $1$0 & -1) | 0; } function ___udivdi3($a$0, $a$1, $b$0, $b$1) { $a$0 = $a$0 | 0; diff --git a/src/jsifier.js b/src/jsifier.js index 8e329f8c..acbcf582 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -418,7 +418,7 @@ function JSify(data, functionsOnly, givenFunctions) { } // In asm, we need to know about library functions. If there is a target, though, then no // need to consider this a library function - we will call directly to it anyhow - if (ASM_JS && !redirectedIdent && (typeof target == 'function' || /Math\.\w+/.exec(snippet))) { + if (ASM_JS && !redirectedIdent && (typeof target == 'function' || /Math_\w+/.exec(snippet))) { Functions.libraryFunctions[ident] = 1; } } else if (typeof snippet === 'object') { @@ -1394,7 +1394,7 @@ function JSify(data, functionsOnly, givenFunctions) { var callIdent = LibraryManager.getRootIdent(simpleIdent); if (callIdent) { simpleIdent = callIdent; // ident may not be in library, if all there is is ident__inline, but in this case it is - if (callIdent.indexOf('.') < 0) { + if (callIdent.indexOf('Math_') !== 0) { callIdent = '_' + callIdent; // Not Math.*, so add the normal prefix } } else { diff --git a/src/library.js b/src/library.js index 3e69cc08..b8f5802a 100644 --- a/src/library.js +++ b/src/library.js @@ -3008,8 +3008,8 @@ LibraryManager.library = { return ret; }, - abs: 'Math.abs', - labs: 'Math.abs', + abs: 'Math_abs', + labs: 'Math_abs', #if USE_TYPED_ARRAYS == 2 llabs__deps: [function() { Types.preciseI64MathUsed = 1 }], llabs: function(lo, hi) { @@ -4702,30 +4702,30 @@ LibraryManager.library = { // math.h // ========================================================================== - cos: 'Math.cos', - cosf: 'Math.cos', - cosl: 'Math.cos', - sin: 'Math.sin', - sinf: 'Math.sin', - sinl: 'Math.sin', - tan: 'Math.tan', - tanf: 'Math.tan', - tanl: 'Math.tan', - acos: 'Math.acos', - acosf: 'Math.acos', - acosl: 'Math.acos', - asin: 'Math.asin', - asinf: 'Math.asin', - asinl: 'Math.asin', - atan: 'Math.atan', - atanf: 'Math.atan', - atanl: 'Math.atan', - atan2: 'Math.atan2', - atan2f: 'Math.atan2', - atan2l: 'Math.atan2', - exp: 'Math.exp', - expf: 'Math.exp', - expl: 'Math.exp', + cos: 'Math_cos', + cosf: 'Math_cos', + cosl: 'Math_cos', + sin: 'Math_sin', + sinf: 'Math_sin', + sinl: 'Math_sin', + tan: 'Math_tan', + tanf: 'Math_tan', + tanl: 'Math_tan', + acos: 'Math_acos', + acosf: 'Math_acos', + acosl: 'Math_acos', + asin: 'Math_asin', + asinf: 'Math_asin', + asinl: 'Math_asin', + atan: 'Math_atan', + atanf: 'Math_atan', + atanl: 'Math_atan', + atan2: 'Math_atan2', + atan2f: 'Math_atan2', + atan2l: 'Math_atan2', + exp: 'Math_exp', + expf: 'Math_exp', + expl: 'Math_exp', // The erf and erfc functions are inspired from // http://www.digitalmars.com/archives/cplusplus/3634.html @@ -4787,32 +4787,32 @@ LibraryManager.library = { }, erff: 'erf', erfl: 'erf', - log: 'Math.log', - logf: 'Math.log', - logl: 'Math.log', - sqrt: 'Math.sqrt', - sqrtf: 'Math.sqrt', - sqrtl: 'Math.sqrt', - fabs: 'Math.abs', - fabsf: 'Math.abs', - fabsl: 'Math.abs', - ceil: 'Math.ceil', - ceilf: 'Math.ceil', - ceill: 'Math.ceil', - floor: 'Math.floor', - floorf: 'Math.floor', - floorl: 'Math.floor', - pow: 'Math.pow', - powf: 'Math.pow', - powl: 'Math.pow', - llvm_sqrt_f32: 'Math.sqrt', - llvm_sqrt_f64: 'Math.sqrt', - llvm_pow_f32: 'Math.pow', - llvm_pow_f64: 'Math.pow', - llvm_log_f32: 'Math.log', - llvm_log_f64: 'Math.log', - llvm_exp_f32: 'Math.exp', - llvm_exp_f64: 'Math.exp', + log: 'Math_log', + logf: 'Math_log', + logl: 'Math_log', + sqrt: 'Math_sqrt', + sqrtf: 'Math_sqrt', + sqrtl: 'Math_sqrt', + fabs: 'Math_abs', + fabsf: 'Math_abs', + fabsl: 'Math_abs', + ceil: 'Math_ceil', + ceilf: 'Math_ceil', + ceill: 'Math_ceil', + floor: 'Math_floor', + floorf: 'Math_floor', + floorl: 'Math_floor', + pow: 'Math_pow', + powf: 'Math_pow', + powl: 'Math_pow', + llvm_sqrt_f32: 'Math_sqrt', + llvm_sqrt_f64: 'Math_sqrt', + llvm_pow_f32: 'Math_pow', + llvm_pow_f64: 'Math_pow', + llvm_log_f32: 'Math_log', + llvm_log_f64: 'Math_log', + llvm_exp_f32: 'Math_exp', + llvm_exp_f64: 'Math_exp', ldexp: function(x, exp_) { return x * Math.pow(2, exp_); }, diff --git a/src/modules.js b/src/modules.js index 5b7c06d5..cc9ca549 100644 --- a/src/modules.js +++ b/src/modules.js @@ -340,7 +340,7 @@ var Functions = { if (table[i]) { var libName = LibraryManager.getRootIdent(table[i].substr(1)); if (libName && typeof libName == 'string') { - table[i] = (libName.indexOf('.') < 0 ? '_' : '') + libName; + table[i] = (libName.indexOf('Math_') < 0 ? '_' : '') + libName; } } if (ASM_JS) { diff --git a/src/parseTools.js b/src/parseTools.js index 7e7a8307..49664170 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -763,10 +763,10 @@ function splitI64(value, floatConversion) { if (floatConversion && ASM_JS) lowInput = asmFloatToInt(lowInput); var low = lowInput + '>>>0'; var high = makeInlineCalculation( - asmCoercion('Math.abs(VALUE)', 'double') + ' >= ' + asmEnsureFloat('1', 'double') + ' ? ' + + asmCoercion('Math_abs(VALUE)', 'double') + ' >= ' + asmEnsureFloat('1', 'double') + ' ? ' + '(VALUE > ' + asmEnsureFloat('0', 'double') + ' ? ' + - asmCoercion('Math.min(' + asmCoercion('Math.floor((VALUE)/' + asmEnsureFloat(4294967296, 'float') + ')', 'double') + ', ' + asmEnsureFloat(4294967295, 'float') + ')', 'i32') + '>>>0' + - ' : ' + asmFloatToInt(asmCoercion('Math.ceil((VALUE - +((' + asmFloatToInt('VALUE') + ')>>>0))/' + asmEnsureFloat(4294967296, 'float') + ')', 'double')) + '>>>0' + + asmCoercion('Math_min(' + asmCoercion('Math_floor((VALUE)/' + asmEnsureFloat(4294967296, 'float') + ')', 'double') + ', ' + asmEnsureFloat(4294967295, 'float') + ')', 'i32') + '>>>0' + + ' : ' + asmFloatToInt(asmCoercion('Math_ceil((VALUE - +((' + asmFloatToInt('VALUE') + ')>>>0))/' + asmEnsureFloat(4294967296, 'float') + ')', 'double')) + '>>>0' + ')' + ' : 0', value, @@ -1532,7 +1532,7 @@ function getFastValue(a, op, b, type) { if (a === '2' && isIntImplemented(type)) { return '(1 << (' + b + '))'; } - return 'Math.pow(' + a + ', ' + b + ')'; + return 'Math_pow(' + a + ', ' + b + ')'; } if ((op === '+' || op === '*') && aNumber !== null) { // if one of them is a number, keep it last var c = b; @@ -1564,7 +1564,7 @@ function getFastValue(a, op, b, type) { if ((aNumber !== null && Math.abs(a) < TWO_TWENTY) || (bNumber !== null && Math.abs(b) < TWO_TWENTY) || (bits < 32 && !ASM_JS)) { return '(((' + a + ')*(' + b + '))&' + ((Math.pow(2, bits)-1)|0) + ')'; // keep a non-eliminatable coercion directly on this } - return '(Math.imul(' + a + ',' + b + ')|0)'; + return '(Math_imul(' + a + ',' + b + ')|0)'; } } else if (op === '/') { if (a === '0' && !(type in Runtime.FLOAT_TYPES)) { // careful on floats, since 0*NaN is not 0 @@ -2060,12 +2060,12 @@ function makeRounding(value, bits, signed, floatConversion) { // as |0, but &-1 hints to the js optimizer that this is a rounding correction // Do Math.floor, which is reasonably fast, if we either don't care, or if we can be sure // the value is non-negative - if (!correctRoundings() || (!signed && !floatConversion)) return 'Math.floor(' + value + ')'; + if (!correctRoundings() || (!signed && !floatConversion)) return 'Math_floor(' + value + ')'; // We are left with >32 bits signed, or a float conversion. Check and correct inline // Note that if converting a float, we may have the wrong sign at this point! But, we have // been rounded properly regardless, and we will be sign-corrected later when actually used, if // necessary. - return makeInlineCalculation(makeComparison('VALUE', '>=', '0', 'float') + ' ? Math.floor(VALUE) : Math.ceil(VALUE)', value, 'tempBigIntR'); + return makeInlineCalculation(makeComparison('VALUE', '>=', '0', 'float') + ' ? Math_floor(VALUE) : Math_ceil(VALUE)', value, 'tempBigIntR'); } else { // asm.js mode, cleaner refactoring of this function as well. TODO: use in non-asm case, most of this if (floatConversion && bits <= 32) { @@ -2080,9 +2080,9 @@ function makeRounding(value, bits, signed, floatConversion) { } } // Math.floor is reasonably fast if we don't care about corrections (and even correct if unsigned) - if (!correctRoundings() || !signed) return 'Math.floor(' + value + ')'; + if (!correctRoundings() || !signed) return 'Math_floor(' + value + ')'; // We are left with >32 bits - return makeInlineCalculation(makeComparison('VALUE', '>=', '0', 'float') + ' ? Math.floor(VALUE) : Math.ceil(VALUE)', value, 'tempBigIntR'); + return makeInlineCalculation(makeComparison('VALUE', '>=', '0', 'float') + ' ? Math_floor(VALUE) : Math_ceil(VALUE)', value, 'tempBigIntR'); } } @@ -2093,7 +2093,7 @@ function makeIsNaN(value) { function makeFloat(value, type) { if (TO_FLOAT32 && type == 'float') { - return 'Math.toFloat32(' + value + ')'; + return 'Math_toFloat32(' + value + ')'; } return value; } diff --git a/src/preamble.js b/src/preamble.js index 75519094..d094b071 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -943,6 +943,23 @@ if (!Math['toFloat32']) Math['toFloat32'] = function(x) { Math.toFloat32 = Math['toFloat32']; #endif +var Math_abs = Math.abs; +var Math_cos = Math.cos; +var Math_sin = Math.sin; +var Math_tan = Math.tan; +var Math_acos = Math.acos; +var Math_asin = Math.asin; +var Math_atan = Math.atan; +var Math_atan2 = Math.atan2; +var Math_exp = Math.exp; +var Math_log = Math.log; +var Math_sqrt = Math.sqrt; +var Math_ceil = Math.ceil; +var Math_floor = Math.floor; +var Math_pow = Math.pow; +var Math_imul = Math.imul; +var Math_toFloat32 = Math.toFloat32; + // A counter of dependencies for calling run(). If we need to // do asynchronous work before running, increment this and // decrement it. Incrementing must happen in a place like |