|
From: Andre R. <and...@us...> - 2004-12-17 13:15:12
|
Update of /cvsroot/frontierkernel/Frontier/Common/headers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32621/Common/headers Modified Files: Tag: New_Tables_Experiment-branch lang.h langinternal.h Log Message: First cut at hash-once optimizations: The new hash function is more costly in terms of CPU cycles than the old one. Luckily, we can compensate for this by reducing the number of times the hash value of the node key will be computed. For example, for a UserTalk identifier, the hash value only really needs to be computed once at compile time. Initially, we start this optimization in the low-level hash table functions in langhash.c and then let it percolate upwards. There is a compatibility layer for existing code implemented as pre-processor macros in lang.h. Index: lang.h =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/headers/lang.h,v retrieving revision 1.4.2.10 retrieving revision 1.4.2.11 diff -C2 -d -r1.4.2.10 -r1.4.2.11 *** lang.h 7 Dec 2004 10:33:13 -0000 1.4.2.10 --- lang.h 17 Dec 2004 13:14:57 -0000 1.4.2.11 *************** *** 414,417 **** --- 414,420 ---- + typedef unsigned long tyhashval; + + typedef struct tyhashnode { *************** *** 448,452 **** byte ctlocks: 8; ! unsigned long hashval; /*2004-11-10 aradke: cache of hashfunction(hashkey)*/ byte hashkey []; /*the identifier of this table element, lives in extension of record*/ --- 451,455 ---- byte ctlocks: 8; ! tyhashval hashval; /*2004-11-10 aradke: cache of hashfunction(hashkey)*/ byte hashkey []; /*the identifier of this table element, lives in extension of record*/ *************** *** 455,473 **** ! #define HNoNode ((hdlhashnode) -1) ! #define gethashkey(h,bs) copystring ((**h).hashkey, bs); ! ! typedef hdlhashnode **hdlhashbucketarray; ! typedef unsigned long tyhashval; ! #define ctinitiallogsize 4 /*(2 ** 4) = 16 buckets*/ ! #define nthhashbucket(ht,i) ((*((**(ht)).hbuckets))[i]) ! #define gethashbucketcount(ht) (1 << (**(ht)).logsize) ! #define hashtobucketindex(ht,hash) ((hash) & ((**ht).bucketmask)) --- 458,479 ---- ! #define HNoNode ((hdlhashnode) -1) ! #define gethashkey(h,bs) copystring ((**h).hashkey, bs); ! #define ctinitiallogsize 4 /*(2 ** 4) = 16 buckets*/ ! #define nthhashbucket(ht,i) ((*((**(ht)).hbuckets))[i]) ! #define gethashbucketcount(ht) (1 << (**(ht)).logsize) /*alt.: (**ht).bucketmask + 1*/ ! #define hashtobucketindex(ht,hash) ((hash) & ((**ht).bucketmask)) ! #define gethashbucket(ht,hash) nthhashbucket(ht,hashtobucketindex(ht,hash)) ! ! #define sethashbucket(ht,hash,hn) do { nthhashbucket(ht,hashtobucketindex(ht,hash)) = hn; } while(0) ! ! ! typedef hdlhashnode **hdlhashbucketarray; *************** *** 924,928 **** #endif ! extern boolean newhashtable (hdlhashtable *, boolean); /*langhash.c*/ extern void dirtyhashtable (hdlhashtable); --- 930,936 ---- #endif ! extern tyhashval hashfunction (const bigstring); /*langhash.c*/ ! ! extern boolean newhashtable (hdlhashtable *, boolean); extern void dirtyhashtable (hdlhashtable); *************** *** 958,972 **** //extern hashmerge (hdlhashtable, hdlhashtable); ! extern boolean hashlocate (const bigstring, hdlhashnode *, hdlhashnode *); ! extern boolean hashunlink (const bigstring, hdlhashnode *); ! extern boolean hashdelete (const bigstring, boolean, boolean); ! extern boolean hashtabledelete (hdlhashtable, bigstring); ! extern boolean hashsymbolexists (const bigstring); ! extern boolean hashtablesymbolexists (hdlhashtable, const bigstring); extern void hashsetlocality (tyvaluerecord *, boolean); /*6.2b16 AR: needed to set locality in langaddlocals [langevaluate.c]*/ --- 966,980 ---- //extern hashmerge (hdlhashtable, hdlhashtable); ! extern boolean hashkeylocate (const bigstring, tyhashval, hdlhashnode *, hdlhashnode *); ! extern boolean hashkeyunlink (const bigstring, tyhashval, hdlhashnode *); ! extern boolean hashkeydelete (const bigstring, tyhashval, boolean, boolean); ! extern boolean hashtablekeydelete (hdlhashtable, bigstring, tyhashval); ! extern boolean hashkeyexists (const bigstring, tyhashval); ! extern boolean hashtablekeyexists (hdlhashtable, const bigstring, tyhashval); extern void hashsetlocality (tyvaluerecord *, boolean); /*6.2b16 AR: needed to set locality in langaddlocals [langevaluate.c]*/ *************** *** 980,990 **** extern boolean hashtableassign (hdlhashtable, const bigstring, tyvaluerecord); ! extern boolean hashlookup (const bigstring, tyvaluerecord *, hdlhashnode *); ! extern boolean hashtablelookup (hdlhashtable, const bigstring, tyvaluerecord *, hdlhashnode *); ! extern boolean hashlookupnode (const bigstring, hdlhashnode *); - extern boolean hashtablelookupnode (hdlhashtable, const bigstring, hdlhashnode *); extern boolean hashtablevisit (hdlhashtable, langtablevisitcallback, ptrvoid); --- 988,1020 ---- extern boolean hashtableassign (hdlhashtable, const bigstring, tyvaluerecord); ! extern boolean hashkeylookup (const bigstring, tyhashval, tyvaluerecord *, hdlhashnode *); ! extern boolean hashtablekeylookup (hdlhashtable, const bigstring, tyhashval, tyvaluerecord *, hdlhashnode *); ! extern boolean hashkeylookupnode (const bigstring, tyhashval, hdlhashnode *); ! ! extern boolean hashtablekeylookupnode (hdlhashtable, const bigstring, tyhashval, hdlhashnode *); ! ! ! #define hashlocate(bs, hn1, hn2) hashkeylocate((bs), hashfunction(bs), (hn1), (hn2)) ! ! #define hashunlink(bs, hn) hashkeyunlink((bs), hashfunction(bs), (hn)) ! ! #define hashdelete(bs, fl, fl2) hashkeydelete((bs), hashfunction(bs), (fl), (fl2)) ! ! #define hashtabledelete(ht, bs) hashtablekeydelete((ht), (bs), hashfunction(bs)) ! ! #define hashsymbolexists(bs) hashkeyexists((bs), hashfunction(bs)) ! ! #define hashtablesymbolexists(ht, bs) hashtablekeyexists((ht), (bs), hashfunction(bs)) ! ! #define hashlookup(bs, v, hn) hashkeylookup((bs), hashfunction(bs), (v), (hn)) ! ! #define hashtablelookup(ht, bs, v, hn) hashtablekeylookup((ht), (bs), hashfunction(bs), (v), (hn)) ! ! #define hashlookupnode(bs, hn) hashkeylookupnode((bs), hashfunction(bs), (hn)) ! ! #define hashtablelookupnode(ht, bs, hn) hashtablekeylookupnode((ht), (bs), hashfunction(bs), (hn)) extern boolean hashtablevisit (hdlhashtable, langtablevisitcallback, ptrvoid); Index: langinternal.h =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/headers/langinternal.h,v retrieving revision 1.3.2.2 retrieving revision 1.3.2.3 diff -C2 -d -r1.3.2.2 -r1.3.2.3 *** langinternal.h 24 Nov 2004 20:48:17 -0000 1.3.2.2 --- langinternal.h 17 Dec 2004 13:14:57 -0000 1.3.2.3 *************** *** 416,421 **** extern boolean hashflushcache (long *); /*langhash.h*/ - extern unsigned long hashfunction (const bigstring); /* 2004-11-10 aradke */ - extern boolean hashresolvevalue (hdlhashtable, hdlhashnode); --- 416,419 ---- |