[Git][ghc/ghc][wip/unroll-evac] Evac: Try unrolling copying

Ben Gamari gitlab at gitlab.haskell.org
Wed May 15 22:30:03 UTC 2019



Ben Gamari pushed to branch wip/unroll-evac at Glasgow Haskell Compiler / GHC


Commits:
e3f51af8 by Ben Gamari at 2019-05-15T22:29:51Z
Evac: Try unrolling copying

- - - - -


1 changed file:

- rts/sm/Evac.c


Changes:

=====================================
rts/sm/Evac.c
=====================================
@@ -88,20 +88,35 @@ alloc_for_copy (uint32_t size, uint32_t gen_no)
    The evacuate() code
    -------------------------------------------------------------------------- */
 
+/* Manually unroll copy for small closures */
+STATIC_INLINE GNUC_ATTR_HOT void
+copy_words(StgWord *from, StgWord *to, uint32_t n)
+{
+    switch (n) {
+      case 7: to[6] = from[6]; FALLTHROUGH;
+      case 6: to[5] = from[5]; FALLTHROUGH;
+      case 5: to[4] = from[4]; FALLTHROUGH;
+      case 4: to[3] = from[3]; FALLTHROUGH;
+      case 3: to[2] = from[2]; FALLTHROUGH;
+      case 2: to[1] = from[1]; FALLTHROUGH;
+      case 1: to[0] = from[0]; FALLTHROUGH;
+      case 0: break;
+      default:
+        memcpy(to, from, count * sizeof(StgWord));
+    }
+}
+
 STATIC_INLINE GNUC_ATTR_HOT void
 copy_tag(StgClosure **p, const StgInfoTable *info,
          StgClosure *src, uint32_t size, uint32_t gen_no, StgWord tag)
 {
     StgPtr to, from;
-    uint32_t i;
 
     to = alloc_for_copy(size,gen_no);
 
     from = (StgPtr)src;
     to[0] = (W_)info;
-    for (i = 1; i < size; i++) { // unroll for small i
-        to[i] = from[i];
-    }
+    copy_words(&from[1], &to[1], size-1)
 
 //  if (to+size+2 < bd->start + BLOCK_SIZE_W) {
 //      __builtin_prefetch(to + size + 2, 1);
@@ -148,15 +163,12 @@ copy_tag_nolock(StgClosure **p, const StgInfoTable *info,
          StgClosure *src, uint32_t size, uint32_t gen_no, StgWord tag)
 {
     StgPtr to, from;
-    uint32_t i;
 
     to = alloc_for_copy(size,gen_no);
 
     from = (StgPtr)src;
     to[0] = (W_)info;
-    for (i = 1; i < size; i++) { // unroll for small i
-        to[i] = from[i];
-    }
+    copy_words(&from[1], &to[1], size-1);
 
     // if somebody else reads the forwarding pointer, we better make
     // sure there's a closure at the end of it.
@@ -211,9 +223,7 @@ spin:
 
     from = (StgPtr)src;
     to[0] = info;
-    for (i = 1; i < size_to_copy; i++) { // unroll for small i
-        to[i] = from[i];
-    }
+    copy_words(&from[1], &to[1], size_to_copy-1);
 
     write_barrier();
     src->header.info = (const StgInfoTable*)MK_FORWARDING_PTR(to);



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/e3f51af859dddc22ef7047e83cbdd26fb9f10d45

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/e3f51af859dddc22ef7047e83cbdd26fb9f10d45
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190515/6b9586e7/attachment-0001.html>


More information about the ghc-commits mailing list