コード例 #1
0
        public void RunReflectionScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));

            typeof(AdvSimd).GetMethod(nameof(AdvSimd.StoreSelectedScalar), new Type[] { typeof(Int16 *), typeof(Vector128 <Int16>), typeof(byte) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(Int16 *)),
                Unsafe.Read <Vector128 <Int16> >(_dataTable.inArray1Ptr),
                ElementIndex
            });

            ValidateResult(_dataTable.inArray1Ptr, _dataTable.outArrayPtr);
        }
コード例 #2
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            typeof(Avx2).GetMethod(nameof(Avx2.MaskStore), new Type[] { typeof(Int64 *), typeof(Vector256 <Int64>), typeof(Vector256 <Int64>) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(Int64 *)),
                Avx.LoadAlignedVector256((Int64 *)(_dataTable.inArray1Ptr)),
                Avx.LoadAlignedVector256((Int64 *)(_dataTable.inArray2Ptr))
            });

            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
コード例 #3
0
        public void RunReflectionScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));

            typeof(AdvSimd).GetMethod(nameof(AdvSimd.StoreSelectedScalar), new Type[] { typeof(Byte *), typeof(Vector64 <Byte>), typeof(byte) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(Byte *)),
                AdvSimd.LoadVector64((Byte *)(_dataTable.inArray1Ptr)),
                ElementIndex
            });

            ValidateResult(_dataTable.inArray1Ptr, _dataTable.outArrayPtr);
        }
コード例 #4
0
        public void RunReflectionScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));

            typeof(AdvSimd.Arm64).GetMethod(nameof(AdvSimd.Arm64.StorePairNonTemporal), new Type[] { typeof(Single *), typeof(Vector64 <Single>), typeof(Vector64 <Single>) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(Single *)),
                AdvSimd.LoadVector64((Single *)(_dataTable.inArray1Ptr)),
                AdvSimd.LoadVector64((Single *)(_dataTable.inArray2Ptr))
            });

            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
コード例 #5
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            var result = typeof(Avx).GetMethod(nameof(Avx.MaskLoad), new Type[] { typeof(Double *), typeof(Vector128 <Double>) })
                         .Invoke(null, new object[] {
                Pointer.Box(_dataTable.inArray1Ptr, typeof(Double *)),
                Avx.LoadAlignedVector128((Double *)(_dataTable.inArray2Ptr))
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector128 <Double>)(result));
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
コード例 #6
0
        public void RunReflectionScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));

            typeof(AdvSimd.Arm64).GetMethod(nameof(AdvSimd.Arm64.StorePairNonTemporal), new Type[] { typeof(UInt32 *), typeof(Vector64 <UInt32>), typeof(Vector64 <UInt32>) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(UInt32 *)),
                Unsafe.Read <Vector64 <UInt32> >(_dataTable.inArray1Ptr),
                Unsafe.Read <Vector64 <UInt32> >(_dataTable.inArray2Ptr)
            });

            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
コード例 #7
0
        public void RunReflectionScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));

            var result = typeof(Avx2).GetMethod(nameof(Avx2.MaskLoad), new Type[] { typeof(Int64 *), typeof(Vector128 <Int64>) })
                         .Invoke(null, new object[] {
                Pointer.Box(_dataTable.inArray1Ptr, typeof(Int64 *)),
                Unsafe.Read <Vector128 <Int64> >(_dataTable.inArray2Ptr)
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector128 <Int64>)(result));
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
コード例 #8
0
        public void RunReflectionScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));

            typeof(Avx2).GetMethod(nameof(Avx2.MaskStore), new Type[] { typeof(UInt32 *), typeof(Vector128 <UInt32>), typeof(Vector128 <UInt32>) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(UInt32 *)),
                Sse2.LoadVector128((UInt32 *)(_dataTable.inArray1Ptr)),
                Sse2.LoadVector128((UInt32 *)(_dataTable.inArray2Ptr))
            });

            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
コード例 #9
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(UInt64 *), typeof(Vector256 <UInt64>), typeof(byte) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(UInt64 *)),
                Avx.LoadAlignedVector256((UInt64 *)(_dataTable.inArrayPtr)),
                (byte)1
            });

            ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
        }
コード例 #10
0
        public void RunReflectionScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));

            typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Byte *), typeof(Vector256 <Byte>), typeof(byte) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(Byte *)),
                Unsafe.Read <Vector256 <Byte> >(_dataTable.inArrayPtr),
                (byte)1
            });

            ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
        }
コード例 #11
0
        public void RunReflectionScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));

            typeof(Avx2).GetMethod(nameof(Avx2.MaskStore), new Type[] { typeof(Int32 *), typeof(Vector256 <Int32>), typeof(Vector256 <Int32>) })
            .Invoke(null, new object[] {
                Pointer.Box(_dataTable.outArrayPtr, typeof(Int32 *)),
                Unsafe.Read <Vector256 <Int32> >(_dataTable.inArray1Ptr),
                Unsafe.Read <Vector256 <Int32> >(_dataTable.inArray2Ptr)
            });

            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
