Bug 331043 - Improve hash performance using _rotr intrinsic (js/src hunk), patch by Michael Moy <mmoy@yahoo.com> with updates by me and r=wtc, r=brendan, a=brendan

This commit is contained in:
crowder@fiverocks.com 2008-01-29 18:36:33 -08:00
parent 1e100ea8d9
commit 8770eff094
7 changed files with 32 additions and 12 deletions

View File

@ -227,6 +227,24 @@ extern JSUword js_FloorLog2wImpl(JSUword n);
#endif
/*
* Macros for rotate left. There is no rotate operation in the C Language so
* the construct (a << 4) | (a >> 28) is used instead. Most compilers convert
* this to a rotate instruction but some versions of MSVC don't without a
* little help. To get MSVC to generate a rotate instruction, we have to use
* the _rotl intrinsic and use a pragma to make _rotl inline.
*
* MSVC in VS2005 will do an inline rotate instruction on the above construct.
*/
#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \
defined(_M_X64))
#include <stdlib.h>
#pragma intrinsic(_rotl)
#define JS_ROTATE_LEFT32(a, bits) _rotl(a, bits)
#else
#define JS_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits))))
#endif
JS_END_EXTERN_C
#endif /* jsbit_h___ */

View File

@ -103,7 +103,7 @@ JS_DHashStringKey(JSDHashTable *table, const void *key)
h = 0;
for (s = (const unsigned char *) key; *s != '\0'; s++)
h = (h >> (JS_DHASH_BITS - 4)) ^ (h << 4) ^ *s;
h = JS_ROTATE_LEFT32(h, 4) ^ *s;
return h;
}

View File

@ -465,7 +465,7 @@ JS_HashString(const void *key)
h = 0;
for (s = (const unsigned char *)key; *s; s++)
h = (h >> (JS_HASH_BITS - 4)) ^ (h << 4) ^ *s;
h = JS_ROTATE_LEFT32(h, 4) ^ *s;
return h;
}

View File

@ -403,18 +403,18 @@ js_HashScopeProperty(JSDHashTable *table, const void *key)
hash = 0;
gsop = sprop->getter;
if (gsop)
hash = (hash >> (JS_DHASH_BITS - 4)) ^ (hash << 4) ^ (jsword)gsop;
hash = JS_ROTATE_LEFT32(hash, 4) ^ (jsword)gsop;
gsop = sprop->setter;
if (gsop)
hash = (hash >> (JS_DHASH_BITS - 4)) ^ (hash << 4) ^ (jsword)gsop;
hash = JS_ROTATE_LEFT32(hash, 4) ^ (jsword)gsop;
hash = (hash >> (JS_DHASH_BITS - 4)) ^ (hash << 4)
hash = JS_ROTATE_LEFT32(hash, 4)
^ (sprop->flags & ~SPROP_FLAGS_NOT_MATCHED);
hash = (hash >> (JS_DHASH_BITS - 4)) ^ (hash << 4) ^ sprop->attrs;
hash = (hash >> (JS_DHASH_BITS - 4)) ^ (hash << 4) ^ sprop->shortid;
hash = (hash >> (JS_DHASH_BITS - 4)) ^ (hash << 4) ^ sprop->slot;
hash = (hash >> (JS_DHASH_BITS - 4)) ^ (hash << 4) ^ sprop->id;
hash = JS_ROTATE_LEFT32(hash, 4) ^ sprop->attrs;
hash = JS_ROTATE_LEFT32(hash, 4) ^ sprop->shortid;
hash = JS_ROTATE_LEFT32(hash, 4) ^ sprop->slot;
hash = JS_ROTATE_LEFT32(hash, 4) ^ sprop->id;
return hash;
}

View File

@ -69,6 +69,7 @@
#include "jsopcode.h"
#include "jsregexp.h"
#include "jsstr.h"
#include "jsbit.h"
#define JSSTRDEP_RECURSION_LIMIT 100
@ -2768,7 +2769,7 @@ js_HashString(JSString *str)
JSSTRING_CHARS_AND_LENGTH(str, s, n);
for (h = 0; n; s++, n--)
h = (h >> (JS_HASH_BITS - 4)) ^ (h << 4) ^ *s;
h = JS_ROTATE_LEFT32(h, 4) ^ *s;
return h;
}

View File

@ -471,7 +471,7 @@ JSJ_HashString(const void *key)
h = 0;
for (s = key; *s; s++)
h = (h >> 28) ^ (h << 4) ^ *s;
h = JS_ROTATE_LEFT32(h, 4) ^ *s;
return h;
}

View File

@ -41,6 +41,7 @@
/* Private maps (hashtables). */
#include "xpcprivate.h"
#include "jsbit.h"
/***************************************************************************/
// static shared...
@ -504,7 +505,7 @@ XPCNativeScriptableSharedMap::Entry::Hash(JSDHashTable *table, const void *key)
h = (JSDHashNumber) obj->GetFlags();
for (s = (const unsigned char*) obj->GetJSClass()->name; *s != '\0'; s++)
h = (h >> (JS_DHASH_BITS - 4)) ^ (h << 4) ^ *s;
h = JS_ROTATE_LEFT32(h, 4) ^ *s;
return h;
}