Bug 1229396: Templatize get{Float,Double,SimdData}; r=jandem
authorBenjamin Bouvier <benj@benj.me>
Tue, 01 Dec 2015 19:09:40 +0100
changeset 309681 b7a7fcf24c4904f2c687eebfba067685a0e3699a
parent 309680 1b964e554709aedb32e894ca044edcfdca8f1298
child 309682 54c0681d35b05e2c333d22667b7490fdb24711cb
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1229396
milestone45.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 1229396: Templatize get{Float,Double,SimdData}; r=jandem
js/src/jit/x86-shared/MacroAssembler-x86-shared.cpp
js/src/jit/x86-shared/MacroAssembler-x86-shared.h
--- a/js/src/jit/x86-shared/MacroAssembler-x86-shared.cpp
+++ b/js/src/jit/x86-shared/MacroAssembler-x86-shared.cpp
@@ -221,83 +221,58 @@ MacroAssemblerX86Shared::atomicExchangeT
 
 template void
 MacroAssemblerX86Shared::atomicExchangeToTypedIntArray(Scalar::Type arrayType, const Address& mem,
                                                        Register value, Register temp, AnyRegister output);
 template void
 MacroAssemblerX86Shared::atomicExchangeToTypedIntArray(Scalar::Type arrayType, const BaseIndex& mem,
                                                        Register value, Register temp, AnyRegister output);
 
