OLD | NEW |
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 Loading... |
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}, | |
50 {V8_2PART_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, | 45 {V8_2PART_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, |
51 {V8_2PART_UINT64_C(0xab70fe17, c79ac6ca), -1060, -300}, | 46 {V8_2PART_UINT64_C(0xab70fe17, c79ac6ca), -1060, -300}, |
52 {V8_2PART_UINT64_C(0xff77b1fc, bebcdc4f), -1034, -292}, | 47 {V8_2PART_UINT64_C(0xff77b1fc, bebcdc4f), -1034, -292}, |
53 {V8_2PART_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284}, | 48 {V8_2PART_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284}, |
54 {V8_2PART_UINT64_C(0x8dd01fad, 907ffc3c), -980, -276}, | 49 {V8_2PART_UINT64_C(0x8dd01fad, 907ffc3c), -980, -276}, |
55 {V8_2PART_UINT64_C(0xd3515c28, 31559a83), -954, -268}, | 50 {V8_2PART_UINT64_C(0xd3515c28, 31559a83), -954, -268}, |
56 {V8_2PART_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, | 51 {V8_2PART_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, |
57 {V8_2PART_UINT64_C(0xea9c2277, 23ee8bcb), -901, -252}, | 52 {V8_2PART_UINT64_C(0xea9c2277, 23ee8bcb), -901, -252}, |
58 {V8_2PART_UINT64_C(0xaecc4991, 4078536d), -874, -244}, | 53 {V8_2PART_UINT64_C(0xaecc4991, 4078536d), -874, -244}, |
59 {V8_2PART_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, | 54 {V8_2PART_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 {V8_2PART_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, | 122 {V8_2PART_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, |
128 {V8_2PART_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, | 123 {V8_2PART_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, |
129 {V8_2PART_UINT64_C(0x9e19db92, b4e31ba9), 1013, 324}, | 124 {V8_2PART_UINT64_C(0x9e19db92, b4e31ba9), 1013, 324}, |
130 {V8_2PART_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, | 125 {V8_2PART_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, |
131 {V8_2PART_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, | 126 {V8_2PART_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, |
132 }; | 127 }; |
133 | 128 |
134 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); | 129 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); |
135 static const int kCachedPowersOffset = -kCachedPowers[0].decimal_exponent; | 130 static const int kCachedPowersOffset = -kCachedPowers[0].decimal_exponent; |
136 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) | 131 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) |
137 const int PowersOfTenCache::kDecimalExponentDistance = | 132 static const int kCachedPowersDecimalDistance = |
138 kCachedPowers[1].decimal_exponent - kCachedPowers[0].decimal_exponent; | 133 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; | |
143 | 134 |
144 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( | 135 void GetCachedPowerForBinaryExponentRange(int min_exponent, |
145 int min_exponent, | 136 int max_exponent, |
146 int max_exponent, | 137 DiyFp* power, |
147 DiyFp* power, | 138 int* decimal_exponent) { |
148 int* decimal_exponent) { | 139 int kQ = DiyFp::kSignificandSize; |
149 int kQ = DiyFp::kSignificandSize; | 140 double k = ceiling((min_exponent + kQ - 1) * kD_1_LOG2_10); |
150 double k = ceiling((min_exponent + kQ - 1) * kD_1_LOG2_10); | 141 int foo = kCachedPowersOffset; |
151 int foo = kCachedPowersOffset; | 142 int index = |
152 int index = | 143 (foo + static_cast<int>(k) - 1) / kCachedPowersDecimalDistance + 1; |
153 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; | 144 ASSERT(0 <= index && index < kCachedPowersLength); |
154 ASSERT(0 <= index && index < kCachedPowersLength); | 145 CachedPower cached_power = kCachedPowers[index]; |
155 CachedPower cached_power = kCachedPowers[index]; | 146 ASSERT(min_exponent <= cached_power.binary_exponent); |
156 ASSERT(min_exponent <= cached_power.binary_exponent); | 147 ASSERT(cached_power.binary_exponent <= max_exponent); |
157 ASSERT(cached_power.binary_exponent <= max_exponent); | 148 *decimal_exponent = cached_power.decimal_exponent; |
158 *decimal_exponent = cached_power.decimal_exponent; | 149 *power = DiyFp(cached_power.significand, cached_power.binary_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); | |
175 } | 150 } |
176 | 151 |
177 } } // namespace v8::internal | 152 } } // namespace v8::internal |
OLD | NEW |