Skip to content

Sixteen bit hash for strings #1170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion jerry-core/ecma/base/ecma-helpers-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,6 @@ ecma_is_string_magic (const ecma_string_t *string_p, /**< ecma-string */
*/
lit_string_hash_t
ecma_string_hash (const ecma_string_t *string_p) /**< ecma-string to calculate hash for */

{
return (string_p->hash);
} /* ecma_string_hash */
Expand Down
12 changes: 6 additions & 6 deletions jerry-core/ecma/base/ecma-property-hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */

uint8_t shift_counter = 0;

if (max_property_count <= (1u << LIT_STRING_HASH_BITS))
if (max_property_count <= LIT_STRING_HASH_LIMIT)
{
hashmap_p->header.types[1].type_and_flags = 0;
}
else
{
while (max_property_count > (1u << LIT_STRING_HASH_BITS))
while (max_property_count > LIT_STRING_HASH_LIMIT)
{
shift_counter++;
max_property_count >>= 1;
Expand Down Expand Up @@ -162,7 +162,7 @@ ecma_property_hashmap_create (ecma_object_t *object_p) /**< object */
uint32_t entry_index = name_p->hash;
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];

if (mask < (1u << LIT_STRING_HASH_BITS))
if (mask < LIT_STRING_HASH_LIMIT)
{
entry_index &= mask;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ ecma_property_hashmap_insert (ecma_object_t *object_p, /**< object */
uint32_t step = ecma_property_hashmap_steps[entry_index & (ECMA_PROPERTY_HASHMAP_NUMBER_OF_STEPS - 1)];
uint32_t mask = hashmap_p->max_property_count - 1;

if (mask < (1u << LIT_STRING_HASH_BITS))
if (mask < LIT_STRING_HASH_LIMIT)
{
entry_index &= mask;
}
Expand Down Expand Up @@ -336,7 +336,7 @@ ecma_property_hashmap_delete (ecma_object_t *object_p, /**< object */
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);

if (mask < (1u << LIT_STRING_HASH_BITS))
if (mask < LIT_STRING_HASH_LIMIT)
{
entry_index &= mask;
}
Expand Down Expand Up @@ -446,7 +446,7 @@ ecma_property_hashmap_find (ecma_property_hashmap_t *hashmap_p, /**< hashmap */
jmem_cpointer_t *pair_list_p = (jmem_cpointer_t *) (hashmap_p + 1);
uint8_t *bits_p = (uint8_t *) (pair_list_p + hashmap_p->max_property_count);

if (mask < (1u << LIT_STRING_HASH_BITS))
if (mask < LIT_STRING_HASH_LIMIT)
{
entry_index &= mask;
}
Expand Down
20 changes: 13 additions & 7 deletions jerry-core/ecma/operations/ecma-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
* @{
*/

/**
* Hash bitmap size for ecma objects
*/
#define ECMA_OBJECT_HASH_BITMAP_SIZE 256

/**
* Assert that specified object type value is valid
*
Expand All @@ -48,6 +53,7 @@
#else /* JERRY_NDEBUG */
#define JERRY_ASSERT_OBJECT_TYPE_IS_VALID(type)
#endif /* !JERRY_NDEBUG */

/**
* [[Get]] ecma object's operation
*
Expand Down Expand Up @@ -483,7 +489,7 @@ ecma_op_object_is_prototype_of (ecma_object_t *base_p, /**< base object */
*
* Order of names in the collection:
* - integer indices in ascending order
* - other indices in creation order (for built-ins - in the order the properties are listed in specification).
* - other indices in creation order (for built-ins: the order of the properties are listed in specification).
*
* Note:
* Implementation of the routine assumes that new properties are appended to beginning of corresponding object's
Expand All @@ -510,7 +516,7 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
const bool obj_is_builtin = ecma_get_object_is_builtin (obj_p);

const size_t bitmap_row_size = sizeof (uint32_t) * JERRY_BITSINBYTE;
uint32_t names_hashes_bitmap[(1u << LIT_STRING_HASH_BITS) / bitmap_row_size];
uint32_t names_hashes_bitmap[ECMA_OBJECT_HASH_BITMAP_SIZE / bitmap_row_size];

memset (names_hashes_bitmap, 0, sizeof (names_hashes_bitmap));

Expand Down Expand Up @@ -571,14 +577,14 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
ecma_collection_iterator_t iter;
ecma_collection_iterator_init (&iter, prop_names_p);

uint32_t own_names_hashes_bitmap[(1u << LIT_STRING_HASH_BITS) / bitmap_row_size];
uint32_t own_names_hashes_bitmap[ECMA_OBJECT_HASH_BITMAP_SIZE / bitmap_row_size];
memset (own_names_hashes_bitmap, 0, sizeof (own_names_hashes_bitmap));

while (ecma_collection_iterator_next (&iter))
{
ecma_string_t *name_p = ecma_get_string_from_value (*iter.current_value_p);

lit_string_hash_t hash = name_p->hash;
uint8_t hash = (uint8_t) name_p->hash;
uint32_t bitmap_row = (uint32_t) (hash / bitmap_row_size);
uint32_t bitmap_column = (uint32_t) (hash % bitmap_row_size);

Expand Down Expand Up @@ -613,7 +619,7 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */

if (!(is_enumerable_only && !ecma_is_property_enumerable (property_p)))
{
lit_string_hash_t hash = name_p->hash;
uint8_t hash = (uint8_t) name_p->hash;
uint32_t bitmap_row = (uint32_t) (hash / bitmap_row_size);
uint32_t bitmap_column = (uint32_t) (hash % bitmap_row_size);

Expand Down Expand Up @@ -652,7 +658,7 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */
ecma_make_string_value (name_p),
true);

lit_string_hash_t hash = name_p->hash;
uint8_t hash = (uint8_t) name_p->hash;
uint32_t bitmap_row = (uint32_t) (hash / bitmap_row_size);
uint32_t bitmap_column = (uint32_t) (hash % bitmap_row_size);

Expand Down Expand Up @@ -771,7 +777,7 @@ ecma_op_object_get_property_names (ecma_object_t *obj_p, /**< object */

ecma_string_t *name_p = names_p[i];

lit_string_hash_t hash = name_p->hash;
uint8_t hash = (uint8_t) name_p->hash;
uint32_t bitmap_row = (uint32_t) (hash / bitmap_row_size);
uint32_t bitmap_column = (uint32_t) (hash % bitmap_row_size);

Expand Down
11 changes: 8 additions & 3 deletions jerry-core/lit/lit-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ typedef uint32_t lit_code_point_t;
/**
* ECMA string hash
*/
typedef uint8_t lit_string_hash_t;
typedef uint16_t lit_string_hash_t;

/**
* ECMA string hash value length, in bits
* Maximum value of ECMA string hash + 1
*
* Note:
* On ARM, this constant can be encoded as an immediate value
* while 0xffffu cannot be. Hence using this constant reduces
* binary size and improves performance.
*/
#define LIT_STRING_HASH_BITS (sizeof (lit_string_hash_t) * JERRY_BITSINBYTE)
#define LIT_STRING_HASH_LIMIT 0x10000u

#endif /* !LIT_GLOBALS_H */