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