From 5e647efdca82a5c7c4e6e91265a27f9c747ddfdb Mon Sep 17 00:00:00 2001 From: acevest Date: Fri, 6 Sep 2024 19:57:43 +0800 Subject: [PATCH] =?utf8?q?compute=5Fqstr=5Fhash=E7=AE=97=E6=B3=95=E9=97=AE?= =?utf8?q?=E9=A2=98=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- fs/dentry.c | 12 +++++++++--- fs/path.c | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/fs/dentry.c b/fs/dentry.c index ab3d8df..7bf7d71 100644 --- a/fs/dentry.c +++ b/fs/dentry.c @@ -28,9 +28,15 @@ dentry_hash_entry_t dentry_hash_table[DENTRY_HASH_TABLE_SIZE] = { uint32_t mod64(uint64_t x, uint32_t y) { #if 1 // TODO FIXME - uint32_t d = (uint32_t)x; - return d % y; -#else + uint32_t a = (uint32_t)x; + uint32_t b = (x >> 32); + + a %= y; + b %= y; + + return (a + b) % y; +#endif +#if 0 uint32_t mod; asm("div %3;" : "=d"(mod) : "a"((uint32_t)x), "d"((uint32_t)(x >> 32)), "r"(y) : "cc"); diff --git a/fs/path.c b/fs/path.c index d647244..905678f 100644 --- a/fs/path.c +++ b/fs/path.c @@ -104,14 +104,14 @@ void follow_dotdot(namei_t *ni) { uint64_t compute_qstr_hash(qstr_t *q) { q->hash = 0; for (int i = 0; i < q->len; i++) { - uint64_t x = (uint64_t)(q->name[i]); + uint64_t c = (uint64_t)(q->name[i]); + uint64_t x = q->hash; q->hash = (x << 4) | (x >> (8 * sizeof(q->hash) - 4)); + q->hash ^= c; } q->hash += q->hash >> (4 * sizeof(q->hash)); - q->hash &= 0x00000000FFFFFFFF; - return q->hash; } -- 2.44.0