OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/v8.h" |
| 6 |
| 7 #include "src/arguments.h" |
| 8 #include "src/base/macros.h" |
| 9 #include "src/conversions.h" |
| 10 #include "src/runtime/runtime-utils.h" |
| 11 |
| 12 // Implement Single Instruction Multiple Data (SIMD) operations as defined in |
| 13 // the SIMD.js draft spec: |
| 14 // http://littledan.github.io/simd.html |
| 15 |
| 16 #define NumberToFloat32x4Component NumberToFloat |
| 17 #define EqualsFloat32x4 EqualsFloat |
| 18 |
| 19 #define CONVERT_SIMD_LANE_ARG_CHECKED(name, index, lanes) \ |
| 20 RUNTIME_ASSERT(args[index]->IsSmi()); \ |
| 21 int name = args.smi_at(index); \ |
| 22 RUNTIME_ASSERT(name >= 0 && name < lanes); |
| 23 |
| 24 #define SIMD4_CREATE_FUNCTION(type) \ |
| 25 RUNTIME_FUNCTION(Runtime_Create##type) { \ |
| 26 HandleScope scope(isolate); \ |
| 27 DCHECK(args.length() == 4); \ |
| 28 CONVERT_NUMBER_ARG_HANDLE_CHECKED(w, 0); \ |
| 29 CONVERT_NUMBER_ARG_HANDLE_CHECKED(x, 1); \ |
| 30 CONVERT_NUMBER_ARG_HANDLE_CHECKED(y, 2); \ |
| 31 CONVERT_NUMBER_ARG_HANDLE_CHECKED(z, 3); \ |
| 32 return *isolate->factory()->NewFloat32x4( \ |
| 33 NumberTo##type##Component(*w), NumberTo##type##Component(*x), \ |
| 34 NumberTo##type##Component(*y), NumberTo##type##Component(*z)); \ |
| 35 } |
| 36 |
| 37 #define SIMD_CREATE_WRAPPER_FUNCTION(type) \ |
| 38 RUNTIME_FUNCTION(Runtime_New##type##Wrapper) { \ |
| 39 HandleScope scope(isolate); \ |
| 40 DCHECK(args.length() == 1); \ |
| 41 CONVERT_ARG_HANDLE_CHECKED(type, value, 0); \ |
| 42 return *Object::ToObject(isolate, value).ToHandleChecked(); \ |
| 43 } |
| 44 |
| 45 #define SIMD_CHECK_FUNCTION(type) \ |
| 46 RUNTIME_FUNCTION(Runtime_##type##Check) { \ |
| 47 HandleScope scope(isolate); \ |
| 48 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \ |
| 49 return *a; \ |
| 50 } |
| 51 |
| 52 #define SIMD_EXTRACT_LANE_FUNCTION(type, lanes) \ |
| 53 RUNTIME_FUNCTION(Runtime_##type##ExtractLane) { \ |
| 54 HandleScope scope(isolate); \ |
| 55 DCHECK(args.length() == 2); \ |
| 56 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \ |
| 57 CONVERT_SIMD_LANE_ARG_CHECKED(lane, 1, lanes); \ |
| 58 return *isolate->factory()->NewNumber(a->get_lane(lane)); \ |
| 59 } |
| 60 |
| 61 #define SIMD4_EQUALS_FUNCTION(type) \ |
| 62 RUNTIME_FUNCTION(Runtime_##type##Equals) { \ |
| 63 HandleScope scope(isolate); \ |
| 64 DCHECK(args.length() == 2); \ |
| 65 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \ |
| 66 CONVERT_ARG_HANDLE_CHECKED(type, b, 1); \ |
| 67 return Equals##type(a->get_lane(0), b->get_lane(0)) && \ |
| 68 Equals##type(a->get_lane(1), b->get_lane(1)) && \ |
| 69 Equals##type(a->get_lane(2), b->get_lane(2)) && \ |
| 70 Equals##type(a->get_lane(3), b->get_lane(3)) \ |
| 71 ? Smi::FromInt(EQUAL) \ |
| 72 : Smi::FromInt(NOT_EQUAL); \ |
| 73 } |
| 74 |
| 75 #define SIMD4_EXTRACT_LANE_FUNCTION(type) SIMD_EXTRACT_LANE_FUNCTION(type, 4) |
| 76 |
| 77 #define SIMD4_FUNCTIONS(type) \ |
| 78 SIMD4_CREATE_FUNCTION(type) \ |
| 79 SIMD_CREATE_WRAPPER_FUNCTION(type) \ |
| 80 SIMD_CHECK_FUNCTION(type) \ |
| 81 SIMD4_EXTRACT_LANE_FUNCTION(type) \ |
| 82 SIMD4_EQUALS_FUNCTION(type) |
| 83 |
| 84 |
| 85 namespace v8 { |
| 86 namespace internal { |
| 87 |
| 88 namespace { |
| 89 |
| 90 // Convert from Number object to float. |
| 91 inline float NumberToFloat(Object* number) { |
| 92 // Don't bother checking for Smi, we might still overflow a float. |
| 93 return DoubleToFloat32(number->Number()); |
| 94 } |
| 95 |
| 96 |
| 97 inline bool EqualsFloat(float x, float y) { |
| 98 if (std::isnan(x) || std::isnan(y)) return false; |
| 99 return x == y; |
| 100 } |
| 101 |
| 102 } // namespace |
| 103 |
| 104 SIMD4_FUNCTIONS(Float32x4) |
| 105 } |
| 106 } // namespace v8::internal |
OLD | NEW |