Reviewers: Hannes Payer,

Description:
Unravel kHeapObjectTagSize from the stub cache.

BUG=

Please review this at https://codereview.chromium.org/401613003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+39, -38 lines):
  M src/arm/stub-cache-arm.cc
  M src/arm64/stub-cache-arm64.cc
  M src/ia32/stub-cache-ia32.cc
  M src/mips/stub-cache-mips.cc
  M src/mips64/stub-cache-mips64.cc
  M src/stub-cache.h
  M src/x64/stub-cache-x64.cc
  M src/x87/stub-cache-x87.cc


Index: src/arm/stub-cache-arm.cc
diff --git a/src/arm/stub-cache-arm.cc b/src/arm/stub-cache-arm.cc
index 1898dbc6fb2704c9fee39495c8eff4fde57d90c8..50c3ff12d9db508e460c22a36c733d5bbced90db 100644
--- a/src/arm/stub-cache-arm.cc
+++ b/src/arm/stub-cache-arm.cc
@@ -202,10 +202,10 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
   uint32_t mask = kPrimaryTableSize - 1;
// We shift out the last two bits because they are not part of the hash and
   // they are always 01 for maps.
-  __ mov(scratch, Operand(scratch, LSR, kHeapObjectTagSize));
+  __ mov(scratch, Operand(scratch, LSR, kCacheIndexShift));
   // Mask down the eor argument to the minimum to keep the immediate
   // ARM-encodable.
-  __ eor(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask));
+  __ eor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask));
   // Prefer and_ to ubfx here because ubfx takes 2 cycles.
   __ and_(scratch, scratch, Operand(mask));

@@ -222,9 +222,9 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
              extra3);

   // Primary miss: Compute hash for secondary probe.
-  __ sub(scratch, scratch, Operand(name, LSR, kHeapObjectTagSize));
+  __ sub(scratch, scratch, Operand(name, LSR, kCacheIndexShift));
   uint32_t mask2 = kSecondaryTableSize - 1;
-  __ add(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask2));
+  __ add(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2));
   __ and_(scratch, scratch, Operand(mask2));

   // Probe the secondary table.
Index: src/arm64/stub-cache-arm64.cc
diff --git a/src/arm64/stub-cache-arm64.cc b/src/arm64/stub-cache-arm64.cc
index c3b48a5815e6037c390e5367a7ad254eed9b4d39..0a672bcf2f0db225f8d62580c78a511a90412caf 100644
--- a/src/arm64/stub-cache-arm64.cc
+++ b/src/arm64/stub-cache-arm64.cc
@@ -177,7 +177,7 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
   __ Add(scratch, scratch, extra);
   __ Eor(scratch, scratch, flags);
   // We shift out the last two bits because they are not part of the hash.
-  __ Ubfx(scratch, scratch, kHeapObjectTagSize,
+  __ Ubfx(scratch, scratch, kCacheIndexShift,
           CountTrailingZeros(kPrimaryTableSize, 64));

   // Probe the primary table.
@@ -185,8 +185,8 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
       scratch, extra, extra2, extra3);

   // Primary miss: Compute hash for secondary table.
-  __ Sub(scratch, scratch, Operand(name, LSR, kHeapObjectTagSize));
-  __ Add(scratch, scratch, flags >> kHeapObjectTagSize);
+  __ Sub(scratch, scratch, Operand(name, LSR, kCacheIndexShift));
+  __ Add(scratch, scratch, flags >> kCacheIndexShift);
   __ And(scratch, scratch, kSecondaryTableSize - 1);

   // Probe the secondary table.
Index: src/ia32/stub-cache-ia32.cc
diff --git a/src/ia32/stub-cache-ia32.cc b/src/ia32/stub-cache-ia32.cc
index a35be80deffac906f522aa68d8d5eb4f46e987e3..e02de20b156e3b9792a38a019d8ce5f031bcf6b2 100644
--- a/src/ia32/stub-cache-ia32.cc
+++ b/src/ia32/stub-cache-ia32.cc
@@ -205,10 +205,10 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
   __ xor_(offset, flags);
