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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 int k = ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); \ | 68 double k = ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); \ |
69 int index = (GRISU_CACHE_OFFSET + k - 1) / i + 1; \ | 69 int index = (GRISU_CACHE_OFFSET + static_cast<int>(k) - 1) / i + 1; \ |
70 cached_power = GRISU_CACHE_NAME(i)[index]; \ | 70 cached_power = GRISU_CACHE_NAME(i)[index]; \ |
71 found = true; \ | 71 found = true; \ |
72 } \ | 72 } \ |
73 | 73 |
74 static void GetCachedPower(int e, int alpha, int gamma, int* mk, DiyFp* c_mk) { | 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 | 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. | 76 // one array is referenced and the others are not included in the object file. |
77 bool found = false; | 77 bool found = false; |
78 CachedPower cached_power; | 78 CachedPower cached_power; |
79 COMPUTE_FOR_CACHE(20); | 79 COMPUTE_FOR_CACHE(20); |
(...skipping 30 matching lines...) Expand all 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 |