コード例 #12
0
ファイル: Reflection.cs プロジェクト: Tryll/CoreRT-armel
        static void TestGeneric <T>()
        {
            var refType = new object();

            Generic <T> .ThreadStaticValueType     = 123;
            Generic <T> .ThreadStaticReferenceType = refType;
            Generic <T> .ThreadStaticPointerType   = (int *)456;

            {
                var fd  = typeof(Generic <T>).GetField(nameof(Generic <T> .ThreadStaticValueType));
                var val = (int)fd.GetValue(null);
                if (val != 123)
                {
                    throw new Exception();
                }
                fd.SetValue(null, 234);
                if (Generic <T> .ThreadStaticValueType != 234)
                {
                    throw new Exception();
                }
            }

            {
                var fd  = typeof(Generic <T>).GetField(nameof(Generic <T> .ThreadStaticReferenceType));
                var val = fd.GetValue(null);
                if (val != refType)
                {
                    throw new Exception();
                }
                val = new object();
                fd.SetValue(null, val);
                if (Generic <T> .ThreadStaticReferenceType != val)
                {
                    throw new Exception();
                }
            }

            {
                var fd  = typeof(Generic <T>).GetField(nameof(Generic <T> .ThreadStaticPointerType));
                var val = Pointer.Unbox(fd.GetValue(null));
                if (val != (int *)456)
                {
                    throw new Exception();
                }
                fd.SetValue(null, Pointer.Box((void *)678, typeof(int *)));
                if (Generic <T> .ThreadStaticPointerType != (void *)678)
                {
                    throw new Exception();
                }
            }
        }
コード例 #13
0
        public void RunReflectionScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));

            var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256 <Int16>), typeof(Int16 *), typeof(byte) })
                         .Invoke(null, new object[] {
                Unsafe.Read <Vector256 <Int16> >(_dataTable.inArray1Ptr),
                Pointer.Box(_dataTable.inArray2Ptr, typeof(Int16 *)),
                (byte)1
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector256 <Int16>)(result));
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
コード例 #14
0
        public void RunReflectionScenario_LoadAligned()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));

            var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256 <SByte>), typeof(SByte *), typeof(byte) })
                         .Invoke(null, new object[] {
                Avx.LoadAlignedVector256((SByte *)(_dataTable.inArray1Ptr)),
                Pointer.Box(_dataTable.inArray2Ptr, typeof(SByte *)),
                (byte)1
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector256 <SByte>)(result));
            ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
        }
コード例 #15
0
        public void RunReflectionScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));

            UInt32 buffer = 0;

            var result = typeof(Bmi2).GetMethod(nameof(Bmi2.MultiplyNoFlags), new Type[] { typeof(UInt32), typeof(UInt32), typeof(UInt32 *) })
                         .Invoke(null, new object[] {
                Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data1)),
                Unsafe.ReadUnaligned <UInt32>(ref Unsafe.As <UInt32, byte>(ref _data2)),
                Pointer.Box(&buffer, typeof(UInt32 *))
            });

            ValidateResult(_data1, _data2, buffer, (UInt32)result);
        }
コード例 #16
0
    private static int CallAsFunctionPointer(int expected)
    {
        Console.WriteLine($"{nameof(CallAsFunctionPointer)} ({expected}) ...");

        IntPtr fptr = SuppressGCTransitionNative.GetNextUIntFunctionPointer();

        int    n      = 0;
        int *  pn     = &n;
        object boxedN = Pointer.Box(pn, typeof(int *));

        MethodInfo callNextUInt = typeof(FunctionPointer).GetMethod("Call_NextUInt");

        callNextUInt.Invoke(null, new object[] { fptr, boxedN });
        Assert.AreEqual(expected, n);
        return(n + 1);
    }
コード例 #17
0
        public void RunReflectionScenario_UnsafeRead()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));

            UInt16 op3 = TestLibrary.Generator.GetUInt16();

            var result = typeof(AdvSimd).GetMethod(nameof(AdvSimd.LoadAndInsertScalar), new Type[] { typeof(Vector128 <UInt16>), typeof(byte), typeof(UInt16 *) })
                         .Invoke(null, new object[] {
                Unsafe.Read <Vector128 <UInt16> >(_dataTable.inArray1Ptr),
                ElementIndex,
                Pointer.Box(&op3, typeof(UInt16 *))
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector128 <UInt16>)(result));
            ValidateResult(_dataTable.inArray1Ptr, op3, _dataTable.outArrayPtr);
        }
コード例 #18
0
        public void RunReflectionScenario_Load()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));

            Single op3 = TestLibrary.Generator.GetSingle();

            var result = typeof(AdvSimd).GetMethod(nameof(AdvSimd.LoadAndInsertScalar), new Type[] { typeof(Vector64 <Single>), typeof(byte), typeof(Single *) })
                         .Invoke(null, new object[] {
                AdvSimd.LoadVector64((Single *)(_dataTable.inArray1Ptr)),
                ElementIndex,
                Pointer.Box(&op3, typeof(Single *))
            });

            Unsafe.Write(_dataTable.outArrayPtr, (Vector64 <Single>)(result));
            ValidateResult(_dataTable.inArray1Ptr, op3, _dataTable.outArrayPtr);
        }
コード例 #19
0
        /// <summary>
        /// Invokes the inner ParseRequestLine method.
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="data"></param>
        /// <param name="length"></param>
        unsafe void ParseRequestLine(TRequestHandler handler, byte *data, int length)
        {
            var h = new GCHandle();
            var t = Encoding.ASCII.GetString(data, length);
            var i = t.IndexOf(' ', 0, Math.Min(20, t.Length));

            if (i > 2 && t.Length > i + 2)
            {
                // is the following character not a '/'?
                var c = t[i + 1];
                if (c != '/')
                {
                    // insert missing '/'
                    t = t.Insert(i + 1, "/");

                    // create a copy of the rewritten request string
                    var buf = Encoding.ASCII.GetBytes(t);
                    var pin = GCHandle.Alloc(buf, GCHandleType.Pinned);
                    var ptr = pin.AddrOfPinnedObject();

                    // will need to free this in the postfix
                    h = pin;

                    // replace argument going into original method
                    data   = (byte *)ptr.ToPointer();
                    length = buf.Length;
                }
            }

            try
            {
                innerParseRequestLineMethod.Invoke(
                    this,
                    new[] { handler, Pointer.Box(data, typeof(byte *)), length });
            }

            finally
            {
                if (h.IsAllocated)
                {
                    h.Free();
                }
            }
        }
