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

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') | src/conversions.cc » ('J')
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 #include <math.h>
32
33 #include "v8.h"
34
35 #include "diy_fp.h"
36
37 namespace v8 {
38 namespace internal {
39
40 struct CachedPower {
41 uint64_t significand;
42 short binary_exponent;
43 short decimal_exponent;
44 };
45
46 #define GRISU_CACHE_STRUCT CachedPower
47 #define GRISU_CACHE_NAME(i) kCachedPowers##i
48 #define GRISU_CACHE_MAX_DISTANCE(i) kCachedPowersMaxDistance##i
49 #define GRISU_CACHE_OFFSET kCachedPowerOffset
50 #define GRISU_UINT64_C V8_2PART_UINT64_C
51 // The following include imports the precompiled cached powers.
52 #include "powers_ten.h"
53
54 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10)
55
56 #define COMPUTE_FOR_CACHE(i) \
57 if (!found && (gamma - alpha + 1 >= GRISU_CACHE_MAX_DISTANCE(i))) { \
58 int kQ = DiyFp::kSignificandSize; \
59 int k = ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); \
60 int index = (GRISU_CACHE_OFFSET + k - 1) / i + 1; \
61 cached_power = GRISU_CACHE_NAME(i)[index]; \
62 found = true; \
63 } \
64
65 static void GetCachedPower(int e, int alpha, int gamma, int* mk, DiyFp* c_mk) {
66 // The following if statement should be optimized by the compiler so that only
67 // one array is referenced and the others are not included in the object file.
68 bool found = false;
69 CachedPower cached_power;
70 COMPUTE_FOR_CACHE(20);
71 COMPUTE_FOR_CACHE(19);
72 COMPUTE_FOR_CACHE(18);
73 COMPUTE_FOR_CACHE(17);
74 COMPUTE_FOR_CACHE(16);
75 COMPUTE_FOR_CACHE(15);
76 COMPUTE_FOR_CACHE(14);
77 COMPUTE_FOR_CACHE(13);
78 COMPUTE_FOR_CACHE(12);
79 COMPUTE_FOR_CACHE(11);
80 COMPUTE_FOR_CACHE(10);
81 COMPUTE_FOR_CACHE(9);
82 if (!found && (gamma - alpha + 1 >= GRISU_CACHE_MAX_DISTANCE(8))) {
83 int k = ceiling((alpha - e + DiyFp::kSignificandSize - 1) * kD_1_LOG2_10);
84 int index = (GRISU_CACHE_OFFSET + k - 1) / 8 + 1;
85 cached_power = GRISU_CACHE_NAME(8)[index];
86 found = true;
87 }
88 COMPUTE_FOR_CACHE(8);
89 COMPUTE_FOR_CACHE(7);
90 COMPUTE_FOR_CACHE(6);
91 COMPUTE_FOR_CACHE(5);
92 COMPUTE_FOR_CACHE(4);
93 COMPUTE_FOR_CACHE(3);
94 COMPUTE_FOR_CACHE(2);
95 COMPUTE_FOR_CACHE(1);
96 if (!found) {
97 UNIMPLEMENTED();
98 }
99 *c_mk = DiyFp(cached_power.significand, cached_power.binary_exponent);
100 *mk = cached_power.decimal_exponent;
101 ASSERT((alpha <= c_mk->e() + e) && (c_mk->e() + e <= gamma));
102 }
103 #undef GRISU_REDUCTION
104 #undef GRISU_CACHE_STRUCT
105 #undef GRISU_CACHE_NAME
106 #undef GRISU_CACHE_MAX_DISTANCE
107 #undef GRISU_CACHE_OFFSET
108 #undef GRISU_UINT64_C
109
110 } } // namespace v8::internal
111
112 #endif // V8_CACHED_POWERS_H_
OLDNEW
« no previous file with comments | « src/SConscript ('k') | src/checks.h » ('j') | src/conversions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698