OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
(...skipping 4752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4763 } | 4763 } |
4764 | 4764 |
4765 static const int kDefaultInitialCapacity = 4; | 4765 static const int kDefaultInitialCapacity = 4; |
4766 | 4766 |
4767 FINAL_HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); | 4767 FINAL_HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); |
4768 friend class Array; | 4768 friend class Array; |
4769 friend class Class; | 4769 friend class Class; |
4770 }; | 4770 }; |
4771 | 4771 |
4772 | 4772 |
| 4773 class Float32x4 : public Instance { |
| 4774 public: |
| 4775 static RawFloat32x4* New(float value0, float value1, float value2, |
| 4776 float value3, Heap::Space space = Heap::kNew); |
| 4777 static RawFloat32x4* New(simd_value_t value, Heap::Space space = Heap::kNew); |
| 4778 |
| 4779 float x() const; |
| 4780 float y() const; |
| 4781 float z() const; |
| 4782 float w() const; |
| 4783 |
| 4784 void set_x(float x) const; |
| 4785 void set_y(float y) const; |
| 4786 void set_z(float z) const; |
| 4787 void set_w(float w) const; |
| 4788 |
| 4789 simd_value_t value() const; |
| 4790 void set_value(simd_value_t value) const; |
| 4791 |
| 4792 static intptr_t InstanceSize() { |
| 4793 return RoundedAllocationSize(sizeof(RawFloat32x4)); |
| 4794 } |
| 4795 |
| 4796 static intptr_t value_offset() { |
| 4797 return OFFSET_OF(RawFloat32x4, value_); |
| 4798 } |
| 4799 |
| 4800 private: |
| 4801 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float32x4, Instance); |
| 4802 friend class Class; |
| 4803 }; |
| 4804 |
| 4805 |
| 4806 class Uint32x4 : public Instance { |
| 4807 public: |
| 4808 static RawUint32x4* New(uint32_t value0, uint32_t value1, uint32_t value2, |
| 4809 uint32_t value3, Heap::Space space = Heap::kNew); |
| 4810 static RawUint32x4* New(simd_value_t value, Heap::Space space = Heap::kNew); |
| 4811 |
| 4812 uint32_t x() const; |
| 4813 uint32_t y() const; |
| 4814 uint32_t z() const; |
| 4815 uint32_t w() const; |
| 4816 |
| 4817 void set_x(uint32_t x) const; |
| 4818 void set_y(uint32_t y) const; |
| 4819 void set_z(uint32_t z) const; |
| 4820 void set_w(uint32_t w) const; |
| 4821 |
| 4822 simd_value_t value() const; |
| 4823 void set_value(simd_value_t value) const; |
| 4824 |
| 4825 static intptr_t InstanceSize() { |
| 4826 return RoundedAllocationSize(sizeof(RawUint32x4)); |
| 4827 } |
| 4828 |
| 4829 static intptr_t value_offset() { |
| 4830 return OFFSET_OF(RawUint32x4, value_); |
| 4831 } |
| 4832 |
| 4833 private: |
| 4834 FINAL_HEAP_OBJECT_IMPLEMENTATION(Uint32x4, Instance); |
| 4835 friend class Class; |
| 4836 }; |
| 4837 |
| 4838 |
4773 class ByteArray : public Instance { | 4839 class ByteArray : public Instance { |
4774 public: | 4840 public: |
4775 intptr_t Length() const { | 4841 intptr_t Length() const { |
4776 ASSERT(!IsNull()); | 4842 ASSERT(!IsNull()); |
4777 return Smi::Value(raw_ptr()->length_); | 4843 return Smi::Value(raw_ptr()->length_); |
4778 } | 4844 } |
4779 | 4845 |
4780 static intptr_t length_offset() { | 4846 static intptr_t length_offset() { |
4781 return OFFSET_OF(RawByteArray, length_); | 4847 return OFFSET_OF(RawByteArray, length_); |
4782 } | 4848 } |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5303 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5369 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
5304 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | 5370 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; |
5305 } | 5371 } |
5306 | 5372 |
5307 FINAL_HEAP_OBJECT_IMPLEMENTATION(Uint64Array, ByteArray); | 5373 FINAL_HEAP_OBJECT_IMPLEMENTATION(Uint64Array, ByteArray); |
5308 friend class ByteArray; | 5374 friend class ByteArray; |
5309 friend class Class; | 5375 friend class Class; |
5310 }; | 5376 }; |
5311 | 5377 |
5312 | 5378 |
| 5379 class Float32x4Array : public ByteArray { |
| 5380 public: |
| 5381 intptr_t ByteLength() const { |
| 5382 return Length() * kBytesPerElement; |
| 5383 } |
| 5384 |
| 5385 simd_value_t At(intptr_t index) const { |
| 5386 ASSERT((index >= 0) && (index < Length())); |
| 5387 simd_value_t* load_ptr = &raw_ptr()->data_[index]; |
| 5388 return simd_value_safe_load(load_ptr); |
| 5389 } |
| 5390 |
| 5391 void SetAt(intptr_t index, simd_value_t value) const { |
| 5392 ASSERT((index >= 0) && (index < Length())); |
| 5393 simd_value_t* store_ptr = &raw_ptr()->data_[index]; |
| 5394 simd_value_safe_store(store_ptr, value); |
| 5395 } |
| 5396 |
| 5397 static const intptr_t kBytesPerElement = 16; |
| 5398 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 5399 |
| 5400 static intptr_t data_offset() { |
| 5401 return OFFSET_OF(RawFloat32x4Array, data_); |
| 5402 } |
| 5403 |
| 5404 static intptr_t InstanceSize() { |
| 5405 ASSERT(sizeof(RawFloat32x4Array) == |
| 5406 OFFSET_OF(RawFloat32x4Array, data_)); |
| 5407 return 0; |
| 5408 } |
| 5409 |
| 5410 static intptr_t InstanceSize(intptr_t len) { |
| 5411 ASSERT(0 <= len && len <= kMaxElements); |
| 5412 return RoundedAllocationSize( |
| 5413 sizeof(RawFloat32x4Array) + (len * kBytesPerElement)); |
| 5414 } |
| 5415 |
| 5416 static RawFloat32x4Array* New(intptr_t len, |
| 5417 Heap::Space space = Heap::kNew); |
| 5418 static RawFloat32x4Array* New(const simd_value_t* data, |
| 5419 intptr_t len, |
| 5420 Heap::Space space = Heap::kNew); |
| 5421 |
| 5422 private: |
| 5423 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 5424 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 5425 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; |
| 5426 } |
| 5427 |
| 5428 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float32x4Array, ByteArray); |
| 5429 friend class ByteArray; |
| 5430 friend class Class; |
| 5431 }; |
| 5432 |
| 5433 |
5313 class Float32Array : public ByteArray { | 5434 class Float32Array : public ByteArray { |
5314 public: | 5435 public: |
5315 intptr_t ByteLength() const { | 5436 intptr_t ByteLength() const { |
5316 return Length() * kBytesPerElement; | 5437 return Length() * kBytesPerElement; |
5317 } | 5438 } |
5318 | 5439 |
5319 float At(intptr_t index) const { | 5440 float At(intptr_t index) const { |
5320 ASSERT((index >= 0) && (index < Length())); | 5441 ASSERT((index >= 0) && (index < Length())); |
5321 return raw_ptr()->data_[index]; | 5442 return raw_ptr()->data_[index]; |
5322 } | 5443 } |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5902 void SetPeer(void* peer) const { | 6023 void SetPeer(void* peer) const { |
5903 raw_ptr()->peer_ = peer; | 6024 raw_ptr()->peer_ = peer; |
5904 } | 6025 } |
5905 | 6026 |
5906 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint64Array, ByteArray); | 6027 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint64Array, ByteArray); |
5907 friend class ByteArray; | 6028 friend class ByteArray; |
5908 friend class Class; | 6029 friend class Class; |
5909 }; | 6030 }; |
5910 | 6031 |
5911 | 6032 |
| 6033 class ExternalFloat32x4Array : public ByteArray { |
| 6034 public: |
| 6035 intptr_t ByteLength() const { |
| 6036 return Length() * kBytesPerElement; |
| 6037 } |
| 6038 |
| 6039 simd_value_t At(intptr_t index) const { |
| 6040 ASSERT((index >= 0) && (index < Length())); |
| 6041 simd_value_t* load_ptr = &raw_ptr()->data_[index]; |
| 6042 return simd_value_safe_load(load_ptr); |
| 6043 } |
| 6044 |
| 6045 void SetAt(intptr_t index, simd_value_t value) const { |
| 6046 ASSERT((index >= 0) && (index < Length())); |
| 6047 simd_value_t* store_ptr = &raw_ptr()->data_[index]; |
| 6048 simd_value_safe_store(store_ptr, value); |
| 6049 } |
| 6050 |
| 6051 |
| 6052 simd_value_t* GetData() const { |
| 6053 return raw_ptr()->data_; |
| 6054 } |
| 6055 |
| 6056 void* GetPeer() const { |
| 6057 return raw_ptr()->peer_; |
| 6058 } |
| 6059 |
| 6060 static const intptr_t kBytesPerElement = 16; |
| 6061 |
| 6062 // Since external arrays may be serialized to non-external ones, |
| 6063 // enforce the same maximum element count. |
| 6064 static const intptr_t kMaxElements = Float32x4Array::kMaxElements; |
| 6065 |
| 6066 static intptr_t InstanceSize() { |
| 6067 return RoundedAllocationSize(sizeof(RawExternalFloat32x4Array)); |
| 6068 } |
| 6069 |
| 6070 static RawExternalFloat32x4Array* New(simd_value_t* data, |
| 6071 intptr_t len, |
| 6072 Heap::Space space = Heap::kNew); |
| 6073 |
| 6074 private: |
| 6075 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 6076 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 6077 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); |
| 6078 return data + byte_offset; |
| 6079 } |
| 6080 |
| 6081 void SetData(simd_value_t* data) const { |
| 6082 raw_ptr()->data_ = data; |
| 6083 } |
| 6084 |
| 6085 void SetPeer(void* peer) const { |
| 6086 raw_ptr()->peer_ = peer; |
| 6087 } |
| 6088 |
| 6089 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalFloat32x4Array, ByteArray); |
| 6090 friend class ByteArray; |
| 6091 friend class Class; |
| 6092 }; |
| 6093 |
| 6094 |
5912 class ExternalFloat32Array : public ByteArray { | 6095 class ExternalFloat32Array : public ByteArray { |
5913 public: | 6096 public: |
5914 intptr_t ByteLength() const { | 6097 intptr_t ByteLength() const { |
5915 return Length() * kBytesPerElement; | 6098 return Length() * kBytesPerElement; |
5916 } | 6099 } |
5917 | 6100 |
5918 float At(intptr_t index) const { | 6101 float At(intptr_t index) const { |
5919 ASSERT((index >= 0) && (index < Length())); | 6102 ASSERT((index >= 0) && (index < Length())); |
5920 return raw_ptr()->data_[index]; | 6103 return raw_ptr()->data_[index]; |
5921 } | 6104 } |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6372 | 6555 |
6373 | 6556 |
6374 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 6557 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
6375 intptr_t index) { | 6558 intptr_t index) { |
6376 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 6559 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
6377 } | 6560 } |
6378 | 6561 |
6379 } // namespace dart | 6562 } // namespace dart |
6380 | 6563 |
6381 #endif // VM_OBJECT_H_ | 6564 #endif // VM_OBJECT_H_ |
OLD | NEW |