Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: src/js/math.js

Issue 1841993002: [builtins] Make Math.ceil, Math.trunc and Math.round optimizable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/counters.h ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 "use strict"; 6 "use strict";
7 7
8 %CheckIsBootstrapping(); 8 %CheckIsBootstrapping();
9 9
10 // ------------------------------------------------------------------- 10 // -------------------------------------------------------------------
(...skipping 21 matching lines...) Expand all
32 32
33 // ECMA 262 - 15.8.2.5 33 // ECMA 262 - 15.8.2.5
34 // The naming of y and x matches the spec, as does the order in which 34 // The naming of y and x matches the spec, as does the order in which
35 // ToNumber (valueOf) is called. 35 // ToNumber (valueOf) is called.
36 function MathAtan2JS(y, x) { 36 function MathAtan2JS(y, x) {
37 y = +y; 37 y = +y;
38 x = +x; 38 x = +x;
39 return %MathAtan2(y, x); 39 return %MathAtan2(y, x);
40 } 40 }
41 41
42 // ECMA 262 - 15.8.2.6
43 function MathCeil(x) {
44 return -%math_floor(-x);
45 }
46
47 // ECMA 262 - 15.8.2.8 42 // ECMA 262 - 15.8.2.8
48 function MathExp(x) { 43 function MathExp(x) {
49 return %MathExpRT(TO_NUMBER(x)); 44 return %MathExpRT(TO_NUMBER(x));
50 } 45 }
51 46
52 // ECMA 262 - 15.8.2.10 47 // ECMA 262 - 15.8.2.10
53 function MathLog(x) { 48 function MathLog(x) {
54 return %_MathLogRT(TO_NUMBER(x)); 49 return %_MathLogRT(TO_NUMBER(x));
55 } 50 }
56 51
(...skipping 17 matching lines...) Expand all
74 } 69 }
75 70
76 function MathRandomRaw() { 71 function MathRandomRaw() {
77 if (nextRandomIndex <= kRandomNumberStart) { 72 if (nextRandomIndex <= kRandomNumberStart) {
78 randomNumbers = %GenerateRandomNumbers(randomNumbers); 73 randomNumbers = %GenerateRandomNumbers(randomNumbers);
79 nextRandomIndex = randomNumbers.length; 74 nextRandomIndex = randomNumbers.length;
80 } 75 }
81 return %_DoubleLo(randomNumbers[--nextRandomIndex]) & 0x3FFFFFFF; 76 return %_DoubleLo(randomNumbers[--nextRandomIndex]) & 0x3FFFFFFF;
82 } 77 }
83 78
84 // ECMA 262 - 15.8.2.15
85 function MathRound(x) {
86 return %RoundNumber(TO_NUMBER(x));
87 }
88
89 // ES6 draft 09-27-13, section 20.2.2.28. 79 // ES6 draft 09-27-13, section 20.2.2.28.
90 function MathSign(x) { 80 function MathSign(x) {
91 x = +x; 81 x = +x;
92 if (x > 0) return 1; 82 if (x > 0) return 1;
93 if (x < 0) return -1; 83 if (x < 0) return -1;
94 // -0, 0 or NaN. 84 // -0, 0 or NaN.
95 return x; 85 return x;
96 } 86 }
97 87
98 // ES6 draft 09-27-13, section 20.2.2.34.
99 function MathTrunc(x) {
100 x = +x;
101 if (x > 0) return %math_floor(x);
102 if (x < 0) return -%math_floor(-x);
103 // -0, 0 or NaN.
104 return x;
105 }
106
107 // ES6 draft 09-27-13, section 20.2.2.5. 88 // ES6 draft 09-27-13, section 20.2.2.5.
108 function MathAsinh(x) { 89 function MathAsinh(x) {
109 x = TO_NUMBER(x); 90 x = TO_NUMBER(x);
110 // Idempotent for NaN, +/-0 and +/-Infinity. 91 // Idempotent for NaN, +/-0 and +/-Infinity.
111 if (x === 0 || !NUMBER_IS_FINITE(x)) return x; 92 if (x === 0 || !NUMBER_IS_FINITE(x)) return x;
112 if (x > 0) return MathLog(x + %math_sqrt(x * x + 1)); 93 if (x > 0) return MathLog(x + %math_sqrt(x * x + 1));
113 // This is to prevent numerical errors caused by large negative x. 94 // This is to prevent numerical errors caused by large negative x.
114 return -MathLog(-x + %math_sqrt(x * x + 1)); 95 return -MathLog(-x + %math_sqrt(x * x + 1));
115 } 96 }
116 97
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 "PI", 3.1415926535897932, 193 "PI", 3.1415926535897932,
213 "SQRT1_2", 0.7071067811865476, 194 "SQRT1_2", 0.7071067811865476,
214 "SQRT2", 1.4142135623730951 195 "SQRT2", 1.4142135623730951
215 ]); 196 ]);
216 197
217 // Set up non-enumerable functions of the Math object and 198 // Set up non-enumerable functions of the Math object and
218 // set their names. 199 // set their names.
219 utils.InstallFunctions(GlobalMath, DONT_ENUM, [ 200 utils.InstallFunctions(GlobalMath, DONT_ENUM, [
220 "random", MathRandom, 201 "random", MathRandom,
221 "abs", MathAbs, 202 "abs", MathAbs,
222 "ceil", MathCeil,
223 "exp", MathExp, 203 "exp", MathExp,
224 "log", MathLog, 204 "log", MathLog,
225 "round", MathRound,
226 "atan2", MathAtan2JS, 205 "atan2", MathAtan2JS,
227 "pow", MathPowJS, 206 "pow", MathPowJS,
228 "sign", MathSign, 207 "sign", MathSign,
229 "trunc", MathTrunc,
230 "asinh", MathAsinh, 208 "asinh", MathAsinh,
231 "acosh", MathAcosh, 209 "acosh", MathAcosh,
232 "atanh", MathAtanh, 210 "atanh", MathAtanh,
233 "hypot", MathHypot, 211 "hypot", MathHypot,
234 "clz32", MathClz32JS, 212 "clz32", MathClz32JS,
235 "cbrt", MathCbrt 213 "cbrt", MathCbrt
236 ]); 214 ]);
237 215
238 %SetForceInlineFlag(MathAbs); 216 %SetForceInlineFlag(MathAbs);
239 %SetForceInlineFlag(MathAtan2JS); 217 %SetForceInlineFlag(MathAtan2JS);
240 %SetForceInlineFlag(MathCeil);
241 %SetForceInlineFlag(MathClz32JS); 218 %SetForceInlineFlag(MathClz32JS);
242 %SetForceInlineFlag(MathRandom); 219 %SetForceInlineFlag(MathRandom);
243 %SetForceInlineFlag(MathSign); 220 %SetForceInlineFlag(MathSign);
244 %SetForceInlineFlag(MathTrunc);
245 221
246 // ------------------------------------------------------------------- 222 // -------------------------------------------------------------------
247 // Exports 223 // Exports
248 224
249 utils.Export(function(to) { 225 utils.Export(function(to) {
250 to.MathAbs = MathAbs; 226 to.MathAbs = MathAbs;
251 to.MathExp = MathExp; 227 to.MathExp = MathExp;
252 to.IntRandom = MathRandomRaw; 228 to.IntRandom = MathRandomRaw;
253 }); 229 });
254 230
255 }) 231 })
OLDNEW
« no previous file with comments | « src/counters.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698