Exemplo n.º 1
0
        public unsafe static TReturn GenericMultiply <TReturn>(TReturn l, TReturn r) where TReturn : struct
        {
            Tuple <TReturn, TReturn> value = new Tuple <TReturn, TReturn>(l, r);

            switch (value)
            {
            case Tuple <Byte, Byte> v:
                return(JemUtil.ValToGenericStruct <Byte, TReturn>((byte)(v.Item1 * v.Item2)));

            case Tuple <SByte, SByte> v:
                return(JemUtil.ValToGenericStruct <SByte, TReturn>((SByte)(v.Item1 * v.Item2)));

            case Tuple <UInt16, UInt16> v:
                return(JemUtil.ValToGenericStruct <UInt16, TReturn>((UInt16)(v.Item1 * v.Item2)));

            case Tuple <Int16, Int16> v:
                return(JemUtil.ValToGenericStruct <Int16, TReturn>((Int16)(v.Item1 * v.Item2)));

            case Tuple <UInt32, UInt32> v:
                return(JemUtil.ValToGenericStruct <UInt32, TReturn>((UInt32)(v.Item1 * v.Item2)));

            case Tuple <Int32, Int32> v:
                return(JemUtil.ValToGenericStruct <Int32, TReturn>((Int32)(v.Item1 * v.Item2)));

            case Tuple <UInt64, UInt64> v:
                return(JemUtil.ValToGenericStruct <UInt64, TReturn>((UInt64)(v.Item1 * v.Item2)));

            case Tuple <Int64, Int64> v:
                return(JemUtil.ValToGenericStruct <Int64, TReturn>((Int64)(v.Item1 * v.Item2)));

            default:
                return(default);
            }
        }
Exemplo n.º 2
0
 static GM()
 {
     if (!JemUtil.IsNumericType <TData>())
     {
         throw new ArithmeticException();
     }
 }
Exemplo n.º 3
0
        public unsafe static TReturn GenericMultiply <TReturn>(TReturn l, TReturn r) where TReturn : struct
        {
            Tuple <TReturn, TReturn> value = new Tuple <TReturn, TReturn>(l, r);

            switch (value)
            {
            case Tuple <Byte, Byte> v:
                return(JemUtil.ValToGenericStruct <Byte, TReturn>(checked ((byte)(v.Item1 * v.Item2))));

            case Tuple <SByte, SByte> v:
                return(JemUtil.ValToGenericStruct <SByte, TReturn>(checked ((SByte)(v.Item1 * v.Item2))));

            case Tuple <UInt16, UInt16> v:
                return(JemUtil.ValToGenericStruct <UInt16, TReturn>(checked ((UInt16)(v.Item1 * v.Item2))));

            case Tuple <Int16, Int16> v:
                return(JemUtil.ValToGenericStruct <Int16, TReturn>(checked ((Int16)(v.Item1 * v.Item2))));

            case Tuple <UInt32, UInt32> v:
                return(JemUtil.ValToGenericStruct <UInt32, TReturn>((checked (v.Item1 * v.Item2))));

            case Tuple <Int32, Int32> v:
                return(JemUtil.ValToGenericStruct <Int32, TReturn>((checked (v.Item1 * v.Item2))));

            case Tuple <UInt64, UInt64> v:
                return(JemUtil.ValToGenericStruct <UInt64, TReturn>((checked (v.Item1 * v.Item2))));

            case Tuple <Int64, Int64> v:
                return(JemUtil.ValToGenericStruct <Int64, TReturn>((checked (v.Item1 * v.Item2))));

            default:
                throw new Exception($"Unsupported type: {typeof(TReturn).Name}");
            }
        }
Exemplo n.º 4
0
 static GM()
 {
     if (!JemUtil.IsNumericType <TData>())
     {
         throw new InvalidOperationException($"Type {typeof(TData).Name} is not a numeric type.");
     }
 }
Exemplo n.º 5
0
 public FixedBufferAllocation(IntPtr ptr, ulong size, long timestamp, int tid, int rid)
 {
     this.Ptr       = ptr;
     this.Size      = size;
     this.TimeStamp = timestamp;
     this.ThreadId  = tid;
     this.Rid       = rid;
     HashCode       = JemUtil.CombineHashCodes(this.Ptr.GetHashCode(), this.Size.GetHashCode(), this.TimeStamp.GetHashCode(), this.ThreadId.GetHashCode(), this.Rid.GetHashCode());
 }
Exemplo n.º 6
0
        public unsafe ReadOnlySpan <C> AcquireSpan <C>() where C : struct, IEquatable <T>, IComparable <T>, IConvertible
        {
            int size = checked ((int)(Size / (ulong)JemUtil.SizeOfStruct <C>()));

            if (size == 0)
            {
                throw new ArgumentException($"Type {typeof(T).Name} is too small to be reinterpreted as {typeof(C).Name}.");
            }
            else
            {
                Acquire();
                return(new ReadOnlySpan <C>((void *)_Ptr, size));
            }
        }
Exemplo n.º 7
0
        public unsafe static double GenericSqrt <TReturn>(TReturn l) where TReturn : struct
        {
            if (!JemUtil.IsNumericType <TReturn>())
            {
                throw new ArithmeticException();
            }
            switch (l)
            {
            case SByte v:
                return(Math.Sqrt(v));

            case Byte v:
                return(Math.Sqrt(v));

            case Int32 v:
                return(Math.Sqrt(v));

            case UInt32 v:
                return(Math.Sqrt(v));

            case Int16 v:
                return(Math.Sqrt(v));

            case UInt16 v:
                return(Math.Sqrt(v));

            case Int64 v:
                return(Math.Sqrt(v));

            case UInt64 v:
                return(Math.Sqrt(v));

            default:
                throw new ArithmeticException();
            }
        }
Exemplo n.º 8
0
 public static uint ElementSizeInBytes <T>() where T : struct => (uint)JemUtil.SizeOfStruct <T>();
Exemplo n.º 9
0
 public unsafe Span <Vector <T> > AcquireVectorWriteSpan()
 {
     ThrowIfNotVectorizable();
     Acquire();
     return(new Span <Vector <T> >(_Ptr.ToPointer(), _Length / JemUtil.VectorLength <T>()));
 }
Exemplo n.º 10
0
 public unsafe ReadOnlySpan <Vector <T> > AcquireVectorSpan()
 {
     ThrowIfNotVectorizable();
     ThrowIfInvalid();
     return(new ReadOnlySpan <Vector <T> >(_Ptr.ToPointer(), _Length / JemUtil.VectorLength <T>()));
 }
Exemplo n.º 11
0
        public Vector <T> AcquireAsSingleVector()
        {
            if (this._Length != Vector <T> .Count)
            {
                throw new InvalidOperationException($"The length of the array must be {Vector<T>.Count} elements to create a vector of type {JemUtil.CLRType<T>().Name}.");
            }
            ReadOnlySpan <T>           span   = AcquireSpan();
            ReadOnlySpan <Vector <T> > vector = span.NonPortableCast <T, Vector <T> >();

            return(vector[0]);
        }