Commits

Remi Meier committed 73c7737

fastpaths for stm_pointer_equal(_prebuilt)

  • Participants
  • Parent commits ba0819e

Comments (0)

Files changed (4)

 static const revision_t GCFLAG_OLD                    = STM_FIRST_GCFLAG << 0;
 static const revision_t GCFLAG_VISITED                = STM_FIRST_GCFLAG << 1;
 static const revision_t GCFLAG_PUBLIC                 = STM_FIRST_GCFLAG << 2;
-static const revision_t GCFLAG_PREBUILT_ORIGINAL      = STM_FIRST_GCFLAG << 3;
+// in stmgc.h:          GCFLAG_PREBUILT_ORIGINAL      = STM_FIRST_GCFLAG << 3;
 // in stmgc.h:          GCFLAG_PUBLIC_TO_PRIVATE      = STM_FIRST_GCFLAG << 4;
 // in stmgc.h:          GCFLAG_WRITE_BARRIER          = STM_FIRST_GCFLAG << 5;
 // in stmgc.h:          GCFLAG_MOVED                  = STM_FIRST_GCFLAG << 6;
     return result;
 }
 
-_Bool stm_pointer_equal(gcptr p1, gcptr p2)
+_Bool stm_direct_pointer_equal(gcptr p1, gcptr p2)
 {
-    if (p1 != NULL && p2 != NULL) {
+    /* commented lines are in the fastpath in stmgc.h */
+    /* if (p1 != NULL && p2 != NULL) { */
         /* resolve h_original, but only if !PREBUILT_ORIGINAL */
         if (p1->h_original && !(p1->h_tid & GCFLAG_PREBUILT_ORIGINAL)) {
             p1 = (gcptr)p1->h_original;
         if (p2->h_original && !(p2->h_tid & GCFLAG_PREBUILT_ORIGINAL)) {
             p2 = (gcptr)p2->h_original;
         }
-    }
+    /* } */
     return (p1 == p2);
 }
 
-_Bool stm_pointer_equal_prebuilt(gcptr p1, gcptr p2)
-{
-    assert(p2 != NULL);
-    assert(p2->h_tid & GCFLAG_PREBUILT_ORIGINAL);
+/* FULLY IMPLEMENTED AS MACRO IN stmgc.h */
+/* _Bool stm_pointer_equal_prebuilt(gcptr p1, gcptr p2) */
+/* { */
+/*     assert(p2 != NULL); */
+/*     assert(p2->h_tid & GCFLAG_PREBUILT_ORIGINAL); */
 
-    if (p1 == p2)
-        return 1;
+/*     if (p1 == p2) */
+/*         return 1; */
 
-    /* the only possible case to still get True is if p2 == p1->h_original */
-    return (p1 != NULL) && (p1->h_original == (revision_t)p2) &&
-        !(p1->h_tid & GCFLAG_PREBUILT_ORIGINAL);
-}
+/*     /\* the only possible case to still get True is if p2 == p1->h_original *\/ */
+/*     return (p1 != NULL) && (p1->h_original == (revision_t)p2) && */
+/*         !(p1->h_tid & GCFLAG_PREBUILT_ORIGINAL); */
+/* } */
 
 /************************************************************/
 

File c4/nursery.c

     return P;
 }
 
-gcptr stm_allocate(size_t size, unsigned long tid)
+inline gcptr stm_allocate(size_t size, unsigned long tid)
 {
     /* XXX inline the fast path */
     assert(tid == (tid & STM_USER_TID_MASK));
 /* push roots around allocating functions! */
 
 /* allocate an object out of the local nursery */
-gcptr stm_allocate(size_t size, unsigned long tid);
+inline gcptr stm_allocate(size_t size, unsigned long tid);
 /* allocate an object that is be immutable. it cannot be changed with
    a stm_write_barrier() or after the next commit */
 gcptr stm_allocate_immutable(size_t size, unsigned long tid);
 revision_t stm_id(gcptr);
 /* returns nonzero if the two object-copy pointers belong to the
 same original object */
+#if 0 // (optimized version below)
 _Bool stm_pointer_equal(gcptr, gcptr);
 _Bool stm_pointer_equal_prebuilt(gcptr, gcptr); /* 2nd arg is known prebuilt */
+#endif
 
 /* to push/pop objects into the local shadowstack */
 #if 0     // (optimized version below)
 gcptr stm_RepeatReadBarrier(gcptr);
 gcptr stm_ImmutReadBarrier(gcptr);
 gcptr stm_RepeatWriteBarrier(gcptr);
+static const revision_t GCFLAG_PREBUILT_ORIGINAL = STM_FIRST_GCFLAG << 3;
 static const revision_t GCFLAG_PUBLIC_TO_PRIVATE = STM_FIRST_GCFLAG << 4;
 static const revision_t GCFLAG_WRITE_BARRIER = STM_FIRST_GCFLAG << 5;
 static const revision_t GCFLAG_MOVED = STM_FIRST_GCFLAG << 6;
 
 #define UNLIKELY(test)  __builtin_expect(test, 0)
 
+_Bool stm_direct_pointer_equal(gcptr, gcptr);
+#define stm_pointer_equal(p1, p2)                    \
+    (((p1) == (p2))                                  \
+    || ((p1) != NULL && (p2) != NULL                 \
+        && stm_direct_pointer_equal(p1, p2)))
+#define stm_pointer_equal_prebuilt(p1, p2)           \
+    (((p1) == (p2))                                  \
+     || (((p1) != NULL) && ((p1)->h_original == (revision_t)(p2)) &&    \
+         !((p1)->h_tid & GCFLAG_PREBUILT_ORIGINAL)))
+
 #ifdef STM_BARRIER_COUNT
 # define STM_BARRIER_NUMBERS  12
 # define STM_BARRIER_NAMES "stm_read_barrier\n"         \