summaryrefslogtreecommitdiff
path: root/tests/src/JIT/CodeGenBringUpTests/Shift.cs
blob: 085ad3f31f83b7d85d74f13e071e1091b069ff10 (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
// 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.Runtime.CompilerServices;

public class Test
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    static ulong shl64(ulong shift, int count)
    {
        return shift << count;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static ulong shl64_32_inplace(ulong shift, ulong addit)
    {
        ulong x = shift + addit;
        x = x << 32;
        return x;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static ulong shl64_33_inplace(ulong shift, ulong addit)
    {
        ulong x = shift + addit;
        x = x << 33;
        return x;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static ulong shr64(ulong shift, int count)
    {
        return shift >> count;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static ulong shr64_32_inplace(ulong shift, ulong addit)
    {
        ulong x = shift + addit;
        x = x >> 32;
        return x;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static ulong shr1_32_add(ulong shift, ulong addit)
    {
        ulong x = (addit + (shift >> 1)) >> 31;
        return x;
    }

    public static int Main()
    {
        const int Pass = 100;
        const int Fail = -1;

        if (shl64_32_inplace(0x123456789abcdef, 0) != shl64(0x123456789abcdef, 32))
        {
            Console.WriteLine("shl64_32");
            return Fail;
        }

        if (shl64_33_inplace(0x123456789abcdef, 0) != shl64(0x123456789abcdef, 33))
        {
            Console.WriteLine("shl64_33");
            return Fail;
        }

        if (shr64_32_inplace(0x123456789abcdef, 0) != shr64(0x123456789abcdef, 32))
        {
            Console.WriteLine("shr64_32 {0:X} {1:X}", shr64_32_inplace(0x123456789abcdef, 0), shr64(0x123456789abcdef, 32));
            return Fail;
        }

        if (shr1_32_add(0x123456789abcdef, 0) != shr64(0x123456789abcdef, 32))
        {
            Console.WriteLine("HAHAHAHAHAHAHA {0:X}", shr1_32_add(0x123456789abcdef, 0));
            return Fail;
        }

        return Pass;
    }
}