Chromium Code Reviews| Index: src/cached_powers.h |
| =================================================================== |
| --- src/cached_powers.h (revision 0) |
| +++ src/cached_powers.h (revision 0) |
| @@ -0,0 +1,106 @@ |
| +// Copyright 2010 the V8 project authors. All rights reserved. |
| +// Redistribution and use in source and binary forms, with or without |
| +// modification, are permitted provided that the following conditions are |
| +// met: |
| +// |
| +// * Redistributions of source code must retain the above copyright |
| +// notice, this list of conditions and the following disclaimer. |
| +// * Redistributions in binary form must reproduce the above |
| +// copyright notice, this list of conditions and the following |
| +// disclaimer in the documentation and/or other materials provided |
| +// with the distribution. |
| +// * Neither the name of Google Inc. nor the names of its |
| +// contributors may be used to endorse or promote products derived |
| +// from this software without specific prior written permission. |
| +// |
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + |
| +#ifndef V8_CACHED_POWERS_H_ |
| +#define V8_CACHED_POWERS_H_ |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| +struct CachedPower { |
| + uint64_t significand; |
| + int16_t binary_exponent; |
| + int16_t decimal_exponent; |
| +}; |
| + |
| +#define GRISU_CACHE_STRUCT CachedPower |
|
fschneider
2010/02/22 16:25:24
No reason for this macro?
|
| +#define GRISU_CACHE_NAME(i) kCachedPowers##i |
| +#define GRISU_CACHE_MAX_DISTANCE(i) kCachedPowersMaxDistance##i |
| +#define GRISU_CACHE_OFFSET kCachedPowerOffset |
|
fschneider
2010/02/22 16:25:24
No reason for this macro either.
|
| +#define GRISU_UINT64_C V8_2PART_UINT64_C |
|
fschneider
2010/02/22 16:25:24
And this one.
|
| +// The following include imports the precompiled cached powers. |
| +#include "powers_ten.h" // NOLINT |
| + |
| +static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) |
| + |
| +#define COMPUTE_FOR_CACHE(i) \ |
|
fschneider
2010/02/22 16:25:24
If this is performance-critical make an inline fun
|
| + if (!found && (gamma - alpha + 1 >= GRISU_CACHE_MAX_DISTANCE(i))) { \ |
| + int kQ = DiyFp::kSignificandSize; \ |
| + int k = ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); \ |
| + int index = (GRISU_CACHE_OFFSET + k - 1) / i + 1; \ |
| + cached_power = GRISU_CACHE_NAME(i)[index]; \ |
| + found = true; \ |
| + } \ |
| + |
| +static void GetCachedPower(int e, int alpha, int gamma, int* mk, DiyFp* c_mk) { |
| + // The following if statement should be optimized by the compiler so that only |
| + // one array is referenced and the others are not included in the object file. |
| + bool found = false; |
| + CachedPower cached_power; |
| + COMPUTE_FOR_CACHE(20); |
| + COMPUTE_FOR_CACHE(19); |
| + COMPUTE_FOR_CACHE(18); |
| + COMPUTE_FOR_CACHE(17); |
| + COMPUTE_FOR_CACHE(16); |
| + COMPUTE_FOR_CACHE(15); |
| + COMPUTE_FOR_CACHE(14); |
| + COMPUTE_FOR_CACHE(13); |
| + COMPUTE_FOR_CACHE(12); |
| + COMPUTE_FOR_CACHE(11); |
| + COMPUTE_FOR_CACHE(10); |
| + COMPUTE_FOR_CACHE(9); |
| + 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.
|
| + int k = ceiling((alpha - e + DiyFp::kSignificandSize - 1) * kD_1_LOG2_10); |
| + int index = (GRISU_CACHE_OFFSET + k - 1) / 8 + 1; |
| + cached_power = GRISU_CACHE_NAME(8)[index]; |
| + found = true; |
| + } |
| + COMPUTE_FOR_CACHE(8); |
| + COMPUTE_FOR_CACHE(7); |
| + COMPUTE_FOR_CACHE(6); |
| + COMPUTE_FOR_CACHE(5); |
| + COMPUTE_FOR_CACHE(4); |
| + COMPUTE_FOR_CACHE(3); |
| + COMPUTE_FOR_CACHE(2); |
| + COMPUTE_FOR_CACHE(1); |
| + if (!found) { |
| + UNIMPLEMENTED(); |
| + } |
| + *c_mk = DiyFp(cached_power.significand, cached_power.binary_exponent); |
| + *mk = cached_power.decimal_exponent; |
| + ASSERT((alpha <= c_mk->e() + e) && (c_mk->e() + e <= gamma)); |
| +} |
| +#undef GRISU_REDUCTION |
| +#undef GRISU_CACHE_STRUCT |
| +#undef GRISU_CACHE_NAME |
| +#undef GRISU_CACHE_MAX_DISTANCE |
| +#undef GRISU_CACHE_OFFSET |
| +#undef GRISU_UINT64_C |
| + |
| +} } // namespace v8::internal |
| + |
| +#endif // V8_CACHED_POWERS_H_ |