示例#1
0
        private unsafe static void ToStringDouble()
        {
            int size = Unsafe.SizeOf <Vector64 <Double> >() / sizeof(Double);

            Double[] values = new Double[size];

            for (int i = 0; i < size; i++)
            {
                values[i] = TestLibrary.Generator.GetDouble();
            }

            Vector64 <Double> vector = Vector64.Create(values[0]);
            string            actual = vector.ToString();

            string expected = '<' + string.Join(", ", values.Select(x => x.ToString("G", System.Globalization.CultureInfo.InvariantCulture))) + '>';

            bool succeeded = string.Equals(expected, actual, StringComparison.Ordinal);

            if (!succeeded)
            {
                TestLibrary.TestFramework.LogInformation($"Vector64DoubleToString: Vector64<Double>.ToString() returned an unexpected result.");
                TestLibrary.TestFramework.LogInformation($"Expected: {expected}");
                TestLibrary.TestFramework.LogInformation($"Actual: {actual}");
                TestLibrary.TestFramework.LogInformation(string.Empty);

                throw new Exception("One or more scenarios did not complete as expected.");
            }
        }
        public void RunReflectionScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

            SByte[] values = new SByte[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetSByte();
            }

            Vector64 <SByte> value = Vector64.Create(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7]);

            object result = typeof(Vector64)
                            .GetMethod(nameof(Vector64.ToVector128))
                            .MakeGenericMethod(typeof(SByte))
                            .Invoke(null, new object[] { value });

            ValidateResult((Vector128 <SByte>)(result), values, isUnsafe: false);

            object unsafeResult = typeof(Vector64)
                                  .GetMethod(nameof(Vector64.ToVector128))
                                  .MakeGenericMethod(typeof(SByte))
                                  .Invoke(null, new object[] { value });

            ValidateResult((Vector128 <SByte>)(unsafeResult), values, isUnsafe: true);
        }
示例#3
0
        public void RunReflectionScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

            Single[] values = new Single[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetSingle();
            }

            Vector64 <Single> value = Vector64.Create(values[0], values[1]);

            object result = typeof(Vector64 <Single>)
                            .GetMethod(nameof(Vector64 <Single> .ToVector128), new Type[] { })
                            .Invoke(value, new object[] { });

            ValidateResult((Vector128 <Single>)(result), values, isUnsafe: false);

            object unsafeResult = typeof(Vector64 <Single>)
                                  .GetMethod(nameof(Vector64 <Single> .ToVector128), new Type[] { })
                                  .Invoke(value, new object[] { });

            ValidateResult((Vector128 <Single>)(unsafeResult), values, isUnsafe: true);
        }
示例#4
0
        public void Vector64Int32IndexerTest(params int[] values)
        {
            var vector = Vector64.Create(values);

            Assert.Equal(vector[0], values[0]);
            Assert.Equal(vector[1], values[1]);
        }
示例#5
0
    static bool CheckVector64()
    {
        var v = new Vector64 <float> [4, 4, 4];
        var e = Vector64.Create(33f);

        v[1, 2, 3] = e;
        return(UseArrayElementAsCallArgument(v, e));
    }
示例#6
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            UInt64            value  = TestLibrary.Generator.GetUInt64();
            Vector64 <UInt64> result = Vector64.Create(value);

            ValidateResult(result, value);
        }
示例#7
0
        public static short Vector64_Create_short(short a)
        {
            Vector64 <short> x = default;

            for (int i = 0; i < 1; i++)
            {
                x = Vector64.Create(1, 2, 3, Inline(a));
            }
            return(x.GetElement(3));
        }