// We mask out the last two bits because they are not part of the hash and // they are always 01 for maps. Also in the two 'and' instructions below.
-  __ and_(offset, (kPrimaryTableSize - 1) << kHeapObjectTagSize);
+  __ and_(offset, (kPrimaryTableSize - 1) << kCacheIndexShift);
// ProbeTable expects the offset to be pointer scaled, which it is, because
   // the heap object tag size is 2 and the pointer size log 2 is also 2.
-  ASSERT(kHeapObjectTagSize == kPointerSizeLog2);
+  ASSERT(kCacheIndexShift == kPointerSizeLog2);

   // Probe the primary table.
ProbeTable(isolate(), masm, flags, kPrimary, name, receiver, offset, extra);
@@ -217,10 +217,10 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
   __ mov(offset, FieldOperand(name, Name::kHashFieldOffset));
   __ add(offset, FieldOperand(receiver, HeapObject::kMapOffset));
   __ xor_(offset, flags);
-  __ and_(offset, (kPrimaryTableSize - 1) << kHeapObjectTagSize);
+  __ and_(offset, (kPrimaryTableSize - 1) << kCacheIndexShift);
   __ sub(offset, name);
   __ add(offset, Immediate(flags));
-  __ and_(offset, (kSecondaryTableSize - 1) << kHeapObjectTagSize);
+  __ and_(offset, (kSecondaryTableSize - 1) << kCacheIndexShift);

   // Probe the secondary table.
   ProbeTable(
Index: src/mips/stub-cache-mips.cc
diff --git a/src/mips/stub-cache-mips.cc b/src/mips/stub-cache-mips.cc
index fc7315781c272dabbd9ab73700c5de2c446ae3d4..7fada5424b559f2fab6b72552e27fdf5dcfc6e41 100644
--- a/src/mips/stub-cache-mips.cc
+++ b/src/mips/stub-cache-mips.cc
@@ -196,8 +196,8 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
   uint32_t mask = kPrimaryTableSize - 1;
// We shift out the last two bits because they are not part of the hash and
   // they are always 01 for maps.
-  __ srl(scratch, scratch, kHeapObjectTagSize);
-  __ Xor(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask));
+  __ srl(scratch, scratch, kCacheIndexShift);
+  __ Xor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask));
   __ And(scratch, scratch, Operand(mask));

   // Probe the primary table.
@@ -213,10 +213,10 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
              extra3);

   // Primary miss: Compute hash for secondary probe.
-  __ srl(at, name, kHeapObjectTagSize);
+  __ srl(at, name, kCacheIndexShift);
   __ Subu(scratch, scratch, at);
   uint32_t mask2 = kSecondaryTableSize - 1;
- __ Addu(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask2));
+  __ Addu(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2));
   __ And(scratch, scratch, Operand(mask2));

   // Probe the secondary table.
Index: src/mips64/stub-cache-mips64.cc
diff --git a/src/mips64/stub-cache-mips64.cc b/src/mips64/stub-cache-mips64.cc index 0979c1e622e210e552e6c8d59234b47237a1878e..39ae974c2bf5e93cb3a4904c012de9b48ec972bb 100644
--- a/src/mips64/stub-cache-mips64.cc
+++ b/src/mips64/stub-cache-mips64.cc
@@ -197,8 +197,8 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
   uint64_t mask = kPrimaryTableSize - 1;
// We shift out the last two bits because they are not part of the hash and
   // they are always 01 for maps.
-  __ dsrl(scratch, scratch, kHeapObjectTagSize);
-  __ Xor(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask));
+  __ dsrl(scratch, scratch, kCacheIndexShift);
+  __ Xor(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask));
   __ And(scratch, scratch, Operand(mask));

   // Probe the primary table.
@@ -214,10 +214,10 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
              extra3);

   // Primary miss: Compute hash for secondary probe.
-  __ dsrl(at, name, kHeapObjectTagSize);
+  __ dsrl(at, name, kCacheIndexShift);
   __ Dsubu(scratch, scratch, at);
   uint64_t mask2 = kSecondaryTableSize - 1;
