HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hash.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7
8#include "required.hpp"
9#include <emmintrin.h>
10#include <wmmintrin.h>
11#include <utility>
12#include <array>
13#include <type_traits>
14
15namespace tt {
16
17[[nodiscard]] inline size_t hash_mix_two(size_t hash1, size_t hash2) noexcept
18{
19 ttlet round = _mm_set_epi64x(0x123456789abcdef0ULL, 0x0fedcba987654321ULL);
20
21 auto hash = _mm_set_epi64x(hash1, hash2);
22 hash = _mm_aesenc_si128(hash, round);
23 hash = _mm_aesenc_si128(hash, round);
24
26 _mm_storeu_si64(buffer.data(), hash);
27 return buffer[0];
28}
29
30template<typename First, typename Second, typename... Args>
31[[nodiscard]] size_t hash_mix(First &&first, Second &&second, Args &&... args) noexcept {
32 if constexpr (sizeof...(args) == 0) {
33 return hash_mix_two(
34 std::hash<std::remove_cvref_t<First>>{}(std::forward<First>(first)),
35 std::hash<std::remove_cvref_t<Second>>{}(std::forward<Second>(second))
36 );
37 } else {
38 return hash_mix_two(
39 std::hash<std::remove_cvref_t<First>>{}(std::forward<First>(first)),
40 hash_mix(std::forward<Second>(second), std::forward<Args>(args)...)
41 );
42 }
43}
44
45
46}
T data(T... args)
T round(T... args)