[uClibc-cvs] svn commit: trunk/uClibc/ldso/ldso

jocke at uclibc.org jocke at uclibc.org
Fri Apr 1 17:11:56 UTC 2005


Author: jocke
Date: 2005-04-01 10:11:55 -0700 (Fri, 01 Apr 2005)
New Revision: 10068

Log:
Optimize _dl_elf_hash(), both smaller and faster. Mostly
taken from glibc.


Modified:
   trunk/uClibc/ldso/ldso/dl-hash.c


Changeset:
Modified: trunk/uClibc/ldso/ldso/dl-hash.c
===================================================================
--- trunk/uClibc/ldso/ldso/dl-hash.c	2005-03-31 22:45:22 UTC (rev 10067)
+++ trunk/uClibc/ldso/ldso/dl-hash.c	2005-04-01 17:11:55 UTC (rev 10068)
@@ -59,14 +59,20 @@
  * it to decode the hash table.  */
 static inline unsigned long _dl_elf_hash(const unsigned char *name)
 {
-	unsigned long hash = 0;
+	unsigned long hash=0;
 	unsigned long tmp;
 
 	while (*name) {
 		hash = (hash << 4) + *name++;
-		if ((tmp = hash & 0xf0000000))
-			hash ^= tmp >> 24;
-		hash &= ~tmp;
+		tmp = hash & 0xf0000000;
+		/* The algorithm specified in the ELF ABI is as follows:
+		   if (tmp != 0)
+		       hash ^= tmp >> 24;
+		   hash &= ~tmp;
+		   But the following is equivalent and a lot
+		   faster, especially on modern processors. */
+		hash ^= tmp;
+		hash ^= tmp >> 24;
 	}
 	return hash;
 }




More information about the uClibc-cvs mailing list