コード例 #20
0
        public static unsafe void TestByRefLikeRefReturn()
        {
            ByRefLike  brl  = new ByRefLike();
            ByRefLike *pBrl = &brl;
            MethodInfo mi   = typeof(TestClass <int>).GetMethod(nameof(TestClass <int> .ByRefLikeRefReturningMethod));

            try
            {
                // Don't use Assert.Throws because that will make a lambda and invalidate the pointer
                object o = mi.Invoke(null, new object[] { Pointer.Box(pBrl, typeof(ByRefLike *)) });

                // If this is reached, it means `o` is a boxed byref-like type. That's a GC hole right there.
                throw new Xunit.Sdk.XunitException("Boxed a byref-like type.");
            }
            catch (NotSupportedException)
            {
                // We expect a NotSupportedException from the Invoke call. Methods returning byref-like types by reference
                // are not reflection invokable.
            }
        }
コード例 #21
0
        public void TestCalliGenerationVoidIntStar()
        {
            int          callCount = 0;
            int          setVal    = 5;
            Take1IntStar vvct      = (i) =>
            {
                callCount++;
                *i = *i + 1;
            };
            var fp = Marshal.GetFunctionPointerForDelegate(vvct);
            CalliILGenerator generator = new CalliILGenerator();
            DynamicMethod    method    = new DynamicMethod("MyFunc", null, new Type[] { typeof(int *) });

            generator.GenerateMethod(method.GetILGenerator(), null, new Type[] { typeof(int *) }, fp);

            method.Invoke(null, new object[] { Pointer.Box(&setVal, typeof(int *)) });

            Assert.Equal(1, callCount);
            Assert.Equal(6, setVal);
        }
コード例 #22
0
ファイル: VMSlot.cs プロジェクト: xuan2261/AndyLarkinsVM
        public unsafe object ToObject(Type type)
        {
            if (type.IsEnum)
            {
                return(Enum.ToObject(type, ToObject(Enum.GetUnderlyingType(type))));
            }

            switch (Type.GetTypeCode(type))
            {
            case TypeCode.Byte:
                return(u1);

            case TypeCode.SByte:
                return((sbyte)u1);

            case TypeCode.Boolean:
                return(u1 != 0);

            case TypeCode.UInt16:
                return(u2);

            case TypeCode.Int16:
                return((short)u2);

            case TypeCode.Char:
                return((char)u2);

            case TypeCode.UInt32:
                return(u4);

            case TypeCode.Int32:
                return((int)u4);

            case TypeCode.UInt64:
                return((ulong)u8);

            case TypeCode.Int64:
                return((long)u8);

            case TypeCode.Single:
                return(r4);

            case TypeCode.Double:
                return(r8);

            default:
                if (type.IsPointer)
                {
                    return(Pointer.Box((void *)u8, type));
                }
                if (type == typeof(IntPtr))
                {
                    return(Platform.x64 ? new IntPtr((long)u8) : new IntPtr((int)u4));
                }
                if (type == typeof(UIntPtr))
                {
                    return(Platform.x64 ? new UIntPtr(u8) : new UIntPtr(u4));
                }
                return(ValueTypeBox.Unbox(o));
            }
        }
コード例 #23
0
ファイル: ReflectionUtils.cs プロジェクト: natilivni/dotNext
 public static unsafe object Wrap <T>(T *ptr)
     where T : unmanaged => Pointer.Box(ptr, typeof(T *));
コード例 #24
0
        public static unsafe void TestExplicitCast()
        {
            nuint value = 42u;

            MethodInfo[] methods = typeof(nuint).GetMethods();

            MethodInfo opExplicitFromUInt32 = typeof(nuint).GetMethod("op_Explicit", new Type[] { typeof(uint) });
            MethodInfo opExplicitToUInt32   = methods.Single((methodInfo) => (methodInfo.Name == "op_Explicit") && (methodInfo.ReturnType == typeof(uint)));

            uint i = (uint)opExplicitToUInt32.Invoke(null, new object[] { value });

            Assert.Equal(42u, i);
            Assert.Equal(value, (nuint)opExplicitFromUInt32.Invoke(null, new object[] { i }));

            MethodInfo opExplicitFromUInt64 = typeof(nuint).GetMethod("op_Explicit", new Type[] { typeof(ulong) });
            MethodInfo opExplicitToUInt64   = methods.Single((methodInfo) => (methodInfo.Name == "op_Explicit") && (methodInfo.ReturnType == typeof(ulong)));

            ulong l = (ulong)opExplicitToUInt64.Invoke(null, new object[] { value });

            Assert.Equal(42u, l);
            Assert.Equal(value, (nuint)opExplicitFromUInt64.Invoke(null, new object[] { l }));

            MethodInfo opExplicitFromPointer = typeof(nuint).GetMethod("op_Explicit", new Type[] { typeof(void *) });
            MethodInfo opExplicitToPointer   = methods.Single((methodInfo) => (methodInfo.Name == "op_Explicit") && (methodInfo.ReturnType == typeof(void *)));

            void *v = Pointer.Unbox(opExplicitToPointer.Invoke(null, new object[] { value }));

            Assert.Equal(value, (nuint)opExplicitFromPointer.Invoke(null, new object[] { Pointer.Box(v, typeof(void *)) }));

            value = unchecked ((nuint)0x7fffffffffffffff);
            Exception ex = Assert.ThrowsAny <Exception>(() => opExplicitToUInt32.Invoke(null, new object[] { value }));


            if (ex is TargetInvocationException)
            {
                // RyuJIT throws TargetInvocationException wrapping an OverflowException
                // while Mono directly throws the OverflowException
                ex = ex.InnerException;
            }
            Assert.IsType <OverflowException>(ex);
        }
