Bug 1388014 part 2 - IonMonkey: Simplify RValueAllocation hash function. r=jandem
authorNicolas B. Pierron <nicolas.b.pierron@mozilla.com>
Fri, 11 Aug 2017 12:26:05 +0000
changeset 374281 68444a862226f251b7a9448e660a435d7be34de2
parent 374280 ea704d8cd7798abea03a969734511e123257ca9a
child 374282 ebd299dd19d6f53ad7a22b55bd283911f77e0a88
push id32318
push userkwierso@gmail.com
push dateFri, 11 Aug 2017 20:16:01 +0000
treeherdermozilla-central@80ff3f300e05 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1388014
milestone57.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 1388014 part 2 - IonMonkey: Simplify RValueAllocation hash function. r=jandem
js/src/jit/Snapshots.cpp
js/src/jit/Snapshots.h
--- a/js/src/jit/Snapshots.cpp
+++ b/js/src/jit/Snapshots.cpp
@@ -376,30 +376,20 @@ RValueAllocation::write(CompactBufferWri
     writer.writeByte(mode_);
     writePayload(writer, layout.type1, arg1_);
     writePayload(writer, layout.type2, arg2_);
     writePadding(writer);
 }
 
 HashNumber
 RValueAllocation::hash() const {
-    CompactBufferWriter writer;
-    write(writer);
-
-    // We should never oom because the compact buffer writer has 32 inlined
-    // bytes, and in the worse case scenario, only encode 12 bytes
-    // (12 == mode + signed + signed + pad).
-    MOZ_ASSERT(!writer.oom());
-    MOZ_ASSERT(writer.length() <= 12);
-
     HashNumber res = 0;
-    for (size_t i = 0; i < writer.length(); i++) {
-        res = ((res << 8) | (res >> (sizeof(res) - 1)));
-        res ^= writer.buffer()[i];
-    }
+    res = HashNumber(mode_);
+    res = arg1_.index + (res << 6) + (res << 16) - res;
+    res = arg2_.index + (res << 6) + (res << 16) - res;
     return res;
 }
 
 static const char*
 ValTypeToString(JSValueType type)
 {
     switch (type) {
       case JSVAL_TYPE_INT32:
@@ -456,37 +446,16 @@ RValueAllocation::dump(GenericPrinter& o
     dumpPayload(out, layout.type1, arg1_);
     if (layout.type2 != PAYLOAD_NONE)
         out.printf(", ");
     dumpPayload(out, layout.type2, arg2_);
     if (layout.type1 != PAYLOAD_NONE)
         out.printf(")");
 }
 
-bool
-RValueAllocation::equalPayloads(PayloadType type, Payload lhs, Payload rhs)
-{
-    switch (type) {
-      case PAYLOAD_NONE:
-        return true;
-      case PAYLOAD_INDEX:
-        return lhs.index == rhs.index;
-      case PAYLOAD_STACK_OFFSET:
-        return lhs.stackOffset == rhs.stackOffset;
-      case PAYLOAD_GPR:
-        return lhs.gpr == rhs.gpr;
-      case PAYLOAD_FPU:
-        return lhs.fpu == rhs.fpu;
-      case PAYLOAD_PACKED_TAG:
-        return lhs.type == rhs.type;
-    }
-
-    return false;
-}
-
 SnapshotReader::SnapshotReader(const uint8_t* snapshots, uint32_t offset,
                                uint32_t RVATableSize, uint32_t listSize)
   : reader_(snapshots + offset, snapshots + listSize),
     allocReader_(snapshots + listSize, snapshots + listSize + RVATableSize),
     allocTable_(snapshots + listSize),
     allocRead_(0)
 {
     if (!snapshots)
--- a/js/src/jit/Snapshots.h
+++ b/js/src/jit/Snapshots.h
@@ -123,16 +123,21 @@ class RValueAllocation
     };
 
     union Payload {
         uint32_t index;
         int32_t stackOffset;
         Register gpr;
         FloatRegisterBits fpu;
         JSValueType type;
+
+        Payload() : index(0) {
+            static_assert(sizeof(index) == sizeof(Payload),
+                          "All Payload bits are initialized.");
+        }
     };
 
     Payload arg1_;
     Payload arg2_;
 
     static Payload payloadOfIndex(uint32_t index) {
         Payload p;
         p.index = index;
@@ -177,27 +182,33 @@ class RValueAllocation
         arg2_(a2)
     {
     }
 
     RValueAllocation(Mode mode, Payload a1)
       : mode_(mode),
         arg1_(a1)
     {
+        arg2_.index = 0;
     }
 
     explicit RValueAllocation(Mode mode)
       : mode_(mode)
     {
+        arg1_.index = 0;
+        arg2_.index = 0;
     }
 
   public:
     RValueAllocation()
       : mode_(INVALID)
-    { }
+    {
+        arg1_.index = 0;
+        arg2_.index = 0;
+    }
 
     // DOUBLE_REG
     static RValueAllocation Double(FloatRegister reg) {
         return RValueAllocation(DOUBLE_REG, payloadOfFloatRegister(reg));
     }
 
     // ANY_FLOAT_REG or ANY_FLOAT_STACK
     static RValueAllocation AnyFloat(FloatRegister reg) {
@@ -336,22 +347,24 @@ class RValueAllocation
         return arg2_.gpr;
     }
 
   public:
     void dump(GenericPrinter& out) const;
 
   public:
     bool operator==(const RValueAllocation& rhs) const {
-        if (mode_ != rhs.mode_)
-            return false;
-
-        const Layout& layout = layoutFromMode(mode());
-        return equalPayloads(layout.type1, arg1_, rhs.arg1_) &&
-            equalPayloads(layout.type2, arg2_, rhs.arg2_);
+        // Note, this equality compares the verbatim content of the payload,
+        // which is made possible because we ensure that the payload content is
+        // fully initialized during the creation.
+        static_assert(sizeof(int32_t) == sizeof(Payload),
+                      "All Payload bits are compared.");
+        return mode_ == rhs.mode_ &&
+               arg1_.index == rhs.arg1_.index &&
+               arg2_.index == rhs.arg2_.index;
     }
 
     HashNumber hash() const;
 
     struct Hasher
     {
         typedef RValueAllocation Key;
         typedef Key Lookup;