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