HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hash.hpp
1// Copyright 2019 Pokitec
2// All rights reserved.
3
4#pragma once
5
6
7#include "TTauri/Foundation/required.hpp"
8#include "TTauri/Foundation/type_traits.hpp"
9#include <emmintrin.h>
10#include <wmmintrin.h>
11#include <utility>
12#include <array>
13
14namespace tt {
15
16[[nodiscard]] inline size_t hash_mix_two(size_t hash1, size_t hash2) noexcept
17{
18 ttlet round = _mm_set_epi64x(0x123456789abcdef0ULL, 0x0fedcba987654321ULL);
19
20 auto hash = _mm_set_epi64x(hash1, hash2);
21 hash = _mm_aesenc_si128(hash, round);
22 hash = _mm_aesenc_si128(hash, round);
23
25 _mm_storeu_si64(buffer.data(), hash);
26 return buffer[0];
27}
28
29template<typename First, typename Second, typename... Args>
30[[nodiscard]] size_t hash_mix(First &&first, Second &&second, Args &&... args) noexcept {
31 if constexpr (sizeof...(args) == 0) {
32 return hash_mix_two(
33 std::hash<remove_cvref_t<First>>{}(std::forward<First>(first)),
34 std::hash<remove_cvref_t<Second>>{}(std::forward<Second>(second))
35 );
36 } else {
37 return hash_mix_two(
38 std::hash<remove_cvref_t<First>>{}(std::forward<First>(first)),
39 hash_mix(std::forward<Second>(second), std::forward<Args>(args)...)
40 );
41 }
42}
43
44
45}
T data(T... args)
T round(T... args)