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

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

Issue 2103733003: [turbofan] Introduce Float64Pow and NumberPow operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE on ARM64 bug fix. Created 4 years, 5 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/interpreter/interpreter-intrinsics.cc ('k') | src/js/v8natives.js » ('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 11 matching lines...) Expand all
22 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); 22 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
23 23
24 //------------------------------------------------------------------- 24 //-------------------------------------------------------------------
25 25
26 // ECMA 262 - 15.8.2.1 26 // ECMA 262 - 15.8.2.1
27 function MathAbs(x) { 27 function MathAbs(x) {
28 x = +x; 28 x = +x;
29 return (x > 0) ? x : 0 - x; 29 return (x > 0) ? x : 0 - x;
30 } 30 }
31 31
32 // ECMA 262 - 15.8.2.13
33 function MathPowJS(x, y) {
34 return %_MathPow(TO_NUMBER(x), TO_NUMBER(y));
35 }
36
37 // ECMA 262 - 15.8.2.14 32 // ECMA 262 - 15.8.2.14
38 function MathRandom() { 33 function MathRandom() {
39 // While creating a startup snapshot, %GenerateRandomNumbers returns a 34 // While creating a startup snapshot, %GenerateRandomNumbers returns a
40 // normal array containing a single random number, and has to be called for 35 // normal array containing a single random number, and has to be called for
41 // every new random number. 36 // every new random number.
42 // Otherwise, it returns a pre-populated typed array of random numbers. The 37 // Otherwise, it returns a pre-populated typed array of random numbers. The
43 // first two elements are reserved for the PRNG state. 38 // first two elements are reserved for the PRNG state.
44 if (nextRandomIndex <= kRandomNumberStart) { 39 if (nextRandomIndex <= kRandomNumberStart) {
45 randomNumbers = %GenerateRandomNumbers(randomNumbers); 40 randomNumbers = %GenerateRandomNumbers(randomNumbers);
46 if (%_IsTypedArray(randomNumbers)) { 41 if (%_IsTypedArray(randomNumbers)) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 var summand = n * n - compensation; 107 var summand = n * n - compensation;
113 var preliminary = sum + summand; 108 var preliminary = sum + summand;
114 compensation = (preliminary - sum) - summand; 109 compensation = (preliminary - sum) - summand;
115 sum = preliminary; 110 sum = preliminary;
116 } 111 }
117 return %math_sqrt(sum) * max; 112 return %math_sqrt(sum) * max;
118 } 113 }
119 114
120 // ------------------------------------------------------------------- 115 // -------------------------------------------------------------------
121 116
122 %InstallToContext([
123 "math_pow", MathPowJS,
124 ]);
125
126 %AddNamedProperty(GlobalMath, toStringTagSymbol, "Math", READ_ONLY | DONT_ENUM); 117 %AddNamedProperty(GlobalMath, toStringTagSymbol, "Math", READ_ONLY | DONT_ENUM);
127 118
128 // Set up math constants. 119 // Set up math constants.
129 utils.InstallConstants(GlobalMath, [ 120 utils.InstallConstants(GlobalMath, [
130 "PI", 3.1415926535897932, 121 "PI", 3.1415926535897932,
131 "SQRT1_2", 0.7071067811865476, 122 "SQRT1_2", 0.7071067811865476,
132 "SQRT2", 1.4142135623730951 123 "SQRT2", 1.4142135623730951
133 ]); 124 ]);
134 125
135 // Set up non-enumerable functions of the Math object and 126 // Set up non-enumerable functions of the Math object and
136 // set their names. 127 // set their names.
137 utils.InstallFunctions(GlobalMath, DONT_ENUM, [ 128 utils.InstallFunctions(GlobalMath, DONT_ENUM, [
138 "random", MathRandom, 129 "random", MathRandom,
139 "abs", MathAbs, 130 "abs", MathAbs,
140 "pow", MathPowJS,
141 "sign", MathSign, 131 "sign", MathSign,
142 "asinh", MathAsinh, 132 "asinh", MathAsinh,
143 "acosh", MathAcosh, 133 "acosh", MathAcosh,
144 "hypot", MathHypot, 134 "hypot", MathHypot,
145 ]); 135 ]);
146 136
147 %SetForceInlineFlag(MathRandom); 137 %SetForceInlineFlag(MathRandom);
148 %SetForceInlineFlag(MathSign); 138 %SetForceInlineFlag(MathSign);
149 139
150 // ------------------------------------------------------------------- 140 // -------------------------------------------------------------------
151 // Exports 141 // Exports
152 142
153 utils.Export(function(to) { 143 utils.Export(function(to) {
154 to.MathAbs = MathAbs; 144 to.MathAbs = MathAbs;
155 to.IntRandom = MathRandomRaw; 145 to.IntRandom = MathRandomRaw;
156 }); 146 });
157 147
158 }) 148 })
OLDNEW
« no previous file with comments | « src/interpreter/interpreter-intrinsics.cc ('k') | src/js/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698