summaryrefslogtreecommitdiff
path: root/tests/src/JIT/SIMD/VectorAbs.cs
blob: 6a8233cb9b8e3bd7248b88fc721598f8fca7046d (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
// 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 VectorAbsTest<T> where T : struct, IComparable<T>, IEquatable<T>
    {
        public static int VectorAbs(T value, T checkValue)
        {
            Vector<T> A = new Vector<T>(value);
            Vector<T> B = Vector.Abs<T>(A);

            for (int i = 0; i < Vector<T>.Count; i++)
            {
                if (!(CheckValue<T>(B[i], checkValue)))
                {
                    return Fail;
                }
            }
            return Pass;
        }
    }

    private class Vector4Test
    {
        public static int VectorAbs()
        {
            Vector4 A = new Vector4(-1f);
            Vector4 B = Vector4.Abs(A);
            if (!(CheckValue<float>(B.X, 1f))) return Fail;
            if (!(CheckValue<float>(B.Y, 1f))) return Fail;
            if (!(CheckValue<float>(B.Z, 1f))) return Fail;
            if (!(CheckValue<float>(B.W, 1f))) return Fail;
            return Pass;
        }
    }

    private class Vector3Test
    {
        public static int VectorAbs()
        {
            Vector3 A = new Vector3(-1f);
            Vector3 B = Vector3.Abs(A);
            if (!(CheckValue<float>(B.X, 1f))) return Fail;
            if (!(CheckValue<float>(B.Y, 1f))) return Fail;
            if (!(CheckValue<float>(B.Z, 1f))) return Fail;
            return Pass;
        }
    }

    private class Vector2Test
    {
        public static int VectorAbs()
        {
            Vector2 A = new Vector2(-1f);
            Vector2 B = Vector2.Abs(A);
            if (!(CheckValue<float>(B.X, 1f))) return Fail;
            if (!(CheckValue<float>(B.Y, 1f))) return Fail;
            return Pass;
        }
    }

    private static int Main()
    {
        int returnVal = Pass;

        if (VectorAbsTest<float>.VectorAbs(-1f, 1f) != Pass) returnVal = Fail;
        if (VectorAbsTest<Double>.VectorAbs(-1d, 1d) != Pass) returnVal = Fail;
        if (VectorAbsTest<int>.VectorAbs(-1, 1) != Pass) returnVal = Fail;
        if (VectorAbsTest<long>.VectorAbs(-1, 1) != Pass) returnVal = Fail;
        if (VectorAbsTest<short>.VectorAbs((short)-1, (short)1) != Pass) returnVal = Fail;
        if (VectorAbsTest<sbyte>.VectorAbs((sbyte)-1, (sbyte)1) != Pass) returnVal = Fail;
        if (Vector4Test.VectorAbs() != Pass) returnVal = Fail;
        if (Vector3Test.VectorAbs() != Pass) returnVal = Fail;
        if (Vector2Test.VectorAbs() != Pass) returnVal = Fail;
        if (VectorAbsTest<ushort>.VectorAbs((ushort)0xffff, (ushort)0xffff) != Pass) returnVal = Fail;
        if (VectorAbsTest<byte>.VectorAbs((byte)0xff, (byte)0xff) != Pass) returnVal = Fail;
        if (VectorAbsTest<uint>.VectorAbs(0x41000000u, 0x41000000u) != Pass) returnVal = Fail;
        if (VectorAbsTest<ulong>.VectorAbs(0x4100000000000000ul, 0x4100000000000000ul) != Pass) returnVal = Fail;

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

        jitLog.Dispose();

        return returnVal;
    }
}