Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/base/macros.h" | 8 #include "src/base/macros.h" |
| 9 #include "src/base/safe_math.h" | |
| 9 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| 10 #include "src/factory.h" | 11 #include "src/factory.h" |
| 11 #include "src/objects-inl.h" | 12 #include "src/objects-inl.h" |
| 12 | 13 |
| 13 // Implement Single Instruction Multiple Data (SIMD) operations as defined in | 14 // Implement Single Instruction Multiple Data (SIMD) operations as defined in |
| 14 // the SIMD.js draft spec: | 15 // the SIMD.js draft spec: |
| 15 // http://littledan.github.io/simd.html | 16 // http://littledan.github.io/simd.html |
| 16 | 17 |
| 17 namespace v8 { | 18 namespace v8 { |
| 18 namespace internal { | 19 namespace internal { |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 lane_type lanes[kLaneCount] = {0}; \ | 451 lane_type lanes[kLaneCount] = {0}; \ |
| 451 if (shift < lane_bits) { \ | 452 if (shift < lane_bits) { \ |
| 452 for (int i = 0; i < kLaneCount; i++) { \ | 453 for (int i = 0; i < kLaneCount; i++) { \ |
| 453 lanes[i] = a->get_lane(i) << shift; \ | 454 lanes[i] = a->get_lane(i) << shift; \ |
| 454 } \ | 455 } \ |
| 455 } \ | 456 } \ |
| 456 Handle<type> result = isolate->factory()->New##type(lanes); \ | 457 Handle<type> result = isolate->factory()->New##type(lanes); \ |
| 457 return *result; \ | 458 return *result; \ |
| 458 } | 459 } |
| 459 | 460 |
| 460 #define SIMD_LSR_FUNCTION(type, lane_type, lane_bits, lane_count) \ | 461 #define SIMD_LSR_FUNCTION(type, lane_type, lane_bits, lane_count) \ |
|
bbudge
2015/09/16 20:25:36
It's a little misleading to have the logical and a
gdeepti1
2015/09/16 20:42:08
Done.
| |
| 461 RUNTIME_FUNCTION(Runtime_##type##ShiftRightLogicalByScalar) { \ | 462 RUNTIME_FUNCTION(Runtime_##type##ShiftRightByScalar) { \ |
| 462 static const int kLaneCount = lane_count; \ | 463 static const int kLaneCount = lane_count; \ |
| 463 HandleScope scope(isolate); \ | 464 HandleScope scope(isolate); \ |
| 464 DCHECK(args.length() == 2); \ | 465 DCHECK(args.length() == 2); \ |
| 465 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \ | 466 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \ |
| 466 CONVERT_SHIFT_ARG_CHECKED(shift, 1); \ | 467 CONVERT_SHIFT_ARG_CHECKED(shift, 1); \ |
| 467 lane_type lanes[kLaneCount] = {0}; \ | 468 lane_type lanes[kLaneCount] = {0}; \ |
| 468 if (shift < lane_bits) { \ | 469 if (base::internal::is_same<lane_type, uint32_t>::value || \ |
| 469 for (int i = 0; i < kLaneCount; i++) { \ | 470 base::internal::is_same<lane_type, uint16_t>::value || \ |
| 470 lanes[i] = static_cast<lane_type>( \ | 471 base::internal::is_same<lane_type, uint8_t>::value) { \ |
| 471 bit_cast<lane_type>(a->get_lane(i)) >> shift); \ | 472 if (shift < lane_bits) { \ |
| 472 } \ | 473 for (int i = 0; i < kLaneCount; i++) { \ |
| 473 } \ | 474 lanes[i] = static_cast<lane_type>( \ |
| 474 Handle<type> result = isolate->factory()->New##type(lanes); \ | 475 bit_cast<lane_type>(a->get_lane(i)) >> shift); \ |
| 475 return *result; \ | 476 } \ |
| 476 } | 477 } \ |
| 477 | 478 Handle<type> result = isolate->factory()->New##type(lanes); \ |
| 478 #define SIMD_ASR_FUNCTION(type, lane_type, lane_bits, lane_count) \ | 479 return *result; \ |
| 479 RUNTIME_FUNCTION(Runtime_##type##ShiftRightArithmeticByScalar) { \ | 480 } else { \ |
| 480 static const int kLaneCount = lane_count; \ | 481 if (shift >= lane_bits) shift = lane_bits - 1; \ |
| 481 HandleScope scope(isolate); \ | 482 for (int i = 0; i < kLaneCount; i++) { \ |
| 482 DCHECK(args.length() == 2); \ | 483 int64_t shifted = static_cast<int64_t>(a->get_lane(i)) >> shift; \ |
| 483 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \ | 484 lanes[i] = static_cast<lane_type>(shifted); \ |
| 484 CONVERT_SHIFT_ARG_CHECKED(shift, 1); \ | 485 } \ |
| 485 if (shift >= lane_bits) shift = lane_bits - 1; \ | 486 Handle<type> result = isolate->factory()->New##type(lanes); \ |
| 486 lane_type lanes[kLaneCount]; \ | 487 return *result; \ |
| 487 for (int i = 0; i < kLaneCount; i++) { \ | 488 } \ |
| 488 int64_t shifted = static_cast<int64_t>(a->get_lane(i)) >> shift; \ | |
| 489 lanes[i] = static_cast<lane_type>(shifted); \ | |
| 490 } \ | |
| 491 Handle<type> result = isolate->factory()->New##type(lanes); \ | |
| 492 return *result; \ | |
| 493 } | 489 } |
| 494 | 490 |
| 495 #define SIMD_HORIZONTAL_SUM_FUNCTION(type, lane_type, lane_bits, lane_count) \ | 491 #define SIMD_HORIZONTAL_SUM_FUNCTION(type, lane_type, lane_bits, lane_count) \ |
| 496 RUNTIME_FUNCTION(Runtime_##type##HorizontalSum) { \ | 492 RUNTIME_FUNCTION(Runtime_##type##HorizontalSum) { \ |
| 497 HandleScope scope(isolate); \ | 493 HandleScope scope(isolate); \ |
| 498 DCHECK(args.length() == 1); \ | 494 DCHECK(args.length() == 1); \ |
| 499 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \ | 495 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \ |
| 500 double sum = 0; \ | 496 double sum = 0; \ |
| 501 for (int i = 0; i < lane_count; i++) { \ | 497 for (int i = 0; i < lane_count; i++) { \ |
| 502 sum += a->get_lane(i); \ | 498 sum += a->get_lane(i); \ |
| 503 } \ | 499 } \ |
| 504 return *isolate->factory()->NewNumber(sum); \ | 500 return *isolate->factory()->NewNumber(sum); \ |
| 505 } | 501 } |
| 506 | 502 |
| 507 SIMD_INT_TYPES(SIMD_LSL_FUNCTION) | 503 SIMD_INT_TYPES(SIMD_LSL_FUNCTION) |
| 508 SIMD_UINT_TYPES(SIMD_LSL_FUNCTION) | 504 SIMD_UINT_TYPES(SIMD_LSL_FUNCTION) |
| 509 SIMD_INT_TYPES(SIMD_ASR_FUNCTION) | 505 SIMD_INT_TYPES(SIMD_LSR_FUNCTION) |
| 510 SIMD_UINT_TYPES(SIMD_LSR_FUNCTION) | 506 SIMD_UINT_TYPES(SIMD_LSR_FUNCTION) |
| 511 SIMD_UINT_TYPES(SIMD_HORIZONTAL_SUM_FUNCTION) | 507 SIMD_UINT_TYPES(SIMD_HORIZONTAL_SUM_FUNCTION) |
| 512 | 508 |
| 513 //------------------------------------------------------------------- | 509 //------------------------------------------------------------------- |
| 514 | 510 |
| 515 // Bool-only functions. | 511 // Bool-only functions. |
| 516 | 512 |
| 517 #define SIMD_BOOL_TYPES(FUNCTION) \ | 513 #define SIMD_BOOL_TYPES(FUNCTION) \ |
| 518 FUNCTION(Bool32x4, 4) \ | 514 FUNCTION(Bool32x4, 4) \ |
| 519 FUNCTION(Bool16x8, 8) \ | 515 FUNCTION(Bool16x8, 8) \ |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1062 SIMD_LOADN_STOREN_TYPES(SIMD_LOAD3_FUNCTION) | 1058 SIMD_LOADN_STOREN_TYPES(SIMD_LOAD3_FUNCTION) |
| 1063 SIMD_NUMERIC_TYPES(SIMD_STORE_FUNCTION) | 1059 SIMD_NUMERIC_TYPES(SIMD_STORE_FUNCTION) |
| 1064 SIMD_LOADN_STOREN_TYPES(SIMD_STORE1_FUNCTION) | 1060 SIMD_LOADN_STOREN_TYPES(SIMD_STORE1_FUNCTION) |
| 1065 SIMD_LOADN_STOREN_TYPES(SIMD_STORE2_FUNCTION) | 1061 SIMD_LOADN_STOREN_TYPES(SIMD_STORE2_FUNCTION) |
| 1066 SIMD_LOADN_STOREN_TYPES(SIMD_STORE3_FUNCTION) | 1062 SIMD_LOADN_STOREN_TYPES(SIMD_STORE3_FUNCTION) |
| 1067 | 1063 |
| 1068 //------------------------------------------------------------------- | 1064 //------------------------------------------------------------------- |
| 1069 | 1065 |
| 1070 } // namespace internal | 1066 } // namespace internal |
| 1071 } // namespace v8 | 1067 } // namespace v8 |
| OLD | NEW |