示例#8
0
        public void RunGenericScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunGenericScenario));
            Vector64 <UInt16> value;

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <byte> byteResult = value.As <UInt16, byte>();

            ValidateResult(byteResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <double> doubleResult = value.As <UInt16, double>();

            ValidateResult(doubleResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <short> shortResult = value.As <UInt16, short>();

            ValidateResult(shortResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <int> intResult = value.As <UInt16, int>();

            ValidateResult(intResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <long> longResult = value.As <UInt16, long>();

            ValidateResult(longResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <sbyte> sbyteResult = value.As <UInt16, sbyte>();

            ValidateResult(sbyteResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <float> floatResult = value.As <UInt16, float>();

            ValidateResult(floatResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <ushort> ushortResult = value.As <UInt16, ushort>();

            ValidateResult(ushortResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <uint> uintResult = value.As <UInt16, uint>();

            ValidateResult(uintResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <ulong> ulongResult = value.As <UInt16, ulong>();

            ValidateResult(ulongResult, value);
        }
示例#9
0
        public void RunBasicScenario(int imm = 0, bool expectedOutOfRangeException = false)
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            UInt32[] values = new UInt32[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetUInt32();
            }

            Vector64 <UInt32> value = Vector64.Create(values[0], values[1]);

            bool succeeded = !expectedOutOfRangeException;

            try
            {
                UInt32 result = value.GetElement(imm);
                ValidateGetResult(result, values);
            }
            catch (ArgumentOutOfRangeException)
            {
                succeeded = expectedOutOfRangeException;
            }

            if (!succeeded)
            {
                Succeeded = false;

                TestLibrary.TestFramework.LogInformation($"Vector64<UInt32.GetElement({imm}): {nameof(RunBasicScenario)} failed to throw ArgumentOutOfRangeException.");
                TestLibrary.TestFramework.LogInformation(string.Empty);
            }

            succeeded = !expectedOutOfRangeException;

            UInt32 insertedValue = TestLibrary.Generator.GetUInt32();

            try
            {
                Vector64 <UInt32> result2 = value.WithElement(imm, insertedValue);
                ValidateWithResult(result2, values, insertedValue);
            }
            catch (ArgumentOutOfRangeException)
            {
                succeeded = expectedOutOfRangeException;
            }

            if (!succeeded)
            {
                Succeeded = false;

                TestLibrary.TestFramework.LogInformation($"Vector64<UInt32.WithElement({imm}): {nameof(RunBasicScenario)} failed to throw ArgumentOutOfRangeException.");
                TestLibrary.TestFramework.LogInformation(string.Empty);
            }
        }
示例#10
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));
            Vector64 <UInt16> value;

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <byte> byteResult = value.AsByte();

            ValidateResult(byteResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <double> doubleResult = value.AsDouble();

            ValidateResult(doubleResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <short> shortResult = value.AsInt16();

            ValidateResult(shortResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <int> intResult = value.AsInt32();

            ValidateResult(intResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <long> longResult = value.AsInt64();

            ValidateResult(longResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <sbyte> sbyteResult = value.AsSByte();

            ValidateResult(sbyteResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <float> floatResult = value.AsSingle();

            ValidateResult(floatResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <ushort> ushortResult = value.AsUInt16();

            ValidateResult(ushortResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <uint> uintResult = value.AsUInt32();

            ValidateResult(uintResult, value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            Vector64 <ulong> ulongResult = value.AsUInt64();

            ValidateResult(ulongResult, value);
        }
示例#11
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            Double            lowerValue = TestLibrary.Generator.GetDouble();
            Vector64 <Double> lower      = Vector64.Create(lowerValue);

            Double            upperValue = TestLibrary.Generator.GetDouble();
            Vector64 <Double> upper      = Vector64.Create(upperValue);

            Vector128 <Double> result = Vector128.Create(lower, upper);

            ValidateResult(result, lowerValue, upperValue);
        }
示例#12
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            Int32            lowerValue = TestLibrary.Generator.GetInt32();
            Vector64 <Int32> lower      = Vector64.Create(lowerValue);

            Int32            upperValue = TestLibrary.Generator.GetInt32();
            Vector64 <Int32> upper      = Vector64.Create(upperValue);

            Vector128 <Int32> result = Vector128.Create(lower, upper);

            ValidateResult(result, lowerValue, upperValue);
        }
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            Int16[] values = new Int16[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetInt16();
            }

            Vector64 <Int16> result = Vector64.Create(values[0], values[1], values[2], values[3]);

            ValidateResult(result, values);
        }
示例#14
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            SByte[] values = new SByte[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetSByte();
            }

            Vector64 <SByte> result = Vector64.Create(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7]);

            ValidateResult(result, values);
        }
示例#15
0
    public static int Main()
    {
        Test(Vector128.Create(0));
        Test(Vector128.Create(0.0f));
        Test(Vector128.Create(-0.0f));
        Test(Vector128.Create(0.0));
        Test(Vector128.Create(-0.0));

        TestReversed(Vector128.Create(0));
        TestReversed(Vector128.Create(0.0f));
        TestReversed(Vector128.Create(-0.0f));
        TestReversed(Vector128.Create(0.0));
        TestReversed(Vector128.Create(-0.0));

        Test(Vector128.Create(-10));
        Test(Vector128.Create(10));
        Test(Vector128.Create((sbyte)-10));
        Test(Vector128.Create((ushort)10));
        Test(Vector64.Create(0));
        Test(Vector64.Create(0.0f));
        Test(Vector64.Create(-0.0f));
        Test(Vector64.Create(0.0));
        Test(Vector64.Create(-0.0));
        Test(Vector64.Create(-10));
        Test(Vector64.Create(10));
        Test(Vector64.Create((sbyte)-10));
        Test(Vector64.Create((ushort)10));
        Test(Vector128.Create(0, 0, 0, 0, 0, 0, 0, 1));
        Test(Vector128.Create(0, 0, 0, 0, 0, 0, 0, -1));
        Test(Vector64.Create(0, 0, 0, 0, 0, 0, 0, 1));
        Test(Vector64.Create(0, 0, 0, 0, 0, 0, 0, -1));

        Test(Vector128.Create(0, 0, 0, 0, 0, 0, 1, 0));
        Test(Vector128.Create(0, 0, 0, 0, 0, 0, 1, 0));
        Test(Vector64.Create(0, 0, 0, 0, 0, 0, -1, 0));
        Test(Vector64.Create(0, 0, 0, 0, 0, 0, -1, 0));

        Test(Vector128.Create(0, 0, 0, 1, 0, 0, 0, 1));
        Test(Vector128.Create(0, 0, 0, -1, 0, 0, 0, -1));
        Test(Vector64.Create(0, 0, 0, 1, 0, 0, 0, 1));
        Test(Vector64.Create(0, 0, 0, -1, 0, 0, 0, -1));

        TestReversed(Vector128.Create(0, 0, 0, 1, 0, 0, 0, 1));
        TestReversed(Vector128.Create(0, 0, 0, -1, 0, 0, 0, -1));
        TestReversed(Vector64.Create(0, 0, 0, 1, 0, 0, 0, 1));
        TestReversed(Vector64.Create(0, 0, 0, -1, 0, 0, 0, -1));
        return(100);
    }
示例#16
0
        public void RunReflectionScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

            Int32            lowerValue = TestLibrary.Generator.GetInt32();
            Vector64 <Int32> lower      = Vector64.Create(lowerValue);

            Int32            upperValue = TestLibrary.Generator.GetInt32();
            Vector64 <Int32> upper      = Vector64.Create(upperValue);

            object result = typeof(Vector128)
                            .GetMethod(nameof(Vector128.Create), new Type[] { typeof(Vector64 <Int32>), typeof(Vector64 <Int32>) })
                            .Invoke(null, new object[] { lower, upper });

            ValidateResult((Vector128 <Int32>)(result), lowerValue, upperValue);
        }
示例#17
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            Int64[] values = new Int64[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetInt64();
            }

            Vector64 <Int64> value = Vector64.Create(values[0]);

            Int64 result = value.ToScalar();

            ValidateResult(result, values);
        }
示例#18
0
        public void RunReflectionScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

            Int64[] values = new Int64[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetInt64();
            }

            Vector64 <Int64> value = Vector64.Create(values[0]);

            object result = typeof(Vector64 <Int64>)
                            .GetMethod(nameof(Vector64 <Int64> .ToScalar), new Type[] { })
                            .Invoke(value, new object[] { });

            ValidateResult((Int64)(result), values);
        }
示例#19
0
        public void RunReflectionScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

            Byte[] values = new Byte[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetByte();
            }

            Vector64 <Byte> value = Vector64.Create(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7]);

            object result = typeof(Vector64 <Byte>)
                            .GetMethod(nameof(Vector64.ToScalar), new Type[] { })
                            .Invoke(value, new object[] { });

            ValidateResult((Byte)(result), values);
        }
示例#20
0
        public void RunReflectionScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

            UInt32[] values = new UInt32[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetUInt32();
            }

            Vector64 <UInt32> value = Vector64.Create(values[0], values[1]);

            object result = typeof(Vector64)
                            .GetMethod(nameof(Vector64.ToScalar))
                            .MakeGenericMethod(typeof(UInt32))
                            .Invoke(null, new object[] { value });

            ValidateResult((UInt32)(result), values);
        }
示例#21
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            Int64[] values = new Int64[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetInt64();
            }

            Vector64 <Int64> value = Vector64.Create(values[0]);

            Vector128 <Int64> result = value.ToVector128();

            ValidateResult(result, values, isUnsafe: false);

            Vector128 <Int64> unsafeResult = value.ToVector128Unsafe();

            ValidateResult(unsafeResult, values, isUnsafe: true);
        }
示例#22
0
        public void RunBasicScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario));

            Byte[] values = new Byte[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetByte();
            }

            Vector64 <Byte> value = Vector64.Create(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7]);

            Vector128 <Byte> result = value.ToVector128();

            ValidateResult(result, values, isUnsafe: false);

            Vector128 <Byte> unsafeResult = value.ToVector128Unsafe();

            ValidateResult(unsafeResult, values, isUnsafe: true);
        }
