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

Side by Side Diff: src/types-inl.h

Issue 882063002: [turbofan] Use unboxed doubles in range types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Make tests less fragile. Created 5 years, 10 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
« no previous file with comments | « src/types.cc ('k') | test/cctest/compiler/test-simplified-lowering.cc » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_TYPES_INL_H_ 5 #ifndef V8_TYPES_INL_H_
6 #define V8_TYPES_INL_H_ 6 #define V8_TYPES_INL_H_
7 7
8 #include "src/types.h" 8 #include "src/types.h"
9 9
10 #include "src/factory.h" 10 #include "src/factory.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 90
91 // static 91 // static
92 bool ZoneTypeConfig::is_bitset(Type* type) { 92 bool ZoneTypeConfig::is_bitset(Type* type) {
93 return reinterpret_cast<uintptr_t>(type) & 1; 93 return reinterpret_cast<uintptr_t>(type) & 1;
94 } 94 }
95 95
96 96
97 // static 97 // static
98 bool ZoneTypeConfig::is_struct(Type* type, int tag) { 98 bool ZoneTypeConfig::is_struct(Type* type, int tag) {
99 return !is_bitset(type) && struct_tag(as_struct(type)) == tag; 99 DCHECK(tag != kRangeStructTag);
100 if (is_bitset(type)) return false;
101 int type_tag = struct_tag(as_struct(type));
102 return type_tag == tag;
100 } 103 }
101 104
102 105
106 // static
107 bool ZoneTypeConfig::is_range(Type* type) {
108 if (is_bitset(type)) return false;
109 int type_tag = struct_tag(as_struct(type));
110 return type_tag == kRangeStructTag;
111 }
112
113
103 // static 114 // static
104 bool ZoneTypeConfig::is_class(Type* type) { 115 bool ZoneTypeConfig::is_class(Type* type) {
105 return false; 116 return false;
106 } 117 }
107 118
108 119
109 // static 120 // static
110 ZoneTypeConfig::Type::bitset ZoneTypeConfig::as_bitset(Type* type) { 121 ZoneTypeConfig::Type::bitset ZoneTypeConfig::as_bitset(Type* type) {
111 DCHECK(is_bitset(type)); 122 DCHECK(is_bitset(type));
112 return static_cast<Type::bitset>(reinterpret_cast<uintptr_t>(type) ^ 1u); 123 return static_cast<Type::bitset>(reinterpret_cast<uintptr_t>(type) ^ 1u);
113 } 124 }
114 125
115 126
116 // static 127 // static
117 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) { 128 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) {
118 DCHECK(!is_bitset(type)); 129 DCHECK(!is_bitset(type));
119 return reinterpret_cast<Struct*>(type); 130 return reinterpret_cast<Struct*>(type);
120 } 131 }
121 132
122 133
123 // static 134 // static
135 ZoneTypeConfig::Range* ZoneTypeConfig::as_range(Type* type) {
136 DCHECK(!is_bitset(type));
137 return reinterpret_cast<Range*>(type);
138 }
139
140
141 // static
124 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { 142 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) {
125 UNREACHABLE(); 143 UNREACHABLE();
126 return i::Handle<i::Map>(); 144 return i::Handle<i::Map>();
127 } 145 }
128 146
129 147
130 // static 148 // static
131 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(Type::bitset bitset) { 149 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(Type::bitset bitset) {
132 return reinterpret_cast<Type*>(static_cast<uintptr_t>(bitset | 1u)); 150 return reinterpret_cast<Type*>(static_cast<uintptr_t>(bitset | 1u));
133 } 151 }
134 152
135 153
136 // static 154 // static
137 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset( 155 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(
138 Type::bitset bitset, Zone* Zone) { 156 Type::bitset bitset, Zone* Zone) {
139 return from_bitset(bitset); 157 return from_bitset(bitset);
140 } 158 }
141 159
142 160
143 // static 161 // static
144 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structure) { 162 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structure) {
145 return reinterpret_cast<Type*>(structure); 163 return reinterpret_cast<Type*>(structure);
146 } 164 }
147 165
148 166
149 // static 167 // static
168 ZoneTypeConfig::Type* ZoneTypeConfig::from_range(Range* range) {
169 return reinterpret_cast<Type*>(range);
170 }
171
172
173 // static
150 ZoneTypeConfig::Type* ZoneTypeConfig::from_class( 174 ZoneTypeConfig::Type* ZoneTypeConfig::from_class(
151 i::Handle<i::Map> map, Zone* zone) { 175 i::Handle<i::Map> map, Zone* zone) {
152 return from_bitset(0); 176 return from_bitset(0);
153 } 177 }
154 178
155 179
156 // static 180 // static
157 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create( 181 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create(
158 int tag, int length, Zone* zone) { 182 int tag, int length, Zone* zone) {
183 DCHECK(tag != kRangeStructTag);
159 Struct* structure = reinterpret_cast<Struct*>( 184 Struct* structure = reinterpret_cast<Struct*>(
160 zone->New(sizeof(void*) * (length + 2))); // NOLINT 185 zone->New(sizeof(void*) * (length + 2))); // NOLINT
161 structure[0] = reinterpret_cast<void*>(tag); 186 structure[0] = reinterpret_cast<void*>(tag);
162 structure[1] = reinterpret_cast<void*>(length); 187 structure[1] = reinterpret_cast<void*>(length);
163 return structure; 188 return structure;
164 } 189 }
165 190
166 191
167 // static 192 // static
168 void ZoneTypeConfig::struct_shrink(Struct* structure, int length) { 193 void ZoneTypeConfig::struct_shrink(Struct* structure, int length) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 232
208 // static 233 // static
209 template<class V> 234 template<class V>
210 void ZoneTypeConfig::struct_set_value( 235 void ZoneTypeConfig::struct_set_value(
211 Struct* structure, int i, i::Handle<V> x) { 236 Struct* structure, int i, i::Handle<V> x) {
212 DCHECK(0 <= i && i <= struct_length(structure)); 237 DCHECK(0 <= i && i <= struct_length(structure));
213 structure[2 + i] = x.location(); 238 structure[2 + i] = x.location();
214 } 239 }
215 240
216 241
242 // static
243 ZoneTypeConfig::Range* ZoneTypeConfig::range_create(Zone* zone) {
244 Range* range = reinterpret_cast<Range*>(zone->New(sizeof(Range))); // NOLINT
245 range->tag = reinterpret_cast<void*>(kRangeStructTag);
246 range->bitset = 0;
247 range->limits[0] = 1;
248 range->limits[1] = 0;
249 return range;
250 }
251
252
253 // static
254 int ZoneTypeConfig::range_get_bitset(ZoneTypeConfig::Range* range) {
255 return range->bitset;
256 }
257
258
259 // static
260 void ZoneTypeConfig::range_set_bitset(ZoneTypeConfig::Range* range, int value) {
261 range->bitset = value;
262 }
263
264
265 // static
266 double ZoneTypeConfig::range_get_double(ZoneTypeConfig::Range* range,
267 int index) {
268 DCHECK(index >= 0 && index < 2);
269 return range->limits[index];
270 }
271
272
273 // static
274 void ZoneTypeConfig::range_set_double(ZoneTypeConfig::Range* range, int index,
275 double value, Zone*) {
276 DCHECK(index >= 0 && index < 2);
277 range->limits[index] = value;
278 }
279
280
217 // ----------------------------------------------------------------------------- 281 // -----------------------------------------------------------------------------
218 // HeapTypeConfig 282 // HeapTypeConfig
219 283
220 // static 284 // static
221 template<class T> 285 template<class T>
222 i::Handle<T> HeapTypeConfig::null_handle() { 286 i::Handle<T> HeapTypeConfig::null_handle() {
223 return i::Handle<T>(); 287 return i::Handle<T>();
224 } 288 }
225 289
226 290
(...skipping 18 matching lines...) Expand all
245 309
246 310
247 // static 311 // static
248 bool HeapTypeConfig::is_class(Type* type) { 312 bool HeapTypeConfig::is_class(Type* type) {
249 return type->IsMap(); 313 return type->IsMap();
250 } 314 }
251 315
252 316
253 // static 317 // static
254 bool HeapTypeConfig::is_struct(Type* type, int tag) { 318 bool HeapTypeConfig::is_struct(Type* type, int tag) {
319 DCHECK(tag != kRangeStructTag);
255 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag; 320 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag;
256 } 321 }
257 322
258 323
259 // static 324 // static
325 bool HeapTypeConfig::is_range(Type* type) {
326 return type->IsFixedArray() && struct_tag(as_struct(type)) == kRangeStructTag;
327 }
328
329
330 // static
260 HeapTypeConfig::Type::bitset HeapTypeConfig::as_bitset(Type* type) { 331 HeapTypeConfig::Type::bitset HeapTypeConfig::as_bitset(Type* type) {
261 // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way. 332 // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way.
262 return static_cast<Type::bitset>(reinterpret_cast<uintptr_t>(type)); 333 return static_cast<Type::bitset>(reinterpret_cast<uintptr_t>(type));
263 } 334 }
264 335
265 336
266 // static 337 // static
267 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { 338 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) {
268 return i::handle(i::Map::cast(type)); 339 return i::handle(i::Map::cast(type));
269 } 340 }
270 341
271 342
272 // static 343 // static
273 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) { 344 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) {
274 return i::handle(Struct::cast(type)); 345 return i::handle(Struct::cast(type));
275 } 346 }
276 347
277 348
278 // static 349 // static
350 i::Handle<HeapTypeConfig::Range> HeapTypeConfig::as_range(Type* type) {
351 return i::handle(Range::cast(type));
352 }
353
354
355 // static
279 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(Type::bitset bitset) { 356 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(Type::bitset bitset) {
280 // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way. 357 // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way.
281 return reinterpret_cast<Type*>(static_cast<uintptr_t>(bitset)); 358 return reinterpret_cast<Type*>(static_cast<uintptr_t>(bitset));
282 } 359 }
283 360
284 361
285 // static 362 // static
286 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset( 363 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset(
287 Type::bitset bitset, Isolate* isolate) { 364 Type::bitset bitset, Isolate* isolate) {
288 return i::handle(from_bitset(bitset), isolate); 365 return i::handle(from_bitset(bitset), isolate);
289 } 366 }
290 367
291 368
292 // static 369 // static
293 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class( 370 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class(
294 i::Handle<i::Map> map, Isolate* isolate) { 371 i::Handle<i::Map> map, Isolate* isolate) {
295 return i::Handle<Type>::cast(i::Handle<Object>::cast(map)); 372 return i::Handle<Type>::cast(i::Handle<Object>::cast(map));
296 } 373 }
297 374
298 375
299 // static 376 // static
300 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_struct( 377 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_struct(
301 i::Handle<Struct> structure) { 378 i::Handle<Struct> structure) {
302 return i::Handle<Type>::cast(i::Handle<Object>::cast(structure)); 379 return i::Handle<Type>::cast(i::Handle<Object>::cast(structure));
303 } 380 }
304 381
305 382
306 // static 383 // static
384 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_range(
385 i::Handle<Range> range) {
386 return i::Handle<Type>::cast(i::Handle<Object>::cast(range));
387 }
388
389
390 // static
307 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::struct_create( 391 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::struct_create(
308 int tag, int length, Isolate* isolate) { 392 int tag, int length, Isolate* isolate) {
309 i::Handle<Struct> structure = isolate->factory()->NewFixedArray(length + 1); 393 i::Handle<Struct> structure = isolate->factory()->NewFixedArray(length + 1);
310 structure->set(0, i::Smi::FromInt(tag)); 394 structure->set(0, i::Smi::FromInt(tag));
311 return structure; 395 return structure;
312 } 396 }
313 397
314 398
315 // static 399 // static
316 void HeapTypeConfig::struct_shrink(i::Handle<Struct> structure, int length) { 400 void HeapTypeConfig::struct_shrink(i::Handle<Struct> structure, int length) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 } 438 }
355 439
356 440
357 // static 441 // static
358 template<class V> 442 template<class V>
359 void HeapTypeConfig::struct_set_value( 443 void HeapTypeConfig::struct_set_value(
360 i::Handle<Struct> structure, int i, i::Handle<V> x) { 444 i::Handle<Struct> structure, int i, i::Handle<V> x) {
361 structure->set(i + 1, *x); 445 structure->set(i + 1, *x);
362 } 446 }
363 447
448
449 // static
450 i::Handle<HeapTypeConfig::Range> HeapTypeConfig::range_create(
451 Isolate* isolate) {
452 i::Handle<Range> range = isolate->factory()->NewFixedArray(4);
453 range->set(0, i::Smi::FromInt(kRangeStructTag));
454 return range;
455 }
456
457
458 // static
459 int HeapTypeConfig::range_get_bitset(i::Handle<HeapTypeConfig::Range> range) {
460 Type* v = static_cast<Type*>(range->get(1));
461 return as_bitset(v);
462 }
463
464
465 // static
466 void HeapTypeConfig::range_set_bitset(i::Handle<HeapTypeConfig::Range> range,
467 int value) {
468 range->set(1, from_bitset(value));
469 }
470
471
472 // static
473 double HeapTypeConfig::range_get_double(i::Handle<HeapTypeConfig::Range> range,
474 int index) {
475 DCHECK(index >= 0 && index < 2);
476 return range->get(index + 2)->Number();
477 }
478
479
480 // static
481 void HeapTypeConfig::range_set_double(i::Handle<HeapTypeConfig::Range> range,
482 int index, double value,
483 Isolate* isolate) {
484 DCHECK(index >= 0 && index < 2);
485 i::Handle<Object> number = isolate->factory()->NewNumber(value);
486 range->set(index + 2, *number);
487 }
364 } } // namespace v8::internal 488 } } // namespace v8::internal
365 489
366 #endif // V8_TYPES_INL_H_ 490 #endif // V8_TYPES_INL_H_
OLDNEW
« no previous file with comments | « src/types.cc ('k') | test/cctest/compiler/test-simplified-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698