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

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

Issue 3760013: Strtod fast-case that uses DiyFps and cached powers of ten. (Closed)
Patch Set: Addressed comments. 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/cached-powers.h ('k') | src/double.h » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 24 matching lines...) Expand all
35 namespace v8 { 35 namespace v8 {
36 namespace internal { 36 namespace internal {
37 37
38 struct CachedPower { 38 struct CachedPower {
39 uint64_t significand; 39 uint64_t significand;
40 int16_t binary_exponent; 40 int16_t binary_exponent;
41 int16_t decimal_exponent; 41 int16_t decimal_exponent;
42 }; 42 };
43 43
44 static const CachedPower kCachedPowers[] = { 44 static const CachedPower kCachedPowers[] = {
45 {V8_2PART_UINT64_C(0xfa8fd5a0, 081c0288), -1220, -348},
46 {V8_2PART_UINT64_C(0xbaaee17f, a23ebf76), -1193, -340},
47 {V8_2PART_UINT64_C(0x8b16fb20, 3055ac76), -1166, -332},
48 {V8_2PART_UINT64_C(0xcf42894a, 5dce35ea), -1140, -324},
49 {V8_2PART_UINT64_C(0x9a6bb0aa, 55653b2d), -1113, -316},
45 {V8_2PART_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, 50 {V8_2PART_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308},
46 {V8_2PART_UINT64_C(0xab70fe17, c79ac6ca), -1060, -300}, 51 {V8_2PART_UINT64_C(0xab70fe17, c79ac6ca), -1060, -300},
47 {V8_2PART_UINT64_C(0xff77b1fc, bebcdc4f), -1034, -292}, 52 {V8_2PART_UINT64_C(0xff77b1fc, bebcdc4f), -1034, -292},
48 {V8_2PART_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284}, 53 {V8_2PART_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284},
49 {V8_2PART_UINT64_C(0x8dd01fad, 907ffc3c), -980, -276}, 54 {V8_2PART_UINT64_C(0x8dd01fad, 907ffc3c), -980, -276},
50 {V8_2PART_UINT64_C(0xd3515c28, 31559a83), -954, -268}, 55 {V8_2PART_UINT64_C(0xd3515c28, 31559a83), -954, -268},
51 {V8_2PART_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, 56 {V8_2PART_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260},
52 {V8_2PART_UINT64_C(0xea9c2277, 23ee8bcb), -901, -252}, 57 {V8_2PART_UINT64_C(0xea9c2277, 23ee8bcb), -901, -252},
53 {V8_2PART_UINT64_C(0xaecc4991, 4078536d), -874, -244}, 58 {V8_2PART_UINT64_C(0xaecc4991, 4078536d), -874, -244},
54 {V8_2PART_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, 59 {V8_2PART_UINT64_C(0x823c1279, 5db6ce57), -847, -236},
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 {V8_2PART_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, 127 {V8_2PART_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308},
123 {V8_2PART_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, 128 {V8_2PART_UINT64_C(0xd433179d, 9c8cb841), 986, 316},
124 {V8_2PART_UINT64_C(0x9e19db92, b4e31ba9), 1013, 324}, 129 {V8_2PART_UINT64_C(0x9e19db92, b4e31ba9), 1013, 324},
125 {V8_2PART_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, 130 {V8_2PART_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332},
126 {V8_2PART_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, 131 {V8_2PART_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340},
127 }; 132 };
128 133
129 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); 134 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers);
130 static const int kCachedPowersOffset = -kCachedPowers[0].decimal_exponent; 135 static const int kCachedPowersOffset = -kCachedPowers[0].decimal_exponent;
131 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) 136 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10)
132 static const int kCachedPowersDecimalDistance = 137 const int PowersOfTenCache::kDecimalExponentDistance =
133 kCachedPowers[1].decimal_exponent - kCachedPowers[0].decimal_exponent; 138 kCachedPowers[1].decimal_exponent - kCachedPowers[0].decimal_exponent;
139 const int PowersOfTenCache::kMinDecimalExponent =
140 kCachedPowers[0].decimal_exponent;
141 const int PowersOfTenCache::kMaxDecimalExponent =
142 kCachedPowers[kCachedPowersLength - 1].decimal_exponent;
134 143
135 void GetCachedPowerForBinaryExponentRange(int min_exponent, 144 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
136 int max_exponent, 145 int min_exponent,
137 DiyFp* power, 146 int max_exponent,
138 int* decimal_exponent) { 147 DiyFp* power,
139 int kQ = DiyFp::kSignificandSize; 148 int* decimal_exponent) {
140 double k = ceiling((min_exponent + kQ - 1) * kD_1_LOG2_10); 149 int kQ = DiyFp::kSignificandSize;
141 int foo = kCachedPowersOffset; 150 double k = ceiling((min_exponent + kQ - 1) * kD_1_LOG2_10);
142 int index = 151 int foo = kCachedPowersOffset;
143 (foo + static_cast<int>(k) - 1) / kCachedPowersDecimalDistance + 1; 152 int index =
144 ASSERT(0 <= index && index < kCachedPowersLength); 153 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1;
145 CachedPower cached_power = kCachedPowers[index]; 154 ASSERT(0 <= index && index < kCachedPowersLength);
146 ASSERT(min_exponent <= cached_power.binary_exponent); 155 CachedPower cached_power = kCachedPowers[index];
147 ASSERT(cached_power.binary_exponent <= max_exponent); 156 ASSERT(min_exponent <= cached_power.binary_exponent);
148 *decimal_exponent = cached_power.decimal_exponent; 157 ASSERT(cached_power.binary_exponent <= max_exponent);
149 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); 158 *decimal_exponent = cached_power.decimal_exponent;
159 *power = DiyFp(cached_power.significand, cached_power.binary_exponent);
160 }
161
162
163 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent,
164 DiyFp* power,
165 int* found_exponent) {
166 ASSERT(kMinDecimalExponent <= requested_exponent);
167 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance);
168 int index =
169 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance;
170 CachedPower cached_power = kCachedPowers[index];
171 *power = DiyFp(cached_power.significand, cached_power.binary_exponent);
172 *found_exponent = cached_power.decimal_exponent;
173 ASSERT(*found_exponent <= requested_exponent);
174 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance);
150 } 175 }
151 176
152 } } // namespace v8::internal 177 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/cached-powers.h ('k') | src/double.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698