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

Side by Side Diff: Source/wtf/dtoa/cached-powers.cc

Issue 397733004: Allow assertions to be enabled in Blink Release builds. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/wtf/WeakPtr.h ('k') | Source/wtf/text/ASCIIFastPath.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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 {UINT64_2PART_C(0x9e19db92, b4e31ba9), 1013, 324}, 133 {UINT64_2PART_C(0x9e19db92, b4e31ba9), 1013, 324},
134 {UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332}, 134 {UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332},
135 {UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340}, 135 {UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340},
136 }; 136 };
137 static const int kCachedPowersOffset = 348; // -kCachedPowers[0].decimal_exp onent 137 static const int kCachedPowersOffset = 348; // -kCachedPowers[0].decimal_exp onent
138 138
139 const int PowersOfTenCache::kDecimalExponentDistance = 8; // kCachedPowers[1 ].decimal_exponent - kCachedPowers[0].decimal_exponent 139 const int PowersOfTenCache::kDecimalExponentDistance = 8; // kCachedPowers[1 ].decimal_exponent - kCachedPowers[0].decimal_exponent
140 const int PowersOfTenCache::kMinDecimalExponent = -348; // kCachedPowers[0]. decimal_exponent 140 const int PowersOfTenCache::kMinDecimalExponent = -348; // kCachedPowers[0]. decimal_exponent
141 const int PowersOfTenCache::kMaxDecimalExponent = 340; // kCachedPowers[kCac hedPowersLength - 1].decimal_exponent 141 const int PowersOfTenCache::kMaxDecimalExponent = 340; // kCachedPowers[kCac hedPowersLength - 1].decimal_exponent
142 142
143 #ifndef NDEBUG
144 #if ENABLE(ASSERT) 143 #if ENABLE(ASSERT)
145 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); 144 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers);
146 #endif
147 145
148 // Check that the static constants match the values in kCachedPowers. 146 // Check that the static constants match the values in kCachedPowers.
149 static void validateStaticConstants() { 147 static void validateStaticConstants() {
150 ASSERT(kCachedPowersOffset == -kCachedPowers[0].decimal_exponent); 148 ASSERT(kCachedPowersOffset == -kCachedPowers[0].decimal_exponent);
151 ASSERT(PowersOfTenCache::kDecimalExponentDistance == (kCachedPowers[1].d ecimal_exponent - kCachedPowers[0].decimal_exponent)); 149 ASSERT(PowersOfTenCache::kDecimalExponentDistance == (kCachedPowers[1].d ecimal_exponent - kCachedPowers[0].decimal_exponent));
152 ASSERT(PowersOfTenCache::kMinDecimalExponent == kCachedPowers[0].decimal _exponent); 150 ASSERT(PowersOfTenCache::kMinDecimalExponent == kCachedPowers[0].decimal _exponent);
153 ASSERT(PowersOfTenCache::kMaxDecimalExponent == kCachedPowers[kCachedPow ersLength - 1].decimal_exponent); 151 ASSERT(PowersOfTenCache::kMaxDecimalExponent == kCachedPowers[kCachedPow ersLength - 1].decimal_exponent);
154 } 152 }
155 #endif 153 #endif
156 154
157 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( 155 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
158 int min_exponent , 156 int min_exponent ,
159 int max_exponent , 157 int max_exponent ,
160 DiyFp* power, 158 DiyFp* power,
161 int* decimal_exp onent) { 159 int* decimal_exp onent) {
162 #ifndef NDEBUG 160 #if ENABLE(ASSERT)
163 validateStaticConstants(); 161 validateStaticConstants();
164 #endif 162 #endif
165 int kQ = DiyFp::kSignificandSize; 163 int kQ = DiyFp::kSignificandSize;
166 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); 164 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10);
167 int foo = kCachedPowersOffset; 165 int foo = kCachedPowersOffset;
168 int index = 166 int index =
169 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; 167 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1;
170 ASSERT(0 <= index && index < kCachedPowersLength); 168 ASSERT(0 <= index && index < kCachedPowersLength);
171 CachedPower cached_power = kCachedPowers[index]; 169 CachedPower cached_power = kCachedPowers[index];
172 ASSERT(min_exponent <= cached_power.binary_exponent); 170 ASSERT(min_exponent <= cached_power.binary_exponent);
173 ASSERT(cached_power.binary_exponent <= max_exponent); 171 ASSERT(cached_power.binary_exponent <= max_exponent);
174 *decimal_exponent = cached_power.decimal_exponent; 172 *decimal_exponent = cached_power.decimal_exponent;
175 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); 173 *power = DiyFp(cached_power.significand, cached_power.binary_exponent);
176 } 174 }
177 175
178 176
179 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_expone nt, 177 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_expone nt,
180 DiyFp* power, 178 DiyFp* power,
181 int* found_exponent) { 179 int* found_exponent) {
182 ASSERT(kMinDecimalExponent <= requested_exponent); 180 ASSERT(kMinDecimalExponent <= requested_exponent);
183 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistan ce); 181 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistan ce);
184 #ifndef NDEBUG 182 #if ENABLE(ASSERT)
185 validateStaticConstants(); 183 validateStaticConstants();
186 #endif 184 #endif
187 int index = 185 int index =
188 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; 186 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance;
189 CachedPower cached_power = kCachedPowers[index]; 187 CachedPower cached_power = kCachedPowers[index];
190 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); 188 *power = DiyFp(cached_power.significand, cached_power.binary_exponent);
191 *found_exponent = cached_power.decimal_exponent; 189 *found_exponent = cached_power.decimal_exponent;
192 ASSERT(*found_exponent <= requested_exponent); 190 ASSERT(*found_exponent <= requested_exponent);
193 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); 191 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance);
194 } 192 }
195 193
196 } // namespace double_conversion 194 } // namespace double_conversion
197 195
198 } // namespace WTF 196 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/WeakPtr.h ('k') | Source/wtf/text/ASCIIFastPath.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698