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 #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 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 return !bigint.FitsIntoSmi() && !bigint.FitsIntoInt64(); | 29 return !bigint.FitsIntoSmi() && !bigint.FitsIntoInt64(); |
30 } | 30 } |
31 if (i.IsMint()) { | 31 if (i.IsMint()) { |
32 const Mint& mint = Mint::Cast(i); | 32 const Mint& mint = Mint::Cast(i); |
33 return !Smi::IsValid(mint.value()); | 33 return !Smi::IsValid(mint.value()); |
34 } | 34 } |
35 return true; | 35 return true; |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 static int BitLengthInt64(int64_t value) { | |
40 value ^= value >> (8 * sizeof(value) - 1); // flip bits if negative. | |
41 // TODO(regis): Utils::HighestBit handles negative values. Why the above? | |
42 return value == 0 ? 0 : Utils::HighestBit(value) + 1; | |
43 } | |
44 | |
45 | |
46 DEFINE_NATIVE_ENTRY(Integer_bitAndFromInteger, 2) { | 39 DEFINE_NATIVE_ENTRY(Integer_bitAndFromInteger, 2) { |
47 const Integer& right = Integer::CheckedHandle(arguments->NativeArgAt(0)); | 40 const Integer& right = Integer::CheckedHandle(arguments->NativeArgAt(0)); |
48 GET_NON_NULL_NATIVE_ARGUMENT(Integer, left, arguments->NativeArgAt(1)); | 41 GET_NON_NULL_NATIVE_ARGUMENT(Integer, left, arguments->NativeArgAt(1)); |
49 ASSERT(CheckInteger(right)); | 42 ASSERT(CheckInteger(right)); |
50 ASSERT(CheckInteger(left)); | 43 ASSERT(CheckInteger(left)); |
51 if (FLAG_trace_intrinsified_natives) { | 44 if (FLAG_trace_intrinsified_natives) { |
52 OS::Print("Integer_bitAndFromInteger %s & %s\n", | 45 OS::Print("Integer_bitAndFromInteger %s & %s\n", |
53 right.ToCString(), left.ToCString()); | 46 right.ToCString(), left.ToCString()); |
54 } | 47 } |
55 const Integer& result = Integer::Handle(left.BitOp(Token::kBIT_AND, right)); | 48 const Integer& result = Integer::Handle(left.BitOp(Token::kBIT_AND, right)); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 return Smi::New(result); | 351 return Smi::New(result); |
359 } | 352 } |
360 | 353 |
361 | 354 |
362 DEFINE_NATIVE_ENTRY(Smi_bitLength, 1) { | 355 DEFINE_NATIVE_ENTRY(Smi_bitLength, 1) { |
363 const Smi& operand = Smi::CheckedHandle(arguments->NativeArgAt(0)); | 356 const Smi& operand = Smi::CheckedHandle(arguments->NativeArgAt(0)); |
364 if (FLAG_trace_intrinsified_natives) { | 357 if (FLAG_trace_intrinsified_natives) { |
365 OS::Print("Smi_bitLength: %s\n", operand.ToCString()); | 358 OS::Print("Smi_bitLength: %s\n", operand.ToCString()); |
366 } | 359 } |
367 int64_t value = operand.AsInt64Value(); | 360 int64_t value = operand.AsInt64Value(); |
368 intptr_t result = BitLengthInt64(value); | 361 intptr_t result = Utils::BitLength(value); |
369 ASSERT(Smi::IsValid(result)); | 362 ASSERT(Smi::IsValid(result)); |
370 return Smi::New(result); | 363 return Smi::New(result); |
371 } | 364 } |
372 | 365 |
373 | 366 |
374 // Mint natives. | 367 // Mint natives. |
375 | 368 |
376 DEFINE_NATIVE_ENTRY(Mint_bitNegate, 1) { | 369 DEFINE_NATIVE_ENTRY(Mint_bitNegate, 1) { |
377 const Mint& operand = Mint::CheckedHandle(arguments->NativeArgAt(0)); | 370 const Mint& operand = Mint::CheckedHandle(arguments->NativeArgAt(0)); |
378 ASSERT(CheckInteger(operand)); | 371 ASSERT(CheckInteger(operand)); |
379 if (FLAG_trace_intrinsified_natives) { | 372 if (FLAG_trace_intrinsified_natives) { |
380 OS::Print("Mint_bitNegate: %s\n", operand.ToCString()); | 373 OS::Print("Mint_bitNegate: %s\n", operand.ToCString()); |
381 } | 374 } |
382 int64_t result = ~operand.value(); | 375 int64_t result = ~operand.value(); |
383 return Integer::New(result); | 376 return Integer::New(result); |
384 } | 377 } |
385 | 378 |
386 | 379 |
387 DEFINE_NATIVE_ENTRY(Mint_bitLength, 1) { | 380 DEFINE_NATIVE_ENTRY(Mint_bitLength, 1) { |
388 const Mint& operand = Mint::CheckedHandle(arguments->NativeArgAt(0)); | 381 const Mint& operand = Mint::CheckedHandle(arguments->NativeArgAt(0)); |
389 ASSERT(CheckInteger(operand)); | 382 ASSERT(CheckInteger(operand)); |
390 if (FLAG_trace_intrinsified_natives) { | 383 if (FLAG_trace_intrinsified_natives) { |
391 OS::Print("Mint_bitLength: %s\n", operand.ToCString()); | 384 OS::Print("Mint_bitLength: %s\n", operand.ToCString()); |
392 } | 385 } |
393 int64_t value = operand.AsInt64Value(); | 386 int64_t value = operand.AsInt64Value(); |
394 intptr_t result = BitLengthInt64(value); | 387 intptr_t result = Utils::BitLength(value); |
395 ASSERT(Smi::IsValid(result)); | 388 ASSERT(Smi::IsValid(result)); |
396 return Smi::New(result); | 389 return Smi::New(result); |
397 } | 390 } |
398 | 391 |
399 | 392 |
400 DEFINE_NATIVE_ENTRY(Mint_shlFromInt, 2) { | 393 DEFINE_NATIVE_ENTRY(Mint_shlFromInt, 2) { |
401 // Use the preallocated out of memory exception to avoid calling | 394 // Use the preallocated out of memory exception to avoid calling |
402 // into dart code or allocating any code. | 395 // into dart code or allocating any code. |
403 const Instance& exception = | 396 const Instance& exception = |
404 Instance::Handle(isolate->object_store()->out_of_memory()); | 397 Instance::Handle(isolate->object_store()->out_of_memory()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 return Object::null(); | 444 return Object::null(); |
452 } | 445 } |
453 | 446 |
454 | 447 |
455 DEFINE_NATIVE_ENTRY(Bigint_allocate, 1) { | 448 DEFINE_NATIVE_ENTRY(Bigint_allocate, 1) { |
456 // Argument is null type arguments, since class Bigint is not parameterized. | 449 // Argument is null type arguments, since class Bigint is not parameterized. |
457 return Bigint::New(); | 450 return Bigint::New(); |
458 } | 451 } |
459 | 452 |
460 } // namespace dart | 453 } // namespace dart |
OLD | NEW |