| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 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 struct CachedPower { |
| 37 uint64_t significand; | 37 uint64_t significand; |
| 38 int16_t binary_exponent; | 38 int16_t binary_exponent; |
| 39 int16_t decimal_exponent; | 39 int16_t decimal_exponent; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // The following defines implement the interface between this file and the | 42 // The following defines implement the interface between this file and the |
| 43 // generated 'powers_ten.h'. | 43 // generated 'powers_ten.h'. |
| 44 // GRISU_CACHE_NAME(1) contains all possible cached powers. | 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 | 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 | 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). | 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. | 48 // The higher 'i' is the fewer elements we use. |
| 49 // Given that there are less elements, the exponent-distance between two | 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 | 50 // elements in the cache grows. The variable GRISU_CACHE_MAX_DISTANCE(i) stores |
| 51 // the maximum distance between two elements. | 51 // the maximum distance between two elements. |
| 52 #define GRISU_CACHE_STRUCT CachedPower | 52 #define GRISU_CACHE_STRUCT CachedPower |
| 53 #define GRISU_CACHE_NAME(i) kCachedPowers##i | 53 #define GRISU_CACHE_NAME(i) kCachedPowers##i |
| 54 #define GRISU_CACHE_MAX_DISTANCE(i) kCachedPowersMaxDistance##i | 54 #define GRISU_CACHE_MAX_DISTANCE(i) kCachedPowersMaxDistance##i |
| 55 #define GRISU_CACHE_OFFSET kCachedPowerOffset | 55 #define GRISU_CACHE_OFFSET kCachedPowerOffset |
| 56 #define GRISU_UINT64_C V8_2PART_UINT64_C | 56 #define GRISU_UINT64_C V8_2PART_UINT64_C |
| 57 // The following include imports the precompiled cached powers. | 57 // The following include imports the precompiled cached powers. |
| 58 #include "powers_ten.h" // NOLINT | 58 #include "powers-ten.h" // NOLINT |
| 59 | 59 |
| 60 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) | 60 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) |
| 61 | 61 |
| 62 // We can't use a function since we reference variables depending on the 'i'. | 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 | 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. | 64 // cache-array variable is used and thus can remove all the others. |
| 65 #define COMPUTE_FOR_CACHE(i) \ | 65 #define COMPUTE_FOR_CACHE(i) \ |
| 66 if (!found && (gamma - alpha + 1 >= GRISU_CACHE_MAX_DISTANCE(i))) { \ | 66 if (!found && (gamma - alpha + 1 >= GRISU_CACHE_MAX_DISTANCE(i))) { \ |
| 67 int kQ = DiyFp::kSignificandSize; \ | 67 int kQ = DiyFp::kSignificandSize; \ |
| 68 double k = ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); \ | 68 double k = ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); \ |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 #undef GRISU_REDUCTION | 110 #undef GRISU_REDUCTION |
| 111 #undef GRISU_CACHE_STRUCT | 111 #undef GRISU_CACHE_STRUCT |
| 112 #undef GRISU_CACHE_NAME | 112 #undef GRISU_CACHE_NAME |
| 113 #undef GRISU_CACHE_MAX_DISTANCE | 113 #undef GRISU_CACHE_MAX_DISTANCE |
| 114 #undef GRISU_CACHE_OFFSET | 114 #undef GRISU_CACHE_OFFSET |
| 115 #undef GRISU_UINT64_C | 115 #undef GRISU_UINT64_C |
| 116 | 116 |
| 117 } } // namespace v8::internal | 117 } } // namespace v8::internal |
| 118 | 118 |
| 119 #endif // V8_CACHED_POWERS_H_ | 119 #endif // V8_CACHED_POWERS_H_ |
| OLD | NEW |