1 1.1 joerg //===-- muloti4_test.c - Test __muloti4 -----------------------------------===// 2 1.1 joerg // 3 1.1 joerg // The LLVM Compiler Infrastructure 4 1.1 joerg // 5 1.1 joerg // This file is dual licensed under the MIT and the University of Illinois Open 6 1.1 joerg // Source Licenses. See LICENSE.TXT for details. 7 1.1 joerg // 8 1.1 joerg //===----------------------------------------------------------------------===// 9 1.1 joerg // 10 1.1 joerg // This file tests __muloti3 for the compiler_rt library. 11 1.1 joerg // 12 1.1 joerg //===----------------------------------------------------------------------===// 13 1.1 joerg 14 1.1 joerg #if __x86_64 15 1.1 joerg 16 1.1 joerg #include "int_lib.h" 17 1.1 joerg #include <stdio.h> 18 1.1 joerg 19 1.1 joerg // Returns: a * b 20 1.1 joerg 21 1.1 joerg // Effects: sets overflow if a * b overflows 22 1.1 joerg 23 1.1 joerg ti_int __muloti4(ti_int a, ti_int b, int *overflow); 24 1.1 joerg 25 1.1 joerg int test__muloti4(ti_int a, ti_int b, ti_int expected, int expected_overflow) 26 1.1 joerg { 27 1.1 joerg int ov; 28 1.1 joerg ti_int x = __muloti4(a, b, &ov); 29 1.1 joerg if (ov != expected_overflow) { 30 1.1 joerg twords at; 31 1.1 joerg at.all = a; 32 1.1 joerg twords bt; 33 1.1 joerg bt.all = b; 34 1.1 joerg twords xt; 35 1.1 joerg xt.all = x; 36 1.1 joerg twords expectedt; 37 1.1 joerg expectedt.all = expected; 38 1.1 joerg 39 1.1 joerg printf("error in __muloti4: overflow=%d expected=%d\n", 40 1.1 joerg ov, expected_overflow); 41 1.1 joerg printf("error in __muloti4: 0x%.16llX%.16llX * 0x%.16llX%.16llX = " 42 1.1 joerg "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n", 43 1.1 joerg at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low, 44 1.1 joerg expectedt.s.high, expectedt.s.low); 45 1.1 joerg return 1; 46 1.1 joerg } 47 1.1 joerg else if (!expected_overflow && x != expected) 48 1.1 joerg { 49 1.1 joerg twords at; 50 1.1 joerg at.all = a; 51 1.1 joerg twords bt; 52 1.1 joerg bt.all = b; 53 1.1 joerg twords xt; 54 1.1 joerg xt.all = x; 55 1.1 joerg twords expectedt; 56 1.1 joerg expectedt.all = expected; 57 1.1 joerg printf("error in __muloti4: 0x%.16llX%.16llX * 0x%.16llX%.16llX = " 58 1.1 joerg "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n", 59 1.1 joerg at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low, 60 1.1 joerg expectedt.s.high, expectedt.s.low); 61 1.1 joerg return 1; 62 1.1 joerg } 63 1.1 joerg return 0; 64 1.1 joerg } 65 1.1 joerg 66 1.1 joerg #endif 67 1.1 joerg 68 1.1 joerg int main() 69 1.1 joerg { 70 1.1 joerg #if __x86_64 71 1.1 joerg if (test__muloti4(0, 0, 0, 0)) 72 1.1 joerg return 1; 73 1.1 joerg if (test__muloti4(0, 1, 0, 0)) 74 1.1 joerg return 1; 75 1.1 joerg if (test__muloti4(1, 0, 0, 0)) 76 1.1 joerg return 1; 77 1.1 joerg if (test__muloti4(0, 10, 0, 0)) 78 1.1 joerg return 1; 79 1.1 joerg if (test__muloti4(10, 0, 0, 0)) 80 1.1 joerg return 1; 81 1.1 joerg if (test__muloti4(0, 81985529216486895LL, 0, 0)) 82 1.1 joerg return 1; 83 1.1 joerg if (test__muloti4(81985529216486895LL, 0, 0, 0)) 84 1.1 joerg return 1; 85 1.1 joerg 86 1.1 joerg if (test__muloti4(0, -1, 0, 0)) 87 1.1 joerg return 1; 88 1.1 joerg if (test__muloti4(-1, 0, 0, 0)) 89 1.1 joerg return 1; 90 1.1 joerg if (test__muloti4(0, -10, 0, 0)) 91 1.1 joerg return 1; 92 1.1 joerg if (test__muloti4(-10, 0, 0, 0)) 93 1.1 joerg return 1; 94 1.1 joerg if (test__muloti4(0, -81985529216486895LL, 0, 0)) 95 1.1 joerg return 1; 96 1.1 joerg if (test__muloti4(-81985529216486895LL, 0, 0, 0)) 97 1.1 joerg return 1; 98 1.1 joerg 99 1.1 joerg if (test__muloti4(1, 1, 1, 0)) 100 1.1 joerg return 1; 101 1.1 joerg if (test__muloti4(1, 10, 10, 0)) 102 1.1 joerg return 1; 103 1.1 joerg if (test__muloti4(10, 1, 10, 0)) 104 1.1 joerg return 1; 105 1.1 joerg if (test__muloti4(1, 81985529216486895LL, 81985529216486895LL, 0)) 106 1.1 joerg return 1; 107 1.1 joerg if (test__muloti4(81985529216486895LL, 1, 81985529216486895LL, 0)) 108 1.1 joerg return 1; 109 1.1 joerg 110 1.1 joerg if (test__muloti4(1, -1, -1, 0)) 111 1.1 joerg return 1; 112 1.1 joerg if (test__muloti4(1, -10, -10, 0)) 113 1.1 joerg return 1; 114 1.1 joerg if (test__muloti4(-10, 1, -10, 0)) 115 1.1 joerg return 1; 116 1.1 joerg if (test__muloti4(1, -81985529216486895LL, -81985529216486895LL, 0)) 117 1.1 joerg return 1; 118 1.1 joerg if (test__muloti4(-81985529216486895LL, 1, -81985529216486895LL, 0)) 119 1.1 joerg return 1; 120 1.1 joerg 121 1.1 joerg if (test__muloti4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0)) 122 1.1 joerg return 1; 123 1.1 joerg if (test__muloti4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0)) 124 1.1 joerg return 1; 125 1.1 joerg if (test__muloti4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0)) 126 1.1 joerg return 1; 127 1.1 joerg if (test__muloti4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0)) 128 1.1 joerg return 1; 129 1.1 joerg 130 1.1 joerg if (test__muloti4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0)) 131 1.1 joerg return 1; 132 1.1 joerg if (test__muloti4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0)) 133 1.1 joerg return 1; 134 1.1 joerg if (test__muloti4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0)) 135 1.1 joerg return 1; 136 1.1 joerg if (test__muloti4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0)) 137 1.1 joerg return 1; 138 1.1 joerg 139 1.1 joerg if (test__muloti4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0)) 140 1.1 joerg return 1; 141 1.1 joerg if (test__muloti4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0)) 142 1.1 joerg return 1; 143 1.1 joerg if (test__muloti4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0)) 144 1.1 joerg return 1; 145 1.1 joerg if (test__muloti4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0)) 146 1.1 joerg return 1; 147 1.1 joerg 148 1.1 joerg if (test__muloti4(make_ti(0x00000000000000B5LL, 0x04F333F9DE5BE000LL), 149 1.1 joerg make_ti(0x0000000000000000LL, 0x00B504F333F9DE5BLL), 150 1.1 joerg make_ti(0x7FFFFFFFFFFFF328LL, 0xDF915DA296E8A000LL), 0)) 151 1.1 joerg return 1; 152 1.1 joerg 153 1.1 joerg if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 154 1.1 joerg -2, 155 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1)) 156 1.1 joerg return 1; 157 1.1 joerg if (test__muloti4(-2, 158 1.1 joerg make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 159 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1)) 160 1.1 joerg return 1; 161 1.1 joerg if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 162 1.1 joerg -1, 163 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0)) 164 1.1 joerg return 1; 165 1.1 joerg if (test__muloti4(-1, 166 1.1 joerg make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 167 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0)) 168 1.1 joerg return 1; 169 1.1 joerg if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 170 1.1 joerg 0, 171 1.1 joerg 0, 0)) 172 1.1 joerg return 1; 173 1.1 joerg if (test__muloti4(0, 174 1.1 joerg make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 175 1.1 joerg 0, 0)) 176 1.1 joerg return 1; 177 1.1 joerg if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 178 1.1 joerg 1, 179 1.1 joerg make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0)) 180 1.1 joerg return 1; 181 1.1 joerg if (test__muloti4(1, 182 1.1 joerg make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 183 1.1 joerg make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0)) 184 1.1 joerg return 1; 185 1.1 joerg if (test__muloti4(make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 186 1.1 joerg 2, 187 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1)) 188 1.1 joerg return 1; 189 1.1 joerg if (test__muloti4(2, 190 1.1 joerg make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 191 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1)) 192 1.1 joerg return 1; 193 1.1 joerg 194 1.1 joerg if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL), 195 1.1 joerg -2, 196 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1)) 197 1.1 joerg return 1; 198 1.1 joerg if (test__muloti4(-2, 199 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 200 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1)) 201 1.1 joerg return 1; 202 1.1 joerg if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL), 203 1.1 joerg -1, 204 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1)) 205 1.1 joerg return 1; 206 1.1 joerg if (test__muloti4(-1, 207 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 208 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1)) 209 1.1 joerg return 1; 210 1.1 joerg if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL), 211 1.1 joerg 0, 212 1.1 joerg 0, 0)) 213 1.1 joerg return 1; 214 1.1 joerg if (test__muloti4(0, 215 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 216 1.1 joerg 0, 0)) 217 1.1 joerg return 1; 218 1.1 joerg if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL), 219 1.1 joerg 1, 220 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 0)) 221 1.1 joerg return 1; 222 1.1 joerg if (test__muloti4(1, 223 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 224 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 0)) 225 1.1 joerg return 1; 226 1.1 joerg if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000000LL), 227 1.1 joerg 2, 228 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1)) 229 1.1 joerg return 1; 230 1.1 joerg if (test__muloti4(2, 231 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 232 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1)) 233 1.1 joerg return 1; 234 1.1 joerg 235 1.1 joerg if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL), 236 1.1 joerg -2, 237 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1)) 238 1.1 joerg return 1; 239 1.1 joerg if (test__muloti4(-2, 240 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 241 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 1)) 242 1.1 joerg return 1; 243 1.1 joerg if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL), 244 1.1 joerg -1, 245 1.1 joerg make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0)) 246 1.1 joerg return 1; 247 1.1 joerg if (test__muloti4(-1, 248 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 249 1.1 joerg make_ti(0x7FFFFFFFFFFFFFFFLL, 0xFFFFFFFFFFFFFFFFLL), 0)) 250 1.1 joerg return 1; 251 1.1 joerg if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL), 252 1.1 joerg 0, 253 1.1 joerg 0, 0)) 254 1.1 joerg return 1; 255 1.1 joerg if (test__muloti4(0, 256 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 257 1.1 joerg 0, 0)) 258 1.1 joerg return 1; 259 1.1 joerg if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL), 260 1.1 joerg 1, 261 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0)) 262 1.1 joerg return 1; 263 1.1 joerg if (test__muloti4(1, 264 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 265 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 0)) 266 1.1 joerg return 1; 267 1.1 joerg if (test__muloti4(make_ti(0x8000000000000000LL, 0x0000000000000001LL), 268 1.1 joerg 2, 269 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1)) 270 1.1 joerg return 1; 271 1.1 joerg if (test__muloti4(2, 272 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000001LL), 273 1.1 joerg make_ti(0x8000000000000000LL, 0x0000000000000000LL), 1)) 274 1.1 joerg return 1; 275 1.1 joerg 276 1.1 joerg #else 277 1.1 joerg printf("skipped\n"); 278 1.1 joerg #endif 279 1.1 joerg return 0; 280 1.1 joerg } 281