[m-rev.] for review: speed up boxing of foreign types

Peter Wang wangp at students.csse.unimelb.edu.au
Tue Aug 21 14:49:45 AEST 2007


Branches: main

runtime/mercury_heap.h:
        Provide fast paths in MR_MAYBE_BOX_FOREIGN_TYPE and
        MR_MAYBE_UNBOX_FOREIGN_TYPE for the case where the foreign type has
        the same size as the box.

        An implementation of the RC4 cipher using bitmaps was ~6x faster on
        neptune with this change in asm_fast.gc.  In hlc.gc there was no
        difference.

Index: runtime/mercury_heap.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_heap.h,v
retrieving revision 1.38
diff -u -p -r1.38 mercury_heap.h
--- runtime/mercury_heap.h      14 Oct 2006 16:59:41 -0000      1.38
+++ runtime/mercury_heap.h      21 Aug 2007 04:44:29 -0000
@@ -409,7 +409,9 @@
         do {                                                                \
             MR_CHECK_EXPR_TYPE((value), T);                                 \
             MR_CHECK_EXPR_TYPE((box), MR_Box);                              \
-            if (sizeof(T) > sizeof(MR_Box)) {                               \
+            if (sizeof(T) == sizeof(MR_Box)) {                              \
+                (box) = * (MR_Box *) &(value);                              \
+            } else if (sizeof(T) > sizeof(MR_Box)) {                        \
                 MR_Word     box_word;                                       \
                 size_t size_in_words =                                      \
                     (sizeof(T) + sizeof(MR_Word) - 1) / sizeof(MR_Word);    \
@@ -456,7 +458,11 @@
                 /* since it might be a global register. */                  \
                 /* Hence we need to use a temporary copy. */                \
                 MR_Box box_copy = (box);                                    \
-                MR_memcpy(&(value), &box_copy, sizeof(T));                  \
+                if (sizeof(T) == sizeof(MR_Box)) {                          \
+                    (value) = * (T *) &box_copy;                            \
+                } else {                                                    \
+                    MR_memcpy(&(value), &box_copy, sizeof(T));              \
+                }                                                           \
             }                                                               \
         } while (0)
 
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list