per thread context loading is ok, working on global context
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Root Type="DevExpress.CodeRush.Formatting.UI.Options.SpacesOptionsContainer">
|
||||||
|
<Options Language="C#">
|
||||||
|
<Options>
|
||||||
|
<Item Id="{a4f7d021-5762-49a9-956e-040794d03b98}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.BinaryExpressionSpacesOption" />
|
||||||
|
<Item Id="{a957508f-bb2d-484c-b792-7eba9a44f0d4}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.RelationalExpressionSpacesOption" />
|
||||||
|
<Item Id="{12b5408f-751d-4709-908f-d269e40b26ab}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.BitwiseExpressionSpacesOption" />
|
||||||
|
<Item Id="{1be4039d-43ba-4867-b1c6-1453ef76638b}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.LogicalExpressionSpacesOption" />
|
||||||
|
<Item Id="{8e1642cf-2fd0-4bd8-b0f9-a289bf7f889a}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.UnaryExpressionSpacesOption" />
|
||||||
|
<Item Id="{43888577-23ae-4e8c-9103-b0e8b006dffd}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.TernaryExpressionSpacesOption" />
|
||||||
|
<Item Id="{6bd37f4f-1c00-4c06-a83a-2746936e6c8b}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.AssignmentExpressionSpacesOption" />
|
||||||
|
<Item Id="{07d202aa-0580-489b-9883-c3a9d2f750f6}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ExpressionSpacesOption" />
|
||||||
|
<Item Id="{b6cc94db-d940-47bc-9e4c-46e7d397e829}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.StatementSpacesOption" />
|
||||||
|
<Item Id="{20314921-1cb7-4b58-a259-e7200cfd1014}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ArgumentListSpacesOption" />
|
||||||
|
<Item Id="{b031d570-6511-4aa1-8dbb-075d09d9ed72}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ParameterListSpacesOption" />
|
||||||
|
<Item Id="{ca5e97ed-0399-47cd-8bc2-8c2677f273ed}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.InitializerSpacesOption" />
|
||||||
|
<Item Id="{bd007738-8ed3-480b-8618-0c8841c68fb1}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.LambdaExpressionSpacesOption" />
|
||||||
|
<Item Id="{e677064b-b741-49b6-b6ad-b2634258bbed}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.ArrowExpressionSpacesOption" />
|
||||||
|
<Item Id="{1ee97312-d3a8-49b0-b557-e396e73a7898}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.TypeParameterListSpacesOption" />
|
||||||
|
<Item Id="{3d7f395a-bb87-43c2-b483-45b0e5662607}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.TypeArgumentListSpacesOption" />
|
||||||
|
<Item Id="{a8d62687-d898-460d-9322-1088c09f5d9b}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.AttributeListSpacesOption" />
|
||||||
|
<Item Id="{35f5e5b0-a043-4989-8680-da5aa592ece0}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CoalesceExpressionSpacesOption" />
|
||||||
|
<Item Id="{c63dcf47-261a-4a10-9a4d-5ca4957f5061}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.BaseListSpacesOption" />
|
||||||
|
<Item Id="{6c1b5b15-b7c8-4b91-ad28-a52e7389dc9b}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CtorInitSpacesOption" />
|
||||||
|
<Item Id="{10781ebe-9235-4229-a95b-a184827b9815}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CommentSpacesOption" />
|
||||||
|
<Item Id="{30a037ea-69da-4198-98ad-bc7342242e53}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.SwitchExpressionSpacesOption" />
|
||||||
|
<Item Id="{7a5f4d31-4fc4-4c34-ba85-2baad09873b4}" Type="DevExpress.CodeRush.Formatting.UI.Options.Conversion.CollectionExpressionSpacesOption">
|
||||||
|
<WithinBrackets>False</WithinBrackets>
|
||||||
|
</Item>
|
||||||
|
</Options>
|
||||||
|
</Options>
|
||||||
|
</Root>
|
||||||
@@ -1,27 +1,30 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="Platform"
|
// file="Platform.cs"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// obtaining a copy of this software and associated documentation
|
||||||
// in the Software without restriction, including without limitation the rights
|
// files (the “Software”), to deal in the Software without restriction,
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// including without limitation the rights to use, copy, modify, merge,
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
// furnished to do so, subject to the following conditions:
|
// and to permit persons to whom the Software is furnished to do so,
|
||||||
//
|
// subject to the following conditions:
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
//
|
||||||
// copies or substantial portions of the Software.
|
// The above copyright notice and
|
||||||
//
|
// this permission notice shall be included in all copies
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// or substantial portions of the Software.
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
//
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
// SOFTWARE.
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -84,41 +87,31 @@ namespace StgSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void LogError(
|
public static void LogError(Exception ex)
|
||||||
Exception ex
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
DefaultLog.InternalWriteLog(ex.Message, LogType.Error);
|
DefaultLog.InternalWriteLog(ex.Message, LogType.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void LogInfo(
|
public static void LogInfo(string log)
|
||||||
string log
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
DefaultLog.InternalWriteLog(log, LogType.Info);
|
DefaultLog.InternalWriteLog(log, LogType.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void LogWarning(
|
public static void LogWarning(string log)
|
||||||
string log
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
DefaultLog.InternalWriteLog(log, LogType.Warning);
|
DefaultLog.InternalWriteLog(log, LogType.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void LogWarning(
|
public static void LogWarning(Exception notVerySeriesException)
|
||||||
Exception notVerySeriesException
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
DefaultLog.InternalWriteLog(notVerySeriesException.Message, LogType.Warning);
|
DefaultLog.InternalWriteLog(notVerySeriesException.Message, LogType.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Mark(
|
public static void Mark(bool needConsole)
|
||||||
bool needConsole
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
markCount++;
|
markCount++;
|
||||||
if (needConsole) {
|
if (needConsole) {
|
||||||
@@ -126,9 +119,7 @@ namespace StgSharp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Terminate(
|
public static void Terminate(int exitCode)
|
||||||
int exitCode
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
MainTimeProvider.StopProvidingTime();
|
MainTimeProvider.StopProvidingTime();
|
||||||
GraphicFramework.glfwTerminate();
|
GraphicFramework.glfwTerminate();
|
||||||
@@ -141,8 +132,7 @@ namespace StgSharp
|
|||||||
bool isConsole,
|
bool isConsole,
|
||||||
[CallerFilePath] string filePath = "",
|
[CallerFilePath] string filePath = "",
|
||||||
[CallerMemberName] string callerName = "",
|
[CallerMemberName] string callerName = "",
|
||||||
[CallerLineNumber] int lineNumber = 0
|
[CallerLineNumber] int lineNumber = 0)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
Type t = target.GetType();
|
Type t = target.GetType();
|
||||||
string log = $"Tracked object: {nameof(target)}\t\tType:{t.Name}\n";
|
string log = $"Tracked object: {nameof(target)}\t\tType:{t.Name}\n";
|
||||||
@@ -173,17 +163,12 @@ namespace StgSharp
|
|||||||
/// The severity of current message.
|
/// The severity of current message.
|
||||||
/// </param>
|
/// </param>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void WriteLog(
|
public static void WriteLog(string message, LogType logType)
|
||||||
string message,
|
|
||||||
LogType logType
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
DefaultLog.InternalWriteLog(message, logType);
|
DefaultLog.InternalWriteLog(message, logType);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static TDele ConvertAPI<TDele>(
|
internal static TDele ConvertAPI<TDele>(IntPtr funcPtr)
|
||||||
IntPtr funcPtr
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (funcPtr == IntPtr.Zero) {
|
if (funcPtr == IntPtr.Zero) {
|
||||||
throw new InvalidCastException(
|
throw new InvalidCastException(
|
||||||
@@ -199,10 +184,7 @@ namespace StgSharp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Delegate ConvertAPI(
|
internal static Delegate ConvertAPI(IntPtr funcPtr, Type T)
|
||||||
IntPtr funcPtr,
|
|
||||||
Type T
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (funcPtr == IntPtr.Zero) {
|
if (funcPtr == IntPtr.Zero) {
|
||||||
throw new InvalidCastException(
|
throw new InvalidCastException(
|
||||||
@@ -238,7 +220,6 @@ namespace StgSharp
|
|||||||
Dialogue.CreateDialogueProcessIfNotExist();
|
Dialogue.CreateDialogueProcessIfNotExist();
|
||||||
}
|
}
|
||||||
/**/
|
/**/
|
||||||
NativeIntrinsic.InitIntrinsicContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class Initializer : IStaticModule
|
internal class Initializer : IStaticModule
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="intrinsicContextProvider"
|
// file="intrinsicContextProvider.cs"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// obtaining a copy of this software and associated documentation
|
||||||
// in the Software without restriction, including without limitation the rights
|
// files (the “Software”), to deal in the Software without restriction,
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// including without limitation the rights to use, copy, modify, merge,
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
// furnished to do so, subject to the following conditions:
|
// and to permit persons to whom the Software is furnished to do so,
|
||||||
//
|
// subject to the following conditions:
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
//
|
||||||
// copies or substantial portions of the Software.
|
// The above copyright notice and
|
||||||
//
|
// this permission notice shall be included in all copies
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// or substantial portions of the Software.
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
//
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
// SOFTWARE.
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -47,6 +50,7 @@ namespace StgSharp.Internal
|
|||||||
get => _intrinsicContext;
|
get => _intrinsicContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
internal static void InitIntrinsicContext()
|
internal static void InitIntrinsicContext()
|
||||||
{
|
{
|
||||||
ulong statCode = 0;
|
ulong statCode = 0;
|
||||||
@@ -71,10 +75,8 @@ namespace StgSharp.Internal
|
|||||||
}
|
}
|
||||||
|
|
||||||
[LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")]
|
[LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")]
|
||||||
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
|
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||||
private static partial ulong LoadIntrinsicFunction(
|
private static partial void LoadIntrinsicFunction(IntrinsicContext* context, ulong id);
|
||||||
IntrinsicContext* context
|
/**/
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel"
|
// file="MatrixParallel"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -27,10 +27,14 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Collections;
|
using StgSharp.Collections;
|
||||||
using StgSharp.HighPerformance.Memory;
|
using StgSharp.HighPerformance.Memory;
|
||||||
|
using StgSharp.Internal;
|
||||||
using StgSharp.Internal.Intrinsic;
|
using StgSharp.Internal.Intrinsic;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -43,6 +47,8 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
private static CapacityFixedStack<MatrixParallelThread> _threads;
|
private static CapacityFixedStack<MatrixParallelThread> _threads;
|
||||||
|
|
||||||
|
private static ConcurrentDictionary<SIMDID, nint> contextMap;
|
||||||
|
|
||||||
private static SlabAllocator<IntrinsicContext> contextAllocator;
|
private static SlabAllocator<IntrinsicContext> contextAllocator;
|
||||||
|
|
||||||
public static bool IsParallelSupported { get; } = Environment.ProcessorCount > 6;
|
public static bool IsParallelSupported { get; } = Environment.ProcessorCount > 6;
|
||||||
@@ -51,6 +57,22 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
private static bool IsInitialized { get; set; } = false;
|
private static bool IsInitialized { get; set; } = false;
|
||||||
|
|
||||||
|
internal static unsafe IntrinsicContext* GetContext(SIMDID simd)
|
||||||
|
{
|
||||||
|
if (!IsParallelSupported) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (contextMap.TryGetValue(simd, out nint handle))
|
||||||
|
{
|
||||||
|
return (IntrinsicContext*)handle;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
IntrinsicContext* context = (IntrinsicContext*)contextAllocator.Allocate();
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal static void Init()
|
internal static void Init()
|
||||||
{
|
{
|
||||||
if (IsInitialized) {
|
if (IsInitialized) {
|
||||||
@@ -63,16 +85,32 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
MatrixParallelFactory.Init();
|
MatrixParallelFactory.Init();
|
||||||
contextAllocator = SlabAllocator<IntrinsicContext>.Create(4, SlabBufferLayout.Chunked, false);
|
contextAllocator = SlabAllocator<IntrinsicContext>.Create(4, SlabBufferLayout.Chunked, false);
|
||||||
int count = Environment.ProcessorCount - 4;
|
contextMap = [];
|
||||||
|
int count = Environment.ProcessorCount;
|
||||||
_threads = new(count);
|
_threads = new(count);
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
MatrixParallelThread thread = new MatrixParallelThread(i);
|
MatrixParallelThread thread = new MatrixParallelThread(i);
|
||||||
_threads.Push(thread);
|
_threads.Push(thread);
|
||||||
}
|
}
|
||||||
|
if (contextMap.Keys.Count == 1)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
MatrixParallelThread thread = _threads.Pop();
|
||||||
|
thread.Dispose();
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
// TODO 排序并丢弃四个能力最弱线程
|
||||||
|
}
|
||||||
_awaitingLeaderHandle = new AwaitingQueue();
|
_awaitingLeaderHandle = new AwaitingQueue();
|
||||||
IsInitialized = true;
|
IsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")]
|
||||||
|
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||||
|
private static unsafe partial void LoadIntrinsicFunction(IntrinsicContext* context, ulong id);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallelThread"
|
// file="MatrixParallelThread"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -27,18 +27,20 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
using StgSharp.Internal;
|
using StgSharp.Internal;
|
||||||
using StgSharp.Internal.Intrinsic;
|
using StgSharp.Internal.Intrinsic;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StgSharp.Mathematics.Numeric
|
namespace StgSharp.Mathematics.Numeric
|
||||||
{
|
{
|
||||||
|
internal enum MatrixThreadState : int
|
||||||
|
{
|
||||||
|
|
||||||
|
Ready = 0,
|
||||||
|
Running = 1,
|
||||||
|
Idle = 2,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public unsafe partial class MatrixParallelThread : IDisposable
|
public unsafe partial class MatrixParallelThread : IDisposable
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -47,9 +49,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
private readonly ManualResetEventSlim _resetEvent;
|
private readonly ManualResetEventSlim _resetEvent;
|
||||||
private readonly Thread _managedThread;
|
private readonly Thread _managedThread;
|
||||||
|
|
||||||
internal MatrixParallelThread(
|
internal MatrixParallelThread(int poolId)
|
||||||
int poolId
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
_resetEvent = new ManualResetEventSlim(false);
|
_resetEvent = new ManualResetEventSlim(false);
|
||||||
_managedThread = new Thread(MatrixParallelWorkLoad);
|
_managedThread = new Thread(MatrixParallelWorkLoad);
|
||||||
@@ -65,9 +65,11 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
internal IntrinsicContext* Intrinsic { get; set; }
|
internal IntrinsicContext* Intrinsic { get; set; }
|
||||||
|
|
||||||
|
internal bool IsSingle { get; set; }
|
||||||
|
|
||||||
internal MatrixParallelWrap BindedWrap { get; set; }
|
internal MatrixParallelWrap BindedWrap { get; set; }
|
||||||
|
|
||||||
internal RoleType Role { get; set; }
|
internal MatrixThreadState state { get; set; }
|
||||||
|
|
||||||
internal SIMDID Simd { get; set; }
|
internal SIMDID Simd { get; set; }
|
||||||
|
|
||||||
@@ -78,9 +80,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static unsafe void ExecuteTaskPackage(
|
public static unsafe void ExecuteTaskPackage(MatrixParallelQueue taskQueue)
|
||||||
MatrixParallelQueue taskQueue
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
MatrixParallelTaskPackage* p = taskQueue.Package;
|
MatrixParallelTaskPackage* p = taskQueue.Package;
|
||||||
switch (p->ComputeMode.OperationStyle)
|
switch (p->ComputeMode.OperationStyle)
|
||||||
@@ -118,42 +118,22 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void Restart()
|
public void Restart()
|
||||||
{
|
{
|
||||||
if (Role == RoleType.Leader)
|
_resetEvent.Set();
|
||||||
{
|
|
||||||
LeaderEvent?.Set();
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
_resetEvent.Set();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void MatrixParallelLeader()
|
[DllImport(
|
||||||
{
|
dllName: Native.LibName,
|
||||||
Thread current = Thread.CurrentThread;
|
EntryPoint = "sn_get_simd_level_local",
|
||||||
current.Priority = ThreadPriority.Highest;
|
CallingConvention = CallingConvention.Cdecl)]
|
||||||
LeaderEvent?.Wait();
|
internal static extern ulong GetSimdId();
|
||||||
LeaderEvent?.Reset();
|
|
||||||
|
|
||||||
// Console.WriteLine("Leader is computing");
|
|
||||||
BindedWrap.ReportThreadAccomplished();
|
|
||||||
|
|
||||||
// Console.WriteLine("leader's computing is done");
|
|
||||||
Role = RoleType.Worker;
|
|
||||||
LeaderEvent = null;
|
|
||||||
current.Priority = BindedWrap.AfterWork;
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport(
|
[DllImport(
|
||||||
dllName:Native.LibName,
|
dllName:Native.LibName,
|
||||||
EntryPoint = "sn_set_thread_affinity",
|
EntryPoint = "sn_set_thread_affinity",
|
||||||
CallingConvention = CallingConvention.Cdecl)]
|
CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern void SetThreadAffinity(
|
internal static extern void SetThreadAffinity(int coreId);
|
||||||
int coreId
|
|
||||||
);
|
|
||||||
|
|
||||||
protected virtual void Dispose(
|
protected virtual void Dispose(bool disposing)
|
||||||
bool disposing
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (!disposedValue)
|
if (!disposedValue)
|
||||||
{
|
{
|
||||||
@@ -162,7 +142,6 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
_resetEvent.Dispose();
|
_resetEvent.Dispose();
|
||||||
_managedThread.Join();
|
_managedThread.Join();
|
||||||
}
|
}
|
||||||
|
|
||||||
disposedValue = true;
|
disposedValue = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,8 +150,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
{
|
{
|
||||||
// Bind OS-thread affinity once when the worker starts running
|
// Bind OS-thread affinity once when the worker starts running
|
||||||
SetThreadAffinity(PoolId);
|
SetThreadAffinity(PoolId);
|
||||||
Thread.Sleep(0);
|
Thread.Sleep(1);
|
||||||
|
SIMDID feature = new();
|
||||||
|
feature.Mask = GetSimdId();
|
||||||
|
_context = (nint*)MatrixParallel.GetContext(feature);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// Thread self = Thread.CurrentThread;
|
// Thread self = Thread.CurrentThread;
|
||||||
@@ -180,35 +161,17 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
_resetEvent.Reset();
|
_resetEvent.Reset();
|
||||||
AfterWork = BindedWrap.AfterWork;
|
AfterWork = BindedWrap.AfterWork;
|
||||||
_managedThread.Priority = ThreadPriority.Highest;
|
_managedThread.Priority = ThreadPriority.Highest;
|
||||||
switch (Role)
|
if (IsSingle)
|
||||||
{
|
{
|
||||||
case RoleType.Worker://worker
|
// TODO 将外部线程绑定到当前线程上,并执行任务包
|
||||||
// _ = Interlocked.Decrement(ref RemainThreadCount);
|
} else
|
||||||
// Console.WriteLine($"worker {Environment.CurrentManagedThreadId} start");
|
{
|
||||||
ExecuteTaskPackage(BindedWrap.TaskQueue);
|
ExecuteTaskPackage(BindedWrap.TaskQueue);
|
||||||
BindedWrap.ReportThreadAccomplished();
|
BindedWrap.ReportThreadAccomplished();
|
||||||
|
|
||||||
// Console.WriteLine($"worker {Environment.CurrentManagedThreadId} end");
|
|
||||||
break;
|
|
||||||
case RoleType.SingleExternal:
|
|
||||||
|
|
||||||
// TODO 将外部线程绑定到当前线程上,并执行任务包
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
_managedThread.Priority = AfterWork;
|
_managedThread.Priority = AfterWork;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal enum RoleType : int
|
|
||||||
{
|
|
||||||
|
|
||||||
Worker = 0,
|
|
||||||
Leader = 1,
|
|
||||||
SingleExternal = 2,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallelWrap"
|
// file="MatrixParallelWrap.cs"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// obtaining a copy of this software and associated documentation
|
||||||
// in the Software without restriction, including without limitation the rights
|
// files (the “Software”), to deal in the Software without restriction,
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// including without limitation the rights to use, copy, modify, merge,
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
// furnished to do so, subject to the following conditions:
|
// and to permit persons to whom the Software is furnished to do so,
|
||||||
//
|
// subject to the following conditions:
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
//
|
||||||
// copies or substantial portions of the Software.
|
// The above copyright notice and
|
||||||
//
|
// this permission notice shall be included in all copies
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// or substantial portions of the Software.
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
//
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
// SOFTWARE.
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -52,12 +55,8 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
private MatrixParallelThread[] _threads;
|
private MatrixParallelThread[] _threads;
|
||||||
private bool _disposed = false;
|
private bool _disposed = false;
|
||||||
private int _count;
|
private int _count;
|
||||||
private ManualResetEventSlim _leaderEvent = new ManualResetEventSlim(false);
|
|
||||||
public ThreadPriority AfterWork { get; private set; }
|
|
||||||
|
|
||||||
internal MatrixParallelWrap(
|
internal MatrixParallelWrap(MatrixParallelThread[] threadArray)
|
||||||
MatrixParallelThread[] threadArray
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
_threads = threadArray;
|
_threads = threadArray;
|
||||||
IsMultithread = threadArray.Length > 1;
|
IsMultithread = threadArray.Length > 1;
|
||||||
@@ -77,6 +76,8 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ThreadPriority AfterWork { get; private set; }
|
||||||
|
|
||||||
private bool IsMultithread { get; init; }
|
private bool IsMultithread { get; init; }
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@@ -89,22 +90,14 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public MatrixParallelThread GetLeader()
|
public void LaunchParallel(SleepMode afterWork)
|
||||||
{
|
|
||||||
MatrixParallelThread leader = Threads[1];
|
|
||||||
leader.Role = MatrixParallelThread.RoleType.Leader;
|
|
||||||
leader.LeaderEvent = _leaderEvent;
|
|
||||||
return leader;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void LaunchParallel(
|
|
||||||
SleepMode afterWork
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
AfterWork = (ThreadPriority)afterWork;
|
AfterWork = (ThreadPriority)afterWork;
|
||||||
MatrixParallelThread leader = GetLeader();
|
foreach (MatrixParallelThread thread in _threads)
|
||||||
leader.MatrixParallelLeader();
|
{
|
||||||
|
thread.AfterWork = AfterWork;
|
||||||
|
thread.BindedWrap = this;
|
||||||
|
}
|
||||||
WaitAllWraps();
|
WaitAllWraps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ SN_API GLFWglproc SN_DECL loadGlfuncDefault(char *procName);
|
|||||||
SN_API void SN_DECL unloadImageData(Image *out);
|
SN_API void SN_DECL unloadImageData(Image *out);
|
||||||
SN_API char *SN_DECL readLog(void);
|
SN_API char *SN_DECL readLog(void);
|
||||||
SN_API void SN_DECL load_glfw_functions(GLFWFunctionTable *table);
|
SN_API void SN_DECL load_glfw_functions(GLFWFunctionTable *table);
|
||||||
SN_API SIMDID SN_DECL load_intrinsic_function(void *intrinsic_context, uint64_t id);
|
SN_API void SN_DECL load_intrinsic_function(void *intrinsic_context, uint64_t id);
|
||||||
SN_API SIMDID SN_DECL sn_get_simd_level_global();
|
SN_API SIMDID SN_DECL sn_get_simd_level_global();
|
||||||
/* Per-core variant: always re-executes CPUID, never caches.
|
/* Per-core variant: always re-executes CPUID, never caches.
|
||||||
* Must be called on the target core (after affinity is set). */
|
* Must be called on the target core (after affinity is set). */
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ PRIVATE void load_intrinsic_avx(sn_intrinsic *context, SIMDID id);
|
|||||||
PRIVATE void load_intrinsic_512_dual(sn_intrinsic *context, SIMDID id);
|
PRIVATE void load_intrinsic_512_dual(sn_intrinsic *context, SIMDID id);
|
||||||
PRIVATE void load_intrinsic_512(sn_intrinsic *context, SIMDID id);
|
PRIVATE void load_intrinsic_512(sn_intrinsic *context, SIMDID id);
|
||||||
|
|
||||||
SN_API SIMDID load_intrinsic_function(void *intrinsic_context, uint64_t id)
|
SN_API void load_intrinsic_function(void *intrinsic_context, uint64_t id)
|
||||||
{
|
{
|
||||||
sn_null_assert(intrinsic_context);
|
sn_null_assert(intrinsic_context);
|
||||||
|
|
||||||
@@ -45,7 +45,6 @@ SN_API SIMDID load_intrinsic_function(void *intrinsic_context, uint64_t id)
|
|||||||
load_intrinsic_512(context, simdid);
|
load_intrinsic_512(context, simdid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return simdid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_intrinsic_sse(sn_intrinsic *context, SIMDID id)
|
void load_intrinsic_sse(sn_intrinsic *context, SIMDID id)
|
||||||
|
|||||||
@@ -20,33 +20,34 @@
|
|||||||
* [63..56] uArchHi make_byte[7]
|
* [63..56] uArchHi make_byte[7]
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
#define FIELD_MAIN(id) ((unsigned char)(id).make_byte[1])
|
#define FIELD_MAIN(id) ((unsigned char)(id).make_byte[1])
|
||||||
#define FIELD_AVX512(id) ((uint16_t)((unsigned char)(id).make_byte[2] | \
|
#define FIELD_AVX512(id) \
|
||||||
((unsigned char)(id).make_byte[3] << 8)))
|
((uint16_t)((unsigned char)(id).make_byte[2] | ((unsigned char)(id).make_byte[3] << 8)))
|
||||||
#define FIELD_AMX(id) ((unsigned char)(id).make_byte[4])
|
#define FIELD_AMX(id) ((unsigned char)(id).make_byte[4])
|
||||||
#define FIELD_AVX(id) ((unsigned char)(id).make_byte[5])
|
#define FIELD_AVX(id) ((unsigned char)(id).make_byte[5])
|
||||||
#define FIELD_AVX10(id) ((unsigned char)(id).make_byte[6])
|
#define FIELD_AVX10(id) ((unsigned char)(id).make_byte[6])
|
||||||
#define FIELD_UARCH(id) ((unsigned char)(id).make_byte[7])
|
#define FIELD_UARCH(id) ((unsigned char)(id).make_byte[7])
|
||||||
|
|
||||||
/* Portable popcount for a 16-bit value. */
|
/* Portable popcount for a 16-bit value. */
|
||||||
static int popcount16(uint16_t v)
|
static int popcount16(uint16_t v)
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while (v) { v &= v - 1; c++; }
|
while (v) {
|
||||||
|
v &= v - 1;
|
||||||
|
c++;
|
||||||
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Map AVX512_IMPL 2-bit field to a strength ordinal for tie-breaking.
|
/* Map AVX512_IMPL 2-bit field to a strength ordinal for tie-breaking.
|
||||||
* DUAL(1) => 0 (weakest), UNKNOWN(0) => 1, NATIVE(2) => 2 (strongest) */
|
* Index = impl value (0=UNKNOWN, 1=DUAL, 2=NATIVE, 3=reserved).
|
||||||
|
* Strength: DUAL(0) < UNKNOWN(1) < NATIVE(2). */
|
||||||
|
static const int impl_strength_table[4] = { 1, 0, 2, 1 };
|
||||||
|
|
||||||
static int impl_strength(uint16_t avx512)
|
static int impl_strength(uint16_t avx512)
|
||||||
{
|
{
|
||||||
unsigned impl = (avx512 >> SIMDID_AVX512_IMPL_SHIFT) & 0x3u;
|
unsigned impl = (avx512 >> SIMDID_AVX512_IMPL_SHIFT) & 0x3u;
|
||||||
switch (impl) {
|
return impl_strength_table[impl];
|
||||||
case 1: return 0; /* DUAL — glue / downclock risk */
|
|
||||||
case 0: return 1; /* UNKNOWN — conservatively mid */
|
|
||||||
case 2: return 2; /* NATIVE — full-width ALU */
|
|
||||||
default: return 1; /* reserved, treat as unknown */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
@@ -85,11 +86,10 @@ SN_API SIMDID SN_DECL sn_get_unite_simd(SIMDID left, SIMDID right)
|
|||||||
/* Clear the IMPL field, then set the weaker one */
|
/* Clear the IMPL field, then set the weaker one */
|
||||||
int ls = impl_strength(l512);
|
int ls = impl_strength(l512);
|
||||||
int rs = impl_strength(r512);
|
int rs = impl_strength(r512);
|
||||||
unsigned weak_impl = (ls <= rs)
|
int s = (ls <= rs) ? l512 : r512; /* pick the one with weaker strength ordinal */
|
||||||
? ((l512 >> SIMDID_AVX512_IMPL_SHIFT) & 0x3u)
|
unsigned weak_impl = (s >> SIMDID_AVX512_IMPL_SHIFT) & 0x3u;
|
||||||
: ((r512 >> SIMDID_AVX512_IMPL_SHIFT) & 0x3u);
|
merged &= ~(uint16_t)SIMDID_AVX512_IMPL_MASK;
|
||||||
merged = (merged & ~(uint16_t)SIMDID_AVX512_IMPL_MASK)
|
merged |= (uint16_t)(weak_impl << SIMDID_AVX512_IMPL_SHIFT);
|
||||||
| (uint16_t)(weak_impl << SIMDID_AVX512_IMPL_SHIFT);
|
|
||||||
out.make_byte[2] = (char)(merged & 0xFF);
|
out.make_byte[2] = (char)(merged & 0xFF);
|
||||||
out.make_byte[3] = (char)((merged >> 8) & 0xFF);
|
out.make_byte[3] = (char)((merged >> 8) & 0xFF);
|
||||||
|
|
||||||
@@ -171,10 +171,9 @@ SN_API int SN_DECL sn_compare_simd(SIMDID left, SIMDID right)
|
|||||||
if (lb != rb)
|
if (lb != rb)
|
||||||
return lb > rb ? 1 : -1;
|
return lb > rb ? 1 : -1;
|
||||||
|
|
||||||
/* 4. Extension popcount (mask out BASE + IMPL + reserved low nibble) */
|
// 4. Extension popcount (mask out BASE + IMPL + reserved low nibble)
|
||||||
uint16_t ext_mask = (uint16_t)~(SIMDID_AVX512_BASE
|
int drop = ~(SIMDID_AVX512_BASE | SIMDID_AVX512_IMPL_MASK | 0x000Fu);
|
||||||
| SIMDID_AVX512_IMPL_MASK
|
uint16_t ext_mask = drop & (l512 | r512); /* only consider bits set in either */
|
||||||
| 0x000Fu);
|
|
||||||
int lp = popcount16(l512 & ext_mask);
|
int lp = popcount16(l512 & ext_mask);
|
||||||
int rp = popcount16(r512 & ext_mask);
|
int rp = popcount16(r512 & ext_mask);
|
||||||
if (lp != rp)
|
if (lp != rp)
|
||||||
@@ -196,4 +195,4 @@ SN_API int SN_DECL sn_compare_simd(SIMDID left, SIMDID right)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user