示例#23
0
        public static int PopCount(uint value)
        {
            if (Popcnt.IsSupported)
            {
                return((int)Popcnt.PopCount(value));
            }

            if (AdvSimd.Arm64.IsSupported)
            {
                // PopCount works on vector so convert input value to vector first.

                // Vector64.CreateScalar(uint) generates suboptimal code by storing and
                // loading the result to memory.
                // See https://github.com/dotnet/runtime/issues/35976 for details.
                // Hence use Vector64.Create(ulong) to create Vector64<ulong> and operate on that.
                Vector64 <ulong> input      = Vector64.Create((ulong)value);
                Vector64 <byte>  aggregated = AdvSimd.Arm64.AddAcross(AdvSimd.PopCount(input.AsByte()));
                return(aggregated.ToScalar());
            }

            return(SoftwareFallback(value));
示例#24
0
    public static void TestVector64()
    {
        // Test get_Zero() optimization:
        Assert("<0, 0, 0, 0, 0, 0, 0, 0>", Vector64.Create(0, 0, 0, 0, 0, 0, 0, 0).ToString());
        Assert("<0, 0, 0, 0, 0, 0, 0, 1>", Vector64.Create(0, 0, 0, 0, 0, 0, 0, 1).ToString());
        Assert("<0, 0, 0, 0, 1, 1, 1, 1>", Vector64.Create(0, 0, 0, 0, 1, 1, 1, 1).ToString());
        Assert("<0, 0, 0, 1, 1, 1, 1, 1>", Vector64.Create(0, 0, 0, 1, 1, 1, 1, 1).ToString());
        Assert("<0, 1, 1, 1, 1, 1, 1, 1>", Vector64.Create(0, 1, 1, 1, 1, 1, 1, 1).ToString());
        Assert("<1, 1, 1, 1, 1, 1, 1, 1>", Vector64.Create(1, 1, 1, 1, 1, 1, 1, 1).ToString());
        Assert("<1, 1, 1, 1, 0, 0, 0, 0>", Vector64.Create(1, 1, 1, 1, 0, 0, 0, 0).ToString());
        Assert("<0, 0, 0, 0>", Vector64.Create(0, 0, 0, 0).ToString());
        Assert("<0, 0, 1, 1>", Vector64.Create(0, 0, 1, 1).ToString());
        Assert("<0, 1, 1, 1>", Vector64.Create(0, 1, 1, 1).ToString());
        Assert("<1, 1, 1, 1>", Vector64.Create(1, 1, 1, 1).ToString());
        Assert("<1, 1, 0, 0>", Vector64.Create(1, 1, 0, 0).ToString());
        Assert("<0, 0>", Vector64.Create(0, 0).ToString());
        Assert("<0, 1>", Vector64.Create(0, 1).ToString());
        Assert("<1, 1>", Vector64.Create(1, 1).ToString());
        Assert("<1, 0>", Vector64.Create(1, 0).ToString());

        // Test get_AllBitSet() optimization:
        Assert("<-1, -1, -1, -1, -1, -1, -1, -1>", Vector64.Create(-1, -1, -1, -1, -1, -1, -1, -1).ToString());
        Assert("<-1, -1, -1, -1, -1, -1, -1, 1>", Vector64.Create(-1, -1, -1, -1, -1, -1, -1, 1).ToString());
        Assert("<-1, -1, -1, -1, 1, 1, 1, 1>", Vector64.Create(-1, -1, -1, -1, 1, 1, 1, 1).ToString());
        Assert("<-1, -1, -1, 1, 1, 1, 1, 1>", Vector64.Create(-1, -1, -1, 1, 1, 1, 1, 1).ToString());
        Assert("<-1, 1, 1, 1, 1, 1, 1, 1>", Vector64.Create(-1, 1, 1, 1, 1, 1, 1, 1).ToString());
        Assert("<1, 1, 1, 1, 1, 1, 1, 1>", Vector64.Create(1, 1, 1, 1, 1, 1, 1, 1).ToString());
        Assert("<1, 1, 1, 1, -1, -1, -1, -1>", Vector64.Create(1, 1, 1, 1, -1, -1, -1, -1).ToString());
        Assert("<-1, -1, -1, -1>", Vector64.Create(-1, -1, -1, -1).ToString());
        Assert("<-1, -1, 1, 1>", Vector64.Create(-1, -1, 1, 1).ToString());
        Assert("<-1, 1, 1, 1>", Vector64.Create(-1, 1, 1, 1).ToString());
        Assert("<1, 1, 1, 1>", Vector64.Create(1, 1, 1, 1).ToString());
        Assert("<1, 1, -1, -1>", Vector64.Create(1, 1, -1, -1).ToString());
        Assert("<-1, -1>", Vector64.Create(-1, -1).ToString());
        Assert("<-1, 1>", Vector64.Create(-1, 1).ToString());
        Assert("<1, -1>", Vector64.Create(1, -1).ToString());
    }
示例#25
0
 static Vector64 <float> AdvSimd_CompareEqual_Vector64_Single_CreateZeroZero(Vector64 <float> left)
 {
     return(AdvSimd.CompareEqual(left, Vector64.Create(0f, 0f)));
 }
示例#26
0
        public void RunReflectionScenario(int imm = 0, bool expectedOutOfRangeException = false)
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

            UInt32[] values = new UInt32[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetUInt32();
            }

            Vector64 <UInt32> value = Vector64.Create(values[0], values[1]);

            bool succeeded = !expectedOutOfRangeException;

            try
            {
                object result = typeof(Vector64 <UInt32>)
                                .GetMethod(nameof(Vector64 <UInt32> .GetElement), new Type[] { typeof(int) })
                                .Invoke(value, new object[] { imm });
                ValidateGetResult((UInt32)(result), values);
            }
            catch (TargetInvocationException e)
            {
                succeeded = expectedOutOfRangeException &&
                            e.InnerException is ArgumentOutOfRangeException;
            }

            if (!succeeded)
            {
                Succeeded = false;

                TestLibrary.TestFramework.LogInformation($"Vector64<UInt32.GetElement({imm}): {nameof(RunReflectionScenario)} failed to throw ArgumentOutOfRangeException.");
                TestLibrary.TestFramework.LogInformation(string.Empty);
            }

            succeeded = !expectedOutOfRangeException;

            UInt32 insertedValue = TestLibrary.Generator.GetUInt32();

            try
            {
                object result2 = typeof(Vector64 <UInt32>)
                                 .GetMethod(nameof(Vector64 <UInt32> .WithElement), new Type[] { typeof(int), typeof(UInt32) })
                                 .Invoke(value, new object[] { imm, insertedValue });
                ValidateWithResult((Vector64 <UInt32>)(result2), values, insertedValue);
            }
            catch (TargetInvocationException e)
            {
                succeeded = expectedOutOfRangeException &&
                            e.InnerException is ArgumentOutOfRangeException;
            }

            if (!succeeded)
            {
                Succeeded = false;

                TestLibrary.TestFramework.LogInformation($"Vector64<UInt32.WithElement({imm}): {nameof(RunReflectionScenario)} failed to throw ArgumentOutOfRangeException.");
                TestLibrary.TestFramework.LogInformation(string.Empty);
            }
        }
        public void RunReflectionScenario(int imm = 0, bool expectedOutOfRangeException = false)
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));

            SByte[] values = new SByte[ElementCount];

            for (int i = 0; i < ElementCount; i++)
            {
                values[i] = TestLibrary.Generator.GetSByte();
            }

            Vector64 <SByte> value = Vector64.Create(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7]);

            bool succeeded = !expectedOutOfRangeException;

            try
            {
                object result = typeof(Vector64)
                                .GetMethod(nameof(Vector64.GetElement))
                                .MakeGenericMethod(typeof(SByte))
                                .Invoke(null, new object[] { value, imm });
                ValidateGetResult((SByte)(result), values);
            }
            catch (TargetInvocationException e)
            {
                succeeded = expectedOutOfRangeException &&
                            e.InnerException is ArgumentOutOfRangeException;
            }

            if (!succeeded)
            {
                TestLibrary.TestFramework.LogInformation($"Vector64<SByte.GetElement({imm}): {nameof(RunReflectionScenario)} failed to throw ArgumentOutOfRangeException.");
                TestLibrary.TestFramework.LogInformation(string.Empty);

                Succeeded = false;
            }

            succeeded = !expectedOutOfRangeException;

            SByte insertedValue = TestLibrary.Generator.GetSByte();

            try
            {
                object result2 = typeof(Vector64)
                                 .GetMethod(nameof(Vector64.WithElement))
                                 .MakeGenericMethod(typeof(SByte))
                                 .Invoke(null, new object[] { value, imm, insertedValue });
                ValidateWithResult((Vector64 <SByte>)(result2), values, insertedValue);
            }
            catch (TargetInvocationException e)
            {
                succeeded = expectedOutOfRangeException &&
                            e.InnerException is ArgumentOutOfRangeException;
            }

            if (!succeeded)
            {
                TestLibrary.TestFramework.LogInformation($"Vector64<SByte.WithElement({imm}): {nameof(RunReflectionScenario)} failed to throw ArgumentOutOfRangeException.");
                TestLibrary.TestFramework.LogInformation(string.Empty);

                Succeeded = false;
            }
        }
