Omit register keyword in performance-critical code if C++ compiler used
authorIvan Maidanski <ivmai@mail.ru>
Thu, 22 Feb 2018 21:19:37 +0000 (00:19 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 22 Feb 2018 21:19:37 +0000 (00:19 +0300)
Issue #206 (bdwgc).

* headers.c (GC_next_used_block): Replace register keyword to REGISTER.
* include/private/gc_hdrs.h [HASH_TL] (GET_BI, GET_HDR_ADDR, GET_HDR,
SET_HDR): Likewise.
* mark.c (GC_push_all_eager): Likewise.
* mark.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager):
Likewise.
* include/private/gc_priv.h (REGISTER): New macro (defined before
include gc_hdrs.h); add comment.

headers.c
include/private/gc_hdrs.h
include/private/gc_priv.h
mark.c

index bdc8311..16bc8b0 100644 (file)
--- a/headers.c
+++ b/headers.c
@@ -341,12 +341,13 @@ void GC_apply_to_all_blocks(void (*fn)(struct hblk *h, word client_data),
 /* Return 0 if there is none.                           */
 GC_INNER struct hblk * GC_next_used_block(struct hblk *h)
 {
-    register bottom_index * bi;
-    register word j = ((word)h >> LOG_HBLKSIZE) & (BOTTOM_SZ-1);
+    REGISTER bottom_index * bi;
+    REGISTER word j = ((word)h >> LOG_HBLKSIZE) & (BOTTOM_SZ-1);
 
     GET_BI(h, bi);
     if (bi == GC_all_nils) {
-        register word hi = (word)h >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE);
+        REGISTER word hi = (word)h >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE);
+
         bi = GC_all_bottom_indices;
         while (bi != 0 && bi -> key < hi) bi = bi -> asc_link;
         j = 0;
index b71ae3e..d44b599 100644 (file)
@@ -176,28 +176,27 @@ typedef struct bi {
   /* Set bottom_indx to point to the bottom index for address p */
 # define GET_BI(p, bottom_indx) \
         do { \
-          register word hi = \
-              (word)(p) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE); \
-          register bottom_index * _bi = GC_top_index[TL_HASH(hi)]; \
+          REGISTER word hi = (word)(p) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE); \
+          REGISTER bottom_index * _bi = GC_top_index[TL_HASH(hi)]; \
           while (_bi -> key != hi && _bi != GC_all_nils) \
               _bi = _bi -> hash_link; \
           (bottom_indx) = _bi; \
         } while (0)
 # define GET_HDR_ADDR(p, ha) \
         do { \
-          register bottom_index * bi; \
+          REGISTER bottom_index * bi; \
           GET_BI(p, bi); \
           (ha) = &HDR_FROM_BI(bi, p); \
         } while (0)
 # define GET_HDR(p, hhdr) \
         do { \
-          register hdr ** _ha; \
+          REGISTER hdr ** _ha; \
           GET_HDR_ADDR(p, _ha); \
           (hhdr) = *_ha; \
         } while (0)
 # define SET_HDR(p, hhdr) \
         do { \
-          register hdr ** _ha; \
+          REGISTER hdr ** _ha; \
           GET_HDR_ADDR(p, _ha); \
           *_ha = (hhdr); \
         } while (0)
index 838facd..42ecda1 100644 (file)
@@ -157,6 +157,15 @@ typedef char * ptr_t;   /* A generic pointer to which we can add        */
   /* The corresponding variable definition must start with GC_INNER.    */
 #endif /* !GC_INNER */
 
+#ifdef __cplusplus
+  /* Register storage specifier is deprecated in C++11. */
+# define REGISTER /* empty */
+#else
+  /* Used only for several local variables in the performance-critical  */
+  /* functions.  Should not be used for new code.                       */
+# define REGISTER register
+#endif
+
 #ifndef HEADERS_H
 # include "gc_hdrs.h"
 #endif
diff --git a/mark.c b/mark.c
index 07a2360..b4f448b 100644 (file)
--- a/mark.c
+++ b/mark.c
@@ -1604,10 +1604,10 @@ GC_API void GC_CALL GC_push_all_eager(void *bottom, void *top)
 {
     word * b = (word *)(((word) bottom + ALIGNMENT-1) & ~(ALIGNMENT-1));
     word * t = (word *)(((word) top) & ~(ALIGNMENT-1));
-    register word *p;
-    register word *lim;
-    register ptr_t greatest_ha = (ptr_t)GC_greatest_plausible_heap_addr;
-    register ptr_t least_ha = (ptr_t)GC_least_plausible_heap_addr;
+    REGISTER word *p;
+    REGISTER word *lim;
+    REGISTER ptr_t greatest_ha = (ptr_t)GC_greatest_plausible_heap_addr;
+    REGISTER ptr_t least_ha = (ptr_t)GC_least_plausible_heap_addr;
 #   define GC_greatest_plausible_heap_addr greatest_ha
 #   define GC_least_plausible_heap_addr least_ha
 
@@ -1617,7 +1617,8 @@ GC_API void GC_CALL GC_push_all_eager(void *bottom, void *top)
       lim = t - 1 /* longword */;
       for (p = b; (word)p <= (word)lim;
            p = (word *)(((ptr_t)p) + ALIGNMENT)) {
-        register word q = *p;
+        REGISTER word q = *p;
+
         GC_PUSH_ONE_STACK(q, p);
       }
 #   undef GC_greatest_plausible_heap_addr
@@ -1649,10 +1650,10 @@ GC_INNER void GC_push_all_stack(ptr_t bottom, ptr_t top)
   {
     word * b = (word *)(((word) bottom + ALIGNMENT-1) & ~(ALIGNMENT-1));
     word * t = (word *)(((word) top) & ~(ALIGNMENT-1));
-    register word *p;
-    register word *lim;
-    register ptr_t greatest_ha = (ptr_t)GC_greatest_plausible_heap_addr;
-    register ptr_t least_ha = (ptr_t)GC_least_plausible_heap_addr;
+    REGISTER word *p;
+    REGISTER word *lim;
+    REGISTER ptr_t greatest_ha = (ptr_t)GC_greatest_plausible_heap_addr;
+    REGISTER ptr_t least_ha = (ptr_t)GC_least_plausible_heap_addr;
 #   define GC_greatest_plausible_heap_addr greatest_ha
 #   define GC_least_plausible_heap_addr least_ha
 
@@ -1662,7 +1663,8 @@ GC_INNER void GC_push_all_stack(ptr_t bottom, ptr_t top)
 
     lim = t - 1;
     for (p = b; (word)p <= (word)lim; p = (word *)((ptr_t)p + ALIGNMENT)) {
-      register word q = *p;
+      REGISTER word q = *p;
+
       GC_PUSH_ONE_HEAP(q, p, GC_mark_stack_top);
     }
 #   undef GC_greatest_plausible_heap_addr