コード例 #25
0
        static unsafe int Main(string[] args)
        {
            int testResult = Pass;

            if (Avx2.IsSupported)
            {
                Four    = 4;
                Eight   = 8;
                invalid = 15;

                for (int i = 0; i < N; i++)
                {
                    floatSourceTable[i]  = (float)i * 10.0f;
                    doubleSourceTable[i] = (double)i * 10.0;
                    intSourceTable[i]    = i * 10;
                    longSourceTable[i]   = i * 10;
                }

                Vector256 <int>  indexi;
                Vector256 <long> indexl;
                Vector128 <int>  indexi128;

                fixed(int *iptr = intIndexTable)
                fixed(long *lptr   = longIndexTable)
                fixed(int *i128ptr = vector128intIndexTable)
                {
                    indexi    = Avx.LoadVector256(iptr);
                    indexl    = Avx.LoadVector256(lptr);
                    indexi128 = Sse2.LoadVector128(i128ptr);
                }

                Vector256 <int>    maski;
                Vector256 <uint>   maskui;
                Vector256 <long>   maskl;
                Vector256 <ulong>  maskul;
                Vector256 <float>  maskf;
                Vector256 <double> maskd;

                fixed(int *iptr = intMaskTable)
                fixed(long *lptr = longMaskTable)
                {
                    maski = Avx.LoadVector256(iptr);
                    maskl = Avx.LoadVector256(lptr);

                    maskui = maski.AsUInt32();
                    maskul = maskl.AsUInt64();
                    maskf  = maski.AsSingle();
                    maskd  = maskl.AsDouble();
                }

                Vector256 <int>    sourcei  = Vector256 <int> .Zero;
                Vector256 <uint>   sourceui = Vector256 <uint> .Zero;
                Vector256 <long>   sourcel  = Vector256 <long> .Zero;
                Vector256 <ulong>  sourceul = Vector256 <ulong> .Zero;
                Vector256 <float>  sourcef  = Vector256 <float> .Zero;
                Vector256 <double> sourced  = Vector256 <double> .Zero;

                // public static unsafe Vector256<float> GatherMaskVector256(Vector256<float> source, float* baseAddress, Vector256<int> index, Vector256<float> mask, byte scale)
                using (TestTable <float, int> floatTable = new TestTable <float, int>(floatSourceTable, new float[8]))
                {
                    var vf = Avx2.GatherMaskVector256(sourcef, (float *)(floatTable.inArrayPtr), indexi, maskf, 4);
                    Unsafe.Write(floatTable.outArrayPtr, vf);

                    if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y), intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on float:");
                        foreach (var item in floatTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    vf = (Vector256 <float>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <float>), typeof(float *), typeof(Vector256 <int>), typeof(Vector256 <float>), typeof(byte) }).
                         Invoke(null, new object[] { sourcef, Pointer.Box(floatTable.inArrayPtr, typeof(float *)), indexi, maskf, (byte)4 });
                    Unsafe.Write(floatTable.outArrayPtr, vf);

                    if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y), intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on float:");
                        foreach (var item in floatTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourcef, (float *)(floatTable.inArrayPtr), indexi, maskf, 3);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on float with invalid scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }

                    vf = Avx2.GatherMaskVector256(sourcef, (float *)(floatTable.inArrayPtr), indexi, maskf, Four);
                    Unsafe.Write(floatTable.outArrayPtr, vf);

                    if (!floatTable.CheckResult((x, y) => BitConverter.SingleToInt32Bits(x) == BitConverter.SingleToInt32Bits(y), intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on float with non-const scale (IMM):");
                        foreach (var item in floatTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourcef, (float *)(floatTable.inArrayPtr), indexi, maskf, invalid);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on float with invalid non-const scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }
                }

                // public static unsafe Vector256<double> GatherMaskVector256(Vector256<double> source, double* baseAddress, Vector128<int> index, Vector256<double> mask, byte scale)
                using (TestTable <double, int> doubletTable = new TestTable <double, int>(doubleSourceTable, new double[4]))
                {
                    var vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexi128, maskd, 8);
                    Unsafe.Write(doubletTable.outArrayPtr, vd);

                    if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), vector128intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on double:");
                        foreach (var item in doubletTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    vd = (Vector256 <double>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <double>), typeof(double *), typeof(Vector128 <int>), typeof(Vector256 <double>), typeof(byte) }).
                         Invoke(null, new object[] { sourced, Pointer.Box(doubletTable.inArrayPtr, typeof(double *)), indexi128, maskd, (byte)8 });
                    Unsafe.Write(doubletTable.outArrayPtr, vd);

                    if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), vector128intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on double:");
                        foreach (var item in doubletTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexi128, maskd, 3);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on double with invalid scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }

                    vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexi128, maskd, Eight);
                    Unsafe.Write(doubletTable.outArrayPtr, vd);

                    if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), vector128intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on double with non-const scale (IMM):");
                        foreach (var item in doubletTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexi128, maskd, invalid);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on double with invalid non-const scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }
                }

                // public static unsafe Vector256<int> GatherMaskVector256(Vector256<int> source, int* baseAddress, Vector256<int> index, Vector256<int> mask, byte scale)
                using (TestTable <int, int> intTable = new TestTable <int, int>(intSourceTable, new int[8]))
                {
                    var vf = Avx2.GatherMaskVector256(sourcei, (int *)(intTable.inArrayPtr), indexi, maski, 4);
                    Unsafe.Write(intTable.outArrayPtr, vf);

                    if (!intTable.CheckResult((x, y) => x == y, intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on int:");
                        foreach (var item in intTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    vf = (Vector256 <int>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <int>), typeof(int *), typeof(Vector256 <int>), typeof(Vector256 <int>), typeof(byte) }).
                         Invoke(null, new object[] { sourcei, Pointer.Box(intTable.inArrayPtr, typeof(int *)), indexi, maski, (byte)4 });
                    Unsafe.Write(intTable.outArrayPtr, vf);

                    if (!intTable.CheckResult((x, y) => x == y, intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on int:");
                        foreach (var item in intTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourcei, (int *)(intTable.inArrayPtr), indexi, maski, 3);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on int with invalid scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }

                    vf = Avx2.GatherMaskVector256(sourcei, (int *)(intTable.inArrayPtr), indexi, maski, Four);
                    Unsafe.Write(intTable.outArrayPtr, vf);

                    if (!intTable.CheckResult((x, y) => x == y, intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on int with non-const scale (IMM):");
                        foreach (var item in intTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourcei, (int *)(intTable.inArrayPtr), indexi, maski, invalid);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on int with invalid non-const scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }
                }

                // public static unsafe Vector256<uint> GatherMaskVector256(Vector256<uint> source, uint* baseAddress, Vector256<int> index, Vector256<uint> mask, byte scale)
                using (TestTable <int, int> intTable = new TestTable <int, int>(intSourceTable, new int[8]))
                {
                    var vf = Avx2.GatherMaskVector256(sourceui, (uint *)(intTable.inArrayPtr), indexi, maskui, 4);
                    Unsafe.Write(intTable.outArrayPtr, vf);

                    if (!intTable.CheckResult((x, y) => x == y, intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on uint:");
                        foreach (var item in intTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    vf = (Vector256 <uint>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <uint>), typeof(uint *), typeof(Vector256 <int>), typeof(Vector256 <uint>), typeof(byte) }).
                         Invoke(null, new object[] { sourceui, Pointer.Box(intTable.inArrayPtr, typeof(uint *)), indexi, maskui, (byte)4 });
                    if (!intTable.CheckResult((x, y) => x == y, intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on uint:");
                        foreach (var item in intTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourceui, (uint *)(intTable.inArrayPtr), indexi, maskui, 3);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on uint with invalid scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }

                    vf = Avx2.GatherMaskVector256(sourceui, (uint *)(intTable.inArrayPtr), indexi, maskui, Four);
                    Unsafe.Write(intTable.outArrayPtr, vf);

                    if (!intTable.CheckResult((x, y) => x == y, intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on uint with non-const scale (IMM):");
                        foreach (var item in intTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourceui, (uint *)(intTable.inArrayPtr), indexi, maskui, invalid);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on uint with invalid non-const scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }
                }

                // public static unsafe Vector256<long> GatherMaskVector256(Vector256<long> source, long* baseAddress, Vector128<int> index, Vector256<long> mask, byte scale)
                using (TestTable <long, int> longTable = new TestTable <long, int>(longSourceTable, new long[4]))
                {
                    var vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexi128, maskl, 8);
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on long:");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    vf = (Vector256 <long>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <long>), typeof(long *), typeof(Vector128 <int>), typeof(Vector256 <long>), typeof(byte) }).
                         Invoke(null, new object[] { sourcel, Pointer.Box(longTable.inArrayPtr, typeof(long *)), indexi128, maskl, (byte)8 });
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on long:");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexi128, maskl, 3);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on long with invalid scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }

                    vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexi128, maskl, Eight);
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on long with non-const scale (IMM):");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexi128, maskl, invalid);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on long with invalid non-const scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }
                }

                // public static unsafe Vector256<ulong> GatherMaskVector256(Vector256<ulong> source, ulong* baseAddress, Vector128<int> index, Vector256<ulong> mask, byte scale)
                using (TestTable <long, int> longTable = new TestTable <long, int>(longSourceTable, new long[4]))
                {
                    var vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexi128, maskul, 8);
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong:");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    vf = (Vector256 <ulong>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <ulong>), typeof(ulong *), typeof(Vector128 <int>), typeof(Vector256 <ulong>), typeof(byte) }).
                         Invoke(null, new object[] { sourceul, Pointer.Box(longTable.inArrayPtr, typeof(ulong *)), indexi128, maskul, (byte)8 });
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on ulong:");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexi128, maskul, 3);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with invalid scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }

                    vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexi128, maskul, Eight);
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, vector128intIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with non-const scale (IMM):");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexi128, maskul, invalid);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with invalid non-const scale (IMM)");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }
                }

                // public static unsafe Vector256<long> GatherMaskVector256(Vector256<long> source, long* baseAddress, Vector256<long> index, Vector256<long> mask, byte scale)
                using (TestTable <long, long> longTable = new TestTable <long, long>(longSourceTable, new long[4]))
                {
                    var vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexl, maskl, 8);
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, longIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on long with Vector256 long index:");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    vf = (Vector256 <long>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <long>), typeof(long *), typeof(Vector256 <long>), typeof(Vector256 <long>), typeof(byte) }).
                         Invoke(null, new object[] { sourcel, Pointer.Box(longTable.inArrayPtr, typeof(long *)), indexl, maskl, (byte)8 });
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, longIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on long with Vector256 long index:");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexl, maskl, 3);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on long with invalid scale (IMM) and Vector256 long index");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }

                    vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexl, maskl, Eight);
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, longIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on long with non-const scale (IMM) and Vector256 long index:");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourcel, (long *)(longTable.inArrayPtr), indexl, maskl, invalid);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on long with invalid non-const scale (IMM) and Vector256 long index");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }
                }

                // public static unsafe Vector256<ulong> GatherMaskVector256(Vector256<ulong> source, ulong* baseAddress, Vector256<long> index, Vector256<ulong> mask, byte scale)
                using (TestTable <long, long> longTable = new TestTable <long, long>(longSourceTable, new long[4]))
                {
                    var vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexl, maskul, 8);
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, longIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with Vector256 long index:");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    vf = (Vector256 <ulong>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <ulong>), typeof(ulong *), typeof(Vector256 <long>), typeof(Vector256 <ulong>), typeof(byte) }).
                         Invoke(null, new object[] { sourceul, Pointer.Box(longTable.inArrayPtr, typeof(ulong *)), indexl, maskul, (byte)8 });
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, longIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on ulong with Vector256 long index:");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexl, maskul, 3);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with invalid scale (IMM) and Vector256 long index");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }

                    vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexl, maskul, Eight);
                    Unsafe.Write(longTable.outArrayPtr, vf);

                    if (!longTable.CheckResult((x, y) => x == y, longIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on ulong with non-const scale (IMM) and Vector256 long index:");
                        foreach (var item in longTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vf = Avx2.GatherMaskVector256(sourceul, (ulong *)(longTable.inArrayPtr), indexl, maskul, invalid);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on long with invalid non-const scale (IMM) and Vector256 long index");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }
                }

                // public static unsafe Vector256<double> GatherMaskVector256(Vector256<double> source, double* baseAddress, Vector256<long> index, Vector256<double> mask, byte scale)
                using (TestTable <double, long> doubletTable = new TestTable <double, long>(doubleSourceTable, new double[4]))
                {
                    var vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexl, maskd, 8);
                    Unsafe.Write(doubletTable.outArrayPtr, vd);

                    if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), longIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on double with Vector256 long index:");
                        foreach (var item in doubletTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    vd = (Vector256 <double>) typeof(Avx2).GetMethod(nameof(Avx2.GatherMaskVector256), new Type[] { typeof(Vector256 <double>), typeof(double *), typeof(Vector256 <long>), typeof(Vector256 <double>), typeof(byte) }).
                         Invoke(null, new object[] { sourced, Pointer.Box(doubletTable.inArrayPtr, typeof(double *)), indexl, maskd, (byte)8 });
                    Unsafe.Write(doubletTable.outArrayPtr, vd);

                    if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), longIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed with reflection on double with Vector256 long index:");
                        foreach (var item in doubletTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexl, maskd, 3);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on double with invalid scale (IMM) and Vector256 long index");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }

                    vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexl, maskd, Eight);
                    Unsafe.Write(doubletTable.outArrayPtr, vd);

                    if (!doubletTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y), longIndexTable))
                    {
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on double with non-const scale (IMM) and Vector256 long index:");
                        foreach (var item in doubletTable.outArray)
                        {
                            Console.Write(item + ", ");
                        }
                        Console.WriteLine();
                        testResult = Fail;
                    }

                    try
                    {
                        vd = Avx2.GatherMaskVector256(sourced, (double *)(doubletTable.inArrayPtr), indexl, maskd, invalid);
                        Console.WriteLine("AVX2 GatherMaskVector256 failed on double with invalid non-const scale (IMM) and Vector256 long index");
                        testResult = Fail;
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        // success
                    }
                }
            }



            return(testResult);
        }
