Bug 947711 part 3 - Refactor SIMD implementation to expose the Create API. r=nbp
authorHaitao Feng <haitao.feng@intel.com>
Fri, 17 Jan 2014 07:30:16 -0800
changeset 163967 defc74986fccde79bae762114ad023d6137b0edd
parent 163966 7218723f5a9b545f6a049a00628b67c5f559d168
child 163968 3475821c244889b1c09922d83ca44a81971ff118
push id38597
push usernpierron@mozilla.com
push dateFri, 17 Jan 2014 15:31:04 +0000
treeherdermozilla-inbound@defc74986fcc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs947711
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 947711 part 3 - Refactor SIMD implementation to expose the Create API. r=nbp --- js/src/builtin/SIMD.cpp | 49 +++++------------------------------------------ js/src/builtin/SIMD.h | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 44 deletions(-)
js/src/builtin/SIMD.cpp
js/src/builtin/SIMD.h
--- a/js/src/builtin/SIMD.cpp
+++ b/js/src/builtin/SIMD.cpp
@@ -30,58 +30,16 @@ using mozilla::IsNaN;
 namespace js {
 extern const JSFunctionSpec Float32x4Methods[];
 extern const JSFunctionSpec Int32x4Methods[];
 }
 
 ///////////////////////////////////////////////////////////////////////////
 // X4
 
-namespace js {
-struct Float32x4 {
-    typedef float Elem;
-    static const int32_t lanes = 4;
-    static const X4TypeRepresentation::Type type =
-        X4TypeRepresentation::TYPE_FLOAT32;
-
-    static JSObject &GetTypeObject(GlobalObject &global) {
-        return global.float32x4TypeObject();
-    }
-    static Elem toType(Elem a) {
-        return a;
-    }
-    static void toType2(JSContext *cx, JS::Handle<JS::Value> v, Elem *out) {
-        *out = v.toNumber();
-    }
-    static void setReturn(CallArgs &args, float value) {
-        args.rval().setDouble(JS::CanonicalizeNaN(value));
-    }
-};
-
-struct Int32x4 {
-    typedef int32_t Elem;
-    static const int32_t lanes = 4;
-    static const X4TypeRepresentation::Type type =
-        X4TypeRepresentation::TYPE_INT32;
-
-    static JSObject &GetTypeObject(GlobalObject &global) {
-        return global.int32x4TypeObject();
-    }
-    static Elem toType(Elem a) {
-        return ToInt32(a);
-    }
-    static void toType2(JSContext *cx, JS::Handle<JS::Value> v, Elem *out) {
-        ToInt32(cx,v,out);
-    }
-    static void setReturn(CallArgs &args, int32_t value) {
-        args.rval().setInt32(value);
-    }
-};
-} // namespace js
-
 #define LANE_ACCESSOR(Type32x4, lane) \
     bool Type32x4##Lane##lane(JSContext *cx, unsigned argc, Value *vp) { \
         static const char *laneNames[] = {"lane 0", "lane 1", "lane 2", "lane3"}; \
         CallArgs args = CallArgsFromVp(argc, vp); \
         if(!args.thisv().isObject() || !IsTypedDatum(args.thisv().toObject())) { \
             JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, \
                                  X4Type::class_.name, laneNames[lane], \
                                  InformalValueTypeName(args.thisv())); \
@@ -419,31 +377,34 @@ ObjectIsVector(JSObject &obj) {
         return false;
     TypeRepresentation *typeRepr = AsTypedDatum(obj).datumTypeRepresentation();
     if (typeRepr->kind() != TypeRepresentation::X4)
         return false;
     return typeRepr->asX4()->type() == V::type;
 }
 
 template<typename V>
-static JSObject *
-Create(JSContext *cx, typename V::Elem *data)
+JSObject *
+js::Create(JSContext *cx, typename V::Elem *data)
 {
     RootedObject typeObj(cx, &V::GetTypeObject(*cx->global()));
     JS_ASSERT(typeObj);
 
     Rooted<TypedObject *> result(cx, TypedObject::createZeroed(cx, typeObj, 0));
     if (!result)
         return nullptr;
 
     typename V::Elem *resultMem = reinterpret_cast<typename V::Elem *>(result->typedMem());
     memcpy(resultMem, data, sizeof(typename V::Elem) * V::lanes);
     return result;
 }
 
+template JSObject *js::Create<Float32x4>(JSContext *cx, Float32x4::Elem *data);
+template JSObject *js::Create<Int32x4>(JSContext *cx, Int32x4::Elem *data);
+
 namespace js {
 template<typename T, typename V>
 struct Abs {
     static inline T apply(T x, T zero) {return V::toType(x < 0 ? -1 * x : x);}
 };
 template<typename T, typename V>
 struct Neg {
     static inline T apply(T x, T zero) {return V::toType(-1 * x);}
--- a/js/src/builtin/SIMD.h
+++ b/js/src/builtin/SIMD.h
@@ -4,16 +4,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef builtin_SIMD_h
 #define builtin_SIMD_h
 
 #include "jsapi.h"
 #include "jsobj.h"
+#include "builtin/TypeRepresentation.h"
+#include "vm/GlobalObject.h"
 
 /*
  * JS SIMD functions.
  * Spec matching polyfill:
  * https://github.com/johnmccutchan/ecmascript_simd/blob/master/src/ecmascript_simd.js
  */
 
 namespace js {
@@ -21,14 +23,59 @@ namespace js {
 class SIMDObject : public JSObject
 {
   public:
     static const Class class_;
     static JSObject* initClass(JSContext *cx, Handle<GlobalObject *> global);
     static bool toString(JSContext *cx, unsigned int argc, jsval *vp);
 };
 
+// These classes exist for use with templates below.
+
+struct Float32x4 {
+    typedef float Elem;
+    static const int32_t lanes = 4;
+    static const X4TypeRepresentation::Type type =
+        X4TypeRepresentation::TYPE_FLOAT32;
+
+    static JSObject &GetTypeObject(GlobalObject &global) {
+        return global.float32x4TypeObject();
+    }
+    static Elem toType(Elem a) {
+        return a;
+    }
+    static void toType2(JSContext *cx, JS::Handle<JS::Value> v, Elem *out) {
+        *out = v.toNumber();
+    }
+    static void setReturn(CallArgs &args, float value) {
+        args.rval().setDouble(JS::CanonicalizeNaN(value));
+    }
+};
+
+struct Int32x4 {
+    typedef int32_t Elem;
+    static const int32_t lanes = 4;
+    static const X4TypeRepresentation::Type type =
+        X4TypeRepresentation::TYPE_INT32;
+
+    static JSObject &GetTypeObject(GlobalObject &global) {
+        return global.int32x4TypeObject();
+    }
+    static Elem toType(Elem a) {
+        return ToInt32(a);
+    }
+    static void toType2(JSContext *cx, JS::Handle<JS::Value> v, Elem *out) {
+        ToInt32(cx,v,out);
+    }
+    static void setReturn(CallArgs &args, int32_t value) {
+        args.rval().setInt32(value);
+    }
+};
+
+template<typename V>
+JSObject *Create(JSContext *cx, typename V::Elem *data);
+
 }  /* namespace js */
 
 JSObject *
 js_InitSIMDClass(JSContext *cx, js::HandleObject obj);
 
 #endif /* builtin_SIMD_h */