From: acevest Date: Fri, 6 Sep 2024 11:57:43 +0000 (+0800) Subject: compute_qstr_hash算法问题修正 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=5e647efdca82a5c7c4e6e91265a27f9c747ddfdb;p=kernel.git compute_qstr_hash算法问题修正 --- 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; }