summaryrefslogtreecommitdiff
path: root/tests/src/JIT/SIMD/VectorMin.cs
blob: 4a9fd90038bdf714578cfc72d600110588876714 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//

using System;
using System.Numerics;

internal partial class VectorTest
{
    private const int Pass = 100;
    private const int Fail = -1;

    private class VectorMinTest<T> where T : struct, IComparable<T>, IEquatable<T>
    {
        public static int VectorMin(T left, T right, T result)
        {
            Vector<T> A = new Vector<T>(left);
            Vector<T> B = new Vector<T>(right);

            Vector<T> C = Vector.Min<T>(A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!(CheckValue<T>(C[i], result)))
                {
                    return Fail;
                }
            }
            return Pass;
        }
    }
    private class Vector4Test
    {
        public static int VectorMin(float left, float right, float result)
        {
            Vector4 A = new Vector4(left);
            Vector4 B = new Vector4(right);
            Vector4 C = Vector4.Min(A, B);
            if (!(CheckValue<float>(C.X, result))) return Fail;
            if (!(CheckValue<float>(C.Y, result))) return Fail;
            if (!(CheckValue<float>(C.Z, result))) return Fail;
            if (!(CheckValue<float>(C.W, result))) return Fail;
            return Pass;
        }
    }

    private class Vector3Test
    {
        public static int VectorMin(float left, float right, float result)
        {
            Vector3 A = new Vector3(left);
            Vector3 B = new Vector3(right);
            Vector3 C = Vector3.Min(A, B);
            if (!(CheckValue<float>(C.X, result))) return Fail;
            if (!(CheckValue<float>(C.Y, result))) return Fail;
            if (!(CheckValue<float>(C.Z, result))) return Fail;
            return Pass;
        }
    }

    private class Vector2Test
    {
        public static int VectorMin(float left, float right, float result)
        {
            Vector2 A = new Vector2(left);
            Vector2 B = new Vector2(right);
            Vector2 C = Vector2.Min(A, B);
            if (!(CheckValue<float>(C.X, result))) return Fail;
            if (!(CheckValue<float>(C.Y, result))) return Fail;
            return Pass;
        }
    }

    private static int Main()
    {
        int returnVal = Pass;
        if (VectorMinTest<float>.VectorMin(2f, 3f, 2f) != Pass) returnVal = Fail;
        if (VectorMinTest<double>.VectorMin(2d, 3d, 2d) != Pass) returnVal = Fail;
        if (VectorMinTest<int>.VectorMin(2, 3, 2) != Pass) returnVal = Fail;
        if (VectorMinTest<long>.VectorMin(2, 3, 2) != Pass) returnVal = Fail;
        if (Vector4Test.VectorMin(2f, 3f, 2f) != Pass) returnVal = Fail;
        if (Vector3Test.VectorMin(2f, 3f, 2f) != Pass) returnVal = Fail;
        if (Vector2Test.VectorMin(2f, 3f, 2f) != Pass) returnVal = Fail;
        if (VectorMinTest<ushort>.VectorMin(2, 3, 2) != Pass) returnVal = Fail;
        if (VectorMinTest<byte>.VectorMin(2, 3, 2) != Pass) returnVal = Fail;
        if (VectorMinTest<short>.VectorMin(-2, -3, -3) != Pass) returnVal = Fail;
        if (VectorMinTest<sbyte>.VectorMin(-2, 3, -2) != Pass) returnVal = Fail;
        if (VectorMinTest<uint>.VectorMin(0x80000000u, 0x40000000u, 0x40000000u) != Pass) returnVal = Fail;
        if (VectorMinTest<ulong>.VectorMin(2ul, 3ul, 2ul) != Pass) returnVal = Fail;

        JitLog jitLog = new JitLog();
        if (!jitLog.Check("Min", "Single")) returnVal = Fail;
        if (!jitLog.Check("Min", "Double")) returnVal = Fail;
        if (!jitLog.Check("Min", "Int32")) returnVal = Fail;
        if (!jitLog.Check("Min", "Int64")) returnVal = Fail;
        if (!jitLog.Check("System.Numerics.Vector4:Min")) returnVal = Fail;
        if (!jitLog.Check("System.Numerics.Vector3:Min")) returnVal = Fail;
        if (!jitLog.Check("System.Numerics.Vector2:Min")) returnVal = Fail;
        if (!jitLog.Check("Min", "UInt16")) returnVal = Fail;
        if (!jitLog.Check("Min", "Byte")) returnVal = Fail;
        if (!jitLog.Check("Min", "Int16")) returnVal = Fail;
        if (!jitLog.Check("Min", "SByte")) returnVal = Fail;
        if (!jitLog.Check("Min", "UInt32")) returnVal = Fail;
        if (!jitLog.Check("Min", "UInt64")) returnVal = Fail;
        jitLog.Dispose();

        return returnVal;
    }
}