summaryrefslogtreecommitdiff
path: root/tests/src/JIT/SIMD/VectorRelOp.cs
blob: 70342f3e7a7b2ca494778da7b286fa273998588f (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// 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 VectorRelopTest<T> where T : struct, IComparable<T>, IEquatable<T>
    {
        public static int VectorRelOp(T larger, T smaller)
        {
            const int Pass = 100;
            const int Fail = -1;
            int returnVal = Pass;

            Vector<T> A = new Vector<T>(larger);
            Vector<T> B = new Vector<T>(smaller);
            Vector<T> C = new Vector<T>(larger);
            Vector<T> D;

            // less than
            Vector<T> condition = Vector.LessThan<T>(A, B);
            D = Vector.ConditionalSelect(condition, A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!D[i].Equals(B[i]))
                {
                    Console.WriteLine("Less than condition failed for type " + typeof(T).Name + " at index " + i);
                    returnVal = Fail;
                }
            }
            condition = Vector.LessThan<T>(B, A);
            D = Vector.ConditionalSelect(condition, A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!D[i].Equals(A[i]))
                {
                    Console.WriteLine("Less than condition failed for type " + typeof(T).Name + " at index " + i);
                    returnVal = Fail;
                }
            }

            // greater than
            condition = Vector.GreaterThan<T>(A, B);
            D = Vector.ConditionalSelect(condition, A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!D[i].Equals(A[i]))
                {
                    Console.WriteLine("Greater than condition failed for type " + typeof(T).Name + " at index " + i);
                    returnVal = Fail;
                }
            }

            condition = Vector.GreaterThan<T>(B, A);
            D = Vector.ConditionalSelect(condition, A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!D[i].Equals(B[i]))
                {
                    Console.WriteLine("Greater than condition failed for type " + typeof(T).Name + " at index " + i);
                    returnVal = Fail;
                }
            }

            // less than or equal
            condition = Vector.LessThanOrEqual<T>(A, C);
            D = Vector.ConditionalSelect(condition, A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!D[i].Equals(A[i]))
                {
                    Console.WriteLine("Less than or equal condition failed for type " + typeof(T).Name + " at index " + i);
                    returnVal = Fail;
                }
            }

            condition = Vector.LessThanOrEqual<T>(A, B);
            D = Vector.ConditionalSelect(condition, A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!D[i].Equals(B[i]))
                {
                    Console.WriteLine("Less than or equal condition failed for type " + typeof(T).Name + " at index " + i);
                    returnVal = Fail;
                }
            }

            // greater than or equal
            condition = Vector.GreaterThanOrEqual<T>(A, C);
            D = Vector.ConditionalSelect(condition, A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!D[i].Equals(A[i]))
                {
                    Console.WriteLine("Greater than or equal condition failed for type " + typeof(T).Name + " at index " + i);
                    returnVal = Fail;
                }
            }

            condition = Vector.GreaterThanOrEqual<T>(B, C);
            D = Vector.ConditionalSelect(condition, A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!D[i].Equals(B[i]))
                {
                    Console.WriteLine("Greater than or equal condition failed for type " + typeof(T).Name + " at index " + i);
                    returnVal = Fail;
                }
            }

            // equal
            condition = Vector.Equals<T>(A, C);
            D = Vector.ConditionalSelect(condition, A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!D[i].Equals(A[i]))
                {
                    Console.WriteLine("Equal condition failed for type " + typeof(T).Name + " at index " + i);
                    returnVal = Fail;
                }
            }

            condition = Vector.Equals<T>(B, C);
            D = Vector.ConditionalSelect(condition, A, B);
            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!D[i].Equals(B[i]))
                {
                    Console.WriteLine("Equal condition failed for type " + typeof(T).Name + " at index " + i);
                    returnVal = Fail;
                }
            }

            return returnVal;
        }
    }

    private static int Main()
    {
        int returnVal = Pass;
        if (VectorRelopTest<float>.VectorRelOp(3, 2) != Pass) returnVal = Fail;
        if (VectorRelopTest<double>.VectorRelOp(3, 2) != Pass) returnVal = Fail;
        if (VectorRelopTest<int>.VectorRelOp(3, 2) != Pass) returnVal = Fail;
        if (VectorRelopTest<long>.VectorRelOp(3, 2) != Pass) returnVal = Fail;
        if (VectorRelopTest<ushort>.VectorRelOp(3, 2) != Pass) returnVal = Fail;
        if (VectorRelopTest<byte>.VectorRelOp(3, 2) != Pass) returnVal = Fail;
        if (VectorRelopTest<short>.VectorRelOp(-2, -3) != Pass) returnVal = Fail;
        if (VectorRelopTest<sbyte>.VectorRelOp(-2, -3) != Pass) returnVal = Fail;
        if (VectorRelopTest<uint>.VectorRelOp(3u, 2u) != Pass) returnVal = Fail;
        if (VectorRelopTest<ulong>.VectorRelOp(3ul, 2ul) != Pass) returnVal = Fail;
        return returnVal;
    }
}