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

Side by Side Diff: src/runtime/runtime-simd.cc

Issue 1356413002: [simdjs] Update Spec version to 0.9 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « src/runtime/runtime.h ('k') | test/simdjs/testcfg.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/conversions.h" 9 #include "src/conversions.h"
10 #include "src/factory.h" 10 #include "src/factory.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 inline T AddSaturate(T a, T b) { 103 inline T AddSaturate(T a, T b) {
104 const T max = std::numeric_limits<T>::max(); 104 const T max = std::numeric_limits<T>::max();
105 const T min = std::numeric_limits<T>::min(); 105 const T min = std::numeric_limits<T>::min();
106 int32_t result = a + b; 106 int32_t result = a + b;
107 if (result > max) return max; 107 if (result > max) return max;
108 if (result < min) return min; 108 if (result < min) return min;
109 return result; 109 return result;
110 } 110 }
111 111
112 112
113 // Widening absolute difference for uint16_t and uint8_t.
114 template <typename T>
115 inline uint32_t AbsoluteDifference(T a, T b) {
116 uint32_t result = std::abs(a - b);
117 return result;
118 }
119
120
121 // Saturating subtraction for int16_t and int8_t. 113 // Saturating subtraction for int16_t and int8_t.
122 template <typename T> 114 template <typename T>
123 inline T SubSaturate(T a, T b) { 115 inline T SubSaturate(T a, T b) {
124 const T max = std::numeric_limits<T>::max(); 116 const T max = std::numeric_limits<T>::max();
125 const T min = std::numeric_limits<T>::min(); 117 const T min = std::numeric_limits<T>::min();
126 int32_t result = a - b; 118 int32_t result = a - b;
127 if (result > max) return max; 119 if (result > max) return max;
128 if (result < min) return min; 120 if (result < min) return min;
129 return result; 121 return result;
130 } 122 }
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 if (shift >= lane_bits) shift = lane_bits - 1; \ 477 if (shift >= lane_bits) shift = lane_bits - 1; \
486 lane_type lanes[kLaneCount]; \ 478 lane_type lanes[kLaneCount]; \
487 for (int i = 0; i < kLaneCount; i++) { \ 479 for (int i = 0; i < kLaneCount; i++) { \
488 int64_t shifted = static_cast<int64_t>(a->get_lane(i)) >> shift; \ 480 int64_t shifted = static_cast<int64_t>(a->get_lane(i)) >> shift; \
489 lanes[i] = static_cast<lane_type>(shifted); \ 481 lanes[i] = static_cast<lane_type>(shifted); \
490 } \ 482 } \
491 Handle<type> result = isolate->factory()->New##type(lanes); \ 483 Handle<type> result = isolate->factory()->New##type(lanes); \
492 return *result; \ 484 return *result; \
493 } 485 }
494 486
495 #define SIMD_HORIZONTAL_SUM_FUNCTION(type, lane_type, lane_bits, lane_count) \
496 RUNTIME_FUNCTION(Runtime_##type##HorizontalSum) { \
497 HandleScope scope(isolate); \
498 DCHECK(args.length() == 1); \
499 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \
500 double sum = 0; \
501 for (int i = 0; i < lane_count; i++) { \
502 sum += a->get_lane(i); \
503 } \
504 return *isolate->factory()->NewNumber(sum); \
505 }
506
507 SIMD_INT_TYPES(SIMD_LSL_FUNCTION) 487 SIMD_INT_TYPES(SIMD_LSL_FUNCTION)
508 SIMD_UINT_TYPES(SIMD_LSL_FUNCTION) 488 SIMD_UINT_TYPES(SIMD_LSL_FUNCTION)
509 SIMD_INT_TYPES(SIMD_ASR_FUNCTION) 489 SIMD_INT_TYPES(SIMD_ASR_FUNCTION)
510 SIMD_UINT_TYPES(SIMD_LSR_FUNCTION) 490 SIMD_UINT_TYPES(SIMD_LSR_FUNCTION)
511 SIMD_UINT_TYPES(SIMD_HORIZONTAL_SUM_FUNCTION)
512 491
513 //------------------------------------------------------------------- 492 //-------------------------------------------------------------------
514 493
515 // Bool-only functions. 494 // Bool-only functions.
516 495
517 #define SIMD_BOOL_TYPES(FUNCTION) \ 496 #define SIMD_BOOL_TYPES(FUNCTION) \
518 FUNCTION(Bool32x4, 4) \ 497 FUNCTION(Bool32x4, 4) \
519 FUNCTION(Bool16x8, 8) \ 498 FUNCTION(Bool16x8, 8) \
520 FUNCTION(Bool8x16, 16) 499 FUNCTION(Bool8x16, 16)
521 500
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 HandleScope scope(isolate); \ 554 HandleScope scope(isolate); \
576 SIMD_BINARY_OP(type, lane_type, lane_count, SubSaturate, result); \ 555 SIMD_BINARY_OP(type, lane_type, lane_count, SubSaturate, result); \
577 return *result; \ 556 return *result; \
578 } 557 }
579 558
580 SIMD_SMALL_INT_TYPES(SIMD_ADD_SATURATE_FUNCTION) 559 SIMD_SMALL_INT_TYPES(SIMD_ADD_SATURATE_FUNCTION)
581 SIMD_SMALL_INT_TYPES(SIMD_SUB_SATURATE_FUNCTION) 560 SIMD_SMALL_INT_TYPES(SIMD_SUB_SATURATE_FUNCTION)
582 561
583 //------------------------------------------------------------------- 562 //-------------------------------------------------------------------
584 563
585 // Small Unsigned int-only functions.
586
587 #define SIMD_SMALL_UINT_TYPES(FUNCTION) \
588 FUNCTION(Uint16x8, uint16_t, 8, Uint32x4, uint32_t) \
589 FUNCTION(Uint8x16, uint8_t, 16, Uint16x8, uint16_t)
590
591 #define SIMD_ABS_DIFF_FUNCTION(type, lane_type, lane_count, wide_type, \
592 wide_ctype) \
593 RUNTIME_FUNCTION(Runtime_##type##AbsoluteDifference) { \
594 HandleScope scope(isolate); \
595 SIMD_BINARY_OP(type, lane_type, lane_count, AbsoluteDifference, result); \
596 return *result; \
597 }
598
599 #define SIMD_WIDE_ABS_DIFF_FUNCTION(type, lane_type, lane_count, wide_type, \
600 wide_ctype) \
601 RUNTIME_FUNCTION(Runtime_##type##WidenedAbsoluteDifference) { \
602 HandleScope scope(isolate); \
603 static const int kLaneCount = lane_count / 2; \
604 DCHECK(args.length() == 2); \
605 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \
606 CONVERT_ARG_HANDLE_CHECKED(type, b, 1); \
607 wide_ctype lanes[kLaneCount]; \
608 for (int i = 0; i < kLaneCount; i++) { \
609 lanes[i] = AbsoluteDifference(a->get_lane(i), b->get_lane(i)); \
610 } \
611 Handle<wide_type> result = isolate->factory()->New##wide_type(lanes); \
612 return *result; \
613 }
614
615 SIMD_SMALL_UINT_TYPES(SIMD_ABS_DIFF_FUNCTION)
616 SIMD_SMALL_UINT_TYPES(SIMD_WIDE_ABS_DIFF_FUNCTION)
617
618 //-------------------------------------------------------------------
619
620 // Numeric functions. 564 // Numeric functions.
621 565
622 #define SIMD_NUMERIC_TYPES(FUNCTION) \ 566 #define SIMD_NUMERIC_TYPES(FUNCTION) \
623 FUNCTION(Float32x4, float, 4) \ 567 FUNCTION(Float32x4, float, 4) \
624 FUNCTION(Int32x4, int32_t, 4) \ 568 FUNCTION(Int32x4, int32_t, 4) \
625 FUNCTION(Uint32x4, uint32_t, 4) \ 569 FUNCTION(Uint32x4, uint32_t, 4) \
626 FUNCTION(Int16x8, int16_t, 8) \ 570 FUNCTION(Int16x8, int16_t, 8) \
627 FUNCTION(Uint16x8, uint16_t, 8) \ 571 FUNCTION(Uint16x8, uint16_t, 8) \
628 FUNCTION(Int8x16, int8_t, 16) \ 572 FUNCTION(Int8x16, int8_t, 16) \
629 FUNCTION(Uint8x16, uint8_t, 16) 573 FUNCTION(Uint8x16, uint8_t, 16)
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 SIMD_LOADN_STOREN_TYPES(SIMD_LOAD3_FUNCTION) 1006 SIMD_LOADN_STOREN_TYPES(SIMD_LOAD3_FUNCTION)
1063 SIMD_NUMERIC_TYPES(SIMD_STORE_FUNCTION) 1007 SIMD_NUMERIC_TYPES(SIMD_STORE_FUNCTION)
1064 SIMD_LOADN_STOREN_TYPES(SIMD_STORE1_FUNCTION) 1008 SIMD_LOADN_STOREN_TYPES(SIMD_STORE1_FUNCTION)
1065 SIMD_LOADN_STOREN_TYPES(SIMD_STORE2_FUNCTION) 1009 SIMD_LOADN_STOREN_TYPES(SIMD_STORE2_FUNCTION)
1066 SIMD_LOADN_STOREN_TYPES(SIMD_STORE3_FUNCTION) 1010 SIMD_LOADN_STOREN_TYPES(SIMD_STORE3_FUNCTION)
1067 1011
1068 //------------------------------------------------------------------- 1012 //-------------------------------------------------------------------
1069 1013
1070 } // namespace internal 1014 } // namespace internal
1071 } // namespace v8 1015 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | test/simdjs/testcfg.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698