Skip to content
New issue

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

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

Already on GitHub? # to your account

Unify the hash function of cache and map #249

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

qwe661234
Copy link
Collaborator

Based on the below performance analysis, the golden ratio hash is a little bit better than map hash. Therefore, we unify the hash function to golden ratio hash.

Metric map hash golden ratio hash
Dhrystone 2.06 s 2.07 s
Nqueens 4.35 s 4.25 s
Stream 76.7 s 75.59 s

Close: #149

src/emulate.c Outdated Show resolved Hide resolved
@qwe661234 qwe661234 force-pushed the unify_hash branch 4 times, most recently from d7f591f to a5cb316 Compare October 16, 2023 13:09
src/utils.h Outdated Show resolved Hide resolved
@qwe661234 qwe661234 force-pushed the unify_hash branch 2 times, most recently from 98c45e6 to ac7b467 Compare October 16, 2023 15:13
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the following macro:

/* This hashing routine is adapted from Linux kernel.
 * See
 * https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/linux/hash.h                                                                 
 */
#define HASH_FUNC_IMPL(name, size_bits, size)                       \
    FORCE_INLINE uint32_t name(uint32_t val)                        \
    {                                                               \
        /* 0x61C88647 is 32-bit golden ratio */                     \
        return (val * 0x61C88647 >> (32 - size_bits)) & (size - 1); \
    }

It should appear in src/utils.h and be used in C source files. For example,

HASH_FUNC_IMPL(hash, cache_size_bis, cache_size)

Based on the below performance analysis, the golden ratio hash is a
little bit better than map hash. Therefore, we unify the hash function
to golden ratio hash.

|Metric | map hash | golden ratio hash |
|----------+----------+-------------------|
|Dhrystone | 2.06 s| 2.07 s |
|Nqueens | 4.35 s| 4.25 s |
|Stream | 76.7 s| 75.59 s |
@jserv jserv merged commit afcde95 into sysprog21:master Oct 17, 2023
@qwe661234 qwe661234 deleted the unify_hash branch October 17, 2023 05:19
vestata pushed a commit to vestata/rv32emu that referenced this pull request Jan 24, 2025
Unify the hash function of cache and map
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify the hash function of cache and map
2 participants