1 /*
2 * List hash algorithms to benchmark
3 * Part of xxHash project
4 * Copyright (C) 2019-2020 Yann Collet
5 *
6 * GPL v2 License
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * You can contact the author at:
23 * - xxHash homepage: https://www.xxhash.com
24 * - xxHash source repository: https://github.com/Cyan4973/xxHash
25 */
26
27
28 /* === Dependencies === */
29
30 #include <stddef.h> /* size_t */
31
32
33 /* ==================================================
34 * Non-portable hash algorithms
35 * =============================================== */
36
37
38 #ifdef HARDWARE_SUPPORT
39
40 /*
41 * List any hash algorithms that depend on specific hardware support,
42 * including for example:
43 * - Hardware crc32c
44 * - Hardware AES support
45 * - Carryless Multipliers (clmul)
46 * - AVX2
47 */
48
49 #endif
50
51
52
53 /* ==================================================
54 * List of hashes
55 * ==================================================
56 * Each hash must be wrapped in a thin redirector conformant with the BMK_benchfn_t.
57 * BMK_benchfn_t is generic, not specifically designed for hashes.
58 * For hashes, the following parameters are expected to be useless:
59 * dst, dstCapacity, customPayload.
60 *
61 * The result of each hash is assumed to be provided as function return value.
62 * This condition is important for latency measurements.
63 */
64
65 /* === xxHash === */
66 #define XXH_INLINE_ALL
67 #include "xxhash.h"
68
XXH32_wrapper(const void * src,size_t srcSize,void * dst,size_t dstCapacity,void * customPayload)69 size_t XXH32_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
70 {
71 (void)dst; (void)dstCapacity; (void)customPayload;
72 return (size_t) XXH32(src, srcSize, 0);
73 }
74
75
XXH64_wrapper(const void * src,size_t srcSize,void * dst,size_t dstCapacity,void * customPayload)76 size_t XXH64_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
77 {
78 (void)dst; (void)dstCapacity; (void)customPayload;
79 return (size_t) XXH64(src, srcSize, 0);
80 }
81
82
xxh3_wrapper(const void * src,size_t srcSize,void * dst,size_t dstCapacity,void * customPayload)83 size_t xxh3_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
84 {
85 (void)dst; (void)dstCapacity; (void)customPayload;
86 return (size_t) XXH3_64bits(src, srcSize);
87 }
88
89
XXH128_wrapper(const void * src,size_t srcSize,void * dst,size_t dstCapacity,void * customPayload)90 size_t XXH128_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
91 {
92 (void)dst; (void)dstCapacity; (void)customPayload;
93 return (size_t) XXH3_128bits(src, srcSize).low64;
94 }
95
96
97
98 /* ==================================================
99 * Table of hashes
100 * =============================================== */
101
102 #include "bhDisplay.h" /* Bench_Entry */
103
104 #ifndef HARDWARE_SUPPORT
105 # define NB_HASHES 4
106 #else
107 # define NB_HASHES 4
108 #endif
109
110 Bench_Entry const hashCandidates[NB_HASHES] = {
111 { "xxh3" , xxh3_wrapper },
112 { "XXH32" , XXH32_wrapper },
113 { "XXH64" , XXH64_wrapper },
114 { "XXH128", XXH128_wrapper },
115 #ifdef HARDWARE_SUPPORT
116 /* list here codecs which require specific hardware support, such SSE4.1, PCLMUL, AVX2, etc. */
117 #endif
118 };
119