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

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

Issue 1219943002: Expose SIMD.Float32x4 type to Javascript. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
(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
18 #define CONVERT_SIMD_LANE_ARG_CHECKED(name, index, lanes) \
19 RUNTIME_ASSERT(args[index]->IsSmi()); \
20 int name = args.smi_at(index); \
21 RUNTIME_ASSERT(name >= 0 && name < lanes);
22
23 #define SIMD_CHECK_FUNCTION(type) \
24 RUNTIME_FUNCTION(Runtime_##type##Check) { \
25 HandleScope scope(isolate); \
26 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \
27 return *a; \
28 }
29
30 #define SIMD_EXTRACT_LANE_FUNCTION(type, lanes) \
31 RUNTIME_FUNCTION(Runtime_##type##ExtractLane) { \
32 HandleScope scope(isolate); \
33 DCHECK(args.length() == 2); \
34 CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \
35 CONVERT_SIMD_LANE_ARG_CHECKED(lane, 1, lanes); \
36 return *isolate->factory()->NewNumber(a->get_lane(lane)); \
37 }
38
39 #define SIMD4_CREATE_FUNCTION(type) \
40 RUNTIME_FUNCTION(Runtime_Create##type) { \
41 HandleScope scope(isolate); \
42 DCHECK(args.length() == 4); \
43 CONVERT_NUMBER_ARG_HANDLE_CHECKED(w, 0); \
44 CONVERT_NUMBER_ARG_HANDLE_CHECKED(x, 1); \
45 CONVERT_NUMBER_ARG_HANDLE_CHECKED(y, 2); \
46 CONVERT_NUMBER_ARG_HANDLE_CHECKED(z, 3); \
47 return *isolate->factory()->NewFloat32x4( \
48 NumberTo##type##Component(*w), NumberTo##type##Component(*x), \
49 NumberTo##type##Component(*y), NumberTo##type##Component(*z)); \
50 }
51
52 #define SIMD_CREATE_WRAPPER_FUNCTION(type) \
53 RUNTIME_FUNCTION(Runtime_New##type##Wrapper) { \
54 HandleScope scope(isolate); \
55 DCHECK(args.length() == 1); \
56 CONVERT_ARG_HANDLE_CHECKED(type, value, 0); \
57 return *Object::ToObject(isolate, value).ToHandleChecked(); \
58 }
59
60 #define SIMD4_EXTRACT_LANE_FUNCTION(type) SIMD_EXTRACT_LANE_FUNCTION(type, 4)
61
62
63 #define SIMD4_FUNCTIONS(type) \
64 SIMD4_CREATE_FUNCTION(type) \
65 SIMD_CREATE_WRAPPER_FUNCTION(type) \
66 SIMD_CHECK_FUNCTION(type) \
67 SIMD4_EXTRACT_LANE_FUNCTION(type)
68
69
70 namespace v8 {
71 namespace internal {
72
73 namespace {
74
75 // Convert from Number object to float.
76 inline float NumberToFloat(Object* number) {
77 // Don't bother checking for Smi, we might still overflow a float.
78 return DoubleToFloat32(number->Number());
79 }
80
81 } // namespace
82
83 SIMD4_FUNCTIONS(Float32x4)
84 }
85 } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698