//----------------------------------------------------------------------- // ----------------------------------------------------------------------- // file="IntrinsicContext" // Project: StgSharp // AuthorGroup: Nitload // Copyright (c) Nitload. All rights reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 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. // // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace StgSharp.Mathematics.Internal { [InlineArray(10)] internal unsafe struct MatrixIntrinsic { private nint handle; //f32_panel_mul public readonly nint this[ MatrixIntrinsicHandle handle ] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => this[(int)handle]; } } internal enum MatrixIntrinsicHandle : int { BufferAdd = 0, BufferFill = 1, BufferScalarMul = 2, BufferSub = 3, BufferTranspose = 4, ClearPanel = 5, KerFma = 6, TileFma = 7, Pivot = 8, } [StructLayout(LayoutKind.Explicit, Size = 4)] public struct MatrixElementType { public const int IntrinsicCount = 0xa; public static readonly MatrixElementType F32 = new(0x00010004); public static readonly MatrixElementType F64 = new(0x00020008); public static readonly MatrixElementType I08 = new(0x00030001); public static readonly MatrixElementType I16 = new(0x00040002); public static readonly MatrixElementType I32 = new(0x00050004); public static readonly MatrixElementType I64 = new(0x00060008); public static readonly MatrixElementType U08 = new(0x00070001); public static readonly MatrixElementType U16 = new(0x00080002); public static readonly MatrixElementType U32 = new(0x00090004); public static readonly MatrixElementType U64 = new(0x000a0008); [FieldOffset(0)] internal readonly int Mask; [FieldOffset(2)] public readonly ushort IntrinsicNode; [FieldOffset(0)] public readonly ushort Size; private MatrixElementType( int mask ) { Unsafe.SkipInit(out this); Unsafe.SkipInit(out Size); Unsafe.SkipInit(out IntrinsicNode); this.Mask = mask; } } [InlineArray(MatrixElementType.IntrinsicCount)] internal unsafe struct MatrixIntrinsicArray { private MatrixIntrinsic e0; } [StructLayout(LayoutKind.Sequential)] internal unsafe struct IntrinsicContext { public delegate* unmanaged[Cdecl] city_hash_simplify; // city_hash_simplify public delegate* unmanaged[Cdecl] factorial_simd; // factorial_simd public delegate* unmanaged[Cdecl] index_pair; // index_pair public delegate* unmanaged[Cdecl] vec_f32_normalize_3; // f32_normalize_3 public MatrixIntrinsicArray mat; // mat[4] in native order public IntrinsicContext() { Unsafe.SkipInit(out this); } } }