From a59795c9860a9a31e6ccf3555ef0e0ca04a0dd87 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 2 Oct 2007 17:40:00 -0700 Subject: Use the crc64 we already use as the perfect hash function prehash Use the same crc64 that we already use for the symbol table hash as the perfect hash function prehash. We appear to get radically faster convergence this way, and the crc64 is probably *faster*, since the table likely to be resident in memory. --- tokhash.pl | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'tokhash.pl') diff --git a/tokhash.pl b/tokhash.pl index 739172c..2265bd0 100755 --- a/tokhash.pl +++ b/tokhash.pl @@ -170,12 +170,10 @@ if ($output eq 'h') { print "#include \n"; print "#include \"nasm.h\"\n"; + print "#include \"hashtbl.h\"\n"; print "#include \"insns.h\"\n"; print "\n"; - print "#define rot(x,y) (((uint32_t)(x) << (y))+((uint32_t)(x) >> (32-(y))))\n"; - print "\n"; - # These somewhat odd sizes and ordering thereof are due to the # relative ranges of the types; this makes it fit in 16 bytes on # 64-bit machines and 12 bytes on 32-bit machines. @@ -215,20 +213,17 @@ if ($output eq 'h') { } print " };\n"; - print " uint32_t k1 = 0, k2 = 0;\n"; - print " uint8_t c;\n"; + print " uint32_t k1, k2;\n"; + print " uint64_t crc;\n"; # For correct overflow behavior, "ix" should be unsigned of the same # width as the hash arrays. print " uint16_t ix;\n"; print " const struct tokendata *data;\n"; - print " const char *p = token;\n"; print "\n"; - - print " while ((c = *p++) != 0) {\n"; - printf " uint32_t kn1 = rot(k1,%2d)^(rot(k2,%2d) + c);\n", ${$sv}[0], ${$sv}[1]; - printf " uint32_t kn2 = rot(k2,%2d)^(rot(k1,%2d) + c);\n", ${$sv}[2], ${$sv}[3]; - print " k1 = kn1; k2 = kn2;\n"; - print " }\n"; + printf " crc = crc64(UINT64_C(0x%08x%08x), token);\n", + $$sv[0], $$sv[1]; + print " k1 = (uint32_t)crc;\n"; + print " k2 = (uint32_t)(crc >> 32);\n"; print "\n"; printf " ix = hash1[k1 & 0x%x] + hash2[k2 & 0x%x];\n", $n-1, $n-1; printf " if (ix >= %d)\n", scalar(@tokendata); -- cgit v1.2.3