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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 return isolate->heap()->ToBoolean(args[0]->IsSimd128Value()); | 164 return isolate->heap()->ToBoolean(args[0]->IsSimd128Value()); |
165 } | 165 } |
166 | 166 |
167 | 167 |
168 //------------------------------------------------------------------- | 168 //------------------------------------------------------------------- |
169 | 169 |
170 // Utility macros. | 170 // Utility macros. |
171 | 171 |
172 // TODO(gdeepti): Fix to use ToNumber conversion once polyfill is updated. | 172 // TODO(gdeepti): Fix to use ToNumber conversion once polyfill is updated. |
173 #define CONVERT_SIMD_LANE_ARG_CHECKED(name, index, lanes) \ | 173 #define CONVERT_SIMD_LANE_ARG_CHECKED(name, index, lanes) \ |
174 Handle<Object> name_object = args.at<Object>(index); \ | 174 Handle<Object> name_object = args.at(index); \ |
175 if (!name_object->IsNumber()) { \ | 175 if (!name_object->IsNumber()) { \ |
176 THROW_NEW_ERROR_RETURN_FAILURE( \ | 176 THROW_NEW_ERROR_RETURN_FAILURE( \ |
177 isolate, NewTypeError(MessageTemplate::kInvalidSimdIndex)); \ | 177 isolate, NewTypeError(MessageTemplate::kInvalidSimdIndex)); \ |
178 } \ | 178 } \ |
179 double number = name_object->Number(); \ | 179 double number = name_object->Number(); \ |
180 if (number < 0 || number >= lanes || !IsInt32Double(number)) { \ | 180 if (number < 0 || number >= lanes || !IsInt32Double(number)) { \ |
181 THROW_NEW_ERROR_RETURN_FAILURE( \ | 181 THROW_NEW_ERROR_RETURN_FAILURE( \ |
182 isolate, NewRangeError(MessageTemplate::kInvalidSimdIndex)); \ | 182 isolate, NewRangeError(MessageTemplate::kInvalidSimdIndex)); \ |
183 } \ | 183 } \ |
184 uint32_t name = static_cast<uint32_t>(number); | 184 uint32_t name = static_cast<uint32_t>(number); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 bool lanes[kLaneCount]; \ | 221 bool lanes[kLaneCount]; \ |
222 for (int i = 0; i < kLaneCount; i++) { \ | 222 for (int i = 0; i < kLaneCount; i++) { \ |
223 lanes[i] = a->get_lane(i) op b->get_lane(i); \ | 223 lanes[i] = a->get_lane(i) op b->get_lane(i); \ |
224 } \ | 224 } \ |
225 Handle<bool_type> result = isolate->factory()->New##bool_type(lanes); | 225 Handle<bool_type> result = isolate->factory()->New##bool_type(lanes); |
226 | 226 |
227 //------------------------------------------------------------------- | 227 //------------------------------------------------------------------- |
228 | 228 |
229 // Common functions. | 229 // Common functions. |
230 | 230 |
231 #define GET_NUMERIC_ARG(lane_type, name, index) \ | 231 #define GET_NUMERIC_ARG(lane_type, name, index) \ |
232 Handle<Object> a; \ | 232 Handle<Object> a; \ |
233 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ | 233 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, a, \ |
234 isolate, a, Object::ToNumber(args.at<Object>(index))); \ | 234 Object::ToNumber(args.at(index))); \ |
235 name = ConvertNumber<lane_type>(a->Number()); | 235 name = ConvertNumber<lane_type>(a->Number()); |
236 | 236 |
237 #define GET_BOOLEAN_ARG(lane_type, name, index) \ | 237 #define GET_BOOLEAN_ARG(lane_type, name, index) \ |
238 name = args[index]->BooleanValue(); | 238 name = args[index]->BooleanValue(); |
239 | 239 |
240 #define SIMD_ALL_TYPES(FUNCTION) \ | 240 #define SIMD_ALL_TYPES(FUNCTION) \ |
241 FUNCTION(Float32x4, float, 4, NewNumber, GET_NUMERIC_ARG) \ | 241 FUNCTION(Float32x4, float, 4, NewNumber, GET_NUMERIC_ARG) \ |
242 FUNCTION(Int32x4, int32_t, 4, NewNumber, GET_NUMERIC_ARG) \ | 242 FUNCTION(Int32x4, int32_t, 4, NewNumber, GET_NUMERIC_ARG) \ |
243 FUNCTION(Uint32x4, uint32_t, 4, NewNumber, GET_NUMERIC_ARG) \ | 243 FUNCTION(Uint32x4, uint32_t, 4, NewNumber, GET_NUMERIC_ARG) \ |
244 FUNCTION(Bool32x4, bool, 4, ToBoolean, GET_BOOLEAN_ARG) \ | 244 FUNCTION(Bool32x4, bool, 4, ToBoolean, GET_BOOLEAN_ARG) \ |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 FUNCTION(Int32x4, int32_t, 32, 4) \ | 402 FUNCTION(Int32x4, int32_t, 32, 4) \ |
403 FUNCTION(Int16x8, int16_t, 16, 8) \ | 403 FUNCTION(Int16x8, int16_t, 16, 8) \ |
404 FUNCTION(Int8x16, int8_t, 8, 16) | 404 FUNCTION(Int8x16, int8_t, 8, 16) |
405 | 405 |
406 #define SIMD_UINT_TYPES(FUNCTION) \ | 406 #define SIMD_UINT_TYPES(FUNCTION) \ |
407 FUNCTION(Uint32x4, uint32_t, 32, 4) \ | 407 FUNCTION(Uint32x4, uint32_t, 32, 4) \ |
408 FUNCTION(Uint16x8, uint16_t, 16, 8) \ | 408 FUNCTION(Uint16x8, uint16_t, 16, 8) \ |
409 FUNCTION(Uint8x16, uint8_t, 8, 16) | 409 FUNCTION(Uint8x16, uint8_t, 8, 16) |
410 | 410 |
411 #define CONVERT_SHIFT_ARG_CHECKED(name, index) \ | 411 #define CONVERT_SHIFT_ARG_CHECKED(name, index) \ |
412 Handle<Object> name_object = args.at<Object>(index); \ | 412 Handle<Object> name_object = args.at(index); \ |
413 if (!name_object->IsNumber()) { \ | 413 if (!name_object->IsNumber()) { \ |
414 THROW_NEW_ERROR_RETURN_FAILURE( \ | 414 THROW_NEW_ERROR_RETURN_FAILURE( \ |
415 isolate, NewTypeError(MessageTemplate::kInvalidSimdOperation)); \ | 415 isolate, NewTypeError(MessageTemplate::kInvalidSimdOperation)); \ |
416 } \ | 416 } \ |
417 int32_t signed_shift = 0; \ | 417 int32_t signed_shift = 0; \ |
418 args[index]->ToInt32(&signed_shift); \ | 418 args[index]->ToInt32(&signed_shift); \ |
419 uint32_t name = bit_cast<uint32_t>(signed_shift); | 419 uint32_t name = bit_cast<uint32_t>(signed_shift); |
420 | 420 |
421 #define SIMD_LSL_FUNCTION(type, lane_type, lane_bits, lane_count) \ | 421 #define SIMD_LSL_FUNCTION(type, lane_type, lane_bits, lane_count) \ |
422 RUNTIME_FUNCTION(Runtime_##type##ShiftLeftByScalar) { \ | 422 RUNTIME_FUNCTION(Runtime_##type##ShiftLeftByScalar) { \ |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 | 873 |
874 //------------------------------------------------------------------- | 874 //------------------------------------------------------------------- |
875 | 875 |
876 // Load and Store functions. | 876 // Load and Store functions. |
877 | 877 |
878 #define SIMD_LOADN_STOREN_TYPES(FUNCTION) \ | 878 #define SIMD_LOADN_STOREN_TYPES(FUNCTION) \ |
879 FUNCTION(Float32x4, float, 4) \ | 879 FUNCTION(Float32x4, float, 4) \ |
880 FUNCTION(Int32x4, int32_t, 4) \ | 880 FUNCTION(Int32x4, int32_t, 4) \ |
881 FUNCTION(Uint32x4, uint32_t, 4) | 881 FUNCTION(Uint32x4, uint32_t, 4) |
882 | 882 |
883 #define SIMD_COERCE_INDEX(name, i) \ | 883 #define SIMD_COERCE_INDEX(name, i) \ |
884 Handle<Object> length_object, number_object; \ | 884 Handle<Object> length_object, number_object; \ |
885 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ | 885 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, length_object, \ |
886 isolate, length_object, Object::ToLength(isolate, args.at<Object>(i))); \ | 886 Object::ToLength(isolate, args.at(i))); \ |
887 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_object, \ | 887 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_object, \ |
888 Object::ToNumber(args.at<Object>(i))); \ | 888 Object::ToNumber(args.at(i))); \ |
889 if (number_object->Number() != length_object->Number()) { \ | 889 if (number_object->Number() != length_object->Number()) { \ |
890 THROW_NEW_ERROR_RETURN_FAILURE( \ | 890 THROW_NEW_ERROR_RETURN_FAILURE( \ |
891 isolate, NewTypeError(MessageTemplate::kInvalidSimdIndex)); \ | 891 isolate, NewTypeError(MessageTemplate::kInvalidSimdIndex)); \ |
892 } \ | 892 } \ |
893 int32_t name = number_object->Number(); | 893 int32_t name = number_object->Number(); |
894 | 894 |
895 // Common Load and Store Functions | 895 // Common Load and Store Functions |
896 | 896 |
897 #define SIMD_LOAD(type, lane_type, lane_count, count, result) \ | 897 #define SIMD_LOAD(type, lane_type, lane_count, count, result) \ |
898 static const int kLaneCount = lane_count; \ | 898 static const int kLaneCount = lane_count; \ |
899 DCHECK(args.length() == 2); \ | 899 DCHECK(args.length() == 2); \ |
900 CONVERT_SIMD_ARG_HANDLE_THROW(JSTypedArray, tarray, 0); \ | 900 CONVERT_SIMD_ARG_HANDLE_THROW(JSTypedArray, tarray, 0); \ |
901 SIMD_COERCE_INDEX(index, 1); \ | 901 SIMD_COERCE_INDEX(index, 1); \ |
902 size_t bpe = tarray->element_size(); \ | 902 size_t bpe = tarray->element_size(); \ |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 SIMD_LOADN_STOREN_TYPES(SIMD_LOAD3_FUNCTION) | 1007 SIMD_LOADN_STOREN_TYPES(SIMD_LOAD3_FUNCTION) |
1008 SIMD_NUMERIC_TYPES(SIMD_STORE_FUNCTION) | 1008 SIMD_NUMERIC_TYPES(SIMD_STORE_FUNCTION) |
1009 SIMD_LOADN_STOREN_TYPES(SIMD_STORE1_FUNCTION) | 1009 SIMD_LOADN_STOREN_TYPES(SIMD_STORE1_FUNCTION) |
1010 SIMD_LOADN_STOREN_TYPES(SIMD_STORE2_FUNCTION) | 1010 SIMD_LOADN_STOREN_TYPES(SIMD_STORE2_FUNCTION) |
1011 SIMD_LOADN_STOREN_TYPES(SIMD_STORE3_FUNCTION) | 1011 SIMD_LOADN_STOREN_TYPES(SIMD_STORE3_FUNCTION) |
1012 | 1012 |
1013 //------------------------------------------------------------------- | 1013 //------------------------------------------------------------------- |
1014 | 1014 |
1015 } // namespace internal | 1015 } // namespace internal |
1016 } // namespace v8 | 1016 } // namespace v8 |
OLD | NEW |