Skip to content

Commit 9cd4342

Browse files
authored
Optimize T1HAGlobals
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent feefb79 commit 9cd4342

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

HashifyNet/Algorithms/T1HA/T1HAGlobals.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// *
1+
// *
22
// *****************************************************************************
33
// *
44
// * Copyright (c) 2025 Deskasoft International
@@ -27,6 +27,12 @@
2727
// ******************************************************************************
2828
// *
2929

30+
#if NET8_0_OR_GREATER
31+
using System;
32+
#endif
33+
34+
using System.Runtime.CompilerServices;
35+
3036
namespace HashifyNet.Algorithms.T1HA
3137
{
3238
internal static class T1HAGlobals
@@ -46,5 +52,38 @@ internal static class T1HAGlobals
4652
public const ulong PRIME_4 = 0x9C06FAF4D023E3ABUL;
4753
public const ulong PRIME_5 = 0xC060724A8424F345UL;
4854
public const ulong PRIME_6 = 0xCB5AF53AE3AAAC31UL;
55+
56+
57+
#if true
58+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
59+
private static ulong BigMul_ref(ulong a, ulong b, out ulong low)
60+
{
61+
unchecked
62+
{
63+
uint al = (uint)a;
64+
uint ah = (uint)(a >> 32);
65+
uint bl = (uint)b;
66+
uint bh = (uint)(b >> 32);
67+
68+
ulong mull = ((ulong)al) * bl;
69+
ulong t = ((ulong)ah) * bl + (mull >> 32);
70+
ulong tl = ((ulong)al) * bh + (uint)t;
71+
72+
low = tl << 32 | (uint)mull;
73+
74+
return ((ulong)ah) * bh + (t >> 32) + (tl >> 32);
75+
}
76+
}
77+
#endif
78+
79+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
80+
public static void BigMul128(ulong x, ulong y, out ulong lo, out ulong hi)
81+
{
82+
#if NET8_0_OR_GREATER
83+
hi = Math.BigMul(x, y, out lo);
84+
#else
85+
hi = BigMul_ref(x, y, out lo);
86+
#endif
87+
}
4988
}
5089
}

0 commit comments

Comments
 (0)