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

Side by Side Diff: src/cached-powers.h

Issue 3608011: Simplify powers-of-ten cache. (Closed)
Patch Set: Created 10 years, 2 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/SConscript ('k') | src/cached-powers.cc » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_CACHED_POWERS_H_ 28 #ifndef V8_CACHED_POWERS_H_
29 #define V8_CACHED_POWERS_H_ 29 #define V8_CACHED_POWERS_H_
30 30
31 #include "diy-fp.h" 31 #include "diy-fp.h"
32 32
33 namespace v8 { 33 namespace v8 {
34 namespace internal { 34 namespace internal {
35 35
36 struct CachedPower { 36 void GetCachedPowerForBinaryExponentRange(int min_exponent,
37 uint64_t significand; 37 int max_exponent,
38 int16_t binary_exponent; 38 DiyFp* power,
39 int16_t decimal_exponent; 39 int* decimal_exponent);
40 };
41
42 // The following defines implement the interface between this file and the
43 // generated 'powers_ten.h'.
44 // GRISU_CACHE_NAME(1) contains all possible cached powers.
45 // GRISU_CACHE_NAME(i) contains GRISU_CACHE_NAME(1) where only every 'i'th
46 // element is kept. More formally GRISU_CACHE_NAME(i) contains the elements j*i
47 // with 0 <= j < k with k such that j*k < the size of GRISU_CACHE_NAME(1).
48 // The higher 'i' is the fewer elements we use.
49 // Given that there are less elements, the exponent-distance between two
50 // elements in the cache grows. The variable GRISU_CACHE_MAX_DISTANCE(i) stores
51 // the maximum distance between two elements.
52 #define GRISU_CACHE_STRUCT CachedPower
53 #define GRISU_CACHE_NAME(i) kCachedPowers##i
54 #define GRISU_CACHE_MAX_DISTANCE(i) kCachedPowersMaxDistance##i
55 #define GRISU_CACHE_OFFSET kCachedPowerOffset
56 #define GRISU_UINT64_C V8_2PART_UINT64_C
57 // The following include imports the precompiled cached powers.
58 #include "powers-ten.h" // NOLINT
59
60 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10)
61
62 // We can't use a function since we reference variables depending on the 'i'.
63 // This way the compiler is able to see at compile time that only one
64 // cache-array variable is used and thus can remove all the others.
65 #define COMPUTE_FOR_CACHE(i) \
66 if (!found && (gamma - alpha + 1 >= GRISU_CACHE_MAX_DISTANCE(i))) { \
67 int kQ = DiyFp::kSignificandSize; \
68 double k = ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); \
69 int index = (GRISU_CACHE_OFFSET + static_cast<int>(k) - 1) / i + 1; \
70 cached_power = GRISU_CACHE_NAME(i)[index]; \
71 found = true; \
72 } \
73
74 static void GetCachedPower(int e, int alpha, int gamma, int* mk, DiyFp* c_mk) {
75 // The following if statement should be optimized by the compiler so that only
76 // one array is referenced and the others are not included in the object file.
77 bool found = false;
78 CachedPower cached_power;
79 COMPUTE_FOR_CACHE(20);
80 COMPUTE_FOR_CACHE(19);
81 COMPUTE_FOR_CACHE(18);
82 COMPUTE_FOR_CACHE(17);
83 COMPUTE_FOR_CACHE(16);
84 COMPUTE_FOR_CACHE(15);
85 COMPUTE_FOR_CACHE(14);
86 COMPUTE_FOR_CACHE(13);
87 COMPUTE_FOR_CACHE(12);
88 COMPUTE_FOR_CACHE(11);
89 COMPUTE_FOR_CACHE(10);
90 COMPUTE_FOR_CACHE(9);
91 COMPUTE_FOR_CACHE(8);
92 COMPUTE_FOR_CACHE(7);
93 COMPUTE_FOR_CACHE(6);
94 COMPUTE_FOR_CACHE(5);
95 COMPUTE_FOR_CACHE(4);
96 COMPUTE_FOR_CACHE(3);
97 COMPUTE_FOR_CACHE(2);
98 COMPUTE_FOR_CACHE(1);
99 if (!found) {
100 UNIMPLEMENTED();
101 // Silence compiler warnings.
102 cached_power.significand = 0;
103 cached_power.binary_exponent = 0;
104 cached_power.decimal_exponent = 0;
105 }
106 *c_mk = DiyFp(cached_power.significand, cached_power.binary_exponent);
107 *mk = cached_power.decimal_exponent;
108 ASSERT((alpha <= c_mk->e() + e) && (c_mk->e() + e <= gamma));
109 }
110 #undef GRISU_REDUCTION
111 #undef GRISU_CACHE_STRUCT
112 #undef GRISU_CACHE_NAME
113 #undef GRISU_CACHE_MAX_DISTANCE
114 #undef GRISU_CACHE_OFFSET
115 #undef GRISU_UINT64_C
116 40
117 } } // namespace v8::internal 41 } } // namespace v8::internal
118 42
119 #endif // V8_CACHED_POWERS_H_ 43 #endif // V8_CACHED_POWERS_H_
OLDNEW
« no previous file with comments | « src/SConscript ('k') | src/cached-powers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698