From e24efd9f9cbd9f9d8122c0e089d16338a275d9e0 Mon Sep 17 00:00:00 2001 From: Nitload Date: Sun, 27 Sep 2026 00:59:42 +0800 Subject: [PATCH] merge C base name prefix to nfn --- Directory.Build.targets | 2 +- .../ProcessorAbstraction/Numa.cs | 10 +- src/Nitload.Common/Threading/ThreadHelper.cs | 2 +- src/Nitload.Graphics/glfw.cs | 2 +- .../Numeric/Graphics/Vec3.cs | 28 --- .../Numeric/Runtime/MatrixParallel.cs | 6 +- .../Numeric/Runtime/MatrixParallelThread.cs | 4 +- src/Nitload.Native/CMakeLists.txt | 168 +++++++------- src/Nitload.Native/CMakePresets.json | 6 +- src/Nitload.Native/ExternalLibs.cmake | 98 ++++---- src/Nitload.Native/Nitload.Native.vcxproj | 54 ++--- .../Nitload.Native.vcxproj.filters | 52 ++--- src/Nitload.Native/README.md | 32 ++- src/Nitload.Native/SIMDID.x86.md | 2 +- src/Nitload.Native/lib/CMakeLists.txt | 6 +- src/Nitload.Native/lib/glfw/CMakeLists.txt | 4 +- src/Nitload.Native/lib/glfw/glfw3native.h | 4 +- src/Nitload.Native/lib/stbi/CMakeLists.txt | 2 +- .../nfn-head/NitloadFrameWork.h | 35 +++ .../{nif-head => nfn-head}/glfw_function.h | 0 .../nfn_internal.h} | 28 +-- .../nfn_intrinsic.context.base.h} | 4 +- .../nfn_intrinsic.context.x86.h} | 214 ++++++++--------- .../nfn_intrinsic.h} | 48 ++-- .../nfn-head/nfn_intrinsic.matkernel.h | 54 +++++ .../nfn-head/nfn_intrinsic.std.h | 101 ++++++++ src/Nitload.Native/nfn-head/nfn_target.h | 94 ++++++++ .../{nif-src => nfn-src}/dllmain.c | 6 +- .../{nif-src => nfn-src}/load_glfw.c | 2 +- .../{nif-src => nfn-src}/load_intrinsic.x86.c | 30 +-- .../{nif-src => nfn-src}/m.bufop.x86.c | 58 ++--- .../{nif-src => nfn-src}/m.solve.x86.c | 18 +- .../{nif-src => nfn-src}/m.transpose.x86.c | 16 +- .../{nif-src => nfn-src}/mk.fma.pack.c | 18 +- .../{nif-src => nfn-src}/mk.fma.x86.c | 116 +++++----- .../{nif-src => nfn-src}/mk.p_scan.x86.c | 20 +- .../{nif-src => nfn-src}/s.factorial.x86.c | 12 +- .../{nif-src => nfn-src}/s.hash.x86.c | 6 +- .../{nif-src => nfn-src}/simdid.x86.c | 14 +- .../{nif-src => nfn-src}/simdid_compare.x86.c | 14 +- .../{nif-src => nfn-src}/sk.fma.x86.c | 26 +-- .../{nif-src => nfn-src}/thread.linux.c | 102 ++++----- .../{nif-src => nfn-src}/thread.windows.c | 14 +- .../{nif-src => nfn-src}/vector.c | 6 +- .../{nif-src => nfn-src}/vector_dot.c | 12 +- .../nfn_template.fma.x86.h} | 18 +- .../nif-head/NitloadFrameWork.h | 35 --- .../nif-head/nif_intrinsic.matkernel.h | 54 ----- .../nif-head/nif_intrinsic.std.h | 101 -------- src/Nitload.Native/nif-head/nif_target.h | 94 -------- tools/Rename-NativePrefix.ps1 | 215 ------------------ tools/Rename-NifToNfn.ps1 | 77 +++++++ 52 files changed, 1002 insertions(+), 1142 deletions(-) create mode 100644 src/Nitload.Native/nfn-head/NitloadFrameWork.h rename src/Nitload.Native/{nif-head => nfn-head}/glfw_function.h (100%) rename src/Nitload.Native/{nif-head/nif_internal.h => nfn-head/nfn_internal.h} (54%) rename src/Nitload.Native/{nif-head/nif_intrinsic.context.base.h => nfn-head/nfn_intrinsic.context.base.h} (94%) rename src/Nitload.Native/{nif-head/nif_intrinsic.context.x86.h => nfn-head/nfn_intrinsic.context.x86.h} (54%) rename src/Nitload.Native/{nif-head/nif_intrinsic.h => nfn-head/nfn_intrinsic.h} (82%) create mode 100644 src/Nitload.Native/nfn-head/nfn_intrinsic.matkernel.h create mode 100644 src/Nitload.Native/nfn-head/nfn_intrinsic.std.h create mode 100644 src/Nitload.Native/nfn-head/nfn_target.h rename src/Nitload.Native/{nif-src => nfn-src}/dllmain.c (85%) rename src/Nitload.Native/{nif-src => nfn-src}/load_glfw.c (99%) rename src/Nitload.Native/{nif-src => nfn-src}/load_intrinsic.x86.c (86%) rename src/Nitload.Native/{nif-src => nfn-src}/m.bufop.x86.c (91%) rename src/Nitload.Native/{nif-src => nfn-src}/m.solve.x86.c (94%) rename src/Nitload.Native/{nif-src => nfn-src}/m.transpose.x86.c (84%) rename src/Nitload.Native/{nif-src => nfn-src}/mk.fma.pack.c (97%) rename src/Nitload.Native/{nif-src => nfn-src}/mk.fma.x86.c (83%) rename src/Nitload.Native/{nif-src => nfn-src}/mk.p_scan.x86.c (75%) rename src/Nitload.Native/{nif-src => nfn-src}/s.factorial.x86.c (80%) rename src/Nitload.Native/{nif-src => nfn-src}/s.hash.x86.c (93%) rename src/Nitload.Native/{nif-src => nfn-src}/simdid.x86.c (97%) rename src/Nitload.Native/{nif-src => nfn-src}/simdid_compare.x86.c (97%) rename src/Nitload.Native/{nif-src => nfn-src}/sk.fma.x86.c (96%) rename src/Nitload.Native/{nif-src => nfn-src}/thread.linux.c (70%) rename src/Nitload.Native/{nif-src => nfn-src}/thread.windows.c (88%) rename src/Nitload.Native/{nif-src => nfn-src}/vector.c (92%) rename src/Nitload.Native/{nif-src => nfn-src}/vector_dot.c (90%) rename src/Nitload.Native/{nif-template/nif_template.fma.x86.h => nfn-template/nfn_template.fma.x86.h} (91%) delete mode 100644 src/Nitload.Native/nif-head/NitloadFrameWork.h delete mode 100644 src/Nitload.Native/nif-head/nif_intrinsic.matkernel.h delete mode 100644 src/Nitload.Native/nif-head/nif_intrinsic.std.h delete mode 100644 src/Nitload.Native/nif-head/nif_target.h delete mode 100644 tools/Rename-NativePrefix.ps1 create mode 100644 tools/Rename-NifToNfn.ps1 diff --git a/Directory.Build.targets b/Directory.Build.targets index 3bd7f0ac..19d271d7 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -10,7 +10,7 @@ $(SolutionRoot)cmake_build/$(NativeCMakePreset) <_NativeCMakeOutputDir>$([System.String]::Copy('$(NativeBuildDir)').Replace('\', '/')) - + diff --git a/src/Nitload.Common/HighPerformance/ProcessorAbstraction/Numa.cs b/src/Nitload.Common/HighPerformance/ProcessorAbstraction/Numa.cs index 4215ea23..d2100eb1 100644 --- a/src/Nitload.Common/HighPerformance/ProcessorAbstraction/Numa.cs +++ b/src/Nitload.Common/HighPerformance/ProcessorAbstraction/Numa.cs @@ -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( @@ -84,7 +84,7 @@ namespace Nitload.Common.HighPerformance.ProcessorAbstraction Span globalCpuIdInNuma ); - [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( @@ -119,7 +119,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( @@ -138,7 +138,7 @@ namespace Nitload.Common.HighPerformance.ProcessorAbstraction return new(numaId, count, globalIndex); } - [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( @@ -146,7 +146,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( diff --git a/src/Nitload.Common/Threading/ThreadHelper.cs b/src/Nitload.Common/Threading/ThreadHelper.cs index 597f9e19..1e7f20af 100644 --- a/src/Nitload.Common/Threading/ThreadHelper.cs +++ b/src/Nitload.Common/Threading/ThreadHelper.cs @@ -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( diff --git a/src/Nitload.Graphics/glfw.cs b/src/Nitload.Graphics/glfw.cs index 3eb892e2..3bc046af 100644 --- a/src/Nitload.Graphics/glfw.cs +++ b/src/Nitload.Graphics/glfw.cs @@ -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 ); diff --git a/src/Nitload.Mathematics/Numeric/Graphics/Vec3.cs b/src/Nitload.Mathematics/Numeric/Graphics/Vec3.cs index 1ef78a69..8389f47e 100644 --- a/src/Nitload.Mathematics/Numeric/Graphics/Vec3.cs +++ b/src/Nitload.Mathematics/Numeric/Graphics/Vec3.cs @@ -16,59 +16,37 @@ namespace Nitload.Mathematics.Numeric.Graphics { [MethodImpl(MethodImplOptions.AggressiveInlining)] -<<<<<<< HEAD - public static Vec3 ConvertToDouble(Vec3 source) -======= public static Vec3 ConvertToDouble( Vec3 source ) ->>>>>>> 8755185e78a8091ca252c1342249110180446be3 { return FromVector256Unsafe(Vector256.ConvertToDouble(source.AsVector256Safe())); } [MethodImpl(MethodImplOptions.AggressiveInlining)] -<<<<<<< HEAD - public static Vec3 ConvertToDouble(Vec3 source) -======= public static Vec3 ConvertToDouble( Vec3 source ) ->>>>>>> 8755185e78a8091ca252c1342249110180446be3 { return FromVector256Unsafe(Vector256.ConvertToDouble(source.AsVector256Safe())); } -<<<<<<< HEAD - #region cast - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 ConvertToSingle(Vec3 source) -======= [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vec3 ConvertToSingle( Vec3 source ) ->>>>>>> 8755185e78a8091ca252c1342249110180446be3 { return FromVector128Unsafe(Vector128.ConvertToSingle(source.AsVector128Safe())); } [MethodImpl(MethodImplOptions.AggressiveInlining)] -<<<<<<< HEAD - public static Vec3 ConvertToSingle(Vec3 source) -======= public static Vec3 ConvertToSingle( Vec3 source ) ->>>>>>> 8755185e78a8091ca252c1342249110180446be3 { return FromVector128Unsafe(Vector128.ConvertToSingle(source.AsVector128Safe())); } -<<<<<<< HEAD - public static bool IsParallel(Vec3 left, Vec3 right) where T: unmanaged,INumber -======= public static Vec3 FromSpan( ReadOnlySpan span ) where T : unmanaged, INumber @@ -84,7 +62,6 @@ namespace Nitload.Mathematics.Numeric.Graphics Vec3 left, Vec3 right ) where T : unmanaged,INumber ->>>>>>> 8755185e78a8091ca252c1342249110180446be3 { return Cross(left, right).Equals(T.Zero); } @@ -145,11 +122,6 @@ namespace Nitload.Mathematics.Numeric.Graphics return Unsafe.As, Vec3>(ref source); } -<<<<<<< HEAD -#ednregion - -======= ->>>>>>> 8755185e78a8091ca252c1342249110180446be3 #region cross [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Nitload.Mathematics/Numeric/Runtime/MatrixParallel.cs b/src/Nitload.Mathematics/Numeric/Runtime/MatrixParallel.cs index c55176f0..89e56af3 100644 --- a/src/Nitload.Mathematics/Numeric/Runtime/MatrixParallel.cs +++ b/src/Nitload.Mathematics/Numeric/Runtime/MatrixParallel.cs @@ -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( diff --git a/src/Nitload.Mathematics/Numeric/Runtime/MatrixParallelThread.cs b/src/Nitload.Mathematics/Numeric/Runtime/MatrixParallelThread.cs index 083d1335..2a8ac7b4 100644 --- a/src/Nitload.Mathematics/Numeric/Runtime/MatrixParallelThread.cs +++ b/src/Nitload.Mathematics/Numeric/Runtime/MatrixParallelThread.cs @@ -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( diff --git a/src/Nitload.Native/CMakeLists.txt b/src/Nitload.Native/CMakeLists.txt index aeea2cc5..7fa06e56 100644 --- a/src/Nitload.Native/CMakeLists.txt +++ b/src/Nitload.Native/CMakeLists.txt @@ -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 /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/) 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}/$/${NIF_ARCH_TAG}) + COMPILE_PDB_OUTPUT_DIRECTORY ${NFN_OBJECT_ROOT_DIR}/$/${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}/$/${NIF_ARCH_TAG}/) + /Fd${NFN_OBJECT_ROOT_DIR}/$/${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}") diff --git a/src/Nitload.Native/CMakePresets.json b/src/Nitload.Native/CMakePresets.json index fc82d3d6..bc698b7e 100644 --- a/src/Nitload.Native/CMakePresets.json +++ b/src/Nitload.Native/CMakePresets.json @@ -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" } } ], diff --git a/src/Nitload.Native/ExternalLibs.cmake b/src/Nitload.Native/ExternalLibs.cmake index 62ec594c..a4f969ab 100644 --- a/src/Nitload.Native/ExternalLibs.cmake +++ b/src/Nitload.Native/ExternalLibs.cmake @@ -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}") diff --git a/src/Nitload.Native/Nitload.Native.vcxproj b/src/Nitload.Native/Nitload.Native.vcxproj index abe5b157..aa5d8c7c 100644 --- a/src/Nitload.Native/Nitload.Native.vcxproj +++ b/src/Nitload.Native/Nitload.Native.vcxproj @@ -111,7 +111,7 @@ stdc11 true Speed - $(ProjectDir)lib;$(ProjectDir)nif-head;$(ProjectDir)nif-template;%(AdditionalIncludeDirectories) + $(ProjectDir)lib;$(ProjectDir)nfn-head;$(ProjectDir)nfn-template;%(AdditionalIncludeDirectories) @@ -173,23 +173,23 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -198,15 +198,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/Nitload.Native/Nitload.Native.vcxproj.filters b/src/Nitload.Native/Nitload.Native.vcxproj.filters index 3a1a072c..6a5f7b20 100644 --- a/src/Nitload.Native/Nitload.Native.vcxproj.filters +++ b/src/Nitload.Native/Nitload.Native.vcxproj.filters @@ -21,69 +21,69 @@ - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 源文件 - + 头文件 - + 头文件 - + 头文件 - + 头文件 @@ -95,19 +95,19 @@ 头文件 - + 头文件 - + 头文件 - + 头文件 - + 头文件 - + 模板文件 diff --git a/src/Nitload.Native/README.md b/src/Nitload.Native/README.md index cd6e5b1f..01e3d6b1 100644 --- a/src/Nitload.Native/README.md +++ b/src/Nitload.Native/README.md @@ -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` at the repository root. +When using CMake Tools, set `cmake.copyCompileCommands` to +`${workspaceFolder}/compile_commands.json` so the active Debug or Release preset +updates that file after configuration. For command-line configuration, copy +`cmake_build//compile_commands.json` to the repository root. Restart +clangd after changing the database or renaming headers. + ## Code Layout Conventions: diff --git a/src/Nitload.Native/SIMDID.x86.md b/src/Nitload.Native/SIMDID.x86.md index f6cd1433..95d210c3 100644 --- a/src/Nitload.Native/SIMDID.x86.md +++ b/src/Nitload.Native/SIMDID.x86.md @@ -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. --- diff --git a/src/Nitload.Native/lib/CMakeLists.txt b/src/Nitload.Native/lib/CMakeLists.txt index cff1de01..55877157 100644 --- a/src/Nitload.Native/lib/CMakeLists.txt +++ b/src/Nitload.Native/lib/CMakeLists.txt @@ -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() \ No newline at end of file diff --git a/src/Nitload.Native/lib/glfw/CMakeLists.txt b/src/Nitload.Native/lib/glfw/CMakeLists.txt index 9e80967c..6f7a2d3c 100644 --- a/src/Nitload.Native/lib/glfw/CMakeLists.txt +++ b/src/Nitload.Native/lib/glfw/CMakeLists.txt @@ -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() \ No newline at end of file diff --git a/src/Nitload.Native/lib/glfw/glfw3native.h b/src/Nitload.Native/lib/glfw/glfw3native.h index 1194958b..79f37ba5 100644 --- a/src/Nitload.Native/lib/glfw/glfw3native.h +++ b/src/Nitload.Native/lib/glfw/glfw3native.h @@ -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)); diff --git a/src/Nitload.Native/lib/stbi/CMakeLists.txt b/src/Nitload.Native/lib/stbi/CMakeLists.txt index 669c2731..959505a0 100644 --- a/src/Nitload.Native/lib/stbi/CMakeLists.txt +++ b/src/Nitload.Native/lib/stbi/CMakeLists.txt @@ -1,3 +1,3 @@ cmake_minimum_required(VERSION 3.16) -nif_register_external_package(${NIF_NATIVE_EXTERNAL_TARGET} stbi ${CMAKE_CURRENT_LIST_DIR}) \ No newline at end of file +nfn_register_external_package(${NFN_NATIVE_EXTERNAL_TARGET} stbi ${CMAKE_CURRENT_LIST_DIR}) \ No newline at end of file diff --git a/src/Nitload.Native/nfn-head/NitloadFrameWork.h b/src/Nitload.Native/nfn-head/NitloadFrameWork.h new file mode 100644 index 00000000..ed9f9663 --- /dev/null +++ b/src/Nitload.Native/nfn-head/NitloadFrameWork.h @@ -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 +#include +#include + +#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 diff --git a/src/Nitload.Native/nif-head/glfw_function.h b/src/Nitload.Native/nfn-head/glfw_function.h similarity index 100% rename from src/Nitload.Native/nif-head/glfw_function.h rename to src/Nitload.Native/nfn-head/glfw_function.h diff --git a/src/Nitload.Native/nif-head/nif_internal.h b/src/Nitload.Native/nfn-head/nfn_internal.h similarity index 54% rename from src/Nitload.Native/nif-head/nif_internal.h rename to src/Nitload.Native/nfn-head/nfn_internal.h index 87e81f1b..eb477586 100644 --- a/src/Nitload.Native/nif-head/nif_internal.h +++ b/src/Nitload.Native/nfn-head/nfn_internal.h @@ -1,6 +1,6 @@ -#ifndef NIF_INTERNAL -#define NIF_INTERNAL +#ifndef NFN_INTERNAL +#define NFN_INTERNAL #include @@ -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 #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 diff --git a/src/Nitload.Native/nif-head/nif_intrinsic.context.base.h b/src/Nitload.Native/nfn-head/nfn_intrinsic.context.base.h similarity index 94% rename from src/Nitload.Native/nif-head/nif_intrinsic.context.base.h rename to src/Nitload.Native/nfn-head/nfn_intrinsic.context.base.h index ec66769d..acfd241f 100644 --- a/src/Nitload.Native/nif-head/nif_intrinsic.context.base.h +++ b/src/Nitload.Native/nfn-head/nfn_intrinsic.context.base.h @@ -1,5 +1,5 @@ -#ifndef NIF_INTRINSIC_CONTEXT_BASE -#define NIF_INTRINSIC_CONTEXT_BASE +#ifndef NFN_INTRINSIC_CONTEXT_BASE +#define NFN_INTRINSIC_CONTEXT_BASE // ----------------------------------------------------------------------------- diff --git a/src/Nitload.Native/nif-head/nif_intrinsic.context.x86.h b/src/Nitload.Native/nfn-head/nfn_intrinsic.context.x86.h similarity index 54% rename from src/Nitload.Native/nif-head/nif_intrinsic.context.x86.h rename to src/Nitload.Native/nfn-head/nfn_intrinsic.context.x86.h index c0a98aab..b35527c7 100644 --- a/src/Nitload.Native/nif-head/nif_intrinsic.context.x86.h +++ b/src/Nitload.Native/nfn-head/nfn_intrinsic.context.x86.h @@ -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 diff --git a/src/Nitload.Native/nif-head/nif_intrinsic.h b/src/Nitload.Native/nfn-head/nfn_intrinsic.h similarity index 82% rename from src/Nitload.Native/nif-head/nif_intrinsic.h rename to src/Nitload.Native/nfn-head/nfn_intrinsic.h index 8fc44040..4fd341c1 100644 --- a/src/Nitload.Native/nif-head/nif_intrinsic.h +++ b/src/Nitload.Native/nfn-head/nfn_intrinsic.h @@ -4,11 +4,11 @@ #define SSC_INTRIN_HEAD #include "NitloadFrameWork.h" -#include "nif_target.h" +#include "nfn_target.h" #include #include #include -#include "nif_intrinsic.matkernel.h" +#include "nfn_intrinsic.matkernel.h" #include #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 { diff --git a/src/Nitload.Native/nfn-head/nfn_intrinsic.matkernel.h b/src/Nitload.Native/nfn-head/nfn_intrinsic.matkernel.h new file mode 100644 index 00000000..8aacf688 --- /dev/null +++ b/src/Nitload.Native/nfn-head/nfn_intrinsic.matkernel.h @@ -0,0 +1,54 @@ +#ifndef NFN_MATKERNEL +#define NFN_MATKERNEL + +#include +#include + +#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 */ diff --git a/src/Nitload.Native/nfn-head/nfn_intrinsic.std.h b/src/Nitload.Native/nfn-head/nfn_intrinsic.std.h new file mode 100644 index 00000000..1032d6f4 --- /dev/null +++ b/src/Nitload.Native/nfn-head/nfn_intrinsic.std.h @@ -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 diff --git a/src/Nitload.Native/nfn-head/nfn_target.h b/src/Nitload.Native/nfn-head/nfn_target.h new file mode 100644 index 00000000..d6faa41f --- /dev/null +++ b/src/Nitload.Native/nfn-head/nfn_target.h @@ -0,0 +1,94 @@ +#ifndef NFN_TARGET +#define NFN_TARGET + +#include "nfn_internal.h" +#include + +#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 diff --git a/src/Nitload.Native/nif-src/dllmain.c b/src/Nitload.Native/nfn-src/dllmain.c similarity index 85% rename from src/Nitload.Native/nif-src/dllmain.c rename to src/Nitload.Native/nfn-src/dllmain.c index 48a349fa..4e5db3a6 100644 --- a/src/Nitload.Native/nif-src/dllmain.c +++ b/src/Nitload.Native/nfn-src/dllmain.c @@ -1,18 +1,18 @@ #include "NitloadFrameWork.h" -#include "nif_intrinsic.matkernel.h" +#include "nfn_intrinsic.matkernel.h" #include #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; } } } diff --git a/src/Nitload.Native/nif-src/load_glfw.c b/src/Nitload.Native/nfn-src/load_glfw.c similarity index 99% rename from src/Nitload.Native/nif-src/load_glfw.c rename to src/Nitload.Native/nfn-src/load_glfw.c index 7f27fcf0..eb54249e 100644 --- a/src/Nitload.Native/nif-src/load_glfw.c +++ b/src/Nitload.Native/nfn-src/load_glfw.c @@ -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; diff --git a/src/Nitload.Native/nif-src/load_intrinsic.x86.c b/src/Nitload.Native/nfn-src/load_intrinsic.x86.c similarity index 86% rename from src/Nitload.Native/nif-src/load_intrinsic.x86.c rename to src/Nitload.Native/nfn-src/load_intrinsic.x86.c index 127b3ee4..34c4eb51 100644 --- a/src/Nitload.Native/nif-src/load_intrinsic.x86.c +++ b/src/Nitload.Native/nfn-src/load_intrinsic.x86.c @@ -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; diff --git a/src/Nitload.Native/nif-src/m.bufop.x86.c b/src/Nitload.Native/nfn-src/m.bufop.x86.c similarity index 91% rename from src/Nitload.Native/nif-src/m.bufop.x86.c rename to src/Nitload.Native/nfn-src/m.bufop.x86.c index 448a5708..9c3a9b8a 100644 --- a/src/Nitload.Native/nif-src/m.bufop.x86.c +++ b/src/Nitload.Native/nfn-src/m.bufop.x86.c @@ -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 -#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); diff --git a/src/Nitload.Native/nif-src/m.solve.x86.c b/src/Nitload.Native/nfn-src/m.solve.x86.c similarity index 94% rename from src/Nitload.Native/nif-src/m.solve.x86.c rename to src/Nitload.Native/nfn-src/m.solve.x86.c index 65015852..d63270d7 100644 --- a/src/Nitload.Native/nif-src/m.solve.x86.c +++ b/src/Nitload.Native/nfn-src/m.solve.x86.c @@ -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 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]); diff --git a/src/Nitload.Native/nif-src/m.transpose.x86.c b/src/Nitload.Native/nfn-src/m.transpose.x86.c similarity index 84% rename from src/Nitload.Native/nif-src/m.transpose.x86.c rename to src/Nitload.Native/nfn-src/m.transpose.x86.c index 6a428dab..3ad9e142 100644 --- a/src/Nitload.Native/nif-src/m.transpose.x86.c +++ b/src/Nitload.Native/nfn-src/m.transpose.x86.c @@ -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]; diff --git a/src/Nitload.Native/nif-src/mk.fma.pack.c b/src/Nitload.Native/nfn-src/mk.fma.pack.c similarity index 97% rename from src/Nitload.Native/nif-src/mk.fma.pack.c rename to src/Nitload.Native/nfn-src/mk.fma.pack.c index b9a89c29..4947dfaf 100644 --- a/src/Nitload.Native/nif-src/mk.fma.pack.c +++ b/src/Nitload.Native/nfn-src/mk.fma.pack.c @@ -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]; diff --git a/src/Nitload.Native/nif-src/mk.fma.x86.c b/src/Nitload.Native/nfn-src/mk.fma.x86.c similarity index 83% rename from src/Nitload.Native/nif-src/mk.fma.x86.c rename to src/Nitload.Native/nfn-src/mk.fma.x86.c index 2a30d351..b2b77d64 100644 --- a/src/Nitload.Native/nif-src/mk.fma.x86.c +++ b/src/Nitload.Native/nfn-src/mk.fma.x86.c @@ -1,22 +1,22 @@ -#include "nif_target.h" +#include "nfn_target.h" #include -#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 #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); diff --git a/src/Nitload.Native/nif-src/mk.p_scan.x86.c b/src/Nitload.Native/nfn-src/mk.p_scan.x86.c similarity index 75% rename from src/Nitload.Native/nif-src/mk.p_scan.x86.c rename to src/Nitload.Native/nfn-src/mk.p_scan.x86.c index a20efd78..93f53066 100644 --- a/src/Nitload.Native/nif-src/mk.p_scan.x86.c +++ b/src/Nitload.Native/nfn-src/mk.p_scan.x86.c @@ -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 #include #include -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]; diff --git a/src/Nitload.Native/nif-src/s.factorial.x86.c b/src/Nitload.Native/nfn-src/s.factorial.x86.c similarity index 80% rename from src/Nitload.Native/nif-src/s.factorial.x86.c rename to src/Nitload.Native/nfn-src/s.factorial.x86.c index 4580600a..61bf559d 100644 --- a/src/Nitload.Native/nif-src/s.factorial.x86.c +++ b/src/Nitload.Native/nfn-src/s.factorial.x86.c @@ -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]; diff --git a/src/Nitload.Native/nif-src/s.hash.x86.c b/src/Nitload.Native/nfn-src/s.hash.x86.c similarity index 93% rename from src/Nitload.Native/nif-src/s.hash.x86.c rename to src/Nitload.Native/nfn-src/s.hash.x86.c index 3bdad8da..7dd2f51d 100644 --- a/src/Nitload.Native/nif-src/s.hash.x86.c +++ b/src/Nitload.Native/nfn-src/s.hash.x86.c @@ -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; diff --git a/src/Nitload.Native/nif-src/simdid.x86.c b/src/Nitload.Native/nfn-src/simdid.x86.c similarity index 97% rename from src/Nitload.Native/nif-src/simdid.x86.c rename to src/Nitload.Native/nfn-src/simdid.x86.c index e3bcd202..b6ef6b1d 100644 --- a/src/Nitload.Native/nif-src/simdid.x86.c +++ b/src/Nitload.Native/nfn-src/simdid.x86.c @@ -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 #include @@ -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; } diff --git a/src/Nitload.Native/nif-src/simdid_compare.x86.c b/src/Nitload.Native/nfn-src/simdid_compare.x86.c similarity index 97% rename from src/Nitload.Native/nif-src/simdid_compare.x86.c rename to src/Nitload.Native/nfn-src/simdid_compare.x86.c index 69d5a10b..fde5c933 100644 --- a/src/Nitload.Native/nif-src/simdid_compare.x86.c +++ b/src/Nitload.Native/nfn-src/simdid_compare.x86.c @@ -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); diff --git a/src/Nitload.Native/nif-src/sk.fma.x86.c b/src/Nitload.Native/nfn-src/sk.fma.x86.c similarity index 96% rename from src/Nitload.Native/nif-src/sk.fma.x86.c rename to src/Nitload.Native/nfn-src/sk.fma.x86.c index 34ab42f6..3ded1184 100644 --- a/src/Nitload.Native/nif-src/sk.fma.x86.c +++ b/src/Nitload.Native/nfn-src/sk.fma.x86.c @@ -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]); diff --git a/src/Nitload.Native/nif-src/thread.linux.c b/src/Nitload.Native/nfn-src/thread.linux.c similarity index 70% rename from src/Nitload.Native/nif-src/thread.linux.c rename to src/Nitload.Native/nfn-src/thread.linux.c index b29bf47e..324fbc77 100644 --- a/src/Nitload.Native/nif-src/thread.linux.c +++ b/src/Nitload.Native/nfn-src/thread.linux.c @@ -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 #include #include @@ -16,27 +16,27 @@ #include #include -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; -typedef struct nif_linux_fill_cpu_context { +typedef struct nfn_linux_fill_cpu_context { uint64_t *internal; uint32_t *global; 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) @@ -47,7 +47,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; @@ -65,7 +65,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; @@ -77,14 +77,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; } @@ -103,24 +103,24 @@ 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; } -static int nif_linux_fill_cpu_id(int value, void *context) +static int nfn_linux_fill_cpu_id(int value, void *context) { - nif_linux_fill_cpu_context *fill_context = (nif_linux_fill_cpu_context *)context; + nfn_linux_fill_cpu_context *fill_context = (nfn_linux_fill_cpu_context *)context; if (fill_context->internal != NULL) fill_context->internal[fill_context->index] = (uint64_t)fill_context->index; @@ -131,37 +131,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; @@ -173,7 +173,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; @@ -197,7 +197,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) @@ -214,7 +214,7 @@ static int nif_linux_populate_writable_mapping(void *address, size_t size) /* 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. */ -NIF_API void NIF_DECL nif_set_thread_affinity(int core_id, int numa_id) +NFN_API void NFN_DECL nfn_set_thread_affinity(int core_id, int numa_id) { int cpu_count = (int)sysconf(_SC_NPROCESSORS_ONLN); if (cpu_count <= 0) @@ -238,14 +238,14 @@ NIF_API void NIF_DECL nif_set_thread_affinity(int core_id, int numa_id) 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; @@ -256,15 +256,15 @@ 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; } -NIF_API int NIF_DECL nif_get_numa_each(int numa_id, uint64_t *internal, uint32_t *global) +NFN_API int NFN_DECL nfn_get_numa_each(int numa_id, uint64_t *internal, uint32_t *global) { if (numa_id < 0) return 0; @@ -272,16 +272,16 @@ NIF_API int NIF_DECL nif_get_numa_each(int numa_id, uint64_t *internal, uint32_t 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; - nif_linux_fill_cpu_context fill_context = { internal, global, 0 }; - return nif_linux_visit_id_list(buffer, nif_linux_fill_cpu_id, &fill_context); + 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_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; @@ -303,9 +303,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; } @@ -313,14 +313,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); } diff --git a/src/Nitload.Native/nif-src/thread.windows.c b/src/Nitload.Native/nfn-src/thread.windows.c similarity index 88% rename from src/Nitload.Native/nif-src/thread.windows.c rename to src/Nitload.Native/nfn-src/thread.windows.c index 74f8fda2..789bf8fc 100644 --- a/src/Nitload.Native/nif-src/thread.windows.c +++ b/src/Nitload.Native/nfn-src/thread.windows.c @@ -1,12 +1,12 @@ -#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) /* 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. */ -NIF_API void NIF_DECL nif_set_thread_affinity(int core_id, int numa_id) +NFN_API void NFN_DECL nfn_set_thread_affinity(int core_id, int numa_id) { if (core_id < 0 || numa_id < 0) { /* Query which group the thread currently belongs to */ @@ -32,7 +32,7 @@ NIF_API void NIF_DECL nif_set_thread_affinity(int core_id, int numa_id) SetThreadGroupAffinity(GetCurrentThread(), &ga, 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)) @@ -47,7 +47,7 @@ NIF_API int NIF_DECL nif_get_numa_overall(int *out_numa_count, int *count_of_eac return 1; } -NIF_API int NIF_DECL nif_get_numa_each(int numa_id, uint64_t *internal, uint32_t *global) +NFN_API int NFN_DECL nfn_get_numa_each(int numa_id, uint64_t *internal, uint32_t *global) { ULONGLONG mask = 0; if (!GetNumaNodeProcessorMask((UCHAR)numa_id, &mask)) @@ -67,7 +67,7 @@ NIF_API int NIF_DECL nif_get_numa_each(int numa_id, uint64_t *internal, uint32_t } -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; @@ -83,7 +83,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; diff --git a/src/Nitload.Native/nif-src/vector.c b/src/Nitload.Native/nfn-src/vector.c similarity index 92% rename from src/Nitload.Native/nif-src/vector.c rename to src/Nitload.Native/nfn-src/vector.c index 8af554ee..9da6655a 100644 --- a/src/Nitload.Native/nif-src/vector.c +++ b/src/Nitload.Native/nfn-src/vector.c @@ -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); diff --git a/src/Nitload.Native/nif-src/vector_dot.c b/src/Nitload.Native/nfn-src/vector_dot.c similarity index 90% rename from src/Nitload.Native/nif-src/vector_dot.c rename to src/Nitload.Native/nfn-src/vector_dot.c index 4d0fd3f7..f949a413 100644 --- a/src/Nitload.Native/nif-src/vector_dot.c +++ b/src/Nitload.Native/nfn-src/vector_dot.c @@ -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]; diff --git a/src/Nitload.Native/nif-template/nif_template.fma.x86.h b/src/Nitload.Native/nfn-template/nfn_template.fma.x86.h similarity index 91% rename from src/Nitload.Native/nif-template/nif_template.fma.x86.h rename to src/Nitload.Native/nfn-template/nfn_template.fma.x86.h index 5493ea65..2d1f4fcc 100644 --- a/src/Nitload.Native/nif-template/nif_template.fma.x86.h +++ b/src/Nitload.Native/nfn-template/nfn_template.fma.x86.h @@ -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)); \ diff --git a/src/Nitload.Native/nif-head/NitloadFrameWork.h b/src/Nitload.Native/nif-head/NitloadFrameWork.h deleted file mode 100644 index 01665b13..00000000 --- a/src/Nitload.Native/nif-head/NitloadFrameWork.h +++ /dev/null @@ -1,35 +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 -#include -#include - -#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 core_id, int numa_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, uint64_t *internal, uint32_t *global); -NIF_API int NIF_DECL nif_get_numa_overall(int *out_numa_count, int *count_of_each_numa); -#endif diff --git a/src/Nitload.Native/nif-head/nif_intrinsic.matkernel.h b/src/Nitload.Native/nif-head/nif_intrinsic.matkernel.h deleted file mode 100644 index 9b508f44..00000000 --- a/src/Nitload.Native/nif-head/nif_intrinsic.matkernel.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef NIF_MATKERNEL -#define NIF_MATKERNEL - -#include -#include - -#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 */ diff --git a/src/Nitload.Native/nif-head/nif_intrinsic.std.h b/src/Nitload.Native/nif-head/nif_intrinsic.std.h deleted file mode 100644 index 5bb17188..00000000 --- a/src/Nitload.Native/nif-head/nif_intrinsic.std.h +++ /dev/null @@ -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 diff --git a/src/Nitload.Native/nif-head/nif_target.h b/src/Nitload.Native/nif-head/nif_target.h deleted file mode 100644 index 8c623d47..00000000 --- a/src/Nitload.Native/nif-head/nif_target.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef NIF_TARGET -#define NIF_TARGET - -#include "nif_internal.h" -#include - -#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 diff --git a/tools/Rename-NativePrefix.ps1 b/tools/Rename-NativePrefix.ps1 deleted file mode 100644 index 075ddb40..00000000 --- a/tools/Rename-NativePrefix.ps1 +++ /dev/null @@ -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 = '(? $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.' diff --git a/tools/Rename-NifToNfn.ps1 b/tools/Rename-NifToNfn.ps1 new file mode 100644 index 00000000..6c8a7e67 --- /dev/null +++ b/tools/Rename-NifToNfn.ps1 @@ -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.'