hashes.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /* === Dependencies === */
  27. #include <stddef.h> /* size_t */
  28. /* ==================================================
  29. * Non-portable hash algorithms
  30. * =============================================== */
  31. #ifdef HARDWARE_SUPPORT
  32. /*
  33. * List any hash algorithms that depend on specific hardware support,
  34. * including for example:
  35. * - Hardware crc32c
  36. * - Hardware AES support
  37. * - Carryless Multipliers (clmul)
  38. * - AVX2
  39. */
  40. #endif
  41. /* ==================================================
  42. * List of hashes
  43. * ==================================================
  44. * Each hash must be wrapped in a thin redirector conformant with the BMK_benchfn_t.
  45. * BMK_benchfn_t is generic, not specifically designed for hashes.
  46. * For hashes, the following parameters are expected to be useless:
  47. * dst, dstCapacity, customPayload.
  48. *
  49. * The result of each hash is assumed to be provided as function return value.
  50. * This condition is important for latency measurements.
  51. */
  52. /* === xxHash === */
  53. #define XXH_INLINE_ALL
  54. #include "xxhash.h"
  55. size_t XXH32_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
  56. {
  57. (void)dst; (void)dstCapacity; (void)customPayload;
  58. return (size_t) XXH32(src, srcSize, 0);
  59. }
  60. size_t XXH64_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
  61. {
  62. (void)dst; (void)dstCapacity; (void)customPayload;
  63. return (size_t) XXH64(src, srcSize, 0);
  64. }
  65. size_t xxh3_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
  66. {
  67. (void)dst; (void)dstCapacity; (void)customPayload;
  68. return (size_t) XXH3_64bits(src, srcSize);
  69. }
  70. size_t XXH128_wrapper(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload)
  71. {
  72. (void)dst; (void)dstCapacity; (void)customPayload;
  73. return (size_t) XXH3_128bits(src, srcSize).low64;
  74. }
  75. /* ==================================================
  76. * Table of hashes
  77. * =============================================== */
  78. #include "bhDisplay.h" /* Bench_Entry */
  79. #ifndef HARDWARE_SUPPORT
  80. # define NB_HASHES 4
  81. #else
  82. # define NB_HASHES 4
  83. #endif
  84. Bench_Entry const hashCandidates[NB_HASHES] = {
  85. { "xxh3" , xxh3_wrapper },
  86. { "XXH32" , XXH32_wrapper },
  87. { "XXH64" , XXH64_wrapper },
  88. { "XXH128", XXH128_wrapper },
  89. #ifdef HARDWARE_SUPPORT
  90. /* list here codecs which require specific hardware support, such SSE4.1, PCLMUL, AVX2, etc. */
  91. #endif
  92. };