Reviewers: sgjesse,

Message:
Søren,

may you have a look?

There might be even faster implementations, but let's start with the basic one.

If overall inline asm is ok, I'd port it under VS. For ARM the loop might be
the best approach (at least I am not aware of any better approach.)

Description:
Faster filling of arrays of holes.

Please review this at http://codereview.chromium.org/661105

Affected files:
  M src/heap.cc
  M src/utils.h


Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index cfb786ac7ab9e8b3f00910029d31b5d6f63e14ca..009be6e06e75904f2376b750714d5619ab67ac10 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -2977,12 +2977,11 @@ Object* Heap::AllocateFixedArrayWithHoles(int length) {
     reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
     FixedArray* array = FixedArray::cast(result);
     array->set_length(length);
-    // Initialize body.
-    Object* value = the_hole_value();
-    for (int index = 0; index < length; index++)  {
-      ASSERT(!Heap::InNewSpace(value));  // value = the hole
-      array->set(index, value, SKIP_WRITE_BARRIER);
-    }
+    // Initialize body.  Hole resides in old space, so no need to
+    // update RSets.
+    MemsetPointer(HeapObject::RawField(array, FixedArray::kHeaderSize),
+                  the_hole_value(),
+                  length);
   }
   return result;
 }
Index: src/utils.h
diff --git a/src/utils.h b/src/utils.h
index 2cad4c12e4a8f93ee46cd4d2214b8583d8f09dbb..8f204bb17efbacfd4db8e1abf81971bc33995513 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -572,6 +572,29 @@ static inline int CompareChars(const lchar* lhs, const rchar* rhs, int chars) {
 }


+template <typename T>
+static inline void MemsetPointer(T** dest, T* value, int counter) {
+#if defined(V8_HOST_ARCH_IA32)
+#define STOS "stosl"
+#elif defined(V8_HOST_ARCH_X64)
+#define STOS "stosq"
+#endif
+
+#if defined(__GNUC__) && defined(STOS)
+  asm("cld\n\trep\n\t" STOS
+      : /* no outout */
+      : "c" (counter), "a" (value), "D" (dest)
+      :);
+#else
+  for (int i = 0; i < counter; i++) {
+    dest[i] = value;
+  }
+#endif
+
+#undef HAS_STOS
+}
+
+
 // Calculate 10^exponent.
 int TenToThe(int exponent);



--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to