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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
Index: src/runtime/runtime-simd.cc
diff --git a/src/runtime/runtime-simd.cc b/src/runtime/runtime-simd.cc
new file mode 100644
index 0000000000000000000000000000000000000000..99b1747506e2d0275cabce1d9f2ec43c524c7bcf
--- /dev/null
+++ b/src/runtime/runtime-simd.cc
@@ -0,0 +1,85 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/v8.h"
+
+#include "src/arguments.h"
+#include "src/base/macros.h"
+#include "src/conversions.h"
+#include "src/runtime/runtime-utils.h"
+
+// Implement Single Instruction Multiple Data (SIMD) operations as defined in
+// the SIMD.js draft spec:
+// http://littledan.github.io/simd.html
+
+#define NumberToFloat32x4Component NumberToFloat
+
+#define CONVERT_SIMD_LANE_ARG_CHECKED(name, index, lanes) \
+ RUNTIME_ASSERT(args[index]->IsSmi()); \
+ int name = args.smi_at(index); \
+ RUNTIME_ASSERT(name >= 0 && name < lanes);
+
+#define SIMD_CHECK_FUNCTION(type) \
+ RUNTIME_FUNCTION(Runtime_##type##Check) { \
+ HandleScope scope(isolate); \
+ CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \
+ return *a; \
+ }
+
+#define SIMD_EXTRACT_LANE_FUNCTION(type, lanes) \
+ RUNTIME_FUNCTION(Runtime_##type##ExtractLane) { \
+ HandleScope scope(isolate); \
+ DCHECK(args.length() == 2); \
+ CONVERT_ARG_HANDLE_CHECKED(type, a, 0); \
+ CONVERT_SIMD_LANE_ARG_CHECKED(lane, 1, lanes); \
+ return *isolate->factory()->NewNumber(a->get_lane(lane)); \
+ }
+
+#define SIMD4_CREATE_FUNCTION(type) \
+ RUNTIME_FUNCTION(Runtime_Create##type) { \
+ HandleScope scope(isolate); \
+ DCHECK(args.length() == 4); \
+ CONVERT_NUMBER_ARG_HANDLE_CHECKED(w, 0); \
+ CONVERT_NUMBER_ARG_HANDLE_CHECKED(x, 1); \
+ CONVERT_NUMBER_ARG_HANDLE_CHECKED(y, 2); \
+ CONVERT_NUMBER_ARG_HANDLE_CHECKED(z, 3); \
+ return *isolate->factory()->NewFloat32x4( \
+ NumberTo##type##Component(*w), NumberTo##type##Component(*x), \
+ NumberTo##type##Component(*y), NumberTo##type##Component(*z)); \
+ }
+
+#define SIMD_CREATE_WRAPPER_FUNCTION(type) \
+ RUNTIME_FUNCTION(Runtime_New##type##Wrapper) { \
+ HandleScope scope(isolate); \
+ DCHECK(args.length() == 1); \
+ CONVERT_ARG_HANDLE_CHECKED(type, value, 0); \
+ return *Object::ToObject(isolate, value).ToHandleChecked(); \
+ }
+
+#define SIMD4_EXTRACT_LANE_FUNCTION(type) SIMD_EXTRACT_LANE_FUNCTION(type, 4)
+
+
+#define SIMD4_FUNCTIONS(type) \
+ SIMD4_CREATE_FUNCTION(type) \
+ SIMD_CREATE_WRAPPER_FUNCTION(type) \
+ SIMD_CHECK_FUNCTION(type) \
+ SIMD4_EXTRACT_LANE_FUNCTION(type)
+
+
+namespace v8 {
+namespace internal {
+
+namespace {
+
+// Convert from Number object to float.
+inline float NumberToFloat(Object* number) {
+ // Don't bother checking for Smi, we might still overflow a float.
+ return DoubleToFloat32(number->Number());
+}
+
+} // namespace
+
+SIMD4_FUNCTIONS(Float32x4)
+}
+} // namespace v8::internal

Powered by Google App Engine
This is Rietveld 408576698