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

Side by Side Diff: src/third_party/fdlibm/fdlibm.js

Issue 866553003: Allocate typed array for rempio2 result. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: make runtime call slightly faster. Created 5 years, 10 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
« src/runtime/runtime-maths.cc ('K') | « src/runtime/runtime-maths.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // The following is adapted from fdlibm (http://www.netlib.org/fdlibm), 1 // The following is adapted from fdlibm (http://www.netlib.org/fdlibm),
2 // 2 //
3 // ==================================================== 3 // ====================================================
4 // Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. 4 // Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved.
5 // 5 //
6 // Developed at SunSoft, a Sun Microsystems, Inc. business. 6 // Developed at SunSoft, a Sun Microsystems, Inc. business.
7 // Permission to use, copy, modify, and distribute this 7 // Permission to use, copy, modify, and distribute this
8 // software is freely granted, provided that this notice 8 // software is freely granted, provided that this notice
9 // is preserved. 9 // is preserved.
10 // ==================================================== 10 // ====================================================
11 // 11 //
12 // The original source code covered by the above license above has been 12 // The original source code covered by the above license above has been
13 // modified significantly by Google Inc. 13 // modified significantly by Google Inc.
14 // Copyright 2014 the V8 project authors. All rights reserved. 14 // Copyright 2014 the V8 project authors. All rights reserved.
15 // 15 //
16 // The following is a straightforward translation of fdlibm routines 16 // The following is a straightforward translation of fdlibm routines
17 // by Raymond Toy (rtoy@google.com). 17 // by Raymond Toy (rtoy@google.com).
18 18
19 // Double constants that do not have empty lower 32 bits are found in fdlibm.cc 19 // Double constants that do not have empty lower 32 bits are found in fdlibm.cc
20 // and exposed through kMath as typed array. We assume the compiler to convert 20 // and exposed through kMath as typed array. We assume the compiler to convert
21 // from decimal to binary accurately enough to produce the intended values. 21 // from decimal to binary accurately enough to produce the intended values.
22 // kMath is initialized to a Float64Array during genesis and not writable. 22 // kMath is initialized to a Float64Array during genesis and not writable.
23 23
24 "use strict"; 24 "use strict";
25 25
26 var kMath; 26 var kMath;
27 var rempio2result;
Sven Panne 2015/02/06 07:37:28 Extend the comment above.
27 28
28 const INVPIO2 = kMath[0]; 29 const INVPIO2 = kMath[0];
29 const PIO2_1 = kMath[1]; 30 const PIO2_1 = kMath[1];
30 const PIO2_1T = kMath[2]; 31 const PIO2_1T = kMath[2];
31 const PIO2_2 = kMath[3]; 32 const PIO2_2 = kMath[3];
32 const PIO2_2T = kMath[4]; 33 const PIO2_2T = kMath[4];
33 const PIO2_3 = kMath[5]; 34 const PIO2_3 = kMath[5];
34 const PIO2_3T = kMath[6]; 35 const PIO2_3T = kMath[6];
35 const PIO4 = kMath[32]; 36 const PIO4 = kMath[32];
36 const PIO4LO = kMath[33]; 37 const PIO4LO = kMath[33];
37 38
38 // Compute k and r such that x - k*pi/2 = r where |r| < pi/4. For 39 // Compute k and r such that x - k*pi/2 = r where |r| < pi/4. For
39 // precision, r is returned as two values y0 and y1 such that r = y0 + y1 40 // precision, r is returned as two values y0 and y1 such that r = y0 + y1
40 // to more than double precision. 41 // to more than double precision.
42
41 macro REMPIO2(X) 43 macro REMPIO2(X)
42 var n, y0, y1; 44 var n, y0, y1;
43 var hx = %_DoubleHi(X); 45 var hx = %_DoubleHi(X);
44 var ix = hx & 0x7fffffff; 46 var ix = hx & 0x7fffffff;
45 47
46 if (ix < 0x4002d97c) { 48 if (ix < 0x4002d97c) {
47 // |X| ~< 3*pi/4, special case with n = +/- 1 49 // |X| ~< 3*pi/4, special case with n = +/- 1
48 if (hx > 0) { 50 if (hx > 0) {
49 var z = X - PIO2_1; 51 var z = X - PIO2_1;
50 if (ix != 0x3ff921fb) { 52 if (ix != 0x3ff921fb) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 100 }
99 } 101 }
100 y1 = (r - y0) - w; 102 y1 = (r - y0) - w;
101 if (hx < 0) { 103 if (hx < 0) {
102 n = -n; 104 n = -n;
103 y0 = -y0; 105 y0 = -y0;
104 y1 = -y1; 106 y1 = -y1;
105 } 107 }
106 } else { 108 } else {
107 // Need to do full Payne-Hanek reduction here. 109 // Need to do full Payne-Hanek reduction here.
108 var r = %RemPiO2(X); 110 n = %RemPiO2(X, rempio2result);
109 n = r[0]; 111 y0 = rempio2result[0];
110 y0 = r[1]; 112 y1 = rempio2result[1];
111 y1 = r[2];
112 } 113 }
113 endmacro 114 endmacro
114 115
115 116
116 // __kernel_sin(X, Y, IY) 117 // __kernel_sin(X, Y, IY)
117 // kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854 118 // kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
118 // Input X is assumed to be bounded by ~pi/4 in magnitude. 119 // Input X is assumed to be bounded by ~pi/4 in magnitude.
119 // Input Y is the tail of X so that x = X + Y. 120 // Input Y is the tail of X so that x = X + Y.
120 // 121 //
121 // Algorithm 122 // Algorithm
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 z_l = CP_L * p_h + p_l * CP + dp_l; 988 z_l = CP_L * p_h + p_l * CP + dp_l;
988 989
989 // log2(ax) = (ss + ...) * 2 / (3 * log(2)) = n + dp_h + z_h + z_l 990 // log2(ax) = (ss + ...) * 2 / (3 * log(2)) = n + dp_h + z_h + z_l
990 var t = n; 991 var t = n;
991 var t1 = %_ConstructDouble(%_DoubleHi(((z_h + z_l) + dp_h) + t), 0); 992 var t1 = %_ConstructDouble(%_DoubleHi(((z_h + z_l) + dp_h) + t), 0);
992 var t2 = z_l - (((t1 - t) - dp_h) - z_h); 993 var t2 = z_l - (((t1 - t) - dp_h) - z_h);
993 994
994 // t1 + t2 = log2(ax), sum up because we do not care about extra precision. 995 // t1 + t2 = log2(ax), sum up because we do not care about extra precision.
995 return t1 + t2; 996 return t1 + t2;
996 } 997 }
OLDNEW
« src/runtime/runtime-maths.cc ('K') | « src/runtime/runtime-maths.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698