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

Side by Side Diff: runtime/lib/typeddata.cc

Issue 14296006: Fast copy between TypedData and ExternalTypedData (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | « no previous file | runtime/vm/object.h » ('j') | runtime/vm/object.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 #include "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return Smi::New(array.Length()); 71 return Smi::New(array.Length());
72 } 72 }
73 const String& error = String::Handle(String::NewFormatted( 73 const String& error = String::Handle(String::NewFormatted(
74 "Expected a TypedData object but found %s", instance.ToCString())); 74 "Expected a TypedData object but found %s", instance.ToCString()));
75 const Array& args = Array::Handle(Array::New(1)); 75 const Array& args = Array::Handle(Array::New(1));
76 args.SetAt(0, error); 76 args.SetAt(0, error);
77 Exceptions::ThrowByType(Exceptions::kArgument, args); 77 Exceptions::ThrowByType(Exceptions::kArgument, args);
78 return Integer::null(); 78 return Integer::null();
79 } 79 }
80 80
81 81 template <typename DstType, typename SrcType>
82 #define COPY_DATA(type, dst, src) \ 82 static RawBool* CopyData(const Instance& dst, const Instance& src,
83 const type& dst_array = type::Cast(dst); \ 83 const Smi& dst_start, const Smi& src_start,
84 const type& src_array = type::Cast(src); \ 84 const Smi& length) {
85 intptr_t element_size_in_bytes = dst_array.ElementSizeInBytes(); \ 85 const DstType& dst_array = DstType::Cast(dst);
86 intptr_t length_in_bytes = length.Value() * element_size_in_bytes; \ 86 const SrcType& src_array = SrcType::Cast(src);
87 intptr_t src_offset_in_bytes = src_start.Value() * element_size_in_bytes; \ 87 intptr_t element_size_in_bytes = dst_array.ElementSizeInBytes();
88 intptr_t dst_offset_in_bytes = dst_start.Value() * element_size_in_bytes; \ 88 intptr_t dst_offset_in_bytes = dst_start.Value() * element_size_in_bytes;
89 SetRangeCheck(src_offset_in_bytes, \ 89 intptr_t src_offset_in_bytes = src_start.Value() * element_size_in_bytes;
90 length_in_bytes, \ 90 intptr_t length_in_bytes = length.Value() * element_size_in_bytes;
91 src_array.LengthInBytes(), \ 91 if (dst_array.ElementType() != src_array.ElementType()) {
92 element_size_in_bytes); \ 92 return Bool::False().raw();
93 SetRangeCheck(dst_offset_in_bytes, \ 93 }
94 length_in_bytes, \ 94 SetRangeCheck(src_offset_in_bytes,
95 dst_array.LengthInBytes(), \ 95 length_in_bytes,
96 element_size_in_bytes); \ 96 src_array.LengthInBytes(),
97 type::Copy(dst_array, dst_offset_in_bytes, \ 97 element_size_in_bytes);
98 src_array, src_offset_in_bytes, \ 98 SetRangeCheck(dst_offset_in_bytes,
99 length_in_bytes); 99 length_in_bytes,
100 dst_array.LengthInBytes(),
101 element_size_in_bytes);
102 TypedArrayCopyData<DstType, SrcType>(dst_array, dst_offset_in_bytes,
103 src_array, src_offset_in_bytes,
104 length_in_bytes);
siva 2013/04/19 17:38:40 See comments in object.h about templatizing TypedD
kustermann 2013/04/19 19:21:54 Done.
105 return Bool::True().raw();
106 }
100 107
101 DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) { 108 DEFINE_NATIVE_ENTRY(TypedData_setRange, 5) {
102 GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0)); 109 GET_NON_NULL_NATIVE_ARGUMENT(Instance, dst, arguments->NativeArgAt(0));
103 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1)); 110 GET_NON_NULL_NATIVE_ARGUMENT(Smi, dst_start, arguments->NativeArgAt(1));
104 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2)); 111 GET_NON_NULL_NATIVE_ARGUMENT(Smi, length, arguments->NativeArgAt(2));
105 GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3)); 112 GET_NON_NULL_NATIVE_ARGUMENT(Instance, src, arguments->NativeArgAt(3));
106 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4)); 113 GET_NON_NULL_NATIVE_ARGUMENT(Smi, src_start, arguments->NativeArgAt(4));
107 114
108 if (length.Value() < 0) { 115 if (length.Value() < 0) {
109 const String& error = String::Handle(String::NewFormatted( 116 const String& error = String::Handle(String::NewFormatted(
110 "length (%"Pd") must be non-negative", length.Value())); 117 "length (%"Pd") must be non-negative", length.Value()));
111 const Array& args = Array::Handle(Array::New(1)); 118 const Array& args = Array::Handle(Array::New(1));
112 args.SetAt(0, error); 119 args.SetAt(0, error);
113 Exceptions::ThrowByType(Exceptions::kArgument, args); 120 Exceptions::ThrowByType(Exceptions::kArgument, args);
114 } 121 }
115 if ((dst.IsTypedData() || dst.IsExternalTypedData()) && 122 if (dst.IsTypedData()) {
116 (dst.clazz() == src.clazz())) { 123 if (src.IsTypedData()) {
117 if (dst.IsTypedData()) { 124 return CopyData<TypedData, TypedData>(
118 ASSERT(src.IsTypedData()); 125 dst, src, dst_start, src_start, length);
119 COPY_DATA(TypedData, dst, src); 126 } else if (src.IsExternalTypedData()) {
120 } else { 127 return CopyData<TypedData, ExternalTypedData>(
121 ASSERT(src.IsExternalTypedData()); 128 dst, src, dst_start, src_start, length);
122 ASSERT(dst.IsExternalTypedData());
123 COPY_DATA(ExternalTypedData, dst, src);
124 } 129 }
125 return Bool::True().raw(); 130 } else if (dst.IsExternalTypedData()) {
131 if (src.IsTypedData()) {
132 return CopyData<ExternalTypedData, TypedData>(
133 dst, src, dst_start, src_start, length);
134 } else if (src.IsExternalTypedData()) {
135 return CopyData<ExternalTypedData, ExternalTypedData>(
136 dst, src, dst_start, src_start, length);
137 }
126 } 138 }
127 return Bool::False().raw(); 139 return Bool::False().raw();
128 } 140 }
129 141
130 142
131 // We check the length parameter against a possible maximum length for the 143 // We check the length parameter against a possible maximum length for the
132 // array based on available physical addressable memory on the system. The 144 // array based on available physical addressable memory on the system. The
133 // maximum possible length is a scaled value of kSmiMax which is set up based 145 // maximum possible length is a scaled value of kSmiMax which is set up based
134 // on whether the underlying architecture is 32-bit or 64-bit. 146 // on whether the underlying architecture is 32-bit or 64-bit.
135 #define TYPED_DATA_NEW(name) \ 147 #define TYPED_DATA_NEW(name) \
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 TYPED_DATA_NATIVES(Uint16Array, GetUint16, SetUint16, Smi, Value) 313 TYPED_DATA_NATIVES(Uint16Array, GetUint16, SetUint16, Smi, Value)
302 TYPED_DATA_NATIVES(Int32Array, GetInt32, SetInt32, Integer, AsInt64Value) 314 TYPED_DATA_NATIVES(Int32Array, GetInt32, SetInt32, Integer, AsInt64Value)
303 TYPED_DATA_NATIVES(Uint32Array, GetUint32, SetUint32, Integer, AsInt64Value) 315 TYPED_DATA_NATIVES(Uint32Array, GetUint32, SetUint32, Integer, AsInt64Value)
304 TYPED_DATA_NATIVES(Int64Array, GetInt64, SetInt64, Integer, AsInt64Value) 316 TYPED_DATA_NATIVES(Int64Array, GetInt64, SetInt64, Integer, AsInt64Value)
305 TYPED_DATA_UINT64_NATIVES(Uint64Array, GetUint64, SetUint64, Integer) 317 TYPED_DATA_UINT64_NATIVES(Uint64Array, GetUint64, SetUint64, Integer)
306 TYPED_DATA_NATIVES(Float32Array, GetFloat32, SetFloat32, Double, value) 318 TYPED_DATA_NATIVES(Float32Array, GetFloat32, SetFloat32, Double, value)
307 TYPED_DATA_NATIVES(Float64Array, GetFloat64, SetFloat64, Double, value) 319 TYPED_DATA_NATIVES(Float64Array, GetFloat64, SetFloat64, Double, value)
308 TYPED_DATA_NATIVES(Float32x4Array, GetFloat32x4, SetFloat32x4, Float32x4, value) 320 TYPED_DATA_NATIVES(Float32x4Array, GetFloat32x4, SetFloat32x4, Float32x4, value)
309 321
310 } // namespace dart 322 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | runtime/vm/object.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698