示例#28
0
    static int Tests_AdvSimd()
    {
        var result = 100;

        // Begin CompareEqual Tests

        // Vector64

        if (!ValidateResult_Vector64 <byte>(AdvSimd_CompareEqual_Vector64_Byte_Zero(Vector64 <byte> .Zero), Byte.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <sbyte>(AdvSimd_CompareEqual_Vector64_SByte_Zero(Vector64 <sbyte> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <ushort>(AdvSimd_CompareEqual_Vector64_UInt16_Zero(Vector64 <ushort> .Zero), UInt16.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <short>(AdvSimd_CompareEqual_Vector64_Int16_Zero(Vector64 <short> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <uint>(AdvSimd_CompareEqual_Vector64_UInt32_Zero(Vector64 <uint> .Zero), UInt32.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <int>(AdvSimd_CompareEqual_Vector64_Int32_Zero(Vector64 <int> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <float>(AdvSimd_CompareEqual_Vector64_Single_Zero(Vector64 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        // Vector64.Create

        if (!ValidateResult_Vector64 <int>(AdvSimd_CompareEqual_Vector64_Int32_CreateZero(Vector64 <int> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <float>(AdvSimd_CompareEqual_Vector64_Single_CreateZero(Vector64 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <int>(AdvSimd_CompareEqual_Vector64_Int32_CreateZeroZero(Vector64 <int> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <float>(AdvSimd_CompareEqual_Vector64_Single_CreateZeroZero(Vector64 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        // Vector128

        if (!ValidateResult_Vector128 <byte>(AdvSimd_CompareEqual_Vector128_Byte_Zero(Vector128 <byte> .Zero), Byte.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <sbyte>(AdvSimd_CompareEqual_Vector128_SByte_Zero(Vector128 <sbyte> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <ushort>(AdvSimd_CompareEqual_Vector128_UInt16_Zero(Vector128 <ushort> .Zero), UInt16.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <short>(AdvSimd_CompareEqual_Vector128_Int16_Zero(Vector128 <short> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <uint>(AdvSimd_CompareEqual_Vector128_UInt32_Zero(Vector128 <uint> .Zero), UInt32.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <int>(AdvSimd_CompareEqual_Vector128_Int32_Zero(Vector128 <int> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <float>(AdvSimd_CompareEqual_Vector128_Single_Zero(Vector128 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        // Vector128.Create

        if (!ValidateResult_Vector128 <int>(AdvSimd_CompareEqual_Vector128_Int32_CreateZero(Vector128 <int> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <float>(AdvSimd_CompareEqual_Vector128_Single_CreateZero(Vector128 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <int>(AdvSimd_CompareEqual_Vector128_Int32_CreateZeroZeroZeroZero(Vector128 <int> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <float>(AdvSimd_CompareEqual_Vector128_Single_CreateZeroZeroZeroZero(Vector128 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <float>(AdvSimd_CompareEqual_Vector128_Single_CreateZeroZeroZeroZero_AsVariable(Vector128 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <float>(AdvSimd_CompareEqual_Vector128_Single_CreateZeroZeroZeroZero_AsVariableLoop(Vector128 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        // End CompareEqual Tests

        // Begin CompareGreaterThan Tests

        if (!ValidateResult_Vector64 <byte>(AdvSimd_CompareGreaterThan_Vector64_Byte_Zero(Vector64.Create((byte)1)), Byte.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <float>(AdvSimd_CompareGreaterThan_Vector64_Single_Zero(Vector64.Create(1.0f)), Single.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <byte>(AdvSimd_CompareGreaterThan_Vector128_Byte_Zero(Vector128.Create((byte)1)), Byte.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <float>(AdvSimd_CompareGreaterThan_Vector128_Single_Zero(Vector128.Create(1.0f)), Single.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <double>(AdvSimd_Arm64_CompareGreaterThan_Vector128_Double_Zero(Vector128.Create(1.0)), Double.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <long>(AdvSimd_Arm64_CompareGreaterThan_Vector128_Int64_Zero(Vector128.Create(1L)), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <double>(AdvSimd_Arm64_CompareGreaterThanScalar_Vector64_Double_Zero(Vector64.Create(1.0)), Double.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <long>(AdvSimd_Arm64_CompareGreaterThanScalar_Vector64_Int64_Zero(Vector64.Create(1L)), -1))
        {
            result = -1;
        }

        if (ValidateResult_Vector64 <byte>(AdvSimd_CompareGreaterThan_Vector64_Byte_Zero(Vector64 <byte> .Zero), Byte.MaxValue))
        {
            result = -1;
        }

        if (ValidateResult_Vector64 <float>(AdvSimd_CompareGreaterThan_Vector64_Single_Zero(Vector64 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        if (ValidateResult_Vector128 <byte>(AdvSimd_CompareGreaterThan_Vector128_Byte_Zero(Vector128 <byte> .Zero), Byte.MaxValue))
        {
            result = -1;
        }

        if (ValidateResult_Vector128 <float>(AdvSimd_CompareGreaterThan_Vector128_Single_Zero(Vector128 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        if (ValidateResult_Vector128 <double>(AdvSimd_Arm64_CompareGreaterThan_Vector128_Double_Zero(Vector128 <double> .Zero), Double.NaN))
        {
            result = -1;
        }

        if (ValidateResult_Vector128 <long>(AdvSimd_Arm64_CompareGreaterThan_Vector128_Int64_Zero(Vector128 <long> .Zero), -1))
        {
            result = -1;
        }

        if (ValidateResult_Vector64 <double>(AdvSimd_Arm64_CompareGreaterThanScalar_Vector64_Double_Zero(Vector64 <double> .Zero), Double.NaN))
        {
            result = -1;
        }

        if (ValidateResult_Vector64 <long>(AdvSimd_Arm64_CompareGreaterThanScalar_Vector64_Int64_Zero(Vector64 <long> .Zero), -1))
        {
            result = -1;
        }

        // End CompareGreaterThan Tests

        // Begin CompareGreaterThanOrEqual Tests

        if (!ValidateResult_Vector64 <byte>(AdvSimd_CompareGreaterThanOrEqual_Vector64_Byte_Zero(Vector64.Create((byte)1)), Byte.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <float>(AdvSimd_CompareGreaterThanOrEqual_Vector64_Single_Zero(Vector64.Create(1.0f)), Single.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <byte>(AdvSimd_CompareGreaterThanOrEqual_Vector128_Byte_Zero(Vector128.Create((byte)1)), Byte.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <float>(AdvSimd_CompareGreaterThanOrEqual_Vector128_Single_Zero(Vector128.Create(1.0f)), Single.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <double>(AdvSimd_Arm64_CompareGreaterThanOrEqual_Vector128_Double_Zero(Vector128.Create(1.0)), Double.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <long>(AdvSimd_Arm64_CompareGreaterThanOrEqual_Vector128_Int64_Zero(Vector128.Create(1L)), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <double>(AdvSimd_Arm64_CompareGreaterThanOrEqualScalar_Vector64_Double_Zero(Vector64.Create(1.0)), Double.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <long>(AdvSimd_Arm64_CompareGreaterThanOrEqualScalar_Vector64_Int64_Zero(Vector64.Create(1L)), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <byte>(AdvSimd_CompareGreaterThanOrEqual_Vector64_Byte_Zero(Vector64 <byte> .Zero), Byte.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <float>(AdvSimd_CompareGreaterThanOrEqual_Vector64_Single_Zero(Vector64 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <byte>(AdvSimd_CompareGreaterThanOrEqual_Vector128_Byte_Zero(Vector128 <byte> .Zero), Byte.MaxValue))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <float>(AdvSimd_CompareGreaterThanOrEqual_Vector128_Single_Zero(Vector128 <float> .Zero), Single.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <double>(AdvSimd_Arm64_CompareGreaterThanOrEqual_Vector128_Double_Zero(Vector128 <double> .Zero), Double.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector128 <long>(AdvSimd_Arm64_CompareGreaterThanOrEqual_Vector128_Int64_Zero(Vector128 <long> .Zero), -1))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <double>(AdvSimd_Arm64_CompareGreaterThanOrEqualScalar_Vector64_Double_Zero(Vector64 <double> .Zero), Double.NaN))
        {
            result = -1;
        }

        if (!ValidateResult_Vector64 <long>(AdvSimd_Arm64_CompareGreaterThanOrEqualScalar_Vector64_Int64_Zero(Vector64 <long> .Zero), -1))
        {
            result = -1;
        }

        // End CompareGreaterThanOrEqual Tests

        return(result);
    }
示例#29
0
 static Vector64 <int> AdvSimd_CompareEqual_Vector64_Int32_CreateZeroZero(Vector64 <int> left)
 {
     return(AdvSimd.CompareEqual(left, Vector64.Create(0, 0)));
 }
示例#30
0
        public void RunReflectionScenario()
        {
            TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario));
            Vector64 <UInt16> value;

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            object byteResult = typeof(Vector64)
                                .GetMethod(nameof(Vector64.AsByte))
                                .MakeGenericMethod(typeof(UInt16))
                                .Invoke(null, new object[] { value });

            ValidateResult((Vector64 <byte>)(byteResult), value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            object doubleResult = typeof(Vector64)
                                  .GetMethod(nameof(Vector64.AsDouble))
                                  .MakeGenericMethod(typeof(UInt16))
                                  .Invoke(null, new object[] { value });

            ValidateResult((Vector64 <double>)(doubleResult), value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            object shortResult = typeof(Vector64)
                                 .GetMethod(nameof(Vector64.AsInt16))
                                 .MakeGenericMethod(typeof(UInt16))
                                 .Invoke(null, new object[] { value });

            ValidateResult((Vector64 <short>)(shortResult), value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            object intResult = typeof(Vector64)
                               .GetMethod(nameof(Vector64.AsInt32))
                               .MakeGenericMethod(typeof(UInt16))
                               .Invoke(null, new object[] { value });

            ValidateResult((Vector64 <int>)(intResult), value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            object longResult = typeof(Vector64)
                                .GetMethod(nameof(Vector64.AsInt64))
                                .MakeGenericMethod(typeof(UInt16))
                                .Invoke(null, new object[] { value });

            ValidateResult((Vector64 <long>)(longResult), value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            object sbyteResult = typeof(Vector64)
                                 .GetMethod(nameof(Vector64.AsSByte))
                                 .MakeGenericMethod(typeof(UInt16))
                                 .Invoke(null, new object[] { value });

            ValidateResult((Vector64 <sbyte>)(sbyteResult), value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            object floatResult = typeof(Vector64)
                                 .GetMethod(nameof(Vector64.AsSingle))
                                 .MakeGenericMethod(typeof(UInt16))
                                 .Invoke(null, new object[] { value });

            ValidateResult((Vector64 <float>)(floatResult), value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            object ushortResult = typeof(Vector64)
                                  .GetMethod(nameof(Vector64.AsUInt16))
                                  .MakeGenericMethod(typeof(UInt16))
                                  .Invoke(null, new object[] { value });

            ValidateResult((Vector64 <ushort>)(ushortResult), value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            object uintResult = typeof(Vector64)
                                .GetMethod(nameof(Vector64.AsUInt32))
                                .MakeGenericMethod(typeof(UInt16))
                                .Invoke(null, new object[] { value });

            ValidateResult((Vector64 <uint>)(uintResult), value);

            value = Vector64.Create(TestLibrary.Generator.GetUInt16());
            object ulongResult = typeof(Vector64)
                                 .GetMethod(nameof(Vector64.AsUInt64))
                                 .MakeGenericMethod(typeof(UInt16))
                                 .Invoke(null, new object[] { value });

            ValidateResult((Vector64 <ulong>)(ulongResult), value);
        }