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/conversions.h" | 9 #include "src/conversions.h" |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 return *result; \ | 581 return *result; \ |
582 } | 582 } |
583 | 583 |
584 #define SIMD_MAX_FUNCTION(type, lane_type, lane_count) \ | 584 #define SIMD_MAX_FUNCTION(type, lane_type, lane_count) \ |
585 RUNTIME_FUNCTION(Runtime_##type##Max) { \ | 585 RUNTIME_FUNCTION(Runtime_##type##Max) { \ |
586 HandleScope scope(isolate); \ | 586 HandleScope scope(isolate); \ |
587 SIMD_BINARY_OP(type, lane_type, lane_count, Max, result); \ | 587 SIMD_BINARY_OP(type, lane_type, lane_count, Max, result); \ |
588 return *result; \ | 588 return *result; \ |
589 } | 589 } |
590 | 590 |
591 | |
591 SIMD_NUMERIC_TYPES(SIMD_NEG_FUNCTION) | 592 SIMD_NUMERIC_TYPES(SIMD_NEG_FUNCTION) |
592 SIMD_NUMERIC_TYPES(SIMD_ADD_FUNCTION) | 593 SIMD_NUMERIC_TYPES(SIMD_ADD_FUNCTION) |
593 SIMD_NUMERIC_TYPES(SIMD_SUB_FUNCTION) | 594 SIMD_NUMERIC_TYPES(SIMD_SUB_FUNCTION) |
594 SIMD_NUMERIC_TYPES(SIMD_MUL_FUNCTION) | 595 SIMD_NUMERIC_TYPES(SIMD_MUL_FUNCTION) |
595 SIMD_NUMERIC_TYPES(SIMD_MIN_FUNCTION) | 596 SIMD_NUMERIC_TYPES(SIMD_MIN_FUNCTION) |
596 SIMD_NUMERIC_TYPES(SIMD_MAX_FUNCTION) | 597 SIMD_NUMERIC_TYPES(SIMD_MAX_FUNCTION) |
597 | 598 |
598 //------------------------------------------------------------------- | 599 //------------------------------------------------------------------- |
599 | 600 |
600 // Relational functions. | 601 // Relational functions. |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
810 } | 811 } |
811 | 812 |
812 | 813 |
813 RUNTIME_FUNCTION(Runtime_Int8x16UnsignedExtractLane) { | 814 RUNTIME_FUNCTION(Runtime_Int8x16UnsignedExtractLane) { |
814 HandleScope scope(isolate); | 815 HandleScope scope(isolate); |
815 DCHECK(args.length() == 2); | 816 DCHECK(args.length() == 2); |
816 CONVERT_ARG_HANDLE_CHECKED(Int8x16, a, 0); | 817 CONVERT_ARG_HANDLE_CHECKED(Int8x16, a, 0); |
817 CONVERT_SIMD_LANE_ARG_CHECKED(lane, 1, 16); | 818 CONVERT_SIMD_LANE_ARG_CHECKED(lane, 1, 16); |
818 return *isolate->factory()->NewNumber(bit_cast<uint8_t>(a->get_lane(lane))); | 819 return *isolate->factory()->NewNumber(bit_cast<uint8_t>(a->get_lane(lane))); |
819 } | 820 } |
821 | |
822 | |
823 //------------------------------------------------------------------- | |
824 | |
825 // Load functions. | |
826 #define SIMD_MEMORY_OP_TYPES(FUNCTION) \ | |
827 FUNCTION(Float32x4, float, 4) \ | |
828 FUNCTION(Int32x4, int32_t, 4) \ | |
829 FUNCTION(Int16x8, int16_t, 8) \ | |
830 FUNCTION(Int8x16, int8_t, 16) | |
bbudge
2015/08/20 18:23:34
You'll have to partition these, since only the 4-l
gdeepti
2015/08/20 22:09:24
Done.
| |
831 | |
832 | |
833 // Common Load Functions | |
834 #define SIMD_LOAD(type, lane_type, lane_count, count, result) \ | |
835 static const int kLaneCount = lane_count; \ | |
836 lane_type lanes[kLaneCount] = {0}; \ | |
837 Handle<type> result; \ | |
838 DCHECK(args.length() == 2); \ | |
839 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, tarray_obj, 0); \ | |
840 CONVERT_INT32_ARG_CHECKED(index, 1) \ | |
841 Handle<JSTypedArray> tarray(JSTypedArray::cast(*tarray_obj)); \ | |
842 size_t bpe = tarray->element_size(); \ | |
843 uint32_t bytes = count * sizeof(lane_type); \ | |
844 size_t byte_length = NumberToSize(isolate, tarray->byte_length()); \ | |
845 \ | |
846 if (index < 0 || (index * bpe + bytes) > byte_length) { \ | |
847 THROW_NEW_ERROR_RETURN_FAILURE( \ | |
848 isolate, NewTypeError(MessageTemplate::kInvalidTypedArrayIndex)); \ | |
849 } \ | |
850 size_t tarray_offset = NumberToSize(isolate, tarray->byte_offset()); \ | |
851 uint8_t* tarray_base = \ | |
852 static_cast<uint8_t*>(tarray->GetBuffer()->backing_store()) + \ | |
853 tarray_offset; \ | |
854 memcpy(lanes, tarray_base + (index)*bpe, bytes); \ | |
855 result = isolate->factory()->New##type(lanes); | |
856 | |
857 | |
858 #define SIMD_LOAD_FUNCTION(type, lane_type, lane_count) \ | |
859 RUNTIME_FUNCTION(Runtime_##type##Load) { \ | |
860 HandleScope scope(isolate); \ | |
861 SIMD_LOAD(type, lane_type, lane_count, lane_count, result); \ | |
862 return *result; \ | |
863 } | |
864 | |
865 | |
866 #define SIMD_LOAD1_FUNCTION(type, lane_type, lane_count) \ | |
867 RUNTIME_FUNCTION(Runtime_##type##Load1) { \ | |
868 HandleScope scope(isolate); \ | |
869 SIMD_LOAD(type, lane_type, lane_count, 1, result); \ | |
870 return *result; \ | |
871 } | |
872 | |
873 | |
874 #define SIMD_LOAD2_FUNCTION(type, lane_type, lane_count) \ | |
875 RUNTIME_FUNCTION(Runtime_##type##Load2) { \ | |
876 HandleScope scope(isolate); \ | |
877 SIMD_LOAD(type, lane_type, lane_count, 2, result); \ | |
878 return *result; \ | |
879 } | |
880 | |
881 | |
882 #define SIMD_LOAD3_FUNCTION(type, lane_type, lane_count) \ | |
883 RUNTIME_FUNCTION(Runtime_##type##Load3) { \ | |
884 HandleScope scope(isolate); \ | |
885 SIMD_LOAD(type, lane_type, lane_count, 3, result); \ | |
886 return *result; \ | |
887 } | |
888 | |
889 | |
890 SIMD_MEMORY_OP_TYPES(SIMD_LOAD_FUNCTION) | |
891 SIMD_MEMORY_OP_TYPES(SIMD_LOAD1_FUNCTION) | |
892 SIMD_MEMORY_OP_TYPES(SIMD_LOAD2_FUNCTION) | |
893 SIMD_MEMORY_OP_TYPES(SIMD_LOAD3_FUNCTION) | |
894 | |
895 //------------------------------------------------------------------- | |
896 | |
820 } // namespace internal | 897 } // namespace internal |
821 } // namespace v8 | 898 } // namespace v8 |
OLD | NEW |