- __ Daddu(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask2));
+  __ Daddu(scratch, scratch, Operand((flags >> kCacheIndexShift) & mask2));
   __ And(scratch, scratch, Operand(mask2));

   // Probe the secondary table.
Index: src/stub-cache.h
diff --git a/src/stub-cache.h b/src/stub-cache.h
index 8c863e1bd895eb8e46c4896336393483248f40fa..4687c1cb2baf5992886d0cb500d42dd627f2686c 100644
--- a/src/stub-cache.h
+++ b/src/stub-cache.h
@@ -183,6 +183,11 @@ class StubCache {
   static const int kInterceptorArgsHolderIndex = 3;
   static const int kInterceptorArgsLength = 4;

+ // Setting the entry size such that the index is shifted by Name::kHashShift + // is convenient; shifting down the length field (to extract the hash code)
+  // automatically discards the hash bit field.
+  static const int kCacheIndexShift = Name::kHashShift;
+
  private:
   explicit StubCache(Isolate* isolate);

@@ -195,13 +200,9 @@ class StubCache {

   // Hash algorithm for the primary table.  This algorithm is replicated in
// assembler for every architecture. Returns an index into the table that
-  // is scaled by 1 << kHeapObjectTagSize.
+  // is scaled by 1 << kCacheIndexShift.
   static int PrimaryOffset(Name* name, Code::Flags flags, Map* map) {
-    // This works well because the heap object tag size and the hash
-    // shift are equal.  Shifting down the length field to get the
-    // hash code would effectively throw away two bits of the hash
-    // code.
-    STATIC_ASSERT(kHeapObjectTagSize == Name::kHashShift);
+    STATIC_ASSERT(kCacheIndexShift == Name::kHashShift);
     // Compute the hash of the name (use entire hash field).
     ASSERT(name->HasHashCode());
     uint32_t field = name->hash_field();
@@ -216,12 +217,12 @@ class StubCache {
         (static_cast<uint32_t>(flags) & ~Code::kFlagsNotUsedInLookup);
     // Base the offset on a simple combination of name, flags, and map.
     uint32_t key = (map_low32bits + field) ^ iflags;
-    return key & ((kPrimaryTableSize - 1) << kHeapObjectTagSize);
+    return key & ((kPrimaryTableSize - 1) << kCacheIndexShift);
   }

// Hash algorithm for the secondary table. This algorithm is replicated in // assembler for every architecture. Returns an index into the table that
-  // is scaled by 1 << kHeapObjectTagSize.
+  // is scaled by 1 << kCacheIndexShift.
   static int SecondaryOffset(Name* name, Code::Flags flags, int seed) {
     // Use the seed from the primary cache in the secondary cache.
     uint32_t name_low32bits =
@@ -231,7 +232,7 @@ class StubCache {
     uint32_t iflags =
         (static_cast<uint32_t>(flags) & ~Code::kFlagsNotUsedInLookup);
     uint32_t key = (seed - name_low32bits) + iflags;
-    return key & ((kSecondaryTableSize - 1) << kHeapObjectTagSize);
+    return key & ((kSecondaryTableSize - 1) << kCacheIndexShift);
   }

   // Compute the entry for a given offset in exactly the same way as
Index: src/x64/stub-cache-x64.cc
diff --git a/src/x64/stub-cache-x64.cc b/src/x64/stub-cache-x64.cc
index 508b1b3a9a2f6a39847e2a8df71b1b74ca06fa15..74f756a969a79c059c790f0d9026bef517f46457 100644
--- a/src/x64/stub-cache-x64.cc
+++ b/src/x64/stub-cache-x64.cc
@@ -24,13 +24,13 @@ static void ProbeTable(Isolate* isolate,
                        Register receiver,
                        Register name,
                        // The offset is scaled by 4, based on
-                       // kHeapObjectTagSize, which is two bits
+                       // kCacheIndexShift, which is two bits
                        Register offset) {
   // We need to scale up the pointer by 2 when the offset is scaled by less
   // than the pointer size.
   ASSERT(kPointerSize == kInt64Size
-      ? kPointerSizeLog2 == kHeapObjectTagSize + 1
-      : kPointerSizeLog2 == kHeapObjectTagSize);
+      ? kPointerSizeLog2 == StubCache::kCacheIndexShift + 1
+      : kPointerSizeLog2 == StubCache::kCacheIndexShift);
ScaleFactor scale_factor = kPointerSize == kInt64Size ? times_2 : times_1;

   ASSERT_EQ(3 * kPointerSize, sizeof(StubCache::Entry));
@@ -175,7 +175,7 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
   __ xorp(scratch, Immediate(flags));
// We mask out the last two bits because they are not part of the hash and // they are always 01 for maps. Also in the two 'and' instructions below. - __ andp(scratch, Immediate((kPrimaryTableSize - 1) << kHeapObjectTagSize));
+  __ andp(scratch, Immediate((kPrimaryTableSize - 1) << kCacheIndexShift));

   // Probe the primary table.
   ProbeTable(isolate, masm, flags, kPrimary, receiver, name, scratch);
@@ -184,10 +184,10 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
   __ movl(scratch, FieldOperand(name, Name::kHashFieldOffset));
   __ addl(scratch, FieldOperand(receiver, HeapObject::kMapOffset));
   __ xorp(scratch, Immediate(flags));
- __ andp(scratch, Immediate((kPrimaryTableSize - 1) << kHeapObjectTagSize));
+  __ andp(scratch, Immediate((kPrimaryTableSize - 1) << kCacheIndexShift));
   __ subl(scratch, name);
   __ addl(scratch, Immediate(flags));
- __ andp(scratch, Immediate((kSecondaryTableSize - 1) << kHeapObjectTagSize)); + __ andp(scratch, Immediate((kSecondaryTableSize - 1) << kCacheIndexShift));

   // Probe the secondary table.
   ProbeTable(isolate, masm, flags, kSecondary, receiver, name, scratch);
Index: src/x87/stub-cache-x87.cc
diff --git a/src/x87/stub-cache-x87.cc b/src/x87/stub-cache-x87.cc
index 74275f937c27c128e75142c0b850b034ef84ce65..98d55f2ba3d100d0badeefd18cba931665069746 100644
--- a/src/x87/stub-cache-x87.cc
+++ b/src/x87/stub-cache-x87.cc
@@ -205,10 +205,10 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
   __ xor_(offset, flags);
// We mask out the last two bits because they are not part of the hash and // they are always 01 for maps. Also in the two 'and' instructions below.
-  __ and_(offset, (kPrimaryTableSize - 1) << kHeapObjectTagSize);
+  __ and_(offset, (kPrimaryTableSize - 1) << kCacheIndexShift);
// ProbeTable expects the offset to be pointer scaled, which it is, because
   // the heap object tag size is 2 and the pointer size log 2 is also 2.
-  ASSERT(kHeapObjectTagSize == kPointerSizeLog2);
+  ASSERT(kCacheIndexShift == kPointerSizeLog2);

   // Probe the primary table.
ProbeTable(isolate(), masm, flags, kPrimary, name, receiver, offset, extra);
@@ -217,10 +217,10 @@ void StubCache::GenerateProbe(MacroAssembler* masm,
   __ mov(offset, FieldOperand(name, Name::kHashFieldOffset));
   __ add(offset, FieldOperand(receiver, HeapObject::kMapOffset));
   __ xor_(offset, flags);
-  __ and_(offset, (kPrimaryTableSize - 1) << kHeapObjectTagSize);
+  __ and_(offset, (kPrimaryTableSize - 1) << kCacheIndexShift);
   __ sub(offset, name);
   __ add(offset, Immediate(flags));
-  __ and_(offset, (kSecondaryTableSize - 1) << kHeapObjectTagSize);
+  __ and_(offset, (kSecondaryTableSize - 1) << kCacheIndexShift);

   // Probe the secondary table.
   ProbeTable(


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to