Compare commits
16
Commits
0cef5aa517
...
6bc7224d4c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bc7224d4c | ||
|
|
b7f1d3d2ba
|
||
|
|
76a9dfa5af
|
||
|
|
2bef14493f
|
||
|
|
ddd83b1b05 | ||
|
|
e24efd9f9c
|
||
|
|
9fc23c29fb
|
||
|
|
3d1d475e25
|
||
|
|
7a820261cf
|
||
|
|
fa1186cd25
|
||
|
|
e49b14f037
|
||
|
|
052afa1dd4
|
||
|
|
1d3d3c10dd
|
||
|
|
902be141d0
|
||
|
|
b5b7c75b5e
|
||
|
|
aa7394503e |
+1
-1
@@ -29,7 +29,7 @@ build.ninja
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# Khronos OpenGL Registry input is supplied locally; keep only its instructions.
|
||||
/tools/Nitload.GenerateGL/xml/*
|
||||
/tools/*GenerateGL/xml/*
|
||||
!/tools/Nitload.GenerateGL/xml/README.md
|
||||
|
||||
/src/Nitload.Native/lib/*
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<NativeCMakeBuildDir Condition="'$(NativeCMakeBuildDir)'==''">$(SolutionRoot)cmake_build/$(NativeCMakePreset)</NativeCMakeBuildDir>
|
||||
<_NativeCMakeOutputDir>$([System.String]::Copy('$(NativeBuildDir)').Replace('\', '/'))</_NativeCMakeOutputDir>
|
||||
</PropertyGroup>
|
||||
<Exec Command="cmake --preset "$(NativeCMakePreset)" -S "$(SolutionRoot)src/Nitload.Native" -B "$(NativeCMakeBuildDir)" "-DNIF_BUILD_OUTPUT_DIR:PATH=$(_NativeCMakeOutputDir)" "-DNIF_EXPECTED_RID:STRING=$(BuildRid)"" />
|
||||
<Exec Command="cmake --preset "$(NativeCMakePreset)" -S "$(SolutionRoot)src/Nitload.Native" -B "$(NativeCMakeBuildDir)" "-DNFN_BUILD_OUTPUT_DIR:PATH=$(_NativeCMakeOutputDir)" "-DNFN_EXPECTED_RID:STRING=$(BuildRid)"" />
|
||||
<Exec Command="cmake --build "$(NativeCMakeBuildDir)" --target "$(NativeLibName)"" />
|
||||
<Error Condition="!Exists('$(NativeBuildDir)$(NativeFileName)')"
|
||||
Text="CMake did not produce the expected native library: $(NativeBuildDir)$(NativeFileName). Check the target OS, architecture and output name." />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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
|
||||
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
|
||||
SOFTWARE.
|
||||
|
||||
StgSharp program uses the following open source projects,
|
||||
I'd like to refer to them here and show my sincere appreciation,
|
||||
while the names are sorted in no particular order
|
||||
The nFramework project uses the following open-source projects.
|
||||
Their respective license notices are reproduced below,
|
||||
and the projects are listed in no particular order.
|
||||
|
||||
1. GLFW
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
<projectUrl>https://github.com/Nitload-NSI/StgSharp</projectUrl>
|
||||
<description>No des right now</description>
|
||||
<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>
|
||||
</metadata>
|
||||
<files>
|
||||
|
||||
@@ -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.
|
||||
@@ -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
|
||||
{
|
||||
Predict();
|
||||
int effectivePredictionCount = Predict();
|
||||
if (effectivePredictionCount > 0)
|
||||
{
|
||||
_ = Interlocked.Exchange(ref _swiss_swap_lock, 1);
|
||||
while (Volatile.Read(ref _swiss_reader_counter) != 0) { }
|
||||
|
||||
_addressMap.SwapBuffers();
|
||||
Volatile.Write(ref _predict_count, effectivePredictionCount);
|
||||
}
|
||||
|
||||
if (_addressMap.TryGet(source, out handle)) {
|
||||
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)) {
|
||||
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}].");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Nitload.Common.HighPerformance.Memory
|
||||
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);
|
||||
}
|
||||
|
||||
internal partial void Predict();
|
||||
internal partial int Predict();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Nitload.Common.HighPerformance.ProcessorAbstraction
|
||||
NumaFreeNative(address, size, numaId);
|
||||
}
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_get_numa_each")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_get_numa_each")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
public static partial int GetNumaEach(
|
||||
@@ -86,7 +86,7 @@ namespace Nitload.Common.HighPerformance.ProcessorAbstraction
|
||||
Span<uint> numaNodeIds
|
||||
);
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_get_numa_overall")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_get_numa_overall")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
public static partial int GetNumaOverall(
|
||||
@@ -136,7 +136,7 @@ namespace Nitload.Common.HighPerformance.ProcessorAbstraction
|
||||
}
|
||||
}
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_set_thread_affinity")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_set_thread_affinity")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
internal static partial void SetThreadAffinity(
|
||||
@@ -170,7 +170,7 @@ namespace Nitload.Common.HighPerformance.ProcessorAbstraction
|
||||
return false;
|
||||
}
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_numa_alloc")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_numa_alloc")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
private static unsafe partial void* NumaAllocNative(
|
||||
@@ -178,7 +178,7 @@ namespace Nitload.Common.HighPerformance.ProcessorAbstraction
|
||||
int numaId
|
||||
);
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_numa_free")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_numa_free")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
private static unsafe partial void NumaFreeNative(
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Nitload.Threading
|
||||
|
||||
#pragma warning disable CA5393
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_set_thread_affinity")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_set_thread_affinity")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
private static partial void SetThreadAffinity(
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Nitload.Graphics
|
||||
|
||||
public static GLFWFunction glfwContext => _glfw;
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_load_glfw_functions")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_load_glfw_functions")]
|
||||
internal static unsafe partial void glfwLoadLibrary(
|
||||
GLFWFunction* context
|
||||
);
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace Nitload.Mathematics.Numeric
|
||||
|
||||
#region C invoke
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_compare_simd")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_compare_simd")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
private static partial int CompareSIMDID(
|
||||
@@ -178,7 +178,7 @@ namespace Nitload.Mathematics.Numeric
|
||||
SIMDID right
|
||||
);
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_load_intrinsic_function")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_load_intrinsic_function")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
private static partial void LoadIntrinsicFunction(
|
||||
@@ -186,7 +186,7 @@ namespace Nitload.Mathematics.Numeric
|
||||
ulong id
|
||||
);
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_get_unite_simd")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_get_unite_simd")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
private static partial SIMDID UniteSIMDID(
|
||||
|
||||
@@ -155,12 +155,12 @@ namespace Nitload.Mathematics.Numeric
|
||||
}
|
||||
|
||||
#pragma warning disable CA5393
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_get_simd_level_local")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_get_simd_level_local")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
internal static partial ulong GetSimdId();
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nif_load_intrinsic_function")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "nfn_load_intrinsic_function")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
|
||||
private static unsafe partial void LoadIntrinsicFunction(
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
CompileFlags:
|
||||
CompilationDatabase: ../..
|
||||
CompilationDatabase: .
|
||||
|
||||
@@ -3,91 +3,91 @@ project(Nitload.Native LANGUAGES C)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/ExternalLibs.cmake OPTIONAL)
|
||||
|
||||
set(NIF_TARGET_OS "auto" CACHE STRING "Target OS identifier: auto, windows, linux, macos, ios, android, unknown")
|
||||
set_property(CACHE NIF_TARGET_OS PROPERTY STRINGS auto windows linux macos ios android unknown)
|
||||
set(NFN_TARGET_OS "auto" CACHE STRING "Target OS identifier: auto, windows, linux, macos, ios, android, unknown")
|
||||
set_property(CACHE NFN_TARGET_OS PROPERTY STRINGS auto windows linux macos ios android unknown)
|
||||
|
||||
set(NIF_TARGET_ARCH "auto" CACHE STRING "Target ISA identifier: auto, x86_64, arm64, riscv64, ppc64le")
|
||||
set_property(CACHE NIF_TARGET_ARCH PROPERTY STRINGS auto x86_64 arm64 riscv64 ppc64le)
|
||||
set(NFN_TARGET_ARCH "auto" CACHE STRING "Target ISA identifier: auto, x86_64, arm64, riscv64, ppc64le")
|
||||
set_property(CACHE NFN_TARGET_ARCH PROPERTY STRINGS auto x86_64 arm64 riscv64 ppc64le)
|
||||
|
||||
nif_resolve_target_identifiers(
|
||||
"${NIF_TARGET_OS}"
|
||||
"${NIF_TARGET_ARCH}"
|
||||
NIF_RESOLVED_OS_NAME
|
||||
NIF_RESOLVED_OS_DEFINE
|
||||
NIF_RESOLVED_ARCH_NAME
|
||||
NIF_RESOLVED_ARCH_DEFINE)
|
||||
nfn_resolve_target_identifiers(
|
||||
"${NFN_TARGET_OS}"
|
||||
"${NFN_TARGET_ARCH}"
|
||||
NFN_RESOLVED_OS_NAME
|
||||
NFN_RESOLVED_OS_DEFINE
|
||||
NFN_RESOLVED_ARCH_NAME
|
||||
NFN_RESOLVED_ARCH_DEFINE)
|
||||
|
||||
set(NIF_NATIVE_SOURCES
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/dllmain.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/load_glfw.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/load_intrinsic.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/m.bufop.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/m.solve.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/m.transpose.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/mk.fma.pack.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/mk.fma.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/mk.p_scan.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/s.factorial.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/s.hash.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/simdid_compare.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/simdid.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/sk.fma.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/thread.linux.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/thread.windows.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/vector.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-src/vector_dot.c)
|
||||
set(NFN_NATIVE_SOURCES
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/dllmain.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/load_glfw.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/load_intrinsic.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/m.bufop.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/m.solve.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/m.transpose.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/mk.fma.pack.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/mk.fma.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/mk.p_scan.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/s.factorial.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/s.hash.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/simdid_compare.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/simdid.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/sk.fma.x86.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/thread.linux.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/thread.windows.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/vector.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-src/vector_dot.c)
|
||||
|
||||
set(NIF_NATIVE_HEADERS
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-head/glfw_function.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-head/nif_internal.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-head/nif_intrinsic.context.base.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-head/nif_intrinsic.context.x86.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-head/nif_intrinsic.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-head/nif_intrinsic.matkernel.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-head/nif_intrinsic.std.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-head/nif_target.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-head/NitloadFrameWork.h)
|
||||
set(NFN_NATIVE_HEADERS
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-head/glfw_function.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-head/nfn_internal.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-head/nfn_intrinsic.context.base.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-head/nfn_intrinsic.context.x86.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-head/nfn_intrinsic.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-head/nfn_intrinsic.matkernel.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-head/nfn_intrinsic.std.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-head/nfn_target.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-head/NitloadFrameWork.h)
|
||||
|
||||
set(NIF_NATIVE_TEMPLATES
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-template/nif_template.fma.x86.h)
|
||||
set(NFN_NATIVE_TEMPLATES
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-template/nfn_template.fma.x86.h)
|
||||
|
||||
# Nitload.Native now lives under <root>/src/Nitload.Native, so walk up two
|
||||
# levels (project dir -> src -> solution root) to reach the solution root.
|
||||
get_filename_component(NIF_NATIVE_SRC_ROOT ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
|
||||
get_filename_component(NIF_SOLUTION_ROOT ${NIF_NATIVE_SRC_ROOT} DIRECTORY)
|
||||
get_filename_component(NFN_NATIVE_SRC_ROOT ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
|
||||
get_filename_component(NFN_SOLUTION_ROOT ${NFN_NATIVE_SRC_ROOT} DIRECTORY)
|
||||
|
||||
if(NIF_RESOLVED_OS_NAME STREQUAL "windows")
|
||||
set(NIF_OS_TAG win)
|
||||
elseif(NIF_RESOLVED_OS_NAME STREQUAL "linux")
|
||||
set(NIF_OS_TAG linux)
|
||||
if(NFN_RESOLVED_OS_NAME STREQUAL "windows")
|
||||
set(NFN_OS_TAG win)
|
||||
elseif(NFN_RESOLVED_OS_NAME STREQUAL "linux")
|
||||
set(NFN_OS_TAG linux)
|
||||
else()
|
||||
set(NIF_OS_TAG unknown)
|
||||
set(NFN_OS_TAG unknown)
|
||||
endif()
|
||||
|
||||
if(NIF_RESOLVED_ARCH_NAME STREQUAL "x86_64")
|
||||
set(NIF_ARCH_TAG x64)
|
||||
if(NFN_RESOLVED_ARCH_NAME STREQUAL "x86_64")
|
||||
set(NFN_ARCH_TAG x64)
|
||||
else()
|
||||
set(NIF_ARCH_TAG ${NIF_RESOLVED_ARCH_NAME})
|
||||
set(NFN_ARCH_TAG ${NFN_RESOLVED_ARCH_NAME})
|
||||
endif()
|
||||
|
||||
set(NIF_EXPECTED_RID "" CACHE STRING "Optional managed target RID to validate before deployment")
|
||||
if(NIF_EXPECTED_RID AND NOT NIF_EXPECTED_RID STREQUAL "${NIF_OS_TAG}-${NIF_ARCH_TAG}")
|
||||
message(FATAL_ERROR "Native target ${NIF_OS_TAG}-${NIF_ARCH_TAG} does not match managed target ${NIF_EXPECTED_RID}. Use a matching compiler/toolchain and a separate build directory.")
|
||||
set(NFN_EXPECTED_RID "" CACHE STRING "Optional managed target RID to validate before deployment")
|
||||
if(NFN_EXPECTED_RID AND NOT NFN_EXPECTED_RID STREQUAL "${NFN_OS_TAG}-${NFN_ARCH_TAG}")
|
||||
message(FATAL_ERROR "Native target ${NFN_OS_TAG}-${NFN_ARCH_TAG} does not match managed target ${NFN_EXPECTED_RID}. Use a matching compiler/toolchain and a separate build directory.")
|
||||
endif()
|
||||
|
||||
set(NIF_BUILD_OUTPUT_DIR "${NIF_SOLUTION_ROOT}/bin/${NIF_OS_TAG}-${NIF_ARCH_TAG}"
|
||||
set(NFN_BUILD_OUTPUT_DIR "${NFN_SOLUTION_ROOT}/bin/${NFN_OS_TAG}-${NFN_ARCH_TAG}"
|
||||
CACHE PATH "Native artifact directory shared with managed build deployment")
|
||||
# Compile-time intermediates (native PDB / .obj side files) live inside the CMake
|
||||
# build tree (cmake_build/<preset>) so they get cleaned up with it.
|
||||
set(NIF_OBJECT_ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR}/obj/${PROJECT_NAME})
|
||||
set(NIF_NATIVE_PROJECT_FILES
|
||||
${NIF_NATIVE_SOURCES}
|
||||
${NIF_NATIVE_HEADERS}
|
||||
${NIF_NATIVE_TEMPLATES})
|
||||
set(NFN_OBJECT_ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR}/obj/${PROJECT_NAME})
|
||||
set(NFN_NATIVE_PROJECT_FILES
|
||||
${NFN_NATIVE_SOURCES}
|
||||
${NFN_NATIVE_HEADERS}
|
||||
${NFN_NATIVE_TEMPLATES})
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED ${NIF_NATIVE_PROJECT_FILES})
|
||||
add_library(${PROJECT_NAME} SHARED ${NFN_NATIVE_PROJECT_FILES})
|
||||
|
||||
source_group(TREE ${CMAKE_CURRENT_LIST_DIR} FILES ${NIF_NATIVE_PROJECT_FILES})
|
||||
source_group(TREE ${CMAKE_CURRENT_LIST_DIR} FILES ${NFN_NATIVE_PROJECT_FILES})
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
C_STANDARD 11
|
||||
@@ -98,10 +98,10 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
RELEASE_POSTFIX ""
|
||||
RELWITHDEBINFO_POSTFIX ""
|
||||
MINSIZEREL_POSTFIX ""
|
||||
RUNTIME_OUTPUT_DIRECTORY "${NIF_BUILD_OUTPUT_DIR}"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${NIF_BUILD_OUTPUT_DIR}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${NIF_BUILD_OUTPUT_DIR}"
|
||||
PDB_OUTPUT_DIRECTORY "${NIF_BUILD_OUTPUT_DIR}")
|
||||
RUNTIME_OUTPUT_DIRECTORY "${NFN_BUILD_OUTPUT_DIR}"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${NFN_BUILD_OUTPUT_DIR}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${NFN_BUILD_OUTPUT_DIR}"
|
||||
PDB_OUTPUT_DIRECTORY "${NFN_BUILD_OUTPUT_DIR}")
|
||||
|
||||
# P/Invoke loads Nitload.Native.dll on Windows, including GNU-style Clang toolchains.
|
||||
if(WIN32)
|
||||
@@ -111,22 +111,22 @@ endif()
|
||||
foreach(_config Debug Release RelWithDebInfo MinSizeRel)
|
||||
string(TOUPPER ${_config} _config_upper)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY_${_config_upper} ${NIF_BUILD_OUTPUT_DIR}
|
||||
LIBRARY_OUTPUT_DIRECTORY_${_config_upper} ${NIF_BUILD_OUTPUT_DIR}
|
||||
ARCHIVE_OUTPUT_DIRECTORY_${_config_upper} ${NIF_BUILD_OUTPUT_DIR}
|
||||
PDB_OUTPUT_DIRECTORY_${_config_upper} ${NIF_BUILD_OUTPUT_DIR}
|
||||
COMPILE_PDB_OUTPUT_DIRECTORY_${_config_upper} ${NIF_OBJECT_ROOT_DIR}/${_config}/${NIF_ARCH_TAG})
|
||||
RUNTIME_OUTPUT_DIRECTORY_${_config_upper} ${NFN_BUILD_OUTPUT_DIR}
|
||||
LIBRARY_OUTPUT_DIRECTORY_${_config_upper} ${NFN_BUILD_OUTPUT_DIR}
|
||||
ARCHIVE_OUTPUT_DIRECTORY_${_config_upper} ${NFN_BUILD_OUTPUT_DIR}
|
||||
PDB_OUTPUT_DIRECTORY_${_config_upper} ${NFN_BUILD_OUTPUT_DIR}
|
||||
COMPILE_PDB_OUTPUT_DIRECTORY_${_config_upper} ${NFN_OBJECT_ROOT_DIR}/${_config}/${NFN_ARCH_TAG})
|
||||
endforeach()
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
COMPILE_PDB_OUTPUT_DIRECTORY ${NIF_OBJECT_ROOT_DIR}/$<CONFIG>/${NIF_ARCH_TAG})
|
||||
COMPILE_PDB_OUTPUT_DIRECTORY ${NFN_OBJECT_ROOT_DIR}/$<CONFIG>/${NFN_ARCH_TAG})
|
||||
|
||||
if(MSVC OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC"))
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
/Fd${NIF_OBJECT_ROOT_DIR}/$<CONFIG>/${NIF_ARCH_TAG}/)
|
||||
/Fd${NFN_OBJECT_ROOT_DIR}/$<CONFIG>/${NFN_ARCH_TAG}/)
|
||||
endif()
|
||||
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NIF_RESOLVED_ARCH_NAME STREQUAL "x86_64")
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NFN_RESOLVED_ARCH_NAME STREQUAL "x86_64")
|
||||
# Keep the intrinsic type system and builtin declarations visible to all TUs.
|
||||
# The runtime dispatch contract still follows T_arch/T_feature at the function level.
|
||||
if(CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
|
||||
@@ -156,19 +156,19 @@ endif()
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-head
|
||||
${CMAKE_CURRENT_LIST_DIR}/nif-template
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-head
|
||||
${CMAKE_CURRENT_LIST_DIR}/nfn-template
|
||||
${CMAKE_CURRENT_LIST_DIR}/lib)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
NIF_EXTERN_TARGET
|
||||
NIF_OS_TARGET=${NIF_RESOLVED_OS_DEFINE}
|
||||
NIF_ARCH_TARGET=${NIF_RESOLVED_ARCH_DEFINE})
|
||||
NFN_EXTERN_TARGET
|
||||
NFN_OS_TARGET=${NFN_RESOLVED_OS_DEFINE}
|
||||
NFN_ARCH_TARGET=${NFN_RESOLVED_ARCH_DEFINE})
|
||||
|
||||
set(NIF_NATIVE_EXTERNAL_TARGET ${PROJECT_NAME})
|
||||
set(NFN_NATIVE_EXTERNAL_TARGET ${PROJECT_NAME})
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib)
|
||||
|
||||
message(STATUS "Nitload.Native target OS: ${NIF_RESOLVED_OS_NAME} (${NIF_RESOLVED_OS_DEFINE})")
|
||||
message(STATUS "Nitload.Native target ISA: ${NIF_RESOLVED_ARCH_NAME} (${NIF_RESOLVED_ARCH_DEFINE})")
|
||||
message(STATUS "Nitload.Native output dir: ${NIF_BUILD_OUTPUT_DIR}")
|
||||
message(STATUS "Nitload.Native target OS: ${NFN_RESOLVED_OS_NAME} (${NFN_RESOLVED_OS_DEFINE})")
|
||||
message(STATUS "Nitload.Native target ISA: ${NFN_RESOLVED_ARCH_NAME} (${NFN_RESOLVED_ARCH_DEFINE})")
|
||||
message(STATUS "Nitload.Native output dir: ${NFN_BUILD_OUTPUT_DIR}")
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
|
||||
"CMAKE_C_COMPILER": "clang",
|
||||
"CMAKE_CXX_COMPILER": "clang++"
|
||||
"CMAKE_C_COMPILER": "clang"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -21,8 +20,7 @@
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
|
||||
"CMAKE_C_COMPILER": "clang",
|
||||
"CMAKE_CXX_COMPILER": "clang++"
|
||||
"CMAKE_C_COMPILER": "clang"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
function(nif_normalize_os_identifier INPUT_VALUE OUTPUT_NAME OUTPUT_DEFINE)
|
||||
string(TOLOWER "${INPUT_VALUE}" _nif_os)
|
||||
function(nfn_normalize_os_identifier INPUT_VALUE OUTPUT_NAME OUTPUT_DEFINE)
|
||||
string(TOLOWER "${INPUT_VALUE}" _nfn_os)
|
||||
|
||||
if(_nif_os STREQUAL "auto")
|
||||
string(TOLOWER "${CMAKE_SYSTEM_NAME}" _nif_system_name)
|
||||
if(_nif_system_name STREQUAL "windows")
|
||||
set(_nif_os "windows")
|
||||
elseif(_nif_system_name STREQUAL "linux")
|
||||
set(_nif_os "linux")
|
||||
if(_nfn_os STREQUAL "auto")
|
||||
string(TOLOWER "${CMAKE_SYSTEM_NAME}" _nfn_system_name)
|
||||
if(_nfn_system_name STREQUAL "windows")
|
||||
set(_nfn_os "windows")
|
||||
elseif(_nfn_system_name STREQUAL "linux")
|
||||
set(_nfn_os "linux")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(_nif_os STREQUAL "windows")
|
||||
set(_nif_define NIF_OS_WINDOWS)
|
||||
elseif(_nif_os STREQUAL "linux")
|
||||
set(_nif_define NIF_OS_LINUX)
|
||||
if(_nfn_os STREQUAL "windows")
|
||||
set(_nfn_define NFN_OS_WINDOWS)
|
||||
elseif(_nfn_os STREQUAL "linux")
|
||||
set(_nfn_define NFN_OS_LINUX)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported NIF_TARGET_OS='${INPUT_VALUE}'.")
|
||||
message(FATAL_ERROR "Unsupported NFN_TARGET_OS='${INPUT_VALUE}'.")
|
||||
endif()
|
||||
|
||||
set(${OUTPUT_NAME} "${_nif_os}" PARENT_SCOPE)
|
||||
set(${OUTPUT_DEFINE} "${_nif_define}" PARENT_SCOPE)
|
||||
set(${OUTPUT_NAME} "${_nfn_os}" PARENT_SCOPE)
|
||||
set(${OUTPUT_DEFINE} "${_nfn_define}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(nif_normalize_arch_identifier INPUT_VALUE OUTPUT_NAME OUTPUT_DEFINE)
|
||||
string(TOLOWER "${INPUT_VALUE}" _nif_arch)
|
||||
function(nfn_normalize_arch_identifier INPUT_VALUE OUTPUT_NAME OUTPUT_DEFINE)
|
||||
string(TOLOWER "${INPUT_VALUE}" _nfn_arch)
|
||||
|
||||
if(_nif_arch STREQUAL "auto")
|
||||
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _nif_processor)
|
||||
if(_nif_processor MATCHES "^(amd64|x86_64|x64)$")
|
||||
set(_nif_arch "x86_64")
|
||||
elseif(_nif_processor MATCHES "^(arm64|aarch64)$")
|
||||
set(_nif_arch "arm64")
|
||||
elseif(_nif_processor STREQUAL "riscv64")
|
||||
set(_nif_arch "riscv64")
|
||||
elseif(_nif_processor MATCHES "^(ppc64le|powerpc64le)$")
|
||||
set(_nif_arch "ppc64le")
|
||||
if(_nfn_arch STREQUAL "auto")
|
||||
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _nfn_processor)
|
||||
if(_nfn_processor MATCHES "^(amd64|x86_64|x64)$")
|
||||
set(_nfn_arch "x86_64")
|
||||
elseif(_nfn_processor MATCHES "^(arm64|aarch64)$")
|
||||
set(_nfn_arch "arm64")
|
||||
elseif(_nfn_processor STREQUAL "riscv64")
|
||||
set(_nfn_arch "riscv64")
|
||||
elseif(_nfn_processor MATCHES "^(ppc64le|powerpc64le)$")
|
||||
set(_nfn_arch "ppc64le")
|
||||
else()
|
||||
message(FATAL_ERROR "Unable to infer ISA from CMAKE_SYSTEM_PROCESSOR='${CMAKE_SYSTEM_PROCESSOR}'. Set NIF_TARGET_ARCH explicitly.")
|
||||
message(FATAL_ERROR "Unable to infer ISA from CMAKE_SYSTEM_PROCESSOR='${CMAKE_SYSTEM_PROCESSOR}'. Set NFN_TARGET_ARCH explicitly.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(_nif_arch STREQUAL "x86_64")
|
||||
set(_nif_define NIF_ARCH_X86_64)
|
||||
elseif(_nif_arch STREQUAL "arm64")
|
||||
set(_nif_define NIF_ARCH_ARM64)
|
||||
elseif(_nif_arch STREQUAL "riscv64")
|
||||
set(_nif_define NIF_ARCH_RISCV64)
|
||||
elseif(_nif_arch STREQUAL "ppc64le")
|
||||
set(_nif_define NIF_ARCH_PPC64le)
|
||||
if(_nfn_arch STREQUAL "x86_64")
|
||||
set(_nfn_define NFN_ARCH_X86_64)
|
||||
elseif(_nfn_arch STREQUAL "arm64")
|
||||
set(_nfn_define NFN_ARCH_ARM64)
|
||||
elseif(_nfn_arch STREQUAL "riscv64")
|
||||
set(_nfn_define NFN_ARCH_RISCV64)
|
||||
elseif(_nfn_arch STREQUAL "ppc64le")
|
||||
set(_nfn_define NFN_ARCH_PPC64le)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported NIF_TARGET_ARCH='${INPUT_VALUE}'.")
|
||||
message(FATAL_ERROR "Unsupported NFN_TARGET_ARCH='${INPUT_VALUE}'.")
|
||||
endif()
|
||||
|
||||
set(${OUTPUT_NAME} "${_nif_arch}" PARENT_SCOPE)
|
||||
set(${OUTPUT_DEFINE} "${_nif_define}" PARENT_SCOPE)
|
||||
set(${OUTPUT_NAME} "${_nfn_arch}" PARENT_SCOPE)
|
||||
set(${OUTPUT_DEFINE} "${_nfn_define}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(nif_resolve_target_identifiers INPUT_OS INPUT_ARCH OUTPUT_OS_NAME OUTPUT_OS_DEFINE OUTPUT_ARCH_NAME OUTPUT_ARCH_DEFINE)
|
||||
nif_normalize_os_identifier("${INPUT_OS}" _nif_os_name _nif_os_define)
|
||||
nif_normalize_arch_identifier("${INPUT_ARCH}" _nif_arch_name _nif_arch_define)
|
||||
function(nfn_resolve_target_identifiers INPUT_OS INPUT_ARCH OUTPUT_OS_NAME OUTPUT_OS_DEFINE OUTPUT_ARCH_NAME OUTPUT_ARCH_DEFINE)
|
||||
nfn_normalize_os_identifier("${INPUT_OS}" _nfn_os_name _nfn_os_define)
|
||||
nfn_normalize_arch_identifier("${INPUT_ARCH}" _nfn_arch_name _nfn_arch_define)
|
||||
|
||||
set(${OUTPUT_OS_NAME} "${_nif_os_name}" PARENT_SCOPE)
|
||||
set(${OUTPUT_OS_DEFINE} "${_nif_os_define}" PARENT_SCOPE)
|
||||
set(${OUTPUT_ARCH_NAME} "${_nif_arch_name}" PARENT_SCOPE)
|
||||
set(${OUTPUT_ARCH_DEFINE} "${_nif_arch_define}" PARENT_SCOPE)
|
||||
set(${OUTPUT_OS_NAME} "${_nfn_os_name}" PARENT_SCOPE)
|
||||
set(${OUTPUT_OS_DEFINE} "${_nfn_os_define}" PARENT_SCOPE)
|
||||
set(${OUTPUT_ARCH_NAME} "${_nfn_arch_name}" PARENT_SCOPE)
|
||||
set(${OUTPUT_ARCH_DEFINE} "${_nfn_arch_define}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(nif_register_external_package TARGET PACKAGE_NAME PACKAGE_DIR)
|
||||
function(nfn_register_external_package TARGET PACKAGE_NAME PACKAGE_DIR)
|
||||
if(NOT TARGET ${TARGET})
|
||||
message(FATAL_ERROR "nif_register_external_package: target '${TARGET}' does not exist.")
|
||||
message(FATAL_ERROR "nfn_register_external_package: target '${TARGET}' does not exist.")
|
||||
endif()
|
||||
|
||||
if(EXISTS "${PACKAGE_DIR}")
|
||||
@@ -79,7 +79,7 @@ function(nif_register_external_package TARGET PACKAGE_NAME PACKAGE_DIR)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(nif_link_external_binary_if_exists TARGET LIBRARY_PATH)
|
||||
function(nfn_link_external_binary_if_exists TARGET LIBRARY_PATH)
|
||||
if(EXISTS "${LIBRARY_PATH}")
|
||||
target_link_libraries(${TARGET} PRIVATE "${LIBRARY_PATH}")
|
||||
message(STATUS "Linked external binary: ${LIBRARY_PATH}")
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)lib;$(ProjectDir)nif-head;$(ProjectDir)nif-template;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)lib;$(ProjectDir)nfn-head;$(ProjectDir)nfn-template;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<!-- DLL 应该用 Windows,不是 Console -->
|
||||
@@ -173,23 +173,23 @@
|
||||
<!-- source files -->
|
||||
<!-- ════════════════════════════════════════════════════════ -->
|
||||
<ItemGroup>
|
||||
<ClCompile Include="nif-src\dllmain.c" />
|
||||
<ClCompile Include="nif-src\m.bufop.x86.c" />
|
||||
<ClCompile Include="nif-src\m.solve.x86.c" />
|
||||
<ClCompile Include="nif-src\m.transpose.x86.c" />
|
||||
<ClCompile Include="nif-src\mk.fma.x86.c" />
|
||||
<ClCompile Include="nif-src\mk.p_scan.x86.c" />
|
||||
<ClCompile Include="nif-src\s.factorial.x86.c" />
|
||||
<ClCompile Include="nif-src\sk.fma.x86.c" />
|
||||
<ClCompile Include="nif-src\s.hash.x86.c" />
|
||||
<ClCompile Include="nif-src\load_intrinsic.x86.c" />
|
||||
<ClCompile Include="nif-src\load_glfw.c" />
|
||||
<ClCompile Include="nif-src\simdid.x86.c" />
|
||||
<ClCompile Include="nif-src\simdid_compare.x86.c" />
|
||||
<ClCompile Include="nif-src\thread.linux.c" />
|
||||
<ClCompile Include="nif-src\thread.windows.c" />
|
||||
<ClCompile Include="nif-src\vector.c" />
|
||||
<ClCompile Include="nif-src\vector_dot.c" />
|
||||
<ClCompile Include="nfn-src\dllmain.c" />
|
||||
<ClCompile Include="nfn-src\m.bufop.x86.c" />
|
||||
<ClCompile Include="nfn-src\m.solve.x86.c" />
|
||||
<ClCompile Include="nfn-src\m.transpose.x86.c" />
|
||||
<ClCompile Include="nfn-src\mk.fma.x86.c" />
|
||||
<ClCompile Include="nfn-src\mk.p_scan.x86.c" />
|
||||
<ClCompile Include="nfn-src\s.factorial.x86.c" />
|
||||
<ClCompile Include="nfn-src\sk.fma.x86.c" />
|
||||
<ClCompile Include="nfn-src\s.hash.x86.c" />
|
||||
<ClCompile Include="nfn-src\load_intrinsic.x86.c" />
|
||||
<ClCompile Include="nfn-src\load_glfw.c" />
|
||||
<ClCompile Include="nfn-src\simdid.x86.c" />
|
||||
<ClCompile Include="nfn-src\simdid_compare.x86.c" />
|
||||
<ClCompile Include="nfn-src\thread.linux.c" />
|
||||
<ClCompile Include="nfn-src\thread.windows.c" />
|
||||
<ClCompile Include="nfn-src\vector.c" />
|
||||
<ClCompile Include="nfn-src\vector_dot.c" />
|
||||
</ItemGroup>
|
||||
<!-- ════════════════════════════════════════════════════════ -->
|
||||
<!-- header files -->
|
||||
@@ -198,15 +198,15 @@
|
||||
<ClInclude Include="lib\glfw\glfw3.h" />
|
||||
<ClInclude Include="lib\glfw\glfw3native.h" />
|
||||
<ClInclude Include="lib\stbi\stb_image.h" />
|
||||
<ClInclude Include="nif-head\glfw_function.h" />
|
||||
<ClInclude Include="nif-head\nif_internal.h" />
|
||||
<ClInclude Include="nif-head\nif_intrinsic.context.x86.h" />
|
||||
<ClInclude Include="nif-head\nif_intrinsic.std.h" />
|
||||
<ClInclude Include="nif-head\nif_intrinsic.h" />
|
||||
<ClInclude Include="nif-head\nif_intrinsic.matkernel.h" />
|
||||
<ClInclude Include="nif-head\nif_target.h" />
|
||||
<ClInclude Include="nif-head\NitloadFrameWork.h" />
|
||||
<ClInclude Include="nif-template\nif_template.fma.x86.h" />
|
||||
<ClInclude Include="nfn-head\glfw_function.h" />
|
||||
<ClInclude Include="nfn-head\nfn_internal.h" />
|
||||
<ClInclude Include="nfn-head\nfn_intrinsic.context.x86.h" />
|
||||
<ClInclude Include="nfn-head\nfn_intrinsic.std.h" />
|
||||
<ClInclude Include="nfn-head\nfn_intrinsic.h" />
|
||||
<ClInclude Include="nfn-head\nfn_intrinsic.matkernel.h" />
|
||||
<ClInclude Include="nfn-head\nfn_target.h" />
|
||||
<ClInclude Include="nfn-head\NitloadFrameWork.h" />
|
||||
<ClInclude Include="nfn-template\nfn_template.fma.x86.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="naming.md" />
|
||||
|
||||
@@ -21,69 +21,69 @@
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="nif-src\dllmain.c">
|
||||
<ClCompile Include="nfn-src\dllmain.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\s.factorial.x86.c">
|
||||
<ClCompile Include="nfn-src\s.factorial.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\s.hash.x86.c">
|
||||
<ClCompile Include="nfn-src\s.hash.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\vector.c">
|
||||
<ClCompile Include="nfn-src\vector.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\vector_dot.c">
|
||||
<ClCompile Include="nfn-src\vector_dot.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\load_glfw.c">
|
||||
<ClCompile Include="nfn-src\load_glfw.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\sk.fma.x86.c">
|
||||
<ClCompile Include="nfn-src\sk.fma.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\load_intrinsic.x86.c">
|
||||
<ClCompile Include="nfn-src\load_intrinsic.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\m.bufop.x86.c">
|
||||
<ClCompile Include="nfn-src\m.bufop.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\m.solve.x86.c">
|
||||
<ClCompile Include="nfn-src\m.solve.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\simdid.x86.c">
|
||||
<ClCompile Include="nfn-src\simdid.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\mk.fma.x86.c">
|
||||
<ClCompile Include="nfn-src\mk.fma.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\simdid_compare.x86.c">
|
||||
<ClCompile Include="nfn-src\simdid_compare.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\thread.linux.c">
|
||||
<ClCompile Include="nfn-src\thread.linux.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\thread.windows.c">
|
||||
<ClCompile Include="nfn-src\thread.windows.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\m.transpose.x86.c">
|
||||
<ClCompile Include="nfn-src\m.transpose.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="nif-src\mk.p_scan.x86.c">
|
||||
<ClCompile Include="nfn-src\mk.p_scan.x86.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="nif-head\nif_internal.h">
|
||||
<ClInclude Include="nfn-head\nfn_internal.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="nif-head\NitloadFrameWork.h">
|
||||
<ClInclude Include="nfn-head\NitloadFrameWork.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="nif-head\glfw_function.h">
|
||||
<ClInclude Include="nfn-head\glfw_function.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="nif-head\nif_intrinsic.matkernel.h">
|
||||
<ClInclude Include="nfn-head\nfn_intrinsic.matkernel.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lib\glfw\glfw3.h">
|
||||
@@ -95,19 +95,19 @@
|
||||
<ClInclude Include="lib\stbi\stb_image.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="nif-head\nif_target.h">
|
||||
<ClInclude Include="nfn-head\nfn_target.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="nif-head\nif_intrinsic.context.x86.h">
|
||||
<ClInclude Include="nfn-head\nfn_intrinsic.context.x86.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="nif-head\nif_intrinsic.h">
|
||||
<ClInclude Include="nfn-head\nfn_intrinsic.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="nif-head\nif_intrinsic.std.h">
|
||||
<ClInclude Include="nfn-head\nfn_intrinsic.std.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="nif-template\nif_template.fma.x86.h">
|
||||
<ClInclude Include="nfn-template\nfn_template.fma.x86.h">
|
||||
<Filter>模板文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
# Nitload.Native
|
||||
|
||||
## Naming convention
|
||||
|
||||
The C implementation uses `nfn` for Nitload Framework Native: exported functions use
|
||||
`nfn_`, macros and CMake cache options use `NFN_`, and native source folders and
|
||||
headers use `nfn-` and `nfn_`. The shared library remains named `Nitload.Native`.
|
||||
The longer prefix also distinguishes these names from Linux Netfilter's `nf_` names.
|
||||
|
||||
This migration renames the exported C symbols from `nif_*` to `nfn_*`. Native
|
||||
binaries and managed assemblies must therefore be rebuilt and deployed together;
|
||||
pre-migration P/Invoke entry points are not compatible with a newly built library.
|
||||
The old `NIF_*` CMake cache options are no longer used. Reconfigure an existing
|
||||
build tree with the corresponding `NFN_*` options, or use a fresh build tree.
|
||||
|
||||
## COMPILE
|
||||
|
||||
Though this project do has a .vcxproj file,
|
||||
@@ -11,15 +24,21 @@ Currently you can only compile this lib via Clang and cmake.
|
||||
From the repository root:
|
||||
|
||||
```powershell
|
||||
# On Windows, add your LLVM bin directory if clang is not already on PATH.
|
||||
$env:PATH = 'C:\Program Files\LLVM\bin;' + $env:PATH
|
||||
cmake --preset clang-debug -S src/Nitload.Native
|
||||
cmake --build cmake_build/clang-debug --target Nitload.Native
|
||||
```
|
||||
|
||||
The presets require `clang` on `PATH`. If an existing CMake cache was configured
|
||||
with an absolute compiler path, make `clang` available on `PATH` before running
|
||||
the preset again. The `NFN_*` options replace the former `NIF_*` options.
|
||||
|
||||
CMake writes `Nitload.Native.dll` and its linker PDB to `bin/win-x64` on Windows x64
|
||||
(Linux uses `bin/linux-x64/libNitload.Native.so`). Debug and release presets currently
|
||||
share this platform directory; the most recent native build is the deployed version.
|
||||
`NIF_BUILD_OUTPUT_DIR` can override the destination. Managed builds pass their expected
|
||||
RID as `NIF_EXPECTED_RID` so an incompatible native target is rejected before deployment.
|
||||
`NFN_BUILD_OUTPUT_DIR` can override the destination. Managed builds pass their expected
|
||||
RID as `NFN_EXPECTED_RID` so an incompatible native target is rejected before deployment.
|
||||
|
||||
`StgSharpDebug.csproj` enables `BuildNativeBeforeManaged` and `RequireNativeLibrary`.
|
||||
Its build runs the incremental CMake build (`clang-debug` for Debug, `clang-release`
|
||||
@@ -32,6 +51,15 @@ Clang/Ninja environment and the local GLFW static library are required for nativ
|
||||
Cross-target builds require a matching toolchain/preset; changing a managed platform alone
|
||||
does not cross-compile the C library.
|
||||
|
||||
## clangd in VS Code
|
||||
|
||||
The `.clangd` file searches for `compile_commands.json` in `src/Nitload.Native`.
|
||||
When using CMake Tools, set `cmake.copyCompileCommands` to
|
||||
`${workspaceFolder}/src/Nitload.Native/compile_commands.json` so the active Debug or Release preset
|
||||
updates that file after configuration. For command-line configuration, copy
|
||||
`cmake_build/<preset>/compile_commands.json` to `src/Nitload.Native`. Restart
|
||||
clangd after changing the database or renaming headers.
|
||||
|
||||
## Code Layout
|
||||
|
||||
Conventions:
|
||||
|
||||
@@ -217,7 +217,7 @@ Detection:
|
||||
- **Unknown hybrid** (flag set but core type unrecognised): leave topology at 00.
|
||||
- **SIMD_DUAL**: set when any of the following: `AVX Feature DUAL=1` (glued YMM), or `AVX512_IMPL=DUAL`.
|
||||
|
||||
`nif_get_unite_simd` computes topology bits [1..0] with bitwise **AND** (conservative intersection — weaker topology wins) and SIMD_DUAL with bitwise **OR** (dual if either core is dual). `nif_compare_simd` compares topology value numerically as step 6 and SIMD_DUAL as the final (step 7) tie-break.
|
||||
`nfn_get_unite_simd` computes topology bits [1..0] with bitwise **AND** (conservative intersection — weaker topology wins) and SIMD_DUAL with bitwise **OR** (dual if either core is dual). `nfn_compare_simd` compares topology value numerically as step 6 and SIMD_DUAL as the final (step 7) tie-break.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
if(NOT DEFINED NIF_NATIVE_EXTERNAL_TARGET)
|
||||
message(FATAL_ERROR "NIF_NATIVE_EXTERNAL_TARGET must be set before adding lib/.")
|
||||
if(NOT DEFINED NFN_NATIVE_EXTERNAL_TARGET)
|
||||
message(FATAL_ERROR "NFN_NATIVE_EXTERNAL_TARGET must be set before adding lib/.")
|
||||
endif()
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../ExternalLibs.cmake OPTIONAL)
|
||||
@@ -17,6 +17,6 @@ foreach(_pkg ${LIB_PACKAGE_DIRS})
|
||||
if(EXISTS ${_pkg_dir}/CMakeLists.txt)
|
||||
add_subdirectory(${_pkg_dir})
|
||||
else()
|
||||
nif_register_external_package(${NIF_NATIVE_EXTERNAL_TARGET} ${_pkg} ${_pkg_dir})
|
||||
nfn_register_external_package(${NFN_NATIVE_EXTERNAL_TARGET} ${_pkg} ${_pkg_dir})
|
||||
endif()
|
||||
endforeach()
|
||||
@@ -1,11 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
nif_register_external_package(${NIF_NATIVE_EXTERNAL_TARGET} glfw ${CMAKE_CURRENT_LIST_DIR})
|
||||
nfn_register_external_package(${NFN_NATIVE_EXTERNAL_TARGET} glfw ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
if(WIN32)
|
||||
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/glfw3_mt.lib)
|
||||
message(FATAL_ERROR "Required GLFW static library not found: ${CMAKE_CURRENT_LIST_DIR}/glfw3_mt.lib")
|
||||
endif()
|
||||
|
||||
nif_link_external_binary_if_exists(${NIF_NATIVE_EXTERNAL_TARGET} ${CMAKE_CURRENT_LIST_DIR}/glfw3_mt.lib)
|
||||
nfn_link_external_binary_if_exists(${NFN_NATIVE_EXTERNAL_TARGET} ${CMAKE_CURRENT_LIST_DIR}/glfw3_mt.lib)
|
||||
endif()
|
||||
@@ -207,7 +207,7 @@ GLFWAPI const char *glfwGetWin32Monitor(GLFWmonitor *monitor);
|
||||
* GLFW_PLATFORM_UNAVAILABLE.
|
||||
*
|
||||
* @remark The `HDC` associated with the window can be queried with the
|
||||
* [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc)
|
||||
* [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nfn-winuser-getdc)
|
||||
* function.
|
||||
* @code
|
||||
* HDC dc = GetDC(glfwGetWin32Window(window));
|
||||
@@ -234,7 +234,7 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow *window);
|
||||
* GLFW_PLATFORM_UNAVAILABLE and @ref GLFW_NO_WINDOW_CONTEXT.
|
||||
*
|
||||
* @remark The `HDC` associated with the window can be queried with the
|
||||
* [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc)
|
||||
* [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nfn-winuser-getdc)
|
||||
* function.
|
||||
* @code
|
||||
* HDC dc = GetDC(glfwGetWin32Window(window));
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
nif_register_external_package(${NIF_NATIVE_EXTERNAL_TARGET} stbi ${CMAKE_CURRENT_LIST_DIR})
|
||||
nfn_register_external_package(${NFN_NATIVE_EXTERNAL_TARGET} stbi ${CMAKE_CURRENT_LIST_DIR})
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef NFN_NATIVE_H
|
||||
#define NFN_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 "nfn_internal.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#include <immintrin.h>
|
||||
#include <assert.h>
|
||||
#include <glfw_function.h>
|
||||
|
||||
#define byte char
|
||||
#define cs_char uint16_t
|
||||
#define nfn_null_assert(ptr) assert(ptr != NULL)
|
||||
|
||||
#ifndef NFN_
|
||||
#endif
|
||||
|
||||
NFN_API void NFN_DECL nfn_load_glfw_functions(GLFWFunctionTable *table);
|
||||
NFN_API void NFN_DECL nfn_load_intrinsic_function(void *intrinsic_context, uint64_t id);
|
||||
NFN_API SIMDID NFN_DECL nfn_get_simd_level_global();
|
||||
/* Per-core variant: always re-executes CPUID, never caches.
|
||||
* Must be called on the target core (after affinity is set). */
|
||||
NFN_API SIMDID NFN_DECL nfn_get_simd_level_local();
|
||||
NFN_API SIMDID NFN_DECL nfn_get_unite_simd(SIMDID left, SIMDID right);
|
||||
NFN_API int NFN_DECL nfn_compare_simd(SIMDID left, SIMDID right);
|
||||
NFN_API void NFN_DECL nfn_set_thread_affinity(int core_id, int numa_id);
|
||||
NFN_API void* NFN_DECL nfn_numa_alloc(size_t size, int numa_id);
|
||||
NFN_API void NFN_DECL nfn_numa_free(void *ptr, size_t size, int numa_id);
|
||||
NFN_API int NFN_DECL nfn_get_numa_each(int numa_id, uint64_t *internal, uint32_t *global);
|
||||
NFN_API int NFN_DECL nfn_get_numa_overall(int *out_numa_count, int *count_of_each_numa);
|
||||
#endif
|
||||
+14
-14
@@ -1,6 +1,6 @@
|
||||
|
||||
#ifndef NIF_INTERNAL
|
||||
#define NIF_INTERNAL
|
||||
#ifndef NFN_INTERNAL
|
||||
#define NFN_INTERNAL
|
||||
|
||||
#include <xmmintrin.h>
|
||||
|
||||
@@ -9,33 +9,33 @@
|
||||
#ifdef _MSC_VER
|
||||
#define _CRT_SECURE_NO_WARNINGS 1
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NIF_DECL __cdecl
|
||||
#define NIF_MAT_DECL __cdecl __forceinline
|
||||
#define NIF_API __declspec(dllexport)
|
||||
#define NFN_DECL __cdecl
|
||||
#define NFN_MAT_DECL __cdecl __forceinline
|
||||
#define NFN_API __declspec(dllexport)
|
||||
#define FORCEINLINE __forceinline
|
||||
#define NOINLINE __declspec(noinline)
|
||||
#include <windows.h>
|
||||
#elif defined(__clang__) || defined(__GNUC__)
|
||||
#define NIF_DECL __attribute__((cdecl))
|
||||
#define NIF_MAT_DECL __attribute__((cdecl)) __attribute__((always_inline))
|
||||
#define NIF_API __attribute__((dllexport))
|
||||
#define NFN_DECL __attribute__((cdecl))
|
||||
#define NFN_MAT_DECL __attribute__((cdecl)) __attribute__((always_inline))
|
||||
#define NFN_API __attribute__((dllexport))
|
||||
#define FORCEINLINE __attribute__((always_inline))
|
||||
#define NOINLINE __attribute__((noinline))
|
||||
#else
|
||||
#define NIF_API
|
||||
#define NIF_DECL
|
||||
#define NIF_MAT_DECL
|
||||
#define NFN_API
|
||||
#define NFN_DECL
|
||||
#define NFN_MAT_DECL
|
||||
#define FORCEINLINE
|
||||
#define NOINLINE
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define NIF_ALIGNAS(n) __declspec(align(n))
|
||||
#define NFN_ALIGNAS(n) __declspec(align(n))
|
||||
#else
|
||||
#define NIF_ALIGNAS(n) __attribute__((aligned(n)))
|
||||
#define NFN_ALIGNAS(n) __attribute__((aligned(n)))
|
||||
#endif
|
||||
|
||||
#define NIF_APIDEF
|
||||
#define NFN_APIDEF
|
||||
|
||||
#define PRIVATE static
|
||||
#define INTERNAL extern
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
#ifndef NIF_INTRINSIC_CONTEXT_BASE
|
||||
#define NIF_INTRINSIC_CONTEXT_BASE
|
||||
#ifndef NFN_INTRINSIC_CONTEXT_BASE
|
||||
#define NFN_INTRINSIC_CONTEXT_BASE
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
+107
-107
@@ -1,20 +1,20 @@
|
||||
#ifndef NIF_INTRINSIC_CONTEXT_X86_H
|
||||
#define NIF_INTRINSIC_CONTEXT_X86_H
|
||||
#ifndef NFN_INTRINSIC_CONTEXT_X86_H
|
||||
#define NFN_INTRINSIC_CONTEXT_X86_H
|
||||
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include "nif_intrinsic.h"
|
||||
#include "nif_intrinsic.std.h"
|
||||
#include "nif_intrinsic.context.base.h"
|
||||
#include "nfn_intrinsic.h"
|
||||
#include "nfn_intrinsic.std.h"
|
||||
#include "nfn_intrinsic.context.base.h"
|
||||
|
||||
#ifndef NIF_X86_TARGET_ATTR_sse
|
||||
#define NIF_STD_TARGET_ATTR_IMPL(T_arch, T_feature) NIF_X86_TARGET_ATTR_##T_arch##T_feature
|
||||
#define NIF_X86_TARGET_ATTR_sse NIF_CLANG_TARGET_ATTR("sse4.2")
|
||||
#define NIF_X86_TARGET_ATTR_avx NIF_CLANG_TARGET_ATTR("avx")
|
||||
#define NIF_X86_TARGET_ATTR_avx_fma NIF_CLANG_TARGET_ATTR("avx,avx2,fma")
|
||||
#define NIF_X86_TARGET_ATTR_512 NIF_CLANG_TARGET_ATTR("avx512f,avx512vl")
|
||||
#ifndef NFN_X86_TARGET_ATTR_sse
|
||||
#define NFN_STD_TARGET_ATTR_IMPL(T_arch, T_feature) NFN_X86_TARGET_ATTR_##T_arch##T_feature
|
||||
#define NFN_X86_TARGET_ATTR_sse NFN_CLANG_TARGET_ATTR("sse4.2")
|
||||
#define NFN_X86_TARGET_ATTR_avx NFN_CLANG_TARGET_ATTR("avx")
|
||||
#define NFN_X86_TARGET_ATTR_avx_fma NFN_CLANG_TARGET_ATTR("avx,avx2,fma")
|
||||
#define NFN_X86_TARGET_ATTR_512 NFN_CLANG_TARGET_ATTR("avx512f,avx512vl")
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -111,45 +111,45 @@
|
||||
|
||||
INTERNAL void f32_normalize(VEC_SEGMENT(float) * source, VEC_SEGMENT(float) * target);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , k_quality);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , k_quality);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , add);
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , add);
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , add);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , add);
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , add);
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , add);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , add);
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , add);
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , add);
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , add);
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , add);
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , add);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , sub);
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , sub);
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , sub);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , sub);
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , sub);
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , sub);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , sub);
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , sub);
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , sub);
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , sub);
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , sub);
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , sub);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , transpose);
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , transpose);
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , transpose);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , transpose);
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , transpose);
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , transpose);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , scalar_mul);
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , scalar_mul);
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , scalar_mul);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , scalar_mul);
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , scalar_mul);
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , scalar_mul);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , scalar_mul);
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , scalar_mul);
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , scalar_mul);
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , scalar_mul);
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , scalar_mul);
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , scalar_mul);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , fill);
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , fill);
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , fill);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , fill);
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , fill);
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , fill);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , fill);
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , fill);
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , fill);
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , fill);
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , fill);
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , fill);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , quality);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , quality);
|
||||
|
||||
/*
|
||||
* pack left matrix data to L4 buffer
|
||||
@@ -166,9 +166,9 @@ NIF_MK_PROC_DECL_STD(float, sse, , quality);
|
||||
* scalar pack carries column length and offset data:
|
||||
* [column length, empty, empty, empty]
|
||||
*/
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , fma_pack_left);
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , fma_pack_left);
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , fma_pack_left);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , fma_pack_left);
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , fma_pack_left);
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , fma_pack_left);
|
||||
|
||||
/*
|
||||
* pack right matrix data to L4 buffer
|
||||
@@ -185,104 +185,104 @@ NIF_MK_PROC_DECL_STD(float, 512, , fma_pack_left);
|
||||
* scalar pack carries column length and offset data:
|
||||
* [column length, empty, empty, empty]
|
||||
*/
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , fma_pack_right);
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , fma_pack_right);
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , fma_pack_right);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , fma_pack_right);
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , fma_pack_right);
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , fma_pack_right);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , fma);
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , fma);
|
||||
NIF_MK_PROC_DECL_STD(float, avx, _fma, fma);
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , fma);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , fma);
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , fma);
|
||||
NFN_MK_PROC_DECL_STD(float, avx, _fma, fma);
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , fma);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , fma_unpack);
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , fma_unpack);
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , fma_unpack);
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , fma_unpack);
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , fma_unpack);
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , fma_unpack);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , fma_pack_left);
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , fma_pack_left);
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , fma_pack_left);
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , fma_pack_left);
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , fma_pack_left);
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , fma_pack_left);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , fma);
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , fma);
|
||||
NIF_MK_PROC_DECL_STD(double, avx, _fma, fma);
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , fma);
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , fma);
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , fma);
|
||||
NFN_MK_PROC_DECL_STD(double, avx, _fma, fma);
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , fma);
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , fma_unpack);
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , fma_unpack);
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , fma_unpack);
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , fma_unpack);
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , fma_unpack);
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , fma_unpack);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, avx, , add);
|
||||
NIF_SK_PROC_DECL_STD(float, 512, , add);
|
||||
NFN_SK_PROC_DECL_STD(float, avx, , add);
|
||||
NFN_SK_PROC_DECL_STD(float, 512, , add);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(double, sse, , add);
|
||||
NIF_SK_PROC_DECL_STD(double, avx, , add);
|
||||
NIF_SK_PROC_DECL_STD(double, 512, , add);
|
||||
NFN_SK_PROC_DECL_STD(double, sse, , add);
|
||||
NFN_SK_PROC_DECL_STD(double, avx, , add);
|
||||
NFN_SK_PROC_DECL_STD(double, 512, , add);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, sse, , sub);
|
||||
NIF_SK_PROC_DECL_STD(float, avx, , sub);
|
||||
NIF_SK_PROC_DECL_STD(float, 512, , sub);
|
||||
NFN_SK_PROC_DECL_STD(float, sse, , sub);
|
||||
NFN_SK_PROC_DECL_STD(float, avx, , sub);
|
||||
NFN_SK_PROC_DECL_STD(float, 512, , sub);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(double, sse, , sub);
|
||||
NIF_SK_PROC_DECL_STD(double, avx, , sub);
|
||||
NIF_SK_PROC_DECL_STD(double, 512, , sub);
|
||||
NFN_SK_PROC_DECL_STD(double, sse, , sub);
|
||||
NFN_SK_PROC_DECL_STD(double, avx, , sub);
|
||||
NFN_SK_PROC_DECL_STD(double, 512, , sub);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, sse, , transpose);
|
||||
NIF_SK_PROC_DECL_STD(float, avx, , transpose);
|
||||
NIF_SK_PROC_DECL_STD(float, 512, , transpose);
|
||||
NFN_SK_PROC_DECL_STD(float, sse, , transpose);
|
||||
NFN_SK_PROC_DECL_STD(float, avx, , transpose);
|
||||
NFN_SK_PROC_DECL_STD(float, 512, , transpose);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, sse, , scalar_mul);
|
||||
NIF_SK_PROC_DECL_STD(float, avx, , scalar_mul);
|
||||
NIF_SK_PROC_DECL_STD(float, 512, , scalar_mul);
|
||||
NFN_SK_PROC_DECL_STD(float, sse, , scalar_mul);
|
||||
NFN_SK_PROC_DECL_STD(float, avx, , scalar_mul);
|
||||
NFN_SK_PROC_DECL_STD(float, 512, , scalar_mul);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(double, sse, , scalar_mul);
|
||||
NIF_SK_PROC_DECL_STD(double, avx, , scalar_mul);
|
||||
NIF_SK_PROC_DECL_STD(double, 512, , scalar_mul);
|
||||
NFN_SK_PROC_DECL_STD(double, sse, , scalar_mul);
|
||||
NFN_SK_PROC_DECL_STD(double, avx, , scalar_mul);
|
||||
NFN_SK_PROC_DECL_STD(double, 512, , scalar_mul);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, sse, , fill);
|
||||
NIF_SK_PROC_DECL_STD(float, avx, , fill);
|
||||
NIF_SK_PROC_DECL_STD(float, 512, , fill);
|
||||
NFN_SK_PROC_DECL_STD(float, sse, , fill);
|
||||
NFN_SK_PROC_DECL_STD(float, avx, , fill);
|
||||
NFN_SK_PROC_DECL_STD(float, 512, , fill);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(double, sse, , fill);
|
||||
NIF_SK_PROC_DECL_STD(double, avx, , fill);
|
||||
NIF_SK_PROC_DECL_STD(double, 512, , fill);
|
||||
NFN_SK_PROC_DECL_STD(double, sse, , fill);
|
||||
NFN_SK_PROC_DECL_STD(double, avx, , fill);
|
||||
NFN_SK_PROC_DECL_STD(double, 512, , fill);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, sse, , quality);
|
||||
NFN_SK_PROC_DECL_STD(float, sse, , quality);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, sse, , fma);
|
||||
NIF_SK_PROC_DECL_STD(float, avx, , fma);
|
||||
NIF_SK_PROC_DECL_STD(float, avx, _fma, fma);
|
||||
NIF_SK_PROC_DECL_STD(float, 512, , fma);
|
||||
NFN_SK_PROC_DECL_STD(float, sse, , fma);
|
||||
NFN_SK_PROC_DECL_STD(float, avx, , fma);
|
||||
NFN_SK_PROC_DECL_STD(float, avx, _fma, fma);
|
||||
NFN_SK_PROC_DECL_STD(float, 512, , fma);
|
||||
|
||||
NIF_SK_PROC_DECL_STD(double, sse, , fma);
|
||||
NIF_SK_PROC_DECL_STD(double, avx, , fma);
|
||||
NIF_SK_PROC_DECL_STD(double, avx, _fma, fma);
|
||||
NIF_SK_PROC_DECL_STD(double, 512, , fma);
|
||||
NFN_SK_PROC_DECL_STD(double, sse, , fma);
|
||||
NFN_SK_PROC_DECL_STD(double, avx, , fma);
|
||||
NFN_SK_PROC_DECL_STD(double, avx, _fma, fma);
|
||||
NFN_SK_PROC_DECL_STD(double, 512, , fma);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region scaler_simd
|
||||
|
||||
INTERNAL uint64_t NIF_DECL factorial_simd_sse(int n);
|
||||
INTERNAL uint64_t NFN_DECL factorial_simd_sse(int n);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region dot_product
|
||||
|
||||
INTERNAL void FORCEINLINE NIF_DECL dot_41_sse(MAT_KERNEL(float) const *transpose,
|
||||
INTERNAL void FORCEINLINE NFN_DECL dot_41_sse(MAT_KERNEL(float) const *transpose,
|
||||
__m128 const *vector, __m128 *ans);
|
||||
INTERNAL void NIF_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
INTERNAL void NFN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans);
|
||||
INTERNAL void NIF_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
INTERNAL void NFN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans);
|
||||
INTERNAL void NIF_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
INTERNAL void NFN_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region string
|
||||
|
||||
INTERNAL int NIF_DECL city_hash_simplify_sse(byte const *str, int length);
|
||||
INTERNAL int NIF_DECL index_pair_sse(short const *stram, uint32_t target, int length);
|
||||
INTERNAL int NFN_DECL city_hash_simplify_sse(byte const *str, int length);
|
||||
INTERNAL int NFN_DECL index_pair_sse(short const *stram, uint32_t target, int length);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
+24
-24
@@ -4,11 +4,11 @@
|
||||
#define SSC_INTRIN_HEAD
|
||||
|
||||
#include "NitloadFrameWork.h"
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
#include <xmmintrin.h>
|
||||
#include <immintrin.h>
|
||||
#include <smmintrin.h>
|
||||
#include "nif_intrinsic.matkernel.h"
|
||||
#include "nfn_intrinsic.matkernel.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -28,7 +28,7 @@
|
||||
((LASTTWO(s3) << 6) | (LASTTWO(s2) << 4) | (LASTTWO(s1) << 2) | (LASTTWO(s0)))
|
||||
#define BIT_CVRT(pack, index, T) *(T *)(pack->data + index)
|
||||
|
||||
#if NIF_IS_ARCH(x86_64)
|
||||
#if NFN_IS_ARCH(x86_64)
|
||||
|
||||
#define vec_128 __m128
|
||||
#define vec_256 __m256
|
||||
@@ -66,7 +66,7 @@ typedef union uint64_u {
|
||||
typedef struct mat_kernel mat_kernel;
|
||||
|
||||
typedef union M128{
|
||||
#if NIF_IS_ARCH(x86_64)
|
||||
#if NFN_IS_ARCH(x86_64)
|
||||
__m128 m128;
|
||||
#endif
|
||||
float f32[4];
|
||||
@@ -76,7 +76,7 @@ typedef union M128{
|
||||
}M128;
|
||||
|
||||
typedef union M256{
|
||||
#if NIF_IS_ARCH(x86_64)
|
||||
#if NFN_IS_ARCH(x86_64)
|
||||
__m256 m256;
|
||||
#endif
|
||||
float f32[8];
|
||||
@@ -86,7 +86,7 @@ typedef union M256{
|
||||
}M256;
|
||||
|
||||
typedef union M512{
|
||||
#if NIF_IS_ARCH(x86_64)
|
||||
#if NFN_IS_ARCH(x86_64)
|
||||
__m512 m512;
|
||||
#endif
|
||||
uint64_t u64[8];
|
||||
@@ -97,24 +97,24 @@ typedef union M512{
|
||||
int64_t i64[8];
|
||||
}M512;
|
||||
|
||||
typedef struct nif_L4_cache_head {
|
||||
typedef struct nfn_L4_cache_head {
|
||||
uint64_t reverse_mask_0;
|
||||
uint32_t position_mask;
|
||||
uint32_t size;
|
||||
uint64_t reverse_mask_1;
|
||||
uint64_t reverse_mask_2;
|
||||
} nif_L4_cache_head;
|
||||
} nfn_L4_cache_head;
|
||||
|
||||
typedef struct nif_L4_handle {
|
||||
typedef struct nfn_L4_handle {
|
||||
void *ptr;
|
||||
nif_L4_cache_head* head;
|
||||
} nif_L4_handle;
|
||||
nfn_L4_cache_head* head;
|
||||
} nfn_L4_handle;
|
||||
|
||||
typedef struct matrix_task {
|
||||
nif_L4_handle buffer_0;
|
||||
nif_L4_handle buffer_1;
|
||||
nif_L4_handle buffer_2;
|
||||
nif_L4_handle buffer_3;
|
||||
nfn_L4_handle buffer_0;
|
||||
nfn_L4_handle buffer_1;
|
||||
nfn_L4_handle buffer_2;
|
||||
nfn_L4_handle buffer_3;
|
||||
union {
|
||||
struct {
|
||||
int32_t reverse_0;
|
||||
@@ -144,18 +144,18 @@ static_assert(sizeof(matrix_task) == 128, "matrix_parallel_task_package size mis
|
||||
static_assert(sizeof(matrix_task) == 128, "matrix_parallel_task_package size mismatch");
|
||||
#endif
|
||||
|
||||
typedef void(NIF_DECL *UNI_MK_PROC)(matrix_task *task);
|
||||
typedef void(NIF_DECL *UNI_SK_PROC)(mat_kernel const *left, mat_kernel const *right,
|
||||
typedef void(NFN_DECL *UNI_MK_PROC)(matrix_task *task);
|
||||
typedef void(NFN_DECL *UNI_SK_PROC)(mat_kernel const *left, mat_kernel const *right,
|
||||
mat_kernel *restrict ans, uint64_t scalar);
|
||||
|
||||
typedef void(NIF_DECL *VECTORNORMALIZEPROC)(VEC_SEGMENT(float) *source, VEC_SEGMENT(float) *target);
|
||||
typedef void(NIF_DECL *DOTPROC)(void *transpose, __m128 *vector, __m128 *ans);
|
||||
typedef uint64_t(NIF_DECL *FACTORIALROC)(int n);
|
||||
typedef void(NFN_DECL *VECTORNORMALIZEPROC)(VEC_SEGMENT(float) *source, VEC_SEGMENT(float) *target);
|
||||
typedef void(NFN_DECL *DOTPROC)(void *transpose, __m128 *vector, __m128 *ans);
|
||||
typedef uint64_t(NFN_DECL *FACTORIALROC)(int n);
|
||||
|
||||
#pragma region string
|
||||
|
||||
typedef int(NIF_DECL *HASH)(byte const *str, int length);
|
||||
typedef int(NIF_DECL *INDEX_PAIR)(short const *stram, uint32_t target, int length);
|
||||
typedef int(NFN_DECL *HASH)(byte const *str, int length);
|
||||
typedef int(NFN_DECL *INDEX_PAIR)(short const *stram, uint32_t target, int length);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
@@ -168,13 +168,13 @@ typedef struct mat_sk_intrinsic {
|
||||
} mat_sk_intrinsic;
|
||||
|
||||
// Mirrors C# IntrinsicContext field order so managed/unmanaged layouts stay in sync.
|
||||
typedef struct nif_intrinsic {
|
||||
typedef struct nfn_intrinsic {
|
||||
HASH city_hash_simplify;
|
||||
FACTORIALROC factorial_simd;
|
||||
VECTORNORMALIZEPROC vec_f32_normalize_3;
|
||||
mat_mk_intrinsic mat_mk[0x0a];
|
||||
mat_sk_intrinsic mat_sk[0x0a];
|
||||
} nif_intrinsic;
|
||||
} nfn_intrinsic;
|
||||
|
||||
|
||||
typedef enum mat_proc_index {
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef NFN_MATKERNEL
|
||||
#define NFN_MATKERNEL
|
||||
|
||||
#include <immintrin.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "nfn_internal.h"
|
||||
|
||||
/* Kernel storage unions for a fixed 4x4 block. */
|
||||
#define ELEMENTSIZE(T) sizeof(T)
|
||||
#define XMMCOUNT(T) (sizeof(T))
|
||||
#define YMMCOUNT(T) (sizeof(T) / 2)
|
||||
#define ZMMCOUNT(T) (sizeof(T) / 4)
|
||||
|
||||
#define NFN_MAT_KERNEL_MEMBER(T) \
|
||||
{ \
|
||||
__m128 x[XMMCOUNT(T)]; \
|
||||
__m256 y[YMMCOUNT(T)]; \
|
||||
__m512 z[ZMMCOUNT(T)]; \
|
||||
T m[4][4]; \
|
||||
}
|
||||
|
||||
#define NFN_MAT_KERNEL_DEFINE(T) \
|
||||
typedef union NFN_MAT_KERNEL_TYPE_##T NFN_MAT_KERNEL_MEMBER(T) NFN_MAT_KERNEL_TYPE_##T
|
||||
|
||||
#define MAT_KERNEL(T) NFN_MAT_KERNEL_TYPE(T)
|
||||
#define NFN_MAT_KERNEL_TYPE(T) NFN_MAT_KERNEL_TYPE_##T
|
||||
|
||||
NFN_MAT_KERNEL_DEFINE(float);
|
||||
NFN_MAT_KERNEL_DEFINE(double);
|
||||
NFN_MAT_KERNEL_DEFINE(uint64_t);
|
||||
|
||||
|
||||
#define NFN_VEC_SEGMENT_MEMBER(T) \
|
||||
{ \
|
||||
__m128 f32_x[XMMCOUNT(T) / 4]; \
|
||||
__m256 f32_y[YMMCOUNT(T) / 4]; \
|
||||
__m512 f32_z[ZMMCOUNT(T) / 4]; \
|
||||
T v[4]; \
|
||||
}
|
||||
|
||||
#define NFN_VEC_SEGMENT_DEFINE(T) \
|
||||
typedef union NFN_VEC_SEGMENT_TYPE_##T NFN_VEC_SEGMENT_MEMBER(T) NFN_VEC_SEGMENT_TYPE_##T
|
||||
|
||||
#define VEC_SEGMENT(T) NFN_VEC_SEGMENT_TYPE(T)
|
||||
#define NFN_VEC_SEGMENT_TYPE(T) NFN_VEC_SEGMENT_TYPE_##T
|
||||
|
||||
NFN_VEC_SEGMENT_DEFINE(float);
|
||||
NFN_VEC_SEGMENT_DEFINE(double);
|
||||
|
||||
/* Global zero kernel declaration (defined in dllmain.c), aligned to 64 bytes */
|
||||
extern __declspec(align(64)) MAT_KERNEL(u64) NFN_ZERO_KERNEL;
|
||||
|
||||
#endif /* NFN_MATKERNEL */
|
||||
@@ -0,0 +1,101 @@
|
||||
#ifndef NFN_INTRINSIC_CALLCONV_STD
|
||||
#define NFN_INTRINSIC_CALLCONV_STD
|
||||
|
||||
#include "nfn_internal.h"
|
||||
#include "nfn_intrinsic.h"
|
||||
|
||||
#ifndef static_assert
|
||||
#define static_assert _Static_assert
|
||||
#endif
|
||||
|
||||
#define NFN_STD_TARGET_ATTR(T_arch, T_feature) NFN_STD_TARGET_ATTR_IMPL(T_arch, T_feature)
|
||||
|
||||
#pragma region mk_proc attributes
|
||||
#define MK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op) \
|
||||
T_type##_multi_kernel_proc_##T_op##_##T_arch##_##T_feature
|
||||
#define GET_MK_PROC_STD(T_type, T_arch, T_feature, T_op) \
|
||||
((UNI_MK_PROC)MK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op))
|
||||
#define NFN_MK_PROC_DECL(T_type, P_name) INTERNAL void NFN_DECL P_name(MAT_TASK(T_type) const *task)
|
||||
#define NFN_MK_PROC_DECL_STD(T_type, T_arch, T_feature, T_op) \
|
||||
INTERNAL NOINLINE NFN_STD_TARGET_ATTR(T_arch, T_feature) void NFN_DECL MK_PROC_NAME_STD( \
|
||||
T_type, T_arch, T_feature, T_op)(MAT_TASK(T_type) const *task)
|
||||
#pragma endregion
|
||||
|
||||
#pragma region sk_proc attributes
|
||||
#define SK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op) \
|
||||
T_type##_single_kernel_proc_##T_op##_##T_arch##_##T_feature
|
||||
#define GET_SK_PROC_STD(T_type, T_arch, T_feature, T_op) \
|
||||
((UNI_SK_PROC)SK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op))
|
||||
#define NFN_SK_PROC_DECL_STD(T_type, T_arch, T_feature, T_op) \
|
||||
INTERNAL NOINLINE NFN_STD_TARGET_ATTR(T_arch, T_feature) void NFN_DECL SK_PROC_NAME_STD( \
|
||||
T_type, T_arch, T_feature, \
|
||||
T_op)(MAT_KERNEL(T_type) const *left, MAT_KERNEL(T_type) const *right, \
|
||||
MAT_KERNEL(T_type) *restrict ans, uint64_t scalar)
|
||||
#pragma endregion
|
||||
|
||||
#define _NFN_STD__PROBE_0 0
|
||||
#define _NFN_STD__PROBE_1 1
|
||||
#define NFN_STD__PROBE_PRINT(x) _NFN_STD__PROBE_##x
|
||||
#define NFN_STD__PROBE(x) NFN_STD__PROBE_PRINT(x)
|
||||
|
||||
#pragma region param styles
|
||||
|
||||
#define _NFN_MATPROC_LEFT_RIGHT_ANS 1
|
||||
#define _NFN_MATPROC_RIGHT_ANS 1
|
||||
#define _NFN_MATPROC_LEFT_RIGHT_ANS_SCALAR 1
|
||||
#define _NFN_MATPROC_RIGHT_ANS_SCALAR 1
|
||||
#define _NFN_MATPROC_ANS_SCALAR 1
|
||||
|
||||
#define _NFN_MK_EXPAND_BUFFER_SIZE(i)\
|
||||
int offset_##i = task->offset_##i;\
|
||||
int count_##i = task->count_##i;\
|
||||
|
||||
#define _NFN_MK_EXPAND_RIGHT_ANS \
|
||||
NFN_MAT_KERNEL_LOCAL const *right = (NFN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans = (NFN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr;\
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(1); \
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _NFN_MK_EXPAND_LEFT_RIGHT_ANS \
|
||||
NFN_MAT_KERNEL_LOCAL const *left = (NFN_MAT_KERNEL_LOCAL const *)task->buffer_0.ptr; \
|
||||
NFN_MAT_KERNEL_LOCAL const *right = (NFN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans = (NFN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr;\
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(0); \
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(1);\
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _NFN_MK_EXPAND_RIGHT_ANS_SCALAR \
|
||||
NFN_MAT_KERNEL_LOCAL const *right = (NFN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans = (NFN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
M128 scalar = task->scalar_pack;\
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(1);\
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _NFN_MK_EXPAND_LEFT_RIGHT_ANS_SCALAR \
|
||||
NFN_MAT_KERNEL_LOCAL const *left = (NFN_MAT_KERNEL_LOCAL const *)task->buffer_0.ptr; \
|
||||
NFN_MAT_KERNEL_LOCAL const *right = (NFN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans = (NFN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
M128 scalar = task->scalar_pack;\
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(0);\
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(1);\
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _NFN_MK_EXPAND_ANS_SCALAR \
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans = (NFN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
M128 scalar = task->scalar_pack;\
|
||||
_NFN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _NFN_PARAM_STYLE(T) _NFN_MATPROC_##T
|
||||
#define _NFN_MK_EXPAND_PARAM(style) _NFN_MK_EXPAND_##style
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#define __mk_param_std(param, T) \
|
||||
typedef MAT_KERNEL(T) NFN_MAT_KERNEL_LOCAL; \
|
||||
matrix_task const *_ = (_NFN_PARAM_STYLE(param), task); \
|
||||
_NFN_MK_EXPAND_PARAM(param)
|
||||
|
||||
#define __sk_param_std(T) \
|
||||
typedef MAT_KERNEL(T) NFN_MAT_KERNEL_LOCAL; \
|
||||
(void)scalar
|
||||
#endif // !NFN_INTRINSIC_PARAM_EXPAND
|
||||
@@ -0,0 +1,94 @@
|
||||
#ifndef NFN_TARGET
|
||||
#define NFN_TARGET
|
||||
|
||||
#include "nfn_internal.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define NFN_OS_WINDOWS 0
|
||||
#define NFN_OS_LINUX 1
|
||||
#define NFN_OS_MACOS 2
|
||||
#define NFN_OS_IOS 3
|
||||
#define NFN_OS_ANDROID 4
|
||||
#define NFN_OS_UNKNOWN 5
|
||||
|
||||
#define NFN_ARCH_X86_64 0
|
||||
#define NFN_ARCH_ARM64 1
|
||||
#define NFN_ARCH_RISCV64 2
|
||||
#define NFN_ARCH_PPC64le 3
|
||||
|
||||
#if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__amd64__)
|
||||
#define NFN_CURRENT_ARCH NFN_ARCH_X86_64
|
||||
|
||||
#elif defined(_M_ARM64) || defined(__aarch64__)
|
||||
#define NFN_CURRENT_ARCH NFN_ARCH_ARM64
|
||||
|
||||
#elif defined(_M_ARM) || defined(__arm__)
|
||||
#define NFN_CURRENT_ARCH NFN_ARCH_ARM32
|
||||
|
||||
#elif defined(_M_IX86) || defined(__i386__)
|
||||
#define NFN_CURRENT_ARCH NFN_ARCH_X86_32
|
||||
|
||||
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)
|
||||
#define NFN_CURRENT_ARCH NFN_ARCH_PPC64LE
|
||||
|
||||
#elif defined(__riscv) && (__riscv_xlen == 64)
|
||||
#define NFN_CURRENT_ARCH NFN_ARCH_RISCV64
|
||||
|
||||
#else
|
||||
#error "SN: Unsupported target architecture"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Target selection policy:
|
||||
* - Default (no NFN_EXTERN_TARGET): fixed Windows + x86_64.
|
||||
* - External (NFN_EXTERN_TARGET): build system must provide NFN_OS and NFN_ARCH.
|
||||
*/
|
||||
#ifndef NFN_EXTERN_TARGET
|
||||
|
||||
#define NFN_OS_TARGET NFN_OS_WINDOWS
|
||||
#define NFN_ARCH_TARGET NFN_ARCH_X86_64
|
||||
|
||||
#else
|
||||
|
||||
#ifndef NFN_OS_TARGET
|
||||
#error "NFN_EXTERN_TARGET is defined but NFN_OS is not provided."
|
||||
#endif
|
||||
|
||||
#ifndef NFN_ARCH_TARGET
|
||||
#error "NFN_EXTERN_TARGET is defined but NFN_ARCH is not provided."
|
||||
#endif
|
||||
|
||||
/* Validate externally supplied values are within known enum constants. */
|
||||
#if (NFN_OS_TARGET != NFN_OS_WINDOWS) && (NFN_OS_TARGET != NFN_OS_LINUX) && \
|
||||
(NFN_OS_TARGET != NFN_OS_MACOS) && (NFN_OS_TARGET != NFN_OS_IOS) && \
|
||||
(NFN_OS_TARGET != NFN_OS_ANDROID) && (NFN_OS_TARGET != NFN_OS_UNKNOWN)
|
||||
#error "NFN_OS has an invalid value. Use NFN_OS_<...> enum constants."
|
||||
#endif
|
||||
|
||||
#if (NFN_ARCH_TARGET != NFN_ARCH_X86_64) && (NFN_ARCH_TARGET != NFN_ARCH_ARM64) && \
|
||||
(NFN_ARCH_TARGET != NFN_ARCH_RISCV64) && (NFN_ARCH_TARGET != NFN_ARCH_PPC64le)
|
||||
#error "NFN_ARCH has an invalid value. Use NFN_ARCH_<...> enum constants."
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define NFN_IS_OS(os) ((NFN_OS_TARGET) == (os))
|
||||
|
||||
#define NFN_IS_ARCH(arch) ((NFN_ARCH_TARGET) == (arch))
|
||||
|
||||
/*
|
||||
* Per-function ISA selection is required for runtime-dispatched kernels that
|
||||
* mix multiple x86 feature levels in one build target.
|
||||
*/
|
||||
#if defined(__clang__) && ((NFN_ARCH_TARGET) == NFN_ARCH_X86_64)
|
||||
#define NFN_CLANG_TARGET_ATTR(options) __attribute__((target(options)))
|
||||
#else
|
||||
#define NFN_CLANG_TARGET_ATTR(options)
|
||||
#endif
|
||||
|
||||
typedef union SIMDID {
|
||||
uint64_t mask;
|
||||
char make_byte[8];
|
||||
} SIMDID;
|
||||
|
||||
#endif // NFN_TARGET
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "NitloadFrameWork.h"
|
||||
#include "nif_intrinsic.matkernel.h"
|
||||
#include "nfn_intrinsic.matkernel.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* Define and initialize a global zero kernel aligned to 64 bytes for universal ISA usage */
|
||||
|
||||
__declspec(align(64)) MAT_KERNEL(u64) NIF_ZERO_KERNEL;
|
||||
__declspec(align(64)) MAT_KERNEL(u64) NFN_ZERO_KERNEL;
|
||||
|
||||
static void init_zero_kernel(void)
|
||||
{
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
for (int r = 0; r < 4; ++r) {
|
||||
NIF_ZERO_KERNEL.m[r][c] = 0;
|
||||
NFN_ZERO_KERNEL.m[r][c] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "NitloadFrameWork.h"
|
||||
|
||||
NIF_API void NIF_DECL nif_load_glfw_functions(GLFWFunctionTable *table)
|
||||
NFN_API void NFN_DECL nfn_load_glfw_functions(GLFWFunctionTable *table)
|
||||
{
|
||||
table->glfwCreateCursor = glfwCreateCursor;
|
||||
table->glfwCreateStandardCursor = glfwCreateStandardCursor;
|
||||
+15
-15
@@ -1,28 +1,28 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include "NitloadFrameWork.h"
|
||||
#include "nif_intrinsic.h"
|
||||
#include "nif_intrinsic.std.h"
|
||||
#include "nif_intrinsic.context.x86.h"
|
||||
#include "nfn_intrinsic.h"
|
||||
#include "nfn_intrinsic.std.h"
|
||||
#include "nfn_intrinsic.context.x86.h"
|
||||
|
||||
PRIVATE void load_intrinsic_sse(nif_intrinsic *context, SIMDID id);
|
||||
PRIVATE void load_intrinsic_avx(nif_intrinsic *context, SIMDID id);
|
||||
PRIVATE void load_intrinsic_512(nif_intrinsic *context, SIMDID id);
|
||||
PRIVATE void load_intrinsic_sse(nfn_intrinsic *context, SIMDID id);
|
||||
PRIVATE void load_intrinsic_avx(nfn_intrinsic *context, SIMDID id);
|
||||
PRIVATE void load_intrinsic_512(nfn_intrinsic *context, SIMDID id);
|
||||
|
||||
NIF_API void NIF_DECL nif_load_intrinsic_function(void *intrinsic_context, uint64_t id)
|
||||
NFN_API void NFN_DECL nfn_load_intrinsic_function(void *intrinsic_context, uint64_t id)
|
||||
{
|
||||
nif_null_assert(intrinsic_context);
|
||||
nfn_null_assert(intrinsic_context);
|
||||
|
||||
SIMDID simdid;
|
||||
if (id) {
|
||||
simdid.mask = id;
|
||||
} else {
|
||||
simdid = nif_get_simd_level_global();
|
||||
simdid = nfn_get_simd_level_global();
|
||||
}
|
||||
|
||||
nif_intrinsic *context = (nif_intrinsic *)intrinsic_context;
|
||||
nfn_intrinsic *context = (nfn_intrinsic *)intrinsic_context;
|
||||
|
||||
switch (simdid.make_byte[1]) {
|
||||
case SIMDID_MAIN_LVL_SSE:
|
||||
@@ -38,7 +38,7 @@ NIF_API void NIF_DECL nif_load_intrinsic_function(void *intrinsic_context, uint6
|
||||
}
|
||||
}
|
||||
|
||||
void load_intrinsic_sse(nif_intrinsic *context, SIMDID id)
|
||||
void load_intrinsic_sse(nfn_intrinsic *context, SIMDID id)
|
||||
{
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
@@ -62,7 +62,7 @@ void load_intrinsic_sse(nif_intrinsic *context, SIMDID id)
|
||||
context->vec_f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
void load_intrinsic_avx(nif_intrinsic *context, SIMDID id)
|
||||
void load_intrinsic_avx(nfn_intrinsic *context, SIMDID id)
|
||||
{
|
||||
char avx_seg = id.make_byte[4];
|
||||
char is_fma = (avx_seg & SIMDID_AVX_FMA) != 0;
|
||||
@@ -91,7 +91,7 @@ void load_intrinsic_avx(nif_intrinsic *context, SIMDID id)
|
||||
context->vec_f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
void load_intrinsic_512(nif_intrinsic *context, SIMDID id)
|
||||
void load_intrinsic_512(nfn_intrinsic *context, SIMDID id)
|
||||
{
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
+29
-29
@@ -1,13 +1,13 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include <immintrin.h>
|
||||
#include "nif_intrinsic.h"
|
||||
#include "nif_intrinsic.std.h"
|
||||
#include "nif_intrinsic.context.x86.h"
|
||||
#include "nfn_intrinsic.h"
|
||||
#include "nfn_intrinsic.std.h"
|
||||
#include "nfn_intrinsic.context.x86.h"
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , fill)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , fill)
|
||||
{
|
||||
__mk_param_std(ANS_SCALAR, float);
|
||||
register __m128 vec = _mm_set_ps1(scalar.f32[0]);
|
||||
@@ -19,7 +19,7 @@ NIF_MK_PROC_DECL_STD(float, sse, , fill)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , fill)
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , fill)
|
||||
{
|
||||
__mk_param_std(ANS_SCALAR, float);
|
||||
register __m256 vec = _mm256_broadcast_ss(&scalar.f32[0]);
|
||||
@@ -29,7 +29,7 @@ NIF_MK_PROC_DECL_STD(float, avx, , fill)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , fill)
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , fill)
|
||||
{
|
||||
__mk_param_std(ANS_SCALAR, float);
|
||||
register __m512 vec = _mm512_broadcastss_ps(scalar.m128);
|
||||
@@ -38,7 +38,7 @@ NIF_MK_PROC_DECL_STD(float, 512, , fill)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , fill)
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , fill)
|
||||
{
|
||||
__mk_param_std(ANS_SCALAR, double);
|
||||
register __m128d vec_d = _mm_set1_pd(scalar.f64[0]);
|
||||
@@ -55,7 +55,7 @@ NIF_MK_PROC_DECL_STD(double, sse, , fill)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , fill)
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , fill)
|
||||
{
|
||||
__mk_param_std(ANS_SCALAR, double);
|
||||
register __m256d vec = _mm256_broadcast_sd(&scalar.f64[0]);
|
||||
@@ -67,7 +67,7 @@ NIF_MK_PROC_DECL_STD(double, avx, , fill)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , fill)
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , fill)
|
||||
{
|
||||
__mk_param_std(ANS_SCALAR, double);
|
||||
register __m512d vec = _mm512_set1_pd(scalar.f64[0]);
|
||||
@@ -77,7 +77,7 @@ NIF_MK_PROC_DECL_STD(double, 512, , fill)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , add)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , add)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, float);
|
||||
|
||||
@@ -94,7 +94,7 @@ NIF_MK_PROC_DECL_STD(float, sse, , add)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , add)
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , add)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, float);
|
||||
|
||||
@@ -107,7 +107,7 @@ NIF_MK_PROC_DECL_STD(float, avx, , add)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , add)
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , add)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, float);
|
||||
|
||||
@@ -116,7 +116,7 @@ NIF_MK_PROC_DECL_STD(float, 512, , add)
|
||||
ans[i].z[0] = c0;
|
||||
}
|
||||
}
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , add)
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , add)
|
||||
{
|
||||
__mk_param_std( LEFT_RIGHT_ANS, double);
|
||||
|
||||
@@ -149,7 +149,7 @@ NIF_MK_PROC_DECL_STD(double, sse, , add)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , add)
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , add)
|
||||
{
|
||||
__mk_param_std( LEFT_RIGHT_ANS, double);
|
||||
|
||||
@@ -166,7 +166,7 @@ NIF_MK_PROC_DECL_STD(double, avx, , add)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , add)
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , add)
|
||||
{
|
||||
__mk_param_std( LEFT_RIGHT_ANS, double);
|
||||
|
||||
@@ -178,7 +178,7 @@ NIF_MK_PROC_DECL_STD(double, 512, , add)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , sub)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , sub)
|
||||
{
|
||||
__mk_param_std( LEFT_RIGHT_ANS, float);
|
||||
|
||||
@@ -195,7 +195,7 @@ NIF_MK_PROC_DECL_STD(float, sse, , sub)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , sub)
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , sub)
|
||||
{
|
||||
__mk_param_std( LEFT_RIGHT_ANS, float);
|
||||
|
||||
@@ -207,7 +207,7 @@ NIF_MK_PROC_DECL_STD(float, avx, , sub)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , sub)
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , sub)
|
||||
{
|
||||
__mk_param_std( LEFT_RIGHT_ANS, float);
|
||||
|
||||
@@ -217,7 +217,7 @@ NIF_MK_PROC_DECL_STD(float, 512, , sub)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , sub)
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , sub)
|
||||
{
|
||||
__mk_param_std( LEFT_RIGHT_ANS, double);
|
||||
|
||||
@@ -242,7 +242,7 @@ NIF_MK_PROC_DECL_STD(double, sse, , sub)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , sub)
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , sub)
|
||||
{
|
||||
__mk_param_std( LEFT_RIGHT_ANS, double);
|
||||
|
||||
@@ -254,7 +254,7 @@ NIF_MK_PROC_DECL_STD(double, avx, , sub)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , sub)
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , sub)
|
||||
{
|
||||
__mk_param_std( LEFT_RIGHT_ANS, double);
|
||||
|
||||
@@ -264,7 +264,7 @@ NIF_MK_PROC_DECL_STD(double, 512, , sub)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , scalar_mul)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , scalar_mul)
|
||||
{
|
||||
__mk_param_std( RIGHT_ANS_SCALAR, float);
|
||||
|
||||
@@ -282,7 +282,7 @@ NIF_MK_PROC_DECL_STD(float, sse, , scalar_mul)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , scalar_mul)
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , scalar_mul)
|
||||
{
|
||||
__mk_param_std( RIGHT_ANS_SCALAR, float);
|
||||
|
||||
@@ -296,7 +296,7 @@ NIF_MK_PROC_DECL_STD(float, avx, , scalar_mul)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , scalar_mul)
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , scalar_mul)
|
||||
{
|
||||
__mk_param_std( RIGHT_ANS_SCALAR, float);
|
||||
|
||||
@@ -308,7 +308,7 @@ NIF_MK_PROC_DECL_STD(float, 512, , scalar_mul)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , scalar_mul)
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , scalar_mul)
|
||||
{
|
||||
__mk_param_std( RIGHT_ANS_SCALAR, double);
|
||||
|
||||
@@ -334,7 +334,7 @@ NIF_MK_PROC_DECL_STD(double, sse, , scalar_mul)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , scalar_mul)
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , scalar_mul)
|
||||
{
|
||||
__mk_param_std( RIGHT_ANS_SCALAR, double);
|
||||
|
||||
@@ -352,7 +352,7 @@ NIF_MK_PROC_DECL_STD(double, avx, , scalar_mul)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , scalar_mul)
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , scalar_mul)
|
||||
{
|
||||
__mk_param_std( RIGHT_ANS_SCALAR, double);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include "nif_intrinsic.h"
|
||||
#include "nif_intrinsic.std.h"
|
||||
#include "nif_intrinsic.context.x86.h"
|
||||
#include "nfn_intrinsic.h"
|
||||
#include "nfn_intrinsic.std.h"
|
||||
#include "nfn_intrinsic.context.x86.h"
|
||||
#include <math.h>
|
||||
|
||||
static const float quality_threshold = 1e-6f;
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , try_plu)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , try_plu)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS_SCALAR, float);
|
||||
|
||||
@@ -115,7 +115,7 @@ NIF_MK_PROC_DECL_STD(float, sse, , try_plu)
|
||||
* layout of scalarpack:
|
||||
*
|
||||
*/
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , quality)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , quality)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS, float);
|
||||
|
||||
@@ -126,7 +126,7 @@ NIF_MK_PROC_DECL_STD(float, sse, , quality)
|
||||
register __m128 col2 = _mm_load_ps((float *)&right->x[2]);
|
||||
register __m128 col3 = _mm_load_ps((float *)&right->x[3]);
|
||||
|
||||
NIF_ALIGNAS(16) float self_dot_src[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
NFN_ALIGNAS(16) float self_dot_src[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
// try in reigister mix later
|
||||
DOT_F32_SSE(col0, col0, self_dot_src[0]);
|
||||
DOT_F32_SSE(col1, col1, self_dot_src[1]);
|
||||
@@ -153,7 +153,7 @@ NIF_MK_PROC_DECL_STD(float, sse, , quality)
|
||||
return;
|
||||
}
|
||||
|
||||
NIF_ALIGNAS(16) float cross_dot_src[2][4] = { 0 };
|
||||
NFN_ALIGNAS(16) float cross_dot_src[2][4] = { 0 };
|
||||
DOT_F32_SSE(col0, col1, cross_dot_src[0][0]);
|
||||
DOT_F32_SSE(col0, col2, cross_dot_src[0][1]);
|
||||
DOT_F32_SSE(col0, col3, cross_dot_src[0][2]);
|
||||
+8
-8
@@ -1,13 +1,13 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include "nif_intrinsic.h"
|
||||
#include "nif_intrinsic.context.x86.h"
|
||||
#include "nif_intrinsic.std.h"
|
||||
#include "nfn_intrinsic.h"
|
||||
#include "nfn_intrinsic.context.x86.h"
|
||||
#include "nfn_intrinsic.std.h"
|
||||
|
||||
// Matrix transpose implementations
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , transpose)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , transpose)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS, float);
|
||||
|
||||
@@ -26,7 +26,7 @@ NIF_MK_PROC_DECL_STD(float, sse, , transpose)
|
||||
ans->x[3] = _mm_movehl_ps(tmp3, tmp1);
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , transpose)
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , transpose)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS, float);
|
||||
register __m256 col_low = right->y[0];
|
||||
@@ -42,7 +42,7 @@ NIF_MK_PROC_DECL_STD(float, avx, , transpose)
|
||||
ans->y[1] = _mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(3, 1, 3, 1));
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , transpose)
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , transpose)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS, float);
|
||||
register __m512 matrix = right->z[0];
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include "nif_intrinsic.context.x86.h"
|
||||
#include "nfn_intrinsic.context.x86.h"
|
||||
|
||||
/*
|
||||
* pack left matrix data to L4 buffer
|
||||
@@ -19,14 +19,14 @@
|
||||
* scalar pack carries column length and offset data:
|
||||
* [column length, empty, empty, empty]
|
||||
*/
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , fma_pack_left)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , fma_pack_left)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS_SCALAR, float);
|
||||
// for SSE branch, no need for rounding, a direct copy is sufficient as long as the buffer is large enough to hold the packed data
|
||||
memcpy(ans, right + offset_1, sizeof(MAT_KERNEL(float)) * count_2);
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , fma_pack_left)
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , fma_pack_left)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS_SCALAR, float);
|
||||
size_t i = 0;
|
||||
@@ -61,7 +61,7 @@ NIF_MK_PROC_DECL_STD(float, avx, , fma_pack_left)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , fma_pack_left)
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , fma_pack_left)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS_SCALAR, float);
|
||||
size_t i = 0;
|
||||
@@ -154,7 +154,7 @@ NIF_MK_PROC_DECL_STD(float, 512, , fma_pack_left)
|
||||
* scalar pack carries column length and offset data:
|
||||
* [column length, empty, empty, empty]
|
||||
*/
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , fma_pack_right)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , fma_pack_right)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS_SCALAR, float);
|
||||
int col_length = scalar.i32[0];
|
||||
@@ -163,7 +163,7 @@ NIF_MK_PROC_DECL_STD(float, sse, , fma_pack_right)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , fma_pack_right)
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , fma_pack_right)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS_SCALAR, float);
|
||||
int col_length = scalar.i32[0];
|
||||
@@ -205,7 +205,7 @@ NIF_MK_PROC_DECL_STD(float, avx, , fma_pack_right)
|
||||
}
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , fma_pack_right)
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , fma_pack_right)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS_SCALAR, float);
|
||||
int col_length = scalar.i32[0];
|
||||
@@ -1,22 +1,22 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
#include <immintrin.h>
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
// #include "nif_intrinsic.h"
|
||||
#include "nif_template.fma.x86.h"
|
||||
#include "nif_intrinsic.std.h"
|
||||
#include "nif_intrinsic.context.x86.h"
|
||||
// #include "nfn_intrinsic.h"
|
||||
#include "nfn_template.fma.x86.h"
|
||||
#include "nfn_intrinsic.std.h"
|
||||
#include "nfn_intrinsic.context.x86.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define _FMA_SELECT(i) _MM_SHUFFLE(i, i, i, i)
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , fma)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , fma)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, float);
|
||||
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
|
||||
register __m128 c0 = _mm_load_ps((float *)&ans_cur->x[0]);
|
||||
register __m128 c1 = _mm_load_ps((float *)&ans_cur->x[1]);
|
||||
@@ -25,8 +25,8 @@ NIF_MK_PROC_DECL_STD(float, sse, , fma)
|
||||
register __m128 bcol;
|
||||
|
||||
for (size_t z = 0; z < count_0; z++) {
|
||||
NIF_MAT_KERNEL_LOCAL const *right_base = right;
|
||||
NIF_MAT_KERNEL_LOCAL const *left_base = left;
|
||||
NFN_MAT_KERNEL_LOCAL const *right_base = right;
|
||||
NFN_MAT_KERNEL_LOCAL const *left_base = left;
|
||||
|
||||
const __m128 a0 = _mm_load_ps((float *)&left_base->x[0]);
|
||||
const __m128 a1 = _mm_load_ps((float *)&left_base->x[1]);
|
||||
@@ -68,18 +68,18 @@ NIF_MK_PROC_DECL_STD(float, sse, , fma)
|
||||
_mm_store_ps((float *)&ans_cur->x[3], c3);
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, avx, , fma)
|
||||
NFN_MK_PROC_DECL_STD(float, avx, , fma)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, float);
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
register __m256 c0 = _mm256_load_ps((float *)&ans_cur->y[0]);
|
||||
register __m256 c1 = _mm256_load_ps((float *)&ans_cur->y[1]);
|
||||
register __m256 c2 = _mm256_load_ps((float *)&ans_cur->y[2]);
|
||||
register __m256 c3 = _mm256_load_ps((float *)&ans_cur->y[3]);
|
||||
|
||||
for (size_t z = 0; z < count_0; z++) {
|
||||
NIF_MAT_KERNEL_LOCAL const *b_base = right;
|
||||
NIF_MAT_KERNEL_LOCAL const *a_base = left;
|
||||
NFN_MAT_KERNEL_LOCAL const *b_base = right;
|
||||
NFN_MAT_KERNEL_LOCAL const *a_base = left;
|
||||
|
||||
register __m256 b0 = _mm256_load_ps((float *)&b_base->y[0]);
|
||||
register __m256 b1 = _mm256_load_ps((float *)&b_base->y[1]);
|
||||
@@ -91,10 +91,10 @@ NIF_MK_PROC_DECL_STD(float, avx, , fma)
|
||||
register __m256 a2 = _mm256_load_ps((float *)&a_base->y[2]);
|
||||
register __m256 a3 = _mm256_load_ps((float *)&a_base->y[3]);
|
||||
|
||||
NIF_MK_FMA_F32_AVX2_CYCLE(0);
|
||||
NIF_MK_FMA_F32_AVX2_CYCLE(1);
|
||||
NIF_MK_FMA_F32_AVX2_CYCLE(2);
|
||||
NIF_MK_FMA_F32_AVX2_CYCLE(3);
|
||||
NFN_MK_FMA_F32_AVX2_CYCLE(0);
|
||||
NFN_MK_FMA_F32_AVX2_CYCLE(1);
|
||||
NFN_MK_FMA_F32_AVX2_CYCLE(2);
|
||||
NFN_MK_FMA_F32_AVX2_CYCLE(3);
|
||||
}
|
||||
_mm256_store_ps((float *)&(ans_cur->y[0]), c0);
|
||||
_mm256_store_ps((float *)&(ans_cur->y[1]), c1);
|
||||
@@ -102,18 +102,18 @@ NIF_MK_PROC_DECL_STD(float, avx, , fma)
|
||||
_mm256_store_ps((float *)&(ans_cur->y[3]), c3);
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, avx, _fma, fma)
|
||||
NFN_MK_PROC_DECL_STD(float, avx, _fma, fma)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, float);
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
register __m256 c0 = _mm256_load_ps((float *)&ans_cur->y[0]);
|
||||
register __m256 c1 = _mm256_load_ps((float *)&ans_cur->y[1]);
|
||||
register __m256 c2 = _mm256_load_ps((float *)&ans_cur->y[2]);
|
||||
register __m256 c3 = _mm256_load_ps((float *)&ans_cur->y[3]);
|
||||
|
||||
for (size_t z = 0; z < count_0; z += 2) {
|
||||
const NIF_MAT_KERNEL_LOCAL *a_base = left + z;
|
||||
const NIF_MAT_KERNEL_LOCAL *b_base = right + z;
|
||||
const NFN_MAT_KERNEL_LOCAL *a_base = left + z;
|
||||
const NFN_MAT_KERNEL_LOCAL *b_base = right + z;
|
||||
|
||||
register __m256 b0 = _mm256_load_ps((float *)&b_base->y[0]);
|
||||
register __m256 b1 = _mm256_load_ps((float *)&b_base->y[1]);
|
||||
@@ -125,10 +125,10 @@ NIF_MK_PROC_DECL_STD(float, avx, _fma, fma)
|
||||
register __m256 a2 = _mm256_load_ps((float *)&a_base->y[2]);
|
||||
register __m256 a3 = _mm256_load_ps((float *)&a_base->y[3]);
|
||||
|
||||
NIF_MK_FMA_F32_AVX2_CYCLE(0);
|
||||
NIF_MK_FMA_F32_AVX2_CYCLE(1);
|
||||
NIF_MK_FMA_F32_AVX2_CYCLE(2);
|
||||
NIF_MK_FMA_F32_AVX2_CYCLE(3);
|
||||
NFN_MK_FMA_F32_AVX2_CYCLE(0);
|
||||
NFN_MK_FMA_F32_AVX2_CYCLE(1);
|
||||
NFN_MK_FMA_F32_AVX2_CYCLE(2);
|
||||
NFN_MK_FMA_F32_AVX2_CYCLE(3);
|
||||
}
|
||||
_mm256_store_ps((float *)&(ans_cur->y[0]), c0);
|
||||
_mm256_store_ps((float *)&(ans_cur->y[1]), c1);
|
||||
@@ -136,18 +136,18 @@ NIF_MK_PROC_DECL_STD(float, avx, _fma, fma)
|
||||
_mm256_store_ps((float *)&(ans_cur->y[3]), c3);
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, 512, , fma)
|
||||
NFN_MK_PROC_DECL_STD(float, 512, , fma)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, float);
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
register __m512 c0 = _mm512_load_ps((float *)&ans_cur->z[0]);
|
||||
register __m512 c1 = _mm512_load_ps((float *)&ans_cur->z[0]);
|
||||
register __m512 c2 = _mm512_load_ps((float *)&ans_cur->z[0]);
|
||||
register __m512 c3 = _mm512_load_ps((float *)&ans_cur->z[0]);
|
||||
|
||||
for (size_t z = 0; z < count_0; z += 4) {
|
||||
const NIF_MAT_KERNEL_LOCAL *a_base = left + z;
|
||||
const NIF_MAT_KERNEL_LOCAL *b_base = right + z;
|
||||
const NFN_MAT_KERNEL_LOCAL *a_base = left + z;
|
||||
const NFN_MAT_KERNEL_LOCAL *b_base = right + z;
|
||||
|
||||
register __m512 b0 = _mm512_load_ps((float *)&b_base->z[0]);
|
||||
register __m512 b1 = _mm512_load_ps((float *)&b_base->z[1]);
|
||||
@@ -159,10 +159,10 @@ NIF_MK_PROC_DECL_STD(float, 512, , fma)
|
||||
register __m512 a2 = _mm512_load_ps((float *)&a_base->z[2]);
|
||||
register __m512 a3 = _mm512_load_ps((float *)&a_base->z[3]);
|
||||
|
||||
NIF_MK_FMA_F32_512_CYCLE(0);
|
||||
NIF_MK_FMA_F32_512_CYCLE(1);
|
||||
NIF_MK_FMA_F32_512_CYCLE(2);
|
||||
NIF_MK_FMA_F32_512_CYCLE(3);
|
||||
NFN_MK_FMA_F32_512_CYCLE(0);
|
||||
NFN_MK_FMA_F32_512_CYCLE(1);
|
||||
NFN_MK_FMA_F32_512_CYCLE(2);
|
||||
NFN_MK_FMA_F32_512_CYCLE(3);
|
||||
}
|
||||
_mm512_store_ps((float *)&ans_cur->z[0], c0);
|
||||
_mm512_store_ps((float *)&ans_cur->z[1], c1);
|
||||
@@ -170,11 +170,11 @@ NIF_MK_PROC_DECL_STD(float, 512, , fma)
|
||||
_mm512_store_ps((float *)&ans_cur->z[3], c3);
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, sse, , fma)
|
||||
NFN_MK_PROC_DECL_STD(double, sse, , fma)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, double);
|
||||
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
|
||||
register __m128d c0_lo = ans_cur->x[0];
|
||||
register __m128d c0_hi = ans_cur->x[1];
|
||||
@@ -186,18 +186,18 @@ NIF_MK_PROC_DECL_STD(double, sse, , fma)
|
||||
register __m128d c3_hi = ans_cur->x[7];
|
||||
|
||||
for (size_t z = 0; z < count_0; z++) {
|
||||
NIF_MAT_KERNEL_LOCAL const *right_base = right;
|
||||
NIF_MAT_KERNEL_LOCAL const *left_base = left;
|
||||
NFN_MAT_KERNEL_LOCAL const *right_base = right;
|
||||
NFN_MAT_KERNEL_LOCAL const *left_base = left;
|
||||
const double *right_values = &right_base->m[0][0];
|
||||
const double *left_values = &left_base->m[0][0];
|
||||
|
||||
NIF_MK_FMA_F64_SSE_PHASE(0);
|
||||
NFN_MK_FMA_F64_SSE_PHASE(0);
|
||||
|
||||
NIF_MK_FMA_F64_SSE_PHASE(1);
|
||||
NFN_MK_FMA_F64_SSE_PHASE(1);
|
||||
|
||||
NIF_MK_FMA_F64_SSE_PHASE(2);
|
||||
NFN_MK_FMA_F64_SSE_PHASE(2);
|
||||
|
||||
NIF_MK_FMA_F64_SSE_PHASE(3);
|
||||
NFN_MK_FMA_F64_SSE_PHASE(3);
|
||||
}
|
||||
|
||||
ans_cur->x[0] = c0_lo;
|
||||
@@ -210,11 +210,11 @@ NIF_MK_PROC_DECL_STD(double, sse, , fma)
|
||||
ans_cur->x[7] = c3_hi;
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, avx, , fma)
|
||||
NFN_MK_PROC_DECL_STD(double, avx, , fma)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, double);
|
||||
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
|
||||
register __m256d c0 = _mm256_load_pd((double *)&ans_cur->y[0]);
|
||||
register __m256d c1 = _mm256_load_pd((double *)&ans_cur->y[1]);
|
||||
@@ -223,8 +223,8 @@ NIF_MK_PROC_DECL_STD(double, avx, , fma)
|
||||
register __m256d bcol;
|
||||
|
||||
for (size_t z = 0; z < count_0; z++) {
|
||||
NIF_MAT_KERNEL_LOCAL const *right_base = right;
|
||||
NIF_MAT_KERNEL_LOCAL const *left_base = left;
|
||||
NFN_MAT_KERNEL_LOCAL const *right_base = right;
|
||||
NFN_MAT_KERNEL_LOCAL const *left_base = left;
|
||||
|
||||
const __m256d a0 = _mm256_load_pd((double *)&left_base->y[0]);
|
||||
const __m256d a1 = _mm256_load_pd((double *)&left_base->y[1]);
|
||||
@@ -282,11 +282,11 @@ NIF_MK_PROC_DECL_STD(double, avx, , fma)
|
||||
_mm256_store_pd((double *)&ans_cur->y[3], c3);
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, avx, _fma, fma)
|
||||
NFN_MK_PROC_DECL_STD(double, avx, _fma, fma)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, double);
|
||||
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
|
||||
register __m256d c0 = _mm256_load_pd((double *)&ans_cur->y[0]);
|
||||
register __m256d c1 = _mm256_load_pd((double *)&ans_cur->y[1]);
|
||||
@@ -295,8 +295,8 @@ NIF_MK_PROC_DECL_STD(double, avx, _fma, fma)
|
||||
register __m256d bcol;
|
||||
|
||||
for (size_t z = 0; z < count_0; z++) {
|
||||
NIF_MAT_KERNEL_LOCAL const *right_base = right;
|
||||
NIF_MAT_KERNEL_LOCAL const *left_base = left;
|
||||
NFN_MAT_KERNEL_LOCAL const *right_base = right;
|
||||
NFN_MAT_KERNEL_LOCAL const *left_base = left;
|
||||
|
||||
const __m256d a0 = _mm256_load_pd((double *)&left_base->y[0]);
|
||||
const __m256d a1 = _mm256_load_pd((double *)&left_base->y[1]);
|
||||
@@ -338,10 +338,10 @@ NIF_MK_PROC_DECL_STD(double, avx, _fma, fma)
|
||||
_mm256_store_pd((double *)&ans_cur->y[3], c3);
|
||||
}
|
||||
|
||||
NIF_MK_PROC_DECL_STD(double, 512, , fma)
|
||||
NFN_MK_PROC_DECL_STD(double, 512, , fma)
|
||||
{
|
||||
__mk_param_std(LEFT_RIGHT_ANS, double);
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
NFN_MAT_KERNEL_LOCAL *restrict ans_cur = ans + offset_2;
|
||||
|
||||
register __m512d c0 = _mm512_load_pd((double *)&ans_cur->z[0]);
|
||||
register __m512d c1 = _mm512_load_pd((double *)&ans_cur->z[1]);
|
||||
@@ -349,8 +349,8 @@ NIF_MK_PROC_DECL_STD(double, 512, , fma)
|
||||
register __m512d c3 = _mm512_load_pd((double *)&ans_cur->z[3]);
|
||||
|
||||
for (size_t z = 0; z < count_0; z += 2) {
|
||||
NIF_MAT_KERNEL_LOCAL const *right_base = right + z;
|
||||
NIF_MAT_KERNEL_LOCAL const *left_base = left + z;
|
||||
NFN_MAT_KERNEL_LOCAL const *right_base = right + z;
|
||||
NFN_MAT_KERNEL_LOCAL const *left_base = left + z;
|
||||
|
||||
register __m512d a0 = _mm512_load_pd((double *)&left_base->z[0]);
|
||||
register __m512d a1 = _mm512_load_pd((double *)&left_base->z[1]);
|
||||
@@ -362,10 +362,10 @@ NIF_MK_PROC_DECL_STD(double, 512, , fma)
|
||||
register __m512d b2 = _mm512_load_pd((double *)&right_base->z[2]);
|
||||
register __m512d b3 = _mm512_load_pd((double *)&right_base->z[3]);
|
||||
|
||||
NIF_MK_FMA_F64_AVX2_CYCLE(0);
|
||||
NIF_MK_FMA_F64_AVX2_CYCLE(1);
|
||||
NIF_MK_FMA_F64_AVX2_CYCLE(2);
|
||||
NIF_MK_FMA_F64_AVX2_CYCLE(3);
|
||||
NFN_MK_FMA_F64_AVX2_CYCLE(0);
|
||||
NFN_MK_FMA_F64_AVX2_CYCLE(1);
|
||||
NFN_MK_FMA_F64_AVX2_CYCLE(2);
|
||||
NFN_MK_FMA_F64_AVX2_CYCLE(3);
|
||||
}
|
||||
_mm512_store_pd((double *)&ans_cur->z[0], c0);
|
||||
_mm512_store_pd((double *)&ans_cur->z[1], c1);
|
||||
+10
-10
@@ -1,25 +1,25 @@
|
||||
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include "nif_internal.h"
|
||||
#include "nif_intrinsic.context.x86.h"
|
||||
#include "nif_intrinsic.std.h"
|
||||
#include "nif_intrinsic.matkernel.h"
|
||||
#include "nfn_internal.h"
|
||||
#include "nfn_intrinsic.context.x86.h"
|
||||
#include "nfn_intrinsic.std.h"
|
||||
#include "nfn_intrinsic.matkernel.h"
|
||||
#include <emmintrin.h>
|
||||
#include <immintrin.h>
|
||||
#include <pmmintrin.h>
|
||||
|
||||
NIF_MK_PROC_DECL_STD(float, sse, , k_quality)
|
||||
NFN_MK_PROC_DECL_STD(float, sse, , k_quality)
|
||||
{
|
||||
__mk_param_std(RIGHT_ANS_SCALAR, float);
|
||||
}
|
||||
|
||||
INTERNAL NIF_STD_TARGET_ATTR(sse, ) void kp_check_f32(mat_kernel *kernel)
|
||||
INTERNAL NFN_STD_TARGET_ATTR(sse, ) void kp_check_f32(mat_kernel *kernel)
|
||||
{
|
||||
typedef MAT_KERNEL(float) NIF_MAT;
|
||||
NIF_MAT const *k = (NIF_MAT const *)kernel;
|
||||
typedef MAT_KERNEL(float) NFN_MAT;
|
||||
NFN_MAT const *k = (NFN_MAT const *)kernel;
|
||||
float cross[4];
|
||||
cross[0] = k->m[0][0];
|
||||
cross[1] = k->m[1][1];
|
||||
+6
-6
@@ -1,14 +1,14 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include "nif_internal.h"
|
||||
#include "nif_intrinsic.h"
|
||||
#include "nfn_internal.h"
|
||||
#include "nfn_intrinsic.h"
|
||||
|
||||
static __m128i facIncrement;
|
||||
static __m128i facBase;
|
||||
|
||||
INTERNAL uint64_t NIF_DECL factorial_simd_sse(int n)
|
||||
INTERNAL uint64_t NFN_DECL factorial_simd_sse(int n)
|
||||
{
|
||||
facIncrement = _mm_set1_epi32(4);
|
||||
facBase = _mm_setr_epi32(1, 2, 3, 4);
|
||||
@@ -20,7 +20,7 @@ INTERNAL uint64_t NIF_DECL factorial_simd_sse(int n)
|
||||
facBaseLocal = _mm_add_epi32(facBaseLocal, facIncrement);
|
||||
baseResult = _mm_mullo_epi32(baseResult, facBaseLocal);
|
||||
}
|
||||
NIF_ALIGNAS(16) int32_t lanes[4];
|
||||
NFN_ALIGNAS(16) int32_t lanes[4];
|
||||
_mm_store_si128((__m128i *)lanes, baseResult);
|
||||
uint64_t result = (uint64_t)lanes[0] * (uint64_t)lanes[1] * (uint64_t)lanes[2] *
|
||||
(uint64_t)lanes[3];
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include "NitloadFrameWork.h"
|
||||
|
||||
INTERNAL int NIF_DECL city_hash_simplify_sse(byte const *str, int const length)
|
||||
INTERNAL int NFN_DECL city_hash_simplify_sse(byte const *str, int const length)
|
||||
{
|
||||
uint32_t hash = length, size = length << 1;
|
||||
byte const *end = str + size;
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#include "nif_intrinsic.h"
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
#include "nfn_intrinsic.h"
|
||||
#include "NitloadFrameWork.h"
|
||||
static SIMDID global_simdid = { 0 };
|
||||
|
||||
#include "nif_intrinsic.context.x86.h"
|
||||
#include "nfn_intrinsic.context.x86.h"
|
||||
|
||||
#include <immintrin.h>
|
||||
#include <string.h>
|
||||
@@ -126,7 +126,7 @@ static int is_amd_glue_ymm(const char *vendor, int cpuid1_eax)
|
||||
return (family == 0x17) && (model < 0x30);
|
||||
}
|
||||
|
||||
NIF_API SIMDID NIF_DECL nif_get_simd_level_local()
|
||||
NFN_API SIMDID NFN_DECL nfn_get_simd_level_local()
|
||||
{
|
||||
SIMDID simdid = { 0 };
|
||||
|
||||
@@ -314,13 +314,13 @@ NIF_API SIMDID NIF_DECL nif_get_simd_level_local()
|
||||
return simdid;
|
||||
}
|
||||
|
||||
NIF_API SIMDID NIF_DECL nif_get_simd_level_global()
|
||||
NFN_API SIMDID NFN_DECL nfn_get_simd_level_global()
|
||||
{
|
||||
if (global_simdid.mask) {
|
||||
return global_simdid;
|
||||
}
|
||||
|
||||
global_simdid = nif_get_simd_level_local();
|
||||
global_simdid = nfn_get_simd_level_local();
|
||||
return global_simdid;
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,9 +1,9 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include "NitloadFrameWork.h"
|
||||
#include "nif_intrinsic.context.x86.h"
|
||||
#include "nfn_intrinsic.context.x86.h"
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
* Field extraction helpers.
|
||||
@@ -49,7 +49,7 @@ static int impl_strength(uint16_t avx512)
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
* nif_get_unite_simd
|
||||
* nfn_get_unite_simd
|
||||
*
|
||||
* Produce the conservative intersection of two SIMDIDs — the strongest
|
||||
* capability set that is safe to use on BOTH cores:
|
||||
@@ -60,7 +60,7 @@ static int impl_strength(uint16_t avx512)
|
||||
* - Root / Manu : keep left (must be same arch in practice)
|
||||
* - uArchHi : bitwise OR (HYBRID_P/E union; SIMD_DUAL set if either core is dual)
|
||||
* ----------------------------------------------------------------------- */
|
||||
NIF_API SIMDID NIF_DECL nif_get_unite_simd(SIMDID left, SIMDID right)
|
||||
NFN_API SIMDID NFN_DECL nfn_get_unite_simd(SIMDID left, SIMDID right)
|
||||
{
|
||||
SIMDID out;
|
||||
out.mask = 0;
|
||||
@@ -117,7 +117,7 @@ NIF_API SIMDID NIF_DECL nif_get_unite_simd(SIMDID left, SIMDID right)
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
* nif_compare_simd
|
||||
* nfn_compare_simd
|
||||
*
|
||||
* Compare two SIMDIDs by ISA strength. Returns:
|
||||
* +1 if left is strictly stronger than right
|
||||
@@ -154,7 +154,7 @@ NIF_API SIMDID NIF_DECL nif_get_unite_simd(SIMDID left, SIMDID right)
|
||||
* 7. uArchHi SIMD_DUAL (final tie-break)
|
||||
* Non-dual (SIMD_DUAL=0) > dual (SIMD_DUAL=1).
|
||||
* ----------------------------------------------------------------------- */
|
||||
NIF_API int NIF_DECL nif_compare_simd(SIMDID left, SIMDID right)
|
||||
NFN_API int NFN_DECL nfn_compare_simd(SIMDID left, SIMDID right)
|
||||
{
|
||||
/* 1. MainLevel */
|
||||
unsigned lm = FIELD_MAIN(left);
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#include "nif_intrinsic.h"
|
||||
#include "nif_intrinsic.std.h"
|
||||
#include "nif_intrinsic.context.x86.h"
|
||||
#include "nfn_intrinsic.h"
|
||||
#include "nfn_intrinsic.std.h"
|
||||
#include "nfn_intrinsic.context.x86.h"
|
||||
|
||||
#define _FMA_SELECT(i) _MM_SHUFFLE(i, i, i, i)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
// float
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, sse, , fma)
|
||||
NFN_SK_PROC_DECL_STD(float, sse, , fma)
|
||||
{
|
||||
__sk_param_std(float);
|
||||
register __m128 c0 = _mm_load_ps((float *)&ans->x[0]);
|
||||
@@ -60,7 +60,7 @@ NIF_SK_PROC_DECL_STD(float, sse, , fma)
|
||||
_mm_store_ps((float *)&ans->x[3], c3);
|
||||
}
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, avx, , fma)
|
||||
NFN_SK_PROC_DECL_STD(float, avx, , fma)
|
||||
{
|
||||
__sk_param_std(float);
|
||||
register __m256 c01 = _mm256_load_ps((float *)&ans->y[0]);
|
||||
@@ -86,7 +86,7 @@ NIF_SK_PROC_DECL_STD(float, avx, , fma)
|
||||
_mm256_store_ps((float *)&ans->y[1], c23);
|
||||
}
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, avx, _fma, fma)
|
||||
NFN_SK_PROC_DECL_STD(float, avx, _fma, fma)
|
||||
{
|
||||
__sk_param_std(float);
|
||||
register __m256 c01 = _mm256_load_ps((float *)&ans->y[0]);
|
||||
@@ -112,7 +112,7 @@ NIF_SK_PROC_DECL_STD(float, avx, _fma, fma)
|
||||
_mm256_store_ps((float *)&ans->y[1], c23);
|
||||
}
|
||||
|
||||
NIF_SK_PROC_DECL_STD(float, 512, , fma)
|
||||
NFN_SK_PROC_DECL_STD(float, 512, , fma)
|
||||
{
|
||||
__sk_param_std(float);
|
||||
register __m512 c = _mm512_load_ps((float *)ans);
|
||||
@@ -173,7 +173,7 @@ NIF_SK_PROC_DECL_STD(float, 512, , fma)
|
||||
|
||||
// clang-format on
|
||||
|
||||
NIF_SK_PROC_DECL_STD(double, sse, , fma)
|
||||
NFN_SK_PROC_DECL_STD(double, sse, , fma)
|
||||
{
|
||||
__sk_param_std(double);
|
||||
const double *left_values = &left->m[0][0];
|
||||
@@ -204,7 +204,7 @@ NIF_SK_PROC_DECL_STD(double, sse, , fma)
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
NIF_SK_PROC_DECL_STD(double, avx, , fma)
|
||||
NFN_SK_PROC_DECL_STD(double, avx, , fma)
|
||||
{
|
||||
__sk_param_std(double);
|
||||
register __m256d c0 = _mm256_load_pd((double *)&ans->y[0]);
|
||||
@@ -253,7 +253,7 @@ NIF_SK_PROC_DECL_STD(double, avx, , fma)
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
NIF_SK_PROC_DECL_STD(double, avx, _fma, fma)
|
||||
NFN_SK_PROC_DECL_STD(double, avx, _fma, fma)
|
||||
{
|
||||
__sk_param_std(double);
|
||||
register __m256d c0 = _mm256_load_pd((double *)&ans->y[0]);
|
||||
@@ -301,7 +301,7 @@ NIF_SK_PROC_DECL_STD(double, avx, _fma, fma)
|
||||
_mm256_store_pd((double *)&ans->y[3], c3);
|
||||
}
|
||||
|
||||
NIF_SK_PROC_DECL_STD(double, 512, , fma)
|
||||
NFN_SK_PROC_DECL_STD(double, 512, , fma)
|
||||
{
|
||||
__sk_param_std(double);
|
||||
register __m512d c01 = _mm512_load_pd((double *)&ans->z[0]);
|
||||
+72
-44
@@ -1,8 +1,8 @@
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_OS(NIF_OS_LINUX)
|
||||
#if NFN_IS_OS(NFN_OS_LINUX)
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
@@ -16,30 +16,36 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef int (*nif_linux_id_visitor)(int value, void *context);
|
||||
typedef int (*nfn_linux_id_visitor)(int value, void *context);
|
||||
|
||||
typedef struct nif_linux_counter_context {
|
||||
typedef struct nfn_linux_counter_context {
|
||||
int count;
|
||||
} nif_linux_counter_context;
|
||||
} nfn_linux_counter_context;
|
||||
|
||||
typedef struct nif_linux_max_context {
|
||||
typedef struct nfn_linux_max_context {
|
||||
int max_value;
|
||||
} nif_linux_max_context;
|
||||
} nfn_linux_max_context;
|
||||
|
||||
<<<<<<< HEAD:src/Nitload.Native/nfn-src/thread.linux.c
|
||||
typedef struct nfn_linux_fill_cpu_context {
|
||||
uint64_t *internal;
|
||||
uint32_t *global;
|
||||
=======
|
||||
typedef struct nif_linux_fill_cpu_context {
|
||||
uint32_t *processor_group_ids;
|
||||
uint32_t *socket_ids;
|
||||
uint32_t *cpu_indices;
|
||||
uint32_t *numa_node_ids;
|
||||
int numa_id;
|
||||
>>>>>>> 3a2b1234782f893f5b71655289b372ffed8dfd93:src/Nitload.Native/nif-src/thread.linux.c
|
||||
int index;
|
||||
} nif_linux_fill_cpu_context;
|
||||
} nfn_linux_fill_cpu_context;
|
||||
|
||||
typedef struct nif_linux_fill_node_count_context {
|
||||
typedef struct nfn_linux_fill_node_count_context {
|
||||
int *count_of_each_numa;
|
||||
} nif_linux_fill_node_count_context;
|
||||
} nfn_linux_fill_node_count_context;
|
||||
|
||||
static int nif_linux_read_first_line(char const *path, char *buffer, size_t buffer_size)
|
||||
static int nfn_linux_read_first_line(char const *path, char *buffer, size_t buffer_size)
|
||||
{
|
||||
FILE *file = fopen(path, "r");
|
||||
if (file == NULL)
|
||||
@@ -50,7 +56,7 @@ static int nif_linux_read_first_line(char const *path, char *buffer, size_t buff
|
||||
return line != NULL;
|
||||
}
|
||||
|
||||
static int nif_linux_parse_nonnegative_int(char const **cursor, int *value)
|
||||
static int nfn_linux_parse_nonnegative_int(char const **cursor, int *value)
|
||||
{
|
||||
char *end = NULL;
|
||||
uintmax_t parsed_value = 0;
|
||||
@@ -68,7 +74,7 @@ static int nif_linux_parse_nonnegative_int(char const **cursor, int *value)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int nif_linux_visit_id_list(char const *text, nif_linux_id_visitor visitor, void *context)
|
||||
static int nfn_linux_visit_id_list(char const *text, nfn_linux_id_visitor visitor, void *context)
|
||||
{
|
||||
char const *cursor = text;
|
||||
|
||||
@@ -80,14 +86,14 @@ static int nif_linux_visit_id_list(char const *text, nif_linux_id_visitor visito
|
||||
break;
|
||||
|
||||
int begin = 0;
|
||||
if (!nif_linux_parse_nonnegative_int(&cursor, &begin))
|
||||
if (!nfn_linux_parse_nonnegative_int(&cursor, &begin))
|
||||
return 0;
|
||||
|
||||
int finish = begin;
|
||||
|
||||
if (*cursor == '-') {
|
||||
cursor++;
|
||||
if (!nif_linux_parse_nonnegative_int(&cursor, &finish))
|
||||
if (!nfn_linux_parse_nonnegative_int(&cursor, &finish))
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -106,21 +112,26 @@ static int nif_linux_visit_id_list(char const *text, nif_linux_id_visitor visito
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int nif_linux_count_id(int value, void *context)
|
||||
static int nfn_linux_count_id(int value, void *context)
|
||||
{
|
||||
(void)value;
|
||||
((nif_linux_counter_context *)context)->count++;
|
||||
((nfn_linux_counter_context *)context)->count++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int nif_linux_track_max_id(int value, void *context)
|
||||
static int nfn_linux_track_max_id(int value, void *context)
|
||||
{
|
||||
nif_linux_max_context *max_context = (nif_linux_max_context *)context;
|
||||
nfn_linux_max_context *max_context = (nfn_linux_max_context *)context;
|
||||
if (value > max_context->max_value)
|
||||
max_context->max_value = value;
|
||||
return 1;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD:src/Nitload.Native/nfn-src/thread.linux.c
|
||||
static int nfn_linux_fill_cpu_id(int value, void *context)
|
||||
{
|
||||
nfn_linux_fill_cpu_context *fill_context = (nfn_linux_fill_cpu_context *)context;
|
||||
=======
|
||||
static int nif_linux_read_socket_id(int cpu_id, uint32_t *socket_id)
|
||||
{
|
||||
char path[160];
|
||||
@@ -147,6 +158,7 @@ static int nif_linux_fill_cpu_id(int value, void *context)
|
||||
uint32_t socket_id = 0;
|
||||
if (!nif_linux_read_socket_id(value, &socket_id))
|
||||
return 0;
|
||||
>>>>>>> 3a2b1234782f893f5b71655289b372ffed8dfd93:src/Nitload.Native/nif-src/thread.linux.c
|
||||
|
||||
fill_context->processor_group_ids[fill_context->index] = 0u;
|
||||
fill_context->socket_ids[fill_context->index] = socket_id;
|
||||
@@ -157,37 +169,37 @@ static int nif_linux_fill_cpu_id(int value, void *context)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int nif_linux_count_cpu_list(char const *path)
|
||||
static int nfn_linux_count_cpu_list(char const *path)
|
||||
{
|
||||
char buffer[256];
|
||||
if (!nif_linux_read_first_line(path, buffer, sizeof(buffer)))
|
||||
if (!nfn_linux_read_first_line(path, buffer, sizeof(buffer)))
|
||||
return 0;
|
||||
|
||||
nif_linux_counter_context counter = { 0 };
|
||||
if (!nif_linux_visit_id_list(buffer, nif_linux_count_id, &counter))
|
||||
nfn_linux_counter_context counter = { 0 };
|
||||
if (!nfn_linux_visit_id_list(buffer, nfn_linux_count_id, &counter))
|
||||
return 0;
|
||||
|
||||
return counter.count;
|
||||
}
|
||||
|
||||
static int nif_linux_fill_node_cpu_count(int value, void *context)
|
||||
static int nfn_linux_fill_node_cpu_count(int value, void *context)
|
||||
{
|
||||
char path[128];
|
||||
snprintf(path, sizeof(path), "/sys/devices/system/node/node%d/cpulist", value);
|
||||
|
||||
((nif_linux_fill_node_count_context *)context)->count_of_each_numa[value] =
|
||||
nif_linux_count_cpu_list(path);
|
||||
((nfn_linux_fill_node_count_context *)context)->count_of_each_numa[value] =
|
||||
nfn_linux_count_cpu_list(path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int nif_linux_node_exists(int numa_id)
|
||||
static int nfn_linux_node_exists(int numa_id)
|
||||
{
|
||||
char path[128];
|
||||
snprintf(path, sizeof(path), "/sys/devices/system/node/node%d", numa_id);
|
||||
return access(path, F_OK) == 0;
|
||||
}
|
||||
|
||||
static size_t nif_linux_round_up_to_page_size(size_t size)
|
||||
static size_t nfn_linux_round_up_to_page_size(size_t size)
|
||||
{
|
||||
int64_t page_size_value = (int64_t)sysconf(_SC_PAGESIZE);
|
||||
size_t effective_page_size = (page_size_value > 0) ? (size_t)page_size_value : 4096u;
|
||||
@@ -199,7 +211,7 @@ static size_t nif_linux_round_up_to_page_size(size_t size)
|
||||
return rounded - (rounded % effective_page_size);
|
||||
}
|
||||
|
||||
static int nif_linux_bind_memory_to_node(void *address, size_t size, int numa_id, uint32_t flags)
|
||||
static int nfn_linux_bind_memory_to_node(void *address, size_t size, int numa_id, uint32_t flags)
|
||||
{
|
||||
#if defined(SYS_mbind)
|
||||
size_t bits_per_word = sizeof(unsigned long) * 8u;
|
||||
@@ -223,7 +235,7 @@ static int nif_linux_bind_memory_to_node(void *address, size_t size, int numa_id
|
||||
#endif
|
||||
}
|
||||
|
||||
static int nif_linux_populate_writable_mapping(void *address, size_t size)
|
||||
static int nfn_linux_populate_writable_mapping(void *address, size_t size)
|
||||
{
|
||||
#if defined(MADV_POPULATE_WRITE)
|
||||
if (madvise(address, size, MADV_POPULATE_WRITE) == 0)
|
||||
@@ -237,8 +249,15 @@ static int nif_linux_populate_writable_mapping(void *address, size_t size)
|
||||
#endif
|
||||
}
|
||||
|
||||
<<<<<<< HEAD:src/Nitload.Native/nfn-src/thread.linux.c
|
||||
/* Pin the calling thread to a single logical processor.
|
||||
* core_id >= 0 : bind to that logical processor (global index, across groups).
|
||||
* core_id < 0 : clear affinity constraint within the current group. */
|
||||
NFN_API void NFN_DECL nfn_set_thread_affinity(int core_id, int numa_id)
|
||||
=======
|
||||
/* Linux has no Windows-style processor groups; processor_group_id is ignored. */
|
||||
NIF_API void NIF_DECL nif_set_thread_affinity(int cpu_index, int processor_group_id)
|
||||
>>>>>>> 3a2b1234782f893f5b71655289b372ffed8dfd93:src/Nitload.Native/nif-src/thread.linux.c
|
||||
{
|
||||
(void)processor_group_id;
|
||||
|
||||
@@ -266,14 +285,14 @@ NIF_API void NIF_DECL nif_set_thread_affinity(int cpu_index, int processor_group
|
||||
CPU_FREE(set);
|
||||
}
|
||||
|
||||
NIF_API int NIF_DECL nif_get_numa_overall(int *out_numa_count, int *count_of_each_numa)
|
||||
NFN_API int NFN_DECL nfn_get_numa_overall(int *out_numa_count, int *count_of_each_numa)
|
||||
{
|
||||
char buffer[256];
|
||||
if (!nif_linux_read_first_line("/sys/devices/system/node/online", buffer, sizeof(buffer)))
|
||||
if (!nfn_linux_read_first_line("/sys/devices/system/node/online", buffer, sizeof(buffer)))
|
||||
return 0;
|
||||
|
||||
nif_linux_max_context max_context = { -1 };
|
||||
if (!nif_linux_visit_id_list(buffer, nif_linux_track_max_id, &max_context) ||
|
||||
nfn_linux_max_context max_context = { -1 };
|
||||
if (!nfn_linux_visit_id_list(buffer, nfn_linux_track_max_id, &max_context) ||
|
||||
max_context.max_value < 0)
|
||||
return 0;
|
||||
|
||||
@@ -284,19 +303,23 @@ NIF_API int NIF_DECL nif_get_numa_overall(int *out_numa_count, int *count_of_eac
|
||||
for (int index = 0; index <= max_context.max_value; index++)
|
||||
count_of_each_numa[index] = 0;
|
||||
|
||||
nif_linux_fill_node_count_context fill_context = { count_of_each_numa };
|
||||
if (!nif_linux_visit_id_list(buffer, nif_linux_fill_node_cpu_count, &fill_context))
|
||||
nfn_linux_fill_node_count_context fill_context = { count_of_each_numa };
|
||||
if (!nfn_linux_visit_id_list(buffer, nfn_linux_fill_node_cpu_count, &fill_context))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD:src/Nitload.Native/nfn-src/thread.linux.c
|
||||
NFN_API int NFN_DECL nfn_get_numa_each(int numa_id, uint64_t *internal, uint32_t *global)
|
||||
=======
|
||||
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)
|
||||
>>>>>>> 3a2b1234782f893f5b71655289b372ffed8dfd93:src/Nitload.Native/nif-src/thread.linux.c
|
||||
{
|
||||
if (numa_id < 0 || processor_group_ids == NULL || socket_ids == NULL ||
|
||||
cpu_indices == NULL || numa_node_ids == NULL)
|
||||
@@ -305,9 +328,13 @@ NIF_API int NIF_DECL nif_get_numa_each(int numa_id,
|
||||
char path[128];
|
||||
char buffer[256];
|
||||
snprintf(path, sizeof(path), "/sys/devices/system/node/node%d/cpulist", numa_id);
|
||||
if (!nif_linux_read_first_line(path, buffer, sizeof(buffer)))
|
||||
if (!nfn_linux_read_first_line(path, buffer, sizeof(buffer)))
|
||||
return 0;
|
||||
|
||||
<<<<<<< HEAD:src/Nitload.Native/nfn-src/thread.linux.c
|
||||
nfn_linux_fill_cpu_context fill_context = { internal, global, 0 };
|
||||
return nfn_linux_visit_id_list(buffer, nfn_linux_fill_cpu_id, &fill_context);
|
||||
=======
|
||||
nif_linux_fill_cpu_context fill_context = {
|
||||
processor_group_ids,
|
||||
socket_ids,
|
||||
@@ -317,11 +344,12 @@ NIF_API int NIF_DECL nif_get_numa_each(int numa_id,
|
||||
0
|
||||
};
|
||||
return nif_linux_visit_id_list(buffer, nif_linux_fill_cpu_id, &fill_context);
|
||||
>>>>>>> 3a2b1234782f893f5b71655289b372ffed8dfd93:src/Nitload.Native/nif-src/thread.linux.c
|
||||
}
|
||||
|
||||
NIF_API void *NIF_DECL nif_numa_alloc(size_t size, int numa_id)
|
||||
NFN_API void *NFN_DECL nfn_numa_alloc(size_t size, int numa_id)
|
||||
{
|
||||
size_t allocation_size = nif_linux_round_up_to_page_size(size);
|
||||
size_t allocation_size = nfn_linux_round_up_to_page_size(size);
|
||||
if (allocation_size == 0)
|
||||
return NULL;
|
||||
|
||||
@@ -343,9 +371,9 @@ NIF_API void *NIF_DECL nif_numa_alloc(size_t size, int numa_id)
|
||||
bind_flags = MPOL_MF_MOVE | MPOL_MF_STRICT;
|
||||
#endif
|
||||
|
||||
if (!nif_linux_node_exists(numa_id) ||
|
||||
!nif_linux_bind_memory_to_node(memory, allocation_size, numa_id, bind_flags) ||
|
||||
!nif_linux_populate_writable_mapping(memory, allocation_size)) {
|
||||
if (!nfn_linux_node_exists(numa_id) ||
|
||||
!nfn_linux_bind_memory_to_node(memory, allocation_size, numa_id, bind_flags) ||
|
||||
!nfn_linux_populate_writable_mapping(memory, allocation_size)) {
|
||||
munmap(memory, allocation_size);
|
||||
return NULL;
|
||||
}
|
||||
@@ -353,14 +381,14 @@ NIF_API void *NIF_DECL nif_numa_alloc(size_t size, int numa_id)
|
||||
return memory;
|
||||
}
|
||||
|
||||
NIF_API void NIF_DECL nif_numa_free(void *ptr, size_t size, int numa_id)
|
||||
NFN_API void NFN_DECL nfn_numa_free(void *ptr, size_t size, int numa_id)
|
||||
{
|
||||
(void)numa_id;
|
||||
|
||||
if (ptr == NULL || size == 0)
|
||||
return;
|
||||
|
||||
size_t allocation_size = nif_linux_round_up_to_page_size(size);
|
||||
size_t allocation_size = nfn_linux_round_up_to_page_size(size);
|
||||
if (allocation_size != 0)
|
||||
munmap(ptr, allocation_size);
|
||||
}
|
||||
+16
-5
@@ -1,9 +1,16 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
#include "NitloadFrameWork.h"
|
||||
|
||||
#if NIF_IS_OS(NIF_OS_WINDOWS)
|
||||
#if NFN_IS_OS(NFN_OS_WINDOWS)
|
||||
|
||||
<<<<<<< HEAD:src/Nitload.Native/nfn-src/thread.windows.c
|
||||
/* Pin the calling thread to a single logical processor.
|
||||
* core_id >= 0 : bind to that logical processor (global index, across groups).
|
||||
* core_id < 0 : clear affinity constraint within the current group. */
|
||||
NFN_API void NFN_DECL nfn_set_thread_affinity(int core_id, int numa_id)
|
||||
=======
|
||||
static int nif_windows_get_socket_map(uint32_t **out_socket_map, DWORD *out_group_count)
|
||||
>>>>>>> 3a2b1234782f893f5b71655289b372ffed8dfd93:src/Nitload.Native/nif-src/thread.windows.c
|
||||
{
|
||||
DWORD group_count = GetActiveProcessorGroupCount();
|
||||
DWORD buffer_size = 0;
|
||||
@@ -101,7 +108,7 @@ NIF_API void NIF_DECL nif_set_thread_affinity(int cpu_index, int processor_group
|
||||
SetThreadGroupAffinity(GetCurrentThread(), &affinity, NULL);
|
||||
}
|
||||
|
||||
NIF_API int NIF_DECL nif_get_numa_overall(int *out_numa_count, int *count_of_each_numa)
|
||||
NFN_API int NFN_DECL nfn_get_numa_overall(int *out_numa_count, int *count_of_each_numa)
|
||||
{
|
||||
ULONG highest;
|
||||
if (!GetNumaHighestNodeNumber(&highest))
|
||||
@@ -125,11 +132,15 @@ NIF_API int NIF_DECL nif_get_numa_overall(int *out_numa_count, int *count_of_eac
|
||||
return 1;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD:src/Nitload.Native/nfn-src/thread.windows.c
|
||||
NFN_API int NFN_DECL nfn_get_numa_each(int numa_id, uint64_t *internal, uint32_t *global)
|
||||
=======
|
||||
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)
|
||||
>>>>>>> 3a2b1234782f893f5b71655289b372ffed8dfd93:src/Nitload.Native/nif-src/thread.windows.c
|
||||
{
|
||||
if (numa_id < 0 || processor_group_ids == NULL || socket_ids == NULL ||
|
||||
cpu_indices == NULL || numa_node_ids == NULL)
|
||||
@@ -166,7 +177,7 @@ NIF_API int NIF_DECL nif_get_numa_each(int numa_id,
|
||||
}
|
||||
|
||||
|
||||
NIF_API void *NIF_DECL nif_numa_alloc(size_t size, int numa_id)
|
||||
NFN_API void *NFN_DECL nfn_numa_alloc(size_t size, int numa_id)
|
||||
{
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
@@ -182,7 +193,7 @@ NIF_API void *NIF_DECL nif_numa_alloc(size_t size, int numa_id)
|
||||
PAGE_READWRITE, (DWORD)numa_id);
|
||||
}
|
||||
|
||||
NIF_API void NIF_DECL nif_numa_free(void *ptr, size_t size, int numa_id)
|
||||
NFN_API void NFN_DECL nfn_numa_free(void *ptr, size_t size, int numa_id)
|
||||
{
|
||||
(void)size;
|
||||
(void)numa_id;
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "nif_intrinsic.h"
|
||||
#include "nif_internal.h"
|
||||
#include "nfn_intrinsic.h"
|
||||
#include "nfn_internal.h"
|
||||
|
||||
INTERNAL void NIF_DECL f32_normalize(VEC_SEGMENT(float) *restrict source, VEC_SEGMENT(float) *restrict target)
|
||||
INTERNAL void NFN_DECL f32_normalize(VEC_SEGMENT(float) *restrict source, VEC_SEGMENT(float) *restrict target)
|
||||
{
|
||||
register __m128 s = source->f32_x[0];
|
||||
register __m128 a_length_sq = _mm_mul_ps(s, s);
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "nif_intrinsic.h"
|
||||
#include "nif_internal.h"
|
||||
#include "nfn_intrinsic.h"
|
||||
#include "nfn_internal.h"
|
||||
|
||||
static const int avxdot_indices[] = { 0, 4, 1, 5, 2, 3, 6, 7 };
|
||||
|
||||
INTERNAL void FORCEINLINE NIF_DECL dot_41_sse(MAT_KERNEL(float) const *transpose,
|
||||
INTERNAL void FORCEINLINE NFN_DECL dot_41_sse(MAT_KERNEL(float) const *transpose,
|
||||
__m128 const *vector, __m128 *ans)
|
||||
{
|
||||
*ans = _mm_dp_ps(transpose->x[0], *vector, 0B11110001);
|
||||
@@ -15,7 +15,7 @@ INTERNAL void FORCEINLINE NIF_DECL dot_41_sse(MAT_KERNEL(float) const *transpose
|
||||
SSE_INSERT_SIMPLE(1, 4));
|
||||
}
|
||||
|
||||
INTERNAL void NIF_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
INTERNAL void NFN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
__m256 _double = _mm256_set_m128(vector[0], vector[0]);
|
||||
@@ -26,7 +26,7 @@ INTERNAL void NIF_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 con
|
||||
_mm256_permutevar8x32_ps(tmp, _mm256_loadu_epi32(avxdot_indices)));
|
||||
}
|
||||
|
||||
INTERNAL void NIF_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
INTERNAL void NFN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
ans[0] = _mm_dp_ps(transpose->x[0], vector[0], 0B11110001);
|
||||
@@ -46,7 +46,7 @@ INTERNAL void NIF_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 con
|
||||
SSE_INSERT_SIMPLE(1, 4));
|
||||
}
|
||||
|
||||
INTERNAL void NIF_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
INTERNAL void NFN_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
__m256 temp = transpose->y[0];
|
||||
+9
-9
@@ -1,8 +1,8 @@
|
||||
#include "nif_target.h"
|
||||
#include "nfn_target.h"
|
||||
|
||||
#if NIF_IS_ARCH(NIF_ARCH_X86_64)
|
||||
#if NFN_IS_ARCH(NFN_ARCH_X86_64)
|
||||
|
||||
#define NIF_MK_FMA_F32_512_CYCLE(i) \
|
||||
#define NFN_MK_FMA_F32_512_CYCLE(i) \
|
||||
do { \
|
||||
c0 = _mm512_fmadd_ps(c0, a0, _mm512_permute_ps(b0, _FMA_SELECT(i))); \
|
||||
c1 = _mm512_fmadd_ps(c1, a1, _mm512_permute_ps(b1, _FMA_SELECT(i))); \
|
||||
@@ -10,7 +10,7 @@
|
||||
c3 = _mm512_fmadd_ps(c3, a3, _mm512_permute_ps(b3, _FMA_SELECT(i))); \
|
||||
} while (0)
|
||||
|
||||
#define NIF_MK_FMA_F32_AVX2_CYCLE(i) \
|
||||
#define NFN_MK_FMA_F32_AVX2_CYCLE(i) \
|
||||
do { \
|
||||
c0 = _mm256_fmadd_ps(c0, a0, _mm256_permute_ps(b0, _FMA_SELECT(i))); \
|
||||
c1 = _mm256_fmadd_ps(c1, a1, _mm256_permute_ps(b1, _FMA_SELECT(i))); \
|
||||
@@ -18,7 +18,7 @@
|
||||
c3 = _mm256_fmadd_ps(c3, a3, _mm256_permute_ps(b3, _FMA_SELECT(i))); \
|
||||
} while (0)
|
||||
|
||||
#define NIF_MK_FMA_F64_AVX2_CYCLE(i) \
|
||||
#define NFN_MK_FMA_F64_AVX2_CYCLE(i) \
|
||||
do { \
|
||||
c0 = _mm512_fmadd_ps(c0, a0, _mm512_permutex_pd(b0, _FMA_SELECT(i))); \
|
||||
c1 = _mm512_fmadd_ps(c1, a1, _mm512_permutex_pd(b1, _FMA_SELECT(i))); \
|
||||
@@ -26,7 +26,7 @@
|
||||
c3 = _mm512_fmadd_ps(c3, a3, _mm512_permutex_pd(b3, _FMA_SELECT(i))); \
|
||||
} while (0)
|
||||
|
||||
#define NIF_FMA_F32_512_PACK_COLUMN(col, target) \
|
||||
#define NFN_FMA_F32_512_PACK_COLUMN(col, target) \
|
||||
do { \
|
||||
register __m256 low = _mm512_castps512_ps256(col); \
|
||||
register __m256 high = _mm512_extractf32x8_ps(col, 1); \
|
||||
@@ -37,7 +37,7 @@
|
||||
_mm_store_ps(target, half128); \
|
||||
} while (0)
|
||||
|
||||
#define NIF_FMA_F32_AVX2_PACK_COLUMN(col, target) \
|
||||
#define NFN_FMA_F32_AVX2_PACK_COLUMN(col, target) \
|
||||
do { \
|
||||
register __m128 high128 = _mm256_extractf32x4_ps(col, 1); \
|
||||
register __m128 low128 = _mm256_castps256_ps128(col); \
|
||||
@@ -45,7 +45,7 @@
|
||||
_mm_store_ps(target, half128); \
|
||||
} while (0)
|
||||
|
||||
#define NIF_FMA_F64_512_PACK_COLUMN(col, target) \
|
||||
#define NFN_FMA_F64_512_PACK_COLUMN(col, target) \
|
||||
do { \
|
||||
register __m128 high128 = _mm256_extractf32x4_ps(col, 1); \
|
||||
register __m128 low128 = _mm256_castps256_ps128(col); \
|
||||
@@ -54,7 +54,7 @@
|
||||
} while (0)
|
||||
|
||||
// double
|
||||
#define NIF_MK_FMA_F64_SSE_PHASE(i) \
|
||||
#define NFN_MK_FMA_F64_SSE_PHASE(i) \
|
||||
do { \
|
||||
/* k = 0 */ \
|
||||
register __m128d b_lo = _mm_load_pd(right_values + (2 * i + 0)); \
|
||||
@@ -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
|
||||
@@ -1,54 +0,0 @@
|
||||
#ifndef NIF_MATKERNEL
|
||||
#define NIF_MATKERNEL
|
||||
|
||||
#include <immintrin.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "nif_internal.h"
|
||||
|
||||
/* Kernel storage unions for a fixed 4x4 block. */
|
||||
#define ELEMENTSIZE(T) sizeof(T)
|
||||
#define XMMCOUNT(T) (sizeof(T))
|
||||
#define YMMCOUNT(T) (sizeof(T) / 2)
|
||||
#define ZMMCOUNT(T) (sizeof(T) / 4)
|
||||
|
||||
#define NIF_MAT_KERNEL_MEMBER(T) \
|
||||
{ \
|
||||
__m128 x[XMMCOUNT(T)]; \
|
||||
__m256 y[YMMCOUNT(T)]; \
|
||||
__m512 z[ZMMCOUNT(T)]; \
|
||||
T m[4][4]; \
|
||||
}
|
||||
|
||||
#define NIF_MAT_KERNEL_DEFINE(T) \
|
||||
typedef union NIF_MAT_KERNEL_TYPE_##T NIF_MAT_KERNEL_MEMBER(T) NIF_MAT_KERNEL_TYPE_##T
|
||||
|
||||
#define MAT_KERNEL(T) NIF_MAT_KERNEL_TYPE(T)
|
||||
#define NIF_MAT_KERNEL_TYPE(T) NIF_MAT_KERNEL_TYPE_##T
|
||||
|
||||
NIF_MAT_KERNEL_DEFINE(float);
|
||||
NIF_MAT_KERNEL_DEFINE(double);
|
||||
NIF_MAT_KERNEL_DEFINE(uint64_t);
|
||||
|
||||
|
||||
#define NIF_VEC_SEGMENT_MEMBER(T) \
|
||||
{ \
|
||||
__m128 f32_x[XMMCOUNT(T) / 4]; \
|
||||
__m256 f32_y[YMMCOUNT(T) / 4]; \
|
||||
__m512 f32_z[ZMMCOUNT(T) / 4]; \
|
||||
T v[4]; \
|
||||
}
|
||||
|
||||
#define NIF_VEC_SEGMENT_DEFINE(T) \
|
||||
typedef union NIF_VEC_SEGMENT_TYPE_##T NIF_VEC_SEGMENT_MEMBER(T) NIF_VEC_SEGMENT_TYPE_##T
|
||||
|
||||
#define VEC_SEGMENT(T) NIF_VEC_SEGMENT_TYPE(T)
|
||||
#define NIF_VEC_SEGMENT_TYPE(T) NIF_VEC_SEGMENT_TYPE_##T
|
||||
|
||||
NIF_VEC_SEGMENT_DEFINE(float);
|
||||
NIF_VEC_SEGMENT_DEFINE(double);
|
||||
|
||||
/* Global zero kernel declaration (defined in dllmain.c), aligned to 64 bytes */
|
||||
extern __declspec(align(64)) MAT_KERNEL(u64) NIF_ZERO_KERNEL;
|
||||
|
||||
#endif /* NIF_MATKERNEL */
|
||||
@@ -1,101 +0,0 @@
|
||||
#ifndef NIF_INTRINSIC_CALLCONV_STD
|
||||
#define NIF_INTRINSIC_CALLCONV_STD
|
||||
|
||||
#include "nif_internal.h"
|
||||
#include "nif_intrinsic.h"
|
||||
|
||||
#ifndef static_assert
|
||||
#define static_assert _Static_assert
|
||||
#endif
|
||||
|
||||
#define NIF_STD_TARGET_ATTR(T_arch, T_feature) NIF_STD_TARGET_ATTR_IMPL(T_arch, T_feature)
|
||||
|
||||
#pragma region mk_proc attributes
|
||||
#define MK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op) \
|
||||
T_type##_multi_kernel_proc_##T_op##_##T_arch##_##T_feature
|
||||
#define GET_MK_PROC_STD(T_type, T_arch, T_feature, T_op) \
|
||||
((UNI_MK_PROC)MK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op))
|
||||
#define NIF_MK_PROC_DECL(T_type, P_name) INTERNAL void NIF_DECL P_name(MAT_TASK(T_type) const *task)
|
||||
#define NIF_MK_PROC_DECL_STD(T_type, T_arch, T_feature, T_op) \
|
||||
INTERNAL NOINLINE NIF_STD_TARGET_ATTR(T_arch, T_feature) void NIF_DECL MK_PROC_NAME_STD( \
|
||||
T_type, T_arch, T_feature, T_op)(MAT_TASK(T_type) const *task)
|
||||
#pragma endregion
|
||||
|
||||
#pragma region sk_proc attributes
|
||||
#define SK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op) \
|
||||
T_type##_single_kernel_proc_##T_op##_##T_arch##_##T_feature
|
||||
#define GET_SK_PROC_STD(T_type, T_arch, T_feature, T_op) \
|
||||
((UNI_SK_PROC)SK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op))
|
||||
#define NIF_SK_PROC_DECL_STD(T_type, T_arch, T_feature, T_op) \
|
||||
INTERNAL NOINLINE NIF_STD_TARGET_ATTR(T_arch, T_feature) void NIF_DECL SK_PROC_NAME_STD( \
|
||||
T_type, T_arch, T_feature, \
|
||||
T_op)(MAT_KERNEL(T_type) const *left, MAT_KERNEL(T_type) const *right, \
|
||||
MAT_KERNEL(T_type) *restrict ans, uint64_t scalar)
|
||||
#pragma endregion
|
||||
|
||||
#define _SN_STD__PROBE_0 0
|
||||
#define _SN_STD__PROBE_1 1
|
||||
#define NIF_STD__PROBE_PRINT(x) _SN_STD__PROBE_##x
|
||||
#define NIF_STD__PROBE(x) NIF_STD__PROBE_PRINT(x)
|
||||
|
||||
#pragma region param styles
|
||||
|
||||
#define _SN_MATPROC_LEFT_RIGHT_ANS 1
|
||||
#define _SN_MATPROC_RIGHT_ANS 1
|
||||
#define _SN_MATPROC_LEFT_RIGHT_ANS_SCALAR 1
|
||||
#define _SN_MATPROC_RIGHT_ANS_SCALAR 1
|
||||
#define _SN_MATPROC_ANS_SCALAR 1
|
||||
|
||||
#define _SN_MK_EXPAND_BUFFER_SIZE(i)\
|
||||
int offset_##i = task->offset_##i;\
|
||||
int count_##i = task->count_##i;\
|
||||
|
||||
#define _SN_MK_EXPAND_RIGHT_ANS \
|
||||
NIF_MAT_KERNEL_LOCAL const *right = (NIF_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans = (NIF_MAT_KERNEL_LOCAL *)task->buffer_2.ptr;\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(1); \
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _SN_MK_EXPAND_LEFT_RIGHT_ANS \
|
||||
NIF_MAT_KERNEL_LOCAL const *left = (NIF_MAT_KERNEL_LOCAL const *)task->buffer_0.ptr; \
|
||||
NIF_MAT_KERNEL_LOCAL const *right = (NIF_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans = (NIF_MAT_KERNEL_LOCAL *)task->buffer_2.ptr;\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(0); \
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(1);\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _SN_MK_EXPAND_RIGHT_ANS_SCALAR \
|
||||
NIF_MAT_KERNEL_LOCAL const *right = (NIF_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans = (NIF_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
M128 scalar = task->scalar_pack;\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(1);\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _SN_MK_EXPAND_LEFT_RIGHT_ANS_SCALAR \
|
||||
NIF_MAT_KERNEL_LOCAL const *left = (NIF_MAT_KERNEL_LOCAL const *)task->buffer_0.ptr; \
|
||||
NIF_MAT_KERNEL_LOCAL const *right = (NIF_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans = (NIF_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
M128 scalar = task->scalar_pack;\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(0);\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(1);\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _SN_MK_EXPAND_ANS_SCALAR \
|
||||
NIF_MAT_KERNEL_LOCAL *restrict ans = (NIF_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
M128 scalar = task->scalar_pack;\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _SN_PARAM_STYLE(T) _SN_MATPROC_##T
|
||||
#define _SN_MK_EXPAND_PARAM(style) _SN_MK_EXPAND_##style
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#define __mk_param_std(param, T) \
|
||||
typedef MAT_KERNEL(T) NIF_MAT_KERNEL_LOCAL; \
|
||||
matrix_task const *_ = (_SN_PARAM_STYLE(param), task); \
|
||||
_SN_MK_EXPAND_PARAM(param)
|
||||
|
||||
#define __sk_param_std(T) \
|
||||
typedef MAT_KERNEL(T) NIF_MAT_KERNEL_LOCAL; \
|
||||
(void)scalar
|
||||
#endif // !NIF_INTRINSIC_PARAM_EXPAND
|
||||
@@ -1,94 +0,0 @@
|
||||
#ifndef NIF_TARGET
|
||||
#define NIF_TARGET
|
||||
|
||||
#include "nif_internal.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define NIF_OS_WINDOWS 0
|
||||
#define NIF_OS_LINUX 1
|
||||
#define NIF_OS_MACOS 2
|
||||
#define NIF_OS_IOS 3
|
||||
#define NIF_OS_ANDROID 4
|
||||
#define NIF_OS_UNKNOWN 5
|
||||
|
||||
#define NIF_ARCH_X86_64 0
|
||||
#define NIF_ARCH_ARM64 1
|
||||
#define NIF_ARCH_RISCV64 2
|
||||
#define NIF_ARCH_PPC64le 3
|
||||
|
||||
#if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__amd64__)
|
||||
#define NIF_CURRENT_ARCH NIF_ARCH_X86_64
|
||||
|
||||
#elif defined(_M_ARM64) || defined(__aarch64__)
|
||||
#define NIF_CURRENT_ARCH NIF_ARCH_ARM64
|
||||
|
||||
#elif defined(_M_ARM) || defined(__arm__)
|
||||
#define NIF_CURRENT_ARCH NIF_ARCH_ARM32
|
||||
|
||||
#elif defined(_M_IX86) || defined(__i386__)
|
||||
#define NIF_CURRENT_ARCH NIF_ARCH_X86_32
|
||||
|
||||
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)
|
||||
#define NIF_CURRENT_ARCH NIF_ARCH_PPC64LE
|
||||
|
||||
#elif defined(__riscv) && (__riscv_xlen == 64)
|
||||
#define NIF_CURRENT_ARCH NIF_ARCH_RISCV64
|
||||
|
||||
#else
|
||||
#error "SN: Unsupported target architecture"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Target selection policy:
|
||||
* - Default (no NIF_EXTERN_TARGET): fixed Windows + x86_64.
|
||||
* - External (NIF_EXTERN_TARGET): build system must provide NIF_OS and NIF_ARCH.
|
||||
*/
|
||||
#ifndef NIF_EXTERN_TARGET
|
||||
|
||||
#define NIF_OS_TARGET NIF_OS_WINDOWS
|
||||
#define NIF_ARCH_TARGET NIF_ARCH_X86_64
|
||||
|
||||
#else
|
||||
|
||||
#ifndef NIF_OS_TARGET
|
||||
#error "NIF_EXTERN_TARGET is defined but NIF_OS is not provided."
|
||||
#endif
|
||||
|
||||
#ifndef NIF_ARCH_TARGET
|
||||
#error "NIF_EXTERN_TARGET is defined but NIF_ARCH is not provided."
|
||||
#endif
|
||||
|
||||
/* Validate externally supplied values are within known enum constants. */
|
||||
#if (NIF_OS_TARGET != NIF_OS_WINDOWS) && (NIF_OS_TARGET != NIF_OS_LINUX) && \
|
||||
(NIF_OS_TARGET != NIF_OS_MACOS) && (NIF_OS_TARGET != NIF_OS_IOS) && \
|
||||
(NIF_OS_TARGET != NIF_OS_ANDROID) && (NIF_OS_TARGET != NIF_OS_UNKNOWN)
|
||||
#error "NIF_OS has an invalid value. Use NIF_OS_<...> enum constants."
|
||||
#endif
|
||||
|
||||
#if (NIF_ARCH_TARGET != NIF_ARCH_X86_64) && (NIF_ARCH_TARGET != NIF_ARCH_ARM64) && \
|
||||
(NIF_ARCH_TARGET != NIF_ARCH_RISCV64) && (NIF_ARCH_TARGET != NIF_ARCH_PPC64le)
|
||||
#error "NIF_ARCH has an invalid value. Use NIF_ARCH_<...> enum constants."
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define NIF_IS_OS(os) ((NIF_OS_TARGET) == (os))
|
||||
|
||||
#define NIF_IS_ARCH(arch) ((NIF_ARCH_TARGET) == (arch))
|
||||
|
||||
/*
|
||||
* Per-function ISA selection is required for runtime-dispatched kernels that
|
||||
* mix multiple x86 feature levels in one build target.
|
||||
*/
|
||||
#if defined(__clang__) && ((NIF_ARCH_TARGET) == NIF_ARCH_X86_64)
|
||||
#define NIF_CLANG_TARGET_ATTR(options) __attribute__((target(options)))
|
||||
#else
|
||||
#define NIF_CLANG_TARGET_ATTR(options)
|
||||
#endif
|
||||
|
||||
typedef union SIMDID {
|
||||
uint64_t mask;
|
||||
char make_byte[8];
|
||||
} SIMDID;
|
||||
|
||||
#endif // NIF_TARGET
|
||||
@@ -1,215 +0,0 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[switch] $Apply
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$taskWorkspaceRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
|
||||
$nativeProjectRoot = Join-Path $taskWorkspaceRoot 'src\Nitload.Native'
|
||||
$textRoots = @(
|
||||
$nativeProjectRoot
|
||||
(Join-Path $taskWorkspaceRoot 'src\Nitload.Common')
|
||||
(Join-Path $taskWorkspaceRoot 'src\Nitload.Mathematics')
|
||||
(Join-Path $taskWorkspaceRoot 'src\Nitload.Graphics')
|
||||
)
|
||||
|
||||
$textExtensions = [Collections.Generic.HashSet[string]]::new(
|
||||
[StringComparer]::OrdinalIgnoreCase
|
||||
)
|
||||
@(
|
||||
'.c', '.h', '.inl', '.inc', '.ipp',
|
||||
'.cs', '.cmake', '.txt', '.md',
|
||||
'.csproj', '.vcxproj', '.filters',
|
||||
'.json', '.props', '.targets'
|
||||
) | ForEach-Object { [void] $textExtensions.Add($_) }
|
||||
|
||||
$replacementRules = @(
|
||||
@{ Pattern = '\bSTGSHARP_'; Replacement = 'NIF_' }
|
||||
@{ Pattern = '\bSN_'; Replacement = 'NIF_' }
|
||||
@{ Pattern = '(?<![A-Za-z0-9])sn_'; Replacement = 'nif_' }
|
||||
@{ Pattern = '\bload_glfw_functions\b'; Replacement = 'nif_load_glfw_functions' }
|
||||
@{ Pattern = '\bload_intrinsic_function\b'; Replacement = 'nif_load_intrinsic_function' }
|
||||
@{ Pattern = '\bStgSharpNative\b'; Replacement = 'NitloadFrameWork' }
|
||||
@{ Pattern = '\bNitloadInnovationFramework\b'; Replacement = 'NitloadFrameWork' }
|
||||
@{ Pattern = '\bNitloadFramework\b'; Replacement = 'NitloadFrameWork' }
|
||||
@{ Pattern = '\bSNative\b'; Replacement = 'NIF_NATIVE_H' }
|
||||
@{ Pattern = 'sn-head'; Replacement = 'nif-head' }
|
||||
@{ Pattern = 'sn-src'; Replacement = 'nif-src' }
|
||||
@{ Pattern = 'sn-template'; Replacement = 'nif-template' }
|
||||
)
|
||||
|
||||
function Test-TaskPath {
|
||||
param([Parameter(Mandatory)][string] $Path)
|
||||
|
||||
$resolvedPath = [IO.Path]::GetFullPath($Path)
|
||||
if (-not $resolvedPath.StartsWith(
|
||||
$taskWorkspaceRoot + [IO.Path]::DirectorySeparatorChar,
|
||||
[StringComparison]::OrdinalIgnoreCase
|
||||
)) {
|
||||
throw "Path escapes workspace: $resolvedPath"
|
||||
}
|
||||
}
|
||||
|
||||
function Get-TaskTextFile {
|
||||
foreach ($textRoot in $textRoots) {
|
||||
Get-ChildItem -LiteralPath $textRoot -Recurse -File | Where-Object {
|
||||
$relativePath = [IO.Path]::GetRelativePath($taskWorkspaceRoot, $_.FullName)
|
||||
if ($relativePath -match '(^|[\\/])(bin|obj|\.discard)([\\/]|$)') {
|
||||
return $false
|
||||
}
|
||||
|
||||
$nativeLibRoot = Join-Path $nativeProjectRoot 'lib'
|
||||
if ($_.FullName.StartsWith(
|
||||
$nativeLibRoot + [IO.Path]::DirectorySeparatorChar,
|
||||
[StringComparison]::OrdinalIgnoreCase
|
||||
) -and $_.Name -ne 'CMakeLists.txt') {
|
||||
return $false
|
||||
}
|
||||
|
||||
return $textExtensions.Contains($_.Extension)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Read-TaskText {
|
||||
param([Parameter(Mandatory)][string] $Path)
|
||||
|
||||
$bytes = [IO.File]::ReadAllBytes($Path)
|
||||
$encoding = [Text.UTF8Encoding]::new($false, $true)
|
||||
$preambleLength = 0
|
||||
$preambleBytes = [byte[]]::new(0)
|
||||
|
||||
if ($bytes.Length -ge 3 -and
|
||||
$bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
|
||||
$preambleLength = 3
|
||||
}
|
||||
elseif ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFF -and $bytes[1] -eq 0xFE) {
|
||||
$encoding = [Text.UnicodeEncoding]::new($false, $false, $true)
|
||||
$preambleLength = 2
|
||||
}
|
||||
elseif ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFE -and $bytes[1] -eq 0xFF) {
|
||||
$encoding = [Text.UnicodeEncoding]::new($true, $false, $true)
|
||||
$preambleLength = 2
|
||||
}
|
||||
|
||||
if ($preambleLength -ne 0) {
|
||||
$preambleBytes = [byte[]] $bytes[0..($preambleLength - 1)]
|
||||
}
|
||||
|
||||
[PSCustomObject]@{
|
||||
Text = $encoding.GetString($bytes, $preambleLength, $bytes.Length - $preambleLength)
|
||||
Encoding = $encoding
|
||||
Preamble = $preambleBytes
|
||||
}
|
||||
}
|
||||
|
||||
function Write-TaskText {
|
||||
param(
|
||||
[Parameter(Mandatory)][string] $Path,
|
||||
[Parameter(Mandatory)][string] $Text,
|
||||
[Parameter(Mandatory)] $Encoding,
|
||||
[Parameter(Mandatory)][AllowEmptyCollection()][byte[]] $Preamble
|
||||
)
|
||||
|
||||
$body = $Encoding.GetBytes($Text)
|
||||
$output = [byte[]]::new($Preamble.Length + $body.Length)
|
||||
if ($Preamble.Length -ne 0) {
|
||||
[Buffer]::BlockCopy($Preamble, 0, $output, 0, $Preamble.Length)
|
||||
}
|
||||
[Buffer]::BlockCopy($body, 0, $output, $Preamble.Length, $body.Length)
|
||||
[IO.File]::WriteAllBytes($Path, $output)
|
||||
}
|
||||
|
||||
$changedTextFiles = [Collections.Generic.List[string]]::new()
|
||||
foreach ($textFile in Get-TaskTextFile) {
|
||||
$fileContent = Read-TaskText -Path $textFile.FullName
|
||||
$updatedText = $fileContent.Text
|
||||
foreach ($rule in $replacementRules) {
|
||||
$updatedText = [Text.RegularExpressions.Regex]::Replace(
|
||||
$updatedText,
|
||||
$rule.Pattern,
|
||||
$rule.Replacement,
|
||||
[Text.RegularExpressions.RegexOptions]::CultureInvariant
|
||||
)
|
||||
}
|
||||
|
||||
if ($updatedText -ceq $fileContent.Text) {
|
||||
continue
|
||||
}
|
||||
|
||||
$relativePath = [IO.Path]::GetRelativePath($taskWorkspaceRoot, $textFile.FullName)
|
||||
$changedTextFiles.Add($relativePath)
|
||||
if ($Apply) {
|
||||
Write-TaskText -Path $textFile.FullName `
|
||||
-Text $updatedText `
|
||||
-Encoding $fileContent.Encoding `
|
||||
-Preamble $fileContent.Preamble
|
||||
}
|
||||
}
|
||||
|
||||
$pathMoves = [Collections.Generic.List[object]]::new()
|
||||
Get-ChildItem -LiteralPath $nativeProjectRoot -Recurse -File |
|
||||
Where-Object {
|
||||
$_.Name -match '^sn_' -or
|
||||
$_.Name -cin @(
|
||||
'StgSharpNative.h',
|
||||
'NitloadInnovationFramework.h',
|
||||
'NitloadFramework.h'
|
||||
)
|
||||
} |
|
||||
ForEach-Object {
|
||||
$newName = if ($_.Name -cin @(
|
||||
'StgSharpNative.h',
|
||||
'NitloadInnovationFramework.h',
|
||||
'NitloadFramework.h'
|
||||
)) {
|
||||
'NitloadFrameWork.h'
|
||||
}
|
||||
else {
|
||||
$_.Name -replace '^sn_', 'nif_'
|
||||
}
|
||||
$pathMoves.Add([PSCustomObject]@{
|
||||
Source = $_.FullName
|
||||
Target = Join-Path $_.DirectoryName $newName
|
||||
})
|
||||
}
|
||||
|
||||
Get-ChildItem -LiteralPath $nativeProjectRoot -Recurse -Directory |
|
||||
Where-Object { $_.Name -in @('sn-head', 'sn-src', 'sn-template') } |
|
||||
Sort-Object { $_.FullName.Length } -Descending |
|
||||
ForEach-Object {
|
||||
$pathMoves.Add([PSCustomObject]@{
|
||||
Source = $_.FullName
|
||||
Target = Join-Path $_.Parent.FullName ($_.Name -replace '^sn-', 'nif-')
|
||||
})
|
||||
}
|
||||
|
||||
foreach ($pathMove in $pathMoves) {
|
||||
Test-TaskPath -Path $pathMove.Source
|
||||
Test-TaskPath -Path $pathMove.Target
|
||||
if (Test-Path -LiteralPath $pathMove.Target) {
|
||||
throw "Rename target already exists: $($pathMove.Target)"
|
||||
}
|
||||
}
|
||||
|
||||
"Text files to update: $($changedTextFiles.Count)"
|
||||
$changedTextFiles | ForEach-Object { " TEXT $_" }
|
||||
"Paths to rename: $($pathMoves.Count)"
|
||||
$pathMoves | ForEach-Object {
|
||||
$source = [IO.Path]::GetRelativePath($taskWorkspaceRoot, $_.Source)
|
||||
$target = [IO.Path]::GetRelativePath($taskWorkspaceRoot, $_.Target)
|
||||
" MOVE $source -> $target"
|
||||
}
|
||||
|
||||
if (-not $Apply) {
|
||||
'Dry run only. Re-run with -Apply to perform the migration.'
|
||||
exit 0
|
||||
}
|
||||
|
||||
foreach ($pathMove in $pathMoves) {
|
||||
Move-Item -LiteralPath $pathMove.Source -Destination $pathMove.Target
|
||||
}
|
||||
|
||||
'NIF prefix migration completed.'
|
||||
@@ -0,0 +1,77 @@
|
||||
[CmdletBinding()]
|
||||
param([switch] $Apply)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$workspaceRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
|
||||
$nativeRoot = Join-Path $workspaceRoot 'src/Nitload.Native'
|
||||
$textRoots = @(
|
||||
(Join-Path $workspaceRoot 'Directory.Build.targets'),
|
||||
$nativeRoot,
|
||||
(Join-Path $workspaceRoot 'src/Nitload.Common'),
|
||||
(Join-Path $workspaceRoot 'src/Nitload.Mathematics'),
|
||||
(Join-Path $workspaceRoot 'src/Nitload.Graphics')
|
||||
)
|
||||
$textExtensions = @('.c', '.h', '.cs', '.cmake', '.txt', '.md', '.vcxproj', '.filters', '.targets')
|
||||
$utf8 = [Text.UTF8Encoding]::new($false, $true)
|
||||
|
||||
$files = foreach ($root in $textRoots) {
|
||||
if (Test-Path -LiteralPath $root -PathType Leaf) {
|
||||
Get-Item -LiteralPath $root
|
||||
} else {
|
||||
Get-ChildItem -LiteralPath $root -Recurse -File | Where-Object {
|
||||
$_.Extension -in $textExtensions -and
|
||||
$_.FullName -notmatch '[\\/](bin|obj|cmake_build)[\\/]'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$changes = [Collections.Generic.List[string]]::new()
|
||||
foreach ($file in $files) {
|
||||
$bytes = [IO.File]::ReadAllBytes($file.FullName)
|
||||
try { $content = $utf8.GetString($bytes) }
|
||||
catch [Text.DecoderFallbackException] { continue }
|
||||
if ($file.FullName -eq (Join-Path $nativeRoot 'README.md') -and
|
||||
$content.Contains('The C implementation uses `nfn`')) { continue }
|
||||
|
||||
$updated = $content.Replace('NIF_', 'NFN_').Replace('nif_', 'nfn_').Replace('nif-', 'nfn-')
|
||||
$updated = $updated.Replace('NF_', 'NFN_').Replace('nf_', 'nfn_').Replace('nf-', 'nfn-')
|
||||
# The previous migration left private SN macros in this header.
|
||||
if ($file.Name -in @('nif_intrinsic.std.h', 'nf_intrinsic.std.h')) {
|
||||
$updated = $updated.Replace('_SN_', '_NFN_')
|
||||
}
|
||||
if ($updated -ceq $content) { continue }
|
||||
|
||||
$changes.Add([IO.Path]::GetRelativePath($workspaceRoot, $file.FullName))
|
||||
if ($Apply) { [IO.File]::WriteAllText($file.FullName, $updated, $utf8) }
|
||||
}
|
||||
|
||||
$moves = [Collections.Generic.List[object]]::new()
|
||||
foreach ($directory in @('nif-head', 'nif-src', 'nif-template', 'nf-head', 'nf-src', 'nf-template')) {
|
||||
$sourceDir = Join-Path $nativeRoot $directory
|
||||
if (-not (Test-Path -LiteralPath $sourceDir)) { continue }
|
||||
foreach ($file in Get-ChildItem -LiteralPath $sourceDir -File | Where-Object { $_.Name -cmatch '^(nif|nf)_' }) {
|
||||
$moves.Add(@($file.FullName, (Join-Path $sourceDir ($file.Name -creplace '^(nif|nf)_', 'nfn_'))))
|
||||
}
|
||||
$moves.Add(@($sourceDir, (Join-Path $nativeRoot ($directory -creplace '^(nif|nf)-', 'nfn-'))))
|
||||
}
|
||||
|
||||
foreach ($move in $moves) {
|
||||
if (Test-Path -LiteralPath $move[1]) { throw "Rename target already exists: $($move[1])" }
|
||||
}
|
||||
|
||||
"Text files to update: $($changes.Count)"
|
||||
$changes | ForEach-Object { " TEXT $_" }
|
||||
"Paths to rename: $($moves.Count)"
|
||||
$moves | ForEach-Object {
|
||||
" MOVE $([IO.Path]::GetRelativePath($workspaceRoot, $_[0])) -> $([IO.Path]::GetRelativePath($workspaceRoot, $_[1]))"
|
||||
}
|
||||
|
||||
if (-not $Apply) {
|
||||
'Dry run only. Re-run with -Apply to perform the migration.'
|
||||
exit 0
|
||||
}
|
||||
|
||||
foreach ($move in $moves) { Move-Item -LiteralPath $move[0] -Destination $move[1] }
|
||||
'NFN prefix migration completed.'
|
||||
Reference in New Issue
Block a user