LMMP 4.3.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
xxhash.c 文件参考
#include "lmmp/secret.h"
xxhash.c 的引用(Include)关系图:

浏览该文件的源代码.

宏定义

#define PRIME64_1   0x9E3779B185EBCA87ULL
 Copyright (C) 2026 HJimmyK (Jericho Knox)
#define PRIME64_2   0xC2B2AE3D27D4EB4FULL
#define PRIME64_3   0x165667B19E3779F9ULL
#define PRIME64_4   0x85EBCA77C2B2AE63ULL
#define PRIME64_5   0x27D4EB2F165667C5ULL

函数

uint64_t lmmp_xxhash_ (mp_srcptr in, mp_size_t inlen, srckey64_t key)
 xxhash 函数(非标准处理任意字节流的 xxhash)
static uint64_t rotl64 (uint64_t x, int b)

宏定义说明

◆ PRIME64_1

#define PRIME64_1   0x9E3779B185EBCA87ULL

Copyright (C) 2026 HJimmyK (Jericho Knox)

This file is part of LMMP.

LMMP is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see https://www.gnu.org/licenses/.

SPDX-License-Identifier: LGPL-3.0-or-later

在文件 xxhash.c 第 25 行定义.

被这些函数引用 lmmp_xxhash_().

◆ PRIME64_2

#define PRIME64_2   0xC2B2AE3D27D4EB4FULL

在文件 xxhash.c 第 26 行定义.

被这些函数引用 lmmp_xxhash_().

◆ PRIME64_3

#define PRIME64_3   0x165667B19E3779F9ULL

在文件 xxhash.c 第 27 行定义.

被这些函数引用 lmmp_xxhash_().

◆ PRIME64_4

#define PRIME64_4   0x85EBCA77C2B2AE63ULL

在文件 xxhash.c 第 28 行定义.

被这些函数引用 lmmp_xxhash_().

◆ PRIME64_5

#define PRIME64_5   0x27D4EB2F165667C5ULL

在文件 xxhash.c 第 29 行定义.

被这些函数引用 lmmp_xxhash_().

函数说明

◆ lmmp_xxhash_()

uint64_t lmmp_xxhash_ ( mp_srcptr in,
mp_size_t inlen,
srckey64_t key )

xxhash 函数(非标准处理任意字节流的 xxhash)

参数
in输入数据,可以为 NULL
inlen输入数据长度
key64-bit 秘钥,可以为 NULL
警告
若 key 为 NULL,则使用全零秘钥
返回
64-bit hash 值

在文件 xxhash.c 第 36 行定义.

36 {
37 uint64_t seed = key == NULL ? 0 : key[0];
38 if (in == NULL || inlen == 0) {
39 seed += PRIME64_5;
40 seed += 0; // len = 0
41 seed ^= seed >> 33;
42 seed *= PRIME64_2;
43 seed ^= seed >> 29;
44 seed *= PRIME64_3;
45 seed ^= seed >> 32;
46 return seed;
47 }
48
49 const uint64_t* p = in;
50 const uint64_t* const end = in + inlen;
51 uint64_t h64;
52
53 if (inlen >= 4) {
54 const uint64_t* const limit = end - 4;
55 uint64_t v1 = seed + PRIME64_1 + PRIME64_2;
56 uint64_t v2 = seed + PRIME64_2;
57 uint64_t v3 = seed + 0;
58 uint64_t v4 = seed - PRIME64_1;
59
60 do {
61 v1 += *p * PRIME64_2;
62 v1 = rotl64(v1, 31);
63 v1 *= PRIME64_1;
64 p++;
65
66 v2 += *p * PRIME64_2;
67 v2 = rotl64(v2, 31);
68 v2 *= PRIME64_1;
69 p++;
70
71 v3 += *p * PRIME64_2;
72 v3 = rotl64(v3, 31);
73 v3 *= PRIME64_1;
74 p++;
75
76 v4 += *p * PRIME64_2;
77 v4 = rotl64(v4, 31);
78 v4 *= PRIME64_1;
79 p++;
80 } while (p <= limit);
81
82 h64 = rotl64(v1, 1) + rotl64(v2, 7) + rotl64(v3, 12) + rotl64(v4, 18);
83
84 v1 *= PRIME64_2;
85 v1 = rotl64(v1, 31);
86 v1 *= PRIME64_1;
87 h64 ^= v1;
88 h64 = h64 * PRIME64_1 + PRIME64_4;
89
90 v2 *= PRIME64_2;
91 v2 = rotl64(v2, 31);
92 v2 *= PRIME64_1;
93 h64 ^= v2;
94 h64 = h64 * PRIME64_1 + PRIME64_4;
95
96 v3 *= PRIME64_2;
97 v3 = rotl64(v3, 31);
98 v3 *= PRIME64_1;
99 h64 ^= v3;
100 h64 = h64 * PRIME64_1 + PRIME64_4;
101
102 v4 *= PRIME64_2;
103 v4 = rotl64(v4, 31);
104 v4 *= PRIME64_1;
105 h64 ^= v4;
106 h64 = h64 * PRIME64_1 + PRIME64_4;
107 } else {
108 h64 = seed + PRIME64_5;
109 }
110
111 h64 += (uint64_t)(inlen * sizeof(mp_limb_t));
112
113 while (p < end) {
114 uint64_t k1 = *p;
115 k1 *= PRIME64_2;
116 k1 = rotl64(k1, 31);
117 k1 *= PRIME64_1;
118 h64 ^= k1;
119 h64 = rotl64(h64, 27) * PRIME64_1 + PRIME64_4;
120 p++;
121 }
122
123 h64 ^= h64 >> 33;
124 h64 *= PRIME64_2;
125 h64 ^= h64 >> 29;
126 h64 *= PRIME64_3;
127 h64 ^= h64 >> 32;
128
129 return h64;
130}
uint64_t mp_limb_t
定义 lmmp.h:92
#define v1
#define v2
#define v3
static uint64_t rotl64(uint64_t x, int b)
Copyright (C) 2026 HJimmyK (Jericho Knox)
#define PRIME64_4
#define PRIME64_1
Copyright (C) 2026 HJimmyK (Jericho Knox)
#define PRIME64_5
#define PRIME64_3
#define PRIME64_2

引用了 lmmp_xxhash_(), PRIME64_1, PRIME64_2, PRIME64_3, PRIME64_4, PRIME64_5, rotl64(), v1, v2 , 以及 v3.

被这些函数引用 lmmp_xxhash_() , 以及 TEST_CASE().

函数调用图:
这是这个函数的调用关系图:

◆ rotl64()

uint64_t rotl64 ( uint64_t x,
int b )
inlinestatic

在文件 xxhash.c 第 31 行定义.

31 {
32 b &= 63;
33 return (x << b) | (x >> (64 - b));
34}

引用了 rotl64().

函数调用图: