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