summaryrefslogtreecommitdiff
path: root/grpc/third_party/xxhash/tests/bench/hashes.h
blob: 2042dc58945fcbe75bb65c96d882ef4091320b3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
*  List hash algorithms to benchmark
*  Part of xxHash project
*  Copyright (C) 2019-2020 Yann Collet
*
*  GPL v2 License
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program 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 General Public License for more details.
*
*  You should have received a copy of the GNU General Public License along
*  with this program; if not, write to the Free Software Foundation, Inc.,
*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*  You can contact the author at:
*  - xxHash homepage: https://www.xxhash.com
*  - xxHash source repository: https://github.com/Cyan4973/xxHash
*/


/* ===   Dependencies   === */

#include <stddef.h>   /* size_t */


/* ==================================================
 *   Non-portable hash algorithms
 * =============================================== */


#ifdef HARDWARE_SUPPORT

/*
 * List any hash algorithms that depend on specific hardware support,
 * including for example:
 * - Hardware crc32c
 * - Hardware AES support
 * - Carryless Multipliers (clmul)
 * - AVX2
 */

#endif



/* ==================================================
 * List of hashes
 * ==================================================
 * Each hash must be wrapped in a thin redirector conformant with the BMK_benchfn_t.
 * BMK_benchfn_t is generic, not specifically designed for hashes.
 * For hashes, the following parameters are expected to be useless:
 * dst, dstCapacity, customPayload.
 *
 * The result of each hash is assumed to be provided as function return value.
 * This condition is important for latency measurements.
 */

 /* ===  xxHash  === */
#define XXH_INLINE_ALL
#include "xxhash.h"

size_t XXH32_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
{
    (void)dst; (void)dstCapacity; (void)customPayload;
    return (size_t) XXH32(src, srcSize, 0);
}


size_t XXH64_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
{
    (void)dst; (void)dstCapacity; (void)customPayload;
    return (size_t) XXH64(src, srcSize, 0);
}


size_t xxh3_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
{
    (void)dst; (void)dstCapacity; (void)customPayload;
    return (size_t) XXH3_64bits(src, srcSize);
}


size_t XXH128_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
{
    (void)dst; (void)dstCapacity; (void)customPayload;
    return (size_t) XXH3_128bits(src, srcSize).low64;
}



/* ==================================================
 * Table of hashes
 * =============================================== */

#include "bhDisplay.h"   /* Bench_Entry */

#ifndef HARDWARE_SUPPORT
#  define NB_HASHES 4
#else
#  define NB_HASHES 4
#endif

Bench_Entry const hashCandidates[NB_HASHES] = {
    { "xxh3"  , xxh3_wrapper },
    { "XXH32" , XXH32_wrapper },
    { "XXH64" , XXH64_wrapper },
    { "XXH128", XXH128_wrapper },
#ifdef HARDWARE_SUPPORT
    /* list here codecs which require specific hardware support, such SSE4.1, PCLMUL, AVX2, etc. */
#endif
};