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

Side by Side Diff: src/cached_powers.h

Issue 619005: Fast algorithm for double->string conversion. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 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 | Annotate | Revision Log
« no previous file with comments | « src/SConscript ('k') | src/checks.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_CACHED_POWERS_H_
29 #define V8_CACHED_POWERS_H_
30
31 namespace v8 {
32 namespace internal {
33
34 struct CachedPower {
35 uint64_t significand;
36 int16_t binary_exponent;
37 int16_t decimal_exponent;
38 };
39
40 #define GRISU_CACHE_STRUCT CachedPower
fschneider 2010/02/22 16:25:24 No reason for this macro?
41 #define GRISU_CACHE_NAME(i) kCachedPowers##i
42 #define GRISU_CACHE_MAX_DISTANCE(i) kCachedPowersMaxDistance##i
43 #define GRISU_CACHE_OFFSET kCachedPowerOffset
fschneider 2010/02/22 16:25:24 No reason for this macro either.
44 #define GRISU_UINT64_C V8_2PART_UINT64_C
fschneider 2010/02/22 16:25:24 And this one.
45 // The following include imports the precompiled cached powers.
46 #include "powers_ten.h" // NOLINT
47
48 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10)
49
50 #define COMPUTE_FOR_CACHE(i) \
fschneider 2010/02/22 16:25:24 If this is performance-critical make an inline fun
51 if (!found && (gamma - alpha + 1 >= GRISU_CACHE_MAX_DISTANCE(i))) { \
52 int kQ = DiyFp::kSignificandSize; \
53 int k = ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); \
54 int index = (GRISU_CACHE_OFFSET + k - 1) / i + 1; \
55 cached_power = GRISU_CACHE_NAME(i)[index]; \
56 found = true; \
57 } \
58
59 static void GetCachedPower(int e, int alpha, int gamma, int* mk, DiyFp* c_mk) {
60 // The following if statement should be optimized by the compiler so that only
61 // one array is referenced and the others are not included in the object file.
62 bool found = false;
63 CachedPower cached_power;
64 COMPUTE_FOR_CACHE(20);
65 COMPUTE_FOR_CACHE(19);
66 COMPUTE_FOR_CACHE(18);
67 COMPUTE_FOR_CACHE(17);
68 COMPUTE_FOR_CACHE(16);
69 COMPUTE_FOR_CACHE(15);
70 COMPUTE_FOR_CACHE(14);
71 COMPUTE_FOR_CACHE(13);
72 COMPUTE_FOR_CACHE(12);
73 COMPUTE_FOR_CACHE(11);
74 COMPUTE_FOR_CACHE(10);
75 COMPUTE_FOR_CACHE(9);
76 if (!found && (gamma - alpha + 1 >= GRISU_CACHE_MAX_DISTANCE(8))) {
fschneider 2010/02/22 16:25:24 Remove. This is the same as: COMPUTE_FOR_CACHE(8)
floitsch 2012/04/10 15:54:34 Done.
77 int k = ceiling((alpha - e + DiyFp::kSignificandSize - 1) * kD_1_LOG2_10);
78 int index = (GRISU_CACHE_OFFSET + k - 1) / 8 + 1;
79 cached_power = GRISU_CACHE_NAME(8)[index];
80 found = true;
81 }
82 COMPUTE_FOR_CACHE(8);
83 COMPUTE_FOR_CACHE(7);
84 COMPUTE_FOR_CACHE(6);
85 COMPUTE_FOR_CACHE(5);
86 COMPUTE_FOR_CACHE(4);
87 COMPUTE_FOR_CACHE(3);
88 COMPUTE_FOR_CACHE(2);
89 COMPUTE_FOR_CACHE(1);
90 if (!found) {
91 UNIMPLEMENTED();
92 }
93 *c_mk = DiyFp(cached_power.significand, cached_power.binary_exponent);
94 *mk = cached_power.decimal_exponent;
95 ASSERT((alpha <= c_mk->e() + e) && (c_mk->e() + e <= gamma));
96 }
97 #undef GRISU_REDUCTION
98 #undef GRISU_CACHE_STRUCT
99 #undef GRISU_CACHE_NAME
100 #undef GRISU_CACHE_MAX_DISTANCE
101 #undef GRISU_CACHE_OFFSET
102 #undef GRISU_UINT64_C
103
104 } } // namespace v8::internal
105
106 #endif // V8_CACHED_POWERS_H_
OLDNEW
« no previous file with comments | « src/SConscript ('k') | src/checks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698