1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_lshrti3
3// REQUIRES: int128
4
5#include "int_lib.h"
6#include <stdio.h>
7
8#ifdef CRT_HAS_128BIT
9
10// Returns: logical a >> b
11
12// Precondition: 0 <= b < bits_in_dword
13
14COMPILER_RT_ABI ti_int __lshrti3(ti_int a, int b);
15
16int test__lshrti3(ti_int a, int b, ti_int expected) {
17 ti_int x = __lshrti3(a, b);
18 if (x != expected) {
19 twords at;
20 at.all = a;
21 twords xt;
22 xt.all = x;
23 twords expectedt;
24 expectedt.all = expected;
25 printf(format: "error in __lshrti3: 0x%llX%.16llX >> %d = 0x%llX%.16llX,"
26 " expected 0x%llX%.16llX\n",
27 at.s.high, at.s.low, b, xt.s.high, xt.s.low, expectedt.s.high,
28 expectedt.s.low);
29 }
30 return x != expected;
31}
32
33char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
34
35#endif
36
37int main()
38{
39#ifdef CRT_HAS_128BIT
40 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 0,
41 expected: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL)))
42 return 1;
43 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 1,
44 expected: make_ti(h: 0x7F6E5D4C3B2A190ALL, l: 0xFF6E5D4C3B2A190ALL)))
45 return 1;
46 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 2,
47 expected: make_ti(h: 0x3FB72EA61D950C85LL, l: 0x7FB72EA61D950C85LL)))
48 return 1;
49 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 3,
50 expected: make_ti(h: 0x1FDB97530ECA8642LL, l: 0xBFDB97530ECA8642LL)))
51 return 1;
52 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 4,
53 expected: make_ti(h: 0x0FEDCBA987654321LL, l: 0x5FEDCBA987654321LL)))
54 return 1;
55
56 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 28,
57 expected: make_ti(h: 0x0000000FEDCBA987LL, l: 0x6543215FEDCBA987LL)))
58 return 1;
59 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 29,
60 expected: make_ti(h: 0x00000007F6E5D4C3LL, l: 0xB2A190AFF6E5D4C3LL)))
61 return 1;
62 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 30,
63 expected: make_ti(h: 0x00000003FB72EA61LL, l: 0xD950C857FB72EA61LL)))
64 return 1;
65 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 31,
66 expected: make_ti(h: 0x00000001FDB97530LL, l: 0xECA8642BFDB97530LL)))
67 return 1;
68
69 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 32,
70 expected: make_ti(h: 0x00000000FEDCBA98LL, l: 0x76543215FEDCBA98LL)))
71 return 1;
72
73 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 33,
74 expected: make_ti(h: 0x000000007F6E5D4CLL, l: 0x3B2A190AFF6E5D4CLL)))
75 return 1;
76 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 34,
77 expected: make_ti(h: 0x000000003FB72EA6LL, l: 0x1D950C857FB72EA6LL)))
78 return 1;
79 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 35,
80 expected: make_ti(h: 0x000000001FDB9753LL, l: 0x0ECA8642BFDB9753LL)))
81 return 1;
82 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 36,
83 expected: make_ti(h: 0x000000000FEDCBA9LL, l: 0x876543215FEDCBA9LL)))
84 return 1;
85
86 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 60,
87 expected: make_ti(h: 0x000000000000000FLL, l: 0xEDCBA9876543215FLL)))
88 return 1;
89 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 61,
90 expected: make_ti(h: 0x0000000000000007LL, l: 0xF6E5D4C3B2A190AFLL)))
91 return 1;
92 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 62,
93 expected: make_ti(h: 0x0000000000000003LL, l: 0xFB72EA61D950C857LL)))
94 return 1;
95 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 63,
96 expected: make_ti(h: 0x0000000000000001LL, l: 0xFDB97530ECA8642BLL)))
97 return 1;
98
99 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 64,
100 expected: make_ti(h: 0x0000000000000000LL, l: 0xFEDCBA9876543215LL)))
101 return 1;
102
103 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 65,
104 expected: make_ti(h: 0x0000000000000000LL, l: 0x7F6E5D4C3B2A190ALL)))
105 return 1;
106 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 66,
107 expected: make_ti(h: 0x0000000000000000LL, l: 0x3FB72EA61D950C85LL)))
108 return 1;
109 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 67,
110 expected: make_ti(h: 0x0000000000000000LL, l: 0x1FDB97530ECA8642LL)))
111 return 1;
112 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 68,
113 expected: make_ti(h: 0x0000000000000000LL, l: 0x0FEDCBA987654321LL)))
114 return 1;
115
116 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 92,
117 expected: make_ti(h: 0x0000000000000000LL, l: 0x0000000FEDCBA987LL)))
118 return 1;
119 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 93,
120 expected: make_ti(h: 0x0000000000000000LL, l: 0x00000007F6E5D4C3LL)))
121 return 1;
122 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 94,
123 expected: make_ti(h: 0x0000000000000000LL, l: 0x00000003FB72EA61LL)))
124 return 1;
125 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 95,
126 expected: make_ti(h: 0x0000000000000000LL, l: 0x00000001FDB97530LL)))
127 return 1;
128
129 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 96,
130 expected: make_ti(h: 0x0000000000000000LL, l: 0x00000000FEDCBA98LL)))
131 return 1;
132
133 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 97,
134 expected: make_ti(h: 0x0000000000000000LL, l: 0x000000007F6E5D4CLL)))
135 return 1;
136 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 98,
137 expected: make_ti(h: 0x0000000000000000LL, l: 0x000000003FB72EA6LL)))
138 return 1;
139 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 99,
140 expected: make_ti(h: 0x0000000000000000LL, l: 0x000000001FDB9753LL)))
141 return 1;
142 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 100,
143 expected: make_ti(h: 0x0000000000000000LL, l: 0x000000000FEDCBA9LL)))
144 return 1;
145
146 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 124,
147 expected: make_ti(h: 0x0000000000000000LL, l: 0x000000000000000FLL)))
148 return 1;
149 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 125,
150 expected: make_ti(h: 0x0000000000000000LL, l: 0x0000000000000007LL)))
151 return 1;
152 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 126,
153 expected: make_ti(h: 0x0000000000000000LL, l: 0x0000000000000003LL)))
154 return 1;
155 if (test__lshrti3(a: make_ti(h: 0xFEDCBA9876543215LL, l: 0xFEDCBA9876543215LL), b: 127,
156 expected: make_ti(h: 0x0000000000000000LL, l: 0x0000000000000001LL)))
157 return 1;
158#else
159 printf("skipped\n");
160#endif
161 return 0;
162}
163

source code of compiler-rt/test/builtins/Unit/lshrti3_test.c