[PATCH] dix: Simpler and faster XID hash

Adam Jackson ajax at redhat.com
Wed Jan 19 16:58:01 PST 2011


The xor chain doesn't seem to have a huge effect on hash distribution.
The new version is so simple that gcc inlines it completely into the
callers, shrinks the binary size by half a kilobyte or so, and looks
marginally faster in synethetic tests.

$ x11perf -falseprecision -pointer

Before:
1000000 trep @   0.0412 msec ( 24275.0/sec): QueryPointer
After:
1000000 trep @   0.0374 msec ( 26737.0/sec): QueryPointer

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 dix/resource.c |   18 +-----------------
 1 files changed, 1 insertions(+), 17 deletions(-)

diff --git a/dix/resource.c b/dix/resource.c
index 6bd2403..52519c9 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -335,23 +335,7 @@ InitClientResources(ClientPtr client)
 static int
 Hash(int client, XID id)
 {
-    id &= RESOURCE_ID_MASK;
-    switch (clientTable[client].hashsize)
-    {
-	case 6:
-	    return ((int)(0x03F & (id ^ (id>>6) ^ (id>>12))));
-	case 7:
-	    return ((int)(0x07F & (id ^ (id>>7) ^ (id>>13))));
-	case 8:
-	    return ((int)(0x0FF & (id ^ (id>>8) ^ (id>>16))));
-	case 9:
-	    return ((int)(0x1FF & (id ^ (id>>9))));
-	case 10:
-	    return ((int)(0x3FF & (id ^ (id>>10))));
-	case 11:
-	    return ((int)(0x7FF & (id ^ (id>>11))));
-    }
-    return -1;
+    return id & (clientTable[client].hashsize - 1);
 }
 
 static XID
-- 
1.7.3.4



More information about the xorg-devel mailing list