コード例 #26
0
        /// <summary>
        /// Handle other type.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="writeAction">Write action.</param>
        /// <param name="readAction">Read action.</param>
        /// <param name="raw">Raw mode.</param>
        /// <param name="forceTimestamp">Force timestamp serialization for DateTime fields..</param>
        private static void HandleOther(FieldInfo field, out BinaryReflectiveWriteAction writeAction,
                                        out BinaryReflectiveReadAction readAction, bool raw, bool forceTimestamp)
        {
            var type = field.FieldType;

            var nullableType = Nullable.GetUnderlyingType(type);

            if (type == typeof(decimal))
            {
                writeAction = raw
                    ? GetRawWriter <decimal>(field, (w, o) => w.WriteDecimal(o))
                    : GetWriter <decimal>(field, (f, w, o) => w.WriteDecimal(f, o));
                readAction = raw
                    ? GetRawReader(field, r => r.ReadDecimal())
                    : GetReader(field, (f, r) => r.ReadDecimal(f));
            }
            else if (type == typeof(string))
            {
                writeAction = raw
                    ? GetRawWriter <string>(field, (w, o) => w.WriteString(o))
                    : GetWriter <string>(field, (f, w, o) => w.WriteString(f, o));
                readAction = raw
                    ? GetRawReader(field, r => r.ReadString())
                    : GetReader(field, (f, r) => r.ReadString(f));
            }
            else if (type == typeof(Guid))
            {
                writeAction = raw
                    ? GetRawWriter <Guid>(field, (w, o) => w.WriteGuid(o))
                    : GetWriter <Guid>(field, (f, w, o) => w.WriteGuid(f, o));
                readAction = raw
                    ? GetRawReader(field, r => r.ReadObject <Guid>())
                    : GetReader(field, (f, r) => r.ReadObject <Guid>(f));
            }
            else if (nullableType == typeof(Guid))
            {
                writeAction = raw
                    ? GetRawWriter <Guid?>(field, (w, o) => w.WriteGuid(o))
                    : GetWriter <Guid?>(field, (f, w, o) => w.WriteGuid(f, o));
                readAction = raw ? GetRawReader(field, r => r.ReadGuid()) : GetReader(field, (f, r) => r.ReadGuid(f));
            }
            else if ((nullableType ?? type).IsEnum &&
                     !new[] { typeof(long), typeof(ulong) }.Contains(Enum.GetUnderlyingType(nullableType ?? type)))
            {
                writeAction = raw
                    ? GetRawWriter <object>(field, (w, o) => w.WriteEnum(o))
                    : GetWriter <object>(field, (f, w, o) => w.WriteEnum(f, o));
                readAction = raw ? GetRawReader(field, MthdReadEnumRaw) : GetReader(field, MthdReadEnum);
            }
            else if (type == typeof(IDictionary) || type == typeof(Hashtable))
            {
                writeAction = raw
                    ? GetRawWriter <IDictionary>(field, (w, o) => w.WriteDictionary(o))
                    : GetWriter <IDictionary>(field, (f, w, o) => w.WriteDictionary(f, o));
                readAction = raw
                    ? GetRawReader(field, r => r.ReadDictionary())
                    : GetReader(field, (f, r) => r.ReadDictionary(f));
            }
            else if (type == typeof(ICollection) || type == typeof(ArrayList))
            {
                writeAction = raw
                    ? GetRawWriter <ICollection>(field, (w, o) => w.WriteCollection(o))
                    : GetWriter <ICollection>(field, (f, w, o) => w.WriteCollection(f, o));
                readAction = raw
                    ? GetRawReader(field, r => r.ReadCollection())
                    : GetReader(field, (f, r) => r.ReadCollection(f));
            }
            else if (type == typeof(DateTime) && IsTimestamp(field, forceTimestamp, raw))
            {
                writeAction = GetWriter <DateTime>(field, (f, w, o) => w.WriteTimestamp(f, o));
                readAction  = GetReader(field, (f, r) => r.ReadObject <DateTime>(f));
            }
            else if (nullableType == typeof(DateTime) && IsTimestamp(field, forceTimestamp, raw))
            {
                writeAction = GetWriter <DateTime?>(field, (f, w, o) => w.WriteTimestamp(f, o));
                readAction  = GetReader(field, (f, r) => r.ReadTimestamp(f));
            }
            else if (type.IsPointer)
            {
                unsafe
                {
                    // Expression trees do not work with pointers properly, use reflection.
                    var fieldName = BinaryUtils.CleanFieldName(field.Name);
                    writeAction = raw
                        ? (BinaryReflectiveWriteAction)((o, w) =>
                                                        w.GetRawWriter().WriteLong((long)Pointer.Unbox(field.GetValue(o))))
                        : ((o, w) => w.WriteLong(fieldName, (long)Pointer.Unbox(field.GetValue(o))));

                    readAction = raw
                        ? (BinaryReflectiveReadAction)((o, r) =>
                                                       field.SetValue(o, Pointer.Box((void *)r.GetRawReader().ReadLong(), field.FieldType)))
                        : ((o, r) => field.SetValue(o, Pointer.Box((void *)r.ReadLong(fieldName), field.FieldType)));
                }
            }
            else
            {
                writeAction = raw ? GetRawWriter(field, MthdWriteObjRaw) : GetWriter(field, MthdWriteObj);
                readAction  = raw ? GetRawReader(field, MthdReadObjRaw) : GetReader(field, MthdReadObj);
            }
        }
