diff options
author | H. Peter Anvin <hpa@zytor.com> | 2007-10-02 17:40:00 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2007-10-02 17:40:00 -0700 |
commit | a59795c9860a9a31e6ccf3555ef0e0ca04a0dd87 (patch) | |
tree | 608679c4a8021e3e2e28644d1e3059a5e0091e4c /tokhash.pl | |
parent | 17394a7d8e3240c6dafddab7725d953904208e5a (diff) | |
download | nasm-a59795c9860a9a31e6ccf3555ef0e0ca04a0dd87.tar.gz nasm-a59795c9860a9a31e6ccf3555ef0e0ca04a0dd87.tar.bz2 nasm-a59795c9860a9a31e6ccf3555ef0e0ca04a0dd87.zip |
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.
Diffstat (limited to 'tokhash.pl')
-rwxr-xr-x | tokhash.pl | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -170,12 +170,10 @@ if ($output eq 'h') { print "#include <string.h>\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); |