Skip to content

Commit 1d24ec0

Browse files
[Rendering] Improve performance;
1 parent 4484a30 commit 1d24ec0

26 files changed

+3673
-97
lines changed

Dependencies/premake5_dotnet.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ project "CrossCopy"
3131
"CrossCopy/*.cs"
3232
}
3333

34+
project "xxHash"
35+
kind "SharedLib"
36+
language "C#"
37+
clr "Unsafe"
38+
39+
files {
40+
"xxHash/**.cs"
41+
}
42+
3443
project "SDL3-CS"
3544
kind "SharedLib"
3645
language "C#"

Dependencies/xxHash/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Melnik Alexander
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Runtime.CompilerServices;
4+
5+
namespace Standart.Hash.xxHash
6+
{
7+
public static class Utils
8+
{
9+
public static Guid ToGuid(this uint128 value)
10+
{
11+
var a = (Int32) (value.low64);
12+
var b = (Int16) (value.low64 >> 32);
13+
var c = (Int16) (value.low64 >> 48);
14+
15+
var d = (Byte) (value.high64);
16+
var e = (Byte) (value.high64 >> 8);
17+
var f = (Byte) (value.high64 >> 16);
18+
var g = (Byte) (value.high64 >> 24);
19+
var h = (Byte) (value.high64 >> 32);
20+
var i = (Byte) (value.high64 >> 40);
21+
var j = (Byte) (value.high64 >> 48);
22+
var k = (Byte) (value.high64 >> 56);
23+
24+
return new Guid(a, b, c, d, e, f,g, h, i, j, k);
25+
}
26+
27+
public static byte[] ToBytes(this uint128 value)
28+
{
29+
// allocation
30+
byte[] bytes = new byte[sizeof(ulong) * 2];
31+
Unsafe.As<byte, ulong>(ref bytes[0]) = value.low64;
32+
Unsafe.As<byte, ulong>(ref bytes[8]) = value.high64;
33+
return bytes;
34+
}
35+
36+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
37+
internal static unsafe void BlockCopy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count)
38+
{
39+
Debug.Assert(src != null);
40+
Debug.Assert(dst != null);
41+
Debug.Assert(srcOffset >= 0 && srcOffset < src.Length);
42+
Debug.Assert(dstOffset >= 0 && dstOffset < dst.Length);
43+
Debug.Assert(count >= 0);
44+
Debug.Assert(count + srcOffset <= src.Length);
45+
Debug.Assert(count + dstOffset <= dst.Length);
46+
47+
fixed (byte* pSrc = &src[srcOffset])
48+
fixed (byte* pDst = &dst[dstOffset])
49+
{
50+
byte* ptrSrc = pSrc;
51+
byte* ptrDst = pDst;
52+
53+
SMALLTABLE:
54+
switch (count)
55+
{
56+
case 0:
57+
return;
58+
case 1:
59+
*ptrDst = *ptrSrc;
60+
return;
61+
case 2:
62+
*(short*)ptrDst = *(short*)ptrSrc;
63+
return;
64+
case 3:
65+
*(short*)(ptrDst + 0) = *(short*)(ptrSrc + 0);
66+
*(ptrDst + 2) = *(ptrSrc + 2);
67+
return;
68+
case 4:
69+
*(int*)ptrDst = *(int*)ptrSrc;
70+
return;
71+
case 5:
72+
*(int*)(ptrDst + 0) = *(int*)(ptrSrc + 0);
73+
*(ptrDst + 4) = *(ptrSrc + 4);
74+
return;
75+
case 6:
76+
*(int*)(ptrDst + 0) = *(int*)(ptrSrc + 0);
77+
*(short*)(ptrDst + 4) = *(short*)(ptrSrc + 4);
78+
return;
79+
case 7:
80+
*(int*)(ptrDst + 0) = *(int*)(ptrSrc + 0);
81+
*(short*)(ptrDst + 4) = *(short*)(ptrSrc + 4);
82+
*(ptrDst + 6) = *(ptrSrc + 6);
83+
return;
84+
case 8:
85+
*(long*)ptrDst = *(long*)ptrSrc;
86+
return;
87+
case 9:
88+
*(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0);
89+
*(ptrDst + 8) = *(ptrSrc + 8);
90+
return;
91+
case 10:
92+
*(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0);
93+
*(short*)(ptrDst + 8) = *(short*)(ptrSrc + 8);
94+
return;
95+
case 11:
96+
*(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0);
97+
*(short*)(ptrDst + 8) = *(short*)(ptrSrc + 8);
98+
*(ptrDst + 10) = *(ptrSrc + 10);
99+
return;
100+
case 12:
101+
*(long*)ptrDst = *(long*)ptrSrc;
102+
*(int*)(ptrDst + 8) = *(int*)(ptrSrc + 8);
103+
return;
104+
case 13:
105+
*(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0);
106+
*(int*)(ptrDst + 8) = *(int*)(ptrSrc + 8);
107+
*(ptrDst + 12) = *(ptrSrc + 12);
108+
return;
109+
case 14:
110+
*(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0);
111+
*(int*)(ptrDst + 8) = *(int*)(ptrSrc + 8);
112+
*(short*)(ptrDst + 12) = *(short*)(ptrSrc + 12);
113+
return;
114+
case 15:
115+
*(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0);
116+
*(int*)(ptrDst + 8) = *(int*)(ptrSrc + 8);
117+
*(short*)(ptrDst + 12) = *(short*)(ptrSrc + 12);
118+
*(ptrDst + 14) = *(ptrSrc + 14);
119+
return;
120+
case 16:
121+
*(long*)ptrDst = *(long*)ptrSrc;
122+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
123+
return;
124+
case 17:
125+
*(long*)ptrDst = *(long*)ptrSrc;
126+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
127+
*(ptrDst + 16) = *(ptrSrc + 16);
128+
return;
129+
case 18:
130+
*(long*)ptrDst = *(long*)ptrSrc;
131+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
132+
*(short*)(ptrDst + 16) = *(short*)(ptrSrc + 16);
133+
return;
134+
case 19:
135+
*(long*)ptrDst = *(long*)ptrSrc;
136+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
137+
*(short*)(ptrDst + 16) = *(short*)(ptrSrc + 16);
138+
*(ptrDst + 18) = *(ptrSrc + 18);
139+
return;
140+
case 20:
141+
*(long*)ptrDst = *(long*)ptrSrc;
142+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
143+
*(int*)(ptrDst + 16) = *(int*)(ptrSrc + 16);
144+
return;
145+
146+
case 21:
147+
*(long*)ptrDst = *(long*)ptrSrc;
148+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
149+
*(int*)(ptrDst + 16) = *(int*)(ptrSrc + 16);
150+
*(ptrDst + 20) = *(ptrSrc + 20);
151+
return;
152+
case 22:
153+
*(long*)ptrDst = *(long*)ptrSrc;
154+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
155+
*(int*)(ptrDst + 16) = *(int*)(ptrSrc + 16);
156+
*(short*)(ptrDst + 20) = *(short*)(ptrSrc + 20);
157+
return;
158+
case 23:
159+
*(long*)ptrDst = *(long*)ptrSrc;
160+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
161+
*(int*)(ptrDst + 16) = *(int*)(ptrSrc + 16);
162+
*(short*)(ptrDst + 20) = *(short*)(ptrSrc + 20);
163+
*(ptrDst + 22) = *(ptrSrc + 22);
164+
return;
165+
case 24:
166+
*(long*)ptrDst = *(long*)ptrSrc;
167+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
168+
*(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16);
169+
return;
170+
case 25:
171+
*(long*)ptrDst = *(long*)ptrSrc;
172+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
173+
*(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16);
174+
*(ptrDst + 24) = *(ptrSrc + 24);
175+
return;
176+
case 26:
177+
*(long*)ptrDst = *(long*)ptrSrc;
178+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
179+
*(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16);
180+
*(short*)(ptrDst + 24) = *(short*)(ptrSrc + 24);
181+
return;
182+
case 27:
183+
*(long*)ptrDst = *(long*)ptrSrc;
184+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
185+
*(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16);
186+
*(short*)(ptrDst + 24) = *(short*)(ptrSrc + 24);
187+
*(ptrDst + 26) = *(ptrSrc + 26);
188+
return;
189+
case 28:
190+
*(long*)ptrDst = *(long*)ptrSrc;
191+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
192+
*(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16);
193+
*(int*)(ptrDst + 24) = *(int*)(ptrSrc + 24);
194+
return;
195+
case 29:
196+
*(long*)ptrDst = *(long*)ptrSrc;
197+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
198+
*(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16);
199+
*(int*)(ptrDst + 24) = *(int*)(ptrSrc + 24);
200+
*(ptrDst + 28) = *(ptrSrc + 28);
201+
return;
202+
case 30:
203+
*(long*)ptrDst = *(long*)ptrSrc;
204+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
205+
*(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16);
206+
*(int*)(ptrDst + 24) = *(int*)(ptrSrc + 24);
207+
*(short*)(ptrDst + 28) = *(short*)(ptrSrc + 28);
208+
return;
209+
case 31:
210+
*(long*)ptrDst = *(long*)ptrSrc;
211+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
212+
*(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16);
213+
*(int*)(ptrDst + 24) = *(int*)(ptrSrc + 24);
214+
*(short*)(ptrDst + 28) = *(short*)(ptrSrc + 28);
215+
*(ptrDst + 30) = *(ptrSrc + 30);
216+
return;
217+
case 32:
218+
*(long*)ptrDst = *(long*)ptrSrc;
219+
*(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8);
220+
*(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16);
221+
*(long*)(ptrDst + 24) = *(long*)(ptrSrc + 24);
222+
return;
223+
}
224+
225+
long* lpSrc = (long*)ptrSrc;
226+
long* ldSrc = (long*)ptrDst;
227+
while (count >= 64)
228+
{
229+
*(ldSrc + 0) = *(lpSrc + 0);
230+
*(ldSrc + 1) = *(lpSrc + 1);
231+
*(ldSrc + 2) = *(lpSrc + 2);
232+
*(ldSrc + 3) = *(lpSrc + 3);
233+
*(ldSrc + 4) = *(lpSrc + 4);
234+
*(ldSrc + 5) = *(lpSrc + 5);
235+
*(ldSrc + 6) = *(lpSrc + 6);
236+
*(ldSrc + 7) = *(lpSrc + 7);
237+
if (count == 64)
238+
return;
239+
count -= 64;
240+
lpSrc += 8;
241+
ldSrc += 8;
242+
}
243+
if (count > 32)
244+
{
245+
*(ldSrc + 0) = *(lpSrc + 0);
246+
*(ldSrc + 1) = *(lpSrc + 1);
247+
*(ldSrc + 2) = *(lpSrc + 2);
248+
*(ldSrc + 3) = *(lpSrc + 3);
249+
count -= 32;
250+
lpSrc += 4;
251+
ldSrc += 4;
252+
}
253+
254+
ptrSrc = (byte*)lpSrc;
255+
ptrDst = (byte*)ldSrc;
256+
goto SMALLTABLE;
257+
}
258+
}
259+
}
260+
}

0 commit comments

Comments
 (0)