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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 HandleScope scope(isolate); | 161 HandleScope scope(isolate); |
162 DCHECK(args.length() == 1); | 162 DCHECK(args.length() == 1); |
163 return isolate->heap()->ToBoolean(args[0]->IsSimd128Value()); | 163 return isolate->heap()->ToBoolean(args[0]->IsSimd128Value()); |
164 } | 164 } |
165 | 165 |
166 | 166 |
167 //------------------------------------------------------------------- | 167 //------------------------------------------------------------------- |
168 | 168 |
169 // Utility macros. | 169 // Utility macros. |
170 | 170 |
171 #define CONVERT_SIMD_LANE_ARG_CHECKED(name, index, lanes) \ | 171 #define CONVERT_SIMD_LANE_ARG_CHECKED(name, index, lanes) \ |
172 CONVERT_INT32_ARG_CHECKED(name, index); \ | 172 Handle<Object> name_object; \ |
173 RUNTIME_ASSERT(name >= 0 && name < lanes); | 173 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ |
174 isolate, name_object, Object::ToNumber(args.at<Object>(index))); \ | |
175 if (!name_object->IsNumber()) { \ | |
bbudge
2016/05/11 18:33:16
Can't you assume name_object is a number at this p
gdeepti
2016/05/17 14:59:41
Removed index coercion here as the polyfill does n
| |
176 THROW_NEW_ERROR_RETURN_FAILURE( \ | |
177 isolate, NewTypeError(MessageTemplate::kInvalidSimdOperation)); \ | |
178 } \ | |
179 uint32_t name; \ | |
180 name = name_object->Number(); \ | |
181 if (name < 0 || name >= lanes) { \ | |
182 THROW_NEW_ERROR_RETURN_FAILURE( \ | |
183 isolate, NewRangeError(MessageTemplate::kInvalidSimdIndex)); \ | |
184 } | |
174 | 185 |
175 #define CONVERT_SIMD_ARG_HANDLE_THROW(Type, name, index) \ | 186 #define CONVERT_SIMD_ARG_HANDLE_THROW(Type, name, index) \ |
176 Handle<Type> name; \ | 187 Handle<Type> name; \ |
177 if (args[index]->Is##Type()) { \ | 188 if (args[index]->Is##Type()) { \ |
178 name = args.at<Type>(index); \ | 189 name = args.at<Type>(index); \ |
179 } else { \ | 190 } else { \ |
180 THROW_NEW_ERROR_RETURN_FAILURE( \ | 191 THROW_NEW_ERROR_RETURN_FAILURE( \ |
181 isolate, NewTypeError(MessageTemplate::kInvalidSimdOperation)); \ | 192 isolate, NewTypeError(MessageTemplate::kInvalidSimdOperation)); \ |
182 } | 193 } |
183 | 194 |
(...skipping 26 matching lines...) Expand all Loading... | |
210 bool lanes[kLaneCount]; \ | 221 bool lanes[kLaneCount]; \ |
211 for (int i = 0; i < kLaneCount; i++) { \ | 222 for (int i = 0; i < kLaneCount; i++) { \ |
212 lanes[i] = a->get_lane(i) op b->get_lane(i); \ | 223 lanes[i] = a->get_lane(i) op b->get_lane(i); \ |
213 } \ | 224 } \ |
214 Handle<bool_type> result = isolate->factory()->New##bool_type(lanes); | 225 Handle<bool_type> result = isolate->factory()->New##bool_type(lanes); |
215 | 226 |
216 //------------------------------------------------------------------- | 227 //------------------------------------------------------------------- |
217 | 228 |
218 // Common functions. | 229 // Common functions. |
219 | 230 |
220 #define GET_NUMERIC_ARG(lane_type, name, index) \ | 231 #define GET_NUMERIC_ARG(lane_type, name, index) \ |
221 CONVERT_NUMBER_ARG_HANDLE_CHECKED(a, index); \ | 232 Handle<Object> a; \ |
233 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ | |
234 isolate, a, Object::ToNumber(args.at<Object>(index))); \ | |
222 name = ConvertNumber<lane_type>(a->Number()); | 235 name = ConvertNumber<lane_type>(a->Number()); |
223 | 236 |
224 #define GET_BOOLEAN_ARG(lane_type, name, index) \ | 237 #define GET_BOOLEAN_ARG(lane_type, name, index) \ |
225 name = args[index]->BooleanValue(); | 238 name = args[index]->BooleanValue(); |
226 | 239 |
227 #define SIMD_ALL_TYPES(FUNCTION) \ | 240 #define SIMD_ALL_TYPES(FUNCTION) \ |
228 FUNCTION(Float32x4, float, 4, NewNumber, GET_NUMERIC_ARG) \ | 241 FUNCTION(Float32x4, float, 4, NewNumber, GET_NUMERIC_ARG) \ |
229 FUNCTION(Int32x4, int32_t, 4, NewNumber, GET_NUMERIC_ARG) \ | 242 FUNCTION(Int32x4, int32_t, 4, NewNumber, GET_NUMERIC_ARG) \ |
230 FUNCTION(Uint32x4, uint32_t, 4, NewNumber, GET_NUMERIC_ARG) \ | 243 FUNCTION(Uint32x4, uint32_t, 4, NewNumber, GET_NUMERIC_ARG) \ |
231 FUNCTION(Bool32x4, bool, 4, ToBoolean, GET_BOOLEAN_ARG) \ | 244 FUNCTION(Bool32x4, bool, 4, ToBoolean, GET_BOOLEAN_ARG) \ |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
856 | 869 |
857 //------------------------------------------------------------------- | 870 //------------------------------------------------------------------- |
858 | 871 |
859 // Load and Store functions. | 872 // Load and Store functions. |
860 | 873 |
861 #define SIMD_LOADN_STOREN_TYPES(FUNCTION) \ | 874 #define SIMD_LOADN_STOREN_TYPES(FUNCTION) \ |
862 FUNCTION(Float32x4, float, 4) \ | 875 FUNCTION(Float32x4, float, 4) \ |
863 FUNCTION(Int32x4, int32_t, 4) \ | 876 FUNCTION(Int32x4, int32_t, 4) \ |
864 FUNCTION(Uint32x4, uint32_t, 4) | 877 FUNCTION(Uint32x4, uint32_t, 4) |
865 | 878 |
879 #define SIMD_COERCE_INDEX(name, index) \ | |
880 Handle<Object> name_object; \ | |
881 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ | |
882 isolate, name_object, \ | |
883 Object::ToLength(isolate, args.at<Object>(index))); \ | |
884 if (!name_object->IsNumber()) { \ | |
bbudge
2016/05/11 18:33:16
Same comment as above.
gdeepti
2016/05/17 14:59:41
Done.
| |
885 THROW_NEW_ERROR_RETURN_FAILURE( \ | |
886 isolate, NewTypeError(MessageTemplate::kInvalidSimdOperation)); \ | |
887 } \ | |
888 uint32_t name; \ | |
889 name = name_object->Number(); | |
866 | 890 |
867 // Common Load and Store Functions | 891 // Common Load and Store Functions |
868 | 892 |
869 #define SIMD_LOAD(type, lane_type, lane_count, count, result) \ | 893 #define SIMD_LOAD(type, lane_type, lane_count, count, result) \ |
870 static const int kLaneCount = lane_count; \ | 894 static const int kLaneCount = lane_count; \ |
871 DCHECK(args.length() == 2); \ | 895 DCHECK(args.length() == 2); \ |
872 CONVERT_SIMD_ARG_HANDLE_THROW(JSTypedArray, tarray, 0); \ | 896 CONVERT_SIMD_ARG_HANDLE_THROW(JSTypedArray, tarray, 0); \ |
873 CONVERT_INT32_ARG_CHECKED(index, 1) \ | 897 SIMD_COERCE_INDEX(lane, 1); \ |
bbudge
2016/05/11 18:33:16
s/lane/index
gdeepti
2016/05/17 14:59:41
Done.
| |
874 size_t bpe = tarray->element_size(); \ | 898 size_t bpe = tarray->element_size(); \ |
875 uint32_t bytes = count * sizeof(lane_type); \ | 899 uint32_t bytes = count * sizeof(lane_type); \ |
876 size_t byte_length = NumberToSize(isolate, tarray->byte_length()); \ | 900 size_t byte_length = NumberToSize(isolate, tarray->byte_length()); \ |
877 RUNTIME_ASSERT(index >= 0 && index * bpe + bytes <= byte_length); \ | 901 Handle<type> result; \ |
902 if (lane < 0 || byte_length < lane * bpe + bytes) { \ | |
903 THROW_NEW_ERROR_RETURN_FAILURE( \ | |
904 isolate, NewRangeError(MessageTemplate::kInvalidSimdIndex)); \ | |
905 } \ | |
878 size_t tarray_offset = NumberToSize(isolate, tarray->byte_offset()); \ | 906 size_t tarray_offset = NumberToSize(isolate, tarray->byte_offset()); \ |
879 uint8_t* tarray_base = \ | 907 uint8_t* tarray_base = \ |
880 static_cast<uint8_t*>(tarray->GetBuffer()->backing_store()) + \ | 908 static_cast<uint8_t*>(tarray->GetBuffer()->backing_store()) + \ |
881 tarray_offset; \ | 909 tarray_offset; \ |
882 lane_type lanes[kLaneCount] = {0}; \ | 910 lane_type lanes[kLaneCount] = {0}; \ |
883 memcpy(lanes, tarray_base + index * bpe, bytes); \ | 911 memcpy(lanes, tarray_base + lane * bpe, bytes); \ |
884 Handle<type> result = isolate->factory()->New##type(lanes); | 912 result = isolate->factory()->New##type(lanes); |
885 | |
886 | 913 |
887 #define SIMD_STORE(type, lane_type, lane_count, count, a) \ | 914 #define SIMD_STORE(type, lane_type, lane_count, count, a) \ |
888 static const int kLaneCount = lane_count; \ | 915 static const int kLaneCount = lane_count; \ |
889 DCHECK(args.length() == 3); \ | 916 DCHECK(args.length() == 3); \ |
890 CONVERT_SIMD_ARG_HANDLE_THROW(JSTypedArray, tarray, 0); \ | 917 CONVERT_SIMD_ARG_HANDLE_THROW(JSTypedArray, tarray, 0); \ |
891 CONVERT_SIMD_ARG_HANDLE_THROW(type, a, 2); \ | 918 CONVERT_SIMD_ARG_HANDLE_THROW(type, a, 2); \ |
892 CONVERT_INT32_ARG_CHECKED(index, 1) \ | 919 SIMD_COERCE_INDEX(lane, 1); \ |
893 size_t bpe = tarray->element_size(); \ | 920 size_t bpe = tarray->element_size(); \ |
894 uint32_t bytes = count * sizeof(lane_type); \ | 921 uint32_t bytes = count * sizeof(lane_type); \ |
895 size_t byte_length = NumberToSize(isolate, tarray->byte_length()); \ | 922 size_t byte_length = NumberToSize(isolate, tarray->byte_length()); \ |
896 RUNTIME_ASSERT(index >= 0 && index * bpe + bytes <= byte_length); \ | 923 if (lane < 0 || byte_length < lane * bpe + bytes) { \ |
924 THROW_NEW_ERROR_RETURN_FAILURE( \ | |
925 isolate, NewRangeError(MessageTemplate::kInvalidSimdIndex)); \ | |
926 } \ | |
897 size_t tarray_offset = NumberToSize(isolate, tarray->byte_offset()); \ | 927 size_t tarray_offset = NumberToSize(isolate, tarray->byte_offset()); \ |
898 uint8_t* tarray_base = \ | 928 uint8_t* tarray_base = \ |
899 static_cast<uint8_t*>(tarray->GetBuffer()->backing_store()) + \ | 929 static_cast<uint8_t*>(tarray->GetBuffer()->backing_store()) + \ |
900 tarray_offset; \ | 930 tarray_offset; \ |
901 lane_type lanes[kLaneCount]; \ | 931 lane_type lanes[kLaneCount]; \ |
902 for (int i = 0; i < kLaneCount; i++) { \ | 932 for (int i = 0; i < kLaneCount; i++) { \ |
903 lanes[i] = a->get_lane(i); \ | 933 lanes[i] = a->get_lane(i); \ |
904 } \ | 934 } \ |
905 memcpy(tarray_base + index * bpe, lanes, bytes); | 935 memcpy(tarray_base + lane * bpe, lanes, bytes); |
906 | |
907 | 936 |
908 #define SIMD_LOAD_FUNCTION(type, lane_type, lane_count) \ | 937 #define SIMD_LOAD_FUNCTION(type, lane_type, lane_count) \ |
909 RUNTIME_FUNCTION(Runtime_##type##Load) { \ | 938 RUNTIME_FUNCTION(Runtime_##type##Load) { \ |
910 HandleScope scope(isolate); \ | 939 HandleScope scope(isolate); \ |
911 SIMD_LOAD(type, lane_type, lane_count, lane_count, result); \ | 940 SIMD_LOAD(type, lane_type, lane_count, lane_count, result); \ |
912 return *result; \ | 941 return *result; \ |
913 } | 942 } |
914 | 943 |
915 | 944 |
916 #define SIMD_LOAD1_FUNCTION(type, lane_type, lane_count) \ | 945 #define SIMD_LOAD1_FUNCTION(type, lane_type, lane_count) \ |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 SIMD_LOADN_STOREN_TYPES(SIMD_LOAD3_FUNCTION) | 1004 SIMD_LOADN_STOREN_TYPES(SIMD_LOAD3_FUNCTION) |
976 SIMD_NUMERIC_TYPES(SIMD_STORE_FUNCTION) | 1005 SIMD_NUMERIC_TYPES(SIMD_STORE_FUNCTION) |
977 SIMD_LOADN_STOREN_TYPES(SIMD_STORE1_FUNCTION) | 1006 SIMD_LOADN_STOREN_TYPES(SIMD_STORE1_FUNCTION) |
978 SIMD_LOADN_STOREN_TYPES(SIMD_STORE2_FUNCTION) | 1007 SIMD_LOADN_STOREN_TYPES(SIMD_STORE2_FUNCTION) |
979 SIMD_LOADN_STOREN_TYPES(SIMD_STORE3_FUNCTION) | 1008 SIMD_LOADN_STOREN_TYPES(SIMD_STORE3_FUNCTION) |
980 | 1009 |
981 //------------------------------------------------------------------- | 1010 //------------------------------------------------------------------- |
982 | 1011 |
983 } // namespace internal | 1012 } // namespace internal |
984 } // namespace v8 | 1013 } // namespace v8 |
OLD | NEW |