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

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

Issue 48833002: Move all static constants in dtoa/cached-powers.* to .rodata section (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix Windows build failure Created 7 years, 1 month 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
« no previous file with comments | « Source/wtf/dtoa/cached-powers.h ('k') | no next file » | 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 27 matching lines...) Expand all
38 namespace WTF { 38 namespace WTF {
39 39
40 namespace double_conversion { 40 namespace double_conversion {
41 41
42 struct CachedPower { 42 struct CachedPower {
43 uint64_t significand; 43 uint64_t significand;
44 int16_t binary_exponent; 44 int16_t binary_exponent;
45 int16_t decimal_exponent; 45 int16_t decimal_exponent;
46 }; 46 };
47 47
48 static int kCachedPowersLength = 1;
49 static int kCachedPowersOffset = 1;
50 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) 48 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10)
51 static CachedPower* kCachedPowers = 0; 49 static const CachedPower kCachedPowers[] = {
50 {UINT64_2PART_C(0xfa8fd5a0, 081c0288), -1220, -348},
51 {UINT64_2PART_C(0xbaaee17f, a23ebf76), -1193, -340},
52 {UINT64_2PART_C(0x8b16fb20, 3055ac76), -1166, -332},
53 {UINT64_2PART_C(0xcf42894a, 5dce35ea), -1140, -324},
54 {UINT64_2PART_C(0x9a6bb0aa, 55653b2d), -1113, -316},
55 {UINT64_2PART_C(0xe61acf03, 3d1a45df), -1087, -308},
56 {UINT64_2PART_C(0xab70fe17, c79ac6ca), -1060, -300},
57 {UINT64_2PART_C(0xff77b1fc, bebcdc4f), -1034, -292},
58 {UINT64_2PART_C(0xbe5691ef, 416bd60c), -1007, -284},
59 {UINT64_2PART_C(0x8dd01fad, 907ffc3c), -980, -276},
60 {UINT64_2PART_C(0xd3515c28, 31559a83), -954, -268},
61 {UINT64_2PART_C(0x9d71ac8f, ada6c9b5), -927, -260},
62 {UINT64_2PART_C(0xea9c2277, 23ee8bcb), -901, -252},
63 {UINT64_2PART_C(0xaecc4991, 4078536d), -874, -244},
64 {UINT64_2PART_C(0x823c1279, 5db6ce57), -847, -236},
65 {UINT64_2PART_C(0xc2109436, 4dfb5637), -821, -228},
66 {UINT64_2PART_C(0x9096ea6f, 3848984f), -794, -220},
67 {UINT64_2PART_C(0xd77485cb, 25823ac7), -768, -212},
68 {UINT64_2PART_C(0xa086cfcd, 97bf97f4), -741, -204},
69 {UINT64_2PART_C(0xef340a98, 172aace5), -715, -196},
70 {UINT64_2PART_C(0xb23867fb, 2a35b28e), -688, -188},
71 {UINT64_2PART_C(0x84c8d4df, d2c63f3b), -661, -180},
72 {UINT64_2PART_C(0xc5dd4427, 1ad3cdba), -635, -172},
73 {UINT64_2PART_C(0x936b9fce, bb25c996), -608, -164},
74 {UINT64_2PART_C(0xdbac6c24, 7d62a584), -582, -156},
75 {UINT64_2PART_C(0xa3ab6658, 0d5fdaf6), -555, -148},
76 {UINT64_2PART_C(0xf3e2f893, dec3f126), -529, -140},
77 {UINT64_2PART_C(0xb5b5ada8, aaff80b8), -502, -132},
78 {UINT64_2PART_C(0x87625f05, 6c7c4a8b), -475, -124},
79 {UINT64_2PART_C(0xc9bcff60, 34c13053), -449, -116},
80 {UINT64_2PART_C(0x964e858c, 91ba2655), -422, -108},
81 {UINT64_2PART_C(0xdff97724, 70297ebd), -396, -100},
82 {UINT64_2PART_C(0xa6dfbd9f, b8e5b88f), -369, -92},
83 {UINT64_2PART_C(0xf8a95fcf, 88747d94), -343, -84},
84 {UINT64_2PART_C(0xb9447093, 8fa89bcf), -316, -76},
85 {UINT64_2PART_C(0x8a08f0f8, bf0f156b), -289, -68},
86 {UINT64_2PART_C(0xcdb02555, 653131b6), -263, -60},
87 {UINT64_2PART_C(0x993fe2c6, d07b7fac), -236, -52},
88 {UINT64_2PART_C(0xe45c10c4, 2a2b3b06), -210, -44},
89 {UINT64_2PART_C(0xaa242499, 697392d3), -183, -36},
90 {UINT64_2PART_C(0xfd87b5f2, 8300ca0e), -157, -28},
91 {UINT64_2PART_C(0xbce50864, 92111aeb), -130, -20},
92 {UINT64_2PART_C(0x8cbccc09, 6f5088cc), -103, -12},
93 {UINT64_2PART_C(0xd1b71758, e219652c), -77, -4},
94 {UINT64_2PART_C(0x9c400000, 00000000), -50, 4},
95 {UINT64_2PART_C(0xe8d4a510, 00000000), -24, 12},
96 {UINT64_2PART_C(0xad78ebc5, ac620000), 3, 20},
97 {UINT64_2PART_C(0x813f3978, f8940984), 30, 28},
98 {UINT64_2PART_C(0xc097ce7b, c90715b3), 56, 36},
99 {UINT64_2PART_C(0x8f7e32ce, 7bea5c70), 83, 44},
100 {UINT64_2PART_C(0xd5d238a4, abe98068), 109, 52},
101 {UINT64_2PART_C(0x9f4f2726, 179a2245), 136, 60},
102 {UINT64_2PART_C(0xed63a231, d4c4fb27), 162, 68},
103 {UINT64_2PART_C(0xb0de6538, 8cc8ada8), 189, 76},
104 {UINT64_2PART_C(0x83c7088e, 1aab65db), 216, 84},
105 {UINT64_2PART_C(0xc45d1df9, 42711d9a), 242, 92},
106 {UINT64_2PART_C(0x924d692c, a61be758), 269, 100},
107 {UINT64_2PART_C(0xda01ee64, 1a708dea), 295, 108},
108 {UINT64_2PART_C(0xa26da399, 9aef774a), 322, 116},
109 {UINT64_2PART_C(0xf209787b, b47d6b85), 348, 124},
110 {UINT64_2PART_C(0xb454e4a1, 79dd1877), 375, 132},
111 {UINT64_2PART_C(0x865b8692, 5b9bc5c2), 402, 140},
112 {UINT64_2PART_C(0xc83553c5, c8965d3d), 428, 148},
113 {UINT64_2PART_C(0x952ab45c, fa97a0b3), 455, 156},
114 {UINT64_2PART_C(0xde469fbd, 99a05fe3), 481, 164},
115 {UINT64_2PART_C(0xa59bc234, db398c25), 508, 172},
116 {UINT64_2PART_C(0xf6c69a72, a3989f5c), 534, 180},
117 {UINT64_2PART_C(0xb7dcbf53, 54e9bece), 561, 188},
118 {UINT64_2PART_C(0x88fcf317, f22241e2), 588, 196},
119 {UINT64_2PART_C(0xcc20ce9b, d35c78a5), 614, 204},
120 {UINT64_2PART_C(0x98165af3, 7b2153df), 641, 212},
121 {UINT64_2PART_C(0xe2a0b5dc, 971f303a), 667, 220},
122 {UINT64_2PART_C(0xa8d9d153, 5ce3b396), 694, 228},
123 {UINT64_2PART_C(0xfb9b7cd9, a4a7443c), 720, 236},
124 {UINT64_2PART_C(0xbb764c4c, a7a44410), 747, 244},
125 {UINT64_2PART_C(0x8bab8eef, b6409c1a), 774, 252},
126 {UINT64_2PART_C(0xd01fef10, a657842c), 800, 260},
127 {UINT64_2PART_C(0x9b10a4e5, e9913129), 827, 268},
128 {UINT64_2PART_C(0xe7109bfb, a19c0c9d), 853, 276},
129 {UINT64_2PART_C(0xac2820d9, 623bf429), 880, 284},
130 {UINT64_2PART_C(0x80444b5e, 7aa7cf85), 907, 292},
131 {UINT64_2PART_C(0xbf21e440, 03acdd2d), 933, 300},
132 {UINT64_2PART_C(0x8e679c2f, 5e44ff8f), 960, 308},
133 {UINT64_2PART_C(0xd433179d, 9c8cb841), 986, 316},
134 {UINT64_2PART_C(0x9e19db92, b4e31ba9), 1013, 324},
135 {UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332},
136 {UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340},
137 };
138 static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers);
Nico 2013/11/04 20:55:03 This isn't used for anything. Is that intentional?
Inactive 2013/11/04 20:59:28 This is used in 2 assertions in this file so I bel
Nico 2013/11/04 21:04:59 Ah. I think we usually use `#if !ASSERT_DISABLED`
139 static const int kCachedPowersOffset = 348; // -kCachedPowers[0].decimal_exp onent
52 140
53 int PowersOfTenCache::kDecimalExponentDistance = 1; 141 const int PowersOfTenCache::kDecimalExponentDistance = 8; // kCachedPowers[1 ].decimal_exponent - kCachedPowers[0].decimal_exponent
54 int PowersOfTenCache::kMinDecimalExponent = 1; 142 const int PowersOfTenCache::kMinDecimalExponent = -348; // kCachedPowers[0]. decimal_exponent
55 int PowersOfTenCache::kMaxDecimalExponent = 1; 143 const int PowersOfTenCache::kMaxDecimalExponent = 340; // kCachedPowers[kCac hedPowersLength - 1].decimal_exponent
56 144
57 void initialize() { 145 #ifndef NDEBUG
58 if (kCachedPowers) 146 // Check that the static constants match the values in kCachedPowers.
59 return; 147 static void validateStaticConstants() {
60 static CachedPower cachedPowers[] = { 148 ASSERT(kCachedPowersOffset == -kCachedPowers[0].decimal_exponent);
61 {UINT64_2PART_C(0xfa8fd5a0, 081c0288), -1220, -348}, 149 ASSERT(PowersOfTenCache::kDecimalExponentDistance == (kCachedPowers[1].d ecimal_exponent - kCachedPowers[0].decimal_exponent));
62 {UINT64_2PART_C(0xbaaee17f, a23ebf76), -1193, -340}, 150 ASSERT(PowersOfTenCache::kMinDecimalExponent == kCachedPowers[0].decimal _exponent);
63 {UINT64_2PART_C(0x8b16fb20, 3055ac76), -1166, -332}, 151 ASSERT(PowersOfTenCache::kMaxDecimalExponent == kCachedPowers[kCachedPow ersLength - 1].decimal_exponent);
64 {UINT64_2PART_C(0xcf42894a, 5dce35ea), -1140, -324},
65 {UINT64_2PART_C(0x9a6bb0aa, 55653b2d), -1113, -316},
66 {UINT64_2PART_C(0xe61acf03, 3d1a45df), -1087, -308},
67 {UINT64_2PART_C(0xab70fe17, c79ac6ca), -1060, -300},
68 {UINT64_2PART_C(0xff77b1fc, bebcdc4f), -1034, -292},
69 {UINT64_2PART_C(0xbe5691ef, 416bd60c), -1007, -284},
70 {UINT64_2PART_C(0x8dd01fad, 907ffc3c), -980, -276},
71 {UINT64_2PART_C(0xd3515c28, 31559a83), -954, -268},
72 {UINT64_2PART_C(0x9d71ac8f, ada6c9b5), -927, -260},
73 {UINT64_2PART_C(0xea9c2277, 23ee8bcb), -901, -252},
74 {UINT64_2PART_C(0xaecc4991, 4078536d), -874, -244},
75 {UINT64_2PART_C(0x823c1279, 5db6ce57), -847, -236},
76 {UINT64_2PART_C(0xc2109436, 4dfb5637), -821, -228},
77 {UINT64_2PART_C(0x9096ea6f, 3848984f), -794, -220},
78 {UINT64_2PART_C(0xd77485cb, 25823ac7), -768, -212},
79 {UINT64_2PART_C(0xa086cfcd, 97bf97f4), -741, -204},
80 {UINT64_2PART_C(0xef340a98, 172aace5), -715, -196},
81 {UINT64_2PART_C(0xb23867fb, 2a35b28e), -688, -188},
82 {UINT64_2PART_C(0x84c8d4df, d2c63f3b), -661, -180},
83 {UINT64_2PART_C(0xc5dd4427, 1ad3cdba), -635, -172},
84 {UINT64_2PART_C(0x936b9fce, bb25c996), -608, -164},
85 {UINT64_2PART_C(0xdbac6c24, 7d62a584), -582, -156},
86 {UINT64_2PART_C(0xa3ab6658, 0d5fdaf6), -555, -148},
87 {UINT64_2PART_C(0xf3e2f893, dec3f126), -529, -140},
88 {UINT64_2PART_C(0xb5b5ada8, aaff80b8), -502, -132},
89 {UINT64_2PART_C(0x87625f05, 6c7c4a8b), -475, -124},
90 {UINT64_2PART_C(0xc9bcff60, 34c13053), -449, -116},
91 {UINT64_2PART_C(0x964e858c, 91ba2655), -422, -108},
92 {UINT64_2PART_C(0xdff97724, 70297ebd), -396, -100},
93 {UINT64_2PART_C(0xa6dfbd9f, b8e5b88f), -369, -92},
94 {UINT64_2PART_C(0xf8a95fcf, 88747d94), -343, -84},
95 {UINT64_2PART_C(0xb9447093, 8fa89bcf), -316, -76},
96 {UINT64_2PART_C(0x8a08f0f8, bf0f156b), -289, -68},
97 {UINT64_2PART_C(0xcdb02555, 653131b6), -263, -60},
98 {UINT64_2PART_C(0x993fe2c6, d07b7fac), -236, -52},
99 {UINT64_2PART_C(0xe45c10c4, 2a2b3b06), -210, -44},
100 {UINT64_2PART_C(0xaa242499, 697392d3), -183, -36},
101 {UINT64_2PART_C(0xfd87b5f2, 8300ca0e), -157, -28},
102 {UINT64_2PART_C(0xbce50864, 92111aeb), -130, -20},
103 {UINT64_2PART_C(0x8cbccc09, 6f5088cc), -103, -12},
104 {UINT64_2PART_C(0xd1b71758, e219652c), -77, -4},
105 {UINT64_2PART_C(0x9c400000, 00000000), -50, 4},
106 {UINT64_2PART_C(0xe8d4a510, 00000000), -24, 12},
107 {UINT64_2PART_C(0xad78ebc5, ac620000), 3, 20},
108 {UINT64_2PART_C(0x813f3978, f8940984), 30, 28},
109 {UINT64_2PART_C(0xc097ce7b, c90715b3), 56, 36},
110 {UINT64_2PART_C(0x8f7e32ce, 7bea5c70), 83, 44},
111 {UINT64_2PART_C(0xd5d238a4, abe98068), 109, 52},
112 {UINT64_2PART_C(0x9f4f2726, 179a2245), 136, 60},
113 {UINT64_2PART_C(0xed63a231, d4c4fb27), 162, 68},
114 {UINT64_2PART_C(0xb0de6538, 8cc8ada8), 189, 76},
115 {UINT64_2PART_C(0x83c7088e, 1aab65db), 216, 84},
116 {UINT64_2PART_C(0xc45d1df9, 42711d9a), 242, 92},
117 {UINT64_2PART_C(0x924d692c, a61be758), 269, 100},
118 {UINT64_2PART_C(0xda01ee64, 1a708dea), 295, 108},
119 {UINT64_2PART_C(0xa26da399, 9aef774a), 322, 116},
120 {UINT64_2PART_C(0xf209787b, b47d6b85), 348, 124},
121 {UINT64_2PART_C(0xb454e4a1, 79dd1877), 375, 132},
122 {UINT64_2PART_C(0x865b8692, 5b9bc5c2), 402, 140},
123 {UINT64_2PART_C(0xc83553c5, c8965d3d), 428, 148},
124 {UINT64_2PART_C(0x952ab45c, fa97a0b3), 455, 156},
125 {UINT64_2PART_C(0xde469fbd, 99a05fe3), 481, 164},
126 {UINT64_2PART_C(0xa59bc234, db398c25), 508, 172},
127 {UINT64_2PART_C(0xf6c69a72, a3989f5c), 534, 180},
128 {UINT64_2PART_C(0xb7dcbf53, 54e9bece), 561, 188},
129 {UINT64_2PART_C(0x88fcf317, f22241e2), 588, 196},
130 {UINT64_2PART_C(0xcc20ce9b, d35c78a5), 614, 204},
131 {UINT64_2PART_C(0x98165af3, 7b2153df), 641, 212},
132 {UINT64_2PART_C(0xe2a0b5dc, 971f303a), 667, 220},
133 {UINT64_2PART_C(0xa8d9d153, 5ce3b396), 694, 228},
134 {UINT64_2PART_C(0xfb9b7cd9, a4a7443c), 720, 236},
135 {UINT64_2PART_C(0xbb764c4c, a7a44410), 747, 244},
136 {UINT64_2PART_C(0x8bab8eef, b6409c1a), 774, 252},
137 {UINT64_2PART_C(0xd01fef10, a657842c), 800, 260},
138 {UINT64_2PART_C(0x9b10a4e5, e9913129), 827, 268},
139 {UINT64_2PART_C(0xe7109bfb, a19c0c9d), 853, 276},
140 {UINT64_2PART_C(0xac2820d9, 623bf429), 880, 284},
141 {UINT64_2PART_C(0x80444b5e, 7aa7cf85), 907, 292},
142 {UINT64_2PART_C(0xbf21e440, 03acdd2d), 933, 300},
143 {UINT64_2PART_C(0x8e679c2f, 5e44ff8f), 960, 308},
144 {UINT64_2PART_C(0xd433179d, 9c8cb841), 986, 316},
145 {UINT64_2PART_C(0x9e19db92, b4e31ba9), 1013, 324},
146 {UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332},
147 {UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340},
148 };
149 kCachedPowers = cachedPowers;
150 kCachedPowersLength = ARRAY_SIZE(cachedPowers);
151 kCachedPowersOffset = -cachedPowers[0].decimal_exponent;
152 PowersOfTenCache::kDecimalExponentDistance = kCachedPowers[1].decimal_ex ponent - kCachedPowers[0].decimal_exponent;
153 PowersOfTenCache::kMinDecimalExponent = kCachedPowers[0].decimal_exponen t;
154 PowersOfTenCache::kMaxDecimalExponent = kCachedPowers[kCachedPowersLengt h - 1].decimal_exponent;
155 } 152 }
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 UNUSED_PARAM(max_exponent); 160 UNUSED_PARAM(max_exponent);
161 #ifndef NDEBUG
162 validateStaticConstants();
163 #endif
163 int kQ = DiyFp::kSignificandSize; 164 int kQ = DiyFp::kSignificandSize;
164 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); 165 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10);
165 int foo = kCachedPowersOffset; 166 int foo = kCachedPowersOffset;
166 int index = 167 int index =
167 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; 168 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1;
168 ASSERT(0 <= index && index < kCachedPowersLength); 169 ASSERT(0 <= index && index < kCachedPowersLength);
169 CachedPower cached_power = kCachedPowers[index]; 170 CachedPower cached_power = kCachedPowers[index];
170 ASSERT(min_exponent <= cached_power.binary_exponent); 171 ASSERT(min_exponent <= cached_power.binary_exponent);
171 ASSERT(cached_power.binary_exponent <= max_exponent); 172 ASSERT(cached_power.binary_exponent <= max_exponent);
172 *decimal_exponent = cached_power.decimal_exponent; 173 *decimal_exponent = cached_power.decimal_exponent;
173 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); 174 *power = DiyFp(cached_power.significand, cached_power.binary_exponent);
174 } 175 }
175 176
176 177
177 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_expone nt, 178 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_expone nt,
178 DiyFp* power, 179 DiyFp* power,
179 int* found_exponent) { 180 int* found_exponent) {
180 ASSERT(kMinDecimalExponent <= requested_exponent); 181 ASSERT(kMinDecimalExponent <= requested_exponent);
181 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistan ce); 182 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistan ce);
183 #ifndef NDEBUG
184 validateStaticConstants();
185 #endif
182 int index = 186 int index =
183 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; 187 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance;
184 CachedPower cached_power = kCachedPowers[index]; 188 CachedPower cached_power = kCachedPowers[index];
185 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); 189 *power = DiyFp(cached_power.significand, cached_power.binary_exponent);
186 *found_exponent = cached_power.decimal_exponent; 190 *found_exponent = cached_power.decimal_exponent;
187 ASSERT(*found_exponent <= requested_exponent); 191 ASSERT(*found_exponent <= requested_exponent);
188 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); 192 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance);
189 } 193 }
190 194
191 } // namespace double_conversion 195 } // namespace double_conversion
192 196
193 } // namespace WTF 197 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/dtoa/cached-powers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698