summaryrefslogtreecommitdiff
path: root/test/builtins/Unit/ashrti3_test.c
blob: 530cff53cb5c430e45b03dc902a5fca496a908ce (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: int128
//===-- ashrti3_test.c - Test __ashrti3 -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file tests __ashrti3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//

#include "int_lib.h"
#include <stdio.h>

#ifdef CRT_HAS_128BIT

// Returns: arithmetic a >> b

// Precondition:  0 <= b < bits_in_tword

COMPILER_RT_ABI ti_int __ashrti3(ti_int a, si_int b);

int test__ashrti3(ti_int a, si_int b, ti_int expected)
{
    ti_int x = __ashrti3(a, b);
    if (x != expected)
    {
        twords at;
        at.all = a;
        twords xt;
        xt.all = x;
        twords expectedt;
        expectedt.all = expected;
        printf("error in __ashrti3: 0x%llX%.16llX >> %d = 0x%llX%.16llX,"
               " expected 0x%llX%.16llX\n",
                at.s.high, at.s.low, b, xt.s.high, xt.s.low,
                expectedt.s.high, expectedt.s.low);
    }
    return x != expected;
}

char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};

#endif

int main()
{
#ifdef CRT_HAS_128BIT
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 0,
                      make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 1,
                      make_ti(0xFF6E5D4C3B2A190ALL, 0xFF6E5D4C3B2A190ALL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 2,
                      make_ti(0xFFB72EA61D950C85LL, 0x7FB72EA61D950C85LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 3,
                      make_ti(0xFFDB97530ECA8642LL, 0xBFDB97530ECA8642LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 4,
                      make_ti(0xFFEDCBA987654321LL, 0x5FEDCBA987654321LL)))
        return 1;

    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 28,
                      make_ti(0xFFFFFFFFEDCBA987LL, 0x6543215FEDCBA987LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 29,
                      make_ti(0xFFFFFFFFF6E5D4C3LL, 0xB2A190AFF6E5D4C3LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 30,
                      make_ti(0xFFFFFFFFFB72EA61LL, 0xD950C857FB72EA61LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 31,
                      make_ti(0xFFFFFFFFFDB97530LL, 0xECA8642BFDB97530LL)))
        return 1;

    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 32,
                      make_ti(0xFFFFFFFFFEDCBA98LL, 0x76543215FEDCBA98LL)))
        return 1;

    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 33,
                      make_ti(0xFFFFFFFFFF6E5D4CLL, 0x3B2A190AFF6E5D4CLL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 34,
                      make_ti(0xFFFFFFFFFFB72EA6LL, 0x1D950C857FB72EA6LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 35,
                      make_ti(0xFFFFFFFFFFDB9753LL, 0x0ECA8642BFDB9753LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 36,
                      make_ti(0xFFFFFFFFFFEDCBA9LL, 0x876543215FEDCBA9LL)))
        return 1;

    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 60,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xEDCBA9876543215FLL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 61,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xF6E5D4C3B2A190AFLL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 62,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFB72EA61D950C857LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 63,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFDB97530ECA8642BLL)))
        return 1;

    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 64,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFEDCBA9876543215LL)))
        return 1;

    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 65,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFF6E5D4C3B2A190ALL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 66,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFB72EA61D950C85LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 67,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFDB97530ECA8642LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 68,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFEDCBA987654321LL)))
        return 1;

    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 92,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFEDCBA987LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 93,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFF6E5D4C3LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 94,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFB72EA61LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 95,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFDB97530LL)))
        return 1;

    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 96,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFEDCBA98LL)))
        return 1;

    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 97,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFF6E5D4CLL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 98,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFB72EA6LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 99,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFDB9753LL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 100,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFEDCBA9LL)))
        return 1;

    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 124,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 125,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 126,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
        return 1;
    if (test__ashrti3(make_ti(0xFEDCBA9876543215LL, 0xFEDCBA9876543215LL), 127,
                      make_ti(0xFFFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL)))
        return 1;
#else
    printf("skipped\n");
#endif
    return 0;
}