-MacroAssemblerX86Shared::Float*
-MacroAssemblerX86Shared::getFloat(float f)
+template<class T, class Map>
+T*
+MacroAssemblerX86Shared::getConstant(const typename T::Pod& value, Map& map,
+                                     Vector<T, 0, SystemAllocPolicy>& vec)
 {
-    if (!floatMap_.initialized()) {
-        enoughMemory_ &= floatMap_.init();
+    typedef typename Map::AddPtr AddPtr;
+    if (!map.initialized()) {
+        enoughMemory_ &= map.init();
         if (!enoughMemory_)
             return nullptr;
     }
-    size_t floatIndex;
-    if (FloatMap::AddPtr p = floatMap_.lookupForAdd(f)) {
-        floatIndex = p->value();
+    size_t index;
+    if (AddPtr p = map.lookupForAdd(value)) {
+        index = p->value();
     } else {
-        floatIndex = floats_.length();
-        enoughMemory_ &= floats_.append(Float(f));
+        index = vec.length();
+        enoughMemory_ &= vec.append(T(value));
         if (!enoughMemory_)
             return nullptr;
-        enoughMemory_ &= floatMap_.add(p, f, floatIndex);
+        enoughMemory_ &= map.add(p, value, index);
         if (!enoughMemory_)
             return nullptr;
     }
-    return &floats_[floatIndex];
+    return &vec[index];
+}
+
+MacroAssemblerX86Shared::Float*
+MacroAssemblerX86Shared::getFloat(float f)
+{
+    return getConstant<Float, FloatMap>(f, floatMap_, floats_);
 }
 
 MacroAssemblerX86Shared::Double*
 MacroAssemblerX86Shared::getDouble(double d)
 {
-    if (!doubleMap_.initialized()) {
-        enoughMemory_ &= doubleMap_.init();
-        if (!enoughMemory_)
-            return nullptr;
-    }
-    size_t doubleIndex;
-    if (DoubleMap::AddPtr p = doubleMap_.lookupForAdd(d)) {
-        doubleIndex = p->value();
-    } else {
-        doubleIndex = doubles_.length();
-        enoughMemory_ &= doubles_.append(Double(d));
-        if (!enoughMemory_)
-            return nullptr;
-        enoughMemory_ &= doubleMap_.add(p, d, doubleIndex);
-        if (!enoughMemory_)
-            return nullptr;
-    }
-    return &doubles_[doubleIndex];
+    return getConstant<Double, DoubleMap>(d, doubleMap_, doubles_);
 }
 
 MacroAssemblerX86Shared::SimdData*
 MacroAssemblerX86Shared::getSimdData(const SimdConstant& v)
 {
-    if (!simdMap_.initialized()) {
-        enoughMemory_ &= simdMap_.init();
-        if (!enoughMemory_)
-            return nullptr;
-    }
-    size_t index;
-    if (SimdMap::AddPtr p = simdMap_.lookupForAdd(v)) {
-        index = p->value();
-    } else {
-        index = simds_.length();
-        enoughMemory_ &= simds_.append(SimdData(v));
-        if (!enoughMemory_)
-            return nullptr;
-        enoughMemory_ &= simdMap_.add(p, v, index);
-        if (!enoughMemory_)
-            return nullptr;
-    }
-    return &simds_[index];
+    return getConstant<SimdData, SimdMap>(v, simdMap_, simds_);
 }
 
 static bool
 AppendShiftedUses(const MacroAssemblerX86Shared::UsesVector& old, size_t delta,
                   MacroAssemblerX86Shared::UsesVector* vec)
 {
     for (CodeOffset use : old) {
         use.offsetBy(delta);
--- a/js/src/jit/x86-shared/MacroAssembler-x86-shared.h
+++ b/js/src/jit/x86-shared/MacroAssembler-x86-shared.h
@@ -44,58 +44,69 @@ class MacroAssemblerX86Shared : public A
     // Perform a downcast. Should be removed by Bug 996602.
     MacroAssembler& asMasm();
     const MacroAssembler& asMasm() const;
 
   public:
     typedef Vector<CodeOffset, 0, SystemAllocPolicy> UsesVector;
 
   protected:
+
     // For Double, Float and SimdData, make the move ctors explicit so that MSVC
     // knows what to use instead of copying these data structures.
     struct Double {
+        typedef double Pod;
         double value;
         UsesVector uses;
+
         explicit Double(double value) : value(value) {}
         Double(Double&& other) : value(other.value), uses(mozilla::Move(other.uses)) {}
         explicit Double(const Double&) = delete;
     };
 
     // These use SystemAllocPolicy since asm.js releases memory after each
     // function is compiled, and these need to live until after all functions
     // are compiled.
     Vector<Double, 0, SystemAllocPolicy> doubles_;
     typedef HashMap<double, size_t, DefaultHasher<double>, SystemAllocPolicy> DoubleMap;
     DoubleMap doubleMap_;
 
     struct Float {
+        typedef float Pod;
         float value;
         UsesVector uses;
+
         explicit Float(float value) : value(value) {}
         Float(Float&& other) : value(other.value), uses(mozilla::Move(other.uses)) {}
         explicit Float(const Float&) = delete;
     };
 
     Vector<Float, 0, SystemAllocPolicy> floats_;
     typedef HashMap<float, size_t, DefaultHasher<float>, SystemAllocPolicy> FloatMap;
     FloatMap floatMap_;
 
     struct SimdData {
+        typedef SimdConstant Pod;
         SimdConstant value;
         UsesVector uses;
+
         explicit SimdData(const SimdConstant& v) : value(v) {}
         SimdData(SimdData&& other) : value(other.value), uses(mozilla::Move(other.uses)) {}
         explicit SimdData(const SimdData&) = delete;
+
         SimdConstant::Type type() const { return value.type(); }
     };
 
     Vector<SimdData, 0, SystemAllocPolicy> simds_;
     typedef HashMap<SimdConstant, size_t, SimdConstant, SystemAllocPolicy> SimdMap;
     SimdMap simdMap_;
 
+    template<class T, class Map>
+    T* getConstant(const typename T::Pod& value, Map& map, Vector<T, 0, SystemAllocPolicy>& vec);
+
     Float* getFloat(float f);
     Double* getDouble(double d);
     SimdData* getSimdData(const SimdConstant& v);
 
     bool asmMergeWith(const MacroAssemblerX86Shared& other);
 
   public:
     using Assembler::call;