daily update on 20241002 by nitload youmu, intrinsic function rebuild, syntax style arrange

This commit is contained in:
Nitload
2024-10-03 04:03:06 +08:00
parent 0979123ac0
commit 6e2f93b053
265 changed files with 26732 additions and 19058 deletions
@@ -52,6 +52,5 @@ namespace StgSharp
return ret;
}
}//------------------ end of class ---------------------
}
+1 -3
View File
@@ -96,8 +96,6 @@ namespace StgSharp
}
""";
#endregion
#endregion
}
}
@@ -0,0 +1,90 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ColumnSet2.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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 StgSharp.Data.Intrinsic;
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Explicit, Size = 12 * sizeof( float ), Pack = 16 )]
internal struct ColumnSet2 : IEquatable<ColumnSet2>
{
[FieldOffset( 0 * sizeof( float ) )] internal float m00;
[FieldOffset( 4 * sizeof( float ) )] internal float m01;
[FieldOffset( 1 * sizeof( float ) )] internal float m10;
[FieldOffset( 5 * sizeof( float ) )] internal float m11;
[FieldOffset( 2 * sizeof( float ) )] internal float m20;
[FieldOffset( 6 * sizeof( float ) )] internal float m21;
[FieldOffset( 3 * sizeof( float ) )] internal float m30;
[FieldOffset( 7 * sizeof( float ) )] internal float m31;
[FieldOffset( 0 )] internal Vector4 colum0;
[FieldOffset( 4 * sizeof( float ) )] internal Vector4 colum1;
internal ColumnSet2( Vector4 c0, Vector4 c1 )
{
colum0 = c0;
colum1 = c1;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public override bool Equals( object? obj )
{
return ( obj is ColumnSet2 mat ) && Equals( mat );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public bool Equals( ColumnSet2 other )
{
return colum0.Equals( other.colum0 ) && colum1.Equals(
other.colum1 );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator !=( ColumnSet2 left, ColumnSet2 right )
{
return !( left == right );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator ==( ColumnSet2 left, ColumnSet2 right )
{
return left.Equals( right );
}
}
}
@@ -0,0 +1,87 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ColumnSet3.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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 StgSharp.Data.Intrinsic;
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Explicit, Size = 12 * sizeof( float ), Pack = 16 )]
internal struct ColumnSet3 : IEquatable<ColumnSet3>, IMat
{
[FieldOffset( 0 * sizeof( float ) )] internal float m00;
[FieldOffset( 4 * sizeof( float ) )] internal float m01;
[FieldOffset( 8 * sizeof( float ) )] internal float m02;
[FieldOffset( 1 * sizeof( float ) )] internal float m10;
[FieldOffset( 5 * sizeof( float ) )] internal float m11;
[FieldOffset( 9 * sizeof( float ) )] internal float m12;
[FieldOffset( 2 * sizeof( float ) )] internal float m20;
[FieldOffset( 6 * sizeof( float ) )] internal float m21;
[FieldOffset( 10 * sizeof( float ) )] internal float m22;
[FieldOffset( 3 * sizeof( float ) )] internal float m30;
[FieldOffset( 7 * sizeof( float ) )] internal float m31;
[FieldOffset( 11 * sizeof( float ) )] internal float m32;
[FieldOffset( 0 )] internal Vector4 colum0;
[FieldOffset( 4 * sizeof( float ) )] internal Vector4 colum1;
[FieldOffset( 8 * sizeof( float ) )] internal Vector4 colum2;
public override bool Equals( object? obj )
{
return ( obj is ColumnSet3 mat ) && Equals( mat );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public bool Equals( ColumnSet3 other )
{
return colum0.Equals( other.colum0 ) && colum1.Equals(
other.colum1 ) && colum2.Equals( other.colum2 );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator !=( ColumnSet3 left, ColumnSet3 right )
{
return !( left == right );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator ==( ColumnSet3 left, ColumnSet3 right )
{
return left.Equals( right );
}
}
}
@@ -0,0 +1,110 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ColumnSet4.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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 StgSharp;
using StgSharp.Data.Intrinsic;
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Explicit, Size = 16 * sizeof( float ) )]
internal struct ColumnSet4 : IEquatable<ColumnSet4>, IMat
{
[FieldOffset( 0 )] internal Vector4 colum0;
[FieldOffset( 16 )] internal Vector4 colum1;
[FieldOffset( 32 )] internal Vector4 colum2;
[FieldOffset( 48 )] internal Vector4 colum3;
[FieldOffset( 0 )] public float m00;
[FieldOffset( 16 )] public float m01;
[FieldOffset( 32 )] public float m02;
[FieldOffset( 48 )] public float m03;
[FieldOffset( 4 )] public float m10;
[FieldOffset( 20 )] public float m11;
[FieldOffset( 36 )] public float m12;
[FieldOffset( 52 )] public float m13;
[FieldOffset( 8 )] public float m20;
[FieldOffset( 24 )] public float m21;
[FieldOffset( 40 )] public float m22;
[FieldOffset( 56 )] public float m23;
[FieldOffset( 12 )] public float m30;
[FieldOffset( 28 )] public float m31;
[FieldOffset( 44 )] public float m32;
[FieldOffset( 60 )] public float m33;
[MethodImpl( MethodImplOptions.AggressiveInlining )]
internal ColumnSet4(
Vector4 colum0,
Vector4 colum1,
Vector4 colum2,
Vector4 colum3 )
{
this.colum0 = colum0;
this.colum1 = colum1;
this.colum2 = colum2;
this.colum3 = colum3;
}
public override bool Equals( object? obj )
{
return ( obj is ColumnSet4 mat ) && Equals( mat );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public bool Equals( ColumnSet4 other )
{
return colum0.Equals( other.colum0 ) && colum1.Equals(
other.colum1 ) && colum2.Equals( other.colum2 ) && colum3.Equals(
other.colum3 );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator !=( ColumnSet4 left, ColumnSet4 right )
{
return !( left == right );
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator ==( ColumnSet4 left, ColumnSet4 right )
{
return left.Equals( right );
}
}
}
@@ -0,0 +1,61 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IRegisterType.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Data.Intrinsic
{
public interface IRegisterType
{
public T Read<T>( int index )
where T: struct
#if NET8_0_OR_GREATER
, INumber
#else
, IConvertible
#endif
;
public void Write<T>( int index, T value )
where T: struct
#if NET8_0_OR_GREATER
, INumber
#else
, IConvertible
#endif
;
}
}
@@ -0,0 +1,59 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IntrinsicContext.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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 StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Sequential )]
internal unsafe struct IntrinsicContext
{
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet3*, void> transpose23;
public delegate* unmanaged[Cdecl]<ColumnSet2*, ColumnSet4*, void> transpose24;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet2*, void> transpose32;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet3*, void> transpose33;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet4*, void> transpose34;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet2*, void> transpose42;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet3*, void> transpose43;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet4*, void> transpose44;
public delegate* unmanaged[Cdecl]<ColumnSet3*, ColumnSet3*, float> det_mat_3;
public delegate* unmanaged[Cdecl]<ColumnSet4*, ColumnSet4*, float> det_mat_4;
public delegate* unmanaged[Cdecl]<M128*, M128*, void> normalize_v3;
public delegate* unmanaged[Cdecl]<char*, int, int> string_quickHash;
}
}
+193
View File
@@ -0,0 +1,193 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="M128.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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 StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if NET5_0_OR_GREATER
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
#endif
using System.Text;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Explicit, Pack = 16 )]
public unsafe struct M128 : IRegisterType
{
[FieldOffset( 0 )] internal Vector4 vec;
internal M128( Vector4 v )
{
vec = v;
}
public override bool Equals( [NotNullWhen( true )] object obj )
{
if( obj is not M128 other ) {
return false;
}
return this == other;
}
public override int GetHashCode()
{
return vec.GetHashCode();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public T Read<T>( int index )
where T: struct
#if NET8_0_OR_GREATER
, INumber
#else
, IConvertible
#endif
{
fixed( Vector4* p = &vec ) {
#pragma warning disable CS8500
return *( ( T* )p + index );
#pragma warning restore CS8500
}
}
public override string ToString()
{
return string.Empty;
}
public string ToString( int sample )
{
string str = string.Empty;
for( int i = 15; i >= 0; i-- ) {
str += $"{Convert.ToString(Read<byte>(i), sample)} ";
}
return str;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public void Write<T>( int index, T value )
where T: struct
#if NET8_0_OR_GREATER
, INumber
#else
, IConvertible
#endif
{
fixed( Vector4* p = &vec ) {
#pragma warning disable CS8500
*( ( T* )p + index ) = value;
#pragma warning restore CS8500
}
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator !=( M128 left, M128 right )
{
return left.vec != right.vec;
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static bool operator ==( M128 left, M128 right )
{
return left.vec == right.vec;
}
#if NET5_0_OR_GREATER
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<byte>( M128 m )
{
return m.vec.AsVector128().As<float, byte>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<sbyte>( M128 m )
{
return m.vec.AsVector128().As<float, sbyte>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<short>( M128 m )
{
return m.vec.AsVector128().As<float, short>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<ushort>( M128 m )
{
return m.vec.AsVector128().As<float, ushort>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<int>( M128 m )
{
return m.vec.AsVector128().As<float, int>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<uint>( M128 m )
{
return m.vec.AsVector128().As<float, uint>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<long>( M128 m )
{
return m.vec.AsVector128().As<float, long>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<ulong>( M128 m )
{
return m.vec.AsVector128().As<float, ulong>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<float>( M128 m )
{
return m.vec.AsVector128().As<float, float>();
}
[MethodImpl( MethodImplOptions.AggressiveInlining )]
public static explicit operator Vector128<double>( M128 m )
{
return m.vec.AsVector128().As<float, double>();
}
#endif
}
}
+63
View File
@@ -0,0 +1,63 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="M256.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Data.Intrinsic
{
[StructLayout( LayoutKind.Sequential )]
public unsafe struct M256 : IRegisterType
{
private M128 v0;
private M128 v1;
T IRegisterType.Read<T>( int index )
{
fixed( M128* mptr = &v0 ) {
return *( ( T* )mptr + index );
}
}
void IRegisterType.Write<T>( int index, T value )
{
fixed( M128* mptr = &v0 ) {
*( ( T* )mptr + index ) = value;
}
}
}
}
@@ -0,0 +1,57 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="intrinsicContextProvider.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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 StgSharp.Data.Intrinsic;
using System;
using System.Runtime.InteropServices;
namespace StgSharp
{
internal static unsafe partial class InternalIO
{
private static readonly IntrinsicContext _intrinsicContext = new IntrinsicContext(
);
internal static IntrinsicContext Intrinsic
{
get => _intrinsicContext;
}
[DllImport(
InternalIO.SSC_libName,
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "load_intrinsic_function" )]
private static extern void LoadIntrinsicFunction(
IntrinsicContext* context );
}
}
+70
View File
@@ -0,0 +1,70 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Lable.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. 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 StgSharp;
using System;
using System.Runtime.CompilerServices;
namespace StgSharp.Data
{
public class DataLabel
{
private readonly string _name;
public DataLabel( string lableName )
{
_name = lableName;
}
public string Name
{
get => _name;
}
public override unsafe int GetHashCode()
{
ReadOnlySpan<char> nameSpan = _name.AsSpan();
fixed( char* cptr = nameSpan ) {
return InternalIO.Intrinsic
.string_quickHash( cptr, _name.Length );
}
}
}
public static class DataLabelBuilder
{
public static DataLabel AsLabel(this string name)
{
return new DataLabel(name);
}
}
}
+37 -52
View File
@@ -28,7 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Data;
using StgSharp.Data.Intrinsic;
using System;
using System.IO;
@@ -46,38 +46,30 @@ namespace StgSharp.Data
private byte[] currentKey;
private readonly byte[] originKey;
private int cycleCount;
private SHA512 hash;
public RandomGenerator() : this(DateTime.UtcNow.ToBinary())
{
public RandomGenerator() : this( DateTime.UtcNow.ToBinary() ) { }
}
public RandomGenerator(object source)
public RandomGenerator( object source )
{
try
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
try {
if( source == null ) {
throw new ArgumentNullException( nameof( source ) );
}
XmlSerializer s = new XmlSerializer(source.GetType());
using (StringWriter sw = new StringWriter())
{
s.Serialize(sw, source);
XmlSerializer s = new XmlSerializer( source.GetType() );
using( StringWriter sw = new StringWriter() ) {
s.Serialize( sw, source );
string data = sw.ToString();
originKey = Encoding.UTF8.GetBytes(data);
originKey = Encoding.UTF8.GetBytes( data );
}
}
catch (Exception)
{
catch( Exception ) {
throw;
}
hash = SHA512.Create();
originKey = hash.ComputeHash(originKey);
originKey = hash.ComputeHash( originKey );
currentKey = originKey;
cycleCount = 0;
}
@@ -105,54 +97,44 @@ namespace StgSharp.Data
/**/
return source.Read<int>(cycleCount % 4);
return source.Read<int>( cycleCount % 4 );
}
public byte GenRandomInt8()
{
cycleCount++;
if (cycleCount % 64 == 0)
{
if( cycleCount % 64 == 0 ) {
PrivateRand();
}
return currentKey[cycleCount % 64];
return currentKey[ cycleCount % 64 ];
}
public float GenRandomSingle()
{
cycleCount++;
while (true)
{
while( true ) {
M128 source = PrivateRand();
uint
temp0 = source.Read<uint>(0),
temp1 = source.Read<uint>(2);
temp0 = source.Read<uint>( 0 ),
temp1 = source.Read<uint>( 2 );
if (temp0 * temp1 != 0)
{
float ret = ((temp0 % temp1) * 1.0f) / temp1;
if (ret < 0.335f)
{
ret = ret * ((ret * (-0.7811934f)) + 1.4489113f);
if( temp0 * temp1 != 0 ) {
float ret = ( ( temp0 % temp1 ) * 1.0f ) / temp1;
if( ret < 0.335f ) {
ret = ret * ( ( ret * ( -0.7811934f ) ) + 1.4489113f );
} else {
ret = ( ret * ( ( ret * ( -0.1158368f ) ) + 1.0580600f ) ) + 0.0590584f;
}
else
{
ret = (ret * ((ret * (-0.1158368f)) + 1.0580600f)) + 0.0590584f;
}
if (ret > 1)
{
if( ret > 1 ) {
continue;
}
return ret;
}
}
}
public void Reset()
{
currentKey = originKey;
@@ -161,24 +143,27 @@ namespace StgSharp.Data
private unsafe M128 PrivateRand()
{
currentKey = hash.ComputeHash(currentKey);
currentKey = hash.ComputeHash( currentKey );
M128 ret;
fixed (byte* bptr = currentKey)
{
switch ((cycleCount % 16) / 4)
{
fixed( byte* bptr = currentKey ) {
switch( ( cycleCount % 16 ) / 4 ) {
case 0:
ret = *(((M128*)bptr) + 0); break;
ret = *( ( ( M128* )bptr ) + 0 );
break;
case 1:
ret = *(((M128*)bptr) + 1); break;
ret = *( ( ( M128* )bptr ) + 1 );
break;
case 2:
ret = *(((M128*)bptr) + 2); break;
ret = *( ( ( M128* )bptr ) + 2 );
break;
case 3:
ret = *(((M128*)bptr) + 3); break;
ret = *( ( ( M128* )bptr ) + 3 );
break;
default:
throw new InvalidOperationException();
}
}
//Console.WriteLine(ret.ToString(16));
return ret;
}
+4 -7
View File
@@ -39,12 +39,9 @@ using System.Threading.Tasks;
namespace StgSharp.Data
{
/// <summary>
/// An independent storage area, used as the only folder type in root folder.
/// Contains several <see cref="SSD"/> files reference as virtual disc.
/// Data is actually stored in <see cref="SSD"/>s in certain RAID mode.
/// An independent storage area, used as the only folder type in root folder. Contains several
/// <see cref="SSD" /> files reference as virtual disc. Data is actually stored in <see
/// cref="SSD" />s in certain RAID mode.
/// </summary>
public partial class Area
{
}
public partial class Area { }
}
+18 -24
View File
@@ -28,6 +28,8 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Data.Intrinsic;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -38,52 +40,44 @@ using System.Text;
namespace StgSharp.Data
{
[StructLayout(LayoutKind.Explicit, Size = 16)]
[StructLayout( LayoutKind.Explicit, Size = 16 )]
public struct SSDSegmentHead
{
[FieldOffset( 12 )] internal byte size;
[FieldOffset(12)] internal byte size;
[FieldOffset(0)] internal M128 data;
[FieldOffset(13)] public byte selfDefine_1;
[FieldOffset(14)] public byte selfDefine_2;
[FieldOffset(15)] public byte selfDefine_3;
[FieldOffset(0)] public int globalID;
[FieldOffset(4)] public int nextID;
[FieldOffset(8)] public int previousHash;
[FieldOffset( 0 )] internal M128 data;
[FieldOffset( 13 )] public byte selfDefine_1;
[FieldOffset( 14 )] public byte selfDefine_2;
[FieldOffset( 15 )] public byte selfDefine_3;
[FieldOffset( 0 )] public int globalID;
[FieldOffset( 4 )] public int nextID;
[FieldOffset( 8 )] public int previousHash;
public int Size
{
get => ((int)size) + 1;
get => ( ( int )size ) + 1;
set
{
if ((value > 256) || (value < 0))
{
if( ( value > 256 ) || ( value < 0 ) ) {
throw new ArgumentOutOfRangeException();
}
size = (byte)(value - 1);
size = ( byte )( value - 1 );
}
}
public unsafe byte[] GetBytes()
{
byte[] ret = new byte[16];
fixed (Vector4* vptr = &data.vec)
{
byte* bptr = (byte*)vptr;
for (int i = 0; i < 15; i++)
{
ret[i] = *bptr;
fixed( Vector4* vptr = &data.vec ) {
byte* bptr = ( byte* )vptr;
for( int i = 0; i < 15; i++ ) {
ret[ i ] = *bptr;
}
}
return ret;
}
}
}
+51 -65
View File
@@ -28,6 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Data.Intrinsic;
using StgSharp.Math;
using System;
@@ -40,38 +41,37 @@ using System.Threading.Tasks;
namespace StgSharp.Data
{
[StructLayout(LayoutKind.Explicit, Size = StgSharp.ssdSegmentLength * 16)]
[StructLayout( LayoutKind.Explicit, Size = StgSharp.ssdSegmentLength * 16 )]
public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment>
{
[FieldOffset(16)] public fixed byte Data[16 * (StgSharp.ssdSegmentLength - 1)];
[FieldOffset(12)] public int DataHash;
[FieldOffset(8)] public int PreviousHash;
[FieldOffset(0 * 16)] public SSDSegmentHead Head;
[FieldOffset( 16 )] public fixed byte Data[
16 * ( StgSharp.ssdSegmentLength - 1 ) ];
[FieldOffset( 12 )] public int DataHash;
[FieldOffset( 8 )] public int PreviousHash;
[FieldOffset( 0 * 16 )] public SSDSegmentHead Head;
public SSDSegment(int previousHash)
public SSDSegment( int previousHash )
{
this.PreviousHash = previousHash;
}
public byte this[int index]
public byte this[ int index ]
{
get
{
if (index > (16 * (StgSharp.ssdSegmentLength - 1)) - 1)
{
if( index > ( 16 * ( StgSharp.ssdSegmentLength - 1 ) ) - 1 ) {
throw new IndexOutOfRangeException();
}
return Data[index];
return Data[ index ];
}
set
{
if (index > (16 * (StgSharp.ssdSegmentLength - 1)) - 1)
{
if( index > ( 16 * ( StgSharp.ssdSegmentLength - 1 ) ) - 1 ) {
throw new IndexOutOfRangeException();
}
Data[index] = value;
Data[ index ] = value;
}
}
@@ -83,31 +83,27 @@ namespace StgSharp.Data
public short Size => Head.size;
public void FillRandomBytes(int begin)
public void FillRandomBytes( int begin )
{
if (begin > 255)
{
if( begin > 255 ) {
return;
}
for (int i = begin; i < 255; i++)
{
Data[i] = Scaler.Random<byte>(); //TODO: 使用STGSHARP内部随机数工具处理它
for( int i = begin; i < 255; i++ ) {
Data[ i ] = Scaler.Random<byte>(); //TODO: 使用STGSHARP内部随机数工具处理它
}
}
public static SSDSegment FromStream(byte[] stream)
public static SSDSegment FromStream( byte[] stream )
{
if (stream.Length != 16 * StgSharp.ssdSegmentLength)
{
if( stream.Length != 16 * StgSharp.ssdSegmentLength ) {
throw new ArgumentException();
}
SSDSegment ret = new SSDSegment();
fixed (byte* bptr = stream)
{
ret.Head.data = *(M128*)bptr;
for (int i = 1; i < StgSharp.ssdSegmentLength; i++)
{
ret.WriteData<M128>(i - 1, *(M128*)(bptr + (16 * i)));
fixed( byte* bptr = stream ) {
ret.Head.data = *( M128* )bptr;
for( int i = 1; i < StgSharp.ssdSegmentLength; i++ ) {
ret.WriteData<M128>(
i - 1, *( M128* )( bptr + ( 16 * i ) ) );
}
}
return ret;
@@ -116,15 +112,12 @@ namespace StgSharp.Data
public byte[] GetBytes()
{
byte[] ret = new byte[16 * StgSharp.ssdSegmentLength];
fixed (M128* mptr = &Head.data)
{
fixed (byte* aptr = ret)
{
Vector4* vsptr = (Vector4*)mptr;
Vector4* vtptr = (Vector4*)aptr;
for (int i = 0; i < 18; i++)
{
*(vtptr + i) = *(vsptr + i);
fixed( M128* mptr = &Head.data ) {
fixed( byte* aptr = ret ) {
Vector4* vsptr = ( Vector4* )mptr;
Vector4* vtptr = ( Vector4* )aptr;
for( int i = 0; i < 18; i++ ) {
*( vtptr + i ) = *( vsptr + i );
}
}
}
@@ -135,15 +128,13 @@ namespace StgSharp.Data
public int GetDataHash()
{
Vector4 v = Vector4.One;
fixed (M128* mptr = &Head.data)
{
Vector4* vptr = (Vector4*)mptr;
for (int i = 0; i < StgSharp.ssdSegmentLength - 1; i += 1)
{
v += (*vptr) * 31;
fixed( M128* mptr = &Head.data ) {
Vector4* vptr = ( Vector4* )mptr;
for( int i = 0; i < StgSharp.ssdSegmentLength - 1; i += 1 ) {
v += ( *vptr ) * 31;
}
}
M128 m = new M128(v);
M128 m = new M128( v );
DataHash = m.vec.GetHashCode();
return DataHash;
}
@@ -151,45 +142,40 @@ namespace StgSharp.Data
public override int GetHashCode()
{
int ret = 17;
fixed (M128* mptr = &Head.data)
{
Vector4* vptr = (Vector4*)mptr;
for (int i = 0; i < StgSharp.ssdSegmentLength; i++)
{
ret = (ret + (*vptr).GetHashCode()) * 31;
fixed( M128* mptr = &Head.data ) {
Vector4* vptr = ( Vector4* )mptr;
for( int i = 0; i < StgSharp.ssdSegmentLength; i++ ) {
ret = ( ret + ( *vptr ).GetHashCode() ) * 31;
}
}
return ret;
}
public unsafe T ReadData<T>(int index) where T : struct
public unsafe T ReadData<T>( int index ) where T: struct
{
fixed (byte* bptr = Data)
{
T* tptr = (T*)bptr;
return *(tptr + index);
fixed( byte* bptr = Data ) {
T* tptr = ( T* )bptr;
return *( tptr + index );
}
}
public unsafe void WriteData<T>(int index, T value) where T : struct
public unsafe void WriteData<T>( int index, T value ) where T: struct
{
fixed (byte* bptr = Data)
{
T* tptr = (T*)bptr;
*(tptr + index) = value;
fixed( byte* bptr = Data ) {
T* tptr = ( T* )bptr;
*( tptr + index ) = value;
}
}
int IComparable<int>.CompareTo(int other)
int IComparable<int>.CompareTo( int other )
{
return ID.CompareTo(other);
return ID.CompareTo( other );
}
int IComparable<SSDSegment>.CompareTo(SSDSegment other)
int IComparable<SSDSegment>.CompareTo( SSDSegment other )
{
return ID.CompareTo(other.ID);
return ID.CompareTo( other.ID );
}
}
}
+6 -4
View File
@@ -50,17 +50,19 @@ namespace StgSharp.Data
fileList = new Dictionary<string, SSDraw>();
}
public SSD(FileStream fileStream)
public SSD( FileStream fileStream )
{
fileList = new Dictionary<string, SSDraw>();
file = fileStream;
}
public static SSD FromFile(string fileRoute)
public static SSD FromFile( string fileRoute )
{
return new SSD(new FileStream(fileRoute, FileMode.Open, FileAccess.Read)) { };
return new SSD(
new FileStream( fileRoute, FileMode.Open, FileAccess.Read ) )
{
};
}
}
}
@@ -49,19 +49,15 @@ namespace StgSharp.Data
folders = new Dictionary<string, SSDFolder>();
}
internal SSDFolder(string name)
internal SSDFolder( string name )
{
if (name == "root")
{
if( name == "root" ) {
throw new ArgumentException(
"Name cannot be root," +
"it is preserved for root file indexer.");
"Name cannot be root," + "it is preserved for root file indexer." );
}
if (name == "default")
{
if( name == "default" ) {
throw new ArgumentException(
"Name cannot be default," +
"it is preserved for default file id provider.");
"Name cannot be default," + "it is preserved for default file id provider." );
}
_name = name;
folders = new Dictionary<string, SSDFolder>();
@@ -69,12 +65,11 @@ namespace StgSharp.Data
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
public void FromBytes(byte[] stream)
public void FromBytes( byte[] stream )
{
throw new NotImplementedException();
}
//TODO 虚拟文件夹的GetBytes好难写
public byte[] GetBytes()
{
+17 -15
View File
@@ -50,28 +50,30 @@ namespace StgSharp.Data.FileIO
private byte[] data;
public SSDraw(string name, Stream streamSource)
public SSDraw( string name, Stream streamSource )
{
if ((streamSource == null) || (streamSource.Length == 0))
{
throw new ArgumentNullException(nameof(streamSource));
if( ( streamSource == null ) || ( streamSource.Length == 0 ) ) {
throw new ArgumentNullException( nameof( streamSource ) );
}
Name = name;
data = new byte[streamSource.Length];
streamSource.Read(data.AsSpan());
streamSource.Read( data.AsSpan() );
}
public SSDrawHead Head { get; set; }
public string Name { get; set; }
public SSDrawHead Head
{
get;
set;
}
public string Name
{
get;
set;
}
}
[StructLayout(LayoutKind.Explicit, Size = 32 * 16)]
public unsafe struct SSDrawHead
{
}
[StructLayout( LayoutKind.Explicit, Size = 32 * 16 )]
public unsafe struct SSDrawHead { }
}
+1 -6
View File
@@ -34,13 +34,8 @@ using System.Text;
namespace StgSharp.Data
{
/// <summary>
/// A class contains a sets of methods to serialize several types
/// </summary>
public static partial class Serializer
{
}
public static partial class Serializer { }
}
@@ -36,20 +36,23 @@ using System.Threading.Tasks;
namespace StgSharp.Data
{
public interface ISSDSerializable
{
public SerializableTypeCode SSDTypeCode { get; }
public SerializableTypeCode SSDTypeCode
{
get;
}
public byte[] GetBytes();
internal void FromBytes(byte[] stream);
internal void FromBytes( byte[] stream );
}
public enum SerializableTypeCode
{
Unknown = 0,
IndexTable = 1,
PixelImage = 2,
@@ -59,22 +62,23 @@ namespace StgSharp.Data
Text = 6,
RawData = 7,
VirtualFolder = int.MaxValue,
}
public static partial class Serializer
{
public static T Deserialize<T>(byte[] stream) where T : ISSDSerializable
public static T Deserialize<T>( byte[] stream )
where T: ISSDSerializable
{
T serializableObject = Activator.CreateInstance<T>();
serializableObject.FromBytes(stream);
serializableObject.FromBytes( stream );
return serializableObject;
}
public static string GetNameTail(SerializableTypeCode typeCode)
public static string GetNameTail( SerializableTypeCode typeCode )
{
switch (typeCode)
{
switch( typeCode ) {
case SerializableTypeCode.IndexTable:
return "_idt";
case SerializableTypeCode.PixelImage:
@@ -92,10 +96,11 @@ namespace StgSharp.Data
case SerializableTypeCode.VirtualFolder:
return "_fod";
default:
throw new ArgumentException("Unknown file type");
throw new ArgumentException( "Unknown file type" );
}
}
public static byte[] Serialize(ISSDSerializable serializableObject)
public static byte[] Serialize( ISSDSerializable serializableObject )
{
return serializableObject.GetBytes();
}