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

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

Issue 14332002: Add endian parameter to the get/set functions in ByteData. (Closed) Base URL: http://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/lib/typeddata.dart » ('j') | sdk/lib/typeddata/typeddata.dart » ('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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 const String& error = String::Handle(String::NewFormatted( \ 278 const String& error = String::Handle(String::NewFormatted( \
279 "Expected a TypedData object but found %s", instance.ToCString())); \ 279 "Expected a TypedData object but found %s", instance.ToCString())); \
280 const Array& args = Array::Handle(Array::New(1)); \ 280 const Array& args = Array::Handle(Array::New(1)); \
281 args.SetAt(0, error); \ 281 args.SetAt(0, error); \
282 Exceptions::ThrowByType(Exceptions::kArgument, args); \ 282 Exceptions::ThrowByType(Exceptions::kArgument, args); \
283 } \ 283 } \
284 return Object::null(); \ 284 return Object::null(); \
285 } 285 }
286 286
287 287
288 #define TYPED_DATA_NATIVES(name, getter, setter, object, get_object_value) \ 288 #define TYPED_DATA_NATIVES(getter, setter, object, get_object_value) \
289 TYPED_DATA_GETTER(getter, object) \ 289 TYPED_DATA_GETTER(getter, object) \
290 TYPED_DATA_SETTER(setter, object, get_object_value) \ 290 TYPED_DATA_SETTER(setter, object, get_object_value) \
291 291
292 292
293 #define TYPED_DATA_UINT64_NATIVES(name, getter, setter, object) \ 293 #define TYPED_DATA_UINT64_NATIVES(getter, setter, object) \
294 TYPED_DATA_UINT64_GETTER(getter, object) \ 294 TYPED_DATA_UINT64_GETTER(getter, object) \
295 TYPED_DATA_UINT64_SETTER(setter, object) \ 295 TYPED_DATA_UINT64_SETTER(setter, object) \
296 296
297 297
298 TYPED_DATA_NATIVES(Int8Array, GetInt8, SetInt8, Smi, Value) 298 TYPED_DATA_NATIVES(GetInt8, SetInt8, Smi, Value)
299 TYPED_DATA_NATIVES(Uint8Array, GetUint8, SetUint8, Smi, Value) 299 TYPED_DATA_NATIVES(GetUint8, SetUint8, Smi, Value)
300 TYPED_DATA_NATIVES(Int16Array, GetInt16, SetInt16, Smi, Value) 300 TYPED_DATA_NATIVES(GetInt16, SetInt16, Smi, Value)
301 TYPED_DATA_NATIVES(Uint16Array, GetUint16, SetUint16, Smi, Value) 301 TYPED_DATA_NATIVES(GetUint16, SetUint16, Smi, Value)
302 TYPED_DATA_NATIVES(Int32Array, GetInt32, SetInt32, Integer, AsInt64Value) 302 TYPED_DATA_NATIVES(GetInt32, SetInt32, Integer, AsInt64Value)
303 TYPED_DATA_NATIVES(Uint32Array, GetUint32, SetUint32, Integer, AsInt64Value) 303 TYPED_DATA_NATIVES(GetUint32, SetUint32, Integer, AsInt64Value)
304 TYPED_DATA_NATIVES(Int64Array, GetInt64, SetInt64, Integer, AsInt64Value) 304 TYPED_DATA_NATIVES(GetInt64, SetInt64, Integer, AsInt64Value)
305 TYPED_DATA_UINT64_NATIVES(Uint64Array, GetUint64, SetUint64, Integer) 305 TYPED_DATA_UINT64_NATIVES(GetUint64, SetUint64, Integer)
306 TYPED_DATA_NATIVES(Float32Array, GetFloat32, SetFloat32, Double, value) 306 TYPED_DATA_NATIVES(GetFloat32, SetFloat32, Double, value)
307 TYPED_DATA_NATIVES(Float64Array, GetFloat64, SetFloat64, Double, value) 307 TYPED_DATA_NATIVES(GetFloat64, SetFloat64, Double, value)
308 TYPED_DATA_NATIVES(Float32x4Array, GetFloat32x4, SetFloat32x4, Float32x4, value) 308 TYPED_DATA_NATIVES(GetFloat32x4, SetFloat32x4, Float32x4, value)
309
310
311 DEFINE_NATIVE_ENTRY(ByteData_ToEndianInt16, 2) {
312 GET_NON_NULL_NATIVE_ARGUMENT(Smi, host_value, arguments->NativeArgAt(0));
313 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1));
314 int16_t value = host_value.Value();
315 if (little_endian.value()) {
316 value = Utils::HostToLittleEndian16(value);
317 } else {
318 value = Utils::HostToBigEndian16(value);
319 }
320 return Smi::New(value);
321 }
322
323
324 DEFINE_NATIVE_ENTRY(ByteData_ToEndianUint16, 2) {
325 GET_NON_NULL_NATIVE_ARGUMENT(Smi, host_value, arguments->NativeArgAt(0));
326 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1));
327 uint16_t value = host_value.Value();
328 if (little_endian.value()) {
329 return Smi::New(Utils::HostToLittleEndian16(value));
330 }
331 return Smi::New(Utils::HostToBigEndian16(value));
332 }
333
334
335 DEFINE_NATIVE_ENTRY(ByteData_ToEndianInt32, 2) {
336 GET_NON_NULL_NATIVE_ARGUMENT(Integer, host_value, arguments->NativeArgAt(0));
337 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1));
338 ASSERT(host_value.AsInt64Value() <= kMaxInt32);
339 int32_t value = host_value.AsInt64Value();
340 if (little_endian.value()) {
341 value = Utils::HostToLittleEndian32(value);
342 } else {
343 value = Utils::HostToBigEndian32(value);
344 }
345 return Integer::New(value);
346 }
347
348
349 DEFINE_NATIVE_ENTRY(ByteData_ToEndianUint32, 2) {
350 GET_NON_NULL_NATIVE_ARGUMENT(Integer, host_value, arguments->NativeArgAt(0));
351 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1));
352 ASSERT(host_value.AsInt64Value() <= kMaxUint32);
353 uint32_t value = host_value.AsInt64Value();
354 if (little_endian.value()) {
355 value = Utils::HostToLittleEndian32(value);
356 } else {
357 value = Utils::HostToBigEndian32(value);
358 }
359 return Integer::New(value);
360 }
361
362
363 DEFINE_NATIVE_ENTRY(ByteData_ToEndianInt64, 2) {
364 GET_NON_NULL_NATIVE_ARGUMENT(Integer, host_value, arguments->NativeArgAt(0));
365 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1));
366 int64_t value = host_value.AsInt64Value();
367 if (little_endian.value()) {
368 value = Utils::HostToLittleEndian64(value);
369 } else {
370 value = Utils::HostToBigEndian64(value);
371 }
372 return Integer::New(value);
373 }
374
375
376 DEFINE_NATIVE_ENTRY(ByteData_ToEndianUint64, 2) {
377 GET_NON_NULL_NATIVE_ARGUMENT(Integer, host_value, arguments->NativeArgAt(0));
378 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1));
379 uint64_t value;
380 if (host_value.IsBigint()) {
381 const Bigint& bigint = Bigint::Cast(host_value);
382 ASSERT(BigintOperations::FitsIntoUint64(bigint));
383 value = BigintOperations::AbsToUint64(bigint);
384 } else {
385 ASSERT(host_value.IsMint() || host_value.IsSmi());
386 value = host_value.AsInt64Value();
387 }
388 if (little_endian.value()) {
389 value = Utils::HostToLittleEndian64(value);
390 } else {
391 value = Utils::HostToBigEndian64(value);
392 }
393 if (value > static_cast<uint64_t>(Mint::kMaxValue)) {
394 return BigintOperations::NewFromUint64(value);
395 } else if (value > static_cast<uint64_t>(Smi::kMaxValue)) {
396 return Mint::New(value);
397 }
398 return Smi::New(value);
399 }
400
401
402 DEFINE_NATIVE_ENTRY(ByteData_ToEndianFloat32, 2) {
403 GET_NON_NULL_NATIVE_ARGUMENT(Double, host_value, arguments->NativeArgAt(0));
404 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1));
405 float value = host_value.value();
406 if (little_endian.value()) {
407 value = bit_cast<float>(
408 Utils::HostToLittleEndian32(bit_cast<uint32_t>(value)));
409 } else {
410 value = bit_cast<float>(
411 Utils::HostToBigEndian32(bit_cast<uint32_t>(value)));
412 }
413 return Double::New(value);
414 }
415
416
417 DEFINE_NATIVE_ENTRY(ByteData_ToEndianFloat64, 2) {
418 GET_NON_NULL_NATIVE_ARGUMENT(Double, host_value, arguments->NativeArgAt(0));
419 GET_NON_NULL_NATIVE_ARGUMENT(Bool, little_endian, arguments->NativeArgAt(1));
420 double value = host_value.value();
421 if (little_endian.value()) {
422 value = bit_cast<double>(
423 Utils::HostToLittleEndian64(bit_cast<uint64_t>(value)));
424 } else {
425 value = bit_cast<double>(
426 Utils::HostToBigEndian64(bit_cast<uint64_t>(value)));
427 }
428 return Double::New(value);
429 }
309 430
310 } // namespace dart 431 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/typeddata.dart » ('j') | sdk/lib/typeddata/typeddata.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698