From f30571ed6d9b834722d37fa04f23aa00f6064233 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Fri, 29 May 1998 20:22:44 +0000 Subject: [PATCH] made hashing routine portable --- src/libCom/fdManager.cc | 55 +++++++++++++--------------------- src/libCom/fdmgr/fdManager.cpp | 55 +++++++++++++--------------------- 2 files changed, 40 insertions(+), 70 deletions(-) diff --git a/src/libCom/fdManager.cc b/src/libCom/fdManager.cc index 84e41679b..a2f300011 100644 --- a/src/libCom/fdManager.cc +++ b/src/libCom/fdManager.cc @@ -4,6 +4,9 @@ // // // $Log$ +// Revision 1.12 1998/02/05 21:12:09 jhill +// removed questionable inline +// // Revision 1.11 1997/08/05 00:37:00 jhill // removed warnings // @@ -277,45 +280,27 @@ void fdRegId::show(unsigned level) const // // fdRegId::resourceHash() // -resTableIndex fdRegId::resourceHash (unsigned nBitsId) const +resTableIndex fdRegId::resourceHash (unsigned) const { - // - // 0.5 uS pentium 200 - // - //unsigned src = (unsigned) this->fd; - //resTableIndex hashid; - // - //hashid = src; - //while (src = src >> nBitsId) { - // hashid = hashid ^ src; - //} - //hashid = hashid ^ this->type; + resTableIndex hashid = (unsigned) this->fd; // - // 0.32 uS Pent 200 MHz - // - // faster because it does not - // check for the hash id size - // (assumes worst case hash id - // of 1 bit) + // This assumes worst case hash table index width of 1 bit. + // We will iterate this loop 5 times on a 32 bit architecture. + // + // A good optimizer will unroll this loop? + // Experiments using the microsoft compiler show that this isnt + // slower than switching on the architecture size and urolling the + // loop explicitly (that solution has resulted in portability + // problems in the past). + // + for (unsigned i=(CHAR_BIT*sizeof(unsigned))/2u; i>0u; i >>= 1u) { + hashid ^= (hashid>>i); + } + + // + // evenly distribute based on the type of interest also // - resTableIndex hashid = (unsigned) this->fd; -#if UINT_MAX >> 128u - hashid ^= (hashid>>128u); -#endif -#if UINT_MAX >> 64u - hashid ^= (hashid>>64u); -#endif -#if UINT_MAX >> 32u - hashid ^= (hashid>>32u); -#endif -#if UINTMAX >> 16u - hashid ^= (hashid>>16u); -#endif - hashid ^= (hashid>>8u); - hashid ^= (hashid>>4u); - hashid ^= (hashid>>2u); - hashid ^= (hashid>>1u); hashid ^= this->type; // diff --git a/src/libCom/fdmgr/fdManager.cpp b/src/libCom/fdmgr/fdManager.cpp index 84e41679b..a2f300011 100644 --- a/src/libCom/fdmgr/fdManager.cpp +++ b/src/libCom/fdmgr/fdManager.cpp @@ -4,6 +4,9 @@ // // // $Log$ +// Revision 1.12 1998/02/05 21:12:09 jhill +// removed questionable inline +// // Revision 1.11 1997/08/05 00:37:00 jhill // removed warnings // @@ -277,45 +280,27 @@ void fdRegId::show(unsigned level) const // // fdRegId::resourceHash() // -resTableIndex fdRegId::resourceHash (unsigned nBitsId) const +resTableIndex fdRegId::resourceHash (unsigned) const { - // - // 0.5 uS pentium 200 - // - //unsigned src = (unsigned) this->fd; - //resTableIndex hashid; - // - //hashid = src; - //while (src = src >> nBitsId) { - // hashid = hashid ^ src; - //} - //hashid = hashid ^ this->type; + resTableIndex hashid = (unsigned) this->fd; // - // 0.32 uS Pent 200 MHz - // - // faster because it does not - // check for the hash id size - // (assumes worst case hash id - // of 1 bit) + // This assumes worst case hash table index width of 1 bit. + // We will iterate this loop 5 times on a 32 bit architecture. + // + // A good optimizer will unroll this loop? + // Experiments using the microsoft compiler show that this isnt + // slower than switching on the architecture size and urolling the + // loop explicitly (that solution has resulted in portability + // problems in the past). + // + for (unsigned i=(CHAR_BIT*sizeof(unsigned))/2u; i>0u; i >>= 1u) { + hashid ^= (hashid>>i); + } + + // + // evenly distribute based on the type of interest also // - resTableIndex hashid = (unsigned) this->fd; -#if UINT_MAX >> 128u - hashid ^= (hashid>>128u); -#endif -#if UINT_MAX >> 64u - hashid ^= (hashid>>64u); -#endif -#if UINT_MAX >> 32u - hashid ^= (hashid>>32u); -#endif -#if UINTMAX >> 16u - hashid ^= (hashid>>16u); -#endif - hashid ^= (hashid>>8u); - hashid ^= (hashid>>4u); - hashid ^= (hashid>>2u); - hashid ^= (hashid>>1u); hashid ^= this->type; //