Ticket #725: add-branch-prediction-annotations.patch

File add-branch-prediction-annotations.patch, 3.0 KB (added by Infinoid, 13 years ago)
  • include/parrot/compiler.h

    [core] Add branch prediction annotations to Parrot.
    
    From: Mark Glines <mark@glines.org>
    
    
    ---
    
     include/parrot/compiler.h   |    8 ++++++++
     include/parrot/exceptions.h |    4 ++--
     src/gc/mark_sweep.c         |    2 +-
     src/hash.c                  |    6 +++---
     4 files changed, 14 insertions(+), 6 deletions(-)
    
    
    diff --git a/include/parrot/compiler.h b/include/parrot/compiler.h
    index 7657801..051718d 100644
    a b  
    2828#  define PARROT_HAS_SAL 0 
    2929#endif 
    3030 
     31#ifdef __GNUC__ 
     32# define likely(x)      __builtin_expect(!!(x), 1) 
     33# define unlikely(x)    __builtin_expect(!!(x), 0) 
     34#else 
     35# define likely(x)      (x) 
     36# define unlikely(x)    (x) 
     37#endif 
     38 
    3139#ifdef HASATTRIBUTE_NEVER_WORKS 
    3240 #  error This attribute can never succeed.  Something has mis-sniffed your configuration. 
    3341#endif 
  • include/parrot/exceptions.h

    diff --git a/include/parrot/exceptions.h b/include/parrot/exceptions.h
    index 1c0a3a2..14def86 100644
    a b  
    280280#  define PARROT_ASSERT_ARG(x) (0) 
    281281#  define ASSERT_ARGS(a) 
    282282#else 
    283 #  define PARROT_ASSERT(x) (x) ? ((void)0) : Parrot_confess(#x, __FILE__, __LINE__) 
    284 #  define PARROT_ASSERT_ARG(x) ((x) ? (0) : (Parrot_confess(#x, __FILE__, __LINE__), 0)) 
     283#  define PARROT_ASSERT(x) likely(x) ? ((void)0) : Parrot_confess(#x, __FILE__, __LINE__) 
     284#  define PARROT_ASSERT_ARG(x) (likely(x) ? (0) : (Parrot_confess(#x, __FILE__, __LINE__), 0)) 
    285285 
    286286#  ifdef __GNUC__ 
    287287#    define ASSERT_ARGS(a) ASSERT_ARGS_ ## a ; 
  • src/gc/mark_sweep.c

    diff --git a/src/gc/mark_sweep.c b/src/gc/mark_sweep.c
    index 8c2b680..d482b6a 100644
    a b  
    771771    Arenas * const arena_base = interp->arena_base; 
    772772 
    773773    /* TODO collect objects with finalizers */ 
    774     if (PObj_needs_early_gc_TEST(p)) 
     774    if (unlikely(PObj_needs_early_gc_TEST(p))) 
    775775        --arena_base->num_early_gc_PMCs; 
    776776 
    777777    if (PObj_active_destroy_TEST(p)) 
  • src/hash.c

    diff --git a/src/hash.c b/src/hash.c
    index 6d5dc0d..0bd7054 100644
    a b  
    11921192{ 
    11931193    ASSERT_ARGS(parrot_hash_get_bucket) 
    11941194 
    1195     if (hash->entries <= 0) 
     1195    if (unlikely(hash->entries <= 0)) 
    11961196        return NULL; 
    11971197 
    11981198    /* a very fast search for very small hashes */ 
     
    12141214        const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed); 
    12151215        HashBucket   *bucket  = hash->bi[hashval & hash->mask]; 
    12161216 
    1217         while (bucket) { 
     1217        while (likely(bucket)) { 
    12181218            /* key equality is always a match, so it's worth checking */ 
    1219             if (bucket->key == key 
     1219            if (unlikely(bucket->key == key) 
    12201220 
    12211221            /* ... but the slower comparison is more accurate */ 
    12221222            || ((hash->compare)(interp, key, bucket->key) == 0))