L4 map use no sync fast route when enouge predict ahead

This commit is contained in:
Youmu Liu
2026-10-13 18:14:16 +08:00
parent b7f1d3d2ba
commit 6bc7224d4c
8 changed files with 39 additions and 51 deletions
+4 -4
View File
@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2024 Nitload StgSharp Team Copyright (c) 2024 Nitload
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@@ -20,9 +20,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
StgSharp program uses the following open source projects, The nFramework project uses the following open-source projects.
I'd like to refer to them here and show my sincere appreciation, Their respective license notices are reproduced below,
while the names are sorted in no particular order and the projects are listed in no particular order.
1. GLFW 1. GLFW
+1 -1
View File
@@ -11,7 +11,7 @@
<projectUrl>https://github.com/Nitload-NSI/StgSharp</projectUrl> <projectUrl>https://github.com/Nitload-NSI/StgSharp</projectUrl>
<description>No des right now</description> <description>No des right now</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes> <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Nitload reserve</copyright> <copyright>Copyright (c) 2024 Nitload</copyright>
<tags>OpenGL C#</tags> <tags>OpenGL C#</tags>
</metadata> </metadata>
<files> <files>
+11
View File
@@ -0,0 +1,11 @@
# nFramework Icon
`nFramework-icon.svg` is the icon-only version of the nFramework mark.
Copyright (c) 2026 Nitload.
The artwork in this directory is licensed under the [Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License (CC BY-NC-ND 4.0)](https://creativecommons.org/licenses/by-nc-nd/4.0/).
You may copy and redistribute the unmodified artwork for noncommercial purposes when you give appropriate credit and link to the license. This license does not permit distributing adaptations, and it does not grant permission for commercial use. Contact the copyright holder for other permissions.
The repository's root MIT License applies to software, not the artwork in this directory. This copyright license does not grant trademark rights in the Nitload or nFramework names or marks, including the former StgSharp name, or imply endorsement.
+11
View File
@@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="104" viewBox="0 0 128 104" role="img" aria-labelledby="title desc">
<title id="title">nFramework icon</title>
<desc id="desc">The geometric nFramework mark, with a diagonal slash suggesting an N.</desc>
<metadata>Copyright (c) 2026 Nitload. Licensed under CC BY-NC-ND 4.0: https://creativecommons.org/licenses/by-nc-nd/4.0/</metadata>
<g fill="#59B2DA" transform="translate(13.6 13.6) scale(0.8)">
<polygon points="8,8 31,8 31,20 20,20 20,76 31,76 31,88 8,88" />
<polygon points="97,8 120,8 120,88 97,88 97,76 108,76 108,20 97,20" />
<polygon points="40,16 53,16 53,45 40,45" />
<circle cx="80" cy="76" r="8" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 709 B

@@ -35,11 +35,16 @@ namespace Nitload.Common.HighPerformance.Memory
{ {
try try
{ {
Predict(); int effectivePredictionCount = Predict();
_ = Interlocked.Exchange(ref _swiss_swap_lock, 1); if (effectivePredictionCount > 0)
while (Volatile.Read(ref _swiss_reader_counter) != 0) { } {
_ = Interlocked.Exchange(ref _swiss_swap_lock, 1);
while (Volatile.Read(ref _swiss_reader_counter) != 0) { }
_addressMap.SwapBuffers();
Volatile.Write(ref _predict_count, effectivePredictionCount);
}
_addressMap.SwapBuffers();
if (_addressMap.TryGet(source, out handle)) { if (_addressMap.TryGet(source, out handle)) {
throw new InvalidOperationException($"Unexpected map request: [address source: 0x{source.Address:x16}; layout profile: {source.Description:x16}]."); throw new InvalidOperationException($"Unexpected map request: [address source: 0x{source.Address:x16}; layout profile: {source.Description:x16}].");
} }
@@ -52,7 +57,7 @@ namespace Nitload.Common.HighPerformance.Memory
} else if (!TryGetAddress(source, out handle)) { } else if (!TryGetAddress(source, out handle)) {
throw new InvalidOperationException($"Unexpected map request: [address source: 0x{source.Address:x16}; layout profile: {source.Description:x16}]."); throw new InvalidOperationException($"Unexpected map request: [address source: 0x{source.Address:x16}; layout profile: {source.Description:x16}].");
} }
} else if (!TryGetAddress(source, out handle)) { } else if (!_addressMap.TryGet(source, out handle)) {
throw new InvalidOperationException($"Unexpected map request: [address source: 0x{source.Address:x16}; layout profile: {source.Description:x16}]."); throw new InvalidOperationException($"Unexpected map request: [address source: 0x{source.Address:x16}; layout profile: {source.Description:x16}].");
} }
@@ -16,7 +16,7 @@ namespace Nitload.Common.HighPerformance.Memory
public unsafe partial class L4 public unsafe partial class L4
{ {
internal partial void Predict() { } internal partial int Predict() => 0;
} }
} }
@@ -81,7 +81,7 @@ namespace Nitload.Common.HighPerformance.Memory
return _bufferAllocator.TryAlloc(size, out handle); return _bufferAllocator.TryAlloc(size, out handle);
} }
internal partial void Predict(); internal partial int Predict();
} }
} }
@@ -1,39 +0,0 @@
#ifndef NIF_NATIVE_H
#define NIF_NATIVE_H
#ifdef __cplusplus
#error "This header is not meant to be included in C++ code. Nitload.Native is a C library and should be used with C linkage."
#endif
#include "nif_internal.h"
#include "nif_target.h"
#include <immintrin.h>
#include <assert.h>
#include <glfw_function.h>
#define byte char
#define cs_char uint16_t
#define nif_null_assert(ptr) assert(ptr != NULL)
#ifndef NIF_
#endif
NIF_API void NIF_DECL nif_load_glfw_functions(GLFWFunctionTable *table);
NIF_API void NIF_DECL nif_load_intrinsic_function(void *intrinsic_context, uint64_t id);
NIF_API SIMDID NIF_DECL nif_get_simd_level_global();
/* Per-core variant: always re-executes CPUID, never caches.
* Must be called on the target core (after affinity is set). */
NIF_API SIMDID NIF_DECL nif_get_simd_level_local();
NIF_API SIMDID NIF_DECL nif_get_unite_simd(SIMDID left, SIMDID right);
NIF_API int NIF_DECL nif_compare_simd(SIMDID left, SIMDID right);
NIF_API void NIF_DECL nif_set_thread_affinity(int cpu_index, int processor_group_id);
NIF_API void* NIF_DECL nif_numa_alloc(size_t size, int numa_id);
NIF_API void NIF_DECL nif_numa_free(void *ptr, size_t size, int numa_id);
NIF_API int NIF_DECL nif_get_numa_each(int numa_id,
uint32_t *processor_group_ids,
uint32_t *socket_ids,
uint32_t *cpu_indices,
uint32_t *numa_node_ids);
NIF_API int NIF_DECL nif_get_numa_overall(int *out_numa_count, int *count_of_each_numa);
#endif