コード例 #27
0
ファイル: ApiGenerator.cs プロジェクト: ThadHouse/quicnet
        // This API will be replaced with Function Pointers once they exist, but for now IL generation is by far the
        // fastest way to generate the QUIC api
        public unsafe static IQuicInteropApi CreateApiImplementation(NativeQuicApi *api, QuicCloseDelegate closeDelegate)
        {
            var constructor = s_apiConstructor.Value;

            return((IQuicInteropApi)constructor.Invoke(new object[] { Pointer.Box(api, typeof(NativeQuicApi *)), closeDelegate }));
        }
コード例 #28
0
 public static unsafe object LoadPointerTypeField(IntPtr address, RuntimeTypeHandle fieldType)
 {
     return(Pointer.Box(*(void **)address, Type.GetTypeFromHandle(fieldType)));
 }
コード例 #29
0
 public object ReturnWithSystemPointer(int expected)
 {
     return(Pointer.Box((byte *)expected, typeof(byte *)));
 }
コード例 #30
0
ファイル: Reflection.cs プロジェクト: Tryll/CoreRT-armel
        public static unsafe void Run()
        {
            Console.WriteLine(nameof(TestReflectionInvoke));

            // Ensure things we reflect on are in the static callgraph
            if (string.Empty.Length > 0)
            {
                new InvokeTests().ToString();
                InvokeTests.GetHello(null);
                InvokeTests.GetHelloGeneric <int>(0);
                InvokeTests.GetHelloGeneric <string>(null);
                InvokeTests.GetHelloPointer(null);
                InvokeTests.GetHelloPointerToo(null);
                InvokeTests.GetPointer(null, null);
                string unused;
                InvokeTests.GetHelloByRef(null, out unused);
                unused.ToString();
                new InvokeTestsGeneric <object>().GetHello(null);
                new InvokeTestsGeneric <object>().GetHelloGeneric <object>(null);
                new InvokeTestsGeneric <int>().GetHello(null);
                new InvokeTestsGeneric <int>().GetHelloGeneric <double>(0);
            }

            {
                MethodInfo helloMethod = typeof(InvokeTests).GetTypeInfo().GetDeclaredMethod("GetHello");
                string     result      = (string)helloMethod.Invoke(null, new object[] { "world" });
                if (result != "Hello world")
                {
                    throw new Exception();
                }
            }

            {
                MethodInfo helloGenericMethod = typeof(InvokeTests).GetTypeInfo().GetDeclaredMethod("GetHelloGeneric").MakeGenericMethod(typeof(int));
                string     result             = (string)helloGenericMethod.Invoke(null, new object[] { 12345 });
                if (result != "Hello 12345")
                {
                    throw new Exception();
                }
            }

            {
                MethodInfo helloGenericMethod = typeof(InvokeTests).GetTypeInfo().GetDeclaredMethod("GetHelloGeneric").MakeGenericMethod(typeof(string));
                string     result             = (string)helloGenericMethod.Invoke(null, new object[] { "buddy" });
                if (result != "Hello buddy")
                {
                    throw new Exception();
                }
            }

            {
                MethodInfo helloGenericMethod = typeof(InvokeTests).GetTypeInfo().GetDeclaredMethod("GetHelloGeneric").MakeGenericMethod(typeof(Type));
                string     result             = (string)helloGenericMethod.Invoke(null, new object[] { typeof(string) });
                if (result != "Hello System.String")
                {
                    throw new Exception();
                }
            }

            {
                MethodInfo helloByRefMethod = typeof(InvokeTests).GetTypeInfo().GetDeclaredMethod("GetHelloByRef");
                object[]   args             = new object[] { "world", null };
                helloByRefMethod.Invoke(null, args);
                if ((string)args[1] != "Hello world")
                {
                    throw new Exception();
                }
            }

            {
                MethodInfo helloPointerMethod = typeof(InvokeTests).GetTypeInfo().GetDeclaredMethod("GetHelloPointer");
                string     resultNull         = (string)helloPointerMethod.Invoke(null, new object[] { null });
                if (resultNull != "Hello 0")
                {
                    throw new Exception();
                }

                string resultVal = (string)helloPointerMethod.Invoke(null, new object[] { Pointer.Box((void *)42, typeof(char *)) });
                if (resultVal != "Hello 42")
                {
                    throw new Exception();
                }
            }

            {
                MethodInfo helloPointerTooMethod = typeof(InvokeTests).GetTypeInfo().GetDeclaredMethod("GetHelloPointerToo");
                string     result = (string)helloPointerTooMethod.Invoke(null, new object[] { Pointer.Box((void *)85, typeof(char **)) });
                if (result != "Hello 85")
                {
                    throw new Exception();
                }
            }

            {
                MethodInfo getPointerMethod = typeof(InvokeTests).GetTypeInfo().GetDeclaredMethod("GetPointer");
                object     result           = getPointerMethod.Invoke(null, new object[] { Pointer.Box((void *)2018, typeof(void *)), null });
                if (Pointer.Unbox(result) != (void *)2018)
                {
                    throw new Exception();
                }
            }

#if !CODEGEN_CPP
            {
                MethodInfo helloMethod = typeof(InvokeTestsGeneric <string>).GetTypeInfo().GetDeclaredMethod("GetHello");
                string     result      = (string)helloMethod.Invoke(new InvokeTestsGeneric <string>(), new object[] { "world" });
                if (result != "Hello world System.String")
                {
                    throw new Exception();
                }
            }

            {
                MethodInfo helloGenericMethod = typeof(InvokeTestsGeneric <string>).GetTypeInfo().GetDeclaredMethod("GetHelloGeneric").MakeGenericMethod(typeof(object));
                string     result             = (string)helloGenericMethod.Invoke(new InvokeTestsGeneric <string>(), new object[] { "world" });
                if (result != "Hello world System.Object")
                {
                    throw new Exception();
                }
            }

            {
                MethodInfo helloMethod = typeof(InvokeTestsGeneric <int>).GetTypeInfo().GetDeclaredMethod("GetHello");
                string     result      = (string)helloMethod.Invoke(new InvokeTestsGeneric <int>(), new object[] { "world" });
                if (result != "Hello world System.Int32")
                {
                    throw new Exception();
                }
            }

            {
                MethodInfo helloGenericMethod = typeof(InvokeTestsGeneric <int>).GetTypeInfo().GetDeclaredMethod("GetHelloGeneric").MakeGenericMethod(typeof(double));
                string     result             = (string)helloGenericMethod.Invoke(new InvokeTestsGeneric <int>(), new object[] { 1.0 });
                if (result != "Hello 1 System.Double")
                {
                    throw new Exception();
                }
            }
#endif
        }