From 064e9a1aa363d8b14264dc56f0dada764bd0f0f4 Mon Sep 17 00:00:00 2001 From: yingnierxiao Date: Fri, 25 Aug 2023 14:53:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=93=E5=8C=85=E9=80=9F?= =?UTF-8?q?=E5=BA=A6=EF=BC=8C=E6=8F=90=E7=A4=BA=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E9=80=9F=E5=BA=A6=EF=BC=8Cmd5=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2xxhash=EF=BC=8C=E9=80=9F=E5=BA=A6=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E4=B8=80=E5=80=8D=E4=BB=A5=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BuildTasks/TaskCreateManifest.cs | 70 ++- .../BuildTasks/TaskUpdateBundleInfo.cs | 4 +- Assets/YooAsset/Editor/EditorTools.cs | 2 +- .../Internal/LoadCacheManifestOperation.cs | 2 +- .../Runtime/PackageSystem/PackageManifest.cs | 2 + Assets/YooAsset/Runtime/Plugins.meta | 8 + ...System.Runtime.CompilerServices.Unsafe.dll | Bin 0 -> 16768 bytes ...m.Runtime.CompilerServices.Unsafe.dll.meta | 33 ++ Assets/YooAsset/Runtime/Utility/YooUtility.cs | 23 + Assets/YooAsset/Runtime/YooAsset.asmdef | 3 +- Assets/YooAsset/Runtime/xxHash.meta | 8 + Assets/YooAsset/Runtime/xxHash/Utils.cs | 260 ++++++++++ Assets/YooAsset/Runtime/xxHash/Utils.cs.meta | 11 + .../Runtime/xxHash/__inline__xxHash32.cs | 191 ++++++++ .../Runtime/xxHash/__inline__xxHash32.cs.meta | 11 + .../Runtime/xxHash/__inline__xxHash64.cs | 252 ++++++++++ .../Runtime/xxHash/__inline__xxHash64.cs.meta | 11 + .../YooAsset/Runtime/xxHash/xxHash128.XXH.cs | 125 +++++ .../Runtime/xxHash/xxHash128.XXH.cs.meta | 11 + .../YooAsset/Runtime/xxHash/xxHash128.XXH3.cs | 452 ++++++++++++++++++ .../Runtime/xxHash/xxHash128.XXH3.cs.meta | 11 + .../Runtime/xxHash/xxHash128.XXH64.cs | 20 + .../Runtime/xxHash/xxHash128.XXH64.cs.meta | 11 + Assets/YooAsset/Runtime/xxHash/xxHash128.cs | 180 +++++++ .../YooAsset/Runtime/xxHash/xxHash128.cs.meta | 11 + Assets/YooAsset/Runtime/xxHash/xxHash3.XXH.cs | 118 +++++ .../Runtime/xxHash/xxHash3.XXH.cs.meta | 11 + .../YooAsset/Runtime/xxHash/xxHash3.XXH3.cs | 368 ++++++++++++++ .../Runtime/xxHash/xxHash3.XXH3.cs.meta | 11 + .../YooAsset/Runtime/xxHash/xxHash3.XXH64.cs | 20 + .../Runtime/xxHash/xxHash3.XXH64.cs.meta | 11 + Assets/YooAsset/Runtime/xxHash/xxHash3.cs | 96 ++++ .../YooAsset/Runtime/xxHash/xxHash3.cs.meta | 11 + .../YooAsset/Runtime/xxHash/xxHash32.XXH.cs | 21 + .../Runtime/xxHash/xxHash32.XXH.cs.meta | 11 + .../YooAsset/Runtime/xxHash/xxHash32.XXH32.cs | 90 ++++ .../Runtime/xxHash/xxHash32.XXH32.cs.meta | 11 + Assets/YooAsset/Runtime/xxHash/xxHash32.cs | 265 ++++++++++ .../YooAsset/Runtime/xxHash/xxHash32.cs.meta | 11 + .../YooAsset/Runtime/xxHash/xxHash64.XXH.cs | 21 + .../Runtime/xxHash/xxHash64.XXH.cs.meta | 11 + .../YooAsset/Runtime/xxHash/xxHash64.XXH64.cs | 106 ++++ .../Runtime/xxHash/xxHash64.XXH64.cs.meta | 11 + Assets/YooAsset/Runtime/xxHash/xxHash64.cs | 266 +++++++++++ .../YooAsset/Runtime/xxHash/xxHash64.cs.meta | 11 + 45 files changed, 3172 insertions(+), 21 deletions(-) create mode 100644 Assets/YooAsset/Runtime/Plugins.meta create mode 100644 Assets/YooAsset/Runtime/Plugins/System.Runtime.CompilerServices.Unsafe.dll create mode 100644 Assets/YooAsset/Runtime/Plugins/System.Runtime.CompilerServices.Unsafe.dll.meta create mode 100644 Assets/YooAsset/Runtime/xxHash.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/Utils.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/Utils.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/__inline__xxHash32.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/__inline__xxHash32.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/__inline__xxHash64.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/__inline__xxHash64.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash128.XXH.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash128.XXH.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash128.XXH3.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash128.XXH3.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash128.XXH64.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash128.XXH64.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash128.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash128.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash3.XXH.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash3.XXH.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash3.XXH3.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash3.XXH3.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash3.XXH64.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash3.XXH64.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash3.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash3.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash32.XXH.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash32.XXH.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash32.XXH32.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash32.XXH32.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash32.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash32.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash64.XXH.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash64.XXH.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash64.XXH64.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash64.XXH64.cs.meta create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash64.cs create mode 100644 Assets/YooAsset/Runtime/xxHash/xxHash64.cs.meta diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs index a4a10da..2b447f9 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs @@ -41,6 +41,14 @@ namespace YooAsset.Editor manifest.PackageName = buildParameters.PackageName; manifest.PackageVersion = buildParameters.PackageVersion; manifest.BundleList = GetAllPackageBundle(context); + int len = manifest.BundleList.Count; + manifest.BundleListMap = new Dictionary(len); + + for (int i = 0; i < len; i++) + { + var item = manifest.BundleList[i]; + manifest.BundleListMap.Add(item.BundleName,i); + } manifest.AssetList = GetAllPackageAsset(context, manifest); // 更新Unity内置资源包的引用关系 @@ -87,7 +95,7 @@ namespace YooAsset.Editor string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion); string filePath = $"{packageOutputDirectory}/{fileName}"; ManifestTools.SerializeToBinary(filePath, manifest); - packageHash = HashUtility.FileMD5(filePath); + packageHash = HashUtility.FileXXhash(filePath); BuildLogger.Log($"创建补丁清单文件:{filePath}"); ManifestContext manifestContext = new ManifestContext(); @@ -156,7 +164,7 @@ namespace YooAsset.Editor } private int[] GetAssetBundleDependIDs(int mainBundleID, BuildAssetInfo assetInfo, PackageManifest manifest) { - List result = new List(); + HashSet result = new HashSet(); foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos) { if (dependAssetInfo.HasBundleName()) @@ -173,11 +181,17 @@ namespace YooAsset.Editor } private int GetAssetBundleID(string bundleName, PackageManifest manifest) { - for (int index = 0; index < manifest.BundleList.Count; index++) + // for (int index = 0; index < manifest.BundleList.Count; index++) + // { + // if (manifest.BundleList[index].BundleName == bundleName) + // return index; + // } + + if (manifest.BundleListMap.ContainsKey(bundleName)) { - if (manifest.BundleList[index].BundleName == bundleName) - return index; + return manifest.BundleListMap[bundleName]; } + throw new Exception($"Not found bundle name : {bundleName}"); } @@ -212,7 +226,7 @@ namespace YooAsset.Editor List conflictAssetPathList = dependBundles.Intersect(shaderBundleReferenceList).ToList(); if (conflictAssetPathList.Count > 0) { - List newDependIDs = new List(packageAsset.DependIDs); + HashSet newDependIDs = new HashSet(packageAsset.DependIDs); if (newDependIDs.Contains(shaderBundleId) == false) newDependIDs.Add(shaderBundleId); packageAsset.DependIDs = newDependIDs.ToArray(); @@ -226,7 +240,7 @@ namespace YooAsset.Editor // 更新资源包标签 var packageBundle = manifest.BundleList[shaderBundleId]; - List newTags = new List(packageBundle.Tags); + HashSet newTags = new HashSet(packageBundle.Tags); foreach (var tag in tagTemps) { if (newTags.Contains(tag) == false) @@ -251,7 +265,7 @@ namespace YooAsset.Editor private readonly Dictionary _cachedBundleID = new Dictionary(10000); private readonly Dictionary _cachedBundleDepends = new Dictionary(10000); - private void UpdateScriptPipelineReference(PackageManifest manifest, TaskBuilding_SBP.BuildResultContext buildResultContext) + private void UpdateScriptPipelineReference(PackageManifest manifest, TaskBuilding_SBP.BuildResultContext buildResultContext) { int progressValue; int totalCount = manifest.BundleList.Count; @@ -263,7 +277,11 @@ namespace YooAsset.Editor { int bundleID = GetAssetBundleID(packageBundle.BundleName, manifest); _cachedBundleID.Add(packageBundle.BundleName, bundleID); - EditorTools.DisplayProgressBar("缓存资源包索引", ++progressValue, totalCount); + int pro = ++progressValue; + if (pro % 100 == 0) + { + EditorTools.DisplayProgressBar("缓存资源包索引", pro, totalCount); + } } EditorTools.ClearProgressBar(); @@ -283,7 +301,11 @@ namespace YooAsset.Editor var depends = buildResultContext.Results.BundleInfos[packageBundle.BundleName].Dependencies; _cachedBundleDepends.Add(packageBundle.BundleName, depends); - EditorTools.DisplayProgressBar("缓存资源包依赖列表", ++progressValue, totalCount); + int pro = ++progressValue; + if (pro % 100 == 0) + { + EditorTools.DisplayProgressBar("缓存资源包依赖列表", pro, totalCount); + } } EditorTools.ClearProgressBar(); @@ -291,7 +313,11 @@ namespace YooAsset.Editor foreach (var packageBundle in manifest.BundleList) { packageBundle.ReferenceIDs = GetBundleRefrenceIDs(manifest, packageBundle); - EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount); + int pro = ++progressValue; + if (pro % 100 == 0) + { + EditorTools.DisplayProgressBar("计算资源包引用关系", pro, totalCount); + } } EditorTools.ClearProgressBar(); } @@ -307,7 +333,11 @@ namespace YooAsset.Editor { int bundleID = GetAssetBundleID(packageBundle.BundleName, manifest); _cachedBundleID.Add(packageBundle.BundleName, bundleID); - EditorTools.DisplayProgressBar("缓存资源包索引", ++progressValue, totalCount); + int pro = ++progressValue; + if (pro % 100 == 0) + { + EditorTools.DisplayProgressBar("缓存资源包索引", pro, totalCount); + } } EditorTools.ClearProgressBar(); @@ -324,7 +354,11 @@ namespace YooAsset.Editor var depends = buildResultContext.UnityManifest.GetDirectDependencies(packageBundle.BundleName); _cachedBundleDepends.Add(packageBundle.BundleName, depends); - EditorTools.DisplayProgressBar("缓存资源包依赖列表", ++progressValue, totalCount); + int pro = ++progressValue; + if (pro % 100 == 0) + { + EditorTools.DisplayProgressBar("缓存资源包依赖列表", pro, totalCount); + } } EditorTools.ClearProgressBar(); @@ -333,7 +367,11 @@ namespace YooAsset.Editor foreach (var packageBundle in manifest.BundleList) { packageBundle.ReferenceIDs = GetBundleRefrenceIDs(manifest, packageBundle); - EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount); + int pro = ++progressValue; + if (pro%100==0) + { + EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount); + } } EditorTools.ClearProgressBar(); } @@ -344,7 +382,7 @@ namespace YooAsset.Editor foreach (var packageBundle in manifest.BundleList) { string bundleName = packageBundle.BundleName; - if (bundleName == targetBundle.BundleName) + if (packageBundle.Equals(targetBundle) || packageBundle.IsRawFile) continue; string[] dependencies = GetCachedBundleDepends(bundleName); @@ -354,7 +392,7 @@ namespace YooAsset.Editor } } - List result = new List(); + HashSet result = new HashSet(); foreach (var bundleName in referenceList) { int bundleID = GetCachedBundleID(bundleName); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskUpdateBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskUpdateBundleInfo.cs index ab7e63f..19c9125 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskUpdateBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskUpdateBundleInfo.cs @@ -68,7 +68,7 @@ namespace YooAsset.Editor if (bundleInfo.IsRawFile) { string filePath = bundleInfo.PackageSourceFilePath; - return HashUtility.FileMD5(filePath); + return HashUtility.FileXXhash(filePath); } if (parameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline) @@ -132,7 +132,7 @@ namespace YooAsset.Editor if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) return "00000000000000000000000000000000"; //32位 else - return HashUtility.FileMD5(filePath); + return HashUtility.FileXXhash(filePath); } private string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext) { diff --git a/Assets/YooAsset/Editor/EditorTools.cs b/Assets/YooAsset/Editor/EditorTools.cs index cb5f061..1a82b36 100644 --- a/Assets/YooAsset/Editor/EditorTools.cs +++ b/Assets/YooAsset/Editor/EditorTools.cs @@ -153,7 +153,7 @@ namespace YooAsset.Editor guids = AssetDatabase.FindAssets($"t:{searchType}", searchInFolders); // 注意:AssetDatabase.FindAssets()可能会获取到重复的资源 - List result = new List(); + HashSet result = new HashSet(); for (int i = 0; i < guids.Length; i++) { string guid = guids[i]; diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadCacheManifestOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadCacheManifestOperation.cs index 0ea054c..fd6d887 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadCacheManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/Internal/LoadCacheManifestOperation.cs @@ -77,7 +77,7 @@ namespace YooAsset return; } - string fileHash = HashUtility.FileMD5(_manifestFilePath); + string fileHash = HashUtility.FileXXhash(_manifestFilePath); if (fileHash != _queryCachePackageHashOp.PackageHash) { _steps = ESteps.Done; diff --git a/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs b/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs index 881b935..2c53d36 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PackageManifest.cs @@ -57,6 +57,8 @@ namespace YooAsset /// public List BundleList = new List(); + public Dictionary BundleListMap; + /// /// 资源包集合(提供BundleName获取PackageBundle) diff --git a/Assets/YooAsset/Runtime/Plugins.meta b/Assets/YooAsset/Runtime/Plugins.meta new file mode 100644 index 0000000..98f9a5c --- /dev/null +++ b/Assets/YooAsset/Runtime/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 626314312007949aebb542dcbbfe1a78 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/Plugins/System.Runtime.CompilerServices.Unsafe.dll b/Assets/YooAsset/Runtime/Plugins/System.Runtime.CompilerServices.Unsafe.dll new file mode 100644 index 0000000000000000000000000000000000000000..1908d925a3162b60ec13b3f4d54f605dc8d1dc87 GIT binary patch literal 16768 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�YGrOyR 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 NXP8vX4Zi>8{{feYTRs2) literal 0 HcmV?d00001 diff --git a/Assets/YooAsset/Runtime/Plugins/System.Runtime.CompilerServices.Unsafe.dll.meta b/Assets/YooAsset/Runtime/Plugins/System.Runtime.CompilerServices.Unsafe.dll.meta new file mode 100644 index 0000000..f75af73 --- /dev/null +++ b/Assets/YooAsset/Runtime/Plugins/System.Runtime.CompilerServices.Unsafe.dll.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: f9ed697de8b5f18478c683c64e889512 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/Utility/YooUtility.cs b/Assets/YooAsset/Runtime/Utility/YooUtility.cs index f1dba37..8d854b8 100644 --- a/Assets/YooAsset/Runtime/Utility/YooUtility.cs +++ b/Assets/YooAsset/Runtime/Utility/YooUtility.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Text; using System.IO; using System.Security.Cryptography; +using Standart.Hash.xxHash; namespace YooAsset { @@ -280,6 +281,28 @@ namespace YooAsset return string.Empty; } } + + + /// + /// 获取文件的XXXhash32 + /// + /// + /// + public static string FileXXhash(string filePath) + { + try + { + using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + return xxHash32.ComputeHash(fs).ToString("x8"); + } + } + catch (Exception e) + { + YooLogger.Exception(e); + return string.Empty; + } + } /// /// 获取数据流的MD5 diff --git a/Assets/YooAsset/Runtime/YooAsset.asmdef b/Assets/YooAsset/Runtime/YooAsset.asmdef index d906ae1..f3b53a8 100644 --- a/Assets/YooAsset/Runtime/YooAsset.asmdef +++ b/Assets/YooAsset/Runtime/YooAsset.asmdef @@ -1,9 +1,10 @@ { "name": "YooAsset", + "rootNamespace": "", "references": [], "includePlatforms": [], "excludePlatforms": [], - "allowUnsafeCode": false, + "allowUnsafeCode": true, "overrideReferences": false, "precompiledReferences": [], "autoReferenced": true, diff --git a/Assets/YooAsset/Runtime/xxHash.meta b/Assets/YooAsset/Runtime/xxHash.meta new file mode 100644 index 0000000..dc9860f --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 99e361f80e17cb540a43e670a09a4745 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/Utils.cs b/Assets/YooAsset/Runtime/xxHash/Utils.cs new file mode 100644 index 0000000..7168007 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/Utils.cs @@ -0,0 +1,260 @@ +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public static class Utils + { + public static Guid ToGuid(this uint128 value) + { + var a = (Int32) (value.low64); + var b = (Int16) (value.low64 >> 32); + var c = (Int16) (value.low64 >> 48); + + var d = (Byte) (value.high64); + var e = (Byte) (value.high64 >> 8); + var f = (Byte) (value.high64 >> 16); + var g = (Byte) (value.high64 >> 24); + var h = (Byte) (value.high64 >> 32); + var i = (Byte) (value.high64 >> 40); + var j = (Byte) (value.high64 >> 48); + var k = (Byte) (value.high64 >> 56); + + return new Guid(a, b, c, d, e, f,g, h, i, j, k); + } + + public static byte[] ToBytes(this uint128 value) + { + // allocation + byte[] bytes = new byte[sizeof(ulong) * 2]; + Unsafe.As(ref bytes[0]) = value.low64; + Unsafe.As(ref bytes[8]) = value.high64; + return bytes; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static unsafe void BlockCopy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count) + { + Debug.Assert(src != null); + Debug.Assert(dst != null); + Debug.Assert(srcOffset >= 0 && srcOffset < src.Length); + Debug.Assert(dstOffset >= 0 && dstOffset < dst.Length); + Debug.Assert(count >= 0); + Debug.Assert(count + srcOffset <= src.Length); + Debug.Assert(count + dstOffset <= dst.Length); + + fixed (byte* pSrc = &src[srcOffset]) + fixed (byte* pDst = &dst[dstOffset]) + { + byte* ptrSrc = pSrc; + byte* ptrDst = pDst; + + SMALLTABLE: + switch (count) + { + case 0: + return; + case 1: + *ptrDst = *ptrSrc; + return; + case 2: + *(short*)ptrDst = *(short*)ptrSrc; + return; + case 3: + *(short*)(ptrDst + 0) = *(short*)(ptrSrc + 0); + *(ptrDst + 2) = *(ptrSrc + 2); + return; + case 4: + *(int*)ptrDst = *(int*)ptrSrc; + return; + case 5: + *(int*)(ptrDst + 0) = *(int*)(ptrSrc + 0); + *(ptrDst + 4) = *(ptrSrc + 4); + return; + case 6: + *(int*)(ptrDst + 0) = *(int*)(ptrSrc + 0); + *(short*)(ptrDst + 4) = *(short*)(ptrSrc + 4); + return; + case 7: + *(int*)(ptrDst + 0) = *(int*)(ptrSrc + 0); + *(short*)(ptrDst + 4) = *(short*)(ptrSrc + 4); + *(ptrDst + 6) = *(ptrSrc + 6); + return; + case 8: + *(long*)ptrDst = *(long*)ptrSrc; + return; + case 9: + *(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0); + *(ptrDst + 8) = *(ptrSrc + 8); + return; + case 10: + *(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0); + *(short*)(ptrDst + 8) = *(short*)(ptrSrc + 8); + return; + case 11: + *(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0); + *(short*)(ptrDst + 8) = *(short*)(ptrSrc + 8); + *(ptrDst + 10) = *(ptrSrc + 10); + return; + case 12: + *(long*)ptrDst = *(long*)ptrSrc; + *(int*)(ptrDst + 8) = *(int*)(ptrSrc + 8); + return; + case 13: + *(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0); + *(int*)(ptrDst + 8) = *(int*)(ptrSrc + 8); + *(ptrDst + 12) = *(ptrSrc + 12); + return; + case 14: + *(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0); + *(int*)(ptrDst + 8) = *(int*)(ptrSrc + 8); + *(short*)(ptrDst + 12) = *(short*)(ptrSrc + 12); + return; + case 15: + *(long*)(ptrDst + 0) = *(long*)(ptrSrc + 0); + *(int*)(ptrDst + 8) = *(int*)(ptrSrc + 8); + *(short*)(ptrDst + 12) = *(short*)(ptrSrc + 12); + *(ptrDst + 14) = *(ptrSrc + 14); + return; + case 16: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + return; + case 17: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(ptrDst + 16) = *(ptrSrc + 16); + return; + case 18: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(short*)(ptrDst + 16) = *(short*)(ptrSrc + 16); + return; + case 19: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(short*)(ptrDst + 16) = *(short*)(ptrSrc + 16); + *(ptrDst + 18) = *(ptrSrc + 18); + return; + case 20: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(int*)(ptrDst + 16) = *(int*)(ptrSrc + 16); + return; + + case 21: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(int*)(ptrDst + 16) = *(int*)(ptrSrc + 16); + *(ptrDst + 20) = *(ptrSrc + 20); + return; + case 22: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(int*)(ptrDst + 16) = *(int*)(ptrSrc + 16); + *(short*)(ptrDst + 20) = *(short*)(ptrSrc + 20); + return; + case 23: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(int*)(ptrDst + 16) = *(int*)(ptrSrc + 16); + *(short*)(ptrDst + 20) = *(short*)(ptrSrc + 20); + *(ptrDst + 22) = *(ptrSrc + 22); + return; + case 24: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16); + return; + case 25: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16); + *(ptrDst + 24) = *(ptrSrc + 24); + return; + case 26: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16); + *(short*)(ptrDst + 24) = *(short*)(ptrSrc + 24); + return; + case 27: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16); + *(short*)(ptrDst + 24) = *(short*)(ptrSrc + 24); + *(ptrDst + 26) = *(ptrSrc + 26); + return; + case 28: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16); + *(int*)(ptrDst + 24) = *(int*)(ptrSrc + 24); + return; + case 29: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16); + *(int*)(ptrDst + 24) = *(int*)(ptrSrc + 24); + *(ptrDst + 28) = *(ptrSrc + 28); + return; + case 30: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16); + *(int*)(ptrDst + 24) = *(int*)(ptrSrc + 24); + *(short*)(ptrDst + 28) = *(short*)(ptrSrc + 28); + return; + case 31: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16); + *(int*)(ptrDst + 24) = *(int*)(ptrSrc + 24); + *(short*)(ptrDst + 28) = *(short*)(ptrSrc + 28); + *(ptrDst + 30) = *(ptrSrc + 30); + return; + case 32: + *(long*)ptrDst = *(long*)ptrSrc; + *(long*)(ptrDst + 8) = *(long*)(ptrSrc + 8); + *(long*)(ptrDst + 16) = *(long*)(ptrSrc + 16); + *(long*)(ptrDst + 24) = *(long*)(ptrSrc + 24); + return; + } + + long* lpSrc = (long*)ptrSrc; + long* ldSrc = (long*)ptrDst; + while (count >= 64) + { + *(ldSrc + 0) = *(lpSrc + 0); + *(ldSrc + 1) = *(lpSrc + 1); + *(ldSrc + 2) = *(lpSrc + 2); + *(ldSrc + 3) = *(lpSrc + 3); + *(ldSrc + 4) = *(lpSrc + 4); + *(ldSrc + 5) = *(lpSrc + 5); + *(ldSrc + 6) = *(lpSrc + 6); + *(ldSrc + 7) = *(lpSrc + 7); + if (count == 64) + return; + count -= 64; + lpSrc += 8; + ldSrc += 8; + } + if (count > 32) + { + *(ldSrc + 0) = *(lpSrc + 0); + *(ldSrc + 1) = *(lpSrc + 1); + *(ldSrc + 2) = *(lpSrc + 2); + *(ldSrc + 3) = *(lpSrc + 3); + count -= 32; + lpSrc += 4; + ldSrc += 4; + } + + ptrSrc = (byte*)lpSrc; + ptrDst = (byte*)ldSrc; + goto SMALLTABLE; + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/Utils.cs.meta b/Assets/YooAsset/Runtime/xxHash/Utils.cs.meta new file mode 100644 index 0000000..3901b6f --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/Utils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 07b97cff0161f014f857bb23a25d73a9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/__inline__xxHash32.cs b/Assets/YooAsset/Runtime/xxHash/__inline__xxHash32.cs new file mode 100644 index 0000000..078f8c0 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/__inline__xxHash32.cs @@ -0,0 +1,191 @@ +/* +* This is the auto generated code. +* All function calls are inlined in XXH32 +* Please don't try to analyze it. +*/ + +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public partial class xxHash32 + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint __inline__XXH32(byte* input, int len, uint seed) + { + uint h32; + + if (len >= 16) + { + byte* end = input + len; + byte* limit = end - 15; + + uint v1 = seed + XXH_PRIME32_1 + XXH_PRIME32_2; + uint v2 = seed + XXH_PRIME32_2; + uint v3 = seed + 0; + uint v4 = seed - XXH_PRIME32_1; + + do + { + var reg1 = *((uint*)(input + 0)); + var reg2 = *((uint*)(input + 4)); + var reg3 = *((uint*)(input + 8)); + var reg4 = *((uint*)(input + 12)); + + // XXH32_round + v1 += reg1 * XXH_PRIME32_2; + v1 = (v1 << 13) | (v1 >> (32 - 13)); + v1 *= XXH_PRIME32_1; + + // XXH32_round + v2 += reg2 * XXH_PRIME32_2; + v2 = (v2 << 13) | (v2 >> (32 - 13)); + v2 *= XXH_PRIME32_1; + + // XXH32_round + v3 += reg3 * XXH_PRIME32_2; + v3 = (v3 << 13) | (v3 >> (32 - 13)); + v3 *= XXH_PRIME32_1; + + // XXH32_round + v4 += reg4 * XXH_PRIME32_2; + v4 = (v4 << 13) | (v4 >> (32 - 13)); + v4 *= XXH_PRIME32_1; + + input += 16; + } while (input < limit); + + h32 = ((v1 << 1) | (v1 >> (32 - 1))) + + ((v2 << 7) | (v2 >> (32 - 7))) + + ((v3 << 12) | (v3 >> (32 - 12))) + + ((v4 << 18) | (v4 >> (32 - 18))); + } + else + { + h32 = seed + XXH_PRIME32_5; + } + + h32 += (uint) len; + + // XXH32_finalize + len &= 15; + while (len >= 4) + { + h32 += *((uint*) input) * XXH_PRIME32_3; + input += 4; + h32 = ((h32 << 17) | (h32 >> (32 - 17))) * XXH_PRIME32_4; + len -= 4; + } + + while (len > 0) + { + h32 += *((byte*) input) * XXH_PRIME32_5; + ++input; + h32 = ((h32 << 11) | (h32 >> (32 - 11))) * XXH_PRIME32_1; + --len; + } + + // XXH32_avalanche + h32 ^= h32 >> 15; + h32 *= XXH_PRIME32_2; + h32 ^= h32 >> 13; + h32 *= XXH_PRIME32_3; + h32 ^= h32 >> 16; + + return h32; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void __inline__XXH32_stream_process(byte[] input, int len, ref uint v1, ref uint v2, ref uint v3, ref uint v4) + { + fixed (byte* pData = &input[0]) + { + byte* ptr = pData; + byte* limit = ptr + len; + + do + { + var reg1 = *((uint*)(ptr + 0)); + var reg2 = *((uint*)(ptr + 4)); + var reg3 = *((uint*)(ptr + 8)); + var reg4 = *((uint*)(ptr + 12)); + + // XXH32_round + v1 += reg1 * XXH_PRIME32_2; + v1 = (v1 << 13) | (v1 >> (32 - 13)); + v1 *= XXH_PRIME32_1; + + // XXH32_round + v2 += reg2 * XXH_PRIME32_2; + v2 = (v2 << 13) | (v2 >> (32 - 13)); + v2 *= XXH_PRIME32_1; + + // XXH32_round + v3 += reg3 * XXH_PRIME32_2; + v3 = (v3 << 13) | (v3 >> (32 - 13)); + v3 *= XXH_PRIME32_1; + + // XXH32_round + v4 += reg4 * XXH_PRIME32_2; + v4 = (v4 << 13) | (v4 >> (32 - 13)); + v4 *= XXH_PRIME32_1; + + ptr += 16; + + } while (ptr < limit); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint __inline__XXH32_stream_finalize(byte[] input, int len, ref uint v1, ref uint v2, ref uint v3, ref uint v4, long length, uint seed) + { + fixed (byte* pData = &input[0]) + { + byte* ptr = pData; + uint h32; + + if (length >= 16) + { + h32 = ((v1 << 1) | (v1 >> (32 - 1))) + + ((v2 << 7) | (v2 >> (32 - 7))) + + ((v3 << 12) | (v3 >> (32 - 12))) + + ((v4 << 18) | (v4 >> (32 - 18))); + } + else + { + h32 = seed + XXH_PRIME32_5; + } + + h32 += (uint)length; + + // XXH32_finalize + len &= 15; + while (len >= 4) + { + h32 += *((uint*)ptr) * XXH_PRIME32_3; + ptr += 4; + h32 = ((h32 << 17) | (h32 >> (32 - 17))) * XXH_PRIME32_4; + len -= 4; + } + + while (len > 0) + { + h32 += *((byte*)ptr) * XXH_PRIME32_5; + ptr++; + h32 = ((h32 << 11) | (h32 >> (32 - 11))) * XXH_PRIME32_1; + len--; + } + + // XXH32_avalanche + h32 ^= h32 >> 15; + h32 *= XXH_PRIME32_2; + h32 ^= h32 >> 13; + h32 *= XXH_PRIME32_3; + h32 ^= h32 >> 16; + + return h32; + } + } + } +} + diff --git a/Assets/YooAsset/Runtime/xxHash/__inline__xxHash32.cs.meta b/Assets/YooAsset/Runtime/xxHash/__inline__xxHash32.cs.meta new file mode 100644 index 0000000..d552a7f --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/__inline__xxHash32.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7bd3966e4951b294d8cda4a41bb4b690 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/__inline__xxHash64.cs b/Assets/YooAsset/Runtime/xxHash/__inline__xxHash64.cs new file mode 100644 index 0000000..451dbf4 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/__inline__xxHash64.cs @@ -0,0 +1,252 @@ +/* +* This is the auto generated code. +* All function calls are inlined in XXH64 +* Please don't try to analyze it. +*/ + +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public partial class xxHash64 + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong __inline__XXH64(byte* input, int len, ulong seed) + { + ulong h64; + + if (len >= 32) + { + byte* end = input + len; + byte* limit = end - 31; + + ulong v1 = seed + XXH_PRIME64_1 + XXH_PRIME64_2; + ulong v2 = seed + XXH_PRIME64_2; + ulong v3 = seed + 0; + ulong v4 = seed - XXH_PRIME64_1; + + do + { + var reg1 = *((ulong*)(input + 0)); + var reg2 = *((ulong*)(input + 8)); + var reg3 = *((ulong*)(input + 16)); + var reg4 = *((ulong*)(input + 24)); + + // XXH64_round + v1 += reg1 * XXH_PRIME64_2; + v1 = (v1 << 31) | (v1 >> (64 - 31)); + v1 *= XXH_PRIME64_1; + + // XXH64_round + v2 += reg2 * XXH_PRIME64_2; + v2 = (v2 << 31) | (v2 >> (64 - 31)); + v2 *= XXH_PRIME64_1; + + // XXH64_round + v3 += reg3 * XXH_PRIME64_2; + v3 = (v3 << 31) | (v3 >> (64 - 31)); + v3 *= XXH_PRIME64_1; + + // XXH64_round + v4 += reg4 * XXH_PRIME64_2; + v4 = (v4 << 31) | (v4 >> (64 - 31)); + v4 *= XXH_PRIME64_1; + input += 32; + } while (input < limit); + + h64 = ((v1 << 1) | (v1 >> (64 - 1))) + + ((v2 << 7) | (v2 >> (64 - 7))) + + ((v3 << 12) | (v3 >> (64 - 12))) + + ((v4 << 18) | (v4 >> (64 - 18))); + + // XXH64_mergeRound + v1 *= XXH_PRIME64_2; + v1 = (v1 << 31) | (v1 >> (64 - 31)); + v1 *= XXH_PRIME64_1; + h64 ^= v1; + h64 = h64 * XXH_PRIME64_1 + XXH_PRIME64_4; + + // XXH64_mergeRound + v2 *= XXH_PRIME64_2; + v2 = (v2 << 31) | (v2 >> (64 - 31)); + v2 *= XXH_PRIME64_1; + h64 ^= v2; + h64 = h64 * XXH_PRIME64_1 + XXH_PRIME64_4; + + // XXH64_mergeRound + v3 *= XXH_PRIME64_2; + v3 = (v3 << 31) | (v3 >> (64 - 31)); + v3 *= XXH_PRIME64_1; + h64 ^= v3; + h64 = h64 * XXH_PRIME64_1 + XXH_PRIME64_4; + + // XXH64_mergeRound + v4 *= XXH_PRIME64_2; + v4 = (v4 << 31) | (v4 >> (64 - 31)); + v4 *= XXH_PRIME64_1; + h64 ^= v4; + h64 = h64 * XXH_PRIME64_1 + XXH_PRIME64_4; + } + else + { + h64 = seed + XXH_PRIME64_5; + } + + h64 += (ulong) len; + + // XXH64_finalize + len &= 31; + while (len >= 8) { + ulong k1 = XXH64_round(0, *(ulong*)input); + input += 8; + h64 ^= k1; + h64 = XXH_rotl64(h64,27) * XXH_PRIME64_1 + XXH_PRIME64_4; + len -= 8; + } + if (len >= 4) { + h64 ^= *(uint*)input * XXH_PRIME64_1; + input += 4; + h64 = XXH_rotl64(h64, 23) * XXH_PRIME64_2 + XXH_PRIME64_3; + len -= 4; + } + while (len > 0) { + h64 ^= (*input++) * XXH_PRIME64_5; + h64 = XXH_rotl64(h64, 11) * XXH_PRIME64_1; + --len; + } + + // XXH64_avalanche + h64 ^= h64 >> 33; + h64 *= XXH_PRIME64_2; + h64 ^= h64 >> 29; + h64 *= XXH_PRIME64_3; + h64 ^= h64 >> 32; + + return h64; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void __inline__XXH64_stream_process(byte[] input, int len, ref ulong v1, ref ulong v2, ref ulong v3, + ref ulong v4) + { + fixed (byte* pData = &input[0]) + { + byte* ptr = pData; + byte* limit = ptr + len; + + do + { + var reg1 = *((ulong*)(ptr + 0)); + var reg2 = *((ulong*)(ptr + 8)); + var reg3 = *((ulong*)(ptr + 16)); + var reg4 = *((ulong*)(ptr + 24)); + + // XXH64_round + v1 += reg1 * XXH_PRIME64_2; + v1 = (v1 << 31) | (v1 >> (64 - 31)); + v1 *= XXH_PRIME64_1; + + // XXH64_round + v2 += reg2 * XXH_PRIME64_2; + v2 = (v2 << 31) | (v2 >> (64 - 31)); + v2 *= XXH_PRIME64_1; + + // XXH64_round + v3 += reg3 * XXH_PRIME64_2; + v3 = (v3 << 31) | (v3 >> (64 - 31)); + v3 *= XXH_PRIME64_1; + + // XXH64_round + v4 += reg4 * XXH_PRIME64_2; + v4 = (v4 << 31) | (v4 >> (64 - 31)); + v4 *= XXH_PRIME64_1; + ptr += 32; + } while (ptr < limit); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong __inline__XXH64_stream_finalize(byte[] input, int len, ref ulong v1, ref ulong v2, ref ulong v3, + ref ulong v4, long length, ulong seed) + { + fixed (byte* pData = &input[0]) + { + byte* ptr = pData; + byte* end = pData + len; + ulong h64; + + if (length >= 32) + { + h64 = ((v1 << 1) | (v1 >> (64 - 1))) + + ((v2 << 7) | (v2 >> (64 - 7))) + + ((v3 << 12) | (v3 >> (64 - 12))) + + ((v4 << 18) | (v4 >> (64 - 18))); + + // XXH64_mergeRound + v1 *= XXH_PRIME64_2; + v1 = (v1 << 31) | (v1 >> (64 - 31)); + v1 *= XXH_PRIME64_1; + h64 ^= v1; + h64 = h64 * XXH_PRIME64_1 + XXH_PRIME64_4; + + // XXH64_mergeRound + v2 *= XXH_PRIME64_2; + v2 = (v2 << 31) | (v2 >> (64 - 31)); + v2 *= XXH_PRIME64_1; + h64 ^= v2; + h64 = h64 * XXH_PRIME64_1 + XXH_PRIME64_4; + + // XXH64_mergeRound + v3 *= XXH_PRIME64_2; + v3 = (v3 << 31) | (v3 >> (64 - 31)); + v3 *= XXH_PRIME64_1; + h64 ^= v3; + h64 = h64 * XXH_PRIME64_1 + XXH_PRIME64_4; + + // XXH64_mergeRound + v4 *= XXH_PRIME64_2; + v4 = (v4 << 31) | (v4 >> (64 - 31)); + v4 *= XXH_PRIME64_1; + h64 ^= v4; + h64 = h64 * XXH_PRIME64_1 + XXH_PRIME64_4; + } + else + { + h64 = seed + XXH_PRIME64_5; + } + + h64 += (ulong) length; + + // XXH64_finalize + len &= 31; + while (len >= 8) { + ulong k1 = XXH64_round(0, *(ulong*)ptr); + ptr += 8; + h64 ^= k1; + h64 = XXH_rotl64(h64,27) * XXH_PRIME64_1 + XXH_PRIME64_4; + len -= 8; + } + if (len >= 4) { + h64 ^= *(uint*)ptr * XXH_PRIME64_1; + ptr += 4; + h64 = XXH_rotl64(h64, 23) * XXH_PRIME64_2 + XXH_PRIME64_3; + len -= 4; + } + while (len > 0) { + h64 ^= (*ptr++) * XXH_PRIME64_5; + h64 = XXH_rotl64(h64, 11) * XXH_PRIME64_1; + --len; + } + + // XXH64_avalanche + h64 ^= h64 >> 33; + h64 *= XXH_PRIME64_2; + h64 ^= h64 >> 29; + h64 *= XXH_PRIME64_3; + h64 ^= h64 >> 32; + + return h64; + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/__inline__xxHash64.cs.meta b/Assets/YooAsset/Runtime/xxHash/__inline__xxHash64.cs.meta new file mode 100644 index 0000000..717881a --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/__inline__xxHash64.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 81174f2235c739845b98c1eed4778f17 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH.cs b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH.cs new file mode 100644 index 0000000..97809c5 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH.cs @@ -0,0 +1,125 @@ +// ReSharper disable InconsistentNaming + +using System.Runtime.CompilerServices; +namespace Standart.Hash.xxHash +{ + public static partial class xxHash128 + { + private static readonly ulong XXH_PRIME64_1 = 11400714785074694791UL; + private static readonly ulong XXH_PRIME64_2 = 14029467366897019727UL; + private static readonly ulong XXH_PRIME64_3 = 1609587929392839161UL; + private static readonly ulong XXH_PRIME64_4 = 9650029242287828579UL; + private static readonly ulong XXH_PRIME64_5 = 2870177450012600261UL; + + private static readonly uint XXH_PRIME32_1 = 2654435761U; + private static readonly uint XXH_PRIME32_2 = 2246822519U; + private static readonly uint XXH_PRIME32_3 = 3266489917U; + private static readonly uint XXH_PRIME32_4 = 668265263U; + private static readonly uint XXH_PRIME32_5 = 374761393U; + + private static readonly int XXH_STRIPE_LEN = 64; + private static readonly int XXH_ACC_NB = 8; + private static readonly int XXH_SECRET_CONSUME_RATE = 8; + private static readonly int XXH_SECRET_MERGEACCS_START = 11; + private static readonly int XXH_SECRET_DEFAULT_SIZE = 192; + private static readonly int XXH_SECRET_LASTACC_START = 7; + + private static readonly byte MM_SHUFFLE_0_3_0_1 = 0b0011_0001; + private static readonly byte MM_SHUFFLE_1_0_3_2 = 0b0100_1110; + + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint XXH_rotl32(uint x, int r) + { + return (x << r) | (x >> (32 - r)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH_rotl64(ulong x, int r) + { + return (x << r) | (x >> (64 - r)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH_readLE64(byte* ptr) + { + return *(ulong*) ptr; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint XXH_readLE32(byte* ptr) + { + return *(uint*) ptr; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH_xorshift64(ulong v64, int shift) + { + return v64 ^ (v64 >> shift); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint XXH_swap32(uint x) + { + return ((x << 24) & 0xff000000 ) | + ((x << 8) & 0x00ff0000 ) | + ((x >> 8) & 0x0000ff00 ) | + ((x >> 24) & 0x000000ff ); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH_swap64(ulong x) + { + return ((x << 56) & 0xff00000000000000UL) | + ((x << 40) & 0x00ff000000000000UL) | + ((x << 24) & 0x0000ff0000000000UL) | + ((x << 8) & 0x000000ff00000000UL) | + ((x >> 8) & 0x00000000ff000000UL) | + ((x >> 24) & 0x0000000000ff0000UL) | + ((x >> 40) & 0x000000000000ff00UL) | + ((x >> 56) & 0x00000000000000ffUL); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH_mult32to64(ulong x, ulong y) + { + return (ulong)(uint)(x) * (ulong)(uint)(y); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint128 XXH_mult64to128(ulong lhs, ulong rhs) + { + + + return XXH_mult64to128_scalar(lhs, rhs); + } + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint128 XXH_mult64to128_scalar(ulong lhs, ulong rhs) + { + ulong lo_lo = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs & 0xFFFFFFFF); + ulong hi_lo = XXH_mult32to64(lhs >> 32, rhs & 0xFFFFFFFF); + ulong lo_hi = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs >> 32); + ulong hi_hi = XXH_mult32to64(lhs >> 32, rhs >> 32); + + ulong cross = (lo_lo >> 32) + (hi_lo & 0xFFFFFFFF) + lo_hi; + ulong upper = (hi_lo >> 32) + (cross >> 32) + hi_hi; + ulong lower = (cross << 32) | (lo_lo & 0xFFFFFFFF); + + uint128 r128; + r128.low64 = lower; + r128.high64 = upper; + return r128; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH_writeLE64(byte* dst, ulong v64) + { + *(ulong*) dst = v64; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH.cs.meta new file mode 100644 index 0000000..0912cb3 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 45095bcca3212f441b4c38711f0ff93d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH3.cs b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH3.cs new file mode 100644 index 0000000..60d4250 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH3.cs @@ -0,0 +1,452 @@ +// ReSharper disable InconsistentNaming + +using System.Diagnostics; +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash128 + { + private static readonly byte[] XXH3_SECRET = + { + 0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c, + 0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f, + 0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21, + 0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c, + 0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3, + 0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8, + 0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d, + 0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64, + 0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb, + 0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e, + 0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce, + 0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e, + }; + + private static readonly ulong[] XXH3_INIT_ACC = + { + XXH_PRIME32_3, XXH_PRIME64_1, XXH_PRIME64_2, XXH_PRIME64_3, + XXH_PRIME64_4, XXH_PRIME32_2, XXH_PRIME64_5, XXH_PRIME32_1 + }; + + private static readonly int XXH3_SECRET_SIZE_MIN = 136; + private static readonly int XXH3_SECRET_DEFAULT_SIZE = 192; + private static readonly int XXH3_MIDSIZE_MAX = 240; + private static readonly int XXH3_MIDSIZE_STARTOFFSET = 3; + private static readonly int XXH3_MIDSIZE_LASTOFFSET = 17; + private static readonly int XXH3_ACC_SIZE = 64; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 XXH3_128bits_internal(byte* input, int len, ulong seed, byte* secret, int secretLen) + { + Debug.Assert(secretLen >= XXH3_SECRET_SIZE_MIN); + + if (len <= 16) + return XXH3_len_0to16_128b(input, len, secret, seed); + if (len <= 128) + return XXH3_len_17to128_128b(input, len, secret, secretLen, seed); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_128b(input, len, secret, secretLen, seed); + + return XXH3_hashLong_128b_withSeed(input, len, secret, secretLen, seed); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 XXH3_len_0to16_128b(byte* input, int len, byte* secret, ulong seed) + { + Debug.Assert(len <= 16); + + if (len > 8) return XXH3_len_9to16_128b(input, len, secret, seed); + if (len >= 4) return XXH3_len_4to8_128b(input, len, secret, seed); + if (len != 0) return XXH3_len_1to3_128b(input, len, secret, seed); + + uint128 h128; + ulong bitflipl = XXH_readLE64(secret + 64) ^ XXH_readLE64(secret + 72); + ulong bitfliph = XXH_readLE64(secret + 80) ^ XXH_readLE64(secret + 88); + h128.low64 = XXH64_avalanche(seed ^ bitflipl); + h128.high64 = XXH64_avalanche(seed ^ bitfliph); + return h128; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 XXH3_len_17to128_128b(byte* input, int len, byte* secret, int secretSize, ulong seed) + { + Debug.Assert(secretSize >= XXH3_SECRET_SIZE_MIN); + Debug.Assert(16 < len && len <= 128); + + uint128 acc; + acc.low64 = (ulong) len * XXH_PRIME64_1; + acc.high64 = 0; + + if (len > 32) { + if (len > 64) { + if (len > 96) { + acc = XXH128_mix32B(acc, input+48, input+len-64, secret+96, seed); + } + acc = XXH128_mix32B(acc, input+32, input+len-48, secret+64, seed); + } + acc = XXH128_mix32B(acc, input+16, input+len-32, secret+32, seed); + } + acc = XXH128_mix32B(acc, input, input+len-16, secret, seed); + + uint128 h128; + h128.low64 = acc.low64 + acc.high64; + h128.high64 = (acc.low64 * XXH_PRIME64_1) + + (acc.high64 * XXH_PRIME64_4) + + (((ulong) len - seed) * XXH_PRIME64_2); + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = (ulong) 0 - XXH3_avalanche(h128.high64); + return h128; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 XXH3_len_9to16_128b(byte* input, int len, byte* secret, ulong seed) + { + Debug.Assert(input != null); + Debug.Assert(secret != null); + Debug.Assert(9 <= len && len <= 16); + + ulong bitflipl = (XXH_readLE64(secret + 32) ^ XXH_readLE64(secret + 40)) - seed; + ulong bitfliph = (XXH_readLE64(secret + 48) ^ XXH_readLE64(secret + 56)) + seed; + ulong input_lo = XXH_readLE64(input); + ulong input_hi = XXH_readLE64(input + len - 8); + uint128 m128 = XXH_mult64to128(input_lo ^ input_hi ^ bitflipl, XXH_PRIME64_1); + + m128.low64 += (ulong) (len - 1) << 54; + input_hi ^= bitfliph; + + m128.high64 += input_hi + XXH_mult32to64((uint) input_hi, XXH_PRIME32_2 - 1); + m128.low64 ^= XXH_swap64(m128.high64); + + uint128 h128 = XXH_mult64to128(m128.low64, XXH_PRIME64_2); + h128.high64 += m128.high64 * XXH_PRIME64_2; + + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = XXH3_avalanche(h128.high64); + return h128; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 XXH3_len_1to3_128b(byte* input, int len, byte* secret, ulong seed) + { + Debug.Assert(input != null); + Debug.Assert(1 <= len && len <= 3); + Debug.Assert(secret != null); + + byte c1 = input[0]; + byte c2 = input[len >> 1]; + byte c3 = input[len - 1]; + + uint combinedl = ((uint) c1 << 16) | + ((uint) c2 << 24) | + ((uint) c3 << 0) | + ((uint) len << 8); + uint combinedh = XXH_rotl32(XXH_swap32(combinedl), 13); + + ulong bitflipl = (XXH_readLE32(secret) ^ XXH_readLE32(secret + 4)) + seed; + ulong bitfliph = (XXH_readLE32(secret + 8) ^ XXH_readLE32(secret + 12)) - seed; + ulong keyed_lo = (ulong) combinedl ^ bitflipl; + ulong keyed_hi = (ulong) combinedh ^ bitfliph; + + uint128 h128; + h128.low64 = XXH64_avalanche(keyed_lo); + h128.high64 = XXH64_avalanche(keyed_hi); + + return h128; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 XXH3_len_4to8_128b(byte* input, int len, byte* secret, ulong seed) + { + Debug.Assert(input != null); + Debug.Assert(secret != null); + Debug.Assert(4 <= len && len <= 8); + + seed ^= (ulong) XXH_swap32((uint) seed) << 32; + + uint input_lo = XXH_readLE32(input); + uint input_hi = XXH_readLE32(input + len - 4); + ulong input_64 = input_lo + ((ulong) input_hi << 32); + ulong bitflip = (XXH_readLE64(secret + 16) ^ XXH_readLE64(secret + 24)) + seed; + ulong keyed = input_64 ^ bitflip; + + uint128 m128 = XXH_mult64to128(keyed, XXH_PRIME64_1 + ((ulong) len << 2)); + + m128.high64 += (m128.low64 << 1); + m128.low64 ^= (m128.high64 >> 3); + + m128.low64 = XXH_xorshift64(m128.low64, 35); + m128.low64 *= 0x9FB21C651E98DF25UL; + m128.low64 = XXH_xorshift64(m128.low64, 28); + m128.high64 = XXH3_avalanche(m128.high64); + + return m128; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 XXH3_len_129to240_128b(byte* input, int len, byte* secret, int secretSize, ulong seed) + { + Debug.Assert(secretSize >= XXH3_SECRET_SIZE_MIN); + Debug.Assert(128 < len && len <= XXH3_MIDSIZE_MAX); + + uint128 acc; + int nbRounds = len / 32; + + acc.low64 = (ulong) len * XXH_PRIME64_1; + acc.high64 = 0; + for (int i = 0; i < 4; i++) { + acc = XXH128_mix32B(acc, + input + (32 * i), + input + (32 * i) + 16, + secret + (32 * i), + seed); + } + + acc.low64 = XXH3_avalanche(acc.low64); + acc.high64 = XXH3_avalanche(acc.high64); + + for (int i = 4 ; i < nbRounds; i++) { + acc = XXH128_mix32B(acc, + input + (32 * i), + input + (32 * i) + 16, + secret + XXH3_MIDSIZE_STARTOFFSET + (32 * (i - 4)), + seed); + } + + acc = XXH128_mix32B(acc, + input + len - 16, + input + len - 32, + secret + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET - 16, + 0UL - seed); + + uint128 h128; + h128.low64 = acc.low64 + acc.high64; + h128.high64 = (acc.low64 * XXH_PRIME64_1) + + (acc.high64 * XXH_PRIME64_4) + + (((ulong)len - seed) * XXH_PRIME64_2); + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = (ulong)0 - XXH3_avalanche(h128.high64); + return h128; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH3_avalanche(ulong h64) + { + h64 = XXH_xorshift64(h64, 37); + h64 *= 0x165667919E3779F9UL; + h64 = XXH_xorshift64(h64, 32); + return h64; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 XXH128_mix32B(uint128 acc, byte* input_1, byte* input_2, byte* secret, ulong seed) + { + acc.low64 += XXH3_mix16B(input_1, secret + 0, seed); + acc.low64 ^= XXH_readLE64(input_2) + XXH_readLE64(input_2 + 8); + acc.high64 += XXH3_mix16B(input_2, secret + 16, seed); + acc.high64 ^= XXH_readLE64(input_1) + XXH_readLE64(input_1 + 8); + return acc; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_mix16B(byte* input, byte* secret, ulong seed) + { + ulong input_lo = XXH_readLE64(input); + ulong input_hi = XXH_readLE64(input + 8); + + return XXH3_mul128_fold64( + input_lo ^ (XXH_readLE64(secret) + seed), + input_hi ^ (XXH_readLE64(secret + 8) - seed) + ); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH3_mul128_fold64(ulong lhs, ulong rhs) + { + uint128 product = XXH_mult64to128(lhs, rhs); + return product.low64 ^ product.high64; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 XXH3_hashLong_128b_withSeed(byte* input, int len, byte* secret, int secretSize, ulong seed) + { + if (seed == 0) + return XXH3_hashLong_128b_internal(input, len, secret, secretSize); + + byte* customSecret = stackalloc byte[XXH3_SECRET_DEFAULT_SIZE]; + + XXH3_initCustomSecret(customSecret, seed); + + return XXH3_hashLong_128b_internal(input, len, customSecret, XXH3_SECRET_DEFAULT_SIZE); + + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 XXH3_hashLong_128b_internal(byte* input, int len, byte* secret, int secretSize) + { + fixed (ulong* src = &XXH3_INIT_ACC[0]) + { + ulong* acc = stackalloc ulong[8] + { + *(src + 0), + *(src + 1), + *(src + 2), + *(src + 3), + *(src + 4), + *(src + 5), + *(src + 6), + *(src + 7), + }; + + XXH3_hashLong_internal_loop(acc, input, len, secret, secretSize); + + uint128 uint128; + uint128.low64 = XXH3_mergeAccs(acc, + secret + XXH_SECRET_MERGEACCS_START, + (ulong)len * XXH_PRIME64_1); + uint128.high64 = XXH3_mergeAccs(acc, + secret + secretSize - XXH3_ACC_SIZE - XXH_SECRET_MERGEACCS_START, + ~((ulong)len * XXH_PRIME64_2)); + + return uint128; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_hashLong_internal_loop(ulong* acc, byte* input, int len, byte* secret, int secretSize) + { + Debug.Assert(secretSize >= XXH3_SECRET_SIZE_MIN); + Debug.Assert(len > XXH_STRIPE_LEN); + + int nbStripesPerBlock = (secretSize - XXH_STRIPE_LEN) / XXH_SECRET_CONSUME_RATE; + int block_len = XXH_STRIPE_LEN * nbStripesPerBlock; + int nb_blocks = (len - 1) / block_len; + + for (int n = 0; n < nb_blocks; n++) { + XXH3_accumulate(acc, input + n * block_len, secret, nbStripesPerBlock); + XXH3_scrambleAcc(acc, secret + secretSize - XXH_STRIPE_LEN); + } + + int nbStripes = ((len - 1) - (block_len * nb_blocks)) / XXH_STRIPE_LEN; + XXH3_accumulate(acc, input + nb_blocks * block_len, secret, nbStripes); + + byte* p = input + len - XXH_STRIPE_LEN; + XXH3_accumulate_512(acc, p, secret + secretSize - XXH_STRIPE_LEN - XXH_SECRET_LASTACC_START); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_mergeAccs(ulong* acc, byte* secret, ulong start) + { + ulong result64 = start; + + for (int i = 0; i < 4; i++) + result64 += XXH3_mix2Accs(acc + 2 * i, secret + 16 * i); + + return XXH3_avalanche(result64); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_mix2Accs(ulong* acc, byte* secret) + { + return XXH3_mul128_fold64( + acc[0] ^ XXH_readLE64(secret), + acc[1] ^ XXH_readLE64(secret+8) ); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_accumulate(ulong* acc, byte* input, byte* secret, int nbStripes) + { + for (int n = 0; n < nbStripes; n++ ) { + byte* inp = input + n * XXH_STRIPE_LEN; + XXH3_accumulate_512(acc, inp, secret + n * XXH_SECRET_CONSUME_RATE); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_accumulate_512(ulong* acc, byte* input, byte* secret) + { + XXH3_accumulate_512_scalar(acc, input, secret); + + } + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_accumulate_512_scalar(ulong* acc, byte* input, byte* secret) + { + for (int i = 0; i < XXH_ACC_NB; i++) + XXH3_scalarRound(acc, input, secret, i); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_scalarRound(ulong* acc, byte* input, byte* secret, int lane) + { + Debug.Assert(lane < XXH_ACC_NB); + + ulong* xacc = acc; + byte* xinput = input; + byte* xsecret = secret; + + ulong data_val = XXH_readLE64(xinput + lane * 8); + ulong data_key = data_val ^ XXH_readLE64(xsecret + lane * 8); + xacc[lane ^ 1] += data_val; + xacc[lane] += XXH_mult32to64(data_key & 0xFFFFFFFF, data_key >> 32); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_scrambleAcc(ulong* acc, byte* secret) + { + XXH3_scrambleAcc_scalar(acc, secret); + } + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_scrambleAcc_scalar(ulong* acc, byte* secret) + { + for (int i = 0; i < XXH_ACC_NB; i++) + XXH3_scalarScrambleRound(acc, secret, i); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_scalarScrambleRound(ulong* acc, byte* secret, int lane) + { + Debug.Assert(lane < XXH_ACC_NB); + + ulong* xacc = acc; + byte* xsecret = secret; + + ulong key64 = XXH_readLE64(xsecret + lane * 8); + ulong acc64 = xacc[lane]; + acc64 = XXH_xorshift64(acc64, 47); + acc64 ^= key64; + acc64 *= XXH_PRIME32_1; + xacc[lane] = acc64; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_initCustomSecret(byte* customSecret, ulong seed) + { + XXH3_initCustomSecret_scalar(customSecret, seed); + } + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_initCustomSecret_scalar(byte* customSecret, ulong seed) + { + fixed (byte* kSecretPtr = &XXH3_SECRET[0]) + { + int nbRounds = XXH_SECRET_DEFAULT_SIZE / 16; + + for (int i = 0; i < nbRounds; i++) + { + ulong lo = XXH_readLE64(kSecretPtr + 16 * i) + seed; + ulong hi = XXH_readLE64(kSecretPtr + 16 * i + 8) - seed; + XXH_writeLE64((byte*) customSecret + 16 * i, lo); + XXH_writeLE64((byte*) customSecret + 16 * i + 8, hi); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH3.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH3.cs.meta new file mode 100644 index 0000000..f1af4cf --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH3.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1df288f95a653c44dbd9a60f9d9c8979 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH64.cs b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH64.cs new file mode 100644 index 0000000..31349bf --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH64.cs @@ -0,0 +1,20 @@ +// ReSharper disable InconsistentNaming + +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash128 + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH64_avalanche(ulong hash) + { + hash ^= hash >> 33; + hash *= XXH_PRIME64_2; + hash ^= hash >> 29; + hash *= XXH_PRIME64_3; + hash ^= hash >> 32; + return hash; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH64.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH64.cs.meta new file mode 100644 index 0000000..f292e17 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash128.XXH64.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 47b4bf89c9a50a845808824ae5a4b295 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash128.cs b/Assets/YooAsset/Runtime/xxHash/xxHash128.cs new file mode 100644 index 0000000..bf6c06d --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash128.cs @@ -0,0 +1,180 @@ +// ReSharper disable InconsistentNaming + +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash128 + { + /// + /// Compute xxHash for the data byte array + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe uint128 ComputeHash(byte[] data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* ptr = &data[0]) + { + return UnsafeComputeHash(ptr, length, seed); + } + } + + /// + /// Compute xxHash for the data byte span + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe uint128 ComputeHash(Span data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* ptr = &data[0]) + { + return UnsafeComputeHash(ptr, length, seed); + } + } + + /// + /// Compute xxHash for the data byte span + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe uint128 ComputeHash(ReadOnlySpan data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* ptr = &data[0]) + { + return UnsafeComputeHash(ptr, length, seed); + } + } + + /// + /// Compute xxHash for the string + /// + /// The source of data + /// The seed number + /// hash + public static unsafe uint128 ComputeHash(string str, ulong seed = 0) + { + Debug.Assert(str != null); + + fixed (char* c = str) + { + byte* ptr = (byte*) c; + int length = str.Length * 2; + + return UnsafeComputeHash(ptr, length, seed); + } + } + + /// + /// Compute hash bytes for the data byte array + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe byte[] ComputeHashBytes(byte[] data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* ptr = &data[0]) + { + return UnsafeComputeHash(ptr, length, seed).ToBytes(); + } + } + + /// + /// Compute hash bytes for the span + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe byte[] ComputeHashBytes(Span data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* ptr = &data[0]) + { + return UnsafeComputeHash(ptr, length, seed).ToBytes(); + } + } + + /// + /// Compute hash bytes for the data byte span + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe byte[] ComputeHashBytes(ReadOnlySpan data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* ptr = &data[0]) + { + return UnsafeComputeHash(ptr, length, seed).ToBytes(); + } + } + + /// + /// Compute hash bytes for the string + /// + /// The source of data + /// The seed number + /// hash + public static unsafe byte[] ComputeHashBytes(string str, ulong seed = 0) + { + Debug.Assert(str != null); + + fixed (char* c = str) + { + byte* ptr = (byte*) c; + int length = str.Length * 2; + + return UnsafeComputeHash(ptr, length, seed).ToBytes(); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint128 UnsafeComputeHash(byte* input, int len, ulong seed) + { + fixed (byte* secret = &XXH3_SECRET[0]) + { + return XXH3_128bits_internal(input, len, seed, secret, XXH3_SECRET_DEFAULT_SIZE); + } + } + } + + [StructLayout(LayoutKind.Sequential)] + public struct uint128 + { + public ulong low64; + public ulong high64; + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash128.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash128.cs.meta new file mode 100644 index 0000000..464fe0f --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash128.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1ea51d2884ca3b94baf4305ff37b0fcb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH.cs b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH.cs new file mode 100644 index 0000000..bcd5820 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH.cs @@ -0,0 +1,118 @@ +// ReSharper disable InconsistentNaming + +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash3 + { + private static readonly ulong XXH_PRIME64_1 = 11400714785074694791UL; + private static readonly ulong XXH_PRIME64_2 = 14029467366897019727UL; + private static readonly ulong XXH_PRIME64_3 = 1609587929392839161UL; + private static readonly ulong XXH_PRIME64_4 = 9650029242287828579UL; + private static readonly ulong XXH_PRIME64_5 = 2870177450012600261UL; + + private static readonly uint XXH_PRIME32_1 = 2654435761U; + private static readonly uint XXH_PRIME32_2 = 2246822519U; + private static readonly uint XXH_PRIME32_3 = 3266489917U; + private static readonly uint XXH_PRIME32_4 = 668265263U; + private static readonly uint XXH_PRIME32_5 = 374761393U; + + private static readonly int XXH_STRIPE_LEN = 64; + private static readonly int XXH_ACC_NB = XXH_STRIPE_LEN / 8; + private static readonly int XXH_SECRET_CONSUME_RATE = 8; + private static readonly int XXH_SECRET_DEFAULT_SIZE = 192; + private static readonly int XXH_SECRET_MERGEACCS_START = 11; + private static readonly int XXH_SECRET_LASTACC_START = 7; + + private static readonly byte MM_SHUFFLE_0_3_0_1 = 0b0011_0001; + private static readonly byte MM_SHUFFLE_1_0_3_2 = 0b0100_1110; + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH_readLE64(byte* ptr) + { + return *(ulong*) ptr; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint XXH_readLE32(byte* ptr) + { + return *(uint*) ptr; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH_swap64(ulong x) + { + return ((x << 56) & 0xff00000000000000UL) | + ((x << 40) & 0x00ff000000000000UL) | + ((x << 24) & 0x0000ff0000000000UL) | + ((x << 8) & 0x000000ff00000000UL) | + ((x >> 8) & 0x00000000ff000000UL) | + ((x >> 24) & 0x0000000000ff0000UL) | + ((x >> 40) & 0x000000000000ff00UL) | + ((x >> 56) & 0x00000000000000ffUL); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH_mult32to64(ulong x, ulong y) + { + return (ulong) (uint) (x) * (ulong) (uint) (y); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH_xorshift64(ulong v64, int shift) + { + return v64 ^ (v64 >> shift); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint XXH_swap32(uint x) + { + return ((x << 24) & 0xff000000) | + ((x << 8) & 0x00ff0000) | + ((x >> 8) & 0x0000ff00) | + ((x >> 24) & 0x000000ff); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH_rotl64(ulong x, int r) + { + return (x << r) | (x >> (64 - r)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH_writeLE64(byte* dst, ulong v64) + { + *(ulong*) dst = v64; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint128 XXH_mult64to128(ulong lhs, ulong rhs) + { + + + return XXH_mult64to128_scalar(lhs, rhs); + } + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint128 XXH_mult64to128_scalar(ulong lhs, ulong rhs) + { + ulong lo_lo = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs & 0xFFFFFFFF); + ulong hi_lo = XXH_mult32to64(lhs >> 32, rhs & 0xFFFFFFFF); + ulong lo_hi = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs >> 32); + ulong hi_hi = XXH_mult32to64(lhs >> 32, rhs >> 32); + + ulong cross = (lo_lo >> 32) + (hi_lo & 0xFFFFFFFF) + lo_hi; + ulong upper = (hi_lo >> 32) + (cross >> 32) + hi_hi; + ulong lower = (cross << 32) | (lo_lo & 0xFFFFFFFF); + + uint128 r128; + r128.low64 = lower; + r128.high64 = upper; + return r128; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH.cs.meta new file mode 100644 index 0000000..77f0bc6 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 93e944ab70a22e948a6bc0ef5de471c3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH3.cs b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH3.cs new file mode 100644 index 0000000..6ef2b0c --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH3.cs @@ -0,0 +1,368 @@ +// ReSharper disable InconsistentNaming + +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash3 + { + private static readonly byte[] XXH3_SECRET = + { + 0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c, + 0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f, + 0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21, + 0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c, + 0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3, + 0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8, + 0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d, + 0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64, + 0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb, + 0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e, + 0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce, + 0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e, + }; + + private static readonly ulong[] XXH3_INIT_ACC = + { + XXH_PRIME32_3, XXH_PRIME64_1, XXH_PRIME64_2, XXH_PRIME64_3, + XXH_PRIME64_4, XXH_PRIME32_2, XXH_PRIME64_5, XXH_PRIME32_1 + }; + + private static readonly int XXH3_MIDSIZE_MAX = 240; + private static readonly int XXH3_MIDSIZE_STARTOFFSET = 3; + private static readonly int XXH3_MIDSIZE_LASTOFFSET = 17; + private static readonly int XXH3_SECRET_SIZE_MIN = 136; + private static readonly int XXH3_SECRET_DEFAULT_SIZE = 192; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_64bits_internal(byte* input, int len, ulong seed64, byte* secret, + int secretLen) + { + if (len <= 16) + return XXH3_len_0to16_64b(input, len, secret, seed64); + if (len <= 128) + return XXH3_len_17to128_64b(input, len, secret, secretLen, seed64); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_64b(input, len, secret, secretLen, seed64); + + return XXH3_hashLong_64b_withSeed(input, len, seed64, secret, secretLen); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_len_0to16_64b(byte* input, int len, byte* secret, ulong seed) + { + if (len > 8) + return XXH3_len_9to16_64b(input, len, secret, seed); + if (len >= 4) + return XXH3_len_4to8_64b(input, len, secret, seed); + if (len != 0) + return XXH3_len_1to3_64b(input, len, secret, seed); + + return XXH64_avalanche(seed ^ (XXH_readLE64(secret + 56) ^ XXH_readLE64(secret + 64))); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_len_9to16_64b(byte* input, int len, byte* secret, ulong seed) + { + ulong bitflip1 = (XXH_readLE64(secret + 24) ^ XXH_readLE64(secret + 32)) + seed; + ulong bitflip2 = (XXH_readLE64(secret + 40) ^ XXH_readLE64(secret + 48)) - seed; + ulong input_lo = XXH_readLE64(input) ^ bitflip1; + ulong input_hi = XXH_readLE64(input + len - 8) ^ bitflip2; + ulong acc = ((ulong) len) + + XXH_swap64(input_lo) + input_hi + + XXH3_mul128_fold64(input_lo, input_hi); + return XXH3_avalanche(acc); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH3_mul128_fold64(ulong lhs, ulong rhs) + { + uint128 product = XXH_mult64to128(lhs, rhs); + return product.low64 ^ product.high64; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH3_avalanche(ulong h64) + { + h64 = XXH_xorshift64(h64, 37); + h64 *= 0x165667919E3779F9UL; + h64 = XXH_xorshift64(h64, 32); + return h64; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_len_4to8_64b(byte* input, int len, byte* secret, ulong seed) + { + seed ^= (ulong) XXH_swap32((uint) seed) << 32; + { + uint input1 = XXH_readLE32(input); + uint input2 = XXH_readLE32(input + len - 4); + ulong bitflip = (XXH_readLE64(secret + 8) ^ XXH_readLE64(secret + 16)) - seed; + ulong input64 = input2 + (((ulong) input1) << 32); + ulong keyed = input64 ^ bitflip; + return XXH3_rrmxmx(keyed, len); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH3_rrmxmx(ulong h64, int len) + { + h64 ^= XXH_rotl64(h64, 49) ^ XXH_rotl64(h64, 24); + h64 *= 0x9FB21C651E98DF25UL; + h64 ^= (h64 >> 35) + (ulong) len; + h64 *= 0x9FB21C651E98DF25UL; + return XXH_xorshift64(h64, 28); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_len_1to3_64b(byte* input, int len, byte* secret, ulong seed) + { + byte c1 = input[0]; + byte c2 = input[len >> 1]; + byte c3 = input[len - 1]; + uint combined = ((uint) c1 << 16) | + ((uint) c2 << 24) | + ((uint) c3 << 0) | + ((uint) len << 8); + + ulong bitflip = (XXH_readLE32(secret) ^ + XXH_readLE32(secret + 4)) + seed; + + ulong keyed = (ulong)combined ^ bitflip; + return XXH64_avalanche(keyed); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_len_17to128_64b(byte* input, int len, byte* secret, int secretSize, ulong seed) + { + ulong acc = ((ulong)len) * XXH_PRIME64_1; + + if (len > 32) + { + if (len > 64) + { + if (len > 96) + { + acc += XXH3_mix16B(input + 48, secret + 96, seed); + acc += XXH3_mix16B(input + len - 64, secret + 112, seed); + } + acc += XXH3_mix16B(input + 32, secret + 64, seed); + acc += XXH3_mix16B(input + len - 48, secret + 80, seed); + } + acc += XXH3_mix16B(input + 16, secret + 32, seed); + acc += XXH3_mix16B(input + len - 32, secret + 48, seed); + } + + acc += XXH3_mix16B(input + 0, secret + 0, seed); + acc += XXH3_mix16B(input + len - 16, secret + 16, seed); + return XXH3_avalanche(acc); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_mix16B(byte* input, byte* secret, ulong seed64) + { + ulong input_lo = XXH_readLE64(input); + ulong input_hi = XXH_readLE64(input + 8); + + return XXH3_mul128_fold64( + input_lo ^ (XXH_readLE64(secret) + seed64), + input_hi ^ (XXH_readLE64(secret + 8) - seed64) + ); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_len_129to240_64b(byte* input, int len, byte* secret, int secretSize, + ulong seed) + { + ulong acc = ((ulong) len) * XXH_PRIME64_1; + int nbRounds = len / 16; + + for (int i = 0; i < 8; i++) + { + acc += XXH3_mix16B(input + (16 * i), secret + (16 * i), seed); + } + acc = XXH3_avalanche(acc); + + for (int i = 8; i < nbRounds; i++) + { + acc += XXH3_mix16B(input + (16 * i), secret + (16 * (i - 8)) + XXH3_MIDSIZE_STARTOFFSET, seed); + } + + acc += XXH3_mix16B(input + len - 16, secret + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET, seed); + return XXH3_avalanche(acc); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_hashLong_64b_withSeed(byte* input, int len, ulong seed, byte* secret, + int secretSize) + { + if (seed == 0) + return XXH3_hashLong_64b_internal(input, len, secret, secretSize); + + byte* customSecret = stackalloc byte[XXH3_SECRET_DEFAULT_SIZE]; + + XXH3_initCustomSecret(customSecret, seed); + + return XXH3_hashLong_64b_internal(input, len, customSecret, XXH3_SECRET_DEFAULT_SIZE); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_initCustomSecret(byte* customSecret, ulong seed) + { + XXH3_initCustomSecret_scalar(customSecret, seed); + } + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_initCustomSecret_scalar(byte* customSecret, ulong seed) + { + fixed (byte* kSecretPtr = &XXH3_SECRET[0]) + { + int nbRounds = XXH_SECRET_DEFAULT_SIZE / 16; + + for (int i = 0; i < nbRounds; i++) + { + ulong lo = XXH_readLE64(kSecretPtr + 16 * i) + seed; + ulong hi = XXH_readLE64(kSecretPtr + 16 * i + 8) - seed; + XXH_writeLE64((byte*) customSecret + 16 * i, lo); + XXH_writeLE64((byte*) customSecret + 16 * i + 8, hi); + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_hashLong_64b_internal(byte* input, int len, byte* secret, int secretSize) + { + fixed (ulong* src = &XXH3_INIT_ACC[0]) + { + ulong* acc = stackalloc ulong[8] + { + *(src + 0), + *(src + 1), + *(src + 2), + *(src + 3), + *(src + 4), + *(src + 5), + *(src + 6), + *(src + 7), + }; + + XXH3_hashLong_internal_loop(acc, input, len, secret, secretSize); + + return XXH3_mergeAccs(acc, secret + XXH_SECRET_MERGEACCS_START, ((ulong)len) * XXH_PRIME64_1); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_mergeAccs(ulong* acc, byte* secret, ulong start) + { + ulong result64 = start; + + for (int i = 0; i < 4; i++) + result64 += XXH3_mix2Accs(acc + 2 * i, secret + 16 * i); + + return XXH3_avalanche(result64); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH3_mix2Accs(ulong* acc, byte* secret) + { + return XXH3_mul128_fold64( + acc[0] ^ XXH_readLE64(secret), + acc[1] ^ XXH_readLE64(secret + 8)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_hashLong_internal_loop(ulong* acc, byte* input, int len, byte* secret, + int secretSize) + { + int nbStripesPerBlock = (secretSize - XXH_STRIPE_LEN) / XXH_SECRET_CONSUME_RATE; + int block_len = XXH_STRIPE_LEN * nbStripesPerBlock; + int nb_blocks = (len - 1) / block_len; + + for (int n = 0; n < nb_blocks; n++) + { + XXH3_accumulate(acc, input + n * block_len, secret, nbStripesPerBlock); + XXH3_scrambleAcc(acc, secret + secretSize - XXH_STRIPE_LEN); + } + + int nbStripes = ((len - 1) - (block_len * nb_blocks)) / XXH_STRIPE_LEN; + XXH3_accumulate(acc, input + nb_blocks * block_len, secret, nbStripes); + + byte* p = input + len - XXH_STRIPE_LEN; + XXH3_accumulate_512(acc, p, secret + secretSize - XXH_STRIPE_LEN - XXH_SECRET_LASTACC_START); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_accumulate(ulong* acc, byte* input, byte* secret, int nbStripes) + { + for (int n = 0; n < nbStripes; n++) + { + byte* inp = input + n * XXH_STRIPE_LEN; + XXH3_accumulate_512(acc, inp, secret + n * XXH_SECRET_CONSUME_RATE); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_accumulate_512(ulong* acc, byte* input, byte* secret) + { + XXH3_accumulate_512_scalar(acc, input, secret); + + } + + + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_accumulate_512_scalar(ulong* acc, byte* input, byte* secret) + { + for (int i = 0; i < XXH_ACC_NB; i++) + XXH3_scalarRound(acc, input, secret, i); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_scalarRound(ulong* acc, byte* input, byte* secret, int lane) + { + ulong* xacc = acc; + byte* xinput = input; + byte* xsecret = secret; + + ulong data_val = XXH_readLE64(xinput + lane * 8); + ulong data_key = data_val ^ XXH_readLE64(xsecret + lane * 8); + xacc[lane ^ 1] += data_val; + xacc[lane] += XXH_mult32to64(data_key & 0xFFFFFFFF, data_key >> 32); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_scrambleAcc(ulong* acc, byte* secret) + { + XXH3_scrambleAcc_scalar(acc, secret); + + } + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_scrambleAcc_scalar(ulong* acc, byte* secret) + { + for (int i = 0; i < XXH_ACC_NB; i++) + XXH3_scalarScrambleRound(acc, secret, i); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe void XXH3_scalarScrambleRound(ulong* acc, byte* secret, int lane) + { + ulong* xacc = acc; + byte* xsecret = secret; + + ulong key64 = XXH_readLE64(xsecret + lane * 8); + ulong acc64 = xacc[lane]; + acc64 = XXH_xorshift64(acc64, 47); + acc64 ^= key64; + acc64 *= XXH_PRIME32_1; + xacc[lane] = acc64; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH3.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH3.cs.meta new file mode 100644 index 0000000..4b9f844 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH3.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 04c10c3dcad63224fab3244c585bc4e4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH64.cs b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH64.cs new file mode 100644 index 0000000..4450c06 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH64.cs @@ -0,0 +1,20 @@ +// ReSharper disable InconsistentNaming + +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash3 + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH64_avalanche(ulong hash) + { + hash ^= hash >> 33; + hash *= XXH_PRIME64_2; + hash ^= hash >> 29; + hash *= XXH_PRIME64_3; + hash ^= hash >> 32; + return hash; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH64.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH64.cs.meta new file mode 100644 index 0000000..5c8eadb --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash3.XXH64.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6b73a0fcfb28bb44b8d7ce7bb03436a0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash3.cs b/Assets/YooAsset/Runtime/xxHash/xxHash3.cs new file mode 100644 index 0000000..6f27344 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash3.cs @@ -0,0 +1,96 @@ +// ReSharper disable InconsistentNaming + +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash3 + { + /// + /// Compute xxHash for the data byte array + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe ulong ComputeHash(byte[] data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* ptr = &data[0]) + { + return UnsafeComputeHash(ptr, length, seed); + } + } + + /// + /// Compute xxHash for the data byte span + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe ulong ComputeHash(Span data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* ptr = &data[0]) + { + return UnsafeComputeHash(ptr, length, seed); + } + } + + /// + /// Compute xxHash for the data byte span + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe ulong ComputeHash(ReadOnlySpan data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* ptr = &data[0]) + { + return UnsafeComputeHash(ptr, length, seed); + } + } + + /// + /// Compute xxHash for the string + /// + /// The source of data + /// The seed number + /// hash + public static unsafe ulong ComputeHash(string unicode, ulong seed = 0) + { + Debug.Assert(unicode != null); + + fixed (char* c = unicode) + { + byte* ptr = (byte*) c; + int length = unicode.Length * 2; + + return UnsafeComputeHash(ptr, length, seed); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong UnsafeComputeHash(byte* input, int len, ulong seed) + { + fixed (byte* secret = &XXH3_SECRET[0]) + { + return XXH3_64bits_internal(input, len, seed, secret, XXH3_SECRET_DEFAULT_SIZE); + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash3.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash3.cs.meta new file mode 100644 index 0000000..fa30d22 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash3.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a61e53921f712184a91693b7937b53fb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH.cs b/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH.cs new file mode 100644 index 0000000..631fd74 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH.cs @@ -0,0 +1,21 @@ +// ReSharper disable InconsistentNaming + +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash32 + { + private static readonly uint XXH_PRIME32_1 = 2654435761U; + private static readonly uint XXH_PRIME32_2 = 2246822519U; + private static readonly uint XXH_PRIME32_3 = 3266489917U; + private static readonly uint XXH_PRIME32_4 = 668265263U; + private static readonly uint XXH_PRIME32_5 = 374761393U; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint XXH_rotl32(uint x, int r) + { + return (x << r) | (x >> (32 - r)); + } + } +} diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH.cs.meta new file mode 100644 index 0000000..1364459 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1c5bf48410ae0d74f8803b0b407b8af5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH32.cs b/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH32.cs new file mode 100644 index 0000000..1ca5c9c --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH32.cs @@ -0,0 +1,90 @@ +// ReSharper disable InconsistentNaming + +namespace Standart.Hash.xxHash +{ + using System.Runtime.CompilerServices; + + public static partial class xxHash32 + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint XXH32(byte* input, int len, uint seed) + { + uint h32; + + if (len >= 16) + { + byte* end = input + len; + byte* limit = end - 15; + + uint v1 = seed + XXH_PRIME32_1 + XXH_PRIME32_2; + uint v2 = seed + XXH_PRIME32_2; + uint v3 = seed + 0; + uint v4 = seed - XXH_PRIME32_1; + + do + { + v1 = XXH32_round(v1, *(uint*) input); input += 4; + v2 = XXH32_round(v2, *(uint*) input); input += 4; + v3 = XXH32_round(v3, *(uint*) input); input += 4; + v4 = XXH32_round(v4, *(uint*) input); input += 4; + } while (input < limit); + + h32 = XXH_rotl32(v1, 1) + + XXH_rotl32(v2, 7) + + XXH_rotl32(v3, 12) + + XXH_rotl32(v4, 18); + } + else + { + h32 = seed + XXH_PRIME32_5; + } + + h32 += (uint)len; + + return XXH32_finalize(h32, input, len); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint XXH32_round(uint acc, uint input) + { + acc += input * XXH_PRIME32_2; + acc = XXH_rotl32(acc, 13); + acc *= XXH_PRIME32_1; + return acc; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static uint XXH32_avalanche(uint hash) + { + hash ^= hash >> 15; + hash *= XXH_PRIME32_2; + hash ^= hash >> 13; + hash *= XXH_PRIME32_3; + hash ^= hash >> 16; + return hash; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint XXH32_finalize(uint hash, byte* ptr, int len) + { + len &= 15; + while (len >= 4) + { + hash += *((uint*)ptr) * XXH_PRIME32_3; + ptr += 4; + hash = XXH_rotl32(hash, 17) * XXH_PRIME32_4; + len -= 4; + } + + while (len > 0) + { + hash += *((byte*)ptr) * XXH_PRIME32_5; + ptr++; + hash = XXH_rotl32(hash, 11) * XXH_PRIME32_1; + len--; + } + + return XXH32_avalanche(hash); + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH32.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH32.cs.meta new file mode 100644 index 0000000..10e2691 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash32.XXH32.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 72917bf63cde5cb4a83abbbf562a684a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash32.cs b/Assets/YooAsset/Runtime/xxHash/xxHash32.cs new file mode 100644 index 0000000..e0c4653 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash32.cs @@ -0,0 +1,265 @@ +// ReSharper disable InconsistentNaming + +using System; +using System.Buffers; +using System.Diagnostics; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash32 + { + /// + /// Compute xxHash for the data byte array + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe uint ComputeHash(byte[] data, int length, uint seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* pData = &data[0]) + { + return UnsafeComputeHash(pData, length, seed); + } + } + + /// + /// Compute xxHash for the data byte array + /// + /// The source of data + /// The offset of the data for hashing + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe uint ComputeHash(byte[] data, int offset, int length, uint seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(offset < data.Length); + Debug.Assert(length <= data.Length - offset); + + fixed (byte* pData = &data[0 + offset]) + { + return UnsafeComputeHash(pData, length, seed); + } + } + + /// + /// Compute xxHash for the data byte array + /// + /// The source of data + /// The seed number + /// hash + public static ulong ComputeHash(ArraySegment data, uint seed = 0) + { + Debug.Assert(data != null); + + return ComputeHash(data.Array, data.Offset, data.Count, seed); + } + + /// + /// Compute xxHash for the async stream + /// + /// The stream of data + /// The buffer size + /// The seed number + /// The hash + public static async ValueTask ComputeHashAsync(Stream stream, int bufferSize = 4096, uint seed = 0) + { + return await ComputeHashAsync(stream, bufferSize, seed, CancellationToken.None); + } + + /// + /// Compute xxHash for the async stream + /// + /// The stream of data + /// The buffer size + /// The seed number + /// The cancellation token + /// The hash + public static async ValueTask ComputeHashAsync(Stream stream, int bufferSize, uint seed, CancellationToken cancellationToken) + { + Debug.Assert(stream != null); + Debug.Assert(bufferSize > 16); + + // Optimizing memory allocation + byte[] buffer = ArrayPool.Shared.Rent(bufferSize + 16); + + int readBytes; + int offset = 0; + long length = 0; + + // Prepare the seed vector + uint v1 = seed + XXH_PRIME32_1 + XXH_PRIME32_2; + uint v2 = seed + XXH_PRIME32_2; + uint v3 = seed + 0; + uint v4 = seed - XXH_PRIME32_1; + + try + { + // Read flow of bytes + while ((readBytes = + await stream.ReadAsync(buffer, offset, bufferSize, cancellationToken).ConfigureAwait(false)) > 0) + { + length = length + readBytes; + offset = offset + readBytes; + + if (offset < 16) continue; + + int r = offset % 16; // remain + int l = offset - r; // length + + // Process the next chunk + __inline__XXH32_stream_process(buffer, l, ref v1, ref v2, ref v3, ref v4); + + // Put remaining bytes to buffer + Utils.BlockCopy(buffer, l, buffer, 0, r); + offset = r; + } + + // Process the final chunk + uint h32 = __inline__XXH32_stream_finalize(buffer, offset, ref v1, ref v2, ref v3, ref v4, length, seed); + + return h32; + } + finally + { + // Free memory + ArrayPool.Shared.Return(buffer); + } + } + + /// + /// Compute xxHash for the data byte span + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe uint ComputeHash(Span data, int length, uint seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* pData = &MemoryMarshal.GetReference(data)) + { + return UnsafeComputeHash(pData, length, seed); + } + } + + /// + /// Compute xxHash for the data byte span + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe uint ComputeHash(ReadOnlySpan data, int length, uint seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* pData = &MemoryMarshal.GetReference(data)) + { + return UnsafeComputeHash(pData, length, seed); + } + } + + /// + /// Compute xxHash for the stream + /// + /// The stream of data + /// The buffer size + /// The seed number + /// The hash + public static uint ComputeHash(Stream stream, int bufferSize = 4096, uint seed = 0) + { + Debug.Assert(stream != null); + Debug.Assert(bufferSize > 16); + + // Optimizing memory allocation + byte[] buffer = ArrayPool.Shared.Rent(bufferSize + 16); + + int readBytes; + int offset = 0; + long length = 0; + + // Prepare the seed vector + uint v1 = seed + XXH_PRIME32_1 + XXH_PRIME32_2; + uint v2 = seed + XXH_PRIME32_2; + uint v3 = seed + 0; + uint v4 = seed - XXH_PRIME32_1; + + try + { + // Read flow of bytes + while ((readBytes = stream.Read(buffer, offset, bufferSize)) > 0) + { + length = length + readBytes; + offset = offset + readBytes; + + if (offset < 16) continue; + + int r = offset % 16; // remain + int l = offset - r; // length + + // Process the next chunk + __inline__XXH32_stream_process(buffer, l, ref v1, ref v2, ref v3, ref v4); + + // Put remaining bytes to buffer + Utils.BlockCopy(buffer, l, buffer, 0, r); + offset = r; + } + + // Process the last chunk + uint h32 = __inline__XXH32_stream_finalize(buffer, offset, ref v1, ref v2, ref v3, ref v4, length, seed); + + return h32; + } + finally + { + // Free memory + ArrayPool.Shared.Return(buffer); + } + } + + /// + /// Compute xxHash for the string + /// + /// The source of data + /// The seed number + /// hash + public static unsafe uint ComputeHash(string str, uint seed = 0) + { + Debug.Assert(str != null); + + fixed (char* c = str) + { + byte* ptr = (byte*) c; + int length = str.Length * 2; + + return UnsafeComputeHash(ptr, length, seed); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe uint UnsafeComputeHash(byte* ptr, int length, uint seed) + { + // Use inlined version + // return XXH32(ptr, length, seed); + + return __inline__XXH32(ptr, length, seed); + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash32.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash32.cs.meta new file mode 100644 index 0000000..7dd9481 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash32.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 877a8f61386aaf044bb5b0876d759d3e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH.cs b/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH.cs new file mode 100644 index 0000000..dafbed8 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH.cs @@ -0,0 +1,21 @@ +// ReSharper disable InconsistentNaming + +using System.Runtime.CompilerServices; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash64 + { + private static readonly ulong XXH_PRIME64_1 = 11400714785074694791UL; + private static readonly ulong XXH_PRIME64_2 = 14029467366897019727UL; + private static readonly ulong XXH_PRIME64_3 = 1609587929392839161UL; + private static readonly ulong XXH_PRIME64_4 = 9650029242287828579UL; + private static readonly ulong XXH_PRIME64_5 = 2870177450012600261UL; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH_rotl64(ulong x, int r) + { + return (x << r) | (x >> (64 - r)); + } + } +} diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH.cs.meta new file mode 100644 index 0000000..47ee835 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 519eafbf3455e3c4e8a3cee3051367ad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH64.cs b/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH64.cs new file mode 100644 index 0000000..5c04f8f --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH64.cs @@ -0,0 +1,106 @@ +// ReSharper disable InconsistentNaming + +namespace Standart.Hash.xxHash +{ + using System.Runtime.CompilerServices; + + public static partial class xxHash64 + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH64(byte* input, int len, ulong seed) + { + ulong h64; + + if (len >= 32) + { + byte* end = input + len; + byte* limit = end - 31; + + ulong v1 = seed + XXH_PRIME64_1 + XXH_PRIME64_2; + ulong v2 = seed + XXH_PRIME64_2; + ulong v3 = seed + 0; + ulong v4 = seed - XXH_PRIME64_1; + + do + { + v1 = XXH64_round(v1, *(ulong*) input); input += 8; + v2 = XXH64_round(v2, *(ulong*) input); input += 8; + v3 = XXH64_round(v3, *(ulong*) input); input += 8; + v4 = XXH64_round(v4, *(ulong*) input); input += 8; + } while (input < limit); + + h64 = XXH_rotl64(v1, 1) + + XXH_rotl64(v2, 7) + + XXH_rotl64(v3, 12) + + XXH_rotl64(v4, 18); + + h64 = XXH64_mergeRound(h64, v1); + h64 = XXH64_mergeRound(h64, v2); + h64 = XXH64_mergeRound(h64, v3); + h64 = XXH64_mergeRound(h64, v4); + } + else + { + h64 = seed + XXH_PRIME64_5; + } + + h64 += (ulong)len; + + return XXH64_finalize(h64, input, len); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH64_round(ulong acc, ulong input) + { + acc += input * XXH_PRIME64_2; + acc = XXH_rotl64(acc, 31); + acc *= XXH_PRIME64_1; + return acc; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH64_mergeRound(ulong acc, ulong val) + { + val = XXH64_round(0, val); + acc ^= val; + acc = acc * XXH_PRIME64_1 + XXH_PRIME64_4; + return acc; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong XXH64_avalanche(ulong hash) + { + hash ^= hash >> 33; + hash *= XXH_PRIME64_2; + hash ^= hash >> 29; + hash *= XXH_PRIME64_3; + hash ^= hash >> 32; + return hash; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong XXH64_finalize(ulong hash, byte* ptr, int len) + { + len &= 31; + while (len >= 8) { + ulong k1 = XXH64_round(0, *(ulong*)ptr); + ptr += 8; + hash ^= k1; + hash = XXH_rotl64(hash,27) * XXH_PRIME64_1 + XXH_PRIME64_4; + len -= 8; + } + if (len >= 4) { + hash ^= *(uint*)ptr * XXH_PRIME64_1; + ptr += 4; + hash = XXH_rotl64(hash, 23) * XXH_PRIME64_2 + XXH_PRIME64_3; + len -= 4; + } + while (len > 0) { + hash ^= (*ptr++) * XXH_PRIME64_5; + hash = XXH_rotl64(hash, 11) * XXH_PRIME64_1; + --len; + } + return XXH64_avalanche(hash); + } + } +} diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH64.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH64.cs.meta new file mode 100644 index 0000000..1260ef3 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash64.XXH64.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fd708be04cb928d4d8b419a27144213e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash64.cs b/Assets/YooAsset/Runtime/xxHash/xxHash64.cs new file mode 100644 index 0000000..671a3bc --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash64.cs @@ -0,0 +1,266 @@ +// ReSharper disable InconsistentNaming + +using System; +using System.Buffers; +using System.Diagnostics; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; + +namespace Standart.Hash.xxHash +{ + public static partial class xxHash64 + { + /// + /// Compute xxHash for the data byte array + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe ulong ComputeHash(byte[] data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* pData = &data[0]) + { + return UnsafeComputeHash(pData, length, seed); + } + } + + /// + /// Compute xxHash for the data byte array + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe ulong ComputeHash(byte[] data, int offset, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(offset < data.Length); + Debug.Assert(length <= data.Length - offset); + + fixed (byte* pData = &data[0 + offset]) + { + return UnsafeComputeHash(pData, length, seed); + } + } + + /// + /// Compute xxHash for the data byte array + /// + /// The source of data + /// The seed number + /// hash + public static unsafe ulong ComputeHash(System.ArraySegment data, ulong seed = 0) + { + Debug.Assert(data != null); + + return ComputeHash(data.Array, data.Offset, data.Count, seed); + } + + /// + /// Compute xxHash for the async stream + /// + /// The stream of data + /// The buffer size + /// The seed number + /// The hash + public static async ValueTask ComputeHashAsync(Stream stream, int bufferSize = 8192, ulong seed = 0) + { + return await ComputeHashAsync(stream, bufferSize, seed, CancellationToken.None); + } + + /// + /// Compute xxHash for the async stream + /// + /// The stream of data + /// The buffer size + /// The seed number + /// The cancelation token + /// The hash + public static async ValueTask ComputeHashAsync(Stream stream, int bufferSize, ulong seed, + CancellationToken cancellationToken) + { + Debug.Assert(stream != null); + Debug.Assert(bufferSize > 32); + + // Optimizing memory allocation + byte[] buffer = ArrayPool.Shared.Rent(bufferSize + 32); + + int readBytes; + int offset = 0; + long length = 0; + + // Prepare the seed vector + ulong v1 = seed + XXH_PRIME64_1 + XXH_PRIME64_2; + ulong v2 = seed + XXH_PRIME64_2; + ulong v3 = seed + 0; + ulong v4 = seed - XXH_PRIME64_1; + + try + { + // Read flow of bytes + while ((readBytes = + await stream.ReadAsync(buffer, offset, bufferSize, cancellationToken).ConfigureAwait(false)) > 0) + { + length = length + readBytes; + offset = offset + readBytes; + + if (offset < 32) continue; + + int r = offset % 32; // remain + int l = offset - r; // length + + // Process the next chunk + __inline__XXH64_stream_process(buffer, l, ref v1, ref v2, ref v3, ref v4); + + // Put remaining bytes to buffer + Utils.BlockCopy(buffer, l, buffer, 0, r); + offset = r; + } + + // Process the final chunk + ulong h64 = __inline__XXH64_stream_finalize(buffer, offset, ref v1, ref v2, ref v3, ref v4, length, seed); + + return h64; + } + finally + { + // Free memory + ArrayPool.Shared.Return(buffer); + } + } + + /// + /// Compute xxHash for the data byte span + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe ulong ComputeHash(Span data, int length, ulong seed = 0) + { + //Debug.Assert(data != null); + //Debug.Assert(length >= 0); + //Debug.Assert(length <= data.Length); + + fixed (byte* pData = &MemoryMarshal.GetReference(data)) + { + return UnsafeComputeHash(pData, length, seed); + } + } + + /// + /// Compute xxHash for the data byte span + /// + /// The source of data + /// The length of the data for hashing + /// The seed number + /// hash + public static unsafe ulong ComputeHash(ReadOnlySpan data, int length, ulong seed = 0) + { + Debug.Assert(data != null); + Debug.Assert(length >= 0); + Debug.Assert(length <= data.Length); + + fixed (byte* pData = &MemoryMarshal.GetReference(data)) + { + return UnsafeComputeHash(pData, length, seed); + } + } + + /// + /// Compute xxHash for the stream + /// + /// The stream of data + /// The buffer size + /// The seed number + /// The hash + public static ulong ComputeHash(Stream stream, int bufferSize = 8192, ulong seed = 0) + { + Debug.Assert(stream != null); + Debug.Assert(bufferSize > 32); + + // Optimizing memory allocation + byte[] buffer = ArrayPool.Shared.Rent(bufferSize + 32); + + int readBytes; + int offset = 0; + long length = 0; + + // Prepare the seed vector + ulong v1 = seed + XXH_PRIME64_1 + XXH_PRIME64_2; + ulong v2 = seed + XXH_PRIME64_2; + ulong v3 = seed + 0; + ulong v4 = seed - XXH_PRIME64_1; + + try + { + // Read flow of bytes + while ((readBytes = stream.Read(buffer, offset, bufferSize)) > 0) + { + length = length + readBytes; + offset = offset + readBytes; + + if (offset < 32) continue; + + int r = offset % 32; // remain + int l = offset - r; // length + + // Process the next chunk + __inline__XXH64_stream_process(buffer, l, ref v1, ref v2, ref v3, ref v4); + + // Put remaining bytes to buffer + Utils.BlockCopy(buffer, l, buffer, 0, r); + offset = r; + } + + // Process the final chunk + ulong h64 = __inline__XXH64_stream_finalize(buffer, offset, ref v1, ref v2, ref v3, ref v4, length, seed); + + return h64; + } + finally + { + // Free memory + ArrayPool.Shared.Return(buffer); + } + } + + /// + /// Compute xxHash for the string + /// + /// The source of data + /// The seed number + /// hash + public static unsafe ulong ComputeHash(string str, uint seed = 0) + { + Debug.Assert(str != null); + + fixed (char* c = str) + { + byte* ptr = (byte*) c; + int length = str.Length * 2; + + return UnsafeComputeHash(ptr, length, seed); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static unsafe ulong UnsafeComputeHash(byte* ptr, int length, ulong seed) + { + // Use inlined version + // return XXH64(ptr, length, seed); + + return __inline__XXH64(ptr, length, seed); + } + } +} + diff --git a/Assets/YooAsset/Runtime/xxHash/xxHash64.cs.meta b/Assets/YooAsset/Runtime/xxHash/xxHash64.cs.meta new file mode 100644 index 0000000..9c31ef9 --- /dev/null +++ b/Assets/YooAsset/Runtime/xxHash/xxHash64.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2ca6cc6a152389145bc1ef4f745d636e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: